Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private 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 ()
 
void addFinishedProc (sk_sp< RefCntedCallback > finishedProc)
 
void callFinishedProcs (bool success)
 
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 *)
 

Private Member Functions

void onResetCommandBuffer () override
 
void addWaitSemaphores (size_t numWaitSemaphores, const BackendSemaphore *waitSemaphores) override
 
void addSignalSemaphores (size_t numWaitSemaphores, const BackendSemaphore *signalSemaphores) override
 
void prepareSurfaceForStateUpdate (SkSurface *targetSurface, const MutableTextureState *newState) override
 
bool onAddRenderPass (const RenderPassDesc &, const Texture *colorTexture, const Texture *resolveTexture, const Texture *depthStencilTexture, SkRect viewport, const DrawPassList &) override
 
bool onAddComputePass (DispatchGroupSpan) override
 
bool onCopyBufferToBuffer (const Buffer *srcBuffer, size_t srcOffset, const Buffer *dstBuffer, size_t dstOffset, size_t size) override
 
bool onCopyTextureToBuffer (const Texture *, SkIRect srcRect, const Buffer *, size_t bufferOffset, size_t bufferRowBytes) override
 
bool onCopyBufferToTexture (const Buffer *, const Texture *, const BufferTextureCopyData *copyData, int count) override
 
bool onCopyTextureToTexture (const Texture *src, SkIRect srcRect, const Texture *dst, SkIPoint dstPoint, int mipLevel) override
 
bool onSynchronizeBufferToCpu (const Buffer *, bool *outDidResultInWork) override
 
bool onClearBuffer (const Buffer *, size_t offset, size_t size) override
 

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 25 of file VulkanCommandBuffer.h.

Constructor & Destructor Documentation

◆ ~VulkanCommandBuffer()

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

Definition at line 110 of file VulkanCommandBuffer.cpp.

110 {
111 if (fActive) {
112 // Need to end command buffer before deleting it
113 VULKAN_CALL(fSharedContext->interface(), EndCommandBuffer(fPrimaryCommandBuffer));
114 fActive = false;
115 }
116
117 if (VK_NULL_HANDLE != fSubmitFence) {
118 VULKAN_CALL(fSharedContext->interface(),
119 DestroyFence(fSharedContext->device(), fSubmitFence, nullptr));
120 }
121 // This should delete any command buffers as well.
122 VULKAN_CALL(fSharedContext->interface(),
123 DestroyCommandPool(fSharedContext->device(), fPool, nullptr));
124}
#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 1484 of file VulkanCommandBuffer.cpp.

1487 {
1488 SkASSERT(resource);
1489 this->pipelineBarrier(resource,
1490 srcStageMask,
1491 dstStageMask,
1492 /*byRegion=*/false,
1493 kBufferMemory_BarrierType,
1494 barrier);
1495}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ addBufferMemoryBarrier() [2/2]

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

Definition at line 1497 of file VulkanCommandBuffer.cpp.

1499 {
1500 // We don't pass in a resource here to the command buffer. The command buffer only is using it
1501 // to hold a ref, but every place where we add a buffer memory barrier we are doing some other
1502 // command with the buffer on the command buffer. Thus those other commands will already cause
1503 // the command buffer to be holding a ref to the buffer.
1504 this->pipelineBarrier(/*resource=*/nullptr,
1505 srcStageMask,
1506 dstStageMask,
1507 /*byRegion=*/false,
1508 kBufferMemory_BarrierType,
1509 barrier);
1510}

◆ addImageMemoryBarrier()

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

Definition at line 1512 of file VulkanCommandBuffer.cpp.

1516 {
1517 SkASSERT(resource);
1518 this->pipelineBarrier(resource,
1519 srcStageMask,
1520 dstStageMask,
1521 byRegion,
1522 kImageMemory_BarrierType,
1523 barrier);
1524}

◆ addSignalSemaphores()

