microsoft / microsoft/DirectXShaderCompiler
Rewriter removed struct declaration which used in constant buffer.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Hello,
the following shader rewrite with dxr.exe -remove-unused-functions -remove-unused-globals -E vs_main
struct InstanceDataStructType
{
float4 data;
};
cbuffer InstanceData
{
InstanceDataStructType mData[2];
};
struct InstanceDataStructTypeNotUsed
{
float4 data;
};
cbuffer InstanceDataNotUsed
{
InstanceDataStructType mDataNotUsed[2];
};
struct VS_INPUT
{
float3 position : POSITION;
float4 texcoord0 : TEXCOORD0;
float4 diffuse: COLOR0;
};
struct VS_OUTPUT
{
float4 position : SV_Position;
float4 uv : TEXCOORD0;
float4 color : VC;
};
VS_OUTPUT vs_main(VS_INPUT input, uint instanceID : SV_InstanceID)
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.position += mData[0].data;
return output;
}
float4 ps_main(VS_OUTPUT input) : SV_Target0
{
return input.color;
}
Output's all cbuffer declaration are still remaining, but its referenced struct definitions are removed.
cbuffer InstanceData {
const InstanceDataStructType mData[2];
}
;
cbuffer InstanceDataNotUsed {
const InstanceDataStructType mDataNotUsed[2];
}
;
struct VS_OUTPUT {
float4 position : SV_Position;
float4 uv : TEXCOORD0;
float4 color : VC;
};
VS_OUTPUT vs_main(VS_INPUT input, uint instanceID : SV_InstanceID) {
VS_OUTPUT output = (VS_OUTPUT)0;
output.position += mData[0].data;
return output;
}
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
Reproduce the issue with the supplied HLSL and the dxr.exe command using -remove-unused-functions, -remove-unused-globals, and -E vs_main. Inspect the rewrite handling for constant buffers and struct declarations; done means referenced struct definitions remain valid while genuinely unused declarations may still be removed, with the reported output no longer containing undefined struct types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100