Commit 17a4b6e7 by Qin Jiajia Committed by Angle LUCI CQ

Fix that clear-srgb-color-buffer is not correct

This change removes the limitation that syncClearState/ syncClearBufferState is only for STANDARD_GL_DESKTOP so that it works on chromeos. Test: conformance2/rendering/clear-srgb-color-buffer.html deqp/functional/gles3/fbocolorbuffer/clear.html Bug: chromium:1208297 Change-Id: I7c5fed3545f623cca3f2245c67fddaf3401388b5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3010630Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
parent b73eee71
...@@ -1379,32 +1379,27 @@ bool FramebufferGL::hasEmulatedAlphaChannelTextureAttachment() const ...@@ -1379,32 +1379,27 @@ bool FramebufferGL::hasEmulatedAlphaChannelTextureAttachment() const
void FramebufferGL::syncClearState(const gl::Context *context, GLbitfield mask) void FramebufferGL::syncClearState(const gl::Context *context, GLbitfield mask)
{ {
const FunctionsGL *functions = GetFunctionsGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
if (functions->standard == STANDARD_GL_DESKTOP) if (features.doesSRGBClearsOnLinearFramebufferAttachments.enabled &&
(mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault)
{ {
StateManagerGL *stateManager = GetStateManagerGL(context); bool hasSRGBAttachment = false;
const angle::FeaturesGL &features = GetFeaturesGL(context); for (const auto &attachment : mState.getColorAttachments())
if (features.doesSRGBClearsOnLinearFramebufferAttachments.enabled &&
(mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault)
{ {
bool hasSRGBAttachment = false; if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB)
for (const auto &attachment : mState.getColorAttachments())
{ {
if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB) hasSRGBAttachment = true;
{ break;
hasSRGBAttachment = true;
break;
}
} }
stateManager->setFramebufferSRGBEnabled(context, hasSRGBAttachment);
}
else
{
stateManager->setFramebufferSRGBEnabled(context, !mIsDefault);
} }
stateManager->setFramebufferSRGBEnabled(context, hasSRGBAttachment);
}
else
{
stateManager->setFramebufferSRGBEnabled(context, !mIsDefault);
} }
} }
...@@ -1412,41 +1407,36 @@ void FramebufferGL::syncClearBufferState(const gl::Context *context, ...@@ -1412,41 +1407,36 @@ void FramebufferGL::syncClearBufferState(const gl::Context *context,
GLenum buffer, GLenum buffer,
GLint drawBuffer) GLint drawBuffer)
{ {
const FunctionsGL *functions = GetFunctionsGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
if (functions->standard == STANDARD_GL_DESKTOP) if (features.doesSRGBClearsOnLinearFramebufferAttachments.enabled && buffer == GL_COLOR &&
!mIsDefault)
{ {
StateManagerGL *stateManager = GetStateManagerGL(context); // If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer
const angle::FeaturesGL &features = GetFeaturesGL(context); // is an SRGB format.
const auto &drawbufferState = mState.getDrawBufferStates();
if (features.doesSRGBClearsOnLinearFramebufferAttachments.enabled && buffer == GL_COLOR && const auto &colorAttachments = mState.getColorAttachments();
!mIsDefault)
const FramebufferAttachment *attachment = nullptr;
if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 &&
drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size())
{ {
// If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer size_t attachmentIdx =
// is an SRGB format. static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0);
const auto &drawbufferState = mState.getDrawBufferStates(); attachment = &colorAttachments[attachmentIdx];
const auto &colorAttachments = mState.getColorAttachments();
const FramebufferAttachment *attachment = nullptr;
if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 &&
drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size())
{
size_t attachmentIdx =
static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0);
attachment = &colorAttachments[attachmentIdx];
}
if (attachment != nullptr)
{
stateManager->setFramebufferSRGBEnabled(context,
attachment->getColorEncoding() == GL_SRGB);
}
} }
else
if (attachment != nullptr)
{ {
stateManager->setFramebufferSRGBEnabled(context, !mIsDefault); stateManager->setFramebufferSRGBEnabled(context,
attachment->getColorEncoding() == GL_SRGB);
} }
} }
else
{
stateManager->setFramebufferSRGBEnabled(context, !mIsDefault);
}
} }
bool FramebufferGL::modifyInvalidateAttachmentsForEmulatedDefaultFBO( bool FramebufferGL::modifyInvalidateAttachmentsForEmulatedDefaultFBO(
......
...@@ -2005,10 +2005,7 @@ angle::Result StateManagerGL::syncState(const gl::Context *context, ...@@ -2005,10 +2005,7 @@ angle::Result StateManagerGL::syncState(const gl::Context *context,
} }
// Changing the draw framebuffer binding sometimes requires resetting srgb blending. // Changing the draw framebuffer binding sometimes requires resetting srgb blending.
if (mFunctions->standard == STANDARD_GL_DESKTOP) iter.setLaterBit(gl::State::DIRTY_BIT_FRAMEBUFFER_SRGB_WRITE_CONTROL_MODE);
{
iter.setLaterBit(gl::State::DIRTY_BIT_FRAMEBUFFER_SRGB_WRITE_CONTROL_MODE);
}
// If the framebuffer is emulating RGB on top of RGBA, the color mask has to be // If the framebuffer is emulating RGB on top of RGBA, the color mask has to be
// updated // updated
...@@ -2225,10 +2222,10 @@ void StateManagerGL::setFramebufferSRGBEnabledForFramebuffer(const gl::Context * ...@@ -2225,10 +2222,10 @@ void StateManagerGL::setFramebufferSRGBEnabledForFramebuffer(const gl::Context *
bool enabled, bool enabled,
const FramebufferGL *framebuffer) const FramebufferGL *framebuffer)
{ {
if (mFunctions->standard == STANDARD_GL_DESKTOP && framebuffer->isDefault()) if (framebuffer->isDefault())
{ {
// Obey the framebuffer sRGB state for blending on all framebuffers except the default // Obey the framebuffer sRGB state for blending on all framebuffers except the default
// framebuffer on Desktop OpenGL. // framebuffer.
// When SRGB blending is enabled, only SRGB capable formats will use it but the default // When SRGB blending is enabled, only SRGB capable formats will use it but the default
// framebuffer will always use it if it is enabled. // framebuffer will always use it if it is enabled.
// TODO(geofflang): Update this when the framebuffer binding dirty changes, when it exists. // TODO(geofflang): Update this when the framebuffer binding dirty changes, when it exists.
......
...@@ -1885,7 +1885,7 @@ void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *feature ...@@ -1885,7 +1885,7 @@ void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *feature
isIntel && IsApple() && IsSkylake(device) && GetMacOSVersion() < OSVersion(10, 13, 2)); isIntel && IsApple() && IsSkylake(device) && GetMacOSVersion() < OSVersion(10, 13, 2));
ANGLE_FEATURE_CONDITION(features, doesSRGBClearsOnLinearFramebufferAttachments, ANGLE_FEATURE_CONDITION(features, doesSRGBClearsOnLinearFramebufferAttachments,
functions->standard == STANDARD_GL_DESKTOP && (isIntel || isAMD)); isIntel || isAMD);
ANGLE_FEATURE_CONDITION(features, emulateMaxVertexAttribStride, ANGLE_FEATURE_CONDITION(features, emulateMaxVertexAttribStride,
IsLinux() && functions->standard == STANDARD_GL_DESKTOP && isAMD); IsLinux() && functions->standard == STANDARD_GL_DESKTOP && isAMD);
......
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