Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
skgpu::graphite::VulkanCommandBuffer Class Referencefinal

#include <VulkanCommandBuffer.h>

Inheritance diagram for skgpu::graphite::VulkanCommandBuffer:
skgpu::graphite::CommandBuffer

Public Member Functions

 ~VulkanCommandBuffer () override
 
bool setNewCommandBufferResources () override
 
bool submit (VkQueue)
 
bool isFinished ()
 
void waitUntilFinished ()
 
void addBufferMemoryBarrier (const Resource *resource, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkBufferMemoryBarrier *barrier)
 
void addBufferMemoryBarrier (VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkBufferMemoryBarrier *barrier)
 
void addImageMemoryBarrier (const Resource *, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, bool byRegion, VkImageMemoryBarrier *barrier)
 
- Public Member Functions inherited from skgpu::graphite::CommandBuffer
virtual ~CommandBuffer ()
 
void trackResource (sk_sp< Resource > resource)
 
void trackCommandBufferResource (sk_sp< Resource > resource)
 
void resetCommandBuffer ()
 
virtual bool setNewCommandBufferResources ()=0
 
void addFinishedProc (sk_sp< RefCntedCallback > finishedProc)
 
void callFinishedProcs (bool success)
 
virtual void addWaitSemaphores (size_t numWaitSemaphores, const BackendSemaphore *waitSemaphores)
 
virtual void addSignalSemaphores (size_t numWaitSemaphores, const BackendSemaphore *signalSemaphores)
 
virtual void prepareSurfaceForStateUpdate (SkSurface *targetSurface, const MutableTextureState *newState)
 
void addBuffersToAsyncMapOnSubmit (SkSpan< const sk_sp< Buffer > >)
 
SkSpan< const sk_sp< Buffer > > buffersToAsyncMapOnSubmit () const
 
bool addRenderPass (const RenderPassDesc &, sk_sp< Texture > colorTexture, sk_sp< Texture > resolveTexture, sk_sp< Texture > depthStencilTexture, SkRect viewport, const DrawPassList &drawPasses)
 
bool addComputePass (DispatchGroupSpan dispatchGroups)
 
bool copyBufferToBuffer (const Buffer *srcBuffer, size_t srcOffset, sk_sp< Buffer > dstBuffer, size_t dstOffset, size_t size)
 
bool copyTextureToBuffer (sk_sp< Texture >, SkIRect srcRect, sk_sp< Buffer >, size_t bufferOffset, size_t bufferRowBytes)
 
bool copyBufferToTexture (const Buffer *, sk_sp< Texture >, const BufferTextureCopyData *, int count)
 
bool copyTextureToTexture (sk_sp< Texture > src, SkIRect srcRect, sk_sp< Texture > dst, SkIPoint dstPoint, int mipLevel)
 
bool synchronizeBufferToCpu (sk_sp< Buffer >)
 
bool clearBuffer (const Buffer *buffer, size_t offset, size_t size)
 
void setReplayTranslation (SkIVector translation)
 
void clearReplayTranslation ()
 

Static Public Member Functions

static std::unique_ptr< VulkanCommandBufferMake (const VulkanSharedContext *, VulkanResourceProvider *)
 

Additional Inherited Members

- Public Types inherited from skgpu::graphite::CommandBuffer
using DrawPassList = skia_private::TArray< std::unique_ptr< DrawPass > >
 
using DispatchGroupSpan = SkSpan< const std::unique_ptr< DispatchGroup > >
 
- Protected Member Functions inherited from skgpu::graphite::CommandBuffer
 CommandBuffer ()
 
- Protected Attributes inherited from skgpu::graphite::CommandBuffer
SkISize fRenderPassSize
 
SkIVector fReplayTranslation
 

Detailed Description

Definition at line 26 of file VulkanCommandBuffer.h.

Constructor & Destructor Documentation

◆ ~VulkanCommandBuffer()

skgpu::graphite::VulkanCommandBuffer::~VulkanCommandBuffer ( )
override

Definition at line 98 of file VulkanCommandBuffer.cpp.

98 {
99 if (fActive) {
100 // Need to end command buffer before deleting it
101 VULKAN_CALL(fSharedContext->interface(), EndCommandBuffer(fPrimaryCommandBuffer));
102 fActive = false;
103 }
104
105 if (VK_NULL_HANDLE != fSubmitFence) {
106 VULKAN_CALL(fSharedContext->interface(),
107 DestroyFence(fSharedContext->device(), fSubmitFence, nullptr));
108 }
109 // This should delete any command buffers as well.
110 VULKAN_CALL(fSharedContext->interface(),
111 DestroyCommandPool(fSharedContext->device(), fPool, nullptr));
112}
#define VULKAN_CALL(IFACE, X)
const skgpu::VulkanInterface * interface() const
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46

Member Function Documentation

