rvargas@google.com | dd25504 | 2012-03-05 20:14:17 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
| 6 | #define GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |
| 7 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 11 | #include <memory> |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 12 | #include <unordered_map> |
reveman@chromium.org | 4aada5a9 | 2013-11-01 13:45:00 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
Anand K Mistry | bf05511 | 2021-03-11 09:10:40 | [diff] [blame^] | 15 | #include "base/containers/small_map.h" |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 16 | #include "base/macros.h" |
levin@chromium.org | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 17 | #include "base/memory/ref_counted.h" |
zmo | a0ee95e | 2015-07-11 01:33:11 | [diff] [blame] | 18 | #include "gpu/command_buffer/service/context_group.h" |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 19 | #include "gpu/command_buffer/service/gl_utils.h" |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 20 | #include "gpu/command_buffer/service/shader_manager.h" |
Antoine Labour | 83a0aed1 | 2018-01-10 04:52:38 | [diff] [blame] | 21 | #include "gpu/gpu_gles2_export.h" |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 22 | |
| 23 | namespace gpu { |
| 24 | namespace gles2 { |
| 25 | |
zmo | 59b6cc5 | 2016-01-30 02:35:59 | [diff] [blame] | 26 | class FeatureInfo; |
tobiasjs | fc199b47 | 2015-08-22 00:39:06 | [diff] [blame] | 27 | class FramebufferCompletenessCache; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 28 | class FramebufferManager; |
gman@chromium.org | 31494b8 | 2013-02-28 10:10:26 | [diff] [blame] | 29 | class Renderbuffer; |
| 30 | class RenderbufferManager; |
piman@chromium.org | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 31 | class TextureRef; |
gman@chromium.org | 31494b8 | 2013-02-28 10:10:26 | [diff] [blame] | 32 | class TextureManager; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 33 | |
| 34 | // Info about a particular Framebuffer. |
Antoine Labour | 83a0aed1 | 2018-01-10 04:52:38 | [diff] [blame] | 35 | class GPU_GLES2_EXPORT Framebuffer : public base::RefCounted<Framebuffer> { |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 36 | public: |
| 37 | class Attachment : public base::RefCounted<Attachment> { |
| 38 | public: |
| 39 | virtual GLsizei width() const = 0; |
| 40 | virtual GLsizei height() const = 0; |
| 41 | virtual GLenum internal_format() const = 0; |
geofflang@chromium.org | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 42 | virtual GLenum texture_type() const = 0; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 43 | virtual GLsizei samples() const = 0; |
piman@chromium.org | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 44 | virtual GLuint object_name() const = 0; |
Zhenyao Mo | 5ae4e21 | 2018-01-08 21:00:26 | [diff] [blame] | 45 | virtual GLint level() const = 0; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 46 | virtual bool cleared() const = 0; |
| 47 | virtual void SetCleared( |
| 48 | RenderbufferManager* renderbuffer_manager, |
| 49 | TextureManager* texture_manager, |
| 50 | bool cleared) = 0; |
zmo | d252e3ea | 2016-02-23 00:38:17 | [diff] [blame] | 51 | virtual bool IsPartiallyCleared() const = 0; |
| 52 | virtual bool IsTextureAttachment() const = 0; |
| 53 | virtual bool IsRenderbufferAttachment() const = 0; |
piman@chromium.org | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 54 | virtual bool IsTexture(TextureRef* texture) const = 0; |
qiankun.miao | db975cd | 2016-07-20 18:00:19 | [diff] [blame] | 55 | virtual bool IsRenderbuffer(Renderbuffer* renderbuffer) const = 0; |
| 56 | virtual bool IsSameAttachment(const Attachment* attachment) const = 0; |
zmo | d252e3ea | 2016-02-23 00:38:17 | [diff] [blame] | 57 | virtual bool Is3D() const = 0; |
zmo | dda9c29 | 2016-05-31 19:04:19 | [diff] [blame] | 58 | |
| 59 | // If it's a 3D texture attachment, return true if |
| 60 | // FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER is smaller than the number of |
| 61 | // layers in the texture. |
| 62 | virtual bool IsLayerValid() const = 0; |
| 63 | |
zmo | 59b6cc5 | 2016-01-30 02:35:59 | [diff] [blame] | 64 | virtual bool CanRenderTo(const FeatureInfo* feature_info) const = 0; |
Kai Ninomiya | 821895e | 2017-06-06 00:03:29 | [diff] [blame] | 65 | virtual void DetachFromFramebuffer(Framebuffer* framebuffer, |
| 66 | GLenum attachment) const = 0; |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 67 | virtual bool ValidForAttachmentType(GLenum attachment_type, |
| 68 | uint32_t max_color_attachments) = 0; |
dyen | cb01731 | 2014-09-29 18:16:20 | [diff] [blame] | 69 | virtual size_t GetSignatureSize(TextureManager* texture_manager) const = 0; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 70 | virtual void AddToSignature( |
| 71 | TextureManager* texture_manager, std::string* signature) const = 0; |
yunchao.he | b29cee86 | 2016-07-29 10:14:21 | [diff] [blame] | 72 | virtual bool FormsFeedbackLoop( |
| 73 | TextureRef* texture, GLint level, GLint layer) const = 0; |
erikchen | 6e48456 | 2016-04-16 01:23:39 | [diff] [blame] | 74 | virtual bool EmulatingRGB() const = 0; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 75 | |
| 76 | protected: |
| 77 | friend class base::RefCounted<Attachment>; |
Chris Watkins | 8103077 | 2017-12-07 01:20:56 | [diff] [blame] | 78 | virtual ~Attachment() = default; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | Framebuffer(FramebufferManager* manager, GLuint service_id); |
| 82 | |
| 83 | GLuint service_id() const { |
| 84 | return service_id_; |
| 85 | } |
| 86 | |
| 87 | bool HasUnclearedAttachment(GLenum attachment) const; |
zmo@chromium.org | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 88 | bool HasUnclearedColorAttachments() const; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 89 | |
zmo | 9d63197 | 2016-06-17 23:31:04 | [diff] [blame] | 90 | bool HasSRGBAttachments() const; |
qiankun.miao | af3b3d8 | 2016-07-22 21:39:53 | [diff] [blame] | 91 | bool HasDepthStencilFormatAttachment() const; |
zmo | 9d63197 | 2016-06-17 23:31:04 | [diff] [blame] | 92 | |
zmo | d252e3ea | 2016-02-23 00:38:17 | [diff] [blame] | 93 | void ClearUnclearedIntOr3DTexturesOrPartiallyClearedTextures( |
| 94 | GLES2Decoder* decoder, |
| 95 | TextureManager* texture_manager); |
| 96 | |
| 97 | bool HasUnclearedIntRenderbufferAttachments() const; |
| 98 | |
| 99 | void ClearUnclearedIntRenderbufferAttachments( |
| 100 | RenderbufferManager* renderbuffer_manager); |
| 101 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 102 | void MarkAttachmentAsCleared( |
| 103 | RenderbufferManager* renderbuffer_manager, |
| 104 | TextureManager* texture_manager, |
| 105 | GLenum attachment, |
| 106 | bool cleared); |
| 107 | |
vmiura | 7d08fee5 | 2015-02-18 18:39:34 | [diff] [blame] | 108 | // Unbinds all attachments from this framebuffer for workaround |
| 109 | // 'unbind_attachments_on_bound_render_fbo_delete'. The Framebuffer must be |
| 110 | // bound when calling this. |
| 111 | void DoUnbindGLAttachmentsForWorkaround(GLenum target); |
| 112 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 113 | // Attaches a renderbuffer to a particlar attachment. |
| 114 | // Pass null to detach. |
| 115 | void AttachRenderbuffer( |
| 116 | GLenum attachment, Renderbuffer* renderbuffer); |
| 117 | |
| 118 | // Attaches a texture to a particlar attachment. Pass null to detach. |
| 119 | void AttachTexture( |
piman@chromium.org | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 120 | GLenum attachment, TextureRef* texture_ref, GLenum target, |
bsalomon@google.com | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 121 | GLint level, GLsizei samples); |
qiankun.miao | 3071b53 | 2015-10-30 09:30:32 | [diff] [blame] | 122 | void AttachTextureLayer( |
| 123 | GLenum attachment, TextureRef* texture_ref, GLenum target, |
| 124 | GLint level, GLint layer); |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 125 | |
| 126 | // Unbinds the given renderbuffer if it is bound. |
| 127 | void UnbindRenderbuffer( |
| 128 | GLenum target, Renderbuffer* renderbuffer); |
| 129 | |
| 130 | // Unbinds the given texture if it is bound. |
| 131 | void UnbindTexture( |
piman@chromium.org | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 132 | GLenum target, TextureRef* texture_ref); |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 133 | |
| 134 | const Attachment* GetAttachment(GLenum attachment) const; |
| 135 | |
zmo | 02f3a30 | 2015-08-05 22:30:38 | [diff] [blame] | 136 | const Attachment* GetReadBufferAttachment() const; |
| 137 | |
Kai Ninomiya | e576154 | 2017-09-16 04:06:43 | [diff] [blame] | 138 | // Returns the max dimensions which fit inside all of the attachments. |
| 139 | // Can only be called after the framebuffer has been checked to be complete. |
| 140 | gfx::Size GetFramebufferValidSize() const; |
| 141 | |
zmo | a432bd18 | 2016-06-08 21:52:27 | [diff] [blame] | 142 | GLsizei GetSamples() const; |
| 143 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 144 | bool IsDeleted() const { |
| 145 | return deleted_; |
| 146 | } |
| 147 | |
| 148 | void MarkAsValid() { |
| 149 | has_been_bound_ = true; |
| 150 | } |
| 151 | |
| 152 | bool IsValid() const { |
| 153 | return has_been_bound_ && !IsDeleted(); |
| 154 | } |
| 155 | |
cwallez | aafbfa0 | 2016-07-06 17:13:58 | [diff] [blame] | 156 | bool HasColorAttachment(int index) const; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 157 | bool HasDepthAttachment() const; |
| 158 | bool HasStencilAttachment() const; |
shrekshao | c50e5ea | 2019-03-07 03:34:30 | [diff] [blame] | 159 | bool HasActiveFloat32ColorAttachment() const; |
shrekshao | 4a1b49b | 2019-04-05 20:14:56 | [diff] [blame] | 160 | GLsizei last_color_attachment_id() const { return last_color_attachment_id_; } |
zmo | a432bd18 | 2016-06-08 21:52:27 | [diff] [blame] | 161 | GLenum GetDepthFormat() const; |
| 162 | GLenum GetStencilFormat() const; |
zmo | 21608f88 | 2015-08-07 21:49:43 | [diff] [blame] | 163 | GLenum GetDrawBufferInternalFormat() const; |
| 164 | GLenum GetReadBufferInternalFormat() const; |
geofflang@chromium.org | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 165 | // If the color attachment is a texture, returns its type; otherwise, |
| 166 | // returns 0. |
zmo | 21608f88 | 2015-08-07 21:49:43 | [diff] [blame] | 167 | GLenum GetReadBufferTextureType() const; |
James Darpinian | 98d0719 | 2018-10-19 23:42:02 | [diff] [blame] | 168 | bool GetReadBufferIsMultisampledTexture() const; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 169 | |
| 170 | // Verify all the rules in OpenGL ES 2.0.25 4.4.5 are followed. |
| 171 | // Returns GL_FRAMEBUFFER_COMPLETE if there are no reasons we know we can't |
| 172 | // use this combination of attachments. Otherwise returns the value |
| 173 | // that glCheckFramebufferStatus should return for this set of attachments. |
| 174 | // Note that receiving GL_FRAMEBUFFER_COMPLETE from this function does |
| 175 | // not mean the real OpenGL will consider it framebuffer complete. It just |
| 176 | // means it passed our tests. |
zmo | 59b6cc5 | 2016-01-30 02:35:59 | [diff] [blame] | 177 | GLenum IsPossiblyComplete(const FeatureInfo* feature_info) const; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 178 | |
| 179 | // Implements optimized glGetFramebufferStatus. |
| 180 | GLenum GetStatus(TextureManager* texture_manager, GLenum target) const; |
| 181 | |
| 182 | // Check all attachments are cleared |
| 183 | bool IsCleared() const; |
| 184 | |
zmo@chromium.org | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 185 | GLenum GetDrawBuffer(GLenum draw_buffer) const; |
| 186 | |
| 187 | void SetDrawBuffers(GLsizei n, const GLenum* bufs); |
| 188 | |
zmo@chromium.org | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 189 | // If a color buffer is attached to GL_COLOR_ATTACHMENTi, enable that |
| 190 | // draw buffer for glClear(). |
zmo | d252e3ea | 2016-02-23 00:38:17 | [diff] [blame] | 191 | // Return true if the DrawBuffers() is actually called. |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 192 | bool PrepareDrawBuffersForClearingUninitializedAttachments() const; |
zmo@chromium.org | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 193 | |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 194 | // Restore |adjusted_draw_buffers_|. |
| 195 | void RestoreDrawBuffers() const; |
| 196 | |
| 197 | // Checks if a draw buffer's format and its corresponding fragment shader |
| 198 | // output's type are compatible, i.e., a signed integer typed variable is |
| 199 | // incompatible with a float or unsigned integer buffer. |
| 200 | // Return false if incompaticle. |
| 201 | // Otherwise, filter out the draw buffers that are not written to but are not |
| 202 | // NONE through DrawBuffers, to be on the safe side. Return true. |
| 203 | // This is applied before a draw call. |
| 204 | bool ValidateAndAdjustDrawBuffers(uint32_t fragment_output_type_mask, |
| 205 | uint32_t fragment_output_written_mask); |
| 206 | |
zmo | 3e2c0df | 2017-01-07 01:38:34 | [diff] [blame] | 207 | // Filter out the draw buffers that have no images attached but are not NONE |
| 208 | // through DrawBuffers, to be on the safe side. |
| 209 | // This is applied before a clear call. |
| 210 | void AdjustDrawBuffers(); |
| 211 | |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 212 | bool ContainsActiveIntegerAttachments() const; |
zmo@chromium.org | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 213 | |
zmo@chromium.org | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 214 | // Return true if any draw buffers has an alpha channel. |
| 215 | bool HasAlphaMRT() const; |
| 216 | |
zmo | 21608f88 | 2015-08-07 21:49:43 | [diff] [blame] | 217 | // Return false if any two active color attachments have different internal |
| 218 | // formats. |
| 219 | bool HasSameInternalFormatsMRT() const; |
| 220 | |
zmo | 02f3a30 | 2015-08-05 22:30:38 | [diff] [blame] | 221 | void set_read_buffer(GLenum read_buffer) { |
| 222 | read_buffer_ = read_buffer; |
| 223 | } |
| 224 | |
| 225 | GLenum read_buffer() const { |
| 226 | return read_buffer_; |
| 227 | } |
| 228 | |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 229 | // See member declaration for details. |
| 230 | // The data are only valid if fbo is complete. |
| 231 | uint32_t draw_buffer_type_mask() const { |
| 232 | return draw_buffer_type_mask_; |
| 233 | } |
| 234 | uint32_t draw_buffer_bound_mask() const { |
| 235 | return draw_buffer_bound_mask_; |
| 236 | } |
| 237 | |
Kai Ninomiya | 821895e | 2017-06-06 00:03:29 | [diff] [blame] | 238 | void UnmarkAsComplete() { framebuffer_complete_state_count_id_ = 0; } |
| 239 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 240 | private: |
| 241 | friend class FramebufferManager; |
| 242 | friend class base::RefCounted<Framebuffer>; |
| 243 | |
| 244 | ~Framebuffer(); |
| 245 | |
shrekshao | 4a1b49b | 2019-04-05 20:14:56 | [diff] [blame] | 246 | // Helper function updating cached last color attachment id bound. |
| 247 | // Called when attachments_ changed |
| 248 | void OnInsertUpdateLastColorAttachmentId(GLenum attachment); |
| 249 | void OnEraseUpdateLastColorAttachmentId(GLenum attachment); |
| 250 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 251 | void MarkAsDeleted(); |
| 252 | |
| 253 | void MarkAttachmentsAsCleared( |
| 254 | RenderbufferManager* renderbuffer_manager, |
| 255 | TextureManager* texture_manager, |
| 256 | bool cleared); |
| 257 | |
| 258 | void MarkAsComplete(unsigned state_id) { |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 259 | UpdateDrawBufferMasks(); |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 260 | framebuffer_complete_state_count_id_ = state_id; |
| 261 | } |
| 262 | |
| 263 | unsigned framebuffer_complete_state_count_id() const { |
| 264 | return framebuffer_complete_state_count_id_; |
| 265 | } |
| 266 | |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 267 | // Cache color attachments' base type mask (FLOAT, INT, UINT) and bound mask. |
| 268 | // If an attachment point has no image, it's set as UNDEFINED_TYPE. |
| 269 | // This call is only valid on a complete fbo. |
| 270 | void UpdateDrawBufferMasks(); |
| 271 | |
zmo | 3e2c0df | 2017-01-07 01:38:34 | [diff] [blame] | 272 | // Helper for ValidateAndAdjustDrawBuffers() and AdjustDrawBuffers(). |
| 273 | void AdjustDrawBuffersImpl(uint32_t desired_mask); |
| 274 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 275 | // The managers that owns this. |
| 276 | FramebufferManager* manager_; |
| 277 | |
| 278 | bool deleted_; |
| 279 | |
| 280 | // Service side framebuffer id. |
| 281 | GLuint service_id_; |
| 282 | |
| 283 | // Whether this framebuffer has ever been bound. |
| 284 | bool has_been_bound_; |
| 285 | |
| 286 | // state count when this framebuffer was last checked for completeness. |
| 287 | unsigned framebuffer_complete_state_count_id_; |
| 288 | |
| 289 | // A map of attachments. |
Anand K Mistry | bf05511 | 2021-03-11 09:10:40 | [diff] [blame^] | 290 | using AttachmentMap = |
| 291 | base::small_map<std::unordered_map<GLenum, scoped_refptr<Attachment>>, 8>; |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 292 | AttachmentMap attachments_; |
| 293 | |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 294 | // User's draw buffers setting through DrawBuffers() call. |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 295 | std::unique_ptr<GLenum[]> draw_buffers_; |
zmo@chromium.org | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 296 | |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 297 | // If a draw buffer does not have an image, or it has no corresponding |
| 298 | // fragment shader output variable, it might be filtered out as NONE. |
| 299 | // Note that the actually draw buffers setting sent to the driver is always |
| 300 | // consistent with |adjusted_draw_buffers_|, not |draw_buffers_|. |
| 301 | std::unique_ptr<GLenum[]> adjusted_draw_buffers_; |
| 302 | |
| 303 | // Draw buffer base types: FLOAT, INT, or UINT. |
| 304 | // We have up to 16 draw buffers, each is encoded into 2 bits, total 32 bits: |
| 305 | // the lowest 2 bits for draw buffer 0, the highest 2 bits for draw buffer 15. |
| 306 | uint32_t draw_buffer_type_mask_; |
shrekshao | c50e5ea | 2019-03-07 03:34:30 | [diff] [blame] | 307 | // Same layout as above, 0x03 if it's 32bit float color attachment, 0x00 if |
| 308 | // not |
| 309 | uint32_t draw_buffer_float32_mask_; |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 310 | // Same layout as above, 2 bits per draw buffer, 0x03 if a draw buffer has a |
| 311 | // bound image, 0x00 if not. |
| 312 | uint32_t draw_buffer_bound_mask_; |
| 313 | // This is the mask for the actual draw buffers sent to driver. |
| 314 | uint32_t adjusted_draw_buffer_bound_mask_; |
shrekshao | 4a1b49b | 2019-04-05 20:14:56 | [diff] [blame] | 315 | // The largest i of all GL_COLOR_ATTACHMENTi |
| 316 | GLsizei last_color_attachment_id_; |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 317 | |
zmo | 02f3a30 | 2015-08-05 22:30:38 | [diff] [blame] | 318 | GLenum read_buffer_; |
| 319 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 320 | DISALLOW_COPY_AND_ASSIGN(Framebuffer); |
| 321 | }; |
| 322 | |
kloveless@chromium.org | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 323 | struct DecoderFramebufferState { |
kloveless@chromium.org | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 324 | DecoderFramebufferState(); |
| 325 | ~DecoderFramebufferState(); |
kloveless@chromium.org | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 326 | |
| 327 | // State saved for clearing so we can clear render buffers and then |
| 328 | // restore to these values. |
| 329 | bool clear_state_dirty; |
kloveless@chromium.org | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 330 | |
| 331 | // The currently bound framebuffers |
| 332 | scoped_refptr<Framebuffer> bound_read_framebuffer; |
| 333 | scoped_refptr<Framebuffer> bound_draw_framebuffer; |
kloveless@chromium.org | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 334 | }; |
| 335 | |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 336 | // This class keeps track of the frambebuffers and their attached renderbuffers |
| 337 | // so we can correctly clear them. |
Antoine Labour | 83a0aed1 | 2018-01-10 04:52:38 | [diff] [blame] | 338 | class GPU_GLES2_EXPORT FramebufferManager { |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 339 | public: |
Antoine Labour | 6bf94249 | 2017-06-14 00:33:42 | [diff] [blame] | 340 | FramebufferManager( |
| 341 | uint32_t max_draw_buffers, |
| 342 | uint32_t max_color_attachments, |
| 343 | FramebufferCompletenessCache* framebuffer_combo_complete_cache); |
gman@chromium.org | d304cbd | 2010-07-01 22:41:16 | [diff] [blame] | 344 | ~FramebufferManager(); |
| 345 | |
| 346 | // Must call before destruction. |
| 347 | void Destroy(bool have_context); |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 348 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 349 | // Creates a Framebuffer for the given framebuffer. |
| 350 | void CreateFramebuffer(GLuint client_id, GLuint service_id); |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 351 | |
| 352 | // Gets the framebuffer info for the given framebuffer. |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 353 | Framebuffer* GetFramebuffer(GLuint client_id); |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 354 | |
| 355 | // Removes a framebuffer info for the given framebuffer. |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 356 | void RemoveFramebuffer(GLuint client_id); |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 357 | |
gman@chromium.org | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 358 | // Gets a client id for a given service id. |
| 359 | bool GetClientId(GLuint service_id, GLuint* client_id) const; |
| 360 | |
gman@chromium.org | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 361 | void MarkAttachmentsAsCleared( |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 362 | Framebuffer* framebuffer, |
gman@chromium.org | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 363 | RenderbufferManager* renderbuffer_manager, |
| 364 | TextureManager* texture_manager); |
| 365 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 366 | void MarkAsComplete(Framebuffer* framebuffer); |
gman@chromium.org | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 367 | |
Kai Ninomiya | e576154 | 2017-09-16 04:06:43 | [diff] [blame] | 368 | bool IsComplete(const Framebuffer* framebuffer); |
gman@chromium.org | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 369 | |
| 370 | void IncFramebufferStateChangeCount() { |
| 371 | // make sure this is never 0. |
| 372 | framebuffer_state_change_count_ = |
| 373 | (framebuffer_state_change_count_ + 1) | 0x80000000U; |
| 374 | } |
| 375 | |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 376 | private: |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 377 | friend class Framebuffer; |
| 378 | |
gman@chromium.org | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 379 | void StartTracking(Framebuffer* framebuffer); |
| 380 | void StopTracking(Framebuffer* framebuffer); |
gman@chromium.org | 7c5e8b1 | 2012-04-06 00:35:24 | [diff] [blame] | 381 | |
tobiasjs | fc199b47 | 2015-08-22 00:39:06 | [diff] [blame] | 382 | FramebufferCompletenessCache* GetFramebufferComboCompleteCache() { |
Antoine Labour | 6bf94249 | 2017-06-14 00:33:42 | [diff] [blame] | 383 | return framebuffer_combo_complete_cache_; |
tobiasjs | fc199b47 | 2015-08-22 00:39:06 | [diff] [blame] | 384 | } |
| 385 | |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 386 | // Info for each framebuffer in the system. |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 387 | typedef std::unordered_map<GLuint, scoped_refptr<Framebuffer>> FramebufferMap; |
gman@chromium.org | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 388 | FramebufferMap framebuffers_; |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 389 | |
gman@chromium.org | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 390 | // Incremented anytime anything changes that might effect framebuffer |
| 391 | // state. |
| 392 | unsigned framebuffer_state_change_count_; |
| 393 | |
gman@chromium.org | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 394 | // Counts the number of Framebuffer allocated with 'this' as its manager. |
| 395 | // Allows to check no Framebuffer will outlive this. |
gman@chromium.org | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 396 | unsigned int framebuffer_count_; |
gman@chromium.org | 7c5e8b1 | 2012-04-06 00:35:24 | [diff] [blame] | 397 | |
| 398 | bool have_context_; |
| 399 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 400 | uint32_t max_draw_buffers_; |
| 401 | uint32_t max_color_attachments_; |
zmo@chromium.org | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 402 | |
Antoine Labour | 6bf94249 | 2017-06-14 00:33:42 | [diff] [blame] | 403 | FramebufferCompletenessCache* framebuffer_combo_complete_cache_; |
tobiasjs | fc199b47 | 2015-08-22 00:39:06 | [diff] [blame] | 404 | |
gman@chromium.org | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 405 | DISALLOW_COPY_AND_ASSIGN(FramebufferManager); |
| 406 | }; |
| 407 | |
| 408 | } // namespace gles2 |
| 409 | } // namespace gpu |
| 410 | |
| 411 | #endif // GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_MANAGER_H_ |