Skip to content

ID3D12ShaderReflectionVariable::GetType always returns NULL #134

Closed

Description

@tangent-vector

Title

ID3D12ShaderReflectionVariable::GetType always returns NULL

Functional impact

Applications that work with d3dcompiler_47.dll, and which rely on being able to perform reflection on the contents of constant buffers (e.g., to find the offsets of sub-fields) do not work properly with dxcompiler.dll and may crash with a NULL pointer dererence (as they will likely assume that all valid ID3D12ShaderReflectionVariables will have valid types).

Minimal repro steps

  1. Use D3DCompile() to compile a shader with at least one variable in a constant buffer
  2. Use D3DReflect() to get an ID3D12ShaderReflection interface
  3. Use ID3D12ShaderReflection::GetConstantBufferByName() to get refleciton info for the constant buffer
  4. Use ID3D12ShaderReflectionConstantBuffer::GetVariableByName() to get the reflection info for the variable
  5. Call ID3D12ShaderReflectionVariable::GetType()

Expected result

The result of ID3D12ShaderReflectionVariable::GetType() should be non-NULL if the input was a valid variable.

Actual result

The result is NULL.

Further technical details

The root cause is pretty clear, arising from the following lines in DxilContainerReflection.cpp, inside CShaderReflectionConstantBuffer::Initialize():

// TODO: create reflection type.
CShaderReflectionType *pVarType = nullptr;

The variable pVarType never gets filled in, but is used in the intialization of the CShaderReflectionVariable:

Var.Initialize(this, &VarDesc, pVarType, pDefaultValue);

The basic problem is then that the feature marked as TODO hasn't been implemented.

I have an initial implementation of the feature in place, at least as far as required for my workload. I will be working toward turning it into a pull request some time this week, unless somebody else already has an implementation that is further along.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions