Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
-- v2: tests: Add some tests for 'technique' token behaviour. tests: Add [effect] section support.
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- tests/shader_runner.c | 43 +++++++++++++++++++++++++++++++++++++++++-- tests/shader_runner.h | 2 ++ 2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c index cae0bf026..d33279567 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -89,6 +89,8 @@ enum parse_state STATE_SHADER_PIXEL_TODO, STATE_SHADER_VERTEX, STATE_SHADER_VERTEX_TODO, + STATE_SHADER_EFFECT, + STATE_SHADER_EFFECT_TODO, STATE_TEST, };
@@ -814,6 +816,7 @@ const char *shader_type_string(enum shader_type type) [SHADER_TYPE_CS] = "cs", [SHADER_TYPE_PS] = "ps", [SHADER_TYPE_VS] = "vs", + [SHADER_TYPE_FX] = "fx", }; assert(type < ARRAY_SIZE(shader_types)); return shader_types[type]; @@ -953,6 +956,14 @@ static void compile_shader(struct shader_runner *runner, IDxcCompiler3 *dxc_comp [SHADER_MODEL_6_0] = "6_0", };
+ static const char *const effect_models[] = + { + [SHADER_MODEL_2_0] = "2_0", + [SHADER_MODEL_4_0] = "4_0", + [SHADER_MODEL_4_1] = "4_1", + [SHADER_MODEL_5_0] = "5_0", + }; + if (use_dxcompiler) { assert(dxc_compiler); @@ -960,7 +971,10 @@ static void compile_shader(struct shader_runner *runner, IDxcCompiler3 *dxc_comp } else { - sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->minimum_shader_model]); + if (type == SHADER_TYPE_FX) + sprintf(profile, "%s_%s", shader_type_string(type), effect_models[runner->minimum_shader_model]); + else + sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->minimum_shader_model]); hr = D3DCompile(source, len, NULL, NULL, NULL, "main", profile, runner->compile_options, 0, &blob, &errors); } hr = map_unidentified_hrs(hr); @@ -996,8 +1010,10 @@ static enum parse_state read_shader_directive(struct shader_runner *runner, enum state = STATE_SHADER_COMPUTE_TODO; else if (state == STATE_SHADER_PIXEL) state = STATE_SHADER_PIXEL_TODO; - else + else if (state == STATE_SHADER_VERTEX) state = STATE_SHADER_VERTEX_TODO; + else + state = STATE_SHADER_EFFECT_TODO; } else if (match_directive_substring(src, "fail", &src)) { @@ -1130,6 +1146,21 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o shader_source_size = 0; break;
+ case STATE_SHADER_EFFECT: + case STATE_SHADER_EFFECT_TODO: + if (!skip_tests) + { + todo_if (state == STATE_SHADER_EFFECT_TODO) + compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_FX, + expect_hr); + } + free(runner->fx_source); + runner->fx_source = shader_source; + shader_source = NULL; + shader_source_len = 0; + shader_source_size = 0; + break; + case STATE_PREPROC_INVALID: { ID3D10Blob *blob = NULL, *errors = NULL; @@ -1318,6 +1349,12 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o expect_hr = S_OK; state = read_shader_directive(runner, state, line_buffer, line, &expect_hr); } + else if (match_directive_substring(line, "[effect", &line)) + { + state = STATE_SHADER_EFFECT; + 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; @@ -1349,6 +1386,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o case STATE_SHADER_PIXEL_TODO: case STATE_SHADER_VERTEX: case STATE_SHADER_VERTEX_TODO: + case STATE_SHADER_EFFECT: + case STATE_SHADER_EFFECT_TODO: { size_t len = strlen(line);
diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 3efbcf362..bda44a429 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -44,6 +44,7 @@ enum shader_type SHADER_TYPE_CS, SHADER_TYPE_PS, SHADER_TYPE_VS, + SHADER_TYPE_FX, };
const char *shader_type_string(enum shader_type type); @@ -118,6 +119,7 @@ struct shader_runner char *vs_source; char *ps_source; char *cs_source; + char *fx_source; enum shader_model minimum_shader_model; enum shader_model maximum_shader_model;
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- Makefile.am | 3 + tests/hlsl/technique-fx_2.shader_test | 104 ++++++++++++++++++++++++++ tests/hlsl/technique-fx_4.shader_test | 82 ++++++++++++++++++++ tests/hlsl/technique-fx_5.shader_test | 82 ++++++++++++++++++++ 4 files changed, 271 insertions(+) create mode 100644 tests/hlsl/technique-fx_2.shader_test create mode 100644 tests/hlsl/technique-fx_4.shader_test create mode 100644 tests/hlsl/technique-fx_5.shader_test
diff --git a/Makefile.am b/Makefile.am index 8364aaa37..8117936c6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -168,6 +168,9 @@ vkd3d_shader_tests = \ tests/hlsl/swizzle-constant-prop.shader_test \ tests/hlsl/swizzle-matrix.shader_test \ tests/hlsl/swizzles.shader_test \ + tests/hlsl/technique-fx_2.shader_test \ + tests/hlsl/technique-fx_4.shader_test \ + tests/hlsl/technique-fx_5.shader_test \ tests/hlsl/ternary.shader_test \ tests/hlsl/texture-load-offset.shader_test \ tests/hlsl/texture-load-typed.shader_test \ diff --git a/tests/hlsl/technique-fx_2.shader_test b/tests/hlsl/technique-fx_2.shader_test new file mode 100644 index 000000000..149506e68 --- /dev/null +++ b/tests/hlsl/technique-fx_2.shader_test @@ -0,0 +1,104 @@ +[require] +shader model < 3.0 + +[pixel shader fail todo] +float4 main() : sv_target +{ + float4 teChnique = {0, 0, 0, 0}; + return teChnique; +} + +[pixel shader fail] +float4 main() : sv_target +{ + float4 technique10 = {0, 0, 0, 0}; + return technique10; +} + +[pixel shader fail todo] +float4 main() : sv_target +{ + float4 technique11 = {0, 0, 0, 0}; + return technique11; +} + +[pixel shader fail] +typedef float4 technique10; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader fail todo] +typedef float4 Technique; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader] +typedef float4 Technique10; +typedef float4 Technique11; + +float4 main() : sv_target +{ + return float4(0, 0, 0, 0); +} + +[pixel shader] +float4 main() : sv_target +{ + float4 teChnique10 = {0, 0, 0, 0}; + float4 teChnique11 = {0, 0, 0, 0}; + return teChnique10 + teChnique11; +} + +[pixel shader] +float4 main() : sv_target +{ + float4 teChnique11 = {0, 0, 0, 0}; + return teChnique11; +} + +[effect todo] +technique +{ +} + +technique10 +{ +} + +% Effects without techniques are not allowed for fx_2_0 +[effect fail] +float4 f; + +% fx_5_0 keyword fails with fx_2_0 profile +[effect fail] +technique +{ +} + +technique11 +{ +} + +[effect fail] +technique +{ +} + +tEchnique10 +{ +} + +[effect fail] +technique +{ +} + +tEchnique11 +{ +} diff --git a/tests/hlsl/technique-fx_4.shader_test b/tests/hlsl/technique-fx_4.shader_test new file mode 100644 index 000000000..3795b75f6 --- /dev/null +++ b/tests/hlsl/technique-fx_4.shader_test @@ -0,0 +1,82 @@ +[require] +shader model >= 4.0 + +[pixel shader fail todo] +float4 main() : sv_target +{ + float4 teChnique = {0, 0, 0, 0}; + return teChnique; +} + +[pixel shader] +float4 main() : sv_target +{ + float4 teChnique10 = {0, 0, 0, 0}; + return teChnique10; +} + +[pixel shader] +float4 main() : sv_target +{ + float4 teChnique11 = {0, 0, 0, 0}; + return teChnique11; +} + +[effect todo] +technique +{ +} + +technique10 +{ +} + +% Effects without techniques are allowed for fx_4_0+ +[effect todo] +float4 f; + +% fx_2_0 keyword is allowed with fx_4_0+ profiles +[effect todo] +technique +{ +} + +technique11 +{ +} + +[effect fail] +technique +{ +} + +tEchnique10 +{ +} + +[effect fail] +technique +{ +} + +tEchnique11 +{ +} + +[effect fail] +float4 technique; + +[effect fail] +float4 technIque; + +[effect fail] +float4 technique10; + +[effect fail] +float4 technique11; + +[effect todo] +float4 technIque10; + +[effect todo] +float4 technIque11; diff --git a/tests/hlsl/technique-fx_5.shader_test b/tests/hlsl/technique-fx_5.shader_test new file mode 100644 index 000000000..a9fd6ab91 --- /dev/null +++ b/tests/hlsl/technique-fx_5.shader_test @@ -0,0 +1,82 @@ +[require] +shader model >= 5.0 + +[pixel shader fail todo] +float4 main() : sv_target +{ + float4 teChnique = {0, 0, 0, 0}; + return teChnique; +} + +[pixel shader] +float4 main() : sv_target +{ + float4 teChnique10 = {0, 0, 0, 0}; + return teChnique10; +} + +[pixel shader] +float4 main() : sv_target +{ + float4 teChnique11 = {0, 0, 0, 0}; + return teChnique11; +} + +[effect todo] +technique +{ +} + +technique10 +{ +} + +% Effects without techniques are allowed for fx_5_0 +[effect todo] +float4 f; + +% fx_2_0 keyword is allowed with fx_5_0 profiles +[effect todo] +technique +{ +} + +technique11 +{ +} + +[effect fail] +technique +{ +} + +tEchnique10 +{ +} + +[effect fail] +technique +{ +} + +tEchnique11 +{ +} + +[effect fail] +float4 technique; + +[effect fail] +float4 technIque; + +[effect fail] +float4 technique10; + +[effect fail] +float4 technique11; + +[effect todo] +float4 technIque10; + +[effect todo] +float4 technIque11;
This is now done differently, with a much smaller change to the test runner. Currently compilation test is using minimal supported version, to make it easier and more readable I used separate files for targets that differ substantially. Later we could probably add fx_4_1 to the fx_4 file, but for technique token specifically that does not introduce any changes in behavior.
This fails when dxcompiler is used. You can't see that in the CI pipeline because you're based on an older version of master, but if you rebase on current master you should see the crash. The problem is likely `shader_profiles` in `dxc_compiler_compile_shader()`. I don't know if dxcompiler supports effects, but depending on that you should either fix `shader_profiles` there or exclude effect compilation on SM6.
On Wed Oct 18 12:28:10 2023 +0000, Giovanni Mascellani wrote:
This fails when dxcompiler is used. You can't see that in the CI pipeline because you're based on an older version of master, but if you rebase on current master you should see the crash. The problem is likely `shader_profiles` in `dxc_compiler_compile_shader()`. I don't know if dxcompiler supports effects, but depending on that you should either fix `shader_profiles` there or exclude effect compilation on SM6.
I don't get any crashes, probably because I don't have this compiler anywhere. And if it's optional it should silently skip anything it could possibly not support. It's getting harder to navigate the testing system. I obviously will want to skip anything [effect] on it. How do I do that? Is it necessary to have [require] to set minimum_shader_model below 6, I hope not.
On Wed Oct 18 12:28:10 2023 +0000, Nikolay Sivov wrote:
I don't get any crashes, probably because I don't have this compiler anywhere. And if it's optional it should silently skip anything it could possibly not support. It's getting harder to navigate the testing system. I obviously will want to skip anything [effect] on it. How do I do that? Is it necessary to have [require] to set minimum_shader_model below 6, I hope not.
Yeah, it's true that dxcompiler is a bit more annoying than we'd like, but it's not too difficult to setup. Since 57280673e51f6b60487e91369bd57213a8243a56 the README has a paragraph on that. You basically need to download the compiler, set `DXCOMPILER_LIBS` when calling `configure` and `LD_LIBRARY_PATH` when running the tests.