Runtime: a Direct3D 11 plane takes only its bind flags' usage, never the attachment feedback loop's

A Direct3D 11 plane's image (Device::import_d3d11_surface, on Windows) took the usage its
texture's bind flags give (0x17 for RENDER_TARGET | SHADER_RESOURCE) and, on a device with the
attachment feedback loop, where its texture was a render target shaders read, also
VK_IMAGE_USAGE_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT (0x80017), the one usage Direct3D 11's description
has no counterpart for. Vulkan states no rule for an image over memory another API made with
other parameters than that API's (its rule for an import of Vulkan's own export is the same image,
VUID-VkMemoryDedicatedAllocateInfo-image-01876). The consumer's issue 181 (device lost on AMD's
legacy Windows driver while work touches imported planes, its logs counting 134 to 20,261 loop
reads over all attachments) points here; nothing shows this is 181's cause, and the lab's Windows
card (UHD 630) has no loop, so no lab device has run a plane made with the loop usage.

The plane's image now takes exactly the usage its bind flags give, on every device: the import
asks no feedback usage and makes none. A draw that reads such a plane as an attachment of its own
pass takes the route rt already has for a surface plane whose image took no feedback usage
(Device::surface_texture): a copy into the plane's shadow, on a device with the loop as on one
without it. One form, no query added, nothing keyed. The cost: on a loop device such a draw pays a
counted copy (Metrics::attachment_read_copies), recorded in the runtime README's known gaps of
render encoders; the import's section and the attachment reads' copy paragraph say so.

How often a draw reads a plane it renders to, from a files read of the consumer (reims-vgpu
development 9889a815bb, read only): the consumer's own work over the planes is copies and clears
(render passes with no draw); the guest's render passes over a video plane are counted by its
boot diagnostics (rt-diag plane-passes) with no count on file, and no counter of the consumer's
splits the loop reads by planes. Not settled by the files; expected rare for decoded video.

Tests: d3d11_reads (new, every device of a device cfg): planes made as d3d11_plane_texture makes
them but for the import (no Direct3D 11 off Windows), an R8Unorm luma and an R16Uint chroma under
an RG8Unorm texture, of usage 0x17, read at their own pixel by draws of a pass over a view of each:
one copy into the shadow and no loop read, one plane submission, every texel exact; the control,
the luma with the feedback usage beside on a loop device, reads through the loop. The Direct3D 11
usage test (Windows) now imports under a render target shaders read and asserts the usage is the
bind flags' exactly, the textures not looped. Verified by the jobs named on landing.

The runtime-sources pin is unchanged (3b7da9e9...): no translator file moved. docs/REFUSALS.md
regenerates unchanged.
This commit is contained in:
Anees Iqbal committed 2026-12-04 11:19:10 -08:00
1 parent 1156d66df8
commit 1baee4fb75
6 files changed
+424 -50

No files matched your search

