From 0dc56519c9d4d89a1a46603265ee7e067797be75 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 20 Nov 2026 20:36:42 -0800 Subject: [PATCH] translator: the identity domains push a render pass's length to a vertex function that writes its slice Under the identity domains a vertex function that writes [[render_target_array_index]] was refused as IdentityDomains (an encoder value the function reads as RenderTargetArrayLength): the field was not among the encoder values those domains push. The runtime now fills it (the pass's length, at least 1, rt's FieldValue::RenderTargetArrayLength), so the field joins the admitted pushed values, beside AlphaTestReference and FetchedColor; nothing else of the form changes. Found by the runtime's layered device test, which refused rt6_layered on every GPU leg at 912548d4db (m3-max-61476, 61477, 61478, 61480, 61481, 61486, 61490) and on lavapipe (61482). SEMANTICS_VERSION 2235, one above development's 2234 (placeholder): such a vertex function now compiles where it was refused. lower/select.rs and cache/mod.rs are not among validation's runtime inputs, so runtime-sources.sha256 and RUNTIME_VERSION stay. A test pins the form on lavapipe's profile (engine_identity_render), and docs/API.md names the pushed length. --- crates/metal2vulkan/src/cache/mod.rs | 2 +- crates/metal2vulkan/src/lower/select.rs | 7 ++- .../src/tests/engine_identity_render.rs | 61 +++++++++++++++++++ docs/API.md | 5 +- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index bdf51ddf6..d69041920 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -61,7 +61,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 = 2234; +pub const SEMANTICS_VERSION: u32 = 2235; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another diff --git a/crates/metal2vulkan/src/lower/select.rs b/crates/metal2vulkan/src/lower/select.rs index 982d7c17c..16a21f124 100644 --- a/crates/metal2vulkan/src/lower/select.rs +++ b/crates/metal2vulkan/src/lower/select.rs @@ -1932,9 +1932,11 @@ fn identity_unsourced(f: &RuntimeFact) -> bool { /// control points and patches, and a plain vertex function's layouts that a pulled-vertex-buffer /// variant or the de-indexed and private list forms pull; the render encoder's alpha test /// reference code a fragment function under the private alpha test compares with -/// (`PushField::AlphaTestReference`); and the index of the sampled-texture array's element a +/// (`PushField::AlphaTestReference`); the index of the sampled-texture array's element a /// fragment function reads a colour attachment through (`PushField::FetchedColor`, framebuffer -/// fetch on a device with neither ordered form). Its fields past the push window are a parameter block, whose +/// fetch on a device with neither ordered form); and the render pass's length, at or past which a +/// vertex function that writes `[[render_target_array_index]]` stores `Layer` 0 +/// (`PushField::RenderTargetArrayLength`). Its fields past the push window are a parameter block, whose /// address the window holds. Its refusal names the first form the plan holds that they do not /// lower ([`identity_refusal`]). fn identity_admits(plan: &Plan) -> Result<(), Error> { @@ -1976,6 +1978,7 @@ fn identity_refusal(plan: &Plan) -> Option { | PushField::VertexBufferStride(_) | PushField::AlphaTestReference | PushField::FetchedColor { .. } + | PushField::RenderTargetArrayLength ), }); if let Some(f) = field { diff --git a/crates/metal2vulkan/src/tests/engine_identity_render.rs b/crates/metal2vulkan/src/tests/engine_identity_render.rs index fee630512..f4f57ad21 100644 --- a/crates/metal2vulkan/src/tests/engine_identity_render.rs +++ b/crates/metal2vulkan/src/tests/engine_identity_render.rs @@ -24,6 +24,12 @@ //! of the position's layout pulls it through the slot's pushed address at the layout's pushed //! stride (`VertexBufferStride`); the de-indexed and private list forms stay refused. //! +//! - On `Device::from_queries`' profile of lavapipe, which enables `shaderOutputLayer`, a vertex +//! function that writes `[[render_target_array_index]]` (the owned fixture `engine/rt6_layered`'s +//! `rt6_layered_vertex`, which reads it from `constant` memory at its instance) compiles in its +//! one form: it pushes the pass's length (`RenderTargetArrayLength`) in its window, depends on +//! `RuntimeFact::RenderTargetArrayLength` with no dropped layer, and declares `Layer`. +//! //! `llvm-as` assembles the fixture; a missing tool skips visibly. No GPU is used. use crate::budget::Budget; @@ -37,6 +43,7 @@ use crate::pipeline::descriptor::{ ColorAttachmentDescriptor, FunctionDescriptor, RenderPipelineDescriptor, StageSource, VertexAttributeDescriptor, VertexBufferLayoutDescriptor, VertexDescriptor, }; +use crate::pipeline::facts::RuntimeFact; use crate::pipeline::interface::PushLoc; use crate::pipeline::sym::{PushField, SlotClass, SlotRef, Stage}; use crate::pipeline::testing::{description, engine_dir, llvm_assemble, AssembleError}; @@ -81,6 +88,60 @@ fn descriptor(library: &Library) -> RenderPipelineDescriptor { d } +/// Under the identity domains on lavapipe's profile, `rt6_layered_vertex` pushes the pass's +/// length in its window, depends on it with no dropped layer and declares `Layer`, beside +/// `rt6_layered_fragment`, which reads the index as written; both modules pass L3. +#[test] +fn from_queries_pushes_the_pass_s_length_to_a_vertex_function_that_writes_its_slice() { + let ll = engine_dir().join("rt6_layered.ll"); + let library = match llvm_assemble(&ll) { + Ok(bitcode) => Library::from_air(&bitcode).expect("the library"), + Err(AssembleError::Missing(why)) => { + eprintln!("SKIPPED: {why}"); + return; + } + Err(e) => panic!("{}: {e:?}", ll.display()), + }; + let function = |name| { + StageSource::Function(FunctionDescriptor::new( + library.function(name).expect("the function"), + )) + }; + let mut d = RenderPipelineDescriptor::new(function("rt6_layered_vertex")); + d.fragment = Some(function("rt6_layered_fragment")); + d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::R32Uint)); + let desc = description("lavapipe").unwrap_or_else(|e| panic!("{e}")); + let device = Device::from_queries(desc, identity()).unwrap_or_else(|e| panic!("{e}")); + assert!( + (device.profile().enabled().features).contains(&VkFeature::ShaderOutputLayer), + "lavapipe's profile enables shaderOutputLayer" + ); + let p = (device.compile_render_pipeline(&d, &Budget::standard())) + .unwrap_or_else(|e| panic!("lavapipe: {e:?}")); + let vertex = &p.interface.push[0]; + assert_eq!(vertex.stage, Stage::Vertex); + assert!( + (vertex.fields.iter()).any(|f| f.field == PushField::RenderTargetArrayLength + && matches!(f.loc, PushLoc::Push { .. })), + "the vertex function pushes the pass's length in its window" + ); + assert!( + (p.dependencies.iter()).any(|dependency| dependency.fact + == RuntimeFact::RenderTargetArrayLength { + layer_dropped: false + }), + "the vertex function depends on the length, its layer kept" + ); + assert!( + p.graphics.declares_layer, + "the vertex function declares Layer" + ); + for stage in &p.stages { + check_words_valid(&stage.spirv, &p.requirements, device.profile()) + .unwrap_or_else(|e| panic!("lavapipe: {:?}: {e}", stage.stage)); + } +} + #[test] fn from_queries_lowers_a_vertex_function_over_its_pushed_buffer_addresses() { let Some(library) = library() else { diff --git a/docs/API.md b/docs/API.md index e242ad2b2..2eb13310a 100644 --- a/docs/API.md +++ b/docs/API.md @@ -206,7 +206,10 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`: its position (its own sample where the pass is multisampled), level 0, the sampled-texture array's element at the index the consumer pushes for that attachment (`PushField::FetchedColor { color, texels }`, `texels` the read's numeric class), and a - read-only signed-integer attachment joins `signed_color_attachments`. Every precision note is + read-only signed-integer attachment joins `signed_color_attachments`. A vertex function that + writes `[[render_target_array_index]]` compiles in the variant that writes `Layer`, which stores + 0 for an index at or past the render pass's length the consumer pushes + (`PushField::RenderTargetArrayLength`, `renderTargetArrayLength` at least 1). Every precision note is static there: no constant or binder decides one. So far they lower a kernel that reaches memory through its buffer slots and the device addresses it loads (an argument buffer's pointer member, a stored `gpuAddress`) or makes from integers, and reads, writes, sizes or tests for nil