OSDN Git Service

Simplify and centralize multisample counts.
authorNicolas Capens <capn@google.com>
Thu, 3 Sep 2015 20:41:09 +0000 (16:41 -0400)
committerNicolas Capens <capn@google.com>
Thu, 3 Sep 2015 21:34:36 +0000 (21:34 +0000)
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>
13 files changed:
src/OpenGL/libGL/Context.cpp
src/OpenGL/libGL/Context.h
src/OpenGL/libGL/Renderbuffer.cpp
src/OpenGL/libGL/Texture.h
src/OpenGL/libGLES_CM/Context.cpp
src/OpenGL/libGLES_CM/Context.h
src/OpenGL/libGLES_CM/Renderbuffer.cpp
src/OpenGL/libGLES_CM/Texture.h
src/OpenGL/libGLESv2/Context.cpp
src/OpenGL/libGLESv2/Context.h
src/OpenGL/libGLESv2/Renderbuffer.cpp
src/OpenGL/libGLESv2/Texture.h
src/OpenGL/libGLESv2/libGLESv3.cpp

index 0285baa..5ca3b5e 100644 (file)
@@ -2685,19 +2685,21 @@ GLenum Context::getError()
     return GL_NO_ERROR;\r
 }\r
 \r
-int Context::getSupportedMultiSampleDepth(sw::Format format, int requested)\r
+int Context::getSupportedMultisampleCount(int requested)\r
 {\r
-    if(requested <= 0)\r
-    {\r
-        return 0;\r
-    }\r
-       \r
-       if(requested <= 2)\r
+       int supported = 0;\r
+\r
+       for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--)\r
        {\r
-               return requested;\r
+               if(supported >= requested)\r
+               {\r
+                       return supported;\r
+               }\r
+\r
+               supported = multisampleCount[i];\r
        }\r
-       \r
-       return 4;\r
+\r
+       return supported;\r
 }\r
 \r
 void Context::detachBuffer(GLuint buffer)\r
index dd08449..101f074 100644 (file)
@@ -335,6 +335,10 @@ const GLenum compressedTextureFormats[] =
 \r
 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);\r
 \r
+const GLint multisampleCount[] = {4, 2, 1};\r
+const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);\r
+const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];\r
+\r
 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;\r
 const float ALIASED_LINE_WIDTH_RANGE_MAX = 128.0f;\r
 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;\r
@@ -669,7 +673,7 @@ public:
 \r
     GLenum getError();\r
 \r
-    static int getSupportedMultiSampleDepth(sw::Format format, int requested);\r
+    static int getSupportedMultisampleCount(int requested);\r
     \r
     void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, \r
                          GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,\r
index 458a69f..ea65da0 100644 (file)
@@ -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)
        {
index 2f8ed28..6574d42 100644 (file)
@@ -40,7 +40,6 @@ enum
     IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),\r
     IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),\r
        IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION,\r
-       IMPLEMENTATION_MAX_SAMPLES = 4\r
 };\r
 \r
 class Texture : public NamedObject\r
index 904beac..e54ee16 100644 (file)
@@ -2941,19 +2941,21 @@ GLenum Context::getError()
     return GL_NO_ERROR;\r
 }\r
 \r
-int Context::getSupportedMultiSampleDepth(sw::Format format, int requested)\r
+int Context::getSupportedMultisampleCount(int requested)\r
 {\r
-    if(requested <= 0)\r
-    {\r
-        return 0;\r
-    }\r
+       int supported = 0;\r
 \r
-       if(requested <= 2)\r
+       for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--)\r
        {\r
-               return requested;\r
+               if(supported >= requested)\r
+               {\r
+                       return supported;\r
+               }\r
+\r
+               supported = multisampleCount[i];\r
        }\r
 \r
-       return 4;\r
+       return supported;\r
 }\r
 \r
 void Context::detachBuffer(GLuint buffer)\r
index 262caad..9c03e26 100644 (file)
@@ -82,6 +82,10 @@ const GLenum compressedTextureFormats[] =
 \r
 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);\r
 \r
+const GLint multisampleCount[] = {4, 2, 1};\r
+const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);\r
+const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];\r
+\r
 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;\r
 const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;\r
 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;\r
@@ -495,7 +499,7 @@ public:
 \r
     GLenum getError();\r
 \r
