[Mesa-dev] [PATCH] Implement EXT_blend_func_extended
Ryan Houdek
sonicadvance1 at gmail.com
Thu Nov 5 08:42:38 PST 2015
This is a very new extension to ES that gives you dual source blending just
like in desktop OpenGL.
This works with the piglits that I've written, which are in the process
of being cleaned up so they can be pushed, and this also works great
with the Dolphin emulator.
---
src/glsl/ast_to_hir.cpp | 16 +++++++++
src/glsl/builtin_variables.cpp | 62 +++++++++++++++++++++++++++++++++
src/glsl/glsl_parser.yy | 5 +++
src/glsl/glsl_parser_extras.cpp | 3 ++
src/glsl/glsl_parser_extras.h | 5 +++
src/mapi/glapi/gen/EXT_gpu_shader4.xml | 3 +-
src/mapi/glapi/gen/es_EXT.xml | 38 ++++++++++++++++++++
src/mesa/main/blend.c | 4 +--
src/mesa/main/extensions.c | 1 +
src/mesa/main/get_hash_params.py | 4 ++-
src/mesa/main/tests/dispatch_sanity.cpp | 8 +++++
11 files changed, 145 insertions(+), 4 deletions(-)
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 0306530..9ac7d80 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -6973,6 +6973,8 @@ detect_conflicting_assignments(struct _mesa_glsl_parse_state *state,
{
bool gl_FragColor_assigned = false;
bool gl_FragData_assigned = false;
+ bool gl_FragSecondaryColor_assigned = false;
+ bool gl_FragSecondaryData_assigned = false;
bool user_defined_fs_output_assigned = false;
ir_variable *user_defined_fs_output = NULL;
@@ -6990,6 +6992,10 @@ detect_conflicting_assignments(struct _mesa_glsl_parse_state *state,
gl_FragColor_assigned = true;
else if (strcmp(var->name, "gl_FragData") == 0)
gl_FragData_assigned = true;
+ else if (strcmp(var->name, "gl_SecondaryFragColorEXT") == 0)
+ gl_FragSecondaryColor_assigned = true;
+ else if (strcmp(var->name, "gl_SecondaryFragDataEXT") == 0)
+ gl_FragSecondaryData_assigned = true;
else if (!is_gl_identifier(var->name)) {
if (state->stage == MESA_SHADER_FRAGMENT &&
var->data.mode == ir_var_shader_out) {
@@ -7021,11 +7027,21 @@ detect_conflicting_assignments(struct _mesa_glsl_parse_state *state,
_mesa_glsl_error(&loc, state, "fragment shader writes to both "
"`gl_FragColor' and `%s'",
user_defined_fs_output->name);
+ } else if (gl_FragSecondaryColor_assigned && gl_FragSecondaryData_assigned) {
+ _mesa_glsl_error(&loc, state, "fragment shader writes to both "
+ "`gl_FragSecondaryColorEXT' and"
+ " `gl_FragSecondaryDataEXT'");
} else if (gl_FragData_assigned && user_defined_fs_output_assigned) {
_mesa_glsl_error(&loc, state, "fragment shader writes to both "
"`gl_FragData' and `%s'",
user_defined_fs_output->name);
}
+
+ if ((gl_FragSecondaryColor_assigned || gl_FragSecondaryData_assigned) &&
+ !state->EXT_blend_func_extended_enable) {
+ _mesa_glsl_error(&loc, state,
+ "Dual source blending requires EXT_blend_func_extended");
+ }
}
diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index c30fb92..ee08993 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -376,6 +376,11 @@ private:
return add_variable(name, type, ir_var_shader_out, slot);
}
+ ir_variable *add_index_output(int slot, int index, const glsl_type *type, const char *name)
+ {
+ return add_index_variable(name, type, ir_var_shader_out, slot, index);
+ }
+
ir_variable *add_system_value(int slot, const glsl_type *type,
const char *name)
{
@@ -384,6 +389,8 @@ private:
ir_variable *add_variable(const char *name, const glsl_type *type,
enum ir_variable_mode mode, int slot);
+ ir_variable *add_index_variable(const char *name, const glsl_type *type,
+ enum ir_variable_mode mode, int slot, int index);
ir_variable *add_uniform(const glsl_type *type, const char *name);
ir_variable *add_const(const char *name, int value);
ir_variable *add_const_ivec3(const char *name, int x, int y, int z);
@@ -429,6 +436,46 @@ builtin_variable_generator::builtin_variable_generator(
{
}
+ir_variable *
+builtin_variable_generator::add_index_variable(const char *name,
+ const glsl_type *type,
+ enum ir_variable_mode mode, int slot, int index)
+{
+ ir_variable *var = new(symtab) ir_variable(type, name, mode);
+ var->data.how_declared = ir_var_declared_implicitly;
+
+ switch (var->data.mode) {
+ case ir_var_auto:
+ case ir_var_shader_in:
+ case ir_var_uniform:
+ case ir_var_system_value:
+ var->data.read_only = true;
+ break;
+ case ir_var_shader_out:
+ case ir_var_shader_storage:
+ break;
+ default:
+ /* The only variables that are added using this function should be
+ * uniforms, shader storage, shader inputs, and shader outputs, constants
+ * (which use ir_var_auto), and system values.
+ */
+ assert(0);
+ break;
+ }
+
+ var->data.location = slot;
+ var->data.explicit_location = (slot >= 0);
+ var->data.explicit_index = 1;
+ var->data.index = index;
+
+ /* Once the variable is created an initialized, add it to the symbol table
+ * and add the declaration to the IR stream.
+ */
+ instructions->push_tail(var);
+
+ symtab->add_variable(var);
+ return var;
+}
ir_variable *
builtin_variable_generator::add_variable(const char *name,
@@ -580,6 +627,14 @@ builtin_variable_generator::generate_constants()
add_const("gl_MaxVaryingVectors",
state->ctx->Const.MaxVarying);
}
+
+ /* EXT_blend_func_extended brings a built in constant
+ * for determining number of dual source draw buffers
+ */
+ if (state->EXT_blend_func_extended_enable) {
+ add_const("gl_MaxDualSourceDrawBuffersEXT",
+ state->Const.MaxDualSourceDrawBuffers);
+ }
} else {
add_const("gl_MaxVertexUniformComponents",
state->Const.MaxVertexUniformComponents);
@@ -1016,6 +1071,13 @@ builtin_variable_generator::generate_fs_special_vars()
array(vec4_t, state->Const.MaxDrawBuffers), "gl_FragData");
}
+ if (state->es_shader && state->language_version == 100 && state->EXT_blend_func_extended_enable) {
+ add_index_output(FRAG_RESULT_DATA0, 1, vec4_t, "gl_SecondaryFragColorEXT");
+ add_index_output(FRAG_RESULT_DATA0, 1,
+ array(vec4_t, state->Const.MaxDualSourceDrawBuffers),
+ "gl_SecondaryFragDataEXT");
+ }
+
/* gl_FragDepth has always been in desktop GLSL, but did not appear in GLSL
* ES 1.00.
*/
diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 4636435..40e60e5 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -1463,6 +1463,11 @@ layout_qualifier_id:
}
if (match_layout_qualifier("index", $1, state) == 0) {
+ if (state->es_shader && !state->EXT_blend_func_extended_enable) {
+ _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
+ YYERROR;
+ }
+
$$.flags.q.explicit_index = 1;
if ($3 >= 0) {
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 14cb9fc..31c0319 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -102,6 +102,8 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
+ this->Const.MaxDualSourceDrawBuffers = ctx->Const.MaxDualSourceDrawBuffers;
+
/* 1.50 constants */
this->Const.MaxVertexOutputComponents = ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents;
this->Const.MaxGeometryInputComponents = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxInputComponents;
@@ -643,6 +645,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
EXT(AMD_shader_trinary_minmax, true, false, dummy_true),
EXT(AMD_vertex_shader_layer, true, false, AMD_vertex_shader_layer),
EXT(AMD_vertex_shader_viewport_index, true, false, AMD_vertex_shader_viewport_index),
+ EXT(EXT_blend_func_extended, false, true, ARB_blend_func_extended),
EXT(EXT_draw_buffers, false, true, dummy_true),
EXT(EXT_separate_shader_objects, false, true, dummy_true),
EXT(EXT_shader_integer_mix, true, true, EXT_shader_integer_mix),
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index b54c535..7dd9477 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -375,6 +375,9 @@ struct _mesa_glsl_parse_state {
/* ARB_draw_buffers */
unsigned MaxDrawBuffers;
+ /* ARB_blend_func_extended */
+ unsigned MaxDualSourceDrawBuffers;
+
/* 3.00 ES */
int MinProgramTexelOffset;
int MaxProgramTexelOffset;
@@ -588,6 +591,8 @@ struct _mesa_glsl_parse_state {
bool AMD_vertex_shader_layer_warn;
bool AMD_vertex_shader_viewport_index_enable;
bool AMD_vertex_shader_viewport_index_warn;
+ bool EXT_blend_func_extended_enable;
+ bool EXT_blend_func_extended_warn;
bool EXT_draw_buffers_enable;
bool EXT_draw_buffers_warn;
bool EXT_separate_shader_objects_enable;
diff --git a/src/mapi/glapi/gen/EXT_gpu_shader4.xml b/src/mapi/glapi/gen/EXT_gpu_shader4.xml
index b1f7eae..b4120b9 100644
--- a/src/mapi/glapi/gen/EXT_gpu_shader4.xml
+++ b/src/mapi/glapi/gen/EXT_gpu_shader4.xml
@@ -232,7 +232,8 @@
<param name="params" type="GLuint *"/>
</function>
- <function name="BindFragDataLocationEXT" alias="BindFragDataLocation">
+ <function name="BindFragDataLocationEXT" alias="BindFragDataLocation"
+ es2="3.0">
<param name="program" type="GLuint"/>
<param name="colorNumber" type="GLuint"/>
<param name="name" type="const GLchar *"/>
diff --git a/src/mapi/glapi/gen/es_EXT.xml b/src/mapi/glapi/gen/es_EXT.xml
index 9a777a2..e689b47 100644
--- a/src/mapi/glapi/gen/es_EXT.xml
+++ b/src/mapi/glapi/gen/es_EXT.xml
@@ -914,4 +914,42 @@
</function>
</category>
+<category name="GL_EXT_blend_func_extended" number="247">
+
+ <function name="BindFragDataLocationIndexedEXT" alias="BindFragDataLocationIndexed"
+ es2="3.0">
+ <param name="program" type="GLuint"/>
+ <param name="colorNumber" type="GLuint"/>
+ <param name="index" type="GLuint"/>
+ <param name="name" type="const GLchar *"/>
+ </function>
+
+ <function name="GetFragDataIndexEXT" alias="GetFragDataIndex"
+ es2="3.0">
+ <param name="program" type="GLuint"/>
+ <param name="name" type="const GLchar *"/>
+ <return type="GLint"/>
+ </function>
+
+ <function name="GetProgramResourceLocationIndexEXT" alias="GetProgramResourceLocationIndex"
+ es2="3.1">
+ <param name="program" type="GLuint"/>
+ <param name="programInterface" type="GLenum"/>
+ <param name="name" type="const GLchar *"/>
+ <return type="GLint"/>
+ </function>
+
+ <enum name="SRC1_COLOR_EXT" value="0x88F9"/>
+ <enum name="SRC1_ALPHA_EXT" value="0x8589"/>
+ <enum name="ONE_MINUS_SRC1_COLOR_EXT" value="0x88FA"/>
+ <enum name="ONE_MINUS_SRC1_ALPHA_EXT" value="0x88FB"/>
+ <enum name="SRC_ALPHA_SATURATE_EXT" value="0x0308"/>
+
+ <enum name="LOCATION_INDEX_EXT" value="0x930F"/>
+
+ <enum name="MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT" value="0x88FC">
+ <size name="Get" mode="get"/>
+ </enum>
+
+</category>
</OpenGLAPI>
diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index 20aa498..8da81ee 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -67,7 +67,7 @@ legal_src_factor(const struct gl_context *ctx, GLenum factor)
case GL_SRC1_ALPHA:
case GL_ONE_MINUS_SRC1_COLOR:
case GL_ONE_MINUS_SRC1_ALPHA:
- return _mesa_is_desktop_gl(ctx)
+ return (_mesa_is_desktop_gl(ctx) || ctx->API == API_OPENGLES2)
&& ctx->Extensions.ARB_blend_func_extended;
default:
return GL_FALSE;
@@ -107,7 +107,7 @@ legal_dst_factor(const struct gl_context *ctx, GLenum factor)
case GL_SRC1_ALPHA:
case GL_ONE_MINUS_SRC1_COLOR:
case GL_ONE_MINUS_SRC1_ALPHA:
- return _mesa_is_desktop_gl(ctx)
+ return (_mesa_is_desktop_gl(ctx) || ctx->API == API_OPENGLES2)
&& ctx->Extensions.ARB_blend_func_extended;
default:
return GL_FALSE;
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index bdc6817..f1692ba 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -221,6 +221,7 @@ static const struct extension extension_table[] = {
{ "GL_EXT_bgra", o(dummy_true), GLL, 1995 },
{ "GL_EXT_blend_color", o(EXT_blend_color), GLL, 1995 },
{ "GL_EXT_blend_equation_separate", o(EXT_blend_equation_separate), GL, 2003 },
+ { "GL_EXT_blend_func_extended", o(ARB_blend_func_extended), ES2, 2015 },
{ "GL_EXT_blend_func_separate", o(EXT_blend_func_separate), GLL, 1999 },
{ "GL_EXT_buffer_storage", o(ARB_buffer_storage), ES31, 2015 },
{ "GL_EXT_discard_framebuffer", o(dummy_true), ES1 | ES2, 2009 },
diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
index fbc7b8f..9b22b91 100644
--- a/src/mesa/main/get_hash_params.py
+++ b/src/mesa/main/get_hash_params.py
@@ -330,6 +330,9 @@ descriptor=[
# GL_KHR_context_flush_control
[ "CONTEXT_RELEASE_BEHAVIOR", "CONTEXT_ENUM(Const.ContextReleaseBehavior), NO_EXTRA" ],
+
+# blend_func_extended
+ [ "MAX_DUAL_SOURCE_DRAW_BUFFERS", "CONTEXT_INT(Const.MaxDualSourceDrawBuffers), extra_ARB_blend_func_extended" ],
]},
# GLES3 is not a typo.
@@ -801,7 +804,6 @@ descriptor=[
# GL_ARB_robustness
[ "RESET_NOTIFICATION_STRATEGY_ARB", "CONTEXT_ENUM(Const.ResetStrategy), NO_EXTRA" ],
- [ "MAX_DUAL_SOURCE_DRAW_BUFFERS", "CONTEXT_INT(Const.MaxDualSourceDrawBuffers), extra_ARB_blend_func_extended" ],
# GL_ARB_uniform_buffer_object
[ "MAX_GEOMETRY_UNIFORM_BLOCKS", "CONTEXT_INT(Const.Program[MESA_SHADER_GEOMETRY].MaxUniformBlocks), extra_ARB_uniform_buffer_object_and_geometry_shader" ],
diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp
index abe0f43..97f81f9 100644
--- a/src/mesa/main/tests/dispatch_sanity.cpp
+++ b/src/mesa/main/tests/dispatch_sanity.cpp
@@ -2421,6 +2421,11 @@ const struct function gles3_functions_possible[] = {
{ "glProgramUniform4uiEXT", 30, -1 },
{ "glProgramUniform4uivEXT", 30, -1 },
+ /* GL_EXT_blend_func_extended */
+ { "glBindFragDataLocationIndexedEXT", 30, -1 },
+ { "glGetFragDataIndexEXT", 30, -1 },
+ { "glBindFragDataLocationEXT", 30, -1 },
+
{ NULL, 0, -1 }
};
@@ -2509,5 +2514,8 @@ const struct function gles31_functions_possible[] = {
/* GL_EXT_buffer_storage */
{ "glBufferStorageEXT", 31, -1 },
+ /* GL_EXT_blend_func_extended */
+ { "glGetProgramResourceLocationIndexEXT", 31, -1 },
+
{ NULL, 0, -1 },
};
--
2.5.0
More information about the mesa-dev
mailing list