Files
metal2vulkan/crates/metal2vulkan-validation/tests/integration/engine_linked_cases.rs
T
Anees Iqbal e6e70666ed Validation: delete the own-context arms of the nine refused families
What: since the refusal rows (d1266e5a5a, a1a47cb9c5), compute_case and render_case refuse a
case of kernel_function_table, kernel_imageblock, texture_buffer, fragment_imageblock,
sparse_texture, kernel_acceleration_structure, kernel_stage_input, rasterization_rate_map or
dynamic_vertex_stride before anything maps it. The executor's own-context code for these
families is reached by no case, so it goes:
- function tables: engine/tables.rs, ComputeCase.function_tables, StageResources.function_tables,
  CompiledCase (the compile functions now return the pipeline), CompileFailure::Tables,
  VariantRequest, the table allocations of compute_shape, and the tables hash of
  CaseArtifact::record;
- imageblocks and tile functions: engine/imageblock.rs, ComputeCase.imageblock,
  RenderCase.imageblock, RenderOutput::Imageblock, RenderFinals.imageblock,
  variants::compile_tile_for_shape, and the tile attachments of plan_resources;
- texture buffers: texel_guard_reach, buffer_target, the texel-buffer views and guards of
  plan_resources, and texel_buffer_bytes;
- sparse textures: platform/sparse_images.rs, device::SparseImages, the sparse paths of
  create_slot_image, the tile-map emulation of executor_contract::sparse, and the executor's
  sparseBinding, sparseResidencyImage2D and sparseResidencyImage3D enables (ExecutorFeature);
- acceleration structures: platform/acceleration.rs and their plan_resources arms;
- kernel stage inputs: the stage-input fetch, stage_in_region and Fetch::of_stage_input;
- rate maps: rate_map_regions, rate_map_pass_census and the per-region draw (a draw now covers the
  whole target in one recording);
- dynamic vertex strides: VertexBuffer.dynamic, DynamicRecord::Strides and
  bind_vertex_buffers2.
runtime_texture was always true after the rows and the cube-array route, so it goes too, and
runs_through_runtime and runs_render_through_runtime take the mapped case alone.
ExecutedCensus.rate_map_pass stays (deny_unknown_fields keeps old rows parsing); every writer
sets None. Enables' Member.registry is now read by the tests alone, so it is cfg(test).

ENGINE_EXECUTOR_ABI goes to vulkan-engine-v204: every artifact digest drops the tables hash, and
the own context no longer enables the three sparse members. opened_chains.txt is re-blessed for
that: each committed profile's chain has 3 members fewer.

Tests removed with the code they held: a_kernel_calls_through_its_visible_function_table,
a_tables_words_are_its_size_and_the_handles_of_its_functions, the_cells_follow_the_reflected_master,
a_plane_must_be_a_master_member_of_its_size, cells_lay_planes_out_at_master_offsets,
the_cells_are_capped, a_guarded_texture_buffer_is_exactly_its_view,
a_texture_buffer_written_past_its_end_is_guarded, texel_buffers_read_one_view_and_write_the_other,
a_tile_map_emulation_maps_exactly_the_cases_texels,
the_new_list_enables_sparse_images_where_the_device_supports_them,
an_oracle_instance_mask_is_refused_typed, a_rate_mapped_pass_is_planned_region_by_region,
a_dynamic_vertex_layout_takes_the_bound_stride and the region and pass tests of
platform/render (now a_draw_covers_the_whole_target). The visible_table fixtures stay: the
runtime's and the conformance suite's tests use them.

No classification moves: executor_contract/out_of_bounds.rs and sparse.rs lose only functions
nothing called. The compile census's executor key moves with the ABI (bless on development).

Verified: gate m3-max-63421 (homelab-um870-1) at this tree before the bless: fmt, validation
clippy with all features, with --cfg m2v_gpu and with --cfg m2v_cpu_icd, Rustdoc, the ignored
bless_opened_chains (its file is the one committed here), and the validation suite, 1342 passed,
3 skipped. Earlier gates m3-max-63393 and m3-max-63412 listed the compile errors fixed here.
2026-11-21 06:12:04 -08:00

180 lines
8.0 KiB
Rust

