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

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

Issue 1813913002: Use dynamic state from vulkan pipelines (Closed) Base URL: https://skia.googlesource.com/skia.git@drawInterface
Patch Set: cache dynamic state updates Created 4 years, 9 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
« no previous file with comments | « src/gpu/vk/GrVkCommandBuffer.h ('k') | src/gpu/vk/GrVkGpu.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "GrVkCommandBuffer.h" 8 #include "GrVkCommandBuffer.h"
9 9
10 #include "GrVkFramebuffer.h" 10 #include "GrVkFramebuffer.h"
11 #include "GrVkImageView.h" 11 #include "GrVkImageView.h"
12 #include "GrVkPipeline.h"
12 #include "GrVkRenderPass.h" 13 #include "GrVkRenderPass.h"
13 #include "GrVkRenderTarget.h" 14 #include "GrVkRenderTarget.h"
14 #include "GrVkProgram.h" 15 #include "GrVkProgram.h"
15 #include "GrVkTransferBuffer.h" 16 #include "GrVkTransferBuffer.h"
16 #include "GrVkUtil.h" 17 #include "GrVkUtil.h"
17 18
18 GrVkCommandBuffer* GrVkCommandBuffer::Create(const GrVkGpu* gpu, VkCommandPool c mdPool) { 19 GrVkCommandBuffer* GrVkCommandBuffer::Create(const GrVkGpu* gpu, VkCommandPool c mdPool) {
19 const VkCommandBufferAllocateInfo cmdInfo = { 20 const VkCommandBufferAllocateInfo cmdInfo = {
20 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType 21 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
21 NULL, // pNext 22 NULL, // pNext
(...skipping 11 matching lines...) Expand all
33 } 34 }
34 return new GrVkCommandBuffer(cmdBuffer); 35 return new GrVkCommandBuffer(cmdBuffer);
35 } 36 }
36 37
37 GrVkCommandBuffer::~GrVkCommandBuffer() { 38 GrVkCommandBuffer::~GrVkCommandBuffer() {
38 // Should have ended any render pass we're in the middle of 39 // Should have ended any render pass we're in the middle of
39 SkASSERT(!fActiveRenderPass); 40 SkASSERT(!fActiveRenderPass);
40 } 41 }
41 42
42 void GrVkCommandBuffer::invalidateState() { 43 void GrVkCommandBuffer::invalidateState() {
43 fBoundVertexBuffer = 0; 44 fBoundVertexBuffer = VK_NULL_HANDLE;
44 fBoundVertexBufferIsValid = false; 45 fBoundVertexBufferIsValid = false;
45 fBoundIndexBuffer = 0; 46 fBoundIndexBuffer = VK_NULL_HANDLE;
46 fBoundIndexBufferIsValid = false; 47 fBoundIndexBufferIsValid = false;
48
49 memset(&fCachedViewport, 0, sizeof(VkViewport));
50 fCachedViewport.width = - 1.0f; // Viewport must have a width greater than 0
51
52 memset(&fCachedScissor, 0, sizeof(VkRect2D));
53 fCachedScissor.offset.x = -1; // Scissor offset must be greater that 0 to be valid
54
55 for (int i = 0; i < 4; ++i) {
56 fCachedBlendConstant[i] = -1.0;
57 }
47 } 58 }
48 59
49 void GrVkCommandBuffer::freeGPUData(const GrVkGpu* gpu) const { 60 void GrVkCommandBuffer::freeGPUData(const GrVkGpu* gpu) const {
50 SkASSERT(!fIsActive); 61 SkASSERT(!fIsActive);
51 SkASSERT(!fActiveRenderPass); 62 SkASSERT(!fActiveRenderPass);
52 for (int i = 0; i < fTrackedResources.count(); ++i) { 63 for (int i = 0; i < fTrackedResources.count(); ++i) {
53 fTrackedResources[i]->unref(gpu); 64 fTrackedResources[i]->unref(gpu);
54 } 65 }
55 66
56 // Destroy the fence, if any 67 // Destroy the fence, if any
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 VK_PIPELINE_BIND_POINT_ GRAPHICS, 359 VK_PIPELINE_BIND_POINT_ GRAPHICS,
349 layout, 360 layout,
350 firstSet, 361 firstSet,
351 setCount, 362 setCount,
352 descriptorSets, 363 descriptorSets,
353 dynamicOffsetCount, 364 dynamicOffsetCount,
354 dynamicOffsets)); 365 dynamicOffsets));
355 program->addUniformResources(*this); 366 program->addUniformResources(*this);
356 } 367 }
357 368
369 void GrVkCommandBuffer::bindPipeline(const GrVkGpu* gpu, const GrVkPipeline* pip eline) {
370 SkASSERT(fIsActive);
371 SkASSERT(fActiveRenderPass);
372 GR_VK_CALL(gpu->vkInterface(), CmdBindPipeline(fCmdBuffer,
373 VK_PIPELINE_BIND_POINT_GRAPHI CS,
374 pipeline->pipeline()));
375 addResource(pipeline);
376 }
377
358 void GrVkCommandBuffer::drawIndexed(const GrVkGpu* gpu, 378 void GrVkCommandBuffer::drawIndexed(const GrVkGpu* gpu,
359 uint32_t indexCount, 379 uint32_t indexCount,
360 uint32_t instanceCount, 380 uint32_t instanceCount,
361 uint32_t firstIndex, 381 uint32_t firstIndex,
362 int32_t vertexOffset, 382 int32_t vertexOffset,
363 uint32_t firstInstance) const { 383 uint32_t firstInstance) const {
364 SkASSERT(fIsActive); 384 SkASSERT(fIsActive);
365 SkASSERT(fActiveRenderPass); 385 SkASSERT(fActiveRenderPass);
366 GR_VK_CALL(gpu->vkInterface(), CmdDrawIndexed(fCmdBuffer, 386 GR_VK_CALL(gpu->vkInterface(), CmdDrawIndexed(fCmdBuffer,
367 indexCount, 387 indexCount,
368 instanceCount, 388 instanceCount,
369 firstIndex, 389 firstIndex,
370 vertexOffset, 390 vertexOffset,
371 firstInstance)); 391 firstInstance));
372 } 392 }
373 393
374 void GrVkCommandBuffer::draw(const GrVkGpu* gpu, 394 void GrVkCommandBuffer::draw(const GrVkGpu* gpu,
375 uint32_t vertexCount, 395 uint32_t vertexCount,
376 uint32_t instanceCount, 396 uint32_t instanceCount,
377 uint32_t firstVertex, 397 uint32_t firstVertex,
378 uint32_t firstInstance) const { 398 uint32_t firstInstance) const {
379 SkASSERT(fIsActive); 399 SkASSERT(fIsActive);
380 SkASSERT(fActiveRenderPass); 400 SkASSERT(fActiveRenderPass);
381 GR_VK_CALL(gpu->vkInterface(), CmdDraw(fCmdBuffer, 401 GR_VK_CALL(gpu->vkInterface(), CmdDraw(fCmdBuffer,
382 vertexCount, 402 vertexCount,
383 instanceCount, 403 instanceCount,
384 firstVertex, 404 firstVertex,
385 firstInstance)); 405 firstInstance));
386 } 406 }
407
408 void GrVkCommandBuffer::setViewport(const GrVkGpu* gpu,
409 uint32_t firstViewport,
410 uint32_t viewportCount,
411 const VkViewport* viewports) {
412 SkASSERT(fIsActive);
413 SkASSERT(1 == viewportCount);
414 if (memcmp(viewports, &fCachedViewport, sizeof(VkViewport))) {
415 GR_VK_CALL(gpu->vkInterface(), CmdSetViewport(fCmdBuffer,
416 firstViewport,
417 viewportCount,
418 viewports));
419 fCachedViewport = viewports[0];
420 }
421 }
422
423 void GrVkCommandBuffer::setScissor(const GrVkGpu* gpu,
424 uint32_t firstScissor,
425 uint32_t scissorCount,
426 const VkRect2D* scissors) {
427 SkASSERT(fIsActive);
428 SkASSERT(1 == scissorCount);
429 if (memcmp(scissors, &fCachedScissor, sizeof(VkRect2D))) {
430 GR_VK_CALL(gpu->vkInterface(), CmdSetScissor(fCmdBuffer,
431 firstScissor,
432 scissorCount,
433 scissors));
434 fCachedScissor = scissors[0];
435 }
436 }
437
438 void GrVkCommandBuffer::setBlendConstants(const GrVkGpu* gpu,
439 const float blendConstants[4]) {
440 SkASSERT(fIsActive);
441 if (memcmp(blendConstants, fCachedBlendConstant, 4 * sizeof(float))) {
442 GR_VK_CALL(gpu->vkInterface(), CmdSetBlendConstants(fCmdBuffer, blendCon stants));
443 memcpy(fCachedBlendConstant, blendConstants, 4 * sizeof(float));
444 }
445 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkCommandBuffer.h ('k') | src/gpu/vk/GrVkGpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698