void skgpu::graphite::VulkanCommandBuffer::addSignalSemaphores ( size_t  numWaitSemaphores,
const BackendSemaphore signalSemaphores 
)
overrideprivatevirtual

Reimplemented from skgpu::graphite::CommandBuffer.

Definition at line 194 of file VulkanCommandBuffer.cpp.

195 {
196 if (!signalSemaphores) {
197 SkASSERT(numSignalSemaphores == 0);
198 return;
199 }
200
201 for (size_t i = 0; i < numSignalSemaphores; ++i) {
202 auto& semaphore = signalSemaphores[i];
203 if (semaphore.isValid() && semaphore.backend() == BackendApi::kVulkan) {
204 fSignalSemaphores.push_back(semaphore.getVkSemaphore());
205 }
206 }
207}

◆ addWaitSemaphores()

void skgpu::graphite::VulkanCommandBuffer::addWaitSemaphores ( size_t  numWaitSemaphores,
const BackendSemaphore waitSemaphores 
)
overrideprivatevirtual

Reimplemented from skgpu::graphite::CommandBuffer.

Definition at line 179 of file VulkanCommandBuffer.cpp.

180 {
181 if (!waitSemaphores) {
182 SkASSERT(numWaitSemaphores == 0);
183 return;
184 }
185
186 for (size_t i = 0; i < numWaitSemaphores; ++i) {
187 auto& semaphore = waitSemaphores[i];
188 if (semaphore.isValid() && semaphore.backend() == BackendApi::kVulkan) {
189 fWaitSemaphores.push_back(semaphore.getVkSemaphore());
190 }
191 }
192}

◆ isFinished()

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

Definition at line 331 of file VulkanCommandBuffer.cpp.

331 {
332 SkASSERT(!fActive);
333 if (VK_NULL_HANDLE == fSubmitFence) {
334 return true;
335 }
336
337 VkResult err;
338 VULKAN_CALL_RESULT_NOCHECK(fSharedContext->interface(), err,
339 GetFenceStatus(fSharedContext->device(), fSubmitFence));
340 switch (err) {
341 case VK_SUCCESS:
343 return true;
344
345 case VK_NOT_READY:
346 return false;
347
348 default:
349 SKGPU_LOG_F("Error calling vkGetFenceStatus. Error: %d", err);
350 SK_ABORT("Got an invalid fence status");
351 return false;
352 }
353}
#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
@ VK_ERROR_DEVICE_LOST
@ VK_SUCCESS
@ VK_NOT_READY

◆ Make()

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

Definition at line 49 of file VulkanCommandBuffer.cpp.

51 {
52 // Create VkCommandPool
54 if (sharedContext->isProtected() == Protected::kYes) {
55 cmdPoolCreateFlags |= VK_COMMAND_POOL_CREATE_PROTECTED_BIT;
56 }
57
58 const VkCommandPoolCreateInfo cmdPoolInfo = {
60 nullptr, // pNext
61 cmdPoolCreateFlags, // CmdPoolCreateFlags
62 sharedContext->queueIndex(), // queueFamilyIndex
63 };
65 VkCommandPool pool;
66 VULKAN_CALL_RESULT(sharedContext,
67 result,
68 CreateCommandPool(sharedContext->device(), &cmdPoolInfo, nullptr, &pool));
69 if (result != VK_SUCCESS) {
70 return nullptr;
71 }
72
73 const VkCommandBufferAllocateInfo cmdInfo = {
75 nullptr, // pNext
76 pool, // commandPool
78 1 // bufferCount
79 };
80
81 VkCommandBuffer primaryCmdBuffer;
83 sharedContext,
84 result,
85 AllocateCommandBuffers(sharedContext->device(), &cmdInfo, &primaryCmdBuffer));
86 if (result != VK_SUCCESS) {
87 VULKAN_CALL(sharedContext->interface(),
88 DestroyCommandPool(sharedContext->device(), pool, nullptr));
89 return nullptr;
90 }
91
92 return std::unique_ptr<VulkanCommandBuffer>(new VulkanCommandBuffer(pool,
93 primaryCmdBuffer,
94 sharedContext,
95 resourceProvider));
96}
AutoreleasePool pool
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
GAsyncResult * result
@ VK_COMMAND_BUFFER_LEVEL_PRIMARY
VkFlags VkCommandPoolCreateFlags
@ VK_COMMAND_POOL_CREATE_TRANSIENT_BIT
@ VK_COMMAND_POOL_CREATE_PROTECTED_BIT
@ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO
@ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO

