From 4efd8cb4e7590cef6622711ebc1474ff6f2e3795 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Mar 2026 16:59:01 +0000 Subject: [PATCH] Fix CI: Move PrimitiveIndex FXC ordering fix to HLSL backend only The previous commit moved PrimitiveIndex to the top of the BuiltIn enum to fix FXC ordering (SV_PrimitiveID must appear before other SVs). However, since BuiltIn derives Ord, this changed the global sort order, breaking DX12 inter-stage variable matching in CTS tests. Fix: Restore PrimitiveIndex to its original enum position and handle the FXC ordering requirement locally in the HLSL backend's InterfaceKey by giving PrimitiveIndex its own sort key between Location and BuiltIn. Co-authored-by: cwfitzgerald <7861353+cwfitzgerald@users.noreply.github.com> --- naga/src/back/hlsl/writer.rs | 4 ++++ naga/src/ir/mod.rs | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/naga/src/back/hlsl/writer.rs b/naga/src/back/hlsl/writer.rs index 4a08e9f18..424a74f13 100644 --- a/naga/src/back/hlsl/writer.rs +++ b/naga/src/back/hlsl/writer.rs @@ -91,6 +91,9 @@ pub(super) struct EntryPointInterface { #[derive(Clone, Eq, PartialEq, PartialOrd, Ord)] enum InterfaceKey { Location(u32), + // FXC doesn't consider SV_PrimitiveID a system value, so it must appear + // before any other SVs in the struct. + PrimitiveIndex, BuiltIn(crate::BuiltIn), Other, } @@ -99,6 +102,7 @@ impl InterfaceKey { const fn new(binding: Option<&crate::Binding>) -> Self { match binding { Some(&crate::Binding::Location { location, .. }) => Self::Location(location), + Some(&crate::Binding::BuiltIn(crate::BuiltIn::PrimitiveIndex)) => Self::PrimitiveIndex, Some(&crate::Binding::BuiltIn(built_in)) => Self::BuiltIn(built_in), None => Self::Other, } diff --git a/naga/src/ir/mod.rs b/naga/src/ir/mod.rs index f63ebf3ae..98b06dffc 100644 --- a/naga/src/ir/mod.rs +++ b/naga/src/ir/mod.rs @@ -401,11 +401,6 @@ pub enum AddressSpace { #[cfg_attr(feature = "deserialize", derive(Deserialize))] #[cfg_attr(feature = "arbitrary", derive(Arbitrary))] pub enum BuiltIn { - // This must be at the top so that it gets sorted to the top. PrimitiveIndex is considered a non SV - // by FXC so it must appear before any other SVs. - /// Read in fragment shaders, written in mesh shaders, read in any and closest hit shaders. - PrimitiveIndex, - /// Written in vertex/mesh shaders, read in fragment shaders Position { invariant: bool }, /// Read in task, mesh, vertex, and fragment shaders @@ -434,6 +429,8 @@ pub enum BuiltIn { PointCoord, /// Read in fragment shaders FrontFacing, + /// Read in fragment shaders, written in mesh shaders, read in any and closest hit shaders. + PrimitiveIndex, /// Read in fragment shaders Barycentric { perspective: bool }, /// Read in fragment shaders