virgl: Add override for BGRA format to use swizzled SRGB format
authorGert Wollny <gert.wollny@collabora.com>
Mon, 27 May 2019 14:28:44 +0000 (16:28 +0200)
committerGert Wollny <gert.wollny@collabora.com>
Thu, 20 Jun 2019 06:50:38 +0000 (08:50 +0200)
Tie in the check whether the host supports tweaks and whether this tweak
is enabled.

v2: Add comment about the emulated formats not being used directly in the
    guest (Gurchetan)

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
src/gallium/drivers/virgl/virgl_driinfo.h.in
src/gallium/drivers/virgl/virgl_hw.h
src/gallium/drivers/virgl/virgl_resource.c
src/gallium/drivers/virgl/virgl_screen.c

index 626e21c3648a7ac053b8449d56ecb57a855da15e..66d547d4712185ce6c2377e71be5d98b45ad7bc8 100644 (file)
@@ -7,5 +7,6 @@
 //   4. Add the code to send the tweek to the host in virgl_send_tweaks
 //   5. Implement the tweak in virglrenderer
 DRI_CONF_SECTION_MISCELLANEOUS
+    DRI_CONF_GLES_EMULATE_BGRA("false")
 DRI_CONF_SECTION_END
 
index 91e4259abe3fc0de2bbf3c2497c4e20def781c7e..94f5987fe32d218825d9fe3f20016c062d8183be 100644 (file)
@@ -222,7 +222,12 @@ enum virgl_formats {
    VIRGL_FORMAT_A4B4G4R4_UNORM          = 311,
 
    VIRGL_FORMAT_R8_SRGB                 = 312,
-   VIRGL_FORMAT_MAX,
+   VIRGL_FORMAT_MAX /* = PIPE_FORMAT_COUNT */,
+
+   /* Below formats must not be used in the guest. */
+   VIRGL_FORMAT_B8G8R8X8_UNORM_EMULATED,
+   VIRGL_FORMAT_B8G8R8A8_UNORM_EMULATED,
+   VIRGL_FORMAT_MAX_EXTENDED
 };
 
 /* These are used by the capability_bits field in virgl_caps_v2. */
@@ -256,6 +261,7 @@ enum virgl_formats {
 #define VIRGL_CAP_COPY_TRANSFER        (1 << 26)
 #define VIRGL_CAP_CLIP_HALFZ           (1 << 27)
 #define VIRGL_CAP_APP_TWEAK_SUPPORT    (1 << 28)
+#define VIRGL_CAP_BGRA_SRGB_IS_EMULATED (1 << 29)
 
 /* virgl bind flags - these are compatible with mesa 10.5 gallium.
  * but are fixed, no other should be passed to virgl either.
@@ -280,6 +286,9 @@ enum virgl_formats {
 #define VIRGL_BIND_STAGING       (1 << 19)
 #define VIRGL_BIND_SHARED        (1 << 20)
 
+/* Extra flags that may be passed  */
+#define VIRGL_BIND_PREFER_EMULATED_BGRA  (1 << 21)
+
 struct virgl_caps_bool_set1 {
         unsigned indep_blend_enable:1;
         unsigned indep_blend_func:1;
index 4e585d72490cfb081f195b68e752052762e8c301..0659b38c692af52db35a55b5ab548fddd8c54ec7 100644 (file)
@@ -222,6 +222,16 @@ static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen,
    pipe_reference_init(&res->u.b.reference, 1);
    vbind = pipe_to_virgl_bind(vs, templ->bind, templ->flags);
    virgl_resource_layout(&res->u.b, &res->metadata);
+
+   if ((vs->caps.caps.v2.capability_bits & VIRGL_CAP_APP_TWEAK_SUPPORT) &&
+       vs->tweak_gles_emulate_bgra &&
+      (templ->format == PIPE_FORMAT_B8G8R8A8_SRGB ||
+        templ->format == PIPE_FORMAT_B8G8R8A8_UNORM ||
+        templ->format == PIPE_FORMAT_B8G8R8X8_SRGB ||
+        templ->format == PIPE_FORMAT_B8G8R8X8_UNORM)) {
+      vbind |= VIRGL_BIND_PREFER_EMULATED_BGRA;
+   }
+
    res->hw_res = vs->vws->resource_create(vs->vws, templ->target,
                                           templ->format, vbind,
                                           templ->width0,
index 1baea5d3f197b4b24ea97c98dc5cb4c3dbcd3c10..31de32f928910f5bf2cd55c14344609cbeb26084 100644 (file)
@@ -639,6 +639,8 @@ virgl_is_format_supported( struct pipe_screen *screen,
    const struct util_format_description *format_desc;
    int i;
 
+   boolean may_emulate_bgra = false;
+
    if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
       return false;
 
@@ -692,6 +694,10 @@ virgl_is_format_supported( struct pipe_screen *screen,
        target == PIPE_TEXTURE_3D)
       return FALSE;
 
+   may_emulate_bgra = (vscreen->caps.caps.v2.capability_bits &
+                       VIRGL_CAP_APP_TWEAK_SUPPORT) &&
+                      vscreen->tweak_gles_emulate_bgra;
+
    if (bind & PIPE_BIND_RENDER_TARGET) {
       /* For ARB_framebuffer_no_attachments. */
       if (format == PIPE_FORMAT_NONE)