gallium: add flags parameter to pipe_screen::context_create
[mesa.git] / src / gallium / tests / trivial / compute.c
index 1812090d3a03c0187a85446d8e76605468ada439..b344f78b25c0cd87a36790ff23b10748eda4a513 100644 (file)
@@ -77,7 +77,7 @@ static void init_ctx(struct context *ctx)
         ctx->screen = pipe_loader_create_screen(ctx->dev, PIPE_SEARCH_DIR);
         assert(ctx->screen);
 
-        ctx->pipe = ctx->screen->context_create(ctx->screen, NULL);
+        ctx->pipe = ctx->screen->context_create(ctx->screen, NULL, 0);
         assert(ctx->pipe);
 
         DUMP_COMPUTE_PARAM(p, PIPE_COMPUTE_CAP_GRID_DIMENSION);
@@ -201,13 +201,11 @@ static void init_tex(struct context *ctx, int slot,
         *tex = ctx->screen->resource_create(ctx->screen, &ttex);
         assert(*tex);
 
-        xfer = pipe->get_transfer(pipe, *tex, 0, PIPE_TRANSFER_WRITE,
+        map = pipe->transfer_map(pipe, *tex, 0, PIPE_TRANSFER_WRITE,
                                   &(struct pipe_box) { .width = w,
                                                   .height = h,
-                                                  .depth = 1 });
+                                                  .depth = 1 }, &xfer);
         assert(xfer);
-
-        map = pipe->transfer_map(pipe, xfer);
         assert(map);
 
         for (y = 0; y < ny; ++y) {
@@ -217,7 +215,6 @@ static void init_tex(struct context *ctx, int slot,
         }
 
         pipe->transfer_unmap(pipe, xfer);
-        pipe->transfer_destroy(pipe, xfer);
 
         ctx->tex_rw[slot] = rw;
 }
@@ -246,13 +243,11 @@ static void check_tex(struct context *ctx, int slot,
         if (!check)
                 check = default_check;
 
-        xfer = pipe->get_transfer(pipe, tex, 0, PIPE_TRANSFER_READ,
+        map = pipe->transfer_map(pipe, tex, 0, PIPE_TRANSFER_READ,
                                   &(struct pipe_box) { .width = tex->width0,
                                         .height = tex->height0,
-                                        .depth = 1 });
+                                        .depth = 1 }, &xfer);
         assert(xfer);
-
-        map = pipe->transfer_map(pipe, xfer);
         assert(map);
 
         for (y = 0; y < ny; ++y) {
@@ -285,7 +280,6 @@ static void check_tex(struct context *ctx, int slot,
         }
 
         pipe->transfer_unmap(pipe, xfer);
-        pipe->transfer_destroy(pipe, xfer);
 
         if (err)
                 printf("(%d, %d): \x1b[31mFAIL\x1b[0m (%d)\n", x, y, err);
@@ -318,7 +312,7 @@ static void init_sampler_views(struct context *ctx, const int *slots)
                 assert(ctx->view[i]);
         }
 
-        pipe->set_compute_sampler_views(pipe, 0, i, ctx->view);
+        pipe->set_sampler_views(pipe, PIPE_SHADER_COMPUTE, 0, i, ctx->view);
 }
 
 static void destroy_sampler_views(struct context *ctx)
@@ -326,7 +320,7 @@ static void destroy_sampler_views(struct context *ctx)
         struct pipe_context *pipe = ctx->pipe;
         int i;
 
