diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index 3c56079e1..df6df198e 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -59e88d1199c8cb7978cb06359ff600b743afe11d5a9cd5dd5c2f7e8e0e08c63f +bde1bb5991c4f8f66303b3030434dd0ca55234992a00f1f7a053844f4809bcc0 diff --git a/crates/metal2vulkan/src/lower/dispatch.rs b/crates/metal2vulkan/src/lower/dispatch.rs index e4c1d0b00..9fb605e53 100644 --- a/crates/metal2vulkan/src/lower/dispatch.rs +++ b/crates/metal2vulkan/src/lower/dispatch.rs @@ -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, /// The subgroup size the pipeline pins ([`DispatchPlan::pinned_subgroup_size`]). pinned_subgroup_size: Option, - /// 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)?; diff --git a/crates/metal2vulkan/src/lower/dispatch/tests.rs b/crates/metal2vulkan/src/lower/dispatch/tests.rs index 50af7fa3f..1c42fd955 100644 --- a/crates/metal2vulkan/src/lower/dispatch/tests.rs +++ b/crates/metal2vulkan/src/lower/dispatch/tests.rs @@ -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 { } /// `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. diff --git a/crates/metal2vulkan/src/lower/mesh/mod.rs b/crates/metal2vulkan/src/lower/mesh/mod.rs index 5975eadd9..b9185e9df 100644 --- a/crates/metal2vulkan/src/lower/mesh/mod.rs +++ b/crates/metal2vulkan/src/lower/mesh/mod.rs @@ -342,21 +342,6 @@ fn missing_caps(p: &DeviceProfile) -> Vec { 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 { e.ep.params.iter().find_map(|b| match b.role { diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index 46149856d..aa1ad5ffb 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -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(); diff --git a/crates/metal2vulkan/src/pipeline/compile/api.rs b/crates/metal2vulkan/src/pipeline/compile/api.rs index ca61cadcc..6808b045a 100644 --- a/crates/metal2vulkan/src/pipeline/compile/api.rs +++ b/crates/metal2vulkan/src/pipeline/compile/api.rs @@ -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)?) } diff --git a/crates/metal2vulkan/src/pipeline/lower_inputs.rs b/crates/metal2vulkan/src/pipeline/lower_inputs.rs index 24c426101..508500938 100644 --- a/crates/metal2vulkan/src/pipeline/lower_inputs.rs +++ b/crates/metal2vulkan/src/pipeline/lower_inputs.rs @@ -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 diff --git a/docs/API.md b/docs/API.md index 834504cb7..86f5c2adc 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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