Mesa (main): i915g: Finish out blend factor overrides for both RGBx and A8.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 23 20:05:10 UTC 2021


Module: Mesa
Branch: main
Commit: 1ccb8ab8011da054c27962e18bc63aabf90c1375
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1ccb8ab8011da054c27962e18bc63aabf90c1375

Author: Emma Anholt <emma at anholt.net>
Date:   Tue Jun 22 16:55:15 2021 -0700

i915g: Finish out blend factor overrides for both RGBx and A8.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11559>

---

 .../drivers/i915/ci/piglit-i915-g33-fails.txt      | 29 ------------
 src/gallium/drivers/i915/i915_context.h            |  9 ++++
 src/gallium/drivers/i915/i915_state.c              | 54 ++++++++++++++++++++++
 src/gallium/drivers/i915/i915_state_dynamic.c      | 14 +++++-
 src/gallium/drivers/i915/i915_state_emit.c         | 23 ---------
 src/gallium/drivers/i915/i915_state_immediate.c    | 11 ++++-
 src/gallium/drivers/i915/i915_surface.c            | 13 +++++-
 7 files changed, 96 insertions(+), 57 deletions(-)

diff --git a/src/gallium/drivers/i915/ci/piglit-i915-g33-fails.txt b/src/gallium/drivers/i915/ci/piglit-i915-g33-fails.txt
index 8b2c8413ffe..f3a3a65f806 100644
--- a/src/gallium/drivers/i915/ci/piglit-i915-g33-fails.txt
+++ b/src/gallium/drivers/i915/ci/piglit-i915-g33-fails.txt
@@ -158,10 +158,6 @@ spec@!opengl 1.1 at clipflat@glDrawElements(GL_QUADS)- glFrontFace(GL_CW)- glPolygo
 spec@!opengl 1.1 at clipflat@glDrawElements(GL_QUAD_STRIP)- glFrontFace(GL_CCW)- glPolygonMode(GL_FILL)- quadrant: center middle PV: FIRST,Fail
 spec@!opengl 1.1 at clipflat@glDrawElements(GL_QUAD_STRIP)- glFrontFace(GL_CW)- glPolygonMode(GL_FILL)- quadrant: center middle PV: FIRST,Fail
 spec@!opengl 1.1 at depthstencil-default_fb-clear,Fail
-spec@!opengl 1.1 at depthstencil-default_fb-copypixels,Fail
-spec@!opengl 1.1 at depthstencil-default_fb-drawpixels-float-and-ushort,Fail
-spec@!opengl 1.1 at draw-pixels,Fail
-spec@!opengl 1.1 at drawpix-z,Fail
 spec@!opengl 1.1 at getteximage-formats,Crash
 spec@!opengl 1.1 at gl-1.1-drawarrays-vertex-count 100000 varray gl_quad_strip,Crash
 spec@!opengl 1.1 at gl-1.1-drawarrays-vertex-count 100000 vbo gl_quad_strip,Crash
@@ -251,7 +247,6 @@ spec@!opengl 1.2 at texwrap 3d proj,Fail
 spec@!opengl 1.2 at texwrap 3d proj at GL_RGBA8- NPOT- projected,Fail
 spec@!opengl 1.2 at texwrap 3d proj bordercolor,Fail
 spec@!opengl 1.2 at texwrap 3d proj bordercolor at GL_RGBA8- projected- border color only,Fail
-spec@!opengl 1.4 at copy-pixels,Fail
 spec@!opengl 1.4 at gl-1.4-polygon-offset,Fail
 
 # 1D textures are treated as 2D, but we don't force
@@ -335,12 +330,6 @@ spec at arb_depth_texture@fbo-clear-formats at GL_DEPTH_COMPONENT,Fail
 spec at arb_depth_texture@fbo-clear-formats at GL_DEPTH_COMPONENT16,Fail
 spec at arb_depth_texture@fbo-clear-formats at GL_DEPTH_COMPONENT24,Fail
 spec at arb_depth_texture@fbo-clear-formats at GL_DEPTH_COMPONENT32,Fail
