r300g: emit VS immediates along with VS code
authorMarek Olšák <maraeo@gmail.com>
Wed, 14 Apr 2010 00:21:06 +0000 (02:21 +0200)
committerMarek Olšák <maraeo@gmail.com>
Wed, 14 Apr 2010 02:48:19 +0000 (04:48 +0200)
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_vs.c
src/gallium/drivers/r300/r300_vs.h

index ce5023c21416800be618a9b55dccca97a28a5afd..b337cd960361dbe4e0111a7b9365d9d2d356740a 100644 (file)
@@ -977,6 +977,10 @@ void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state)
                                   vtx_mem_size / output_count, 10);
     unsigned pvs_num_controllers = MIN2(vtx_mem_size / temp_count, 6);
 
+    unsigned imm_first = vs->externals_count;
+    unsigned imm_end = vs->code.constants.Count;
+    unsigned imm_count = vs->immediates_count;
+
     CS_LOCALS(r300);
 
     BEGIN_CS(size);
@@ -1002,6 +1006,22 @@ void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state)
             R300_PVS_NUM_FPUS(r300screen->caps.num_vert_fpus) |
             R300_PVS_VF_MAX_VTX_NUM(12) |
             (r300screen->caps.is_r500 ? R500_TCL_STATE_OPTIMIZATION : 0));
+
+    /* Emit immediates. */
+    if (imm_count) {
+        OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG,
+                   (r300->screen->caps.is_r500 ?
+                   R500_PVS_CONST_START : R300_PVS_CONST_START) +
+                   imm_first);
+        OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, imm_count * 4);
+        for (i = imm_first; i < imm_end; i++) {
+            const float *data = vs->code.constants.Constants[i].u.Immediate;
+            OUT_CS_32F(data[0]);
+            OUT_CS_32F(data[1]);
+            OUT_CS_32F(data[2]);
+            OUT_CS_32F(data[3]);
+        }
+    }
     END_CS;
 }
 
@@ -1009,17 +1029,17 @@ void r300_emit_vs_constant_buffer(struct r300_context* r300,
                                   struct rc_constant_list* constants)
 {
     unsigned i;
+    unsigned count = ((struct r300_vertex_shader*)r300->vs_state.state)->externals_count;
     CS_LOCALS(r300);
 
-    BEGIN_CS(constants->Count * 4 + 3);
+    BEGIN_CS(count * 4 + 3);
     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, constants->Count * 4);
-    for (i = 0; i < constants->Count; i++) {
-        const float *data = get_shader_constant(r300,
-                                                &constants->Constants[i],
-                                                &r300->shader_constants[PIPE_SHADER_VERTEX]);
+    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];
         OUT_CS_32F(data[0]);
         OUT_CS_32F(data[1]);
         OUT_CS_32F(data[2]);
index 0cb102359df4a1ad2191826b809e892255493cab..a732ef3a1049388d1c30f9ba93ac6b7ab78dd58e 100644 (file)
@@ -1379,7 +1379,9 @@ static void r300_bind_vs_state(struct pipe_context* pipe, void* shader)
 
     if (r300->screen->caps.has_tcl) {
         r300->vs_state.dirty = TRUE;
-        r300->vs_state.size = vs->code.length + 9;
+        r300->vs_state.size =
+                vs->code.length + 9 +
+                (vs->immediates_count ? vs->immediates_count * 4 + 3 : 0);
 
         r300->pvs_flush.dirty = TRUE;
 
index 2f9ee76bd899a147e49efc89015c938ecea2ef11..8137972f0188a989207fd9a029d809156732d731 100644 (file)
@@ -333,6 +333,10 @@ void r300_translate_vertex_shader(struct r300_context* r300,
         r300_dummy_vertex_shader(r300, vs);
     }
 
+    /* Initialize numbers of constants for each type. */
+    vs->externals_count = ttr.immediate_offset;
+    vs->immediates_count = vs->code.constants.Count - vs->externals_count;
+
     /* And, finally... */
     rc_destroy(&compiler.Base);
 }
index 261c31ee2f5bc6b10e4e5b3c9b4304c8fe08686e..56bcc3b70b8e6f69982a182ef0eb201c5a01dd42 100644 (file)
@@ -45,6 +45,10 @@ struct r300_vertex_shader {
      * compilation failure. */
     boolean dummy;
 
+    /* Numbers of constants for each type. */
+    unsigned externals_count;
+    unsigned immediates_count;
+
     /* Stream locations for SWTCL or if TCL is bypassed. */
     int stream_loc_notcl[16];