rt: a view of its own format of a texture in place resolves through the texture's resolve image

For the consumer: a same-format view of 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 as a resolve
target with Gap::RenderPass{ResolveUsage}. Measured on the RTX 3090 and KosmicKrisp, where the
linear tiling renders no format, that is every texture in place. The view resolves as its texture
does: into the texture's resolve image, then the pass's end copies it into the buffer. A view of
another pixel format of such a texture stays refused, a known gap.

Why: the runtime refuses only what the device lacks, and the device lacks nothing for this view. A
texture over a buffer has one level and one slice, so a view of it covers the same texel bytes in
the same buffer place. A view of the same Vulkan format resolves into the same image, through the
same identity view.

How: resolve_attachment no longer requires the texture to be no view. The view's image is its
parent's, which carries the Resolving, and its Named holds the parent's one place. It now refuses
only a view whose Vulkan format is not the resolve image's (object.format != plan.format). The
copy is the same, from the view's Named, which is the parent's place. That is 3 product lines.
Where the linear image takes the usage, a view already resolves in place through attachment_view
(7193df2244).

Docs: the runtime README's two Render encoders paragraphs, RenderPassKind::ResolveUsage and
resolve_attachment's doc now name only a view of another format as refused. docs/REFUSALS.md and
the signatures table do not change.

Test: every_device_resolves_a_loaded_pass_into_a_shader_read_texture_over_a_buffer now does more
on each in-place row:
- After the host refills the buffer with 0xee, it resolves the guest's pass into a same-format
  view of the texture (new_texture_view, 2D, level 0, slice 0).
- The buffer reads the clear within one code, and 0 bytes past the texels change.
- The resolve copies count 1 through the resolve image (the RTX 3090 and KosmicKrisp), and 0
  where the view resolves in place (where the linear image takes the usage).
This commit is contained in:
Anees Iqbal committed 2026-11-22 04:17:28 -08:00
1 parent d5917d9ee5
commit d78f23726b
4 files changed
+82 -18

No files matched your search

+6 -5
View File
@@ -3574,9 +3574,10 @@ cache is answered compile-required on both.
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 whose linear image takes no
attachment usage (where the linear image takes it, a view resolves in place, as its texture
does). Refused as
a dma-buf's import, and a view of another pixel format of a texture in place over a buffer
whose linear image takes no attachment usage (a view of its own format resolves as the texture
does, through its resolve image; where the linear image takes the usage, a view resolves in
place). 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.
@@ -3979,8 +3980,8 @@ cache is answered compile-required on both.
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 whose linear image takes no attachment usage; the usage grows a 1920 x 1080 `RGBA8Unorm`
texture does not, nor a texture in place over a dma-buf's import, nor a view of another format
of a texture in place whose linear image takes no attachment usage; 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
+3 -3
View File
@@ -1794,9 +1794,9 @@ pub enum RenderPassKind {
/// 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 whose linear image takes no attachment usage
/// (where it takes the usage, a view resolves in place, as its texture does). A texture in
/// place over a buffer of the
/// a view of another pixel format of a texture in place over a buffer whose linear image takes
/// no attachment usage (a view of its own format resolves as the texture does; where the linear
/// image takes the usage, a view resolves in place). 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
@@ -29,7 +29,8 @@
//! 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 pass
//! of a smaller area copies its render area alone, the texels past it untouched. A depth
//! of a smaller area copies its render area alone, the texels past it untouched; in place, a view
//! of the texture of its format resolves as the texture does. 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
@@ -729,6 +730,7 @@ mod on_device {
/// 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. A pass of a 300 x 300 area
/// resolves Vulkan's 320 x 320 render area alone, the texels past it keeping the host's bytes.
/// In place, a view of the texture of its format resolves as the texture does.
#[test]
fn every_device_resolves_a_loaded_pass_into_a_shader_read_texture_over_a_buffer() {
const WALK: u32 = 600;
@@ -795,7 +797,7 @@ mod on_device {
let mut pitches = vec![ROW, rounded, 2_560];
pitches.dedup();
let mut index = IndexClass::Texture.range().start;
(device.grant_indices(IndexClass::Texture, index, 2 * pitches.len() as u32))
(device.grant_indices(IndexClass::Texture, index, 4 * pitches.len() as u32))
.expect("a grant");
let queue = device.new_command_queue(1).expect("a queue");
for pitch in pitches {
@@ -1002,6 +1004,64 @@ mod on_device {
resolved {reach} x {reach} texels; {outside} bytes of the texels past \
them and {past} past the rows changed; resolve copy bytes {copy_bytes}"
);
// A view of it of its format resolves as it does, in place.
if in_place {
// SAFETY: the buffer's bytes, which no command uses now.
unsafe { contents.as_ptr().write_bytes(0xee, len as usize) };
if managed {
(buffer.did_modify_range(0, len)).expect("a modified range");
}
let view = (over.new_texture_view(
format,
td.texture_type,
0..1,
0..1,
Some(index),
))
.unwrap_or_else(|error| {
panic!("{name}: {kind} at {pitch}: a view: {error}")
});
index += 1;
let mut viewed = walk.clone();
viewed.color_attachments[0].resolve_texture = Some(view.clone());
let command_buffer = queue.command_buffer().expect("a command buffer");
let before = device.counters().metrics();
let encoder = (command_buffer.render_command_encoder(&viewed))
.unwrap_or_else(|e| panic!("{name}: {kind} at {pitch}: a view: {e}"));
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);
let copies =
device.counters().metrics().resolve_copies - before.resolve_copies;
assert_eq!(
copies,
u64::from(through),
"{name}: {kind} at {pitch}: a view"
);
// SAFETY: the buffer's bytes, which no command uses now.
let held =
unsafe { std::slice::from_raw_parts(contents.as_ptr(), len as usize) };
let texels: Vec<u8> = (held.chunks(pitch_bytes))
.flat_map(|r| r[..row].iter().copied())
.collect();
let past = (held.chunks(pitch_bytes)).flat_map(|r| &r[row..]);
let changed = past.filter(|&&byte| byte != 0xee).count();
cleared(name, &texels);
assert_eq!(
changed, 0,
"{name}: {kind} at {pitch}: a view, past the texels"
);
println!(
"resolve_over: {name}: {kind} pitch {pitch}: a view of its format \
resolved; {changed} bytes past the texels changed; resolve copies {copies}"
);
drop((view, viewed));
}
drop((over, buffer, block));
}
}
+11 -8
View File
@@ -4661,17 +4661,16 @@ pub(crate) trait TextureObject {
/// 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.
/// its first resolve), and so does a view of it of its format, 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 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 whose linear image takes none; [`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.
/// a view of another format of a texture in place whose linear image takes none;
/// [`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(
@@ -4693,12 +4692,16 @@ pub(crate) trait TextureObject {
})
};
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)
let (Some(resolving), Some(named), Some(unit)) = (resolving, &object.named, object.unit)
else {
return Err(gap());
};
let (d, shape, plan) = &resolving.made;
// A view of the texture resolves into its parent's resolve image where it is of its
// format: its one level and slice are the parent's.
if object.format != plan.format {
return Err(gap());
}
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 {