[PATCH vkd3d v2 5/6] tests: Add bundle tests for compute pipelines.

Conor McCarthy cmccarthy at codeweavers.com
Wed Sep 8 23:46:57 CDT 2021


Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
v2: Use check_buffer_uint() and check_readback_data_uint().
Supersedes 213798.
---
 tests/d3d12.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 188 insertions(+)

diff --git a/tests/d3d12.c b/tests/d3d12.c
index 66b28c4f..eac95f69 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -7588,6 +7588,193 @@ 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;
+    D3D12_BOX box = {0, 0, 0, 1, 1, 1};
+    struct test_context_desc desc;
+    struct test_context context;
+    struct resource_readback rb;
+    ID3D12CommandQueue *queue;
+    ID3D12Device *device;
+    unsigned int i;
+    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. */
+    todo
+    check_buffer_uint(root_buffer, queue, command_list, 0xcafef00d, 0);
+    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. */
+    todo
+    check_readback_data_uint(&rb, &box, 0xc0ffee, 0);
+    /* Root CBV was set. */
+    ++box.left; ++box.right;
+    todo
+    check_readback_data_uint(&rb, &box, cb_constant, 0);
+    /* Root SRV was set. */
+    ++box.left; ++box.right;
+    todo
+    check_readback_data_uint(&rb, &box, sr_data, 0);
+    /* Root constants were set. */
+    for (i = 0; i < ARRAY_SIZE(root_constants); ++i)
+    {
+        ++box.left; ++box.right;
+        todo
+        check_readback_data_uint(&rb, &box, root_constants[i], 0);
+    }
+    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
@@ -35242,6 +35429,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);
-- 
2.32.0




More information about the wine-devel mailing list