//! The engine candidate takes a case that links visible functions up to the device: in an owned
//! scratch corpus, a case over the public linked caller (`engine/linked_visible_caller`) whose
//! visible-function references name the harvested modules the Metal oracle links passes admission
//! and the executor's device-free checks, and its kernel, linked with those modules' functions,
//! compiles through a real compile worker into a pipeline that validates on every committed profile
//! it compiles for. No device is opened: the GPU run (Metal and the candidate) is the operator's.
use base64::Engine as _;
use metal2vulkan::bind::BufferRanges;
use metal2vulkan::device::DevicePolicy;
use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError};
use metal2vulkan_validation::acceptance::{retained, LinkedLibrary};
use metal2vulkan_validation::candidate::engine::{
compile_case, compute_case, compute_shape, linked_modules, prepare_case, LinkedModule,
};
use metal2vulkan_validation::case::AuthoredCase;
use metal2vulkan_validation::check::admission::{admit, ExecutionRequest};
use metal2vulkan_validation::engine::load_description;
use metal2vulkan_validation::gpu::DeviceType;
use metal2vulkan_validation::hash::sha256_bytes;
use metal2vulkan_validation::l3::{check_words_l3, L3Failure};
use metal2vulkan_validation::library_module::{merge_library_module_shards, LibraryModuleRow};
use metal2vulkan_validation::worker::compile::{CompileWorker, WorkerDevice};
use metal2vulkan_validation::ScratchDir;
/// The fixture `stem`'s text and its bitcode, or `None` without `llvm-as`.
fn fixture(stem: &str) -> Option<(String, Vec<u8>)> {
let path = engine_dir().join(format!("{stem}.ll"));
let text = std::fs::read_to_string(&path).unwrap();
match llvm_assemble(&path) {
Ok(bitcode) => Some((text, bitcode)),
Err(AssembleError::Missing(why)) => {
eprintln!("SKIPPED: {why}");
None
}
Err(AssembleError::Rejected(why)) => panic!("llvm-as rejected {stem}: {why}"),
}
}
fn b64(bytes: &[u8]) -> String {
base64::engine::general_purpose::STANDARD.encode(bytes)
}
/// `corpus-vulkan`, a tool that runs the engine candidate, as the compile worker, executed
/// once first: the OS may scan a freshly linked binary on its first exec, which the 20-s worker
/// deadline would count.
fn worker() -> CompileWorker {
let program = bin_exe!("corpus-vulkan");
let _ = std::process::Command::new(&program)
.arg("--help")
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status();
CompileWorker::program(program)
}
#[test]
fn a_case_with_visible_function_references_compiles_linked_through_the_worker() {
let (Some((caller_ll, caller)), Some((functions_ll, functions))) = (
fixture("linked_visible_caller"),
fixture("linked_visible_functions"),
) else {
return;
};
let scratch = ScratchDir::new("engine-linked-case").unwrap();
let root = scratch.path();
let library = "44".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 modules it links.
let caller_sha256 = sha256_bytes(caller_ll.as_bytes());
// The functions module defines `linked_scale` and `linked_blend`; `linked_scale` references
// `linked_offset`, which the caller's own library defines and so also supplies.
let module = |ll: &str, bitcode: &[u8], label: &str| LibraryModuleRow {
module_sha256: sha256_bytes(ll.as_bytes()),
air_ll: ll.into(),
blob_b64: b64(bitcode),
lib_sha256s: vec![library.clone()],
label: label.into(),
};
let functions_module = module(
&functions_ll,
&functions,
"test/linked_visible_functions.air",
);
let caller_module = module(&caller_ll, &caller, "test/linked_visible_caller.air");
merge_library_module_shards(root, [functions_module.clone(), caller_module.clone()]).unwrap();
let threads = 8u32;
let bytes = vec![0u8; 4 * threads as usize];
let mut case: AuthoredCase = serde_json::from_value(serde_json::json!({
"air_sha256": caller_sha256,
"case_id": "pending",
"name": "linked-visible-caller",
"entry": "linked_visible_caller",
"stage": "kernel",
"buffers": [
{"binding": 0, "role": "output", "initial_bytes_b64": b64(&bytes)},
{"binding": 1, "role": "output", "initial_bytes_b64": b64(&bytes)},
],
"visible_function_references": [
{"module_sha256": functions_module.module_sha256, "function": "linked_blend"},
{"module_sha256": caller_module.module_sha256, "function": "linked_offset"},
{"module_sha256": functions_module.module_sha256, "function": "linked_sample"},
{"module_sha256": functions_module.module_sha256, "function": "linked_scale"},
],
"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).unwrap();
// Each module once, with the functions the Metal oracle links from it, in reference order.
let linked = linked_modules(&checked.primary.linked_functions).unwrap();
let names = |names: &[&str]| LinkedLibrary {
functions: names.iter().map(|name| (*name).to_owned()).collect(),
};
assert_eq!(
linked,
[
LinkedModule {
module_sha256: functions_module.module_sha256.clone(),
bitcode: functions.clone(),
library: names(&["linked_blend", "linked_sample", "linked_scale"]),
},
LinkedModule {
module_sha256: caller_module.module_sha256.clone(),
bitcode: caller.clone(),
library: names(&["linked_offset"]),
},
]
);
// The executor's device-free checks no longer refuse a case for linking.
if let Err(error) = prepare_case(DeviceType::Gpu, admitted) {
panic!("the executor's device-free checks refused the linked case: {error}");
}
let worker = worker();
for stem in ["moltenvk-m3", "runtime-floor", "lavapipe"] {
let device =
WorkerDevice::new(load_description(stem).unwrap(), DevicePolicy::default()).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 pipeline = compile_case(
&worker,
&device,
&retained(&caller),
&linked,
&compute,
&shape,
)
.unwrap_or_else(|error| panic!("{stem}: {error}"));
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}"),
}
// Without the linked modules the same compile is the product's typed refusal of the
// unresolved reference, never a candidate-side one.
match compile_case(&worker, &device, &retained(&caller), &[], &compute, &shape) {
Err(error) => assert!(
error.to_string().contains("LinkedFunction"),
"{stem}: {error}"
),
Ok(_) => panic!("{stem}: the caller compiled without its linked functions"),
}
}
}