glsl: use bitwise operators in varying_matches::compute_packing_class()
authorBrian Paul <brianp@vmware.com>
Fri, 15 Dec 2017 21:30:26 +0000 (14:30 -0700)
committerBrian Paul <brianp@vmware.com>
Wed, 20 Dec 2017 18:23:16 +0000 (11:23 -0700)
The mix of bitwise operators with * and + to compute the packing_class
values was a little weird.  Just use bitwise ops instead.

v2: add assertion to make sure interpolation bits fit without collision,
per Timothy.  Basically, rewrite function to be simpler.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl/link_varyings.cpp

index 7821b1ec8162c8725b9f263d0356ca5adc2ce33b..5d398894d71d27a3828fb0d9fc1bf7a678521742 100644 (file)
@@ -1982,12 +1982,17 @@ varying_matches::compute_packing_class(const ir_variable *var)
     *
     * Therefore, the packing class depends only on the interpolation type.
     */
-   unsigned packing_class = var->data.centroid | (var->data.sample << 1) |
-                            (var->data.patch << 2) |
-                            (var->data.must_be_shader_input << 3);
-   packing_class *= 8;
-   packing_class += var->is_interpolation_flat()
+   const unsigned interp = var->is_interpolation_flat()
       ? unsigned(INTERP_MODE_FLAT) : var->data.interpolation;
+
+   assert(interp < (1 << 3));
+
+   const unsigned packing_class = (interp << 0) |
+                                  (var->data.centroid << 3) |
+                                  (var->data.sample << 4) |
+                                  (var->data.patch << 5) |
+                                  (var->data.must_be_shader_input << 6);
+
    return packing_class;
 }