-spec at arb_depth_texture@fbo-depth-gl_depth_component16-copypixels,Fail
-spec at arb_depth_texture@fbo-depth-gl_depth_component16-drawpixels,Fail
-spec at arb_depth_texture@fbo-depth-gl_depth_component24-copypixels,Fail
-spec at arb_depth_texture@fbo-depth-gl_depth_component24-drawpixels,Fail
-spec at arb_depth_texture@fbo-depth-gl_depth_component32-copypixels,Fail
-spec at arb_depth_texture@fbo-depth-gl_depth_component32-drawpixels,Fail
 spec at arb_depth_texture@fbo-generatemipmap-formats,Fail
 spec at arb_depth_texture@fbo-generatemipmap-formats at GL_DEPTH_COMPONENT,Fail
 spec at arb_depth_texture@fbo-generatemipmap-formats at GL_DEPTH_COMPONENT NPOT,Fail
@@ -366,7 +355,6 @@ spec at arb_fragment_program_shadow@tex-shadow2drect,Fail
 spec at arb_fragment_program_shadow@txp-shadow1d,Fail
 spec at arb_fragment_program_shadow@txp-shadow2d,Fail
 spec at arb_fragment_program_shadow@txp-shadow2drect,Fail
-spec at arb_framebuffer_object@arb_framebuffer_object-depth-stencil-blit depth gl_depth24_stencil8,Fail
 spec at arb_framebuffer_object@arb_framebuffer_object-depth-stencil-blit stencil gl_depth24_stencil8,Fail
 spec at arb_framebuffer_object@arb_framebuffer_object-depth-stencil-blit stencil gl_stencil_index1,Fail
 spec at arb_framebuffer_object@arb_framebuffer_object-depth-stencil-blit stencil gl_stencil_index16,Fail
@@ -410,7 +398,6 @@ spec at arb_texture_compression@texwrap formats bordercolor at GL_COMPRESSED_RGB- bord
 spec at arb_texture_compression@texwrap formats bordercolor at GL_COMPRESSED_RGBA- border color only,Fail
 spec at arb_texture_cube_map@copyteximage cube,Fail
 spec at arb_texture_cube_map@cubemap npot,Fail
-spec at arb_texture_rectangle@copyteximage rect,Fail
 spec at arb_texture_rectangle@glsl-fs-shadow2drect,Fail
 spec at arb_texture_rectangle@glsl-fs-shadow2drect-01,Fail
 spec at arb_texture_rectangle@glsl-fs-shadow2drect-03,Fail
@@ -491,12 +478,6 @@ spec at ext_framebuffer_multisample@accuracy all_samples stencil_resolve depthstenc
 spec at ext_framebuffer_multisample@accuracy all_samples stencil_resolve small depthstencil,Fail
 spec at ext_framebuffer_object@fbo-blending-format-quirks,Fail
 spec at ext_framebuffer_object@fbo-blending-formats,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at 3,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_ALPHA,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_ALPHA12,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_ALPHA16,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_ALPHA4,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_ALPHA8,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_INTENSITY,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_INTENSITY12,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_INTENSITY16,Fail
@@ -507,13 +488,9 @@ spec at ext_framebuffer_object@fbo-blending-formats at GL_LUMINANCE12,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_LUMINANCE16,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_LUMINANCE4,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_LUMINANCE8,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_RGB,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_RGB10,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_RGB12,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_RGB16,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_RGB4,Fail
 spec at ext_framebuffer_object@fbo-blending-formats at GL_RGB5,Fail
-spec at ext_framebuffer_object@fbo-blending-formats at GL_RGB8,Fail
 spec at ext_framebuffer_object@fbo-clear-formats,Fail
 spec at ext_framebuffer_object@fbo-clear-formats at GL_INTENSITY,Fail
 spec at ext_framebuffer_object@fbo-clear-formats at GL_INTENSITY12,Fail
@@ -581,19 +558,13 @@ spec at ext_image_dma_buf_import@ext_image_dma_buf_import-transcode-nv12-as-r8-gr88
 spec at ext_image_dma_buf_import@ext_image_dma_buf_import-unsupported_format,Fail
 spec at ext_occlusion_query_boolean@any-samples,Fail
 spec at ext_packed_depth_stencil@depth_stencil texture,Fail
