Commit a02315b0 by Jamie Madill Committed by Commit Bot

WebGL Compat: Add DEPTH_STENCIL attachments.

This is a special WebGL 1 binding point, that does not correspond to any native functionality. Due to particularities in validation we need to represent this with additional state in the Framebuffer. WebGL 2 fixes this oddity by resolving to the GLES 3 native spec. In order to pass the WebGL framebuffer objects test, we will also need a chromium-side CL to work with the additional state tracking it does in the blink layer, and an additional patch to ANGLE to clear the depth buffer before the first use (robust resource init). BUG=angleproject:1708 Change-Id: I111f8f5a451cce7de6cf281a6bc335b92dd2daf2 Reviewed-on: https://chromium-review.googlesource.com/444095 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 89fcb8e8
......@@ -2123,7 +2123,7 @@ void Context::detachTexture(GLuint texture)
// allocation map management either here or in the resource manager at detach time.
// Zero textures are held by the Context, and we don't attempt to request them from
// the State.
mGLState.detachTexture(mZeroTextures, texture);
mGLState.detachTexture(this, mZeroTextures, texture);
}
void Context::detachBuffer(GLuint buffer)
......@@ -2162,7 +2162,7 @@ void Context::detachFramebuffer(GLuint framebuffer)
void Context::detachRenderbuffer(GLuint renderbuffer)
{
mGLState.detachRenderbuffer(renderbuffer);
mGLState.detachRenderbuffer(this, renderbuffer);
}
void Context::detachVertexArray(GLuint vertexArray)
......@@ -2738,11 +2738,11 @@ void Context::framebufferTexture2D(GLenum target,
index = ImageIndex::MakeCube(textarget, level);
}
framebuffer->setAttachment(GL_TEXTURE, attachment, index, textureObj);
framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
}
else
{
framebuffer->resetAttachment(attachment);
framebuffer->resetAttachment(this, attachment);
}
mGLState.setObjectDirty(target);
......@@ -2759,12 +2759,13 @@ void Context::framebufferRenderbuffer(GLenum target,
if (renderbuffer != 0)
{
Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
framebuffer->setAttachment(GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
renderbufferObject);
}
else
{
framebuffer->resetAttachment(attachment);
framebuffer->resetAttachment(this, attachment);
}
mGLState.setObjectDirty(target);
......@@ -2795,11 +2796,11 @@ void Context::framebufferTextureLayer(GLenum target,
index = ImageIndex::Make2DArray(level, layer);
}
framebuffer->setAttachment(GL_TEXTURE, attachment, index, textureObject);
framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
}
else
{
framebuffer->resetAttachment(attachment);
framebuffer->resetAttachment(this, attachment);
}
mGLState.setObjectDirty(target);
......
......@@ -98,6 +98,11 @@ ContextState::~ContextState()
// Handles are released by the Context.
}
bool ContextState::isWebGL1() const
{
return (mExtensions.webglCompatibility && mClientVersion.major == 2);
}
const TextureCaps &ContextState::getTextureCap(GLenum internalFormat) const
{
return mTextureCaps.get(internalFormat);
......
......@@ -58,6 +58,8 @@ class ContextState final : public angle::NonCopyable
bool usingDisplayTextureShareGroup() const;
bool isWebGL1() const;
private:
friend class Context;
friend class ValidationContext;
......@@ -124,6 +126,8 @@ class ValidationContext : angle::NonCopyable
// Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
GLenum getConvertedRenderbufferFormat(GLenum internalformat) const;
bool isWebGL1() const { return mState.isWebGL1(); }
protected:
ContextState mState;
bool mSkipValidation;
......
......@@ -105,6 +105,13 @@ class FramebufferState final : angle::NonCopyable
GLint mDefaultHeight;
GLint mDefaultSamples;
GLboolean mDefaultFixedSampleLocations;
// It's necessary to store all this extra state so we can restore attachments
// when DEPTH_STENCIL/DEPTH/STENCIL is unbound in WebGL 1.
FramebufferAttachment mWebGLDepthStencilAttachment;
FramebufferAttachment mWebGLDepthAttachment;
FramebufferAttachment mWebGLStencilAttachment;
bool mWebGLDepthStencilConsistent;
};
class Framebuffer final : public LabeledObject, public angle::SignalReceiver
......@@ -128,14 +135,15 @@ class Framebuffer final : public LabeledObject, public angle::SignalReceiver
GLuint id() const { return mId; }
void setAttachment(GLenum type,
void setAttachment(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
void resetAttachment(GLenum binding);
void resetAttachment(const Context *context, GLenum binding);
void detachTexture(GLuint texture);
void detachRenderbuffer(GLuint renderbuffer);
void detachTexture(const Context *context, GLuint texture);
void detachRenderbuffer(const Context *context, GLuint renderbuffer);
const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
const FramebufferAttachment *getDepthbuffer() const;
......@@ -254,12 +262,18 @@ class Framebuffer final : public LabeledObject, public angle::SignalReceiver
GLint copyTextureLayer) const;
private:
void detachResourceById(GLenum resourceType, GLuint resourceId);
void detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
void detachMatchingAttachment(FramebufferAttachment *attachment,
GLenum matchType,
GLuint matchId,
size_t dirtyBit);
GLenum checkStatusImpl(const ContextState &state);
void commitWebGL1DepthStencilIfConsistent();
void setAttachmentImpl(GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
FramebufferState mState;
rx::FramebufferImpl *mImpl;
......
......@@ -210,6 +210,11 @@ const egl::Surface *FramebufferAttachment::getSurface() const
return rx::GetAs<egl::Surface>(mResource);
}
FramebufferAttachmentObject *FramebufferAttachment::getResource() const
{
return mResource;
}
bool FramebufferAttachment::operator==(const FramebufferAttachment &other) const
{
if (mResource != other.mResource || mType != other.mType)
......
......@@ -126,6 +126,7 @@ class FramebufferAttachment final
Renderbuffer *getRenderbuffer() const;
Texture *getTexture() const;
const egl::Surface *getSurface() const;
FramebufferAttachmentObject *getResource() const;
// "T" must be static_castable from FramebufferAttachmentRenderTarget
template <typename T>
......@@ -177,22 +178,26 @@ class FramebufferAttachmentObject
inline Extents FramebufferAttachment::getSize() const
{
ASSERT(mResource);
return mResource->getAttachmentSize(mTarget);
}
inline const Format &FramebufferAttachment::getFormat() const
{
ASSERT(mResource);
return mResource->getAttachmentFormat(mTarget);
}
inline GLsizei FramebufferAttachment::getSamples() const
{
ASSERT(mResource);
return mResource->getAttachmentSamples(mTarget);
}
inline gl::Error FramebufferAttachment::getRenderTargetImpl(
rx::FramebufferAttachmentRenderTarget **rtOut) const
{
ASSERT(mResource);
return mResource->getAttachmentRenderTarget(mTarget, rtOut);
}
......
......@@ -779,7 +779,7 @@ GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
return it->second[sampler].id();
}
void State::detachTexture(const TextureMap &zeroTextures, GLuint texture)
void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture)
{
// Textures have a detach method on State rather than a simple
// removeBinding, because the zero/null texture objects are managed
......@@ -814,12 +814,12 @@ void State::detachTexture(const TextureMap &zeroTextures, GLuint texture)
if (mReadFramebuffer)
{
mReadFramebuffer->detachTexture(texture);
mReadFramebuffer->detachTexture(context, texture);
}
if (mDrawFramebuffer)
{
mDrawFramebuffer->detachTexture(texture);
mDrawFramebuffer->detachTexture(context, texture);
}
}
......@@ -883,7 +883,7 @@ Renderbuffer *State::getCurrentRenderbuffer() const
return mRenderbuffer.get();
}
void State::detachRenderbuffer(GLuint renderbuffer)
void State::detachRenderbuffer(const Context *context, GLuint renderbuffer)
{
// [OpenGL ES 2.0.24] section 4.4 page 109:
// If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer
......@@ -904,12 +904,12 @@ void State::detachRenderbuffer(GLuint renderbuffer)
if (readFramebuffer)
{
readFramebuffer->detachRenderbuffer(renderbuffer);
readFramebuffer->detachRenderbuffer(context, renderbuffer);
}
if (drawFramebuffer && drawFramebuffer != readFramebuffer)
{
drawFramebuffer->detachRenderbuffer(renderbuffer);
drawFramebuffer->detachRenderbuffer(context, renderbuffer);
}
}
......
......@@ -167,7 +167,7 @@ class State : angle::NonCopyable
Texture *getTargetTexture(GLenum target) const;
Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
GLuint getSamplerTextureId(unsigned int sampler, GLenum type) const;
void detachTexture(const TextureMap &zeroTextures, GLuint texture);
void detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture);
void initializeZeroTextures(const TextureMap &zeroTextures);
// Sampler object binding manipulation
......@@ -180,7 +180,7 @@ class State : angle::NonCopyable
void setRenderbufferBinding(Renderbuffer *renderbuffer);
GLuint getRenderbufferId() const;
Renderbuffer *getCurrentRenderbuffer() const;
void detachRenderbuffer(GLuint renderbuffer);
void detachRenderbuffer(const Context *context, GLuint renderbuffer);
// Framebuffer binding manipulation
void setReadFramebufferBinding(Framebuffer *framebuffer);
......
......@@ -628,8 +628,7 @@ void QueryRenderbufferiv(const Context *context,
break;
case GL_RENDERBUFFER_INTERNAL_FORMAT:
// Special case the WebGL 1 DEPTH_STENCIL format.
if (context->getExtensions().webglCompatibility &&
context->getClientMajorVersion() == 2 &&
if (context->isWebGL1() &&
renderbuffer->getFormat().info->internalFormat == GL_DEPTH24_STENCIL8)
{
*params = GL_DEPTH_STENCIL;
......
......@@ -91,7 +91,8 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError)
VertexArray *vertexArray = new VertexArray(&mockFactory, 0, 1, 1);
Framebuffer *framebuffer = new Framebuffer(caps, &mockFactory, 1);
framebuffer->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex::Make2D(0), texture);
framebuffer->setAttachment(nullptr, GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex::Make2D(0),
texture);
Program *program = new Program(&mockFactory, nullptr, 1);
......
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