diff --git a/Makefile.am b/Makefile.am index d016ceed..e7971b1f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -203,6 +203,7 @@ vkd3d_shader_tests = \ tests/hlsl/uav-load.shader_test \ tests/hlsl/uav-out-param.shader_test \ tests/hlsl/uav-rwbuffer.shader_test \ + tests/hlsl/uav-rwbyteaddressbuffer.shader_test \ tests/hlsl/uav-rwstructuredbuffer.shader_test \ tests/hlsl/uav-rwtexture.shader_test \ tests/hlsl/uniform-parameters.shader_test \ diff --git a/tests/d3d12.c b/tests/d3d12.c index d7933ed6..fe42d36b 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -52,13 +52,6 @@ static bool compare_uint16(uint16_t a, uint16_t b, unsigned int max_diff) return abs(a - b) <= max_diff; } -static bool compare_uint64(uint64_t a, uint64_t b, unsigned int max_diff) -{ - uint64_t diff = a > b ? a - b : b - a; - - return diff <= max_diff; -} - static ULONG get_refcount(void *iface) { IUnknown *unk = iface; @@ -244,11 +237,6 @@ static uint16_t get_readback_uint16(struct resource_readback *rb, unsigned int x return *(uint16_t *)get_readback_data(rb, x, y, 0, sizeof(uint16_t)); } -static uint64_t get_readback_uint64(struct resource_readback *rb, unsigned int x, unsigned int y) -{ - return *(uint64_t *)get_readback_data(rb, x, y, 0, sizeof(uint64_t)); -} - #define check_sub_resource_float(a, b, c, d, e, f) check_sub_resource_float_(__LINE__, a, b, c, d, e, f) static void check_sub_resource_float_(unsigned int line, ID3D12Resource *resource, unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list, @@ -343,35 +331,6 @@ static void check_sub_resource_uint16_(unsigned int line, ID3D12Resource *resour release_resource_readback(&rb); } -#define check_readback_data_uint64(a, b, c, d) check_readback_data_uint64_(__LINE__, a, b, c, d) -static void check_readback_data_uint64_(unsigned int line, struct resource_readback *rb, - const RECT *rect, uint64_t expected, unsigned int max_diff) -{ - RECT r = {0, 0, rb->width, rb->height}; - unsigned int x = 0, y; - bool all_match = true; - uint64_t got = 0; - - if (rect) - r = *rect; - - for (y = r.top; y < r.bottom; ++y) - { - for (x = r.left; x < r.right; ++x) - { - got = get_readback_uint64(rb, x, y); - if (!compare_uint64(got, expected, max_diff)) - { - all_match = false; - break; - } - } - if (!all_match) - break; - } - ok_(line)(all_match, "Got %#"PRIx64", expected %#"PRIx64" at (%u, %u).\n", got, expected, x, y); -} - #define check_sub_resource_uint64(a, b, c, d, e, f) check_sub_resource_uint64_(__LINE__, a, b, c, d, e, f) static void check_sub_resource_uint64_(unsigned int line, ID3D12Resource *resource, unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list, diff --git a/tests/hlsl/uav-rwbyteaddressbuffer.shader_test b/tests/hlsl/uav-rwbyteaddressbuffer.shader_test new file mode 100644 index 00000000..056f94f6 --- /dev/null +++ b/tests/hlsl/uav-rwbyteaddressbuffer.shader_test @@ -0,0 +1,59 @@ +[require] +shader model >= 5.0 + +[uav 1] +format r32 float +size (buffer, 4) + +0.1 0.2 0.3 0.4 + +[pixel shader todo] +RWByteAddressBuffer u : register(u1); + +float4 main() : sv_target +{ + u.Store(0, 10); + u.Store(4, 11.1f); + return 0; +} + +[test] +todo(sm<6) draw quad +probe uav 1 (0) ri (10) +if(sm<6) probe uav 1 (1) ri (11) +if(sm>=6) probe uav 1 (1) r (11.1) + + +[pixel shader todo] +RWByteAddressBuffer u : register(u1); + +float4 main() : sv_target +{ + u.Store(0, (double)12.2); + return 0; +} + +[test] +todo draw quad +if(sm<6) probe uav 1 (0) ri (12) +if(sm>=6) probe uav 1 (0) rd (12.2) + + +% SM 6 add support for templated Store<>(). +[require] +shader model >= 6.0 + +[pixel shader] +RWByteAddressBuffer u : register(u1); + +float4 main() : sv_target +{ + u.Store(0, (int64_t)-12); + u.Store(8, 13.3); + return 0; +} + +[test] +todo draw quad +probe uav 1 (0) ri64 (-12) +probe uav 1 (1) rd (13.3) diff --git a/tests/shader_runner.c b/tests/shader_runner.c index d0d80650..0d6bb8ec 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -639,7 +639,7 @@ static void read_uint4(const char **line, struct uvec4 *v, bool is_uniform) read_uint(line, &v->w, is_uniform); } -static void read_int64(const char **line, int64_t *i) +static void read_int64(const char **line, int64_t *i, bool is_uniform) { char *rest; int64_t val; @@ -647,14 +647,14 @@ static void read_int64(const char **line, int64_t *i) errno = 0; val = strtoll(*line, &rest, 0); - if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest))) + if (errno != 0 || (is_uniform && *rest != '\0' && !isspace((unsigned char)*rest))) fatal_error("Malformed int64 constant '%s'.\n", *line); *i = val; - *line = rest; + *line = rest + (!is_uniform && *rest == ','); } -static void read_uint64(const char **line, uint64_t *u) +static void read_uint64(const char **line, uint64_t *u, bool is_uniform) { char *rest; uint64_t val; @@ -662,23 +662,23 @@ static void read_uint64(const char **line, uint64_t *u) errno = 0; val = strtoull(*line, &rest, 0); - if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest))) + if (errno != 0 || (is_uniform && *rest != '\0' && !isspace((unsigned char)*rest))) fatal_error("Malformed uint64 constant '%s'.\n", *line); *u = val; - *line = rest; + *line = rest + (!is_uniform && *rest == ','); } static void read_int64_t2(const char **line, struct i64vec2 *v) { - read_int64(line, &v->x); - read_int64(line, &v->y); + read_int64(line, &v->x, true); + read_int64(line, &v->y, true); } static void read_uint64_t2(const char **line, struct u64vec2 *v) { - read_uint64(line, &v->x); - read_uint64(line, &v->y); + read_uint64(line, &v->x, true); + read_uint64(line, &v->y, true); } static void parse_test_directive(struct shader_runner *runner, const char *line) @@ -951,6 +951,38 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) line = close_parentheses(line); todo_if(runner->is_todo) check_readback_data_uint(rb, &box, expect, 0); } + else if (match_string(line, "rui64", &line) || (is_signed = match_string(line, "ri64", &line))) + { + uint64_t expect; + D3D12_BOX box; + + box.left = rect.left; + box.right = rect.right; + box.top = rect.top; + box.bottom = rect.bottom; + box.front = 0; + box.back = 1; + if (*line != '(') + fatal_error("Malformed probe arguments '%s'.\n", line); + ++line; + if (is_signed) + read_int64(&line, (int64_t *)&expect, false); + else + read_uint64(&line, &expect, false); + line = close_parentheses(line); + todo_if(runner->is_todo) check_readback_data_uint64(rb, &box, expect, 0); + } + else if (match_string(line, "rd", &line)) + { + double expect; + + ret = sscanf(line, "( %lf ) %u", &expect, &ulps); + if (ret < 1) + fatal_error("Malformed probe arguments '%s'.\n", line); + if (ret < 2) + ulps = 0; + todo_if(runner->is_todo) check_readback_data_double(rb, &rect, expect, ulps); + } else if (match_string(line, "r", &line)) { float expect; diff --git a/tests/utils.h b/tests/utils.h index cd5215fe..03c9b578 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -104,6 +104,13 @@ static bool compare_uint(unsigned int x, unsigned int y, unsigned int max_diff) return diff <= max_diff; } +static bool compare_uint64(uint64_t x, uint64_t y, uint64_t max_diff) +{ + uint64_t diff = x > y ? x - y : y - x; + + return diff <= max_diff; +} + static bool compare_color(DWORD c1, DWORD c2, BYTE max_diff) { return compare_uint(c1 & 0xff, c2 & 0xff, max_diff) @@ -134,6 +141,28 @@ static bool compare_float(float f, float g, unsigned int ulps) return compare_uint(x, y, ulps); } +static bool compare_double(double f, double g, unsigned int ulps) +{ + int64_t x, y; + union + { + double f; + int64_t i; + } u; + + u.f = f; + x = u.i; + u.f = g; + y = u.i; + + if (x < 0) + x = INT64_MIN - x; + if (y < 0) + y = INT64_MIN - y; + + return compare_uint64(x, y, ulps); +} + static inline bool compare_uvec4(const struct uvec4 *v1, const struct uvec4 *v2) { return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w; @@ -167,11 +196,21 @@ static float get_readback_float(const struct resource_readback *rb, unsigned int return *(float *)get_readback_data(rb, x, y, 0, sizeof(float)); } +static double get_readback_double(const struct resource_readback *rb, unsigned int x, unsigned int y) +{ + return *(double *)get_readback_data(rb, x, y, 0, sizeof(double)); +} + static unsigned int get_readback_uint(const struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z) { return *(unsigned int*)get_readback_data(rb, x, y, z, sizeof(unsigned int)); } +static uint64_t get_readback_uint64(const struct resource_readback *rb, unsigned int x, unsigned int y) +{ + return *(uint64_t*)get_readback_data(rb, x, y, 0, sizeof(uint64_t)); +} + static const struct vec4 *get_readback_vec4(const struct resource_readback *rb, unsigned int x, unsigned int y) { return get_readback_data(rb, x, y, 0, sizeof(struct vec4)); @@ -211,6 +250,35 @@ static inline void check_readback_data_float_(unsigned int line, const struct re ok_(line)(all_match, "Got %.8e, expected %.8e at (%u, %u).\n", got, expected, x, y); } +#define check_readback_data_double(a, b, c, d) check_readback_data_double_(__LINE__, a, b, c, d) +static inline void check_readback_data_double_(unsigned int line, const struct resource_readback *rb, + const RECT *rect, double expected, unsigned int max_diff) +{ + RECT r = {0, 0, rb->width, rb->height}; + unsigned int x = 0, y; + bool all_match = true; + double got = 0; + + if (rect) + r = *rect; + + for (y = r.top; y < r.bottom; ++y) + { + for (x = r.left; x < r.right; ++x) + { + got = get_readback_double(rb, x, y); + if (!compare_double(got, expected, max_diff)) + { + all_match = false; + break; + } + } + if (!all_match) + break; + } + ok_(line)(all_match, "Got %.15le, expected %.15le at (%u, %u).\n", got, expected, x, y); +} + #define check_readback_data_uint(a, b, c, d) check_readback_data_uint_(__LINE__, a, b, c, d) static inline void check_readback_data_uint_(unsigned int line, struct resource_readback *rb, const D3D12_BOX *box, unsigned int expected, unsigned int max_diff) @@ -245,6 +313,35 @@ static inline void check_readback_data_uint_(unsigned int line, struct resource_ ok_(line)(all_match, "Got 0x%08x, expected 0x%08x at (%u, %u, %u).\n", got, expected, x, y, z); } +#define check_readback_data_uint64(a, b, c, d) check_readback_data_uint64_(__LINE__, a, b, c, d) +static inline void check_readback_data_uint64_(unsigned int line, struct resource_readback *rb, + const D3D12_BOX *box, uint64_t expected, unsigned int max_diff) +{ + D3D12_BOX b = {0, 0, 0, rb->width, rb->height, rb->depth}; + unsigned int x = 0, y = 0; + bool all_match = true; + uint64_t got = 0; + + if (box) + b = *box; + + for (y = b.top; y < b.bottom; ++y) + { + for (x = b.left; x < b.right; ++x) + { + got = get_readback_uint64(rb, x, y); + if (!compare_uint64(got, expected, max_diff)) + { + all_match = false; + break; + } + } + if (!all_match) + break; + } + ok_(line)(all_match, "Got 0x%016"PRIx64", expected 0x%016"PRIx64" at (%u, %u).\n", got, expected, x, y); +} + #define check_readback_data_vec4(a, b, c, d) check_readback_data_vec4_(__LINE__, a, b, c, d) static inline void check_readback_data_vec4_(unsigned int line, const struct resource_readback *rb, const RECT *rect, const struct vec4 *expected, unsigned int max_diff)