svga: assign a separate function for is_format_supported() for vgpu10 device
authorCharmaine Lee <charmainel@vmware.com>
Wed, 29 Nov 2017 21:09:26 +0000 (13:09 -0800)
committerBrian Paul <brianp@vmware.com>
Mon, 10 Sep 2018 19:07:30 +0000 (13:07 -0600)
This patch adds a new function svga_is_dx_format_supported() to check
for format support in a VGPU10 device.

v2: reapply the patch after svga_is_format_supported is moved to svga_format.c

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Neha Bhende <bhenden@vmware.com>
src/gallium/drivers/svga/svga_format.c
src/gallium/drivers/svga/svga_format.h
src/gallium/drivers/svga/svga_screen.c

index 79b0c769b0454767fba81f3e8d17b3ddec8bbfac..641d4bcce49f700fbf6be208963fe0c8999749af 100644 (file)
@@ -2284,6 +2284,104 @@ svga_is_format_supported(struct pipe_screen *screen,
    SVGA3dSurfaceFormatCaps mask;
 
    assert(bindings);
+   assert(!ss->sws->have_vgpu10);
+
+   svga_format = svga_translate_format(ss, format, bindings);
+   if (svga_format == SVGA3D_FORMAT_INVALID) {
+      return FALSE;
+   }
+
+   if (util_format_is_srgb(format) &&
+       (bindings & PIPE_BIND_DISPLAY_TARGET)) {
+       /* We only support sRGB rendering with vgpu10 */
+      return FALSE;
+   }
+
+   /*
+    * Override host capabilities, so that we end up with the same
+    * visuals for all virtual hardware implementations.
+    */
+   if (bindings & PIPE_BIND_DISPLAY_TARGET) {
+      switch (svga_format) {
+      case SVGA3D_A8R8G8B8:
+      case SVGA3D_X8R8G8B8:
+      case SVGA3D_R5G6B5:
+         break;
+
+      /* VGPU10 formats */
+      case SVGA3D_B8G8R8A8_UNORM:
+      case SVGA3D_B8G8R8X8_UNORM:
+      case SVGA3D_B5G6R5_UNORM:
+      case SVGA3D_B8G8R8X8_UNORM_SRGB:
+      case SVGA3D_B8G8R8A8_UNORM_SRGB:
+      case SVGA3D_R8G8B8A8_UNORM_SRGB:
+         break;
+
+      /* Often unsupported/problematic. This means we end up with the same
+       * visuals for all virtual hardware implementations.
+       */
+      case SVGA3D_A4R4G4B4:
+      case SVGA3D_A1R5G5B5:
+         return FALSE;
+
+      default:
+         return FALSE;
+      }
+   }
+
+   /*
+    * Query the host capabilities.
+    */
+   svga_get_format_cap(ss, svga_format, &caps);
+
+   if (bindings & PIPE_BIND_RENDER_TARGET) {
+      /* Check that the color surface is blendable, unless it's an
+       * integer format.
+       */
+      if (!svga_format_is_integer(svga_format) &&
+          (caps.value & SVGA3DFORMAT_OP_NOALPHABLEND)) {
+         return FALSE;
+      }
+   }
+
+   mask.value = 0;
+   if (bindings & PIPE_BIND_RENDER_TARGET)
+      mask.value |= SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
+
+   if (bindings & PIPE_BIND_DEPTH_STENCIL)
+      mask.value |= SVGA3DFORMAT_OP_ZSTENCIL;
+
+   if (bindings & PIPE_BIND_SAMPLER_VIEW)
+      mask.value |= SVGA3DFORMAT_OP_TEXTURE;
+
+   if (target == PIPE_TEXTURE_CUBE)
+      mask.value |= SVGA3DFORMAT_OP_CUBETEXTURE;
+   else if (target == PIPE_TEXTURE_3D)
+      mask.value |= SVGA3DFORMAT_OP_VOLUMETEXTURE;
+
+   return (caps.value & mask.value) == mask.value;
+}
+
+
+/**
+ * Implement pipe_screen::is_format_supported() for VGPU10 device.
+ * \param bindings  bitmask of PIPE_BIND_x flags
+ */
+boolean
+svga_is_dx_format_supported(struct pipe_screen *screen,
+                            enum pipe_format format,
+                            enum pipe_texture_target target,
+                            unsigned sample_count,
+                            unsigned storage_sample_count,
+                            unsigned bindings)
+{
+   struct svga_screen *ss = svga_screen(screen);
+   SVGA3dSurfaceFormat svga_format;
+   SVGA3dSurfaceFormatCaps caps;
+   SVGA3dSurfaceFormatCaps mask;
+
+   assert(bindings);
+   assert(ss->sws->have_vgpu10);
 
    if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
       return false;
@@ -2302,18 +2400,11 @@ svga_is_format_supported(struct pipe_screen *screen,
       return FALSE;
    }
 
-   if (!ss->sws->have_vgpu10 &&
-       util_format_is_srgb(format) &&
-       (bindings & (PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_RENDER_TARGET))) {
-       /* We only support sRGB rendering with vgpu10 */
-      return FALSE;
-   }
-
    /*
     * For VGPU10 vertex formats, skip querying host capabilities
     */
 
-   if (ss->sws->have_vgpu10 && (bindings & PIPE_BIND_VERTEX_BUFFER)) {
+   if (bindings & PIPE_BIND_VERTEX_BUFFER) {
       SVGA3dSurfaceFormat svga_format;
       unsigned flags;
       svga_translate_vertex_format_vgpu10(format, &svga_format, &flags);
@@ -2368,22 +2459,19 @@ svga_is_format_supported(struct pipe_screen *screen,
    }
 
    mask.value = 0;
-   if (bindings & PIPE_BIND_RENDER_TARGET) {
+   if (bindings & PIPE_BIND_RENDER_TARGET)
       mask.value |= SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
-   }
-   if (bindings & PIPE_BIND_DEPTH_STENCIL) {
+
+   if (bindings & PIPE_BIND_DEPTH_STENCIL)
       mask.value |= SVGA3DFORMAT_OP_ZSTENCIL;
-   }
-   if (bindings & PIPE_BIND_SAMPLER_VIEW) {
+
+   if (bindings & PIPE_BIND_SAMPLER_VIEW)
       mask.value |= SVGA3DFORMAT_OP_TEXTURE;
-   }
 
-   if (target == PIPE_TEXTURE_CUBE) {
+   if (target == PIPE_TEXTURE_CUBE)
       mask.value |= SVGA3DFORMAT_OP_CUBETEXTURE;
-   }
-   else if (target == PIPE_TEXTURE_3D) {
+   else if (target == PIPE_TEXTURE_3D)
       mask.value |= SVGA3DFORMAT_OP_VOLUMETEXTURE;
-   }
 
    return (caps.value & mask.value) == mask.value;
 }
index 11e7e41e506882b119a492490947260347de8d08..a32b0669c0dfd8b6bda47c0eb54a89ac50538c18 100644 (file)
@@ -131,4 +131,12 @@ svga_is_format_supported(struct pipe_screen *screen,
                          unsigned bindings);
 
 
+boolean
+svga_is_dx_format_supported(struct pipe_screen *screen,
+                            enum pipe_format format,
+                            enum pipe_texture_target target,
+                            unsigned sample_count,
+                            unsigned storage_sample_count,
+                            unsigned bindings);
+
 #endif /* SVGA_FORMAT_H_ */
index f376367f6e2d3420ef426bdcf010e3ac2442ec44..92523315191191966db148e7dddbcfc0eabaa672 100644 (file)
@@ -1070,6 +1070,8 @@ svga_screen_create(struct svga_winsys_screen *sws)
       svgascreen->max_const_buffers =
          get_uint_cap(sws, SVGA3D_DEVCAP_DX_MAX_CONSTANT_BUFFERS, 1);
       assert(svgascreen->max_const_buffers <= SVGA_MAX_CONST_BUFS);
+
+      screen->is_format_supported = svga_is_dx_format_supported;
    }
    else {
       /* VGPU9 */