summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/tgsi/tgsi_exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/tgsi/tgsi_exec.c')
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_exec.c305
1 files changed, 148 insertions, 157 deletions
diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 2bcb33392a..262422364b 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -264,6 +264,12 @@ static void
micro_rcp(union tgsi_exec_channel *dst,
const union tgsi_exec_channel *src)
{
+#if 0 /* for debugging */
+ assert(src->f[0] != 0.0f);
+ assert(src->f[1] != 0.0f);
+ assert(src->f[2] != 0.0f);
+ assert(src->f[3] != 0.0f);
+#endif
dst->f[0] = 1.0f / src->f[0];
dst->f[1] = 1.0f / src->f[1];
dst->f[2] = 1.0f / src->f[2];
@@ -284,6 +290,12 @@ static void
micro_rsq(union tgsi_exec_channel *dst,
const union tgsi_exec_channel *src)
{
+#if 0 /* for debugging */
+ assert(src->f[0] != 0.0f);
+ assert(src->f[1] != 0.0f);
+ assert(src->f[2] != 0.0f);
+ assert(src->f[3] != 0.0f);
+#endif
dst->f[0] = 1.0f / sqrtf(fabsf(src->f[0]));
dst->f[1] = 1.0f / sqrtf(fabsf(src->f[1]));
dst->f[2] = 1.0f / sqrtf(fabsf(src->f[2]));
@@ -450,12 +462,20 @@ static const union tgsi_exec_channel ZeroVec =
{ { 0.0, 0.0, 0.0, 0.0 } };
-#define CHECK_INF_OR_NAN(chan) do {\
- assert(!util_is_inf_or_nan((chan)->f[0]));\
- assert(!util_is_inf_or_nan((chan)->f[1]));\
- assert(!util_is_inf_or_nan((chan)->f[2]));\
- assert(!util_is_inf_or_nan((chan)->f[3]));\
- } while (0)
+/**
+ * Assert that none of the float values in 'chan' are infinite or NaN.
+ * NaN and Inf may occur normally during program execution and should
+ * not lead to crashes, etc. But when debugging, it's helpful to catch
+ * them.
+ */
+static INLINE void
+check_inf_or_nan(const union tgsi_exec_channel *chan)
+{
+ assert(!util_is_inf_or_nan((chan)->f[0]));
+ assert(!util_is_inf_or_nan((chan)->f[1]));
+ assert(!util_is_inf_or_nan((chan)->f[2]));
+ assert(!util_is_inf_or_nan((chan)->f[3]));
+}
#ifdef DEBUG
@@ -953,99 +973,90 @@ micro_sub(
}
static void
-fetch_src_file_channel(
- const struct tgsi_exec_machine *mach,
- const uint file,
- const uint swizzle,
- const union tgsi_exec_channel *index,
- union tgsi_exec_channel *chan )
-{
- switch( swizzle ) {
- case TGSI_SWIZZLE_X:
- case TGSI_SWIZZLE_Y:
- case TGSI_SWIZZLE_Z:
- case TGSI_SWIZZLE_W:
- switch( file ) {
- case TGSI_FILE_CONSTANT:
- assert(mach->Consts);
- if (index->i[0] < 0)
- chan->f[0] = 0.0f;
- else
- chan->f[0] = mach->Consts[index->i[0]][swizzle];
- if (index->i[1] < 0)
- chan->f[1] = 0.0f;
- else
- chan->f[1] = mach->Consts[index->i[1]][swizzle];
- if (index->i[2] < 0)
- chan->f[2] = 0.0f;
- else
- chan->f[2] = mach->Consts[index->i[2]][swizzle];
- if (index->i[3] < 0)
- chan->f[3] = 0.0f;
- else
- chan->f[3] = mach->Consts[index->i[3]][swizzle];
- break;
+fetch_src_file_channel(const struct tgsi_exec_machine *mach,
+ const uint file,
+ const uint swizzle,
+ const union tgsi_exec_channel *index,
+ const union tgsi_exec_channel *index2D,
+ union tgsi_exec_channel *chan)
+{
+ uint i;
- case TGSI_FILE_INPUT:
- case TGSI_FILE_SYSTEM_VALUE:
- chan->u[0] = mach->Inputs[index->i[0]].xyzw[swizzle].u[0];
- chan->u[1] = mach->Inputs[index->i[1]].xyzw[swizzle].u[1];
- chan->u[2] = mach->Inputs[index->i[2]].xyzw[swizzle].u[2];
- chan->u[3] = mach->Inputs[index->i[3]].xyzw[swizzle].u[3];
- break;
+ switch (file) {
+ case TGSI_FILE_CONSTANT:
+ for (i = 0; i < QUAD_SIZE; i++) {
+ assert(index2D->i[i] >= 0 && index2D->i[i] < PIPE_MAX_CONSTANT_BUFFERS);
+ assert(mach->Consts[index2D->i[i]]);
- case TGSI_FILE_TEMPORARY:
- assert(index->i[0] < TGSI_EXEC_NUM_TEMPS);
- chan->u[0] = mach->Temps[index->i[0]].xyzw[swizzle].u[0];
- chan->u[1] = mach->Temps[index->i[1]].xyzw[swizzle].u[1];
- chan->u[2] = mach->Temps[index->i[2]].xyzw[swizzle].u[2];
- chan->u[3] = mach->Temps[index->i[3]].xyzw[swizzle].u[3];
- break;
+ if (index->i[i] < 0) {
+ chan->u[i] = 0;
+ } else {
+ const uint *p = (const uint *)mach->Consts[index2D->i[i]];
- case TGSI_FILE_IMMEDIATE:
- assert( index->i[0] < (int) mach->ImmLimit );
- chan->f[0] = mach->Imms[index->i[0]][swizzle];
- assert( index->i[1] < (int) mach->ImmLimit );
- chan->f[1] = mach->Imms[index->i[1]][swizzle];
- assert( index->i[2] < (int) mach->ImmLimit );
- chan->f[2] = mach->Imms[index->i[2]][swizzle];
- assert( index->i[3] < (int) mach->ImmLimit );
- chan->f[3] = mach->Imms[index->i[3]][swizzle];
- break;
+ chan->u[i] = p[index->i[i] * 4 + swizzle];
+ }
+ }
+ break;
- case TGSI_FILE_ADDRESS:
- chan->u[0] = mach->Addrs[index->i[0]].xyzw[swizzle].u[0];
- chan->u[1] = mach->Addrs[index->i[1]].xyzw[swizzle].u[1];
- chan->u[2] = mach->Addrs[index->i[2]].xyzw[swizzle].u[2];
- chan->u[3] = mach->Addrs[index->i[3]].xyzw[swizzle].u[3];
- break;
+ case TGSI_FILE_INPUT:
+ case TGSI_FILE_SYSTEM_VALUE:
+ for (i = 0; i < QUAD_SIZE; i++) {
+ /* XXX: 2D indexing */
+ chan->u[i] = mach->Inputs[index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i]].xyzw[swizzle].u[i];
+ }
+ break;
- case TGSI_FILE_PREDICATE:
- assert(index->i[0] < TGSI_EXEC_NUM_PREDS);
- assert(index->i[1] < TGSI_EXEC_NUM_PREDS);
- assert(index->i[2] < TGSI_EXEC_NUM_PREDS);
- assert(index->i[3] < TGSI_EXEC_NUM_PREDS);
- chan->u[0] = mach->Predicates[0].xyzw[swizzle].u[0];
- chan->u[1] = mach->Predicates[0].xyzw[swizzle].u[1];
- chan->u[2] = mach->Predicates[0].xyzw[swizzle].u[2];
- chan->u[3] = mach->Predicates[0].xyzw[swizzle].u[3];
- break;
+ case TGSI_FILE_TEMPORARY:
+ for (i = 0; i < QUAD_SIZE; i++) {
+ assert(index->i[i] < TGSI_EXEC_NUM_TEMPS);
+ assert(index2D->i[i] == 0);
- case TGSI_FILE_OUTPUT:
- /* vertex/fragment output vars can be read too */
- chan->u[0] = mach->Outputs[index->i[0]].xyzw[swizzle].u[0];
- chan->u[1] = mach->Outputs[index->i[1]].xyzw[swizzle].u[1];
- chan->u[2] = mach->Outputs[index->i[2]].xyzw[swizzle].u[2];
- chan->u[3] = mach->Outputs[index->i[3]].xyzw[swizzle].u[3];
- break;
+ chan->u[i] = mach->Temps[index->i[i]].xyzw[swizzle].u[i];
+ }
+ break;
- default:
- assert( 0 );
+ case TGSI_FILE_IMMEDIATE:
+ for (i = 0; i < QUAD_SIZE; i++) {
+ assert(index->i[i] >= 0 && index->i[i] < (int)mach->ImmLimit);
+ assert(index2D->i[i] == 0);
+
+ chan->f[i] = mach->Imms[index->i[i]][swizzle];
+ }
+ break;
+
+ case TGSI_FILE_ADDRESS:
+ for (i = 0; i < QUAD_SIZE; i++) {
+ assert(index->i[i] >= 0);
+ assert(index2D->i[i] == 0);
+
+ chan->u[i] = mach->Addrs[index->i[i]].xyzw[swizzle].u[i];
+ }
+ break;
+
+ case TGSI_FILE_PREDICATE:
+ for (i = 0; i < QUAD_SIZE; i++) {
+ assert(index->i[i] >= 0 && index->i[i] < TGSI_EXEC_NUM_PREDS);
+ assert(index2D->i[i] == 0);
+
+ chan->u[i] = mach->Predicates[0].xyzw[swizzle].u[i];
+ }
+ break;
+
+ case TGSI_FILE_OUTPUT:
+ /* vertex/fragment output vars can be read too */
+ for (i = 0; i < QUAD_SIZE; i++) {
+ assert(index->i[i] >= 0);
+ assert(index2D->i[i] == 0);
+
+ chan->u[i] = mach->Outputs[index->i[i]].xyzw[swizzle].u[i];
}
break;
default:
- assert( 0 );
+ assert(0);
+ for (i = 0; i < QUAD_SIZE; i++) {
+ chan->u[i] = 0;
+ }
}
}
@@ -1057,6 +1068,7 @@ fetch_source(const struct tgsi_exec_machine *mach,
enum tgsi_exec_datatype src_datatype)
{
union tgsi_exec_channel index;
+ union tgsi_exec_channel index2D;
uint swizzle;
/* We start with a direct index into a register file.
@@ -1095,12 +1107,12 @@ fetch_source(const struct tgsi_exec_machine *mach,
/* get current value of address register[swizzle] */
swizzle = tgsi_util_get_src_register_swizzle( &reg->Indirect, CHAN_X );
- fetch_src_file_channel(
- mach,
- reg->Indirect.File,
- swizzle,
- &index2,
- &indir_index );
+ fetch_src_file_channel(mach,
+ reg->Indirect.File,
+ swizzle,
+ &index2,
+ &ZeroVec,
+ &indir_index);
/* add value of address register to the offset */
index.i[0] += indir_index.i[0];
@@ -1121,44 +1133,22 @@ fetch_source(const struct tgsi_exec_machine *mach,
* subscript to a register file. Effectively it means that
* the register file is actually a 2D array of registers.
*
- * file[1][3] == file[1*sizeof(file[1])+3],
+ * file[3][1],
* where:
* [3] = Dimension.Index
*/
if (reg->Register.Dimension) {
- /* The size of the first-order array depends on the register file type.
- * We need to multiply the index to the first array to get an effective,
- * "flat" index that points to the beginning of the second-order array.
- */
- switch (reg->Register.File) {
- case TGSI_FILE_INPUT:
- case TGSI_FILE_SYSTEM_VALUE:
- index.i[0] *= TGSI_EXEC_MAX_INPUT_ATTRIBS;
- index.i[1] *= TGSI_EXEC_MAX_INPUT_ATTRIBS;
- index.i[2] *= TGSI_EXEC_MAX_INPUT_ATTRIBS;
- index.i[3] *= TGSI_EXEC_MAX_INPUT_ATTRIBS;
- break;
- case TGSI_FILE_CONSTANT:
- index.i[0] *= TGSI_EXEC_MAX_CONST_BUFFER;
- index.i[1] *= TGSI_EXEC_MAX_CONST_BUFFER;
- index.i[2] *= TGSI_EXEC_MAX_CONST_BUFFER;
- index.i[3] *= TGSI_EXEC_MAX_CONST_BUFFER;
- break;
- default:
- assert( 0 );
- }
-
- index.i[0] += reg->Dimension.Index;
- index.i[1] += reg->Dimension.Index;
- index.i[2] += reg->Dimension.Index;
- index.i[3] += reg->Dimension.Index;
+ index2D.i[0] =
+ index2D.i[1] =
+ index2D.i[2] =
+ index2D.i[3] = reg->Dimension.Index;
/* Again, the second subscript index can be addressed indirectly
* identically to the first one.
* Nothing stops us from indirectly addressing the indirect register,
* but there is no need for that, so we won't exercise it.
*
- * file[1][ind[4].y+3],
+ * file[ind[4].y+3][1],
* where:
* ind = DimIndirect.File
* [4] = DimIndirect.Index
@@ -1176,24 +1166,25 @@ fetch_source(const struct tgsi_exec_machine *mach,
index2.i[3] = reg->DimIndirect.Index;
swizzle = tgsi_util_get_src_register_swizzle( &reg->DimIndirect, CHAN_X );
- fetch_src_file_channel(
- mach,
- reg->DimIndirect.File,
- swizzle,
- &index2,
- &indir_index );
-
- index.i[0] += indir_index.i[0];
- index.i[1] += indir_index.i[1];
- index.i[2] += indir_index.i[2];
- index.i[3] += indir_index.i[3];
+ fetch_src_file_channel(mach,
+ reg->DimIndirect.File,
+ swizzle,
+ &index2,
+ &ZeroVec,
+ &indir_index);
+
+ index2D.i[0] += indir_index.i[0];
+ index2D.i[1] += indir_index.i[1];
+ index2D.i[2] += indir_index.i[2];
+ index2D.i[3] += indir_index.i[3];
/* for disabled execution channels, zero-out the index to
* avoid using a potential garbage value.
*/
for (i = 0; i < QUAD_SIZE; i++) {
- if ((execmask & (1 << i)) == 0)
- index.i[i] = 0;
+ if ((execmask & (1 << i)) == 0) {
+ index2D.i[i] = 0;
+ }
}
}
@@ -1201,15 +1192,20 @@ fetch_source(const struct tgsi_exec_machine *mach,
* files, we would have to check whether Dimension is followed
* by a dimension register and continue the saga.
*/
+ } else {
+ index2D.i[0] =
+ index2D.i[1] =
+ index2D.i[2] =
+ index2D.i[3] = 0;
}
swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index );
- fetch_src_file_channel(
- mach,
- reg->Register.File,
- swizzle,
- &index,
- chan );
+ fetch_src_file_channel(mach,
+ reg->Register.File,
+ swizzle,
+ &index,
+ &index2D,
+ chan);
if (reg->Register.Absolute) {
if (src_datatype == TGSI_EXEC_DATA_FLOAT) {
@@ -1243,8 +1239,9 @@ store_dest(struct tgsi_exec_machine *mach,
int offset = 0; /* indirection offset */
int index;
- if (dst_datatype == TGSI_EXEC_DATA_FLOAT) {
- CHECK_INF_OR_NAN(chan);
+ /* for debugging */
+ if (0 && dst_datatype == TGSI_EXEC_DATA_FLOAT) {
+ check_inf_or_nan(chan);
}
/* There is an extra source register that indirectly subscripts
@@ -1272,12 +1269,12 @@ store_dest(struct tgsi_exec_machine *mach,
swizzle = tgsi_util_get_src_register_swizzle( &reg->Indirect, CHAN_X );
/* fetch values from the address/indirection register */
- fetch_src_file_channel(
- mach,
- reg->Indirect.File,
- swizzle,
- &index,
- &indir_index );
+ fetch_src_file_channel(mach,
+ reg->Indirect.File,
+ swizzle,
+ &index,
+ &ZeroVec,
+ &indir_index);
/* save indirection offset */
offset = indir_index.i[0];
@@ -1502,7 +1499,7 @@ emit_primitive(struct tgsi_exec_machine *mach)
}
/*
- * Fetch a four texture samples using STR texture coordinates.
+ * Fetch four texture samples using STR texture coordinates.
*/
static void
fetch_texel( struct tgsi_sampler *sampler,
@@ -1764,13 +1761,7 @@ exec_declaration(struct tgsi_exec_machine *mach,
last = decl->Range.Last;
mask = decl->Declaration.UsageMask;
- if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) {
- assert(decl->Semantic.Index == 0);
- assert(first == last);
- assert(mask == TGSI_WRITEMASK_XYZW);
-
- mach->Inputs[first] = mach->QuadPos;
- } else if (decl->Semantic.Name == TGSI_SEMANTIC_FACE) {
+ if (decl->Semantic.Name == TGSI_SEMANTIC_FACE) {
uint i;
assert(decl->Semantic.Index == 0);