Module: vkd3d Branch: master Commit: 46b7fccfd7e6a08e037d5335225df7f81d170610 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/46b7fccfd7e6a08e037d5335225df7...
Author: Giovanni Mascellani gmascellani@codeweavers.com Date: Tue Oct 31 13:53:00 2023 +0100
tests: Immediately transition textures after creation 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 | 28 +++++++++++++++++++++++++--- tests/shader_runner_d3d12.c | 15 +++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h index f0c4b411..3c3e50ca 100644 --- a/tests/d3d12_test_utils.h +++ b/tests/d3d12_test_utils.h @@ -671,10 +671,11 @@ static void copy_sub_resource_data(const D3D12_MEMCPY_DEST *dst, const D3D12_SUB } }
-#define upload_texture_data(a, b, c, d, e) upload_texture_data_(__LINE__, a, b, c, d, e) -static inline void upload_texture_data_(unsigned int line, ID3D12Resource *texture, +#define upload_texture_data_with_states(a, b, c, d, e, f, g) upload_texture_data_with_states_(__LINE__, a, b, c, d, e, f, g) +static inline void upload_texture_data_with_states_(unsigned int line, ID3D12Resource *texture, const D3D12_SUBRESOURCE_DATA *data, unsigned int sub_resource_count, - ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list) + ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list, + D3D12_RESOURCE_STATES initial_state, D3D12_RESOURCE_STATES final_state) { D3D12_TEXTURE_COPY_LOCATION dst_location, src_location; D3D12_PLACED_SUBRESOURCE_FOOTPRINT *layouts; @@ -718,7 +719,13 @@ static inline void upload_texture_data_(unsigned int line, ID3D12Resource *textu
if (resource_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) { + if (initial_state != RESOURCE_STATE_DO_NOT_CHANGE) + transition_resource_state(command_list, texture, initial_state, D3D12_RESOURCE_STATE_COPY_DEST); + ID3D12GraphicsCommandList_CopyResource(command_list, texture, upload_buffer); + + if (final_state != RESOURCE_STATE_DO_NOT_CHANGE) + transition_resource_state(command_list, texture, D3D12_RESOURCE_STATE_COPY_DEST, final_state); } else { @@ -732,8 +739,14 @@ static inline void upload_texture_data_(unsigned int line, ID3D12Resource *textu src_location.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; src_location.PlacedFootprint = layouts[i];
+ if (initial_state != RESOURCE_STATE_DO_NOT_CHANGE) + transition_sub_resource_state(command_list, texture, i, initial_state, D3D12_RESOURCE_STATE_COPY_DEST); + 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, texture, i, D3D12_RESOURCE_STATE_COPY_DEST, final_state); } }
@@ -751,6 +764,15 @@ static inline void upload_texture_data_(unsigned int line, ID3D12Resource *textu free(row_sizes); }
+#define upload_texture_data(a, b, c, d, e) upload_texture_data_(__LINE__, a, b, c, d, e) +static inline void upload_texture_data_(unsigned int line, ID3D12Resource *texture, + const D3D12_SUBRESOURCE_DATA *data, unsigned int sub_resource_count, + ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list) +{ + return upload_texture_data_with_states_(line, texture, data, sub_resource_count, queue, command_list, + RESOURCE_STATE_DO_NOT_CHANGE, RESOURCE_STATE_DO_NOT_CHANGE); +} + #define upload_buffer_data(a, b, c, d, e, f) upload_buffer_data_(__LINE__, a, b, c, d, e, f) static inline void upload_buffer_data_(unsigned int line, ID3D12Resource *buffer, size_t offset, size_t size, const void *data, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list) diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 79d637e6..6c71b90f 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -147,11 +147,11 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co
resource->resource = create_default_texture2d(device, params->width, params->height, 1, params->level_count, params->format, 0, D3D12_RESOURCE_STATE_COPY_DEST); - upload_texture_data(resource->resource, resource_data, - params->level_count, test_context->queue, test_context->list); - reset_command_list(test_context->list, test_context->allocator); - transition_resource_state(test_context->list, resource->resource, D3D12_RESOURCE_STATE_COPY_DEST, + upload_texture_data_with_states(resource->resource, resource_data, + params->level_count, test_context->queue, test_context->list, + RESOURCE_STATE_DO_NOT_CHANGE, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); + reset_command_list(test_context->list, test_context->allocator); ID3D12Device_CreateShaderResourceView(device, resource->resource, NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot)); break; @@ -163,11 +163,10 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co
resource->resource = create_default_texture2d(device, params->width, params->height, 1, params->level_count, params->format, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST); - upload_texture_data(resource->resource, resource_data, - params->level_count, test_context->queue, test_context->list); + upload_texture_data_with_states(resource->resource, resource_data, + params->level_count, test_context->queue, test_context->list, + RESOURCE_STATE_DO_NOT_CHANGE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); reset_command_list(test_context->list, test_context->allocator); - transition_resource_state(test_context->list, resource->resource, - D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); ID3D12Device_CreateUnorderedAccessView(device, resource->resource, NULL, NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot + MAX_RESOURCES)); break;