Delete the half gather's fetch and the compiler-word-bound fit, which have nothing left to drop
With the NaN lane landed beside this one, two exact-only paths lost their last use. The half gather's fetch (lower::sampler::fetched) read a half-float texel's NaN through TexelNanRoute, which the NaN lane removed: no selection reaches it. Deleted with the Sampling field, the RuntimeSlot word fields it set (filters, fetched, fetched_depth), the shared switch's fetched emulation and its lane constants, the heap fetch in emit, and the helpers only it used (LinearImage, HEAP_WORDS, footprint_from, texel_format_spec, texel_format_const, constant_lanes_by folded into constant_lanes). The compiler-word-bound fit (pipeline::compile::fit) retranslated a pipeline past ANV's 400,000-word bound with its exact forms dropped. No exact form is left to drop, so the fit, fit_render_variant / fit_mesh_variant / fit_compute_pipeline / fit_tile_pipeline, DeviceProfile::module_word_bound, RuntimeFact::ExactFormsOverCompilerLimit, the runtime's Degradation::ExactFormsOverCompilerLimit and its notice, the runtime and validation tests of it, its FAST-PATHS row and its API.md passages go. DriverWorkaround::RegisterAllocatorOverflowsLargeModules stays, recorded on the profile alone. fast_paths loses its FastDefault class, now empty. Verified: cargo clippy --workspace --all-targets --all-features -D warnings, plain and with --cfg m2v_gpu; RUSTDOCFLAGS='-D warnings' cargo doc --workspace --all-features --no-deps; refusal_surface.py leaves docs/REFUSALS.md unchanged. Originally 50fcff8a4e (archive/development-linear-2026-10-28).
This commit is contained in:
1 parent
78ed264c90
commit
3c129f4d6f
32 files changed
+91
-2273
No files matched your search
@@ -445,19 +445,6 @@ degradations! {
|
||||
"each draw runs a geometry stage of its topology class between the vertex and \
|
||||
fragment stages, which emits each primitive's vertices with the barycentric weights \
|
||||
or the first vertex's slice and viewport";
|
||||
/// A pipeline state (render, mesh render, tile render or compute) whose largest stage
|
||||
/// module, under the consumer's exact forms, exceeded the device's compiler word bound
|
||||
/// ([`metal2vulkan::pipeline::RuntimeFact::ExactFormsOverCompilerLimit`];
|
||||
/// [`metal2vulkan::device::DriverWorkaround::RegisterAllocatorOverflowsLargeModules`],
|
||||
/// ANV's register allocator faults compiling a module past it), so the translation dropped
|
||||
/// the consumer's exact forms: every module-growing exact answer native. Announced where the runtime makes a variant whose
|
||||
/// pipeline the fit reduced, the base variant or another (`pipeline/render.rs` for a
|
||||
/// render or mesh render state, `pipeline/mod.rs` for a compute or tile render state, from
|
||||
/// the pipeline's dependencies), naming the state's kind and the forms dropped; the
|
||||
/// reduced stages announce their own precision notes besides.
|
||||
ExactFormsOverCompilerLimit = "exact-forms-over-compiler-limit", Precision,
|
||||
"the dropped exact forms' results can differ from Metal's as their notes' \
|
||||
documentation states, where the device's compiler would fault on the exact module";
|
||||
/// Visibility results start where Vulkan writes no query result.
|
||||
LandedVisibilityResults = "landed-visibility-results", Performance,
|
||||
"they land in an upload region and are copied on into the buffer after the pass";
|
||||
@@ -2514,9 +2501,6 @@ impl Kinds {
|
||||
kinds.add(Degradation::UnadvertisedVertexSimdgroups);
|
||||
}
|
||||
}
|
||||
if dropped_exact_forms(pipeline.dependencies()).is_some() {
|
||||
kinds.add(Degradation::ExactFormsOverCompilerLimit);
|
||||
}
|
||||
kinds
|
||||
}
|
||||
|
||||
@@ -2544,14 +2528,6 @@ impl<'a> CompiledPipeline<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The pipeline's runtime dependencies.
|
||||
fn dependencies(self) -> &'a [metal2vulkan::pipeline::RuntimeDependency] {
|
||||
match self {
|
||||
CompiledPipeline::Render(p) => &p.dependencies,
|
||||
CompiledPipeline::Kernel(p) => &p.dependencies,
|
||||
}
|
||||
}
|
||||
|
||||
/// The kind of pipeline state a notice of the pipeline names, from its structure: a render
|
||||
/// pipeline with an object or mesh stage, or with the records of an emulated mesh, is a mesh
|
||||
/// render pipeline state's; a compute pipeline of a tile function
|
||||
@@ -2584,25 +2560,6 @@ impl<'a> CompiledPipeline<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The exact forms a pipeline's translation dropped to fit the device's compiler word bound
|
||||
/// (`RuntimeFact::ExactFormsOverCompilerLimit` among its `dependencies`), named; `None` where it
|
||||
/// dropped none.
|
||||
pub(crate) fn dropped_exact_forms(
|
||||
dependencies: &[metal2vulkan::pipeline::RuntimeDependency],
|
||||
) -> Option<Vec<&'static str>> {
|
||||
dependencies.iter().find_map(|d| match d.fact {
|
||||
metal2vulkan::pipeline::RuntimeFact::ExactFormsOverCompilerLimit {
|
||||
} => Some(
|
||||
[
|
||||
]
|
||||
.into_iter()
|
||||
.filter_map(|(dropped, name)| dropped.then_some(name))
|
||||
.collect(),
|
||||
),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Where a variant's notices are announced: as the variant (or a `VkPipeline` of it) is made,
|
||||
/// or as a dispatch or draw binds it.
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -3107,27 +3064,14 @@ impl Device {
|
||||
|
||||
impl Device {
|
||||
/// Announce, `at` its variant's making or a bind ([`Occurrence`]), what a variant's `pipeline`
|
||||
/// records beside its stages: exact forms the translation dropped to fit the device's compiler
|
||||
/// word bound ([`Degradation::ExactFormsOverCompilerLimit`]), naming the pipeline state's kind
|
||||
/// (render, mesh render, tile render or compute), and, for a render variant, requirements that
|
||||
/// hold a vertex function's subgroup operations on a driver that runs them as Metal does
|
||||
/// without advertising the vertex stage ([`Degradation::UnadvertisedVertexSimdgroups`]), and,
|
||||
/// for any, a set layout its driver refuses though it runs it
|
||||
/// ([`Degradation::SetPastLayoutSupport`], before any layout of the variant is made); for the
|
||||
/// base variant and every other alike, each pipeline by its own records.
|
||||
/// records beside its stages: for a render variant, requirements that hold a vertex
|
||||
/// function's subgroup operations on a driver that runs them as Metal does without advertising
|
||||
/// the vertex stage ([`Degradation::UnadvertisedVertexSimdgroups`]), and, for any, a set
|
||||
/// layout its driver refuses though it runs it ([`Degradation::SetPastLayoutSupport`], before
|
||||
/// any layout of the variant is made), naming the pipeline state's kind (render, mesh render,
|
||||
/// tile render or compute); for the base variant and every other alike, each pipeline by its
|
||||
/// own records.
|
||||
pub(super) fn degrade_pipeline(&self, pipeline: CompiledPipeline<'_>, at: Occurrence<'_>) {
|
||||
if let Some(dropped) = dropped_exact_forms(pipeline.dependencies()) {
|
||||
self.degrade_at(at, Degradation::ExactFormsOverCompilerLimit, || {
|
||||
(
|
||||
pipeline.object().to_owned(),
|
||||
format!(
|
||||
"its largest stage module passed the device's compiler word bound, so its \
|
||||
translation dropped {} to the device's answer",
|
||||
dropped.join(", ")
|
||||
),
|
||||
)
|
||||
});
|
||||
}
|
||||
if self
|
||||
.shared()
|
||||
.announced
|
||||
|
||||
@@ -489,27 +489,6 @@ impl Kernel {
|
||||
}
|
||||
inputs
|
||||
}
|
||||
|
||||
/// `pipeline`, this descriptor's compile with its kernel or tile function compiled under
|
||||
/// `inputs` ([`Kernel::inputs`]), held to the device's compiler word bound
|
||||
/// (`fit_compute_pipeline`, `fit_tile_pipeline`): translated again from the function this
|
||||
/// descriptor holds, with the exact forms dropped, where its module passes the bound.
|
||||
fn fit(
|
||||
&self,
|
||||
compile: &metal2vulkan::device::Device,
|
||||
inputs: &metal2vulkan::pipeline::LoweringInputs,
|
||||
budget: &metal2vulkan::Budget,
|
||||
pipeline: ComputePipeline,
|
||||
) -> Result<ComputePipeline, metal2vulkan::error::Error> {
|
||||
match self {
|
||||
Kernel::Compute(descriptor) => {
|
||||
compile.fit_compute_pipeline(descriptor, inputs, budget, pipeline)
|
||||
}
|
||||
Kernel::Tile(descriptor) => {
|
||||
compile.fit_tile_pipeline(descriptor, inputs, budget, pipeline)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One compiled variant of a state.
|
||||
@@ -1581,9 +1560,8 @@ impl Variant {
|
||||
/// the variant of it the memo knows live, or the pipeline `sources` give, each stage found or
|
||||
/// compiled under one budget. The function compiles under the descriptor's stage input
|
||||
/// descriptor or color attachment formats ([`Kernel::inputs`]), and the pipeline under its
|
||||
/// other fields, held to the device's compiler word bound from `descriptor`, which holds the
|
||||
/// function ([`Kernel::fit`]); with `descriptor` holding the function as compiled. A refusal is
|
||||
/// the compile layer's.
|
||||
/// other fields; with `descriptor` holding the function as compiled. A refusal is the compile
|
||||
/// layer's.
|
||||
///
|
||||
/// The compile reads the kernel's specialized entry from the device's stage entries, as a
|
||||
/// render creation's stages do: a sibling pipeline of the same kernel at the same call-stack
|
||||
@@ -1611,7 +1589,7 @@ impl Variant {
|
||||
let compiled =
|
||||
sources.function(function, &inputs, (&function_key, Some(entries)), &budget)?;
|
||||
let compiled = descriptor.with_stage(StageSource::Compiled(compiled));
|
||||
let found = sources.kernel(&compiled, (descriptor, &inputs), &budget)?;
|
||||
let found = sources.kernel(&compiled, &budget)?;
|
||||
Ok((found, compiled))
|
||||
}
|
||||
|
||||
|
||||
@@ -2628,9 +2628,6 @@ impl RenderVariant {
|
||||
)?));
|
||||
}
|
||||
let pipeline = compile.compile_render_variant(&linked, key, &budget)?;
|
||||
// Held to the driver's compiler word bound, translated again from the functions where its
|
||||
// largest stage passes it; it keeps its key, so the cache stores and finds it as compiled.
|
||||
let pipeline = compile.fit_render_variant(descriptor, key, &budget, pipeline)?;
|
||||
// The stages the link was given, whichever way they arrived: the ones this creation
|
||||
// compiled, and the ones the descriptor already carried compiled.
|
||||
let functions: Vec<CompiledFunction> = [Some(&linked.vertex), linked.fragment.as_ref()]
|
||||
|
||||
@@ -152,13 +152,10 @@ impl<'a> Sources<'a> {
|
||||
/// The compute pipeline of `descriptor`, a compute or tile descriptor whose kernel or tile
|
||||
/// function is compiled: the variant of it the memo knows live, or the pipeline found or
|
||||
/// linked now under `budget` (`compile_compute_pipeline` or `compile_tile_pipeline`, each
|
||||
/// under its own key) and held to the device's compiler word bound from `functions`, the same
|
||||
/// descriptor holding the function, compiled under `inputs` ([`Kernel::fit`]). A refusal is
|
||||
/// the compile layer's.
|
||||
/// under its own key). A refusal is the compile layer's.
|
||||
pub(crate) fn kernel(
|
||||
&self,
|
||||
descriptor: &Kernel,
|
||||
(functions, inputs): (&Kernel, &LoweringInputs),
|
||||
budget: &Budget,
|
||||
) -> Result<Remembered<ComputePipeline, Variant>, metal2vulkan::error::Error> {
|
||||
let compile = self.device.compile_device();
|
||||
@@ -186,10 +183,6 @@ impl<'a> Sources<'a> {
|
||||
compile.compile_tile_pipeline(descriptor, budget)?
|
||||
}
|
||||
};
|
||||
// Held to the driver's compiler word bound, translated again from the
|
||||
// function where its module passes it; it keeps its key, so the cache
|
||||
// stores and finds it as compiled.
|
||||
let pipeline = functions.fit(compile, inputs, budget, pipeline)?;
|
||||
let bytes = cache.store_compute_pipeline(compile, &pipeline);
|
||||
(pipeline, bytes)
|
||||
}
|
||||
|
||||
@@ -1,289 +0,0 @@
|
||||
//! The exact forms a pipeline's translation dropped to fit the device's compiler word bound
|
||||
//! (`RuntimeFact::ExactFormsOverCompilerLimit`) are announced from each variant's own pipeline:
|
||||
//! `Device::degrade_pipeline`, which every variant's making runs (the base variant and every
|
||||
//! other, of a render, mesh render, compute or tile render state alike), and `Kinds::of`, whose
|
||||
//! kinds a bind's notices are made of. So a variant the fit reduced while its base was not
|
||||
//! announces `exact-forms-over-compiler-limit`, once per device, naming the forms dropped and its
|
||||
//! state's kind, and a bind of it on a device asking for the kind at every occurrence announces it
|
||||
//! there; the base announces nothing of it. The notice names each dropped form, so a consumer hears
|
||||
//! which exact answer the fit gave up.
|
||||
//!
|
||||
//! A device test: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
|
||||
//! `m2v_cpu_icd`), on the kind of device the cfg selects. The pipelines are the owned
|
||||
//! `runtime_examples`, `mesh_draws` and `cfb_tile_norm` fixtures' (`llvm-as`), compiled for the
|
||||
//! device, each fitted one carrying the fit's record as the translation adds it; nothing runs on
|
||||
//! the GPU.
|
||||
|
||||
use crate::degradation::{CompiledPipeline, Kinds, Occurrence};
|
||||
use crate::device::lock;
|
||||
use crate::{Degradation, Device, DeviceKind, DeviceOptions, MessageSink};
|
||||
use metal2vulkan::library::Library;
|
||||
use metal2vulkan::metal::PixelFormat;
|
||||
use metal2vulkan::pipeline::{
|
||||
ColorAttachmentDescriptor, ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor,
|
||||
Mechanism, MeshPipelineDescriptor, RenderPipeline, RenderPipelineDescriptor, RuntimeDependency,
|
||||
RuntimeFact, StageModule, StageSource, TileRenderPipelineDescriptor,
|
||||
};
|
||||
use metal2vulkan::Budget;
|
||||
use std::collections::BTreeSet;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
/// What the device's sink heard: each degrade notice's kind, object and reason.
|
||||
type Heard = Arc<Mutex<Vec<(Degradation, String, String)>>>;
|
||||
|
||||
/// The device the cfg selects, asking for `each` at every occurrence, with a sink that keeps every
|
||||
/// degrade notice.
|
||||
fn listening(each: BTreeSet<Degradation>) -> (Device, Heard) {
|
||||
let heard: Heard = Arc::default();
|
||||
let kept = Arc::clone(&heard);
|
||||
let sink = MessageSink::new(move |message: &crate::DebugMessage| {
|
||||
if let Some(notice) = &message.degradation {
|
||||
lock(&kept).push((
|
||||
notice.degradation,
|
||||
notice.object.clone(),
|
||||
notice.reason.clone(),
|
||||
));
|
||||
}
|
||||
});
|
||||
let options = DeviceOptions {
|
||||
kinds: match cfg!(m2v_cpu_icd) {
|
||||
true => vec![DeviceKind::Cpu],
|
||||
false => vec![
|
||||
DeviceKind::Discrete,
|
||||
DeviceKind::Integrated,
|
||||
DeviceKind::Virtual,
|
||||
],
|
||||
},
|
||||
messages: Some(sink),
|
||||
announce_each: each,
|
||||
..DeviceOptions::default()
|
||||
};
|
||||
(Device::system_default_with(&options).unwrap(), heard)
|
||||
}
|
||||
|
||||
/// The owned fixture `name` (under the public fixtures) as a library.
|
||||
fn library(name: &str) -> Library {
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../metal2vulkan-validation/fixtures/public")
|
||||
.join(name);
|
||||
let bitcode = metal2vulkan_devtools::llvm_assemble(&ll).unwrap();
|
||||
Library::from_air(&bitcode).unwrap()
|
||||
}
|
||||
|
||||
/// Add to `dependencies` the fit's record of dropping exact NaN and minimum and maximum.
|
||||
fn fit_into(dependencies: &mut Vec<RuntimeDependency>) {
|
||||
dependencies.push(RuntimeDependency::new(
|
||||
RuntimeFact::ExactFormsOverCompilerLimit {
|
||||
|
||||
},
|
||||
Mechanism::None,
|
||||
));
|
||||
}
|
||||
|
||||
/// `pipeline` as the fit records it.
|
||||
fn render_fit(pipeline: &RenderPipeline) -> RenderPipeline {
|
||||
let mut fit = pipeline.clone();
|
||||
fit_into(&mut fit.dependencies);
|
||||
fit
|
||||
}
|
||||
|
||||
/// `pipeline` as the fit records it.
|
||||
fn kernel_fit(pipeline: &ComputePipeline) -> ComputePipeline {
|
||||
let mut fit = pipeline.clone();
|
||||
fit_into(&mut fit.dependencies);
|
||||
fit
|
||||
}
|
||||
|
||||
/// The fixture's render pipeline (`colored_vertex`, `colored_fragment`, one `RGBA8Unorm` target),
|
||||
/// compiled for `device`, and the same pipeline as the fit records it.
|
||||
fn pipelines(device: &Device) -> (RenderPipeline, RenderPipeline) {
|
||||
let library = library("examples/runtime_examples.ll");
|
||||
let function = |name| FunctionDescriptor::new(library.function(name).unwrap());
|
||||
let mut descriptor =
|
||||
RenderPipelineDescriptor::new(StageSource::Function(function("colored_vertex")));
|
||||
descriptor.fragment = Some(StageSource::Function(function("colored_fragment")));
|
||||
descriptor.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm));
|
||||
let base = device
|
||||
.compile_device()
|
||||
.compile_render_pipeline(&descriptor, &Budget::standard())
|
||||
.unwrap();
|
||||
let fit = render_fit(&base);
|
||||
(base, fit)
|
||||
}
|
||||
|
||||
/// A mesh render pipeline (`mesh_draws`' object, mesh and fragment functions, two `RGBA32Uint`
|
||||
/// targets), compiled for `device`: its `MeshEXT` stages, or the compute and vertex stages that
|
||||
/// emulate them.
|
||||
fn mesh_pipeline(device: &Device) -> RenderPipeline {
|
||||
let library = library("engine/mesh_draws.ll");
|
||||
let stage =
|
||||
|name| StageSource::Function(FunctionDescriptor::new(library.function(name).unwrap()));
|
||||
let mut descriptor = MeshPipelineDescriptor::new(stage("mesh_draws_mesh"));
|
||||
descriptor.object = Some(stage("mesh_draws_object"));
|
||||
descriptor.fragment = Some(stage("mesh_draws_fragment"));
|
||||
for color in &mut descriptor.color_attachments[..2] {
|
||||
*color = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint));
|
||||
}
|
||||
device
|
||||
.compile_device()
|
||||
.compile_mesh_pipeline(&descriptor, &Budget::standard())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// A compute pipeline (`runtime_examples`' `scale_and_offset` kernel) and a tile render pipeline
|
||||
/// (`cfb_tile_norm`'s write of an `RGBA8Unorm` attachment), compiled for `device`.
|
||||
fn kernel_pipelines(device: &Device) -> (ComputePipeline, ComputePipeline) {
|
||||
let compile = device.compile_device();
|
||||
let examples = library("examples/runtime_examples.ll");
|
||||
let kernel = FunctionDescriptor::new(examples.function("scale_and_offset").unwrap());
|
||||
let compute = compile
|
||||
.compile_compute_pipeline(
|
||||
&ComputePipelineDescriptor::new(StageSource::Function(kernel)),
|
||||
&Budget::standard(),
|
||||
)
|
||||
.unwrap();
|
||||
let tiles = library("engine/cfb_tile_norm.ll");
|
||||
let tile = FunctionDescriptor::new(tiles.function("cfb_tn_write4").unwrap());
|
||||
let mut descriptor = TileRenderPipelineDescriptor::new(StageSource::Function(tile));
|
||||
descriptor.color_attachment_formats[0] = Some(PixelFormat::RGBA8Unorm);
|
||||
let tile = compile
|
||||
.compile_tile_pipeline(&descriptor, &Budget::standard())
|
||||
.unwrap();
|
||||
(compute, tile)
|
||||
}
|
||||
|
||||
/// A render variant of `pipeline`: its stages and pipeline, as its making and binds announce them.
|
||||
fn render_variant(pipeline: &RenderPipeline) -> (&[StageModule], CompiledPipeline<'_>) {
|
||||
(&pipeline.stages, CompiledPipeline::Render(pipeline))
|
||||
}
|
||||
|
||||
/// A compute or tile variant of `pipeline`: its stage and pipeline, as its making and binds
|
||||
/// announce them.
|
||||
fn kernel_variant(pipeline: &ComputePipeline) -> (&[StageModule], CompiledPipeline<'_>) {
|
||||
(
|
||||
std::slice::from_ref(&pipeline.stage),
|
||||
CompiledPipeline::Kernel(pipeline),
|
||||
)
|
||||
}
|
||||
|
||||
/// The notices of `kind` the sink heard, each's object and reason.
|
||||
fn of_kind(heard: &Heard, kind: Degradation) -> Vec<(String, String)> {
|
||||
lock(heard)
|
||||
.iter()
|
||||
.filter(|(k, _, _)| *k == kind)
|
||||
.map(|(_, object, reason)| (object.clone(), reason.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_variant_fitted_while_its_base_was_not_still_announces() {
|
||||
let kind = Degradation::ExactFormsOverCompilerLimit;
|
||||
let (device, heard) = listening(BTreeSet::new());
|
||||
let (base, fit) = pipelines(&device);
|
||||
// The base variant's making: no form dropped, nothing of the kind.
|
||||
device.degrade_pipeline(CompiledPipeline::Render(&base), Occurrence::Made);
|
||||
assert!(of_kind(&heard, kind).is_empty(), "the base announced it");
|
||||
// Another variant's making, its pipeline fitted: announced, naming the forms dropped.
|
||||
device.degrade_pipeline(CompiledPipeline::Render(&fit), Occurrence::Made);
|
||||
let said = of_kind(&heard, kind);
|
||||
assert_eq!(said.len(), 1, "{said:?}");
|
||||
let (object, reason) = &said[0];
|
||||
assert_eq!(object, "a render pipeline state");
|
||||
assert!(
|
||||
reason.contains("exact NaN and minimum and maximum"),
|
||||
"{reason}"
|
||||
);
|
||||
// Once per device: a later fitted variant adds no second notice.
|
||||
device.degrade_pipeline(CompiledPipeline::Render(&fit), Occurrence::Made);
|
||||
assert_eq!(of_kind(&heard, kind).len(), 1);
|
||||
|
||||
// A device asking for the kind at every occurrence: the fitted variant's kinds hold it, and each
|
||||
// bind's notices carry it, where the base's hold none of it; its making announces nothing.
|
||||
let (each, heard) = listening(BTreeSet::from([kind]));
|
||||
let (base, fit) = pipelines(&each);
|
||||
let (base, fit) = (render_variant(&base), render_variant(&fit));
|
||||
each.degrade_pipeline(fit.1, Occurrence::Made);
|
||||
assert!(of_kind(&heard, kind).is_empty(), "announced at the making");
|
||||
assert!(each.binds_each(&Kinds::of(fit.0, fit.1)));
|
||||
assert!(!each.binds_each(&Kinds::of(base.0, base.1)));
|
||||
for _ in 0..2 {
|
||||
let notices = each.bound_notices(fit, &[]);
|
||||
let kinds: Vec<Degradation> = notices.iter().map(|(k, _)| *k).collect();
|
||||
assert_eq!(kinds, [kind], "a bind of the fitted variant");
|
||||
}
|
||||
assert!(each
|
||||
.bound_notices(base, &[])
|
||||
.iter()
|
||||
.all(|(k, _)| *k != kind));
|
||||
}
|
||||
|
||||
/// A mesh render, compute or tile render state's fitted variant announces the kind as a vertex
|
||||
/// and fragment state's does, naming its own state's kind, read from its pipeline's structure:
|
||||
/// at its making (a compute variant's too, which `pipeline/mod.rs` makes), and at each bind on a
|
||||
/// device asking for the kind at every occurrence, where its unfitted base announces nothing of
|
||||
/// it.
|
||||
#[test]
|
||||
fn every_kind_of_fitted_pipeline_announces_its_state_kind() {
|
||||
let kind = Degradation::ExactFormsOverCompilerLimit;
|
||||
// A compute variant's making: announced, as a compute pipeline state's.
|
||||
let (device, heard) = listening(BTreeSet::new());
|
||||
let (compute, _) = kernel_pipelines(&device);
|
||||
device.degrade_pipeline(CompiledPipeline::Kernel(&compute), Occurrence::Made);
|
||||
assert!(of_kind(&heard, kind).is_empty(), "the base announced it");
|
||||
let fit = kernel_fit(&compute);
|
||||
device.degrade_pipeline(CompiledPipeline::Kernel(&fit), Occurrence::Made);
|
||||
let said = of_kind(&heard, kind);
|
||||
assert_eq!(said.len(), 1, "{said:?}");
|
||||
assert_eq!(said[0].0, "a compute pipeline state");
|
||||
assert!(
|
||||
said[0].1.contains("exact NaN and minimum and maximum"),
|
||||
"{said:?}"
|
||||
);
|
||||
|
||||
// Each kind's bind, on a device asking for the kind at every occurrence.
|
||||
let (each, _) = listening(BTreeSet::from([kind]));
|
||||
let (render, _) = pipelines(&each);
|
||||
let mesh = mesh_pipeline(&each);
|
||||
let (compute, tile) = kernel_pipelines(&each);
|
||||
let (render_fitted, mesh_fitted) = (render_fit(&render), render_fit(&mesh));
|
||||
let (compute_fitted, tile_fitted) = (kernel_fit(&compute), kernel_fit(&tile));
|
||||
let cases = [
|
||||
(
|
||||
"a render pipeline state",
|
||||
render_variant(&render),
|
||||
render_variant(&render_fitted),
|
||||
),
|
||||
(
|
||||
"a mesh render pipeline state",
|
||||
render_variant(&mesh),
|
||||
render_variant(&mesh_fitted),
|
||||
),
|
||||
(
|
||||
"a compute pipeline state",
|
||||
kernel_variant(&compute),
|
||||
kernel_variant(&compute_fitted),
|
||||
),
|
||||
(
|
||||
"a tile render pipeline state",
|
||||
kernel_variant(&tile),
|
||||
kernel_variant(&tile_fitted),
|
||||
),
|
||||
];
|
||||
for (object, base, fit) in cases {
|
||||
assert!(each.binds_each(&Kinds::of(fit.0, fit.1)), "{object}");
|
||||
let notices = each.bound_notices(fit, &[]);
|
||||
let named: Vec<&str> = notices
|
||||
.iter()
|
||||
.filter(|(k, _)| *k == kind)
|
||||
.filter_map(|(_, message)| Some(message.degradation.as_ref()?.object.as_str()))
|
||||
.collect();
|
||||
assert_eq!(named, [object], "a bind of the fitted variant");
|
||||
assert!(
|
||||
each.bound_notices(base, &[])
|
||||
.iter()
|
||||
.all(|(k, _)| *k != kind),
|
||||
"{object}: its base"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,6 @@ mod fences;
|
||||
mod fill_value;
|
||||
mod first_moves;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod fitted_variant_notice;
|
||||
mod framebuffer_fetch;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod freed_memory;
|
||||
|
||||
@@ -146,9 +146,7 @@
|
||||
//! consumer's shaders: they stay on the hosts the guest data rule allows and are never committed.
|
||||
|
||||
use metal2vulkan::bind::SamplerDescriptor;
|
||||
use metal2vulkan::device::{
|
||||
DevicePolicy,
|
||||
};
|
||||
use metal2vulkan::device::DevicePolicy;
|
||||
use metal2vulkan::metal::state::DepthStencilDescriptor;
|
||||
use metal2vulkan::metal::CompareFunction;
|
||||
use metal2vulkan::metal::{
|
||||
@@ -312,11 +310,7 @@ fn policy(options: &BTreeMap<String, String>) -> Result<DevicePolicy, String> {
|
||||
for name in names.split(',').filter(|name| !name.is_empty()) {
|
||||
match name {
|
||||
"exact-answers" => policy = policy.exact_answers(),
|
||||
_ => {
|
||||
return Err(format!(
|
||||
"--policy {name:?}: exact-answers"
|
||||
))
|
||||
}
|
||||
_ => return Err(format!("--policy {name:?}: exact-answers")),
|
||||
}
|
||||
}
|
||||
Ok(policy)
|
||||
|
||||
@@ -63,9 +63,7 @@
|
||||
//! `provoking_mesh` ([`PROVOKING`]),
|
||||
//! render pipeline states whose draws run a synthesized geometry stage in `barycentric_weights`
|
||||
//! ([`SYNTHESIZED_GEOMETRY`]), tessellated draws emulated on a device without
|
||||
//! `tessellationShader` in `patches` ([`EMULATED_TESSELLATION`]), render and compute pipeline
|
||||
//! states whose exact forms a stage past the device's compiler word bound dropped here
|
||||
//! ([`EXACT_FORMS_OVER_LIMIT`]),
|
||||
//! `tessellationShader` in `patches` ([`EMULATED_TESSELLATION`]),
|
||||
//! vertex-stage reads in place of bytes a fragment stage of the pass wrote in `pass_start_reads`
|
||||
//! ([`IN_PLACE_VERTEX_READS`]) and a vertex stage's write of bytes one wrote there
|
||||
//! ([`FRAGMENTS_BEFORE_GEOMETRY`]), constant biases of 16-bit unorm depths the device converts
|
||||
@@ -244,11 +242,9 @@ use metal2vulkan::metal::{
|
||||
use metal2vulkan::pipeline::MeshPipelineDescriptor;
|
||||
use metal2vulkan::pipeline::PipelineLayout;
|
||||
use metal2vulkan::pipeline::StageModule;
|
||||
use metal2vulkan::pipeline::{
|
||||
ColorAttachmentDescriptor, RenderPipelineDescriptor, Stage, StageSource,
|
||||
};
|
||||
use metal2vulkan::pipeline::{ComputePipelineDescriptor, FunctionDescriptor, Reconvergence};
|
||||
use metal2vulkan::pipeline::{PrecisionNote, SlotRef, SpecKey};
|
||||
use metal2vulkan::pipeline::{RenderPipelineDescriptor, Stage, StageSource};
|
||||
use metal2vulkan::vk::DriverId;
|
||||
use metal2vulkan::vk::ResolveModeFlags as Mode;
|
||||
use metal2vulkan::Budget;
|
||||
@@ -261,7 +257,6 @@ use metal2vulkan_runtime::{
|
||||
StorageMode, StoreAction, TextureDescriptor,
|
||||
};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
/// The longest a command buffer here may take.
|
||||
@@ -578,7 +573,6 @@ fn every_kind_has_a_site_a_lane_test_takes() {
|
||||
&UNSIZED_POINTS,
|
||||
&SYNTHESIZED_GEOMETRY,
|
||||
&EMULATED_TESSELLATION,
|
||||
&EXACT_FORMS_OVER_LIMIT,
|
||||
&GROUPED,
|
||||
&WORD_PAST_BUFFER,
|
||||
&XR_RESOLVE,
|
||||
@@ -664,86 +658,6 @@ fn moltenvk_argument_buffers_are_announced_where_unread_and_refused_off() {
|
||||
assert_eq!(off.take(), Vec::new(), "the validation layer reported");
|
||||
}
|
||||
|
||||
/// The kind a pipeline state takes where a stage of its translation, with the device's exact
|
||||
/// forms, is longer than the device's compiler word bound, and the translation dropped exact
|
||||
/// forms to fit it ([`exact_forms_past_the_compiler_bound_are_announced_exactly_there`]).
|
||||
const EXACT_FORMS_OVER_LIMIT: [Degradation; 1] = [Degradation::ExactFormsOverCompilerLimit];
|
||||
|
||||
/// A render pipeline state, and a compute pipeline state, announces [`EXACT_FORMS_OVER_LIMIT`]
|
||||
/// exactly where a stage of its translation with the lane's exact forms
|
||||
/// (`runtime_lane::validated_options`) is longer than the device's compiler word bound
|
||||
/// (`DeviceProfile::module_word_bound`: ANV's, `None` elsewhere). No owned fixture's stage reaches
|
||||
/// ANV's bound, so no venue announces it today; each checks the rule on its own device, with the
|
||||
/// owned `runtime_examples` render pipeline and kernel. The runtime's own tests
|
||||
/// (`fitted_variant_notice`) take the announcement of a fitted variant of every kind of state,
|
||||
/// and the translator's (`pipeline::compile::fit`) the fit of every kind of pipeline.
|
||||
#[test]
|
||||
fn exact_forms_past_the_compiler_bound_are_announced_exactly_there() {
|
||||
on_device(|device, messages| {
|
||||
let ll = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("fixtures/public/examples/runtime_examples.ll");
|
||||
let library = device
|
||||
.new_library_with_air(&llvm_assemble(&ll).unwrap())
|
||||
.unwrap();
|
||||
let function = |name| {
|
||||
library
|
||||
.new_function_with_name(name)
|
||||
.unwrap()
|
||||
.function_descriptor()
|
||||
};
|
||||
let mut descriptor =
|
||||
RenderPipelineDescriptor::new(StageSource::Function(function("colored_vertex")));
|
||||
descriptor.fragment = Some(StageSource::Function(function("colored_fragment")));
|
||||
descriptor.color_attachments[0] =
|
||||
Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm));
|
||||
let compile = device.compile_device();
|
||||
let bound = compile.profile().module_word_bound();
|
||||
// The notices a state's creation made, against whether its longest stage passes the bound.
|
||||
let check = |what: &str, longest: usize| {
|
||||
let past = bound.is_some_and(|bound| longest > bound as usize);
|
||||
let announced = counts(&messages.take_notices())
|
||||
.get(&Degradation::ExactFormsOverCompilerLimit)
|
||||
.copied()
|
||||
.unwrap_or(0);
|
||||
eprintln!(
|
||||
"{}: {what}: longest stage {longest} words, compiler word bound {bound:?}",
|
||||
device.name()
|
||||
);
|
||||
assert_eq!(
|
||||
announced,
|
||||
usize::from(past),
|
||||
"{what}: {:?} exactly past the bound",
|
||||
EXACT_FORMS_OVER_LIMIT
|
||||
);
|
||||
};
|
||||
let compiled = compile
|
||||
.compile_render_pipeline(&descriptor, &Budget::standard())
|
||||
.unwrap();
|
||||
let longest = compiled
|
||||
.stages
|
||||
.iter()
|
||||
.map(|stage| stage.spirv.len())
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
let _state = device
|
||||
.new_render_pipeline_state(&descriptor, &PipelineOptions::default())
|
||||
.unwrap();
|
||||
check("render", longest);
|
||||
let kernel =
|
||||
ComputePipelineDescriptor::new(StageSource::Function(function("scale_and_offset")));
|
||||
let longest = compile
|
||||
.compile_compute_pipeline(&kernel, &Budget::standard())
|
||||
.unwrap()
|
||||
.stage
|
||||
.spirv
|
||||
.len();
|
||||
let _state = device
|
||||
.new_compute_pipeline_state(&kernel, &PipelineOptions::default())
|
||||
.unwrap();
|
||||
check("compute", longest);
|
||||
});
|
||||
}
|
||||
|
||||
/// The kind an anisotropy past the device's largest takes
|
||||
/// ([`an_anisotropy_past_the_devices_largest_is_announced_once`]).
|
||||
const CAPPED_ANISOTROPY: [Degradation; 1] = [Degradation::CappedAnisotropy];
|
||||
|
||||
-1
@@ -1267,7 +1267,6 @@ codec_enum! {
|
||||
MovableStorageWrites { early_variant },
|
||||
SynthesizedGeometry { weights, layer, viewport },
|
||||
ObjectThreadgroupArena { static_bytes, payload },
|
||||
ExactFormsOverCompilerLimit {},
|
||||
MergedDraws,
|
||||
QuadPrimitiveIds,
|
||||
PrivateList,
|
||||
|
||||
@@ -12,9 +12,7 @@ use crate::device::description::{
|
||||
};
|
||||
use crate::device::function_storage;
|
||||
use crate::device::metal::MetalDeviceProperties;
|
||||
use crate::device::policy::{
|
||||
ContainmentPolicy, DevicePolicy,
|
||||
};
|
||||
use crate::device::policy::{ContainmentPolicy, DevicePolicy};
|
||||
use crate::device::profile::{
|
||||
BufferAccess, Containment, CubeGradientRoute, CubeGradients, DescriptorCaps, DeviceProfile,
|
||||
DriverWorkaround, EnabledCaps, FloatFunctions, FormatTable, FragmentCaps, GuestIsolation,
|
||||
@@ -51,10 +49,6 @@ struct DeviceInner {
|
||||
/// The description's allocation sizes, which the Metal-facing `maxBufferLength` and the
|
||||
/// runtime's heap sizes read; not a profile field, as above.
|
||||
allocation: AllocationLimits,
|
||||
/// The description the device was made from, kept so a compile over a device's compiler word
|
||||
/// bound can rebuild the device under a reduced policy (`Device::fit_render_variant` and the
|
||||
/// other kinds' fits); not a profile field, as above.
|
||||
description: DeviceDescription,
|
||||
}
|
||||
|
||||
impl Device {
|
||||
@@ -125,7 +119,6 @@ impl Device {
|
||||
robust_buffer_access_update_after_bind: desc.robust_buffer_access_update_after_bind,
|
||||
generated_commands: desc.generated_commands,
|
||||
allocation: desc.allocation,
|
||||
description: desc,
|
||||
})))
|
||||
}
|
||||
|
||||
@@ -151,13 +144,6 @@ impl Device {
|
||||
&self.0.policy
|
||||
}
|
||||
|
||||
/// The description the device was made from, for a compile that rebuilds the device under a
|
||||
/// reduced policy to fit a compiler word bound (`Device::fit_render_variant` and the other
|
||||
/// kinds' fits).
|
||||
pub(crate) fn description(&self) -> &DeviceDescription {
|
||||
&self.0.description
|
||||
}
|
||||
|
||||
/// The description's `robustBufferAccessUpdateAfterBind`.
|
||||
pub(crate) fn robust_buffer_access_update_after_bind(&self) -> bool {
|
||||
self.0.robust_buffer_access_update_after_bind
|
||||
|
||||
@@ -259,6 +259,5 @@ pub fn mechanism(fact: &RuntimeFact, profile: &DeviceProfile) -> Mechanism {
|
||||
RuntimeFact::SynthesizedGeometry { .. } => Mechanism::None,
|
||||
// The pipeline's exact forms were dropped to fit the device's compiler word bound; the
|
||||
// consumer announces it, and the reduced stages carry their own notes.
|
||||
RuntimeFact::ExactFormsOverCompilerLimit { .. } => Mechanism::None,
|
||||
}
|
||||
}
|
||||
@@ -219,22 +219,6 @@ impl DeviceProfile {
|
||||
&self.fields.workarounds
|
||||
}
|
||||
|
||||
/// The stage-module word count a pipeline's largest stage must fit for this device, where its
|
||||
/// driver faults compiling a module past it
|
||||
/// ([`DriverWorkaround::RegisterAllocatorOverflowsLargeModules`]); `None` where no such bound
|
||||
/// is measured. A compile of any pipeline kind over the bound retranslates with the consumer's
|
||||
/// exact forms dropped to fit
|
||||
/// ([`Device::fit_render_variant`](crate::device::Device::fit_render_variant),
|
||||
/// [`fit_mesh_variant`](crate::device::Device::fit_mesh_variant),
|
||||
/// [`fit_compute_pipeline`](crate::device::Device::fit_compute_pipeline),
|
||||
/// [`fit_tile_pipeline`](crate::device::Device::fit_tile_pipeline)).
|
||||
pub fn module_word_bound(&self) -> Option<u32> {
|
||||
self.fields
|
||||
.workarounds
|
||||
.contains(&DriverWorkaround::RegisterAllocatorOverflowsLargeModules)
|
||||
.then_some(REGISTER_ALLOCATOR_MODULE_WORD_BOUND)
|
||||
}
|
||||
|
||||
/// Whether the profile takes the driver deviation `deviation` (`device::driver_facts`): its
|
||||
/// driver is measured with it on the device's GPU, so the translation relies on it. A
|
||||
/// profile that does not take it compiles the conservative route the deviation's
|
||||
@@ -1144,13 +1128,6 @@ pub struct FormatTable {
|
||||
pub formats: BTreeMap<vk::Format, BTreeSet<FormatUsage>>,
|
||||
}
|
||||
|
||||
/// The stage-module word bound for a device whose driver faults compiling a module past it
|
||||
/// ([`DriverWorkaround::RegisterAllocatorOverflowsLargeModules`], ANV's register allocator):
|
||||
/// its overflow is a 32-bit triangular pair index, and 400,000 words sits below the smallest
|
||||
/// module observed to fault with margin. [`DeviceProfile::module_word_bound`] returns it where the
|
||||
/// workaround is taken.
|
||||
pub(crate) const REGISTER_ALLOCATOR_MODULE_WORD_BOUND: u32 = 400_000;
|
||||
|
||||
/// A typed driver workaround: a defect of the driver measured on it, which changes a leaf
|
||||
/// encoding or refuses the construct the driver runs wrong ([`Needs::DriverDefect`]), never the
|
||||
/// pointer model or a semantic; or a measured answer of the driver's that the specifications allow
|
||||
@@ -1424,27 +1401,15 @@ pub enum DriverWorkaround {
|
||||
/// there (`link::tessellation::note_evaluation_stage`).
|
||||
TessellatorNotMetals,
|
||||
/// The driver's shader compiler faults creating a pipeline from a stage module past a word
|
||||
/// bound, so a module the consumer's exact forms grow beyond it is retranslated with those
|
||||
/// forms made native ([`DeviceProfile::module_word_bound`]): the one
|
||||
/// workaround that changes no leaf encoding and refuses nothing, but bounds a module's size by
|
||||
/// trading exactness for the fast form, device by device.
|
||||
///
|
||||
/// ANV (`VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA`), Mesa 26.2.4, faults in its `brw` backend's
|
||||
/// register allocator: a bitset indexed by the triangular pair index `n·(n-1)/2` of two live
|
||||
/// ranges, computed in 32 bits, which overflows once the function's live-range count is large
|
||||
/// and reads outside the allocation (`libvulkan_intel.so`, `SEGV_ACCERR`). Measured on the
|
||||
/// Iris Xe of RPL-P with a synthetic compute module whose one function keeps a sliding window
|
||||
/// of `W` live `float` values: `vkCreateComputePipelines` compiled `W` = 50,000 (750,107 words)
|
||||
/// and faulted `W` = 60,000, 65,000 and 92,000 (900,107 words and up); and with the consumer's
|
||||
/// fragments, where a module carrying exact sampling alone (455,402 words) compiled but one
|
||||
/// carrying every exact answer faulted. The bound is 400,000 words, below the smallest module
|
||||
/// observed to combine enough exact forms to fault, with margin: a module above it is reduced,
|
||||
/// since the fault point for a module's register
|
||||
/// pressure is not known exactly and the fault is unrecoverable, where the reduction is a
|
||||
/// logged precision note. Keyed on the driver whatever its GPU, whatever its release, in
|
||||
/// `device::derive`; a release that fixes the overflow keeps it until a measurement raises or
|
||||
/// removes the bound, and the fast-default form of every module stays below it. The consumer
|
||||
/// announces each reduced pipeline (`RuntimeFact::ExactFormsOverCompilerLimit`).
|
||||
/// bound. ANV (`VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA`), Mesa 26.2.4, faults in its `brw`
|
||||
/// backend's register allocator: a bitset indexed by the triangular pair index `n·(n-1)/2` of
|
||||
/// two live ranges, computed in 32 bits, which overflows once the function's live-range count
|
||||
/// is large and reads outside the allocation (`libvulkan_intel.so`, `SEGV_ACCERR`). Measured on
|
||||
/// the Iris Xe of RPL-P with a synthetic compute module whose one function keeps a sliding
|
||||
/// window of `W` live `float` values: `vkCreateComputePipelines` compiled `W` = 50,000 (750,107
|
||||
/// words) and faulted `W` = 60,000, 65,000 and 92,000 (900,107 words and up). Keyed on the
|
||||
/// driver whatever its GPU, whatever its release, in `device::derive`. Recorded on the profile
|
||||
/// alone: it changes no leaf encoding, refuses nothing and reduces no module.
|
||||
RegisterAllocatorOverflowsLargeModules,
|
||||
}
|
||||
|
||||
|
||||
@@ -263,8 +263,6 @@ fn every_fact() -> Vec<RuntimeFact> {
|
||||
static_bytes: 0,
|
||||
payload: None,
|
||||
},
|
||||
RuntimeFact::ExactFormsOverCompilerLimit {
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -356,13 +354,12 @@ fn variant(f: &RuntimeFact) -> usize {
|
||||
RuntimeFact::MovableStorageWrites { .. } => 83,
|
||||
RuntimeFact::SynthesizedGeometry { .. } => 84,
|
||||
RuntimeFact::ObjectThreadgroupArena { .. } => 85,
|
||||
RuntimeFact::ExactFormsOverCompilerLimit { .. } => 86,
|
||||
RuntimeFact::WordInputMerge { .. } => 87,
|
||||
RuntimeFact::ReplayBindings => 88,
|
||||
RuntimeFact::MergedDraws => 89,
|
||||
RuntimeFact::QuadPrimitiveIds => 90,
|
||||
RuntimeFact::RotatedWeights => 91,
|
||||
RuntimeFact::PrivateList => 92,
|
||||
RuntimeFact::PrivateList => 86,
|
||||
RuntimeFact::MeshLastFirst => 71,
|
||||
RuntimeFact::YCbCrInPlace { .. } => 65,
|
||||
}
|
||||
@@ -372,7 +369,7 @@ fn variant(f: &RuntimeFact) -> usize {
|
||||
fn mechanism_is_total_over_every_fact_and_profile() {
|
||||
let facts = every_fact();
|
||||
let covered: std::collections::BTreeSet<usize> = facts.iter().map(variant).collect();
|
||||
assert_eq!(covered, (0..93).collect(), "every_fact misses a variant");
|
||||
assert_eq!(covered, (0..92).collect(), "every_fact misses a variant");
|
||||
for (stem, _) in super::committed_profiles() {
|
||||
let dev = device(&stem);
|
||||
let p = dev.profile();
|
||||
@@ -510,8 +507,7 @@ fn mechanism_is_total_over_every_fact_and_profile() {
|
||||
RuntimeFact::AliasedImageblock { .. } => Mechanism::None,
|
||||
RuntimeFact::CallStackDepth { .. }
|
||||
| RuntimeFact::AbsentArgumentRead { .. }
|
||||
| RuntimeFact::SynthesizedGeometry { .. }
|
||||
| RuntimeFact::ExactFormsOverCompilerLimit { .. } => Mechanism::None,
|
||||
| RuntimeFact::SynthesizedGeometry { .. } => Mechanism::None,
|
||||
};
|
||||
assert_eq!(m, expected, "{stem}: {fact:?}");
|
||||
}
|
||||
|
||||
@@ -1095,12 +1095,11 @@ fn uniform_reads_outpace_storage_reads_on_anv_and_narrow_lavapipe() {
|
||||
}
|
||||
|
||||
/// `DriverWorkaround::RegisterAllocatorOverflowsLargeModules` is keyed on ANV, whatever its GPU
|
||||
/// and release; every committed ANV profile carries it and gives a 400,000-word module bound, and
|
||||
/// no other profile carries it or bounds a module. The UHD 770's description under RADV or
|
||||
/// NVIDIA's driver loses it.
|
||||
/// and release; every committed ANV profile carries it, and no other profile does. The UHD 770's
|
||||
/// description under RADV or NVIDIA's driver loses it.
|
||||
#[test]
|
||||
fn register_allocator_overflow_is_keyed_on_anv() {
|
||||
use crate::device::profile::{DriverWorkaround, REGISTER_ALLOCATOR_MODULE_WORD_BOUND};
|
||||
use crate::device::profile::DriverWorkaround;
|
||||
let fact = DriverWorkaround::RegisterAllocatorOverflowsLargeModules;
|
||||
let profile_of = |desc: &DeviceDescription| {
|
||||
Device::new(desc.clone(), DevicePolicy::default())
|
||||
@@ -1113,11 +1112,6 @@ fn register_allocator_overflow_is_keyed_on_anv() {
|
||||
let anv = desc.driver_id == Some(vk::DriverId::INTEL_OPEN_SOURCE_MESA);
|
||||
let p = profile_of(&desc);
|
||||
assert_eq!(p.workarounds().contains(&fact), anv, "{stem}");
|
||||
assert_eq!(
|
||||
p.module_word_bound(),
|
||||
anv.then_some(REGISTER_ALLOCATOR_MODULE_WORD_BOUND),
|
||||
"{stem}"
|
||||
);
|
||||
}
|
||||
let mut desc = profile("intel-irisxe-rplp-anv");
|
||||
assert!(profile_of(&desc).workarounds().contains(&fact));
|
||||
@@ -1125,7 +1119,6 @@ fn register_allocator_overflow_is_keyed_on_anv() {
|
||||
desc.driver_id = Some(other);
|
||||
let p = profile_of(&desc);
|
||||
assert!(!p.workarounds().contains(&fact), "{other:?}");
|
||||
assert_eq!(p.module_word_bound(), None, "{other:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1084,45 +1084,13 @@ impl At {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`footprint`] of a sample whose plain data is `at`.
|
||||
pub(super) fn footprint_from(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
t: &Tys,
|
||||
at: &At,
|
||||
(si, image): (SValue, CombinedImage),
|
||||
bits: Bits,
|
||||
taps: &Taps<'_>,
|
||||
) -> BResult<(Footprint, SValue)> {
|
||||
let img = fb.image(si)?;
|
||||
let zero_u = fb.u32_const(0)?;
|
||||
let zero_u = value(fb, zero_u)?;
|
||||
// A level's taps read its size, and Metal's offset rule the base level's too where an offset
|
||||
// moves them.
|
||||
let offset = at.offset.is_some() || taps.offset.is_some_and(|o| o.iter().any(|o| *o != 0));
|
||||
let fp = match taps.level {
|
||||
Some(level) => {
|
||||
let size = fb.query(ImageQuery::SizeLod(level), img)?;
|
||||
let base = match offset {
|
||||
true => Some(fb.query(ImageQuery::SizeLod(zero_u), img)?),
|
||||
false => None,
|
||||
};
|
||||
footprint_at(fb, t, at, (size, base, image), bits, taps)?
|
||||
}
|
||||
None => {
|
||||
let size = fb.query(ImageQuery::SizeLod(zero_u), img)?;
|
||||
footprint_at(fb, t, at, (size, None, image), bits, taps)?
|
||||
}
|
||||
};
|
||||
Ok((fp, img))
|
||||
}
|
||||
|
||||
/// The footprint over `taps` of a sample at plane coordinate `coord` (and array layer `layer`)
|
||||
/// of image `img` (image facts `image`) at the taps' level, whose taps are fetched from `img`, the
|
||||
/// border color seen through the channels of the format's treatment `bits`: an extended-range
|
||||
/// texture's emulated sample (`super::extended`), which reads its slot's own image, its offset
|
||||
/// (its taps' constant one, or a sampling routine's call's value `offset`, as [`At::offset`])
|
||||
/// placed by the slot's `SpecKey::OffsetBaseAxes` tests `parent` where it reads them (a level's
|
||||
/// taps read its size, and the offset rule the base level's too, as [`footprint_from`]'s).
|
||||
/// taps read its size, and the offset rule the base level's too).
|
||||
pub(super) fn footprint_of_image(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
t: &Tys,
|
||||
|
||||
@@ -1210,23 +1210,6 @@ pub(super) fn sampled_value(
|
||||
let mut ops = ImageOperands::default();
|
||||
offset_operands(cx, fb, offset, s.lanes, &mut ops)?;
|
||||
let component = *component;
|
||||
// A `half` gather whose taps the shader fetches, where the bound format is a
|
||||
// half-float one: component `component` of each tap's texel, else the device's gather.
|
||||
// It observes no residency, so the word is 0.
|
||||
if let (Some((p, texture)), Source::Combined(key)) = (
|
||||
s.fetched.as_ref().and_then(|p| Some((p, p.image.slot()?))),
|
||||
s.source,
|
||||
) {
|
||||
let x = super::fetched::branch(
|
||||
cx,
|
||||
fb,
|
||||
(s, key),
|
||||
(texture, &p.fetch),
|
||||
image,
|
||||
&|fb, si| fb.gather(si, coord, component, &ops),
|
||||
)?;
|
||||
return texel_value(cx, fb, s, image, (x, TexelOrigin::Computed), None);
|
||||
}
|
||||
let dref = match dref {
|
||||
Some(r) => Some(reference(cx, fb, s, *r)?),
|
||||
None => None,
|
||||
@@ -1279,12 +1262,6 @@ pub(super) fn sampled_value(
|
||||
};
|
||||
// Metal's value of texels in a sparse image's block that holds no mapped tile.
|
||||
let texel = unmapped_value(cx, fb, s, texel, named)?;
|
||||
// A heap texture's `half` gather: the texels the shader fetches where the class its handle
|
||||
// carries is the half-float one, else the device's.
|
||||
let texel = match s.fetched.as_ref().filter(|p| p.image.slot().is_none()) {
|
||||
Some(p) => super::fetched::heap(cx, fb, s, image, p, texel)?,
|
||||
None => texel,
|
||||
};
|
||||
let texel = live_or_zero(fb, live, texel)?;
|
||||
texel_value(cx, fb, s, image, (texel, TexelOrigin::Image), word)
|
||||
}
|
||||
|
||||
@@ -1,456 +0,0 @@
|
||||
//! A `half` gather's texels the shader fetches itself, where Metal's footprint is known
|
||||
//! ([`Plain`]).
|
||||
//!
|
||||
//! **Why.** Under the NaN switch Metal's gather hands back a 16-bit float texel's own NaN; a
|
||||
//! device's gather need not (NVIDIA's hands back every NaN as `0x7fffffff`), and its fetch does
|
||||
//! where its read does ([`half_gather`]).
|
||||
//!
|
||||
//! **How.** The shader fetches a gather's four taps at Metal's quantized position
|
||||
//! (`TapBase::Quantized`) of the base level, in gather order (`texels`), through
|
||||
//! `bicubic::footprint`. Each tap is addressed as the sampler's axes say, and a border axis's
|
||||
//! outside tap reads the border color as the bound format holds it: a constexpr sampler's
|
||||
//! addressing is the function's own ([`FetchAddress::Modes`]), a runtime sampler's its slot's
|
||||
//! word's, read in the function ([`FetchAddress::Word`]), and an argument buffer's sampler's its
|
||||
//! table entry's word's ([`FetchAddress::Entry`]). The fetch sits behind the slot's `TexelFormat`
|
||||
//! specialization (`branch`): the half-float class takes the fetches, and any other the device's
|
||||
//! own gather. A heap texture's gather fetches where the class its handle carries is the
|
||||
//! half-float one ([`heap`]), after the device's access. An arm of a switch-at-use keeps the
|
||||
//! device's read through a word, so its arms share one emulation.
|
||||
//!
|
||||
//! **The device reads the texels** elsewhere: a dynamic offset, an observed residency, a raw sRGB
|
||||
//! view.
|
||||
|
||||
use crate::air::abi::Coordinates;
|
||||
use crate::air::intrinsics::{ImageDim, ImageShape};
|
||||
use crate::error::Error;
|
||||
use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::SelectCx;
|
||||
use crate::lower::texture::{ImageRef, TexelConv, TexelForm};
|
||||
use crate::metal::bicubic::BicubicTexels;
|
||||
use crate::pipeline::sym::SamplerRef;
|
||||
use crate::spirv::builder::constructs::{ArmEnd, ArmFn, Merged};
|
||||
use crate::spirv::builder::FunctionBuilder;
|
||||
use crate::spirv::error::BResult;
|
||||
use crate::spirv::ids::Value as SValue;
|
||||
use crate::spirv::ir::Constant;
|
||||
|
||||
use super::bicubic::{
|
||||
flag, footprint_from, footprint_on, value, Addressing, At, Bits, Footprint, Tap, TapAddress,
|
||||
TapBase, Taps, Texels, Tys,
|
||||
};
|
||||
use super::linear::LinearImage;
|
||||
use super::{BindingKey, CombinedImage, Offset, Pixel, SampleOp, Sampling, Source};
|
||||
|
||||
/// How the shader fetches the texels of a gather (module docs): how its taps are addressed, and
|
||||
/// Metal's constant texel offset.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Fetch {
|
||||
pub address: FetchAddress,
|
||||
pub offset: Option<Vec<i32>>,
|
||||
}
|
||||
|
||||
/// How a fetch addresses its taps (`bicubic::Addressing`).
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum FetchAddress {
|
||||
/// A constexpr sampler's: each plane axis's addressing, the sampler's border color (which
|
||||
/// every axis clamping to zero or to the border reads), and whether the coordinate is in
|
||||
/// pixels.
|
||||
Modes {
|
||||
address: Vec<TapAddress>,
|
||||
border: crate::air::abi::BorderColor,
|
||||
pixel: bool,
|
||||
},
|
||||
/// Runtime sampler slot `sampler`'s word on `axes` plane axes: each axis's address mode, the
|
||||
/// border color and the coordinates, read in the function from the slot's `SamplerState`
|
||||
/// specialization.
|
||||
Word { sampler: u32, axes: u8 },
|
||||
/// An argument buffer's sampler's word on `axes` plane axes, as [`FetchAddress::Word`], read
|
||||
/// in the function from the sampler's table entry.
|
||||
Entry { axes: u8 },
|
||||
}
|
||||
|
||||
/// The estimated words of a fetch's footprint beyond its taps: the size query, each of two axes'
|
||||
/// position ([`super::position::POSITION_WORDS`]) and base, the layer's clamp, the border texel,
|
||||
/// and the format's branch and the device's arm.
|
||||
pub(super) const FETCH_WORDS: u32 = 2 * super::position::POSITION_WORDS + 320;
|
||||
|
||||
/// The estimated words of one fetched tap: its index under its addressing on each axis, the fetch,
|
||||
/// the border's select, and the component's extraction.
|
||||
pub(super) const FETCH_TAP_WORDS: u32 = 96;
|
||||
|
||||
impl Fetch {
|
||||
/// The estimated words of fetching a gather's four texels: the footprint and each tap, and for
|
||||
/// a runtime sampler's word the word's tests and each axis's position and taps under every
|
||||
/// mode (`linear::WORD_WORDS`), and Metal's offset rule on each axis a constant offset moves
|
||||
/// (`position::OFFSET_RULE_WORDS`).
|
||||
pub fn words(&self) -> u32 {
|
||||
let word = match &self.address {
|
||||
FetchAddress::Modes { .. } => 0,
|
||||
FetchAddress::Word { axes, .. } | FetchAddress::Entry { axes } => {
|
||||
super::linear::WORD_WORDS
|
||||
+ u32::from(*axes)
|
||||
* (super::position::MODE_POSITION_WORDS + 2 * super::linear::WORD_TAP_WORDS)
|
||||
}
|
||||
};
|
||||
let offset = self
|
||||
.offset
|
||||
.as_deref()
|
||||
.map_or(0, |o| o.iter().filter(|o| **o != 0).count() as u32)
|
||||
* super::position::OFFSET_RULE_WORDS;
|
||||
FETCH_WORDS + 4 * FETCH_TAP_WORDS + word + offset
|
||||
}
|
||||
|
||||
/// The taps of a gather fetched as `self` says from the base level, a runtime sampler's
|
||||
/// addressed by its word `word` (a `u32`): a footprint of two taps per axis from Metal's
|
||||
/// quantized position. `None` for a word-addressed fetch without its word.
|
||||
pub(super) fn taps(&self, word: Option<SValue>) -> Option<Taps<'_>> {
|
||||
let addressing = match (&self.address, word) {
|
||||
(
|
||||
FetchAddress::Modes {
|
||||
address,
|
||||
border,
|
||||
pixel,
|
||||
},
|
||||
_,
|
||||
) => Addressing::Modes {
|
||||
address,
|
||||
border: *border,
|
||||
pixel: *pixel,
|
||||
},
|
||||
(FetchAddress::Word { axes, .. } | FetchAddress::Entry { axes }, Some(word)) => {
|
||||
Addressing::Word {
|
||||
word,
|
||||
axes: usize::from(*axes),
|
||||
}
|
||||
}
|
||||
(FetchAddress::Word { .. } | FetchAddress::Entry { .. }, None) => return None,
|
||||
};
|
||||
Some(Taps {
|
||||
addressing,
|
||||
offset: self.offset.as_deref(),
|
||||
span: &[0, 1],
|
||||
base: TapBase::Quantized,
|
||||
level: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A `half` gather whose texels the shader fetches (module docs): where its texel class is read
|
||||
/// (a texture slot's `TexelFormat` specialization, or the class a heap texture's handle carries),
|
||||
/// and how the fetches are made.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Plain {
|
||||
pub image: LinearImage,
|
||||
pub fetch: Fetch,
|
||||
}
|
||||
|
||||
impl Plain {
|
||||
/// The estimated words of fetching the texels ([`Fetch::words`]), and a heap texture's class
|
||||
/// from its handle, its element loaded again in the fetch's arm, an argument buffer's sampler's
|
||||
/// word from its entry, and the branch (`linear::HEAP_WORDS`).
|
||||
pub fn words(&self) -> u32 {
|
||||
let heap = match (self.image, &self.fetch.address) {
|
||||
(LinearImage::Slot(_), _) => 0,
|
||||
(LinearImage::Heap, FetchAddress::Entry { .. }) => {
|
||||
super::linear::HEAP_WORDS + crate::memory::handles::ENTRY_FIELD_WORDS
|
||||
}
|
||||
(LinearImage::Heap, _) => super::linear::HEAP_WORDS,
|
||||
};
|
||||
self.fetch.words() + heap
|
||||
}
|
||||
}
|
||||
|
||||
/// The fetch of `op`, a gather without comparison of a 2D texture or array with texel form `form`
|
||||
/// (module docs, [`half_gather`]), of `image` (shape `shape`) through `stat` (or, where
|
||||
/// `argument`, its argument buffer's sampler): through a constexpr sampler addressed by its modes,
|
||||
/// through a runtime or argument buffer's sampler by its word. A heap texture's fetch reads the
|
||||
/// class its handle carries.
|
||||
pub(super) fn select(
|
||||
cx: &mut SelectCx<'_>,
|
||||
op: &SampleOp,
|
||||
form: Option<TexelForm>,
|
||||
(stat, argument): (Option<(SamplerRef, Coordinates)>, bool),
|
||||
(image, shape): (ImageRef, ImageShape),
|
||||
) -> Result<Option<Plain>, Error> {
|
||||
if !half_gather(cx, op, form) || shape.dim != ImageDim::D2 || shape.ms {
|
||||
return Ok(None);
|
||||
}
|
||||
let SampleOp::Gather { offset, .. } = op else {
|
||||
return Ok(None);
|
||||
};
|
||||
let offset = match offset {
|
||||
None => None,
|
||||
Some(Offset::Const(k)) => Some(k.clone()),
|
||||
Some(Offset::Dynamic(..)) => return Ok(None),
|
||||
};
|
||||
let address = match (stat.map(|(r, _)| r), argument) {
|
||||
(Some(SamplerRef::Constexpr(words)), _) => {
|
||||
let s = super::state_of(words)?;
|
||||
FetchAddress::Modes {
|
||||
address: [s.address_s, s.address_t]
|
||||
.into_iter()
|
||||
.map(super::position::address)
|
||||
.collect(),
|
||||
border: s.border_color,
|
||||
pixel: s.coordinates == Coordinates::Pixel,
|
||||
}
|
||||
}
|
||||
(Some(SamplerRef::Slot(sampler)), _) => FetchAddress::Word { sampler, axes: 2 },
|
||||
(None, true) => FetchAddress::Entry { axes: 2 },
|
||||
(None, false) => return Ok(None),
|
||||
};
|
||||
let image = match image {
|
||||
ImageRef::Slot(n) => LinearImage::Slot(n),
|
||||
ImageRef::Heap { .. } => LinearImage::Heap,
|
||||
};
|
||||
cx.families.access.heap_class |= image == LinearImage::Heap;
|
||||
Ok(Some(Plain {
|
||||
image,
|
||||
fetch: Fetch { address, offset },
|
||||
}))
|
||||
}
|
||||
|
||||
/// Whether `op` is a gather with a `half` result whose texels the shader fetches where the bound
|
||||
/// class is a 16-bit float one: where the NaN switch asks for Metal's NaN
|
||||
/// (`NanMinMaxPolicy::Exact`, the profile's `TexelNanRoute::Metal`) on a device without Metal's
|
||||
/// own sampler. Metal's gather hands back a 16-bit float texel's own NaN; a device's gather need
|
||||
/// not (NVIDIA's hands back every NaN as `0x7fffffff`), and its fetch does
|
||||
/// where its read does.
|
||||
fn half_gather(cx: &SelectCx<'_>, op: &SampleOp, form: Option<TexelForm>) -> bool {
|
||||
use crate::device::profile::TexelNanRoute;
|
||||
use crate::device::requirements::VkProperty;
|
||||
matches!(op, SampleOp::Gather { dref: None, .. })
|
||||
&& form.map(|f| f.conv) == Some(TexelConv::F16)
|
||||
&& cx.profile.fields().texel_nans == TexelNanRoute::Metal
|
||||
&& !cx
|
||||
.profile
|
||||
.fields()
|
||||
.enabled
|
||||
.properties
|
||||
.contains(&VkProperty::MetalSampler)
|
||||
}
|
||||
|
||||
/// The value of gather `s` from the texels fetched as `f` says through combined binding `key` (one
|
||||
/// without comparison), where the slot `texture`'s `TexelFormat` specialization states the
|
||||
/// half-float class: [`plain_value`] of [`texels`]' texels. Elsewhere `device`'s access of the
|
||||
/// binding's sampled image makes it. Each arm makes the sampled image it reads, so once a device
|
||||
/// specializes the module the other arm is dead.
|
||||
pub(super) fn branch(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
(s, key): (&Sampling, BindingKey),
|
||||
(texture, f): (u32, &Fetch),
|
||||
image: CombinedImage,
|
||||
device: &dyn Fn(&mut FunctionBuilder<'_>, SValue) -> BResult<SValue>,
|
||||
) -> BResult<SValue> {
|
||||
let Some(spec) = crate::lower::texture::texel_format_const(cx, texture) else {
|
||||
return Err(cx.fail(format!(
|
||||
"texture slot {texture} has no `TexelFormat` specialization"
|
||||
)));
|
||||
};
|
||||
let Some(&(binding, _)) = cx.decl.families.sampler.combined.get(&key) else {
|
||||
return Err(cx.fail(format!("combined binding {key:?} is not declared")));
|
||||
};
|
||||
// A runtime sampler's word, which addresses its taps.
|
||||
let word = match &f.address {
|
||||
FetchAddress::Word { sampler, .. } => {
|
||||
Some(super::emit::sampler_word(cx, fb, Pixel::Spec(*sampler))?)
|
||||
}
|
||||
FetchAddress::Modes { .. } => None,
|
||||
FetchAddress::Entry { .. } => {
|
||||
return Err(cx.fail("a slot's fetch addressed by an argument buffer's sampler"))
|
||||
}
|
||||
};
|
||||
let t = Tys::new(fb)?;
|
||||
let measured = flag(fb, &t, spec, BicubicTexels::HALF)?;
|
||||
let t = &t;
|
||||
let fetch: ArmFn<'_, EmitCx<'_>> = Box::new(move |fb, cx| {
|
||||
let si = binding.sampled_image(fb)?;
|
||||
let Some(taps) = f.taps(word) else {
|
||||
return Err(cx.fail("a word-addressed fetch without its word"));
|
||||
};
|
||||
let x = texels(cx, fb, t, s, (si, image), Bits::Spec(spec), &taps)?;
|
||||
Ok(ArmEnd::FallThrough(vec![plain_value(fb, s, &x)?]))
|
||||
});
|
||||
let read: ArmFn<'_, EmitCx<'_>> = Box::new(move |fb, _| {
|
||||
let si = binding.sampled_image(fb)?;
|
||||
let x = device(fb, si)?;
|
||||
Ok(ArmEnd::FallThrough(vec![x]))
|
||||
});
|
||||
let Merged(merged) = fb.if_(cx, measured, fetch, Some(read))?;
|
||||
match merged[..] {
|
||||
[x] => Ok(x),
|
||||
_ => Err(cx.fail("fetched texels' branch without its value")),
|
||||
}
|
||||
}
|
||||
|
||||
/// The value of fetch `p` of heap texture gather `s` (image facts `image`): `device`, the device's
|
||||
/// gather already made, in uniform control flow; and where the class the texture's handle carries
|
||||
/// is the half-float one, a component of the four texels the shader fetches from the element as a
|
||||
/// slot of that class would ([`texels`]). The fetch arm holds fetches alone, so a divergent handle
|
||||
/// puts no gather in divergent flow.
|
||||
pub(super) fn heap(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
s: &Sampling,
|
||||
image: CombinedImage,
|
||||
p: &Plain,
|
||||
device: SValue,
|
||||
) -> BResult<SValue> {
|
||||
let handle = match s.source {
|
||||
Source::Heap { handle, .. } | Source::HeapSampler { handle, .. } => handle,
|
||||
Source::Combined(_) => return Err(cx.fail("a heap texture's fetch of a slot")),
|
||||
};
|
||||
let t = Tys::new(fb)?;
|
||||
let h = cx.operand(fb, handle)?;
|
||||
let bits = Bits::Value(crate::lower::texture::heap_texel_class(cx, fb, h)?);
|
||||
let word = match (&p.fetch.address, super::emit::word_pixel(s)) {
|
||||
(FetchAddress::Modes { .. }, _) => None,
|
||||
(_, Some(pixel)) => Some(super::emit::sampler_word(cx, fb, pixel)?),
|
||||
(_, None) => return Err(cx.fail("a word-addressed heap fetch without its word")),
|
||||
};
|
||||
let take = bits.test(fb, &t, BicubicTexels::HALF)?;
|
||||
let t = &t;
|
||||
let fetch: ArmFn<'_, EmitCx<'_>> = Box::new(move |fb, cx| {
|
||||
let (si, _, _) = super::emit::sampled_image(cx, fb, s.source)?;
|
||||
let Some(taps) = p.fetch.taps(word) else {
|
||||
return Err(cx.fail("a word-addressed heap fetch without its word"));
|
||||
};
|
||||
let x = texels(cx, fb, t, s, (si, image), bits, &taps)?;
|
||||
Ok(ArmEnd::FallThrough(vec![plain_value(fb, s, &x)?]))
|
||||
});
|
||||
let kept: ArmFn<'_, EmitCx<'_>> = Box::new(move |_, _| Ok(ArmEnd::FallThrough(vec![device])));
|
||||
let Merged(merged) = fb.if_(cx, take, fetch, Some(kept))?;
|
||||
match merged[..] {
|
||||
[x] => Ok(x),
|
||||
_ => Err(cx.fail("a heap texture's fetch without its texel")),
|
||||
}
|
||||
}
|
||||
|
||||
/// The value of gather `s` of its fetched `texels`, as the device's gather returns it: its
|
||||
/// component of each of its four (a `vec4`).
|
||||
pub(super) fn plain_value(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
s: &Sampling,
|
||||
texels: &[SValue],
|
||||
) -> BResult<SValue> {
|
||||
let SampleOp::Gather { component, .. } = s.op else {
|
||||
return Err(super::bicubic::missing_tap());
|
||||
};
|
||||
let vec4 = Tys::new(fb)?.vec4;
|
||||
let mut parts = Vec::with_capacity(texels.len());
|
||||
for &texel in texels {
|
||||
parts.push(fb.composite_extract(texel, &[component])?);
|
||||
}
|
||||
fb.composite_construct(vec4, &parts)
|
||||
}
|
||||
|
||||
/// The `vec4` texels of `s` at `taps` (any [`Addressing`]: a constexpr sampler's, or a runtime
|
||||
/// sampler's word) from sampled image `si` (image facts `image`), a border tap's texel the border
|
||||
/// color seen through format bits `bits` (the slot's `TexelFormat` specialization, or a heap
|
||||
/// element's class's): a gather's four in gather order, `x` `(i, j + 1)`, `y` `(i + 1, j + 1)`,
|
||||
/// `z` `(i + 1, j)` and `w` `(i, j)`, of a span of two taps per axis; else the one of a span of
|
||||
/// one tap per axis.
|
||||
pub(super) fn texels(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
t: &Tys,
|
||||
s: &Sampling,
|
||||
(si, image): (SValue, CombinedImage),
|
||||
bits: Bits,
|
||||
taps: &Taps<'_>,
|
||||
) -> BResult<Vec<SValue>> {
|
||||
let at = At::of(cx, fb, s)?;
|
||||
texels_at(cx, fb, t, &at, (si, image), bits, taps)
|
||||
}
|
||||
|
||||
/// [`texels`] of a sampling whose plain data is `at`.
|
||||
fn texels_at(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
t: &Tys,
|
||||
at: &At,
|
||||
(si, image): (SValue, CombinedImage),
|
||||
bits: Bits,
|
||||
taps: &Taps<'_>,
|
||||
) -> BResult<Vec<SValue>> {
|
||||
let (fp, img) = footprint_from(fb, t, at, (si, image), bits, taps)?;
|
||||
let Some(sites) = sites(&fp) else {
|
||||
return Err(cx.fail("fetched texels' footprint without its taps"));
|
||||
};
|
||||
let mut out = Vec::with_capacity(sites.len());
|
||||
for site in &sites {
|
||||
out.push(fp.fetch(fb, img, site)?);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The sites [`texels`] fetches over footprint `fp`: a span of two taps per axis's four in gather
|
||||
/// order, `(i, j + 1)`, `(i + 1, j + 1)`, `(i + 1, j)` and `(i, j)`, else a span of one tap per
|
||||
/// axis's one; `None` for another footprint.
|
||||
fn sites(fp: &Footprint) -> Option<Vec<Vec<Tap>>> {
|
||||
let rows: Vec<&[Tap]> = fp.axes.iter().map(|(_, row)| &row[..]).collect();
|
||||
match &rows[..] {
|
||||
[&[s0, s1], &[t0, t1]] => {
|
||||
Some(vec![vec![s0, t1], vec![s1, t1], vec![s1, t0], vec![s0, t0]])
|
||||
}
|
||||
_ => rows
|
||||
.iter()
|
||||
.map(|r| match **r {
|
||||
[tap] => Some(tap),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Option<Vec<Tap>>>()
|
||||
.map(|site| vec![site]),
|
||||
}
|
||||
}
|
||||
|
||||
/// The shared form of fetch `p` of gather `s` in a switch-at-use (SEMANTICS 1012;
|
||||
/// `shared::shared_value`): the taps once on the named candidate's level-0 size `size` (image facts
|
||||
/// `image`), fetched in one dispatch over the candidates `c` from each arm's image where the named
|
||||
/// format's bits `bits` are of the half-float class, and [`plain_value`] of their texels;
|
||||
/// elsewhere `device`'s access, dispatched the same way from each arm's sampled image.
|
||||
pub(super) fn emit_shared(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
s: &Sampling,
|
||||
(size, image): (SValue, CombinedImage),
|
||||
p: &Plain,
|
||||
(bits, c): (SValue, &super::Candidates<'_>),
|
||||
device: &dyn Fn(&mut FunctionBuilder<'_>, SValue) -> BResult<SValue>,
|
||||
) -> BResult<SValue> {
|
||||
let t = Tys::new(fb)?;
|
||||
let bits = Bits::Value(bits);
|
||||
let measured = bits.test(fb, &t, BicubicTexels::HALF)?;
|
||||
let t = &t;
|
||||
let fetch: ArmFn<'_, EmitCx<'_>> = Box::new(move |fb, cx| {
|
||||
let Some(taps) = p.fetch.taps(None) else {
|
||||
return Err(cx.fail("a shared fetch without its taps"));
|
||||
};
|
||||
let fp = footprint_on(cx, fb, t, s, (size, image), bits, &taps)?;
|
||||
let Some(sites) = sites(&fp) else {
|
||||
return Err(cx.fail("a shared fetch's footprint without its taps"));
|
||||
};
|
||||
let x = Texels::Candidates(c).fetch(cx, fb, (t, &fp), &sites, &|_, _, v| Ok(v))?;
|
||||
Ok(ArmEnd::FallThrough(vec![plain_value(fb, s, &x)?]))
|
||||
});
|
||||
let read: ArmFn<'_, EmitCx<'_>> = Box::new(move |fb, cx| {
|
||||
let read = |cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, a: &Sampling| {
|
||||
let si = c.sampled_image(cx, fb, a)?;
|
||||
Ok(vec![device(fb, si)?])
|
||||
};
|
||||
let null = |_: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>| {
|
||||
let z = fb.module().constant(Constant::Null { ty: t.vec4 })?;
|
||||
Ok(vec![value(fb, z)?])
|
||||
};
|
||||
let [x] = c.each(cx, fb, &read, &null)?[..] else {
|
||||
return Err(cx.fail("a shared fetch's device texel"));
|
||||
};
|
||||
Ok(ArmEnd::FallThrough(vec![x]))
|
||||
});
|
||||
let Merged(merged) = fb.if_(cx, measured, fetch, Some(read))?;
|
||||
match merged[..] {
|
||||
[x] => Ok(x),
|
||||
_ => Err(cx.fail("a shared fetch's branch without its texel")),
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
//! What the device-sampled filters share with the emulated ones the device has no form for
|
||||
//! (`extended`, `heap_raw`, `in_place`, `bicubic`): the texture whose bound format's class a
|
||||
//! filter reads ([`LinearImage`]), the census words of a filter's footprint and of a runtime
|
||||
//! sampler's word, the rule of an axis whose two taps read one texel ([`merged`]), the samplers
|
||||
//! (`extended`, `heap_raw`, `in_place`, `bicubic`): the census words of a filter's footprint and
|
||||
//! of a runtime sampler's word, the rule of an axis whose two taps read one texel ([`merged`]), the samplers
|
||||
//! that read one texel of one level ([`unfiltered`], [`word_filters`]), and the note of a filtered
|
||||
//! sample that Metal's own sampler answers otherwise than Metal filters the format bound there
|
||||
//! ([`filter_note`]).
|
||||
@@ -37,26 +36,6 @@ use crate::spirv::ir::BinOp;
|
||||
use super::bicubic::{scalar, value, Tap, Tys};
|
||||
use super::SampleOp;
|
||||
|
||||
/// The texture whose bound format's treatment a sample reads.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum LinearImage {
|
||||
/// Texture slot `n`, whose `TexelFormat` specialization states the bound format's class.
|
||||
Slot(u32),
|
||||
/// The sample's heap texture, whose handle carries its class's index
|
||||
/// (`memory::handles::HANDLE_TEXEL_CLASS`).
|
||||
Heap,
|
||||
}
|
||||
|
||||
impl LinearImage {
|
||||
/// The texture slot, or `None` for a heap texture.
|
||||
pub(super) fn slot(self) -> Option<u32> {
|
||||
match self {
|
||||
LinearImage::Slot(n) => Some(n),
|
||||
LinearImage::Heap => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The census words a runtime sampler's emulation adds once per sample: the word's filter test and
|
||||
/// each axis's mode test (`reaches_word`), each axis's mode and the coordinates' extraction, the
|
||||
/// border color's selection, and a 3D sample's reflected-axis test, with their constants.
|
||||
@@ -67,11 +46,6 @@ pub(super) const WORD_WORDS: u32 = 448;
|
||||
/// test.
|
||||
pub(super) const WORD_TAP_WORDS: u32 = 160;
|
||||
|
||||
/// The census words a heap texture's emulation adds: its class's read
|
||||
/// (`texture::HEAP_CLASS_WORDS`), its element's access chain, load, and sampled image in the
|
||||
/// emulation's arm, and the branch and its merge, with their constants.
|
||||
pub(super) const HEAP_WORDS: u32 = crate::lower::texture::HEAP_CLASS_WORDS + 64;
|
||||
|
||||
/// [`Linear::words`] of a 2D sample.
|
||||
pub(super) const PLANE_WORDS: u32 = 576;
|
||||
|
||||
|
||||
@@ -149,7 +149,6 @@ mod constexpr;
|
||||
mod emit;
|
||||
pub mod extended;
|
||||
pub mod face;
|
||||
pub mod fetched;
|
||||
pub mod footprint;
|
||||
pub mod heap_raw;
|
||||
pub mod in_place;
|
||||
@@ -605,10 +604,6 @@ pub struct Sampling {
|
||||
/// before anything reads it, as Metal's texture unit reads it, a bit per axis
|
||||
/// ([`position::subnormal_flush`]).
|
||||
pub flush_subnormals: u8,
|
||||
/// A `half` gather whose texels the shader fetches where the slot is bound in (or a heap
|
||||
/// texture's handle carries the class of) a half-float format ([`fetched`]); the device's
|
||||
/// gather answers otherwise.
|
||||
pub fetched: Option<fetched::Plain>,
|
||||
/// It reads a cube by a direction, whose ties between major axes the device is handed broken
|
||||
/// as Metal breaks them ([`face`]).
|
||||
pub cube: bool,
|
||||
@@ -744,16 +739,13 @@ impl Sampling {
|
||||
/// The shape the arms of a switch-at-use share where it emulates once (SEMANTICS 1012,
|
||||
/// `sampler::shared_value`): this sampling with its texture slot and sampler taken out, where
|
||||
/// it is an emulation on a combined binding whose residency the function does not observe: a
|
||||
/// bicubic sample, fetched texels, or a snapped gather or sample but a runtime sampler's word
|
||||
/// snap. Arms of one shape differ only in the binding they read: each emulation states its
|
||||
/// bicubic sample, or a snapped gather or sample but a runtime sampler's word snap. Arms of one shape differ only in the binding they read: each emulation states its
|
||||
/// sampler's addressing in its own fields, and the device's access stays in each arm.
|
||||
pub(crate) fn shared_shape(&self) -> Option<Sampling> {
|
||||
let Source::Combined(key) = self.source else {
|
||||
return None;
|
||||
};
|
||||
// A plain fetch of the base level fetches its taps on the named candidate's facts once; one of another level
|
||||
// reads in each arm's own branch, its level clamped into the arm's own levels. A texture of
|
||||
// another class's words are handed back as declared in each arm's own access. A swizzled
|
||||
// A texture of another class's words are handed back as declared in each arm's own access. A swizzled
|
||||
// slot's sampling swizzles under its own slot's swizzle; an offset placed by a slot's
|
||||
// `OffsetBaseAxes` is placed by its own slot's.
|
||||
if self.residency
|
||||
@@ -770,10 +762,6 @@ impl Sampling {
|
||||
sampler: SamplerRef::Slot(0),
|
||||
..key
|
||||
});
|
||||
if let Some(p) = &mut k.fetched {
|
||||
p.image = linear::LinearImage::Slot(0);
|
||||
return Some(k);
|
||||
}
|
||||
match (&mut k.op, &k.snap) {
|
||||
(SampleOp::Bicubic(b), None) => b.texture = 0,
|
||||
// A runtime sampler's word snap alone is no emulation to share.
|
||||
@@ -812,13 +800,7 @@ impl Sampling {
|
||||
const ARM: u32 = 48;
|
||||
// A read in an arm: the fetch or access with its operands, and its merge operands.
|
||||
const READ: u32 = 16;
|
||||
// The facts' merge operands of the lanes Metal reads as constants, eight lane tests, where
|
||||
// a plain fetch takes them.
|
||||
let lanes = match (self.unmapped, self.fetched.is_some()) {
|
||||
(Unmapped::Constants | Unmapped::Named, true) => 8 * 2,
|
||||
_ => 0,
|
||||
};
|
||||
let facts = ARM + 3 * READ + lanes;
|
||||
let facts = ARM + 3 * READ;
|
||||
let half = match self.texel {
|
||||
Some(f) if f.conv == crate::lower::texture::TexelConv::F16 => {
|
||||
crate::lower::texture::half::CALL_WORDS.max(f.read_words())
|
||||
@@ -826,14 +808,6 @@ impl Sampling {
|
||||
Some(f) => f.read_words(),
|
||||
None => 0,
|
||||
};
|
||||
// A plain fetch's dispatch of its taps, and the device's access in a second.
|
||||
if self.fetched.is_some() {
|
||||
let taps = match self.op {
|
||||
SampleOp::Gather { .. } => 4,
|
||||
_ => 1,
|
||||
};
|
||||
return facts + (ARM + taps * READ) + ARM + READ + half;
|
||||
}
|
||||
match (&self.op, &self.snap) {
|
||||
(SampleOp::Bicubic(b), _) => {
|
||||
// A 1D texture's one row of two taps, else each row of four and the half sum's
|
||||
@@ -1070,7 +1044,6 @@ impl Sampling {
|
||||
.as_ref()
|
||||
.filter(|_| offset.is_some())
|
||||
.map_or(0, position::Snap::offset_words)
|
||||
+ self.fetched.as_ref().map_or(0, |p| p.words())
|
||||
+ match self.flush_subnormals {
|
||||
0 => 0,
|
||||
_ => position::FLUSH_WORDS,
|
||||
@@ -1138,19 +1111,8 @@ pub struct RuntimeSlot {
|
||||
/// An extended-range or heap raw texture's emulated filter reads it: the function reads its
|
||||
/// word's filter, coordinates, address modes, and border color.
|
||||
pub linear: bool,
|
||||
/// A sample whose texel the shader fetches where its word reads one texel reads it
|
||||
/// (`fetched::word_reach`): the function reads its word's filter.
|
||||
pub filters: bool,
|
||||
/// Texels the shader fetches by its word (`fetched::FetchAddress::Word`): the function reads
|
||||
/// its word's coordinates, its plane axes' address modes, and its border color.
|
||||
pub fetched: bool,
|
||||
/// A 3D texture's texel the shader fetches by its word (`fetched::FetchAddress::Word`): the
|
||||
/// function reads its word's `r` address mode too.
|
||||
pub fetched_depth: bool,
|
||||
/// A fetched texel is read from the level its word reads (`fetched::FetchLevel::Word`), or an
|
||||
/// extended-range sample reads its levels by its word
|
||||
/// (`extended::Level::Word`): the function reads its word's mip filter and the levels its
|
||||
/// clamp leaves.
|
||||
/// An extended-range sample reads its levels by its word (`extended::Level::Word`): the function
|
||||
/// reads its word's mip filter and the levels its clamp leaves.
|
||||
pub fetch_levels: bool,
|
||||
/// A cube's explicit gradients take their footprint by its word (`CubeFootprint::Word`): the
|
||||
/// function reads whether its word is anisotropic.
|
||||
@@ -1201,27 +1163,13 @@ impl RuntimeSlot {
|
||||
cells: _,
|
||||
min_level: _,
|
||||
linear,
|
||||
filters,
|
||||
fetched,
|
||||
fetched_depth,
|
||||
fetch_levels,
|
||||
anisotropy,
|
||||
gathers,
|
||||
texels,
|
||||
emulated,
|
||||
} = *self;
|
||||
![
|
||||
linear,
|
||||
filters,
|
||||
fetched,
|
||||
fetched_depth,
|
||||
fetch_levels,
|
||||
anisotropy,
|
||||
emulated,
|
||||
gathers,
|
||||
texels,
|
||||
]
|
||||
.contains(&true)
|
||||
![linear, fetch_levels, anisotropy, emulated, gathers, texels].contains(&true)
|
||||
}
|
||||
|
||||
/// The fields the slot's uses read of its word, without [`SamplerWord::PIXEL_GATED`].
|
||||
@@ -1236,18 +1184,6 @@ impl RuntimeSlot {
|
||||
if self.linear {
|
||||
fields |= SamplerWord::LINEAR_STATE;
|
||||
}
|
||||
if self.filters {
|
||||
fields |= SamplerWord::LINEAR_FILTER;
|
||||
}
|
||||
if self.fetched {
|
||||
fields |= SamplerWord::PIXEL_COORDINATES
|
||||
| SamplerWord::ADDRESS[0]
|
||||
| SamplerWord::ADDRESS[1]
|
||||
| SamplerWord::BORDER;
|
||||
}
|
||||
if self.fetched_depth {
|
||||
fields |= SamplerWord::ADDRESS[2];
|
||||
}
|
||||
if self.fetch_levels {
|
||||
fields |= SamplerWord::MIP_FILTER | SamplerWord::LEVEL_MIN | SamplerWord::LEVEL_MAX;
|
||||
}
|
||||
@@ -1774,9 +1710,6 @@ pub fn select_param(cx: &mut SelectCx<'_>, b: &ParamBinding) -> Result<(), Error
|
||||
coordinates: false,
|
||||
nearest: false,
|
||||
linear: false,
|
||||
filters: false,
|
||||
fetched: false,
|
||||
fetched_depth: false,
|
||||
fetch_levels: false,
|
||||
anisotropy: false,
|
||||
gathers: false,
|
||||
|
||||
@@ -1581,9 +1581,8 @@ fn select_extended(
|
||||
/// Select sampling call `inst` (sample, gather, or LOD query) of `image` (a texture slot, or a
|
||||
/// heap element) through sampler `sampler` (a static one, or an argument buffer's heap sampler),
|
||||
/// decoded as `t`. `arm` is set for an arm of a switch-at-use: with `Some(true)`, a fragment
|
||||
/// implicit-LOD sample reads the gradients its switch hoisted; and a texel the device reads through
|
||||
/// a runtime sampler's word stays its read (no `fetched::FetchAddress::Word` fetch), so that the
|
||||
/// arms share one emulation (SEMANTICS 1012, `Sampling::shared_shape`).
|
||||
/// implicit-LOD sample reads the gradients its switch hoisted, so that the arms share one emulation
|
||||
/// (SEMANTICS 1012, `Sampling::shared_shape`).
|
||||
fn select_one(
|
||||
cx: &mut SelectCx<'_>,
|
||||
call: Call<'_>,
|
||||
@@ -2163,10 +2162,6 @@ fn select_one(
|
||||
// footprint cell. The note holds where none of them runs and the device's filter reads the
|
||||
// scaled coordinate, as `pixel_note` says. An argument buffer's sampler records a note of its
|
||||
// own, which the runtime announces only while a bound state can need it.
|
||||
let argument = match sampler {
|
||||
SamplerArg::Heap(h) => Some(h),
|
||||
SamplerArg::Static(..) => None,
|
||||
};
|
||||
let when = pixel_note(&op, pixel, (centred, integer), snap.as_ref());
|
||||
let note = match pixel {
|
||||
Pixel::Heap(_) => PrecisionNote::ArgumentPixelSamplerScaling,
|
||||
@@ -2176,34 +2171,6 @@ fn select_one(
|
||||
if let SampleOp::Bicubic(b) = &mut op {
|
||||
b.raw = raw;
|
||||
}
|
||||
// A bicubic sample rounds its `half` result exactly, keeping denormals, as a raw texel's decode
|
||||
// does; another converts its texel by the bound format's class. A `half` gather's texels
|
||||
// fetched where Metal's footprint is known (`fetched::select`).
|
||||
let fetched = match (observed, raw) {
|
||||
(false, false) => {
|
||||
super::fetched::select(cx, &op, form, (stat, argument.is_some()), (image, shape))?
|
||||
.filter(|p| {
|
||||
arm.is_none()
|
||||
|| matches!(p.fetch.address, super::fetched::FetchAddress::Modes { .. })
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
// A runtime sampler's word addresses the fetch: the function reads its coordinates, address
|
||||
// modes and border color.
|
||||
if let Some(super::fetched::Plain {
|
||||
fetch:
|
||||
super::fetched::Fetch {
|
||||
address: super::fetched::FetchAddress::Word { sampler: n, .. },
|
||||
..
|
||||
},
|
||||
..
|
||||
}) = &fetched
|
||||
{
|
||||
if let Some(s) = cx.families.sampler.slots.get_mut(n) {
|
||||
s.fetched = true;
|
||||
}
|
||||
}
|
||||
// Whether the access reads one texel of one level, whose `half` or `float` texel a packed or
|
||||
// normalized class converts from its codes; a runtime sampler's word decides it, which the
|
||||
// slot's specialization then reads.
|
||||
@@ -2233,30 +2200,18 @@ fn select_one(
|
||||
}
|
||||
other => other,
|
||||
};
|
||||
// A heap texture's fetches read its handle's texel class, no slot's format.
|
||||
let by_format = fetched.as_ref().is_some_and(|p| p.image.slot().is_some());
|
||||
// Where a sample's `half` texel is the device's, no conversion declares the slot's class: the
|
||||
// emulation that reads it declares it itself.
|
||||
// A bicubic sample rounds its `half` result exactly, keeping denormals, as a raw texel's decode
|
||||
// does; another `half` access converts its texel: the device's where the device's texel is
|
||||
// the answer, else by the bound format's class (a heap color texture's by the class its
|
||||
// handle carries: the module's routine, called with the class read from the handle).
|
||||
let device = crate::lower::texture::device_texels(cx);
|
||||
if by_format && !raw && half && device {
|
||||
crate::lower::texture::texel_format_spec(cx, image)?;
|
||||
}
|
||||
match (by_format, raw) {
|
||||
(true, true) => crate::lower::texture::texel_format_spec(cx, image)?,
|
||||
(true, false) if !half => crate::lower::texture::texel_format_spec(cx, image)?,
|
||||
// A runtime sampler's emulation of raw codes converts the device's texel on its device
|
||||
// arm alone.
|
||||
(_, false) if half && !matches!(op, SampleOp::Bicubic(_)) => {
|
||||
// A heap color texture's `half` texels convert by the class its handle carries: the
|
||||
// module's routine, called with the class read from the handle.
|
||||
if image.heap() && !shape.depth && !device {
|
||||
cx.families.texture.heap_half = true;
|
||||
cx.families.access.heap_class = true;
|
||||
cx.families.texture.half_families = crate::lower::texture::half_families(cx);
|
||||
}
|
||||
crate::lower::texture::half_texels(cx, image, shape, (one_texel, None), device, m)?
|
||||
if !raw && half && !matches!(op, SampleOp::Bicubic(_)) {
|
||||
if image.heap() && !shape.depth && !device {
|
||||
cx.families.texture.heap_half = true;
|
||||
cx.families.access.heap_class = true;
|
||||
cx.families.texture.half_families = crate::lower::texture::half_families(cx);
|
||||
}
|
||||
_ => {}
|
||||
crate::lower::texture::half_texels(cx, image, shape, (one_texel, None), device, m)?
|
||||
}
|
||||
// A `float` texel that may be one texel's is the device's conversion of its codes: not an sRGB
|
||||
// raw texel's (decoded exactly), a bicubic sample's, or an LOD query's; nor a depth
|
||||
@@ -2395,7 +2350,7 @@ fn select_one(
|
||||
// Metal's anisotropic filter emulated by the device's samples at explicit levels, where it
|
||||
// reaches the sample; the device's anisotropic filter, recorded, where it does not. An
|
||||
// isotropic cube's level too, where no exact path of its own answers it.
|
||||
let answered = snap.is_some() || fetched.is_some() || centred;
|
||||
let answered = snap.is_some() || centred;
|
||||
let anisotropic = super::anisotropic::select(
|
||||
cx,
|
||||
&op,
|
||||
@@ -2448,7 +2403,6 @@ fn select_one(
|
||||
footprint,
|
||||
snap,
|
||||
flush_subnormals,
|
||||
fetched,
|
||||
cube,
|
||||
centred,
|
||||
centre_word,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//! The shared emulation of a switch-at-use (SEMANTICS 1012).
|
||||
//!
|
||||
//! A switch-at-use whose every arm takes the same emulated sampling on its own texture slot
|
||||
//! ([`Sampling::shared_shape`]): a bicubic sample, a snapped gather or sample, or a `half` gather
|
||||
//! whose base-level texels the shader fetches. Emitted per arm, each arm repeats the whole
|
||||
//! ([`Sampling::shared_shape`]): a bicubic sample, or a snapped gather or sample. Emitted per arm, each arm repeats the whole
|
||||
//! emulation (its position, weights, sums, and routine calls), so the switch's words grow with arms × emulation, and so does
|
||||
//! the driver's work once the bound formats make every arm's emulation live (an Intel ANV pipeline
|
||||
//! of 32 such arms took 6 s to create).
|
||||
@@ -11,14 +10,12 @@
|
||||
//! facts, and dispatches only what reads a candidate's own image:
|
||||
//!
|
||||
//! - a facts dispatch, whose arms yield their level-0 size (`OpImageQuerySizeLod` 0), the bound
|
||||
//! format's bits (the slot's `BicubicTexels` or `TexelFormat` specialization) and `true`, and
|
||||
//! format's bits (the slot's `BicubicTexels` specialization) and `true`, and
|
||||
//! whose null arm yields a size of ones, bits 0 and `false`;
|
||||
//! - the emulation on those facts (its footprint, weights and routine calls once), whose taps a
|
||||
//! dispatch reads from each arm's image (the null arm's are zero);
|
||||
//! - a snapped sample's coordinate snapped once on the named size, and the device's access and
|
||||
//! texel conversion in each arm, the null arm yielding the switch's null value;
|
||||
//! - a plain fetch's taps on the named size, fetched in one dispatch where the named format is of
|
||||
//! the class the fetch names, else the device's access (its coordinate snapped once) in another.
|
||||
//! texel conversion in each arm, the null arm yielding the switch's null value.
|
||||
//!
|
||||
//! Where a handle names a candidate the facts are that candidate's, so every value is the one its
|
||||
//! own arm computed; elsewhere the switch's null value is selected. The emulation of a null handle
|
||||
@@ -33,10 +30,10 @@ use crate::spirv::ids::{ConstId, Value as SValue};
|
||||
use crate::spirv::ir::{ConstBits, Constant, ImageOperands, ImageQuery, Type as SType};
|
||||
|
||||
use super::emit::{
|
||||
held_value, layered, offset_operands, op_offset, pixel_coordinates, plane_and_gradients,
|
||||
sample_access, sample_operands, scaled, snap_offsets, texel_value,
|
||||
layered, offset_operands, op_offset, pixel_coordinates, plane_and_gradients, sample_access,
|
||||
sample_operands, scaled, snap_offsets, texel_value,
|
||||
};
|
||||
use super::{Binding, CombinedImage, SampleOp, Sampling, Source, Unmapped};
|
||||
use super::{Binding, CombinedImage, SampleOp, Sampling, Source};
|
||||
|
||||
/// The candidates of a switch-at-use that emulates once: the handles' values dispatched on,
|
||||
/// outermost first, and each arm's case literals and sampling.
|
||||
@@ -97,15 +94,10 @@ fn binding(cx: &mut EmitCx<'_>, a: &Sampling) -> BResult<(Binding, CombinedImage
|
||||
enum Emulation<'a> {
|
||||
Bicubic(&'a super::bicubic::Bicubic),
|
||||
Snap(&'a super::position::Snap),
|
||||
/// A plain fetch of the base level, its device arm snapped where it has a snap.
|
||||
Fetched(&'a super::fetched::Plain),
|
||||
}
|
||||
|
||||
impl<'a> Emulation<'a> {
|
||||
fn of(s: &'a Sampling) -> Option<Emulation<'a>> {
|
||||
if let Some(p) = &s.fetched {
|
||||
return Some(Emulation::Fetched(p));
|
||||
}
|
||||
match (&s.op, &s.snap) {
|
||||
(SampleOp::Bicubic(b), None) => Some(Emulation::Bicubic(b)),
|
||||
(SampleOp::Sample { .. } | SampleOp::Gather { .. }, Some(p)) if !p.by_word() => {
|
||||
@@ -116,16 +108,12 @@ impl<'a> Emulation<'a> {
|
||||
}
|
||||
|
||||
/// The specialization holding the bound format's bits of arm sampling `a`'s slot, where the
|
||||
/// emulation reads them: a bicubic sample's `BicubicTexels`, a fetch's `TexelFormat`.
|
||||
/// emulation reads them: a bicubic sample's `BicubicTexels`.
|
||||
fn bits(self, cx: &mut EmitCx<'_>, a: &Sampling) -> BResult<Option<ConstId>> {
|
||||
let spec = match (self, Emulation::of(a)) {
|
||||
(Emulation::Bicubic(_), Some(Emulation::Bicubic(b))) => {
|
||||
cx.decl.families.sampler.bicubic.get(&b.texture).copied()
|
||||
}
|
||||
(Emulation::Fetched(_), Some(Emulation::Fetched(p))) => p
|
||||
.image
|
||||
.slot()
|
||||
.and_then(|t| crate::lower::texture::texel_format_const(cx, t)),
|
||||
(Emulation::Snap(_), Some(Emulation::Snap(_))) => return Ok(None),
|
||||
_ => return Err(cx.fail("a shared switch's arms of different emulations")),
|
||||
};
|
||||
@@ -162,27 +150,11 @@ pub(crate) fn shared_value(
|
||||
[size, rest @ ..] => (*size, rest),
|
||||
_ => return Err(cx.fail("a shared switch's facts without their sizes")),
|
||||
};
|
||||
let (bits, named, lanes) = match (kind, rest) {
|
||||
(Emulation::Snap(_), &[]) => (None, None, None),
|
||||
(Emulation::Bicubic(_) | Emulation::Fetched(_), &[bits, named]) => {
|
||||
(Some(bits), Some(named), None)
|
||||
}
|
||||
(Emulation::Fetched(_), &[bits, named, c0, c1, c2, c3, o0, o1, o2, o3]) => (
|
||||
Some(bits),
|
||||
Some(named),
|
||||
Some(crate::lower::texture::LaneConstants {
|
||||
constant: [c0, c1, c2, c3],
|
||||
one: [o0, o1, o2, o3],
|
||||
}),
|
||||
),
|
||||
let (bits, named) = match (kind, rest) {
|
||||
(Emulation::Snap(_), &[]) => (None, None),
|
||||
(Emulation::Bicubic(_), &[bits, named]) => (Some(bits), Some(named)),
|
||||
_ => return Err(cx.fail("a shared switch's facts without their values")),
|
||||
};
|
||||
// The lanes Metal reads as constants, by the named candidate's tests: each arm's own conversion
|
||||
// is the shared one, so they are set after it.
|
||||
let constants = |cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, x: SValue| match lanes {
|
||||
Some(tests) => crate::lower::texture::constant_lanes_by(cx, fb, tests, x, None),
|
||||
None => Ok(x),
|
||||
};
|
||||
let x = match (kind, bits) {
|
||||
(Emulation::Bicubic(b), Some(bits)) => {
|
||||
super::bicubic::emit_shared(cx, fb, first, (size, image), b, bits, c)?
|
||||
@@ -190,33 +162,8 @@ pub(crate) fn shared_value(
|
||||
(Emulation::Snap(p), _) => {
|
||||
return snapped(cx, fb, c, (first, p), grads, (size, image), null);
|
||||
}
|
||||
(Emulation::Fetched(p), Some(bits)) => {
|
||||
let x = fetched(cx, fb, c, (first, p), grads, (size, image), bits)?;
|
||||
// The conversion, then the lanes Metal reads as constants by the merged tests, not
|
||||
// the named candidate's own.
|
||||
let x = held_value(
|
||||
cx,
|
||||
fb,
|
||||
first,
|
||||
image,
|
||||
(x, crate::lower::texture::half::TexelOrigin::Computed),
|
||||
)?;
|
||||
let x = constants(cx, fb, x)?;
|
||||
let x = with_word(cx, fb, &first.result, x, None)?;
|
||||
let Some(named) = named else {
|
||||
return Err(cx.fail("a shared fetch without its named test"));
|
||||
};
|
||||
let [n] = null(cx, fb)?[..] else {
|
||||
return Err(cx.fail("a shared switch without its null value"));
|
||||
};
|
||||
return fb.select(named, x, n);
|
||||
}
|
||||
_ => return Err(cx.fail("a shared emulation without its format bits")),
|
||||
};
|
||||
let x = match first.depth {
|
||||
true => x,
|
||||
false => constants(cx, fb, x)?,
|
||||
};
|
||||
let x = with_word(cx, fb, &first.result, x, None)?;
|
||||
let Some(named) = named else {
|
||||
return Err(cx.fail("a shared emulation without its named test"));
|
||||
@@ -228,9 +175,7 @@ pub(crate) fn shared_value(
|
||||
}
|
||||
|
||||
/// The facts dispatch (module docs): each arm's level-0 size, and where `kind` reads them its
|
||||
/// format's bits and `true`, then where the shared value takes the lanes Metal reads
|
||||
/// as constants (`shared_constants`) its slot's eight lane tests (`LaneConstants`); the null arm's
|
||||
/// ones, 0, and `false`.
|
||||
/// format's bits and `true`; the null arm's ones, 0, and `false`.
|
||||
fn facts(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
@@ -265,7 +210,6 @@ fn facts(
|
||||
let yes = scalar(fb, bool_, 1)?;
|
||||
let no = scalar(fb, bool_, 0)?;
|
||||
let with_bits = !matches!(kind, Emulation::Snap(_));
|
||||
let lanes_read = shared_constants(kind, c);
|
||||
let read = |cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, a: &Sampling| {
|
||||
let img = c.image(cx, fb, a)?;
|
||||
let level = fb.module().const_value(zero)?;
|
||||
@@ -274,11 +218,6 @@ fn facts(
|
||||
v.push(fb.module().const_value(bits)?);
|
||||
v.push(fb.module().const_value(yes)?);
|
||||
}
|
||||
if lanes_read {
|
||||
let tests = lane_tests(cx, a)?;
|
||||
v.extend(tests.constant);
|
||||
v.extend(tests.one);
|
||||
}
|
||||
Ok(v)
|
||||
};
|
||||
let null_facts = |_: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>| {
|
||||
@@ -287,10 +226,6 @@ fn facts(
|
||||
v.push(fb.module().const_value(zero)?);
|
||||
v.push(fb.module().const_value(no)?);
|
||||
}
|
||||
if lanes_read {
|
||||
let no = fb.module().const_value(no)?;
|
||||
v.extend([no; 8]);
|
||||
}
|
||||
Ok(v)
|
||||
};
|
||||
c.each(cx, fb, &read, &null_facts)
|
||||
@@ -436,56 +371,3 @@ fn snapped(
|
||||
_ => Err(cx.fail("a shared snapped access without its value")),
|
||||
}
|
||||
}
|
||||
|
||||
/// A shared `half` gather's fetch (module docs): the device's coordinate snapped once on the named
|
||||
/// size where the sampling has a snap, and `fetched::emit_shared`'s fetches of each arm's texels
|
||||
/// where the named format `bits` is of the half-float class, else each arm's device gather of
|
||||
/// component `component`.
|
||||
fn fetched(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
c: &Candidates<'_>,
|
||||
(first, p): (&Sampling, &super::fetched::Plain),
|
||||
grads: Option<(SValue, SValue)>,
|
||||
(size, image): (SValue, CombinedImage),
|
||||
bits: SValue,
|
||||
) -> BResult<SValue> {
|
||||
let ((_, coord), _) =
|
||||
device_coordinate(cx, fb, first, grads, (size, image), first.snap.as_ref())?;
|
||||
let SampleOp::Gather {
|
||||
component,
|
||||
dref: None,
|
||||
offset,
|
||||
} = &first.op
|
||||
else {
|
||||
return Err(cx.fail("a shared fetch without its gather"));
|
||||
};
|
||||
let mut ops = ImageOperands::default();
|
||||
offset_operands(cx, fb, offset, first.lanes, &mut ops)?;
|
||||
let component = *component;
|
||||
let device = |fb: &mut FunctionBuilder<'_>, si: SValue| fb.gather(si, coord, component, &ops);
|
||||
super::fetched::emit_shared(cx, fb, first, (size, image), p, (bits, c), &device)
|
||||
}
|
||||
|
||||
/// Whether the shared value of `kind` over `c` sets the lanes Metal reads as constants by its
|
||||
/// arms' merged lane tests: a plain fetch's, whose arms take them
|
||||
/// ([`Unmapped`]). A snapped access converts each arm's texel in its arm, with its own slot's; a
|
||||
/// bicubic sample's fetches take none.
|
||||
fn shared_constants(kind: Emulation<'_>, c: &Candidates<'_>) -> bool {
|
||||
matches!(kind, Emulation::Fetched(_))
|
||||
&& c.arms.iter().any(|(_, a)| a.unmapped != Unmapped::Device)
|
||||
}
|
||||
|
||||
/// The lane tests of arm sampling `a`'s texture slot.
|
||||
fn lane_tests(cx: &mut EmitCx<'_>, a: &Sampling) -> BResult<crate::lower::texture::LaneConstants> {
|
||||
let Source::Combined(key) = a.source else {
|
||||
return Err(cx.fail("a shared sampling of a heap element"));
|
||||
};
|
||||
match cx.decl.families.texture.constant_lanes.get(&key.texture) {
|
||||
Some(&tests) => Ok(tests),
|
||||
None => Err(cx.fail(format!(
|
||||
"texture slot {} has no constant lanes",
|
||||
key.texture
|
||||
))),
|
||||
}
|
||||
}
|
||||
@@ -1225,11 +1225,6 @@ impl HalfClass {
|
||||
}
|
||||
}
|
||||
|
||||
/// Texture slot `index`'s `TexelFormat` specialization constant, where it declares one.
|
||||
pub(crate) fn texel_format_const(cx: &EmitCx<'_>, index: u32) -> Option<ConstId> {
|
||||
cx.decl.families.texture.half_format.get(&index).copied()
|
||||
}
|
||||
|
||||
/// How the `half` texels of a read, gather, or sample of `image` in form `texel` convert: by the
|
||||
/// bound format's class where the slot takes its `TexelFormat` specialization, else (any other
|
||||
/// result, a heap element, a depth texture) through [`held_texel`].
|
||||
@@ -2546,18 +2541,6 @@ pub(crate) fn constant_lanes(
|
||||
let Some(tests) = cx.decl.families.texture.constant_lanes.get(&index).copied() else {
|
||||
return Err(cx.fail(format!("texture slot {index} has no constant lanes")));
|
||||
};
|
||||
constant_lanes_by(cx, fb, tests, x, gathered)
|
||||
}
|
||||
|
||||
/// [`constant_lanes`] by the lane tests `tests`: a slot's, or the ones a switch's arms merged
|
||||
/// (`sampler::shared_value`).
|
||||
pub(crate) fn constant_lanes_by(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
tests: super::LaneConstants,
|
||||
x: SValue,
|
||||
gathered: Option<u32>,
|
||||
) -> BResult<SValue> {
|
||||
let ty = fb.value_ty(x)?;
|
||||
let elem = match fb.module().types().get(ty)? {
|
||||
SType::Vector { elem, len: 4 } => *elem,
|
||||
|
||||
@@ -111,8 +111,7 @@ pub enum TexelOrigin {
|
||||
/// An image instruction's texel (a read, fetch, sample or gather), or lanes and selections of
|
||||
/// such texels and constants: no arithmetic computes it.
|
||||
Image,
|
||||
/// A value the translation computes from texels (an emulated filter, a comparison, a fetched
|
||||
/// footprint's sum).
|
||||
/// A value the translation computes from texels (an emulated filter's sum).
|
||||
Computed,
|
||||
}
|
||||
|
||||
|
||||
@@ -133,12 +133,11 @@ pub(crate) use absent::absent_arm;
|
||||
pub use absent::ABSENT_ARM;
|
||||
pub use atomic::TexAtomic;
|
||||
pub(crate) use emit::{
|
||||
constant_lanes, constant_lanes_by, dispatch, extended_table, half_class, heap_element,
|
||||
heap_half_class, heap_raw_form, heap_raw_image, live_or_zero, reinterpret, resident_access,
|
||||
rgb9e5_word, slot_image, sparse_spec, srgb_filtered_texel, srgb_raw_tap, srgb_raw_texel,
|
||||
swizzled_float, swizzled_gather, swizzled_held, texel_format_const, tile_map, tiled_word,
|
||||
with_word, NullLeaf, TileLevel, RGB9E5_WORDS, SRGB_FILTERED_WORDS, SRGB_RAW_WORDS,
|
||||
SRGB_TAP_WORDS, SRGB_TEXEL,
|
||||
constant_lanes, dispatch, extended_table, half_class, heap_element, heap_half_class,
|
||||
heap_raw_form, heap_raw_image, live_or_zero, reinterpret, resident_access, rgb9e5_word,
|
||||
slot_image, sparse_spec, srgb_filtered_texel, srgb_raw_tap, srgb_raw_texel, swizzled_float,
|
||||
swizzled_gather, swizzled_held, tile_map, tiled_word, with_word, NullLeaf, TileLevel,
|
||||
RGB9E5_WORDS, SRGB_FILTERED_WORDS, SRGB_RAW_WORDS, SRGB_TAP_WORDS, SRGB_TEXEL,
|
||||
};
|
||||
pub use emit::{emit, held_texel, to_image};
|
||||
pub(crate) use slot::depth_comparison;
|
||||
@@ -733,16 +732,14 @@ impl FamilyStrategy for TextureStrategy {
|
||||
impl TextureStrategy {
|
||||
/// The sampled images of combined bindings this strategy makes: its own sampling's, or its
|
||||
/// switch's arms' (each the static sampling of one binding). Under the separate form each is
|
||||
/// made from the separate texture and sampler. A sampling makes one in its open block, and a
|
||||
/// plain fetch one in each arm of its branch, the fetch's and the device's access's. A switch that emulates once ([`Switch::shared`],
|
||||
/// made from the separate texture and sampler. A sampling makes one in its open block. A switch
|
||||
/// that emulates once ([`Switch::shared`],
|
||||
/// SEMANTICS 1012) makes them only for its arms' device accesses
|
||||
/// ([`Sampling::shared_sampled_images`]).
|
||||
pub fn combined_samplings(&self) -> u32 {
|
||||
match self {
|
||||
TextureStrategy::Sampling(s) => match s.source {
|
||||
crate::lower::sampler::Source::Combined(_) => {
|
||||
1 + 2 * u32::from(s.fetched.is_some())
|
||||
}
|
||||
crate::lower::sampler::Source::Combined(_) => 1,
|
||||
_ => 0,
|
||||
},
|
||||
TextureStrategy::Switch(w) => match w.shared() {
|
||||
@@ -1751,24 +1748,6 @@ fn unconverted_class(cx: &mut SelectCx<'_>, index: u32) -> Result<NoteClause, Er
|
||||
.into())
|
||||
}
|
||||
|
||||
/// An access of texture slot `image` that reads its class without converting a texel to `half` by
|
||||
/// it: a raw sRGB access, whose decode reads the `UNORM`, `SRGB`, and channel bits, a fetched
|
||||
/// gather and a NaN texel's rule. The slot's `TexelFormat` specialization
|
||||
/// (`RuntimeFact::TexelFormat`), without the conversion routine. Nothing is noted here: a raw
|
||||
/// access's decode is exact, and the access's selection records its own notes.
|
||||
pub(crate) fn texel_format_spec(cx: &mut SelectCx<'_>, image: ImageRef) -> Result<(), Error> {
|
||||
let ImageRef::Slot(index) = image else {
|
||||
return Err(cx.invariant("a slot's class of a heap element"));
|
||||
};
|
||||
let slot = slot_of(cx, index)?.slot;
|
||||
if let Some(s) = cx.families.texture.slots.get_mut(&index) {
|
||||
s.texel_format = true;
|
||||
}
|
||||
cx.facts
|
||||
.insert(crate::pipeline::facts::RuntimeFact::TexelFormat { slot });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The address-mode map constexpr sampler `words` samples texture slot `index` under: the map
|
||||
/// of the texture the slot's variant binds there (`LoweringInputs::address_maps`), `None` for
|
||||
/// the identity. The slot records `RuntimeFact::ConstexprSampled` with the sampler's modes,
|
||||
|
||||
@@ -11,12 +11,11 @@
|
||||
//!
|
||||
//! The public surface (`Device::compile_function`, `function_compile_key`,
|
||||
//! `compile_compute_pipeline`, `compile_render_pipeline`, and the pipeline keys) is [`api`]; the
|
||||
//! key derivation is [`key`]; holding a pipeline to the device's compiler word bound is `fit`.
|
||||
//! key derivation is [`key`].
|
||||
|
||||
pub mod api;
|
||||
pub(crate) mod color_group;
|
||||
mod entry;
|
||||
mod fit;
|
||||
pub mod key;
|
||||
mod numbered;
|
||||
mod partition;
|
||||
|
||||
@@ -279,8 +279,6 @@ impl Device {
|
||||
/// call stack was sized for another depth (`RuntimeFact::CallStackDepth`) is
|
||||
/// `InvalidDescriptor(MaxCallStackDepth)`. A stage-input attribute whose buffer has no layout,
|
||||
/// read or not, is `InvalidDescriptor(StageInputLayout)`, where Metal stops at an assertion.
|
||||
/// A `Function` kernel's pipeline is held to the device's compiler word bound
|
||||
/// ([`Device::fit_compute_pipeline`]).
|
||||
pub fn compile_compute_pipeline(
|
||||
&self,
|
||||
d: &ComputePipelineDescriptor,
|
||||
@@ -288,9 +286,7 @@ impl Device {
|
||||
) -> Result<ComputePipeline, Error> {
|
||||
guarded(|| {
|
||||
let inputs = kernel_inputs(d);
|
||||
let first = self.compute_pipeline(d, &inputs, &mut Meter::new(b))?;
|
||||
let bound = self.profile().module_word_bound();
|
||||
self.fit_compute_within(d, &inputs, b, first, bound)
|
||||
self.compute_pipeline(d, &inputs, &mut Meter::new(b))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -321,8 +317,7 @@ impl Device {
|
||||
/// `InvalidDescriptor(ColorAttachment)`. A multisampled pass (`raster_sample_count` above 1) is
|
||||
/// `Unsupported{TileShading, NotImplemented}`: what its imageblock's samples are is not read.
|
||||
/// The tile function's recursion is sized for `d`'s `maxCallStackDepth` as a compute kernel's
|
||||
/// is. A `Function` tile function's pipeline is held to the device's compiler word bound
|
||||
/// ([`Device::fit_tile_pipeline`]).
|
||||
/// is.
|
||||
pub fn compile_tile_pipeline(
|
||||
&self,
|
||||
d: &TileRenderPipelineDescriptor,
|
||||
@@ -330,9 +325,7 @@ impl Device {
|
||||
) -> Result<ComputePipeline, Error> {
|
||||
guarded(|| {
|
||||
let inputs = tile_inputs(d);
|
||||
let first = self.tile_pipeline(d, &inputs, &mut Meter::new(b))?;
|
||||
let bound = self.profile().module_word_bound();
|
||||
self.fit_tile_within(d, &inputs, b, first, bound)
|
||||
self.tile_pipeline(d, &inputs, &mut Meter::new(b))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -490,18 +483,14 @@ impl Device {
|
||||
/// compiled under the same inputs; link refuses a vertex stage compiled under another
|
||||
/// projection. Each stage's recursion is sized for `d`'s `maxVertexCallStackDepth` or
|
||||
/// `maxFragmentCallStackDepth`, as a compute kernel's is for its pipeline's; a `Compiled` stage
|
||||
/// sized for another depth is `InvalidDescriptor(MaxCallStackDepth)`. A pipeline of `Function`
|
||||
/// stages is held to the device's compiler word bound ([`Device::fit_render_variant`]).
|
||||
/// sized for another depth is `InvalidDescriptor(MaxCallStackDepth)`.
|
||||
pub fn compile_render_variant(
|
||||
&self,
|
||||
d: &RenderPipelineDescriptor,
|
||||
v: &VariantKey,
|
||||
b: &Budget,
|
||||
) -> Result<RenderPipeline, Error> {
|
||||
guarded(|| {
|
||||
let first = self.render_pipeline(d, v, &mut Meter::new(b))?;
|
||||
self.fit_render_within(d, v, b, first, self.profile().module_word_bound())
|
||||
})
|
||||
guarded(|| self.render_pipeline(d, v, &mut Meter::new(b)))
|
||||
}
|
||||
|
||||
/// Compile the mesh render pipeline `d` under budget `b`: its object function (when it has one)
|
||||
@@ -528,21 +517,17 @@ impl Device {
|
||||
/// Compile the mesh render pipeline `d` under the variant `v` a plan of it asked for
|
||||
/// (`BindingPlan::variant`) and budget `b`, as [`Device::compile_mesh_pipeline`] does: each
|
||||
/// `Function` stage under [`VariantKey::lowering_inputs`] of its stage, the fragment function's
|
||||
/// for the mesh function's outputs. A pipeline of `Function` stages is held to the device's
|
||||
/// compiler word bound ([`Device::fit_mesh_variant`]).
|
||||
/// for the mesh function's outputs.
|
||||
pub fn compile_mesh_variant(
|
||||
&self,
|
||||
d: &MeshPipelineDescriptor,
|
||||
v: &VariantKey,
|
||||
b: &Budget,
|
||||
) -> Result<RenderPipeline, Error> {
|
||||
guarded(|| {
|
||||
let first = self.mesh_pipeline(d, v, &mut Meter::new(b))?;
|
||||
self.fit_mesh_within(d, v, b, first, self.profile().module_word_bound())
|
||||
})
|
||||
guarded(|| self.mesh_pipeline(d, v, &mut Meter::new(b)))
|
||||
}
|
||||
|
||||
/// [`Device::compile_mesh_variant`] with the caller's meter, unfitted.
|
||||
/// [`Device::compile_mesh_variant`] with the caller's meter.
|
||||
pub(crate) fn mesh_pipeline(
|
||||
&self,
|
||||
d: &MeshPipelineDescriptor,
|
||||
@@ -710,8 +695,7 @@ impl Device {
|
||||
}
|
||||
|
||||
/// [`Device::compile_compute_pipeline`] with the caller's meter (tests count its work),
|
||||
/// unfitted, a `Function` kernel compiled under `inputs` (`d`'s own, `kernel_inputs`, or a
|
||||
/// fit's).
|
||||
/// a `Function` kernel compiled under `inputs` (`d`'s own, `kernel_inputs`).
|
||||
pub(crate) fn compute_pipeline(
|
||||
&self,
|
||||
d: &ComputePipelineDescriptor,
|
||||
@@ -749,8 +733,8 @@ impl Device {
|
||||
})
|
||||
}
|
||||
|
||||
/// [`Device::compile_tile_pipeline`] with the caller's meter, unfitted, a `Function` tile
|
||||
/// function compiled under `inputs` (`d`'s own, `tile_inputs`, or a fit's).
|
||||
/// [`Device::compile_tile_pipeline`] with the caller's meter, a `Function` tile function
|
||||
/// compiled under `inputs` (`d`'s own, `tile_inputs`).
|
||||
pub(crate) fn tile_pipeline(
|
||||
&self,
|
||||
d: &TileRenderPipelineDescriptor,
|
||||
@@ -798,7 +782,7 @@ impl Device {
|
||||
})
|
||||
}
|
||||
|
||||
/// [`Device::compile_render_variant`] with the caller's meter, unfitted. A variant of one of
|
||||
/// [`Device::compile_render_variant`] with the caller's meter. A variant of one of
|
||||
/// the pipeline's color groups (`VariantKey::color_group`) compiles and links as the pipeline
|
||||
/// of its group's attachments (`color_group`), its key's choices of colors naming the group's.
|
||||
pub(crate) fn render_pipeline(
|
||||
|
||||
@@ -1,288 +0,0 @@
|
||||
//! The compiler-word-bound fit: a pipeline whose largest stage module passes the device's
|
||||
//! compiler word bound ([`DeviceProfile::module_word_bound`], where the driver faults compiling a
|
||||
//! module past it), translated again from its functions with the device policy's module-growing
|
||||
//! exact forms made native, recording the forms dropped
|
||||
//! (`RuntimeFact::ExactFormsOverCompilerLimit`). Every pipeline kind is fitted by the one rule: a
|
||||
//! render pipeline of vertex and fragment stages, a mesh render pipeline (object, mesh and
|
||||
//! fragment stages, or the compute and synthesized vertex stages of an emulated mesh), a compute
|
||||
//! pipeline and a tile render pipeline. Each kind's compile from `Function` stages fits itself
|
||||
//! ([`Device::compile_render_variant`], [`Device::compile_mesh_variant`],
|
||||
//! [`Device::compile_compute_pipeline`], [`Device::compile_tile_pipeline`]); a pipeline linked from
|
||||
//! `Compiled` stages is fitted from the descriptor of its functions by the kind's `fit_*` call.
|
||||
|
||||
use crate::budget::{Budget, Meter};
|
||||
use crate::cache::VariantKey;
|
||||
use crate::device::policy::{
|
||||
DevicePolicy,
|
||||
};
|
||||
use crate::device::{mechanism, Device, DeviceProfile};
|
||||
use crate::error::Error;
|
||||
use crate::pipeline::artifact::{ComputePipeline, RenderPipeline, RuntimeDependency};
|
||||
use crate::pipeline::compile::guarded;
|
||||
use crate::pipeline::descriptor::{
|
||||
ComputePipelineDescriptor, MeshPipelineDescriptor, RenderPipelineDescriptor, StageSource,
|
||||
TileRenderPipelineDescriptor,
|
||||
};
|
||||
use crate::pipeline::facts::RuntimeFact;
|
||||
use crate::pipeline::lower_inputs::LoweringInputs;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
impl Device {
|
||||
/// `pipeline`, [`Device::compile_render_variant`]'s compile of `d` under `v` (whose stages may
|
||||
/// be `Compiled`), held to the device's compiler word bound
|
||||
/// ([`DeviceProfile::module_word_bound`]): where the driver faults compiling a module past it
|
||||
/// and `pipeline`'s largest stage passes it, `d`'s stages translated again with the device
|
||||
/// policy's module-growing exact answers made native, recording the forms dropped
|
||||
/// (`RuntimeFact::ExactFormsOverCompilerLimit`) and keeping `pipeline`'s key and profile
|
||||
/// fingerprint, so a cache finds it where it would find `pipeline`. The stages carry the
|
||||
/// reduced forms' own precision notes. `pipeline` itself where the device has no bound, it
|
||||
/// fits, or a stage of `d` is `Compiled` (only a `Function` stage can be translated again):
|
||||
/// a caller that compiled its stages ahead must pass the descriptor of their functions here,
|
||||
/// or the module goes to the driver unreduced.
|
||||
pub fn fit_render_variant(
|
||||
&self,
|
||||
d: &RenderPipelineDescriptor,
|
||||
v: &VariantKey,
|
||||
b: &Budget,
|
||||
pipeline: RenderPipeline,
|
||||
) -> Result<RenderPipeline, Error> {
|
||||
guarded(|| self.fit_render_within(d, v, b, pipeline, self.profile().module_word_bound()))
|
||||
}
|
||||
|
||||
/// `pipeline`, [`Device::compile_mesh_variant`]'s compile of `d` under `v` (whose stages may be
|
||||
/// `Compiled`), held to the device's compiler word bound as
|
||||
/// [`Device::fit_render_variant`] holds a render pipeline: its object, mesh and fragment
|
||||
/// stages translated again from `d`'s functions with the exact forms dropped where its largest
|
||||
/// stage (the synthesized vertex stage of an emulated mesh among them) passes the bound, under
|
||||
/// `pipeline`'s key. `pipeline` itself where the device has no bound, it fits, or a stage of
|
||||
/// `d` is `Compiled`.
|
||||
pub fn fit_mesh_variant(
|
||||
&self,
|
||||
d: &MeshPipelineDescriptor,
|
||||
v: &VariantKey,
|
||||
b: &Budget,
|
||||
pipeline: RenderPipeline,
|
||||
) -> Result<RenderPipeline, Error> {
|
||||
guarded(|| self.fit_mesh_within(d, v, b, pipeline, self.profile().module_word_bound()))
|
||||
}
|
||||
|
||||
/// `pipeline`, [`Device::compile_compute_pipeline`]'s compile of `d` (whose kernel may be
|
||||
/// `Compiled`), its kernel compiled under `inputs`, held to the device's compiler word bound as
|
||||
/// [`Device::fit_render_variant`] holds a render pipeline: `d`'s kernel function translated
|
||||
/// again under `inputs` with the exact forms dropped where its module passes the bound, under
|
||||
/// `pipeline`'s key. `inputs` are those the kernel was compiled under: a `Function` kernel's
|
||||
/// in [`Device::compile_compute_pipeline`] are `d`'s stage-input descriptor and
|
||||
/// `maxCallStackDepth`, and a kernel compiled ahead ([`Device::compile_function`]) is fitted
|
||||
/// under the inputs given there. `pipeline` itself where the device has no bound, it fits, or
|
||||
/// `d`'s kernel is `Compiled`.
|
||||
pub fn fit_compute_pipeline(
|
||||
&self,
|
||||
d: &ComputePipelineDescriptor,
|
||||
inputs: &LoweringInputs,
|
||||
b: &Budget,
|
||||
pipeline: ComputePipeline,
|
||||
) -> Result<ComputePipeline, Error> {
|
||||
let bound = self.profile().module_word_bound();
|
||||
guarded(|| self.fit_compute_within(d, inputs, b, pipeline, bound))
|
||||
}
|
||||
|
||||
/// `pipeline`, [`Device::compile_tile_pipeline`]'s compile of `d` (whose tile function may be
|
||||
/// `Compiled`), its tile function compiled under `inputs`, held to the device's compiler word
|
||||
/// bound as [`Device::fit_compute_pipeline`] holds a compute pipeline: `inputs` are those the
|
||||
/// tile function was compiled under (in [`Device::compile_tile_pipeline`], `d`'s color
|
||||
/// attachment formats, `threadgroupSizeMatchesTileSize` and `maxCallStackDepth`). `pipeline`
|
||||
/// itself where the device has no bound, it fits, or `d`'s tile function is `Compiled`.
|
||||
pub fn fit_tile_pipeline(
|
||||
&self,
|
||||
d: &TileRenderPipelineDescriptor,
|
||||
inputs: &LoweringInputs,
|
||||
b: &Budget,
|
||||
pipeline: ComputePipeline,
|
||||
) -> Result<ComputePipeline, Error> {
|
||||
let bound = self.profile().module_word_bound();
|
||||
guarded(|| self.fit_tile_within(d, inputs, b, pipeline, bound))
|
||||
}
|
||||
|
||||
/// [`Device::fit_render_variant`] under `bound` in place of the device's own: a test pins a
|
||||
/// low bound without a device that carries the workaround.
|
||||
pub(crate) fn fit_render_within(
|
||||
&self,
|
||||
d: &RenderPipelineDescriptor,
|
||||
v: &VariantKey,
|
||||
b: &Budget,
|
||||
pipeline: RenderPipeline,
|
||||
bound: Option<u32>,
|
||||
) -> Result<RenderPipeline, Error> {
|
||||
let translatable = function(&d.vertex) && d.fragment.as_ref().is_none_or(function);
|
||||
self.held_to(pipeline, bound, translatable, |device| {
|
||||
device.render_pipeline(d, v, &mut Meter::new(b))
|
||||
})
|
||||
}
|
||||
|
||||
/// [`Device::fit_mesh_variant`] under `bound` in place of the device's own.
|
||||
pub(crate) fn fit_mesh_within(
|
||||
&self,
|
||||
d: &MeshPipelineDescriptor,
|
||||
v: &VariantKey,
|
||||
b: &Budget,
|
||||
pipeline: RenderPipeline,
|
||||
bound: Option<u32>,
|
||||
) -> Result<RenderPipeline, Error> {
|
||||
let translatable = d.object.as_ref().is_none_or(function)
|
||||
&& function(&d.mesh)
|
||||
&& d.fragment.as_ref().is_none_or(function);
|
||||
self.held_to(pipeline, bound, translatable, |device| {
|
||||
device.mesh_pipeline(d, v, &mut Meter::new(b))
|
||||
})
|
||||
}
|
||||
|
||||
/// [`Device::fit_compute_pipeline`] under `bound` in place of the device's own.
|
||||
pub(crate) fn fit_compute_within(
|
||||
&self,
|
||||
d: &ComputePipelineDescriptor,
|
||||
inputs: &LoweringInputs,
|
||||
b: &Budget,
|
||||
pipeline: ComputePipeline,
|
||||
bound: Option<u32>,
|
||||
) -> Result<ComputePipeline, Error> {
|
||||
self.held_to(pipeline, bound, function(&d.kernel), |device| {
|
||||
device.compute_pipeline(d, inputs, &mut Meter::new(b))
|
||||
})
|
||||
}
|
||||
|
||||
/// [`Device::fit_tile_pipeline`] under `bound` in place of the device's own.
|
||||
pub(crate) fn fit_tile_within(
|
||||
&self,
|
||||
d: &TileRenderPipelineDescriptor,
|
||||
inputs: &LoweringInputs,
|
||||
b: &Budget,
|
||||
pipeline: ComputePipeline,
|
||||
bound: Option<u32>,
|
||||
) -> Result<ComputePipeline, Error> {
|
||||
self.held_to(pipeline, bound, function(&d.tile), |device| {
|
||||
device.tile_pipeline(d, inputs, &mut Meter::new(b))
|
||||
})
|
||||
}
|
||||
|
||||
/// `pipeline` held to `bound`, every kind by the one rule: where its stages can be translated
|
||||
/// again (`translatable`) and its largest stage passes `bound`, `again` (the pipeline's compile
|
||||
/// on a device of a reduced policy) under every module-growing exact answer native, with the
|
||||
/// forms it dropped recorded and `pipeline`'s key and profile fingerprint kept. A reduction
|
||||
/// that changes nothing of the policy is skipped.
|
||||
fn held_to<P: Fitted>(
|
||||
&self,
|
||||
pipeline: P,
|
||||
bound: Option<u32>,
|
||||
translatable: bool,
|
||||
again: impl Fn(&Device) -> Result<P, Error>,
|
||||
) -> Result<P, Error> {
|
||||
if !bound.is_some_and(|w| translatable && pipeline.largest_stage_words() > w) {
|
||||
return Ok(pipeline);
|
||||
}
|
||||
let base = *self.policy();
|
||||
let policy = native_forms(base);
|
||||
if policy == base {
|
||||
return Ok(pipeline);
|
||||
}
|
||||
// The lowering reads the profile, never the policy, and `Device::new` is the profile's
|
||||
// one producer: the description kept, the policy reduced.
|
||||
let device = Device::new(self.description().clone(), policy)?;
|
||||
let mut reduced = again(&device)?;
|
||||
reduced
|
||||
.dependencies_mut()
|
||||
.push(dropped_forms(base, &policy, device.profile()));
|
||||
Ok(reduced.named_as(&pipeline))
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a stage can be translated again: a `Function` stage, not one taken `Compiled`.
|
||||
fn function(source: &StageSource) -> bool {
|
||||
matches!(source, StageSource::Function(_))
|
||||
}
|
||||
|
||||
/// A compiled pipeline the compiler word bound holds: a render pipeline (vertex or mesh) or a
|
||||
/// compute pipeline (kernel or tile).
|
||||
trait Fitted: Sized {
|
||||
/// The word count of its largest stage module: what a device's compiler word bound holds
|
||||
/// ([`DeviceProfile::module_word_bound`]). A pipeline with no stage counts as 0.
|
||||
fn largest_stage_words(&self) -> u32;
|
||||
/// Its runtime dependencies, where the fit records the forms it dropped.
|
||||
fn dependencies_mut(&mut self) -> &mut Vec<RuntimeDependency>;
|
||||
/// `self`, named as `compiled` is (its key and profile fingerprint), so a cache stores and
|
||||
/// finds it where it would `compiled`.
|
||||
fn named_as(self, compiled: &Self) -> Self;
|
||||
}
|
||||
|
||||
impl Fitted for RenderPipeline {
|
||||
fn largest_stage_words(&self) -> u32 {
|
||||
self.stages
|
||||
.iter()
|
||||
.map(|s| words(&s.spirv))
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
fn dependencies_mut(&mut self) -> &mut Vec<RuntimeDependency> {
|
||||
&mut self.dependencies
|
||||
}
|
||||
|
||||
fn named_as(self, compiled: &RenderPipeline) -> RenderPipeline {
|
||||
RenderPipeline {
|
||||
key: compiled.key,
|
||||
profile: compiled.profile,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Fitted for ComputePipeline {
|
||||
fn largest_stage_words(&self) -> u32 {
|
||||
words(&self.stage.spirv)
|
||||
}
|
||||
|
||||
fn dependencies_mut(&mut self) -> &mut Vec<RuntimeDependency> {
|
||||
&mut self.dependencies
|
||||
}
|
||||
|
||||
fn named_as(self, compiled: &ComputePipeline) -> ComputePipeline {
|
||||
ComputePipeline {
|
||||
key: compiled.key,
|
||||
profile: compiled.profile,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A module's word count, saturated.
|
||||
fn words(spirv: &[u32]) -> u32 {
|
||||
u32::try_from(spirv.len()).unwrap_or(u32::MAX)
|
||||
}
|
||||
|
||||
/// The compiler-word-bound fallback's policy: `base` with every module-growing exact answer (the
|
||||
/// fast default's forms) set to its native, module-smaller answer. It does not touch the policy's
|
||||
/// other choices (pointer and handle domains, containment, isolation, framebuffer fetch, or the
|
||||
/// runtime's choices, which change no module), so a reduced device keeps them.
|
||||
fn native_forms(base: DevicePolicy) -> DevicePolicy {
|
||||
DevicePolicy {
|
||||
nan_and_min_max: NanMinMaxPolicy::Native,
|
||||
..base
|
||||
}
|
||||
}
|
||||
|
||||
/// Which of the consumer's exact forms the fallback dropped to fit the bound, as the dependency a
|
||||
/// fitted pipeline records: each field of [`RuntimeFact::ExactFormsOverCompilerLimit`] is set
|
||||
/// where `base`'s form differs from the reduced `policy`'s. The consumer announces it.
|
||||
fn dropped_forms(
|
||||
base: DevicePolicy,
|
||||
policy: &DevicePolicy,
|
||||
reduced: &DeviceProfile,
|
||||
) -> RuntimeDependency {
|
||||
let fact = RuntimeFact::ExactFormsOverCompilerLimit {
|
||||
};
|
||||
RuntimeDependency {
|
||||
fact,
|
||||
mechanism: mechanism(&fact, reduced),
|
||||
}
|
||||
}
|
||||
@@ -1,500 +0,0 @@
|
||||
//! Tests of the compiler-word-bound fit, one per pipeline kind (render, mesh, tile, compute): past
|
||||
//! the bound, the pipeline is its functions' compile on a device of the reduced policy, recording
|
||||
//! the forms dropped (`RuntimeFact::ExactFormsOverCompilerLimit`) under its own compile's key and
|
||||
//! profile fingerprint; within the bound, or on a device without one, it is the compile unchanged.
|
||||
//! A pipeline linked from stages compiled ahead (the runtime's shape) is fitted from its
|
||||
//! functions' descriptor and left as it is from its `Compiled` stages. The bound is pinned low in
|
||||
//! code (`Device::fit_*_within`); no device runs, and no driver's compiler is driven.
|
||||
//!
|
||||
//! `llvm-as` assembles the owned fixtures; a missing tool skips a test visibly.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
|
||||
use super::{native_forms, Fitted};
|
||||
use crate::budget::{Budget, Meter};
|
||||
use crate::cache::VariantKey;
|
||||
use crate::device::{Device, DeviceDescription, DevicePolicy};
|
||||
use crate::library::Library;
|
||||
use crate::metal;
|
||||
use crate::pipeline::artifact::{RenderPipeline, RuntimeDependency};
|
||||
use crate::pipeline::descriptor::{
|
||||
ColorAttachmentDescriptor, ComputePipelineDescriptor, FunctionDescriptor,
|
||||
MeshPipelineDescriptor, RenderPipelineDescriptor, StageSource, TileRenderPipelineDescriptor,
|
||||
};
|
||||
use crate::pipeline::facts::{Mechanism, RuntimeFact};
|
||||
use crate::pipeline::lower_inputs::LoweringInputs;
|
||||
use crate::pipeline::sym::Stage;
|
||||
use crate::pipeline::testing::{engine_dir, llvm_assemble, AssembleError};
|
||||
use crate::vk::ShaderStage;
|
||||
|
||||
/// The owned fixture at `path` as a library, or `None` (skipped visibly) without `llvm-as`.
|
||||
fn library(path: &Path) -> Option<Library> {
|
||||
match llvm_assemble(path) {
|
||||
Ok(bc) => Some(Library::from_air(&bc).expect("library")),
|
||||
Err(AssembleError::Missing(why)) => {
|
||||
eprintln!("SKIPPED: {why}");
|
||||
None
|
||||
}
|
||||
Err(AssembleError::Rejected(why)) => panic!("llvm-as rejected {path:?}: {why}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Committed profile `stem` as the Khronos reader describes it.
|
||||
fn description(stem: &str) -> DeviceDescription {
|
||||
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../metal2vulkan-validation/profiles")
|
||||
.join(format!("{stem}.json"));
|
||||
let text = std::fs::read_to_string(&path).expect("profile");
|
||||
DeviceDescription::from_khronos_json(&text, None).expect("description")
|
||||
}
|
||||
|
||||
/// Every exact form.
|
||||
fn exact() -> DevicePolicy {
|
||||
DevicePolicy::default().exact_answers()
|
||||
}
|
||||
|
||||
/// Committed profile `stem` as a device under `policy`.
|
||||
fn device(stem: &str, policy: DevicePolicy) -> Device {
|
||||
Device::new(description(stem), policy).expect("device")
|
||||
}
|
||||
|
||||
/// The forms a fitted pipeline's `dependencies` record it dropped, in the fact's field order;
|
||||
/// `None` where it records none.
|
||||
fn dropped(dependencies: &[RuntimeDependency]) -> Option<[bool; 1]> {
|
||||
dependencies.iter().find_map(|d| match d.fact {
|
||||
RuntimeFact::ExactFormsOverCompilerLimit { nan_and_min_max } => Some([nan_and_min_max]),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// `reduced`, the compile of the fitted functions on a device of `exact()` with every
|
||||
/// module-growing form native, as the fit of `compiled` (their compile under `exact()`) past its
|
||||
/// bound gives it: recording that it dropped every exact form, named as `compiled` is.
|
||||
fn fitted_as<P: Fitted>(reduced: P, compiled: &P) -> P {
|
||||
let fact = RuntimeFact::ExactFormsOverCompilerLimit {
|
||||
};
|
||||
let mut reduced = reduced;
|
||||
reduced
|
||||
.dependencies_mut()
|
||||
.push(RuntimeDependency::new(fact, Mechanism::None));
|
||||
reduced.named_as(compiled)
|
||||
}
|
||||
|
||||
/// A render pipeline whose largest stage module passes a device's compiler word bound is
|
||||
/// translated again with every exact answer that grows a module native, recording which forms it
|
||||
/// dropped
|
||||
/// (`RuntimeFact::ExactFormsOverCompilerLimit`) and keeping the compile's key and profile
|
||||
/// fingerprint. A pipeline compiled from stages compiled ahead (the runtime's shape) is fitted from
|
||||
/// its functions' descriptor ([`Device::fit_render_variant`]), and is left as it is from its
|
||||
/// `Compiled` stages, which cannot be translated again. Uses the owned `runtime_examples` fixture
|
||||
/// (a sampled `half` fragment), on a generic desktop profile whose sampler is not Metal's own.
|
||||
#[test]
|
||||
fn a_module_over_the_compiler_bound_drops_its_exact_forms_to_fit() {
|
||||
let path = metal2vulkan_devtools::fixtures_dir().join("examples/runtime_examples.ll");
|
||||
let Some(lib) = library(&path) else {
|
||||
return;
|
||||
};
|
||||
let vertex = lib.function("colored_vertex").expect("vertex");
|
||||
let fragment = lib.function("sampled_fragment").expect("fragment");
|
||||
let descriptor = || {
|
||||
let mut d = RenderPipelineDescriptor::new(StageSource::Function(FunctionDescriptor::new(
|
||||
vertex.clone(),
|
||||
)));
|
||||
d.fragment = Some(StageSource::Function(FunctionDescriptor::new(
|
||||
fragment.clone(),
|
||||
)));
|
||||
d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(
|
||||
metal::PixelFormat::RGBA8Unorm,
|
||||
));
|
||||
d
|
||||
};
|
||||
let v = VariantKey::new();
|
||||
let b = Budget::standard();
|
||||
let stem = "lunarg-desktop-baseline-2023";
|
||||
let words = |policy: DevicePolicy| -> u32 {
|
||||
let pipe = device(stem, policy)
|
||||
.compile_render_variant(&descriptor(), &v, &b)
|
||||
.expect("compile");
|
||||
largest(&pipe)
|
||||
};
|
||||
fn largest(pipe: &RenderPipeline) -> u32 {
|
||||
pipe.largest_stage_words()
|
||||
}
|
||||
|
||||
let w_exact = words(exact());
|
||||
let w_fast = words(DevicePolicy::default());
|
||||
assert!(w_fast <= w_exact, "fast {w_fast} <= exact {w_exact}");
|
||||
|
||||
let dev = device(stem, exact());
|
||||
let first = || {
|
||||
dev.compile_render_variant(&descriptor(), &v, &b)
|
||||
.expect("compile")
|
||||
};
|
||||
let fit = |bound: u32| {
|
||||
let first = first();
|
||||
let fitted = dev
|
||||
.fit_render_within(&descriptor(), &v, &b, first.clone(), Some(bound))
|
||||
.expect("fit");
|
||||
// The fitted pipeline is what the device's compile of the descriptor gives, as a cache
|
||||
// stores and finds it.
|
||||
assert_eq!(fitted.key, first.key, "the compile's key kept");
|
||||
assert_eq!(fitted.profile, first.profile, "the compile's profile kept");
|
||||
fitted
|
||||
};
|
||||
|
||||
// A bound below every form drops every exact form the policy carries: the fast default.
|
||||
let pipe = fit(0);
|
||||
assert_eq!(largest(&pipe), w_fast, "reduced to the fast default");
|
||||
assert_eq!(
|
||||
dropped(&pipe.dependencies),
|
||||
Some([true; 1]),
|
||||
"every exact form dropped"
|
||||
);
|
||||
|
||||
// Within the bound, or on a device without one: no fallback, no fact, the exact forms kept.
|
||||
for pipe in [
|
||||
fit(u32::MAX),
|
||||
dev.fit_render_within(&descriptor(), &v, &b, first(), None)
|
||||
.expect("no bound"),
|
||||
dev.fit_render_variant(&descriptor(), &v, &b, first())
|
||||
.expect("the device's own: none"),
|
||||
] {
|
||||
assert_eq!(
|
||||
dropped(&pipe.dependencies),
|
||||
None,
|
||||
"no fallback within the bound"
|
||||
);
|
||||
assert_eq!(largest(&pipe), w_exact);
|
||||
}
|
||||
|
||||
// The runtime's shape: each stage compiled ahead under the keys' inputs, linked from the
|
||||
// `Compiled` stages, then fitted from the functions' descriptor.
|
||||
let keys = dev.render_pipeline_key(&descriptor(), &b).expect("keys");
|
||||
let compiled = |source: &StageSource, inputs: &LoweringInputs| match source {
|
||||
StageSource::Function(f) => {
|
||||
StageSource::Compiled(dev.compile_function(f, inputs, &b).expect("stage"))
|
||||
}
|
||||
StageSource::Compiled(_) => unreachable!("the descriptor's stages are functions"),
|
||||
};
|
||||
let mut linked = descriptor();
|
||||
linked.vertex = compiled(&linked.vertex, keys.vertex_inputs.as_ref().expect("inputs"));
|
||||
linked.fragment = linked
|
||||
.fragment
|
||||
.as_ref()
|
||||
.map(|f| compiled(f, keys.fragment_inputs.as_ref().expect("inputs")));
|
||||
let ahead = dev
|
||||
.compile_render_variant(&linked, &v, &b)
|
||||
.expect("compiled stages");
|
||||
assert_eq!(ahead.key, keys.pipeline);
|
||||
assert_eq!(largest(&ahead), w_exact);
|
||||
// From the compiled stages alone nothing can be translated again: left as it is.
|
||||
let kept = dev
|
||||
.fit_render_within(&linked, &v, &b, ahead.clone(), Some(0))
|
||||
.expect("compiled stages kept");
|
||||
assert_eq!(kept, ahead);
|
||||
// From the functions' descriptor: fitted, under the compiled pipeline's key.
|
||||
let fitted = dev
|
||||
.fit_render_within(&descriptor(), &v, &b, ahead, Some(0))
|
||||
.expect("fitted from the functions");
|
||||
assert_eq!(fitted.key, keys.pipeline);
|
||||
assert_eq!(largest(&fitted), w_fast);
|
||||
assert_eq!(dropped(&fitted.dependencies), Some([true; 1]));
|
||||
}
|
||||
|
||||
/// A mesh render pipeline is fitted as a vertex and fragment pipeline is: past the bound, its
|
||||
/// object, mesh and fragment functions translated again with every exact form dropped (its
|
||||
/// largest stage counted among all of them), recording the forms under its compile's key; within
|
||||
/// the bound, on a device without one, or with a `Compiled` stage, the compile unchanged. Both
|
||||
/// forms of a mesh pipeline: `TaskEXT` and `MeshEXT` stages on ANV's Arrow Lake profile, whose
|
||||
/// own bound (400,000 words) the fixture fits, so its compile is the unfitted one; and on a
|
||||
/// device without `VK_EXT_mesh_shader`, the compute stages and synthesized vertex stage that
|
||||
/// emulate them. Uses the owned `mesh_draws` fixture.
|
||||
#[test]
|
||||
fn a_mesh_pipeline_over_the_compiler_bound_drops_its_exact_forms_to_fit() {
|
||||
let Some(lib) = library(&engine_dir().join("mesh_draws.ll")) else {
|
||||
return;
|
||||
};
|
||||
let function = |name: &str| FunctionDescriptor::new(lib.function(name).expect("function"));
|
||||
let descriptor = || {
|
||||
let mut d = MeshPipelineDescriptor::new(StageSource::Function(function("mesh_draws_mesh")));
|
||||
d.object = Some(StageSource::Function(function("mesh_draws_object")));
|
||||
d.fragment = Some(StageSource::Function(function("mesh_draws_fragment")));
|
||||
for color in &mut d.color_attachments[..2] {
|
||||
*color = Some(ColorAttachmentDescriptor::new(
|
||||
metal::PixelFormat::RGBA32Uint,
|
||||
));
|
||||
}
|
||||
d
|
||||
};
|
||||
let (v, b) = (VariantKey::new(), Budget::standard());
|
||||
for (stem, bound, kinds) in [
|
||||
(
|
||||
"intel-arl-anv",
|
||||
Some(400_000),
|
||||
&[
|
||||
ShaderStage::TASK_EXT,
|
||||
ShaderStage::MESH_EXT,
|
||||
ShaderStage::FRAGMENT,
|
||||
][..],
|
||||
),
|
||||
(
|
||||
"lunarg-desktop-baseline-2023",
|
||||
None,
|
||||
&[
|
||||
ShaderStage::COMPUTE,
|
||||
ShaderStage::COMPUTE,
|
||||
ShaderStage::VERTEX,
|
||||
ShaderStage::FRAGMENT,
|
||||
][..],
|
||||
),
|
||||
] {
|
||||
let dev = device(stem, exact());
|
||||
assert_eq!(dev.profile().module_word_bound(), bound, "{stem}");
|
||||
let compiled = dev.compile_mesh_variant(&descriptor(), &v, &b).expect(stem);
|
||||
let unfitted = dev
|
||||
.mesh_pipeline(&descriptor(), &v, &mut Meter::new(&b))
|
||||
.expect(stem);
|
||||
assert_eq!(compiled, unfitted, "{stem}: within the device's own bound");
|
||||
assert_eq!(dropped(&compiled.dependencies), None, "{stem}");
|
||||
let stages: Vec<ShaderStage> = compiled.stages.iter().map(|s| s.stage).collect();
|
||||
assert_eq!(stages, kinds, "{stem}");
|
||||
|
||||
let fast = device(stem, native_forms(exact()));
|
||||
let reduced = fast
|
||||
.mesh_pipeline(&descriptor(), &v, &mut Meter::new(&b))
|
||||
.expect(stem);
|
||||
let w_fast = device(stem, DevicePolicy::default())
|
||||
.compile_mesh_variant(&descriptor(), &v, &b)
|
||||
.expect(stem)
|
||||
.largest_stage_words();
|
||||
assert_eq!(
|
||||
reduced.largest_stage_words(),
|
||||
w_fast,
|
||||
"{stem}: the fast forms"
|
||||
);
|
||||
// The fixture's maths are the device's under every policy, so no exact form need grow it.
|
||||
let w_exact = compiled.largest_stage_words();
|
||||
assert!(
|
||||
w_fast <= w_exact,
|
||||
"{stem}: fast {w_fast} <= exact {w_exact}"
|
||||
);
|
||||
let fit = |d: &MeshPipelineDescriptor, bound| {
|
||||
dev.fit_mesh_within(d, &v, &b, compiled.clone(), bound)
|
||||
.expect(stem)
|
||||
};
|
||||
assert_eq!(
|
||||
fit(&descriptor(), Some(0)),
|
||||
fitted_as(reduced, &compiled),
|
||||
"{stem}: past the bound"
|
||||
);
|
||||
for bound in [Some(u32::MAX), None] {
|
||||
assert_eq!(
|
||||
fit(&descriptor(), bound),
|
||||
compiled,
|
||||
"{stem}: within {bound:?}"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
dev.fit_mesh_variant(&descriptor(), &v, &b, compiled.clone())
|
||||
.expect(stem),
|
||||
compiled,
|
||||
"{stem}: the device's own bound"
|
||||
);
|
||||
// A `Compiled` stage cannot be translated again: left as it is, past the bound too.
|
||||
let object = dev
|
||||
.compile_function(
|
||||
&function("mesh_draws_object"),
|
||||
&v.lowering_inputs(Stage::Object),
|
||||
&b,
|
||||
)
|
||||
.expect(stem);
|
||||
let mut ahead = descriptor();
|
||||
ahead.object = Some(StageSource::Compiled(object));
|
||||
assert_eq!(fit(&ahead, Some(0)), compiled, "{stem}: a compiled stage");
|
||||
}
|
||||
}
|
||||
|
||||
/// A tile render pipeline is fitted as a render pipeline is, its tile function translated again
|
||||
/// under the inputs it was compiled under: past the bound, every exact form dropped, recorded
|
||||
/// under the compile's key; within it, or on a device without one, the compile unchanged. In the
|
||||
/// runtime's shape (the tile function compiled ahead under the descriptor's inputs and linked
|
||||
/// from the `Compiled` stage) it is fitted from the function's descriptor and left as it is from
|
||||
/// the `Compiled` one. On ANV's UHD 770 profile, whose own bound the fixture fits, and a device
|
||||
/// without a bound. Uses the owned `ttg_tile_simd_blur` fixture (`half` arithmetic into an
|
||||
/// `RGBA16Float` attachment), its threadgroup the tile's size.
|
||||
#[test]
|
||||
fn a_tile_pipeline_over_the_compiler_bound_drops_its_exact_forms_to_fit() {
|
||||
let Some(lib) = library(&engine_dir().join("ttg_tile_simd_blur.ll")) else {
|
||||
return;
|
||||
};
|
||||
let f = FunctionDescriptor::new(lib.function("ttg_tile_simd_blur").expect("function"));
|
||||
let format = metal::PixelFormat::RGBA16Float;
|
||||
let mut d = TileRenderPipelineDescriptor::new(StageSource::Function(f.clone()));
|
||||
d.color_attachment_formats[0] = Some(format);
|
||||
d.threadgroup_size_matches_tile_size = true;
|
||||
// The inputs `compile_tile_pipeline` compiles a `Function` tile function of `d` under.
|
||||
let inputs = LoweringInputs {
|
||||
tile_attachments: Some(BTreeMap::from([(0, format)])),
|
||||
threadgroup_size_matches_tile_size: true,
|
||||
..LoweringInputs::new()
|
||||
};
|
||||
let b = Budget::standard();
|
||||
for (stem, bound) in [
|
||||
("intel-uhd770-rpls-anv", Some(400_000)),
|
||||
("lunarg-desktop-baseline-2023", None),
|
||||
] {
|
||||
let dev = device(stem, exact());
|
||||
assert_eq!(dev.profile().module_word_bound(), bound, "{stem}");
|
||||
let compiled = dev.compile_tile_pipeline(&d, &b).expect(stem);
|
||||
let unfitted = dev
|
||||
.tile_pipeline(&d, &inputs, &mut Meter::new(&b))
|
||||
.expect(stem);
|
||||
assert_eq!(compiled, unfitted, "{stem}: within the device's own bound");
|
||||
assert_eq!(dropped(&compiled.dependencies), None, "{stem}");
|
||||
|
||||
let fast = device(stem, native_forms(exact()));
|
||||
let reduced = fast
|
||||
.tile_pipeline(&d, &inputs, &mut Meter::new(&b))
|
||||
.expect(stem);
|
||||
let w_fast = device(stem, DevicePolicy::default())
|
||||
.compile_tile_pipeline(&d, &b)
|
||||
.expect(stem)
|
||||
.largest_stage_words();
|
||||
assert_eq!(
|
||||
reduced.largest_stage_words(),
|
||||
w_fast,
|
||||
"{stem}: the fast forms"
|
||||
);
|
||||
let w_exact = compiled.largest_stage_words();
|
||||
assert!(w_fast < w_exact, "{stem}: fast {w_fast} < exact {w_exact}");
|
||||
let expected = fitted_as(reduced, &compiled);
|
||||
let fit = |d: &TileRenderPipelineDescriptor, pipeline, bound| {
|
||||
dev.fit_tile_within(d, &inputs, &b, pipeline, bound)
|
||||
.expect(stem)
|
||||
};
|
||||
assert_eq!(
|
||||
fit(&d, compiled.clone(), Some(0)),
|
||||
expected,
|
||||
"{stem}: past the bound"
|
||||
);
|
||||
for bound in [Some(u32::MAX), None] {
|
||||
assert_eq!(fit(&d, compiled.clone(), bound), compiled, "{stem}: within");
|
||||
}
|
||||
|
||||
// The runtime's shape.
|
||||
let function = dev.compile_function(&f, &inputs, &b).expect(stem);
|
||||
let mut linked = d.clone();
|
||||
linked.tile = StageSource::Compiled(function);
|
||||
let ahead = dev.compile_tile_pipeline(&linked, &b).expect(stem);
|
||||
assert_eq!(ahead, compiled, "{stem}: linked from the compiled function");
|
||||
assert_eq!(
|
||||
dev.fit_tile_pipeline(&d, &inputs, &b, ahead.clone())
|
||||
.expect(stem),
|
||||
compiled,
|
||||
"{stem}: the device's own bound"
|
||||
);
|
||||
assert_eq!(
|
||||
fit(&linked, ahead.clone(), Some(0)),
|
||||
compiled,
|
||||
"{stem}: a compiled stage"
|
||||
);
|
||||
assert_eq!(
|
||||
fit(&d, ahead, Some(0)),
|
||||
expected,
|
||||
"{stem}: fitted from the function"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A compute pipeline is fitted as a render pipeline is, its kernel translated again under the
|
||||
/// inputs it was compiled under, and one within the bound translates exactly as before the fit:
|
||||
/// on ANV's UHD 770 profile, whose own bound the kernel fits, and on a device without a bound,
|
||||
/// under every exact form and under the fast default, `compile_compute_pipeline` is the unfitted
|
||||
/// compile, word for word. Past the bound every exact form is dropped. In the runtime's shape (the kernel compiled ahead and linked from the
|
||||
/// `Compiled` stage) it is fitted from the function's descriptor and left as it is from the
|
||||
/// `Compiled` one. Uses the owned `a2_kernel_lod_filter` fixture, a kernel that samples.
|
||||
#[test]
|
||||
fn a_compute_pipeline_over_the_compiler_bound_drops_its_exact_forms_to_fit() {
|
||||
let Some(lib) = library(&engine_dir().join("a2_kernel_lod_filter.ll")) else {
|
||||
return;
|
||||
};
|
||||
let f = FunctionDescriptor::new(lib.function("a2_kernel_lod_filter").expect("function"));
|
||||
let d = ComputePipelineDescriptor::new(StageSource::Function(f.clone()));
|
||||
// The inputs `compile_compute_pipeline` compiles a `Function` kernel of `d` under.
|
||||
let inputs = LoweringInputs::new();
|
||||
let b = Budget::standard();
|
||||
for (stem, bound) in [
|
||||
("intel-uhd770-rpls-anv", Some(400_000)),
|
||||
("lunarg-desktop-baseline-2023", None),
|
||||
] {
|
||||
let unfitted = |dev: &Device| {
|
||||
dev.compute_pipeline(&d, &inputs, &mut Meter::new(&b))
|
||||
.expect(stem)
|
||||
};
|
||||
for policy in [exact(), DevicePolicy::default()] {
|
||||
let dev = device(stem, policy);
|
||||
assert_eq!(dev.profile().module_word_bound(), bound, "{stem}");
|
||||
let compiled = dev.compile_compute_pipeline(&d, &b).expect(stem);
|
||||
assert_eq!(
|
||||
compiled,
|
||||
unfitted(&dev),
|
||||
"{stem}: within the device's own bound, as before the fit"
|
||||
);
|
||||
assert_eq!(dropped(&compiled.dependencies), None, "{stem}");
|
||||
}
|
||||
|
||||
let dev = device(stem, exact());
|
||||
let compiled = dev.compile_compute_pipeline(&d, &b).expect(stem);
|
||||
let w_exact = compiled.largest_stage_words();
|
||||
let reduced = unfitted(&device(stem, native_forms(exact())));
|
||||
let w_fast = device(stem, DevicePolicy::default())
|
||||
.compile_compute_pipeline(&d, &b)
|
||||
.expect(stem)
|
||||
.largest_stage_words();
|
||||
assert_eq!(
|
||||
reduced.largest_stage_words(),
|
||||
w_fast,
|
||||
"{stem}: the fast forms"
|
||||
);
|
||||
assert!(
|
||||
w_fast <= w_exact,
|
||||
"{stem}: fast {w_fast} <= exact {w_exact}"
|
||||
);
|
||||
let expected = fitted_as(reduced, &compiled);
|
||||
let fit = |d: &ComputePipelineDescriptor, pipeline, bound| {
|
||||
dev.fit_compute_within(d, &inputs, &b, pipeline, bound)
|
||||
.expect(stem)
|
||||
};
|
||||
assert_eq!(
|
||||
fit(&d, compiled.clone(), Some(0)),
|
||||
expected,
|
||||
"{stem}: past the bound"
|
||||
);
|
||||
for bound in [Some(w_exact), Some(u32::MAX), None] {
|
||||
assert_eq!(fit(&d, compiled.clone(), bound), compiled, "{stem}: within");
|
||||
}
|
||||
|
||||
// The runtime's shape.
|
||||
let function = dev.compile_function(&f, &inputs, &b).expect(stem);
|
||||
let linked = ComputePipelineDescriptor::new(StageSource::Compiled(function));
|
||||
let ahead = dev.compile_compute_pipeline(&linked, &b).expect(stem);
|
||||
assert_eq!(ahead, compiled, "{stem}: linked from the compiled function");
|
||||
assert_eq!(
|
||||
dev.fit_compute_pipeline(&d, &inputs, &b, ahead.clone())
|
||||
.expect(stem),
|
||||
compiled,
|
||||
"{stem}: the device's own bound"
|
||||
);
|
||||
assert_eq!(
|
||||
fit(&linked, ahead.clone(), Some(0)),
|
||||
compiled,
|
||||
"{stem}: a compiled stage"
|
||||
);
|
||||
assert_eq!(
|
||||
fit(&d, ahead, Some(0)),
|
||||
expected,
|
||||
"{stem}: fitted from the function"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -736,17 +736,6 @@ pub enum RuntimeFact {
|
||||
static_bytes: u32,
|
||||
payload: Option<u32>,
|
||||
},
|
||||
/// The pipeline (render, mesh render, compute or tile render) was retranslated with some of the
|
||||
/// consumer's exact forms dropped to native, because its largest stage module exceeded the
|
||||
/// device's compiler word bound and that driver faults compiling a module past it
|
||||
/// ([`DriverWorkaround::RegisterAllocatorOverflowsLargeModules`](crate::device::DriverWorkaround::RegisterAllocatorOverflowsLargeModules):
|
||||
/// ANV's register allocator). Each `true` field is an exact form the pipeline would carry under
|
||||
/// the consumer's policy that the fitting translation gave up to fit the bound; the stages carry
|
||||
/// the reduced policy's own precision notes besides. The consumer announces it once per device
|
||||
/// (the runtime's `Degradation::ExactFormsOverCompilerLimit`), naming the pipeline and the forms
|
||||
/// dropped. Nothing binds it.
|
||||
ExactFormsOverCompilerLimit {
|
||||
},
|
||||
/// The render pipeline was compiled under `VariantKey::quad_primitive_ids`, and its fragment
|
||||
/// function reads `[[primitive_id]]` from Vulkan's `PrimitiveId` shifted right by one
|
||||
/// (`LoweringInputs::quad_primitive_ids`): for a draw of Metal's private quads or quad strip,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//! docs/FAST-PATHS.md, the ledger of the defaults that trade exactness against Metal for making
|
||||
//! time, stays accurate by construction: it names every accuracy choice of `DevicePolicy` with each
|
||||
//! of its values, as `field = Type::Value`, and every precision note a fast default, a
|
||||
//! not-yet-built accurate form or a listed device gap records, with its degrade code;
|
||||
//! and it names no policy value that no longer exists. The lists below are exhaustive matches: a
|
||||
//! of its values, as `field = Type::Value`, and every precision note a not-yet-built accurate
|
||||
//! form or a listed device gap records, with its degrade code; and it names no policy value that no longer exists. The lists below are exhaustive matches: a
|
||||
//! field, a policy value or a precision note added to the crate fails to compile here until it is
|
||||
//! classed, and so reaches the ledger.
|
||||
|
||||
@@ -79,8 +78,6 @@ fn choices() -> Vec<Choice> {
|
||||
/// Where a precision note stands in the ledger.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Ledger {
|
||||
/// Recorded by a fast default whose accurate form is a switch: a row of the first table.
|
||||
FastDefault,
|
||||
/// The default's form where the accurate one is not built yet: a row of the first table.
|
||||
NotBuilt,
|
||||
/// A device gap, no speed choice: a row of the second table.
|
||||
@@ -104,8 +101,6 @@ macro_rules! notes {
|
||||
|
||||
fn notes() -> Vec<(&'static str, Ledger)> {
|
||||
notes! {
|
||||
FastDefault: [
|
||||
],
|
||||
NotBuilt: [
|
||||
ExtendedRangeBlendSource,
|
||||
ExtendedRangeFloatBlendSource,
|
||||
@@ -305,8 +300,8 @@ fn the_ledger_names_only_choices_the_policy_has() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The ledger names every precision note a fast default, a not-yet-built accurate form or a
|
||||
/// listed device gap records, each with its degrade code, which docs/API.md's catalogue lists.
|
||||
/// The ledger names every precision note a not-yet-built accurate form or a listed device gap
|
||||
/// records, each with its degrade code, which docs/API.md's catalogue lists.
|
||||
#[test]
|
||||
fn the_ledger_names_every_note_of_its_rows_with_its_code() {
|
||||
let ledger = text("../../docs/FAST-PATHS.md");
|
||||
|
||||
+1
-22
@@ -1016,17 +1016,7 @@ assert_eq!(linked, pipeline);
|
||||
the attributes its entry reads, and the kernel keys and compiles under those, so states that
|
||||
differ only in an attribute it never reads share one compiled function. What a creation reads of
|
||||
the descriptor past the fetch -- its layout agreement, its reflection, and `compute_pipeline_key`
|
||||
-- reads it whole. Each pipeline kind's compile (`compile_render_variant`,
|
||||
`compile_mesh_variant`, `compile_compute_pipeline`, `compile_tile_pipeline`) holds a pipeline of
|
||||
`Function` stages to the device's compiler word bound (`DeviceProfile::module_word_bound`,
|
||||
ANV's) itself; one linked from `Compiled` stages it cannot translate again. A caller who
|
||||
compiles stages ahead must pass the linked pipeline, with the descriptor of its functions, to
|
||||
the kind's fit, or its module goes to the driver unreduced: `device.fit_render_variant(
|
||||
&descriptor, &variant, &budget, pipeline)`, `fit_mesh_variant` likewise, and
|
||||
`fit_compute_pipeline(&descriptor, &inputs, &budget, pipeline)` or `fit_tile_pipeline` with the
|
||||
`LoweringInputs` the kernel or tile function was compiled under. The call translates the
|
||||
functions again with the policy's exact forms dropped where the largest stage passes the bound
|
||||
(`exact-forms-over-compiler-limit`), under the same key.
|
||||
-- reads it whole.
|
||||
- A key names an artifact by its inputs and versions; a content digest names it by what it says.
|
||||
`pipeline.content_digest()` hashes everything but the key and profile, and `plan.content_digest()`
|
||||
(with `serde`) everything a plan states. A cache of driver objects keyed on the digest survives a
|
||||
@@ -1408,17 +1398,6 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
|
||||
function. Announced at the state's making, naming which. Cost: each draw runs a geometry stage of
|
||||
its topology class between the vertex and fragment stages, which emits each primitive's vertices
|
||||
with the barycentric weights or the first vertex's slice and viewport.
|
||||
- `metal2vulkan-degrade-exact-forms-over-compiler-limit` (precision). `ExactFormsOverCompilerLimit`:
|
||||
A pipeline state (render, mesh render, tile render or compute) whose largest stage module, under
|
||||
the consumer's exact forms, exceeded the device's compiler word bound
|
||||
(`RuntimeFact::ExactFormsOverCompilerLimit`;
|
||||
`DriverWorkaround::RegisterAllocatorOverflowsLargeModules`, ANV's register allocator faults
|
||||
compiling a module past it), so the translation dropped those forms until it fit: native sampling
|
||||
first, then every module-growing exact answer native. Announced where the runtime makes a variant
|
||||
whose pipeline the fit reduced, the base variant or another, naming the state's kind and the
|
||||
forms dropped; the reduced stages announce their own precision notes besides.
|
||||
Cost: the dropped exact forms' results can differ from Metal's as their notes' documentation
|
||||
states, where the device's compiler would fault on the exact module.
|
||||
- `metal2vulkan-degrade-landed-visibility-results` (performance). `LandedVisibilityResults`:
|
||||
Visibility results start where Vulkan writes no query result. Cost: they land in an upload region
|
||||
and are copied on into the buffer after the pass.
|
||||
|
||||
@@ -68,7 +68,6 @@ known. The rest of the differences are docs/API.md section 9's precision notes.
|
||||
| A `Counting` visibility result of a draw writing more than one color attachment, on ANV (Mesa 26.2.4): Metal's count multiplied by the colors written, not divided back. `Boolean` results stay exact. | The driver counts each sample once per color output (`RuntimeDriverDefect::OcclusionCountPerColorOutput`), no documented Vulkan form counts it once, and a refusal would withhold the Mac2 and Metal3 families. | `VisibilityCountPerColor` (`visibility-count-per-color`) |
|
||||
| On MoltenVK a no-copy buffer or heap released with no keep-alive while batches are in flight runs its deallocator once the batches submitted before its release completed, and the program's own submissions through `CommandQueue::with_vk_queue` before it, where Metal runs it at the release. | MoltenVK 1.4.1 fails pending work that reads device addresses where memory a device-address buffer lay in is freed (`RuntimeDriverDefect::FreedAddressMemoryFailsPendingWork`), so freed memory waits for the batches in flight (`WorkCounts::freed_memory_parked`). | `HostDeallocatorDelayed` (`host-deallocator-delayed`) |
|
||||
| On MoltenVK a `Shared` or `Managed` texture whose format packs more than one texel into a block (every block-compressed family) keeps its image out of host-transfer memory, so its CPU copies take submissions where another driver's take none. The stored texels are Metal's either way; what changes is the work, in `WorkCounts::command_buffers_begun_batch_work` and the `command_buffers_begun` and `command_buffers_submitted` that carry it (`bc1-rgba`, four 16 x 16 `BC1_RGBA` levels: `command_buffers_begun` 8 on the bind-time path and 15 off it; `fresh-texture-bc1-rgba-managed`: 3 and 5). A `replaceRegion` of such a texture stages its bytes for the device's next submission and waits for none (`texture/first_move.rs`). Its CPU **reads** come out of a host shadow of the image's texels, made at the first read of the texture by the submission that read waits for either way and read from by every read after it: exact (it holds the image's own bytes, and a CPU write writes both), bounded (`host_shadow::SHADOW_BYTES`, past which a read takes the submission path), and lazy, so a texture nobody reads back holds nothing. It is dropped wherever anything but a CPU write may have written the texels: every commit of the program's, its own Vulkan submissions, another `VkImage`, a detach, or the program taking the image's handle (`texture/host_shadow.rs`; `WorkCounts::texel_shadows_made`, `texel_shadow_reads`, `texel_shadows_dropped`). Measured on an M3 Max: `compressed-moves-bc1-rgba` reads `internal_submissions` 5 where it read 56 and `command_buffers_begun` 30 where it read 81, for 1,168 bytes of shadow over its five textures and 56 reads out of them. | MoltenVK 1.4.2 binds such an image through a `flushToDevice` that `replaceRegion:`s every subresource at one block's bytes a row instead of the row of blocks, tripping AGX's `bytes_per_row >= used_bytes_per_row` assertion (`RuntimeDriverDefect::HostTransferImagesCopiedAtBind`). The copy is the driver's own and no call of the program's asks for it, so the only way not to provoke it is not to ask for the image; every other driver keeps the host-transfer path, as does a device without `VK_EXT_host_image_copy`. A write cannot leave the GPU's copy of the texels unwritten, so only reads come off the host shadow. | None (cost only, and exact) |
|
||||
| On ANV (Mesa 26.2.4) a pipeline whose largest stage module, under the consumer's exact forms, passes 400,000 words is retranslated with every module-growing exact answer native. Every kind is fitted: render (vertex and fragment), mesh render (object, mesh and fragment, or the stages that emulate them), compute and tile render; the notice names the state's kind. On a large enough module the driver's register allocator reads past its interference bitset and the process faults at pipeline creation. | ANV's `brw` register allocator faults on such modules (`DriverWorkaround::RegisterAllocatorOverflowsLargeModules`), no documented Vulkan form bounds a module's register pressure, and a refusal would withhold the consumer's large shaders. | `ExactFormsOverCompilerLimit` (`exact-forms-over-compiler-limit`) |
|
||||
| On a driver that does not take a set-0 buffer binding whose entry point uses it through several variables as a **dynamic** descriptor, every draw or dispatch of such a variant allocates and writes a descriptor set of its own, where one dynamic binding would let them share one set, bound again at each command's own offset. Such a binding is a slot or store sink reached through its word view and a narrow or `uvec4` unit view (`memory::views`): of the 1,378 store sinks the public fixtures plan on this profile, 20 entries have one (`record_stride_not_a_multiple_of_four`, `encoders_plain`, `encoder_types_*`, `hwd_half_reads`, `kernel_copy_runtime_ulong_length`, `kernel_simdgroup_matrix_block`). The stored values are the same either way; what changes is the set a command allocates and writes (`WorkCounts::set_zero_sets_reused` counts none of them). The device answers for itself, by creating one pipeline of exactly that shape and destroying it (`pipeline::objects::takes_multi_variable_dynamic`, `bind::DynamicViewsModule`, asked once and only where a layout has such a binding), so a driver without the defect pays nothing. A binding the device takes still turns dynamic only while the layout's dynamic-buffer budget lasts (`maxDescriptorSetUniformBuffersDynamic`, `maxDescriptorSetStorageBuffersDynamic`), spent in binding order: on a Radeon 780M (RADV, Mesa 26.2.4, eight dynamic storage buffers) `encoders_plain`'s sink is its twenty-seventh binding and gets none, so that entry keeps a set per dispatch wherever its set 0 is not pushed. A device whose set 0 is pushed (`VK_KHR_push_descriptor` with an eligible layout) never reaches the choice. | Nothing in Vulkan bounds the variables at a binding, dynamic or not, so there is no exact form to switch to: the driver either compiles the shape or does not. MoltenVK's SPIRV-Cross declares one variable's local alone -- read in 1.4.1's source and measured on 1.4.2 (`driverVersion` 10402) on an Apple M3 Max, where `vkCreateComputePipelines` answers `VK_ERROR_INITIALIZATION_FAILED` for a kernel of three and of four variables at one dynamic binding. The check proves the driver compiles the shape, not that it applies the dynamic offset to every variable at it; no device is measured to get that wrong, and RADV (Mesa 26.2.4, Radeon 780M) is measured to get it right, `record_stride_not_a_multiple_of_four` answering Metal's `sizeof` and both its narrow stores with its two-variable and three-variable bindings dynamic. | None (cost only, and exact) |
|
||||
|
||||
## Accuracy switches whose default is Metal's
|
||||
|
||||
Reference in new issue
Block a user