Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 26 +++++++++----------------- tests/d3d12_test_utils.h | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/tests/d3d12.c b/tests/d3d12.c index f723dbaa..eddd6cbf 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -7372,11 +7372,10 @@ static void test_bundle_state_inheritance(void) { static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; ID3D12GraphicsCommandList *command_list, *bundle; - ID3D12CommandAllocator *bundle_allocator; + struct bundle_context bundle_context; struct test_context context; struct resource_readback rb; ID3D12CommandQueue *queue; - ID3D12Device *device; unsigned int x, y; HRESULT hr;
@@ -7388,16 +7387,10 @@ static void test_bundle_state_inheritance(void)
if (!init_test_context(&context, NULL)) return; - device = context.device; command_list = context.list; queue = context.queue; - - hr = ID3D12Device_CreateCommandAllocator(device, D3D12_COMMAND_LIST_TYPE_BUNDLE, - &IID_ID3D12CommandAllocator, (void **)&bundle_allocator); - ok(SUCCEEDED(hr), "Failed to create command allocator, hr %#x.\n", hr); - hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_BUNDLE, - bundle_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&bundle); - ok(SUCCEEDED(hr), "Failed to create command list, hr %#x.\n", hr); + init_bundle_context(context.device, &bundle_context); + bundle = bundle_context.list;
/* A bundle does not inherit the current pipeline state. */ ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); @@ -7431,7 +7424,7 @@ static void test_bundle_state_inheritance(void) release_resource_readback(&rb);
reset_command_list(command_list, context.allocator); - reset_command_list(bundle, bundle_allocator); + reset_command_list(bundle, bundle_context.allocator);
/* A bundle sets to null the pipeline state in the executing command list. */ ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); @@ -7466,7 +7459,7 @@ static void test_bundle_state_inheritance(void) release_resource_readback(&rb);
reset_command_list(command_list, context.allocator); - reset_command_list(bundle, bundle_allocator); + reset_command_list(bundle, bundle_context.allocator);
/* A bundle does not inherit the current primitive topology. */ transition_resource_state(command_list, context.render_target, @@ -7503,7 +7496,7 @@ static void test_bundle_state_inheritance(void) release_resource_readback(&rb);
reset_command_list(command_list, context.allocator); - reset_command_list(bundle, bundle_allocator); + reset_command_list(bundle, bundle_context.allocator);
/* A bundle sets to undefined the primitive topology in the executing command list. */ transition_resource_state(command_list, context.render_target, @@ -7540,7 +7533,7 @@ static void test_bundle_state_inheritance(void) release_resource_readback(&rb);
reset_command_list(command_list, context.allocator); - reset_command_list(bundle, bundle_allocator); + reset_command_list(bundle, bundle_context.allocator);
/* A bundle inherit all other states. */ transition_resource_state(command_list, context.render_target, @@ -7566,7 +7559,7 @@ static void test_bundle_state_inheritance(void) check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xff00ff00, 0);
reset_command_list(command_list, context.allocator); - reset_command_list(bundle, bundle_allocator); + reset_command_list(bundle, bundle_context.allocator);
/* All state that is set in a bundle affects a command list. */ transition_resource_state(command_list, context.render_target, @@ -7591,8 +7584,7 @@ static void test_bundle_state_inheritance(void) todo check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xff00ff00, 0);
- ID3D12CommandAllocator_Release(bundle_allocator); - ID3D12GraphicsCommandList_Release(bundle); + destroy_bundle_context(&bundle_context); destroy_test_context(&context); }
diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h index 0374d8d1..5cf2c130 100644 --- a/tests/d3d12_test_utils.h +++ b/tests/d3d12_test_utils.h @@ -1008,6 +1008,29 @@ static inline void destroy_test_context_(unsigned int line, struct test_context ok_(line)(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount); }
+struct bundle_context +{ + ID3D12CommandAllocator *allocator; + ID3D12GraphicsCommandList *list; +}; + +#define init_bundle_context(device, context) init_bundle_context_(__LINE__, device, context) +static inline void init_bundle_context_(unsigned int line, ID3D12Device *device, struct bundle_context *bundle) +{ + HRESULT hr = ID3D12Device_CreateCommandAllocator(device, D3D12_COMMAND_LIST_TYPE_BUNDLE, + &IID_ID3D12CommandAllocator, (void **)&bundle->allocator); + ok_(line)(SUCCEEDED(hr), "Failed to create bundle command allocator, hr %#x.\n", hr); + hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_BUNDLE, + bundle->allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&bundle->list); + ok(SUCCEEDED(hr), "Failed to create bundle command list, hr %#x.\n", hr); +} + +static inline void destroy_bundle_context(struct bundle_context *bundle) +{ + ID3D12CommandAllocator_Release(bundle->allocator); + ID3D12GraphicsCommandList_Release(bundle->list); +} + static inline D3D12_CPU_DESCRIPTOR_HANDLE get_cpu_handle(ID3D12Device *device, ID3D12DescriptorHeap *heap, D3D12_DESCRIPTOR_HEAP_TYPE heap_type, unsigned int offset) {
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index eddd6cbf..a838a9fb 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -7588,6 +7588,196 @@ static void test_bundle_state_inheritance(void) destroy_test_context(&context); }
+static void test_compute_bundle(void) +{ + ID3D12Resource *cb, *sr_buffer, *root_buffer, *heap_buffer; + ID3D12GraphicsCommandList *command_list, *bundle; + D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc; + ID3D12DescriptorHeap *descriptor_heap; + D3D12_DESCRIPTOR_HEAP_DESC heap_desc; + struct bundle_context bundle_context; + struct test_context_desc desc; + struct test_context context; + struct resource_readback rb; + ID3D12CommandQueue *queue; + unsigned int i, value; + ID3D12Device *device; + HRESULT hr; + + static const D3D12_DESCRIPTOR_RANGE descriptor_ranges[] = + { + {D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0}, + }; + + static const D3D12_ROOT_PARAMETER root_parameters[] = + { + {D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, + .DescriptorTable = {ARRAY_SIZE(descriptor_ranges), descriptor_ranges}}, + {D3D12_ROOT_PARAMETER_TYPE_CBV, .Descriptor = {0, 0}}, + {D3D12_ROOT_PARAMETER_TYPE_SRV, .Descriptor = {0, 0}}, + {D3D12_ROOT_PARAMETER_TYPE_UAV, .Descriptor = {0, 0}}, + {D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS, .Constants = {1, 0, 3}}, + }; + + static const D3D12_ROOT_SIGNATURE_DESC root_signature_desc = + { + .NumParameters = ARRAY_SIZE(root_parameters), + .pParameters = root_parameters, + }; + + static const DWORD cs_code[] = + { +#if 0 + cbuffer cb0 : register(b0) + { + uint c0; + } + cbuffer cb1 : register(b1) + { + uint3 c1; + } + + ByteAddressBuffer t0 : register(t0); + + RWByteAddressBuffer u0 : register(u0); + RWByteAddressBuffer u1 : register(u1); + + [numthreads(1, 1, 1)] + void main() + { + u0.Store(0, 0xcafef00d); /* Test root UAV. */ + u1.Store(0 * 4, 0xc0ffee); /* Test heap UAV. */ + u1.Store(1 * 4, c0); /* Test CBV. */ + u1.Store(2 * 4, t0.Load(0)); /* Test SRV. */ + u1.Store(3 * 4, c1.x); /* Test setting one root constant. */ + u1.Store(4 * 4, c1.y); /* Test setting multiple root constants. */ + u1.Store(5 * 4, c1.z); /* " */ + } +#endif + 0x43425844, 0xc9916567, 0xbc1d4d84, 0xd66efd25, 0x3095566c, 0x00000001, 0x00000180, 0x00000003, + 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000012c, 0x00050050, 0x0000004b, 0x0100086a, + 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000059, 0x00208e46, 0x00000001, 0x00000001, + 0x030000a1, 0x00107000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, + 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a6, + 0x0011e012, 0x00000000, 0x00004001, 0x00000000, 0x00004001, 0xcafef00d, 0x890000a5, 0x800002c2, + 0x00199983, 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x00107006, 0x00000000, 0x05000036, + 0x00100012, 0x00000000, 0x00004001, 0x00c0ffee, 0x06000036, 0x00100022, 0x00000000, 0x0020800a, + 0x00000000, 0x00000000, 0x06000036, 0x00100082, 0x00000000, 0x0020800a, 0x00000001, 0x00000000, + 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x080000a6, + 0x0011e032, 0x00000001, 0x00004001, 0x00000010, 0x00208596, 0x00000001, 0x00000000, 0x0100003e, + }; + static const uint32_t cb_constant = 0x11111111; + static const uint32_t sr_data = 0x22222222; + static const uint32_t root_constants[] = {0x33333333, 0x44444444, 0x55555555}; + + memset(&desc, 0, sizeof(desc)); + desc.no_root_signature = true; + desc.no_render_target = true; + if (!init_test_context(&context, &desc)) + return; + device = context.device; + command_list = context.list; + queue = context.queue; + init_bundle_context(device, &bundle_context); + bundle = bundle_context.list; + + hr = create_root_signature(device, &root_signature_desc, &context.root_signature); + ok(SUCCEEDED(hr), "Failed to create root signature, hr %#x.\n", hr); + + context.pipeline_state = create_compute_pipeline_state(device, context.root_signature, + shader_bytecode(cs_code, sizeof(cs_code))); + + cb = create_upload_buffer(device, sizeof(cb_constant), &cb_constant); + sr_buffer = create_upload_buffer(device, sizeof(sr_data), &sr_data); + root_buffer = create_default_buffer(device, 1 * sizeof(uint32_t), + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + heap_buffer = create_default_buffer(device, 6 * sizeof(uint32_t), + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + + heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; + heap_desc.NumDescriptors = 1; + heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; + heap_desc.NodeMask = 0; + hr = ID3D12Device_CreateDescriptorHeap(device, &heap_desc, + &IID_ID3D12DescriptorHeap, (void **)&descriptor_heap); + ok(SUCCEEDED(hr), "Failed to create descriptor heap, hr %#x.\n", hr); + + uav_desc.Format = DXGI_FORMAT_R32_TYPELESS; + uav_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; + uav_desc.Buffer.FirstElement = 0; + uav_desc.Buffer.NumElements = 6; + uav_desc.Buffer.StructureByteStride = 0; + uav_desc.Buffer.CounterOffsetInBytes = 0; + uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; + ID3D12Device_CreateUnorderedAccessView(device, heap_buffer, NULL, &uav_desc, + ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(descriptor_heap)); + + ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &descriptor_heap); + ID3D12GraphicsCommandList_SetComputeRootSignature(bundle, context.root_signature); + /* Setting descriptor heaps in a bundle is valid if the heaps match those + * set in the executing command list. */ + ID3D12GraphicsCommandList_SetDescriptorHeaps(bundle, 1, &descriptor_heap); + ID3D12GraphicsCommandList_SetPipelineState(bundle, context.pipeline_state); + ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(bundle, 0, + ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(descriptor_heap)); + ID3D12GraphicsCommandList_SetComputeRootConstantBufferView(bundle, + 1, ID3D12Resource_GetGPUVirtualAddress(cb)); + ID3D12GraphicsCommandList_SetComputeRootShaderResourceView(bundle, + 2, ID3D12Resource_GetGPUVirtualAddress(sr_buffer)); + ID3D12GraphicsCommandList_SetComputeRootUnorderedAccessView(bundle, + 3, ID3D12Resource_GetGPUVirtualAddress(root_buffer)); + ID3D12GraphicsCommandList_SetComputeRoot32BitConstant(bundle, 4, root_constants[0], 0); + ID3D12GraphicsCommandList_SetComputeRoot32BitConstants(bundle, 4, 2, &root_constants[1], 1); + + ID3D12GraphicsCommandList_Dispatch(bundle, 1, 1, 1); + ID3D12GraphicsCommandList_Close(bundle); + ID3D12GraphicsCommandList_ExecuteBundle(command_list, bundle); + + transition_sub_resource_state(command_list, root_buffer, 0, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); + transition_sub_resource_state(command_list, heap_buffer, 0, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE); + + /* Root UAV was set. */ + get_buffer_readback_with_command_list(root_buffer, uav_desc.Format, &rb, queue, command_list); + value = get_readback_uint(&rb, 0, 0, 0); + todo + ok(value == 0xcafef00d, "Expected 0xcafef00d, got %08x for root UAV.\n", value); + release_resource_readback(&rb); + reset_command_list(command_list, context.allocator); + + get_buffer_readback_with_command_list(heap_buffer, uav_desc.Format, &rb, queue, command_list); + /* Heap UAV was set. */ + value = get_readback_uint(&rb, 0, 0, 0); + todo + ok(value == 0xc0ffee, "Expected 0xc0ffee, got %08x for heap UAV.\n", value); + /* Root CBV was set. */ + value = get_readback_uint(&rb, 1, 0, 0); + todo + ok(value == cb_constant, "Expected %08x, got %08x for root CBV.\n", cb_constant, value); + /* Root SRV was set. */ + value = get_readback_uint(&rb, 2, 0, 0); + todo + ok(value == sr_data, "Expected %08x, got %08x for root SRV.\n", sr_data, value); + /* Root constants were set. */ + for (i = 0; i < ARRAY_SIZE(root_constants); ++i) + { + value = get_readback_uint(&rb, 3 + i, 0, 0); + todo + ok(value == root_constants[i], "Expected %08x, got %08x for root constant %u.\n", root_constants[i], value, i); + } + release_resource_readback(&rb); + + ID3D12Resource_Release(cb); + ID3D12Resource_Release(root_buffer); + ID3D12Resource_Release(heap_buffer); + ID3D12Resource_Release(sr_buffer); + ID3D12DescriptorHeap_Release(descriptor_heap); + destroy_bundle_context(&bundle_context); + destroy_test_context(&context); +} + static void test_shader_instructions(void) { struct named_shader @@ -34917,6 +35107,7 @@ START_TEST(d3d12) run_test(test_map_resource); run_test(test_map_placed_resources); run_test(test_bundle_state_inheritance); + run_test(test_compute_bundle); run_test(test_shader_instructions); run_test(test_compute_shader_instructions); run_test(test_discard_instruction);
Not tested: OMSetBlendFactor(), OMSetStencilRef(), and methods not implemented on our command list object.
Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- tests/d3d12.c | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index a838a9fb..fbb1781b 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -7778,6 +7778,255 @@ static void test_compute_bundle(void) destroy_test_context(&context); }
+static void test_graphics_bundle(void) +{ + ID3D12Resource *cb, *sr_buffer, *root_buffer, *heap_buffer, *vb, *ib; + ID3D12GraphicsCommandList *command_list, *bundle; + D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc; + ID3D12DescriptorHeap *descriptor_heap; + D3D12_DESCRIPTOR_HEAP_DESC heap_desc; + D3D12_INPUT_LAYOUT_DESC input_layout; + struct bundle_context bundle_context; + struct test_context_desc desc; + D3D12_VERTEX_BUFFER_VIEW vbv; + struct test_context context; + struct resource_readback rb; + D3D12_INDEX_BUFFER_VIEW ibv; + ID3D12CommandQueue *queue; + ID3D12Device *device; + unsigned int value; + HRESULT hr; + + static const D3D12_DESCRIPTOR_RANGE descriptor_ranges[] = + { + {D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 2, 0, 0}, + }; + + static const D3D12_ROOT_PARAMETER root_parameters[] = + { + {D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, + .DescriptorTable = {ARRAY_SIZE(descriptor_ranges), descriptor_ranges}}, + {D3D12_ROOT_PARAMETER_TYPE_CBV, .Descriptor = {0, 0}}, + {D3D12_ROOT_PARAMETER_TYPE_SRV, .Descriptor = {0, 0}}, + {D3D12_ROOT_PARAMETER_TYPE_UAV, .Descriptor = {1, 0}}, + {D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS, .Constants = {1, 0, 3}}, + }; + + static const D3D12_ROOT_SIGNATURE_DESC root_signature_desc = + { + .NumParameters = ARRAY_SIZE(root_parameters), + .pParameters = root_parameters, + .Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT, + }; + + static const DWORD vs_code[] = + { +#if 0 + void main(float4 in_position : POSITION, out float4 out_position : SV_POSITION) + { + out_position = in_position; + } +#endif + 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, + 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040, + 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, + 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE vs = {vs_code, sizeof(vs_code)}; + static const DWORD ps_code[] = + { +#if 0 + cbuffer cb0 : register(b0) + { + uint c0; + } + cbuffer cb1 : register(b1) + { + uint3 c1; + } + + ByteAddressBuffer t0 : register(t0); + + RWByteAddressBuffer u1 : register(u1); + RWByteAddressBuffer u2 : register(u2); + + void main(out float4 target : SV_Target0) + { + target = float4(1.0f, 1.0f, 1.0f, 1.0f); + if (c0 != 0x11111111) /* Test CBV. */ + target.x = 0.0f; + if (t0.Load(0) != 0x22222222) /* Test SRV. */ + target.x = 0.0f; + if (u1.Load(0) != 0xcafef00d) /* Test root UAV. */ + target.x = 0.0f; + if (u2.Load(0) != 0xc0ffee) /* Test heap UAV. */ + target.y = 0.0f; + if (c1.x != 0x33333333) /* Test setting one root constant. */ + target.z = 0.0f; + if (c1.z != 0x55555555) /* Test setting multiple root constants. */ + target.w = 0.0f; + } +#endif + 0x43425844, 0x01abdf56, 0xb7ffa3e4, 0x356ba2d5, 0xdc1e8864, 0x00000001, 0x000002a8, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000230, 0x00000050, 0x0000008c, + 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000059, 0x00208e46, 0x00000001, + 0x00000001, 0x030000a1, 0x00107000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0300009d, + 0x0011e000, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x890000a5, + 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x00107006, 0x00000000, + 0x07000027, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x22222222, 0x08000027, + 0x00100022, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x11111111, 0x0700003c, + 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x890000a5, 0x800002c2, + 0x00199983, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000001, 0x07000027, + 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xcafef00d, 0x0700003c, 0x00100012, + 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x09000037, 0x00102012, 0x00000000, + 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004001, 0x3f800000, 0x890000a5, 0x800002c2, + 0x00199983, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000002, 0x07000027, + 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00c0ffee, 0x09000037, 0x00102022, + 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004001, 0x3f800000, 0x0b000027, + 0x00100032, 0x00000000, 0x00208086, 0x00000001, 0x00000000, 0x00004002, 0x33333333, 0x55555555, + 0x00000000, 0x00000000, 0x0f000037, 0x001020c2, 0x00000000, 0x00100406, 0x00000000, 0x00004002, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, + 0x3f800000, 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE ps = {ps_code, sizeof(ps_code)}; + + static const D3D12_INPUT_ELEMENT_DESC layout_desc[] = + { + {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}, + }; + static const struct vec4 vertices[] = + { + {-1.0f, 1.0f, 0.00f, 1.00f}, + {-1.0f, 1.0f, 0.00f, 1.00f}, + { 3.0f, 1.0f, 0.00f, 1.00f}, + {-1.0f, -3.0f, 0.00f, 1.00f}, + }; + static const uint16_t indices[] = {0, 0, 1, 2}; + + static const float grey[] = {0.5f, 0.5f, 0.5f, 0.5f}; + static const uint32_t root_ua_data = 0xcafef00d; + static const uint32_t heap_ua_data = 0xc0ffee; + static const uint32_t cb_constant = 0x11111111; + static const uint32_t sr_data = 0x22222222; + static const uint32_t root_constants[] = {0x33333333, 0x44444444, 0x55555555}; + + memset(&desc, 0, sizeof(desc)); + desc.no_root_signature = true; + desc.no_pipeline = true; + if (!init_test_context(&context, &desc)) + return; + device = context.device; + command_list = context.list; + queue = context.queue; + init_bundle_context(device, &bundle_context); + bundle = bundle_context.list; + + hr = create_root_signature(device, &root_signature_desc, &context.root_signature); + ok(SUCCEEDED(hr), "Failed to create root signature, hr %#x.\n", hr); + + input_layout.pInputElementDescs = layout_desc; + input_layout.NumElements = ARRAY_SIZE(layout_desc); + context.pipeline_state = create_pipeline_state(device, + context.root_signature, context.render_target_desc.Format, &vs, &ps, &input_layout); + + cb = create_upload_buffer(device, sizeof(cb_constant), &cb_constant); + sr_buffer = create_upload_buffer(device, sizeof(sr_data), &sr_data); + + root_buffer = create_default_buffer(device, sizeof(root_ua_data), + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST); + upload_buffer_data(root_buffer, 0, sizeof(root_ua_data), &root_ua_data, queue, command_list); + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, root_buffer, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + + heap_buffer = create_default_buffer(device, sizeof(heap_ua_data), + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST); + upload_buffer_data(heap_buffer, 0, sizeof(heap_ua_data), &heap_ua_data, queue, command_list); + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, heap_buffer, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + + heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; + heap_desc.NumDescriptors = 1; + heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; + heap_desc.NodeMask = 0; + hr = ID3D12Device_CreateDescriptorHeap(device, &heap_desc, &IID_ID3D12DescriptorHeap, (void **)&descriptor_heap); + ok(SUCCEEDED(hr), "Failed to create descriptor heap, hr %#x.\n", hr); + + uav_desc.Format = DXGI_FORMAT_R32_TYPELESS; + uav_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; + uav_desc.Buffer.FirstElement = 0; + uav_desc.Buffer.NumElements = 1; + uav_desc.Buffer.StructureByteStride = 0; + uav_desc.Buffer.CounterOffsetInBytes = 0; + uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; + ID3D12Device_CreateUnorderedAccessView(device, heap_buffer, NULL, &uav_desc, + ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(descriptor_heap)); + + vb = create_upload_buffer(context.device, sizeof(vertices), vertices); + vbv.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(vb); + vbv.StrideInBytes = sizeof(*vertices); + vbv.SizeInBytes = sizeof(vertices); + + ib = create_upload_buffer(device, sizeof(indices), indices); + ibv.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(ib); + ibv.SizeInBytes = sizeof(indices); + ibv.Format = DXGI_FORMAT_R16_UINT; + + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, grey, 0, NULL); + + ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &descriptor_heap); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(bundle, context.root_signature); + /* Setting descriptor heaps in a bundle is valid if the heaps match those + * set in the executing command list. */ + ID3D12GraphicsCommandList_SetDescriptorHeaps(bundle, 1, &descriptor_heap); + ID3D12GraphicsCommandList_SetPipelineState(bundle, context.pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(bundle, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_IASetVertexBuffers(bundle, 0, 1, &vbv); + ID3D12GraphicsCommandList_IASetIndexBuffer(bundle, &ibv); + ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(bundle, 0, + ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(descriptor_heap)); + ID3D12GraphicsCommandList_SetGraphicsRootConstantBufferView(bundle, + 1, ID3D12Resource_GetGPUVirtualAddress(cb)); + ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(bundle, + 2, ID3D12Resource_GetGPUVirtualAddress(sr_buffer)); + ID3D12GraphicsCommandList_SetGraphicsRootUnorderedAccessView(bundle, + 3, ID3D12Resource_GetGPUVirtualAddress(root_buffer)); + ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstant(bundle, 4, root_constants[0], 0); + ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(bundle, 4, 2, &root_constants[1], 1); + ID3D12GraphicsCommandList_DrawIndexedInstanced(bundle, 3, 1, 1, 1, 0); + ID3D12GraphicsCommandList_Close(bundle); + + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, false, NULL); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_ExecuteBundle(command_list, bundle); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + + get_texture_readback_with_command_list(context.render_target, 0, &rb, queue, command_list); + value = get_readback_uint(&rb, 0, 0, 0); + todo + ok(value == 0xffffffff, "Expected 0xffffffff, got %08x.\n", value); + release_resource_readback(&rb); + + ID3D12Resource_Release(cb); + ID3D12Resource_Release(root_buffer); + ID3D12Resource_Release(heap_buffer); + ID3D12Resource_Release(sr_buffer); + ID3D12Resource_Release(vb); + ID3D12Resource_Release(ib); + ID3D12DescriptorHeap_Release(descriptor_heap); + destroy_bundle_context(&bundle_context); + destroy_test_context(&context); +} + static void test_shader_instructions(void) { struct named_shader @@ -35108,6 +35357,7 @@ START_TEST(d3d12) run_test(test_map_placed_resources); run_test(test_bundle_state_inheritance); run_test(test_compute_bundle); + run_test(test_graphics_bundle); run_test(test_shader_instructions); run_test(test_compute_shader_instructions); run_test(test_discard_instruction);