-        pipe->set_compute_sampler_views(pipe, 0, MAX_RESOURCES, NULL);
+        pipe->set_sampler_views(pipe, PIPE_SHADER_COMPUTE, 0, MAX_RESOURCES, NULL);
 
         for (i = 0; i < MAX_RESOURCES; ++i) {
                 if (ctx->view[i]) {
@@ -344,7 +338,6 @@ static void init_compute_resources(struct context *ctx, const int *slots)
         for (i = 0; *slots >= 0; ++i, ++slots) {
                 struct pipe_surface tsurf = {
                         .format = ctx->tex[*slots]->format,
-                        .usage = ctx->tex[*slots]->bind,
                         .writable = ctx->tex_rw[*slots]
                 };
 
@@ -387,7 +380,7 @@ static void init_sampler_states(struct context *ctx, int n)
                 assert(ctx->hwsmp[i]);
         }
 
-        pipe->bind_compute_sampler_states(pipe, 0, i, ctx->hwsmp);
+        pipe->bind_sampler_states(pipe, PIPE_SHADER_COMPUTE, 0, i, ctx->hwsmp);
 }
 
 static void destroy_sampler_states(struct context *ctx)
@@ -395,7 +388,8 @@ static void destroy_sampler_states(struct context *ctx)
         struct pipe_context *pipe = ctx->pipe;
         int i;
 
-        pipe->bind_compute_sampler_states(pipe, 0, MAX_RESOURCES, NULL);
+        pipe->bind_sampler_states(pipe, PIPE_SHADER_COMPUTE,
+                                 0, MAX_RESOURCES, NULL);
 
         for (i = 0; i < MAX_RESOURCES; ++i) {
                 if (ctx->hwsmp[i]) {
@@ -1083,6 +1077,13 @@ static void test_surface_ld(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,
+                       PIPE_BIND_COMPUTE_RESOURCE)) {
+                   printf("(unsupported)\n");
+                   continue;
+                }
+
                 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, surface_fmts[i],
                          128, 32, (is_int ? init0i : init0f));
                 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
@@ -1183,6 +1184,13 @@ 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,
+                       PIPE_BIND_COMPUTE_RESOURCE)) {
+                   printf("(unsupported)\n");
+                   continue;
+                }
+
                 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
                          512, 32, (is_int ? init0i : init0f));
                 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, surface_fmts[i],
@@ -1568,24 +1576,45 @@ int main(int argc, char *argv[])
 {
         struct context *ctx = CALLOC_STRUCT(context);
 
+        unsigned tests = (argc > 1) ? strtoul(argv[1], NULL, 0) : ~0;
+
         init_ctx(ctx);
-        test_system_values(ctx);
-        test_resource_access(ctx);
-        test_function_calls(ctx);
-        test_input_global(ctx);
-        test_private(ctx);
-        test_local(ctx);
-        test_sample(ctx);
-        test_many_kern(ctx);
-        test_constant(ctx);
-        test_resource_indirect(ctx);
-        test_surface_ld(ctx);
-        test_surface_st(ctx);
-        test_barrier(ctx);
-        test_atom_ops(ctx, true);
-        test_atom_race(ctx, true);
-        test_atom_ops(ctx, false);
-        test_atom_race(ctx, false);
+
+        if (tests & (1 << 0))
+           test_system_values(ctx);
+        if (tests & (1 << 1))
+           test_resource_access(ctx);
+        if (tests & (1 << 2))
+           test_function_calls(ctx);
+        if (tests & (1 << 3))
+           test_input_global(ctx);
+        if (tests & (1 << 4))
+           test_private(ctx);
+        if (tests & (1 << 5))
+           test_local(ctx);
+        if (tests & (1 << 6))
+           test_sample(ctx);
+        if (tests & (1 << 7))
+           test_many_kern(ctx);
+        if (tests & (1 << 8))
+           test_constant(ctx);
+        if (tests & (1 << 9))
+           test_resource_indirect(ctx);
+        if (tests & (1 << 10))
+           test_surface_ld(ctx);
+        if (tests & (1 << 11))
+           test_surface_st(ctx);
+        if (tests & (1 << 12))
+           test_barrier(ctx);
+        if (tests & (1 << 13))
+           test_atom_ops(ctx, true);
+        if (tests & (1 << 14))
+           test_atom_race(ctx, true);
+        if (tests & (1 << 15))
+           test_atom_ops(ctx, false);
+        if (tests & (1 << 16))
+           test_atom_race(ctx, false);
+
         destroy_ctx(ctx);
 
         return 0;