Validation: nine families the runtime does not build are refusal rows naming their requirement

The family map's first commit (the planner's GO): every committed case either runs through the
runtime or is a refusal row naming its requirement. Nine families of the cases the executor still
ran on its own context have no runtime call, or a runtime refusal at creation on every device. Each
is now a ToolingRequirement of Limit::Runtime that stops only the engine's candidate and keeps its
cases Metal-qualified. Each is raised from the case's literals in executor_contract::case_requirements,
by the template of SeparateDepthStencil and RenderFunctionTable, so no census row carries one:
- kernel_function_table (303 cases): no setVisibleFunctionTable:atBufferIndex:; the make is
  Gap::KernelInput of Slot, held by rt's device test
  kernel_input::a_visible_function_table_kernel_is_refused_as_a_slot;
- kernel_imageblock (51, every tile-pass case among them): no setImageblockWidth:height:; the make
  is Gap::KernelInput of RuntimeFact ImageblockSize (rt's
  an_explicit_imageblock_kernel_is_refused_as_its_named_runtime_fact); no tile function is built;
- texture_buffer (28): new_texture refuses one (Gap::TextureBuffer), held both ways by
  engine_compute::a_texture_buffer_is_refused_where_a_2d_texture_is_made;
- fragment_imageblock (21): refused at creation on every device (Imageblocks, NotImplemented);
- sparse_texture (15): the texture descriptor has no sparse form;
- rasterization_rate_map (12: 8 render-pass maps, 4 kernel cases whose buffers hold map data):
  rt makes no rate map and its pass takes none;
- kernel_acceleration_structure (10): rt makes no acceleration structure and binds neither it nor
  an intersection-function table;
