[Mesa-dev] [PATCH] util: add u_lowering

Rob Clark robdclark at gmail.com
Tue Sep 30 16:55:57 PDT 2014


On Tue, Sep 30, 2014 at 6:57 PM, Roland Scheidegger <sroland at vmware.com> wrote:
>
>> +/* Inserts a MOV_SAT for the needed components of tex coord.  Note that
>> + * in the case of TXP, the clamping must happen *after* projection, so
>> + * we need to lower TXP to TEX.
>> + *
>> + *   MOV tmpA, src0
>> + *   if (opc == TXP) {
>> + *     ; do perspective division manually before clamping:
>> + *     RCP tmpB, tmpA.w
>> + *     MUL tmpB.<pmask>, tmpA, tmpB.xxxx
>> + *     opc = TEX;
>> + *   }
>> + *   MOV_SAT tmpA.<mask>, tmpA  ; <mask> is the clamped s/t/r coords
>> + *   <opc> dst, tmpA, ...
>> + */
>> +#define SAMP_GROW (NINST(1) + NINST(1) + NINST(2) + NINST(1))
>> +#define SAMP_TMP  2
>> +static int
>> +transform_samp(struct tgsi_transform_context *tctx,
>> +               struct tgsi_full_instruction *inst)
>> +{
>> +   struct u_lowering_context *ctx = u_lowering_context(tctx);
>> +   struct tgsi_full_src_register *coord = &inst->Src[0];
>> +   struct tgsi_full_src_register *samp;
>> +   struct tgsi_full_instruction new_inst;
>> +   /* mask is clamped coords, pmask is all coords (for projection): */
>> +   unsigned mask = 0, pmask = 0, smask;
>> +   unsigned opcode = inst->Instruction.Opcode;
>> +
>> +   if (opcode == TGSI_OPCODE_TXB2) {
>> +      samp = &inst->Src[2];
>> +   }
>> +   else {
>> +      samp = &inst->Src[1];
>> +   }
>> +
>> +   /* convert sampler # to bitmask to test: */
>> +   smask = 1 << samp->Register.Index;
>> +
>> +   /* check if we actually need to lower this one: */
>> +   if (!(ctx->saturate & smask))
>> +      return -1;
>> +
>> +   /* figure out which coordinates need saturating:
>> +    *   - RECT textures should not get saturated
>> +    *   - array index coords should not get saturated
>> +    */
>> +   switch (inst->Texture.Texture) {
>> +   case TGSI_TEXTURE_3D:
>> +   case TGSI_TEXTURE_CUBE:
>> +   case TGSI_TEXTURE_CUBE_ARRAY:
> FWIW there's no way this is going to work with cube textures (as you'd
> need to do it post cube transform).
> Maybe you intended this be the drivers responsibility to not set it in
> this case (cube texturing may or may not ignore the wrap modes depending
> on hw I guess, it certainly will with seamless, but even without we
> ended up forcing it to clamp_to_edge in llvmpipe in any case though
> technically with GL this isn't quite right). But clamping it pre cube
> transform would definitely break things (so probably should be an
> assert() or just not doing any clamping in this case here).


Ok, I guess I should drop CUBE/CUBE_ARRAY then and not pretend..  at
the end of the day this was mostly for trying to do GL on GLES hw (and
because big chunks of piglit fail because of GL_CLAMP+LINEAR), so if
some cases are simply not possible, so be it.

Ilia brought up that I probably am not quite doing it right for TXP +
shadow as well, so I need to figure out quite how that is *supposed*
to work.

(But even with a few things wrong, making GL_CLAMP emulation mostly
work was worth something like +90 piglits or so..)

BR,
-R


More information about the mesa-dev mailing list