[Mesa-dev] [PATCH 4/6] nir/lower_tex: add lowering for texture gradient on shadow samplers
Eric Anholt
eric at anholt.net
Tue Dec 6 18:07:21 UTC 2016
Kenneth Graunke <kenneth at whitecape.org> writes:
> [ Unknown signature status ]
> On Thursday, December 1, 2016 8:53:19 AM PST Iago Toral Quiroga wrote:
>> This is ported from the Intel lowering pass that we use with GLSL IR.
>> This takes care of lowering texture gradients on shadow samplers other
>> than cube maps. Intel hardware requires this for gen < 8.
>> ---
>> src/compiler/nir/nir.h | 7 +++++++
>> src/compiler/nir/nir_lower_tex.c | 40 ++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 47 insertions(+)
>>
>> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
>> index ed388c6..d494d5f 100644
>> --- a/src/compiler/nir/nir.h
>> +++ b/src/compiler/nir/nir.h
>> @@ -2437,6 +2437,13 @@ typedef struct nir_lower_tex_options {
>> * If true, lower nir_texop_txd on cube maps with nir_texop_txl.
>> */
>> bool lower_txd_cube_map;
>> +
>> + /**
>> + * If true, lower nir_texop_txd on shadow samplers (except cube maps)
>> + * with nir_texop_txl. Notice that cube map shadow samplers are lowered
>> + * with lower_txd_cube_map.
>> + */
>> + bool lower_txd_shadow;
>> } nir_lower_tex_options;
>>
>> bool nir_lower_tex(nir_shader *shader,
>> diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
>> index c7c3db2..d5ea509 100644
>> --- a/src/compiler/nir/nir_lower_tex.c
>> +++ b/src/compiler/nir/nir_lower_tex.c
>> @@ -556,6 +556,40 @@ lower_gradient_cube_map(nir_builder *b, nir_tex_instr *tex)
>> }
>>
>> static void
>> +lower_gradient_shadow(nir_builder *b, nir_tex_instr *tex)
>> +{
>> + assert(tex->sampler_dim != GLSL_SAMPLER_DIM_CUBE);
>> + assert(tex->is_shadow);
>> + assert(tex->op == nir_texop_txd);
>> + assert(tex->dest.is_ssa);
>> +
>> + /* Use textureSize() to get the width and height of LOD 0 */
>> + nir_ssa_def *size = get_texture_size(b, tex);
>> +
>> + /* Scale the gradients by width and height. Effectively, the incoming
>> + * gradients are s'(x,y), t'(x,y), and r'(x,y) from equation 3.19 in the
>> + * GL 3.0 spec; we want u'(x,y), which is w_t * s'(x,y).
>> + */
>> + nir_ssa_def *dPdx = nir_fmul(b, tex->src[2].src.ssa, size);
>> + nir_ssa_def *dPdy = nir_fmul(b, tex->src[3].src.ssa, size);
>
> NIR texture sources aren't guaranteed to be in any particular order
> (it's kind of annoying)...you should instead do:
>
> nir_ssa_def *dPdx;
> nir_ssa_def *dPdy;
>
> for (unsigned i = 0; i < tex->num_srcs; i++) {
> switch (tex->src[i].src_type) {
> case nir_tex_src_ddx:
> dPdx = nir_fmul(b, tex->src[i].src.ssa, size);
> break;
> case nir_tex_src_ddy:
> dPdy = nir_fmul(b, tex->src[i].src.ssa, size);
> break;
> default:
> break;
> }
> }
>
> Same comment on patch two. Maybe make a get_ddx_ddy() helper?
nir_tex_instr_src_index() helps with this.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161206/d6ee57fc/attachment.sig>
More information about the mesa-dev
mailing list