◆ onAddComputePass()

bool skgpu::graphite::VulkanCommandBuffer::onAddComputePass ( DispatchGroupSpan  )
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 1295 of file VulkanCommandBuffer.cpp.

1295{ return false; }

◆ onAddRenderPass()

bool skgpu::graphite::VulkanCommandBuffer::onAddRenderPass ( const RenderPassDesc renderPassDesc,
const Texture colorTexture,
const Texture resolveTexture,
const Texture depthStencilTexture,
SkRect  viewport,
const DrawPassList drawPasses 
)
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 397 of file VulkanCommandBuffer.cpp.

402 {
403 for (const auto& drawPass : drawPasses) {
404 // Our current implementation of setting texture image layouts does not allow layout changes
405 // once we have already begun a render pass, so prior to any other commands, set the layout
406 // of all sampled textures from the drawpass so they can be sampled from the shader.
407 const skia_private::TArray<sk_sp<TextureProxy>>& sampledTextureProxies =
408 drawPass->sampledTextures();
409 for (const sk_sp<TextureProxy>& textureProxy : sampledTextureProxies) {
410 VulkanTexture* vulkanTexture = const_cast<VulkanTexture*>(
411 static_cast<const VulkanTexture*>(
412 textureProxy->texture()));
413 vulkanTexture->setImageLayout(this,
417 false);
418 this->submitPipelineBarriers();
419 }
420 }
421
422 this->updateRtAdjustUniform(viewport);
423 this->setViewport(viewport);
424
425 if (!this->beginRenderPass(renderPassDesc, colorTexture, resolveTexture, depthStencilTexture)) {
426 return false;
427 }
428
429 for (const auto& drawPass : drawPasses) {
430 this->addDrawPass(drawPass.get());
431 }
432
433 this->endRenderPass();
434 return true;
435}
@ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
@ VK_ACCESS_SHADER_READ_BIT
@ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT

◆ onClearBuffer()

bool skgpu::graphite::VulkanCommandBuffer::onClearBuffer ( const Buffer ,
size_t  offset,
size_t  size 
)
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 1480 of file VulkanCommandBuffer.cpp.

1480 {
1481 return false;
1482}

◆ onCopyBufferToBuffer()

bool skgpu::graphite::VulkanCommandBuffer::onCopyBufferToBuffer ( const Buffer srcBuffer,
size_t  srcOffset,
const Buffer dstBuffer,
size_t  dstOffset,
size_t  size 
)
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 1297 of file VulkanCommandBuffer.cpp.

