Alias a padded texture that only reads by default, the shadow behind PaddedReadsPolicy::Shadow
The padded-reads work packet (the owner's choice): a padded texture that is only read aliases the
buffer by default, under the same documented first-move gap as tight aliases, checked per driver;
the exact shadow stays behind PaddedReadsPolicy::Shadow, which exact_answers() selects.
What: a 2D texture (or array) over a buffer whose rows or slices lie with bytes between them, and
whose usage as Metal reports it holds no RenderTarget, ShaderWrite, ShaderAtomic or block writes
(Unknown reads as 0x17, so it stays a shadow; a swizzled texture reports ShaderRead |
PixelFormatView and reads), is now an image over the buffer's bytes at Metal's row pitch, as a
texture of packed rows is: the device's own linear image (PREINITIALIZED over ordinary memory, for
host allocations over a no-copy buffer), a DRM_FORMAT_MOD_LINEAR image at that pitch, or one over
a dma-buf of the pages. Its subresources may hold the bytes between its rows and its last row's
padding (to row_pitch x rows); a driver whose image reaches past that is refused as for packed rows
(lavapipe's height rounded up to 4). A render target or a texture a shader writes stays a shadow.
The rebind remakes the image under the same rule (AliasKind::Linear keeps it).
The switch: DevicePolicy.padded_reads, PaddedReadsPolicy::{Alias (default), Shadow};
DevicePolicy::exact_answers() selects Shadow, the runtime's shadow copied in before each use. It
is the runtime's alone: no ProfileFields carries it, so no profile fingerprint moves
(tests::fast_paths::the_runtime_s_padded_reads_choice_keys_no_profile) and SEMANTICS_VERSION
stays. The owner's ruling (relayed by reims-vgpu-orchestrator, 2026-10-14 15:55): "I'll take 1 &
2", (2) being this, "exact to the same standard as tight aliases", under 30c8b4bff8's first-move
known gap extended to the padding bytes, checked by the same per-driver lane check.
Why it is the same standard: the first move is the only layout transition a runtime image takes.
- Every image memory barrier the runtime records is a first move (texture/first_move.rs
FirstMove::barrier), a new image's own (storage_form.rs, host_copy.rs; never an alias), or a
caller-wrapped image's Transition (submit.rs via texture/wrapped.rs).
- The tracker's barriers are VkMemoryBarriers (tracker.rs Barrier::record), which transition no
layout.
- Blits into a texture copy in GENERAL: blit_texture.rs's vkCmdCopyBufferToImage and
vkCmdCopyImage. VUID-vkCmdCopyBufferToImage-dstImageLayout-01396 and
VUID-vkCmdCopyImage-dstImageLayout-01395 allow GENERAL; GENERAL "supports all types of device
access".
- "Each source region specified by pRegions is copied from the source buffer to the destination
region of the destination image". The Memory Model: "A memory operation must not affect memory
at a memory location not within its set of memory locations".
- Every descriptor names GENERAL (binding.rs, heap_sets.rs).
- A texture over a buffer has one level (linear_plan's MipmapLevelCount), so generate_mipmaps
leaves it, and optimize_contents_for_gpu_access records nothing.
- A texture without RenderTarget usage has no COLOR_ATTACHMENT usage. A pass renders it through a
stand-in, copied in GENERAL, so no load or store operation reaches its image.
How:
- linear_plan's padding() becomes holding(layout, usage, policy) -> Result<Holds, String>, with
Holds::{Texels, Padding}, Holds::fits (texels_alone, or the new padded_alone) and only_reads.
- aliases() takes the Holds. So do alias_image, dma_buf_alias_image (DmaBufTexels.alone),
host_alias_unbound, host_pitched_image, and the pointer and dma-buf rebinds.
- storage_over_buffer decides it once, from texture_usage (the effective usage), so the shadow's
reason no longer reads the raw descriptor's RenderTarget bit. The reason of a read-only texture
shadowed under the switch names PaddedReadsPolicy::Shadow.
- RUNTIME_VERSION 1211 (renumbered at compose); the runtime-sources pin is recomputed at this tree.
Docs:
- FAST-PATHS.md: a fast-defaults row (padded_reads = PaddedReadsPolicy::Alias/Shadow, ANV's 0.63
ms copy in per tile use and 135 vs 41 us making).
- FAST-PATHS.md: the padded-row shadow row now covers textures that render or that a shader
writes.
- FAST-PATHS.md: the first-move gap row now covers the bytes between rows, with the GENERAL anchors
in prose and the M3 Max probe's point (Metal never writes padding, even under concurrent CPU
writes).
- API.md's shadowed-texture entry, ShadowedTexture's rustdoc, HOWTO.md, interop.rs and dma_buf.rs.
- The refusal surface is unchanged (refusal_surface.py --check).
Verified so far:
- clippy -D warnings, all targets, all features, --cfg m2v_cpu_icd: clean (um780, Rust 1.98.1).
- cargo fmt --check: clean.
The unit and lane runs follow with the lane checks' commit.
Check per driver that a padded texture that only reads keeps every byte of its pages:
What: three lane tests in runtime_lane::pitched_surfaces, under PaddedReadsPolicy::Alias (the lane's
own devices take exact_answers, so Shadow), each over no-copy buffers of anonymous pages:
- a_texture_that_only_reads_keeps_every_byte_of_its_pages: a ShaderRead texture over each of the
11 layouts. Its first use is a fragment function's read through its image, before anything else
touches the pages: it must read the pages' texels, and every byte of the pages, the bytes between
the rows among them, must be unchanged. That is the image's first move, the known gap 30c8b4bff8
records, now over padding.
Then: a nearest and a linear sample, get_bytes and a blit out. The caller rewrites the texels and
the bytes between the rows; a sample and a read must give the new texels. Blits Metal makes into
any texture: a buffer's box at an odd origin, replace_region of a box, a private texture's box.
After each step every byte of the pages is compared (the blit-into-alias check the peer asked
for: a driver whose copy writes past its region fails, naming the bytes).
Prints PITCHED-READS, how many padded layouts aliased. Off MoltenVK at least one must, or no
first move over padded rows was checked.
- a_padded_texture_that_only_reads_copies_no_shadow_by_default: each padded layout under Alias and
under Shadow. Three nearest samples and a blit out read the texels. An aliased texture copies no
shadow (WorkCounts::shadow_copies unchanged), a shadow copies one in (more than 0). Under Shadow
it is never aliased off MoltenVK. Off MoltenVK at least one layout aliases under Alias.
- a_padded_texture_that_renders_or_writes_is_a_shadow_under_either_policy: the browser's tile with
RenderTarget | ShaderRead, ShaderRead | ShaderWrite and Unknown usage, under both policies, over
a no-copy buffer (shadow off MoltenVK) and an ordinary buffer (shadow everywhere).
surface() takes whether the device may alias the texture's padded rows; the existing callers pass
false and keep their assertion.
Why: the owner's standard for the read-only padded alias is the tight aliases', checked per driver
by the same first-use lane check. A driver that fails it gets a structural driver-defect entry
that keeps the shadow there.
Lane filter for the round: runtime_lane::pitched_surfaces.
Verified: clippy -D warnings with --cfg m2v_cpu_icd (um780). The device runs follow.
Check a padded texture that only reads over an ordinary buffer's rows too:
What: runtime_lane::pitched_surfaces::a_padded_texture_that_only_reads_over_an_ordinary_buffer_keeps_its_bytes,
over each padded layout of LAYOUTS in a Shared buffer (not host pages), under both policies.
- Under PaddedReadsPolicy::Alias the texture is the device's own linear image over the buffer's
memory (made PREINITIALIZED, linear_image), where the device lays one at the rows' pitch.
- Its first use, a fragment function's read through it, must read the buffer's texels and leave
every byte of the buffer as it was, the bytes between the rows included.
- A nearest sample must read the texels too; an aliased texture copies no shadow over the two.
- Under Shadow it is never aliased.
- It prints each layout's form (PITCHED-READS).
Why: the read-only padded alias also takes the runtime's own PREINITIALIZED linear image, a path the
no-copy lanes do not reach. Its first move keeps the contents by the spec (the old layout is the
current one); the move's reach over the padding is the same known gap, now checked here per driver.
Verified: to follow, with the GPU runs (lavapipe, ANV, RADV x2, NVIDIA x2).
Name the drivers whose first move keeps a padded texture's bytes:
docs/FAST-PATHS.md's first-move known gap now lists the drivers whose run showed the bytes kept.
That covers the bytes between the rows of each padded layout the driver aliases, and the ordinary
buffer's check joins the cited tests.
Verified: runtime_lane::pitched_surfaces passed 19 of 19 at 6d4508a65d's tree on each:
- lavapipe and ANV (Iris Xe RPL-P), Mesa 26.2.4;
- RADV: the Radeon 780M on Mesa 26.2.4, the RX 7900 XTX on 26.0.8;
- NVIDIA 615.71.09: RTX 3090 and RTX 5080 Laptop GPU.
Padded layouts that only read and were aliased by default: 8, 8, 2, 2, 4 and 4 of 8. None changed
a byte of the pages. MoltenVK was not run.
Name the padded-reads alias among the default's choices in the API guide and the runtime's guide:
What: docs/API.md's list of what DevicePolicy::UNTRUSTED holds gains the image over a padded
texture that only reads (PaddedReadsPolicy::Alias), its structural test (no RenderTarget,
ShaderWrite, ShaderAtomic or block writes in the usage), its known gap (the bytes between the
rows are kept as far as the driver's first move keeps them) and the switch exact_answers()
selects. The runtime README's sentence on textures over buffers now says when the runtime keeps
a copy: where linear images cannot hold Metal's layout, and over padded rows when the texture
renders or a shader writes it, or only reads under PaddedReadsPolicy::Shadow.
Why: both guides described the default without the runtime's new choice; the README's sentence
already missed the padded render-target shadow.
Verified: docs only. The degrade-catalogue tests read API.md's catalogue, which this does not
touch; no degrade code is named. The runtime-sources pin covers src/ alone, so it is unchanged.
Time a compositor's frame over padded textures that only read, under each PaddedReadsPolicy:
What: surface_texture_costs gains read_only_padded_costs, an ignored release-mode measurement
(SURFTEX-READS). Each frame makes, for each padded layout of LAYOUTS, a no-copy buffer over its
surface's anonymous pages and a ShaderRead-only texture over it, samples each into a private
target of the browser tile in one pass, commits and waits. It runs under PaddedReadsPolicy::Alias
and ::Shadow, a device each, interleaved over three rounds, and prints per policy and round the
textures' forms, the medians and 90th percentiles of a texture's making, the frame's encoding,
commit to completion and process CPU, and the shadow copies a frame. pitched_surfaces' reading
pipeline and sampler helpers become pub(super) for it.
Why: FAST-PATHS' padded-reads row quotes ANV's copy-in cost per use; this measures what the
default saves per frame against the exact switch on any device, with the forms shown so a device
that shadows anyway is not counted as a saving.
Verified: validation-only and ignored by default; it changes no product source, so the runtime
pin and versions are unchanged. Its build and clippy under --cfg m2v_gpu are checked on um780,
and its run is on ms01's ANV.
Print why a padded texture that only reads over an ordinary buffer is a shadow:
What: a_padded_texture_that_only_reads_over_an_ordinary_buffer_keeps_its_bytes appends the
shadowed-texture notice's reason to its PITCHED-READS line, as the pages' tests already do in
their PITCHED-SURFACE lines, instead of taking the notices unread.
Why: on ANV (Mesa 26.2.4, ms01) none of the 8 padded layouts aliased over an ordinary buffer
under PaddedReadsPolicy::Alias, while all 8 alias over no-copy pages; the run showed the form but
not the reason, so the cause could only be guessed. The print names it per device.
Verified: test-only; the run on ms01's ANV prints the reasons (in the follow-up timing window).
Clippy under --cfg m2v_gpu on um780.
Quote ANV's measured frame cost of the padded-reads shadow in its ledger row:
What: FAST-PATHS.md's padded_reads row now quotes what read_only_padded_costs measured on ms01's
ANV (Iris Xe, Mesa 26.2.4). A frame sampling four BGRA8Unorm tiles over no-copy pages
(1307x512 at 5248 and 5376-byte rows, 300x200 at 1216, 1913x96 at 7680) in one pass completes
about 0.36 ms later as shadows: the median of 15 interleaved Alias/Shadow pairs, 0.08 to 0.60 ms,
all 15 positive. It also takes about 56 us more encoding and 91 us more process CPU. A texture's
making costs the same either way, about 45 us.
Why: the row quoted a 0.63 ms copy in per use and 135 vs 41 us making. Those were relayed
figures, not this case's measurement. Here making costs the same, and sampling the linear image
over host pages gives back part of the copy's saving, so the frame saves less than the copies'
sum.
Verified: 5 runs of read_only_padded_costs (3 interleaved rounds of 100 frames after 10 warm,
each) on ms01, release, --cfg m2v_gpu --cfg m2v_system_alloc, under both ANV locks, taskset
0-11, load under 1, forms "aaaa" under Alias and "ssss" under Shadow, 4.00 shadow copies a frame.
A first run of 3 more pairs, taken right after another workload, swung from -2.2 to +0.57 ms,
and is not counted. tests::fast_paths passes with the edited row (5/5, um780).
Versions: RUNTIME_VERSION 1204 -> 1205. RUNTIME_VERSION moves: read-only padded textures alias by
default. crates/metal2vulkan-validation/runtime-sources.sha256 holds
edc97e709c2605eaa13ac8696ea119fb9b727243a276a679d0b3288ed5b760b3, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
This commit is contained in:
1 parent
1e05c4a72c
commit
dd5a19aea1
18 files changed
+1060
-186
No files matched your search
@@ -199,8 +199,10 @@ the runtime made.
|
||||
bytes widened to 16-byte granules from the device's offset alignment, so it reports hazards
|
||||
between commands whose bytes are apart, as it does between untracked uses Metal leaves to the
|
||||
program; no order of either changes a result.
|
||||
- **Textures over buffers** share the buffer's bytes; where the device's linear images cannot hold
|
||||
Metal's layout the runtime keeps a copy and announces it (`shadowed-texture`).
|
||||
- **Textures over buffers** share the buffer's bytes. The runtime keeps a copy and announces it
|
||||
(`shadowed-texture`) where the device's linear images cannot hold Metal's layout, and where the
|
||||
rows lie with bytes between them and the texture renders or a shader writes it (or it only
|
||||
reads, under `PaddedReadsPolicy::Shadow`).
|
||||
|
||||
## Runtime extensions
|
||||
|
||||
|
||||
@@ -220,13 +220,13 @@ macro_rules! degradations {
|
||||
degradations! {
|
||||
runtime {
|
||||
/// A 2D texture over a buffer is a shadow image: its rows (or an array's slices) lie with
|
||||
/// the buffer's bytes between them, which an image over them would hold in its
|
||||
/// subresource, where Vulkan lets the image's layout transitions (its first move among
|
||||
/// them, which a texture that only reads takes too) read and write any byte of its
|
||||
/// subresources, and a render pass's load and store operations read and write back any
|
||||
/// byte of an attachment's image subresource, and Metal leaves them as the program writes
|
||||
/// them (but where the device's image of it is a Metal texture over the
|
||||
/// buffer, on MoltenVK); or no linear image of the device
|
||||
/// the buffer's bytes between them, and it renders or a shader writes it (or it only
|
||||
/// reads, under [`metal2vulkan::device::PaddedReadsPolicy::Shadow`]), which an image over
|
||||
/// them would hold in its subresource, where Vulkan lets the image's layout transitions
|
||||
/// (its first move among them) read and write any byte of its subresources, and a render
|
||||
/// pass's load and store operations read and write back any byte of an attachment's image
|
||||
/// subresource, and Metal leaves them as the program writes them (but where the device's
|
||||
/// image of it is a Metal texture over the buffer, on MoltenVK); or no linear image of the device
|
||||
/// lays its texels out as Metal does in the buffer's memory, holding no byte past them
|
||||
/// (over a no-copy buffer's imported
|
||||
/// host memory, no linear image made for host allocations does: neither the driver's own
|
||||
|
||||
@@ -44,10 +44,11 @@
|
||||
//! driver and takes its answer, never a rule of its own. The source is called only once the image
|
||||
//! is made and checked; the import keeps it, and goes after the image. Counted:
|
||||
//! `WorkCounts::dma_buf_images`. A texture whose rows (or slices) lie with the buffer's bytes
|
||||
//! between them takes no such image, nor one whose plane holds bytes past its texels: Vulkan
|
||||
//! lets an image's layout transitions and a render pass's load and store operations write any
|
||||
//! byte of its subresource (`linear_plan::padding`, `texels_alone`); it is a shadow, the source
|
||||
//! not asked, counted as a fallback. Over pages imported by their pointer, a texture over a
|
||||
//! between them takes no such image unless it only reads (under `PaddedReadsPolicy::Alias`, the
|
||||
//! default), nor one whose plane holds bytes past its texels (past its last row's pitch, for one
|
||||
//! that only reads): Vulkan lets an image's layout transitions and a render pass's load and
|
||||
//! store operations write any byte of its subresource (`linear_plan::holding`, `Holds`); it is a
|
||||
//! shadow, the source not asked, counted as a fallback. Over pages imported by their pointer, a texture over a
|
||||
//! buffer, its rows packed, whose rows the driver's linear image lays out otherwise is likewise
|
||||
//! a `DRM_FORMAT_MOD_LINEAR` image, its plane at the texture's pitches, made for host allocations
|
||||
//! ([`ModifierMemory::Host`]) and bound in the buffer's import, its features and limits checked
|
||||
@@ -95,7 +96,7 @@ use super::exit_guard::{self, Call};
|
||||
use super::host_memory::{based_size, import_refused, not_importable, ImportWindow, Importer};
|
||||
use super::image_plan::{ImageFacts, ImagePlan};
|
||||
use super::linear_plan::{
|
||||
check_linear_limits, texels_alone, tiling_lack, viewed_formats, BufferLayout, LinearLack,
|
||||
check_linear_limits, tiling_lack, viewed_formats, BufferLayout, Holds, LinearLack,
|
||||
};
|
||||
use super::memory::{ImportFailure, MemoryClass, Placement};
|
||||
use super::Device;
|
||||
@@ -617,10 +618,10 @@ pub(super) struct DmaBufTexels<'a> {
|
||||
pub(super) row_pitch: u64,
|
||||
/// The bytes from a slice's first texel to the next slice's, for a plan of several layers.
|
||||
pub(super) slice_pitch: u64,
|
||||
/// For a texture over a buffer, its texels' layout, which the image's plane holds alone
|
||||
/// (`linear_plan::texels_alone`): the buffer's other bytes are the program's. `None` for a
|
||||
/// For a texture over a buffer, its texels' layout, and what the image's plane may hold beside
|
||||
/// them (`linear_plan::Holds`): the buffer's other bytes are the program's. `None` for a
|
||||
/// heap's texture, whose image's bytes are its own.
|
||||
pub(super) alone: Option<BufferLayout>,
|
||||
pub(super) alone: Option<(BufferLayout, Holds)>,
|
||||
}
|
||||
|
||||
/// A texture's image over dma-buf pages, made and bound ([`Device::dma_buf_image`]): its
|
||||
@@ -774,12 +775,12 @@ impl Device {
|
||||
report.offset, report.row_pitch, report.array_pitch, texels.row_pitch
|
||||
));
|
||||
}
|
||||
if let Some(layout) = &texels.alone {
|
||||
if !texels_alone(layout, report.size, report.array_pitch) {
|
||||
if let Some((layout, holds)) = &texels.alone {
|
||||
if !holds.fits(layout, report.size, report.array_pitch) {
|
||||
return refuse(format!(
|
||||
"the driver's plane takes {} bytes, past the texels' {}",
|
||||
report.size,
|
||||
layout.end() - layout.offset
|
||||
holds.reach(layout)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +108,12 @@ impl Texture {
|
||||
/// `VK_IMAGE_TILING_LINEAR`, or of `VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT` with
|
||||
/// `DRM_FORMAT_MOD_LINEAR` and one memory plane laid out at the texels' offset and the
|
||||
/// texture's `bytes_per_row`. Such a texture's rows lie one after another and its image's
|
||||
/// subresource holds no byte but its texels: a texture whose rows lie with the buffer's bytes
|
||||
/// between them gives none (it is a shadow, `shadowed-texture`) but on MoltenVK, whose image
|
||||
/// is a Metal texture over the buffer. The second is the image over host pages imported as
|
||||
/// subresource holds no byte but its texels, or, for a texture that only reads under
|
||||
/// `PaddedReadsPolicy::Alias` (the default), its rows lie apart and its subresource holds the
|
||||
/// buffer's bytes between them too, up to its last row's pitch. A texture whose rows lie with
|
||||
/// the buffer's bytes between them and which renders or which a shader writes gives none (it
|
||||
/// is a shadow, `shadowed-texture`) but on MoltenVK, whose image is a Metal texture over the
|
||||
/// buffer. The second is the image over host pages imported as
|
||||
/// dma-bufs (`HostMemory::with_dma_buf`), and over a no-copy buffer's host pages where the
|
||||
/// driver's own linear image lays its rows out otherwise than `bytes_per_row`
|
||||
/// (`WorkCounts::pitched_host_images` counts them). Ask such an image's layout of its memory
|
||||
|
||||
@@ -117,13 +117,15 @@
|
||||
//! **Aliasing**. A 2D texture or array over a buffer is a linear image bound to the buffer's memory
|
||||
//! where the device's linear image has every feature its optimal image has for the texture's uses
|
||||
//! (it lacks nothing, [`linear_lack`]), and the image the device made, at the pitch it chose
|
||||
//! itself, sits exactly on Metal's layout and holds no byte but the texels ([`aliases`]): a
|
||||
//! texture whose rows or slices lie with the buffer's bytes between them is never one
|
||||
//! ([`padding`]), as Vulkan lets an image's layout transitions, and a render pass's load and store
|
||||
//! operations, write every byte of its subresource, and Metal leaves those bytes as the program
|
||||
//! writes them. Otherwise it is a shadow image the encoders copy from and to the buffer
|
||||
//! (`shadow.rs`), whose copies address the buffer's texels alone, which is exact for Metal's
|
||||
//! defined behaviour.
|
||||
//! itself, sits exactly on Metal's layout and holds no byte but the texels ([`aliases`]). A
|
||||
//! texture whose rows or slices lie with the buffer's bytes between them, which Metal leaves as the
|
||||
//! program writes them, is one only where it only reads, under the policy's default
|
||||
//! (`PaddedReadsPolicy::Alias`): its image then holds those bytes too, which Vulkan lets its layout
|
||||
//! transitions write, and it takes one, its first move ([`holding`]). A texture that renders or
|
||||
//! writes over such rows never is one, as a render pass's load and store operations write every
|
||||
//! byte of an attachment's subresource. Otherwise it is a shadow image the encoders copy from and
|
||||
//! to the buffer (`shadow.rs`), whose copies address the buffer's texels alone, which is exact for
|
||||
//! Metal's defined behaviour.
|
||||
|
||||
use super::chroma_pairs::is_four_two_two;
|
||||
use super::copy_plan::block_extent;
|
||||
@@ -131,9 +133,10 @@ use super::image_plan::{compatible, view_formats, ImageFacts, ImagePlan};
|
||||
use super::metal_level::MetalLevel;
|
||||
use super::texture_descriptor::TextureLayout;
|
||||
use super::values::StorageMode;
|
||||
use metal2vulkan::device::PaddedReadsPolicy;
|
||||
use metal2vulkan::error::LinearNeed;
|
||||
use metal2vulkan::metal::format::is_depth_stencil;
|
||||
use metal2vulkan::metal::{PixelFormat, TextureType};
|
||||
use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage};
|
||||
use metal2vulkan::vk::{
|
||||
Format, FormatFeatureFlags2, ImageCreateFlags, ImageUsageFlags, SampleCountFlags,
|
||||
};
|
||||
@@ -699,11 +702,13 @@ pub(super) struct LinearImage {
|
||||
/// memory block), holds exactly Metal's texels in the `room` bytes from there to the end of the
|
||||
/// buffer's memory: the binding is a multiple of the image's alignment, its texels start at the
|
||||
/// binding, its row pitch is Metal's and so is its slice pitch where it has several slices, its
|
||||
/// subresources hold no byte but the texture's texels ([`texels_alone`]), and its memory stays in
|
||||
/// the buffer's. A driver may report a pitch other than the one asked of it (NVIDIA does for
|
||||
/// explicit layouts it does not support), so the image's own report decides.
|
||||
/// subresources hold no byte but what `holds` lets them (the texture's texels, and for
|
||||
/// [`Holds::Padding`] the bytes between its rows), and its memory stays in the buffer's. A driver
|
||||
/// may report a pitch other than the one asked of it (NVIDIA does for explicit layouts it does not
|
||||
/// support), so the image's own report decides.
|
||||
pub(super) fn aliases(
|
||||
layout: &BufferLayout,
|
||||
holds: Holds,
|
||||
memory_offset: u64,
|
||||
room: u64,
|
||||
image: &LinearImage,
|
||||
@@ -713,15 +718,60 @@ pub(super) fn aliases(
|
||||
&& image.offset == 0
|
||||
&& image.row_pitch == layout.row_pitch
|
||||
&& (layout.slices == 1 || image.array_pitch == layout.slice_pitch)
|
||||
&& texels_alone(layout, image.subresource, image.array_pitch)
|
||||
&& holds.fits(layout, image.subresource, image.array_pitch)
|
||||
&& image.size <= room
|
||||
}
|
||||
|
||||
/// Why no image over `layout`'s texels holds them alone, where its rows or slices lie with bytes
|
||||
/// between them that are not texels (the buffer's, which Metal's writes of the texture never
|
||||
/// reach): `None` where they lie one after another, or the texture has one row (one slice).
|
||||
/// `renders`: the texture's usage holds `RenderTarget`, so a render pass may take its image as an
|
||||
/// attachment.
|
||||
/// What an image over a texture's texels in a buffer may hold in its subresources beside the
|
||||
/// texels ([`holding`]).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(super) enum Holds {
|
||||
/// The texels alone: no byte of its subresources is another's ([`texels_alone`]).
|
||||
Texels,
|
||||
/// The texels and the bytes between the texture's rows (and slices), its last row's to its row
|
||||
/// pitch among them, but nothing past them ([`padded_alone`]): a texture that only reads, over
|
||||
/// rows that lie apart, under `PaddedReadsPolicy::Alias`.
|
||||
Padding,
|
||||
}
|
||||
|
||||
impl Holds {
|
||||
/// Whether an image whose subresources take `size` bytes each from the first texel of their
|
||||
/// slice, `array_pitch` apart, holds only what `self` lets it over `layout`'s texels.
|
||||
pub(super) fn fits(self, layout: &BufferLayout, size: u64, array_pitch: u64) -> bool {
|
||||
match self {
|
||||
Holds::Texels => texels_alone(layout, size, array_pitch),
|
||||
Holds::Padding => padded_alone(layout, size, array_pitch),
|
||||
}
|
||||
}
|
||||
|
||||
/// The bytes from the texture's first texel that its image's subresources may reach.
|
||||
pub(super) fn reach(self, layout: &BufferLayout) -> u64 {
|
||||
match self {
|
||||
Holds::Texels => layout.end() - layout.offset,
|
||||
Holds::Padding => rows_end(layout) - layout.offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a texture of Metal `usage` (as Metal reports it: `Unknown` as `ShaderRead |
|
||||
/// ShaderWrite | RenderTarget | PixelFormatView`, `texture_descriptor::texture_usage`) only reads:
|
||||
/// no render pass takes its image as an attachment (`RenderTarget`), and no shader writes it
|
||||
/// (`ShaderWrite`, `ShaderAtomic`, block writes).
|
||||
pub(super) fn only_reads(usage: TextureUsage) -> bool {
|
||||
!usage.intersects(
|
||||
TextureUsage::RENDER_TARGET
|
||||
| TextureUsage::SHADER_WRITE
|
||||
| TextureUsage::SHADER_ATOMIC
|
||||
| TextureUsage::BLOCK_WRITES_ONLY,
|
||||
)
|
||||
}
|
||||
|
||||
/// What an image over `layout`'s texels may hold beside them, for a texture of Metal `usage` (as
|
||||
/// [`only_reads`] takes it) under `policy`, or why no image may hold them: the texels alone
|
||||
/// where its rows (and slices) lie one after another, or it has one row (one slice); else, where
|
||||
/// they lie with bytes between them that are not texels (the buffer's, which Metal's writes of the
|
||||
/// texture never reach), those bytes too where the texture only reads and the policy aliases them
|
||||
/// (`PaddedReadsPolicy::Alias`), and else why not.
|
||||
///
|
||||
/// An image whose rows lie `row_pitch` apart holds those bytes in its subresource
|
||||
/// (`VkSubresourceLayout`: "size includes any extra memory that is required based on rowPitch"),
|
||||
@@ -733,7 +783,9 @@ pub(super) fn aliases(
|
||||
/// read and write accesses on all memory bound to the image subresource range", and "If the old
|
||||
/// layout is VK_IMAGE_LAYOUT_UNDEFINED, the contents of that range may be discarded". No
|
||||
/// operation lets an image be read before it leaves `UNDEFINED` or `PREINITIALIZED`, the layouts
|
||||
/// it is made in, so a texture that only reads takes a transition too.
|
||||
/// it is made in, so a texture that only reads takes a transition too. It takes no other: every
|
||||
/// command uses a runtime image in `GENERAL`, and its barriers are memory barriers, which
|
||||
/// transition no layout (`tracker.rs`).
|
||||
/// - A render pass's attachments (the Render Pass chapter's Load Operations, Store Operations and
|
||||
/// Multisample Resolve Operations): "any writes performed by a load operation (as defined by its
|
||||
/// access masks) to a given attachment may read and write back any memory locations within the
|
||||
@@ -741,10 +793,17 @@ pub(super) fn aliases(
|
||||
///
|
||||
/// A copy and a shader's read or write of the image touch its texels alone (the Memory
|
||||
/// Model: "A memory operation must not affect memory at a memory location not within its set of
|
||||
/// memory locations"). So such a texture is a shadow: a write back of what was read would undo the
|
||||
/// program's write of the bytes meanwhile, which Metal keeps, and lavapipe reads the bytes its
|
||||
/// 4-texel blocks reach past a row's texels and writes them back, a signaling NaN's bits quieted.
|
||||
pub(super) fn padding(layout: &BufferLayout, renders: bool) -> Option<String> {
|
||||
/// memory locations"). So a texture that renders or writes is a shadow: a write back of what was
|
||||
/// read would undo the program's write of the bytes meanwhile, which Metal keeps, and lavapipe
|
||||
/// reads the bytes its 4-texel blocks reach past a row's texels and writes them back, a signaling
|
||||
/// NaN's bits quieted. A texture that only reads meets the bytes at its first move alone, which
|
||||
/// keeps them where the driver's move does (`docs/FAST-PATHS.md`'s known gap, which tight rows
|
||||
/// share): the policy's default aliases them, and `PaddedReadsPolicy::Shadow` keeps the shadow.
|
||||
pub(super) fn holding(
|
||||
layout: &BufferLayout,
|
||||
usage: TextureUsage,
|
||||
policy: PaddedReadsPolicy,
|
||||
) -> Result<Holds, String> {
|
||||
let (rows, slices) = apart(layout);
|
||||
let apart = if rows {
|
||||
format!(
|
||||
@@ -757,23 +816,34 @@ pub(super) fn padding(layout: &BufferLayout, renders: bool) -> Option<String> {
|
||||
layout.slice_pitch, layout.rows, layout.row_pitch
|
||||
)
|
||||
} else {
|
||||
return None;
|
||||
return Ok(Holds::Texels);
|
||||
};
|
||||
let writers = if renders {
|
||||
let reads = only_reads(usage);
|
||||
if reads && policy == PaddedReadsPolicy::Alias {
|
||||
return Ok(Holds::Padding);
|
||||
}
|
||||
let writers = if usage.contains(TextureUsage::RENDER_TARGET) {
|
||||
"its layout transitions read and write, and a render pass's load and store operations \
|
||||
write back"
|
||||
} else {
|
||||
"its layout transitions read and write, its first move from the layout it is made in \
|
||||
among them"
|
||||
};
|
||||
Some(format!(
|
||||
"{apart}: an image over them holds the bytes between them, which Vulkan lets {writers}"
|
||||
let asked = if reads {
|
||||
" (the device's policy asks no image over them for a texture that only reads, \
|
||||
`PaddedReadsPolicy::Shadow`)"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
Err(format!(
|
||||
"{apart}: an image over them holds the bytes between them, which Vulkan lets \
|
||||
{writers}{asked}"
|
||||
))
|
||||
}
|
||||
|
||||
/// Whether a linear image over `layout`'s texels, whose subresources take `size` bytes each from
|
||||
/// the first texel of their slice, `array_pitch` apart, holds no byte but the texture's texels:
|
||||
/// the texels lie with no byte between them ([`padding`]), and its last subresource ends at their
|
||||
/// the texels lie with no byte between them ([`holding`]), and its last subresource ends at their
|
||||
/// last byte or before. A driver may lay rows out past the texture's (lavapipe rounds the height
|
||||
/// up to 4), where the buffer's later bytes lie (a surface's next plane). A byte of the image's
|
||||
/// memory past every subresource is no texel's, and no write through the image reaches it:
|
||||
@@ -786,6 +856,24 @@ pub(super) fn texels_alone(layout: &BufferLayout, size: u64, array_pitch: u64) -
|
||||
apart(layout) == (false, false) && last.saturating_add(size) <= texels
|
||||
}
|
||||
|
||||
/// Whether a linear image over `layout`'s texels, whose subresources take `size` bytes each from
|
||||
/// the first texel of their slice, `array_pitch` apart, holds no byte but the texture's texels and
|
||||
/// the bytes between its rows and slices ([`Holds::Padding`]): its last subresource ends at its last
|
||||
/// row's pitch or before ([`rows_end`]). A byte past that is no row's, and no move of the image may
|
||||
/// reach it, as [`texels_alone`] keeps it for tight rows (lavapipe's rows rounded up to 4).
|
||||
pub(super) fn padded_alone(layout: &BufferLayout, size: u64, array_pitch: u64) -> bool {
|
||||
let last = array_pitch.saturating_mul(layout.slices - 1);
|
||||
last.saturating_add(size) <= rows_end(layout) - layout.offset
|
||||
}
|
||||
|
||||
/// One past `layout`'s last row at its row pitch: the texels' end with the last row's padding.
|
||||
fn rows_end(layout: &BufferLayout) -> u64 {
|
||||
layout
|
||||
.offset
|
||||
.saturating_add(layout.slice_pitch.saturating_mul(layout.slices - 1))
|
||||
.saturating_add(layout.row_pitch.saturating_mul(layout.rows))
|
||||
}
|
||||
|
||||
/// Whether `layout`'s rows, and its slices, lie with bytes between them that are not texels.
|
||||
fn apart(layout: &BufferLayout) -> (bool, bool) {
|
||||
let rows = layout.rows > 1 && layout.row_pitch != layout.row_bytes;
|
||||
|
||||
@@ -4,15 +4,17 @@
|
||||
|
||||
use super::super::image_plan::plan_image;
|
||||
use super::super::linear_plan::{
|
||||
aliases, check_linear_limits, linear_alignment, linear_lack, padding, plan_buffer_texture,
|
||||
BufferFacts, BufferLayout, BufferRefusal, BufferTexture, BufferTextureCall,
|
||||
BufferTextureProblem, LinearImage, LinearLack, Placed, LINEAR_ALIGNMENT,
|
||||
aliases, check_linear_limits, holding, linear_alignment, linear_lack, only_reads,
|
||||
plan_buffer_texture, BufferFacts, BufferLayout, BufferRefusal, BufferTexture,
|
||||
BufferTextureCall, BufferTextureProblem, Holds, LinearImage, LinearLack, Placed,
|
||||
LINEAR_ALIGNMENT,
|
||||
};
|
||||
use super::super::texture_descriptor::{no_texture_alone, TextureDescriptor};
|
||||
use super::super::texture_descriptor::{effective_usage, no_texture_alone, TextureDescriptor};
|
||||
use super::super::values::StorageMode;
|
||||
use super::image_plan::{committed, facts};
|
||||
use super::texture_descriptor::APPLE;
|
||||
use crate::MetalLevel;
|
||||
use metal2vulkan::device::PaddedReadsPolicy;
|
||||
use metal2vulkan::metal::format::direct_format;
|
||||
use metal2vulkan::metal::PixelFormat as P;
|
||||
use metal2vulkan::metal::TextureType;
|
||||
@@ -696,10 +698,11 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
row_pitch: 80,
|
||||
array_pitch: 320,
|
||||
};
|
||||
assert!(aliases(&single, 4096 + 256, 320, &image));
|
||||
assert!(aliases(&single, Holds::Texels, 4096 + 256, 320, &image));
|
||||
// The binding off the image's alignment (RADV's 256 at a 16-byte offset).
|
||||
assert!(!aliases(
|
||||
&single,
|
||||
Holds::Texels,
|
||||
4096 + 272,
|
||||
320,
|
||||
&LinearImage {
|
||||
@@ -710,6 +713,7 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
// The driver's own pitch where another was asked for (NVIDIA's explicit layouts).
|
||||
assert!(!aliases(
|
||||
&single,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
320,
|
||||
&LinearImage {
|
||||
@@ -720,6 +724,7 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
// Texels not at the binding, or memory past the buffer's.
|
||||
assert!(!aliases(
|
||||
&single,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
320,
|
||||
&LinearImage {
|
||||
@@ -727,10 +732,11 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
..image
|
||||
}
|
||||
));
|
||||
assert!(!aliases(&single, 4096, 319, &image));
|
||||
assert!(!aliases(&single, Holds::Texels, 4096, 319, &image));
|
||||
// Memory past the subresource, within the buffer's: no write through the image reaches it.
|
||||
assert!(aliases(
|
||||
&single,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
4096,
|
||||
&LinearImage {
|
||||
@@ -740,9 +746,10 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
));
|
||||
// A subresource past the texels (lavapipe's rows rounded up to 4, of a texture of 3).
|
||||
let three = BufferLayout { rows: 3, ..single };
|
||||
assert!(!aliases(&three, 4096, 320, &image));
|
||||
assert!(!aliases(&three, Holds::Texels, 4096, 320, &image));
|
||||
assert!(aliases(
|
||||
&three,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
320,
|
||||
&LinearImage {
|
||||
@@ -755,18 +762,45 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
row_bytes: 68,
|
||||
..single
|
||||
};
|
||||
assert!(!aliases(&padded, 4096, 320, &image));
|
||||
assert!(padding(&padded, true).is_some());
|
||||
assert!(padding(&single, true).is_none());
|
||||
assert!(!aliases(&padded, Holds::Texels, 4096, 320, &image));
|
||||
let renders = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ;
|
||||
let alias = PaddedReadsPolicy::Alias;
|
||||
assert!(holding(&padded, renders, alias).is_err());
|
||||
assert_eq!(holding(&single, renders, alias), Ok(Holds::Texels));
|
||||
// A texture that only reads may hold the bytes between its rows, its last row's to its pitch
|
||||
// among them, but none past them.
|
||||
assert!(aliases(&padded, Holds::Padding, 4096, 320, &image));
|
||||
assert!(!aliases(
|
||||
&padded,
|
||||
Holds::Padding,
|
||||
4096,
|
||||
400,
|
||||
&LinearImage {
|
||||
size: 400,
|
||||
subresource: 400,
|
||||
..image
|
||||
}
|
||||
));
|
||||
assert!(!aliases(
|
||||
&padded,
|
||||
Holds::Padding,
|
||||
4096,
|
||||
320,
|
||||
&LinearImage {
|
||||
row_pitch: 96,
|
||||
..image
|
||||
}
|
||||
));
|
||||
// One row has nothing between rows, but its pitch's padding past the texels.
|
||||
let row = BufferLayout {
|
||||
rows: 1,
|
||||
slice_pitch: 80,
|
||||
..padded
|
||||
};
|
||||
assert!(padding(&row, true).is_none());
|
||||
assert_eq!(holding(&row, renders, alias), Ok(Holds::Texels));
|
||||
assert!(!aliases(
|
||||
&row,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
80,
|
||||
&LinearImage {
|
||||
@@ -777,6 +811,7 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
));
|
||||
assert!(aliases(
|
||||
&row,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
80,
|
||||
&LinearImage {
|
||||
@@ -791,9 +826,10 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
..single
|
||||
};
|
||||
let stacked = LinearImage { size: 960, ..image };
|
||||
assert!(aliases(&slices, 4096, 960, &stacked));
|
||||
assert!(aliases(&slices, Holds::Texels, 4096, 960, &stacked));
|
||||
assert!(!aliases(
|
||||
&slices,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
960,
|
||||
&LinearImage {
|
||||
@@ -806,9 +842,25 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
slice_pitch: 384,
|
||||
..slices
|
||||
};
|
||||
assert!(padding(&apart, true).is_some());
|
||||
assert!(holding(&apart, renders, alias).is_err());
|
||||
assert_eq!(
|
||||
holding(&apart, TextureUsage::SHADER_READ, alias),
|
||||
Ok(Holds::Padding)
|
||||
);
|
||||
assert!(aliases(
|
||||
&apart,
|
||||
Holds::Padding,
|
||||
4096,
|
||||
1088,
|
||||
&LinearImage {
|
||||
size: 1088,
|
||||
array_pitch: 384,
|
||||
..image
|
||||
}
|
||||
));
|
||||
assert!(!aliases(
|
||||
&apart,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
1088,
|
||||
&LinearImage {
|
||||
@@ -820,6 +872,7 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
// A driver that reports the array's whole bytes as its first subresource's.
|
||||
assert!(!aliases(
|
||||
&slices,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
960,
|
||||
&LinearImage {
|
||||
@@ -830,6 +883,7 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
// A single slice ignores the array pitch a driver reports.
|
||||
assert!(aliases(
|
||||
&single,
|
||||
Holds::Texels,
|
||||
4096,
|
||||
320,
|
||||
&LinearImage {
|
||||
@@ -840,8 +894,11 @@ fn a_linear_image_aliases_only_metals_layout() {
|
||||
}
|
||||
|
||||
/// A texture over padded rows is a shadow for the operations Vulkan lets write the padding: a
|
||||
/// texture that only reads names its image's layout transitions (its first move among them), not a
|
||||
/// render pass, which no image of its takes; a render target names both.
|
||||
/// render target names its image's layout transitions (its first move among them) and a render
|
||||
/// pass's load and store operations; a texture a shader writes names its layout transitions alone,
|
||||
/// as one that only reads does under `PaddedReadsPolicy::Shadow`, which says the policy asked it.
|
||||
/// A texture that only reads, under `PaddedReadsPolicy::Alias`, may hold the bytes between its
|
||||
/// rows: its usage as Metal reports it decides, `Unknown` a render target's.
|
||||
#[test]
|
||||
fn a_padded_texture_s_shadow_names_what_may_write_its_padding() {
|
||||
let padded = BufferLayout {
|
||||
@@ -852,21 +909,50 @@ fn a_padded_texture_s_shadow_names_what_may_write_its_padding() {
|
||||
rows: 4,
|
||||
slices: 1,
|
||||
};
|
||||
let reads = padding(&padded, false).unwrap();
|
||||
let (alias, shadow) = (PaddedReadsPolicy::Alias, PaddedReadsPolicy::Shadow);
|
||||
let transitions = "its rows lie 80 bytes apart, 68 bytes of texels each: an image over them \
|
||||
holds the bytes between them, which Vulkan lets its layout transitions \
|
||||
read and write, its first move from the layout it is made in among them";
|
||||
let reads = holding(&padded, TextureUsage::SHADER_READ, shadow).unwrap_err();
|
||||
assert_eq!(
|
||||
reads,
|
||||
"its rows lie 80 bytes apart, 68 bytes of texels each: an image over them holds the \
|
||||
bytes between them, which Vulkan lets its layout transitions read and write, its first \
|
||||
move from the layout it is made in among them"
|
||||
format!(
|
||||
"{transitions} (the device's policy asks no image over them for a texture that only \
|
||||
reads, `PaddedReadsPolicy::Shadow`)"
|
||||
)
|
||||
);
|
||||
assert!(!reads.contains("render pass"), "{reads}");
|
||||
let renders = padding(&padded, true).unwrap();
|
||||
assert_eq!(
|
||||
renders,
|
||||
"its rows lie 80 bytes apart, 68 bytes of texels each: an image over them holds the \
|
||||
bytes between them, which Vulkan lets its layout transitions read and write, and a render \
|
||||
pass's load and store operations write back"
|
||||
);
|
||||
let writes = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE;
|
||||
for policy in [alias, shadow] {
|
||||
assert_eq!(
|
||||
holding(&padded, writes, policy),
|
||||
Err(transitions.to_owned())
|
||||
);
|
||||
let renders = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ;
|
||||
assert_eq!(
|
||||
holding(&padded, renders, policy).unwrap_err(),
|
||||
"its rows lie 80 bytes apart, 68 bytes of texels each: an image over them holds the \
|
||||
bytes between them, which Vulkan lets its layout transitions read and write, and a \
|
||||
render pass's load and store operations write back"
|
||||
);
|
||||
}
|
||||
for usage in [
|
||||
TextureUsage::SHADER_READ,
|
||||
TextureUsage::SHADER_READ | TextureUsage::PIXEL_FORMAT_VIEW,
|
||||
] {
|
||||
assert!(only_reads(usage), "{usage:?}");
|
||||
assert_eq!(holding(&padded, usage, alias), Ok(Holds::Padding));
|
||||
}
|
||||
for usage in [
|
||||
TextureUsage::RENDER_TARGET,
|
||||
TextureUsage::SHADER_WRITE,
|
||||
TextureUsage::SHADER_ATOMIC,
|
||||
TextureUsage::BLOCK_WRITES_ONLY,
|
||||
effective_usage(TextureUsage::UNKNOWN),
|
||||
] {
|
||||
assert!(!only_reads(usage), "{usage:?}");
|
||||
assert!(holding(&padded, usage, alias).is_err(), "{usage:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A linear image serves a texture where its tiling has every feature the optimal one has for
|
||||
|
||||
@@ -83,7 +83,7 @@ use super::image_plan::{
|
||||
ImagePlan, ImageRefusal,
|
||||
};
|
||||
use super::linear_plan::{
|
||||
aliases, check_linear_limits, linear_lack, padding, texels_alone, BufferLayout, LinearImage,
|
||||
aliases, check_linear_limits, holding, linear_lack, BufferLayout, Holds, LinearImage,
|
||||
LinearLack,
|
||||
};
|
||||
use super::memory::{MemoryClass, Placement};
|
||||
@@ -741,8 +741,9 @@ pub(super) enum AliasKind {
|
||||
/// ([`Device::alias_image`]); over pages imported as dma-bufs, a `DRM_FORMAT_MOD_LINEAR` image
|
||||
/// bound to a dedicated import of a dma-buf of its own pages
|
||||
/// ([`Device::dma_buf_alias_image`]). A rebind makes the kind its new pages take, over the
|
||||
/// same texels (`layout`, whose offset is in the buffer the texture was made over).
|
||||
Linear { layout: BufferLayout },
|
||||
/// same texels (`layout`, whose offset is in the buffer the texture was made over), holding
|
||||
/// what the first held beside them (`holds`).
|
||||
Linear { layout: BufferLayout, holds: Holds },
|
||||
/// A Metal texture over the import's `MTLBuffer` (`metal_texture.rs`).
|
||||
Metal(MetalOver),
|
||||
}
|
||||
@@ -1958,6 +1959,10 @@ impl Device {
|
||||
let wider = undeclared_usage(plan.clone(), layout, usage, false, &facts, |_, wider| {
|
||||
Ok(wider)
|
||||
})?;
|
||||
// What an image over the texels may hold beside them: the bytes between padded rows too
|
||||
// where the texture only reads, by the policy (`linear_plan::holding`); else why none may.
|
||||
let policy = self.compile_device().policy().padded_reads;
|
||||
let holds = holding(&texels.layout, usage, policy);
|
||||
// Over bytes detached from their pages (`detach.rs`) no image aliases them: the texture
|
||||
// is their shadow, which presents a stand-in until they lie in pages again.
|
||||
let detached = texels.buffer.detached();
|
||||
@@ -1976,17 +1981,19 @@ impl Device {
|
||||
} else {
|
||||
&plans[1..]
|
||||
};
|
||||
match self.dma_buf_alias_image(plans, layout, descriptor, &texels, &facts)? {
|
||||
let over = (&*texels, &holds);
|
||||
match self.dma_buf_alias_image(plans, layout, descriptor, over, &facts)? {
|
||||
Ok(image) => return Ok(Storage::Alias { image, texels }),
|
||||
Err(why) => why,
|
||||
}
|
||||
} else {
|
||||
let over = (&*texels, &holds);
|
||||
if wider != plan {
|
||||
if let Ok(image) = self.alias_image(wider, layout, descriptor, &texels, &facts)? {
|
||||
if let Ok(image) = self.alias_image(wider, layout, descriptor, over, &facts)? {
|
||||
return Ok(Storage::Alias { image, texels });
|
||||
}
|
||||
}
|
||||
match self.alias_image(plan.clone(), layout, descriptor, &texels, &facts)? {
|
||||
match self.alias_image(plan.clone(), layout, descriptor, over, &facts)? {
|
||||
Ok(image) => return Ok(Storage::Alias { image, texels }),
|
||||
Err(why) => why,
|
||||
}
|
||||
@@ -2202,13 +2209,14 @@ impl Device {
|
||||
/// their `MTLBuffer`s it is instead made of a Metal texture over the import's `MTLBuffer`
|
||||
/// ([`Device::metal_alias_image`]), which renders where the driver's linear images do not.
|
||||
/// Pages the runtime imported as dma-buf memory take [`Device::dma_buf_alias_image`]'s image
|
||||
/// instead. The image's hazard tracking is the buffer's.
|
||||
/// instead. The image's hazard tracking is the buffer's. `holds`: what the image may hold
|
||||
/// beside the texels (`linear_plan::holding`), or why no image may hold them.
|
||||
fn alias_image(
|
||||
&self,
|
||||
plan: ImagePlan,
|
||||
layout: &TextureLayout,
|
||||
descriptor: &TextureDescriptor,
|
||||
texels: &Texels,
|
||||
(texels, holds): (&Texels, &Result<Holds, String>),
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Aliased, Error> {
|
||||
let host = match texels.buffer.caller_memory() {
|
||||
@@ -2225,17 +2233,17 @@ impl Device {
|
||||
if host && self.exports_metal() {
|
||||
return self.metal_alias_image(plan, layout, descriptor, texels);
|
||||
}
|
||||
let renders = descriptor.usage.contains(TextureUsage::RENDER_TARGET);
|
||||
if let Some(why) = padding(&texels.layout, renders) {
|
||||
return Ok(Err(why));
|
||||
}
|
||||
let holds = match holds {
|
||||
Ok(holds) => *holds,
|
||||
Err(why) => return Ok(Err(why.clone())),
|
||||
};
|
||||
let who = if host {
|
||||
"the buffer is a no-copy buffer, and the device"
|
||||
} else {
|
||||
"the device"
|
||||
};
|
||||
let made = if host {
|
||||
self.host_alias_unbound(&plan, &texels.layout, facts)?
|
||||
self.host_alias_unbound(&plan, &texels.layout, holds, facts)?
|
||||
} else if let Some(LinearLack { format, features }) = linear_lack(&plan, facts) {
|
||||
Err(
|
||||
LinearRefusal::Need(LinearNeed::Features { format, features })
|
||||
@@ -2271,7 +2279,7 @@ impl Device {
|
||||
row_pitch: report.row_pitch,
|
||||
array_pitch: report.array_pitch,
|
||||
};
|
||||
let why = if !aliases(&texels.layout, memory_offset, room, &image) {
|
||||
let why = if !aliases(&texels.layout, holds, memory_offset, room, &image) {
|
||||
Some(format!(
|
||||
"{who}'s linear image of the texture lays its texels out otherwise than Metal \
|
||||
at the texels' offset and row pitch, or holds other bytes than its texels \
|
||||
@@ -2344,6 +2352,7 @@ impl Device {
|
||||
texture_type: layout.texture_type,
|
||||
kind: AliasKind::Linear {
|
||||
layout: texels.layout,
|
||||
holds,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -2440,14 +2449,15 @@ impl Device {
|
||||
/// key), as every image aliasing a buffer's bytes is: a write through the one orders before a
|
||||
/// read through the other in a command buffer, by the tracker's memory barriers. Where the
|
||||
/// device makes none, why, the fallback counted (`WorkCounts::dma_buf_image_fallbacks`): the
|
||||
/// texture takes the way a texture over memory no image aliases takes.
|
||||
/// texture takes the way a texture over memory no image aliases takes. `holds`: what the image
|
||||
/// may hold beside the texels (`linear_plan::holding`), or why no image may hold them.
|
||||
#[cfg(unix)]
|
||||
fn dma_buf_alias_image(
|
||||
&self,
|
||||
plans: &[&ImagePlan],
|
||||
layout: &TextureLayout,
|
||||
descriptor: &TextureDescriptor,
|
||||
texels: &Texels,
|
||||
(texels, holds): (&Texels, &Result<Holds, String>),
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Aliased, Error> {
|
||||
let pages = texels.buffer.host_pages();
|
||||
@@ -2457,13 +2467,16 @@ impl Device {
|
||||
"a texture over dma-buf pages the buffer does not lie in",
|
||||
));
|
||||
};
|
||||
// Rows (or slices) with the buffer's bytes between them take no image (`linear_plan.rs`):
|
||||
// the pages' source is not asked.
|
||||
let renders = descriptor.usage.contains(TextureUsage::RENDER_TARGET);
|
||||
if let Some(why) = padding(&texels.layout, renders) {
|
||||
self.shared().counts.dma_buf_image_fell_back();
|
||||
return Ok(Err(why));
|
||||
}
|
||||
// Rows (or slices) with the buffer's bytes between them take no image but that of a
|
||||
// texture that only reads, by the policy (`linear_plan::holding`): else the pages' source
|
||||
// is not asked.
|
||||
let holds = match holds {
|
||||
Ok(holds) => *holds,
|
||||
Err(why) => {
|
||||
self.shared().counts.dma_buf_image_fell_back();
|
||||
return Ok(Err(why.clone()));
|
||||
}
|
||||
};
|
||||
let base = texels.buffer.pages_base()?;
|
||||
let (_, buffer_offset, _) = texels.buffer.memory();
|
||||
let from_base = buffer_offset + texels.layout.offset - base;
|
||||
@@ -2473,7 +2486,7 @@ impl Device {
|
||||
at: start + from_base,
|
||||
row_pitch: texels.layout.row_pitch,
|
||||
slice_pitch: texels.layout.slice_pitch,
|
||||
alone: Some(texels.layout),
|
||||
alone: Some((texels.layout, holds)),
|
||||
};
|
||||
let made = match self.dma_buf_image(plans, facts, &place)? {
|
||||
Ok(made) => made,
|
||||
@@ -2506,6 +2519,7 @@ impl Device {
|
||||
texture_type: layout.texture_type,
|
||||
kind: AliasKind::Linear {
|
||||
layout: texels.layout,
|
||||
holds,
|
||||
},
|
||||
});
|
||||
Ok(Ok(image))
|
||||
@@ -2559,7 +2573,7 @@ impl Device {
|
||||
_plans: &[&ImagePlan],
|
||||
_layout: &TextureLayout,
|
||||
_descriptor: &TextureDescriptor,
|
||||
_texels: &Texels,
|
||||
_over: (&Texels, &Result<Holds, String>),
|
||||
_facts: &ImageFacts<'_>,
|
||||
) -> Result<Aliased, Error> {
|
||||
Err(internal("a texture over dma-buf pages on a system of none"))
|
||||
@@ -2718,7 +2732,7 @@ impl Device {
|
||||
|
||||
/// The unbound image of `plan` made for host allocations whose texels lie at Metal's `layout`
|
||||
/// in a no-copy buffer's pages, its rows `layout.row_pitch` apart (and slices
|
||||
/// `layout.slice_pitch`), holding no byte but them (`linear_plan::texels_alone`): the driver's
|
||||
/// `layout.slice_pitch`), holding no byte but what `holds` lets it (`linear_plan::Holds`): the driver's
|
||||
/// linear image ([`Device::host_linear_image`]) where it lays them out so, its subresource at
|
||||
/// offset 0; else, where the device enables `VK_EXT_image_drm_format_modifier`, a
|
||||
/// `DRM_FORMAT_MOD_LINEAR` image whose one plane the runtime lays out at those pitches
|
||||
@@ -2729,13 +2743,14 @@ impl Device {
|
||||
&self,
|
||||
plan: &ImagePlan,
|
||||
layout: &BufferLayout,
|
||||
holds: Holds,
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Result<LinearMade, String>, Error> {
|
||||
let lies = |report: &vk::SubresourceLayout| {
|
||||
report.offset == 0
|
||||
&& report.row_pitch == layout.row_pitch
|
||||
&& (layout.slices == 1 || report.array_pitch == layout.slice_pitch)
|
||||
&& texels_alone(layout, report.size, report.array_pitch)
|
||||
&& holds.fits(layout, report.size, report.array_pitch)
|
||||
};
|
||||
let made = match linear_lack(plan, facts) {
|
||||
Some(LinearLack { format, features }) => {
|
||||
@@ -2763,15 +2778,16 @@ impl Device {
|
||||
Err(refusal) => refusal.describe(plan, true),
|
||||
};
|
||||
Ok(self
|
||||
.host_pitched_image(plan, layout, facts)?
|
||||
.host_pitched_image(plan, layout, holds, facts)?
|
||||
.map_err(|pitched| format!("{linear}; and {pitched}")))
|
||||
}
|
||||
|
||||
/// A `DRM_FORMAT_MOD_LINEAR` image of `plan` made for host allocations, unbound, whose one
|
||||
/// plane lies at offset 0 with rows `texels.row_pitch` apart (and slices `texels.slice_pitch`,
|
||||
/// for a plan of several layers), holding no byte but the texels: a texture over a no-copy
|
||||
/// buffer's host pages, its rows one after another, where the driver's own linear image lays
|
||||
/// them out otherwise (further apart, its row pitch rounded up to an alignment of its own).
|
||||
/// for a plan of several layers), holding no byte but what `holds` lets it: a texture over a
|
||||
/// no-copy buffer's host pages, its rows one after another (or, for a texture that only reads,
|
||||
/// apart: `linear_plan::Holds::Padding`), where the driver's own linear image lays them out
|
||||
/// otherwise (further apart, its row pitch rounded up to an alignment of its own).
|
||||
/// Its memory requirements and its plane's layout as the driver reports
|
||||
/// them, starting `UNDEFINED` as Vulkan has an image of external memory made. Why not where
|
||||
/// the device does not enable the extension, makes no such image for host allocations
|
||||
@@ -2785,6 +2801,7 @@ impl Device {
|
||||
&self,
|
||||
plan: &ImagePlan,
|
||||
texels: &BufferLayout,
|
||||
holds: Holds,
|
||||
facts: &ImageFacts<'_>,
|
||||
) -> Result<Result<LinearMade, String>, Error> {
|
||||
use crate::dma_buf::{memory_plane_0, ModifierMemory, DRM_FORMAT_MOD_LINEAR};
|
||||
@@ -2880,12 +2897,12 @@ impl Device {
|
||||
{row_pitch} and slices {array_pitch} apart",
|
||||
report.offset, report.row_pitch, report.array_pitch
|
||||
))
|
||||
} else if !texels_alone(texels, report.size, report.array_pitch) {
|
||||
} else if !holds.fits(texels, report.size, report.array_pitch) {
|
||||
Some(format!(
|
||||
"the driver's DRM_FORMAT_MOD_LINEAR plane for host allocations takes {} bytes, \
|
||||
past the texels' {}",
|
||||
report.size,
|
||||
texels.end() - texels.offset
|
||||
holds.reach(texels)
|
||||
))
|
||||
} else {
|
||||
None
|
||||
@@ -2910,6 +2927,7 @@ impl Device {
|
||||
&self,
|
||||
_plan: &ImagePlan,
|
||||
_texels: &BufferLayout,
|
||||
_holds: Holds,
|
||||
_facts: &ImageFacts<'_>,
|
||||
) -> Result<Result<LinearMade, String>, Error> {
|
||||
Ok(Err(
|
||||
@@ -2964,8 +2982,8 @@ impl Device {
|
||||
swaps.push(ImageSwap::acquired(image, objects, pages, family));
|
||||
continue;
|
||||
}
|
||||
let layout = match &watch.kind {
|
||||
AliasKind::Linear { layout } => *layout,
|
||||
let (layout, holds) = match &watch.kind {
|
||||
AliasKind::Linear { layout, holds } => (*layout, *holds),
|
||||
AliasKind::Metal(over) => {
|
||||
let made =
|
||||
self.metal_image(image.plan(), over, watch.texture_type, memory, at)?;
|
||||
@@ -2984,8 +3002,8 @@ impl Device {
|
||||
};
|
||||
// Its rows (and slices) lie as the old image's did: the texture's, in the driver's
|
||||
// linear image where it lays them out so, else in a `DRM_FORMAT_MOD_LINEAR` image
|
||||
// at those pitches; either holding no byte but the texels.
|
||||
let made = self.host_alias_unbound(image.plan(), &layout, &facts)?;
|
||||
// at those pitches; either holding no byte but what the old image held.
|
||||
let made = self.host_alias_unbound(image.plan(), &layout, holds, &facts)?;
|
||||
let Ok(LinearMade {
|
||||
raw,
|
||||
requirements,
|
||||
@@ -3060,7 +3078,7 @@ impl Device {
|
||||
continue;
|
||||
};
|
||||
// A Metal texture's rebind to dma-buf pages is refused as the swaps are made.
|
||||
let AliasKind::Linear { layout } = watch.kind else {
|
||||
let AliasKind::Linear { layout, holds } = watch.kind else {
|
||||
continue;
|
||||
};
|
||||
let texels = crate::dma_buf::DmaBufTexels {
|
||||
@@ -3069,7 +3087,7 @@ impl Device {
|
||||
at: pointer.as_ptr() as u64 + watch.from_base,
|
||||
row_pitch: layout.row_pitch,
|
||||
slice_pitch: layout.slice_pitch,
|
||||
alone: Some(layout),
|
||||
alone: Some((layout, holds)),
|
||||
};
|
||||
let Ok((_, made)) = self.dma_buf_image(&[image.plan()], &facts, &texels)? else {
|
||||
return Err(Error::NotImplemented(RuntimeGap::RebindTextures));
|
||||
|
||||
@@ -1 +1 @@
|
||||
d92b3692f9ec6dd09aa276901b3e5e2ca89520a9fe474835a57c7a22aeb4b85e
|
||||
edc97e709c2605eaa13ac8696ea119fb9b727243a276a679d0b3288ed5b760b3
|
||||
@@ -11,10 +11,11 @@
|
||||
//! Whatever form the device gives the texture (its own linear image, a `DRM_FORMAT_MOD_LINEAR`
|
||||
//! image laid out at Metal's row pitch, or a shadow), every step reads and writes Metal's bytes at
|
||||
//! Metal's places, and no write reaches the bytes between the rows or past the last. A texture
|
||||
//! whose rows lie with bytes between them is never a linear image over the pages (Vulkan lets an
|
||||
//! image's layout transitions, and a render pass's load and store operations, write every byte of
|
||||
//! its subresource), but on a driver that runs on Metal, whose image is a Metal texture over the
|
||||
//! buffer:
|
||||
//! that renders or writes, whose rows lie with bytes between them, is never a linear image over
|
||||
//! the pages (Vulkan lets a render pass's load and store operations write every byte of an
|
||||
//! attachment's subresource), but on a driver that runs on Metal, whose image is a Metal texture
|
||||
//! over the buffer; nor is one that only reads under the lane's policy (`exact_answers`,
|
||||
//! `PaddedReadsPolicy::Shadow`). The steps:
|
||||
//!
|
||||
//! - **reads**: a blit out, `get_bytes`, a fragment function's `read`, and its `sample` through a
|
||||
//! nearest sampler give the caller's texels; a linear sampler gives what it gives over a private
|
||||
@@ -36,15 +37,30 @@
|
||||
//! an ordinary buffer's padded rows: a texture that only reads names its layout transitions, a
|
||||
//! render target a render pass's load and store operations too.
|
||||
//!
|
||||
//! Under the policy's default (`PaddedReadsPolicy::Alias`), a texture that only reads (`ShaderRead`
|
||||
//! usage) is an image over its padded rows where the device lays one at their pitch.
|
||||
//! [`a_texture_that_only_reads_keeps_every_byte_of_its_pages`] makes one over each layout and
|
||||
//! reads it first through its image, before anything else touches the pages: its image's first
|
||||
//! move keeps every byte only where the driver's does (docs/FAST-PATHS.md's known gap), and a
|
||||
//! driver that does not fails here, naming the bytes. Then it samples, blits out, reads the
|
||||
//! caller's later bytes (the bytes between the rows rewritten too), blits a buffer's box and a
|
||||
//! private texture's box in and replaces a box: after each, every byte of the pages is checked.
|
||||
//! [`a_padded_texture_that_only_reads_copies_no_shadow_by_default`] counts its copies
|
||||
//! (`WorkCounts::shadow_copies`: none across its uses, and a shadow's under
|
||||
//! `PaddedReadsPolicy::Shadow`), and
|
||||
//! [`a_padded_texture_that_renders_or_writes_is_a_shadow_under_either_policy`] keeps a render
|
||||
//! target's, a written texture's and an `Unknown` usage's shadow.
|
||||
//!
|
||||
//! Printed per layout (`PITCHED-SURFACE`): the form, the images the making counted
|
||||
//! (`WorkCounts::pitched_host_images`, `shadowed_textures`), and a shadow's reason.
|
||||
|
||||
use super::host_memory::{counting, no_copy, not_importable, Mapping, GUEST_PAGE};
|
||||
use super::no_copy_textures::{blending, floats, staged};
|
||||
use super::{validated_device, Messages, ScratchCache, WAIT};
|
||||
use super::{validated_device, validated_device_with, Messages, ScratchCache, WAIT};
|
||||
use crate::air_library::AirLibrary;
|
||||
use crate::gpu::TEST_DEVICE;
|
||||
use metal2vulkan::bind::SamplerDescriptor;
|
||||
use metal2vulkan::device::PaddedReadsPolicy;
|
||||
use metal2vulkan::metal::{PixelFormat, PrimitiveType, SamplerMinMagFilter, TextureUsage};
|
||||
use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource};
|
||||
use metal2vulkan::vk::DriverId;
|
||||
@@ -301,7 +317,7 @@ fn private_with(queue: &CommandQueue, layout: &Layout, texels: &[u8]) -> Texture
|
||||
|
||||
/// The owned fixture's `tob_rect` over the whole target with `fragment` (`tob_read` or
|
||||
/// `tob_sample`), into one attachment of `pf`.
|
||||
fn reading(device: &Device, pf: PixelFormat, fragment: &str) -> RenderPipelineState {
|
||||
pub(super) fn reading(device: &Device, pf: PixelFormat, fragment: &str) -> RenderPipelineState {
|
||||
let library = device
|
||||
.new_library_with_air(&llvm_assemble(&engine_dir().join("tob_renders.ll")).unwrap())
|
||||
.unwrap();
|
||||
@@ -395,7 +411,7 @@ fn blend_pass(
|
||||
}
|
||||
|
||||
/// A sampler of `filter`, clamped to the edge.
|
||||
fn sampler(device: &Device, filter: SamplerMinMagFilter) -> SamplerState {
|
||||
pub(super) fn sampler(device: &Device, filter: SamplerMinMagFilter) -> SamplerState {
|
||||
let mut d = SamplerDescriptor::new();
|
||||
d.min_filter = filter;
|
||||
d.mag_filter = filter;
|
||||
@@ -412,8 +428,14 @@ fn on_metal(device: &Device) -> bool {
|
||||
/// `usage`: the pages hold a pattern of their own, the texels `texels_of(.., 1)` laid at the rows;
|
||||
/// with the buffer, the mapping and the pages as written. `None` where the device imports no host
|
||||
/// memory. Its form is checked against the making's counts: a shadow counted where it is not
|
||||
/// aliased, and never a linear image over padded rows off Metal.
|
||||
fn surface(device: &Device, layout: &Layout, usage: TextureUsage) -> Option<Surface> {
|
||||
/// aliased, and never a linear image over padded rows off Metal but where `padded_alias` (a
|
||||
/// texture that only reads, under `PaddedReadsPolicy::Alias`).
|
||||
fn surface(
|
||||
device: &Device,
|
||||
layout: &Layout,
|
||||
usage: TextureUsage,
|
||||
padded_alias: bool,
|
||||
) -> Option<Surface> {
|
||||
let len = layout.len().next_multiple_of(GUEST_PAGE);
|
||||
let mapping = Mapping::anonymous(len);
|
||||
// The pages: texels a blend keeps finite, and the bytes between the rows a pattern of
|
||||
@@ -462,7 +484,7 @@ fn surface(device: &Device, layout: &Layout, usage: TextureUsage) -> Option<Surf
|
||||
"{what}: aliased {aliased}, but {shadowed} shadows counted"
|
||||
);
|
||||
assert!(
|
||||
!(aliased && layout.padded()) || on_metal(device),
|
||||
!(aliased && layout.padded()) || on_metal(device) || padded_alias,
|
||||
"{what}: rows with bytes between them aliased by a linear image (pitched images \
|
||||
{pitched})"
|
||||
);
|
||||
@@ -550,7 +572,7 @@ fn reads_writes_and_renders_as_metal(layout: Layout) {
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let texel = layout.texel;
|
||||
let usage = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ;
|
||||
let Some(surface) = surface(&device, &layout, usage) else {
|
||||
let Some(surface) = surface(&device, &layout, usage, false) else {
|
||||
return;
|
||||
};
|
||||
let (texture, what) = (&surface.texture, &surface.what);
|
||||
@@ -723,7 +745,7 @@ fn first_use_reads_the_bytes(layout: Layout) {
|
||||
let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap();
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let usage = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ;
|
||||
let Some(surface) = surface(&device, &layout, usage) else {
|
||||
let Some(surface) = surface(&device, &layout, usage, false) else {
|
||||
return;
|
||||
};
|
||||
let texels = rows(&layout, &surface.pages);
|
||||
@@ -979,7 +1001,7 @@ fn writes_as_metal(layout: Layout) {
|
||||
let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap();
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE;
|
||||
let Some(surface) = surface(&device, &layout, usage) else {
|
||||
let Some(surface) = surface(&device, &layout, usage, false) else {
|
||||
return;
|
||||
};
|
||||
let mut expected = surface.pages.clone();
|
||||
@@ -1041,3 +1063,429 @@ fn a_fragment_function_s_writes_leave_the_bytes_between_rows() {
|
||||
writes_as_metal(LAYOUTS[index]);
|
||||
}
|
||||
}
|
||||
|
||||
/// A lane device whose policy takes `padded_reads` (the lane's own takes
|
||||
/// `PaddedReadsPolicy::Shadow`, with `exact_answers`).
|
||||
fn device_with(
|
||||
messages: &Messages,
|
||||
cache: &ScratchCache,
|
||||
padded_reads: PaddedReadsPolicy,
|
||||
) -> Device {
|
||||
validated_device_with(TEST_DEVICE, messages, cache.path(), |options| {
|
||||
options.policy.padded_reads = padded_reads;
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// `boxed` (rows of `bw` texels) laid into `expected` at texel (`bx`, `by`) of `layout`'s rows.
|
||||
fn lay_box(layout: &Layout, expected: &mut [u8], (bx, by, bw): (u64, u64, u64), boxed: &[u8]) {
|
||||
for (y, row) in boxed.chunks((bw * layout.texel) as usize).enumerate() {
|
||||
let at = ((by + y as u64) * layout.bpr + bx * layout.texel) as usize;
|
||||
expected[at..at + row.len()].copy_from_slice(row);
|
||||
}
|
||||
}
|
||||
|
||||
/// A texture of `layout` that only reads (`ShaderRead` usage), over a no-copy buffer, on a device
|
||||
/// of the policy's default (`PaddedReadsPolicy::Alias`): its first use reads it through its image
|
||||
/// (a fragment function's `read`) before any command reads or writes the pages another way, and
|
||||
/// must read the pages' texels and leave every byte of the pages, the bytes between the rows
|
||||
/// among them, as it was: the image's first move keeps them only as far as the driver's does
|
||||
/// (docs/FAST-PATHS.md's known gap). Then its reads (a nearest and a linear sample, `get_bytes`,
|
||||
/// a blit out), the caller's later bytes (texels and the bytes between the rows alike) read by a
|
||||
/// sample and a blit, and its writes that Metal makes of any texture (a buffer's box blitted in
|
||||
/// at an odd origin, `replace_region` of a box, a private texture's box blitted in): each reads
|
||||
/// Metal's texels, and after each every byte of the pages is the program's. Whether it aliased,
|
||||
/// and whether the device runs on Metal; `None` where it imports no host memory.
|
||||
fn reads_and_blits_as_metal(layout: Layout) -> Option<(bool, bool)> {
|
||||
let cache = ScratchCache::new().unwrap();
|
||||
let messages = Messages::default();
|
||||
let made = {
|
||||
let device = device_with(&messages, &cache, PaddedReadsPolicy::Alias);
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let texel = layout.texel;
|
||||
let surface = surface(&device, &layout, TextureUsage::SHADER_READ, true)?;
|
||||
let (texture, what) = (&surface.texture, &surface.what);
|
||||
let mut expected = surface.pages.clone();
|
||||
let check = |step: &str, expected: &[u8]| surface.check(&layout, step, expected);
|
||||
let read = |step: &str, ours: &[u8], theirs: &[u8]| {
|
||||
let (count, first) = differing(ours, theirs, texel);
|
||||
assert!(
|
||||
count == 0,
|
||||
"{what}, {step}: {count} texels differ, the first at texel {first:?}"
|
||||
);
|
||||
};
|
||||
|
||||
// The first use, through the image, before anything else touches the pages.
|
||||
let texels = rows(&layout, &expected);
|
||||
let reads = reading(&device, layout.pf, "tob_read");
|
||||
read(
|
||||
"its first use, a fragment function's read",
|
||||
&drawn(&queue, &layout, &reads, texture, None),
|
||||
&texels,
|
||||
);
|
||||
check("its first use", &expected);
|
||||
|
||||
// Its other reads.
|
||||
let samples = reading(&device, layout.pf, "tob_sample");
|
||||
let nearest = sampler(&device, SamplerMinMagFilter::Nearest);
|
||||
let linear = sampler(&device, SamplerMinMagFilter::Linear);
|
||||
read(
|
||||
"a nearest sample",
|
||||
&drawn(&queue, &layout, &samples, texture, Some(&nearest)),
|
||||
&texels,
|
||||
);
|
||||
let private = private_with(&queue, &layout, &texels);
|
||||
read(
|
||||
"a linear sample, against a private texture's",
|
||||
&drawn(&queue, &layout, &samples, texture, Some(&linear)),
|
||||
&drawn(&queue, &layout, &samples, &private, Some(&linear)),
|
||||
);
|
||||
let mut got = vec![0u8; texels.len()];
|
||||
let whole = Region::new_2d(0, 0, layout.w, layout.h);
|
||||
texture
|
||||
.get_bytes(&mut got, layout.row(), 0, whole, 0, 0)
|
||||
.unwrap();
|
||||
read("get_bytes", &got, &texels);
|
||||
read("a blit out", &blit_out(&queue, &layout, texture), &texels);
|
||||
check("the reads", &expected);
|
||||
|
||||
// The caller's later bytes: new texels, and new bytes between the rows, which no later
|
||||
// command may move.
|
||||
let mut later_pages = counting(surface.len, 9);
|
||||
let later = texels_of(&layout, texels.len(), 2);
|
||||
lay(&layout, &mut later_pages, &later);
|
||||
expected.copy_from_slice(&later_pages);
|
||||
surface.mapping.write(0, &expected);
|
||||
read(
|
||||
"a nearest sample of the caller's later bytes",
|
||||
&drawn(&queue, &layout, &samples, texture, Some(&nearest)),
|
||||
&later,
|
||||
);
|
||||
read(
|
||||
"a fragment function's read of the caller's later bytes",
|
||||
&drawn(&queue, &layout, &reads, texture, None),
|
||||
&later,
|
||||
);
|
||||
check("the reads of the caller's later bytes", &expected);
|
||||
|
||||
// Writes Metal makes of any texture: a buffer's box blitted in at an odd origin.
|
||||
let (bx, by, bw, bh) = (3, 5, layout.w / 2 + 1, layout.h / 3 + 1);
|
||||
let boxed = texels_of(&layout, (bw * bh * texel) as usize, 3);
|
||||
let source = staged(&device, &boxed);
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
blit.copy_from_buffer_to_texture(
|
||||
&source,
|
||||
0,
|
||||
bw * texel,
|
||||
boxed.len() as u64,
|
||||
Size::new(bw, bh, 1),
|
||||
texture,
|
||||
0,
|
||||
0,
|
||||
Origin::new(bx, by, 0),
|
||||
BlitOption::None,
|
||||
)
|
||||
.unwrap();
|
||||
blit.end_encoding().unwrap();
|
||||
run(&command_buffer);
|
||||
lay_box(&layout, &mut expected, (bx, by, bw), &boxed);
|
||||
check("a buffer's box blitted in", &expected);
|
||||
// `replace_region` of a box.
|
||||
let (rx, ry, rw, rh) = (layout.w / 3, 1, layout.w / 4 + 1, layout.h / 2);
|
||||
let replaced = texels_of(&layout, (rw * rh * texel) as usize, 4);
|
||||
texture
|
||||
.replace_region(
|
||||
Region::new_2d(rx, ry, rw, rh),
|
||||
0,
|
||||
0,
|
||||
&replaced,
|
||||
rw * texel,
|
||||
0,
|
||||
)
|
||||
.unwrap();
|
||||
lay_box(&layout, &mut expected, (rx, ry, rw), &replaced);
|
||||
check("replace_region", &expected);
|
||||
// A private texture's box blitted in.
|
||||
let other = private_with(&queue, &layout, &texels_of(&layout, texels.len(), 5));
|
||||
let (fx, fy, tx, ty) = (7, 1, layout.w / 3, 2);
|
||||
let size = Size::new(layout.w / 2, layout.h / 2, 1);
|
||||
blit_box(
|
||||
&queue,
|
||||
(&other, Origin::new(fx, fy, 0)),
|
||||
(texture, Origin::new(tx, ty, 0)),
|
||||
size,
|
||||
);
|
||||
let from = blit_out(&queue, &layout, &other);
|
||||
for y in 0..size.height {
|
||||
let start = ((fy + y) * layout.row() + fx * texel) as usize;
|
||||
let row = &from[start..start + (size.width * texel) as usize];
|
||||
let at = ((ty + y) * layout.bpr + tx * texel) as usize;
|
||||
expected[at..at + row.len()].copy_from_slice(row);
|
||||
}
|
||||
check("a private texture's box blitted in", &expected);
|
||||
// And the writes read back through the image.
|
||||
read(
|
||||
"a fragment function's read after the writes",
|
||||
&drawn(&queue, &layout, &reads, texture, None),
|
||||
&rows(&layout, &expected),
|
||||
);
|
||||
check("the last read", &expected);
|
||||
let made = (surface.form.0, on_metal(&device));
|
||||
surface.report(&device, &messages);
|
||||
made
|
||||
};
|
||||
let messages = messages.take();
|
||||
assert!(
|
||||
messages.is_empty(),
|
||||
"the validation layer reported: {messages:#?}"
|
||||
);
|
||||
Some(made)
|
||||
}
|
||||
|
||||
/// [`reads_and_blits_as_metal`] over each of [`LAYOUTS`]: a texture that only reads, aliased
|
||||
/// where the device lays an image at the rows' pitch, keeps every byte of its pages through its
|
||||
/// first move, its reads, the caller's writes and Metal's blits into it. Printed: how many of the
|
||||
/// padded layouts aliased (`PITCHED-READS`); off Metal at least one must, or no first move over
|
||||
/// padded rows was checked.
|
||||
#[test]
|
||||
fn a_texture_that_only_reads_keeps_every_byte_of_its_pages() {
|
||||
let (mut aliased, mut padded, mut metal) = (0, 0, false);
|
||||
for layout in LAYOUTS {
|
||||
let Some((alias, on_metal)) = reads_and_blits_as_metal(layout) else {
|
||||
return;
|
||||
};
|
||||
metal = on_metal;
|
||||
if layout.padded() {
|
||||
aliased += u64::from(alias);
|
||||
padded += 1;
|
||||
}
|
||||
}
|
||||
eprintln!("PITCHED-READS: {aliased} of {padded} padded layouts that only read aliased");
|
||||
assert!(
|
||||
aliased > 0 || metal,
|
||||
"no padded layout that only reads was aliased, so no first move over padded rows was \
|
||||
checked"
|
||||
);
|
||||
}
|
||||
|
||||
/// A texture that only reads over padded rows (each padded layout of [`LAYOUTS`] over a no-copy
|
||||
/// buffer) copies no shadow under the policy's default where it is aliased:
|
||||
/// `WorkCounts::shadow_copies` stays the same across three sampling passes and a blit out. Under
|
||||
/// `PaddedReadsPolicy::Shadow` the same texture is a shadow (but on Metal, whose image of it is a
|
||||
/// Metal texture over the buffer either way), copied in for its uses. Off Metal at least one layout
|
||||
/// is aliased by default.
|
||||
#[test]
|
||||
fn a_padded_texture_that_only_reads_copies_no_shadow_by_default() {
|
||||
let mut aliased_layouts = 0;
|
||||
let mut metal = false;
|
||||
for layout in LAYOUTS.into_iter().filter(Layout::padded) {
|
||||
for policy in [PaddedReadsPolicy::Alias, PaddedReadsPolicy::Shadow] {
|
||||
let cache = ScratchCache::new().unwrap();
|
||||
let messages = Messages::default();
|
||||
{
|
||||
let device = device_with(&messages, &cache, policy);
|
||||
metal = on_metal(&device);
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let alias = policy == PaddedReadsPolicy::Alias;
|
||||
let usage = TextureUsage::SHADER_READ;
|
||||
let Some(surface) = surface(&device, &layout, usage, alias) else {
|
||||
return;
|
||||
};
|
||||
let (aliased, _, _) = surface.form;
|
||||
let what = format!("{} under {policy:?}", surface.what);
|
||||
if !alias {
|
||||
assert!(!aliased || metal, "{what}: aliased");
|
||||
}
|
||||
let texels = rows(&layout, &surface.pages);
|
||||
let samples = reading(&device, layout.pf, "tob_sample");
|
||||
let nearest = sampler(&device, SamplerMinMagFilter::Nearest);
|
||||
let copies = || device.work_counts().shadow_copies;
|
||||
let before = copies();
|
||||
for _ in 0..3 {
|
||||
let got = drawn(&queue, &layout, &samples, &surface.texture, Some(&nearest));
|
||||
assert!(
|
||||
got == texels,
|
||||
"{what}: a sample differs from the pages' texels"
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
blit_out(&queue, &layout, &surface.texture) == texels,
|
||||
"{what}"
|
||||
);
|
||||
let copied = copies() - before;
|
||||
eprintln!(
|
||||
"PITCHED-READS on {}: {what}: {}, {copied} shadow copies over three samples \
|
||||
and a blit out",
|
||||
device.name(),
|
||||
if aliased { "aliased" } else { "shadowed" }
|
||||
);
|
||||
if aliased {
|
||||
assert_eq!(copied, 0, "{what}: an aliased texture copied a shadow");
|
||||
aliased_layouts += u64::from(alias);
|
||||
} else {
|
||||
assert!(copied > 0, "{what}: a shadow its uses copied nothing into");
|
||||
}
|
||||
surface.check(&layout, "its uses", &surface.pages);
|
||||
surface.report(&device, &messages);
|
||||
}
|
||||
let messages = messages.take();
|
||||
assert!(
|
||||
messages.is_empty(),
|
||||
"the validation layer reported: {messages:#?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
aliased_layouts > 0 || metal,
|
||||
"no padded layout that only reads was aliased by default"
|
||||
);
|
||||
}
|
||||
|
||||
/// A padded texture that renders (`RenderTarget`), that a shader writes (`ShaderWrite`), or of
|
||||
/// `Unknown` usage (which Metal reports as both) is a shadow under either policy, off Metal: over
|
||||
/// a no-copy buffer's pages and over an ordinary buffer alike (the browser's tile, [`LAYOUTS`]'
|
||||
/// first).
|
||||
#[test]
|
||||
fn a_padded_texture_that_renders_or_writes_is_a_shadow_under_either_policy() {
|
||||
let layout = LAYOUTS[0];
|
||||
assert!(layout.padded(), "{}", layout.name);
|
||||
for policy in [PaddedReadsPolicy::Alias, PaddedReadsPolicy::Shadow] {
|
||||
for usage in [
|
||||
TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ,
|
||||
TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE,
|
||||
TextureUsage::UNKNOWN,
|
||||
] {
|
||||
let cache = ScratchCache::new().unwrap();
|
||||
let messages = Messages::default();
|
||||
{
|
||||
let device = device_with(&messages, &cache, policy);
|
||||
// Over a no-copy buffer's pages (`surface` checks the form against the counts).
|
||||
if let Some(surface) = surface(&device, &layout, usage, false) {
|
||||
surface.report(&device, &messages);
|
||||
}
|
||||
// Over an ordinary buffer.
|
||||
let buffer = device
|
||||
.new_buffer(layout.bpr * layout.h, ResourceOptions::default())
|
||||
.unwrap();
|
||||
let mut d = TextureDescriptor::texture_2d(layout.pf, layout.w, layout.h, false);
|
||||
d.usage = usage;
|
||||
d.resource_options = buffer.resource_options();
|
||||
let texture = buffer.new_texture(&d, 0, layout.bpr).unwrap();
|
||||
// SAFETY: the handle is only compared, while the texture lives.
|
||||
let aliased = unsafe { texture.vk_image() }.is_some();
|
||||
assert!(
|
||||
!aliased,
|
||||
"{} ({usage:?}) under {policy:?}, an ordinary buffer's: aliased",
|
||||
layout.name
|
||||
);
|
||||
messages.take_notices();
|
||||
drop((texture, buffer));
|
||||
}
|
||||
let messages = messages.take();
|
||||
assert!(
|
||||
messages.is_empty(),
|
||||
"the validation layer reported: {messages:#?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A texture that only reads over an ordinary `Shared` buffer's padded rows (each padded layout
|
||||
/// of [`LAYOUTS`]): under the policy's default it is the device's own linear image over the
|
||||
/// buffer's memory, made `PREINITIALIZED`, where the device lays one at the rows' pitch, and its
|
||||
/// first use, a fragment function's read through it, reads the buffer's texels and leaves every
|
||||
/// byte of the buffer, the bytes between the rows among them, as it was; an aliased one copies
|
||||
/// no shadow over that read and a nearest sample. Under `PaddedReadsPolicy::Shadow` it is a
|
||||
/// shadow on every device. Printed (`PITCHED-READS`): each layout's form, and a shadow's reason.
|
||||
#[test]
|
||||
fn a_padded_texture_that_only_reads_over_an_ordinary_buffer_keeps_its_bytes() {
|
||||
for layout in LAYOUTS.into_iter().filter(Layout::padded) {
|
||||
for policy in [PaddedReadsPolicy::Alias, PaddedReadsPolicy::Shadow] {
|
||||
let cache = ScratchCache::new().unwrap();
|
||||
let messages = Messages::default();
|
||||
{
|
||||
let device = device_with(&messages, &cache, policy);
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let len = layout.bpr * layout.h;
|
||||
let buffer = device.new_buffer(len, ResourceOptions::default()).unwrap();
|
||||
let mut bytes = counting(len as usize, 11);
|
||||
lay(
|
||||
&layout,
|
||||
&mut bytes,
|
||||
&texels_of(&layout, (layout.row() * layout.h) as usize, 6),
|
||||
);
|
||||
let contents = buffer.contents().unwrap();
|
||||
// SAFETY: a new `Shared` buffer of `len` bytes, which no command uses yet.
|
||||
unsafe {
|
||||
std::ptr::copy_nonoverlapping(bytes.as_ptr(), contents.as_ptr(), bytes.len())
|
||||
};
|
||||
let mut d = TextureDescriptor::texture_2d(layout.pf, layout.w, layout.h, false);
|
||||
d.usage = TextureUsage::SHADER_READ;
|
||||
d.resource_options = buffer.resource_options();
|
||||
let texture = buffer.new_texture(&d, 0, layout.bpr).unwrap();
|
||||
// SAFETY: the handle is only compared, while the texture lives.
|
||||
let aliased = unsafe { texture.vk_image() }.is_some();
|
||||
let what = format!(
|
||||
"{} (ShaderRead) under {policy:?}, an ordinary buffer's",
|
||||
layout.name
|
||||
);
|
||||
if policy == PaddedReadsPolicy::Shadow {
|
||||
assert!(!aliased, "{what}: aliased");
|
||||
}
|
||||
let texels = rows(&layout, &bytes);
|
||||
let copies = || device.work_counts().shadow_copies;
|
||||
let before = copies();
|
||||
let reads = reading(&device, layout.pf, "tob_read");
|
||||
let read = drawn(&queue, &layout, &reads, &texture, None);
|
||||
let (count, first) = differing(&read, &texels, layout.texel);
|
||||
assert!(
|
||||
count == 0,
|
||||
"{what}, its first use: {count} texels read differ from the buffer's, the \
|
||||
first at texel {first:?}"
|
||||
);
|
||||
let now = bytes_of(&buffer);
|
||||
assert!(
|
||||
now == bytes,
|
||||
"{what}, its first use: the bytes between the rows (or past the last) \
|
||||
changed: {}",
|
||||
padding_changes(&layout, &now, &bytes)
|
||||
);
|
||||
let samples = reading(&device, layout.pf, "tob_sample");
|
||||
let nearest = sampler(&device, SamplerMinMagFilter::Nearest);
|
||||
let got = drawn(&queue, &layout, &samples, &texture, Some(&nearest));
|
||||
assert!(
|
||||
got == texels,
|
||||
"{what}: a sample differs from the buffer's texels"
|
||||
);
|
||||
let copied = copies() - before;
|
||||
if aliased {
|
||||
assert_eq!(copied, 0, "{what}: an aliased texture copied a shadow");
|
||||
}
|
||||
assert!(
|
||||
bytes_of(&buffer) == bytes,
|
||||
"{what}: the buffer's bytes changed"
|
||||
);
|
||||
let reason = messages
|
||||
.take_notices()
|
||||
.into_iter()
|
||||
.filter_map(|message| message.degradation)
|
||||
.find(|notice| notice.degradation == Degradation::ShadowedTexture)
|
||||
.map(|notice| format!(": {}", notice.reason))
|
||||
.unwrap_or_default();
|
||||
eprintln!(
|
||||
"PITCHED-READS on {}: {what}: {}, {copied} shadow copies over a read and a \
|
||||
sample{reason}",
|
||||
device.name(),
|
||||
if aliased { "aliased" } else { "shadowed" }
|
||||
);
|
||||
drop((texture, buffer));
|
||||
}
|
||||
let messages = messages.take();
|
||||
assert!(
|
||||
messages.is_empty(),
|
||||
"the validation layer reported: {messages:#?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,12 @@
|
||||
//! [`shadow_copy_costs`] times a shadow's copies alone, and the same bytes moved between other
|
||||
//! memories, to tell the image's tiling from the pages' memory (`SURFTEX-COPY`).
|
||||
//!
|
||||
//! All four are ignored by default: measurements, not checks. Run them by name with `--run-ignored all`, in a
|
||||
//! [`read_only_padded_costs`] times a compositor's frame over the padded layouts' textures made
|
||||
//! with `ShaderRead` usage alone, each sampled by a draw, under each `PaddedReadsPolicy`: an image
|
||||
//! over the rows (`Alias`, the default) against the shadow copied in at each use (`Shadow`),
|
||||
//! interleaved (`SURFTEX-READS`).
|
||||
//!
|
||||
//! All five are ignored by default: measurements, not checks. Run them by name with `--run-ignored all`, in a
|
||||
//! build with `--cfg m2v_system_alloc`, whose lib test binary keeps the system allocator as a
|
||||
//! consumer's process does.
|
||||
|
||||
@@ -949,3 +954,128 @@ fn pitch_classes() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A compositor's frame over textures that only read: each frame, for each padded layout of
|
||||
/// [`LAYOUTS`] (the tight one left out), a no-copy buffer over its surface's anonymous pages and a
|
||||
/// texture of its plane over it with `ShaderRead` usage alone; one pass into a private target of
|
||||
/// the browser's tile, drawing each texture over the whole target through a nearest sampler; one
|
||||
/// command buffer, committed and waited for; then the textures and buffers are released. Run under
|
||||
/// `PaddedReadsPolicy::Alias` (an image over the rows where the device lays one) and `Shadow` (the
|
||||
/// shadow, copied in before the pass), a device each, the two interleaved in rounds so a drift of
|
||||
/// the host's falls on both. Printed per policy and round (`SURFTEX-READS`): the textures' forms,
|
||||
/// the medians and 90th percentiles of a texture's making, the frame's encoding, commit to
|
||||
/// completion and process CPU time, and the shadow copies a frame.
|
||||
#[test]
|
||||
#[ignore = "a release-mode measurement: run by name"]
|
||||
fn read_only_padded_costs() {
|
||||
use super::pitched_surfaces::{reading, sampler};
|
||||
use metal2vulkan::device::PaddedReadsPolicy;
|
||||
use metal2vulkan::metal::SamplerMinMagFilter;
|
||||
let chosen: Vec<usize> = (0..LAYOUTS.len())
|
||||
.filter(|&i| LAYOUTS[i].3 != LAYOUTS[i].1 * 4)
|
||||
.collect();
|
||||
let surfaces: Vec<Surface> = LAYOUTS
|
||||
.iter()
|
||||
.map(|&(_, _, h, bpr)| Surface::Anonymous(Mapping::anonymous(Surface::len(bpr, h))))
|
||||
.collect();
|
||||
for round in 0..3 {
|
||||
for policy in [PaddedReadsPolicy::Alias, PaddedReadsPolicy::Shadow] {
|
||||
let cache = ScratchCache::new().unwrap();
|
||||
let messages = Messages::default();
|
||||
let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), |options| {
|
||||
options.layers.clear();
|
||||
options.policy.padded_reads = policy;
|
||||
})
|
||||
.unwrap();
|
||||
messages.take_notices();
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let pipeline = reading(&device, PixelFormat::BGRA8Unorm, "tob_sample");
|
||||
let nearest = sampler(&device, SamplerMinMagFilter::Nearest);
|
||||
let corners = staged(&device, &floats([-1.0, -1.0, 1.0, 1.0]));
|
||||
let (_, tw, th, _) = LAYOUTS[0];
|
||||
let mut d = TextureDescriptor::texture_2d(PixelFormat::BGRA8Unorm, tw, th, false);
|
||||
d.usage = TextureUsage::RENDER_TARGET;
|
||||
d.resource_options = ResourceOptions::private();
|
||||
let target = device.new_texture(&d).unwrap();
|
||||
let mut forms = String::new();
|
||||
let mut makes = Vec::new();
|
||||
let (mut encodes, mut waits, mut cpus) = (Vec::new(), Vec::new(), Vec::new());
|
||||
let mut before = device.work_counts();
|
||||
for k in 0..WARM + FRAMES {
|
||||
if k == WARM {
|
||||
before = device.work_counts();
|
||||
}
|
||||
let cpu = process_cpu_us();
|
||||
let mut made = Vec::new();
|
||||
for &index in &chosen {
|
||||
let (_, w, h, bpr) = LAYOUTS[index];
|
||||
let len = Surface::len(bpr, h);
|
||||
let began = Instant::now();
|
||||
let buffer = surfaces[index].buffer(&device, len, None);
|
||||
let mut d = TextureDescriptor::texture_2d(PixelFormat::BGRA8Unorm, w, h, false);
|
||||
d.usage = TextureUsage::SHADER_READ;
|
||||
d.resource_options = buffer.resource_options();
|
||||
let texture = buffer
|
||||
.new_texture_with_iosurface_plane(&d, IoSurfacePlane::new(0, bpr, false))
|
||||
.unwrap();
|
||||
if k >= WARM {
|
||||
makes.push(since(began));
|
||||
}
|
||||
made.push((texture, buffer));
|
||||
}
|
||||
if k == 0 {
|
||||
forms = made
|
||||
.iter()
|
||||
.map(|(texture, _)| if aliased(texture) { 'a' } else { 's' })
|
||||
.collect();
|
||||
}
|
||||
let began = Instant::now();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut pass = RenderPassDescriptor::new();
|
||||
let attachment = &mut pass.color_attachments[0];
|
||||
attachment.texture = Some(target.clone());
|
||||
attachment.load_action = LoadAction::Clear;
|
||||
attachment.store_action = StoreAction::Store;
|
||||
let mut encoder = command_buffer.render_command_encoder(&pass).unwrap();
|
||||
encoder.set_render_pipeline_state(&pipeline).unwrap();
|
||||
encoder.set_vertex_buffer(Some(&corners), 0, 0).unwrap();
|
||||
encoder
|
||||
.set_fragment_sampler_state(Some(&nearest), 0)
|
||||
.unwrap();
|
||||
for (texture, _) in &made {
|
||||
encoder.set_fragment_texture(Some(texture), 0).unwrap();
|
||||
encoder
|
||||
.draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0)
|
||||
.unwrap();
|
||||
}
|
||||
encoder.end_encoding().unwrap();
|
||||
let encoded = since(began);
|
||||
let committed = Instant::now();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.error(), None);
|
||||
let waited = since(committed);
|
||||
drop(made);
|
||||
if k >= WARM {
|
||||
encodes.push(encoded);
|
||||
waits.push(waited);
|
||||
cpus.push(process_cpu_us() - cpu);
|
||||
}
|
||||
}
|
||||
let after = device.work_counts();
|
||||
let copies = (after.shadow_copies - before.shadow_copies) as f64 / FRAMES as f64;
|
||||
let (make, make90) = median_p90(makes);
|
||||
let (encode, encode90) = median_p90(encodes);
|
||||
let (wait, wait90) = median_p90(waits);
|
||||
let (cpu, cpu90) = median_p90(cpus);
|
||||
println!(
|
||||
"SURFTEX-READS on {}: round {round}, {policy:?}, forms {forms} (a aliased, s \
|
||||
shadowed): making {make:.0} us a texture (p90 {make90:.0}), encode {encode:.0} \
|
||||
us (p90 {encode90:.0}), commit to completion {wait:.0} us (p90 {wait90:.0}), \
|
||||
process CPU {cpu:.0} us (p90 {cpu90:.0}); shadow copies a frame {copies:.2}",
|
||||
device.name(),
|
||||
);
|
||||
}
|
||||
}
|
||||
drop(surfaces);
|
||||
}
|
||||
Vendored
+1
-1
@@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 399;
|
||||
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
|
||||
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
|
||||
/// keeps no history.
|
||||
pub const RUNTIME_VERSION: u32 = 1204;
|
||||
pub const RUNTIME_VERSION: u32 = 1205;
|
||||
|
||||
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
|
||||
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles
|
||||
|
||||
@@ -67,7 +67,7 @@ pub(crate) use mechanism::mechanism;
|
||||
pub use metal::{MetalDeviceProperties, SimdSupport, StageSimd};
|
||||
pub use policy::{
|
||||
ContainmentPolicy, DevicePolicy, FloatMathsPolicy, HalfBlendPolicy, HalfRoundingPolicy,
|
||||
NanMinMaxPolicy, RoundingOrderPolicy, SamplingPolicy, TexelConversionPolicy,
|
||||
NanMinMaxPolicy, PaddedReadsPolicy, RoundingOrderPolicy, SamplingPolicy, TexelConversionPolicy,
|
||||
Unorm8LinearFilterPolicy,
|
||||
};
|
||||
pub(crate) use profile::whole_point_size;
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
|
||||
use crate::device::profile::{FramebufferFetchPolicy, GuestIsolation, HandleDomain, PointerDomain};
|
||||
|
||||
/// Policy inputs of `Device::new`. Every field can change emitted code, so the profile carries it
|
||||
/// (containment as the encoding it selects) and its fingerprint covers it.
|
||||
/// Policy inputs of `Device::new`. Every field but `padded_reads` can change emitted code, so the
|
||||
/// profile carries it (containment as the encoding it selects) and its fingerprint covers it;
|
||||
/// `padded_reads` is the runtime's alone (how it makes a texture over a buffer), and no profile
|
||||
/// carries it.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
@@ -52,6 +54,12 @@ pub struct DevicePolicy {
|
||||
/// attachment in the device's blend (the default) or in Metal's `half` arithmetic, which the
|
||||
/// function computes in the shader.
|
||||
pub half_blend: HalfBlendPolicy,
|
||||
/// Whether a texture over a buffer whose rows (or slices) lie with bytes between them, and
|
||||
/// which only reads (its usage holds no `RenderTarget`, `ShaderWrite`, `ShaderAtomic` or block
|
||||
/// writes), is an image over the buffer's bytes at Metal's row pitch (the default) or the
|
||||
/// runtime's shadow of them, copied in before each use. The runtime's choice alone: no
|
||||
/// emitted code changes.
|
||||
pub padded_reads: PaddedReadsPolicy,
|
||||
}
|
||||
|
||||
impl DevicePolicy {
|
||||
@@ -59,7 +67,8 @@ impl DevicePolicy {
|
||||
/// ordered framebuffer fetch required, Metal's 8-bit linear filter emulated exactly where the
|
||||
/// emulation runs, native device sampling, native device maths, the device's own texel
|
||||
/// conversions, native half rounding, the device's NaN and minimum and maximum, the device's
|
||||
/// rounding order, and the device's blend of a `half` output into a 16-bit float attachment.
|
||||
/// rounding order, the device's blend of a `half` output into a 16-bit float attachment, and
|
||||
/// an image over a texture's padded rows where the texture only reads.
|
||||
pub const UNTRUSTED: DevicePolicy = DevicePolicy {
|
||||
pointer_domain: PointerDomain::ResidentTable,
|
||||
handle_domain: HandleDomain::Table,
|
||||
@@ -74,14 +83,17 @@ impl DevicePolicy {
|
||||
nan_and_min_max: NanMinMaxPolicy::Native,
|
||||
rounding_order: RoundingOrderPolicy::Native,
|
||||
half_blend: HalfBlendPolicy::Device,
|
||||
padded_reads: PaddedReadsPolicy::Alias,
|
||||
};
|
||||
|
||||
/// This policy with Metal's answer wherever the choices offer it: its maths functions,
|
||||
/// divisions and fused multiply-adds ([`FloatMathsPolicy::Exact`]), its texel conversions
|
||||
/// ([`TexelConversionPolicy::Exact`]), its `half` rounding ([`HalfRoundingPolicy::Exact`]), its
|
||||
/// NaN and minimum and maximum ([`NanMinMaxPolicy::Exact`]), its rounding order
|
||||
/// ([`RoundingOrderPolicy::Exact`]), and its 16-bit float blend of a `half` output
|
||||
/// ([`HalfBlendPolicy::Exact`]). Sampling and every other field are kept.
|
||||
/// ([`RoundingOrderPolicy::Exact`]), its 16-bit float blend of a `half` output
|
||||
/// ([`HalfBlendPolicy::Exact`]), and the bytes between a texture's rows that no first move of
|
||||
/// an image over them reaches ([`PaddedReadsPolicy::Shadow`]). Sampling and every other field
|
||||
/// are kept.
|
||||
pub const fn exact_answers(self) -> DevicePolicy {
|
||||
DevicePolicy {
|
||||
float_maths: FloatMathsPolicy::Exact,
|
||||
@@ -90,6 +102,7 @@ impl DevicePolicy {
|
||||
nan_and_min_max: NanMinMaxPolicy::Exact,
|
||||
rounding_order: RoundingOrderPolicy::Exact,
|
||||
half_blend: HalfBlendPolicy::Exact,
|
||||
padded_reads: PaddedReadsPolicy::Shadow,
|
||||
..self
|
||||
}
|
||||
}
|
||||
@@ -323,3 +336,31 @@ pub enum HalfBlendPolicy {
|
||||
/// [`HalfBlendPolicy::Device`].
|
||||
Exact,
|
||||
}
|
||||
|
||||
/// How the runtime makes a texture over a buffer whose rows (or an array's slices) lie with bytes
|
||||
/// between them that are not its texels (a guest browser's padded surfaces), and which only reads:
|
||||
/// its usage, as Metal reports it (`Unknown` reads as `ShaderRead | ShaderWrite | RenderTarget |
|
||||
/// PixelFormatView`), holds no `RenderTarget`, `ShaderWrite`, `ShaderAtomic` or block writes.
|
||||
/// Metal never writes those bytes. A render target, or a texture a shader writes, is a shadow
|
||||
/// under either value: a render pass's load and store operations may write back any byte of an
|
||||
/// attachment's subresource.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum PaddedReadsPolicy {
|
||||
/// An image over the buffer's bytes at Metal's row pitch, as a texture whose rows lie one
|
||||
/// after another has (the default): the device's own linear image, a `DRM_FORMAT_MOD_LINEAR`
|
||||
/// image at that pitch, or one over a dma-buf of the pages, holding the bytes between the
|
||||
/// rows in its subresource. After its first move every command uses it in `GENERAL`, and
|
||||
/// copies and shader reads touch its texels alone; the first move, a layout transition, "may
|
||||
/// perform read and write accesses on all memory bound to the image subresource range"
|
||||
/// (Vulkan's Image Layout Transitions), and from `UNDEFINED` may discard it. So the bytes
|
||||
/// between the rows stay the program's only as far as the driver's move keeps them, which
|
||||
/// the validation lane checks per driver (docs/FAST-PATHS.md, its known gaps).
|
||||
#[default]
|
||||
Alias,
|
||||
/// The runtime's shadow image of the texels, copied in from the buffer before each use: the
|
||||
/// copies address the texels alone, so no byte between the rows is ever read or written
|
||||
/// through an image.
|
||||
Shadow,
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
use crate::device::{
|
||||
DevicePolicy, FloatMathsPolicy, FramebufferFetchPolicy, HalfBlendPolicy, HalfRoundingPolicy,
|
||||
NanMinMaxPolicy, RoundingOrderPolicy, SamplingPolicy, TexelConversionPolicy,
|
||||
NanMinMaxPolicy, PaddedReadsPolicy, RoundingOrderPolicy, SamplingPolicy, TexelConversionPolicy,
|
||||
Unorm8LinearFilterPolicy,
|
||||
};
|
||||
use crate::pipeline::PrecisionNote;
|
||||
@@ -68,6 +68,8 @@ fn choices() -> Vec<Choice> {
|
||||
nan_and_min_max: _,
|
||||
rounding_order: _,
|
||||
half_blend: _,
|
||||
// The runtime's: whether a texture over padded rows that only reads aliases them.
|
||||
padded_reads: _,
|
||||
} = p;
|
||||
vec![
|
||||
choice!(p.framebuffer_fetch: FramebufferFetchPolicy { RequireOrdered, AcceptUnordered }),
|
||||
@@ -79,6 +81,7 @@ fn choices() -> Vec<Choice> {
|
||||
choice!(p.nan_and_min_max: NanMinMaxPolicy { Native, Exact }),
|
||||
choice!(p.rounding_order: RoundingOrderPolicy { Native, Exact }),
|
||||
choice!(p.half_blend: HalfBlendPolicy { Device, Exact }),
|
||||
choice!(p.padded_reads: PaddedReadsPolicy { Alias, Shadow }),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -368,3 +371,23 @@ fn the_ledger_readers_read_names_and_switches() {
|
||||
BTreeSet::from([("sampling".to_owned(), "SamplingPolicy::Exact".to_owned())])
|
||||
);
|
||||
}
|
||||
|
||||
/// The runtime's choice for a texture over padded rows that only reads (`padded_reads`) moves no
|
||||
/// committed profile's fingerprint: no profile carries it, so no translation, cache key or
|
||||
/// recorded row follows it, and the ledger's row is the runtime's alone.
|
||||
#[test]
|
||||
fn the_runtime_s_padded_reads_choice_keys_no_profile() {
|
||||
use crate::spirv::testing::committed_profiles_with;
|
||||
let alias = committed_profiles_with(DevicePolicy::UNTRUSTED).expect("profiles");
|
||||
let shadow = committed_profiles_with(DevicePolicy {
|
||||
padded_reads: PaddedReadsPolicy::Shadow,
|
||||
..DevicePolicy::UNTRUSTED
|
||||
})
|
||||
.expect("profiles");
|
||||
assert!(alias.len() >= 10, "{} profiles", alias.len());
|
||||
assert_eq!(alias.len(), shadow.len());
|
||||
for ((stem, a), (other, s)) in alias.iter().zip(&shadow) {
|
||||
assert_eq!(stem, other);
|
||||
assert_eq!(a.fingerprint(), s.fingerprint(), "{stem}");
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,7 @@ surface! {
|
||||
enum NanMinMaxPolicy N;
|
||||
enum RoundingOrderPolicy N;
|
||||
enum HalfBlendPolicy N;
|
||||
enum PaddedReadsPolicy N;
|
||||
struct DeviceProfile O;
|
||||
struct SpirvValidation N;
|
||||
struct EnabledCaps N;
|
||||
|
||||
+13
-6
@@ -93,6 +93,13 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
|
||||
[FAST-PATHS.md](FAST-PATHS.md) lists every choice, its bound and the measured cost of its exact
|
||||
form. On MoltenVK on an Apple GPU, whose sampler and `float` functions are Metal's own, most of
|
||||
these choices change nothing.
|
||||
- **An image over a padded texture that only reads** (`PaddedReadsPolicy::Alias`, the runtime's
|
||||
choice; no pipeline differs). A texture over a buffer whose rows lie with bytes between them,
|
||||
and whose usage holds no `RenderTarget`, `ShaderWrite`, `ShaderAtomic` or block writes, is an
|
||||
image over the buffer's bytes at its row pitch where the device lays one there. Its subresources
|
||||
hold the bytes between the rows, which they keep as far as the driver's first move of the image
|
||||
does (FAST-PATHS.md's known gaps). `padded_reads = PaddedReadsPolicy::Shadow`, which
|
||||
`exact_answers()` selects, makes it the runtime's shadow, copied in before each use.
|
||||
|
||||
Loops run as written: no execution bound is translated in.
|
||||
|
||||
@@ -705,12 +712,12 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
|
||||
|
||||
- `metal2vulkan-degrade-shadowed-texture` (performance). `ShadowedTexture`: A 2D texture over a
|
||||
buffer is a shadow image: its rows (or an array's slices) lie with the buffer's bytes between
|
||||
them, which an image over them would hold in its subresource, where Vulkan lets the image's
|
||||
layout transitions (its first move among them, which a texture that only reads takes too) read
|
||||
and write any byte of its subresources, and a render pass's load and store operations read and
|
||||
write back any byte of an attachment's image subresource, and Metal leaves them as the program
|
||||
writes them (but where the device's image of it is a Metal
|
||||
texture over the buffer, on MoltenVK); or no linear image of the device lays its texels out as
|
||||
them, and it renders or a shader writes it (or it only reads, under `padded_reads =
|
||||
PaddedReadsPolicy::Shadow`), which an image over them would hold in its subresource, where
|
||||
Vulkan lets the image's layout transitions (its first move among them) read and write any byte
|
||||
of its subresources, and a render pass's load and store operations read and write back any byte
|
||||
of an attachment's image subresource, and Metal leaves them as the program writes them (but
|
||||
where the device's image of it is a Metal texture over the buffer, on MoltenVK); or no linear image of the device lays its texels out as
|
||||
Metal does in the buffer's memory, holding no byte past them (over a no-copy buffer's imported
|
||||
host memory, no linear image made for host allocations does: neither the driver's own nor, where
|
||||
the device enables `VK_EXT_image_drm_format_modifier`, a `DRM_FORMAT_MOD_LINEAR` image laid out
|
||||
|
||||
+51
-31
@@ -39,6 +39,7 @@ a cell that names another source took its numbers there.
|
||||
| The `half` conversion converts the value itself (no `NoContraction` barrier), so the device's compiler may fold it into the instruction computing the value, rounding once. | `half_rounding = HalfRoundingPolicy::Native` | `half_rounding = HalfRoundingPolicy::Exact` (with the rows above) | The row above's: on NVIDIA (RTX 3090), and on lavapipe for a loaded texel (Mesa 26.0.8), the pair is dropped whether or not the barrier stands, so the barrier does not restore the rounding there. `NativeHalfConversion` (`native-half-conversion`) | At its merge: A2X 0.99-1.02 s without the barrier against 1.00-1.05 s with it; Xgc within a round's spread |
|
||||
| A `half` texel's NaN is the rounding's own NaN, not the texel's bits (the keep's four instructions a texel are left out). | `half_rounding = HalfRoundingPolicy::Native` and `nan_and_min_max = NanMinMaxPolicy::Native` | `nan_and_min_max = NanMinMaxPolicy::Exact` (the keep under native half rounding, master ecd39568bb); `half_rounding = HalfRoundingPolicy::Exact` also keeps it, at that row's cost. The same switch also gives Metal's full rule: `0x7e00` for every NaN but a one-texel read, nearest sample or gather of a 16-bit float texture, by the slot's format class read as data, a heap handle's class index and a runtime sampler's filter. A gather with a `half` result fetches its four texels where the class is a half-float one, since NVIDIA's gather hands back every NaN as `0x7fffffff`. **Not yet exact:** a cube gather, bicubic and emulated linear, fetched or compared samples. Possible, not built: the runtime sampler's filter read as push data rather than specialized, which would spare the remake below. Measured on the RTX 5080: under the switch no `half` lane of the runtime lane's texel reads, samples and gathers differs from Metal's (1,469 differ by default). Under the switch `DeviceNanEncoding` is still announced; the consumer logs notes, so no device fact is built to drop it | NaN bits the device's (`0x7FFF` on the RTX 5080), where Metal hands back a 16-bit float texel's own bits on a read, nearest sample or gather, and `0x7e00` for a 32-bit or small float texel's NaN and a linear sample's. `NativeHalfConversion` (`native-half-conversion`); the read also records `DeviceNanEncoding` (`device-nan-encoding`) | Measured on top of the NaN switch's own row (its probe with the keep, c0a814a13, against its probe without, 3e8a01c54): A2X 341,299 → 347,519 words, 1.82-1.86 → 1.81-1.87 s, GPU 0.115-0.117 → 0.115-0.116 ms, within noise; Xgc14 and Xgc15 read no `half` texel (words unchanged). The full rule (its probe a5c642ebe against the same tip without it, 851650c81): A2X 347,519 → 372,429 words (+7.2%), creation 1.85-1.88 → 1.99-2.04 s; where a linear runtime sampler is bound at the draw the sampler word's filter is now specialized, so the first draw remakes (1.94-1.96 s) and its GPU time rises 0.115-0.117 → 0.124-0.125 ms; with a nearest sampler GPU 0.115-0.116 → 0.115-0.117 ms; Xgc14 and Xgc15 words unchanged. On the RTX 3090 the same pair: A2X creation 2.91-3.06 → 3.17-3.23 s, the first draw's remake 3.0 s and its GPU time 0.17-0.18 → 0.79-1.15 ms, with a nearest sampler 0.17-0.18 ms both |
|
||||
| A fragment function without fast math returns a `half` color to a blended attachment: the device blends in its own arithmetic and rounds once, where Metal blends a 16-bit float attachment in `half` arithmetic (each factor, product and sum rounded to `half`). | `half_blend = HalfBlendPolicy::Device` | `half_blend = HalfBlendPolicy::Exact`: the function computes Metal's blend in the interlocked storage form, for a `half4` output into `R16Float`, `RG16Float` or `RGBA16Float` where that form is exact for the pipeline (RADV, ANV, NVIDIA, MoltenVK); elsewhere, and for lavapipe, 32-bit float, 8-bit, a module naming no math mode or a blend of the second source, the device's blend and its note stay | 2.5 `half` ulps at the largest operand on NVIDIA (the blend color and one minus it), two on RADV, ANV and lavapipe (16-bit float); two `float` ulps (32-bit float, one on NVIDIA); one or two codes (8-bit, extended range); MoltenVK stores Metal's bytes. Measured with and without the factors' magnitudes at 0bcc0163e5. `HalfOutputPrecision` (`half-output-precision`) | A probe at 924fc11603 (a `half4` over a 1920x1080 `RGBA16Float` target, One / OneMinusSourceAlpha): making 11.1 → 24.0 ms; GPU 25 → 82 us one draw, 506 → 2291 us 32 overlapping draws (the interlock orders them). RTX 3090 (the same draw at 50a065eb98): making 12.9 → 27.4 ms; GPU 45 → 115 us one draw, 648 → 3268 us 32 overlapping draws |
|
||||
| A texture over a buffer whose rows (or an array's slices) lie with bytes between them, and which only reads (its usage, as Metal reports it, holds no `RenderTarget`, `ShaderWrite`, `ShaderAtomic` or block writes; `Unknown` holds them all), is an image over the buffer's bytes at Metal's row pitch, as one of packed rows is: the driver's own linear image, a `DRM_FORMAT_MOD_LINEAR` image at that pitch, or one over a dma-buf of the pages. Its subresources hold the bytes between its rows, which Metal never writes, and its first move reaches them. The runtime's choice: no pipeline differs. | `padded_reads = PaddedReadsPolicy::Alias` | `padded_reads = PaddedReadsPolicy::Shadow`: the runtime's shadow image of the texels, copied in from the buffer before each use (`shadowed-texture`), whose copies address the texels alone | The bytes between the rows stay the program's as far as the driver's first move of the image keeps them, unannounced, as for packed rows (the known gap below); `runtime_lane::pitched_surfaces::a_texture_that_only_reads_keeps_every_byte_of_its_pages` fails on a driver whose move changes one | Measured on ANV (Iris Xe, Mesa 26.2.4; `surface_texture_costs::read_only_padded_costs`): a frame that samples four `BGRA8Unorm` tiles over no-copy pages (1307x512 at 5248- and 5376-byte rows, 300x200 at 1216, 1913x96 at 7680) in one pass completes about 0.36 ms later as shadows (the median of 15 interleaved pairs, 0.08 to 0.60 ms), with about 56 µs more encoding and 91 µs more process CPU; a texture's making costs the same either way, about 45 µs |
|
||||
| A computed `half` or `float` color blended into an extended-range attachment (`BGR10_XR`, `BGRA10_XR`, `RGB10A8_2P_XR10`) rounds the blend's source as a loaded one; Metal's compiler rounds it by how it computed it. Every device. | The in-shader blend's loaded rounding (no switch) | **Not built yet:** Metal's rounding per shape is probed, not modelled | One code. `ExtendedRangeBlendSource` (`extended-range-blend-source`), `ExtendedRangeFloatBlendSource` (`extended-range-float-blend-source`) | Not measured |
|
||||
| A bicubic sample of an 8- or 16-bit normalized texture sums its taps exactly and rounds half up; Metal truncates its row terms, row sums and column terms first. Every device. | The exact sum (no switch) | **Not built yet:** Metal's datapath is pinned (17.75M lanes measured, no miss); its emitter is not written | One grid step (1/4080 at 8 bits) within about 2^-21 of a tie. `BicubicFilterArithmetic` (`bicubic-filter-arithmetic`) | Not measured (Metal's form is expected no larger) |
|
||||
| A bicubic sample of an extended-range texture (`BGR10_XR`, `BGRA10_XR`, `RGB10A8_2P_XR10` and their sRGB twins) sums its taps' steps exactly, rounds half up and clamps into the format's decoded endpoints; within 0.014 of a grid step of a rounding tie Metal may round the other way. Every device. | The exact sum (no switch) | **None known:** no model of Metal's datapath tried fits; 3,317,760 lanes measured on the M3 Max (macOS 26.7) | One grid step (1/8160 a color lane, 1/8192 an sRGB color lane, 1/4080 alpha), 4,050 of the lanes measured, each within 0.014 of a step of a tie. `BicubicFilterArithmetic` (`bicubic-filter-arithmetic`) | No accurate form |
|
||||
@@ -144,19 +145,20 @@ driver's. Each is open work.
|
||||
the encoding thread and 2.7 ms through completion less a frame, as nothing is copied back), and
|
||||
one that stores it renders in place at no added cost. Where MoltenVK runs the pass as one
|
||||
unbroken instance, Metal keeps the bytes at no cost.
|
||||
- **A texture over a buffer whose rows lie with bytes between them** (a guest browser's padded
|
||||
surfaces, an array whose slices are rounded up to 128 bytes) is a shadow on every device but
|
||||
MoltenVK (`shadowed-texture`), its texels copied in before each use and back after each write.
|
||||
An image over those rows would hold the bytes between them in its subresource, where Metal
|
||||
leaves them as the program writes them, and Vulkan lets two kinds of operation write them: the
|
||||
image's layout transitions "may perform read and write accesses on all memory bound to the image
|
||||
subresource range", and every image takes one, its first move from the layout it is made in,
|
||||
before any use (so a texture that only reads is a shadow too); and a render pass's load and store
|
||||
operations "read and write back any memory locations within the image subresource bound for that
|
||||
attachment" (lavapipe writes back those its 4-texel blocks reach, a signaling NaN's bits
|
||||
quieted). No query of the device's promises otherwise. On ANV (Mesa 26.2.4) making the browser's 1307x512
|
||||
tile took about 135 µs as a shadow against 41 µs as an image at its row pitch. Packed rows
|
||||
(`bytes_per_row` the texels' bytes) avoid it where the device lays an image's rows there.
|
||||
- **A texture over a buffer whose rows lie with bytes between them, which renders or which a
|
||||
shader writes** (a guest browser's padded surfaces, an array whose slices are rounded up to 128
|
||||
bytes) is a shadow on every device but MoltenVK (`shadowed-texture`), its texels copied in
|
||||
before each use and back after each write. An image over those rows would hold the bytes between
|
||||
them in its subresource, where Metal leaves them as the program writes them, and a render pass's
|
||||
load and store operations "read and write back any memory locations within the image subresource
|
||||
bound for that attachment" (lavapipe writes back those its 4-texel blocks reach, a signaling
|
||||
NaN's bits quieted). No query of the device's promises otherwise. A texture a shader writes and
|
||||
no render pass takes meets them only at its image's first move, as one that only reads does, and
|
||||
is a shadow all the same. One that only reads is an image over its rows by default (the fast
|
||||
default above, `padded_reads = PaddedReadsPolicy::Alias`; the known gap below), and a shadow
|
||||
under the switch. On ANV (Mesa 26.2.4) making the browser's 1307x512 tile took about 135 µs as a
|
||||
shadow against 41 µs as an image at its row pitch. Packed rows (`bytes_per_row` the texels'
|
||||
bytes) avoid it where the device lays an image's rows there.
|
||||
- **A shadow's copy back after a pass that draws covers every texel inside the draws'
|
||||
scissors**, where Metal's store writes back only the 32x32 tiles a draw's primitives touch
|
||||
(reims-vgpu's padding probe on an M3 Max, macOS 27.0.1: a tile with geometry stores its
|
||||
@@ -166,24 +168,42 @@ driver's. Each is open work.
|
||||
copy back can undo it where Metal keeps it: the host does not know which tiles the primitives
|
||||
touch. A pass that reaches no tile copies nothing back, and no copy reaches the bytes between
|
||||
rows.
|
||||
- **A texture's image over pages imported by their pointer keeps their bytes past its first
|
||||
move only because the drivers do.** Vulkan makes an image of host allocations start in
|
||||
`UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`), and a move from `UNDEFINED` "will cause the
|
||||
contents of the image's memory to be undefined"; memory imported from a host pointer "shares
|
||||
ownership of the memory between the host and the Vulkan implementation", host access as to any
|
||||
memory, so no queue-family acquire from outside keeps them either. That holds for the driver's
|
||||
own linear image for host allocations (`texture.rs`'s `host_linear_image`), the
|
||||
`DRM_FORMAT_MOD_LINEAR` image at Metal's row pitch (`host_pitched_image`), and, on MoltenVK,
|
||||
the image of a Metal texture over the import's `MTLBuffer` (`metal_alias_image`; Vulkan says
|
||||
nothing of such an image's contents). lavapipe (Mesa 26.2.4) keeps the bytes
|
||||
(`runtime_lane::pitched_surfaces::a_texture_s_first_use_reads_the_bytes_it_was_made_over`, a
|
||||
first use that reads through the image, fails where a driver drops them). Spec-backed: an
|
||||
image over a dma-buf of its own pages, which its first move acquires from
|
||||
`VK_QUEUE_FAMILY_FOREIGN_EXT` in `GENERAL` (the external memory chapter: "acquire exclusive
|
||||
ownership in the destination instance or API", the `UNDEFINED` initial layout "a placeholder"),
|
||||
and a linear image of the runtime's own memory, made `PREINITIALIZED`. The exact form, a shadow
|
||||
of every texture over such pages (on ANV a tile's making about 135 µs against 41 µs, and a copy
|
||||
in and back at each use), is the owner's call.
|
||||
- **A texture's image over a buffer's bytes keeps them past its first move only because the
|
||||
drivers do**, its texels and, for a texture that only reads over padded rows, the bytes between
|
||||
its rows (which its subresources hold). The first move is the one layout transition such an
|
||||
image takes: every command that uses it after names `GENERAL` (each copy into or out of it, its
|
||||
descriptors), and the encoders' barriers are memory barriers, which transition no layout. A copy
|
||||
writes its region alone ("Each source region specified by pRegions is copied from the source
|
||||
buffer to the destination region of the destination image"; the Memory Model: "A memory
|
||||
operation must not affect memory at a memory location not within its set of memory locations"),
|
||||
and a texture over a buffer has one level, so no mipmap blit reaches it. But the move "may
|
||||
perform read and write accesses on all memory bound to the image subresource range", and Metal
|
||||
never writes the bytes between a texture's rows, keeping a CPU write to them under any GPU work
|
||||
(reims-vgpu's padding probe on an M3 Max, macOS 27.0.1): a move that discards them, or reads and
|
||||
writes them back across a CPU write, differs from Metal there alone. Vulkan makes an image of
|
||||
host allocations start in `UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`), and a move from
|
||||
`UNDEFINED` "will cause the contents of the image's memory to be undefined"; memory imported
|
||||
from a host pointer "shares ownership of the memory between the host and the Vulkan
|
||||
implementation", host access as to any memory, so no queue-family acquire from outside keeps
|
||||
them either. That holds for the driver's own linear image for host allocations (`texture.rs`'s
|
||||
`host_linear_image`), the `DRM_FORMAT_MOD_LINEAR` image at Metal's row pitch
|
||||
(`host_pitched_image`), and, on MoltenVK, the image of a Metal texture over the import's
|
||||
`MTLBuffer` (`metal_alias_image`; Vulkan says nothing of such an image's contents). lavapipe
|
||||
and ANV (Mesa 26.2.4), RADV (Mesa 26.2.4 on the Radeon 780M, 26.0.8 on the RX 7900 XTX) and
|
||||
NVIDIA 615.71.09 (RTX 3090, RTX 5080 Laptop GPU) keep the bytes, the bytes between the rows of
|
||||
every padded layout each aliases among them
|
||||
(`runtime_lane::pitched_surfaces::a_texture_s_first_use_reads_the_bytes_it_was_made_over`, and
|
||||
for padded rows `a_texture_that_only_reads_keeps_every_byte_of_its_pages` and
|
||||
`a_padded_texture_that_only_reads_over_an_ordinary_buffer_keeps_its_bytes`, each a first use
|
||||
that reads through the image and then every byte of the pages checked, fail where a driver
|
||||
changes one; their blits into the image check that a copy writes its region alone). Spec-backed for the contents, not for a CPU write during the move: an image over a dma-buf
|
||||
of its own pages, which its first move acquires from `VK_QUEUE_FAMILY_FOREIGN_EXT` in `GENERAL`
|
||||
(the external memory chapter: "acquire exclusive ownership in the destination instance or API",
|
||||
the `UNDEFINED` initial layout "a placeholder"), and a linear image of the runtime's own memory,
|
||||
made `PREINITIALIZED`. The exact form, a shadow of every texture over such pages (on ANV a
|
||||
tile's making about 135 µs against 41 µs, and a copy in and back at each use), is the owner's
|
||||
call for packed rows; for padded rows that only read it is `padded_reads =
|
||||
PaddedReadsPolicy::Shadow`.
|
||||
- **A cold pipeline making on NVIDIA grows with a module's sampling sites.** NVIDIA's compiler
|
||||
(615.71.09) takes about 1 s for macOS 26's largest CoreAnimation fragment (210,033 words) on the
|
||||
RTX 5080 Laptop GPU, made once per cold cache (the first boot, and after an update changes the
|
||||
|
||||
+17
-11
@@ -176,19 +176,25 @@ rebind that cannot make the image again is refused (`NotImplemented(RebindTextur
|
||||
`WorkCounts::dma_buf_imports`, `dma_buf_sparse_buffers`, `dma_buf_images` and
|
||||
`dma_buf_image_fallbacks` count what the route did.
|
||||
|
||||
A texture over a buffer's bytes is an image over them only where its rows lie one after another
|
||||
A texture over a buffer's bytes is an image over them where its rows lie one after another
|
||||
(`bytes_per_row` is its texels' bytes, or it has one row; an array's slices likewise) and the
|
||||
image holds no byte past its texels. A texture whose rows lie with bytes between them, as a guest
|
||||
browser's padded surfaces' do, is a shadow (`shadowed-texture`) on every device but MoltenVK, whose
|
||||
image is a Metal texture over the buffer: an image at that pitch holds the bytes between the rows
|
||||
in its subresource (`VkSubresourceLayout`: "size includes any extra memory that is required based
|
||||
on rowPitch"), and Vulkan lets two kinds of operation write them, where Metal leaves them as the
|
||||
program writes them. The image's layout transitions "may perform read and write accesses on all
|
||||
memory bound to the image subresource range", and every image takes one, its first move from the
|
||||
layout it is made in, before any use, so a texture that only reads is a shadow too. A render pass's
|
||||
load and store operations "read and write back any memory locations within the image subresource
|
||||
bound for that attachment" (lavapipe writes back the bytes its 4-texel blocks reach past a row, a
|
||||
signaling NaN's bits quieted). No query of the device's states otherwise. To keep a surface
|
||||
browser's padded surfaces' do, is one only where it only reads (no `RenderTarget`, `ShaderWrite`,
|
||||
`ShaderAtomic` or block-write usage; `Unknown` usage counts as all of them), under the default
|
||||
`padded_reads = PaddedReadsPolicy::Alias`; otherwise it is a shadow (`shadowed-texture`) on every
|
||||
device but MoltenVK, whose image is a Metal texture over the buffer. An image at that pitch holds
|
||||
the bytes between the rows in its subresource (`VkSubresourceLayout`: "size includes any extra
|
||||
memory that is required based on rowPitch"), and Vulkan lets two kinds of operation write them,
|
||||
where Metal leaves them as the program writes them. The image's layout transitions "may perform
|
||||
read and write accesses on all memory bound to the image subresource range", and every image takes
|
||||
one, its first move from the layout it is made in, before any use; the runtime's images take no
|
||||
other. A render pass's load and store operations "read and write back any memory locations within
|
||||
the image subresource bound for that attachment" (lavapipe writes back the bytes its 4-texel blocks
|
||||
reach past a row, a signaling NaN's bits quieted). No query of the device's states otherwise. So a
|
||||
texture that renders or that a shader writes is a shadow, and one that only reads keeps the bytes
|
||||
between its rows as far as the driver's first move does (docs/FAST-PATHS.md's known gap, checked
|
||||
per driver by the validation lane); `padded_reads = PaddedReadsPolicy::Shadow`, which
|
||||
`DevicePolicy::exact_answers()` selects, makes it a shadow too. To keep a surface that renders
|
||||
aliased, lay its rows packed.
|
||||
|
||||
Over pages imported by their pointer, such a texture aliases them where the device lays an image's
|
||||
|
||||
Reference in new issue
Block a user