From 1a4310899abc9aa06b649200e579e7d30f1303ff Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 27 Nov 2026 03:30:54 -0800 Subject: [PATCH] Runtime tests: OpenGL mode's depth output without a depth attachment, and the void vertex refusal The old runtime's OpenGL-mode device tests went with it on 11-20 and were never ported, so the private render state the guest's GL renderer sets on every pipeline lost its guard. This ports them onto the new runtime's device-test helpers, with the M3 Max's answers as they stood (probe conformance/probes/opengl_mode.m, macOS 27.0.1): - opengl_mode_makes_a_depth_output_without_a_depth_attachment: with the mode, a fragment function writing depth without a depth attachment makes a state whose colors are those it draws with a depth attachment. The old test's other half, the refusal without the mode, is not ported: only the M3 Max's driver refuses it and no Metal document states it (MTLRenderPipeline.h, Apple's pages for depthAttachmentPixelFormat and makeRenderPipelineState(descriptor:), the MSL spec's depth output), so on the planner's ruling the runtime makes the state, recorded in docs/API.md's accepted differences. - without_opengl_mode_a_rasterizing_void_vertex_function_is_refused: the refusal half of the old void-vertex test, as the translator's typed DescriptorError::RasterizedVoidVertex; Metal's text stays in the module doc, as the runtime's errors carry none. The module doc names the nine deleted tests not ported and why: point_size_notices' per-draw notice is gone (the note is the state's), and private_properties' eight tests test Apple's private device properties, which the consumer answers and the runtime holds none of. Verified: to run on lavapipe at the branch tip (a CPU job), reported to main with its job. --- crates/metal2vulkan-runtime/src/tests/mod.rs | 1 + .../src/tests/opengl_mode.rs | 195 ++++++++++++++++++ docs/API.md | 5 + 3 files changed, 201 insertions(+) create mode 100644 crates/metal2vulkan-runtime/src/tests/opengl_mode.rs diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 70a3d8829..6ad4627d2 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -94,6 +94,7 @@ mod opencl_local; mod opencl_mode; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod opencl_swizzles; +mod opengl_mode; mod over; mod over_aliases; mod over_causes; diff --git a/crates/metal2vulkan-runtime/src/tests/opengl_mode.rs b/crates/metal2vulkan-runtime/src/tests/opengl_mode.rs new file mode 100644 index 000000000..823ccfbc4 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/opengl_mode.rs @@ -0,0 +1,195 @@ +//! OpenGL mode (`PrivateRenderState::open_gl_mode_enabled`) makes the two render states Metal +//! refuses without it, each drawing as an Apple M3 Max draws it (probe +//! `conformance/probes/opengl_mode.m`, macOS 27.0.1): a fragment function writing depth without a +//! depth attachment draws its colors as with one; a rasterizing state whose vertex function returns +//! `void` runs the vertex function and rasterizes nothing. Without the mode Metal refuses the +//! second ("RasterizationEnabled is true but the vertex shader's return type is void"), as the +//! translator's link does (`DescriptorError::RasterizedVoidVertex`). The first only the M3 Max's +//! driver refuses ("depthAttachmentPixelFormat is not valid and shader writes to depth"), and the +//! runtime makes it in either mode (docs/API.md, accepted differences). +//! +//! Device tests, under a device cfg on every device of the cfg's kind. The functions are those of +//! the owned fixture `validation/fixtures/public/examples/icb_linked_arguments.ll`; `llvm-as` +//! assembles them, and without it the tests skip visibly. +//! +//! Not ported from the earlier runtime's tests of this state, for want of the part each tested: +//! - `only_a_draw_of_points_announces_the_device_s_point_size`: the runtime announces no notice +//! at a draw; `DevicePointSize` is the state's static note (`point_size_note`). +//! +//! Apple's private device properties, which the consumer answers and the runtime holds none of: +//! - `every_property_has_one_selector`: each property's selector. +//! - `the_answers_are_the_probes`: the M3 Max's values of some properties. +//! - `metals_answers_are_the_undocumented_properties`: which properties answer Metal's values. +//! - `table_counts_and_sizes_are_what_the_runtime_takes`: table counts and texture sizes. +//! - `the_device_draws_the_public_primitive_types`: `supportsPrimitiveType:`. +//! - `predication_answers_where_it_runs`: command predication's properties. +//! - `the_core_count_and_fp16_are_the_devices`: `gpuCoreCount` and native half floats. +//! - `the_alignments_atomics_and_formats_are_the_devices`: alignments, atomics and formats. + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use crate::tests::command::on_device::each_device; + use crate::tests::draw::on_device::{library, read, run, state, target, Buffers, SIDE}; + use crate::{ + Buffer, ClearColor, ColorAttachmentDescriptor, Device, Error, FunctionDescriptor, + IndexClass, Library, LoadAction, PixelFormat, PrimitiveType, Region, RenderPassDescriptor, + RenderPipelineDescriptor, RenderPipelineState, StageSource, StorageMode, Texture, + TextureDescriptor, TextureType, TextureUsage, + }; + use metal2vulkan::error::DescriptorError; + use metal2vulkan_devtools::fixtures_dir; + + /// The texel `tint` holds at (1, 0), which the depth-writing fragment function writes as its + /// depth and the `void` vertex function stores. + const TEXEL: [f32; 4] = [0.25, 0.5, 0.75, 1.0]; + + /// The index `tint` takes. + const TINT: u32 = 4096; + + /// The fixture's library, or None where `llvm-as` is missing. + fn examples() -> Option { + library(&fixtures_dir().join("examples/icb_linked_arguments.ll")) + } + + fn stage(library: &Library, name: &str) -> StageSource { + StageSource::Function(FunctionDescriptor::new( + library.function(name).expect("the function"), + )) + } + + /// A descriptor of `vertex` and `fragment` drawing into `RGBA8Unorm`, in OpenGL mode where + /// `gl`. + fn descriptor( + library: &Library, + (vertex, fragment): (&str, Option<&str>), + gl: bool, + ) -> RenderPipelineDescriptor { + let mut d = RenderPipelineDescriptor::new(stage(library, vertex)); + d.fragment = fragment.map(|name| stage(library, name)); + d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm)); + d.private.open_gl_mode_enabled = gl; + d + } + + /// A 2 x 1 `RGBA32Float` texture holding [`TEXEL`] at (1, 0), at index [`TINT`]. + fn tint(name: &str, device: &Device) -> Texture { + (device.grant_indices(IndexClass::Texture, TINT, 1)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let mut d = TextureDescriptor::new(TextureType::Type2D, PixelFormat::RGBA32Float, 2, 1); + d.usage = TextureUsage::SHADER_READ; + d.storage_mode = StorageMode::Shared; + let texture = + (device.new_texture(&d, Some(TINT))).unwrap_or_else(|error| panic!("{name}: {error}")); + let bytes: Vec = [0.0; 4] + .iter() + .chain(&TEXEL) + .flat_map(|v: &f32| v.to_le_bytes()) + .collect(); + let region = Region { + origin: [0; 3], + size: [2, 1, 1], + }; + (texture.replace_region(region, 0, 0, crate::HostBytes::from(&bytes[..]), 32, 0)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + texture + } + + /// The bytes of a [`SIDE`]-square `RGBA8Unorm` target cleared to zero after one draw of three + /// vertices by `state`, `tint` bound at vertex and fragment texture 0 and `out` at vertex + /// buffer 0, and of `depth` where given, cleared to 1. + fn drawn( + name: &str, + device: &Device, + state: &RenderPipelineState, + (tint, out): (&Texture, &Buffer), + depth: Option<&Texture>, + ) -> Vec { + let target = target(device, PixelFormat::RGBA8Unorm, TextureUsage::RENDER_TARGET); + let mut pass = RenderPassDescriptor::default(); + let color = &mut pass.color_attachments[0]; + color.texture = Some(target.clone()); + color.load_action = LoadAction::Clear; + color.clear_color = ClearColor::new(0.0, 0.0, 0.0, 0.0); + if let Some(depth) = depth { + pass.depth_attachment.texture = Some(depth.clone()); + pass.depth_attachment.load_action = LoadAction::Clear; + pass.depth_attachment.clear_depth = 1.0; + } + let queue = device.new_command_queue(4).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let mut encoder = (command_buffer.render_command_encoder(&pass)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let ok = |result: Result<(), Error>| result.unwrap_or_else(|e| panic!("{name}: {e}")); + ok(encoder.set_render_pipeline_state(state)); + ok(encoder.set_vertex_texture(Some(tint), 0)); + ok(encoder.set_fragment_texture(Some(tint), 0)); + ok(encoder.set_vertex_buffer(Some(out), 0, 0)); + ok(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0)); + encoder.end_encoding(); + run(name, &command_buffer); + read(&target, 4) + } + + /// With the mode, a fragment function writing depth without a depth attachment makes a + /// state, and its colors are those it draws with a depth attachment. + #[test] + fn opengl_mode_makes_a_depth_output_without_a_depth_attachment() { + let Some(library) = examples() else { + return; + }; + let functions = ("plain_vertex", Some("depth_writing_fragment")); + let gl = descriptor(&library, functions, true); + let mut attached = descriptor(&library, functions, false); + attached.depth_format = Some(PixelFormat::Depth32Float); + each_device("opengl_mode_depth", |name, _, device| { + let unattached = state(name, &device, &gl); + let attached = state(name, &device, &attached); + let mut d = + TextureDescriptor::new(TextureType::Type2D, PixelFormat::Depth32Float, SIDE, SIDE); + d.usage = TextureUsage::RENDER_TARGET; + let depth = (device.new_texture_for_views(&d)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let tint = tint(name, &device); + let mut buffers = Buffers::new(&device); + let out = buffers.of(&device, &[0; 48]); + let without = drawn(name, &device, &unattached, (&tint, &out), None); + let with = drawn(name, &device, &attached, (&tint, &out), Some(&depth)); + assert!( + without.iter().any(|&b| b != 0), + "{name}: the state drew nothing" + ); + assert_eq!(without, with, "{name}"); + println!("{name}: OpenGL mode drew a depth output without a depth attachment"); + }); + } + + /// Without the mode, a rasterizing state whose vertex function returns `void` is refused + /// with Metal's error, with or without a fragment function. + #[test] + fn without_opengl_mode_a_rasterizing_void_vertex_function_is_refused() { + let Some(library) = examples() else { + return; + }; + each_device("opengl_mode_void_refused", |name, _, device| { + for fragment in [None, Some("inputless_fragment")] { + let functions = ("void_store_vertex", fragment); + let refused = device.new_render_pipeline_state( + &descriptor(&library, functions, false), + crate::tests::no_constexpr_samplers, + ); + match refused { + Err(Error::Translation { + error: + metal2vulkan::error::Error::InvalidDescriptor( + DescriptorError::RasterizedVoidVertex, + ), + .. + }) => {} + Err(other) => panic!("{name}: {fragment:?}: not Metal's error: {other:?}"), + Ok(_) => panic!("{name}: {fragment:?}: made"), + } + } + println!("{name}: a rasterizing void vertex function refused without OpenGL mode"); + }); + } +} diff --git a/docs/API.md b/docs/API.md index ba0b1c0b2..3300dfce0 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2572,6 +2572,11 @@ named states the rule in full. same precise count as `Counting`, nonzero exactly where a sample passed (`RenderCommandEncoder::VISIBILITY_NOTE`, section 9). The conformance cases `visibility-boolean-*` compare its word as nonzero alone. +- **A render pipeline state whose fragment function writes depth, with no depth attachment format, + is made, and its depth output goes nowhere**, where the driver of an Apple M3 Max (macOS + 27.0.1) refuses it outside the private OpenGL mode with "depthAttachmentPixelFormat is not valid + and shader writes to depth" (the probe `metal2vulkan-conformance/probes/opengl_mode.m`), a + refusal no Metal document states (`MTLRenderPipeline.h`, `depthAttachmentPixelFormat`). **Resource IDs and identifiers**