From 5e488d4fea71e701233ad59a40f3904f97ef400a Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 3 Feb 2021 23:00:51 +0100 Subject: [PATCH 1/3] Added player test with compute shader reading & writing an uninitialized buffer --- player/tests/data/all.ron | 3 +- .../data/buffer-zero-init-for-binding.ron | 99 +++++++++++++++++++ .../data/buffer-zero-init-for-binding.wgsl | 15 +++ ...fer-zero-init-for-mapping-and-writing.ron} | 0 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 player/tests/data/buffer-zero-init-for-binding.ron create mode 100644 player/tests/data/buffer-zero-init-for-binding.wgsl rename player/tests/data/{buffer-zero-init.ron => buffer-zero-init-for-mapping-and-writing.ron} (100%) diff --git a/player/tests/data/all.ron b/player/tests/data/all.ron index 0b493a9b8..d75a105ba 100644 --- a/player/tests/data/all.ron +++ b/player/tests/data/all.ron @@ -2,7 +2,8 @@ backends: (bits: 0xF), tests: [ "buffer-copy.ron", - "buffer-zero-init.ron", + "buffer-zero-init-for-mapping-and-writing.ron", + "buffer-zero-init-for-binding.ron", "bind-group.ron", "quad.ron", ], diff --git a/player/tests/data/buffer-zero-init-for-binding.ron b/player/tests/data/buffer-zero-init-for-binding.ron new file mode 100644 index 000000000..5ceb42484 --- /dev/null +++ b/player/tests/data/buffer-zero-init-for-binding.ron @@ -0,0 +1,99 @@ +( + features: (bits: 0x0), + expectations: [ + ( + name: "buffer has correct values", + buffer: (index: 0, epoch: 1), + offset: 0, + data: Raw([0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00]), + ) + ], + actions: [ + CreateShaderModule( + id: Id(0, 1, Empty), + desc: ( + label: None, + experimental_translation: true, + ), + data: "buffer-zero-init-for-binding.wgsl", + ), + CreateBuffer(Id(0, 1, Empty), ( + label: None, + size: 16, + usage: ( + bits: 129, // STORAGE + MAP_READ + ), + mapped_at_creation: false, + )), + CreateBindGroupLayout(Id(0, 1, Empty), ( + label: None, + entries: [ + ( + binding: 0, + visibility: ( + bits: 4, + ), + ty: Buffer( + ty: Storage( + read_only: false, + ), + has_dynamic_offset: false, + min_binding_size: Some(16), + ), + count: None, + ), + ], + )), + CreateBindGroup(Id(0, 1, Empty), ( + label: None, + layout: Id(0, 1, Empty), + entries: [ + ( + binding: 0, + resource: Buffer(( + buffer_id: Id(0, 1, Empty), + offset: 0, + size: Some(16), + )), + ), + ], + )), + CreatePipelineLayout(Id(0, 1, Empty), ( + label: None, + bind_group_layouts: [ + Id(0, 1, Empty), + ], + push_constant_ranges: [], + )), + CreateComputePipeline(Id(0, 1, Empty), ( + label: None, + layout: Some(Id(0, 1, Empty)), + stage: ( + module: Id(0, 1, Empty), + entry_point: "main", + ), + )), + Submit(1, [ + RunComputePass( + base: ( + label: None, + 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: [], + ), + ) + ]), + ] +) \ No newline at end of file diff --git a/player/tests/data/buffer-zero-init-for-binding.wgsl b/player/tests/data/buffer-zero-init-for-binding.wgsl new file mode 100644 index 000000000..291485a53 --- /dev/null +++ b/player/tests/data/buffer-zero-init-for-binding.wgsl @@ -0,0 +1,15 @@ +[[builtin(global_invocation_id)]] +var global_id: vec3; + +[[block]] +struct InOutBuffer { + data: [[stride(4)]] array; +}; + +[[group(0), binding(0)]] +var buffer: [[access(read_write)]] InOutBuffer; + +[[stage(compute), workgroup_size(1)]] +fn main() { + buffer.data[global_id.x] = buffer.data[global_id.x] + global_id.x; +} diff --git a/player/tests/data/buffer-zero-init.ron b/player/tests/data/buffer-zero-init-for-mapping-and-writing.ron similarity index 100% rename from player/tests/data/buffer-zero-init.ron rename to player/tests/data/buffer-zero-init-for-mapping-and-writing.ron From 52aee1a0379c5d7201f432e26dfcb0f7f8374009 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 3 Feb 2021 23:07:54 +0100 Subject: [PATCH 2/3] Better error output for player test --- player/tests/test.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/player/tests/test.rs b/player/tests/test.rs index 6789259dc..6ca36750e 100644 --- a/player/tests/test.rs +++ b/player/tests/test.rs @@ -144,7 +144,10 @@ impl Test<'_> { }; if &expected_data[..] != contents { - panic!("Test expectation is not met!"); + panic!( + "Test expectation is not met!\nBuffer content was:\n{:?}\nbut expected:\n{:?}", + contents, expected_data + ); } } From fd810f839ecce653b27cd04481c0d617a4a6706c Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sat, 6 Feb 2021 12:09:38 +0100 Subject: [PATCH 3/3] merged buffer-zero-init-for-binding and buffer-zero-init-for-mapping-and-writing tests --- player/tests/data/all.ron | 3 +- ...ffer-zero-init-for-mapping-and-writing.ron | 70 ----------------- ...t-for-binding.ron => buffer-zero-init.ron} | 78 +++++++++++++++++-- 3 files changed, 74 insertions(+), 77 deletions(-) delete mode 100644 player/tests/data/buffer-zero-init-for-mapping-and-writing.ron rename player/tests/data/{buffer-zero-init-for-binding.ron => buffer-zero-init.ron} (53%) diff --git a/player/tests/data/all.ron b/player/tests/data/all.ron index d75a105ba..0b493a9b8 100644 --- a/player/tests/data/all.ron +++ b/player/tests/data/all.ron @@ -2,8 +2,7 @@ backends: (bits: 0xF), tests: [ "buffer-copy.ron", - "buffer-zero-init-for-mapping-and-writing.ron", - "buffer-zero-init-for-binding.ron", + "buffer-zero-init.ron", "bind-group.ron", "quad.ron", ], diff --git a/player/tests/data/buffer-zero-init-for-mapping-and-writing.ron b/player/tests/data/buffer-zero-init-for-mapping-and-writing.ron deleted file mode 100644 index 90a9f0c7b..000000000 --- a/player/tests/data/buffer-zero-init-for-mapping-and-writing.ron +++ /dev/null @@ -1,70 +0,0 @@ -( - features: (bits: 0x0), - expectations: [ - ( - name: "mapped_at_creation: false, with MAP_WRITE", - buffer: (index: 0, epoch: 1), - offset: 0, - data: Raw([0x00, 0x00, 0x00, 0x00]), - ), - ( - name: "mapped_at_creation: false, without MAP_WRITE", - buffer: (index: 1, epoch: 1), - offset: 0, - data: Raw([0x00, 0x00, 0x00, 0x00]), - ), - ( - name: "partially written buffer", - buffer: (index: 2, epoch: 1), - offset: 0, - data: Raw([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xBF, 0x00, 0x00, 0x80, 0xBF, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00]), - ), - ], - actions: [ - CreateBuffer( - Id(0, 1, Empty), - ( - label: Some("mapped_at_creation: false, with MAP_WRITE"), - size: 16, - usage: ( - bits: 131, // STORAGE + MAP_READ + MAP_WRITE - ), - mapped_at_creation: false, - ), - ), - CreateBuffer( - Id(1, 1, Empty), - ( - label: Some("mapped_at_creation: false, without MAP_WRITE"), - size: 16, - usage: ( - bits: 129, // STORAGE + MAP_READ - ), - mapped_at_creation: false, - ), - ), - CreateBuffer( - Id(2, 1, Empty), - ( - label: Some("partially written"), - size: 24, - usage: ( - bits: 9, // MAP_READ + COPY_DST - ), - mapped_at_creation: false, - ), - ), - WriteBuffer( - id: Id(2, 1, Empty), - data: "data1.bin", - range: ( - start: 4, - end: 20, - ), - queued: true, - ), - - // TODO: Add a buffer with `mapped_at_creation: true`. As of writing there's no unmap action we could insert here. - Submit(1, []), - ], -) \ No newline at end of file diff --git a/player/tests/data/buffer-zero-init-for-binding.ron b/player/tests/data/buffer-zero-init.ron similarity index 53% rename from player/tests/data/buffer-zero-init-for-binding.ron rename to player/tests/data/buffer-zero-init.ron index 5ceb42484..dc4d91f74 100644 --- a/player/tests/data/buffer-zero-init-for-binding.ron +++ b/player/tests/data/buffer-zero-init.ron @@ -1,9 +1,35 @@ ( features: (bits: 0x0), expectations: [ + // Ensuring that mapping zero-inits buffers. + ( + name: "mapped_at_creation: false, with MAP_WRITE", + buffer: (index: 0, epoch: 1), + offset: 0, + data: Raw([0x00, 0x00, 0x00, 0x00]), + ), + ( + name: "mapped_at_creation: false, without MAP_WRITE", + buffer: (index: 1, epoch: 1), + offset: 0, + data: Raw([0x00, 0x00, 0x00, 0x00]), + ), + ( + name: "partially written buffer", + buffer: (index: 2, epoch: 1), + offset: 0, + data: Raw([0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0xBF, + 0x00, 0x00, 0x80, 0xBF, + 0x00, 0x00, 0x80, 0x3F, + 0x00, 0x00, 0x80, 0x3F, + 0x00, 0x00, 0x00, 0x00]), + ), + // Ensuring that binding zero-inits buffers + // (by observing correct side effects of compute shader reading & writing values) ( name: "buffer has correct values", - buffer: (index: 0, epoch: 1), + buffer: (index: 3, epoch: 1), offset: 0, data: Raw([0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, @@ -12,6 +38,48 @@ ) ], actions: [ + CreateBuffer( + Id(0, 1, Empty), + ( + label: Some("mapped_at_creation: false, with MAP_WRITE"), + size: 16, + usage: ( + bits: 131, // STORAGE + MAP_READ + MAP_WRITE + ), + mapped_at_creation: false, + ), + ), + CreateBuffer( + Id(1, 1, Empty), + ( + label: Some("mapped_at_creation: false, without MAP_WRITE"), + size: 16, + usage: ( + bits: 129, // STORAGE + MAP_READ + ), + mapped_at_creation: false, + ), + ), + CreateBuffer( + Id(2, 1, Empty), + ( + label: Some("partially written"), + size: 24, + usage: ( + bits: 9, // MAP_READ + COPY_DST + ), + mapped_at_creation: false, + ), + ), + WriteBuffer( + id: Id(2, 1, Empty), + data: "data1.bin", + range: ( + start: 4, + end: 20, + ), + queued: true, + ), CreateShaderModule( id: Id(0, 1, Empty), desc: ( @@ -20,8 +88,8 @@ ), data: "buffer-zero-init-for-binding.wgsl", ), - CreateBuffer(Id(0, 1, Empty), ( - label: None, + CreateBuffer(Id(3, 1, Empty), ( + label: Some("used in binding"), size: 16, usage: ( bits: 129, // STORAGE + MAP_READ @@ -54,7 +122,7 @@ ( binding: 0, resource: Buffer(( - buffer_id: Id(0, 1, Empty), + buffer_id: Id(3, 1, Empty), offset: 0, size: Some(16), )), @@ -96,4 +164,4 @@ ) ]), ] -) \ No newline at end of file +)