svga: move some svga/tgsi functions
authorBrian Paul <brianp@vmware.com>
Wed, 19 Jun 2013 16:39:43 +0000 (10:39 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 19 Jun 2013 17:13:14 +0000 (11:13 -0600)
Move some functions from the svga_tgsi_insn.h header into the
svga_tgsi_insn.c file since they're only used there.  Plus, add
comments and fix formatting.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/drivers/svga/svga_tgsi_decl_sm30.c
src/gallium/drivers/svga/svga_tgsi_emit.h
src/gallium/drivers/svga/svga_tgsi_insn.c

index becd159b79f8271b71625b1ac55979a9f97a1903..7faa275f33ea350726f668832e64841292c10adf 100644 (file)
@@ -491,6 +491,26 @@ vs30_output(struct svga_shader_emitter *emit,
 }
 
 
+/** Translate PIPE_TEXTURE_x to SVGA3DSAMP_x */
+static ubyte
+svga_tgsi_sampler_type(const struct svga_shader_emitter *emit, int idx)
+{
+   switch (emit->key.fkey.tex[idx].texture_target) {
+   case PIPE_TEXTURE_1D:
+      return SVGA3DSAMP_2D;
+   case PIPE_TEXTURE_2D:
+   case PIPE_TEXTURE_RECT:
+      return SVGA3DSAMP_2D;
+   case PIPE_TEXTURE_3D:
+      return SVGA3DSAMP_VOLUME;
+   case PIPE_TEXTURE_CUBE:
+      return SVGA3DSAMP_CUBE;
+   }
+
+   return SVGA3DSAMP_UNKNOWN;
+}
+
+
 static boolean
 ps30_sampler( struct svga_shader_emitter *emit,
               struct tgsi_declaration_semantic semantic,
index 73c4cdabefcdde613b0e213d824cd5a1479e31ce..949c39dd3ee35aff86a0444a8e3254069366cccd 100644 (file)
@@ -146,30 +146,6 @@ boolean svga_translate_decl_sm30( struct svga_shader_emitter *emit,
                                const struct tgsi_full_declaration *decl );
 
 
-static INLINE boolean emit_dst( struct svga_shader_emitter *emit,
-                         SVGA3dShaderDestToken dest )
-{
-   assert(dest.reserved0);
-   assert(dest.mask);
-   return svga_shader_emit_dword( emit, dest.value );
-}
-
-static INLINE boolean emit_src( struct svga_shader_emitter *emit,
-                         const struct src_register src )
-{
-   if (src.base.relAddr) {
-      assert(src.base.reserved0);
-      assert(src.indirect.reserved0);
-      return (svga_shader_emit_dword( emit, src.base.value ) &&
-              svga_shader_emit_dword( emit, src.indirect.value ));
-   }
-   else {
-      assert(src.base.reserved0);
-      return svga_shader_emit_dword( emit, src.base.value );
-   }
-}
-
-
 static INLINE boolean emit_instruction( struct svga_shader_emitter *emit,
                                  SVGA3dShaderInstToken opcode )
 {
@@ -177,60 +153,6 @@ static INLINE boolean emit_instruction( struct svga_shader_emitter *emit,
 }
 
 
-static INLINE boolean emit_op1( struct svga_shader_emitter *emit,
-                         SVGA3dShaderInstToken inst,
-                         SVGA3dShaderDestToken dest,
-                         struct src_register src0 )
-{
-   return (emit_instruction( emit, inst ) &&
-           emit_dst( emit, dest ) &&
-           emit_src( emit, src0 ));
-}
-
-static INLINE boolean emit_op2( struct svga_shader_emitter *emit,
-                     SVGA3dShaderInstToken inst,
-                     SVGA3dShaderDestToken dest,
-                     struct src_register src0,
-                     struct src_register src1 )
-{
-   return (emit_instruction( emit, inst ) &&
-           emit_dst( emit, dest ) &&
-           emit_src( emit, src0 ) &&
-           emit_src( emit, src1 ));
-}
-
-static INLINE boolean emit_op3( struct svga_shader_emitter *emit,
-                         SVGA3dShaderInstToken inst,
-                         SVGA3dShaderDestToken dest,
-                         struct src_register src0,
-                         struct src_register src1,
-                         struct src_register src2 )
-{
-   return (emit_instruction( emit, inst ) &&
-           emit_dst( emit, dest ) &&
-           emit_src( emit, src0 ) &&
-           emit_src( emit, src1 ) &&
-           emit_src( emit, src2 ));
-}
-
-
-static INLINE boolean emit_op4( struct svga_shader_emitter *emit,
-                                SVGA3dShaderInstToken inst,
-                                SVGA3dShaderDestToken dest,
-                                struct src_register src0,
-                                struct src_register src1,
-                                struct src_register src2,
-                                struct src_register src3)
-{
-   return (emit_instruction( emit, inst ) &&
-           emit_dst( emit, dest ) &&
-           emit_src( emit, src0 ) &&
-           emit_src( emit, src1 ) &&
-           emit_src( emit, src2 ) &&
-           emit_src( emit, src3 ));
-}
-
-
 #define TRANSLATE_SWIZZLE(x,y,z,w)  ((x) | ((y) << 2) | ((z) << 4) | ((w) << 6))
 #define SWIZZLE_XYZW  \
  TRANSLATE_SWIZZLE(TGSI_SWIZZLE_X,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_W)
@@ -319,36 +241,6 @@ src_token( unsigned file, int number )
 }
 
 
-static INLINE struct src_register 
-absolute( struct src_register src )
-{
-   src.base.srcMod = SVGA3DSRCMOD_ABS;
-
-   return src;
-}
-
-
-static INLINE struct src_register 
-negate( struct src_register src )
-{
-   switch (src.base.srcMod) {
-   case SVGA3DSRCMOD_ABS:
-      src.base.srcMod = SVGA3DSRCMOD_ABSNEG;
-      break;
-   case SVGA3DSRCMOD_ABSNEG:
-      src.base.srcMod = SVGA3DSRCMOD_ABS;
-      break;
-   case SVGA3DSRCMOD_NEG:
-      src.base.srcMod = SVGA3DSRCMOD_NONE;
-      break;
-   case SVGA3DSRCMOD_NONE:
-      src.base.srcMod = SVGA3DSRCMOD_NEG;
-      break;
-   }
-   return src;
-}
-
-
 static INLINE struct src_register 
 src_register( unsigned file, int number )
 {
@@ -372,22 +264,5 @@ static INLINE struct src_register src( SVGA3dShaderDestToken dst )
                         dst.num );
 }
 
-static INLINE ubyte svga_tgsi_sampler_type( struct svga_shader_emitter *emit,
-                                            int idx )
-{
-   switch (emit->key.fkey.tex[idx].texture_target) {
-   case PIPE_TEXTURE_1D:
-      return SVGA3DSAMP_2D;
-   case PIPE_TEXTURE_2D:
-   case PIPE_TEXTURE_RECT:
-      return SVGA3DSAMP_2D;
-   case PIPE_TEXTURE_3D:
-      return SVGA3DSAMP_VOLUME;
-   case PIPE_TEXTURE_CUBE:
-      return SVGA3DSAMP_CUBE;
-   }
-
-   return SVGA3DSAMP_UNKNOWN;
-}
 
 #endif
index 1e0579d95e64bd68d5884b8d8970ded1780e79f1..92ee444a0db75d41f00c1a704ac3979e961ae88b 100644 (file)
@@ -292,6 +292,135 @@ reset_temp_regs(struct svga_shader_emitter *emit)
 }
 
 
