Validation: the engine candidate runs a kernel case's stage inputs through the runtime
What: a kernel case's stage inputs of a fixed stride, and its dispatch's
stage-in region, now run on the engine candidate as the Metal oracle runs
them (executor_contract::stage_inputs, the derivation both executors
share):
- compute_case takes the checked entry's AIR-layer interface and maps
each input's data to its own buffer at the slot its location takes;
- ComputeCase carries the stage-input descriptor, the region (the
dispatch's, or the grid's from the origin) and each slot's location;
- the run through the runtime makes its state with that descriptor, sets
the region before the dispatch, and guards a stage input's data as its
OutOfBoundsResource::AttributeBuffer target (guards::buffer_resource);
- the authored compile census compiles the kernel under it
(PipelineRequest::Kernel::stage_input, variants::compile_kernel).
ToolingRequirement::KernelStageInput ("kernel_stage_input") becomes
DynamicStageInStride ("dynamic_stage_in_stride"): it now fires only for
an input of a dynamic stride. The runtime refuses that layout (Gap::StageIn
of DynamicStride), since its compute encoder has no
setBuffer:offset:attributeStride:atIndex:. Docs say the same:
docs/VALIDATION.md, the requirement's, case_requirements' and
compute_case's. A neighbouring line now says the implicit imageblock is
the runtime's limit, where it said explicit; the code already said so.
Why: the runtime has fetched stage inputs at every step function since
a916e61185 and sets the region (set_stage_in_region), but the candidate
built its state without the descriptor and set no region. So twelve
authored cases stayed Metal-only, the twelve the authored compile census
holds as not_supported{tooling_requirement:kernel_stage_input}.
Also: AUTHORED_COMPILE_CENSUS_VERSION 9 -> 10. Its table is re-blessed
on development. ENGINE_EXECUTOR_ABI unchanged: every case this lets run
was refused before, which its doc says needs no bump.
Verified here: cargo fmt; signatures --check. Tests:
engine_case_families_follow_the_case_literals (red at the commit
before) and stage_inputs_map_onto_their_slots_descriptor_and_region.
Clippy, rustdoc, the validation suite and the cases' runs on a device go
in the jobs the lane's report names.
This commit is contained in:
1 parent
3015b115dd
commit
98435ae812
15 files changed
+250
-72
No files matched your search
@@ -42,7 +42,7 @@ use metal2vulkan::library::{FunctionConstantValues, Library};
|
||||
use metal2vulkan::pipeline::Stage;
|
||||
use metal2vulkan::pipeline::{
|
||||
ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, LinkedFunction,
|
||||
LinkedFunctions, PrecisionNote, RenderPipeline, StageModule, StageSource,
|
||||
LinkedFunctions, PrecisionNote, RenderPipeline, StageInputDescriptor, StageModule, StageSource,
|
||||
};
|
||||
use metal2vulkan::vk;
|
||||
use metal2vulkan::Budget;
|
||||
@@ -220,12 +220,15 @@ pub enum PipelineRequest {
|
||||
constants: FunctionConstantValues,
|
||||
},
|
||||
/// Kernel `function` as the runtime compiles it for a dispatch of threadgroups of
|
||||
/// `threads_per_threadgroup` (`candidate::engine::variants::compile_kernel`): its plain module,
|
||||
/// or its emulated-simdgroups variant where that threadgroup ends in a partial simdgroup. The
|
||||
/// `threads_per_threadgroup` (`candidate::engine::variants::compile_kernel`), under its
|
||||
/// stage-input descriptor `stage_input` where the case has stage inputs: its plain module, or
|
||||
/// its emulated-simdgroups variant where that threadgroup ends in a partial simdgroup. The
|
||||
/// authored compile census's kernel.
|
||||
Kernel {
|
||||
function: RequestFunction,
|
||||
threads_per_threadgroup: [u32; 3],
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
stage_input: Option<StageInputDescriptor>,
|
||||
},
|
||||
/// The L4 row `entry`, a `stage` function with the function-constant values `constants`
|
||||
/// (none, the default: Metal's undefined, the plain census's compile), built as [`row`]
|
||||
@@ -668,12 +671,14 @@ fn compile_counted(
|
||||
PipelineRequest::Kernel {
|
||||
function: kernel,
|
||||
threads_per_threadgroup,
|
||||
stage_input,
|
||||
} => {
|
||||
let kernel = function(0, Stage::Kernel, kernel, linked(0))?;
|
||||
let pipeline = crate::candidate::engine::variants::compile_kernel(
|
||||
device,
|
||||
&kernel,
|
||||
*threads_per_threadgroup,
|
||||
stage_input.as_ref(),
|
||||
&budget,
|
||||
)?;
|
||||
AcceptancePipeline::Compute(Box::new(pipeline))
|
||||
@@ -1527,6 +1532,7 @@ mod tests {
|
||||
linked,
|
||||
},
|
||||
threads_per_threadgroup: [32, 1, 1],
|
||||
stage_input: None,
|
||||
};
|
||||
let library = |names: &[&str]| LinkedLibrary {
|
||||
functions: names.iter().map(|name| (*name).to_owned()).collect(),
|
||||
@@ -1591,6 +1597,7 @@ mod tests {
|
||||
let kernel = PipelineRequest::Kernel {
|
||||
function: function("k", 2),
|
||||
threads_per_threadgroup: [32, 1, 1],
|
||||
stage_input: None,
|
||||
};
|
||||
assert_eq!(kernel.linked_ranges(), vec![Range { start: 1, end: 3 }]);
|
||||
assert_eq!(kernel.libraries(), 3);
|
||||
|
||||
@@ -95,7 +95,10 @@ mod tests;
|
||||
/// draw or mesh draw with no binding plan's variant.
|
||||
/// 9: a kernel case with an explicit imageblock compiles at the size its run sets
|
||||
/// (`ComputeCommandEncoder::set_imageblock_size`), where it was refused as `KernelImageblock`.
|
||||
pub const AUTHORED_COMPILE_CENSUS_VERSION: u32 = 9;
|
||||
/// 10: a kernel case with stage inputs of a fixed stride compiles under its stage-input descriptor
|
||||
/// (`PipelineRequest::Kernel::stage_input`), where it was refused as `kernel_stage_input`; one
|
||||
/// of a dynamic stride is refused as `dynamic_stage_in_stride`.
|
||||
pub const AUTHORED_COMPILE_CENSUS_VERSION: u32 = 10;
|
||||
|
||||
/// The expectation file's name under the corpus root (`validation/corpus`).
|
||||
pub const EXPECTATIONS: &str = "authored-compile.tsv";
|
||||
|
||||
@@ -44,6 +44,7 @@ use crate::coverage::ExecutedCensus;
|
||||
use crate::cutover::List as _;
|
||||
use crate::engine::{bounded_detail, Outcome, RowSource};
|
||||
use crate::executor_contract::out_of_bounds::{self, OutOfBoundsRun, TargetRun};
|
||||
use crate::executor_contract::stage_inputs;
|
||||
use crate::gpu::wait::wait_timeout;
|
||||
use crate::gpu::DeviceType;
|
||||
use crate::hash::sha256_bytes;
|
||||
@@ -66,13 +67,13 @@ use crate::worker::compile::{
|
||||
use crate::worker::device::{DeviceInput, DeviceOutcome, DeviceRun, OpenedDevice, VenueRun};
|
||||
use crate::worker::WorkerFailure;
|
||||
use base64::Engine as _;
|
||||
use metal2vulkan::bind::{Dispatch, DrawCall};
|
||||
use metal2vulkan::bind::{Dispatch, DrawCall, StageInRegion};
|
||||
use metal2vulkan::cache::Hash256;
|
||||
use metal2vulkan::device::DeviceProfile;
|
||||
use metal2vulkan::error::Error;
|
||||
use metal2vulkan::library::{FunctionConstantValue, FunctionConstantValues};
|
||||
use metal2vulkan::pipeline::Stage as ShaderStage;
|
||||
use metal2vulkan::pipeline::{ComputePipeline, RenderPipeline};
|
||||
use metal2vulkan::pipeline::{ComputePipeline, RenderPipeline, StageInputDescriptor};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::path::Path;
|
||||
@@ -100,8 +101,8 @@ pub const ENGINE_EXECUTOR_ABI: &str = "vulkan-engine-v217";
|
||||
/// One kernel case in the terms the runtime route takes: what this executor supports of an
|
||||
/// [`AuthoredCase`] (buffers, device buffer arrays, argument-buffer buffers and textures,
|
||||
/// textures, texture arrays, samplers, threadgroup lengths, function
|
||||
/// constants, a `dispatchThreads` grid, and a buffer, argument-buffer buffer, texture or
|
||||
/// argument-buffer texture output).
|
||||
/// constants, stage inputs of a fixed stride and their stage-in region, a `dispatchThreads` grid,
|
||||
/// and a buffer, argument-buffer buffer, texture or argument-buffer texture output).
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ComputeCase {
|
||||
pub entry: String,
|
||||
@@ -110,8 +111,19 @@ pub struct ComputeCase {
|
||||
/// array at `binding` is the buffer bound at `binding + i`, as the Metal oracle binds it
|
||||
/// (`executor_contract::device_buffer_array_completeness_error`) and as the product reads a
|
||||
/// buffer table. An argument buffer's owner covers each of its embedded pointer fields
|
||||
/// ([`ComputeCase::argument_buffer_buffers`]).
|
||||
/// ([`ComputeCase::argument_buffer_buffers`]). A stage input's data is the buffer at its slot
|
||||
/// ([`ComputeCase::stage_input_locations`]).
|
||||
pub buffers: BTreeMap<u32, Vec<u8>>,
|
||||
/// The kernel's stage-input descriptor, as both executors fetch the case's `[[stage_in]]`
|
||||
/// data (`executor_contract::stage_inputs`); `None` for a case without stage inputs.
|
||||
pub stage_input: Option<StageInputDescriptor>,
|
||||
/// The stage-in region the dispatch sets (`setStageInRegion:`) for a case with stage
|
||||
/// inputs: its dispatch's, or the grid's from the origin (`stage_inputs::region`).
|
||||
pub stage_in_region: Option<StageInRegion>,
|
||||
/// The location of the stage input whose data each of [`ComputeCase::buffers`] holds, by
|
||||
/// Metal buffer index: an out-of-bounds target of that data is its
|
||||
/// `OutOfBoundsResource::AttributeBuffer`.
|
||||
pub stage_input_locations: BTreeMap<u32, u32>,
|
||||
/// Initial bytes of each argument-buffer buffer, by `(owner Metal index, field offset)`:
|
||||
/// a buffer the owner's argument buffer points to (loaded pointers). The run writes its guest
|
||||
/// address into the owner's bytes at the field offset, the pointer Metal's argument encoder
|
||||
@@ -235,16 +247,22 @@ impl RunAttempt {
|
||||
/// Map `case` onto what this executor runs, or name what it does not implement yet. The families of
|
||||
/// the shared vocabulary that stop this executor for a kernel case
|
||||
/// (`executor_contract::case_requirements`: among them acceleration structures and
|
||||
/// intersection-function tables, imageblocks, stage inputs, rate maps, sparse textures and texture
|
||||
/// buffers, the runtime's limits, and every indirect command buffer and pipeline state an argument
|
||||
/// buffer holds) are `NotSupported::Requirements`; it runs buffers, device buffer arrays,
|
||||
/// argument-buffer buffers and textures, textures, texture arrays, samplers and threadgroup
|
||||
/// lengths, and visible-function tables (the run makes them, [`RuntimeKernel::tables`]), and a
|
||||
/// case whose literals do not map onto them is
|
||||
/// intersection-function tables, imageblocks, stage inputs of a dynamic stride, rate maps, sparse
|
||||
/// textures and texture buffers, the runtime's limits, and every indirect command buffer and
|
||||
/// pipeline state an argument buffer holds) are `NotSupported::Requirements`; it runs buffers,
|
||||
/// device buffer arrays, argument-buffer buffers and textures, textures, texture arrays, samplers
|
||||
/// and threadgroup lengths, visible-function tables (the run makes them,
|
||||
/// [`RuntimeKernel::tables`]), and stage inputs of a fixed stride, each its own buffer at the slot
|
||||
/// `interface`, the checked entry's AIR-layer interface, gives it, under the descriptor and region
|
||||
/// the Metal oracle sets (`executor_contract::stage_inputs`); a case whose literals do not map
|
||||
/// onto them is
|
||||
/// `NotSupported::NotImplemented` (graphics stages are `candidate::engine::graphics`). A case has no
|
||||
/// indirect dispatch to map: its dispatch is a `dispatchThreads` grid, and indirect work is
|
||||
/// authored only as indirect command buffers.
|
||||
pub fn compute_case(case: &AuthoredCase) -> Result<ComputeCase, NotSupported> {
|
||||
pub fn compute_case(
|
||||
case: &AuthoredCase,
|
||||
interface: &AirInterface,
|
||||
) -> Result<ComputeCase, NotSupported> {
|
||||
let gap = |what: &str| NotSupported::NotImplemented(format!("engine candidate: {what}"));
|
||||
if case.stage != Stage::Kernel {
|
||||
return Err(gap(&format!(
|
||||
@@ -362,6 +380,30 @@ pub fn compute_case(case: &AuthoredCase) -> Result<ComputeCase, NotSupported> {
|
||||
return Err(gap(&format!("buffer {binding} bound twice")));
|
||||
}
|
||||
}
|
||||
let fetches = match case.kernel_stage_inputs.is_empty() {
|
||||
true => Vec::new(),
|
||||
false => stage_inputs::authored(&case.kernel_stage_inputs, interface)
|
||||
.map_err(|error| gap(&format!("stage inputs: {error}")))?,
|
||||
};
|
||||
let mut stage_input_locations = BTreeMap::new();
|
||||
for fetch in &fetches {
|
||||
if fetch.dynamic {
|
||||
return Err(gap("a stage input of a dynamic stride"));
|
||||
}
|
||||
let Some(input) =
|
||||
(resources.kernel_stage_inputs.iter()).find(|input| input.location == fetch.location)
|
||||
else {
|
||||
return Err(gap(&format!("stage input {} has no data", fetch.location)));
|
||||
};
|
||||
if buffers.insert(fetch.slot, input.bytes.clone()).is_some() {
|
||||
return Err(gap(&format!("buffer {} bound twice", fetch.slot)));
|
||||
}
|
||||
stage_input_locations.insert(fetch.slot, fetch.location);
|
||||
}
|
||||
let stage_input = stage_inputs::descriptor(&fetches);
|
||||
let stage_in_region = stage_input
|
||||
.is_some()
|
||||
.then(|| stage_inputs::region(dispatch.stage_in_region, dispatch.grid));
|
||||
let argument_buffer_buffers =
|
||||
argument_buffers::embed(&mut buffers, &resources.argument_buffer_buffers)
|
||||
.map_err(|error| gap(&error))?;
|
||||
@@ -387,6 +429,9 @@ pub fn compute_case(case: &AuthoredCase) -> Result<ComputeCase, NotSupported> {
|
||||
entry: case.entry.clone(),
|
||||
constants,
|
||||
buffers,
|
||||
stage_input,
|
||||
stage_in_region,
|
||||
stage_input_locations,
|
||||
argument_buffer_buffers,
|
||||
argument_buffer_textures,
|
||||
argument_buffer_samplers,
|
||||
@@ -418,9 +463,9 @@ pub fn compute_case(case: &AuthoredCase) -> Result<ComputeCase, NotSupported> {
|
||||
/// Refuse the families of `case`'s own literals that stop this executor
|
||||
/// (`executor_contract::case_requirements`): argument-buffer intersection-function tables, linked
|
||||
/// intersection functions, the runtime's limits (a render stage's function tables, acceleration
|
||||
/// structures and intersection-function tables, imageblocks, stage inputs, rate maps, sparse
|
||||
/// textures, texture
|
||||
/// buffers and dynamic vertex strides among them), and the render executor's own (device buffer
|
||||
/// structures and intersection-function tables, implicit imageblocks, stage inputs of a dynamic
|
||||
/// stride, rate maps, sparse textures, texture buffers and dynamic vertex strides among them), and
|
||||
/// the render executor's own (device buffer
|
||||
/// arrays, a vertex case's depth/stencil attachment, a rasterization-disabled vertex case's render
|
||||
/// targets; it draws a tessellation case's patches). The checker computed them with the source's
|
||||
/// families ([`crate::check::CheckedShader::requirements`]), which [`prepare_case`] refuses; this
|
||||
@@ -994,9 +1039,10 @@ fn linking(
|
||||
}
|
||||
|
||||
/// The compile request for `case`'s kernel from `library` as the runtime compiles it for the
|
||||
/// case's dispatch (`PipelineRequest::Kernel`, its threadgroup size), linking the functions of
|
||||
/// `linked`, and its libraries in [`PipelineRequest::libraries`] order (`library`, then each of
|
||||
/// `linked`'s): the authored compile census's.
|
||||
/// case's dispatch (`PipelineRequest::Kernel`, its threadgroup size, under the case's
|
||||
/// stage-input descriptor), linking the functions of `linked`, and its libraries in
|
||||
/// [`PipelineRequest::libraries`] order (`library`, then each of `linked`'s): the authored compile
|
||||
/// census's.
|
||||
pub fn kernel_request<'a>(
|
||||
library: &RowSource<'a>,
|
||||
linked: &[LinkedModule],
|
||||
@@ -1005,6 +1051,7 @@ pub fn kernel_request<'a>(
|
||||
let request = PipelineRequest::Kernel {
|
||||
function: linking(&case.entry, &case.constants, linked),
|
||||
threads_per_threadgroup: case.dispatch.threads_per_group(),
|
||||
stage_input: case.stage_input.clone(),
|
||||
};
|
||||
(request, with_linked(&[library], linked))
|
||||
}
|
||||
@@ -1273,7 +1320,7 @@ fn prepare(
|
||||
.map_err(NotSupported::Requirements)?;
|
||||
let case = &checked.primary.case;
|
||||
let mapped = match case.stage {
|
||||
Stage::Kernel => Mapped::Compute(Box::new(compute_case(case)?)),
|
||||
Stage::Kernel => Mapped::Compute(Box::new(compute_case(case, &checked.primary.interface)?)),
|
||||
Stage::Vertex | Stage::Fragment => Mapped::Render(Box::new(graphics::render_case(
|
||||
case,
|
||||
&checked.primary.interface,
|
||||
|
||||
@@ -44,12 +44,18 @@ pub fn declared_reach(
|
||||
}
|
||||
|
||||
/// The guard reach of the buffer at Metal index `index` when `case` declares it an out-of-bounds
|
||||
/// target.
|
||||
/// target ([`buffer_resource`]).
|
||||
pub fn guard_reach(case: &ComputeCase, index: u32) -> Option<GuardReach> {
|
||||
declared_reach(
|
||||
&case.out_of_bounds,
|
||||
OutOfBoundsResource::Buffer { binding: index },
|
||||
)
|
||||
declared_reach(&case.out_of_bounds, buffer_resource(case, index))
|
||||
}
|
||||
|
||||
/// The out-of-bounds resource the buffer at Metal index `index` of `case` is: a stage input's
|
||||
/// data is its attribute buffer (`ComputeCase::stage_input_locations`), every other buffer itself.
|
||||
pub fn buffer_resource(case: &ComputeCase, index: u32) -> OutOfBoundsResource {
|
||||
match case.stage_input_locations.get(&index) {
|
||||
Some(&location) => OutOfBoundsResource::AttributeBuffer { location },
|
||||
None => OutOfBoundsResource::Buffer { binding: index },
|
||||
}
|
||||
}
|
||||
|
||||
/// The guard reach of the texture buffer at Metal index `index` when `targets` declares it a
|
||||
|
||||
@@ -151,7 +151,94 @@ fn a_mismatch_is_held_open_by_the_gap_whose_note_reaches_every_unexcused_word()
|
||||
/// [`compute_case`] of a case whose entry declares no stage input: every case here but the
|
||||
/// stage-input ones, which map against their own interface.
|
||||
fn map_kernel(case: &AuthoredCase) -> Result<ComputeCase, NotSupported> {
|
||||
compute_case(case)
|
||||
compute_case(case, &kernel_interface(vec![]))
|
||||
}
|
||||
|
||||
/// A kernel's AIR-layer interface of `params` alone.
|
||||
fn kernel_interface(params: Vec<crate::check::interface::Param>) -> AirInterface {
|
||||
let stage = metal2vulkan_air::abi::Stage::Kernel {
|
||||
max_total_threads: None,
|
||||
work_group_size: None,
|
||||
};
|
||||
AirInterface::synthetic(stage, params, vec![], vec![])
|
||||
}
|
||||
|
||||
/// A kernel case's stage inputs of a fixed stride run through the runtime as the Metal oracle
|
||||
/// binds them (`executor_contract::stage_inputs`): each input's data is its own buffer at the
|
||||
/// slot its location takes, under the descriptor both executors derive and the dispatch's
|
||||
/// stage-in region (the grid's from the origin where the case sets none), each slot naming its
|
||||
/// input's location for its out-of-bounds guard. A dynamic stride is the runtime's refusal, a
|
||||
/// requirement before the case maps.
|
||||
#[test]
|
||||
fn stage_inputs_map_onto_their_slots_descriptor_and_region() {
|
||||
use crate::case::indirect_commands::HostStageInRegion;
|
||||
use crate::check::interface::tests::param;
|
||||
use metal2vulkan_air::abi::{AbiInt, Access, BufferArg, ParamRole, Slot};
|
||||
let slot = |index| Slot {
|
||||
index: AbiInt::Const(index),
|
||||
count: AbiInt::Const(1),
|
||||
};
|
||||
let buffer = ParamRole::Buffer(BufferArg {
|
||||
location: slot(0),
|
||||
access: Access::ReadWrite,
|
||||
space: metal2vulkan_air::ir::AddrSpace::Device,
|
||||
buffer_size: None,
|
||||
layout: None,
|
||||
raster_order_group: None,
|
||||
});
|
||||
let interface = kernel_interface(vec![
|
||||
param(0, buffer),
|
||||
param(1, ParamRole::StageIn { location: slot(2) }),
|
||||
]);
|
||||
let data = [0x00, 0x00, 0x80, 0x3f];
|
||||
let mut case = kernel_case();
|
||||
case.kernel_stage_inputs = vec![crate::case::AttributeInput {
|
||||
location: 2,
|
||||
format: crate::case::AttributeFormat::Float,
|
||||
stride: 4,
|
||||
dynamic_stride: false,
|
||||
bytes_b64: b64(&data),
|
||||
}];
|
||||
let fetches =
|
||||
stage_inputs::authored(&case.kernel_stage_inputs, &interface).expect("the fetches");
|
||||
let [fetch] = fetches.as_slice() else {
|
||||
panic!("one fetch: {fetches:?}");
|
||||
};
|
||||
let grid = case.dispatch.as_ref().expect("a dispatch").grid;
|
||||
let mapped = compute_case(&case, &interface).expect("a case of stage inputs");
|
||||
assert_eq!(mapped.stage_input, stage_inputs::descriptor(&fetches));
|
||||
assert_eq!(mapped.buffers.get(&fetch.slot), Some(&data.to_vec()));
|
||||
assert_eq!(
|
||||
mapped.stage_input_locations,
|
||||
BTreeMap::from([(fetch.slot, 2)])
|
||||
);
|
||||
assert_eq!(
|
||||
mapped.stage_in_region,
|
||||
Some(StageInRegion::new([0; 3], grid))
|
||||
);
|
||||
let region = HostStageInRegion {
|
||||
origin: [3, 0, 0],
|
||||
size: [5, 1, 1],
|
||||
};
|
||||
if let Some(dispatch) = case.dispatch.as_mut() {
|
||||
dispatch.stage_in_region = Some(region);
|
||||
}
|
||||
let regioned = compute_case(&case, &interface).expect("a case of a region");
|
||||
assert_eq!(
|
||||
regioned.stage_in_region,
|
||||
Some(StageInRegion::new(region.origin, region.size))
|
||||
);
|
||||
case.kernel_stage_inputs[0].dynamic_stride = true;
|
||||
assert_eq!(
|
||||
compute_case(&case, &interface),
|
||||
Err(NotSupported::Requirements(
|
||||
[ToolingRequirement::DynamicStageInStride].into()
|
||||
))
|
||||
);
|
||||
// A case without stage inputs binds no slot for them and sets no region.
|
||||
let plain = map_kernel(&kernel_case()).expect("a plain case");
|
||||
assert_eq!((plain.stage_input, plain.stage_in_region), (None, None));
|
||||
assert!(plain.stage_input_locations.is_empty());
|
||||
}
|
||||
|
||||
fn kernel_case() -> AuthoredCase {
|
||||
@@ -416,6 +503,7 @@ fn the_cases_own_function_links_and_its_libraries_follow_the_stages() {
|
||||
PipelineRequest::Kernel {
|
||||
function: linking(&kernel.entry),
|
||||
threads_per_threadgroup: kernel.dispatch.threads_per_group(),
|
||||
stage_input: None,
|
||||
}
|
||||
);
|
||||
assert_eq!(given, expected_libraries(&[&case]));
|
||||
|
||||
@@ -11,13 +11,14 @@ use metal2vulkan::device::Device;
|
||||
use metal2vulkan::error::Error;
|
||||
use metal2vulkan::pipeline::{
|
||||
ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, KernelVariant, LoweringInputs,
|
||||
RuntimeFact, StageSource,
|
||||
RuntimeFact, StageInputDescriptor, StageSource,
|
||||
};
|
||||
use metal2vulkan::Budget;
|
||||
|
||||
/// Compile `function` into a compute pipeline for `device` under `budget` as the runtime compiles
|
||||
/// it for a dispatch of threadgroups of `threads_per_threadgroup`: its plain module
|
||||
/// (`LoweringInputs::new`), or its emulated-simdgroups variant
|
||||
/// it for a dispatch of threadgroups of `threads_per_threadgroup`, under the stage-input
|
||||
/// descriptor `stage_input` where the kernel has one: its plain module (`LoweringInputs::new`
|
||||
/// with that descriptor), or its emulated-simdgroups variant
|
||||
/// (`KernelVariant::EmulatedSimdgroups`) where the threadgroup's threads are not a multiple of a
|
||||
/// `RuntimeFact::LocalSizeConstraint` the plain module states (a partial simdgroup its
|
||||
/// flattened simd tier cannot run), as the runtime's encoder chooses the module a dispatch runs.
|
||||
@@ -25,6 +26,7 @@ pub fn compile_kernel(
|
||||
device: &Device,
|
||||
function: &FunctionDescriptor,
|
||||
threads_per_threadgroup: [u32; 3],
|
||||
stage_input: Option<&StageInputDescriptor>,
|
||||
budget: &Budget,
|
||||
) -> Result<ComputePipeline, Error> {
|
||||
let compile = |inputs: &LoweringInputs| {
|
||||
@@ -32,7 +34,8 @@ pub fn compile_kernel(
|
||||
let descriptor = ComputePipelineDescriptor::new(StageSource::Compiled(compiled));
|
||||
device.compile_compute_pipeline(&descriptor, budget)
|
||||
};
|
||||
let plain = LoweringInputs::new();
|
||||
let mut plain = LoweringInputs::new();
|
||||
plain.stage_input = stage_input.cloned();
|
||||
let pipeline = compile(&plain)?;
|
||||
let threads = threads_per_threadgroup
|
||||
.iter()
|
||||
@@ -93,10 +96,10 @@ mod tests {
|
||||
under(&LoweringInputs::new().kernel_variant(KernelVariant::EmulatedSimdgroups));
|
||||
assert_ne!(plain, emulated);
|
||||
for n in [1, 4, 16] {
|
||||
let kernel = compile_kernel(&device, &function, [n, 1, 1], &budget).unwrap();
|
||||
let kernel = compile_kernel(&device, &function, [n, 1, 1], None, &budget).unwrap();
|
||||
assert_eq!(kernel, emulated, "{n}");
|
||||
}
|
||||
let kernel = compile_kernel(&device, &function, [32, 1, 1], &budget).unwrap();
|
||||
let kernel = compile_kernel(&device, &function, [32, 1, 1], None, &budget).unwrap();
|
||||
assert_eq!(kernel, plain);
|
||||
}
|
||||
}
|
||||
@@ -615,10 +615,7 @@ fn run(
|
||||
// What the dispatch changed around each guarded target.
|
||||
let escaped: BTreeMap<OutOfBoundsResource, GuardCount> = (buffers.iter())
|
||||
.filter_map(|(&index, placed)| {
|
||||
Some((
|
||||
OutOfBoundsResource::Buffer { binding: index },
|
||||
placed.escaped()?,
|
||||
))
|
||||
Some((guards::buffer_resource(case, index), placed.escaped()?))
|
||||
})
|
||||
.chain(members.iter().filter_map(|(&(owner, field), placed)| {
|
||||
let resource = OutOfBoundsResource::ArgumentBufferBuffer {
|
||||
@@ -785,9 +782,10 @@ fn descriptor(
|
||||
.with_specialized(true)
|
||||
.with_linked(linked);
|
||||
function.constants = case.constants.clone();
|
||||
Ok(ComputePipelineDescriptor::new(StageSource::Function(
|
||||
function,
|
||||
)))
|
||||
let mut descriptor = ComputePipelineDescriptor::new(StageSource::Function(function));
|
||||
// The stage-input descriptor the oracle's `MTLComputePipelineDescriptor` holds.
|
||||
descriptor.stage_input = case.stage_input.clone();
|
||||
Ok(descriptor)
|
||||
}
|
||||
|
||||
/// The pipeline state `make` makes, within the per-attempt ceilings ([`within_ceilings`]), the
|
||||
@@ -1063,6 +1061,12 @@ fn dispatched(
|
||||
.set_imageblock_size(width, height)
|
||||
.map_err(fail("the imageblock size"))?;
|
||||
}
|
||||
if let Some(region) = case.stage_in_region {
|
||||
encoder.set_stage_in_region(rt::Region {
|
||||
origin: region.origin,
|
||||
size: region.size,
|
||||
});
|
||||
}
|
||||
match dispatch {
|
||||
rt::Dispatch::Threads(threads) => {
|
||||
encoder.dispatch_threads(threads, threads_per_group)
|
||||
|
||||
@@ -81,6 +81,9 @@ pub(crate) fn case(entry: &str, buffer: Vec<u8>, dispatch: Dispatch) -> ComputeC
|
||||
ComputeCase {
|
||||
out_of_bounds: Vec::new(),
|
||||
creation_bound: crate::budgets::PIPELINE_CREATION_CEILING,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
stage_input_locations: BTreeMap::new(),
|
||||
entry: entry.into(),
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
buffers: BTreeMap::from([(0, buffer)]),
|
||||
|
||||
@@ -60,6 +60,9 @@ fn kernel(
|
||||
ComputeCase {
|
||||
out_of_bounds: Vec::new(),
|
||||
creation_bound: crate::budgets::PIPELINE_CREATION_CEILING,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
stage_input_locations: BTreeMap::new(),
|
||||
entry: entry.into(),
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
buffers: if out.is_empty() {
|
||||
|
||||
@@ -142,6 +142,9 @@ pub(super) mod device {
|
||||
Ok(ComputeCase {
|
||||
out_of_bounds: Vec::new(),
|
||||
creation_bound: crate::budgets::PIPELINE_CREATION_CEILING,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
stage_input_locations: BTreeMap::new(),
|
||||
entry: kernel.entry.to_owned(),
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
buffers,
|
||||
|
||||
@@ -66,6 +66,9 @@ fn run(entry: &str, bitcode: &[u8], n: u32, limits: [u32; 2]) -> (Vec<u32>, usiz
|
||||
let case = ComputeCase {
|
||||
out_of_bounds: Vec::new(),
|
||||
creation_bound: crate::budgets::PIPELINE_CREATION_CEILING,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
stage_input_locations: BTreeMap::new(),
|
||||
entry: entry.into(),
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
buffers: BTreeMap::from([
|
||||
|
||||
@@ -745,8 +745,8 @@ pub fn unsupported_source_requirements(
|
||||
/// checker does not require one), a linked intersection function (the case's acceleration
|
||||
/// structures are opaque triangles, which call none), a vertex case's depth/stencil attachment or
|
||||
/// a rasterization-disabled vertex case's render targets, and the families the runtime builds no
|
||||
/// call for: a kernel's function table, imageblock, acceleration structure or stage inputs, and a
|
||||
/// fragment function's imageblock among them.
|
||||
/// call for: a kernel's function table, imageblock, acceleration structure or stage input of a
|
||||
/// dynamic stride, and a fragment function's imageblock among them.
|
||||
pub fn engine_source_requirements(reflection: &ShaderInterface) -> BTreeSet<ToolingRequirement> {
|
||||
let render = matches!(
|
||||
reflection.stage,
|
||||
@@ -801,8 +801,8 @@ pub fn engine_source_requirements(reflection: &ShaderInterface) -> BTreeSet<Tool
|
||||
/// ([`depth_range::depth_range_requirement`]), and so are an indexed draw past its index buffer
|
||||
/// (its out-of-bounds target, [`ToolingRequirement::IndexBufferPastEnd`]) and a depth/stencil
|
||||
/// attachment of both aspects ([`ToolingRequirement::SeparateDepthStencil`]). So are the families
|
||||
/// the runtime builds no call for, or refuses at creation on every device: a kernel's explicit
|
||||
/// imageblock, acceleration structure or stage inputs, a sparse texture, a
|
||||
/// the runtime builds no call for, or refuses at creation on every device: a kernel's implicit
|
||||
/// imageblock, acceleration structure or stage input of a dynamic stride, a sparse texture, a
|
||||
/// fragment function's imageblock, a rasterization-rate map, a vertex buffer's dynamic stride, an indirect command buffer of any form but kernel-encoded indexed
|
||||
/// draws that inherit the pipeline state and bind their own buffers (its compute commands, its
|
||||
/// other draw types, its other inheritance, or a command the host encodes), and a pipeline state
|
||||
@@ -895,12 +895,11 @@ pub fn case_requirements(case: &AuthoredCase) -> BTreeSet<ToolingRequirement> {
|
||||
),
|
||||
(
|
||||
kernel
|
||||
&& (!case.kernel_stage_inputs.is_empty()
|
||||
|| case
|
||||
.dispatch
|
||||
.as_ref()
|
||||
.is_some_and(|dispatch| dispatch.stage_in_region.is_some())),
|
||||
ToolingRequirement::KernelStageInput,
|
||||
&& case
|
||||
.kernel_stage_inputs
|
||||
.iter()
|
||||
.any(|input| input.dynamic_stride),
|
||||
ToolingRequirement::DynamicStageInStride,
|
||||
),
|
||||
(
|
||||
case.render_pass_rate_map.is_some()
|
||||
@@ -3083,7 +3082,7 @@ entry:
|
||||
}
|
||||
only(&aspects, ToolingRequirement::SeparateDepthStencil);
|
||||
// What the runtime builds no call for, or refuses at creation: a sparse texture, a
|
||||
// kernel's stage inputs or stage-in region, a vertex buffer's dynamic stride, a fragment
|
||||
// kernel's stage input of a dynamic stride, a vertex buffer's dynamic stride, a fragment
|
||||
// function's imageblock and a rasterization-rate map. A bound texture buffer it makes.
|
||||
let texture = |texture_type| TextureResource {
|
||||
binding: 0,
|
||||
@@ -3134,7 +3133,7 @@ entry:
|
||||
assert!(case_requirements(®ion).is_empty());
|
||||
let mut dynamic = kernel.clone();
|
||||
dynamic.kernel_stage_inputs = vec![input(true)];
|
||||
only(&dynamic, ToolingRequirement::KernelStageInput);
|
||||
only(&dynamic, ToolingRequirement::DynamicStageInStride);
|
||||
let mut fetched = kernel.clone();
|
||||
fetched.stage = Stage::Vertex;
|
||||
fetched.vertex_observation = Some(VertexObservation::Position);
|
||||
|
||||
@@ -218,12 +218,13 @@ pub enum ToolingRequirement {
|
||||
/// [`Self::RenderAccelerationStructure`]). The runtime makes no acceleration structure, and its
|
||||
/// compute encoder binds neither, so no call of it runs such a kernel.
|
||||
KernelAccelerationStructure,
|
||||
/// A compute kernel's `[[stage_in]]` inputs, or its dispatch's stage-in region
|
||||
/// (`executor_contract::case_requirements`). The runtime fetches stage inputs, but the engine's
|
||||
/// run through it (`candidate::platform::runtime`) makes its pipeline state without the
|
||||
/// case's stage-input descriptor and sets no stage-in region, so no call of it runs such a
|
||||
/// case as written.
|
||||
KernelStageInput,
|
||||
/// A compute kernel's `[[stage_in]]` input of a layout of `MTLBufferLayoutStrideDynamic`
|
||||
/// (`executor_contract::case_requirements`), whose data the case binds with the stride form.
|
||||
/// The runtime refuses such a layout (`metal2vulkan_runtime::Gap::StageIn` of
|
||||
/// `StageInKind::DynamicStride`): its compute encoder has no
|
||||
/// `setBuffer:offset:attributeStride:atIndex:`, which is its guard. A kernel's stage inputs of
|
||||
/// a fixed stride and its dispatch's stage-in region run through the runtime.
|
||||
DynamicStageInStride,
|
||||
/// A rasterization-rate map (`executor_contract::case_requirements`): a render pass's, or one
|
||||
/// whose parameter data a buffer or an argument buffer's buffer holds. The runtime makes no
|
||||
/// rate map, and its render pass descriptor has no field for one, so no call of it makes one.
|
||||
@@ -317,7 +318,7 @@ impl ToolingRequirement {
|
||||
Self::FragmentImageblock,
|
||||
Self::SparseTexture,
|
||||
Self::KernelAccelerationStructure,
|
||||
Self::KernelStageInput,
|
||||
Self::DynamicStageInStride,
|
||||
Self::RasterizationRateMap,
|
||||
Self::DynamicVertexStride,
|
||||
Self::IndirectComputeCommands,
|
||||
@@ -364,7 +365,7 @@ impl ToolingRequirement {
|
||||
Self::FragmentImageblock => "fragment_imageblock",
|
||||
Self::SparseTexture => "sparse_texture",
|
||||
Self::KernelAccelerationStructure => "kernel_acceleration_structure",
|
||||
Self::KernelStageInput => "kernel_stage_input",
|
||||
Self::DynamicStageInStride => "dynamic_stage_in_stride",
|
||||
Self::RasterizationRateMap => "rasterization_rate_map",
|
||||
Self::DynamicVertexStride => "dynamic_vertex_stride",
|
||||
Self::IndirectComputeCommands => "indirect_compute_commands",
|
||||
@@ -433,7 +434,7 @@ impl ToolingRequirement {
|
||||
| Self::FragmentImageblock
|
||||
| Self::SparseTexture
|
||||
| Self::KernelAccelerationStructure
|
||||
| Self::KernelStageInput
|
||||
| Self::DynamicStageInStride
|
||||
| Self::RasterizationRateMap
|
||||
| Self::DynamicVertexStride
|
||||
| Self::IndirectComputeCommands
|
||||
@@ -462,7 +463,7 @@ impl ToolingRequirement {
|
||||
/// [`ToolingRequirement::SeparateDepthStencil`], [`ToolingRequirement::KernelImageblock`],
|
||||
/// [`ToolingRequirement::FragmentImageblock`], [`ToolingRequirement::SparseTexture`],
|
||||
/// [`ToolingRequirement::KernelAccelerationStructure`],
|
||||
/// [`ToolingRequirement::KernelStageInput`], [`ToolingRequirement::RasterizationRateMap`],
|
||||
/// [`ToolingRequirement::DynamicStageInStride`], [`ToolingRequirement::RasterizationRateMap`],
|
||||
/// [`ToolingRequirement::DynamicVertexStride`], [`ToolingRequirement::IndirectComputeCommands`],
|
||||
/// [`ToolingRequirement::IndirectDrawTypes`], [`ToolingRequirement::IndirectCommandInheritance`],
|
||||
/// [`ToolingRequirement::HostEncodedIndirectCommands`] and
|
||||
@@ -482,7 +483,7 @@ impl ToolingRequirement {
|
||||
| Self::FragmentImageblock
|
||||
| Self::SparseTexture
|
||||
| Self::KernelAccelerationStructure
|
||||
| Self::KernelStageInput
|
||||
| Self::DynamicStageInStride
|
||||
| Self::RasterizationRateMap
|
||||
| Self::DynamicVertexStride
|
||||
| Self::IndirectComputeCommands
|
||||
@@ -726,7 +727,10 @@ mod tests {
|
||||
ToolingRequirement::KernelAccelerationStructure,
|
||||
"kernel_acceleration_structure",
|
||||
),
|
||||
(ToolingRequirement::KernelStageInput, "kernel_stage_input"),
|
||||
(
|
||||
ToolingRequirement::DynamicStageInStride,
|
||||
"dynamic_stage_in_stride",
|
||||
),
|
||||
(
|
||||
ToolingRequirement::RasterizationRateMap,
|
||||
"rasterization_rate_map",
|
||||
@@ -816,7 +820,7 @@ mod tests {
|
||||
ToolingRequirement::FragmentImageblock,
|
||||
ToolingRequirement::SparseTexture,
|
||||
ToolingRequirement::KernelAccelerationStructure,
|
||||
ToolingRequirement::KernelStageInput,
|
||||
ToolingRequirement::DynamicStageInStride,
|
||||
ToolingRequirement::RasterizationRateMap,
|
||||
ToolingRequirement::DynamicVertexStride,
|
||||
ToolingRequirement::IndirectComputeCommands,
|
||||
|
||||
@@ -869,6 +869,7 @@ mod tests {
|
||||
],
|
||||
},
|
||||
threads_per_threadgroup: [32, 1, 1],
|
||||
stage_input: None,
|
||||
};
|
||||
let libraries = [caller.as_slice(), functions.as_slice(), caller.as_slice()];
|
||||
let (bytes, digest) = libraries_input(&device, &libraries, request.clone());
|
||||
|
||||
+9
-5
@@ -556,11 +556,15 @@ cargo run -p metal2vulkan-validation --release --bin corpus-vulkan -- \
|
||||
on both executors (the runtime makes it over its buffer's bytes); a kernel's visible-function
|
||||
table runs on both: the run makes it of the state, as the oracle does, each authored entry the
|
||||
handle of its linked function, and binds it at its index. A kernel's explicit imageblock runs
|
||||
on both executors at the size the case sets (`setImageblockWidth:height:`); a tile function's
|
||||
implicit one carries `kernel_imageblock`, a kernel's acceleration structure or
|
||||
intersection-function table `kernel_acceleration_structure`, its stage inputs or stage-in region
|
||||
`kernel_stage_input`, and a rasterization-rate map, a render pass's or one whose data a buffer
|
||||
holds, `rasterization_rate_map`: each the runtime's limit, run on Metal alone. The runtime's
|
||||
on both executors at the size the case sets (`setImageblockWidth:height:`). A kernel's stage
|
||||
inputs of a fixed stride run on both executors under the stage-input descriptor and the
|
||||
stage-in region the oracle sets (`executor_contract::stage_inputs`), each input's data its own
|
||||
buffer at the slot its location takes. A tile function's implicit imageblock carries
|
||||
`kernel_imageblock`, a kernel's acceleration structure or intersection-function table
|
||||
`kernel_acceleration_structure`, a stage input of a dynamic stride `dynamic_stage_in_stride`
|
||||
(the runtime's compute encoder binds no stride), and a rasterization-rate map, a render pass's
|
||||
or one whose data a buffer holds, `rasterization_rate_map`: each the runtime's limit, run on
|
||||
Metal alone. The runtime's
|
||||
indirect command buffer holds kernel-encoded indexed draws that inherit the pipeline state and
|
||||
bind their own buffers; one of compute commands carries `indirect_compute_commands`, one that
|
||||
allows other draws `indirect_draw_types`, one whose commands set their own pipeline state or
|
||||
|
||||
Reference in new issue
Block a user