#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
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");
*/
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,
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];
+ }
}
/*
*/
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,
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];
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
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];
}
}
*/
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,
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
#if MESA
GET_CURRENT_CONTEXT(ctx);
#endif
- GLuint chan_index;
+ GLuint chan_index, unit;
union tgsi_exec_channel r[8];
switch (inst->Instruction.Opcode) {
break;
case TGSI_OPCODE_TEX:
+ unit = inst->FullSrcRegisters[1].SrcRegister.Index;
switch (inst->InstructionExtTexture.Texture) {
case TGSI_TEXTURE_1D:
}
#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]);
#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]);
#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]);