Module: vkd3d Branch: master Commit: ca7fa0c0150fd0defb1459ac74f58e393e341a78 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/ca7fa0c0150fd0defb1459ac74f58e...
Author: Giovanni Mascellani gmascellani@codeweavers.com Date: Mon Oct 23 21:53:51 2023 +0200
tests: Immediately transition resources after readback in the shader runner.
The resource could be destructed before the command list left open is executed; instead, we immediately perform the transition.
---
tests/d3d12_test_utils.h | 21 +++++++++++++++++++-- tests/shader_runner_d3d12.c | 8 ++------ 2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h index 2c7b10f4..f0c4b411 100644 --- a/tests/d3d12_test_utils.h +++ b/tests/d3d12_test_utils.h @@ -415,8 +415,11 @@ struct d3d12_resource_readback ID3D12Resource *resource; };
-static void get_resource_readback_with_command_list(ID3D12Resource *resource, unsigned int sub_resource, - struct d3d12_resource_readback *rb, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list) +#define RESOURCE_STATE_DO_NOT_CHANGE (~0u) + +static void get_resource_readback_with_command_list_and_states(ID3D12Resource *resource, unsigned int sub_resource, + struct d3d12_resource_readback *rb, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list, + D3D12_RESOURCE_STATES initial_state, D3D12_RESOURCE_STATES final_state) { D3D12_HEAP_PROPERTIES heap_properties; D3D12_RESOURCE_DESC resource_desc; @@ -444,6 +447,9 @@ static void get_resource_readback_with_command_list(ID3D12Resource *resource, un rb->rb.row_pitch = align(rb->rb.row_pitch, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); rb->rb.data = NULL;
+ if (initial_state != RESOURCE_STATE_DO_NOT_CHANGE) + transition_sub_resource_state(command_list, resource, sub_resource, initial_state, D3D12_RESOURCE_STATE_COPY_SOURCE); + src_resource = resource; if (resource_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER && resource_desc.SampleDesc.Count > 1) { @@ -493,6 +499,10 @@ static void get_resource_readback_with_command_list(ID3D12Resource *resource, un
ID3D12GraphicsCommandList_CopyTextureRegion(command_list, &dst_location, 0, 0, 0, &src_location, NULL); } + + if (final_state != RESOURCE_STATE_DO_NOT_CHANGE) + transition_sub_resource_state(command_list, resource, sub_resource, D3D12_RESOURCE_STATE_COPY_SOURCE, final_state); + hr = ID3D12GraphicsCommandList_Close(command_list); assert_that(hr == S_OK, "Failed to close command list, hr %#x.\n", hr);
@@ -509,6 +519,13 @@ static void get_resource_readback_with_command_list(ID3D12Resource *resource, un assert_that(hr == S_OK, "Failed to map readback buffer, hr %#x.\n", hr); }
+static void get_resource_readback_with_command_list(ID3D12Resource *resource, unsigned int sub_resource, + struct d3d12_resource_readback *rb, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list) +{ + return get_resource_readback_with_command_list_and_states(resource, sub_resource, rb, queue, command_list, + RESOURCE_STATE_DO_NOT_CHANGE, RESOURCE_STATE_DO_NOT_CHANGE); +} + static unsigned int get_readback_uint(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z) { diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 8453617e..79d637e6 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -546,13 +546,9 @@ static struct resource_readback *d3d12_runner_get_resource_readback(struct shade else state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
- transition_resource_state(test_context->list, resource->resource, - state, D3D12_RESOURCE_STATE_COPY_SOURCE); - get_resource_readback_with_command_list(resource->resource, 0, rb, - test_context->queue, test_context->list); + get_resource_readback_with_command_list_and_states(resource->resource, 0, rb, + test_context->queue, test_context->list, state, state); reset_command_list(test_context->list, test_context->allocator); - transition_resource_state(test_context->list, resource->resource, - D3D12_RESOURCE_STATE_COPY_SOURCE, state);
return &rb->rb; }