diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index 7e1ba64c6..7bbf63995 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -1559,7 +1559,12 @@ that touch blocks first. for a kernel that declares no imageblock, as Metal does. A kernel that reaches an imageblock has no state (`Gap::KernelInput`); one that declares an imageblock it never reaches, or whose compile kept no reflection to tell, answers `Gap::ImageblockLength`, as no case measures - Metal's length. + Metal's length. `requiredThreadsPerThreadgroup` (`required_threads_per_threadgroup`) is the + descriptor's size, `[0, 0, 0]` where it set none, as the M3 recordings + `pipeline-facts-compute-plain` and `pipeline-facts-compute-described` answer, and + `supportIndirectCommandBuffers` (`support_indirect_command_buffers`) is false: a descriptor + that asks for indirect command buffers is refused at the making + (`Gap::IndirectCommandBuffers`). ### The cache directory @@ -1791,7 +1796,10 @@ or does not check is rebuilt from the generations' names, with young counted ful suite's recordings `pipeline-facts-render-plain`, `pipeline-facts-render-two-attachments` and `pipeline-facts-render-multisampled` (an Apple M3 Max, macOS 27.0.1 build 26A434, three runs each): `RGBA8Unorm` answers 4 and 128 at `[8, 4, 3]`; `RGBA8Unorm` then `RGBA16Float` 12 and - 384; the same at four samples 12 and 1536. + 384; the same at four samples 12 and 1536. `support_indirect_command_buffers` is false, as a + compute state's is: a descriptor that asks for indirect command buffers is refused at the + making. The runtime makes no tile render state, so it has no tile getters + (`threadgroupSizeMatchesTileSize`, `requiredThreadsPerTileThreadgroup`). - A state numbers its functions' samplers as a compute state numbers its kernel's: `sampler_ids` takes the vertex function's, then the fragment function's, each in Metal's order, and answers the index the consumer gives each. Each constexpr sampler a function samples diff --git a/crates/metal2vulkan-rt/src/pipeline.rs b/crates/metal2vulkan-rt/src/pipeline.rs index d90f74047..630f1d5db 100644 --- a/crates/metal2vulkan-rt/src/pipeline.rs +++ b/crates/metal2vulkan-rt/src/pipeline.rs @@ -137,6 +137,8 @@ struct Answers { /// Whether the kernel declares an imageblock, as the compile's kept reflection answers it; /// `None` where the compile kept none. imageblock: Option, + /// `requiredThreadsPerThreadgroup`: the descriptor's, zeros where it set none. + required_threads_per_threadgroup: [u32; 3], } impl Answers { @@ -146,6 +148,7 @@ impl Answers { static_threadgroup_memory_length: pipeline.metal_info.static_threadgroup_memory_length, thread_execution_width: pipeline.metal_info.thread_execution_width, imageblock, + required_threads_per_threadgroup: [0; 3], } } } @@ -856,6 +859,10 @@ impl Compiled { (None, false) => Form::Tiled, (None, true) => Form::Square, }; + let answers = Answers { + required_threads_per_threadgroup: required.unwrap_or([0; 3]), + ..answers + }; let compiled = Compiled::new(core, (whole, rows), form, emulated, (notes, answers)); // A tiling kernel's grids one deep run on one `VkPipeline`, made with the state: its // tiles', or an image-only kernel's square workgroups'; and so do an observing kernel's @@ -1369,6 +1376,20 @@ impl ComputePipelineState { } } + /// `requiredThreadsPerThreadgroup`: the descriptor's size, `[0, 0, 0]` where it set none, as + /// Metal answers (the conformance recordings `pipeline-facts-compute-plain` and + /// `pipeline-facts-compute-described`, an Apple M3 Max under macOS 27.0.1). + pub fn required_threads_per_threadgroup(&self) -> [u32; 3] { + self.inner.compiled.answers.required_threads_per_threadgroup + } + + /// `supportIndirectCommandBuffers`: false on every state the runtime makes, as a descriptor + /// that asks for indirect command buffers is refused at the making + /// ([`Gap::IndirectCommandBuffers`]). + pub fn support_indirect_command_buffers(&self) -> bool { + false + } + /// No Metal counterpart as such: each texture slot the kernel uses, by index, ascending, with /// the access a dispatch of the state marks in its encoder's hazards for the texture bound /// there, read from the same interface: `ReadOnly` where the kernel samples, reads or only diff --git a/crates/metal2vulkan-rt/src/render.rs b/crates/metal2vulkan-rt/src/render.rs index e722e980a..d6cd99d31 100644 --- a/crates/metal2vulkan-rt/src/render.rs +++ b/crates/metal2vulkan-rt/src/render.rs @@ -1001,6 +1001,13 @@ impl RenderPipelineState { .saturating_mul(samples)) } + /// `supportIndirectCommandBuffers`: false on every state the runtime makes, as a descriptor + /// that asks for indirect command buffers is refused at the making + /// ([`Gap::IndirectCommandBuffers`]). + pub fn support_indirect_command_buffers(&self) -> bool { + false + } + /// Whether two handles are one state. pub(crate) fn is(&self, other: &RenderPipelineState) -> bool { Arc::ptr_eq(&self.inner, &other.inner) diff --git a/crates/metal2vulkan-rt/src/tests/state_answers.rs b/crates/metal2vulkan-rt/src/tests/state_answers.rs index 430984040..426d43a22 100644 --- a/crates/metal2vulkan-rt/src/tests/state_answers.rs +++ b/crates/metal2vulkan-rt/src/tests/state_answers.rs @@ -1,9 +1,11 @@ //! What a pipeline state answers of Metal's beside its threads, under a device cfg on every device //! of the cfg's kind. The harness's `block_scan` holds 256 words of static threadgroup memory, //! 1024 bytes as Metal reports them; `sample_down` holds none. Both answer a thread execution -//! width of 32 and, declaring no imageblock, an imageblock memory length of 0. A render state of -//! `R8Unorm` and `R32Float` colors answers Metal's measured sample of 8 bytes (the float at its -//! alignment), and 8 by 8 pixels of one sample 512 bytes. +//! width of 32 and, declaring no imageblock, an imageblock memory length of 0. A compute state +//! answers its descriptor's required threadgroup size, zeros where it set none, as Metal does. A +//! render state of `R8Unorm` and `R32Float` colors answers Metal's measured sample of 8 bytes (the +//! float at its alignment), and 8 by 8 pixels of one sample 512 bytes. No state the runtime makes +//! supports indirect command buffers. //! //! `llvm-as` assembles the functions; without it the test skips visibly. @@ -27,9 +29,13 @@ mod on_device { let function = workloads.function(function).expect("the kernel"); ComputePipelineDescriptor::new(StageSource::Function(FunctionDescriptor::new(function))) }; + // `block_scan` runs 256 threads a threadgroup in the harness. + let mut sized = kernel("block_scan"); + sized.required_threads_per_threadgroup = Some([256, 1, 1]); let kernels = [ - ("block_scan", kernel("block_scan"), 1024), - ("sample_down", kernel("sample_down"), 0), + ("block_scan", kernel("block_scan"), 1024, [0; 3]), + ("sample_down", kernel("sample_down"), 0, [0; 3]), + ("block_scan at 256", sized, 1024, [256, 1, 1]), ]; let Some(examples) = examples() else { return; @@ -37,7 +43,7 @@ mod on_device { let mut drawn = descriptor(&examples, "first_texel_fragment", PixelFormat::R8Unorm); drawn.color_attachments[1] = Some(ColorAttachmentDescriptor::new(PixelFormat::R32Float)); each_device("state_answers", |name, _, device| { - for (function, descriptor, length) in &kernels { + for (function, descriptor, length, required) in &kernels { let compute = (device .new_compute_pipeline_state(descriptor, no_constexpr_samplers)) .unwrap_or_else(|error| panic!("{name}: {function}: {error}")); @@ -47,6 +53,15 @@ mod on_device { "{name}: {function}" ); assert_eq!(compute.thread_execution_width(), 32, "{name}: {function}"); + assert_eq!( + compute.required_threads_per_threadgroup(), + *required, + "{name}: {function}" + ); + assert!( + !compute.support_indirect_command_buffers(), + "{name}: {function}" + ); let imageblock = (compute.imageblock_memory_length_for_dimensions([8, 8, 1])) .unwrap_or_else(|error| panic!("{name}: {function}: {error}")); assert_eq!(imageblock, 0, "{name}: {function}"); @@ -58,6 +73,7 @@ mod on_device { let pixels = (render.imageblock_memory_length_for_dimensions([8, 8, 1])) .unwrap_or_else(|error| panic!("{name}: the render state: {error}")); assert_eq!(pixels, 512, "{name}: 8 by 8 of one sample"); + assert!(!render.support_indirect_command_buffers(), "{name}"); println!("{name}: a state's static threadgroup memory, width and imageblock answered"); }); } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 5a6bfaee4..89ad19d2f 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -9601,7 +9601,9 @@ method metal2vulkan-rt::ComputePipelineDescriptor::uses_direct_arguments pub fn method metal2vulkan-rt::ComputePipelineState::imageblock_memory_length_for_dimensions pub fn imageblock_memory_length_for_dimensions(&self, _dimensions: [u32; 3]) -> Result method metal2vulkan-rt::ComputePipelineState::max_total_threads_per_threadgroup pub fn max_total_threads_per_threadgroup(&self) -> u32 method metal2vulkan-rt::ComputePipelineState::precision_notes pub fn precision_notes(&self) -> Vec +method metal2vulkan-rt::ComputePipelineState::required_threads_per_threadgroup pub fn required_threads_per_threadgroup(&self) -> [u32; 3] method metal2vulkan-rt::ComputePipelineState::static_threadgroup_memory_length pub fn static_threadgroup_memory_length(&self) -> u32 +method metal2vulkan-rt::ComputePipelineState::support_indirect_command_buffers pub fn support_indirect_command_buffers(&self) -> bool method metal2vulkan-rt::ComputePipelineState::texture_accesses pub fn texture_accesses(&self) -> Vec<(u32, BindingAccess)> method metal2vulkan-rt::ComputePipelineState::thread_execution_width pub fn thread_execution_width(&self) -> u32 method metal2vulkan-rt::Counters::gauges pub fn gauges(&self) -> Gauges @@ -9732,6 +9734,7 @@ method metal2vulkan-rt::RenderPipelineDescriptor::vertex_returns_value pub fn ve method metal2vulkan-rt::RenderPipelineState::imageblock_memory_length_for_dimensions pub fn imageblock_memory_length_for_dimensions(&self, dimensions: [u32; 3]) -> Result method metal2vulkan-rt::RenderPipelineState::imageblock_sample_length pub fn imageblock_sample_length(&self) -> Result method metal2vulkan-rt::RenderPipelineState::precision_notes pub fn precision_notes(&self) -> Vec +method metal2vulkan-rt::RenderPipelineState::support_indirect_command_buffers pub fn support_indirect_command_buffers(&self) -> bool method metal2vulkan-rt::RenderPipelineState::texture_accesses pub fn texture_accesses(&self, stage: Stage) -> Vec<(u32, BindingAccess)> method metal2vulkan-rt::ResourceId::to_bits pub fn to_bits(self) -> u64 method metal2vulkan-rt::SamplerDescriptor::new pub fn new() -> SamplerDescriptor