-spec at ext_packed_depth_stencil@fbo-blit-d24s8,Fail
 spec at ext_packed_depth_stencil@fbo-clear-formats,Fail
 spec at ext_packed_depth_stencil@fbo-clear-formats at GL_DEPTH24_STENCIL8,Fail
 spec at ext_packed_depth_stencil@fbo-clear-formats at GL_DEPTH_STENCIL,Fail
 spec at ext_packed_depth_stencil@fbo-clear-formats stencil,Fail
 spec at ext_packed_depth_stencil@fbo-clear-formats stencil at GL_DEPTH24_STENCIL8,Fail
 spec at ext_packed_depth_stencil@fbo-clear-formats stencil at GL_DEPTH_STENCIL,Fail
-spec at ext_packed_depth_stencil@fbo-depth-gl_depth24_stencil8-blit,Fail
-spec at ext_packed_depth_stencil@fbo-depth-gl_depth24_stencil8-copypixels,Fail
-spec at ext_packed_depth_stencil@fbo-depth-gl_depth24_stencil8-drawpixels,Fail
 spec at ext_packed_depth_stencil@fbo-depthstencil-gl_depth24_stencil8-clear,Fail
-spec at ext_packed_depth_stencil@fbo-depthstencil-gl_depth24_stencil8-copypixels,Fail
-spec at ext_packed_depth_stencil@fbo-depthstencil-gl_depth24_stencil8-drawpixels-float-and-ushort,Fail
 spec at ext_packed_depth_stencil@fbo-stencil-gl_depth24_stencil8-blit,Fail
 spec at ext_packed_depth_stencil@texwrap formats bordercolor,Fail
 spec at ext_packed_depth_stencil@texwrap formats bordercolor at GL_DEPTH24_STENCIL8- border color only,Fail
diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h
index b0bfdba4dc4..179e0cc29c0 100644
--- a/src/gallium/drivers/i915/i915_context.h
+++ b/src/gallium/drivers/i915/i915_context.h
@@ -181,9 +181,15 @@ struct i915_state
 
 struct i915_blend_state {
    unsigned iab;
+   unsigned iab_alpha_in_g;
+   unsigned iab_alpha_is_x;
+
    unsigned modes4;
    unsigned LIS5;
+
    unsigned LIS6;
+   unsigned LIS6_alpha_in_g;
+   unsigned LIS6_alpha_is_x;
 };
 
 struct i915_depth_stencil_state {
@@ -222,6 +228,9 @@ struct i915_surface {
    uint32_t oc_swizzle;
    /* cbuf swizzle from dst r/g/b/a channels in memory to channels of gallium API. */
    uint8_t color_swizzle[4];
+
+   bool alpha_in_g : 1;
+   bool alpha_is_x : 1;
 };
 
 struct i915_velems_state {
diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c
index 1e85d7c4846..ef5710a7d22 100644
--- a/src/gallium/drivers/i915/i915_state.c
+++ b/src/gallium/drivers/i915/i915_state.c
@@ -97,6 +97,50 @@ static unsigned translate_mip_filter( unsigned filter )
    }
 }
 
+static uint32_t
+i915_remap_lis6_blend_dst_alpha(uint32_t lis6, uint32_t normal, uint32_t inv)
+{
+   uint32_t src = (lis6 >> S6_CBUF_SRC_BLEND_FACT_SHIFT) & BLENDFACT_MASK;
+   lis6 &= ~SRC_BLND_FACT(BLENDFACT_MASK);
+   if (src == BLENDFACT_DST_ALPHA)
+      src = normal;
+   else if (src == BLENDFACT_INV_DST_ALPHA)
+      src = inv;
+   lis6 |= SRC_BLND_FACT(src);
+
+   uint32_t dst = (lis6 >> S6_CBUF_DST_BLEND_FACT_SHIFT) & BLENDFACT_MASK;
+   lis6 &= ~DST_BLND_FACT(BLENDFACT_MASK);
+   if (dst == BLENDFACT_DST_ALPHA)
+      dst = normal;
+   else if (dst == BLENDFACT_INV_DST_ALPHA)
+      dst = inv;
+   lis6 |= DST_BLND_FACT(dst);
+
+   return lis6;
+}
+
+static uint32_t
+i915_remap_iab_blend_dst_alpha(uint32_t iab, uint32_t normal, uint32_t inv)
+{
+   uint32_t src = (iab >> IAB_SRC_FACTOR_SHIFT) & BLENDFACT_MASK;
+   iab &= ~SRC_BLND_FACT(BLENDFACT_MASK);
+   if (src == BLENDFACT_DST_ALPHA)
+      src = normal;
+   else if (src == BLENDFACT_INV_DST_ALPHA)
+      src = inv;
+   iab |= SRC_ABLND_FACT(src);
+
+   uint32_t dst = (iab >> IAB_DST_FACTOR_SHIFT) & BLENDFACT_MASK;
+   iab &= ~DST_BLND_FACT(BLENDFACT_MASK);
+   if (dst == BLENDFACT_DST_ALPHA)
+      dst = normal;
+   else if (dst == BLENDFACT_INV_DST_ALPHA)
+      dst = inv;
+   iab |= DST_ABLND_FACT(dst);
+
+   return iab;
+}
+
 /* None of this state is actually used for anything yet.
  */
 static void *
