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.
This commit is contained in:
Giovanni Mascellani
2023-10-31 13:53:00 +01:00
committed by Alexandre Julliard
parent ca7fa0c015
commit 46b7fccfd7
Notes: Alexandre Julliard 2023-11-01 22:40:06 +01:00
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/425
2 changed files with 32 additions and 11 deletions

View File

@ -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) #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_(unsigned int line, ID3D12Resource *texture, static inline void upload_texture_data_with_states_(unsigned int line, ID3D12Resource *texture,
const D3D12_SUBRESOURCE_DATA *data, unsigned int sub_resource_count, 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_TEXTURE_COPY_LOCATION dst_location, src_location;
D3D12_PLACED_SUBRESOURCE_FOOTPRINT *layouts; 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 (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); 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 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.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
src_location.PlacedFootprint = layouts[i]; 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, ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
&dst_location, 0, 0, 0, &src_location, NULL); &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); 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) #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, 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) size_t size, const void *data, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list)

View File

@ -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, resource->resource = create_default_texture2d(device, params->width, params->height, 1, params->level_count,
params->format, 0, D3D12_RESOURCE_STATE_COPY_DEST); params->format, 0, D3D12_RESOURCE_STATE_COPY_DEST);
upload_texture_data(resource->resource, resource_data, upload_texture_data_with_states(resource->resource, resource_data,
params->level_count, test_context->queue, test_context->list); params->level_count, test_context->queue, test_context->list,
reset_command_list(test_context->list, test_context->allocator); RESOURCE_STATE_DO_NOT_CHANGE,
transition_resource_state(test_context->list, resource->resource, D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); 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, ID3D12Device_CreateShaderResourceView(device, resource->resource,
NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot)); NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot));
break; 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, 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); params->format, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST);
upload_texture_data(resource->resource, resource_data, upload_texture_data_with_states(resource->resource, resource_data,
params->level_count, test_context->queue, test_context->list); 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); 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, ID3D12Device_CreateUnorderedAccessView(device, resource->resource,
NULL, NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot + MAX_RESOURCES)); NULL, NULL, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot + MAX_RESOURCES));
break; break;