From 6b35c2b110be0d9ae6a292250fdcbab11a9190a5 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Wed, 27 Feb 2013 19:07:18 +0100 Subject: softpipe/draw/tgsi: simplify driver/tgsi sampler interface Use a single sampler adapter instead of per-sampler-unit samplers, and just pass along texture unit and sampler unit in the calls. The reason is that for dx10-style sample opcodes pre-wired samplers including all the texture state aren't really feasible (and for sample_i/sviewinfo we don't even have samplers). Of course right now softpipe doesn't actually do anything more than just look up all its pre-wired per-texunit/per-samplerunit sampler as it did before so this doesn't really achieve much except one more function call, however this is now all softpipe's fault (fixing that in a way which doesn't suck is still an unsolved problem). Reviewed-by: Jose Fonseca --- src/gallium/auxiliary/tgsi/tgsi_exec.c | 81 ++++++++++++++++------------------ src/gallium/auxiliary/tgsi/tgsi_exec.h | 22 +++++---- 2 files changed, 51 insertions(+), 52 deletions(-) (limited to 'src/gallium/auxiliary/tgsi') diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index a2b2a81..6277c3e 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -641,8 +641,7 @@ void tgsi_exec_machine_bind_shader( struct tgsi_exec_machine *mach, const struct tgsi_token *tokens, - uint numSamplers, - struct tgsi_sampler **samplers) + struct tgsi_sampler *sampler) { uint k; struct tgsi_parse_context parse; @@ -657,12 +656,9 @@ tgsi_exec_machine_bind_shader( util_init_math(); - if (numSamplers) { - assert(samplers); - } mach->Tokens = tokens; - mach->Samplers = samplers; + mach->Sampler = sampler; if (!tokens) { /* unbind and free all */ @@ -1717,6 +1713,8 @@ conditional_emit_primitive(struct tgsi_exec_machine *mach) */ static void fetch_texel( struct tgsi_sampler *sampler, + const unsigned sview_idx, + const unsigned sampler_idx, const union tgsi_exec_channel *s, const union tgsi_exec_channel *t, const union tgsi_exec_channel *p, @@ -1732,7 +1730,8 @@ fetch_texel( struct tgsi_sampler *sampler, float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]; /* FIXME: handle explicit derivs, offsets */ - sampler->get_samples(sampler, s->f, t->f, p->f, c0->f, c1->f, control, rgba); + sampler->get_samples(sampler, sview_idx, sampler_idx, + s->f, t->f, p->f, c0->f, c1->f, control, rgba); for (j = 0; j < 4; j++) { r->f[j] = rgba[0][j]; @@ -1790,7 +1789,7 @@ exec_tex(struct tgsi_exec_machine *mach, micro_div(&r[0], &r[0], &r[3]); } - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &ZeroVec, &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ @@ -1803,7 +1802,7 @@ exec_tex(struct tgsi_exec_machine *mach, micro_div(&r[0], &r[0], &r[3]); } - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &ZeroVec, &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ @@ -1823,7 +1822,7 @@ exec_tex(struct tgsi_exec_machine *mach, micro_div(&r[2], &r[2], &r[3]); } - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -1837,7 +1836,7 @@ exec_tex(struct tgsi_exec_machine *mach, micro_div(&r[0], &r[0], &r[3]); } - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -1851,7 +1850,7 @@ exec_tex(struct tgsi_exec_machine *mach, micro_div(&r[0], &r[0], &r[3]); } - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -1867,7 +1866,7 @@ exec_tex(struct tgsi_exec_machine *mach, micro_div(&r[1], &r[1], &r[3]); } - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -1879,7 +1878,7 @@ exec_tex(struct tgsi_exec_machine *mach, FETCH(&r[2], 0, TGSI_CHAN_Z); FETCH(&r[3], 0, TGSI_CHAN_W); - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &r[3], &ZeroVec, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -1896,7 +1895,7 @@ exec_tex(struct tgsi_exec_machine *mach, else cubelod = ZeroVec; - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &r[3], &cubelod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -1913,7 +1912,7 @@ exec_tex(struct tgsi_exec_machine *mach, micro_div(&r[2], &r[2], &r[3]); } - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &ZeroVec, lod, control, &r[0], &r[1], &r[2], &r[3]); @@ -1927,7 +1926,7 @@ exec_tex(struct tgsi_exec_machine *mach, FETCH(&cubearraycomp, 1, TGSI_CHAN_X); - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &r[3], &cubearraycomp, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -1972,7 +1971,7 @@ exec_txd(struct tgsi_exec_machine *mach, FETCH(&r[0], 0, TGSI_CHAN_X); - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &ZeroVec, &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */ tgsi_sampler_lod_none, &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ @@ -1989,7 +1988,7 @@ exec_txd(struct tgsi_exec_machine *mach, FETCH(&r[1], 0, TGSI_CHAN_Y); FETCH(&r[2], 0, TGSI_CHAN_Z); - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &ZeroVec, &ZeroVec, /* inputs */ tgsi_sampler_lod_none, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -2003,7 +2002,7 @@ exec_txd(struct tgsi_exec_machine *mach, FETCH(&r[1], 0, TGSI_CHAN_Y); FETCH(&r[2], 0, TGSI_CHAN_Z); - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &ZeroVec, &ZeroVec, tgsi_sampler_lod_none, &r[0], &r[1], &r[2], &r[3]); @@ -2016,7 +2015,7 @@ exec_txd(struct tgsi_exec_machine *mach, FETCH(&r[2], 0, TGSI_CHAN_Z); FETCH(&r[3], 0, TGSI_CHAN_W); - fetch_texel(mach->Samplers[unit], + fetch_texel(mach->Sampler, unit, unit, &r[0], &r[1], &r[2], &r[3], &ZeroVec, tgsi_sampler_lod_none, &r[0], &r[1], &r[2], &r[3]); @@ -2038,7 +2037,6 @@ static void exec_txf(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst) { - struct tgsi_sampler *sampler; const uint unit = inst->Src[2].Register.Index; union tgsi_exec_channel r[4]; union tgsi_exec_channel offset[3]; @@ -2088,9 +2086,8 @@ exec_txf(struct tgsi_exec_machine *mach, break; } - sampler = mach->Samplers[unit]; - sampler->get_texel(sampler, r[0].i, r[1].i, r[2].i, r[3].i, - offsets, rgba); + mach->Sampler->get_texel(mach->Sampler, unit, r[0].i, r[1].i, r[2].i, r[3].i, + offsets, rgba); for (j = 0; j < TGSI_QUAD_SIZE; j++) { r[0].f[j] = rgba[0][j]; @@ -2110,7 +2107,6 @@ static void exec_txq(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst) { - struct tgsi_sampler *sampler; const uint unit = inst->Src[1].Register.Index; int result[4]; union tgsi_exec_channel r[4], src; @@ -2118,20 +2114,19 @@ exec_txq(struct tgsi_exec_machine *mach, int i,j; fetch_source(mach, &src, &inst->Src[0], TGSI_CHAN_X, TGSI_EXEC_DATA_INT); - sampler = mach->Samplers[unit]; - sampler->get_dims(sampler, src.i[0], result); + mach->Sampler->get_dims(mach->Sampler, unit, src.i[0], result); for (i = 0; i < TGSI_QUAD_SIZE; i++) { for (j = 0; j < 4; j++) { - r[j].i[i] = result[j]; + r[j].i[i] = result[j]; } } for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { if (inst->Dst[0].Register.WriteMask & (1 << chan)) { - store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, - TGSI_EXEC_DATA_INT); + store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, + TGSI_EXEC_DATA_INT); } } } @@ -2173,13 +2168,13 @@ exec_sample(struct tgsi_exec_machine *mach, case TGSI_TEXTURE_1D: if (compare) { FETCH(&r[2], 3, TGSI_CHAN_X); - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &ZeroVec, &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ } else { - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &ZeroVec, &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ @@ -2192,13 +2187,13 @@ exec_sample(struct tgsi_exec_machine *mach, FETCH(&r[1], 0, TGSI_CHAN_Y); if (compare) { FETCH(&r[2], 3, TGSI_CHAN_X); - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &r[2], &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ } else { - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &ZeroVec, &ZeroVec, lod, /* S, T, P, C, LOD */ control, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -2212,13 +2207,13 @@ exec_sample(struct tgsi_exec_machine *mach, FETCH(&r[2], 0, TGSI_CHAN_Z); if(compare) { FETCH(&r[3], 3, TGSI_CHAN_X); - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &r[2], &r[3], lod, control, &r[0], &r[1], &r[2], &r[3]); } else { - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &r[2], &ZeroVec, lod, control, &r[0], &r[1], &r[2], &r[3]); @@ -2231,13 +2226,13 @@ exec_sample(struct tgsi_exec_machine *mach, FETCH(&r[3], 0, TGSI_CHAN_W); if(compare) { FETCH(&r[4], 3, TGSI_CHAN_X); - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &r[2], &r[3], &r[4], control, &r[0], &r[1], &r[2], &r[3]); } else { - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &r[2], &r[3], lod, control, &r[0], &r[1], &r[2], &r[3]); @@ -2272,7 +2267,7 @@ exec_sample_d(struct tgsi_exec_machine *mach, case TGSI_TEXTURE_1D: FETCH(&r[0], 0, TGSI_CHAN_X); - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &ZeroVec, &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, C, LOD */ tgsi_sampler_lod_none, &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ @@ -2283,7 +2278,7 @@ exec_sample_d(struct tgsi_exec_machine *mach, FETCH(&r[0], 0, TGSI_CHAN_X); FETCH(&r[1], 0, TGSI_CHAN_Y); - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &ZeroVec, &ZeroVec, &ZeroVec, /* inputs */ tgsi_sampler_lod_none, &r[0], &r[1], &r[2], &r[3]); /* outputs */ @@ -2295,7 +2290,7 @@ exec_sample_d(struct tgsi_exec_machine *mach, FETCH(&r[1], 0, TGSI_CHAN_Y); FETCH(&r[2], 0, TGSI_CHAN_Z); - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &r[2], &ZeroVec, &ZeroVec, tgsi_sampler_lod_none, &r[0], &r[1], &r[2], &r[3]); @@ -2307,7 +2302,7 @@ exec_sample_d(struct tgsi_exec_machine *mach, FETCH(&r[2], 0, TGSI_CHAN_Z); FETCH(&r[3], 0, TGSI_CHAN_W); - fetch_texel(mach->Samplers[sampler_unit], + fetch_texel(mach->Sampler, resource_unit, sampler_unit, &r[0], &r[1], &r[2], &r[3], &ZeroVec, tgsi_sampler_lod_none, &r[0], &r[1], &r[2], &r[3]); diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.h b/src/gallium/auxiliary/tgsi/tgsi_exec.h index a66c919..c009a97 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.h +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.h @@ -115,6 +115,8 @@ struct tgsi_sampler * lod - lod value, except for shadow cube arrays (compare value there). */ void (*get_samples)(struct tgsi_sampler *sampler, + const unsigned sview_index, + const unsigned sampler_index, const float s[TGSI_QUAD_SIZE], const float t[TGSI_QUAD_SIZE], const float r[TGSI_QUAD_SIZE], @@ -122,12 +124,15 @@ struct tgsi_sampler const float c1[TGSI_QUAD_SIZE], enum tgsi_sampler_control control, float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]); - void (*get_dims)(struct tgsi_sampler *sampler, int level, - int dims[4]); - void (*get_texel)(struct tgsi_sampler *sampler, const int i[TGSI_QUAD_SIZE], - const int j[TGSI_QUAD_SIZE], const int k[TGSI_QUAD_SIZE], - const int lod[TGSI_QUAD_SIZE], const int8_t offset[3], - float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]); + void (*get_dims)(struct tgsi_sampler *sampler, + const unsigned sview_index, + int level, int dims[4]); + void (*get_texel)(struct tgsi_sampler *sampler, + const unsigned sview_index, + const int i[TGSI_QUAD_SIZE], + const int j[TGSI_QUAD_SIZE], const int k[TGSI_QUAD_SIZE], + const int lod[TGSI_QUAD_SIZE], const int8_t offset[3], + float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]); }; #define TGSI_EXEC_NUM_TEMPS 4096 @@ -276,7 +281,7 @@ struct tgsi_exec_machine struct tgsi_exec_vector *Addrs; struct tgsi_exec_vector *Predicates; - struct tgsi_sampler **Samplers; + struct tgsi_sampler *Sampler; unsigned ImmLimit; @@ -363,8 +368,7 @@ void tgsi_exec_machine_bind_shader( struct tgsi_exec_machine *mach, const struct tgsi_token *tokens, - uint numSamplers, - struct tgsi_sampler **samplers); + struct tgsi_sampler *sampler); uint tgsi_exec_machine_run( -- cgit v1.1