mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
tests: Read integer uniforms with strtol() and strtoul().
Because %i sscanf() converters are deprecated, and in practice clamp to [-2^31, 2^31) on 32 bit.
This commit is contained in:
committed by
Alexandre Julliard
parent
eb71c5f20d
commit
9a27df3a8c
Notes:
Alexandre Julliard
2023-04-03 22:09:37 +02:00
Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/129
@@ -28,11 +28,6 @@ struct test_options test_options = {0};
|
|||||||
static PFN_D3D12_CREATE_VERSIONED_ROOT_SIGNATURE_DESERIALIZER pfn_D3D12CreateVersionedRootSignatureDeserializer;
|
static PFN_D3D12_CREATE_VERSIONED_ROOT_SIGNATURE_DESERIALIZER pfn_D3D12CreateVersionedRootSignatureDeserializer;
|
||||||
static PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE pfn_D3D12SerializeVersionedRootSignature;
|
static PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE pfn_D3D12SerializeVersionedRootSignature;
|
||||||
|
|
||||||
struct ivec4
|
|
||||||
{
|
|
||||||
int x, y, z, w;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dvec2
|
struct dvec2
|
||||||
{
|
{
|
||||||
double x, y;
|
double x, y;
|
||||||
|
@@ -371,6 +371,58 @@ static void set_uniforms(struct shader_runner *runner, size_t offset, size_t cou
|
|||||||
memcpy(runner->uniforms + offset, uniforms, count * sizeof(*runner->uniforms));
|
memcpy(runner->uniforms + offset, uniforms, count * sizeof(*runner->uniforms));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void read_int(const char **line, int *i)
|
||||||
|
{
|
||||||
|
char *rest;
|
||||||
|
long val;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
val = strtol(*line, &rest, 0);
|
||||||
|
|
||||||
|
if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest)))
|
||||||
|
fatal_error("Malformed int constant '%s'.\n", *line);
|
||||||
|
|
||||||
|
*i = val;
|
||||||
|
if (*i != val)
|
||||||
|
fatal_error("Out of range int constant '%.*s'.\n", (int)(rest - *line), *line);
|
||||||
|
|
||||||
|
*line = rest;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void read_uint(const char **line, unsigned int *u)
|
||||||
|
{
|
||||||
|
char *rest;
|
||||||
|
unsigned long val;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
val = strtoul(*line, &rest, 0);
|
||||||
|
|
||||||
|
if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest)))
|
||||||
|
fatal_error("Malformed uint constant '%s'.\n", *line);
|
||||||
|
|
||||||
|
*u = val;
|
||||||
|
if (*u != val)
|
||||||
|
fatal_error("Out of range uint constant '%.*s'.\n", (int)(rest - *line), *line);
|
||||||
|
|
||||||
|
*line = rest;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void read_int4(const char **line, struct ivec4 *v)
|
||||||
|
{
|
||||||
|
read_int(line, &v->x);
|
||||||
|
read_int(line, &v->y);
|
||||||
|
read_int(line, &v->z);
|
||||||
|
read_int(line, &v->w);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void read_uint4(const char **line, struct uvec4 *v)
|
||||||
|
{
|
||||||
|
read_uint(line, &v->x);
|
||||||
|
read_uint(line, &v->y);
|
||||||
|
read_uint(line, &v->z);
|
||||||
|
read_uint(line, &v->w);
|
||||||
|
}
|
||||||
|
|
||||||
static void parse_test_directive(struct shader_runner *runner, const char *line)
|
static void parse_test_directive(struct shader_runner *runner, const char *line)
|
||||||
{
|
{
|
||||||
char *rest;
|
char *rest;
|
||||||
@@ -590,28 +642,32 @@ static void parse_test_directive(struct shader_runner *runner, const char *line)
|
|||||||
fatal_error("Malformed float constant '%s'.\n", line);
|
fatal_error("Malformed float constant '%s'.\n", line);
|
||||||
set_uniforms(runner, offset, 1, &f);
|
set_uniforms(runner, offset, 1, &f);
|
||||||
}
|
}
|
||||||
else if (match_string(line, "int4", &line) || match_string(line, "uint4", &line))
|
else if (match_string(line, "int4", &line))
|
||||||
{
|
{
|
||||||
int v[4];
|
struct ivec4 v;
|
||||||
|
|
||||||
if (sscanf(line, "%i %i %i %i", &v[0], &v[1], &v[2], &v[3]) < 4)
|
read_int4(&line, &v);
|
||||||
fatal_error("Malformed (u)int4 constant '%s'.\n", line);
|
set_uniforms(runner, offset, 4, &v);
|
||||||
set_uniforms(runner, offset, 4, v);
|
}
|
||||||
|
else if (match_string(line, "uint4", &line))
|
||||||
|
{
|
||||||
|
struct uvec4 v;
|
||||||
|
|
||||||
|
read_uint4(&line, &v);
|
||||||
|
set_uniforms(runner, offset, 4, &v);
|
||||||
}
|
}
|
||||||
else if (match_string(line, "int", &line))
|
else if (match_string(line, "int", &line))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (sscanf(line, "%i", &i) < 1)
|
read_int(&line, &i);
|
||||||
fatal_error("Malformed int constant '%s'.\n", line);
|
|
||||||
set_uniforms(runner, offset, 1, &i);
|
set_uniforms(runner, offset, 1, &i);
|
||||||
}
|
}
|
||||||
else if (match_string(line, "uint", &line))
|
else if (match_string(line, "uint", &line))
|
||||||
{
|
{
|
||||||
unsigned int u;
|
unsigned int u;
|
||||||
|
|
||||||
if (sscanf(line, "%u", &u) < 1)
|
read_uint(&line, &u);
|
||||||
fatal_error("Malformed uint constant '%s'.\n", line);
|
|
||||||
set_uniforms(runner, offset, 1, &u);
|
set_uniforms(runner, offset, 1, &u);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -35,6 +35,11 @@ struct vec4
|
|||||||
float x, y, z, w;
|
float x, y, z, w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ivec4
|
||||||
|
{
|
||||||
|
int x, y, z, w;
|
||||||
|
};
|
||||||
|
|
||||||
struct uvec4
|
struct uvec4
|
||||||
{
|
{
|
||||||
unsigned int x, y, z, w;
|
unsigned int x, y, z, w;
|
||||||
|
Reference in New Issue
Block a user