gallium: Refactor some single-pixel util_format_read/writes.
[mesa.git] / src / gallium / tests / trivial / compute.c
index 5d5e0b0b8c3dfd361c47f4fa5e09bc3c2f3026b8..cfdbdf1cc8dc29b3f3f9a416116c955db465b98c 100644 (file)
@@ -36,7 +36,7 @@
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
 #include "util/u_sampler.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
 #include "tgsi/tgsi_text.h"
 #include "pipe-loader/pipe_loader.h"
 
@@ -58,7 +58,9 @@ struct context {
                 uint64_t __v[4];                                        \
                 int __i, __n;                                           \
                                                                         \
-                __n = ctx->screen->get_compute_param(ctx->screen, c, __v); \
+                __n = ctx->screen->get_compute_param(ctx->screen,       \
+                                                     PIPE_SHADER_IR_TGSI, \
+                                                     c, __v);           \
                 printf("%s: {", #c);                                    \
                                                                         \
                 for (__i = 0; __i < __n / sizeof(*__v); ++__i)          \
@@ -144,6 +146,7 @@ static void init_prog(struct context *ctx, unsigned local_sz,
         struct pipe_context *pipe = ctx->pipe;
         struct tgsi_token prog[1024];
         struct pipe_compute_state cs = {
+                .ir_type = PIPE_SHADER_IR_TGSI,
                 .prog = prog,
                 .req_local_mem = local_sz,
                 .req_private_mem = private_sz,
@@ -152,7 +155,7 @@ static void init_prog(struct context *ctx, unsigned local_sz,
         char *psrc = preprocess_prog(ctx, src, defs);
         int ret;
 
-        ret = tgsi_text_translate(psrc, prog, Elements(prog));
+        ret = tgsi_text_translate(psrc, prog, ARRAY_SIZE(prog));
         assert(ret);
         free(psrc);
 
@@ -237,7 +240,7 @@ static void check_tex(struct context *ctx, int slot,
                   util_format_get_nblocksy(tex->format, tex->height0));
         struct pipe_transfer *xfer;
         char *map;
-        int x, y, i;
+        int x = 0, y, i;
         int err = 0;
 
         if (!check)
@@ -1069,7 +1072,7 @@ static void test_surface_ld_init0f(void *p, int s, int x, int y)
         float v[] = { 1.0, -.75, .50, -.25 };
         int i = 0;
 
-        util_format_write_4f(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
+        util_format_pack_rgba(surface_fmts[i], p, v, 1);
 }
 
 static void test_surface_ld_init0i(void *p, int s, int x, int y)
@@ -1077,7 +1080,7 @@ static void test_surface_ld_init0i(void *p, int s, int x, int y)
         int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
         int i = 0;
 
-        util_format_write_4i(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
+        util_format_pack_rgba(surface_fmts[i], p, v, 1);
 }
 
 static void test_surface_ld_expectf(void *p, int s, int x, int y)
@@ -1086,7 +1089,7 @@ static void test_surface_ld_expectf(void *p, int s, int x, int y)
         int i = 0;
 
         test_surface_ld_init0f(v, s, x / 4, y);
-        util_format_read_4f(surface_fmts[i], w, 0, v, 0, 0, 0, 1, 1);
+        util_format_unpack_rgba(surface_fmts[i], w, v, 1);
         *(float *)p = w[x % 4];
 }
 
@@ -1096,7 +1099,7 @@ static void test_surface_ld_expecti(void *p, int s, int x, int y)
         int i = 0;
 
         test_surface_ld_init0i(v, s, x / 4, y);
-        util_format_read_4i(surface_fmts[i], w, 0, v, 0, 0, 0, 1, 1);
+        util_format_unpack_rgba(surface_fmts[i], w, v, 1);
         *(uint32_t *)p = w[x % 4];
 }
 
@@ -1122,13 +1125,13 @@ static void test_surface_ld(struct context *ctx)
 
         init_prog(ctx, 0, 0, 0, src, NULL);
 
-        for (i = 0; i < Elements(surface_fmts); i++) {
+        for (i = 0; i < ARRAY_SIZE(surface_fmts); i++) {
                 bool is_int = util_format_is_pure_integer(surface_fmts[i]);
 
                 printf("   - %s\n", util_format_name(surface_fmts[i]));
 
                 if (!ctx->screen->is_format_supported(ctx->screen,
-                       surface_fmts[i], PIPE_TEXTURE_2D, 1,
+                       surface_fmts[i], PIPE_TEXTURE_2D, 1, 1,
                        PIPE_BIND_COMPUTE_RESOURCE)) {
                    printf("(unsupported)\n");
                    continue;
@@ -1177,7 +1180,7 @@ static void test_surface_st_expectf(void *p, int s, int x, int y)
 
         for (j = 0; j < 4; j++)
                 test_surface_st_init0f(&vf[j], s, 4 * x + j, y);
-        util_format_write_4f(surface_fmts[i], vf, 0, p, 0, 0, 0, 1, 1);
+        util_format_pack_rgba(surface_fmts[i], p, vf, 1);
 }
 
 static void test_surface_st_expects(void *p, int s, int x, int y)
@@ -1187,7 +1190,7 @@ static void test_surface_st_expects(void *p, int s, int x, int y)
 
         for (j = 0; j < 4; j++)
                 test_surface_st_init0i(&v[j], s, 4 * x + j, y);
-        util_format_write_4i(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
+        util_format_pack_rgba(surface_fmts[i], p, v, 1);
 }
 
 static void test_surface_st_expectu(void *p, int s, int x, int y)
@@ -1197,7 +1200,7 @@ static void test_surface_st_expectu(void *p, int s, int x, int y)
 
         for (j = 0; j < 4; j++)
                 test_surface_st_init0i(&v[j], s, 4 * x + j, y);
-        util_format_write_4ui(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
+        util_format_pack_rgba(surface_fmts[i], p, v, 1);
 }
 
 static bool test_surface_st_check(void *x, void *y, int sz)
@@ -1240,7 +1243,7 @@ static void test_surface_st(struct context *ctx)
 
         init_prog(ctx, 0, 0, 0, src, NULL);
 
-        for (i = 0; i < Elements(surface_fmts); i++) {
+        for (i = 0; i < ARRAY_SIZE(surface_fmts); i++) {
                 bool is_signed = (util_format_description(surface_fmts[i])
                                   ->channel[0].type == UTIL_FORMAT_TYPE_SIGNED);
                 bool is_int = util_format_is_pure_integer(surface_fmts[i]);
@@ -1248,7 +1251,7 @@ static void test_surface_st(struct context *ctx)
                 printf("   - %s\n", util_format_name(surface_fmts[i]));
 
                 if (!ctx->screen->is_format_supported(ctx->screen,
-                       surface_fmts[i], PIPE_TEXTURE_2D, 1,
+                       surface_fmts[i], PIPE_TEXTURE_2D, 1, 1,
                        PIPE_BIND_COMPUTE_RESOURCE)) {
                    printf("(unsupported)\n");
                    continue;