rt: a resolve into a texture in place over a buffer whose linear image cannot render goes through a resolve image
For the consumer: a pass that resolves into a texture in place over a buffer of the runtime's
own memory, whose linear image takes no colour attachment usage, is no longer refused with
Gap::RenderPass{ResolveUsage}. It resolves into the texture's resolve image, and the pass's end
copies the render area into the buffer at the texture's pitch. This is the guest's 600 x 600
BGRA8Unorm_sRGB ShaderRead texture over a Managed buffer, on every NVIDIA host and on KosmicKrisp:
their linear tiling features hold COLOR_ATTACHMENT for no format (count jobs m3-max-67031 and
m3-max-67032), and a pitch of the row rounded up to the alignment answer (128 and 16) lies in place.
It also covers a texture whose subresource reaches past its own rows or its buffer (the render-reach
rule), on every device. Additive public items: Metrics::resolve_copies and resolve_copy_bytes (in
bytes_copied too), Gauges::resolve_images and resolve_image_bytes. Still refused: a texture in place
over a dma-buf's import (an imported surface's memory) and a view of a texture in place.
Why this form: owner's rule 3 allows "where a format query offers no linear image for the format and
usage, a counted copy", the sentence OverCause::LinearFeatures and RenderReach already rest on for a
render target over a buffer. This is the smallest such copy: one per resolve, of the render area
only, and nothing on later uses. The texture stays in place, so shaders keep reading the buffer's
bytes through its linear image. The planner chose it over moving the texture to the copy form at
its first resolve (2,880,000 bytes per resolving pass, then a copy in every submission that uses
it).
How:
- texture.rs: the in-place texture's Image keeps a Resolving where it lies in the runtime's own
memory (Laid::Own), its linear image took no attachment usage, and its plan's optimal image does
(Plan::resolves, the image format query that already made it with COLOR_ATTACHMENT). The first
resolve makes the resolve image from the texture's plan (Plan::resolved, Bind::Pooled) and a 2D
identity view of it. Every later resolve reuses them, and they are freed with the texture
(Free::Resolved, the resolve images gauges). resolve_attachment returns the attachment and, for a
resolve image, a ResolveCopy: the VkBuffer of the bytes shaders reach and the region at the
texture's pitch. That is Named::region, the region copied_over already built, now shared. A level,
slice or layer count past the texture's one is Refusal::AttachmentPlace, as attachment_view
refuses it.
- pass.rs: Resolve carries the copy. Its image's home is TRANSFER_SRC_OPTIMAL and it renders in
ATTACHMENT_OPTIMAL. Resolve::from moves it away from UNDEFINED: the pass resolves every texel of
its render area and copies only those, so nothing it held earlier is kept.
- render_encoder.rs: after the pass's back barrier (which moves the image to TRANSFER_SRC_OPTIMAL),
end() records vkCmdCopyImageToBuffer of the render area (Pass::reach) into the buffer at the
texture's pitch. It counts the copy and owes the pass's barrier, so the next command, or the
segment's end, orders the copy before later work. bufferOffset is a whole number of texels, which
check_over already requires (VUID-vkCmdCopyImageToBuffer-srcImage-07975; the multiple-of-4 rule,
07978, is depth and stencil only). The block's buffer has TRANSFER_DST.
Readable through the linear image: the copy writes the buffer, and a later pass reads the same
memory through the texture's linear image. Vulkan 12.11 Memory Aliasing says "If two aliases are
both host-accessible, then they interpret the contents of the memory in consistent ways, and data
written to one alias can be read by the other alias". Buffers, and linear image subresources in
GENERAL or PREINITIALIZED, are host-accessible. The in-place form already rests on that sentence:
its linear image starts preinitialized and stays GENERAL through every use, copies included
(Image::copy_layout, "so that it and the buffer are aliases that interpret their bytes alike
(Vulkan's memory aliasing)"). The order between the copy and the read is the owed barrier, a memory
barrier from every command to every command.
Docs: RenderPassKind::ResolveUsage, the resolve texture's doc, resolve_attachment's and resolve()'s
docs, and the pass module say what resolves through the resolve image and what is still refused.
The runtime README's two Render encoders paragraphs and its counters list are updated, the card
names under "measured on". docs/REFUSALS.md is regenerated (two more AttachmentPlace sites, in
resolve_attachment), and so is the signatures table (the four new fields).
Test: every_device_resolves_a_loaded_pass_into_a_shader_read_texture_over_a_buffer runs the
guest's shape over a Managed and over a Shared buffer, at 2,400, at the row rounded to the alignment
answer, and at 2,560. On an in-place row whose linear image took no attachment usage, it asserts:
- the first resolve makes exactly one image;
- one resolve copy of 1,440,000 bytes, and bytes_copied equal to it;
- the buffer reads the clear within one code, with 0 bytes past the texels changed;
- a pass after it in the same command buffer reads the texture at each pixel (own_pixel_fragment
into a 600 x 600 target), its centre texel (299, 300) the clear within one code;
- a second resolve, in a command buffer of its own, makes no image and no allocation
(image_creates, consumer_allocations), and the resolve images gauge does not grow.
The other rows are unchanged: in place with the usage, 0 copies; copied, counted copies. Every
gauge is zero at device drop (each_device). Without this change, the RTX 3090's in-place row at
2,432 is refused with ResolveUsage (job m3-max-67081 on the resolve fix's tree).
This commit is contained in:
1 parent
ebbce6789c
commit
bda5ed08e9
10 files changed
+508
-128
No files matched your search
@@ -211,7 +211,8 @@ bound and its blob writes skipped past it (`pipeline_caches_replaced`,
|
||||
`pipeline_cache_writes_skipped`, The cache directory below); the dispatches that ran a kernel's
|
||||
emulated-SIMD-group module (`emulated_simdgroup_dispatches`, Compute pipeline states below); the
|
||||
compiled contents a state's make dropped because an equal one landed in the device's map first
|
||||
(`kernel_makes_dropped`);
|
||||
(`kernel_makes_dropped`); the copies of resolve images into the buffers their textures lie over
|
||||
(`resolve_copies` and `resolve_copy_bytes`, Render encoders below);
|
||||
`gauges()` are live counts per kind of resource, every one zero after teardown, and
|
||||
`handles_out`, 1 while a handle of the device is out (Teardown). They are relaxed atomics, always
|
||||
on. What an encoder's commands count arrives when the encoder ends.
|
||||
@@ -3555,19 +3556,25 @@ cache is answered compile-required on both.
|
||||
takes the attachment usage on every device where its format renders, whatever Metal's usage.
|
||||
So does the linear image of a texture in place over a buffer of the runtime's own memory, where
|
||||
the device's linear tiling renders its format and its image format query makes the image with
|
||||
the usage, which left its layout as it was on every venue counted. A resolve into a texture made
|
||||
without `RenderTarget` usage whose image has no attachment usage is a known gap
|
||||
(`RenderPassKind::ResolveUsage`): a depth or stencil texture, a colour texture of another type
|
||||
or of a format the device's optimal image does not render, and a texture in place over a buffer
|
||||
whose linear image takes none. On the RTX 3090 and on KosmicKrisp that is every texture in place
|
||||
over a buffer, as their linear tiling features hold the attachment for no format (and a pitch of
|
||||
the row rounded up to the alignment answer, 128 and 16, lies in place). Elsewhere it is one over
|
||||
a dma-buf's import, one of a format the device's linear tiling does not render, and one whose
|
||||
subresource reaches past its own rows or its buffer, as a resolve "may read and write back any
|
||||
memory locations within the image subresource bound for that attachment" (Vulkan's multisample
|
||||
resolve operations): on every venue counted, a buffer that ends at the texture's last texel
|
||||
where its rows are padded.
|
||||
Such a texture stays in place, never copied to gain the usage. Refused as
|
||||
the usage, which left its layout as it was on every venue counted. Where such a texture's linear
|
||||
image takes none, the texture stays in place and the resolve is a counted copy, a known gap: the
|
||||
pass resolves into the texture's resolve image, a one-sample optimal image of its format and
|
||||
size made at the first pass that resolves into it and freed with it (`Gauges::resolve_images`
|
||||
and `resolve_image_bytes`), and the pass's end copies the render area's texels into the buffer
|
||||
at the texture's pitch, leaving the bytes past each row's texels as they were. That is one copy
|
||||
per resolve, 1,440,000 bytes for a 600 x 600 `BGRA8Unorm_sRGB` pass, and none on the texture's
|
||||
later uses (`Metrics::resolve_copies` and `resolve_copy_bytes`, in `bytes_copied` too); Metal
|
||||
makes no such copy. A linear image takes no attachment usage where the device's format query
|
||||
offers no linear image of the format with it (measured on the RTX 3090 and on KosmicKrisp, for
|
||||
every format, where a pitch of the row rounded up to the alignment answer, 128 and 16, lies in
|
||||
place), and where its subresource reaches past its own rows or its buffer, as a resolve "may
|
||||
read and write back any memory locations within the image subresource bound for that
|
||||
attachment" (Vulkan's multisample resolve operations; measured on every venue counted where a
|
||||
buffer ends at the texture's last texel and its rows are padded). A resolve into a texture made
|
||||
without `RenderTarget` usage whose image has no attachment usage and that has no resolve image
|
||||
is a known gap (`RenderPassKind::ResolveUsage`): a depth or stencil texture, a colour texture of
|
||||
another type or of a format the device's optimal image does not render, a texture in place over
|
||||
a dma-buf's import, and a view of a texture in place over a buffer. Refused as
|
||||
Metal refuses it: a resolving action with no resolve texture (`Refusal::ResolveTexture`, also
|
||||
where an encoder sets it later) and an integer format's resolve (`Refusal::ResolveFormat`).
|
||||
`Metrics::resolves` counts the attachments passes resolved.
|
||||
@@ -3967,12 +3974,13 @@ cache is answered compile-required on both.
|
||||
resolves into a texture of any usage; Vulkan only into a view with the attachment usage,
|
||||
`VUID-VkRenderingInfo-colorAttachmentCount-09476`, which a one-sample colour texture of an
|
||||
optimal image takes where its format renders, and a texture's linear image in place over a
|
||||
buffer of the runtime's own memory where the device's linear tiling renders its format, and a
|
||||
depth or stencil texture does not, nor a texture in place on the RTX 3090 or KosmicKrisp, whose
|
||||
linear tiling features hold the attachment for no format, over a dma-buf's import, or whose
|
||||
subresource reaches past its own rows or its buffer, which a resolve may write back whole; the
|
||||
usage grows a 1920 x 1080 `RGBA8Unorm` optimal image of one level 1.0056 times on the Radeon
|
||||
780M and changes no linear image's layout, `RenderPassKind::ResolveUsage` has the measures),
|
||||
buffer of the runtime's own memory where the device's linear tiling renders its format (where
|
||||
it does not, or where its subresource reaches past its own rows or its buffer, the pass resolves
|
||||
into the texture's resolve image and copies it into the buffer, above), and a depth or stencil
|
||||
texture does not, nor a texture in place over a dma-buf's import, nor a view of a texture in
|
||||
place; the usage grows a 1920 x 1080 `RGBA8Unorm` optimal image of one level 1.0056 times on
|
||||
the Radeon 780M and changes no linear image's layout, `RenderPassKind::ResolveUsage` has the
|
||||
measures),
|
||||
a depth or stencil resolve the device's resolve modes do not offer (`ResolveFilter`: `Min` or
|
||||
`Max` where `supportedDepthResolveModes` lacks it, the stencil filter `DepthResolvedSample`,
|
||||
which no Vulkan resolve mode is, and two aspects paired where `independentResolve` or
|
||||
|
||||
@@ -438,6 +438,10 @@ pub(crate) enum Gauge {
|
||||
Shadows,
|
||||
/// [`Gauges::shadow_bytes`].
|
||||
ShadowBytes,
|
||||
/// [`Gauges::resolve_images`].
|
||||
ResolveImages,
|
||||
/// [`Gauges::resolve_image_bytes`].
|
||||
ResolveImageBytes,
|
||||
/// [`Gauges::textures_copied_over`].
|
||||
TexturesCopiedOver,
|
||||
/// [`Gauges::timestamp_pools`].
|
||||
@@ -684,6 +688,8 @@ struct Atomics {
|
||||
over_by_cause: [[AtomicU64; 2]; OVER_CAUSES],
|
||||
attachment_read_copies: AtomicU64,
|
||||
attachment_read_copy_bytes: AtomicU64,
|
||||
resolve_copies: AtomicU64,
|
||||
resolve_copy_bytes: AtomicU64,
|
||||
attachment_loop_reads: AtomicU64,
|
||||
allocations_freed: AtomicU64,
|
||||
submissions_during_frees: AtomicU64,
|
||||
@@ -766,6 +772,8 @@ struct Atomics {
|
||||
pipeline_cache_bytes: AtomicU64,
|
||||
shadows: AtomicU64,
|
||||
shadow_bytes: AtomicU64,
|
||||
resolve_images: AtomicU64,
|
||||
resolve_image_bytes: AtomicU64,
|
||||
textures_copied_over: AtomicU64,
|
||||
timestamp_pools: AtomicU64,
|
||||
occlusion_pools: AtomicU64,
|
||||
@@ -1302,6 +1310,16 @@ impl Counters {
|
||||
a.bytes_copied.fetch_add(bytes, Relaxed);
|
||||
}
|
||||
|
||||
/// A copy of what a pass resolved into a resolve image, of `bytes`
|
||||
/// ([`Metrics::resolve_copies`], [`Metrics::resolve_copy_bytes`]), which counts in
|
||||
/// [`Metrics::bytes_copied`] too.
|
||||
pub(crate) fn resolve_copied(&self, bytes: u64) {
|
||||
let a = &self.atomics;
|
||||
a.resolve_copies.fetch_add(1, Relaxed);
|
||||
a.resolve_copy_bytes.fetch_add(bytes, Relaxed);
|
||||
a.bytes_copied.fetch_add(bytes, Relaxed);
|
||||
}
|
||||
|
||||
/// `bytes` more of a new buffer zeroed ([`Metrics::bytes_zeroed`]).
|
||||
pub(crate) fn zeroed(&self, bytes: u64) {
|
||||
self.atomics.bytes_zeroed.fetch_add(bytes, Relaxed);
|
||||
@@ -1495,6 +1513,8 @@ impl Counters {
|
||||
Gauge::PipelineCacheBytes => &a.pipeline_cache_bytes,
|
||||
Gauge::Shadows => &a.shadows,
|
||||
Gauge::ShadowBytes => &a.shadow_bytes,
|
||||
Gauge::ResolveImages => &a.resolve_images,
|
||||
Gauge::ResolveImageBytes => &a.resolve_image_bytes,
|
||||
Gauge::TexturesCopiedOver => &a.textures_copied_over,
|
||||
Gauge::TimestampPools => &a.timestamp_pools,
|
||||
Gauge::OcclusionPools => &a.occlusion_pools,
|
||||
@@ -1714,6 +1734,8 @@ impl Counters {
|
||||
over_copy_bytes_image_memory: over(OverCause::ImageMemory)[1],
|
||||
attachment_read_copies: a.attachment_read_copies.load(Relaxed),
|
||||
attachment_read_copy_bytes: a.attachment_read_copy_bytes.load(Relaxed),
|
||||
resolve_copies: a.resolve_copies.load(Relaxed),
|
||||
resolve_copy_bytes: a.resolve_copy_bytes.load(Relaxed),
|
||||
attachment_loop_reads: a.attachment_loop_reads.load(Relaxed),
|
||||
allocations_freed: a.allocations_freed.load(Relaxed),
|
||||
submissions_during_frees: a.submissions_during_frees.load(Relaxed),
|
||||
@@ -1828,6 +1850,8 @@ impl Counters {
|
||||
pipeline_cache_bytes: a.pipeline_cache_bytes.load(Relaxed),
|
||||
shadows: a.shadows.load(Relaxed),
|
||||
shadow_bytes: a.shadow_bytes.load(Relaxed),
|
||||
resolve_images: a.resolve_images.load(Relaxed),
|
||||
resolve_image_bytes: a.resolve_image_bytes.load(Relaxed),
|
||||
textures_copied_over: a.textures_copied_over.load(Relaxed),
|
||||
timestamp_pools: a.timestamp_pools.load(Relaxed),
|
||||
occlusion_pools: a.occlusion_pools.load(Relaxed),
|
||||
@@ -2014,8 +2038,9 @@ pub struct Metrics {
|
||||
pub barriers: u64,
|
||||
/// Bytes the runtime copied for a call: `replace_region` and `get_bytes` staging, the copies
|
||||
/// between a texture over a buffer and its image of its own
|
||||
/// ([`over_copy_bytes`](Self::over_copy_bytes)), and the copies of attachments' images into their
|
||||
/// shadows ([`attachment_read_copy_bytes`](Self::attachment_read_copy_bytes)). A blit's own
|
||||
/// ([`over_copy_bytes`](Self::over_copy_bytes)), the copies of attachments' images into their
|
||||
/// shadows ([`attachment_read_copy_bytes`](Self::attachment_read_copy_bytes)), and the copies of
|
||||
/// resolve images into buffers ([`resolve_copy_bytes`](Self::resolve_copy_bytes)). A blit's own
|
||||
/// copy, and a synchronize's, is the program's and is not counted.
|
||||
pub bytes_copied: u64,
|
||||
/// Bytes of new buffers zeroed: [`Device::new_buffer`](crate::Device::new_buffer)'s from its
|
||||
@@ -2346,6 +2371,13 @@ pub struct Metrics {
|
||||
pub attachment_read_copies: u64,
|
||||
/// The bytes of those copies, which count in [`bytes_copied`](Self::bytes_copied) too.
|
||||
pub attachment_read_copy_bytes: u64,
|
||||
/// Copies of what a pass resolved into a texture's resolve image, which Metal does not make:
|
||||
/// one for each resolve into a texture in place over a buffer whose linear image takes no
|
||||
/// attachment usage, of the pass's render area into the buffer's bytes at the texture's pitch
|
||||
/// as the pass ends. The images are [`Gauges::resolve_images`].
|
||||
pub resolve_copies: u64,
|
||||
/// The bytes of those copies, which count in [`bytes_copied`](Self::bytes_copied) too.
|
||||
pub resolve_copy_bytes: u64,
|
||||
/// Draws that read an attachment of their own pass through the attachment feedback loop, a
|
||||
/// fragment function's colour read (`[[color(n)]]`) or a texture argument over the
|
||||
/// attachment: each with the image in the feedback layout, after the barrier that moved it
|
||||
@@ -2922,6 +2954,12 @@ pub struct Gauges {
|
||||
pub shadows: u64,
|
||||
/// The bytes of the shadows' memory.
|
||||
pub shadow_bytes: u64,
|
||||
/// Resolve images: one for each texture in place over a buffer whose linear image takes no
|
||||
/// attachment usage that a pass resolved into, made at the first such pass and freed with
|
||||
/// the texture ([`Metrics::resolve_copies`]).
|
||||
pub resolve_images: u64,
|
||||
/// The bytes of the resolve images' memory.
|
||||
pub resolve_image_bytes: u64,
|
||||
/// Textures over a buffer the runtime holds in an image of their own, where the device's
|
||||
/// linear image does not take the texture or the buffer's bytes are imported
|
||||
/// ([`Buffer::new_texture`](crate::Buffer::new_texture)): the copies between them and their
|
||||
|
||||
@@ -1789,17 +1789,22 @@ pub enum RenderPassKind {
|
||||
/// (VUID-VkRenderingInfo-pDepthAttachment-06086).
|
||||
Resolve,
|
||||
/// A resolve into a texture made without `RenderTarget` usage (and not of Metal's unknown
|
||||
/// usage) whose image has no attachment usage: a depth or stencil texture; a colour texture of
|
||||
/// a type but 2D, a 2D array, a cube or a cube array, or whose format the device's optimal
|
||||
/// image does not render, by its format features or its image format query at the texture's
|
||||
/// extent; or a texture in place over a buffer whose linear image takes none: over a dma-buf's
|
||||
/// import; of a format the device's linear tiling does not render, by its linear features or
|
||||
/// its image format query at the texture's extent (on the RTX 3090 and KosmicKrisp, every
|
||||
/// format); or whose
|
||||
/// subresource reaches past its own rows or its buffer, as a resolve "may read and write back
|
||||
/// any memory locations within the image subresource bound for that attachment" (Vulkan's
|
||||
/// multisample resolve operations). Such a texture stays in place, and is never copied to
|
||||
/// gain the usage.
|
||||
/// usage) whose image has no attachment usage and that has no resolve image: a depth or
|
||||
/// stencil texture; a colour texture of a type but 2D, a 2D array, a cube or a cube array, or
|
||||
/// whose format the device's optimal image does not render, by its format features or its
|
||||
/// image format query at the texture's extent; a texture in place over a dma-buf's import (an
|
||||
/// imported surface's memory, whose bytes reach its image through the import's acquire); and
|
||||
/// a view of a texture in place over a buffer. A texture in place over a buffer of the
|
||||
/// runtime's own memory whose linear image takes none (of a format the device's linear tiling
|
||||
/// does not render, by its linear features or its image format query at the texture's extent,
|
||||
/// measured on the RTX 3090 and KosmicKrisp for every format; or whose subresource reaches
|
||||
/// past its own rows or its buffer, as a resolve "may read and write back any memory locations
|
||||
/// within the image subresource bound for that attachment", Vulkan's multisample resolve
|
||||
/// operations) stays in place and is resolved into: the pass resolves into the texture's
|
||||
/// resolve image, a one-sample optimal image of its plan made at the first such pass and
|
||||
/// freed with it, and its end copies the render area into the buffer's bytes at the texture's
|
||||
/// pitch, the bytes past each row's texels untouched (`Metrics::resolve_copies`, a copy Metal
|
||||
/// does not make).
|
||||
/// Metal resolves into a texture of any usage: probe `resolve_texture_usage.m` in the
|
||||
/// conformance crate (an Apple M3 Max, macOS 27.0.1, job m3-max-59768) resolved a 4-sample
|
||||
/// `BGRA8Unorm_sRGB` attachment into a texture of `ShaderRead` usage and of `ShaderRead |
|
||||
|
||||
@@ -34,7 +34,10 @@
|
||||
//! [`MultisampleStencilResolveFilter`]'s, where the device's resolve modes offer them. Either
|
||||
//! action stores the multisample texels too, as a `DontCare` store does: a rendering the encoder
|
||||
//! ends early and begins again resolves again as it ends, and its last resolve holds the pass's
|
||||
//! whole result.
|
||||
//! whole result. A texture in place over a buffer whose linear image takes no attachment usage is
|
||||
//! resolved into through its resolve image (`Resolve::copy`): the pass moves the image from
|
||||
//! undefined, resolves into it, moves it to the transfer source layout as it ends, and the
|
||||
//! encoder's end copies Vulkan's render area of it into the buffer's bytes at the texture's pitch.
|
||||
//!
|
||||
//! A surface plane that renders as a linear colour attachment alone ([`Attachment::linear`]:
|
||||
//! `VK_NV_linear_color_attachment`'s `LINEAR` image, `crate::surface`) renders only in a pass whose
|
||||
@@ -45,7 +48,7 @@
|
||||
use crate::buffer::{Buffer, BufferObject};
|
||||
use crate::device::Core;
|
||||
use crate::error::{Error, Gap, LinearPlanePassKind, Refusal, RenderPassKind};
|
||||
use crate::texture::{Attachment, Texture, TextureObject};
|
||||
use crate::texture::{Attachment, ResolveCopy, Texture, TextureObject};
|
||||
use ash::vk;
|
||||
use metal2vulkan::metal::format::{self as formats, FormatEmulation};
|
||||
use metal2vulkan::metal::PixelFormat;
|
||||
@@ -223,10 +226,15 @@ pub struct RenderPassColorAttachmentDescriptor {
|
||||
/// attachment's pixel format and one sample, and its level the attachment level's width and
|
||||
/// height; another is [`Gap::RenderPass`] of [`RenderPassKind::Resolve`]. Metal resolves into
|
||||
/// a texture of any usage, and so does the runtime into a colour texture whose format the
|
||||
/// device's optimal image renders, and into one in place over a buffer whose format the
|
||||
/// device's linear tiling renders; into one made without `RenderTarget` usage whose image has
|
||||
/// no attachment usage, such as a texture in place over a buffer whose linear tiling does not
|
||||
/// render its format, it is [`Gap::RenderPass`] of [`RenderPassKind::ResolveUsage`].
|
||||
/// device's optimal image renders, into one in place over a buffer whose format the device's
|
||||
/// linear tiling renders, and into one in place over a buffer of the runtime's own memory
|
||||
/// whose linear image does not render, through the texture's resolve image, which the pass's
|
||||
/// end copies into the buffer (a copy Metal does not make, [`Metrics::resolve_copies`]); into
|
||||
/// one made without `RenderTarget` usage whose image has no attachment usage and that has no
|
||||
/// resolve image, such as a texture in place over a dma-buf's import, it is
|
||||
/// [`Gap::RenderPass`] of [`RenderPassKind::ResolveUsage`].
|
||||
///
|
||||
/// [`Metrics::resolve_copies`]: crate::Metrics::resolve_copies
|
||||
pub resolve_texture: Option<Texture>,
|
||||
/// `resolveLevel`: the resolve texture's mipmap level resolved into.
|
||||
pub resolve_level: u32,
|
||||
@@ -450,6 +458,10 @@ pub(crate) struct Resolve {
|
||||
/// whose home is shader-read-only, which the pass moves there and back.
|
||||
pub(crate) layout: vk::ImageLayout,
|
||||
pub(crate) mode: vk::ResolveModeFlags,
|
||||
/// Where it resolves into the texture's resolve image, in place of a linear image that takes
|
||||
/// no attachment usage: the copy of the image into the buffer's bytes, which the pass's end
|
||||
/// records, cut to its render area (`Texture::resolve_attachment`).
|
||||
pub(crate) copy: Option<ResolveCopy>,
|
||||
}
|
||||
|
||||
impl Resolve {
|
||||
@@ -458,6 +470,16 @@ impl Resolve {
|
||||
self.layout != self.attachment.home
|
||||
}
|
||||
|
||||
/// The layout the pass moves its image away from: its home, or undefined for a resolve image
|
||||
/// (`copy`), which keeps nothing between passes: each resolves every texel of its render
|
||||
/// area into it, and copies those alone.
|
||||
pub(crate) fn from(&self) -> vk::ImageLayout {
|
||||
match self.copy {
|
||||
Some(_) => vk::ImageLayout::UNDEFINED,
|
||||
None => self.attachment.home,
|
||||
}
|
||||
}
|
||||
|
||||
/// The barrier that moves its level and layers, every aspect, from `old` to `new`, after
|
||||
/// every earlier command and before every later one.
|
||||
pub(crate) fn barrier(
|
||||
@@ -1070,7 +1092,7 @@ struct ResolveInto<'a> {
|
||||
/// width and height; [`Gap::RenderPass`] of [`RenderPassKind::TextureType`] for a depth plane
|
||||
/// but 0; what the resolve texture's resolve attachment returns, [`Gap::RenderPass`] of
|
||||
/// [`RenderPassKind::ResolveUsage`] for a resolve texture whose image has no attachment usage
|
||||
/// among it.
|
||||
/// and that has no resolve image among it.
|
||||
fn resolve(
|
||||
core: &Arc<Core>,
|
||||
texture: &Texture,
|
||||
@@ -1089,15 +1111,19 @@ fn resolve(
|
||||
{
|
||||
return gap(RenderPassKind::Resolve);
|
||||
}
|
||||
let view = (into.texture).resolve_attachment(into.level, into.slice, attachment.layers)?;
|
||||
let (view, copy) =
|
||||
(into.texture).resolve_attachment(into.level, into.slice, attachment.layers)?;
|
||||
if into.depth_plane != 0 {
|
||||
return gap(RenderPassKind::TextureType);
|
||||
}
|
||||
if view.extent != attachment.extent || view.format != attachment.format {
|
||||
return gap(RenderPassKind::Resolve);
|
||||
}
|
||||
// A resolve image's home is the layout its copy reads it in.
|
||||
let layout = match view.home {
|
||||
vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL => vk::ImageLayout::ATTACHMENT_OPTIMAL,
|
||||
vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL | vk::ImageLayout::TRANSFER_SRC_OPTIMAL => {
|
||||
vk::ImageLayout::ATTACHMENT_OPTIMAL
|
||||
}
|
||||
home => home,
|
||||
};
|
||||
Ok(Resolve {
|
||||
@@ -1105,6 +1131,7 @@ fn resolve(
|
||||
attachment: view,
|
||||
layout,
|
||||
mode,
|
||||
copy,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,15 @@ pub(crate) enum Free {
|
||||
},
|
||||
/// A dropped texture's view of its image's shadow.
|
||||
ShadowView(vk::ImageView),
|
||||
/// A dropped texture's resolve image (`crate::texture`'s `Resolved`), its attachment view
|
||||
/// and its memory of `bytes`, freed as a texture's are; the resolve images gauges fall with
|
||||
/// it.
|
||||
Resolved {
|
||||
view: vk::ImageView,
|
||||
image: vk::Image,
|
||||
backing: Backing,
|
||||
bytes: u64,
|
||||
},
|
||||
/// A dropped texture's attachment views; the attachment views gauge falls with each.
|
||||
AttachmentViews(Vec<vk::ImageView>),
|
||||
/// A device sampler no sampler state holds; the device samplers gauge falls with it.
|
||||
@@ -231,6 +240,22 @@ pub(crate) fn free(core: &Core, object: Free) {
|
||||
// SAFETY: no pending work uses it: every command buffer that read through it held its
|
||||
// texture until it retired, and its element of set 1 is null or another texture's.
|
||||
Free::ShadowView(view) => unsafe { device.destroy_image_view(view, None) },
|
||||
Free::Resolved {
|
||||
view,
|
||||
image,
|
||||
backing,
|
||||
bytes,
|
||||
} => {
|
||||
// SAFETY: no pending work uses them: every command buffer whose pass resolved into
|
||||
// the image held its texture until it retired.
|
||||
unsafe {
|
||||
device.destroy_image_view(view, None);
|
||||
device.destroy_image(image, None);
|
||||
free_backing(core, backing);
|
||||
}
|
||||
core.counters.fall(Gauge::ResolveImages);
|
||||
core.counters.fall_by(Gauge::ResolveImageBytes, bytes);
|
||||
}
|
||||
Free::AttachmentViews(views) => {
|
||||
// SAFETY: no pending work uses them: every command buffer whose pass rendered into
|
||||
// the texture held it until it retired.
|
||||
|
||||
@@ -848,7 +848,7 @@ fn begin(
|
||||
away.extend(
|
||||
(pass.resolves())
|
||||
.filter(|r| r.moves())
|
||||
.map(|r| r.barrier(r.attachment.home, r.layout)),
|
||||
.map(|r| r.barrier(r.from(), r.layout)),
|
||||
);
|
||||
}
|
||||
let device = &core.device;
|
||||
@@ -3452,6 +3452,34 @@ impl RenderCommandEncoder {
|
||||
}
|
||||
building.count(Metric::Barriers);
|
||||
}
|
||||
// A resolve into a resolve image copies its render area into the buffer's bytes, at the
|
||||
// texture's pitch, after the barrier that moved the image home; the barrier that orders
|
||||
// the copy before later commands, and their reads of the bytes through the texture's
|
||||
// linear image, is owed.
|
||||
let [width, height] = self.pass.reach;
|
||||
let copies = (self.pass.resolving.then(|| self.pass.resolves()))
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|r| Some((r.attachment.image, r.copy.as_ref()?)));
|
||||
for (image, copy) in copies {
|
||||
let region = vk::BufferImageCopy {
|
||||
image_extent: vk::Extent3D {
|
||||
width,
|
||||
height,
|
||||
depth: 1,
|
||||
},
|
||||
..copy.region
|
||||
};
|
||||
let source = vk::ImageLayout::TRANSFER_SRC_OPTIMAL;
|
||||
// SAFETY: the command buffer records outside any rendering and keeps the texture, and
|
||||
// so the image and the buffer, until it retires; the image is in its home layout, and
|
||||
// the region lies in the level and in the buffer, at a whole texel.
|
||||
unsafe {
|
||||
device.cmd_copy_image_to_buffer(self.command, image, source, copy.buffer, &[region])
|
||||
};
|
||||
(core.counters).resolve_copied(u64::from(width) * u64::from(height) * copy.texel);
|
||||
building.owe_pass();
|
||||
}
|
||||
self.command_buffer.close_encoder(building);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,12 @@
|
||||
//! 600 such pass into a `ShaderRead` texture over a Managed and over a Shared buffer, at tight
|
||||
//! rows, at its row rounded up to the device's linear alignment (where it lies in place on
|
||||
//! every device) and at 2,560 bytes: in place, its linear image took the attachment usage where
|
||||
//! the device's linear tiling renders the format, and the pass copies nothing (a Managed
|
||||
//! buffer's synchronize aside); the buffer reads the clear within one code and keeps the bytes
|
||||
//! past each row's texels. Where the linear tiling does not render the format, a resolve into
|
||||
//! such a texture in place is the gap `ResolveUsage`, and so is a depth resolve into a
|
||||
//! `Depth32Float` texture of `ShaderRead` usage.
|
||||
//! the device's linear tiling renders the format, and the pass copies nothing; where it took
|
||||
//! none, the pass resolves into the texture's resolve image and copies its texels into the
|
||||
//! buffer, one copy of 1,440,000 bytes counted. The buffer reads the clear within one code and
|
||||
//! keeps the bytes past each row's texels; a pass after it in the same command buffer reads the
|
||||
//! clear through the texture; a second resolve into it makes no image and no allocation. A depth
|
||||
//! resolve into a `Depth32Float` texture of `ShaderRead` usage is the gap `ResolveUsage`.
|
||||
//! - Under a device cfg, on every device of the cfg's kind, whether it has
|
||||
//! `shaderStorageImageMultisample` or not: a 4-sample `RGBA8Unorm` texture made for shader
|
||||
//! reads, shader writes and rendering, as Metal makes one, has no storage usage in its image and
|
||||
@@ -720,13 +721,20 @@ mod on_device {
|
||||
/// 2,400 bytes apart (tight), its row rounded up to the device's linear alignment, and 2,560.
|
||||
/// At the rounded row the texture lies in place on every device. In place, its linear image
|
||||
/// took the attachment usage where the device's linear tiling renders its format, and the
|
||||
/// pass copies nothing; copied, the copies are counted. The buffer's bytes read the clear
|
||||
/// within one code, and the bytes past each row's texels keep the host's. Where the linear
|
||||
/// tiling does not render the format, a resolve into the texture in place is `ResolveUsage`.
|
||||
/// pass copies nothing; where it took none, the pass resolves into the texture's resolve
|
||||
/// image and copies its 600 x 600 texels into the buffer, one copy counted; copied, the copies
|
||||
/// are counted. The buffer's bytes read the clear within one code, and the bytes past each
|
||||
/// row's texels keep the host's. A pass after it in the same command buffer reads the texture
|
||||
/// at each pixel, its centre the clear within one code. A second resolve into the texture, in
|
||||
/// a command buffer of its own, makes no image and no allocation.
|
||||
#[test]
|
||||
fn every_device_resolves_a_loaded_pass_into_a_shader_read_texture_over_a_buffer() {
|
||||
const WALK: u32 = 600;
|
||||
const ROW: u64 = WALK as u64 * 4;
|
||||
const TEXELS: u64 = WALK as u64 * WALK as u64 * 4;
|
||||
let Some(library) = examples() else {
|
||||
return;
|
||||
};
|
||||
each_device("resolve_over", |name, _, device| {
|
||||
let format = PixelFormat::BGRA8UnormSRGB;
|
||||
let color = four_of(name, &device, format, WALK)
|
||||
@@ -749,6 +757,35 @@ mod on_device {
|
||||
let mut first = attached(LoadAction::Clear);
|
||||
first.color_attachments[0].clear_color = CLEAR;
|
||||
first.color_attachments[0].store_action = StoreAction::Store;
|
||||
// The pass after the resolve: each pixel of a target the texture's texel there.
|
||||
let reading = state(
|
||||
name,
|
||||
&device,
|
||||
&descriptor(&library, "own_pixel_fragment", format),
|
||||
);
|
||||
let mut buffers = Buffers::new(&device);
|
||||
let positions = buffers.of(&device, &floats(&[-1.0, -1.0, 3.0, -1.0, -1.0, 3.0]));
|
||||
let colors = buffers.of(&device, &floats(&[0.0; 12]));
|
||||
let seen = one(
|
||||
name,
|
||||
&device,
|
||||
format,
|
||||
TextureUsage::RENDER_TARGET,
|
||||
StorageMode::Shared,
|
||||
WALK,
|
||||
);
|
||||
let read = |command_buffer: &crate::CommandBuffer, over: &Texture| {
|
||||
let done =
|
||||
|result: Result<(), Error>| result.unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
let mut encoder = (command_buffer.render_command_encoder(&pass(&seen, None)))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
done(encoder.set_render_pipeline_state(&reading));
|
||||
done(encoder.set_vertex_buffer(Some(&positions), 0, 0));
|
||||
done(encoder.set_vertex_buffer(Some(&colors), 0, 1));
|
||||
done(encoder.set_fragment_texture(Some(over), 0));
|
||||
done(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0));
|
||||
encoder.end_encoding();
|
||||
};
|
||||
let align = (device.minimum_linear_texture_alignment(format))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let rounded = ROW.next_multiple_of(align);
|
||||
@@ -791,58 +828,60 @@ mod on_device {
|
||||
.object()
|
||||
.image_usage()
|
||||
.contains(vk::ImageUsageFlags::COLOR_ATTACHMENT);
|
||||
let (linear, _) = device.core().format_features(TextureObject::format(&over));
|
||||
let tiling = linear.contains(vk::FormatFeatureFlags2::COLOR_ATTACHMENT);
|
||||
let form = match in_place {
|
||||
true => "in place",
|
||||
false => "copied",
|
||||
assert!(
|
||||
renders || in_place,
|
||||
"{name}: {kind} at {pitch}: copied, the attachment usage"
|
||||
);
|
||||
// In place with no attachment usage: through its resolve image.
|
||||
let through = in_place && !renders;
|
||||
let form = match (in_place, through) {
|
||||
(true, false) => "in place",
|
||||
(true, true) => "in place, through its resolve image",
|
||||
(false, _) => "copied",
|
||||
};
|
||||
let mut walk = attached(LoadAction::Load);
|
||||
walk.color_attachments[0].store_action = StoreAction::MultisampleResolve;
|
||||
walk.color_attachments[0].resolve_texture = Some(over.clone());
|
||||
let resolve = |command_buffer: &crate::CommandBuffer| {
|
||||
let encoder = (command_buffer.render_command_encoder(&walk))
|
||||
.unwrap_or_else(|e| panic!("{name}: {kind} at {pitch}: {e}"));
|
||||
encoder.end_encoding();
|
||||
read(command_buffer, &over);
|
||||
if managed {
|
||||
let mut blit = command_buffer.blit_command_encoder().expect("a blit");
|
||||
(blit.synchronize_resource(Resource::Buffer(&buffer)))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
blit.end_encoding();
|
||||
}
|
||||
run(name, command_buffer);
|
||||
};
|
||||
let command_buffer = queue.command_buffer().expect("a command buffer");
|
||||
let encoder = (command_buffer.render_command_encoder(&first))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
encoder.end_encoding();
|
||||
if in_place && !tiling {
|
||||
assert!(!renders, "{name}: {kind} at {pitch}: no attachment usage");
|
||||
assert_eq!(
|
||||
(command_buffer.render_command_encoder(&walk).err())
|
||||
.map(|e| e.to_string()),
|
||||
Some(gap(RenderPassKind::ResolveUsage).to_string()),
|
||||
"{name}: {kind} at {pitch}: in place, its tiling renders no {format:?}"
|
||||
);
|
||||
run(name, &command_buffer);
|
||||
println!(
|
||||
"resolve_over: {name}: {kind} pitch {pitch}: in place, its linear \
|
||||
tiling renders no {format:?}: ResolveUsage"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
assert!(
|
||||
renders,
|
||||
"{name}: {kind} at {pitch}: {form}, the attachment usage"
|
||||
);
|
||||
let before = device.counters().metrics();
|
||||
let encoder = (command_buffer.render_command_encoder(&walk))
|
||||
.unwrap_or_else(|error| panic!("{name}: {kind} at {pitch}: {error}"));
|
||||
encoder.end_encoding();
|
||||
if managed {
|
||||
let mut blit = command_buffer.blit_command_encoder().expect("a blit");
|
||||
(blit.synchronize_resource(Resource::Buffer(&buffer)))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
blit.end_encoding();
|
||||
}
|
||||
run(name, &command_buffer);
|
||||
resolve(&command_buffer);
|
||||
let after = device.counters().metrics();
|
||||
assert_eq!(after.resolves - before.resolves, 1, "{name}: one resolve");
|
||||
let copied = after.bytes_copied - before.bytes_copied;
|
||||
// A Managed buffer's synchronize copies its device copy, where it has one.
|
||||
let synchronized = managed && !device.has_unified_memory();
|
||||
let copies = after.resolve_copies - before.resolve_copies;
|
||||
let copy_bytes = after.resolve_copy_bytes - before.resolve_copy_bytes;
|
||||
assert_eq!(
|
||||
(copies, copy_bytes),
|
||||
(u64::from(through), u64::from(through) * TEXELS),
|
||||
"{name}: {kind} at {pitch}: {form}, the resolve copies"
|
||||
);
|
||||
assert!(
|
||||
((copied == 0 || synchronized) && in_place) || (copied > 0 && !in_place),
|
||||
(in_place && copied == copy_bytes) || (!in_place && copied > 0),
|
||||
"{name}: {kind} at {pitch}: {form}, {copied} bytes copied"
|
||||
);
|
||||
// Its resolve image is the one image the first resolve makes.
|
||||
let made = after.image_creates.count - before.image_creates.count;
|
||||
assert_eq!(
|
||||
made,
|
||||
u64::from(through),
|
||||
"{name}: {kind} at {pitch}: images"
|
||||
);
|
||||
// SAFETY: the buffer's bytes, which no command uses now.
|
||||
let held =
|
||||
unsafe { std::slice::from_raw_parts(contents.as_ptr(), len as usize) };
|
||||
@@ -860,20 +899,53 @@ mod on_device {
|
||||
let fnv = (texels.iter()).fold(0xcbf2_9ce4_8422_2325u64, |hash, &byte| {
|
||||
(hash ^ u64::from(byte)).wrapping_mul(0x0100_0000_01b3)
|
||||
});
|
||||
// Metal's centre texel, (299, 300), as the pass after the resolve read it.
|
||||
let centre = (300 * WALK as usize + 299) * 4;
|
||||
let read_back = read_at(&seen, WALK, 4, 0, 0);
|
||||
let centre = &read_back[centre..centre + 4];
|
||||
cleared(name, centre);
|
||||
println!(
|
||||
"resolve_over: {name}: {kind} pitch {pitch}: {form}, resolved; texels fnv \
|
||||
{fnv:016x} (0,0)={:02x}{:02x}{:02x}{:02x}; {changed} of {} bytes past \
|
||||
the texels changed; bytes copied {copied}",
|
||||
the texels changed; bytes copied {copied}, resolve copies {copies}, \
|
||||
images made {made}; the next pass read (299,300)={:02x}{:02x}{:02x}{:02x}",
|
||||
texels[0],
|
||||
texels[1],
|
||||
texels[2],
|
||||
texels[3],
|
||||
(pitch - ROW) * u64::from(WALK)
|
||||
(pitch - ROW) * u64::from(WALK),
|
||||
centre[0],
|
||||
centre[1],
|
||||
centre[2],
|
||||
centre[3]
|
||||
);
|
||||
// A second resolve into it makes no image and no allocation, and the resolve
|
||||
// images do not grow (an earlier row's may go as the reaper frees it).
|
||||
let images = device.counters().gauges().resolve_images;
|
||||
let command_buffer = queue.command_buffer().expect("a command buffer");
|
||||
let before = device.counters().metrics();
|
||||
resolve(&command_buffer);
|
||||
let after = device.counters().metrics();
|
||||
let made = after.image_creates.count - before.image_creates.count;
|
||||
let allocated = after.consumer_allocations - before.consumer_allocations;
|
||||
let again = after.resolve_copies - before.resolve_copies;
|
||||
let copied = after.bytes_copied - before.bytes_copied;
|
||||
let live = device.counters().gauges().resolve_images;
|
||||
assert!(
|
||||
made == 0 && allocated == 0 && live <= images,
|
||||
"{name}: {kind} at {pitch}: {form}, the second resolve made {made} \
|
||||
images and {allocated} allocations, resolve images {images} to {live}"
|
||||
);
|
||||
assert_eq!(again, u64::from(through), "{name}: {kind} at {pitch}");
|
||||
println!(
|
||||
"resolve_over: {name}: {kind} pitch {pitch}: the second resolve made \
|
||||
{made} images and {allocated} allocations, resolve images {images} to \
|
||||
{live}; bytes copied {copied}, resolve copies {again}"
|
||||
);
|
||||
drop((over, buffer, block));
|
||||
}
|
||||
}
|
||||
drop((color, depth));
|
||||
drop((color, depth, seen));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -343,6 +343,38 @@ struct Named {
|
||||
form: Form,
|
||||
}
|
||||
|
||||
impl Named {
|
||||
/// Of a texture over a buffer of `d` and `unit`: the `VkBuffer` of the bytes shaders reach
|
||||
/// (the block's, or a Managed buffer's device copy's), and the copy between them and an image
|
||||
/// of the texture's whole level at its pitch; `None` where the pitch is past a `u32` of texels.
|
||||
fn region(
|
||||
&self,
|
||||
unit: CopyUnit,
|
||||
d: &TextureDescriptor,
|
||||
) -> Option<(vk::Buffer, vk::BufferImageCopy)> {
|
||||
let place = self.places[0];
|
||||
let (buffer, at) = self.buffer.device_range();
|
||||
let region = vk::BufferImageCopy {
|
||||
buffer_offset: at + place.offset,
|
||||
buffer_row_length: u32::try_from(place.bytes_per_row / u64::from(unit.bytes)).ok()?,
|
||||
buffer_image_height: 0,
|
||||
image_subresource: vk::ImageSubresourceLayers {
|
||||
aspect_mask: unit.aspect,
|
||||
mip_level: 0,
|
||||
base_array_layer: 0,
|
||||
layer_count: 1,
|
||||
},
|
||||
image_offset: vk::Offset3D::default(),
|
||||
image_extent: vk::Extent3D {
|
||||
width: d.width,
|
||||
height: d.height,
|
||||
depth: 1,
|
||||
},
|
||||
};
|
||||
Some((buffer, region))
|
||||
}
|
||||
}
|
||||
|
||||
/// How a texture's image holds its named bytes.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Form {
|
||||
@@ -414,6 +446,11 @@ pub(crate) struct Image {
|
||||
shadowing: Option<Box<Shadowing>>,
|
||||
/// The image is another's shadow: its drop lowers the shadow gauges, not the textures gauge.
|
||||
shadow: bool,
|
||||
/// A linear image in place over a buffer of the runtime's own memory that takes no attachment
|
||||
/// usage, of a texture whose plan's optimal image does (`Plan::resolves`): what the image a
|
||||
/// pass resolves into in its place is made of, and that image once a pass made it
|
||||
/// (`TextureObject::resolve_attachment`). `None` for every other image.
|
||||
resolving: Option<Box<Resolving>>,
|
||||
/// Every aspect of the image's format, which a change of layout names.
|
||||
aspects: vk::ImageAspectFlags,
|
||||
/// The image's format and usage, and the formats it lists for views of another format (empty
|
||||
@@ -485,6 +522,48 @@ struct Shadowing {
|
||||
shadow: Mutex<Option<Arc<Image>>>,
|
||||
}
|
||||
|
||||
/// What the image a pass resolves into in place of a linear image that takes no attachment usage
|
||||
/// is made of, and that image once made (`Image`'s `resolving`).
|
||||
struct Resolving {
|
||||
/// The texture's descriptor and shape, and its plan's optimal image with no view of its own.
|
||||
made: (TextureDescriptor, Shape, Plan),
|
||||
image: Mutex<Option<Resolved>>,
|
||||
}
|
||||
|
||||
/// The one-sample image a pass resolves into in place of a texture's linear image, and its
|
||||
/// attachment view: made at the first pass that resolves into the texture, kept for every later
|
||||
/// one, and freed with the texture. The resolve images gauges count it.
|
||||
struct Resolved {
|
||||
core: Arc<Core>,
|
||||
image: vk::Image,
|
||||
backing: Backing,
|
||||
bytes: u64,
|
||||
view: vk::ImageView,
|
||||
}
|
||||
|
||||
impl Drop for Resolved {
|
||||
fn drop(&mut self) {
|
||||
let free = Free::Resolved {
|
||||
view: self.view,
|
||||
image: self.image,
|
||||
backing: self.backing,
|
||||
bytes: self.bytes,
|
||||
};
|
||||
self.core.pool.release(&self.core, free);
|
||||
}
|
||||
}
|
||||
|
||||
/// A pass's resolve into a texture's resolve image (`Resolved`): the copy of what it resolved
|
||||
/// into the bytes shaders reach of the buffer the texture lies over, at the texture's pitch.
|
||||
pub(crate) struct ResolveCopy {
|
||||
/// The `VkBuffer` of those bytes: the block's, or a Managed buffer's device copy's.
|
||||
pub(crate) buffer: vk::Buffer,
|
||||
/// The copy of the texture's whole level, which the pass cuts to its render area.
|
||||
pub(crate) region: vk::BufferImageCopy,
|
||||
/// A texel's bytes.
|
||||
pub(crate) texel: u64,
|
||||
}
|
||||
|
||||
/// What holds the memory an image lies in that is not its own.
|
||||
enum Under {
|
||||
/// A heap texture's block, and the image's first byte there.
|
||||
@@ -777,6 +856,7 @@ impl Image {
|
||||
attachment_reads: false,
|
||||
shadowing: None,
|
||||
shadow: true,
|
||||
resolving: None,
|
||||
aspects: self.aspects,
|
||||
format: plan.format,
|
||||
usage: plan.usage,
|
||||
@@ -1319,6 +1399,7 @@ impl Device {
|
||||
attachment_reads: false,
|
||||
shadowing: None,
|
||||
shadow: false,
|
||||
resolving: None,
|
||||
aspects: plan.aspects,
|
||||
format: plan.format,
|
||||
usage: swapchain.image_usage,
|
||||
@@ -1549,6 +1630,15 @@ impl Device {
|
||||
shadow: Mutex::new(None),
|
||||
})
|
||||
});
|
||||
// In place in the runtime's own memory with no attachment usage, where the plan's optimal
|
||||
// image takes it, a pass resolves into such an image and copies it into the bytes.
|
||||
let own = laid_over && matches!(laid, Some(Laid::Own));
|
||||
let resolving = (own && !resolved && plan.resolves).then(|| {
|
||||
Box::new(Resolving {
|
||||
made: (d, shape, plan.resolved()),
|
||||
image: Mutex::new(None),
|
||||
})
|
||||
});
|
||||
let image = Arc::new(Image {
|
||||
core: Arc::clone(core),
|
||||
image,
|
||||
@@ -1560,6 +1650,7 @@ impl Device {
|
||||
attachment_reads,
|
||||
shadowing,
|
||||
shadow: false,
|
||||
resolving,
|
||||
aspects: plan.aspects,
|
||||
format: plan.format,
|
||||
// A linear image in place takes the attachment usage for its resolves where they stay
|
||||
@@ -1788,6 +1879,20 @@ impl Plan {
|
||||
}
|
||||
}
|
||||
|
||||
/// The plan of the image a pass resolves into in place of a linear image that takes no
|
||||
/// attachment usage (`Image`'s `resolving`): the plan's optimal image, which its image format
|
||||
/// query makes with the attachment usage (`resolves`), with no view of its own.
|
||||
fn resolved(&self) -> Plan {
|
||||
Plan {
|
||||
sampled: None,
|
||||
storage: false,
|
||||
attachment_reads: false,
|
||||
linear_resolves: false,
|
||||
view_formats: self.view_formats.clone(),
|
||||
..*self
|
||||
}
|
||||
}
|
||||
|
||||
/// The image's create flags over `shape`'s: mutable where it lists formats for its views, and
|
||||
/// cube-compatible where the plan makes it so.
|
||||
fn flags(&self, shape: &Shape) -> vk::ImageCreateFlags {
|
||||
@@ -4552,30 +4657,114 @@ pub(crate) trait TextureObject {
|
||||
/// views them, of any usage, as Metal resolves into a texture of any usage: where its image
|
||||
/// has an attachment usage, which `RenderTarget` usage gives it and a one-sample colour
|
||||
/// texture takes where its format renders (`Plan::resolves`), its linear image in place over
|
||||
/// a buffer of the runtime's own memory included (`Plan::linear_resolves`).
|
||||
/// a buffer of the runtime's own memory included (`Plan::linear_resolves`). A texture in place
|
||||
/// over a buffer of the runtime's own memory whose linear image takes none (its linear tiling
|
||||
/// does not render its format, or its subresource reaches past its own rows or its buffer),
|
||||
/// where its plan's optimal image does, resolves into its resolve image (`Resolved`, made at
|
||||
/// its first resolve) with the copy the pass's end makes of it into the buffer's bytes, a copy
|
||||
/// Metal does not make.
|
||||
///
|
||||
/// Err: [`Gap::RenderPass`] of [`RenderPassKind::ResolveUsage`] for a texture whose image has
|
||||
/// none: a depth or stencil texture made without `RenderTarget` usage, a colour texture of a
|
||||
/// type but 2D, a 2D array, a cube or a cube array or whose format the device's optimal image
|
||||
/// does not render, and a texture in place over a buffer whose linear image takes none: over
|
||||
/// a dma-buf's import, of a format the device's linear tiling does not render or whose
|
||||
/// linear image its query does not make with the usage, or whose subresource reaches past its
|
||||
/// own rows or its buffer; as [`attachment`] for the rest.
|
||||
/// none and that has no resolve image: a depth or stencil texture made without `RenderTarget`
|
||||
/// usage, a colour texture of a type but 2D, a 2D array, a cube or a cube array or whose format
|
||||
/// the device's optimal image does not render, a texture in place over a dma-buf's import, and
|
||||
/// a view of a texture in place; [`Refusal::AttachmentPlace`] past a texture over a buffer's
|
||||
/// one level and slice; [`Error::Vulkan`] where its resolve image cannot be made; as
|
||||
/// [`attachment`] for the rest.
|
||||
///
|
||||
/// [`attachment`]: TextureObject::attachment
|
||||
fn resolve_attachment(&self, level: u32, slice: u32, layers: u32) -> Result<Attachment, Error> {
|
||||
fn resolve_attachment(
|
||||
&self,
|
||||
level: u32,
|
||||
slice: u32,
|
||||
layers: u32,
|
||||
) -> Result<(Attachment, Option<ResolveCopy>), Error> {
|
||||
let renders =
|
||||
vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT;
|
||||
if !self
|
||||
.object()
|
||||
.image_of()
|
||||
.is_some_and(|image| image.usage.intersects(renders))
|
||||
{
|
||||
return Err(Error::Unsupported(Gap::RenderPass {
|
||||
kind: RenderPassKind::ResolveUsage,
|
||||
}));
|
||||
let object = self.object();
|
||||
let image = object.image_of();
|
||||
if image.is_some_and(|image| image.usage.intersects(renders)) {
|
||||
return Ok((self.attachment_view(level, slice, layers)?, None));
|
||||
}
|
||||
self.attachment_view(level, slice, layers)
|
||||
let gap = || {
|
||||
Error::Unsupported(Gap::RenderPass {
|
||||
kind: RenderPassKind::ResolveUsage,
|
||||
})
|
||||
};
|
||||
let resolving = image.and_then(|image| image.resolving.as_deref());
|
||||
let (Some(resolving), None, Some(named), Some(unit)) =
|
||||
(resolving, &object.view, &object.named, object.unit)
|
||||
else {
|
||||
return Err(gap());
|
||||
};
|
||||
let (d, shape, plan) = &resolving.made;
|
||||
let (buffer, region) = named.region(unit, d).ok_or_else(gap)?;
|
||||
// As `attachment_view` refuses a place past the texture's one level and slice.
|
||||
if level != 0 || slice != 0 || layers != 1 {
|
||||
let slice = if level != 0 || slice != 0 {
|
||||
slice
|
||||
} else {
|
||||
layers - 1
|
||||
};
|
||||
return Err(Error::Refused(Refusal::AttachmentPlace { level, slice }));
|
||||
}
|
||||
let core = &object.core;
|
||||
let mut kept = lock(&resolving.image);
|
||||
let (view, image) = match &*kept {
|
||||
Some(made) => (made.view, made.image),
|
||||
None => {
|
||||
// SAFETY: the device is live, and the texture's plan checked the image's usage
|
||||
// against its image format query for the shape (`Plan::resolves`).
|
||||
let (image, backing, bytes, _, _) =
|
||||
unsafe { make(core, d, shape, plan, Bind::Pooled) }
|
||||
.map_err(|unmade| unmade.error(d))?;
|
||||
core.counters.rise(Gauge::ResolveImages);
|
||||
core.counters.rise_by(Gauge::ResolveImageBytes, bytes);
|
||||
let mut made = Resolved {
|
||||
core: Arc::clone(core),
|
||||
image,
|
||||
backing,
|
||||
bytes,
|
||||
view: vk::ImageView::null(),
|
||||
};
|
||||
let range = vk::ImageSubresourceRange {
|
||||
aspect_mask: vk::ImageAspectFlags::COLOR,
|
||||
base_mip_level: 0,
|
||||
level_count: 1,
|
||||
base_array_layer: 0,
|
||||
layer_count: 1,
|
||||
};
|
||||
let identity = vk::ComponentMapping::default();
|
||||
let kind = vk::ImageViewType::TYPE_2D;
|
||||
// SAFETY: the image is bound, 2D of one level and layer, of the plan's format,
|
||||
// with the attachment usage; a refusal frees it as `made` drops.
|
||||
made.view =
|
||||
unsafe { image_view(core, image, kind, plan.format, identity, range, None) }?;
|
||||
let made = kept.insert(made);
|
||||
(made.view, made.image)
|
||||
}
|
||||
};
|
||||
let attachment = Attachment {
|
||||
view,
|
||||
image,
|
||||
level: 0,
|
||||
layer: 0,
|
||||
layers: 1,
|
||||
aspects: vk::ImageAspectFlags::COLOR,
|
||||
// Where each pass leaves it, for its copy (`pass::Resolve::from`).
|
||||
home: vk::ImageLayout::TRANSFER_SRC_OPTIMAL,
|
||||
extent: [d.width, d.height],
|
||||
format: plan.format,
|
||||
samples: vk::SampleCountFlags::TYPE_1,
|
||||
linear: false,
|
||||
};
|
||||
let texel = u64::from(unit.bytes);
|
||||
let copy = ResolveCopy {
|
||||
buffer,
|
||||
region,
|
||||
texel,
|
||||
};
|
||||
Ok((attachment, Some(copy)))
|
||||
}
|
||||
|
||||
/// `level` and the `layers` slices from `slice` of the texture as a render pass attachment,
|
||||
@@ -4915,25 +5104,8 @@ pub(crate) trait TextureObject {
|
||||
let unit = inner.unit?;
|
||||
let place = named.places[0];
|
||||
let d = &inner.descriptor;
|
||||
let (buffer, at) = named.buffer.device_range();
|
||||
let (buffer, region) = named.region(unit, d)?;
|
||||
let (block, device_copy) = named.buffer.held();
|
||||
let region = vk::BufferImageCopy {
|
||||
buffer_offset: at + place.offset,
|
||||
buffer_row_length: u32::try_from(place.bytes_per_row / u64::from(unit.bytes)).ok()?,
|
||||
buffer_image_height: 0,
|
||||
image_subresource: vk::ImageSubresourceLayers {
|
||||
aspect_mask: unit.aspect,
|
||||
mip_level: 0,
|
||||
base_array_layer: 0,
|
||||
layer_count: 1,
|
||||
},
|
||||
image_offset: vk::Offset3D::default(),
|
||||
image_extent: vk::Extent3D {
|
||||
width: d.width,
|
||||
height: d.height,
|
||||
depth: 1,
|
||||
},
|
||||
};
|
||||
let end = place.offset
|
||||
+ u64::from(d.height - 1) * place.bytes_per_row
|
||||
+ u64::from(d.width) * u64::from(unit.bytes);
|
||||
@@ -5603,6 +5775,7 @@ impl Device {
|
||||
attachment_reads: looped || shadowing.is_some(),
|
||||
shadowing,
|
||||
shadow: false,
|
||||
resolving: None,
|
||||
aspects: plan.aspects,
|
||||
format: made.format,
|
||||
usage: made.usage,
|
||||
|
||||
@@ -1418,6 +1418,8 @@ field metal2vulkan-runtime::Gauges.private_unit_used_bytes pub private_unit_used
|
||||
field metal2vulkan-runtime::Gauges.private_units pub private_units: u64
|
||||
field metal2vulkan-runtime::Gauges.releases_waiting pub releases_waiting: u64
|
||||
field metal2vulkan-runtime::Gauges.render_contents pub render_contents: u64
|
||||
field metal2vulkan-runtime::Gauges.resolve_image_bytes pub resolve_image_bytes: u64
|
||||
field metal2vulkan-runtime::Gauges.resolve_images pub resolve_images: u64
|
||||
field metal2vulkan-runtime::Gauges.samplers pub samplers: u64
|
||||
field metal2vulkan-runtime::Gauges.shadow_bytes pub shadow_bytes: u64
|
||||
field metal2vulkan-runtime::Gauges.shadows pub shadows: u64
|
||||
@@ -1597,6 +1599,8 @@ field metal2vulkan-runtime::Metrics.render_makes_past_kernel_bound pub render_ma
|
||||
field metal2vulkan-runtime::Metrics.render_records_read pub render_records_read: u64
|
||||
field metal2vulkan-runtime::Metrics.render_records_stale pub render_records_stale: u64
|
||||
field metal2vulkan-runtime::Metrics.render_weight_past_kernel_bound_max pub render_weight_past_kernel_bound_max: u64
|
||||
field metal2vulkan-runtime::Metrics.resolve_copies pub resolve_copies: u64
|
||||
field metal2vulkan-runtime::Metrics.resolve_copy_bytes pub resolve_copy_bytes: u64
|
||||
field metal2vulkan-runtime::Metrics.resolves pub resolves: u64
|
||||
field metal2vulkan-runtime::Metrics.ring_block_allocations pub ring_block_allocations: SiteAllocations
|
||||
field metal2vulkan-runtime::Metrics.ring_writes pub ring_writes: u64
|
||||
|
||||
|
Can't render this file because it is too large.
|
+2
-2
@@ -310,7 +310,7 @@ Columns:
|
||||
| `AttachmentUsage` | A render pass attachment (`CommandBuffer::render_command_encoder`) whose texture was made without `RenderTarget` usage | every device (a public call's own check of its arguments) | `metal-documented`: a texture a render pass renders into needs `MTLTextureUsageRenderTarget`; Metal's validation stops the descriptor | 1: `crates/metal2vulkan-runtime/src/texture.rs (attachment)` | `-` |
|
||||
| `ResolveTexture` | A store action that resolves (`MultisampleResolve` or `StoreAndMultisampleResolve`), on a render pass attachment or set by its encoder, for an... | every device (a public call's own check of its arguments) | `metal-documented`: `MTLRenderPass.h`: `resolveTexture` is "Only used (and required) if the store action is set to MTLStoreActionMultisampleResolve" | 2: `crates/metal2vulkan-runtime/src/pass.rs (resolving)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (later_store)` | `-` |
|
||||
| `ResolveFormat` | A resolve of a render pass color attachment of an integer pixel format | every device (a public call's own check of its arguments) | `metal-documented`: Metal's validation asserts that an integer color format "cannot be a MSAA resolve target", and plain Metal writes values no sample holds | 1: `crates/metal2vulkan-runtime/src/pass.rs (check)` | `-` |
|
||||
| `AttachmentPlace` | A render pass attachment or resolve texture of a level or slice past its texture's | every device (a public call's own check of its arguments) | `ours`: no texel of the texture is there to render into | 2: `crates/metal2vulkan-runtime/src/texture.rs (attachment_view, 2 sites)` | `-` |
|
||||
| `AttachmentPlace` | A render pass attachment or resolve texture of a level or slice past its texture's | every device (a public call's own check of its arguments) | `ours`: no texel of the texture is there to render into | 4: `crates/metal2vulkan-runtime/src/texture.rs (attachment_view, 2 sites)`, `crates/metal2vulkan-runtime/src/texture.rs (resolve_attachment, 2 sites)` | `-` |
|
||||
| `AttachmentFormat` | A render pass color attachment of a depth or stencil pixel format, a depth attachment of a format without depth, or a stencil attachment of a... | every device (a public call's own check of its arguments) | `metal-documented`: a color attachment takes a color-renderable format, a depth attachment a format with depth and a stencil attachment a format with stencil; Metal's validation stops the descriptor | 3: `crates/metal2vulkan-runtime/src/pass.rs (check, 3 sites)` | `-` |
|
||||
| `NoAttachmentPass` | A render pass with no attachment whose `renderTargetWidth` or `renderTargetHeight` is 0, or whose `defaultRasterSampleCount` is 0, Metal's default | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, the API validation layer off, m3-max-62174, `probes/no_attachment_passes.m`: a side of 0 makes no encoder, nil, and a count of 0 ends the process at the encoder, SIGABRT, where 64 by 64 pixels at 1 sample makes one | 1: `crates/metal2vulkan-runtime/src/pass.rs (check)` | `-` |
|
||||
| `VertexBufferOffset` | A draw whose vertex descriptor reads a vertex buffer at an offset at or past the buffer's length | every device (a public call's own check of its arguments) | `metal-documented`: a buffer's offset lies inside it; Metal's validation stops the bind | 1: `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` | `-` |
|
||||
@@ -612,7 +612,7 @@ Each refusal's sites, with the function that builds it.
|
||||
- `rt:Refusal::AttachmentUsage`: `crates/metal2vulkan-runtime/src/texture.rs (attachment)`
|
||||
- `rt:Refusal::ResolveTexture`: `crates/metal2vulkan-runtime/src/pass.rs (resolving)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (later_store)`
|
||||
- `rt:Refusal::ResolveFormat`: `crates/metal2vulkan-runtime/src/pass.rs (check)`
|
||||
- `rt:Refusal::AttachmentPlace`: `crates/metal2vulkan-runtime/src/texture.rs (attachment_view, 2 sites)`
|
||||
- `rt:Refusal::AttachmentPlace`: `crates/metal2vulkan-runtime/src/texture.rs (attachment_view, 2 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (resolve_attachment, 2 sites)`
|
||||
- `rt:Refusal::AttachmentFormat`: `crates/metal2vulkan-runtime/src/pass.rs (check, 3 sites)`
|
||||
- `rt:Refusal::NoAttachmentPass`: `crates/metal2vulkan-runtime/src/pass.rs (check)`
|
||||
- `rt:Refusal::VertexBufferOffset`: `crates/metal2vulkan-runtime/src/render_encoder.rs (find)`
|
||||
|
||||
Reference in new issue
Block a user