diff options
-rw-r--r-- | src/gallium/drivers/r300/r300_context.h | 11 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_state_derived.c | 173 |
2 files changed, 108 insertions, 76 deletions
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index fec2bad5461..4c695c1195a 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -60,7 +60,7 @@ struct r300_dsa_state { }; struct r300_rs_state { - /* XXX icky as fucking hell */ + /* Draw-specific rasterizer state */ struct pipe_rasterizer_state rs; uint32_t vap_control_status; /* R300_VAP_CNTL_STATUS: 0x2140 */ @@ -225,10 +225,11 @@ struct r300_vertex_format { uint32_t vap_prog_stream_cntl[8]; /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */ uint32_t vap_prog_stream_cntl_ext[8]; - /* This is a map of VAP/SW TCL outputs into the GA/RS. - * tab[i] is the location of input i in GA/RS input memory. - * Named tab for historical reasons. */ - int tab[16]; + /* 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]; }; struct r300_vertex_shader { diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index f1feafbcf91..a777771930b 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -25,37 +25,35 @@ /* r300_state_derived: Various bits of state which are dependent upon * currently bound CSO data. */ -/* Update the vertex_info struct in our r300_context. - * - * The vertex_info struct describes the post-TCL format of vertices. It is - * required for Draw when doing SW TCL, and also for describing the - * dreaded RS block on R300 chipsets. */ -static void r300_update_vertex_layout(struct r300_context* r300) +/* Set up the vs_tab and routes. */ +static void r300_vs_tab_routes(struct r300_context* r300, + struct r300_vertex_format* vformat) { struct r300_screen* r300screen = r300_screen(r300->context.screen); - struct r300_vertex_format vformat; - struct vertex_info vinfo; + struct vertex_info* vinfo = &vformat->vinfo; + int* tab = vformat->vs_tab; boolean pos = FALSE, psize = FALSE, fog = FALSE; int i, texs = 0, cols = 0; - int tab[16]; - - struct tgsi_shader_info* info = &r300->fs->info; + struct tgsi_shader_info* info; - memset(&vinfo, 0, sizeof(vinfo)); - for (i = 0; i < 16; i++) { - tab[i] = -1; + if (r300screen->caps->has_tcl) { + /* Use vertex shader to determine required routes. */ + info = &r300->vs->info; + } else { + /* Use fragment shader to determine required routes. */ + info = &r300->fs->info; } assert(info->num_inputs <= 16); - for (i = 0; i < info->num_inputs; i++) { - switch (info->input_semantic_name[i]) { + switch (info->output_semantic_name[i]) { case TGSI_SEMANTIC_POSITION: pos = TRUE; tab[i] = 0; break; case TGSI_SEMANTIC_COLOR: - tab[i] = 2 + cols++; + tab[i] = 2 + cols; + cols++; break; case TGSI_SEMANTIC_PSIZE: psize = TRUE; @@ -63,9 +61,10 @@ static void r300_update_vertex_layout(struct r300_context* r300) break; case TGSI_SEMANTIC_FOG: fog = TRUE; - /* Fall through... */ + /* Fall through */ case TGSI_SEMANTIC_GENERIC: - tab[i] = 6 + texs++; + tab[i] = 6 + texs; + texs++; break; default: debug_printf("r300: Unknown vertex input %d\n", @@ -75,8 +74,8 @@ static void r300_update_vertex_layout(struct r300_context* r300) } if (r300screen->caps->has_tcl) { + /* Just copy vert attribs over as-is. */ for (i = 0; i < info->num_inputs; i++) { - /* XXX should probably do real lookup with vert shader */ tab[i] = i; } } @@ -89,7 +88,7 @@ static void r300_update_vertex_layout(struct r300_context* r300) * vinfo.hwfmt[2] is R300_VAP_OUTPUT_VTX_FMT_0 * vinfo.hwfmt[3] is R300_VAP_OUTPUT_VTX_FMT_1 */ - vinfo.hwfmt[0] = 0x5555; /* XXX this is classic Mesa bonghits */ + vinfo->hwfmt[0] = 0x5555; /* XXX this is classic Mesa bonghits */ if (!pos) { debug_printf("r300: Forcing vertex position attribute emit...\n"); @@ -100,80 +99,112 @@ static void r300_update_vertex_layout(struct r300_context* r300) } tab[0] = 0; - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_POS, + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_POS, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_POSITION, 0)); } else { - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_POSITION, 0)); } - vinfo.hwfmt[1] |= R300_INPUT_CNTL_POS; - vinfo.hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; + vinfo->hwfmt[1] |= R300_INPUT_CNTL_POS; + vinfo->hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; if (psize) { - draw_emit_vertex_attr(&vinfo, EMIT_1F_PSIZE, INTERP_POS, + draw_emit_vertex_attr(vinfo, EMIT_1F_PSIZE, INTERP_POS, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_PSIZE, 0)); - vinfo.hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT; + vinfo->hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT; } for (i = 0; i < cols; i++) { - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_LINEAR, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_COLOR, i)); - vinfo.hwfmt[1] |= R300_INPUT_CNTL_COLOR; - vinfo.hwfmt[2] |= (R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i); + vinfo->hwfmt[1] |= R300_INPUT_CNTL_COLOR; + vinfo->hwfmt[2] |= (R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i); } for (i = 0; i < texs; i++) { - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_GENERIC, i)); - vinfo.hwfmt[1] |= (R300_INPUT_CNTL_TC0 << i); - vinfo.hwfmt[3] |= (4 << (3 * i)); + vinfo->hwfmt[1] |= (R300_INPUT_CNTL_TC0 << i); + vinfo->hwfmt[3] |= (4 << (3 * i)); } if (fog) { i++; - draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, draw_find_vs_output(r300->draw, TGSI_SEMANTIC_FOG, 0)); - vinfo.hwfmt[1] |= (R300_INPUT_CNTL_TC0 << i); - vinfo.hwfmt[3] |= (4 << (3 * i)); + vinfo->hwfmt[1] |= (R300_INPUT_CNTL_TC0 << i); + vinfo->hwfmt[3] |= (4 << (3 * i)); } - draw_compute_vertex_size(&vinfo); - - if (memcmp(&r300->vertex_info, &vinfo, sizeof(struct vertex_info))) { - uint32_t temp; - debug_printf("attrib count: %d, fp input count: %d\n", - vinfo.num_attribs, info->num_inputs); - for (i = 0; i < vinfo.num_attribs; i++) { - debug_printf("attrib: offset %d, interp %d, size %d," - " tab %d\n", vinfo.attrib[i].src_index, - vinfo.attrib[i].interp_mode, vinfo.attrib[i].emit, - tab[i]); - } + draw_compute_vertex_size(vinfo); +} - for (i = 0; i < vinfo.num_attribs; i++) { - /* Make sure we have a proper destination for our attribute */ - assert(tab[i] != -1); - - temp = translate_vertex_data_type(vinfo.attrib[i].emit) | - (tab[i] << R300_DST_VEC_LOC_SHIFT); - if (i & 1) { - r300->vertex_info.vap_prog_stream_cntl[i >> 1] &= 0x0000ffff; - r300->vertex_info.vap_prog_stream_cntl[i >> 1] |= temp << 16; - } else { - r300->vertex_info.vap_prog_stream_cntl[i >> 1] &= 0xffff0000; - r300->vertex_info.vap_prog_stream_cntl[i >> 1] |= temp; - } +/* Update the PSC tables. */ +static void r300_vertex_psc(struct r300_context* r300, + struct r300_vertex_format* vformat) +{ + struct vertex_info* vinfo = &vformat->vinfo; + int* tab = vformat->vs_tab; + uint32_t temp; + int i; + + debug_printf("r300: attrib count: %d\n", vinfo->num_attribs); + for (i = 0; i < vinfo->num_attribs; i++) { + debug_printf("r300: attrib: offset %d, interp %d, size %d," + " tab %d\n", vinfo->attrib[i].src_index, + vinfo->attrib[i].interp_mode, vinfo->attrib[i].emit, + tab[i]); + } - r300->vertex_info.vap_prog_stream_cntl_ext[i >> 1] |= - (R300_VAP_SWIZZLE_XYZW << (i & 1 ? 16 : 0)); + for (i = 0; i < vinfo->num_attribs; i++) { + /* Make sure we have a proper destination for our attribute */ + assert(tab[i] != -1); + + /* Add the attribute to the PSC table. */ + temp = translate_vertex_data_type(vinfo->attrib[i].emit) | + (tab[i] << R300_DST_VEC_LOC_SHIFT); + 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_ext[i >> 1] |= + (R300_VAP_SWIZZLE_XYZW << 16); + } else { + vformat->vap_prog_stream_cntl[i >> 1] &= 0xffff0000; + vformat->vap_prog_stream_cntl[i >> 1] |= temp << 0; + + vformat->vap_prog_stream_cntl_ext[i >> 1] |= + (R300_VAP_SWIZZLE_XYZW << 0); } - /* Set the last vector. */ - i--; - r300->vertex_info.vap_prog_stream_cntl[i >> 1] |= (R300_LAST_VEC << - (i & 1 ? 16 : 0)); + } + + /* Set the last vector in the PSC. */ + i--; + vformat->vap_prog_stream_cntl[i >> 1] |= + (R300_LAST_VEC << (i & 1 ? 16 : 0)); +} + +/* Update the vertex format. */ +static void r300_update_vertex_format(struct r300_context* r300) +{ + struct r300_screen* r300screen = r300_screen(r300->context.screen); + struct r300_vertex_format vformat; + int i; + + memset(&vformat, 0, sizeof(struct r300_vertex_format)); + for (i = 0; i < 16; i++) { + vformat.vs_tab[i] = -1; + vformat.fs_tab[i] = -1; + } + + r300_vs_tab_routes(r300, &vformat); + + r300_vertex_psc(r300, &vformat); - memcpy(r300->vertex_info.tab, tab, sizeof(tab)); - memcpy(&r300->vertex_info, &vinfo, sizeof(struct vertex_info)); + if (memcmp(&r300->vertex_info, &vformat, + sizeof(struct r300_vertex_format))) { + memcpy(&r300->vertex_info, &vformat, + sizeof(struct r300_vertex_format)); r300->dirty_state |= R300_NEW_VERTEX_FORMAT; } } @@ -185,7 +216,7 @@ static void r300_update_rs_block(struct r300_context* r300) { struct r300_rs_block* rs = r300->rs_block; struct vertex_info* vinfo = &r300->vertex_info.vinfo; - int* tab = r300->vertex_info.tab; + int* tab = r300->vertex_info.vs_tab; int col_count = 0, fp_offset = 0, i, memory_pos, tex_count = 0; memset(rs, 0, sizeof(struct r300_rs_block)); @@ -307,7 +338,7 @@ void r300_update_derived_state(struct r300_context* r300) { if (r300->dirty_state & (R300_NEW_FRAGMENT_SHADER | R300_NEW_VERTEX_SHADER)) { - r300_update_vertex_layout(r300); + r300_update_vertex_format(r300); } if (r300->dirty_state & R300_NEW_VERTEX_FORMAT) { |