gallium: Redefine the max texture 2d cap from _LEVELS to _SIZE.
[mesa.git] / src / gallium / drivers / i915 / i915_fpc.h
index 2f0f99d0468fcc7a57499f1e0a57757b43808bed..309cf8e67f92abd00cd5858e1250ddd6576b1163 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2003 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "i915_context.h"
 #include "i915_reg.h"
 
+#include "pipe/p_shader_tokens.h"
 
+#include "tgsi/tgsi_parse.h"
 
 #define I915_PROGRAM_SIZE 192
 
+/* Use those indices for pos/face routing, must be >= num of inputs */
+#define I915_SEMANTIC_POS  100
+#define I915_SEMANTIC_FACE 101
 
 
 /**
@@ -67,13 +72,13 @@ struct i915_fp_compile {
    uint temp_flag;       /**< Tracks temporary regs which are in use */
    uint utemp_flag;      /**< Tracks TYPE_U temporary regs which are in use */
 
+   uint register_phases[I915_MAX_TEMPORARY];
    uint nr_tex_indirect;
    uint nr_tex_insn;
    uint nr_alu_insn;
    uint nr_decl_insn;
 
    boolean error;      /**< Set if i915_program_error() is called */
-   uint wpos_tex;
    uint NumNativeInstructions;
    uint NumNativeAluInstructions;
    uint NumNativeTexInstructions;
@@ -131,7 +136,7 @@ struct i915_fp_compile {
 
 /* One neat thing about the UREG representation:  
  */
-static INLINE int
+static inline int
 swizzle(int reg, uint x, uint y, uint z, uint w)
 {
    assert(x <= SRC_ONE);
@@ -146,6 +151,38 @@ swizzle(int reg, uint x, uint y, uint z, uint w)
 }
 
 
+#define A0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT)
+#define D0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT)
+#define T0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT)
+#define A0_SRC0( reg ) (((reg)&UREG_MASK)>>UREG_A0_SRC0_SHIFT_LEFT)
+#define A1_SRC0( reg ) (((reg)&UREG_MASK)<<UREG_A1_SRC0_SHIFT_RIGHT)
+#define A1_SRC1( reg ) (((reg)&UREG_MASK)>>UREG_A1_SRC1_SHIFT_LEFT)
+#define A2_SRC1( reg ) (((reg)&UREG_MASK)<<UREG_A2_SRC1_SHIFT_RIGHT)
+#define A2_SRC2( reg ) (((reg)&UREG_MASK)>>UREG_A2_SRC2_SHIFT_LEFT)
+
+/* These are special, and don't have swizzle/negate bits.
+ */
+#define T0_SAMPLER( reg )     (GET_UREG_NR(reg)<<T0_SAMPLER_NR_SHIFT)
+#define T1_ADDRESS_REG( reg ) ((GET_UREG_NR(reg)<<T1_ADDRESS_REG_NR_SHIFT) | \
+                              (GET_UREG_TYPE(reg)<<T1_ADDRESS_REG_TYPE_SHIFT))
+
+
+/* Macros for translating UREG's into the various register fields used
+ * by the I915 programmable unit.
+ */
+#define UREG_A0_DEST_SHIFT_LEFT  (UREG_TYPE_SHIFT - A0_DEST_TYPE_SHIFT)
+#define UREG_A0_SRC0_SHIFT_LEFT  (UREG_TYPE_SHIFT - A0_SRC0_TYPE_SHIFT)
+#define UREG_A1_SRC0_SHIFT_RIGHT (A1_SRC0_CHANNEL_W_SHIFT - UREG_CHANNEL_W_SHIFT)
+#define UREG_A1_SRC1_SHIFT_LEFT  (UREG_TYPE_SHIFT - A1_SRC1_TYPE_SHIFT)
+#define UREG_A2_SRC1_SHIFT_RIGHT (A2_SRC1_CHANNEL_W_SHIFT - UREG_CHANNEL_W_SHIFT)
+#define UREG_A2_SRC2_SHIFT_LEFT  (UREG_TYPE_SHIFT - A2_SRC2_TYPE_SHIFT)
+
+#define UREG_MASK         0xffffff00
+#define UREG_TYPE_NR_MASK ((REG_TYPE_MASK << UREG_TYPE_SHIFT) | \
+                          (REG_NR_MASK << UREG_NR_SHIFT))
+
+
+
 
 /***********************************************************************
  * Public interface for the compiler
@@ -164,7 +201,10 @@ extern void i915_release_utemps(struct i915_fp_compile *p);
 extern uint i915_emit_texld(struct i915_fp_compile *p,
                               uint dest,
                               uint destmask,
-                              uint sampler, uint coord, uint op);
+                              uint sampler,
+                              uint coord,
+                              uint op,
+                              uint num_coord);
 
 extern uint i915_emit_arith(struct i915_fp_compile *p,
                               uint op,
@@ -191,17 +231,98 @@ extern uint i915_emit_const4f(struct i915_fp_compile *p,
 
 
 /*======================================================================
- * i915_fpc_debug.c
+ * i915_fpc_translate.c
  */