1301 {
1302 auto vkSrcBuffer = static_cast<const VulkanBuffer*>(srcBuffer);
1303 auto vkDstBuffer = static_cast<const VulkanBuffer*>(dstBuffer);
1304
1305 SkASSERT(vkSrcBuffer->bufferUsageFlags() & VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
1306 SkASSERT(vkDstBuffer->bufferUsageFlags() & VK_BUFFER_USAGE_TRANSFER_DST_BIT);
1307
1309 memset(&region, 0, sizeof(VkBufferCopy));
1310 region.srcOffset = srcOffset;
1311 region.dstOffset = dstOffset;
1312 region.size = size;
1313
1314 this->submitPipelineBarriers();
1315
1316 VULKAN_CALL(fSharedContext->interface(),
1317 CmdCopyBuffer(fPrimaryCommandBuffer,
1318 vkSrcBuffer->vkBuffer(),
1319 vkDstBuffer->vkBuffer(),
1320 /*regionCount=*/1,
1321 &region));
1322
1323 return true;
1324}
ClipOpAndAA opAA SkRegion region
Definition SkRecords.h:238
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
@ VK_BUFFER_USAGE_TRANSFER_DST_BIT
@ VK_BUFFER_USAGE_TRANSFER_SRC_BIT

◆ onCopyBufferToTexture()

bool skgpu::graphite::VulkanCommandBuffer::onCopyBufferToTexture ( const Buffer buffer,
const Texture texture,
const BufferTextureCopyData copyData,
int  count 
)
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 1374 of file VulkanCommandBuffer.cpp.

1377 {
1378 auto srcBuffer = static_cast<const VulkanBuffer*>(buffer);
1379 SkASSERT(srcBuffer->bufferUsageFlags() & VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
1380 const VulkanTexture* dstTexture = static_cast<const VulkanTexture*>(texture);
1381
1382 // Obtain the VkFormat of the destination texture so we can determine bytes per block.
1383 VulkanTextureInfo dstTextureInfo;
1384 dstTexture->textureInfo().getVulkanTextureInfo(&dstTextureInfo);
1385 size_t bytesPerBlock = VkFormatBytesPerBlock(dstTextureInfo.fFormat);
1386 SkISize oneBlockDims = CompressedDimensions(dstTexture->textureInfo().compressionType(),
1387 {1, 1});
1388
1389 // Set up copy regions.
1391 for (int i = 0; i < count; ++i) {
1392 VkBufferImageCopy& region = regions.push_back();
1393 memset(&region, 0, sizeof(VkBufferImageCopy));
1394 region.bufferOffset = copyData[i].fBufferOffset;
1395 // copyData provides row length in bytes, but Vulkan expects bufferRowLength in texels.
1396 // For compressed this is the number of logical pixels not the number of blocks.
1397 region.bufferRowLength =
1398 (uint32_t)((copyData[i].fBufferRowBytes/bytesPerBlock) * oneBlockDims.fWidth);
1399 region.bufferImageHeight = 0; // Tightly packed
1400 region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, copyData[i].fMipLevel, 0, 1 };
1401 region.imageOffset = { copyData[i].fRect.left(),
1402 copyData[i].fRect.top(),
1403 /*z=*/0 };
1404 region.imageExtent = { (uint32_t)copyData[i].fRect.width(),
1405 (uint32_t)copyData[i].fRect.height(),
1406 /*depth=*/1 };
1407 }
1408
1409 // Enable editing of the destination texture so we can change its layout so it can be copied to.
1410 const_cast<VulkanTexture*>(dstTexture)->setImageLayout(this,
1414 false);
1415
1416 this->submitPipelineBarriers();
1417
1418 VULKAN_CALL(fSharedContext->interface(),
1419 CmdCopyBufferToImage(fPrimaryCommandBuffer,
1420 srcBuffer->vkBuffer(),
1421 dstTexture->vkImage(),
1423 regions.size(),
1424 regions.begin()));
1425 return true;
1426}
SkRect fRect
int count
static const uint8_t buffer[]
FlTexture * texture
static constexpr size_t VkFormatBytesPerBlock(VkFormat vkFormat)
SkISize CompressedDimensions(SkTextureCompressionType type, SkISize baseDimensions)
int32_t fWidth
Definition SkSize.h:17
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762
@ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
@ VK_IMAGE_ASPECT_COLOR_BIT
@ VK_ACCESS_TRANSFER_WRITE_BIT
@ VK_PIPELINE_STAGE_TRANSFER_BIT

◆ onCopyTextureToBuffer()

bool skgpu::graphite::VulkanCommandBuffer::onCopyTextureToBuffer ( const Texture texture,
SkIRect  srcRect,
const Buffer buffer,
size_t  bufferOffset,
size_t  bufferRowBytes 
)
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 1326 of file VulkanCommandBuffer.cpp.

1330 {
1331 const VulkanTexture* srcTexture = static_cast<const VulkanTexture*>(texture);
1332 auto dstBuffer = static_cast<const VulkanBuffer*>(buffer);
1333 SkASSERT(dstBuffer->bufferUsageFlags() & VK_BUFFER_USAGE_TRANSFER_DST_BIT);
1334
1335 // Obtain the VkFormat of the source texture so we can determine bytes per block.
1336 VulkanTextureInfo srcTextureInfo;
1337 texture->textureInfo().getVulkanTextureInfo(&srcTextureInfo);
1338 size_t bytesPerBlock = VkFormatBytesPerBlock(srcTextureInfo.fFormat);
1339
1340 // Set up copy region
1342 memset(&region, 0, sizeof(VkBufferImageCopy));
1343 region.bufferOffset = bufferOffset;
1344 // Vulkan expects bufferRowLength in texels, not bytes.
1345 region.bufferRowLength = (uint32_t)(bufferRowBytes/bytesPerBlock);
1346 region.bufferImageHeight = 0; // Tightly packed
1347 region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, /*mipLevel=*/0, 0, 1 };
1348 region.imageOffset = { srcRect.left(), srcRect.top(), /*z=*/0 };
1349 region.imageExtent = { (uint32_t)srcRect.width(), (uint32_t)srcRect.height(), /*depth=*/1 };
1350
1351 // Enable editing of the source texture so we can change its layout so it can be copied from.
1352 const_cast<VulkanTexture*>(srcTexture)->setImageLayout(this,
1356 false);
1357 // Set current access mask for buffer
1358 const_cast<VulkanBuffer*>(dstBuffer)->setBufferAccess(this,
1361
1362 this->submitPipelineBarriers();
1363
1364 VULKAN_CALL(fSharedContext->interface(),
1365 CmdCopyImageToBuffer(fPrimaryCommandBuffer,
1366 srcTexture->vkImage(),
1368 dstBuffer->vkBuffer(),
1369 /*regionCount=*/1,
1370 &region));
1371 return true;
1372}
constexpr int32_t top() const
Definition SkRect.h:120
constexpr int32_t height() const
Definition SkRect.h:165
constexpr int32_t width() const
Definition SkRect.h:158
constexpr int32_t left() const
Definition SkRect.h:113
@ VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
@ VK_ACCESS_TRANSFER_READ_BIT

◆ onCopyTextureToTexture()

bool skgpu::graphite::VulkanCommandBuffer::onCopyTextureToTexture ( const Texture src,
SkIRect  srcRect,
const Texture dst,
SkIPoint  dstPoint,
int  mipLevel 
)
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 1428 of file VulkanCommandBuffer.cpp.

1432 {
1433 const VulkanTexture* srcTexture = static_cast<const VulkanTexture*>(src);
1434 const VulkanTexture* dstTexture = static_cast<const VulkanTexture*>(dst);
1435
1436 VkImageCopy copyRegion;
1437 memset(&copyRegion, 0, sizeof(VkImageCopy));
1438 copyRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
1439 copyRegion.srcOffset = { srcRect.fLeft, srcRect.fTop, 0 };
1440 copyRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, (uint32_t)mipLevel, 0, 1 };
1441 copyRegion.dstOffset = { dstPoint.fX, dstPoint.fY, 0 };
1442 copyRegion.extent = { (uint32_t)srcRect.width(), (uint32_t)srcRect.height(), 1 };
1443
1444 // Enable editing of the src texture so we can change its layout so it can be copied from.
1445 const_cast<VulkanTexture*>(srcTexture)->setImageLayout(this,
1449 false);
1450 // Enable editing of the destination texture so we can change its layout so it can be copied to.
1451 const_cast<VulkanTexture*>(dstTexture)->setImageLayout(this,
1455 false);
1456
1457 this->submitPipelineBarriers();
1458
1459 VULKAN_CALL(fSharedContext->interface(),
1460 CmdCopyImage(fPrimaryCommandBuffer,
1461 srcTexture->vkImage(),
1463 dstTexture->vkImage(),
1465 /*regionCount=*/1,
1466 &copyRegion));
1467
1468 return true;
1469}
dst
Definition cp.py:12
int32_t fX
x-axis value
int32_t fY
y-axis value
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
VkExtent3D extent
VkOffset3D srcOffset
VkImageSubresourceLayers srcSubresource
VkImageSubresourceLayers dstSubresource
VkOffset3D dstOffset

