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