From 3ff330f7e55dfc1dbd9bacb0972aef47f1be8b00 Mon Sep 17 00:00:00 2001 From: Nicolas Capens Date: Thu, 3 Sep 2015 16:41:09 -0400 Subject: [PATCH] Simplify and centralize multisample counts. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I012bb669444e28f844c5571ff639b31dd1a35e1d Reviewed-on: https://swiftshader-review.googlesource.com/3950 Reviewed-by: Alexis Hétu Reviewed-by: Nicolas Capens Tested-by: Nicolas Capens --- src/OpenGL/libGL/Context.cpp | 22 ++++++++++++---------- src/OpenGL/libGL/Context.h | 6 +++++- src/OpenGL/libGL/Renderbuffer.cpp | 10 ++++------ src/OpenGL/libGL/Texture.h | 1 - src/OpenGL/libGLES_CM/Context.cpp | 18 ++++++++++-------- src/OpenGL/libGLES_CM/Context.h | 6 +++++- src/OpenGL/libGLES_CM/Renderbuffer.cpp | 10 ++++------ src/OpenGL/libGLES_CM/Texture.h | 1 - src/OpenGL/libGLESv2/Context.cpp | 22 ++++++++++++---------- src/OpenGL/libGLESv2/Context.h | 6 +++++- src/OpenGL/libGLESv2/Renderbuffer.cpp | 10 ++++------ src/OpenGL/libGLESv2/Texture.h | 1 - src/OpenGL/libGLESv2/libGLESv3.cpp | 26 +++----------------------- 13 files changed, 64 insertions(+), 75 deletions(-) diff --git a/src/OpenGL/libGL/Context.cpp b/src/OpenGL/libGL/Context.cpp index 0285baaac..5ca3b5eae 100644 --- a/src/OpenGL/libGL/Context.cpp +++ b/src/OpenGL/libGL/Context.cpp @@ -2685,19 +2685,21 @@ GLenum Context::getError() 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/libGL/Context.h b/src/OpenGL/libGL/Context.h index dd0844963..101f07435 100644 --- a/src/OpenGL/libGL/Context.h +++ b/src/OpenGL/libGL/Context.h @@ -335,6 +335,10 @@ const GLenum compressedTextureFormats[] = 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 = 128.0f; const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f; @@ -669,7 +673,7 @@ public: 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/libGL/Renderbuffer.cpp b/src/OpenGL/libGL/Renderbuffer.cpp index 458a69f04..ea65da072 100644 --- a/src/OpenGL/libGL/Renderbuffer.cpp +++ b/src/OpenGL/libGL/Renderbuffer.cpp @@ -336,12 +336,12 @@ Colorbuffer::Colorbuffer(Image *renderTarget) : mRenderTarget(renderTarget) } } -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) { @@ -395,13 +395,11 @@ DepthStencilbuffer::DepthStencilbuffer(Image *depthStencil) : mDepthStencil(dept } } -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/libGL/Texture.h b/src/OpenGL/libGL/Texture.h index 2f8ed28bc..6574d42fe 100644 --- a/src/OpenGL/libGL/Texture.h +++ b/src/OpenGL/libGL/Texture.h @@ -40,7 +40,6 @@ enum 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 }; class Texture : public NamedObject diff --git a/src/OpenGL/libGLES_CM/Context.cpp b/src/OpenGL/libGLES_CM/Context.cpp index 904beacdc..e54ee1669 100644 --- a/src/OpenGL/libGLES_CM/Context.cpp +++ b/src/OpenGL/libGLES_CM/Context.cpp @@ -2941,19 +2941,21 @@ GLenum Context::getError() return GL_NO_ERROR; } -int Context::getSupportedMultiSampleDepth(sw::Format format, int requested) +int Context::getSupportedMultisampleCount(int requested) { - if(requested <= 0) - { - return 0; - } + int supported = 0; - if(requested <= 2) + 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/libGLES_CM/Context.h b/src/OpenGL/libGLES_CM/Context.h index 262caad07..9c03e26a5 100644 --- a/src/OpenGL/libGLES_CM/Context.h +++ b/src/OpenGL/libGLES_CM/Context.h @@ -82,6 +82,10 @@ const GLenum compressedTextureFormats[] = 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; @@ -495,7 +499,7 @@ public: GLenum getError(); - static int getSupportedMultiSampleDepth(sw::Format format, int requested); + static int getSupportedMultisampleCount(int requested); virtual void bindTexImage(egl::Surface *surface); virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel); diff --git a/src/OpenGL/libGLES_CM/Renderbuffer.cpp b/src/OpenGL/libGLES_CM/Renderbuffer.cpp index 2d0d9ed80..fccb011c3 100644 --- a/src/OpenGL/libGLES_CM/Renderbuffer.cpp +++ b/src/OpenGL/libGLES_CM/Renderbuffer.cpp @@ -297,12 +297,12 @@ Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget) } } -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) { @@ -374,13 +374,11 @@ DepthStencilbuffer::DepthStencilbuffer(egl::Image *depthStencil) : mDepthStencil } } -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/libGLES_CM/Texture.h b/src/OpenGL/libGLES_CM/Texture.h index 13501cb69..575126f01 100644 --- a/src/OpenGL/libGLES_CM/Texture.h +++ b/src/OpenGL/libGLES_CM/Texture.h @@ -42,7 +42,6 @@ enum 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 }; class Texture : public egl::Texture diff --git a/src/OpenGL/libGLESv2/Context.cpp b/src/OpenGL/libGLESv2/Context.cpp index 2d1c16b2a..72aa86fe7 100644 --- a/src/OpenGL/libGLESv2/Context.cpp +++ b/src/OpenGL/libGLESv2/Context.cpp @@ -3843,19 +3843,21 @@ GLenum Context::getError() 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 ef7769b69..da624bea6 100644 --- a/src/OpenGL/libGLESv2/Context.h +++ b/src/OpenGL/libGLESv2/Context.h @@ -142,6 +142,10 @@ const GLenum compressedTextureFormats[] = 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 @@ public: 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 99239560b..2f641f647 100644 --- a/src/OpenGL/libGLESv2/Renderbuffer.cpp +++ b/src/OpenGL/libGLESv2/Renderbuffer.cpp @@ -442,12 +442,12 @@ Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget) } } -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(egl::Image *depthStencil) : mDepthStencil } } -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 33123b886..7f0519a45 100644 --- a/src/OpenGL/libGLESv2/Texture.h +++ b/src/OpenGL/libGLESv2/Texture.h @@ -42,7 +42,6 @@ enum 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 0d3bccf90..2e2267857 100644 --- a/src/OpenGL/libGLESv2/libGLESv3.cpp +++ b/src/OpenGL/libGLESv2/libGLESv3.cpp @@ -3968,35 +3968,15 @@ GL_APICALL void GL_APIENTRY glGetInternalformativ(GLenum target, GLenum internal return error(GL_INVALID_ENUM); } - sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(internalformat); - std::vector 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(bufSize, supportedMultiSampleDepths.size()); - for(size_t sampleIndex = 0; sampleIndex < returnCount; ++sampleIndex) - { - params[sampleIndex] = supportedMultiSampleDepths[sampleIndex]; - } + params[i] = multisampleCount[i]; } break; default: -- 2.11.0