From 3d6a54f5ff82a8f5447d7b30cf6d48e6c1509a09 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Nov 2026 04:07:21 +0100 Subject: [PATCH 1/2] Shaders: a vertex shader that declares a UAV says so in its flags and 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 (#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. --- apps/victory/src/translate.rs | 9 ++- crates/victory-shader/src/emit/shader.rs | 94 +++++++++++++++++------- 2 files changed, 74 insertions(+), 29 deletions(-) diff --git a/apps/victory/src/translate.rs b/apps/victory/src/translate.rs index 242ea26261..d86b46f7f4 100644 --- a/apps/victory/src/translate.rs +++ b/apps/victory/src/translate.rs @@ -652,6 +652,13 @@ fn check( .find(|l| l.contains("error")) .unwrap_or(text.lines().next().unwrap_or("")) .to_owned(); + // The line after an error says what the validator compared, and + // it is the one that tells you what to fix: "Flags must match + // usage" arrives with a `note: Flags declared=…, actual=…`. + let reason = match text.lines().find(|l| l.contains("note:")) { + Some(note) => format!("{first} ({})", note.trim()), + None => first.clone(), + }; if let Ok(dir) = std::env::var("VICTORY_EMIT_DUMP") { let n = t .failed @@ -670,7 +677,7 @@ fn check( let _ = std::fs::write(format!("{name}.txt"), format!("{}\n{text}", label())); } } - t.fail(format!("validator: {first}"), label); + t.fail(format!("validator: {reason}"), label); } } } diff --git a/crates/victory-shader/src/emit/shader.rs b/crates/victory-shader/src/emit/shader.rs index e68e2627c9..27feb083cb 100644 --- a/crates/victory-shader/src/emit/shader.rs +++ b/crates/victory-shader/src/emit/shader.rs @@ -53,8 +53,35 @@ pub(crate) mod flags { pub const RESOURCE_HEAP: u64 = 1 << 30; pub const SAMPLER_HEAP: u64 = 1 << 31; pub const ATOMIC64_HEAP: u64 = 1 << 32; + /// A vertex (or hull, domain, geometry) shader that declares a UAV: the + /// validator recomputes this from the declarations and refuses the + /// module without it ("Flags must match usage", #1987). Stages that have + /// always been able to hold one — pixel, compute, mesh — do not set it. + pub const UAVS_AT_EVERY_STAGE: u64 = 1 << 16; } +/// The `SFI0` feature-info bits of a module's shader flags, as DXC's +/// `DxilShaderFlags::GetFeatureInfo` computes them (`ShaderFeatureInfo_*`). +pub(crate) fn feature_info(flags: u64) -> u64 { + let mut features = 0u64; + for (flag, feature) in [ + (flags::STENCIL_REF, 0x200), + (flags::TYPED_UAV_LOADS, 0x800), + (flags::UAVS_AT_EVERY_STAGE, 0x4), + (flags::ROVS, 0x1000), + (flags::WAVE_OPS, 0x4000), + (flags::INT64, 0x8000), + (flags::RESOURCE_HEAP, 0x200_0000), + (flags::SAMPLER_HEAP, 0x400_0000), + (flags::ATOMIC64_TYPED, 0x40_0000), + (flags::ATOMIC64_HEAP, 0x1000_0000), + ] { + if flags & flag != 0 { + features |= feature; + } + } + features +} pub(crate) struct Types { pub void: Ty, pub i1: Ty, @@ -793,6 +820,16 @@ impl Shader { if self.pixel && self.outputs.iter().any(|o| o.kind == 20) { self.flags |= flags::STENCIL_REF; } + // A stage that traditionally had no UAVs, declaring one: the write + // marking is what put one in a vertex shader (#1987). + if !self.pixel + && self.threads.is_none() + && self.mesh.is_none() + && self.gs.is_none() + && (self.view_writes.is_some() || !self.root_uavs.is_empty()) + { + self.flags |= flags::UAVS_AT_EVERY_STAGE; + } // Entry properties: shader flags (tag 0), thread-group size (4), // wave size (11). let mut props = Vec::new(); @@ -878,34 +915,7 @@ impl Shader { dxil.extend((bitcode.len() as u32).to_le_bytes()); dxil.extend(&bitcode); - let mut features = 0u64; - if self.flags & flags::STENCIL_REF != 0 { - features |= 0x200; - } - if self.flags & flags::TYPED_UAV_LOADS != 0 { - features |= 0x800; - } - if self.flags & flags::ROVS != 0 { - features |= 0x1000; - } - if self.flags & flags::WAVE_OPS != 0 { - features |= 0x4000; - } - if self.flags & flags::INT64 != 0 { - features |= 0x8000; - } - if self.flags & flags::RESOURCE_HEAP != 0 { - features |= 0x200_0000; - } - if self.flags & flags::SAMPLER_HEAP != 0 { - features |= 0x400_0000; - } - if self.flags & flags::ATOMIC64_TYPED != 0 { - features |= 0x40_0000; - } - if self.flags & flags::ATOMIC64_HEAP != 0 { - features |= 0x1000_0000; - } + let features = feature_info(self.flags); let sfi0 = features.to_le_bytes(); let isg1 = container::signature(&self.inputs, true); let osg1 = container::signature(&self.outputs, false); @@ -986,3 +996,31 @@ impl Shader { Some(self.m.md_node(list)) } } +#[cfg(test)] +mod tests { + use super::*; + + /// The feature part has to say what the module's flags say, or the + /// validator rejects the container ("Container part 'Feature Info' does + /// not match expected for module", #1987). The bit values are DXC's + /// `ShaderFeatureInfo_*`. + #[test] + fn the_feature_bits_follow_the_shader_flags() { + assert_eq!(feature_info(0), 0); + assert_eq!(feature_info(flags::UAVS_AT_EVERY_STAGE), 0x4); + assert_eq!(feature_info(flags::STENCIL_REF), 0x200); + assert_eq!(feature_info(flags::TYPED_UAV_LOADS), 0x800); + assert_eq!(feature_info(flags::ROVS), 0x1000); + assert_eq!(feature_info(flags::WAVE_OPS), 0x4000); + assert_eq!(feature_info(flags::INT64), 0x8000); + assert_eq!(feature_info(flags::ATOMIC64_TYPED), 0x40_0000); + assert_eq!(feature_info(flags::RESOURCE_HEAP), 0x200_0000); + assert_eq!(feature_info(flags::SAMPLER_HEAP), 0x400_0000); + assert_eq!(feature_info(flags::ATOMIC64_HEAP), 0x1000_0000); + assert_eq!( + feature_info(flags::RAW_BUFFERS | flags::UAVS_AT_EVERY_STAGE), + 0x4, + "raw buffers alone carry no feature bit" + ); + } +} From ad50733a2c9c1d80a571fdda1a43e473b97fbbac Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Nov 2026 05:59:05 +0100 Subject: [PATCH 2/2] Shaders: a vertex shader that declares a UAV says so in its flags and 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 (#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 #1767's, which is where it belongs: this change is only what the modules declare. --- apps/victory/src/translate.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/apps/victory/src/translate.rs b/apps/victory/src/translate.rs index d86b46f7f4..242ea26261 100644 --- a/apps/victory/src/translate.rs +++ b/apps/victory/src/translate.rs @@ -652,13 +652,6 @@ fn check( .find(|l| l.contains("error")) .unwrap_or(text.lines().next().unwrap_or("")) .to_owned(); - // The line after an error says what the validator compared, and - // it is the one that tells you what to fix: "Flags must match - // usage" arrives with a `note: Flags declared=…, actual=…`. - let reason = match text.lines().find(|l| l.contains("note:")) { - Some(note) => format!("{first} ({})", note.trim()), - None => first.clone(), - }; if let Ok(dir) = std::env::var("VICTORY_EMIT_DUMP") { let n = t .failed @@ -677,7 +670,7 @@ fn check( let _ = std::fs::write(format!("{name}.txt"), format!("{}\n{text}", label())); } } - t.fail(format!("validator: {reason}"), label); + t.fail(format!("validator: {first}"), label); } } }