A memory-writing fragment runs as the device runs it, noted DeviceFragmentRuns
What: a fragment function that writes memory no longer counts as per-sample under
multisampling. The coverage loop's memory-writes trigger goes: the loop stays for
`[[sample_id]]` and sample-qualified varyings beside `[[sample_mask]]`, and its refusals
(early fragment tests, attachments, the interpolation functions, discard, quad operations)
no longer reach a memory writer that reads neither. Such a function takes the plain form and
runs as many times per pixel as the device runs it. `GraphicsState::sample_shading`, the
`sampleRateShading` requirement in `multisample_features`, and validation's candidate read of
the field (graphics_pipeline.rs) go with it. consumer-uses.sh: `sample_shading` 0 hits (code)
over the consumer's development a48b3984af and 68 refs.
The new static note `PrecisionNote::DeviceFragmentRuns` goes on the fragment stage of a
pipeline of more than one sample whose function writes memory, recorded by the compile layer
beside `MultisamplePosition`. Its conformance code is
`metal2vulkan-degrade-device-fragment-runs`, and validation's table makes it `Unbounded`.
docs/API.md section 9 lists it, and section 10 adds the accepted difference: "Metal's GPUs
were measured to run a memory-writing fragment once per covered sample; documented Metal names
no count; here the count is the device's."
Why: documented Metal names no run count for a memory-writing fragment. MSL 5.5 makes a
function run per sample only for a sample-qualified input, `[[sample_id]]` or `[[color(m)]]`.
Vulkan without sample shading runs at least one invocation per fragment, and "Multiple
fragment shader invocations may be executed for the same fragment for any number of
implementation-dependent reasons" (vkspec 35.5). One form now covers both classes of guest:
the replay count of 36 streams found no multisampled memory-writing fragment. History: the old
runtime, deleted in 5d725aeec7, applied `sample_shading` (sampleShadingEnable with
minSampleShading 1.0). So at the cutover, memory writers without a coverage read went from once
per covered sample to once per pixel. This commit makes that the stated form, and the coverage
readers now match it.
Conformance: `alpha_coverage_pairs` pinned Metal's measured count, four runs. Its four-sample
report rows now declare `device-fragment-runs` and no longer `looped-sample-outputs`, because
the loop does not fire. They compare the report's runs word (`case/drawn/coverage/0`) as
`Nonzero`, justified by the notice. The coverage word and the texels stay exact.
docs/CONFORMANCE-COVERAGE.md is regenerated.
Tests:
- The lost_writes per-sample test now asserts what Vulkan promises. Every pixel `lw_half`
covers ran at least once and no other pixel ran. Each pixel's ORed mask is its coverage at
the standard 4-sample locations exactly. The state notes DeviceFragmentRuns. The test prints
the (covered samples, runs) histogram.
- The translator's link, engine_multisample, engine_coverage_loop, engine_stencil, compile and
spirv-cross form tests assert the plain form and the note where they asserted sample
shading or the memory writer's loop. The looped-body form test reads cov_loop_record.
SEMANTICS_VERSION 2223 -> 2224 (emitted modules and stored notes change).
ARTIFACT_FORMAT_VERSION 566 -> 567 (a GraphicsState field removed, a PrecisionNote variant
added). api_signatures.tsv is blessed.
Verified: not yet. Jobs follow on this sha.
This commit is contained in:
1 parent
2628c03fb2
commit
3ba18a4b19
27 files changed
+436
-294
No files matched your search
@@ -31,9 +31,10 @@
|
||||
//! stored. So the field acts after the fragment, on the fragment's output, as blending does, and a
|
||||
//! case that tried to read the alpha's coverage from the shader would have measured the rasterizer
|
||||
//! instead. The report is kept because that independence is worth comparing, and because the run
|
||||
//! count says Metal shades this fragment **once per sample** at four samples (four runs, not one),
|
||||
//! which is the shape our own `GraphicsState::sample_shading` claims for a fragment that writes
|
||||
//! memory.
|
||||
//! count says Metal shades this fragment **once per sample** at four samples (four runs, not one).
|
||||
//! Documented Metal names no run count for a fragment that writes memory, and the runtime runs it
|
||||
//! as many times as the device does (`device-fragment-runs`), so the runs word is compared as
|
||||
//! nonzero alone, justified by that notice; the coverage word beside it is compared exactly.
|
||||
//!
|
||||
//! What the alpha's coverage *is* read from is therefore the stored texel, and for the same reason a
|
||||
//! sample mask the **fragment writes** can only be seen there.
|
||||
@@ -115,7 +116,7 @@
|
||||
//! One one-pixel target a row, four samples at most, one triangle a pass, no loop, and a report
|
||||
//! buffer of eight bytes indexed by the one pixel's own coordinate.
|
||||
|
||||
use crate::allowance::Allowance;
|
||||
use crate::allowance::{Allowance, Justification, Loosening};
|
||||
use crate::case::{Abort, Case, Failure, Input, MetalSource, Side};
|
||||
use crate::degradation::Degradation;
|
||||
use crate::fixture::{Fixture, METAL_TEXT, RUNTIME_TEXT};
|
||||
@@ -219,19 +220,22 @@ impl Row {
|
||||
}
|
||||
}
|
||||
|
||||
/// What a **four-sample** row with an alpha output announced: the coverage of a clipped edge split
|
||||
/// per sample (`clipped-coverage-split`) and the sample outputs written in a loop
|
||||
/// (`looped-sample-outputs`), with `alphaToCoverage` on or off. With it on, the device's own
|
||||
/// conversion of the alpha into the attachment (`device-color-conversion`) and its own coverage of
|
||||
/// the alpha (`device-alpha-coverage`) fire too, which the suite declares for every case
|
||||
/// The report's runs word, the first of its two: the element at byte offset 0 of the coverage site.
|
||||
const RUNS_WORD: &str = "case/drawn/coverage/0";
|
||||
|
||||
/// What a **four-sample** row with an alpha output announces: the coverage of a clipped edge split
|
||||
/// per sample (`clipped-coverage-split`), with `alphaToCoverage` on or off, measured on the RTX
|
||||
/// 5080 Laptop (615.71.09) for all ten such rows, each divergent on the notices site and nothing
|
||||
/// else (replay-nvidia.log); and the run count of its fragment, which writes memory, as the
|
||||
/// device's (`device-fragment-runs`), which the compile records for such a fragment in a pipeline
|
||||
/// of more than one sample. With the field on, the device's own conversion of the alpha into the
|
||||
/// attachment (`device-color-conversion`) and its own coverage of the alpha
|
||||
/// (`device-alpha-coverage`) fire too, which the suite declares for every case
|
||||
/// ([`crate::replay::NATIVE_NOTES`]). A four-sample row whose fragment writes **no alpha** names
|
||||
/// none: nothing narrows the coverage, so neither the split nor the looped outputs fire.
|
||||
///
|
||||
/// Measured on the RTX 5080 Laptop (615.71.09) for all ten such rows, each divergent on the
|
||||
/// notices site and nothing else (replay-nvidia.log).
|
||||
/// none: it reads no coverage and writes no memory.
|
||||
const ALPHA_MULTISAMPLE: &[Degradation] = &[
|
||||
Degradation::ClippedCoverageSplit,
|
||||
Degradation::LoopedSampleOutputs,
|
||||
Degradation::DeviceFragmentRuns,
|
||||
];
|
||||
|
||||
/// A single-sample row, whose store announces nothing but the device's own answers, which the suite
|
||||
@@ -500,16 +504,27 @@ impl Case for AlphaCoverageCase {
|
||||
}
|
||||
|
||||
fn allowances(&self) -> Vec<Allowance> {
|
||||
// **No value is loosened.** The coverage report is an integer, and the resolve of `k`
|
||||
// covered samples against `4 - k` uncovered is compared exactly, which is this suite's
|
||||
// ruling for the same shape in `super::sample_positions`. Every entry below is a notice
|
||||
// declaration at `case/notices/*`, which moves no coverage and no texel. The notices are
|
||||
// [`Row::notices`], the set measured **for that row** rather than for the family.
|
||||
self.row
|
||||
// **One value is loosened: the run count.** The coverage word is an integer, and the
|
||||
// resolve of `k` covered samples against `4 - k` uncovered is compared exactly, which is
|
||||
// this suite's ruling for the same shape in `super::sample_positions`. The notices are
|
||||
// [`Row::notices`], each a declaration at `case/notices/*` that moves no coverage and no
|
||||
// texel. A row that announces `device-fragment-runs` compares its report's runs word, the
|
||||
// first, as nonzero alone: documented Metal names no count of runs for a fragment that
|
||||
// writes memory, and the device's count is the runtime's.
|
||||
let mut allowances: Vec<Allowance> = self
|
||||
.row
|
||||
.notices
|
||||
.iter()
|
||||
.map(|kind| crate::replay::notice_allowance(kind.code()))
|
||||
.collect()
|
||||
.collect();
|
||||
if self.row.notices.contains(&Degradation::DeviceFragmentRuns) {
|
||||
allowances.push(Allowance::new(
|
||||
RUNS_WORD,
|
||||
Loosening::Nonzero,
|
||||
Justification::notice(Degradation::DeviceFragmentRuns),
|
||||
));
|
||||
}
|
||||
allowances
|
||||
}
|
||||
|
||||
fn shaders(&self) -> Result<Vec<ShaderRef>, String> {
|
||||
@@ -999,29 +1014,47 @@ mod tests {
|
||||
}
|
||||
|
||||
/// Every row fingerprints its own inputs, so no recording can be read for another row, and no
|
||||
/// row loosens a **value**: every allowance it names is a notice declaration at
|
||||
/// `case/notices/*`, which the comparison reads as the set of notices our side announced and
|
||||
/// never as a tolerance on a coverage or a texel.
|
||||
/// row loosens a **value** but the run count: every allowance it names is a notice declaration
|
||||
/// at `case/notices/*`, which the comparison reads as the set of notices our side announced and
|
||||
/// never as a tolerance on a coverage or a texel, or, for a four-sample row with a report, its
|
||||
/// runs word as nonzero, justified by `device-fragment-runs`.
|
||||
#[test]
|
||||
fn every_row_fingerprints_apart_and_nothing_is_loosened() {
|
||||
fn every_row_fingerprints_apart_and_only_the_run_count_is_loosened() {
|
||||
let notices = format!("case/{}/*", crate::replay::NOTICES_SITE);
|
||||
let runs = Justification::notice(Degradation::DeviceFragmentRuns);
|
||||
let mut seen: Vec<Vec<u8>> = Vec::new();
|
||||
for case in all() {
|
||||
let reports_runs = case.row.samples > 1 && case.row.report != Report::NoAlpha;
|
||||
assert_eq!(
|
||||
case.row.notices.contains(&Degradation::DeviceFragmentRuns),
|
||||
reports_runs,
|
||||
"{}",
|
||||
case.name()
|
||||
);
|
||||
for allowance in case.allowances() {
|
||||
assert_eq!(allowance.path, notices, "{}: a loosened value", case.name());
|
||||
assert!(
|
||||
matches!(
|
||||
allowance.justified_by,
|
||||
crate::allowance::Justification::Degradation(_)
|
||||
matches!(allowance.justified_by, Justification::Degradation(_)),
|
||||
"{}: an allowance that is not a notice's",
|
||||
case.name()
|
||||
);
|
||||
if allowance.path == notices {
|
||||
continue;
|
||||
}
|
||||
assert_eq!(
|
||||
(
|
||||
allowance.path.as_str(),
|
||||
&allowance.loosening,
|
||||
&allowance.justified_by
|
||||
),
|
||||
"{}: an allowance that is not a notice declaration",
|
||||
(RUNS_WORD, &Loosening::Nonzero, &runs),
|
||||
"{}: a loosened value",
|
||||
case.name()
|
||||
);
|
||||
}
|
||||
// Whatever the row itself was measured announcing.
|
||||
// Whatever the row itself announces, and the runs word where it reports them.
|
||||
assert_eq!(
|
||||
case.allowances().len(),
|
||||
case.row.notices.len(),
|
||||
case.row.notices.len() + usize::from(reports_runs),
|
||||
"{}",
|
||||
case.name()
|
||||
);
|
||||
|
||||
@@ -185,6 +185,8 @@ pub enum Degradation {
|
||||
SwizzledOpaqueBlackBorder,
|
||||
/// `metal2vulkan-degrade-device-line-rasterization`.
|
||||
DeviceLineRasterization,
|
||||
/// `metal2vulkan-degrade-device-fragment-runs`.
|
||||
DeviceFragmentRuns,
|
||||
}
|
||||
|
||||
impl Degradation {
|
||||
@@ -277,6 +279,7 @@ impl Degradation {
|
||||
Degradation::DeviceDepthBias,
|
||||
Degradation::SwizzledOpaqueBlackBorder,
|
||||
Degradation::DeviceLineRasterization,
|
||||
Degradation::DeviceFragmentRuns,
|
||||
];
|
||||
|
||||
/// The kind's code, `metal2vulkan-degrade-<kind>`.
|
||||
@@ -415,6 +418,7 @@ impl Degradation {
|
||||
Degradation::DeviceLineRasterization => {
|
||||
"metal2vulkan-degrade-device-line-rasterization"
|
||||
}
|
||||
Degradation::DeviceFragmentRuns => "metal2vulkan-degrade-device-fragment-runs",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,6 +518,7 @@ impl Degradation {
|
||||
PrecisionNote::DeviceReconvergence => Degradation::DeviceReconvergence,
|
||||
PrecisionNote::SimdgroupAccessOrder => Degradation::SimdgroupAccessOrder,
|
||||
PrecisionNote::DeviceLineRasterization => Degradation::DeviceLineRasterization,
|
||||
PrecisionNote::DeviceFragmentRuns => Degradation::DeviceFragmentRuns,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,12 @@
|
||||
//! gaps of pipeline states), and the argument buffer's form joins the test once they do.
|
||||
//! - A memory-writing fragment at 4 samples: `lw_count` reads `[[sample_mask]]`, adds 1 to its
|
||||
//! pixel's run count and ORs the mask into its pixel's word, drawn by `lw_half` over the
|
||||
//! target's lower-left half. Metal runs such a function once per covered sample, each run
|
||||
//! reading the pixel's whole coverage: each pixel's count is its mask's bits, every pixel
|
||||
//! inside the triangle is all four samples, and some on its diagonal fewer. Measured on Apple's
|
||||
//! GPU through a driver that also ran each such shader per covered sample: a looping function
|
||||
//! counted each covered sample once per covered sample.
|
||||
//! target's lower-left half. Apple's GPUs were measured to run such a function once per covered
|
||||
//! sample, each run reading the pixel's whole coverage; documented Metal names no count, and the
|
||||
//! runtime runs it as the device does (`PrecisionNote::DeviceFragmentRuns`). The test holds the
|
||||
//! device to what Vulkan promises: every pixel the triangle covers ran at least once and no
|
||||
//! other pixel ran, and the masks a pixel's runs read are its coverage at the standard sample
|
||||
//! locations, exactly. It prints how many runs each count of covered samples took.
|
||||
//!
|
||||
//! `llvm-as` assembles the fixture; without it the tests skip visibly.
|
||||
|
||||
@@ -37,8 +38,9 @@ mod on_device {
|
||||
use crate::tests::draw::on_device::{library, pass, run, state, Buffers};
|
||||
use crate::{
|
||||
ColorAttachmentDescriptor, CullMode, Device, Error, FunctionDescriptor, IndexClass,
|
||||
Library, NumberedSampler, PixelFormat, PrimitiveType, Region, RenderPipelineDescriptor,
|
||||
StageSource, StorageMode, Texture, TextureDescriptor, TextureType, TextureUsage,
|
||||
Library, NumberedSampler, PixelFormat, PrecisionNote, PrimitiveType, Region,
|
||||
RenderPipelineDescriptor, StageSource, StorageMode, Texture, TextureDescriptor,
|
||||
TextureType, TextureUsage,
|
||||
};
|
||||
use metal2vulkan_devtools::fixtures_dir;
|
||||
|
||||
@@ -334,16 +336,43 @@ mod on_device {
|
||||
});
|
||||
}
|
||||
|
||||
/// A memory-writing fragment at 4 samples runs once per covered sample, each run reading the
|
||||
/// pixel's whole coverage: each pixel's run count is its mask's bits.
|
||||
/// The samples of pixel `(x, y)` that `lw_half` covers at Vulkan's standard 4-sample
|
||||
/// locations, bit `i` for sample `i`: its triangle covers the framebuffer points with
|
||||
/// `x / WIDTH <= y / HEIGHT`, and no sample lies on that edge.
|
||||
fn half_coverage(x: u32, y: u32) -> u32 {
|
||||
const STANDARD_4: [(f64, f64); 4] = [
|
||||
(0.375, 0.125),
|
||||
(0.875, 0.375),
|
||||
(0.125, 0.625),
|
||||
(0.625, 0.875),
|
||||
];
|
||||
(STANDARD_4.iter().enumerate())
|
||||
.filter(|(_, (sx, sy))| {
|
||||
(f64::from(x) + sx) * f64::from(HEIGHT) <= (f64::from(y) + sy) * f64::from(WIDTH)
|
||||
})
|
||||
.fold(0, |mask, (i, _)| mask | 1 << i)
|
||||
}
|
||||
|
||||
/// A memory-writing fragment at 4 samples runs as many times as the device runs it, which its
|
||||
/// state notes (`PrecisionNote::DeviceFragmentRuns`). Vulkan runs at least one invocation for a
|
||||
/// fragment, includes each covered sample in at least one, and sets an invocation's
|
||||
/// `SampleMask` bit "if and only if the sample is considered covered for this fragment shader
|
||||
/// invocation" (vkspec 35.5 and the `SampleMask` built-in): so every covered pixel ran at least
|
||||
/// once, no other pixel ran, and the masks each pixel's runs ORed are its coverage exactly.
|
||||
#[test]
|
||||
fn every_device_runs_a_memory_writing_fragment_once_per_covered_sample() {
|
||||
fn every_device_runs_a_memory_writing_fragment_at_least_once_per_covered_pixel() {
|
||||
let Some(library) = fixture() else {
|
||||
return;
|
||||
};
|
||||
let d = descriptor(&library, "lw_half", "lw_count", 4);
|
||||
each_device("lost_writes_per_sample", |name, _, device| {
|
||||
let state = state(name, &device, &d);
|
||||
assert!(
|
||||
state
|
||||
.precision_notes()
|
||||
.contains(&PrecisionNote::DeviceFragmentRuns),
|
||||
"{name}: the state does not note the device's runs"
|
||||
);
|
||||
let pixels = (WIDTH * HEIGHT) as usize;
|
||||
let mut buffers = Buffers::new(&device);
|
||||
let runs = buffers.of(&device, &vec![0; pixels * 4]);
|
||||
@@ -370,23 +399,35 @@ mod on_device {
|
||||
.to_vec()
|
||||
};
|
||||
let (runs, masks) = (read(&runs), read(&masks));
|
||||
let wrong: Vec<(usize, u32, u32)> = (0..pixels)
|
||||
.filter(|&p| runs[p] != masks[p].count_ones() || masks[p] > 0xf)
|
||||
.map(|p| (p, runs[p], masks[p]))
|
||||
// Pixel `p` is `(p % WIDTH, p / WIDTH)`, as `lw_count` indexes its words.
|
||||
let coverage: Vec<u32> = (0..pixels as u32)
|
||||
.map(|p| half_coverage(p % WIDTH, p / WIDTH))
|
||||
.collect();
|
||||
let wrong: Vec<(usize, u32, u32, u32)> = (0..pixels)
|
||||
.filter(|&p| masks[p] != coverage[p] || (runs[p] == 0) != (coverage[p] == 0))
|
||||
.map(|p| (p, runs[p], masks[p], coverage[p]))
|
||||
.collect();
|
||||
assert!(
|
||||
wrong.is_empty(),
|
||||
"{name}: (pixel, runs, mask) not once per covered sample: {wrong:?}"
|
||||
"{name}: (pixel, runs, mask, coverage) off Vulkan's promise: {wrong:?}"
|
||||
);
|
||||
let full = masks.iter().filter(|&&m| m == 0xf).count();
|
||||
let partial = masks.iter().filter(|&&m| m != 0 && m != 0xf).count();
|
||||
let empty = masks.iter().filter(|&&m| m == 0).count();
|
||||
let full = coverage.iter().filter(|&&m| m == 0xf).count();
|
||||
let partial = coverage.iter().filter(|&&m| m != 0 && m != 0xf).count();
|
||||
let empty = coverage.iter().filter(|&&m| m == 0).count();
|
||||
assert!(
|
||||
full > 0 && partial > 0 && empty > 0,
|
||||
"{name}: {full} covered pixels, {partial} partly, {empty} not"
|
||||
);
|
||||
// How many runs each count of covered samples took: (covered samples, runs) -> pixels.
|
||||
let mut taken = std::collections::BTreeMap::<(u32, u32), usize>::new();
|
||||
for p in (0..pixels).filter(|&p| coverage[p] != 0) {
|
||||
*taken
|
||||
.entry((coverage[p].count_ones(), runs[p]))
|
||||
.or_default() += 1;
|
||||
}
|
||||
println!(
|
||||
"{name}: {full} covered pixels ran 4 times, {partial} on the edge once per covered sample"
|
||||
"{name}: {full} pixels covered, {partial} partly, {empty} not; (covered samples, \
|
||||
runs) -> pixels: {taken:?}"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -335,7 +335,6 @@ fn a_multisampled_stencil_output_case_plans_a_shadow_of_its_samples() {
|
||||
let (pipeline, _, _) = planned_draw(&device("nvidia-rtx50-linux"), &render, libraries).unwrap();
|
||||
let shadow = pipeline.graphics.shadow_stencil.expect("the shadow");
|
||||
assert_eq!((shadow.format, shadow.samples), (vk::Format::R8_UINT, 4));
|
||||
assert!(!pipeline.graphics.sample_shading);
|
||||
let requirements = &pipeline.requirements;
|
||||
assert!(requirements.features.contains(&VkFeature::Maintenance8));
|
||||
assert!(requirements
|
||||
|
||||
@@ -563,10 +563,6 @@ pub(super) fn create_graphics_pipeline(
|
||||
.line_width(1.0);
|
||||
let mut multisample = vk::PipelineMultisampleStateCreateInfo::default()
|
||||
.rasterization_samples(graphics.rasterization_samples.into())
|
||||
// Metal's once-per-covered-sample invocations of a function that writes memory; the minimum
|
||||
// is ignored without sample shading, and stays Vulkan's default there.
|
||||
.sample_shading_enable(graphics.sample_shading)
|
||||
.min_sample_shading(if graphics.sample_shading { 1.0 } else { 0.0 })
|
||||
.alpha_to_coverage_enable(graphics.alpha_to_coverage)
|
||||
.alpha_to_one_enable(graphics.alpha_to_one);
|
||||
// The descriptor's private sample mask, one word.
|
||||
|
||||
@@ -347,7 +347,8 @@ pub fn allowance(note: PrecisionNote) -> Allowance {
|
||||
| N::CompressedTexelDecode
|
||||
| N::SharedExponentKept
|
||||
| N::SwizzledOpaqueBlackBorder
|
||||
| N::DeviceLineRasterization => Allowance::Unbounded,
|
||||
| N::DeviceLineRasterization
|
||||
| N::DeviceFragmentRuns => Allowance::Unbounded,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ fn every_precision_note_has_its_table_row() {
|
||||
(N::SwizzledOpaqueBlackBorder, Allowance::Unbounded),
|
||||
(N::SimdgroupAccessOrder, Allowance::Unbounded),
|
||||
(N::DeviceLineRasterization, Allowance::Unbounded),
|
||||
(N::DeviceFragmentRuns, Allowance::Unbounded),
|
||||
];
|
||||
for (note, expected) in rows {
|
||||
assert_eq!(allowance(note), expected, "{note:?}");
|
||||
|
||||
+2
-1
@@ -1409,7 +1409,7 @@ codec_struct! {
|
||||
alpha_to_coverage, alpha_to_one, rasterizer_discard, dynamic_states, input_attachments,
|
||||
rasterization_order_attachment_access, max_vertex_amplification_count, declares_layer,
|
||||
tessellation,
|
||||
fragment_imageblock, sample_shading, vertex_writes_memory, writes_viewport_index,
|
||||
fragment_imageblock, vertex_writes_memory, writes_viewport_index,
|
||||
storage_attachments, shadow_stencil, early_fragment_tests,
|
||||
writes_point_size, flat_fragment_inputs,
|
||||
clip_distances, writes_depth, reads_barycentric_coord, reads_primitive_id,
|
||||
@@ -1523,6 +1523,7 @@ codec_enum! {
|
||||
SwizzledOpaqueBlackBorder,
|
||||
SimdgroupAccessOrder,
|
||||
DeviceLineRasterization,
|
||||
DeviceFragmentRuns,
|
||||
}
|
||||
BindingSource {
|
||||
Buffer(f0), Texture(f0), Sampler(f0), CombinedTextureSampler { texture, sampler },
|
||||
|
||||
Vendored
+1
-1
@@ -61,7 +61,7 @@ mod tests;
|
||||
/// unchanged version, and its bless records the version. Independent of the crate's version and of
|
||||
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
|
||||
/// history.
|
||||
pub const SEMANTICS_VERSION: u32 = 2223;
|
||||
pub const SEMANTICS_VERSION: u32 = 2224;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
|
||||
@@ -29,11 +29,10 @@
|
||||
//! access is the arena's: contained against `TileThreadgroupLength`, its sub-word stores and its
|
||||
//! atomics `Device`-scope word atomics of the buffer, ordering it as device memory. A write of it
|
||||
//! (a store, or any atomic) needs `fragmentStoresAndAtomics`. A function that writes it writes
|
||||
//! memory (`StageInterface::writes_memory`), so in a multisampled pipeline link runs it once per
|
||||
//! covered sample under the pipeline's sample shading, as Metal runs it (it needs
|
||||
//! `sampleRateShading`, and one compiled without `multisampled` is `NeedsInput(Multisampled)`, as
|
||||
//! it reads `FragCoord`); one that only reads it runs once per pixel, reading what each of the
|
||||
//! pixel's samples would.
|
||||
//! memory (`StageInterface::writes_memory`), so in a multisampled pipeline it runs as many times
|
||||
//! per pixel as the device runs it (`PrecisionNote::DeviceFragmentRuns`), where Apple's GPUs run
|
||||
//! it once per covered sample; one that only reads it reads what each of the pixel's samples
|
||||
//! would.
|
||||
//!
|
||||
//! **Order.** The fragments of one draw reach the memory as Metal's do, unordered but for their
|
||||
//! atomics. The render encoder orders draws that reach it in encode order across render pass
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! `[[sample_mask]]` in a fragment function that Metal runs once per covered sample.
|
||||
//!
|
||||
//! Metal runs a fragment function of a multisampled pipeline once per covered sample when it
|
||||
//! reads `[[sample_id]]` or a sample-qualified varying, or writes memory, and hands every one of
|
||||
//! those runs the pixel's whole coverage as `[[sample_mask]]`, each run its own sample index and
|
||||
//! reads `[[sample_id]]` or a sample-qualified varying, and hands every one of those runs the
|
||||
//! pixel's whole coverage as `[[sample_mask]]`, each run its own sample index and
|
||||
//! its sample-qualified varyings at its sample, and everything else at the pixel (an M3 Max and an
|
||||
//! M4, measured). A Vulkan invocation under sample shading sees only its own sample's bit of the
|
||||
//! coverage, and nothing gathers a pixel's sample invocations, so such a function, compiled for a
|
||||
@@ -137,8 +137,8 @@ fn sampled_varying(cx: &SelectCx<'_>, param: u32, role: &ParamRole, sampling: Ai
|
||||
|
||||
/// Plan the loop over the covered samples before the stage interface (`fragment::plan_entry`):
|
||||
/// a fragment function that reads `[[sample_mask]]` and runs once per covered sample on Metal (it
|
||||
/// reads `[[sample_id]]` or a sample-qualified varying, or has a memory side effect) loops,
|
||||
/// compiled for a multisampled pipeline, unless its interface already shows why it cannot.
|
||||
/// reads `[[sample_id]]` or a sample-qualified varying) loops, compiled for a multisampled
|
||||
/// pipeline, unless its interface already shows why it cannot.
|
||||
pub(super) fn plan(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
if cx.stage != Stage::Fragment {
|
||||
return Ok(());
|
||||
@@ -167,11 +167,9 @@ pub(super) fn plan(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
}
|
||||
let sample_id = used(&|r| matches!(r, ParamRole::Builtin(Builtin::SampleId)));
|
||||
let sample_varying = varying(cx, AirSampling::Sample);
|
||||
let writes = body
|
||||
.insts
|
||||
.iter()
|
||||
.any(|(id, inst)| super::discard::side_effect(cx, id, inst));
|
||||
let per_sample = sample_id || sample_varying || writes;
|
||||
// A function that writes memory runs as the device runs it, as any other
|
||||
// (`PrecisionNote::DeviceFragmentRuns`): documented Metal names no count for it.
|
||||
let per_sample = sample_id || sample_varying;
|
||||
// A multisampled read of the coverage, or of a centroid varying at the pixel, meets no split
|
||||
// of a clipped primitive, where Metal's can (the module docs).
|
||||
if cx.inputs.multisampled && (mask || !per_sample) {
|
||||
|
||||
@@ -618,7 +618,6 @@ mod serde_round_trips {
|
||||
data_size: 12,
|
||||
alignment: 4,
|
||||
}),
|
||||
sample_shading: true,
|
||||
vertex_writes_memory: true,
|
||||
writes_viewport_index: true,
|
||||
storage_attachments: vec![StorageAttachmentUse {
|
||||
|
||||
@@ -2347,6 +2347,22 @@ pub enum PrecisionNote {
|
||||
/// Validation derives no tolerance from it: a difference stays a mismatch, which the note
|
||||
/// explains.
|
||||
DeviceLineRasterization,
|
||||
/// A fragment function that writes memory (`StageInterface::writes_memory`) in a render
|
||||
/// pipeline of more than one sample runs as many times per pixel as the device runs it, each
|
||||
/// run reading the pixel's whole coverage as `[[sample_mask]]` (a function that loops over its
|
||||
/// covered samples, `CoverageLoop::Looped`, runs its loop in each). Documented Metal names no
|
||||
/// run count for it: MSL's section 5.5 names only sample-qualified inputs, `[[sample_id]]` and
|
||||
/// `[[color(m)]]` as making a function run per sample. Apple's GPUs were measured to run such a
|
||||
/// function once per covered sample (an M3 Max and an M4). Vulkan runs a fragment shader
|
||||
/// without sample shading at least once per pixel, and more where the device chooses ("Multiple
|
||||
/// fragment shader invocations may be executed for the same fragment for any number of
|
||||
/// implementation-dependent reasons", vkspec 35.5). So its writes repeat as often as the
|
||||
/// device's runs. Static, decided by the pipeline's sample count and the function's writes:
|
||||
/// the pipeline's compile records it on its fragment stage.
|
||||
///
|
||||
/// Validation derives no tolerance from it: a difference stays a mismatch, which the note
|
||||
/// explains.
|
||||
DeviceFragmentRuns,
|
||||
}
|
||||
|
||||
/// The math mode of an entry's module, which decides, on a device whose `float` functions are
|
||||
|
||||
@@ -662,6 +662,7 @@ impl Device {
|
||||
stages.push(stage_module(c, &linked, i)?);
|
||||
}
|
||||
note_sample_position(d.into(), &artifacts, &mut stages);
|
||||
note_device_runs(d.into(), &artifacts, &mut stages);
|
||||
let keys: Vec<FunctionCompileKey> = artifacts.iter().map(|a| a.key).collect();
|
||||
let mut requirements = mesh.artifact().requirements.clone();
|
||||
for a in artifacts
|
||||
@@ -945,6 +946,7 @@ impl Device {
|
||||
stages.push(stage_module(c, &linked, i)?);
|
||||
}
|
||||
note_sample_position(pass(), &artifacts, &mut stages);
|
||||
note_device_runs(pass(), &artifacts, &mut stages);
|
||||
let keys: Vec<FunctionCompileKey> = artifacts.iter().map(|a| a.key).collect();
|
||||
let mut requirements = vertex.artifact().requirements.clone();
|
||||
for a in artifacts.iter().skip(1) {
|
||||
@@ -1917,6 +1919,31 @@ fn note_sample_position(
|
||||
}
|
||||
}
|
||||
|
||||
/// Record `PrecisionNote::DeviceFragmentRuns` on the fragment stage of a pipeline of pass `d` that
|
||||
/// rasterizes more than one sample, where its function writes memory: it runs as many times per
|
||||
/// pixel as the device runs it.
|
||||
fn note_device_runs(
|
||||
d: FragmentPass<'_>,
|
||||
stages: &[&FunctionArtifact],
|
||||
modules: &mut [StageModule],
|
||||
) {
|
||||
if d.raster_sample_count <= 1 || !d.rasterization_enabled {
|
||||
return;
|
||||
}
|
||||
for (a, m) in stages.iter().zip(modules) {
|
||||
if a.interface.stage != Stage::Fragment || !a.interface.writes_memory {
|
||||
continue;
|
||||
}
|
||||
if !m
|
||||
.precision_notes
|
||||
.contains(&PrecisionNote::DeviceFragmentRuns)
|
||||
{
|
||||
m.precision_notes.push(PrecisionNote::DeviceFragmentRuns);
|
||||
m.precision_notes.sort_unstable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Every runtime fact of the stages, once, with the mechanism this profile honors it by.
|
||||
fn dependencies(stages: &[&FunctionArtifact], dev: &Device) -> Vec<RuntimeDependency> {
|
||||
let mut out: Vec<RuntimeDependency> = Vec::new();
|
||||
|
||||
@@ -3680,11 +3680,12 @@ entry:
|
||||
"#;
|
||||
|
||||
/// A multisampled render pipeline whose fragment function only reads through a pointer it loads
|
||||
/// from a buffer (`WIDE_READ`) runs it at pixel rate: the resident-miss count its access keeps in
|
||||
/// the `ExecutionStatus` buffer is the product's write, not the function's, so the pipeline needs
|
||||
/// no sample shading and compiles on moltenvk-m3 as on lavapipe.
|
||||
/// from a buffer (`WIDE_READ`) does not write memory: the resident-miss count its access keeps in
|
||||
/// the `ExecutionStatus` buffer is the product's write, not the function's, so its fragment stage
|
||||
/// records nothing of its runs (`PrecisionNote::DeviceFragmentRuns`) and compiles on moltenvk-m3 as
|
||||
/// on lavapipe.
|
||||
#[test]
|
||||
fn a_fragment_reading_through_a_loaded_pointer_runs_at_pixel_rate() {
|
||||
fn a_fragment_reading_through_a_loaded_pointer_writes_no_memory() {
|
||||
let Some(bc) = assemble_text("wide_read", WIDE_READ) else {
|
||||
return;
|
||||
};
|
||||
@@ -3703,7 +3704,12 @@ fn a_fragment_reading_through_a_loaded_pointer_runs_at_pixel_rate() {
|
||||
let pipe = device(stem)
|
||||
.compile_render_pipeline(&d, &Budget::standard())
|
||||
.unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
assert!(!pipe.graphics.sample_shading, "{stem}");
|
||||
assert!(
|
||||
!pipe.stages.iter().any(|m| m
|
||||
.precision_notes
|
||||
.contains(&crate::pipeline::PrecisionNote::DeviceFragmentRuns)),
|
||||
"{stem}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,13 +93,6 @@ pub struct GraphicsState {
|
||||
/// consumer binds the pass's imageblock storage to every draw of the pass
|
||||
/// (`WriteSource::Imageblock`).
|
||||
pub fragment_imageblock: Option<FragmentImageblock>,
|
||||
/// `VkPipelineMultisampleStateCreateInfo::sampleShadingEnable`, with `minSampleShading` 1.0:
|
||||
/// the pipeline rasterizes more than one sample and its fragment function writes memory
|
||||
/// (`StageInterface::writes_memory`), which Metal runs once per covered sample. The pipeline's
|
||||
/// requirements name `sampleRateShading`
|
||||
/// (`VUID-VkPipelineMultisampleStateCreateInfo-sampleShadingEnable-00784`). Without it the
|
||||
/// consumer leaves sample shading disabled.
|
||||
pub sample_shading: bool,
|
||||
/// The vertex function (a post-tessellation vertex function included) writes memory
|
||||
/// (`StageInterface::writes_memory`): each run of the pipeline's vertex stage repeats its
|
||||
/// side effects. A rate-mapped pass drawn region by region records each draw once per region,
|
||||
@@ -525,7 +518,6 @@ impl GraphicsState {
|
||||
declares_layer: false,
|
||||
tessellation: None,
|
||||
fragment_imageblock: None,
|
||||
sample_shading: false,
|
||||
vertex_writes_memory: false,
|
||||
writes_viewport_index: false,
|
||||
storage_attachments: Vec::new(),
|
||||
@@ -612,16 +604,11 @@ impl GraphicsState {
|
||||
features
|
||||
}
|
||||
|
||||
/// The features the pipeline's multisample state needs: `sampleRateShading` for
|
||||
/// [`sample_shading`](GraphicsState::sample_shading)
|
||||
/// (`VUID-VkPipelineMultisampleStateCreateInfo-sampleShadingEnable-00784`), and `alphaToOne`
|
||||
/// for [`alpha_to_one`](GraphicsState::alpha_to_one)
|
||||
/// The features the pipeline's multisample state needs: `alphaToOne` for
|
||||
/// [`alpha_to_one`](GraphicsState::alpha_to_one)
|
||||
/// (`VUID-VkPipelineMultisampleStateCreateInfo-alphaToOneEnable-00785`).
|
||||
pub(crate) fn multisample_features(&self) -> BTreeSet<VkFeature> {
|
||||
let mut features = BTreeSet::new();
|
||||
if self.sample_shading {
|
||||
features.insert(VkFeature::SampleRateShading);
|
||||
}
|
||||
if self.alpha_to_one {
|
||||
features.insert(VkFeature::AlphaToOne);
|
||||
}
|
||||
|
||||
@@ -73,11 +73,15 @@
|
||||
//! per sample, and an Apple M3 Max ran a function with a device atomic once per covered sample
|
||||
//! under 4x multisampling with or without one.
|
||||
//! - **Fragment invocations under multisampling**. With `rasterSampleCount` above 1 and
|
||||
//! rasterization on, Metal (Apple M3 Max, 4x, measured) runs a fragment function that writes
|
||||
//! memory once per covered sample, whatever its inputs, and every invocation reads `[[position]]`
|
||||
//! (x, y, z, and w), its center and centroid varyings, `[[point_coord]]`, and
|
||||
//! `[[barycentric_coord]]` as the pixel's, and `[[sample_mask]]` as the pixel's coverage; only
|
||||
//! `[[sample_id]]` and sample-qualified varyings are the sample's. Vulkan runs a fragment shader
|
||||
//! rasterization on, Metal runs a fragment function that reads `[[sample_id]]` or a
|
||||
//! sample-qualified varying per sample (MSL 5.5: the function "may execute per-sample"), and every
|
||||
//! invocation reads `[[position]]` (x, y, z, and w), its center and centroid varyings,
|
||||
//! `[[point_coord]]`, and `[[barycentric_coord]]` as the pixel's, and `[[sample_mask]]` as the
|
||||
//! pixel's coverage; only `[[sample_id]]` and sample-qualified varyings are the sample's (Apple M3
|
||||
//! Max, 4x, measured). Documented Metal names no run count for any other function: one that
|
||||
//! writes memory runs as any other, as many times as the device runs it (Apple's GPUs were
|
||||
//! measured to run it once per covered sample; Vulkan runs a fragment shader at least once per
|
||||
//! pixel, `PrecisionNote::DeviceFragmentRuns`). Vulkan runs a fragment shader
|
||||
//! once per covered sample only under sample shading, which a `SampleId` input turns on and a
|
||||
//! `Sample` input may, and sample shading moves `FragCoord` to the sample, lets an undecorated or
|
||||
//! `Centroid` input interpolate anywhere in the sample's area, may move `PointCoord` there, and
|
||||
@@ -87,12 +91,9 @@
|
||||
//! pixel center, its center varyings through that instruction at offset 0, or, where the device
|
||||
//! reads them at the pixel center itself as Metal does (`VkProperty::MetalCenterVaryings`,
|
||||
//! MoltenVK), as they are: both the pixel center whatever the invocation shades
|
||||
//! (`StageIo::{multisampled, varyings_at_pixel, position_depth}`). A function that writes memory
|
||||
//! (`StageInterface::writes_memory`) runs under the pipeline's sample shading at a minimum of 1.0
|
||||
//! (`GraphicsState::sample_shading`, needing `sampleRateShading`), as one that reads
|
||||
//! `[[sample_id]]` does: once per covered sample, where a Vulkan stage without sample shading
|
||||
//! runs at least once per pixel. A function that runs per sample (one of those, or one that
|
||||
//! reads a sample-qualified varying) beside `[[sample_mask]]` cannot run under sample shading:
|
||||
//! (`StageIo::{multisampled, varyings_at_pixel, position_depth}`). A function that runs per
|
||||
//! sample (one that reads `[[sample_id]]` or a sample-qualified varying) beside `[[sample_mask]]`
|
||||
//! cannot run under sample shading:
|
||||
//! Vulkan gives an invocation under sample shading only the bits of the samples it shades, a quad
|
||||
//! holds one sample index, and no subgroup is promised to hold a pixel's other sample
|
||||
//! invocations, so no form gathers the pixel's coverage. Compiled for the pipeline, such a
|
||||
@@ -702,7 +703,7 @@ pub fn graphics_state(
|
||||
return Err(Error::NeedsInput(RuntimeInput::Multisampled));
|
||||
}
|
||||
}
|
||||
let sample_shading = sample_invocations(r, fs, p)?;
|
||||
sample_invocations(r, fs, p)?;
|
||||
use vk::DynamicState as D;
|
||||
let mut dynamic_states = vec![
|
||||
D::VIEWPORT,
|
||||
@@ -786,7 +787,6 @@ pub fn graphics_state(
|
||||
// The fragment stage's facts decide them (`link::fetch`).
|
||||
storage_attachments: Vec::new(),
|
||||
shadow_stencil: None,
|
||||
sample_shading,
|
||||
vertex_writes_memory: vs.writes_memory,
|
||||
// Stored as the builtin, through the synthesized geometry stages, or (on a device with
|
||||
// one viewport) nowhere: the raw varying is written in every case.
|
||||
@@ -904,28 +904,26 @@ fn interpolates_at_sample(io: &StageIo) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Check how the fragment stage `fs` runs and reads under multisampling (see the module docs),
|
||||
/// returning whether the pipeline enables sample shading at a minimum of 1.0
|
||||
/// (`GraphicsState::sample_shading`). With more than one sample and rasterization on, a function
|
||||
/// that writes memory runs per covered sample under sample shading, which needs
|
||||
/// `sampleRateShading`; a function that runs per sample (that one, or one that reads
|
||||
/// `[[sample_id]]`, as a per-sample framebuffer fetch's stage does, or a sample-qualified varying)
|
||||
/// reads `[[position]]`'s x and y and its center varyings at the pixel through their pixel forms,
|
||||
/// is refused for a center varying where the device has no pixel form, and needs `multisampled`
|
||||
/// where it has one but was compiled without it. Its other pixel reads (`[[position]]`'s z and w,
|
||||
/// `[[point_coord]]`, `[[barycentric_coord]]`, a centroid varying) read where Vulkan evaluates
|
||||
/// them, noted by the compile layer.
|
||||
/// Check how the fragment stage `fs` runs and reads under multisampling (see the module docs).
|
||||
/// With more than one sample and rasterization on, a function that runs per sample (one that
|
||||
/// reads `[[sample_id]]`, as a per-sample framebuffer fetch's stage does, or a sample-qualified
|
||||
/// varying) reads `[[position]]`'s x and y and its center varyings at the pixel through their pixel
|
||||
/// forms, is refused for a center varying where the device has no pixel form, and needs
|
||||
/// `multisampled` where it has one but was compiled without it. Its other pixel reads
|
||||
/// (`[[position]]`'s z and w, `[[point_coord]]`, `[[barycentric_coord]]`, a centroid varying) read
|
||||
/// where Vulkan evaluates them, noted by the compile layer. A function that writes memory runs as
|
||||
/// any other, as many times as the device runs it (`PrecisionNote::DeviceFragmentRuns`).
|
||||
fn sample_invocations(
|
||||
r: &RenderLinkInputs,
|
||||
fs: Option<&StageInterface>,
|
||||
p: &DeviceProfile,
|
||||
) -> Result<bool, Error> {
|
||||
) -> Result<(), Error> {
|
||||
// A pipeline has a fragment stage only with rasterization on.
|
||||
let Some(fs) = fs else {
|
||||
return Ok(false);
|
||||
return Ok(());
|
||||
};
|
||||
if r.raster_sample_count <= 1 {
|
||||
return Ok(false);
|
||||
return Ok(());
|
||||
}
|
||||
let io = &fs.io;
|
||||
// The barycentric weights' varyings are center varyings, and an interpolant read at the
|
||||
@@ -952,14 +950,11 @@ fn sample_invocations(
|
||||
}
|
||||
.into()
|
||||
};
|
||||
// Metal repeats the side effects per covered sample; Vulkan does under sample shading at a
|
||||
// minimum of 1.0, which the pipeline enables (a `SampleId` input enables it too).
|
||||
let sample_shading = fs.writes_memory;
|
||||
let per_sample = sample_shading
|
||||
|| io.builtins.contains(&StageBuiltin::SampleId)
|
||||
|| interpolated(|s| s == Sampling::Sample);
|
||||
// A `SampleId` input, or a `Sample` one, runs the stage once per covered sample.
|
||||
let per_sample =
|
||||
io.builtins.contains(&StageBuiltin::SampleId) || interpolated(|s| s == Sampling::Sample);
|
||||
if !per_sample {
|
||||
return Ok(false);
|
||||
return Ok(());
|
||||
}
|
||||
// Metal hands each of the pixel's sample invocations the pixel's coverage. A Vulkan
|
||||
// invocation under sample shading sees only its own samples' bits, and nothing gathers a
|
||||
@@ -969,7 +964,7 @@ fn sample_invocations(
|
||||
// for the reason its interface records.
|
||||
if io.builtins.contains(&StageBuiltin::SampleMaskIn) {
|
||||
match io.coverage_loop {
|
||||
CoverageLoop::Looped => return Ok(false),
|
||||
CoverageLoop::Looped => return Ok(()),
|
||||
CoverageLoop::Unlooped => return Err(Error::NeedsInput(RuntimeInput::Multisampled)),
|
||||
CoverageLoop::Refused(r) => return Err(r.error()),
|
||||
CoverageLoop::NotNeeded => {
|
||||
@@ -979,9 +974,6 @@ fn sample_invocations(
|
||||
}
|
||||
}
|
||||
}
|
||||
if sample_shading && !rate {
|
||||
return Err(refused());
|
||||
}
|
||||
// Compiled for a multisampled pipeline, the function reads `[[position]]`'s x and y and
|
||||
// (with the pixel form) its center varyings at the pixel. `[[position]]`'s z and w,
|
||||
// `[[point_coord]]`, `[[barycentric_coord]]` and a centroid varying have no pixel form under
|
||||
@@ -990,7 +982,7 @@ fn sample_invocations(
|
||||
let position = io.builtins.contains(&StageBuiltin::FragCoord);
|
||||
let center = interpolated(Sampling::reads_center);
|
||||
if !position && !center {
|
||||
return Ok(sample_shading);
|
||||
return Ok(());
|
||||
}
|
||||
if !rate {
|
||||
return Err(refused());
|
||||
@@ -1033,7 +1025,7 @@ fn sample_invocations(
|
||||
// Compiled for another device.
|
||||
return Err(refused());
|
||||
}
|
||||
Ok(sample_shading)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// What the device's alpha to coverage gives a render pipeline whose graphics state is `g` on `p`
|
||||
|
||||
@@ -2257,19 +2257,21 @@ fn the_raster_sample_count_needs_the_framebuffer_sample_counts() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Under multisampling Metal (Apple M3 Max, 4x) runs a fragment function that writes memory once
|
||||
/// per covered sample, whatever its inputs, and every invocation reads its position, its center
|
||||
/// and centroid varyings, its point and barycentric coordinates, and its sample mask as the
|
||||
/// pixel's. Vulkan runs per sample only under sample shading, which `SampleId` turns on, a `Sample`
|
||||
/// input may, and the pipeline enables for a function that writes memory; it moves those reads to
|
||||
/// the sample there. The same pipelines at one sample, a pixel-rate function that reads them, a
|
||||
/// Under multisampling Metal (Apple M3 Max, 4x) runs a fragment function that reads
|
||||
/// `[[sample_id]]` or a sample-qualified varying once per covered sample, and every invocation
|
||||
/// reads its position, its center and centroid varyings, its point and barycentric coordinates,
|
||||
/// and its sample mask as the pixel's. Vulkan runs per sample only under sample shading, which
|
||||
/// `SampleId` turns on and a `Sample` input may, and moves those reads to the sample there. A
|
||||
/// function that writes memory runs as any other, as the device runs it
|
||||
/// (`PrecisionNote::DeviceFragmentRuns`): its writes change nothing link decides. The same
|
||||
/// pipelines at one sample, a pixel-rate function that reads them, with side effects or without, a
|
||||
/// per-sample one that does not, one compiled for the pipeline that reads `[[position]]`'s x and y
|
||||
/// or its center varyings at the pixel, and a per-sample one that reads `[[position]]`'s z or w, a
|
||||
/// centroid varying, or its point or barycentric coordinates where Vulkan evaluates them (which
|
||||
/// the compile layer notes), link, with sample shading exactly where the function writes memory
|
||||
/// at four samples. A per-sample function whose pixel reads all have forms on the
|
||||
/// device, compiled without `multisampled`, needs that input. A device without `sampleRateShading`
|
||||
/// is named for the side effects and for a read that recompiling would not fix.
|
||||
/// the compile layer notes), link, and none needs `sampleRateShading` for its multisample state.
|
||||
/// A per-sample function whose pixel reads all have forms on the device, compiled without
|
||||
/// `multisampled`, needs that input. A device without `sampleRateShading` is named for a read that
|
||||
/// recompiling would not fix, and links the side effects.
|
||||
#[test]
|
||||
fn multisampled_fragment_invocations_follow_metals_measured_rules() {
|
||||
use crate::error::RuntimeInput;
|
||||
@@ -2338,17 +2340,17 @@ fn multisampled_fragment_invocations_follow_metals_measured_rules() {
|
||||
fragment(vec![center.clone(), centroid.clone()], pixel_reads, false),
|
||||
Links,
|
||||
),
|
||||
// Side effects: the pipeline's sample shading runs them once per covered sample.
|
||||
// Side effects: the function runs as the device runs it, and its pixel reads stay the
|
||||
// pixel's, as without them.
|
||||
(fragment(vec![], vec![], true), Links),
|
||||
(
|
||||
fragment(vec![flat.clone()], vec![B::FrontFacing], true),
|
||||
Links,
|
||||
),
|
||||
(fragment(vec![sample.clone()], vec![], true), Links),
|
||||
// ... and moves the pixel reads to the sample, where they have no pixel form.
|
||||
(fragment(vec![center.clone()], vec![], true), Center),
|
||||
(fragment(vec![], vec![B::FragCoord], true), Recompile),
|
||||
(fragment(vec![], vec![B::SampleMaskIn], true), Coverage),
|
||||
(fragment(vec![center.clone()], vec![], true), Links),
|
||||
(fragment(vec![], vec![B::FragCoord], true), Links),
|
||||
(fragment(vec![], vec![B::SampleMaskIn], true), Links),
|
||||
// Side effects with `SampleId`: once per covered sample in both.
|
||||
(
|
||||
fragment(
|
||||
@@ -2436,7 +2438,7 @@ fn multisampled_fragment_invocations_follow_metals_measured_rules() {
|
||||
compiled(vec![sample], vec![B::SampleMaskIn], true, false),
|
||||
Coverage,
|
||||
),
|
||||
// Side effects beside the pixel forms, and beside a center varying without its form.
|
||||
// Side effects compiled for the pipeline, with the pixel forms and without them.
|
||||
(
|
||||
{
|
||||
let mut a = compiled(vec![center.clone()], vec![B::FragCoord], true, false);
|
||||
@@ -2451,7 +2453,7 @@ fn multisampled_fragment_invocations_follow_metals_measured_rules() {
|
||||
a.interface.writes_memory = true;
|
||||
a
|
||||
},
|
||||
Center,
|
||||
Links,
|
||||
),
|
||||
];
|
||||
let mut r = RenderLinkInputs::new();
|
||||
@@ -2471,24 +2473,16 @@ fn multisampled_fragment_invocations_follow_metals_measured_rules() {
|
||||
for (i, (fa, expect)) in cases.iter().enumerate() {
|
||||
let one =
|
||||
link(&[&va, fa], &at(1), &p).unwrap_or_else(|e| panic!("{stem} case {i}: {e}"));
|
||||
assert!(
|
||||
!one.graphics.expect("graphics").sample_shading,
|
||||
assert_eq!(
|
||||
one.graphics.expect("graphics").multisample_features(),
|
||||
BTreeSet::new(),
|
||||
"{stem} case {i}"
|
||||
);
|
||||
let four = link(&[&va, fa], &at(4), &p).map(|l| {
|
||||
let g = l.graphics.expect("graphics");
|
||||
// No multisample state of these needs `sampleRateShading`.
|
||||
assert_eq!(
|
||||
g.sample_shading, fa.interface.writes_memory,
|
||||
"{stem} case {i}"
|
||||
);
|
||||
// Sample shading needs `sampleRateShading`.
|
||||
assert_eq!(
|
||||
g.multisample_features(),
|
||||
if g.sample_shading {
|
||||
BTreeSet::from([VkFeature::SampleRateShading])
|
||||
} else {
|
||||
BTreeSet::new()
|
||||
},
|
||||
l.graphics.expect("graphics").multisample_features(),
|
||||
BTreeSet::new(),
|
||||
"{stem} case {i}"
|
||||
);
|
||||
});
|
||||
@@ -2511,13 +2505,9 @@ fn multisampled_fragment_invocations_follow_metals_measured_rules() {
|
||||
)
|
||||
.expect("profile");
|
||||
assert!(!p.fields().fragment.sample_rate_shading);
|
||||
assert_eq!(
|
||||
link(&[&va, &cases[1].0], &at(4), &p).unwrap_err(),
|
||||
Error::Unsupported(Unsupported::needs(
|
||||
Feature::SampleRateShading,
|
||||
Capability::Feature(VkFeature::SampleRateShading)
|
||||
))
|
||||
);
|
||||
// The side effects need no sample shading, so the device links them at four samples.
|
||||
assert!(cases[1].0.interface.writes_memory);
|
||||
link(&[&va, &cases[1].0], &at(4), &p).expect("side effects at four samples");
|
||||
link(&[&va, &cases[1].0], &at(1), &p).expect("one sample");
|
||||
assert_eq!(cases[12].1, Recompile);
|
||||
assert_eq!(
|
||||
@@ -2530,7 +2520,7 @@ fn multisampled_fragment_invocations_follow_metals_measured_rules() {
|
||||
// The pixel's coverage at sample rate is no device's to gain: a device without
|
||||
// `sampleRateShading` refuses it as not representable too, not as the feature it lacks.
|
||||
let covering: Vec<_> = cases.iter().filter(|(_, at4)| *at4 == Coverage).collect();
|
||||
assert_eq!(covering.len(), 3);
|
||||
assert_eq!(covering.len(), 2);
|
||||
for (fa, _) in covering {
|
||||
assert_eq!(link(&[&va, fa], &at(4), &p).unwrap_err(), coverage);
|
||||
}
|
||||
|
||||
@@ -421,13 +421,14 @@ impl DepthCompares {
|
||||
}
|
||||
|
||||
/// How a fragment function reads `[[sample_mask]]` where Metal runs it once per covered sample: it
|
||||
/// reads `[[sample_id]]` or a sample-qualified varying, or writes memory. Metal hands each of those
|
||||
/// runs the pixel's whole coverage, and a Vulkan invocation under sample shading sees only its own
|
||||
/// sample's bit, so such a function runs once per pixel instead, reads the coverage there, and runs
|
||||
/// its body once per covered sample in a loop over the coverage's bits, each pass reading its
|
||||
/// sample's index and its sample-qualified varyings at its sample. One pixel-rate invocation cannot
|
||||
/// write each sample's outputs, so the loop is only for a function whose side effects are its
|
||||
/// memory writes.
|
||||
/// reads `[[sample_id]]` or a sample-qualified varying. Metal hands each of those runs the pixel's
|
||||
/// whole coverage, and a Vulkan invocation under sample shading sees only its own sample's bit, so
|
||||
/// such a function runs once per pixel instead, reads the coverage there, and runs its body once
|
||||
/// per covered sample in a loop over the coverage's bits, each pass reading its sample's index and
|
||||
/// its sample-qualified varyings at its sample. One pixel-rate invocation writes one value per
|
||||
/// output, so its outputs are the last pass's (`PrecisionNote::LoopedSampleOutputs`). A function
|
||||
/// that writes memory and reads neither runs as any other, as many times as the device runs it
|
||||
/// (`PrecisionNote::DeviceFragmentRuns`).
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//! Whether a module writes memory of its own.
|
||||
//!
|
||||
//! Metal runs a multisampled fragment function that writes memory another invocation or a later
|
||||
//! command can read once per covered sample, so link runs such a function under sample shading
|
||||
//! (`StageInterface::writes_memory`). The writes that count are the function's: a store, a copy,
|
||||
//! or an atomic other than a load into a storage buffer, a physical storage buffer, or an image,
|
||||
//! and an image write.
|
||||
//! A multisampled fragment function that writes memory another invocation or a later command can
|
||||
//! read runs as many times per pixel as the device runs it, which its pipeline's compile records
|
||||
//! (`StageInterface::writes_memory`, `PrecisionNote::DeviceFragmentRuns`). The writes that count
|
||||
//! are the function's: a store, a copy, or an atomic other than a load into a storage buffer, a
|
||||
//! physical storage buffer, or an image, and an image write.
|
||||
//!
|
||||
//! The product also writes one buffer the guest never names: the command buffer's
|
||||
//! `ExecutionStatus` buffer, whose words the resident-miss count, an absent read's mark and a
|
||||
|
||||
@@ -2,27 +2,30 @@
|
||||
//! `engine/sample_rate`, `engine/coverage_loop`, `engine/coverage_natural` and
|
||||
//! `engine/coverage_outputs`:
|
||||
//!
|
||||
//! - `rt6_mark_coverage` reads `[[sample_mask]]` and writes memory, so Metal runs it once per
|
||||
//! covered sample, each run reading the pixel's coverage. Compiled for a multisampled pipeline it
|
||||
//! runs once per pixel, without sample shading: the module declares no `SampleId` and no
|
||||
//! `SampleRateShading`, reads `SampleMask`, and runs the body from a loop over the coverage's set
|
||||
//! bits (`FindILsb`). Its interface says so (`CoverageLoop::Looped`); compiled on its own it says
|
||||
//! `Unlooped`, and link asks for `multisampled` (`NeedsInput(Multisampled)`) at four samples
|
||||
//! and takes it at one.
|
||||
//! - `sample_rate_mask_in` returns a color beside `[[sample_mask]]` and `[[sample_id]]`: it loops
|
||||
//! as the memory writer does, its color the last pass's (`PrecisionNote::LoopedSampleOutputs`).
|
||||
//! - `coverage_outputs`' memory writers return a color, one also a sample mask: they loop
|
||||
//! wherever the device makes them, recording the note, the masked one storing the union of the
|
||||
//! samples its passes keep after the loop.
|
||||
//! - `rt6_mark_coverage` reads `[[sample_mask]]` and writes memory without a sample index or a
|
||||
//! sample-qualified varying. Apple's GPUs were measured to run it once per covered sample, and
|
||||
//! documented Metal names no count, so it runs as the device runs it
|
||||
//! (`PrecisionNote::DeviceFragmentRuns`): compiled as written, with no loop, no `SampleId` and no
|
||||
//! `SampleRateShading`, reading `SampleMask`. Its interface needs no loop
|
||||
//! (`CoverageLoop::NotNeeded`), and compiled on its own it links at four samples.
|
||||
//! - `sample_rate_mask_in` returns a color beside `[[sample_mask]]` and `[[sample_id]]`: Metal runs
|
||||
//! it once per covered sample, and compiled for a multisampled pipeline it runs once per pixel,
|
||||
//! without sample shading, and runs its body from a loop over the coverage's set bits
|
||||
//! (`FindILsb`), its color the last pass's (`PrecisionNote::LoopedSampleOutputs`). Its interface
|
||||
//! says so (`CoverageLoop::Looped`); compiled on its own it says `Unlooped`, and link asks for
|
||||
//! `multisampled` (`NeedsInput(Multisampled)`) at four samples.
|
||||
//! - `coverage_outputs`' memory writers return a color, one also a sample mask, without a sample
|
||||
//! index: they run as the device runs them, with no loop, recording `DeviceFragmentRuns`.
|
||||
//! - `rt6_mark_sample` runs per sample without reading the coverage: no loop.
|
||||
//! - `coverage_loop`'s memory writers loop at four samples wherever the device makes them; each of
|
||||
//! - `coverage_loop`'s memory writers read `[[sample_id]]` and loop at four samples wherever the
|
||||
//! device makes them; each of
|
||||
//! its functions holding one thing the loop does not fit (early fragment tests, a discard, a
|
||||
//! derivative, a simdgroup operation, a color attachment read) is refused by that thing; its
|
||||
//! sample-qualified varying is interpolated at its samples (`InterpolateAtSample`, no `Sample`
|
||||
//! decoration), or refused as needing the interpolation functions where withheld.
|
||||
//!
|
||||
//! - `coverage_natural`'s functions read no `[[position]]` beside a sample index or varying: each
|
||||
//! loops.
|
||||
//! that reads one loops, and each that reads neither runs as the device runs it.
|
||||
//! - The looping functions' sample-qualified varyings are read at every sample a pipeline of the
|
||||
//! device may have, by constant, before the loop, where the whole quad runs, on every profile.
|
||||
//!
|
||||
@@ -58,12 +61,13 @@ const COV_COVER_UV: &str = "cov_cover_uv";
|
||||
const COV_FITS: [&str; 2] = ["cov_loop_record", "cov_loop_union"];
|
||||
const COV_VARYING: &str = "cov_loop_varying";
|
||||
const COV_FETCH: &str = "cov_loop_fetch";
|
||||
/// `coverage_natural`'s functions, each with the `coverage_loop` vertex function that feeds it.
|
||||
const NATURAL: [(&str, &str); 4] = [
|
||||
("nat_coverage", COV_COVER),
|
||||
("nat_coverage_at_pixel", COV_COVER),
|
||||
("nat_sample", COV_COVER),
|
||||
("nat_varying", COV_COVER_UV),
|
||||
/// `coverage_natural`'s functions, each with the `coverage_loop` vertex function that feeds it and
|
||||
/// whether it loops: those that read a sample index or a sample-qualified varying.
|
||||
const NATURAL: [(&str, &str, bool); 4] = [
|
||||
("nat_coverage", COV_COVER, false),
|
||||
("nat_coverage_at_pixel", COV_COVER, false),
|
||||
("nat_sample", COV_COVER, true),
|
||||
("nat_varying", COV_COVER_UV, true),
|
||||
];
|
||||
const COV_REFUSED: [(&str, CoverageLoopRefusal); 5] = [
|
||||
("cov_loop_early", CoverageLoopRefusal::EarlyFragmentTests),
|
||||
@@ -227,19 +231,22 @@ fn interpolated_samples(words: &[u32]) -> Vec<Option<u32>> {
|
||||
reads
|
||||
}
|
||||
|
||||
/// On every committed profile, the coverage-reading memory writer at two and four samples runs
|
||||
/// once per pixel and loops over its covered samples, with no sample shading, or is refused for
|
||||
/// what the device lacks (fragment stores, lavapipe's split of a clipped triangle's fragments),
|
||||
/// never as not representable. On a driver that runs a memory writer once per covered sample
|
||||
/// (MoltenVK on Apple's GPU) it is compiled as written, which reads no sample index and so keeps
|
||||
/// the coverage whole there: no loop, no `SampleId`, no `SampleRateShading`, and no sample shading.
|
||||
/// At one sample it compiles without the loop.
|
||||
/// Whether a stage of `p` records `note`.
|
||||
fn noted(p: &RenderPipeline, note: PrecisionNote) -> bool {
|
||||
p.stages.iter().any(|m| m.precision_notes.contains(¬e))
|
||||
}
|
||||
|
||||
/// On every committed profile, the coverage-reading memory writer without a sample index at two
|
||||
/// and four samples runs as the device runs it: compiled as written, with no loop, no `SampleId`
|
||||
/// and no `SampleRateShading`, reading `SampleMask`, and recording
|
||||
/// `PrecisionNote::DeviceFragmentRuns`; or refused for what the device lacks (fragment stores),
|
||||
/// never as not representable. At one sample it compiles the same, recording nothing of its runs.
|
||||
#[test]
|
||||
fn a_coverage_reading_memory_writer_loops_over_its_covered_samples() {
|
||||
fn a_coverage_reading_memory_writer_runs_as_the_device_runs_it() {
|
||||
let Some(lib) = library("rt6_attachmentless") else {
|
||||
return;
|
||||
};
|
||||
let mut looped = 0;
|
||||
let mut plain = 0;
|
||||
for stem in stems() {
|
||||
let dev = device(&stem);
|
||||
for samples in [2, 4] {
|
||||
@@ -247,8 +254,7 @@ fn a_coverage_reading_memory_writer_loops_over_its_covered_samples() {
|
||||
let d = render(&lib, function(&lib, COVERAGE), samples, false);
|
||||
match dev.compile_render_pipeline(&d, &Budget::standard()) {
|
||||
Ok(p) => {
|
||||
looped += 1;
|
||||
assert!(!p.graphics.sample_shading, "{what}");
|
||||
plain += 1;
|
||||
assert_eq!(
|
||||
Shape {
|
||||
frag_coord: false,
|
||||
@@ -256,12 +262,11 @@ fn a_coverage_reading_memory_writer_loops_over_its_covered_samples() {
|
||||
},
|
||||
Shape {
|
||||
sample_mask: true,
|
||||
loops: true,
|
||||
find_lsb: true,
|
||||
..Shape::default()
|
||||
},
|
||||
"{what}"
|
||||
);
|
||||
assert!(noted(&p, PrecisionNote::DeviceFragmentRuns), "{what}");
|
||||
for m in &p.stages {
|
||||
check_words_valid(&m.spirv, &p.requirements, dev.profile())
|
||||
.unwrap_or_else(|e| panic!("{what} {:?}: L3: {e}", m.stage));
|
||||
@@ -281,9 +286,10 @@ fn a_coverage_reading_memory_writer_loops_over_its_covered_samples() {
|
||||
if let Ok(p) = dev.compile_render_pipeline(&d, &Budget::standard()) {
|
||||
let s = shape(fragment_words(&p));
|
||||
assert!(!s.loops && !s.sample_id, "{stem} at 1: {s:?}");
|
||||
assert!(!noted(&p, PrecisionNote::DeviceFragmentRuns), "{stem} at 1");
|
||||
}
|
||||
}
|
||||
assert!(looped >= 6, "{looped} pipelines looped");
|
||||
assert!(plain >= 6, "{plain} pipelines compiled it as written");
|
||||
}
|
||||
|
||||
/// A coverage reader in a multisampled pipeline records `PrecisionNote::ClippedCoverageSplit` on
|
||||
@@ -372,9 +378,10 @@ fn a_multisampled_centroid_reader_at_the_pixel_announces_the_split() {
|
||||
}
|
||||
|
||||
/// The interface states the loop: `Looped` under `multisampled`, `Unlooped` without, and link asks
|
||||
/// a function compiled without it for `multisampled` at four samples and takes it at one; a
|
||||
/// function that runs per sample without reading the coverage has no loop; one with a color output
|
||||
/// loops as well, recording `PrecisionNote::LoopedSampleOutputs`.
|
||||
/// a function compiled without it for `multisampled` at four samples; a function that runs per
|
||||
/// sample without reading the coverage has no loop, and neither has a memory writer that reads the
|
||||
/// coverage without a sample index, which compiled on its own links at four samples and at one; a
|
||||
/// looping function with a color output records `PrecisionNote::LoopedSampleOutputs`.
|
||||
#[test]
|
||||
fn the_interface_states_the_coverage_loop() {
|
||||
let (Some(attachmentless), Some(sample_rate)) =
|
||||
@@ -402,8 +409,8 @@ fn the_interface_states_the_coverage_loop() {
|
||||
(
|
||||
&attachmentless,
|
||||
COVERAGE,
|
||||
CoverageLoop::Unlooped,
|
||||
CoverageLoop::Looped,
|
||||
CoverageLoop::NotNeeded,
|
||||
CoverageLoop::NotNeeded,
|
||||
),
|
||||
(
|
||||
&attachmentless,
|
||||
@@ -425,17 +432,16 @@ fn the_interface_states_the_coverage_loop() {
|
||||
"{name} multisampled"
|
||||
);
|
||||
}
|
||||
// Compiled on its own, the coverage reader is asked for `multisampled` at four samples.
|
||||
// Compiled on its own, the memory writer links at four samples, as the device runs it.
|
||||
let alone = StageSource::Compiled(compile(&attachmentless, COVERAGE, &none));
|
||||
let budget = Budget::standard();
|
||||
assert_eq!(
|
||||
dev.compile_render_pipeline(&render(&attachmentless, alone.clone(), 4, false), &budget)
|
||||
.map(|_| ()),
|
||||
Err(Error::NeedsInput(RuntimeInput::Multisampled))
|
||||
);
|
||||
let four = dev
|
||||
.compile_render_pipeline(&render(&attachmentless, alone.clone(), 4, false), &budget)
|
||||
.expect("four samples");
|
||||
assert!(noted(&four, PrecisionNote::DeviceFragmentRuns));
|
||||
dev.compile_render_pipeline(&render(&attachmentless, alone, 1, false), &budget)
|
||||
.expect("one sample");
|
||||
// A color output beside the coverage at sample rate loops too, its color the last pass's.
|
||||
// A color output beside the coverage at sample rate loops, its color the last pass's.
|
||||
let alone = StageSource::Compiled(compile(&sample_rate, MASK_IN, &none));
|
||||
assert_eq!(
|
||||
dev.compile_render_pipeline(&render(&attachmentless, alone, 4, true), &budget)
|
||||
@@ -448,7 +454,6 @@ fn the_interface_states_the_coverage_loop() {
|
||||
&budget,
|
||||
)
|
||||
.expect("the looping color writer");
|
||||
assert!(!p.graphics.sample_shading);
|
||||
let s = shape(fragment_words(&p));
|
||||
assert!(s.loops && s.find_lsb && !s.sample_id, "{s:?}");
|
||||
assert!(p.stages.iter().any(|m| m
|
||||
@@ -537,7 +542,6 @@ fn the_loop_refuses_each_function_it_does_not_fit_by_its_reason() {
|
||||
continue;
|
||||
};
|
||||
let what = format!("{f} on {stem}");
|
||||
assert!(!p.graphics.sample_shading, "{what}");
|
||||
assert_eq!(
|
||||
Shape {
|
||||
frag_coord: false,
|
||||
@@ -562,7 +566,6 @@ fn the_loop_refuses_each_function_it_does_not_fit_by_its_reason() {
|
||||
match coverage_loop_pipeline(&dev, &lib, COV_COVER_UV, COV_VARYING) {
|
||||
Ok(p) => {
|
||||
varying += 1;
|
||||
assert!(!p.graphics.sample_shading, "{what}");
|
||||
assert_eq!(
|
||||
Shape {
|
||||
frag_coord: false,
|
||||
@@ -589,20 +592,22 @@ fn the_loop_refuses_each_function_it_does_not_fit_by_its_reason() {
|
||||
assert!(varying >= 6, "{varying} profiles looped the varying");
|
||||
}
|
||||
|
||||
/// `coverage_natural` at 2 and 4 samples on every committed profile: each function loops without
|
||||
/// sample shading, its coverage read, or is refused for what the device lacks (the interpolation
|
||||
/// functions among them), never for the loop.
|
||||
/// `coverage_natural` at 2 and 4 samples on every committed profile: each function that reads a
|
||||
/// sample index or a sample-qualified varying loops without sample shading, its coverage read, and
|
||||
/// each that reads neither compiles as written, with no loop; every one, as a memory writer,
|
||||
/// records `PrecisionNote::DeviceFragmentRuns`. Or it is refused for what the device lacks (the
|
||||
/// interpolation functions among them), never for the loop.
|
||||
#[test]
|
||||
fn the_natural_functions_loop_over_their_covered_samples() {
|
||||
fn the_natural_functions_loop_where_they_read_a_sample() {
|
||||
let (Some(natural_lib), Some(vertex_lib)) =
|
||||
(library("coverage_natural"), library("coverage_loop"))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let mut looped = 0;
|
||||
let mut compiled = 0;
|
||||
for stem in stems() {
|
||||
let dev = device(&stem);
|
||||
for (f, vertex) in NATURAL {
|
||||
for (f, vertex, loops) in NATURAL {
|
||||
for samples in [2, 4] {
|
||||
let what = format!("{f} at {samples} on {stem}");
|
||||
let mut d = RenderPipelineDescriptor::new(function(&vertex_lib, vertex));
|
||||
@@ -610,10 +615,12 @@ fn the_natural_functions_loop_over_their_covered_samples() {
|
||||
d.raster_sample_count = samples;
|
||||
match dev.compile_render_pipeline(&d, &Budget::standard()) {
|
||||
Ok(p) => {
|
||||
assert!(!p.graphics.sample_shading, "{what}");
|
||||
let s = shape(fragment_words(&p));
|
||||
assert!(s.sample_mask && s.loops, "{what}: {s:?}");
|
||||
looped += 1;
|
||||
assert!(s.sample_mask, "{what}: {s:?}");
|
||||
assert_eq!((s.loops, s.find_lsb), (loops, loops), "{what}: {s:?}");
|
||||
assert!(!s.sample_rate_shading, "{what}: {s:?}");
|
||||
assert!(noted(&p, PrecisionNote::DeviceFragmentRuns), "{what}");
|
||||
compiled += 1;
|
||||
l3(&dev, &p, &what);
|
||||
}
|
||||
Err(e) if e == CoverageLoopRefusal::InterpolationFunctions.error() => {}
|
||||
@@ -629,7 +636,10 @@ fn the_natural_functions_loop_over_their_covered_samples() {
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(looped >= 6 * NATURAL.len(), "{looped} pipelines looped");
|
||||
assert!(
|
||||
compiled >= 6 * NATURAL.len(),
|
||||
"{compiled} pipelines compiled"
|
||||
);
|
||||
}
|
||||
|
||||
/// A looping function's sample-qualified varying (`coverage_loop`'s `cov_loop_varying`, and
|
||||
@@ -704,16 +714,18 @@ fn sample_mask_decorations(words: &[u32]) -> usize {
|
||||
}
|
||||
|
||||
/// `coverage_outputs`' memory writers return a color beside `[[sample_mask]]`, one also a sample
|
||||
/// mask, which Metal writes per covered sample, each from that sample's run (our probe `co`). At
|
||||
/// two and four samples on every committed profile each loops, without sample shading, recording
|
||||
/// `PrecisionNote::LoopedSampleOutputs`, or is refused for what the device lacks, never as the
|
||||
/// coverage at sample rate; the masked one declares the `SampleMask` output beside the input.
|
||||
/// mask, and read no sample index: Apple's GPUs were measured to write them per covered sample,
|
||||
/// each from that sample's run (our probe `co`), and documented Metal names no count. At two and
|
||||
/// four samples on every committed profile each runs as the device runs it, compiled with no loop
|
||||
/// and recording `PrecisionNote::DeviceFragmentRuns` and not `LoopedSampleOutputs`, or is refused
|
||||
/// for what the device lacks, never as the coverage at sample rate; the masked one declares the
|
||||
/// `SampleMask` output beside the input.
|
||||
#[test]
|
||||
fn coverage_reading_color_writers_loop() {
|
||||
fn coverage_reading_color_writers_run_as_the_device_runs_them() {
|
||||
let Some(lib) = library("coverage_outputs") else {
|
||||
return;
|
||||
};
|
||||
let mut looped = 0;
|
||||
let mut plain = 0;
|
||||
for stem in stems() {
|
||||
let dev = device(&stem);
|
||||
for (name, masks) in [("cvo_color", 1), ("cvo_masked", 2)] {
|
||||
@@ -726,25 +738,21 @@ fn coverage_reading_color_writers_loop() {
|
||||
d.raster_sample_count = samples;
|
||||
match dev.compile_render_pipeline(&d, &Budget::standard()) {
|
||||
Ok(p) => {
|
||||
assert!(!p.graphics.sample_shading, "{what}");
|
||||
let words = fragment_words(&p);
|
||||
let s = shape(words);
|
||||
assert_eq!(
|
||||
(s.loops, s.find_lsb, s.sample_id),
|
||||
(true, true, false),
|
||||
(false, false, false),
|
||||
"{what}"
|
||||
);
|
||||
assert_eq!(sample_mask_decorations(words), masks, "{what}");
|
||||
let noted = p.stages.iter().any(|m| {
|
||||
m.precision_notes
|
||||
.contains(&PrecisionNote::LoopedSampleOutputs)
|
||||
});
|
||||
assert!(noted, "{what}");
|
||||
assert!(noted(&p, PrecisionNote::DeviceFragmentRuns), "{what}");
|
||||
assert!(!noted(&p, PrecisionNote::LoopedSampleOutputs), "{what}");
|
||||
for m in &p.stages {
|
||||
check_words_valid(&m.spirv, &p.requirements, dev.profile())
|
||||
.unwrap_or_else(|e| panic!("{what} {:?}: L3: {e}", m.stage));
|
||||
}
|
||||
looped += 1;
|
||||
plain += 1;
|
||||
}
|
||||
Err(Error::Unsupported(u)) => {
|
||||
assert_ne!(
|
||||
@@ -758,5 +766,5 @@ fn coverage_reading_color_writers_loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(looped >= 12, "{looped} looped");
|
||||
assert!(plain >= 12, "{plain} compiled as written");
|
||||
}
|
||||
@@ -9,10 +9,12 @@
|
||||
//! requires `VkProperty::InterpolateAtOffsetCentered`, which every device holds, and on a
|
||||
//! portability-subset device `shaderSampleRateInterpolationFunctions`. A center varying read at
|
||||
//! sample rate on a device without those interpolation functions is refused naming them.
|
||||
//! - A function that writes memory, which Metal runs once per covered sample, runs under the
|
||||
//! pipeline's sample shading (`GraphicsState::sample_shading`, needing `sampleRateShading`).
|
||||
//! - A per-sample function (that one, or one that reads `[[sample_id]]` or a sample-qualified
|
||||
//! varying) reads what has no pixel form under sample shading (`[[position]]`'s z and w, a
|
||||
//! - A function that writes memory runs as the device runs it, at pixel rate where nothing else
|
||||
//! makes it per-sample, and its fragment stage notes `PrecisionNote::DeviceFragmentRuns` at four
|
||||
//! samples: Apple's GPUs were measured to run it once per covered sample, and documented Metal
|
||||
//! names no count.
|
||||
//! - A per-sample function (one that reads `[[sample_id]]` or a sample-qualified varying) reads
|
||||
//! what has no pixel form under sample shading (`[[position]]`'s z and w, a
|
||||
//! centroid varying) where Vulkan evaluates it for its sample, and notes
|
||||
//! `PrecisionNote::MultisamplePosition`, as Metal accepts it.
|
||||
//! - At one sample every function compiles as without multisampling.
|
||||
@@ -204,6 +206,16 @@ fn noted(p: &RenderPipeline) -> bool {
|
||||
.contains(&PrecisionNote::MultisamplePosition)
|
||||
}
|
||||
|
||||
/// Whether the fragment module of `p` notes `DeviceFragmentRuns`.
|
||||
fn noted_runs(p: &RenderPipeline) -> bool {
|
||||
p.stages
|
||||
.iter()
|
||||
.find(|m| m.stage == crate::vk::ShaderStage::FRAGMENT)
|
||||
.expect("fragment stage")
|
||||
.precision_notes
|
||||
.contains(&PrecisionNote::DeviceFragmentRuns)
|
||||
}
|
||||
|
||||
/// The refusal of a per-sample function's center varying on a device that lacks `needs`.
|
||||
fn needs_pixel_form(needs: Vec<Capability>) -> Error {
|
||||
Unsupported::needs_any_of(Feature::SampleRateShading, vec![needs]).into()
|
||||
@@ -235,12 +247,15 @@ pub(super) fn pixel_form(dev: &Device) -> bool {
|
||||
/// `InterpolateAtOffset` at offset 0, which every device reads from the center. A per-sample
|
||||
/// `[[position]]` z
|
||||
/// and w, or centroid varying, compiles on every profile with `sampleRateShading` too, noting
|
||||
/// `MultisamplePosition`.
|
||||
/// `MultisamplePosition`. The function that writes memory compiles at pixel rate on every profile
|
||||
/// with fragment stores, its center varying read at the pixel where the device has the form, and
|
||||
/// notes `DeviceFragmentRuns` at four samples only.
|
||||
#[test]
|
||||
fn multisampled_fragments_read_the_pixel_center_or_are_refused() {
|
||||
let Some(lib) = fixture() else { return };
|
||||
let mut checked = 0usize;
|
||||
let mut unformed = 0usize;
|
||||
let mut writers = 0usize;
|
||||
for stem in stems() {
|
||||
let dev =
|
||||
Device::from_queries(description(&stem), DevicePolicy::default()).expect("device");
|
||||
@@ -290,12 +305,13 @@ fn multisampled_fragments_read_the_pixel_center_or_are_refused() {
|
||||
!ext_insts(fragment_words(&one)).contains(&INTERPOLATE_AT_OFFSET),
|
||||
"{what} at 1"
|
||||
);
|
||||
assert!(!noted_runs(&one), "{what} at 1");
|
||||
let four = dev.compile_render_pipeline(&render(&lib, fragment, 4), &Budget::standard());
|
||||
match (fragment, four) {
|
||||
(_, Err(Error::Unsupported(u))) if u.feature == Feature::RasterSampleCount => {
|
||||
eprintln!("{what}: four samples are not a framebuffer sample count");
|
||||
}
|
||||
(CENTER | SAMPLED | COUNTER, Ok(p)) => {
|
||||
(CENTER | SAMPLED, Ok(p)) => {
|
||||
validate(&p, &dev, &what);
|
||||
// `InterpolateAtOffset` at offset 0 is the pixel form.
|
||||
let ext = ext_insts(fragment_words(&p));
|
||||
@@ -314,9 +330,8 @@ fn multisampled_fragments_read_the_pixel_center_or_are_refused() {
|
||||
.contains(&VkProperty::InterpolateAtOffsetCentered),
|
||||
"{what}"
|
||||
);
|
||||
// Only the function that writes memory runs under the pipeline's sample
|
||||
// shading, which needs `sampleRateShading`.
|
||||
assert_eq!(p.graphics.sample_shading, fragment == COUNTER, "{what}");
|
||||
// Per sample through its input, which needs `sampleRateShading`.
|
||||
assert!(!noted_runs(&p), "{what}");
|
||||
assert!(
|
||||
p.requirements
|
||||
.features
|
||||
@@ -332,8 +347,8 @@ fn multisampled_fragments_read_the_pixel_center_or_are_refused() {
|
||||
assert!(noted(&p), "{what}");
|
||||
let ext = ext_insts(fragment_words(&p));
|
||||
assert!(!ext.contains(&INTERPOLATE_AT_OFFSET), "{what}: {ext:?}");
|
||||
// `[[sample_id]]` turns sample shading on itself; the pipeline does not.
|
||||
assert!(!p.graphics.sample_shading, "{what}");
|
||||
// `[[sample_id]]` turns sample shading on itself.
|
||||
assert!(!noted_runs(&p), "{what}");
|
||||
assert!(
|
||||
p.requirements
|
||||
.features
|
||||
@@ -342,15 +357,20 @@ fn multisampled_fragments_read_the_pixel_center_or_are_refused() {
|
||||
);
|
||||
unformed += 1;
|
||||
}
|
||||
(COUNTER, Err(e)) => assert_eq!(
|
||||
e,
|
||||
Unsupported::needs(
|
||||
Feature::SampleRateShading,
|
||||
Capability::Feature(VkFeature::SampleRateShading)
|
||||
)
|
||||
.into(),
|
||||
"{what}"
|
||||
),
|
||||
// The function that writes memory runs as the device runs it, at pixel rate, and
|
||||
// reads its position and center varying as a pixel-rate function does.
|
||||
(COUNTER, Ok(p)) => {
|
||||
validate(&p, &dev, &what);
|
||||
let ext = ext_insts(fragment_words(&p));
|
||||
assert!(ext.contains(&FLOOR), "{what}: {ext:?}");
|
||||
assert_eq!(
|
||||
ext.contains(&INTERPOLATE_AT_OFFSET),
|
||||
pixel_form(&dev),
|
||||
"{what}: {ext:?}"
|
||||
);
|
||||
assert!(noted_runs(&p), "{what}");
|
||||
writers += 1;
|
||||
}
|
||||
(_, other) => panic!("{what} at 4: {other:?}"),
|
||||
}
|
||||
}
|
||||
@@ -363,6 +383,10 @@ fn multisampled_fragments_read_the_pixel_center_or_are_refused() {
|
||||
unformed > 0,
|
||||
"no profile compiled a per-sample read without a pixel form"
|
||||
);
|
||||
assert!(
|
||||
writers > 0,
|
||||
"no profile compiled the memory writer at four samples"
|
||||
);
|
||||
}
|
||||
|
||||
/// A pixel-rate function of a multisampled pipeline reads its center varyings at the pixel center
|
||||
@@ -409,8 +433,8 @@ fn a_pixel_rate_center_varying_reads_the_pixel_center_where_the_device_has_the_f
|
||||
form,
|
||||
"{what}"
|
||||
);
|
||||
// A pixel-rate function runs without sample shading.
|
||||
assert!(!p.graphics.sample_shading, "{what}");
|
||||
// A pixel-rate function that writes no memory runs as Metal's does.
|
||||
assert!(!noted_runs(&p), "{what}");
|
||||
with_form += usize::from(form);
|
||||
if samples == 4 && !form {
|
||||
without_form.push(stem.clone());
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//! loop over the covered samples), the body reads the entry's copy. SPIRV-Cross declares the
|
||||
//! input a scalar in the entry and passes it to a function as an array. The owned fixtures
|
||||
//! `engine/msf_fetch_ms`'s `msf_fetch_mask_in` (the interlocked storage form of a framebuffer
|
||||
//! fetch) and `engine/rt6_attachmentless`'s `rt6_mark_coverage` (the loop) read it.
|
||||
//! fetch) and `engine/coverage_loop`'s `cov_loop_record` (the loop) read it.
|
||||
//!
|
||||
//! And one form that keeps MoltenVK's pipeline creation within the ceiling: SPIRV-Cross
|
||||
//! force-inlines every function it writes, so Metal's back end compiles a routine once per call. A
|
||||
@@ -245,23 +245,23 @@ fn only_the_entry_reads_the_coverage_of_an_interlocked_body() {
|
||||
assert!(wrapped >= 2, "{wrapped} interlocked modules");
|
||||
}
|
||||
|
||||
/// The loop over the covered samples of `rt6_mark_coverage` at four samples reads the coverage in
|
||||
/// The loop over the covered samples of `cov_loop_record` at four samples reads the coverage in
|
||||
/// the entry, and the body reads the entry's copy, on every profile where it compiles; on macOS the
|
||||
/// MoltenVK profiles' modules compile as MoltenVK's MSL.
|
||||
#[test]
|
||||
fn only_the_entry_reads_the_coverage_of_a_looped_body() {
|
||||
let Some(lib) = library("rt6_attachmentless") else {
|
||||
let Some(lib) = library("coverage_loop") else {
|
||||
return;
|
||||
};
|
||||
let mut looped = 0;
|
||||
for (stem, dev) in devices() {
|
||||
let what = format!("{stem} rt6_mark_coverage at 4");
|
||||
let what = format!("{stem} cov_loop_record at 4");
|
||||
let vertex = StageSource::Function(FunctionDescriptor::new(
|
||||
lib.function("rt6_cover").expect("vertex"),
|
||||
lib.function("cov_cover").expect("vertex"),
|
||||
));
|
||||
let mut d = RenderPipelineDescriptor::new(vertex);
|
||||
d.fragment = Some(StageSource::Function(FunctionDescriptor::new(
|
||||
lib.function("rt6_mark_coverage").expect("fragment"),
|
||||
lib.function("cov_loop_record").expect("fragment"),
|
||||
)));
|
||||
d.raster_sample_count = 4;
|
||||
let p = match dev.compile_render_pipeline(&d, &Budget::standard()) {
|
||||
|
||||
@@ -254,9 +254,11 @@ fn the_render_pipeline_states_the_shadow_and_refuses_what_it_cannot_order() {
|
||||
(s.format, s.formatless, s.samples),
|
||||
(vk::Format::R8_UINT, false, 4)
|
||||
);
|
||||
// The shadow's writes are the product's: a function that writes no memory of its own runs
|
||||
// per pixel, as on Metal, and tests each covered sample.
|
||||
assert!(!four.graphics.sample_shading);
|
||||
// The shadow's writes are the product's: a function that writes no memory of its own records
|
||||
// nothing of its runs, and tests each covered sample.
|
||||
assert!(!four.stages.iter().any(|m| m
|
||||
.precision_notes
|
||||
.contains(&crate::pipeline::PrecisionNote::DeviceFragmentRuns)));
|
||||
assert!(four
|
||||
.requirements
|
||||
.features
|
||||
|
||||
@@ -3042,7 +3042,6 @@ field metal2vulkan::pipeline::GraphicsState.reads_position_depth pub reads_posit
|
||||
field metal2vulkan::pipeline::GraphicsState.reads_primitive_id pub reads_primitive_id: bool
|
||||
field metal2vulkan::pipeline::GraphicsState.region_fan_out pub region_fan_out: Option<FanOutState>
|
||||
field metal2vulkan::pipeline::GraphicsState.sample_mask pub sample_mask: Option<u32>
|
||||
field metal2vulkan::pipeline::GraphicsState.sample_shading pub sample_shading: bool
|
||||
field metal2vulkan::pipeline::GraphicsState.shader_tests pub shader_tests: Option<ShaderTestsUse>
|
||||
field metal2vulkan::pipeline::GraphicsState.shadow_stencil pub shadow_stencil: Option<ShadowStencilUse>
|
||||
field metal2vulkan::pipeline::GraphicsState.snapshot_reads pub snapshot_reads: bool
|
||||
@@ -9488,6 +9487,7 @@ variant metal2vulkan-runtime::PrecisionNote::DeviceColorConversion DeviceColorCo
|
||||
variant metal2vulkan-runtime::PrecisionNote::DeviceDenormals DeviceDenormals
|
||||
variant metal2vulkan-runtime::PrecisionNote::DeviceDepthBias DeviceDepthBias
|
||||
variant metal2vulkan-runtime::PrecisionNote::DeviceFilteredMipmaps DeviceFilteredMipmaps
|
||||
variant metal2vulkan-runtime::PrecisionNote::DeviceFragmentRuns DeviceFragmentRuns
|
||||
variant metal2vulkan-runtime::PrecisionNote::DeviceInterpolation DeviceInterpolation
|
||||
variant metal2vulkan-runtime::PrecisionNote::DeviceInterpolationOffset DeviceInterpolationOffset
|
||||
variant metal2vulkan-runtime::PrecisionNote::DeviceLineRasterization DeviceLineRasterization
|
||||
@@ -11128,6 +11128,7 @@ variant metal2vulkan::pipeline::PrecisionNote::DeviceColorConversion DeviceColor
|
||||
variant metal2vulkan::pipeline::PrecisionNote::DeviceDenormals DeviceDenormals
|
||||
variant metal2vulkan::pipeline::PrecisionNote::DeviceDepthBias DeviceDepthBias
|
||||
variant metal2vulkan::pipeline::PrecisionNote::DeviceFilteredMipmaps DeviceFilteredMipmaps
|
||||
variant metal2vulkan::pipeline::PrecisionNote::DeviceFragmentRuns DeviceFragmentRuns
|
||||
variant metal2vulkan::pipeline::PrecisionNote::DeviceInterpolation DeviceInterpolation
|
||||
variant metal2vulkan::pipeline::PrecisionNote::DeviceInterpolationOffset DeviceInterpolationOffset
|
||||
variant metal2vulkan::pipeline::PrecisionNote::DeviceLineRasterization DeviceLineRasterization
|
||||
|
||||
|
Can't render this file because it is too large.
|
+15
@@ -2671,6 +2671,15 @@ bound.
|
||||
`Invariant`; Vulkan promises no more across pipelines of other fragment modules and attachments.
|
||||
Groups past the first may differ at discard or depth edges if the driver compiles the variants
|
||||
differently.
|
||||
- `metal2vulkan-degrade-device-fragment-runs` (precision). `PrecisionNote::DeviceFragmentRuns`: A
|
||||
fragment function that writes memory (`StageInterface::writes_memory`) in a render pipeline of
|
||||
more than one sample, which the pipeline's compile records on its fragment stage, decided by the
|
||||
sample count and the function's writes alone. It runs as many times per pixel as the device runs
|
||||
it, each run reading the pixel's whole coverage as `[[sample_mask]]`, so its writes repeat as
|
||||
often as the device's runs. Apple's GPUs were measured to run it once per covered sample;
|
||||
documented Metal names no count (MSL section 5.5 makes a function run per sample only for a
|
||||
sample-qualified input, `[[sample_id]]` or `[[color(m)]]`). Vulkan runs a fragment shader
|
||||
without sample shading at least once per pixel and more where the device chooses (vkspec 35.5).
|
||||
|
||||
## 10. Accepted differences
|
||||
|
||||
@@ -2695,6 +2704,12 @@ each item named states the rule in full.
|
||||
driver covers there. Measured, where a line of the conformance case
|
||||
`primitive-type-restart-indices` runs through the boundary point (3.5, 1.0), Metal on an Apple M3
|
||||
Max covers the lower pixel and NVIDIA's driver on an RTX 5080 the upper.
|
||||
- **A memory-writing fragment function runs as many times as the device runs it.** Metal's GPUs
|
||||
were measured to run a memory-writing fragment once per covered sample; documented Metal names
|
||||
no count; here the count is the device's. The pipeline's fragment stage records
|
||||
`PrecisionNote::DeviceFragmentRuns` (section 9). The conformance case `a2c-off-4-alpha-50`
|
||||
records four runs of a fully covered pixel at four samples on an Apple M3 Max, and compares the
|
||||
runs word as nonzero alone.
|
||||
|
||||
**Resource IDs and identifiers**
|
||||
|
||||
|
||||
@@ -506,10 +506,10 @@ An implemented container no case's Metal leg touches. These are the families of
|
||||
| cases whose Metal answer is `metal_run` | 1235 |
|
||||
| cases whose Metal answer is `carried` | 80 |
|
||||
| cases whose Metal answer is `never_returned` | 4 |
|
||||
| modules that loosen a measured value | 15 |
|
||||
| tolerances in all | 19 |
|
||||
| modules that loosen a measured value | 16 |
|
||||
| tolerances in all | 20 |
|
||||
| modules declaring a notice (loosening no value) | 43 |
|
||||
| loosenings used | `Unchecked`, `AnyOf`, `Absolute` |
|
||||
| loosenings used | `Unchecked`, `AnyOf`, `Absolute`, `Nonzero` |
|
||||
| justifications named | `Degradation`, `AcceptedDifference`, `WithoutCompression` |
|
||||
| modules forbidding a re-record | 8 |
|
||||
| `Side` methods (the suite's whole device vocabulary) | 133 |
|
||||
@@ -527,7 +527,7 @@ Each case module: the cases it holds, the `Side` methods it calls, and how many
|
||||
|
||||
| family | cases | Metal ran | compared | items reached |
|
||||
|---|---|---|---|---|
|
||||
| `alpha_coverage_pairs` | 17 | 17 | every field | 113 |
|
||||
| `alpha_coverage_pairs` | 17 | 17 | 1 tolerance(s): `Degradation` | 113 |
|
||||
| `argument_encoder_crossings` | 4 | 4 | every field | 41 |
|
||||
| `argument_encoders` | 5 | 5 | every field | 57 |
|
||||
| `astc_textures` | 42 | 42 | 1 tolerance(s): `Degradation` | 41 |
|
||||
|
||||
Reference in new issue
Block a user