-extern void i915_disassemble_program(const uint * program, uint sz);
+
+extern void
+i915_program_error(struct i915_fp_compile *p, const char *msg, ...);
 
 
 /*======================================================================
- * i915_fpc_translate.c
+ * i915_fpc_optimize.c
  */
 
-extern void
-i915_program_error(struct i915_fp_compile *p, const char *msg, ...);
 
+struct i915_src_register
+{
+   unsigned File        : 4;  /* TGSI_FILE_ */
+   unsigned Indirect    : 1;  /* BOOL */
+   unsigned Dimension   : 1;  /* BOOL */
+   int      Index       : 16; /* SINT */
+   unsigned SwizzleX    : 3;  /* TGSI_SWIZZLE_ */
+   unsigned SwizzleY    : 3;  /* TGSI_SWIZZLE_ */
+   unsigned SwizzleZ    : 3;  /* TGSI_SWIZZLE_ */
+   unsigned SwizzleW    : 3;  /* TGSI_SWIZZLE_ */
+   unsigned Absolute    : 1;    /* BOOL */
+   unsigned Negate      : 1;    /* BOOL */
+};
+
+/* Additional swizzle supported in i915 */
+#define TGSI_SWIZZLE_ZERO 4
+#define TGSI_SWIZZLE_ONE 5
+
+struct i915_dst_register
+{
+   unsigned File        : 4;  /* TGSI_FILE_ */
+   unsigned WriteMask   : 4;  /* TGSI_WRITEMASK_ */
+   unsigned Indirect    : 1;  /* BOOL */
+   unsigned Dimension   : 1;  /* BOOL */
+   int      Index       : 16; /* SINT */
+   unsigned Padding     : 6;
+};
+
+
+struct i915_full_dst_register
+{
+   struct i915_dst_register               Register;
+/*
+   struct tgsi_ind_register               Indirect;
+   struct tgsi_dimension                  Dimension;
+   struct tgsi_ind_register               DimIndirect;
+*/
+};
+
+struct i915_full_src_register
+{
+   struct i915_src_register         Register;
+/*
+   struct tgsi_ind_register         Indirect;
+   struct tgsi_dimension            Dimension;
+   struct tgsi_ind_register         DimIndirect;
+*/
+};
+
+struct i915_full_instruction
+{
+   struct tgsi_instruction             Instruction;
+/*
+   struct tgsi_instruction_label       Label;
+*/
+   struct tgsi_instruction_texture     Texture;
+   struct i915_full_dst_register       Dst[1];
+   struct i915_full_src_register       Src[3];
+};
+
+
+union i915_full_token
+{
+   struct tgsi_token             Token;
+   struct tgsi_full_declaration  FullDeclaration;
+   struct tgsi_full_immediate    FullImmediate;
+   struct i915_full_instruction  FullInstruction;
+   struct tgsi_full_property     FullProperty;
+};
+
+struct i915_token_list
+{
+   union i915_full_token*     Tokens;
+   unsigned                   NumTokens;
+};
+
+extern struct i915_token_list* i915_optimize(const struct tgsi_token *tokens);
+
+extern void i915_optimize_free(struct i915_token_list *tokens);
+
+extern uint i915_num_coords(uint tex);
 
 #endif