@@ -173,6 +217,16 @@ i915_create_blend_state(struct pipe_context *pipe,
                          (i915_translate_blend_func(funcRGB) << S6_CBUF_BLEND_FUNC_SHIFT));
    }
 
+   cso_data->LIS6_alpha_in_g =
+      i915_remap_lis6_blend_dst_alpha(cso_data->LIS6, BLENDFACT_DST_COLR, BLENDFACT_INV_DST_COLR);
+   cso_data->LIS6_alpha_is_x =
+      i915_remap_lis6_blend_dst_alpha(cso_data->LIS6, BLENDFACT_ONE, BLENDFACT_ZERO);
+
+   cso_data->iab_alpha_in_g =
+      i915_remap_iab_blend_dst_alpha(cso_data->iab, BLENDFACT_DST_COLR, BLENDFACT_INV_DST_COLR);
+   cso_data->iab_alpha_is_x =
+      i915_remap_iab_blend_dst_alpha(cso_data->iab, BLENDFACT_ONE, BLENDFACT_ZERO);
+
    return cso_data;
 }
 
diff --git a/src/gallium/drivers/i915/i915_state_dynamic.c b/src/gallium/drivers/i915/i915_state_dynamic.c
index 9193df07ff1..278ca9bda7e 100644
--- a/src/gallium/drivers/i915/i915_state_dynamic.c
+++ b/src/gallium/drivers/i915/i915_state_dynamic.c
@@ -164,7 +164,17 @@ const struct i915_tracked_state i915_upload_BLENDCOLOR = {
  */
 static void upload_IAB(struct i915_context *i915)
 {
-   unsigned iab = i915->blend->iab;
+   unsigned iab = 0;
+
+   if (i915->blend) {
+      struct i915_surface *cbuf = i915_surface(i915->framebuffer.cbufs[0]);
+      if (cbuf && cbuf->alpha_in_g)
+         iab |= i915->blend->iab_alpha_in_g;
+      else if (cbuf && cbuf->alpha_is_x)
+         iab |= i915->blend->iab_alpha_is_x;
+      else
+         iab |= i915->blend->iab;
+   }
 
    set_dynamic(i915, I915_DYNAMIC_IAB, iab);
 }
@@ -172,7 +182,7 @@ static void upload_IAB(struct i915_context *i915)
 const struct i915_tracked_state i915_upload_IAB = {
    "IAB",
    upload_IAB,
-   I915_NEW_BLEND
+   I915_NEW_BLEND | I915_NEW_FRAMEBUFFER
 };
 
 
diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c
index 4e48040c18a..0296a17287b 100644
--- a/src/gallium/drivers/i915/i915_state_emit.c
+++ b/src/gallium/drivers/i915/i915_state_emit.c
@@ -154,27 +154,6 @@ static void emit_immediate_s5(struct i915_context *i915, uint imm)
    OUT_BATCH(imm);
 }
 
