Simplify and centralize multisample counts. Change-Id: I012bb669444e28f844c5571ff639b31dd1a35e1d Reviewed-on: https://swiftshader-review.googlesource.com/3950 Reviewed-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Nicolas Capens <capn@google.com> Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLESv2/Context.cpp b/src/OpenGL/libGLESv2/Context.cpp index 2d1c16b..72aa86f 100644 --- a/src/OpenGL/libGLESv2/Context.cpp +++ b/src/OpenGL/libGLESv2/Context.cpp
@@ -3843,19 +3843,21 @@ return GL_NO_ERROR; } -int Context::getSupportedMultiSampleDepth(sw::Format format, int requested) +int Context::getSupportedMultisampleCount(int requested) { - if(requested <= 0) - { - return 0; - } - - if(requested <= 2) + int supported = 0; + + for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--) { - return requested; + if(supported >= requested) + { + return supported; + } + + supported = multisampleCount[i]; } - - return 4; + + return supported; } void Context::detachBuffer(GLuint buffer)
diff --git a/src/OpenGL/libGLESv2/Context.h b/src/OpenGL/libGLESv2/Context.h index ef7769b..da624be 100644 --- a/src/OpenGL/libGLESv2/Context.h +++ b/src/OpenGL/libGLESv2/Context.h
@@ -142,6 +142,10 @@ const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]); +const GLint multisampleCount[] = {4, 2, 1}; +const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]); +const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0]; + const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f; const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f; const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f; @@ -651,7 +655,7 @@ GLenum getError(); - static int getSupportedMultiSampleDepth(sw::Format format, int requested); + static int getSupportedMultisampleCount(int requested); void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
diff --git a/src/OpenGL/libGLESv2/Renderbuffer.cpp b/src/OpenGL/libGLESv2/Renderbuffer.cpp index 9923956..2f641f6 100644 --- a/src/OpenGL/libGLESv2/Renderbuffer.cpp +++ b/src/OpenGL/libGLESv2/Renderbuffer.cpp
@@ -442,12 +442,12 @@ } } -Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(NULL) +Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(nullptr) { Device *device = getDevice(); sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format); - int supportedSamples = Context::getSupportedMultiSampleDepth(requestedFormat, samples); + int supportedSamples = Context::getSupportedMultisampleCount(samples); if(width > 0 && height > 0) { @@ -519,13 +519,11 @@ } } -DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) +DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) : mDepthStencil(nullptr) { Device *device = getDevice(); - mDepthStencil = NULL; - - int supportedSamples = Context::getSupportedMultiSampleDepth(sw::FORMAT_D24S8, samples); + int supportedSamples = Context::getSupportedMultisampleCount(samples); if(width > 0 && height > 0) {
diff --git a/src/OpenGL/libGLESv2/Texture.h b/src/OpenGL/libGLESv2/Texture.h index 33123b8..7f0519a 100644 --- a/src/OpenGL/libGLESv2/Texture.h +++ b/src/OpenGL/libGLESv2/Texture.h
@@ -42,7 +42,6 @@ IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1), IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1), IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION, - IMPLEMENTATION_MAX_SAMPLES = 4, IMPLEMENTATION_MAX_COLOR_ATTACHMENTS = MAX_COLOR_ATTACHMENTS, IMPLEMENTATION_MAX_DRAW_BUFFERS = 8, IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
diff --git a/src/OpenGL/libGLESv2/libGLESv3.cpp b/src/OpenGL/libGLESv2/libGLESv3.cpp index 0d3bccf..2e22678 100644 --- a/src/OpenGL/libGLESv2/libGLESv3.cpp +++ b/src/OpenGL/libGLESv2/libGLESv3.cpp
@@ -3968,35 +3968,15 @@ return error(GL_INVALID_ENUM); } - sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(internalformat); - std::vector<GLint> supportedMultiSampleDepths; - int maxDepth = Context::getSupportedMultiSampleDepth(requestedFormat, INT_MAX); - for(int depth = maxDepth; depth > 1;) - { - supportedMultiSampleDepths.push_back(depth); - for(int nextDepth = depth - 1; nextDepth >= 0; --nextDepth) - { - int supportedDepth = Context::getSupportedMultiSampleDepth(requestedFormat, nextDepth); - if(supportedDepth != depth) - { - depth = supportedDepth; - break; - } - } - } - switch(pname) { case GL_NUM_SAMPLE_COUNTS: - *params = supportedMultiSampleDepths.size(); + *params = NUM_MULTISAMPLE_COUNTS; break; case GL_SAMPLES: + for(int i = 0; i < NUM_MULTISAMPLE_COUNTS && i < bufSize; i++) { - size_t returnCount = std::min<size_t>(bufSize, supportedMultiSampleDepths.size()); - for(size_t sampleIndex = 0; sampleIndex < returnCount; ++sampleIndex) - { - params[sampleIndex] = supportedMultiSampleDepths[sampleIndex]; - } + params[i] = multisampleCount[i]; } break; default: