Chromium Code Reviews| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 vkResolveOps, | 165 vkResolveOps, |
| 165 vkStencilOps); | 166 vkStencilOps); |
| 166 } | 167 } |
| 167 | 168 |
| 168 SkASSERT(fRenderPass->isCompatible(*oldRP)); | 169 SkASSERT(fRenderPass->isCompatible(*oldRP)); |
| 169 oldRP->unref(fGpu); | 170 oldRP->unref(fGpu); |
| 170 } | 171 } |
| 171 } | 172 } |
| 172 | 173 |
| 173 void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* target, | 174 void GrVkGpuCommandBuffer::onClearStencilClip(GrRenderTarget* target, |
| 174 const SkIRect& rect, | 175 const GrFixedClip& clip, |
| 175 bool insideClip) { | 176 bool insideStencilMask) { |
| 176 SkASSERT(target); | 177 SkASSERT(target); |
| 177 | 178 |
| 178 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); | 179 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); |
| 179 GrStencilAttachment* sb = target->renderTargetPriv().getStencilAttachment(); | 180 GrStencilAttachment* sb = target->renderTargetPriv().getStencilAttachment(); |
| 180 // this should only be called internally when we know we have a | 181 // this should only be called internally when we know we have a |
| 181 // stencil buffer. | 182 // stencil buffer. |
| 182 SkASSERT(sb); | 183 SkASSERT(sb); |
| 183 int stencilBitCount = sb->bits(); | 184 int stencilBitCount = sb->bits(); |
| 184 | 185 |
| 185 // The contract with the callers does not guarantee that we preserve all bit s in the stencil | 186 // The contract with the callers does not guarantee that we preserve all bit s in the stencil |
| 186 // during this clear. Thus we will clear the entire stencil to the desired v alue. | 187 // during this clear. Thus we will clear the entire stencil to the desired v alue. |
| 187 | 188 |
| 188 VkClearDepthStencilValue vkStencilColor; | 189 VkClearDepthStencilValue vkStencilColor; |
| 189 memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); | 190 memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); |
| 190 if (insideClip) { | 191 if (insideStencilMask) { |
| 191 vkStencilColor.stencil = (1 << (stencilBitCount - 1)); | 192 vkStencilColor.stencil = (1 << (stencilBitCount - 1)); |
| 192 } else { | 193 } else { |
| 193 vkStencilColor.stencil = 0; | 194 vkStencilColor.stencil = 0; |
| 194 } | 195 } |
| 195 | 196 |
| 196 VkClearRect clearRect; | 197 VkClearRect clearRect; |
| 197 // Flip rect if necessary | 198 // Flip rect if necessary |
| 198 SkIRect vkRect = rect; | 199 SkIRect vkRect = clip.scissorEnabled() ? clip.scissorRect() |
| 199 | 200 : SkIRect::MakeWH(vkRT->width(), vkRT ->height()); |
|
egdaniel
2016/08/19 20:09:37
For some minimal optimization, we don't need to do
csmartdalton
2016/08/19 20:46:49
Done. Looks better now.
| |
| 200 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { | 201 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { |
| 201 vkRect.fTop = vkRT->height() - rect.fBottom; | 202 SkTSwap(vkRect.fTop, vkRect.fBottom); |
| 202 vkRect.fBottom = vkRT->height() - rect.fTop; | 203 vkRect.fTop = vkRT->height() - vkRect.fTop; |
| 204 vkRect.fBottom = vkRT->height() - vkRect.fBottom; | |
| 203 } | 205 } |
| 204 | 206 |
| 205 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; | 207 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; |
| 206 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height( ) }; | 208 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height( ) }; |
| 207 | 209 |
| 208 clearRect.baseArrayLayer = 0; | 210 clearRect.baseArrayLayer = 0; |
| 209 clearRect.layerCount = 1; | 211 clearRect.layerCount = 1; |
| 210 | 212 |
| 211 uint32_t stencilIndex; | 213 uint32_t stencilIndex; |
| 212 SkAssertResult(fRenderPass->stencilAttachmentIndex(&stencilIndex)); | 214 SkAssertResult(fRenderPass->stencilAttachmentIndex(&stencilIndex)); |
| 213 | 215 |
| 214 VkClearAttachment attachment; | 216 VkClearAttachment attachment; |
| 215 attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; | 217 attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 216 attachment.colorAttachment = 0; // this value shouldn't matter | 218 attachment.colorAttachment = 0; // this value shouldn't matter |
| 217 attachment.clearValue.depthStencil = vkStencilColor; | 219 attachment.clearValue.depthStencil = vkStencilColor; |
| 218 | 220 |
| 219 fCommandBuffer->clearAttachments(fGpu, 1, &attachment, 1, &clearRect); | 221 fCommandBuffer->clearAttachments(fGpu, 1, &attachment, 1, &clearRect); |
| 220 fIsEmpty = false; | 222 fIsEmpty = false; |
| 221 } | 223 } |
| 222 | 224 |
| 223 void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const SkIRect& rect, GrColor color) { | 225 void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const GrFixedClip& cl ip, GrColor color) { |
| 224 // parent class should never let us get here with no RT | 226 // parent class should never let us get here with no RT |
| 225 SkASSERT(target); | 227 SkASSERT(target); |
| 226 | 228 |
| 227 VkClearColorValue vkColor; | 229 VkClearColorValue vkColor; |
| 228 GrColorToRGBAFloat(color, vkColor.float32); | 230 GrColorToRGBAFloat(color, vkColor.float32); |
| 229 | 231 |
| 230 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); | 232 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); |
| 231 | 233 |
| 232 if (fIsEmpty && rect.width() == target->width() && rect.height() == target-> height()) { | 234 if (fIsEmpty && !clip.scissorEnabled()) { |
| 233 // We will change the render pass to do a clear load instead | 235 // We will change the render pass to do a clear load instead |
| 234 GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR, | 236 GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR, |
| 235 VK_ATTACHMENT_STORE_OP_STORE); | 237 VK_ATTACHMENT_STORE_OP_STORE); |
| 236 GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD, | 238 GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD, |
| 237 VK_ATTACHMENT_STORE_OP_STORE); | 239 VK_ATTACHMENT_STORE_OP_STORE); |
| 238 GrVkRenderPass::LoadStoreOps vkResolveOps(VK_ATTACHMENT_LOAD_OP_LOAD, | 240 GrVkRenderPass::LoadStoreOps vkResolveOps(VK_ATTACHMENT_LOAD_OP_LOAD, |
| 239 VK_ATTACHMENT_STORE_OP_STORE); | 241 VK_ATTACHMENT_STORE_OP_STORE); |
| 240 | 242 |
| 241 const GrVkRenderPass* oldRP = fRenderPass; | 243 const GrVkRenderPass* oldRP = fRenderPass; |
| 242 | 244 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 257 SkASSERT(fRenderPass->isCompatible(*oldRP)); | 259 SkASSERT(fRenderPass->isCompatible(*oldRP)); |
| 258 oldRP->unref(fGpu); | 260 oldRP->unref(fGpu); |
| 259 | 261 |
| 260 GrColorToRGBAFloat(color, fColorClearValue.color.float32); | 262 GrColorToRGBAFloat(color, fColorClearValue.color.float32); |
| 261 return; | 263 return; |
| 262 } | 264 } |
| 263 | 265 |
| 264 // We always do a sub rect clear with clearAttachments since we are inside a render pass | 266 // We always do a sub rect clear with clearAttachments since we are inside a render pass |
| 265 VkClearRect clearRect; | 267 VkClearRect clearRect; |
| 266 // Flip rect if necessary | 268 // Flip rect if necessary |
| 267 SkIRect vkRect = rect; | 269 SkIRect vkRect = clip.scissorEnabled() ? clip.scissorRect() |
| 270 : SkIRect::MakeWH(vkRT->width(), vkRT ->height()); | |
| 268 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { | 271 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { |
| 269 vkRect.fTop = vkRT->height() - rect.fBottom; | 272 SkTSwap(vkRect.fTop, vkRect.fBottom); |
| 270 vkRect.fBottom = vkRT->height() - rect.fTop; | 273 vkRect.fTop = vkRT->height() - vkRect.fTop; |
| 274 vkRect.fBottom = vkRT->height() - vkRect.fBottom; | |
| 271 } | 275 } |
| 272 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; | 276 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; |
| 273 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height( ) }; | 277 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height( ) }; |
| 274 clearRect.baseArrayLayer = 0; | 278 clearRect.baseArrayLayer = 0; |
| 275 clearRect.layerCount = 1; | 279 clearRect.layerCount = 1; |
| 276 | 280 |
| 277 uint32_t colorIndex; | 281 uint32_t colorIndex; |
| 278 SkAssertResult(fRenderPass->colorAttachmentIndex(&colorIndex)); | 282 SkAssertResult(fRenderPass->colorAttachmentIndex(&colorIndex)); |
| 279 | 283 |
| 280 VkClearAttachment attachment; | 284 VkClearAttachment attachment; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 fGpu->stats()->incNumDraws(); | 434 fGpu->stats()->incNumDraws(); |
| 431 } while ((nonIdxMesh = iter.next())); | 435 } while ((nonIdxMesh = iter.next())); |
| 432 } | 436 } |
| 433 | 437 |
| 434 // Technically we don't have to call this here (since there is a safety chec k in | 438 // Technically we don't have to call this here (since there is a safety chec k in |
| 435 // pipelineState:setData but this will allow for quicker freeing of resource s if the | 439 // pipelineState:setData but this will allow for quicker freeing of resource s if the |
| 436 // pipelineState sits in a cache for a while. | 440 // pipelineState sits in a cache for a while. |
| 437 pipelineState->freeTempResources(fGpu); | 441 pipelineState->freeTempResources(fGpu); |
| 438 } | 442 } |
| 439 | 443 |
| OLD | NEW |