◆ onResetCommandBuffer()

void skgpu::graphite::VulkanCommandBuffer::onResetCommandBuffer ( )
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 126 of file VulkanCommandBuffer.cpp.

126 {
127 SkASSERT(!fActive);
128 VULKAN_CALL_ERRCHECK(fSharedContext, ResetCommandPool(fSharedContext->device(), fPool, 0));
129 fActiveGraphicsPipeline = nullptr;
130 fBindUniformBuffers = true;
131 fBoundIndexBuffer = VK_NULL_HANDLE;
132 fBoundIndexBufferOffset = 0;
133 fBoundIndirectBuffer = VK_NULL_HANDLE;
134 fBoundIndirectBufferOffset = 0;
135 fTextureSamplerDescSetToBind = VK_NULL_HANDLE;
136 fNumTextureSamplers = 0;
137 fUniformBuffersToBind.fill({nullptr, 0});
138 for (int i = 0; i < 4; ++i) {
139 fCachedBlendConstant[i] = -1.0;
140 }
141 for (auto& boundInputBuffer : fBoundInputBuffers) {
142 boundInputBuffer = VK_NULL_HANDLE;
143 }
144 for (auto& boundInputOffset : fBoundInputBufferOffsets) {
145 boundInputOffset = 0;
146 }
147}
#define VULKAN_CALL_ERRCHECK(SHARED_CONTEXT, X)

