Order a pass's clear before a draw that reads it after a barrier at the pass's start
A pass that clears a color and begins with a memory barrier over the render targets (after the fragment stage, before it) and then samples that color's texture in a draw read the texels from before the pass. Mac2 GPUs read the clear there (an Intel UHD 630 after the barrier, an AMD Radeon Pro 5300M with or without it). The draw reads the texture's copy, taken ahead of the pass's load actions (render/shadows.rs), and a barrier split the pass only where a draw of the current instance came before it, so a barrier at the pass's start split nothing. Such a barrier now orders the pass's load actions (`loads_ordered`): the scope form with the render targets, or the resource form over an attachment's texture, after the fragment stage and before a stage at or before it, recorded before any draw of the pass. A draw after it that samples the texture of a color the pass clears (`Texture::cleared_in`) takes the existing after-barrier path: it records into an instance after the pass's first, which runs the clear and draws nothing (`next_instance` keeps the first instead of replacing it), so the copy before it holds the clear; or, where the device has them, it reads through snapshots inside the first instance. The split is counted as the after-barrier read's (`attachment_read_splits`, `instance_splits_attached_read`) and reloads stand-ins over a buffer's bytes as one after a barrier does. A pass with such a barrier but no such draw records as without it. docs/API.md section 10 gets the accepted difference this ordering is: Apple GPUs do not support the render-target scope, and the M3 Max reads the texels from before the pass after it. The owned fixture psb_reads (regen-air-fixtures) holds the functions the lane and the coming conformance cases draw with: a read and a pixel-coordinate sample of texture 0 at the fragment's own pixel, channels reordered so a read is told from a skipped draw, and two-texture reads. Verified on the M3 Max (MoltenVK, debug, --cfg m2v_gpu), runtime_lane::attachment_reads: - a_draw_after_a_barrier_at_the_pass_start_reads_the_clear: both targets (own image, over a buffer), psb_read and psb_sample, the scope alone, with the textures and the resource form: the clear inside the scissor, one split each (attachment_read_splits 1, instance splits 1, 2 instances begun), own-pixel copies of 308 texels (the 20x12 scissor and a pixel round). - a_draw_after_a_clear_with_no_barrier_reads_the_texels_from_before_the_pass: no split. - a_barrier_at_the_pass_start_costs_nothing_without_a_read_of_a_cleared_color: a loaded target read after the barrier, and a cleared one with a draw reading another texture: no split, as many instances begun and copies taken as with no barrier. Negative control: the same tests on the tree without the runtime change fail at pixel (4, 4), reading [0, 64, 0, 255] (the texel from before the pass, reordered) where the clear's [120, 200, 40, 255] is due. (cherry picked from commit 923095effcd188a93ee5134ecc4dad3fab21b3fe)
This commit is contained in:
1 parent
be72c4bebc
commit
3797c098eb
14 files changed
+937
-45
No files matched your search
@@ -41,12 +41,21 @@
|
||||
//! (buffers or textures, which a fragment may write at any address and a draw may read at any
|
||||
//! stage) splits the pass: the next draw records into a new instance, after a barrier from
|
||||
//! everything before to everything after (`render.rs`, the `render-pass-split` degradation).
|
||||
//! - **Before the pass's first draw**, a barrier over the render targets (or with them, or over
|
||||
//! an attachment's texture), after the fragment stage and before a stage at or before it, orders
|
||||
//! the pass's load actions, which write its render targets ahead of every draw, before the
|
||||
//! draws after it, as Mac2 GPUs answer (measured: an Intel UHD 630 read the clear after one and
|
||||
//! the texels from before the pass without one, an AMD Radeon Pro 5300M the clear either way):
|
||||
//! a draw after it that samples the texture of a color the pass clears records into an instance
|
||||
//! after the pass's first, which runs the clear alone, or reads through snapshots
|
||||
//! (`texture/attached_reads.rs`). A pass with no such draw records as with no barrier.
|
||||
//! - **Barriers over the render targets on Apple GPUs.** The Metal Feature Set Tables give that
|
||||
//! scope to Mac2 GPUs, not to Apple3 to Apple10 ones: on the M3 Max under macOS 27.0.1 (probe
|
||||
//! `rtbarrier`), a draw after one read its own pixel's texels from before the pass, as with no
|
||||
//! barrier, and (probe `rtb`) a draw after one from the fragment stage to the fragment or the
|
||||
//! vertex stage read other pixels' texels from before the pass too, as an Apple GPU orders none
|
||||
//! of them. The runtime orders what each barrier names, as a Mac2 GPU does.
|
||||
//! of them, nor, after one at the pass's start, its clear: the draw read the texels from before
|
||||
//! the pass. The runtime orders what each barrier names, as a Mac2 GPU does.
|
||||
//! - **Barriers after the fragment stage.** On an Apple GPU Metal's validation stops one
|
||||
//! ("afterStages (0x2) can not contain MTLRenderStageTile or MTLRenderStageFragment on this
|
||||
//! device", M4), and Metal without it did not order a fragment's buffer write before the next
|
||||
@@ -297,6 +306,13 @@ const UP_TO_FRAGMENT: RenderStages = RenderStages::VERTEX
|
||||
.union(RenderStages::MESH)
|
||||
.union(RenderStages::FRAGMENT);
|
||||
|
||||
/// Whether a barrier after `after_stages` and before `before_stages` orders the fragment stage's
|
||||
/// writes before the later draws' fragment stages: after the fragment stage, before a stage at or
|
||||
/// before it.
|
||||
fn orders_fragments(after_stages: RenderStages, before_stages: RenderStages) -> bool {
|
||||
after_stages.contains(RenderStages::FRAGMENT) && before_stages.intersects(UP_TO_FRAGMENT)
|
||||
}
|
||||
|
||||
impl RenderLowering {
|
||||
/// The lowering of [`RenderCommandEncoder::update_fence`].
|
||||
pub(crate) fn update_fence(
|
||||
@@ -342,10 +358,14 @@ impl RenderLowering {
|
||||
if scope.is_empty() || after_stages.is_empty() || before_stages.is_empty() {
|
||||
return;
|
||||
}
|
||||
// The pass's load actions write its render targets ahead of its first draw.
|
||||
if scope.contains(BarrierScope::RENDER_TARGETS)
|
||||
&& orders_fragments(after_stages, before_stages)
|
||||
{
|
||||
self.barrier_orders_loads();
|
||||
}
|
||||
if scope == BarrierScope::RENDER_TARGETS {
|
||||
if after_stages.contains(RenderStages::FRAGMENT)
|
||||
&& before_stages.intersects(UP_TO_FRAGMENT)
|
||||
{
|
||||
if orders_fragments(after_stages, before_stages) {
|
||||
self.barrier_between_draws();
|
||||
}
|
||||
return;
|
||||
@@ -368,6 +388,9 @@ impl RenderLowering {
|
||||
self.core().check_device(CALL, resource.device())?;
|
||||
}
|
||||
if !resources.is_empty() && !after_stages.is_empty() && !before_stages.is_empty() {
|
||||
if orders_fragments(after_stages, before_stages) {
|
||||
self.barrier_orders_loads_of(resources);
|
||||
}
|
||||
self.barrier_before_next_draw();
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -131,7 +131,9 @@
|
||||
//! the current one's place when nothing recorded into it and, for the pass's first, every
|
||||
//! attachment it leaves out that Metal clears can be cleared before the pass instead (its
|
||||
//! level and layer is the whole render area, cleared by `vkCmdClearColorImage` with the value
|
||||
//! the load operation would take; Vulkan converts both alike); otherwise the pass splits, and
|
||||
//! the load operation would take; Vulkan converts both alike), and the draw is not one that
|
||||
//! samples a color the pass clears after a memory barrier before its first draw, whose copy
|
||||
//! must follow the clear (`texture/attached_reads.rs`); otherwise the pass splits, and
|
||||
//! the new instance follows the current one after a barrier from everything before to
|
||||
//! everything after. A split pass renders its memoryless attachments into stand-ins
|
||||
//! (`attachment_stand_in.rs`), since its instances keep their contents in memory. A query
|
||||
@@ -328,7 +330,7 @@ use super::residency::Residency;
|
||||
use super::resolve::{
|
||||
self, DepthStencilResolve, Resolve, ResolveCopies, ResolveMode, ResolveSource,
|
||||
};
|
||||
use super::resource::ResourceKey;
|
||||
use super::resource::{ResourceKey, ResourceRef};
|
||||
use super::sample_planes::{self, Planes, PlanesCommands};
|
||||
use super::sample_positions;
|
||||
use super::sampler::OwnedSampler;
|
||||
@@ -1471,6 +1473,12 @@ pub(crate) struct RenderLowering {
|
||||
/// A memory barrier follows draws of the current instance: the next draw records into a new
|
||||
/// instance after a barrier from everything before (`fence.rs`).
|
||||
barrier: bool,
|
||||
/// A memory barrier over the render targets after the fragment stage came before any draw of
|
||||
/// the pass recorded (`fence.rs`): it orders the pass's load actions before the draws after
|
||||
/// it, so a draw that samples a color the pass clears records into an instance after the
|
||||
/// pass's first, which runs them (`texture/attached_reads.rs`), or reads through snapshots
|
||||
/// (`render/snapshot.rs`). The pass's first split takes it.
|
||||
loads_ordered: bool,
|
||||
/// The splits such barriers made, for the split's degrade notice.
|
||||
barrier_splits: usize,
|
||||
/// What MoltenVK restarts its Metal render pass for inside the subpass, storing the
|
||||
@@ -2077,6 +2085,7 @@ impl RenderLowering {
|
||||
rate_map,
|
||||
amplification: Versioned::new(Amplification::default()),
|
||||
barrier: false,
|
||||
loads_ordered: false,
|
||||
barrier_splits: 0,
|
||||
driver_restarts: false,
|
||||
tile_memory_splits: 0,
|
||||
@@ -3955,7 +3964,7 @@ impl RenderLowering {
|
||||
(&[], None),
|
||||
(false, false),
|
||||
ViewSetup::default(),
|
||||
false,
|
||||
(false, false),
|
||||
None,
|
||||
&[],
|
||||
&[],
|
||||
@@ -6375,7 +6384,10 @@ impl RenderLowering {
|
||||
/// layers `views` records, and the pass's layout from it on where stand-ins or sample planes
|
||||
/// arrive with it (the module docs, `attachment_stand_in.rs` and `sample_planes.rs`); a draw
|
||||
/// `ordered` after the current instance's draws (`render/tile_memory.rs`) records into a new
|
||||
/// one. Refused (`NotImplemented(Render)`) where a fetched texture's scratch cannot be
|
||||
/// one, and one ordered after the pass's load actions alone (`behind_loads`: a draw that
|
||||
/// samples a color the pass clears, after a memory barrier before its first draw,
|
||||
/// `texture/attached_reads.rs`) into one after the pass's first, which runs them with no
|
||||
/// draw. Refused (`NotImplemented(Render)`) where a fetched texture's scratch cannot be
|
||||
/// copied, and (`Unsupported`) where the device cannot run the sample planes' copies.
|
||||
/// `by`: the state of the draw that fetches them, which a scratch's notice names.
|
||||
fn next_instance(
|
||||
@@ -6383,7 +6395,7 @@ impl RenderLowering {
|
||||
(fetched, by): (&[u32], Option<&DrawingState>),
|
||||
(shadow, shader_tests): (bool, bool),
|
||||
views: ViewSetup,
|
||||
ordered: bool,
|
||||
(ordered, behind_loads): (bool, bool),
|
||||
hidden: Option<Target>,
|
||||
locations: &[Option<u32>],
|
||||
reformats: &[Reformat],
|
||||
@@ -6564,12 +6576,13 @@ impl RenderLowering {
|
||||
.and_then(Option::as_ref)
|
||||
.is_some_and(|color| color.load == LoadAction::Clear)
|
||||
});
|
||||
// An instance a tile dispatch follows runs before it, recorded or not.
|
||||
// An instance a tile dispatch follows runs before it, recorded or not, and so does the
|
||||
// pass's first ahead of a draw ordered after its load actions.
|
||||
// An instance that records the current one's draws again takes its place as an empty
|
||||
// one's would (`render/reroute.rs`).
|
||||
let replace = !self.dispatched
|
||||
&& (!self.current.recorded || self.rerouting)
|
||||
&& (!first || (ahead && loads && !viewed_clears));
|
||||
&& (!first || (ahead && loads && !viewed_clears && !behind_loads));
|
||||
let split = !replace;
|
||||
if split {
|
||||
// A split pass keeps its memoryless attachments in memory between its instances.
|
||||
@@ -6834,9 +6847,12 @@ impl RenderLowering {
|
||||
let previous = std::mem::replace(&mut self.current, *instance);
|
||||
self.earlier.push(previous);
|
||||
self.barrier_splits += usize::from(self.barrier);
|
||||
if self.barrier {
|
||||
// The instance after the one that ran the pass's load actions behind a barrier
|
||||
// before its first draw follows that barrier too.
|
||||
if self.barrier || self.loads_ordered {
|
||||
self.reload_at.insert(self.earlier.len());
|
||||
}
|
||||
self.loads_ordered = false;
|
||||
} else {
|
||||
// It takes the place of the current one, whose draws it records again.
|
||||
let mut instance = *instance;
|
||||
@@ -6923,6 +6939,29 @@ impl RenderLowering {
|
||||
unsafe { render_target::between_draws(raw, self.current.draws, view_mask) };
|
||||
}
|
||||
|
||||
/// Order the pass's load actions before the draws after a memory barrier over the render
|
||||
/// targets after the fragment stage (`fence.rs`), where it comes before any draw of the pass
|
||||
/// recorded (`loads_ordered`). Past one, the draws before it order themselves
|
||||
/// (`barrier_between_draws`), and an instance after the pass's first follows its load
|
||||
/// actions already.
|
||||
pub(super) fn barrier_orders_loads(&mut self) {
|
||||
if self.earlier.is_empty() && !self.current.recorded {
|
||||
self.loads_ordered = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// [`barrier_orders_loads`](Self::barrier_orders_loads) for a memory barrier over
|
||||
/// `resources`, where one of them is a texture a color attachment of the pass renders.
|
||||
pub(super) fn barrier_orders_loads_of(&mut self, resources: &[ResourceRef<'_>]) {
|
||||
let attached = resources.iter().any(|resource| match resource {
|
||||
ResourceRef::Texture(texture) => texture.attached_in(&self.layout),
|
||||
_ => false,
|
||||
});
|
||||
if attached {
|
||||
self.barrier_orders_loads();
|
||||
}
|
||||
}
|
||||
|
||||
/// Bound the copy in of each shadow among `shadows` of a texture that presents a color
|
||||
/// attachment of the pass and that a draw of `plan` reads at its fragments' own pixels alone
|
||||
/// (`texture/attached_reads.rs`): every binding of the texture in its tables is a sampled one
|
||||
@@ -7028,9 +7067,14 @@ impl RenderLowering {
|
||||
}
|
||||
|
||||
/// Whether a draw of `plan` samples, at a slot of its tables, a texture that presents a color
|
||||
/// attachment of the pass (`texture/attached_reads.rs`): a sampled image or combined image
|
||||
/// sampler binding, not a storage one.
|
||||
fn samples_attachment(&self, plan: &BindingPlan) -> bool {
|
||||
/// attachment of the pass (`texture/attached_reads.rs`) as `presents` tells
|
||||
/// (`Texture::attached_in`, or `Texture::cleared_in` for one the pass clears): a sampled image
|
||||
/// or combined image sampler binding, not a storage one.
|
||||
fn samples_attachment(
|
||||
&self,
|
||||
plan: &BindingPlan,
|
||||
presents: fn(&Texture, &PassLayout) -> bool,
|
||||
) -> bool {
|
||||
plan.descriptors.iter().any(|write| {
|
||||
let slot = match &write.source {
|
||||
WriteSource::Texture { slot, .. } => slot,
|
||||
@@ -7051,7 +7095,7 @@ impl RenderLowering {
|
||||
&& table
|
||||
.textures
|
||||
.get(&slot.index)
|
||||
.is_some_and(|texture| texture.attached_in(&self.layout))
|
||||
.is_some_and(|texture| presents(texture, &self.layout))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7091,7 +7135,7 @@ impl RenderLowering {
|
||||
(&[], None),
|
||||
(false, false),
|
||||
ViewSetup::default(),
|
||||
false,
|
||||
(false, false),
|
||||
None,
|
||||
&[],
|
||||
&[],
|
||||
@@ -8407,8 +8451,16 @@ impl RenderLowering {
|
||||
// has begun its render pass instance with no color in the feedback loop layout, so the
|
||||
// draw records into a new one (`render/snapshot.rs`). So does a draw that binds a texture
|
||||
// the current instance holds in that layout as a storage image.
|
||||
let attached = !self.replaying && snapshot.is_none() && self.samples_attachment(&plan);
|
||||
let after_barrier = attached && (self.current.barriers || self.barrier);
|
||||
// After a memory barrier before the pass's first draw, one that samples a color the pass
|
||||
// clears records into an instance after the pass's first, which runs the clear, so its
|
||||
// copy holds it (`texture/attached_reads.rs`): the pass's load actions are behind the
|
||||
// barrier.
|
||||
let attached = !self.replaying
|
||||
&& snapshot.is_none()
|
||||
&& self.samples_attachment(&plan, Texture::attached_in);
|
||||
let behind_loads =
|
||||
attached && self.loads_ordered && self.samples_attachment(&plan, Texture::cleared_in);
|
||||
let after_barrier = (attached && (self.current.barriers || self.barrier)) || behind_loads;
|
||||
let snapshot_split = snapshot.as_ref().is_some_and(|w| self.snapshot_apart(w));
|
||||
let storage_colors = self.storage_colors(&plan);
|
||||
let apart = snapshot_split || storage_colors & self.current.feedback.0 != 0;
|
||||
@@ -8424,7 +8476,10 @@ impl RenderLowering {
|
||||
(&fetched, Some(&pipeline)),
|
||||
(stencil_use.is_some(), tests_use.is_some()),
|
||||
views,
|
||||
(ordered || after_barrier || apart || first_write) && !self.replaying,
|
||||
(
|
||||
(ordered || after_barrier || apart || first_write) && !self.replaying,
|
||||
behind_loads,
|
||||
),
|
||||
hidden,
|
||||
&routing.locations,
|
||||
&reformats,
|
||||
@@ -9674,7 +9729,7 @@ impl RenderLowering {
|
||||
(&fetched, Some(&pipeline)),
|
||||
(stencil_use.is_some(), tests_use.is_some()),
|
||||
views,
|
||||
true,
|
||||
(true, false),
|
||||
None,
|
||||
&routing.locations,
|
||||
&reformats,
|
||||
|
||||
@@ -58,6 +58,7 @@ use crate::error::Error;
|
||||
use crate::live_bind::{LiveBind, Reshape};
|
||||
use crate::pipeline::{RenderStateKind, Settled};
|
||||
use crate::render::{Assembly, Bound, DrawBuffers, DrawState, Recording};
|
||||
use crate::texture::Texture;
|
||||
|
||||
/// The most slots a draw rebound takes changed: a draw after more takes every step.
|
||||
const SLOTS: usize = 8;
|
||||
@@ -364,7 +365,7 @@ impl RenderLowering {
|
||||
// texture is bound through a shadow (`LiveBind`'s state), as for the kept draw.
|
||||
let images = changed.images();
|
||||
if images
|
||||
&& (self.samples_attachment(plan)
|
||||
&& (self.samples_attachment(plan, Texture::attached_in)
|
||||
|| self.storage_colors(plan) != 0
|
||||
|| !live.state.extended_shadows.is_empty())
|
||||
{
|
||||
|
||||
@@ -617,7 +617,7 @@ impl RenderLowering {
|
||||
(&[], None),
|
||||
(false, false),
|
||||
ViewSetup::default(),
|
||||
apart,
|
||||
(apart, false),
|
||||
hidden,
|
||||
&[],
|
||||
&[],
|
||||
@@ -2475,6 +2475,7 @@ impl RenderExecution {
|
||||
rate_map: snapshot.rate_map.clone(),
|
||||
amplification: Versioned::new(snapshot.amplification.clone()),
|
||||
barrier: false,
|
||||
loads_ordered: false,
|
||||
barrier_splits: 0,
|
||||
driver_restarts: false,
|
||||
tile_memory_splits: 0,
|
||||
|
||||
@@ -156,7 +156,7 @@ impl RenderLowering {
|
||||
(&colors, Some(by)),
|
||||
(false, false),
|
||||
ViewSetup::default(),
|
||||
true,
|
||||
(true, false),
|
||||
None,
|
||||
&locations,
|
||||
&[],
|
||||
|
||||
@@ -257,7 +257,12 @@ impl RenderLowering {
|
||||
pipeline: &DrawingState,
|
||||
reformats: &[Reformat],
|
||||
) -> Option<Wanted> {
|
||||
if self.replaying || self.rerouting || !(self.current.barriers || self.barrier) {
|
||||
// After a barrier before the pass's first draw alone (`loads_ordered`), a slot reads
|
||||
// through a snapshot only where its texture's color is one the pass clears: one the pass
|
||||
// loads holds the texels from before the pass, which its copy holds
|
||||
// (`texture/attached_reads.rs`).
|
||||
let ordered = self.current.barriers || self.barrier;
|
||||
if self.replaying || self.rerouting || !(ordered || self.loads_ordered) {
|
||||
return None;
|
||||
}
|
||||
let base = pipeline.base();
|
||||
@@ -270,7 +275,8 @@ impl RenderLowering {
|
||||
let Some(texture) = self.fragment.textures.get(&slot) else {
|
||||
continue;
|
||||
};
|
||||
if !texture.attached_in(&self.layout) {
|
||||
if !texture.attached_in(&self.layout) || !(ordered || texture.cleared_in(&self.layout))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let Some(index) = texture.snapshot_color(&self.layout) else {
|
||||
|
||||
@@ -33,6 +33,15 @@
|
||||
//! a new instance (`render.rs`, `WorkCounts::attachment_read_splits`), before which the copy
|
||||
//! is taken: it holds every texel the draws before the barrier wrote, and those of the draws
|
||||
//! between the barrier and it, which Metal does not order before it.
|
||||
//! - **After a memory barrier before the pass's first draw.** Such a barrier orders the pass's
|
||||
//! load actions before the draws after it (`fence.rs`): a draw after it that samples the
|
||||
//! texture of a color the pass clears ([`Texture::cleared_in`]) reads the clear on a Mac2 GPU,
|
||||
//! where the copy taken ahead of the pass's load actions holds the texels from before the pass.
|
||||
//! It records into an instance after the pass's first, which runs the pass's load actions and
|
||||
//! draws nothing where no draw came before (`render.rs`, `WorkCounts::attachment_read_splits`),
|
||||
//! before which the copy is taken, or reads through snapshots inside its instance (below). A
|
||||
//! draw that samples a color the pass loads, or none, records as with no barrier: the copy
|
||||
//! ahead of the load holds what it loads.
|
||||
//! - **The copy** is the texture's shadow, an image of its own, whose truth is the texture's
|
||||
//! image or its buffer's bytes. The pass's shadow plan (`render/shadows.rs`) copies the truth
|
||||
//! in before each instance whose draws read the shadow, after the instances before it wrote
|
||||
@@ -102,7 +111,8 @@ use crate::binding_view::VkView;
|
||||
use crate::command_buffer::CommandBuffer;
|
||||
use crate::error::Error;
|
||||
use crate::image_plan::ImagePlan;
|
||||
use crate::render_pass::PassLayout;
|
||||
use crate::render_pass::{ColorTarget, PassLayout};
|
||||
use crate::render_values::LoadAction;
|
||||
use crate::texture_descriptor::TextureDescriptor;
|
||||
use crate::tracker::{Access, Use};
|
||||
use crate::values::ResourceOptions;
|
||||
@@ -151,6 +161,20 @@ impl Texture {
|
||||
/// instance renders: the same image, and an overlapping level and layer (every layer of a 3D
|
||||
/// image, which has one, its depth planes the attachment's layers).
|
||||
pub(crate) fn attached_in(&self, layout: &PassLayout) -> bool {
|
||||
self.attached_where(layout, |_| true)
|
||||
}
|
||||
|
||||
/// Whether the texture presents a level and layer that a color attachment of `layout`'s
|
||||
/// instance whose load action clears it renders, as [`attached_in`](Self::attached_in) tells:
|
||||
/// what a draw after a memory barrier before the pass's first draw reads of it is the clear
|
||||
/// (the module docs).
|
||||
pub(crate) fn cleared_in(&self, layout: &PassLayout) -> bool {
|
||||
self.attached_where(layout, |color| color.load == LoadAction::Clear)
|
||||
}
|
||||
|
||||
/// [`attached_in`](Self::attached_in) of the color attachments of `layout` that `keep`
|
||||
/// keeps.
|
||||
fn attached_where(&self, layout: &PassLayout, keep: impl Fn(&ColorTarget) -> bool) -> bool {
|
||||
let Ok(image) = self.image() else {
|
||||
return false;
|
||||
};
|
||||
@@ -158,16 +182,21 @@ impl Texture {
|
||||
let levels = record.base_level..record.base_level + record.level_count;
|
||||
let layers = record.base_layer..record.base_layer + record.layer_count;
|
||||
let volume = image.plan().image_type == ImageType::TYPE_3D;
|
||||
layout.colors.iter().flatten().any(|color| {
|
||||
let target = &color.target;
|
||||
let same = target
|
||||
.texture
|
||||
.image()
|
||||
.is_ok_and(|other| other.identity.key == image.identity.key);
|
||||
let rendered = target.layer..target.layer + target.layers;
|
||||
same && levels.contains(&target.level)
|
||||
&& (volume || (rendered.start < layers.end && layers.start < rendered.end))
|
||||
})
|
||||
layout
|
||||
.colors
|
||||
.iter()
|
||||
.flatten()
|
||||
.filter(|c| keep(c))
|
||||
.any(|color| {
|
||||
let target = &color.target;
|
||||
let same = target
|
||||
.texture
|
||||
.image()
|
||||
.is_ok_and(|other| other.identity.key == image.identity.key);
|
||||
let rendered = target.layer..target.layer + target.layers;
|
||||
same && levels.contains(&target.level)
|
||||
&& (volume || (rendered.start < layers.end && layers.start < rendered.end))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -583,8 +583,8 @@ pub(crate) enum Split {
|
||||
/// A draw ordered after draws of the instance that reached the tile threadgroup memory
|
||||
/// (`render/tile_memory.rs`).
|
||||
TileMemory,
|
||||
/// A draw that samples a color attachment's texture after a barrier inside the instance
|
||||
/// (`texture/attached_reads.rs`).
|
||||
/// A draw that samples a color attachment's texture after a barrier inside the instance, or a
|
||||
/// color the pass clears after a barrier before its first draw (`texture/attached_reads.rs`).
|
||||
AttachedRead,
|
||||
/// A draw that reads through snapshots apart from the instance, or binds a color the instance
|
||||
/// holds in the feedback loop layout (`render/snapshot.rs`).
|
||||
@@ -4511,14 +4511,16 @@ pub struct WorkCounts {
|
||||
/// Instances of no draws that resolve a pass after its last (`render/pass_steps.rs`).
|
||||
pub render_passes_begun_resolves: u64,
|
||||
/// Splits of render encoders' passes, each a new render pass instance after one that
|
||||
/// recorded (`render.rs`, **Instances**), at a memory barrier of the program's (`fence.rs`).
|
||||
/// recorded, or that runs the pass's load actions alone (`render.rs`, **Instances**), at a
|
||||
/// memory barrier of the program's (`fence.rs`).
|
||||
/// With the nine fields after this one, every split, by its first cause in this order.
|
||||
pub instance_splits_barrier: u64,
|
||||
/// At a tile dispatch, or for the store actions after the pass's last one.
|
||||
pub instance_splits_tile_dispatch: u64,
|
||||
/// At a draw ordered after draws that reached the tile threadgroup memory.
|
||||
pub instance_splits_tile_memory: u64,
|
||||
/// At a draw that samples a color attachment's texture after a barrier inside the instance.
|
||||
/// At a draw that samples a color attachment's texture after a barrier inside the instance,
|
||||
/// or a color the pass clears after a barrier before its first draw.
|
||||
pub instance_splits_attached_read: u64,
|
||||
/// At a draw that reads through snapshots apart, or binds a color held in the feedback loop
|
||||
/// layout.
|
||||
@@ -5669,7 +5671,9 @@ pub struct WorkCounts {
|
||||
pub attachment_reads_through_copies: u64,
|
||||
/// Draws that sample a color attachment's texture after a memory barrier of their render
|
||||
/// pass, each recorded into a new instance (a barrier inside an instance orders one pixel
|
||||
/// alone), whose copy holds what the draws before the barrier wrote
|
||||
/// alone), whose copy holds what the draws before the barrier wrote; and those that sample a
|
||||
/// color the pass clears after a barrier before its first draw, each recorded into an
|
||||
/// instance after the pass's first, which runs the clear, whose copy holds it
|
||||
/// (`texture/attached_reads.rs`).
|
||||
pub attachment_read_splits: u64,
|
||||
/// Draws that sample a color attachment's texture after a memory barrier of their render
|
||||
|
||||
@@ -237,6 +237,7 @@ fixture ob3_vertex_input: metal: Apple metal version 32023.921 (metalfe-32023.92
|
||||
fixture pdc_compare_clamp: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
|
||||
fixture pdc_post_depth_coverage: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
|
||||
fixture primitive_ids: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
|
||||
fixture psb_reads: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
|
||||
fixture psc_sample_coverage: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
|
||||
fixture pull_model_interpolants: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
|
||||
fixture px_edges: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
; Generated by scripts/regen-air-fixtures from psb_reads.metal (typed pointers; xcrun metal-as reassembles it). Do not edit.
|
||||
; ModuleID = '-'
|
||||
source_filename = "-"
|
||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
|
||||
target triple = "air64_v28-apple-macosx26.0.0"
|
||||
|
||||
%struct._texture_2d_t = type opaque
|
||||
%struct._sampler_t = type opaque
|
||||
|
||||
@__air_sampler_state = internal addrspace(2) constant [2 x i64] [i64 34901797601050697, i64 0], align 8
|
||||
|
||||
; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn
|
||||
define <{ <4 x float> }> @psb_rect(i32 noundef %0, <4 x float> addrspace(2)* nocapture noundef readonly align 16 dereferenceable(16) "air-buffer-no-alias" %1) local_unnamed_addr #0 {
|
||||
%3 = and i32 %0, -3
|
||||
%4 = icmp eq i32 %3, 1
|
||||
%5 = icmp eq i32 %0, 4
|
||||
%6 = or i1 %5, %4
|
||||
%7 = select i1 %6, float 1.000000e+00, float 0.000000e+00
|
||||
%8 = icmp eq i32 %0, 2
|
||||
%9 = and i32 %0, -2
|
||||
%10 = icmp eq i32 %9, 4
|
||||
%11 = or i1 %8, %10
|
||||
%12 = select i1 %11, float 1.000000e+00, float 0.000000e+00
|
||||
%13 = load <4 x float>, <4 x float> addrspace(2)* %1, align 16, !alias.scope !39
|
||||
%14 = shufflevector <4 x float> %13, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%15 = shufflevector <4 x float> %13, <4 x float> poison, <2 x i32> <i32 2, i32 3>
|
||||
%16 = insertelement <2 x float> undef, float %7, i64 0
|
||||
%17 = insertelement <2 x float> %16, float %12, i64 1
|
||||
%18 = tail call fast <2 x float> @air.mix.v2f32(<2 x float> %14, <2 x float> %15, <2 x float> %17) #8
|
||||
%19 = shufflevector <2 x float> %18, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
|
||||
%20 = shufflevector <4 x float> %19, <4 x float> <float poison, float poison, float 0.000000e+00, float 1.000000e+00>, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
|
||||
%21 = insertvalue <{ <4 x float> }> undef, <4 x float> %20, 0
|
||||
ret <{ <4 x float> }> %21
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone willreturn
|
||||
define <4 x float> @psb_solid(<4 x float> %0, <4 x float> addrspace(2)* nocapture noundef readonly align 16 dereferenceable(16) "air-buffer-no-alias" %1) local_unnamed_addr #1 {
|
||||
%3 = load <4 x float>, <4 x float> addrspace(2)* %1, align 16, !tbaa !42, !alias.scope !45
|
||||
ret <4 x float> %3
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind readonly willreturn
|
||||
define <4 x float> @psb_read(<4 x float> %0, %struct._texture_2d_t addrspace(1)* nocapture readonly %1) local_unnamed_addr #2 {
|
||||
%3 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%4 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %3) #8
|
||||
%5 = tail call %struct._sampler_t addrspace(2)* @air.get_read_sampler() #9
|
||||
%6 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %1, %struct._sampler_t addrspace(2)* %5, <2 x i32> %4, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%7 = extractvalue { <4 x float>, i8 } %6, 0
|
||||
%8 = shufflevector <4 x float> <float poison, float poison, float poison, float 1.000000e+00>, <4 x float> %7, <4 x i32> <i32 6, i32 4, i32 5, i32 3>
|
||||
ret <4 x float> %8
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn
|
||||
declare <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float>) local_unnamed_addr #3
|
||||
|
||||
; Function Attrs: argmemonly convergent mustprogress nofree nounwind readonly willreturn
|
||||
define <4 x float> @psb_sample(<4 x float> %0, %struct._texture_2d_t addrspace(1)* nocapture readonly %1) local_unnamed_addr #4 {
|
||||
%3 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%4 = tail call { <4 x float>, i8 } @air.sample_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %1, %struct._sampler_t addrspace(2)* nocapture readonly bitcast ([2 x i64] addrspace(2)* @__air_sampler_state to %struct._sampler_t addrspace(2)*), <2 x float> %3, i1 true, <2 x i32> zeroinitializer, i1 false, float 0.000000e+00, float 0.000000e+00, i32 0) #11
|
||||
%5 = extractvalue { <4 x float>, i8 } %4, 0
|
||||
%6 = shufflevector <4 x float> <float poison, float poison, float poison, float 1.000000e+00>, <4 x float> %5, <4 x i32> <i32 6, i32 4, i32 5, i32 3>
|
||||
ret <4 x float> %6
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind readonly willreturn
|
||||
define <4 x float> @psb_masked(<4 x float> %0, %struct._texture_2d_t addrspace(1)* nocapture readonly %1, %struct._texture_2d_t addrspace(1)* %2) local_unnamed_addr #2 {
|
||||
%4 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%5 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %4) #8
|
||||
%6 = tail call %struct._sampler_t addrspace(2)* @air.get_read_sampler() #9
|
||||
%7 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %1, %struct._sampler_t addrspace(2)* %6, <2 x i32> %5, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%8 = extractvalue { <4 x float>, i8 } %7, 0
|
||||
%9 = extractelement <2 x i32> %5, i64 0
|
||||
%10 = tail call i32 @air.get_width_texture_2d(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, i32 0) #10, !alias.scope !48
|
||||
%11 = urem i32 %9, %10
|
||||
%12 = insertelement <2 x i32> undef, i32 %11, i64 0
|
||||
%13 = extractelement <2 x i32> %5, i64 1
|
||||
%14 = tail call i32 @air.get_height_texture_2d(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, i32 0) #10, !alias.scope !48
|
||||
%15 = urem i32 %13, %14
|
||||
%16 = insertelement <2 x i32> %12, i32 %15, i64 1
|
||||
%17 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, %struct._sampler_t addrspace(2)* %6, <2 x i32> %16, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%18 = extractvalue { <4 x float>, i8 } %17, 0
|
||||
%19 = shufflevector <4 x float> %8, <4 x float> %18, <4 x i32> <i32 2, i32 0, i32 1, i32 7>
|
||||
ret <4 x float> %19
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind readonly willreturn
|
||||
define <4 x float> @psb_under(<4 x float> %0, %struct._texture_2d_t addrspace(1)* nocapture readonly %1, %struct._texture_2d_t addrspace(1)* %2) local_unnamed_addr #2 {
|
||||
%4 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%5 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %4) #8
|
||||
%6 = tail call %struct._sampler_t addrspace(2)* @air.get_read_sampler() #9
|
||||
%7 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %1, %struct._sampler_t addrspace(2)* %6, <2 x i32> %5, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%8 = extractvalue { <4 x float>, i8 } %7, 0
|
||||
%9 = extractelement <2 x i32> %5, i64 0
|
||||
%10 = tail call i32 @air.get_width_texture_2d(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, i32 0) #10, !alias.scope !51
|
||||
%11 = urem i32 %9, %10
|
||||
%12 = insertelement <2 x i32> undef, i32 %11, i64 0
|
||||
%13 = extractelement <2 x i32> %5, i64 1
|
||||
%14 = tail call i32 @air.get_height_texture_2d(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, i32 0) #10, !alias.scope !51
|
||||
%15 = urem i32 %13, %14
|
||||
%16 = insertelement <2 x i32> %12, i32 %15, i64 1
|
||||
%17 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly %2, %struct._sampler_t addrspace(2)* %6, <2 x i32> %16, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%18 = extractvalue { <4 x float>, i8 } %17, 0
|
||||
%19 = shufflevector <4 x float> %18, <4 x float> %8, <4 x i32> <i32 2, i32 0, i32 1, i32 7>
|
||||
ret <4 x float> %19
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn
|
||||
declare <2 x float> @air.mix.v2f32(<2 x float>, <2 x float>, <2 x float>) local_unnamed_addr #3
|
||||
|
||||
; Function Attrs: inaccessiblememonly mustprogress nofree nounwind readonly willreturn
|
||||
declare %struct._sampler_t addrspace(2)* @air.get_read_sampler() local_unnamed_addr #5
|
||||
|
||||
; Function Attrs: argmemonly mustprogress nofree nounwind readonly willreturn
|
||||
declare { <4 x float>, i8 } @air.read_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly, %struct._sampler_t addrspace(2)*, <2 x i32>, <2 x i32>, i32, i32) local_unnamed_addr #6
|
||||
|
||||
; Function Attrs: argmemonly convergent mustprogress nofree nounwind readonly willreturn
|
||||
declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(%struct._texture_2d_t addrspace(1)* nocapture readonly, %struct._sampler_t addrspace(2)* nocapture readonly, <2 x float>, i1, <2 x i32>, i1, float, float, i32) local_unnamed_addr #7
|
||||
|
||||
; Function Attrs: argmemonly mustprogress nofree nounwind readonly willreturn
|
||||
declare i32 @air.get_width_texture_2d(%struct._texture_2d_t addrspace(1)* nocapture readonly, i32) local_unnamed_addr #6
|
||||
|
||||
; Function Attrs: argmemonly mustprogress nofree nounwind readonly willreturn
|
||||
declare i32 @air.get_height_texture_2d(%struct._texture_2d_t addrspace(1)* nocapture readonly, i32) local_unnamed_addr #6
|
||||
|
||||
attributes #0 = { mustprogress nofree nosync nounwind readnone willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="64" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
|
||||
attributes #1 = { mustprogress nofree norecurse nosync nounwind readnone willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
|
||||
attributes #2 = { mustprogress nofree nounwind readonly willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
|
||||
attributes #3 = { mustprogress nofree nosync nounwind readnone willreturn }
|
||||
attributes #4 = { argmemonly convergent mustprogress nofree nounwind readonly willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
|
||||
attributes #5 = { inaccessiblememonly mustprogress nofree nounwind readonly willreturn }
|
||||
attributes #6 = { argmemonly mustprogress nofree nounwind readonly willreturn }
|
||||
attributes #7 = { argmemonly convergent mustprogress nofree nounwind readonly willreturn }
|
||||
attributes #8 = { nounwind readnone willreturn }
|
||||
attributes #9 = { inaccessiblememonly nounwind readonly willreturn }
|
||||
attributes #10 = { argmemonly nounwind readonly willreturn }
|
||||
attributes #11 = { argmemonly convergent nounwind readonly willreturn }
|
||||
|
||||
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
|
||||
!air.vertex = !{!9}
|
||||
!air.fragment = !{!15, !21, !25, !28, !31}
|
||||
!air.compile_options = !{!32, !33, !34}
|
||||
!air.sampler_states = !{!35}
|
||||
!llvm.ident = !{!36}
|
||||
!air.version = !{!37}
|
||||
!air.language_version = !{!38}
|
||||
|
||||
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]}
|
||||
!1 = !{i32 1, !"wchar_size", i32 4}
|
||||
!2 = !{i32 7, !"frame-pointer", i32 2}
|
||||
!3 = !{i32 7, !"air.max_device_buffers", i32 31}
|
||||
!4 = !{i32 7, !"air.max_constant_buffers", i32 31}
|
||||
!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31}
|
||||
!6 = !{i32 7, !"air.max_textures", i32 128}
|
||||
!7 = !{i32 7, !"air.max_read_write_textures", i32 8}
|
||||
!8 = !{i32 7, !"air.max_samplers", i32 16}
|
||||
!9 = !{<{ <4 x float> }> (i32, <4 x float> addrspace(2)*)* @psb_rect, !10, !12}
|
||||
!10 = !{!11}
|
||||
!11 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
|
||||
!12 = !{!13, !14}
|
||||
!13 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"}
|
||||
!14 = !{i32 1, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"r"}
|
||||
!15 = !{<4 x float> (<4 x float>, <4 x float> addrspace(2)*)* @psb_solid, !16, !18}
|
||||
!16 = !{!17}
|
||||
!17 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"}
|
||||
!18 = !{!19, !20}
|
||||
!19 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"}
|
||||
!20 = !{i32 1, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"c"}
|
||||
!21 = !{<4 x float> (<4 x float>, %struct._texture_2d_t addrspace(1)*)* @psb_read, !16, !22}
|
||||
!22 = !{!23, !24}
|
||||
!23 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
|
||||
!24 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.read", !"air.arg_type_name", !"texture2d<float, read>", !"air.arg_name", !"t"}
|
||||
!25 = !{<4 x float> (<4 x float>, %struct._texture_2d_t addrspace(1)*)* @psb_sample, !16, !26}
|
||||
!26 = !{!23, !27}
|
||||
!27 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.sample", !"air.arg_type_name", !"texture2d<float, sample>", !"air.arg_name", !"t"}
|
||||
!28 = !{<4 x float> (<4 x float>, %struct._texture_2d_t addrspace(1)*, %struct._texture_2d_t addrspace(1)*)* @psb_masked, !16, !29}
|
||||
!29 = !{!23, !24, !30}
|
||||
!30 = !{i32 2, !"air.texture", !"air.location_index", i32 3, i32 1, !"air.read", !"air.arg_type_name", !"texture2d<float, read>", !"air.arg_name", !"m"}
|
||||
!31 = !{<4 x float> (<4 x float>, %struct._texture_2d_t addrspace(1)*, %struct._texture_2d_t addrspace(1)*)* @psb_under, !16, !29}
|
||||
!32 = !{!"air.compile.denorms_disable"}
|
||||
!33 = !{!"air.compile.fast_math_enable"}
|
||||
!34 = !{!"air.compile.framebuffer_fetch_enable"}
|
||||
!35 = !{!"air.sampler_state", [2 x i64] addrspace(2)* @__air_sampler_state}
|
||||
!36 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"}
|
||||
!37 = !{i32 2, i32 8, i32 0}
|
||||
!38 = !{!"Metal", i32 4, i32 0, i32 0}
|
||||
!39 = !{!40}
|
||||
!40 = distinct !{!40, !41, !"air-alias-scope-arg(1)"}
|
||||
!41 = distinct !{!41, !"air-alias-scopes(psb_rect)"}
|
||||
!42 = !{!43, !43, i64 0}
|
||||
!43 = !{!"omnipotent char", !44, i64 0}
|
||||
!44 = !{!"Simple C++ TBAA"}
|
||||
!45 = !{!46}
|
||||
!46 = distinct !{!46, !47, !"air-alias-scope-arg(1)"}
|
||||
!47 = distinct !{!47, !"air-alias-scopes(psb_solid)"}
|
||||
!48 = !{!49}
|
||||
!49 = distinct !{!49, !50, !"air-alias-scope-textures"}
|
||||
!50 = distinct !{!50, !"air-alias-scopes(psb_masked)"}
|
||||
!51 = !{!52}
|
||||
!52 = distinct !{!52, !53, !"air-alias-scope-textures"}
|
||||
!53 = distinct !{!53, !"air-alias-scopes(psb_under)"}
|
||||
@@ -0,0 +1,197 @@
|
||||
; Generated by scripts/regen-air-fixtures from psb_reads.metal (llvm-dis of psb_reads.air). Do not edit.
|
||||
; ModuleID = '<stdin>'
|
||||
source_filename = "-"
|
||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
|
||||
target triple = "air64_v28-apple-macosx26.0.0"
|
||||
|
||||
@__air_sampler_state = internal addrspace(2) constant [2 x i64] [i64 34901797601050697, i64 0], align 8
|
||||
|
||||
; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
|
||||
define <{ <4 x float> }> @psb_rect(i32 noundef %0, ptr addrspace(2) noundef readonly align 16 captures(none) dereferenceable(16) "air-buffer-no-alias" %1) local_unnamed_addr #0 {
|
||||
%3 = and i32 %0, -3
|
||||
%4 = icmp eq i32 %3, 1
|
||||
%5 = icmp eq i32 %0, 4
|
||||
%6 = or i1 %5, %4
|
||||
%7 = select i1 %6, float 1.000000e+00, float 0.000000e+00
|
||||
%8 = icmp eq i32 %0, 2
|
||||
%9 = and i32 %0, -2
|
||||
%10 = icmp eq i32 %9, 4
|
||||
%11 = or i1 %8, %10
|
||||
%12 = select i1 %11, float 1.000000e+00, float 0.000000e+00
|
||||
%13 = load <4 x float>, ptr addrspace(2) %1, align 16, !alias.scope !39
|
||||
%14 = shufflevector <4 x float> %13, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%15 = shufflevector <4 x float> %13, <4 x float> poison, <2 x i32> <i32 2, i32 3>
|
||||
%16 = insertelement <2 x float> undef, float %7, i64 0
|
||||
%17 = insertelement <2 x float> %16, float %12, i64 1
|
||||
%18 = tail call fast <2 x float> @air.mix.v2f32(<2 x float> %14, <2 x float> %15, <2 x float> %17) #8
|
||||
%19 = shufflevector <2 x float> %18, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
|
||||
%20 = shufflevector <4 x float> %19, <4 x float> <float poison, float poison, float 0.000000e+00, float 1.000000e+00>, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
|
||||
%21 = insertvalue <{ <4 x float> }> undef, <4 x float> %20, 0
|
||||
ret <{ <4 x float> }> %21
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
|
||||
define <4 x float> @psb_solid(<4 x float> %0, ptr addrspace(2) noundef readonly align 16 captures(none) dereferenceable(16) "air-buffer-no-alias" %1) local_unnamed_addr #1 {
|
||||
%3 = load <4 x float>, ptr addrspace(2) %1, align 16, !tbaa !42, !alias.scope !45
|
||||
ret <4 x float> %3
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
|
||||
define <4 x float> @psb_read(<4 x float> %0, ptr addrspace(1) readonly captures(none) %1) local_unnamed_addr #2 {
|
||||
%3 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%4 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %3) #8
|
||||
%5 = tail call ptr addrspace(2) @air.get_read_sampler() #9
|
||||
%6 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %1, ptr addrspace(2) %5, <2 x i32> %4, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%7 = extractvalue { <4 x float>, i8 } %6, 0
|
||||
%8 = shufflevector <4 x float> <float poison, float poison, float poison, float 1.000000e+00>, <4 x float> %7, <4 x i32> <i32 6, i32 4, i32 5, i32 3>
|
||||
ret <4 x float> %8
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
|
||||
declare <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float>) local_unnamed_addr #3
|
||||
|
||||
; Function Attrs: convergent mustprogress nofree nounwind willreturn memory(argmem: read)
|
||||
define <4 x float> @psb_sample(<4 x float> %0, ptr addrspace(1) readonly captures(none) %1) local_unnamed_addr #4 {
|
||||
%3 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%4 = tail call { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %1, ptr addrspace(2) readonly captures(none) @__air_sampler_state, <2 x float> %3, i1 true, <2 x i32> zeroinitializer, i1 false, float 0.000000e+00, float 0.000000e+00, i32 0) #11
|
||||
%5 = extractvalue { <4 x float>, i8 } %4, 0
|
||||
%6 = shufflevector <4 x float> <float poison, float poison, float poison, float 1.000000e+00>, <4 x float> %5, <4 x i32> <i32 6, i32 4, i32 5, i32 3>
|
||||
ret <4 x float> %6
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
|
||||
define <4 x float> @psb_masked(<4 x float> %0, ptr addrspace(1) readonly captures(none) %1, ptr addrspace(1) %2) local_unnamed_addr #2 {
|
||||
%4 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%5 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %4) #8
|
||||
%6 = tail call ptr addrspace(2) @air.get_read_sampler() #9
|
||||
%7 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %1, ptr addrspace(2) %6, <2 x i32> %5, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%8 = extractvalue { <4 x float>, i8 } %7, 0
|
||||
%9 = extractelement <2 x i32> %5, i64 0
|
||||
%10 = tail call i32 @air.get_width_texture_2d(ptr addrspace(1) readonly captures(none) %2, i32 0) #10, !alias.scope !48
|
||||
%11 = urem i32 %9, %10
|
||||
%12 = insertelement <2 x i32> undef, i32 %11, i64 0
|
||||
%13 = extractelement <2 x i32> %5, i64 1
|
||||
%14 = tail call i32 @air.get_height_texture_2d(ptr addrspace(1) readonly captures(none) %2, i32 0) #10, !alias.scope !48
|
||||
%15 = urem i32 %13, %14
|
||||
%16 = insertelement <2 x i32> %12, i32 %15, i64 1
|
||||
%17 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %2, ptr addrspace(2) %6, <2 x i32> %16, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%18 = extractvalue { <4 x float>, i8 } %17, 0
|
||||
%19 = shufflevector <4 x float> %8, <4 x float> %18, <4 x i32> <i32 2, i32 0, i32 1, i32 7>
|
||||
ret <4 x float> %19
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
|
||||
define <4 x float> @psb_under(<4 x float> %0, ptr addrspace(1) readonly captures(none) %1, ptr addrspace(1) %2) local_unnamed_addr #2 {
|
||||
%4 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> <i32 0, i32 1>
|
||||
%5 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %4) #8
|
||||
%6 = tail call ptr addrspace(2) @air.get_read_sampler() #9
|
||||
%7 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %1, ptr addrspace(2) %6, <2 x i32> %5, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%8 = extractvalue { <4 x float>, i8 } %7, 0
|
||||
%9 = extractelement <2 x i32> %5, i64 0
|
||||
%10 = tail call i32 @air.get_width_texture_2d(ptr addrspace(1) readonly captures(none) %2, i32 0) #10, !alias.scope !51
|
||||
%11 = urem i32 %9, %10
|
||||
%12 = insertelement <2 x i32> undef, i32 %11, i64 0
|
||||
%13 = extractelement <2 x i32> %5, i64 1
|
||||
%14 = tail call i32 @air.get_height_texture_2d(ptr addrspace(1) readonly captures(none) %2, i32 0) #10, !alias.scope !51
|
||||
%15 = urem i32 %13, %14
|
||||
%16 = insertelement <2 x i32> %12, i32 %15, i64 1
|
||||
%17 = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none) %2, ptr addrspace(2) %6, <2 x i32> %16, <2 x i32> zeroinitializer, i32 0, i32 1) #10
|
||||
%18 = extractvalue { <4 x float>, i8 } %17, 0
|
||||
%19 = shufflevector <4 x float> %18, <4 x float> %8, <4 x i32> <i32 2, i32 0, i32 1, i32 7>
|
||||
ret <4 x float> %19
|
||||
}
|
||||
|
||||
; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
|
||||
declare <2 x float> @air.mix.v2f32(<2 x float>, <2 x float>, <2 x float>) local_unnamed_addr #3
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind willreturn memory(inaccessiblemem: read)
|
||||
declare ptr addrspace(2) @air.get_read_sampler() local_unnamed_addr #5
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
|
||||
declare { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) readonly captures(none), ptr addrspace(2), <2 x i32>, <2 x i32>, i32, i32) local_unnamed_addr #6
|
||||
|
||||
; Function Attrs: convergent mustprogress nofree nounwind willreturn memory(argmem: read)
|
||||
declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1) readonly captures(none), ptr addrspace(2) readonly captures(none), <2 x float>, i1, <2 x i32>, i1, float, float, i32) local_unnamed_addr #7
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
|
||||
declare i32 @air.get_width_texture_2d(ptr addrspace(1) readonly captures(none), i32) local_unnamed_addr #6
|
||||
|
||||
; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
|
||||
declare i32 @air.get_height_texture_2d(ptr addrspace(1) readonly captures(none), i32) local_unnamed_addr #6
|
||||
|
||||
attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="64" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
|
||||
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
|
||||
attributes #2 = { mustprogress nofree nounwind willreturn memory(read) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
|
||||
attributes #3 = { mustprogress nofree nosync nounwind willreturn memory(none) }
|
||||
attributes #4 = { convergent mustprogress nofree nounwind willreturn memory(argmem: read) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
|
||||
attributes #5 = { mustprogress nofree nounwind willreturn memory(inaccessiblemem: read) }
|
||||
attributes #6 = { mustprogress nofree nounwind willreturn memory(argmem: read) }
|
||||
attributes #7 = { convergent mustprogress nofree nounwind willreturn memory(argmem: read) }
|
||||
attributes #8 = { nounwind willreturn memory(none) }
|
||||
attributes #9 = { nounwind willreturn memory(inaccessiblemem: read) }
|
||||
attributes #10 = { nounwind willreturn memory(argmem: read) }
|
||||
attributes #11 = { convergent nounwind willreturn memory(argmem: read) }
|
||||
|
||||
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
|
||||
!air.vertex = !{!9}
|
||||
!air.fragment = !{!15, !21, !25, !28, !31}
|
||||
!air.compile_options = !{!32, !33, !34}
|
||||
!air.sampler_states = !{!35}
|
||||
!llvm.ident = !{!36}
|
||||
!air.version = !{!37}
|
||||
!air.language_version = !{!38}
|
||||
|
||||
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]}
|
||||
!1 = !{i32 1, !"wchar_size", i32 4}
|
||||
!2 = !{i32 7, !"frame-pointer", i32 2}
|
||||
!3 = !{i32 7, !"air.max_device_buffers", i32 31}
|
||||
!4 = !{i32 7, !"air.max_constant_buffers", i32 31}
|
||||
!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31}
|
||||
!6 = !{i32 7, !"air.max_textures", i32 128}
|
||||
!7 = !{i32 7, !"air.max_read_write_textures", i32 8}
|
||||
!8 = !{i32 7, !"air.max_samplers", i32 16}
|
||||
!9 = !{ptr @psb_rect, !10, !12}
|
||||
!10 = !{!11}
|
||||
!11 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
|
||||
!12 = !{!13, !14}
|
||||
!13 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"}
|
||||
!14 = !{i32 1, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"r"}
|
||||
!15 = !{ptr @psb_solid, !16, !18}
|
||||
!16 = !{!17}
|
||||
!17 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"}
|
||||
!18 = !{!19, !20}
|
||||
!19 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"}
|
||||
!20 = !{i32 1, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"c"}
|
||||
!21 = !{ptr @psb_read, !16, !22}
|
||||
!22 = !{!23, !24}
|
||||
!23 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
|
||||
!24 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.read", !"air.arg_type_name", !"texture2d<float, read>", !"air.arg_name", !"t"}
|
||||
!25 = !{ptr @psb_sample, !16, !26}
|
||||
!26 = !{!23, !27}
|
||||
!27 = !{i32 1, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.sample", !"air.arg_type_name", !"texture2d<float, sample>", !"air.arg_name", !"t"}
|
||||
!28 = !{ptr @psb_masked, !16, !29}
|
||||
!29 = !{!23, !24, !30}
|
||||
!30 = !{i32 2, !"air.texture", !"air.location_index", i32 3, i32 1, !"air.read", !"air.arg_type_name", !"texture2d<float, read>", !"air.arg_name", !"m"}
|
||||
!31 = !{ptr @psb_under, !16, !29}
|
||||
!32 = !{!"air.compile.denorms_disable"}
|
||||
!33 = !{!"air.compile.fast_math_enable"}
|
||||
!34 = !{!"air.compile.framebuffer_fetch_enable"}
|
||||
!35 = !{!"air.sampler_state", ptr addrspace(2) @__air_sampler_state}
|
||||
!36 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"}
|
||||
!37 = !{i32 2, i32 8, i32 0}
|
||||
!38 = !{!"Metal", i32 4, i32 0, i32 0}
|
||||
!39 = !{!40}
|
||||
!40 = distinct !{!40, !41, !"air-alias-scope-arg(1)"}
|
||||
!41 = distinct !{!41, !"air-alias-scopes(psb_rect)"}
|
||||
!42 = !{!43, !43, i64 0}
|
||||
!43 = !{!"omnipotent char", !44, i64 0}
|
||||
!44 = !{!"Simple C++ TBAA"}
|
||||
!45 = !{!46}
|
||||
!46 = distinct !{!46, !47, !"air-alias-scope-arg(1)"}
|
||||
!47 = distinct !{!47, !"air-alias-scopes(psb_solid)"}
|
||||
!48 = !{!49}
|
||||
!49 = distinct !{!49, !50, !"air-alias-scope-textures"}
|
||||
!50 = distinct !{!50, !"air-alias-scopes(psb_masked)"}
|
||||
!51 = !{!52}
|
||||
!52 = distinct !{!52, !53, !"air-alias-scope-textures"}
|
||||
!53 = distinct !{!53, !"air-alias-scopes(psb_under)"}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Owned fixture: a rectangle and fragment functions that read the texture their own render pass
|
||||
// renders, at the fragment's own pixel, as a pass that begins with a memory barrier over the render
|
||||
// targets reads it: a solid color, a read and a pixel-coordinate sample of texture 0 with its
|
||||
// channels reordered, a read of texture 0 beside a mask at texture 3, and a read of texture 3 over
|
||||
// texture 0's alpha. Written for this repository; no third-party source. Loop-free.
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
struct PsbVertex {
|
||||
float4 position [[position]];
|
||||
};
|
||||
|
||||
// A rectangle, two triangles of six vertices, from corner r.xy to corner r.zw.
|
||||
vertex PsbVertex psb_rect(uint vid [[vertex_id]], constant float4 &r [[buffer(0)]]) {
|
||||
bool right = vid == 1u || vid == 3u || vid == 4u;
|
||||
bool up = vid == 2u || vid == 4u || vid == 5u;
|
||||
PsbVertex out;
|
||||
out.position = float4(mix(r.xy, r.zw, float2(right ? 1.0 : 0.0, up ? 1.0 : 0.0)), 0.0, 1.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
fragment float4 psb_solid(PsbVertex in [[stage_in]], constant float4 &c [[buffer(0)]]) {
|
||||
return c;
|
||||
}
|
||||
|
||||
// t's texel under the pixel, its channels as (b, r, g), opaque.
|
||||
fragment float4 psb_read(PsbVertex in [[stage_in]], texture2d<float, access::read> t [[texture(0)]]) {
|
||||
float4 c = t.read(uint2(in.position.xy));
|
||||
return float4(c.b, c.r, c.g, 1.0);
|
||||
}
|
||||
|
||||
// The same through a nearest sampler in pixel coordinates, at the pixel's center.
|
||||
fragment float4 psb_sample(PsbVertex in [[stage_in]], texture2d<float> t [[texture(0)]]) {
|
||||
constexpr sampler s(coord::pixel, filter::nearest);
|
||||
float4 c = t.sample(s, in.position.xy);
|
||||
return float4(c.b, c.r, c.g, 1.0);
|
||||
}
|
||||
|
||||
// t's texel under the pixel as psb_read reorders it, with the alpha of m's texel at the pixel
|
||||
// wrapped to m's extent.
|
||||
fragment float4 psb_masked(PsbVertex in [[stage_in]],
|
||||
texture2d<float, access::read> t [[texture(0)]],
|
||||
texture2d<float, access::read> m [[texture(3)]]) {
|
||||
uint2 p = uint2(in.position.xy);
|
||||
float4 c = t.read(p);
|
||||
float4 k = m.read(uint2(p.x % m.get_width(), p.y % m.get_height()));
|
||||
return float4(c.b, c.r, c.g, k.a);
|
||||
}
|
||||
|
||||
// m's texel at the pixel wrapped to m's extent, its channels as (b, r, g), with the alpha of t's
|
||||
// texel under the pixel.
|
||||
fragment float4 psb_under(PsbVertex in [[stage_in]],
|
||||
texture2d<float, access::read> t [[texture(0)]],
|
||||
texture2d<float, access::read> m [[texture(3)]]) {
|
||||
uint2 p = uint2(in.position.xy);
|
||||
float4 c = t.read(p);
|
||||
float4 k = m.read(uint2(p.x % m.get_width(), p.y % m.get_height()));
|
||||
return float4(k.b, k.r, k.g, c.a);
|
||||
}
|
||||
@@ -43,6 +43,17 @@
|
||||
//! its copy the texels around the block alone.
|
||||
//! - [`a_pass_that_samples_no_attachment_copies_nothing`]: A, then `tob_read` of another texture:
|
||||
//! no read through a copy, split, own-pixel read or shadow copy.
|
||||
//! - [`a_draw_after_a_barrier_at_the_pass_start_reads_the_clear`]: a pass that clears the target
|
||||
//! to [`CLEAR`] and begins with a memory barrier over the render targets (the scope alone, with
|
||||
//! the textures, or the target named), then one draw through [`READ_AREA`] that reads the target
|
||||
//! at its own pixel (`psb_read`) or samples it at its pixel's center in pixel coordinates
|
||||
//! (`psb_sample`): the draw reads the clear, its instance after the pass's first, which runs the
|
||||
//! clear alone (`attachment_read_splits`), or through a snapshot.
|
||||
//! - [`a_draw_after_a_clear_with_no_barrier_reads_the_texels_from_before_the_pass`]: the same with
|
||||
//! no barrier reads the red from before the pass, with no split.
|
||||
//! - [`a_barrier_at_the_pass_start_costs_nothing_without_a_read_of_a_cleared_color`]: a pass that
|
||||
//! loads the target and reads it after the barrier, or clears it and reads another texture,
|
||||
//! splits nothing and begins as many instances and copies as the same pass with no barrier.
|
||||
|
||||
use super::degrade_notices::{assert_once, counts, on_device};
|
||||
use crate::air_library::AirLibrary;
|
||||
@@ -51,9 +62,10 @@ use metal2vulkan::metal::{BarrierScope, PixelFormat, PrimitiveType, RenderStages
|
||||
use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource};
|
||||
use metal2vulkan_devtools::llvm_assemble;
|
||||
use metal2vulkan_runtime::{
|
||||
BlitOption, Buffer, CommandQueue, Degradation, Device, LoadAction, Origin, PipelineOptions,
|
||||
Region, RenderCommandEncoder, RenderPassDescriptor, RenderPipelineState, ResourceOptions,
|
||||
ScissorRect, Size, StoreAction, Texture, TextureDescriptor, WorkCounts,
|
||||
BlitOption, Buffer, ClearColor, CommandQueue, Degradation, Device, LoadAction, Origin,
|
||||
PipelineOptions, Region, RenderCommandEncoder, RenderPassDescriptor, RenderPipelineState,
|
||||
ResourceOptions, ResourceRef, ScissorRect, Size, StoreAction, Texture, TextureDescriptor,
|
||||
WorkCounts,
|
||||
};
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
@@ -804,3 +816,298 @@ fn a_chain_of_barriers_copies_in_only_what_each_instance_drew() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// The clear a pass of [`started_pass`] that clears its target clears it to: codes none of
|
||||
/// [`BEFORE`]'s texel's, each a whole code so the clear stores it exactly.
|
||||
const CLEAR: [u8; 4] = [200, 40, 120, 160];
|
||||
|
||||
/// The scissor of the draw of [`started_pass`]: inside the target, off its edges.
|
||||
const READ_AREA: ScissorRect = ScissorRect {
|
||||
x: 4,
|
||||
y: 4,
|
||||
width: 20,
|
||||
height: 12,
|
||||
};
|
||||
|
||||
/// What a pass of [`started_pass`] encodes before its draw.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum Start {
|
||||
/// Nothing.
|
||||
Nothing,
|
||||
/// `memoryBarrierWithScope:` of this scope, after the fragment stage and before it.
|
||||
Scope(BarrierScope),
|
||||
/// `memoryBarrierWithResources:` over the target, after the fragment stage and before it.
|
||||
Resources,
|
||||
}
|
||||
|
||||
/// The `psb_rect` state with the fragment function `fragment` of `psb_reads`, into an unblended
|
||||
/// `RGBA8Unorm` color.
|
||||
fn psb_state(device: &Device, fragment: &str) -> RenderPipelineState {
|
||||
let mut d = RenderPipelineDescriptor::new(function(device, "psb_rect", "psb_reads.ll"));
|
||||
d.fragment = Some(function(device, fragment, "psb_reads.ll"));
|
||||
d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm));
|
||||
device
|
||||
.new_render_pipeline_state(&d, &PipelineOptions::default())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// One pass over `target`, loaded by `load` (to [`CLEAR`] where it clears) and stored: `start`
|
||||
/// first, then one draw of `state` over the whole target through [`READ_AREA`], `read` at its
|
||||
/// fragment texture 0; and the target's bytes, tight rows, read back.
|
||||
fn started_pass(
|
||||
queue: &CommandQueue,
|
||||
target: &Texture,
|
||||
load: LoadAction,
|
||||
start: Start,
|
||||
(state, read): (&RenderPipelineState, &Texture),
|
||||
) -> Vec<u8> {
|
||||
let device = queue.device();
|
||||
let mut d = RenderPassDescriptor::new();
|
||||
let color = &mut d.color_attachments[0];
|
||||
color.texture = Some(target.clone());
|
||||
color.load_action = load;
|
||||
color.store_action = StoreAction::Store;
|
||||
let code = |at: usize| f64::from(CLEAR[at]) / 255.0;
|
||||
color.clear_color = ClearColor::new(code(0), code(1), code(2), code(3));
|
||||
let back = device
|
||||
.new_buffer(SIDE * SIDE * 4, ResourceOptions::shared())
|
||||
.unwrap();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut encoder = command_buffer.render_command_encoder(&d).unwrap();
|
||||
let fragment = RenderStages::FRAGMENT;
|
||||
match start {
|
||||
Start::Nothing => {}
|
||||
Start::Scope(scope) => encoder.memory_barrier_with_scope(scope, fragment, fragment),
|
||||
Start::Resources => encoder
|
||||
.memory_barrier_with_resources(&[ResourceRef::Texture(target)], fragment, fragment)
|
||||
.unwrap(),
|
||||
}
|
||||
encoder.set_render_pipeline_state(state).unwrap();
|
||||
encoder
|
||||
.set_vertex_bytes(&corners([0, 0, SIDE, SIDE]), 0)
|
||||
.unwrap();
|
||||
encoder.set_scissor_rect(READ_AREA).unwrap();
|
||||
encoder.set_fragment_texture(Some(read), 0).unwrap();
|
||||
encoder
|
||||
.draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0)
|
||||
.unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
blit.copy_from_texture_to_buffer(
|
||||
target,
|
||||
0,
|
||||
0,
|
||||
Origin::new(0, 0, 0),
|
||||
Size::new(SIDE, SIDE, 1),
|
||||
&back,
|
||||
0,
|
||||
SIDE * 4,
|
||||
SIDE * SIDE * 4,
|
||||
BlitOption::None,
|
||||
)
|
||||
.unwrap();
|
||||
blit.end_encoding().unwrap();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.error(), None);
|
||||
let contents = back.contents().unwrap();
|
||||
// SAFETY: the buffer's bytes, which no command uses now.
|
||||
unsafe { std::slice::from_raw_parts(contents.as_ptr(), back.length() as usize) }.to_vec()
|
||||
}
|
||||
|
||||
/// What `psb_read` and `psb_sample` write for the texel `seen`: its channels as `(b, r, g)`,
|
||||
/// opaque.
|
||||
fn reordered(seen: [u8; 4]) -> [u8; 4] {
|
||||
[seen[2], seen[0], seen[1], 255]
|
||||
}
|
||||
|
||||
/// Hold `bytes`, a pass of [`started_pass`]'s, to `inside` in [`READ_AREA`] and `outside` around
|
||||
/// it.
|
||||
fn hold_area(name: &str, bytes: &[u8], inside: [u8; 4], outside: [u8; 4]) {
|
||||
let area = |x: u64, y: u64| {
|
||||
let (x0, y0) = (READ_AREA.x, READ_AREA.y);
|
||||
(x0..x0 + READ_AREA.width).contains(&x) && (y0..y0 + READ_AREA.height).contains(&y)
|
||||
};
|
||||
for y in 0..SIDE {
|
||||
for x in 0..SIDE {
|
||||
let at = ((y * SIDE + x) * 4) as usize;
|
||||
let want = if area(x, y) { inside } else { outside };
|
||||
assert_eq!(bytes[at..at + 4], want, "{name}: pixel ({x}, {y})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The instance splits and the render pass instances a pass moved, by every cause.
|
||||
fn instances(before: &WorkCounts, after: &WorkCounts) -> [u64; 2] {
|
||||
let splits = |c: &WorkCounts| {
|
||||
c.instance_splits_barrier
|
||||
+ c.instance_splits_tile_dispatch
|
||||
+ c.instance_splits_tile_memory
|
||||
+ c.instance_splits_attached_read
|
||||
+ c.instance_splits_feedback
|
||||
+ c.instance_splits_memoryless_write
|
||||
+ c.instance_splits_pending_pipeline
|
||||
+ c.instance_splits_execution
|
||||
+ c.instance_splits_visibility
|
||||
+ c.instance_splits_shape
|
||||
};
|
||||
let begun = |c: &WorkCounts| {
|
||||
c.render_passes_begun_instances
|
||||
+ c.render_passes_begun_inline
|
||||
+ c.render_passes_begun_inline_splits
|
||||
+ c.render_passes_begun_resolves
|
||||
};
|
||||
[splits(after) - splits(before), begun(after) - begun(before)]
|
||||
}
|
||||
|
||||
/// The barriers [`a_draw_after_a_barrier_at_the_pass_start_reads_the_clear`] begins its passes
|
||||
/// with: over the render targets alone (inside an instance where draws came before it), over
|
||||
/// them and the textures (a split where draws came before it), and over the target itself.
|
||||
const STARTS: [Start; 3] = [
|
||||
Start::Scope(BarrierScope::RENDER_TARGETS),
|
||||
Start::Scope(BarrierScope::RENDER_TARGETS.union(BarrierScope::TEXTURES)),
|
||||
Start::Resources,
|
||||
];
|
||||
|
||||
/// A pass that clears its target and begins with a memory barrier over the render targets, after
|
||||
/// the fragment stage and before it: its draw reads, at its own pixel (`psb_read`) or sampling at
|
||||
/// its pixel's center in pixel coordinates (`psb_sample`), the clear, as a Mac2 GPU orders the
|
||||
/// barrier (the pass's load actions are behind it; an M3 Max, whose GPU does not support the
|
||||
/// scope, reads the texels from before the pass, `fence.rs`). It records into an instance after
|
||||
/// the pass's first, which runs the clear alone (`attachment_read_splits`,
|
||||
/// `instance_splits_attached_read`), or reads through a snapshot inside the first
|
||||
/// (`reading_draws_snapshotted`).
|
||||
#[test]
|
||||
fn a_draw_after_a_barrier_at_the_pass_start_reads_the_clear() {
|
||||
on_device(|device, _messages| {
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
for fragment in ["psb_read", "psb_sample"] {
|
||||
let state = psb_state(device, fragment);
|
||||
for start in STARTS {
|
||||
for (name, target, _buffer) in targets(device) {
|
||||
let name = format!("{name}, {fragment}, {start:?}");
|
||||
let counted = device.work_counts();
|
||||
let bytes =
|
||||
started_pass(&queue, &target, LoadAction::Clear, start, (&state, &target));
|
||||
let after = device.work_counts();
|
||||
hold_area(&name, &bytes, reordered(CLEAR), CLEAR);
|
||||
let moved = moved(&counted, &after);
|
||||
let [splits, begun] = instances(&counted, &after);
|
||||
let attached =
|
||||
after.instance_splits_attached_read - counted.instance_splits_attached_read;
|
||||
eprintln!(
|
||||
"{name}: instance splits {splits} ({attached} attached), begun {begun}"
|
||||
);
|
||||
check(&name, &moved, 1);
|
||||
if !moved.apart {
|
||||
assert_eq!(attached, moved.splits, "{name}: splits for the read");
|
||||
assert_eq!(splits, moved.splits, "{name}: no other split");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// With no barrier, the draw of a pass that clears its target reads the texels from before the
|
||||
/// pass at its own pixel, Metal's answer there (probe `selfsample`; the M3 Max reads them after a
|
||||
/// barrier too), with no split.
|
||||
#[test]
|
||||
fn a_draw_after_a_clear_with_no_barrier_reads_the_texels_from_before_the_pass() {
|
||||
on_device(|device, _messages| {
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
for fragment in ["psb_read", "psb_sample"] {
|
||||
let state = psb_state(device, fragment);
|
||||
for (name, target, _buffer) in targets(device) {
|
||||
let name = format!("{name}, {fragment}");
|
||||
let counted = device.work_counts();
|
||||
let bytes = started_pass(
|
||||
&queue,
|
||||
&target,
|
||||
LoadAction::Clear,
|
||||
Start::Nothing,
|
||||
(&state, &target),
|
||||
);
|
||||
let after = device.work_counts();
|
||||
hold_area(&name, &bytes, reordered([BEFORE, 0, 0, 255]), CLEAR);
|
||||
let moved = moved(&counted, &after);
|
||||
check(&name, &moved, 0);
|
||||
assert_eq!(instances(&counted, &after)[0], 0, "{name}: a split");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// A barrier at the start of a pass costs nothing where no draw after it samples a color the pass
|
||||
/// clears: a pass that loads its target, whose draw reads at its own pixel the texels from before
|
||||
/// the pass (what the load holds), and one that clears it, whose draw reads another texture. Each
|
||||
/// splits no instance, begins as many render pass instances and takes as many copies as the same
|
||||
/// pass with no barrier.
|
||||
#[test]
|
||||
fn a_barrier_at_the_pass_start_costs_nothing_without_a_read_of_a_cleared_color() {
|
||||
on_device(|device, _messages| {
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let read = psb_state(device, "psb_read");
|
||||
let mut d = TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, SIDE, SIDE, false);
|
||||
d.usage = TextureUsage::SHADER_READ;
|
||||
d.resource_options = ResourceOptions::shared();
|
||||
let other = device.new_texture(&d).unwrap();
|
||||
other
|
||||
.replace_region(
|
||||
Region::new_2d(0, 0, SIDE, SIDE),
|
||||
0,
|
||||
0,
|
||||
&before(),
|
||||
SIDE * 4,
|
||||
0,
|
||||
)
|
||||
.unwrap();
|
||||
let rt = Start::Scope(BarrierScope::RENDER_TARGETS);
|
||||
for (name, target, _buffer) in targets(device) {
|
||||
for (what, load, texture) in [
|
||||
("loaded, reading itself", LoadAction::Load, &target),
|
||||
(
|
||||
"cleared, reading another texture",
|
||||
LoadAction::Clear,
|
||||
&other,
|
||||
),
|
||||
] {
|
||||
let name = format!("{name}, {what}");
|
||||
let outside = match load {
|
||||
LoadAction::Clear => CLEAR,
|
||||
_ => [BEFORE, 0, 0, 255],
|
||||
};
|
||||
let mut costs = Vec::new();
|
||||
for start in [Start::Nothing, rt] {
|
||||
if load == LoadAction::Load {
|
||||
target
|
||||
.replace_region(
|
||||
Region::new_2d(0, 0, SIDE, SIDE),
|
||||
0,
|
||||
0,
|
||||
&before(),
|
||||
SIDE * 4,
|
||||
0,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let counted = device.work_counts();
|
||||
let bytes = started_pass(&queue, &target, load, start, (&read, texture));
|
||||
let after = device.work_counts();
|
||||
hold_area(&name, &bytes, reordered([BEFORE, 0, 0, 255]), outside);
|
||||
let moved = moved(&counted, &after);
|
||||
let [splits, begun] = instances(&counted, &after);
|
||||
eprintln!(
|
||||
"{name}, {start:?}: instance splits {splits}, begun {begun}, shadow \
|
||||
copies {}, snapshotted {}",
|
||||
moved.copies, moved.snapshotted
|
||||
);
|
||||
assert_eq!(splits, 0, "{name}, {start:?}: a split");
|
||||
assert_eq!(moved.snapshotted, 0, "{name}, {start:?}: a snapshot");
|
||||
costs.push((begun, moved.copies));
|
||||
}
|
||||
assert_eq!(costs[0], costs[1], "{name}: the barrier cost something");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -3937,6 +3937,15 @@ each item named states the rule in full.
|
||||
no notice says so, and every field the pass does determine is Metal's: the conformance case
|
||||
`mesh-commands-unordered-draws` compares those exactly and keeps Metal's own texels beside them,
|
||||
for the next macOS to be read against.
|
||||
- **A barrier over the render targets orders what it names, as a Mac2 GPU's does.** The Metal
|
||||
Feature Set Tables give `MTLBarrierScopeRenderTargets` to Mac2 GPUs, not to Apple GPUs, and an
|
||||
M3 Max (macOS 27.0.1) orders nothing with it: a draw after one that samples its own pass's color
|
||||
attachment's texture reads the texels from before the pass, whatever the pass's load action or
|
||||
draws wrote before the barrier. The runtime orders the draws after such a barrier, or one over
|
||||
the texture, after the fragment stage, behind the draws before it and, where it comes before
|
||||
the pass's first draw, behind the pass's load actions: that draw reads what the draws before the
|
||||
barrier wrote, or the clear (the runtime's `fence.rs` and `texture/attached_reads.rs`). With no
|
||||
barrier it reads the texels from before the pass at its own pixel, the M3 Max's answer.
|
||||
|
||||
**GPU hangs and faults** (a draw of private primitive type 9, `DrawPrimitiveType::Nine`)
|
||||
|
||||
|
||||
Reference in new issue
Block a user