tests/shader_runner: Use ID3D12Device2_CreatePipelineState() when available.

This commit is contained in:
Anna (navi) Figueiredo Gomes 2024-08-31 17:57:38 +02:00 committed by Henri Verbeet
parent 04d7ad90e5
commit 12a7cde092
Notes: Henri Verbeet 2024-09-11 15:31:24 +02:00
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1031
3 changed files with 291 additions and 123 deletions

View File

@ -3467,114 +3467,6 @@ static void test_create_pipeline_state(void)
" return float4(1.0f, 1.0f, 1.0f, 1.0f);\n" " return float4(1.0f, 1.0f, 1.0f, 1.0f);\n"
"}\n"; "}\n";
struct d3d12_root_signature_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
ID3D12RootSignature *root_signature;
};
struct d3d12_shader_bytecode_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_SHADER_BYTECODE shader_bytecode;
};
struct d3d12_stream_output_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_STREAM_OUTPUT_DESC stream_output_desc;
};
struct d3d12_blend_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_BLEND_DESC blend_desc;
};
struct d3d12_sample_mask_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
UINT sample_mask;
};
struct d3d12_rasterizer_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_RASTERIZER_DESC rasterizer_desc;
};
struct d3d12_depth_stencil_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_DEPTH_STENCIL_DESC depth_stencil_desc;
};
struct d3d12_input_layout_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_INPUT_LAYOUT_DESC input_layout;
};
struct d3d12_ib_strip_cut_value_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_INDEX_BUFFER_STRIP_CUT_VALUE strip_cut_value;
};
struct d3d12_primitive_topology_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_PRIMITIVE_TOPOLOGY_TYPE primitive_topology_type;
};
struct d3d12_render_target_formats_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
struct D3D12_RT_FORMAT_ARRAY render_target_formats;
};
struct d3d12_depth_stencil_format_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
DXGI_FORMAT depth_stencil_format;
};
struct d3d12_sample_desc_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
DXGI_SAMPLE_DESC sample_desc;
};
struct d3d12_node_mask_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
UINT node_mask;
};
struct d3d12_cached_pso_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_CACHED_PIPELINE_STATE cached_pso;
};
struct d3d12_flags_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_PIPELINE_STATE_FLAGS flags;
};
struct d3d12_depth_stencil1_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_DEPTH_STENCIL_DESC1 depth_stencil_desc;
};
struct d3d12_view_instancing_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_VIEW_INSTANCING_DESC view_instancing_desc;
};
static const struct d3d12_root_signature_subobject root_signature_subobject = static const struct d3d12_root_signature_subobject root_signature_subobject =
{ {
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE,

View File

@ -21,6 +21,114 @@
#include "utils.h" #include "utils.h"
struct d3d12_root_signature_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
ID3D12RootSignature *root_signature;
};
struct d3d12_shader_bytecode_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_SHADER_BYTECODE shader_bytecode;
};
struct d3d12_stream_output_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_STREAM_OUTPUT_DESC stream_output_desc;
};
struct d3d12_blend_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_BLEND_DESC blend_desc;
};
struct d3d12_sample_mask_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
UINT sample_mask;
};
struct d3d12_rasterizer_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_RASTERIZER_DESC rasterizer_desc;
};
struct d3d12_depth_stencil_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_DEPTH_STENCIL_DESC depth_stencil_desc;
};
struct d3d12_input_layout_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_INPUT_LAYOUT_DESC input_layout;
};
struct d3d12_ib_strip_cut_value_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_INDEX_BUFFER_STRIP_CUT_VALUE strip_cut_value;
};
struct d3d12_primitive_topology_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_PRIMITIVE_TOPOLOGY_TYPE primitive_topology_type;
};
struct d3d12_render_target_formats_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
struct D3D12_RT_FORMAT_ARRAY render_target_formats;
};
struct d3d12_depth_stencil_format_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
DXGI_FORMAT depth_stencil_format;
};
struct d3d12_sample_desc_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
DXGI_SAMPLE_DESC sample_desc;
};
struct d3d12_node_mask_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
UINT node_mask;
};
struct d3d12_cached_pso_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_CACHED_PIPELINE_STATE cached_pso;
};
struct d3d12_flags_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_PIPELINE_STATE_FLAGS flags;
};
struct d3d12_depth_stencil1_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_DEPTH_STENCIL_DESC1 depth_stencil_desc;
};
struct d3d12_view_instancing_subobject
{
DECLSPEC_ALIGN(sizeof(void *)) D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type;
D3D12_VIEW_INSTANCING_DESC view_instancing_desc;
};
#define wait_queue_idle(a, b) wait_queue_idle_(__LINE__, a, b) #define wait_queue_idle(a, b) wait_queue_idle_(__LINE__, a, b)
static void wait_queue_idle_(unsigned int line, ID3D12Device *device, ID3D12CommandQueue *queue); static void wait_queue_idle_(unsigned int line, ID3D12Device *device, ID3D12CommandQueue *queue);
static ID3D12Device *create_device(void); static ID3D12Device *create_device(void);
@ -1015,6 +1123,7 @@ struct test_context_desc
struct test_context struct test_context
{ {
ID3D12Device *device; ID3D12Device *device;
ID3D12Device2 *device2;
ID3D12CommandQueue *queue; ID3D12CommandQueue *queue;
ID3D12CommandAllocator *allocator; ID3D12CommandAllocator *allocator;
@ -1127,6 +1236,9 @@ static inline bool init_test_context_(unsigned int line, struct test_context *co
} }
device = context->device; device = context->device;
if (FAILED(hr = ID3D12Device_QueryInterface(device, &IID_ID3D12Device2, (void **)&context->device2)))
context->device2 = NULL;
context->queue = create_command_queue_(line, device, D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_QUEUE_PRIORITY_NORMAL); context->queue = create_command_queue_(line, device, D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_QUEUE_PRIORITY_NORMAL);
hr = ID3D12Device_CreateCommandAllocator(device, D3D12_COMMAND_LIST_TYPE_DIRECT, hr = ID3D12Device_CreateCommandAllocator(device, D3D12_COMMAND_LIST_TYPE_DIRECT,
@ -1232,6 +1344,9 @@ static inline void destroy_test_context_(unsigned int line, struct test_context
destroy_pipeline_state_objects(context); destroy_pipeline_state_objects(context);
free(context->pso); free(context->pso);
if (context->device2)
ID3D12Device2_Release(context->device2);
refcount = ID3D12Device_Release(context->device); refcount = ID3D12Device_Release(context->device);
ok_(line)(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount); ok_(line)(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
} }

View File

@ -521,6 +521,25 @@ static D3D12_PRIMITIVE_TOPOLOGY_TYPE d3d12_primitive_topology_type_from_primitiv
} }
} }
static D3D12_INPUT_ELEMENT_DESC *create_element_descs(const struct d3d12_shader_runner *runner)
{
D3D12_INPUT_ELEMENT_DESC *input_element_descs = calloc(runner->r.input_element_count, sizeof(*input_element_descs));
for (size_t i = 0; i < runner->r.input_element_count; ++i)
{
const struct input_element *element = &runner->r.input_elements[i];
D3D12_INPUT_ELEMENT_DESC *desc = &input_element_descs[i];
desc->SemanticName = element->name;
desc->SemanticIndex = element->index;
desc->Format = element->format;
desc->InputSlot = element->slot;
desc->AlignedByteOffset = D3D12_APPEND_ALIGNED_ELEMENT;
desc->InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
}
return input_element_descs;
}
static ID3D12PipelineState *create_pipeline(struct d3d12_shader_runner *runner, static ID3D12PipelineState *create_pipeline(struct d3d12_shader_runner *runner,
D3D12_PRIMITIVE_TOPOLOGY primitive_topology, ID3D10Blob *vs_code, ID3D10Blob *ps_code, D3D12_PRIMITIVE_TOPOLOGY primitive_topology, ID3D10Blob *vs_code, ID3D10Blob *ps_code,
ID3D10Blob *hs_code, ID3D10Blob *ds_code, ID3D10Blob *gs_code) ID3D10Blob *hs_code, ID3D10Blob *ds_code, ID3D10Blob *gs_code)
@ -581,20 +600,7 @@ static ID3D12PipelineState *create_pipeline(struct d3d12_shader_runner *runner,
pso_desc.SampleMask = runner->r.sample_mask ? runner->r.sample_mask : ~(UINT)0; pso_desc.SampleMask = runner->r.sample_mask ? runner->r.sample_mask : ~(UINT)0;
pso_desc.pRootSignature = test_context->root_signature; pso_desc.pRootSignature = test_context->root_signature;
input_element_descs = calloc(runner->r.input_element_count, sizeof(*input_element_descs)); input_element_descs = create_element_descs(runner);
for (size_t i = 0; i < runner->r.input_element_count; ++i)
{
const struct input_element *element = &runner->r.input_elements[i];
D3D12_INPUT_ELEMENT_DESC *desc = &input_element_descs[i];
desc->SemanticName = element->name;
desc->SemanticIndex = element->index;
desc->Format = element->format;
desc->InputSlot = element->slot;
desc->AlignedByteOffset = D3D12_APPEND_ALIGNED_ELEMENT;
desc->InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
}
pso_desc.InputLayout.pInputElementDescs = input_element_descs; pso_desc.InputLayout.pInputElementDescs = input_element_descs;
pso_desc.InputLayout.NumElements = runner->r.input_element_count; pso_desc.InputLayout.NumElements = runner->r.input_element_count;
@ -610,6 +616,159 @@ static ID3D12PipelineState *create_pipeline(struct d3d12_shader_runner *runner,
return pso; return pso;
} }
static ID3D12PipelineState *create_pipeline_device2(struct d3d12_shader_runner *runner,
D3D12_PRIMITIVE_TOPOLOGY primitive_topology, ID3D10Blob *vs_code, ID3D10Blob *ps_code,
ID3D10Blob *hs_code, ID3D10Blob *ds_code, ID3D10Blob *gs_code)
{
struct test_context *test_context = &runner->test_context;
ID3D12Device2 *device2 = test_context->device2;
D3D12_PIPELINE_STATE_STREAM_DESC pipeline_desc;
D3D12_INPUT_ELEMENT_DESC *input_element_descs;
unsigned int sample_count = 1;
ID3D12PipelineState *pso;
HRESULT hr;
struct
{
struct d3d12_root_signature_subobject root_signature;
struct d3d12_shader_bytecode_subobject vs;
struct d3d12_shader_bytecode_subobject ps;
struct d3d12_shader_bytecode_subobject hs;
struct d3d12_shader_bytecode_subobject ds;
struct d3d12_shader_bytecode_subobject gs;
struct d3d12_render_target_formats_subobject rtv_format;
struct d3d12_blend_subobject blend;
struct d3d12_depth_stencil_format_subobject dsv_format;
struct d3d12_depth_stencil1_subobject dsv;
struct d3d12_rasterizer_subobject rasterizer;
struct d3d12_primitive_topology_subobject topology;
struct d3d12_sample_desc_subobject sample_desc;
struct d3d12_sample_mask_subobject sample_mask;
struct d3d12_input_layout_subobject input_layout;
}
pipeline =
{
.root_signature =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE,
.root_signature = test_context->root_signature,
},
.vs =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS,
.shader_bytecode = shader_bytecode_from_blob(vs_code),
},
.ps =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS,
.shader_bytecode = shader_bytecode_from_blob(ps_code),
},
.hs =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS,
.shader_bytecode = hs_code ? shader_bytecode_from_blob(hs_code) : (D3D12_SHADER_BYTECODE) {0},
},
.ds =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS,
.shader_bytecode = ds_code ? shader_bytecode_from_blob(ds_code) : (D3D12_SHADER_BYTECODE) {0},
},
.gs =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS,
.shader_bytecode = gs_code ? shader_bytecode_from_blob(gs_code) : (D3D12_SHADER_BYTECODE) {0},
},
.rtv_format =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS,
},
.blend =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND,
},
.dsv_format =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT,
},
.dsv =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1,
},
.rasterizer =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER,
.rasterizer_desc =
{
.FillMode = D3D12_FILL_MODE_SOLID,
.CullMode = D3D12_CULL_MODE_NONE,
}
},
.topology =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY,
.primitive_topology_type = d3d12_primitive_topology_type_from_primitive_topology(primitive_topology),
},
.sample_desc =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC,
},
.sample_mask =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK,
.sample_mask = runner->r.sample_mask ? runner->r.sample_mask : ~(UINT)0,
},
.input_layout =
{
.type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT,
},
};
if (!device2)
return NULL;
input_element_descs = create_element_descs(runner);
pipeline.input_layout.input_layout.NumElements = runner->r.input_element_count;
pipeline.input_layout.input_layout.pInputElementDescs = input_element_descs;
for (size_t i = 0; i < runner->r.resource_count; ++i)
{
struct d3d12_resource *resource = d3d12_resource(runner->r.resources[i]);
if (resource->r.desc.type == RESOURCE_TYPE_RENDER_TARGET)
{
pipeline.rtv_format.render_target_formats.RTFormats[resource->r.desc.slot] = resource->r.desc.format;
pipeline.rtv_format.render_target_formats.NumRenderTargets =
max(pipeline.rtv_format.render_target_formats.NumRenderTargets, resource->r.desc.slot + 1);
pipeline.blend.blend_desc.RenderTarget[resource->r.desc.slot].RenderTargetWriteMask =
D3D12_COLOR_WRITE_ENABLE_ALL;
if (resource->r.desc.sample_count)
sample_count = resource->r.desc.sample_count;
}
else if (resource->r.desc.type == RESOURCE_TYPE_DEPTH_STENCIL)
{
assert(!resource->r.desc.slot);
pipeline.dsv_format.depth_stencil_format = resource->r.desc.format;
pipeline.dsv.depth_stencil_desc.DepthEnable = true;
pipeline.dsv.depth_stencil_desc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
pipeline.dsv.depth_stencil_desc.DepthFunc = runner->r.depth_func;
}
}
pipeline.sample_desc.sample_desc.Count = sample_count;
pipeline_desc.SizeInBytes = sizeof(pipeline);
pipeline_desc.pPipelineStateSubobjectStream = &pipeline;
hr = ID3D12Device2_CreatePipelineState(device2, &pipeline_desc, &IID_ID3D12PipelineState, (void **)&pso);
todo_if(runner->r.is_todo) ok(hr == S_OK, "Failed to create state, hr %#x.\n", hr);
free(input_element_descs);
if (FAILED(hr))
return NULL;
return pso;
}
static bool d3d12_runner_draw(struct shader_runner *r, static bool d3d12_runner_draw(struct shader_runner *r,
D3D_PRIMITIVE_TOPOLOGY primitive_topology, unsigned int vertex_count, unsigned int instance_count) D3D_PRIMITIVE_TOPOLOGY primitive_topology, unsigned int vertex_count, unsigned int instance_count)
{ {
@ -671,7 +830,9 @@ static bool d3d12_runner_draw(struct shader_runner *r,
test_context->root_signature = d3d12_runner_create_root_signature(runner, test_context->root_signature = d3d12_runner_create_root_signature(runner,
queue, test_context->allocator, command_list, &uniform_index); queue, test_context->allocator, command_list, &uniform_index);
pso = create_pipeline(runner, primitive_topology, vs_code, ps_code, hs_code, ds_code, gs_code); pso = test_context->device2
? create_pipeline_device2(runner, primitive_topology, vs_code, ps_code, hs_code, ds_code, gs_code)
: create_pipeline(runner, primitive_topology, vs_code, ps_code, hs_code, ds_code, gs_code);
ID3D10Blob_Release(vs_code); ID3D10Blob_Release(vs_code);
ID3D10Blob_Release(ps_code); ID3D10Blob_Release(ps_code);