tests: Add a helper to set uniforms.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2022-01-26 19:40:32 -06:00 committed by Alexandre Julliard
parent 3994cec7b1
commit ecbdd8f994
2 changed files with 13 additions and 25 deletions

View File

@ -276,6 +276,14 @@ static void parse_texture_directive(struct texture_params *texture, const char *
} }
} }
static void set_uniforms(struct shader_context *context, size_t offset, size_t count, const void *uniforms)
{
context->uniform_count = max(context->uniform_count, offset + count);
vkd3d_array_reserve((void **)&context->uniforms, &context->uniform_capacity,
context->uniform_count, sizeof(*context->uniforms));
memcpy(context->uniforms + offset, uniforms, count * sizeof(*context->uniforms));
}
static void parse_test_directive(struct shader_context *context, const char *line) static void parse_test_directive(struct shader_context *context, const char *line)
{ {
if (match_string(line, "draw quad", &line)) if (match_string(line, "draw quad", &line))
@ -350,12 +358,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%f %f %f %f", &v.x, &v.y, &v.z, &v.w) < 4) if (sscanf(line, "%f %f %f %f", &v.x, &v.y, &v.z, &v.w) < 4)
fatal_error("Malformed float4 constant '%s'.\n", line); fatal_error("Malformed float4 constant '%s'.\n", line);
if (offset + 4 > context->uniform_count) set_uniforms(context, offset, 4, &v);
{
context->uniform_count = offset + 4;
context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
}
memcpy(context->uniforms + offset, &v, sizeof(v));
} }
else if (match_string(line, "float", &line)) else if (match_string(line, "float", &line))
{ {
@ -363,12 +366,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%f", &f) < 1) if (sscanf(line, "%f", &f) < 1)
fatal_error("Malformed float constant '%s'.\n", line); fatal_error("Malformed float constant '%s'.\n", line);
if (offset + 1 > context->uniform_count) set_uniforms(context, offset, 1, &f);
{
context->uniform_count = offset + 1;
context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
}
memcpy(context->uniforms + offset, &f, sizeof(f));
} }
else if (match_string(line, "int", &line)) else if (match_string(line, "int", &line))
{ {
@ -376,12 +374,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%i", &i) < 1) if (sscanf(line, "%i", &i) < 1)
fatal_error("Malformed int constant '%s'.\n", line); fatal_error("Malformed int constant '%s'.\n", line);
if (offset + 1 > context->uniform_count) set_uniforms(context, offset, 1, &i);
{
context->uniform_count = offset + 1;
context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
}
memcpy(context->uniforms + offset, &i, sizeof(i));
} }
else if (match_string(line, "uint", &line)) else if (match_string(line, "uint", &line))
{ {
@ -389,12 +382,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%u", &u) < 1) if (sscanf(line, "%u", &u) < 1)
fatal_error("Malformed uint constant '%s'.\n", line); fatal_error("Malformed uint constant '%s'.\n", line);
if (offset + 1 > context->uniform_count) set_uniforms(context, offset, 1, &u);
{
context->uniform_count = offset + 1;
context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
}
memcpy(context->uniforms + offset, &u, sizeof(u));
} }
} }
else else

View File

@ -70,7 +70,7 @@ struct shader_context
enum shader_model minimum_shader_model; enum shader_model minimum_shader_model;
uint32_t *uniforms; uint32_t *uniforms;
size_t uniform_count; size_t uniform_count, uniform_capacity;
struct texture **textures; struct texture **textures;
size_t texture_count; size_t texture_count;