| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrVkGpuCommandBuffer.h" | 8 #include "GrVkGpuCommandBuffer.h" |
| 9 | 9 |
| 10 #include "GrFixedClip.h" |
| 10 #include "GrMesh.h" | 11 #include "GrMesh.h" |
| 11 #include "GrPipeline.h" | 12 #include "GrPipeline.h" |
| 12 #include "GrRenderTargetPriv.h" | 13 #include "GrRenderTargetPriv.h" |
| 13 #include "GrTextureAccess.h" | 14 #include "GrTextureAccess.h" |
| 14 #include "GrTexturePriv.h" | 15 #include "GrTexturePriv.h" |
| 15 #include "GrVkCommandBuffer.h" | 16 #include "GrVkCommandBuffer.h" |
| 16 #include "GrVkGpu.h" | 17 #include "GrVkGpu.h" |
| 17 #include "GrVkPipeline.h" | 18 #include "GrVkPipeline.h" |
| 18 #include "GrVkRenderPass.h" | 19 #include "GrVkRenderPass.h" |
| 19 #include "GrVkRenderTarget.h" | 20 #include "GrVkRenderTarget.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 vkResolveOps, | 160 vkResolveOps, |
| 160 vkStencilOps); | 161 vkStencilOps); |
| 161 } | 162 } |
| 162 | 163 |
| 163 SkASSERT(fRenderPass->isCompatible(*oldRP)); | 164 SkASSERT(fRenderPass->isCompatible(*oldRP)); |
| 164 oldRP->unref(fGpu); | 165 oldRP->unref(fGpu); |
| 165 } | 166 } |
| 166 } | 167 } |
| 167 | 168 |
| 168 void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* target, | 169 void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* target, |
| 169 const SkIRect& rect, | 170 const GrFixedClip& clip, |
| 170 bool insideClip) { | 171 bool insideStencilMask) { |
| 171 SkASSERT(target); | 172 SkASSERT(target); |
| 172 | 173 |
| 173 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); | 174 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); |
| 174 GrStencilAttachment* sb = target->renderTargetPriv().getStencilAttachment(); | 175 GrStencilAttachment* sb = target->renderTargetPriv().getStencilAttachment(); |
| 175 // this should only be called internally when we know we have a | 176 // this should only be called internally when we know we have a |
| 176 // stencil buffer. | 177 // stencil buffer. |
| 177 SkASSERT(sb); | 178 SkASSERT(sb); |
| 178 int stencilBitCount = sb->bits(); | 179 int stencilBitCount = sb->bits(); |
| 179 | 180 |
| 180 // The contract with the callers does not guarantee that we preserve all bit
s in the stencil | 181 // The contract with the callers does not guarantee that we preserve all bit
s in the stencil |
| 181 // during this clear. Thus we will clear the entire stencil to the desired v
alue. | 182 // during this clear. Thus we will clear the entire stencil to the desired v
alue. |
| 182 | 183 |
| 183 VkClearDepthStencilValue vkStencilColor; | 184 VkClearDepthStencilValue vkStencilColor; |
| 184 memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); | 185 memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); |
| 185 if (insideClip) { | 186 if (insideStencilMask) { |
| 186 vkStencilColor.stencil = (1 << (stencilBitCount - 1)); | 187 vkStencilColor.stencil = (1 << (stencilBitCount - 1)); |
| 187 } else { | 188 } else { |
| 188 vkStencilColor.stencil = 0; | 189 vkStencilColor.stencil = 0; |
| 189 } | 190 } |
| 190 | 191 |
| 191 VkClearRect clearRect; | 192 VkClearRect clearRect; |
| 192 // Flip rect if necessary | 193 // Flip rect if necessary |
| 193 SkIRect vkRect = rect; | 194 SkIRect vkRect; |
| 194 | 195 if (!clip.scissorEnabled()) { |
| 195 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { | 196 vkRect.setXYWH(0, 0, vkRT->width(), vkRT->height()); |
| 196 vkRect.fTop = vkRT->height() - rect.fBottom; | 197 } else if (kBottomLeft_GrSurfaceOrigin != vkRT->origin()) { |
| 197 vkRect.fBottom = vkRT->height() - rect.fTop; | 198 vkRect = clip.scissorRect(); |
| 199 } else { |
| 200 const SkIRect& scissor = clip.scissorRect(); |
| 201 vkRect.setLTRB(scissor.fLeft, vkRT->height() - scissor.fBottom, |
| 202 scissor.fRight, vkRT->height() - scissor.fTop); |
| 198 } | 203 } |
| 199 | 204 |
| 200 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; | 205 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; |
| 201 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height(
) }; | 206 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height(
) }; |
| 202 | 207 |
| 203 clearRect.baseArrayLayer = 0; | 208 clearRect.baseArrayLayer = 0; |
| 204 clearRect.layerCount = 1; | 209 clearRect.layerCount = 1; |
| 205 | 210 |
| 206 uint32_t stencilIndex; | 211 uint32_t stencilIndex; |
| 207 SkAssertResult(fRenderPass->stencilAttachmentIndex(&stencilIndex)); | 212 SkAssertResult(fRenderPass->stencilAttachmentIndex(&stencilIndex)); |
| 208 | 213 |
| 209 VkClearAttachment attachment; | 214 VkClearAttachment attachment; |
| 210 attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; | 215 attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 211 attachment.colorAttachment = 0; // this value shouldn't matter | 216 attachment.colorAttachment = 0; // this value shouldn't matter |
| 212 attachment.clearValue.depthStencil = vkStencilColor; | 217 attachment.clearValue.depthStencil = vkStencilColor; |
| 213 | 218 |
| 214 fCommandBuffer->clearAttachments(fGpu, 1, &attachment, 1, &clearRect); | 219 fCommandBuffer->clearAttachments(fGpu, 1, &attachment, 1, &clearRect); |
| 215 fIsEmpty = false; | 220 fIsEmpty = false; |
| 216 } | 221 } |
| 217 | 222 |
| 218 void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const SkIRect& rect,
GrColor color) { | 223 void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const GrFixedClip& cl
ip, GrColor color) { |
| 219 // parent class should never let us get here with no RT | 224 // parent class should never let us get here with no RT |
| 220 SkASSERT(target); | 225 SkASSERT(target); |
| 221 | 226 |
| 222 VkClearColorValue vkColor; | 227 VkClearColorValue vkColor; |
| 223 GrColorToRGBAFloat(color, vkColor.float32); | 228 GrColorToRGBAFloat(color, vkColor.float32); |
| 224 | 229 |
| 225 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); | 230 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); |
| 226 | 231 |
| 227 if (fIsEmpty && rect.width() == target->width() && rect.height() == target->
height()) { | 232 if (fIsEmpty && !clip.scissorEnabled()) { |
| 228 // We will change the render pass to do a clear load instead | 233 // We will change the render pass to do a clear load instead |
| 229 GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR, | 234 GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR, |
| 230 VK_ATTACHMENT_STORE_OP_STORE); | 235 VK_ATTACHMENT_STORE_OP_STORE); |
| 231 GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD, | 236 GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD, |
| 232 VK_ATTACHMENT_STORE_OP_STORE); | 237 VK_ATTACHMENT_STORE_OP_STORE); |
| 233 GrVkRenderPass::LoadStoreOps vkResolveOps(VK_ATTACHMENT_LOAD_OP_LOAD, | 238 GrVkRenderPass::LoadStoreOps vkResolveOps(VK_ATTACHMENT_LOAD_OP_LOAD, |
| 234 VK_ATTACHMENT_STORE_OP_STORE); | 239 VK_ATTACHMENT_STORE_OP_STORE); |
| 235 | 240 |
| 236 const GrVkRenderPass* oldRP = fRenderPass; | 241 const GrVkRenderPass* oldRP = fRenderPass; |
| 237 | 242 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 252 SkASSERT(fRenderPass->isCompatible(*oldRP)); | 257 SkASSERT(fRenderPass->isCompatible(*oldRP)); |
| 253 oldRP->unref(fGpu); | 258 oldRP->unref(fGpu); |
| 254 | 259 |
| 255 GrColorToRGBAFloat(color, fColorClearValue.color.float32); | 260 GrColorToRGBAFloat(color, fColorClearValue.color.float32); |
| 256 return; | 261 return; |
| 257 } | 262 } |
| 258 | 263 |
| 259 // We always do a sub rect clear with clearAttachments since we are inside a
render pass | 264 // We always do a sub rect clear with clearAttachments since we are inside a
render pass |
| 260 VkClearRect clearRect; | 265 VkClearRect clearRect; |
| 261 // Flip rect if necessary | 266 // Flip rect if necessary |
| 262 SkIRect vkRect = rect; | 267 SkIRect vkRect; |
| 263 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { | 268 if (!clip.scissorEnabled()) { |
| 264 vkRect.fTop = vkRT->height() - rect.fBottom; | 269 vkRect.setXYWH(0, 0, vkRT->width(), vkRT->height()); |
| 265 vkRect.fBottom = vkRT->height() - rect.fTop; | 270 } else if (kBottomLeft_GrSurfaceOrigin != vkRT->origin()) { |
| 271 vkRect = clip.scissorRect(); |
| 272 } else { |
| 273 const SkIRect& scissor = clip.scissorRect(); |
| 274 vkRect.setLTRB(scissor.fLeft, vkRT->height() - scissor.fBottom, |
| 275 scissor.fRight, vkRT->height() - scissor.fTop); |
| 266 } | 276 } |
| 267 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; | 277 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; |
| 268 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height(
) }; | 278 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height(
) }; |
| 269 clearRect.baseArrayLayer = 0; | 279 clearRect.baseArrayLayer = 0; |
| 270 clearRect.layerCount = 1; | 280 clearRect.layerCount = 1; |
| 271 | 281 |
| 272 uint32_t colorIndex; | 282 uint32_t colorIndex; |
| 273 SkAssertResult(fRenderPass->colorAttachmentIndex(&colorIndex)); | 283 SkAssertResult(fRenderPass->colorAttachmentIndex(&colorIndex)); |
| 274 | 284 |
| 275 VkClearAttachment attachment; | 285 VkClearAttachment attachment; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 fGpu->stats()->incNumDraws(); | 442 fGpu->stats()->incNumDraws(); |
| 433 } while ((nonIdxMesh = iter.next())); | 443 } while ((nonIdxMesh = iter.next())); |
| 434 } | 444 } |
| 435 | 445 |
| 436 // Technically we don't have to call this here (since there is a safety chec
k in | 446 // Technically we don't have to call this here (since there is a safety chec
k in |
| 437 // pipelineState:setData but this will allow for quicker freeing of resource
s if the | 447 // pipelineState:setData but this will allow for quicker freeing of resource
s if the |
| 438 // pipelineState sits in a cache for a while. | 448 // pipelineState sits in a cache for a while. |
| 439 pipelineState->freeTempResources(fGpu); | 449 pipelineState->freeTempResources(fGpu); |
| 440 } | 450 } |
| 441 | 451 |
| OLD | NEW |