Primitive restart fixed SwiftShader wasn't correctly handling having no restart indices in the index buffer while having primitive restart enabled. In the WebGL 2 conformance tests, the reference image is also computed while primitive restart is on, which means that Context::drawElements() may modify the internal primitive type, so indices must be adjusted to reflect that change, even if no restart indices are present in the index buffer. Fixes all WebGL 2 tests in: all/deqp/functional/gles3/primitiverestart Change-Id: I24f129e0f7bd42b5037b74617b48a32621440ddb Reviewed-on: https://swiftshader-review.googlesource.com/16548 Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/OpenGL/libGLESv2/IndexDataManager.cpp b/src/OpenGL/libGLESv2/IndexDataManager.cpp index a32b7d1..55c15b2 100644 --- a/src/OpenGL/libGLESv2/IndexDataManager.cpp +++ b/src/OpenGL/libGLESv2/IndexDataManager.cpp
@@ -65,7 +65,8 @@ inline GLsizei getNumIndices(const std::vector<GLsizei>& restartIndices, size_t i, GLsizei count) { - return (i == 0) ? restartIndices[0] : ((i == restartIndices.size()) ? (count - restartIndices[i - 1] - 1) : (restartIndices[i] - restartIndices[i - 1] - 1)); + return restartIndices.empty() ? count : + ((i == 0) ? restartIndices[0] : ((i == restartIndices.size()) ? (count - restartIndices[i - 1] - 1) : (restartIndices[i] - restartIndices[i - 1] - 1))); } void copyIndices(GLenum mode, GLenum type, const std::vector<GLsizei>& restartIndices, const void *input, GLsizei count, void* output) @@ -290,11 +291,6 @@ std::vector<GLsizei>* restartIndices = primitiveRestart ? new std::vector<GLsizei>() : nullptr; computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex, restartIndices); - if(restartIndices && restartIndices->empty()) - { - delete restartIndices; - restartIndices = nullptr; - } StreamingIndexBuffer *streamingBuffer = mStreamingBuffer;