Skip to content

Shaders: a vertex shader that declares a UAV says so in its flags and SFI0 (fixes #1987) - #2016

Open
fiestorra wants to merge 2 commits into
Marvisak:mainfrom
fiestorra:fix/vertex-uav-flag
Open

fiestorra wants to merge 2 commits into
Marvisak:mainfrom
fiestorra:fix/vertex-uav-flag

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

Fixed: the missing bit was "UAVs at every shader stage" (16) plus its feature bit (0x4), and the corpus is back to 24,785

The sentence I was missing last round was in the validator's own message, which translate was throwing away:

error: Flags must match usage. (note: Flags declared=1075314704, actual=1075380240)

actual - declared = 65536 = 1 << 16, on every one of the 868. Bit 16 of the shader flags is documented in DXIL.rst as "UAVs at every shader stage — set when a vertex, hull, domain, or geometry shader declares one or more UAVs". The write marking put a UAV into vertex programs that never had one, and the emitter never set the flag.

Declaring the flag alone is not enough: the validator then compares the container's SFI0 with the module's flags, and the next error is Container part 'Feature Info' does not match expected for module. DXC's DxilShaderFlags::GetFeatureInfo maps bit 16 to ShaderFeatureInfo_UAVsAtEveryStage = 0x0004, so that bit goes with it.

Three measured steps over the same local 1.0.2.1 archive (26,503 containers), validator SDK 10.0.26100 dxil.dll 1.9:

change Flags must match usage Feature Info validated
none (main 940d32f) 871 0 23,918
flag 16 only 0 867 23,918
flag 16 and feature 0x4 0 0 24,785

24,785 is the count the parent commit ccfb029 had, so the 868 VfxVBuffer vertex programs are back to validating and nothing else moved.

Two things came with it, because without them this would not have been findable:

  • translate --validate keeps the validator's note: line, appended to the error it already reported. The old line said "Flags must match usage" and nothing else; the note says which flag, which is the difference between four rounds of guessing and a one-line fix.
  • the flags-to-SFI0 mapping moved out of finish into feature_info, with a test that pins every bit against DXC's values (STENCIL_REF 0x200, TYPED_UAV_LOADS 0x800, UAVS_AT_EVERY_STAGE 0x4, ROVS 0x1000, WAVE_OPS 0x4000, INT64 0x8000, ATOMIC64_TYPED 0x400000, RESOURCE_HEAP 0x2000000, SAMPLER_HEAP 0x4000000, ATOMIC64_HEAP 0x10000000). That pair is what broke here, and a table is cheaper to check than a chain of ifs in a 900-line function.

Recipe: cargo test -p victory-shader --locked --lib 248 passed, 3 ignored; cargo test --workspace --locked 26 suites with the one failure main also has in a session without a desktop (lifecycle::tests::showing_a_title_window_shows_its_stand_in); clippy --workspace --all-targets with and without --all-features clean under -D warnings; rustfmt --check with the same two hunks main already has in shader.rs and no others (I reverted the two unrelated lines rustfmt wanted to reflow, so the diff carries no formatting churn).

What this does not do: it does not make the marking cheaper or change what it marks — the flag is a declaration of what the module already does. And it does not touch the 735 programs refused for "entry function performs some operation that is incompatible with the shader stage" or the 195 with "an address in an SGPR that is no root parameter"; those are separate families with their own causes.

No game data is involved: flag values, counts and error text.

Written with an AI assistant.

… SFI0

The write marking added on 2026-11-25 puts a UAV into programs that never had
one, and the validator recomputes the shader flags from what a module
declares: a vertex shader holding a UAV must carry ShaderFlags bit 16
("UAVs at every shader stage", DXIL.rst) or it is refused with "Flags must
match usage". Declaring the module flag is not enough on its own - the
feature part has to agree, or the next error is "Container part 'Feature
Info' does not match expected for module" - so the SFI0 bit 0x4
(ShaderFeatureInfo_UAVsAtEveryStage) goes with it.

The flags-to-feature mapping moves out of `finish` into `feature_info`, which
is what makes the pair testable, and a test pins every bit against DXC's
values.

Measured on the offline census over a local 1.0.2.1 shader archive (26,503
containers), validator = SDK 10.0.26100 dxil.dll 1.9:

  before  Flags must match usage        871, validated 23,918
  flags   Feature Info instead of it    867, validated 23,918
  both    neither                          0, validated 24,785

i.e. the 868 VfxVBuffer vertex programs that cd94d35 cost (Marvisak#1987) validate
again, and the corpus is back to the parent commit's count.

`translate --validate` also keeps the validator's `note:` line now, because
"Flags must match usage" comes with "note: Flags declared=..., actual=..."
and that pair is what identifies the missing bit; without it the reason was
one line that said nothing about which flag.
@Yoshi-233

Copy link
Copy Markdown

I reproduced the flags mismatch with a small synthetic vertex shader on native Linux, independently of the title corpus. I supplied an SV_Position output signature and ran the public emit_with path with a descriptor-table buffer_store_dword and write marking enabled. Linux dxv (DXC build 3f85295c) rejected the base output at 940d32f with:

Flags must match usage.
Flags declared=1073741840, actual=1073807376

At 3d6a54f the same input validated. Its SFI0 changed from 0x02000000 to 0x02000004.

I checked eight combinations in total: vertex/compute × with/without the buffer store × write marking on/off. The other seven containers were byte-for-byte identical between revisions and passed dxv on both. That includes the vertex shader with the same store and write marking off, and the compute shader with marking on. All eight passed on the PR. This checks translation and validator acceptance; there was no GPU dispatch or game input.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 3d6a54f. victory-shader: 245 passed, 3 failed, 3 ignored; the new the_feature_bits_follow_the_shader_flags passes. The 3 are #1744's NVIDIA failures on main (the two stride_tests heap-buffer reads and gathers_at_a_level_match_the_hardware). Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

@Dathinel

Copy link
Copy Markdown
Contributor

I compared this head (3d6a54f) with #1989 (0f11320) using the same Windows SDK 10.0.26100.0 x64 validator. Both fix the marked vertex case. Four synthetic cases distinguish them:

Stage and only UAV binding This PR #1989
Mesh, view-write marks (fixture from #1989) rejected validated
Vertex, dirty-page bitmap rejected validated
Geometry, view-write marks rejected validated
Geometry, dirty-page bitmap rejected validated

The three new cases are emitter tests. Starting from the copy-through vertex shader and rectangle geometry shader in emit/rect.rs, emit one atomicBinOp.i32 (OR, byte offset 0, value 1) through either view_writes_handle() or memory_dirty_handle(), then validate the finished container. All three report flags declared 0x10, actual 0x10010. The same stages without a UAV validate, as do the pixel controls with either binding.

Changing only the predicate in this branch to #1989's stage and binding conditions made all nine emitter cases and all six cases of the earlier stage fixture validate. The missing conditions are geometry/mesh stages and the memory_dirty binding. The CLI change that retains the validator's diagnostic note is separate and could be reviewed on its own.

These are validator results for synthetic shaders. They do not measure how often these cases occur in a title. AI-assisted.

fiestorra added a commit to fiestorra/VIctory that referenced this pull request Nov 25, 2026
`dx.op.sample` takes derivatives, and a compute shader has none: the
validator refuses the module with "Function uses features incompatible with
the shader stage (cs) of the entry function". Measured on the offline census
over a local 1.0.2.1 shader archive (26,503 containers), validator SDK
10.0.26100 dxil.dll 1.9, the class is 735 programs, every one of them a
compute shader, and the ones dumped all carry three uses of the implicit
`sample` next to hundreds of explicit `sampleLevel`:

  billboard_nobump:CS_RaytracingResolve_a56bfb9c_Wrapped   Cs
  cloth_default:CS_RaytracingResolve_b1139868_Wrapped       Cs
  threads (32,1,1), wave 32, no shader flags declared

The console's `image_sample` in that stage has no derivatives to take either,
so level 0 is what it means; emitting `sampleLevel` with 0 keeps the meaning
and makes the module valid.

Census before and after, same archive, same validator:

  before   incompatibles 735, validated 23,918
  after    incompatibles   0, validated 24,653
  stacked on Marvisak#2016 (the vertex UAV flags): 25,520 validated, from 23,918 on main.

The choice of operation is `sample_op`, which is also what the test pins:
`("sampleLevel.f32", 62)` for a compute stage, `("sample.f32", 60)` elsewhere.
@AgneyaK

AgneyaK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

A full-corpus run, so reviewers can compare this with #1989, which fixes the same regression (#1987). Offline translate --validate over the title 1.0.2.1's shader pack, release build, Windows 11 26300, validator DXC 1.9.2602 (the serviced SDK 10.0.26100.0 copy here).

vertex + pixel validated compute mesh Flags must match usage
main 940d32f 13,350 of 14,217 1,961 of 2,696 8,694 of 8,765 867
this PR (3d6a54f) 14,217 of 14,217 1,961 of 2,696 8,694 of 8,765 0
#1989 (0f11320) 14,217 of 14,217 1,961 of 2,696 8,694 of 8,765 0

The same counts and the same remaining refusals (735 compute, 71 mesh) as #1989. On this corpus the two are interchangeable; the difference is in the code (stage predicate, mesh handling, tests).

AI use: Claude Code (Claude Opus 5.5) ran the builds and wrote this; counts only, no game data.

@Calvix2k

Copy link
Copy Markdown
Contributor

Two things before this lands, because there are now two open PRs for the same bit (#1989 and this one):

1. Mesh shaders are still missed. Your condition keeps && self.mesh.is_none(), so a mesh program that declares the view-write UAV does not get the flag. Dathinel's fixture on 940d32f (Windows SDK 10.0.26100 validator, the same engine as the corpus run):

synthetic shader main this predicate #1989
Vertex, view marks enabled fails passes passes
Mesh, view marks enabled fails still fails (Flags declared=0x40000010, expected 0x40010010) passes

graphics && !self.pixel (drop mesh.is_none(); graphics is threads.is_none() || mesh.is_some()) makes all six of their cases pass. I hit the same trap in #1977 — that is why I closed it in favour of #1989.

2. The feature_info table is worth keeping. Mapping the flags to their SFI0 bits in one place instead of the chain of if arms is the better shape, and translate.rs printing the validator's declared/actual note is what let you find this at all. I would keep both even if the flag condition ends up identical to #1989's.

Corpus confirmation from this machine, for the body: 940d32f 23,918 validated / 868 Flags must match usage; the fix makes it 24,785 / 0 (+867, 0 lost), RX 7800 XT, Windows 10, SDK dxil.dll 1.7.

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

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

145 passed / 0 failed / 2 ignored. Vertex shader declaring a UAV says so in flags and SFI0 (+1 test) — mixed apps+shader PR; shader half verified here, apps half Windows-only.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib emit::shader:: — 1 passed, 0 failed (the_feature_bits_follow_the_shader_flags)
  • cargo clippy -p victory-shader -p victory --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean fix setting the UAV shader flags and SFI0 feature info bits for vertex shaders declaring UAVs (fixing #1987 / 867 vertex programs). Looks great.

AI-assisted (Gemini 4 Neon).

fiestorra added a commit to fiestorra/VIctory that referenced this pull request Nov 25, 2026
`dx.op.sample` takes derivatives, and a compute shader has none: the
validator refuses the module with "Function uses features incompatible with
the shader stage (cs) of the entry function". Measured on the offline census
over a local 1.0.2.1 shader archive (26,503 containers), validator SDK
10.0.26100 dxil.dll 1.9, the class is 735 programs, every one of them a
compute shader, and the ones dumped all carry three uses of the implicit
`sample` next to hundreds of explicit `sampleLevel`:

  billboard_nobump:CS_RaytracingResolve_a56bfb9c_Wrapped   Cs
  cloth_default:CS_RaytracingResolve_b1139868_Wrapped       Cs
  threads (32,1,1), wave 32, no shader flags declared

The console's `image_sample` in that stage has no derivatives to take either,
so level 0 is what it means; emitting `sampleLevel` with 0 keeps the meaning
and makes the module valid.

Census before and after, same archive, same validator:

  before   incompatibles 735, validated 23,918
  after    incompatibles   0, validated 24,653
  stacked on Marvisak#2016 (the vertex UAV flags): 25,520 validated, from 23,918 on main.

The choice of operation is `sample_op`, which is also what the test pins:
`("sampleLevel.f32", 62)` for a compute stage, `("sample.f32", 60)` elsewhere.
… SFI0

The write marking added on 2026-11-25 puts a UAV into programs that never had
one, and the validator recomputes the shader flags from what a module
declares: a vertex shader holding a UAV must carry ShaderFlags bit 16
("UAVs at every shader stage", DXIL.rst) or it is refused with "Flags must
match usage". Declaring the module flag is not enough on its own - the
feature part has to agree, or the next error is "Container part 'Feature
Info' does not match expected for module" - so the SFI0 bit 0x4
(ShaderFeatureInfo_UAVsAtEveryStage) goes with it.

The flags-to-feature mapping moves out of `finish` into `feature_info`, which
is what makes the pair testable, and a test pins every bit against DXC's
values.

Measured on the offline census over a local 1.0.2.1 shader archive (26,503
containers), validator = SDK 10.0.26100 dxil.dll 1.9:

  before  Flags must match usage        871, validated 23,918
  flags   Feature Info instead of it    867, validated 23,918
  both    neither                          0, validated 24,785

i.e. the 868 VfxVBuffer vertex programs that cd94d35 cost (Marvisak#1987) validate
again, and the corpus is back to the parent commit's count.

The reporting side of that fix (keeping the validator's `note:` line) is
Marvisak#1767's, which is where it belongs: this change is only what the modules
declare.
@fiestorra

Copy link
Copy Markdown
Contributor Author

Trimmed back to the fix itself: the note handling moved to #1767, and the queue is conflict-free

This pull request no longer touches apps/victory/src/translate.rs. The validator's note: line — which is what made #1987 solvable — is now kept by validator_reason in #1767, which is where the reason-building lives, and my comment there has the detail:

validator: error: Flags must match usage. (note: Flags declared=1074790416, actual=1074855952)

So what is left here is only what the modules declare: the shader flags for a vertex program that holds a UAV, the SFI0 feature bit that has to agree with it, and the feature_info table with its test. The measured effect is unchanged (871 → 0 on Flags must match usage, 23,918 → 24,785 validated, the parent commit's count).

The point of trimming it: keeping the note here as well made #1767 and this conflict in translate.rs in either merge order, for two lines of duplicated code. With it there and not here, I re-ran the merge of all seventeen of my open pull requests onto main 940d32f and every one merges cleanly, in any order I tried — which is the state I wanted the queue in.

Re-checked after the change: cargo test -p victory-shader --locked --lib 248 passed, 3 ignored; clippy --workspace --all-targets with and without --all-features clean under -D warnings; rustfmt --check on shader.rs shows the same 2 hunks main already has and no others.

No game data is involved: flag values, counts and file names.

Written with an AI assistant.

@Calvix2k

Copy link
Copy Markdown
Contributor

The trimmed head still has && self.mesh.is_none() in the flag condition, so the mesh case from Dathinel's fixture still fails:

synthetic shader main this head #1989
Mesh, view marks enabled fails still fails (Flags declared=0x40000010, expected 0x40010010) passes

graphics is already threads.is_none() || mesh.is_some(), so dropping that one clause is the whole change: if graphics && !self.pixel && has_uavs. If there is a reason mesh programs should stay out — a validator limitation or a mesh pipeline that refuses the flag — please say so and I will stop bringing it up; otherwise it is the last correctness gap in this fix, and #2027 inherits it because its branch is stacked on this commit.

Not blocking the nicer feature_info table: that part is good and I hope it lands either here or in #1767.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.
Proposed close.

This duplicates open PR #1989, which fixes the same regression (#1987) more completely and merges cleanly. Both set UAVS_AT_EVERY_STAGE (bit 16) and the matching SFI0 bit 0x4 in crates/victory-shader/src/emit/shader.rs (Shader::finish). The difference is the condition. This head's condition excludes mesh and geometry stages (self.mesh.is_none() && self.gs.is_none()) and does not count the memory_dirty binding. #1989 uses graphics && !self.pixel && has_uavs, with memory_dirty included. Dathinel's and Calvix2k's validator runs on this PR show the mesh, geometry and dirty-bitmap cases still rejected here (Flags declared=0x40000010, expected 0x40010010) and passing with #1989. On the title corpus both give the same counts.

The feature_info table and its test are a reasonable cleanup. They could come back as a small follow-up on top of #1989 once it lands.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.

CI: passing (check).


Generated by Claude Code

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants