r300g: Cleanup PSC setup math a bit and stop using Draw formats.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Thu, 22 Oct 2009 20:42:03 +0000 (13:42 -0700)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Thu, 22 Oct 2009 21:29:48 +0000 (14:29 -0700)
src/gallium/drivers/r300/r300_reg.h
src/gallium/drivers/r300/r300_state_derived.c
src/gallium/drivers/r300/r300_state_inlines.h

index ae94bb9b9fcf9c1964322ef5e685e4ee399ce44d..e920b2a5e773587332f5f57c07d468cc132dbc89 100644 (file)
@@ -348,6 +348,27 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #       define R300_WRITE_ENA_W                         8
 #       define R300_SWIZZLE1_SHIFT                      16
 
+#       define R300_VAP_SWIZZLE_X001 \
+        ((R300_SWIZZLE_SELECT_X << R300_SWIZZLE_SELECT_X_SHIFT) | \
+         (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_Y_SHIFT) | \
+         (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_Z_SHIFT) | \
+         (R300_SWIZZLE_SELECT_FP_ONE << R300_SWIZZLE_SELECT_W_SHIFT) | \
+         (0xf << R300_WRITE_ENA_SHIFT))
+
+#       define R300_VAP_SWIZZLE_XY01 \
+        ((R300_SWIZZLE_SELECT_X << R300_SWIZZLE_SELECT_X_SHIFT) | \
+         (R300_SWIZZLE_SELECT_Y << R300_SWIZZLE_SELECT_Y_SHIFT) | \
+         (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_Z_SHIFT) | \
+         (R300_SWIZZLE_SELECT_FP_ONE << R300_SWIZZLE_SELECT_W_SHIFT) | \
+         (0xf << R300_WRITE_ENA_SHIFT))
+
+#       define R300_VAP_SWIZZLE_XYZ1 \
+        ((R300_SWIZZLE_SELECT_X << R300_SWIZZLE_SELECT_X_SHIFT) | \
+         (R300_SWIZZLE_SELECT_Y << R300_SWIZZLE_SELECT_Y_SHIFT) | \
+         (R300_SWIZZLE_SELECT_Z << R300_SWIZZLE_SELECT_Z_SHIFT) | \
+         (R300_SWIZZLE_SELECT_FP_ONE << R300_SWIZZLE_SELECT_W_SHIFT) | \
+         (0xf << R300_WRITE_ENA_SHIFT))
+
 #       define R300_VAP_SWIZZLE_XYZW \
         ((R300_SWIZZLE_SELECT_X << R300_SWIZZLE_SELECT_X_SHIFT) | \
          (R300_SWIZZLE_SELECT_Y << R300_SWIZZLE_SELECT_Y_SHIFT) | \
index 42aee7231eb33efa85cb778e0da0d75b1688870e..7d000e9e2da97cd218d308d92a03f3389a28ff60 100644 (file)
@@ -224,7 +224,8 @@ static void r300_vertex_psc(struct r300_context* r300,
     struct r300_screen* r300screen = r300_screen(r300->context.screen);
     struct vertex_info* vinfo = &vformat->vinfo;
     int* tab = vformat->vs_tab;
-    uint32_t temp;
+    uint16_t type, swizzle;
+    enum pipe_format format;
     unsigned i, attrib_count;
 
     /* Vertex shaders have no semantics on their inputs,
@@ -246,25 +247,28 @@ static void r300_vertex_psc(struct r300_context* r300,
     }
 
     for (i = 0; i < attrib_count; i++) {
-        /* Make sure we have a proper destination for our attribute */
+        /* Make sure we have a proper destination for our attribute. */
         assert(tab[i] != -1);
 
-        /* Add the attribute to the PSC table. */
-        temp = translate_draw_vertex_data_type(vinfo->attrib[i].emit) |
+        format = draw_translate_vinfo_format(vinfo->attrib[i].emit);
+
+        /* Obtain the type of data in this attribute. */
+        type = r300_translate_vertex_data_type(format) |
             tab[i] << R300_DST_VEC_LOC_SHIFT;
 
+        /* Obtain the swizzle for this attribute. Note that the default
+         * swizzle in the hardware is not XYZW! */
+        swizzle = r300_translate_vertex_data_swizzle(format);
+
+        /* Add the attribute to the PSC table. */
         if (i & 1) {
-            vformat->vap_prog_stream_cntl[i >> 1] &= 0x0000ffff;
-            vformat->vap_prog_stream_cntl[i >> 1] |= temp << 16;
+            vformat->vap_prog_stream_cntl[i >> 1] |= type << 16;
 
-            vformat->vap_prog_stream_cntl_ext[i >> 1] |=
-                (R300_VAP_SWIZZLE_XYZW << 16);
+            vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
         } else {
-            vformat->vap_prog_stream_cntl[i >> 1] &= 0xffff0000;
-            vformat->vap_prog_stream_cntl[i >> 1] |= temp <<  0;
+            vformat->vap_prog_stream_cntl[i >> 1] |= type <<  0;
 
-            vformat->vap_prog_stream_cntl_ext[i >> 1] |=
-                (R300_VAP_SWIZZLE_XYZW <<  0);
+            vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 0;
         }
     }
 
index c82d8e5f08094da17bb5ac4a28e86dbc23489fd1..2431b75a51bf9bc3507dbc4c181f811d4f18dc8c 100644 (file)
@@ -400,28 +400,54 @@ static INLINE uint32_t r300_translate_gb_pipes(int pipe_count)
     return 0;
 }
 
