From: Jactry Zeng Subject: [PATCH vkd3d] tests: Add tests for sample_b instruction. Message-Id: <2ae8bb31-f857-9a35-c8e5-8826252f2437@codeweavers.com> Date: Wed, 17 Jul 2019 16:46:41 +0800 Signed-off-by: Jactry Zeng --- tests/d3d12.c | 310 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 310 insertions(+) diff --git a/tests/d3d12.c b/tests/d3d12.c index bd055fb..72951c9 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -31335,6 +31335,315 @@ static void test_conditional_rendering(void) destroy_test_context(&context); } +static void test_sample_b(void) +{ + static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f}; + ID3D12GraphicsCommandList *command_list; + D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle; + D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle; + D3D12_STATIC_SAMPLER_DESC sampler_desc; + struct test_context_desc desc; + struct resource_readback rb; + struct test_context context; + unsigned int x_step, y_step; + ID3D12DescriptorHeap *heap; + ID3D12CommandQueue *queue; + ID3D12Resource *texture; + ID3D12Device *device; + unsigned int i, x, y; + float constant; + static const DWORD ps_sample_code[] = + { +#if 0 + Texture2D t; + SamplerState s; + + float bias; + + float4 main(float4 position : SV_POSITION) : SV_Target + { + float2 p; + + p.x = position.x / 640.0f; + p.y = position.y / 480.0f; + return t.SampleBias(s, p, bias); + } +#endif + 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 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, 0x52444853, 0x000000b4, 0x00000040, + 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000, + 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, + 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000, + 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a, + 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, + 0x0020800a, 0x00000000, 0x00000000, 0x0100003e, + }; + static const D3D12_SHADER_BYTECODE ps_sample = {ps_sample_code, sizeof(ps_sample_code)}; + static const unsigned int r8g8b8a8_data[] = + { + 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00, + 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f, + 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000, + 0xffffffff, 0xff000000, 0xff000000, 0xff000000, + }; + static const uint8_t a8_data[] = + { + 0x00, 0xff, 0x7f, 0xf0, + 0x0f, 0x11, 0x00, 0x00, + 0xff, 0xf0, 0x0f, 0xff, + 0xfa, 0xfe, 0xaa, 0xcc, + }; + static const unsigned int a8_expected_data[] = + { + 0x00000000, 0xff000000, 0x7f000000, 0xf0000000, + 0x0f000000, 0x11000000, 0x00000000, 0x00000000, + 0xff000000, 0xf0000000, 0x0f000000, 0xff000000, + 0xfa000000, 0xfe000000, 0xaa000000, 0xcc000000, + }; + static const unsigned int rgba_level_0[] = + { + 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00, + 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f, + 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000, + 0xffffffff, 0xff000000, 0xff000000, 0xff000000, + }; + static const unsigned int rgba_level_1[] = + { + 0xffffffff, 0xff0000ff, + 0xff000000, 0xff00ff00, + }; + static const unsigned int rgba_level_2[] = + { + 0xffff0000, + }; + static const unsigned int level_1_colors[] = + { + 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff, + 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff, + 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00, + 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00, + }; + static const unsigned int level_2_colors[] = + { + 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, + 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, + 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, + 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, + }; + static const struct + { + unsigned int width; + unsigned int height; + unsigned int miplevel_count; + unsigned int array_size; + float lod_bias; + float min_lod; + float max_lod; + float ps_constant; + DXGI_FORMAT format; + D3D12_SUBRESOURCE_DATA data[3]; + const unsigned int *expected_data; + } + tests[] = + { + { + 4, 4, 1, 1, 0.0f, 0.0f, D3D12_FLOAT32_MAX, 0.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {r8g8b8a8_data, 4 * sizeof(*r8g8b8a8_data), 16 * sizeof(*r8g8b8a8_data)}, + }, + r8g8b8a8_data, + }, + { + 4, 4, 1, 1, 0.0f, 0.0f, D3D12_FLOAT32_MAX, 0.0f, DXGI_FORMAT_A8_UNORM, + { + {a8_data, 4 * sizeof(*a8_data), 16 * sizeof(*a8_data)}, + }, + a8_expected_data, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, D3D12_FLOAT32_MAX, 0.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + rgba_level_0, + }, + { + 4, 4, 3, 1, 8.0f, 0.0f, D3D12_FLOAT32_MAX, 0.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + level_1_colors, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, D3D12_FLOAT32_MAX, 8.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + level_1_colors, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, D3D12_FLOAT32_MAX, 8.4f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + level_1_colors, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, D3D12_FLOAT32_MAX, 8.5f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + level_2_colors, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, D3D12_FLOAT32_MAX, 9.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + level_2_colors, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, 2.0f, 1.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + rgba_level_0, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, 2.0f, 9.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + level_2_colors, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, 1.0f, 9.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + level_1_colors, + }, + { + 4, 4, 3, 1, 0.0f, 0.0f, 0.0f, 9.0f, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + }, + rgba_level_0, + }, + }; + + memset(&desc, 0, sizeof(desc)); + desc.rt_width = 640.0f; + desc.rt_height = 480.0f; + desc.no_root_signature = true; + if (!init_test_context(&context, &desc)) + return; + device = context.device; + command_list = context.list; + queue = context.queue; + + heap = create_gpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1); + cpu_handle = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap); + gpu_handle = ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(heap); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + vkd3d_test_set_context("Test %u", i); + + 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; + sampler_desc.MipLODBias = tests[i].lod_bias; + sampler_desc.MinLOD = tests[i].min_lod; + sampler_desc.MaxLOD = tests[i].max_lod; + context.root_signature = create_texture_root_signature_(__LINE__, context.device, + D3D12_SHADER_VISIBILITY_PIXEL, 1, 0, &sampler_desc); + context.pipeline_state = create_pipeline_state(device, context.root_signature, + context.render_target_desc.Format, NULL, &ps_sample, NULL); + + texture = create_default_texture2d(device, tests[i].width, tests[i].height, tests[i].array_size, + tests[i].miplevel_count, tests[i].format, D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COPY_DEST); + upload_texture_data(texture, tests[i].data, tests[i].miplevel_count * tests[i].array_size, + queue, command_list); + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, texture, + D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); + + ID3D12Device_CreateShaderResourceView(device, texture, NULL, cpu_handle); + + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, red, 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); + ID3D12GraphicsCommandList_SetDescriptorHeaps(command_list, 1, &heap); + ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(command_list, 0, 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); + constant = tests[i].ps_constant; + ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(command_list, 1, 1, &constant, 0); + 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); + + x_step = desc.rt_width / tests[i].width; + y_step = desc.rt_height / tests[i].height; + get_texture_readback_with_command_list(context.render_target, 0, &rb, queue, command_list); + for (y = 0; y < tests[i].height; ++y) + { + for (x = 0; x < tests[i].width; ++x) + { + unsigned int color = get_readback_uint(&rb, x * x_step + x_step / 2, y * y_step + y_step / 2, 0); + ok(compare_color(color, tests[i].expected_data[tests[i].width * y + x], 0), + "Got color 0x%08x, expected 0x%08x at (%u, %u).\n", + color, tests[i].expected_data[tests[i].width * y + x], x, y); + } + } + release_resource_readback(&rb); + + ID3D12Resource_Release(texture); + reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + + ID3D12PipelineState_Release(context.pipeline_state); + context.pipeline_state = NULL; + ID3D12RootSignature_Release(context.root_signature); + context.root_signature = NULL; + } + vkd3d_test_set_context(NULL); + + ID3D12DescriptorHeap_Release(heap); + destroy_test_context(&context); +} + START_TEST(d3d12) { parse_args(argc, argv); @@ -31496,4 +31805,5 @@ START_TEST(d3d12) run_test(test_graphics_compute_queue_synchronization); run_test(test_early_depth_stencil_tests); run_test(test_conditional_rendering); + run_test(test_sample_b); } -- 2.20.1