<div dir="ltr">On 20 November 2013 14:29, Paul Berry <span dir="ltr"><<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">From section 4.4.7 (Layered Framebuffers) of the GLSL 3.2 spec:<br>
<br>
When the Clear or ClearBuffer* commands are used to clear a<br>
layered framebuffer attachment, all layers of the attachment are<br>
cleared.<br>
<br>
This patch fixes meta clears to properly clear all layers of a layered<br>
framebuffer attachment. We accomplish this by adding a geometry<br>
shader to the meta clear program which sets gl_Layer to a uniform<br>
value. When clearing a layered framebuffer, we execute in a loop,<br>
setting the uniform to point to each layer in turn.<br>
<br>
Cc: "10.0" <<a href="mailto:mesa-stable@lists.freedesktop.org">mesa-stable@lists.freedesktop.org</a>><br></div></blockquote><div><br></div><div>I had previously asked for us *not* to cherry-pick this back to stable, because it caused bug 71870 to turn into a crash.<br>
<br>That issue has now been addressed by commit 2714ca8 (i965/gs: Properly skip GS binding table upload when no GS active.) Once commit 2714ca8 has been cherry-picked to 10.0, it should be safe to cherry pick this commit (068a073) to 10.0.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">
---<br>
src/mesa/drivers/common/meta.c | 51 +++++++++++++++++++++++++++++++++++++++---<br>
1 file changed, 48 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c<br>
</div>index 99b02ba..0c05cc0 100644<br>
<div><div class="h5">--- a/src/mesa/drivers/common/meta.c<br>
+++ b/src/mesa/drivers/common/meta.c<br>
@@ -241,9 +241,11 @@ struct clear_state<br>
GLuint VBO;<br>
GLuint ShaderProg;<br>
GLint ColorLocation;<br>
+ GLint LayerLocation;<br>
<br>
GLuint IntegerShaderProg;<br>
GLint IntegerColorLocation;<br>
+ GLint IntegerLayerLocation;<br>
};<br>
<br>
<br>
@@ -2145,6 +2147,19 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear)<br>
"{\n"<br>
" gl_Position = position;\n"<br>
"}\n";<br>
+ const char *gs_source =<br>
+ "#version 150\n"<br>
+ "layout(triangles) in;\n"<br>
+ "layout(triangle_strip, max_vertices = 4) out;\n"<br>
+ "uniform int layer;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " for (int i = 0; i < 3; i++) {\n"<br>
+ " gl_Layer = layer;\n"<br>
+ " gl_Position = gl_in[i].gl_Position;\n"<br>
+ " EmitVertex();\n"<br>
+ " }\n"<br>
+ "}\n";<br>
const char *fs_source =<br>
"#ifdef GL_ES\n"<br>
"precision highp float;\n"<br>
@@ -2154,7 +2169,7 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear)<br>
"{\n"<br>
" gl_FragColor = color;\n"<br>
"}\n";<br>
- GLuint vs, fs;<br>
+ GLuint vs, gs = 0, fs;<br>
bool has_integer_textures;<br>
<br>
if (clear->ArrayObj != 0)<br>
@@ -2176,6 +2191,12 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear)<br>
_mesa_ShaderSource(vs, 1, &vs_source, NULL);<br>
_mesa_CompileShader(vs);<br>
<br>
+ if (_mesa_has_geometry_shaders(ctx)) {<br>
+ gs = _mesa_CreateShaderObjectARB(GL_GEOMETRY_SHADER);<br>
+ _mesa_ShaderSource(gs, 1, &gs_source, NULL);<br>
+ _mesa_CompileShader(gs);<br>
+ }<br>
+<br>
fs = _mesa_CreateShaderObjectARB(GL_FRAGMENT_SHADER);<br>
_mesa_ShaderSource(fs, 1, &fs_source, NULL);<br>
_mesa_CompileShader(fs);<br>
@@ -2183,6 +2204,8 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear)<br>
clear->ShaderProg = _mesa_CreateProgramObjectARB();<br>
_mesa_AttachShader(clear->ShaderProg, fs);<br>
_mesa_DeleteObjectARB(fs);<br>
+ if (gs != 0)<br>
+ _mesa_AttachShader(clear->ShaderProg, gs);<br>
_mesa_AttachShader(clear->ShaderProg, vs);<br>
_mesa_DeleteObjectARB(vs);<br>
_mesa_BindAttribLocation(clear->ShaderProg, 0, "position");<br>
@@ -2190,6 +2213,10 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear)<br>
<br>
clear->ColorLocation = _mesa_GetUniformLocation(clear->ShaderProg,<br>
"color");<br>
+ if (gs != 0) {<br>
+ clear->LayerLocation = _mesa_GetUniformLocation(clear->ShaderProg,<br>
+ "layer");<br>
+ }<br>
<br>
has_integer_textures = _mesa_is_gles3(ctx) ||<br>
(_mesa_is_desktop_gl(ctx) && ctx->Const.GLSLVersion >= 130);<br>
@@ -2227,6 +2254,8 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear)<br>
clear->IntegerShaderProg = _mesa_CreateProgramObjectARB();<br>
_mesa_AttachShader(clear->IntegerShaderProg, fs);<br>
_mesa_DeleteObjectARB(fs);<br>
+ if (gs != 0)<br>
+ _mesa_AttachShader(clear->IntegerShaderProg, gs);<br>
_mesa_AttachShader(clear->IntegerShaderProg, vs);<br>
_mesa_DeleteObjectARB(vs);<br>
_mesa_BindAttribLocation(clear->IntegerShaderProg, 0, "position");<br>
@@ -2240,7 +2269,13 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear)<br>
<br>
clear->IntegerColorLocation =<br>
_mesa_GetUniformLocation(clear->IntegerShaderProg, "color");<br>
+ if (gs != 0) {<br>
+ clear->IntegerLayerLocation =<br>
+ _mesa_GetUniformLocation(clear->IntegerShaderProg, "layer");<br>
+ }<br>
}<br>
+ if (gs != 0)<br>
+ _mesa_DeleteObjectARB(gs);<br>
}<br>
<br>
static void<br>
@@ -2371,8 +2406,18 @@ _mesa_meta_glsl_Clear(struct gl_context *ctx, GLbitfield buffers)<br>
_mesa_BufferData(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts,<br>
GL_DYNAMIC_DRAW_ARB);<br>
<br>
- /* draw quad */<br>
- _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);<br>
+ /* draw quad(s) */<br>
</div></div>+ if (fb->NumLayers > 0) {<br>
<div class=""><div class="h5">+ for (unsigned layer = 0; layer < fb->NumLayers; layer++) {<br>
+ if (fb->_IntegerColor)<br>
+ _mesa_Uniform1i(clear->IntegerLayerLocation, layer);<br>
+ else<br>
+ _mesa_Uniform1i(clear->LayerLocation, layer);<br>
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);<br>
+ }<br>
+ } else {<br>
+ _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);<br>
+ }<br>
<br>
_mesa_meta_end(ctx);<br>
}<br>
--<br>
1.8.4.2<br>
<br>
</div></div></blockquote></div><br></div></div>