r300g: atomize VS constant buffer
authorMarek Olšák <maraeo@gmail.com>
Wed, 14 Apr 2010 02:12:08 +0000 (04:12 +0200)
committerMarek Olšák <maraeo@gmail.com>
Wed, 14 Apr 2010 02:48:19 +0000 (04:48 +0200)
src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_defines.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_emit.h
src/gallium/drivers/r300/r300_flush.c
src/gallium/drivers/r300/r300_state.c

index bdc1ebedcc05f83b2726f7473bac960cdf92f12d..9a235baf7d70c5fb7cce6b5f011420eeb69b288e 100644 (file)
@@ -67,6 +67,7 @@ static void r300_destroy_context(struct pipe_context* context)
     FREE(r300->viewport_state.state);
     FREE(r300->ztop_state.state);
     FREE(r300->fs_constants.state);
+    FREE(r300->vs_constants.state);
     FREE(r300);
 }
 
@@ -114,6 +115,7 @@ static void r300_setup_atoms(struct r300_context* r300)
     R300_INIT_ATOM(vap_output_state, 6);
     R300_INIT_ATOM(pvs_flush, 2);
     R300_INIT_ATOM(vs_state, 0);
+    R300_INIT_ATOM(vs_constants, 0);
     R300_INIT_ATOM(texture_cache_inval, 2);
     R300_INIT_ATOM(textures_state, 0);
     R300_INIT_ATOM(fs, 0);
@@ -138,6 +140,7 @@ static void r300_setup_atoms(struct r300_context* r300)
     r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state);
     r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state);
     r300->fs_constants.state = CALLOC_STRUCT(r300_constant_buffer);
+    r300->vs_constants.state = CALLOC_STRUCT(r300_constant_buffer);
 }
 
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
index 6ab10c874ddddf987e31c979afd5886d13473fcf..2655e7e0e1405858158241852e1a0ac2aa0b6cea 100644 (file)
@@ -362,8 +362,6 @@ struct r300_context {
     struct r300_atom blend_color_state;
     /* User clip planes. */
     struct r300_atom clip_state;
-    /* Shader constants. */
-    struct r300_constant_buffer shader_constants[PIPE_SHADER_TYPES];
     /* Depth, stencil, and alpha state. */
     struct r300_atom dsa_state;
     /* Fragment shader. */
@@ -388,6 +386,8 @@ struct r300_context {
     struct r300_atom vap_output_state;
     /* Vertex shader. */
     struct r300_atom vs_state;
+    /* Vertex shader constant buffer. */
+    struct r300_atom vs_constants;
     /* Viewport state. */
     struct r300_atom viewport_state;
     /* ZTOP state. */
index da85137625c2f482a5395d8bcd745a062ac453aa..0c3b970501d72375631b1911fd7ca5ab9872530a 100644 (file)
@@ -31,7 +31,6 @@
 #define R300_RESOURCE_FLAG_TRANSFER     PIPE_RESOURCE_FLAG_DRV_PRIV
 
 /* Non-atom dirty state flags. */
-#define R300_NEW_VERTEX_SHADER_CONSTANTS        0x10000000
 #define R300_NEW_QUERY                          0x40000000
 #define R300_NEW_KITCHEN_SINK                   0x7fffffff
 
index b337cd960361dbe4e0111a7b9365d9d2d356740a..afb47ead9c59863fd90e7c3a20ad367e6b6d8db0 100644 (file)
@@ -1025,21 +1025,25 @@ void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state)
     END_CS;
 }
 
-void r300_emit_vs_constant_buffer(struct r300_context* r300,
-                                  struct rc_constant_list* constants)
+void r300_emit_vs_constants(struct r300_context* r300,
+                            unsigned size, void *state)
 {
     unsigned i;
-    unsigned count = ((struct r300_vertex_shader*)r300->vs_state.state)->externals_count;
+    unsigned count =
+        ((struct r300_vertex_shader*)r300->vs_state.state)->externals_count;
+    struct r300_constant_buffer *buf = (struct r300_constant_buffer*)state;
     CS_LOCALS(r300);
 
-    BEGIN_CS(count * 4 + 3);
+    if (!count)
+        return;
+
+    BEGIN_CS(size);
     OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG,
                (r300->screen->caps.is_r500 ?
                R500_PVS_CONST_START : R300_PVS_CONST_START));
     OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, count * 4);
     for (i = 0; i < count; i++) {
-        const float *data =
-                r300->shader_constants[PIPE_SHADER_VERTEX].constants[i];
+        const float *data = buf->constants[i];
         OUT_CS_32F(data[0]);
         OUT_CS_32F(data[1]);
         OUT_CS_32F(data[2]);
@@ -1227,14 +1231,6 @@ void r300_emit_dirty_state(struct r300_context* r300)
         }
     }
 
