i965: Emit zero initialization for NV VP temporaries as required.
authorEric Anholt <eric@anholt.net>
Thu, 24 Sep 2009 18:58:33 +0000 (11:58 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 24 Sep 2009 20:34:06 +0000 (13:34 -0700)
This is similar to what r300 does inside the driver, but I've added it as
a generic option since it seems most hardware will want it.

Fixes piglit nv-init-zero-reg.vpfp and nv-init-zero-addr.vpfp.

src/mesa/drivers/dri/i965/brw_context.c
src/mesa/main/mtypes.h
src/mesa/shader/nvprogram.c
src/mesa/shader/nvprogram.h
src/mesa/shader/nvvertparse.c

index 3c5b84831974deb5ca9312e2f8ad40c527b13863..c300c33adce838f906ac2523c7854b2659a87cf8 100644 (file)
@@ -125,6 +125,7 @@ GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
 
    /* We want the GLSL compiler to emit code that uses condition codes */
    ctx->Shader.EmitCondCodes = GL_TRUE;
+   ctx->Shader.EmitNVTempInitialization = GL_TRUE;
 
    ctx->Const.VertexProgram.MaxNativeInstructions = (16 * 1024);
    ctx->Const.VertexProgram.MaxAluInstructions = 0;
index 6b64bf8139f49315db5a845a67442190a1c22d85..f8e4e41583d9e5f70e02ed02c78c1f1278746d5d 100644 (file)
@@ -2079,6 +2079,7 @@ struct gl_shader_state
    GLboolean EmitContReturn;            /**< Emit CONT/RET opcodes? */
    GLboolean EmitCondCodes;             /**< Use condition codes? */
    GLboolean EmitComments;              /**< Annotated instructions */
+   GLboolean EmitNVTempInitialization;  /**< 0-fill NV temp registers */
    void *MemPool;
    GLbitfield Flags;                    /**< Mask of GLSL_x flags */
    struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */
index fdb2f4210addf3734facc85d9446b66989b9f71a..471a7358a2f4bc3aa34c275ad4739281cc80624b 100644 (file)
@@ -509,7 +509,51 @@ _mesa_GetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid **pointer)
    *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
 }
 
+void
+_mesa_emit_nv_temp_initialization(GLcontext *ctx,
+                                 struct gl_program *program)
+{
+   struct prog_instruction *inst;
+   int i;
+
+   if (!ctx->Shader.EmitNVTempInitialization)
+      return;
 
+   /* We'll swizzle up a zero temporary so we can use it for the
+    * ARL.
+    */
+   if (program->NumTemporaries == 0)
+      program->NumTemporaries = 1;
+
+   _mesa_insert_instructions(program, 0, program->NumTemporaries + 1);
+
+   for (i = 0; i < program->NumTemporaries; i++) {
+      struct prog_instruction *inst = &program->Instructions[i];
+
+      inst->Opcode = OPCODE_SWZ;
+      inst->DstReg.File = PROGRAM_TEMPORARY;
+      inst->DstReg.Index = i;
+      inst->DstReg.WriteMask = WRITEMASK_XYZW;
+      inst->SrcReg[0].File = PROGRAM_TEMPORARY;
+      inst->SrcReg[0].Index = 0;
+      inst->SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_ZERO,
+                                             SWIZZLE_ZERO,
+                                             SWIZZLE_ZERO,
+                                             SWIZZLE_ZERO);
+   }
+
+   inst = &program->Instructions[i];
+   inst->Opcode = OPCODE_ARL;
+   inst->DstReg.File = PROGRAM_ADDRESS;
+   inst->DstReg.Index = 0;
+   inst->DstReg.WriteMask = WRITEMASK_XYZW;
+   inst->SrcReg[0].File = PROGRAM_TEMPORARY;
+   inst->SrcReg[0].Index = 0;
+   inst->SrcReg[0].Swizzle = SWIZZLE_XXXX;
+
+   if (program->NumAddressRegs == 0)
+      program->NumAddressRegs = 1;
+}
 
 void
 _mesa_setup_nv_temporary_count(GLcontext *ctx, struct gl_program *program)
index 0ed143d52f726cc0f81571c55b89043b1b991526..8ee59661bd0952aa3a9f8c25e3b934f45e871604 100644 (file)
@@ -106,4 +106,8 @@ _mesa_GetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte *name,
 extern void
 _mesa_setup_nv_temporary_count(GLcontext *ctx, struct gl_program *program);
 
+extern void
+_mesa_emit_nv_temp_initialization(GLcontext *ctx,
+                                 struct gl_program *program);
+
 #endif
index a94e6b8b80353aa57b7b89806ce40a2295c986a3..6ab8a14cb9b394408322df54b16c41801e0acc5a 100644 (file)
@@ -1423,6 +1423,7 @@ _mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum dstTarget,
       program->Base.NumParameters = program->Base.Parameters->NumParameters;
 
       _mesa_setup_nv_temporary_count(ctx, &program->Base);
+      _mesa_emit_nv_temp_initialization(ctx, &program->Base);
    }
    else {
       /* Error! */