From d07d0d8eff42fd8674e5c2f02aa9e3c8f04bb2b7 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Wed, 26 Jan 2022 15:35:33 +0100 Subject: [PATCH] tests: Add tests for texture gather methods. Signed-off-by: Francisco Casas Signed-off-by: Zebediah Figura Signed-off-by: Giovanni Mascellani Signed-off-by: Matteo Bruni Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- Makefile.am | 3 + tests/hlsl-gather-offset.shader_test | 101 +++++++++++++++++++++++ tests/hlsl-gather.shader_test | 115 +++++++++++++++++++++++++++ tests/shader_runner_d3d12.c | 63 ++++++++++++++- 4 files changed, 280 insertions(+), 2 deletions(-) create mode 100644 tests/hlsl-gather-offset.shader_test create mode 100644 tests/hlsl-gather.shader_test diff --git a/Makefile.am b/Makefile.am index 46f11072..db0a6f68 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,6 +68,8 @@ vkd3d_shader_tests = \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \ + tests/hlsl-gather-offset.shader_test \ + tests/hlsl-gather.shader_test \ tests/hlsl-intrinsic-override.shader_test \ tests/hlsl-invalid.shader_test \ tests/hlsl-majority-pragma.shader_test \ @@ -294,6 +296,7 @@ XFAIL_TESTS = \ tests/hlsl-duplicate-modifiers.shader_test \ tests/hlsl-for.shader_test \ tests/hlsl-function-overload.shader_test \ + tests/hlsl-gather.shader_test \ tests/hlsl-intrinsic-override.shader_test \ tests/hlsl-majority-pragma.shader_test \ tests/hlsl-majority-typedef.shader_test \ diff --git a/tests/hlsl-gather-offset.shader_test b/tests/hlsl-gather-offset.shader_test new file mode 100644 index 00000000..51e6a6b6 --- /dev/null +++ b/tests/hlsl-gather-offset.shader_test @@ -0,0 +1,101 @@ +[require] +shader model >= 4.1 + + +[sampler 0] +filter linear linear linear +address clamp clamp clamp + +[texture 0] +size (3, 3) +0.0 0.0 0.0 0.4 0.1 0.0 0.5 0.0 0.2 0.0 0.0 0.4 +0.0 0.1 0.5 0.0 0.1 0.1 0.0 0.4 0.2 0.1 0.5 0.0 +0.0 0.2 0.0 0.4 0.1 0.2 0.5 0.0 0.2 0.2 0.0 0.4 + + +[pixel shader] +sampler s; +Texture2D t; + +float4 main() : sv_target +{ + return t.Gather(s, float2(0.2, 0.2), int2(1, 0)); +} + +[test] +draw quad +probe all rgba (0.1, 0.2, 0.2, 0.1) + + +[pixel shader] +sampler s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherRed(s, float2(0.6, 0.6), int2(-1, 0)); +} + +[test] +draw quad +probe all rgba (0.0, 0.1, 0.1, 0.0) + + +[require] +shader model >= 5.0 + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherGreen(s, float2(0.2, 0.2), int2(0, 1)); +} + +[test] +draw quad +probe all rgba (0.2, 0.2, 0.1, 0.1) + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherGreen(s, float2(0.8, 0.8), int2(-1, -1)); +} + +[test] +draw quad +probe all rgba (0.1, 0.1, 0.0, 0.0) + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherBlue(s, float2(0.2, 0.8), int2(1, 0)); +} + +[test] +draw quad +probe all rgba (0.5, 0.0, 0.5, 0.0) + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherAlpha(s, float2(0.2, 0.8), int2(0, -1)); +} + +[test] +draw quad +probe all rgba (0.0, 0.4, 0.0, 0.4) diff --git a/tests/hlsl-gather.shader_test b/tests/hlsl-gather.shader_test new file mode 100644 index 00000000..57af23d0 --- /dev/null +++ b/tests/hlsl-gather.shader_test @@ -0,0 +1,115 @@ +[require] +shader model >= 4.1 + + +[sampler 0] +filter linear linear linear +address clamp clamp clamp + +[texture 0] +size (3, 3) +0.0 0.0 0.0 0.4 0.1 0.0 0.5 0.0 0.2 0.0 0.0 0.4 +0.0 0.1 0.5 0.0 0.1 0.1 0.0 0.4 0.2 0.1 0.5 0.0 +0.0 0.2 0.0 0.4 0.1 0.2 0.5 0.0 0.2 0.2 0.0 0.4 + + +[pixel shader] +sampler s; +Texture2D t; + +float4 main() : sv_target +{ + return t.Gather(s, float2(0.2, 0.2)); +} + +[test] +draw quad +probe all rgba (0.0, 0.1, 0.1, 0.0) + + +[pixel shader] +sampler s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherRed(s, float2(0.6, 0.6), int2(0, 0)); +} + +[test] +draw quad +probe all rgba (0.1, 0.2, 0.2, 0.1) + + +[require] +shader model >= 5.0 + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherGreen(s, float2(0.2, 0.2), int2(0, 0)); +} + +[test] +draw quad +probe all rgba (0.1, 0.1, 0.0, 0.0) + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherGreen(s, float2(0.8, 0.8)); +} + +[test] +draw quad +probe all rgba (0.2, 0.2, 0.1, 0.1) + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherGreen(s, float2(0.2, 0.2), int2(0, 0), int2(0, 0), int2(0, 0), int2(0, 0)); +} + +[test] +draw quad +probe all rgba (0.1, 0.1, 0.0, 0.0) + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherBlue(s, float2(0.2, 0.8), int2(0, 0)); +} + +[test] +draw quad +probe all rgba (0.0, 0.5, 0.0, 0.5) + + +[pixel shader] +SamplerState s; +Texture2D t; + +float4 main() : sv_target +{ + return t.GatherAlpha(s, float2(0.2, 0.8), int2(0, 0)); +} + +[test] +draw quad +probe all rgba (0.4, 0.0, 0.4, 0.0) diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 47f419b9..4a8d1f18 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -115,9 +115,18 @@ struct texture unsigned int root_index; }; +enum shader_model +{ + SHADER_MODEL_4_0 = 0, + SHADER_MODEL_4_1, + SHADER_MODEL_5_0, + SHADER_MODEL_5_1, +}; + struct shader_context { struct test_context c; + enum shader_model minimum_shader_model; ID3D10Blob *ps_code; @@ -160,6 +169,7 @@ enum parse_state STATE_NONE, STATE_PREPROC, STATE_PREPROC_INVALID, + STATE_REQUIRE, STATE_SAMPLER, STATE_SHADER_INVALID_PIXEL, STATE_SHADER_PIXEL, @@ -182,6 +192,36 @@ static bool match_string(const char *line, const char *token, const char **const return true; } +static void parse_require_directive(struct shader_context *context, const char *line) +{ + if (match_string(line, "shader model >=", &line)) + { + static const char *const model_strings[] = + { + [SHADER_MODEL_4_0] = "4.0", + [SHADER_MODEL_4_1] = "4.1", + [SHADER_MODEL_5_0] = "5.0", + [SHADER_MODEL_5_1] = "5.1", + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(model_strings); ++i) + { + if (match_string(line, model_strings[i], &line)) + { + context->minimum_shader_model = i; + return; + } + } + + fatal_error("Unknown shader model '%s'.\n", line); + } + else + { + fatal_error("Unknown require directive '%s'.\n", line); + } +} + static void parse_texture_format(struct texture *texture, const char *line) { static const struct @@ -662,16 +702,27 @@ START_TEST(shader_runner_d3d12) switch (state) { case STATE_NONE: + case STATE_REQUIRE: case STATE_SAMPLER: case STATE_TEST: case STATE_TEXTURE: break; case STATE_SHADER_PIXEL: - if (!(context.ps_code = compile_shader(shader_source, "ps_4_0"))) + { + static const char *const shader_models[] = + { + [SHADER_MODEL_4_0] = "ps_4_0", + [SHADER_MODEL_4_1] = "ps_4_1", + [SHADER_MODEL_5_0] = "ps_5_0", + [SHADER_MODEL_5_1] = "ps_5_1", + }; + + if (!(context.ps_code = compile_shader(shader_source, shader_models[context.minimum_shader_model]))) return; shader_source_len = 0; break; + } case STATE_SHADER_INVALID_PIXEL: { @@ -755,7 +806,11 @@ START_TEST(shader_runner_d3d12) { unsigned int index; - if (!strcmp(line, "[pixel shader]\n")) + if (!strcmp(line, "[require]\n")) + { + state = STATE_REQUIRE; + } + else if (!strcmp(line, "[pixel shader]\n")) { state = STATE_SHADER_PIXEL; @@ -844,6 +899,10 @@ START_TEST(shader_runner_d3d12) break; } + case STATE_REQUIRE: + parse_require_directive(&context, line); + break; + case STATE_SAMPLER: parse_sampler_directive(current_sampler, line); break;