-static void emit_immediate_s6(struct i915_context *i915, uint imm)
-{
-   /* Fixup blend function for A8 dst buffers.
-    * When we blend to an A8 buffer, the GPU thinks it's a G8 buffer,
-    * and therefore we need to use the color factor for alphas. */
-   uint srcRGB;
-
-   if (i915->framebuffer.cbufs[0] &&
-       i915->framebuffer.cbufs[0]->format == PIPE_FORMAT_A8_UNORM) {
-      srcRGB = (imm >> S6_CBUF_SRC_BLEND_FACT_SHIFT) & BLENDFACT_MASK;
-      if (srcRGB == BLENDFACT_DST_ALPHA)
-         srcRGB = BLENDFACT_DST_COLR;
-      else if (srcRGB == BLENDFACT_INV_DST_ALPHA)
-         srcRGB = BLENDFACT_INV_DST_COLR;
-      imm &= ~SRC_BLND_FACT(BLENDFACT_MASK);
-      imm |= SRC_BLND_FACT(srcRGB);
-   }
-
-   OUT_BATCH(imm);
-}
-
 static void
 emit_immediate(struct i915_context *i915)
 {
@@ -202,8 +181,6 @@ emit_immediate(struct i915_context *i915)
       if (dirty & (1 << i)) {
          if (i == I915_IMMEDIATE_S5)
             emit_immediate_s5(i915, i915->current.immediate[i]);
-         else if (i == I915_IMMEDIATE_S6)
-            emit_immediate_s6(i915, i915->current.immediate[i]);
          else
             OUT_BATCH(i915->current.immediate[i]);
       }
diff --git a/src/gallium/drivers/i915/i915_state_immediate.c b/src/gallium/drivers/i915/i915_state_immediate.c
index 0631fa1d126..91b6cf5ceb6 100644
--- a/src/gallium/drivers/i915/i915_state_immediate.c
+++ b/src/gallium/drivers/i915/i915_state_immediate.c
@@ -168,8 +168,15 @@ static void upload_S6(struct i915_context *i915)
 
    /* I915_NEW_BLEND
     */
-   if (i915->blend)
-      LIS6 |= i915->blend->LIS6;
+   if (i915->blend) {
+      struct i915_surface *cbuf = i915_surface(i915->framebuffer.cbufs[0]);
+      if (cbuf && cbuf->alpha_in_g)
+         LIS6 |= i915->blend->LIS6_alpha_in_g;
+      else if (cbuf && cbuf->alpha_is_x)
+         LIS6 |= i915->blend->LIS6_alpha_is_x;
+      else
+         LIS6 |= i915->blend->LIS6;
+   }
 
    /* I915_NEW_DEPTH
     */
diff --git a/src/gallium/drivers/i915/i915_surface.c b/src/gallium/drivers/i915/i915_surface.c
index f642c151c47..84b0207b7e1 100644
--- a/src/gallium/drivers/i915/i915_surface.c
+++ b/src/gallium/drivers/i915/i915_surface.c
@@ -351,6 +351,8 @@ i915_clear_depth_stencil_blitter(struct pipe_context *pipe,
 
 static void i915_set_color_surface_swizzle(struct i915_surface *surf)
 {
+   enum pipe_format format = surf->templ.format;
+
    const struct {
       enum pipe_format format;
       uint8_t color_swizzle[4];
@@ -358,13 +360,22 @@ static void i915_set_color_surface_swizzle(struct i915_surface *surf)
    } fixup_formats[] = {
       { PIPE_FORMAT_R8G8B8A8_UNORM, {2, 1, 0, 3 }, 0x21030000 /* BGRA */},
       { PIPE_FORMAT_R8G8B8X8_UNORM, {2, 1, 0, 3 }, 0x21030000 /* BGRX */},
+
+      /* These are rendered to using COLORBUF_8BIT, where the G channel written
+       * by shader (and output by blending) is used.
+       */
       { PIPE_FORMAT_L8_UNORM,       {0, 0, 0, 0 }, 0x00030000 /* RRRA */},
       { PIPE_FORMAT_I8_UNORM,       {0, 0, 0, 0 }, 0x00030000 /* RRRA */},
       { PIPE_FORMAT_A8_UNORM,       {3, 3, 3, 3 }, 0x33330000 /* AAAA */},
    };
 
+   if (format == PIPE_FORMAT_A8_UNORM)
+      surf->alpha_in_g = true;
+   else if (util_format_is_rgbx_or_bgrx(format))
+      surf->alpha_is_x = true;
+
    for (int i = 0; i < ARRAY_SIZE(fixup_formats); i++) {
-      if (fixup_formats[i].format == surf->templ.format) {
+      if (fixup_formats[i].format == format) {
          memcpy(surf->color_swizzle, fixup_formats[i].color_swizzle, sizeof(surf->color_swizzle));
          surf->oc_swizzle = fixup_formats[i].oc_swizzle;
          return;



More information about the mesa-commit mailing list