diff --git a/crates/metal2vulkan-validation/src/replay/old_runtime/encoders.rs b/crates/metal2vulkan-validation/src/replay/old_runtime/encoders.rs index 63c4bea03..58978fe66 100644 --- a/crates/metal2vulkan-validation/src/replay/old_runtime/encoders.rs +++ b/crates/metal2vulkan-validation/src/replay/old_runtime/encoders.rs @@ -11,7 +11,8 @@ use crate::replay::value::Value; use metal2vulkan::metal::{BarrierScope, DispatchType, IndexType, RenderStages, ResourceUsage}; use metal2vulkan_runtime::{ BlitCommandEncoder, BlitOption, Buffer, ComputeCommandEncoder, DrawPrimitiveType, - RenderCommandEncoder, ResourceOptions, ResourceRef, ScissorRect, Texture, Viewport, + RenderCommandEncoder, ResourceOptions, ResourceRef, ScissorRect, StoreAction, Texture, + Viewport, }; use std::ops::Range; @@ -497,6 +498,29 @@ impl OldRuntime { self.render(id) .set_fragment_sampler_states(&samplers, None, at) } + "setFragmentSamplerStates:lodMinClamps:lodMaxClamps:withRange:" => { + let samplers = self.samplers(call, 0)?; + let clamps = |at: usize| -> Result, PlayError> { + let clamps = list(call, at)?.iter().map(|value| match value.as_f64() { + Some(clamp) => Ok(clamp as f32), + None => Err(refuse(call, format!("{value} is no clamp"))), + }); + let clamps = clamps.collect::, _>>()?; + match clamps.len() == samplers.len() { + true => Ok(clamps), + false => Err(refuse(call, "clamps of another count than the samplers")), + } + }; + let (mins, maxes) = (clamps(1)?, clamps(2)?); + let at = first(call, 3, samplers.len())?; + let samplers: Vec<_> = samplers.iter().map(Option::as_ref).collect(); + (self.render(id)).set_fragment_sampler_states(&samplers, Some((&mins, &maxes)), at) + } + "setColorStoreAction:atIndex:" => { + let action = StoreAction::from_raw(uint(call, 0)?).map_err(failed(call))?; + let at = index(call, 1)?; + self.render(id).set_color_store_action(action, at) + } "setViewport:" => { let known = ["originX", "originY", "width", "height", "znear", "zfar"]; let f = Fields::arg(call, 0, &known)?; diff --git a/crates/metal2vulkan-validation/src/runtime_lane/replay_streams.rs b/crates/metal2vulkan-validation/src/runtime_lane/replay_streams.rs index 748877b86..dc7e31b7e 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/replay_streams.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/replay_streams.rs @@ -18,6 +18,8 @@ //! - A view made through a swizzle, by the public call and by Apple's private one at a resource //! index, is sampled through it. //! - A blit's generated mipmaps fill a texture's levels below its first. +//! - A store action an encoder sets over its pass's unknown one stores the pass's clear, with +//! fragment samplers bound with LOD clamps. //! //! Each device takes its queue plan ([`at_plan`]): the player's readbacks take a command queue of //! their own beside the stream's. @@ -989,3 +991,66 @@ fn a_blit_s_generated_mipmaps_fill_the_levels_below_the_first() { } }); } + +/// A pass whose colour attachment's store action is unknown until its encoder sets it: the +/// encoder binds two fragment samplers with LOD clamps, sets the store action to store, and the +/// cleared green is what the texture holds after. +#[test] +fn an_encoder_s_store_action_and_clamped_samplers_play() { + let dir = ScratchDir::new("replay-store-action").unwrap(); + let green: Vec = [0u8, 255, 0, 255].repeat(16); + let path = written(&dir, |w| { + w.call("MTLCreateSystemDefaultDevice", 0, 1, &[], &[])?; + w.call("newCommandQueue", 1, 2, &[], &[])?; + w.call("m2v.textureDescriptor", 0, 3, &[render_target(vec![])], &[])?; + w.call("newTextureWithDescriptor:", 1, 4, &[Value::Object(3)], &[])?; + for sampler in [5, 6] { + let plain = [Value::Map(Vec::new())]; + w.call("newSamplerStateWithDescriptor:", 1, sampler, &plain, &[])?; + } + w.call("MTLRenderPassDescriptor.new", 0, 7, &[], &[])?; + let clear = Value::Map( + [("red", 0.0), ("green", 1.0), ("blue", 0.0), ("alpha", 1.0)] + .map(|(key, value)| (key.into(), Value::F64(value))) + .to_vec(), + ); + // Load action clear (2), store action unknown (4). + let Value::Map(mut color) = uints(&[("level", 0), ("loadAction", 2), ("storeAction", 4)]) + else { + unreachable!("a map"); + }; + color.push(("texture".into(), Value::Object(4))); + color.push(("resolveTexture".into(), Value::Nil)); + color.push(("clearColor".into(), clear)); + let args = [Value::Uint(0), Value::Map(color)]; + w.call("m2v.setColorAttachment", 7, 0, &args, &[])?; + w.call("commandBuffer", 2, 8, &[], &[])?; + let pass = [Value::Object(7)]; + w.call("renderCommandEncoderWithDescriptor:", 8, 9, &pass, &[])?; + let clamped = [ + Value::List(vec![Value::Object(5), Value::Object(6)]), + Value::List(vec![Value::F64(1.0), Value::F64(0.0)]), + Value::List(vec![Value::F64(2.0), Value::F64(0.5)]), + uints(&[("location", 1), ("length", 2)]), + ]; + let selector = "setFragmentSamplerStates:lodMinClamps:lodMaxClamps:withRange:"; + w.call(selector, 9, 0, &clamped, &[])?; + // Store (1) at colour attachment 0. + let store = [Value::Uint(1), Value::Uint(0)]; + w.call("setColorStoreAction:atIndex:", 9, 0, &store, &[])?; + w.call("endEncoding", 9, 0, &[], &[])?; + w.call("commit", 8, 0, &[], &[])?; + w.call( + "m2v.check", + 0, + 0, + &[Value::Object(4)], + &[("sha256", sha(&green))], + ) + }); + on_device_with(at_plan, |device| { + let report = play("store-action", device, &path); + assert_eq!(report.checks.len(), 1); + assert_eq!(Some(report.checks[0].sha256), report.checks[0].recorded); + }); +}