st/xorg: setup constant buffers for vertex and fragment shaders
authorZack Rusin <zackr@vmware.com>
Fri, 28 Aug 2009 20:43:21 +0000 (16:43 -0400)
committerZack Rusin <zackr@vmware.com>
Mon, 31 Aug 2009 17:26:01 +0000 (13:26 -0400)
src/gallium/state_trackers/xorg/xorg_composite.c

index af4ae05fb4ac98249bb2644bc1f5276ad789b9cd..ad14eb75ed7270436b2459b5eabfac32136dce82 100644 (file)
@@ -172,27 +172,10 @@ set_viewport(struct exa_context *exa, int width, int height,
 static void
 bind_viewport_state(struct exa_context *exa, PicturePtr pDstPicture)
 {
-   const int param_bytes = 8 * sizeof(float);
    int width = pDstPicture->pDrawable->width;
    int height = pDstPicture->pDrawable->height;
-   float vs_consts[8] = {
-      2.f/width, 2.f/height, 1, 1,
-      -1, -1, 0, 0
-   };
-   struct pipe_constant_buffer *cbuf = &exa->vs_const_buffer;
 
    set_viewport(exa, width, height, Y0_BOTTOM);
-
-   pipe_buffer_reference(&cbuf->buffer, NULL);
-   cbuf->buffer = pipe_buffer_create(exa->ctx->screen, 16,
-                                     PIPE_BUFFER_USAGE_CONSTANT,
-                                     param_bytes);
-
-   if (cbuf->buffer) {
-      pipe_buffer_write(exa->ctx->screen, cbuf->buffer,
-                        0, param_bytes, vs_consts);
-   }
-   exa->ctx->set_constant_buffer(exa->ctx, PIPE_SHADER_VERTEX, 0, cbuf);
 }
 
 static void
@@ -295,6 +278,61 @@ bind_samplers(struct exa_context *exa, int op,
    cso_set_sampler_textures(exa->cso, 3, textures);
 }
 
+static void
+setup_vs_constant_buffer(struct exa_context *exa,
+                         int width, int height)
+{
+   const int param_bytes = 8 * sizeof(float);
+   float vs_consts[8] = {
+      2.f/width, 2.f/height, 1, 1,
+      -1, -1, 0, 0
+   };
+   struct pipe_constant_buffer *cbuf = &exa->vs_const_buffer;
+
+   pipe_buffer_reference(&cbuf->buffer, NULL);
+   cbuf->buffer = pipe_buffer_create(exa->ctx->screen, 16,
+                                     PIPE_BUFFER_USAGE_CONSTANT,
+                                     param_bytes);
+
+   if (cbuf->buffer) {
+      pipe_buffer_write(exa->ctx->screen, cbuf->buffer,
+                        0, param_bytes, vs_consts);
+   }
+   exa->ctx->set_constant_buffer(exa->ctx, PIPE_SHADER_VERTEX, 0, cbuf);
+}
+
+
+static void
+setup_fs_constant_buffer(struct exa_context *exa)
+{
+   const int param_bytes = 4 * sizeof(float);
+   float fs_consts[8] = {
+      0, 0, 0, 1,
+   };
+   struct pipe_constant_buffer *cbuf = &exa->fs_const_buffer;
+
+   pipe_buffer_reference(&cbuf->buffer, NULL);
+   cbuf->buffer = pipe_buffer_create(exa->ctx->screen, 16,
+                                     PIPE_BUFFER_USAGE_CONSTANT,
+                                     param_bytes);
+
+   if (cbuf->buffer) {
+      pipe_buffer_write(exa->ctx->screen, cbuf->buffer,
+                        0, param_bytes, fs_consts);
+   }
+   exa->ctx->set_constant_buffer(exa->ctx, PIPE_SHADER_FRAGMENT, 0, cbuf);
+}
+
+static void
+setup_constant_buffers(struct exa_context *exa, PicturePtr pDstPicture)
+{
+   int width = pDstPicture->pDrawable->width;
+   int height = pDstPicture->pDrawable->height;
+
+   setup_vs_constant_buffer(exa, width, height);
+   setup_fs_constant_buffer(exa);
+}
+
 boolean xorg_composite_bind_state(struct exa_context *exa,
                                   int op,
                                   PicturePtr pSrcPicture,
@@ -312,6 +350,8 @@ boolean xorg_composite_bind_state(struct exa_context *exa,
    bind_samplers(exa, op, pSrcPicture, pMaskPicture, pDstPicture,
                  pSrc, pMask, pDst);
 
+   setup_constant_buffers(exa, pDstPicture);
+
    return FALSE;
 }