Hash :
a491bbe3
Author :
Date :
2023-03-18T19:05:08
Add PLS utilities for interrupting a rendering pass Adds two more simple commands to ANGLE_shader_pixel_local_storage that allow WebGL and the command buffer to interrupt rendering passes without having to either (1) make expensive queries, or (2) track lots of complex state for validation that they are not currently equipped to track. Bug: chromium:1421437 Change-Id: I80eaef3ae6b0b4bbbecb9cd2268ac90b43675d1c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4355032 Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Kenneth Russell <kbr@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
//
// Copyright 2022 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.
//
// PixelLocalStorage.h: Defines the renderer-agnostic container classes
// gl::PixelLocalStorage and gl::PixelLocalStoragePlane for
// ANGLE_shader_pixel_local_storage.
#ifndef LIBANGLE_PIXEL_LOCAL_STORAGE_H_
#define LIBANGLE_PIXEL_LOCAL_STORAGE_H_
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "libANGLE/ImageIndex.h"
#include "libANGLE/angletypes.h"
namespace gl
{
class Context;
class Texture;
// Holds the configuration of an ANGLE_shader_pixel_local_storage plane.
//
// Unlike normal framebuffer attachments, pixel local storage planes don't take effect until the
// application calls glBeginPixelLocalStorageANGLE, and the manner in which they take effect is
// highly dependent on the backend implementation. A PixelLocalStoragePlane is just a plain data
// description what to set up later once PLS is enabled.
class PixelLocalStoragePlane : angle::NonCopyable
{
public:
~PixelLocalStoragePlane();
// Called when the context is lost or destroyed. Causes this class to clear its GL object
// handles.
void onContextObjectsLost();
// Called when the owning framebuffer is being destroyed. Causes this class to release its
// texture object reference.
void onFramebufferDestroyed(const Context *);
void deinitialize(Context *);
void setMemoryless(Context *, GLenum internalformat);
void setTextureBacked(Context *, Texture *, int level, int layer);
bool isDeinitialized() const { return mInternalformat == GL_NONE; }
// Returns true if the texture ID bound to this plane has been deleted.
//
// [ANGLE_shader_pixel_local_storage] Section 4.4.2.X "Configuring Pixel Local Storage
// on a Framebuffer": When a texture object is deleted, any pixel local storage plane to
// which it was bound is automatically converted to a memoryless plane of matching
// internalformat.
bool isTextureIDDeleted(const Context *) const;
bool isMemoryless() const
{
// isMemoryless() should be false if the plane is deinitialized.
ASSERT(!(isDeinitialized() && mMemoryless));
return mMemoryless;
}
// Ensures we have an internal backing texture for memoryless planes. In some implementations we
// need a backing texture even if the plane is memoryless.
void ensureBackingTextureIfMemoryless(Context *, Extents plsSize);
GLenum getInternalformat() const { return mInternalformat; }
// Implements glGetIntegeri_v() for GL_PIXEL_LOCAL_FORMAT_ANGLE,
// GL_PIXEL_LOCAL_TEXTURE_NAME_ANGLE, GL_PIXEL_LOCAL_TEXTURE_LEVEL_ANGLE, and
// GL_PIXEL_LOCAL_TEXTURE_LAYER_ANGLE
GLint getIntegeri(const Context *, GLenum target) const;
// If this plane is texture backed, stores the bound texture image's {width, height, 0} to
// Extents and returns true. Otherwise returns false, meaning the plane is either deinitialized
// or memoryless.
bool getTextureImageExtents(const Context *, Extents *extents) const;
// Attaches this plane to the specified color attachment point on the current draw framebuffer.
void attachToDrawFramebuffer(Context *, GLenum colorAttachment) const;
// Interface for clearing typed pixel local storage planes.
class ClearCommands
{
public:
virtual ~ClearCommands() {}
virtual void clearfv(int target, const GLfloat[]) const = 0;
virtual void cleariv(int target, const GLint[]) const = 0;
virtual void clearuiv(int target, const GLuint[]) const = 0;
};
// Issues the approprite command from ClearCommands for this plane's internalformat. Uses the
// clear state value that corresponds to mInternalFormat, and potentially clamps it to ensure it
// is representable.
void issueClearCommand(ClearCommands *, int target, GLenum loadop) const;
// Binds this PLS plane to a texture image unit for image load/store shader operations.
void bindToImage(Context *, GLuint unit, bool needsR32Packing) const;
// Low-level access to the backing texture. The plane must not be memoryless or deinitialized.
const ImageIndex &getTextureImageIndex() const { return mTextureImageIndex; }
const Texture *getBackingTexture(const Context *context) const;
void setClearValuef(const GLfloat value[4]) { memcpy(mClearValuef.data(), value, 4 * 4); }
void setClearValuei(const GLint value[4]) { memcpy(mClearValuei.data(), value, 4 * 4); }
void setClearValueui(const GLuint value[4]) { memcpy(mClearValueui.data(), value, 4 * 4); }
void getClearValuef(GLfloat value[4]) const { memcpy(value, mClearValuef.data(), 4 * 4); }
void getClearValuei(GLint value[4]) const { memcpy(value, mClearValuei.data(), 4 * 4); }
void getClearValueui(GLuint value[4]) const { memcpy(value, mClearValueui.data(), 4 * 4); }
// True if PLS is currently active and this plane is enabled.
bool isActive() const { return mActive; }
void markActive(bool active) { mActive = active; }
private:
GLenum mInternalformat = GL_NONE; // GL_NONE if this plane is in a deinitialized state.
bool mMemoryless = false;
TextureID mMemorylessTextureID{}; // We own memoryless backing textures and must delete them.
ImageIndex mTextureImageIndex;
Texture *mTextureRef = nullptr;
// Clear value state.
std::array<GLfloat, 4> mClearValuef{};
std::array<GLint, 4> mClearValuei{};
std::array<GLuint, 4> mClearValueui{};
// True if PLS is currently active and this plane is enabled.
bool mActive = false;
};
// Manages a collection of PixelLocalStoragePlanes and applies them to ANGLE's GL state.
//
// The main magic of ANGLE_shader_pixel_local_storage happens inside shaders, so we just emulate the
// client API on top of ANGLE's OpenGL ES API for simplicity.
class PixelLocalStorage
{
public:
static std::unique_ptr<PixelLocalStorage> Make(const Context *);
virtual ~PixelLocalStorage();
// Called when the owning framebuffer is being destroyed.
void onFramebufferDestroyed(const Context *);
// Deletes any GL objects that have been allocated for pixel local storage. These can't be
// cleaned up in the destructor because they require a non-const Context object.
void deleteContextObjects(Context *);
const PixelLocalStoragePlane &getPlane(GLint plane) const
{
ASSERT(0 <= plane && plane < IMPLEMENTATION_MAX_PIXEL_LOCAL_STORAGE_PLANES);
return mPlanes[plane];
}
const PixelLocalStoragePlane *getPlanes() { return mPlanes.data(); }
size_t interruptCount() const { return mInterruptCount; }
// ANGLE_shader_pixel_local_storage API.
void deinitialize(Context *context, GLint plane) { mPlanes[plane].deinitialize(context); }
void setMemoryless(Context *context, GLint plane, GLenum internalformat)
{
mPlanes[plane].setMemoryless(context, internalformat);
}
void setTextureBacked(Context *context, GLint plane, Texture *tex, int level, int layer)
{
mPlanes[plane].setTextureBacked(context, tex, level, layer);
}
void setClearValuef(GLint plane, const GLfloat val[4]) { mPlanes[plane].setClearValuef(val); }
void setClearValuei(GLint plane, const GLint val[4]) { mPlanes[plane].setClearValuei(val); }
void setClearValueui(GLint plane, const GLuint val[4]) { mPlanes[plane].setClearValueui(val); }
void begin(Context *, GLsizei n, const GLenum loadops[]);
void end(Context *, const GLenum storeops[]);
void barrier(Context *);
void interrupt(Context *);
void restore(Context *);
protected:
PixelLocalStorage(const ShPixelLocalStorageOptions &);
// Called when the context is lost or destroyed. Causes the subclass to clear its GL object
// handles.
virtual void onContextObjectsLost() = 0;
// Called when the framebuffer is being destroyed. Causes the subclass to delete its frontend GL
// object handles.
virtual void onDeleteContextObjects(Context *) = 0;
// ANGLE_shader_pixel_local_storage API.
virtual void onBegin(Context *, GLsizei n, const GLenum loadops[], Extents plsSize) = 0;
virtual void onEnd(Context *, const GLenum storeops[]) = 0;
virtual void onBarrier(Context *) = 0;
const ShPixelLocalStorageOptions mPLSOptions;
private:
std::array<PixelLocalStoragePlane, IMPLEMENTATION_MAX_PIXEL_LOCAL_STORAGE_PLANES> mPlanes;
size_t mInterruptCount = 0;
GLsizei mActivePlanesAtInterrupt = 0;
};
} // namespace gl
#endif // LIBANGLE_PIXEL_LOCAL_STORAGE_H_