◆ addBufferMemoryBarrier() [1/2]

void skgpu::graphite::VulkanCommandBuffer::addBufferMemoryBarrier ( const Resource resource,
VkPipelineStageFlags  srcStageMask,
VkPipelineStageFlags  dstStageMask,
VkBufferMemoryBarrier barrier 
)

Definition at line 1438 of file VulkanCommandBuffer.cpp.

1441 {
1443 this->pipelineBarrier(resource,
1444 srcStageMask,
1445 dstStageMask,
1446 /*byRegion=*/false,
1447 kBufferMemory_BarrierType,
1448 barrier);
1449}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkString resource(SkPDFResourceType type, int index)

◆ addBufferMemoryBarrier() [2/2]

void skgpu::graphite::VulkanCommandBuffer::addBufferMemoryBarrier ( VkPipelineStageFlags  srcStageMask,
VkPipelineStageFlags  dstStageMask,
VkBufferMemoryBarrier barrier 
)

Definition at line 1451 of file VulkanCommandBuffer.cpp.

1453 {
1454 // We don't pass in a resource here to the command buffer. The command buffer only is using it
1455 // to hold a ref, but every place where we add a buffer memory barrier we are doing some other
1456 // command with the buffer on the command buffer. Thus those other commands will already cause
1457 // the command buffer to be holding a ref to the buffer.
1458 this->pipelineBarrier(/*resource=*/nullptr,
1459 srcStageMask,
1460 dstStageMask,
1461 /*byRegion=*/false,
1462 kBufferMemory_BarrierType,
1463 barrier);
1464}

◆ addImageMemoryBarrier()

void skgpu::graphite::VulkanCommandBuffer::addImageMemoryBarrier ( const Resource resource,
VkPipelineStageFlags  srcStageMask,
VkPipelineStageFlags  dstStageMask,
bool  byRegion,
VkImageMemoryBarrier barrier 
)

Definition at line 1466 of file VulkanCommandBuffer.cpp.

1470 {
1472 this->pipelineBarrier(resource,
1473 srcStageMask,
1474 dstStageMask,
1475 byRegion,
1476 kImageMemory_BarrierType,
1477 barrier);
1478}

◆ isFinished()

bool skgpu::graphite::VulkanCommandBuffer::isFinished ( )

Definition at line 319 of file VulkanCommandBuffer.cpp.

319 {
320 SkASSERT(!fActive);
321 if (VK_NULL_HANDLE == fSubmitFence) {
322 return true;
323 }
324
325 VkResult err;
326 VULKAN_CALL_RESULT_NOCHECK(fSharedContext->interface(), err,
327 GetFenceStatus(fSharedContext->device(), fSubmitFence));
328 switch (err) {
329 case VK_SUCCESS:
331 return true;
332
333 case VK_NOT_READY:
334 return false;
335
336 default:
337 SKGPU_LOG_F("Error calling vkGetFenceStatus. Error: %d", err);
338 SK_ABORT("Got an invalid fence status");
339 return false;
340 }
341}
#define SKGPU_LOG_F(fmt,...)
Definition: Log.h:36
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
#define VULKAN_CALL_RESULT_NOCHECK(IFACE, RESULT, X)
VkResult
Definition: vulkan_core.h:140
@ VK_ERROR_DEVICE_LOST
Definition: vulkan_core.h:150
@ VK_SUCCESS
Definition: vulkan_core.h:141
@ VK_NOT_READY
Definition: vulkan_core.h:142

◆ Make()

std::unique_ptr< VulkanCommandBuffer > skgpu::graphite::VulkanCommandBuffer::Make ( const VulkanSharedContext sharedContext,
VulkanResourceProvider resourceProvider 
)
static

Definition at line 37 of file VulkanCommandBuffer.cpp.

39 {
40 // Create VkCommandPool
42 if (sharedContext->isProtected() == Protected::kYes) {
43 cmdPoolCreateFlags |= VK_COMMAND_POOL_CREATE_PROTECTED_BIT;
44 }
45
46 const VkCommandPoolCreateInfo cmdPoolInfo = {
48 nullptr, // pNext
49 cmdPoolCreateFlags, // CmdPoolCreateFlags
50 sharedContext->queueIndex(), // queueFamilyIndex
51 };
53 VkCommandPool pool;
54 VULKAN_CALL_RESULT(sharedContext,
55 result,
56 CreateCommandPool(sharedContext->device(), &cmdPoolInfo, nullptr, &pool));
57 if (result != VK_SUCCESS) {
58 return nullptr;
59 }
60
61 const VkCommandBufferAllocateInfo cmdInfo = {
63 nullptr, // pNext
64 pool, // commandPool
66 1 // bufferCount
67 };
68
69 VkCommandBuffer primaryCmdBuffer;
71 sharedContext,
72 result,
73 AllocateCommandBuffers(sharedContext->device(), &cmdInfo, &primaryCmdBuffer));
74 if (result != VK_SUCCESS) {
75 VULKAN_CALL(sharedContext->interface(),
76 DestroyCommandPool(sharedContext->device(), pool, nullptr));
77 return nullptr;
78 }
79
80 return std::unique_ptr<VulkanCommandBuffer>(new VulkanCommandBuffer(pool,
81 primaryCmdBuffer,
82 sharedContext,
83 resourceProvider));
84}
AutoreleasePool pool
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
GAsyncResult * result
@ VK_COMMAND_BUFFER_LEVEL_PRIMARY
Definition: vulkan_core.h:2178
VkFlags VkCommandPoolCreateFlags
Definition: vulkan_core.h:2821
@ VK_COMMAND_POOL_CREATE_TRANSIENT_BIT
Definition: vulkan_core.h:2816
@ VK_COMMAND_POOL_CREATE_PROTECTED_BIT
Definition: vulkan_core.h:2818
@ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO
Definition: vulkan_core.h:242
@ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO
Definition: vulkan_core.h:241

