35class VulkanDescriptorSet;
56 CreateCommandPool(sharedContext->
device(), &cmdPoolInfo,
nullptr, &
pool));
69 VkCommandBuffer primaryCmdBuffer;
73 AllocateCommandBuffers(sharedContext->
device(), &cmdInfo, &primaryCmdBuffer));
76 DestroyCommandPool(sharedContext->
device(),
pool,
nullptr));
86VulkanCommandBuffer::VulkanCommandBuffer(VkCommandPool
pool,
87 VkCommandBuffer primaryCommandBuffer,
91 , fPrimaryCommandBuffer(primaryCommandBuffer)
92 , fSharedContext(sharedContext)
93 , fResourceProvider(resourceProvider) {
107 DestroyFence(fSharedContext->
device(), fSubmitFence,
nullptr));
111 DestroyCommandPool(fSharedContext->
device(), fPool,
nullptr));
114void VulkanCommandBuffer::onResetCommandBuffer() {
117 fActiveGraphicsPipeline =
nullptr;
118 fBindUniformBuffers =
true;
120 fBoundIndexBufferOffset = 0;
122 fBoundIndirectBufferOffset = 0;
124 fNumTextureSamplers = 0;
125 fUniformBuffersToBind.fill({});
126 for (
int i = 0;
i < 4; ++
i) {
127 fCachedBlendConstant[
i] = -1.0;
129 for (
auto& boundInputBuffer : fBoundInputBuffers) {
132 for (
auto& boundInputOffset : fBoundInputBufferOffsets) {
133 boundInputOffset = 0;
147 cmdBufferBeginInfo.
pNext =
nullptr;
152 BeginCommandBuffer(fPrimaryCommandBuffer, &cmdBufferBeginInfo));
160 this->submitPipelineBarriers();
167void VulkanCommandBuffer::addWaitSemaphores(
size_t numWaitSemaphores,
168 const BackendSemaphore* waitSemaphores) {
169 if (!waitSemaphores) {
174 for (
size_t i = 0;
i < numWaitSemaphores; ++
i) {
175 auto& semaphore = waitSemaphores[
i];
177 fWaitSemaphores.
push_back(semaphore.getVkSemaphore());
182void VulkanCommandBuffer::addSignalSemaphores(
size_t numSignalSemaphores,
183 const BackendSemaphore* signalSemaphores) {
184 if (!signalSemaphores) {
189 for (
size_t i = 0;
i < numSignalSemaphores; ++
i) {
190 auto& semaphore = signalSemaphores[
i];
192 fSignalSemaphores.
push_back(semaphore.getVkSemaphore());
197void VulkanCommandBuffer::prepareSurfaceForStateUpdate(
SkSurface* targetSurface,
198 const MutableTextureState* newState) {
199 TextureProxy* textureProxy =
static_cast<Surface*
>(targetSurface)->backingTextureProxy();
200 VulkanTexture*
texture =
static_cast<VulkanTexture*
>(textureProxy->texture());
207 newLayout =
texture->currentLayout();
212 uint32_t currentQueueFamilyIndex =
texture->currentQueueFamilyIndex();
214 auto isSpecialQueue = [](uint32_t queueFamilyIndex) {
218 if (isSpecialQueue(currentQueueFamilyIndex) && isSpecialQueue(newQueueFamilyIndex)) {
224 texture->setImageLayoutAndQueueIndex(
this,
229 newQueueFamilyIndex);
236 const VkSemaphore* waitSemaphores,
238 uint32_t commandBufferCount,
239 const VkCommandBuffer* commandBuffers,
240 uint32_t signalCount,
241 const VkSemaphore* signalSemaphores,
247 protectedSubmitInfo.
pNext =
nullptr;
278 fSharedContext, err, CreateFence(
device, &fenceInfo,
nullptr, &fSubmitFence));
290 int waitCount = fWaitSemaphores.
size();
292 for (
int i = 0;
i < waitCount; ++
i) {
301 fWaitSemaphores.
data(),
304 &fPrimaryCommandBuffer,
305 fSignalSemaphores.
size(),
306 fSignalSemaphores.
data(),
308 fWaitSemaphores.
clear();
309 fSignalSemaphores.
clear();
327 GetFenceStatus(fSharedContext->
device(), fSubmitFence));
337 SKGPU_LOG_F(
"Error calling vkGetFenceStatus. Error: %d", err);
338 SK_ABORT(
"Got an invalid fence status");
348 WaitForFences(fSharedContext->
device(),
355void VulkanCommandBuffer::updateRtAdjustUniform(
const SkRect& viewport) {
356 SkASSERT(fActive && !fActiveRenderPass);
363 float invTwoW = 2.f / viewport.
width();
364 float invTwoH = 2.f / viewport.
height();
365 const float rtAdjust[4] = {invTwoW, invTwoH, -1.f -
x * invTwoW, -1.f -
y * invTwoH};
368 const VulkanBuffer* intrinsicVulkanBuffer =
369 static_cast<VulkanBuffer*
>(intrinsicUniformBuffer.
get());
373 {intrinsicUniformBuffer.
get(), 0},
376 this->updateBuffer(intrinsicVulkanBuffer,
386bool VulkanCommandBuffer::onAddRenderPass(
const RenderPassDesc& renderPassDesc,
387 const Texture* colorTexture,
388 const Texture* resolveTexture,
389 const Texture* depthStencilTexture,
391 const DrawPassList& drawPasses) {
392 for (
const auto& drawPass : drawPasses) {
397 drawPass->sampledTextures();
399 VulkanTexture* vulkanTexture =
const_cast<VulkanTexture*
>(
400 static_cast<const VulkanTexture*
>(
401 textureProxy->texture()));
402 vulkanTexture->setImageLayout(
this,
407 this->submitPipelineBarriers();
411 this->updateRtAdjustUniform(viewport);
412 this->setViewport(viewport);
414 if (!this->beginRenderPass(renderPassDesc, colorTexture, resolveTexture, depthStencilTexture)) {
418 for (
const auto& drawPass : drawPasses) {
419 this->addDrawPass(drawPass.get());
422 this->endRenderPass();
426bool VulkanCommandBuffer::updateLoadMSAAVertexBuffer() {
431 const VulkanBuffer* vulkanVertexBuffer =
static_cast<const VulkanBuffer*
>(vertexBuffer);
437 static constexpr float kVertices[8] = { 1.f, 1.f,
441 this->updateBuffer(vulkanVertexBuffer,
452bool VulkanCommandBuffer::updateAndBindLoadMSAAInputAttachment(
const VulkanTexture& resolveTexture)
468 textureInfo.
imageLayout = resolveTexture.currentLayout();
473 writeInfo.
pNext =
nullptr;
474 writeInfo.
dstSet = *
set->descriptorSet();
484 UpdateDescriptorSets(fSharedContext->
device(),
491 CmdBindDescriptorSets(fPrimaryCommandBuffer,
493 fActiveGraphicsPipeline->
layout(),
496 set->descriptorSet(),
504bool VulkanCommandBuffer::loadMSAAFromResolve(
const RenderPassDesc& renderPassDesc,
505 VulkanTexture& resolveTexture,
508 fResourceProvider->findOrCreateLoadMSAAPipeline(renderPassDesc);
510 SKGPU_LOG_E(
"Unable to create pipeline to load resolve texture into MSAA attachment");
514 this->bindGraphicsPipeline(loadPipeline.
get());
517 fBindUniformBuffers =
false;
518 fBindTextureSamplers =
false;
520 this->setScissor(0, 0, dstDimensions.
width(), dstDimensions.
height());
522 if (!this->updateAndBindLoadMSAAInputAttachment(resolveTexture)) {
523 SKGPU_LOG_E(
"Unable to update and bind an input attachment descriptor for loading MSAA "
546 fBindUniformBuffers =
true;
547 fBindTextureSamplers =
true;
552void setup_texture_layouts(VulkanCommandBuffer* cmdBuf,
553 VulkanTexture* colorTexture,
554 VulkanTexture* resolveTexture,
555 VulkanTexture* depthStencilTexture,
556 bool loadMSAAFromResolve) {
558 colorTexture->setImageLayout(cmdBuf,
564 if (resolveTexture) {
565 if (loadMSAAFromResolve) {
570 resolveTexture->setImageLayout(cmdBuf,
578 resolveTexture->setImageLayout(cmdBuf,
587 if (depthStencilTexture) {
588 depthStencilTexture->setImageLayout(cmdBuf,
597void track_attachments(VulkanCommandBuffer* cmdBuf,
598 VulkanTexture* colorTexture,
599 VulkanTexture* resolveTexture,
600 VulkanTexture* depthStencilTexture) {
602 cmdBuf->trackResource(
sk_ref_sp(colorTexture));
605 cmdBuf->trackResource(
sk_ref_sp(resolveTexture));
607 if (depthStencilTexture) {
608 cmdBuf->trackResource(
sk_ref_sp(depthStencilTexture));
613 VulkanTexture* colorTexture,
614 VulkanTexture* resolveTexture,
615 VulkanTexture* depthStencilTexture) {
617 VkImageView& colorAttachmentView = attachmentViews.
push_back();
618 colorAttachmentView =
621 if (resolveTexture) {
622 VkImageView& resolveView = attachmentViews.
push_back();
628 if (depthStencilTexture) {
629 VkImageView& stencilView = attachmentViews.
push_back();
635void gather_clear_values(
637 const RenderPassDesc& renderPassDesc,
638 VulkanTexture* colorTexture,
639 VulkanTexture* depthStencilTexture,
640 int depthStencilAttachmentIdx) {
646 colorAttachmentClear.
color = {{renderPassDesc.fClearColor[0],
647 renderPassDesc.fClearColor[1],
648 renderPassDesc.fClearColor[2],
649 renderPassDesc.fClearColor[3]}};
652 if (depthStencilTexture) {
653 VkClearValue& depthStencilAttachmentClear = clearValues.
at(depthStencilAttachmentIdx);
654 memset(&depthStencilAttachmentClear, 0,
sizeof(
VkClearValue));
655 depthStencilAttachmentClear.
depthStencil = {renderPassDesc.fClearDepth,
656 renderPassDesc.fClearStencil};
662bool VulkanCommandBuffer::beginRenderPass(
const RenderPassDesc& renderPassDesc,
663 const Texture* colorTexture,
664 const Texture* resolveTexture,
665 const Texture* depthStencilTexture) {
667 VulkanTexture* vulkanColorTexture =
668 const_cast<VulkanTexture*
>(
static_cast<const VulkanTexture*
>(colorTexture));
669 VulkanTexture* vulkanResolveTexture =
670 const_cast<VulkanTexture*
>(
static_cast<const VulkanTexture*
>(resolveTexture));
671 VulkanTexture* vulkanDepthStencilTexture =
672 const_cast<VulkanTexture*
>(
static_cast<const VulkanTexture*
>(depthStencilTexture));
679 bool loadMSAAFromResolve = renderPassDesc.fColorResolveAttachment.fTextureInfo.isValid() &&
680 renderPassDesc.fColorResolveAttachment.fLoadOp ==
LoadOp::kLoad;
681 if (loadMSAAFromResolve && (!vulkanResolveTexture || !vulkanColorTexture ||
682 !vulkanResolveTexture->supportsInputAttachmentUsage())) {
683 SKGPU_LOG_E(
"Cannot begin render pass. In order to load MSAA from resolve, the color "
684 "attachment must have input attachment usage and both the color and resolve "
685 "attachments must be valid.");
689 track_attachments(
this, vulkanColorTexture, vulkanResolveTexture, vulkanDepthStencilTexture);
692 setup_texture_layouts(
this,
694 vulkanResolveTexture,
695 vulkanDepthStencilTexture,
696 loadMSAAFromResolve);
698 static constexpr int kMaxNumAttachments = 3;
701 gather_attachment_views(
702 attachmentViews, vulkanColorTexture, vulkanResolveTexture, vulkanDepthStencilTexture);
708 int depthStencilAttachmentIndex = resolveTexture ? 2 : 1;
709 gather_clear_values(clearValues,
712 vulkanDepthStencilTexture,
713 depthStencilAttachmentIndex);
716 fResourceProvider->findOrCreateRenderPass(renderPassDesc,
false);
717 if (!vulkanRenderPass) {
721 this->submitPipelineBarriers();
724 int frameBufferWidth = 0;
725 int frameBufferHeight = 0;
729 frameBufferWidth = colorTexture->dimensions().width();
730 frameBufferHeight = colorTexture->dimensions().height();
731 }
else if (depthStencilTexture) {
732 frameBufferWidth = depthStencilTexture->dimensions().width();
733 frameBufferHeight = depthStencilTexture->dimensions().height();
741 SKGPU_LOG_W(
"Could not create Vulkan Framebuffer");
748 beginInfo.
pNext =
nullptr;
749 beginInfo.
renderPass = vulkanRenderPass->renderPass();
750 beginInfo.
framebuffer = framebuffer->framebuffer();
752 { (
unsigned int) frameBufferWidth, (
unsigned int) frameBufferHeight }};
759 if (loadMSAAFromResolve) {
766 if (!this->updateLoadMSAAVertexBuffer()) {
767 SKGPU_LOG_E(
"Failed to update vertex buffer for loading MSAA from resolve");
774 this->submitPipelineBarriers();
777 CmdBeginRenderPass(fPrimaryCommandBuffer,
780 fActiveRenderPass =
true;
782 if (loadMSAAFromResolve && !this->loadMSAAFromResolve(renderPassDesc,
783 *vulkanResolveTexture,
784 vulkanColorTexture->dimensions())) {
786 this->endRenderPass();
795void VulkanCommandBuffer::endRenderPass() {
798 fActiveRenderPass =
false;
801void VulkanCommandBuffer::addDrawPass(
const DrawPass* drawPass) {
802 drawPass->addResourceRefs(
this);
803 for (
auto [
type, cmdPtr] : drawPass->commands()) {
805 case DrawPassCommands::Type::kBindGraphicsPipeline: {
806 auto bgp =
static_cast<DrawPassCommands::BindGraphicsPipeline*
>(cmdPtr);
807 this->bindGraphicsPipeline(drawPass->getPipeline(bgp->fPipelineIndex));
810 case DrawPassCommands::Type::kSetBlendConstants: {
811 auto sbc =
static_cast<DrawPassCommands::SetBlendConstants*
>(cmdPtr);
812 this->setBlendConstants(sbc->fBlendConstants);
815 case DrawPassCommands::Type::kBindUniformBuffer: {
816 auto bub =
static_cast<DrawPassCommands::BindUniformBuffer*
>(cmdPtr);
817 this->recordBufferBindingInfo(bub->fInfo, bub->fSlot);
820 case DrawPassCommands::Type::kBindDrawBuffers: {
821 auto bdb =
static_cast<DrawPassCommands::BindDrawBuffers*
>(cmdPtr);
822 this->bindDrawBuffers(
823 bdb->fVertices, bdb->fInstances, bdb->fIndices, bdb->fIndirect);
826 case DrawPassCommands::Type::kBindTexturesAndSamplers: {
827 auto bts =
static_cast<DrawPassCommands::BindTexturesAndSamplers*
>(cmdPtr);
828 this->recordTextureAndSamplerDescSet(*drawPass, *bts);
831 case DrawPassCommands::Type::kSetScissor: {
832 auto ss =
static_cast<DrawPassCommands::SetScissor*
>(cmdPtr);
837 case DrawPassCommands::Type::kDraw: {
839 this->draw(draw->fType, draw->fBaseVertex, draw->fVertexCount);
842 case DrawPassCommands::Type::kDrawIndexed: {
843 auto draw =
static_cast<DrawPassCommands::DrawIndexed*
>(cmdPtr);
845 draw->fType, draw->fBaseIndex, draw->fIndexCount, draw->fBaseVertex);
848 case DrawPassCommands::Type::kDrawInstanced: {
849 auto draw =
static_cast<DrawPassCommands::DrawInstanced*
>(cmdPtr);
850 this->drawInstanced(draw->fType,
854 draw->fInstanceCount);
857 case DrawPassCommands::Type::kDrawIndexedInstanced: {
858 auto draw =
static_cast<DrawPassCommands::DrawIndexedInstanced*
>(cmdPtr);
859 this->drawIndexedInstanced(draw->fType,
864 draw->fInstanceCount);
867 case DrawPassCommands::Type::kDrawIndirect: {
868 auto draw =
static_cast<DrawPassCommands::DrawIndirect*
>(cmdPtr);
869 this->drawIndirect(draw->fType);
872 case DrawPassCommands::Type::kDrawIndexedIndirect: {
873 auto draw =
static_cast<DrawPassCommands::DrawIndexedIndirect*
>(cmdPtr);
874 this->drawIndexedIndirect(draw->fType);
881void VulkanCommandBuffer::bindGraphicsPipeline(
const GraphicsPipeline* graphicsPipeline) {
882 fActiveGraphicsPipeline =
static_cast<const VulkanGraphicsPipeline*
>(graphicsPipeline);
886 fActiveGraphicsPipeline->
pipeline()));
890 fBindUniformBuffers =
true;
893void VulkanCommandBuffer::setBlendConstants(
float* blendConstants) {
895 if (0 != memcmp(blendConstants, fCachedBlendConstant, 4 *
sizeof(
float))) {
897 CmdSetBlendConstants(fPrimaryCommandBuffer, blendConstants));
898 memcpy(fCachedBlendConstant, blendConstants, 4 *
sizeof(
float));
902void VulkanCommandBuffer::recordBufferBindingInfo(
const BindUniformBufferInfo&
info,
904 unsigned int bufferIndex = 0;
916 fUniformBuffersToBind[bufferIndex] =
info;
917 fBindUniformBuffers =
true;
920void VulkanCommandBuffer::syncDescriptorSets() {
921 if (fBindUniformBuffers) {
922 this->bindUniformBuffers();
926 fBindTextureSamplers =
true;
928 if (fBindTextureSamplers) {
929 this->bindTextureSamplers();
933void VulkanCommandBuffer::bindUniformBuffers() {
934 fBindUniformBuffers =
false;
950 descriptors, fUniformBuffersToBind);
952 SKGPU_LOG_E(
"Unable to find or create uniform descriptor set");
956 for (
int i = 0;
i < descriptors.
size();
i++) {
957 int descriptorBindingIndex = descriptors[
i].fBindingIndex;
958 SkASSERT(
static_cast<unsigned long>(descriptorBindingIndex) < fUniformBuffersToBind.size());
959 const auto& bindInfo = fUniformBuffersToBind[descriptorBindingIndex];
960 dynamicOffsets[
i] = bindInfo.fOffset;
964 CmdBindDescriptorSets(fPrimaryCommandBuffer,
966 fActiveGraphicsPipeline->
layout(),
969 descSet->descriptorSet(),
971 dynamicOffsets.get()));
975void VulkanCommandBuffer::bindDrawBuffers(
const BindBufferInfo& vertices,
976 const BindBufferInfo& instances,
977 const BindBufferInfo& indices,
978 const BindBufferInfo& indirect) {
979 this->bindVertexBuffers(vertices.fBuffer,
983 this->bindIndexBuffer(indices.fBuffer, indices.fOffset);
984 this->bindIndirectBuffer(indirect.fBuffer, indirect.fOffset);
987void VulkanCommandBuffer::bindVertexBuffers(
const Buffer* vertexBuffer,
989 const Buffer* instanceBuffer,
990 size_t instanceOffset) {
991 this->bindInputBuffer(vertexBuffer, vertexOffset,
993 this->bindInputBuffer(instanceBuffer, instanceOffset,
1000 VkBuffer vkBuffer =
static_cast<const VulkanBuffer*
>(
buffer)->vkBuffer();
1002 if (vkBuffer != fBoundInputBuffers[binding] ||
1003 offset != fBoundInputBufferOffsets[binding]) {
1005 CmdBindVertexBuffers(fPrimaryCommandBuffer,
1010 fBoundInputBuffers[binding] = vkBuffer;
1011 fBoundInputBufferOffsets[binding] =
offset;
1017void VulkanCommandBuffer::bindIndexBuffer(
const Buffer* indexBuffer,
size_t offset) {
1019 VkBuffer vkBuffer =
static_cast<const VulkanBuffer*
>(indexBuffer)->vkBuffer();
1021 if (vkBuffer != fBoundIndexBuffer ||
offset != fBoundIndexBufferOffset) {
1026 fBoundIndexBuffer = vkBuffer;
1027 fBoundIndexBufferOffset =
offset;
1032 fBoundIndexBufferOffset = 0;
1036void VulkanCommandBuffer::bindIndirectBuffer(
const Buffer* indirectBuffer,
size_t offset) {
1038 if (indirectBuffer) {
1039 fBoundIndirectBuffer =
static_cast<const VulkanBuffer*
>(indirectBuffer)->vkBuffer();
1040 fBoundIndirectBufferOffset =
offset;
1044 fBoundIndirectBufferOffset = 0;
1048void VulkanCommandBuffer::recordTextureAndSamplerDescSet(
1049 const DrawPass& drawPass,
const DrawPassCommands::BindTexturesAndSamplers&
command) {
1050 if (
command.fNumTexSamplers == 0) {
1051 fNumTextureSamplers = 0;
1053 fBindTextureSamplers =
false;
1058 for (
int i = 0;
i <
command.fNumTexSamplers;
i++) {
1068 SKGPU_LOG_E(
"Unable to find or create descriptor set");
1069 fNumTextureSamplers = 0;
1071 fBindTextureSamplers =
false;
1077 for (
int i = 0;
i <
command.fNumTexSamplers; ++
i) {
1078 auto texture =
const_cast<VulkanTexture*
>(
static_cast<const VulkanTexture*
>(
1079 drawPass.getTexture(
command.fTextureIndices[
i])));
1080 auto sampler =
static_cast<const VulkanSampler*
>(
1081 drawPass.getSampler(
command.fSamplerIndices[
i]));
1085 SKGPU_LOG_E(
"Texture and sampler must not be null");
1086 fNumTextureSamplers = 0;
1088 fBindTextureSamplers =
false;
1094 textureInfo.
sampler = sampler->vkSampler();
1102 writeInfo.
pNext =
nullptr;
1103 writeInfo.
dstSet = *
set->descriptorSet();
1115 &writeDescriptorSets[0],
1122 fTextureSamplerDescSetToBind = *
set->descriptorSet();
1123 fBindTextureSamplers =
true;
1124 fNumTextureSamplers =
command.fNumTexSamplers;
1128void VulkanCommandBuffer::bindTextureSamplers() {
1129 fBindTextureSamplers =
false;
1133 CmdBindDescriptorSets(fPrimaryCommandBuffer,
1135 fActiveGraphicsPipeline->
layout(),
1138 &fTextureSamplerDescSetToBind,
1144void VulkanCommandBuffer::setScissor(
unsigned int left,
unsigned int top,
unsigned int width,
1147 {(int32_t)left, (int32_t)top},
1151 CmdSetScissor(fPrimaryCommandBuffer,
1158 unsigned int baseVertex,
1159 unsigned int vertexCount) {
1161 this->syncDescriptorSets();
1164 CmdDraw(fPrimaryCommandBuffer,
1172 unsigned int baseIndex,
1173 unsigned int indexCount,
1174 unsigned int baseVertex) {
1176 this->syncDescriptorSets();
1179 CmdDrawIndexed(fPrimaryCommandBuffer,
1188 unsigned int baseVertex,
1189 unsigned int vertexCount,
1190 unsigned int baseInstance,
1191 unsigned int instanceCount) {
1193 this->syncDescriptorSets();
1196 CmdDraw(fPrimaryCommandBuffer,
1203void VulkanCommandBuffer::drawIndexedInstanced(
PrimitiveType,
1204 unsigned int baseIndex,
1205 unsigned int indexCount,
1206 unsigned int baseVertex,
1207 unsigned int baseInstance,
1208 unsigned int instanceCount) {
1210 this->syncDescriptorSets();
1213 CmdDrawIndexed(fPrimaryCommandBuffer,
1223 this->syncDescriptorSets();
1228 CmdDrawIndirect(fPrimaryCommandBuffer,
1229 fBoundIndirectBuffer,
1230 fBoundIndirectBufferOffset,
1235void VulkanCommandBuffer::drawIndexedIndirect(
PrimitiveType) {
1237 this->syncDescriptorSets();
1242 CmdDrawIndexedIndirect(fPrimaryCommandBuffer,
1243 fBoundIndirectBuffer,
1244 fBoundIndirectBufferOffset,
1249bool VulkanCommandBuffer::onAddComputePass(DispatchGroupSpan) {
return false; }
1251bool VulkanCommandBuffer::onCopyBufferToBuffer(
const Buffer* srcBuffer,
1253 const Buffer* dstBuffer,
1256 auto vkSrcBuffer =
static_cast<const VulkanBuffer*
>(srcBuffer);
1257 auto vkDstBuffer =
static_cast<const VulkanBuffer*
>(dstBuffer);
1264 region.srcOffset = srcOffset;
1265 region.dstOffset = dstOffset;
1268 this->submitPipelineBarriers();
1271 CmdCopyBuffer(fPrimaryCommandBuffer,
1272 vkSrcBuffer->vkBuffer(),
1273 vkDstBuffer->vkBuffer(),
1280bool VulkanCommandBuffer::onCopyTextureToBuffer(
const Texture*
texture,
1283 size_t bufferOffset,
1284 size_t bufferRowBytes) {
1285 const VulkanTexture* srcTexture =
static_cast<const VulkanTexture*
>(
texture);
1286 auto dstBuffer =
static_cast<const VulkanBuffer*
>(
buffer);
1290 VulkanTextureInfo srcTextureInfo;
1291 texture->textureInfo().getVulkanTextureInfo(&srcTextureInfo);
1297 region.bufferOffset = bufferOffset;
1299 region.bufferRowLength = (uint32_t)(bufferRowBytes/bytesPerBlock);
1300 region.bufferImageHeight = 0;
1303 region.imageExtent = { (uint32_t)srcRect.
width(), (uint32_t)srcRect.
height(), 1 };
1306 const_cast<VulkanTexture*
>(srcTexture)->setImageLayout(
this,
1312 const_cast<VulkanBuffer*
>(dstBuffer)->setBufferAccess(
this,
1316 this->submitPipelineBarriers();
1319 CmdCopyImageToBuffer(fPrimaryCommandBuffer,
1320 srcTexture->vkImage(),
1322 dstBuffer->vkBuffer(),
1328bool VulkanCommandBuffer::onCopyBufferToTexture(
const Buffer*
buffer,
1330 const BufferTextureCopyData* copyData,
1332 auto srcBuffer =
static_cast<const VulkanBuffer*
>(
buffer);
1334 const VulkanTexture* dstTexture =
static_cast<const VulkanTexture*
>(
texture);
1337 VulkanTextureInfo dstTextureInfo;
1338 dstTexture->textureInfo().getVulkanTextureInfo(&dstTextureInfo);
1348 region.bufferOffset = copyData[
i].fBufferOffset;
1352 (uint32_t)((copyData[
i].fBufferRowBytes/bytesPerBlock) * oneBlockDims.
fWidth);
1353 region.bufferImageHeight = 0;
1355 region.imageOffset = { copyData[
i].fRect.left(),
1356 copyData[
i].fRect.top(),
1364 const_cast<VulkanTexture*
>(dstTexture)->setImageLayout(
this,
1370 this->submitPipelineBarriers();
1373 CmdCopyBufferToImage(fPrimaryCommandBuffer,
1374 srcBuffer->vkBuffer(),
1375 dstTexture->vkImage(),
1382bool VulkanCommandBuffer::onCopyTextureToTexture(
const Texture*
src,
1387 const VulkanTexture* srcTexture =
static_cast<const VulkanTexture*
>(
src);
1388 const VulkanTexture* dstTexture =
static_cast<const VulkanTexture*
>(
dst);
1396 copyRegion.
extent = { (uint32_t)srcRect.
width(), (uint32_t)srcRect.
height(), 1 };
1399 const_cast<VulkanTexture*
>(srcTexture)->setImageLayout(
this,
1405 const_cast<VulkanTexture*
>(dstTexture)->setImageLayout(
this,
1411 this->submitPipelineBarriers();
1414 CmdCopyImage(fPrimaryCommandBuffer,
1415 srcTexture->vkImage(),
1417 dstTexture->vkImage(),
1425bool VulkanCommandBuffer::onSynchronizeBufferToCpu(
const Buffer*
buffer,
bool* outDidResultInWork) {
1426 static_cast<const VulkanBuffer*
>(
buffer)->setBufferAccess(
this,
1430 *outDidResultInWork =
true;
1434bool VulkanCommandBuffer::onClearBuffer(
const Buffer*,
size_t offset,
size_t size) {
1447 kBufferMemory_BarrierType,
1458 this->pipelineBarrier(
nullptr,
1462 kBufferMemory_BarrierType,
1476 kImageMemory_BarrierType,
1484 BarrierType barrierType,
1494 bool isValidSubpassBarrier =
false;
1495 if (barrierType == kImageMemory_BarrierType) {
1502 SkASSERT(!fActiveRenderPass || isValidSubpassBarrier);
1505 if (barrierType == kBufferMemory_BarrierType) {
1509 SkASSERT(barrierType == kImageMemory_BarrierType);
1517 for (
int i = 0;
i < fImageBarriers.
size(); ++
i) {
1519 if (barrierPtr->
image == currentBarrier.
image) {
1530 this->submitPipelineBarriers();
1537 fBarriersByRegion |= byRegion;
1538 fSrcStageMask = fSrcStageMask | srcStageMask;
1539 fDstStageMask = fDstStageMask | dstStageMask;
1544 if (fActiveRenderPass) {
1545 this->submitPipelineBarriers(
true);
1549void VulkanCommandBuffer::submitPipelineBarriers(
bool forSelfDependency) {
1555 if (fBufferBarriers.
size() || fImageBarriers.
size()) {
1560 SkASSERT(!fActiveRenderPass || forSelfDependency);
1563 SkASSERT(fSrcStageMask && fDstStageMask);
1567 CmdPipelineBarrier(fPrimaryCommandBuffer, fSrcStageMask, fDstStageMask,
1570 fBufferBarriers.
size(), fBufferBarriers.
begin(),
1571 fImageBarriers.
size(), fImageBarriers.
begin()));
1572 fBufferBarriers.
clear();
1573 fImageBarriers.
clear();
1574 fBarriersByRegion =
false;
1585void VulkanCommandBuffer::updateBuffer(
const VulkanBuffer*
buffer,
1590 SkASSERT(fActive && !fActiveRenderPass);
1592 SKGPU_LOG_W(
"VulkanCommandBuffer::updateBuffer requires a valid VulkanBuffer pointer backed"
1593 "by a valid VkBuffer handle");
1601 this->submitPipelineBarriers();
1610void VulkanCommandBuffer::nextSubpass() {
1616void VulkanCommandBuffer::setViewport(
const SkRect& viewport) {
1626 CmdSetViewport(fPrimaryCommandBuffer,
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SKGPU_LOG_E(fmt,...)
#define SKGPU_LOG_W(fmt,...)
#define SKGPU_LOG_F(fmt,...)
#define SK_ABORT(message,...)
static SkString resource(SkPDFResourceType type, int index)
sk_sp< T > sk_ref_sp(T *obj)
#define VULKAN_CALL(IFACE, X)
#define VULKAN_CALL_ERRCHECK(SHARED_CONTEXT, X)
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
#define VULKAN_CALL_RESULT_NOCHECK(IFACE, RESULT, X)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
SkIVector fReplayTranslation
void trackResource(sk_sp< Resource > resource)
Protected isProtected() const
bool setNewCommandBufferResources() override
void addBufferMemoryBarrier(const Resource *resource, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkBufferMemoryBarrier *barrier)
~VulkanCommandBuffer() override
void addImageMemoryBarrier(const Resource *, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, bool byRegion, VkImageMemoryBarrier *barrier)
static std::unique_ptr< VulkanCommandBuffer > Make(const VulkanSharedContext *, VulkanResourceProvider *)
static constexpr unsigned int kPaintUniformBufferIndex
static constexpr unsigned int kInputAttachmentBindingIndex
static const DescriptorData kRenderStepUniformDescriptor
bool hasFragmentUniforms() const
static constexpr unsigned int kInstanceBufferIndex
static const DescriptorData kInputAttachmentDescriptor
static const DescriptorData kIntrinsicUniformBufferDescriptor
static constexpr unsigned int kInputAttachmentDescSetIndex
bool hasStepUniforms() const
static constexpr unsigned int kVertexBufferIndex
static constexpr unsigned int kIntrinsicUniformBufferIndex
int numTextureSamplers() const
static constexpr unsigned int kRenderStepUniformBufferIndex
static const DescriptorData kPaintUniformDescriptor
VkPipeline pipeline() const
static constexpr unsigned int kTextureBindDescSetIndex
static constexpr unsigned int kUniformBufferDescSetIndex
VkPipelineLayout layout() const
static constexpr int kColorAttachmentIdx
static constexpr int kMaxExpectedAttachmentCount
const Buffer * loadMSAAVertexBuffer() const
static constexpr size_t kLoadMSAAVertexBufferSize
static constexpr size_t kIntrinsicConstantSize
sk_sp< Buffer > refIntrinsicConstantBuffer() const
const skgpu::VulkanInterface * interface() const
uint32_t queueIndex() const
static VkAccessFlags LayoutToSrcAccessMask(const VkImageLayout layout)
static VkPipelineStageFlags LayoutToPipelineSrcStageFlags(const VkImageLayout layout)
static void Draw(SkCanvas *canvas, const SkRect &rect)
static const char * begin(const StringSlice &s)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
ClipOpAndAA opAA SkRegion region
sk_sp< SkBlender > blender SkRect rect
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
SK_API uint32_t GetVkQueueFamilyIndex(const MutableTextureState &state)
SK_API VkImageLayout GetVkImageLayout(const MutableTextureState &state)
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)
@ kCombinedTextureSampler
VkDescriptorType DsTypeEnumToVkDs(DescriptorType type)
static constexpr size_t VkFormatBytesPerBlock(VkFormat vkFormat)
SkISize CompressedDimensions(SkTextureCompressionType type, SkISize baseDimensions)
constexpr int32_t y() const
constexpr int32_t x() const
constexpr int32_t top() const
constexpr int32_t height() const
int32_t fTop
smaller y-axis bounds
constexpr int32_t width() const
int32_t fLeft
smaller x-axis bounds
constexpr int32_t left() const
constexpr int32_t width() const
constexpr int32_t height() const
SkScalar fLeft
smaller x-axis bounds
constexpr float x() const
constexpr float y() const
constexpr float height() const
constexpr float width() const
SkScalar fTop
smaller y-axis bounds
const VkCommandBufferInheritanceInfo * pInheritanceInfo
VkCommandBufferUsageFlags flags
VkImageLayout imageLayout
VkImageSubresourceLayers srcSubresource
VkImageSubresourceLayers dstSubresource
uint32_t dstQueueFamilyIndex
VkImageSubresourceRange subresourceRange
uint32_t srcQueueFamilyIndex
VkImageAspectFlags aspectMask
const VkClearValue * pClearValues
VkFramebuffer framebuffer
uint32_t waitSemaphoreCount
const VkPipelineStageFlags * pWaitDstStageMask
uint32_t commandBufferCount
const VkSemaphore * pWaitSemaphores
uint32_t signalSemaphoreCount
const VkCommandBuffer * pCommandBuffers
const VkSemaphore * pSignalSemaphores
const VkBufferView * pTexelBufferView
const VkDescriptorImageInfo * pImageInfo
const VkDescriptorBufferInfo * pBufferInfo
VkDescriptorType descriptorType
std::shared_ptr< const fml::Mapping > data
VkClearDepthStencilValue depthStencil
VkFlags VkPipelineStageFlags
@ VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
@ VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
@ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
@ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
@ VK_IMAGE_LAYOUT_UNDEFINED
@ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
@ VK_COMMAND_BUFFER_LEVEL_PRIMARY
@ VK_DEPENDENCY_BY_REGION_BIT
VkFlags VkDependencyFlags
VkFlags VkCommandPoolCreateFlags
@ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
@ VK_PIPELINE_BIND_POINT_GRAPHICS
@ VK_IMAGE_ASPECT_COLOR_BIT
#define VK_QUEUE_FAMILY_FOREIGN_EXT
@ VK_BUFFER_USAGE_TRANSFER_DST_BIT
@ VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
@ VK_BUFFER_USAGE_TRANSFER_SRC_BIT
@ VK_ACCESS_HOST_READ_BIT
@ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
@ VK_ACCESS_TRANSFER_WRITE_BIT
@ VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
@ VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
@ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
@ VK_ACCESS_TRANSFER_READ_BIT
@ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
@ VK_ACCESS_SHADER_READ_BIT
@ VK_ACCESS_UNIFORM_READ_BIT
@ VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
@ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
#define VK_QUEUE_FAMILY_EXTERNAL
@ VK_SUBPASS_CONTENTS_INLINE
@ VK_COMMAND_POOL_CREATE_TRANSIENT_BIT
@ VK_COMMAND_POOL_CREATE_PROTECTED_BIT
@ VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
@ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
@ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
@ VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
@ VK_PIPELINE_STAGE_HOST_BIT
@ VK_PIPELINE_STAGE_TRANSFER_BIT
@ VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
#define VK_QUEUE_FAMILY_IGNORED
@ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO
@ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
@ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO
@ VK_STRUCTURE_TYPE_PROTECTED_SUBMIT_INFO
@ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
@ VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
@ VK_STRUCTURE_TYPE_SUBMIT_INFO
@ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO