diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 0b570c27..3a5a9d30 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -958,7 +958,7 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) " return pos;\n" "}"; - if (!runner->hs_source != !runner->ds_source) + if (!runner->shader_source[SHADER_TYPE_HS] != !runner->shader_source[SHADER_TYPE_DS]) fatal_error("Have a domain or hull shader but not both.\n"); set_default_target(runner); @@ -987,8 +987,8 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) set_resource(runner, ¶ms); free(params.data); - if (!runner->vs_source) - runner->vs_source = strdup(vs_source); + if (!runner->shader_source[SHADER_TYPE_VS]) + runner->shader_source[SHADER_TYPE_VS] = strdup(vs_source); runner->sample_count = 1; for (i = 0; i < runner->resource_count; ++i) @@ -1005,7 +1005,7 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) unsigned int vertex_count, instance_count; D3D_PRIMITIVE_TOPOLOGY topology; - if (!runner->hs_source != !runner->ds_source) + if (!runner->shader_source[SHADER_TYPE_HS] != !runner->shader_source[SHADER_TYPE_DS]) fatal_error("Have a domain or hull shader but not both.\n"); set_default_target(runner); @@ -1823,8 +1823,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_CS, expect_hr); } - free(runner->cs_source); - runner->cs_source = shader_source; + free(runner->shader_source[SHADER_TYPE_CS]); + runner->shader_source[SHADER_TYPE_CS] = shader_source; shader_source = NULL; shader_source_len = 0; shader_source_size = 0; @@ -1838,8 +1838,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_PS, expect_hr); } - free(runner->ps_source); - runner->ps_source = shader_source; + free(runner->shader_source[SHADER_TYPE_PS]); + runner->shader_source[SHADER_TYPE_PS] = shader_source; shader_source = NULL; shader_source_len = 0; shader_source_size = 0; @@ -1853,8 +1853,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_VS, expect_hr); } - free(runner->vs_source); - runner->vs_source = shader_source; + free(runner->shader_source[SHADER_TYPE_VS]); + runner->shader_source[SHADER_TYPE_VS] = shader_source; shader_source = NULL; shader_source_len = 0; shader_source_size = 0; @@ -1868,8 +1868,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_FX, expect_hr); } - free(runner->fx_source); - runner->fx_source = shader_source; + free(runner->shader_source[SHADER_TYPE_FX]); + runner->shader_source[SHADER_TYPE_FX] = shader_source; shader_source = NULL; shader_source_len = 0; shader_source_size = 0; @@ -1883,8 +1883,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_HS, expect_hr); } - free(runner->hs_source); - runner->hs_source = shader_source; + free(runner->shader_source[SHADER_TYPE_HS]); + runner->shader_source[SHADER_TYPE_HS] = shader_source; shader_source = NULL; shader_source_len = 0; shader_source_size = 0; @@ -1898,8 +1898,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_DS, expect_hr); } - free(runner->ds_source); - runner->ds_source = shader_source; + free(runner->shader_source[SHADER_TYPE_DS]); + runner->shader_source[SHADER_TYPE_DS] = shader_source; shader_source = NULL; shader_source_len = 0; shader_source_size = 0; @@ -1913,8 +1913,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_GS, expect_hr); } - free(runner->gs_source); - runner->gs_source = shader_source; + free(runner->shader_source[SHADER_TYPE_GS]); + runner->shader_source[SHADER_TYPE_GS] = shader_source; shader_source = NULL; shader_source_len = 0; shader_source_size = 0; @@ -2212,13 +2212,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c for (i = 0; i < runner->input_element_count; ++i) free(runner->input_elements[i].name); free(runner->input_elements); - free(runner->vs_source); - free(runner->ps_source); - free(runner->cs_source); - free(runner->hs_source); - free(runner->ds_source); - free(runner->gs_source); - free(runner->fx_source); + for (i = 0; i < SHADER_TYPE_COUNT; ++i) + free(runner->shader_source[i]); free(runner->uniforms); for (i = 0; i < runner->resource_count; ++i) { diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 58fb2dba..ee05595b 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -49,6 +49,7 @@ enum shader_type SHADER_TYPE_DS, SHADER_TYPE_GS, SHADER_TYPE_FX, + SHADER_TYPE_COUNT, }; const char *shader_type_string(enum shader_type type); @@ -179,13 +180,7 @@ struct shader_runner bool is_todo; - char *vs_source; - char *ps_source; - char *cs_source; - char *fx_source; - char *hs_source; - char *ds_source; - char *gs_source; + char *shader_source[SHADER_TYPE_COUNT]; enum shader_model minimum_shader_model; enum shader_model maximum_shader_model; bool require_shader_caps[SHADER_CAP_COUNT]; diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 91d816ce..d4c51a04 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -75,8 +75,9 @@ static struct d3d11_shader_runner *d3d11_shader_runner(struct shader_runner *r) return CONTAINING_RECORD(r, struct d3d11_shader_runner, r); } -static ID3D10Blob *compile_shader(const struct d3d11_shader_runner *runner, const char *source, const char *type) +static ID3D10Blob *compile_shader(const struct d3d11_shader_runner *runner, enum shader_type type) { + const char *source = runner->r.shader_source[type]; ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; HRESULT hr; @@ -91,7 +92,7 @@ static ID3D10Blob *compile_shader(const struct d3d11_shader_runner *runner, cons [SHADER_MODEL_5_1] = "5_1", }; - sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]); + sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->r.minimum_shader_model]); hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, runner->r.compile_options, 0, &blob, &errors); ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr); if (errors) @@ -613,7 +614,7 @@ static bool d3d11_runner_dispatch(struct shader_runner *r, unsigned int x, unsig HRESULT hr; size_t i; - if (!(cs_code = compile_shader(runner, runner->r.cs_source, "cs"))) + if (!(cs_code = compile_shader(runner, SHADER_TYPE_CS))) return false; hr = ID3D11Device_CreateComputeShader(device, ID3D10Blob_GetBufferPointer(cs_code), @@ -714,23 +715,23 @@ static bool d3d11_runner_draw(struct shader_runner *r, unsigned int i; HRESULT hr; - vs_code = compile_shader(runner, runner->r.vs_source, "vs"); - ps_code = compile_shader(runner, runner->r.ps_source, "ps"); + vs_code = compile_shader(runner, SHADER_TYPE_VS); + ps_code = compile_shader(runner, SHADER_TYPE_PS); succeeded = vs_code && ps_code; - if (runner->r.hs_source) + if (runner->r.shader_source[SHADER_TYPE_HS]) { - hs_code = compile_shader(runner, runner->r.hs_source, "hs"); + hs_code = compile_shader(runner, SHADER_TYPE_HS); succeeded = succeeded && hs_code; } - if (runner->r.ds_source) + if (runner->r.shader_source[SHADER_TYPE_DS]) { - ds_code = compile_shader(runner, runner->r.ds_source, "ds"); + ds_code = compile_shader(runner, SHADER_TYPE_DS); succeeded = succeeded && ds_code; } - if (runner->r.gs_source) + if (runner->r.shader_source[SHADER_TYPE_GS]) { - gs_code = compile_shader(runner, runner->r.gs_source, "gs"); + gs_code = compile_shader(runner, SHADER_TYPE_GS); succeeded = succeeded && gs_code; } diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 5d687f4a..f156197b 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -65,8 +65,9 @@ static struct d3d12_shader_runner *d3d12_shader_runner(struct shader_runner *r) return CONTAINING_RECORD(r, struct d3d12_shader_runner, r); } -static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, const char *source, enum shader_type type) +static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, enum shader_type type) { + const char *source = runner->r.shader_source[type]; ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; HRESULT hr; @@ -396,7 +397,7 @@ static bool d3d12_runner_dispatch(struct shader_runner *r, unsigned int x, unsig HRESULT hr; size_t i; - cs_code = compile_shader(runner, runner->r.cs_source, SHADER_TYPE_CS); + cs_code = compile_shader(runner, SHADER_TYPE_CS); todo_if(runner->r.is_todo && runner->r.minimum_shader_model < SHADER_MODEL_6_0) ok(cs_code, "Failed to compile shader.\n"); if (!cs_code) return false; @@ -790,23 +791,23 @@ static bool d3d12_runner_draw(struct shader_runner *r, 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); + ps_code = compile_shader(runner, SHADER_TYPE_PS); + vs_code = compile_shader(runner, SHADER_TYPE_VS); succeeded = ps_code && vs_code; - if (runner->r.hs_source) + if (runner->r.shader_source[SHADER_TYPE_HS]) { - hs_code = compile_shader(runner, runner->r.hs_source, SHADER_TYPE_HS); + hs_code = compile_shader(runner, SHADER_TYPE_HS); succeeded = succeeded && hs_code; } - if (runner->r.ds_source) + if (runner->r.shader_source[SHADER_TYPE_DS]) { - ds_code = compile_shader(runner, runner->r.ds_source, SHADER_TYPE_DS); + ds_code = compile_shader(runner, SHADER_TYPE_DS); succeeded = succeeded && ds_code; } - if (runner->r.gs_source) + if (runner->r.shader_source[SHADER_TYPE_GS]) { - gs_code = compile_shader(runner, runner->r.gs_source, SHADER_TYPE_GS); + gs_code = compile_shader(runner, SHADER_TYPE_GS); succeeded = succeeded && gs_code; } diff --git a/tests/shader_runner_d3d9.c b/tests/shader_runner_d3d9.c index 4400f18f..d44f5fff 100644 --- a/tests/shader_runner_d3d9.c +++ b/tests/shader_runner_d3d9.c @@ -57,8 +57,9 @@ static struct d3d9_shader_runner *d3d9_shader_runner(struct shader_runner *r) static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT sdk_version); -static ID3D10Blob *compile_shader(const struct d3d9_shader_runner *runner, const char *source, const char *type) +static ID3D10Blob *compile_shader(const struct d3d9_shader_runner *runner, enum shader_type type) { + const char *source = runner->r.shader_source[type]; ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; HRESULT hr; @@ -69,7 +70,7 @@ static ID3D10Blob *compile_shader(const struct d3d9_shader_runner *runner, const [SHADER_MODEL_3_0] = "3_0", }; - sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]); + sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->r.minimum_shader_model]); hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, runner->r.compile_options, 0, &blob, &errors); ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr); if (errors) @@ -361,10 +362,10 @@ static bool d3d9_runner_draw(struct shader_runner *r, if (instance_count > 1) fatal_error("Unhandled instance count %u.\n", instance_count); - if (!(vs_code = compile_shader(runner, runner->r.vs_source, "vs"))) + if (!(vs_code = compile_shader(runner, SHADER_TYPE_VS))) return false; - if (!(ps_code = compile_shader(runner, runner->r.ps_source, "ps"))) + if (!(ps_code = compile_shader(runner, SHADER_TYPE_PS))) { ID3D10Blob_Release(vs_code); return false; diff --git a/tests/shader_runner_gl.c b/tests/shader_runner_gl.c index d84e89f7..a8e31c82 100644 --- a/tests/shader_runner_gl.c +++ b/tests/shader_runner_gl.c @@ -533,8 +533,9 @@ static void gl_runner_destroy_resource(struct shader_runner *r, struct resource free(resource); } -static ID3DBlob *compile_hlsl(const struct shader_runner *runner, const char *source, const char *type) +static ID3DBlob *compile_hlsl(const struct shader_runner *runner, enum shader_type type) { + const char *source = runner->shader_source[type]; ID3DBlob *blob = NULL, *errors = NULL; char profile[7]; @@ -546,7 +547,7 @@ static ID3DBlob *compile_hlsl(const struct shader_runner *runner, const char *so [SHADER_MODEL_5_1] = "5_1", }; - sprintf(profile, "%s_%s", type, shader_models[runner->minimum_shader_model]); + sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->minimum_shader_model]); D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, runner->compile_options, 0, &blob, &errors); if (errors) @@ -742,7 +743,7 @@ static GLuint compile_compute_shader_program(struct gl_runner *runner) bool ret; reset_combined_samplers(runner); - if (!(cs_blob = compile_hlsl(&runner->r, runner->r.cs_source, "cs"))) + if (!(cs_blob = compile_hlsl(&runner->r, SHADER_TYPE_CS))) return false; ret = compile_shader(runner, cs_blob, &cs_code); ID3D10Blob_Release(cs_blob); @@ -916,23 +917,23 @@ static GLuint compile_graphics_shader_program(struct gl_runner *runner, ID3D10Bl reset_combined_samplers(runner); - *vs_blob = compile_hlsl(&runner->r, runner->r.vs_source, "vs"); - fs_blob = compile_hlsl(&runner->r, runner->r.ps_source, "ps"); + *vs_blob = compile_hlsl(&runner->r, SHADER_TYPE_VS); + fs_blob = compile_hlsl(&runner->r, SHADER_TYPE_PS); succeeded = *vs_blob && fs_blob; - if (runner->r.hs_source) + if (runner->r.shader_source[SHADER_TYPE_HS]) { - hs_blob = compile_hlsl(&runner->r, runner->r.hs_source, "hs"); + hs_blob = compile_hlsl(&runner->r, SHADER_TYPE_HS); succeeded = succeeded && hs_blob; } - if (runner->r.ds_source) + if (runner->r.shader_source[SHADER_TYPE_DS]) { - ds_blob = compile_hlsl(&runner->r, runner->r.ds_source, "ds"); + ds_blob = compile_hlsl(&runner->r, SHADER_TYPE_DS); succeeded = succeeded && ds_blob; } - if (runner->r.gs_source) + if (runner->r.shader_source[SHADER_TYPE_GS]) { - gs_blob = compile_hlsl(&runner->r, runner->r.gs_source, "gs"); + gs_blob = compile_hlsl(&runner->r, SHADER_TYPE_GS); succeeded = succeeded && gs_blob; } diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index ab0824a9..fe4c7a9b 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -503,14 +503,15 @@ static bool compile_shader(struct vulkan_shader_runner *runner, return true; } -static bool create_shader_stage(struct vulkan_shader_runner *runner, VkPipelineShaderStageCreateInfo *stage_info, - const char *type, enum VkShaderStageFlagBits stage, const char *source) +static bool create_shader_stage(struct vulkan_shader_runner *runner, + VkPipelineShaderStageCreateInfo *stage_info, enum shader_type type, enum VkShaderStageFlagBits stage) { VkShaderModuleCreateInfo module_info = {.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; const struct vulkan_test_context *context = &runner->context; + const char *source = runner->r.shader_source[type]; struct vkd3d_shader_code spirv; - if (!compile_shader(runner, source, type, &spirv)) + if (!compile_shader(runner, source, shader_type_string(type), &spirv)) return false; memset(stage_info, 0, sizeof(*stage_info)); @@ -621,22 +622,19 @@ static VkPipeline create_graphics_pipeline(struct vulkan_shader_runner *runner, int ret; memset(stage_desc, 0, sizeof(stage_desc)); - ret = create_shader_stage(runner, &stage_desc[stage_count++], - "vs", VK_SHADER_STAGE_VERTEX_BIT, runner->r.vs_source); - ret &= create_shader_stage(runner, &stage_desc[stage_count++], - "ps", VK_SHADER_STAGE_FRAGMENT_BIT, runner->r.ps_source); + ret = create_shader_stage(runner, &stage_desc[stage_count++], SHADER_TYPE_VS, VK_SHADER_STAGE_VERTEX_BIT); + ret &= create_shader_stage(runner, &stage_desc[stage_count++], SHADER_TYPE_PS, VK_SHADER_STAGE_FRAGMENT_BIT); - if (runner->r.hs_source) + if (runner->r.shader_source[SHADER_TYPE_HS]) { - ret &= create_shader_stage(runner, &stage_desc[stage_count++], "hs", - VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, runner->r.hs_source); - ret &= create_shader_stage(runner, &stage_desc[stage_count++], "ds", - VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, runner->r.ds_source); + ret &= create_shader_stage(runner, &stage_desc[stage_count++], + SHADER_TYPE_HS, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); + ret &= create_shader_stage(runner, &stage_desc[stage_count++], + SHADER_TYPE_DS, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); } - if (runner->r.gs_source) - ret &= create_shader_stage(runner, &stage_desc[stage_count++], - "gs", VK_SHADER_STAGE_GEOMETRY_BIT, runner->r.gs_source); + if (runner->r.shader_source[SHADER_TYPE_GS]) + ret &= create_shader_stage(runner, &stage_desc[stage_count++], SHADER_TYPE_GS, VK_SHADER_STAGE_GEOMETRY_BIT); if (!ret) { @@ -756,7 +754,7 @@ static VkPipeline create_graphics_pipeline(struct vulkan_shader_runner *runner, pipeline_desc.renderPass = render_pass; pipeline_desc.subpass = 0; - if (runner->r.hs_source) + if (runner->r.shader_source[SHADER_TYPE_HS]) { tessellation_info.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; tessellation_info.pNext = NULL; @@ -783,7 +781,7 @@ static VkPipeline create_compute_pipeline(struct vulkan_shader_runner *runner, V VkPipeline pipeline; bool ret; - ret = create_shader_stage(runner, &pipeline_desc.stage, "cs", VK_SHADER_STAGE_COMPUTE_BIT, runner->r.cs_source); + ret = create_shader_stage(runner, &pipeline_desc.stage, SHADER_TYPE_CS, VK_SHADER_STAGE_COMPUTE_BIT); todo_if (runner->r.is_todo) ok(ret, "Failed to compile shader.\n"); if (!ret) return VK_NULL_HANDLE;