mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
tests: Add test for GPU virtual addresses.
This commit is contained in:
parent
4d7a86295d
commit
6478dea0d1
161
tests/d3d12.c
161
tests/d3d12.c
@ -712,6 +712,36 @@ static void release_resource_readback(struct resource_readback *rb)
|
||||
ID3D12Resource_Release(rb->resource);
|
||||
}
|
||||
|
||||
#define check_sub_resource_uint(a, b, c, d, e, f) check_sub_resource_uint_(__LINE__, a, b, c, d, e, f)
|
||||
static void check_sub_resource_uint_(unsigned int line, ID3D12Resource *texture,
|
||||
unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list,
|
||||
unsigned int expected, unsigned int max_diff)
|
||||
{
|
||||
struct resource_readback rb;
|
||||
unsigned int x = 0, y;
|
||||
bool all_match = true;
|
||||
unsigned int got = 0;
|
||||
|
||||
get_texture_readback_with_command_list(texture, 0, &rb, queue, command_list);
|
||||
for (y = 0; y < rb.height; ++y)
|
||||
{
|
||||
for (x = 0; x < rb.width; ++x)
|
||||
{
|
||||
got = get_readback_uint(&rb, x, y);
|
||||
if (!compare_color(got, expected, max_diff))
|
||||
{
|
||||
all_match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!all_match)
|
||||
break;
|
||||
}
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ok_(line)(all_match, "Got 0x%08x, expected 0x%08x at (%u, %u).\n", got, expected, x, y);
|
||||
}
|
||||
|
||||
#define check_sub_resource_vec4(a, b, c, d, e, f) check_sub_resource_vec4_(__LINE__, a, b, c, d, e, f)
|
||||
static void check_sub_resource_vec4_(unsigned int line, ID3D12Resource *texture,
|
||||
unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list,
|
||||
@ -739,7 +769,7 @@ static void check_sub_resource_vec4_(unsigned int line, ID3D12Resource *texture,
|
||||
}
|
||||
release_resource_readback(&rb);
|
||||
|
||||
ok_(line)(all_match, "Got {%.8e, %.8e, %.8e, %.8e} expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
|
||||
ok_(line)(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
|
||||
got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
|
||||
}
|
||||
|
||||
@ -3202,6 +3232,134 @@ static void test_draw_indexed_instanced(void)
|
||||
destroy_test_context(&context);
|
||||
}
|
||||
|
||||
static void test_gpu_virtual_address(void)
|
||||
{
|
||||
D3D12_GPU_VIRTUAL_ADDRESS vb_offset, ib_offset;
|
||||
ID3D12GraphicsCommandList *command_list;
|
||||
D3D12_INPUT_LAYOUT_DESC input_layout;
|
||||
struct test_context_desc desc;
|
||||
D3D12_VERTEX_BUFFER_VIEW vbv;
|
||||
struct test_context context;
|
||||
D3D12_INDEX_BUFFER_VIEW ibv;
|
||||
ID3D12CommandQueue *queue;
|
||||
ID3D12Resource *buffer;
|
||||
HRESULT hr;
|
||||
BYTE *ptr;
|
||||
|
||||
static const DWORD vs_code[] =
|
||||
{
|
||||
#if 0
|
||||
void main(float4 in_position : POSITION, float4 in_color : COLOR,
|
||||
out float4 out_position : SV_POSITION, out float4 out_color : COLOR)
|
||||
{
|
||||
out_position = in_position;
|
||||
out_color = in_color;
|
||||
}
|
||||
#endif
|
||||
0x43425844, 0xa58fc911, 0x280038e9, 0x14cfff54, 0xe43fc328, 0x00000001, 0x00000144, 0x00000003,
|
||||
0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
|
||||
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
|
||||
0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
|
||||
0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
|
||||
0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
|
||||
0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x0000006c, 0x00010050, 0x0000001b,
|
||||
0x0100086a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
|
||||
0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
|
||||
0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
|
||||
0x0100003e,
|
||||
};
|
||||
static const D3D12_SHADER_BYTECODE vs = {vs_code, sizeof(vs_code)};
|
||||
static const DWORD ps_code[] =
|
||||
{
|
||||
#if 0
|
||||
void main(float4 in_position : SV_POSITION, float4 in_color : COLOR,
|
||||
out float4 out_color : SV_TARGET)
|
||||
{
|
||||
out_color = in_color;
|
||||
}
|
||||
#endif
|
||||
0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
|
||||
0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
|
||||
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
|
||||
0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
|
||||
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
|
||||
0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
|
||||
0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
|
||||
0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 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 uint32_t indices[] = {0, 1, 2, 3};
|
||||
static const D3D12_INPUT_ELEMENT_DESC layout_desc[] =
|
||||
{
|
||||
{"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
|
||||
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 8, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
|
||||
};
|
||||
static const struct
|
||||
{
|
||||
struct vec2 position;
|
||||
struct vec4 color;
|
||||
}
|
||||
quad[] =
|
||||
{
|
||||
{{-1.0f, -1.0f}, {0.0f, 1.0f, 0.0f, 1.0f}},
|
||||
{{-1.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f}},
|
||||
{{ 1.0f, -1.0f}, {0.0f, 1.0f, 0.0f, 1.0f}},
|
||||
{{ 1.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f}},
|
||||
};
|
||||
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.no_root_signature = true;
|
||||
if (!init_test_context(&context, &desc))
|
||||
return;
|
||||
command_list = context.list;
|
||||
queue = context.queue;
|
||||
|
||||
context.root_signature = create_empty_root_signature(context.device,
|
||||
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
|
||||
input_layout.pInputElementDescs = layout_desc;
|
||||
input_layout.NumElements = ARRAY_SIZE(layout_desc);
|
||||
context.pipeline_state = create_pipeline_state(context.device,
|
||||
context.root_signature, context.render_target_desc.Format, &vs, &ps, &input_layout);
|
||||
|
||||
vb_offset = 0x200;
|
||||
ib_offset = 0x500;
|
||||
buffer = create_upload_buffer(context.device, ib_offset + sizeof(indices), NULL);
|
||||
|
||||
hr = ID3D12Resource_Map(buffer, 0, NULL, (void **)&ptr);
|
||||
ok(SUCCEEDED(hr), "Failed to map upload buffer, hr %#x.\n", hr);
|
||||
memcpy(ptr + vb_offset, quad, sizeof(quad));
|
||||
memcpy(ptr + ib_offset, indices, sizeof(indices));
|
||||
ID3D12Resource_Unmap(buffer, 0, NULL);
|
||||
|
||||
vbv.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(buffer) + vb_offset;
|
||||
vbv.StrideInBytes = sizeof(*quad);
|
||||
vbv.SizeInBytes = sizeof(quad);
|
||||
ibv.BufferLocation = ID3D12Resource_GetGPUVirtualAddress(buffer) + ib_offset;
|
||||
ibv.SizeInBytes = sizeof(indices);
|
||||
ibv.Format = DXGI_FORMAT_R32_UINT;
|
||||
|
||||
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);
|
||||
ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 0, 1, &vbv);
|
||||
ID3D12GraphicsCommandList_IASetIndexBuffer(command_list, &ibv);
|
||||
ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport);
|
||||
ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect);
|
||||
ID3D12GraphicsCommandList_DrawIndexedInstanced(command_list, 4, 1, 0, 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(buffer);
|
||||
destroy_test_context(&context);
|
||||
}
|
||||
|
||||
static void test_fragment_coords(void)
|
||||
{
|
||||
static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
@ -7288,6 +7446,7 @@ START_TEST(d3d12)
|
||||
run_test(test_clear_render_target_view);
|
||||
run_test(test_draw_instanced);
|
||||
run_test(test_draw_indexed_instanced);
|
||||
run_test(test_gpu_virtual_address);
|
||||
run_test(test_fragment_coords);
|
||||
run_test(test_fractional_viewports);
|
||||
run_test(test_scissor);
|
||||
|
Loading…
Reference in New Issue
Block a user