microsoft / microsoft/DirectXShaderCompiler

[SPIR-V] Semantic index limits for system values are not enforced on -spirv path

Open
#8,878 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

The SPIR-V backend does not enforce system-value semantic index limits, so -spirv silently accepts semantics that the DXIL path rejects. It's just a missing diagnostic rather than bad codegen; the index is discarded and the emitted module becomes the legal index-0 spelling.

Steps to Reproduce

// repro.hlsl
[shader("vertex")]
float4 main(uint vid : SV_VertexID) : SV_Position1 {
    return float4((float)vid, 0.0, 0.0, 1.0);
}
dxc -T vs_6_8 -E main repro.hlsl -Fo repro.dxo          # rejected
dxc -T vs_6_8 -E main -spirv repro.hlsl -Fo repro.spv   # accepted

Actual Behavior

DXIL path errors as expected:

error: SV_Position semantic index exceeds maximum (0).
Validation failed.

SPIR-V path exits 0 with no diagnostic and emits the index-0 builtin, so the
1 is silently dropped:

OpDecorate %gl_Position BuiltIn Position

Other SVs behave the same way (SV_VertexID1, SV_Depth1, SV_DispatchThreadID1, SV_PrimitiveID1, ...). The once exception is SV_Target, since its bound is checked in the frontend rather than backend.

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 with repro.hlsl and run the two dxc commands to compare the DXIL and -spirv paths. Trace the SPIR-V backend's handling of system-value semantic indices, then verify that invalid indices produce a diagnostic instead of being silently emitted as index 0, including the listed SV examples while preserving the SV_Target exception.

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
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.