From 6acb26eadfcb3c21fd09d0b22804b49de9a82cf7 Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sun, 25 Oct 2009 13:22:22 +0100 Subject: r300g: move vborender context function to seperate file r300g: Un-migrate r300_draw_render. It'll make maintaining the SW TCL path easier. --- src/gallium/drivers/r300/r300_render.c | 5 ++++- src/gallium/drivers/r300/r300_render.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index c36350d29e2..634c803f2a8 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -20,6 +20,9 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/* r300_render: Vertex and index buffer primitive emission. Contains both + * HW TCL fastpath rendering, and SW TCL Draw-assisted rendering. */ + #include "draw/draw_context.h" #include "draw/draw_vbuf.h" @@ -38,7 +41,7 @@ /* r300_render: Vertex and index buffer primitive emission. */ #define R300_MAX_VBO_SIZE (1024 * 1024) -static uint32_t r300_translate_primitive(unsigned prim) +uint32_t r300_translate_primitive(unsigned prim) { switch (prim) { case PIPE_PRIM_POINTS: diff --git a/src/gallium/drivers/r300/r300_render.h b/src/gallium/drivers/r300/r300_render.h index 3d8f47ba75f..3f8ac1fb7a4 100644 --- a/src/gallium/drivers/r300/r300_render.h +++ b/src/gallium/drivers/r300/r300_render.h @@ -23,6 +23,8 @@ #ifndef R300_RENDER_H #define R300_RENDER_H +uint32_t r300_translate_primitive(unsigned prim); + boolean r300_draw_range_elements(struct pipe_context* pipe, struct pipe_buffer* indexBuffer, unsigned indexSize, -- cgit v1.2.3 From c7dfffc5d5078e3cf1c28c230177cbbb43b91131 Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sun, 25 Oct 2009 12:08:02 +0100 Subject: r300g: enable CS dumping --- src/gallium/drivers/r300/r300_cs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_cs.h b/src/gallium/drivers/r300/r300_cs.h index 883f0a02dc5..86ba91db52e 100644 --- a/src/gallium/drivers/r300/r300_cs.h +++ b/src/gallium/drivers/r300/r300_cs.h @@ -34,8 +34,8 @@ #define MAX_CS_SIZE 64 * 1024 / 4 -#define VERY_VERBOSE_CS 0 -#define VERY_VERBOSE_REGISTERS 0 +#define VERY_VERBOSE_CS 1 +#define VERY_VERBOSE_REGISTERS 1 /* XXX stolen from radeon_drm.h */ #define RADEON_GEM_DOMAIN_CPU 0x1 -- cgit v1.2.3 From d8592d1724d8c8fd0b36eb21f4007b52f809e062 Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sun, 1 Nov 2009 17:04:32 +0100 Subject: r300g: add missing flush --- src/gallium/drivers/r300/r300_state.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 658a8cba132..bed886fad04 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -577,6 +577,8 @@ static void r300_set_sampler_textures(struct pipe_context* pipe, if (count > 8) { return; } + + r300->context.flush(&r300->context, 0, NULL); for (i = 0; i < count; i++) { if (r300->textures[i] != (struct r300_texture*)texture[i]) { -- cgit v1.2.3 From 3445f476977ae403cef9ca15661fa0f96ff50eca Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sun, 25 Oct 2009 13:53:25 +0100 Subject: r300g: VBOs WIP --- src/gallium/drivers/r300/Makefile | 1 + src/gallium/drivers/r300/r300_context.c | 14 +- src/gallium/drivers/r300/r300_context.h | 27 +-- src/gallium/drivers/r300/r300_emit.c | 108 +++++++++++- src/gallium/drivers/r300/r300_emit.h | 12 ++ src/gallium/drivers/r300/r300_render.c | 135 +++++++-------- src/gallium/drivers/r300/r300_state.c | 13 +- src/gallium/drivers/r300/r300_state_derived.c | 14 +- src/gallium/drivers/r300/r300_vbo.c | 226 ++++++++++++++++++++++++++ src/gallium/drivers/r300/r300_vbo.h | 36 ++++ 10 files changed, 477 insertions(+), 109 deletions(-) create mode 100644 src/gallium/drivers/r300/r300_vbo.c create mode 100644 src/gallium/drivers/r300/r300_vbo.h (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/Makefile b/src/gallium/drivers/r300/Makefile index f73d80de882..d13bb7a36b1 100644 --- a/src/gallium/drivers/r300/Makefile +++ b/src/gallium/drivers/r300/Makefile @@ -17,6 +17,7 @@ C_SOURCES = \ r300_state.c \ r300_state_derived.c \ r300_state_invariant.c \ + r300_vbo.c \ r300_vs.c \ r300_texture.c \ r300_tgsi_to_rc.c diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index f974147ea43..b520e5929e2 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -104,6 +104,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, struct r300_winsys* r300_winsys) { struct r300_context* r300 = CALLOC_STRUCT(r300_context); + struct r300_screen* r300screen = r300_screen(screen); if (!r300) return NULL; @@ -119,9 +120,16 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, r300->context.clear = r300_clear; - r300->context.draw_arrays = r300_draw_arrays; - r300->context.draw_elements = r300_draw_elements; - r300->context.draw_range_elements = r300_swtcl_draw_range_elements; + if (r300screen->caps->has_tcl) + { + r300->context.draw_arrays = r300_draw_arrays; + r300->context.draw_elements = r300_draw_elements; + r300->context.draw_range_elements = r300_draw_range_elements; + } + else + { + assert(0); + } r300->context.is_texture_referenced = r300_is_texture_referenced; r300->context.is_buffer_referenced = r300_is_buffer_referenced; diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 850e5a41c91..a6748852d83 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -216,18 +216,19 @@ struct r300_texture { struct r300_texture_state state; }; -struct r300_vertex_format { +struct r300_vertex_info { /* Parent class */ struct vertex_info vinfo; - /* R300_VAP_PROG_STREAK_CNTL_[0-7] */ - uint32_t vap_prog_stream_cntl[8]; - /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */ - uint32_t vap_prog_stream_cntl_ext[8]; /* Map of vertex attributes into PVS memory for HW TCL, * or GA memory for SW TCL. */ int vs_tab[16]; /* Map of rasterizer attributes from GB through RS to US. */ int fs_tab[16]; + + /* R300_VAP_PROG_STREAK_CNTL_[0-7] */ + uint32_t vap_prog_stream_cntl[8]; + /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */ + uint32_t vap_prog_stream_cntl_ext[8]; }; extern struct pipe_viewport_state r300_viewport_identity; @@ -256,7 +257,7 @@ struct r300_context { * depends on the combination of both currently loaded shaders. */ struct util_hash_table* shader_hash_table; /* Vertex formatting information. */ - struct r300_vertex_format* vertex_info; + struct r300_vertex_info* vertex_info; /* Various CSO state objects. */ /* Blend state. */ @@ -285,12 +286,6 @@ struct r300_context { /* Texture states. */ struct r300_texture* textures[8]; int texture_count; - /* Vertex buffers for Gallium. */ - struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; - int vertex_buffer_count; - /* Vertex elements for Gallium. */ - struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS]; - int vertex_element_count; /* Vertex shader. */ struct r300_vertex_shader* vs; /* Viewport state. */ @@ -298,6 +293,14 @@ struct r300_context { /* ZTOP state. */ struct r300_ztop_state ztop_state; + /* Vertex buffers for Gallium. */ + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + int vbuf_count; + /* Vertex elements for Gallium. */ + struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; + int aos_count; + unsigned hw_prim; + /* Bitmask of dirty state objects. */ uint32_t dirty_state; /* Flag indicating whether or not the HW is dirty. */ diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 69ce5966e80..92e6ec606ca 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -582,7 +582,48 @@ void r300_emit_texture(struct r300_context* r300, END_CS; } -void r300_emit_vertex_buffer(struct r300_context* r300) +void r300_emit_aos(struct r300_context* r300, unsigned offset) +{ + struct pipe_vertex_buffer *vbuf = r300->vertex_buffer; + struct pipe_vertex_element *velem = r300->vertex_element; + CS_LOCALS(r300); + int i; + unsigned packet_size = (r300->aos_count * 3 + 1) / 2; + BEGIN_CS(2 + packet_size + r300->aos_count * 2); + OUT_CS_PKT3(R300_PACKET3_3D_LOAD_VBPNTR, packet_size); + OUT_CS(r300->aos_count); + for (i = 0; i < r300->aos_count - 1; i += 2) { + int buf_num1 = velem[i].vertex_buffer_index; + int buf_num2 = velem[i+1].vertex_buffer_index; + assert(vbuf[buf_num1].stride % 4 == 0 && pf_get_size(velem[i].src_format) % 4 == 0); + assert(vbuf[buf_num2].stride % 4 == 0 && pf_get_size(velem[i+1].src_format) % 4 == 0); + OUT_CS((pf_get_size(velem[i].src_format) >> 2) | (vbuf[buf_num1].stride << 6) | + (pf_get_size(velem[i+1].src_format) << 14) | (vbuf[buf_num2].stride << 22)); + OUT_CS(vbuf[buf_num1].buffer_offset + velem[i].src_offset + + offset * vbuf[buf_num1].stride); + OUT_CS(vbuf[buf_num2].buffer_offset + velem[i+1].src_offset + + offset * vbuf[buf_num2].stride); + } + if (r300->aos_count & 1) { + int buf_num = velem[i].vertex_buffer_index; + assert(vbuf[buf_num].stride % 4 == 0 && pf_get_size(velem[i].src_format) % 4 == 0); + OUT_CS((pf_get_size(velem[i].src_format) >> 2) | (vbuf[buf_num].stride << 6)); + OUT_CS(vbuf[buf_num].buffer_offset + velem[i].src_offset + + offset * vbuf[buf_num].stride); + } + + for (i = 0; i < r300->aos_count; i++) { + cs_winsys->write_cs_reloc(cs_winsys, + vbuf[velem[i].vertex_buffer_index].buffer, + RADEON_GEM_DOMAIN_GTT, + 0, + 0); + cs_count -= 2; + } + END_CS; +} +#if 0 +void r300_emit_draw_packet(struct r300_context* r300) { CS_LOCALS(r300); @@ -605,6 +646,65 @@ void r300_emit_vertex_buffer(struct r300_context* r300) OUT_CS_RELOC(r300->vbo, 0, RADEON_GEM_DOMAIN_GTT, 0, 0); END_CS; } +#endif +void r300_emit_draw_arrays(struct r300_context *r300, + unsigned count) +{ + CS_LOCALS(r300); + assert(count < 65536); + + BEGIN_CS(4); + OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | + r300->hw_prim); + END_CS; +} + +void r300_emit_draw_elements(struct r300_context *r300, + struct pipe_buffer* indexBuffer, + unsigned indexSize, + unsigned minIndex, + unsigned maxIndex, + unsigned start, + unsigned count) +{ + CS_LOCALS(r300); + assert(indexSize == 4 || indexSize == 2); + assert(count < 65536); + assert((start * indexSize) % 4 == 0); + + uint32_t size_dwords; + uint32_t skip_dwords = indexSize * start / sizeof(uint32_t); + assert(skip_dwords == 0); + + BEGIN_CS(10); + OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, maxIndex); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); + if (indexSize == 4) { + size_dwords = count + start; + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | + R300_VAP_VF_CNTL__INDEX_SIZE_32bit | r300->hw_prim); + } else { + size_dwords = (count + start + 1) / 2; + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | + (count << 16) | r300->hw_prim); + } + + OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); + OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) | + (0 << R300_INDX_BUFFER_SKIP_SHIFT)); + OUT_CS(skip_dwords); + OUT_CS(size_dwords); + cs_winsys->write_cs_reloc(cs_winsys, + indexBuffer, + RADEON_GEM_DOMAIN_GTT, + 0, + 0); + cs_count -= 2; + + END_CS; +} void r300_emit_vertex_format_state(struct r300_context* r300) { @@ -771,8 +871,6 @@ void r300_emit_dirty_state(struct r300_context* r300) return; } - r300_update_derived_state(r300); - /* Clean out BOs. */ r300->winsys->reset_bos(r300->winsys); @@ -823,7 +921,7 @@ validate: goto validate; } } else { - debug_printf("No VBO while emitting dirty state!\n"); + // debug_printf("No VBO while emitting dirty state!\n"); } if (!r300->winsys->validate(r300->winsys)) { r300->context.flush(&r300->context, 0, NULL); @@ -951,7 +1049,7 @@ validate: */ /* Finally, emit the VBO. */ - r300_emit_vertex_buffer(r300); + //r300_emit_vertex_buffer(r300); r300->dirty_hw++; } diff --git a/src/gallium/drivers/r300/r300_emit.h b/src/gallium/drivers/r300/r300_emit.h index 6befca72ced..b4fdfecde01 100644 --- a/src/gallium/drivers/r300/r300_emit.h +++ b/src/gallium/drivers/r300/r300_emit.h @@ -29,6 +29,8 @@ struct rX00_fragment_program_code; struct r300_vertex_program_code; +void r300_emit_aos(struct r300_context* r300, unsigned offset); + void r300_emit_blend_state(struct r300_context* r300, struct r300_blend_state* blend); @@ -38,6 +40,16 @@ void r300_emit_blend_color_state(struct r300_context* r300, void r300_emit_clip_state(struct r300_context* r300, struct pipe_clip_state* clip); +void r300_emit_draw_arrays(struct r300_context *r300, unsigned count); + +void r300_emit_draw_elements(struct r300_context *r300, + struct pipe_buffer* indexBuffer, + unsigned indexSize, + unsigned minIndex, + unsigned maxIndex, + unsigned start, + unsigned count); + void r300_emit_dsa_state(struct r300_context* r300, struct r300_dsa_state* dsa); diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 634c803f2a8..86aaf841dd6 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -31,6 +31,7 @@ #include "util/u_memory.h" #include "util/u_prim.h" +#include "r300_vbo.h" #include "r300_cs.h" #include "r300_context.h" #include "r300_emit.h" @@ -69,98 +70,64 @@ uint32_t r300_translate_primitive(unsigned prim) } } -/* This is the fast-path drawing & emission for HW TCL. */ -boolean r300_draw_range_elements(struct pipe_context* pipe, - struct pipe_buffer* indexBuffer, - unsigned indexSize, - unsigned minIndex, - unsigned maxIndex, - unsigned mode, - unsigned start, - unsigned count) +static boolean setup_vertex_buffers(struct r300_context *r300) { - struct r300_context* r300 = r300_context(pipe); - uint32_t prim = r300_translate_primitive(mode); - struct pipe_vertex_buffer* aos = r300->vertex_buffers; - unsigned aos_count = r300->vertex_buffer_count; - short* indices; - unsigned packet_size; - unsigned i; - bool invalid = FALSE; - - CS_LOCALS(r300); - - if (!u_trim_pipe_prim(mode, &count)) { - return FALSE; - } + unsigned vbuf_count = r300->aos_count; + struct pipe_vertex_buffer *vbuf= r300->vertex_buffer; + struct pipe_vertex_element *velem= r300->vertex_element; + bool invalid = false; validate: - for (i = 0; i < aos_count; i++) { - if (!r300->winsys->add_buffer(r300->winsys, aos[i].buffer, - RADEON_GEM_DOMAIN_GTT, 0)) { - pipe->flush(pipe, 0, NULL); + for (int i = 0; i < vbuf_count; i++) { + if (!r300->winsys->add_buffer(r300->winsys, vbuf[velem[i].vertex_buffer_index].buffer, + RADEON_GEM_DOMAIN_GTT, 0)) { + r300->context.flush(&r300->context, 0, NULL); goto validate; } } + if (!r300->winsys->validate(r300->winsys)) { - pipe->flush(pipe, 0, NULL); + r300->context.flush(&r300->context, 0, NULL); if (invalid) { /* Well, hell. */ debug_printf("r300: Stuck in validation loop, gonna quit now."); exit(1); } - invalid = TRUE; + invalid = true; goto validate; } - r300_emit_dirty_state(r300); + return invalid; +} - packet_size = (aos_count >> 1) * 3 + (aos_count & 1) * 2; - - BEGIN_CS(3 + packet_size + (aos_count * 2)); - OUT_CS_PKT3(R300_PACKET3_3D_LOAD_VBPNTR, packet_size); - OUT_CS(aos_count); - for (i = 0; i < aos_count - 1; i += 2) { - OUT_CS(aos[i].stride | - (aos[i].stride << 8) | - (aos[i + 1].stride << 16) | - (aos[i + 1].stride << 24)); - OUT_CS(aos[i].buffer_offset + start * 4 * aos[i].stride); - OUT_CS(aos[i + 1].buffer_offset + start * 4 * aos[i + 1].stride); - } - if (aos_count & 1) { - OUT_CS(aos[i].stride | (aos[i].stride << 8)); - OUT_CS(aos[i].buffer_offset + start * 4 * aos[i].stride); - } - for (i = 0; i < aos_count; i++) { - OUT_CS_RELOC(aos[i].buffer, 0, RADEON_GEM_DOMAIN_GTT, 0, 0); - } - END_CS; +/* This is the fast-path drawing & emission for HW TCL. */ +boolean r300_draw_range_elements(struct pipe_context* pipe, + struct pipe_buffer* indexBuffer, + unsigned indexSize, + unsigned minIndex, + unsigned maxIndex, + unsigned mode, + unsigned start, + unsigned count) +{ + struct r300_context* r300 = r300_context(pipe); - if (indexBuffer) { - indices = (short*)pipe_buffer_map(pipe->screen, indexBuffer, - PIPE_BUFFER_USAGE_CPU_READ); + r300_update_derived_state(r300); - /* Set the starting point. */ - indices += start; + setup_vertex_buffers(r300); - BEGIN_CS(2 + (count+1)/2); - OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (count + 1)/2); - OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | prim); - for (i = 0; i < count - 1; i += 2) { - OUT_CS(indices[i + 1] << 16 | indices[i]); - } - if (count % 2) { - OUT_CS(indices[count - 1]); - } - END_CS; - } else { - BEGIN_CS(2); - OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); - OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | - prim); - END_CS; - } + setup_vertex_attributes(r300); + + setup_index_buffer(r300, indexBuffer, indexSize); + + r300->hw_prim = r300_translate_primitive(mode); + + r300_emit_dirty_state(r300); + + r300_emit_aos(r300, 0); + + r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex, + start, count); return TRUE; } @@ -178,7 +145,23 @@ boolean r300_draw_elements(struct pipe_context* pipe, boolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode, unsigned start, unsigned count) { - return pipe->draw_elements(pipe, NULL, 0, mode, start, count); + struct r300_context* r300 = r300_context(pipe); + + r300_update_derived_state(r300); + + setup_vertex_buffers(r300); + + setup_vertex_attributes(r300); + + r300->hw_prim = r300_translate_primitive(mode); + + r300_emit_dirty_state(r300); + + r300_emit_aos(r300, start); + + r300_emit_draw_arrays(r300, count); + + return TRUE; } /**************************************************************************** @@ -196,7 +179,9 @@ boolean r300_swtcl_draw_range_elements(struct pipe_context* pipe, unsigned start, unsigned count) { + assert(0); struct r300_context* r300 = r300_context(pipe); +#if 0 int i; if (!u_trim_pipe_prim(mode, &count)) { @@ -236,7 +221,7 @@ boolean r300_swtcl_draw_range_elements(struct pipe_context* pipe, draw_set_mapped_element_buffer_range(r300->draw, 0, start, start + count - 1, NULL); } - +#endif return TRUE; } diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index bed886fad04..e0b85ab768b 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -666,10 +666,9 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); - memcpy(r300->vertex_buffers, buffers, + memcpy(r300->vertex_buffer, buffers, sizeof(struct pipe_vertex_buffer) * count); - - r300->vertex_buffer_count = count; + r300->vbuf_count = count; if (r300->draw) { draw_flush(r300->draw); @@ -683,10 +682,10 @@ static void r300_set_vertex_elements(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); - memcpy(r300->vertex_elements, elements, - sizeof(struct pipe_vertex_element) * count); - - r300->vertex_element_count = count; + memcpy(r300->vertex_element, + elements, + sizeof(struct pipe_vertex_element) * count); + r300->aos_count = count; if (r300->draw) { draw_flush(r300->draw); diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 7d000e9e2da..14d7bb094c5 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -63,7 +63,7 @@ int r300_shader_key_compare(void* key1, void* key2) { /* Set up the vs_tab and routes. */ static void r300_vs_tab_routes(struct r300_context* r300, - struct r300_vertex_format* vformat) + struct r300_vertex_info* vformat) { struct r300_screen* r300screen = r300_screen(r300->context.screen); struct vertex_info* vinfo = &vformat->vinfo; @@ -219,7 +219,7 @@ static void r300_vs_tab_routes(struct r300_context* r300, /* Update the PSC tables. */ static void r300_vertex_psc(struct r300_context* r300, - struct r300_vertex_format* vformat) + struct r300_vertex_info* vformat) { struct r300_screen* r300screen = r300_screen(r300->context.screen); struct vertex_info* vinfo = &vformat->vinfo; @@ -282,7 +282,7 @@ static void r300_vertex_psc(struct r300_context* r300, /* Set up the mappings from GB to US, for RS block. */ static void r300_update_fs_tab(struct r300_context* r300, - struct r300_vertex_format* vformat) + struct r300_vertex_info* vformat) { struct tgsi_shader_info* info = &r300->fs->info; int i, cols = 0, texs = 0, cols_emitted = 0; @@ -455,13 +455,13 @@ static void r300_update_rs_block(struct r300_context* r300, /* Update the vertex format. */ static void r300_update_derived_shader_state(struct r300_context* r300) { - struct r300_shader_key* key; - struct r300_vertex_format* vformat; + struct r300_vertex_info* vformat; struct r300_rs_block* rs_block; - struct r300_shader_derived_value* value; int i; /* + struct r300_shader_key* key; + struct r300_shader_derived_value* value; key = CALLOC_STRUCT(r300_shader_key); key->vs = r300->vs; key->fs = r300->fs; @@ -486,7 +486,7 @@ static void r300_update_derived_shader_state(struct r300_context* r300) } */ /* XXX This will be refactored ASAP. */ - vformat = CALLOC_STRUCT(r300_vertex_format); + vformat = CALLOC_STRUCT(r300_vertex_info); rs_block = CALLOC_STRUCT(r300_rs_block); for (i = 0; i < 16; i++) { diff --git a/src/gallium/drivers/r300/r300_vbo.c b/src/gallium/drivers/r300/r300_vbo.c new file mode 100644 index 00000000000..e0326412865 --- /dev/null +++ b/src/gallium/drivers/r300/r300_vbo.c @@ -0,0 +1,226 @@ +/* + * Copyright 2009 Maciej Cencora + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "r300_vbo.h" + +#include "pipe/p_format.h" + +#include "r300_cs.h" +#include "r300_context.h" +#include "r300_reg.h" +#include "r300_winsys.h" + +static void translate_vertex_format(enum pipe_format format, + unsigned nr_comps, + unsigned component_size, + unsigned dst_loc, + uint32_t *hw_fmt1, + uint32_t *hw_fmt2) +{ + uint32_t fmt1 = 0; + + switch (pf_type(format)) + { + case PIPE_FORMAT_TYPE_FLOAT: + assert(component_size == 4); + fmt1 = R300_DATA_TYPE_FLOAT_1 + nr_comps - 1; + break; + case PIPE_FORMAT_TYPE_UNORM: + case PIPE_FORMAT_TYPE_SNORM: + case PIPE_FORMAT_TYPE_USCALED: + case PIPE_FORMAT_TYPE_SSCALED: + if (component_size == 1) + { + assert(nr_comps == 4); + fmt1 = R300_DATA_TYPE_BYTE; + } + else if (component_size == 2) + { + if (nr_comps == 2) + fmt1 = R300_DATA_TYPE_SHORT_2; + else if (nr_comps == 4) + fmt1 = R300_DATA_TYPE_SHORT_4; + else + assert(0); + } + else + { + assert(0); + } + + if (pf_type(format) == PIPE_FORMAT_TYPE_SNORM) + { + fmt1 |= R300_SIGNED; + } + else if (pf_type(format) == PIPE_FORMAT_TYPE_SSCALED) + { + fmt1 |= R300_SIGNED; + fmt1 |= R300_NORMALIZE; + } + else if (pf_type(format) == PIPE_FORMAT_TYPE_USCALED) + { + fmt1 |= R300_NORMALIZE; + } + break; + default: + assert(0); + break; + } + + *hw_fmt1 = fmt1 | (dst_loc << R300_DST_VEC_LOC_SHIFT); + *hw_fmt2 = (pf_swizzle_x(format) << R300_SWIZZLE_SELECT_X_SHIFT) | + (pf_swizzle_y(format) << R300_SWIZZLE_SELECT_Y_SHIFT) | + (pf_swizzle_z(format) << R300_SWIZZLE_SELECT_Z_SHIFT) | + (pf_swizzle_w(format) << R300_SWIZZLE_SELECT_W_SHIFT) | + (0xf << R300_WRITE_ENA_SHIFT); +} + +static INLINE void setup_vertex_attribute(struct r300_vertex_info *vinfo, + struct pipe_vertex_element *vert_elem, + unsigned attr_num) +{ + uint32_t hw_fmt1, hw_fmt2; + translate_vertex_format(vert_elem->src_format, + vert_elem->nr_components, + pf_size_x(vert_elem->src_format), + attr_num, + &hw_fmt1, + &hw_fmt2); + + if (attr_num % 2 == 0) + { + vinfo->vap_prog_stream_cntl[attr_num >> 1] = hw_fmt1; + vinfo->vap_prog_stream_cntl_ext[attr_num >> 1] = hw_fmt2; + } + else + { + vinfo->vap_prog_stream_cntl[attr_num >> 1] |= hw_fmt1 << 16; + vinfo->vap_prog_stream_cntl_ext[attr_num >> 1] |= hw_fmt2 << 16; + } +} + +static void finish_vertex_attribs_setup(struct r300_vertex_info *vinfo, + unsigned attribs_num) +{ + uint32_t last_vec_bit = (attribs_num % 2 == 0) ? (R300_LAST_VEC << 16) : R300_LAST_VEC; + + assert(attribs_num > 0 && attribs_num <= 16); + vinfo->vap_prog_stream_cntl[(attribs_num - 1) >> 1] |= last_vec_bit; +} + +void setup_vertex_attributes(struct r300_context *r300) +{ + for (int i=0; iaos_count; i++) + { + struct pipe_vertex_element *vert_elem = &r300->vertex_element[i]; + + setup_vertex_attribute(r300->vertex_info, vert_elem, i); + } + + finish_vertex_attribs_setup(r300->vertex_info, r300->aos_count); +} + +static void setup_vertex_array(struct r300_context *r300, struct pipe_vertex_element *element) +{ +} + +static void finish_vertex_arrays_setup(struct r300_context *r300) +{ +} + +static bool format_is_supported(enum pipe_format format, int nr_components) +{ + if (pf_layout(format) != PIPE_FORMAT_LAYOUT_RGBAZS) + return false; + + if ((pf_size_x(format) != pf_size_y(format)) || + (pf_size_x(format) != pf_size_z(format)) || + (pf_size_x(format) != pf_size_w(format))) + return false; + + /* Following should be supported as long as stride is 4 bytes aligned */ + if (pf_size_x(format) != 1 && nr_components != 4) + return false; + + if (pf_size_x(format) != 2 && !(nr_components == 2 || nr_components == 4)) + return false; + + if (pf_size_x(format) == 3 || pf_size_x(format) > 4) + return false; + + return true; +} + +static INLINE int get_buffer_offset(struct r300_context *r300, + unsigned int buf_nr, + unsigned int elem_offset) +{ + return r300->vertex_buffer[buf_nr].buffer_offset + elem_offset; +} + +/** + */ +static void setup_vertex_buffers(struct r300_context *r300) +{ + for (int i=0; iaos_count; i++) + { + struct pipe_vertex_element *vert_elem = &r300->vertex_element[i]; + if (!format_is_supported(vert_elem->src_format, vert_elem->nr_components)) + { + assert(0); + /* use translate module to convert the data */ + /* + struct pipe_buffer *buf; + const unsigned int max_index = r300->vertex_buffers[vert_elem->vertex_buffer_index].max_index; + buf = pipe_buffer_create(r300->context.screen, 4, usage, vert_elem->nr_components * max_index * sizeof(float)); + */ + } + + if (get_buffer_offset(r300, vert_elem->vertex_buffer_index, vert_elem->src_offset) % 4 != 0) + { + /* need to align buffer */ + assert(0); + } + setup_vertex_array(r300, vert_elem); + } + + finish_vertex_arrays_setup(r300); +} + +void setup_index_buffer(struct r300_context *r300, + struct pipe_buffer* indexBuffer, + unsigned indexSize) +{ + assert(indexSize = 2); + + if (!r300->winsys->add_buffer(r300->winsys, indexBuffer, RADEON_GEM_DOMAIN_GTT, 0)) + { + assert(0); + } + + if (!r300->winsys->validate(r300->winsys)) + { + assert(0); + } +} + diff --git a/src/gallium/drivers/r300/r300_vbo.h b/src/gallium/drivers/r300/r300_vbo.h new file mode 100644 index 00000000000..7afa75899cf --- /dev/null +++ b/src/gallium/drivers/r300/r300_vbo.h @@ -0,0 +1,36 @@ +/* + * Copyright 2009 Maciej Cencora + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef R300_VBO_H +#define R300_VBO_H + +struct r300_context; +struct pipe_buffer; + +void setup_vertex_attributes(struct r300_context *r300); + +void setup_index_buffer(struct r300_context *r300, + struct pipe_buffer* indexBuffer, + unsigned indexSize); + +#endif -- cgit v1.2.3 From 1ef0341ea7ee08284ebafe4f347643e1190d5777 Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sun, 25 Oct 2009 13:51:45 +0100 Subject: r300g: don't hang GPU on misbehaving apps --- src/gallium/drivers/r300/r300_render.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 86aaf841dd6..cbda30227da 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -112,6 +112,9 @@ boolean r300_draw_range_elements(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); + if (!u_trim_pipe_prim(mode, &count)) + return false; + r300_update_derived_state(r300); setup_vertex_buffers(r300); @@ -147,6 +150,9 @@ boolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode, { struct r300_context* r300 = r300_context(pipe); + if (!u_trim_pipe_prim(mode, &count)) + return false; + r300_update_derived_state(r300); setup_vertex_buffers(r300); -- cgit v1.2.3 From 24c6fdbd32a84314c81897d0d1567121ed1c6118 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Fri, 6 Nov 2009 20:21:38 -0800 Subject: r300g: Use common state funcs for translating vert formats. --- src/gallium/drivers/r300/r300_vbo.c | 78 +++---------------------------------- 1 file changed, 6 insertions(+), 72 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_vbo.c b/src/gallium/drivers/r300/r300_vbo.c index e0326412865..37b5c9224fc 100644 --- a/src/gallium/drivers/r300/r300_vbo.c +++ b/src/gallium/drivers/r300/r300_vbo.c @@ -27,85 +27,19 @@ #include "r300_cs.h" #include "r300_context.h" +#include "r300_state_inlines.h" #include "r300_reg.h" #include "r300_winsys.h" -static void translate_vertex_format(enum pipe_format format, - unsigned nr_comps, - unsigned component_size, - unsigned dst_loc, - uint32_t *hw_fmt1, - uint32_t *hw_fmt2) -{ - uint32_t fmt1 = 0; - - switch (pf_type(format)) - { - case PIPE_FORMAT_TYPE_FLOAT: - assert(component_size == 4); - fmt1 = R300_DATA_TYPE_FLOAT_1 + nr_comps - 1; - break; - case PIPE_FORMAT_TYPE_UNORM: - case PIPE_FORMAT_TYPE_SNORM: - case PIPE_FORMAT_TYPE_USCALED: - case PIPE_FORMAT_TYPE_SSCALED: - if (component_size == 1) - { - assert(nr_comps == 4); - fmt1 = R300_DATA_TYPE_BYTE; - } - else if (component_size == 2) - { - if (nr_comps == 2) - fmt1 = R300_DATA_TYPE_SHORT_2; - else if (nr_comps == 4) - fmt1 = R300_DATA_TYPE_SHORT_4; - else - assert(0); - } - else - { - assert(0); - } - - if (pf_type(format) == PIPE_FORMAT_TYPE_SNORM) - { - fmt1 |= R300_SIGNED; - } - else if (pf_type(format) == PIPE_FORMAT_TYPE_SSCALED) - { - fmt1 |= R300_SIGNED; - fmt1 |= R300_NORMALIZE; - } - else if (pf_type(format) == PIPE_FORMAT_TYPE_USCALED) - { - fmt1 |= R300_NORMALIZE; - } - break; - default: - assert(0); - break; - } - - *hw_fmt1 = fmt1 | (dst_loc << R300_DST_VEC_LOC_SHIFT); - *hw_fmt2 = (pf_swizzle_x(format) << R300_SWIZZLE_SELECT_X_SHIFT) | - (pf_swizzle_y(format) << R300_SWIZZLE_SELECT_Y_SHIFT) | - (pf_swizzle_z(format) << R300_SWIZZLE_SELECT_Z_SHIFT) | - (pf_swizzle_w(format) << R300_SWIZZLE_SELECT_W_SHIFT) | - (0xf << R300_WRITE_ENA_SHIFT); -} - static INLINE void setup_vertex_attribute(struct r300_vertex_info *vinfo, struct pipe_vertex_element *vert_elem, unsigned attr_num) { - uint32_t hw_fmt1, hw_fmt2; - translate_vertex_format(vert_elem->src_format, - vert_elem->nr_components, - pf_size_x(vert_elem->src_format), - attr_num, - &hw_fmt1, - &hw_fmt2); + uint16_t hw_fmt1, hw_fmt2; + + hw_fmt1 = r300_translate_vertex_data_type(vert_elem->src_format) | + (attr_num << R300_DST_VEC_LOC_SHIFT); + hw_fmt2 = r300_translate_vertex_data_swizzle(vert_elem->src_format); if (attr_num % 2 == 0) { -- cgit v1.2.3 From 96b729f926fafeca6479eed0933bc4275fb7843b Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 7 Nov 2009 09:47:01 -0800 Subject: r300g: Don't pass hw_prim around in the context. And some other fixes. --- src/gallium/drivers/r300/r300_context.h | 1 - src/gallium/drivers/r300/r300_emit.c | 58 ------------------------- src/gallium/drivers/r300/r300_emit.h | 10 ----- src/gallium/drivers/r300/r300_render.c | 76 +++++++++++++++++++++++++++++---- src/gallium/drivers/r300/r300_vbo.c | 10 +++-- 5 files changed, 74 insertions(+), 81 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index a6748852d83..8d14c53f492 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -299,7 +299,6 @@ struct r300_context { /* Vertex elements for Gallium. */ struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; int aos_count; - unsigned hw_prim; /* Bitmask of dirty state objects. */ uint32_t dirty_state; diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 92e6ec606ca..ec1d521800c 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -647,64 +647,6 @@ void r300_emit_draw_packet(struct r300_context* r300) END_CS; } #endif -void r300_emit_draw_arrays(struct r300_context *r300, - unsigned count) -{ - CS_LOCALS(r300); - assert(count < 65536); - - BEGIN_CS(4); - OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count); - OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); - OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | - r300->hw_prim); - END_CS; -} - -void r300_emit_draw_elements(struct r300_context *r300, - struct pipe_buffer* indexBuffer, - unsigned indexSize, - unsigned minIndex, - unsigned maxIndex, - unsigned start, - unsigned count) -{ - CS_LOCALS(r300); - assert(indexSize == 4 || indexSize == 2); - assert(count < 65536); - assert((start * indexSize) % 4 == 0); - - uint32_t size_dwords; - uint32_t skip_dwords = indexSize * start / sizeof(uint32_t); - assert(skip_dwords == 0); - - BEGIN_CS(10); - OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, maxIndex); - OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); - if (indexSize == 4) { - size_dwords = count + start; - OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | - R300_VAP_VF_CNTL__INDEX_SIZE_32bit | r300->hw_prim); - } else { - size_dwords = (count + start + 1) / 2; - OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | - (count << 16) | r300->hw_prim); - } - - OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); - OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) | - (0 << R300_INDX_BUFFER_SKIP_SHIFT)); - OUT_CS(skip_dwords); - OUT_CS(size_dwords); - cs_winsys->write_cs_reloc(cs_winsys, - indexBuffer, - RADEON_GEM_DOMAIN_GTT, - 0, - 0); - cs_count -= 2; - - END_CS; -} void r300_emit_vertex_format_state(struct r300_context* r300) { diff --git a/src/gallium/drivers/r300/r300_emit.h b/src/gallium/drivers/r300/r300_emit.h index b4fdfecde01..7c83c5166de 100644 --- a/src/gallium/drivers/r300/r300_emit.h +++ b/src/gallium/drivers/r300/r300_emit.h @@ -40,16 +40,6 @@ void r300_emit_blend_color_state(struct r300_context* r300, void r300_emit_clip_state(struct r300_context* r300, struct pipe_clip_state* clip); -void r300_emit_draw_arrays(struct r300_context *r300, unsigned count); - -void r300_emit_draw_elements(struct r300_context *r300, - struct pipe_buffer* indexBuffer, - unsigned indexSize, - unsigned minIndex, - unsigned maxIndex, - unsigned start, - unsigned count); - void r300_emit_dsa_state(struct r300_context* r300, struct r300_dsa_state* dsa); diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index cbda30227da..6f7c6453342 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -31,13 +31,13 @@ #include "util/u_memory.h" #include "util/u_prim.h" -#include "r300_vbo.h" #include "r300_cs.h" #include "r300_context.h" #include "r300_emit.h" #include "r300_reg.h" #include "r300_render.h" #include "r300_state_derived.h" +#include "r300_vbo.h" /* r300_render: Vertex and index buffer primitive emission. */ #define R300_MAX_VBO_SIZE (1024 * 1024) @@ -70,6 +70,70 @@ uint32_t r300_translate_primitive(unsigned prim) } } +static void r300_emit_draw_arrays(struct r300_context *r300, + unsigned mode, + unsigned count) +{ + CS_LOCALS(r300); + assert(count < 65536); + + BEGIN_CS(4); + OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | + r300_translate_primitive(mode)); + END_CS; +} + +static void r300_emit_draw_elements(struct r300_context *r300, + struct pipe_buffer* indexBuffer, + unsigned indexSize, + unsigned minIndex, + unsigned maxIndex, + unsigned mode, + unsigned start, + unsigned count) +{ + CS_LOCALS(r300); + assert(indexSize == 4 || indexSize == 2); + assert(count < 65536); + assert((start * indexSize) % 4 == 0); + + uint32_t size_dwords; + uint32_t skip_dwords = indexSize * start / sizeof(uint32_t); + assert(skip_dwords == 0); + + BEGIN_CS(10); + OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, maxIndex); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); + if (indexSize == 4) { + size_dwords = count + start; + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | + R300_VAP_VF_CNTL__INDEX_SIZE_32bit | + r300_translate_primitive(mode)); + } else { + size_dwords = (count + start + 1) / 2; + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | + r300_translate_primitive(mode)); + } + + OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); + OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) | + (0 << R300_INDX_BUFFER_SKIP_SHIFT)); + OUT_CS(skip_dwords); + OUT_CS(size_dwords); + /* XXX hax */ + cs_winsys->write_cs_reloc(cs_winsys, + indexBuffer, + RADEON_GEM_DOMAIN_GTT, + 0, + 0); + cs_count -= 2; + + END_CS; +} + + static boolean setup_vertex_buffers(struct r300_context *r300) { unsigned vbuf_count = r300->aos_count; @@ -123,14 +187,12 @@ boolean r300_draw_range_elements(struct pipe_context* pipe, setup_index_buffer(r300, indexBuffer, indexSize); - r300->hw_prim = r300_translate_primitive(mode); - r300_emit_dirty_state(r300); r300_emit_aos(r300, 0); r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex, - start, count); + mode, start, count); return TRUE; } @@ -159,13 +221,11 @@ boolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode, setup_vertex_attributes(r300); - r300->hw_prim = r300_translate_primitive(mode); - r300_emit_dirty_state(r300); r300_emit_aos(r300, start); - r300_emit_draw_arrays(r300, count); + r300_emit_draw_arrays(r300, mode, count); return TRUE; } @@ -186,8 +246,8 @@ boolean r300_swtcl_draw_range_elements(struct pipe_context* pipe, unsigned count) { assert(0); - struct r300_context* r300 = r300_context(pipe); #if 0 + struct r300_context* r300 = r300_context(pipe); int i; if (!u_trim_pipe_prim(mode, &count)) { diff --git a/src/gallium/drivers/r300/r300_vbo.c b/src/gallium/drivers/r300/r300_vbo.c index 37b5c9224fc..ab6f5c59426 100644 --- a/src/gallium/drivers/r300/r300_vbo.c +++ b/src/gallium/drivers/r300/r300_vbo.c @@ -56,7 +56,8 @@ static INLINE void setup_vertex_attribute(struct r300_vertex_info *vinfo, static void finish_vertex_attribs_setup(struct r300_vertex_info *vinfo, unsigned attribs_num) { - uint32_t last_vec_bit = (attribs_num % 2 == 0) ? (R300_LAST_VEC << 16) : R300_LAST_VEC; + uint32_t last_vec_bit = (attribs_num % 2 == 0) ? + (R300_LAST_VEC << 16) : R300_LAST_VEC; assert(attribs_num > 0 && attribs_num <= 16); vinfo->vap_prog_stream_cntl[(attribs_num - 1) >> 1] |= last_vec_bit; @@ -64,10 +65,11 @@ static void finish_vertex_attribs_setup(struct r300_vertex_info *vinfo, void setup_vertex_attributes(struct r300_context *r300) { - for (int i=0; iaos_count; i++) - { - struct pipe_vertex_element *vert_elem = &r300->vertex_element[i]; + struct pipe_vertex_element *vert_elem; + int i; + for (i = 0; i < r300->aos_count; i++) { + vert_elem = &r300->vertex_element[i]; setup_vertex_attribute(r300->vertex_info, vert_elem, i); } -- cgit v1.2.3 From 7518d9b1b7369f6e5ca1fdaf6a34e39a4acace9a Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 7 Nov 2009 10:05:31 -0800 Subject: r300g: Clean up r300_setup_vertex_buffers. --- src/gallium/drivers/r300/r300_render.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 6f7c6453342..e28af7600a1 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -134,16 +134,16 @@ static void r300_emit_draw_elements(struct r300_context *r300, } -static boolean setup_vertex_buffers(struct r300_context *r300) +static boolean r300_setup_vertex_buffers(struct r300_context *r300) { unsigned vbuf_count = r300->aos_count; - struct pipe_vertex_buffer *vbuf= r300->vertex_buffer; - struct pipe_vertex_element *velem= r300->vertex_element; - bool invalid = false; + struct pipe_vertex_buffer *vbuf = r300->vertex_buffer; + struct pipe_vertex_element *velem = r300->vertex_element; validate: for (int i = 0; i < vbuf_count; i++) { - if (!r300->winsys->add_buffer(r300->winsys, vbuf[velem[i].vertex_buffer_index].buffer, + if (!r300->winsys->add_buffer(r300->winsys, + vbuf[velem[i].vertex_buffer_index].buffer, RADEON_GEM_DOMAIN_GTT, 0)) { r300->context.flush(&r300->context, 0, NULL); goto validate; @@ -152,16 +152,10 @@ validate: if (!r300->winsys->validate(r300->winsys)) { r300->context.flush(&r300->context, 0, NULL); - if (invalid) { - /* Well, hell. */ - debug_printf("r300: Stuck in validation loop, gonna quit now."); - exit(1); - } - invalid = true; - goto validate; + return r300->winsys->validate(r300->winsys); } - return invalid; + return TRUE; } /* This is the fast-path drawing & emission for HW TCL. */ @@ -181,7 +175,9 @@ boolean r300_draw_range_elements(struct pipe_context* pipe, r300_update_derived_state(r300); - setup_vertex_buffers(r300); + if (!r300_setup_vertex_buffers(r300)) { + return FALSE; + } setup_vertex_attributes(r300); @@ -217,7 +213,9 @@ boolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode, r300_update_derived_state(r300); - setup_vertex_buffers(r300); + if (!r300_setup_vertex_buffers(r300)) { + return FALSE; + } setup_vertex_attributes(r300); -- cgit v1.2.3 From 7da3cc4241b8550ccc1ec5ba3c93334094f5fb11 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 7 Nov 2009 10:14:07 -0800 Subject: r300g: Clean up indexbuf render, switch to RELOC macro. --- src/gallium/drivers/r300/r300_render.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index e28af7600a1..b4351d541d7 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -94,41 +94,43 @@ static void r300_emit_draw_elements(struct r300_context *r300, unsigned start, unsigned count) { + uint32_t count_dwords; + uint32_t offset_dwords = indexSize * start / sizeof(uint32_t); CS_LOCALS(r300); + + /* XXX most of these are stupid */ assert(indexSize == 4 || indexSize == 2); assert(count < 65536); assert((start * indexSize) % 4 == 0); - - uint32_t size_dwords; - uint32_t skip_dwords = indexSize * start / sizeof(uint32_t); - assert(skip_dwords == 0); + assert(offset_dwords == 0); BEGIN_CS(10); OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, maxIndex); OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); if (indexSize == 4) { - size_dwords = count + start; + count_dwords = count + start; OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | R300_VAP_VF_CNTL__INDEX_SIZE_32bit | r300_translate_primitive(mode)); } else { - size_dwords = (count + start + 1) / 2; + count_dwords = (count + start + 1) / 2; OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | r300_translate_primitive(mode)); } + /* INDX_BUFFER is a truly special packet3. + * Unlike most other packet3, where the offset is after the count, + * the order is reversed, so the relocation ends up carrying the + * size of the indexbuf instead of the offset. + * + * XXX Fix offset + */ OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) | (0 << R300_INDX_BUFFER_SKIP_SHIFT)); - OUT_CS(skip_dwords); - OUT_CS(size_dwords); - /* XXX hax */ - cs_winsys->write_cs_reloc(cs_winsys, - indexBuffer, - RADEON_GEM_DOMAIN_GTT, - 0, - 0); - cs_count -= 2; + OUT_CS(offset_dwords); + OUT_CS_RELOC(indexBuffer, count_dwords, + RADEON_GEM_DOMAIN_GTT, 0, 0); END_CS; } -- cgit v1.2.3 From b6c3954138ef70ea7d2cbd3ba9519f404ef616d7 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 7 Nov 2009 10:26:57 -0800 Subject: r300g: s/false/FALSE/ Also s/true/TRUE/ --- src/gallium/drivers/r300/r300_render.c | 4 ++-- src/gallium/drivers/r300/r300_vbo.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index b4351d541d7..1532de367f6 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -173,7 +173,7 @@ boolean r300_draw_range_elements(struct pipe_context* pipe, struct r300_context* r300 = r300_context(pipe); if (!u_trim_pipe_prim(mode, &count)) - return false; + return FALSE; r300_update_derived_state(r300); @@ -211,7 +211,7 @@ boolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode, struct r300_context* r300 = r300_context(pipe); if (!u_trim_pipe_prim(mode, &count)) - return false; + return FALSE; r300_update_derived_state(r300); diff --git a/src/gallium/drivers/r300/r300_vbo.c b/src/gallium/drivers/r300/r300_vbo.c index ab6f5c59426..be74a49eb8c 100644 --- a/src/gallium/drivers/r300/r300_vbo.c +++ b/src/gallium/drivers/r300/r300_vbo.c @@ -84,27 +84,27 @@ static void finish_vertex_arrays_setup(struct r300_context *r300) { } -static bool format_is_supported(enum pipe_format format, int nr_components) +static boolean format_is_supported(enum pipe_format format, int nr_components) { if (pf_layout(format) != PIPE_FORMAT_LAYOUT_RGBAZS) - return false; + return FALSE; if ((pf_size_x(format) != pf_size_y(format)) || (pf_size_x(format) != pf_size_z(format)) || (pf_size_x(format) != pf_size_w(format))) - return false; + return FALSE; /* Following should be supported as long as stride is 4 bytes aligned */ if (pf_size_x(format) != 1 && nr_components != 4) - return false; + return FALSE; if (pf_size_x(format) != 2 && !(nr_components == 2 || nr_components == 4)) - return false; + return FALSE; if (pf_size_x(format) == 3 || pf_size_x(format) > 4) - return false; + return FALSE; - return true; + return TRUE; } static INLINE int get_buffer_offset(struct r300_context *r300, -- cgit v1.2.3 From 746c01b3b2f77d8d8ba14fc517d04dbaf080d77d Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 7 Nov 2009 10:34:00 -0800 Subject: r300g: Moar vbo cleanup. --- src/gallium/drivers/r300/r300_vbo.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_vbo.c b/src/gallium/drivers/r300/r300_vbo.c index be74a49eb8c..cec79ec97e0 100644 --- a/src/gallium/drivers/r300/r300_vbo.c +++ b/src/gallium/drivers/r300/r300_vbo.c @@ -118,13 +118,16 @@ static INLINE int get_buffer_offset(struct r300_context *r300, */ static void setup_vertex_buffers(struct r300_context *r300) { - for (int i=0; iaos_count; i++) + struct pipe_vertex_element *vert_elem; + int i; + + for (i = 0; i < r300->aos_count; i++) { - struct pipe_vertex_element *vert_elem = &r300->vertex_element[i]; - if (!format_is_supported(vert_elem->src_format, vert_elem->nr_components)) - { + vert_elem = &r300->vertex_element[i]; + if (!format_is_supported(vert_elem->src_format, + vert_elem->nr_components)) { + /* XXX use translate module to convert the data */ assert(0); - /* use translate module to convert the data */ /* struct pipe_buffer *buf; const unsigned int max_index = r300->vertex_buffers[vert_elem->vertex_buffer_index].max_index; @@ -132,9 +135,10 @@ static void setup_vertex_buffers(struct r300_context *r300) */ } - if (get_buffer_offset(r300, vert_elem->vertex_buffer_index, vert_elem->src_offset) % 4 != 0) - { - /* need to align buffer */ + if (get_buffer_offset(r300, + vert_elem->vertex_buffer_index, + vert_elem->src_offset) % 4) { + /* XXX need to align buffer */ assert(0); } setup_vertex_array(r300, vert_elem); -- cgit v1.2.3 From ef513776b5bdd11968d2ca03862e9d1ac48e099f Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 7 Nov 2009 10:39:42 -0800 Subject: r300g: Don't assert on oversized VBOs, just return FALSE. --- src/gallium/drivers/r300/r300_render.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 1532de367f6..89bf749b5fa 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -75,7 +75,6 @@ static void r300_emit_draw_arrays(struct r300_context *r300, unsigned count) { CS_LOCALS(r300); - assert(count < 65536); BEGIN_CS(4); OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count); @@ -100,7 +99,6 @@ static void r300_emit_draw_elements(struct r300_context *r300, /* XXX most of these are stupid */ assert(indexSize == 4 || indexSize == 2); - assert(count < 65536); assert((start * indexSize) % 4 == 0); assert(offset_dwords == 0); @@ -172,8 +170,13 @@ boolean r300_draw_range_elements(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); - if (!u_trim_pipe_prim(mode, &count)) + if (!u_trim_pipe_prim(mode, &count)) { return FALSE; + } + + if (count > 65535) { + return FALSE; + } r300_update_derived_state(r300); @@ -210,8 +213,13 @@ boolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode, { struct r300_context* r300 = r300_context(pipe); - if (!u_trim_pipe_prim(mode, &count)) + if (!u_trim_pipe_prim(mode, &count)) { return FALSE; + } + + if (count > 65535) { + return FALSE; + } r300_update_derived_state(r300); -- cgit v1.2.3 From cd5b2a93d5c9c60dbe72ebc963dcddf0db0b665c Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 7 Nov 2009 10:52:06 -0800 Subject: r300g: Comments. --- src/gallium/drivers/r300/r300_render.c | 3 ++- src/gallium/drivers/r300/r300_vbo.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 89bf749b5fa..0df9a946102 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -243,7 +243,8 @@ boolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode, * keep these functions separated so that they are easier to locate. ~C. * ***************************************************************************/ -/* Draw-based drawing for SW TCL chipsets. */ +/* Draw-based drawing for SW TCL chipsets. + * XXX currently broken as fucking hell. */ boolean r300_swtcl_draw_range_elements(struct pipe_context* pipe, struct pipe_buffer* indexBuffer, unsigned indexSize, diff --git a/src/gallium/drivers/r300/r300_vbo.c b/src/gallium/drivers/r300/r300_vbo.c index cec79ec97e0..d8b356a0617 100644 --- a/src/gallium/drivers/r300/r300_vbo.c +++ b/src/gallium/drivers/r300/r300_vbo.c @@ -21,6 +21,9 @@ * USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/* r300_vbo: Various helpers for emitting vertex buffers. Needs cleanup, + * refactoring, etc. */ + #include "r300_vbo.h" #include "pipe/p_format.h" @@ -76,6 +79,7 @@ void setup_vertex_attributes(struct r300_context *r300) finish_vertex_attribs_setup(r300->vertex_info, r300->aos_count); } +/* XXX WTF are these doing? */ static void setup_vertex_array(struct r300_context *r300, struct pipe_vertex_element *element) { } @@ -84,6 +88,7 @@ static void finish_vertex_arrays_setup(struct r300_context *r300) { } +/* XXX move/integrate this with the checks in r300_state_inlines */ static boolean format_is_supported(enum pipe_format format, int nr_components) { if (pf_layout(format) != PIPE_FORMAT_LAYOUT_RGBAZS) @@ -151,16 +156,15 @@ void setup_index_buffer(struct r300_context *r300, struct pipe_buffer* indexBuffer, unsigned indexSize) { + /* XXX I call BS; why is this different from the assert in r300_render? */ assert(indexSize = 2); - if (!r300->winsys->add_buffer(r300->winsys, indexBuffer, RADEON_GEM_DOMAIN_GTT, 0)) - { + if (!r300->winsys->add_buffer(r300->winsys, indexBuffer, + RADEON_GEM_DOMAIN_GTT, 0)) { assert(0); } - if (!r300->winsys->validate(r300->winsys)) - { + if (!r300->winsys->validate(r300->winsys)) { assert(0); } } - -- cgit v1.2.3 From 0fe5f0c09abce9d540d51942eab08b2248243943 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 7 Nov 2009 11:49:39 -0800 Subject: r300g: Be more verbose in what's killing us WRT vert formats. --- src/gallium/drivers/r300/r300_state_inlines.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/r300/r300_state_inlines.h b/src/gallium/drivers/r300/r300_state_inlines.h index 52b9650fc16..e53db3d0b55 100644 --- a/src/gallium/drivers/r300/r300_state_inlines.h +++ b/src/gallium/drivers/r300/r300_state_inlines.h @@ -434,8 +434,8 @@ r300_translate_vertex_data_type(enum pipe_format format) { unsigned components = pf_component_count(format); if (pf_layout(format) != PIPE_FORMAT_LAYOUT_RGBAZS) { - debug_printf("r300: Bad format %s in %s\n", pf_name(format), - __FUNCTION__); + debug_printf("r300: Bad format %s in %s:%d\n", pf_name(format), + __FUNCTION__, __LINE__); return 0; } @@ -447,6 +447,8 @@ r300_translate_vertex_data_type(enum pipe_format format) { result = R300_DATA_TYPE_FLOAT_1 + (components - 1); break; default: + debug_printf("r300: Bad format %s in %s:%d\n", + pf_name(format), __FUNCTION__, __LINE__); assert(0); } break; @@ -470,10 +472,16 @@ r300_translate_vertex_data_type(enum pipe_format format) { } break; default: + debug_printf("r300: Bad format %s in %s:%d\n", + pf_name(format), __FUNCTION__, __LINE__); + debug_printf("r300: pf_size_x(format) == %d\n", + pf_size_x(format)); assert(0); } break; default: + debug_printf("r300: Bad format %s in %s:%d\n", + pf_name(format), __FUNCTION__, __LINE__); assert(0); } @@ -492,8 +500,8 @@ static INLINE uint16_t r300_translate_vertex_data_swizzle(enum pipe_format format) { if (pf_layout(format) != PIPE_FORMAT_LAYOUT_RGBAZS) { - debug_printf("r300: Bad format %s in %s\n", pf_name(format), - __FUNCTION__); + debug_printf("r300: Bad format %s in %s:%d\n", + pf_name(format), __FUNCTION__, __LINE__); return 0; } -- cgit v1.2.3