diff --git a/crates/metal2vulkan-runtime/src/apple_only.rs b/crates/metal2vulkan-runtime/src/apple_only.rs index 884803f5c..60e1a2474 100644 --- a/crates/metal2vulkan-runtime/src/apple_only.rs +++ b/crates/metal2vulkan-runtime/src/apple_only.rs @@ -48,6 +48,7 @@ use super::compute::ComputeCommandEncoder; use super::error::Error; use super::render::RenderCall; use super::render::RenderCommandEncoder; +use super::render::RenderLowering; use super::replay::BlitCall; use super::texture::Texture; @@ -281,63 +282,109 @@ impl ComputeCommandEncoder { pub fn insert_compressed_texture_reinterpretation_flush(&mut self) {} } +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::set_alpha_test_reference_value`]. + pub(crate) fn set_alpha_test_reference_value(&mut self, value: f32) -> Result<(), Error> { + self.log(|_| RenderCall::AlphaTestReferenceValue(value)); + answer(AppleOnlyCall::SetAlphaTestReferenceValue(value)) + } + + /// The lowering of [`RenderCommandEncoder::set_line_width`]. + pub(crate) fn set_line_width(&mut self, width: f32) -> Result<(), Error> { + self.log(|_| RenderCall::LineWidth(width)); + answer(AppleOnlyCall::SetLineWidth(width)) + } + + /// The lowering of [`RenderCommandEncoder::set_point_size`]. + pub(crate) fn set_point_size(&mut self, size: f32) -> Result<(), Error> { + self.log(|_| RenderCall::PointSize(size)); + answer(AppleOnlyCall::SetPointSize(size)) + } + + /// The lowering of [`RenderCommandEncoder::set_provoking_vertex_mode`]. + pub(crate) fn set_provoking_vertex_mode(&mut self, mode: u64) -> Result<(), Error> { + self.log(|_| RenderCall::ProvokingVertexMode(mode)); + answer(AppleOnlyCall::SetProvokingVertexMode(mode)) + } + + /// The lowering of [`RenderCommandEncoder::set_viewport_transform_enabled`]. + pub(crate) fn set_viewport_transform_enabled(&mut self, enabled: bool) -> Result<(), Error> { + self.log(|_| RenderCall::ViewportTransformEnabled(enabled)); + answer(AppleOnlyCall::SetViewportTransformEnabled(enabled)) + } + + /// The lowering of [`RenderCommandEncoder::set_vertex_amplification_mode`]. + pub(crate) fn set_vertex_amplification_mode( + &mut self, + mode: u64, + value: u64, + ) -> Result<(), Error> { + self.log(|_| RenderCall::VertexAmplificationMode(mode, value)); + answer(AppleOnlyCall::SetVertexAmplificationMode { mode, value }) + } + + /// The lowering of [`RenderCommandEncoder::set_depth_cleared`]. + pub(crate) fn set_depth_cleared(&mut self) -> Result<(), Error> { + self.log(|_| RenderCall::DepthCleared); + answer(AppleOnlyCall::SetDepthCleared) + } + + /// The lowering of [`RenderCommandEncoder::set_stencil_cleared`]. + pub(crate) fn set_stencil_cleared(&mut self) -> Result<(), Error> { + self.log(|_| RenderCall::StencilCleared); + answer(AppleOnlyCall::SetStencilCleared) + } +} + impl RenderCommandEncoder { /// `setAlphaTestReferenceValue:` (SPI): a no-op. No pipeline the runtime builds has a /// fixed-function alpha test, so the reference has no effect, as on Metal with the test off. pub fn set_alpha_test_reference_value(&mut self, value: f32) -> Result<(), Error> { - self.log(|_| RenderCall::AlphaTestReferenceValue(value)); - answer(AppleOnlyCall::SetAlphaTestReferenceValue(value)) + self.lowering.set_alpha_test_reference_value(value) } /// `setLineWidth:` (SPI): accepted at Metal's default width of 1, which every line the /// runtime draws has; any other width is refused ([`AppleOnly::LineWidth`]): Apple's /// wide-line rule is unmeasured. pub fn set_line_width(&mut self, width: f32) -> Result<(), Error> { - self.log(|_| RenderCall::LineWidth(width)); - answer(AppleOnlyCall::SetLineWidth(width)) + self.lowering.set_line_width(width) } /// `setPointSize:` (SPI): a no-op. On an M4 it changes nothing Metal draws at any size (0, /// 0.5, 1, 3, 5, 100, -2, NaN, infinity), whether the vertex function writes `[[point_size]]` /// or not and whether the pipeline's private `pointSizeOutputVS` is set. pub fn set_point_size(&mut self, size: f32) -> Result<(), Error> { - self.log(|_| RenderCall::PointSize(size)); - answer(AppleOnlyCall::SetPointSize(size)) + self.lowering.set_point_size(size) } /// `setProvokingVertexMode:` (SPI): accepted at Metal's default, mode 0, the first vertex, /// from which every runtime draw takes a flat varying; any other mode is refused /// ([`AppleOnly::ProvokingVertexMode`]). pub fn set_provoking_vertex_mode(&mut self, mode: u64) -> Result<(), Error> { - self.log(|_| RenderCall::ProvokingVertexMode(mode)); - answer(AppleOnlyCall::SetProvokingVertexMode(mode)) + self.lowering.set_provoking_vertex_mode(mode) } /// `setViewportTransformEnabled:` (SPI): accepted on, Metal's default and every runtime /// draw's; off is refused ([`AppleOnly::ViewportTransformDisabled`]): Vulkan has no form for /// it. pub fn set_viewport_transform_enabled(&mut self, enabled: bool) -> Result<(), Error> { - self.log(|_| RenderCall::ViewportTransformEnabled(enabled)); - answer(AppleOnlyCall::SetViewportTransformEnabled(enabled)) + self.lowering.set_viewport_transform_enabled(enabled) } /// `setVertexAmplificationMode:value:` (SPI): refused /// ([`AppleOnly::VertexAmplificationMode`]), its meaning unmeasured. pub fn set_vertex_amplification_mode(&mut self, mode: u64, value: u64) -> Result<(), Error> { - self.log(|_| RenderCall::VertexAmplificationMode(mode, value)); - answer(AppleOnlyCall::SetVertexAmplificationMode { mode, value }) + self.lowering.set_vertex_amplification_mode(mode, value) } /// `setDepthCleared` (SPI): refused ([`AppleOnly::DepthCleared`]), its meaning unmeasured. pub fn set_depth_cleared(&mut self) -> Result<(), Error> { - self.log(|_| RenderCall::DepthCleared); - answer(AppleOnlyCall::SetDepthCleared) + self.lowering.set_depth_cleared() } /// `setStencilCleared` (SPI): refused ([`AppleOnly::StencilCleared`]), its meaning /// unmeasured. pub fn set_stencil_cleared(&mut self) -> Result<(), Error> { - self.log(|_| RenderCall::StencilCleared); - answer(AppleOnlyCall::SetStencilCleared) + self.lowering.set_stencil_cleared() } } diff --git a/crates/metal2vulkan-runtime/src/fence.rs b/crates/metal2vulkan-runtime/src/fence.rs index 957042724..8fcb1a5f3 100644 --- a/crates/metal2vulkan-runtime/src/fence.rs +++ b/crates/metal2vulkan-runtime/src/fence.rs @@ -64,6 +64,7 @@ use super::error::Error; use super::predication::Event; use super::render::RenderCall; use super::render::RenderCommandEncoder; +use super::render::RenderLowering; use super::render::{FRAGMENT_DRAW_STAGES, GEOMETRY_DRAW_STAGES}; use super::replay::{BlitCall, ComputeCall, Resource}; use super::resource::{ResourceKey, ResourceRef}; @@ -276,11 +277,13 @@ const UP_TO_FRAGMENT: RenderStages = RenderStages::VERTEX .union(RenderStages::MESH) .union(RenderStages::FRAGMENT); -impl RenderCommandEncoder { - /// `updateFence:afterStages:`: the fence is updated after the encoder's draws' work in - /// `after_stages` and every stage before them (the module docs), and its work outside its - /// draws; Metal's `Tile` stage, or no stage, after all of its work. - pub fn update_fence(&mut self, fence: &Fence, after_stages: RenderStages) -> Result<(), Error> { +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::update_fence`]. + pub(crate) fn update_fence( + &mut self, + fence: &Fence, + after_stages: RenderStages, + ) -> Result<(), Error> { self.log(|_| RenderCall::UpdateFence(fence.clone(), after_stages)); // The update follows the encoder's work, its later color groups' passes too, which // record in its core after the first group's: their encoders' calls change nothing @@ -292,13 +295,8 @@ impl RenderCommandEncoder { .update_fence("update_fence", fence, after_stages_of(after_stages)) } - /// `waitForFence:beforeStages:`: the encoder's draws' work in `before_stages` and every stage - /// after them waits for the fence's last update before the encoder in the queue's commit - /// order, also after the encoder updated the fence, as the compute encoder's does, and so - /// does its work outside its draws (the module docs); its draws' earlier stages may run - /// before the update. A wait before the vertex, object or mesh stage, or before no stage, - /// orders all of its work. - pub fn wait_for_fence( + /// The lowering of [`RenderCommandEncoder::wait_for_fence`]. + pub(crate) fn wait_for_fence( &mut self, fence: &Fence, before_stages: RenderStages, @@ -313,18 +311,8 @@ impl RenderCommandEncoder { .wait_for_fence("wait_for_fence", fence, before_stages_of(before_stages)) } - /// `memoryBarrierWithScope:afterStages:beforeStages:`: the writes of the encoder's draws - /// before the barrier to the kinds of resource `scope` names (buffers, textures, render - /// targets) are visible to its draws after it (the module docs). A scope of the render - /// targets alone, after the fragment stage and before a stage at or before it (the vertex, - /// object, mesh or fragment stage), orders the fragment stage's writes before the later - /// draws' fragment stages, which run after their earlier stages, inside the render pass - /// instance; another scope splits the pass there. An empty scope, no stage before or after, - /// or a scope of the render targets alone after no fragment stage or before none of those - /// stages orders nothing more than the pass does: only the fragment stage writes a render - /// target, and a tile dispatch runs between render pass instances - /// (`render/tile_dispatch.rs`). - pub fn memory_barrier_with_scope( + /// The lowering of [`RenderCommandEncoder::memory_barrier_with_scope`]. + pub(crate) fn memory_barrier_with_scope( &mut self, scope: BarrierScope, after_stages: RenderStages, @@ -345,12 +333,8 @@ impl RenderCommandEncoder { self.barrier_before_next_draw(); } - /// `memoryBarrierWithResources:count:afterStages:beforeStages:`: as - /// [`memory_barrier_with_scope`](Self::memory_barrier_with_scope) over buffers and textures, - /// for the writes to `resources`, which splits the pass; an empty list orders nothing. - /// - /// Refused, changing nothing (`Invalid`): a resource of another device. - pub fn memory_barrier_with_resources( + /// The lowering of [`RenderCommandEncoder::memory_barrier_with_resources`]. + pub(crate) fn memory_barrier_with_resources( &mut self, resources: &[ResourceRef<'_>], after_stages: RenderStages, @@ -369,3 +353,62 @@ impl RenderCommandEncoder { Ok(()) } } + +impl RenderCommandEncoder { + /// `updateFence:afterStages:`: the fence is updated after the encoder's draws' work in + /// `after_stages` and every stage before them (the module docs), and its work outside its + /// draws; Metal's `Tile` stage, or no stage, after all of its work. + pub fn update_fence(&mut self, fence: &Fence, after_stages: RenderStages) -> Result<(), Error> { + self.lowering.update_fence(fence, after_stages) + } + + /// `waitForFence:beforeStages:`: the encoder's draws' work in `before_stages` and every stage + /// after them waits for the fence's last update before the encoder in the queue's commit + /// order, also after the encoder updated the fence, as the compute encoder's does, and so + /// does its work outside its draws (the module docs); its draws' earlier stages may run + /// before the update. A wait before the vertex, object or mesh stage, or before no stage, + /// orders all of its work. + pub fn wait_for_fence( + &mut self, + fence: &Fence, + before_stages: RenderStages, + ) -> Result<(), Error> { + self.lowering.wait_for_fence(fence, before_stages) + } + + /// `memoryBarrierWithScope:afterStages:beforeStages:`: the writes of the encoder's draws + /// before the barrier to the kinds of resource `scope` names (buffers, textures, render + /// targets) are visible to its draws after it (the module docs). A scope of the render + /// targets alone, after the fragment stage and before a stage at or before it (the vertex, + /// object, mesh or fragment stage), orders the fragment stage's writes before the later + /// draws' fragment stages, which run after their earlier stages, inside the render pass + /// instance; another scope splits the pass there. An empty scope, no stage before or after, + /// or a scope of the render targets alone after no fragment stage or before none of those + /// stages orders nothing more than the pass does: only the fragment stage writes a render + /// target, and a tile dispatch runs between render pass instances + /// (`render/tile_dispatch.rs`). + pub fn memory_barrier_with_scope( + &mut self, + scope: BarrierScope, + after_stages: RenderStages, + before_stages: RenderStages, + ) { + self.lowering + .memory_barrier_with_scope(scope, after_stages, before_stages) + } + + /// `memoryBarrierWithResources:count:afterStages:beforeStages:`: as + /// [`memory_barrier_with_scope`](Self::memory_barrier_with_scope) over buffers and textures, + /// for the writes to `resources`, which splits the pass; an empty list orders nothing. + /// + /// Refused, changing nothing (`Invalid`): a resource of another device. + pub fn memory_barrier_with_resources( + &mut self, + resources: &[ResourceRef<'_>], + after_stages: RenderStages, + before_stages: RenderStages, + ) -> Result<(), Error> { + self.lowering + .memory_barrier_with_resources(resources, after_stages, before_stages) + } +} diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index 4564aae8b..0cf7cc196 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -1083,6 +1083,26 @@ enum Standing { /// committed, is released), as Metal holds what an encoder was handed: one a later call replaced /// or unbound before any draw used it, and one bound after the last draw, too. pub struct RenderCommandEncoder { + /// What runs its calls, in place: an encoder opens with no allocation of its own. + pub(crate) lowering: RenderLowering, +} + +impl RenderCommandEncoder { + /// The program's encoder over `lowering`. + fn new(lowering: RenderLowering) -> RenderCommandEncoder { + RenderCommandEncoder { lowering } + } +} + +impl std::fmt::Debug for RenderCommandEncoder { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.lowering.fmt(f) + } +} + +/// A render encoder's lowering ([`RenderCommandEncoder`]): the encoder's state, which each of its +/// calls runs on. +pub(crate) struct RenderLowering { core: EncoderCore, /// The pass's instances before the current one, which the draws record into. earlier: Vec, @@ -1447,9 +1467,9 @@ struct RoutedColors { dropped: BTreeSet, } -impl std::fmt::Debug for RenderCommandEncoder { +impl std::fmt::Debug for RenderLowering { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("RenderCommandEncoder") + f.debug_struct("RenderLowering") .field("extent", &self.layout.extent) .field("samples", &self.layout.samples) .finish() @@ -1466,6 +1486,7 @@ impl CommandBuffer { descriptor: &RenderPassDescriptor, ) -> Result { self.open_render(descriptor, None) + .map(RenderCommandEncoder::new) } /// [`render_command_encoder`](Self::render_command_encoder)'s encoder, or with `again` the @@ -1478,7 +1499,7 @@ impl CommandBuffer { &self, given: &RenderPassDescriptor, again: Option, - ) -> Result { + ) -> Result { const CALL: &str = "render_command_encoder"; let device = self.device(); rate_mapped_pass::check_descriptor(CALL, device, given)?; @@ -1585,7 +1606,7 @@ impl CommandBuffer { log, grouped, ); - Ok(RenderCommandEncoder::assemble(core, draws, opening)) + Ok(RenderLowering::assemble(core, draws, opening)) } } @@ -1645,7 +1666,7 @@ impl Opening { } } -impl RenderCommandEncoder { +impl RenderLowering { /// An encoder over `core` of the pass `opening` describes, its first instance's draws /// recording into `draws` (null where it records inline). fn assemble(core: EncoderCore, draws: vk::CommandBuffer, opening: Opening) -> Self { @@ -1668,7 +1689,7 @@ impl RenderCommandEncoder { let live = core.device().shared().live_binds.take(); // The views and sampler descriptions its binds made or found (`binding::BindMemo`). let bind_memo = core.device().shared().bind_memos.take(); - RenderCommandEncoder { + RenderLowering { core, earlier: Vec::new(), current: Instance { @@ -1923,35 +1944,12 @@ const RECORDED: [vk::DynamicState; 16] = [ vk::DynamicState::STENCIL_OP, ]; -impl RenderCommandEncoder { - /// `setRenderPipelineState:`. Refused (`Invalid`, measured: Metal's validation stops the - /// call): a color pixel format other than the pass's, as `DrawProblem::AttachmentFormat` - /// says (plain Metal stores each place of the state's per-sample record into the pass's - /// attachment at that place, writes zero bytes at every sample a draw covers to a pass color - /// at no place where its code reads no attachment and keeps it otherwise, and drops the - /// output of a state color at no place, as the runtime does; it draws a color whose format is - /// the pass's in another channel order, such as `RGBA8Unorm` into `BGRA8Unorm`, in the pass's - /// channel order; it takes the pass's depth and stencil attachments whatever depth and stencil - /// formats the state names), the raster sample count other than the pass's - /// (`DrawProblem::SampleCount`; plain Metal draws a render pipeline's state of more samples in - /// a pass of one as a state of one sample, as the runtime does, but for alpha to coverage and - /// `get_num_samples()`, which read the state's count, and stay refused), and a tile pipeline's - /// state whose function aliases an explicit imageblock onto its implicit one, or a drawing - /// state whose fragment function declares an explicit imageblock, of more imageblock bytes per - /// sample than the pass gives (`DrawProblem::ImageblockSampleLength`; a tile state whose - /// explicit imageblock stands alone runs there, as plain Metal runs it). Refused - /// `NotImplemented` where the formats agree in Metal's terms but not in Vulkan's, and for a - /// state of another device; `Unsupported` (`IndependentBlending`) where the pass has a color - /// the state keeps unwritten and the device lacks `independentBlend`. Where the device draws - /// the pass's colors in groups (`render/color_groups.rs`), refused `NotImplemented` - /// (`ColorAttachmentGroups`) for a drawing state whose colors with a pixel format are not the - /// pass's colors with a texture, and for a tile pipeline's state; and for a drawing state the - /// device draws in groups in a pass it draws in one. Metal's validation stops a state whose - /// color formats are not the pass's attachments' where both name one, as above; where one side - /// names none it draws (a color without an attachment nowhere, a pass color without a format - /// as zeroes), which the groups' variants do not state. A refused call keeps the state set - /// before. - pub fn set_render_pipeline_state(&mut self, state: &RenderPipelineState) -> Result<(), Error> { +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::set_render_pipeline_state`]. + pub(crate) fn set_render_pipeline_state( + &mut self, + state: &RenderPipelineState, + ) -> Result<(), Error> { self.log(|log| RenderCall::PipelineState(log.hold_render_state(state))); let turn = self.group_turn(); if let color_groups::Turn::Later(false) = turn { @@ -2025,9 +2023,8 @@ impl RenderCommandEncoder { Ok(twin) } - /// `setVertexBuffer:offset:atIndex:` (`None` unbinds the index). Refused: an index past the - /// table, an offset past the buffer's length, a buffer of another device. - pub fn set_vertex_buffer( + /// The lowering of [`RenderCommandEncoder::set_vertex_buffer`]. + pub(crate) fn set_vertex_buffer( &mut self, buffer: Option<&Buffer>, offset: u64, @@ -2041,10 +2038,8 @@ impl RenderCommandEncoder { .set_buffer(&mut self.core, "set_vertex_buffer", buffer, offset, index) } - /// `setVertexBuffers:offsets:withRange:`. Refused as - /// [`RenderCommandEncoder::set_vertex_buffer`] is, and when the slices' lengths differ; a - /// refusal binds none of them. - pub fn set_vertex_buffers( + /// The lowering of [`RenderCommandEncoder::set_vertex_buffers`]. + pub(crate) fn set_vertex_buffers( &mut self, buffers: &[Option<&Buffer>], offsets: &[u64], @@ -2067,37 +2062,26 @@ impl RenderCommandEncoder { ) } - /// `setVertexBufferOffset:atIndex:`, which clears the index's attribute stride - /// (`render/vertex_strides.rs`). At an index holding a visible-function table, the stage then - /// reads the null table there (size 0, every entry null) until a table or buffer is bound at - /// the index again, as plain Metal reads it. At an index holding inline bytes - /// ([`set_vertex_bytes`](Self::set_vertex_bytes)), they then read as zeros at any offset until - /// the index is bound again, as plain Metal reads them (an M4; its debug layer asserts there is - /// no buffer). Refused: nothing bound at the index, an offset past the buffer's length. - pub fn set_vertex_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_vertex_buffer_offset`]. + pub(crate) fn set_vertex_buffer_offset( + &mut self, + offset: u64, + index: u32, + ) -> Result<(), Error> { self.log(|_| RenderCall::BufferOffset(Table::Vertex, offset, index)); self.vertex .set_buffer_offset(&mut self.core, "set_vertex_buffer_offset", offset, index) } - /// `setVertexBytes:length:atIndex:`: `bytes`, copied now, at vertex buffer index `index` in - /// place of anything bound there, so a later write of the caller's memory reaches no draw, as - /// Metal copies them at the call. Every later draw reads the copy until the index is bound - /// again, as a buffer argument or as a vertex descriptor's buffer; a layout of - /// `MTLBufferLayoutStrideDynamic` reads it at stride 0, as a buffer bound without a stride - /// (`render/vertex_strides.rs`). A slot the stage reaches through a pointer loaded from - /// memory (one of a device-address form) cannot read inline bytes: - /// `Bind(MissingDeviceAddress)`, at the draw. Refused: an index past the table, and more than - /// 4096 bytes, Metal's limit for inline bytes (`Invalid(InlineBytesLength)`). - pub fn set_vertex_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_vertex_bytes`]. + pub(crate) fn set_vertex_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { self.log(|log| RenderCall::Bytes(Table::Vertex, log.byte_span(bytes), index)); self.vertex .set_bytes(&mut self.core, "set_vertex_bytes", bytes, None, index) } - /// `setVertexTexture:atIndex:` (`None` unbinds the index). Refused: an index past the table, - /// a texture of another device. - pub fn set_vertex_texture( + /// The lowering of [`RenderCommandEncoder::set_vertex_texture`]. + pub(crate) fn set_vertex_texture( &mut self, texture: Option<&Texture>, index: u32, @@ -2110,9 +2094,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_vertex_texture", &[texture], index) } - /// `setVertexTextures:withRange:`. Refused as [`RenderCommandEncoder::set_vertex_texture`] - /// is; a refusal binds none of them. - pub fn set_vertex_textures( + /// The lowering of [`RenderCommandEncoder::set_vertex_textures`]. + pub(crate) fn set_vertex_textures( &mut self, textures: &[Option<&Texture>], first: u32, @@ -2122,9 +2105,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_vertex_textures", textures, first) } - /// `setVertexSamplerState:atIndex:` (`None` unbinds the index). Refused: an index past the - /// table, a state of another device. - pub fn set_vertex_sampler_state( + /// The lowering of [`RenderCommandEncoder::set_vertex_sampler_state`]. + pub(crate) fn set_vertex_sampler_state( &mut self, sampler: Option<&SamplerState>, index: u32, @@ -2142,11 +2124,8 @@ impl RenderCommandEncoder { ) } - /// `setVertexSamplerStates:withRange:`, or with `clamps` (minimums and maximums) - /// `setVertexSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as - /// [`RenderCommandEncoder::set_vertex_sampler_state`] is, and when the slices' lengths differ; - /// a refusal binds none of them. - pub fn set_vertex_sampler_states( + /// The lowering of [`RenderCommandEncoder::set_vertex_sampler_states`]. + pub(crate) fn set_vertex_sampler_states( &mut self, samplers: &[Option<&SamplerState>], clamps: Option<(&[f32], &[f32])>, @@ -2162,9 +2141,8 @@ impl RenderCommandEncoder { ) } - /// `setFragmentBuffer:offset:atIndex:` (`None` unbinds the index). Refused as - /// [`RenderCommandEncoder::set_vertex_buffer`] is. - pub fn set_fragment_buffer( + /// The lowering of [`RenderCommandEncoder::set_fragment_buffer`]. + pub(crate) fn set_fragment_buffer( &mut self, buffer: Option<&Buffer>, offset: u64, @@ -2178,9 +2156,8 @@ impl RenderCommandEncoder { .set_buffer(&mut self.core, "set_fragment_buffer", buffer, offset, index) } - /// `setFragmentBuffers:offsets:withRange:`. Refused as - /// [`RenderCommandEncoder::set_vertex_buffers`] is. - pub fn set_fragment_buffers( + /// The lowering of [`RenderCommandEncoder::set_fragment_buffers`]. + pub(crate) fn set_fragment_buffers( &mut self, buffers: &[Option<&Buffer>], offsets: &[u64], @@ -2203,26 +2180,26 @@ impl RenderCommandEncoder { ) } - /// `setFragmentBufferOffset:atIndex:`. Refused as - /// [`RenderCommandEncoder::set_vertex_buffer_offset`] is. - pub fn set_fragment_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_fragment_buffer_offset`]. + pub(crate) fn set_fragment_buffer_offset( + &mut self, + offset: u64, + index: u32, + ) -> Result<(), Error> { self.log(|_| RenderCall::BufferOffset(Table::Fragment, offset, index)); self.fragment .set_buffer_offset(&mut self.core, "set_fragment_buffer_offset", offset, index) } - /// `setFragmentBytes:length:atIndex:`: as - /// [`set_vertex_bytes`](Self::set_vertex_bytes), in the fragment stage's table. Refused as - /// that is. - pub fn set_fragment_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_fragment_bytes`]. + pub(crate) fn set_fragment_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { self.log(|log| RenderCall::Bytes(Table::Fragment, log.byte_span(bytes), index)); self.fragment .set_bytes(&mut self.core, "set_fragment_bytes", bytes, None, index) } - /// `setFragmentTexture:atIndex:` (`None` unbinds the index). Refused as - /// [`RenderCommandEncoder::set_vertex_texture`] is. - pub fn set_fragment_texture( + /// The lowering of [`RenderCommandEncoder::set_fragment_texture`]. + pub(crate) fn set_fragment_texture( &mut self, texture: Option<&Texture>, index: u32, @@ -2235,9 +2212,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_fragment_texture", &[texture], index) } - /// `setFragmentTextures:withRange:`. Refused as - /// [`RenderCommandEncoder::set_vertex_textures`] is. - pub fn set_fragment_textures( + /// The lowering of [`RenderCommandEncoder::set_fragment_textures`]. + pub(crate) fn set_fragment_textures( &mut self, textures: &[Option<&Texture>], first: u32, @@ -2247,9 +2223,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_fragment_textures", textures, first) } - /// `setFragmentSamplerState:atIndex:` (`None` unbinds the index). Refused as - /// [`RenderCommandEncoder::set_vertex_sampler_state`] is. - pub fn set_fragment_sampler_state( + /// The lowering of [`RenderCommandEncoder::set_fragment_sampler_state`]. + pub(crate) fn set_fragment_sampler_state( &mut self, sampler: Option<&SamplerState>, index: u32, @@ -2267,10 +2242,8 @@ impl RenderCommandEncoder { ) } - /// `setFragmentSamplerStates:withRange:`, or with `clamps` - /// `setFragmentSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as - /// [`RenderCommandEncoder::set_vertex_sampler_states`] is. - pub fn set_fragment_sampler_states( + /// The lowering of [`RenderCommandEncoder::set_fragment_sampler_states`]. + pub(crate) fn set_fragment_sampler_states( &mut self, samplers: &[Option<&SamplerState>], clamps: Option<(&[f32], &[f32])>, @@ -2286,15 +2259,12 @@ impl RenderCommandEncoder { ) } - /// `setColorStoreAction:atIndex:`: the store action of color attachment `index`, which the - /// descriptor left `Unknown`. As plain Metal does where its validation stops the call (measured - /// on an M4): for an attachment without a texture, or over an action the descriptor knew, - /// nothing changes; a resolving action where nothing resolves resolves nothing - /// (`MultisampleResolve` keeps no sample, `StoreAndMultisampleResolve` stores them); and one - /// that does not resolve where a resolve texture is named leaves that texture untouched. - /// Refused (`Invalid`, measured): an index past the attachments, `Unknown` itself, and `Store` - /// or `StoreAndMultisampleResolve` for a memoryless attachment. - pub fn set_color_store_action(&mut self, action: StoreAction, index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_color_store_action`]. + pub(crate) fn set_color_store_action( + &mut self, + action: StoreAction, + index: u32, + ) -> Result<(), Error> { self.log(|_| RenderCall::ColorStoreAction(action, index)); const CALL: &str = "set_color_store_action"; check_index(CALL, index, MAX_COLOR_ATTACHMENTS as u32)?; @@ -2329,34 +2299,20 @@ impl RenderCommandEncoder { Ok(()) } - /// `setDepthStoreAction:`: the depth attachment's store action, which the descriptor left - /// `Unknown`; without a depth attachment nothing changes, as plain Metal does where its - /// validation stops the call (measured on an M4); one that does not resolve where a resolve - /// texture is named leaves that texture untouched and stores the depth by the action, as plain - /// Metal does where its validation stops it. Refused (`Invalid`, measured): - /// an action over one the descriptor knew, `Unknown` itself, a resolving action without a - /// resolve texture, `Store` for a memoryless attachment, and `Store` where the stencil - /// attachment is the same texture resolved by `MultisampleResolve`. - pub fn set_depth_store_action(&mut self, action: StoreAction) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_depth_store_action`]. + pub(crate) fn set_depth_store_action(&mut self, action: StoreAction) -> Result<(), Error> { self.log(|_| RenderCall::DepthStoreAction(action)); self.set_aspect_store_action("set_depth_store_action", Attachment::Depth, action) } - /// `setStencilStoreAction:`: the stencil attachment's store action, which the descriptor - /// left `Unknown`. Refused as [`RenderCommandEncoder::set_depth_store_action`] is, but for - /// the last: here `MultisampleResolve` where the depth attachment is the same texture, - /// stored; and without a stencil attachment (unmeasured). - pub fn set_stencil_store_action(&mut self, action: StoreAction) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_stencil_store_action`]. + pub(crate) fn set_stencil_store_action(&mut self, action: StoreAction) -> Result<(), Error> { self.log(|_| RenderCall::StencilStoreAction(action)); self.set_aspect_store_action("set_stencil_store_action", Attachment::Stencil, action) } - /// `setColorStoreActionOptions:atIndex:`: the color attachment's store action options, which - /// change nothing, as plain Metal's: Apple's GPUs ignore them, and plain Metal takes them over - /// a store action the descriptor knew and under one that keeps no samples, where its validation - /// stops them (measured on an M4, `sample_positions.rs`). Refused (`Invalid`): an index past - /// the attachments and an attachment without a texture (unmeasured). - pub fn set_color_store_action_options( + /// The lowering of [`RenderCommandEncoder::set_color_store_action_options`]. + pub(crate) fn set_color_store_action_options( &mut self, _options: StoreActionOptions, index: u32, @@ -2375,11 +2331,8 @@ impl RenderCommandEncoder { } } - /// `setDepthStoreActionOptions:`: the depth attachment's store action options, where the - /// descriptor left its store action `Unknown`; they change nothing, as plain Metal's (Metal - /// probe case `opt_depth_late` on an M4). Refused (`Invalid`, measured): an attachment without - /// a texture, and one whose descriptor knew its store action. - pub fn set_depth_store_action_options( + /// The lowering of [`RenderCommandEncoder::set_depth_store_action_options`]. + pub(crate) fn set_depth_store_action_options( &mut self, options: StoreActionOptions, ) -> Result<(), Error> { @@ -2391,11 +2344,8 @@ impl RenderCommandEncoder { ) } - /// `setStencilStoreActionOptions:`: the stencil attachment's store action options. Refused - /// as [`RenderCommandEncoder::set_depth_store_action_options`] is; `end_encoding` refuses - /// `CustomSamplePositions` under a store action that keeps no samples (unmeasured for a - /// stencil attachment, `sample_positions.rs`). - pub fn set_stencil_store_action_options( + /// The lowering of [`RenderCommandEncoder::set_stencil_store_action_options`]. + pub(crate) fn set_stencil_store_action_options( &mut self, options: StoreActionOptions, ) -> Result<(), Error> { @@ -2522,70 +2472,48 @@ impl RenderCommandEncoder { Ok(()) } - /// `setViewport:`. A NaN origin x draws nothing, as plain Metal's where its validation stops it - /// (measured on an M4). Refused (`Invalid`, measured): any other NaN or infinite field. A depth - /// range past `[0, 1]` is refused on a device that takes it neither natively nor by the vertex - /// stage's compensation: `NotImplemented` without the features, `Unsupported` on a driver that - /// draws the compensated depths inexactly (`render_state.rs`). A refused call keeps the - /// viewports set before. - pub fn set_viewport(&mut self, viewport: Viewport) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_viewport`]. + pub(crate) fn set_viewport(&mut self, viewport: Viewport) -> Result<(), Error> { self.log(|_| RenderCall::Viewport(Box::new(viewport))); let refused = render_state::depth_ranges_refused(self.core.device()); self.state .set_viewports("set_viewport", &[viewport], refused) } - /// `setViewports:count:`. Refused as [`RenderCommandEncoder::set_viewport`] is, and for a - /// count outside 1 to 16 (measured). On a device without `multiViewport`, a draw that selects - /// among more than one viewport (its vertex function writes `[[viewport_array_index]]`, or an - /// amplification's mapping offsets the viewport) is refused at the draw, - /// `Unsupported(LayeredRendering)` needing the feature; with one it draws through it. - pub fn set_viewports(&mut self, viewports: &[Viewport]) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_viewports`]. + pub(crate) fn set_viewports(&mut self, viewports: &[Viewport]) -> Result<(), Error> { self.log(|_| RenderCall::Viewports(viewports.into())); let refused = render_state::depth_ranges_refused(self.core.device()); self.state .set_viewports("set_viewports", viewports, refused) } - /// `setScissorRect:`. A rectangle past the render area is clipped to it, as plain Metal clips - /// it where its validation stops the call (measured on an M4). - pub fn set_scissor_rect(&mut self, rect: ScissorRect) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_scissor_rect`]. + pub(crate) fn set_scissor_rect(&mut self, rect: ScissorRect) -> Result<(), Error> { self.log(|_| RenderCall::ScissorRect(rect)); self.state.set_scissors("set_scissor_rect", &[rect]) } - /// `setScissorRects:count:`. Each rectangle is clipped to the render area as - /// [`RenderCommandEncoder::set_scissor_rect`] clips it, and more than 16 are taken, as plain - /// Metal takes them where its validation stops them (Metal probe case `scissors_17` on an M4). - /// Refused (`Invalid`): no rectangle (unmeasured). A draw whose pipeline selects no viewport - /// draws through the first; one that selects draws each viewport through the rectangle of its - /// index, one rectangle serving every viewport and a viewport past two or more drawing nothing, - /// as plain Metal draws them where its validation stops a count other than 1 and the viewport - /// count (probes). - pub fn set_scissor_rects(&mut self, rects: &[ScissorRect]) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_scissor_rects`]. + pub(crate) fn set_scissor_rects(&mut self, rects: &[ScissorRect]) -> Result<(), Error> { self.log(|_| RenderCall::ScissorRects(rects.into())); self.state.set_scissors("set_scissor_rects", rects) } - /// `setCullMode:`. - pub fn set_cull_mode(&mut self, mode: CullMode) { + /// The lowering of [`RenderCommandEncoder::set_cull_mode`]. + pub(crate) fn set_cull_mode(&mut self, mode: CullMode) { self.log(|_| RenderCall::CullMode(mode)); self.state.set_cull_mode(mode); } - /// `setFrontFacingWinding:`. - pub fn set_front_facing_winding(&mut self, winding: Winding) { + /// The lowering of [`RenderCommandEncoder::set_front_facing_winding`]. + pub(crate) fn set_front_facing_winding(&mut self, winding: Winding) { self.log(|_| RenderCall::FrontFacingWinding(winding)); self.state.set_winding(winding); } - /// `setDepthStencilState:`: `state` is a `&DepthStencilState`, or `None` for nil, which - /// makes the encoder's state Metal's default again (a depth compare of `Always` without - /// writes, and no stencil test), as plain Metal draws after nil where its validation stops - /// it. Refused: a state of another device. A draw refuses a state that - /// writes depth in a pass without a depth attachment, or uses the stencil in one without a - /// stencil attachment (measured). - pub fn set_depth_stencil_state<'a>( + /// The lowering of [`RenderCommandEncoder::set_depth_stencil_state`]. + pub(crate) fn set_depth_stencil_state<'a>( &mut self, state: impl Into>, ) -> Result<(), Error> { @@ -2603,29 +2531,20 @@ impl RenderCommandEncoder { Ok(()) } - /// `setStencilReferenceValue:`: both faces' reference, saturated at 255 as Metal's is - /// (measured). - pub fn set_stencil_reference_value(&mut self, value: u32) { + /// The lowering of [`RenderCommandEncoder::set_stencil_reference_value`]. + pub(crate) fn set_stencil_reference_value(&mut self, value: u32) { self.log(|_| RenderCall::StencilReferenceValue(value)); self.state.set_stencil_references(value, value); } - /// `setStencilFrontReferenceValue:backReferenceValue:`, saturated at 255 as Metal's are. - pub fn set_stencil_reference_values(&mut self, front: u32, back: u32) { + /// The lowering of [`RenderCommandEncoder::set_stencil_reference_values`]. + pub(crate) fn set_stencil_reference_values(&mut self, front: u32, back: u32) { self.log(|_| RenderCall::StencilReferenceValues(front, back)); self.state.set_stencil_references(front, back); } - /// `setDepthBias:slopeScale:clamp:`. NaN and infinite factors give Metal's measured depths: a - /// NaN constant biases as +inf; an unbounded infinite or NaN bias saturates the depth (at 1 or - /// 0, in depth clamp mode at the viewport's larger or smaller depth); a NaN or infinite clamp - /// clamps nothing; a clamp that bounds an infinite or NaN bias adds itself to the depth. - /// Refused `NotImplemented(NonFiniteDepthBias)`: factors whose effect differs between flat and - /// sloped triangles (an infinite slope factor against an unbounded or opposite clamp, or - /// against the opposite infinite constant); and at a draw of triangles, a clamp's addition that - /// moves a viewport's depth range past `[0, 1]` or that depth clamp mode bounds. A draw refuses - /// a clamp other than 0 on a device without `depthBiasClamp` (`Unsupported`). - pub fn set_depth_bias( + /// The lowering of [`RenderCommandEncoder::set_depth_bias`]. + pub(crate) fn set_depth_bias( &mut self, depth_bias: f32, slope_scale: f32, @@ -2635,36 +2554,28 @@ impl RenderCommandEncoder { self.state.set_depth_bias(depth_bias, slope_scale, clamp) } - /// `setDepthClipMode:`. `Clamp` needs `depthClamp` (`Unsupported`). - pub fn set_depth_clip_mode(&mut self, mode: DepthClipMode) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_depth_clip_mode`]. + pub(crate) fn set_depth_clip_mode(&mut self, mode: DepthClipMode) -> Result<(), Error> { self.log(|_| RenderCall::DepthClipMode(mode)); let profile = self.core.device().compile_device().profile(); self.state.set_clip_mode(mode, profile) } - /// `setTriangleFillMode:`. `Lines` needs `fillModeNonSolid` (`Unsupported`). - pub fn set_triangle_fill_mode(&mut self, mode: TriangleFillMode) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_triangle_fill_mode`]. + pub(crate) fn set_triangle_fill_mode(&mut self, mode: TriangleFillMode) -> Result<(), Error> { self.log(|_| RenderCall::TriangleFillMode(mode)); let profile = self.core.device().compile_device().profile(); self.state.set_fill_mode(mode, profile) } - /// `setBlendColorRed:green:blue:alpha:`. - pub fn set_blend_color(&mut self, red: f32, green: f32, blue: f32, alpha: f32) { + /// The lowering of [`RenderCommandEncoder::set_blend_color`]. + pub(crate) fn set_blend_color(&mut self, red: f32, green: f32, blue: f32, alpha: f32) { self.log(|_| RenderCall::BlendColor([red, green, blue, alpha])); self.state.set_blend_color([red, green, blue, alpha]); } - /// `setTessellationFactorBuffer:offset:instanceStride:` (`tessellation.rs`): the factors a - /// patch draw reads, `None` for `nil`, from the offset rounded down to a multiple of 2, each - /// instance's at the instance stride rounded down to a multiple of 4: Metal's validation stops - /// an offset or a stride that is not a multiple of 4, but plain Metal reads an offset of 2 at - /// that byte (Metal probe case `factor_offset_2` on an M4), an odd one from the byte below (1 - /// read from 0, 3 from 2, 7 from 6), and steps the instances by a stride rounded down to a - /// multiple of 4 (Metal probes: strides 2 and 14 drew what 0 and 12 draw, 6 and 10 what 4 and 8 - /// draw: 13 and 15 what 12 draws, 17 and 19 what 16 draws). Refused (`Invalid`) for a buffer of - /// another device, keeping the buffer set before. - pub fn set_tessellation_factor_buffer( + /// The lowering of [`RenderCommandEncoder::set_tessellation_factor_buffer`]. + pub(crate) fn set_tessellation_factor_buffer( &mut self, buffer: Option<&Buffer>, offset: u64, @@ -2685,26 +2596,14 @@ impl RenderCommandEncoder { Ok(()) } - /// `setTessellationFactorScale:` (`tessellation.rs`), which a pipeline that enables - /// `tessellationFactorScaleEnabled` multiplies its factors by, rounded to `half` as Metal - /// rounds it (one infinite as a `half` takes the factors to the maximum, and one that is 0, - /// negative or NaN as a `half` culls every patch; and a Metal probe - /// on an M4). Every scale is taken, as plain Metal takes those its validation stops (0, a - /// negative one, NaN, an infinity and a subnormal `float`; Metal probes on an M4): each culls - /// or draws as its `half` does under a pipeline that enables the scale, and a pipeline that - /// does not draws as before. - pub fn set_tessellation_factor_scale(&mut self, scale: f32) { + /// The lowering of [`RenderCommandEncoder::set_tessellation_factor_scale`]. + pub(crate) fn set_tessellation_factor_scale(&mut self, scale: f32) { self.log(|_| RenderCall::TessellationFactorScale(scale)); self.factors.scale = Some(scale); } - /// `setVertexAmplificationCount:viewMappings:` (`amplification.rs`): each later draw - /// processes its vertices `count` times, amplification `a` offset by `view_mappings[a]` - /// (`None` for `nil`, offsets of 0). Refused (`Invalid`): fewer mappings than `count`. A - /// draw draws a count above its pipeline's `maxVertexAmplificationCount` as plain Metal does - /// where its validation stops it, and refuses one above a maximum of 1 or above 8 - /// (`DrawProblem::AmplificationCount`); a refused call keeps the amplification set before. - pub fn set_vertex_amplification_count( + /// The lowering of [`RenderCommandEncoder::set_vertex_amplification_count`]. + pub(crate) fn set_vertex_amplification_count( &mut self, count: u64, view_mappings: Option<&[VertexAmplificationViewMapping]>, @@ -2715,10 +2614,8 @@ impl RenderCommandEncoder { Ok(()) } - /// `drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:` (Metal's shorter - /// forms take one instance and a base instance of 0). A draw of no vertices or no instances - /// records nothing (the module docs). Refused as the module docs say. - pub fn draw_primitives( + /// The lowering of [`RenderCommandEncoder::draw_primitives`]. + pub(crate) fn draw_primitives( &mut self, primitive_type: PrimitiveType, vertex_start: u32, @@ -2748,14 +2645,8 @@ impl RenderCommandEncoder { self.draw(CALL, assembly, draw, buffers, empty) } - /// `drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount: - /// baseVertex:baseInstance:` (Metal's shorter forms take one instance and a base vertex and - /// instance of 0). Index positions past the buffer's length draw as the module docs say, and - /// the indices are read from the offset's low 32 bits rounded down to a multiple of the index - /// size, as plain Metal reads them (an M4 read an offset of 2^32 + 16 into a buffer past 4 GiB - /// at 16). A draw of no indices or no instances records nothing. Refused as the - /// module docs say, and for an index buffer of another device. - pub fn draw_indexed_primitives( + /// The lowering of [`RenderCommandEncoder::draw_indexed_primitives`]. + pub(crate) fn draw_indexed_primitives( &mut self, primitive_type: PrimitiveType, index_count: u32, @@ -2840,10 +2731,8 @@ impl RenderCommandEncoder { self.draw(call, assembly, draw, buffers, empty) } - /// `drawPrimitives:indirectBuffer:indirectBufferOffset:`: Metal's - /// `MTLDrawPrimitivesIndirectArguments` at `indirect_buffer_offset`. Refused as the module - /// docs say, and for an indirect buffer of another device. - pub fn draw_primitives_indirect( + /// The lowering of [`RenderCommandEncoder::draw_primitives_indirect`]. + pub(crate) fn draw_primitives_indirect( &mut self, primitive_type: PrimitiveType, indirect_buffer: &Buffer, @@ -2874,13 +2763,8 @@ impl RenderCommandEncoder { self.draw(CALL, assembly, draw, buffers, false) } - /// `drawIndexedPrimitives:indexType:indexBuffer:indexBufferOffset:indirectBuffer: - /// indirectBufferOffset:`: Metal's `MTLDrawIndexedPrimitivesIndirectArguments` at - /// `indirect_buffer_offset`, drawing `index_type` indices of `index_buffer` from - /// `index_buffer_offset`, those past the buffer's length as the module docs say, each offset - /// rounded down as the direct draws' are. Refused as the module docs say, and for buffers of - /// another device. - pub fn draw_indexed_primitives_indirect( + /// The lowering of [`RenderCommandEncoder::draw_indexed_primitives_indirect`]. + pub(crate) fn draw_indexed_primitives_indirect( &mut self, primitive_type: PrimitiveType, index_type: IndexType, @@ -2972,18 +2856,8 @@ impl RenderCommandEncoder { self.draw(CALL, assembly, draw, buffers, false) } - /// `drawPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:instanceCount: - /// baseInstance:` of a tessellation pipeline (`tessellation.rs`): `patch_count` patches of - /// `number_of_patch_control_points` control points from `patch_start`, `instance_count` - /// instances from `base_instance`, patch `i` the one the patch index buffer's `uint` at - /// `patch_start + i` names where one is given (its factors stay at `patch_start + i`), read - /// from its offset rounded down to a multiple of 4 as plain Metal reads it. A draw of no - /// patches or no instances records nothing; the draw's control points are its pipeline's where - /// its function states them, and a pipeline with a control-point index type reads every control - /// point's index as 0, as plain Metal draws them. Refused as the module docs say, for a patch - /// index buffer of another device, and as Metal's validation refuses it (`Invalid`, measured): - /// indices `patch_start + patch_count` past the buffer from the offset. - pub fn draw_patches( + /// The lowering of [`RenderCommandEncoder::draw_patches`]. + pub(crate) fn draw_patches( &mut self, number_of_patch_control_points: u32, patch_start: u32, @@ -3069,16 +2943,8 @@ impl RenderCommandEncoder { self.draw(call, Assembly::Patches, draw, buffers, empty) } - /// `drawPatches:patchIndexBuffer:patchIndexBufferOffset:indirectBuffer: - /// indirectBufferOffset:` of a tessellation pipeline: Metal's `MTLDrawPatchIndirectArguments` - /// at `indirect_buffer_offset` (a `VkDrawIndirectCommand`'s layout). Refused as - /// [`RenderCommandEncoder::draw_patches`] and [`RenderCommandEncoder::draw_primitives_indirect`] - /// are, but for the patch indices past the buffer, whose count the arguments hold: a patch - /// whose index lies past the buffer's length reads patch index 0 (Metal reads memory past the - /// buffer there, which its validation does not check). A pipeline with a control-point index - /// type, which Metal's validation stops, reads every index as 0, as the direct draw does (a - /// Metal probe `cpi_plain_typed_indirect`). - pub fn draw_patches_indirect( + /// The lowering of [`RenderCommandEncoder::draw_patches_indirect`]. + pub(crate) fn draw_patches_indirect( &mut self, number_of_patch_control_points: u32, patch_index_buffer: Option<&Buffer>, @@ -3122,20 +2988,8 @@ impl RenderCommandEncoder { self.draw(CALL, Assembly::Patches, draw, buffers, false) } - /// `drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset: - /// controlPointIndexBuffer:controlPointIndexBufferOffset:instanceCount:baseInstance:` of a - /// tessellation pipeline whose `tessellationControlPointIndexType` is not `None`: as - /// [`RenderCommandEncoder::draw_patches`], but control point `k` of the patch whose index is - /// `p` is the index (of the pipeline's type) at position `p · N + k` of the control-point index - /// buffer from its offset (measured), `N` the pipeline's control points where its function - /// states them, an offset that is not a multiple of the index size rounded down to one, as - /// plain Metal reads it, where its validation stops the draw. A pipeline whose type is `None`, - /// which Metal's validation stops, draws the patches' own control points, the buffer unread, as - /// plain Metal draws them (Metal probe case `indexed_without_type` on an M4). Refused as - /// `draw_patches` is, for a control-point index buffer of another device, and as Metal's - /// validation refuses it (`Invalid`, measured): `(patch_start + patch_count) · N` indices past - /// the buffer from the offset. - pub fn draw_indexed_patches( + /// The lowering of [`RenderCommandEncoder::draw_indexed_patches`]. + pub(crate) fn draw_indexed_patches( &mut self, number_of_patch_control_points: u32, patch_start: u32, @@ -3200,17 +3054,8 @@ impl RenderCommandEncoder { ) } - /// `drawIndexedPatches:patchIndexBuffer:patchIndexBufferOffset:controlPointIndexBuffer: - /// controlPointIndexBufferOffset:indirectBuffer:indirectBufferOffset:` of a tessellation - /// pipeline whose `tessellationControlPointIndexType` is not `None`: the arguments of - /// [`RenderCommandEncoder::draw_patches_indirect`], the control points of - /// [`RenderCommandEncoder::draw_indexed_patches`]. Refused as both are, but for the indices - /// past the buffers, whose counts the arguments hold: an index that lies past the buffer's - /// length reads 0 (Metal reads memory past the buffer there, which its validation does not - /// check). A pipeline without a control-point index type, which Metal's validation stops, draws - /// the patches' own control points, the buffer unread, as the direct draw does (a Metal probe - /// `cpi_indexed_untyped_indirect`). - pub fn draw_indexed_patches_indirect( + /// The lowering of [`RenderCommandEncoder::draw_indexed_patches_indirect`]. + pub(crate) fn draw_indexed_patches_indirect( &mut self, number_of_patch_control_points: u32, patch_index_buffer: Option<&Buffer>, @@ -3390,18 +3235,8 @@ impl RenderCommandEncoder { Ok(offset) } - /// `setVisibilityResultMode:offset:` (`visibility.rs`). An offset that is not a multiple of 8 - /// is rounded down to one, where plain Metal writes the result (measured on an M4). Refused - /// (`Invalid`, measured) for `Boolean` and `Counting`: a pass without a visibility result - /// buffer, an offset whose 8 bytes run past the buffer, an offset the encoder took before. - /// `Counting` is `Unsupported` where the device lacks `occlusionQueryPrecise`. A refused call - /// keeps the mode set before. While a mode other than `Disabled` is set, amplified draws draw - /// one amplification at a time, whose samples the one query counts as Metal's does - /// (`VertexAmplification::one_at_a_time`); a mode set after a draw amplified as views begins - /// its query in a new instance of the pass's layers, since a query in a multiview instance - /// takes one query per view. Where the device draws the pass's colors in groups, the first - /// group's pass counts the results (`render/color_groups.rs`). - pub fn set_visibility_result_mode( + /// The lowering of [`RenderCommandEncoder::set_visibility_result_mode`]. + pub(crate) fn set_visibility_result_mode( &mut self, mode: VisibilityResultMode, offset: u64, @@ -3474,13 +3309,8 @@ impl RenderCommandEncoder { Ok(()) } - /// `endEncoding`: begin the pass with its load and store operations, run the draws, and end it. - /// A store action still `Unknown` is `DontCare`, as plain Metal stores it where its validation - /// stops it: a color attachment's (measured on an M4), and a depth or stencil attachment's, - /// resolving or not; a resolve texture is left untouched, as plain Metal leaves it. The encoder - /// is consumed either way, so a refusal leaves its command buffer abandoned, as Metal stops - /// there. - pub fn end_encoding(self) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::end_encoding`]. + pub(crate) fn end_encoding(self) -> Result<(), Error> { self.core.device().shared().counts.render_encoder_ended(); // And the pass's later color groups, where it draws in groups (`render/color_groups.rs`). let (core, residency, log) = self.end_pass()?.with_later_groups()?; @@ -3505,7 +3335,7 @@ impl RenderCommandEncoder { command_buffer: &CommandBuffer, descriptor: &RenderPassDescriptor, residency: Residency, - ) -> Result { + ) -> Result { command_buffer.open_render(descriptor, Some(residency)) } @@ -3540,7 +3370,7 @@ impl RenderCommandEncoder { // Whether a command of the pass may read an attachment's bytes it did not name. let unnamed_reads = self.barrier_inside || self.reaches_unnamed || !self.executions.is_empty(); - let RenderCommandEncoder { + let RenderLowering { mut core, mut earlier, current, @@ -9380,6 +9210,673 @@ impl RenderCommandEncoder { } } +impl RenderCommandEncoder { + /// `setRenderPipelineState:`. Refused (`Invalid`, measured: Metal's validation stops the + /// call): a color pixel format other than the pass's, as `DrawProblem::AttachmentFormat` + /// says (plain Metal stores each place of the state's per-sample record into the pass's + /// attachment at that place, writes zero bytes at every sample a draw covers to a pass color + /// at no place where its code reads no attachment and keeps it otherwise, and drops the + /// output of a state color at no place, as the runtime does; it draws a color whose format is + /// the pass's in another channel order, such as `RGBA8Unorm` into `BGRA8Unorm`, in the pass's + /// channel order; it takes the pass's depth and stencil attachments whatever depth and stencil + /// formats the state names), the raster sample count other than the pass's + /// (`DrawProblem::SampleCount`; plain Metal draws a render pipeline's state of more samples in + /// a pass of one as a state of one sample, as the runtime does, but for alpha to coverage and + /// `get_num_samples()`, which read the state's count, and stay refused), and a tile pipeline's + /// state whose function aliases an explicit imageblock onto its implicit one, or a drawing + /// state whose fragment function declares an explicit imageblock, of more imageblock bytes per + /// sample than the pass gives (`DrawProblem::ImageblockSampleLength`; a tile state whose + /// explicit imageblock stands alone runs there, as plain Metal runs it). Refused + /// `NotImplemented` where the formats agree in Metal's terms but not in Vulkan's, and for a + /// state of another device; `Unsupported` (`IndependentBlending`) where the pass has a color + /// the state keeps unwritten and the device lacks `independentBlend`. Where the device draws + /// the pass's colors in groups (`render/color_groups.rs`), refused `NotImplemented` + /// (`ColorAttachmentGroups`) for a drawing state whose colors with a pixel format are not the + /// pass's colors with a texture, and for a tile pipeline's state; and for a drawing state the + /// device draws in groups in a pass it draws in one. Metal's validation stops a state whose + /// color formats are not the pass's attachments' where both name one, as above; where one side + /// names none it draws (a color without an attachment nowhere, a pass color without a format + /// as zeroes), which the groups' variants do not state. A refused call keeps the state set + /// before. + pub fn set_render_pipeline_state(&mut self, state: &RenderPipelineState) -> Result<(), Error> { + self.lowering.set_render_pipeline_state(state) + } + + /// `setVertexBuffer:offset:atIndex:` (`None` unbinds the index). Refused: an index past the + /// table, an offset past the buffer's length, a buffer of another device. + pub fn set_vertex_buffer( + &mut self, + buffer: Option<&Buffer>, + offset: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_vertex_buffer(buffer, offset, index) + } + + /// `setVertexBuffers:offsets:withRange:`. Refused as + /// [`RenderCommandEncoder::set_vertex_buffer`] is, and when the slices' lengths differ; a + /// refusal binds none of them. + pub fn set_vertex_buffers( + &mut self, + buffers: &[Option<&Buffer>], + offsets: &[u64], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_vertex_buffers(buffers, offsets, first) + } + + /// `setVertexBufferOffset:atIndex:`, which clears the index's attribute stride + /// (`render/vertex_strides.rs`). At an index holding a visible-function table, the stage then + /// reads the null table there (size 0, every entry null) until a table or buffer is bound at + /// the index again, as plain Metal reads it. At an index holding inline bytes + /// ([`set_vertex_bytes`](Self::set_vertex_bytes)), they then read as zeros at any offset until + /// the index is bound again, as plain Metal reads them (an M4; its debug layer asserts there is + /// no buffer). Refused: nothing bound at the index, an offset past the buffer's length. + pub fn set_vertex_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + self.lowering.set_vertex_buffer_offset(offset, index) + } + + /// `setVertexBytes:length:atIndex:`: `bytes`, copied now, at vertex buffer index `index` in + /// place of anything bound there, so a later write of the caller's memory reaches no draw, as + /// Metal copies them at the call. Every later draw reads the copy until the index is bound + /// again, as a buffer argument or as a vertex descriptor's buffer; a layout of + /// `MTLBufferLayoutStrideDynamic` reads it at stride 0, as a buffer bound without a stride + /// (`render/vertex_strides.rs`). A slot the stage reaches through a pointer loaded from + /// memory (one of a device-address form) cannot read inline bytes: + /// `Bind(MissingDeviceAddress)`, at the draw. Refused: an index past the table, and more than + /// 4096 bytes, Metal's limit for inline bytes (`Invalid(InlineBytesLength)`). + pub fn set_vertex_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + self.lowering.set_vertex_bytes(bytes, index) + } + + /// `setVertexTexture:atIndex:` (`None` unbinds the index). Refused: an index past the table, + /// a texture of another device. + pub fn set_vertex_texture( + &mut self, + texture: Option<&Texture>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_vertex_texture(texture, index) + } + + /// `setVertexTextures:withRange:`. Refused as [`RenderCommandEncoder::set_vertex_texture`] + /// is; a refusal binds none of them. + pub fn set_vertex_textures( + &mut self, + textures: &[Option<&Texture>], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_vertex_textures(textures, first) + } + + /// `setVertexSamplerState:atIndex:` (`None` unbinds the index). Refused: an index past the + /// table, a state of another device. + pub fn set_vertex_sampler_state( + &mut self, + sampler: Option<&SamplerState>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_vertex_sampler_state(sampler, index) + } + + /// `setVertexSamplerStates:withRange:`, or with `clamps` (minimums and maximums) + /// `setVertexSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as + /// [`RenderCommandEncoder::set_vertex_sampler_state`] is, and when the slices' lengths differ; + /// a refusal binds none of them. + pub fn set_vertex_sampler_states( + &mut self, + samplers: &[Option<&SamplerState>], + clamps: Option<(&[f32], &[f32])>, + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_vertex_sampler_states(samplers, clamps, first) + } + + /// `setFragmentBuffer:offset:atIndex:` (`None` unbinds the index). Refused as + /// [`RenderCommandEncoder::set_vertex_buffer`] is. + pub fn set_fragment_buffer( + &mut self, + buffer: Option<&Buffer>, + offset: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_fragment_buffer(buffer, offset, index) + } + + /// `setFragmentBuffers:offsets:withRange:`. Refused as + /// [`RenderCommandEncoder::set_vertex_buffers`] is. + pub fn set_fragment_buffers( + &mut self, + buffers: &[Option<&Buffer>], + offsets: &[u64], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_fragment_buffers(buffers, offsets, first) + } + + /// `setFragmentBufferOffset:atIndex:`. Refused as + /// [`RenderCommandEncoder::set_vertex_buffer_offset`] is. + pub fn set_fragment_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + self.lowering.set_fragment_buffer_offset(offset, index) + } + + /// `setFragmentBytes:length:atIndex:`: as + /// [`set_vertex_bytes`](Self::set_vertex_bytes), in the fragment stage's table. Refused as + /// that is. + pub fn set_fragment_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + self.lowering.set_fragment_bytes(bytes, index) + } + + /// `setFragmentTexture:atIndex:` (`None` unbinds the index). Refused as + /// [`RenderCommandEncoder::set_vertex_texture`] is. + pub fn set_fragment_texture( + &mut self, + texture: Option<&Texture>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_fragment_texture(texture, index) + } + + /// `setFragmentTextures:withRange:`. Refused as + /// [`RenderCommandEncoder::set_vertex_textures`] is. + pub fn set_fragment_textures( + &mut self, + textures: &[Option<&Texture>], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_fragment_textures(textures, first) + } + + /// `setFragmentSamplerState:atIndex:` (`None` unbinds the index). Refused as + /// [`RenderCommandEncoder::set_vertex_sampler_state`] is. + pub fn set_fragment_sampler_state( + &mut self, + sampler: Option<&SamplerState>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_fragment_sampler_state(sampler, index) + } + + /// `setFragmentSamplerStates:withRange:`, or with `clamps` + /// `setFragmentSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as + /// [`RenderCommandEncoder::set_vertex_sampler_states`] is. + pub fn set_fragment_sampler_states( + &mut self, + samplers: &[Option<&SamplerState>], + clamps: Option<(&[f32], &[f32])>, + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_fragment_sampler_states(samplers, clamps, first) + } + + /// `setColorStoreAction:atIndex:`: the store action of color attachment `index`, which the + /// descriptor left `Unknown`. As plain Metal does where its validation stops the call (measured + /// on an M4): for an attachment without a texture, or over an action the descriptor knew, + /// nothing changes; a resolving action where nothing resolves resolves nothing + /// (`MultisampleResolve` keeps no sample, `StoreAndMultisampleResolve` stores them); and one + /// that does not resolve where a resolve texture is named leaves that texture untouched. + /// Refused (`Invalid`, measured): an index past the attachments, `Unknown` itself, and `Store` + /// or `StoreAndMultisampleResolve` for a memoryless attachment. + pub fn set_color_store_action(&mut self, action: StoreAction, index: u32) -> Result<(), Error> { + self.lowering.set_color_store_action(action, index) + } + + /// `setDepthStoreAction:`: the depth attachment's store action, which the descriptor left + /// `Unknown`; without a depth attachment nothing changes, as plain Metal does where its + /// validation stops the call (measured on an M4); one that does not resolve where a resolve + /// texture is named leaves that texture untouched and stores the depth by the action, as plain + /// Metal does where its validation stops it. Refused (`Invalid`, measured): + /// an action over one the descriptor knew, `Unknown` itself, a resolving action without a + /// resolve texture, `Store` for a memoryless attachment, and `Store` where the stencil + /// attachment is the same texture resolved by `MultisampleResolve`. + pub fn set_depth_store_action(&mut self, action: StoreAction) -> Result<(), Error> { + self.lowering.set_depth_store_action(action) + } + + /// `setStencilStoreAction:`: the stencil attachment's store action, which the descriptor + /// left `Unknown`. Refused as [`RenderCommandEncoder::set_depth_store_action`] is, but for + /// the last: here `MultisampleResolve` where the depth attachment is the same texture, + /// stored; and without a stencil attachment (unmeasured). + pub fn set_stencil_store_action(&mut self, action: StoreAction) -> Result<(), Error> { + self.lowering.set_stencil_store_action(action) + } + + /// `setColorStoreActionOptions:atIndex:`: the color attachment's store action options, which + /// change nothing, as plain Metal's: Apple's GPUs ignore them, and plain Metal takes them over + /// a store action the descriptor knew and under one that keeps no samples, where its validation + /// stops them (measured on an M4, `sample_positions.rs`). Refused (`Invalid`): an index past + /// the attachments and an attachment without a texture (unmeasured). + pub fn set_color_store_action_options( + &mut self, + _options: StoreActionOptions, + index: u32, + ) -> Result<(), Error> { + self.lowering + .set_color_store_action_options(_options, index) + } + + /// `setDepthStoreActionOptions:`: the depth attachment's store action options, where the + /// descriptor left its store action `Unknown`; they change nothing, as plain Metal's (Metal + /// probe case `opt_depth_late` on an M4). Refused (`Invalid`, measured): an attachment without + /// a texture, and one whose descriptor knew its store action. + pub fn set_depth_store_action_options( + &mut self, + options: StoreActionOptions, + ) -> Result<(), Error> { + self.lowering.set_depth_store_action_options(options) + } + + /// `setStencilStoreActionOptions:`: the stencil attachment's store action options. Refused + /// as [`RenderCommandEncoder::set_depth_store_action_options`] is; `end_encoding` refuses + /// `CustomSamplePositions` under a store action that keeps no samples (unmeasured for a + /// stencil attachment, `sample_positions.rs`). + pub fn set_stencil_store_action_options( + &mut self, + options: StoreActionOptions, + ) -> Result<(), Error> { + self.lowering.set_stencil_store_action_options(options) + } + + /// `setViewport:`. A NaN origin x draws nothing, as plain Metal's where its validation stops it + /// (measured on an M4). Refused (`Invalid`, measured): any other NaN or infinite field. A depth + /// range past `[0, 1]` is refused on a device that takes it neither natively nor by the vertex + /// stage's compensation: `NotImplemented` without the features, `Unsupported` on a driver that + /// draws the compensated depths inexactly (`render_state.rs`). A refused call keeps the + /// viewports set before. + pub fn set_viewport(&mut self, viewport: Viewport) -> Result<(), Error> { + self.lowering.set_viewport(viewport) + } + + /// `setViewports:count:`. Refused as [`RenderCommandEncoder::set_viewport`] is, and for a + /// count outside 1 to 16 (measured). On a device without `multiViewport`, a draw that selects + /// among more than one viewport (its vertex function writes `[[viewport_array_index]]`, or an + /// amplification's mapping offsets the viewport) is refused at the draw, + /// `Unsupported(LayeredRendering)` needing the feature; with one it draws through it. + pub fn set_viewports(&mut self, viewports: &[Viewport]) -> Result<(), Error> { + self.lowering.set_viewports(viewports) + } + + /// `setScissorRect:`. A rectangle past the render area is clipped to it, as plain Metal clips + /// it where its validation stops the call (measured on an M4). + pub fn set_scissor_rect(&mut self, rect: ScissorRect) -> Result<(), Error> { + self.lowering.set_scissor_rect(rect) + } + + /// `setScissorRects:count:`. Each rectangle is clipped to the render area as + /// [`RenderCommandEncoder::set_scissor_rect`] clips it, and more than 16 are taken, as plain + /// Metal takes them where its validation stops them (Metal probe case `scissors_17` on an M4). + /// Refused (`Invalid`): no rectangle (unmeasured). A draw whose pipeline selects no viewport + /// draws through the first; one that selects draws each viewport through the rectangle of its + /// index, one rectangle serving every viewport and a viewport past two or more drawing nothing, + /// as plain Metal draws them where its validation stops a count other than 1 and the viewport + /// count (probes). + pub fn set_scissor_rects(&mut self, rects: &[ScissorRect]) -> Result<(), Error> { + self.lowering.set_scissor_rects(rects) + } + + /// `setCullMode:`. + pub fn set_cull_mode(&mut self, mode: CullMode) { + self.lowering.set_cull_mode(mode) + } + + /// `setFrontFacingWinding:`. + pub fn set_front_facing_winding(&mut self, winding: Winding) { + self.lowering.set_front_facing_winding(winding) + } + + /// `setDepthStencilState:`: `state` is a `&DepthStencilState`, or `None` for nil, which + /// makes the encoder's state Metal's default again (a depth compare of `Always` without + /// writes, and no stencil test), as plain Metal draws after nil where its validation stops + /// it. Refused: a state of another device. A draw refuses a state that + /// writes depth in a pass without a depth attachment, or uses the stencil in one without a + /// stencil attachment (measured). + pub fn set_depth_stencil_state<'a>( + &mut self, + state: impl Into>, + ) -> Result<(), Error> { + self.lowering.set_depth_stencil_state(state) + } + + /// `setStencilReferenceValue:`: both faces' reference, saturated at 255 as Metal's is + /// (measured). + pub fn set_stencil_reference_value(&mut self, value: u32) { + self.lowering.set_stencil_reference_value(value) + } + + /// `setStencilFrontReferenceValue:backReferenceValue:`, saturated at 255 as Metal's are. + pub fn set_stencil_reference_values(&mut self, front: u32, back: u32) { + self.lowering.set_stencil_reference_values(front, back) + } + + /// `setDepthBias:slopeScale:clamp:`. NaN and infinite factors give Metal's measured depths: a + /// NaN constant biases as +inf; an unbounded infinite or NaN bias saturates the depth (at 1 or + /// 0, in depth clamp mode at the viewport's larger or smaller depth); a NaN or infinite clamp + /// clamps nothing; a clamp that bounds an infinite or NaN bias adds itself to the depth. + /// Refused `NotImplemented(NonFiniteDepthBias)`: factors whose effect differs between flat and + /// sloped triangles (an infinite slope factor against an unbounded or opposite clamp, or + /// against the opposite infinite constant); and at a draw of triangles, a clamp's addition that + /// moves a viewport's depth range past `[0, 1]` or that depth clamp mode bounds. A draw refuses + /// a clamp other than 0 on a device without `depthBiasClamp` (`Unsupported`). + pub fn set_depth_bias( + &mut self, + depth_bias: f32, + slope_scale: f32, + clamp: f32, + ) -> Result<(), Error> { + self.lowering.set_depth_bias(depth_bias, slope_scale, clamp) + } + + /// `setDepthClipMode:`. `Clamp` needs `depthClamp` (`Unsupported`). + pub fn set_depth_clip_mode(&mut self, mode: DepthClipMode) -> Result<(), Error> { + self.lowering.set_depth_clip_mode(mode) + } + + /// `setTriangleFillMode:`. `Lines` needs `fillModeNonSolid` (`Unsupported`). + pub fn set_triangle_fill_mode(&mut self, mode: TriangleFillMode) -> Result<(), Error> { + self.lowering.set_triangle_fill_mode(mode) + } + + /// `setBlendColorRed:green:blue:alpha:`. + pub fn set_blend_color(&mut self, red: f32, green: f32, blue: f32, alpha: f32) { + self.lowering.set_blend_color(red, green, blue, alpha) + } + + /// `setTessellationFactorBuffer:offset:instanceStride:` (`tessellation.rs`): the factors a + /// patch draw reads, `None` for `nil`, from the offset rounded down to a multiple of 2, each + /// instance's at the instance stride rounded down to a multiple of 4: Metal's validation stops + /// an offset or a stride that is not a multiple of 4, but plain Metal reads an offset of 2 at + /// that byte (Metal probe case `factor_offset_2` on an M4), an odd one from the byte below (1 + /// read from 0, 3 from 2, 7 from 6), and steps the instances by a stride rounded down to a + /// multiple of 4 (Metal probes: strides 2 and 14 drew what 0 and 12 draw, 6 and 10 what 4 and 8 + /// draw: 13 and 15 what 12 draws, 17 and 19 what 16 draws). Refused (`Invalid`) for a buffer of + /// another device, keeping the buffer set before. + pub fn set_tessellation_factor_buffer( + &mut self, + buffer: Option<&Buffer>, + offset: u64, + instance_stride: u64, + ) -> Result<(), Error> { + self.lowering + .set_tessellation_factor_buffer(buffer, offset, instance_stride) + } + + /// `setTessellationFactorScale:` (`tessellation.rs`), which a pipeline that enables + /// `tessellationFactorScaleEnabled` multiplies its factors by, rounded to `half` as Metal + /// rounds it (one infinite as a `half` takes the factors to the maximum, and one that is 0, + /// negative or NaN as a `half` culls every patch; and a Metal probe + /// on an M4). Every scale is taken, as plain Metal takes those its validation stops (0, a + /// negative one, NaN, an infinity and a subnormal `float`; Metal probes on an M4): each culls + /// or draws as its `half` does under a pipeline that enables the scale, and a pipeline that + /// does not draws as before. + pub fn set_tessellation_factor_scale(&mut self, scale: f32) { + self.lowering.set_tessellation_factor_scale(scale) + } + + /// `setVertexAmplificationCount:viewMappings:` (`amplification.rs`): each later draw + /// processes its vertices `count` times, amplification `a` offset by `view_mappings[a]` + /// (`None` for `nil`, offsets of 0). Refused (`Invalid`): fewer mappings than `count`. A + /// draw draws a count above its pipeline's `maxVertexAmplificationCount` as plain Metal does + /// where its validation stops it, and refuses one above a maximum of 1 or above 8 + /// (`DrawProblem::AmplificationCount`); a refused call keeps the amplification set before. + pub fn set_vertex_amplification_count( + &mut self, + count: u64, + view_mappings: Option<&[VertexAmplificationViewMapping]>, + ) -> Result<(), Error> { + self.lowering + .set_vertex_amplification_count(count, view_mappings) + } + + /// `drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:` (Metal's shorter + /// forms take one instance and a base instance of 0). A draw of no vertices or no instances + /// records nothing (the module docs). Refused as the module docs say. + pub fn draw_primitives( + &mut self, + primitive_type: PrimitiveType, + vertex_start: u32, + vertex_count: u32, + instance_count: u32, + base_instance: u32, + ) -> Result<(), Error> { + self.lowering.draw_primitives( + primitive_type, + vertex_start, + vertex_count, + instance_count, + base_instance, + ) + } + + /// `drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount: + /// baseVertex:baseInstance:` (Metal's shorter forms take one instance and a base vertex and + /// instance of 0). Index positions past the buffer's length draw as the module docs say, and + /// the indices are read from the offset's low 32 bits rounded down to a multiple of the index + /// size, as plain Metal reads them (an M4 read an offset of 2^32 + 16 into a buffer past 4 GiB + /// at 16). A draw of no indices or no instances records nothing. Refused as the + /// module docs say, and for an index buffer of another device. + pub fn draw_indexed_primitives( + &mut self, + primitive_type: PrimitiveType, + index_count: u32, + index_type: IndexType, + index_buffer: &Buffer, + index_buffer_offset: u64, + instance_count: u32, + base_vertex: i32, + base_instance: u32, + ) -> Result<(), Error> { + self.lowering.draw_indexed_primitives( + primitive_type, + index_count, + index_type, + index_buffer, + index_buffer_offset, + instance_count, + base_vertex, + base_instance, + ) + } + + /// `drawPrimitives:indirectBuffer:indirectBufferOffset:`: Metal's + /// `MTLDrawPrimitivesIndirectArguments` at `indirect_buffer_offset`. Refused as the module + /// docs say, and for an indirect buffer of another device. + pub fn draw_primitives_indirect( + &mut self, + primitive_type: PrimitiveType, + indirect_buffer: &Buffer, + indirect_buffer_offset: u64, + ) -> Result<(), Error> { + self.lowering.draw_primitives_indirect( + primitive_type, + indirect_buffer, + indirect_buffer_offset, + ) + } + + /// `drawIndexedPrimitives:indexType:indexBuffer:indexBufferOffset:indirectBuffer: + /// indirectBufferOffset:`: Metal's `MTLDrawIndexedPrimitivesIndirectArguments` at + /// `indirect_buffer_offset`, drawing `index_type` indices of `index_buffer` from + /// `index_buffer_offset`, those past the buffer's length as the module docs say, each offset + /// rounded down as the direct draws' are. Refused as the module docs say, and for buffers of + /// another device. + pub fn draw_indexed_primitives_indirect( + &mut self, + primitive_type: PrimitiveType, + index_type: IndexType, + index_buffer: &Buffer, + index_buffer_offset: u64, + indirect_buffer: &Buffer, + indirect_buffer_offset: u64, + ) -> Result<(), Error> { + self.lowering.draw_indexed_primitives_indirect( + primitive_type, + index_type, + index_buffer, + index_buffer_offset, + indirect_buffer, + indirect_buffer_offset, + ) + } + + /// `drawPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:instanceCount: + /// baseInstance:` of a tessellation pipeline (`tessellation.rs`): `patch_count` patches of + /// `number_of_patch_control_points` control points from `patch_start`, `instance_count` + /// instances from `base_instance`, patch `i` the one the patch index buffer's `uint` at + /// `patch_start + i` names where one is given (its factors stay at `patch_start + i`), read + /// from its offset rounded down to a multiple of 4 as plain Metal reads it. A draw of no + /// patches or no instances records nothing; the draw's control points are its pipeline's where + /// its function states them, and a pipeline with a control-point index type reads every control + /// point's index as 0, as plain Metal draws them. Refused as the module docs say, for a patch + /// index buffer of another device, and as Metal's validation refuses it (`Invalid`, measured): + /// indices `patch_start + patch_count` past the buffer from the offset. + pub fn draw_patches( + &mut self, + number_of_patch_control_points: u32, + patch_start: u32, + patch_count: u32, + patch_index_buffer: Option<&Buffer>, + patch_index_buffer_offset: u64, + instance_count: u32, + base_instance: u32, + ) -> Result<(), Error> { + self.lowering.draw_patches( + number_of_patch_control_points, + patch_start, + patch_count, + patch_index_buffer, + patch_index_buffer_offset, + instance_count, + base_instance, + ) + } + + /// `drawPatches:patchIndexBuffer:patchIndexBufferOffset:indirectBuffer: + /// indirectBufferOffset:` of a tessellation pipeline: Metal's `MTLDrawPatchIndirectArguments` + /// at `indirect_buffer_offset` (a `VkDrawIndirectCommand`'s layout). Refused as + /// [`RenderCommandEncoder::draw_patches`] and [`RenderCommandEncoder::draw_primitives_indirect`] + /// are, but for the patch indices past the buffer, whose count the arguments hold: a patch + /// whose index lies past the buffer's length reads patch index 0 (Metal reads memory past the + /// buffer there, which its validation does not check). A pipeline with a control-point index + /// type, which Metal's validation stops, reads every index as 0, as the direct draw does (a + /// Metal probe `cpi_plain_typed_indirect`). + pub fn draw_patches_indirect( + &mut self, + number_of_patch_control_points: u32, + patch_index_buffer: Option<&Buffer>, + patch_index_buffer_offset: u64, + indirect_buffer: &Buffer, + indirect_buffer_offset: u64, + ) -> Result<(), Error> { + self.lowering.draw_patches_indirect( + number_of_patch_control_points, + patch_index_buffer, + patch_index_buffer_offset, + indirect_buffer, + indirect_buffer_offset, + ) + } + + /// `drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset: + /// controlPointIndexBuffer:controlPointIndexBufferOffset:instanceCount:baseInstance:` of a + /// tessellation pipeline whose `tessellationControlPointIndexType` is not `None`: as + /// [`RenderCommandEncoder::draw_patches`], but control point `k` of the patch whose index is + /// `p` is the index (of the pipeline's type) at position `p · N + k` of the control-point index + /// buffer from its offset (measured), `N` the pipeline's control points where its function + /// states them, an offset that is not a multiple of the index size rounded down to one, as + /// plain Metal reads it, where its validation stops the draw. A pipeline whose type is `None`, + /// which Metal's validation stops, draws the patches' own control points, the buffer unread, as + /// plain Metal draws them (Metal probe case `indexed_without_type` on an M4). Refused as + /// `draw_patches` is, for a control-point index buffer of another device, and as Metal's + /// validation refuses it (`Invalid`, measured): `(patch_start + patch_count) · N` indices past + /// the buffer from the offset. + pub fn draw_indexed_patches( + &mut self, + number_of_patch_control_points: u32, + patch_start: u32, + patch_count: u32, + patch_index_buffer: Option<&Buffer>, + patch_index_buffer_offset: u64, + control_point_index_buffer: &Buffer, + control_point_index_buffer_offset: u64, + instance_count: u32, + base_instance: u32, + ) -> Result<(), Error> { + self.lowering.draw_indexed_patches( + number_of_patch_control_points, + patch_start, + patch_count, + patch_index_buffer, + patch_index_buffer_offset, + control_point_index_buffer, + control_point_index_buffer_offset, + instance_count, + base_instance, + ) + } + + /// `drawIndexedPatches:patchIndexBuffer:patchIndexBufferOffset:controlPointIndexBuffer: + /// controlPointIndexBufferOffset:indirectBuffer:indirectBufferOffset:` of a tessellation + /// pipeline whose `tessellationControlPointIndexType` is not `None`: the arguments of + /// [`RenderCommandEncoder::draw_patches_indirect`], the control points of + /// [`RenderCommandEncoder::draw_indexed_patches`]. Refused as both are, but for the indices + /// past the buffers, whose counts the arguments hold: an index that lies past the buffer's + /// length reads 0 (Metal reads memory past the buffer there, which its validation does not + /// check). A pipeline without a control-point index type, which Metal's validation stops, draws + /// the patches' own control points, the buffer unread, as the direct draw does (a Metal probe + /// `cpi_indexed_untyped_indirect`). + pub fn draw_indexed_patches_indirect( + &mut self, + number_of_patch_control_points: u32, + patch_index_buffer: Option<&Buffer>, + patch_index_buffer_offset: u64, + control_point_index_buffer: &Buffer, + control_point_index_buffer_offset: u64, + indirect_buffer: &Buffer, + indirect_buffer_offset: u64, + ) -> Result<(), Error> { + self.lowering.draw_indexed_patches_indirect( + number_of_patch_control_points, + patch_index_buffer, + patch_index_buffer_offset, + control_point_index_buffer, + control_point_index_buffer_offset, + indirect_buffer, + indirect_buffer_offset, + ) + } + + /// `setVisibilityResultMode:offset:` (`visibility.rs`). An offset that is not a multiple of 8 + /// is rounded down to one, where plain Metal writes the result (measured on an M4). Refused + /// (`Invalid`, measured) for `Boolean` and `Counting`: a pass without a visibility result + /// buffer, an offset whose 8 bytes run past the buffer, an offset the encoder took before. + /// `Counting` is `Unsupported` where the device lacks `occlusionQueryPrecise`. A refused call + /// keeps the mode set before. While a mode other than `Disabled` is set, amplified draws draw + /// one amplification at a time, whose samples the one query counts as Metal's does + /// (`VertexAmplification::one_at_a_time`); a mode set after a draw amplified as views begins + /// its query in a new instance of the pass's layers, since a query in a multiview instance + /// takes one query per view. Where the device draws the pass's colors in groups, the first + /// group's pass counts the results (`render/color_groups.rs`). + pub fn set_visibility_result_mode( + &mut self, + mode: VisibilityResultMode, + offset: u64, + ) -> Result<(), Error> { + self.lowering.set_visibility_result_mode(mode, offset) + } + + /// `endEncoding`: begin the pass with its load and store operations, run the draws, and end it. + /// A store action still `Unknown` is `DontCare`, as plain Metal stores it where its validation + /// stops it: a color attachment's (measured on an M4), and a depth or stencil attachment's, + /// resolving or not; a resolve texture is left untouched, as plain Metal leaves it. The encoder + /// is consumed either way, so a refusal leaves its command buffer abandoned, as Metal stops + /// there. + pub fn end_encoding(self) -> Result<(), Error> { + self.lowering.end_encoding() + } +} + /// Color attachment indices, a bit each: the sets of colors a pass's end works out, which would /// otherwise allocate at every end. Every index is below [`MAX_COLOR_ATTACHMENTS`], as a pass's /// colors are. diff --git a/crates/metal2vulkan-runtime/src/render/arguments.rs b/crates/metal2vulkan-runtime/src/render/arguments.rs index a224b0f3d..ca7a5284d 100644 --- a/crates/metal2vulkan-runtime/src/render/arguments.rs +++ b/crates/metal2vulkan-runtime/src/render/arguments.rs @@ -25,6 +25,7 @@ //! dispatch (`render/shadows.rs`). use super::RenderCommandEncoder; +use super::RenderLowering; use super::{RenderCall, Table}; use crate::error::Error; use crate::function_table::VisibleFunctionTable; @@ -34,13 +35,9 @@ use crate::replay::Resource; use crate::resource::ResourceRef; use metal2vulkan::metal::{RenderStages, ResourceUsage}; -impl RenderCommandEncoder { - /// `useResource:usage:stages:`: the encoder's later draws and tile dispatches may reach - /// `resource` in render `stages` through an address or a resource ID held in memory, reading - /// or writing as `usage` says (the module docs). - /// - /// Refused, changing nothing: a resource of another device (`Invalid`). - pub fn use_resource( +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::use_resource`]. + pub(crate) fn use_resource( &mut self, resource: ResourceRef<'_>, usage: ResourceUsage, @@ -50,9 +47,8 @@ impl RenderCommandEncoder { self.use_all("use_resource", &[resource], usage, stages) } - /// `useResources:count:usage:stages:`: [`use_resource`](Self::use_resource) of each of - /// `resources`, refused, changing nothing, as it is for any of them. - pub fn use_resources( + /// The lowering of [`RenderCommandEncoder::use_resources`]. + pub(crate) fn use_resources( &mut self, resources: &[ResourceRef<'_>], usage: ResourceUsage, @@ -85,23 +81,14 @@ impl RenderCommandEncoder { Ok(()) } - /// `useHeap:stages:`: the encoder's later draws and tile dispatches may read every buffer - /// placed in `heap` in render `stages` through an address held in memory, and every texture - /// made in it or over a buffer placed in it through its resource ID, as Metal's contract makes - /// a heap's resources resident for reading only (`residency.rs`): the textures that live now, - /// and each made later, from the first command encoded after it is made. - /// - /// A sparse heap's live sparse textures are made resident, as on a compute encoder. - /// - /// Refused, changing nothing (`Invalid`): a heap of another device. - pub fn use_heap(&mut self, heap: &Heap, stages: RenderStages) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::use_heap`]. + pub(crate) fn use_heap(&mut self, heap: &Heap, stages: RenderStages) -> Result<(), Error> { self.log(|_| RenderCall::UseHeap(heap.clone(), stages)); self.use_heaps_of("use_heap", &[heap], stages) } - /// `useHeaps:count:stages:`: [`use_heap`](Self::use_heap) of each of `heaps`, refused, - /// changing nothing, as it is for any of them. - pub fn use_heaps(&mut self, heaps: &[&Heap], stages: RenderStages) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::use_heaps`]. + pub(crate) fn use_heaps(&mut self, heaps: &[&Heap], stages: RenderStages) -> Result<(), Error> { self.log(|_| { RenderCall::UseHeaps(heaps.iter().map(|&heap| heap.clone()).collect(), stages) }); @@ -166,13 +153,54 @@ impl RenderCommandEncoder { } impl RenderCommandEncoder { - /// `setVertexVisibleFunctionTable:atBufferIndex:` (`None` unbinds the index): the table at - /// the vertex stage's buffer index `index`, in place of any buffer there, as a compute - /// encoder's `set_visible_function_table` binds one (`function_table.rs`). Refused: an index - /// past the buffer table, a table of another device. A draw whose vertex function reads a - /// buffer at the index, or a table where a buffer is bound, is refused - /// (`Invalid(FunctionTable)`), as Metal's validation stops it. - pub fn set_vertex_visible_function_table( + /// `useResource:usage:stages:`: the encoder's later draws and tile dispatches may reach + /// `resource` in render `stages` through an address or a resource ID held in memory, reading + /// or writing as `usage` says (the module docs). + /// + /// Refused, changing nothing: a resource of another device (`Invalid`). + pub fn use_resource( + &mut self, + resource: ResourceRef<'_>, + usage: ResourceUsage, + stages: RenderStages, + ) -> Result<(), Error> { + self.lowering.use_resource(resource, usage, stages) + } + + /// `useResources:count:usage:stages:`: [`use_resource`](Self::use_resource) of each of + /// `resources`, refused, changing nothing, as it is for any of them. + pub fn use_resources( + &mut self, + resources: &[ResourceRef<'_>], + usage: ResourceUsage, + stages: RenderStages, + ) -> Result<(), Error> { + self.lowering.use_resources(resources, usage, stages) + } + + /// `useHeap:stages:`: the encoder's later draws and tile dispatches may read every buffer + /// placed in `heap` in render `stages` through an address held in memory, and every texture + /// made in it or over a buffer placed in it through its resource ID, as Metal's contract makes + /// a heap's resources resident for reading only (`residency.rs`): the textures that live now, + /// and each made later, from the first command encoded after it is made. + /// + /// A sparse heap's live sparse textures are made resident, as on a compute encoder. + /// + /// Refused, changing nothing (`Invalid`): a heap of another device. + pub fn use_heap(&mut self, heap: &Heap, stages: RenderStages) -> Result<(), Error> { + self.lowering.use_heap(heap, stages) + } + + /// `useHeaps:count:stages:`: [`use_heap`](Self::use_heap) of each of `heaps`, refused, + /// changing nothing, as it is for any of them. + pub fn use_heaps(&mut self, heaps: &[&Heap], stages: RenderStages) -> Result<(), Error> { + self.lowering.use_heaps(heaps, stages) + } +} + +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::set_vertex_visible_function_table`]. + pub(crate) fn set_vertex_visible_function_table( &mut self, table: Option<&VisibleFunctionTable>, index: u32, @@ -183,11 +211,8 @@ impl RenderCommandEncoder { .set_function_tables(&mut self.core, CALL, &[table], index) } - /// `setVertexVisibleFunctionTables:withBufferRange:`: `tables[i]` at the vertex stage's - /// buffer index `first + i`, refused as - /// [`set_vertex_visible_function_table`](Self::set_vertex_visible_function_table) is; a - /// refusal binds none of them. - pub fn set_vertex_visible_function_tables( + /// The lowering of [`RenderCommandEncoder::set_vertex_visible_function_tables`]. + pub(crate) fn set_vertex_visible_function_tables( &mut self, tables: &[Option<&VisibleFunctionTable>], first: u32, @@ -204,10 +229,8 @@ impl RenderCommandEncoder { .set_function_tables(&mut self.core, CALL, tables, first) } - /// `setFragmentVisibleFunctionTable:atBufferIndex:`: as - /// [`set_vertex_visible_function_table`](Self::set_vertex_visible_function_table), at the - /// fragment stage's buffer index. - pub fn set_fragment_visible_function_table( + /// The lowering of [`RenderCommandEncoder::set_fragment_visible_function_table`]. + pub(crate) fn set_fragment_visible_function_table( &mut self, table: Option<&VisibleFunctionTable>, index: u32, @@ -218,10 +241,8 @@ impl RenderCommandEncoder { .set_function_tables(&mut self.core, CALL, &[table], index) } - /// `setFragmentVisibleFunctionTables:withBufferRange:`: as - /// [`set_vertex_visible_function_tables`](Self::set_vertex_visible_function_tables), at the - /// fragment stage's buffer indices. - pub fn set_fragment_visible_function_tables( + /// The lowering of [`RenderCommandEncoder::set_fragment_visible_function_tables`]. + pub(crate) fn set_fragment_visible_function_tables( &mut self, tables: &[Option<&VisibleFunctionTable>], first: u32, @@ -238,10 +259,8 @@ impl RenderCommandEncoder { .set_function_tables(&mut self.core, CALL, tables, first) } - /// `setTileVisibleFunctionTable:atBufferIndex:`: as - /// [`set_vertex_visible_function_table`](Self::set_vertex_visible_function_table), at the - /// tile stage's buffer index, which tile dispatches read. - pub fn set_tile_visible_function_table( + /// The lowering of [`RenderCommandEncoder::set_tile_visible_function_table`]. + pub(crate) fn set_tile_visible_function_table( &mut self, table: Option<&VisibleFunctionTable>, index: u32, @@ -252,10 +271,8 @@ impl RenderCommandEncoder { .set_function_tables(&mut self.core, CALL, &[table], index) } - /// `setTileVisibleFunctionTables:withBufferRange:`: as - /// [`set_vertex_visible_function_tables`](Self::set_vertex_visible_function_tables), at the - /// tile stage's buffer indices. - pub fn set_tile_visible_function_tables( + /// The lowering of [`RenderCommandEncoder::set_tile_visible_function_tables`]. + pub(crate) fn set_tile_visible_function_tables( &mut self, tables: &[Option<&VisibleFunctionTable>], first: u32, @@ -272,3 +289,80 @@ impl RenderCommandEncoder { .set_function_tables(&mut self.core, CALL, tables, first) } } + +impl RenderCommandEncoder { + /// `setVertexVisibleFunctionTable:atBufferIndex:` (`None` unbinds the index): the table at + /// the vertex stage's buffer index `index`, in place of any buffer there, as a compute + /// encoder's `set_visible_function_table` binds one (`function_table.rs`). Refused: an index + /// past the buffer table, a table of another device. A draw whose vertex function reads a + /// buffer at the index, or a table where a buffer is bound, is refused + /// (`Invalid(FunctionTable)`), as Metal's validation stops it. + pub fn set_vertex_visible_function_table( + &mut self, + table: Option<&VisibleFunctionTable>, + index: u32, + ) -> Result<(), Error> { + self.lowering + .set_vertex_visible_function_table(table, index) + } + + /// `setVertexVisibleFunctionTables:withBufferRange:`: `tables[i]` at the vertex stage's + /// buffer index `first + i`, refused as + /// [`set_vertex_visible_function_table`](Self::set_vertex_visible_function_table) is; a + /// refusal binds none of them. + pub fn set_vertex_visible_function_tables( + &mut self, + tables: &[Option<&VisibleFunctionTable>], + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_vertex_visible_function_tables(tables, first) + } + + /// `setFragmentVisibleFunctionTable:atBufferIndex:`: as + /// [`set_vertex_visible_function_table`](Self::set_vertex_visible_function_table), at the + /// fragment stage's buffer index. + pub fn set_fragment_visible_function_table( + &mut self, + table: Option<&VisibleFunctionTable>, + index: u32, + ) -> Result<(), Error> { + self.lowering + .set_fragment_visible_function_table(table, index) + } + + /// `setFragmentVisibleFunctionTables:withBufferRange:`: as + /// [`set_vertex_visible_function_tables`](Self::set_vertex_visible_function_tables), at the + /// fragment stage's buffer indices. + pub fn set_fragment_visible_function_tables( + &mut self, + tables: &[Option<&VisibleFunctionTable>], + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_fragment_visible_function_tables(tables, first) + } + + /// `setTileVisibleFunctionTable:atBufferIndex:`: as + /// [`set_vertex_visible_function_table`](Self::set_vertex_visible_function_table), at the + /// tile stage's buffer index, which tile dispatches read. + pub fn set_tile_visible_function_table( + &mut self, + table: Option<&VisibleFunctionTable>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_tile_visible_function_table(table, index) + } + + /// `setTileVisibleFunctionTables:withBufferRange:`: as + /// [`set_vertex_visible_function_tables`](Self::set_vertex_visible_function_tables), at the + /// tile stage's buffer indices. + pub fn set_tile_visible_function_tables( + &mut self, + tables: &[Option<&VisibleFunctionTable>], + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_tile_visible_function_tables(tables, first) + } +} diff --git a/crates/metal2vulkan-runtime/src/render/capture.rs b/crates/metal2vulkan-runtime/src/render/capture.rs index f916ec150..e7be57a3a 100644 --- a/crates/metal2vulkan-runtime/src/render/capture.rs +++ b/crates/metal2vulkan-runtime/src/render/capture.rs @@ -43,7 +43,7 @@ use super::bound::Bound; use super::reroute::Rerecord; use super::shadows::InstanceShadows; -use super::{Assembly, Instance, InterlockedStorage, RenderCommandEncoder}; +use super::{Assembly, Instance, InterlockedStorage, RenderLowering}; use crate::attachmentless; use crate::binding::CommandUses; use crate::clear_reach::{DrawnArea, DrawnTiles, PassReach}; @@ -182,7 +182,7 @@ struct Placed { culls: bool, } -impl RenderCommandEncoder { +impl RenderLowering { /// Keep the draw just recorded (`call` of `assembly` and `draw`, its indices from `index`) /// for capture replay where the pass keeps its draws and `capturable` (the module docs); /// otherwise the pass keeps none from here on. A draw recorded again (a reroute's, or a diff --git a/crates/metal2vulkan-runtime/src/render/color_groups.rs b/crates/metal2vulkan-runtime/src/render/color_groups.rs index d61531fe2..df605eab3 100644 --- a/crates/metal2vulkan-runtime/src/render/color_groups.rs +++ b/crates/metal2vulkan-runtime/src/render/color_groups.rs @@ -78,7 +78,7 @@ use super::capture; use super::extended_shadow::ExtendedShadows; use super::{ - reads_handles, DrawingState, Opening, RenderCommandEncoder, RenderLog, RenderPipelineState, + reads_handles, DrawingState, Opening, RenderLog, RenderLowering, RenderPipelineState, RenderStateKind, }; use crate::attachment_stand_in::{self, StandInCopies}; @@ -444,7 +444,7 @@ impl Ended { .as_ref() .ok_or_else(|| internal("a pass of several color groups without its log"))?; for group in 1..later.group.groups() { - let mut encoder = RenderCommandEncoder::later_group(core, &later, group, log)?; + let mut encoder = RenderLowering::later_group(core, &later, group, log)?; log.replay_into(&mut encoder); if encoder.group_diverged() { return Err(internal( @@ -461,7 +461,7 @@ impl Ended { } } -impl RenderCommandEncoder { +impl RenderLowering { /// The encoder of later group `group` of the pass `later` and `log` describe, over `core` /// (the module docs). fn later_group( @@ -469,7 +469,7 @@ impl RenderCommandEncoder { later: &Later, group: u32, log: &RenderLog, - ) -> Result { + ) -> Result { const CALL: &str = "end_encoding"; let grouping = ColorGroup::of(later.group.present.clone(), later.group.width, group) .ok_or_else(|| internal("a later color group of a pass in one"))?; @@ -500,7 +500,7 @@ impl RenderCommandEncoder { counting: false, })), ); - Ok(RenderCommandEncoder::assemble(core, draws, opening)) + Ok(RenderLowering::assemble(core, draws, opening)) } /// Whether a later group's decisive call ran otherwise than the first group's. diff --git a/crates/metal2vulkan-runtime/src/render/executions.rs b/crates/metal2vulkan-runtime/src/render/executions.rs index d3e6616a4..563e37f50 100644 --- a/crates/metal2vulkan-runtime/src/render/executions.rs +++ b/crates/metal2vulkan-runtime/src/render/executions.rs @@ -257,9 +257,10 @@ use super::pending_tile::TilePipelines; use super::shadows::InstanceShadows; use super::tile_memory::TileMemory; use super::RenderCall; +use super::RenderCommandEncoder; use super::{ index_size, Assembly, Before, DrawBuffers, DrawingState, IndexedDraw, Instance, - InterlockedStorage, Next, PatchDraw, PendingDraw, Piece, RenderCommandEncoder, RenderStateKind, + InterlockedStorage, Next, PatchDraw, PendingDraw, Piece, RenderLowering, RenderStateKind, PASS_DRAW_STAGES, }; use crate::amplification::Amplification; @@ -337,31 +338,9 @@ enum Inherited { Faults, } -impl RenderCommandEncoder { - /// `executeCommandsInBuffer:withRange:`: run render commands `range` of `icb` here, as their - /// records stand when the command buffer is committed, or, where an encoder made `icb` - /// resident for writing, once the work before them completed (a host step the device - /// announces once, `Degradation::HostReplayedIndirectCommands`). Each draws as this - /// encoder's `draw_primitives`, `draw_indexed_primitives` or `draw_patches` would, with the - /// encoder's state as it is now, and its own pipeline state and buffers, or the encoder's - /// where `icb` inherits them (the module docs). - /// The encoder's draws before run before them and its draws after run after them. - /// - /// Refused, changing nothing (`Invalid`): a buffer of another device, a range that ends past - /// its size (`IndirectCommandBufferProblem::Range`), and, for a range that is not empty, an - /// inherited pipeline state that is unset (`NoPipelineState`), at which Metal's process ends. - /// For a range that is not empty, an inherited state made without - /// `supportIndirectCommandBuffers` faults Metal's GPU at the encoder: the call is taken, the - /// encoder runs nothing, not even its load, clear or store actions, and the command buffer - /// completes with [`CommandBufferError::PageFault`](crate::CommandBufferError::PageFault), the - /// other encoders run and every event signal fires. A buffer of no command types, or of - /// dispatches beside draws of primitives, runs nothing, as plain Metal's; one of dispatches - /// alone, or beside other draws (unmeasured in a pass), is - /// `NotImplemented(IndirectRenderCommands)`. An empty range runs nothing, whatever the - /// encoder's pipeline state, as plain Metal's. What a command's draw would be - /// refused refuses the commit ([`CommandBuffer::commit`]). Where a visibility result mode is - /// set, the commands' draws count in it (the module docs). - pub fn execute_commands_in_buffer( +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::execute_commands_in_buffer`]. + pub(crate) fn execute_commands_in_buffer( &mut self, icb: &IndirectCommandBuffer, range: Range, @@ -369,18 +348,8 @@ impl RenderCommandEncoder { self.execute_range(icb, range, None) } - /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) with a check of the - /// commands its host step runs (a runtime extension; Metal has none), which looks for `needs`: - /// where a host step records the pass from the records as the GPU and the CPU left them (an - /// encoder made `icb` resident for writing, `IndirectCommandBuffer::gpu_written`), the step - /// first calls `check` with each command of the range it will record, in order, before it - /// records any of them ([`IndirectCommandCheck`]). An execution `commit` records from the CPU's - /// records never calls it; nor does one that runs on the GPU alone (`render/executions/gpu.rs`), - /// which it may only where what `icb`'s records may hold, at the commit and again as the - /// pass's batch is ready to submit, rules out every kind `needs` names - /// ([`IndirectCommandCheckNeeds`], [`IndirectCommandCheckNeeds::ALL`] included). Refused as - /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) refuses. - pub fn execute_commands_in_buffer_checked( + /// The lowering of [`RenderCommandEncoder::execute_commands_in_buffer_checked`]. + pub(crate) fn execute_commands_in_buffer_checked( &mut self, icb: &IndirectCommandBuffer, range: Range, @@ -424,31 +393,8 @@ impl RenderCommandEncoder { self.defer_execution(icb, ExecutionRange::Fixed(range), pipeline, check) } - /// `executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:`: run the render commands - /// of `icb` that the `MTLIndirectCommandBufferExecutionRange` at `offset` of `range_buffer` - /// (`location`, then `length`, each a `u32`) names as the execution runs, as - /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) runs a range given. The - /// range is taken as Metal's execution takes it (a probe, an M3 Max and an M4): from the - /// location, clamped at the buffer's size, so a length of 0 or a location at the size runs - /// nothing and a length past it runs to its end; a location past the size, or a range past - /// `2^32 - 1`, at which Metal's GPU faults the command buffer, runs nothing, and the command - /// buffer's execution report states `ReplayFaults::RANGE`. The encoder copies the range where - /// it is encoded, behind a barrier from everything before, so the range a kernel of an earlier - /// encoder wrote is read; a host step records the pass once the work before it completed, which - /// the device announces once (`Degradation::HostReplayedIndirectCommands`). - /// - /// Refused, changing nothing: what - /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) refuses but a range (an - /// unset inherited state whatever the range); a range buffer of another device, and a range - /// Metal's reading of is not defined (`Invalid`, `IndirectCommandBufferProblem::RangeBuffer`): - /// an offset that is not a multiple of 4 bytes, at which Metal's GPU faulted, or 8 bytes that - /// run past `range_buffer`, which Metal reads from whatever follows it. A range a draw of the - /// encoder before the call may write is `NotImplemented(IndirectRenderCommands)`: Metal's - /// execution reads that draw's write, where the runtime's copy, made before the pass, would - /// not; as for the index bounds pass, an untracked buffer's writes are not seen. Under an - /// inherited state made without `supportIndirectCommandBuffers`, whatever the range, `{0, 0}` - /// included, the encoder faults as `execute_commands_in_buffer`'s does. - pub fn execute_commands_in_buffer_indirect( + /// The lowering of [`RenderCommandEncoder::execute_commands_in_buffer_indirect`]. + pub(crate) fn execute_commands_in_buffer_indirect( &mut self, icb: &IndirectCommandBuffer, range_buffer: &Buffer, @@ -457,14 +403,8 @@ impl RenderCommandEncoder { self.execute_indirect_range(icb, range_buffer, offset, None) } - /// [`execute_commands_in_buffer_indirect`](Self::execute_commands_in_buffer_indirect) with a - /// check of the commands its host step runs, which always records the pass: the step first - /// calls `check` with each command of the range it read that it will record, in order, before - /// it records any of them, as - /// [`execute_commands_in_buffer_checked`](Self::execute_commands_in_buffer_checked)'s does - /// ([`IndirectCommandCheck`]). Refused as - /// [`execute_commands_in_buffer_indirect`](Self::execute_commands_in_buffer_indirect) refuses. - pub fn execute_commands_in_buffer_indirect_checked( + /// The lowering of [`RenderCommandEncoder::execute_commands_in_buffer_indirect_checked`]. + pub(crate) fn execute_commands_in_buffer_indirect_checked( &mut self, icb: &IndirectCommandBuffer, range_buffer: &Buffer, @@ -791,6 +731,113 @@ impl RenderCommandEncoder { } } +impl RenderCommandEncoder { + /// `executeCommandsInBuffer:withRange:`: run render commands `range` of `icb` here, as their + /// records stand when the command buffer is committed, or, where an encoder made `icb` + /// resident for writing, once the work before them completed (a host step the device + /// announces once, `Degradation::HostReplayedIndirectCommands`). Each draws as this + /// encoder's `draw_primitives`, `draw_indexed_primitives` or `draw_patches` would, with the + /// encoder's state as it is now, and its own pipeline state and buffers, or the encoder's + /// where `icb` inherits them (the module docs). + /// The encoder's draws before run before them and its draws after run after them. + /// + /// Refused, changing nothing (`Invalid`): a buffer of another device, a range that ends past + /// its size (`IndirectCommandBufferProblem::Range`), and, for a range that is not empty, an + /// inherited pipeline state that is unset (`NoPipelineState`), at which Metal's process ends. + /// For a range that is not empty, an inherited state made without + /// `supportIndirectCommandBuffers` faults Metal's GPU at the encoder: the call is taken, the + /// encoder runs nothing, not even its load, clear or store actions, and the command buffer + /// completes with [`CommandBufferError::PageFault`](crate::CommandBufferError::PageFault), the + /// other encoders run and every event signal fires. A buffer of no command types, or of + /// dispatches beside draws of primitives, runs nothing, as plain Metal's; one of dispatches + /// alone, or beside other draws (unmeasured in a pass), is + /// `NotImplemented(IndirectRenderCommands)`. An empty range runs nothing, whatever the + /// encoder's pipeline state, as plain Metal's. What a command's draw would be + /// refused refuses the commit ([`CommandBuffer::commit`]). Where a visibility result mode is + /// set, the commands' draws count in it (the module docs). + pub fn execute_commands_in_buffer( + &mut self, + icb: &IndirectCommandBuffer, + range: Range, + ) -> Result<(), Error> { + self.lowering.execute_commands_in_buffer(icb, range) + } + + /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) with a check of the + /// commands its host step runs (a runtime extension; Metal has none), which looks for `needs`: + /// where a host step records the pass from the records as the GPU and the CPU left them (an + /// encoder made `icb` resident for writing, `IndirectCommandBuffer::gpu_written`), the step + /// first calls `check` with each command of the range it will record, in order, before it + /// records any of them ([`IndirectCommandCheck`]). An execution `commit` records from the CPU's + /// records never calls it; nor does one that runs on the GPU alone (`render/executions/gpu.rs`), + /// which it may only where what `icb`'s records may hold, at the commit and again as the + /// pass's batch is ready to submit, rules out every kind `needs` names + /// ([`IndirectCommandCheckNeeds`], [`IndirectCommandCheckNeeds::ALL`] included). Refused as + /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) refuses. + pub fn execute_commands_in_buffer_checked( + &mut self, + icb: &IndirectCommandBuffer, + range: Range, + check: IndirectCommandCheck, + needs: IndirectCommandCheckNeeds, + ) -> Result<(), Error> { + self.lowering + .execute_commands_in_buffer_checked(icb, range, check, needs) + } + + /// `executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:`: run the render commands + /// of `icb` that the `MTLIndirectCommandBufferExecutionRange` at `offset` of `range_buffer` + /// (`location`, then `length`, each a `u32`) names as the execution runs, as + /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) runs a range given. The + /// range is taken as Metal's execution takes it (a probe, an M3 Max and an M4): from the + /// location, clamped at the buffer's size, so a length of 0 or a location at the size runs + /// nothing and a length past it runs to its end; a location past the size, or a range past + /// `2^32 - 1`, at which Metal's GPU faults the command buffer, runs nothing, and the command + /// buffer's execution report states `ReplayFaults::RANGE`. The encoder copies the range where + /// it is encoded, behind a barrier from everything before, so the range a kernel of an earlier + /// encoder wrote is read; a host step records the pass once the work before it completed, which + /// the device announces once (`Degradation::HostReplayedIndirectCommands`). + /// + /// Refused, changing nothing: what + /// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) refuses but a range (an + /// unset inherited state whatever the range); a range buffer of another device, and a range + /// Metal's reading of is not defined (`Invalid`, `IndirectCommandBufferProblem::RangeBuffer`): + /// an offset that is not a multiple of 4 bytes, at which Metal's GPU faulted, or 8 bytes that + /// run past `range_buffer`, which Metal reads from whatever follows it. A range a draw of the + /// encoder before the call may write is `NotImplemented(IndirectRenderCommands)`: Metal's + /// execution reads that draw's write, where the runtime's copy, made before the pass, would + /// not; as for the index bounds pass, an untracked buffer's writes are not seen. Under an + /// inherited state made without `supportIndirectCommandBuffers`, whatever the range, `{0, 0}` + /// included, the encoder faults as `execute_commands_in_buffer`'s does. + pub fn execute_commands_in_buffer_indirect( + &mut self, + icb: &IndirectCommandBuffer, + range_buffer: &Buffer, + offset: u64, + ) -> Result<(), Error> { + self.lowering + .execute_commands_in_buffer_indirect(icb, range_buffer, offset) + } + + /// [`execute_commands_in_buffer_indirect`](Self::execute_commands_in_buffer_indirect) with a + /// check of the commands its host step runs, which always records the pass: the step first + /// calls `check` with each command of the range it read that it will record, in order, before + /// it records any of them, as + /// [`execute_commands_in_buffer_checked`](Self::execute_commands_in_buffer_checked)'s does + /// ([`IndirectCommandCheck`]). Refused as + /// [`execute_commands_in_buffer_indirect`](Self::execute_commands_in_buffer_indirect) refuses. + pub fn execute_commands_in_buffer_indirect_checked( + &mut self, + icb: &IndirectCommandBuffer, + range_buffer: &Buffer, + offset: u64, + check: IndirectCommandCheck, + ) -> Result<(), Error> { + self.lowering + .execute_commands_in_buffer_indirect_checked(icb, range_buffer, offset, check) + } +} + /// Announce, once per device, an execution of commands `range` of `icb` after one in the same /// encoder from the same command with length `earlier`, another: Metal's executions then do not /// each run their own range, and not the same way from run to run (the module docs); the @@ -1642,7 +1689,7 @@ fn reads_vertex_stride(pipeline: &RenderPipelineState, index: u32) -> bool { /// it. The command buffer holds them until it completes. pub(crate) type SettledDraw = (Arc, Option>); -impl RenderCommandEncoder { +impl RenderLowering { /// Make, into `made`, what a command's draw of `pipeline` under the encoder's state (an /// execution's at its call, `RenderExecution::settle`) compiles at the host step: for each /// primitive type its input primitive topology class holds (every type for the unspecified @@ -2040,7 +2087,7 @@ impl RenderExecution { /// commands ran as several, and each run's steps. fn finish( &self, - mut encoder: RenderCommandEncoder, + mut encoder: RenderLowering, found: &mut Found, rendered: &mut Rendered, device: &Device, @@ -2051,7 +2098,7 @@ impl RenderExecution { // left begins and ends there, empty. encoder.visibility.end(raw, encoder.current.draws); encoder.visibility.close_spares(raw, encoder.current.draws); - let RenderCommandEncoder { + let RenderLowering { core, earlier, current, @@ -2147,12 +2194,12 @@ impl RenderExecution { (draws, visibility): (vk::CommandBuffer, Visibility), (storage, layout, residency): (PassStorage, PassLayout, &Residency), forms: BufferForms, - ) -> RenderCommandEncoder { + ) -> RenderLowering { let snapshot = &self.snapshot; // The draws use only the shadowed textures the call gathered. let mut shadows = InstanceShadows::default(); shadows.add(&self.shadows, &[]); - RenderCommandEncoder { + RenderLowering { core, earlier: Vec::new(), current: Instance { @@ -2316,7 +2363,7 @@ impl RenderExecution { for pipeline in named { encoder.settle_draws(pipeline, made); } - let RenderCommandEncoder { core, .. } = encoder; + let RenderLowering { core, .. } = encoder; core } diff --git a/crates/metal2vulkan-runtime/src/render/executions/gpu.rs b/crates/metal2vulkan-runtime/src/render/executions/gpu.rs index 28760c2f0..dba172f04 100644 --- a/crates/metal2vulkan-runtime/src/render/executions/gpu.rs +++ b/crates/metal2vulkan-runtime/src/render/executions/gpu.rs @@ -74,7 +74,7 @@ use std::sync::Arc; use super::super::bound::{Bound, Recorded}; use super::super::pass_start_reads::PassStartTables; -use super::super::{Assembly, DrawBuffers, Recording, RenderCommandEncoder}; +use super::super::{Assembly, DrawBuffers, Recording, RenderLowering}; use super::{HostStepCause, PassStorage, RenderExecution, Rendered, CALL}; use crate::binding::PushWrite; use crate::blit::{reads_by, writes_by}; @@ -351,7 +351,7 @@ impl RenderExecution { encoder.pipeline = Some(pipeline.clone()); encoder.replay_draw_of(state, primitive_type) }); - let RenderCommandEncoder { core, .. } = encoder; + let RenderLowering { core, .. } = encoder; let form = match slots { Ok(Ok(slots)) => { let commands = (decided, primitive_type, range); @@ -485,7 +485,7 @@ impl RenderExecution { (command_buffer, residency): (&CommandBuffer, &Residency), form: &GpuForm, (storage, rendered): (PassStorage, &mut Rendered), - ) -> Result { + ) -> Result { let snapshot = &self.snapshot; let device = command_buffer.device().clone(); let pipeline = (self.pipeline.as_ref()) @@ -689,7 +689,7 @@ fn scratch_head(pre: &DrawReplayPreprocess, sink: u64) -> Result, Error> Ok(bytes) } -impl RenderCommandEncoder { +impl RenderLowering { /// The buffer slots the vertex and fragment functions of a command's draw of `state` as /// `primitive_type` read, through this encoder (an execution's at its call, in the replay /// form or the merged one, its `forms`), where that draw records as the GPU form's draws do diff --git a/crates/metal2vulkan-runtime/src/render/extended_shadow.rs b/crates/metal2vulkan-runtime/src/render/extended_shadow.rs index 7a7d36669..900aa9529 100644 --- a/crates/metal2vulkan-runtime/src/render/extended_shadow.rs +++ b/crates/metal2vulkan-runtime/src/render/extended_shadow.rs @@ -38,7 +38,7 @@ //! so `extended-range-blends-stored-codes` names only the colors a draw read from the codes //! (`degrade_extended_range_blends`, `ExtendedShadows::held`). -use super::RenderCommandEncoder; +use super::RenderLowering; use crate::blit::TRANSFER; use crate::command_buffer::CommandBuffer; use crate::device::functions::Vk; @@ -411,7 +411,7 @@ fn color( .and_then(Option::as_ref) } -impl RenderCommandEncoder { +impl RenderLowering { /// The shadows a draw binds: the held ones, none while the encoder records an execution's /// commands or a capture draw. pub(super) fn extended_shadows_bound(&self) -> &BTreeSet { diff --git a/crates/metal2vulkan-runtime/src/render/inline_first.rs b/crates/metal2vulkan-runtime/src/render/inline_first.rs index 5140b760e..fad46aeab 100644 --- a/crates/metal2vulkan-runtime/src/render/inline_first.rs +++ b/crates/metal2vulkan-runtime/src/render/inline_first.rs @@ -129,7 +129,7 @@ use super::extended_shadow::ExtendedShadows; use super::inline_splits::Later; -use super::{Instance, Next, RenderCommandEncoder, ViewSetup}; +use super::{Instance, Next, RenderLowering, ViewSetup}; use crate::clear_reach; use crate::device::Device; use crate::error::Error; @@ -298,7 +298,7 @@ fn inline_area(layout: &PassLayout) -> [u32; 2] { } } -impl RenderCommandEncoder { +impl RenderLowering { /// Begin the current instance's secondary where the pass left it unbegun (`Instance::draws`): /// a pass that may record its first instance inline begins none at its opening, and one only /// where a command records into that instance's secondary or a split keeps the instance. An diff --git a/crates/metal2vulkan-runtime/src/render/inline_splits.rs b/crates/metal2vulkan-runtime/src/render/inline_splits.rs index eca3f2aa9..c7c9e6420 100644 --- a/crates/metal2vulkan-runtime/src/render/inline_splits.rs +++ b/crates/metal2vulkan-runtime/src/render/inline_splits.rs @@ -73,9 +73,7 @@ use super::bound::{Bound, Recorded}; use super::pending::OwnedRecording; -use super::{ - inline_first, shadows, Clears, Instance, Next, Recording, RenderCommandEncoder, ViewSetup, -}; +use super::{inline_first, shadows, Clears, Instance, Next, Recording, RenderLowering, ViewSetup}; use crate::attachment_stand_in::Cause; use crate::clear_reach; use crate::color_list::ColorList; @@ -242,7 +240,7 @@ pub(super) struct SplitBegin { clears: Option, } -impl RenderCommandEncoder { +impl RenderLowering { /// Whether the draw about to record into `next` begins a new instance that records inline /// after the current one (the module docs; `records`: the draw records, `made` its pipeline, /// `capture` a capture draw, `stood` a stand-in arriving with it); where it does, the current diff --git a/crates/metal2vulkan-runtime/src/render/late_resolve.rs b/crates/metal2vulkan-runtime/src/render/late_resolve.rs index fbb4abede..9a34f7eb0 100644 --- a/crates/metal2vulkan-runtime/src/render/late_resolve.rs +++ b/crates/metal2vulkan-runtime/src/render/late_resolve.rs @@ -31,6 +31,7 @@ use super::RenderCall; use super::RenderCommandEncoder; +use super::RenderLowering; use crate::argument_table::check_index; use crate::command_buffer::CommandBuffer; use crate::error::{invalid, Error, Problem}; @@ -95,12 +96,9 @@ fn wanted(target: Option<&ResolveTarget>, store: StoreAction) -> Wanted<'_> { } } -impl RenderCommandEncoder { - /// The color attachment at `index` resolves into `target` (`None`: nowhere), whatever the - /// descriptor named (the module docs). Refused (`Invalid`): an index past the attachments, - /// an attachment without a texture, and a target the descriptor's resolve texture would be - /// refused as (Metal's validation stops another pixel format or size, measured). - pub fn set_color_resolve_target( +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::set_color_resolve_target`]. + pub(crate) fn set_color_resolve_target( &mut self, target: Option, index: u32, @@ -152,18 +150,17 @@ impl RenderCommandEncoder { Ok(()) } - /// The depth attachment resolves into `target` (`None`: nowhere), whatever the descriptor - /// named. Refused as [`RenderCommandEncoder::set_color_resolve_target`] is, and as the - /// descriptor's depth resolve is where the stencil attachment is the same texture (both - /// aspects into one texture, the stencil stored while the depth resolves). - pub fn set_depth_resolve_target(&mut self, target: Option) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_depth_resolve_target`]. + pub(crate) fn set_depth_resolve_target( + &mut self, + target: Option, + ) -> Result<(), Error> { self.log(|_| RenderCall::DepthResolveTarget(target.clone().map(Box::new))); self.set_aspect_resolve_target("set_depth_resolve_target", Attachment::Depth, target) } - /// The stencil attachment resolves into `target` (`None`: nowhere). Refused as - /// [`RenderCommandEncoder::set_depth_resolve_target`] is, the aspects swapped. - pub fn set_stencil_resolve_target( + /// The lowering of [`RenderCommandEncoder::set_stencil_resolve_target`]. + pub(crate) fn set_stencil_resolve_target( &mut self, target: Option, ) -> Result<(), Error> { @@ -239,6 +236,37 @@ impl RenderCommandEncoder { } } +impl RenderCommandEncoder { + /// The color attachment at `index` resolves into `target` (`None`: nowhere), whatever the + /// descriptor named (the module docs). Refused (`Invalid`): an index past the attachments, + /// an attachment without a texture, and a target the descriptor's resolve texture would be + /// refused as (Metal's validation stops another pixel format or size, measured). + pub fn set_color_resolve_target( + &mut self, + target: Option, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_color_resolve_target(target, index) + } + + /// The depth attachment resolves into `target` (`None`: nowhere), whatever the descriptor + /// named. Refused as [`RenderCommandEncoder::set_color_resolve_target`] is, and as the + /// descriptor's depth resolve is where the stencil attachment is the same texture (both + /// aspects into one texture, the stencil stored while the depth resolves). + pub fn set_depth_resolve_target(&mut self, target: Option) -> Result<(), Error> { + self.lowering.set_depth_resolve_target(target) + } + + /// The stencil attachment resolves into `target` (`None`: nowhere). Refused as + /// [`RenderCommandEncoder::set_depth_resolve_target`] is, the aspects swapped. + pub fn set_stencil_resolve_target( + &mut self, + target: Option, + ) -> Result<(), Error> { + self.lowering.set_stencil_resolve_target(target) + } +} + fn problem(call: &'static str, p: RenderPassProblem) -> Error { invalid(call, Problem::RenderPass(p)) } diff --git a/crates/metal2vulkan-runtime/src/render/mesh.rs b/crates/metal2vulkan-runtime/src/render/mesh.rs index 436d346e2..1a2644fce 100644 --- a/crates/metal2vulkan-runtime/src/render/mesh.rs +++ b/crates/metal2vulkan-runtime/src/render/mesh.rs @@ -73,6 +73,7 @@ use super::replay::Samplers; use super::RenderCommandEncoder; +use super::RenderLowering; use super::{check_arguments, draw_problem, Assembly, DrawBuffers, DrawProblem}; use super::{RenderCall, Table}; use crate::binding::{MeshRegions, PushWrite}; @@ -123,10 +124,9 @@ const METAL_THREADGROUP_THREADS: u64 = 1024; /// `VkDrawMeshTasksIndirectCommandEXT`'s. const INDIRECT_BYTES: u64 = 12; -impl RenderCommandEncoder { - /// `setObjectBuffer:offset:atIndex:` (`None` unbinds the index). Refused as - /// [`set_vertex_buffer`](Self::set_vertex_buffer) is. - pub fn set_object_buffer( +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::set_object_buffer`]. + pub(crate) fn set_object_buffer( &mut self, buffer: Option<&Buffer>, offset: u64, @@ -140,9 +140,8 @@ impl RenderCommandEncoder { .set_buffer(&mut self.core, "set_object_buffer", buffer, offset, index) } - /// `setObjectBuffers:offsets:withRange:`. Refused as - /// [`set_vertex_buffers`](Self::set_vertex_buffers) is. - pub fn set_object_buffers( + /// The lowering of [`RenderCommandEncoder::set_object_buffers`]. + pub(crate) fn set_object_buffers( &mut self, buffers: &[Option<&Buffer>], offsets: &[u64], @@ -165,25 +164,26 @@ impl RenderCommandEncoder { ) } - /// `setObjectBufferOffset:atIndex:`. Refused as - /// [`set_vertex_buffer_offset`](Self::set_vertex_buffer_offset) is. - pub fn set_object_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_object_buffer_offset`]. + pub(crate) fn set_object_buffer_offset( + &mut self, + offset: u64, + index: u32, + ) -> Result<(), Error> { self.log(|_| RenderCall::BufferOffset(Table::Object, offset, index)); self.object .set_buffer_offset(&mut self.core, "set_object_buffer_offset", offset, index) } - /// `setObjectBytes:length:atIndex:`: as [`set_vertex_bytes`](Self::set_vertex_bytes), in - /// the object stage's table. Refused as that is. - pub fn set_object_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_object_bytes`]. + pub(crate) fn set_object_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { self.log(|log| RenderCall::Bytes(Table::Object, log.byte_span(bytes), index)); self.object .set_bytes(&mut self.core, "set_object_bytes", bytes, None, index) } - /// `setObjectTexture:atIndex:` (`None` unbinds the index). Refused as - /// [`set_vertex_texture`](Self::set_vertex_texture) is. - pub fn set_object_texture( + /// The lowering of [`RenderCommandEncoder::set_object_texture`]. + pub(crate) fn set_object_texture( &mut self, texture: Option<&Texture>, index: u32, @@ -196,9 +196,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_object_texture", &[texture], index) } - /// `setObjectTextures:withRange:`. Refused as - /// [`set_vertex_textures`](Self::set_vertex_textures) is. - pub fn set_object_textures( + /// The lowering of [`RenderCommandEncoder::set_object_textures`]. + pub(crate) fn set_object_textures( &mut self, textures: &[Option<&Texture>], first: u32, @@ -208,9 +207,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_object_textures", textures, first) } - /// `setObjectSamplerState:atIndex:` (`None` unbinds the index). Refused as - /// [`set_vertex_sampler_state`](Self::set_vertex_sampler_state) is. - pub fn set_object_sampler_state( + /// The lowering of [`RenderCommandEncoder::set_object_sampler_state`]. + pub(crate) fn set_object_sampler_state( &mut self, sampler: Option<&SamplerState>, index: u32, @@ -228,10 +226,8 @@ impl RenderCommandEncoder { ) } - /// `setObjectSamplerStates:withRange:`, or with `clamps` - /// `setObjectSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as - /// [`set_vertex_sampler_states`](Self::set_vertex_sampler_states) is. - pub fn set_object_sampler_states( + /// The lowering of [`RenderCommandEncoder::set_object_sampler_states`]. + pub(crate) fn set_object_sampler_states( &mut self, samplers: &[Option<&SamplerState>], clamps: Option<(&[f32], &[f32])>, @@ -247,17 +243,8 @@ impl RenderCommandEncoder { ) } - /// `setObjectThreadgroupMemoryLength:atIndex:`: the length of the object function's - /// `[[threadgroup(index)]]` argument in the encoder's later mesh draws, whichever pipeline - /// state they use; until it is set an argument's length is 0. A length that is not a multiple - /// of 16 bytes is rounded up to 16 at the draw, as a kernel's - /// (`ComputeCommandEncoder::set_threadgroup_memory_length`) is. Refused: an index past the - /// table (`Invalid`). The object function's arena with these lengths must fit the device's - /// workgroup memory for the object stage, checked at the draw - /// (`Unsupported{ThreadgroupMemorySize}` naming the limit). An indirect command's mesh draw - /// takes none of these: one whose object function reads them is - /// `NotImplemented(IndirectRenderCommands)`. - pub fn set_object_threadgroup_memory_length( + /// The lowering of [`RenderCommandEncoder::set_object_threadgroup_memory_length`]. + pub(crate) fn set_object_threadgroup_memory_length( &mut self, length: u32, index: u32, @@ -269,9 +256,8 @@ impl RenderCommandEncoder { Ok(()) } - /// `setMeshBuffer:offset:atIndex:` (`None` unbinds the index). Refused as - /// [`set_vertex_buffer`](Self::set_vertex_buffer) is. - pub fn set_mesh_buffer( + /// The lowering of [`RenderCommandEncoder::set_mesh_buffer`]. + pub(crate) fn set_mesh_buffer( &mut self, buffer: Option<&Buffer>, offset: u64, @@ -285,9 +271,8 @@ impl RenderCommandEncoder { .set_buffer(&mut self.core, "set_mesh_buffer", buffer, offset, index) } - /// `setMeshBuffers:offsets:withRange:`. Refused as - /// [`set_vertex_buffers`](Self::set_vertex_buffers) is. - pub fn set_mesh_buffers( + /// The lowering of [`RenderCommandEncoder::set_mesh_buffers`]. + pub(crate) fn set_mesh_buffers( &mut self, buffers: &[Option<&Buffer>], offsets: &[u64], @@ -305,25 +290,26 @@ impl RenderCommandEncoder { .set_buffers(&mut self.core, "set_mesh_buffers", buffers, offsets, first) } - /// `setMeshBufferOffset:atIndex:`. Refused as - /// [`set_vertex_buffer_offset`](Self::set_vertex_buffer_offset) is. - pub fn set_mesh_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_mesh_buffer_offset`]. + pub(crate) fn set_mesh_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { self.log(|_| RenderCall::BufferOffset(Table::Mesh, offset, index)); self.mesh .set_buffer_offset(&mut self.core, "set_mesh_buffer_offset", offset, index) } - /// `setMeshBytes:length:atIndex:`: as [`set_vertex_bytes`](Self::set_vertex_bytes), in the - /// mesh stage's table. Refused as that is. - pub fn set_mesh_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_mesh_bytes`]. + pub(crate) fn set_mesh_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { self.log(|log| RenderCall::Bytes(Table::Mesh, log.byte_span(bytes), index)); self.mesh .set_bytes(&mut self.core, "set_mesh_bytes", bytes, None, index) } - /// `setMeshTexture:atIndex:` (`None` unbinds the index). Refused as - /// [`set_vertex_texture`](Self::set_vertex_texture) is. - pub fn set_mesh_texture(&mut self, texture: Option<&Texture>, index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_mesh_texture`]. + pub(crate) fn set_mesh_texture( + &mut self, + texture: Option<&Texture>, + index: u32, + ) -> Result<(), Error> { self.log(|log| { let texture = texture.map(|texture| log.hold_texture(texture)); RenderCall::Texture(Table::Mesh, texture, index) @@ -332,9 +318,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_mesh_texture", &[texture], index) } - /// `setMeshTextures:withRange:`. Refused as - /// [`set_vertex_textures`](Self::set_vertex_textures) is. - pub fn set_mesh_textures( + /// The lowering of [`RenderCommandEncoder::set_mesh_textures`]. + pub(crate) fn set_mesh_textures( &mut self, textures: &[Option<&Texture>], first: u32, @@ -344,9 +329,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_mesh_textures", textures, first) } - /// `setMeshSamplerState:atIndex:` (`None` unbinds the index). Refused as - /// [`set_vertex_sampler_state`](Self::set_vertex_sampler_state) is. - pub fn set_mesh_sampler_state( + /// The lowering of [`RenderCommandEncoder::set_mesh_sampler_state`]. + pub(crate) fn set_mesh_sampler_state( &mut self, sampler: Option<&SamplerState>, index: u32, @@ -364,10 +348,8 @@ impl RenderCommandEncoder { ) } - /// `setMeshSamplerStates:withRange:`, or with `clamps` - /// `setMeshSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as - /// [`set_vertex_sampler_states`](Self::set_vertex_sampler_states) is. - pub fn set_mesh_sampler_states( + /// The lowering of [`RenderCommandEncoder::set_mesh_sampler_states`]. + pub(crate) fn set_mesh_sampler_states( &mut self, samplers: &[Option<&SamplerState>], clamps: Option<(&[f32], &[f32])>, @@ -383,10 +365,8 @@ impl RenderCommandEncoder { ) } - /// `drawMeshThreadgroups:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup:`: `groups` - /// mesh threadgroups of `threads_per_mesh_group` threads (the module docs). Refused as the - /// module docs say, and for a size past 32 bits on an axis (`Invalid(SizeOutOfRange)`). - pub fn draw_mesh_threadgroups( + /// The lowering of [`RenderCommandEncoder::draw_mesh_threadgroups`]. + pub(crate) fn draw_mesh_threadgroups( &mut self, groups: Size, threads_per_object_group: Size, @@ -406,10 +386,8 @@ impl RenderCommandEncoder { self.draw_mesh(CALL, grid, object, mesh) } - /// `drawMeshThreads:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup:`: the whole mesh - /// threadgroups of `threads_per_mesh_group` threads that `threads` fill (the module docs). - /// Refused as [`draw_mesh_threadgroups`](Self::draw_mesh_threadgroups) is. - pub fn draw_mesh_threads( + /// The lowering of [`RenderCommandEncoder::draw_mesh_threads`]. + pub(crate) fn draw_mesh_threads( &mut self, threads: Size, threads_per_object_group: Size, @@ -462,15 +440,8 @@ impl RenderCommandEncoder { self.draw(call, Assembly::Meshes, draw, DrawBuffers::default(), empty) } - /// `drawMeshThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerObjectThreadgroup: - /// threadsPerMeshThreadgroup:`: Metal's `MTLDispatchThreadgroupsIndirectArguments` at - /// `indirect_buffer_offset`, the threadgroups' counts. Refused as - /// [`draw_mesh_threadgroups`](Self::draw_mesh_threadgroups) is, as an indirect draw's - /// arguments are (`render.rs`'s module docs), and for an indirect buffer of another device. - /// On a device with `VK_EXT_mesh_shader` the draw is `NotImplemented(IndirectDrawArguments)`, - /// and on one without it, of a pipeline with an object function, `NotImplemented(MeshShading)` - /// (the module docs). - pub fn draw_mesh_threadgroups_indirect( + /// The lowering of [`RenderCommandEncoder::draw_mesh_threadgroups_indirect`]. + pub(crate) fn draw_mesh_threadgroups_indirect( &mut self, indirect_buffer: &Buffer, indirect_buffer_offset: u64, @@ -567,6 +538,229 @@ impl RenderCommandEncoder { } } +impl RenderCommandEncoder { + /// `setObjectBuffer:offset:atIndex:` (`None` unbinds the index). Refused as + /// [`set_vertex_buffer`](Self::set_vertex_buffer) is. + pub fn set_object_buffer( + &mut self, + buffer: Option<&Buffer>, + offset: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_object_buffer(buffer, offset, index) + } + + /// `setObjectBuffers:offsets:withRange:`. Refused as + /// [`set_vertex_buffers`](Self::set_vertex_buffers) is. + pub fn set_object_buffers( + &mut self, + buffers: &[Option<&Buffer>], + offsets: &[u64], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_object_buffers(buffers, offsets, first) + } + + /// `setObjectBufferOffset:atIndex:`. Refused as + /// [`set_vertex_buffer_offset`](Self::set_vertex_buffer_offset) is. + pub fn set_object_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + self.lowering.set_object_buffer_offset(offset, index) + } + + /// `setObjectBytes:length:atIndex:`: as [`set_vertex_bytes`](Self::set_vertex_bytes), in + /// the object stage's table. Refused as that is. + pub fn set_object_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + self.lowering.set_object_bytes(bytes, index) + } + + /// `setObjectTexture:atIndex:` (`None` unbinds the index). Refused as + /// [`set_vertex_texture`](Self::set_vertex_texture) is. + pub fn set_object_texture( + &mut self, + texture: Option<&Texture>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_object_texture(texture, index) + } + + /// `setObjectTextures:withRange:`. Refused as + /// [`set_vertex_textures`](Self::set_vertex_textures) is. + pub fn set_object_textures( + &mut self, + textures: &[Option<&Texture>], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_object_textures(textures, first) + } + + /// `setObjectSamplerState:atIndex:` (`None` unbinds the index). Refused as + /// [`set_vertex_sampler_state`](Self::set_vertex_sampler_state) is. + pub fn set_object_sampler_state( + &mut self, + sampler: Option<&SamplerState>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_object_sampler_state(sampler, index) + } + + /// `setObjectSamplerStates:withRange:`, or with `clamps` + /// `setObjectSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as + /// [`set_vertex_sampler_states`](Self::set_vertex_sampler_states) is. + pub fn set_object_sampler_states( + &mut self, + samplers: &[Option<&SamplerState>], + clamps: Option<(&[f32], &[f32])>, + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_object_sampler_states(samplers, clamps, first) + } + + /// `setObjectThreadgroupMemoryLength:atIndex:`: the length of the object function's + /// `[[threadgroup(index)]]` argument in the encoder's later mesh draws, whichever pipeline + /// state they use; until it is set an argument's length is 0. A length that is not a multiple + /// of 16 bytes is rounded up to 16 at the draw, as a kernel's + /// (`ComputeCommandEncoder::set_threadgroup_memory_length`) is. Refused: an index past the + /// table (`Invalid`). The object function's arena with these lengths must fit the device's + /// workgroup memory for the object stage, checked at the draw + /// (`Unsupported{ThreadgroupMemorySize}` naming the limit). An indirect command's mesh draw + /// takes none of these: one whose object function reads them is + /// `NotImplemented(IndirectRenderCommands)`. + pub fn set_object_threadgroup_memory_length( + &mut self, + length: u32, + index: u32, + ) -> Result<(), Error> { + self.lowering + .set_object_threadgroup_memory_length(length, index) + } + + /// `setMeshBuffer:offset:atIndex:` (`None` unbinds the index). Refused as + /// [`set_vertex_buffer`](Self::set_vertex_buffer) is. + pub fn set_mesh_buffer( + &mut self, + buffer: Option<&Buffer>, + offset: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_mesh_buffer(buffer, offset, index) + } + + /// `setMeshBuffers:offsets:withRange:`. Refused as + /// [`set_vertex_buffers`](Self::set_vertex_buffers) is. + pub fn set_mesh_buffers( + &mut self, + buffers: &[Option<&Buffer>], + offsets: &[u64], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_mesh_buffers(buffers, offsets, first) + } + + /// `setMeshBufferOffset:atIndex:`. Refused as + /// [`set_vertex_buffer_offset`](Self::set_vertex_buffer_offset) is. + pub fn set_mesh_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + self.lowering.set_mesh_buffer_offset(offset, index) + } + + /// `setMeshBytes:length:atIndex:`: as [`set_vertex_bytes`](Self::set_vertex_bytes), in the + /// mesh stage's table. Refused as that is. + pub fn set_mesh_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + self.lowering.set_mesh_bytes(bytes, index) + } + + /// `setMeshTexture:atIndex:` (`None` unbinds the index). Refused as + /// [`set_vertex_texture`](Self::set_vertex_texture) is. + pub fn set_mesh_texture(&mut self, texture: Option<&Texture>, index: u32) -> Result<(), Error> { + self.lowering.set_mesh_texture(texture, index) + } + + /// `setMeshTextures:withRange:`. Refused as + /// [`set_vertex_textures`](Self::set_vertex_textures) is. + pub fn set_mesh_textures( + &mut self, + textures: &[Option<&Texture>], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_mesh_textures(textures, first) + } + + /// `setMeshSamplerState:atIndex:` (`None` unbinds the index). Refused as + /// [`set_vertex_sampler_state`](Self::set_vertex_sampler_state) is. + pub fn set_mesh_sampler_state( + &mut self, + sampler: Option<&SamplerState>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_mesh_sampler_state(sampler, index) + } + + /// `setMeshSamplerStates:withRange:`, or with `clamps` + /// `setMeshSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as + /// [`set_vertex_sampler_states`](Self::set_vertex_sampler_states) is. + pub fn set_mesh_sampler_states( + &mut self, + samplers: &[Option<&SamplerState>], + clamps: Option<(&[f32], &[f32])>, + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_mesh_sampler_states(samplers, clamps, first) + } + + /// `drawMeshThreadgroups:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup:`: `groups` + /// mesh threadgroups of `threads_per_mesh_group` threads (the module docs). Refused as the + /// module docs say, and for a size past 32 bits on an axis (`Invalid(SizeOutOfRange)`). + pub fn draw_mesh_threadgroups( + &mut self, + groups: Size, + threads_per_object_group: Size, + threads_per_mesh_group: Size, + ) -> Result<(), Error> { + self.lowering.draw_mesh_threadgroups( + groups, + threads_per_object_group, + threads_per_mesh_group, + ) + } + + /// `drawMeshThreads:threadsPerObjectThreadgroup:threadsPerMeshThreadgroup:`: the whole mesh + /// threadgroups of `threads_per_mesh_group` threads that `threads` fill (the module docs). + /// Refused as [`draw_mesh_threadgroups`](Self::draw_mesh_threadgroups) is. + pub fn draw_mesh_threads( + &mut self, + threads: Size, + threads_per_object_group: Size, + threads_per_mesh_group: Size, + ) -> Result<(), Error> { + self.lowering + .draw_mesh_threads(threads, threads_per_object_group, threads_per_mesh_group) + } + + /// `drawMeshThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerObjectThreadgroup: + /// threadsPerMeshThreadgroup:`: Metal's `MTLDispatchThreadgroupsIndirectArguments` at + /// `indirect_buffer_offset`, the threadgroups' counts. Refused as + /// [`draw_mesh_threadgroups`](Self::draw_mesh_threadgroups) is, as an indirect draw's + /// arguments are (`render.rs`'s module docs), and for an indirect buffer of another device. + /// On a device with `VK_EXT_mesh_shader` the draw is `NotImplemented(IndirectDrawArguments)`, + /// and on one without it, of a pipeline with an object function, `NotImplemented(MeshShading)` + /// (the module docs). + pub fn draw_mesh_threadgroups_indirect( + &mut self, + indirect_buffer: &Buffer, + indirect_buffer_offset: u64, + threads_per_object_group: Size, + threads_per_mesh_group: Size, + ) -> Result<(), Error> { + self.lowering.draw_mesh_threadgroups_indirect( + indirect_buffer, + indirect_buffer_offset, + threads_per_object_group, + threads_per_mesh_group, + ) + } +} + /// A direct mesh draw's grid: of threadgroups (`drawMeshThreadgroups`) or of threads /// (`drawMeshThreads`). #[derive(Clone, Copy, Debug)] diff --git a/crates/metal2vulkan-runtime/src/render/replay.rs b/crates/metal2vulkan-runtime/src/render/replay.rs index 8d6c6cb5d..5e9342c88 100644 --- a/crates/metal2vulkan-runtime/src/render/replay.rs +++ b/crates/metal2vulkan-runtime/src/render/replay.rs @@ -15,7 +15,7 @@ //! buffer, where an encoding again would leave the first one's beside its own. //! - **Per-stage calls** share a variant, with the [`Table`] they set. -use super::RenderCommandEncoder; +use super::RenderLowering; use crate::amplification::VertexAmplificationViewMapping; use crate::buffer::Buffer; use crate::command_buffer::CommandBuffer; @@ -103,7 +103,7 @@ impl RenderLog { /// (`render/color_groups.rs`). A call refused there was refused in the first group's /// encoder, whose answer the program had, or is a divergence the later group's encoder notes /// (`RenderCommandEncoder::group_outcome`): either way the calls after it run. - pub(crate) fn replay_into(&self, encoder: &mut RenderCommandEncoder) { + pub(crate) fn replay_into(&self, encoder: &mut RenderLowering) { for call in &self.calls.calls { let _ = render(encoder, (&self.calls, &self.indexed), call); } @@ -115,8 +115,7 @@ impl RenderLog { command_buffer: &CommandBuffer, residency: Residency, ) -> Result<(Replayed, Option), Error> { - let mut encoder = - RenderCommandEncoder::replaying(command_buffer, &self.descriptor, residency)?; + let mut encoder = RenderLowering::replaying(command_buffer, &self.descriptor, residency)?; for call in &self.calls.calls { render(&mut encoder, (&self.calls, &self.indexed), call)?; } @@ -345,7 +344,7 @@ pub(crate) struct DrawIndexedPatchesIndirect { pub(super) indirect_buffer_offset: u64, } -impl RenderCommandEncoder { +impl RenderLowering { /// Log the call `call` makes of the log, before it runs, where the encoder logs (the module /// docs). pub(crate) fn log(&mut self, call: impl FnOnce(&mut CallLog) -> RenderCall) { @@ -376,7 +375,7 @@ impl RenderCommandEncoder { /// Run `call` again on `encoder`, its slices in `log`'s arenas and an indexed draw's arguments in /// `indexed`. fn render( - encoder: &mut RenderCommandEncoder, + encoder: &mut RenderLowering, (log, indexed): (&CallLog, &[DrawIndexed]), call: &RenderCall, ) -> Result<(), Error> { diff --git a/crates/metal2vulkan-runtime/src/render/reroute.rs b/crates/metal2vulkan-runtime/src/render/reroute.rs index c5d964bb9..fdd08ed7a 100644 --- a/crates/metal2vulkan-runtime/src/render/reroute.rs +++ b/crates/metal2vulkan-runtime/src/render/reroute.rs @@ -35,7 +35,7 @@ //! view or image of its own, so a texture's storage form taking another image after the command //! buffer commits (`texture/storage_form.rs`) changes nothing it records. -use super::{Assembly, DrawBuffers, Next, RenderCommandEncoder}; +use super::{Assembly, DrawBuffers, Next, RenderLowering}; use crate::amplification::Amplification; use crate::argument_table::ArgumentTable; use crate::draw_source::{DrawSource, KeptSource}; @@ -94,7 +94,7 @@ struct Held { amplification: Amplification, } -impl RenderCommandEncoder { +impl RenderLowering { /// Keep the draw just recorded into the current instance (`call` of `assembly` and `draw`, /// its indices from `index`) for recording again where `again` (the module docs) and the /// instance keeps fewer than `MAX_DRAWS`; otherwise the instance's draws record again no diff --git a/crates/metal2vulkan-runtime/src/render/restart.rs b/crates/metal2vulkan-runtime/src/render/restart.rs index 91caa26b8..85a2c245d 100644 --- a/crates/metal2vulkan-runtime/src/render/restart.rs +++ b/crates/metal2vulkan-runtime/src/render/restart.rs @@ -22,7 +22,8 @@ //! rewrite pass writes (`index_rewrite.rs`), with the class's list topology. use super::RenderCall; -use super::{Assembly, RenderCommandEncoder}; +use super::RenderCommandEncoder; +use super::{Assembly, RenderLowering}; use metal2vulkan::bind::{DrawCall, RewriteProgram}; use metal2vulkan::metal::PrimitiveType; @@ -45,16 +46,9 @@ impl Restarted { } } -impl RenderCommandEncoder { - /// `setPrimitiveRestartEnabled:index:` (SPI): the encoder's indexed line and triangle strips - /// drawn after the call restart at `index` as Metal takes it for their index type (`k mod - /// 2^32` for 32-bit indices, the lesser of that and `0xffff` for 16-bit ones), and only - /// there: the all-ones index then draws as a vertex unless it is that index. `_enabled` - /// changes nothing, as on Metal. Lists, points, draws without indices and executions of - /// indirect render commands are as before; the last call wins until the encoder ends (an M4). A - /// strip restarting elsewhere than at the all-ones index is drawn as a list a GPU pass writes - /// before the pass; a draw it cannot draw so is refused (`NotImplemented(RestartedStrip)`). - pub fn set_primitive_restart_enabled(&mut self, _enabled: bool, index: u64) { +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::set_primitive_restart_enabled`]. + pub(crate) fn set_primitive_restart_enabled(&mut self, _enabled: bool, index: u64) { self.log(|_| RenderCall::PrimitiveRestartEnabled(_enabled, index)); self.restart = Some(index); } @@ -87,6 +81,20 @@ impl RenderCommandEncoder { } } +impl RenderCommandEncoder { + /// `setPrimitiveRestartEnabled:index:` (SPI): the encoder's indexed line and triangle strips + /// drawn after the call restart at `index` as Metal takes it for their index type (`k mod + /// 2^32` for 32-bit indices, the lesser of that and `0xffff` for 16-bit ones), and only + /// there: the all-ones index then draws as a vertex unless it is that index. `_enabled` + /// changes nothing, as on Metal. Lists, points, draws without indices and executions of + /// indirect render commands are as before; the last call wins until the encoder ends (an M4). A + /// strip restarting elsewhere than at the all-ones index is drawn as a list a GPU pass writes + /// before the pass; a draw it cannot draw so is refused (`NotImplemented(RestartedStrip)`). + pub fn set_primitive_restart_enabled(&mut self, _enabled: bool, index: u64) { + self.lowering.set_primitive_restart_enabled(_enabled, index) + } +} + /// `k'` for a call with `k` over 32-bit indices (`wide`) or 16-bit ones, and the index type's /// all-ones index. fn restart_index(k: u64, wide: bool) -> (u32, u32) { diff --git a/crates/metal2vulkan-runtime/src/render/snapshot.rs b/crates/metal2vulkan-runtime/src/render/snapshot.rs index 95473b9d3..c140aec9b 100644 --- a/crates/metal2vulkan-runtime/src/render/snapshot.rs +++ b/crates/metal2vulkan-runtime/src/render/snapshot.rs @@ -102,7 +102,7 @@ //! share of their colors' pixels and texel bytes, a line at 64 of them, each power of two //! after, and as the device ends (`metal2vulkan-snapshot-readers`, `reader_sizes.rs`). -use super::{Reformat, RenderCommandEncoder}; +use super::{Reformat, RenderLowering}; use crate::copy_plan::block_bytes; use crate::dynamic_state::ColorWriteMasks; use crate::pipeline::{GraphicsState as DrawingState, Settled}; @@ -248,7 +248,7 @@ pub(super) fn phase_hole(holes: &[PushHole]) -> Option<(vk::ShaderStageFlags, u3 }) } -impl RenderCommandEncoder { +impl RenderLowering { /// What a draw of `pipeline` (its state's base) through `reformats` asks to read through /// snapshots, where it can ask (the module docs' checks that come before the plan); `None` /// where it reads no attachment so or takes the split. diff --git a/crates/metal2vulkan-runtime/src/render/tile_dispatch.rs b/crates/metal2vulkan-runtime/src/render/tile_dispatch.rs index 8850f8a07..fe99523c0 100644 --- a/crates/metal2vulkan-runtime/src/render/tile_dispatch.rs +++ b/crates/metal2vulkan-runtime/src/render/tile_dispatch.rs @@ -97,7 +97,8 @@ use super::pending_tile::{TileCall, TilePipelines}; use super::replay::Samplers; use super::shadows::InstanceShadows; -use super::{draw_problem, DrawProblem, RenderCommandEncoder}; +use super::RenderCommandEncoder; +use super::{draw_problem, DrawProblem, RenderLowering}; use super::{RenderCall, Table}; use crate::address_map; use crate::attachment_stand_in; @@ -579,23 +580,19 @@ fn scratch( }) } -impl RenderCommandEncoder { - /// `tileWidth`: the pass's tile width, or the default for its samples (32; `tile_pass.rs`). - /// Not measured (`NotImplemented(TileAtSampleCount)`) in a pass of a sample count Apple's - /// GPUs lack. - pub fn tile_width(&self) -> Result { +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::tile_width`]. + pub(crate) fn tile_width(&self) -> Result { self.layout.tile_size().map(|[width, _]| width.into()) } - /// `tileHeight`: the pass's tile height, or the default for its samples (32, and 16 at 4 - /// samples; `tile_pass.rs`). Not measured as [`RenderCommandEncoder::tile_width`] is not. - pub fn tile_height(&self) -> Result { + /// The lowering of [`RenderCommandEncoder::tile_height`]. + pub(crate) fn tile_height(&self) -> Result { self.layout.tile_size().map(|[_, height]| height.into()) } - /// `setTileBuffer:offset:atIndex:` (`None` unbinds the index). Refused as - /// [`RenderCommandEncoder::set_vertex_buffer`] is. - pub fn set_tile_buffer( + /// The lowering of [`RenderCommandEncoder::set_tile_buffer`]. + pub(crate) fn set_tile_buffer( &mut self, buffer: Option<&Buffer>, offset: u64, @@ -609,9 +606,8 @@ impl RenderCommandEncoder { .set_buffer(&mut self.core, "set_tile_buffer", buffer, offset, index) } - /// `setTileBuffers:offsets:withRange:`. Refused as - /// [`RenderCommandEncoder::set_vertex_buffers`] is. - pub fn set_tile_buffers( + /// The lowering of [`RenderCommandEncoder::set_tile_buffers`]. + pub(crate) fn set_tile_buffers( &mut self, buffers: &[Option<&Buffer>], offsets: &[u64], @@ -629,26 +625,26 @@ impl RenderCommandEncoder { .set_buffers(&mut self.core, "set_tile_buffers", buffers, offsets, first) } - /// `setTileBufferOffset:atIndex:`. Refused as - /// [`RenderCommandEncoder::set_vertex_buffer_offset`] is. - pub fn set_tile_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_tile_buffer_offset`]. + pub(crate) fn set_tile_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { self.log(|_| RenderCall::BufferOffset(Table::Tile, offset, index)); self.tile .set_buffer_offset(&mut self.core, "set_tile_buffer_offset", offset, index) } - /// `setTileBytes:length:atIndex:`: as - /// [`RenderCommandEncoder::set_vertex_bytes`], in the tile stage's table, which the pass's - /// later tile dispatches read. Refused as that is. - pub fn set_tile_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_tile_bytes`]. + pub(crate) fn set_tile_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { self.log(|log| RenderCall::Bytes(Table::Tile, log.byte_span(bytes), index)); self.tile .set_bytes(&mut self.core, "set_tile_bytes", bytes, None, index) } - /// `setTileTexture:atIndex:` (`None` unbinds the index). Refused as - /// [`RenderCommandEncoder::set_vertex_texture`] is. - pub fn set_tile_texture(&mut self, texture: Option<&Texture>, index: u32) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::set_tile_texture`]. + pub(crate) fn set_tile_texture( + &mut self, + texture: Option<&Texture>, + index: u32, + ) -> Result<(), Error> { self.log(|log| { let texture = texture.map(|texture| log.hold_texture(texture)); RenderCall::Texture(Table::Tile, texture, index) @@ -657,9 +653,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_tile_texture", &[texture], index) } - /// `setTileTextures:withRange:`. Refused as - /// [`RenderCommandEncoder::set_vertex_textures`] is. - pub fn set_tile_textures( + /// The lowering of [`RenderCommandEncoder::set_tile_textures`]. + pub(crate) fn set_tile_textures( &mut self, textures: &[Option<&Texture>], first: u32, @@ -669,9 +664,8 @@ impl RenderCommandEncoder { .set_textures(&mut self.core, "set_tile_textures", textures, first) } - /// `setTileSamplerState:atIndex:` (`None` unbinds the index). Refused as - /// [`RenderCommandEncoder::set_vertex_sampler_state`] is. - pub fn set_tile_sampler_state( + /// The lowering of [`RenderCommandEncoder::set_tile_sampler_state`]. + pub(crate) fn set_tile_sampler_state( &mut self, sampler: Option<&SamplerState>, index: u32, @@ -689,10 +683,8 @@ impl RenderCommandEncoder { ) } - /// `setTileSamplerStates:withRange:`, or with `clamps` - /// `setTileSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as - /// [`RenderCommandEncoder::set_vertex_sampler_states`] is. - pub fn set_tile_sampler_states( + /// The lowering of [`RenderCommandEncoder::set_tile_sampler_states`]. + pub(crate) fn set_tile_sampler_states( &mut self, samplers: &[Option<&SamplerState>], clamps: Option<(&[f32], &[f32])>, @@ -708,26 +700,14 @@ impl RenderCommandEncoder { ) } - /// `dispatchThreadsPerTile:`: run the tile pipeline's state set on every tile of the pass - /// (the module docs). Threads per tile of a depth other than 1 run as 1, and threads per tile - /// past Metal's limit for the state run nothing, as plain Metal runs them. Refused - /// (`Invalid`), as Metal's validation refuses it: no state set, a drawing state - /// (`DrawProblem::NotTileState`), threads per tile that are empty or wider or taller than - /// the pass's tile (`DrawProblem::ThreadsPerTilePastTile`). What the binder refuses is - /// refused (`Bind`, `Unsupported`), threads per tile within Metal's limit but past the - /// state's `max_total_threads_per_threadgroup` (this device's lower limit) among them. A - /// refused dispatch records nothing and changes nothing. - pub fn dispatch_threads_per_tile(&mut self, threads: Size) -> Result<(), Error> { + /// The lowering of [`RenderCommandEncoder::dispatch_threads_per_tile`]. + pub(crate) fn dispatch_threads_per_tile(&mut self, threads: Size) -> Result<(), Error> { self.log(|_| RenderCall::ThreadsPerTile(Box::new(threads))); self.dispatch_tiles("dispatch_threads_per_tile", threads, None) } - /// `dispatchThreadsPerTile:inRegion:`, or with `render_target_array_index` - /// `dispatchThreadsPerTile:inRegion:withRenderTargetArrayIndex:` (SPI): run the tile - /// pipeline's state set on the tiles of the pass that `region`'s pixels touch, each as - /// [`RenderCommandEncoder::dispatch_threads_per_tile`] runs it (the module docs). Refused as - /// that is; a region that touches no tile runs nothing. - pub fn dispatch_threads_per_tile_in_region( + /// The lowering of [`RenderCommandEncoder::dispatch_threads_per_tile_in_region`]. + pub(crate) fn dispatch_threads_per_tile_in_region( &mut self, threads: Size, region: Region, @@ -1306,6 +1286,126 @@ impl RenderCommandEncoder { } } +impl RenderCommandEncoder { + /// `tileWidth`: the pass's tile width, or the default for its samples (32; `tile_pass.rs`). + /// Not measured (`NotImplemented(TileAtSampleCount)`) in a pass of a sample count Apple's + /// GPUs lack. + pub fn tile_width(&self) -> Result { + self.lowering.tile_width() + } + + /// `tileHeight`: the pass's tile height, or the default for its samples (32, and 16 at 4 + /// samples; `tile_pass.rs`). Not measured as [`RenderCommandEncoder::tile_width`] is not. + pub fn tile_height(&self) -> Result { + self.lowering.tile_height() + } + + /// `setTileBuffer:offset:atIndex:` (`None` unbinds the index). Refused as + /// [`RenderCommandEncoder::set_vertex_buffer`] is. + pub fn set_tile_buffer( + &mut self, + buffer: Option<&Buffer>, + offset: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_tile_buffer(buffer, offset, index) + } + + /// `setTileBuffers:offsets:withRange:`. Refused as + /// [`RenderCommandEncoder::set_vertex_buffers`] is. + pub fn set_tile_buffers( + &mut self, + buffers: &[Option<&Buffer>], + offsets: &[u64], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_tile_buffers(buffers, offsets, first) + } + + /// `setTileBufferOffset:atIndex:`. Refused as + /// [`RenderCommandEncoder::set_vertex_buffer_offset`] is. + pub fn set_tile_buffer_offset(&mut self, offset: u64, index: u32) -> Result<(), Error> { + self.lowering.set_tile_buffer_offset(offset, index) + } + + /// `setTileBytes:length:atIndex:`: as + /// [`RenderCommandEncoder::set_vertex_bytes`], in the tile stage's table, which the pass's + /// later tile dispatches read. Refused as that is. + pub fn set_tile_bytes(&mut self, bytes: &[u8], index: u32) -> Result<(), Error> { + self.lowering.set_tile_bytes(bytes, index) + } + + /// `setTileTexture:atIndex:` (`None` unbinds the index). Refused as + /// [`RenderCommandEncoder::set_vertex_texture`] is. + pub fn set_tile_texture(&mut self, texture: Option<&Texture>, index: u32) -> Result<(), Error> { + self.lowering.set_tile_texture(texture, index) + } + + /// `setTileTextures:withRange:`. Refused as + /// [`RenderCommandEncoder::set_vertex_textures`] is. + pub fn set_tile_textures( + &mut self, + textures: &[Option<&Texture>], + first: u32, + ) -> Result<(), Error> { + self.lowering.set_tile_textures(textures, first) + } + + /// `setTileSamplerState:atIndex:` (`None` unbinds the index). Refused as + /// [`RenderCommandEncoder::set_vertex_sampler_state`] is. + pub fn set_tile_sampler_state( + &mut self, + sampler: Option<&SamplerState>, + index: u32, + ) -> Result<(), Error> { + self.lowering.set_tile_sampler_state(sampler, index) + } + + /// `setTileSamplerStates:withRange:`, or with `clamps` + /// `setTileSamplerStates:lodMinClamps:lodMaxClamps:withRange:`. Refused as + /// [`RenderCommandEncoder::set_vertex_sampler_states`] is. + pub fn set_tile_sampler_states( + &mut self, + samplers: &[Option<&SamplerState>], + clamps: Option<(&[f32], &[f32])>, + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_tile_sampler_states(samplers, clamps, first) + } + + /// `dispatchThreadsPerTile:`: run the tile pipeline's state set on every tile of the pass + /// (the module docs). Threads per tile of a depth other than 1 run as 1, and threads per tile + /// past Metal's limit for the state run nothing, as plain Metal runs them. Refused + /// (`Invalid`), as Metal's validation refuses it: no state set, a drawing state + /// (`DrawProblem::NotTileState`), threads per tile that are empty or wider or taller than + /// the pass's tile (`DrawProblem::ThreadsPerTilePastTile`). What the binder refuses is + /// refused (`Bind`, `Unsupported`), threads per tile within Metal's limit but past the + /// state's `max_total_threads_per_threadgroup` (this device's lower limit) among them. A + /// refused dispatch records nothing and changes nothing. + pub fn dispatch_threads_per_tile(&mut self, threads: Size) -> Result<(), Error> { + self.lowering.dispatch_threads_per_tile(threads) + } + + /// `dispatchThreadsPerTile:inRegion:`, or with `render_target_array_index` + /// `dispatchThreadsPerTile:inRegion:withRenderTargetArrayIndex:` (SPI): run the tile + /// pipeline's state set on the tiles of the pass that `region`'s pixels touch, each as + /// [`RenderCommandEncoder::dispatch_threads_per_tile`] runs it (the module docs). Refused as + /// that is; a region that touches no tile runs nothing. + pub fn dispatch_threads_per_tile_in_region( + &mut self, + threads: Size, + region: Region, + render_target_array_index: Option, + ) -> Result<(), Error> { + self.lowering.dispatch_threads_per_tile_in_region( + threads, + region, + render_target_array_index, + ) + } +} + /// The tiles `region`'s pixels touch in a pass of `groups` tiles of `tile` pixels, per axis /// `(first, count)`, as Metal takes the region (the module docs): in 32-bit arithmetic that wraps, /// the first tile is `x / tile`, the end `(x + w + tile - 1) / tile`, and the count `end - first`, diff --git a/crates/metal2vulkan-runtime/src/render/tile_memory.rs b/crates/metal2vulkan-runtime/src/render/tile_memory.rs index 8e6e3ef22..2d374e4ba 100644 --- a/crates/metal2vulkan-runtime/src/render/tile_memory.rs +++ b/crates/metal2vulkan-runtime/src/render/tile_memory.rs @@ -48,6 +48,7 @@ use super::RenderCall; use super::RenderCommandEncoder; +use super::RenderLowering; use crate::argument_table::{check_index, BUFFER_SLOTS}; use crate::buffer::Buffer; use crate::error::{internal, invalid, Error, Problem}; @@ -119,14 +120,9 @@ impl TileMemory { } } -impl RenderCommandEncoder { - /// `setThreadgroupMemoryLength:offset:atIndex:`: a tile or fragment function's threadgroup - /// argument `index` is `length` bytes at byte `offset` of its tile's threadgroup memory, for - /// the encoder's later tile dispatches and draws (the module docs). Refused (`Invalid`), as Metal's - /// validation refuses it: an index past the table (`IndexOutOfRange`), and a length or an - /// offset that is not a multiple of 16 bytes, or an argument that ends past the pass's - /// `threadgroupMemoryLength` (`TileThreadgroupArgument`). - pub fn set_threadgroup_memory_length( +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::set_threadgroup_memory_length`]. + pub(crate) fn set_threadgroup_memory_length( &mut self, length: u64, offset: u64, @@ -157,3 +153,21 @@ impl RenderCommandEncoder { Ok(()) } } + +impl RenderCommandEncoder { + /// `setThreadgroupMemoryLength:offset:atIndex:`: a tile or fragment function's threadgroup + /// argument `index` is `length` bytes at byte `offset` of its tile's threadgroup memory, for + /// the encoder's later tile dispatches and draws (the module docs). Refused (`Invalid`), as Metal's + /// validation refuses it: an index past the table (`IndexOutOfRange`), and a length or an + /// offset that is not a multiple of 16 bytes, or an argument that ends past the pass's + /// `threadgroupMemoryLength` (`TileThreadgroupArgument`). + pub fn set_threadgroup_memory_length( + &mut self, + length: u64, + offset: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering + .set_threadgroup_memory_length(length, offset, index) + } +} diff --git a/crates/metal2vulkan-runtime/src/render/vertex_reach.rs b/crates/metal2vulkan-runtime/src/render/vertex_reach.rs index 147ce6b2f..82f966fe4 100644 --- a/crates/metal2vulkan-runtime/src/render/vertex_reach.rs +++ b/crates/metal2vulkan-runtime/src/render/vertex_reach.rs @@ -21,7 +21,7 @@ //! 32-bit indices, or an indirect draw, that pulls an attribute at a stride from such a buffer //! is refused whatever its indices or arguments hold: they are GPU memory. -use super::RenderCommandEncoder; +use super::RenderLowering; use crate::error::{Error, RuntimeGap}; use crate::fetch_reach::{format_bytes, reach, REACHED}; use metal2vulkan::bind::DrawCall; @@ -29,7 +29,7 @@ use metal2vulkan::metal::VertexStepFunction; use metal2vulkan::pipeline::{PulledAttribute, VertexStride}; use metal2vulkan::vk; -impl RenderCommandEncoder { +impl RenderLowering { /// Refuse `draw` (`NotImplemented(VertexFetchPast4GiB)`, the module docs) where it may /// read an attribute of `pulled`, its pipeline variant's pulled attributes, past `2^32` bytes /// of the bind offset of a buffer of the encoder's vertex table that runs past them. diff --git a/crates/metal2vulkan-runtime/src/render/vertex_strides.rs b/crates/metal2vulkan-runtime/src/render/vertex_strides.rs index 8bb8a6b09..34cdf6973 100644 --- a/crates/metal2vulkan-runtime/src/render/vertex_strides.rs +++ b/crates/metal2vulkan-runtime/src/render/vertex_strides.rs @@ -22,16 +22,13 @@ use super::RenderCall; use super::RenderCommandEncoder; +use super::RenderLowering; use crate::buffer::Buffer; use crate::error::Error; -impl RenderCommandEncoder { - /// `setVertexBuffer:offset:attributeStride:atIndex:`: as - /// [`set_vertex_buffer`](Self::set_vertex_buffer), the buffer read at `stride` by a layout of - /// `MTLBufferLayoutStrideDynamic` (the module docs); `MTLAttributeStrideStatic` (`u64::MAX`) - /// sets no stride; any other stride past 32 bits is taken modulo `2^32`, as plain Metal - /// reads it and its validation takes it (an M4). Refused as `set_vertex_buffer` is. - pub fn set_vertex_buffer_with_stride( +impl RenderLowering { + /// The lowering of [`RenderCommandEncoder::set_vertex_buffer_with_stride`]. + pub(crate) fn set_vertex_buffer_with_stride( &mut self, buffer: Option<&Buffer>, offset: u64, @@ -52,13 +49,8 @@ impl RenderCommandEncoder { ) } - /// `setVertexBytes:length:attributeStride:atIndex:`: as - /// [`set_vertex_bytes`](Self::set_vertex_bytes), the bytes read at `stride`, its low 32 bits, - /// by a layout of `MTLBufferLayoutStrideDynamic`. At `MTLAttributeStrideStatic` (`u64::MAX`) - /// a draw whose layout reads them so is refused (`Bind(MissingVertexStride)`): an M4 read - /// element 0 of the bytes and zeros past it there, which the fetch does not emulate. Refused as - /// `set_vertex_bytes` is. - pub fn set_vertex_bytes_with_stride( + /// The lowering of [`RenderCommandEncoder::set_vertex_bytes_with_stride`]. + pub(crate) fn set_vertex_bytes_with_stride( &mut self, bytes: &[u8], stride: u64, @@ -74,11 +66,8 @@ impl RenderCommandEncoder { ) } - /// `setVertexBuffers:offsets:attributeStrides:withRange:`: `buffers[i]` at offset - /// `offsets[i]` and stride `strides[i]` at index `first + i`, each as - /// [`set_vertex_buffer_with_stride`](Self::set_vertex_buffer_with_stride). Refused as that - /// is, and when the slices' lengths differ; a refusal binds none of them. - pub fn set_vertex_buffers_with_strides( + /// The lowering of [`RenderCommandEncoder::set_vertex_buffers_with_strides`]. + pub(crate) fn set_vertex_buffers_with_strides( &mut self, buffers: &[Option<&Buffer>], offsets: &[u64], @@ -104,11 +93,8 @@ impl RenderCommandEncoder { ) } - /// `setVertexBufferOffset:attributeStride:atIndex:`: as - /// [`set_vertex_buffer_offset`](Self::set_vertex_buffer_offset), with the index's stride set - /// as [`set_vertex_buffer_with_stride`](Self::set_vertex_buffer_with_stride) sets it. - /// Refused as both are. - pub fn set_vertex_buffer_offset_with_stride( + /// The lowering of [`RenderCommandEncoder::set_vertex_buffer_offset_with_stride`]. + pub(crate) fn set_vertex_buffer_offset_with_stride( &mut self, offset: u64, stride: u64, @@ -124,3 +110,66 @@ impl RenderCommandEncoder { ) } } + +impl RenderCommandEncoder { + /// `setVertexBuffer:offset:attributeStride:atIndex:`: as + /// [`set_vertex_buffer`](Self::set_vertex_buffer), the buffer read at `stride` by a layout of + /// `MTLBufferLayoutStrideDynamic` (the module docs); `MTLAttributeStrideStatic` (`u64::MAX`) + /// sets no stride; any other stride past 32 bits is taken modulo `2^32`, as plain Metal + /// reads it and its validation takes it (an M4). Refused as `set_vertex_buffer` is. + pub fn set_vertex_buffer_with_stride( + &mut self, + buffer: Option<&Buffer>, + offset: u64, + stride: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering + .set_vertex_buffer_with_stride(buffer, offset, stride, index) + } + + /// `setVertexBytes:length:attributeStride:atIndex:`: as + /// [`set_vertex_bytes`](Self::set_vertex_bytes), the bytes read at `stride`, its low 32 bits, + /// by a layout of `MTLBufferLayoutStrideDynamic`. At `MTLAttributeStrideStatic` (`u64::MAX`) + /// a draw whose layout reads them so is refused (`Bind(MissingVertexStride)`): an M4 read + /// element 0 of the bytes and zeros past it there, which the fetch does not emulate. Refused as + /// `set_vertex_bytes` is. + pub fn set_vertex_bytes_with_stride( + &mut self, + bytes: &[u8], + stride: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering + .set_vertex_bytes_with_stride(bytes, stride, index) + } + + /// `setVertexBuffers:offsets:attributeStrides:withRange:`: `buffers[i]` at offset + /// `offsets[i]` and stride `strides[i]` at index `first + i`, each as + /// [`set_vertex_buffer_with_stride`](Self::set_vertex_buffer_with_stride). Refused as that + /// is, and when the slices' lengths differ; a refusal binds none of them. + pub fn set_vertex_buffers_with_strides( + &mut self, + buffers: &[Option<&Buffer>], + offsets: &[u64], + strides: &[u64], + first: u32, + ) -> Result<(), Error> { + self.lowering + .set_vertex_buffers_with_strides(buffers, offsets, strides, first) + } + + /// `setVertexBufferOffset:attributeStride:atIndex:`: as + /// [`set_vertex_buffer_offset`](Self::set_vertex_buffer_offset), with the index's stride set + /// as [`set_vertex_buffer_with_stride`](Self::set_vertex_buffer_with_stride) sets it. + /// Refused as both are. + pub fn set_vertex_buffer_offset_with_stride( + &mut self, + offset: u64, + stride: u64, + index: u32, + ) -> Result<(), Error> { + self.lowering + .set_vertex_buffer_offset_with_stride(offset, stride, index) + } +}