summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/programopt.c
diff options
context:
space:
mode:
authorZack Rusin <[email protected]>2008-06-12 18:53:52 -0400
committerZack Rusin <[email protected]>2008-06-12 19:39:20 -0400
commit928ec5cd3be5c7d6f3d9df0ace18371b1ec8c68c (patch)
tree76d9d016980c2336a51818285b0248e91063b8c6 /src/mesa/shader/programopt.c
parent53f5b9741a5453f9166aee8da6e1f8bf5b10d59e (diff)
glsl: make sure we replace all output reads with temporaries
test in if.glsl
Diffstat (limited to 'src/mesa/shader/programopt.c')
-rw-r--r--src/mesa/shader/programopt.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c
index 7d560c74a54..da4e3fcfcfc 100644
--- a/src/mesa/shader/programopt.c
+++ b/src/mesa/shader/programopt.c
@@ -367,20 +367,22 @@ _mesa_count_texture_instructions(struct gl_program *prog)
/**
- * Scan/rewrite program to remove reads of varying (output) registers.
+ * Scan/rewrite program to remove reads of custom (output) registers.
+ * The passed type has to be either PROGRAM_VARYING or PROGRAM_OUTPUT.
* In GLSL vertex shaders, varying vars can be read and written.
* Normally, vertex varying vars are implemented as output registers.
* On some hardware, trying to read an output register causes trouble.
* So, rewrite the program to use a temporary register in this case.
*/
void
-_mesa_remove_varying_reads(struct gl_program *prog)
+_mesa_remove_output_reads(struct gl_program *prog, enum register_file type)
{
GLuint i;
GLint outputMap[VERT_RESULT_MAX];
GLuint numVaryingReads = 0;
assert(prog->Target == GL_VERTEX_PROGRAM_ARB);
+ assert(type == PROGRAM_UNIFORM || type == PROGRAM_OUTPUT);
for (i = 0; i < VERT_RESULT_MAX; i++)
outputMap[i] = -1;
@@ -391,7 +393,7 @@ _mesa_remove_varying_reads(struct gl_program *prog)
const GLuint numSrc = _mesa_num_inst_src_regs(inst->Opcode);
GLuint j;
for (j = 0; j < numSrc; j++) {
- if (inst->SrcReg[j].File == PROGRAM_VARYING) {
+ if (inst->SrcReg[j].File == type) {
/* replace the read with a temp reg */
const GLuint var = inst->SrcReg[j].Index;
if (outputMap[var] == -1) {
@@ -414,7 +416,7 @@ _mesa_remove_varying_reads(struct gl_program *prog)
const GLuint numSrc = _mesa_num_inst_src_regs(inst->Opcode);
GLuint j;
for (j = 0; j < numSrc; j++) {
- if (inst->DstReg.File == PROGRAM_VARYING &&
+ if (inst->DstReg.File == type &&
outputMap[inst->DstReg.Index] >= 0) {
/* change inst to write to the temp reg, instead of the varying */
inst->DstReg.File = PROGRAM_TEMPORARY;
@@ -447,7 +449,7 @@ _mesa_remove_varying_reads(struct gl_program *prog)
if (outputMap[var] >= 0) {
/* MOV VAR[var], TEMP[tmp]; */
inst->Opcode = OPCODE_MOV;
- inst->DstReg.File = PROGRAM_VARYING;
+ inst->DstReg.File = type;
inst->DstReg.Index = var;
inst->SrcReg[0].File = PROGRAM_TEMPORARY;
inst->SrcReg[0].Index = outputMap[var];