r300g: fix the size of constant buffers
authorMarek Olšák <maraeo@gmail.com>
Sun, 14 Feb 2010 23:04:32 +0000 (00:04 +0100)
committerMarek Olšák <maraeo@gmail.com>
Mon, 15 Feb 2010 03:03:12 +0000 (04:03 +0100)
4 more piglit tests pass, sweet.

src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r300/r300_state.c

index ac2b08b41c208fb35380c967cb35a49addbef044..1eba8a8ed12e2abba8f79aa2dc52e6f6a915a040 100644 (file)
@@ -155,8 +155,7 @@ struct r300_ztop_state {
 
 struct r300_constant_buffer {
     /* Buffer of constants */
-    /* XXX first number should be raised */
-    float constants[32][4];
+    float constants[256][4];
     /* Total number of constants */
     unsigned count;
 };
index 8e9f51aba2d919061144dc689cc3b92c4e457b5c..b892c084c04e17ea2e8bb316a9f64b2767ccbe2f 100644 (file)
@@ -152,6 +152,10 @@ static int r300_get_param(struct pipe_screen* pscreen, int param)
             } else {
                 return 0;
             }
+        case PIPE_CAP_MAX_CONST_BUFFERS:
+            return 1;
+        case PIPE_CAP_MAX_CONST_BUFFER_SIZE:
+            return 256;
         case PIPE_CAP_INDEP_BLEND_ENABLE:
             return 0;
         case PIPE_CAP_INDEP_BLEND_FUNC:
index b4c8ca45ab73e8a3e2e65af2cf6bda12b04b5394..34bf81c1930cb05b0fa023fdd6904a4c208742f5 100644 (file)
@@ -1150,7 +1150,9 @@ static void r300_set_constant_buffer(struct pipe_context *pipe,
                                      struct pipe_buffer *buf)
 {
     struct r300_context* r300 = r300_context(pipe);
+    struct r300_screen *r300screen = r300_screen(pipe->screen);
     void *mapped;
+    int max_size = 0;
 
     if (buf == NULL || buf->size == 0 ||
         (mapped = pipe_buffer_map(pipe->screen, buf, PIPE_BUFFER_USAGE_CPU_READ)) == NULL)
@@ -1160,6 +1162,33 @@ static void r300_set_constant_buffer(struct pipe_context *pipe,
     }
 
     assert((buf->size % 4 * sizeof(float)) == 0);
+
+    /* Check the size of the constant buffer. */
+    switch (shader) {
+        case PIPE_SHADER_VERTEX:
+            max_size = 256;
+            break;
+        case PIPE_SHADER_FRAGMENT:
+            if (r300screen->caps->is_r500) {
+                max_size = 256;
+            /* XXX Implement emission of r400's extended constant buffer. */
+            /*} else if (r300screen->caps->is_r400) {
+                max_size = 64;*/
+            } else {
+                max_size = 32;
+            }
+            break;
+        default:
+            assert(0);
+    }
+
+    /* XXX Subtract immediates and RC_STATE_* variables. */
+    if (buf->size > (sizeof(float) * 4 * max_size)) {
+        debug_printf("r300: Max size of the constant buffer is "
+                      "%i*4 floats.\n", max_size);
+        abort();
+    }
+
     memcpy(r300->shader_constants[shader].constants, mapped, buf->size);
     r300->shader_constants[shader].count = buf->size / (4 * sizeof(float));
     pipe_buffer_unmap(pipe->screen, buf);