From 4ec60707e20336143987c4bf440075dac4199950 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Sun, 30 Apr 2023 19:27:58 -0500 Subject: [PATCH] tests: Add a test for sampling from nonzero mipmap levels. --- Makefile.am | 1 + tests/sample-level.shader_test | 36 ++++++++++++++++++++++++++++++++++ tests/shader_runner.c | 2 ++ tests/shader_runner.h | 1 + tests/shader_runner_d3d11.c | 1 + tests/shader_runner_d3d12.c | 1 + tests/shader_runner_d3d9.c | 14 ++++++++++--- tests/shader_runner_vulkan.c | 1 + 8 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 tests/sample-level.shader_test diff --git a/Makefile.am b/Makefile.am index 678d3903..f5cee9a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -157,6 +157,7 @@ vkd3d_shader_tests = \ tests/register-reservations.shader_test \ tests/return.shader_test \ tests/round.shader_test \ + tests/sample-level.shader_test \ tests/sampler.shader_test \ tests/sampler-offset.shader_test \ tests/saturate.shader_test \ diff --git a/tests/sample-level.shader_test b/tests/sample-level.shader_test new file mode 100644 index 00000000..564826d0 --- /dev/null +++ b/tests/sample-level.shader_test @@ -0,0 +1,36 @@ +[require] +shader model >= 3.0 + +[sampler 0] +filter linear linear linear +address clamp clamp clamp + +[texture 0] +size (2, 2) +levels 2 + +1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 +1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 + +0.0 0.0 1.0 0.0 + +[pixel shader todo] +sampler s; +Texture2D t; +uniform float level; + +float4 main() : sv_target +{ + return t.SampleLevel(s, float2(0.5, 0.5), level); +} + +[test] +uniform 0 float4 0.0 0.0 0.0 0.0 +todo draw quad +probe all rgba (1.0, 0.0, 1.0, 0.0) +uniform 0 float4 0.5 0.0 0.0 0.0 +todo draw quad +probe all rgba (0.5, 0.0, 1.0, 0.0) +uniform 0 float4 1.0 0.0 0.0 0.0 +todo draw quad +probe all rgba (0.0, 0.0, 1.0, 0.0) diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 8c0f59dc..b51145c7 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -116,6 +116,7 @@ static void parse_require_directive(struct shader_runner *runner, const char *li static const char *const model_strings[] = { [SHADER_MODEL_2_0] = "2.0", + [SHADER_MODEL_3_0] = "3.0", [SHADER_MODEL_4_0] = "4.0", [SHADER_MODEL_4_1] = "4.1", [SHADER_MODEL_5_0] = "5.0", @@ -747,6 +748,7 @@ static void compile_shader(struct shader_runner *runner, const char *source, siz static const char *const shader_models[] = { [SHADER_MODEL_2_0] = "4_0", + [SHADER_MODEL_3_0] = "4_0", [SHADER_MODEL_4_0] = "4_0", [SHADER_MODEL_4_1] = "4_1", [SHADER_MODEL_5_0] = "5_0", diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 8f8cf979..8962a8fc 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -31,6 +31,7 @@ enum shader_model { SHADER_MODEL_2_0, + SHADER_MODEL_3_0, SHADER_MODEL_4_0, SHADER_MODEL_4_1, SHADER_MODEL_5_0, diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index 12d00bf8..a6b9c693 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -80,6 +80,7 @@ static ID3D10Blob *compile_shader(const char *source, const char *type, enum sha static const char *const shader_models[] = { [SHADER_MODEL_2_0] = "4_0", + [SHADER_MODEL_3_0] = "4_0", [SHADER_MODEL_4_0] = "4_0", [SHADER_MODEL_4_1] = "4_1", [SHADER_MODEL_5_0] = "5_0", diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 09e3eb28..c73dbf64 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -65,6 +65,7 @@ static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, cons static const char *const shader_models[] = { [SHADER_MODEL_2_0] = "4_0", + [SHADER_MODEL_3_0] = "4_0", [SHADER_MODEL_4_0] = "4_0", [SHADER_MODEL_4_1] = "4_1", [SHADER_MODEL_5_0] = "5_0", diff --git a/tests/shader_runner_d3d9.c b/tests/shader_runner_d3d9.c index 26b8cb8f..973b2342 100644 --- a/tests/shader_runner_d3d9.c +++ b/tests/shader_runner_d3d9.c @@ -56,11 +56,19 @@ static struct d3d9_shader_runner *d3d9_shader_runner(struct shader_runner *r) static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT sdk_version); -static ID3D10Blob *compile_shader(const char *source, const char *profile) +static ID3D10Blob *compile_shader(const char *source, const char *type, enum shader_model shader_model) { ID3D10Blob *blob = NULL, *errors = NULL; + char profile[7]; HRESULT hr; + static const char *const shader_models[] = + { + [SHADER_MODEL_2_0] = "2_0", + [SHADER_MODEL_3_0] = "3_0", + }; + + sprintf(profile, "%s_%s", type, shader_models[shader_model]); hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, 0, 0, &blob, &errors); ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr); if (errors) @@ -325,10 +333,10 @@ static bool d3d9_runner_draw(struct shader_runner *r, unsigned int i, j; HRESULT hr; - if (!(vs_code = compile_shader(runner->r.vs_source, "vs_2_0"))) + if (!(vs_code = compile_shader(runner->r.vs_source, "vs", runner->r.minimum_shader_model))) return false; - if (!(ps_code = compile_shader(runner->r.ps_source, "ps_2_0"))) + if (!(ps_code = compile_shader(runner->r.ps_source, "ps", runner->r.minimum_shader_model))) { ID3D10Blob_Release(vs_code); return false; diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index 43b7b265..670a454d 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -364,6 +364,7 @@ static bool compile_shader(const struct vulkan_shader_runner *runner, const char static const char *const shader_models[] = { [SHADER_MODEL_2_0] = "4_0", + [SHADER_MODEL_3_0] = "4_0", [SHADER_MODEL_4_0] = "4_0", [SHADER_MODEL_4_1] = "4_1", [SHADER_MODEL_5_0] = "5_0",