Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXC: Compilation fails if a Buffer/Texture resource defined inside a namespace is sampled/used #2472

Closed
Sparkrai opened this issue Sep 19, 2019 · 4 comments · Fixed by #3284
Assignees
Labels
bug Bug, regression, crash

Comments

@Sparkrai
Copy link

Sparkrai commented Sep 19, 2019

namespace test
{
    Texture2D<float4> colorMap : register(t0);
}

SamplerState pointSampler : register(s0);

float4 PSMain(in float2 uv : TEXCOORD0) : SV_TARGET0
{
    return test::colorMap.Sample(pointSampler, uv);
}

The provided code, even if entirely valid, will not compile. When run dxc will output this error:

test.hlsl:10:26: error: no member named 'Sample' in 'Texture2D<vector<float, 4> >'
return test::colorMap.Sample(pointSampler, uv);
~~~~~~~~~~~~~ ^

With FXC the shader gets compiled correctly without any errors/warnings. This is the assembly output by FXC with shader model ps_5_1:

Microsoft (R) Direct3D Shader Compiler 10.1 (using D:\p4\HMD2\Development\LsTools\Bin\pipeline\D3DCOMPILER_47.dll)
Copyright (C) 2013 Microsoft. All rights reserved.
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
// Resource Bindings:
//
// Name Type Format Dim ID HLSL Bind Count
// ------------------------------ ---------- ------- ----------- ------- -------------- ------
// pointSampler sampler NA NA S0 s0 1
// test::colorMap texture float4 2d T0 t0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD 0 xy 0 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET 0 xyzw 0 TARGET float xyzw
//
ps_5_1
dcl_globalFlags refactoringAllowed
dcl_sampler S0[0:0], mode_default, space=0
dcl_resource_texture2d (float,float,float,float) T0[0:0], space=0
dcl_input_ps linear v0.xy
dcl_output o0.xyzw
sample o0.xyzw, v0.xyxx, T0[0].xyzw, S0[0]
ret
// Approximately 2 instruction slots used

@Sparkrai Sparkrai changed the title DXC: Compilation fails if a Texture resource defined inside a namespace is sampled/used DXC: Compilation fails if a Buffer/Texture resource defined inside a namespace is sampled/used Sep 19, 2019
@Sparkrai
Copy link
Author

To add to this, it seems any type of Buffer has the same behaviour.
This code:

namespace test
{
    StructuredBuffer<float4> colorMap : register(t0);
}

float4 PSMain(in float2 uv : TEXCOORD0) : SV_TARGET0
{
    return test::colorMap[0];
}

Also doesn't compile and produces the following error:

test.hlsl:8:26: error: type 'StructuredBuffer' does not provide a subscript operator
return test::colorMap[0];
~~~~~~~~~~~~~^~

@tex3d tex3d added the bug Bug, regression, crash label Oct 25, 2019
@Reedbeta
Copy link

I've just encountered this issue as well.

@vaspoul
Copy link

vaspoul commented Aug 9, 2020

Any movement on this? I'm desperately trying to find ways of grouping resources together to assist with building root signatures. Namespace would help.

@vaspoul
Copy link

vaspoul commented Aug 9, 2020

Additionally, having textures (and probably other resources) declared before or after the namespace also affects this.

In the following example, all 3 sample() lines compile ok

`Texture2D texture1;

namespace SomeNamespace
{
Texture2D texture2;
}

Texture2D texture3;

SamplerState g_samplerState;

float4 main(float2 uv : TEXCOORD0) : SV_Target0
{
//return texture1.Sample(g_samplerState, uv);
//return SomeNamespace::texture2.Sample(g_samplerState, uv);
return texture3.Sample(g_samplerState, uv);
}
`

but removing the texture1 declaration breaks the remaining 2:

`//Texture2D texture1;

namespace SomeNamespace
{
Texture2D texture2;
}

Texture2D texture3;

SamplerState g_samplerState;

float4 main(float2 uv : TEXCOORD0) : SV_Target0
{
//return texture1.Sample(g_samplerState, uv);
//return SomeNamespace::texture2.Sample(g_samplerState, uv);
return texture3.Sample(g_samplerState, uv);
}
`

So perhaps a workaround for now would be to declare a dummy texture before all the namespaces. :/

@pow2clk pow2clk self-assigned this Nov 26, 2020
pow2clk added a commit to pow2clk/DirectXShaderCompiler that referenced this issue Nov 28, 2020
Builtin object types such as Texture2D add all their object methods
to the associated decl context when they are first seen. However,
previously, if the code meant to effect that was found in a namespace
it would skip this addition. This removes that restriction so that
the methods can be added and then found when needed.

Fixes microsoft#2472
pow2clk added a commit that referenced this issue Jan 12, 2021
Builtin object types such as Texture2D add all their object methods
to the associated decl context when they are first seen. However,
previously, if the code meant to effect that was found in a namespace
it would skip this addition. This removes that restriction so that
the methods can be added and then found when needed.

Fixes #2472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants