Fix out-of-bounds buffer access in tese ShaderExecutor
authorPyry Haulos <phaulos@google.com>
Thu, 3 Sep 2015 15:41:09 +0000 (08:41 -0700)
committerPyry Haulos <phaulos@google.com>
Thu, 3 Sep 2015 15:41:09 +0000 (08:41 -0700)
Tessellation evaluation shader executor was accessing input and output
buffers one element out of bounds at the end. In addition elements
1..N-1 were evaluated twice unnecessarily.

Bug: 23684915
Change-Id: I1c187b506d36befe05b21222a7006e84b812ceca

modules/glshared/glsShaderExecUtil.cpp

index fad4d71..9e324fd 100644 (file)
@@ -1480,7 +1480,7 @@ std::string TessEvaluationExecutor::generateTessEvalShader (const ShaderSpec& sh
 
        src << "void main (void)\n{\n"
                << "\tgl_Position = vec4(gl_TessCoord.x, 0.0, 0.0, 1.0);\n"
-               << "\thighp uint invocationId = uint(gl_PrimitiveID) + (gl_TessCoord.x > 0.5 ? 1u : 0u);\n";
+               << "\thighp uint invocationId = uint(gl_PrimitiveID)*2u + (gl_TessCoord.x > 0.5 ? 1u : 0u);\n";
 
        generateExecBufferIo(src, shaderSpec, "invocationId");
 
@@ -1523,7 +1523,7 @@ void TessEvaluationExecutor::execute (int numValues, const void* const* inputs,
 
        // Render patches
        gl.patchParameteri(GL_PATCH_VERTICES, 2);
-       gl.drawArrays(GL_PATCHES, 0, 2*alignedValues);
+       gl.drawArrays(GL_PATCHES, 0, alignedValues);
 
        // Read back data
        readOutputBuffer(outputs, numValues);