Skip to content

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

Closed

Description

@Sparkrai
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

Activity

  1. 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[/+] on Sep 19, 2019
  2. Sparkrai commented on Sep 19, 2019

    @Sparkrai
    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];
    ~~~~~~~~~~~~~^~

  3. added
    bug
    on Oct 25, 2019
  4. Reedbeta commented on Apr 19, 2020

    @Reedbeta

    I've just encountered this issue as well.

  5. vaspoul commented on Aug 9, 2020

    @vaspoul

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

  6. vaspoul commented on Aug 9, 2020

    @vaspoul

    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. :/

  7. added a commit that references this issue on Nov 28, 2020
    6506b63
  8. added a commit that references this issue on Jan 12, 2021
    11f0765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions