From e785f190f0d49f0367f7468c22b77962d0f14ea0 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 14 Dec 2007 11:00:46 -0700 Subject: Don't always declare frag shader INPUT[0] as fragment position. We were doing this for the sake of softpipe and the tgsi intergrepter since we always need the fragment position and W-coordinate information in order to compute fragment interpolants. But that's not appropriate for hardware drivers. The tgsi interpreter now get x,y,w information from a separate tgsi_exec_vector variable setup by softpipe. The new pipe_shader_state->input_map[] defines how vert shader outputs map to frag shader inputs. It may go away though, since one can also examine the semantic label on frag shader input[0] to figure things out. --- src/mesa/state_tracker/st_atom_shader.c | 25 ++++++++++++----- src/mesa/state_tracker/st_mesa_to_tgsi.c | 46 +++++++++----------------------- src/mesa/state_tracker/st_program.c | 25 +++++++++-------- 3 files changed, 45 insertions(+), 51 deletions(-) (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 4ec10badad..33372b0f39 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -151,8 +151,7 @@ find_translated_vp(struct st_context *st, { static const GLuint UNUSED = ~0; struct translated_vertex_program *xvp; - const GLbitfield fragInputsRead - = stfp->Base.Base.InputsRead | FRAG_BIT_WPOS; + const GLbitfield fragInputsRead = stfp->Base.Base.InputsRead; /* * Translate fragment program if needed. @@ -206,6 +205,7 @@ find_translated_vp(struct st_context *st, if (xvp->serialNo != stvp->serialNo) { GLuint outAttr, dummySlot; const GLbitfield outputsWritten = stvp->Base.Base.OutputsWritten; + GLuint numVpOuts = 0; /* Compute mapping of vertex program outputs to slots, which depends * on the fragment program's input->slot mapping. @@ -214,11 +214,24 @@ find_translated_vp(struct st_context *st, /* set default: */ xvp->output_to_slot[outAttr] = UNUSED; - if (outputsWritten & (1 << outAttr)) { + if (outAttr == VERT_RESULT_HPOS) { + /* always put xformed position into slot zero */ + xvp->output_to_slot[VERT_RESULT_HPOS] = 0; + numVpOuts++; + } + else if (outputsWritten & (1 << outAttr)) { /* see if the frag prog wants this vert output */ - GLint fpIn = vp_out_to_fp_in(outAttr); - if (fpIn >= 0) { - xvp->output_to_slot[outAttr] = stfp->input_to_slot[fpIn]; + GLint fpInAttrib = vp_out_to_fp_in(outAttr); + if (fpInAttrib >= 0) { + GLuint fpInSlot = stfp->input_to_slot[fpInAttrib]; + GLuint vpOutSlot = stfp->fs->state.input_map[fpInSlot]; + xvp->output_to_slot[outAttr] = vpOutSlot; + numVpOuts++; + } + else if (outAttr == VERT_RESULT_BFC0 || + outAttr == VERT_RESULT_BFC1) { + /* backface colors go into last slots */ + xvp->output_to_slot[outAttr] = numVpOuts++; } } } diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index b392edf16d..27dab5b9c0 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -675,44 +675,22 @@ tgsi_translate_mesa_program( if (procType == TGSI_PROCESSOR_FRAGMENT) { for (i = 0; i < numInputs; i++) { struct tgsi_full_declaration fulldecl; - switch (inputSemanticName[i]) { - case TGSI_SEMANTIC_POSITION: - /* Fragment XY pos */ - fulldecl = make_input_decl(i, - GL_TRUE, TGSI_INTERPOLATE_CONSTANT, - TGSI_WRITEMASK_XY, - GL_TRUE, TGSI_SEMANTIC_POSITION, 0 ); - ti += tgsi_build_full_declaration( - &fulldecl, - &tokens[ti], - header, - maxTokens - ti ); - /* Fragment ZW pos */ - fulldecl = make_input_decl(i, - GL_TRUE, TGSI_INTERPOLATE_LINEAR, - TGSI_WRITEMASK_ZW, - GL_TRUE, TGSI_SEMANTIC_POSITION, 0 ); - ti += tgsi_build_full_declaration(&fulldecl, - &tokens[ti], - header, - maxTokens - ti ); - break; - default: - fulldecl = make_input_decl(i, - GL_TRUE, interpMode[i], - TGSI_WRITEMASK_XYZW, - GL_TRUE, inputSemanticName[i], - inputSemanticIndex[i]); - ti += tgsi_build_full_declaration(&fulldecl, - &tokens[ti], - header, - maxTokens - ti ); - break; - } + fulldecl = make_input_decl(i, + GL_TRUE, interpMode[i], + TGSI_WRITEMASK_XYZW, + GL_TRUE, inputSemanticName[i], + inputSemanticIndex[i]); + ti += tgsi_build_full_declaration(&fulldecl, + &tokens[ti], + header, + maxTokens - ti ); } } else { /* vertex prog */ + /* XXX: this could probaby be merged with the clause above. + * the only difference is the semantic tags. + */ for (i = 0; i < numInputs; i++) { struct tgsi_full_declaration fulldecl; fulldecl = make_input_decl(i, diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index e64bf14d56..fe22233c93 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -47,7 +47,7 @@ #include "st_mesa_to_tgsi.h" -#define TGSI_DEBUG 0 +#define TGSI_DEBUG 01 /** @@ -283,16 +283,17 @@ st_translate_fragment_program(struct st_context *st, const struct cso_fragment_shader *cso; GLuint interpMode[16]; /* XXX size? */ GLuint attr; - GLbitfield inputsRead = stfp->Base.Base.InputsRead; - - /* For software rendering, we always need the fragment input position - * in order to calculate interpolated values. - * For i915, we always want to emit the semantic info for position. - */ - inputsRead |= FRAG_BIT_WPOS; + const GLbitfield inputsRead = stfp->Base.Base.InputsRead; + GLuint vslot = 0; memset(&fs, 0, sizeof(fs)); + /* which vertex output goes to the first fragment input: */ + if (inputsRead & FRAG_BIT_WPOS) + vslot = 0; + else + vslot = 1; + /* * Convert Mesa program inputs to TGSI input register semantics. */ @@ -300,15 +301,17 @@ st_translate_fragment_program(struct st_context *st, if (inputsRead & (1 << attr)) { const GLuint slot = fs.num_inputs; - fs.num_inputs++; - defaultInputMapping[attr] = slot; + fs.input_map[slot] = vslot++; + + fs.num_inputs++; + switch (attr) { case FRAG_ATTRIB_WPOS: fs.input_semantic_name[slot] = TGSI_SEMANTIC_POSITION; fs.input_semantic_index[slot] = 0; - interpMode[slot] = TGSI_INTERPOLATE_CONSTANT; + interpMode[slot] = TGSI_INTERPOLATE_LINEAR; break; case FRAG_ATTRIB_COL0: fs.input_semantic_name[slot] = TGSI_SEMANTIC_COLOR; -- cgit v1.2.3