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.
This commit is contained in:
1 parent
78a5c1346b
commit
e6e70666ed
41 files changed
+534
-4652
No files matched your search
@@ -39,18 +39,16 @@ use metal2vulkan::device::Requirements;
|
||||
use metal2vulkan::device::{Device, DeviceDescription, DevicePolicy, DeviceProfile, EnableSet};
|
||||
use metal2vulkan::error::{DescriptorError, Error, RuntimeInput};
|
||||
use metal2vulkan::library::{FunctionConstantValues, Library};
|
||||
use metal2vulkan::metal::PixelFormat;
|
||||
use metal2vulkan::pipeline::Stage;
|
||||
use metal2vulkan::pipeline::{
|
||||
ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, FunctionHandle, LinkedFunction,
|
||||
LinkedFunctions, PrecisionNote, RenderPipeline, RenderPipelineDescriptor, StageInputDescriptor,
|
||||
StageModule, StageSource,
|
||||
LinkedFunctions, PrecisionNote, RenderPipeline, RenderPipelineDescriptor, StageModule,
|
||||
StageSource,
|
||||
};
|
||||
use metal2vulkan::vk;
|
||||
use metal2vulkan::Budget;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Range;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -278,18 +276,9 @@ pub enum PipelineRequest {
|
||||
shape: BindShape,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
dispatch: Option<Dispatch>,
|
||||
/// The compute pipeline's stage-input descriptor, which the kernel compiles under.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
stage_input: Option<StageInputDescriptor>,
|
||||
/// A tile function's color attachment formats by color index: the kernel compiles as
|
||||
/// a tile function under them, into `Device::compile_tile_pipeline`'s pipeline
|
||||
/// (`variants::compile_tile_for_shape`). A tile pipeline has no stage-input descriptor.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
tile: Option<BTreeMap<u32, PixelFormat>>,
|
||||
/// The kernel compiles as a device-replay variant (`LoweringInputs::replay_bindings`,
|
||||
/// `variants::compile_replay_for_shape`): a replayed template's pipeline, its buffers read
|
||||
/// through the slot table the replay's preprocess writes per command. A replay variant has
|
||||
/// no stage-input descriptor and no tile pass.
|
||||
/// through the slot table the replay's preprocess writes per command.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
replay: bool,
|
||||
},
|
||||
@@ -514,9 +503,7 @@ pub enum PipelineCompileError {
|
||||
/// descriptor or companion, [`row`]): a modelled limit of the tool.
|
||||
Unmodelled(row::Unmodelled),
|
||||
/// The host's tooling failed while building the request's inputs (`llvm-as` assembling an L4
|
||||
/// fragment row's generated companion), or the request names inputs no pipeline takes
|
||||
/// together (a tile pipeline's attachments with a stage-input descriptor): neither a product
|
||||
/// outcome nor a modelled limit.
|
||||
/// fragment row's generated companion): neither a product outcome nor a modelled limit.
|
||||
Tooling(String),
|
||||
}
|
||||
|
||||
@@ -808,52 +795,15 @@ fn compile_counted(
|
||||
function: kernel,
|
||||
shape,
|
||||
dispatch,
|
||||
stage_input,
|
||||
tile,
|
||||
replay,
|
||||
} => {
|
||||
use crate::candidate::engine::variants;
|
||||
let (kernel, handles) = function(0, Stage::Kernel, kernel, linked(0))?;
|
||||
let (pipeline, _) = match (tile, stage_input) {
|
||||
(None, None) if *replay => {
|
||||
crate::candidate::engine::variants::compile_replay_for_shape(
|
||||
device,
|
||||
&kernel,
|
||||
shape,
|
||||
dispatch.as_ref(),
|
||||
&budget,
|
||||
)?
|
||||
}
|
||||
_ if *replay => {
|
||||
return Err(PipelineCompileError::Tooling(
|
||||
"a replay variant has no stage-input descriptor and no tile pass".into(),
|
||||
))
|
||||
}
|
||||
(Some(formats), None) => {
|
||||
crate::candidate::engine::variants::compile_tile_for_shape(
|
||||
device,
|
||||
&kernel,
|
||||
shape,
|
||||
dispatch.as_ref(),
|
||||
formats,
|
||||
&budget,
|
||||
)?
|
||||
}
|
||||
(Some(_), Some(_)) => {
|
||||
return Err(PipelineCompileError::Tooling(
|
||||
"a tile pipeline has no stage-input descriptor".into(),
|
||||
))
|
||||
}
|
||||
(None, stage_input) => {
|
||||
crate::candidate::engine::variants::compile_compute_for_shape(
|
||||
device,
|
||||
&kernel,
|
||||
shape,
|
||||
dispatch.as_ref(),
|
||||
stage_input.as_ref(),
|
||||
&budget,
|
||||
)?
|
||||
}
|
||||
let compile = match replay {
|
||||
true => variants::compile_replay_for_shape,
|
||||
false => variants::compile_compute_for_shape,
|
||||
};
|
||||
let (pipeline, _) = compile(device, &kernel, shape, dispatch.as_ref(), &budget)?;
|
||||
CompiledRequest {
|
||||
pipeline: AcceptancePipeline::Compute(Box::new(pipeline)),
|
||||
handles: vec![handles],
|
||||
@@ -1292,6 +1242,7 @@ pub fn unmet_device_facts(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use metal2vulkan::library::FunctionConstantValue;
|
||||
use metal2vulkan::metal::PixelFormat;
|
||||
use metal2vulkan::vk;
|
||||
use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError};
|
||||
|
||||
@@ -1783,8 +1734,6 @@ mod tests {
|
||||
},
|
||||
shape: BindShape::default(),
|
||||
dispatch: None,
|
||||
stage_input: None,
|
||||
tile: None,
|
||||
replay: false,
|
||||
};
|
||||
let library = |names: &[&str]| LinkedLibrary {
|
||||
@@ -1875,8 +1824,6 @@ mod tests {
|
||||
function: function("k", 2),
|
||||
shape: BindShape::default(),
|
||||
dispatch: None,
|
||||
stage_input: None,
|
||||
tile: None,
|
||||
replay: false,
|
||||
};
|
||||
assert_eq!(kernel.linked_ranges(), vec![Range { start: 1, end: 3 }]);
|
||||
|
||||
@@ -759,9 +759,7 @@ fn compile_outcome(failure: CompileFailure) -> Result<CellOutcome, CellFailure>
|
||||
key: "unmodelled".into(),
|
||||
detail: bounded_detail(&format!("the compile worker built no inputs: {why:?}")),
|
||||
}),
|
||||
CompileFailure::Tables(error) | CompileFailure::Artifact(error) => {
|
||||
executor_outcome(error, FailureClass::Tool)
|
||||
}
|
||||
CompileFailure::Artifact(error) => executor_outcome(error, FailureClass::Tool),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,10 +171,7 @@ mod platform {
|
||||
_compile: impl FnOnce(
|
||||
&crate::worker::compile::WorkerDevice,
|
||||
&metal2vulkan::bind::BindShape,
|
||||
) -> Result<
|
||||
super::engine::CompiledCase<metal2vulkan::pipeline::ComputePipeline>,
|
||||
ExecutorError,
|
||||
>,
|
||||
) -> Result<metal2vulkan::pipeline::ComputePipeline, ExecutorError>,
|
||||
_children: impl FnMut(
|
||||
&crate::worker::compile::WorkerDevice,
|
||||
u64,
|
||||
@@ -195,10 +192,7 @@ mod platform {
|
||||
_compile: impl FnOnce(
|
||||
&crate::worker::compile::WorkerDevice,
|
||||
&metal2vulkan::bind::BindShape,
|
||||
) -> Result<
|
||||
super::engine::CompiledCase<metal2vulkan::pipeline::RenderPipeline>,
|
||||
ExecutorError,
|
||||
>,
|
||||
) -> Result<metal2vulkan::pipeline::RenderPipeline, ExecutorError>,
|
||||
_children: impl FnMut(
|
||||
&crate::worker::compile::WorkerDevice,
|
||||
u64,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -4,10 +4,9 @@
|
||||
//! device-replay variant, the compiles [`super::case_compiles`] lists) contributes one compile
|
||||
//! digest: its subject, the pipeline's content digest (`ComputePipeline::content_digest`, every
|
||||
//! field but the cache identity), the content digest of the binding plan the run makes of it for
|
||||
//! its bind shape (`BindingPlan::content_digest`, or the refusal of that plan), and the bytes of
|
||||
//! its visible-function tables. A run that replays its compute commands on the device adds the
|
||||
//! preprocess module's words. The case's artifact is the SHA-256 over those, in subject order, so
|
||||
//! the order the run compiled them in does not enter.
|
||||
//! its bind shape (`BindingPlan::content_digest`, or the refusal of that plan). A run that replays
|
||||
//! its compute commands on the device adds the preprocess module's words. The case's artifact is
|
||||
//! the SHA-256 over those, in subject order, so the order the run compiled them in does not enter.
|
||||
//!
|
||||
//! The executor records it ([`ExecutedArtifact`]) with the product's
|
||||
//! `cache::RUNTIME_VERSION`; the authored compile census computes it the same way, device-free,
|
||||
@@ -25,7 +24,6 @@ use metal2vulkan::pipeline::{ComputePipeline, RenderPipeline};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use super::tables::TableBuffers;
|
||||
use super::CompileSubject;
|
||||
use crate::check::admission::ExecutorError;
|
||||
|
||||
@@ -112,14 +110,12 @@ pub struct CaseArtifact {
|
||||
const REPLAY_MODULE: &str = "replay-preprocess-module";
|
||||
|
||||
impl CaseArtifact {
|
||||
/// Record the compile of `subject`: `pipeline` (with its visible-function `tables`) planned
|
||||
/// for `shape` on `device`. A plan the binder refuses is part of the digest as its refusal.
|
||||
/// Record the compile of `subject`: `pipeline` planned for `shape` on `device`. A plan the binder refuses is part of the digest as its refusal.
|
||||
/// A subject compiled twice (a variant the run asked for again) must be the same compile.
|
||||
pub fn record(
|
||||
&mut self,
|
||||
subject: CompileSubject,
|
||||
pipeline: &dyn Planned,
|
||||
tables: &TableBuffers,
|
||||
device: &Device,
|
||||
shape: &BindShape,
|
||||
) -> Result<(), ExecutorError> {
|
||||
@@ -140,12 +136,6 @@ impl CaseArtifact {
|
||||
put(&mut h, format!("{refusal:?}").as_bytes());
|
||||
}
|
||||
}
|
||||
h.update((tables.len() as u64).to_le_bytes());
|
||||
for ((stage, index), bytes) in tables {
|
||||
put(&mut h, format!("{stage:?}").as_bytes());
|
||||
h.update(index.to_le_bytes());
|
||||
put(&mut h, bytes);
|
||||
}
|
||||
self.insert(label, h.finalize().into())
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
//! draw: the vertex function alone, its stage-in attributes fed by vertex buffers at the
|
||||
//! oracle's slots ([`vertex_input_slots`]), the oracle's 1×1 `R8Unorm` color attachment as API
|
||||
//! scaffolding, and the case's buffers, textures (texture-array elements at their slots),
|
||||
//! samplers, visible-function tables ([`super::tables`]), argument-buffer buffers
|
||||
//! ([`super::argument_buffers`]), and argument-buffer textures and command buffers bound to the
|
||||
//! vertex stage;
|
||||
//! samplers, argument-buffer buffers ([`super::argument_buffers`]), and argument-buffer textures
|
||||
//! and command buffers bound to the vertex stage;
|
||||
//! - a fragment case draws through its generated passthrough vertex companion, with the case's
|
||||
//! resources bound to the fragment stage and its render targets attached;
|
||||
//! - a vertex case observed through its position or a varying draws into its generated observer
|
||||
@@ -26,11 +25,7 @@
|
||||
//! partition mode and output winding), its control points and patch attributes fed per patch
|
||||
//! control point and per patch at the oracle's slots, its factors in one buffer, the case's cull
|
||||
//! mode, and one patch draw through its observer, or with rasterization disabled and no observer
|
||||
//! when the case has no vertex observation;
|
||||
//! - a fragment case's explicit imageblock is the pass's cells as the Metal oracle's initializer
|
||||
//! defines them, each authored plane at its offset in the checked reflection's master
|
||||
//! ([`super::imageblock`]), and an imageblock output is the oracle resolver's plane of the
|
||||
//! selected member.
|
||||
//! when the case has no vertex observation.
|
||||
//!
|
||||
//! The companion is the checker's ([`crate::companion`], derived from the entry's AIR): the Metal
|
||||
//! oracle draws with the same generated module, so both sides run the same companion semantics.
|
||||
@@ -38,13 +33,10 @@
|
||||
//! functions of two libraries through one pipeline with derived expectations.
|
||||
|
||||
use super::argument_buffers::{self, FieldKey};
|
||||
use super::imageblock::{self, Cells};
|
||||
use super::tables::{function_tables, FunctionTable};
|
||||
use super::{
|
||||
function_constants, require_case_families, resources, select_range, views_told_apart,
|
||||
BufferAddress,
|
||||
};
|
||||
use crate::air::reflect::FragmentImageblock;
|
||||
use crate::case::indirect_commands::CommandBufferResource;
|
||||
use crate::case::out_of_bounds::OutOfBoundsTarget;
|
||||
use crate::case::{
|
||||
@@ -54,7 +46,6 @@ use crate::case::{
|
||||
use crate::check::admission::{ExecutorError, NotSupported};
|
||||
use crate::check::interface::AirInterface;
|
||||
use crate::companion::Companion;
|
||||
use crate::coverage::RateMapPassRun;
|
||||
use crate::executor_contract::buffer_slots::vertex_input_slots;
|
||||
use crate::executor_contract::multisample::AttachmentTransfer;
|
||||
use crate::executor_contract::render_target_array::render_target_array_length;
|
||||
@@ -62,9 +53,8 @@ use crate::executor_contract::tessellation as patches;
|
||||
use crate::executor_contract::DrawDepthStencil;
|
||||
use crate::literal::{LiteralDepthStencil, LiteralResources, LiteralStageInput, LiteralTexture};
|
||||
use metal2vulkan::bind::{
|
||||
BindShape, BindState, BoundBuffer, BufferRanges, DrawCall, IndexBufferRef,
|
||||
RasterizationRateMap, RateMapRegions, RegionLimits, StageTable, TessellationFactorBuffer,
|
||||
TessellationFactors,
|
||||
BindShape, BindState, BoundBuffer, BufferRanges, DrawCall, IndexBufferRef, StageTable,
|
||||
TessellationFactorBuffer, TessellationFactors,
|
||||
};
|
||||
use metal2vulkan::error::{DescriptorError, Error, MetalAnswer};
|
||||
use metal2vulkan::library::FunctionConstantValues;
|
||||
@@ -103,12 +93,10 @@ pub struct StageResources {
|
||||
/// ([`records_ids`]); the run checks its final records
|
||||
/// ([`argument_buffers::validate_records`]).
|
||||
pub command_buffers: BTreeMap<FieldKey, CommandBufferResource>,
|
||||
/// Each bound texture (texture buffers and texture-array elements included, each element at
|
||||
/// its own slot, [`resources::bound_textures`]) with its initial contents.
|
||||
/// Each bound texture (texture-array elements included, each element at its own slot,
|
||||
/// [`resources::bound_textures`]) with its initial contents.
|
||||
pub textures: BTreeMap<u32, LiteralTexture>,
|
||||
pub samplers: BTreeMap<u32, SamplerResource>,
|
||||
/// Each visible-function table, by Metal buffer index: a buffer of its table words.
|
||||
pub function_tables: BTreeMap<u32, FunctionTable>,
|
||||
}
|
||||
|
||||
/// One stage's function and what it binds.
|
||||
@@ -129,9 +117,6 @@ pub struct VertexBuffer {
|
||||
pub buffer_index: u32,
|
||||
pub format: AttributeFormat,
|
||||
pub stride: u32,
|
||||
/// The layout's stride is `MTLBufferLayoutStrideDynamic`: the buffer is bound with the
|
||||
/// stride form at `stride`, as the oracle binds it.
|
||||
pub dynamic: bool,
|
||||
pub step: metal::VertexStepFunction,
|
||||
pub bytes: Vec<u8>,
|
||||
}
|
||||
@@ -199,13 +184,6 @@ pub enum RenderOutput {
|
||||
origin: [u32; 2],
|
||||
dimensions: [u32; 2],
|
||||
},
|
||||
/// A region of the plane of one member of the fragment imageblock's master, at `member`'s
|
||||
/// offset in each pixel's cell.
|
||||
Imageblock {
|
||||
member: imageblock::Member,
|
||||
origin: [u32; 2],
|
||||
dimensions: [u32; 2],
|
||||
},
|
||||
}
|
||||
|
||||
/// What a draw assembles.
|
||||
@@ -254,20 +232,11 @@ pub struct RenderCase {
|
||||
/// (`executor_contract::tessellation::cull_mode`), and otherwise Metal's default, none. The
|
||||
/// front face is [`RenderCase::depth_stencil_state`]'s winding.
|
||||
pub cull_mode: metal::CullMode,
|
||||
/// A fragment case's explicit imageblock: the pass's cells when the case's draw begins, as
|
||||
/// the Metal oracle's initializer leaves them ([`Cells::initial`]). A draw leaves them so: the
|
||||
/// product compiles no fragment function that reads or writes them.
|
||||
pub imageblock: Option<Cells>,
|
||||
pub output: RenderOutput,
|
||||
/// The generated stage that completes the case: `vertex` is its passthrough vertex function, or
|
||||
/// `fragment` its observer fragment function. `None` for a rasterization-disabled vertex case
|
||||
/// and for owned two-stage fixtures.
|
||||
pub companion: Option<Companion>,
|
||||
/// The render pass's rasterization-rate map, the product's compile of it (Apple M3's rule),
|
||||
/// whose parameter data every map literal of the case binds (`RateMapLiteral::parameter_data`):
|
||||
/// the render executor draws the pass region by region into its physical size
|
||||
/// ([`rate_map_regions`]), on every device.
|
||||
pub rate_map_pass: Option<RasterizationRateMap>,
|
||||
/// The render pass's sample count, the case's: `None` for one sample, as every case drew before
|
||||
/// the count was authorable; the pipeline's `rasterSampleCount`
|
||||
/// ([`RenderTemplate::raster_sample_count`]), and every attachment holds that many samples
|
||||
@@ -424,7 +393,6 @@ pub fn vertex_buffers(
|
||||
buffer_index,
|
||||
format: input.format,
|
||||
stride: input.stride,
|
||||
dynamic: input.dynamic_stride,
|
||||
step,
|
||||
bytes: input.bytes.clone(),
|
||||
})
|
||||
@@ -434,8 +402,9 @@ pub fn vertex_buffers(
|
||||
|
||||
/// Map `case` onto what the render executor runs, or name what it does not implement yet: the
|
||||
/// families of the shared vocabulary that stop it ([`require_case_families`], among them device
|
||||
/// buffer arrays, acceleration structures and intersection function tables, a vertex case's
|
||||
/// depth/stencil attachment, and a rasterization-disabled vertex case's render targets) are
|
||||
/// buffer arrays, function tables, rate maps, fragment imageblocks, dynamic vertex strides, a
|
||||
/// vertex case's depth/stencil attachment, and a rasterization-disabled vertex case's render
|
||||
/// targets) are
|
||||
/// `NotSupported::Requirements`, and a case whose literals do not map is
|
||||
/// `NotSupported::NotImplemented`. A tessellation case draws its patches as the oracle does
|
||||
/// ([`patch_draw`]). `interface` is the checked entry's AIR-layer interface, whose buffer slots the
|
||||
@@ -444,15 +413,12 @@ pub fn vertex_buffers(
|
||||
/// oracle's does ([`render_target_array_length`]); `companion` is the checked entry's generated
|
||||
/// companion ([`crate::check::CheckedShader::companion`]), which a fragment case and an observed
|
||||
/// vertex case draw with. A companion that does not complete the case's stage is a failure: the
|
||||
/// checker derives exactly one for exactly those cases. `fragment_imageblock` is the checked
|
||||
/// reflection's (`CheckedShader::reflection`), whose master a fragment case's imageblock cells and
|
||||
/// output follow, as the checker's and the oracle's do ([`imageblock::layout`]).
|
||||
/// checker derives exactly one for exactly those cases.
|
||||
pub fn render_case(
|
||||
case: &AuthoredCase,
|
||||
interface: &AirInterface,
|
||||
air_ll: &str,
|
||||
companion: Option<&Companion>,
|
||||
fragment_imageblock: Option<&FragmentImageblock>,
|
||||
) -> Result<RenderCase, ExecutorError> {
|
||||
let gap = |what: &str| NotSupported::NotImplemented(format!("engine candidate: {what}"));
|
||||
let generated = |companion: &Companion| RenderFunction {
|
||||
@@ -525,14 +491,6 @@ pub fn render_case(
|
||||
}
|
||||
_ => return Err(gap("a render case without exactly one draw").into()),
|
||||
};
|
||||
// The reflected master layout of the function's imageblock, which its authored planes and
|
||||
// imageblock output name members of.
|
||||
let imageblock_layout = match (stage, fragment_imageblock) {
|
||||
(ShaderStage::Fragment, Some(reflected)) => {
|
||||
Some(imageblock::layout(reflected).map_err(|error| gap(&error))?)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let output = match stage_output(&case.output, stage).map_err(|error| gap(&error))? {
|
||||
Some(output) => output,
|
||||
None => match case.output {
|
||||
@@ -551,32 +509,10 @@ pub fn render_case(
|
||||
OutputSelection::Stencil { origin, dimensions } if stage == ShaderStage::Fragment => {
|
||||
RenderOutput::Stencil { origin, dimensions }
|
||||
}
|
||||
OutputSelection::FragmentImageblock {
|
||||
ref semantic,
|
||||
origin,
|
||||
dimensions,
|
||||
} if stage == ShaderStage::Fragment => {
|
||||
let member = imageblock_layout
|
||||
.as_ref()
|
||||
.and_then(|layout| layout.members.get(semantic))
|
||||
.copied()
|
||||
.ok_or_else(|| {
|
||||
gap(&format!(
|
||||
"imageblock output {semantic}, which no master member of the \
|
||||
function's views names"
|
||||
))
|
||||
})?;
|
||||
RenderOutput::Imageblock {
|
||||
member,
|
||||
origin,
|
||||
dimensions,
|
||||
}
|
||||
}
|
||||
_ => return Err(gap(
|
||||
"a render output other than a buffer or argument-buffer buffer range, a region of \
|
||||
a texture, a texture-array element, or an argument-buffer texture, or a region of \
|
||||
a rasterized render target, of a fragment case's depth/stencil attachment, or of \
|
||||
its imageblock",
|
||||
a rasterized render target or of a fragment case's depth/stencil attachment",
|
||||
)
|
||||
.into()),
|
||||
},
|
||||
@@ -589,15 +525,6 @@ pub fn render_case(
|
||||
}
|
||||
let vertex_buffers = vertex_buffers(case, &literal, interface)?;
|
||||
let color_targets = color_targets(&literal, generated.is_some());
|
||||
let imageblock = match (&literal.fragment_imageblock, &imageblock_layout) {
|
||||
(None, _) => None,
|
||||
(Some(authored), Some(layout)) => {
|
||||
Some(Cells::initial(layout, authored).map_err(|error| gap(&error))?)
|
||||
}
|
||||
(Some(_), None) => {
|
||||
return Err(gap("an authored imageblock of a function that reflects none").into())
|
||||
}
|
||||
};
|
||||
let own = RenderFunction {
|
||||
entry: case.entry.clone(),
|
||||
constants: function_constants(&literal)?,
|
||||
@@ -639,15 +566,8 @@ pub fn render_case(
|
||||
.tessellation
|
||||
.as_ref()
|
||||
.map_or(metal::CullMode::None, patches::cull_mode),
|
||||
imageblock,
|
||||
output,
|
||||
companion: companion.cloned(),
|
||||
rate_map_pass: case
|
||||
.render_pass_rate_map
|
||||
.as_ref()
|
||||
.map(|map| map.compiled())
|
||||
.transpose()
|
||||
.map_err(|error| gap(&error))?,
|
||||
raster_sample_count: case.raster_sample_count,
|
||||
})
|
||||
}
|
||||
@@ -687,7 +607,7 @@ pub fn color_targets(literal: &LiteralResources, rasterizes: bool) -> BTreeMap<u
|
||||
/// The output `output` selects of the case's own function at `stage`, when it is a resource of that
|
||||
/// function's (a buffer range, a region of a texture or a texture-array element, an argument
|
||||
/// buffer's buffer range or texture region) or no output; `None` for an output of the pass (a
|
||||
/// render target, the depth/stencil attachment, an imageblock). The one mapping a render case's
|
||||
/// render target, the depth/stencil attachment). The one mapping a render case's
|
||||
/// and a mesh case's own stage share.
|
||||
pub fn stage_output(
|
||||
output: &OutputSelection,
|
||||
@@ -759,8 +679,7 @@ pub fn stage_output(
|
||||
/// What the case's own function binds, from its literals `literal`: its buffers (an argument
|
||||
/// buffer's owner covering each pointer field), its argument buffers' members, the pipeline states
|
||||
/// and command buffers its argument buffers hold, its textures (texture-array elements each at its
|
||||
/// own slot), samplers and visible-function tables. The one mapping a render case's and a mesh
|
||||
/// case's own stage share.
|
||||
/// own slot) and samplers. The one mapping a render case's and a mesh case's own stage share.
|
||||
pub fn stage_resources(
|
||||
case: &AuthoredCase,
|
||||
literal: &LiteralResources,
|
||||
@@ -805,58 +724,9 @@ pub fn stage_resources(
|
||||
return Err(gap(&format!("sampler {} bound twice", sampler.binding)).into());
|
||||
}
|
||||
}
|
||||
resources.function_tables = function_tables(&case.visible_function_tables)?;
|
||||
if let Some(binding) = resources
|
||||
.function_tables
|
||||
.keys()
|
||||
.find(|binding| resources.buffers.contains_key(binding))
|
||||
{
|
||||
return Err(gap(&format!(
|
||||
"buffer {binding} is also a visible function table"
|
||||
))
|
||||
.into());
|
||||
}
|
||||
Ok(resources)
|
||||
}
|
||||
|
||||
/// The region plan the render executor draws a rate-mapped pass of `map` with: the map's screen as
|
||||
/// the guest's viewport and no guest scissor (the Metal oracle sets neither), within the device's
|
||||
/// viewport `limits`, for a pipeline of `graphics`. A refusal of the planner (a viewport the device
|
||||
/// cannot set, a layered or viewport-selecting pipeline, or a vertex function that writes memory in
|
||||
/// a pass of several regions) is the binder's on this device (`not_supported{bind}`).
|
||||
pub fn rate_map_regions(
|
||||
map: &RasterizationRateMap,
|
||||
limits: &RegionLimits,
|
||||
graphics: &metal2vulkan::pipeline::GraphicsState,
|
||||
) -> Result<RateMapRegions, ExecutorError> {
|
||||
let [width, height] = map.screen_size();
|
||||
let refused = |error: metal2vulkan::bind::RegionError| {
|
||||
ExecutorError::from(NotSupported::Bind(format!(
|
||||
"rate-mapped render pass: {error}"
|
||||
)))
|
||||
};
|
||||
let plan = map
|
||||
.regions(
|
||||
0,
|
||||
[0.0, 0.0, f64::from(width), f64::from(height)],
|
||||
None,
|
||||
limits,
|
||||
)
|
||||
.map_err(refused)?;
|
||||
plan.admits(graphics).map_err(refused)?;
|
||||
Ok(plan)
|
||||
}
|
||||
|
||||
/// The census of a rate-mapped pass of `map` drawn by `plan`, with the plan's near-equivalent.
|
||||
pub fn rate_map_pass_census(map: &RasterizationRateMap, plan: &RateMapRegions) -> RateMapPassRun {
|
||||
RateMapPassRun {
|
||||
screen_size: map.screen_size(),
|
||||
compiled_physical_size: plan.physical_size(),
|
||||
regions: plan.regions().len() as u32,
|
||||
precision: plan.precision().into_iter().collect(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The consumer token of an indexed draw's index buffer (`IndexBufferRef::token`): the one index
|
||||
/// buffer a case's draw binds.
|
||||
pub const INDEX_BUFFER_TOKEN: u32 = 0;
|
||||
@@ -1136,8 +1006,7 @@ pub fn vertex_descriptor(buffers: &[VertexBuffer]) -> Option<VertexDescriptor> {
|
||||
}
|
||||
let mut layout = VertexDescriptor::new();
|
||||
for buffer in buffers {
|
||||
let mut buffer_layout =
|
||||
VertexBufferLayoutDescriptor::new((!buffer.dynamic).then_some(buffer.stride));
|
||||
let mut buffer_layout = VertexBufferLayoutDescriptor::new(Some(buffer.stride));
|
||||
buffer_layout.step_function = buffer.step;
|
||||
layout.layouts.insert(buffer.buffer_index, buffer_layout);
|
||||
layout.attributes.insert(
|
||||
@@ -1209,9 +1078,8 @@ pub fn synthetic_address(stage: ShaderStage, index: u32) -> BufferAddress {
|
||||
}
|
||||
|
||||
/// The `BindState` of `case`: each stage's buffers at offset 0 with their lengths and addresses
|
||||
/// (`addresses` by stage and Metal index), its visible-function tables the same way as buffers of
|
||||
/// their table words' length (`bind::table`), textures, and samplers; the vertex buffers bound to
|
||||
/// the vertex stage at their slots (static strides come from the descriptor); each argument-buffer
|
||||
/// (`addresses` by stage and Metal index), textures, and samplers; the vertex buffers bound to the
|
||||
/// vertex stage at their slots (their strides come from the descriptor); each argument-buffer
|
||||
/// buffer as a used buffer at its address (`embedded` by stage, owner, and field offset; its
|
||||
/// consumer token is its position in [`RenderCase::argument_buffer_buffers`]) and each
|
||||
/// argument-buffer texture as a used texture with its resource id (its token follows the buffers',
|
||||
@@ -1228,14 +1096,14 @@ pub fn bind_state(
|
||||
embedded: &BTreeMap<(ShaderStage, u32, u32), BufferAddress>,
|
||||
ranges: BufferRanges,
|
||||
) -> Result<BindState, String> {
|
||||
let bound = |stage: ShaderStage, index: u32, length: u64, attribute_stride: Option<u32>| {
|
||||
let bound = |stage: ShaderStage, index: u32, length: u64| {
|
||||
let address = addresses.get(&(stage, index)).copied().unwrap_or_default();
|
||||
BoundBuffer::Buffer {
|
||||
length,
|
||||
offset: 0,
|
||||
gpu_address: address.guest,
|
||||
device_address: address.host,
|
||||
attribute_stride,
|
||||
attribute_stride: None,
|
||||
}
|
||||
};
|
||||
let mut state = BindState::default();
|
||||
@@ -1251,19 +1119,15 @@ pub fn bind_state(
|
||||
);
|
||||
}
|
||||
for (stage, function) in case.stages() {
|
||||
let table = stage_table(stage, function, |index, length| {
|
||||
bound(stage, index, length, None)
|
||||
})?;
|
||||
let table = stage_table(function, |index, length| bound(stage, index, length))?;
|
||||
state.stages.insert(stage, table);
|
||||
}
|
||||
let table = state.stages.entry(ShaderStage::Vertex).or_default();
|
||||
for buffer in &case.vertex_buffers {
|
||||
// A dynamic layout's buffer is bound with the stride form.
|
||||
let slot = bound(
|
||||
ShaderStage::Vertex,
|
||||
buffer.buffer_index,
|
||||
buffer.bytes.len() as u64,
|
||||
buffer.dynamic.then_some(buffer.stride),
|
||||
);
|
||||
if table.buffers.insert(buffer.buffer_index, slot).is_some() {
|
||||
return Err(format!(
|
||||
@@ -1294,33 +1158,17 @@ pub fn bind_state(
|
||||
Ok(views_told_apart(state, ranges))
|
||||
}
|
||||
|
||||
/// The bind table of `function`'s own resources at `stage`: its buffers and visible function
|
||||
/// tables, each bound as `bound` binds a buffer of its index and length, its textures and its
|
||||
/// samplers.
|
||||
/// The bind table of `function`'s own resources: its buffers, each bound as `bound` binds a buffer
|
||||
/// of its index and length, its textures and its samplers.
|
||||
pub fn stage_table(
|
||||
stage: ShaderStage,
|
||||
function: &RenderFunction,
|
||||
bound: impl Fn(u32, u64) -> BoundBuffer,
|
||||
) -> Result<StageTable, String> {
|
||||
let mut table = StageTable::default();
|
||||
let lengths = function
|
||||
.resources
|
||||
.buffers
|
||||
.iter()
|
||||
.map(|(&index, bytes)| (index, bytes.len() as u64))
|
||||
.chain(
|
||||
function
|
||||
.resources
|
||||
.function_tables
|
||||
.iter()
|
||||
.map(|(&index, function_table)| (index, function_table.byte_len())),
|
||||
);
|
||||
for (index, length) in lengths {
|
||||
if table.buffers.insert(index, bound(index, length)).is_some() {
|
||||
return Err(format!(
|
||||
"{stage:?} buffer {index} is also a visible function table"
|
||||
));
|
||||
}
|
||||
for (&index, bytes) in &function.resources.buffers {
|
||||
table
|
||||
.buffers
|
||||
.insert(index, bound(index, bytes.len() as u64));
|
||||
}
|
||||
for (&index, texture) in &function.resources.textures {
|
||||
table
|
||||
@@ -1386,13 +1234,7 @@ pub fn render_shape(
|
||||
};
|
||||
let addresses = case
|
||||
.stages()
|
||||
.flat_map(|(stage, f)| {
|
||||
f.resources
|
||||
.buffers
|
||||
.keys()
|
||||
.chain(f.resources.function_tables.keys())
|
||||
.map(move |&index| (stage, index))
|
||||
})
|
||||
.flat_map(|(stage, f)| f.resources.buffers.keys().map(move |&index| (stage, index)))
|
||||
.chain(
|
||||
case.vertex_buffers
|
||||
.iter()
|
||||
@@ -1419,8 +1261,6 @@ pub struct RenderFinals {
|
||||
pub targets: BTreeMap<u32, ColorTarget>,
|
||||
/// The depth/stencil attachment's final aspects.
|
||||
pub depth_stencil: Option<LiteralDepthStencil>,
|
||||
/// The fragment imageblock's final cells.
|
||||
pub imageblock: Option<Cells>,
|
||||
}
|
||||
|
||||
/// The bytes of `output` from a run's final contents.
|
||||
@@ -1509,15 +1349,6 @@ pub fn select_render_output(
|
||||
dimensions,
|
||||
)
|
||||
}
|
||||
RenderOutput::Imageblock {
|
||||
member,
|
||||
origin,
|
||||
dimensions,
|
||||
} => finals
|
||||
.imageblock
|
||||
.as_ref()
|
||||
.ok_or("the output imageblock's cells were not read")?
|
||||
.select(member, origin, dimensions),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,18 +56,6 @@ pub(crate) fn checked_companion(
|
||||
(interface, companion)
|
||||
}
|
||||
|
||||
/// The product's declared fragment imageblock of `entry` in the module text `ll`: the reflection
|
||||
/// the checker validates a case's planes against, whose master the render executor's cells
|
||||
/// follow.
|
||||
pub(crate) fn reflected_imageblock(
|
||||
ll: &str,
|
||||
entry: &str,
|
||||
) -> Option<crate::air::reflect::FragmentImageblock> {
|
||||
crate::air::reflect::inspect(ll, crate::case::Stage::Fragment, entry, &[])
|
||||
.unwrap()
|
||||
.fragment_imageblock
|
||||
}
|
||||
|
||||
/// A fragment case's authored aspect is its depth/stencil attachment (the oracle's `Stencil8` here,
|
||||
/// as its `Depth32Float` for a depth), its depth-stencil state is the one its outputs imply, and
|
||||
/// each aspect is an observable output; an attachment of both aspects, the oracle's two textures,
|
||||
@@ -101,20 +89,12 @@ fn a_fragment_cases_depth_stencil_attachment_and_state_are_the_oracles() {
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None
|
||||
companion.as_ref()
|
||||
)),
|
||||
[crate::requirement::ToolingRequirement::SeparateDepthStencil].into()
|
||||
);
|
||||
authored.depth_stencil.as_mut().unwrap().initial_depth_b64 = None;
|
||||
let render = render_case(
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let render = render_case(&authored, &interface, WITHOUT_SLICE, companion.as_ref()).unwrap();
|
||||
assert!(render.color_targets.is_empty());
|
||||
assert_eq!(
|
||||
render.depth_stencil,
|
||||
@@ -177,7 +157,7 @@ fn a_fragment_cases_depth_stencil_attachment_and_state_are_the_oracles() {
|
||||
vertex.stage = Stage::Vertex;
|
||||
vertex.output = OutputSelection::None;
|
||||
assert!(
|
||||
requirements(render_case(&vertex, &interface, WITHOUT_SLICE, None, None))
|
||||
requirements(render_case(&vertex, &interface, WITHOUT_SLICE, None))
|
||||
.contains(&crate::requirement::ToolingRequirement::VertexDepthStencilAttachment)
|
||||
);
|
||||
|
||||
@@ -194,8 +174,7 @@ fn a_fragment_cases_depth_stencil_attachment_and_state_are_the_oracles() {
|
||||
&traced,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None
|
||||
companion.as_ref()
|
||||
)),
|
||||
[crate::requirement::ToolingRequirement::RenderAccelerationStructure].into()
|
||||
);
|
||||
@@ -229,14 +208,7 @@ fn a_stencil_output_case_plans_through_stencil_export() {
|
||||
dimensions: [1, 1],
|
||||
};
|
||||
let (interface, companion) = checked_companion(&authored, &bitcode);
|
||||
let mut render = render_case(
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let mut render = render_case(&authored, &interface, WITHOUT_SLICE, companion.as_ref()).unwrap();
|
||||
// Both aspects are the runtime's limit (`SeparateDepthStencil`), which stops such a case
|
||||
// before the engine plans it; the plan below is the translator's for both, so the case maps
|
||||
// with its stencil and takes its depth after.
|
||||
@@ -299,14 +271,7 @@ fn a_framebuffer_fetch_case_plans_its_ordered_input_attachment() {
|
||||
dimensions: [1, 1],
|
||||
};
|
||||
let (interface, companion) = checked_companion(&authored, &bitcode);
|
||||
let render = render_case(
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let render = render_case(&authored, &interface, WITHOUT_SLICE, companion.as_ref()).unwrap();
|
||||
assert_eq!(render.color_targets[&0].bytes, 3.0f32.to_le_bytes());
|
||||
let companion_bitcode = render.companion.as_ref().unwrap().opaque_bitcode().unwrap();
|
||||
let libraries = RenderLibraries {
|
||||
@@ -385,14 +350,7 @@ fn graphics_cases_map_onto_a_draw_with_their_companion() {
|
||||
dimensions: [1, 1],
|
||||
};
|
||||
let (interface, companion) = checked_companion(&authored, &fragment);
|
||||
let render = render_case(
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let render = render_case(&authored, &interface, WITHOUT_SLICE, companion.as_ref()).unwrap();
|
||||
assert_eq!(
|
||||
render.vertex.entry,
|
||||
crate::companion::PASSTHROUGH_VERTEX_ENTRY
|
||||
@@ -428,14 +386,7 @@ fn graphics_cases_map_onto_a_draw_with_their_companion() {
|
||||
offset: 0,
|
||||
length: 4,
|
||||
};
|
||||
let render = render_case(
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let render = render_case(&authored, &interface, WITHOUT_SLICE, companion.as_ref()).unwrap();
|
||||
assert_eq!(
|
||||
render.fragment.as_ref().unwrap().resources.buffers[&3],
|
||||
vec![0; 4]
|
||||
@@ -462,14 +413,7 @@ fn graphics_cases_map_onto_a_draw_with_their_companion() {
|
||||
dimensions: [1, 1],
|
||||
};
|
||||
let (interface, observer) = checked_companion(&observed, &triangle);
|
||||
let render = render_case(
|
||||
&observed,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
observer.as_ref(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let render = render_case(&observed, &interface, WITHOUT_SLICE, observer.as_ref()).unwrap();
|
||||
assert_eq!(render.vertex.entry, "vertex_varying_triangle");
|
||||
assert_eq!(
|
||||
render.fragment.as_ref().map(|f| f.entry.as_str()),
|
||||
@@ -480,7 +424,7 @@ fn graphics_cases_map_onto_a_draw_with_their_companion() {
|
||||
|
||||
// A companion that does not complete the case's stage is the executor's failure, not a gap.
|
||||
for (authored, companion) in [(&observed, None), (&authored, observer.as_ref())] {
|
||||
match render_case(authored, &interface, WITHOUT_SLICE, companion, None) {
|
||||
match render_case(authored, &interface, WITHOUT_SLICE, companion) {
|
||||
Err(ExecutorError::Failed(why)) => assert!(why.contains("has companion"), "{why}"),
|
||||
other => panic!("a mismatched companion mapped: {other:?}"),
|
||||
}
|
||||
@@ -491,7 +435,6 @@ fn graphics_cases_map_onto_a_draw_with_their_companion() {
|
||||
&kernel,
|
||||
&vertex_buffers_at(&[]),
|
||||
WITHOUT_SLICE,
|
||||
None,
|
||||
None
|
||||
))
|
||||
.contains("not a render case"));
|
||||
@@ -503,7 +446,6 @@ fn graphics_cases_map_onto_a_draw_with_their_companion() {
|
||||
&vertex,
|
||||
&vertex_buffers_at(&[0]),
|
||||
WITHOUT_SLICE,
|
||||
None,
|
||||
None
|
||||
)),
|
||||
[crate::requirement::ToolingRequirement::RasterizationDisabledRenderTarget].into()
|
||||
@@ -515,7 +457,7 @@ fn graphics_cases_map_onto_a_draw_with_their_companion() {
|
||||
#[test]
|
||||
fn a_rasterization_disabled_vertex_case_maps_onto_the_oracles_draw() {
|
||||
let case = crate::case::narrow_vertex_test_case(String::new(), "v".into());
|
||||
let render = render_case(&case, &vertex_buffers_at(&[0]), WITHOUT_SLICE, None, None).unwrap();
|
||||
let render = render_case(&case, &vertex_buffers_at(&[0]), WITHOUT_SLICE, None).unwrap();
|
||||
assert_eq!(render.fragment, None);
|
||||
assert_eq!(render.companion, None);
|
||||
assert_eq!(
|
||||
@@ -708,14 +650,12 @@ pub(crate) fn two_stage_case(
|
||||
},
|
||||
index_buffer: None,
|
||||
out_of_bounds: Vec::new(),
|
||||
imageblock: None,
|
||||
output: RenderOutput::RenderTarget {
|
||||
index: 0,
|
||||
origin: [0, 0],
|
||||
dimensions: [1, 1],
|
||||
},
|
||||
companion: None,
|
||||
rate_map_pass: None,
|
||||
raster_sample_count: None,
|
||||
}
|
||||
}
|
||||
@@ -759,13 +699,7 @@ fn planned_draw(
|
||||
};
|
||||
let addresses = case
|
||||
.stages()
|
||||
.flat_map(|(stage, f)| {
|
||||
f.resources
|
||||
.buffers
|
||||
.keys()
|
||||
.chain(f.resources.function_tables.keys())
|
||||
.map(move |&index| (stage, index))
|
||||
})
|
||||
.flat_map(|(stage, f)| f.resources.buffers.keys().map(move |&index| (stage, index)))
|
||||
.chain(
|
||||
case.vertex_buffers
|
||||
.iter()
|
||||
@@ -857,14 +791,7 @@ fn a_tessellation_case_maps_onto_the_oracles_patch_draw() {
|
||||
});
|
||||
let draw = authored.tessellation.clone().unwrap();
|
||||
let (interface, observer) = checked_companion(&authored, &bitcode);
|
||||
let render = render_case(
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
observer.as_ref(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let render = render_case(&authored, &interface, WITHOUT_SLICE, observer.as_ref()).unwrap();
|
||||
let bytes = shared::factor_bytes(&factors);
|
||||
assert_eq!(bytes.len(), 16);
|
||||
// The case's partition mode, winding, and cull mode.
|
||||
@@ -1007,7 +934,6 @@ fn owned_render_pipelines_plan_without_variants_or_diagnostics() {
|
||||
buffer_index: 30,
|
||||
format: AttributeFormat::Float2,
|
||||
stride: 8,
|
||||
dynamic: false,
|
||||
step: metal::VertexStepFunction::PerVertex,
|
||||
bytes: vec![0; 24],
|
||||
},
|
||||
@@ -1016,7 +942,6 @@ fn owned_render_pipelines_plan_without_variants_or_diagnostics() {
|
||||
buffer_index: 29,
|
||||
format: AttributeFormat::Float2,
|
||||
stride: 8,
|
||||
dynamic: false,
|
||||
step: metal::VertexStepFunction::PerVertex,
|
||||
bytes: vec![0; 24],
|
||||
},
|
||||
@@ -1076,7 +1001,7 @@ fn render_cases_bind_argument_buffer_buffers_and_texture_arrays() {
|
||||
.unwrap_or_else(|errors| panic!("{}: {errors:?}", case.name));
|
||||
let interface = &checked.primary.interface;
|
||||
let companion = checked.primary.companion.as_ref();
|
||||
let render = render_case(&case, interface, &row.air_ll, companion, None).unwrap();
|
||||
let render = render_case(&case, interface, &row.air_ll, companion).unwrap();
|
||||
let own = render.fragment.as_ref().expect("a fragment case");
|
||||
let key = (
|
||||
case.argument_buffer_buffers[0].buffer_binding,
|
||||
@@ -1235,7 +1160,7 @@ fn render_cases_bind_argument_buffer_buffers_and_texture_arrays() {
|
||||
origin: [0, 0, 0],
|
||||
dimensions: [1, 1, 1],
|
||||
};
|
||||
let render = render_case(&arrays, interface, &row.air_ll, companion, None).unwrap();
|
||||
let render = render_case(&arrays, interface, &row.air_ll, companion).unwrap();
|
||||
let textures = &render.fragment.as_ref().unwrap().resources.textures;
|
||||
assert_eq!(
|
||||
textures
|
||||
@@ -1321,7 +1246,7 @@ fn render_cases_bind_argument_buffer_buffers_and_texture_arrays() {
|
||||
origin: [1, 0, 0],
|
||||
dimensions: [1, 1, 1],
|
||||
};
|
||||
let render = render_case(&members, interface, &row.air_ll, companion, None).unwrap();
|
||||
let render = render_case(&members, interface, &row.air_ll, companion).unwrap();
|
||||
let fragment = &render.fragment.as_ref().unwrap().resources;
|
||||
assert!(fragment.buffers[&key.0].len() >= sampler_field as usize + 8);
|
||||
assert_eq!(
|
||||
@@ -1481,7 +1406,6 @@ fn a_slice_choosing_case_binds_the_oracles_one_layer_pass() {
|
||||
interface,
|
||||
&row.air_ll,
|
||||
checked.primary.companion.as_ref(),
|
||||
checked.primary.reflection.fragment_imageblock.as_ref(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
@@ -1571,7 +1495,6 @@ fn public_render_cases_plan_or_refuse_typed() {
|
||||
&checked.primary.interface,
|
||||
&row.air_ll,
|
||||
checked.primary.companion.as_ref(),
|
||||
checked.primary.reflection.fragment_imageblock.as_ref(),
|
||||
) {
|
||||
Ok(render) => render,
|
||||
Err(ExecutorError::NotSupported(
|
||||
@@ -1656,7 +1579,6 @@ fn public_tessellation_cases_plan_their_patch_draws() {
|
||||
&checked.primary.interface,
|
||||
&row.air_ll,
|
||||
checked.primary.companion.as_ref(),
|
||||
checked.primary.reflection.fragment_imageblock.as_ref(),
|
||||
)
|
||||
.unwrap_or_else(|error| panic!("{}: {error:?}", case.name));
|
||||
let factors = shared::factor_bytes(&draw.factors);
|
||||
@@ -1819,7 +1741,6 @@ fn public_framebuffer_fetch_cases_plan_their_ordered_input_attachments() {
|
||||
&checked.primary.interface,
|
||||
&row.air_ll,
|
||||
checked.primary.companion.as_ref(),
|
||||
checked.primary.reflection.fragment_imageblock.as_ref(),
|
||||
)
|
||||
.unwrap_or_else(|error| panic!("{}: {error:?}", case.name));
|
||||
for color in &colors {
|
||||
@@ -1994,7 +1915,6 @@ fn public_framebuffer_fetch_cases_plan_input_attachments_without_an_ordered_form
|
||||
&checked.primary.interface,
|
||||
&row.air_ll,
|
||||
checked.primary.companion.as_ref(),
|
||||
checked.primary.reflection.fragment_imageblock.as_ref(),
|
||||
)
|
||||
.unwrap_or_else(|error| panic!("{}: {error:?}", case.name));
|
||||
let companion = render
|
||||
@@ -2075,210 +1995,6 @@ fn a_draw_restarts_exactly_its_strips_within_its_class() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The render executor's cells follow the checked reflection's master, the one the checker
|
||||
/// validates the planes against and the Metal oracle's initializer writes and resolver reads, each
|
||||
/// member at its reflected offset with its reflected size. `imageblock_two_masters` reads `a`
|
||||
/// through an input view of `Master` (`a` at byte 0 of 16) and writes it through an output view of
|
||||
/// `Swapped` (`a` at byte 2 of 4): the reflection, and so the cells, follow the larger master,
|
||||
/// `Master`, whose cell both views reach, not the output view's. Every owned function's cell covers
|
||||
/// its reflected data size.
|
||||
#[test]
|
||||
fn the_cells_follow_the_reflected_master() {
|
||||
let views = std::fs::read_to_string(
|
||||
metal2vulkan_devtools::engine_dir().join("fragment_imageblock_views.ll"),
|
||||
)
|
||||
.unwrap();
|
||||
let custom =
|
||||
std::fs::read_to_string(fixtures_dir().join("fragment_custom_imageblock.ll")).unwrap();
|
||||
let mut compared = 0;
|
||||
for (ll, entries) in [
|
||||
(&custom, &["fragment_custom_imageblock"][..]),
|
||||
(
|
||||
&views,
|
||||
&[
|
||||
"imageblock_transition",
|
||||
"imageblock_accumulate",
|
||||
"imageblock_clear_odd",
|
||||
"imageblock_resolve",
|
||||
"imageblock_masked",
|
||||
"imageblock_two_masters",
|
||||
][..],
|
||||
),
|
||||
] {
|
||||
for &entry in entries {
|
||||
let reflected = reflected_imageblock(ll, entry)
|
||||
.unwrap_or_else(|| panic!("{entry} reflects an imageblock"));
|
||||
let layout = super::imageblock::layout(&reflected).unwrap();
|
||||
for member in &reflected.members {
|
||||
assert_eq!(
|
||||
layout.members[&member.semantic],
|
||||
super::imageblock::Member {
|
||||
offset: member.offset,
|
||||
size: member.size,
|
||||
},
|
||||
"{entry}: {}",
|
||||
member.semantic
|
||||
);
|
||||
}
|
||||
assert_eq!(layout.members.len(), reflected.members.len(), "{entry}");
|
||||
assert!(
|
||||
layout.cell_bytes >= reflected.sample_size && layout.cell_bytes.is_multiple_of(4),
|
||||
"{entry}: a {}-byte cell of a {}-byte imageblock",
|
||||
layout.cell_bytes,
|
||||
reflected.sample_size
|
||||
);
|
||||
compared += 1;
|
||||
}
|
||||
}
|
||||
assert_eq!(compared, 7);
|
||||
// `Master` is the master: `a` at byte 0 and `b` at byte 2 of a 16-byte cell, beside `tag`,
|
||||
// `sum`, and `n`.
|
||||
let two =
|
||||
super::imageblock::layout(&reflected_imageblock(&views, "imageblock_two_masters").unwrap())
|
||||
.unwrap();
|
||||
let at = |offset, size| super::imageblock::Member { offset, size };
|
||||
assert_eq!(
|
||||
two.members,
|
||||
BTreeMap::from([
|
||||
("user(a)".into(), at(0, 2)),
|
||||
("user(b)".into(), at(2, 2)),
|
||||
("user(tag)".into(), at(4, 4)),
|
||||
("user(sum)".into(), at(8, 4)),
|
||||
("user(n)".into(), at(12, 2)),
|
||||
])
|
||||
);
|
||||
assert_eq!(two.cell_bytes, 16);
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
let ll = metal2vulkan_devtools::fixtures_dir().join("fragment_rate_map_position.ll");
|
||||
let bitcode = assembled(&ll)?;
|
||||
let mut authored = crate::companion::tests::case(
|
||||
Stage::Fragment,
|
||||
"fragment_rate_map_position",
|
||||
TextureFormat::Rgba32Float,
|
||||
);
|
||||
authored.buffers = vec![crate::case::BufferResource {
|
||||
binding: 0,
|
||||
role: crate::case::ResourceRole::Input,
|
||||
bytes_b64: Some(b64(&[0; 8])),
|
||||
initial_bytes_b64: None,
|
||||
rasterization_rate_map: None,
|
||||
}];
|
||||
let (interface, companion) = checked_companion(&authored, &bitcode);
|
||||
let render = render_case(
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let vertex = render
|
||||
.companion
|
||||
.as_ref()
|
||||
.expect("a fragment case's generated vertex function")
|
||||
.opaque_bitcode()
|
||||
.unwrap();
|
||||
let shape = render_shape(&render, true, BufferRanges::default()).unwrap();
|
||||
let pipeline = compile_in_process(
|
||||
&device("lavapipe"),
|
||||
&render,
|
||||
RenderLibraries {
|
||||
vertex: &vertex,
|
||||
fragment: Some(&bitcode),
|
||||
},
|
||||
&shape,
|
||||
)
|
||||
.unwrap();
|
||||
Some(pipeline.graphics)
|
||||
}
|
||||
|
||||
/// A rate-mapped pass is planned region by region with the product's compile of its map, for the
|
||||
/// map's screen, on every device: its census states the compile's physical size and the region
|
||||
/// count; a plan the device's viewport limits cannot hold, and a vertex function that writes memory
|
||||
/// in a plan of several regions, are the binder's refusals.
|
||||
#[test]
|
||||
fn a_rate_mapped_pass_is_planned_region_by_region() {
|
||||
use metal2vulkan::bind::{
|
||||
RasterizationRateMap, RateMapDescriptor, RateMapLayerDescriptor, RegionLimits,
|
||||
};
|
||||
let compile = |screen: [u32; 2], horizontal: Vec<f32>, vertical: Vec<f32>| {
|
||||
let mut descriptor = RateMapDescriptor::new(screen);
|
||||
descriptor.layers = vec![RateMapLayerDescriptor::new(horizontal, vertical)];
|
||||
RasterizationRateMap::new(&descriptor).unwrap()
|
||||
};
|
||||
let limits = RegionLimits::new([4096, 4096], [-8192.0, 8191.0]);
|
||||
// The graphics state of the position fixture drawn by its generated vertex function, which
|
||||
// writes no memory; and the same state as if its vertex function wrote memory.
|
||||
let Some(pure) = rate_map_position_graphics() else {
|
||||
return;
|
||||
};
|
||||
assert!(!pure.vertex_writes_memory);
|
||||
let graphics = |vertex_writes_memory: bool| {
|
||||
let mut state = pure.clone();
|
||||
state.vertex_writes_memory = vertex_writes_memory;
|
||||
state
|
||||
};
|
||||
// The crate compiles this map to 36x23, as Apple M3 does: 33 screen pixels to 32, then 4 to 4,
|
||||
// across.
|
||||
let skewed = compile([37, 23], vec![0.5, 1.0], vec![1.0, 0.5]);
|
||||
let plan = rate_map_regions(&skewed, &limits, &graphics(false)).unwrap();
|
||||
assert_eq!(plan.physical_size(), [36, 23]);
|
||||
assert_eq!(
|
||||
rate_map_pass_census(&skewed, &plan),
|
||||
RateMapPassRun {
|
||||
screen_size: [37, 23],
|
||||
compiled_physical_size: [36, 23],
|
||||
regions: 2,
|
||||
precision: [PrecisionNote::RasterizationRateMap].into(),
|
||||
}
|
||||
);
|
||||
let mut layered = graphics(false);
|
||||
layered.declares_layer = true;
|
||||
for refused in [
|
||||
rate_map_regions(&skewed, &limits, &graphics(true)),
|
||||
rate_map_regions(&skewed, &limits, &layered),
|
||||
rate_map_regions(
|
||||
&skewed,
|
||||
&RegionLimits::new([16, 4096], [-8192.0, 8191.0]),
|
||||
&graphics(false),
|
||||
),
|
||||
] {
|
||||
match refused {
|
||||
Err(ExecutorError::NotSupported(NotSupported::Bind(why))) => {
|
||||
assert!(why.starts_with("rate-mapped render pass: "), "{why}");
|
||||
}
|
||||
other => panic!("expected the binder's refusal, got {other:?}"),
|
||||
}
|
||||
}
|
||||
// 32x32 at half quality compiles to the identity, as Apple M3 compiles it: one region, which
|
||||
// admits a vertex function that writes memory.
|
||||
let identity = compile([32, 32], vec![0.5], vec![0.5]);
|
||||
assert!(identity.is_identity());
|
||||
let plan = rate_map_regions(&identity, &limits, &graphics(true)).unwrap();
|
||||
assert_eq!(plan.regions().len(), 1);
|
||||
// The identity is Metal's pass exactly; every other map's pass is the decoder's
|
||||
// near-equivalent.
|
||||
assert!(rate_map_pass_census(&identity, &plan).precision.is_empty());
|
||||
// 0.25 compiles 126 screen pixels to 32 and the last 2 to 1, across, and 32 rows to 16: a
|
||||
// pass of tiles more than twice as wide as their physical pixels is drawn by regions too.
|
||||
let quarter = compile([128, 32], vec![0.25], vec![0.25]);
|
||||
let plan = rate_map_regions(&quarter, &limits, &graphics(false)).unwrap();
|
||||
assert_eq!((plan.physical_size(), plan.regions().len()), ([33, 16], 2));
|
||||
// The other authored cases' maps, whose outputs are these physical regions: 80x40 at 0.5 (63:32
|
||||
// then 17:16 across, 40 rows to 32), and a graded 120x60 map (32:32, 53:32, then 32:32 and 3:3
|
||||
// on one line across; 41:32 and 19:19 down).
|
||||
let half = compile([80, 40], vec![0.5], vec![0.5]);
|
||||
let plan = rate_map_regions(&half, &limits, &graphics(false)).unwrap();
|
||||
assert_eq!((plan.physical_size(), plan.regions().len()), ([48, 32], 2));
|
||||
let graded = compile([120, 60], vec![1.0, 0.25, 1.0], vec![0.25, 1.0]);
|
||||
let plan = rate_map_regions(&graded, &limits, &graphics(false)).unwrap();
|
||||
assert_eq!((plan.physical_size(), plan.regions().len()), ([99, 51], 6));
|
||||
}
|
||||
|
||||
/// A render case of one sample draws as before: its template names no sample count (so the pipeline
|
||||
/// keeps Metal's default of one, and the template crosses the compile worker's exchange in the
|
||||
/// bytes it always did), and its attachments are uploaded and read back by copies. A multisampled
|
||||
@@ -2316,21 +2032,3 @@ fn a_render_case_of_one_sample_draws_as_it_always_did() {
|
||||
let text = serde_json::to_string(&template).unwrap();
|
||||
assert!(text.contains("\"raster_sample_count\":4"), "{text}");
|
||||
}
|
||||
|
||||
/// A vertex buffer of a dynamic layout: its layout's stride is `MTLBufferLayoutStrideDynamic`, so
|
||||
/// the fetch reads the stride the buffer is bound with; a fixed layout's is its stride.
|
||||
#[test]
|
||||
fn a_dynamic_vertex_layout_takes_the_bound_stride() {
|
||||
let buffer = |location, buffer_index, dynamic| VertexBuffer {
|
||||
location,
|
||||
buffer_index,
|
||||
format: AttributeFormat::Uint,
|
||||
stride: 8,
|
||||
dynamic,
|
||||
step: metal::VertexStepFunction::PerVertex,
|
||||
bytes: vec![0; 32],
|
||||
};
|
||||
let descriptor = vertex_descriptor(&[buffer(0, 30, true), buffer(1, 29, false)]).unwrap();
|
||||
assert_eq!(descriptor.layouts[&30].stride, None);
|
||||
assert_eq!(descriptor.layouts[&29].stride, Some(8));
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
//! each target in an allocation of its own).
|
||||
|
||||
use super::ComputeCase;
|
||||
use crate::case::out_of_bounds::{ContainmentForm, OutOfBoundsResource, OutOfBoundsTarget};
|
||||
use crate::case::out_of_bounds::{OutOfBoundsResource, OutOfBoundsTarget};
|
||||
use crate::executor_contract::out_of_bounds::{self, OutOfBoundsRun};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@@ -43,26 +43,13 @@ pub fn declared_reach(
|
||||
})
|
||||
}
|
||||
|
||||
/// The out-of-bounds target the buffer at Metal index `index` holds in `case`: the buffer
|
||||
/// itself, or the stage input whose data the buffer binds.
|
||||
pub fn buffer_target(case: &ComputeCase, index: u32) -> OutOfBoundsResource {
|
||||
let stage_input = case.stage_input.as_ref().and_then(|descriptor| {
|
||||
descriptor
|
||||
.attributes
|
||||
.iter()
|
||||
.find(|(_, attribute)| attribute.buffer_index == index)
|
||||
.map(|(&location, _)| location)
|
||||
});
|
||||
match stage_input {
|
||||
Some(location) => OutOfBoundsResource::AttributeBuffer { location },
|
||||
None => OutOfBoundsResource::Buffer { binding: index },
|
||||
}
|
||||
}
|
||||
|
||||
/// The guard reach of the buffer at Metal index `index` when `case` declares it, or the stage
|
||||
/// input it binds, an out-of-bounds target.
|
||||
/// The guard reach of the buffer at Metal index `index` when `case` declares it an out-of-bounds
|
||||
/// target.
|
||||
pub fn guard_reach(case: &ComputeCase, index: u32) -> Option<GuardReach> {
|
||||
declared_reach(&case.out_of_bounds, buffer_target(case, index))
|
||||
declared_reach(
|
||||
&case.out_of_bounds,
|
||||
OutOfBoundsResource::Buffer { binding: index },
|
||||
)
|
||||
}
|
||||
|
||||
/// The guard reach of the argument-buffer buffer at `(owner, field offset)` when `case` declares
|
||||
@@ -80,20 +67,6 @@ pub fn embedded_guard_reach(
|
||||
)
|
||||
}
|
||||
|
||||
/// The guard reach of the texture at Metal slot `binding` when `case` declares it an
|
||||
/// out-of-bounds target of the texel-buffer form: a texture buffer, whose texels are buffer
|
||||
/// memory. An image's memory is opaque and has no guard.
|
||||
pub fn texel_guard_reach(case: &ComputeCase, binding: u32) -> Option<GuardReach> {
|
||||
case.out_of_bounds.iter().find_map(|target| {
|
||||
(target.resource == OutOfBoundsResource::Texture { binding }
|
||||
&& target.form == ContainmentForm::TexelBuffer)
|
||||
.then_some(GuardReach {
|
||||
before: target.reach_before,
|
||||
after: target.reach_after,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// `run` with the guard and padding bytes the run changed around each target it guarded (a
|
||||
/// buffer, an argument buffer's included, an attribute buffer, an index buffer, or a texture
|
||||
/// buffer), as it counted them by target, each target in an allocation of its own.
|
||||
|
||||
@@ -1,285 +0,0 @@
|
||||
//! A fragment case's imageblock in the engine render candidate.
|
||||
//!
|
||||
//! Metal keeps a fragment function's explicit imageblock in tile memory: one cell per pixel, of
|
||||
//! the master layout's bytes, undefined when the render pass begins. The Metal oracle defines
|
||||
//! every cell before the case's draw: its generated initializer, drawn first in the same pass,
|
||||
//! writes each master member's authored plane (zero for a member the case does not author), and
|
||||
//! its resolver, drawn after the case's draw, reads the selected member's plane
|
||||
//! (`metal::platform::imageblocks`). So a case observes only cells the oracle defined, and never
|
||||
//! a byte the pass left undefined.
|
||||
//!
|
||||
//! The render executor holds the same cells. The product compiles no fragment function that reads
|
||||
//! or writes an imageblock (`Feature::Imageblocks`), so a draw leaves them as the initializer left
|
||||
//! them. The cells follow the master of the checked reflection ([`layout`]), the one the checker
|
||||
//! validates the planes against and the oracle's initializer and resolver use. [`Cells::initial`]
|
||||
//! lays the authored planes out at their master members' offsets, and [`Cells::select`] is the
|
||||
//! oracle resolver's plane of one member. Bytes no member covers are zero.
|
||||
|
||||
use crate::air::reflect::FragmentImageblock;
|
||||
use crate::literal::LiteralFragmentImageblock;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// One member of a master layout: its byte offset in the cell and its size in bytes, as the
|
||||
/// reflection states them (an array member, which is refused, is never drawn).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Member {
|
||||
pub offset: u32,
|
||||
pub size: u32,
|
||||
}
|
||||
|
||||
/// The master layout a fragment function's imageblock views view (MSL §4.7.1): its members by
|
||||
/// user key, which is what an authored plane's `semantic` names, and the bytes of one cell.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Layout {
|
||||
pub members: BTreeMap<String, Member>,
|
||||
/// The master's `air.imageblock_data_size`, or the end of its last member if larger, rounded
|
||||
/// up to a whole word.
|
||||
pub cell_bytes: u32,
|
||||
}
|
||||
|
||||
impl Layout {
|
||||
/// The 32-bit words of one cell.
|
||||
pub fn words(&self) -> u32 {
|
||||
self.cell_bytes / 4
|
||||
}
|
||||
}
|
||||
|
||||
/// The master layout of a fragment function's explicit imageblock, from the checked reflection
|
||||
/// (`ShaderInterface::fragment_imageblock`): the largest master of the function's views (the
|
||||
/// first output view's on a tie, else the first input view's), each member at its reflected
|
||||
/// offset, keyed by its semantic, and the cell [`crate::check::caps::fragment_imageblock_cell_bytes`]
|
||||
/// long, the size the checker caps.
|
||||
///
|
||||
/// Views of two masters each reach their own master's bytes of the one cell, which spans the
|
||||
/// larger (as the product plans them). The cells are the bytes the Metal oracle's pass holds, which
|
||||
/// its initializer writes and its resolver reads through this master; each view the product plans
|
||||
/// reads and writes them through its own master, as Metal's does. Two members of one semantic, and
|
||||
/// a cell past `u32` bytes, are refused.
|
||||
pub fn layout(reflected: &FragmentImageblock) -> Result<Layout, String> {
|
||||
let mut members = BTreeMap::new();
|
||||
for member in &reflected.members {
|
||||
let at = Member {
|
||||
offset: member.offset,
|
||||
size: member.size,
|
||||
};
|
||||
if members.insert(member.semantic.clone(), at).is_some() {
|
||||
return Err(format!(
|
||||
"two imageblock master members are named {}",
|
||||
member.semantic
|
||||
));
|
||||
}
|
||||
}
|
||||
let cell_bytes = u32::try_from(crate::check::caps::fragment_imageblock_cell_bytes(
|
||||
reflected,
|
||||
))
|
||||
.map_err(|_| "an imageblock cell past u32 bytes")?;
|
||||
Ok(Layout {
|
||||
members,
|
||||
cell_bytes,
|
||||
})
|
||||
}
|
||||
|
||||
/// Every pixel's cell of a pass's imageblock: `dimensions` pixels in rows, each `cell_bytes`
|
||||
/// bytes.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Cells {
|
||||
pub dimensions: [u32; 2],
|
||||
pub cell_bytes: u32,
|
||||
pub bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Cells {
|
||||
/// The cells the Metal oracle's initializer writes before the case's draw: each authored
|
||||
/// plane at its master member's offset in every pixel's cell, every other byte zero.
|
||||
pub fn initial(layout: &Layout, authored: &LiteralFragmentImageblock) -> Result<Cells, String> {
|
||||
let [width, height] = authored.dimensions;
|
||||
let pixels = width as usize * height as usize;
|
||||
let cell = layout.cell_bytes as usize;
|
||||
// The checker caps the cells with the case's resources
|
||||
// (`caps::fragment_imageblock_cap_errors`); this bounds an unchecked caller too.
|
||||
let length = pixels
|
||||
.checked_mul(cell)
|
||||
.filter(|&length| length as u64 <= crate::check::caps::MAX_RESOURCE_BYTES)
|
||||
.ok_or_else(|| {
|
||||
format!("{width}x{height} imageblock cells of {cell} bytes exceed the resource cap")
|
||||
})?;
|
||||
let mut bytes = vec![0; length];
|
||||
for plane in &authored.members {
|
||||
let at = layout.members.get(&plane.semantic).ok_or_else(|| {
|
||||
format!(
|
||||
"authored imageblock plane {} names no member of the master",
|
||||
plane.semantic
|
||||
)
|
||||
})?;
|
||||
let size = plane.format.byte_size();
|
||||
if size != at.size as usize {
|
||||
return Err(format!(
|
||||
"imageblock plane {} is {size}-byte {:?}, its master member {} bytes",
|
||||
plane.semantic, plane.format, at.size
|
||||
));
|
||||
}
|
||||
if plane.bytes.len() != pixels * size {
|
||||
return Err(format!(
|
||||
"imageblock plane {} holds {} bytes, not {width}x{height} of {size}",
|
||||
plane.semantic,
|
||||
plane.bytes.len()
|
||||
));
|
||||
}
|
||||
let offset = at.offset as usize;
|
||||
for (pixel, value) in plane.bytes.chunks_exact(size).enumerate() {
|
||||
let start = pixel * cell + offset;
|
||||
bytes[start..start + size].copy_from_slice(value);
|
||||
}
|
||||
}
|
||||
Ok(Cells {
|
||||
dimensions: authored.dimensions,
|
||||
cell_bytes: layout.cell_bytes,
|
||||
bytes,
|
||||
})
|
||||
}
|
||||
|
||||
/// The `(origin, dimensions)` region of `member`'s plane, rows in order, tightly packed: what
|
||||
/// the Metal oracle's resolver writes and its readback selects.
|
||||
pub fn select(
|
||||
&self,
|
||||
member: Member,
|
||||
origin: [u32; 2],
|
||||
dimensions: [u32; 2],
|
||||
) -> Result<Vec<u8>, String> {
|
||||
let cell = self.cell_bytes as usize;
|
||||
let (offset, size) = (member.offset as usize, member.size as usize);
|
||||
if offset + size > cell {
|
||||
return Err(format!(
|
||||
"imageblock member at {offset}+{size} exceeds its {cell}-byte cell"
|
||||
));
|
||||
}
|
||||
let plane: Vec<u8> = self
|
||||
.bytes
|
||||
.chunks_exact(cell)
|
||||
.flat_map(|bytes| &bytes[offset..offset + size])
|
||||
.copied()
|
||||
.collect();
|
||||
crate::literal::select_tightly_packed_2d(&plane, self.dimensions, origin, dimensions, size)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::case::{FragmentImageblockFormat, ResourceRole};
|
||||
use crate::literal::LiteralFragmentImageblockMember;
|
||||
|
||||
fn plane(
|
||||
semantic: &str,
|
||||
format: FragmentImageblockFormat,
|
||||
bytes: Vec<u8>,
|
||||
) -> LiteralFragmentImageblockMember {
|
||||
LiteralFragmentImageblockMember {
|
||||
semantic: semantic.into(),
|
||||
format,
|
||||
role: ResourceRole::InOut,
|
||||
bytes,
|
||||
}
|
||||
}
|
||||
|
||||
/// A master of `a` (half at 0), `b` (half at 2, the high half of word 0), `tag` (uchar4 at 4),
|
||||
/// and `n` (ushort at 8) in a 12-byte cell, over 2x1 pixels.
|
||||
fn master() -> Layout {
|
||||
Layout {
|
||||
members: BTreeMap::from([
|
||||
("a".into(), Member { offset: 0, size: 2 }),
|
||||
("b".into(), Member { offset: 2, size: 2 }),
|
||||
("tag".into(), Member { offset: 4, size: 4 }),
|
||||
("n".into(), Member { offset: 8, size: 2 }),
|
||||
]),
|
||||
cell_bytes: 12,
|
||||
}
|
||||
}
|
||||
|
||||
/// Each plane lands at its member's offset in every cell, little-endian within the words, an
|
||||
/// unauthored member and the padding are zero, and a member's plane selects exactly its bytes.
|
||||
#[test]
|
||||
fn cells_lay_planes_out_at_master_offsets() {
|
||||
use FragmentImageblockFormat as F;
|
||||
let authored = LiteralFragmentImageblock {
|
||||
dimensions: [2, 1],
|
||||
members: vec![
|
||||
plane("b", F::Half, vec![0x11, 0x22, 0x33, 0x44]),
|
||||
plane("tag", F::Uchar4, vec![1, 2, 3, 4, 5, 6, 7, 8]),
|
||||
plane("n", F::Ushort, vec![0xaa, 0xbb, 0xcc, 0xdd]),
|
||||
],
|
||||
};
|
||||
let cells = Cells::initial(&master(), &authored).unwrap();
|
||||
assert_eq!(
|
||||
cells.bytes,
|
||||
[
|
||||
[0, 0, 0x11, 0x22, 1, 2, 3, 4, 0xaa, 0xbb, 0, 0],
|
||||
[0, 0, 0x33, 0x44, 5, 6, 7, 8, 0xcc, 0xdd, 0, 0],
|
||||
]
|
||||
.concat()
|
||||
);
|
||||
assert_eq!(
|
||||
cells
|
||||
.select(Member { offset: 2, size: 2 }, [0, 0], [2, 1])
|
||||
.unwrap(),
|
||||
[0x11, 0x22, 0x33, 0x44]
|
||||
);
|
||||
assert_eq!(
|
||||
cells
|
||||
.select(Member { offset: 4, size: 4 }, [1, 0], [1, 1])
|
||||
.unwrap(),
|
||||
[5, 6, 7, 8]
|
||||
);
|
||||
assert!(cells
|
||||
.select(
|
||||
Member {
|
||||
offset: 10,
|
||||
size: 4
|
||||
},
|
||||
[0, 0],
|
||||
[1, 1]
|
||||
)
|
||||
.is_err());
|
||||
assert!(cells
|
||||
.select(Member { offset: 0, size: 2 }, [1, 0], [2, 1])
|
||||
.is_err());
|
||||
}
|
||||
|
||||
/// Cells past the resource cap are refused before they are allocated.
|
||||
#[test]
|
||||
fn the_cells_are_capped() {
|
||||
let huge = Layout {
|
||||
members: BTreeMap::new(),
|
||||
cell_bytes: 1 << 12,
|
||||
};
|
||||
let refused = Cells::initial(
|
||||
&huge,
|
||||
&LiteralFragmentImageblock {
|
||||
dimensions: [1024, 1024],
|
||||
members: vec![],
|
||||
},
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(refused.contains("exceed the resource cap"), "{refused}");
|
||||
}
|
||||
|
||||
/// A plane that names no master member, has another member's size, or holds the wrong number
|
||||
/// of bytes is refused.
|
||||
#[test]
|
||||
fn a_plane_must_be_a_master_member_of_its_size() {
|
||||
use FragmentImageblockFormat as F;
|
||||
let refused = |member| {
|
||||
Cells::initial(
|
||||
&master(),
|
||||
&LiteralFragmentImageblock {
|
||||
dimensions: [2, 1],
|
||||
members: vec![member],
|
||||
},
|
||||
)
|
||||
.unwrap_err()
|
||||
};
|
||||
assert!(refused(plane("c", F::Half, vec![0; 4])).contains("names no member"));
|
||||
assert!(refused(plane("tag", F::Half, vec![0; 4])).contains("master member 4 bytes"));
|
||||
assert!(refused(plane("a", F::Half, vec![0; 2])).contains("holds 2 bytes"));
|
||||
}
|
||||
}
|
||||
@@ -280,7 +280,7 @@ pub fn mesh_shape(
|
||||
attribute_stride: None,
|
||||
}
|
||||
};
|
||||
let table = graphics::stage_table(stage, function, bound).map_err(ExecutorError::Failed)?;
|
||||
let table = graphics::stage_table(function, bound).map_err(ExecutorError::Failed)?;
|
||||
state.stages.insert(stage, table);
|
||||
}
|
||||
Ok(views_told_apart(state, ranges).shape())
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
//! decides (`variants`), and planned by the binder, or refused typed. No device is opened.
|
||||
|
||||
use super::*;
|
||||
use crate::check::loop_free::DecodedModule;
|
||||
use crate::source::public_sources;
|
||||
use metal2vulkan::bind::{ImageSource, WriteSource};
|
||||
use metal2vulkan::device::FormatUsage;
|
||||
@@ -85,19 +84,6 @@ fn lacks_a_bound_format(device: &Device, case: &AuthoredCase, sets: &[Vec<Capabi
|
||||
})
|
||||
}
|
||||
|
||||
/// The AIR-layer interface of `case`'s entry in `bitcode`, as the checker derives it.
|
||||
fn interface(case: &AuthoredCase, bitcode: &[u8]) -> AirInterface {
|
||||
let decoded = DecodedModule::from_bitcode(&case.entry, bitcode).unwrap();
|
||||
let constants = crate::check::case_constants(case).unwrap();
|
||||
AirInterface::new(
|
||||
decoded.module(),
|
||||
decoded.abi().unwrap(),
|
||||
&case.entry,
|
||||
&constants,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn plan_case(device: &Device, case: &AuthoredCase, row: &crate::source::SourceRow) -> Planned {
|
||||
let scratch = crate::ScratchDir::new("public-texture-case").unwrap();
|
||||
let ll = scratch.path().join("case.ll");
|
||||
@@ -107,7 +93,7 @@ fn plan_case(device: &Device, case: &AuthoredCase, row: &crate::source::SourceRo
|
||||
Err(AssembleError::Missing(why)) => return Planned::NoAssembler(why),
|
||||
Err(AssembleError::Rejected(why)) => return Planned::Unassembled(why),
|
||||
};
|
||||
let Ok(compute) = compute_case(case, &interface(case, &bitcode)) else {
|
||||
let Ok(compute) = compute_case(case) else {
|
||||
return Planned::Refused;
|
||||
};
|
||||
let library = Library::from_air(&bitcode).unwrap();
|
||||
@@ -119,7 +105,6 @@ fn plan_case(device: &Device, case: &AuthoredCase, row: &crate::source::SourceRo
|
||||
&function,
|
||||
&shape,
|
||||
Some(&compute.dispatch),
|
||||
compute.stage_input.as_ref(),
|
||||
&Budget::standard(),
|
||||
) {
|
||||
Ok(compiled) => compiled,
|
||||
@@ -338,7 +323,7 @@ fn public_texture_array_cases_plan_their_elements_at_their_slots() {
|
||||
panic!("{}: llvm-as rejected it: {why}", case.name)
|
||||
}
|
||||
};
|
||||
let compute = compute_case(case, &interface(case, &bitcode)).unwrap();
|
||||
let compute = compute_case(case).unwrap();
|
||||
let slots = case
|
||||
.texture_arrays
|
||||
.iter()
|
||||
@@ -363,7 +348,6 @@ fn public_texture_array_cases_plan_their_elements_at_their_slots() {
|
||||
&function,
|
||||
&shape,
|
||||
None,
|
||||
None,
|
||||
&Budget::standard(),
|
||||
);
|
||||
let sampled = device
|
||||
@@ -459,7 +443,7 @@ fn the_public_argument_buffer_cases_plan_their_pointees_resident() {
|
||||
panic!("{}: llvm-as rejected it: {why}", case.name)
|
||||
}
|
||||
};
|
||||
let compute = compute_case(case, &interface(case, &bitcode)).unwrap();
|
||||
let compute = compute_case(case).unwrap();
|
||||
assert_eq!(
|
||||
compute.argument_buffer_buffers.len(),
|
||||
case.argument_buffer_buffers.len(),
|
||||
@@ -495,7 +479,6 @@ fn the_public_argument_buffer_cases_plan_their_pointees_resident() {
|
||||
&function,
|
||||
&shape,
|
||||
Some(&compute.dispatch),
|
||||
None,
|
||||
&Budget::standard(),
|
||||
)
|
||||
.unwrap_or_else(|error| panic!("{} {stem}: compile: {error:?}", case.name));
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
//! Visible-function tables in the engine candidate.
|
||||
//!
|
||||
//! A case's `visible_function_tables` are bound as the product's binder says a consumer binds a
|
||||
//! table (`bind::table`): a buffer the consumer owns, bound at the table's Metal buffer index as a
|
||||
//! `BoundBuffer::Buffer` of the table's stage, holding the table's `FunctionTableWords`: a bound
|
||||
//! table of the authored size, each authored entry the `FunctionHandle` of the function it holds,
|
||||
//! every other entry null. A function's handle is what `LinkedFunctions::function_handle` answers
|
||||
//! over the linked functions the compile built for the stage's function. Those exist only in the
|
||||
//! compile worker, so the worker returns the handles with the pipeline
|
||||
//! ([`crate::acceptance::LinkedHandles`]), and the executor encodes the words here. The Metal
|
||||
//! oracle builds the same table with `newVisibleFunctionTableWithDescriptor:` and
|
||||
//! `setFunction:atIndex:` of `functionHandleWithFunction:` over the same linked functions.
|
||||
|
||||
use super::LinkedModule;
|
||||
use crate::acceptance::LinkedHandles;
|
||||
use crate::case::FunctionTableResource;
|
||||
use crate::check::admission::{ExecutorError, NotSupported};
|
||||
use metal2vulkan::bind::FunctionTableWords;
|
||||
use metal2vulkan::pipeline::Stage as ShaderStage;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// The bytes of each visible-function table's buffer, by stage and Metal buffer index: what a run
|
||||
/// binds there.
|
||||
pub type TableBuffers = BTreeMap<(ShaderStage, u32), Vec<u8>>;
|
||||
|
||||
/// One authored visible-function table: its size (`functionCount`) and the linked function each
|
||||
/// non-null entry holds, by entry index.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct FunctionTable {
|
||||
pub size: u32,
|
||||
pub entries: BTreeMap<u32, TableFunction>,
|
||||
}
|
||||
|
||||
/// The linked function a table entry holds: its module, by SHA-256, and its Metal name.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct TableFunction {
|
||||
pub module_sha256: String,
|
||||
pub function: String,
|
||||
}
|
||||
|
||||
impl FunctionTable {
|
||||
/// The length in bytes of the table's buffer (`FunctionTableWords::byte_len`).
|
||||
pub fn byte_len(&self) -> u64 {
|
||||
FunctionTableWords::byte_len(self.size)
|
||||
}
|
||||
}
|
||||
|
||||
/// The case's visible-function tables (`authored`), by Metal buffer index. A table bound twice,
|
||||
/// an entry set twice, and an entry past the table's size are refused (the case checker refuses
|
||||
/// each first).
|
||||
pub fn function_tables(
|
||||
authored: &[FunctionTableResource],
|
||||
) -> Result<BTreeMap<u32, FunctionTable>, NotSupported> {
|
||||
let gap = |what: String| NotSupported::NotImplemented(format!("engine candidate: {what}"));
|
||||
let mut tables = BTreeMap::new();
|
||||
for table in authored {
|
||||
let mut entries = BTreeMap::new();
|
||||
for entry in &table.entries {
|
||||
if entry.index >= table.size {
|
||||
return Err(gap(format!(
|
||||
"visible function table {} entry {} is past its size {}",
|
||||
table.binding, entry.index, table.size
|
||||
)));
|
||||
}
|
||||
let function = TableFunction {
|
||||
module_sha256: entry.module_sha256.clone(),
|
||||
function: entry.function.clone(),
|
||||
};
|
||||
if entries.insert(entry.index, function).is_some() {
|
||||
return Err(gap(format!(
|
||||
"visible function table {} entry {} set twice",
|
||||
table.binding, entry.index
|
||||
)));
|
||||
}
|
||||
}
|
||||
let table_value = FunctionTable {
|
||||
size: table.size,
|
||||
entries,
|
||||
};
|
||||
if tables.insert(table.binding, table_value).is_some() {
|
||||
return Err(gap(format!(
|
||||
"visible function table {} bound twice",
|
||||
table.binding
|
||||
)));
|
||||
}
|
||||
}
|
||||
Ok(tables)
|
||||
}
|
||||
|
||||
/// The buffer bytes of each of `tables`, a `stage` function's, keyed by `stage` and Metal index:
|
||||
/// `FunctionTableWords` of the table's size with each entry the handle of the function it holds.
|
||||
/// `handles` are the function's linked handles ([`crate::acceptance::LinkedHandles`]), which
|
||||
/// answer its linked libraries `linked` in order; an entry's function is found in them by module
|
||||
/// and name. A function that is not linked, or that the product gives no handle, fails the run:
|
||||
/// the executor links every table entry into `functions` ([`super::linked_modules`]), each of
|
||||
/// which has one.
|
||||
pub fn table_buffers(
|
||||
stage: ShaderStage,
|
||||
tables: &BTreeMap<u32, FunctionTable>,
|
||||
linked: &[LinkedModule],
|
||||
handles: &LinkedHandles,
|
||||
) -> Result<TableBuffers, ExecutorError> {
|
||||
let mut buffers = TableBuffers::new();
|
||||
for (&binding, table) in tables {
|
||||
let mut words = FunctionTableWords::new(table.size);
|
||||
for (&index, entry) in &table.entries {
|
||||
let handle = linked
|
||||
.iter()
|
||||
.zip(handles)
|
||||
.find(|(module, _)| module.module_sha256 == entry.module_sha256)
|
||||
.and_then(|(module, handles)| {
|
||||
let at = module
|
||||
.library
|
||||
.functions
|
||||
.iter()
|
||||
.position(|name| *name == entry.function)?;
|
||||
handles.get(at).copied()
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
ExecutorError::Failed(format!(
|
||||
"visible function table {binding} entry {index}: {} of module {} is not \
|
||||
linked",
|
||||
entry.function, entry.module_sha256
|
||||
))
|
||||
})?
|
||||
.ok_or_else(|| {
|
||||
ExecutorError::Failed(format!(
|
||||
"visible function table {binding} entry {index}: the product gives linked \
|
||||
function {} no table handle",
|
||||
entry.function
|
||||
))
|
||||
})?;
|
||||
if !words.set(index, Some(handle)) {
|
||||
return Err(ExecutorError::Failed(format!(
|
||||
"visible function table {binding} has no entry {index}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
buffers.insert((stage, binding), words.to_bytes());
|
||||
}
|
||||
Ok(buffers)
|
||||
}
|
||||
@@ -101,20 +101,7 @@ fn the_status_starts_zero_and_stops_non_evidence() {
|
||||
/// [`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, &kernel_interface(vec![]))
|
||||
}
|
||||
|
||||
/// The AIR-layer interface of a kernel with `params`.
|
||||
fn kernel_interface(params: Vec<crate::check::interface::Param>) -> AirInterface {
|
||||
AirInterface::synthetic(
|
||||
metal2vulkan_air::abi::Stage::Kernel {
|
||||
max_total_threads: None,
|
||||
work_group_size: None,
|
||||
},
|
||||
params,
|
||||
vec![],
|
||||
vec![],
|
||||
)
|
||||
compute_case(case)
|
||||
}
|
||||
|
||||
fn kernel_case() -> AuthoredCase {
|
||||
@@ -349,108 +336,6 @@ fn references_link_and_function_tables_are_typed_gaps() {
|
||||
assert_eq!(map_kernel(&encoded).map(|_| ()), encoded_table);
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// words' length at its index, in the shape the compile is asked for. A function that is not
|
||||
/// linked, or that has no handle, fails the run.
|
||||
#[test]
|
||||
fn a_tables_words_are_its_size_and_the_handles_of_its_functions() {
|
||||
use crate::acceptance::LinkedHandles;
|
||||
use metal2vulkan::pipeline::FunctionHandle;
|
||||
// The handles a compile of a kernel linking `[a, b]` of one module and `[c]` of another
|
||||
// gives (`functions` numbered from 2), as they cross the worker exchange.
|
||||
let handle = |word: u32| {
|
||||
Some(serde_json::from_value::<FunctionHandle>(serde_json::json!(word)).unwrap())
|
||||
};
|
||||
let handles: LinkedHandles = vec![vec![handle(2), handle(3)], vec![handle(4)]];
|
||||
let module = |sha: &str, names: &[&str]| LinkedModule {
|
||||
module_sha256: sha.repeat(32),
|
||||
bitcode: Vec::new(),
|
||||
library: LinkedLibrary {
|
||||
functions: names.iter().map(|name| (*name).to_owned()).collect(),
|
||||
},
|
||||
};
|
||||
let linked = [module("aa", &["a", "b"]), module("bb", &["c"])];
|
||||
let entry = |sha: &str, function: &str| tables::TableFunction {
|
||||
module_sha256: sha.repeat(32),
|
||||
function: function.into(),
|
||||
};
|
||||
let table = FunctionTable {
|
||||
size: 5,
|
||||
entries: BTreeMap::from([
|
||||
(0, entry("bb", "c")),
|
||||
(1, entry("aa", "a")),
|
||||
(3, entry("aa", "b")),
|
||||
(4, entry("bb", "c")),
|
||||
]),
|
||||
};
|
||||
let tables_at = BTreeMap::from([(7, table.clone())]);
|
||||
let buffers = table_buffers(ShaderStage::Kernel, &tables_at, &linked, &handles).unwrap();
|
||||
let words = |bytes: &[u8]| {
|
||||
bytes
|
||||
.as_chunks::<4>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|word| u32::from_le_bytes(*word))
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(buffers.len(), 1);
|
||||
let bytes = &buffers[&(ShaderStage::Kernel, 7)];
|
||||
assert_eq!(words(bytes), [1, 5, 4, 2, 0, 3, 4]);
|
||||
assert_eq!(bytes.len() as u64, table.byte_len());
|
||||
|
||||
// The kernel's bind state binds the table as a buffer of that length, in the shape.
|
||||
let mut case = map_kernel(&kernel_case()).unwrap();
|
||||
case.function_tables = tables_at.clone();
|
||||
let state = bind_state(
|
||||
&case,
|
||||
&BTreeMap::from([(7, BufferAddress::synthetic(7))]),
|
||||
&BTreeMap::new(),
|
||||
BufferRanges::default(),
|
||||
)
|
||||
.unwrap();
|
||||
match state.stages[&ShaderStage::Kernel].buffers.get(&7) {
|
||||
Some(BoundBuffer::Buffer { length, .. }) => assert_eq!(*length, table.byte_len()),
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
let shape = compute_shape(&case, false, BufferRanges::default()).unwrap();
|
||||
assert_eq!(state.shape(), shape);
|
||||
assert_eq!(
|
||||
compute_tables(&case, &linked, std::slice::from_ref(&handles)).unwrap(),
|
||||
buffers
|
||||
);
|
||||
assert!(compute_tables(&case, &linked, &[]).is_err());
|
||||
|
||||
// An entry whose function is not linked, or which has no handle, fails the run.
|
||||
let mut stray = tables_at.clone();
|
||||
stray
|
||||
.get_mut(&7)
|
||||
.unwrap()
|
||||
.entries
|
||||
.insert(2, entry("cc", "c"));
|
||||
match table_buffers(ShaderStage::Kernel, &stray, &linked, &handles) {
|
||||
Err(ExecutorError::Failed(why)) => assert!(why.contains("not linked"), "{why}"),
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
let mut unhandled: LinkedHandles = handles.clone();
|
||||
unhandled[1][0] = None;
|
||||
match table_buffers(ShaderStage::Kernel, &tables_at, &linked, &unhandled) {
|
||||
Err(ExecutorError::Failed(why)) => assert!(why.contains("no table handle"), "{why}"),
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
// Without entries the table is bound, sized, and all null.
|
||||
let empty = BTreeMap::from([(
|
||||
3,
|
||||
FunctionTable {
|
||||
size: 2,
|
||||
entries: BTreeMap::new(),
|
||||
},
|
||||
)]);
|
||||
let buffers = table_buffers(ShaderStage::Vertex, &empty, &[], &Vec::new()).unwrap();
|
||||
assert_eq!(words(&buffers[&(ShaderStage::Vertex, 3)]), [1, 2, 0, 0]);
|
||||
}
|
||||
|
||||
/// The case's own function links the functions of the case's linked modules, and its libraries
|
||||
/// follow the stage libraries in stage order: the kernel of a compute case, the vertex function of
|
||||
/// a rasterization-disabled vertex case, the fragment function a passthrough vertex companion draws
|
||||
@@ -507,8 +392,6 @@ fn the_cases_own_function_links_and_its_libraries_follow_the_stages() {
|
||||
function: linking(&kernel.entry),
|
||||
shape: shape.clone(),
|
||||
dispatch: Some(kernel.dispatch),
|
||||
stage_input: None,
|
||||
tile: None,
|
||||
replay: false,
|
||||
}
|
||||
);
|
||||
@@ -533,8 +416,6 @@ fn the_cases_own_function_links_and_its_libraries_follow_the_stages() {
|
||||
function: linking(&kernel.entry),
|
||||
shape: shape.clone(),
|
||||
dispatch: Some(replay_dispatch([8, 1, 1])),
|
||||
stage_input: None,
|
||||
tile: None,
|
||||
replay: true,
|
||||
}
|
||||
);
|
||||
@@ -630,45 +511,10 @@ fn the_cases_own_function_links_and_its_libraries_follow_the_stages() {
|
||||
Err(ExecutorError::Failed(_))
|
||||
));
|
||||
|
||||
// The tables of the case's own stage take its function's handles, in stage order; the
|
||||
// generated companion links nothing.
|
||||
// The generated companion is the stage the case's own function is not.
|
||||
assert_eq!(observed_case.companion_stage(), Some(ShaderStage::Fragment));
|
||||
assert_eq!(fragment_case.companion_stage(), Some(ShaderStage::Vertex));
|
||||
assert_eq!(vertex_case.companion_stage(), None);
|
||||
let handle = |word: u32| {
|
||||
Some(
|
||||
serde_json::from_value::<metal2vulkan::pipeline::FunctionHandle>(serde_json::json!(
|
||||
word
|
||||
))
|
||||
.unwrap(),
|
||||
)
|
||||
};
|
||||
let own = vec![vec![handle(2)], vec![handle(3), handle(4)]];
|
||||
observed_case.vertex.resources.function_tables = BTreeMap::from([(
|
||||
5,
|
||||
FunctionTable {
|
||||
size: 1,
|
||||
entries: BTreeMap::from([(
|
||||
0,
|
||||
tables::TableFunction {
|
||||
module_sha256: "22".repeat(32),
|
||||
function: "c".into(),
|
||||
},
|
||||
)]),
|
||||
},
|
||||
)]);
|
||||
let buffers = render_tables(&observed_case, &linked, &[own.clone(), Vec::new()]).unwrap();
|
||||
assert_eq!(
|
||||
buffers,
|
||||
BTreeMap::from([(
|
||||
(ShaderStage::Vertex, 5),
|
||||
[1u32, 1, 4]
|
||||
.iter()
|
||||
.flat_map(|word| word.to_le_bytes())
|
||||
.collect::<Vec<_>>()
|
||||
)])
|
||||
);
|
||||
assert!(render_tables(&observed_case, &linked, &[own]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -693,7 +539,6 @@ fn outputs_are_exact_ranges_of_the_bound_buffer() {
|
||||
&BTreeMap::new(),
|
||||
textures,
|
||||
&BTreeMap::new(),
|
||||
&BTreeMap::new(),
|
||||
)
|
||||
};
|
||||
assert_eq!(select(ComputeOutput::None, &none), Ok(vec![]));
|
||||
@@ -734,16 +579,7 @@ fn outputs_are_exact_ranges_of_the_bound_buffer() {
|
||||
offset,
|
||||
length,
|
||||
};
|
||||
let selected = |output| {
|
||||
select_output(
|
||||
output,
|
||||
&buffers,
|
||||
&embedded,
|
||||
&none,
|
||||
&BTreeMap::new(),
|
||||
&BTreeMap::new(),
|
||||
)
|
||||
};
|
||||
let selected = |output| select_output(output, &buffers, &embedded, &none, &BTreeMap::new());
|
||||
assert_eq!(selected(pointee(1, 8, 1, 2)), Ok(vec![8, 7]));
|
||||
assert!(selected(pointee(1, 0, 0, 1)).is_err());
|
||||
assert!(selected(pointee(1, 8, 3, 2)).is_err());
|
||||
@@ -767,54 +603,10 @@ fn outputs_are_exact_ranges_of_the_bound_buffer() {
|
||||
origin,
|
||||
dimensions: [1, 2, 1],
|
||||
};
|
||||
let selected = |output| {
|
||||
select_output(
|
||||
output,
|
||||
&buffers,
|
||||
&embedded,
|
||||
&none,
|
||||
&member,
|
||||
&BTreeMap::new(),
|
||||
)
|
||||
};
|
||||
let selected = |output| select_output(output, &buffers, &embedded, &none, &member);
|
||||
assert_eq!(selected(region(16, [1, 0, 0])), Ok(vec![2, 4]));
|
||||
assert!(selected(region(8, [0, 0, 0])).is_err());
|
||||
assert!(selected(region(16, [2, 0, 0])).is_err());
|
||||
|
||||
// A tile pass's render target's region, rows tightly packed as the Metal oracle reads them.
|
||||
let attachment = crate::literal::LiteralTexture {
|
||||
binding: 2,
|
||||
role: crate::case::ResourceRole::InOut,
|
||||
texture_type: crate::case::TextureType::D2,
|
||||
format: crate::case::TextureFormat::R16Uint,
|
||||
dimensions: [3, 2, 1],
|
||||
sample_count: 1,
|
||||
bytes: (0u8..12).collect(),
|
||||
sparse: None,
|
||||
mip_levels: 1,
|
||||
};
|
||||
let attachments = BTreeMap::from([(2, attachment)]);
|
||||
let target = |index, origin, dimensions| ComputeOutput::RenderTarget {
|
||||
index,
|
||||
origin,
|
||||
dimensions,
|
||||
};
|
||||
let selected = |output| {
|
||||
select_output(
|
||||
output,
|
||||
&buffers,
|
||||
&embedded,
|
||||
&none,
|
||||
&BTreeMap::new(),
|
||||
&attachments,
|
||||
)
|
||||
};
|
||||
assert_eq!(
|
||||
selected(target(2, [1, 0], [2, 2])),
|
||||
Ok(vec![2, 3, 4, 5, 8, 9, 10, 11])
|
||||
);
|
||||
assert!(selected(target(1, [0, 0], [1, 1])).is_err());
|
||||
assert!(selected(target(2, [2, 0], [2, 1])).is_err());
|
||||
}
|
||||
|
||||
/// `bytes` as the base64 an authored case spells.
|
||||
@@ -1089,7 +881,6 @@ fn texture_arrays_bind_each_element_at_its_slot() {
|
||||
&BTreeMap::new(),
|
||||
&BTreeMap::new(),
|
||||
&finals,
|
||||
&BTreeMap::new(),
|
||||
&BTreeMap::new()
|
||||
),
|
||||
Ok(99u32.to_le_bytes().to_vec())
|
||||
@@ -1203,7 +994,6 @@ fn a_device_buffer_array_plans_as_the_functions_buffer_table() {
|
||||
&function,
|
||||
&shape,
|
||||
Some(&compute.dispatch),
|
||||
None,
|
||||
&Budget::standard(),
|
||||
)
|
||||
.unwrap_or_else(|error| panic!("{stem}: compile: {error:?}"));
|
||||
@@ -1252,23 +1042,14 @@ fn the_binder_plans_the_executors_state() {
|
||||
entry: "count".into(),
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
buffers: BTreeMap::from([(0, vec![0; 4])]),
|
||||
rate_maps: BTreeMap::new(),
|
||||
argument_buffer_buffers: BTreeMap::new(),
|
||||
argument_buffer_rate_maps: BTreeMap::new(),
|
||||
argument_buffer_textures: BTreeMap::new(),
|
||||
argument_buffer_samplers: BTreeMap::new(),
|
||||
objects: BTreeMap::new(),
|
||||
command_buffers: BTreeMap::new(),
|
||||
textures: BTreeMap::new(),
|
||||
samplers: BTreeMap::new(),
|
||||
function_tables: BTreeMap::new(),
|
||||
acceleration_structures: BTreeMap::new(),
|
||||
threadgroup_lengths: BTreeMap::new(),
|
||||
imageblock: None,
|
||||
tile: None,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
attribute_strides: Default::default(),
|
||||
dispatch: Dispatch::Threads {
|
||||
threads: [5, 1, 1],
|
||||
threads_per_group: [2, 1, 1],
|
||||
@@ -2066,23 +1847,14 @@ fn plain_kernel() -> ComputeCase {
|
||||
entry: "main".into(),
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
buffers: BTreeMap::from([(0, vec![0; 4]), (1, vec![0; 16])]),
|
||||
rate_maps: BTreeMap::new(),
|
||||
argument_buffer_buffers: BTreeMap::new(),
|
||||
argument_buffer_rate_maps: BTreeMap::new(),
|
||||
argument_buffer_textures: BTreeMap::new(),
|
||||
argument_buffer_samplers: BTreeMap::new(),
|
||||
objects: BTreeMap::new(),
|
||||
command_buffers: BTreeMap::new(),
|
||||
textures: BTreeMap::new(),
|
||||
samplers: BTreeMap::new(),
|
||||
function_tables: BTreeMap::new(),
|
||||
acceleration_structures: BTreeMap::new(),
|
||||
threadgroup_lengths: BTreeMap::from([(0, 64)]),
|
||||
imageblock: None,
|
||||
tile: None,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
attribute_strides: Default::default(),
|
||||
dispatch: Dispatch::Threads {
|
||||
threads: [5, 1, 1],
|
||||
threads_per_group: [2, 1, 1],
|
||||
@@ -2101,18 +1873,15 @@ fn plain_kernel() -> ComputeCase {
|
||||
/// nothing, a 32-bit float depth or a multisampled texture among its textures (which the run
|
||||
/// fills by a draw), a cube array among them, and its out-of-bounds targets among them
|
||||
/// (`platform::runtime_bounds`); a case with anything else (a pipeline state in an argument
|
||||
/// buffer, an explicit imageblock, an indirect dispatch, a texture the runtime does not make:
|
||||
/// sparse or a texture buffer) stays on the executor's own context.
|
||||
/// buffer, an indirect dispatch) stays on the executor's own context.
|
||||
#[test]
|
||||
fn a_plain_kernel_case_and_only_one_runs_through_the_runtime() {
|
||||
use crate::case::{
|
||||
sparse::SparseTextureResource, ArgumentBufferSamplerResource, ResourceRole,
|
||||
SamplerAddressMode, SamplerFilter, SamplerMipFilter, SamplerResource, TextureFormat,
|
||||
TextureType,
|
||||
ArgumentBufferSamplerResource, ResourceRole, SamplerAddressMode, SamplerFilter,
|
||||
SamplerMipFilter, SamplerResource, TextureFormat, TextureType,
|
||||
};
|
||||
let authored = kernel_case();
|
||||
let plain = plain_kernel();
|
||||
assert!(runs_through_runtime(&authored, &plain));
|
||||
assert!(runs_through_runtime(&plain));
|
||||
let groups = ComputeCase {
|
||||
dispatch: Dispatch::Threadgroups {
|
||||
groups: [2, 1, 1],
|
||||
@@ -2121,7 +1890,7 @@ fn a_plain_kernel_case_and_only_one_runs_through_the_runtime() {
|
||||
output: ComputeOutput::None,
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_through_runtime(&authored, &groups));
|
||||
assert!(runs_through_runtime(&groups));
|
||||
let texture = |texture_type, sample_count| LiteralTexture {
|
||||
binding: 0,
|
||||
role: ResourceRole::InOut,
|
||||
@@ -2155,7 +1924,7 @@ fn a_plain_kernel_case_and_only_one_runs_through_the_runtime() {
|
||||
normalized_coordinates: true,
|
||||
},
|
||||
);
|
||||
assert!(runs_through_runtime(&authored, &sampled));
|
||||
assert!(runs_through_runtime(&sampled));
|
||||
let mut members = plain.clone();
|
||||
members.argument_buffer_buffers.insert((0, 0), vec![0; 16]);
|
||||
members
|
||||
@@ -2192,36 +1961,26 @@ fn a_plain_kernel_case_and_only_one_runs_through_the_runtime() {
|
||||
output,
|
||||
..members.clone()
|
||||
};
|
||||
assert!(runs_through_runtime(&authored, &case));
|
||||
assert!(runs_through_runtime(&case));
|
||||
}
|
||||
let mut member_buffer = plain.clone();
|
||||
member_buffer
|
||||
.argument_buffer_textures
|
||||
.insert((0, 8), texture(TextureType::Buffer, 1));
|
||||
let mut object = plain.clone();
|
||||
object.objects.insert((1, 0), 7);
|
||||
let sparse = LiteralTexture {
|
||||
sparse: Some(SparseTextureResource {
|
||||
mappings: Vec::new(),
|
||||
}),
|
||||
..texture(TextureType::D2, 1)
|
||||
};
|
||||
let depth = LiteralTexture {
|
||||
format: TextureFormat::Depth32Float,
|
||||
bytes: vec![0; 64],
|
||||
..texture(TextureType::D2, 1)
|
||||
};
|
||||
assert!(runs_through_runtime(&authored, &textured(depth)));
|
||||
assert!(runs_through_runtime(
|
||||
&authored,
|
||||
&textured(texture(TextureType::D2Multisample, 4))
|
||||
));
|
||||
assert!(runs_through_runtime(&textured(depth)));
|
||||
assert!(runs_through_runtime(&textured(texture(
|
||||
TextureType::D2Multisample,
|
||||
4
|
||||
))));
|
||||
let cube_array = LiteralTexture {
|
||||
dimensions: [4, 4, 12],
|
||||
bytes: vec![0; 768],
|
||||
..texture(TextureType::CubeArray, 1)
|
||||
};
|
||||
assert!(runs_through_runtime(&authored, &textured(cube_array)));
|
||||
assert!(runs_through_runtime(&textured(cube_array)));
|
||||
let bounded = ComputeCase {
|
||||
out_of_bounds: vec![OutOfBoundsTarget {
|
||||
resource: OutOfBoundsResource::Buffer { binding: 0 },
|
||||
@@ -2231,43 +1990,34 @@ fn a_plain_kernel_case_and_only_one_runs_through_the_runtime() {
|
||||
}],
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_through_runtime(&authored, &bounded));
|
||||
assert!(runs_through_runtime(&bounded));
|
||||
let others = [
|
||||
object,
|
||||
ComputeCase {
|
||||
imageblock: Some([8, 8]),
|
||||
..plain.clone()
|
||||
},
|
||||
ComputeCase {
|
||||
dispatch: replay_dispatch([2, 1, 1]),
|
||||
..plain.clone()
|
||||
},
|
||||
textured(sparse),
|
||||
textured(texture(TextureType::Buffer, 1)),
|
||||
member_buffer,
|
||||
];
|
||||
for other in &others {
|
||||
assert!(!runs_through_runtime(&authored, other), "{other:?}");
|
||||
assert!(!runs_through_runtime(other), "{other:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The runtime draws a vertex or fragment case of any sample count, its own stage's buffers,
|
||||
/// textures and samplers, static vertex strides, color targets, and one direct or indexed draw
|
||||
/// textures and samplers, vertex buffers, color targets, and one direct or indexed draw
|
||||
/// of primitives or one patch draw with no index buffer, observing a buffer, a texture, a color
|
||||
/// target or nothing; and a rasterization-disabled vertex case, which renders into the oracle's
|
||||
/// sink; a depth/stencil attachment of one aspect, of one sample or more, observed or not; a
|
||||
/// fragment pass with no attachment, of one sample or more; and an attribute buffer's
|
||||
/// out-of-bounds target. A case with anything else (a depth/stencil attachment of both aspects,
|
||||
/// layered rendering, a dynamic vertex stride, an argument-buffer member, an explicit imageblock,
|
||||
/// a patch draw through a patch index buffer, or an index buffer's out-of-bounds target) stays on
|
||||
/// the executor's own context.
|
||||
/// layered rendering, an argument-buffer member, a patch draw through a patch index buffer, or an
|
||||
/// index buffer's out-of-bounds target) stays on the executor's own context.
|
||||
#[test]
|
||||
fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
use super::graphics::tests::two_stage_case;
|
||||
use super::graphics::{ColorTarget, RenderCase, RenderOutput, VertexBuffer};
|
||||
use crate::case::{AttributeFormat, TextureFormat};
|
||||
use super::graphics::{ColorTarget, RenderCase, RenderOutput};
|
||||
use crate::case::TextureFormat;
|
||||
use crate::literal::LiteralDepthStencil;
|
||||
let authored = kernel_case();
|
||||
let target = ColorTarget {
|
||||
format: TextureFormat::Rgba8Unorm,
|
||||
dimensions: [2, 2],
|
||||
@@ -2281,7 +2031,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
BTreeMap::from([(0, target.clone())]),
|
||||
3,
|
||||
);
|
||||
assert!(runs_render_through_runtime(&authored, &plain));
|
||||
assert!(runs_render_through_runtime(&plain));
|
||||
let indexed = RenderCase {
|
||||
draw: DrawCall::Indexed {
|
||||
index_type: metal2vulkan::vk::IndexType::UINT16,
|
||||
@@ -2296,7 +2046,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
output: RenderOutput::None,
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_render_through_runtime(&authored, &indexed));
|
||||
assert!(runs_render_through_runtime(&indexed));
|
||||
let unrasterized = RenderCase {
|
||||
fragment: None,
|
||||
color_targets: BTreeMap::new(),
|
||||
@@ -2308,7 +2058,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
},
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_render_through_runtime(&authored, &unrasterized));
|
||||
assert!(runs_render_through_runtime(&unrasterized));
|
||||
let patches = |patch_index| RenderCase {
|
||||
assembly: graphics::Assembly::Patches {
|
||||
tessellation: metal2vulkan::pipeline::TessellationDescriptor::default(),
|
||||
@@ -2325,7 +2075,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
},
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_render_through_runtime(&authored, &patches(None)));
|
||||
assert!(runs_render_through_runtime(&patches(None)));
|
||||
// An attribute buffer's out-of-bounds target draws through the runtime, whose facts refuse or
|
||||
// run it (`runtime_bounds::drawn`); no other target does (an index buffer's case carries the
|
||||
// runtime's limit, `index_buffer_past_end`, which stops it before either context).
|
||||
@@ -2339,22 +2089,10 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
}],
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_render_through_runtime(
|
||||
&authored,
|
||||
&bounded(
|
||||
OutOfBoundsResource::AttributeBuffer { location: 0 },
|
||||
ContainmentForm::VertexInput
|
||||
)
|
||||
));
|
||||
let dynamic = VertexBuffer {
|
||||
location: 0,
|
||||
buffer_index: 30,
|
||||
format: AttributeFormat::Float2,
|
||||
stride: 8,
|
||||
dynamic: true,
|
||||
step: metal2vulkan::metal::VertexStepFunction::PerVertex,
|
||||
bytes: vec![0; 24],
|
||||
};
|
||||
assert!(runs_render_through_runtime(&bounded(
|
||||
OutOfBoundsResource::AttributeBuffer { location: 0 },
|
||||
ContainmentForm::VertexInput
|
||||
)));
|
||||
let mut member = plain.clone();
|
||||
if let Some(fragment) = &mut member.fragment {
|
||||
fragment
|
||||
@@ -2390,7 +2128,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
depth_stencil: Some(attachment.clone()),
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_render_through_runtime(&authored, &attached));
|
||||
assert!(runs_render_through_runtime(&attached));
|
||||
let observed = RenderCase {
|
||||
color_targets: BTreeMap::new(),
|
||||
output: match attachment.depth {
|
||||
@@ -2405,7 +2143,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
},
|
||||
..attached
|
||||
};
|
||||
assert!(runs_render_through_runtime(&authored, &observed));
|
||||
assert!(runs_render_through_runtime(&observed));
|
||||
}
|
||||
// A pass of more samples, its color target filled and read back sample by sample.
|
||||
let multisampled = RenderCase {
|
||||
@@ -2420,7 +2158,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
)]),
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_render_through_runtime(&authored, &multisampled));
|
||||
assert!(runs_render_through_runtime(&multisampled));
|
||||
// A fragment pass of no attachment, of one sample or more.
|
||||
for raster_sample_count in [None, Some(4)] {
|
||||
let attachmentless = RenderCase {
|
||||
@@ -2429,7 +2167,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
raster_sample_count,
|
||||
..plain.clone()
|
||||
};
|
||||
assert!(runs_render_through_runtime(&authored, &attachmentless));
|
||||
assert!(runs_render_through_runtime(&attachmentless));
|
||||
}
|
||||
let others = [
|
||||
RenderCase {
|
||||
@@ -2443,19 +2181,7 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
render_target_array_length: 1,
|
||||
..plain.clone()
|
||||
},
|
||||
RenderCase {
|
||||
vertex_buffers: vec![dynamic],
|
||||
..plain.clone()
|
||||
},
|
||||
member,
|
||||
RenderCase {
|
||||
imageblock: Some(super::imageblock::Cells {
|
||||
dimensions: [2, 2],
|
||||
cell_bytes: 4,
|
||||
bytes: vec![0; 16],
|
||||
}),
|
||||
..plain.clone()
|
||||
},
|
||||
bounded(
|
||||
OutOfBoundsResource::IndexBuffer,
|
||||
ContainmentForm::IndexBuffer,
|
||||
@@ -2470,6 +2196,6 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() {
|
||||
},
|
||||
];
|
||||
for other in &others {
|
||||
assert!(!runs_render_through_runtime(&authored, other), "{other:?}");
|
||||
assert!(!runs_render_through_runtime(other), "{other:?}");
|
||||
}
|
||||
}
|
||||
@@ -388,7 +388,6 @@ fn an_argument_buffer_texture_is_the_heap_member_its_owner_names() {
|
||||
&function,
|
||||
&shape,
|
||||
Some(&mapped.dispatch),
|
||||
None,
|
||||
&Budget::standard(),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -567,7 +566,6 @@ fn a_pipeline_state_whose_bytes_a_kernel_reads_never_reaches_a_comparison() {
|
||||
&function,
|
||||
&shape,
|
||||
Some(&mapped.dispatch),
|
||||
None,
|
||||
&Budget::standard(),
|
||||
);
|
||||
match (compiled, compiles) {
|
||||
@@ -703,7 +701,6 @@ fn an_argument_buffer_sampler_is_the_sampler_table_entry_its_owner_names() {
|
||||
&function,
|
||||
&shape,
|
||||
Some(&mapped.dispatch),
|
||||
None,
|
||||
&Budget::standard(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
//!
|
||||
//! One loop ([`compile_for_bind_state`]) serves both pipeline kinds, in terms of the pipeline's
|
||||
//! `VariantKey`: a kernel compiles its function under the key's kernel inputs
|
||||
//! ([`compile_compute_for_shape`]; a tile function the same way, under its attachments' formats
|
||||
//! too, into a tile pipeline, [`compile_tile_for_shape`]), a render pipeline both stages under the
|
||||
//! ([`compile_compute_for_shape`]), a render pipeline both stages under the
|
||||
//! key (`Device::compile_render_variant`, [`compile_render_for_shape`]), so a storage texture of
|
||||
//! either the vertex or the fragment stage gets its format, and a render plan's pulled vertex
|
||||
//! buffers are compiled for too. These are what the compile worker runs for the engine
|
||||
@@ -28,20 +27,16 @@
|
||||
use metal2vulkan::bind::{draw_replay_vertex_layouts, BindShape, Dispatch, TextureShape};
|
||||
use metal2vulkan::cache::VariantKey;
|
||||
use metal2vulkan::device::{Device, DeviceProfile};
|
||||
use metal2vulkan::error::{
|
||||
DescriptorError, Error, InternalError, InternalKind, MetalAnswer, RuntimeInput,
|
||||
};
|
||||
use metal2vulkan::error::{Error, InternalError, InternalKind, RuntimeInput};
|
||||
use metal2vulkan::metal::format::storage_image_choice;
|
||||
use metal2vulkan::metal::PixelFormat;
|
||||
use metal2vulkan::pipeline::{
|
||||
ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, MeshPipelineDescriptor,
|
||||
RenderPipeline, RenderPipelineDescriptor, StageInputDescriptor, StageSource,
|
||||
TileRenderPipelineDescriptor,
|
||||
RenderPipeline, RenderPipelineDescriptor, StageSource,
|
||||
};
|
||||
use metal2vulkan::pipeline::{SlotClass, SlotRef, Stage};
|
||||
use metal2vulkan::Budget;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// Whether a pipeline compiled under `compiled` is the one `variant` asks for.
|
||||
pub fn compiled_for(compiled: &VariantKey, variant: &VariantKey) -> bool {
|
||||
@@ -114,23 +109,19 @@ pub fn compile_for_bind_state<P>(
|
||||
|
||||
/// Compile `function` into a compute pipeline for `device` under `budget` with the inputs the
|
||||
/// bind shape `shape` decides, and those `dispatch` runs on when given (its plan's
|
||||
/// `dispatch_variant`) ([`compile_for_bind_state`], the key's kernel inputs), in a pipeline of
|
||||
/// stage-input descriptor `stage_input`, which the kernel compiles under too; returns the pipeline
|
||||
/// `dispatch_variant`) ([`compile_for_bind_state`], the key's kernel inputs); returns the pipeline
|
||||
/// and that key.
|
||||
pub fn compile_compute_for_shape(
|
||||
device: &Device,
|
||||
function: &FunctionDescriptor,
|
||||
shape: &BindShape,
|
||||
dispatch: Option<&Dispatch>,
|
||||
stage_input: Option<&StageInputDescriptor>,
|
||||
budget: &Budget,
|
||||
) -> Result<(ComputePipeline, VariantKey), Error> {
|
||||
compile_kernel_for_shape(device, shape, dispatch, |key| {
|
||||
let mut inputs = key.lowering_inputs(Stage::Kernel);
|
||||
inputs.stage_input = stage_input.cloned();
|
||||
let inputs = key.lowering_inputs(Stage::Kernel);
|
||||
let compiled = device.compile_function(function, &inputs, budget)?;
|
||||
let mut descriptor = ComputePipelineDescriptor::new(StageSource::Compiled(compiled));
|
||||
descriptor.stage_input = stage_input.cloned();
|
||||
let descriptor = ComputePipelineDescriptor::new(StageSource::Compiled(compiled));
|
||||
device.compile_compute_pipeline(&descriptor, budget)
|
||||
})
|
||||
}
|
||||
@@ -155,39 +146,6 @@ pub fn compile_replay_for_shape(
|
||||
})
|
||||
}
|
||||
|
||||
/// Compile the tile function `function` into a tile pipeline (`Device::compile_tile_pipeline`)
|
||||
/// for `device` under `budget`, its color attachments of `formats` by color index, with the
|
||||
/// inputs the bind shape `shape` and `dispatch` decide as for [`compile_compute_for_shape`]: the
|
||||
/// function compiles under the key's kernel inputs and the attachments' formats
|
||||
/// (`LoweringInputs::tile_attachments`), and the pipeline links it under the same formats. Returns
|
||||
/// the pipeline and that key.
|
||||
pub fn compile_tile_for_shape(
|
||||
device: &Device,
|
||||
function: &FunctionDescriptor,
|
||||
shape: &BindShape,
|
||||
dispatch: Option<&Dispatch>,
|
||||
formats: &BTreeMap<u32, PixelFormat>,
|
||||
budget: &Budget,
|
||||
) -> Result<(ComputePipeline, VariantKey), Error> {
|
||||
compile_kernel_for_shape(device, shape, dispatch, |key| {
|
||||
let mut inputs = key.lowering_inputs(Stage::Kernel);
|
||||
inputs.tile_attachments = Some(formats.clone());
|
||||
let compiled = device.compile_function(function, &inputs, budget)?;
|
||||
let mut descriptor = TileRenderPipelineDescriptor::new(StageSource::Compiled(compiled));
|
||||
for (&index, &format) in formats {
|
||||
let attachment = usize::try_from(index)
|
||||
.ok()
|
||||
.and_then(|index| descriptor.color_attachment_formats.get_mut(index))
|
||||
.ok_or(Error::InvalidDescriptor(DescriptorError::ColorAttachment {
|
||||
index,
|
||||
metal: MetalAnswer::EndsProcess,
|
||||
}))?;
|
||||
*attachment = Some(format);
|
||||
}
|
||||
device.compile_tile_pipeline(&descriptor, budget)
|
||||
})
|
||||
}
|
||||
|
||||
/// [`compile_for_bind_state`] of a kernel pipeline `compile` builds under a key, settling on the
|
||||
/// variant the plan of `shape` asks for, or the one `dispatch` runs on when given (its plan's
|
||||
/// `dispatch_variant`).
|
||||
@@ -500,15 +458,9 @@ mod tests {
|
||||
};
|
||||
let budget = Budget::standard();
|
||||
for n in [1, 4, 16] {
|
||||
let (pipeline, key) = compile_compute_for_shape(
|
||||
&device,
|
||||
&function,
|
||||
&shape,
|
||||
Some(&dispatch(n)),
|
||||
None,
|
||||
&budget,
|
||||
)
|
||||
.unwrap();
|
||||
let (pipeline, key) =
|
||||
compile_compute_for_shape(&device, &function, &shape, Some(&dispatch(n)), &budget)
|
||||
.unwrap();
|
||||
assert!(key.emulated_simdgroups, "{n}");
|
||||
let plan = pipeline.plan(&device, &shape).unwrap();
|
||||
assert!(compiled_for(&key, &plan.variant), "{n}");
|
||||
@@ -519,8 +471,7 @@ mod tests {
|
||||
}
|
||||
for d in [Some(dispatch(32)), None] {
|
||||
let (pipeline, key) =
|
||||
compile_compute_for_shape(&device, &function, &shape, d.as_ref(), None, &budget)
|
||||
.unwrap();
|
||||
compile_compute_for_shape(&device, &function, &shape, d.as_ref(), &budget).unwrap();
|
||||
assert!(key.is_empty(), "{d:?}");
|
||||
let plan = pipeline.plan(&device, &shape).unwrap();
|
||||
assert!(plan.instantiate_dispatch(&state, &dispatch(32)).is_ok());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use ash::vk;
|
||||
|
||||
mod acceleration;
|
||||
mod acceptance;
|
||||
mod buffers;
|
||||
mod compute;
|
||||
@@ -22,7 +21,6 @@ mod runtime_multisample;
|
||||
mod runtime_probe;
|
||||
mod runtime_render;
|
||||
mod runtime_textures;
|
||||
mod sparse_images;
|
||||
pub use acceptance::create_acceptance_pipeline;
|
||||
pub use compute::execute_engine;
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
|
||||
@@ -1,389 +0,0 @@
|
||||
//! The acceleration structures behind a plan's `WriteSource::AccelerationStructure` writes, shared
|
||||
//! by the engine compute and render executors.
|
||||
//!
|
||||
//! A case's structure is built as the Metal oracle builds it ([`CaseStructure`]) and as a
|
||||
//! consumer builds Metal's (`metal2vulkan::bind::acceleration`): a bottom-level structure of one
|
||||
//! triangle geometry with Metal's default geometry settings (`geometry_flags`) over the case's
|
||||
//! vertices or the instanced triangle, and the top-level structure the write binds: a primitive
|
||||
//! structure's one-instance wrap (`primitive_wrap`) or an instance structure's instance records
|
||||
//! (`instance_record`, whose typed refusals the run reports as the product's). A slot the case
|
||||
//! leaves unbound binds a top-level structure of no instances, which every ray misses. A
|
||||
//! structure of the other level than the argument's is not implemented (Metal leaves it
|
||||
//! undefined).
|
||||
//!
|
||||
//! Every structure and its build inputs live in host-visible memory the host wrote before the
|
||||
//! submission. The builds are recorded before the work ([`Structures::record`]): the bottom
|
||||
//! levels, a build-to-build dependency, the top levels, and a build-to-shader dependency. Each
|
||||
//! build has its own scratch buffer, so no two builds touch the same memory.
|
||||
|
||||
use super::buffers::{create_host_buffer, HostBuffer};
|
||||
use super::device::VulkanContext;
|
||||
use crate::candidate::engine::{bound_refusal, CaseStructure};
|
||||
use crate::case::AccelerationStructureKind;
|
||||
use crate::check::admission::{ExecutorError, NotSupported};
|
||||
use ash::khr::acceleration_structure;
|
||||
use ash::vk;
|
||||
use metal2vulkan::bind::{geometry_flags, instance_record, primitive_wrap, InstanceRecord};
|
||||
use metal2vulkan::device::VkFeature;
|
||||
use metal2vulkan::error::{Error, Unsupported};
|
||||
use metal2vulkan::pipeline::{AccelerationStructureLevel, SlotRef};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// Bytes of one `float3` vertex.
|
||||
const VERTEX_BYTES: u32 = 12;
|
||||
/// `VkAccelerationStructureGeometryInstancesDataKHR::data` alignment.
|
||||
const INSTANCE_ALIGNMENT: u64 = 16;
|
||||
|
||||
/// One build, recorded before the work.
|
||||
struct Build {
|
||||
ty: vk::AccelerationStructureTypeKHR,
|
||||
structure: vk::AccelerationStructureKHR,
|
||||
geometry: vk::AccelerationStructureGeometryKHR<'static>,
|
||||
primitives: u32,
|
||||
scratch: vk::DeviceAddress,
|
||||
}
|
||||
|
||||
/// Every acceleration structure of one run, destroyed before the buffers that back them.
|
||||
pub(super) struct Structures {
|
||||
device: ash::Device,
|
||||
/// The extension's device functions, loaded with the first structure.
|
||||
loader: Option<acceleration_structure::Device>,
|
||||
/// Every structure created.
|
||||
created: Vec<vk::AccelerationStructureKHR>,
|
||||
/// Storage, scratch, and build-input buffers.
|
||||
buffers: Vec<HostBuffer>,
|
||||
bottom: Vec<Build>,
|
||||
top: Vec<Build>,
|
||||
/// The top-level structure each slot's write binds.
|
||||
bound: BTreeMap<SlotRef, vk::AccelerationStructureKHR>,
|
||||
}
|
||||
|
||||
impl Drop for Structures {
|
||||
fn drop(&mut self) {
|
||||
if let Some(loader) = &self.loader {
|
||||
for structure in &self.created {
|
||||
// SAFETY: each structure was created by this run on `loader`'s device and is
|
||||
// destroyed once, after the submission that used it completed (or before any).
|
||||
unsafe { loader.destroy_acceleration_structure(*structure, None) };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn not_implemented(what: impl Into<String>) -> ExecutorError {
|
||||
NotSupported::NotImplemented(format!("engine candidate: {}", what.into())).into()
|
||||
}
|
||||
|
||||
/// A binder refusal of a structure the case builds, reported as the product's, at bind.
|
||||
fn refusal(unsupported: Unsupported) -> ExecutorError {
|
||||
bound_refusal(&Error::Unsupported(unsupported))
|
||||
}
|
||||
|
||||
impl Structures {
|
||||
pub(super) fn new(context: &VulkanContext) -> Structures {
|
||||
Structures {
|
||||
device: context.device.clone(),
|
||||
loader: None,
|
||||
created: Vec::new(),
|
||||
buffers: Vec::new(),
|
||||
bottom: Vec::new(),
|
||||
top: Vec::new(),
|
||||
bound: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The top-level structure a write of `level` at `slot` binds: built (once per slot) from
|
||||
/// `structure`, the case's structure at the slot, if any.
|
||||
pub(super) fn top_level(
|
||||
&mut self,
|
||||
context: &VulkanContext,
|
||||
slot: SlotRef,
|
||||
level: AccelerationStructureLevel,
|
||||
structure: Option<&CaseStructure>,
|
||||
) -> Result<vk::AccelerationStructureKHR, ExecutorError> {
|
||||
if let Some(&built) = self.bound.get(&slot) {
|
||||
return Ok(built);
|
||||
}
|
||||
let records = match (level, structure) {
|
||||
(_, None) => Vec::new(),
|
||||
(
|
||||
AccelerationStructureLevel::Primitive,
|
||||
Some(CaseStructure::Primitive { vertices }),
|
||||
) => {
|
||||
let reference = self.bottom_level(context, vertices)?;
|
||||
vec![primitive_wrap(reference, 0).map_err(refusal)?]
|
||||
}
|
||||
(
|
||||
AccelerationStructureLevel::Instance,
|
||||
Some(CaseStructure::Instances { instances }),
|
||||
) => {
|
||||
let instance = CaseStructure::instance();
|
||||
// What Vulkan's instance fields cannot hold is refused before anything is built.
|
||||
instance_record(&instance, 0, 0).map_err(refusal)?;
|
||||
let vertices: Vec<u8> = AccelerationStructureKind::INSTANCED_TRIANGLE
|
||||
.iter()
|
||||
.flat_map(|v| v.to_le_bytes())
|
||||
.collect();
|
||||
let reference = self.bottom_level(context, &vertices)?;
|
||||
(0..*instances)
|
||||
.map(|_| instance_record(&instance, reference, 0).map_err(refusal))
|
||||
.collect::<Result<_, _>>()?
|
||||
}
|
||||
(level, Some(structure)) => {
|
||||
let kind = match structure {
|
||||
CaseStructure::Primitive { .. } => "a primitive",
|
||||
CaseStructure::Instances { .. } => "an instance",
|
||||
};
|
||||
return Err(not_implemented(format!(
|
||||
"{kind} structure bound to a {level:?} acceleration-structure argument"
|
||||
)));
|
||||
}
|
||||
};
|
||||
let top = self.top_level_of(context, &records)?;
|
||||
self.bound.insert(slot, top);
|
||||
Ok(top)
|
||||
}
|
||||
|
||||
/// Record every build, bottom levels first, and the dependencies of the top levels on them
|
||||
/// and of every shader on the top levels.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// `command` is in the recording state on this run's device, and every structure and buffer
|
||||
/// stays alive until its submission completes.
|
||||
pub(super) unsafe fn record(&self, command: vk::CommandBuffer) {
|
||||
let Some(loader) = &self.loader else {
|
||||
return;
|
||||
};
|
||||
let build = |builds: &[Build]| {
|
||||
for b in builds {
|
||||
let geometries = [b.geometry];
|
||||
let info = vk::AccelerationStructureBuildGeometryInfoKHR::default()
|
||||
.ty(b.ty)
|
||||
.mode(vk::BuildAccelerationStructureModeKHR::BUILD)
|
||||
.dst_acceleration_structure(b.structure)
|
||||
.geometries(&geometries)
|
||||
.scratch_data(vk::DeviceOrHostAddressKHR {
|
||||
device_address: b.scratch,
|
||||
});
|
||||
let range = [vk::AccelerationStructureBuildRangeInfoKHR::default()
|
||||
.primitive_count(b.primitives)];
|
||||
// SAFETY: the caller's contract; every address is a live buffer of this run.
|
||||
unsafe { loader.cmd_build_acceleration_structures(command, &[info], &[&range]) };
|
||||
}
|
||||
};
|
||||
let built = |dst_stage, dst_access| {
|
||||
let barrier = vk::MemoryBarrier::default()
|
||||
.src_access_mask(vk::AccessFlags::ACCELERATION_STRUCTURE_WRITE_KHR)
|
||||
.dst_access_mask(dst_access);
|
||||
// SAFETY: the caller's contract.
|
||||
unsafe {
|
||||
self.device.cmd_pipeline_barrier(
|
||||
command,
|
||||
vk::PipelineStageFlags::ACCELERATION_STRUCTURE_BUILD_KHR,
|
||||
dst_stage,
|
||||
vk::DependencyFlags::empty(),
|
||||
&[barrier],
|
||||
&[],
|
||||
&[],
|
||||
)
|
||||
};
|
||||
};
|
||||
build(&self.bottom);
|
||||
built(
|
||||
vk::PipelineStageFlags::ACCELERATION_STRUCTURE_BUILD_KHR,
|
||||
vk::AccessFlags::ACCELERATION_STRUCTURE_READ_KHR,
|
||||
);
|
||||
build(&self.top);
|
||||
built(
|
||||
vk::PipelineStageFlags::ALL_COMMANDS,
|
||||
vk::AccessFlags::ACCELERATION_STRUCTURE_READ_KHR | vk::AccessFlags::SHADER_READ,
|
||||
);
|
||||
}
|
||||
|
||||
/// Build a bottom-level structure of one triangle geometry over `vertices`: its device
|
||||
/// address.
|
||||
fn bottom_level(
|
||||
&mut self,
|
||||
context: &VulkanContext,
|
||||
vertices: &[u8],
|
||||
) -> Result<vk::DeviceAddress, ExecutorError> {
|
||||
let count = u32::try_from(vertices.len())
|
||||
.map_err(|_| "a primitive structure's vertices overflow")?
|
||||
/ VERTEX_BYTES;
|
||||
let input = self.input(context, "structure vertices", vertices)?;
|
||||
let triangles = vk::AccelerationStructureGeometryTrianglesDataKHR::default()
|
||||
.vertex_format(vk::Format::R32G32B32_SFLOAT)
|
||||
.vertex_data(vk::DeviceOrHostAddressConstKHR {
|
||||
device_address: input,
|
||||
})
|
||||
.vertex_stride(u64::from(VERTEX_BYTES))
|
||||
.max_vertex(count.saturating_sub(1))
|
||||
.index_type(vk::IndexType::NONE_KHR);
|
||||
let geometry = vk::AccelerationStructureGeometryKHR::default()
|
||||
.geometry_type(vk::GeometryTypeKHR::TRIANGLES)
|
||||
.geometry(vk::AccelerationStructureGeometryDataKHR { triangles })
|
||||
.flags(vk::GeometryFlagsKHR::from_raw(geometry_flags(true, true)));
|
||||
let (structure, build) = self.structure(
|
||||
context,
|
||||
vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL,
|
||||
geometry,
|
||||
count / 3,
|
||||
)?;
|
||||
self.bottom.push(build);
|
||||
let loader = self
|
||||
.loader
|
||||
.as_ref()
|
||||
.ok_or("no acceleration-structure loader")?;
|
||||
let info = vk::AccelerationStructureDeviceAddressInfoKHR::default()
|
||||
.acceleration_structure(structure);
|
||||
// SAFETY: `structure` is live on this device.
|
||||
Ok(unsafe { loader.get_acceleration_structure_device_address(&info) })
|
||||
}
|
||||
|
||||
/// Build a top-level structure of `records`.
|
||||
fn top_level_of(
|
||||
&mut self,
|
||||
context: &VulkanContext,
|
||||
records: &[InstanceRecord],
|
||||
) -> Result<vk::AccelerationStructureKHR, ExecutorError> {
|
||||
let mut bytes: Vec<u8> = records.iter().flat_map(|r| *r.bytes()).collect();
|
||||
// A structure of no instances still names an instance buffer, which it never reads.
|
||||
bytes.resize(bytes.len().max(InstanceRecord::BYTES), 0);
|
||||
let input = self.input(context, "structure instances", &bytes)?;
|
||||
if input % INSTANCE_ALIGNMENT != 0 {
|
||||
return Err(
|
||||
format!("the instance buffer's address {input:#x} is not 16-aligned").into(),
|
||||
);
|
||||
}
|
||||
let instances = vk::AccelerationStructureGeometryInstancesDataKHR::default()
|
||||
.array_of_pointers(false)
|
||||
.data(vk::DeviceOrHostAddressConstKHR {
|
||||
device_address: input,
|
||||
});
|
||||
let geometry = vk::AccelerationStructureGeometryKHR::default()
|
||||
.geometry_type(vk::GeometryTypeKHR::INSTANCES)
|
||||
.geometry(vk::AccelerationStructureGeometryDataKHR { instances });
|
||||
let primitives = u32::try_from(records.len())
|
||||
.map_err(|_| "a top-level structure's instances overflow")?;
|
||||
let (structure, build) = self.structure(
|
||||
context,
|
||||
vk::AccelerationStructureTypeKHR::TOP_LEVEL,
|
||||
geometry,
|
||||
primitives,
|
||||
)?;
|
||||
self.top.push(build);
|
||||
Ok(structure)
|
||||
}
|
||||
|
||||
/// A read-only build input holding `bytes`: its device address.
|
||||
fn input(
|
||||
&mut self,
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
bytes: &[u8],
|
||||
) -> Result<vk::DeviceAddress, ExecutorError> {
|
||||
let usage = vk::BufferUsageFlags::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR
|
||||
| vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS;
|
||||
let buffer = create_host_buffer(context, label, bytes, usage)?;
|
||||
let address = address(context, &buffer);
|
||||
self.buffers.push(buffer);
|
||||
Ok(address)
|
||||
}
|
||||
|
||||
/// Create a structure of `ty` sized for `geometry` of `primitives` primitives, and the build
|
||||
/// that fills it.
|
||||
fn structure(
|
||||
&mut self,
|
||||
context: &VulkanContext,
|
||||
ty: vk::AccelerationStructureTypeKHR,
|
||||
geometry: vk::AccelerationStructureGeometryKHR<'static>,
|
||||
primitives: u32,
|
||||
) -> Result<(vk::AccelerationStructureKHR, Build), ExecutorError> {
|
||||
if !context
|
||||
.enabled
|
||||
.features
|
||||
.contains(&VkFeature::AccelerationStructure)
|
||||
{
|
||||
return Err("an acceleration structure on a device without them enabled".into());
|
||||
}
|
||||
let loader = self
|
||||
.loader
|
||||
.get_or_insert_with(|| context.acceleration_structure())
|
||||
.clone();
|
||||
let geometries = [geometry];
|
||||
let info = vk::AccelerationStructureBuildGeometryInfoKHR::default()
|
||||
.ty(ty)
|
||||
.mode(vk::BuildAccelerationStructureModeKHR::BUILD)
|
||||
.geometries(&geometries);
|
||||
let mut sizes = vk::AccelerationStructureBuildSizesInfoKHR::default();
|
||||
// SAFETY: `info` and its geometry are live for the call; the extension is enabled.
|
||||
unsafe {
|
||||
loader.get_acceleration_structure_build_sizes(
|
||||
vk::AccelerationStructureBuildTypeKHR::DEVICE,
|
||||
&info,
|
||||
&[primitives],
|
||||
&mut sizes,
|
||||
)
|
||||
};
|
||||
let storage = create_host_buffer(
|
||||
context,
|
||||
"acceleration structure",
|
||||
&vec![0; to_usize(sizes.acceleration_structure_size)?.max(1)],
|
||||
vk::BufferUsageFlags::ACCELERATION_STRUCTURE_STORAGE_KHR
|
||||
| vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS,
|
||||
)?;
|
||||
let create = vk::AccelerationStructureCreateInfoKHR::default()
|
||||
.buffer(storage.buffer)
|
||||
.size(sizes.acceleration_structure_size)
|
||||
.ty(ty);
|
||||
self.buffers.push(storage);
|
||||
// SAFETY: the storage buffer is live and bound to memory.
|
||||
let structure = unsafe { loader.create_acceleration_structure(&create, None) }
|
||||
.map_err(|error| format!("create acceleration structure: {error}"))?;
|
||||
self.created.push(structure);
|
||||
let alignment = u64::from(scratch_alignment(context)).max(1);
|
||||
let scratch = create_host_buffer(
|
||||
context,
|
||||
"acceleration structure scratch",
|
||||
&vec![0; to_usize(sizes.build_scratch_size + alignment)?],
|
||||
vk::BufferUsageFlags::STORAGE_BUFFER | vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS,
|
||||
)?;
|
||||
let scratch_address = address(context, &scratch).next_multiple_of(alignment);
|
||||
self.buffers.push(scratch);
|
||||
Ok((
|
||||
structure,
|
||||
Build {
|
||||
ty,
|
||||
structure,
|
||||
geometry,
|
||||
primitives,
|
||||
scratch: scratch_address,
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn to_usize(size: vk::DeviceSize) -> Result<usize, ExecutorError> {
|
||||
usize::try_from(size).map_err(|_| format!("a structure size {size} overflows").into())
|
||||
}
|
||||
|
||||
/// The device address of `buffer`, created with `SHADER_DEVICE_ADDRESS`.
|
||||
fn address(context: &VulkanContext, buffer: &HostBuffer) -> vk::DeviceAddress {
|
||||
let info = vk::BufferDeviceAddressInfo::default().buffer(buffer.buffer);
|
||||
// SAFETY: the buffer was created with SHADER_DEVICE_ADDRESS and its memory is bound.
|
||||
unsafe { context.device.get_buffer_device_address(&info) }
|
||||
}
|
||||
|
||||
/// `minAccelerationStructureScratchOffsetAlignment`.
|
||||
fn scratch_alignment(context: &VulkanContext) -> u32 {
|
||||
let mut structures = vk::PhysicalDeviceAccelerationStructurePropertiesKHR::default();
|
||||
let mut properties = vk::PhysicalDeviceProperties2::default().push_next(&mut structures);
|
||||
// SAFETY: the physical device is the context's; `properties` is live for the call.
|
||||
unsafe {
|
||||
context
|
||||
.instance
|
||||
.get_physical_device_properties2(context.physical, &mut properties)
|
||||
};
|
||||
structures.min_acceleration_structure_scratch_offset_alignment
|
||||
}
|
||||
@@ -18,15 +18,13 @@ use crate::candidate::engine::argument_buffers::{
|
||||
field_words, owner_bytes, records_storage, validate_records,
|
||||
};
|
||||
use crate::candidate::engine::guards::{
|
||||
buffer_target, embedded_guard_reach, guard_reach, texel_guard_reach, with_escaped, GuardCount,
|
||||
GuardReach,
|
||||
embedded_guard_reach, guard_reach, with_escaped, GuardCount, GuardReach,
|
||||
};
|
||||
use crate::candidate::engine::tables::TableBuffers;
|
||||
use crate::candidate::engine::{
|
||||
bind_refusal, bind_state, compute_shape, engine_fingerprint, out_of_bounds_run,
|
||||
product_refusal, records_ids, resources, run_allocations, sampler_ids, select_output,
|
||||
status_verdict, synthetic_used_addresses, texture_tokens, BufferAddress, CaseStructure,
|
||||
CompiledCase, ComputeCase, ComputeOutput, ComputeRun, RunAllocation, RunAttempt,
|
||||
status_verdict, synthetic_used_addresses, texture_tokens, BufferAddress, ComputeCase,
|
||||
ComputeOutput, ComputeRun, RunAllocation, RunAttempt,
|
||||
};
|
||||
use crate::case::out_of_bounds::OutOfBoundsResource;
|
||||
use crate::check::admission::{ExecutorError, NotSupported};
|
||||
@@ -67,7 +65,7 @@ type PushWrites = Vec<(vk::ShaderStageFlags, u32, Vec<u8>)>;
|
||||
|
||||
/// Compile `case` for the device `device_type` opens with `compile` (given the opened device's
|
||||
/// description and policy, and the shape the dispatch binds, which decides the lowering inputs; it
|
||||
/// returns the pipeline and its visible-function tables' bytes), plan and execute its dispatch, and
|
||||
/// returns the pipeline), plan and execute its dispatch, and
|
||||
/// read the status before the output. The commands of each executed command buffer run after it,
|
||||
/// compiled with `children`: on the device over the `registered` replay variants where the product
|
||||
/// sets the device replay up, by the host replay elsewhere. Every refusal is typed; only a device,
|
||||
@@ -77,10 +75,7 @@ pub fn execute_engine(
|
||||
device_type: DeviceType,
|
||||
case_id: &str,
|
||||
case: &ComputeCase,
|
||||
compile: impl FnOnce(
|
||||
&WorkerDevice,
|
||||
&BindShape,
|
||||
) -> Result<CompiledCase<ComputePipeline>, ExecutorError>,
|
||||
compile: impl FnOnce(&WorkerDevice, &BindShape) -> Result<ComputePipeline, ExecutorError>,
|
||||
children: impl FnMut(
|
||||
&WorkerDevice,
|
||||
u64,
|
||||
@@ -233,7 +228,7 @@ fn run(
|
||||
case_id: &str,
|
||||
case: &ComputeCase,
|
||||
(compile, mut children): (
|
||||
impl FnOnce(&WorkerDevice, &BindShape) -> Result<CompiledCase<ComputePipeline>, ExecutorError>,
|
||||
impl FnOnce(&WorkerDevice, &BindShape) -> Result<ComputePipeline, ExecutorError>,
|
||||
impl FnMut(
|
||||
&WorkerDevice,
|
||||
u64,
|
||||
@@ -252,22 +247,21 @@ fn run(
|
||||
let shape = compute_shape(case, addressed, ranges).map_err(ExecutorError::Failed)?;
|
||||
// The census and the precision notes come from the artifact the compile worker returned and
|
||||
// this process decoded (`pipeline.stage`), never from a compile of its own.
|
||||
let CompiledCase { pipeline, tables } = compile(&target, &shape)?;
|
||||
let pipeline = compile(&target, &shape)?;
|
||||
let device = target.device();
|
||||
let missing = unmet_requirements(context, &pipeline.requirements);
|
||||
if !missing.is_empty() {
|
||||
return Err(NotSupported::NotEnabled(missing).into());
|
||||
}
|
||||
// How the compiled module contains each out-of-bounds target on this device, decided before
|
||||
// anything runs; a target checked nowhere is refused, never run. A kernel fetches each stage
|
||||
// input as the descriptor it was compiled under says.
|
||||
let attributes = out_of_bounds::Fetch::of_stage_input(case.stage_input.as_ref());
|
||||
// anything runs; a target checked nowhere is refused, never run. The kernel fetches no stage
|
||||
// input.
|
||||
let out_of_bounds = out_of_bounds_run(
|
||||
device.profile(),
|
||||
&out_of_bounds::ModuleFacts {
|
||||
stage: Stage::Kernel,
|
||||
slots: &pipeline.interface.slots,
|
||||
attributes: &attributes,
|
||||
attributes: &BTreeMap::new(),
|
||||
resident_roots: pipeline.interface.needs_pointer_translation,
|
||||
handle_table: pipeline.interface.needs_handle_translation,
|
||||
policy: *device.policy(),
|
||||
@@ -287,7 +281,7 @@ fn run(
|
||||
execute(
|
||||
context,
|
||||
device,
|
||||
(&pipeline, &tables, &shape),
|
||||
(&pipeline, &shape),
|
||||
case,
|
||||
(&mut compile_child, registered),
|
||||
)
|
||||
@@ -446,9 +440,8 @@ impl Drop for Objects<'_> {
|
||||
}
|
||||
|
||||
/// What [`execute`] read after the run: the output, the status, the census of each module a
|
||||
/// replayed command executed, the guard and padding bytes that changed around each guarded buffer
|
||||
/// and texture buffer, by out-of-bounds target, and which replay ran each executed command buffer,
|
||||
/// in key order.
|
||||
/// replayed command executed, the guard and padding bytes that changed around each guarded buffer,
|
||||
/// by out-of-bounds target, and which replay ran each executed command buffer, in key order.
|
||||
struct Executed {
|
||||
output: Vec<u8>,
|
||||
status: metal2vulkan::bind::StatusReport,
|
||||
@@ -511,16 +504,15 @@ fn not_implemented(what: impl Into<String>) -> ExecutorError {
|
||||
|
||||
/// Allocate the case's buffers (argument-buffer buffers first, so each owner is created with their
|
||||
/// addresses, its textures' and samplers' resource ids, and its command buffers', [`field_words`],
|
||||
/// [`owner_bytes`]) and its visible-function tables' buffers (holding `tables`' bytes), plan and
|
||||
/// instantiate its dispatch, create what every plan write names (`plan_resources`: textures,
|
||||
/// argument-buffer textures, heap arrays, handle tables, samplers, texel buffers, acceleration
|
||||
/// structures, and neutrals included), record and submit it, wait, and read the status and then
|
||||
/// [`owner_bytes`]), plan and instantiate its dispatch, create what every plan write names
|
||||
/// (`plan_resources`: textures, argument-buffer textures, heap arrays, handle tables, samplers, and
|
||||
/// neutrals included), record and submit it, wait, and read the status and then
|
||||
/// the output ([`Executed`]). `compile` compiles the children the case's executed command
|
||||
/// buffers dispatch, each in a compile worker: on the device, the `registered` replay variants.
|
||||
fn execute(
|
||||
context: &VulkanContext,
|
||||
device: &Device,
|
||||
(pipeline, tables, compiled_for): (&ComputePipeline, &TableBuffers, &BindShape),
|
||||
(pipeline, compiled_for): (&ComputePipeline, &BindShape),
|
||||
case: &ComputeCase,
|
||||
(compile, registered): (&mut CompileChild<'_>, &[ReplayVariant]),
|
||||
) -> Result<Executed, ExecutorError> {
|
||||
@@ -579,21 +571,8 @@ fn execute(
|
||||
)?;
|
||||
buffers.insert(index, allocation);
|
||||
}
|
||||
let mut table_buffers = BTreeMap::new();
|
||||
for (&index, table) in &case.function_tables {
|
||||
let bytes = table_bytes(tables, Stage::Kernel, index, table.byte_len())?;
|
||||
let allocation = allocate(
|
||||
context,
|
||||
&format!("visible function table {index}"),
|
||||
bytes,
|
||||
addressed,
|
||||
vk::BufferUsageFlags::empty(),
|
||||
)?;
|
||||
table_buffers.insert(index, allocation);
|
||||
}
|
||||
let addresses: BTreeMap<u32, BufferAddress> = buffers
|
||||
.iter()
|
||||
.chain(&table_buffers)
|
||||
.map(|(&index, allocation)| {
|
||||
Ok((
|
||||
index,
|
||||
@@ -656,7 +635,6 @@ fn execute(
|
||||
};
|
||||
let guest_buffers: BTreeMap<SlotRef, vk::Buffer> = buffers
|
||||
.iter()
|
||||
.chain(&table_buffers)
|
||||
.map(|(&index, allocation)| (slot(SlotClass::Buffer, index), allocation.buffer.buffer))
|
||||
.collect();
|
||||
let textures: BTreeMap<SlotRef, &LiteralTexture> = case
|
||||
@@ -664,14 +642,6 @@ fn execute(
|
||||
.iter()
|
||||
.map(|(&index, texture)| (slot(SlotClass::Texture, index), texture))
|
||||
.collect();
|
||||
let texel_guards: BTreeMap<SlotRef, GuardReach> = case
|
||||
.textures
|
||||
.keys()
|
||||
.filter_map(|&binding| {
|
||||
let reach = texel_guard_reach(case, binding)?;
|
||||
Some((slot(SlotClass::Texture, binding), reach))
|
||||
})
|
||||
.collect();
|
||||
let used_textures: BTreeMap<u32, &LiteralTexture> = case
|
||||
.argument_buffer_textures
|
||||
.iter()
|
||||
@@ -687,11 +657,6 @@ fn execute(
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let structures: BTreeMap<SlotRef, CaseStructure> = case
|
||||
.acceleration_structures
|
||||
.iter()
|
||||
.map(|(&index, structure)| (slot(SlotClass::Buffer, index), structure.clone()))
|
||||
.collect();
|
||||
let constant_blobs: BTreeMap<Stage, Arc<[u8]>> = pipeline
|
||||
.stage
|
||||
.constant_blob
|
||||
@@ -710,16 +675,10 @@ fn execute(
|
||||
.get(&(owner, field_offset))
|
||||
.copied()
|
||||
.map(TextureKey::Used),
|
||||
ComputeOutput::RenderTarget { index, .. } => Some(TextureKey::TileAttachment(index)),
|
||||
ComputeOutput::None
|
||||
| ComputeOutput::Buffer { .. }
|
||||
| ComputeOutput::ArgumentBufferBuffer { .. } => None,
|
||||
};
|
||||
let no_attachments = BTreeMap::new();
|
||||
let tile_attachments = case
|
||||
.tile
|
||||
.as_ref()
|
||||
.map_or(&no_attachments, |pass| &pass.tiled);
|
||||
let mut resources = PlanResources::create(
|
||||
context,
|
||||
device,
|
||||
@@ -727,18 +686,15 @@ fn execute(
|
||||
&Guest {
|
||||
buffers: &guest_buffers,
|
||||
textures: &textures,
|
||||
texel_guards: &texel_guards,
|
||||
used_textures: &used_textures,
|
||||
samplers: &samplers,
|
||||
argument_samplers: &state.argument_samplers,
|
||||
constant_blobs: &constant_blobs,
|
||||
descriptor_ranges: &commands.descriptor_ranges,
|
||||
descriptor_bytes: &commands.descriptor_bytes,
|
||||
structures: &structures,
|
||||
// A dispatch draws no patches and has no attachments.
|
||||
tessellation_factors: None,
|
||||
attachments: &BTreeMap::new(),
|
||||
tile_attachments,
|
||||
status: Some(status.buffer.buffer),
|
||||
},
|
||||
observed,
|
||||
@@ -821,7 +777,6 @@ fn execute(
|
||||
.map(|(held, length)| {
|
||||
let (address, allocation) = match held {
|
||||
RunAllocation::Buffer(index) => (addresses[&index], &buffers[&index]),
|
||||
RunAllocation::FunctionTable(index) => (addresses[&index], &table_buffers[&index]),
|
||||
RunAllocation::ArgumentBuffer(key) => (embedded_addresses[&key], &embedded[&key]),
|
||||
};
|
||||
Live {
|
||||
@@ -858,7 +813,7 @@ fn execute(
|
||||
finals.insert(index, bytes);
|
||||
// SAFETY: as for the status buffer.
|
||||
if let Some(count) = unsafe { allocation.buffer.escaped()? } {
|
||||
escaped.insert(buffer_target(case, index), count);
|
||||
escaped.insert(OutOfBoundsResource::Buffer { binding: index }, count);
|
||||
}
|
||||
}
|
||||
let mut embedded_finals = BTreeMap::new();
|
||||
@@ -878,28 +833,9 @@ fn execute(
|
||||
);
|
||||
}
|
||||
}
|
||||
// SAFETY: as for the status buffer.
|
||||
for (slot, count) in unsafe { resources.texel_guard_counts()? } {
|
||||
escaped.insert(
|
||||
OutOfBoundsResource::Texture {
|
||||
binding: slot.index,
|
||||
},
|
||||
count,
|
||||
);
|
||||
}
|
||||
let mut final_textures = BTreeMap::new();
|
||||
let mut embedded_final_textures = BTreeMap::new();
|
||||
let mut final_attachments = BTreeMap::new();
|
||||
match (observed, case.output) {
|
||||
// An attachment no plan write reaches keeps its contents, as the pass loads and stores
|
||||
// it (`final_texture`).
|
||||
(Some(key @ TextureKey::TileAttachment(index)), _) => {
|
||||
if let Some(attachment) = tile_attachments.get(&index) {
|
||||
// SAFETY: as for the status buffer.
|
||||
let attachment = unsafe { resources.final_texture(key, attachment)? };
|
||||
final_attachments.insert(index, attachment);
|
||||
}
|
||||
}
|
||||
(Some(key @ TextureKey::Slot(observed)), _) => {
|
||||
if let Some(texture) = textures.get(&observed) {
|
||||
// SAFETY: as for the status buffer.
|
||||
@@ -929,7 +865,6 @@ fn execute(
|
||||
&embedded_finals,
|
||||
&final_textures,
|
||||
&embedded_final_textures,
|
||||
&final_attachments,
|
||||
)
|
||||
.map_err(ExecutorError::Failed)?;
|
||||
drop(objects);
|
||||
@@ -943,25 +878,6 @@ fn execute(
|
||||
})
|
||||
}
|
||||
|
||||
/// The bytes of the visible-function table at `index` of `stage` (the compile's), which must be the
|
||||
/// `length` its bind state binds.
|
||||
pub(super) fn table_bytes(
|
||||
tables: &TableBuffers,
|
||||
stage: Stage,
|
||||
index: u32,
|
||||
length: u64,
|
||||
) -> Result<&[u8], ExecutorError> {
|
||||
match tables.get(&(stage, index)) {
|
||||
Some(bytes) if bytes.len() as u64 == length => Ok(bytes),
|
||||
Some(bytes) => Err(format!(
|
||||
"the {stage:?} visible function table {index} has {} bytes, not {length}",
|
||||
bytes.len()
|
||||
)
|
||||
.into()),
|
||||
None => Err(format!("the {stage:?} visible function table {index} has no words").into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Upload a resident root table with its sink entry filled: `(table, sink)`; the table's device
|
||||
/// address fills its `RootTableAddress` holes.
|
||||
pub(super) fn upload_root_table(
|
||||
|
||||
@@ -586,8 +586,6 @@ impl Prepared {
|
||||
&Guest {
|
||||
buffers: &BTreeMap::new(),
|
||||
textures: &BTreeMap::new(),
|
||||
texel_guards: &BTreeMap::new(),
|
||||
tile_attachments: &BTreeMap::new(),
|
||||
status: None,
|
||||
used_textures: &BTreeMap::new(),
|
||||
samplers: &BTreeMap::new(),
|
||||
@@ -597,7 +595,6 @@ impl Prepared {
|
||||
constant_blobs: &self.constant_blobs(),
|
||||
descriptor_ranges: &self.commands.descriptor_ranges,
|
||||
descriptor_bytes: &self.commands.descriptor_bytes,
|
||||
structures: &BTreeMap::new(),
|
||||
tessellation_factors: None,
|
||||
attachments: &BTreeMap::new(),
|
||||
},
|
||||
@@ -643,7 +640,7 @@ fn prepare(
|
||||
threads_per_group: variant.threads_per_threadgroup,
|
||||
};
|
||||
let pipeline = match compile(token, &shape, &child)? {
|
||||
CompiledChild::Compute(compiled) => compiled.pipeline,
|
||||
CompiledChild::Compute(pipeline) => *pipeline,
|
||||
CompiledChild::Render(..) => return Err(fail("the token names a render template".into())),
|
||||
};
|
||||
require_enabled(context, &pipeline.requirements)?;
|
||||
|
||||
@@ -402,7 +402,7 @@ fn compiled(
|
||||
compile: &mut CompileChild<'_>,
|
||||
) -> Result<Option<(RenderCase, RenderPipeline)>, ExecutorError> {
|
||||
match compile(token, &state.shape(), &ChildCommand::DrawReplay { merged }) {
|
||||
Ok(CompiledChild::Render(case, compiled)) => Ok(Some((*case, compiled.pipeline))),
|
||||
Ok(CompiledChild::Render(case, pipeline)) => Ok(Some((*case, *pipeline))),
|
||||
Ok(CompiledChild::Compute(_)) => Err(ExecutorError::Failed(format!(
|
||||
"an executed command's pipeline token {token} names a compute template for render \
|
||||
commands"
|
||||
|
||||
@@ -44,8 +44,8 @@ pub(in crate::candidate) type CompileChild<'a> =
|
||||
/// What a replay executed: each child's module census, for the run's census.
|
||||
pub(in crate::candidate::platform) type Executed = Vec<ModuleCensus>;
|
||||
|
||||
/// What a replay runs over: the run's allocations `live` (every case buffer, function table, and
|
||||
/// argument-buffer buffer), the final records `records` (by command-buffer key), the guest
|
||||
/// What a replay runs over: the run's allocations `live` (every case buffer and argument-buffer
|
||||
/// buffer), the final records `records` (by command-buffer key), the guest
|
||||
/// address of each case buffer of a command buffer's owner (`addresses`, by its key and the
|
||||
/// buffer's Metal index, for the parent's bindings), and the compile of each child.
|
||||
pub(in crate::candidate::platform) struct Replay<'a, 'b, K> {
|
||||
@@ -197,18 +197,16 @@ pub(in crate::candidate::platform) fn execute_commands<'c, K: Ord + Copy + std::
|
||||
}
|
||||
let shape = state.shape();
|
||||
let stages = match (compile(token, &shape, &child)?, child) {
|
||||
(CompiledChild::Compute(compiled), ChildCommand::Dispatch(dispatch)) => {
|
||||
let pipeline = &compiled.pipeline;
|
||||
(CompiledChild::Compute(pipeline), ChildCommand::Dispatch(dispatch)) => {
|
||||
require_enabled(context, &pipeline.requirements)?;
|
||||
submit_child(context, device, pipeline, &state, &dispatch, &guest)
|
||||
submit_child(context, device, &pipeline, &state, &dispatch, &guest)
|
||||
.map_err(|error| refine(error, &fail))?;
|
||||
vec![pipeline.stage.clone()]
|
||||
}
|
||||
(CompiledChild::Render(case, compiled), ChildCommand::Draw { primitive, .. }) => {
|
||||
let pipeline = &compiled.pipeline;
|
||||
(CompiledChild::Render(case, pipeline), ChildCommand::Draw { primitive, .. }) => {
|
||||
require_enabled(context, &pipeline.requirements)?;
|
||||
super::super::render::submit_draw_child(
|
||||
context, device, &case, pipeline, &state, primitive, &guest,
|
||||
context, device, &case, &pipeline, &state, primitive, &guest,
|
||||
)
|
||||
.map_err(|error| refine(error, &fail))?;
|
||||
pipeline.stages.clone()
|
||||
@@ -354,9 +352,6 @@ fn submit_child(
|
||||
&Guest {
|
||||
buffers: guest,
|
||||
textures: &BTreeMap::new(),
|
||||
// A replayed command declares no out-of-bounds target.
|
||||
texel_guards: &BTreeMap::new(),
|
||||
tile_attachments: &BTreeMap::new(),
|
||||
status: Some(status.buffer.buffer),
|
||||
used_textures: &BTreeMap::new(),
|
||||
samplers: &BTreeMap::new(),
|
||||
@@ -364,7 +359,6 @@ fn submit_child(
|
||||
constant_blobs: &constant_blobs,
|
||||
descriptor_ranges: &commands.descriptor_ranges,
|
||||
descriptor_bytes: &commands.descriptor_bytes,
|
||||
structures: &BTreeMap::new(),
|
||||
tessellation_factors: None,
|
||||
attachments: &BTreeMap::new(),
|
||||
},
|
||||
|
||||
@@ -283,9 +283,6 @@ pub(super) struct ExtendedDynamicState {
|
||||
pub(super) depth_compare_op: vk::PFN_vkCmdSetDepthCompareOp,
|
||||
pub(super) stencil_test_enable: vk::PFN_vkCmdSetStencilTestEnable,
|
||||
pub(super) stencil_op: vk::PFN_vkCmdSetStencilOp,
|
||||
/// Binds vertex buffers with their strides, for a pipeline whose strides are dynamic state
|
||||
/// (`VERTEX_INPUT_BINDING_STRIDE`).
|
||||
pub(super) bind_vertex_buffers2: vk::PFN_vkCmdBindVertexBuffers2,
|
||||
/// `vkCmdSetPrimitiveRestartEnable`, Vulkan 1.3's core command or
|
||||
/// `VK_EXT_extended_dynamic_state2`'s where the context enabled it, for a pipeline that makes
|
||||
/// the topology and restart dynamic.
|
||||
@@ -305,7 +302,6 @@ impl ExtendedDynamicState {
|
||||
depth_compare_op: f.cmd_set_depth_compare_op,
|
||||
stencil_test_enable: f.cmd_set_stencil_test_enable,
|
||||
stencil_op: f.cmd_set_stencil_op,
|
||||
bind_vertex_buffers2: f.cmd_bind_vertex_buffers2,
|
||||
primitive_restart_enable: Some(f.cmd_set_primitive_restart_enable),
|
||||
}
|
||||
}
|
||||
@@ -326,7 +322,6 @@ impl ExtendedDynamicState {
|
||||
depth_compare_op: f.cmd_set_depth_compare_op_ext,
|
||||
stencil_test_enable: f.cmd_set_stencil_test_enable_ext,
|
||||
stencil_op: f.cmd_set_stencil_op_ext,
|
||||
bind_vertex_buffers2: f.cmd_bind_vertex_buffers2_ext,
|
||||
primitive_restart_enable: second.map(|s| s.fp().cmd_set_primitive_restart_enable_ext),
|
||||
}
|
||||
}
|
||||
@@ -384,8 +379,6 @@ pub(super) struct VulkanContext {
|
||||
/// The robustness features the context could not enable
|
||||
/// (`enables::Enables::unmet_robustness`): every run on the context is refused naming them.
|
||||
pub(super) unmet_robustness: BTreeSet<VkFeature>,
|
||||
/// What the context can do with a sparse case texture.
|
||||
pub(super) sparse_images: SparseImages,
|
||||
/// Whether the context enabled `VK_EXT_device_generated_commands` with its
|
||||
/// `deviceGeneratedCommands` ([`enables::enable_generated_commands`]).
|
||||
pub(super) generated_commands: bool,
|
||||
@@ -401,16 +394,6 @@ pub(super) struct VulkanContext {
|
||||
loader_word: LoaderWord,
|
||||
}
|
||||
|
||||
/// What a context can do with a sparse case texture: the executor features it enabled
|
||||
/// (`sparseBinding`, `sparseResidencyImage2D`, `sparseResidencyImage3D`, each where the device
|
||||
/// supports it, on an engine context only), and whether its queue binds sparse memory.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub(super) struct SparseImages {
|
||||
pub(super) features: BTreeSet<enables::ExecutorFeature>,
|
||||
/// The context's queue family has `VK_QUEUE_SPARSE_BINDING_BIT`.
|
||||
pub(super) queue: bool,
|
||||
}
|
||||
|
||||
/// Which Vulkan implementation a context opened: rows from different ICDs are different backends,
|
||||
/// never relabeled as one another.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -1824,14 +1807,6 @@ impl VulkanContext {
|
||||
// (false where the device lists no subset).
|
||||
let multisample_array_image = available.has(ash::khr::portability_subset::NAME)
|
||||
&& on(supported.portability_subset.multisample_array_image);
|
||||
// SAFETY: `physical` belongs to the live instance.
|
||||
let families = unsafe { instance.get_physical_device_queue_family_properties(physical) };
|
||||
let sparse_images = SparseImages {
|
||||
features: enables::executor_features(&enables),
|
||||
queue: families
|
||||
.get(queue_family as usize)
|
||||
.is_some_and(|family| family.queue_flags.contains(vk::QueueFlags::SPARSE_BINDING)),
|
||||
};
|
||||
Ok(Self {
|
||||
backend: SubmissionBackend::vulkan(device_type),
|
||||
_entry: entry,
|
||||
@@ -1857,7 +1832,6 @@ impl VulkanContext {
|
||||
restriction,
|
||||
hidden,
|
||||
unmet_robustness: enables.unmet_robustness,
|
||||
sparse_images,
|
||||
generated_commands,
|
||||
runtime_probe,
|
||||
messenger,
|
||||
@@ -1943,20 +1917,6 @@ impl VulkanContext {
|
||||
})
|
||||
}
|
||||
|
||||
/// `VK_KHR_acceleration_structure`'s commands, loaded through the loader's
|
||||
/// `vkGetDeviceProcAddr`, which reads the device's loader word ([`LoaderWord`]): the word is
|
||||
/// put back first. The commands work only where the context enabled the extension; otherwise
|
||||
/// each loads as a stub that panics when called.
|
||||
#[expect(
|
||||
clippy::disallowed_methods,
|
||||
reason = "the one call site, after the loader word is put back"
|
||||
)]
|
||||
pub(super) fn acceleration_structure(&self) -> ash::khr::acceleration_structure::Device {
|
||||
// SAFETY: the device is live, and its context is used by its own thread only.
|
||||
unsafe { self.loader_word.restore() };
|
||||
ash::khr::acceleration_structure::Device::new(&self.instance, &self.device)
|
||||
}
|
||||
|
||||
/// Everything the validation layer reported since the last call, and clear the sink.
|
||||
pub(super) fn take_messages(&self) -> Vec<String> {
|
||||
self.messages.take()
|
||||
@@ -2064,17 +2024,6 @@ impl VulkanContext {
|
||||
pub(super) fn wait_for_fence(&self, fence: vk::Fence, operation: &str) -> Result<(), String> {
|
||||
wait::vulkan::wait_for_fence(&self.device, fence, self.backend, operation)
|
||||
}
|
||||
|
||||
/// The device's viewport limits, which each region of a rate-mapped pass's plan must respect:
|
||||
/// `maxViewportDimensions` and `viewportBoundsRange`.
|
||||
pub(super) fn region_limits(&self) -> metal2vulkan::bind::RegionLimits {
|
||||
// SAFETY: `physical` was enumerated from `instance`, which is live.
|
||||
let limits = unsafe { self.instance.get_physical_device_properties(self.physical) }.limits;
|
||||
metal2vulkan::bind::RegionLimits::new(
|
||||
limits.max_viewport_dimensions,
|
||||
limits.viewport_bounds_range,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for VulkanContext {
|
||||
@@ -2323,13 +2272,11 @@ mod tests {
|
||||
}
|
||||
|
||||
/// The loader's own entry points the context calls after a driver overwrote the loader's word
|
||||
/// of the device still run. They are `vkAllocateCommandBuffers`, `vkGetDeviceProcAddr`
|
||||
/// (`VK_KHR_acceleration_structure`'s commands, which load whether or not the extension is
|
||||
/// enabled: an absent command loads as one that panics), and `vkDestroyDevice` when the context
|
||||
/// drops. Without the context putting the word back, the loader reads `ICD_LOADER_MAGIC` as its
|
||||
/// dispatch table and faults at `0x1cdc0de`. Our probe measured this at 9caf79a2, before
|
||||
/// the `vkGetDeviceProcAddr` step was added: the test passed on lavapipe and on MoltenVK, and
|
||||
/// on lavapipe a build without the allocation's and `Drop`'s restores failed it by `SIGSEGV`.
|
||||
/// of the device still run. They are `vkAllocateCommandBuffers`, and `vkDestroyDevice` when the
|
||||
/// context drops. Without the context putting the word back, the loader reads
|
||||
/// `ICD_LOADER_MAGIC` as its dispatch table and faults at `0x1cdc0de`. Our probe measured this
|
||||
/// at 9caf79a2: the test passed on lavapipe and on MoltenVK, and on lavapipe a build without the
|
||||
/// allocation's and `Drop`'s restores failed it by `SIGSEGV`.
|
||||
/// Other drivers are expected to behave the same, since the context has no layer and no driver
|
||||
/// reads the word, so the overwrite reaches only the loader.
|
||||
#[test]
|
||||
@@ -2349,9 +2296,6 @@ mod tests {
|
||||
// SAFETY: nothing was recorded into or submitted from the pool's buffer.
|
||||
unsafe { context.device.destroy_command_pool(pool, None) };
|
||||
overwrite_loader_word(&context);
|
||||
let commands = context.acceleration_structure();
|
||||
assert_eq!(commands.device(), context.device.handle());
|
||||
overwrite_loader_word(&context);
|
||||
drop(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,7 @@
|
||||
//! (`coverage::ROBUSTNESS_FEATURES`), so the opened profile compiles the robust containment
|
||||
//! encodings the device states. Extended dynamic state is enabled where
|
||||
//! the device lists it: a render pipeline states it as a requirement, and the render executor
|
||||
//! records its states. The [`ExecutorFeature`]s (sparse binding and residency) are enabled where
|
||||
//! the device supports them, for the executor's own sparse case textures: no pipeline requires
|
||||
//! them, so the opened profile does not see them.
|
||||
//! records its states.
|
||||
//!
|
||||
//! What a context enabled is read back from the enabled chain, member by member, through the
|
||||
//! one table ([`MEMBERS`]) that also writes it: [`enabled_set`] in the engine's vocabulary
|
||||
@@ -895,31 +893,6 @@ impl FeatureChain {
|
||||
}
|
||||
}
|
||||
|
||||
/// A feature an engine context enables for this executor's own objects rather than for any
|
||||
/// pipeline: no module requires it, and neither engine's vocabulary names it.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub(super) enum ExecutorFeature {
|
||||
/// `sparseBinding`: a sparse case texture's image binds its memory on the queue.
|
||||
SparseBinding,
|
||||
/// `sparseResidencyImage2D`: a 2D (or 2D array) sparse case texture is a sparse resident
|
||||
/// image.
|
||||
SparseResidencyImage2D,
|
||||
/// `sparseResidencyImage3D`: a 3D sparse case texture is a sparse resident image.
|
||||
SparseResidencyImage3D,
|
||||
}
|
||||
|
||||
impl ExecutorFeature {
|
||||
/// The member's name in the Vulkan registry, from its row ([`Member::registry`]): no
|
||||
/// `ExecutorFeature` is in the engine's vocabulary, so its row carries the name.
|
||||
pub(super) fn name(self) -> &'static str {
|
||||
MEMBERS
|
||||
.iter()
|
||||
.find(|member| member.executor == Some(self))
|
||||
.and_then(|member| member.registry)
|
||||
.expect("every executor feature has a row carrying its registry name")
|
||||
}
|
||||
}
|
||||
|
||||
/// One `VkBool32` member of a [`FeatureChain`] structure.
|
||||
pub(super) struct Member {
|
||||
pub(super) structure: Structure,
|
||||
@@ -929,13 +902,11 @@ pub(super) struct Member {
|
||||
pub(super) feature: Option<VkFeature>,
|
||||
/// The member's name in the Vulkan registry, carried for exactly the members the engine's
|
||||
/// vocabulary does not name ([`Member::feature`] is `None`). A device states such a member by
|
||||
/// this name alone: no `DeviceDescription` can carry it, so a model of a device reads it from
|
||||
/// the device's own capture by this name (`tests::Capture`), and a `None` row without one
|
||||
/// would be a member nothing could ever report as unsupported.
|
||||
/// this name alone: no `DeviceDescription` can carry it, so the tests' model of a device reads
|
||||
/// it from the device's own capture by this name (`tests::Capture`), and a `None` row without
|
||||
/// one would be a member nothing could ever report as unsupported.
|
||||
#[cfg(test)]
|
||||
pub(super) registry: Option<&'static str>,
|
||||
/// The executor's own name for it, when an engine context enables it for the executor's
|
||||
/// objects ([`ExecutorFeature`]).
|
||||
pub(super) executor: Option<ExecutorFeature>,
|
||||
read: fn(&FeatureChain) -> vk::Bool32,
|
||||
write: fn(&mut FeatureChain) -> &mut vk::Bool32,
|
||||
}
|
||||
@@ -951,20 +922,18 @@ impl Member {
|
||||
}
|
||||
|
||||
/// Defines [`MEMBERS`] from `structure.field.member => feature` rows. A row whose feature is
|
||||
/// `None` carries `, registry = "<its Vulkan name>"` ([`Member::registry`]), and one an engine
|
||||
/// context enables for the executor's own objects carries `, executor = <name>` after it.
|
||||
/// `None` carries `, registry = "<its Vulkan name>"` (`Member::registry`, read by the tests).
|
||||
macro_rules! members {
|
||||
($($structure:ident . $field:ident . $member:ident => $feature:expr
|
||||
$(, registry = $registry:literal)?
|
||||
$(, executor = $executor:expr)?;)*) => {
|
||||
$(, registry = $registry:literal)?;)*) => {
|
||||
/// Every member a context reads or writes, each once: the one table that enables a
|
||||
/// feature and names what was enabled.
|
||||
pub(super) const MEMBERS: &[Member] = &[$(Member {
|
||||
structure: Structure::$structure,
|
||||
name: stringify!($member),
|
||||
feature: $feature,
|
||||
#[cfg(test)]
|
||||
registry: members!(@optional $($registry)?),
|
||||
executor: members!(@optional $($executor)?),
|
||||
read: {
|
||||
fn read(chain: &FeatureChain) -> vk::Bool32 {
|
||||
chain.$field.$member
|
||||
@@ -987,7 +956,6 @@ macro_rules! members {
|
||||
};
|
||||
}
|
||||
|
||||
use ExecutorFeature as X;
|
||||
use VkFeature as F;
|
||||
|
||||
members! {
|
||||
@@ -1036,11 +1004,6 @@ members! {
|
||||
Core.core.full_draw_index_uint32 => Some(F::FullDrawIndexUint32);
|
||||
Core.core.shader_tessellation_and_geometry_point_size =>
|
||||
Some(F::ShaderTessellationAndGeometryPointSize);
|
||||
Core.core.sparse_binding => None, registry = "sparseBinding", executor = X::SparseBinding;
|
||||
Core.core.sparse_residency_image2_d => None, registry = "sparseResidencyImage2D",
|
||||
executor = X::SparseResidencyImage2D;
|
||||
Core.core.sparse_residency_image3_d => None, registry = "sparseResidencyImage3D",
|
||||
executor = X::SparseResidencyImage3D;
|
||||
V11.v11.storage_buffer16_bit_access => Some(F::StorageBuffer16BitAccess);
|
||||
V11.v11.uniform_and_storage_buffer16_bit_access => Some(F::UniformAndStorageBuffer16BitAccess);
|
||||
V11.v11.storage_push_constant16 => Some(F::StoragePushConstant16);
|
||||
@@ -1682,9 +1645,8 @@ pub(super) fn enable_runtime_probe(
|
||||
/// ([`ROBUSTNESS_FEATURES`]) the description states. Each recommended extension is enabled by the
|
||||
/// first name the device lists for it, each recommended feature by its member (chaining its
|
||||
/// structure through an enabled extension), and each member no vocabulary names
|
||||
/// (`textureCompressionASTC_HDR` and the rest, by their registry names, [`Member::registry`])
|
||||
/// where an enabled extension exposes its structure and the device supports it; and each
|
||||
/// [`ExecutorFeature`] where the device supports it.
|
||||
/// (`textureCompressionASTC_HDR` and the rest, by their registry names, `Member::registry`)
|
||||
/// where an enabled extension exposes its structure and the device supports it.
|
||||
///
|
||||
/// A stated robustness feature the feature chain does not report, or whose structure no enabled
|
||||
/// extension exposes, is not an error: no robustness feature is enabled then, and the stated ones
|
||||
@@ -1761,21 +1723,9 @@ pub(super) fn engine_list(
|
||||
member.set(&mut enables.chain);
|
||||
}
|
||||
}
|
||||
for member in MEMBERS.iter().filter(|member| member.executor.is_some()) {
|
||||
enables.copy(member, supported, available);
|
||||
}
|
||||
Ok(enables)
|
||||
}
|
||||
|
||||
/// The executor features `enables` enabled ([`ExecutorFeature`]).
|
||||
pub(super) fn executor_features(enables: &Enables) -> BTreeSet<ExecutorFeature> {
|
||||
MEMBERS
|
||||
.iter()
|
||||
.filter(|member| enabled(enables, member))
|
||||
.filter_map(|member| member.executor)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether the enabled chain of `enables` sets `member`'s bit through a structure it chains.
|
||||
fn enabled(enables: &Enables, member: &Member) -> bool {
|
||||
let chained = match member.structure {
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
amd-780m-hawkpoint-radv device f104739e9e2661ec21e62851c044f7ea5f161aff37b66ed33e13e34603d3e3a1 members=150 extensions=51
|
||||
amd-780m-hawkpoint-radv restricted c26c0fbac03f1627fe7a85c3f8259edff4f2bc332b014519144533162683cbe5 members=148 extensions=32
|
||||
amd-780m-radv device f104739e9e2661ec21e62851c044f7ea5f161aff37b66ed33e13e34603d3e3a1 members=150 extensions=51
|
||||
amd-780m-radv restricted c26c0fbac03f1627fe7a85c3f8259edff4f2bc332b014519144533162683cbe5 members=148 extensions=32
|
||||
amd-rdna2-apu-radv device f5a5c09eb47ad584428f319013d83222d749fa81b0660e06f6bc42794b7a9ef0 members=151 extensions=51
|
||||
amd-rdna2-apu-radv restricted b8a8f5a955871bbb456aff2678a1eb98919a323fc06d53ceaf6fe19a055ad4f8 members=149 extensions=32
|
||||
amd-rdna3-radv device f104739e9e2661ec21e62851c044f7ea5f161aff37b66ed33e13e34603d3e3a1 members=150 extensions=51
|
||||
amd-rdna3-radv restricted c26c0fbac03f1627fe7a85c3f8259edff4f2bc332b014519144533162683cbe5 members=148 extensions=32
|
||||
gate-lavapipe device b5ddddab0b92326e004341e0b1a7aeed2f25be4b5393307f774fa6cac04ddc7a members=149 extensions=48
|
||||
gate-lavapipe restricted 168eef90c56417253a74b57842c325b9a55b68767714fe6ca254ac6af383f5ad members=147 extensions=29
|
||||
gate-lavapipe-x86_64 device b5ddddab0b92326e004341e0b1a7aeed2f25be4b5393307f774fa6cac04ddc7a members=149 extensions=48
|
||||
gate-lavapipe-x86_64 restricted 168eef90c56417253a74b57842c325b9a55b68767714fe6ca254ac6af383f5ad members=147 extensions=29
|
||||
intel-arl-anv device bba82cf623659eec54d689658def06e54b7f0afd0bd6f2df87d513530c9e2f3f members=148 extensions=49
|
||||
intel-arl-anv restricted 0c12dd0a2a58473f74b41e3deb86e6dba53e70d1c04924dff8260d9171d21d43 members=146 extensions=30
|
||||
intel-irisxe-anv device 3c75b664300b00dcf2ca09831f7687fd6be9c6991a6edb62a69986cf21d200d2 members=134 extensions=44
|
||||
intel-irisxe-anv restricted aec53caa6392a62cc7f264e6315fd91edb7e7ff747c8ab66515d73105403a188 members=132 extensions=25
|
||||
intel-irisxe-rplp-anv device 3c75b664300b00dcf2ca09831f7687fd6be9c6991a6edb62a69986cf21d200d2 members=134 extensions=44
|
||||
intel-irisxe-rplp-anv restricted aec53caa6392a62cc7f264e6315fd91edb7e7ff747c8ab66515d73105403a188 members=132 extensions=25
|
||||
intel-uhd770-rpls-anv device 3c75b664300b00dcf2ca09831f7687fd6be9c6991a6edb62a69986cf21d200d2 members=134 extensions=44
|
||||
intel-uhd770-rpls-anv restricted aec53caa6392a62cc7f264e6315fd91edb7e7ff747c8ab66515d73105403a188 members=132 extensions=25
|
||||
lavapipe device b5ddddab0b92326e004341e0b1a7aeed2f25be4b5393307f774fa6cac04ddc7a members=149 extensions=48
|
||||
lavapipe restricted 168eef90c56417253a74b57842c325b9a55b68767714fe6ca254ac6af383f5ad members=147 extensions=29
|
||||
amd-780m-hawkpoint-radv device 8fef8ecec0b3eb2b3093a11ffba939d551d4073f98b24ac2d43731813b642669 members=147 extensions=51
|
||||
amd-780m-hawkpoint-radv restricted f362d1a71220ab78dff66acf8d6b6ee50219368287e6fada628d1a9d0b6584a5 members=145 extensions=32
|
||||
amd-780m-radv device 8fef8ecec0b3eb2b3093a11ffba939d551d4073f98b24ac2d43731813b642669 members=147 extensions=51
|
||||
amd-780m-radv restricted f362d1a71220ab78dff66acf8d6b6ee50219368287e6fada628d1a9d0b6584a5 members=145 extensions=32
|
||||
amd-rdna2-apu-radv device 82dfbe79571e8f029c24aa15ed4ce80c675aac7dd165b964cac74d952e762933 members=148 extensions=51
|
||||
amd-rdna2-apu-radv restricted a99bd94a0f733ce4eb0ad0b963d834a4bc4154174b5c3f5d874ea094dabcd632 members=146 extensions=32
|
||||
amd-rdna3-radv device 8fef8ecec0b3eb2b3093a11ffba939d551d4073f98b24ac2d43731813b642669 members=147 extensions=51
|
||||
amd-rdna3-radv restricted f362d1a71220ab78dff66acf8d6b6ee50219368287e6fada628d1a9d0b6584a5 members=145 extensions=32
|
||||
gate-lavapipe device 470a6c659853921b70a5fc47eeff627024699443fec4e14db62fe472c1903779 members=146 extensions=48
|
||||
gate-lavapipe restricted ab67fbb5abe0d50891a7c05e3160bf20dbc6da68ec430f515c1465300c32f7c4 members=144 extensions=29
|
||||
gate-lavapipe-x86_64 device 470a6c659853921b70a5fc47eeff627024699443fec4e14db62fe472c1903779 members=146 extensions=48
|
||||
gate-lavapipe-x86_64 restricted ab67fbb5abe0d50891a7c05e3160bf20dbc6da68ec430f515c1465300c32f7c4 members=144 extensions=29
|
||||
intel-arl-anv device 490c19b3ddd28dd78f1cf221c47012f473c3c286bea9a0deccb209ef936ba089 members=145 extensions=49
|
||||
intel-arl-anv restricted 7de9b8701e2f6483eb34fe181258619014985a44e8309d207361ff6e52b0e130 members=143 extensions=30
|
||||
intel-irisxe-anv device 671fec888ac841a30de3ce51a06fd669b63e811ec017a0acf7e33d80f0b1192d members=131 extensions=44
|
||||
intel-irisxe-anv restricted 19d47a3689a267787baf01ca87f38cad67e9a0a88fbdf3d07beb379d0862bc0c members=129 extensions=25
|
||||
intel-irisxe-rplp-anv device 671fec888ac841a30de3ce51a06fd669b63e811ec017a0acf7e33d80f0b1192d members=131 extensions=44
|
||||
intel-irisxe-rplp-anv restricted 19d47a3689a267787baf01ca87f38cad67e9a0a88fbdf3d07beb379d0862bc0c members=129 extensions=25
|
||||
intel-uhd770-rpls-anv device 671fec888ac841a30de3ce51a06fd669b63e811ec017a0acf7e33d80f0b1192d members=131 extensions=44
|
||||
intel-uhd770-rpls-anv restricted 19d47a3689a267787baf01ca87f38cad67e9a0a88fbdf3d07beb379d0862bc0c members=129 extensions=25
|
||||
lavapipe device 470a6c659853921b70a5fc47eeff627024699443fec4e14db62fe472c1903779 members=146 extensions=48
|
||||
lavapipe restricted ab67fbb5abe0d50891a7c05e3160bf20dbc6da68ec430f515c1465300c32f7c4 members=144 extensions=29
|
||||
moltenvk-m3 device fba1f14799f8de2f3fce11270bfe5acfe70a9181fba05b39b03ca584abb02353 members=110 extensions=35
|
||||
moltenvk-m3 restricted 29f45720a234e7d9a6d6539d970e098623a37105073f268b6c3f7d4d5e654e1f members=108 extensions=15
|
||||
nvidia-pascal-linux device f207a75377dbd3941f1f16cdbfa02fc5cb2fed4c04119e3645542499c61a6a17 members=138 extensions=40
|
||||
nvidia-pascal-linux restricted 4b2e5af7f5e86ab2f8638691d5bf649fe91c4cf883777115b0d68cd8a297c6f1 members=136 extensions=21
|
||||
nvidia-rtx50-linux device cbc227d09a278b641ac92963d31c69c73a5b377d9e641882b62937299e7cec4c members=152 extensions=50
|
||||
nvidia-rtx50-linux restricted 0de75175778cf3738fef0e8311e2452598e707f4ca5b744b865c2ef6ed0452cd members=150 extensions=31
|
||||
nvidia-rtx5080-laptop device cbc227d09a278b641ac92963d31c69c73a5b377d9e641882b62937299e7cec4c members=152 extensions=50
|
||||
nvidia-rtx5080-laptop restricted 0de75175778cf3738fef0e8311e2452598e707f4ca5b744b865c2ef6ed0452cd members=150 extensions=31
|
||||
nvidia-pascal-linux device de68854a001c472412947358cec38b6520256375bad2d519dc956895c62e4a1c members=135 extensions=40
|
||||
nvidia-pascal-linux restricted 43c7169b5a6189a500d9abe4bd506549751bfae07d4bf511134da7851683b9fc members=133 extensions=21
|
||||
nvidia-rtx50-linux device 519533e41cf40fed1d8f602a64b0ee7eaf392e2e9d96bff7137703bb5220276f members=149 extensions=50
|
||||
nvidia-rtx50-linux restricted 2029fcd82315bc8b15b41da5fd840e7bdf3596444fd70922f5701b7e24382fef members=147 extensions=31
|
||||
nvidia-rtx5080-laptop device 519533e41cf40fed1d8f602a64b0ee7eaf392e2e9d96bff7137703bb5220276f members=149 extensions=50
|
||||
nvidia-rtx5080-laptop restricted 2029fcd82315bc8b15b41da5fd840e7bdf3596444fd70922f5701b7e24382fef members=147 extensions=31
|
||||
runtime-floor device 35a2f1eb212749175ca1916712fd51f2b6f3b581ee9efcd87885631ec576611f members=48 extensions=2
|
||||
runtime-floor restricted 431519ffc473256488efe51b8668e5ac9f77b06390c68c5100629065c6b76943 members=56 extensions=2
|
||||
@@ -88,8 +88,8 @@ impl Capture {
|
||||
/// What a device described by `description` supports, as a chain: every member the description
|
||||
/// lists, and every member the engine's vocabulary does not name as `capture`, the device's own,
|
||||
/// states it. Claiming the latter supported would model a device no profile describes:
|
||||
/// `moltenvk-m3` states `sparseBinding` and every line-rasterization member false, and
|
||||
/// `swiftshader` states `textureCompressionASTC_HDR` false.
|
||||
/// `moltenvk-m3` states every line-rasterization member false, and `swiftshader` states
|
||||
/// `textureCompressionASTC_HDR` false.
|
||||
fn supported_by(description: &DeviceDescription, capture: &Capture) -> FeatureChain {
|
||||
let mut chain = FeatureChain::default();
|
||||
for member in MEMBERS {
|
||||
@@ -168,9 +168,8 @@ fn listed_at(version: ApiVersion, description: &DeviceDescription, capture: &Cap
|
||||
/// Every member the engine's vocabulary does not name carries its registry name, and no member it
|
||||
/// names carries one. That name is the only way a model of a device can read what the device
|
||||
/// states about the member, so a `None` row without one is a member nothing can report
|
||||
/// unsupported. The executor's own names are those rows' ([`ExecutorFeature::name`]), and every
|
||||
/// name is one some committed capture states, so a misspelling cannot read as an unsupported
|
||||
/// member on every device.
|
||||
/// unsupported. Every name is one some committed capture states, so a misspelling cannot read as
|
||||
/// an unsupported member on every device.
|
||||
#[test]
|
||||
fn a_member_the_vocabulary_does_not_name_carries_its_registry_name() {
|
||||
let mut unnamed = 0;
|
||||
@@ -190,17 +189,8 @@ fn a_member_the_vocabulary_does_not_name_carries_its_registry_name() {
|
||||
unnamed += 1;
|
||||
}
|
||||
}
|
||||
if let Some(executor) = member.executor {
|
||||
assert_eq!(
|
||||
Some(executor.name()),
|
||||
member.registry,
|
||||
"{:?}.{}",
|
||||
member.structure,
|
||||
member.name
|
||||
);
|
||||
}
|
||||
}
|
||||
assert_eq!(unnamed, 14, "members the vocabulary does not name");
|
||||
assert_eq!(unnamed, 11, "members the vocabulary does not name");
|
||||
// Every one of them is a name some committed capture states: a misspelled name would read as
|
||||
// a device that does not support the member, on every device.
|
||||
let captures: Vec<Capture> = committed_profiles()
|
||||
@@ -794,51 +784,6 @@ fn a_disagreeing_description_is_refused() {
|
||||
assert!(error.contains("ExtRobustness2"), "{error}");
|
||||
}
|
||||
|
||||
/// An engine context enables sparse binding and 2D and 3D sparse residency where the device
|
||||
/// supports them, for the executor's sparse case textures. The vocabulary does not name them, so
|
||||
/// the opened profile does not move; the old engine's list enables none, and a device without them
|
||||
/// gets none.
|
||||
#[test]
|
||||
fn the_new_list_enables_sparse_images_where_the_device_supports_them() {
|
||||
for member in MEMBERS.iter().filter(|member| member.executor.is_some()) {
|
||||
assert_eq!(member.structure, Structure::Core);
|
||||
assert!(member.feature.is_none());
|
||||
}
|
||||
let description = at_1_2(load_description("lavapipe").unwrap());
|
||||
let (supported, available) = modelled("lavapipe", &description, ApiVersion::V1_2);
|
||||
assert!(executor_features(&old_engine_list(&supported, &available)).is_empty());
|
||||
let list = |supported: &FeatureChain| {
|
||||
engine_list(
|
||||
old_engine_list(supported, &available),
|
||||
&description,
|
||||
supported,
|
||||
&available,
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
let enables = list(&supported);
|
||||
assert_eq!(
|
||||
executor_features(&enables),
|
||||
BTreeSet::from([
|
||||
ExecutorFeature::SparseBinding,
|
||||
ExecutorFeature::SparseResidencyImage2D,
|
||||
ExecutorFeature::SparseResidencyImage3D,
|
||||
])
|
||||
);
|
||||
assert_eq!(enables.chain.core.sparse_binding, vk::TRUE);
|
||||
assert_eq!(enables.chain.core.sparse_residency_image2_d, vk::TRUE);
|
||||
assert_eq!(enables.chain.core.sparse_residency_image3_d, vk::TRUE);
|
||||
let mut without = supported;
|
||||
without.core.sparse_binding = vk::FALSE;
|
||||
without.core.sparse_residency_image3_d = vk::FALSE;
|
||||
let enables = list(&without);
|
||||
assert_eq!(
|
||||
executor_features(&enables),
|
||||
BTreeSet::from([ExecutorFeature::SparseResidencyImage2D])
|
||||
);
|
||||
assert_eq!(enabled_set(&enables), enabled_set(&list(&supported)));
|
||||
}
|
||||
|
||||
/// The executor's MoltenVK device (the Q1 refusals): the old list dropped subgroup size control and
|
||||
/// the memory model, so the opened kernel stage could not require full subgroups; the engine's
|
||||
/// list enables both, and the opened profile carries them.
|
||||
|
||||
@@ -18,35 +18,28 @@
|
||||
//! image per texture whatever writes view it (every view of one member takes one layout); each
|
||||
//! stage's handle table is a buffer of exactly the bytes instantiation gave it, bound over
|
||||
//! exactly its planned length;
|
||||
//! - a texel-buffer write views the slot's buffer with the plan's format over the plan's range;
|
||||
//! - a sampler (plain, or the sampler half of a combined write) is `bind::sampler_desc` of the
|
||||
//! bound descriptor for the write's use, and the image format for a combined write; an
|
||||
//! immutable one is the layout's;
|
||||
//! - a neutral image is created once per kind, cleared to zero, and left in the layout its
|
||||
//! descriptor type reads (`GENERAL` for storage, `SHADER_READ_ONLY_OPTIMAL` otherwise); a
|
||||
//! neutral texel buffer is 16 zero bytes; the neutral sampler is nearest and clamped;
|
||||
//! - an acceleration-structure write binds the top-level structure of the case's structure at
|
||||
//! the write's slot, built before the work ([`Structures`]);
|
||||
//! - a tessellation-factor write binds the draw's factor buffer over exactly the plan's range;
|
||||
//! - an input-attachment write views the draw's color attachment of its index in `GENERAL`, the
|
||||
//! layout the render pass keeps a framebuffer-fetch attachment in;
|
||||
//! - a tile-attachment write views the tile pass's color attachment of its index, one 2D image of
|
||||
//! the attachment's format, extent, and contents, as a storage image in `GENERAL`: uploaded
|
||||
//! before the work and read back after it like a bound texture.
|
||||
//! layout the render pass keeps a framebuffer-fetch attachment in.
|
||||
//!
|
||||
//! The run keeps no imageblock storage: an imageblock write fails. Inline bytes are typed
|
||||
//! The run keeps no imageblock storage: an imageblock write fails. A write of a source the runtime
|
||||
//! does not build (a texture buffer, an acceleration structure, a tile pass's attachment, a sparse
|
||||
//! texture's tile map), which the case's requirements refuse first, and inline bytes are typed
|
||||
//! `NotImplemented`. Descriptor sets come from one
|
||||
//! pool sized from the layout's bindings, update-after-bind when the layout has the heap's set
|
||||
//! ([`PlanResources::write_sets`]).
|
||||
|
||||
use super::acceleration::Structures;
|
||||
use super::acceptance::LayoutObjects;
|
||||
use super::buffers::{create_guarded_host_buffer, create_host_buffer, HostBuffer};
|
||||
use super::buffers::{create_host_buffer, HostBuffer};
|
||||
use super::device::VulkanContext;
|
||||
use super::multisample::initialize_multisample_image;
|
||||
use super::sparse_images::{create_sparse_image, create_tile_mapped_image};
|
||||
use crate::candidate::engine::guards::{GuardCount, GuardReach};
|
||||
use crate::candidate::engine::{bind_refusal, CaseStructure};
|
||||
use crate::candidate::engine::bind_refusal;
|
||||
use crate::check::admission::{ExecutorError, NotSupported};
|
||||
use crate::literal::{texture_layout, LiteralTexture, TextureLayout};
|
||||
use ash::vk;
|
||||
@@ -59,7 +52,7 @@ use metal2vulkan::device::Device;
|
||||
use metal2vulkan::metal::sampler::{OpaqueBlackBorder, SamplerUse};
|
||||
use metal2vulkan::pipeline::{SlotRef, Stage};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Bytes of a neutral texel buffer: one texel of any format the core declares.
|
||||
@@ -69,14 +62,12 @@ fn not_implemented(what: impl Into<String>) -> ExecutorError {
|
||||
NotSupported::NotImplemented(format!("engine candidate: {}", what.into())).into()
|
||||
}
|
||||
|
||||
/// A texture a plan write views: the texture bound at a slot, the used texture with a consumer
|
||||
/// token (a heap member; an argument-buffer texture), or the color attachment of an index that a
|
||||
/// tile pass stages.
|
||||
/// A texture a plan write views: the texture bound at a slot, or the used texture with a consumer
|
||||
/// token (a heap member; an argument-buffer texture).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(super) enum TextureKey {
|
||||
Slot(SlotRef),
|
||||
Used(u32),
|
||||
TileAttachment(u32),
|
||||
}
|
||||
|
||||
impl TextureKey {
|
||||
@@ -93,7 +84,6 @@ impl TextureKey {
|
||||
match self {
|
||||
TextureKey::Slot(slot) => format!("texture {}", slot.index),
|
||||
TextureKey::Used(token) => format!("used texture {token}"),
|
||||
TextureKey::TileAttachment(index) => format!("storage attachment {index}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,11 +92,8 @@ impl TextureKey {
|
||||
pub(super) struct Guest<'a> {
|
||||
/// Each bound buffer's allocation, by slot.
|
||||
pub(super) buffers: &'a BTreeMap<SlotRef, vk::Buffer>,
|
||||
/// Each bound texture (texture buffers included) with its initial contents, by slot.
|
||||
/// Each bound texture with its initial contents, by slot.
|
||||
pub(super) textures: &'a BTreeMap<SlotRef, &'a LiteralTexture>,
|
||||
/// The guard reach of each texture buffer the case declares an out-of-bounds target, by slot:
|
||||
/// its buffer is allocated inside a guard of that reach.
|
||||
pub(super) texel_guards: &'a BTreeMap<SlotRef, GuardReach>,
|
||||
/// Each used texture (an argument-buffer texture) with its initial contents, by consumer
|
||||
/// token.
|
||||
pub(super) used_textures: &'a BTreeMap<u32, &'a LiteralTexture>,
|
||||
@@ -119,16 +106,11 @@ pub(super) struct Guest<'a> {
|
||||
pub(super) constant_blobs: &'a BTreeMap<Stage, Arc<[u8]>>,
|
||||
pub(super) descriptor_ranges: &'a [DescriptorRange],
|
||||
pub(super) descriptor_bytes: &'a [DescriptorBytes],
|
||||
/// Each bound acceleration structure, by slot.
|
||||
pub(super) structures: &'a BTreeMap<SlotRef, CaseStructure>,
|
||||
/// The encoder's tessellation factor buffer of a patch draw.
|
||||
pub(super) tessellation_factors: Option<vk::Buffer>,
|
||||
/// Each color target's view of a draw's pass, by Metal index: what an input-attachment write
|
||||
/// reads (framebuffer fetch), in `GENERAL`. A dispatch has none.
|
||||
pub(super) attachments: &'a BTreeMap<u32, vk::ImageView>,
|
||||
/// A tile pass's color attachments with their initial contents, by color index: 2D textures
|
||||
/// the tile-attachment writes view. A draw, and a dispatch of no tile function, have none.
|
||||
pub(super) tile_attachments: &'a BTreeMap<u32, LiteralTexture>,
|
||||
/// The run's `ExecutionStatus` buffer, which a stage binds on a device that does not address
|
||||
/// buffers (`WriteSource::ExecutionStatus`). A device replay, which needs the addresses,
|
||||
/// has none.
|
||||
@@ -140,7 +122,6 @@ enum Info {
|
||||
Buffer(vk::DescriptorBufferInfo),
|
||||
Image(vk::DescriptorImageInfo),
|
||||
Texel(vk::BufferView),
|
||||
AccelerationStructure(vk::AccelerationStructureKHR),
|
||||
}
|
||||
|
||||
/// One resolved descriptor write.
|
||||
@@ -166,8 +147,7 @@ struct SlotImage {
|
||||
/// The authored contents, uploaded before the work; `None` for a multisampled image, which
|
||||
/// its own initializer submission wrote per sample and left in `GENERAL`.
|
||||
staging: Option<HostBuffer>,
|
||||
/// The copies from `staging` that upload the image: each level's whole extent, or a sparse
|
||||
/// image's mapped texels alone.
|
||||
/// The copies from `staging` that upload the image: each level's whole extent.
|
||||
copies: Vec<vk::BufferImageCopy>,
|
||||
/// The final contents, when the texture is the observed output.
|
||||
readback: Option<HostBuffer>,
|
||||
@@ -206,10 +186,6 @@ pub(super) struct PlanResources<'a> {
|
||||
descriptor_pool: vk::DescriptorPool,
|
||||
/// Buffers this module allocated (neutrals, tables, blobs).
|
||||
buffers: Vec<HostBuffer>,
|
||||
/// Each bound texture buffer's allocation.
|
||||
texel_buffers: BTreeMap<SlotRef, HostBuffer>,
|
||||
/// The acceleration structures the writes bind.
|
||||
structures: Structures,
|
||||
}
|
||||
|
||||
impl Drop for PlanResources<'_> {
|
||||
@@ -291,8 +267,6 @@ impl<'a> PlanResources<'a> {
|
||||
samplers: Vec::new(),
|
||||
descriptor_pool: vk::DescriptorPool::null(),
|
||||
buffers: Vec::new(),
|
||||
texel_buffers: BTreeMap::new(),
|
||||
structures: Structures::new(context),
|
||||
};
|
||||
// Every view of each texture first: its image serves all of them.
|
||||
let mut uses: BTreeMap<TextureKey, TextureUse> = BTreeMap::new();
|
||||
@@ -307,14 +281,6 @@ impl<'a> PlanResources<'a> {
|
||||
WriteSource::HeapEntry { source, view, .. } => {
|
||||
(TextureKey::of_heap(*source)?, ViewUse::from(view))
|
||||
}
|
||||
// In the plan's view format, which makes the image mutable to it.
|
||||
WriteSource::TileAttachment {
|
||||
color_index,
|
||||
format,
|
||||
} => (
|
||||
TextureKey::TileAttachment(*color_index),
|
||||
tile_attachment_view(guest, *color_index, *format)?,
|
||||
),
|
||||
_ => continue,
|
||||
};
|
||||
let entry = uses.entry(key).or_default();
|
||||
@@ -325,30 +291,18 @@ impl<'a> PlanResources<'a> {
|
||||
entry.sampled = true;
|
||||
}
|
||||
}
|
||||
// The slots whose sparse texture the plan answers from a tile map: made as the runtime
|
||||
// makes them (`create_slot_image`).
|
||||
let tiled: BTreeSet<SlotRef> = descriptors
|
||||
.iter()
|
||||
.filter_map(|write| match &write.source {
|
||||
WriteSource::TileMap { slot } => Some(*slot),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
for (&key, texture_use) in &uses {
|
||||
let texture: &LiteralTexture = match key {
|
||||
TextureKey::Slot(slot) => guest.textures.get(&slot).copied(),
|
||||
TextureKey::Used(token) => guest.used_textures.get(&token).copied(),
|
||||
TextureKey::TileAttachment(index) => guest.tile_attachments.get(&index),
|
||||
}
|
||||
.ok_or_else(|| format!("the plan views {} that is not bound", key.label()))?;
|
||||
let emulated = matches!(key, TextureKey::Slot(slot) if tiled.contains(&slot));
|
||||
let image = create_slot_image(
|
||||
context,
|
||||
&key.label(),
|
||||
texture,
|
||||
texture_use,
|
||||
observed == Some(key),
|
||||
emulated,
|
||||
)?;
|
||||
resources.images.insert(key, image);
|
||||
}
|
||||
@@ -569,35 +523,6 @@ impl<'a> PlanResources<'a> {
|
||||
.image_layout(layout),
|
||||
)
|
||||
}
|
||||
WriteSource::TexelBuffer { slot, format, .. } => {
|
||||
let texture = guest
|
||||
.textures
|
||||
.get(slot)
|
||||
.ok_or_else(|| format!("the plan views unbound texture buffer {slot:?}"))?;
|
||||
let range = range(key)?;
|
||||
let usage = if is_storage(ty) {
|
||||
vk::BufferUsageFlags::STORAGE_TEXEL_BUFFER
|
||||
} else {
|
||||
vk::BufferUsageFlags::UNIFORM_TEXEL_BUFFER
|
||||
};
|
||||
if self.texel_buffers.contains_key(slot) {
|
||||
return Err(not_implemented("one texture buffer behind two descriptors"));
|
||||
}
|
||||
let label = format!("texture buffer {}", slot.index);
|
||||
let guard = guest.texel_guards.get(slot).copied();
|
||||
let view = (range.offset, range.range);
|
||||
let bytes = texel_buffer_bytes(&texture.bytes, view, guard.is_some())
|
||||
.map_err(|error| format!("{label}: {error}"))?;
|
||||
let buffer = match guard {
|
||||
Some(reach) => {
|
||||
create_guarded_host_buffer(context, &label, &bytes, usage, reach)?
|
||||
}
|
||||
None => create_host_buffer(context, &label, &bytes, usage)?,
|
||||
};
|
||||
let view = self.buffer_view(context, buffer.buffer, (*format).into(), view)?;
|
||||
self.texel_buffers.insert(*slot, buffer);
|
||||
Info::Texel(view)
|
||||
}
|
||||
WriteSource::Neutral(NeutralResource::TexelBuffer { format }) => {
|
||||
let usage = if is_storage(ty) {
|
||||
vk::BufferUsageFlags::STORAGE_TEXEL_BUFFER
|
||||
@@ -656,56 +581,9 @@ impl<'a> PlanResources<'a> {
|
||||
.image_layout(vk::ImageLayout::GENERAL),
|
||||
)
|
||||
}
|
||||
WriteSource::AccelerationStructure { slot, level } => Info::AccelerationStructure(
|
||||
self.structures
|
||||
.top_level(context, *slot, *level, guest.structures.get(slot))?,
|
||||
),
|
||||
WriteSource::Imageblock => {
|
||||
return Err("the plan binds an imageblock storage the run does not keep".into())
|
||||
}
|
||||
// A tile pass's color attachment, a storage image in the plan's view format in
|
||||
// `GENERAL`.
|
||||
WriteSource::TileAttachment {
|
||||
color_index,
|
||||
format,
|
||||
} => {
|
||||
let key = TextureKey::TileAttachment(*color_index);
|
||||
let (image, layout) = self.image(key)?;
|
||||
let format = tile_attachment_view(guest, *color_index, *format)?.format;
|
||||
let info = vk::ImageViewCreateInfo::default()
|
||||
.image(image)
|
||||
.view_type(vk::ImageViewType::TYPE_2D)
|
||||
.format(format)
|
||||
.subresource_range(self::range(vk::ImageAspectFlags::COLOR, 1));
|
||||
// SAFETY: `info` names a live image of this run.
|
||||
let view = unsafe { context.device.create_image_view(&info, None) }
|
||||
.map_err(|error| format!("create the {} view: {error}", key.label()))?;
|
||||
self.views.push(view);
|
||||
Info::Image(
|
||||
vk::DescriptorImageInfo::default()
|
||||
.image_view(view)
|
||||
.image_layout(layout),
|
||||
)
|
||||
}
|
||||
// A sparse texture's tile map: the map of the case's mappings, as the consumer keeps
|
||||
// it, over exactly its bytes.
|
||||
WriteSource::TileMap { slot } => {
|
||||
use crate::executor_contract::sparse::{tile_map, tile_map_tiling};
|
||||
let texture = guest
|
||||
.textures
|
||||
.get(slot)
|
||||
.ok_or_else(|| format!("the plan reads the tile map of unbound {slot:?}"))?;
|
||||
let map = tile_map(texture, tile_map_tiling(texture)?)?.ok_or_else(|| {
|
||||
format!("the plan reads the tile map of {slot:?}, not sparse")
|
||||
})?;
|
||||
let buffer = self.buffer(context, "tile map", &map.to_bytes())?;
|
||||
Info::Buffer(
|
||||
vk::DescriptorBufferInfo::default()
|
||||
.buffer(buffer.buffer)
|
||||
.offset(0)
|
||||
.range(map.byte_len()),
|
||||
)
|
||||
}
|
||||
other => return Err(not_implemented(format!("the descriptor source {other:?}"))),
|
||||
})
|
||||
}
|
||||
@@ -945,8 +823,8 @@ impl<'a> PlanResources<'a> {
|
||||
Ok((view, layout))
|
||||
}
|
||||
|
||||
/// Record, before the work: every acceleration structure's build, and every bound texture's
|
||||
/// upload and every neutral image's clear, each left in the layout its descriptors name.
|
||||
/// Record, before the work: every bound texture's upload and every neutral image's clear, each
|
||||
/// left in the layout its descriptors name.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
@@ -954,8 +832,6 @@ impl<'a> PlanResources<'a> {
|
||||
/// until its submission completes.
|
||||
pub(super) unsafe fn record_uploads(&self, command: vk::CommandBuffer) {
|
||||
let device = self.device;
|
||||
// SAFETY: the caller's contract.
|
||||
unsafe { self.structures.record(command) };
|
||||
let to_transfer: Vec<vk::ImageMemoryBarrier<'_>> = self
|
||||
.images
|
||||
.values()
|
||||
@@ -1096,8 +972,8 @@ impl<'a> PlanResources<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Record, after the work: the observed texture's copy into its host readback, and a
|
||||
/// shader-to-host dependency for texture buffers.
|
||||
/// Record, after the work: a shader-to-host dependency, and the observed texture's copy into its
|
||||
/// host readback.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
@@ -1166,8 +1042,8 @@ impl<'a> PlanResources<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// `texture` (the texture `key`) with its final contents: the observed image's readback, a
|
||||
/// texture buffer's bytes, or its authored bytes when no descriptor of the plan reaches it.
|
||||
/// `texture` (the texture `key`) with its final contents: the observed image's readback, or its
|
||||
/// authored bytes when no descriptor of the plan reaches it.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
@@ -1177,10 +1053,6 @@ impl<'a> PlanResources<'a> {
|
||||
key: TextureKey,
|
||||
texture: &LiteralTexture,
|
||||
) -> Result<LiteralTexture, String> {
|
||||
let texel_buffer = match key {
|
||||
TextureKey::Slot(slot) => self.texel_buffers.get(&slot),
|
||||
TextureKey::Used(_) | TextureKey::TileAttachment(_) => None,
|
||||
};
|
||||
let bytes = if let Some(image) = self.images.get(&key) {
|
||||
let readback = image
|
||||
.readback
|
||||
@@ -1188,9 +1060,6 @@ impl<'a> PlanResources<'a> {
|
||||
.ok_or_else(|| format!("{} was not read back", key.label()))?;
|
||||
// SAFETY: the caller's contract.
|
||||
unsafe { readback.map()? }.bytes[..texture.bytes.len()].to_vec()
|
||||
} else if let Some(buffer) = texel_buffer {
|
||||
// SAFETY: the caller's contract.
|
||||
unsafe { buffer.map()? }.bytes[..texture.bytes.len()].to_vec()
|
||||
} else {
|
||||
texture.bytes.clone()
|
||||
};
|
||||
@@ -1200,25 +1069,6 @@ impl<'a> PlanResources<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The guard and padding bytes each guarded texture buffer's run changed, by slot
|
||||
/// ([`HostBuffer::escaped`]).
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The submission that used the resources has completed.
|
||||
pub(super) unsafe fn texel_guard_counts(
|
||||
&self,
|
||||
) -> Result<BTreeMap<SlotRef, GuardCount>, String> {
|
||||
let mut counts = BTreeMap::new();
|
||||
for (&slot, buffer) in &self.texel_buffers {
|
||||
// SAFETY: the caller's contract.
|
||||
if let Some(count) = unsafe { buffer.escaped()? } {
|
||||
counts.insert(slot, count);
|
||||
}
|
||||
}
|
||||
Ok(counts)
|
||||
}
|
||||
|
||||
/// Allocate one descriptor set per layout set, from one pool sized from the layout's
|
||||
/// bindings (each binding's whole count, written or not: a heap array's capacity, an
|
||||
/// immutable heap sampler the plan never writes) and update-after-bind when the layout has
|
||||
@@ -1244,19 +1094,6 @@ impl<'a> PlanResources<'a> {
|
||||
// SAFETY: the pool and the layouts are live; the sets are freed with the pool.
|
||||
let sets = unsafe { context.device.allocate_descriptor_sets(&allocate_info) }
|
||||
.map_err(|error| format!("allocate descriptor sets: {error}"))?;
|
||||
// Each acceleration-structure write's chained structure list, one per such write in order.
|
||||
let mut chained: Vec<vk::WriteDescriptorSetAccelerationStructureKHR<'_>> = self
|
||||
.writes
|
||||
.iter()
|
||||
.filter_map(|write| match &write.info {
|
||||
Info::AccelerationStructure(structure) => Some(
|
||||
vk::WriteDescriptorSetAccelerationStructureKHR::default()
|
||||
.acceleration_structures(std::slice::from_ref(structure)),
|
||||
),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
let mut chained = chained.iter_mut();
|
||||
let mut vk_writes = Vec::with_capacity(self.writes.len());
|
||||
for write in &self.writes {
|
||||
let set = *sets
|
||||
@@ -1271,9 +1108,6 @@ impl<'a> PlanResources<'a> {
|
||||
Info::Buffer(info) => base.buffer_info(std::slice::from_ref(info)),
|
||||
Info::Image(info) => base.image_info(std::slice::from_ref(info)),
|
||||
Info::Texel(view) => base.texel_buffer_view(std::slice::from_ref(view)),
|
||||
Info::AccelerationStructure(_) => base
|
||||
.descriptor_count(1)
|
||||
.push_next(chained.next().ok_or("an unchained structure write")?),
|
||||
});
|
||||
}
|
||||
// SAFETY: every set, buffer, view, sampler, and info array is live for the call.
|
||||
@@ -1282,25 +1116,6 @@ impl<'a> PlanResources<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The view of color attachment `index` of a tile pass in the plan's `format`, in `GENERAL`: the
|
||||
/// attachment's own format for an integer one and the unsigned-integer format of the same channels
|
||||
/// for a float one, which [`create_slot_image`] makes the image `MUTABLE_FORMAT` for.
|
||||
fn tile_attachment_view(
|
||||
guest: &Guest<'_>,
|
||||
index: u32,
|
||||
format: metal2vulkan::vk::Format,
|
||||
) -> Result<ViewUse, ExecutorError> {
|
||||
if !guest.tile_attachments.contains_key(&index) {
|
||||
return Err(
|
||||
format!("the plan views storage attachment {index}, which the pass lacks").into(),
|
||||
);
|
||||
}
|
||||
Ok(ViewUse {
|
||||
layout: vk::ImageLayout::GENERAL,
|
||||
format: format.into(),
|
||||
})
|
||||
}
|
||||
|
||||
/// The descriptor of the sampler bound at `slot`.
|
||||
fn bound_sampler<'g>(
|
||||
guest: &'g Guest<'_>,
|
||||
@@ -1320,31 +1135,6 @@ pub(super) fn padded(bytes: &[u8]) -> Vec<u8> {
|
||||
out
|
||||
}
|
||||
|
||||
/// The bytes a texture buffer's host buffer is created from, for its `view` (offset, range).
|
||||
/// An unguarded one is [`padded`]. A guarded one (an out-of-bounds target) is exactly its view, so
|
||||
/// every byte past the view is the memory requirement's padding or the guard, and a write there is
|
||||
/// counted ([`HostBuffer::escaped`]); bytes padded inside the buffer would be neither. The view
|
||||
/// must then cover the authored bytes from offset 0, as the case checker makes it.
|
||||
fn texel_buffer_bytes(
|
||||
bytes: &[u8],
|
||||
view: (vk::DeviceSize, vk::DeviceSize),
|
||||
guarded: bool,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
if !guarded {
|
||||
return Ok(padded(bytes));
|
||||
}
|
||||
if view != (0, bytes.len() as vk::DeviceSize) {
|
||||
return Err(format!(
|
||||
"a guarded texture buffer is exactly its view, but the view [{}, +{}) is not its {} \
|
||||
authored bytes",
|
||||
view.0,
|
||||
view.1,
|
||||
bytes.len()
|
||||
));
|
||||
}
|
||||
Ok(bytes.to_vec())
|
||||
}
|
||||
|
||||
fn sample_count(samples: u32) -> Result<vk::SampleCountFlags, ExecutorError> {
|
||||
Ok(match samples {
|
||||
1 => vk::SampleCountFlags::TYPE_1,
|
||||
@@ -1621,18 +1411,13 @@ pub(super) fn multisample_initializer_support(
|
||||
/// texture's own (a storage alias), the one layout every view names, and a host readback when it
|
||||
/// is the `observed` output. Each level is uploaded whole from its bytes ([`level_uploads`]). A
|
||||
/// mipmapped texture is one the case checker admits (`case::mips`): single-sample, not sparse,
|
||||
/// and an input, which no executor reads back. A sparse texture is a sparse resident image, or,
|
||||
/// where the plan answers its residency from a tile map (`emulated`), what the runtime makes of
|
||||
/// it: a sparse resident image with each block that holds a mapped tile bound, its unmapped
|
||||
/// texels zero, where the context makes one, else an ordinary image holding its mapped texels and
|
||||
/// zero elsewhere.
|
||||
/// and an input, which no executor reads back.
|
||||
fn create_slot_image(
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
texture: &LiteralTexture,
|
||||
texture_use: &TextureUse,
|
||||
observed: bool,
|
||||
emulated: bool,
|
||||
) -> Result<SlotImage, ExecutorError> {
|
||||
use crate::case::TextureType as T;
|
||||
let pixel_format = crate::candidate::engine::resources::pixel_format(texture.format);
|
||||
@@ -1652,11 +1437,11 @@ fn create_slot_image(
|
||||
let (image_type, extent) = image_shape(texture.texture_type, &literal)
|
||||
.ok_or_else(|| format!("{label} is a texture buffer, not an image"))?;
|
||||
let multisampled = literal.sample_count != 1;
|
||||
// Levels only where the checker admits them: a multisampled or sparse image is made and
|
||||
// uploaded one level, and a readback copies one.
|
||||
if texture.mip_levels != 1 && (multisampled || texture.sparse.is_some() || observed) {
|
||||
// Levels only where the checker admits them: a multisampled image is made and uploaded one
|
||||
// level, and a readback copies one.
|
||||
if texture.mip_levels != 1 && (multisampled || observed) {
|
||||
return Err(not_implemented(format!(
|
||||
"{label}: a mipmapped texture ({} levels) that is multisampled, sparse, or read back",
|
||||
"{label}: a mipmapped texture ({} levels) that is multisampled or read back",
|
||||
texture.mip_levels
|
||||
)));
|
||||
}
|
||||
@@ -1696,54 +1481,8 @@ fn create_slot_image(
|
||||
.usage(usage)
|
||||
.sharing_mode(vk::SharingMode::EXCLUSIVE)
|
||||
.initial_layout(vk::ImageLayout::UNDEFINED);
|
||||
// A sparse texture is a sparse resident image with the case's regions bound, and uploads its
|
||||
// mapped texels alone. One whose plan answers its residency from a tile map is what the runtime
|
||||
// makes of it: where the context makes a sparse resident image, one with each block that holds
|
||||
// a mapped tile bound and uploaded whole, its unmapped texels zero; elsewhere an ordinary image
|
||||
// holding its mapped texels and zero elsewhere. Any other image is bound whole and uploaded
|
||||
// whole.
|
||||
let mapped = match (&texture.sparse, emulated) {
|
||||
(Some(_), true) => {
|
||||
use crate::executor_contract::sparse::{
|
||||
device_mappings, mapped_bytes, mapped_texels, tile_map_tiling,
|
||||
};
|
||||
// A region the emulation's tiles do not divide is refused as a device's own tiles
|
||||
// refuse it, before anything is made.
|
||||
let refused = |why: String| ExecutorError::from(NotSupported::NotEnabled(vec![why]));
|
||||
let tiling = tile_map_tiling(texture).map_err(refused)?;
|
||||
let mappings = device_mappings(texture, tiling)
|
||||
.map_err(refused)?
|
||||
.unwrap_or_default();
|
||||
let regions = mapped_texels(texture, tiling, &mappings)?;
|
||||
Some((mapped_bytes(texture, ®ions)?, regions))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let tile_mapped = match &mapped {
|
||||
Some((_, regions)) if !multisampled => {
|
||||
create_tile_mapped_image(context, label, texture, info, regions)?
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let (level_bytes, level_copies) = level_uploads(texture, aspect)?;
|
||||
let upload: &[u8] = match &mapped {
|
||||
Some((bytes, _)) => bytes,
|
||||
None => &level_bytes,
|
||||
};
|
||||
let (image, memory, copies) = if let Some(sparse) = tile_mapped {
|
||||
(sparse.image, sparse.memory, sparse.copies)
|
||||
} else if texture.sparse.is_some() && !emulated {
|
||||
if multisampled {
|
||||
return Err(not_implemented(format!(
|
||||
"{label}: a multisampled sparse texture"
|
||||
)));
|
||||
}
|
||||
let sparse = create_sparse_image(context, label, texture, info)?;
|
||||
(sparse.image, sparse.memory, sparse.copies)
|
||||
} else {
|
||||
let (image, memory) = create_image(context, label, &info)?;
|
||||
(image, memory, level_copies)
|
||||
};
|
||||
let (upload, copies) = level_uploads(texture, aspect)?;
|
||||
let (image, memory) = create_image(context, label, &info)?;
|
||||
let destroy = || {
|
||||
// SAFETY: the image and memory were created above and are unused.
|
||||
unsafe {
|
||||
@@ -1769,7 +1508,7 @@ fn create_slot_image(
|
||||
match create_host_buffer(
|
||||
context,
|
||||
&format!("{label} staging"),
|
||||
upload,
|
||||
&upload,
|
||||
vk::BufferUsageFlags::TRANSFER_SRC,
|
||||
) {
|
||||
Ok(staging) => Some(staging),
|
||||
@@ -1884,24 +1623,3 @@ fn level_uploads(
|
||||
}
|
||||
Ok((Cow::Owned(staged), copies))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::texel_buffer_bytes;
|
||||
|
||||
/// A guarded texture buffer is created from exactly its view: five `r8_uint` texels make a
|
||||
/// 5-byte buffer, so a write to texel 5 lands in the memory requirement's padding or the guard,
|
||||
/// where it is counted, not in bytes the buffer pads itself to 16 with. An unguarded one is
|
||||
/// still padded to 16, and a guarded view that is not its authored bytes is refused.
|
||||
#[test]
|
||||
fn a_guarded_texture_buffer_is_exactly_its_view() {
|
||||
let texels = [1, 2, 3, 4, 5];
|
||||
assert_eq!(texel_buffer_bytes(&texels, (0, 5), true).unwrap(), texels);
|
||||
let padded = texel_buffer_bytes(&texels, (0, 5), false).unwrap();
|
||||
assert_eq!(padded.len(), 16);
|
||||
assert_eq!(&padded[..5], &texels);
|
||||
assert!(texel_buffer_bytes(&texels, (0, 4), true)
|
||||
.unwrap_err()
|
||||
.contains("is exactly its view"));
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,7 @@
|
||||
//!
|
||||
//! - the viewport is the whole target with a negative height, so framebuffer rows, `FragCoord`,
|
||||
//! and derivative signs match Metal's y-up clip space without touching the shader (spec
|
||||
//! "Y-flip"); the scissor is the whole target. A rate-mapped pass is drawn on the product's
|
||||
//! region path, on every device (Metal's pass over the identity, a near-equivalent over any other
|
||||
//! map): the draw is recorded once per region of the map's plan for the map's screen
|
||||
//! (`graphics::rate_map_regions`), each with its region's viewport, flipped the same way, and its
|
||||
//! scissor, into the targets, which hold the screen and so the compile's physical size;
|
||||
//! "Y-flip"); the scissor is the whole target;
|
||||
//! - the front face is the case's front-facing winding (`graphics::RenderCase::
|
||||
//! depth_stencil_state`; Metal's default is clockwise, [`super::METAL_DEFAULT_FRONT_FACE`]), and
|
||||
//! culling is the case's (`graphics::RenderCase::cull_mode`: a tessellation case's authored one,
|
||||
@@ -23,9 +19,7 @@
|
||||
//! would otherwise take statically: the case's culling and front face, the draw's topology, and
|
||||
//! the depth-stencil state below, through Vulkan 1.3's core commands in a context at 1.3 or later
|
||||
//! (one restricted to a profile of that version), else `VK_EXT_extended_dynamic_state`'s
|
||||
//! (`device::ExtendedDynamicState`); a per-bind vertex stride (`VERTEX_INPUT_BINDING_STRIDE`, a
|
||||
//! layout of `MTLBufferLayoutStrideDynamic`) is recorded as the vertex buffers are bound, every
|
||||
//! binding's stride the binder's (`DrawCommands::vertex_strides`);
|
||||
//! (`device::ExtendedDynamicState`);
|
||||
//! - every color attachment, and a fragment case's depth/stencil attachment (one Vulkan
|
||||
//! attachment for Metal's separate depth and stencil ones, holding each authored aspect), is
|
||||
//! loaded before and stored after the draw, and the depth-stencil state is the one the Metal
|
||||
@@ -41,11 +35,7 @@
|
||||
//! - a patch draw binds its factor buffer where the plan's `WriteSource::TessellationFactors` names
|
||||
//! it, over the draw's range, and draws a patch list: the tessellation pipeline's synthesized
|
||||
//! vertex and control stages bind nothing of Metal's, and its evaluation stage binds the vertex
|
||||
//! function's resources;
|
||||
//! - a fragment case's explicit imageblock holds the cells the Metal oracle's initializer
|
||||
//! defines. The product compiles no fragment function that reads or writes an imageblock
|
||||
//! (`Feature::Imageblocks`), so a pipeline that draws reaches none (the function dropped every
|
||||
//! view) and leaves the cells as the initializer left them, as Metal's pass does.
|
||||
//! function's resources.
|
||||
//!
|
||||
//! The run obeys the compute executor's rules (status before output, the validation layer); a
|
||||
//! pipeline whose modules loop draws once, as compiled, like any other.
|
||||
@@ -55,7 +45,7 @@ use super::buffers::{create_host_buffer, HostBuffer};
|
||||
use super::compute::{
|
||||
allocate, allocate_in, attempt, command_replay, environment, executed_census,
|
||||
incompatible_binding, module_censuses, opened_device, refused_attempt, replay_commands,
|
||||
table_bytes, upload_root_table, Allocation, CompileChild, Live, OnDevice, Replay, ReplayPath,
|
||||
upload_root_table, Allocation, CompileChild, Live, OnDevice, Replay, ReplayPath,
|
||||
};
|
||||
use super::device::{with_validated_context, ExtendedDynamicState, VulkanContext};
|
||||
use super::graphics_pipeline::{self, GraphicsError};
|
||||
@@ -69,7 +59,7 @@ use crate::candidate::engine::graphics::{
|
||||
use crate::candidate::engine::guards::{declared_reach, with_escaped, GuardCount};
|
||||
use crate::candidate::engine::{
|
||||
bind_refusal, draw_out_of_bounds_run, engine_fingerprint, resources, status_verdict,
|
||||
BufferAddress, CompiledCase, ComputeRun, RunAttempt,
|
||||
BufferAddress, ComputeRun, RunAttempt,
|
||||
};
|
||||
use crate::candidate::engine::{index_padding_agrees, ChildCommand, CompiledChild};
|
||||
use crate::case::out_of_bounds::OutOfBoundsResource;
|
||||
@@ -84,7 +74,7 @@ use crate::worker::compile::WorkerDevice;
|
||||
use ash::vk;
|
||||
use metal2vulkan::bind::{
|
||||
BindShape, BindState, BindingPlan, BufferRanges, DrawCommands, ExecutionStatus, PushHole,
|
||||
RateMapRegions, SamplerDescriptor, StatusReport, DRAW_ARGUMENT_BYTES,
|
||||
SamplerDescriptor, StatusReport, DRAW_ARGUMENT_BYTES,
|
||||
};
|
||||
use metal2vulkan::device::Device;
|
||||
use metal2vulkan::device::VkFeature;
|
||||
@@ -99,7 +89,7 @@ fn not_implemented(what: impl Into<String>) -> ExecutorError {
|
||||
|
||||
/// Compile `case` for the device `device_type` opens with `compile` (given the opened device's
|
||||
/// description and policy and the bind shape the draw binds, `graphics::render_shape`; the tools'
|
||||
/// compile worker; it returns the pipeline and its visible-function tables' bytes), plan and
|
||||
/// compile worker; it returns the pipeline), plan and
|
||||
/// execute its draw, and read the status before the output. Every refusal is typed; only a device,
|
||||
/// driver, or tool failure is `Failed`. `children` compiles the template each command the case
|
||||
/// executes runs, in a compile worker.
|
||||
@@ -107,10 +97,7 @@ pub fn execute_engine_render(
|
||||
device_type: DeviceType,
|
||||
case_id: &str,
|
||||
case: &RenderCase,
|
||||
compile: impl FnOnce(
|
||||
&WorkerDevice,
|
||||
&BindShape,
|
||||
) -> Result<CompiledCase<RenderPipeline>, ExecutorError>,
|
||||
compile: impl FnOnce(&WorkerDevice, &BindShape) -> Result<RenderPipeline, ExecutorError>,
|
||||
children: impl FnMut(
|
||||
&WorkerDevice,
|
||||
u64,
|
||||
@@ -133,7 +120,7 @@ fn run(
|
||||
case_id: &str,
|
||||
case: &RenderCase,
|
||||
(compile, mut children): (
|
||||
impl FnOnce(&WorkerDevice, &BindShape) -> Result<CompiledCase<RenderPipeline>, ExecutorError>,
|
||||
impl FnOnce(&WorkerDevice, &BindShape) -> Result<RenderPipeline, ExecutorError>,
|
||||
impl FnMut(
|
||||
&WorkerDevice,
|
||||
u64,
|
||||
@@ -149,19 +136,12 @@ fn run(
|
||||
.contains(&VkFeature::BufferDeviceAddress);
|
||||
let ranges = BufferRanges::of(target.device().profile().limits());
|
||||
let shape = graphics::render_shape(case, addressed, ranges).map_err(ExecutorError::Failed)?;
|
||||
let compiled = compile(&target, &shape)?;
|
||||
let pipeline = &compiled.pipeline;
|
||||
let pipeline = &compile(&target, &shape)?;
|
||||
let device = target.device();
|
||||
let missing = unmet_requirements(context, &pipeline.requirements);
|
||||
if !missing.is_empty() {
|
||||
return Err(NotSupported::NotEnabled(missing).into());
|
||||
}
|
||||
// A rate-mapped pass's regions, planned for the device's viewport limits and this pipeline
|
||||
// before anything is allocated.
|
||||
let rate_map = case.rate_map_pass.as_ref();
|
||||
let regions = rate_map
|
||||
.map(|map| graphics::rate_map_regions(map, &context.region_limits(), &pipeline.graphics))
|
||||
.transpose()?;
|
||||
// How the Metal vertex function's module contains each out-of-bounds target on this device,
|
||||
// decided before anything runs; a target checked nowhere is refused, never run.
|
||||
let out_of_bounds = draw_out_of_bounds_run(device, pipeline, case)?;
|
||||
@@ -194,8 +174,8 @@ fn run(
|
||||
execute(
|
||||
context,
|
||||
device,
|
||||
(&compiled, &shape),
|
||||
(case, regions.as_ref()),
|
||||
(pipeline, &shape),
|
||||
case,
|
||||
out_of_bounds.as_ref(),
|
||||
&mut compile_child,
|
||||
)
|
||||
@@ -226,14 +206,11 @@ fn run(
|
||||
let planned = pipeline.plan(device, &shape).ok();
|
||||
let mut modules = module_censuses(&pipeline.stages, device.profile(), planned.as_ref())?;
|
||||
modules.extend(children);
|
||||
let mut census = executed_census(
|
||||
let census = executed_census(
|
||||
context,
|
||||
modules,
|
||||
out_of_bounds.map(|run| with_escaped(run, &escaped)),
|
||||
);
|
||||
census.rate_map_pass = rate_map
|
||||
.zip(regions.as_ref())
|
||||
.map(|(map, plan)| graphics::rate_map_pass_census(map, plan));
|
||||
let mut environment = environment(context, device, "engine-render");
|
||||
command_replay(&mut environment, &replayed);
|
||||
super::device::record_withheld(&mut environment, withheld);
|
||||
@@ -251,8 +228,7 @@ fn run(
|
||||
/// Allocate the case's buffers (argument-buffer buffers first, so each owner is created with
|
||||
/// their addresses, its textures' and samplers' resource ids, and its command buffers',
|
||||
/// [`field_words`],
|
||||
/// [`owner_bytes`]), visible-function tables (holding the compile's table bytes), and vertex
|
||||
/// buffers, write the commands the host encodes into their record storage, plan and instantiate
|
||||
/// [`owner_bytes`]) and vertex buffers, write the commands the host encodes into their record storage, plan and instantiate
|
||||
/// its draw, create what every plan write names (argument-buffer textures, heap arrays, and
|
||||
/// handle tables included), the color targets, and the pipeline, record and submit the draw,
|
||||
/// wait, read the status, check the records, execute the commands the case executes (`compile`
|
||||
@@ -262,12 +238,11 @@ fn run(
|
||||
fn execute(
|
||||
context: &VulkanContext,
|
||||
device: &Device,
|
||||
(compiled, compiled_for): (&CompiledCase<RenderPipeline>, &BindShape),
|
||||
(case, regions): (&RenderCase, Option<&RateMapRegions>),
|
||||
(pipeline, compiled_for): (&RenderPipeline, &BindShape),
|
||||
case: &RenderCase,
|
||||
out_of_bounds: Option<&OutOfBoundsRun>,
|
||||
compile: &mut CompileChild<'_>,
|
||||
) -> Result<Drawn, ExecutorError> {
|
||||
let CompiledCase { pipeline, tables } = compiled;
|
||||
let addressed = context
|
||||
.enabled
|
||||
.features
|
||||
@@ -337,21 +312,6 @@ fn execute(
|
||||
buffers.insert((stage, index), allocation);
|
||||
}
|
||||
}
|
||||
let mut table_buffers: BTreeMap<(Stage, u32), Allocation> = BTreeMap::new();
|
||||
for (stage, function) in case.stages() {
|
||||
for (&index, table) in &function.resources.function_tables {
|
||||
let bytes = table_bytes(tables, stage, index, table.byte_len())?;
|
||||
let label = format!("{stage:?} visible function table {index}");
|
||||
let allocation = allocate(
|
||||
context,
|
||||
&label,
|
||||
bytes,
|
||||
addressed,
|
||||
vk::BufferUsageFlags::empty(),
|
||||
)?;
|
||||
table_buffers.insert((stage, index), allocation);
|
||||
}
|
||||
}
|
||||
// A patch draw's factors, read by the control stage as a storage buffer.
|
||||
let factors = match &case.assembly {
|
||||
Assembly::Patches { factors, .. } => Some(allocate(
|
||||
@@ -392,7 +352,6 @@ fn execute(
|
||||
}
|
||||
let addresses: BTreeMap<(Stage, u32), BufferAddress> = buffers
|
||||
.iter()
|
||||
.chain(&table_buffers)
|
||||
.map(|(&(stage, index), allocation)| {
|
||||
let address = own_guest(allocation, graphics::synthetic_address(stage, index))?;
|
||||
Ok(((stage, index), address))
|
||||
@@ -475,7 +434,6 @@ fn execute(
|
||||
)?;
|
||||
let guest_buffers: BTreeMap<SlotRef, vk::Buffer> = buffers
|
||||
.iter()
|
||||
.chain(&table_buffers)
|
||||
.map(|(&(stage, index), allocation)| {
|
||||
(
|
||||
slot(stage, SlotClass::Buffer, index),
|
||||
@@ -531,8 +489,7 @@ fn execute(
|
||||
| RenderOutput::ArgumentBufferBuffer { .. }
|
||||
| RenderOutput::RenderTarget { .. }
|
||||
| RenderOutput::Depth { .. }
|
||||
| RenderOutput::Stencil { .. }
|
||||
| RenderOutput::Imageblock { .. } => None,
|
||||
| RenderOutput::Stencil { .. } => None,
|
||||
};
|
||||
// The attachments first: a framebuffer-fetch input's descriptor views its color attachment.
|
||||
let targets = Targets::create(context, &pipeline.graphics, case)?;
|
||||
@@ -550,20 +507,14 @@ fn execute(
|
||||
&Guest {
|
||||
buffers: &guest_buffers,
|
||||
textures: &textures,
|
||||
// A render case's out-of-bounds targets are attribute and index buffers, none a texture
|
||||
// buffer.
|
||||
texel_guards: &BTreeMap::new(),
|
||||
used_textures: &used_textures,
|
||||
samplers: &samplers,
|
||||
argument_samplers: &state.argument_samplers,
|
||||
constant_blobs: &constant_blobs,
|
||||
descriptor_ranges: &commands.descriptor_ranges,
|
||||
descriptor_bytes: &commands.descriptor_bytes,
|
||||
// `graphics::render_case` refuses a case's acceleration structures.
|
||||
structures: &BTreeMap::new(),
|
||||
tessellation_factors: factors.as_ref().map(|factors| factors.buffer.buffer),
|
||||
attachments: &attachments,
|
||||
tile_attachments: &BTreeMap::new(),
|
||||
status: Some(status.buffer.buffer),
|
||||
},
|
||||
observed,
|
||||
@@ -608,10 +559,6 @@ fn execute(
|
||||
encoder,
|
||||
)?;
|
||||
let sets = resources.write_sets(context, &objects.layout)?;
|
||||
// Where the pipeline's strides are dynamic state, every binding is bound with its stride.
|
||||
let dynamic_strides = pipeline.graphics.dynamic_states.iter().any(|&state| {
|
||||
vk::DynamicState::from(state) == vk::DynamicState::VERTEX_INPUT_BINDING_STRIDE
|
||||
});
|
||||
let vertex_buffers: Vec<VertexBinding> = plan
|
||||
.vertex_buffers
|
||||
.iter()
|
||||
@@ -627,21 +574,9 @@ fn execute(
|
||||
.find(|(binding, _)| *binding == bind.binding)
|
||||
.map(|&(_, offset)| offset)
|
||||
.ok_or_else(|| format!("no offset for vertex binding {}", bind.binding))?;
|
||||
let stride = if dynamic_strides {
|
||||
let stride = commands
|
||||
.vertex_strides
|
||||
.iter()
|
||||
.find(|(binding, _)| *binding == bind.binding)
|
||||
.map(|&(_, stride)| u64::from(stride))
|
||||
.ok_or_else(|| format!("no stride for vertex binding {}", bind.binding))?;
|
||||
Some(stride)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok((bind.binding, buffer.buffer.buffer, offset, stride))
|
||||
Ok((bind.binding, buffer.buffer.buffer, offset))
|
||||
})
|
||||
.collect::<Result<_, ExecutorError>>()?;
|
||||
let draws = draws(targets.extent, regions);
|
||||
record_and_submit(
|
||||
context,
|
||||
&mut objects,
|
||||
@@ -649,7 +584,7 @@ fn execute(
|
||||
resources: &resources,
|
||||
targets: &targets,
|
||||
readers: readers.as_ref(),
|
||||
draws: &draws,
|
||||
area: draw_area(targets.extent),
|
||||
sets: &sets,
|
||||
push: &push,
|
||||
vertex_buffers: &vertex_buffers,
|
||||
@@ -729,20 +664,11 @@ fn execute(
|
||||
.resources
|
||||
.buffers
|
||||
.get(&index)
|
||||
.map(|bytes| bytes.len() as u64)
|
||||
.or_else(|| {
|
||||
function
|
||||
.resources
|
||||
.function_tables
|
||||
.get(&index)
|
||||
.map(|table| table.byte_len())
|
||||
})
|
||||
.unwrap_or(0)
|
||||
.map_or(0, |bytes| bytes.len() as u64)
|
||||
})
|
||||
};
|
||||
let live = buffers
|
||||
.iter()
|
||||
.chain(&table_buffers)
|
||||
.filter(|(&(stage, index), _)| lengths(stage, index) != 0)
|
||||
.map(|(&(stage, index), allocation)| {
|
||||
(
|
||||
@@ -842,10 +768,6 @@ fn execute(
|
||||
}
|
||||
// SAFETY: as for the status buffer.
|
||||
finals.depth_stencil = unsafe { targets.final_depth_stencil()? };
|
||||
// No write reaches the imageblock: the cells are the initializer's.
|
||||
if let (RenderOutput::Imageblock { .. }, Some(cells)) = (case.output, &case.imageblock) {
|
||||
finals.imageblock = Some(cells.clone());
|
||||
}
|
||||
let output =
|
||||
graphics::select_render_output(case.output, &finals).map_err(ExecutorError::Failed)?;
|
||||
drop(objects);
|
||||
@@ -1033,18 +955,14 @@ fn draw_child(
|
||||
&Guest {
|
||||
buffers: guest,
|
||||
textures: &BTreeMap::new(),
|
||||
// A replayed command declares no out-of-bounds target.
|
||||
texel_guards: &BTreeMap::new(),
|
||||
used_textures: &BTreeMap::new(),
|
||||
samplers: &BTreeMap::new(),
|
||||
argument_samplers: &state.argument_samplers,
|
||||
constant_blobs: &constant_blobs,
|
||||
descriptor_ranges: &commands.descriptor_ranges,
|
||||
descriptor_bytes: &commands.descriptor_bytes,
|
||||
structures: &BTreeMap::new(),
|
||||
tessellation_factors: None,
|
||||
attachments: &BTreeMap::new(),
|
||||
tile_attachments: &BTreeMap::new(),
|
||||
status: Some(status.buffer.buffer),
|
||||
},
|
||||
None,
|
||||
@@ -1091,8 +1009,7 @@ fn draw_child(
|
||||
resources: &resources,
|
||||
targets: &targets,
|
||||
readers: readers.as_ref(),
|
||||
// A replayed draw's pass is its template's, which has no rate map.
|
||||
draws: &draws(targets.extent, None),
|
||||
area: draw_area(targets.extent),
|
||||
sets: &sets,
|
||||
push: &push,
|
||||
vertex_buffers: &[],
|
||||
@@ -1919,13 +1836,8 @@ fn create_pipeline(
|
||||
/// draw's own state (its topology, primitive restart and depth-stencil state).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum DynamicRecord {
|
||||
/// The viewport and scissor, set for each recording of the draw ([`draws`]).
|
||||
/// The viewport and scissor, set with the draw ([`draw_area`]).
|
||||
PerDraw,
|
||||
/// The per-bind vertex strides (`VERTEX_INPUT_BINDING_STRIDE`, a vertex layout of
|
||||
/// `MTLBufferLayoutStrideDynamic` where the profile makes strides dynamic), recorded with the
|
||||
/// vertex buffers at the strides the case binds them with, through
|
||||
/// [`VulkanContext::extended_dynamic_state`].
|
||||
Strides,
|
||||
/// A Vulkan 1.0 command of the bound pipeline.
|
||||
Core,
|
||||
/// A state `VK_EXT_extended_dynamic_state` defines (core in Vulkan 1.3), or the primitive
|
||||
@@ -1940,7 +1852,6 @@ impl DynamicRecord {
|
||||
use vk::DynamicState as D;
|
||||
Some(match state {
|
||||
D::VIEWPORT | D::SCISSOR => DynamicRecord::PerDraw,
|
||||
D::VERTEX_INPUT_BINDING_STRIDE => DynamicRecord::Strides,
|
||||
D::DEPTH_BIAS
|
||||
| D::BLEND_CONSTANTS
|
||||
| D::STENCIL_COMPARE_MASK
|
||||
@@ -1961,7 +1872,7 @@ impl DynamicRecord {
|
||||
|
||||
/// Whether the draw records it through [`VulkanContext::extended_dynamic_state`].
|
||||
fn needs_extended(self) -> bool {
|
||||
matches!(self, DynamicRecord::Strides | DynamicRecord::Extended)
|
||||
matches!(self, DynamicRecord::Extended)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1996,8 +1907,8 @@ struct Recording<'r> {
|
||||
/// The per-sample fill and readback of a multisampled pass's attachments; `None` for one
|
||||
/// sample, whose attachments `targets` copies.
|
||||
readers: Option<&'r multisampled::SampleReaders<'r>>,
|
||||
/// The draw's viewport and scissor, once per recording of it ([`draws`]).
|
||||
draws: &'r [(vk::Viewport, vk::Rect2D)],
|
||||
/// The draw's viewport and scissor ([`draw_area`]).
|
||||
area: (vk::Viewport, vk::Rect2D),
|
||||
sets: &'r [vk::DescriptorSet],
|
||||
push: &'r [(vk::ShaderStageFlags, u32, Vec<u8>)],
|
||||
/// Each vertex buffer's binding.
|
||||
@@ -2023,52 +1934,26 @@ struct Recording<'r> {
|
||||
replayed: Option<&'r ReplayedDraws<'r>>,
|
||||
}
|
||||
|
||||
/// A vertex buffer's `(binding, buffer, offset, stride)`, the stride where the pipeline's
|
||||
/// strides are dynamic state (`VERTEX_INPUT_BINDING_STRIDE`), every binding's then.
|
||||
type VertexBinding = (u32, vk::Buffer, u64, Option<u64>);
|
||||
/// A vertex buffer's `(binding, buffer, offset)`.
|
||||
type VertexBinding = (u32, vk::Buffer, u64);
|
||||
|
||||
/// The draw's `(viewport, scissor)`, once per recording of it: the whole target `extent` with a
|
||||
/// negative height (the module docs), or, for a rate-mapped pass, each region of its plan, whose
|
||||
/// Metal-convention viewport `[x, y, width, height]` (y down) is flipped the same way, `y + height`
|
||||
/// and `-height`, with the region's scissor.
|
||||
fn draws(
|
||||
extent: vk::Extent2D,
|
||||
regions: Option<&RateMapRegions>,
|
||||
) -> Vec<(vk::Viewport, vk::Rect2D)> {
|
||||
let flipped = |[x, y, width, height]: [f32; 4]| vk::Viewport {
|
||||
x,
|
||||
y: y + height,
|
||||
width,
|
||||
height: -height,
|
||||
min_depth: 0.0,
|
||||
max_depth: 1.0,
|
||||
};
|
||||
let Some(plan) = regions else {
|
||||
return vec![(
|
||||
flipped([0.0, 0.0, extent.width as f32, extent.height as f32]),
|
||||
vk::Rect2D {
|
||||
offset: vk::Offset2D { x: 0, y: 0 },
|
||||
extent,
|
||||
},
|
||||
)];
|
||||
};
|
||||
plan.regions()
|
||||
.iter()
|
||||
.map(|region| {
|
||||
let [x, y] = region.scissor_offset();
|
||||
let [width, height] = region.scissor_extent();
|
||||
(
|
||||
flipped(region.viewport()),
|
||||
vk::Rect2D {
|
||||
offset: vk::Offset2D {
|
||||
x: x as i32,
|
||||
y: y as i32,
|
||||
},
|
||||
extent: vk::Extent2D { width, height },
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
/// The draw's `(viewport, scissor)`: the whole target `extent`, the viewport with a negative height
|
||||
/// (the module docs).
|
||||
fn draw_area(extent: vk::Extent2D) -> (vk::Viewport, vk::Rect2D) {
|
||||
(
|
||||
vk::Viewport {
|
||||
x: 0.0,
|
||||
y: extent.height as f32,
|
||||
width: extent.width as f32,
|
||||
height: -(extent.height as f32),
|
||||
min_depth: 0.0,
|
||||
max_depth: 1.0,
|
||||
},
|
||||
vk::Rect2D {
|
||||
offset: vk::Offset2D { x: 0, y: 0 },
|
||||
extent,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether `state` belongs to the fragment shader or fragment output state, which a pipeline
|
||||
@@ -2431,20 +2316,8 @@ fn record_and_submit(
|
||||
bytes,
|
||||
);
|
||||
}
|
||||
for &(binding, buffer, offset, stride) in recording.vertex_buffers {
|
||||
match (stride, &context.extended_dynamic_state) {
|
||||
// `create_pipeline` refused dynamic strides without the extension's commands.
|
||||
(Some(stride), Some(extended)) => (extended.bind_vertex_buffers2)(
|
||||
command,
|
||||
binding,
|
||||
1,
|
||||
&buffer,
|
||||
&offset,
|
||||
std::ptr::null(),
|
||||
&stride,
|
||||
),
|
||||
_ => device.cmd_bind_vertex_buffers(command, binding, &[buffer], &[offset]),
|
||||
}
|
||||
for &(binding, buffer, offset) in recording.vertex_buffers {
|
||||
device.cmd_bind_vertex_buffers(command, binding, &[buffer], &[offset]);
|
||||
}
|
||||
for state in recording
|
||||
.dynamic
|
||||
@@ -2455,9 +2328,8 @@ fn record_and_submit(
|
||||
continue;
|
||||
}
|
||||
match (DynamicRecord::of(state), state) {
|
||||
// Set per draw, below; the strides with the vertex buffers, above;
|
||||
// `create_pipeline` refused every state without a record.
|
||||
(None | Some(DynamicRecord::PerDraw | DynamicRecord::Strides), _) => {}
|
||||
// Set with the draw, below; `create_pipeline` refused every state without a record.
|
||||
(None | Some(DynamicRecord::PerDraw), _) => {}
|
||||
// `create_pipeline` refused these without the extension's commands.
|
||||
(Some(DynamicRecord::Extended), state) => {
|
||||
if let Some(extended) = &context.extended_dynamic_state {
|
||||
@@ -2499,69 +2371,65 @@ fn record_and_submit(
|
||||
dynamic(vk::DynamicState::VIEWPORT),
|
||||
dynamic(vk::DynamicState::SCISSOR),
|
||||
);
|
||||
// One draw per recording of it: the whole target, or each region of a rate-mapped pass.
|
||||
// A fetch ordered between draws alone records after the barrier of the subpass's
|
||||
// dependency on itself before each: the pass is `create_render_pass`'s of the pipeline's
|
||||
// graphics state, whose subpass then reads input attachments.
|
||||
let between_draws = graphics_pipeline::fetches_between_draws(recording.graphics);
|
||||
for (viewport, scissor) in recording.draws {
|
||||
if between_draws {
|
||||
graphics_pipeline::fetch_between_draws(device, command);
|
||||
}
|
||||
if set_viewport {
|
||||
device.cmd_set_viewport(command, 0, std::slice::from_ref(viewport));
|
||||
}
|
||||
if set_scissor {
|
||||
device.cmd_set_scissor(command, 0, std::slice::from_ref(scissor));
|
||||
}
|
||||
match (draw, recording.index_buffer) {
|
||||
(
|
||||
metal2vulkan::vk::DrawCommand::DrawIndexed {
|
||||
index_type,
|
||||
index_buffer_offset,
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
vertex_offset,
|
||||
first_instance,
|
||||
},
|
||||
Some(index_buffer),
|
||||
) => {
|
||||
device.cmd_bind_index_buffer(
|
||||
command,
|
||||
index_buffer,
|
||||
index_buffer_offset,
|
||||
vk::IndexType::from_raw(index_type.as_raw()),
|
||||
);
|
||||
device.cmd_draw_indexed(
|
||||
command,
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
vertex_offset,
|
||||
first_instance,
|
||||
);
|
||||
}
|
||||
(
|
||||
metal2vulkan::vk::DrawCommand::Draw {
|
||||
vertex_count,
|
||||
instance_count,
|
||||
first_vertex,
|
||||
first_instance,
|
||||
},
|
||||
_,
|
||||
) => device.cmd_draw(
|
||||
// dependency on itself before the draw: the pass is `create_render_pass`'s of the
|
||||
// pipeline's graphics state, whose subpass then reads input attachments.
|
||||
let (viewport, scissor) = &recording.area;
|
||||
if graphics_pipeline::fetches_between_draws(recording.graphics) {
|
||||
graphics_pipeline::fetch_between_draws(device, command);
|
||||
}
|
||||
if set_viewport {
|
||||
device.cmd_set_viewport(command, 0, std::slice::from_ref(viewport));
|
||||
}
|
||||
if set_scissor {
|
||||
device.cmd_set_scissor(command, 0, std::slice::from_ref(scissor));
|
||||
}
|
||||
match (draw, recording.index_buffer) {
|
||||
(
|
||||
metal2vulkan::vk::DrawCommand::DrawIndexed {
|
||||
index_type,
|
||||
index_buffer_offset,
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
vertex_offset,
|
||||
first_instance,
|
||||
},
|
||||
Some(index_buffer),
|
||||
) => {
|
||||
device.cmd_bind_index_buffer(
|
||||
command,
|
||||
index_buffer,
|
||||
index_buffer_offset,
|
||||
vk::IndexType::from_raw(index_type.as_raw()),
|
||||
);
|
||||
device.cmd_draw_indexed(
|
||||
command,
|
||||
index_count,
|
||||
instance_count,
|
||||
first_index,
|
||||
vertex_offset,
|
||||
first_instance,
|
||||
);
|
||||
}
|
||||
(
|
||||
metal2vulkan::vk::DrawCommand::Draw {
|
||||
vertex_count,
|
||||
instance_count,
|
||||
first_vertex,
|
||||
first_instance,
|
||||
),
|
||||
// A draw replay's draws, each of one draw at its arguments.
|
||||
(metal2vulkan::vk::DrawCommand::DrawIndirect { .. }, _) => {
|
||||
let Some(replayed) = recording.replayed else {
|
||||
continue;
|
||||
};
|
||||
},
|
||||
_,
|
||||
) => device.cmd_draw(
|
||||
command,
|
||||
vertex_count,
|
||||
instance_count,
|
||||
first_vertex,
|
||||
first_instance,
|
||||
),
|
||||
// A draw replay's draws, each of one draw at its arguments.
|
||||
(metal2vulkan::vk::DrawCommand::DrawIndirect { .. }, _) => {
|
||||
if let Some(replayed) = recording.replayed {
|
||||
for draw in replayed.draws {
|
||||
for (stages, offset, bytes) in &draw.push {
|
||||
device.cmd_push_constants(
|
||||
@@ -2581,9 +2449,9 @@ fn record_and_submit(
|
||||
);
|
||||
}
|
||||
}
|
||||
// Refused before recording began.
|
||||
_ => {}
|
||||
}
|
||||
// Refused before recording began.
|
||||
_ => {}
|
||||
}
|
||||
device.cmd_end_render_pass(command);
|
||||
if recording.replayed.is_some() {
|
||||
|
||||
@@ -1,65 +1,22 @@
|
||||
//! The render executor's draws (no device): the whole target, and a rate-mapped pass's regions,
|
||||
//! flipped as the module docs flip the viewport.
|
||||
//! The render executor's draw area (no device), and its targets' attachment forms.
|
||||
|
||||
use super::*;
|
||||
use metal2vulkan::bind::{RasterizationRateMap, RateMapAxis, RegionLimits};
|
||||
|
||||
/// A draw as plain values: the viewport's `[x, y, width, height, min_depth, max_depth]` and the
|
||||
/// scissor's offset and extent (`ash`'s types compare and print nothing).
|
||||
type Draw = ([f32; 6], [i32; 2], [u32; 2]);
|
||||
|
||||
fn plain(draws: Vec<(vk::Viewport, vk::Rect2D)>) -> Vec<Draw> {
|
||||
draws
|
||||
.into_iter()
|
||||
.map(|(v, s)| {
|
||||
(
|
||||
[v.x, v.y, v.width, v.height, v.min_depth, v.max_depth],
|
||||
[s.offset.x, s.offset.y],
|
||||
[s.extent.width, s.extent.height],
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn extent(width: u32, height: u32) -> vk::Extent2D {
|
||||
vk::Extent2D { width, height }
|
||||
}
|
||||
|
||||
/// The draw covers the whole target, its viewport flipped as the module docs flip it: compared as
|
||||
/// plain values (`ash`'s types compare and print nothing).
|
||||
#[test]
|
||||
fn a_pass_without_a_map_draws_once_over_the_whole_target() {
|
||||
fn a_draw_covers_the_whole_target() {
|
||||
let (v, s) = draw_area(vk::Extent2D {
|
||||
width: 37,
|
||||
height: 23,
|
||||
});
|
||||
assert_eq!(
|
||||
plain(draws(extent(37, 23), None)),
|
||||
[([0.0, 23.0, 37.0, -23.0, 0.0, 1.0], [0, 0], [37, 23])]
|
||||
);
|
||||
}
|
||||
|
||||
/// Each region is one recording of the draw: its viewport, Metal's convention flipped to a
|
||||
/// negative height from its bottom edge, and its scissor in physical pixels.
|
||||
#[test]
|
||||
fn a_rate_mapped_pass_draws_once_per_region() {
|
||||
let axis = |tiles: &[(u32, u32)]| RateMapAxis::from_tiles(32, tiles).unwrap();
|
||||
// Apple M3's compile of 37x23 at [0.5, 1] by [1, 0.5]: 33 screen pixels to 32, then 4 to 4, by
|
||||
// one tile of 23.
|
||||
let map = RasterizationRateMap::from_layers(
|
||||
[37, 23],
|
||||
vec![[axis(&[(33, 32), (4, 4)]), axis(&[(23, 23)])]],
|
||||
)
|
||||
.unwrap();
|
||||
let plan = map
|
||||
.regions(
|
||||
0,
|
||||
[0.0, 0.0, 37.0, 23.0],
|
||||
None,
|
||||
&RegionLimits::new([4096, 4096], [-8192.0, 8191.0]),
|
||||
)
|
||||
.unwrap();
|
||||
let width = (37.0f64 * 32.0 / 33.0) as f32;
|
||||
assert_eq!(
|
||||
plain(draws(extent(37, 23), Some(&plan))),
|
||||
[
|
||||
([0.0, 23.0, width, -23.0, 0.0, 1.0], [0, 0], [32, 23]),
|
||||
([-1.0, 23.0, 37.0, -23.0, 0.0, 1.0], [32, 0], [4, 23]),
|
||||
]
|
||||
(
|
||||
[v.x, v.y, v.width, v.height, v.min_depth, v.max_depth],
|
||||
[s.offset.x, s.offset.y],
|
||||
[s.extent.width, s.extent.height],
|
||||
),
|
||||
([0.0, 23.0, 37.0, -23.0, 0.0, 1.0], [0, 0], [37, 23])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -129,9 +86,5 @@ fn every_state_a_render_pipeline_makes_dynamic_is_recorded() {
|
||||
state.as_raw()
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
DynamicRecord::of(D::VERTEX_INPUT_BINDING_STRIDE),
|
||||
Some(DynamicRecord::Strides)
|
||||
);
|
||||
assert_eq!(DynamicRecord::of(D::LINE_WIDTH), None);
|
||||
}
|
||||
@@ -521,7 +521,6 @@ fn run(
|
||||
&embedded,
|
||||
&BTreeMap::new(),
|
||||
&BTreeMap::new(),
|
||||
&BTreeMap::new(),
|
||||
)
|
||||
.map_err(ExecutorError::Failed)?
|
||||
}
|
||||
@@ -529,7 +528,10 @@ fn run(
|
||||
// What the dispatch changed around each guarded target.
|
||||
let escaped: BTreeMap<OutOfBoundsResource, GuardCount> = (buffers.iter())
|
||||
.filter_map(|(&index, placed)| {
|
||||
Some((guards::buffer_target(case, index), placed.escaped()?))
|
||||
Some((
|
||||
OutOfBoundsResource::Buffer { binding: index },
|
||||
placed.escaped()?,
|
||||
))
|
||||
})
|
||||
.chain(members.iter().filter_map(|(&(owner, field), placed)| {
|
||||
let resource = OutOfBoundsResource::ArgumentBufferBuffer {
|
||||
|
||||
@@ -1,529 +0,0 @@
|
||||
//! A sparse case texture's image.
|
||||
//!
|
||||
//! The Metal oracle makes a sparse texture from a sparse heap and maps the case's regions and
|
||||
//! mip tails before the work (`metal::platform::textures`). Here the same texture is an image
|
||||
//! created with `VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT`, whose
|
||||
//! regions and tails are bound to device memory by one `vkQueueBindSparse` on the context's queue,
|
||||
//! in the case's order, and waited for before the upload is recorded. Both executors make the
|
||||
//! mappings through `executor_contract::sparse::device_mappings`, here under the image's
|
||||
//! `imageGranularity` and `imageMipTailFirstLod`, so a region that is not a whole number of the
|
||||
//! image's blocks, or that covers part of a level in its mip tail, is refused, typed
|
||||
//! (`not_supported{not_enabled}`), before anything is bound (a case's mip tail is its one level
|
||||
//! whole, bound as that level's blocks where the image keeps no tail); so is a device or queue
|
||||
//! without what
|
||||
//! a sparse resident image needs (`sparseBinding`, `sparseResidencyImage2D` or `3D` enabled, a
|
||||
//! queue with `VK_QUEUE_SPARSE_BINDING_BIT`, and the format's sparse properties). The upload
|
||||
//! copies only the mapped texels: on a device that is not `residencyNonResidentStrict` a write
|
||||
//! to an unbound block is undefined.
|
||||
//!
|
||||
//! A slot whose plan answers its residency from a tile map is what the runtime makes of it
|
||||
//! ([`create_tile_mapped_image`]): each block that holds a tile the case maps under Metal's tiles
|
||||
//! bound and uploaded whole, the unmapped tiles in it zero, where the context makes the sparse
|
||||
//! image; an ordinary image elsewhere (`plan_resources`).
|
||||
|
||||
use super::device::VulkanContext;
|
||||
use super::enables::ExecutorFeature;
|
||||
use super::plan_resources::image_support;
|
||||
use crate::check::admission::{ExecutorError, NotSupported};
|
||||
use crate::executor_contract::sparse::{
|
||||
device_mappings, level_extent, literal_offset, mapped_texels, DeviceMapping, SparseTiling,
|
||||
TexelRegion,
|
||||
};
|
||||
use crate::literal::LiteralTexture;
|
||||
use ash::vk;
|
||||
|
||||
/// A sparse image with its mapped regions bound, and the copies that upload their texels.
|
||||
pub(super) struct SparseImage {
|
||||
pub(super) image: vk::Image,
|
||||
/// The memory every mapped block and tail is bound to; null when nothing is mapped.
|
||||
pub(super) memory: vk::DeviceMemory,
|
||||
/// The copies of exactly the mapped texels from a staging buffer of the authored bytes.
|
||||
pub(super) copies: Vec<vk::BufferImageCopy>,
|
||||
}
|
||||
|
||||
fn not_enabled(what: String) -> ExecutorError {
|
||||
NotSupported::NotEnabled(vec![what]).into()
|
||||
}
|
||||
|
||||
/// What the context lacks to create a sparse resident image of `info` and bind it, if anything.
|
||||
fn missing_support(context: &VulkanContext, info: &vk::ImageCreateInfo<'_>) -> Vec<String> {
|
||||
let residency = match info.image_type {
|
||||
vk::ImageType::TYPE_3D => ExecutorFeature::SparseResidencyImage3D,
|
||||
_ => ExecutorFeature::SparseResidencyImage2D,
|
||||
};
|
||||
let mut missing: Vec<String> = [ExecutorFeature::SparseBinding, residency]
|
||||
.into_iter()
|
||||
.filter(|feature| !context.sparse_images.features.contains(feature))
|
||||
.map(|feature| format!("{} (a sparse case texture)", feature.name()))
|
||||
.collect();
|
||||
if !context.sparse_images.queue {
|
||||
missing.push("a queue with VK_QUEUE_SPARSE_BINDING_BIT (a sparse case texture)".into());
|
||||
}
|
||||
missing
|
||||
}
|
||||
|
||||
/// Create the sparse image of `texture` from `info` (with the sparse flags added), bind its
|
||||
/// mapped regions and tails on the context's queue, wait for the binding, and return the copies
|
||||
/// that upload its mapped texels.
|
||||
pub(super) fn create_sparse_image(
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
texture: &LiteralTexture,
|
||||
info: vk::ImageCreateInfo<'_>,
|
||||
) -> Result<SparseImage, ExecutorError> {
|
||||
let info = sparse_info(info);
|
||||
check_support(context, label, &info)?;
|
||||
// SAFETY: `info` is live for the call and the device supports it.
|
||||
let image = unsafe { context.device.create_image(&info, None) }
|
||||
.map_err(|error| format!("create sparse {label}: {error}"))?;
|
||||
match bind(context, label, texture, &info, image) {
|
||||
Ok((memory, copies)) => Ok(SparseImage {
|
||||
image,
|
||||
memory,
|
||||
copies,
|
||||
}),
|
||||
Err(error) => {
|
||||
// SAFETY: the image was created above; `bind` waited for or never made a binding,
|
||||
// and freed whatever memory it allocated.
|
||||
unsafe { context.device.destroy_image(image, None) };
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `info` with the sparse flags added.
|
||||
fn sparse_info(info: vk::ImageCreateInfo<'_>) -> vk::ImageCreateInfo<'_> {
|
||||
info.flags(
|
||||
info.flags | vk::ImageCreateFlags::SPARSE_BINDING | vk::ImageCreateFlags::SPARSE_RESIDENCY,
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether the context creates a sparse resident image of `info` (with the sparse flags) and
|
||||
/// binds it: its features and queue, the image's format properties, and the format's sparse
|
||||
/// properties of a color aspect; why not, typed, where it does not.
|
||||
fn check_support(
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
info: &vk::ImageCreateInfo<'_>,
|
||||
) -> Result<(), ExecutorError> {
|
||||
let missing = missing_support(context, info);
|
||||
if !missing.is_empty() {
|
||||
return Err(NotSupported::NotEnabled(missing).into());
|
||||
}
|
||||
image_support(context, label, info)?;
|
||||
// SAFETY: the physical device belongs to the live instance.
|
||||
let formats = unsafe {
|
||||
context
|
||||
.instance
|
||||
.get_physical_device_sparse_image_format_properties(
|
||||
context.physical,
|
||||
info.format,
|
||||
info.image_type,
|
||||
info.samples,
|
||||
info.usage,
|
||||
info.tiling,
|
||||
)
|
||||
};
|
||||
if !formats
|
||||
.iter()
|
||||
.any(|format| format.aspect_mask.contains(vk::ImageAspectFlags::COLOR))
|
||||
{
|
||||
return Err(not_enabled(format!(
|
||||
"{label}: sparse residency for VkFormat {} with usage {:#x} \
|
||||
(vkGetPhysicalDeviceSparseImageFormatProperties lists none)",
|
||||
info.format.as_raw(),
|
||||
info.usage.as_raw()
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create the sparse image of `texture` from `info` (with the sparse flags added), a slot whose
|
||||
/// plan answers its residency from a tile map, as the runtime makes it where the device makes a
|
||||
/// sparse resident image: each of the image's blocks that holds a texel of `regions` (the case's
|
||||
/// mappings under Metal's tiles, `tile_map_tiling`) bound, and uploaded whole from a staging buffer
|
||||
/// of the authored bytes with every texel outside `regions` zero
|
||||
/// ([`mapped_bytes`](crate::executor_contract::sparse::mapped_bytes)): a mapped tile reads its
|
||||
/// texels, an unmapped tile in a bound block zero, Metal's answer, and a block that holds no mapped
|
||||
/// tile the device's value, as the runtime's. `Ok(None)` where the context makes no such image (the
|
||||
/// caller emulates the texture by an ordinary image, as the runtime does on such a device).
|
||||
pub(super) fn create_tile_mapped_image(
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
texture: &LiteralTexture,
|
||||
info: vk::ImageCreateInfo<'_>,
|
||||
regions: &[TexelRegion],
|
||||
) -> Result<Option<SparseImage>, ExecutorError> {
|
||||
let info = sparse_info(info);
|
||||
if check_support(context, label, &info).is_err() {
|
||||
return Ok(None);
|
||||
}
|
||||
// SAFETY: `info` is live for the call and the device supports it.
|
||||
let image = unsafe { context.device.create_image(&info, None) }
|
||||
.map_err(|error| format!("create sparse {label}: {error}"))?;
|
||||
match bind_tile_mapped(context, label, texture, &info, image, regions) {
|
||||
Ok((memory, copies)) => Ok(Some(SparseImage {
|
||||
image,
|
||||
memory,
|
||||
copies,
|
||||
})),
|
||||
Err(error) => {
|
||||
// SAFETY: the image was created above; the binding was waited for or never made,
|
||||
// and whatever memory it allocated freed.
|
||||
unsafe { context.device.destroy_image(image, None) };
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One of a sparse image's units the tile-mapped path binds: a block of level 0 of a slice, or a
|
||||
/// layer's mip tail.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
enum Unit {
|
||||
Block { slice: u32, at: [u32; 3] },
|
||||
Tail { layer: u32 },
|
||||
}
|
||||
|
||||
/// Bind each unit of `image` that holds a texel of `regions`, and return the memory and the
|
||||
/// copies that upload each bound unit whole.
|
||||
fn bind_tile_mapped(
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
texture: &LiteralTexture,
|
||||
info: &vk::ImageCreateInfo<'_>,
|
||||
image: vk::Image,
|
||||
regions: &[TexelRegion],
|
||||
) -> Result<(vk::DeviceMemory, Vec<vk::BufferImageCopy>), ExecutorError> {
|
||||
let color = color_requirements(context, label, image)?;
|
||||
let granularity = color.format_properties.image_granularity;
|
||||
let granularity = [granularity.width, granularity.height, granularity.depth].map(|g| g.max(1));
|
||||
let single_tail = color
|
||||
.format_properties
|
||||
.flags
|
||||
.contains(vk::SparseImageFormatFlags::SINGLE_MIPTAIL);
|
||||
let tail_lod = if color.image_mip_tail_size != 0 {
|
||||
color.image_mip_tail_first_lod
|
||||
} else {
|
||||
info.mip_levels
|
||||
};
|
||||
let (extent, _) = crate::case::sparse::sparse_extent(texture.texture_type, texture.dimensions)
|
||||
.ok_or_else(|| format!("{label} is not a sparse texture type"))?;
|
||||
let mut units = std::collections::BTreeSet::new();
|
||||
for region in regions {
|
||||
if region.level >= tail_lod {
|
||||
let layer = if single_tail { 0 } else { region.slice };
|
||||
units.insert(Unit::Tail { layer });
|
||||
continue;
|
||||
}
|
||||
let end = [0, 1, 2].map(|axis| region.origin[axis] + region.size[axis]);
|
||||
let first = [0, 1, 2].map(|axis| region.origin[axis] / granularity[axis]);
|
||||
let last = [0, 1, 2].map(|axis| end[axis].div_ceil(granularity[axis]));
|
||||
for z in first[2]..last[2] {
|
||||
for y in first[1]..last[1] {
|
||||
for x in first[0]..last[0] {
|
||||
let at = [x, y, z];
|
||||
units.insert(Unit::Block {
|
||||
slice: region.slice,
|
||||
at,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let level = level_extent(extent, 0);
|
||||
let mut mappings = Vec::new();
|
||||
let mut uploaded = Vec::new();
|
||||
for unit in units {
|
||||
match unit {
|
||||
Unit::Block { slice, at } => {
|
||||
let origin = [0, 1, 2].map(|axis| at[axis] * granularity[axis]);
|
||||
let size = [0, 1, 2].map(|axis| granularity[axis].min(level[axis] - origin[axis]));
|
||||
let texels = TexelRegion {
|
||||
level: 0,
|
||||
slice,
|
||||
origin,
|
||||
size,
|
||||
};
|
||||
mappings.push(DeviceMapping::Tiles {
|
||||
texels,
|
||||
tile_origin: at,
|
||||
tile_count: [1, 1, 1],
|
||||
});
|
||||
uploaded.push(texels);
|
||||
}
|
||||
Unit::Tail { layer } => {
|
||||
mappings.push(DeviceMapping::MipTail { slice: layer });
|
||||
let slices = if single_tail {
|
||||
0..info.array_layers
|
||||
} else {
|
||||
layer..layer + 1
|
||||
};
|
||||
uploaded.extend(slices.map(|slice| TexelRegion {
|
||||
level: 0,
|
||||
slice,
|
||||
origin: [0; 3],
|
||||
size: level,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
// The upload's copies first: nothing can fail once memory is bound.
|
||||
let copies = upload_copies(texture, extent, &uploaded).map_err(|e| format!("{label}: {e}"))?;
|
||||
let memory = bind_mappings(context, label, image, color, single_tail, &mappings)?;
|
||||
Ok((memory, copies))
|
||||
}
|
||||
|
||||
/// The color aspect's sparse memory requirements of `image`.
|
||||
fn color_requirements(
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
image: vk::Image,
|
||||
) -> Result<vk::SparseImageMemoryRequirements, ExecutorError> {
|
||||
// SAFETY: the image was just created on this device.
|
||||
let sparse = unsafe { context.device.get_image_sparse_memory_requirements(image) };
|
||||
let color = sparse
|
||||
.into_iter()
|
||||
.find(|requirements| {
|
||||
requirements
|
||||
.format_properties
|
||||
.aspect_mask
|
||||
.contains(vk::ImageAspectFlags::COLOR)
|
||||
})
|
||||
.ok_or_else(|| format!("{label}: the sparse image has no color aspect's requirements"))?;
|
||||
Ok(color)
|
||||
}
|
||||
|
||||
/// The copies that upload `regions` (each of level 0) of `texture`, whose level 0 is `extent`,
|
||||
/// from a staging buffer of its literal's layout.
|
||||
fn upload_copies(
|
||||
texture: &LiteralTexture,
|
||||
extent: [u32; 3],
|
||||
regions: &[TexelRegion],
|
||||
) -> Result<Vec<vk::BufferImageCopy>, String> {
|
||||
regions
|
||||
.iter()
|
||||
.map(|region| {
|
||||
let level = level_extent(extent, region.level);
|
||||
Ok(vk::BufferImageCopy::default()
|
||||
.buffer_offset(literal_offset(texture, region)?)
|
||||
.buffer_row_length(level[0])
|
||||
.buffer_image_height(level[1])
|
||||
.image_subresource(vk::ImageSubresourceLayers {
|
||||
aspect_mask: vk::ImageAspectFlags::COLOR,
|
||||
mip_level: region.level,
|
||||
base_array_layer: region.slice,
|
||||
layer_count: 1,
|
||||
})
|
||||
.image_offset(vk::Offset3D {
|
||||
x: region.origin[0] as i32,
|
||||
y: region.origin[1] as i32,
|
||||
z: region.origin[2] as i32,
|
||||
})
|
||||
.image_extent(vk::Extent3D {
|
||||
width: region.size[0],
|
||||
height: region.size[1],
|
||||
depth: region.size[2],
|
||||
}))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Bind `texture`'s mappings of `image` and return the memory and the upload's copies.
|
||||
fn bind(
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
texture: &LiteralTexture,
|
||||
info: &vk::ImageCreateInfo<'_>,
|
||||
image: vk::Image,
|
||||
) -> Result<(vk::DeviceMemory, Vec<vk::BufferImageCopy>), ExecutorError> {
|
||||
let color = color_requirements(context, label, image)?;
|
||||
let granularity = color.format_properties.image_granularity;
|
||||
let flags = color.format_properties.flags;
|
||||
let has_tail =
|
||||
color.image_mip_tail_size != 0 && color.image_mip_tail_first_lod < info.mip_levels;
|
||||
let tiling = SparseTiling {
|
||||
tile: [granularity.width, granularity.height, granularity.depth],
|
||||
first_level_in_tail: if has_tail {
|
||||
color.image_mip_tail_first_lod
|
||||
} else {
|
||||
info.mip_levels
|
||||
},
|
||||
};
|
||||
eprintln!(
|
||||
"vulkan-sparse-image {label} format={} granularity={:?} flags={:#x} \
|
||||
mip_tail_first_lod={} mip_tail_size={} mip_tail_offset={} mip_tail_stride={}",
|
||||
info.format.as_raw(),
|
||||
tiling.tile,
|
||||
flags.as_raw(),
|
||||
color.image_mip_tail_first_lod,
|
||||
color.image_mip_tail_size,
|
||||
color.image_mip_tail_offset,
|
||||
color.image_mip_tail_stride
|
||||
);
|
||||
let mappings = device_mappings(texture, tiling)
|
||||
.map_err(|error| not_enabled(format!("{label}: {error}")))?
|
||||
.ok_or_else(|| format!("{label} is not a sparse texture"))?;
|
||||
let single_tail = flags.contains(vk::SparseImageFormatFlags::SINGLE_MIPTAIL);
|
||||
if single_tail && info.array_layers > 1 {
|
||||
let tails = mappings
|
||||
.iter()
|
||||
.filter(|mapping| matches!(mapping, DeviceMapping::MipTail { .. }))
|
||||
.count();
|
||||
if tails != 0 && tails != info.array_layers as usize {
|
||||
return Err(not_enabled(format!(
|
||||
"{label}: the device keeps one mip tail for all {} layers \
|
||||
(VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT), and the case maps {tails} of them",
|
||||
info.array_layers
|
||||
)));
|
||||
}
|
||||
}
|
||||
// The upload's copies first: nothing can fail once memory is bound.
|
||||
let regions =
|
||||
mapped_texels(texture, tiling, &mappings).map_err(|error| format!("{label}: {error}"))?;
|
||||
let (extent, _) = crate::case::sparse::sparse_extent(texture.texture_type, texture.dimensions)
|
||||
.ok_or_else(|| format!("{label} is not a sparse texture type"))?;
|
||||
let copies =
|
||||
upload_copies(texture, extent, ®ions).map_err(|error| format!("{label}: {error}"))?;
|
||||
let memory = bind_mappings(context, label, image, color, single_tail, &mappings)?;
|
||||
Ok((memory, copies))
|
||||
}
|
||||
|
||||
/// Bind `mappings` of `image` (whose color aspect's sparse requirements are `color`, one tail
|
||||
/// for all layers where `single_tail`) to memory allocated for them, in order, on the context's
|
||||
/// queue, and wait for the binding; the memory, null when nothing is mapped.
|
||||
fn bind_mappings(
|
||||
context: &VulkanContext,
|
||||
label: &str,
|
||||
image: vk::Image,
|
||||
color: vk::SparseImageMemoryRequirements,
|
||||
single_tail: bool,
|
||||
mappings: &[DeviceMapping],
|
||||
) -> Result<vk::DeviceMemory, ExecutorError> {
|
||||
// SAFETY: the image was just created on this device.
|
||||
let requirements = unsafe { context.device.get_image_memory_requirements(image) };
|
||||
let block = requirements.alignment.max(1);
|
||||
// Where each mapping's memory starts, in the case's order; a single tail binds once.
|
||||
let mut offsets = Vec::with_capacity(mappings.len());
|
||||
let mut size: vk::DeviceSize = 0;
|
||||
let mut single_tail_bound = false;
|
||||
for mapping in mappings {
|
||||
offsets.push(size);
|
||||
size += match *mapping {
|
||||
DeviceMapping::Tiles { tile_count, .. } => {
|
||||
tile_count
|
||||
.iter()
|
||||
.map(|&count| u64::from(count))
|
||||
.product::<u64>()
|
||||
* block
|
||||
}
|
||||
DeviceMapping::MipTail { .. } if single_tail && single_tail_bound => 0,
|
||||
DeviceMapping::MipTail { .. } => {
|
||||
single_tail_bound = true;
|
||||
color.image_mip_tail_size.next_multiple_of(block)
|
||||
}
|
||||
};
|
||||
}
|
||||
let memory = if size == 0 {
|
||||
vk::DeviceMemory::null()
|
||||
} else {
|
||||
let memory_type = context.memory_type(
|
||||
requirements.memory_type_bits,
|
||||
vk::MemoryPropertyFlags::DEVICE_LOCAL,
|
||||
)?;
|
||||
let allocation = vk::MemoryAllocateInfo::default()
|
||||
.allocation_size(size)
|
||||
.memory_type_index(memory_type);
|
||||
// SAFETY: `allocation` is live for the call.
|
||||
unsafe { context.device.allocate_memory(&allocation, None) }
|
||||
.map_err(|error| format!("allocate the memory of sparse {label}: {error}"))?
|
||||
};
|
||||
let free = || {
|
||||
// SAFETY: the memory was allocated above and nothing waits on it.
|
||||
unsafe { context.device.free_memory(memory, None) };
|
||||
};
|
||||
let mut blocks = Vec::new();
|
||||
let mut tails = Vec::new();
|
||||
let mut single_tail_bound = false;
|
||||
for (mapping, &offset) in mappings.iter().zip(&offsets) {
|
||||
match *mapping {
|
||||
DeviceMapping::Tiles { texels, .. } => blocks.push(
|
||||
vk::SparseImageMemoryBind::default()
|
||||
.subresource(vk::ImageSubresource {
|
||||
aspect_mask: vk::ImageAspectFlags::COLOR,
|
||||
mip_level: texels.level,
|
||||
array_layer: texels.slice,
|
||||
})
|
||||
.offset(vk::Offset3D {
|
||||
x: texels.origin[0] as i32,
|
||||
y: texels.origin[1] as i32,
|
||||
z: texels.origin[2] as i32,
|
||||
})
|
||||
.extent(vk::Extent3D {
|
||||
width: texels.size[0],
|
||||
height: texels.size[1],
|
||||
depth: texels.size[2],
|
||||
})
|
||||
.memory(memory)
|
||||
.memory_offset(offset),
|
||||
),
|
||||
DeviceMapping::MipTail { .. } if single_tail && single_tail_bound => {}
|
||||
DeviceMapping::MipTail { slice } => {
|
||||
single_tail_bound = true;
|
||||
let layer = if single_tail { 0 } else { u64::from(slice) };
|
||||
tails.push(
|
||||
vk::SparseMemoryBind::default()
|
||||
.resource_offset(
|
||||
color.image_mip_tail_offset + layer * color.image_mip_tail_stride,
|
||||
)
|
||||
.size(color.image_mip_tail_size)
|
||||
.memory(memory)
|
||||
.memory_offset(offset),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !blocks.is_empty() || !tails.is_empty() {
|
||||
let image_binds = [vk::SparseImageMemoryBindInfo::default()
|
||||
.image(image)
|
||||
.binds(&blocks)];
|
||||
let opaque_binds = [vk::SparseImageOpaqueMemoryBindInfo::default()
|
||||
.image(image)
|
||||
.binds(&tails)];
|
||||
let mut bind_info = vk::BindSparseInfo::default();
|
||||
if !blocks.is_empty() {
|
||||
bind_info = bind_info.image_binds(&image_binds);
|
||||
}
|
||||
if !tails.is_empty() {
|
||||
bind_info = bind_info.image_opaque_binds(&opaque_binds);
|
||||
}
|
||||
// SAFETY: a fence create info has no pointers.
|
||||
let fence = match unsafe {
|
||||
context
|
||||
.device
|
||||
.create_fence(&vk::FenceCreateInfo::default(), None)
|
||||
} {
|
||||
Ok(fence) => fence,
|
||||
Err(error) => {
|
||||
free();
|
||||
return Err(format!("create the binding fence of sparse {label}: {error}").into());
|
||||
}
|
||||
};
|
||||
// SAFETY: every handle is live; the binds lie in the image (`device_mappings`) and the
|
||||
// memory (`offsets`); the fence is waited for before anything uses the image.
|
||||
let bound = unsafe {
|
||||
context
|
||||
.device
|
||||
.queue_bind_sparse(context.queue, &[bind_info], fence)
|
||||
}
|
||||
.map_err(|error| format!("bind the memory of sparse {label}: {error}"))
|
||||
.and_then(|()| context.wait_for_fence(fence, &format!("Vulkan sparse binding of {label}")));
|
||||
// SAFETY: the binding was waited for (a wait returns only once nothing is in flight) or
|
||||
// never submitted (a failed `vkQueueBindSparse` leaves every object unaffected).
|
||||
unsafe { context.device.destroy_fence(fence, None) };
|
||||
if let Err(error) = bound {
|
||||
free();
|
||||
return Err(error.into());
|
||||
}
|
||||
}
|
||||
Ok(memory)
|
||||
}
|
||||
@@ -26,20 +26,11 @@ pub(crate) fn case(entry: &str, buffer: Vec<u8>, dispatch: Dispatch) -> ComputeC
|
||||
argument_buffer_buffers: BTreeMap::new(),
|
||||
argument_buffer_textures: BTreeMap::new(),
|
||||
argument_buffer_samplers: BTreeMap::new(),
|
||||
rate_maps: BTreeMap::new(),
|
||||
argument_buffer_rate_maps: BTreeMap::new(),
|
||||
objects: std::collections::BTreeMap::new(),
|
||||
command_buffers: std::collections::BTreeMap::new(),
|
||||
textures: BTreeMap::new(),
|
||||
samplers: BTreeMap::new(),
|
||||
function_tables: BTreeMap::new(),
|
||||
acceleration_structures: BTreeMap::new(),
|
||||
threadgroup_lengths: BTreeMap::new(),
|
||||
imageblock: None,
|
||||
tile: None,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
attribute_strides: BTreeMap::new(),
|
||||
dispatch,
|
||||
output: ComputeOutput::Buffer {
|
||||
binding: 0,
|
||||
@@ -228,75 +219,6 @@ fn a_kernel_runs_with_the_public_linked_modules() {
|
||||
assert_eq!(words, expected);
|
||||
}
|
||||
|
||||
/// A kernel calls through its visible-function table: the table's buffer holds the product's words
|
||||
/// with the handles the compile gave the linked functions, so entry `tid % 4` of `[table_add,
|
||||
/// table_mul, null, table_sub]` computes what the MSL states with `(tid, 3)` (a null entry writes
|
||||
/// `0xfffffffd`), and a table the case does not bind reads the zero neutral as a null table
|
||||
/// (`0xffffffff`).
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[test]
|
||||
fn a_kernel_calls_through_its_visible_function_table() {
|
||||
use crate::candidate::engine::tables::{FunctionTable, TableFunction};
|
||||
let caller = llvm_assemble(&engine_dir().join("visible_table_caller.ll")).unwrap();
|
||||
let functions = llvm_assemble(&engine_dir().join("visible_table_functions.ll")).unwrap();
|
||||
let linked = [LinkedModule {
|
||||
module_sha256: "functions".into(),
|
||||
bitcode: functions,
|
||||
library: LinkedLibrary {
|
||||
functions: ["table_add", "table_mul", "table_sub"]
|
||||
.map(str::to_owned)
|
||||
.to_vec(),
|
||||
},
|
||||
}];
|
||||
const THREADS: u32 = 12;
|
||||
let mut kernel = case(
|
||||
"visible_table_dispatch",
|
||||
vec![0; 4 * THREADS as usize],
|
||||
Dispatch::Threads {
|
||||
threads: [THREADS, 1, 1],
|
||||
threads_per_group: [THREADS, 1, 1],
|
||||
},
|
||||
);
|
||||
let entry = |function: &str| TableFunction {
|
||||
module_sha256: "functions".into(),
|
||||
function: function.into(),
|
||||
};
|
||||
kernel.function_tables = BTreeMap::from([(
|
||||
1,
|
||||
FunctionTable {
|
||||
size: 4,
|
||||
entries: BTreeMap::from([
|
||||
(0, entry("table_add")),
|
||||
(1, entry("table_mul")),
|
||||
(3, entry("table_sub")),
|
||||
]),
|
||||
},
|
||||
)]);
|
||||
let expected = (0..THREADS)
|
||||
.flat_map(|tid| {
|
||||
match tid % 4 {
|
||||
0 => tid + 3,
|
||||
1 => tid * 3,
|
||||
2 => 0xffff_fffd,
|
||||
_ => tid.wrapping_sub(3),
|
||||
}
|
||||
.to_le_bytes()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
run_linked(&kernel, &caller, &linked).unwrap().output,
|
||||
expected
|
||||
);
|
||||
kernel.function_tables.clear();
|
||||
let unbound = (0..THREADS)
|
||||
.flat_map(|_| 0xffff_ffffu32.to_le_bytes())
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
run_linked(&kernel, &caller, &linked).unwrap().output,
|
||||
unbound
|
||||
);
|
||||
}
|
||||
|
||||
/// A loop runs to completion as compiled, with no execution bound, on both lanes.
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[test]
|
||||
@@ -520,42 +442,6 @@ fn a_device_buffer_accessed_past_its_end_is_contained_through_the_runtime() {
|
||||
}
|
||||
}
|
||||
|
||||
/// An instance structure is built as the Metal oracle builds it, each instance with mask
|
||||
/// `0xFFFFFFFF`, which Vulkan's 8-bit instance mask cannot hold: the binder's refusal is the
|
||||
/// run's typed refusal, never a run. CPU lane only: lavapipe traces rays, and MoltenVK has no ray
|
||||
/// queries.
|
||||
#[cfg(all(m2v_cpu_icd, any(target_os = "linux", target_os = "macos")))]
|
||||
#[test]
|
||||
fn an_oracle_instance_mask_is_refused_typed() {
|
||||
use crate::candidate::engine::CaseStructure;
|
||||
let fixture = metal2vulkan_devtools::fixtures_dir().join("kernel_instance_as_intersect.ll");
|
||||
let bitcode = llvm_assemble(&fixture).unwrap();
|
||||
let mut trace = case("instance_as_intersect", vec![0; 36], one_thread());
|
||||
trace
|
||||
.acceleration_structures
|
||||
.insert(5, CaseStructure::Instances { instances: 1 });
|
||||
// An intersection function table of one null entry: bound, size 1.
|
||||
trace.buffers.insert(
|
||||
6,
|
||||
[1u32, 1, 0]
|
||||
.into_iter()
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.collect(),
|
||||
);
|
||||
use crate::check::admission::NotSupported;
|
||||
use crate::engine::{Outcome, UnsupportedReason};
|
||||
match run(&trace, &bitcode) {
|
||||
Err(ExecutorError::NotSupported(NotSupported::Product { outcome, .. })) => assert_eq!(
|
||||
outcome,
|
||||
Outcome::Unsupported {
|
||||
reason: UnsupportedReason::NotRepresentable,
|
||||
feature: "RayTracing".into(),
|
||||
}
|
||||
),
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// [`run`] through the runtime ([`run_on_runtime`] with no linked module).
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) fn run_through_runtime(
|
||||
|
||||
@@ -22,7 +22,7 @@ use metal2vulkan_devtools::{fixtures_dir, llvm_assemble};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// Draw `case`, compiled in the device tests' compile worker ([`compile_worker`]) by the request
|
||||
/// the tools send it. Owned draws link nothing, so they bind no visible-function tables.
|
||||
/// the tools send it.
|
||||
fn run(case: &RenderCase, libraries: RenderLibraries<'_>) -> Result<ComputeRun, ExecutorError> {
|
||||
platform::execute_engine_render(
|
||||
crate::gpu::TEST_DEVICE,
|
||||
@@ -34,7 +34,7 @@ fn run(case: &RenderCase, libraries: RenderLibraries<'_>) -> Result<ComputeRun,
|
||||
.into_iter()
|
||||
.map(crate::acceptance::retained)
|
||||
.collect::<Vec<_>>();
|
||||
compile_render(compile_worker(), device, &request, &sources, case, &[])
|
||||
compile_render(compile_worker(), device, &request, &sources)
|
||||
},
|
||||
|_, token, _, _| Err(format!("no template has pipeline token {token}").into()),
|
||||
)
|
||||
@@ -95,7 +95,6 @@ fn triangle_inputs(positions: &[[f32; 2]], uv: [f32; 2]) -> Vec<VertexBuffer> {
|
||||
buffer_index: 30,
|
||||
format: AttributeFormat::Float2,
|
||||
stride: 8,
|
||||
dynamic: false,
|
||||
step: metal2vulkan::metal::VertexStepFunction::PerVertex,
|
||||
bytes: floats(&positions.concat()),
|
||||
},
|
||||
@@ -104,7 +103,6 @@ fn triangle_inputs(positions: &[[f32; 2]], uv: [f32; 2]) -> Vec<VertexBuffer> {
|
||||
buffer_index: 29,
|
||||
format: AttributeFormat::Float2,
|
||||
stride: 8,
|
||||
dynamic: false,
|
||||
step: metal2vulkan::metal::VertexStepFunction::PerVertex,
|
||||
bytes: floats(&uv.repeat(count)),
|
||||
},
|
||||
@@ -261,7 +259,7 @@ fn a_vertex_varying_reaches_the_fragment_stage() {
|
||||
/// libraries its two stages come from: the companion's opaque spelling assembled, in stage order.
|
||||
fn with_companion(case: &AuthoredCase, bitcode: &[u8]) -> (RenderCase, Vec<u8>) {
|
||||
let (interface, companion) = checked_companion(case, bitcode);
|
||||
let render = render_case(case, &interface, WITHOUT_SLICE, companion.as_ref(), None).unwrap();
|
||||
let render = render_case(case, &interface, WITHOUT_SLICE, companion.as_ref()).unwrap();
|
||||
let companion = companion.expect("a graphics case with a companion");
|
||||
(render, companion.opaque_bitcode().unwrap())
|
||||
}
|
||||
@@ -317,9 +315,7 @@ fn a_fragment_case_draws_through_its_generated_passthrough_vertex() {
|
||||
);
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(
|
||||
&authored, &case
|
||||
));
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(&case));
|
||||
let through = run_on_runtime(&case, &fragment, Some(&companion)).unwrap();
|
||||
assert_eq!(through.output, floats(&expected));
|
||||
assert_eq!(through.status, None);
|
||||
@@ -362,13 +358,7 @@ fn a_fragment_case_writes_its_depth_and_stencil_attachment() {
|
||||
authored.depth_stencil = depth_stencil(true, true);
|
||||
authored.output = stencil.clone();
|
||||
let (interface, companion) = checked_companion(&authored, &fragment);
|
||||
match render_case(
|
||||
&authored,
|
||||
&interface,
|
||||
WITHOUT_SLICE,
|
||||
companion.as_ref(),
|
||||
None,
|
||||
) {
|
||||
match render_case(&authored, &interface, WITHOUT_SLICE, companion.as_ref()) {
|
||||
Err(ExecutorError::NotSupported(crate::check::admission::NotSupported::Requirements(
|
||||
requirements,
|
||||
))) => assert_eq!(
|
||||
@@ -401,9 +391,7 @@ fn a_fragment_case_writes_its_depth_and_stencil_attachment() {
|
||||
authored.depth_stencil = depth_stencil(aspect, !aspect);
|
||||
authored.output = output;
|
||||
let (case, companion) = with_companion(&authored, &own);
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(
|
||||
&authored, &case
|
||||
));
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(&case));
|
||||
let drawn = run(
|
||||
&case,
|
||||
RenderLibraries {
|
||||
@@ -420,9 +408,7 @@ fn a_fragment_case_writes_its_depth_and_stencil_attachment() {
|
||||
}
|
||||
authored.depth_stencil = depth_stencil(false, true);
|
||||
let (case, companion) = with_companion(&authored, &fragment);
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(
|
||||
&authored, &case
|
||||
));
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(&case));
|
||||
match run_on_runtime(&case, &fragment, Some(&companion)) {
|
||||
Ok(through) => {
|
||||
let drawn = run(
|
||||
@@ -506,9 +492,7 @@ fn an_observed_vertex_case_draws_into_its_generated_observer() {
|
||||
assert_eq!(run.output, expected, "{observation:?}");
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(
|
||||
&authored, &case
|
||||
));
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(&case));
|
||||
let through = run_on_runtime(&case, &vertex, Some(&companion)).unwrap();
|
||||
assert_eq!(
|
||||
through.output, expected,
|
||||
@@ -546,9 +530,7 @@ fn each_sample_of_a_multisampled_target_keeps_its_own_contents() {
|
||||
let expected = floats(&[written, sample(1.0), written, sample(3.0)].concat());
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(
|
||||
&authored, &case
|
||||
));
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(&case));
|
||||
let through = run_on_runtime(&case, &fragment, Some(&companion)).unwrap();
|
||||
assert_eq!(through.output, expected, "through the runtime");
|
||||
}
|
||||
@@ -621,9 +603,7 @@ fn a_fragment_pass_of_no_attachment_runs_each_sample_once() {
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(
|
||||
&authored, &case
|
||||
));
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(&case));
|
||||
let through = run_on_runtime(&case, &fragment, Some(&companion)).unwrap();
|
||||
assert_eq!(
|
||||
through.output, drawn.output,
|
||||
@@ -707,9 +687,7 @@ fn a_back_culled_patch_and_its_mirror_leave_exactly_one_drawn() {
|
||||
.output;
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(
|
||||
authored, &case
|
||||
));
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(&case));
|
||||
let through = run_on_runtime(&case, &vertex, Some(&companion)).unwrap();
|
||||
assert_eq!(through.output, output, "through the runtime");
|
||||
}
|
||||
@@ -819,7 +797,6 @@ fn a_rasterization_disabled_vertex_draw_stores_through_its_buffer() {
|
||||
&crate::check::interface::tests::vertex_buffers_at(&[0]),
|
||||
WITHOUT_SLICE,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let vertex = public("vertex_narrow_attributes.ll");
|
||||
@@ -834,9 +811,7 @@ fn a_rasterization_disabled_vertex_draw_stores_through_its_buffer() {
|
||||
assert_eq!(run.output, (2u32 + 3 + 4).to_le_bytes());
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(
|
||||
&authored, &case
|
||||
));
|
||||
assert!(crate::candidate::engine::runs_render_through_runtime(&case));
|
||||
let through = run_on_runtime(&case, &vertex, None).unwrap();
|
||||
assert_eq!(through.output, (2u32 + 3 + 4).to_le_bytes());
|
||||
}
|
||||
|
||||
@@ -71,8 +71,6 @@ fn kernel(
|
||||
argument_buffer_buffers: BTreeMap::new(),
|
||||
argument_buffer_textures: BTreeMap::new(),
|
||||
argument_buffer_samplers: BTreeMap::new(),
|
||||
rate_maps: BTreeMap::new(),
|
||||
argument_buffer_rate_maps: BTreeMap::new(),
|
||||
objects: std::collections::BTreeMap::new(),
|
||||
command_buffers: std::collections::BTreeMap::new(),
|
||||
textures: textures
|
||||
@@ -80,14 +78,7 @@ fn kernel(
|
||||
.map(|texture| (texture.binding, texture))
|
||||
.collect(),
|
||||
samplers: BTreeMap::new(),
|
||||
function_tables: BTreeMap::new(),
|
||||
acceleration_structures: BTreeMap::new(),
|
||||
threadgroup_lengths: BTreeMap::new(),
|
||||
imageblock: None,
|
||||
tile: None,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
attribute_strides: Default::default(),
|
||||
dispatch: Dispatch::Threads {
|
||||
threads,
|
||||
threads_per_group: [1, 1, 1],
|
||||
@@ -166,104 +157,6 @@ fn a_texture_array_element_is_the_texture_at_its_slot() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A uniform texel buffer read and a storage texel buffer written and observed.
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[test]
|
||||
fn texel_buffers_read_one_view_and_write_the_other() {
|
||||
let source = [1.0f32, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0];
|
||||
let case = kernel(
|
||||
"texel_buffers",
|
||||
vec![
|
||||
texture(
|
||||
0,
|
||||
TextureType::Buffer,
|
||||
TextureFormat::Rgba32Float,
|
||||
[2, 1, 1],
|
||||
floats(&source),
|
||||
),
|
||||
texture(
|
||||
1,
|
||||
TextureType::Buffer,
|
||||
TextureFormat::Rgba32Float,
|
||||
[2, 1, 1],
|
||||
vec![0xab; 32],
|
||||
),
|
||||
],
|
||||
Vec::new(),
|
||||
[2, 1, 1],
|
||||
ComputeOutput::Texture {
|
||||
binding: 1,
|
||||
origin: [0, 0, 0],
|
||||
dimensions: [2, 1, 1],
|
||||
},
|
||||
);
|
||||
let run = run(&case, &fixture("texture_ops.ll")).unwrap();
|
||||
let doubled: Vec<f32> = source.iter().map(|value| value * 2.0).collect();
|
||||
assert_eq!(run.output, floats(&doubled));
|
||||
}
|
||||
|
||||
/// The public out-of-bounds texture-buffer case (`ob1_texel_buffer`): reads and writes past two
|
||||
/// 4-texel `r32_uint` texture buffers. Each is host-visible buffer memory, which the candidate
|
||||
/// allocates inside a guard of the case's reach, so the census counts the guard bytes each run
|
||||
/// changed: none, and the written buffer's own texels are the in-bounds writes.
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[test]
|
||||
fn a_texture_buffer_written_past_its_end_is_guarded() {
|
||||
use crate::case::out_of_bounds::{ContainmentForm, OutOfBoundsResource, OutOfBoundsTarget};
|
||||
let idx = [0u32, 1, 2, 3, 4, 5, 64, 1000, 3, 2, 1, 0, 4, 8, 100, 4096];
|
||||
let mut case = kernel(
|
||||
"ob1_texel_buffer",
|
||||
vec![
|
||||
texture(
|
||||
0,
|
||||
TextureType::Buffer,
|
||||
TextureFormat::R32Uint,
|
||||
[4, 1, 1],
|
||||
words(&[0xF100_0001, 0xF100_0002, 0xF100_0003, 0xF100_0004]),
|
||||
),
|
||||
texture(
|
||||
1,
|
||||
TextureType::Buffer,
|
||||
TextureFormat::R32Uint,
|
||||
[4, 1, 1],
|
||||
vec![0xab; 16],
|
||||
),
|
||||
],
|
||||
Vec::new(),
|
||||
[8, 1, 1],
|
||||
ComputeOutput::Texture {
|
||||
binding: 1,
|
||||
origin: [0, 0, 0],
|
||||
dimensions: [4, 1, 1],
|
||||
},
|
||||
);
|
||||
case.buffers = BTreeMap::from([(0, words(&idx)), (1, vec![0xab; 32])]);
|
||||
case.out_of_bounds = [(0, 4000), (1, 16384)]
|
||||
.into_iter()
|
||||
.map(|(binding, reach_after)| OutOfBoundsTarget {
|
||||
resource: OutOfBoundsResource::Texture { binding },
|
||||
form: ContainmentForm::TexelBuffer,
|
||||
reach_before: 0,
|
||||
reach_after,
|
||||
})
|
||||
.collect();
|
||||
let run = run(&case, &fixture("ob1_texel_buffer.ll")).unwrap();
|
||||
assert_eq!(
|
||||
run.output,
|
||||
words(&[0xA000_0003, 0xA000_0002, 0xA000_0001, 0xA000_0000])
|
||||
);
|
||||
let targets = run
|
||||
.census
|
||||
.out_of_bounds
|
||||
.expect("an out-of-bounds case's census records its targets")
|
||||
.targets;
|
||||
assert_eq!(targets.len(), 2);
|
||||
for target in targets {
|
||||
assert_eq!(target.escaped, Some(0), "{target:?}");
|
||||
assert!(target.past_end.is_some(), "{target:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A `read_write` texture read, written, fenced, and read again, observed as a texture region.
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[test]
|
||||
|
||||
@@ -168,20 +168,11 @@ pub(super) mod device {
|
||||
argument_buffer_buffers,
|
||||
argument_buffer_textures: BTreeMap::new(),
|
||||
argument_buffer_samplers: BTreeMap::new(),
|
||||
rate_maps: BTreeMap::new(),
|
||||
argument_buffer_rate_maps: BTreeMap::new(),
|
||||
objects: BTreeMap::new(),
|
||||
command_buffers: BTreeMap::new(),
|
||||
textures: BTreeMap::new(),
|
||||
samplers: BTreeMap::new(),
|
||||
function_tables: BTreeMap::new(),
|
||||
acceleration_structures: BTreeMap::new(),
|
||||
threadgroup_lengths: BTreeMap::new(),
|
||||
imageblock: None,
|
||||
tile: None,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
attribute_strides: Default::default(),
|
||||
dispatch: Dispatch::Threads {
|
||||
threads: [kernel.threads, 1, 1],
|
||||
threads_per_group: [kernel.threads, 1, 1],
|
||||
|
||||
@@ -100,7 +100,7 @@ fn command_buffer_literals_participate_in_identity_and_validate_resources() {
|
||||
assert!(crate::executor_contract::require_case(&case, "test").is_ok());
|
||||
assert_engine_refuses(&case, "without its owner buffer");
|
||||
case.command_buffers[0].buffer_binding = case.buffers[0].binding;
|
||||
let mapped = crate::candidate::engine::compute_case(&case, &kernel_interface()).unwrap();
|
||||
let mapped = crate::candidate::engine::compute_case(&case).unwrap();
|
||||
let key = (case.buffers[0].binding, 0);
|
||||
assert!(mapped.objects.is_empty());
|
||||
assert_eq!(
|
||||
@@ -117,21 +117,8 @@ fn command_buffer_literals_participate_in_identity_and_validate_resources() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The AIR-layer interface of a kernel without parameters.
|
||||
fn kernel_interface() -> crate::check::interface::AirInterface {
|
||||
crate::check::interface::AirInterface::synthetic(
|
||||
metal2vulkan_air::abi::Stage::Kernel {
|
||||
max_total_threads: None,
|
||||
work_group_size: None,
|
||||
},
|
||||
vec![],
|
||||
vec![],
|
||||
vec![],
|
||||
)
|
||||
}
|
||||
|
||||
fn assert_engine_refuses(case: &AuthoredCase, what: &str) {
|
||||
match crate::candidate::engine::compute_case(case, &kernel_interface()) {
|
||||
match crate::candidate::engine::compute_case(case) {
|
||||
Err(crate::check::admission::NotSupported::NotImplemented(detail)) => {
|
||||
assert!(detail.contains(what), "{detail}")
|
||||
}
|
||||
@@ -179,7 +166,7 @@ fn pipeline_handles_require_unique_tokens_and_hash_the_template() {
|
||||
assert!(crate::executor_contract::require_case(&case, "test").is_ok());
|
||||
// The engine candidate maps a pipeline state as its authored token in its owner, the
|
||||
// word a command's pipeline field records, and refuses one whose owner is not bound.
|
||||
let mapped = crate::candidate::engine::compute_case(&case, &kernel_interface()).unwrap();
|
||||
let mapped = crate::candidate::engine::compute_case(&case).unwrap();
|
||||
assert_eq!(
|
||||
mapped.objects.into_iter().collect::<Vec<_>>(),
|
||||
[((case.buffers[0].binding, 0), 1)]
|
||||
@@ -1489,7 +1476,7 @@ fn executed_command_buffers_run_in_identity_order() {
|
||||
assert_eq!(keys(&reversed), keys(&case));
|
||||
// The candidate's map iterates the same keys in the same order.
|
||||
for listing in [&case, &reversed] {
|
||||
let mapped = crate::candidate::engine::compute_case(listing, &kernel_interface()).unwrap();
|
||||
let mapped = crate::candidate::engine::compute_case(listing).unwrap();
|
||||
assert_eq!(
|
||||
mapped
|
||||
.command_buffers
|
||||
|
||||
@@ -53,10 +53,10 @@ use crate::observation_contract::{ComparisonClass, ObservationLanes};
|
||||
use base64::Engine as _;
|
||||
use metal2vulkan::device::{DevicePolicy, DeviceProfile, HandleDomain, PointerDomain, Robustness};
|
||||
use metal2vulkan::library::CompiledFunction;
|
||||
use metal2vulkan::pipeline::VertexInputState;
|
||||
use metal2vulkan::pipeline::{AttributeFetch, StrategyCensus};
|
||||
use metal2vulkan::pipeline::{BufferForm, DescriptorView, SlotInterface};
|
||||
use metal2vulkan::pipeline::{SlotClass, SlotRef, Stage as SymStage};
|
||||
use metal2vulkan::pipeline::{StageInputDescriptor, VertexInputState};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
@@ -319,23 +319,6 @@ impl Fetch {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Each stage input a kernel compiled under stage-input descriptor `descriptor` fetches, by
|
||||
/// Metal attribute index: in the shader, from the buffer its attribute names.
|
||||
pub fn of_stage_input(descriptor: Option<&StageInputDescriptor>) -> BTreeMap<u32, Fetch> {
|
||||
descriptor
|
||||
.iter()
|
||||
.flat_map(|descriptor| &descriptor.attributes)
|
||||
.map(|(&location, attribute)| {
|
||||
(
|
||||
location,
|
||||
Fetch::Pulled {
|
||||
buffer_index: attribute.buffer_index,
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Each attribute a render pipeline of vertex input state `state` fetches, by Metal attribute
|
||||
/// index, of the attributes `buffers` names with the Metal buffer each one's data is bound at
|
||||
/// (one attribute per buffer, as a case binds them): pulled in the shader from the buffer
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
//! What both executors make of a sparse texture's mappings.
|
||||
//! What the Metal oracle makes of a sparse texture's mappings.
|
||||
//!
|
||||
//! A case names its mapped texels ([`crate::case::sparse`]); each device divides the texture into
|
||||
//! its own tiles: the Metal oracle's sparse tiles (`sparseTileSizeWithTextureType:...` at the
|
||||
//! heap's page size) and the Vulkan candidate's sparse image blocks (`imageGranularity`), with a
|
||||
//! first level kept in a mip tail (`firstMipmapInTail`, `imageMipTailFirstLod`). Both executors
|
||||
//! make each mapping through [`device_mappings`] under their own [`SparseTiling`], so a region
|
||||
//! that is not a whole number of the device's tiles, or that covers part of a level in its mip
|
||||
//! tail, is refused the same way before anything runs. A case's mip tail is its slice's one level
|
||||
//! whole (`case::sparse`): a device that keeps that level in its tail maps the tail, and one that
|
||||
//! does not maps the level's tiles; a region covering a whole level in the tail maps the tail. On
|
||||
//! a device that makes every mapping, the mapped texels are exactly the regions and tails the
|
||||
//! case names ([`mapped_texels`]), which is what each executor uploads ([`literal_offset`]).
|
||||
//!
|
||||
//! Where the plan answers a slot's residency from a tile map (on every device for a slot whose type
|
||||
//! has one), the candidate makes the sparse texture as the runtime does: the mapped texels and zero
|
||||
//! elsewhere ([`mapped_bytes`]), in each block of a sparse resident image that holds a mapped tile
|
||||
//! where the device makes one, else in an ordinary image, and the tile map of the same mappings
|
||||
//! ([`tile_map`]) made under [`tile_map_tiling`].
|
||||
//! A case names its mapped texels ([`crate::case::sparse`]); the device divides the texture into
|
||||
//! its own tiles, Metal's sparse tiles (`sparseTileSizeWithTextureType:...` at the heap's page
|
||||
//! size), with a first level kept in a mip tail (`firstMipmapInTail`). The oracle makes each
|
||||
//! mapping through [`device_mappings`] under its [`SparseTiling`], so a region that is not a whole
|
||||
//! number of the device's tiles, or that covers part of a level in its mip tail, is refused before
|
||||
//! anything runs. A case's mip tail is its slice's one level whole (`case::sparse`): a device that
|
||||
//! keeps that level in its tail maps the tail, and one that does not maps the level's tiles; a
|
||||
//! region covering a whole level in the tail maps the tail. On a device that makes every mapping,
|
||||
//! the mapped texels are exactly the regions and tails the case names ([`mapped_texels`]), which is
|
||||
//! what the oracle uploads ([`literal_offset`]). The engine's candidate runs no sparse texture
|
||||
//! (`ToolingRequirement::SparseTexture`).
|
||||
|
||||
use crate::case::sparse::{sparse_extent, SparseMapping, LITERAL_LEVELS};
|
||||
use crate::literal::LiteralTexture;
|
||||
@@ -28,10 +22,10 @@ const _: () = assert!(LITERAL_LEVELS == 1);
|
||||
/// How one device divides a sparse texture.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct SparseTiling {
|
||||
/// A tile's extent in texels (x, y, z): Metal's sparse tile, Vulkan's `imageGranularity`.
|
||||
/// A tile's extent in texels (x, y, z): Metal's sparse tile.
|
||||
pub tile: [u32; 3],
|
||||
/// The first mipmap level in the mip tail, or the texture's level count when it has no tail
|
||||
/// (Metal's `firstMipmapInTail`, Vulkan's `imageMipTailFirstLod`).
|
||||
/// (Metal's `firstMipmapInTail`).
|
||||
pub first_level_in_tail: u32,
|
||||
}
|
||||
|
||||
@@ -247,116 +241,6 @@ pub fn literal_offset(texture: &LiteralTexture, region: &TexelRegion) -> Result<
|
||||
Ok(offset)
|
||||
}
|
||||
|
||||
/// The tiling under which the candidate emulates `texture` from a tile map: Metal's sparse tile at
|
||||
/// the oracle's 16 KiB page, as apple-m3-max-macos26.7 answers it for 4-byte texels (64x64x1, for a
|
||||
/// 2D, 2D array, and 3D texture alike), extended to the other texel sizes as the 16 KiB tile whose
|
||||
/// width is its height or twice it (128x128 for 1 byte, 128x64 for 2, 64x32 for 8, 32x32 for 16);
|
||||
/// level 0 is in the mip tail where it is narrower or shorter than a tile, as Metal kept it for a
|
||||
/// 16x16 2D array and a 64x32x32 3D texture and not for a 256x128 or 256x64 one. The tiling decides
|
||||
/// only which regions the emulation refuses ([`device_mappings`]): the texels it maps are the
|
||||
/// case's regions and tails either way.
|
||||
pub fn tile_map_tiling(texture: &LiteralTexture) -> Result<SparseTiling, String> {
|
||||
let (extent, _) = extent_of(texture)?;
|
||||
let texel = texture.format.bytes_per_pixel();
|
||||
let tile = match texel {
|
||||
1 => [128, 128, 1],
|
||||
2 => [128, 64, 1],
|
||||
4 => [64, 64, 1],
|
||||
8 => [64, 32, 1],
|
||||
16 => [32, 32, 1],
|
||||
_ => {
|
||||
return Err(format!(
|
||||
"texture {}: no 16 KiB tile of {texel}-byte texels",
|
||||
texture.binding
|
||||
))
|
||||
}
|
||||
};
|
||||
let tailed = extent[0] < tile[0] || extent[1] < tile[1];
|
||||
Ok(SparseTiling {
|
||||
tile,
|
||||
first_level_in_tail: if tailed { 0 } else { LITERAL_LEVELS },
|
||||
})
|
||||
}
|
||||
|
||||
/// The tile map of `texture`'s mappings under `tiling`, as the consumer keeps it: each region's
|
||||
/// tiles and each slice's mip tail mapped, in the case's order. `Ok(None)` for a texture that is
|
||||
/// not sparse.
|
||||
pub fn tile_map(
|
||||
texture: &LiteralTexture,
|
||||
tiling: SparseTiling,
|
||||
) -> Result<Option<metal2vulkan::bind::SparseTileMap>, String> {
|
||||
use crate::case::TextureType as T;
|
||||
use metal2vulkan::bind::{SparseTileMap, TileMapping};
|
||||
use metal2vulkan::metal::TextureType as Metal;
|
||||
let Some(mappings) = device_mappings(texture, tiling)? else {
|
||||
return Ok(None);
|
||||
};
|
||||
let (extent, slices) = extent_of(texture)?;
|
||||
let texture_type = match texture.texture_type {
|
||||
T::D2 => Metal::Type2D,
|
||||
T::D2Array => Metal::Type2DArray,
|
||||
T::D3 => Metal::Type3D,
|
||||
other => {
|
||||
return Err(format!(
|
||||
"texture {}: a {other:?} texture has no tile map",
|
||||
texture.binding
|
||||
))
|
||||
}
|
||||
};
|
||||
let error = |e: metal2vulkan::bind::TileMapError| format!("texture {}: {e}", texture.binding);
|
||||
let mut map = SparseTileMap::new(
|
||||
texture_type,
|
||||
extent,
|
||||
LITERAL_LEVELS,
|
||||
slices,
|
||||
tiling.tile,
|
||||
tiling.first_level_in_tail,
|
||||
)
|
||||
.map_err(error)?;
|
||||
for mapping in mappings {
|
||||
let (level, slice, origin, size) = match mapping {
|
||||
DeviceMapping::Tiles {
|
||||
texels,
|
||||
tile_origin,
|
||||
tile_count,
|
||||
} => (texels.level, texels.slice, tile_origin, tile_count),
|
||||
DeviceMapping::MipTail { slice } => (tiling.first_level_in_tail, slice, [0; 3], [1; 3]),
|
||||
};
|
||||
map.update(TileMapping::Map, level, slice, origin, size)
|
||||
.map_err(error)?;
|
||||
}
|
||||
Ok(Some(map))
|
||||
}
|
||||
|
||||
/// `texture`'s authored bytes with every texel outside `regions` zero: what the consumer's
|
||||
/// ordinary image holds for a sparse texture emulated from a tile map, whose unmapped texels read
|
||||
/// as Metal's do (zero memory).
|
||||
pub fn mapped_bytes(texture: &LiteralTexture, regions: &[TexelRegion]) -> Result<Vec<u8>, String> {
|
||||
let (extent, _) = extent_of(texture)?;
|
||||
let texel = texture.format.bytes_per_pixel() as u64;
|
||||
let [width, height, _] = extent.map(u64::from);
|
||||
let mut bytes = vec![0u8; texture.bytes.len()];
|
||||
for region in regions {
|
||||
let first = literal_offset(texture, region)?;
|
||||
let row = u64::from(region.size[0]) * texel;
|
||||
for z in 0..u64::from(region.size[2]) {
|
||||
for y in 0..u64::from(region.size[1]) {
|
||||
let at = (first + (z * height + y) * width * texel) as usize;
|
||||
let end = at + row as usize;
|
||||
let (Some(from), Some(to)) = (texture.bytes.get(at..end), bytes.get_mut(at..end))
|
||||
else {
|
||||
return Err(format!(
|
||||
"texture {}: region {region:?} leaves the authored bytes",
|
||||
texture.binding
|
||||
));
|
||||
};
|
||||
to.copy_from_slice(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -508,77 +392,6 @@ mod tests {
|
||||
assert!(device_mappings(&part, untailed).is_err());
|
||||
}
|
||||
|
||||
/// The emulation from a tile map: a 16 KiB tile of the texel size, level 0 in the tail where it
|
||||
/// is smaller than a tile; the map's bits are exactly the case's mapped texels, a tail
|
||||
/// included, and the image's bytes are the authored ones there and zero elsewhere.
|
||||
#[test]
|
||||
fn a_tile_map_emulation_maps_exactly_the_cases_texels() {
|
||||
let left = sparse(
|
||||
TextureType::D2,
|
||||
[256, 128, 1],
|
||||
vec![region(0, [0, 0, 0], [128, 128, 1])],
|
||||
);
|
||||
let tiling = tile_map_tiling(&left).unwrap();
|
||||
assert_eq!(
|
||||
tiling,
|
||||
SparseTiling {
|
||||
tile: [64, 64, 1],
|
||||
first_level_in_tail: NO_TAIL
|
||||
}
|
||||
);
|
||||
let map = tile_map(&left, tiling).unwrap().unwrap();
|
||||
for (texel, mapped) in [
|
||||
([127, 127, 0], true),
|
||||
([128, 0, 0], false),
|
||||
([5, 7, 0], true),
|
||||
] {
|
||||
assert_eq!(map.is_mapped(0, 0, texel), mapped, "{texel:?}");
|
||||
}
|
||||
let mut left = left;
|
||||
left.bytes = (0..left.bytes.len()).map(|i| (i % 251) as u8 + 1).collect();
|
||||
let mappings = device_mappings(&left, tiling).unwrap().unwrap();
|
||||
let bytes = mapped_bytes(&left, &mapped_texels(&left, tiling, &mappings).unwrap()).unwrap();
|
||||
for (x, y) in [(0usize, 0usize), (127, 5), (128, 5), (255, 127)] {
|
||||
let at = (y * 256 + x) * 4;
|
||||
let want = if x < 128 {
|
||||
&left.bytes[at..at + 4]
|
||||
} else {
|
||||
&[0u8; 4][..]
|
||||
};
|
||||
assert_eq!(&bytes[at..at + 4], want, "({x}, {y})");
|
||||
}
|
||||
let small = sparse(
|
||||
TextureType::D2Array,
|
||||
[16, 16, 3],
|
||||
vec![
|
||||
SparseMapping::MipTail { slice: 0 },
|
||||
SparseMapping::MipTail { slice: 2 },
|
||||
],
|
||||
);
|
||||
let tiling = tile_map_tiling(&small).unwrap();
|
||||
assert_eq!(tiling.first_level_in_tail, 0);
|
||||
let map = tile_map(&small, tiling).unwrap().unwrap();
|
||||
for (slice, mapped) in [(0, true), (1, false), (2, true)] {
|
||||
assert_eq!(
|
||||
map.is_mapped(0, slice, [15, 15, 0]),
|
||||
mapped,
|
||||
"slice {slice}"
|
||||
);
|
||||
}
|
||||
let volume = sparse(
|
||||
TextureType::D3,
|
||||
[64, 64, 32],
|
||||
vec![region(0, [0, 0, 0], [64, 64, 16])],
|
||||
);
|
||||
let tiling = tile_map_tiling(&volume).unwrap();
|
||||
let map = tile_map(&volume, tiling).unwrap().unwrap();
|
||||
assert!(map.is_mapped(0, 0, [63, 63, 15]));
|
||||
assert!(!map.is_mapped(0, 0, [0, 0, 16]));
|
||||
let mut ordinary = volume;
|
||||
ordinary.sparse = None;
|
||||
assert_eq!(tile_map(&ordinary, tiling), Ok(None));
|
||||
}
|
||||
|
||||
/// The upload reads each region from the literal's packing: slices, then planes, then rows.
|
||||
#[test]
|
||||
fn a_region_is_copied_from_the_literals_packing() {
|
||||
|
||||
@@ -164,9 +164,10 @@ pub enum ToolingRequirement {
|
||||
MeshRenderPipeline,
|
||||
/// A replayed pipeline template the engine's candidate does not replay
|
||||
/// (`candidate::engine::replay_templates`): a compute template that binds more than buffers
|
||||
/// and threadgroup memory or runs a stage input, or a render template that is not a
|
||||
/// rasterization-disabled vertex function binding buffers only. A case's templates raise it,
|
||||
/// never a source's structure, so no census row carries it.
|
||||
/// and threadgroup memory, or a render template that is not a rasterization-disabled vertex
|
||||
/// function binding buffers only (a template of a family the runtime does not build is refused
|
||||
/// as that family first). A case's templates raise it, never a source's structure, so no census
|
||||
/// row carries it.
|
||||
ReplayedTemplateResources,
|
||||
/// A sequentially consistent fence its entry's pipeline compiles
|
||||
/// (`executor_contract::seq_cst_fence`): an `atomic_thread_fence` of `memory_order_seq_cst`
|
||||
|
||||
@@ -788,9 +788,7 @@ mod tests {
|
||||
entry: "read_write_fence".into(),
|
||||
constants: FunctionConstantValues::defaults(),
|
||||
buffers: Default::default(),
|
||||
rate_maps: Default::default(),
|
||||
argument_buffer_buffers: Default::default(),
|
||||
argument_buffer_rate_maps: Default::default(),
|
||||
argument_buffer_textures: Default::default(),
|
||||
argument_buffer_samplers: Default::default(),
|
||||
objects: Default::default(),
|
||||
@@ -811,14 +809,7 @@ mod tests {
|
||||
)]
|
||||
.into(),
|
||||
samplers: Default::default(),
|
||||
function_tables: Default::default(),
|
||||
acceleration_structures: Default::default(),
|
||||
threadgroup_lengths: Default::default(),
|
||||
imageblock: None,
|
||||
tile: None,
|
||||
stage_input: None,
|
||||
stage_in_region: None,
|
||||
attribute_strides: Default::default(),
|
||||
dispatch: metal2vulkan::bind::Dispatch::Threads {
|
||||
threads: [2, 2, 1],
|
||||
threads_per_group: [1, 1, 1],
|
||||
@@ -830,8 +821,6 @@ mod tests {
|
||||
function: RequestFunction::new(case.entry.as_str(), case.constants.clone()),
|
||||
shape: shape.clone(),
|
||||
dispatch: None,
|
||||
stage_input: None,
|
||||
tile: None,
|
||||
replay: false,
|
||||
};
|
||||
let (bytes, digest) = input(&device, &bitcode, request.clone());
|
||||
@@ -858,7 +847,6 @@ mod tests {
|
||||
&function,
|
||||
&shape,
|
||||
None,
|
||||
None,
|
||||
&metal2vulkan::Budget::standard(),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -889,7 +877,6 @@ mod tests {
|
||||
&crate::check::interface::tests::vertex_buffers_at(&[0]),
|
||||
crate::candidate::engine::graphics::tests::WITHOUT_SLICE,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let template = render_template(&case);
|
||||
@@ -1030,8 +1017,6 @@ mod tests {
|
||||
},
|
||||
shape: BindShape::default(),
|
||||
dispatch: None,
|
||||
stage_input: None,
|
||||
tile: None,
|
||||
replay: false,
|
||||
};
|
||||
let libraries = [caller.as_slice(), functions.as_slice(), caller.as_slice()];
|
||||
|
||||
@@ -119,7 +119,7 @@ fn a_case_with_visible_function_references_compiles_linked_through_the_worker()
|
||||
)
|
||||
.unwrap_or_else(|error| panic!("admission: {error}"));
|
||||
let checked = admitted.checked();
|
||||
let compute = compute_case(&checked.primary.case, &checked.primary.interface).unwrap();
|
||||
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 {
|
||||
@@ -160,8 +160,7 @@ fn a_case_with_visible_function_references_compiles_linked_through_the_worker()
|
||||
&compute,
|
||||
&shape,
|
||||
)
|
||||
.unwrap_or_else(|error| panic!("{stem}: {error}"))
|
||||
.pipeline;
|
||||
.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}"),
|
||||
|
||||
+1
-1
@@ -488,7 +488,7 @@ cargo run -p metal2vulkan-validation --release --bin corpus-vulkan -- \
|
||||
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
|
||||
generated companion, its vertex buffers at static strides, its color targets (Shared 2D
|
||||
generated companion, its vertex buffers, its color targets (Shared 2D
|
||||
textures, loaded and stored by the pass), a depth/stencil attachment of one aspect as the oracle
|
||||
makes it (a Shared `Depth32Float` filled by a draw of its depths, as a 32-bit float depth texture
|
||||
is, or a Shared `Stencil8` written from its bytes, loaded and stored by the pass; in a pass of
|
||||
|
||||
Reference in new issue
Block a user