[PATCH vkd3d v2 6/6] tests: Add bundle tests for graphics pipelines.
Conor McCarthy
cmccarthy at codeweavers.com
Wed Sep 8 23:46:58 CDT 2021
Not tested: OMSetBlendFactor(), OMSetStencilRef(), and methods
not implemented on the vkd3d command list object.
Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
v2: Use check_sub_resource_uint().
Supersedes 213799.
---
tests/d3d12.c | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 244 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c
index eac95f69..744346e8 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -7775,6 +7775,249 @@ 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;
+ D3D12_INDEX_BUFFER_VIEW ibv;
+ ID3D12CommandQueue *queue;
+ ID3D12Device *device;
+ 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);
+ todo
+ check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xffffffff, 0);
+
+ 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
@@ -35430,6 +35673,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);
--
2.32.0
More information about the wine-devel
mailing list