[Mesa-dev] [PATCH] virgl: Add support for glGetMultisample (v2)

Gert Wollny gert.wollny at collabora.com
Mon Jun 25 15:13:48 UTC 2018


Use caps to obtain the multisample sample positions for up to 16
positions and implement the according Gallium interface.

v2: remove unrelated chunk (thanks Ilia Mirkin)

Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
---
This patch requires another patch against virglrenderer to work. 

 src/gallium/drivers/virgl/virgl_context.c | 48 +++++++++++++++++++++++
 src/gallium/drivers/virgl/virgl_hw.h      |  1 +
 src/gallium/drivers/virgl/virgl_screen.c  |  8 +---
 3 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/virgl/virgl_context.c b/src/gallium/drivers/virgl/virgl_context.c
index 8d701bb8f4..fedd9786c0 100644
--- a/src/gallium/drivers/virgl/virgl_context.c
+++ b/src/gallium/drivers/virgl/virgl_context.c
@@ -858,6 +858,52 @@ virgl_context_destroy( struct pipe_context *ctx )
    FREE(vctx);
 }
 
+static void virgl_get_sample_position(struct pipe_context *ctx,
+                                      unsigned sample_count,
+                                      unsigned index,
+                                      float *out_value)
+{
+   struct virgl_context *vctx = virgl_context(ctx);
+   struct virgl_screen *vs = virgl_screen(vctx->base.screen);
+
+   int sample_count_selector = 1;
+
+   if (sample_count > vs->caps.caps.v1.max_samples) {
+      debug_printf("VIRGL: requested %d MSAA samples, but only %d supported\n",
+                   sample_count, vs->caps.caps.v1.max_samples);
+      return;
+   }
+
+   /* For non-power of two sample counts pick the next higher power of two
+    * to base the sample positions on */
+   while (sample_count_selector < sample_count)
+      sample_count_selector <<= 1;
+
+   /* The following is basically copied from dri/i965gen6_get_sample_position
+    * The only addition is that we hold the msaa positions for all sample
+    * counts in a flat array. */
+   uint32_t bits = 0;
+   switch (sample_count_selector) {
+   case 1:
+      out_value[0] = out_value[1] = 0.5f;
+      return;
+   case 2:
+      bits = vs->caps.caps.v2.msaa_sample_positions[0] >> (8 * index);
+      break;
+   case 4:
+      bits = vs->caps.caps.v2.msaa_sample_positions[1] >> (8 * index);
+      break;
+   case 8:
+      bits = vs->caps.caps.v2.msaa_sample_positions[2 + (index >> 2)] >> (8 * (index & 3));
+      break;
+   case 16:
+      bits = vs->caps.caps.v2.msaa_sample_positions[4 + (index >> 2)] >> (8 * (index & 3));
+      break;
+   }
+   out_value[0] = ((bits >> 4) & 0xf) / 16.0f;
+   out_value[1] = (bits & 0xf) / 16.0f;
+}
+
 struct pipe_context *virgl_context_create(struct pipe_screen *pscreen,
                                           void *priv,
                                           unsigned flags)
@@ -925,6 +971,8 @@ struct pipe_context *virgl_context_create(struct pipe_screen *pscreen,
 
    vctx->base.set_blend_color = virgl_set_blend_color;
 
+   vctx->base.get_sample_position = virgl_get_sample_position;
+
    vctx->base.resource_copy_region = virgl_resource_copy_region;
    vctx->base.flush_resource = virgl_flush_resource;
    vctx->base.blit =  virgl_blit;
diff --git a/src/gallium/drivers/virgl/virgl_hw.h b/src/gallium/drivers/virgl/virgl_hw.h
index ee58520f9b..82cbb8aed1 100644
--- a/src/gallium/drivers/virgl/virgl_hw.h
+++ b/src/gallium/drivers/virgl/virgl_hw.h
@@ -298,6 +298,7 @@ struct virgl_caps_v2 {
         uint32_t uniform_buffer_offset_alignment;
         uint32_t shader_buffer_offset_alignment;
         uint32_t capability_bits;
+        uint32_t msaa_sample_positions[8];
 };
 
 union virgl_caps {-- 
2.17.1



More information about the mesa-dev mailing list