Hash :
05b35b21
Author :
Date :
2017-10-03T09:01:44
D3D11: Lazy robust resource init. This patch moves the robust resource init logic to the GL front-end. Instead of initializing texture resources immediately on creation in D3D11, it defers the clear until before a draw call in some cases, or skips the update if we can determine if a texture (or other resource) has been fully initialized. Currently lazy init is only implemented for Textures, Renderbuffers, and Surfaces. Various places where lazy resource init is triggered: * Framebuffer operations (Draw, Blit, CopyTexImage, Clear, ReadPixels) * Texture operations (SubImage, GenerateMipmap, CopyTexImage) Some efficiency gains remain to be implemented, such as when a SubImage call fills the entire object. Similarly for Blit, and a few other operations. In these cases we can skip lazy init as an optimization. Edge cases with EGLImage are mostly untested. BUG=angleproject:2107 Change-Id: I2bf3a69b1eae0d4feeb5b17daca23451f1037be8 Reviewed-on: https://chromium-review.googlesource.com/576058 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Framebuffer.h: Defines the gl::Framebuffer class. Implements GL framebuffer
// objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105.
#ifndef LIBANGLE_FRAMEBUFFER_H_
#define LIBANGLE_FRAMEBUFFER_H_
#include <vector>
#include "common/Optional.h"
#include "common/angleutils.h"
#include "libANGLE/Constants.h"
#include "libANGLE/Debug.h"
#include "libANGLE/Error.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/RefCountObject.h"
#include "libANGLE/signal_utils.h"
namespace rx
{
class GLImplFactory;
class FramebufferImpl;
class RenderbufferImpl;
class SurfaceImpl;
}
namespace egl
{
class Display;
class Surface;
}
namespace gl
{
class Context;
class ContextState;
class Framebuffer;
class Renderbuffer;
class State;
class Texture;
class TextureCapsMap;
class ValidationContext;
struct Caps;
struct Extensions;
struct ImageIndex;
struct Rectangle;
class FramebufferState final : angle::NonCopyable
{
public:
FramebufferState();
explicit FramebufferState(const Caps &caps);
~FramebufferState();
const std::string &getLabel();
size_t getReadIndex() const;
const FramebufferAttachment *getAttachment(GLenum attachment) const;
const FramebufferAttachment *getReadAttachment() const;
const FramebufferAttachment *getFirstNonNullAttachment() const;
const FramebufferAttachment *getFirstColorAttachment() const;
const FramebufferAttachment *getDepthOrStencilAttachment() const;
const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
const FramebufferAttachment *getDepthAttachment() const;
const FramebufferAttachment *getStencilAttachment() const;
const FramebufferAttachment *getDepthStencilAttachment() const;
const std::vector<GLenum> &getDrawBufferStates() const { return mDrawBufferStates; }
DrawBufferMask getEnabledDrawBuffers() const { return mEnabledDrawBuffers; }
GLenum getReadBufferState() const { return mReadBufferState; }
const std::vector<FramebufferAttachment> &getColorAttachments() const
{
return mColorAttachments;
}
bool attachmentsHaveSameDimensions() const;
bool colorAttachmentsAreUniqueImages() const;
Box getDimensions() const;
const FramebufferAttachment *getDrawBuffer(size_t drawBufferIdx) const;
size_t getDrawBufferCount() const;
GLint getDefaultWidth() const { return mDefaultWidth; };
GLint getDefaultHeight() const { return mDefaultHeight; };
GLint getDefaultSamples() const { return mDefaultSamples; };
GLboolean getDefaultFixedSampleLocations() const { return mDefaultFixedSampleLocations; };
bool hasDepth() const;
bool hasStencil() const;
GLenum getMultiviewLayout() const;
GLsizei getNumViews() const;
const std::vector<Offset> *getViewportOffsets() const;
GLint getBaseViewIndex() const;
private:
friend class Framebuffer;
std::string mLabel;
std::vector<FramebufferAttachment> mColorAttachments;
FramebufferAttachment mDepthAttachment;
FramebufferAttachment mStencilAttachment;
std::vector<GLenum> mDrawBufferStates;
GLenum mReadBufferState;
DrawBufferMask mEnabledDrawBuffers;
GLint mDefaultWidth;
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;
// Tracks if we need to initialize the resources for each attachment.
angle::BitSet<IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS + 2> mResourceNeedsInit;
};
class Framebuffer final : public LabeledObject, public OnAttachmentDirtyReceiver
{
public:
// Constructor to build application-defined framebuffers
Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id);
// Constructor to build default framebuffers for a surface
Framebuffer(const egl::Display *display, egl::Surface *surface);
// Constructor to build a fake default framebuffer when surfaceless
Framebuffer(rx::GLImplFactory *factory);
virtual ~Framebuffer();
void onDestroy(const Context *context);
void destroyDefault(const egl::Display *display);
void setLabel(const std::string &label) override;
const std::string &getLabel() const override;
rx::FramebufferImpl *getImplementation() const { return mImpl; }
GLuint id() const { return mId; }
void setAttachment(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
void setAttachmentMultiviewLayered(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
GLint baseViewIndex);
void setAttachmentMultiviewSideBySide(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
const GLint *viewportOffsets);
void resetAttachment(const Context *context, GLenum binding);
bool detachTexture(const Context *context, GLuint texture);
bool detachRenderbuffer(const Context *context, GLuint renderbuffer);
const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
const FramebufferAttachment *getDepthbuffer() const;
const FramebufferAttachment *getStencilbuffer() const;
const FramebufferAttachment *getDepthStencilBuffer() const;
const FramebufferAttachment *getDepthOrStencilbuffer() const;
const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
const FramebufferAttachment *getReadColorbuffer() const;
GLenum getReadColorbufferType() const;
const FramebufferAttachment *getFirstColorbuffer() const;
const FramebufferAttachment *getFirstNonNullAttachment() const;
const FramebufferAttachment *getAttachment(GLenum attachment) const;
GLenum getMultiviewLayout() const;
GLsizei getNumViews() const;
GLint getBaseViewIndex() const;
const std::vector<Offset> *getViewportOffsets() const;
size_t getDrawbufferStateCount() const;
GLenum getDrawBufferState(size_t drawBuffer) const;
const std::vector<GLenum> &getDrawBufferStates() const;
void setDrawBuffers(size_t count, const GLenum *buffers);
const FramebufferAttachment *getDrawBuffer(size_t drawBuffer) const;
GLenum getDrawbufferWriteType(size_t drawBuffer) const;
bool hasEnabledDrawBuffer() const;
GLenum getReadBufferState() const;
void setReadBuffer(GLenum buffer);
size_t getNumColorBuffers() const;
bool hasDepth() const;
bool hasStencil() const;
bool usingExtendedDrawBuffers() const;
// This method calls checkStatus.
int getSamples(const Context *context);
Error getSamplePosition(size_t index, GLfloat *xy) const;
GLint getDefaultWidth() const;
GLint getDefaultHeight() const;
GLint getDefaultSamples() const;
GLboolean getDefaultFixedSampleLocations() const;
void setDefaultWidth(GLint defaultWidth);
void setDefaultHeight(GLint defaultHeight);
void setDefaultSamples(GLint defaultSamples);
void setDefaultFixedSampleLocations(GLboolean defaultFixedSampleLocations);
void invalidateCompletenessCache();
GLenum checkStatus(const Context *context);
// TODO(jmadill): Remove this kludge.
GLenum checkStatus(const ValidationContext *context);
int getSamples(const ValidationContext *context);
// For when we don't want to check completeness in getSamples().
int getCachedSamples(const Context *context);
// Helper for checkStatus == GL_FRAMEBUFFER_COMPLETE.
bool complete(const Context *context);
bool cachedComplete() const;
bool hasValidDepthStencil() const;
Error discard(const Context *context, size_t count, const GLenum *attachments);
Error invalidate(const Context *context, size_t count, const GLenum *attachments);
Error invalidateSub(const Context *context,
size_t count,
const GLenum *attachments,
const gl::Rectangle &area);
Error clear(const gl::Context *context, GLbitfield mask);
Error clearBufferfv(const gl::Context *context,
GLenum buffer,
GLint drawbuffer,
const GLfloat *values);
Error clearBufferuiv(const gl::Context *context,
GLenum buffer,
GLint drawbuffer,
const GLuint *values);
Error clearBufferiv(const gl::Context *context,
GLenum buffer,
GLint drawbuffer,
const GLint *values);
Error clearBufferfi(const gl::Context *context,
GLenum buffer,
GLint drawbuffer,
GLfloat depth,
GLint stencil);
GLenum getImplementationColorReadFormat(const Context *context) const;
GLenum getImplementationColorReadType(const Context *context) const;
Error readPixels(const gl::Context *context,
const gl::Rectangle &area,
GLenum format,
GLenum type,
void *pixels);
Error blit(const gl::Context *context,
const Rectangle &sourceArea,
const Rectangle &destArea,
GLbitfield mask,
GLenum filter);
enum DirtyBitType : size_t
{
DIRTY_BIT_COLOR_ATTACHMENT_0,
DIRTY_BIT_COLOR_ATTACHMENT_MAX =
DIRTY_BIT_COLOR_ATTACHMENT_0 + gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS,
DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
DIRTY_BIT_STENCIL_ATTACHMENT,
DIRTY_BIT_DRAW_BUFFERS,
DIRTY_BIT_READ_BUFFER,
DIRTY_BIT_DEFAULT_WIDTH,
DIRTY_BIT_DEFAULT_HEIGHT,
DIRTY_BIT_DEFAULT_SAMPLES,
DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS,
DIRTY_BIT_UNKNOWN,
DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN
};
typedef angle::BitSet<DIRTY_BIT_MAX> DirtyBits;
bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
void syncState(const Context *context);
// OnAttachmentChangedReceiver implementation
void signal(size_t dirtyBit, InitState state) override;
bool formsRenderingFeedbackLoopWith(const State &state) const;
bool formsCopyingFeedbackLoopWith(GLuint copyTextureID,
GLint copyTextureLevel,
GLint copyTextureLayer) const;
Error ensureDrawAttachmentsInitialized(const Context *context);
Error ensureReadAttachmentInitialized(const Context *context, GLbitfield blitMask);
Box getDimensions() const;
private:
bool detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
bool detachMatchingAttachment(const Context *context,
FramebufferAttachment *attachment,
GLenum matchType,
GLuint matchId,
size_t dirtyBit);
GLenum checkStatusImpl(const Context *context);
void setAttachment(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
GLuint baseViewIndex,
GLenum multiviewLayout,
const GLint *viewportOffsets);
void commitWebGL1DepthStencilIfConsistent(const Context *context,
GLsizei numViews,
GLuint baseViewIndex,
GLenum multiviewLayout,
const GLint *viewportOffsets);
void setAttachmentImpl(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
GLuint baseViewIndex,
GLenum multiviewLayout,
const GLint *viewportOffsets);
void updateAttachment(const Context *context,
FramebufferAttachment *attachment,
size_t dirtyBit,
OnAttachmentDirtyBinding *onDirtyBinding,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
GLuint baseViewIndex,
GLenum multiviewLayout,
const GLint *viewportOffsets);
void markDrawAttachmentsInitialized(bool color, bool depth, bool stencil);
void markBufferInitialized(GLenum bufferType, GLint bufferIndex);
Error ensureBufferInitialized(const Context *context, GLenum bufferType, GLint bufferIndex);
// Checks that we have a partially masked clear:
// * some color channels are masked out
// * some stencil values are masked out
// * scissor test partially overlaps the framebuffer
bool partialClearNeedsInit(const Context *context, bool color, bool depth, bool stencil);
bool partialBufferClearNeedsInit(const Context *context, GLenum bufferType);
FramebufferState mState;
rx::FramebufferImpl *mImpl;
GLuint mId;
Optional<GLenum> mCachedStatus;
std::vector<OnAttachmentDirtyBinding> mDirtyColorAttachmentBindings;
OnAttachmentDirtyBinding mDirtyDepthAttachmentBinding;
OnAttachmentDirtyBinding mDirtyStencilAttachmentBinding;
DirtyBits mDirtyBits;
};
} // namespace gl
#endif // LIBANGLE_FRAMEBUFFER_H_