Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index 3892c1db..ab13f397 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -21984,6 +21984,139 @@ static void test_decrement_uav_counter(void) destroy_test_context(&context); }
+static void test_graphics_uav_counters(void) +{ + D3D12_ROOT_SIGNATURE_DESC root_signature_desc; + D3D12_DESCRIPTOR_RANGE descriptor_ranges[1]; + D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc; + ID3D12DescriptorHeap *cpu_heap, *gpu_heap; + ID3D12GraphicsCommandList *command_list; + ID3D12Resource *buffer, *counter_buffer; + D3D12_ROOT_PARAMETER root_parameters[1]; + struct test_context_desc desc; + struct test_context context; + struct resource_readback rb; + ID3D12CommandQueue *queue; + ID3D12Device *device; + uint32_t counter; + D3D12_BOX box; + HRESULT hr; + + static const uint32_t clear_value[4] = {0}; + static const DWORD ps_code[] = + { +#if 0 + RWStructuredBuffer<uint> u; + + void main() + { + uint i = u.IncrementCounter(); + ++u[i]; + } +#endif + 0x43425844, 0x951850a3, 0xb2e7dcee, 0x6195cf5f, 0x3e1e6220, 0x00000001, 0x000000fc, 0x00000003, + 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a, 0x0100086a, + 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x02000068, 0x00000001, 0x050000b2, 0x00100012, + 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000, + 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x0700001e, 0x00100022, + 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x090000a8, 0x0011e012, 0x00000000, + 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE ps = {ps_code, sizeof(ps_code)}; + + memset(&desc, 0, sizeof(desc)); + desc.rt_width = 64; + desc.rt_height = 1; + desc.no_root_signature = true; + if (!init_test_context(&context, &desc)) + return; + device = context.device; + command_list = context.list; + queue = context.queue; + + descriptor_ranges[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV; + descriptor_ranges[0].NumDescriptors = 1; + descriptor_ranges[0].BaseShaderRegister = 0; + descriptor_ranges[0].RegisterSpace = 0; + descriptor_ranges[0].OffsetInDescriptorsFromTableStart = 0; + root_parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; + root_parameters[0].DescriptorTable.NumDescriptorRanges = 1; + root_parameters[0].DescriptorTable.pDescriptorRanges = descriptor_ranges; + root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; + root_signature_desc.NumParameters = 1; + root_signature_desc.pParameters = root_parameters; + root_signature_desc.NumStaticSamplers = 0; + root_signature_desc.pStaticSamplers = NULL; + root_signature_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE; + hr = create_root_signature(device, &root_signature_desc, &context.root_signature); + ok(SUCCEEDED(hr), "Failed to create root signature, hr %#x.\n", hr); + + cpu_heap = create_cpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); + gpu_heap = create_gpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); + + buffer = create_default_buffer(device, 64 * sizeof(uint32_t), + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + counter_buffer = create_default_buffer(device, D3D12_UAV_COUNTER_PLACEMENT_ALIGNMENT + sizeof(uint32_t), + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST); + + context.pipeline_state = create_pipeline_state(context.device, context.root_signature, 0, NULL, &ps, NULL); + + memset(&uav_desc, 0, sizeof(uav_desc)); + uav_desc.Format = DXGI_FORMAT_UNKNOWN; + uav_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; + uav_desc.Buffer.NumElements = 64; + uav_desc.Buffer.StructureByteStride = sizeof(uint32_t); + uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE; + ID3D12Device_CreateUnorderedAccessView(device, buffer, NULL, &uav_desc, + get_cpu_descriptor_handle(&context, cpu_heap, 0)); + uav_desc.Buffer.CounterOffsetInBytes = D3D12_UAV_COUNTER_PLACEMENT_ALIGNMENT; + ID3D12Device_CreateUnorderedAccessView(device, buffer, counter_buffer, &uav_desc, + get_cpu_descriptor_handle(&context, gpu_heap, 0)); + + ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &gpu_heap); + + ID3D12GraphicsCommandList_ClearUnorderedAccessViewUint(command_list, + get_gpu_descriptor_handle(&context, gpu_heap, 0), + get_cpu_descriptor_handle(&context, cpu_heap, 0), + buffer, clear_value, 0, NULL); + uav_barrier(command_list, buffer); + + counter = 0; + upload_buffer_data(counter_buffer, uav_desc.Buffer.CounterOffsetInBytes, + sizeof(counter), &counter, queue, command_list); + reset_command_list(command_list, context.allocator); + transition_sub_resource_state(command_list, counter_buffer, 0, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, 0, + ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(gpu_heap)); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); + + counter = read_uav_counter(&context, counter_buffer, uav_desc.Buffer.CounterOffsetInBytes); + todo + ok(counter == 64, "Got %u, expected 64.\n", counter); + + transition_sub_resource_state(command_list, buffer, 0, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); + get_buffer_readback_with_command_list(buffer, DXGI_FORMAT_R32_UINT, &rb, queue, command_list); + set_box(&box, 0, 0, 0, uav_desc.Buffer.NumElements, 1, 1); + todo + check_readback_data_uint(&rb, &box, 1, 0); + release_resource_readback(&rb); + + ID3D12Resource_Release(buffer); + ID3D12Resource_Release(counter_buffer); + ID3D12DescriptorHeap_Release(cpu_heap); + ID3D12DescriptorHeap_Release(gpu_heap); + destroy_test_context(&context); +} + static void test_atomic_instructions(void) { ID3D12Resource *ps_buffer, *cs_buffer, *cs_buffer2; @@ -34249,6 +34382,7 @@ START_TEST(d3d12) run_test(test_cs_uav_store); run_test(test_uav_counters); run_test(test_decrement_uav_counter); + run_test(test_graphics_uav_counters); run_test(test_atomic_instructions); run_test(test_buffer_srv); run_test(test_create_query_heap);
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/state.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index e459c998..4537e319 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1414,9 +1414,9 @@ static HRESULT vkd3d_create_compute_pipeline(struct d3d12_device *device, return S_OK; }
-static HRESULT d3d12_pipeline_state_init_compute_uav_counters(struct d3d12_pipeline_state *state, +static HRESULT d3d12_pipeline_state_init_uav_counters(struct d3d12_pipeline_state *state, struct d3d12_device *device, const struct d3d12_root_signature *root_signature, - const struct vkd3d_shader_scan_descriptor_info *shader_info) + const struct vkd3d_shader_scan_descriptor_info *shader_info, VkShaderStageFlags stage_flags) { const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; VkDescriptorSetLayout set_layouts[VKD3D_MAX_DESCRIPTOR_SETS + 1]; @@ -1426,6 +1426,8 @@ static HRESULT d3d12_pipeline_state_init_compute_uav_counters(struct d3d12_pipel unsigned int i, j; HRESULT hr;
+ assert(vkd3d_popcount(stage_flags) == 1); + for (i = 0; i < shader_info->descriptor_count; ++i) { const struct vkd3d_shader_descriptor_info *d = &shader_info->descriptors[i]; @@ -1438,6 +1440,16 @@ static HRESULT d3d12_pipeline_state_init_compute_uav_counters(struct d3d12_pipel if (!uav_counter_count) return S_OK;
+ /* It should be possible to support other stages in Vulkan, but in a graphics pipeline + * D3D12 currently only supports counters in pixel shaders, and handling multiple stages + * would be more complex. */ + if (!(stage_flags & (VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT))) + { + FIXME("Found a UAV counter for Vulkan shader stage %#x. UAV counters in a " + "graphics pipeline are only supported in pixel shaders.\n", stage_flags); + return E_INVALIDARG; + } + if (!(binding_desc = vkd3d_calloc(uav_counter_count, sizeof(*binding_desc)))) return E_OUTOFMEMORY; if (!(state->uav_counters = vkd3d_calloc(uav_counter_count, sizeof(*state->uav_counters)))) @@ -1461,17 +1473,16 @@ static HRESULT d3d12_pipeline_state_init_compute_uav_counters(struct d3d12_pipel
state->uav_counters[j].register_space = d->register_space; state->uav_counters[j].register_index = d->register_index; - state->uav_counters[j].shader_visibility = VKD3D_SHADER_VISIBILITY_COMPUTE; + state->uav_counters[j].shader_visibility = (stage_flags == VK_SHADER_STAGE_COMPUTE_BIT) + ? VKD3D_SHADER_VISIBILITY_COMPUTE : VKD3D_SHADER_VISIBILITY_PIXEL; state->uav_counters[j].binding.set = set_index; state->uav_counters[j].binding.binding = descriptor_binding; state->uav_counters[j].binding.count = 1;
- /* FIXME: For the graphics pipeline we have to take the shader - * visibility into account. */ binding_desc[j].binding = descriptor_binding; binding_desc[j].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; binding_desc[j].descriptorCount = 1; - binding_desc[j].stageFlags = VK_SHADER_STAGE_ALL; + binding_desc[j].stageFlags = stage_flags; binding_desc[j].pImmutableSamplers = NULL;
++descriptor_binding; @@ -1538,8 +1549,8 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st return hresult_from_vkd3d_result(ret); }
- if (FAILED(hr = d3d12_pipeline_state_init_compute_uav_counters(state, - device, root_signature, &shader_info))) + if (FAILED(hr = d3d12_pipeline_state_init_uav_counters(state, + device, root_signature, &shader_info, VK_SHADER_STAGE_COMPUTE_BIT))) { WARN("Failed to create descriptor set layout for UAV counters, hr %#x.\n", hr); return hr;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49107 Allows GRID 2019 to run in D3D12 mode.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/state.c | 22 ++++++++++------------ tests/d3d12.c | 2 -- 2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 4537e319..8fef5a38 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -2274,8 +2274,6 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s shader_interface.push_constant_buffer_count = root_signature->root_constant_count; shader_interface.combined_samplers = NULL; shader_interface.combined_sampler_count = 0; - shader_interface.uav_counters = NULL; - shader_interface.uav_counter_count = 0;
for (i = 0; i < ARRAY_SIZE(shader_stages); ++i) { @@ -2296,19 +2294,16 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s hr = hresult_from_vkd3d_result(ret); goto fail; } - for (j = 0; j < shader_info.descriptor_count; ++j) + if (FAILED(hr = d3d12_pipeline_state_init_uav_counters(state, + device, root_signature, &shader_info, shader_stages[i].stage))) { - const struct vkd3d_shader_descriptor_info *d = &shader_info.descriptors[j]; - - if (d->type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV - && (d->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_COUNTER)) - { - FIXME("UAV counters not implemented for graphics pipelines.\n"); - break; - } + WARN("Failed to create descriptor set layout for UAV counters, hr %#x.\n", hr); + return hr; } vkd3d_shader_free_scan_descriptor_info(&shader_info);
+ shader_interface.uav_counters = NULL; + shader_interface.uav_counter_count = 0; target_info = NULL; switch (shader_stages[i].stage) { @@ -2334,6 +2329,8 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s break;
case VK_SHADER_STAGE_FRAGMENT_BIT: + shader_interface.uav_counters = state->uav_counters; + shader_interface.uav_counter_count = state->uav_counter_count; target_info = &ps_target_info; break;
@@ -2817,7 +2814,8 @@ VkPipeline d3d12_pipeline_state_get_or_create_pipeline(struct d3d12_pipeline_sta pipeline_desc.pDepthStencilState = &graphics->ds_desc; pipeline_desc.pColorBlendState = &blend_desc; pipeline_desc.pDynamicState = &dynamic_desc; - pipeline_desc.layout = graphics->root_signature->vk_pipeline_layout; + pipeline_desc.layout = state->vk_pipeline_layout ? state->vk_pipeline_layout + : graphics->root_signature->vk_pipeline_layout; pipeline_desc.subpass = 0; pipeline_desc.basePipelineHandle = VK_NULL_HANDLE; pipeline_desc.basePipelineIndex = -1; diff --git a/tests/d3d12.c b/tests/d3d12.c index ab13f397..75c8c222 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -22099,14 +22099,12 @@ static void test_graphics_uav_counters(void) ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0);
counter = read_uav_counter(&context, counter_buffer, uav_desc.Buffer.CounterOffsetInBytes); - todo ok(counter == 64, "Got %u, expected 64.\n", counter);
transition_sub_resource_state(command_list, buffer, 0, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); get_buffer_readback_with_command_list(buffer, DXGI_FORMAT_R32_UINT, &rb, queue, command_list); set_box(&box, 0, 0, 0, uav_desc.Buffer.NumElements, 1, 1); - todo check_readback_data_uint(&rb, &box, 1, 0); release_resource_readback(&rb);
On Wed, 14 Jul 2021 at 17:48, Conor McCarthy cmccarthy@codeweavers.com wrote:
@@ -2296,19 +2294,16 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s hr = hresult_from_vkd3d_result(ret); goto fail; }
for (j = 0; j < shader_info.descriptor_count; ++j)
if (FAILED(hr = d3d12_pipeline_state_init_uav_counters(state,
device, root_signature, &shader_info, shader_stages[i].stage))) {
const struct vkd3d_shader_descriptor_info *d = &shader_info.descriptors[j];
if (d->type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV
&& (d->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_COUNTER))
{
FIXME("UAV counters not implemented for graphics pipelines.\n");
break;
}
WARN("Failed to create descriptor set layout for UAV counters, hr %#x.\n", hr);
return hr; } vkd3d_shader_free_scan_descriptor_info(&shader_info);
This potentially leaks the input signature and shader modules for previous stages.