i915: Fix wpos_tex vs. -1 comparison
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Mon, 5 Jun 2017 11:01:58 +0000 (14:01 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Wed, 14 Jun 2017 15:22:52 +0000 (18:22 +0300)
wpos_tex used to be a GLuint so assigning -1 to it and
later comparing with -1 worked correctly, but commit
c349031c27b7 ("i915: Fix texcoord vs. varying collision in
fragment programs") changed wpos_tex to uint8_t and hence
broke the comparison. To fix this define a more explicit
invalid value for wpos_tex.

gcc warns us:
i915_fragprog.c:1255:57: warning: comparison is always true due to limited range of data type [-Wtype-limits]
    if (inputsRead & VARYING_BITS_TEX_ANY || p->wpos_tex != -1) {
                                                         ^

And clang says:
i915_fragprog.c:1255:57: warning: comparison of constant -1 with expression of type 'uint8_t' (aka 'unsigned char') is always true [-Wtautological-constant-out-of-range-compare]
   if (inputsRead & VARYING_BITS_TEX_ANY || p->wpos_tex != -1) {
                                            ~~~~~~~~~~~ ^  ~~

Cc: Chih-Wei Huang <cwhuang@android-x86.org>
Cc: Eric Anholt <eric@anholt.net>
Cc: Ian Romanick <ian.d.romanick@intel.com>
Cc: mesa-stable@lists.freedesktop.org
Fixes: c349031c27b7 ("i915: Fix texcoord vs. varying collision in fragment programs")
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/mesa/drivers/dri/i915/i915_context.h
src/mesa/drivers/dri/i915/i915_fragprog.c
src/mesa/drivers/dri/i915/i915_program.c

index 2046d78471d70421748d5a783d5be13bbeeb0f93..f95b531a413e4aa2a39f86a3d89f2a028e20fd2b 100644 (file)
@@ -116,6 +116,7 @@ enum {
 };
 
 #define I915_TEX_UNITS 8
+#define I915_WPOS_TEX_INVALID 0xff
 
 #define I915_MAX_CONSTANT      32
 #define I915_CONSTANT_SIZE     (2+(4*I915_MAX_CONSTANT))
index 0fad2c34c3460b018e0c4dd546db531fa664c425..e19ca60bd3344b38a309fc564595d305316e7e59 100644 (file)
@@ -1063,7 +1063,7 @@ check_wpos(struct i915_fragment_program *p)
    GLint i;
    unsigned unit = 0;
 
-   p->wpos_tex = -1;
+   p->wpos_tex = I915_WPOS_TEX_INVALID;
 
    if ((inputs & VARYING_BIT_POS) == 0)
       return;
@@ -1252,7 +1252,7 @@ i915ValidateFragmentProgram(struct i915_context *i915)
    intel->coloroffset = 0;
    intel->specoffset = 0;
 
-   if (inputsRead & VARYING_BITS_TEX_ANY || p->wpos_tex != -1) {
+   if (inputsRead & VARYING_BITS_TEX_ANY || p->wpos_tex != I915_WPOS_TEX_INVALID) {
       EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, S4_VFMT_XYZW, 16);
    }
    else {
index a8f693f71af86634b1b34af2d321a1547eda5aee..20a47804249ed16bb3d9d300c3b48e45e64e4eb8 100644 (file)
@@ -482,7 +482,7 @@ i915_init_program(struct i915_context *i915, struct i915_fragment_program *p)
    p->decl_t = 0;
    p->temp_flag = 0xffff000;
    p->utemp_flag = ~0x7;
-   p->wpos_tex = -1;
+   p->wpos_tex = I915_WPOS_TEX_INVALID;
    p->depth_written = 0;
    p->nr_params = 0;