rt: overlapping regions of one texture copy in slabs, as from the source before the copy
copy_from_texture refused a copy whose regions overlap in one level and slice of one image (a texture into itself, or a texture and its view) as Gap::TextureCopy, and the program's copy was skipped. Metal does not refuse the call; it leaves the result undefined, and an Apple M3 Max gives each destination texel what the source held before the copy (the conformance crate's buffer_texture_blits case, which recorded it). No vkCmdCopyImage may read a texel it writes (VUID-vkCmdCopyImage-pRegions-00124), so texture_copy now cuts such a copy into slabs along one shifted axis, the one of fewest slabs. Each slab is no thicker than the shift there, so its two regions lie apart, and the slab at the end the shift points to goes first, so no slab reads a texel an earlier one wrote: the result is memmove's. Each slab is one vkCmdCopyImage in the general layout, with an execution barrier (COPY to COPY) between two slabs, every hazard between slabs being a write after a read. Each extra barrier is counted. Regions apart remain one slab and one command, and the same region still records nothing. A shift of 20 texels over a 21-texel row is 2 commands; the worst case, a shift of one texel, is one command per texel of the region's extent on that axis. No scratch image, no cap. Gap::TextureCopy keeps its other arms (a multisample texture, depth and stencil both, one pixel format in two Vulkan formats, 1D with another type); its doc, the rt README's blit section and docs/REFUSALS.md (regenerated) drop the overlapping arm. The conformance ledger's row for buffer-texture-blits-overlapping goes, since the rt side now answers that case, and docs/CONFORMANCE-COVERAGE.md is regenerated. Tests: overlapping_regions_copy_in_slabs_the_far_end_of_the_shift_first checks the slabs' regions and order (a 21x1 row shifted by 20, a shift toward lower y, a diagonal shift on the axis of fewer slabs, regions apart as one slab); the 3D/array host test now expects slabs where it expected the gap. On a device, every_device_copies_overlapping_regions_from_the_source_before_the_copy copies toward higher and toward lower x and y, from a view into its texture, along a 3D texture's depth, and by whole BC1 blocks where the device makes them. Each case expects the source's bytes from before the copy, one submission, 2 + slabs barriers and no byte copied of the runtime's own.
This commit is contained in:
1 parent
1d79c26b7a
commit
7c1baad228
7 files changed
+379
-76
No files matched your search
@@ -244,7 +244,6 @@ buffer-depth-samples-s8-54-2 RX 550 refused case/work Err({refused: Error::Unsup
|
||||
buffer-tails-blits * refused case/work Err({refused: Error::Refused("a texture at offset 4096, rows 64 bytes apart, does not lie in whole texels inside a buffer of 20000 bytes"), resource: 1 (0x1)}) An accepted difference: Metal documents the texture as the buffer's storage, which these rows run past, and rt refuses it typed. Apple's makeTexture(descriptor:offset:bytesPerRow:) page: the call "Creates a texture that shares its storage with the buffer"; MTLBuffer.h: "Create a 2D texture or texture buffer that shares storage with this buffer." The M3 Max (macOS 27.0.1) made the texture with its API validation off, its texels past the length in the buffer's allocation, and its validation layer stops it: "Length required by texture offset, bytes per row, height and array length(20480) exceed buffer capacity(20000)."
|
||||
buffer-tails-kernels * refused case/texture Err(Error::Refused("a texture at offset 4096, rows 64 bytes apart, does not lie in whole texels inside a buffer of 20000 bytes")) An accepted difference: Metal documents the texture as the buffer's storage, which these rows run past, and rt refuses it typed. Apple's makeTexture(descriptor:offset:bytesPerRow:) page: the call "Creates a texture that shares its storage with the buffer"; MTLBuffer.h: "Create a 2D texture or texture buffer that shares storage with this buffer." The M3 Max (macOS 27.0.1) made the texture with its API validation off, its texels past the length in the buffer's allocation, and its validation layer stops it: "Length required by texture offset, bytes per row, height and array length(20480) exceed buffer capacity(20000)."
|
||||
buffer-tails-texture-buffer * refused case/pipeline Err(Error::Translation("the translator made no pipeline: unsupported: IdentityDomains (texture argument SlotRef { stage: Kernel, class: Texture, index: 0 }: a type the identity arrays hold no element of, or state of the bound texture beyond its resource ID); needs NotImplemented")) refused: no stream uses it yet (states-only play 11-19, m3-max-56371-56373, 56375, player 44668b439f: 32 streams, every render and compute pipeline state made). The translator refuses the state (IdentityDomains: a form the identity domains do not lower); rt README, Known gaps of pipeline states.
|
||||
buffer-texture-blits-overlapping * refused case/onto-itself-overlapping Err({refused: Error::Unsupported("this copy from a texture of RGBA8Unorm to one of RGBA8Unorm is not built"), step: 0 (0x0)}) Known gap (rt README, blit encoder): a copy between overlapping regions of one level and slice of one image is Gap::TextureCopy, not built. Metal leaves such a copy undefined (Apple's `copy(from:...to:...)` page: "unexpected behavior"), and the Apple M3 Max copies as if through a temporary (the case's doc); one vkCmdCopyImage cannot make it, as no memory a command reads may be both a source and a destination region (VUID-vkCmdCopyImage-pRegions-00124).
|
||||
compressed-views-bc4-r-snorm * refused case/2d-13x7/work Err({refused: Error::Refused("a BC4RUnorm view of a BC4RSnorm texture, which Metal does not view it as with its usage"), resource: 1 (0x1)}) An accepted difference: Metal documents no BC4 view between the format's signed and unsigned forms, and rt refuses it typed. MTLTexture.h makes a view "with a different (but compatible) pixel format"; Apple's makeTextureView(pixelFormat:) page lists the compatible groups: "All 8-, 16-, 32-, 64-, and 128-bit color formats are compatible with other formats with the same bit length.", "sRGB and non-sRGB forms of the same compressed format (for example, bc1_rgba and bc1_rgba_srgb)" and a combined depth-stencil format with its stencil view, and a compressed format's other forms are in none. The M3 Max (macOS 27.0.1) made and read the view, its API validation layer on as well.
|
||||
compressed-views-bc4-r-unorm * refused case/2d-13x7/work Err({refused: Error::Refused("a BC4RSnorm view of a BC4RUnorm texture, which Metal does not view it as with its usage"), resource: 1 (0x1)}) An accepted difference: Metal documents no BC4 view between the format's signed and unsigned forms, and rt refuses it typed. MTLTexture.h makes a view "with a different (but compatible) pixel format"; Apple's makeTextureView(pixelFormat:) page lists the compatible groups: "All 8-, 16-, 32-, 64-, and 128-bit color formats are compatible with other formats with the same bit length.", "sRGB and non-sRGB forms of the same compressed format (for example, bc1_rgba and bc1_rgba_srgb)" and a combined depth-stencil format with its stencil view, and a compressed format's other forms are in none. The M3 Max (macOS 27.0.1) made and read the view, its API validation layer on as well.
|
||||
compressed-views-bc5-rg-snorm * refused case/2d-13x7/work Err({refused: Error::Refused("a BC5RGUnorm view of a BC5RGSnorm texture, which Metal does not view it as with its usage"), resource: 1 (0x1)}) An accepted difference: Metal documents no BC5 view between the format's signed and unsigned forms, and rt refuses it typed. MTLTexture.h makes a view "with a different (but compatible) pixel format"; Apple's makeTextureView(pixelFormat:) page lists the compatible groups: "All 8-, 16-, 32-, 64-, and 128-bit color formats are compatible with other formats with the same bit length.", "sRGB and non-sRGB forms of the same compressed format (for example, bc1_rgba and bc1_rgba_srgb)" and a combined depth-stencil format with its stencil view, and a compressed format's other forms are in none. The M3 Max (macOS 27.0.1) made and read the view, its API validation layer on as well.
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2177,13 +2177,18 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
|
||||
(`Refusal::TextureCopyMismatch`), and a region outside either texture or off its block grid
|
||||
(`Refusal::TextureRegion`). Not built (`Gap::TextureCopy`): what one `vkCmdCopyImage` in the
|
||||
floor does not make (a multisample texture, a format of depth and stencil both, one pixel format
|
||||
held in two Vulkan formats by the textures' usages, a 1D texture with another type), and
|
||||
overlapping regions of one level and slice of one image, which Metal leaves undefined (Apple's
|
||||
`copy(from:...to:...)` page: "unexpected behavior").
|
||||
held in two Vulkan formats by the textures' usages, a 1D texture with another type).
|
||||
- Within one level and slice of one image (a texture into itself, or a texture and its view,
|
||||
which shares its image), regions apart copy with one `vkCmdCopyImage`, that subresource in the
|
||||
general layout: one barrier moves it there and one home, the same three barriers as any copy.
|
||||
The same region copies nothing and records no command, every texel already its own.
|
||||
- Overlapping regions there, which Metal leaves undefined (Apple's `copy(from:...to:...)` page:
|
||||
"unexpected behavior"), copy as if the source were read whole before any texel is written,
|
||||
which is what an Apple M3 Max gives. No `vkCmdCopyImage` reads a texel it writes, so the region
|
||||
is cut into slabs along one axis it is shifted on, the axis that takes the fewest. Each slab is
|
||||
no thicker than the shift there, and the slab at the far end of the shift goes first. Each slab
|
||||
is one `vkCmdCopyImage`, with an execution barrier between two slabs. A shift of one texel takes
|
||||
one slab and one barrier per texel of the region's extent on that axis.
|
||||
- `copy_from_buffer` is `copyFromBuffer:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:`
|
||||
`sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:` and
|
||||
`copy_from_texture_to_buffer` is `copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:`
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
//! once the copy has run, and holds one global memory barrier beside the image barriers, so the
|
||||
//! copy's writes are visible to every later command through any resource over the same bytes (a
|
||||
//! heap's aliases), not through the image alone. Nothing is copied but the region Metal names.
|
||||
//! Overlapping regions of one level and slice are the one exception to one command: slabs, one
|
||||
//! `vkCmdCopyImage` each, an execution barrier between two ([`Slabs`]).
|
||||
//!
|
||||
//! A copy between a buffer and a texture is the same: `vkCmdCopyBufferToImage` or
|
||||
//! `vkCmdCopyImageToBuffer` against the bytes shaders reach (the buffer's range of its block, or a
|
||||
@@ -165,13 +167,18 @@ impl BlitCommandEncoder {
|
||||
/// nothing, as plain Metal does where its validation stops the call. Within one level and
|
||||
/// slice of one image (the texture into itself, or a texture and its view), regions apart
|
||||
/// copy with that subresource in the general layout, and the same region copies nothing and
|
||||
/// records no command, every texel already its own; Metal leaves overlapping regions
|
||||
/// undefined. The command buffer keeps both textures until it retires.
|
||||
/// records no command, every texel already its own. Overlapping regions there, which Metal
|
||||
/// leaves undefined, copy as if the source were read whole before any texel is written, the
|
||||
/// answer an Apple M3 Max gives: in slabs across one axis, each no thicker than the shift
|
||||
/// between the regions there, so that its two regions lie apart, one `vkCmdCopyImage` a slab
|
||||
/// and the far end of the shift first, an execution barrier between two slabs. The axis is the
|
||||
/// one of fewest slabs; a shift of one texel takes one slab a texel. The command buffer keeps
|
||||
/// both textures until it retires.
|
||||
///
|
||||
/// Err: [`Refusal::OtherDevice`] for another device's texture; [`Refusal::TextureRegion`] for
|
||||
/// a level, slice or region outside either texture or off its format's block grid;
|
||||
/// [`Refusal::TextureCopyMismatch`]; [`Gap::TextureCopy`], overlapping regions of one
|
||||
/// subresource among it; [`Error::Vulkan`] where the command buffer cannot record.
|
||||
/// [`Refusal::TextureCopyMismatch`]; [`Gap::TextureCopy`]; [`Error::Vulkan`] where the command
|
||||
/// buffer cannot record.
|
||||
pub fn copy_from_texture(
|
||||
&mut self,
|
||||
source: &Texture,
|
||||
@@ -234,19 +241,17 @@ impl BlitCommandEncoder {
|
||||
(&away_one, &back_one)
|
||||
}
|
||||
};
|
||||
let regions = [vk::ImageCopy {
|
||||
src_subresource: copy.from.layers(copy.aspect),
|
||||
src_offset: copy.from.offset(),
|
||||
dst_subresource: copy.to.layers(copy.aspect),
|
||||
dst_offset: copy.to.offset(),
|
||||
extent: copy.from.extent(),
|
||||
}];
|
||||
// Between two slabs, every hazard is a write after a read: no slab reads a texel an
|
||||
// earlier one wrote (`Slabs`), so an execution dependency orders them.
|
||||
let between = [vk::MemoryBarrier2::default()
|
||||
.src_stage_mask(vk::PipelineStageFlags2::COPY)
|
||||
.dst_stage_mask(vk::PipelineStageFlags2::COPY)];
|
||||
let device = &core.device;
|
||||
let (named_read, named_write) = (source.copy_layout(read), destination.copy_layout(write));
|
||||
// SAFETY: the command buffer records outside any render pass and keeps both images until
|
||||
// it retires; each subresource is in its home layout between commands, and in its copy
|
||||
// layout between the barriers: two subresources, or one in the general layout whose two
|
||||
// regions lie apart (`texture_copy`); the region lies in both.
|
||||
// regions lie apart in each slab (`texture_copy`); each slab's regions lie in both.
|
||||
unsafe {
|
||||
device.cmd_pipeline_barrier2(
|
||||
command,
|
||||
@@ -254,14 +259,21 @@ impl BlitCommandEncoder {
|
||||
.memory_barriers(&earlier)
|
||||
.image_memory_barriers(away),
|
||||
);
|
||||
device.cmd_copy_image(
|
||||
command,
|
||||
source.image(),
|
||||
named_read,
|
||||
destination.image(),
|
||||
named_write,
|
||||
®ions,
|
||||
);
|
||||
for (n, region) in copy.regions().enumerate() {
|
||||
if n > 0 {
|
||||
let dependency = vk::DependencyInfo::default().memory_barriers(&between);
|
||||
device.cmd_pipeline_barrier2(command, &dependency);
|
||||
building.count(Metric::Barriers);
|
||||
}
|
||||
device.cmd_copy_image(
|
||||
command,
|
||||
source.image(),
|
||||
named_read,
|
||||
destination.image(),
|
||||
named_write,
|
||||
&[region],
|
||||
);
|
||||
}
|
||||
close(core, command, back);
|
||||
}
|
||||
building.count(Metric::Barriers);
|
||||
@@ -1264,14 +1276,64 @@ impl<'a> Side<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A copy between two textures, checked: the region in each, the aspect it copies, and whether
|
||||
/// the two regions lie apart in one subresource of one image, which the copy takes in the
|
||||
/// general layout.
|
||||
/// A copy between two textures, checked: the region in each, the aspect it copies, whether the
|
||||
/// two regions lie in one subresource of one image, which the copy takes in the general layout,
|
||||
/// and the slabs it copies in.
|
||||
pub(crate) struct ImageCopy {
|
||||
pub(crate) from: Placed,
|
||||
pub(crate) to: Placed,
|
||||
pub(crate) aspect: vk::ImageAspectFlags,
|
||||
pub(crate) shared: bool,
|
||||
pub(crate) slabs: Slabs,
|
||||
}
|
||||
|
||||
impl ImageCopy {
|
||||
/// Its copy commands' regions, in the order they run: one a slab.
|
||||
pub(crate) fn regions(&self) -> impl Iterator<Item = vk::ImageCopy> + '_ {
|
||||
let Slabs {
|
||||
axis,
|
||||
thickness,
|
||||
reversed,
|
||||
} = self.slabs;
|
||||
let extent = self.from.size[axis];
|
||||
let count = extent.div_ceil(thickness);
|
||||
(0..count).map(move |n| {
|
||||
let start = thickness
|
||||
* match reversed {
|
||||
true => count - 1 - n,
|
||||
false => n,
|
||||
};
|
||||
let slab = |placed: &Placed| {
|
||||
let mut slab = *placed;
|
||||
slab.origin[axis] += start;
|
||||
slab.size[axis] = thickness.min(extent - start);
|
||||
slab
|
||||
};
|
||||
let (from, to) = (slab(&self.from), slab(&self.to));
|
||||
vk::ImageCopy {
|
||||
src_subresource: from.layers(self.aspect),
|
||||
src_offset: from.offset(),
|
||||
dst_subresource: to.layers(self.aspect),
|
||||
dst_offset: to.offset(),
|
||||
extent: from.extent(),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// The slabs a copy between textures runs as, one copy command each: the region cut across
|
||||
/// `axis` into slabs `thickness` texels thick (the last what is left), from the far end of the
|
||||
/// axis first where `reversed`. Regions apart copy as one slab. Overlapping regions of one
|
||||
/// subresource are cut no thicker than the shift between them along an axis they are shifted
|
||||
/// along, so that each slab's two regions lie apart, on the axis of fewest slabs; and the slab
|
||||
/// at the end the shift points to goes first, so that no slab reads a texel an earlier one
|
||||
/// wrote. The copy so gives what reading its source whole before writing gives, as `memmove`
|
||||
/// does.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct Slabs {
|
||||
pub(crate) axis: usize,
|
||||
pub(crate) thickness: u32,
|
||||
pub(crate) reversed: bool,
|
||||
}
|
||||
|
||||
/// Checks a fill of `range` of a buffer at `base` in its block, `len` bytes long: its offset in
|
||||
@@ -1595,26 +1657,43 @@ pub(crate) fn texture_copy(
|
||||
let (Some(from), Some(to)) = placed else {
|
||||
return Ok(None);
|
||||
};
|
||||
// One subresource of one image, the textures one or a texture and its view: Metal leaves a
|
||||
// copy whose regions overlap undefined (Apple's `copy(from:...to:...)` page: "unexpected
|
||||
// behavior"). The same region copies nothing, every texel already its own; disjoint regions
|
||||
// copy in the general layout (`VUID-vkCmdCopyImage-srcImage-09460`, `-pRegions-00124`).
|
||||
// One subresource of one image, the textures one or a texture and its view, copies in the
|
||||
// general layout (`VUID-vkCmdCopyImage-srcImage-09460`), and no command's source and
|
||||
// destination share a texel (`-pRegions-00124`). The same region copies nothing, every texel
|
||||
// already its own. Metal leaves a copy whose regions overlap undefined (Apple's
|
||||
// `copy(from:...to:...)` page: "unexpected behavior"); an Apple M3 Max reads the source whole
|
||||
// before it writes, which slabs give (`Slabs`).
|
||||
let shared = same && from.level == to.level && from.layer == to.layer;
|
||||
if shared && from.origin == to.origin {
|
||||
return Ok(None);
|
||||
}
|
||||
let apart = (0..3).any(|axis| {
|
||||
let (a, b, extent) = (from.origin[axis], to.origin[axis], from.size[axis]);
|
||||
a + extent <= b || b + extent <= a
|
||||
});
|
||||
if shared && !apart {
|
||||
return Err(gap());
|
||||
}
|
||||
let slabs = match shared && !apart {
|
||||
false => Slabs {
|
||||
axis: 0,
|
||||
thickness: from.size[0],
|
||||
reversed: false,
|
||||
},
|
||||
true => {
|
||||
let shifted = (0..3).filter(|&axis| from.origin[axis] != to.origin[axis]);
|
||||
let thickness = |axis: usize| from.origin[axis].abs_diff(to.origin[axis]);
|
||||
let fewest = shifted.min_by_key(|&axis| from.size[axis].div_ceil(thickness(axis)));
|
||||
let Some(axis) = fewest else {
|
||||
return Ok(None);
|
||||
};
|
||||
Slabs {
|
||||
axis,
|
||||
thickness: thickness(axis),
|
||||
reversed: to.origin[axis] > from.origin[axis],
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(Some(ImageCopy {
|
||||
from,
|
||||
to,
|
||||
aspect: unit.aspect,
|
||||
shared,
|
||||
slabs,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -1113,13 +1113,10 @@ pub enum Gap {
|
||||
/// [`BlitCommandEncoder::copy_from_texture`](crate::BlitCommandEncoder::copy_from_texture)
|
||||
/// that no single `vkCmdCopyImage` in the floor makes: a multisample texture; a format of
|
||||
/// depth and stencil both; one pixel format held in two Vulkan formats, which the two
|
||||
/// textures' usages chose; a 1D texture with one of another type; or overlapping regions of
|
||||
/// one level and slice of one image (one texture, or a texture and its view), which Metal
|
||||
/// leaves undefined. Regions apart there copy, and the same region copies nothing.
|
||||
/// textures' usages chose; or a 1D texture with one of another type.
|
||||
///
|
||||
/// Basis: ours (Vulkan 1.3 copies none of these with one command; each is built when a replay
|
||||
/// stream makes one; Apple's `copy(from:sourceSlice:sourceLevel:sourceOrigin:sourceSize:to:`
|
||||
/// page calls a copy between overlapping regions of one texture "unexpected behavior").
|
||||
/// stream makes one).
|
||||
TextureCopy {
|
||||
/// The source texture's pixel format.
|
||||
source: PixelFormat,
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
//! what one copy command in the floor does not make, one pixel format held in two Vulkan formats
|
||||
//! among it, is `Gap::TextureCopy`; within one level and slice of one image (one texture, or a
|
||||
//! texture and its view), regions apart copy in the general layout, the same region copies
|
||||
//! nothing, and overlapping regions, which Metal leaves undefined, are `Gap::TextureCopy`; a
|
||||
//! level, slice or region outside a texture or
|
||||
//! off its block grid is `Refusal::TextureRegion`; a size of 0 on an axis a texture lacks copies
|
||||
//! one texel there, and on another copies nothing; a 3D texture's image copies to and from a 2D
|
||||
//! slice.
|
||||
//! nothing, and overlapping regions, which Metal leaves undefined, copy in slabs across the
|
||||
//! axis of fewest, each no thicker than the shift there, the far end of the shift first; a
|
||||
//! level, slice or region outside a texture or off its block grid is `Refusal::TextureRegion`;
|
||||
//! a size of 0 on an axis a texture lacks copies one texel there, and on another copies
|
||||
//! nothing; a 3D texture's image copies to and from a 2D slice.
|
||||
//! - Under a device cfg, on every device of the cfg's kind: the bytes of a level of a 2D texture
|
||||
//! land in a slice of a 2D array, a cube's face in an
|
||||
//! image of a 3D texture, an image of a 3D texture in a 2D texture, a slice of an array in
|
||||
@@ -20,7 +20,9 @@
|
||||
//! by the copy's first. Every gauge comes back to zero with the device. The bytes each copy
|
||||
//! must leave are plain Metal's: their FNV-1a 64 hashes are those of probe `blit_copy_layouts.m`
|
||||
//! in the conformance crate (an Apple M3 Max, macOS 27.0.1, job m3-max-43464, plain and under
|
||||
//! the validation layer).
|
||||
//! the validation layer). Overlapping regions of one level and slice leave the source's bytes
|
||||
//! from before the copy, toward higher and lower coordinates on each axis, through a view, and
|
||||
//! in BC1 blocks where the device makes them, at one barrier more a slab after the first.
|
||||
//! - Between a buffer and a texture: each image of the region lies at its own offset, its rows a
|
||||
//! count of texels apart; what Metal's validation stops is `Refusal::BufferCopyLayout`, and an
|
||||
//! offset or row stride a copy command cannot address `Gap::BufferCopyAlignment`. Under a device
|
||||
@@ -53,7 +55,7 @@
|
||||
|
||||
use crate::blit::{
|
||||
buffer_copy, buffer_to_buffer, fill_range, texture_copy, BufferCopy, BufferLayout, ImageCopy,
|
||||
Lies, Side, Span, TexturePlace,
|
||||
Lies, Side, Slabs, Span, TexturePlace,
|
||||
};
|
||||
use crate::error::{Error, Gap, Refusal};
|
||||
use crate::texture::{CopyUnit, Placed};
|
||||
@@ -234,7 +236,7 @@ fn a_3d_image_copies_to_and_from_a_2d_slice_and_a_cube_face_is_its_slice() {
|
||||
Refusal::TextureRegion { .. }
|
||||
));
|
||||
// One texture's two slices copy; within one slice, regions apart copy in the general layout,
|
||||
// the same region copies nothing, and overlapping regions are not built.
|
||||
// the same region copies nothing, and overlapping regions copy in slabs.
|
||||
let mut array = descriptor(TextureType::Type2DArray, PixelFormat::R8Unorm, [4, 4, 1]);
|
||||
array.array_length = 2;
|
||||
let a = side(&array, vk::Format::R8_UNORM, color(1));
|
||||
@@ -251,22 +253,94 @@ fn a_3d_image_copies_to_and_from_a_2d_slice_and_a_cube_face_is_its_slice() {
|
||||
assert_eq!(apart.to, placed(0, 0, to, size));
|
||||
}
|
||||
assert!(matches!(within(at(0, 0, [0; 3]), [3, 3, 1]), Ok(None)));
|
||||
for (to, size) in [
|
||||
([1, 1, 0], [2, 2, 1]),
|
||||
([1, 0, 0], [2, 1, 1]),
|
||||
([0, 1, 0], [4, 2, 1]),
|
||||
// Overlapping regions copy in slabs, each one's regions apart.
|
||||
for (to, size, slabs) in [
|
||||
([1, 1, 0], [2, 2, 1], (0, 1, true)),
|
||||
([1, 0, 0], [2, 1, 1], (0, 1, true)),
|
||||
([0, 1, 0], [4, 2, 1], (1, 1, true)),
|
||||
] {
|
||||
let copy = copied(within(at(0, 0, to), size));
|
||||
assert!(copy.shared, "{to:?} {size:?}");
|
||||
let (axis, thickness, reversed) = slabs;
|
||||
assert_eq!(
|
||||
gap(within(at(0, 0, to), size)),
|
||||
Gap::TextureCopy {
|
||||
source: PixelFormat::R8Unorm,
|
||||
destination: PixelFormat::R8Unorm
|
||||
copy.slabs,
|
||||
Slabs {
|
||||
axis,
|
||||
thickness,
|
||||
reversed
|
||||
},
|
||||
"{to:?} {size:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The regions of `copy`'s commands, in order: each one's source and destination origins and its
|
||||
/// extent.
|
||||
fn slab_regions(copy: &ImageCopy) -> Vec<([i32; 2], [i32; 2], [u32; 2])> {
|
||||
(copy.regions())
|
||||
.map(|r| {
|
||||
(
|
||||
[r.src_offset.x, r.src_offset.y],
|
||||
[r.dst_offset.x, r.dst_offset.y],
|
||||
[r.extent.width, r.extent.height],
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlapping_regions_copy_in_slabs_the_far_end_of_the_shift_first() {
|
||||
let d = descriptor(TextureType::Type2D, PixelFormat::RG8Unorm, [256, 352, 1]);
|
||||
let s = side(&d, vk::Format::R8G8_UNORM, color(2));
|
||||
let within = |from, size, to| {
|
||||
copied(texture_copy(
|
||||
&s,
|
||||
at(0, 0, from),
|
||||
size,
|
||||
&s,
|
||||
at(0, 0, to),
|
||||
true,
|
||||
))
|
||||
};
|
||||
// Columns 0 to 20 of a row onto columns 20 to 40: the last column first, then the rest.
|
||||
assert_eq!(
|
||||
slab_regions(&within([0, 0, 0], [21, 1, 0], [20, 0, 0])),
|
||||
[([20, 0], [40, 0], [1, 1]), ([0, 0], [20, 0], [20, 1])]
|
||||
);
|
||||
// Toward lower coordinates, the first slab first; the last slab what is left.
|
||||
assert_eq!(
|
||||
slab_regions(&within([0, 5, 0], [3, 5, 1], [0, 3, 0])),
|
||||
[
|
||||
([0, 5], [0, 3], [3, 2]),
|
||||
([0, 7], [0, 5], [3, 2]),
|
||||
([0, 9], [0, 7], [3, 1]),
|
||||
]
|
||||
);
|
||||
// Shifted along both axes, the axis of fewer slabs: three across y against eight across x.
|
||||
let both = within([4, 4, 0], [8, 6, 1], [5, 2, 0]);
|
||||
assert_eq!(
|
||||
both.slabs,
|
||||
Slabs {
|
||||
axis: 1,
|
||||
thickness: 2,
|
||||
reversed: false
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
slab_regions(&both),
|
||||
[
|
||||
([4, 4], [5, 2], [8, 2]),
|
||||
([4, 6], [5, 4], [8, 2]),
|
||||
([4, 8], [5, 6], [8, 2]),
|
||||
]
|
||||
);
|
||||
// Regions apart are one slab, the whole region.
|
||||
assert_eq!(
|
||||
slab_regions(&within([0, 0, 0], [4, 4, 1], [4, 0, 0])),
|
||||
[([0, 0], [4, 0], [4, 4])]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_metal_refuses_is_refused_and_what_one_command_does_not_make_is_a_gap() {
|
||||
let d = |format, extent| descriptor(TextureType::Type2D, format, extent);
|
||||
@@ -1330,7 +1404,7 @@ pub(crate) mod on_device {
|
||||
/// A copy within one subresource of one image, from a texture's view or from the texture
|
||||
/// itself into the texture: disjoint regions copy, one submission and three barriers as any
|
||||
/// copy, everything around the region kept; the same region copies nothing and records no
|
||||
/// command; overlapping regions, which Metal leaves undefined, are `Gap::TextureCopy`.
|
||||
/// command.
|
||||
#[test]
|
||||
fn every_device_copies_within_one_subresource_of_a_texture_and_its_view() {
|
||||
each_device("blit_within", |name, _, device| {
|
||||
@@ -1416,20 +1490,6 @@ pub(crate) mod on_device {
|
||||
};
|
||||
(encoder.copy_from_texture(&view, at([2, 1, 0]), [3, 3, 1], &texture, at([2, 1, 0])))
|
||||
.unwrap_or_else(|error| panic!("{name}: the same region: {error}"));
|
||||
// Overlapping regions are not built.
|
||||
assert!(
|
||||
matches!(
|
||||
encoder.copy_from_texture(
|
||||
&view,
|
||||
at([0, 0, 0]),
|
||||
[4, 4, 1],
|
||||
&texture,
|
||||
at([2, 2, 0])
|
||||
),
|
||||
Err(Error::Unsupported(Gap::TextureCopy { .. }))
|
||||
),
|
||||
"{name}: overlapping regions"
|
||||
);
|
||||
encoder.end_encoding();
|
||||
command_buffer.commit().expect("a commit");
|
||||
finished(name, &command_buffer);
|
||||
@@ -1452,6 +1512,170 @@ pub(crate) mod on_device {
|
||||
});
|
||||
}
|
||||
|
||||
/// Overlapping regions of one level and slice, which Metal leaves undefined, leave each
|
||||
/// destination texel holding what the source held before the copy, the answer an Apple M3
|
||||
/// Max gives (the conformance crate's `buffer_texture_blits.rs`), everything around them
|
||||
/// kept: shifted toward higher and toward lower coordinates along x and along y, from a
|
||||
/// texture's view into the texture, along the depth of a 3D texture, and by whole blocks of
|
||||
/// BC1 where the device makes it. Each copy is one submission and copies no byte of the
|
||||
/// runtime's own; each slab after the first costs one barrier more than a copy's three.
|
||||
#[test]
|
||||
fn every_device_copies_overlapping_regions_from_the_source_before_the_copy() {
|
||||
each_device("blit_overlapping", |name, _, device| {
|
||||
device
|
||||
.grant_indices(IndexClass::Texture, 4096, 4)
|
||||
.expect("a grant");
|
||||
let made = |texture_type, format, extent, index| {
|
||||
let read = TextureUsage::SHADER_READ;
|
||||
texture(&device, texture_type, format, extent, read, index)
|
||||
};
|
||||
let plane = (made(
|
||||
TextureType::Type2D,
|
||||
PixelFormat::RGBA8Unorm,
|
||||
[8, 8, 1],
|
||||
4096,
|
||||
))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let view = (plane.new_texture_view(
|
||||
PixelFormat::RGBA8Unorm,
|
||||
TextureType::Type2D,
|
||||
0..1,
|
||||
0..1,
|
||||
Some(4097),
|
||||
))
|
||||
.unwrap_or_else(|error| panic!("{name}: the view: {error}"));
|
||||
let volume = (made(TextureType::Type3D, PixelFormat::R8Unorm, [4, 4, 4], 4098))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let blocks = made(TextureType::Type2D, PixelFormat::BC1RGBA, [16, 16, 1], 4099);
|
||||
let level = |texture, unit, block| Level {
|
||||
texture,
|
||||
slice: 0,
|
||||
level: 0,
|
||||
unit,
|
||||
block,
|
||||
};
|
||||
let (whole, through_view) = (level(&plane, 4, 1), level(&view, 4, 1));
|
||||
let images = level(&volume, 1, 1);
|
||||
let bc1 = match &blocks {
|
||||
Ok(texture) => Some(level(texture, 8, 4)),
|
||||
Err(Error::Unsupported(Gap::TextureFormat { .. })) => {
|
||||
println!("{name}: no BC1 texture on this device");
|
||||
None
|
||||
}
|
||||
Err(error) => panic!("{name}: BC1: {error}"),
|
||||
};
|
||||
// Each case: the source and where in it, the destination and where in it, the size
|
||||
// in elements, and the slabs the copy takes.
|
||||
let mut cases = vec![
|
||||
(
|
||||
"toward higher x",
|
||||
&whole,
|
||||
[0, 1, 0],
|
||||
&whole,
|
||||
[3, 1, 0],
|
||||
[5, 2, 1],
|
||||
2,
|
||||
),
|
||||
(
|
||||
"toward lower x",
|
||||
&whole,
|
||||
[2, 0, 0],
|
||||
&whole,
|
||||
[0, 0, 0],
|
||||
[6, 3, 1],
|
||||
3,
|
||||
),
|
||||
(
|
||||
"toward higher y",
|
||||
&whole,
|
||||
[1, 0, 0],
|
||||
&whole,
|
||||
[1, 1, 0],
|
||||
[3, 6, 1],
|
||||
6,
|
||||
),
|
||||
(
|
||||
"toward lower y",
|
||||
&whole,
|
||||
[0, 3, 0],
|
||||
&whole,
|
||||
[0, 1, 0],
|
||||
[8, 5, 1],
|
||||
3,
|
||||
),
|
||||
(
|
||||
"from the view",
|
||||
&through_view,
|
||||
[0; 3],
|
||||
&whole,
|
||||
[2, 2, 0],
|
||||
[4, 4, 1],
|
||||
2,
|
||||
),
|
||||
(
|
||||
"along the depth",
|
||||
&images,
|
||||
[0; 3],
|
||||
&images,
|
||||
[0, 0, 1],
|
||||
[4, 4, 3],
|
||||
3,
|
||||
),
|
||||
];
|
||||
if let Some(bc1) = &bc1 {
|
||||
cases.push((
|
||||
"by whole BC1 blocks",
|
||||
bc1,
|
||||
[0; 3],
|
||||
bc1,
|
||||
[1, 0, 0],
|
||||
[3, 2, 1],
|
||||
3,
|
||||
));
|
||||
}
|
||||
let queue = device.new_command_queue(4).expect("a queue");
|
||||
let counters = device.counters();
|
||||
for (seed, (case, from, at, to, to_at, size, slabs)) in (1..).zip(cases) {
|
||||
let source = to.write(seed);
|
||||
// The upload goes with a command buffer of its own, one with commands.
|
||||
let upload = queue.command_buffer().expect("a command buffer");
|
||||
upload
|
||||
.record_for_test(&[], |_, _| {})
|
||||
.expect("a command buffer's commands");
|
||||
upload.commit().expect("a commit");
|
||||
finished(name, &upload);
|
||||
let copy = Expect {
|
||||
from,
|
||||
source: &source,
|
||||
at,
|
||||
to,
|
||||
before: source.clone(),
|
||||
to_at,
|
||||
size,
|
||||
};
|
||||
settled(&device);
|
||||
let before = counters.metrics();
|
||||
let command_buffer = queue.command_buffer().expect("a command buffer");
|
||||
copy.record(name, &command_buffer);
|
||||
command_buffer.commit().expect("a commit");
|
||||
finished(name, &command_buffer);
|
||||
assert_eq!(command_buffer.error(), None, "{name}: {case}");
|
||||
let after = counters.metrics();
|
||||
assert_eq!(
|
||||
(
|
||||
after.submissions - before.submissions,
|
||||
after.barriers - before.barriers,
|
||||
after.bytes_copied - before.bytes_copied,
|
||||
),
|
||||
(1, 2 + slabs, 0),
|
||||
"{name}: {case}: submissions, barriers, bytes copied"
|
||||
);
|
||||
assert_eq!(to.read(), copy.after(), "{name}: {case}");
|
||||
}
|
||||
println!("{name}: overlapping copies, each from the source before the copy");
|
||||
});
|
||||
}
|
||||
|
||||
/// Writes `bytes` over the start of a Shared buffer.
|
||||
fn write(buffer: &Buffer, bytes: &[u8]) {
|
||||
let contents = buffer.contents().expect("a Shared buffer");
|
||||
|
||||
@@ -42,7 +42,7 @@ Its limits, measured rather than asserted:
|
||||
| committed recordings | 1319 |
|
||||
| distinct SDK items the Metal leg reaches, of any status | 806 |
|
||||
| of those, reached only where this cannot name the family | 5 |
|
||||
| ledger rows (a case whose gap is recorded) | 7354 |
|
||||
| ledger rows (a case whose gap is recorded) | 7353 |
|
||||
| declared crossings of the option space (pairs put to Metal at once) | 26 |
|
||||
| declared crossings that are no pair of it (a boolean or numeric field, or one type in two slots) | 30 |
|
||||
|
||||
@@ -2301,7 +2301,6 @@ A case whose difference from Metal is recorded rather than compared away. The le
|
||||
| `buffer-tails-blits` | An accepted difference: Metal documents the texture as the buffer's storage, which these rows run past, and rt refuses it typed. Apple's makeTexture(descriptor:… |
|
||||
| `buffer-tails-kernels` | An accepted difference: Metal documents the texture as the buffer's storage, which these rows run past, and rt refuses it typed. Apple's makeTexture(descriptor:… |
|
||||
| `buffer-tails-texture-buffer` | refused: no stream uses it yet (states-only play 11-19, m3-max-56371-56373, 56375, player 44668b439f: 32 streams, every render and compute pipeline state made).… |
|
||||
| `buffer-texture-blits-overlapping` | Known gap (rt README, blit encoder): a copy between overlapping regions of one level and slice of one image is Gap::TextureCopy, not built. Metal leaves such a … |
|
||||
| `compressed-views-bc4-r-snorm` | An accepted difference: Metal documents no BC4 view between the format's signed and unsigned forms, and rt refuses it typed. MTLTexture.h makes a view "with a d… |
|
||||
| `compressed-views-bc4-r-unorm` | An accepted difference: Metal documents no BC4 view between the format's signed and unsigned forms, and rt refuses it typed. MTLTexture.h makes a view "with a d… |
|
||||
| `compressed-views-bc5-rg-snorm` | An accepted difference: Metal documents no BC5 view between the format's signed and unsigned forms, and rt refuses it typed. MTLTexture.h makes a view "with a d… |
|
||||
|
||||
+1
-1
@@ -374,7 +374,7 @@ Columns:
|
||||
| `LodClamps` | A sampler state bound with LOD clamps its samples read otherwise through (`ComputeCommandEncoder::set_sampler_state_with_lod_clamps` and the... | every device (a public call's own check of its arguments) | `ours`: no replay stream binds such clamps: every bind-time clamp the streams make reads as its state's own | 1: `crates/metal2vulkan-runtime/src/sampler.rs (clamps_at_bind)` | `-` |
|
||||
| `TextureBytes` | `Texture::replace_region`, `Texture::get_bytes` or a blit copy between a buffer and a texture (`BlitCommandEncoder::copy_from_buffer`) of a... | every device (a public call's own check of its arguments) | `ours`: no copy between such an image and bytes is built | 4: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-runtime/src/blit.rs (with_option)` (+2) | `-` |
|
||||
| `FloatDepthUpload` | `Texture::replace_region` or `BlitCommandEncoder::copy_from_buffer` into a 32-bit float depth (`Depth32Float`) | every device (a public call's own check of its arguments) | `ours`: no upload of a 32-bit float depth is built | 3: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-runtime/src/texture.rs (replace_region)` (+1) | `-` |
|
||||
| `TextureCopy` | `BlitCommandEncoder::copy_from_texture` that no single `vkCmdCopyImage` in the floor makes | every device (a public call's own check of its arguments) | `ours`: Vulkan 1.3 copies none of these with one command; each is built when a replay stream makes one; Apple's `copy(from:sourceSlice:sourceLevel:sourceOrigin:sourceSize:to:` page calls a copy between overlapping regions of one texture "unexpected behavior" | 1: `crates/metal2vulkan-runtime/src/blit.rs (texture_copy)` | `-` |
|
||||
| `TextureCopy` | `BlitCommandEncoder::copy_from_texture` that no single `vkCmdCopyImage` in the floor makes | every device (a public call's own check of its arguments) | `ours`: Vulkan 1.3 copies none of these with one command; each is built when a replay stream makes one | 1: `crates/metal2vulkan-runtime/src/blit.rs (texture_copy)` | `-` |
|
||||
| `TextureOverBuffer` | A texture over a buffer (`Buffer::new_texture`) the runtime does not make | every device (a public call's own check of its arguments) | `ours`: the in-place linear image and the copy form take one 2D color image | 3: `crates/metal2vulkan-runtime/src/texture.rs (check_over)`, `crates/metal2vulkan-runtime/src/texture.rs (error)` (+1) | `-` |
|
||||
| `HeapTexture` | A heap texture the runtime does not place (`Device::new_heap_texture`, `Device::new_heap_texture_for_views` and `Device::heap_texture_size_and_align`) | every device (a public call's own check of its arguments) | `ours`: heap textures are built for Private heaps of placeable images | 2: `crates/metal2vulkan-runtime/src/texture.rs (heap_fit)`, `crates/metal2vulkan-runtime/src/texture.rs (heap_source)` | `-` |
|
||||
| `SurfaceUsage` | A surface plane in place (`Device::new_exported_surface`) whose texture's uses ask an image usage its linear tiling lacks (storage, for one) | at the device's limit | `device`: the image format query and the format features of the plane's tiling | 3: `crates/metal2vulkan-runtime/src/d3d11.rs (d3d11_plane)`, `crates/metal2vulkan-runtime/src/surface.rs (plane)` (+1) | `-` |
|
||||
|
||||
Reference in new issue
Block a user