- kernel_stage_input (9): Gap::KernelInput of StageIn (rt's a_stage_in_kernel_is_refused_as_stage_in);
- dynamic_vertex_stride (1): setVertexBuffer:offset:attributeStride:atIndex: is not built.
The nine raise on 450 committed cases with no overlap. No case is deleted.
ToolingRequirement::qualifies_on_metal is now exactly Limit::Runtime (it listed the same eight).

The compile census (authored-compile.tsv) is due a bless here: every cell of the 450 cases moves to
its requirement. All read `compiled` today except 6 texture_buffer cases already
`ulong_texture_atomic` (now `ulong_texture_atomic,texture_buffer`) and 6 kernel_acceleration_structure
cells that read RayTracing device_capability_missing. 4 ICB cases replay a template of these
families, which compute_case/render_case now refuse before the replay check: their
`replayed_template_resources` becomes the template's family:
a-kernel-encodes-the-stage-in-regions-of-its-dispatches and
host-encoded-stage-in-regions-and-attribute-strides-of-executed-commands (kernel_stage_input),
a-kernel-encodes-the-imageblock-sizes-of-its-dispatches (kernel_imageblock),
host-encoded-vertex-attribute-strides-of-executed-draws (dynamic_vertex_stride).
The authoring-capabilities census is untouched: Limit::Runtime rows close without a candidate, and
executor_contract.rs is a classifier input, so cached triage recomputes.

Tests that mapped these families through the own context now meet the refusal. They are rewritten
to assert it: the requirement and case-literal tests, the_case_maps_onto_the_binder_or_names_the_gap,
references_link_and_function_tables_are_typed_gaps, the sparse and rate-map case tests, and the
public argument-buffer case, which now selects the cases with no requirement. Or they are removed
with the mapping they held: stage inputs, acceleration structures, the tile pass, fragment
imageblock cells, the public stage-input, ray, tile and fragment-imageblock cases, the kernel
table's integration case, and the dynamic-stride device test. The device-worker test's case is
now single-thread-store-constant: its acceleration-structure case is refused before the digest
check it holds. The own-context arms these families used are deleted in the next commit.

Owed answer: of the cases that route today, 0 render into one combined depth-stencil texture
using both aspects. The case files hold only Depth32Float textures, the 5 both-aspect attachments
carry separate_depth_stencil, and the route takes one aspect.

Verified: probe at a0f86a2efc, job m3-max-63255, listed the 16 tests the requirements failed. All
16 are fixed in m3-max-63274: fmt, validation clippy plain and --cfg m2v_cpu_icd, Rustdoc, and the
validation suite, 1352 passed. This commit is that tree on a8c2bfbfae.
This commit is contained in:
Anees Iqbal committed 2026-11-21 05:29:40 -08:00
1 parent fb466b4519
commit d1266e5a5a
12 files changed
+383 -1157

No files matched your search

@@ -2150,65 +2150,6 @@ fn the_cells_follow_the_reflected_master() {
assert_eq!(two.cell_bytes, 16);
}
/// Every committed public fragment imageblock case maps onto a draw, its cells the initializer's,
/// and the product refuses its pipeline typed on every device (`NotImplemented(Imageblocks)`): the
/// product's refusal, not the executor's.
#[test]
fn public_fragment_imageblock_cases_are_refused_typed() {
use metal2vulkan::error::{Feature, Needs};
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let sources = public_sources().unwrap();
let mut refused = 0;
for case in CorpusStore::new(&root).read_all_cases().unwrap() {
if case.fragment_imageblock.is_none() {
continue;
}
let Some(row) = sources
.iter()
.find(|row| row.air_sha256 == case.air_sha256 && row.entry == case.entry)
else {
continue;
};
let scratch = crate::ScratchDir::new("public-imageblock-case").unwrap();
let ll = scratch.path().join("case.ll");
std::fs::write(&ll, &row.air_ll).unwrap();
let Some(bitcode) = assembled(&ll) else {
return;
};
let name = &case.name;
let checked = crate::check::check_case_against_source(&root, case.clone(), row)
.unwrap_or_else(|errors| panic!("{name}: {errors:?}"));
let render = render_case(
&case,
&checked.primary.interface,
&row.air_ll,
checked.primary.companion.as_ref(),
checked.primary.reflection.fragment_imageblock.as_ref(),
)
.unwrap_or_else(|error| panic!("{name}: {error:?}"));
assert!(render.imageblock.is_some(), "{name}: no cells");
let companion = render.companion.as_ref().unwrap().opaque_bitcode().unwrap();
let libraries = RenderLibraries {
vertex: &companion,
fragment: Some(&bitcode),
};
for stem in ["lavapipe", "moltenvk-m3", "runtime-floor"] {
match plan_render(&device(stem), &render, libraries) {
Err(Error::Unsupported(refusal)) => assert_eq!(
(refusal.feature, refusal.needs),
(Feature::Imageblocks, Needs::NotImplemented),
"{name} on {stem}"
),
other => panic!("{name} on {stem}: {:?}", other.map(|_| ())),
}
}
refused += 1;
}
// fragment-custom-imageblock-depth, the ten cases, the imageblock_transition case, the two
// splat cases, and the six cases on `rfs_imageblock_cover`.
assert_eq!(refused, 20);
}
/// The graphics state of the public fixture `fragment_rate_map_position` drawn by its generated
/// fullscreen vertex function, compiled for lavapipe; `None` without `llvm-as`.
fn rate_map_position_graphics() -> Option<metal2vulkan::pipeline::GraphicsState> {
@@ -12,7 +12,6 @@ use metal2vulkan::error::{BindError, Capability, Feature, Needs, Unsupported};
use metal2vulkan::library::Library;
use metal2vulkan::metal::format::vk_format;
use metal2vulkan::pipeline::FunctionDescriptor;
use metal2vulkan::pipeline::PushField;
use metal2vulkan::Budget;
use metal2vulkan_devtools::{llvm_assemble, AssembleError};
use std::collections::{BTreeMap, BTreeSet};
@@ -202,14 +201,8 @@ fn plan_case(device: &Device, case: &AuthoredCase, row: &crate::source::SourceRo
plan.diagnostics
);
// A plan that needed a variant counts as its own family, so the lowering-input path is
// known to run; so does a structure's instance count the binder pushes.
// known to run.
let variant = (!plan.variant.is_empty()).then_some("pipeline variant");
let count = plan
.push
.fields
.iter()
.any(|placement| matches!(placement.field, PushField::InstanceCount(_)))
.then_some("instance count");
Planned::Writes(
plan.descriptors
.iter()
@@ -221,24 +214,20 @@ fn plan_case(device: &Device, case: &AuthoredCase, row: &crate::source::SourceRo
}
WriteSource::Texture { .. } => "texture",
WriteSource::CombinedImageSampler { .. } => "combined image sampler",
WriteSource::TexelBuffer { .. } => "texel buffer",
WriteSource::Sampler { .. } => "sampler",
WriteSource::Neutral(_) => "neutral",
WriteSource::AccelerationStructure { .. } => "acceleration structure",
WriteSource::TileMap { .. } => "tile map",
_ => "buffer-like",
})
.chain(variant)
.chain(count)
.collect(),
)
}
/// Every public kernel case with textures or samplers that maps and compiles for its bind state
/// plans the variant it was compiled for and no plan diagnostic (which the executor refuses), and
/// together they write every texture descriptor family `plan_resources` creates. On a profile
/// that needs storage formats as inputs, some of them plan a variant; on every profile a sparse
/// case plans a tile map. At least one case plans on every profile; the test skips only when no
/// together they write a sampled texture, a storage texture and a sampler. On a profile that needs
/// storage formats as inputs, some of them plan a variant. At least one case plans on every
/// profile; the test skips only when no
/// `llvm-as` is installed, and a case whose fixture the installed `llvm-as` rejects is skipped
/// alone, with a printed line.
#[test]
@@ -270,7 +259,7 @@ fn public_texture_cases_plan_their_compiled_variant_without_diagnostics() {
}
// Refusing every case would pass the checks below vacuously.
assert!(planned > 0, "{stem}: no public texture case planned");
for family in ["texture", "storage texture", "texel buffer"] {
for family in ["texture", "storage texture"] {
assert!(families.contains(family), "{stem}: no {family} write");
}
assert!(
@@ -282,13 +271,6 @@ fn public_texture_cases_plan_their_compiled_variant_without_diagnostics() {
if stem == "runtime-floor" {
assert!(families.contains("pipeline variant"), "{stem}: no variant");
}
// A sparse case whose observed accesses each name their texels answers residency from
// its tile map on every device, lavapipe's shader residency included (a 16-KiB tile inside
// a device's 64-KiB block).
assert!(
families.contains("tile map"),
"{stem}: tile maps {families:?}"
);
}
}
@@ -446,17 +428,21 @@ fn public_texture_array_cases_plan_their_elements_at_their_slots() {
/// Each public kernel case whose root argument points to further nodes (argument-buffer buffers)
/// maps, compiles for its bind state, and plans on devices with device addresses; its dispatch's
/// root table holds each pointee's resident entry (host and guest address), which is what a loaded
/// pointer is translated through. The cases are the one-member case and the rate-map case whose
/// maps are members.
/// pointer is translated through. The case is the one-member case: the rate-map case whose maps are
/// members is the runtime's limit (`ToolingRequirement::RasterizationRateMap`).
#[test]
fn the_public_argument_buffer_cases_plan_their_pointees_resident() {
let cases = public_cases();
let selected = cases
.iter()
.filter(|(case, _)| case.stage == Stage::Kernel && !case.argument_buffer_buffers.is_empty())
.filter(|(case, _)| {
case.stage == Stage::Kernel
&& !case.argument_buffer_buffers.is_empty()
&& crate::executor_contract::case_requirements(case).is_empty()
})
.collect::<Vec<_>>();
assert!(
selected.len() >= 2,
!selected.is_empty(),
"the public kernel cases with argument-buffer buffers"
);
for (case, row) in selected {
@@ -547,281 +533,3 @@ fn the_public_argument_buffer_cases_plan_their_pointees_resident() {
}
}
}
/// The public kernel case with a stage input maps each input's data to its slot and compiles under
/// the stage-input descriptor the Metal oracle's pipeline has; its plan binds the input's buffer,
/// and the dispatch writes the stage-in region the oracle sets.
#[test]
fn the_public_stage_input_case_compiles_under_the_oracles_descriptor() {
let cases = public_cases();
let (case, row) = cases
.iter()
.find(|(case, _)| case.stage == Stage::Kernel && !case.kernel_stage_inputs.is_empty())
.expect("a public kernel case with a stage input");
let scratch = crate::ScratchDir::new("public-stage-input-case").unwrap();
let ll = scratch.path().join("case.ll");
std::fs::write(&ll, &row.air_ll).unwrap();
let bitcode = match llvm_assemble(&ll) {
Ok(bitcode) => bitcode,
Err(AssembleError::Missing(why)) => {
eprintln!("SKIPPED: {why}");
return;
}
Err(AssembleError::Rejected(why)) => panic!("{}: llvm-as rejected it: {why}", case.name),
};
let interface = interface(case, &bitcode);
let compute = compute_case(case, &interface).unwrap();
let fetches =
crate::executor_contract::stage_inputs::authored(&case.kernel_stage_inputs, &interface)
.unwrap();
let descriptor = compute
.stage_input
.clone()
.expect("a stage-input descriptor");
for fetch in &fetches {
assert!(compute.buffers.contains_key(&fetch.slot), "{fetch:?}");
assert_eq!(
descriptor.attributes[&fetch.location].buffer_index,
fetch.slot
);
}
let library = Library::from_air(&bitcode).unwrap();
let mut function = FunctionDescriptor::new(library.function(&compute.entry).unwrap());
function.constants = compute.constants.clone();
for stem in ["lavapipe", "moltenvk-m3", "runtime-floor"] {
let device = device(stem);
let shape = compute_shape(&compute, true, BufferRanges::default()).unwrap();
// Without the descriptor, the kernel asks for it.
assert!(matches!(
variants::compile_compute_for_shape(
&device,
&function,
&shape,
Some(&compute.dispatch),
None,
&Budget::standard(),
),
Err(metal2vulkan::error::Error::NeedsInput(
metal2vulkan::error::RuntimeInput::StageInputDescriptor { .. }
))
));
let (pipeline, inputs) = variants::compile_compute_for_shape(
&device,
&function,
&shape,
Some(&compute.dispatch),
Some(&descriptor),
&Budget::standard(),
)
.unwrap_or_else(|error| panic!("{stem}: compile: {error:?}"));
let plan = pipeline.plan(&device, &shape).unwrap();
assert!(variants::compiled_for(&inputs, &plan.variant), "{stem}");
assert!(
plan.diagnostics.is_empty(),
"{stem}: {:?}",
plan.diagnostics
);
let addresses = compute
.buffers
.keys()
.map(|&index| {
let mut address = BufferAddress::synthetic(index);
address.host = Some(address.guest);
(index, address)
})
.collect();
let state = bind_state(
&compute,
&addresses,
&BTreeMap::new(),
BufferRanges::default(),
)
.unwrap();
assert_eq!(state.shape(), shape, "{stem}");
assert_eq!(
state.stage_in_region.map(|r| r.size),
Some(case.dispatch.as_ref().unwrap().grid)
);
plan.instantiate_dispatch(&state, &compute.dispatch)
.unwrap_or_else(|error| panic!("{stem}: {error}"));
}
}
/// The public kernel cases over acceleration structures map, compile for lavapipe, which traces
/// rays, and plan with no diagnostic, those that intersect an acceleration-structure write (a
/// kernel that never reads its structure declares none). MoltenVK has no ray queries: the product
/// refuses every case that intersects its structure there. A case that only counts its structure's
/// instances plans on both, with no structure write and the count a push field.
#[test]
fn public_ray_cases_plan_their_structures_where_the_device_traces_rays() {
let cases: Vec<_> = public_cases()
.into_iter()
.filter(|(case, _)| case.stage == Stage::Kernel && !case.acceleration_structures.is_empty())
.collect();
assert!(!cases.is_empty(), "no public ray case");
for (stem, traces) in [("lavapipe", true), ("moltenvk-m3", false)] {
let device = device(stem);
let mut structures = 0;
let mut counts = 0;
for (case, row) in &cases {
match plan_case(&device, case, row) {
Planned::Refused => assert!(!traces, "{stem}: {} refused", case.name),
Planned::NoAssembler(why) => {
eprintln!("SKIPPED: {why}");
return;
}
Planned::Unassembled(why) => {
eprintln!("SKIPPED {}: llvm-as rejected its fixture: {why}", case.name);
}
Planned::Writes(writes) => {
if writes.contains("acceleration structure") {
assert!(traces, "{stem}: {} planned a structure", case.name);
structures += 1;
}
counts += usize::from(writes.contains("instance count"));
}
}
}
assert_eq!(
structures > 0,
traces,
"{stem}: {structures} structure writes"
);
assert!(counts > 0, "{stem}: no case counted its instances");
}
}
/// Every public tile case (an implicit imageblock over render targets) maps to a tile pass whose
/// dispatch is one threadgroup per tile of its render area, compiles as a tile pipeline under its
/// render targets' formats with the inputs its bind state decides, and plans the variant it was
/// compiled for with no diagnostic, a tile-attachment write of every attachment it stages, and the
/// pass's whole tiles as its render area and its tile size specialized; or the profile refuses it
/// typed (an attachment format it cannot store, such as `RG16Float` without extended storage
/// formats). At least one case plans on every profile.
#[test]
fn public_tile_cases_plan_their_attachments() {
use metal2vulkan::pipeline::SpecKey;
let cases = public_cases();
let tiles = cases
.iter()
.filter(|(case, _)| {
case.imageblock
.as_ref()
.is_some_and(|imageblock| imageblock.implicit_coverage.is_some())
})
.collect::<Vec<_>>();
assert!(!tiles.is_empty(), "no public tile case");
for stem in ["lavapipe", "moltenvk-m3", "runtime-floor"] {
let device = device(stem);
let mut planned = 0;
for (case, row) in &tiles {
let scratch = crate::ScratchDir::new("public-tile-case").unwrap();
let ll = scratch.path().join("case.ll");
std::fs::write(&ll, &row.air_ll).unwrap();
let bitcode = match llvm_assemble(&ll) {
Ok(bitcode) => bitcode,
Err(AssembleError::Missing(why)) => {
eprintln!("SKIPPED: {why}");
return;
}
Err(AssembleError::Rejected(why)) => {
eprintln!("SKIPPED {}: llvm-as rejected its fixture: {why}", case.name);
continue;
}
};
let compute = compute_case(case, &interface(case, &bitcode))
.unwrap_or_else(|error| panic!("{}: {error:?}", case.name));
let pass = compute.tile.as_ref().expect("a tile pass");
let [tile_width, tile_height] = case.imageblock.as_ref().unwrap().dimensions;
let dispatch = case.dispatch.as_ref().unwrap();
assert_eq!(
compute.dispatch,
Dispatch::Threadgroups {
groups: [
pass.area[0].div_ceil(tile_width),
pass.area[1].div_ceil(tile_height),
1
],
threads_per_group: dispatch.threads_per_threadgroup,
},
"{}",
case.name
);
let library = Library::from_air(&bitcode).unwrap();
let mut function = FunctionDescriptor::new(library.function(&compute.entry).unwrap());
function.constants = compute.constants.clone();
let shape = compute_shape(&compute, true, BufferRanges::default()).unwrap();
let (pipeline, inputs) = match variants::compile_tile_for_shape(
&device,
&function,
&shape,
Some(&compute.dispatch),
&pass.formats(),
&Budget::standard(),
) {
Ok(compiled) => compiled,
Err(error) if !Outcome::from(&error).is_defect() => continue,
Err(error) => panic!("{} on {stem}: compile: {error:?}", case.name),
};
let plan = pipeline
.plan(&device, &shape)
.unwrap_or_else(|error| panic!("{} on {stem}: plan: {error}", case.name));
assert!(
variants::compiled_for(&inputs, &plan.variant),
"{}",
case.name
);
assert!(plan.diagnostics.is_empty(), "{}", case.name);
let attachments = plan
.descriptors
.iter()
.filter_map(|write| match write.source {
WriteSource::TileAttachment { color_index, .. } => Some(color_index),
_ => None,
})
.collect::<BTreeSet<_>>();
assert!(!attachments.is_empty(), "{} on {stem}", case.name);
assert!(
attachments.is_subset(&pass.attachments.keys().copied().collect()),
"{} on {stem}: {attachments:?}",
case.name
);
let specialized = |key: SpecKey| {
let id = pipeline
.stage
.specialization
.constants
.iter()
.find(|constant| constant.key == key)?
.id;
let entry = plan
.specialization
.entries
.iter()
.find(|entry| entry.constant_id == id)?;
let at = entry.offset as usize;
Some(u32::from_le_bytes(
plan.specialization.data[at..at + 4].try_into().ok()?,
))
};
assert_eq!(
(
specialized(SpecKey::RenderAreaWidth),
specialized(SpecKey::RenderAreaHeight),
specialized(SpecKey::ImageblockWidth),
specialized(SpecKey::ImageblockHeight),
),
(
Some(pass.tiles[0]),
Some(pass.tiles[1]),
Some(tile_width),
Some(tile_height),
),
"{} on {stem}",
case.name
);
planned += 1;
}
assert!(planned > 0, "{stem}: no public tile case planned");
}
}
@@ -181,30 +181,18 @@ fn the_case_maps_onto_the_binder_or_names_the_gap() {
}
}
// An explicit imageblock runs, its dimensions the dispatch's imageblock size.
assert_eq!(mapped.imageblock, None);
assert_eq!(mapped.tile, None);
assert_eq!(state.imageblock_size, Default::default());
// An explicit imageblock is the runtime's limit.
let mut imageblock = kernel_case();
imageblock.imageblock = Some(crate::case::ImageblockResource {
dimensions: [16, 8],
implicit_coverage: None,
});
let explicit = map_kernel(&imageblock).unwrap();
assert_eq!(explicit.imageblock, Some([16, 8]));
assert_eq!(explicit.tile, None);
let state = bind_state(
&explicit,
&BTreeMap::new(),
&BTreeMap::new(),
BufferRanges::default(),
)
.unwrap();
assert_eq!(
state.imageblock_size,
metal2vulkan::bind::ImageblockSize::new(16, 8)
map_kernel(&imageblock),
Err(NotSupported::Requirements(
[ToolingRequirement::KernelImageblock].into()
))
);
assert_eq!(state.shape().imageblock_size, state.imageblock_size);
let mut vertex = kernel_case();
vertex.stage = Stage::Vertex;
assert!(matches!(
@@ -213,146 +201,14 @@ fn the_case_maps_onto_the_binder_or_names_the_gap() {
));
}
/// A kernel case's stage inputs run as the Metal oracle fetches them: each input's data is its own
/// buffer at the shared slot rule's slot (the lowest one no AIR argument occupies), the kernel
/// compiles under the descriptor `executor_contract::stage_inputs` derives, and the dispatch's
/// stage-in region is the grid. A location the entry does not declare, or a slot the case binds
/// itself, is a typed gap.
#[test]
fn stage_inputs_are_bound_where_the_oracle_binds_them() {
use crate::check::interface::tests::param;
use metal2vulkan_air::abi::{AbiInt, ParamRole, Slot};
let at = |index| Slot {
index: AbiInt::Const(index),
count: AbiInt::Const(1),
};
let buffer = param(
1,
ParamRole::Buffer(metal2vulkan_air::abi::BufferArg {
location: at(0),
access: metal2vulkan_air::abi::Access::ReadWrite,
space: metal2vulkan_air::ir::AddrSpace::Device,
buffer_size: None,
layout: None,
raster_order_group: None,
}),
);
let interface = kernel_interface(vec![
param(0, ParamRole::StageIn { location: at(4) }),
buffer,
]);
let mut case = kernel_case();
case.kernel_stage_inputs
.push(crate::case::KernelStageInput {
location: 4,
format: crate::case::AttributeFormat::Float3,
stride: 16,
dynamic_stride: false,
bytes_b64: base64::engine::general_purpose::STANDARD.encode([7u8; 16]),
});
let mapped = compute_case(&case, &interface).unwrap();
assert_eq!(mapped.buffers.get(&1), Some(&vec![7u8; 16]));
let d = mapped
.stage_input
.clone()
.expect("a stage-input descriptor");
assert_eq!(
d.attributes[&4],
metal2vulkan::pipeline::StageInputAttributeDescriptor::new(
metal2vulkan::metal::AttributeFormat::Float3,
0,
1
)
);
assert_eq!(d.layouts[&1].stride, Some(16));
assert_eq!(
d.layouts[&1].step_function,
metal2vulkan::metal::StepFunction::ThreadPositionInGridX
);
let state = bind_state(
&mapped,
&BTreeMap::new(),
&BTreeMap::new(),
BufferRanges::default(),
)
.unwrap();
let grid = case.dispatch.as_ref().unwrap().grid;
assert_eq!(
state.stage_in_region,
Some(metal2vulkan::bind::StageInRegion::new([0; 3], grid))
);
assert!(matches!(
state.stages[&ShaderStage::Kernel].buffers[&1],
BoundBuffer::Buffer {
length: 16,
attribute_stride: None,
..
}
));
assert!(mapped.attribute_strides.is_empty());
// A dynamic stride: the layout's is `MTLBufferLayoutStrideDynamic`, and the data's buffer is
// bound at the case's stride, as the oracle binds it.
let mut dynamic = case.clone();
dynamic.kernel_stage_inputs[0].dynamic_stride = true;
let mapped = compute_case(&dynamic, &interface).unwrap();
assert_eq!(
mapped.stage_input.as_ref().unwrap().layouts[&1].stride,
None
);
assert_eq!(mapped.attribute_strides, BTreeMap::from([(1, 16)]));
let state = bind_state(
&mapped,
&BTreeMap::new(),
&BTreeMap::new(),
BufferRanges::default(),
)
.unwrap();
assert!(matches!(
state.stages[&ShaderStage::Kernel].buffers[&1],
BoundBuffer::Buffer {
attribute_stride: Some(16),
..
}
));
// Without stage inputs: no descriptor, and no region, as the oracle sets none.
let plain = map_kernel(&kernel_case()).unwrap();
assert_eq!(plain.stage_input, None);
let state = bind_state(
&plain,
&BTreeMap::new(),
&BTreeMap::new(),
BufferRanges::default(),
)
.unwrap();
assert_eq!(state.stage_in_region, None);
let gap = |case: &AuthoredCase, interface: &AirInterface, what: &str| match compute_case(
case, interface,
) {
Err(NotSupported::NotImplemented(detail)) => assert!(detail.contains(what), "{detail}"),
other => panic!("{what}: {other:?}"),
};
gap(&case, &kernel_interface(vec![]), "no AIR stage input");
let mut taken = case.clone();
taken.buffers.push(crate::case::BufferResource {
binding: 1,
role: crate::case::ResourceRole::Input,
bytes_b64: Some("AAAAAA==".into()),
initial_bytes_b64: None,
rasterization_rate_map: None,
});
gap(&taken, &interface, "bound twice");
}
/// A case's visible-function references are no resource gap: its function links them, each
/// module once with the functions it supplies and its retained bitcode, as the Metal oracle links
/// them. Its visible-function tables map to tables the executor binds; an intersection-function
/// table of opaque triangle entries is a buffer of the product's table words, and a linked
/// intersection function and an argument-buffer intersection-function table are requirements that
/// stop this executor ([`require_case_families`]). The linking takes the tables' entries' functions
/// as the oracle's does.
/// them. A kernel's visible-function table and intersection-function table, a linked intersection
/// function and an argument-buffer intersection-function table are requirements that stop this
/// executor ([`require_case_families`]). The linking takes the tables' entries' functions as the
/// oracle's does.
#[test]
fn references_link_visible_tables_map_and_intersection_tables_are_words_or_typed_gaps() {
fn references_link_and_function_tables_are_typed_gaps() {
use crate::case::{
ArgumentBufferIntersectionFunctionTableResource, FunctionTableEntry, FunctionTableResource,
IntersectionFunctionSignature, IntersectionFunctionTableEntry,
@@ -363,7 +219,6 @@ fn references_link_visible_tables_map_and_intersection_tables_are_words_or_typed
ResolvedIntersectionFunctionEntry, ResolvedIntersectionFunctionTable,
ResolvedIntersectionFunctionTableLocation,
};
use metal2vulkan::pipeline::FunctionHandle;
let module = LibraryModuleRow {
module_sha256: "22".repeat(32),
air_ll: "define i32 @a(i32 %v) { ret i32 %v }".into(),
@@ -429,6 +284,12 @@ fn references_link_visible_tables_map_and_intersection_tables_are_words_or_typed
}]
);
// A kernel's function table and intersection-function table are the runtime's limits.
let refused = |requirements: &[ToolingRequirement]| {
Err(NotSupported::Requirements(
requirements.iter().copied().collect(),
))
};
let mut visible = case.clone();
visible.visible_function_tables = vec![FunctionTableResource {
binding: 1,
@@ -439,34 +300,10 @@ fn references_link_visible_tables_map_and_intersection_tables_are_words_or_typed
function: "c".into(),
}],
}];
assert_eq!(require_case_families(&visible), Ok(()));
let mapped = map_kernel(&visible).unwrap();
assert_eq!(
mapped.function_tables,
BTreeMap::from([(
1,
FunctionTable {
size: 3,
entries: BTreeMap::from([(
2,
tables::TableFunction {
module_sha256: module.module_sha256.clone(),
function: "c".into(),
}
)]),
}
)])
require_case_families(&visible),
refused(&[ToolingRequirement::KernelFunctionTable])
);
// A table at a buffer's index is refused (the checker refuses it first).
let mut shared = visible.clone();
shared.visible_function_tables[0].binding = 0;
match map_kernel(&shared) {
Err(NotSupported::NotImplemented(detail)) => {
assert!(detail.contains("also a visible function table"), "{detail}")
}
other => panic!("{other:?}"),
}
let mut opaque = case.clone();
opaque.intersection_function_tables = vec![IntersectionFunctionTableResource {
binding: 2,
@@ -476,30 +313,10 @@ fn references_link_visible_tables_map_and_intersection_tables_are_words_or_typed
signature: vec![IntersectionFunctionSignature::TriangleData],
}],
}];
assert_eq!(require_case_families(&opaque), Ok(()));
let words: Vec<u8> = [1u32, 3, 0, FunctionHandle::RESERVED_WORD, 0]
.into_iter()
.flat_map(u32::to_le_bytes)
.collect();
assert_eq!(map_kernel(&opaque).unwrap().buffers.get(&2), Some(&words));
let mut past = opaque.clone();
past.intersection_function_tables[0].entries =
vec![IntersectionFunctionTableEntry::OpaqueTriangle {
index: 3,
signature: vec![],
}];
assert!(matches!(
map_kernel(&past),
Err(NotSupported::NotImplemented(detail)) if detail.contains("past its size")
));
let mut shared = opaque.clone();
shared.intersection_function_tables[0].binding = 0;
assert!(matches!(
map_kernel(&shared),
Err(NotSupported::NotImplemented(detail))
if detail.contains("also an intersection function table")
));
assert_eq!(
require_case_families(&opaque),
refused(&[ToolingRequirement::KernelAccelerationStructure])
);
let mut intersection = case.clone();
intersection.intersection_function_tables = vec![IntersectionFunctionTableResource {
binding: 2,
@@ -510,9 +327,10 @@ fn references_link_visible_tables_map_and_intersection_tables_are_words_or_typed
function: "a".into(),
}],
}];
let linked = Err(NotSupported::Requirements(
[ToolingRequirement::LinkedIntersectionFunction].into(),
));
let linked = refused(&[
ToolingRequirement::LinkedIntersectionFunction,
ToolingRequirement::KernelAccelerationStructure,
]);
assert_eq!(require_case_families(&intersection), linked);
assert_eq!(map_kernel(&intersection).map(|_| ()), linked);
@@ -531,67 +349,6 @@ fn references_link_visible_tables_map_and_intersection_tables_are_words_or_typed
assert_eq!(map_kernel(&encoded).map(|_| ()), encoded_table);
}
/// A case's acceleration structures map to the structures the executor builds as the Metal
/// oracle does: a primitive structure its authored vertices, an instance structure its instance
/// count, each instance the oracle's (opaque, mask `0xFFFFFFFF`, which Vulkan's 8-bit instance mask
/// cannot hold: the binder refuses it). A render case refuses them. The bind state states each
/// instance structure's count, which `get_instance_count()` reads; a primitive structure is not
/// listed.
#[test]
fn acceleration_structures_map_to_what_the_oracle_builds() {
use crate::case::{AccelerationStructureKind, AccelerationStructureResource};
let vertices: Vec<u8> = AccelerationStructureKind::INSTANCED_TRIANGLE
.iter()
.flat_map(|v| v.to_le_bytes())
.collect();
let mut case = kernel_case();
case.acceleration_structures = vec![
AccelerationStructureResource {
binding: 5,
kind: AccelerationStructureKind::Primitive,
primitive_triangles_b64: Some(b64(&vertices)),
child_references: vec![],
},
AccelerationStructureResource {
binding: 6,
kind: AccelerationStructureKind::Instance,
primitive_triangles_b64: None,
child_references: vec![0, 0],
},
];
assert_eq!(require_case_families(&case), Ok(()));
assert_eq!(
map_kernel(&case).unwrap().acceleration_structures,
BTreeMap::from([
(5, CaseStructure::Primitive { vertices }),
(6, CaseStructure::Instances { instances: 2 }),
])
);
let state = bind_state(
&map_kernel(&case).unwrap(),
&BTreeMap::new(),
&BTreeMap::new(),
BufferRanges::default(),
)
.unwrap();
assert_eq!(
state.stages[&ShaderStage::Kernel].acceleration_structures,
BTreeMap::from([(6, metal2vulkan::bind::BoundAccelerationStructure::new(2))])
);
assert_eq!(
metal2vulkan::bind::instance_record(&CaseStructure::instance(), 0, 0),
Err(metal2vulkan::error::Unsupported::not_representable(
metal2vulkan::error::Feature::RayTracing
))
);
let mut shared = case.clone();
shared.acceleration_structures[0].binding = 0;
assert!(matches!(
map_kernel(&shared),
Err(NotSupported::NotImplemented(detail)) if detail.contains("bound twice")
));
}
/// A table's buffer is the product's table words (`FunctionTableWords`): bound, its size, and each
/// authored entry the handle the compile gave the function it holds, found by module and name among
/// the function's linked libraries; every other entry is null. It is bound as a buffer of its
@@ -1060,165 +817,6 @@ fn outputs_are_exact_ranges_of_the_bound_buffer() {
assert!(selected(target(2, [2, 0], [2, 1])).is_err());
}
/// A tile kernel over render targets runs in the Metal oracle's tile pass: its render area the
/// dispatch grid's width and height, its tile size the imageblock's dimensions, one threadgroup of
/// the case's threads per tile (a partial tile included), each render target a 2D attachment of its
/// format and contents, which the executor binds over the whole tiles (past its texels the
/// nearest), bound with the whole tiles as the render area, as the runtime's dispatch binds it, and
/// compiled as a tile pipeline under the attachments' formats; a render-target output selects an
/// attachment.
#[test]
fn a_tile_kernel_runs_in_its_tile_pass() {
use crate::case::{
Dispatch as CaseDispatch, ImageblockResource, ImplicitImageblockCoverage,
RenderTargetResource, TextureFormat,
};
let mut case = kernel_case();
case.imageblock = Some(ImageblockResource {
dimensions: [16, 16],
implicit_coverage: Some(ImplicitImageblockCoverage::FullSingleSample),
});
case.dispatch = Some(CaseDispatch {
grid: [40, 24, 1],
threads_per_threadgroup: [8, 8, 1],
stage_in_region: None,
});
let pixels: Vec<u8> = (0..40 * 24 * 4).map(|i| i as u8).collect();
case.render_targets = vec![RenderTargetResource {
index: 1,
format: TextureFormat::R32Uint,
dimensions: [40, 24],
initial_bytes_b64: b64(&pixels),
}];
case.output = OutputSelection::RenderTarget {
index: 1,
origin: [8, 2],
dimensions: [4, 3],
};
let mapped = map_kernel(&case).unwrap();
assert_eq!(
mapped.dispatch,
Dispatch::Threadgroups {
groups: [3, 2, 1],
threads_per_group: [8, 8, 1],
}
);
assert_eq!(mapped.imageblock, Some([16, 16]));
let pass = mapped.tile.as_ref().unwrap();
assert_eq!(pass.area, [40, 24]);
assert_eq!(pass.tiles, [48, 32]);
assert_eq!(
pass.formats(),
BTreeMap::from([(1, metal2vulkan::metal::PixelFormat::R32Uint)])
);
let attachment = &pass.attachments[&1];
assert_eq!(
(
attachment.texture_type,
attachment.dimensions,
attachment.sample_count
),
(crate::case::TextureType::D2, [40, 24, 1], 1)
);
assert_eq!(attachment.bytes, pixels);
// The executor's attachment over the whole tiles: the authored texels, and past them the
// nearest, clamped to their edge.
let tiled = &pass.tiled[&1];
assert_eq!(
(tiled.format, tiled.dimensions, tiled.sample_count),
(attachment.format, [48, 32, 1], 1)
);
let padded: Vec<u8> = (0..32usize)
.flat_map(|y| (0..48usize).map(move |x| (x.min(39), y.min(23))))
.flat_map(|(x, y)| {
let at = (y * 40 + x) * 4;
pixels[at..at + 4].to_vec()
})
.collect();
assert_eq!(tiled.bytes, padded);
assert_eq!(
mapped.output,
ComputeOutput::RenderTarget {
index: 1,
origin: [8, 2],
dimensions: [4, 3],
}
);
let state = bind_state(
&mapped,
&BTreeMap::new(),
&BTreeMap::new(),
BufferRanges::default(),
)
.unwrap();
assert_eq!(state.render_area, [48, 32]);
assert_eq!(
state.imageblock_size,
metal2vulkan::bind::ImageblockSize::new(16, 16)
);
let shape = state.shape();
assert_eq!(shape.render_area, [48, 32]);
let library = RowSource::Text(Cow::Borrowed(""));
let (request, _) = compute_request(&library, &[], &mapped, &shape);
match request {
PipelineRequest::BoundCompute {
tile, stage_input, ..
} => {
assert_eq!(tile, Some(pass.formats()));
assert_eq!(stage_input, None);
}
other => panic!("{other:?}"),
}
// The selected region, rows tightly packed (the oracle's `LiteralRenderTarget::select`).
let finals = BTreeMap::from([(1, attachment.clone())]);
let expected = crate::literal::LiteralRenderTarget {
index: 1,
format: TextureFormat::R32Uint,
dimensions: [40, 24],
samples: 1,
bytes: pixels.clone(),
}
.select([8, 2], [4, 3])
.unwrap();
assert_eq!(
select_output(
mapped.output,
&BTreeMap::new(),
&BTreeMap::new(),
&BTreeMap::new(),
&BTreeMap::new(),
&finals
),
Ok(expected)
);
// Render targets of a kernel with no implicit imageblock, and a tile grid of more than one
// plane, are not implemented.
let mut plain = case.clone();
plain.imageblock = None;
assert!(matches!(
map_kernel(&plain),
Err(NotSupported::NotImplemented(what)) if what.contains("no tile function")
));
let mut planes = case.clone();
planes.dispatch = Some(CaseDispatch {
grid: [40, 24, 2],
threads_per_threadgroup: [8, 8, 1],
stage_in_region: None,
});
assert!(matches!(
map_kernel(&planes),
Err(NotSupported::NotImplemented(what)) if what.contains("more than one plane")
));
// A render-target output of a kernel in no tile pass is not implemented.
let mut output = kernel_case();
output.output = case.output.clone();
assert!(matches!(
map_kernel(&output),
Err(NotSupported::NotImplemented(what)) if what.contains("no tile pass")
));
}
/// `bytes` as the base64 an authored case spells.
fn b64(bytes: &[u8]) -> String {
base64::engine::general_purpose::STANDARD.encode(bytes)
@@ -1759,51 +1357,6 @@ fn a_restricted_row_has_its_own_engine_slot() {
}
}
/// The checker accepts a committed public fragment case over an explicit imageblock with no
/// requirement that stops this executor, which prepares it device-free: the case's plane lands at
/// its master member's offset in the pass's one cell (`fragment_custom_imageblock`'s master holds
/// four halves, `user(depth)` the second), every other byte zero as the Metal oracle's initializer
/// leaves an unauthored member, and the output is that member's plane.
#[test]
fn a_checked_fragment_imageblock_case_maps_its_plane_onto_the_cells() {
use super::graphics::RenderOutput;
use super::imageblock::Member;
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let case = CorpusStore::new(&root)
.read_all_cases()
.unwrap()
.into_iter()
.find(|case| case.name == "fragment-custom-imageblock-depth")
.expect("the committed public case");
let device = DeviceType::Cpu;
let admitted = admit(&root, case, ExecutionRequest::EngineCandidate { device })
.unwrap_or_else(|error| panic!("{error}"));
assert_eq!(
crate::executor_contract::require_executor(
&admitted.checked().requirements(),
Executor::EngineCandidate
),
Ok(())
);
let prepared = prepare_case(device, admitted).unwrap_or_else(|error| panic!("{error}"));
let Mapped::Render(render) = &prepared.mapped else {
panic!("a fragment case maps onto a draw");
};
let cells = render.imageblock.as_ref().expect("the case's imageblock");
assert_eq!(cells.dimensions, [1, 1]);
assert_eq!(cells.cell_bytes, 8);
// The authored depth, half 1.099609375 (0x3c66), little-endian at byte 2.
assert_eq!(cells.bytes, [0, 0, 0x66, 0x3c, 0, 0, 0, 0]);
assert_eq!(
render.output,
RenderOutput::Imageblock {
member: Member { offset: 2, size: 2 },
origin: [0, 0],
dimensions: [1, 1],
}
);
}
/// The checker accepts the committed public cases over pipeline-state members (a kernel's and a
/// rasterization-disabled vertex function's), resolving their two templates, with no requirement
/// that stops this executor, which prepares each device-free: every authored pipeline state is its
@@ -747,9 +747,10 @@ fn a_fence_of_another_order_is_made_through_the_runtime() {
assert_eq!(output, expected);
}
/// `ToolingRequirement::TextureBufferMember`'s limit at the texture, both ways: the runtime makes
/// no texture buffer, so `new_texture` refuses one, typed (`Gap::TextureBuffer`), where it makes a
/// 2D texture of the same format and width. The day the runtime makes one, this fails.
/// `ToolingRequirement::TextureBuffer`'s limit, and `ToolingRequirement::TextureBufferMember`'s at
/// the texture, both ways: the runtime makes no texture buffer, so `new_texture` refuses one, typed
/// (`Gap::TextureBuffer`), where it makes a 2D texture of the same format and width. The day the
/// runtime makes one, this fails.
#[cfg(target_os = "linux")]
#[test]
fn a_texture_buffer_is_refused_where_a_2d_texture_is_made() {
@@ -772,65 +772,6 @@ fn a_rasterization_disabled_vertex_draw_stores_through_its_buffer() {
}
}
/// The narrow-attribute case with layouts of `MTLBufferLayoutStrideDynamic`, its buffers bound
/// at strides 2 and 8, drawn: vertex 1 reads each attribute one stride on, as Metal's fetch does,
/// where the pipeline's strides are dynamic state (`VERTEX_INPUT_BINDING_STRIDE`), which the
/// executor records as it binds the vertex buffers.
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[test]
fn dynamic_stride_layouts_read_at_the_strides_the_buffers_are_bound_with() {
let mut authored =
crate::case::narrow_vertex_test_case(String::new(), "vertex_narrow_attributes".into());
authored.buffers[0].initial_bytes_b64 = Some(b64(&[0xab; 8]));
let inputs: [(u32, &[u8]); 2] = [
(2, &[2, 9, 5, 9]),
(8, &[3, 0, 4, 0, 99, 0, 99, 0, 6, 0, 7, 0]),
];
for (input, (stride, bytes)) in authored.vertex_inputs.iter_mut().zip(inputs) {
input.stride = stride;
input.dynamic_stride = true;
input.bytes_b64 = b64(bytes);
}
authored.draw.as_mut().expect("a draw").vertex_count = 2;
authored.output = crate::case::OutputSelection::Buffer {
binding: 0,
offset: 0,
length: 8,
};
let case = render_case(
&authored,
&crate::check::interface::tests::vertex_buffers_at(&[0]),
WITHOUT_SLICE,
None,
None,
)
.unwrap();
assert!(case.vertex_buffers.iter().all(|buffer| buffer.dynamic));
let vertex = public("vertex_narrow_attributes.ll");
let ran = run(
&case,
RenderLibraries {
vertex: &vertex,
fragment: None,
},
);
let expected: Vec<u8> = [2u32 + 3 + 4, 5 + 6 + 7]
.iter()
.flat_map(|sum| sum.to_le_bytes())
.collect();
match ran {
Ok(run) => assert_eq!(run.output, expected),
// A profile without dynamic strides keeps a per-bind stride static, a pipeline per
// stride, which the executor does not create.
Err(ExecutorError::NotSupported(
crate::check::admission::NotSupported::NotImplemented(why),
)) if why.contains("a pipeline per stride") => {
eprintln!("dynamic stride layouts: {why}")
}
Err(other) => panic!("dynamic stride layouts: {other}"),
}
}
/// A fragment function that loops `n` times (`n` from its constant buffer) draws once, as
/// compiled, with no execution bound and no headroom probe, on both lanes.
#[cfg(any(target_os = "linux", target_os = "macos"))]
@@ -228,11 +228,15 @@ fn every_map_of_a_case_binds_the_products_compile() {
assert_eq!(skewed.compiled().unwrap(), rule);
}
/// A rate-mapped pass is no executor's gap: both executors render it.
/// A rate-mapped pass is the runtime's limit: the Metal oracle renders it, and the engine's
/// candidate alone stops.
#[test]
fn a_rate_mapped_pass_stops_no_executor() {
fn a_rate_mapped_pass_is_the_runtimes_limit() {
let mut case = fragment_case([37, 23]);
assert!(case_requirements(&case).is_empty());
case.render_pass_rate_map = Some(map([37, 23], &[1.0], &[1.0]));
assert!(case_requirements(&case).is_empty());
assert_eq!(
case_requirements(&case),
[crate::requirement::ToolingRequirement::RasterizationRateMap].into()
);
}
@@ -36,10 +36,10 @@ fn errors(case: &AuthoredCase) -> String {
.join("\n")
}
/// A sparse texture is part of the identity and no executor's gap; a texture without the field
/// serializes as before it existed.
/// A sparse texture is part of the identity and the runtime's limit, which stops the engine's
/// candidate alone; a texture without the field serializes as before it existed.
#[test]
fn a_sparse_texture_is_identity_and_stops_no_executor() {
fn a_sparse_texture_is_identity_and_the_runtimes_limit() {
let case = sparse_case(vec![region(0, 0, [0, 0, 0], [128, 128, 1])]);
assert_eq!(errors(&case), "");
let mut ordinary = case.clone();
@@ -50,7 +50,11 @@ fn a_sparse_texture_is_identity_and_stops_no_executor() {
unmapped.textures[0].sparse = Some(SparseTextureResource { mappings: vec![] });
assert_eq!(errors(&unmapped), "", "every texel may be unmapped");
assert_ne!(unmapped.computed_case_id().unwrap(), case.case_id);
assert!(crate::executor_contract::case_requirements(&case).is_empty());
assert_eq!(
crate::executor_contract::case_requirements(&case),
[crate::requirement::ToolingRequirement::SparseTexture].into()
);
assert!(crate::executor_contract::case_requirements(&ordinary).is_empty());
// The schema's spelling.
let json = serde_json::to_value(&case.textures[0]).unwrap();
assert_eq!(
@@ -22,7 +22,7 @@ use crate::air::reflect::{
use crate::case::out_of_bounds::OutOfBoundsResource;
use crate::case::{
AuthoredCase, DeviceBufferArrayResource, OutputSelection, Primitive, Stage, TextureFormat,
ThreadgroupMemoryResource,
TextureType, ThreadgroupMemoryResource,
};
use crate::requirement::{Executor, Limit, ToolingRequirement, UnobservedEffect};
use std::borrow::Cow;
@@ -745,16 +745,15 @@ pub fn unsupported_source_requirements(
///
/// A post-tessellation vertex function is none of them: the candidate draws its patches as the
/// oracle does (`tessellation`); nor is a fragment function's color input, whose render target the
/// candidate attaches as the input attachment the plan reads, nor its explicit imageblock, whose
/// cells the candidate holds as the oracle's initializer defines them and whose reads and writes
/// the product refuses (`Feature::Imageblocks`), the case's answer; nor is an argument-buffer member holding a compute or render
/// pipeline state, which the candidate writes into its owner as an opaque id that no translated
/// pipeline reads; nor a kernel's implicit imageblock attachments, which the candidate runs as the
/// oracle's tile pipeline over the render area's tiles. The engine's other gaps are a case's
/// choice, not the source's ([`case_requirements`]): an argument-buffer intersection-function table
/// (the checker does not require one), a linked intersection function (the case's acceleration
/// structures are opaque triangles, which call none), and a vertex case's depth/stencil
/// attachment or a rasterization-disabled vertex case's render targets.
/// candidate attaches as the input attachment the plan reads; nor is an argument-buffer member
/// holding a compute or render pipeline state, which the candidate writes into its owner as an
/// opaque id that no translated pipeline reads. The engine's other gaps are a case's choice, not
/// the source's ([`case_requirements`]): an argument-buffer intersection-function table (the
/// 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.
pub fn engine_source_requirements(reflection: &ShaderInterface) -> BTreeSet<ToolingRequirement> {
let render = matches!(
reflection.stage,
@@ -808,9 +807,14 @@ pub fn engine_source_requirements(reflection: &ShaderInterface) -> BTreeSet<Tool
/// case gives a depth image is the runtime's limit on every device
/// ([`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`]).
/// 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 function
/// table, explicit imageblock, acceleration structure or stage inputs, a bound texture buffer or
/// sparse texture, a fragment function's imageblock, a rasterization-rate map, and a vertex
/// buffer's dynamic stride.
pub fn case_requirements(case: &AuthoredCase) -> BTreeSet<ToolingRequirement> {
let render = matches!(case.stage, Stage::Vertex | Stage::Fragment);
let kernel = case.stage == Stage::Kernel;
let drawn = render || case.stage.is_mesh_pipeline_stage();
let linked = |entries: &[crate::case::IntersectionFunctionTableEntry]| {
entries.iter().any(|entry| {
@@ -874,6 +878,59 @@ pub fn case_requirements(case: &AuthoredCase) -> BTreeSet<ToolingRequirement> {
}),
ToolingRequirement::SeparateDepthStencil,
),
(
kernel && !case.visible_function_tables.is_empty(),
ToolingRequirement::KernelFunctionTable,
),
(
kernel && case.imageblock.is_some(),
ToolingRequirement::KernelImageblock,
),
(
case.textures
.iter()
.any(|texture| texture.texture_type == TextureType::Buffer),
ToolingRequirement::TextureBuffer,
),
(
case.fragment_imageblock.is_some(),
ToolingRequirement::FragmentImageblock,
),
(
case.textures.iter().any(|texture| texture.sparse.is_some()),
ToolingRequirement::SparseTexture,
),
(
kernel
&& (!case.acceleration_structures.is_empty()
|| !case.intersection_function_tables.is_empty()),
ToolingRequirement::KernelAccelerationStructure,
),
(
kernel
&& (!case.kernel_stage_inputs.is_empty()
|| case
.dispatch
.as_ref()
.is_some_and(|dispatch| dispatch.stage_in_region.is_some())),
ToolingRequirement::KernelStageInput,
),
(
case.render_pass_rate_map.is_some()
|| case
.buffers
.iter()
.any(|buffer| buffer.rasterization_rate_map.is_some())
|| case
.argument_buffer_buffers
.iter()
.any(|buffer| buffer.rasterization_rate_map.is_some()),
ToolingRequirement::RasterizationRateMap,
),
(
case.vertex_inputs.iter().any(|input| input.dynamic_stride),
ToolingRequirement::DynamicVertexStride,
),
]
.into_iter()
.filter_map(|(present, requirement)| present.then_some(requirement))
@@ -2846,44 +2903,16 @@ entry:
// A pipeline-state literal is an opaque id in its owner.
assert!(case_requirements(&pipelines).is_empty());
// A kernel's imageblock, a tile function's implicit one or an explicit one, is the
// runtime's limit.
let mut tile = kernel.clone();
tile.imageblock = Some(ImageblockResource {
dimensions: [1, 1],
implicit_coverage: Some(ImplicitImageblockCoverage::FullSingleSample),
});
// The candidate runs a tile function over any grid of tiles: one tile of one thread per
// cell, a render area of more than one tile, a threadgroup that is not the tile's, or a
// tile past 2x2.
for (dimensions, grid, threads) in [
([1, 1], [1, 1, 1], [1, 1, 1]),
([2, 2], [2, 2, 1], [2, 2, 1]),
([1, 1], [2, 1, 1], [1, 1, 1]),
([1, 1], [1, 1, 1], [2, 1, 1]),
([1, 1], [1, 1, 2], [1, 1, 1]),
([1, 2], [1, 2, 1], [1, 2, 1]),
([4, 4], [4, 4, 1], [4, 4, 1]),
([16, 16], [16, 16, 1], [16, 16, 1]),
] {
let mut grid_case = tile.clone();
grid_case.imageblock.as_mut().unwrap().dimensions = dimensions;
grid_case.dispatch = Some(Dispatch {
grid,
threads_per_threadgroup: threads,
stage_in_region: None,
});
assert!(
case_requirements(&grid_case).is_empty(),
"{dimensions:?} {grid:?} {threads:?}"
);
}
// An explicit imageblock is no tile function.
only(&tile, ToolingRequirement::KernelImageblock);
tile.imageblock.as_mut().unwrap().implicit_coverage = None;
tile.dispatch = Some(Dispatch {
grid: [2, 1, 1],
threads_per_threadgroup: [1, 1, 1],
stage_in_region: None,
});
assert!(case_requirements(&tile).is_empty());
only(&tile, ToolingRequirement::KernelImageblock);
let opaque = IntersectionFunctionTableEntry::OpaqueTriangle {
index: 0,
@@ -2919,23 +2948,29 @@ entry:
primitive_triangles_b64: None,
child_references: vec![0],
}];
assert!(case_requirements(&traced).is_empty());
only(&traced, ToolingRequirement::KernelAccelerationStructure);
let mut linking = traced.clone();
linking.intersection_function_tables = vec![table(linked)];
only(&linking, ToolingRequirement::LinkedIntersectionFunction);
assert_eq!(
case_requirements(&linking),
BTreeSet::from([
ToolingRequirement::LinkedIntersectionFunction,
ToolingRequirement::KernelAccelerationStructure
])
);
let mut fragment = traced.clone();
fragment.stage = Stage::Fragment;
only(&fragment, ToolingRequirement::RenderAccelerationStructure);
// A function table: a kernel's runs; a vertex or fragment function's is the runtime's
// limit.
// A function table is the runtime's limit, a kernel's and a vertex or fragment
// function's each by its own name.
let mut tabled = kernel.clone();
tabled.visible_function_tables = vec![crate::case::FunctionTableResource {
binding: 1,
size: 1,
entries: Vec::new(),
}];
assert!(case_requirements(&tabled).is_empty());
only(&tabled, ToolingRequirement::KernelFunctionTable);
for stage in [Stage::Vertex, Stage::Fragment] {
let mut drawn = tabled.clone();
drawn.stage = stage;
@@ -3008,6 +3043,87 @@ entry:
attachment.initial_stencil_b64 = Some("qw==".into());
}
only(&aspects, ToolingRequirement::SeparateDepthStencil);
// What the runtime builds no call for, or refuses at creation: a bound texture buffer or
// sparse texture, a kernel's stage inputs or stage-in region, a vertex buffer's dynamic
// stride, a fragment function's imageblock and a rasterization-rate map.
let texture = |texture_type| TextureResource {
binding: 0,
role: ResourceRole::Input,
texture_type,
format: TextureFormat::Rgba32Float,
dimensions: [1, 1, 1],
sample_count: 1,
bytes_b64: Some("AAAAAAAAAAAAAAAAAAAAAA==".into()),
initial_bytes_b64: None,
sparse: None,
mip_levels: 1,
};
let mut textured = kernel.clone();
textured.textures = vec![texture(TextureType::D2)];
assert!(case_requirements(&textured).is_empty());
textured.textures = vec![texture(TextureType::Buffer)];
only(&textured, ToolingRequirement::TextureBuffer);
textured.textures = vec![TextureResource {
sparse: Some(crate::case::sparse::SparseTextureResource {
mappings: Vec::new(),
}),
..texture(TextureType::D2)
}];
only(&textured, ToolingRequirement::SparseTexture);
let input = |dynamic_stride| crate::case::AttributeInput {
location: 0,
format: crate::case::AttributeFormat::Float,
stride: 4,
dynamic_stride,
bytes_b64: "AAAAAA==".into(),
};
let mut staged = kernel.clone();
staged.kernel_stage_inputs = vec![input(false)];
only(&staged, ToolingRequirement::KernelStageInput);
let mut region = kernel.clone();
region.dispatch = Some(Dispatch {
grid: [1, 1, 1],
threads_per_threadgroup: [1, 1, 1],
stage_in_region: Some(crate::case::indirect_commands::HostStageInRegion {
origin: [0, 0, 0],
size: [1, 1, 1],
}),
});
only(&region, ToolingRequirement::KernelStageInput);
let mut fetched = kernel.clone();
fetched.stage = Stage::Vertex;
fetched.vertex_observation = Some(VertexObservation::Position);
fetched.vertex_inputs = vec![input(false)];
assert!(case_requirements(&fetched).is_empty());
fetched.vertex_inputs = vec![input(true)];
only(&fetched, ToolingRequirement::DynamicVertexStride);
let mut blocked = kernel.clone();
blocked.stage = Stage::Fragment;
blocked.fragment_imageblock = Some(FragmentImageblockResource {
dimensions: [1, 1],
members: Vec::new(),
});
only(&blocked, ToolingRequirement::FragmentImageblock);
let map = crate::case::RateMapLiteral {
screen_size: [1, 1],
layers: vec![crate::case::RateMapLayerLiteral {
horizontal: vec![crate::case::RateSample(1.0)],
vertical: vec![crate::case::RateSample(1.0)],
}],
};
let mut mapped = kernel.clone();
mapped.stage = Stage::Fragment;
mapped.render_pass_rate_map = Some(map.clone());
only(&mapped, ToolingRequirement::RasterizationRateMap);
let mut mapped = kernel.clone();
mapped.buffers = vec![BufferResource {
binding: 0,
role: ResourceRole::Input,
bytes_b64: None,
initial_bytes_b64: None,
rasterization_rate_map: Some(map),
}];
only(&mapped, ToolingRequirement::RasterizationRateMap);
let mut disabled = kernel.clone();
disabled.stage = Stage::Vertex;
disabled.render_targets.push(RenderTargetResource {
+146 -38
View File
@@ -221,6 +221,55 @@ pub enum ToolingRequirement {
/// structure, so no census row carries it. The Metal oracle draws it, so a case of it stays
/// Metal-qualified ([`Self::qualifies_on_metal`]).
SeparateDepthStencil,
/// A visible function table bound to a compute kernel (`executor_contract::case_requirements`;
/// a render function's is [`Self::RenderFunctionTable`]). The runtime's compute encoder has no
/// `setVisibleFunctionTable:atBufferIndex:`, and its make of a pipeline state that reads a
/// table is `metal2vulkan_runtime::Gap::KernelInput` of `KernelInputKind::Slot`, a known gap
/// its README states, held on lavapipe by the runtime's device test
/// `tests::kernel_input::a_visible_function_table_kernel_is_refused_as_a_slot`.
KernelFunctionTable,
/// A compute kernel's explicit imageblock (`executor_contract::case_requirements`), a tile
/// pass's tile size included. The runtime's compute encoder has no
/// `setImageblockWidth:height:`, and its make of a pipeline state that reaches an imageblock is
/// `metal2vulkan_runtime::Gap::KernelInput` of `KernelInputKind::RuntimeFact` naming
/// `ImageblockSize`, held on lavapipe by the runtime's device test
/// `tests::kernel_input::an_explicit_imageblock_kernel_is_refused_as_its_named_runtime_fact`;
/// it builds no tile function. Both are known gaps its README states.
KernelImageblock,
/// A texture buffer a case binds to an entry parameter (`executor_contract::case_requirements`;
/// one an argument buffer holds is [`Self::TextureBufferMember`]). The runtime makes no texture
/// buffer (`metal2vulkan_runtime::Gap::TextureBuffer` at `new_texture`), a known gap its README
/// states, held both ways on lavapipe by the device test
/// `candidate::tests::engine_compute::a_texture_buffer_is_refused_where_a_2d_texture_is_made`.
TextureBuffer,
/// A fragment function's imageblock, the case's cells of it
/// (`executor_contract::case_requirements`). The runtime refuses a fragment function with an
/// `[[imageblock_data]]` input or output at creation on every device (`Error::Translation`
/// naming `Imageblocks`, `NotImplemented`), a known gap its README states, which is its guard.
FragmentImageblock,
/// A sparse texture a case binds (`executor_contract::case_requirements`). The runtime makes
/// no sparse texture: its texture descriptor has no sparse form, so no call of it makes one.
SparseTexture,
/// An acceleration structure or an intersection-function table bound to a compute kernel
/// (`executor_contract::case_requirements`; a render function's is
/// [`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's make of a pipeline state that
/// fetches stage inputs is `metal2vulkan_runtime::Gap::KernelInput` of
/// `KernelInputKind::StageIn`, a known gap its README states, held on lavapipe by the runtime's
/// device test `tests::kernel_input::a_stage_in_kernel_is_refused_as_stage_in`.
KernelStageInput,
/// 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.
RasterizationRateMap,
/// A vertex buffer bound at the stride its draw sets, a dynamic layout stride
/// (`executor_contract::case_requirements`). The runtime's render encoder does not build
/// `setVertexBuffer:offset:attributeStride:atIndex:`, a known gap its README states, which is
/// its guard.
DynamicVertexStride,
}
/// Every executor (the requirement leaves no case to author, or none to observe).
@@ -228,7 +277,7 @@ const AUTHORING: &[Executor] = &Executor::ALL;
const ENGINE: &[Executor] = &[Executor::EngineCandidate];
impl ToolingRequirement {
pub const ALL: [Self; 30] = [
pub const ALL: [Self; 39] = [
Self::FunctionConstantLiteral,
Self::VertexAttributeLiteral,
Self::TessellationAttributeLiteral,
@@ -259,6 +308,15 @@ impl ToolingRequirement {
Self::IndexBufferPastEnd,
Self::UlongTextureAtomic,
Self::SeparateDepthStencil,
Self::KernelFunctionTable,
Self::KernelImageblock,
Self::TextureBuffer,
Self::FragmentImageblock,
Self::SparseTexture,
Self::KernelAccelerationStructure,
Self::KernelStageInput,
Self::RasterizationRateMap,
Self::DynamicVertexStride,
];
pub const fn as_str(self) -> &'static str {
@@ -295,6 +353,15 @@ impl ToolingRequirement {
Self::IndexBufferPastEnd => "index_buffer_past_end",
Self::UlongTextureAtomic => "ulong_texture_atomic",
Self::SeparateDepthStencil => "separate_depth_stencil",
Self::KernelFunctionTable => "kernel_function_table",
Self::KernelImageblock => "kernel_imageblock",
Self::TextureBuffer => "texture_buffer",
Self::FragmentImageblock => "fragment_imageblock",
Self::SparseTexture => "sparse_texture",
Self::KernelAccelerationStructure => "kernel_acceleration_structure",
Self::KernelStageInput => "kernel_stage_input",
Self::RasterizationRateMap => "rasterization_rate_map",
Self::DynamicVertexStride => "dynamic_vertex_stride",
}
}
@@ -354,30 +421,26 @@ impl ToolingRequirement {
| Self::RenderFunctionTable
| Self::IndexBufferPastEnd
| Self::UlongTextureAtomic
| Self::SeparateDepthStencil => ENGINE,
| Self::SeparateDepthStencil
| Self::KernelFunctionTable
| Self::KernelImageblock
| Self::TextureBuffer
| Self::FragmentImageblock
| Self::SparseTexture
| Self::KernelAccelerationStructure
| Self::KernelStageInput
| Self::RasterizationRateMap
| Self::DynamicVertexStride => ENGINE,
}
}
/// Whether a case carrying this requirement is still a case to keep: the Metal oracle runs it
/// and its observation is evidence for a candidate that runs the family again, so the checker
/// accepts it with no candidate (`executor_contract::evidence_gap`), and the engine's candidate
/// refuses it, typed. Only [`ToolingRequirement::MeshRenderPipeline`],
/// [`ToolingRequirement::TextureBufferMember`], [`ToolingRequirement::DepthOutsideUnitRange`],
/// [`ToolingRequirement::SeqCstFence`], [`ToolingRequirement::RenderFunctionTable`] and
/// [`ToolingRequirement::IndexBufferPastEnd`], [`ToolingRequirement::UlongTextureAtomic`] and
/// [`ToolingRequirement::SeparateDepthStencil`]: their cases are qualified on Metal.
/// refuses it, typed. Exactly the runtime's limits ([`Limit::Runtime`]): their cases are
/// qualified on Metal.
pub const fn qualifies_on_metal(self) -> bool {
matches!(
self,
Self::MeshRenderPipeline
| Self::TextureBufferMember
| Self::DepthOutsideUnitRange
| Self::SeqCstFence
| Self::RenderFunctionTable
| Self::IndexBufferPastEnd
| Self::UlongTextureAtomic
| Self::SeparateDepthStencil
)
matches!(self.limit(), Limit::Runtime)
}
/// Whose limit this requirement records. Every requirement is this crate's tooling's except
@@ -385,8 +448,12 @@ impl ToolingRequirement {
/// for, and [`ToolingRequirement::SeqCstFence`], [`ToolingRequirement::TextureBufferMember`],
/// [`ToolingRequirement::DepthOutsideUnitRange`], [`ToolingRequirement::MeshRenderPipeline`],
/// [`ToolingRequirement::RenderFunctionTable`], [`ToolingRequirement::IndexBufferPastEnd`],
/// [`ToolingRequirement::UlongTextureAtomic`] and [`ToolingRequirement::SeparateDepthStencil`],
/// which the runtime refuses.
/// [`ToolingRequirement::UlongTextureAtomic`], [`ToolingRequirement::SeparateDepthStencil`],
/// [`ToolingRequirement::KernelFunctionTable`], [`ToolingRequirement::KernelImageblock`],
/// [`ToolingRequirement::TextureBuffer`], [`ToolingRequirement::FragmentImageblock`],
/// [`ToolingRequirement::SparseTexture`], [`ToolingRequirement::KernelAccelerationStructure`],
/// [`ToolingRequirement::KernelStageInput`], [`ToolingRequirement::RasterizationRateMap`] and
/// [`ToolingRequirement::DynamicVertexStride`], which the runtime refuses or does not build.
pub const fn limit(self) -> Limit {
match self {
Self::KernelMinLodClamp => Limit::Metal,
@@ -397,7 +464,16 @@ impl ToolingRequirement {
| Self::RenderFunctionTable
| Self::IndexBufferPastEnd
| Self::UlongTextureAtomic
| Self::SeparateDepthStencil => Limit::Runtime,
| Self::SeparateDepthStencil
| Self::KernelFunctionTable
| Self::KernelImageblock
| Self::TextureBuffer
| Self::FragmentImageblock
| Self::SparseTexture
| Self::KernelAccelerationStructure
| Self::KernelStageInput
| Self::RasterizationRateMap
| Self::DynamicVertexStride => Limit::Runtime,
_ => Limit::Tooling,
}
}
@@ -540,22 +616,6 @@ mod tests {
assert_eq!(requirement.limit(), Limit::Runtime, "{requirement}");
assert!(!requirement.blocks_closure(), "{requirement}");
assert!(requirement.qualifies_on_metal(), "{requirement}");
assert_eq!(
ToolingRequirement::ALL
.into_iter()
.filter(|requirement| requirement.qualifies_on_metal())
.collect::<Vec<_>>(),
[
ToolingRequirement::TextureBufferMember,
ToolingRequirement::DepthOutsideUnitRange,
ToolingRequirement::MeshRenderPipeline,
ToolingRequirement::SeqCstFence,
ToolingRequirement::RenderFunctionTable,
ToolingRequirement::IndexBufferPastEnd,
ToolingRequirement::UlongTextureAtomic,
ToolingRequirement::SeparateDepthStencil
]
);
}
/// A texture buffer an argument buffer or a texture-handle array holds: a case expresses it
@@ -638,6 +698,45 @@ mod tests {
assert_eq!("separate_depth_stencil".parse(), Ok(requirement));
}
/// The families the runtime builds no call for, or refuses at creation on every device: the
/// Metal oracle runs each, so its cases stay Metal-qualified; the engine's candidate runs none,
/// the runtime's limit, which closes their rows.
#[test]
fn what_the_runtime_does_not_build_stops_only_the_candidate() {
for (requirement, name) in [
(
ToolingRequirement::KernelFunctionTable,
"kernel_function_table",
),
(ToolingRequirement::KernelImageblock, "kernel_imageblock"),
(ToolingRequirement::TextureBuffer, "texture_buffer"),
(
ToolingRequirement::FragmentImageblock,
"fragment_imageblock",
),
(ToolingRequirement::SparseTexture, "sparse_texture"),
(
ToolingRequirement::KernelAccelerationStructure,
"kernel_acceleration_structure",
),
(ToolingRequirement::KernelStageInput, "kernel_stage_input"),
(
ToolingRequirement::RasterizationRateMap,
"rasterization_rate_map",
),
(
ToolingRequirement::DynamicVertexStride,
"dynamic_vertex_stride",
),
] {
assert_eq!(requirement.stops(), [Executor::EngineCandidate]);
assert_eq!(requirement.limit(), Limit::Runtime, "{requirement}");
assert!(!requirement.blocks_closure(), "{requirement}");
assert!(requirement.qualifies_on_metal(), "{requirement}");
assert_eq!(name.parse(), Ok(requirement));
}
}
/// Every requirement stops some executor, and an executor's name is as stable as a
/// requirement's. A requirement that stops the Metal oracle stops every executor: when Metal
/// cannot run a case, no candidate has an observation to be compared with. Only a tooling gap
@@ -689,7 +788,16 @@ mod tests {
ToolingRequirement::RenderFunctionTable,
ToolingRequirement::IndexBufferPastEnd,
ToolingRequirement::UlongTextureAtomic,
ToolingRequirement::SeparateDepthStencil
ToolingRequirement::SeparateDepthStencil,
ToolingRequirement::KernelFunctionTable,
ToolingRequirement::KernelImageblock,
ToolingRequirement::TextureBuffer,
ToolingRequirement::FragmentImageblock,
ToolingRequirement::SparseTexture,
ToolingRequirement::KernelAccelerationStructure,
ToolingRequirement::KernelStageInput,
ToolingRequirement::RasterizationRateMap,
ToolingRequirement::DynamicVertexStride,
]
);
for executor in Executor::ALL {
@@ -14,9 +14,8 @@ fn serving() -> PathBuf {
bin_exe!("corpus-vulkan")
}
/// A public authored case (`primitive-acceleration-structure-intersection`), whose AIR the
/// public fixtures give.
const CASE: &str = r#"{"acceleration_structures":[{"binding":5,"kind":"primitive","primitive_triangles_b64":"AACAvwAAgL8AAAAAAACAPwAAgL8AAAAAAAAAAAAAgD8AAAAA"}],"air_sha256":"3dec51430c72d7901180dcdc22624a135640bf74af06c3a59b100b048a4107c6","argument_buffer_buffers":[],"argument_buffer_intersection_function_tables":[],"argument_buffer_textures":[],"authored_by":"codex:gpt-5.6-sol","buffers":[{"binding":0,"initial_bytes_b64":"q6urq6urq6urq6urq6urq6urq6urq6ur","role":"output"}],"case_id":"21de8b823123dfcac765adf9786fbb1f0741b4543d307064df6832313eb6b575","compare":{"kind":"exact"},"device_buffer_arrays":[],"dispatch":{"grid":[1,1,1],"threads_per_threadgroup":[1,1,1]},"entry":"primitive_as_intersect","execution_safety":"loop_free","function_constants":[],"intersection_function_tables":[],"kernel_stage_inputs":[],"name":"primitive-acceleration-structure-intersection","output":{"binding":0,"kind":"buffer","length":24,"offset":0},"rationale":"A downward ray hits one authored counter-clockwise triangle at unit distance; all observable triangle-intersection result fields are compared exactly.","render_targets":[],"samplers":[],"stage":"kernel","texture_arrays":[],"textures":[],"threadgroup_memory":[],"vertex_inputs":[],"visible_function_references":[],"visible_function_tables":[]}"#;
/// A public authored case (`single-thread-store-constant`), whose AIR the public fixtures give.
const CASE: &str = r#"{"acceleration_structures":[],"air_sha256":"dc4e4be315732ae7ea24fe171945c4c25b42ca65e10f83530eed6cc95f80b50b","argument_buffer_buffers":[],"argument_buffer_intersection_function_tables":[],"argument_buffer_textures":[],"authored_by":"metal2vulkan project","buffers":[{"binding":0,"initial_bytes_b64":"q6urqw==","role":"output"}],"case_id":"1e54315eb0ffcac633d4992c577f3e6ac384ed1bdf2321887c1f37242c00c887","compare":{"kind":"exact"},"device_buffer_arrays":[],"dispatch":{"grid":[1,1,1],"threads_per_threadgroup":[1,1,1]},"entry":"store_const","execution_safety":"loop_free","function_constants":[],"intersection_function_tables":[],"kernel_stage_inputs":[],"name":"single-thread-store-constant","output":{"binding":0,"kind":"buffer","length":4,"offset":0},"public_source":"crates/metal2vulkan-validation/fixtures/public/kernel_store_const.ll","rationale":"A single invocation writes the integer constant 42 into one explicitly poisoned output word.","render_targets":[],"samplers":[],"stage":"kernel","texture_arrays":[],"textures":[],"threadgroup_memory":[],"vertex_inputs":[],"visible_function_references":[],"visible_function_tables":[]}"#;
/// The worker input for [`CASE`] restricted to `restricted_to`, with `VK_EXT_device_generated_commands` enabled where supported or not (`generated_commands`),
/// claiming a checked-input digest the case does not have.
@@ -178,158 +178,3 @@ fn a_case_with_visible_function_references_compiles_linked_through_the_worker()
}
}
}
/// A case with a visible-function table over the public table caller
/// (`engine/visible_table_caller`, entry `tid % size` of the table at buffer 1) passes the
/// executor's device-free checks, and its kernel, linked with the table's functions, compiles
/// through a real compile worker, which returns the product's handles of those functions with
/// the pipeline: the table's buffer is the product's table words, bound at the table's index in
/// the shape the pipeline was compiled for. No device is opened. Under the resident-table
/// domains, the executor's own context's, which runs visible-function tables.
#[test]
fn a_case_with_a_visible_function_table_binds_the_products_table_words() {
use metal2vulkan::bind::BoundBuffer;
use metal2vulkan::pipeline::Stage;
use metal2vulkan_validation::candidate::engine::bind_state;
let (Some((caller_ll, caller)), Some((functions_ll, functions))) = (
fixture("visible_table_caller"),
fixture("visible_table_functions"),
) else {
return;
};
let scratch = ScratchDir::new("engine-table-case").unwrap();
let root = scratch.path();
let library = "55".repeat(32);
// The caller declares two kernels, so the case is over its public entry row, which the checkout
// supplies: the scratch corpus holds only the harvested module it links.
let caller_sha256 = sha256_bytes(caller_ll.as_bytes());
let functions_module = LibraryModuleRow {
module_sha256: sha256_bytes(functions_ll.as_bytes()),
air_ll: functions_ll.clone(),
blob_b64: b64(&functions),
lib_sha256s: vec![library.clone()],
label: "test/visible_table_functions.air".into(),
};
merge_library_module_shards(root, [functions_module.clone()]).unwrap();
let module = functions_module.module_sha256.clone();
let threads = 10u32;
let bytes = vec![0u8; 4 * threads as usize];
// `table_add`, `table_mul`, a null entry, `table_sub`, and `table_half` (another type).
let entry = |index: u32, function: &str| serde_json::json!({"index": index, "module_sha256": module, "function": function});
let mut case: AuthoredCase = serde_json::from_value(serde_json::json!({
"air_sha256": caller_sha256,
"case_id": "pending",
"name": "visible-table-dispatch",
"entry": "visible_table_dispatch",
"stage": "kernel",
"buffers": [
{"binding": 0, "role": "output", "initial_bytes_b64": b64(&bytes)},
],
// The module's other kernel references these two directly; this entry calls them
// through the table. Linking takes each once.
"visible_function_references": [
{"module_sha256": module, "function": "table_add"},
{"module_sha256": module, "function": "table_mul"},
],
"visible_function_tables": [{
"binding": 1,
"size": 5,
"entries": [
entry(0, "table_add"),
entry(1, "table_mul"),
entry(3, "table_sub"),
entry(4, "table_half"),
],
}],
"dispatch": {"grid": [threads, 1, 1], "threads_per_threadgroup": [threads, 1, 1]},
"output": {"kind": "buffer", "binding": 0, "offset": 0, "length": bytes.len()},
"compare": {"kind": "exact"},
"execution_safety": "loop_free",
}))
.unwrap();
case.case_id = case.computed_case_id().unwrap();
let admitted = admit(
root,
case,
ExecutionRequest::EngineCandidate {
device: DeviceType::Gpu,
},
)
.unwrap_or_else(|error| panic!("admission: {error}"));
let checked = admitted.checked();
let compute = compute_case(&checked.primary.case, &checked.primary.interface).unwrap();
assert_eq!(compute.function_tables[&1].size, 5);
// The referenced functions, then the table's others in entry order, from their one module.
let linked = linked_modules(&checked.primary.linked_functions).unwrap();
assert_eq!(
linked,
[LinkedModule {
module_sha256: module.clone(),
bitcode: functions.clone(),
library: LinkedLibrary {
functions: ["table_add", "table_mul", "table_sub", "table_half"]
.map(str::to_owned)
.to_vec(),
},
}]
);
if let Err(error) = prepare_case(DeviceType::Gpu, admitted) {
panic!("the executor's device-free checks refused the table case: {error}");
}
let worker = worker();
for stem in ["moltenvk-m3", "runtime-floor", "lavapipe"] {
let device = WorkerDevice::new(
load_description(stem).unwrap(),
DevicePolicy::RESIDENT_TABLES,
)
.unwrap();
let profile = device.device().profile();
let addressed = profile.descriptors().buffer_device_address;
let shape = compute_shape(&compute, addressed, BufferRanges::of(profile.limits())).unwrap();
let compiled = compile_case(
&worker,
&device,
&retained(&caller),
&linked,
&compute,
&shape,
)
.unwrap_or_else(|error| panic!("{stem}: {error}"));
// Bound, size 5, then each entry's handle: the linked `functions` from 2, null at 2.
let words = compiled.tables[&(Stage::Kernel, 1)]
.as_chunks::<4>()
.0
.iter()
.map(|word| u32::from_le_bytes(*word))
.collect::<Vec<_>>();
assert_eq!(words, [1, 5, 2, 3, 0, 4, 5], "{stem}");
assert_eq!(compiled.tables.len(), 1, "{stem}");
// The table is a buffer of its words' length at its index, in the compiled-for shape.
let state = bind_state(
&compute,
&Default::default(),
&Default::default(),
BufferRanges::default(),
)
.unwrap();
match state.stages[&Stage::Kernel].buffers.get(&1) {
Some(BoundBuffer::Buffer { length, .. }) => assert_eq!(*length, 28, "{stem}"),
other => panic!("{stem}: {other:?}"),
}
let pipeline = compiled.pipeline;
match check_words_l3(&pipeline.stage.spirv, &pipeline.requirements, profile) {
Ok(()) => {}
Err(L3Failure::Tooling(why)) => eprintln!("SKIPPED spirv-val on {stem}: {why}"),
Err(failure) => panic!("{stem}: {failure}"),
}
// The plan of the executor's shape binds a buffer at the table's index.
let plan = pipeline.plan(device.device(), &shape).unwrap();
assert!(
plan.diagnostics.is_empty(),
"{stem}: {:?}",
plan.diagnostics
);
}
}
+12 -6
View File
@@ -478,8 +478,13 @@ cargo run -p metal2vulkan-validation --release --bin corpus-vulkan -- \
filled by a draw per slice of the owned `sample_fill` pair, its fragment run once per sample
writing that sample's texel from a buffer, a color one through an unsigned-integer view of its
texel size so its bits cross unconverted, a depth one under an always-passing depth test that
writes. A sparse, texture-buffer or cube-array texture keeps the case on the executor's own
context. A pixel format the runtime makes no image of on the device records `not_enabled`, as
writes. A cube-array texture keeps the case on the executor's own context. A bound sparse
texture carries `sparse_texture` and a bound texture buffer `texture_buffer`, which the runtime
makes neither of; a kernel's function table carries `kernel_function_table`, its imageblock (a
tile function's included) `kernel_imageblock`, its 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. A pixel format the runtime makes no image of on the device records `not_enabled`, as
the executor's own context records a format its query lacks. A vertex or fragment case of any
sample count draws through the runtime the same way (`engine::runs_render_through_runtime`): its own
stage's buffers, bound textures and samplers, function constants and linked functions, its
@@ -500,10 +505,11 @@ cargo run -p metal2vulkan-validation --release --bin corpus-vulkan -- \
runtime device's own translator: the runtime's floor enables no buffer robustness, so a
fixed-function vertex fetch past its buffer is checked nowhere and the case is refused as
`not_supported{uncontained:unchecked vertex_input}`. A rasterization-disabled vertex case renders
into the oracle's 1x1 `R8Unorm` attachment. Layered rendering, a dynamic vertex
stride, an argument-buffer member, a patch index buffer, an imageblock, a rasterization-rate map, an
out-of-bounds target other than an attribute buffer or a fragment pass with no attachment (the
runtime makes no pass without one) keeps the case on the executor's own context. An indexed
into the oracle's 1x1 `R8Unorm` attachment. Layered rendering, an argument-buffer member, a
patch index buffer, an out-of-bounds target other than an attribute buffer or a fragment pass
with no attachment (the runtime makes no pass without one) keeps the case on the executor's own
context. A vertex buffer's dynamic stride carries `dynamic_vertex_stride` and a fragment
function's imageblock `fragment_imageblock`, each the runtime's limit. An indexed
draw past its index buffer, which the runtime refuses as Metal's validation does
(`Refusal::IndexBufferOffset`), carries `index_buffer_past_end`, and a depth/stencil attachment
of both aspects, the oracle's two textures, which the runtime renders into in no one pass yet