-/* Translate Draw vertex types into PSC vertex types. */
-static INLINE uint32_t translate_draw_vertex_data_type(int type) {
-    switch (type) {
-        case EMIT_1F:
-        case EMIT_1F_PSIZE:
+/* Translate pipe_formats into PSC vertex types. */
+static INLINE uint16_t
+r300_translate_vertex_data_type(enum pipe_format format) {
+    switch (format) {
+        case PIPE_FORMAT_R32_FLOAT:
             return R300_DATA_TYPE_FLOAT_1;
             break;
-        case EMIT_2F:
+        case PIPE_FORMAT_R32G32_FLOAT:
             return R300_DATA_TYPE_FLOAT_2;
             break;
-        case EMIT_3F:
+        case PIPE_FORMAT_R32G32B32_FLOAT:
             return R300_DATA_TYPE_FLOAT_3;
             break;
-        case EMIT_4F:
+        case PIPE_FORMAT_R32G32B32A32_FLOAT:
             return R300_DATA_TYPE_FLOAT_4;
             break;
-        case EMIT_4UB:
-            return R300_DATA_TYPE_BYTE;
+        case PIPE_FORMAT_R8G8B8A8_UNORM:
+            return R300_DATA_TYPE_BYTE |
+                R300_NORMALIZE;
+            break;
+        default:
+            debug_printf("r300: Implementation error: "
+                    "Bad vertex data format %s!\n", pf_name(format));
+            assert(0);
+            break;
+    }
+    return 0;
+}
+
+static INLINE uint16_t
+r300_translate_vertex_data_swizzle(enum pipe_format format) {
+    switch (format) {
+        case PIPE_FORMAT_R32_FLOAT:
+            return R300_VAP_SWIZZLE_X001;
+            break;
+        case PIPE_FORMAT_R32G32_FLOAT:
+            return R300_VAP_SWIZZLE_XY01;
+            break;
+        case PIPE_FORMAT_R32G32B32_FLOAT:
+            return R300_VAP_SWIZZLE_XYZ1;
+            break;
+        case PIPE_FORMAT_R32G32B32A32_FLOAT:
+        case PIPE_FORMAT_R8G8B8A8_UNORM:
+            return R300_VAP_SWIZZLE_XYZW;
             break;
         default:
             debug_printf("r300: Implementation error: "
-                    "Bad vertex data type!\n");
+                    "Bad vertex data format %s!\n", pf_name(format));
             assert(0);
             break;
     }