tests: Add test for descriptor tables.

This commit is contained in:
Józef Kucia 2017-08-04 17:06:33 +02:00
parent 074513dc4d
commit ba91aeb720
1 changed files with 221 additions and 0 deletions

View File

@ -224,6 +224,18 @@ static void exec_command_list(ID3D12CommandQueue *queue, ID3D12GraphicsCommandLi
ID3D12CommandQueue_ExecuteCommandLists(queue, 1, lists);
}
#define reset_command_list(a, b) reset_command_list_(__LINE__, a, b)
static void reset_command_list_(unsigned int line,
ID3D12GraphicsCommandList *list, ID3D12CommandAllocator *allocator)
{
HRESULT hr;
hr = ID3D12CommandAllocator_Reset(allocator);
ok_(line)(SUCCEEDED(hr), "Failed to reset command allocator, hr %#x.\n", hr);
hr = ID3D12GraphicsCommandList_Reset(list, allocator, NULL);
ok_(line)(SUCCEEDED(hr), "Failed to reset command list, hr %#x.\n", hr);
}
#ifdef _WIN32
static HANDLE create_event(void)
{
@ -7833,6 +7845,214 @@ static void test_texture(void)
destroy_test_context(&context);
}
static void test_descriptor_tables(void)
{
ID3D12DescriptorHeap *heap, *sampler_heap, *heaps[2];
D3D12_ROOT_SIGNATURE_DESC root_signature_desc;
D3D12_DESCRIPTOR_RANGE descriptor_range[4];
D3D12_CONSTANT_BUFFER_VIEW_DESC cbv_desc;
D3D12_ROOT_PARAMETER root_parameters[3];
ID3D12GraphicsCommandList *command_list;
D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle;
D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle;
D3D12_DESCRIPTOR_HEAP_DESC heap_desc;
ID3D12Resource *cb, *textures[4];
unsigned int i, descriptor_size;
D3D12_SAMPLER_DESC sampler_desc;
struct test_context_desc desc;
D3D12_SUBRESOURCE_DATA data;
struct test_context context;
ID3D12CommandQueue *queue;
HRESULT hr;
static const DWORD ps_code[] =
{
#if 0
Texture2D t0;
Texture2D t1;
Texture2D t2;
Texture2D t3;
SamplerState s0;
cbuffer cb0
{
float4 c;
};
float4 main(float4 position : SV_POSITION) : SV_Target
{
float2 p = float2(position.x / 32.0f, position.y / 32.0f);
return c.x * t0.Sample(s0, p) + c.y * t1.Sample(s0, p)
+ c.z * t2.Sample(s0, p) + c.w * t3.Sample(s0, p);
}
#endif
0x43425844, 0xf848ef5f, 0x4da3fe0c, 0x776883a0, 0x6b3f0297, 0x00000001, 0x0000029c, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000200, 0x00000050,
0x00000080, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001,
0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555, 0x04001858, 0x00107000, 0x00000003,
0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
0x02000068, 0x00000003, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
0x3d000000, 0x3d000000, 0x00000000, 0x00000000, 0x8b000045, 0x800000c2, 0x00155543, 0x001000f2,
0x00000001, 0x00100046, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x08000038,
0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208556, 0x00000000, 0x00000000, 0x8b000045,
0x800000c2, 0x00155543, 0x001000f2, 0x00000002, 0x00100046, 0x00000000, 0x00107e46, 0x00000000,
0x00106000, 0x00000000, 0x0a000032, 0x001000f2, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
0x00100e46, 0x00000002, 0x00100e46, 0x00000001, 0x8b000045, 0x800000c2, 0x00155543, 0x001000f2,
0x00000002, 0x00100046, 0x00000000, 0x00107e46, 0x00000002, 0x00106000, 0x00000000, 0x8b000045,
0x800000c2, 0x00155543, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000003,
0x00106000, 0x00000000, 0x0a000032, 0x001000f2, 0x00000001, 0x00208aa6, 0x00000000, 0x00000000,
0x00100e46, 0x00000002, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2, 0x00000000, 0x00208ff6,
0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
};
static const D3D12_SHADER_BYTECODE ps = {ps_code, sizeof(ps_code)};
static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
static const struct vec4 constant = {0.1f, 0.2f, 0.3f, 0.1f};
static const unsigned int texture_data[4] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffff00};
memset(&desc, 0, sizeof(desc));
desc.no_root_signature = true;
if (!init_test_context(&context, &desc))
return;
command_list = context.list;
queue = context.queue;
cb = create_upload_buffer(context.device, sizeof(constant), &constant.x);
descriptor_range[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
descriptor_range[0].NumDescriptors = 2;
descriptor_range[0].BaseShaderRegister = 0;
descriptor_range[0].RegisterSpace = 0;
descriptor_range[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_range[0];
root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
descriptor_range[1].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
descriptor_range[1].NumDescriptors = 1;
descriptor_range[1].BaseShaderRegister = 0;
descriptor_range[1].RegisterSpace = 0;
descriptor_range[1].OffsetInDescriptorsFromTableStart = 0;
root_parameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
root_parameters[1].DescriptorTable.NumDescriptorRanges = 1;
root_parameters[1].DescriptorTable.pDescriptorRanges = &descriptor_range[1];
root_parameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
descriptor_range[2].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
descriptor_range[2].NumDescriptors = 2;
descriptor_range[2].BaseShaderRegister = 2;
descriptor_range[2].RegisterSpace = 0;
descriptor_range[2].OffsetInDescriptorsFromTableStart = 0;
descriptor_range[3].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
descriptor_range[3].NumDescriptors = 1;
descriptor_range[3].BaseShaderRegister = 0;
descriptor_range[3].RegisterSpace = 0;
descriptor_range[3].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
root_parameters[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
root_parameters[2].DescriptorTable.NumDescriptorRanges = 2;
root_parameters[2].DescriptorTable.pDescriptorRanges = &descriptor_range[2];
root_parameters[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
memset(&root_signature_desc, 0, sizeof(root_signature_desc));
root_signature_desc.NumParameters = 3;
root_signature_desc.pParameters = root_parameters;
hr = create_root_signature(context.device, &root_signature_desc, &context.root_signature);
ok(SUCCEEDED(hr), "Failed to create root signature, hr %#x.\n", hr);
context.pipeline_state = create_pipeline_state(context.device,
context.root_signature, context.render_target_desc.Format, NULL, &ps, NULL);
memset(&sampler_desc, 0, sizeof(sampler_desc));
sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
sampler_desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
memset(&heap_desc, 0, sizeof(heap_desc));
heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
heap_desc.NumDescriptors = 5;
heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
hr = ID3D12Device_CreateDescriptorHeap(context.device, &heap_desc,
&IID_ID3D12DescriptorHeap, (void **)&heap);
ok(SUCCEEDED(hr), "Failed to create descriptor heap, hr %#x.\n", hr);
heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
heap_desc.NumDescriptors = 1;
hr = ID3D12Device_CreateDescriptorHeap(context.device, &heap_desc,
&IID_ID3D12DescriptorHeap, (void **)&sampler_heap);
ok(SUCCEEDED(hr), "Failed to create descriptor heap, hr %#x.\n", hr);
descriptor_size = ID3D12Device_GetDescriptorHandleIncrementSize(context.device,
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
for (i = 0; i < ARRAY_SIZE(textures); ++i)
{
textures[i] = create_texture(context.device,
1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_STATE_COPY_DEST);
data.pData = &texture_data[i];
data.RowPitch = sizeof(texture_data[i]);
data.SlicePitch = data.RowPitch;
upload_texture_data(textures[i], &data, queue, command_list);
reset_command_list(command_list, context.allocator);
}
for (i = 0; i < ARRAY_SIZE(textures); ++i)
transition_resource_state(command_list, textures[i],
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
cpu_handle = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap);
/* t0-t3 */
for (i = 0; i < ARRAY_SIZE(textures); ++i)
{
ID3D12Device_CreateShaderResourceView(context.device, textures[i], NULL, cpu_handle);
cpu_handle.ptr += descriptor_size;
}
/* cbv0 */
cbv_desc.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(cb);
cbv_desc.SizeInBytes = align(sizeof(constant), D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT);
ID3D12Device_CreateConstantBufferView(context.device, &cbv_desc, cpu_handle);
cpu_handle = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(sampler_heap);
/* s0 */
ID3D12Device_CreateSampler(context.device, &sampler_desc, cpu_handle);
gpu_handle = ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap);
ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 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);
heaps[0] = heap; heaps[1] = sampler_heap;
ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, ARRAY_SIZE(heaps), heaps);
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, 0, gpu_handle);
gpu_handle.ptr += 2 * descriptor_size;
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, 1,
ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(sampler_heap));
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, 2, gpu_handle);
ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport);
ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect);
ID3D12GraphicsCommandList_DrawInstanced(command_list, 3, 1, 0, 0);
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, 0xb2664c19, 2);
ID3D12Resource_Release(cb);
for (i = 0; i < ARRAY_SIZE(textures); ++i)
ID3D12Resource_Release(textures[i]);
ID3D12DescriptorHeap_Release(heap);
ID3D12DescriptorHeap_Release(sampler_heap);
destroy_test_context(&context);
}
#define check_copyable_footprints(a, b, c, d, e, f, g) \
check_copyable_footprints_(__LINE__, a, b, c, d, e, f, g)
static void check_copyable_footprints_(unsigned int line, const D3D12_RESOURCE_DESC *desc,
@ -8262,6 +8482,7 @@ START_TEST(d3d12)
run_test(test_immediate_constant_buffer);
run_test(test_root_constants);
run_test(test_texture);
run_test(test_descriptor_tables);
run_test(test_get_copyable_footprints);
run_test(test_typed_buffer_uav);
}