[PATCH vkd3d v2 6/7] tests: Add a helper to set uniforms.
Zebediah Figura
zfigura at codeweavers.com
Fri Jan 14 17:33:07 CST 2022
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
tests/shader_runner.c | 36 ++++++++++++------------------------
tests/shader_runner.h | 2 +-
2 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c
index 701a7e8b0..d64d04380 100644
--- a/tests/shader_runner.c
+++ b/tests/shader_runner.c
@@ -240,6 +240,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)
{
if (match_string(line, "draw quad", &line))
@@ -314,12 +322,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)
fatal_error("Malformed float4 constant '%s'.\n", line);
- if (offset + 4 > context->uniform_count)
- {
- context->uniform_count = offset + 4;
- context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
- }
- memcpy(context->uniforms + offset, &v, sizeof(v));
+ set_uniforms(context, offset, 4, &v);
}
else if (match_string(line, "float", &line))
{
@@ -327,12 +330,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%f", &f) < 1)
fatal_error("Malformed float constant '%s'.\n", line);
- if (offset + 1 > context->uniform_count)
- {
- context->uniform_count = offset + 1;
- context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
- }
- memcpy(context->uniforms + offset, &f, sizeof(f));
+ set_uniforms(context, offset, 1, &f);
}
else if (match_string(line, "int", &line))
{
@@ -340,12 +338,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%i", &i) < 1)
fatal_error("Malformed int constant '%s'.\n", line);
- if (offset + 1 > context->uniform_count)
- {
- context->uniform_count = offset + 1;
- context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
- }
- memcpy(context->uniforms + offset, &i, sizeof(i));
+ set_uniforms(context, offset, 1, &i);
}
else if (match_string(line, "uint", &line))
{
@@ -353,12 +346,7 @@ static void parse_test_directive(struct shader_context *context, const char *lin
if (sscanf(line, "%u", &u) < 1)
fatal_error("Malformed uint constant '%s'.\n", line);
- if (offset + 1 > context->uniform_count)
- {
- context->uniform_count = offset + 1;
- context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
- }
- memcpy(context->uniforms + offset, &u, sizeof(u));
+ set_uniforms(context, offset, 1, &u);
}
}
else
diff --git a/tests/shader_runner.h b/tests/shader_runner.h
index c2337e9be..4dd518e1d 100644
--- a/tests/shader_runner.h
+++ b/tests/shader_runner.h
@@ -63,7 +63,7 @@ struct shader_context
char *ps_source;
uint32_t *uniforms;
- size_t uniform_count;
+ size_t uniform_count, uniform_capacity;
struct texture **textures;
size_t texture_count;
--
2.34.1
More information about the wine-devel
mailing list