program: add a helper for rewriting FP position input to sysval
authorMarek Olšák <marek.olsak@amd.com>
Sat, 2 Jan 2016 22:08:27 +0000 (23:08 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 8 Jan 2016 19:06:23 +0000 (20:06 +0100)
Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/program/programopt.c
src/mesa/program/programopt.h

index af78150d5949cea8f6718e8b0ec3887fa70022cf..24dde57725e00f4f536fc2dfe2e2eef4673b3662 100644 (file)
@@ -589,3 +589,30 @@ _mesa_remove_output_reads(struct gl_program *prog, gl_register_file type)
       }
    }
 }
+
+void
+_mesa_program_fragment_position_to_sysval(struct gl_program *prog)
+{
+   GLuint i;
+
+   if (prog->Target != GL_FRAGMENT_PROGRAM_ARB ||
+       !(prog->InputsRead & BITFIELD64_BIT(VARYING_SLOT_POS)))
+      return;
+
+   prog->InputsRead &= ~BITFIELD64_BIT(VARYING_SLOT_POS);
+   prog->SystemValuesRead |= 1 << SYSTEM_VALUE_FRAG_COORD;
+
+   for (i = 0; i < prog->NumInstructions; i++) {
+      struct prog_instruction *inst = prog->Instructions + i;
+      const GLuint numSrc = _mesa_num_inst_src_regs(inst->Opcode);
+      GLuint j;
+
+      for (j = 0; j < numSrc; j++) {
+         if (inst->SrcReg[j].File == PROGRAM_INPUT &&
+             inst->SrcReg[j].Index == VARYING_SLOT_POS) {
+            inst->SrcReg[j].File = PROGRAM_SYSTEM_VALUE;
+            inst->SrcReg[j].Index = SYSTEM_VALUE_FRAG_COORD;
+         }
+      }
+   }
+}
index 757421edfe15f93f118d761a3a229634b3db5802..1520d161ea811c4773897cc3f7b6f23ae311167e 100644 (file)
@@ -51,6 +51,8 @@ _mesa_count_texture_instructions(struct gl_program *prog);
 extern void
 _mesa_remove_output_reads(struct gl_program *prog, gl_register_file type);
 
+extern void
+_mesa_program_fragment_position_to_sysval(struct gl_program *prog);
 
 #ifdef __cplusplus
 }