Rob Clark <[email protected]> writes: > On Tue, Aug 4, 2015 at 5:28 PM, Eric Anholt <[email protected]> wrote: >> This avoids exceeding the size of the .index bitfield since it got >> truncated, and should make our NIR look more like the NIR that the rest of >> the NIR developers are working on. >> --- >> The freedreno changes here are untested. >> >> src/gallium/auxiliary/nir/tgsi_to_nir.c | 144 +++++++++++++++-- >> src/gallium/auxiliary/nir/tgsi_to_nir.h | 3 + >> .../drivers/freedreno/ir3/ir3_compiler_nir.c | 14 +- >> src/gallium/drivers/vc4/vc4_context.h | 9 +- >> src/gallium/drivers/vc4/vc4_nir_lower_io.c | 18 +-- >> src/gallium/drivers/vc4/vc4_opt_dead_code.c | 2 +- >> src/gallium/drivers/vc4/vc4_program.c | 174 >> +++++++++------------ >> src/gallium/drivers/vc4/vc4_qir.c | 2 +- >> src/gallium/drivers/vc4/vc4_qir.h | 21 ++- >> 9 files changed, 241 insertions(+), 146 deletions(-) >> >> diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c >> b/src/gallium/auxiliary/nir/tgsi_to_nir.c >> index 4130697..983d19d 100644 >> --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c >> +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c >> @@ -93,6 +93,99 @@ struct ttn_compile { >> #define ttn_channel(b, src, swiz) \ >> nir_swizzle(b, src, SWIZ(swiz, swiz, swiz, swiz), 1, false) >> >> +static gl_varying_slot >> +tgsi_varying_semantic_to_slot(unsigned semantic, unsigned index) >> +{ >> + switch (semantic) { >> + case TGSI_SEMANTIC_POSITION: >> + return VARYING_SLOT_POS; >> + case TGSI_SEMANTIC_COLOR: >> + if (index == 0) >> + return VARYING_SLOT_COL0; >> + else >> + return VARYING_SLOT_COL1; >> + case TGSI_SEMANTIC_BCOLOR: >> + if (index == 0) >> + return VARYING_SLOT_BFC0; >> + else >> + return VARYING_SLOT_BFC1; >> + case TGSI_SEMANTIC_FOG: >> + return VARYING_SLOT_FOGC; >> + case TGSI_SEMANTIC_PSIZE: >> + return VARYING_SLOT_PSIZ; >> + case TGSI_SEMANTIC_GENERIC: >> + return VARYING_SLOT_VAR0 + index; >> + case TGSI_SEMANTIC_FACE: >> + return VARYING_SLOT_FACE; >> + case TGSI_SEMANTIC_EDGEFLAG: >> + return VARYING_SLOT_EDGE; >> + case TGSI_SEMANTIC_PRIMID: >> + return VARYING_SLOT_PRIMITIVE_ID; >> + case TGSI_SEMANTIC_CLIPDIST: >> + if (index == 0) >> + return VARYING_SLOT_CLIP_DIST0; >> + else >> + return VARYING_SLOT_CLIP_DIST1; >> + case TGSI_SEMANTIC_CLIPVERTEX: >> + return VARYING_SLOT_CLIP_VERTEX; >> + case TGSI_SEMANTIC_TEXCOORD: >> + return VARYING_SLOT_TEX0 + index; >> + case TGSI_SEMANTIC_PCOORD: >> + return VARYING_SLOT_PNTC; >> + case TGSI_SEMANTIC_VIEWPORT_INDEX: >> + return VARYING_SLOT_VIEWPORT; >> + case TGSI_SEMANTIC_LAYER: >> + return VARYING_SLOT_LAYER; >> + default: >> + fprintf(stderr, "Bad TGSI semantic: %d/%d\n", semantic, index); >> + abort(); >> + } >> +} >> + >> +void >> +varying_slot_to_tgsi_semantic(gl_varying_slot slot, >> + unsigned *semantic_name, unsigned >> *semantic_index) >> +{ >> + static const unsigned map[][2] = { >> + [VARYING_SLOT_POS] = { TGSI_SEMANTIC_POSITION, 0 }, >> + [VARYING_SLOT_COL0] = { TGSI_SEMANTIC_COLOR, 0 }, >> + [VARYING_SLOT_COL1] = { TGSI_SEMANTIC_COLOR, 1 }, >> + [VARYING_SLOT_BFC0] = { TGSI_SEMANTIC_BCOLOR, 0 }, >> + [VARYING_SLOT_BFC1] = { TGSI_SEMANTIC_BCOLOR, 1 }, >> + [VARYING_SLOT_FOGC] = { TGSI_SEMANTIC_FOG, 0 }, >> + [VARYING_SLOT_PSIZ] = { TGSI_SEMANTIC_PSIZE, 0 }, >> + [VARYING_SLOT_FACE] = { TGSI_SEMANTIC_FACE, 0 }, >> + [VARYING_SLOT_EDGE] = { TGSI_SEMANTIC_EDGEFLAG, 0 }, >> + [VARYING_SLOT_PRIMITIVE_ID] = { TGSI_SEMANTIC_PRIMID, 0 }, >> + [VARYING_SLOT_CLIP_DIST0] = { TGSI_SEMANTIC_CLIPDIST, 0 }, >> + [VARYING_SLOT_CLIP_DIST1] = { TGSI_SEMANTIC_CLIPDIST, 1 }, >> + [VARYING_SLOT_CLIP_VERTEX] = { TGSI_SEMANTIC_CLIPVERTEX, 0 }, >> + [VARYING_SLOT_PNTC] = { TGSI_SEMANTIC_PCOORD, 0 }, >> + [VARYING_SLOT_VIEWPORT] = { TGSI_SEMANTIC_VIEWPORT_INDEX, 0 }, >> + [VARYING_SLOT_LAYER] = { TGSI_SEMANTIC_LAYER, 0 }, >> + }; >> + >> + if (slot >= VARYING_SLOT_VAR0) { >> + *semantic_name = TGSI_SEMANTIC_GENERIC; >> + *semantic_index = slot - VARYING_SLOT_VAR0; >> + return; >> + } >> + >> + if (slot >= VARYING_SLOT_TEX0 && slot <= VARYING_SLOT_TEX7) { >> + *semantic_name = TGSI_SEMANTIC_TEXCOORD; >> + *semantic_index = slot - VARYING_SLOT_TEX0; >> + return; >> + } >> + >> + if (slot >= ARRAY_SIZE(map)) { >> + fprintf(stderr, "Unknown varying slot %d\n", slot); >> + abort(); >> + } >> + >> + *semantic_name = map[slot][0]; >> + *semantic_index = map[slot][1]; >> +} >> + >> static nir_ssa_def * >> ttn_src_for_dest(nir_builder *b, nir_alu_dest *dest) >> { >> @@ -215,12 +308,14 @@ ttn_emit_declaration(struct ttn_compile *c) >> var->data.mode = nir_var_shader_in; >> var->name = ralloc_asprintf(var, "in_%d", idx); >> >> - /* We should probably translate to a VERT_ATTRIB_* or >> VARYING_SLOT_* >> - * instead, but nothing in NIR core is looking at the value >> - * currently, and this is less change to drivers. >> - */ >> - var->data.location = decl->Semantic.Name; >> - var->data.index = decl->Semantic.Index; >> + if (c->scan->processor == TGSI_PROCESSOR_FRAGMENT) { >> + var->data.location = >> + tgsi_varying_semantic_to_slot(decl->Semantic.Name, >> + decl->Semantic.Index); >> + } else { >> + var->data.location = idx; >> + } >> + var->data.index = 0; >> >> /* We definitely need to translate the interpolation field, >> because >> * nir_print will decode it. >> @@ -240,6 +335,8 @@ ttn_emit_declaration(struct ttn_compile *c) >> exec_list_push_tail(&b->shader->inputs, &var->node); >> break; >> case TGSI_FILE_OUTPUT: { >> + int semantic_name = decl->Semantic.Name; >> + int semantic_index = decl->Semantic.Index; >> /* Since we can't load from outputs in the IR, we make >> temporaries >> * for the outputs and emit stores to the real outputs at the >> end of >> * the shader. >> @@ -251,14 +348,33 @@ ttn_emit_declaration(struct ttn_compile *c) >> >> var->data.mode = nir_var_shader_out; >> var->name = ralloc_asprintf(var, "out_%d", idx); >> - >> - var->data.location = decl->Semantic.Name; >> - if (decl->Semantic.Name == TGSI_SEMANTIC_COLOR && >> - decl->Semantic.Index == 0 && >> - >> c->scan->properties[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS]) >> - var->data.index = -1; >> - else >> - var->data.index = decl->Semantic.Index; >> + var->data.index = 0; >> + >> + if (c->scan->processor == TGSI_PROCESSOR_FRAGMENT) { >> + switch (semantic_name) { >> + case TGSI_SEMANTIC_COLOR: >> + if (semantic_index == 1) { >> + var->data.location = FRAG_RESULT_DATA0; >> + var->data.index = 1; >> + } else { >> + if >> (c->scan->properties[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS]) >> + var->data.location = FRAG_RESULT_COLOR; >> + else >> + var->data.location = FRAG_RESULT_DATA0; >> + } > > hmm, this doesn't quite look right for MRT.. > > At any rate, I'm kinda thinking it is a better idea to revert the > patch that changed index to one bit, and then re-apply it again > *after* we've managed to work the kinks out of > VARYING_SLOT_*/FRAG_RESULT_*...
So we just add semantic_index here -- anything else?
signature.asc
Description: PGP signature
_______________________________________________ mesa-dev mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-dev
