tests: Add test for descriptors visibility.

This commit is contained in:
Józef Kucia 2017-09-22 16:42:07 +02:00
parent 5a020d6673
commit 2323c36fbd

View File

@ -10833,6 +10833,290 @@ static void test_copy_descriptors(void)
destroy_test_context(&context);
}
static void test_descriptors_visibility(void)
{
ID3D12Resource *vs_raw_buffer, *ps_raw_buffer;
D3D12_ROOT_SIGNATURE_DESC root_signature_desc;
D3D12_DESCRIPTOR_RANGE descriptor_ranges[2];
D3D12_STATIC_SAMPLER_DESC sampler_desc[2];
ID3D12Resource *vs_texture, *ps_texture;
ID3D12GraphicsCommandList *command_list;
D3D12_ROOT_PARAMETER root_parameters[6];
D3D12_DESCRIPTOR_HEAP_DESC heap_desc;
ID3D12Resource *vs_cb, *ps_cb;
struct test_context_desc desc;
D3D12_SUBRESOURCE_DATA data;
struct test_context context;
ID3D12DescriptorHeap *heap;
ID3D12CommandQueue *queue;
ID3D12Device *device;
HRESULT hr;
static const DWORD vs_code[] =
{
#if 0
ByteAddressBuffer b;
Texture2D t;
SamplerState s;
float4 cb;
float4 main(uint id : SV_VertexID) : SV_Position
{
float2 coords = float2((id << 1) & 2, id & 2);
uint i;
if (cb.x != 4.0 || cb.y != 8.0 || cb.z != 16.0 || cb.w != 32.0)
return (float4)0;
for (i = 0; i <= 6; ++i)
{
if (b.Load(4 * i) != i)
return (float4)0;
}
if (any(t.SampleLevel(s, (float2)0, 0) != float4(1.0, 1.0, 0.0, 1.0)))
return (float4)0;
return float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
}
#endif
0x43425844, 0x046e4d13, 0xd2103a18, 0x8576703b, 0x6f58933a, 0x00000001, 0x0000043c, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000003a0, 0x00010050,
0x000000e8, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
0x00000000, 0x030000a1, 0x00107000, 0x00000000, 0x04001858, 0x00107000, 0x00000001, 0x00005555,
0x04000060, 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
0x02000068, 0x00000002, 0x0b000039, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
0x00004002, 0x40800000, 0x41000000, 0x41800000, 0x42000000, 0x0700003c, 0x00100012, 0x00000000,
0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0700003c, 0x00100012, 0x00000000, 0x0010002a,
0x00000000, 0x0010000a, 0x00000000, 0x0700003c, 0x00100012, 0x00000000, 0x0010003a, 0x00000000,
0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e, 0x01000015, 0x05000036,
0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x0700004f, 0x00100022, 0x00000000,
0x00004001, 0x00000006, 0x0010000a, 0x00000000, 0x03040003, 0x0010001a, 0x00000000, 0x07000029,
0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x890000a5, 0x800002c2,
0x00199983, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00107006, 0x00000000, 0x07000027,
0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010001a,
0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x0100003e, 0x01000015, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
0x00004001, 0x00000001, 0x01000016, 0x90000048, 0x800000c2, 0x00155543, 0x001000f2, 0x00000000,
0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
0x00000000, 0x00004001, 0x00000000, 0x0a000039, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
0x00004002, 0x3f800000, 0x3f800000, 0x00000000, 0x3f800000, 0x0700003c, 0x00100032, 0x00000000,
0x00100ae6, 0x00000000, 0x00100046, 0x00000000, 0x0700003c, 0x00100012, 0x00000000, 0x0010001a,
0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e, 0x01000015,
0x0b00008c, 0x00100012, 0x00000000, 0x00004001, 0x00000001, 0x00004001, 0x00000001, 0x0010100a,
0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100022, 0x00000000, 0x0010100a, 0x00000000,
0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x0f000032,
0x00102032, 0x00000000, 0x00100046, 0x00000001, 0x00004002, 0x40000000, 0xc0000000, 0x00000000,
0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x001020c2,
0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
};
static const D3D12_SHADER_BYTECODE vs = {vs_code, sizeof(vs_code)};
static const DWORD ps_code[] =
{
#if 0
ByteAddressBuffer b;
Texture2D t;
SamplerState s;
float4 cb;
float4 main(float4 position : SV_POSITION) : SV_Target
{
if (cb.x != 1.0 || cb.y != 2.0 || cb.z != 3.0 || cb.w != 4.0)
return float4(1.0, 0.0, 0.0, 1.0);
if (b.Load(0) != 2 || b.Load(4) != 4 || b.Load(8) != 8)
return float4(1.0, 0.0, 0.0, 1.0);
return t.Sample(s, float2(position.x / 32.0, position.y / 32.0));
}
#endif
0x43425844, 0x1b1aafc1, 0xeab215f6, 0x77d65b25, 0x03cbe695, 0x00000001, 0x000002dc, 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, 0x00000240, 0x00000050,
0x00000090, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
0x00000000, 0x030000a1, 0x00107000, 0x00000000, 0x04001858, 0x00107000, 0x00000001, 0x00005555,
0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
0x00000001, 0x0b000039, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00004002,
0x3f800000, 0x40000000, 0x40400000, 0x40800000, 0x0700003c, 0x00100012, 0x00000000, 0x0010001a,
0x00000000, 0x0010000a, 0x00000000, 0x0700003c, 0x00100012, 0x00000000, 0x0010002a, 0x00000000,
0x0010000a, 0x00000000, 0x0700003c, 0x00100012, 0x00000000, 0x0010003a, 0x00000000, 0x0010000a,
0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x890000a5, 0x800002c2,
0x00199983, 0x00100072, 0x00000000, 0x00004001, 0x00000000, 0x00107246, 0x00000000, 0x0a000027,
0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000002, 0x00000004, 0x00000008,
0x00000000, 0x0700003c, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
0x0700003c, 0x00100012, 0x00000000, 0x0010002a, 0x00000000, 0x0010000a, 0x00000000, 0x0304001f,
0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000,
0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0a000038, 0x00100032, 0x00000000, 0x00101046,
0x00000000, 0x00004002, 0x3d000000, 0x3d000000, 0x00000000, 0x00000000, 0x8b000045, 0x800000c2,
0x00155543, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
};
static const D3D12_SHADER_BYTECODE ps = {ps_code, sizeof(ps_code)};
static const struct vec4 vs_cb_data = {4.0f, 8.0f, 16.0f, 32.0f};
static const struct vec4 ps_cb_data = {1.0f, 2.0f, 3.0f, 4.0f};
static const uint32_t vs_buffer_data[] = {0, 1, 2, 3, 4, 5, 6};
static const uint32_t ps_buffer_data[] = {2, 4, 8};
static const float vs_texture_data[] = {1.0f, 1.0f, 0.0f, 1.0f};
static const float ps_texture_data[] = {0.0f, 1.0f, 0.0f, 1.0f};
static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
memset(&desc, 0, sizeof(desc));
desc.no_root_signature = true;
if (!init_test_context(&context, &desc))
return;
device = context.device;
command_list = context.list;
queue = context.queue;
sampler_desc[0].Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
sampler_desc[0].AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
sampler_desc[0].AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
sampler_desc[0].AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
sampler_desc[0].MipLODBias = 0.0f;
sampler_desc[0].MaxAnisotropy = 0;
sampler_desc[0].ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
sampler_desc[0].BorderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE;
sampler_desc[0].MinLOD = 0.0f;
sampler_desc[0].MaxLOD = 0.0f;
sampler_desc[0].ShaderRegister = 0;
sampler_desc[0].RegisterSpace = 0;
sampler_desc[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX;
sampler_desc[1] = sampler_desc[0];
sampler_desc[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
root_parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
root_parameters[0].Descriptor.ShaderRegister = 0;
root_parameters[0].Descriptor.RegisterSpace = 0;
root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX;
root_parameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
root_parameters[1].Descriptor.ShaderRegister = 0;
root_parameters[1].Descriptor.RegisterSpace = 0;
root_parameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
root_parameters[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
root_parameters[2].Descriptor.ShaderRegister = 0;
root_parameters[2].Descriptor.RegisterSpace = 0;
root_parameters[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX;
root_parameters[3].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
root_parameters[3].Descriptor.ShaderRegister = 0;
root_parameters[3].Descriptor.RegisterSpace = 0;
root_parameters[3].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
descriptor_ranges[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
descriptor_ranges[0].NumDescriptors = 1;
descriptor_ranges[0].BaseShaderRegister = 1;
descriptor_ranges[0].RegisterSpace = 0;
descriptor_ranges[0].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
root_parameters[4].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
root_parameters[4].DescriptorTable.NumDescriptorRanges = 1;
root_parameters[4].DescriptorTable.pDescriptorRanges = &descriptor_ranges[0];
root_parameters[4].ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX;
descriptor_ranges[1].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
descriptor_ranges[1].NumDescriptors = 1;
descriptor_ranges[1].BaseShaderRegister = 1;
descriptor_ranges[1].RegisterSpace = 0;
descriptor_ranges[1].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
root_parameters[5].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
root_parameters[5].DescriptorTable.NumDescriptorRanges = 1;
root_parameters[5].DescriptorTable.pDescriptorRanges = &descriptor_ranges[1];
root_parameters[5].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
memset(&root_signature_desc, 0, sizeof(root_signature_desc));
root_signature_desc.NumParameters = 6;
root_signature_desc.pParameters = root_parameters;
root_signature_desc.NumStaticSamplers = 2;
root_signature_desc.pStaticSamplers = sampler_desc;
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_pipeline_state(device,
context.root_signature, context.render_target_desc.Format,
&vs, &ps, NULL);
vs_cb = create_upload_buffer(device, sizeof(vs_cb_data), &vs_cb_data);
ps_cb = create_upload_buffer(device, sizeof(ps_cb_data), &ps_cb_data);
vs_raw_buffer = create_upload_buffer(device, sizeof(vs_buffer_data), vs_buffer_data);
ps_raw_buffer = create_upload_buffer(device, sizeof(ps_buffer_data), ps_buffer_data);
vs_texture = create_texture(device,
1, 1, DXGI_FORMAT_R32G32B32A32_FLOAT, D3D12_RESOURCE_STATE_COPY_DEST);
data.pData = vs_texture_data;
data.RowPitch = sizeof(vs_texture_data);
data.SlicePitch = data.RowPitch;
upload_texture_data(vs_texture, &data, 1, queue, command_list);
reset_command_list(command_list, context.allocator);
transition_resource_state(command_list, vs_texture,
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
ps_texture = create_texture(device,
1, 1, DXGI_FORMAT_R32G32B32A32_FLOAT, D3D12_RESOURCE_STATE_COPY_DEST);
data.pData = ps_texture_data;
data.RowPitch = sizeof(ps_texture_data);
data.SlicePitch = data.RowPitch;
upload_texture_data(ps_texture, &data, 1, queue, command_list);
reset_command_list(command_list, context.allocator);
transition_resource_state(command_list, ps_texture,
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
memset(&heap_desc, 0, sizeof(heap_desc));
heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
heap_desc.NumDescriptors = 2;
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);
ID3D12Device_CreateShaderResourceView(device, vs_texture, NULL,
get_cpu_descriptor_handle(&context, heap, 0));
ID3D12Device_CreateShaderResourceView(device, ps_texture, NULL,
get_cpu_descriptor_handle(&context, heap, 1));
ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature);
ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &heap);
ID3D12GraphicsCommandList_SetGraphicsRootConstantBufferView(command_list,
0, ID3D12Resource_GetGPUVirtualAddress(vs_cb));
ID3D12GraphicsCommandList_SetGraphicsRootConstantBufferView(command_list,
1, ID3D12Resource_GetGPUVirtualAddress(ps_cb));
ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(command_list,
2, ID3D12Resource_GetGPUVirtualAddress(vs_raw_buffer));
ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(command_list,
3, ID3D12Resource_GetGPUVirtualAddress(ps_raw_buffer));
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list,
4, get_gpu_descriptor_handle(&context, heap, 0));
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list,
5, get_gpu_descriptor_handle(&context, heap, 1));
ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state);
ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL);
ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport);
ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect);
ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL);
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, 0xff00ff00, 0);
ID3D12Resource_Release(vs_cb);
ID3D12Resource_Release(ps_cb);
ID3D12Resource_Release(vs_texture);
ID3D12Resource_Release(ps_texture);
ID3D12Resource_Release(vs_raw_buffer);
ID3D12Resource_Release(ps_raw_buffer);
ID3D12DescriptorHeap_Release(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,
@ -15394,6 +15678,7 @@ START_TEST(d3d12)
run_test(test_update_descriptor_heap_after_closing_command_list);
run_test(test_update_compute_descriptor_tables);
run_test(test_copy_descriptors);
run_test(test_descriptors_visibility);
run_test(test_get_copyable_footprints);
run_test(test_depth_stencil_sampling);
run_test(test_typed_buffer_uav);