tests: Always compile HLSL shaders.

Do not rely on a draw or dispatch command to do this.

This allows more efficiently testing syntax, in cases where testing the actual
shader functionality is not interesting.
This commit is contained in:
Zebediah Figura 2022-10-30 17:21:12 -05:00 committed by Alexandre Julliard
parent 520c7457a9
commit 4d17758657
Notes: Alexandre Julliard 2022-11-08 23:05:16 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/43
21 changed files with 96 additions and 62 deletions

View File

@ -124,7 +124,7 @@ draw quad
probe all rgba (4.0, 4.0, 4.0, 4.0)
[pixel shader]
[pixel shader todo]
Texture2D tex;
struct apple

View File

@ -1,7 +1,7 @@
[require]
shader model >= 4.0
[pixel shader]
[pixel shader todo]
float4 main(uniform int i, uniform uint u, uniform bool b, uniform float f) : sv_target
{

View File

@ -7,7 +7,7 @@ size (1, 1)
0.1
[compute shader]
[compute shader todo]
RWTexture2D<float> u;
[numthreads(1, 1, 1)]

View File

@ -1,6 +1,6 @@
% Test what kinds of expressions are valid array dimensions.
[pixel shader]
[pixel shader todo]
float4 main() : sv_target
{
const int dim = 4;

View File

@ -4,7 +4,7 @@ void main(out float tex : texcoord, inout float4 pos : sv_position)
tex = pos.x;
}
[pixel shader]
[pixel shader todo]
float4 main(float tex : texcoord) : sv_target
{
int i;

View File

@ -1,6 +1,6 @@
% Test implicit and explicit casts on function output parameters.
[pixel shader]
[pixel shader todo]
uniform float4 f;
@ -23,7 +23,7 @@ probe all rgba (-1.0, -1.0, 2.0, 4.0)
% As above, but cast "x" to float4 first.
[pixel shader]
[pixel shader todo]
uniform float4 f;
@ -46,7 +46,7 @@ probe all rgba (-1.0, -1.0, 2.0, 4.0)
% As above, but declare "x" as float4 and cast it to int4.
[pixel shader]
[pixel shader todo]
uniform float4 f;
@ -70,7 +70,7 @@ probe all rgba (-1.0, -1.0, 2.0, 4.0)
[require]
shader model >= 4.0
[pixel shader]
[pixel shader todo]
void func(inout float4 a)
{

View File

@ -16,7 +16,7 @@ float4 main() : sv_target
return 0;
}
[pixel shader]
[pixel shader todo]
/* Test a basic overload. */
float func(int arg)
{

View File

@ -9,7 +9,7 @@ float4 main() : sv_target
% It's legal to call an undefined function in unused code, though.
[pixel shader]
[pixel shader todo]
float4 func();
@ -118,7 +118,7 @@ void func()
{
}
[pixel shader]
[pixel shader todo]
float func(in float a, out float b, inout float c)
{
@ -142,7 +142,7 @@ float4 main() : sv_target
todo draw quad
probe all rgba (0.5, 0.6, 0.7, 0)
[pixel shader]
[pixel shader todo]
void func(in float a, inout float2 b)
{

View File

@ -73,7 +73,7 @@ draw quad
probe all rgba (0.2, 0.2, 0.1, 0.1)
[pixel shader]
[pixel shader todo]
SamplerState s;
Texture2D t;

View File

@ -29,7 +29,7 @@ draw quad
probe all rgba (0.2, 0.2, 0.2, 0.1)
[pixel shader]
[pixel shader todo]
Texture2D tex;
struct foo
@ -52,7 +52,7 @@ todo draw quad
todo probe all rgba (31.1, 41.1, 51.1, 61.1) 1
[pixel shader]
[pixel shader todo]
Texture2D tex1;
Texture2D tex2;

View File

@ -1,4 +1,4 @@
[pixel shader]
[pixel shader todo]
float2 max(float2 a, float2 b)
{
@ -14,7 +14,7 @@ float4 main() : sv_target
todo draw quad
probe all rgba (0.3, 0.3, 0.4, 0.6)
[pixel shader]
[pixel shader todo]
float2 max(float2 a, float3 b)
{

View File

@ -38,7 +38,7 @@ float4x1 main() : sv_target
draw quad
probe all rgba (0.4, 0.3, 0.2, 0.1)
[pixel shader]
[pixel shader todo]
float3 func()
{
return float3x1(0.4, 0.3, 0.2);
@ -53,7 +53,7 @@ float4 main() : sv_target
todo draw quad
probe all rgba (0.4, 0.3, 0.2, 0.0)
[pixel shader]
[pixel shader todo]
float3 func()
{
return float1x3(0.4, 0.3, 0.2);
@ -68,7 +68,7 @@ float4 main() : sv_target
todo draw quad
probe all rgba (0.4, 0.3, 0.2, 0.0)
[pixel shader]
[pixel shader todo]
float1x3 func()
{
return float3(0.4, 0.3, 0.2);
@ -83,7 +83,7 @@ float4 main() : sv_target
todo draw quad
probe all rgba (0.4, 0.3, 0.2, 0.0)
[pixel shader]
[pixel shader todo]
float3x1 func()
{
return float3(0.4, 0.3, 0.2);
@ -120,7 +120,7 @@ float4 main() : sv_target
return float4(func(), 0.0);
}
[pixel shader]
[pixel shader todo]
float3 func()
{
return float4(0.4, 0.3, 0.2, 0.1);
@ -135,7 +135,7 @@ float4 main() : sv_target
todo draw quad
probe all rgba (0.4, 0.3, 0.2, 0.0)
[pixel shader]
[pixel shader todo]
float3 func()
{
return float4x1(0.4, 0.3, 0.2, 0.1);
@ -150,7 +150,7 @@ float4 main() : sv_target
todo draw quad
probe all rgba (0.4, 0.3, 0.2, 0.0)
[pixel shader]
[pixel shader todo]
float3 func()
{
return float1x4(0.4, 0.3, 0.2, 0.1);
@ -176,7 +176,7 @@ float4 main() : sv_target
return float4(func(), 0.0);
}
[pixel shader]
[pixel shader todo]
float3x1 func()
{
return float4x1(0.4, 0.3, 0.2, 0.1);
@ -202,7 +202,7 @@ float4 main() : sv_target
return float4(func(), 0.0);
}
[pixel shader]
[pixel shader todo]
float1x3 func()
{
return float4(0.4, 0.3, 0.2, 0.1);
@ -228,7 +228,7 @@ float4 main() : sv_target
return float4(func(), 0.0);
}
[pixel shader]
[pixel shader todo]
float1x3 func()
{
return float1x4(0.4, 0.3, 0.2, 0.1);

View File

@ -1,4 +1,4 @@
[pixel shader]
[pixel shader todo]
float myfunc()
{
return 0.6;

View File

@ -1,4 +1,4 @@
[pixel shader]
[pixel shader todo]
void sub2(in uniform float4 i, out float4 o)
{
o = i;

View File

@ -1,6 +1,6 @@
% Use a uniform to prevent the compiler from optimizing.
[pixel shader]
[pixel shader todo]
uniform float i;
float4 main() : SV_TARGET
{

View File

@ -43,7 +43,7 @@ size (1, 1)
size (1, 1)
3.0 3.0 3.0 1.0
[pixel shader]
[pixel shader todo]
Texture2D tex[3];
struct foo {

View File

@ -12,7 +12,7 @@ size (3, 3)
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]
[pixel shader todo]
sampler s;
Texture2D t;
@ -26,7 +26,7 @@ todo draw quad
probe all rgba (0.1, 0.2, 0.5, 0.0)
[pixel shader]
[pixel shader todo]
sampler s;
Texture2D t;
@ -40,7 +40,7 @@ todo draw quad
probe all rgba (0.2, 0.2, 0.0, 0.4)
[pixel shader]
[pixel shader todo]
sampler s;
Texture2D t;

View File

@ -81,9 +81,11 @@ enum parse_state
STATE_RESOURCE,
STATE_SAMPLER,
STATE_SHADER_COMPUTE,
STATE_SHADER_COMPUTE_TODO,
STATE_SHADER_INVALID_PIXEL,
STATE_SHADER_INVALID_PIXEL_TODO,
STATE_SHADER_PIXEL,
STATE_SHADER_PIXEL_TODO,
STATE_SHADER_VERTEX,
STATE_TEST,
};
@ -657,6 +659,44 @@ unsigned int get_vb_stride(const struct shader_runner *runner, unsigned int slot
return stride;
}
static void compile_shader(struct shader_runner *runner, const char *source, size_t len, const char *type, bool invalid)
{
ID3D10Blob *blob = NULL, *errors = NULL;
char profile[7];
HRESULT hr;
static const char *const shader_models[] =
{
[SHADER_MODEL_2_0] = "4_0",
[SHADER_MODEL_4_0] = "4_0",
[SHADER_MODEL_4_1] = "4_1",
[SHADER_MODEL_5_0] = "5_0",
[SHADER_MODEL_5_1] = "5_1",
};
sprintf(profile, "%s_%s", type, shader_models[runner->minimum_shader_model]);
hr = D3DCompile(source, len, NULL, NULL, NULL, "main", profile, 0, 0, &blob, &errors);
if (invalid)
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
else
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
if (hr == S_OK)
{
ID3D10Blob_Release(blob);
}
else
{
assert_that(!blob, "Expected no compiled shader blob.\n");
assert_that(!!errors, "Expected non-NULL error blob.\n");
}
if (errors)
{
if (vkd3d_test_state.debug_level)
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
ID3D10Blob_Release(errors);
}
}
void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const struct shader_runner_ops *ops)
{
size_t shader_source_size = 0, shader_source_len = 0;
@ -722,6 +762,9 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const
break;
case STATE_SHADER_COMPUTE:
case STATE_SHADER_COMPUTE_TODO:
todo_if (state == STATE_SHADER_COMPUTE_TODO)
compile_shader(runner, shader_source, shader_source_len, "cs", false);
free(runner->cs_source);
runner->cs_source = shader_source;
shader_source = NULL;
@ -730,6 +773,9 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const
break;
case STATE_SHADER_PIXEL:
case STATE_SHADER_PIXEL_TODO:
todo_if (state == STATE_SHADER_PIXEL_TODO)
compile_shader(runner, shader_source, shader_source_len, "ps", false);
free(runner->ps_source);
runner->ps_source = shader_source;
shader_source = NULL;
@ -738,6 +784,7 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const
break;
case STATE_SHADER_VERTEX:
compile_shader(runner, shader_source, shader_source_len, "vs", false);
free(runner->vs_source);
runner->vs_source = shader_source;
shader_source = NULL;
@ -747,33 +794,10 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const
case STATE_SHADER_INVALID_PIXEL:
case STATE_SHADER_INVALID_PIXEL_TODO:
{
ID3D10Blob *blob = NULL, *errors = NULL;
HRESULT hr;
hr = D3DCompile(shader_source, strlen(shader_source), NULL,
NULL, NULL, "main", "ps_4_0", 0, 0, &blob, &errors);
todo_if (state == STATE_SHADER_INVALID_PIXEL_TODO)
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
if (hr == S_OK)
{
ID3D10Blob_Release(blob);
}
else
{
ok(!blob, "Expected no compiled shader blob.\n");
ok(!!errors, "Expected non-NULL error blob.\n");
}
if (errors)
{
if (vkd3d_test_state.debug_level)
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
ID3D10Blob_Release(errors);
}
compile_shader(runner, shader_source, shader_source_len, "ps", true);
shader_source_len = 0;
break;
}
case STATE_PREPROC_INVALID:
{
@ -840,6 +864,10 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const
{
state = STATE_SHADER_COMPUTE;
}
else if (!strcmp(line, "[compute shader todo]\n"))
{
state = STATE_SHADER_COMPUTE_TODO;
}
else if (!strcmp(line, "[require]\n"))
{
state = STATE_REQUIRE;
@ -848,6 +876,10 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const
{
state = STATE_SHADER_PIXEL;
}
else if (!strcmp(line, "[pixel shader todo]\n"))
{
state = STATE_SHADER_PIXEL_TODO;
}
else if (!strcmp(line, "[pixel shader fail]\n"))
{
state = STATE_SHADER_INVALID_PIXEL;
@ -962,9 +994,11 @@ void run_shader_tests(struct shader_runner *runner, int argc, char **argv, const
case STATE_PREPROC:
case STATE_PREPROC_INVALID:
case STATE_SHADER_COMPUTE:
case STATE_SHADER_COMPUTE_TODO:
case STATE_SHADER_INVALID_PIXEL:
case STATE_SHADER_INVALID_PIXEL_TODO:
case STATE_SHADER_PIXEL:
case STATE_SHADER_PIXEL_TODO:
case STATE_SHADER_VERTEX:
{
size_t len = strlen(line);

View File

@ -4,7 +4,7 @@ void main(out float tex : texcoord, inout float4 pos : sv_position)
tex = (pos.x + 1) * 320;
}
[pixel shader]
[pixel shader todo]
float4 main(float tex : texcoord) : sv_target
{
tex = floor(tex + 0.25);

View File

@ -13,7 +13,7 @@ size (1, 1)
0.5
[compute shader]
[compute shader todo]
RWTexture2D<float> u, v;
[numthreads(1, 1, 1)]
void main()

View File

@ -133,7 +133,7 @@ size (1, 1)
0.5 0.6 0.7 0.8
[pixel shader]
[pixel shader todo]
RWTexture2D<float4> u[2] : register(u2);
float4 main() : sv_target1