Translator: an object function has one grid form, folded; the unfolded object grid is deleted
What: given_inputs compiles every object function folded (LoweringInputs::folded_groups), alone or in a mesh render pipeline, so its draws run any object grid in pieces within the task stage's limits (bind::mesh_arguments). The unfolded form is deleted: DispatchPlan::object_grid and the decl's object_grid (an unfolded object function's threadgroups per grid, wrapped at 2^32), lower::mesh::folds_object_grids with lower::mesh::mesh_stages, which only it called, and compile_mesh_pipeline's choice between the two. The single-region builtins test keeps its kernel cases and drops the object grid's. Why: condition 1 of the planner's ruling on the mesh build: one grid form, no device-chosen second one. folds_object_grids chose the folded form on a device that runs mesh stages and has device addresses, 64-bit integers, multiDrawIndirect and drawIndirectCount. Device::from_queries refuses a device without the first two, and object and mesh functions now need the last two with the extension, so every device that compiles an object function took the folded form and the unfolded one was reached only by an object function compiled alone. No SEMANTICS_VERSION bump: an object function's key holds folded_groups, so its key changes with its module, and every profile refuses object functions under the identity domains today. docs/API.md's mesh pipelines section and LoweringInputs::folded_groups say an object function is always folded. Verified: see the job named below.
This commit is contained in:
1 parent
7948443887
commit
3e2e65ee1a
8 files changed
+16
-53
No files matched your search
@@ -1 +1 @@
|
||||
59e88d1199c8cb7978cb06359ff600b743afe11d5a9cd5dd5c2f7e8e0e08c63f
|
||||
bde1bb5991c4f8f66303b3030434dd0ca55234992a00f1f7a053844f4809bcc0
|
||||
@@ -76,10 +76,7 @@
|
||||
//! `thread_position_in_grid = (base + WorkgroupId) · L + position in threadgroup` (an edge axis
|
||||
//! has one group), and `threadgroups_per_grid = ⌈threads_per_grid / L⌉`. Both forms are
|
||||
//! evaluated and selected by the specialization constant; the packing never yields a zero divisor,
|
||||
//! so the unselected form is always defined. An unfolded object function's single-region
|
||||
//! `threadgroups_per_grid` is `⌈threads_per_grid / L⌉` too, of `NumWorkgroups · L` wrapped at 2^32
|
||||
//! as Metal's object grid is (measured: an indirect draw runs every threadgroup and reports the
|
||||
//! grid its wrapped threads fill); it is `NumWorkgroups` wherever no axis wraps.
|
||||
//! so the unselected form is always defined.
|
||||
//!
|
||||
//! Every dispatch states its region, and the region's grid selects the grid builtins' form: a
|
||||
//! dispatch the host knows (`dispatchThreads`, `dispatchThreadgroups`, and each piece of a split of
|
||||
@@ -497,12 +494,6 @@ pub struct DispatchPlan {
|
||||
/// threadgroups, so its threadgroup's number adds `DrawIndex · nx · ny · nz`
|
||||
/// ([`KernelDecl::folded`]).
|
||||
pub draw_pieces: bool,
|
||||
/// An unfolded object function: its single-region `threadgroups_per_grid` is Metal's object
|
||||
/// grid's, the threadgroups its threads per grid fill once each axis wraps at 2^32
|
||||
/// (`bind::metal_object_grid`, measured): `⌈(NumWorkgroups · L mod 2^32) / L⌉`, which is
|
||||
/// `NumWorkgroups` unless an axis's threads wrap, as an indirect draw's may (Metal runs every
|
||||
/// threadgroup of it and reports the wrapped grid).
|
||||
pub object_grid: bool,
|
||||
/// An object function, or a kernel under `LoweringInputs::partial_threadgroups`
|
||||
/// (`lower::mesh::plan_partial_groups`): where its region says so ([`NONUNIFORM`]), its
|
||||
/// threadgroup runs only the threads Metal's partial threadgroup has (the module docs). It
|
||||
@@ -703,7 +694,6 @@ pub fn plan_kernel(cx: &mut SelectCx<'_>, tier: Tier) -> Result<DispatchPlan, Er
|
||||
keys: SpecKey::dispatch_keys(cx.stage),
|
||||
folded_groups,
|
||||
draw_pieces: folded_groups && cx.stage == crate::pipeline::sym::Stage::Object,
|
||||
object_grid: !folded_groups && cx.stage == crate::pipeline::sym::Stage::Object,
|
||||
partial_groups,
|
||||
grid_edge,
|
||||
pinned_subgroup_size,
|
||||
@@ -971,8 +961,6 @@ pub struct KernelDecl {
|
||||
subgroup_local: Option<GlobalId>,
|
||||
/// The subgroup size the pipeline pins ([`DispatchPlan::pinned_subgroup_size`]).
|
||||
pinned_subgroup_size: Option<u32>,
|
||||
/// An unfolded object function's grid ([`DispatchPlan::object_grid`]).
|
||||
object_grid: bool,
|
||||
/// A function whose threadgroup may be partial ([`DispatchPlan::partial_groups`]).
|
||||
partial_groups: bool,
|
||||
/// Its threadgroups run whole, its invocations past the grid return
|
||||
@@ -1334,7 +1322,6 @@ impl KernelDecl {
|
||||
)?,
|
||||
subgroup_local: var(subgroups, B::SubgroupLocalInvocationId, u32_)?,
|
||||
pinned_subgroup_size: dp.pinned_subgroup_size,
|
||||
object_grid: dp.object_grid,
|
||||
partial_groups: dp.partial_groups,
|
||||
grid_edge: dp.grid_edge,
|
||||
})
|
||||
@@ -2101,7 +2088,7 @@ impl KernelDecl {
|
||||
/// bits. A kernel's counts are `threads_per_grid / (sx, sy, sz)` (`region[1].xyz`); a folded
|
||||
/// object function's are the record's base words (`region[0].xyz`, which no folded variant
|
||||
/// reads as a base), since its threads per grid are Metal's, wrapped to 32 bits
|
||||
/// (`bind::metal_object_grid`). Every value it reads is the workgroup's, so the whole workgroup
|
||||
/// (`bind::mesh_arguments`). Every value it reads is the workgroup's, so the whole workgroup
|
||||
/// is inside or past. Inside the grid each axis's position is below its
|
||||
/// count, so it fits its `u32`; past it the position is unused. A count of zero runs no
|
||||
/// workgroup (the preprocess writes a zero dispatch), so no running invocation divides by it.
|
||||
@@ -2309,13 +2296,7 @@ impl KernelDecl {
|
||||
}
|
||||
}
|
||||
K::ThreadgroupsPerGrid => {
|
||||
let mut groups = self.load(fb, self.num_workgroups)?;
|
||||
// An object function's grid: the threadgroups its wrapped threads fill.
|
||||
if self.object_grid {
|
||||
let s = self.size3(fb)?;
|
||||
let threads = fb.binary(BinOp::IMul, groups, s)?;
|
||||
groups = self.ceil_div(fb, threads, s)?;
|
||||
}
|
||||
let groups = self.load(fb, self.num_workgroups)?;
|
||||
match self.region_threads(fb, region)? {
|
||||
Some((mr, t)) => {
|
||||
let (_, l) = self.region(fb, region)?;
|
||||
|
||||
@@ -34,7 +34,6 @@ fn plan(form: LocalSizeForm, multi_region: bool) -> DispatchPlan {
|
||||
keys: SpecKey::dispatch_keys(Stage::Kernel),
|
||||
folded_groups: false,
|
||||
draw_pieces: false,
|
||||
object_grid: false,
|
||||
partial_groups: false,
|
||||
grid_edge: false,
|
||||
pinned_subgroup_size: None,
|
||||
@@ -365,14 +364,12 @@ fn thread_regions(threads: [u32; 3], l: [u32; 3]) -> Vec<Region> {
|
||||
}
|
||||
|
||||
/// `MultiRegion = 0`: a `Threadgroups` dispatch reads `NumWorkgroups` and no push field, in both
|
||||
/// local-size forms and both modelled subgroup widths; so does an object function's grid
|
||||
/// (`DispatchPlan::object_grid`), whose threads per grid here wrap on no axis.
|
||||
/// local-size forms and both modelled subgroup widths.
|
||||
#[test]
|
||||
fn single_region_builtins_match_metal() {
|
||||
for form in [LocalSizeForm::Spec, LocalSizeForm::Flat] {
|
||||
for (mr, object) in [(false, false), (true, false), (false, true), (true, true)] {
|
||||
let mut dp = plan(form, mr);
|
||||
dp.object_grid = object;
|
||||
for mr in [false, true] {
|
||||
let dp = plan(form, mr);
|
||||
let m = module(&dp);
|
||||
for sg in [SubgroupSize::W32, SubgroupSize::W64] {
|
||||
// Flattened tiers need N % S = 0 (LocalSizeConstraint); 64 fits both widths.
|
||||
|
||||
@@ -342,21 +342,6 @@ fn missing_caps(p: &DeviceProfile) -> Vec<Capability> {
|
||||
missing
|
||||
}
|
||||
|
||||
/// Whether profile `p` runs object and mesh functions: it enables `VK_EXT_mesh_shader` and every
|
||||
/// one of [`FEATURES`].
|
||||
pub fn mesh_stages(p: &DeviceProfile) -> bool {
|
||||
missing_caps(p).is_empty()
|
||||
}
|
||||
|
||||
/// Whether profile `p` compiles an object function folded (`LoweringInputs::folded_groups`), so
|
||||
/// that its draws run any object grid Metal runs in pieces within the task stage's limits
|
||||
/// (`bind::mesh_arguments`): it runs mesh functions ([`mesh_stages`], whose `multiDrawIndirect`
|
||||
/// takes a direct draw's pieces, with `maxDrawIndirectCount` at least 65,535, and whose
|
||||
/// `drawIndirectCount` an indirect draw's).
|
||||
pub fn folds_object_grids(p: &DeviceProfile) -> bool {
|
||||
mesh_stages(p)
|
||||
}
|
||||
|
||||
/// The bytes of the entry's payload (`air.payload`'s `air.arg_type_size`), if it has one.
|
||||
pub fn payload_size(e: &Entry) -> Option<u64> {
|
||||
e.ep.params.iter().find_map(|b| match b.role {
|
||||
|
||||
@@ -2502,9 +2502,12 @@ fn instanced_attributes(
|
||||
/// The caller's inputs `i` for the specialized entry `spec`, its object payload kept only where it
|
||||
/// widens an object or mesh function's payload arena (`LoweringInputs::object_payload`): any other
|
||||
/// function, and one whose own arena holds it, compiles as without it. OpenCL mode is kept for a
|
||||
/// kernel alone (`LoweringInputs::open_cl_mode`).
|
||||
/// kernel alone (`LoweringInputs::open_cl_mode`). An object function is always folded
|
||||
/// (`LoweringInputs::folded_groups`): its draws run any object grid Metal runs in pieces within the
|
||||
/// task stage's limits (`bind::mesh_arguments`), its one grid form.
|
||||
fn given_inputs(spec: &air::Entry, i: &LowerInputs) -> LowerInputs {
|
||||
let mut out = i.clone();
|
||||
out.folded_groups = i.folded_groups || matches!(spec.ep.stage, AbiStage::Object { .. });
|
||||
out.open_cl_mode = i.open_cl_mode && matches!(spec.ep.stage, AbiStage::Kernel { .. });
|
||||
if !out.open_cl_mode {
|
||||
out.open_cl_lines = BTreeSet::new();
|
||||
|
||||
@@ -508,10 +508,7 @@ impl Device {
|
||||
let payload_length = d.payload_memory_length.filter(|&bytes| bytes > 0);
|
||||
let object = match &d.object {
|
||||
Some(o) => {
|
||||
// An object function on a device that folds its grids runs any object grid in
|
||||
// pieces within the task stage's limits (`bind::mesh_arguments`).
|
||||
let mut inputs = v.lowering_inputs(Stage::Object);
|
||||
inputs.folded_groups = crate::lower::mesh::folds_object_grids(p);
|
||||
inputs.object_payload = payload_length;
|
||||
Some(self.stage(o, InputsFrom::Given(&inputs), m)?)
|
||||
}
|
||||
|
||||
@@ -363,8 +363,9 @@ pub struct LoweringInputs {
|
||||
/// Metal's last threadgroup returns before the body, as a whole. So a kernel that observes its
|
||||
/// threadgroup partition runs any group counts on one variant of the call's threadgroup size.
|
||||
/// It needs device addresses, and refuses a stage-input region, a tile function, `flat_grid`
|
||||
/// and `replay_bindings` (`Unsupported{GpuEncodedIndirectCommands, NotImplemented}`). Any other
|
||||
/// function compiles as without it.
|
||||
/// and `replay_bindings` (`Unsupported{GpuEncodedIndirectCommands, NotImplemented}`). An object
|
||||
/// function is folded whatever this says: its draws run its grid in pieces
|
||||
/// (`bind::mesh_arguments`), its one grid form. Any other function compiles as without it.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub folded_groups: bool,
|
||||
/// The kernel runs a `dispatchThreads` grid that is not a whole number of threadgroups in the
|
||||
|
||||
+2
-3
@@ -1194,9 +1194,8 @@ A grid Metal draws nothing for (an axis past 65,535 threadgroups, or more than 1
|
||||
measured on the M3 Max) draws nothing: an object function's wrapper launches nothing for such a
|
||||
grid.
|
||||
|
||||
An object grid runs at any count Metal runs, past the task stage's limits too, on a device with
|
||||
`multiDrawIndirect` and `drawIndirectCount` (every committed profile with the extension): the
|
||||
object function is compiled folded, its object stage reading the
|
||||
An object grid runs at any count Metal runs, past the task stage's limits too: an object function
|
||||
is always compiled folded, its one grid form, its object stage reading the
|
||||
threadgroups Metal runs and its grid from a 32-byte region record at its
|
||||
`PushField::ReplayRegionAddress`, so a draw runs its grid in pieces within the task limits. Metal's
|
||||
threads per grid wrap to 32 bits along each axis, as its builtins report them. The lowering takes
|
||||
|
||||
Reference in new issue
Block a user