16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**************************************************************************
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved.
56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the
86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including
96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions:
136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the
156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software.
176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/
276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#ifndef I915_PROGRAM_H
306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define I915_PROGRAM_H
316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i915_context.h"
336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i915_reg.h"
346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Having zero and one in here makes the definition of swizzle a lot
386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * easier.
396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_TYPE_SHIFT               29
416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_NR_SHIFT                 24
426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_X_NEGATE_SHIFT   23
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_X_SHIFT          20
446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_Y_NEGATE_SHIFT   19
456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_Y_SHIFT          16
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_Z_NEGATE_SHIFT   15
476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_Z_SHIFT          12
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_W_NEGATE_SHIFT   11
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_W_SHIFT          8
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_ZERO_NEGATE_MBZ  5
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_ZERO_SHIFT       4
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_ONE_NEGATE_MBZ   1
536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_CHANNEL_ONE_SHIFT        0
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_BAD          0xffffffff    /* not a valid ureg */
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define X    SRC_X
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define Y    SRC_Y
596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define Z    SRC_Z
606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define W    SRC_W
616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define ZERO SRC_ZERO
626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define ONE  SRC_ONE
636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Construct a ureg:
656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) |		\
676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			  ((nr)  << UREG_NR_SHIFT) |		\
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			  (X     << UREG_CHANNEL_X_SHIFT) |	\
696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			  (Y     << UREG_CHANNEL_Y_SHIFT) |	\
706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			  (Z     << UREG_CHANNEL_Z_SHIFT) |	\
716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			  (W     << UREG_CHANNEL_W_SHIFT) |	\
726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			  (ZERO  << UREG_CHANNEL_ZERO_SHIFT) |	\
736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			  (ONE   << UREG_CHANNEL_ONE_SHIFT))
746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define CHANNEL_SRC( src, channel ) (src>>(channel*4))
776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)&REG_TYPE_MASK)
796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define GET_UREG_NR(reg)   (((reg)>>UREG_NR_SHIFT)&REG_NR_MASK)
806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UREG_XYZW_CHANNEL_MASK 0x00ffff00
846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* One neat thing about the UREG representation:
866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE int
886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellswizzle(int reg, int x, int y, int z, int w)
896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return ((reg & ~UREG_XYZW_CHANNEL_MASK) |
916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           CHANNEL_SRC(GET_CHANNEL_SRC(reg, x), 0) |
926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           CHANNEL_SRC(GET_CHANNEL_SRC(reg, y), 1) |
936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           CHANNEL_SRC(GET_CHANNEL_SRC(reg, z), 2) |
946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           CHANNEL_SRC(GET_CHANNEL_SRC(reg, w), 3));
956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Another neat thing about the UREG representation:
986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE int
1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellnegate(int reg, int x, int y, int z, int w)
1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return reg ^ (((x & 1) << UREG_CHANNEL_X_NEGATE_SHIFT) |
1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                 ((y & 1) << UREG_CHANNEL_Y_NEGATE_SHIFT) |
1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                 ((z & 1) << UREG_CHANNEL_Z_NEGATE_SHIFT) |
1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                 ((w & 1) << UREG_CHANNEL_W_NEGATE_SHIFT));
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_get_temp(struct i915_fragment_program *p);
1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_get_utemp(struct i915_fragment_program *p);
1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern void i915_release_utemps(struct i915_fragment_program *p);
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_emit_texld(struct i915_fragment_program *p,
1153369cd9a6f943365242d7832e69788d4aede9a8fXiang, Haihao                              GLuint live_regs,
1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              GLuint dest,
1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              GLuint destmask,
1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              GLuint sampler, GLuint coord, GLuint op);
1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_emit_arith(struct i915_fragment_program *p,
1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              GLuint op,
1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              GLuint dest,
1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              GLuint mask,
1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              GLuint saturate,
1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              GLuint src0, GLuint src1, GLuint src2);
1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_emit_decl(struct i915_fragment_program *p,
1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                             GLuint type, GLuint nr, GLuint d0_flags);
1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_emit_const1f(struct i915_fragment_program *p, GLfloat c0);
1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_emit_const2f(struct i915_fragment_program *p,
1346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                GLfloat c0, GLfloat c1);
1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_emit_const4fv(struct i915_fragment_program *p,
1376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 const GLfloat * c);
1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_emit_const4f(struct i915_fragment_program *p,
1406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                GLfloat c0, GLfloat c1,
1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                GLfloat c2, GLfloat c3);
1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern GLuint i915_emit_param4fv(struct i915_fragment_program *p,
1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 const GLfloat * values);
1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern void i915_program_error(struct i915_fragment_program *p,
148994d1db079b4947e6f10ab22a4b366a676382345Eric Anholt                               const char *fmt, ...);
1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern void i915_init_program(struct i915_context *i915,
1516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                              struct i915_fragment_program *p);
1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern void i915_upload_program(struct i915_context *i915,
1546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                struct i915_fragment_program *p);
1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellextern void i915_fini_program(struct i915_fragment_program *p);
1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
158f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergextern void i915_update_program(struct gl_context *ctx);
1596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
161