+/** Emit bytecode for a src_register */
+static boolean
+emit_src(struct svga_shader_emitter *emit, const struct src_register src)
+{
+   if (src.base.relAddr) {
+      assert(src.base.reserved0);
+      assert(src.indirect.reserved0);
+      return (svga_shader_emit_dword( emit, src.base.value ) &&
+              svga_shader_emit_dword( emit, src.indirect.value ));
+   }
+   else {
+      assert(src.base.reserved0);
+      return svga_shader_emit_dword( emit, src.base.value );
+   }
+}
+
+
+/** Emit bytecode for a dst_register */
+static boolean
+emit_dst(struct svga_shader_emitter *emit, SVGA3dShaderDestToken dest)
+{
+   assert(dest.reserved0);
+   assert(dest.mask);
+   return svga_shader_emit_dword( emit, dest.value );
+}
+
+
+/** Emit bytecode for a 1-operand instruction */
+static boolean
+emit_op1(struct svga_shader_emitter *emit,
+         SVGA3dShaderInstToken inst,
+         SVGA3dShaderDestToken dest,
+         struct src_register src0)
+{
+   return (emit_instruction(emit, inst) &&
+           emit_dst(emit, dest) &&
+           emit_src(emit, src0));
+}
+
+
+/** Emit bytecode for a 2-operand instruction */
+static boolean
+emit_op2(struct svga_shader_emitter *emit,
+         SVGA3dShaderInstToken inst,
+         SVGA3dShaderDestToken dest,
+         struct src_register src0,
+         struct src_register src1)
+{
+   return (emit_instruction(emit, inst) &&
+           emit_dst(emit, dest) &&
+           emit_src(emit, src0) &&
+           emit_src(emit, src1));
+}
+
+
+/** Emit bytecode for a 3-operand instruction */
+static boolean
+emit_op3(struct svga_shader_emitter *emit,
+         SVGA3dShaderInstToken inst,
+         SVGA3dShaderDestToken dest,
+         struct src_register src0,
+         struct src_register src1,
+         struct src_register src2)
+{
+   return (emit_instruction(emit, inst) &&
+           emit_dst(emit, dest) &&
+           emit_src(emit, src0) &&
+           emit_src(emit, src1) &&
+           emit_src(emit, src2));
+}
+
+
+/** Emit bytecode for a 4-operand instruction */
+static boolean
+emit_op4(struct svga_shader_emitter *emit,
+         SVGA3dShaderInstToken inst,
+         SVGA3dShaderDestToken dest,
+         struct src_register src0,
+         struct src_register src1,
+         struct src_register src2,
+         struct src_register src3)
+{
+   return (emit_instruction(emit, inst) &&
+           emit_dst(emit, dest) &&
+           emit_src(emit, src0) &&
+           emit_src(emit, src1) &&
+           emit_src(emit, src2) &&
+           emit_src(emit, src3));
+}
+
+
+/**
+ * Apply the absolute value modifier to the given src_register, returning
+ * a new src_register.
+ */
+static struct src_register 
+absolute(struct src_register src)
+{
+   src.base.srcMod = SVGA3DSRCMOD_ABS;
+   return src;
+}
+
+
+/**
+ * Apply the negation modifier to the given src_register, returning
+ * a new src_register.
+ */
+static struct src_register 
+negate(struct src_register src)
+{
+   switch (src.base.srcMod) {
+   case SVGA3DSRCMOD_ABS:
+      src.base.srcMod = SVGA3DSRCMOD_ABSNEG;
+      break;
+   case SVGA3DSRCMOD_ABSNEG:
+      src.base.srcMod = SVGA3DSRCMOD_ABS;
+      break;
+   case SVGA3DSRCMOD_NEG:
+      src.base.srcMod = SVGA3DSRCMOD_NONE;
+      break;
+   case SVGA3DSRCMOD_NONE:
+      src.base.srcMod = SVGA3DSRCMOD_NEG;
+      break;
+   }
+   return src;
+}
+
+
+
 /* Replace the src with the temporary specified in the dst, but copying
  * only the necessary channels, and preserving the original swizzle (which is
  * important given that several opcodes have constraints in the allowed