From 52a831ba0d0f67fe1f7fe07c5efa57fc5732d66e Mon Sep 17 00:00:00 2001 From: Conor McCarthy Date: Wed, 13 Mar 2024 16:36:59 +1000 Subject: [PATCH] tests/hlsl: Add UAV counter tests. --- Makefile.am | 1 + tests/hlsl/uav-counter.shader_test | 39 ++++++++++++++++++++++++++++++ tests/shader_runner.c | 9 +++++++ tests/shader_runner.h | 1 + tests/shader_runner_d3d11.c | 9 +++++-- tests/shader_runner_d3d12.c | 3 ++- 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 tests/hlsl/uav-counter.shader_test diff --git a/Makefile.am b/Makefile.am index 52e154fe..8abe0863 100644 --- a/Makefile.am +++ b/Makefile.am @@ -205,6 +205,7 @@ vkd3d_shader_tests = \ tests/hlsl/trunc.shader_test \ tests/hlsl/type-names.shader_test \ tests/hlsl/uav-atomics.shader_test \ + tests/hlsl/uav-counter.shader_test \ tests/hlsl/uav-load.shader_test \ tests/hlsl/uav-out-param.shader_test \ tests/hlsl/uav-rwbuffer.shader_test \ diff --git a/tests/hlsl/uav-counter.shader_test b/tests/hlsl/uav-counter.shader_test new file mode 100644 index 00000000..b008d52f --- /dev/null +++ b/tests/hlsl/uav-counter.shader_test @@ -0,0 +1,39 @@ +[require] +shader model >= 5.0 + +[uav 1] +format r32 uint +size (counter_buffer, 1) +0 + +[compute shader todo] +RWStructuredBuffer u : register(u1); + + [numthreads(4, 1, 1)] +void main() +{ + u.IncrementCounter(); +} + +[test] +todo dispatch 3 1 1 +probe uav 1 (0) rui (12) + + +[uav 1] +format r32 sint +size (counter_buffer, 1) +0 + +[compute shader todo] +RWStructuredBuffer u : register(u1); + + [numthreads(4, 1, 1)] +void main() +{ + u.DecrementCounter(); +} + +[test] +todo dispatch 3 1 1 +probe uav 1 (0) ri (-12) diff --git a/tests/shader_runner.c b/tests/shader_runner.c index ccdda5b7..2f99eed9 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -481,6 +481,15 @@ static void parse_resource_directive(struct resource_params *resource, const cha resource->dimension = RESOURCE_DIMENSION_BUFFER; resource->height = 1; } + else if (sscanf(line, "( counter_buffer , %u ) ", &resource->width) == 1) + { + resource->dimension = RESOURCE_DIMENSION_BUFFER; + resource->height = 1; + resource->is_uav_counter = true; + resource->stride = sizeof(uint32_t); + resource->texel_size = resource->stride; + resource->format = DXGI_FORMAT_UNKNOWN; + } else if (sscanf(line, "( 2d , %u , %u ) ", &resource->width, &resource->height) == 2) { resource->dimension = RESOURCE_DIMENSION_2D; diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 5666b2d5..7cba0a52 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -88,6 +88,7 @@ struct resource_params DXGI_FORMAT format; bool is_shadow; + bool is_uav_counter; enum texture_data_type data_type; unsigned int texel_size; unsigned int stride; diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index ffc89085..1285ca41 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -49,6 +49,7 @@ struct d3d11_resource ID3D11RenderTargetView *rtv; ID3D11ShaderResourceView *srv; ID3D11UnorderedAccessView *uav; + bool is_uav_counter; }; static struct d3d11_resource *d3d11_resource(struct resource *r) @@ -438,12 +439,13 @@ static void init_resource_uav_buffer(struct d3d11_shader_runner *runner, struct resource->buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, params->data_size, params->stride, params->data); resource->resource = (ID3D11Resource *)resource->buffer; + resource->is_uav_counter = params->is_uav_counter; uav_desc.Format = params->format; uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; uav_desc.Buffer.FirstElement = 0; uav_desc.Buffer.NumElements = params->data_size / params->texel_size; - uav_desc.Buffer.Flags = 0; + uav_desc.Buffer.Flags = params->is_uav_counter ? D3D11_BUFFER_UAV_FLAG_COUNTER : 0; hr = ID3D11Device_CreateUnorderedAccessView(device, resource->resource, &uav_desc, &resource->uav); ok(hr == S_OK, "Failed to create view, hr %#lx.\n", hr); } @@ -754,7 +756,10 @@ static struct resource_readback *d3d11_runner_get_resource_readback(struct shade assert(0); } - ID3D11DeviceContext_CopyResource(runner->immediate_context, rb->resource, resource->resource); + if (resource->is_uav_counter) + ID3D11DeviceContext_CopyStructureCount(runner->immediate_context, (ID3D11Buffer *)rb->resource, 0, resource->uav); + else + ID3D11DeviceContext_CopyResource(runner->immediate_context, rb->resource, resource->resource); hr = ID3D11DeviceContext_Map(runner->immediate_context, rb->resource, 0, D3D11_MAP_READ, 0, &map_desc); ok(hr == S_OK, "Failed to map texture, hr %#lx.\n", hr); diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index ce27ad22..9bf7bb24 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -203,7 +203,8 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co uav_desc.Buffer.StructureByteStride = params->stride; ID3D12Device_CreateUnorderedAccessView(device, resource->resource, - NULL, &uav_desc, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot + MAX_RESOURCES)); + params->is_uav_counter ? resource->resource : NULL, &uav_desc, + get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot + MAX_RESOURCES)); } else {