summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian@i915.localnet.net>2007-08-07 15:28:12 -0600
committerBrian <brian@i915.localnet.net>2007-08-07 15:28:12 -0600
commitadf5560ea5f6955425939df7e75ce9d11ea36511 (patch)
treebcba217903e9777ab35f67ba00dbb60bce69fdcd
parentab80be0df126066c441cef5e2042b77fa6e0bdde (diff)
checkpoint new tgsi_sampler_state struct
-rw-r--r--src/mesa/pipe/softpipe/sp_quad_fs.c20
-rw-r--r--src/mesa/pipe/tgsi/core/tgsi_exec.c270
-rw-r--r--src/mesa/pipe/tgsi/core/tgsi_exec.h13
3 files changed, 138 insertions, 165 deletions
diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c
index 66513bb4369..8eedb2ecc84 100644
--- a/src/mesa/pipe/softpipe/sp_quad_fs.c
+++ b/src/mesa/pipe/softpipe/sp_quad_fs.c
@@ -129,6 +129,16 @@ static INLINE void pinterp( struct exec_machine *exec,
}
+static void
+get_sample(const struct tgsi_sampler_state *sampler,
+ const GLfloat strq[4], GLfloat rgba[4])
+{
+ rgba[0] = 1;
+ rgba[1] = 1;
+ rgba[2] = 0;
+ rgba[3] = 0;
+}
+
/* This should be done by the fragment shader execution unit (code
* generated from the decl instructions). Do it here for now.
@@ -196,6 +206,7 @@ shade_quad( struct quad_stage *qs, struct quad_header *quad )
struct tgsi_exec_machine machine;
struct tgsi_exec_vector outputs[FRAG_ATTRIB_MAX + 1];
struct tgsi_exec_vector *aoutputs;
+ struct tgsi_sampler_state samplers[8];
GLuint i;
#if !ALIGNED_ATTRIBS
@@ -207,10 +218,17 @@ shade_quad( struct quad_stage *qs, struct quad_header *quad )
memset(&machine, 0, sizeof(machine));
#endif
+#if 11 /* temp sampler setup */
+ samplers[0].state = &softpipe->sampler[0];
+ samplers[0].texture = softpipe->texture[0];
+ samplers[0].get_sample = get_sample;
+#endif
+
/* init machine state */
tgsi_exec_machine_init(
&machine,
- softpipe->fs.tokens );
+ softpipe->fs.tokens,
+ 8, samplers);
/* Consts does not require 16 byte alignment. */
machine.Consts = softpipe->fs.constants->constant;
diff --git a/src/mesa/pipe/tgsi/core/tgsi_exec.c b/src/mesa/pipe/tgsi/core/tgsi_exec.c
index 37ca7c1b2ab..2bd2e7ce051 100644
--- a/src/mesa/pipe/tgsi/core/tgsi_exec.c
+++ b/src/mesa/pipe/tgsi/core/tgsi_exec.c
@@ -1,13 +1,12 @@
#include "tgsi_platform.h"
#include "tgsi_core.h"
+#include "pipe/p_state.h"
#define MESA 1
#if MESA
#include "main/context.h"
#include "main/macros.h"
#include "main/colormac.h"
-#include "swrast/swrast.h"
-#include "swrast/s_context.h"
#endif
#define TILE_BOTTOM_LEFT 0
@@ -64,13 +63,17 @@
void
tgsi_exec_machine_init(
struct tgsi_exec_machine *mach,
- struct tgsi_token *tokens )
+ struct tgsi_token *tokens,
+ GLuint numSamplers,
+ const struct tgsi_sampler_state *samplers)
{
GLuint i, k;
struct tgsi_parse_context parse;
mach->Tokens = tokens;
+ mach->Samplers = samplers;
+
k = tgsi_parse_init (&parse, mach->Tokens);
if (k != TGSI_PARSE_OK) {
printf("Problem parsing!\n");
@@ -1032,7 +1035,7 @@ exec_kil (struct tgsi_exec_machine *mach,
*/
static void
fetch_texel_1d( GLcontext *ctx,
- struct tgsi_sampler_state *sampler,
+ const struct tgsi_sampler_state *sampler,
const union tgsi_exec_channel *s,
GLuint unit,
union tgsi_exec_channel *r,
@@ -1040,68 +1043,48 @@ fetch_texel_1d( GLcontext *ctx,
union tgsi_exec_channel *b,
union tgsi_exec_channel *a )
{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLuint fragment_index;
- GLfloat stpq[4][4];
- GLfloat lambdas[4];
- GLchan rgba[4][4];
-
- for (fragment_index = 0; fragment_index < 4; fragment_index++)
- {
- stpq[fragment_index][0] = s->f[fragment_index];
- }
-
- if (sampler->NeedLambda)
- {
- GLfloat dsdx = s->f[TILE_BOTTOM_RIGHT] - s->f[TILE_BOTTOM_LEFT];
- GLfloat dsdy = s->f[TILE_TOP_LEFT] - s->f[TILE_BOTTOM_LEFT];
-
- GLfloat rho, lambda;
-
- dsdx = FABSF(dsdx);
- dsdy = FABSF(dsdy);
+ GLuint fragment_index;
+ GLfloat stpq[4][4];
+ GLfloat lambdas[4];
- rho = MAX2(dsdx, dsdy) * sampler->ImageWidth;
+ for (fragment_index = 0; fragment_index < 4; fragment_index++) {
+ stpq[fragment_index][0] = s->f[fragment_index];
+ }
- lambda = LOG2(rho);
+ if (sampler->state->min_filter != sampler->state->mag_filter) {
+ GLfloat dsdx = s->f[TILE_BOTTOM_RIGHT] - s->f[TILE_BOTTOM_LEFT];
+ GLfloat dsdy = s->f[TILE_TOP_LEFT] - s->f[TILE_BOTTOM_LEFT];
+ GLfloat rho, lambda;
- if (sampler->NeedLodBias)
- lambda += sampler->LodBias;
+ dsdx = FABSF(dsdx);
+ dsdy = FABSF(dsdy);
- if (sampler->NeedLambdaClamp)
- lambda = CLAMP(lambda, sampler->MinLod, sampler->MaxLod);
+ rho = MAX2(dsdx, dsdy) * sampler->texture->width0;
- /* XXX: Use the same lambda value throughout the tile. Could
- * end up with four unique values by recalculating partial
- * derivs in the other row and column, and calculating lambda
- * using the dx and dy values appropriate for each fragment in
- * the tile.
- */
- lambdas[0] =
- lambdas[1] =
- lambdas[2] =
- lambdas[3] = lambda;
- }
+ lambda = LOG2(rho);
+ lambda += sampler->state->lod_bias;
+ lambda = CLAMP(lambda, sampler->state->min_lod, sampler->state->max_lod);
- if (!swrast->TextureSample[unit]) {
- _swrast_update_texture_samplers(ctx);
- }
-
- /* XXX use a float-valued TextureSample routine here!!! */
- swrast->TextureSample[unit] (ctx,
- ctx->Texture.Unit[unit]._Current,
- 4,
- (const GLfloat (*)[4])stpq,
- lambdas,
- rgba);
+ /* XXX: Use the same lambda value throughout the tile. Could
+ * end up with four unique values by recalculating partial
+ * derivs in the other row and column, and calculating lambda
+ * using the dx and dy values appropriate for each fragment in
+ * the tile.
+ */
+ lambdas[0] =
+ lambdas[1] =
+ lambdas[2] =
+ lambdas[3] = lambda;
+ }
- for (fragment_index = 0; fragment_index < 4; fragment_index++)
- {
- r->f[fragment_index] = CHAN_TO_FLOAT(rgba[fragment_index][0]);
- g->f[fragment_index] = CHAN_TO_FLOAT(rgba[fragment_index][1]);
- b->f[fragment_index] = CHAN_TO_FLOAT(rgba[fragment_index][2]);
- a->f[fragment_index] = CHAN_TO_FLOAT(rgba[fragment_index][3]);
- }
+ for (fragment_index = 0; fragment_index < 4; fragment_index++) {
+ GLfloat rgba[4];
+ sampler->get_sample(sampler, stpq[fragment_index], rgba);
+ r->f[fragment_index] = rgba[0];
+ g->f[fragment_index] = rgba[1];
+ b->f[fragment_index] = rgba[2];
+ a->f[fragment_index] = rgba[3];
+ }
}
/*
@@ -1109,7 +1092,7 @@ fetch_texel_1d( GLcontext *ctx,
*/
static void
fetch_texel_2d( GLcontext *ctx,
- struct tgsi_sampler_state *sampler,
+ const struct tgsi_sampler_state *sampler,
const union tgsi_exec_channel *s,
const union tgsi_exec_channel *t,
GLuint unit,
@@ -1118,18 +1101,16 @@ fetch_texel_2d( GLcontext *ctx,
union tgsi_exec_channel *b,
union tgsi_exec_channel *a )
{
- SWcontext *swrast = SWRAST_CONTEXT( ctx );
GLuint fragment_index;
GLfloat stpq[4][4];
GLfloat lambdas[4];
- GLchan rgba[4][4];
for (fragment_index = 0; fragment_index < 4; fragment_index++) {
stpq[fragment_index][0] = s->f[fragment_index];
stpq[fragment_index][1] = t->f[fragment_index];
}
- if (sampler->NeedLambda) {
+ if (sampler->state->min_filter != sampler->state->mag_filter) {
GLfloat dsdx = s->f[TILE_BOTTOM_RIGHT] - s->f[TILE_BOTTOM_LEFT];
GLfloat dsdy = s->f[TILE_TOP_LEFT] - s->f[TILE_BOTTOM_LEFT];
@@ -1143,21 +1124,15 @@ fetch_texel_2d( GLcontext *ctx,
dtdx = FABSF( dtdx );
dtdy = FABSF( dtdy );
- maxU = MAX2( dsdx, dsdy ) * sampler->ImageWidth;
- maxV = MAX2( dtdx, dtdy ) * sampler->ImageHeight;
+ maxU = MAX2( dsdx, dsdy ) * sampler->texture->width0;
+ maxV = MAX2( dtdx, dtdy ) * sampler->texture->height0;
rho = MAX2( maxU, maxV );
lambda = LOG2( rho );
- if (sampler->NeedLodBias)
- lambda += sampler->LodBias;
-
- if (sampler->NeedLambdaClamp)
- lambda = CLAMP(
- lambda,
- sampler->MinLod,
- sampler->MaxLod );
+ lambda += sampler->state->lod_bias;
+ lambda = CLAMP(lambda, sampler->state->min_lod, sampler->state->max_lod);
/* XXX: Use the same lambda value throughout the tile. Could
* end up with four unique values by recalculating partial
@@ -1171,24 +1146,13 @@ fetch_texel_2d( GLcontext *ctx,
lambdas[3] = lambda;
}
- if (!swrast->TextureSample[unit]) {
- _swrast_update_texture_samplers(ctx);
- }
-
- /* XXX use a float-valued TextureSample routine here!!! */
- swrast->TextureSample[unit](
- ctx,
- ctx->Texture.Unit[unit]._Current,
- 4,
- (const GLfloat (*)[4]) stpq,
- lambdas,
- rgba );
-
for (fragment_index = 0; fragment_index < 4; fragment_index++) {
- r->f[fragment_index] = CHAN_TO_FLOAT( rgba[fragment_index][0] );
- g->f[fragment_index] = CHAN_TO_FLOAT( rgba[fragment_index][1] );
- b->f[fragment_index] = CHAN_TO_FLOAT( rgba[fragment_index][2] );
- a->f[fragment_index] = CHAN_TO_FLOAT( rgba[fragment_index][3] );
+ GLfloat rgba[4];
+ sampler->get_sample(sampler, stpq[fragment_index], rgba);
+ r->f[fragment_index] = rgba[0];
+ g->f[fragment_index] = rgba[1];
+ b->f[fragment_index] = rgba[2];
+ a->f[fragment_index] = rgba[3];
}
}
@@ -1197,7 +1161,7 @@ fetch_texel_2d( GLcontext *ctx,
*/
static void
fetch_texel_3d( GLcontext *ctx,
- struct tgsi_sampler_state *sampler,
+ const struct tgsi_sampler_state *sampler,
const union tgsi_exec_channel *s,
const union tgsi_exec_channel *t,
const union tgsi_exec_channel *p,
@@ -1207,84 +1171,65 @@ fetch_texel_3d( GLcontext *ctx,
union tgsi_exec_channel *b,
union tgsi_exec_channel *a )
{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLuint fragment_index;
- GLfloat stpq[4][4];
- GLfloat lambdas[4];
- GLchan rgba[4][4];
-
- for (fragment_index = 0; fragment_index < 4; fragment_index++)
- {
- stpq[fragment_index][0] = s->f[fragment_index];
- stpq[fragment_index][1] = t->f[fragment_index];
- stpq[fragment_index][2] = p->f[fragment_index];
- }
-
- if (sampler->NeedLambda)
- {
- GLfloat dsdx = s->f[TILE_BOTTOM_RIGHT] - s->f[TILE_BOTTOM_LEFT];
- GLfloat dsdy = s->f[TILE_TOP_LEFT] - s->f[TILE_BOTTOM_LEFT];
-
- GLfloat dtdx = t->f[TILE_BOTTOM_RIGHT] - t->f[TILE_BOTTOM_LEFT];
- GLfloat dtdy = t->f[TILE_TOP_LEFT] - t->f[TILE_BOTTOM_LEFT];
-
- GLfloat dpdx = p->f[TILE_BOTTOM_RIGHT] - p->f[TILE_BOTTOM_LEFT];
- GLfloat dpdy = p->f[TILE_TOP_LEFT] - p->f[TILE_BOTTOM_LEFT];
+ GLuint fragment_index;
+ GLfloat stpq[4][4];
+ GLfloat lambdas[4];
- GLfloat maxU, maxV, maxW, rho, lambda;
+ for (fragment_index = 0; fragment_index < 4; fragment_index++) {
+ stpq[fragment_index][0] = s->f[fragment_index];
+ stpq[fragment_index][1] = t->f[fragment_index];
+ stpq[fragment_index][2] = p->f[fragment_index];
+ }
- dsdx = FABSF(dsdx);
- dsdy = FABSF(dsdy);
- dtdx = FABSF(dtdx);
- dtdy = FABSF(dtdy);
- dpdx = FABSF(dpdx);
- dpdy = FABSF(dpdy);
+ if (sampler->state->min_filter != sampler->state->mag_filter) {
+ GLfloat dsdx = s->f[TILE_BOTTOM_RIGHT] - s->f[TILE_BOTTOM_LEFT];
+ GLfloat dsdy = s->f[TILE_TOP_LEFT] - s->f[TILE_BOTTOM_LEFT];
- maxU = MAX2(dsdx, dsdy) * sampler->ImageWidth;
- maxV = MAX2(dtdx, dtdy) * sampler->ImageHeight;
- maxW = MAX2(dpdx, dpdy) * sampler->ImageDepth;
+ GLfloat dtdx = t->f[TILE_BOTTOM_RIGHT] - t->f[TILE_BOTTOM_LEFT];
+ GLfloat dtdy = t->f[TILE_TOP_LEFT] - t->f[TILE_BOTTOM_LEFT];
- rho = MAX2(maxU, MAX2(maxV, maxW));
+ GLfloat dpdx = p->f[TILE_BOTTOM_RIGHT] - p->f[TILE_BOTTOM_LEFT];
+ GLfloat dpdy = p->f[TILE_TOP_LEFT] - p->f[TILE_BOTTOM_LEFT];
- lambda = LOG2(rho);
+ GLfloat maxU, maxV, maxW, rho, lambda;
- if (sampler->NeedLodBias)
- lambda += sampler->LodBias;
+ dsdx = FABSF(dsdx);
+ dsdy = FABSF(dsdy);
+ dtdx = FABSF(dtdx);
+ dtdy = FABSF(dtdy);
+ dpdx = FABSF(dpdx);
+ dpdy = FABSF(dpdy);
- if (sampler->NeedLambdaClamp)
- lambda = CLAMP(lambda, sampler->MinLod, sampler->MaxLod);
+ maxU = MAX2(dsdx, dsdy) * sampler->texture->width0;
+ maxV = MAX2(dtdx, dtdy) * sampler->texture->height0;
+ maxW = MAX2(dpdx, dpdy) * sampler->texture->depth0;
- /* XXX: Use the same lambda value throughout the tile. Could
- * end up with four unique values by recalculating partial
- * derivs in the other row and column, and calculating lambda
- * using the dx and dy values appropriate for each fragment in
- * the tile.
- */
- lambdas[0] =
- lambdas[1] =
- lambdas[2] =
- lambdas[3] = lambda;
- }
+ rho = MAX2(maxU, MAX2(maxV, maxW));
- if (!swrast->TextureSample[unit]) {
- _swrast_update_texture_samplers(ctx);
- }
+ lambda = LOG2(rho);
+ lambda += sampler->state->lod_bias;
+ lambda = CLAMP(lambda, sampler->state->min_lod, sampler->state->max_lod);
- /* XXX use a float-valued TextureSample routine here!!! */
- swrast->TextureSample[unit] (ctx,
- ctx->Texture.Unit[unit]._Current,
- 4,
- (const GLfloat (*)[4])stpq,
- lambdas,
- rgba);
+ /* XXX: Use the same lambda value throughout the tile. Could
+ * end up with four unique values by recalculating partial
+ * derivs in the other row and column, and calculating lambda
+ * using the dx and dy values appropriate for each fragment in
+ * the tile.
+ */
+ lambdas[0] =
+ lambdas[1] =
+ lambdas[2] =
+ lambdas[3] = lambda;
+ }
- for (fragment_index = 0; fragment_index < 4; fragment_index++)
- {
- r->f[fragment_index] = CHAN_TO_FLOAT(rgba[fragment_index][0]);
- g->f[fragment_index] = CHAN_TO_FLOAT(rgba[fragment_index][1]);
- b->f[fragment_index] = CHAN_TO_FLOAT(rgba[fragment_index][2]);
- a->f[fragment_index] = CHAN_TO_FLOAT(rgba[fragment_index][3]);
- }
+ for (fragment_index = 0; fragment_index < 4; fragment_index++) {
+ GLfloat rgba[4];
+ sampler->get_sample(sampler, stpq[fragment_index], rgba);
+ r->f[fragment_index] = rgba[0];
+ g->f[fragment_index] = rgba[1];
+ b->f[fragment_index] = rgba[2];
+ a->f[fragment_index] = rgba[3];
+ }
}
#endif
@@ -1314,7 +1259,7 @@ exec_instruction(
#if MESA
GET_CURRENT_CONTEXT(ctx);
#endif
- GLuint chan_index;
+ GLuint chan_index, unit;
union tgsi_exec_channel r[8];
switch (inst->Instruction.Opcode) {
@@ -1830,6 +1775,7 @@ exec_instruction(
break;
case TGSI_OPCODE_TEX:
+ unit = inst->FullSrcRegisters[1].SrcRegister.Index;
switch (inst->InstructionExtTexture.Texture) {
case TGSI_TEXTURE_1D:
@@ -1849,7 +1795,7 @@ exec_instruction(
}
#if MESA
fetch_texel_1d (ctx,
- &mach->Samplers[inst->FullSrcRegisters[1].SrcRegister.Index],
+ &mach->Samplers[unit],
&r[0],
inst->FullSrcRegisters[1].SrcRegister.Index,
&r[0], &r[1], &r[2], &r[3]);
@@ -1878,7 +1824,7 @@ exec_instruction(
#if MESA
fetch_texel_2d (ctx,
- &mach->Samplers[inst->FullSrcRegisters[1].SrcRegister.Index],
+ &mach->Samplers[unit],
&r[0], &r[1],
inst->FullSrcRegisters[1].SrcRegister.Index,
&r[0], &r[1], &r[2], &r[3]);
@@ -1909,7 +1855,7 @@ exec_instruction(
#if MESA
fetch_texel_3d (ctx,
- &mach->Samplers[inst->FullSrcRegisters[1].SrcRegister.Index],
+ &mach->Samplers[unit],
&r[0], &r[1], &r[2],
inst->FullSrcRegisters[1].SrcRegister.Index,
&r[0], &r[1], &r[2], &r[3]);
diff --git a/src/mesa/pipe/tgsi/core/tgsi_exec.h b/src/mesa/pipe/tgsi/core/tgsi_exec.h
index abce6ee924a..d2ff40cabbc 100644
--- a/src/mesa/pipe/tgsi/core/tgsi_exec.h
+++ b/src/mesa/pipe/tgsi/core/tgsi_exec.h
@@ -23,6 +23,12 @@ struct tgsi_exec_vector
struct tgsi_sampler_state
{
+ const struct pipe_sampler_state *state;
+ const struct pipe_mipmap_tree *texture;
+ void (*get_sample)(const struct tgsi_sampler_state *sampler,
+ const GLfloat strq[4], GLfloat rgba[4]);
+
+#if 0
GLboolean NeedLambda;
GLboolean NeedLodBias; /* if NeedLambda */
GLboolean NeedLambdaClamp; /* if NeedLambda */
@@ -32,6 +38,7 @@ struct tgsi_sampler_state
GLfloat ImageWidth;
GLfloat ImageHeight;
GLfloat ImageDepth;
+#endif
};
struct tgsi_exec_labels
@@ -94,7 +101,7 @@ struct tgsi_exec_machine
struct tgsi_exec_vector *Temps;
struct tgsi_exec_vector *Addrs;
- struct tgsi_sampler_state Samplers[16];
+ const struct tgsi_sampler_state *Samplers;
GLfloat Imms[256][4];
GLuint ImmLimit;
@@ -113,7 +120,9 @@ struct tgsi_exec_machine
void
tgsi_exec_machine_init(
struct tgsi_exec_machine *mach,
- struct tgsi_token *tokens );
+ struct tgsi_token *tokens,
+ GLuint numSamplers,
+ const struct tgsi_sampler_state *samplers);
void
tgsi_exec_prepare(