Read a mesh descriptor's limit fields in the mesh-descriptor cases
What: MeshDescriptorFacts gains the descriptor's limit fields (both thread maxima, both execution-width hints, the payload length, the mesh-grid maximum, the vertex amplification count and both required sizes), read on both sides, and the set shape states each away from its default. Why: the runtime holds Metal's defaults for them as literals, and no case read one back from Metal. Verified: the three mesh-descriptor cases are re-recorded on the M3 Max and replayed in later commits. (cherry picked from commit 284272cc86572aa5ff7e4651af370f510a80d2d6)
This commit is contained in:
1 parent
c0b9e3425a
commit
4b02ba4515
3 files changed
+209
-7
No files matched your search
@@ -28,8 +28,9 @@
|
||||
//! state is not a comparison, so no site here reads one. They are the runtime's gap, not this
|
||||
//! family's. The object and mesh thread limits, the two execution-width hints, the payload length,
|
||||
//! the mesh-grid limit, the vertex amplification count and the two required threadgroup sizes are
|
||||
//! fields of `MeshPipelineDescriptor` with Metal's defaults, and no site here reads them yet: this
|
||||
//! family's recordings hold no answer of theirs.
|
||||
//! read as [`DescriptorLimits`]: a field of `MeshPipelineDescriptor` the runtime holds as `None`
|
||||
//! is Metal's 0 or zero size. What a pipeline made under them answers is
|
||||
//! [`crate::pipeline_limits`]'s question.
|
||||
//!
|
||||
//! Four getters answer **objects a program supplies**, and the runtime takes each one somewhere
|
||||
//! other than the descriptor: `binaryArchives` is `PipelineOptions.binary_archives`, and
|
||||
@@ -75,6 +76,97 @@ pub struct Away {
|
||||
pub depth_format: metal::PixelFormat,
|
||||
pub stencil_format: metal::PixelFormat,
|
||||
pub support_indirect_command_buffers: bool,
|
||||
pub limits: DescriptorLimits,
|
||||
}
|
||||
|
||||
/// A mesh descriptor's limit fields, each as Metal's getter answers it: 0, a zero size or false
|
||||
/// for Metal's default, and the amplification count's default 1.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct DescriptorLimits {
|
||||
pub max_total_threads_per_object_threadgroup: u32,
|
||||
pub max_total_threads_per_mesh_threadgroup: u32,
|
||||
pub object_threadgroup_size_is_multiple_of_thread_execution_width: bool,
|
||||
pub mesh_threadgroup_size_is_multiple_of_thread_execution_width: bool,
|
||||
pub payload_memory_length: u32,
|
||||
pub max_total_threadgroups_per_mesh_grid: u32,
|
||||
pub max_vertex_amplification_count: u32,
|
||||
pub required_threads_per_object_threadgroup: [u32; 3],
|
||||
pub required_threads_per_mesh_threadgroup: [u32; 3],
|
||||
}
|
||||
|
||||
impl DescriptorLimits {
|
||||
/// The words a case's input fingerprint covers: every field.
|
||||
fn words(&self) -> Vec<u8> {
|
||||
let mut out = Vec::new();
|
||||
for word in [
|
||||
self.max_total_threads_per_object_threadgroup,
|
||||
self.max_total_threads_per_mesh_threadgroup,
|
||||
self.payload_memory_length,
|
||||
self.max_total_threadgroups_per_mesh_grid,
|
||||
self.max_vertex_amplification_count,
|
||||
]
|
||||
.into_iter()
|
||||
.chain(self.required_threads_per_object_threadgroup)
|
||||
.chain(self.required_threads_per_mesh_threadgroup)
|
||||
{
|
||||
out.extend(word.to_le_bytes());
|
||||
}
|
||||
out.push(u8::from(
|
||||
self.object_threadgroup_size_is_multiple_of_thread_execution_width,
|
||||
));
|
||||
out.push(u8::from(
|
||||
self.mesh_threadgroup_size_is_multiple_of_thread_execution_width,
|
||||
));
|
||||
out
|
||||
}
|
||||
|
||||
/// The limits as the sites a case emits under one node.
|
||||
fn node(&self, name: impl Into<NodeName>) -> Node {
|
||||
let value = Observed::value;
|
||||
let uint = |held: u32| value(Value::Uint(u64::from(held)));
|
||||
let axes = |held: [u32; 3]| value(crate::pipeline_facts::size(&held.map(u64::from)));
|
||||
Node::branch(name, Vec::new())
|
||||
.with(Node::leaf(
|
||||
"max_total_threads_per_object_threadgroup",
|
||||
uint(self.max_total_threads_per_object_threadgroup),
|
||||
))
|
||||
.with(Node::leaf(
|
||||
"max_total_threads_per_mesh_threadgroup",
|
||||
uint(self.max_total_threads_per_mesh_threadgroup),
|
||||
))
|
||||
.with(Node::leaf(
|
||||
"object_threadgroup_size_is_multiple_of_thread_execution_width",
|
||||
value(Value::Bool(
|
||||
self.object_threadgroup_size_is_multiple_of_thread_execution_width,
|
||||
)),
|
||||
))
|
||||
.with(Node::leaf(
|
||||
"mesh_threadgroup_size_is_multiple_of_thread_execution_width",
|
||||
value(Value::Bool(
|
||||
self.mesh_threadgroup_size_is_multiple_of_thread_execution_width,
|
||||
)),
|
||||
))
|
||||
.with(Node::leaf(
|
||||
"payload_memory_length",
|
||||
uint(self.payload_memory_length),
|
||||
))
|
||||
.with(Node::leaf(
|
||||
"max_total_threadgroups_per_mesh_grid",
|
||||
uint(self.max_total_threadgroups_per_mesh_grid),
|
||||
))
|
||||
.with(Node::leaf(
|
||||
"max_vertex_amplification_count",
|
||||
uint(self.max_vertex_amplification_count),
|
||||
))
|
||||
.with(Node::leaf(
|
||||
"required_threads_per_object_threadgroup",
|
||||
axes(self.required_threads_per_object_threadgroup),
|
||||
))
|
||||
.with(Node::leaf(
|
||||
"required_threads_per_mesh_threadgroup",
|
||||
axes(self.required_threads_per_mesh_threadgroup),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// The one table of stated values, each away from Metal's default.
|
||||
@@ -130,6 +222,19 @@ pub const AWAY: Away = Away {
|
||||
depth_format: metal::PixelFormat::Depth16Unorm,
|
||||
stencil_format: metal::PixelFormat::Stencil8,
|
||||
support_indirect_command_buffers: true,
|
||||
// No two numbers alike, and each a value Metal's descriptor holds without checking it: no
|
||||
// shape makes a pipeline of it.
|
||||
limits: DescriptorLimits {
|
||||
max_total_threads_per_object_threadgroup: 96,
|
||||
max_total_threads_per_mesh_threadgroup: 48,
|
||||
object_threadgroup_size_is_multiple_of_thread_execution_width: true,
|
||||
mesh_threadgroup_size_is_multiple_of_thread_execution_width: true,
|
||||
payload_memory_length: 80,
|
||||
max_total_threadgroups_per_mesh_grid: 12,
|
||||
max_vertex_amplification_count: 2,
|
||||
required_threads_per_object_threadgroup: [8, 2, 1],
|
||||
required_threads_per_mesh_threadgroup: [4, 3, 1],
|
||||
},
|
||||
};
|
||||
|
||||
impl Away {
|
||||
@@ -167,6 +272,7 @@ impl Away {
|
||||
}
|
||||
out.push(u8::from(color.blending_enabled));
|
||||
}
|
||||
out.extend(self.limits.words());
|
||||
out
|
||||
}
|
||||
}
|
||||
@@ -259,6 +365,8 @@ pub struct MeshDescriptorFacts {
|
||||
pub support_indirect_command_buffers: bool,
|
||||
/// `binaryArchives`' length; a nil list is 0.
|
||||
pub binary_archives: u64,
|
||||
/// The limit fields.
|
||||
pub limits: DescriptorLimits,
|
||||
/// The three per-stage linked-function lists, which [`Shape::Reset`] does not read.
|
||||
pub supplied: Option<SuppliedLists>,
|
||||
}
|
||||
@@ -324,7 +432,8 @@ impl MeshDescriptorFacts {
|
||||
.with(Node::leaf(
|
||||
"binary_archives",
|
||||
value(Value::Uint(self.binary_archives)),
|
||||
));
|
||||
))
|
||||
.with(self.limits.node("limits"));
|
||||
if let Some(supplied) = &self.supplied {
|
||||
node = node
|
||||
.with(Node::leaf(
|
||||
|
||||
@@ -44,8 +44,8 @@ use crate::indirect_commands::{
|
||||
};
|
||||
use crate::library_facts::{FunctionDescriptorSpec, LibraryFacts};
|
||||
use crate::mesh_descriptors::{
|
||||
DescriptorSpec as MeshDescriptorSpec, MeshDescriptorFacts, SuppliedLists as MeshSuppliedLists,
|
||||
AWAY as MESH_AWAY,
|
||||
DescriptorLimits as MeshDescriptorLimits, DescriptorSpec as MeshDescriptorSpec,
|
||||
MeshDescriptorFacts, SuppliedLists as MeshSuppliedLists, AWAY as MESH_AWAY,
|
||||
};
|
||||
use crate::pass_descriptors::{
|
||||
AttachmentFacts, Indices, Numbers, PassDescriptorFacts, PassSpec, Reads, Row, Shape,
|
||||
@@ -1873,6 +1873,32 @@ fn state_mesh_descriptor(descriptor: &Retained<MTLMeshRenderPipelineDescriptor>)
|
||||
MESH_AWAY.stencil_format.as_raw() as usize
|
||||
));
|
||||
descriptor.setSupportIndirectCommandBuffers(MESH_AWAY.support_indirect_command_buffers);
|
||||
let limits = MESH_AWAY.limits;
|
||||
descriptor.setMaxTotalThreadsPerObjectThreadgroup(
|
||||
limits.max_total_threads_per_object_threadgroup as usize,
|
||||
);
|
||||
descriptor.setMaxTotalThreadsPerMeshThreadgroup(
|
||||
limits.max_total_threads_per_mesh_threadgroup as usize,
|
||||
);
|
||||
descriptor.setObjectThreadgroupSizeIsMultipleOfThreadExecutionWidth(
|
||||
limits.object_threadgroup_size_is_multiple_of_thread_execution_width,
|
||||
);
|
||||
descriptor.setMeshThreadgroupSizeIsMultipleOfThreadExecutionWidth(
|
||||
limits.mesh_threadgroup_size_is_multiple_of_thread_execution_width,
|
||||
);
|
||||
descriptor.setPayloadMemoryLength(limits.payload_memory_length as usize);
|
||||
descriptor
|
||||
.setMaxTotalThreadgroupsPerMeshGrid(limits.max_total_threadgroups_per_mesh_grid as usize);
|
||||
// SAFETY: the count is the stated table's own 2, and nothing of this family compiles the
|
||||
// descriptor.
|
||||
unsafe {
|
||||
descriptor.setMaxVertexAmplificationCount(limits.max_vertex_amplification_count as usize)
|
||||
};
|
||||
descriptor.setRequiredThreadsPerObjectThreadgroup(size(
|
||||
limits.required_threads_per_object_threadgroup,
|
||||
));
|
||||
descriptor
|
||||
.setRequiredThreadsPerMeshThreadgroup(size(limits.required_threads_per_mesh_threadgroup));
|
||||
let colors: Retained<MTLRenderPipelineColorAttachmentDescriptorArray> =
|
||||
descriptor.colorAttachments();
|
||||
for color in MESH_AWAY.colors {
|
||||
@@ -1916,10 +1942,35 @@ fn read_mesh_descriptor(
|
||||
stencil_attachment_pixel_format: descriptor.stencilAttachmentPixelFormat().0 as u32,
|
||||
support_indirect_command_buffers: descriptor.supportIndirectCommandBuffers(),
|
||||
binary_archives: archives.map_or(0, |held| held.len() as u64),
|
||||
limits: read_mesh_limits(descriptor),
|
||||
supplied: supplied.then(|| read_mesh_supplied(descriptor)),
|
||||
}
|
||||
}
|
||||
|
||||
/// A mesh descriptor's limit fields, as its getters answer them.
|
||||
fn read_mesh_limits(
|
||||
descriptor: &Retained<MTLMeshRenderPipelineDescriptor>,
|
||||
) -> MeshDescriptorLimits {
|
||||
let axes = |held: MTLSize| [held.width as u32, held.height as u32, held.depth as u32];
|
||||
MeshDescriptorLimits {
|
||||
max_total_threads_per_object_threadgroup: descriptor.maxTotalThreadsPerObjectThreadgroup()
|
||||
as u32,
|
||||
max_total_threads_per_mesh_threadgroup: descriptor.maxTotalThreadsPerMeshThreadgroup()
|
||||
as u32,
|
||||
object_threadgroup_size_is_multiple_of_thread_execution_width: descriptor
|
||||
.objectThreadgroupSizeIsMultipleOfThreadExecutionWidth(),
|
||||
mesh_threadgroup_size_is_multiple_of_thread_execution_width: descriptor
|
||||
.meshThreadgroupSizeIsMultipleOfThreadExecutionWidth(),
|
||||
payload_memory_length: descriptor.payloadMemoryLength() as u32,
|
||||
max_total_threadgroups_per_mesh_grid: descriptor.maxTotalThreadgroupsPerMeshGrid() as u32,
|
||||
max_vertex_amplification_count: descriptor.maxVertexAmplificationCount() as u32,
|
||||
required_threads_per_object_threadgroup: axes(
|
||||
descriptor.requiredThreadsPerObjectThreadgroup(),
|
||||
),
|
||||
required_threads_per_mesh_threadgroup: axes(descriptor.requiredThreadsPerMeshThreadgroup()),
|
||||
}
|
||||
}
|
||||
|
||||
/// A mesh descriptor's three per-stage linked-function lists, by how many objects each holds.
|
||||
///
|
||||
/// Read only where the shape asks for it: all three accessors are non-null and `reset` leaves each
|
||||
|
||||
@@ -40,8 +40,8 @@ use crate::indirect_commands::{
|
||||
};
|
||||
use crate::library_facts::{FunctionDescriptorSpec, LibraryFacts};
|
||||
use crate::mesh_descriptors::{
|
||||
DescriptorSpec as MeshDescriptorSpec, MeshDescriptorFacts, SuppliedLists as MeshSuppliedLists,
|
||||
AWAY as MESH_AWAY,
|
||||
DescriptorLimits as MeshDescriptorLimits, DescriptorSpec as MeshDescriptorSpec,
|
||||
MeshDescriptorFacts, SuppliedLists as MeshSuppliedLists, AWAY as MESH_AWAY,
|
||||
};
|
||||
use crate::pass_descriptors::{
|
||||
AttachmentFacts, Indices, Numbers, PassDescriptorFacts, PassSpec, Reads, Row, Shape,
|
||||
@@ -531,6 +531,24 @@ fn state_mesh_descriptor(descriptor: &mut MeshPipelineDescriptor, options: &mut
|
||||
descriptor.depth_format = Some(MESH_AWAY.depth_format);
|
||||
descriptor.stencil_format = Some(MESH_AWAY.stencil_format);
|
||||
descriptor.support_indirect_command_buffers = MESH_AWAY.support_indirect_command_buffers;
|
||||
// Metal's 0 and zero size are the runtime's `None`; the table states none of them.
|
||||
let limits = MESH_AWAY.limits;
|
||||
descriptor.max_total_threads_per_object_threadgroup =
|
||||
Some(limits.max_total_threads_per_object_threadgroup);
|
||||
descriptor.max_total_threads_per_mesh_threadgroup =
|
||||
Some(limits.max_total_threads_per_mesh_threadgroup);
|
||||
descriptor.object_threadgroup_size_is_multiple_of_thread_execution_width =
|
||||
limits.object_threadgroup_size_is_multiple_of_thread_execution_width;
|
||||
descriptor.mesh_threadgroup_size_is_multiple_of_thread_execution_width =
|
||||
limits.mesh_threadgroup_size_is_multiple_of_thread_execution_width;
|
||||
descriptor.payload_memory_length = Some(limits.payload_memory_length);
|
||||
descriptor.max_total_threadgroups_per_mesh_grid =
|
||||
Some(limits.max_total_threadgroups_per_mesh_grid);
|
||||
descriptor.max_vertex_amplification_count = limits.max_vertex_amplification_count;
|
||||
descriptor.required_threads_per_object_threadgroup =
|
||||
Some(limits.required_threads_per_object_threadgroup);
|
||||
descriptor.required_threads_per_mesh_threadgroup =
|
||||
Some(limits.required_threads_per_mesh_threadgroup);
|
||||
for color in MESH_AWAY.colors {
|
||||
let mut attachment = ColorAttachmentDescriptor::new(color.pixel_format);
|
||||
attachment.blending_enabled = color.blending_enabled;
|
||||
@@ -600,6 +618,30 @@ fn read_mesh_descriptor(
|
||||
.as_raw(),
|
||||
support_indirect_command_buffers: descriptor.support_indirect_command_buffers,
|
||||
binary_archives: options.binary_archives.len() as u64,
|
||||
// A field the runtime holds as `None` is Metal's 0 or zero size.
|
||||
limits: MeshDescriptorLimits {
|
||||
max_total_threads_per_object_threadgroup: descriptor
|
||||
.max_total_threads_per_object_threadgroup
|
||||
.unwrap_or(0),
|
||||
max_total_threads_per_mesh_threadgroup: descriptor
|
||||
.max_total_threads_per_mesh_threadgroup
|
||||
.unwrap_or(0),
|
||||
object_threadgroup_size_is_multiple_of_thread_execution_width: descriptor
|
||||
.object_threadgroup_size_is_multiple_of_thread_execution_width,
|
||||
mesh_threadgroup_size_is_multiple_of_thread_execution_width: descriptor
|
||||
.mesh_threadgroup_size_is_multiple_of_thread_execution_width,
|
||||
payload_memory_length: descriptor.payload_memory_length.unwrap_or(0),
|
||||
max_total_threadgroups_per_mesh_grid: descriptor
|
||||
.max_total_threadgroups_per_mesh_grid
|
||||
.unwrap_or(0),
|
||||
max_vertex_amplification_count: descriptor.max_vertex_amplification_count,
|
||||
required_threads_per_object_threadgroup: descriptor
|
||||
.required_threads_per_object_threadgroup
|
||||
.unwrap_or([0; 3]),
|
||||
required_threads_per_mesh_threadgroup: descriptor
|
||||
.required_threads_per_mesh_threadgroup
|
||||
.unwrap_or([0; 3]),
|
||||
},
|
||||
supplied: supplied.then_some(MeshSuppliedLists {
|
||||
object_linked_functions: object_linked,
|
||||
mesh_linked_functions: mesh_linked,
|
||||
|
||||
Reference in new issue
Block a user