# 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) | \
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,
}
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;
}
}
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;
}