From d6c110338d46d6293d7acdcaf74a93163e37a496 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 21 Nov 2026 00:28:14 -0800 Subject: [PATCH] rt: a translator's viewport and scissor dynamic states are the pipeline's with-count states The viewports' piece made the pipeline's viewports and scissors dynamic with their count (VIEWPORT_WITH_COUNT, SCISSOR_WITH_COUNT), but render.rs still compared the translator's dynamic states (VIEWPORT, SCISSOR) with that list one for one, so every render pipeline state was RenderPipelineKind::DynamicState (m3-max-62168, at 99e5d42deb). The ash form of a translator state now maps VIEWPORT and SCISSOR to their with-count states, which the pipeline holds in their place (VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-04132 and -04133 forbid both forms). The translator's tests of target indices (engine_target_indices) that read runtime-floor as a device without multiViewport now take it below the floor, without multiViewport and shaderOutputViewportIndex, which the floor now requires: the raw viewport index alone, and a fragment function's read of a viewport no stage writes, which reads 0 only where the device cannot declare ViewportIndex (with multiViewport it declares the input). The same fix was made to engine_selected_indices before development deleted that file (3ecf606aa8). --- crates/metal2vulkan-runtime/src/render.rs | 10 ++++++++-- .../src/tests/engine_target_indices.rs | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index f82afcd60..ac054d98b 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -814,9 +814,15 @@ fn unbuilt(pipeline: &RenderPipeline, enabled: &EnabledCaps) -> Option vk::DynamicState { - vk::DynamicState::from_raw(state.as_raw()) + match vk::DynamicState::from_raw(state.as_raw()) { + vk::DynamicState::VIEWPORT => vk::DynamicState::VIEWPORT_WITH_COUNT, + vk::DynamicState::SCISSOR => vk::DynamicState::SCISSOR_WITH_COUNT, + other => other, + } } impl Fixed { diff --git a/crates/metal2vulkan/src/tests/engine_target_indices.rs b/crates/metal2vulkan/src/tests/engine_target_indices.rs index 395fdcbb2..ac6be539d 100644 --- a/crates/metal2vulkan/src/tests/engine_target_indices.rs +++ b/crates/metal2vulkan/src/tests/engine_target_indices.rs @@ -193,13 +193,16 @@ fn a_uniform_viewport_takes_the_output_or_goes_nowhere() { needs(F::ShaderOutputViewportIndex), "multiViewport without the output", ); - // Without `multiViewport`, on the floor too: the raw index alone. + // Without `multiViewport`, below the floor too, which requires it: the raw index alone. for dev in [ device( "lavapipe", &[F::ShaderOutputViewportIndex, F::MultiViewport], ), - device("runtime-floor", &[]), + device( + "runtime-floor", + &[F::ShaderOutputViewportIndex, F::MultiViewport], + ), ] { let (outputs, builtins) = vertex_io(&bc, "rt6_select", &dev); assert_eq!(outputs, [IoRole::ViewportIndex], "{builtins:?}"); @@ -267,10 +270,11 @@ fn indices_that_differ_among_a_primitive_s_vertices_are_refused() { } /// A fragment function that reads the slice or viewport no stage writes reads 0 on a device that -/// cannot declare the builtin, which it lists: the viewport on the floor, and the slice on the -/// floor without its `shaderOutputLayer`. +/// cannot declare the builtin, which it lists: below the floor, the viewport without +/// `multiViewport` and `shaderOutputViewportIndex`, and the slice without `shaderOutputLayer`, +/// each of which the floor requires. #[test] -fn on_the_floor_a_read_of_an_index_no_stage_writes_is_zero() { +fn below_the_floor_a_read_of_an_index_no_stage_writes_is_zero() { let Some(amp) = assemble("vertex_amplification.ll") else { return; }; @@ -283,7 +287,10 @@ fn on_the_floor_a_read_of_an_index_no_stage_writes_is_zero() { ( "amp_fragment", vec![StageBuiltin::ViewportIndex], - device("runtime-floor", &[]), + device( + "runtime-floor", + &[F::ShaderOutputViewportIndex, F::MultiViewport], + ), ), ] { let a = compile(&, entry, floor.profile()).unwrap_or_else(|e| panic!("{entry}: {e}"));