[Mesa-dev] [PATCH 10/16] compiler: Add a new STATE_VAR_ADVANCED_BLENDING_MODE built-in uniform.

Kenneth Graunke kenneth at whitecape.org
Sat Aug 13 03:13:02 UTC 2016


This will be used for emulating GL_KHR_advanced_blend_equation features
in shader code.  We'll pass in the blending mode that's in use, and use
that in (effectively) a switch statement in the shader.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/program/prog_statevars.c | 53 +++++++++++++++++++++++++++++++++++++++
 src/mesa/program/prog_statevars.h |  5 ++++
 2 files changed, 58 insertions(+)

diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
index 8dddc0b..a63c2a5 100644
--- a/src/mesa/program/prog_statevars.c
+++ b/src/mesa/program/prog_statevars.c
@@ -45,6 +45,44 @@
 
 #define ONE_DIV_SQRT_LN2 (1.201122408786449815)
 
+static enum gl_blend_support_qualifier
+advanced_blend_mode_from_gl_enum(GLenum mode)
+{
+   switch (mode) {
+   case GL_MULTIPLY_KHR:
+      return BLEND_MULTIPLY;
+   case GL_SCREEN_KHR:
+      return BLEND_SCREEN;
+   case GL_OVERLAY_KHR:
+      return BLEND_OVERLAY;
+   case GL_DARKEN_KHR:
+      return BLEND_DARKEN;
+   case GL_LIGHTEN_KHR:
+      return BLEND_LIGHTEN;
+   case GL_COLORDODGE_KHR:
+      return BLEND_COLORDODGE;
+   case GL_COLORBURN_KHR:
+      return BLEND_COLORBURN;
+   case GL_HARDLIGHT_KHR:
+      return BLEND_HARDLIGHT;
+   case GL_SOFTLIGHT_KHR:
+      return BLEND_SOFTLIGHT;
+   case GL_DIFFERENCE_KHR:
+      return BLEND_DIFFERENCE;
+   case GL_EXCLUSION_KHR:
+      return BLEND_EXCLUSION;
+   case GL_HSL_HUE_KHR:
+      return BLEND_HSL_HUE;
+   case GL_HSL_SATURATION_KHR:
+      return BLEND_HSL_SATURATION;
+   case GL_HSL_COLOR_KHR:
+      return BLEND_HSL_COLOR;
+   case GL_HSL_LUMINOSITY_KHR:
+      return BLEND_HSL_LUMINOSITY;
+   default:
+      return 0;
+   }
+}
 
 /**
  * Use the list of tokens in the state[] array to find global GL state
@@ -609,6 +647,15 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
             val[0].i = ctx->TessCtrlProgram.patch_vertices;
          return;
 
+      case STATE_ADVANCED_BLENDING_MODE:
+         if (ctx->Color.BlendEnabled & 1) {
+            GLenum eqn = ctx->Color.Blend[0].EquationRGB;
+            val[0].i = advanced_blend_mode_from_gl_enum(eqn);
+         } else {
+            val[0].i = 0;
+         }
+         return;
+
       /* XXX: make sure new tokens added here are also handled in the 
        * _mesa_program_state_flags() switch, below.
        */
@@ -719,6 +766,9 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
       case STATE_FB_WPOS_Y_TRANSFORM:
          return _NEW_BUFFERS;
 
+      case STATE_ADVANCED_BLENDING_MODE:
+         return _NEW_COLOR;
+
       default:
          /* unknown state indexes are silently ignored and
          *  no flag set, since it is handled by the driver.
@@ -925,6 +975,9 @@ append_token(char *dst, gl_state_index k)
    case STATE_FB_WPOS_Y_TRANSFORM:
       append(dst, "FbWposYTransform");
       break;
+   case STATE_ADVANCED_BLENDING_MODE:
+      append(dst, "AdvancedBlendingMode");
+      break;
    default:
       /* probably STATE_INTERNAL_DRIVER+i (driver private state) */
       append(dst, "driverState");
diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h
index e716d90..7fecb37 100644
--- a/src/mesa/program/prog_statevars.h
+++ b/src/mesa/program/prog_statevars.h
@@ -130,6 +130,11 @@ typedef enum gl_state_index_ {
    STATE_FB_WPOS_Y_TRANSFORM,   /**< (1, 0, -1, height) if a FBO is bound, (-1, height, 1, 0) otherwise */
    STATE_TCS_PATCH_VERTICES_IN, /**< gl_PatchVerticesIn for TCS (integer) */
    STATE_TES_PATCH_VERTICES_IN, /**< gl_PatchVerticesIn for TES (integer) */
+   /**
+    * A single enum gl_blend_support_qualifier value representing the
+    * currently active advanced blending equation, or zero if disabled.
+    */
+   STATE_ADVANCED_BLENDING_MODE,
    STATE_INTERNAL_DRIVER	/* first available state index for drivers (must be last) */
 } gl_state_index;
 
-- 
2.9.0



More information about the mesa-dev mailing list