microsoft / microsoft/DirectXShaderCompiler
Using a static const array in a member function declaration causes CREATEPIXELSHADER_INVALIDSHADERBYTECODE during CreatePipelineState
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Tested with dxcompiler.dll version 1.6.0.3597 (commit a19c32629, 2022/06/22)
The following snippet compiles successfully with no errors but, returns CREATEPIXELSHADER_INVALIDSHADERBYTECODE or CREATEMESHSHADER_INVALIDSHADERBYTECODE, depending on where the code is used.
struct MyClass {
float3 GetTestValue(uint index) {
static const float3 kValues[3] = {float3(0, 0, 1), float3(0, 1, 0), float3(1, 0, 0)};
return kValues[index];
}
};
Workarounds:
- Removing the static declaration fixes the error.
- Using a global function instead of a class member function fixes the error.
- Moving the static array declaration to global scope fixes the error.
Test sample code:
test_dxc_bug.hlsl.txt
The following test case define will cause an error when creating a pipeline state.
#define TEST_CASE CASE_MEMBER_FUNCTION_STATIC
D3D12 Validation Layer Error log
Note that the error message says Pixel Shader is unsigned, but using a different define (with no change to compile pipeline), that error message doesn't happen.
D3D12 ERROR: ID3D12Device::CreatePixelShader: Pixel Shader is unsigned. [ STATE_CREATION ERROR #93: CREATEPIXELSHADER_INVALIDSHADERBYTECODE]
D3D12: **BREAK** enabled for the previous message, which was: [ ERROR STATE_CREATION #93: CREATEPIXELSHADER_INVALIDSHADERBYTECODE ]
D3D12 ERROR: ID3D12Device::CreateMeshShader: Mesh Shader is corrupt unsigned. [ STATE_CREATION ERROR #1265: CREATEMESHSHADER_INVALIDSHADERBYTECODE]
D3D12: **BREAK** enabled for the previous message, which was: [ ERROR STATE_CREATION #1265: CREATEMESHSHADER_INVALIDSHADERBYTECODE ]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached test_dxc_bug.hlsl.txt sample and reproduce the failure using #define TEST_CASE CASE_MEMBER_FUNCTION_STATIC. Compare pipeline creation with the listed workarounds and trace the generated shader bytecode to identify why the member-function static array produces invalid bytecode. Done means the sample creates the pipeline successfully without requiring those workarounds.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100