Skip to content

Commit

Permalink
Zero init textures (#1688)
Browse files Browse the repository at this point in the history
* Added tests for texture zero init
sadly, they are typically passing even if texture zero init isn't doing its job
However, they form nice isolated examples for testing out texture initialization
It could be possible to dirty texture memory prior to ensure zero init did the job

* texture init tracker

* tracking texture init requirements for bind group, transfer and rendertarget

* texture clears for texture init
* queue submit
* write_texture

* Enforce presence of either render target or copy_dst flag

* clear render targets also with using buffer copies
enforce COPY_DST usage now on all textures

* adjust ImageSubresourceRange.layer_range calculation for 3D textures

init_tracker has now a `discard` function to get single data points back to uninitialized

use new standardized partition_point function

* track init state for discarded textures from renderpasses

missing:
* init on the fly if discarded is found within command buffer
* handle discarding only stencil or only depth

* added tests for zero init after discard

* tracking discarded surfaces now in separate struct, piping all inits through utility function
allows to resolve discard/init_action interactions

* Move various memory init code to separate mod
CommandBufferTextureMemoryActions is now fully encapsulated

* implemented discard init fixups for everything but renderpass

* render passes also cause now discard fixups

* fixup_discarded_surfaces takes now an iterator instead of Drain

* Add memory init test for discarding depth targets

* handle divergently discarded depth/stencil target

* comment & clippy fixes

* fix collect_zero_buffer_copies_for_clear_texture yielding block breaking copies

* [pr feedback] minor cleanup in zero_init_texture_after_discard, `use` hygenie

* [pr feedback] fix bug in ImageSubresourceRange range utils

* [pr feedback] fix texture tracker check, bundle transition_texture on init, cleanups

* Implemented drop for InitTrackerDrain

* remove incorrect comment about extents in add_pass_texture_init_actions

* Fix unit test & clippy issues in init_tracker
  • Loading branch information
Wumpf authored Oct 28, 2021
1 parent cd9498d commit 9887169
Show file tree
Hide file tree
Showing 26 changed files with 1,716 additions and 192 deletions.
5 changes: 4 additions & 1 deletion player/tests/data/all.ron
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"bind-group.ron",
"buffer-copy.ron",
"clear-buffer-texture.ron",
"buffer-zero-init.ron",
"pipeline-statistics-query.ron",
"quad.ron",
"zero-init-buffer.ron",
"zero-init-texture-binding.ron",
"zero-init-texture-copytobuffer.ron",
"zero-init-texture-rendertarget.ron",
],
)
Binary file added player/tests/data/zero-16k.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
label: None,
flags: (bits: 3),
),
data: "buffer-zero-init-for-binding.wgsl",
data: "zero-init-buffer-for-binding.wgsl",
),
CreateBuffer(Id(3, 1, Empty), (
label: Some("used in binding"),
Expand Down
213 changes: 213 additions & 0 deletions player/tests/data/zero-init-texture-binding.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
(
features: (bits: 0x0),
expectations: [
(
name: "Sampled Texture",
buffer: (index: 0, epoch: 1),
offset: 0,
data: File("zero-16k.bin", 16384),
),
(
name: "Storage Texture",
buffer: (index: 1, epoch: 1),
offset: 0,
data: File("zero-16k.bin", 16384),
),
// MISSING: Texture binding arrays
// MISSING: Partial views
],
actions: [
CreateTexture(Id(0, 1, Empty), (
label: Some("Sampled Texture"),
size: (
width: 64,
height: 64,
depth_or_array_layers: 1,
),
mip_level_count: 1,
sample_count: 1,
dimension: D2,
format: Rgba8Unorm,
usage: (
bits: 5, // SAMPLED + COPY_SRC
),
)),
CreateTextureView(
id: Id(0, 1, Empty),
parent_id: Id(0, 1, Empty),
desc: (),
),
CreateBuffer(
Id(0, 1, Empty),
(
label: Some("Sampled Texture Buffer"),
size: 16384,
usage: (
bits: 9,
),
mapped_at_creation: false,
),
),
CreateTexture(Id(1, 1, Empty), (
label: Some("Storage Texture"),
size: (
width: 64,
height: 64,
depth_or_array_layers: 1,
),
mip_level_count: 1,
sample_count: 1,
dimension: D2,
format: Rgba8Unorm,
usage: (
bits: 9, // STORAGE + COPY_SRC
),
)),
CreateTextureView(
id: Id(1, 1, Empty),
parent_id: Id(1, 1, Empty),
desc: (),
),
CreateBuffer(
Id(1, 1, Empty),
(
label: Some("Storage Texture Buffer"),
size: 16384,
usage: (
bits: 9,
),
mapped_at_creation: false,
),
),


CreateBindGroupLayout(Id(0, 1, Empty), (
label: None,
entries: [
(
binding: 0,
visibility: (
bits: 4, // COMPUTE
),
ty: Texture (
sample_type: Float(filterable: true),
view_dimension: D2,
multisampled: false,
),
count: None,
),
(
binding: 1,
visibility: (
bits: 4, // COMPUTE
),
ty: StorageTexture (
access: WriteOnly,
format: Rgba8Unorm,
view_dimension: D2,
),
count: None,
),
],
)),
CreateBindGroup(Id(0, 1, Empty), (
label: None,
layout: Id(0, 1, Empty),
entries: [
(
binding: 0,
resource: TextureView(Id(0, 1, Empty)),
),
(
binding: 1,
resource: TextureView(Id(1, 1, Empty)),
),
],
)),
CreatePipelineLayout(Id(0, 1, Empty), (
label: None,
bind_group_layouts: [
Id(0, 1, Empty),
],
push_constant_ranges: [],
)),
CreateShaderModule(
id: Id(0, 1, Empty),
desc: (
label: None,
flags: (bits: 3),
),
data: "zero-init-texture-binding.wgsl",
),
CreateComputePipeline(
id: Id(0, 1, Empty),
desc: (
label: None,
layout: Some(Id(0, 1, Empty)),
stage: (
module: Id(0, 1, Empty),
entry_point: "main",
),
),
),

Submit(1, [
RunComputePass(
base: (
commands: [
SetPipeline(Id(0, 1, Empty)),
SetBindGroup(
index: 0,
num_dynamic_offsets: 0,
bind_group_id: Id(0, 1, Empty),
),
Dispatch((4, 1, 1)),
],
dynamic_offsets: [],
string_data: [],
push_constant_data: [],
),
),
CopyTextureToBuffer(
src: (
texture: Id(0, 1, Empty),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(0, 1, Empty),
layout: (
offset: 0,
bytes_per_row: Some(256),
rows_per_image: Some(64),
),
),
size: (
width: 64,
height: 64,
depth_or_array_layers: 1,
),
),
CopyTextureToBuffer(
src: (
texture: Id(1, 1, Empty),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(1, 1, Empty),
layout: (
offset: 0,
bytes_per_row: Some(256),
rows_per_image: Some(64),
),
),
size: (
width: 64,
height: 64,
depth_or_array_layers: 1,
),
),
]),
],
)
6 changes: 6 additions & 0 deletions player/tests/data/zero-init-texture-binding.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[[group(0), binding(0)]] var tex: texture_2d<f32>;
[[group(0), binding(1)]] var tex_storage: texture_storage_2d<rgba8uint>;

[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
}
62 changes: 62 additions & 0 deletions player/tests/data/zero-init-texture-copytobuffer.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(
features: (bits: 0x0),
expectations: [
(
name: "Copy to Buffer",
buffer: (index: 0, epoch: 1),
offset: 0,
data: File("zero-16k.bin", 16384),
),
// MISSING: Partial copies
],
actions: [
CreateTexture(Id(0, 1, Empty), (
label: Some("Copy To Buffer Texture"),
size: (
width: 64,
height: 64,
depth_or_array_layers: 1,
),
mip_level_count: 1,
sample_count: 1,
dimension: D2,
format: Rgba8Unorm,
usage: (
bits: 1, // COPY_SRC
),
)),
CreateBuffer(
Id(0, 1, Empty),
(
label: Some("Copy to Buffer Buffer"),
size: 16384,
usage: (
bits: 9,
),
mapped_at_creation: false,
),
),
Submit(1, [
CopyTextureToBuffer(
src: (
texture: Id(0, 1, Empty),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(0, 1, Empty),
layout: (
offset: 0,
bytes_per_row: Some(256),
rows_per_image: Some(64),
),
),
size: (
width: 64,
height: 64,
depth_or_array_layers: 1,
),
),
]),
],
)
Loading

0 comments on commit 9887169

Please sign in to comment.