diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 32484aaa2..de1d32c49 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -4400,11 +4400,6 @@ cache is answered compile-required on both. The states-only plays of the 35 replay streams on lavapipe refuse none of their render or compute states (jobs m3-max-63105 to 63108, and m3-max-63132 and m3-max-63156 for the two streams that ran past those jobs' 300-second limit). -- Under the private OpenGL mode (`PrivateRenderState::open_gl_mode_enabled`), a render pipeline - whose vertex function returns `void` with rasterization enabled is refused, an - `Error::Translation` naming `RasterizedVoidVertex`, where Metal makes a state that runs the - vertex function and rasterizes nothing (an Apple M3 Max, macOS 27.0.1, the probe - `metal2vulkan-conformance/probes/opengl_mode.m`). - On a device that does not list `VK_EXT_shader_stencil_export`, a fragment function's `[[stencil]]` output is drawn by bits (`RuntimeFact::StencilBitDraws`). Each draw through its state is drawn once under the stencil reference 0, then once for each bit of the low 8 of the write masks of diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 70aeb71c0..1246ea65c 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -60,7 +60,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 = 2312; +pub const SEMANTICS_VERSION: u32 = 2313; /// 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/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 1a5178cae..7f9b87dc9 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -1172,8 +1172,9 @@ pub enum DescriptorError { /// returning `void`, as every other vertex function Metal's compiler builds returns its /// position. `newRenderPipelineStateWithDescriptor:` refuses it ("RasterizationEnabled is true /// but the vertex shader's return type is void", on an M3 Max under macOS 27.0.1), and makes it - /// under `PrivateRenderState::open_gl_mode_enabled` as a state that rasterizes nothing, which - /// is the descriptor with rasterization disabled: the link refuses it whatever the mode. + /// under `PrivateRenderState::open_gl_mode_enabled` as a state that runs the vertex function + /// and rasterizes nothing, which the compile makes as the descriptor with rasterization + /// disabled and no fragment function: refused without the mode only. RasterizedVoidVertex, /// A device description (or the Khronos profile JSON it was read from) is malformed or /// inconsistent. diff --git a/crates/metal2vulkan/src/pipeline/compile/api.rs b/crates/metal2vulkan/src/pipeline/compile/api.rs index a5810862f..92e674f3f 100644 --- a/crates/metal2vulkan/src/pipeline/compile/api.rs +++ b/crates/metal2vulkan/src/pipeline/compile/api.rs @@ -335,6 +335,14 @@ impl Device { guarded(|| { crate::pipeline::private_state::check_render(d)?; let p = self.profile(); + // The descriptor OpenGL mode makes of a rasterizing `void` vertex function + // (`render_pipeline`). + let unrasterized = crate::pipeline::private_state::unrasterized_void_vertex( + d, + entries, + &mut Meter::new(b), + )?; + let d = unrasterized.as_ref(); // The attachments as the private logic operation draws them (`render_pipeline`). let (operated, _) = crate::pipeline::private_state::logic_operation(d, p)?; let d = operated.as_ref(); @@ -445,7 +453,11 @@ impl Device { /// Metal stops at an assertion. Each stage's recursion is sized for `d`'s /// `maxVertexCallStackDepth` or `maxFragmentCallStackDepth`, as a compute kernel's is for its /// pipeline's; a `Compiled` stage sized for another depth is - /// `InvalidDescriptor(MaxCallStackDepth)`. + /// `InvalidDescriptor(MaxCallStackDepth)`. Under `PrivateRenderState::open_gl_mode_enabled`, a + /// rasterizing pipeline whose vertex function returns `void` compiles as the descriptor with + /// rasterization disabled and no fragment function, which Metal's state of it draws as: the + /// vertex function runs and nothing rasterizes. Without the mode it is + /// `InvalidDescriptor(RasterizedVoidVertex)`, as Metal refuses it. pub fn compile_render_pipeline( &self, d: &RenderPipelineDescriptor, @@ -746,6 +758,12 @@ impl Device { ) -> Result { crate::pipeline::private_state::check_render(d)?; let p = self.profile(); + // Under OpenGL mode a rasterizing state whose vertex function returns `void` is made as + // the descriptor with rasterization disabled and no fragment function, decided before + // anything compiles, as the keys decide it (`render_variant_key`). + let unrasterized = + crate::pipeline::private_state::unrasterized_void_vertex(d, &StageEntries::new(), m)?; + let d = unrasterized.as_ref(); // The attachments as the private logic operation draws them: its normalized and integer // attachments unblended (unwritten under a no-op), and Vulkan's operation where one is // needed. diff --git a/crates/metal2vulkan/src/pipeline/descriptor.rs b/crates/metal2vulkan/src/pipeline/descriptor.rs index 9266a3252..c33d0d36d 100644 --- a/crates/metal2vulkan/src/pipeline/descriptor.rs +++ b/crates/metal2vulkan/src/pipeline/descriptor.rs @@ -512,10 +512,11 @@ pub struct PrivateRenderState { /// `openGLModeEnabled` (default off): changes nothing Metal draws or reflects, and makes two /// states Metal otherwise refuses (`pipeline::private_state`'s docs): a fragment function /// writing depth without a depth attachment, its depth going nowhere, and a rasterizing state - /// whose vertex function returns `void`, which rasterizes nothing. The runtime answers both, - /// the second as the state of the - /// descriptor with rasterization disabled; the compile reads it not, and its link refuses a - /// rasterizing `void` vertex function whatever the mode + /// whose vertex function returns `void`, which runs the vertex function and rasterizes + /// nothing. The compile makes both: the second as the descriptor with rasterization disabled + /// and no fragment function, which never runs and is not compiled + /// ([`Device::compile_render_pipeline`](crate::device::Device::compile_render_pipeline)); + /// without the mode that state is refused, as Metal refuses it /// ([`DescriptorError::RasterizedVoidVertex`](crate::error::DescriptorError::RasterizedVoidVertex)). pub open_gl_mode_enabled: bool, } diff --git a/crates/metal2vulkan/src/pipeline/link.rs b/crates/metal2vulkan/src/pipeline/link.rs index a1df8e270..f933d4d1d 100644 --- a/crates/metal2vulkan/src/pipeline/link.rs +++ b/crates/metal2vulkan/src/pipeline/link.rs @@ -612,7 +612,9 @@ fn check_stages(ifaces: &[&StageInterface], inputs: &LinkInputs) -> Result<(), E return Err(mismatch(*expected.last().unwrap_or(&Stage::Vertex), *extra)); } // Metal refuses a rasterizing pipeline whose vertex function returns `void`, the one - // vertex function without a position, which the compile read from its entry. + // vertex function without a position, which the compile read from its entry. Under + // OpenGL mode Metal makes it, and the compile links it with rasterization disabled + // (`private_state::unrasterized_void_vertex`). let positioned = |iface: &StageInterface| { (iface.io.builtins.iter()).any(|b| matches!(b, StageBuiltin::Position { .. })) }; diff --git a/crates/metal2vulkan/src/pipeline/private_state.rs b/crates/metal2vulkan/src/pipeline/private_state.rs index e3b761759..dfe368018 100644 --- a/crates/metal2vulkan/src/pipeline/private_state.rs +++ b/crates/metal2vulkan/src/pipeline/private_state.rs @@ -98,10 +98,15 @@ //! the bindings a pipeline reflects): the properties above that change nothing change nothing //! with it either. It makes two states Metal otherwise refuses, which the runtime answers: a //! fragment function writing depth without a depth attachment, whose colors draw as without the -//! output, and a rasterizing state whose vertex function returns `void`, whose draws run the -//! vertex function and rasterize nothing. The other refusals tried stand: fragment inputs no -//! vertex output writes or of another type, a `float` output to an integer attachment, and -//! stage-in attributes without a vertex descriptor or missing from it. The compile reads it not. +//! output, and a rasterizing state whose vertex function returns `void`, with a fragment function +//! or none, whose draws run the vertex function, its stores landing, and leave the colors as +//! cleared. The other refusals tried stand: fragment inputs no vertex output writes or of +//! another type, a `float` output to an integer attachment, and stage-in attributes without a +//! vertex descriptor or missing from it. The compile makes the first as it makes it without the +//! mode, and the second as the descriptor with rasterization disabled and no fragment function +//! ([`unrasterized_void_vertex`]): that fragment function, which never runs, is neither compiled +//! nor checked, so a state of one Metal would refuse for another reason is made, an answer not +//! measured. The compile reads the mode nowhere else. //! - `pointSmoothEnabled` changes what Metal draws; until the translation builds it, on is //! refused `NotImplemented` naming it. //! - `textureWriteRoundingMode` 2 rounds a fragment function's texture writes to half-float and @@ -114,6 +119,7 @@ use std::borrow::Cow; +use crate::budget::Meter; use crate::device::requirements::VkFeature; use crate::device::DeviceProfile; use crate::error::{ @@ -124,7 +130,8 @@ use crate::library::FunctionArtifact; use crate::metal::format::{write_conversion, WriteConversion}; use crate::metal::{ColorWriteMask, CompareFunction, PixelFormat}; use crate::pipeline::artifact::{PrecisionNote, StageModule}; -use crate::pipeline::descriptor::{PrivateRenderState, RenderPipelineDescriptor}; +use crate::pipeline::compile::{stage_returns_value, StageEntries}; +use crate::pipeline::descriptor::{PrivateRenderState, RenderPipelineDescriptor, StageSource}; use crate::pipeline::lower_inputs::ChannelWrite; use crate::pipeline::stage_io::{DepthCompares, StageBuiltin}; use crate::pipeline::sym::SampledType; @@ -167,6 +174,34 @@ pub(crate) fn check_render(d: &RenderPipelineDescriptor) -> Result<(), Error> { } } +/// `d` as Metal makes it under `openGLModeEnabled` where it rasterizes and its vertex function +/// returns `void` (the module docs): the descriptor with rasterization disabled and no fragment +/// function, which never runs; every other descriptor as it is. Whether a `Function` vertex stage +/// returns a value is read through `entries` under `m` ([`stage_returns_value`], a decode that +/// the stage's specialization through the same object shares); a `Compiled` one's from its +/// interface, as the link reads it: a vertex function that returns a value writes its position. +pub(crate) fn unrasterized_void_vertex<'a>( + d: &'a RenderPipelineDescriptor, + entries: &StageEntries, + m: &mut Meter, +) -> Result, Error> { + if !(d.private.open_gl_mode_enabled && d.rasterization_enabled) { + return Ok(Cow::Borrowed(d)); + } + let returns = match &d.vertex { + StageSource::Function(f) => stage_returns_value(f, entries, m)?, + StageSource::Compiled(c) => (c.artifact().interface.io.builtins.iter()) + .any(|b| matches!(b, StageBuiltin::Position { .. })), + }; + if returns { + return Ok(Cow::Borrowed(d)); + } + let mut unrasterized = d.clone(); + unrasterized.rasterization_enabled = false; + unrasterized.fragment = None; + Ok(Cow::Owned(unrasterized)) +} + /// The samples of a pixel at `samples` samples, as a mask. fn all_samples(samples: u32) -> u32 { match samples {