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

[Feature Request] Support reflection for a StructuredBuffer's underlying type #376

Open
Toctave opened this issue Jan 27, 2025 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@Toctave
Copy link

Toctave commented Jan 27, 2025

Describe the solution you'd like
I'd like to have a way to introspect a shader's structured buffers and read their internal layout. Currently, it seems like the only way to access information about a structured buffer is to use ID3D12ShaderReflection::GetResourceBindingDesc, from which I can get the resource's name and input type (D3D_SIT_STRUCTURED or D3D_SIT_UAV_RWSTRUCTURED in the case of structured buffers), and the element stride in the D3D12_SHADER_INPUT_BIND_DESC::NumSamples field, as documented in this issue.

This does not tell us anything about the specific fields that are present in the structured buffer. For more detail, it would be nice to have a way to get to the underlying type of the structured buffer. What I'd need is an API call to get from a D3D12_SHADER_INPUT_BIND_DESC to a ID3D12ShaderReflectionType* in case the input binding is a structured buffer.

All the necessary information is available in the shader disassembly as returned by D3DDisassemble, for instance:

Shader:

struct Vertex
{
    float3 pos;
    float3 norm;
};

struct Object
{
    float4x3 m;
};

struct BufType
{
    Object obj;
    Vertex vertex;
};

RWStructuredBuffer<BufType> BufferOut : register(u0);

[numthreads(64, 1, 1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
    BufferOut[DTid.x].vertex.pos = float3(0, 0, 0);
}

Disassembly:

// [...]
// Resource bind info for BufferOut
// {
//
//   struct BufType
//   {
//       
//       struct Object
//       {
//           
//           float4x3 m;                // Offset:    0
//
//       } obj;                         // Offset:    0
//       
//       struct Vertex
//       {
//           
//           float3 pos;                // Offset:   48
//           float3 norm;               // Offset:   60
//
//       } vertex;                      // Offset:   48
//
//   } $Element;                        // Offset:    0 Size:    72
//
// }
// [...]

The only missing piece is a public API to access the type information from an input description.

Describe alternatives you've considered
I've tried parsing the pdb generated by DXC with the DIA SDK, but it has the same missing link: I can get the stride and name for a structured buffer, but not the underlying type

@Toctave Toctave added enhancement New feature or request needs-triage labels Jan 27, 2025
@damyanp damyanp transferred this issue from microsoft/DirectXShaderCompiler Jan 29, 2025
@damyanp damyanp moved this to Triaged in HLSL Triage Jan 29, 2025
@damyanp damyanp added this to the Dormant milestone Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Triaged
Development

No branches or pull requests

2 participants