-    static int getSupportedMultiSampleDepth(sw::Format format, int requested);\r
+    static int getSupportedMultisampleCount(int requested);\r
 \r
        virtual void bindTexImage(egl::Surface *surface);\r
        virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);\r
index 2d0d9ed..fccb011 100644 (file)
@@ -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)
        {
index 13501cb..575126f 100644 (file)
@@ -42,7 +42,6 @@ enum
     IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),\r
     IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),\r
        IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION,\r
-       IMPLEMENTATION_MAX_SAMPLES = 4\r
 };\r
 \r
 class Texture : public egl::Texture\r
index 2d1c16b..72aa86f 100644 (file)
@@ -3843,19 +3843,21 @@ GLenum Context::getError()
     return GL_NO_ERROR;\r
 }\r
 \r
-int Context::getSupportedMultiSampleDepth(sw::Format format, int requested)\r
+int Context::getSupportedMultisampleCount(int requested)\r
 {\r
-    if(requested <= 0)\r
-    {\r
-        return 0;\r
-    }\r
-       \r
-       if(requested <= 2)\r
+       int supported = 0;\r
+\r
+       for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--)\r
        {\r
-               return requested;\r
+               if(supported >= requested)\r
+               {\r
+                       return supported;\r
+               }\r
+\r
+               supported = multisampleCount[i];\r
        }\r
-       \r
-       return 4;\r
+\r
+       return supported;\r
 }\r
 \r
 void Context::detachBuffer(GLuint buffer)\r
index ef7769b..da624be 100644 (file)
@@ -142,6 +142,10 @@ const GLenum compressedTextureFormats[] =
 \r
 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);\r
 \r
+const GLint multisampleCount[] = {4, 2, 1};\r
+const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);\r
+const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];\r
+\r
 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;\r
 const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;\r
 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;\r
@@ -651,7 +655,7 @@ public:
 \r
     GLenum getError();\r
 \r
-    static int getSupportedMultiSampleDepth(sw::Format format, int requested);\r
+    static int getSupportedMultisampleCount(int requested);\r
     \r
     void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, \r
                          GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,\r
index 9923956..2f641f6 100644 (file)
@@ -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)
        {
index 33123b8..7f0519a 100644 (file)
@@ -42,7 +42,6 @@ enum
     IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),\r
     IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),\r
        IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION,\r
-       IMPLEMENTATION_MAX_SAMPLES = 4,\r
        IMPLEMENTATION_MAX_COLOR_ATTACHMENTS = MAX_COLOR_ATTACHMENTS,\r
        IMPLEMENTATION_MAX_DRAW_BUFFERS = 8,\r
        IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,\r
index 0d3bccf..2e22678 100644 (file)
@@ -3968,35 +3968,15 @@ GL_APICALL void GL_APIENTRY glGetInternalformativ(GLenum target, GLenum internal
                return error(GL_INVALID_ENUM);\r
        }\r
 \r
-       sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(internalformat);\r
-       std::vector<GLint> supportedMultiSampleDepths;\r
-       int maxDepth = Context::getSupportedMultiSampleDepth(requestedFormat, INT_MAX);\r
-       for(int depth = maxDepth; depth > 1;)\r
-       {\r
-               supportedMultiSampleDepths.push_back(depth);\r
-               for(int nextDepth = depth - 1; nextDepth >= 0; --nextDepth)\r
-               {\r
-                       int supportedDepth = Context::getSupportedMultiSampleDepth(requestedFormat, nextDepth);\r
-                       if(supportedDepth != depth)\r
-                       {\r
-                               depth = supportedDepth;\r
-                               break;\r
-                       }\r
-               }\r
-       }\r
-\r
        switch(pname)\r
        {\r
        case GL_NUM_SAMPLE_COUNTS:\r
-               *params = supportedMultiSampleDepths.size();\r
+               *params = NUM_MULTISAMPLE_COUNTS;\r
                break;\r
        case GL_SAMPLES:\r
+               for(int i = 0; i < NUM_MULTISAMPLE_COUNTS && i < bufSize; i++)\r
                {\r
-                       size_t returnCount = std::min<size_t>(bufSize, supportedMultiSampleDepths.size());\r
-                       for(size_t sampleIndex = 0; sampleIndex < returnCount; ++sampleIndex)\r
-                       {\r
-                               params[sampleIndex] = supportedMultiSampleDepths[sampleIndex];\r
-                       }\r
+                       params[i] = multisampleCount[i];\r
                }\r
                break;\r
        default:\r