Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: src/gpu/vk/GrVkGpuCommandBuffer.cpp

Issue 2262473003: Define clear regions in terms of GrFixedClip (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_fixedcliptosrc
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
199 200 if (!clip.scissorEnabled()) {
200 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { 201 vkRect.setXYWH(0, 0, vkRT->width(), vkRT->height());
201 vkRect.fTop = vkRT->height() - rect.fBottom; 202 } else if (kBottomLeft_GrSurfaceOrigin != vkRT->origin()) {
202 vkRect.fBottom = vkRT->height() - rect.fTop; 203 vkRect = clip.scissorRect();
204 } else {
205 const SkIRect& scissor = clip.scissorRect();
206 vkRect.setLTRB(scissor.fLeft, vkRT->height() - scissor.fBottom,
207 scissor.fRight, vkRT->height() - scissor.fTop);
203 } 208 }
204 209
205 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; 210 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop };
206 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height( ) }; 211 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height( ) };
207 212
208 clearRect.baseArrayLayer = 0; 213 clearRect.baseArrayLayer = 0;
209 clearRect.layerCount = 1; 214 clearRect.layerCount = 1;
210 215
211 uint32_t stencilIndex; 216 uint32_t stencilIndex;
212 SkAssertResult(fRenderPass->stencilAttachmentIndex(&stencilIndex)); 217 SkAssertResult(fRenderPass->stencilAttachmentIndex(&stencilIndex));
213 218
214 VkClearAttachment attachment; 219 VkClearAttachment attachment;
215 attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; 220 attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
216 attachment.colorAttachment = 0; // this value shouldn't matter 221 attachment.colorAttachment = 0; // this value shouldn't matter
217 attachment.clearValue.depthStencil = vkStencilColor; 222 attachment.clearValue.depthStencil = vkStencilColor;
218 223
219 fCommandBuffer->clearAttachments(fGpu, 1, &attachment, 1, &clearRect); 224 fCommandBuffer->clearAttachments(fGpu, 1, &attachment, 1, &clearRect);
220 fIsEmpty = false; 225 fIsEmpty = false;
221 } 226 }
222 227
223 void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const SkIRect& rect, GrColor color) { 228 void GrVkGpuCommandBuffer::onClear(GrRenderTarget* target, const GrFixedClip& cl ip, GrColor color) {
224 // parent class should never let us get here with no RT 229 // parent class should never let us get here with no RT
225 SkASSERT(target); 230 SkASSERT(target);
226 231
227 VkClearColorValue vkColor; 232 VkClearColorValue vkColor;
228 GrColorToRGBAFloat(color, vkColor.float32); 233 GrColorToRGBAFloat(color, vkColor.float32);
229 234
230 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); 235 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target);
231 236
232 if (fIsEmpty && rect.width() == target->width() && rect.height() == target-> height()) { 237 if (fIsEmpty && !clip.scissorEnabled()) {
233 // We will change the render pass to do a clear load instead 238 // We will change the render pass to do a clear load instead
234 GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR, 239 GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR,
235 VK_ATTACHMENT_STORE_OP_STORE); 240 VK_ATTACHMENT_STORE_OP_STORE);
236 GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD, 241 GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD,
237 VK_ATTACHMENT_STORE_OP_STORE); 242 VK_ATTACHMENT_STORE_OP_STORE);
238 GrVkRenderPass::LoadStoreOps vkResolveOps(VK_ATTACHMENT_LOAD_OP_LOAD, 243 GrVkRenderPass::LoadStoreOps vkResolveOps(VK_ATTACHMENT_LOAD_OP_LOAD,
239 VK_ATTACHMENT_STORE_OP_STORE); 244 VK_ATTACHMENT_STORE_OP_STORE);
240 245
241 const GrVkRenderPass* oldRP = fRenderPass; 246 const GrVkRenderPass* oldRP = fRenderPass;
242 247
(...skipping 14 matching lines...) Expand all
257 SkASSERT(fRenderPass->isCompatible(*oldRP)); 262 SkASSERT(fRenderPass->isCompatible(*oldRP));
258 oldRP->unref(fGpu); 263 oldRP->unref(fGpu);
259 264
260 GrColorToRGBAFloat(color, fColorClearValue.color.float32); 265 GrColorToRGBAFloat(color, fColorClearValue.color.float32);
261 return; 266 return;
262 } 267 }
263 268
264 // We always do a sub rect clear with clearAttachments since we are inside a render pass 269 // We always do a sub rect clear with clearAttachments since we are inside a render pass
265 VkClearRect clearRect; 270 VkClearRect clearRect;
266 // Flip rect if necessary 271 // Flip rect if necessary
267 SkIRect vkRect = rect; 272 SkIRect vkRect;
268 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { 273 if (!clip.scissorEnabled()) {
269 vkRect.fTop = vkRT->height() - rect.fBottom; 274 vkRect.setXYWH(0, 0, vkRT->width(), vkRT->height());
270 vkRect.fBottom = vkRT->height() - rect.fTop; 275 } else if (kBottomLeft_GrSurfaceOrigin != vkRT->origin()) {
276 vkRect = clip.scissorRect();
277 } else {
278 const SkIRect& scissor = clip.scissorRect();
279 vkRect.setLTRB(scissor.fLeft, vkRT->height() - scissor.fBottom,
280 scissor.fRight, vkRT->height() - scissor.fTop);
271 } 281 }
272 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; 282 clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop };
273 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height( ) }; 283 clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height( ) };
274 clearRect.baseArrayLayer = 0; 284 clearRect.baseArrayLayer = 0;
275 clearRect.layerCount = 1; 285 clearRect.layerCount = 1;
276 286
277 uint32_t colorIndex; 287 uint32_t colorIndex;
278 SkAssertResult(fRenderPass->colorAttachmentIndex(&colorIndex)); 288 SkAssertResult(fRenderPass->colorAttachmentIndex(&colorIndex));
279 289
280 VkClearAttachment attachment; 290 VkClearAttachment attachment;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 fGpu->stats()->incNumDraws(); 440 fGpu->stats()->incNumDraws();
431 } while ((nonIdxMesh = iter.next())); 441 } while ((nonIdxMesh = iter.next()));
432 } 442 }
433 443
434 // Technically we don't have to call this here (since there is a safety chec k in 444 // 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 445 // pipelineState:setData but this will allow for quicker freeing of resource s if the
436 // pipelineState sits in a cache for a while. 446 // pipelineState sits in a cache for a while.
437 pipelineState->freeTempResources(fGpu); 447 pipelineState->freeTempResources(fGpu);
438 } 448 }
439 449
OLDNEW
« src/gpu/batches/GrClearBatch.h ('K') | « src/gpu/vk/GrVkGpuCommandBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698