Commit 3ff330f7 by Nicolas Capens

Simplify and centralize multisample counts.

Change-Id: I012bb669444e28f844c5571ff639b31dd1a35e1d Reviewed-on: https://swiftshader-review.googlesource.com/3950Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 5767099d
...@@ -2685,19 +2685,21 @@ GLenum Context::getError() ...@@ -2685,19 +2685,21 @@ GLenum Context::getError()
return GL_NO_ERROR; return GL_NO_ERROR;
} }
int Context::getSupportedMultiSampleDepth(sw::Format format, int requested) int Context::getSupportedMultisampleCount(int requested)
{ {
if(requested <= 0) int supported = 0;
{
return 0; for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--)
}
if(requested <= 2)
{ {
return requested; if(supported >= requested)
{
return supported;
}
supported = multisampleCount[i];
} }
return 4; return supported;
} }
void Context::detachBuffer(GLuint buffer) void Context::detachBuffer(GLuint buffer)
......
...@@ -335,6 +335,10 @@ const GLenum compressedTextureFormats[] = ...@@ -335,6 +335,10 @@ const GLenum compressedTextureFormats[] =
const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]); 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_MIN = 1.0f;
const float ALIASED_LINE_WIDTH_RANGE_MAX = 128.0f; const float ALIASED_LINE_WIDTH_RANGE_MAX = 128.0f;
const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f; const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
...@@ -669,7 +673,7 @@ public: ...@@ -669,7 +673,7 @@ public:
GLenum getError(); 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, void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
......
...@@ -336,12 +336,12 @@ Colorbuffer::Colorbuffer(Image *renderTarget) : mRenderTarget(renderTarget) ...@@ -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(); Device *device = getDevice();
sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format); sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format);
int supportedSamples = Context::getSupportedMultiSampleDepth(requestedFormat, samples); int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0) if(width > 0 && height > 0)
{ {
...@@ -395,13 +395,11 @@ DepthStencilbuffer::DepthStencilbuffer(Image *depthStencil) : mDepthStencil(dept ...@@ -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(); Device *device = getDevice();
mDepthStencil = NULL; int supportedSamples = Context::getSupportedMultisampleCount(samples);
int supportedSamples = Context::getSupportedMultiSampleDepth(sw::FORMAT_D24S8, samples);
if(width > 0 && height > 0) if(width > 0 && height > 0)
{ {
......
...@@ -40,7 +40,6 @@ enum ...@@ -40,7 +40,6 @@ enum
IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1), IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1), IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION, IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION,
IMPLEMENTATION_MAX_SAMPLES = 4
}; };
class Texture : public NamedObject class Texture : public NamedObject
......
...@@ -2941,19 +2941,21 @@ GLenum Context::getError() ...@@ -2941,19 +2941,21 @@ GLenum Context::getError()
return GL_NO_ERROR; return GL_NO_ERROR;
} }
int Context::getSupportedMultiSampleDepth(sw::Format format, int requested) int Context::getSupportedMultisampleCount(int requested)
{ {
if(requested <= 0) int supported = 0;
{
return 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) void Context::detachBuffer(GLuint buffer)
......
...@@ -82,6 +82,10 @@ const GLenum compressedTextureFormats[] = ...@@ -82,6 +82,10 @@ const GLenum compressedTextureFormats[] =
const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]); 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_MIN = 1.0f;
const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f; const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f; const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
...@@ -495,7 +499,7 @@ public: ...@@ -495,7 +499,7 @@ public:
GLenum getError(); GLenum getError();
static int getSupportedMultiSampleDepth(sw::Format format, int requested); static int getSupportedMultisampleCount(int requested);
virtual void bindTexImage(egl::Surface *surface); virtual void bindTexImage(egl::Surface *surface);
virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel); virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
......
...@@ -297,12 +297,12 @@ Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget) ...@@ -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(); Device *device = getDevice();
sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format); sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format);
int supportedSamples = Context::getSupportedMultiSampleDepth(requestedFormat, samples); int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0) if(width > 0 && height > 0)
{ {
...@@ -374,13 +374,11 @@ DepthStencilbuffer::DepthStencilbuffer(egl::Image *depthStencil) : mDepthStencil ...@@ -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(); Device *device = getDevice();
mDepthStencil = NULL;
int supportedSamples = Context::getSupportedMultiSampleDepth(sw::FORMAT_D24S8, samples); int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0) if(width > 0 && height > 0)
{ {
......
...@@ -42,7 +42,6 @@ enum ...@@ -42,7 +42,6 @@ enum
IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1), IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1), IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION, IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION,
IMPLEMENTATION_MAX_SAMPLES = 4
}; };
class Texture : public egl::Texture class Texture : public egl::Texture
......
...@@ -3843,19 +3843,21 @@ GLenum Context::getError() ...@@ -3843,19 +3843,21 @@ GLenum Context::getError()
return GL_NO_ERROR; return GL_NO_ERROR;
} }
int Context::getSupportedMultiSampleDepth(sw::Format format, int requested) int Context::getSupportedMultisampleCount(int requested)
{ {
if(requested <= 0) int supported = 0;
{
return 0; for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--)
}
if(requested <= 2)
{ {
return requested; if(supported >= requested)
{
return supported;
}
supported = multisampleCount[i];
} }
return 4; return supported;
} }
void Context::detachBuffer(GLuint buffer) void Context::detachBuffer(GLuint buffer)
......
...@@ -142,6 +142,10 @@ const GLenum compressedTextureFormats[] = ...@@ -142,6 +142,10 @@ const GLenum compressedTextureFormats[] =
const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]); 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_MIN = 1.0f;
const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f; const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f; const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
...@@ -651,7 +655,7 @@ public: ...@@ -651,7 +655,7 @@ public:
GLenum getError(); 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, void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
......
...@@ -442,12 +442,12 @@ Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget) ...@@ -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(); Device *device = getDevice();
sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format); sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format);
int supportedSamples = Context::getSupportedMultiSampleDepth(requestedFormat, samples); int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0) if(width > 0 && height > 0)
{ {
...@@ -519,13 +519,11 @@ DepthStencilbuffer::DepthStencilbuffer(egl::Image *depthStencil) : mDepthStencil ...@@ -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(); Device *device = getDevice();
mDepthStencil = NULL; int supportedSamples = Context::getSupportedMultisampleCount(samples);
int supportedSamples = Context::getSupportedMultiSampleDepth(sw::FORMAT_D24S8, samples);
if(width > 0 && height > 0) if(width > 0 && height > 0)
{ {
......
...@@ -42,7 +42,6 @@ enum ...@@ -42,7 +42,6 @@ enum
IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1), IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1), IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION, IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION,
IMPLEMENTATION_MAX_SAMPLES = 4,
IMPLEMENTATION_MAX_COLOR_ATTACHMENTS = MAX_COLOR_ATTACHMENTS, IMPLEMENTATION_MAX_COLOR_ATTACHMENTS = MAX_COLOR_ATTACHMENTS,
IMPLEMENTATION_MAX_DRAW_BUFFERS = 8, IMPLEMENTATION_MAX_DRAW_BUFFERS = 8,
IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
......
...@@ -3968,35 +3968,15 @@ GL_APICALL void GL_APIENTRY glGetInternalformativ(GLenum target, GLenum internal ...@@ -3968,35 +3968,15 @@ GL_APICALL void GL_APIENTRY glGetInternalformativ(GLenum target, GLenum internal
return error(GL_INVALID_ENUM); 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) switch(pname)
{ {
case GL_NUM_SAMPLE_COUNTS: case GL_NUM_SAMPLE_COUNTS:
*params = supportedMultiSampleDepths.size(); *params = NUM_MULTISAMPLE_COUNTS;
break; break;
case GL_SAMPLES: case GL_SAMPLES:
for(int i = 0; i < NUM_MULTISAMPLE_COUNTS && i < bufSize; i++)
{ {
size_t returnCount = std::min<size_t>(bufSize, supportedMultiSampleDepths.size()); params[i] = multisampleCount[i];
for(size_t sampleIndex = 0; sampleIndex < returnCount; ++sampleIndex)
{
params[sampleIndex] = supportedMultiSampleDepths[sampleIndex];
}
} }
break; break;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment