summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2015-08-04 14:28:02 -0700
committerEric Anholt <[email protected]>2015-09-16 15:03:53 -0400
commit8fd3e53f3dc40e4013348e63a0cc7a2787410899 (patch)
treec5bca82d5093d81a4b5ecd7d5232c636dd684761 /src/gallium/auxiliary
parent7a275fcda8ffa3d69b7be6f356469f4af272a6ad (diff)
gallium/ttn: Convert to using VARYING_SLOT_* / FRAG_RESULT_*.
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. v2: split out vc4 updates, first patch uses varying_slot_to_tgsi_semantic() helper, and second patch does the actual conversion. v3: add frag_result_to_tgsi_semantic() helper and don't try to map frag_results to semantic name/index as if they were varying_slot's v4: use VERT_ATTRIB_ for VS inputs v5: Fix vc4 build. Signed-off-by: Rob Clark <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/nir/tgsi_to_nir.c181
-rw-r--r--src/gallium/auxiliary/nir/tgsi_to_nir.h6
2 files changed, 173 insertions, 14 deletions
diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c
index cccc5606ccf..cf43ef2506f 100644
--- a/src/gallium/auxiliary/nir/tgsi_to_nir.c
+++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c
@@ -94,6 +94,128 @@ 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();
+ }
+}
+
+/* Temporary helper to remap back to TGSI style semantic name/index
+ * values, for use in drivers that haven't been converted to using
+ * VARYING_SLOT_
+ */
+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];
+}
+
+/* Temporary helper to remap back to TGSI style semantic name/index
+ * values, for use in drivers that haven't been converted to using
+ * FRAG_RESULT_
+ */
+void
+frag_result_to_tgsi_semantic(gl_frag_result slot,
+ unsigned *semantic_name, unsigned *semantic_index)
+{
+ static const unsigned map[][2] = {
+ [FRAG_RESULT_DEPTH] = { TGSI_SEMANTIC_POSITION, 0 },
+ [FRAG_RESULT_COLOR] = { TGSI_SEMANTIC_COLOR, -1 },
+ [FRAG_RESULT_DATA0 + 0] = { TGSI_SEMANTIC_COLOR, 0 },
+ [FRAG_RESULT_DATA0 + 1] = { TGSI_SEMANTIC_COLOR, 1 },
+ [FRAG_RESULT_DATA0 + 2] = { TGSI_SEMANTIC_COLOR, 2 },
+ [FRAG_RESULT_DATA0 + 3] = { TGSI_SEMANTIC_COLOR, 3 },
+ [FRAG_RESULT_DATA0 + 4] = { TGSI_SEMANTIC_COLOR, 4 },
+ [FRAG_RESULT_DATA0 + 5] = { TGSI_SEMANTIC_COLOR, 5 },
+ [FRAG_RESULT_DATA0 + 6] = { TGSI_SEMANTIC_COLOR, 6 },
+ [FRAG_RESULT_DATA0 + 7] = { TGSI_SEMANTIC_COLOR, 7 },
+ };
+
+ *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)
{
@@ -216,12 +338,15 @@ 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 {
+ assert(!decl->Declaration.Semantic);
+ var->data.location = VERT_ATTRIB_GENERIC0 + idx;
+ }
+ var->data.index = 0;
/* We definitely need to translate the interpolation field, because
* nir_print will decode it.
@@ -241,6 +366,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.
@@ -252,14 +379,40 @@ 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: {
+ /* TODO tgsi loses some information, so we cannot
+ * actually differentiate here between DSB and MRT
+ * at this point. But so far no drivers using tgsi-
+ * to-nir support dual source blend:
+ */
+ bool dual_src_blend = false;
+ if (dual_src_blend && (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 + semantic_index;
+ }
+ break;
+ }
+ case TGSI_SEMANTIC_POSITION:
+ var->data.location = FRAG_RESULT_DEPTH;
+ break;
+ default:
+ fprintf(stderr, "Bad TGSI semantic: %d/%d\n",
+ decl->Semantic.Name, decl->Semantic.Index);
+ abort();
+ }
+ } else {
+ var->data.location =
+ tgsi_varying_semantic_to_slot(semantic_name, semantic_index);
+ }
if (is_array) {
unsigned j;
diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.h b/src/gallium/auxiliary/nir/tgsi_to_nir.h
index 687348a80ef..1a185a83219 100644
--- a/src/gallium/auxiliary/nir/tgsi_to_nir.h
+++ b/src/gallium/auxiliary/nir/tgsi_to_nir.h
@@ -28,3 +28,9 @@ struct nir_shader_compiler_options *options;
struct nir_shader *
tgsi_to_nir(const void *tgsi_tokens,
const struct nir_shader_compiler_options *options);
+void
+varying_slot_to_tgsi_semantic(gl_varying_slot slot,
+ unsigned *semantic_name, unsigned *semantic_index);
+void
+frag_result_to_tgsi_semantic(gl_frag_result slot,
+ unsigned *semantic_name, unsigned *semantic_index);