From: Conor McCarthy cmccarthy@codeweavers.com
--- Makefile.am | 1 + tests/shader_runner.c | 73 ++++++++++++++++++++++++++++++++++++ tests/shader_runner.h | 6 +++ tests/shader_runner_d3d11.c | 68 ++++++++++++++++++++++++++++++--- tests/shader_runner_d3d12.c | 45 ++++++++++++++++++++-- tests/shader_runner_vulkan.c | 31 ++++++++++++--- 6 files changed, 210 insertions(+), 14 deletions(-)
diff --git a/Makefile.am b/Makefile.am index 68e8642e0..9380af450 100644 --- a/Makefile.am +++ b/Makefile.am @@ -197,6 +197,7 @@ vkd3d_shader_tests = \ tests/hlsl/swizzle-matrix.shader_test \ tests/hlsl/swizzles.shader_test \ tests/hlsl/ternary.shader_test \ + tests/hlsl/tessellation.shader_test \ tests/hlsl/texture-load-offset.shader_test \ tests/hlsl/texture-load-typed.shader_test \ tests/hlsl/texture-load.shader_test \ diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 5eafbcbe4..c3aa05395 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -107,6 +107,10 @@ enum parse_state STATE_SHADER_VERTEX_TODO, STATE_SHADER_EFFECT, STATE_SHADER_EFFECT_TODO, + STATE_SHADER_HULL, + STATE_SHADER_HULL_TODO, + STATE_SHADER_DOMAIN, + STATE_SHADER_DOMAIN_TODO, STATE_TEST, };
@@ -320,6 +324,10 @@ static void parse_require_directive(struct shader_runner *runner, const char *li runner->compile_options |= options[i].option; } } + else if (match_string(line, "tessellation", &line)) + { + runner->require_tessellation = true; + } else if (match_string(line, "float64", &line)) { runner->require_float64 = true; @@ -887,6 +895,14 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; else if (match_string(line, "triangle strip", &line)) topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; + else if (match_string(line, "1 control point patch list", &line)) + topology = D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST; + else if (match_string(line, "2 control point patch list", &line)) + topology = D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST; + else if (match_string(line, "3 control point patch list", &line)) + topology = D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST; + else if (match_string(line, "4 control point patch list", &line)) + topology = D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST; else fatal_error("Unknown primitive topology '%s'.\n", line);
@@ -1204,6 +1220,8 @@ const char *shader_type_string(enum shader_type type) [SHADER_TYPE_CS] = "cs", [SHADER_TYPE_PS] = "ps", [SHADER_TYPE_VS] = "vs", + [SHADER_TYPE_HS] = "hs", + [SHADER_TYPE_DS] = "ds", [SHADER_TYPE_FX] = "fx", }; assert(type < ARRAY_SIZE(shader_types)); @@ -1265,6 +1283,8 @@ HRESULT dxc_compiler_compile_shader(void *dxc_compiler, enum shader_type type, u [SHADER_TYPE_CS] = L"cs_6_0", [SHADER_TYPE_PS] = L"ps_6_0", [SHADER_TYPE_VS] = L"vs_6_0", + [SHADER_TYPE_HS] = L"hs_6_0", + [SHADER_TYPE_DS] = L"ds_6_0", }; const WCHAR *args[] = { @@ -1392,6 +1412,10 @@ static enum parse_state get_parse_state_todo(enum parse_state state) return STATE_SHADER_PIXEL_TODO; else if (state == STATE_SHADER_VERTEX) return STATE_SHADER_VERTEX_TODO; + else if (state == STATE_SHADER_HULL) + return STATE_SHADER_HULL_TODO; + else if (state == STATE_SHADER_DOMAIN) + return STATE_SHADER_DOMAIN_TODO; else return STATE_SHADER_EFFECT_TODO; } @@ -1435,6 +1459,8 @@ static bool check_requirements(const struct shader_runner *runner, const struct { if (runner->maximum_shader_model < runner->minimum_shader_model) return false; + if (runner->require_tessellation && !caps->tessellation) + return false; if (runner->require_float64 && !caps->float64) return false; if (runner->require_int64 && !caps->int64) @@ -1612,6 +1638,36 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c shader_source_size = 0; break;
+ case STATE_SHADER_HULL: + case STATE_SHADER_HULL_TODO: + if (!skip_tests) + { + todo_if (state == STATE_SHADER_HULL_TODO) + compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_HS, + expect_hr); + } + free(runner->hs_source); + runner->hs_source = shader_source; + shader_source = NULL; + shader_source_len = 0; + shader_source_size = 0; + break; + + case STATE_SHADER_DOMAIN: + case STATE_SHADER_DOMAIN_TODO: + if (!skip_tests) + { + todo_if (state == STATE_SHADER_DOMAIN_TODO) + compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_DS, + expect_hr); + } + free(runner->ds_source); + runner->ds_source = shader_source; + shader_source = NULL; + shader_source_len = 0; + shader_source_size = 0; + break; + case STATE_PREPROC_INVALID: { ID3D10Blob *blob = NULL, *errors = NULL; @@ -1690,6 +1746,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c state = STATE_REQUIRE; runner->minimum_shader_model = caps->minimum_shader_model; runner->maximum_shader_model = caps->maximum_shader_model; + runner->require_tessellation = false; runner->require_float64 = false; runner->require_int64 = false; runner->require_rov = false; @@ -1794,6 +1851,18 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c expect_hr = S_OK; state = read_shader_directive(runner, state, line_buffer, line, &expect_hr); } + else if (match_directive_substring(line, "[hull shader", &line)) + { + state = STATE_SHADER_HULL; + expect_hr = S_OK; + state = read_shader_directive(runner, state, line_buffer, line, &expect_hr); + } + else if (match_directive_substring(line, "[domain shader", &line)) + { + state = STATE_SHADER_DOMAIN; + expect_hr = S_OK; + state = read_shader_directive(runner, state, line_buffer, line, &expect_hr); + } else if (!strcmp(line, "[input layout]\n")) { state = STATE_INPUT_LAYOUT; @@ -1825,6 +1894,10 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c case STATE_SHADER_VERTEX_TODO: case STATE_SHADER_EFFECT: case STATE_SHADER_EFFECT_TODO: + case STATE_SHADER_HULL: + case STATE_SHADER_HULL_TODO: + case STATE_SHADER_DOMAIN: + case STATE_SHADER_DOMAIN_TODO: { size_t len = strlen(line);
diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 2f7e8fb25..8497c0961 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -45,6 +45,8 @@ enum shader_type SHADER_TYPE_CS, SHADER_TYPE_PS, SHADER_TYPE_VS, + SHADER_TYPE_HS, + SHADER_TYPE_DS, SHADER_TYPE_FX, };
@@ -129,6 +131,7 @@ struct shader_runner_caps size_t tag_count; enum shader_model minimum_shader_model; enum shader_model maximum_shader_model; + bool tessellation; bool float64; bool int64; bool rov; @@ -157,8 +160,11 @@ struct shader_runner char *ps_source; char *cs_source; char *fx_source; + char *hs_source; + char *ds_source; enum shader_model minimum_shader_model; enum shader_model maximum_shader_model; + bool require_tessellation; /* For the GL runner, until HLSL compiler support is added. */ bool require_float64; bool require_int64; bool require_rov; diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 1285ca41f..b1df14aaa 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -273,6 +273,7 @@ static BOOL init_test_context(struct d3d11_shader_runner *runner) runner->caps.runner = "d3d11.dll"; runner->caps.minimum_shader_model = SHADER_MODEL_4_0; runner->caps.maximum_shader_model = SHADER_MODEL_5_1; + runner->caps.tessellation = true;
hr = ID3D11Device_CheckFeatureSupport(runner->device, D3D11_FEATURE_DOUBLES, &doubles, sizeof(doubles)); @@ -589,27 +590,52 @@ static bool d3d11_runner_draw(struct shader_runner *r, { ID3D11UnorderedAccessView *uavs[D3D11_PS_CS_UAV_REGISTER_COUNT] = {0}; ID3D11RenderTargetView *rtvs[D3D11_PS_CS_UAV_REGISTER_COUNT] = {0}; + ID3D10Blob *vs_code, *ps_code, *hs_code = NULL, *ds_code = NULL; struct d3d11_shader_runner *runner = d3d11_shader_runner(r); ID3D11DeviceContext *context = runner->immediate_context; unsigned int min_uav_slot = ARRAY_SIZE(uavs); ID3D11Device *device = runner->device; - ID3D10Blob *vs_code, *ps_code; unsigned int rtv_count = 0; ID3D11Buffer *cb = NULL; ID3D11VertexShader *vs; + ID3D11DomainShader *ds; ID3D11PixelShader *ps; + ID3D11HullShader *hs; + bool succeeded; unsigned int i; HRESULT hr;
- if (!(vs_code = compile_shader(runner, runner->r.vs_source, "vs"))) - return false; + vs_code = compile_shader(runner, runner->r.vs_source, "vs"); + ps_code = compile_shader(runner, runner->r.ps_source, "ps"); + succeeded = vs_code && ps_code;
- if (!(ps_code = compile_shader(runner, runner->r.ps_source, "ps"))) + if (runner->r.hs_source) + { + hs_code = compile_shader(runner, runner->r.hs_source, "hs"); + succeeded = succeeded && hs_code; + } + if (runner->r.ds_source) { - ID3D10Blob_Release(vs_code); + ds_code = compile_shader(runner, runner->r.ds_source, "ds"); + succeeded = succeeded && ds_code; + } + + if (!succeeded) + { + if (ps_code) + ID3D10Blob_Release(ps_code); + if (vs_code) + ID3D10Blob_Release(vs_code); + if (hs_code) + ID3D10Blob_Release(hs_code); + if (ds_code) + ID3D10Blob_Release(ds_code); return false; }
+ if (!hs_code != !ds_code) + fatal_error("Have a domain or hull shader but not both.\n"); + hr = ID3D11Device_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code), ID3D10Blob_GetBufferSize(vs_code), NULL, &vs); ok(hr == S_OK, "Failed to create vertex shader, hr %#lx.\n", hr); @@ -618,12 +644,36 @@ static bool d3d11_runner_draw(struct shader_runner *r, ID3D10Blob_GetBufferSize(ps_code), NULL, &ps); ok(hr == S_OK, "Failed to create pixel shader, hr %#lx.\n", hr);
+ if (hs_code) + { + hr = ID3D11Device_CreateHullShader(device, ID3D10Blob_GetBufferPointer(hs_code), + ID3D10Blob_GetBufferSize(hs_code), NULL, &hs); + ok(hr == S_OK, "Failed to create hull shader, hr %#lx.\n", hr); + } + if (ds_code) + { + hr = ID3D11Device_CreateDomainShader(device, ID3D10Blob_GetBufferPointer(ds_code), + ID3D10Blob_GetBufferSize(ds_code), NULL, &ds); + ok(hr == S_OK, "Failed to create domain shader, hr %#lx.\n", hr); + } + + ID3D10Blob_Release(ps_code); + ID3D10Blob_Release(vs_code); + if (hs_code) + ID3D10Blob_Release(hs_code); + if (ds_code) + ID3D10Blob_Release(ds_code); + if (runner->r.uniform_count) { cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, runner->r.uniform_count * sizeof(*runner->r.uniforms), 0, runner->r.uniforms); ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb); ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb); + if (hs_code) + ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb); + if (ds_code) + ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &cb); }
for (i = 0; i < runner->r.resource_count; ++i) @@ -697,12 +747,20 @@ static bool d3d11_runner_draw(struct shader_runner *r, ID3D11DeviceContext_IASetPrimitiveTopology(context, primitive_topology); ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0); ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + if (hs_code) + ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0); + if (ds_code) + ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0); ID3D11DeviceContext_RSSetState(context, runner->rasterizer_state);
ID3D11DeviceContext_Draw(context, vertex_count, 0);
ID3D11PixelShader_Release(ps); ID3D11VertexShader_Release(vs); + if (hs_code) + ID3D11HullShader_Release(hs); + if (ds_code) + ID3D11DomainShader_Release(ds); if (cb) ID3D11Buffer_Release(cb);
diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 9bf7bb248..e82a11c6d 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -434,32 +434,53 @@ static bool d3d12_runner_draw(struct shader_runner *r, struct test_context *test_context = &runner->test_context;
D3D12_CPU_DESCRIPTOR_HANDLE rtvs[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0}; + ID3D10Blob *vs_code, *ps_code, *hs_code = NULL, *ds_code = NULL; ID3D12GraphicsCommandList *command_list = test_context->list; D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = {0}; ID3D12CommandQueue *queue = test_context->queue; D3D12_INPUT_ELEMENT_DESC *input_element_descs; ID3D12Device *device = test_context->device; - ID3D10Blob *vs_code, *ps_code; unsigned int uniform_index; unsigned int rtv_count = 0; ID3D12PipelineState *pso; + bool succeeded; HRESULT hr; size_t i;
ps_code = compile_shader(runner, runner->r.ps_source, SHADER_TYPE_PS); vs_code = compile_shader(runner, runner->r.vs_source, SHADER_TYPE_VS); + succeeded = ps_code && vs_code; + + if (runner->r.hs_source) + { + hs_code = compile_shader(runner, runner->r.hs_source, SHADER_TYPE_HS); + succeeded = succeeded && hs_code; + } + if (runner->r.ds_source) + { + ds_code = compile_shader(runner, runner->r.ds_source, SHADER_TYPE_DS); + succeeded = succeeded && ds_code; + } + todo_if(runner->r.is_todo && runner->r.minimum_shader_model < SHADER_MODEL_6_0) - ok(ps_code && vs_code, "Failed to compile shaders.\n"); + ok(succeeded, "Failed to compile shaders.\n");
- if (!ps_code || !vs_code) + if (!succeeded) { if (ps_code) ID3D10Blob_Release(ps_code); if (vs_code) ID3D10Blob_Release(vs_code); + if (hs_code) + ID3D10Blob_Release(hs_code); + if (ds_code) + ID3D10Blob_Release(ds_code); return false; }
+ if (!hs_code != !ds_code) + fatal_error("Have a domain or hull shader but not both.\n"); + if (test_context->root_signature) ID3D12RootSignature_Release(test_context->root_signature); test_context->root_signature = d3d12_runner_create_root_signature(runner, @@ -481,9 +502,20 @@ static bool d3d12_runner_draw(struct shader_runner *r, pso_desc.VS.BytecodeLength = ID3D10Blob_GetBufferSize(vs_code); pso_desc.PS.pShaderBytecode = ID3D10Blob_GetBufferPointer(ps_code); pso_desc.PS.BytecodeLength = ID3D10Blob_GetBufferSize(ps_code); + if (hs_code) + { + pso_desc.HS.pShaderBytecode = ID3D10Blob_GetBufferPointer(hs_code); + pso_desc.HS.BytecodeLength = ID3D10Blob_GetBufferSize(hs_code); + pso_desc.DS.pShaderBytecode = ID3D10Blob_GetBufferPointer(ds_code); + pso_desc.DS.BytecodeLength = ID3D10Blob_GetBufferSize(ds_code); + pso_desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH; + } + else + { + pso_desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; + } pso_desc.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID; pso_desc.RasterizerState.CullMode = D3D12_CULL_MODE_NONE; - pso_desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; pso_desc.SampleDesc.Count = 1; pso_desc.SampleMask = ~(UINT)0; pso_desc.pRootSignature = test_context->root_signature; @@ -510,6 +542,10 @@ static bool d3d12_runner_draw(struct shader_runner *r, todo_if(runner->r.is_todo) ok(hr == S_OK, "Failed to create state, hr %#x.\n", hr); ID3D10Blob_Release(vs_code); ID3D10Blob_Release(ps_code); + if (hs_code) + ID3D10Blob_Release(hs_code); + if (ds_code) + ID3D10Blob_Release(ds_code); free(input_element_descs);
if (FAILED(hr)) @@ -632,6 +668,7 @@ static void d3d12_runner_init_caps(struct d3d12_shader_runner *runner) #endif runner->caps.minimum_shader_model = SHADER_MODEL_4_0; runner->caps.maximum_shader_model = SHADER_MODEL_5_1; + runner->caps.tessellation = true; runner->caps.float64 = options.DoublePrecisionFloatShaderOps; runner->caps.int64 = options1.Int64ShaderOps; runner->caps.rov = options.ROVsSupported; diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index a3bbf170c..353998bb5 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -683,9 +683,10 @@ static VkPipeline create_graphics_pipeline(struct vulkan_shader_runner *runner, static const VkRect2D rt_rect = {.extent.width = RENDER_TARGET_WIDTH, .extent.height = RENDER_TARGET_HEIGHT}; VkGraphicsPipelineCreateInfo pipeline_desc = {.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; VkPipelineColorBlendAttachmentState attachment_desc[MAX_RESOURCES] = {0}; + VkPipelineTessellationStateCreateInfo tessellation_info; VkVertexInputAttributeDescription input_attributes[32]; VkVertexInputBindingDescription input_bindings[32]; - VkPipelineShaderStageCreateInfo stage_desc[2]; + VkPipelineShaderStageCreateInfo stage_desc[4]; struct vkd3d_shader_code vs_dxbc; VkDevice device = runner->device; VkPipeline pipeline; @@ -696,11 +697,20 @@ static VkPipeline create_graphics_pipeline(struct vulkan_shader_runner *runner, memset(stage_desc, 0, sizeof(stage_desc)); ret = create_shader_stage(runner, &stage_desc[0], "vs", VK_SHADER_STAGE_VERTEX_BIT, runner->r.vs_source, &vs_dxbc) && create_shader_stage(runner, &stage_desc[1], "ps", VK_SHADER_STAGE_FRAGMENT_BIT, runner->r.ps_source, NULL); + + if (!runner->r.hs_source != !runner->r.ds_source) + fatal_error("Have a domain or hull shader but not both.\n"); + + if (runner->r.hs_source) + { + ret &= create_shader_stage(runner, &stage_desc[1], "hs", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, runner->r.hs_source, NULL); + ret &= create_shader_stage(runner, &stage_desc[2], "ds", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, runner->r.ds_source, NULL); + } todo_if (runner->r.is_todo) ok(ret, "Failed to compile shaders.\n"); if (!ret) { - VK_CALL(vkDestroyShaderModule(device, stage_desc[0].module, NULL)); - VK_CALL(vkDestroyShaderModule(device, stage_desc[1].module, NULL)); + for (i = 0; i < ARRAY_SIZE(stage_desc); ++i) + VK_CALL(vkDestroyShaderModule(device, stage_desc[i].module, NULL)); return VK_NULL_HANDLE; }
@@ -791,11 +801,21 @@ static VkPipeline create_graphics_pipeline(struct vulkan_shader_runner *runner, pipeline_desc.renderPass = render_pass; pipeline_desc.subpass = 0;
+ if (runner->r.hs_source) + { + tessellation_info.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; + tessellation_info.pNext = NULL; + tessellation_info.flags = 0; + tessellation_info.patchControlPoints + = max(primitive_topology - D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + 1, 1); + pipeline_desc.pTessellationState = &tessellation_info; + } + vr = VK_CALL(vkCreateGraphicsPipelines(runner->device, VK_NULL_HANDLE, 1, &pipeline_desc, NULL, &pipeline)); ok(vr == VK_SUCCESS, "Failed to create graphics pipeline, vr %d.\n", vr);
- VK_CALL(vkDestroyShaderModule(device, stage_desc[0].module, NULL)); - VK_CALL(vkDestroyShaderModule(device, stage_desc[1].module, NULL)); + for (i = 0; i < ARRAY_SIZE(stage_desc); ++i) + VK_CALL(vkDestroyShaderModule(device, stage_desc[i].module, NULL)); vkd3d_shader_free_scan_signature_info(&runner->vs_signatures); vkd3d_shader_free_shader_code(&vs_dxbc);
@@ -1495,6 +1515,7 @@ static bool init_vulkan_runner(struct vulkan_shader_runner *runner) }
runner->caps.runner = "Vulkan"; + runner->caps.tessellation = true; get_physical_device_info(runner, &device_info); ret_features = &device_info.features2.features;