From d00c32ecf63578ee6d42a1f92cc903fee2accda5 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 21 Nov 2026 00:16:12 -0800 Subject: [PATCH] translator: the identity domains push the draw's viewport count to a vertex function that selects its viewport Under the identity domains a vertex function that writes [[viewport_array_index]] was refused as IdentityDomains (an encoder value the function reads as ViewportCount): the field was not among the encoder values those domains push. The runtime fills it per draw (the encoder's viewport count, 99e5d42deb), so the field joins the admitted pushed values beside RenderTargetArrayLength; nothing else of the form changes. Found by 99e5d42deb's suite (m3-max-62168), whose viewports device test the translator refused. SEMANTICS_VERSION 2250, one above development's 2249: 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: rt6_viewports' rt6_select pushes ViewportCount in its window, depends on RuntimeFact::ViewportCount and stores ViewportIndex under shaderOutputViewportIndex; both modules L3), and docs/API.md names the pushed count. --- crates/metal2vulkan/src/cache/mod.rs | 2 +- crates/metal2vulkan/src/lower/select.rs | 14 +++-- .../src/tests/engine_identity_render.rs | 60 +++++++++++++++++++ docs/API.md | 4 +- 4 files changed, 72 insertions(+), 8 deletions(-) diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 26a7c2b0a..128b0ef02 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 = 2249; +pub const SEMANTICS_VERSION: u32 = 2250; /// 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 4569fee86..5350b533f 100644 --- a/crates/metal2vulkan/src/lower/select.rs +++ b/crates/metal2vulkan/src/lower/select.rs @@ -1923,13 +1923,14 @@ fn identity_unsourced(f: &RuntimeFact) -> bool { /// reference code a fragment function under the private alpha test compares with /// (`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); and the render pass's length, at or past which a +/// fetch on a device with neither ordered form); the render pass's length, at or past which a /// vertex function that writes `[[render_target_array_index]]` stores `Layer` 0 -/// (`PushField::RenderTargetArrayLength`); and the address of the runtime's memory that holds a -/// kernel's private arena past the floor (`PushField::PrivateArenaAddress`). 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`]). +/// (`PushField::RenderTargetArrayLength`); the address of the runtime's memory that holds a +/// kernel's private arena past the floor (`PushField::PrivateArenaAddress`); and the draw's +/// viewport count, at or past which a vertex function that writes `[[viewport_array_index]]` stores +/// `ViewportIndex` 0 (`PushField::ViewportCount`). 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> { match identity_refusal(plan) { None => Ok(()), @@ -1971,6 +1972,7 @@ fn identity_refusal(plan: &Plan) -> Option { | PushField::FetchedColor { .. } | PushField::RenderTargetArrayLength | PushField::PrivateArenaAddress + | PushField::ViewportCount ), }); 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 f4f57ad21..cd7dd72c1 100644 --- a/crates/metal2vulkan/src/tests/engine_identity_render.rs +++ b/crates/metal2vulkan/src/tests/engine_identity_render.rs @@ -29,6 +29,12 @@ //! `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`. +//! - On `Device::from_queries`' profile of lavapipe, which enables `multiViewport` and +//! `shaderOutputViewportIndex`, a vertex function that writes `[[viewport_array_index]]` (the +//! owned fixture `engine/rt6_viewports`'s `rt6_select`, which selects its instance's viewport) +//! compiles in its one form: it pushes the draw's viewport count (`ViewportCount`) in its window, +//! depends on `RuntimeFact::ViewportCount`, and stores `ViewportIndex` under +//! `shaderOutputViewportIndex`. //! //! `llvm-as` assembles the fixture; a missing tool skips visibly. No GPU is used. @@ -626,3 +632,57 @@ fn pulls_at_pushed_strides( .unwrap_or_else(|e| panic!("{stem}: {form}: {:?}: {e}", stage.stage)); } } + +/// Under the identity domains on lavapipe's profile, `rt6_select` pushes the draw's viewport count +/// in its window, depends on it and stores `ViewportIndex`, beside `rt6_viewport_read`, which reads +/// the index; both modules pass L3. +#[test] +fn from_queries_pushes_the_viewport_count_to_a_vertex_function_that_selects_its_viewport() { + let ll = engine_dir().join("rt6_viewports.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_select")); + d.fragment = Some(function("rt6_viewport_read")); + d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm)); + let desc = description("lavapipe").unwrap_or_else(|e| panic!("{e}")); + let device = Device::from_queries(desc, identity()).unwrap_or_else(|e| panic!("{e}")); + let enabled = &device.profile().enabled().features; + assert!( + enabled.contains(&VkFeature::MultiViewport) + && enabled.contains(&VkFeature::ShaderOutputViewportIndex), + "lavapipe's profile enables multiViewport and shaderOutputViewportIndex" + ); + 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::ViewportCount && matches!(f.loc, PushLoc::Push { .. })), + "the vertex function pushes the draw's viewport count in its window" + ); + assert!( + (p.dependencies.iter()).any(|dependency| dependency.fact == RuntimeFact::ViewportCount), + "the vertex function depends on the viewport count" + ); + assert!( + p.graphics.writes_viewport_index + && (p.requirements.features).contains(&VkFeature::ShaderOutputViewportIndex), + "the vertex function stores ViewportIndex under shaderOutputViewportIndex" + ); + for stage in &p.stages { + check_words_valid(&stage.spirv, &p.requirements, device.profile()) + .unwrap_or_else(|e| panic!("lavapipe: {:?}: {e}", stage.stage)); + } +} diff --git a/docs/API.md b/docs/API.md index d575aa0e7..fbbee2438 100644 --- a/docs/API.md +++ b/docs/API.md @@ -209,7 +209,9 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`: 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). A kernel without a + (`PushField::RenderTargetArrayLength`, `renderTargetArrayLength` at least 1), and one that writes + `[[viewport_array_index]]` stores `ViewportIndex` 0 for an index at or past the draw's viewport + count the consumer pushes (`PushField::ViewportCount`). A kernel without a call stack whose private bytes pass the 16 KiB floor every device holds keeps its private memory in the consumer's device memory: every alloca it indexes at run time is in its private arena, whose words for an invocation are the slot of `RuntimeFact::PrivateArena { slot_bytes }` (the