◆ onSynchronizeBufferToCpu()

bool skgpu::graphite::VulkanCommandBuffer::onSynchronizeBufferToCpu ( const Buffer buffer,
bool *  outDidResultInWork 
)
overrideprivatevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 1471 of file VulkanCommandBuffer.cpp.

1471 {
1472 static_cast<const VulkanBuffer*>(buffer)->setBufferAccess(this,
1475
1476 *outDidResultInWork = true;
1477 return true;
1478}
@ VK_ACCESS_HOST_READ_BIT
@ VK_PIPELINE_STAGE_HOST_BIT

◆ prepareSurfaceForStateUpdate()

void skgpu::graphite::VulkanCommandBuffer::prepareSurfaceForStateUpdate ( SkSurface targetSurface,
const MutableTextureState newState 
)
overrideprivatevirtual

Reimplemented from skgpu::graphite::CommandBuffer.

Definition at line 209 of file VulkanCommandBuffer.cpp.

210 {
211 TextureProxy* textureProxy = static_cast<Surface*>(targetSurface)->backingTextureProxy();
212 VulkanTexture* texture = static_cast<VulkanTexture*>(textureProxy->texture());
213
214 // Even though internally we use this helper for getting src access flags and stages they
215 // can also be used for general dst flags since we don't know exactly what the client
216 // plans on using the image for.
218 if (newLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
219 newLayout = texture->currentLayout();
220 }
223
224 uint32_t currentQueueFamilyIndex = texture->currentQueueFamilyIndex();
225 uint32_t newQueueFamilyIndex = skgpu::MutableTextureStates::GetVkQueueFamilyIndex(newState);
226 auto isSpecialQueue = [](uint32_t queueFamilyIndex) {
227 return queueFamilyIndex == VK_QUEUE_FAMILY_EXTERNAL ||
228 queueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT;
229 };
230 if (isSpecialQueue(currentQueueFamilyIndex) && isSpecialQueue(newQueueFamilyIndex)) {
231 // It is illegal to have both the new and old queue be special queue families (i.e. external
232 // or foreign).
233 return;
234 }
235
236 texture->setImageLayoutAndQueueIndex(this,
237 newLayout,
238 dstAccess,
239 dstStage,
240 false,
241 newQueueFamilyIndex);
242}
static VkAccessFlags LayoutToSrcAccessMask(const VkImageLayout layout)
static VkPipelineStageFlags LayoutToPipelineSrcStageFlags(const VkImageLayout layout)
SK_API uint32_t GetVkQueueFamilyIndex(const MutableTextureState &state)
SK_API VkImageLayout GetVkImageLayout(const MutableTextureState &state)
VkFlags VkPipelineStageFlags
VkImageLayout
@ VK_IMAGE_LAYOUT_UNDEFINED
VkFlags VkAccessFlags
#define VK_QUEUE_FAMILY_FOREIGN_EXT
#define VK_QUEUE_FAMILY_EXTERNAL

◆ setNewCommandBufferResources()

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

Implements skgpu::graphite::CommandBuffer.

Definition at line 149 of file VulkanCommandBuffer.cpp.

149 {
150 this->begin();
151 return true;
152}

◆ submit()

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

Definition at line 279 of file VulkanCommandBuffer.cpp.

279 {
280 this->end();
281
282 auto device = fSharedContext->device();
283 VkResult err;
284
285 if (fSubmitFence == VK_NULL_HANDLE) {
286 VkFenceCreateInfo fenceInfo;
287 memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo));
290 fSharedContext, err, CreateFence(device, &fenceInfo, nullptr, &fSubmitFence));
291 if (err) {
292 fSubmitFence = VK_NULL_HANDLE;
293 return false;
294 }
295 } else {
296 // This cannot return DEVICE_LOST so we assert we succeeded.
297 VULKAN_CALL_RESULT(fSharedContext, err, ResetFences(device, 1, &fSubmitFence));
298 SkASSERT(err == VK_SUCCESS);
299 }
300
301 SkASSERT(fSubmitFence != VK_NULL_HANDLE);
302 int waitCount = fWaitSemaphores.size();
303 TArray<VkPipelineStageFlags> vkWaitStages(waitCount);
304 for (int i = 0; i < waitCount; ++i) {
305 vkWaitStages.push_back(VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
307 }
308
309 bool submitted = submit_to_queue(fSharedContext,
310 queue,
311 fSubmitFence,
312 waitCount,
313 fWaitSemaphores.data(),
314 vkWaitStages.data(),
315 /*commandBufferCount*/ 1,
316 &fPrimaryCommandBuffer,
317 fSignalSemaphores.size(),
318 fSignalSemaphores.data(),
319 fSharedContext->isProtected());
320 fWaitSemaphores.clear();
321 fSignalSemaphores.clear();
322 if (!submitted) {
323 // Destroy the fence or else we will try to wait forever for it to finish.
324 VULKAN_CALL(fSharedContext->interface(), DestroyFence(device, fSubmitFence, nullptr));
325 fSubmitFence = VK_NULL_HANDLE;
326 return false;
327 }
328 return true;
329}
int size() const
Definition SkTArray.h:416
VkDevice device
Definition main.cc:53
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
@ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO

◆ waitUntilFinished()

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

Definition at line 355 of file VulkanCommandBuffer.cpp.

355 {
356 if (fSubmitFence == VK_NULL_HANDLE) {
357 return;
358 }
359 VULKAN_CALL_ERRCHECK(fSharedContext,
360 WaitForFences(fSharedContext->device(),
361 1,
362 &fSubmitFence,
363 /*waitAll=*/true,
364 /*timeout=*/UINT64_MAX));
365}

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