microsoft / microsoft/DirectXShaderCompiler

Rewriter remove used static global variable which is used for other static global variable definition used by entryPoint

Open
#5,268 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug rewriter
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

dxr test.hlsl -E VSMain -remove-unused-globals

static const float POINT_SIZE = 3.0f;
static const float3 POINT_SIZE_3 = float3(1.0f, 1.0f, 1.0f) * POINT_SIZE;

struct PSInput
{
    float4 position : POSITION;
};

PSInput VSMain(float3 position : POSITION)
{
    PSInput psInput;
    psInput.position = float4(position, 1.0f);
    psInput.position.xyz *= POINT_SIZE_3;
    return psInput;
}

In the above test case, EntryPoint is using POINT_SIZE_3 and thus it is not optimized out by rewriter. That POINT_SIZE_3 need POINT_SIZE for variable definition, but rewriter remove POINT_SIZE. It leads to compile error

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the shown test.hlsl and dxr test.hlsl -E VSMain -remove-unused-globals, then trace the rewriter's unused-global handling. Done means POINT_SIZE is retained when POINT_SIZE_3 is used by VSMain, and the rewritten shader compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.