DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Retrieving reflection data for structs used in input signatures

Open mattsinger opened this issue 3 years ago • 5 comments

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?

mattsinger avatar Mar 04 '21 02:03 mattsinger

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

damyanp avatar Apr 17 '24 16:04 damyanp

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;

coopp avatar Apr 18 '24 16:04 coopp

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

damyanp avatar Apr 18 '24 17:04 damyanp

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

coopp avatar Apr 18 '24 17:04 coopp

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.

coopp avatar Apr 18 '24 20:04 coopp

I've noticed that ID3D12ShaderReflectionType::GetMemberTypeName returns the member name, not the type name. While this seems like a bug to me, it is currently doing what was requested in this issue.

aclysma avatar Sep 08 '24 23:09 aclysma