+12 -5
View File
@@ -1226,9 +1226,10 @@ memory another API made with other parameters: its rule for an import of Vulkan'
the same image (`VUID-VkMemoryDedicatedAllocateInfo-image-01876`), and its memory aliasing
promises a consistent reading to images of the same creation parameters. A texture whose uses
ask more (`ShaderWrite` on a texture made without `D3D11_BIND_UNORDERED_ACCESS`) is
`Gap::SurfaceUsage`. The one usage beside them is the attachment feedback loop's, which Direct3D
11's description has no counterpart for: taken where the descriptor's texture is a render target
a draw may read in its own pass. The image is mutable where it lists more than its own format, and
`Gap::SurfaceUsage`. So the image never takes the attachment feedback loop's usage, which Direct3D
11's description has no counterpart for: a draw that reads a plane as an attachment of its own
pass reads it through a copy into the plane's shadow on every device, with the loop or without it
(Known gaps of render encoders). The image is mutable where it lists more than its own format, and
it lists at most two more, the two places it asks beyond the texture Direct3D 11 made: the
descriptor's format where it differs (a chroma plane of `R16Uint` under an `RG8Unorm` texture, the
same bytes per texel in Metal's same view class), and the descriptor's sRGB sibling, which a guest
@@ -5654,8 +5655,8 @@ cache is answered compile-required on both.
attachment through the loop, through a texture or by a fetch (below), counts in
`Metrics::attachment_loop_reads`, its barriers in `Metrics::barriers`.
- Through a copy, on a device without the feedback loop, and for a surface plane or a texture in
place over a buffer whose image took no feedback usage (Exported surfaces; Memory blocks and
buffers), the draw reads the image's shadow: an image of the same
place over a buffer whose image took no feedback usage, a Direct3D 11 plane's on every device
(Exported surfaces; Memory blocks and buffers), the draw reads the image's shadow: an image of the same
format, extent, levels and layers, made at the first draw that reads the image and freed with it
(`Gauges::shadows` and `shadow_bytes`). A texture that reaches the attachment's level and layer
reads the shadow through its second element; one that reaches neither reads the image at home.
@@ -5898,6 +5899,12 @@ cache is answered compile-required on both.
attachment of its own pass through its shadow, the copy a device without the feedback loop
takes, which Metal does not make (`Metrics::attachment_read_copies` and
`attachment_read_copy_bytes`, in `bytes_copied` too).
- A Direct3D 11 plane (`Device::import_d3d11_surface`, on Windows) whose texture is a render
target shaders read is read as an attachment of its own pass through its shadow on every device,
the copy a device without the feedback loop takes, which Metal does not make
(`Metrics::attachment_read_copies` and `attachment_read_copy_bytes`, in `bytes_copied` too):
its image takes the usage its Direct3D 11 texture's bind flags give and no other, and that
description has no counterpart for the feedback usage (Exported surfaces).
- A colour render target in place over a buffer (Memory blocks and buffers), on a device with
the feedback loop whose linear image query (`vkGetPhysicalDeviceImageFormatProperties2`: the
texture's format and usage in linear tiling, with the sampled and feedback usages added)
+15 -19
View File
@@ -87,16 +87,18 @@ impl Device {
/// while its texture lives.
///
/// **The image is the texture Direct3D 11 made.** Its usage is what the texture's
/// [`bind_flags`](D3d11Plane::bind_flags) give, and nothing more: copied from and into, as
/// Direct3D 11 copies any texture of default usage; sampled for `D3D11_BIND_SHADER_RESOURCE`,
/// rendered for `D3D11_BIND_RENDER_TARGET` and storage for `D3D11_BIND_UNORDERED_ACCESS`; each
/// where the descriptor's format holds it and the import query
/// (`vkGetPhysicalDeviceImageFormatProperties2`) offers it. The one usage beside them, which
/// the description has no counterpart for, is the attachment feedback loop's, taken where the
/// descriptor's texture is a render target a draw may read in its own pass and the import
/// offers it with the rest. Vulkan's import of memory another API made states no rule for an image of other usage or
/// flags than the texture's; its rules for an import of Vulkan's own export ask the same
/// image (`VUID-VkMemoryDedicatedAllocateInfo-image-01876`).
/// [`bind_flags`](D3d11Plane::bind_flags) give, and nothing more, on every device: copied from
/// and into, as Direct3D 11 copies any texture of default usage; sampled for
/// `D3D11_BIND_SHADER_RESOURCE`, rendered for `D3D11_BIND_RENDER_TARGET` and storage for
/// `D3D11_BIND_UNORDERED_ACCESS`; each where the descriptor's format holds it and the import
/// query (`vkGetPhysicalDeviceImageFormatProperties2`) offers it. Vulkan's import of memory
/// another API made states no rule for an image of other usage or flags than the texture's;
/// its rules for an import of Vulkan's own export ask the same image
/// (`VUID-VkMemoryDedicatedAllocateInfo-image-01876`). So the image never takes the attachment
/// feedback loop's usage, which the description has no counterpart for: a draw that reads a
/// plane as an attachment of its own pass reads it through a copy into the plane's shadow, on
/// a device with the loop as on one without it, a copy Metal does not make
/// ([`Metrics::attachment_read_copies`](crate::Metrics::attachment_read_copies)).
///
/// **Views of another format.** The image is mutable where it lists more than its own
/// format, and lists at most two more, the two places it asks beyond the texture Direct3D 11
@@ -286,15 +288,9 @@ impl Device {
if usage.is_empty() || !imports(usage, &pair) {
return Err(Error::Limit(Limit::NoImport { handle }));
}
// With the feedback usage where the plane asks it and the import offers it with the
// rest, so a draw reads it as an attachment of its own pass through the loop; else
// through its shadow. The one usage Direct3D 11's description has no counterpart for,
// taken only where the plane's descriptor asks it.
let looped = usage | vk::ImageUsageFlags::ATTACHMENT_FEEDBACK_LOOP_EXT;
let usage = match plan.looped && imports(looped, &pair) {
true => looped,
false => usage,
};
// No feedback usage, which Direct3D 11's description has no counterpart for: a draw
// reads the plane as an attachment of its own pass through its shadow
// (`Device::surface_texture`).
let missing = plan.usage & !usage;
if !missing.is_empty() {
return Err(Error::Unsupported(Gap::SurfaceUsage {
+41 -25
View File
@@ -21,7 +21,9 @@
//! of a plane, the first included, names the general layout, with or without the call before it.
//! While the surface lives, the surface imports gauge holds its two planes; it has no buffer and
//! no export handle. Each plane's image takes the usage its texture's bind flags give and no
//! other: made rendered and sampled, no storage; made sampled alone, not rendered; and a texture
//! other, on every device: made rendered and sampled under a render target shaders read, copied,
//! sampled and rendered, with no storage and no attachment feedback loop usage, so a draw reads it
//! through its shadow; made sampled alone, not rendered; and a texture
//! over a plane whose uses ask storage is `Gap::SurfaceUsage`, where the device stores its
//! format. Planes made with `PixelFormatView` usage, an 8-bit luma, a chroma and a 10-bit luma,
//! list no format past their own, their texture's and that one's sRGB sibling (the 10-bit luma's
@@ -1066,14 +1068,17 @@ mod on_device {
});
}
/// Each plane's image takes the usage its texture's bind flags give and no other. Made
/// rendered and sampled (`D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE`, as a
/// video's planes are), it is copied and sampled, and rendered at most beside, with no
/// storage; made sampled alone, it is copied and sampled, and not rendered. A texture over
/// a plane whose uses ask storage (`ShaderWrite`) is `Gap::SurfaceUsage` of storage, where
/// the device stores the texture's format through a storage image without a format, as
/// Direct3D 11 made the texture without `D3D11_BIND_UNORDERED_ACCESS`; where it does not,
/// the uses ask no storage and the import is made.
/// Each plane's image takes the usage its texture's bind flags give and no other, on
/// every device. Made rendered and sampled (`D3D11_BIND_RENDER_TARGET |
/// D3D11_BIND_SHADER_RESOURCE`, as a video's planes are) under a texture of the consumer's
/// planes' uses (`ShaderRead | RenderTarget`), a render target shaders read, which a draw
/// may read in its own pass, it is copied, sampled and rendered (0x17), with no storage and
/// no attachment feedback loop usage, whether or not the device has the loop; made sampled
/// alone under a texture shaders read, it is copied and sampled (0x7), and not rendered. A
/// texture over a plane whose uses ask storage (`ShaderWrite`) is `Gap::SurfaceUsage` of
/// storage, where the device stores the texture's format through a storage image without a
/// format, as Direct3D 11 made the texture without `D3D11_BIND_UNORDERED_ACCESS`; where it
/// does not, the uses ask no storage and the import is made.
#[test]
fn every_device_makes_a_direct3d_11_plane_of_the_usage_its_bind_flags_give() {
each_device("import_d3d11_surface_usage", |name, _, device| {
@@ -1083,22 +1088,34 @@ mod on_device {
let copied = vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::TRANSFER_DST;
let read = copied | vk::ImageUsageFlags::SAMPLED;
let rendered = read | vk::ImageUsageFlags::COLOR_ATTACHMENT;
for (bind, given) in [(BOUND, rendered), (SHADER_RESOURCE, read)] {
let looped = device.core().feedback_loop;
for (bind, given, uses) in [
(
BOUND,
rendered,
TextureUsage::SHADER_READ | TextureUsage::RENDER_TARGET,
),
(SHADER_RESOURCE, read, TextureUsage::SHADER_READ),
] {
let textures = PLANES
.each_ref()
.map(|p| d3d.shared_texture(p.width, p.height, p.dxgi, bind));
let planes: Vec<D3d11Plane<'_>> = (textures.iter().zip(&PLANES))
.map(|(texture, plane)| D3d11Plane {
handle: texture.handle.as_handle(),
image_format: plane.image,
bind_flags: bind,
descriptor: TextureDescriptor::new(
.map(|(texture, plane)| {
let mut descriptor = TextureDescriptor::new(
TextureType::Type2D,
plane.view,
plane.width,
plane.height,
),
index: None,
);
descriptor.usage = uses;
D3d11Plane {
handle: texture.handle.as_handle(),
image_format: plane.image,
bind_flags: bind,
descriptor,
index: None,
}
})
.collect();
let surface = (device.import_d3d11_surface(&planes))
@@ -1110,20 +1127,19 @@ mod on_device {
);
let usage = texture.object().image_usage();
println!(
"d3d11-usage: {label}: the image's usage {:#x}, the flags give {:#x}",
"d3d11-usage: {label}: the image's usage {:#x}, the flags give {:#x}; \
the device has the attachment feedback loop: {looped}",
usage.as_raw(),
given.as_raw()
);
assert_eq!(
(usage & !given).as_raw(),
0,
"{label}: a usage the bind flags do not give, of {:#x}",
usage.as_raw()
usage.as_raw(),
given.as_raw(),
"{label}: the usage the bind flags give, and no other"
);
assert!(
usage.contains(read),
"{label}: copied and sampled: {:#x}",
usage.as_raw()
!texture.looped(),
"{label}: a draw reads the plane through its shadow, not the loop"
);
}
}
@@ -0,0 +1,353 @@
//! A draw that reads, through a texture, a Direct3D 11 plane its own pass renders
//! (`Device::import_d3d11_surface`, on Windows). The plane's image takes the usage its texture's
//! bind flags give and no other, never the attachment feedback loop's, so such a draw reads it
//! through a copy into the plane's shadow on every device, one with the loop included.
//!
//! Under a device cfg, on every device of the cfg's kind: no Direct3D 11 texture is at hand off
//! Windows, so each plane is made as `d3d11_plane_texture` makes one but for the import: an optimal
//! image of the Direct3D 11 texture's format and of the usage `D3D11_BIND_RENDER_TARGET |
//! D3D11_BIND_SHADER_RESOURCE` gives (0x17: copied from and into, sampled and rendered), mutable
//! over its own format and its texture's where they differ, on a dedicated allocation of the
//! device's own, which `Device::surface_texture` takes as a Direct3D 11 plane's (at home in the
//! general layout, acquired from `VK_QUEUE_FAMILY_EXTERNAL` at each submission that uses it),
//! under a texture of the consumer's planes' uses (`ShaderRead | RenderTarget | PixelFormatView`),
//! with no index. A view of it in its texture's format at an index is the guest's texture over the
//! plane, as the consumer makes one. For the luma (`R8Unorm`) and the chroma (an `R16Uint` image
//! under an `RG8Unorm` texture), a pass that clears the view draws, reading it at its own pixel,
//! then a colour over it, then, after a memory barrier, each pixel read plus a second colour. Both
//! reading draws read through the shadow, the first through its clear and the one after the
//! barrier through one copy: `Metrics::attachment_read_copies` grows by 1 and
//! `attachment_loop_reads` by 0, `d3d11_plane_submissions` by 1, and every texel of the plane,
//! blitted out, is the first colour plus the second. Neither texture reads through the loop.
//!
//! The control, on a device with the loop: the luma made with the feedback usage beside (0x80017,
//! the form the import took before), whose draws read it through the loop (2 loop reads, no copy),
//! to the same texels.
//!
//! `examples/runtime_examples`' `own_pixel_fragment` reads the attachment at the fragment's own
//! pixel and `colored_fragment` writes the vertices' colour. `llvm-as` assembles them; without it
//! the test skips visibly.
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod on_device {
use crate::hazard::HeapId;
use crate::memory;
use crate::tests::blit::on_device::settled;
use crate::tests::command::on_device::each_device;
use crate::tests::draw::on_device::{descriptor, examples, floats, run, state, Buffers};
use crate::texture::{Backing, SurfaceImage, TextureObject};
use crate::{
BufferLayout, Device, Error, IndexClass, LoadAction, PixelFormat, PrimitiveType,
RenderPassDescriptor, StorageMode, StoreAction, Texture, TextureDescriptor, TexturePlace,
TextureType, TextureUsage,
};
use ash::vk;
/// The usage `D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE` give a plane's image
/// (`crate::d3d11::bound_usage`, on Windows): copied from and into, sampled and rendered.
const BOUND: vk::ImageUsageFlags = vk::ImageUsageFlags::from_raw(
vk::ImageUsageFlags::TRANSFER_SRC.as_raw()
| vk::ImageUsageFlags::TRANSFER_DST.as_raw()
| vk::ImageUsageFlags::SAMPLED.as_raw()
| vk::ImageUsageFlags::COLOR_ATTACHMENT.as_raw(),
);
/// The colour of the draw over the plane, and the one added to each pixel read after it:
/// each channel a multiple of 1/255 apart from rounding, their sum too.
const FIRST: [f32; 4] = [0.2, 0.6, 0.0, 1.0];
const SECOND: [f32; 4] = [0.4, 0.2, 0.0, 0.0];
/// Each texel at the pass's end, its first two channels: the first colour read plus the
/// second.
const SUM: [u8; 2] = [153, 204];
/// The bytes of the buffer each plane is blitted out into: past every plane's.
const OUT: usize = 4096;
/// A plane: the Direct3D 11 texture's format, its texture's, its extent and its texel's
/// bytes.
struct Plane {
image: PixelFormat,
view: PixelFormat,
width: u32,
height: u32,
texel: u32,
}
const PLANES: [Plane; 2] = [
Plane {
image: PixelFormat::R8Unorm,
view: PixelFormat::R8Unorm,
width: 16,
height: 8,
texel: 1,
},
Plane {
image: PixelFormat::R16Uint,
view: PixelFormat::RG8Unorm,
width: 8,
height: 4,
texel: 2,
},
];
/// The texture over `plane`, of no index, as `d3d11_plane_texture` makes it from an image of
/// `usage` but for the import: its memory a dedicated allocation of the device's own.
fn plane_texture(
name: &str,
device: &Device,
plane: &Plane,
usage: vk::ImageUsageFlags,
) -> Texture {
let core = device.core();
let mut d =
TextureDescriptor::new(TextureType::Type2D, plane.view, plane.width, plane.height);
d.usage = TextureUsage::SHADER_READ
| TextureUsage::RENDER_TARGET
| TextureUsage::PIXEL_FORMAT_VIEW;
d.storage_mode = StorageMode::Private;
let mut own = d;
own.pixel_format = plane.image;
let plan = |d: &TextureDescriptor| {
(device.plane_plan(d)).unwrap_or_else(|error| panic!("{name}: a plan: {error}"))
};
let (format, view) = (plan(&own).format, plan(&d).format);
let list = match format == view {
true => Vec::new(),
false => vec![format, view],
};
let mut listed = vk::ImageFormatListCreateInfo::default().view_formats(&list);
let mut info = vk::ImageCreateInfo::default()
.image_type(vk::ImageType::TYPE_2D)
.format(format)
.extent(vk::Extent3D {
width: plane.width,
height: plane.height,
depth: 1,
})
.mip_levels(1)
.array_layers(1)
.samples(vk::SampleCountFlags::TYPE_1)
.tiling(vk::ImageTiling::OPTIMAL)
.usage(usage)
.sharing_mode(vk::SharingMode::EXCLUSIVE)
.initial_layout(vk::ImageLayout::UNDEFINED);
if !list.is_empty() {
info = info
.flags(vk::ImageCreateFlags::MUTABLE_FORMAT)
.push_next(&mut listed);
}
let device_vk = &core.device;
// SAFETY: a 2D optimal image of a format the plan holds with the plan's usage, and of the
// feedback usage only where the device enables the loop (the caller's).
let image = (unsafe { device_vk.create_image(&info, None) })
.unwrap_or_else(|error| panic!("{name}: the image: {error}"));
// SAFETY: the image is the device's.
let needs = unsafe { device_vk.get_image_memory_requirements(image) };
let index = match needs.memory_type_bits & core.device_local {
0 => needs.memory_type_bits.trailing_zeros(),
local => local.trailing_zeros(),
};
let mut dedicated = vk::MemoryDedicatedAllocateInfo::default().image(image);
let allocate = vk::MemoryAllocateInfo::default()
.allocation_size(needs.size)
.memory_type_index(index)
.push_next(&mut dedicated);
// SAFETY: an allocation dedicated to the image, of a type its requirements list.
let memory = unsafe {
memory::allocate(
device_vk,
&core.counters,
core.max_allocations,
&allocate,
None,
)
}
.unwrap_or_else(|error| panic!("{name}: the memory: {error}"));
core.counters.surface_imported(needs.size);
// SAFETY: the memory is the image's dedicated allocation, of a type its requirements
// list.
unsafe { device_vk.bind_image_memory(image, memory, 0) }
.unwrap_or_else(|error| panic!("{name}: the binding: {error}"));
let made = SurfaceImage {
image,
backing: Backing::Import(memory, needs.size),
bytes: needs.size,
usage,
format,
view_formats: list,
block: None,
d3d11: true,
family: vk::QUEUE_FAMILY_EXTERNAL,
linear_attachment: false,
laid: None,
};
(device.surface_texture(&d, None, made, HeapId::unit(core), None))
.unwrap_or_else(|error| panic!("{name}: the plane's texture: {error}"))
}
/// For each plane, made with the usage its Direct3D 11 texture's bind flags give, on every
/// device, and, the luma on a device with the loop, with the feedback usage beside (the
/// control): a pass that clears a view of it at an index draws, reading the view at its own
/// pixel, then the first colour, then, after a memory barrier, each pixel read plus the
/// second. Made of the bind flags' usage, its draws read it through its shadow, one copy and
/// no loop read; with the feedback usage, through the loop, two loop reads and no copy. Each
/// pass leaves every texel the first colour plus the second, its submission handing the plane
/// over.
#[test]
fn every_device_reads_a_direct3d_11_plane_its_pass_renders_through_its_shadow() {
let Some(library) = examples() else {
return;
};
each_device("d3d11_reads", |name, _, device| {
let looped = device.core().feedback_loop;
// An index for each case's view: a plane in each form.
(device.grant_indices(IndexClass::Texture, 4096, 4))
.unwrap_or_else(|error| panic!("{name}: {error}"));
let mut buffers = Buffers::new(&device);
// Three triangles over the whole plane, their colours none, the first and the second.
let whole = [-1.0, -1.0, 3.0, -1.0, -1.0, 3.0];
let positions = buffers.of(&device, &floats(&[whole; 3].concat()));
let colors: Vec<f32> = [[0.0; 4], FIRST, SECOND]
.iter()
.flat_map(|c| [*c; 3].concat())
.collect();
let colors = buffers.of(&device, &floats(&colors));
let out = buffers.of(&device, &[0; OUT]);
let queue = device.new_command_queue(4).expect("a queue");
let control = vk::ImageUsageFlags::ATTACHMENT_FEEDBACK_LOOP_EXT;
let mut index = 4096;
for plane in &PLANES {
// The control on the luma alone, whose texture is of its image's format.
let forms = match looped && plane.image == plane.view {
true => vec![
("the bind flags' usage", BOUND),
("the control", BOUND | control),
],
false => vec![("the bind flags' usage", BOUND)],
};
let plain = state(
name,
&device,
&descriptor(&library, "colored_fragment", plane.view),
);
let reading = state(
name,
&device,
&descriptor(&library, "own_pixel_fragment", plane.view),
);
for &(form, usage) in &forms {
let case = format!(
"{name}: {:?} as {:?}, {form} {:#x}",
plane.image,
plane.view,
usage.as_raw()
);
let texture = plane_texture(name, &device, plane, usage);
let view = (texture.new_texture_view(
plane.view,
TextureType::Type2D,
0..1,
0..1,
Some(index),
))
.unwrap_or_else(|error| panic!("{case}: the view: {error}"));
index += 1;
assert_eq!(
texture.object().image_usage(),
usage,
"{case}: the image's usage"
);
let counters = device.counters();
settled(&device);
let before = counters.metrics();
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut pass = RenderPassDescriptor::default();
let c = &mut pass.color_attachments[0];
c.texture = Some(view.clone());
c.load_action = LoadAction::Clear;
c.store_action = StoreAction::Store;
let mut encoder = (command_buffer.render_command_encoder(&pass))
.unwrap_or_else(|error| panic!("{case}: {error}"));
let draw = |result: Result<(), Error>| {
result.unwrap_or_else(|e| panic!("{case}: {e}"))
};
draw(encoder.set_vertex_buffer(Some(&positions), 0, 0));
draw(encoder.set_vertex_buffer(Some(&colors), 0, 1));
draw(encoder.set_fragment_texture(Some(&view), 0));
draw(encoder.set_render_pipeline_state(&reading));
// The pass's first read of the plane: the clear's black, and none added.
draw(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0));
// The first colour over every pixel, then the barrier, then each pixel read
// plus the second.
draw(encoder.set_render_pipeline_state(&plain));
draw(encoder.draw_primitives(PrimitiveType::Triangle, 3, 3, 1, 0));
draw(encoder.memory_barrier());
draw(encoder.set_render_pipeline_state(&reading));
draw(encoder.draw_primitives(PrimitiveType::Triangle, 6, 3, 1, 0));
encoder.end_encoding();
run(&case, &command_buffer);
let after = counters.metrics();
let loop_reads = after.attachment_loop_reads - before.attachment_loop_reads;
let copies = after.attachment_read_copies - before.attachment_read_copies;
let handed = after.d3d11_plane_submissions - before.d3d11_plane_submissions;
let shadows = counters.gauges().shadows;
println!(
"d3d11_reads: {case}: the device has the loop: {looped}; loop reads \
{loop_reads}, copies {copies}, plane submissions {handed}, shadows live \
{shadows}"
);
let want = match usage.contains(control) {
true => (2, 0),
false => (0, 1),
};
assert_eq!(
(loop_reads, copies),
want,
"{case}: loop reads and copies into the shadow"
);
assert_eq!(
handed, 1,
"{case}: the pass's submission hands the plane over"
);
assert_eq!(
(texture.looped(), view.looped()),
(want.0 == 2, want.0 == 2),
"{case}: the textures' form, their draws'"
);
// The plane's texels, blitted out.
let row = plane.width * plane.texel;
let read = queue.command_buffer().expect("a command buffer");
let mut blit = read.blit_command_encoder().expect("an encoder");
(blit.copy_from_texture_to_buffer(
&texture,
TexturePlace::default(),
[plane.width, plane.height, 1],
&out,
BufferLayout {
offset: 0,
bytes_per_row: u64::from(row),
bytes_per_image: 0,
},
))
.unwrap_or_else(|error| panic!("{case}: the read: {error}"));
blit.end_encoding();
run(&case, &read);
let bytes = (row * plane.height) as usize;
let contents = out.contents().expect("Shared");
// SAFETY: the buffer holds `OUT` bytes, past `bytes`, and no command writes it.
let texels = unsafe { std::slice::from_raw_parts(contents.as_ptr(), bytes) };
let sum = &SUM[..plane.texel as usize];
let wrong = (texels.chunks(plane.texel as usize))
.filter(|texel| *texel != sum)
.count();
assert!(
wrong == 0,
"{case}: {wrong} texels are not {sum:?}; the first {:?}",
&texels[..plane.texel as usize]
);
drop((view, texture, command_buffer, read));
}
}
drop((out, positions, colors, queue));
});
}
}
@@ -29,6 +29,7 @@ mod copy_over;
mod cube_reads;
mod cube_views;
mod d3d11;
mod d3d11_reads;
mod deep_threadgroups;
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod depth_planes;
+2 -1
View File
@@ -8163,7 +8163,8 @@ impl Device {
let views_usage = (made.format != plan.format).then_some(made.usage & plan.supported);
// A draw may read an attachment of its own pass through it as through a texture of its
// own image: in the feedback layout where the plane's image took the feedback usage
// (`crate::surface`), else through a copy into its shadow.
// (`crate::surface`), else through a copy into its shadow, as it reads a Direct3D 11
// plane, whose image never takes it (`Device::import_d3d11_surface`).
let looped = made
.usage
.contains(vk::ImageUsageFlags::ATTACHMENT_FEEDBACK_LOOP_EXT);