◆ setNewCommandBufferResources()

bool skgpu::graphite::VulkanCommandBuffer::setNewCommandBufferResources ( )
overridevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 137 of file VulkanCommandBuffer.cpp.

137 {
138 this->begin();
139 return true;
140}

◆ submit()

bool skgpu::graphite::VulkanCommandBuffer::submit ( VkQueue  queue)

Definition at line 267 of file VulkanCommandBuffer.cpp.

267 {
268 this->end();
269
270 auto device = fSharedContext->device();
271 VkResult err;
272
273 if (fSubmitFence == VK_NULL_HANDLE) {
274 VkFenceCreateInfo fenceInfo;
275 memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo));
278 fSharedContext, err, CreateFence(device, &fenceInfo, nullptr, &fSubmitFence));
279 if (err) {
280 fSubmitFence = VK_NULL_HANDLE;
281 return false;
282 }
283 } else {
284 // This cannot return DEVICE_LOST so we assert we succeeded.
285 VULKAN_CALL_RESULT(fSharedContext, err, ResetFences(device, 1, &fSubmitFence));
286 SkASSERT(err == VK_SUCCESS);
287 }
288
289 SkASSERT(fSubmitFence != VK_NULL_HANDLE);
290 int waitCount = fWaitSemaphores.size();
291 TArray<VkPipelineStageFlags> vkWaitStages(waitCount);
292 for (int i = 0; i < waitCount; ++i) {
293 vkWaitStages.push_back(VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
295 }
296
297 bool submitted = submit_to_queue(fSharedContext,
298 queue,
299 fSubmitFence,
300 waitCount,
301 fWaitSemaphores.data(),
302 vkWaitStages.data(),
303 /*commandBufferCount*/ 1,
304 &fPrimaryCommandBuffer,
305 fSignalSemaphores.size(),
306 fSignalSemaphores.data(),
307 fSharedContext->isProtected());
308 fWaitSemaphores.clear();
309 fSignalSemaphores.clear();
310 if (!submitted) {
311 // Destroy the fence or else we will try to wait forever for it to finish.
312 VULKAN_CALL(fSharedContext->interface(), DestroyFence(device, fSubmitFence, nullptr));
313 fSubmitFence = VK_NULL_HANDLE;
314 return false;
315 }
316 return true;
317}
int size() const
Definition: SkTArray.h:421
VkDevice device
Definition: main.cc:53
VkQueue queue
Definition: main.cc:55
static bool submit_to_queue(const VulkanSharedContext *sharedContext, VkQueue queue, VkFence fence, uint32_t waitCount, const VkSemaphore *waitSemaphores, const VkPipelineStageFlags *waitStages, uint32_t commandBufferCount, const VkCommandBuffer *commandBuffers, uint32_t signalCount, const VkSemaphore *signalSemaphores, Protected protectedContext)
VkStructureType sType
Definition: vulkan_core.h:3386
@ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
Definition: vulkan_core.h:2442
@ VK_PIPELINE_STAGE_TRANSFER_BIT
Definition: vulkan_core.h:2447
@ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
Definition: vulkan_core.h:210

◆ waitUntilFinished()

void skgpu::graphite::VulkanCommandBuffer::waitUntilFinished ( )

Definition at line 343 of file VulkanCommandBuffer.cpp.

343 {
344 if (fSubmitFence == VK_NULL_HANDLE) {
345 return;
346 }
347 VULKAN_CALL_ERRCHECK(fSharedContext,
348 WaitForFences(fSharedContext->device(),
349 1,
350 &fSubmitFence,
351 /*waitAll=*/true,
352 /*timeout=*/UINT64_MAX));
353}
#define VULKAN_CALL_ERRCHECK(SHARED_CONTEXT, X)

The documentation for this class was generated from the following files: