Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
GrVkCommandPool Class Reference

#include <GrVkCommandPool.h>

Inheritance diagram for GrVkCommandPool:
GrVkManagedResource GrManagedResource SkNoncopyable

Public Member Functions

VkCommandPool vkCommandPool () const
 
void reset (GrVkGpu *gpu)
 
GrVkPrimaryCommandBuffergetPrimaryCommandBuffer ()
 
std::unique_ptr< GrVkSecondaryCommandBufferfindOrCreateSecondaryCommandBuffer (GrVkGpu *gpu)
 
void recycleSecondaryCommandBuffer (GrVkSecondaryCommandBuffer *buffer)
 
void close ()
 
bool isOpen () const
 
- Public Member Functions inherited from GrVkManagedResource
 GrVkManagedResource (const GrVkGpu *gpu)
 
- Public Member Functions inherited from GrManagedResource
 GrManagedResource ()
 
virtual ~GrManagedResource ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static GrVkCommandPoolCreate (GrVkGpu *gpu)
 

Private Member Functions

void freeGPUData () const override
 

Additional Inherited Members

- Protected Attributes inherited from GrVkManagedResource
const GrVkGpufGpu
 

Detailed Description

Definition at line 21 of file GrVkCommandPool.h.

Member Function Documentation

◆ close()

void GrVkCommandPool::close ( )

Definition at line 75 of file GrVkCommandPool.cpp.

75 {
76 fOpen = false;
77}

◆ Create()

GrVkCommandPool * GrVkCommandPool::Create ( GrVkGpu gpu)
static

Definition at line 15 of file GrVkCommandPool.cpp.

15 {
17 if (gpu->protectedContext()) {
18 cmdPoolCreateFlags |= VK_COMMAND_POOL_CREATE_PROTECTED_BIT;
19 }
20
21 const VkCommandPoolCreateInfo cmdPoolInfo = {
23 nullptr, // pNext
24 cmdPoolCreateFlags, // CmdPoolCreateFlags
25 gpu->queueIndex(), // queueFamilyIndex
26 };
28 VkCommandPool pool;
29 GR_VK_CALL_RESULT(gpu, result, CreateCommandPool(gpu->device(), &cmdPoolInfo, nullptr, &pool));
30 if (result != VK_SUCCESS) {
31 return nullptr;
32 }
33
35 if (!primaryCmdBuffer) {
36 GR_VK_CALL(gpu->vkInterface(), DestroyCommandPool(gpu->device(), pool, nullptr));
37 return nullptr;
38 }
39
40 return new GrVkCommandPool(gpu, pool, primaryCmdBuffer);
41}
AutoreleasePool pool
#define GR_VK_CALL(IFACE, X)
Definition GrVkUtil.h:24
#define GR_VK_CALL_RESULT(GPU, RESULT, X)
Definition GrVkUtil.h:35
uint32_t queueIndex() const
Definition GrVkGpu.h:73
const skgpu::VulkanInterface * vkInterface() const
Definition GrVkGpu.h:60
VkDevice device() const
Definition GrVkGpu.h:71
bool protectedContext() const
Definition GrVkGpu.h:81
static GrVkPrimaryCommandBuffer * Create(GrVkGpu *gpu, VkCommandPool cmdPool)
GAsyncResult * result
VkFlags VkCommandPoolCreateFlags
VkResult
@ VK_SUCCESS
@ VK_COMMAND_POOL_CREATE_TRANSIENT_BIT
@ VK_COMMAND_POOL_CREATE_PROTECTED_BIT
@ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO

◆ findOrCreateSecondaryCommandBuffer()

std::unique_ptr< GrVkSecondaryCommandBuffer > GrVkCommandPool::findOrCreateSecondaryCommandBuffer ( GrVkGpu gpu)

Definition at line 52 of file GrVkCommandPool.cpp.

53 {
54 std::unique_ptr<GrVkSecondaryCommandBuffer> result;
55 if (!fAvailableSecondaryBuffers.empty()) {
56 result = std::move(fAvailableSecondaryBuffers.back());
57 fAvailableSecondaryBuffers.pop_back();
58 } else{
60 }
61 return result;
62}
static GrVkSecondaryCommandBuffer * Create(GrVkGpu *gpu, GrVkCommandPool *cmdPool)
bool empty() const
Definition SkTArray.h:194

◆ freeGPUData()

void GrVkCommandPool::freeGPUData ( ) const
overrideprivatevirtual

Must be implemented by any subclasses. Deletes any GPU data associated with this resource

Implements GrManagedResource.

Definition at line 108 of file GrVkCommandPool.cpp.

108 {
109 // TODO: having freeGPUData virtual on GrManagedResource be const seems like a bad restriction since
110 // we are changing the internal objects of these classes when it is called. We should go back a
111 // revisit how much of a headache it would be to make this function non-const
112 GrVkCommandPool* nonConstThis = const_cast<GrVkCommandPool*>(this);
113 nonConstThis->close();
114 nonConstThis->releaseResources();
115 fPrimaryCommandBuffer->freeGPUData(fGpu, fCommandPool);
116 for (const auto& buffer : fAvailableSecondaryBuffers) {
117 buffer->freeGPUData(fGpu, fCommandPool);
118 }
119 if (fCommandPool != VK_NULL_HANDLE) {
121 DestroyCommandPool(fGpu->device(), fCommandPool, nullptr));
122 }
123}
static const uint8_t buffer[]
#define VK_NULL_HANDLE
Definition vulkan_core.h:46

◆ getPrimaryCommandBuffer()

GrVkPrimaryCommandBuffer * GrVkCommandPool::getPrimaryCommandBuffer ( )
inline

Definition at line 32 of file GrVkCommandPool.h.

32{ return fPrimaryCommandBuffer.get(); }

◆ isOpen()

bool GrVkCommandPool::isOpen ( ) const
inline

Definition at line 43 of file GrVkCommandPool.h.

43{ return fOpen; }

◆ recycleSecondaryCommandBuffer()

void GrVkCommandPool::recycleSecondaryCommandBuffer ( GrVkSecondaryCommandBuffer buffer)

Definition at line 64 of file GrVkCommandPool.cpp.

64 {
65 std::unique_ptr<GrVkSecondaryCommandBuffer> scb(buffer);
66 if (fAvailableSecondaryBuffers.size() < fMaxCachedSecondaryCommandBuffers) {
67 fAvailableSecondaryBuffers.push_back(std::move(scb));
68 } else {
69 VkCommandBuffer vkBuffer = buffer->vkCommandBuffer();
71 FreeCommandBuffers(fGpu->device(), fCommandPool, 1, &vkBuffer));
72 }
73}
int size() const
Definition SkTArray.h:416

◆ reset()

void GrVkCommandPool::reset ( GrVkGpu gpu)

Definition at line 79 of file GrVkCommandPool.cpp.

79 {
80 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
81 SkASSERT(!fOpen);
82 // We can't use the normal result macro calls here because we may call reset on a different
83 // thread and we can't be modifying the lost state on the GrVkGpu. We just call
84 // vkResetCommandPool and assume the "next" vulkan call will catch the lost device.
85 SkDEBUGCODE(VkResult result = )GR_VK_CALL(gpu->vkInterface(),
86 ResetCommandPool(gpu->device(), fCommandPool, 0));
88
89 // It should be safe to release the resources before actually resetting the VkCommandPool.
90 // However, on qualcomm devices running R drivers there was a few months period where the driver
91 // had a bug which it incorrectly was accessing objects on the command buffer while it was being
92 // reset. If these objects were already destroyed (which is a valid thing to do) it would crash.
93 // So to be safe we do the reset first since it doesn't really matter when single threaded. If
94 // we ever add back in threaded resets we'll want to add checks to make sure everything happens
95 // in the right order (and probably do single threaded resets on bad devices).
96 this->releaseResources();
97
98 fOpen = true;
99}
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
#define TRACE_FUNC
VkDevice device
Definition main.cc:53
#define TRACE_EVENT0(category_group, name)
@ VK_ERROR_DEVICE_LOST

◆ vkCommandPool()

VkCommandPool GrVkCommandPool::vkCommandPool ( ) const
inline

Definition at line 25 of file GrVkCommandPool.h.

25 {
26 return fCommandPool;
27 }

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