Commit e466c551 by Geoff Lang Committed by Commit Bot

Preserve ImageIndex of texture attachments when committing.

When calling Framebuffer::commitWebGL1DepthStencilIfConsistent with textures attached to depth or stencil, an invalid ImageIndex would be provided and later cause crashes when trying to index image arrays with a -1 mip level. BUG=angleproject:1708 Change-Id: Iadd159ad740aa79561de823d8812c6b07454e5e5 Reviewed-on: https://chromium-review.googlesource.com/456840 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent d7d526ad
...@@ -1085,26 +1085,39 @@ void Framebuffer::commitWebGL1DepthStencilIfConsistent() ...@@ -1085,26 +1085,39 @@ void Framebuffer::commitWebGL1DepthStencilIfConsistent()
return; return;
} }
auto getImageIndexIfTextureAttachment = [](const FramebufferAttachment &attachment) {
if (attachment.type() == GL_TEXTURE)
{
return attachment.getTextureImageIndex();
}
else
{
return ImageIndex::MakeInvalid();
}
};
if (mState.mWebGLDepthAttachment.isAttached()) if (mState.mWebGLDepthAttachment.isAttached())
{ {
const auto &depth = mState.mWebGLDepthAttachment; const auto &depth = mState.mWebGLDepthAttachment;
setAttachmentImpl(depth.type(), GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), setAttachmentImpl(depth.type(), GL_DEPTH_ATTACHMENT,
depth.getResource()); getImageIndexIfTextureAttachment(depth), depth.getResource());
setAttachmentImpl(GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr); setAttachmentImpl(GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr);
} }
else if (mState.mWebGLStencilAttachment.isAttached()) else if (mState.mWebGLStencilAttachment.isAttached())
{ {
const auto &stencil = mState.mWebGLStencilAttachment; const auto &stencil = mState.mWebGLStencilAttachment;
setAttachmentImpl(GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr); setAttachmentImpl(GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr);
setAttachmentImpl(stencil.type(), GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), setAttachmentImpl(stencil.type(), GL_STENCIL_ATTACHMENT,
stencil.getResource()); getImageIndexIfTextureAttachment(stencil), stencil.getResource());
} }
else if (mState.mWebGLDepthStencilAttachment.isAttached()) else if (mState.mWebGLDepthStencilAttachment.isAttached())
{ {
const auto &depthStencil = mState.mWebGLDepthStencilAttachment; const auto &depthStencil = mState.mWebGLDepthStencilAttachment;
setAttachmentImpl(depthStencil.type(), GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), setAttachmentImpl(depthStencil.type(), GL_DEPTH_ATTACHMENT,
getImageIndexIfTextureAttachment(depthStencil),
depthStencil.getResource()); depthStencil.getResource());
setAttachmentImpl(depthStencil.type(), GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), setAttachmentImpl(depthStencil.type(), GL_STENCIL_ATTACHMENT,
getImageIndexIfTextureAttachment(depthStencil),
depthStencil.getResource()); depthStencil.getResource());
} }
else else
......
...@@ -28,6 +28,13 @@ class WebGLFramebufferTest : public ANGLETest ...@@ -28,6 +28,13 @@ class WebGLFramebufferTest : public ANGLETest
setWebGLCompatibilityEnabled(true); setWebGLCompatibilityEnabled(true);
} }
void SetUp() override
{
ANGLETest::SetUp();
glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
eglGetProcAddress("glRequestExtensionANGLE"));
}
void drawUByteColorQuad(GLuint program, GLint uniformLoc, const GLColor &color); void drawUByteColorQuad(GLuint program, GLint uniformLoc, const GLColor &color);
void testDepthStencilDepthStencil(GLint width, GLint height); void testDepthStencilDepthStencil(GLint width, GLint height);
void testDepthStencilRenderbuffer(GLint width, void testDepthStencilRenderbuffer(GLint width,
...@@ -36,6 +43,8 @@ class WebGLFramebufferTest : public ANGLETest ...@@ -36,6 +43,8 @@ class WebGLFramebufferTest : public ANGLETest
GLbitfield allowedStatuses); GLbitfield allowedStatuses);
void testRenderingAndReading(GLuint program); void testRenderingAndReading(GLuint program);
void testUsingIncompleteFramebuffer(GLenum depthFormat, GLenum depthAttachment); void testUsingIncompleteFramebuffer(GLenum depthFormat, GLenum depthAttachment);
PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
}; };
constexpr GLint ALLOW_COMPLETE = 0x1; constexpr GLint ALLOW_COMPLETE = 0x1;
...@@ -786,6 +795,35 @@ TEST_P(WebGLFramebufferTest, CheckValidColorDepthCombination) ...@@ -786,6 +795,35 @@ TEST_P(WebGLFramebufferTest, CheckValidColorDepthCombination)
} }
} }
// Test to cover a bug in preserving the texture image index for WebGL framebuffer attachments
TEST_P(WebGLFramebufferTest, TextureAttachmentCommitBug)
{
if (extensionRequestable("GL_ANGLE_depth_texture"))
{
glRequestExtensionANGLE("GL_ANGLE_depth_texture");
}
if (!extensionEnabled("GL_ANGLE_depth_texture"))
{
std::cout << "Test skipped because depth textures are not available.\n";
return;
}
GLTexture depthTexture;
glBindTexture(GL_TEXTURE_2D, depthTexture.get());
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
nullptr);
GLFramebuffer framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture.get(),
0);
glCheckFramebufferStatus(GL_FRAMEBUFFER);
EXPECT_GL_NO_ERROR();
}
// Only run against WebGL 1 validation, since much was changed in 2. // Only run against WebGL 1 validation, since much was changed in 2.
ANGLE_INSTANTIATE_TEST(WebGLFramebufferTest, ANGLE_INSTANTIATE_TEST(WebGLFramebufferTest,
ES2_D3D9(), ES2_D3D9(),
......
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