graw/fs-test: Use user constant buffers.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 26 Oct 2012 14:12:31 +0000 (15:12 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 26 Oct 2012 15:02:59 +0000 (16:02 +0100)
Much simpler. More interesting.

src/gallium/tests/graw/fs-test.c

index f31034406f619dcf890cd4d5bfc99a6d50550ff8..51be87478f771039fe550242cab1e2a61d3467b9 100644 (file)
@@ -42,8 +42,6 @@ static const int HEIGHT = 250;
 static struct pipe_screen *screen = NULL;
 static struct pipe_context *ctx = NULL;
 static struct pipe_resource *rttex = NULL;
-static struct pipe_resource *constbuf1 = NULL;
-static struct pipe_resource *constbuf2 = NULL;
 static struct pipe_surface *surf = NULL;
 static struct pipe_sampler_view *sv = NULL;
 static void *sampler = NULL;
@@ -111,64 +109,24 @@ static float constants2[] =
 
 static void init_fs_constbuf( void )
 {
-   struct pipe_resource templat;
-   struct pipe_box box;
-
-   templat.target = PIPE_BUFFER;
-   templat.format = PIPE_FORMAT_R8_UNORM;
-   templat.width0 = sizeof(constants1);
-   templat.height0 = 1;
-   templat.depth0 = 1;
-   templat.array_size = 1;
-   templat.last_level = 0;
-   templat.nr_samples = 1;
-   templat.bind = PIPE_BIND_CONSTANT_BUFFER;
+   struct pipe_constant_buffer cb1;
+   struct pipe_constant_buffer cb2;
 
-   constbuf1 = screen->resource_create(screen,
-                                       &templat);
-   if (constbuf1 == NULL)
-      exit(4);
+   memset(&cb1, 0, sizeof cb1);
+   cb1.buffer_size = sizeof constants1;
+   cb1.user_buffer = constants1;
 
-   constbuf2 = screen->resource_create(screen,
-                                       &templat);
-   if (constbuf2 == NULL)
-      exit(4);
+   ctx->set_constant_buffer(ctx,
+                            PIPE_SHADER_FRAGMENT, 0,
+                            &cb1);
 
+   memset(&cb2, 0, sizeof cb2);
+   cb2.buffer_size = sizeof constants2;
+   cb2.user_buffer = constants2;
 
-   {
-      u_box_2d(0,0,sizeof(constants1),1, &box);
-
-      ctx->transfer_inline_write(ctx,
-                                 constbuf1,
-                                 0,
-                                 PIPE_TRANSFER_WRITE,
-                                 &box,
-                                 constants1,
-                                 sizeof constants1,
-                                 sizeof constants1);
-
-
-      pipe_set_constant_buffer(ctx,
-                               PIPE_SHADER_FRAGMENT, 0,
-                               constbuf1);
-   }
-   {
-      u_box_2d(0,0,sizeof(constants2),1, &box);
-
-      ctx->transfer_inline_write(ctx,
-                                 constbuf2,
-                                 0,
-                                 PIPE_TRANSFER_WRITE,
-                                 &box,
-                                 constants2,
-                                 sizeof constants2,
-                                 sizeof constants2);
-
-
-      pipe_set_constant_buffer(ctx,
-                               PIPE_SHADER_FRAGMENT, 1,
-                               constbuf2);
-   }
+   ctx->set_constant_buffer(ctx,
+                            PIPE_SHADER_FRAGMENT, 1,
+                            &cb2);
 }