Hold a shadowed extended-range colour beside its input attachment
On a device that orders framebuffer fetch through rasterization-order input attachments (lavapipe), a colour attachment whose extended-range half shadow the runtime keeps was taken off the input form, so the function read the codes and lost the values above 1.0 and below 0.0. Plan A (the pixel-interlock plan): the attachment stays a subpass input and output, and the function reads and writes its R16G16B16A16_SFLOAT shadow as a storage image inside the fragment shader pixel interlock. Discarded fragments leave the shadow alone; with a depth or stencil attachment the variant declares early fragment tests or is refused. A sample mask, alpha to coverage, a multisampled colour the function does not read and a function that loops over coverage are refused as FramebufferFetch. The runtime holds the shadow in the input form only where the device has the interlock, fragment stores, storage multisample when needed and the storage format, orders draws over the shadow with the interlocked-storage barrier, and re-records the instance's draws into the input form at the start of a shadow. SEMANTICS_VERSION 1979 -> 1980. Verified: not yet; the build, the unit tests and the lavapipe replay follow. (cherry picked from commit d521a571ffbce39dbb6490dc2d70cf02555d9678)
This commit is contained in:
1 parent
dd4ec79964
commit
1d1678f459
16 files changed
+547
-82
No files matched your search
@@ -98,7 +98,7 @@ use super::image_plan::{hiz_candidate, ImagePlan};
|
||||
use super::key_hash::KeyMap;
|
||||
use super::Device;
|
||||
use metal2vulkan::bind::PlanesCopy;
|
||||
use metal2vulkan::device::{DeviceProfile, DriverFact, FormatUsage, VkProperty};
|
||||
use metal2vulkan::device::{DeviceProfile, DriverFact, FormatUsage, VkFeature, VkProperty};
|
||||
use metal2vulkan::error::Capability;
|
||||
use metal2vulkan::metal::format::WordAttachment;
|
||||
use metal2vulkan::metal::TextureType;
|
||||
@@ -113,6 +113,30 @@ pub(crate) fn through_inputs(profile: &DeviceProfile) -> bool {
|
||||
profile.fragment().rasterization_order_color_access
|
||||
}
|
||||
|
||||
/// Whether a render pass on `profile` of `samples` samples, fetching through input attachments
|
||||
/// where `fetch_inputs`, may hold an extended-range color's `half` shadow
|
||||
/// (`render/extended_shadow.rs`): every pass that fetches in the pixel interlock, whose storage
|
||||
/// form reads and writes it; and one that fetches through input attachments on a device with
|
||||
/// `fragmentShaderPixelInterlock` and `fragmentStoresAndAtomics` that stores the shadow's format,
|
||||
/// and at more than one sample multisampled storage images, whose functions read and write the
|
||||
/// shadow beside the input attachment in the interlock (`lower::fragment`'s `input_shadow`).
|
||||
pub(crate) fn holds_extended_shadows(
|
||||
profile: &DeviceProfile,
|
||||
fetch_inputs: bool,
|
||||
samples: u32,
|
||||
) -> bool {
|
||||
if !fetch_inputs {
|
||||
return true;
|
||||
}
|
||||
profile.fragment().pixel_interlock
|
||||
&& profile
|
||||
.enabled()
|
||||
.features
|
||||
.contains(&VkFeature::FragmentStoresAndAtomics)
|
||||
&& profile.supports_format(Format::R16G16B16A16_SFLOAT, FormatUsage::StorageImage)
|
||||
&& (samples <= 1 || profile.images().storage_multisample)
|
||||
}
|
||||
|
||||
/// Whether the compile layer reads `profile`'s fetched color attachments as storage images in the
|
||||
/// ordered pixel interlock (`lower::fragment::fetch`): where it has `fragmentShaderPixelInterlock`
|
||||
/// without rasterization-order color attachment access.
|
||||
|
||||
@@ -188,15 +188,17 @@ impl GraphicsState {
|
||||
let formats: Vec<Option<PixelFormat>> = (descriptor.color_attachments.iter())
|
||||
.map(|color| color.as_ref().map(|c| c.pixel_format))
|
||||
.collect();
|
||||
let fetch_inputs = formats
|
||||
.iter()
|
||||
.flatten()
|
||||
.any(|&pf| pf != PixelFormat::Invalid)
|
||||
&& framebuffer_fetch::through_inputs(profile);
|
||||
let samples = descriptor.raster_sample_count;
|
||||
let shadows = predicted_shadows(
|
||||
graphics,
|
||||
&formats,
|
||||
descriptor.raster_sample_count,
|
||||
formats
|
||||
.iter()
|
||||
.flatten()
|
||||
.any(|&pf| pf != PixelFormat::Invalid)
|
||||
&& framebuffer_fetch::through_inputs(profile),
|
||||
samples,
|
||||
framebuffer_fetch::holds_extended_shadows(profile, fetch_inputs, samples),
|
||||
);
|
||||
let planned = |mut shape: BindShape| {
|
||||
shape.fragment_tests = tests;
|
||||
|
||||
@@ -1022,7 +1022,9 @@ impl DrawStates {
|
||||
struct InterlockedStorage {
|
||||
/// The pass's fragment imageblock storage (`fragment_imageblock.rs`).
|
||||
imageblock: bool,
|
||||
/// Colors in the interlocked storage form, the fetch's (`framebuffer_fetch.rs`).
|
||||
/// Colors in the interlocked storage form, the fetch's (`framebuffer_fetch.rs`), and in a
|
||||
/// pass that fetches through input attachments the extended-range colors' `half` shadows,
|
||||
/// which its draws read and write in the interlock beside them (`render/extended_shadow.rs`).
|
||||
colors: bool,
|
||||
/// The depth's stand-in, which a draw that tests the depth in the shader reads and may write
|
||||
/// (`depth_stand_in.rs`).
|
||||
@@ -1044,26 +1046,27 @@ impl InterlockedStorage {
|
||||
depth: true,
|
||||
};
|
||||
|
||||
/// What a draw of `graphics` whose colors in the interlocked storage form are `storage`
|
||||
/// What a draw of `graphics` whose colors in the interlocked storage form are `storage`, and
|
||||
/// which reads and writes extended-range shadows beside input attachments where `shadows`,
|
||||
/// reaches, and what it writes, on a device whose driver orders interlocked draws' colors by
|
||||
/// the interlock alone where `colors_ordered` (then no color is a kind of it). A draw that
|
||||
/// reaches the imageblock may write it, and one that tests the depth in the shader may write
|
||||
/// the depth's stand-in.
|
||||
/// reaches the imageblock may write it, one that tests the depth in the shader may write the
|
||||
/// depth's stand-in, and one that binds shadows may write them.
|
||||
fn of(
|
||||
graphics: &GraphicsState,
|
||||
storage: &[StorageAttachmentUse],
|
||||
(storage, shadows): (&[StorageAttachmentUse], bool),
|
||||
colors_ordered: bool,
|
||||
) -> (Self, Self) {
|
||||
let imageblock = graphics.fragment_imageblock.is_some();
|
||||
let depth = graphics.shader_tests.is_some();
|
||||
let reaches = Self {
|
||||
imageblock,
|
||||
colors: !colors_ordered && !storage.is_empty(),
|
||||
colors: !colors_ordered && (!storage.is_empty() || shadows),
|
||||
depth,
|
||||
};
|
||||
let writes = Self {
|
||||
imageblock,
|
||||
colors: !colors_ordered && storage.iter().any(|s| s.writes),
|
||||
colors: !colors_ordered && (storage.iter().any(|s| s.writes) || shadows),
|
||||
depth,
|
||||
};
|
||||
(reaches, writes)
|
||||
@@ -1956,7 +1959,7 @@ impl CommandBuffer {
|
||||
// an ended encoder's calls again, nor in a pass of several color groups, whose later
|
||||
// groups record after the first group's pass: its draws' secondary begins only where a
|
||||
// command records into it (`RenderCommandEncoder::begin_current_draws`).
|
||||
let extended = ExtendedShadows::of(descriptor, &layout, rate_map.is_some());
|
||||
let extended = ExtendedShadows::of(device, descriptor, &layout, rate_map.is_some());
|
||||
let opens = match again.is_none() && groups == 1 {
|
||||
true => inline_first::opens_inline(device, &layout, rate_map.is_some(), &extended),
|
||||
false => Err(NotInline::Encoders),
|
||||
@@ -8523,8 +8526,11 @@ impl RenderLowering {
|
||||
let storage = self.storage_attachments(graphics)?;
|
||||
let colors_ordered =
|
||||
(device.properties().driver_facts).contains(&DriverFact::InterlockOrdersDraws);
|
||||
// The shadows a draw of a pass that fetches through input attachments reads and writes
|
||||
// in the interlock (`render/extended_shadow.rs`), where the storage form holds none.
|
||||
let shadows = self.layout.fetch_inputs && !live.state.extended_shadows.is_empty();
|
||||
let (interlocked, interlocked_writes) =
|
||||
InterlockedStorage::of(graphics, &storage, colors_ordered);
|
||||
InterlockedStorage::of(graphics, (&storage, shadows), colors_ordered);
|
||||
let failing = match &failing_state {
|
||||
None => None,
|
||||
Some(state) => {
|
||||
|
||||
@@ -468,7 +468,7 @@ impl RenderLowering {
|
||||
let shape = PassShape::of(&layout)?;
|
||||
let compatible = render_target::shared_compatible_pass(&device, &shape)?;
|
||||
let draws = core.command_buffer().begin_draws(&compatible)?;
|
||||
let extended = ExtendedShadows::of(&descriptor, &layout, rate_map.is_some());
|
||||
let extended = ExtendedShadows::of(&device, &descriptor, &layout, rate_map.is_some());
|
||||
let opening = Opening::new(
|
||||
&descriptor,
|
||||
(layout, extended),
|
||||
|
||||
@@ -17,26 +17,36 @@
|
||||
//! Each draw that binds it reads and writes it in the fragment shader, inside the pixel
|
||||
//! interlock that orders the color's own storage form, so what orders that form between draws
|
||||
//! orders it too (`InterlockedStorage`'s colors: a barrier, or the interlock alone on a driver
|
||||
//! measured to order such draws).
|
||||
//! measured to order such draws). In a pass that fetches through input attachments the color
|
||||
//! stays the subpass's, its codes read and written through its input attachment in
|
||||
//! rasterization order, and the draw reads and writes the shadow beside it inside the pixel
|
||||
//! interlock (`lower::fragment`'s `input_shadow`), behind the same barrier; there a multisampled
|
||||
//! pass holds the samples in a multisampled image.
|
||||
//! - **The start.** The pass's instances keep their draws for recording again
|
||||
//! (`render/reroute.rs`) on every device while the pass has such a color, of one layer, without
|
||||
//! a rasterization-rate map, fetching in the pixel interlock; a multisampled pass's draws do not
|
||||
//! a rasterization-rate map, fetching in the pixel interlock, or through input attachments on a
|
||||
//! device whose functions read and write the shadow beside them (the pixel interlock, fragment
|
||||
//! stores, the shadow's format as a storage image and, at more than one sample, multisampled
|
||||
//! storage images: `framebuffer_fetch::holds_extended_shadows`); a multisampled pass's draws do not
|
||||
//! record again, so there a color starts at the first draw that reads it (blends into it,
|
||||
//! fetches it), not only at one that reads what an earlier draw wrote. At the draw
|
||||
//! (the gate above), a color that no instance before the current one wrote (no draw, tile
|
||||
//! dispatch or execution of render commands) starts: where the current instance's draws wrote
|
||||
//! it, they record again first into an instance that leaves the color out of its subpass, in
|
||||
//! its place, holding the shadow (`record_leaving_out`); else the draw's own instance holds it.
|
||||
//! it, they record again first into an instance that leaves the color out of its subpass (in a
|
||||
//! pass that fetches through input attachments, one of the same shape), in its place, holding
|
||||
//! the shadow (`record_leaving_out`); else the draw's own instance holds it.
|
||||
//! The instance that first holds it sets it before it, between barriers: to the clear color's
|
||||
//! halves where the pass clears the color (`ExtendedRange::clear_tile_value`, every sample),
|
||||
//! else, in a single-sampled pass, by the shadow load of the codes
|
||||
//! (`bind::extended_shadow_module`), which writes each texel's tile value, the fetch's own
|
||||
//! decode. A color an earlier instance wrote, or whose instance's draws cannot record again,
|
||||
//! decode, reading the codes as a storage image (in a pass that fetches through input
|
||||
//! attachments, where the texture's image has that usage). A color an earlier instance wrote, or whose instance's draws cannot record again,
|
||||
//! keeps the codes (the announcement), as does one whose start fails (its draws' shadowed
|
||||
//! variants refused, a load the device cannot build, a multisampled pass that does not clear
|
||||
//! it), for the rest of the pass.
|
||||
//! - **The end.** A draw whose shadowed variant is refused (a mesh pipeline's, an amplified
|
||||
//! draw's) gives up the shadows of the colors it writes or reads, and an execution of render
|
||||
//! draw's, and over input attachments one whose shadow stores the tests or the coverage could
|
||||
//! leave apart from its codes: `lower::fragment`'s `input_shadow`) gives up the shadows of the colors it writes or reads, and an execution of render
|
||||
//! commands or a tile dispatch, whose commands write the codes alone, gives up every shadow:
|
||||
//! the codes hold the encode of the last `half` written, and the draws after it see them, as
|
||||
//! before the shadow. None starts again in the pass. Not while the encoder records an
|
||||
@@ -83,8 +93,9 @@ pub(super) struct ExtendedShadows {
|
||||
/// The pass's colors of a measured extended-range form, by index: the form, and the halves
|
||||
/// its tile holds after the pass's clear where it clears.
|
||||
colors: BTreeMap<u32, (ExtendedRange, Option<[f32; 4]>)>,
|
||||
/// The pass holds shadows: of one layer, fetching in the pixel interlock, without a
|
||||
/// rasterization-rate map, with such a color.
|
||||
/// The pass holds shadows: of one layer, without a rasterization-rate map, with such a color,
|
||||
/// fetching in the pixel interlock, or through input attachments on a device whose functions
|
||||
/// read and write the shadow beside them (`framebuffer_fetch::holds_extended_shadows`).
|
||||
holds: bool,
|
||||
/// The first instance, by index, whose draws, tile dispatches or executed commands may have
|
||||
/// written each color.
|
||||
@@ -102,9 +113,10 @@ pub(super) struct ExtendedShadows {
|
||||
}
|
||||
|
||||
impl ExtendedShadows {
|
||||
/// The shadows of the pass `descriptor` describes, of `layout`, with a rasterization-rate
|
||||
/// map where `rate_mapped`: none made yet.
|
||||
/// The shadows of the pass `descriptor` describes, of `layout`, on `device`, with a
|
||||
/// rasterization-rate map where `rate_mapped`: none made yet.
|
||||
pub(super) fn of(
|
||||
device: &Device,
|
||||
descriptor: &RenderPassDescriptor,
|
||||
layout: &PassLayout,
|
||||
rate_mapped: bool,
|
||||
@@ -123,8 +135,15 @@ impl ExtendedShadows {
|
||||
Some((index, (form, tile)))
|
||||
})
|
||||
.collect();
|
||||
let holds =
|
||||
!colors.is_empty() && !layout.fetch_inputs && layout.layers == 1 && !rate_mapped;
|
||||
let profile = device.compile_device().profile();
|
||||
let holds = !colors.is_empty()
|
||||
&& framebuffer_fetch::holds_extended_shadows(
|
||||
profile,
|
||||
layout.fetch_inputs,
|
||||
layout.samples,
|
||||
)
|
||||
&& layout.layers == 1
|
||||
&& !rate_mapped;
|
||||
ExtendedShadows {
|
||||
colors,
|
||||
holds,
|
||||
@@ -393,8 +412,7 @@ pub(super) fn reads_color(graphics: &GraphicsState, index: u32) -> bool {
|
||||
|
||||
/// The colors whose shadows a state's creation predicts its first draw holds
|
||||
/// (`pipeline/predicted.rs`), for a pipeline of `graphics` whose color attachments are `colors`
|
||||
/// (each index's pixel format) at `samples`, in a pass fetching through input attachments where
|
||||
/// `fetch_inputs`: in a multisampled pass, each color of a measured extended-range form the draw
|
||||
/// (each index's pixel format) at `samples`, in a pass that `holds` shadows: in a multisampled pass, each color of a measured extended-range form the draw
|
||||
/// reads ([`reads_color`]), as such a pass starts that color's shadow at the first draw that reads
|
||||
/// it where it clears the color ([`RenderLowering::start_extended_shadows`]), and a multisampled
|
||||
/// color's only contents at the pass's start that are not undefined are its clear's or its
|
||||
@@ -402,16 +420,17 @@ pub(super) fn reads_color(graphics: &GraphicsState, index: u32) -> bool {
|
||||
/// pass, which starts the shadow only where an earlier draw of the pass wrote the color or its
|
||||
/// clear's codes cannot hold the clear, which no creation sees: of the suite's single-sampled
|
||||
/// draws that blend into such a color, the `xr-blend-planes-*` ones blend once over a loaded
|
||||
/// target and hold no shadow. None where the pass would hold no shadow ([`ExtendedShadows::of`]):
|
||||
/// a device whose pass fetches through input attachments; the creation predicts the pass of one
|
||||
/// target and hold no shadow. None where the pass would hold no shadow (not `holds`,
|
||||
/// [`ExtendedShadows::of`]: a device whose pass fetches through input attachments and whose
|
||||
/// functions cannot read and write the shadow beside them); the creation predicts the pass of one
|
||||
/// layer without a rasterization-rate map, Metal's defaults.
|
||||
pub(crate) fn predicted_shadows(
|
||||
graphics: &GraphicsState,
|
||||
colors: &[Option<PixelFormat>],
|
||||
samples: u32,
|
||||
fetch_inputs: bool,
|
||||
holds: bool,
|
||||
) -> BTreeSet<u32> {
|
||||
if samples <= 1 || fetch_inputs {
|
||||
if samples <= 1 || !holds {
|
||||
return BTreeSet::new();
|
||||
}
|
||||
(0u32..)
|
||||
@@ -556,12 +575,22 @@ impl RenderLowering {
|
||||
if self.layout.samples > 1 {
|
||||
return Ok(false);
|
||||
}
|
||||
// The load reads the codes as a storage image: in a pass that fetches through input
|
||||
// attachments, only where the texture's image has that usage.
|
||||
let raw = self
|
||||
.layout
|
||||
.colors
|
||||
.get(c as usize)
|
||||
.and_then(Option::as_ref)
|
||||
.is_some_and(|color| color.target.format == form.raw_format());
|
||||
.is_some_and(|color| {
|
||||
color.target.format == form.raw_format()
|
||||
&& (!self.layout.fetch_inputs
|
||||
|| color
|
||||
.target
|
||||
.texture
|
||||
.image_plan()
|
||||
.is_ok_and(|plan| plan.usage.contains(ImageUsageFlags::STORAGE)))
|
||||
});
|
||||
if !raw {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Recording a render pass instance's draws again, into an instance that leaves more colors out
|
||||
//! of its subpass, in its place: the start of an extended-range color's `half` shadow where the
|
||||
//! current instance's draws wrote the color (`render/extended_shadow.rs`).
|
||||
//! of its subpass (in a pass that fetches through input attachments, one of the same shape), in
|
||||
//! its place: the start of an extended-range color's `half` shadow where the current instance's
|
||||
//! draws wrote the color (`render/extended_shadow.rs`).
|
||||
//!
|
||||
//! In a pass that may hold such a shadow (`ExtendedShadows::keeps_draws`), on every device, while
|
||||
//! every recording of the current instance is a draw that can record again (below), each draw
|
||||
@@ -131,7 +132,6 @@ impl RenderLowering {
|
||||
|| self.rerouting
|
||||
|| !current.recorded
|
||||
|| !kept
|
||||
|| self.layout.fetch_inputs
|
||||
|| self.layout.samples != 1
|
||||
|| self.dispatched
|
||||
|| self.barrier
|
||||
@@ -146,6 +146,13 @@ impl RenderLowering {
|
||||
return Ok(false);
|
||||
}
|
||||
let locations = current.shape.locations.clone();
|
||||
// A pass that fetches through input attachments leaves no color out: its draws read and
|
||||
// write the shadow beside the color's input attachment (`lower::fragment`'s
|
||||
// `input_shadow`), so the rerouted instance is one of the current one's shape.
|
||||
let colors = match self.layout.fetch_inputs {
|
||||
true => Vec::new(),
|
||||
false => colors,
|
||||
};
|
||||
// `rerouting` has `next_instance` take the current instance's place as an empty one's.
|
||||
// Ordered after the current instance's draws: a new instance even where its shape is
|
||||
// the current one's (a shadow's start, whose color the current instance may already
|
||||
|
||||
@@ -1308,13 +1308,23 @@ fn plan(p: &RenderPipeline, device: &Device, shape: &BindShape) -> Result<Bindin
|
||||
.map(|a| a.color_index)
|
||||
.collect();
|
||||
// The extended-range colors whose `half` shadow the draw's instance holds that the fragment
|
||||
// function writes or reads in the storage form: the variant that reads and writes the
|
||||
// shadows beside the codes. Every such color is in a pass of one layer (the encoder holds no
|
||||
// other shadow); a pipeline compiled with shadows binds them. In a multisampled pipeline only
|
||||
// a color the pipeline already reads in the storage form (a blended or fetched one, whose
|
||||
// function runs per sample): a plain writer's would be moved into the per-sample form, which
|
||||
// runs the function per sample where Metal runs it per pixel, as for the interlocked colors
|
||||
// above.
|
||||
// function writes or reads in the storage form, or, on a device that fetches through input
|
||||
// attachments, writes or reads through its input attachment: the variant that reads and writes
|
||||
// the shadows beside the codes. Every such color is in a pass of one layer (the encoder holds
|
||||
// no other shadow); a pipeline compiled with shadows binds them. In a multisampled pipeline
|
||||
// only a color the pipeline already reads (a blended or fetched one, whose function runs per
|
||||
// sample): a plain writer's would run the function per sample where Metal runs it per pixel,
|
||||
// as for the interlocked colors above.
|
||||
let reads_color = |c: u32| {
|
||||
p.graphics
|
||||
.storage_attachments
|
||||
.iter()
|
||||
.any(|a| a.color_index == c)
|
||||
|| p.graphics
|
||||
.input_attachments
|
||||
.iter()
|
||||
.any(|a| a.color_index == c)
|
||||
};
|
||||
let extended_shadows: std::collections::BTreeSet<u32> = shape
|
||||
.extended_shadows
|
||||
.iter()
|
||||
@@ -1322,18 +1332,10 @@ fn plan(p: &RenderPipeline, device: &Device, shape: &BindShape) -> Result<Bindin
|
||||
.filter(|&c| {
|
||||
1u32.checked_shl(c)
|
||||
.is_some_and(|bit| p.graphics.color_outputs & bit != 0)
|
||||
|| p.graphics
|
||||
.storage_attachments
|
||||
.iter()
|
||||
.any(|a| a.color_index == c)
|
||||
|| reads_color(c)
|
||||
})
|
||||
.collect();
|
||||
let moved_shadow = extended_shadows.iter().any(|&c| {
|
||||
!p.graphics
|
||||
.storage_attachments
|
||||
.iter()
|
||||
.any(|a| a.color_index == c)
|
||||
});
|
||||
let moved_shadow = extended_shadows.iter().any(|&c| !reads_color(c));
|
||||
if !extended_shadows.is_empty()
|
||||
&& (mesh
|
||||
|| (p.graphics.rasterization_samples.as_raw() > 1 && moved_shadow)
|
||||
|
||||
Vendored
+1
-1
@@ -60,7 +60,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 = 1979;
|
||||
pub const SEMANTICS_VERSION: u32 = 1980;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
//! interface records the attachment (`StageIo::extended_range_colors`), so link holds a stage
|
||||
//! compiled for it to the pipeline's attachments. Where the pipeline blends such an attachment the
|
||||
//! function writes, the write blends over the same input attachment (`input_blend`), which a
|
||||
//! `[[color(n)]]` read of the attachment shares ([`input_texel`]).
|
||||
//! `[[color(n)]]` read of the attachment shares ([`input_texel`]). Where the draw's instance holds
|
||||
//! the attachment's `half` shadow, a read is the shadow's texel instead (`input_shadow`).
|
||||
//!
|
||||
//! **An 8-bit sRGB attachment** (`RGBA8Unorm_sRGB`, `BGRA8Unorm_sRGB` and the rest) reads through
|
||||
//! its input attachment the device's decode of its bytes, Vulkan's sRGB EOTF within the device's
|
||||
@@ -421,12 +422,19 @@ pub(super) fn value(
|
||||
if cx.plan.families.fragment.fetch.contains_key(&c.color) {
|
||||
return super::fetch::value(cx, fb, c);
|
||||
}
|
||||
let texel = input_texel(cx, fb, c.color)?;
|
||||
let texel = match c.extended {
|
||||
Some(form) => extended_range::tile_value(fb, form, texel)?,
|
||||
let texel = match (c.extended, super::input_shadow::shadows(cx, c.color)) {
|
||||
// The instance's shadow holds the tile value itself (`input_shadow`).
|
||||
(Some(_), Some(_)) => super::input_shadow::read(cx, fb, c.color)?,
|
||||
(Some(form), None) => {
|
||||
let texel = input_texel(cx, fb, c.color)?;
|
||||
extended_range::tile_value(fb, form, texel)?
|
||||
}
|
||||
// The image's red, Metal's alpha: `(0, 0, 0, r)`.
|
||||
None if c.alpha_red => alpha_in_red(fb, texel)?,
|
||||
None => texel,
|
||||
(None, _) if c.alpha_red => {
|
||||
let texel = input_texel(cx, fb, c.color)?;
|
||||
alpha_in_red(fb, texel)?
|
||||
}
|
||||
(None, _) => input_texel(cx, fb, c.color)?,
|
||||
};
|
||||
let x = match c.form.lanes {
|
||||
4 => texel,
|
||||
|
||||
@@ -188,7 +188,9 @@
|
||||
//! value the shadow holds is a `half`, so the device's conversions both ways are exact, and the
|
||||
//! codes always hold the encode of the last `half` written to each channel. A shadowed attachment
|
||||
//! the storage form does not take, or of a padded or bfloat form, is refused whatever the policy
|
||||
//! (the runtime keeps such a draw off the shadow).
|
||||
//! (the runtime keeps such a draw off the shadow). On a device that orders fetch through
|
||||
//! rasterization-order input attachments the attachment keeps its input attachment, and the
|
||||
//! function reads and writes the shadow beside it inside the interlock (`input_shadow`).
|
||||
//!
|
||||
//! **A 16-bit float attachment's blend** (`R16Float`, `RG16Float`, `RGBA16Float`): no Vulkan blend
|
||||
//! applies to a storage write, so the shader computes Metal's: the write reads the texel at the pixel inside the interlock, blends the function's `half`
|
||||
@@ -1390,7 +1392,7 @@ pub(super) fn body_facts(cx: &SelectCx<'_>) -> BodyFacts {
|
||||
/// constant index (another index is refused when the parameter is planned). Each such
|
||||
/// parameter's type is checked here, so a function no pipeline state would make lowerable is
|
||||
/// refused before it needs one.
|
||||
fn colors_read(cx: &SelectCx<'_>, used: &BTreeSet<u32>) -> Result<BTreeSet<u32>, Error> {
|
||||
pub(super) fn colors_read(cx: &SelectCx<'_>, used: &BTreeSet<u32>) -> Result<BTreeSet<u32>, Error> {
|
||||
let mut out = BTreeSet::new();
|
||||
for b in cx
|
||||
.entry
|
||||
@@ -2362,7 +2364,7 @@ pub(super) fn declare_shadow(
|
||||
/// The shadow of attachment `color`, held as `samples` ([`declare_shadow`]), the texel of the
|
||||
/// invocation's sample, and the access's image operands, as [`image_and_texel`] gives the
|
||||
/// attachment's own.
|
||||
fn shadow_and_texel(
|
||||
pub(super) fn shadow_and_texel(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
color: u32,
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
//! `half` shadow does (the announcement, `extended-range-blends-stored-codes`, stays the runtime's
|
||||
//! there).
|
||||
//!
|
||||
//! Where the draw's instance holds the attachment's `half` shadow (`input_shadow`), the blend's
|
||||
//! destination is the shadow's texel, Metal's tile value, and the write stores the blend's result
|
||||
//! there too; a merge stores the written channels' `half`s there.
|
||||
//!
|
||||
//! There too an unblended write of some of the codes one word holds (`BGR10_XR`'s word, the
|
||||
//! two-plane forms' color word, `color_writes::merged_extended`), which no mask of the raw
|
||||
//! components gives, reads the texel's raw codes through the input attachment and writes the
|
||||
@@ -315,6 +319,9 @@ pub(crate) fn texel(
|
||||
vk::ColorComponentFlags::A,
|
||||
]
|
||||
.map(|c| ib.kept.contains(c));
|
||||
// The instance's `half` shadow of the attachment, which the write reads as its destination
|
||||
// and stores its value into (`input_shadow`).
|
||||
let shadowed = super::input_shadow::shadows(cx, color).is_some();
|
||||
let Some(b) = &ib.blend else {
|
||||
if !ib.merges() {
|
||||
return crate::lower::stage_io::extended_color::texel(fb, ib.form, form, part);
|
||||
@@ -322,17 +329,32 @@ pub(crate) fn texel(
|
||||
// The unblended write's `half`, encoded, the codes the mask keeps taken from the texel.
|
||||
let codes = super::color::input_texel(cx, fb, color)?;
|
||||
let v = crate::lower::stage_io::extended_color::held(fb, ib.form, form, part)?;
|
||||
if shadowed {
|
||||
super::input_shadow::store(cx, fb, color, v)?;
|
||||
}
|
||||
return extended_range::encode_keeping(fb, ib.form, v, (codes, kept));
|
||||
};
|
||||
let s1 = fetch::blend_second(cx, b, second)?;
|
||||
let codes = super::color::input_texel(cx, fb, color)?;
|
||||
let d = extended_range::tile_value(fb, ib.form, codes)?;
|
||||
let (d, codes) = match shadowed {
|
||||
true => (super::input_shadow::read(cx, fb, color)?, None),
|
||||
false => {
|
||||
let codes = super::color::input_texel(cx, fb, color)?;
|
||||
(extended_range::tile_value(fb, ib.form, codes)?, Some(codes))
|
||||
}
|
||||
};
|
||||
let constant = fetch::blend_constant(cx, fb, b)?;
|
||||
let ranges = Some(extended_range::blend::extended_ranges(ib.form));
|
||||
let v = extended_range::blend::native(fb, b, ranges, (part, s1, d), constant)?;
|
||||
if shadowed {
|
||||
super::input_shadow::store(cx, fb, color, v)?;
|
||||
}
|
||||
if ib.kept.is_empty() {
|
||||
return extended_range::encode(fb, ib.form, v);
|
||||
}
|
||||
let codes = match codes {
|
||||
Some(codes) => codes,
|
||||
None => super::color::input_texel(cx, fb, color)?,
|
||||
};
|
||||
extended_range::encode_keeping(fb, ib.form, v, (codes, kept))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
//! The `half` shadow of an extended-range attachment on a device that orders framebuffer fetch
|
||||
//! through rasterization-order input attachments (lavapipe).
|
||||
//!
|
||||
//! Metal's tile memory holds a `BGR10_XR`, `BGRA10_XR` or `RGB10A8_2P_XR10` color (and the `_sRGB`
|
||||
//! twins) as `half` through a render pass and rounds it to the codes only at the store, so a blend
|
||||
//! or a fetch onto what an earlier draw of the pass wrote sees that draw's `half` (`fetch`'s module
|
||||
//! docs, "The `half` shadow"). Where the draw's render pass instance holds the attachment's shadow
|
||||
//! (`LoweringInputs::extended_shadows`) on such a device, the attachment stays the subpass's: its
|
||||
//! codes are read through its input attachment and written through the output variable, ordered
|
||||
//! by rasterization-order attachment access, as without the shadow (`input_blend`, `color`). The
|
||||
//! shadow is a second storage image of the attachment's extent in `Rgba16f`
|
||||
//! (`ResourceKind::ExtendedShadow`, `fetch::declare_shadow`), one sample, or a multisampled image of
|
||||
//! the pipeline's samples read and written at the invocation's `SampleId`. The function's body runs
|
||||
//! inside the ordered pixel interlock (`fragment::wrap_entry`), which orders each fragment's read and
|
||||
//! write of the shadow after every earlier fragment's of the pixel in primitive order, across the
|
||||
//! draws of the instance, as the storage form's are. A `[[color(n)]]` read and a blend's destination
|
||||
//! are the shadow's texel as Metal reads the tile (`extended_range::tile_read`), and every write
|
||||
//! stores the value it computes there, unclamped, the blend's result or the unblended output's
|
||||
//! `half` (the channels a write mask keeps as the shadow held them), beside the codes' encode,
|
||||
//! unless the invocation was discarded. Every value the shadow holds is a `half`, so the device's
|
||||
//! conversions both ways are exact, and the codes always hold the encode of the last `half` written
|
||||
//! to each written channel.
|
||||
//!
|
||||
//! The device's depth and stencil tests run after the function, so a store of the shadow before
|
||||
//! them would keep a fragment they drop and its codes do not: beside a depth or stencil attachment
|
||||
//! the module declares early fragment tests, which drop the fragment before its codes and its shadow
|
||||
//! alike, where that keeps Metal's answers (Metal's function declares them, or it discards nothing,
|
||||
//! writes no other memory and returns no depth or stencil, on a driver that keeps an early-tests
|
||||
//! function's image writes at the pipeline's samples). Every other shadowed function is refused
|
||||
//! (`NotImplemented(FramebufferFetch)`), and so is one that returns a sample mask, one in a pipeline
|
||||
//! with alpha to coverage (both drop samples of the codes after the function), one that loops over
|
||||
//! its covered samples, and in a multisampled pipeline one that does not read the attachment (Metal
|
||||
//! runs it once per pixel, where the shadow holds each sample): the runtime keeps such a draw's
|
||||
//! colors on the codes (`render/extended_shadow.rs`), which it announces.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::air::abi::{AbiInt, OutputRole, Stage as AbiStage};
|
||||
use crate::device::profile::DriverWorkaround;
|
||||
use crate::device::requirements::{FormatUsage, VkFeature};
|
||||
use crate::device::DeviceProfile;
|
||||
use crate::error::{Attachment, Capability, Error, Feature, RuntimeInput, Unsupported};
|
||||
use crate::lower::arith::extended_range;
|
||||
use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::SelectCx;
|
||||
use crate::lower::stage_io;
|
||||
use crate::lower::sync::memory_model;
|
||||
use crate::metal::format::ExtendedRange;
|
||||
use crate::metal::ColorWriteMask;
|
||||
use crate::pipeline::sym::Stage;
|
||||
use crate::spirv::builder::constructs::{ArmEnd, ArmFn};
|
||||
use crate::spirv::builder::FunctionBuilder;
|
||||
use crate::spirv::error::BResult;
|
||||
use crate::spirv::ids::Value as SValue;
|
||||
use crate::spirv::ir::{MemAccess, UnOp};
|
||||
use crate::vk;
|
||||
|
||||
use super::{fetch, InputBlend, StorageSamples};
|
||||
|
||||
/// An extended-range attachment whose `half` shadow the draw's render pass instance holds, on a
|
||||
/// device that fetches through input attachments (see the module docs).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct InputShadow {
|
||||
/// The attachment's form.
|
||||
pub form: ExtendedRange,
|
||||
/// How the shadow holds the pipeline's samples: one, or a multisampled image of them.
|
||||
pub samples: StorageSamples,
|
||||
/// The format's channels (red, green, blue, alpha) the function's write keeps as the shadow
|
||||
/// held them, those its write mask leaves out; `None` where the function does not write the
|
||||
/// attachment, and all four where its write stores none of them.
|
||||
pub kept: Option<[bool; 4]>,
|
||||
}
|
||||
|
||||
impl InputShadow {
|
||||
/// Whether the function stores into the shadow: it writes some of the format's channels.
|
||||
pub fn stores(&self) -> bool {
|
||||
self.kept.is_some_and(|kept| !kept.iter().all(|&k| k))
|
||||
}
|
||||
}
|
||||
|
||||
/// The shadow's format.
|
||||
const SHADOW_FORMAT: vk::Format = vk::Format::R16G16B16A16_SFLOAT;
|
||||
|
||||
/// What the device lacks for the shadow on `p` (see the module docs): the ordered pixel interlock,
|
||||
/// fragment stores, the shadow's format as a storage image, and, `multisampled`, multisampled
|
||||
/// storage images.
|
||||
fn device_form(p: &DeviceProfile, multisampled: bool) -> Result<(), Unsupported> {
|
||||
let f = p.fields();
|
||||
let mut missing = Vec::new();
|
||||
if !f.fragment.pixel_interlock {
|
||||
missing.push(Capability::Feature(VkFeature::FragmentShaderPixelInterlock));
|
||||
}
|
||||
if !f.leaf.fragment_stores_and_atomics {
|
||||
missing.push(Capability::Feature(VkFeature::FragmentStoresAndAtomics));
|
||||
}
|
||||
if multisampled && !f.images.storage_multisample {
|
||||
missing.push(Capability::Feature(
|
||||
VkFeature::ShaderStorageImageMultisample,
|
||||
));
|
||||
}
|
||||
if !p.supports_format(SHADOW_FORMAT, FormatUsage::StorageImage) {
|
||||
missing.push(Capability::Format {
|
||||
format: SHADOW_FORMAT,
|
||||
usage: FormatUsage::StorageImage,
|
||||
});
|
||||
}
|
||||
match missing.is_empty() {
|
||||
true => Ok(()),
|
||||
false => Err(Unsupported::needs_any_of(
|
||||
Feature::FramebufferFetch,
|
||||
vec![missing],
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Plan the shadows of the extended-range attachments the draw's instance holds
|
||||
/// (`LoweringInputs::extended_shadows`) on a device that fetches through input attachments, before
|
||||
/// the stage interface and after the blends over input attachments (`input_blend::plan`): each one
|
||||
/// the function writes through its first output or reads, with its samples and the channels its
|
||||
/// write keeps, the early tests beside a depth or stencil attachment, the pixel's `FragCoord` and
|
||||
/// the invocation's sample (see the module docs).
|
||||
pub(super) fn plan(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
if cx.stage != Stage::Fragment
|
||||
|| cx.inputs.extended_shadows.is_empty()
|
||||
|| !fetch::inputs_order(cx.profile)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
let multisampled = cx.inputs.multisampled;
|
||||
device_form(cx.profile, multisampled)?;
|
||||
let Some(inputs) = cx.inputs.framebuffer_fetch.clone() else {
|
||||
return Err(Error::NeedsInput(RuntimeInput::FramebufferFetch));
|
||||
};
|
||||
let body = fetch::body_facts(cx);
|
||||
let read = fetch::colors_read(cx, &body.used)?;
|
||||
let outputs = &cx.entry.ep.outputs;
|
||||
let returns = |role: fn(&OutputRole) -> bool| outputs.iter().any(|o| role(&o.role));
|
||||
let exports = returns(|r| matches!(r, OutputRole::Depth(_) | OutputRole::Stencil));
|
||||
let sample_mask = returns(|r| matches!(r, OutputRole::SampleMask));
|
||||
let declared_early = matches!(
|
||||
cx.entry.ep.stage,
|
||||
AbiStage::Fragment {
|
||||
early_fragment_tests: true
|
||||
}
|
||||
);
|
||||
let refused = |color: u32| -> Error {
|
||||
let refused = Unsupported::not_implemented(Feature::FramebufferFetch);
|
||||
refused.at_attachment(Attachment::Color(color)).into()
|
||||
};
|
||||
let mut planned = BTreeMap::new();
|
||||
for &color in &cx.inputs.extended_shadows {
|
||||
let Some(form) = (cx.inputs.extended_range_colors.get(&color))
|
||||
.map(|e| e.form)
|
||||
.filter(|f| !f.padded() && !f.bfloat())
|
||||
else {
|
||||
return Err(refused(color));
|
||||
};
|
||||
let writes = outputs.iter().any(|o| {
|
||||
matches!(
|
||||
o.role,
|
||||
OutputRole::RenderTarget {
|
||||
attachment: AbiInt::Const(a),
|
||||
index: 0,
|
||||
..
|
||||
} if a == color
|
||||
)
|
||||
});
|
||||
let reads = read.contains(&color)
|
||||
|| (cx.families.fragment.input_blends)
|
||||
.get(&color)
|
||||
.is_some_and(InputBlend::reads);
|
||||
if !(writes || reads) || sample_mask || inputs.alpha_to_coverage || (multisampled && !reads)
|
||||
{
|
||||
return Err(refused(color));
|
||||
}
|
||||
let kept = match writes {
|
||||
true => {
|
||||
let Some(a) = inputs.attachments.get(&color).copied().flatten() else {
|
||||
return Err(Error::NeedsInput(RuntimeInput::FramebufferFetch));
|
||||
};
|
||||
let kept = fetch::kept_channels(a.pixel_format, a.write_mask, true);
|
||||
Some(
|
||||
[
|
||||
ColorWriteMask::RED,
|
||||
ColorWriteMask::GREEN,
|
||||
ColorWriteMask::BLUE,
|
||||
ColorWriteMask::ALPHA,
|
||||
]
|
||||
.map(|c| kept.contains(c)),
|
||||
)
|
||||
}
|
||||
false => None,
|
||||
};
|
||||
let samples = match multisampled {
|
||||
true => StorageSamples::Multisampled,
|
||||
false => StorageSamples::One,
|
||||
};
|
||||
cx.families.arith.converts(form);
|
||||
planned.insert(
|
||||
color,
|
||||
InputShadow {
|
||||
form,
|
||||
samples,
|
||||
kept,
|
||||
},
|
||||
);
|
||||
}
|
||||
// Beside a depth or stencil attachment, the shadow's stores follow the tests only under early
|
||||
// tests (see the module docs).
|
||||
let stores = planned.values().any(InputShadow::stores);
|
||||
if inputs.depth_or_stencil && stores && !declared_early {
|
||||
let dropped = multisampled
|
||||
&& cx
|
||||
.profile
|
||||
.fields()
|
||||
.workarounds
|
||||
.contains(&DriverWorkaround::EarlyTestsDropMultisampledImageWrites);
|
||||
if exports || body.discards || body.side_effects || dropped {
|
||||
let color = planned.keys().next().copied().unwrap_or_default();
|
||||
return Err(refused(color));
|
||||
}
|
||||
cx.families.fragment.fetch_early_tests = true;
|
||||
}
|
||||
fetch::plan_sample(cx)?;
|
||||
let coord = stage_io::frag_coord(cx);
|
||||
cx.families.fragment.fetch_coord = Some(coord);
|
||||
cx.descriptors.storage_images = (cx.descriptors.storage_images)
|
||||
.saturating_add(u32::try_from(planned.len()).unwrap_or(u32::MAX));
|
||||
cx.families.fragment.input_shadows = planned;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Whether the function holds attachment `color`'s shadow on a device that fetches through input
|
||||
/// attachments.
|
||||
pub(crate) fn shadows(cx: &EmitCx<'_>, color: u32) -> Option<InputShadow> {
|
||||
cx.plan.families.fragment.input_shadows.get(&color).copied()
|
||||
}
|
||||
|
||||
/// The tile value attachment `color`'s shadow holds at the invocation's pixel (and sample), read
|
||||
/// inside the interlock: Metal's read of what the tile holds (`extended_range::tile_read`).
|
||||
pub(crate) fn read(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
color: u32,
|
||||
) -> BResult<SValue> {
|
||||
let Some(shadow) = shadows(cx, color) else {
|
||||
return Err(cx.fail(format!("attachment {color} holds no shadow")));
|
||||
};
|
||||
let (image, at, ops) = fetch::shadow_and_texel(cx, fb, color, shadow.samples)?;
|
||||
let mem = memory_model::coherence(cx.plan).texel(fb)?;
|
||||
let texel = fb.read(image, at, &ops, mem)?;
|
||||
extended_range::tile_read(fb, shadow.form, texel)
|
||||
}
|
||||
|
||||
/// Store `v`, the `half`s a write of attachment `color` leaves in Metal's tile (a `vec4`), into
|
||||
/// its shadow at the invocation's pixel (and sample), the channels the write keeps as the shadow
|
||||
/// held them, unless the invocation was discarded. Nothing where the write stores none of the
|
||||
/// format's channels.
|
||||
pub(crate) fn store(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
color: u32,
|
||||
v: SValue,
|
||||
) -> BResult<()> {
|
||||
let Some(shadow) = shadows(cx, color) else {
|
||||
return Err(cx.fail(format!("attachment {color} holds no shadow")));
|
||||
};
|
||||
let Some(kept) = shadow.kept.filter(|_| shadow.stores()) else {
|
||||
return Ok(());
|
||||
};
|
||||
let v = match kept.iter().any(|&k| k) {
|
||||
true => {
|
||||
let held = read(cx, fb, color)?;
|
||||
let lanes: Vec<u32> = (kept.iter().zip(0..4u32))
|
||||
.map(|(&kept, lane)| match kept {
|
||||
true => 4 + lane,
|
||||
false => lane,
|
||||
})
|
||||
.collect();
|
||||
fb.vector_shuffle(v, held, &lanes)?
|
||||
}
|
||||
false => v,
|
||||
};
|
||||
let (image, at, ops) = fetch::shadow_and_texel(cx, fb, color, shadow.samples)?;
|
||||
let mem = memory_model::coherence(cx.plan).texel(fb)?;
|
||||
let Some(g) = cx.decl.families.fragment.discarded else {
|
||||
return fb.write(image, at, v, &ops, mem);
|
||||
};
|
||||
let p = fb.module().global_value(g)?;
|
||||
let discarded = fb.load(p, MemAccess::default())?;
|
||||
let kept = fb.unary(UnOp::LogicalNot, discarded)?;
|
||||
let arm: ArmFn<'_, ()> = Box::new(move |fb, _| {
|
||||
fb.write(image, at, v, &ops, mem)?;
|
||||
Ok(ArmEnd::FallThrough(Vec::new()))
|
||||
});
|
||||
fb.if_(&mut (), kept, arm, None)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// An upper estimate of the words the shadows add at `rets` returns: the object and its type, and
|
||||
/// at each return the coordinate, a read where the write keeps channels, the guard, and the
|
||||
/// write; and a read per `uses` of a `[[color(n)]]` input.
|
||||
pub(super) fn words(cx: &SelectCx<'_>, uses: u64, rets: u64) -> u64 {
|
||||
const OBJECT: u64 = 40;
|
||||
const READ: u64 = 64;
|
||||
const WRITE: u64 = 96;
|
||||
let shadows = &cx.families.fragment.input_shadows;
|
||||
if shadows.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
let reads = uses.saturating_mul(READ);
|
||||
shadows
|
||||
.values()
|
||||
.map(|s| {
|
||||
let write = match s.stores() {
|
||||
true => (READ + WRITE).saturating_mul(rets.max(1)),
|
||||
false => 0,
|
||||
};
|
||||
OBJECT.saturating_add(write)
|
||||
})
|
||||
.fold(reads, u64::saturating_add)
|
||||
}
|
||||
@@ -63,6 +63,7 @@ mod discard;
|
||||
pub(crate) mod fetch;
|
||||
mod imageblock;
|
||||
mod input_blend;
|
||||
mod input_shadow;
|
||||
mod interpolate;
|
||||
mod rog;
|
||||
mod snapshot;
|
||||
@@ -115,6 +116,8 @@ pub use fetch::{
|
||||
pub use imageblock::{select_output as select_imageblock_output, ImageblockPlan};
|
||||
pub(crate) use input_blend::texel as input_blend_texel;
|
||||
pub use input_blend::{select_second_output as select_input_second_output, InputBlend};
|
||||
pub use input_shadow::InputShadow;
|
||||
pub(crate) use input_shadow::{shadows as input_shadow, store as input_shadow_store};
|
||||
#[cfg(test)]
|
||||
pub(crate) use snapshot::{decode as snapshot_decode, encode as snapshot_encode};
|
||||
pub(crate) use snapshot::{prepare as snapshot_prepare, read as snapshot_read};
|
||||
@@ -208,6 +211,9 @@ pub struct FragmentPlan {
|
||||
/// attachments, on a device that orders fetch through them (`word_input`), by index: the bits
|
||||
/// of the fields each write keeps from the texel.
|
||||
pub word_merges: BTreeMap<u32, u32>,
|
||||
/// The extended-range attachments whose `half` shadow the draw's instance holds, on a device
|
||||
/// that orders fetch through input attachments (`input_shadow`), by index.
|
||||
pub input_shadows: BTreeMap<u32, InputShadow>,
|
||||
/// The stage interface's `FragCoord` object, which gives the pixel of the storage form and
|
||||
/// of the shader-side stencil.
|
||||
pub fetch_coord: Option<usize>,
|
||||
@@ -346,11 +352,16 @@ pub fn finish(cx: &mut SelectCx<'_>, m: &mut Meter) -> Result<(), Error> {
|
||||
imageblock::finish(cx)?;
|
||||
fetch::finish(cx)?;
|
||||
stencil::finish(cx)?;
|
||||
// An imageblock, an attachment in the storage form, and the shadow of a shader-side stencil
|
||||
// are read and written inside the critical section whether or not the function names a
|
||||
// raster order group.
|
||||
// An imageblock, an attachment in the storage form, the shadow of a shader-side stencil and
|
||||
// an extended-range attachment's shadow over its input attachment are read and written inside
|
||||
// the critical section whether or not the function names a raster order group.
|
||||
let shadow = cx.families.fragment.stencil.is_some();
|
||||
let storage = !cx.families.fragment.fetch.is_empty() || shadow;
|
||||
let input_shadows = !cx.families.fragment.input_shadows.is_empty();
|
||||
// A function looping over its covered samples runs no interlocked body (`wrap_entry`).
|
||||
if input_shadows && looped {
|
||||
return Err(Unsupported::not_implemented(Feature::FramebufferFetch).into());
|
||||
}
|
||||
let storage = !cx.families.fragment.fetch.is_empty() || shadow || input_shadows;
|
||||
let interlock =
|
||||
if rog::declared(cx.entry) || cx.families.fragment.imageblock.is_some() || storage {
|
||||
Some(rog::mode(cx)?)
|
||||
@@ -413,6 +424,11 @@ pub fn finish(cx: &mut SelectCx<'_>, m: &mut Meter) -> Result<(), Error> {
|
||||
))
|
||||
.saturating_add(stencil::words(cx, rets))
|
||||
.saturating_add(input_blend::words(cx, returns(cx)))
|
||||
.saturating_add(input_shadow::words(
|
||||
cx,
|
||||
color::uses(cx, &cx.families.fragment.colors),
|
||||
returns(cx),
|
||||
))
|
||||
.saturating_add(word_input::words(cx, returns(cx)))
|
||||
.saturating_add(depth_test::words(cx, rets))
|
||||
.saturating_add(killing_rets.saturating_mul(RETURN_KILL_WORDS))
|
||||
@@ -456,7 +472,8 @@ pub struct Declared {
|
||||
/// The stand-in of the stencil attachment an in-shader stencil test reads and writes.
|
||||
pub stencil_stand_in: Option<GlobalId>,
|
||||
/// The `half` shadow of each extended-range attachment the storage form reads and writes
|
||||
/// against it (`fetch::StorageColor::shadowed`), by color index.
|
||||
/// against it (`fetch::StorageColor::shadowed`), or that a function on a device that fetches
|
||||
/// through input attachments reads and writes beside them (`input_shadow`), by color index.
|
||||
pub extended_shadows: BTreeMap<u32, GlobalId>,
|
||||
/// The `Private u32` holding the sample of the loop's pass over the covered samples.
|
||||
pub loop_sample: Option<GlobalId>,
|
||||
@@ -512,6 +529,10 @@ pub fn declare(
|
||||
.insert(color, fetch::declare_shadow(mb, color, sc.view.samples)?);
|
||||
}
|
||||
}
|
||||
for (&color, shadow) in &fp.input_shadows {
|
||||
d.extended_shadows
|
||||
.insert(color, fetch::declare_shadow(mb, color, shadow.samples)?);
|
||||
}
|
||||
d.imageblock = imageblock::declare(mb, fp.imageblock.as_ref())?;
|
||||
d.shadow_stencil = stencil::declare(mb, fp.stencil.as_ref())?;
|
||||
d.depth_stand_in = depth_test::declare(mb, fp.depth_test.as_ref())?;
|
||||
@@ -618,6 +639,7 @@ pub fn select_param(cx: &mut SelectCx<'_>, b: &ParamBinding) -> Result<(), Error
|
||||
pub fn plan_entry(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
fetch::plan(cx)?;
|
||||
input_blend::plan(cx)?;
|
||||
input_shadow::plan(cx)?;
|
||||
word_input::plan(cx)?;
|
||||
coverage::plan(cx)
|
||||
}
|
||||
|
||||
@@ -2203,6 +2203,14 @@ fn output_part(
|
||||
None => word,
|
||||
}
|
||||
}
|
||||
// The output's `half`, which the instance's shadow of the attachment holds
|
||||
// (`lower::fragment`'s `input_shadow`), and its encode.
|
||||
(None, Some(e)) if crate::lower::fragment::input_shadow(cx, color).is_some() => {
|
||||
let v = extended_color::held(fb, e.form, o.link.form, part)?;
|
||||
crate::lower::fragment::input_shadow_store(cx, fb, color, v)?;
|
||||
let texel = crate::lower::arith::extended_range::encode(fb, e.form, v)?;
|
||||
extended_color::raw_components(fb, e.form, texel)?
|
||||
}
|
||||
(None, Some(e)) => extended_color::encode(fb, e, o.link.form, part)?,
|
||||
(None, None) => color_write::round(cx, fb, color, o.link.form, part)?,
|
||||
},
|
||||
|
||||
@@ -2106,7 +2106,10 @@ pub(crate) fn unattached_colors_written(
|
||||
/// word attachment it writes under a mask of some of the word's channels (whose word the function
|
||||
/// merges into its input attachment's, `color_writes::merged_word`), and of every extended-range
|
||||
/// attachment it writes unblended under a mask of some of the codes one word holds (merged so,
|
||||
/// `color_writes::merged_extended`).
|
||||
/// `color_writes::merged_extended`); and, where `v`'s instance holds extended-range shadows
|
||||
/// (`VariantKey::extended_shadows`), the state of each shadowed attachment the entry reads or
|
||||
/// writes through its first output, with the pass's depth or stencil attachment and alpha to
|
||||
/// coverage, which bear on the shadow the function stores (`lower::fragment`'s `input_shadow`).
|
||||
pub(crate) fn fetch_inputs(
|
||||
spec: &air::Entry,
|
||||
d: FragmentPass<'_>,
|
||||
@@ -2118,6 +2121,9 @@ pub(crate) fn fetch_inputs(
|
||||
if !matches!(spec.ep.stage, AbiStage::Fragment { .. }) || !(interlock || inputs) {
|
||||
return None;
|
||||
}
|
||||
// An extended-range color whose `half` shadow the draw's instance holds, which a function on
|
||||
// a device that fetches through input attachments reads beside it.
|
||||
let shadowed = |color: u32| inputs && v.extended_shadows.contains(&color);
|
||||
let blended = |color: u32| {
|
||||
d.color_attachments
|
||||
.get(color as usize)
|
||||
@@ -2166,7 +2172,7 @@ pub(crate) fn fetch_inputs(
|
||||
ParamRole::ColorInput {
|
||||
index: AbiInt::Const(color),
|
||||
..
|
||||
} if interlock => Some(color),
|
||||
} if interlock || shadowed(color) => Some(color),
|
||||
_ => None,
|
||||
})
|
||||
.chain(spec.ep.outputs.iter().filter_map(|o| match o.role {
|
||||
@@ -2188,12 +2194,13 @@ pub(crate) fn fetch_inputs(
|
||||
..
|
||||
} if interlock && v.interlocked_colors.contains(&color) => Some(color),
|
||||
// An extended-range color whose `half` shadow the draw's instance holds, written
|
||||
// through the storage form against it.
|
||||
// through the storage form against it, or over an input attachment beside its shadow
|
||||
// (`lower::fragment`'s `input_shadow`).
|
||||
OutputRole::RenderTarget {
|
||||
attachment: AbiInt::Const(color),
|
||||
index: 0,
|
||||
..
|
||||
} if interlock && v.extended_shadows.contains(&color) => Some(color),
|
||||
} if v.extended_shadows.contains(&color) => Some(color),
|
||||
_ => None,
|
||||
}))
|
||||
.collect();
|
||||
@@ -2201,7 +2208,9 @@ pub(crate) fn fetch_inputs(
|
||||
return None;
|
||||
}
|
||||
// The blend over an input attachment depends on the attachments' state alone: its write is
|
||||
// the fixed function's, which the tests, coverage and views take as any other's.
|
||||
// the fixed function's, which the tests, coverage and views take as any other's. A shadow
|
||||
// beside it is stored by the function, so the tests and the coverage bear on it.
|
||||
let shadows = inputs && !v.extended_shadows.is_empty();
|
||||
Some(match interlock {
|
||||
true => crate::pipeline::lower_inputs::FramebufferFetchInputs::of(
|
||||
read,
|
||||
@@ -2213,8 +2222,8 @@ pub(crate) fn fetch_inputs(
|
||||
false => crate::pipeline::lower_inputs::FramebufferFetchInputs::of(
|
||||
read,
|
||||
d.color_attachments,
|
||||
false,
|
||||
false,
|
||||
shadows && d.depth_or_stencil,
|
||||
shadows && d.alpha_to_coverage,
|
||||
1,
|
||||
),
|
||||
})
|
||||
|
||||
@@ -684,8 +684,10 @@ pub struct LoweringInputs {
|
||||
/// (`ResourceKind::ExtendedShadow`) as the tile value, and a write stores the value it computes
|
||||
/// there as well as the codes, at the invocation's own sample in a multisampled pipeline. Each
|
||||
/// is an attachment the function writes or reads in the storage form under
|
||||
/// `framebuffer_fetch`; any other is `NotImplemented(FramebufferFetch)`. Empty for any other
|
||||
/// function.
|
||||
/// `framebuffer_fetch`, or on a device that fetches through rasterization-order input
|
||||
/// attachments one it writes through its first output or reads, beside its input attachment
|
||||
/// (`lower::fragment`'s `input_shadow`); any other is `NotImplemented(FramebufferFetch)`.
|
||||
/// Empty for any other function.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub extended_shadows: BTreeSet<u32>,
|
||||
/// Sampled texture slots bound to a texture whose format's numeric class (`Float`, `Sint` or
|
||||
|
||||
Reference in new issue
Block a user