summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r300/r300_render.c
diff options
context:
space:
mode:
authorCorbin Simpson <[email protected]>2010-01-25 11:27:50 -0800
committerCorbin Simpson <[email protected]>2010-01-25 11:30:39 -0800
commit5fe71949d9e3790ce38ab616aee29079c6b67721 (patch)
tree6fee30a0e1949eb855591b8d378fa7bb897b62d9 /src/gallium/drivers/r300/r300_render.c
parent1571602153128971ae9ed549d633d67aac65da14 (diff)
r300g: Finish and enable immediate mode.
Based on Marek's immd-mode patch.
Diffstat (limited to 'src/gallium/drivers/r300/r300_render.c')
-rw-r--r--src/gallium/drivers/r300/r300_render.c115
1 files changed, 84 insertions, 31 deletions
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index 677031ef04e..dcd0761944f 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -28,6 +28,7 @@
#include "pipe/p_inlines.h"
+#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_prim.h"
@@ -114,20 +115,58 @@ static uint32_t r300_provoking_vertex_fixes(struct r300_context *r300,
return color_control;
}
-static void r300_emit_draw_immediate(struct r300_context *r300,
- unsigned mode,
- unsigned start,
- unsigned count)
+static boolean immd_is_good_idea(struct r300_context *r300,
+ unsigned count)
{
- struct pipe_buffer* vbo = r300->vertex_buffer[0].buffer;
- unsigned vertex_size = r300->vertex_buffer[0].stride / sizeof(float);
- unsigned i;
- uint32_t* map;
+ return count <= 4;
+}
+
+static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
+ unsigned mode,
+ unsigned start,
+ unsigned count)
+{
+ struct pipe_vertex_element* velem;
+ struct pipe_vertex_buffer* vbuf;
+ unsigned vertex_element_count = r300->vertex_element_count;
+ unsigned i, v, vbi, dw, elem_offset;
+
+ /* Size of the vertex, in dwords. */
+ unsigned vertex_size = 0;
+
+ /* Offsets of the attribute, in dwords, from the start of the vertex. */
+ unsigned offset[PIPE_MAX_ATTRIBS];
+
+ /* Size of the vertex element, in dwords. */
+ unsigned size[PIPE_MAX_ATTRIBS];
+
+ /* Stride to the same attrib in the next vertex in the vertex buffer,
+ * in dwords. */
+ unsigned stride[PIPE_MAX_ATTRIBS];
+
+ /* Mapped vertex buffers. */
+ uint32_t* map[PIPE_MAX_ATTRIBS] = {0};
+
CS_LOCALS(r300);
- map = (uint32_t*)pipe_buffer_map_range(r300->context.screen, vbo,
- start * vertex_size, count * vertex_size,
- PIPE_BUFFER_USAGE_CPU_READ);
+ /* Calculate the vertex size, offsets, strides etc. and map the buffers. */
+ for (i = 0; i < vertex_element_count; i++) {
+ velem = &r300->vertex_element[i];
+ offset[i] = velem->src_offset / 4;
+ size[i] = util_format_get_blocksize(velem->src_format) / 4;
+ vertex_size += size[i];
+ vbi = velem->vertex_buffer_index;
+
+ /* Map the buffer. */
+ if (!map[vbi]) {
+ vbuf = &r300->vertex_buffer[vbi];
+ map[vbi] = (uint32_t*)pipe_buffer_map(r300->context.screen,
+ vbuf->buffer,
+ PIPE_BUFFER_USAGE_CPU_READ);
+ map[vbi] += vbuf->buffer_offset / 4;
+ stride[vbi] = vbuf->stride / 4;
+ }
+ }
BEGIN_CS(10 + count * vertex_size);
OUT_CS_REG(R300_GA_COLOR_CONTROL,
@@ -138,18 +177,31 @@ static void r300_emit_draw_immediate(struct r300_context *r300,
OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2, count * vertex_size);
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | (count << 16) |
r300_translate_primitive(mode));
- //debug_printf("r300: Immd %d verts, %d attrs\n", count, vertex_size);
- for (i = 0; i < count * vertex_size; i++) {
- if (i % vertex_size == 0) {
- //debug_printf("r300: -- vert --\n");
+
+ /* Emit vertices. */
+ for (v = 0; v < count; v++) {
+ for (i = 0; i < vertex_element_count; i++) {
+ velem = &r300->vertex_element[i];
+ vbi = velem->vertex_buffer_index;
+ elem_offset = offset[i] + stride[vbi] * (v + start);
+
+ for (dw = 0; dw < size[i]; dw++) {
+ OUT_CS(map[vbi][elem_offset + dw]);
+ }
}
- //debug_printf("r300: 0x%08x\n", *map);
- OUT_CS(*map);
- map++;
}
END_CS;
- pipe_buffer_unmap(r300->context.screen, vbo);
+ /* Unmap buffers. */
+ for (i = 0; i < vertex_element_count; i++) {
+ vbi = r300->vertex_element[i].vertex_buffer_index;
+
+ if (map[vbi]) {
+ vbuf = &r300->vertex_buffer[vbi];
+ pipe_buffer_unmap(r300->context.screen, vbuf->buffer);
+ map[vbi] = NULL;
+ }
+ }
}
static void r300_emit_draw_arrays(struct r300_context *r300,
@@ -221,17 +273,18 @@ static void r300_emit_draw_elements(struct r300_context *r300,
END_CS;
}
-
static boolean r300_setup_vertex_buffers(struct r300_context *r300)
{
struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
struct pipe_vertex_element *velem = r300->vertex_element;
+ struct pipe_buffer *pbuf;
validate:
for (int i = 0; i < r300->vertex_element_count; i++) {
- if (!r300->winsys->add_buffer(r300->winsys,
- vbuf[velem[i].vertex_buffer_index].buffer,
- RADEON_GEM_DOMAIN_GTT, 0)) {
+ pbuf = vbuf[velem[i].vertex_buffer_index].buffer;
+
+ if (!r300->winsys->add_buffer(r300->winsys, pbuf,
+ RADEON_GEM_DOMAIN_GTT, 0)) {
r300->context.flush(&r300->context, 0, NULL);
goto validate;
}
@@ -365,15 +418,15 @@ void r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
r300_emit_buffer_validate(r300);
- if (!r300_setup_vertex_buffers(r300)) {
- return;
- }
-
- r300_emit_dirty_state(r300);
-
- if (FALSE && count <= 4 && r300->vertex_buffer_count == 1) {
- r300_emit_draw_immediate(r300, mode, start, count);
+ if (immd_is_good_idea(r300, count)) {
+ r300_emit_dirty_state(r300);
+ r300_emit_draw_arrays_immediate(r300, mode, start, count);
} else {
+ if (!r300_setup_vertex_buffers(r300)) {
+ return;
+ }
+
+ r300_emit_dirty_state(r300);
r300_emit_aos(r300, start);
r300_emit_draw_arrays(r300, mode, count);
}