[PATCH vkd3d 3/5] tests: Pass HLSL source to the draw_quad() function.

Zebediah Figura zfigura at codeweavers.com
Tue Jan 11 12:16:50 CST 2022


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 tests/shader_runner.c       | 17 +++++++----------
 tests/shader_runner.h       |  3 +--
 tests/shader_runner_d3d12.c | 13 +++++++++----
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/tests/shader_runner.c b/tests/shader_runner.c
index 052415947..f6fd028f8 100644
--- a/tests/shader_runner.c
+++ b/tests/shader_runner.c
@@ -71,7 +71,7 @@ struct shader_context
     const struct shader_runner_ops *ops;
     void *private;
 
-    ID3D10Blob *ps_code;
+    char *ps_source;
 
     uint32_t *uniforms;
     size_t uniform_count;
@@ -269,7 +269,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
     {
         const struct draw_params params =
         {
-            .ps_code = context->ps_code,
+            .ps_source = context->ps_source,
 
             .uniforms = context->uniforms,
             .uniform_count = context->uniform_count,
@@ -490,9 +490,11 @@ void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops
                     break;
 
                 case STATE_SHADER_PIXEL:
-                    if (!(context.ps_code = context.ops->compile_shader(context.private, shader_source)))
-                        return;
+                    free(context.ps_source);
+                    context.ps_source = shader_source;
+                    shader_source = NULL;
                     shader_source_len = 0;
+                    shader_source_size = 0;
                     break;
 
                 case STATE_SHADER_INVALID_PIXEL:
@@ -580,10 +582,6 @@ void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops
             if (!strcmp(line, "[pixel shader]\n"))
             {
                 state = STATE_SHADER_PIXEL;
-
-                if (context.ps_code)
-                    ID3D10Blob_Release(context.ps_code);
-                context.ps_code = NULL;
             }
             else if (!strcmp(line, "[pixel shader fail]\n"))
             {
@@ -681,8 +679,7 @@ void run_shader_tests(int argc, char **argv, const struct shader_runner_ops *ops
         }
     }
 
-    if (context.ps_code)
-        ID3D10Blob_Release(context.ps_code);
+    free(context.ps_source);
     for (i = 0; i < context.texture_count; ++i)
         free_texture(&context.textures[i]);
 
diff --git a/tests/shader_runner.h b/tests/shader_runner.h
index ec152978e..cb3486b35 100644
--- a/tests/shader_runner.h
+++ b/tests/shader_runner.h
@@ -55,7 +55,7 @@ struct texture
 
 struct draw_params
 {
-    ID3D10Blob *ps_code;
+    const char *ps_source;
 
     const uint32_t *uniforms;
     size_t uniform_count;
@@ -69,7 +69,6 @@ struct draw_params
 
 struct shader_runner_ops
 {
-    ID3D10Blob *(*compile_shader)(void *private, const char *source);
     void (*draw_quad)(void *private, const struct draw_params *params);
     void (*probe_vec4)(void *private, const RECT *rect, const struct vec4 *v, unsigned int ulps);
 };
diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c
index 5c9db69c0..2bb1a9bac 100644
--- a/tests/shader_runner_d3d12.c
+++ b/tests/shader_runner_d3d12.c
@@ -31,7 +31,7 @@ struct d3d12_texture
     unsigned int root_index;
 };
 
-static ID3D10Blob *d3d12_runner_compile_shader(void *private, const char *source)
+static ID3D10Blob *compile_shader(const char *source)
 {
     ID3D10Blob *blob = NULL, *errors = NULL;
     HRESULT hr;
@@ -51,8 +51,6 @@ static void d3d12_runner_draw_quad(void *private, const struct draw_params *para
 {
     struct test_context *context = private;
 
-    D3D12_SHADER_BYTECODE ps
-            = {ID3D10Blob_GetBufferPointer(params->ps_code), ID3D10Blob_GetBufferSize(params->ps_code)};
     ID3D12GraphicsCommandList *command_list = context->list;
     D3D12_ROOT_SIGNATURE_DESC root_signature_desc = {0};
     D3D12_ROOT_PARAMETER root_params[3], *root_param;
@@ -60,10 +58,15 @@ static void d3d12_runner_draw_quad(void *private, const struct draw_params *para
     ID3D12Device *device = context->device;
     static const float clear_color[4];
     unsigned int uniform_index;
+    D3D12_SHADER_BYTECODE ps;
     ID3D12PipelineState *pso;
+    ID3D10Blob *ps_code;
     HRESULT hr;
     size_t i;
 
+    if (!(ps_code = compile_shader(params->ps_source)))
+        return;
+
     root_signature_desc.NumParameters = 0;
     root_signature_desc.pParameters = root_params;
     root_signature_desc.NumStaticSamplers = 0;
@@ -142,8 +145,11 @@ static void d3d12_runner_draw_quad(void *private, const struct draw_params *para
     hr = create_root_signature(device, &root_signature_desc, &context->root_signature);
     ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr);
 
+    ps.pShaderBytecode = ID3D10Blob_GetBufferPointer(ps_code);
+    ps.BytecodeLength = ID3D10Blob_GetBufferSize(ps_code);
     pso = create_pipeline_state(device, context->root_signature,
             context->render_target_desc.Format, NULL, &ps, NULL);
+    ID3D10Blob_Release(ps_code);
     if (!pso)
         return;
     vkd3d_array_reserve((void **)&context->pso, &context->pso_capacity, context->pso_count + 1, sizeof(*context->pso));
@@ -201,7 +207,6 @@ static void d3d12_runner_probe_vec4(void *private, const RECT *rect, const struc
 
 static const struct shader_runner_ops d3d12_runner_ops =
 {
-    .compile_shader = d3d12_runner_compile_shader,
     .draw_quad = d3d12_runner_draw_quad,
     .probe_vec4 = d3d12_runner_probe_vec4,
 };
-- 
2.34.1




More information about the wine-devel mailing list