frontend/nine: fix fog key overflow
authorAxel Davy <davyaxel0@gmail.com>
Thu, 13 Apr 2023 17:44:04 +0000 (19:44 +0200)
committerMarge Bot <emma+marge@anholt.net>
Sat, 22 Apr 2023 21:09:07 +0000 (21:09 +0000)
FOGTABLEMODE is 2 bits. It could thus
overwrite the part of the ps key reserved
for centroid interpolation.

Fix the size of FOGTABLEMODE and the key

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22583>

src/gallium/frontends/nine/nine_limits.h
src/gallium/frontends/nine/pixelshader9.c
src/gallium/frontends/nine/pixelshader9.h

index b5090da..f94b7c9 100644 (file)
@@ -90,7 +90,7 @@ render_state_limits_table[D3DRS_BLENDOPALPHA + 1] = {
     __BOOLEAN_RS(FOGENABLE),
     __BOOLEAN_RS(SPECULARENABLE),
     __NO_LIMIT_RS(FOGCOLOR),
-    __MASK_RS(FOGTABLEMODE, 0x00000007),
+    __MASK_RS(FOGTABLEMODE, 0x00000003),
     __NO_LIMIT_RS(FOGSTART), /* a bit more complex than that, lets ignore */
     __NO_LIMIT_RS(FOGEND),
     __NO_LIMIT_RS(FOGDENSITY), /* actually should be between 0.0 and 1.0 */
@@ -115,7 +115,7 @@ render_state_limits_table[D3DRS_BLENDOPALPHA + 1] = {
     __BOOLEAN_RS(CLIPPING),
     __BOOLEAN_RS(LIGHTING),
     __NO_LIMIT_RS(AMBIENT),
-    __MASK_RS(FOGVERTEXMODE, 0x00000007),
+    __MASK_RS(FOGVERTEXMODE, 0x00000003),
     __BOOLEAN_RS(COLORVERTEX),
     __BOOLEAN_RS(LOCALVIEWER),
     __BOOLEAN_RS(NORMALIZENORMALS),
index c5fe93c..8df27a9 100644 (file)
@@ -211,7 +211,7 @@ NinePixelShader9_GetVariant( struct NinePixelShader9 *This,
         }
         info.fog_enable = device->context.rs[D3DRS_FOGENABLE];
         info.fog_mode = device->context.rs[D3DRS_FOGTABLEMODE];
-        info.force_color_in_centroid = (key >> 22) & 1;
+        info.force_color_in_centroid = (key >> 23) & 1;
         info.add_constants_defs.c_combination =
             nine_shader_constant_combination_get(This->c_combinations, (key >> 24) & 0xff);
         info.add_constants_defs.int_const_added = &This->int_slots_used;
index 1cf5a55..dd5e1ed 100644 (file)
@@ -113,12 +113,12 @@ NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
 
     if (ps->byte_code.version < 0x30) {
         key |= ((uint64_t)context->rs[D3DRS_FOGENABLE]) << 20;
-        key |= ((uint64_t)context->rs[D3DRS_FOGTABLEMODE]) << 21;
+        key |= ((uint64_t)context->rs[D3DRS_FOGTABLEMODE]) << 21; /* 2 bits */
     }
 
     /* centroid interpolation automatically used for color ps inputs */
     if (context->rt[0]->base.info.nr_samples)
-        key |= ((uint64_t)1) << 22;
+        key |= ((uint64_t)1) << 23;
 
     if ((ps->const_int_slots > 0 || ps->const_bool_slots > 0) && context->inline_constants)
         key |= ((uint64_t)nine_shader_constant_combination_key(&ps->c_combinations,