diff --git a/tests/d3d12.c b/tests/d3d12.c index 44e128a9..5393072f 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -24965,74 +24965,60 @@ static void test_sample_mask(void) static void test_coverage(void) { - static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; + D3D12_ROOT_SIGNATURE_DESC root_signature_desc; D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc; + D3D12_DESCRIPTOR_RANGE descriptor_ranges[1]; + ID3D12DescriptorHeap *cpu_heap, *gpu_heap; ID3D12GraphicsCommandList *command_list; - D3D12_CPU_DESCRIPTOR_HANDLE ms_rtv; - ID3D12Resource *ms_render_target; - ID3D12PipelineState *pso_resolve; + D3D12_ROOT_PARAMETER root_parameters[1]; struct test_context_desc desc; struct test_context context; - ID3D12DescriptorHeap *heap; ID3D12CommandQueue *queue; + ID3D12Resource *texture; unsigned int i; HRESULT hr; + static const float black[4]; + static const unsigned int zero[4]; static const DWORD ps_code[] = { #if 0 - uint4 main(uint coverage : SV_Coverage) : SV_Target - { - return coverage; - } -#endif - 0x43425844, 0x0d652986, 0x6144c247, 0x743bacfa, 0x95068994, 0x00000001, 0x000000ac, 0x00000003, - 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, - 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000, - 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000034, 0x00000050, 0x0000000d, - 0x0100086a, 0x0200005f, 0x00023001, 0x03000065, 0x001020f2, 0x00000000, 0x04000036, 0x001020f2, - 0x00000000, 0x00023006, 0x0100003e, - }; - static const D3D12_SHADER_BYTECODE ps = {ps_code, sizeof(ps_code)}; - static const DWORD ps_resolve_code[] = - { -#if 0 - Texture2DMS t; + RWTexture2D u; - uint4 main(float4 position : SV_Position) : SV_Target + float4 main(float4 position : SV_Position, uint coverage : SV_Coverage) : SV_Target { - return t.Load((int2)position.xy, 0); + InterlockedOr(u[uint2(position.x, position.y)], coverage); + return float4(0.0, 1.0, 0.0, 1.0); } #endif - 0x43425844, 0x280a495f, 0x88543834, 0x1fd0597d, 0xe7ed74ac, 0x00000001, 0x00000154, 0x00000003, + 0x43425844, 0x53236006, 0x68a61a42, 0x5d0a06e7, 0x05a9405b, 0x00000001, 0x00000134, 0x00000003, 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69, - 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, - 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000b8, 0x00000050, - 0x0000002e, 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, - 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0500001b, - 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8b00002e, 0x80000102, 0x00111103, 0x00100012, - 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00004001, 0x00000000, 0x05000036, - 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, + 0x00000026, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, + 0x00000000, 0x00000001, 0x0200005f, 0x00023001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, + 0x00000001, 0x0500001c, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x060000aa, 0x0011e000, + 0x00000001, 0x00100046, 0x00000000, 0x0002300a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, + 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, }; - static const D3D12_SHADER_BYTECODE ps_resolve = {ps_resolve_code, sizeof(ps_resolve_code)}; + static const D3D12_SHADER_BYTECODE ps = {ps_code, sizeof(ps_code)}; static const struct { unsigned int sample_mask; - unsigned int expected_result; + unsigned int expected_color; } tests[] = { - {0x01, 0x1}, - {0x03, 0x3}, - {0x07, 0x7}, - {0x09, 0x9}, - {0x0d, 0xd}, - {0x0f, 0xf}, - {0xff, 0xf}, - { ~0u, 0xf}, + {0x01, 0x40004000}, + {0x03, 0x7f007f00}, + {0x07, 0xbf00bf00}, + {0x09, 0x7f007f00}, + {0x0d, 0xbf00bf00}, + {0x0f, 0xff00ff00}, + {0xff, 0xff00ff00}, + { ~0u, 0xff00ff00}, }; if (use_warp_device) @@ -25043,27 +25029,41 @@ static void test_coverage(void) memset(&desc, 0, sizeof(desc)); desc.rt_width = desc.rt_height = 32; - desc.rt_format = DXGI_FORMAT_R32_UINT; - desc.rt_descriptor_count = 2; + desc.sample_desc.Count = 4; desc.no_root_signature = true; if (!init_test_context(&context, &desc)) return; command_list = context.list; queue = context.queue; - context.root_signature = create_texture_root_signature(context.device, - D3D12_SHADER_VISIBILITY_PIXEL, 1, 0); + descriptor_ranges[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV; + descriptor_ranges[0].NumDescriptors = 1; + descriptor_ranges[0].BaseShaderRegister = 1; + 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 = ARRAY_SIZE(descriptor_ranges); + root_parameters[0].DescriptorTable.pDescriptorRanges = descriptor_ranges; + root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + root_signature_desc.NumParameters = ARRAY_SIZE(root_parameters); + 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(context.device, &root_signature_desc, &context.root_signature); + ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr); - ms_rtv = get_cpu_rtv_handle(&context, context.rtv_heap, 1); - desc.sample_desc.Count = 4; - create_render_target(&context, &desc, &ms_render_target, &ms_rtv); + texture = create_default_texture(context.device, desc.rt_width, desc.rt_height, DXGI_FORMAT_R32_UINT, + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); - heap = create_gpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); - ID3D12Device_CreateShaderResourceView(context.device, ms_render_target, NULL, - get_cpu_descriptor_handle(&context, heap, 0)); - - pso_resolve = create_pipeline_state(context.device, - context.root_signature, context.render_target_desc.Format, NULL, &ps_resolve, NULL); + cpu_heap = create_cpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); + gpu_heap = create_gpu_descriptor_heap(context.device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); + ID3D12Device_CreateUnorderedAccessView(context.device, texture, NULL, NULL, + get_cpu_descriptor_handle(&context, cpu_heap, 0)); + ID3D12Device_CopyDescriptorsSimple(context.device, 1, + get_cpu_descriptor_handle(&context, gpu_heap, 0), + get_cpu_descriptor_handle(&context, cpu_heap, 0), + D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); for (i = 0; i < ARRAY_SIZE(tests); ++i) { @@ -25075,50 +25075,50 @@ static void test_coverage(void) init_pipeline_state_desc(&pso_desc, context.root_signature, context.render_target_desc.Format, NULL, &ps, NULL); pso_desc.SampleMask = tests[i].sample_mask; - pso_desc.SampleDesc.Count = 4; + pso_desc.SampleDesc.Count = desc.sample_desc.Count; hr = ID3D12Device_CreateGraphicsPipelineState(context.device, &pso_desc, &IID_ID3D12PipelineState, (void **)&context.pipeline_state); ok(hr == S_OK, "Failed to create pipeline, hr %#x.\n", hr); - ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); - ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, ms_rtv, white, 0, NULL); - ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &ms_rtv, FALSE, NULL); + ID3D12GraphicsCommandList_ClearUnorderedAccessViewUint(command_list, + get_gpu_descriptor_handle(&context, gpu_heap, 0), + get_cpu_descriptor_handle(&context, cpu_heap, 0), + texture, zero, 0, NULL); + + uav_barrier(command_list, texture); + + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, black, 0, NULL); + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL); ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &gpu_heap); + ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, + 0, get_gpu_descriptor_handle(&context, gpu_heap, 0)); ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); - transition_resource_state(command_list, ms_render_target, - D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); - - ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL); - ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); - ID3D12GraphicsCommandList_SetPipelineState(command_list, pso_resolve); - ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); - ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); - ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &heap); - ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, 0, - get_gpu_descriptor_handle(&context, heap, 0)); - ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0); - - transition_resource_state(command_list, ms_render_target, - D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); transition_resource_state(command_list, context.render_target, - D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); - check_sub_resource_uint(context.render_target, 0, queue, command_list, tests[i].expected_result, 0); + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); + check_sub_resource_uint(context.render_target, 0, queue, command_list, tests[i].expected_color, 2); + + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, texture, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); + check_sub_resource_uint(texture, 0, queue, command_list, tests[i].sample_mask & 0xf, 0); reset_command_list(command_list, context.allocator); transition_resource_state(command_list, context.render_target, - D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + D3D12_RESOURCE_STATE_RESOLVE_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + transition_resource_state(command_list, texture, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); } vkd3d_test_set_context(NULL); - ID3D12DescriptorHeap_Release(heap); - ID3D12PipelineState_Release(pso_resolve); - ID3D12Resource_Release(ms_render_target); + ID3D12DescriptorHeap_Release(cpu_heap); + ID3D12DescriptorHeap_Release(gpu_heap); + ID3D12Resource_Release(texture); destroy_test_context(&context); } diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h index 6ccbc649..1b2aec59 100644 --- a/tests/d3d12_test_utils.h +++ b/tests/d3d12_test_utils.h @@ -315,14 +315,14 @@ static void get_texture_readback_with_command_list(ID3D12Resource *texture, unsi resource_desc.SampleDesc.Count = 1; resource_desc.SampleDesc.Quality = 0; hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE, - &resource_desc, D3D12_RESOURCE_STATE_COPY_DEST, NULL, + &resource_desc, D3D12_RESOURCE_STATE_RESOLVE_DEST, NULL, &IID_ID3D12Resource, (void **)&src_resource); ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr); ID3D12GraphicsCommandList_ResolveSubresource(command_list, src_resource, 0, texture, sub_resource, resource_desc.Format); transition_resource_state(command_list, src_resource, - D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE); + D3D12_RESOURCE_STATE_RESOLVE_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE); sub_resource = 0; } @@ -637,7 +637,7 @@ static void create_render_target_(unsigned int line, struct test_context *contex resource_desc.MipLevels = 1; resource_desc.Format = desc && desc->rt_format ? desc->rt_format : DXGI_FORMAT_R8G8B8A8_UNORM; resource_desc.SampleDesc.Count = desc && desc->sample_desc.Count ? desc->sample_desc.Count : 1; - resource_desc.SampleDesc.Quality = desc ? desc->sample_desc.Quality : 0; + resource_desc.SampleDesc.Quality = desc && desc->sample_desc.Count ? desc->sample_desc.Quality : 0; resource_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; resource_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; clear_value.Format = resource_desc.Format; @@ -649,7 +649,7 @@ static void create_render_target_(unsigned int line, struct test_context *contex &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, &clear_value, &IID_ID3D12Resource, (void **)render_target); - ok_(line)(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); + ok_(line)(hr == S_OK, "Failed to create texture, hr %#x.\n", hr); context->render_target_desc = resource_desc;