Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2014 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 7 | // FramebufferD3D.cpp: Implements the DefaultAttachmentD3D and FramebufferD3D classes. |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/renderer/d3d/FramebufferD3D.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 10 | |
Jamie Madill | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 11 | #include "common/bitset_utils.h" |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 12 | #include "libANGLE/Context.h" |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 13 | #include "libANGLE/Framebuffer.h" |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 14 | #include "libANGLE/FramebufferAttachment.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 15 | #include "libANGLE/Surface.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 16 | #include "libANGLE/formatutils.h" |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 17 | #include "libANGLE/renderer/ContextImpl.h" |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 18 | #include "libANGLE/renderer/d3d/ContextD3D.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 19 | #include "libANGLE/renderer/d3d/RenderTargetD3D.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 20 | #include "libANGLE/renderer/d3d/RenderbufferD3D.h" |
| 21 | #include "libANGLE/renderer/d3d/RendererD3D.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 22 | #include "libANGLE/renderer/d3d/SurfaceD3D.h" |
| 23 | #include "libANGLE/renderer/d3d/SwapChainD3D.h" |
| 24 | #include "libANGLE/renderer/d3d/TextureD3D.h" |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 25 | |
| 26 | namespace rx |
| 27 | { |
| 28 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 29 | namespace |
| 30 | { |
| 31 | |
| 32 | ClearParameters GetClearParameters(const gl::State &state, GLbitfield mask) |
| 33 | { |
| 34 | ClearParameters clearParams; |
| 35 | memset(&clearParams, 0, sizeof(ClearParameters)); |
| 36 | |
| 37 | const auto &blendState = state.getBlendState(); |
| 38 | |
| 39 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 40 | { |
| 41 | clearParams.clearColor[i] = false; |
| 42 | } |
Shahmeer Esmail | 5416f75 | 2017-03-09 22:02:43 -0800 | [diff] [blame] | 43 | clearParams.colorF = state.getColorClearValue(); |
| 44 | clearParams.colorType = GL_FLOAT; |
| 45 | clearParams.colorMaskRed = blendState.colorMaskRed; |
| 46 | clearParams.colorMaskGreen = blendState.colorMaskGreen; |
| 47 | clearParams.colorMaskBlue = blendState.colorMaskBlue; |
| 48 | clearParams.colorMaskAlpha = blendState.colorMaskAlpha; |
| 49 | clearParams.clearDepth = false; |
| 50 | clearParams.depthValue = state.getDepthClearValue(); |
| 51 | clearParams.clearStencil = false; |
| 52 | clearParams.stencilValue = state.getStencilClearValue(); |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 53 | clearParams.stencilWriteMask = state.getDepthStencilState().stencilWritemask; |
Shahmeer Esmail | 5416f75 | 2017-03-09 22:02:43 -0800 | [diff] [blame] | 54 | clearParams.scissorEnabled = state.isScissorTestEnabled(); |
| 55 | clearParams.scissor = state.getScissor(); |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 56 | |
| 57 | const gl::Framebuffer *framebufferObject = state.getDrawFramebuffer(); |
| 58 | if (mask & GL_COLOR_BUFFER_BIT) |
| 59 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 60 | if (framebufferObject->hasEnabledDrawBuffer()) |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 61 | { |
| 62 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 63 | { |
| 64 | clearParams.clearColor[i] = true; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 70 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 71 | if (state.getDepthStencilState().depthMask && |
| 72 | framebufferObject->getDepthbuffer() != nullptr) |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 73 | { |
| 74 | clearParams.clearDepth = true; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 79 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 80 | if (framebufferObject->getStencilbuffer() != nullptr && |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 81 | framebufferObject->getStencilbuffer()->getStencilSize() > 0) |
| 82 | { |
| 83 | clearParams.clearStencil = true; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return clearParams; |
| 88 | } |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 89 | } |
| 90 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 91 | ClearParameters::ClearParameters() = default; |
| 92 | |
| 93 | ClearParameters::ClearParameters(const ClearParameters &other) = default; |
| 94 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 95 | FramebufferD3D::FramebufferD3D(const gl::FramebufferState &data, RendererD3D *renderer) |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 96 | : FramebufferImpl(data), mRenderer(renderer), mDummyAttachment() |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 97 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | FramebufferD3D::~FramebufferD3D() |
| 101 | { |
| 102 | } |
| 103 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 104 | angle::Result FramebufferD3D::clear(const gl::Context *context, GLbitfield mask) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 105 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 106 | ClearParameters clearParams = GetClearParameters(context->getGLState(), mask); |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 107 | return clearImpl(context, clearParams); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 108 | } |
| 109 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 110 | angle::Result FramebufferD3D::clearBufferfv(const gl::Context *context, |
| 111 | GLenum buffer, |
| 112 | GLint drawbuffer, |
| 113 | const GLfloat *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 114 | { |
| 115 | // glClearBufferfv can be called to clear the color buffer or depth buffer |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 116 | ClearParameters clearParams = GetClearParameters(context->getGLState(), 0); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 117 | |
| 118 | if (buffer == GL_COLOR) |
| 119 | { |
| 120 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 121 | { |
| 122 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 123 | } |
Shahmeer Esmail | 5416f75 | 2017-03-09 22:02:43 -0800 | [diff] [blame] | 124 | clearParams.colorF = gl::ColorF(values[0], values[1], values[2], values[3]); |
| 125 | clearParams.colorType = GL_FLOAT; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | if (buffer == GL_DEPTH) |
| 129 | { |
| 130 | clearParams.clearDepth = true; |
Shahmeer Esmail | 5416f75 | 2017-03-09 22:02:43 -0800 | [diff] [blame] | 131 | clearParams.depthValue = values[0]; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 132 | } |
| 133 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 134 | return clearImpl(context, clearParams); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 135 | } |
| 136 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 137 | angle::Result FramebufferD3D::clearBufferuiv(const gl::Context *context, |
| 138 | GLenum buffer, |
| 139 | GLint drawbuffer, |
| 140 | const GLuint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 141 | { |
| 142 | // glClearBufferuiv can only be called to clear a color buffer |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 143 | ClearParameters clearParams = GetClearParameters(context->getGLState(), 0); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 144 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 145 | { |
| 146 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 147 | } |
Shahmeer Esmail | 5416f75 | 2017-03-09 22:02:43 -0800 | [diff] [blame] | 148 | clearParams.colorUI = gl::ColorUI(values[0], values[1], values[2], values[3]); |
| 149 | clearParams.colorType = GL_UNSIGNED_INT; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 150 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 151 | return clearImpl(context, clearParams); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 152 | } |
| 153 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 154 | angle::Result FramebufferD3D::clearBufferiv(const gl::Context *context, |
| 155 | GLenum buffer, |
| 156 | GLint drawbuffer, |
| 157 | const GLint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 158 | { |
| 159 | // glClearBufferiv can be called to clear the color buffer or stencil buffer |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 160 | ClearParameters clearParams = GetClearParameters(context->getGLState(), 0); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 161 | |
| 162 | if (buffer == GL_COLOR) |
| 163 | { |
| 164 | for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++) |
| 165 | { |
| 166 | clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i)); |
| 167 | } |
Shahmeer Esmail | 5416f75 | 2017-03-09 22:02:43 -0800 | [diff] [blame] | 168 | clearParams.colorI = gl::ColorI(values[0], values[1], values[2], values[3]); |
| 169 | clearParams.colorType = GL_INT; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | if (buffer == GL_STENCIL) |
| 173 | { |
| 174 | clearParams.clearStencil = true; |
Jamie Madill | 805d281 | 2017-09-20 13:21:42 -0400 | [diff] [blame] | 175 | clearParams.stencilValue = values[0]; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 176 | } |
| 177 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 178 | return clearImpl(context, clearParams); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 179 | } |
| 180 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 181 | angle::Result FramebufferD3D::clearBufferfi(const gl::Context *context, |
| 182 | GLenum buffer, |
| 183 | GLint drawbuffer, |
| 184 | GLfloat depth, |
| 185 | GLint stencil) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 186 | { |
| 187 | // glClearBufferfi can only be called to clear a depth stencil buffer |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 188 | ClearParameters clearParams = GetClearParameters(context->getGLState(), 0); |
Shahmeer Esmail | 5416f75 | 2017-03-09 22:02:43 -0800 | [diff] [blame] | 189 | clearParams.clearDepth = true; |
| 190 | clearParams.depthValue = depth; |
| 191 | clearParams.clearStencil = true; |
| 192 | clearParams.stencilValue = stencil; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 193 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 194 | return clearImpl(context, clearParams); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 195 | } |
| 196 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 197 | GLenum FramebufferD3D::getImplementationColorReadFormat(const gl::Context *context) const |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 198 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 199 | const gl::FramebufferAttachment *readAttachment = mState.getReadAttachment(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 200 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 201 | if (readAttachment == nullptr) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 202 | { |
| 203 | return GL_NONE; |
| 204 | } |
| 205 | |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 206 | RenderTargetD3D *attachmentRenderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 207 | gl::Error error = readAttachment->getRenderTarget(context, &attachmentRenderTarget); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 208 | if (error.isError()) |
| 209 | { |
| 210 | return GL_NONE; |
| 211 | } |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 212 | |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 213 | GLenum implementationFormat = getRenderTargetImplementationFormat(attachmentRenderTarget); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 214 | const gl::InternalFormat &implementationFormatInfo = |
| 215 | gl::GetSizedInternalFormatInfo(implementationFormat); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 216 | |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 217 | return implementationFormatInfo.getReadPixelsFormat(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 218 | } |
| 219 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 220 | GLenum FramebufferD3D::getImplementationColorReadType(const gl::Context *context) const |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 221 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 222 | const gl::FramebufferAttachment *readAttachment = mState.getReadAttachment(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 223 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 224 | if (readAttachment == nullptr) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 225 | { |
| 226 | return GL_NONE; |
| 227 | } |
| 228 | |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 229 | RenderTargetD3D *attachmentRenderTarget = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 230 | gl::Error error = readAttachment->getRenderTarget(context, &attachmentRenderTarget); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 231 | if (error.isError()) |
| 232 | { |
| 233 | return GL_NONE; |
| 234 | } |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 235 | |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 236 | GLenum implementationFormat = getRenderTargetImplementationFormat(attachmentRenderTarget); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 237 | const gl::InternalFormat &implementationFormatInfo = |
| 238 | gl::GetSizedInternalFormatInfo(implementationFormat); |
Geoff Lang | d8a2258 | 2014-12-17 15:28:23 -0500 | [diff] [blame] | 239 | |
Geoff Lang | c71ea66 | 2017-09-26 17:06:02 -0400 | [diff] [blame] | 240 | return implementationFormatInfo.getReadPixelsType(context->getClientVersion()); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 241 | } |
| 242 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 243 | angle::Result FramebufferD3D::readPixels(const gl::Context *context, |
| 244 | const gl::Rectangle &area, |
| 245 | GLenum format, |
| 246 | GLenum type, |
| 247 | void *pixels) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 248 | { |
Frank Henigman | 739bd8b | 2017-06-19 21:02:27 -0400 | [diff] [blame] | 249 | // Clip read area to framebuffer. |
| 250 | const gl::Extents fbSize = getState().getReadAttachment()->getSize(); |
| 251 | const gl::Rectangle fbRect(0, 0, fbSize.width, fbSize.height); |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 252 | gl::Rectangle clippedArea; |
| 253 | if (!ClipRectangle(area, fbRect, &clippedArea)) |
Frank Henigman | 739bd8b | 2017-06-19 21:02:27 -0400 | [diff] [blame] | 254 | { |
| 255 | // nothing to read |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 256 | return angle::Result::Continue(); |
Frank Henigman | 739bd8b | 2017-06-19 21:02:27 -0400 | [diff] [blame] | 257 | } |
| 258 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 259 | const gl::PixelPackState &packState = context->getGLState().getPackState(); |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 260 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 261 | const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type); |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 262 | |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 263 | ContextD3D *contextD3D = GetImplAs<ContextD3D>(context); |
| 264 | |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 265 | GLuint outputPitch = 0; |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 266 | ANGLE_CHECK_HR_MATH(contextD3D, |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 267 | sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 268 | packState.rowLength, &outputPitch)); |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 269 | |
Olli Etuaho | 989cac3 | 2016-06-08 16:18:49 -0700 | [diff] [blame] | 270 | GLuint outputSkipBytes = 0; |
Jamie Madill | abfbc0f | 2018-10-09 12:48:52 -0400 | [diff] [blame] | 271 | ANGLE_CHECK_HR_MATH(contextD3D, sizedFormatInfo.computeSkipBytes( |
| 272 | type, outputPitch, 0, packState, false, &outputSkipBytes)); |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 273 | outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes + |
| 274 | (clippedArea.y - area.y) * outputPitch; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 275 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 276 | return readPixelsImpl(context, clippedArea, format, type, outputPitch, packState, |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 277 | static_cast<uint8_t *>(pixels) + outputSkipBytes); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 278 | } |
| 279 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 280 | angle::Result FramebufferD3D::blit(const gl::Context *context, |
| 281 | const gl::Rectangle &sourceArea, |
| 282 | const gl::Rectangle &destArea, |
| 283 | GLbitfield mask, |
| 284 | GLenum filter) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 285 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 286 | const auto &glState = context->getGLState(); |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 287 | const gl::Framebuffer *sourceFramebuffer = glState.getReadFramebuffer(); |
He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 288 | const gl::Rectangle *scissor = glState.isScissorTestEnabled() ? &glState.getScissor() : nullptr; |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 289 | ANGLE_TRY(blitImpl(context, sourceArea, destArea, scissor, (mask & GL_COLOR_BUFFER_BIT) != 0, |
He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 290 | (mask & GL_DEPTH_BUFFER_BIT) != 0, (mask & GL_STENCIL_BUFFER_BIT) != 0, |
| 291 | filter, sourceFramebuffer)); |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 292 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame^] | 293 | return angle::Result::Continue(); |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 296 | bool FramebufferD3D::checkStatus(const gl::Context *context) const |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 297 | { |
Geoff Lang | c252056 | 2015-04-29 11:42:33 -0400 | [diff] [blame] | 298 | // if we have both a depth and stencil buffer, they must refer to the same object |
| 299 | // since we only support packed_depth_stencil and not separate depth and stencil |
Luc Ferron | 5bdf8bd | 2018-06-20 09:51:37 -0400 | [diff] [blame] | 300 | if (mState.hasSeparateDepthAndStencilAttachments()) |
Geoff Lang | c252056 | 2015-04-29 11:42:33 -0400 | [diff] [blame] | 301 | { |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 302 | return false; |
Geoff Lang | c252056 | 2015-04-29 11:42:33 -0400 | [diff] [blame] | 303 | } |
| 304 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 305 | // D3D11 does not allow for overlapping RenderTargetViews. |
| 306 | // If WebGL compatibility is enabled, this has already been checked at a higher level. |
| 307 | ASSERT(!context->getExtensions().webglCompatibility || mState.colorAttachmentsAreUniqueImages()); |
| 308 | if (!context->getExtensions().webglCompatibility) |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 309 | { |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 310 | if (!mState.colorAttachmentsAreUniqueImages()) |
| 311 | { |
| 312 | return false; |
| 313 | } |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 316 | // D3D requires all render targets to have the same dimensions. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 317 | if (!mState.attachmentsHaveSameDimensions()) |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 318 | { |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | return true; |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 323 | } |
| 324 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 325 | angle::Result FramebufferD3D::syncState(const gl::Context *context, |
| 326 | const gl::Framebuffer::DirtyBits &dirtyBits) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 327 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 328 | if (!mColorAttachmentsForRender.valid()) |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 329 | { |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 330 | return angle::Result::Continue(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 333 | for (auto dirtyBit : dirtyBits) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 334 | { |
| 335 | if ((dirtyBit >= gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 && |
| 336 | dirtyBit < gl::Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX) || |
| 337 | dirtyBit == gl::Framebuffer::DIRTY_BIT_DRAW_BUFFERS) |
| 338 | { |
Corentin Wallez | db9e5d3 | 2017-06-12 12:05:45 -0700 | [diff] [blame] | 339 | mColorAttachmentsForRender.reset(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 340 | } |
| 341 | } |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 342 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 343 | return angle::Result::Continue(); |
Corentin Wallez | db9e5d3 | 2017-06-12 12:05:45 -0700 | [diff] [blame] | 344 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 345 | |
Corentin Wallez | db9e5d3 | 2017-06-12 12:05:45 -0700 | [diff] [blame] | 346 | const gl::AttachmentList &FramebufferD3D::getColorAttachmentsForRender(const gl::Context *context) |
| 347 | { |
| 348 | gl::DrawBufferMask activeProgramOutputs = |
| 349 | context->getContextState().getState().getProgram()->getActiveOutputVariables(); |
| 350 | |
| 351 | if (mColorAttachmentsForRender.valid() && mCurrentActiveProgramOutputs == activeProgramOutputs) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 352 | { |
Corentin Wallez | db9e5d3 | 2017-06-12 12:05:45 -0700 | [diff] [blame] | 353 | return mColorAttachmentsForRender.value(); |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 354 | } |
| 355 | |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 356 | // Does not actually free memory |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 357 | gl::AttachmentList colorAttachmentsForRender; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 358 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 359 | const auto &colorAttachments = mState.getColorAttachments(); |
| 360 | const auto &drawBufferStates = mState.getDrawBufferStates(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 361 | const auto &workarounds = mRenderer->getWorkarounds(); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 362 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 363 | for (size_t attachmentIndex = 0; attachmentIndex < colorAttachments.size(); ++attachmentIndex) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 364 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 365 | GLenum drawBufferState = drawBufferStates[attachmentIndex]; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 366 | const gl::FramebufferAttachment &colorAttachment = colorAttachments[attachmentIndex]; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 367 | |
Corentin Wallez | db9e5d3 | 2017-06-12 12:05:45 -0700 | [diff] [blame] | 368 | if (colorAttachment.isAttached() && drawBufferState != GL_NONE && |
| 369 | activeProgramOutputs[attachmentIndex]) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 370 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 371 | ASSERT(drawBufferState == GL_BACK || |
| 372 | drawBufferState == (GL_COLOR_ATTACHMENT0_EXT + attachmentIndex)); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 373 | colorAttachmentsForRender.push_back(&colorAttachment); |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 374 | } |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 375 | else if (!workarounds.mrtPerfWorkaround) |
| 376 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 377 | colorAttachmentsForRender.push_back(nullptr); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 378 | } |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 379 | } |
| 380 | |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 381 | // When rendering with no render target on D3D, two bugs lead to incorrect behavior on Intel |
| 382 | // drivers < 4815. The rendering samples always pass neglecting discard statements in pixel |
| 383 | // shader. We add a dummy texture as render target in such case. |
| 384 | if (mRenderer->getWorkarounds().addDummyTextureNoRenderTarget && |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 385 | colorAttachmentsForRender.empty() && activeProgramOutputs.any()) |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 386 | { |
| 387 | static_assert(static_cast<size_t>(activeProgramOutputs.size()) <= 32, |
| 388 | "Size of active program outputs should less or equal than 32."); |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 389 | const GLuint activeProgramLocation = static_cast<GLuint>( |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 390 | gl::ScanForward(static_cast<uint32_t>(activeProgramOutputs.bits()))); |
| 391 | |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 392 | if (mDummyAttachment.isAttached() && |
| 393 | (mDummyAttachment.getBinding() - GL_COLOR_ATTACHMENT0) == activeProgramLocation) |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 394 | { |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 395 | colorAttachmentsForRender.push_back(&mDummyAttachment); |
| 396 | } |
| 397 | else |
| 398 | { |
| 399 | // Remove dummy attachment to prevents us from leaking it, and the program may require |
| 400 | // it to be attached to a new binding point. |
| 401 | if (mDummyAttachment.isAttached()) |
| 402 | { |
| 403 | mDummyAttachment.detach(context); |
| 404 | } |
| 405 | |
| 406 | gl::Texture *dummyTex = nullptr; |
| 407 | // TODO(Jamie): Handle error if dummy texture can't be created. |
Jamie Madill | ec1fe5b | 2018-08-10 10:05:52 -0400 | [diff] [blame] | 408 | (void)mRenderer->getIncompleteTexture(context, gl::TextureType::_2D, &dummyTex); |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 409 | if (dummyTex) |
| 410 | { |
| 411 | |
| 412 | gl::ImageIndex index = gl::ImageIndex::Make2D(0); |
| 413 | mDummyAttachment = gl::FramebufferAttachment( |
| 414 | context, GL_TEXTURE, GL_COLOR_ATTACHMENT0_EXT + activeProgramLocation, index, |
| 415 | dummyTex); |
| 416 | colorAttachmentsForRender.push_back(&mDummyAttachment); |
| 417 | } |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 421 | mColorAttachmentsForRender = std::move(colorAttachmentsForRender); |
Corentin Wallez | db9e5d3 | 2017-06-12 12:05:45 -0700 | [diff] [blame] | 422 | mCurrentActiveProgramOutputs = activeProgramOutputs; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 423 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 424 | return mColorAttachmentsForRender.value(); |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 425 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 426 | |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 427 | void FramebufferD3D::destroy(const gl::Context *context) |
| 428 | { |
| 429 | if (mDummyAttachment.isAttached()) |
| 430 | { |
| 431 | mDummyAttachment.detach(context); |
| 432 | } |
| 433 | } |
| 434 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 435 | } // namespace rx |