broadcom/vc5: Add PIPE_TEX_WRAP_CLAMP support for linear-filtered textures.
authorEric Anholt <eric@anholt.net>
Tue, 24 Oct 2017 19:29:39 +0000 (12:29 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 30 Oct 2017 20:31:16 +0000 (13:31 -0700)
I already had the texture's wrapping set up to use different behavior for
nearest or linear, so we just needed to saturate the coordinates in linear
mode to get the "proper" blend between the edge and border values.

src/broadcom/compiler/v3d_compiler.h
src/broadcom/compiler/vir.c
src/gallium/drivers/vc5/vc5_program.c

index 021c88f7b937cdfd9276d83c2087852e0804e4a5..56a9d143e3253f493037a5e01c215e8ab62cbbbe 100644 (file)
@@ -294,8 +294,9 @@ struct v3d_key {
                         struct {
                                 unsigned compare_mode:1;
                                 unsigned compare_func:3;
-                                unsigned wrap_s:3;
-                                unsigned wrap_t:3;
+                                bool clamp_s:1;
+                                bool clamp_t:1;
+                                bool clamp_r:1;
                         };
                         struct {
                                 uint16_t msaa_width, msaa_height;
index 99b31841b379eb85554f8aac74a0ca2546acc64f..d9201e68dc541b34205a2c1d3fddc24ebc4c6341 100644 (file)
@@ -553,6 +553,13 @@ v3d_lower_nir(struct v3d_compile *c)
         for (int i = 0; i < ARRAY_SIZE(c->key->tex); i++) {
                 for (int j = 0; j < 4; j++)
                         tex_options.swizzles[i][j] = c->key->tex[i].swizzle[j];
+
+                if (c->key->tex[i].clamp_s)
+                        tex_options.saturate_s |= 1 << i;
+                if (c->key->tex[i].clamp_t)
+                        tex_options.saturate_t |= 1 << i;
+                if (c->key->tex[i].clamp_r)
+                        tex_options.saturate_r |= 1 << i;
         }
 
         NIR_PASS_V(c->s, nir_lower_tex, &tex_options);
index 8e9af1ad8ab07dcc73da93106096332c987be9ac..37173ae58d5b1e9197798b505cf9c867022388eb 100644 (file)
@@ -304,8 +304,12 @@ vc5_setup_shared_key(struct vc5_context *vc5, struct v3d_key *key,
                 } else if (sampler){
                         key->tex[i].compare_mode = sampler_state->compare_mode;
                         key->tex[i].compare_func = sampler_state->compare_func;
-                        key->tex[i].wrap_s = sampler_state->wrap_s;
-                        key->tex[i].wrap_t = sampler_state->wrap_t;
+                        key->tex[i].clamp_s =
+                                sampler_state->wrap_s == PIPE_TEX_WRAP_CLAMP;
+                        key->tex[i].clamp_t =
+                                sampler_state->wrap_t == PIPE_TEX_WRAP_CLAMP;
+                        key->tex[i].clamp_r =
+                                sampler_state->wrap_r == PIPE_TEX_WRAP_CLAMP;
                 }
         }