summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnuj Phogat <anuj.phogat@gmail.com>2014-05-19 11:55:01 -0700
committerIan Romanick <ian.d.romanick@intel.com>2014-05-23 09:53:42 -0700
commit00f2dcb791bf108669d4d3c809613f81510bf8ba (patch)
tree9940854bb6c6615e97782bda0cee29aa21037c38 /src
parented1ffa0197382253a348e1defcc0b84b0f5865c5 (diff)
meta: Use gl_FragColor to output color values to all the draw buffers
_mesa_meta_setup_blit_shader() currently generates a fragment shader which, irrespective of the number of draw buffers, writes the color to only one 'out' variable. Current shader rely on an undefined behavior and possibly works by chance. From OpenGL 4.0 spec, page 256: "If a fragment shader writes to gl_FragColor, DrawBuffers specifies a set of draw buffers into which the single fragment color defined by gl_FragColor is written. If a fragment shader writes to gl_FragData, or a user-defined varying out variable, DrawBuffers specifies a set of draw buffers into which each of the multiple output colors defined by these variables are separately written. If a fragment shader writes to none of gl_FragColor, gl_FragData, nor any user defined varying out variables, the values of the fragment colors following shader execution are undefined, and may differ for each fragment color." OpenGL 4.4 spec, page 463, added an additional line in this section: "If some, but not all user-defined output variables are written, the values of fragment colors corresponding to unwritten variables are similarly undefined." V2: Write color output to gl_FragColor instead of writing to multiple 'out' variables. This'll avoid recompiling the shader every time draw buffers count is updated. Cc: <mesa-stable@lists.freedesktop.org> Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (cherry picked from commit 46737cebd337200f8b88ba9081796fa0f94e9143)
Diffstat (limited to 'src')
-rw-r--r--src/mesa/drivers/common/meta.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 1b2fe8a764c..fec0d2be541 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -246,7 +246,6 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
void *const mem_ctx = ralloc_context(NULL);
struct blit_shader *shader = choose_blit_shader(target, table);
const char *vs_input, *vs_output, *fs_input, *vs_preprocess, *fs_preprocess;
- const char *fs_output_var, *fs_output_var_decl;
if (ctx->Const.GLSLVersion < 130) {
vs_preprocess = "";
@@ -254,16 +253,12 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
vs_output = "varying";
fs_preprocess = "#extension GL_EXT_texture_array : enable";
fs_input = "varying";
- fs_output_var_decl = "";
- fs_output_var = "gl_FragColor";
} else {
vs_preprocess = "#version 130";
vs_input = "in";
vs_output = "out";
fs_preprocess = "#version 130";
fs_input = "in";
- fs_output_var_decl = "out vec4 out_color;";
- fs_output_var = "out_color";
shader->func = "texture";
}
@@ -291,15 +286,13 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
"#extension GL_ARB_texture_cube_map_array: enable\n"
"uniform %s texSampler;\n"
"%s vec4 texCoords;\n"
- "%s\n"
"void main()\n"
"{\n"
- " vec4 color = %s(texSampler, %s);\n"
- " %s = color;\n"
- " gl_FragDepth = color.x;\n"
+ " gl_FragColor = %s(texSampler, %s);\n"
+ " gl_FragDepth = gl_FragColor.x;\n"
"}\n",
- fs_preprocess, shader->type, fs_input, fs_output_var_decl,
- shader->func, shader->texcoords, fs_output_var);
+ fs_preprocess, shader->type, fs_input,
+ shader->func, shader->texcoords);
_mesa_meta_compile_and_link_program(ctx, vs_source, fs_source,
ralloc_asprintf(mem_ctx, "%s blit",