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) ...@@ -2123,7 +2123,7 @@ void Context::detachTexture(GLuint texture)
// allocation map management either here or in the resource manager at detach time. // 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 // Zero textures are held by the Context, and we don't attempt to request them from
// the State. // the State.
mGLState.detachTexture(mZeroTextures, texture); mGLState.detachTexture(this, mZeroTextures, texture);
} }
void Context::detachBuffer(GLuint buffer) void Context::detachBuffer(GLuint buffer)
...@@ -2162,7 +2162,7 @@ void Context::detachFramebuffer(GLuint framebuffer) ...@@ -2162,7 +2162,7 @@ void Context::detachFramebuffer(GLuint framebuffer)
void Context::detachRenderbuffer(GLuint renderbuffer) void Context::detachRenderbuffer(GLuint renderbuffer)
{ {
mGLState.detachRenderbuffer(renderbuffer); mGLState.detachRenderbuffer(this, renderbuffer);
} }
void Context::detachVertexArray(GLuint vertexArray) void Context::detachVertexArray(GLuint vertexArray)
...@@ -2738,11 +2738,11 @@ void Context::framebufferTexture2D(GLenum target, ...@@ -2738,11 +2738,11 @@ void Context::framebufferTexture2D(GLenum target,
index = ImageIndex::MakeCube(textarget, level); index = ImageIndex::MakeCube(textarget, level);
} }
framebuffer->setAttachment(GL_TEXTURE, attachment, index, textureObj); framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
} }
else else
{ {
framebuffer->resetAttachment(attachment); framebuffer->resetAttachment(this, attachment);
} }
mGLState.setObjectDirty(target); mGLState.setObjectDirty(target);
...@@ -2759,12 +2759,13 @@ void Context::framebufferRenderbuffer(GLenum target, ...@@ -2759,12 +2759,13 @@ void Context::framebufferRenderbuffer(GLenum target,
if (renderbuffer != 0) if (renderbuffer != 0)
{ {
Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer); Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
framebuffer->setAttachment(GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
renderbufferObject); renderbufferObject);
} }
else else
{ {
framebuffer->resetAttachment(attachment); framebuffer->resetAttachment(this, attachment);
} }
mGLState.setObjectDirty(target); mGLState.setObjectDirty(target);
...@@ -2795,11 +2796,11 @@ void Context::framebufferTextureLayer(GLenum target, ...@@ -2795,11 +2796,11 @@ void Context::framebufferTextureLayer(GLenum target,
index = ImageIndex::Make2DArray(level, layer); index = ImageIndex::Make2DArray(level, layer);
} }
framebuffer->setAttachment(GL_TEXTURE, attachment, index, textureObject); framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
} }
else else
{ {
framebuffer->resetAttachment(attachment); framebuffer->resetAttachment(this, attachment);
} }
mGLState.setObjectDirty(target); mGLState.setObjectDirty(target);
......
...@@ -98,6 +98,11 @@ ContextState::~ContextState() ...@@ -98,6 +98,11 @@ ContextState::~ContextState()
// Handles are released by the Context. // Handles are released by the Context.
} }
bool ContextState::isWebGL1() const
{
return (mExtensions.webglCompatibility && mClientVersion.major == 2);
}
const TextureCaps &ContextState::getTextureCap(GLenum internalFormat) const const TextureCaps &ContextState::getTextureCap(GLenum internalFormat) const
{ {
return mTextureCaps.get(internalFormat); return mTextureCaps.get(internalFormat);
......
...@@ -58,6 +58,8 @@ class ContextState final : public angle::NonCopyable ...@@ -58,6 +58,8 @@ class ContextState final : public angle::NonCopyable
bool usingDisplayTextureShareGroup() const; bool usingDisplayTextureShareGroup() const;
bool isWebGL1() const;
private: private:
friend class Context; friend class Context;
friend class ValidationContext; friend class ValidationContext;
...@@ -124,6 +126,8 @@ class ValidationContext : angle::NonCopyable ...@@ -124,6 +126,8 @@ class ValidationContext : angle::NonCopyable
// Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
GLenum getConvertedRenderbufferFormat(GLenum internalformat) const; GLenum getConvertedRenderbufferFormat(GLenum internalformat) const;
bool isWebGL1() const { return mState.isWebGL1(); }
protected: protected:
ContextState mState; ContextState mState;
bool mSkipValidation; bool mSkipValidation;
......
...@@ -105,6 +105,13 @@ class FramebufferState final : angle::NonCopyable ...@@ -105,6 +105,13 @@ class FramebufferState final : angle::NonCopyable
GLint mDefaultHeight; GLint mDefaultHeight;
GLint mDefaultSamples; GLint mDefaultSamples;
GLboolean mDefaultFixedSampleLocations; 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 class Framebuffer final : public LabeledObject, public angle::SignalReceiver
...@@ -128,14 +135,15 @@ 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; } GLuint id() const { return mId; }
void setAttachment(GLenum type, void setAttachment(const Context *context,
GLenum type,
GLenum binding, GLenum binding,
const ImageIndex &textureIndex, const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource); FramebufferAttachmentObject *resource);
void resetAttachment(GLenum binding); void resetAttachment(const Context *context, GLenum binding);
void detachTexture(GLuint texture); void detachTexture(const Context *context, GLuint texture);
void detachRenderbuffer(GLuint renderbuffer); void detachRenderbuffer(const Context *context, GLuint renderbuffer);
const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const; const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
const FramebufferAttachment *getDepthbuffer() const; const FramebufferAttachment *getDepthbuffer() const;
...@@ -254,12 +262,18 @@ class Framebuffer final : public LabeledObject, public angle::SignalReceiver ...@@ -254,12 +262,18 @@ class Framebuffer final : public LabeledObject, public angle::SignalReceiver
GLint copyTextureLayer) const; GLint copyTextureLayer) const;
private: private:
void detachResourceById(GLenum resourceType, GLuint resourceId); void detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
void detachMatchingAttachment(FramebufferAttachment *attachment, void detachMatchingAttachment(FramebufferAttachment *attachment,
GLenum matchType, GLenum matchType,
GLuint matchId, GLuint matchId,
size_t dirtyBit); size_t dirtyBit);
GLenum checkStatusImpl(const ContextState &state); GLenum checkStatusImpl(const ContextState &state);
void commitWebGL1DepthStencilIfConsistent();
void setAttachmentImpl(GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
FramebufferState mState; FramebufferState mState;
rx::FramebufferImpl *mImpl; rx::FramebufferImpl *mImpl;
......
...@@ -210,6 +210,11 @@ const egl::Surface *FramebufferAttachment::getSurface() const ...@@ -210,6 +210,11 @@ const egl::Surface *FramebufferAttachment::getSurface() const
return rx::GetAs<egl::Surface>(mResource); return rx::GetAs<egl::Surface>(mResource);
} }
FramebufferAttachmentObject *FramebufferAttachment::getResource() const
{
return mResource;
}
bool FramebufferAttachment::operator==(const FramebufferAttachment &other) const bool FramebufferAttachment::operator==(const FramebufferAttachment &other) const
{ {
if (mResource != other.mResource || mType != other.mType) if (mResource != other.mResource || mType != other.mType)
......
...@@ -126,6 +126,7 @@ class FramebufferAttachment final ...@@ -126,6 +126,7 @@ class FramebufferAttachment final
Renderbuffer *getRenderbuffer() const; Renderbuffer *getRenderbuffer() const;
Texture *getTexture() const; Texture *getTexture() const;
const egl::Surface *getSurface() const; const egl::Surface *getSurface() const;
FramebufferAttachmentObject *getResource() const;
// "T" must be static_castable from FramebufferAttachmentRenderTarget // "T" must be static_castable from FramebufferAttachmentRenderTarget
template <typename T> template <typename T>
...@@ -177,22 +178,26 @@ class FramebufferAttachmentObject ...@@ -177,22 +178,26 @@ class FramebufferAttachmentObject
inline Extents FramebufferAttachment::getSize() const inline Extents FramebufferAttachment::getSize() const
{ {
ASSERT(mResource);
return mResource->getAttachmentSize(mTarget); return mResource->getAttachmentSize(mTarget);
} }
inline const Format &FramebufferAttachment::getFormat() const inline const Format &FramebufferAttachment::getFormat() const
{ {
ASSERT(mResource);
return mResource->getAttachmentFormat(mTarget); return mResource->getAttachmentFormat(mTarget);
} }
inline GLsizei FramebufferAttachment::getSamples() const inline GLsizei FramebufferAttachment::getSamples() const
{ {
ASSERT(mResource);
return mResource->getAttachmentSamples(mTarget); return mResource->getAttachmentSamples(mTarget);
} }
inline gl::Error FramebufferAttachment::getRenderTargetImpl( inline gl::Error FramebufferAttachment::getRenderTargetImpl(
rx::FramebufferAttachmentRenderTarget **rtOut) const rx::FramebufferAttachmentRenderTarget **rtOut) const
{ {
ASSERT(mResource);
return mResource->getAttachmentRenderTarget(mTarget, rtOut); return mResource->getAttachmentRenderTarget(mTarget, rtOut);
} }
......
...@@ -779,7 +779,7 @@ GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const ...@@ -779,7 +779,7 @@ GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
return it->second[sampler].id(); 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 // Textures have a detach method on State rather than a simple
// removeBinding, because the zero/null texture objects are managed // removeBinding, because the zero/null texture objects are managed
...@@ -814,12 +814,12 @@ void State::detachTexture(const TextureMap &zeroTextures, GLuint texture) ...@@ -814,12 +814,12 @@ void State::detachTexture(const TextureMap &zeroTextures, GLuint texture)
if (mReadFramebuffer) if (mReadFramebuffer)
{ {
mReadFramebuffer->detachTexture(texture); mReadFramebuffer->detachTexture(context, texture);
} }
if (mDrawFramebuffer) if (mDrawFramebuffer)
{ {
mDrawFramebuffer->detachTexture(texture); mDrawFramebuffer->detachTexture(context, texture);
} }
} }
...@@ -883,7 +883,7 @@ Renderbuffer *State::getCurrentRenderbuffer() const ...@@ -883,7 +883,7 @@ Renderbuffer *State::getCurrentRenderbuffer() const
return mRenderbuffer.get(); 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: // [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 // 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) ...@@ -904,12 +904,12 @@ void State::detachRenderbuffer(GLuint renderbuffer)
if (readFramebuffer) if (readFramebuffer)
{ {
readFramebuffer->detachRenderbuffer(renderbuffer); readFramebuffer->detachRenderbuffer(context, renderbuffer);
} }
if (drawFramebuffer && drawFramebuffer != readFramebuffer) if (drawFramebuffer && drawFramebuffer != readFramebuffer)
{ {
drawFramebuffer->detachRenderbuffer(renderbuffer); drawFramebuffer->detachRenderbuffer(context, renderbuffer);
} }
} }
......
...@@ -167,7 +167,7 @@ class State : angle::NonCopyable ...@@ -167,7 +167,7 @@ class State : angle::NonCopyable
Texture *getTargetTexture(GLenum target) const; Texture *getTargetTexture(GLenum target) const;
Texture *getSamplerTexture(unsigned int sampler, GLenum type) const; Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
GLuint getSamplerTextureId(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); void initializeZeroTextures(const TextureMap &zeroTextures);
// Sampler object binding manipulation // Sampler object binding manipulation
...@@ -180,7 +180,7 @@ class State : angle::NonCopyable ...@@ -180,7 +180,7 @@ class State : angle::NonCopyable
void setRenderbufferBinding(Renderbuffer *renderbuffer); void setRenderbufferBinding(Renderbuffer *renderbuffer);
GLuint getRenderbufferId() const; GLuint getRenderbufferId() const;
Renderbuffer *getCurrentRenderbuffer() const; Renderbuffer *getCurrentRenderbuffer() const;
void detachRenderbuffer(GLuint renderbuffer); void detachRenderbuffer(const Context *context, GLuint renderbuffer);
// Framebuffer binding manipulation // Framebuffer binding manipulation
void setReadFramebufferBinding(Framebuffer *framebuffer); void setReadFramebufferBinding(Framebuffer *framebuffer);
......
...@@ -628,8 +628,7 @@ void QueryRenderbufferiv(const Context *context, ...@@ -628,8 +628,7 @@ void QueryRenderbufferiv(const Context *context,
break; break;
case GL_RENDERBUFFER_INTERNAL_FORMAT: case GL_RENDERBUFFER_INTERNAL_FORMAT:
// Special case the WebGL 1 DEPTH_STENCIL format. // Special case the WebGL 1 DEPTH_STENCIL format.
if (context->getExtensions().webglCompatibility && if (context->isWebGL1() &&
context->getClientMajorVersion() == 2 &&
renderbuffer->getFormat().info->internalFormat == GL_DEPTH24_STENCIL8) renderbuffer->getFormat().info->internalFormat == GL_DEPTH24_STENCIL8)
{ {
*params = GL_DEPTH_STENCIL; *params = GL_DEPTH_STENCIL;
......
...@@ -91,7 +91,8 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError) ...@@ -91,7 +91,8 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError)
VertexArray *vertexArray = new VertexArray(&mockFactory, 0, 1, 1); VertexArray *vertexArray = new VertexArray(&mockFactory, 0, 1, 1);
Framebuffer *framebuffer = new Framebuffer(caps, &mockFactory, 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); 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