35#ifdef SK_BUILD_FOR_ANDROID
47 size_t resourceBudget,
51 , fIntrinsicUniformBuffer(
std::move(intrinsicConstantUniformBuffer))
52 , fLoadMSAAVertexBuffer(
std::move(loadMSAAVertexBuffer))
57 VULKAN_CALL(this->vulkanSharedContext()->interface(),
58 DestroyPipelineCache(this->vulkanSharedContext()->
device(),
63 VULKAN_CALL(this->vulkanSharedContext()->interface(),
64 DestroyShaderModule(this->vulkanSharedContext()->
device(),
65 fMSAALoadVertShaderModule,
69 VULKAN_CALL(this->vulkanSharedContext()->interface(),
70 DestroyShaderModule(this->vulkanSharedContext()->
device(),
71 fMSAALoadFragShaderModule,
75 VULKAN_CALL(this->vulkanSharedContext()->interface(),
76 DestroyPipelineLayout(this->vulkanSharedContext()->
device(),
77 fMSAALoadPipelineLayout,
88 if (
texture.info().vulkanTextureSpec().fYcbcrConversionInfo.isValid()) {
90 texture.info().vulkanTextureSpec().fYcbcrConversionInfo);
91 if (!ycbcrConversion) {
102 std::move(ycbcrConversion));
106 return fIntrinsicUniformBuffer;
110 return fLoadMSAAVertexBuffer.get();
117 auto compatibleRenderPass =
118 this->findOrCreateRenderPass(renderPassDesc,
true);
123 compatibleRenderPass,
124 this->pipelineCache());
132 const TextureInfo&
info,
135 if (
info.vulkanTextureSpec().fYcbcrConversionInfo.isValid()) {
137 info.vulkanTextureSpec().fYcbcrConversionInfo);
138 if (!ycbcrConversion) {
147 std::move(ycbcrConversion));
156sk_sp<Sampler> VulkanResourceProvider::createSampler(
const SamplerDesc& samplerDesc) {
161 if (usesYcbcrConversion) {
169 this->vulkanSharedContext(),
170 static_cast<uint32_t
>(
172 (uint64_t)(samplerDesc.externalFormatMSBs()) << 32 | samplerDesc.format());
175 ycbcrConversion->setKey(ycbcrKey);
181 samplerDesc.samplingOptions(),
182 samplerDesc.tileModeX(),
183 samplerDesc.tileModeY(),
184 std::move(ycbcrConversion));
187BackendTexture VulkanResourceProvider::onCreateBackendTexture(
SkISize dimensions,
188 const TextureInfo&
info) {
189 VulkanTextureInfo vkTexInfo;
190 if (!
info.getVulkanTextureInfo(&vkTexInfo)) {
193 VulkanTexture::CreatedImageInfo createdTextureInfo;
195 &createdTextureInfo)) {
202 createdTextureInfo.fImage,
203 createdTextureInfo.fMemoryAlloc};
210 const int num32DataCnt = requestedDescriptors.
size() + 1;
212 GraphiteResourceKey
key;
216 for (
int i = 1;
i < num32DataCnt;
i++) {
217 const auto& currDesc = requestedDescriptors[
i - 1];
219 uint16_t smallerCount =
static_cast<uint16_t
>(currDesc.fCount);
220 builder[
i] =
static_cast<uint8_t
>(currDesc.fType) << 24 |
221 currDesc.fBindingIndex << 16 |
230 const GraphiteResourceKey& descSetKey,
231 ResourceCache* resourceCache) {
236 descSet->setKey(descSetKey);
237 resourceCache->insertResource(descSet.
get());
245 if (requestedDescriptors.
empty()) {
249 GraphiteResourceKey
key = build_desc_set_key(requestedDescriptors);
258 VkDescriptorSetLayout layout;
259 const VulkanSharedContext* context = this->vulkanSharedContext();
266 VULKAN_CALL(context->interface(), DestroyDescriptorSetLayout(context->device(),
288 SKGPU_LOG_W(
"Descriptor set allocation %d of %d was unsuccessful; no more sets will be"
310 &uniqueKey, kBufferBindGroupDomain, 6,
"GraphicsPipelineBufferDescSet");
317 for (uint32_t
i = 0;
i < requestedDescriptors.
size(); ++
i) {
318 int descriptorBindingIndex = requestedDescriptors[
i].fBindingIndex;
319 SkASSERT(SkTo<unsigned long>(descriptorBindingIndex) < bindUniformBufferInfo.
size());
320 SkASSERT(SkTo<unsigned long>(descriptorBindingIndex) <
322 const auto& bindInfo = bindUniformBufferInfo[descriptorBindingIndex];
323 const VulkanBuffer* boundBuffer =
static_cast<const VulkanBuffer*
>(bindInfo.fBuffer);
325 const uint32_t bindingSize = bindInfo.fBindingSize;
326 builder[2 * descriptorBindingIndex] = boundBuffer->uniqueID().asUInt();
327 builder[2 * descriptorBindingIndex + 1] = bindingSize;
338 VkDescriptorSet descSet,
339 const VulkanSharedContext* sharedContext) {
340 for (
size_t i = 0;
i < requestedDescriptors.
size();
i++) {
341 int descriptorBindingIndex = requestedDescriptors[
i].fBindingIndex;
342 SkASSERT(SkTo<unsigned long>(descriptorBindingIndex) < bindUniformBufferInfo.
size());
343 const auto& bindInfo = bindUniformBufferInfo[descriptorBindingIndex];
344 if (bindInfo.fBuffer) {
346 static uint64_t maxUniformBufferRange =
347 sharedContext->vulkanCaps().maxUniformBufferRange();
348 SkASSERT(bindInfo.fBindingSize <= maxUniformBufferRange);
352 auto vulkanBuffer =
static_cast<const VulkanBuffer*
>(bindInfo.fBuffer);
353 bufferInfo.
buffer = vulkanBuffer->vkBuffer();
355 bufferInfo.
range = bindInfo.fBindingSize;
360 writeInfo.
pNext =
nullptr;
361 writeInfo.
dstSet = descSet;
362 writeInfo.
dstBinding = descriptorBindingIndex;
376 UpdateDescriptorSets(sharedContext->device(),
392 auto key = make_ubo_bind_group_key(requestedDescriptors, bindUniformBufferInfo);
393 auto* existingDescSet = fUniformBufferDescSetCache.
find(
key);
394 if (existingDescSet) {
395 return *existingDescSet;
402 update_uniform_descriptor_set(requestedDescriptors,
403 bindUniformBufferInfo,
404 *newDS->descriptorSet(),
405 this->vulkanSharedContext());
406 return *fUniformBufferDescSetCache.
insert(
key, newDS);
411 const RenderPassDesc& renderPassDesc,
413 const GraphiteResourceKey& rpKey) {
427 renderPass->setKey(rpKey);
434 const RenderPassDesc& renderPassDesc,
bool compatibleOnly) {
437 return this->findOrCreateRenderPassWithKnownKey(renderPassDesc, compatibleOnly, rpKey);
440VkPipelineCache VulkanResourceProvider::pipelineCache() {
445 createInfo.
pNext =
nullptr;
446 createInfo.
flags = 0;
452 CreatePipelineCache(this->vulkanSharedContext()->
device(),
460 return fPipelineCache;
464 const VulkanSharedContext* context,
466 const VulkanRenderPass& renderPass,
474 framebufferInfo.
pNext =
nullptr;
475 framebufferInfo.
flags = 0;
476 framebufferInfo.
renderPass = renderPass.renderPass();
481 framebufferInfo.
layers = 1;
485void VulkanResourceProvider::onDeleteBackendTexture(
const BackendTexture&
texture) {
489 VULKAN_CALL(this->vulkanSharedContext()->interface(),
490 DestroyImage(this->vulkanSharedContext()->
device(),
texture.getVkImage(),
499 if (
texture.getMemoryAlloc()->fBackendMemory) {
504 VULKAN_CALL(this->vulkanSharedContext()->interface(),
505 FreeMemory(this->vulkanSharedContext()->
device(),
506 texture.getMemoryAlloc()->fMemory,
525 if (!ycbcrConversion) {
529 ycbcrConversion->setKey(ycbcrConversionKey);
532 return ycbcrConversion;
540 SKGPU_LOG_E(
"Loading MSAA from resolve texture requires valid color & resolve attachment");
545 GraphiteResourceKey renderPassKey =
547 for (
int i = 0;
i < fLoadMSAAPipelines.size();
i++) {
548 if (renderPassKey == fLoadMSAAPipelines.at(
i).first) {
549 return fLoadMSAAPipelines.at(
i).second;
560 this->vulkanSharedContext(),
561 &fMSAALoadVertShaderModule,
562 &fMSAALoadFragShaderModule,
563 &fMSAALoadShaderStageInfo[0],
564 &fMSAALoadPipelineLayout)) {
565 SKGPU_LOG_E(
"Failed to initialize MSAA load pipeline creation structure(s)");
571 this->findOrCreateRenderPassWithKnownKey(renderPassDesc,
574 if (!compatibleRenderPass) {
575 SKGPU_LOG_E(
"Failed to make compatible render pass for loading MSAA");
579 this->vulkanSharedContext(),
580 fMSAALoadVertShaderModule,
581 fMSAALoadFragShaderModule,
582 &fMSAALoadShaderStageInfo[0],
583 fMSAALoadPipelineLayout,
584 compatibleRenderPass,
585 this->pipelineCache(),
589 SKGPU_LOG_E(
"Failed to create MSAA load pipeline");
593 fLoadMSAAPipelines.push_back(std::make_pair(renderPassKey, pipeline));
597#ifdef SK_BUILD_FOR_ANDROID
599BackendTexture VulkanResourceProvider::onCreateBackendTexture(
AHardwareBuffer* hardwareBuffer,
601 bool isProtectedContent,
603 bool fromAndroidWindow)
const {
605 const VulkanSharedContext* vkContext = this->vulkanSharedContext();
606 VkDevice
device = vkContext->device();
607 const VulkanCaps& vkCaps = vkContext->vulkanCaps();
611 if (!skgpu::GetAHardwareBufferProperties(
612 &hwbFormatProps, &hwbProps, vkContext->interface(), hardwareBuffer,
device)) {
627 if (!importAsExternalFormat) {
642 VulkanYcbcrConversionInfo() };
644 if (isRenderable && (importAsExternalFormat || !vkCaps.isRenderable(vkTexInfo))) {
645 SKGPU_LOG_W(
"Renderable texture requested from an AHardwareBuffer which uses a VkFormat "
646 "that Skia cannot render to (VkFormat: %d).\n", hwbFormatProps.
format);
650 if (!importAsExternalFormat && (!vkCaps.isTransferSrc(vkTexInfo) ||
651 !vkCaps.isTransferDst(vkTexInfo) ||
652 !vkCaps.isTexturable(vkTexInfo))) {
654 SKGPU_LOG_W(
"VkFormat %d is either unfamiliar to Skia or doesn't support the necessary"
655 " format features. Because a renerable texture was requested, we cannot "
656 "fall back to importing with an external format.\n", hwbFormatProps.
format);
660 importAsExternalFormat =
true;
667 VulkanYcbcrConversionInfo ycbcrInfo;
670 externalFormat.
pNext =
nullptr;
672 if (importAsExternalFormat) {
673 GetYcbcrConversionInfoFromFormatProps(&ycbcrInfo, hwbFormatProps);
674 if (!ycbcrInfo.isValid()) {
675 SKGPU_LOG_W(
"Failed to create valid YCbCr conversion information from hardware buffer"
676 "format properties.\n");
692 &externalMemoryImageInfo,
696 { (uint32_t)dimensions.
fWidth, (uint32_t)dimensions.
fHeight, 1 },
700 vkTexInfo.fImageTiling,
701 vkTexInfo.fImageUsageFlags,
702 vkTexInfo.fSharingMode,
711 CreateImage(
device, &imageCreateInfo,
nullptr, &
image));
717 vkContext->vulkanCaps().physicalDeviceMemoryProperties2();
719 if (!AllocateAndBindImageMemory(&alloc,
image, phyDevMemProps, hwbProps, hardwareBuffer,
720 vkContext->interface(),
device)) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
struct AHardwareBuffer AHardwareBuffer
#define SKGPU_LOG_E(fmt,...)
#define SKGPU_LOG_W(fmt,...)
static SkString resource(SkPDFResourceType type, int index)
#define VULKAN_CALL(IFACE, X)
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
V * insert(const K &key, V value)
constexpr bool empty() const
constexpr size_t size() const
static Domain GenerateDomain()
static ResourceType GenerateResourceType()
sk_sp< ResourceCache > fResourceCache
SharedContext * fSharedContext
Protected isProtected() const
static sk_sp< Buffer > Make(const VulkanSharedContext *, size_t, BufferType, AccessPattern)
static sk_sp< VulkanDescriptorPool > Make(const VulkanSharedContext *, SkSpan< DescriptorData >, VkDescriptorSetLayout)
static constexpr int kMaxNumSets
static sk_sp< VulkanDescriptorSet > Make(const VulkanSharedContext *, const sk_sp< VulkanDescriptorPool > &)
static sk_sp< VulkanFramebuffer > Make(const VulkanSharedContext *, const VkFramebufferCreateInfo &)
static sk_sp< VulkanGraphicsPipeline > Make(const VulkanSharedContext *, const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &, const sk_sp< VulkanRenderPass > &compatibleRenderPass, VkPipelineCache)
static constexpr unsigned int kNumUniformBuffers
static sk_sp< VulkanGraphicsPipeline > MakeLoadMSAAPipeline(const VulkanSharedContext *, VkShaderModule vsModule, VkShaderModule fsModule, VkPipelineShaderStageCreateInfo *pipelineShaderStages, VkPipelineLayout, sk_sp< VulkanRenderPass > compatibleRenderPass, VkPipelineCache, const TextureInfo &dstColorAttachmentTexInfo)
static bool InitializeMSAALoadPipelineStructs(const VulkanSharedContext *, VkShaderModule *outVertexShaderModule, VkShaderModule *outFragShaderModule, VkPipelineShaderStageCreateInfo *outShaderStageInfo, VkPipelineLayout *outPipelineLayout)
static sk_sp< VulkanRenderPass > MakeRenderPass(const VulkanSharedContext *, const RenderPassDesc &, bool compatibleOnly)
static GraphiteResourceKey MakeRenderPassKey(const RenderPassDesc &, bool compatibleOnly)
sk_sp< VulkanYcbcrConversion > findOrCreateCompatibleYcbcrConversion(const VulkanYcbcrConversionInfo &ycbcrInfo) const
const Buffer * loadMSAAVertexBuffer() const
~VulkanResourceProvider() override
VulkanResourceProvider(SharedContext *sharedContext, SingleOwner *, uint32_t recorderID, size_t resourceBudget, sk_sp< Buffer > intrinsicConstantUniformBuffer, sk_sp< Buffer > loadMSAAVertexBuffer)
sk_sp< Buffer > refIntrinsicConstantBuffer() const
static sk_sp< VulkanSampler > Make(const VulkanSharedContext *, const SkSamplingOptions &, SkTileMode xTileMode, SkTileMode yTileMode, sk_sp< VulkanYcbcrConversion > ycbcrConversion=nullptr)
static bool MakeVkImage(const VulkanSharedContext *, SkISize dimensions, const TextureInfo &, CreatedImageInfo *outInfo)
static sk_sp< Texture > Make(const VulkanSharedContext *, SkISize dimensions, const TextureInfo &, skgpu::Budgeted, sk_sp< VulkanYcbcrConversion >)
static sk_sp< Texture > MakeWrapped(const VulkanSharedContext *, SkISize dimensions, const TextureInfo &, sk_sp< MutableTextureState >, VkImage, const VulkanAlloc &, sk_sp< VulkanYcbcrConversion >)
static GraphiteResourceKey GetKeyFromSamplerDesc(const SamplerDesc &samplerDesc)
static sk_sp< VulkanYcbcrConversion > Make(const VulkanSharedContext *, const VulkanYcbcrConversionInfo &)
static GraphiteResourceKey MakeYcbcrConversionKey(const VulkanSharedContext *, const VulkanYcbcrConversionInfo &)
sk_sp< const SkImage > image
DlVertices::Builder Builder
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
SK_API uint32_t GetVkQueueFamilyIndex(const MutableTextureState &state)
SK_API VkImageLayout GetVkImageLayout(const MutableTextureState &state)
void FreeImageMemory(VulkanMemoryAllocator *, const VulkanAlloc &alloc)
VkDescriptorType DsTypeEnumToVkDs(DescriptorType type)
void DescriptorDataToVkDescSetLayout(const VulkanSharedContext *ctxt, const SkSpan< DescriptorData > &requestedDescriptors, VkDescriptorSetLayout *outLayout)
constexpr int kMaxNumberOfCachedBufferDescSets
const VkImageView * pAttachments
VkFramebufferCreateFlags flags
VkPipelineCacheCreateFlags flags
const void * pInitialData
const VkBufferView * pTexelBufferView
const VkDescriptorImageInfo * pImageInfo
const VkDescriptorBufferInfo * pBufferInfo
VkDescriptorType descriptorType
AttachmentDesc fColorResolveAttachment
AttachmentDesc fColorAttachment
static constexpr int kImmutableSamplerInfoShift
@ VK_IMAGE_LAYOUT_UNDEFINED
@ VK_SHARING_MODE_EXCLUSIVE
VkFlags VkImageUsageFlags
@ VK_IMAGE_CREATE_PROTECTED_BIT
@ VK_IMAGE_TILING_OPTIMAL
@ VK_IMAGE_ASPECT_COLOR_BIT
@ VK_IMAGE_USAGE_TRANSFER_DST_BIT
@ VK_IMAGE_USAGE_SAMPLED_BIT
@ VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
@ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
@ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
@ VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
#define VK_QUEUE_FAMILY_FOREIGN_EXT
VkFlags VkImageCreateFlags
@ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
@ VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
@ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
@ VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID
@ VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
@ VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO