v3d: Add support for glSampleMask / glSampleCoverage.
authorEric Anholt <eric@anholt.net>
Tue, 8 May 2018 21:28:33 +0000 (14:28 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 17 May 2018 14:09:46 +0000 (15:09 +0100)
src/broadcom/cle/v3d_packet_v41.xml
src/broadcom/cle/v3d_packet_v42.xml
src/gallium/drivers/v3d/v3d_context.h
src/gallium/drivers/v3d/v3d_program.c
src/gallium/drivers/v3d/v3d_uniforms.c
src/gallium/drivers/v3d/v3dx_emit.c
src/gallium/drivers/v3d/v3dx_state.c

index 1fb5d5d2843071de1ee21055243b949866e749e9..c516561407907383876f748873b4909e09949604 100644 (file)
     <field name="Varying offset V0" size="4" start="0" type="uint"/>
   </packet>
 
+  <packet code="91" name="Sample State">
+    <field name="Coverage" size="16" start="16" type="uint"/> <!-- float-1-8-7 -->
+    <field name="Mask" size="4" start="0" type="uint"/>
+  </packet>
+
   <packet code="92" name="Occlusion Query Counter">
     <field name="address" size="32" start="0" type="address"/>
   </packet>
index a562d662ff3624b11a05051fdacbec67db00dc18..fb4425968c36028db82afc8f0b600c2ef6c00d84 100644 (file)
     <field name="Varying offset V0" size="4" start="0" type="uint"/>
   </packet>
 
+  <packet code="91" name="Sample State">
+    <field name="Coverage" size="16" start="16" type="uint"/> <!-- float-1-8-7 -->
+    <field name="Mask" size="4" start="0" type="uint"/>
+  </packet>
+
   <packet code="92" name="Occlusion Query Counter">
     <field name="address" size="32" start="0" type="address"/>
   </packet>
index d110ed50222d373bbca2930d0b701686a875ff08..47945f964972f3429880e755ba8cbcf025d99787 100644 (file)
@@ -61,7 +61,7 @@ void v3d_job_add_bo(struct v3d_job *job, struct v3d_bo *bo);
 
 #define VC5_DIRTY_BLEND_COLOR   (1 <<  7)
 #define VC5_DIRTY_STENCIL_REF   (1 <<  8)
-#define VC5_DIRTY_SAMPLE_MASK   (1 <<  9)
+#define VC5_DIRTY_SAMPLE_STATE  (1 <<  9)
 #define VC5_DIRTY_FRAMEBUFFER   (1 << 10)
 #define VC5_DIRTY_STIPPLE       (1 << 11)
 #define VC5_DIRTY_VIEWPORT      (1 << 12)
index 63e6fda5471de72af88c91dabdce21c79d64f384..036f7c6e6728d03ed7efce96ba0437cfb57195b4 100644 (file)
@@ -399,7 +399,7 @@ v3d_update_compiled_fs(struct v3d_context *v3d, uint8_t prim_mode)
                             VC5_DIRTY_FRAMEBUFFER |
                             VC5_DIRTY_ZSA |
                             VC5_DIRTY_RASTERIZER |
-                            VC5_DIRTY_SAMPLE_MASK |
+                            VC5_DIRTY_SAMPLE_STATE |
                             VC5_DIRTY_FRAGTEX |
                             VC5_DIRTY_UNCOMPILED_FS))) {
                 return;
index 9dd128ab418838562ca74da6d013357242b45a44..ad46c691218f157c4851143dfa690c13c2e16b75 100644 (file)
@@ -475,7 +475,7 @@ v3d_set_shader_uniform_dirty_flags(struct v3d_compiled_shader *shader)
                         break;
 
                 case QUNIFORM_SAMPLE_MASK:
-                        dirty |= VC5_DIRTY_SAMPLE_MASK;
+                        dirty |= VC5_DIRTY_SAMPLE_STATE;
                         break;
 
                 default:
index 8a65478a1614e455461ef00a69a5e1dc5f00ad8c..161ce51b2ff54f58f90eaac8e196eeaaeb55fd6f 100644 (file)
@@ -387,8 +387,17 @@ v3dX(emit_state)(struct pipe_context *pctx)
                         config.enable_depth_offset =
                                 v3d->rasterizer->base.offset_tri;
 
+                        /* V3D follows GL behavior where the sample mask only
+                         * applies when MSAA is enabled.  Gallium has sample
+                         * mask apply anyway, and the MSAA blit shaders will
+                         * set sample mask without explicitly setting
+                         * rasterizer oversample.  Just force it on here,
+                         * since the blit shaders are the only way to have
+                         * !multisample && samplemask != 0xf.
+                         */
                         config.rasterizer_oversample_mode =
-                                v3d->rasterizer->base.multisample;
+                                v3d->rasterizer->base.multisample ||
+                                v3d->sample_mask != 0xf;
 
                         config.direct3d_provoking_vertex =
                                 v3d->rasterizer->base.flatshade_first;
@@ -719,4 +728,16 @@ v3dX(emit_state)(struct pipe_context *pctx)
                         }
                 }
         }
+
+#if V3D_VERSION >= 40
+        if (v3d->dirty & VC5_DIRTY_SAMPLE_STATE) {
+                cl_emit(&job->bcl, SAMPLE_STATE, state) {
+                        /* Note: SampleCoverage was handled at the
+                         * state_tracker level by converting to sample_mask.
+                         */
+                        state.coverage = fui(1.0) >> 16;
+                        state.mask = job->msaa ? v3d->sample_mask : 0xf;
+                }
+        }
+#endif
 }
index 1387a22e048dc2e5d65787a715064bbe107a4a9a..e48e0f3767d324f449bd85137710f6af70c78388 100644 (file)
@@ -88,7 +88,7 @@ v3d_set_sample_mask(struct pipe_context *pctx, unsigned sample_mask)
 {
         struct v3d_context *v3d = v3d_context(pctx);
         v3d->sample_mask = sample_mask & ((1 << VC5_MAX_SAMPLES) - 1);
-        v3d->dirty |= VC5_DIRTY_SAMPLE_MASK;
+        v3d->dirty |= VC5_DIRTY_SAMPLE_STATE;
 }
 
 static uint16_t