tests: Add support for UAV buffers to d3d12 runner.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov
2023-05-18 12:46:33 +02:00
committed by Alexandre Julliard
parent 74c0ad0a7a
commit f470c00453
Notes: Alexandre Julliard 2023-05-22 23:19:48 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/193
3 changed files with 94 additions and 57 deletions

View File

@@ -137,31 +137,6 @@ static void uav_barrier(ID3D12GraphicsCommandList *list, ID3D12Resource *resourc
ID3D12GraphicsCommandList_ResourceBarrier(list, 1, &barrier); ID3D12GraphicsCommandList_ResourceBarrier(list, 1, &barrier);
} }
#define upload_buffer_data(a, b, c, d, e, f) upload_buffer_data_(__LINE__, a, b, c, d, e, f)
static void upload_buffer_data_(unsigned int line, ID3D12Resource *buffer, size_t offset,
size_t size, const void *data, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list)
{
ID3D12Resource *upload_buffer;
ID3D12Device *device;
HRESULT hr;
hr = ID3D12Resource_GetDevice(buffer, &IID_ID3D12Device, (void **)&device);
ok_(line)(SUCCEEDED(hr), "Failed to get device, hr %#x.\n", hr);
upload_buffer = create_upload_buffer_(line, device, size, data);
ID3D12GraphicsCommandList_CopyBufferRegion(command_list, buffer, offset,
upload_buffer, 0, size);
hr = ID3D12GraphicsCommandList_Close(command_list);
ok_(line)(SUCCEEDED(hr), "Failed to close command list, hr %#x.\n", hr);
exec_command_list(queue, command_list);
wait_queue_idle(device, queue);
ID3D12Resource_Release(upload_buffer);
ID3D12Device_Release(device);
}
static const DXGI_FORMAT depth_stencil_formats[] = static const DXGI_FORMAT depth_stencil_formats[] =
{ {
DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_R32G8X24_TYPELESS,

View File

@@ -420,7 +420,6 @@ struct d3d12_resource_readback
static void get_resource_readback_with_command_list(ID3D12Resource *resource, unsigned int sub_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) struct d3d12_resource_readback *rb, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list)
{ {
D3D12_TEXTURE_COPY_LOCATION dst_location, src_location;
D3D12_HEAP_PROPERTIES heap_properties; D3D12_HEAP_PROPERTIES heap_properties;
D3D12_RESOURCE_DESC resource_desc; D3D12_RESOURCE_DESC resource_desc;
ID3D12Resource *src_resource; ID3D12Resource *src_resource;
@@ -434,8 +433,6 @@ static void get_resource_readback_with_command_list(ID3D12Resource *resource, un
assert_that(hr == S_OK, "Failed to get device, hr %#x.\n", hr); assert_that(hr == S_OK, "Failed to get device, hr %#x.\n", hr);
resource_desc = ID3D12Resource_GetDesc(resource); resource_desc = ID3D12Resource_GetDesc(resource);
assert_that(resource_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER,
"Resource %p is not texture.\n", resource);
miplevel = sub_resource % resource_desc.MipLevels; miplevel = sub_resource % resource_desc.MipLevels;
rb->rb.width = max(1, resource_desc.Width >> miplevel); rb->rb.width = max(1, resource_desc.Width >> miplevel);
@@ -444,10 +441,13 @@ static void get_resource_readback_with_command_list(ID3D12Resource *resource, un
rb->rb.height = align(rb->rb.height, format_block_height(resource_desc.Format)); rb->rb.height = align(rb->rb.height, format_block_height(resource_desc.Format));
rb->rb.depth = resource_desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D rb->rb.depth = resource_desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D
? max(1, resource_desc.DepthOrArraySize >> miplevel) : 1; ? max(1, resource_desc.DepthOrArraySize >> miplevel) : 1;
rb->rb.row_pitch = align(rb->rb.width * format_size(resource_desc.Format), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); rb->rb.row_pitch = rb->rb.width * format_size(resource_desc.Format);
if (resource_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER)
rb->rb.row_pitch = align(rb->rb.row_pitch, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
rb->rb.data = NULL; rb->rb.data = NULL;
if (resource_desc.SampleDesc.Count > 1) src_resource = resource;
if (resource_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER && resource_desc.SampleDesc.Count > 1)
{ {
memset(&heap_properties, 0, sizeof(heap_properties)); memset(&heap_properties, 0, sizeof(heap_properties));
heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT; heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT;
@@ -468,28 +468,33 @@ static void get_resource_readback_with_command_list(ID3D12Resource *resource, un
sub_resource = 0; sub_resource = 0;
} }
else
{
src_resource = resource;
}
buffer_size = rb->rb.row_pitch * rb->rb.height * rb->rb.depth; buffer_size = rb->rb.row_pitch * rb->rb.height * rb->rb.depth;
rb->resource = create_readback_buffer(device, buffer_size); rb->resource = create_readback_buffer(device, buffer_size);
dst_location.pResource = rb->resource; if (resource_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
dst_location.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; {
dst_location.PlacedFootprint.Offset = 0; ID3D12GraphicsCommandList_CopyResource(command_list, rb->resource, resource);
dst_location.PlacedFootprint.Footprint.Format = resource_desc.Format; }
dst_location.PlacedFootprint.Footprint.Width = rb->rb.width; else
dst_location.PlacedFootprint.Footprint.Height = rb->rb.height; {
dst_location.PlacedFootprint.Footprint.Depth = rb->rb.depth; D3D12_TEXTURE_COPY_LOCATION dst_location, src_location;
dst_location.PlacedFootprint.Footprint.RowPitch = rb->rb.row_pitch;
src_location.pResource = src_resource; dst_location.pResource = rb->resource;
src_location.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; dst_location.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
src_location.SubresourceIndex = sub_resource; dst_location.PlacedFootprint.Offset = 0;
dst_location.PlacedFootprint.Footprint.Format = resource_desc.Format;
dst_location.PlacedFootprint.Footprint.Width = rb->rb.width;
dst_location.PlacedFootprint.Footprint.Height = rb->rb.height;
dst_location.PlacedFootprint.Footprint.Depth = rb->rb.depth;
dst_location.PlacedFootprint.Footprint.RowPitch = rb->rb.row_pitch;
ID3D12GraphicsCommandList_CopyTextureRegion(command_list, &dst_location, 0, 0, 0, &src_location, NULL); src_location.pResource = src_resource;
src_location.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
src_location.SubresourceIndex = sub_resource;
ID3D12GraphicsCommandList_CopyTextureRegion(command_list, &dst_location, 0, 0, 0, &src_location, NULL);
}
hr = ID3D12GraphicsCommandList_Close(command_list); hr = ID3D12GraphicsCommandList_Close(command_list);
assert_that(hr == S_OK, "Failed to close command list, hr %#x.\n", hr); assert_that(hr == S_OK, "Failed to close command list, hr %#x.\n", hr);
@@ -696,18 +701,25 @@ static inline void upload_texture_data_(unsigned int line, ID3D12Resource *textu
} }
ID3D12Resource_Unmap(upload_buffer, 0, NULL); ID3D12Resource_Unmap(upload_buffer, 0, NULL);
for (i = 0; i < sub_resource_count; ++i) if (resource_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
{ {
dst_location.pResource = texture; ID3D12GraphicsCommandList_CopyResource(command_list, texture, upload_buffer);
dst_location.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; }
dst_location.SubresourceIndex = i; else
{
for (i = 0; i < sub_resource_count; ++i)
{
dst_location.pResource = texture;
dst_location.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
dst_location.SubresourceIndex = i;
src_location.pResource = upload_buffer; src_location.pResource = upload_buffer;
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];
ID3D12GraphicsCommandList_CopyTextureRegion(command_list, ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
&dst_location, 0, 0, 0, &src_location, NULL); &dst_location, 0, 0, 0, &src_location, NULL);
}
} }
hr = ID3D12GraphicsCommandList_Close(command_list); hr = ID3D12GraphicsCommandList_Close(command_list);
@@ -724,6 +736,31 @@ static inline void upload_texture_data_(unsigned int line, ID3D12Resource *textu
free(row_sizes); free(row_sizes);
} }
#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)
{
ID3D12Resource *upload_buffer;
ID3D12Device *device;
HRESULT hr;
hr = ID3D12Resource_GetDevice(buffer, &IID_ID3D12Device, (void **)&device);
ok_(line)(SUCCEEDED(hr), "Failed to get device, hr %#x.\n", hr);
upload_buffer = create_upload_buffer_(line, device, size, data);
ID3D12GraphicsCommandList_CopyBufferRegion(command_list, buffer, offset,
upload_buffer, 0, size);
hr = ID3D12GraphicsCommandList_Close(command_list);
ok_(line)(SUCCEEDED(hr), "Failed to close command list, hr %#x.\n", hr);
exec_command_list(queue, command_list);
wait_queue_idle(device, queue);
ID3D12Resource_Release(upload_buffer);
ID3D12Device_Release(device);
}
static HRESULT create_root_signature(ID3D12Device *device, const D3D12_ROOT_SIGNATURE_DESC *desc, static HRESULT create_root_signature(ID3D12Device *device, const D3D12_ROOT_SIGNATURE_DESC *desc,
ID3D12RootSignature **root_signature) ID3D12RootSignature **root_signature)
{ {

View File

@@ -145,7 +145,6 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co
break; break;
case RESOURCE_TYPE_UAV: case RESOURCE_TYPE_UAV:
case RESOURCE_TYPE_BUFFER_UAV:
if (!runner->heap) if (!runner->heap)
runner->heap = create_gpu_descriptor_heap(device, runner->heap = create_gpu_descriptor_heap(device,
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, MAX_RESOURCE_DESCRIPTORS); D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, MAX_RESOURCE_DESCRIPTORS);
@@ -161,6 +160,30 @@ static struct resource *d3d12_runner_create_resource(struct shader_runner *r, co
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;
case RESOURCE_TYPE_BUFFER_UAV:
{
D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc = { 0 };
if (!runner->heap)
runner->heap = create_gpu_descriptor_heap(device,
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, MAX_RESOURCE_DESCRIPTORS);
resource->resource = create_default_buffer(device, params->data_size,
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST);
upload_buffer_data(resource->resource, 0, params->data_size, resource_data,
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, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
uav_desc.Format = params->format;
uav_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
uav_desc.Buffer.NumElements = params->width * params->height;
ID3D12Device_CreateUnorderedAccessView(device, resource->resource,
NULL, &uav_desc, get_cpu_descriptor_handle(test_context, runner->heap, resource->r.slot + MAX_RESOURCES));
break;
}
case RESOURCE_TYPE_VERTEX_BUFFER: case RESOURCE_TYPE_VERTEX_BUFFER:
resource->resource = create_upload_buffer(device, params->data_size, params->data); resource->resource = create_upload_buffer(device, params->data_size, params->data);
break; break;
@@ -224,7 +247,7 @@ static ID3D12RootSignature *d3d12_runner_create_root_signature(struct d3d12_shad
root_param->DescriptorTable.pDescriptorRanges = range; root_param->DescriptorTable.pDescriptorRanges = range;
root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; root_param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
if (resource->r.type == RESOURCE_TYPE_UAV) if (resource->r.type == RESOURCE_TYPE_UAV || resource->r.type == RESOURCE_TYPE_BUFFER_UAV)
range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV; range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
else else
range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; range->RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
@@ -432,6 +455,8 @@ static bool d3d12_runner_draw(struct shader_runner *r,
if (runner->r.uniform_count) if (runner->r.uniform_count)
ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, uniform_index, ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, uniform_index,
runner->r.uniform_count, runner->r.uniforms, 0); runner->r.uniform_count, runner->r.uniforms, 0);
if (runner->heap)
ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &runner->heap);
for (i = 0; i < runner->r.resource_count; ++i) for (i = 0; i < runner->r.resource_count; ++i)
{ {
struct d3d12_resource *resource = d3d12_resource(runner->r.resources[i]); struct d3d12_resource *resource = d3d12_resource(runner->r.resources[i]);