microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.04k stars 676 forks source link

Retrieving reflection data for structs used in input signatures #3535

Open mattsinger opened 3 years ago

mattsinger commented 3 years ago

I am writing a code generator based on D3D12 shader reflection data. Given a simple vertex shader:

struct VertexIn
{
    float3 mPos : POSITION;
    float3 mColor : COLOR;
};
struct VertexOut;  // layout unimportant to question

VertexOut VS(VertexIn vin) 
{ 
    // some math here, return a VertexOut
}

I can use ID3D12ShaderReflection::GetInputParameterDesc to get the type and semantic for each member of VertexIn, as well as the register it is mapped to. However, I would like to retrieve the names of the VertexIn members (i.e. "mPos" and "mColor") for my generated code. Is there a way to do this?

damyanp commented 4 months ago

@coopp - as you're looking in to the reflection stuff at the moment you may be able to answer whether or not this is possible.

coopp commented 4 months ago

I think the SemanticName is available as part of the _D3D12_SIGNATURE_PARAMETER_DESC

typedef struct _D3D12_SIGNATURE_PARAMETER_DESC
{
    LPCSTR                      SemanticName;   // Name of the semantic
    UINT                        SemanticIndex;  // Index of the semantic
    UINT                        Register;       // Number of member variables
    D3D_NAME                    SystemValueType;// A predefined system value, or D3D_NAME_UNDEFINED if not applicable
    D3D_REGISTER_COMPONENT_TYPE ComponentType;  // Scalar type (e.g. uint, float, etc.)
    BYTE                        Mask;           // Mask to indicate which components of the register
                                                // are used (combination of D3D10_COMPONENT_MASK values)
    BYTE                        ReadWriteMask;  // Mask to indicate whether a given component is 
                                                // never written (if this is an output signature) or
                                                // always read (if this is an input signature).
                                                // (combination of D3D_MASK_* values)
    UINT                        Stream;         // Stream index
    D3D_MIN_PRECISION           MinPrecision;   // Minimum desired interpolation precision
} D3D12_SIGNATURE_PARAMETER_DESC;
damyanp commented 4 months ago

The question is about obtaining the member name (eg mPos) as opposed to the semantic name (eg POSITION).

coopp commented 4 months ago

OH! I misread the question. I'll look some more to see if that information can be retrieved.

coopp commented 4 months ago

I do not see a way to get this information. Looks like there are ways to inspect buffers/resources etc and get their names but not the names of members on these inputs.