Skip to content

rdna2spirv: deduplicate vertex inputs per register (SHADER-644) - #3498

Closed
sarveshgamers wants to merge 1 commit into
ItsNotRexed:mainfrom
sarveshgamers:fix/vs-packed-inputs-dedup
Closed

sarveshgamers wants to merge 1 commit into
ItsNotRexed:mainfrom
sarveshgamers:fix/vs-packed-inputs-dedup

Conversation

@sarveshgamers

Copy link
Copy Markdown
Contributor

Summary

Fixes SHADER-644: deduplicate vertex inputs per register in rdna2spirv.py.

When an ISG1 input signature packs multiple semantic elements into the same register (e.g. .xy as TEXCOORD0 and .zw as TEXCOORD1), building g.vertex_inputs directly from input_signature() produced duplicate entries for that register. This caused rdna2spirv to emit:

  • Duplicate %vin{reg} tokens in the OpEntryPoint Vertex interface list
  • Duplicate OpDecorate %vin{reg} Location {reg} instructions
  • Duplicate %vin{reg} = OpVariable declarations
  • Duplicate %vinv{reg} = OpLoad and %vinc{reg}_{c} = OpCompositeExtract assignments, failing spirv-val with Id <id> is defined more than once.

Changes

  • tools/rdna2spirv.py:
    • Deduplicate g.vertex_inputs per register index.
    • Verify component types across elements sharing a register are consistent, raising Unsupported on type conflicts.
  • tests/semantic/test_vs_packed_inputs.py:
    • Adds synthetic ISG1 tests verifying that packed registers declare each decoration, interface token, and OpVariable exactly once.
    • Verifies generated SPIR-V passes spirv-as and spirv-val.
    • Verifies conflicting component types in the same register raise Unsupported.
  • docs/design.md:
    • Documents register deduplication and conflict rejection in the Vertex fetch contract row.

Testing

  • python -m unittest tests/semantic/test_vs_packed_inputs.py -v: 2/2 tests pass.
  • python -m unittest discover -s tests/semantic -v: all 7,324 semantic tests pass.
  • python -m compileall -q make_game.py tools tests: 0 errors.
  • Clean-room synthetic test fixtures only; no game files or raw retail data.
  • AI-assisted.

Claimed in #3232.

When an ISG1 input signature packs multiple semantic elements into the same input register (e.g. .xy and .zw), building g.vertex_inputs directly from the signature produced duplicate entries for that register.

This caused rdna2spirv to emit duplicate %vin{reg} OpVariable declarations, duplicate interface tokens in OpEntryPoint, and duplicate entry-block loads, failing spirv-val with 'Id is defined more than once'.

Deduplicate vertex inputs per register index while verifying that components sharing a register declare consistent component types (rejecting conflicting types with Unsupported).

Add tests/semantic/test_vs_packed_inputs.py covering deduplication, OpEntryPoint/OpVariable/OpDecorate integrity, spirv-val validation, and conflicting-type rejection. Update docs/design.md.

All 7,324 semantic tests pass. AI-assisted.

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted source review at 4aa29e7c. The per-register deduplication fixes the duplicate SPIR-V IDs for same-type signatures. There is a remaining input-layout issue: runtime/shims/d3d12_vulkan_device.cpp:2643 sets each Vulkan attribute's location from input->register_index. If TEXCOORD0.xy and TEXCOORD1.zw both describe register 0 and the application binds them as separate attributes, the runtime still emits two attributes at location 0, even with this translator fix. The subsequent feed check also accepts one bound attribute as feeding both semantics.

The existing D3D-388 work (#3512, stacked on #3403) overlaps this translator hunk and gives each independently bound semantic a location, then reconstructs the logical register columns. The two approaches should be reconciled before either is used as the end-to-end packed-input fix. A regression that gives the two attributes different buffers or offsets and checks all four independent words distinguishes the fixes. This review used source only and did not submit a duplicate-location pipeline to a driver.

@paratustra

Copy link
Copy Markdown

Code read at 4aa29e7. The module becomes valid, but I think the data for the second element of a shared register can no longer arrive correctly, so it would be safer to refuse this case than to accept it.

  • One vec4 input per register, two elements feeding it. After dedup, %vin0 is a single vec4 at Location 0, and the VS reads .xy (TEXCOORD0) and .zw (TEXCOORD1) from it. The runtime builds one attribute per input-layout element at location = register_index (runtime/shims/d3d12_vulkan_device.cpp ~2643), so this signature gives two VkVertexInputAttributeDescriptions with the same location, which Vulkan requires to be unique. Even where a driver accepted it, each attribute fills the location from component 0, so TEXCOORD1's data would land in .xy, not .zw. Before this change the shader failed spirv-val loudly; after it, it translates and the error moves to pipeline creation or to wrong vertex data.
  • No corpus case. The README reports all 26,503 shaders translated and spirv-val-valid, and a fetch-calling VS with a shared input register would fail validation with the duplicate %vin. So no shader in 1.0.2.1 seems to have this signature, and the description doesn't name one.

Suggestion: keep it Unsupported, with a clear message ("two input elements share register N"), instead of the duplicate-id failure. If a real shader turns up, the translator and create_graphics need to handle it together (per-element inputs, or merging the elements into one attribute when they are contiguous in the same slot).

No game files. AI-assisted (Claude Code).

@sarveshgamers

Copy link
Copy Markdown
Contributor Author

Thank you @whattheflop for the detailed architectural review.

Indeed, while this PR addresses the standalone translator issue where duplicate %vin\ variables caused \spirv-val\ failures, your D3D-388 work (#3512) is the complete end-to-end fix that handles separate D3D12 vertex buffer slots and offsets in \d3d12_vulkan_device.cpp\ by assigning per-semantic Vulkan locations.

Deferring to #3512 for the full end-to-end packed input solution. Closing in favor of #3512.

@sarveshgamers

Copy link
Copy Markdown
Contributor Author

Thanks @whattheflop for the detailed architectural review. While this PR addressed the standalone translator duplicate %vin\ ID defect on packed ISG1 containers, #3512 provides the complete end-to-end handling across both the D3D12 runtime (\d3d12_vulkan_device.cpp\ separate slot/offset binding) and translator column routing. Closing in favor of #3512.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants