i965: Use ffs() for sample counting in gen7_surface_msaa_bits().
authorKenneth Graunke <kenneth@whitecape.org>
Mon, 10 Feb 2014 19:06:03 +0000 (11:06 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 19 Feb 2014 23:35:53 +0000 (15:35 -0800)
The enumerations are just log2(num_samples) shifted by 3, which we can
easily compute via ffs().

This also makes it reusable for Broadwell, which has 2x MSAA.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
src/mesa/drivers/dri/i965/gen7_wm_surface_state.c

index 12d0fa9de58faf33b58743cd2fb2510a0df59e97..154a0fdd83c4f7b926d2a8ee66e2f67138ea5b03 100644 (file)
@@ -82,12 +82,10 @@ gen7_surface_msaa_bits(unsigned num_samples, enum intel_msaa_layout layout)
 {
    uint32_t ss4 = 0;
 
-   if (num_samples > 4)
-      ss4 |= GEN7_SURFACE_MULTISAMPLECOUNT_8;
-   else if (num_samples > 1)
-      ss4 |= GEN7_SURFACE_MULTISAMPLECOUNT_4;
-   else
-      ss4 |= GEN7_SURFACE_MULTISAMPLECOUNT_1;
+   assert(num_samples <= 8);
+
+   /* The SURFACE_MULTISAMPLECOUNT_X enums are simply log2(num_samples) << 3. */
+   ss4 |= (ffs(MAX2(num_samples, 1)) - 1) << 3;
 
    if (layout == INTEL_MSAA_LAYOUT_IMS)
       ss4 |= GEN7_SURFACE_MSFMT_DEPTH_STENCIL;