List a constant-step attribute among the instanced ones

Content: the tree of `development` at aa9db9b9d9, unchanged.
This commit is contained in:
Anees Iqbal committed 2026-10-26 13:19:21 +02:00
1 parent 709049b45a
commit c701549ed4
3 files changed
+28 -8

No files matched your search

+1 -1
View File
@@ -60,7 +60,7 @@ mod tests;
/// unchanged version, and its bless records the version. Independent of the crate's version and of
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
/// history.
pub const SEMANTICS_VERSION: u32 = 1865;
pub const SEMANTICS_VERSION: u32 = 1866;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
+19 -4
View File
@@ -2125,9 +2125,18 @@ pub(crate) fn depth16_stage_form(
}
/// The attributes the vertex function `spec` fetches in fixed function under `inputs` from
/// layouts `desc` steps per instance, where taking them so makes it write some varying the same
/// at every vertex of a primitive (`LoweringInputs::instanced_attributes`); else none, and the
/// function keeps the key of any step.
/// layouts `desc` steps per instance or at a constant step, where taking them so makes it write
/// some varying the same at every vertex of a primitive
/// (`LoweringInputs::instanced_attributes`); else none, and the function keeps the key of any
/// step.
///
/// A constant step is in that set because it is the stronger statement of the same thing: the
/// fetch reads the layout's first element for every vertex and every instance, so a varying it
/// makes is alike at every vertex of a primitive as surely as a per-instance one's is. It needs
/// saying here only since the step became a fixed-function binding (`metal::vertex::fetch_as`
/// answers a divisor of 0): a pulled constant-step fetch reads element 0 in the shader, where the
/// uniformity is already plain, so this listing is what keeps the two fetch paths writing the
/// same varyings flat.
fn instanced_attributes(
spec: &air::Entry,
inputs: &LowerInputs,
@@ -2150,7 +2159,13 @@ fn instanced_attributes(
desc.attributes
.get(a)
.and_then(|attr| desc.layouts.get(&attr.buffer_index))
.is_some_and(|l| l.step_function == crate::metal::VertexStepFunction::PerInstance)
.is_some_and(|l| {
matches!(
l.step_function,
crate::metal::VertexStepFunction::PerInstance
| crate::metal::VertexStepFunction::Constant
)
})
})
.map(|(a, _)| *a)
.collect();
@@ -247,7 +247,11 @@ fn fixed_function(inputs: &LoweringInputs) -> bool {
/// it steps per instance or at a constant step), never one of the vertex or of device memory;
/// the pipeline's key gives the fragment function those it interpolates, and the compile reads
/// them flat, where its key and the compiled pipeline's agree. A fixed-function attribute
/// stepped per instance is in the vertex function's key exactly where it makes a varying alike.
/// stepped per instance or at a constant step is in the vertex function's key exactly where it
/// makes a varying alike; a pulled one is not, because its element index is already a constant in
/// the shader. So the key moves with the device: the constant step is a fixed-function binding on
/// `nvidia-rtx5080-laptop` and `amd-780m-radv` and pulled on `lavapipe` and `moltenvk-m3`, and the
/// varyings written alike are the same set either way.
#[test]
fn a_fragment_reads_flat_what_its_vertex_function_writes_alike_at_every_vertex() {
let Some(bc) = module() else {
@@ -274,8 +278,9 @@ fn a_fragment_reads_flat_what_its_vertex_function_writes_alike_at_every_vertex()
.render_variant_key(&d, &VariantKey::new(), &budget, &StageEntries::new())
.unwrap_or_else(|e| panic!("{what}: {e}"));
let vertex_inputs = k.vertex_inputs.clone().expect("vertex inputs");
let instanced =
step == VertexStepFunction::PerInstance && fixed_function(&vertex_inputs);
// A constant step makes an attribute alike at every vertex as a per-instance step
// does, so both are listed where the device fetches them in fixed function.
let instanced = stepped && fixed_function(&vertex_inputs);
assert_eq!(
vertex_inputs.instanced_attributes,
if instanced {