-    if (r300->dirty_state & R300_NEW_VERTEX_SHADER_CONSTANTS) {
-        struct r300_vertex_shader* vs = r300->vs_state.state;
-        if (vs->code.constants.Count) {
-            r300_emit_vs_constant_buffer(r300, &vs->code.constants);
-        }
-        r300->dirty_state &= ~R300_NEW_VERTEX_SHADER_CONSTANTS;
-    }
-
     /* Emit the VBO for SWTCL. */
     if (!r300screen->caps.has_tcl) {
         r300_emit_vertex_buffer(r300);
index d275bb211a81dd6b0f1ef0326097b53307e9ba66..678e1822123833c316aa24ced710d57d6f1f0f57 100644 (file)
@@ -84,8 +84,8 @@ void r300_emit_vertex_stream_state(struct r300_context* r300,
 void r300_emit_vap_output_state(struct r300_context* r300,
                                unsigned size, void* state);
 
-void r300_emit_vs_constant_buffer(struct r300_context* r300,
-                                  struct rc_constant_list* constants);
+void r300_emit_vs_constants(struct r300_context* r300,
+                            unsigned size, void *state);
 
 void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state);
 
index 0aa2e3573535c0fae7c9601a467fa667a0d1644a..0d8158e19904b8bf2cb0619cbd466a65bbffa775 100644 (file)
@@ -65,7 +65,7 @@ static void r300_flush(struct pipe_context* pipe,
         /* Unmark HWTCL state for SWTCL. */
         if (!r300->screen->caps.has_tcl) {
             r300->vs_state.dirty = FALSE;
-            r300->dirty_state &= ~R300_NEW_VERTEX_SHADER_CONSTANTS;
+            r300->vs_constants.dirty = FALSE;
         }
     }
 
index a732ef3a1049388d1c30f9ba93ac6b7ab78dd58e..a10953c04aeb05694da67c77febca3a98f20e8e5 100644 (file)
@@ -1383,9 +1383,14 @@ static void r300_bind_vs_state(struct pipe_context* pipe, void* shader)
                 vs->code.length + 9 +
                 (vs->immediates_count ? vs->immediates_count * 4 + 3 : 0);
 
-        r300->pvs_flush.dirty = TRUE;
+        if (vs->externals_count) {
+            r300->vs_constants.dirty = TRUE;
+            r300->vs_constants.size = vs->externals_count * 4 + 3;
+        } else {
+            r300->vs_constants.size = 0;
+        }
 
-        r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS;
+        r300->pvs_flush.dirty = TRUE;
     } else {
         draw_flush(r300->draw);
         draw_bind_vertex_shader(r300->draw,
@@ -1421,7 +1426,7 @@ static void r300_set_constant_buffer(struct pipe_context *pipe,
 
     switch (shader) {
         case PIPE_SHADER_VERTEX:
-            cbuf = &r300->shader_constants[PIPE_SHADER_VERTEX];
+            cbuf = (struct r300_constant_buffer*)r300->vs_constants.state;
             max_size = 256;
             break;
         case PIPE_SHADER_FRAGMENT:
@@ -1434,7 +1439,7 @@ static void r300_set_constant_buffer(struct pipe_context *pipe,
             break;
         default:
             assert(0);
-            cbuf = NULL;
+            return;
     }
 
     if (buf == NULL || buf->width0 == 0 ||
@@ -1460,7 +1465,9 @@ static void r300_set_constant_buffer(struct pipe_context *pipe,
 
     if (shader == PIPE_SHADER_VERTEX) {
         if (r300->screen->caps.has_tcl) {
-            r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS;
+            if (r300->vs_constants.size) {
+                r300->vs_constants.dirty = TRUE;
+            }
             r300->pvs_flush.dirty = TRUE;
         } else if (r300->draw) {
             draw_set_mapped_constant_buffer(r300->draw, PIPE_SHADER_VERTEX,