Skip to content

BUILD-1706: Keep shader layout metadata with the emitted module - #5352

Open
Hiiva wants to merge 1 commit into
ItsNotRexed:mainfrom
Hiiva:fix/shader-layout-metadata
Open

Hiiva wants to merge 1 commit into
ItsNotRexed:mainfrom
Hiiva:fix/shader-layout-metadata

Conversation

@Hiiva

@Hiiva Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Problem

shader_meta(g, asm) currently reads the current PC_TAIL_UBO and F16_HALVES globals. A library caller that retains the generator and emitted module, restores its options, and generates metadata later can therefore record a different layout from the one in the module:

  • A 144-byte push-constant block can be recorded as 128 bytes.
  • A module using the set-1 PC-tail uniform block can lose that descriptor metadata.
  • The emitted f16-half location mapping can disappear, or a mesh-compute mapping can be invented after enabling the option for another shader.

This affects delayed or interleaved library API metadata generation. The stock CLI indexes immediately while its options are stable and does not trigger this failure.

Claim: #5256 (comment)
Item: BUILD-1706.

Change

Record the two layout options on the generator when assemble() emits the module, and use those recorded values in shader_meta(). Initialize the fields in Gen as well to preserve metadata queries on manually constructed generators. The emitted shader instructions and declarations are unchanged.

The new tests translate complete synthetic CS, VS, PS, native mesh, and mesh-compute modules. They cover both option directions, absence of tail reads, interleaved generators, preserved f16 locations, and the mesh-compute slot/PC-tail layout.

Validation

The GPU check creates pipelines only. It does not claim dispatch results or testing on a device limited to 128-byte push constants. Vulkan SDK 1.4.363.0; Python 3.14.6; isolated LLVM 21.1.8 AMDGPU tools for the existing fixture tests. Synthetic inputs only, no game files. AI-assisted.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested da093a8 on Windows 11 with NVIDIA GeForce RTX 4090 (driver 32.0.16.2101) and AMD Radeon(TM) Graphics (driver 32.0.21043.5001): pass.

I used the synthetic compute shader from test_shader_layout_metadata.py. I translated it once with the PC-tail uniform block enabled and once with it disabled. For each module, I reversed the option before I generated the metadata. I assembled each module with spirv-as --target-env vulkan1.2. I ran vk_pipeline_check <fixture-dir> --jobs 1 with the Khronos validation layer on each adapter.

Each GPU created both compute pipelines. Each run reported zero failures, zero skips, and no validation messages with a VUID. With the translator from merge base 3faac557, the same test reported both VUID-VkComputePipelineCreateInfo-layout-07988 and VUID-VkComputePipelineCreateInfo-layout-10069 on each GPU. This check covers pipeline creation only.

py -3.14 -I tests/semantic/test_shader_layout_metadata.py passed all five tests on the PR. The same file reported 16 subcase failures with the merge-base translator. The related metadata, index, PC-tail, mesh, and interpolation tests passed (131 tests and 98 subtests).

AI-assisted. Synthetic inputs only.

@daemosofchaos

Copy link
Copy Markdown
Contributor

Independent Windows 11 / Python 3.12 synthetic check of da093a8a:

  • 93 tests passed across PC-tail, mesh-compute, shader metadata/index, f16 interpolation and the PR's new layout suite. The latter includes assembly and spirv-val of 12 synthetic modules.
  • I added two reviewer-only checks for manually constructed Gen objects: one changes both options after construction before metadata generation; the other changes the PC-tail option between construction and assemble(), then changes it again before metadata generation. Both pass on this head. Against the unmodified parent 3faac557, those checks reported 10 failing subtests across the two metadata fields. They may be useful regression coverage for the initialization behavior described in the PR.

CPU-only synthetic inputs; no game files or GPU. This checks metadata behavior and module validation, not game rendering. AI-assisted review.

— LocalFirst-AI

@kacper-serewis kacper-serewis 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 independent review. At da093a8 both CPU builds translated and validated 24 cached shaders (eight each VS, PS and MS), with all 49 immediate CLI outputs byte-identical. With emission options alternated and indexing reversed under flipped options, all 24 delayed records matched their immediate records. Push-constant sizes, all nine emitted tail blocks and eight nonempty half-location maps agreed with the assembly. The scratch comparison adapted #5269’s conflicting FMA metadata hunk identically on both sides. Compute coverage came from the synthetic layout suite.

@Kam471 Kam471 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.

Reviewed da093a8

  • python tests/semantic/test_shader_layout_metadata.py -> 5 tests OK.
  • python -I -m pytest tests/test_shader_meta.py tests/test_shader_meta_operands.py tests/test_pc_tail_ubo.py tests/test_shader_index.py tests/test_mesh_compute.py tests/test_fspx_shaders_stage.py tests/test_fssm_wave_size.py -q -> 65 passed, 20 skipped, 14 subtests. The skips are the SDK/llvm fixture cases absent here; the PR saw none.
  • python tests/semantic/test_f16_interp_fallback.py -> 15 OK; python tests/semantic/test_bary_fallback.py -> 12 OK.
  • Negative control: the new test file on 3faac557 -> FAILED (failures=16), so the tests do catch the delayed-metadata bug.
  • git diff --check clean.

Verdict: OK to merge.

@memorypressure

Copy link
Copy Markdown

Checked against main 3faac55: merges clean, the new test_shader_layout_metadata.py is 5/5 under unittest discover, and the closest consumers stay green: test_f16_interp_fallback 15/15 and pytest test_pc_tail_ubo 8/8. I swept the shader_meta range for bare global reads — none remain, and the translate.last_gen library caller is exactly the scenario the fix protects; translator-use guard green. Note: the branch reports no CI checks at all — worth a push. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

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.

6 participants