// Copyright (C) 2021 The Android Open Source Project // Copyright (C) 2021 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include "android/base/containers/EntityManager.h" #include #include #include namespace goldfish_vk { enum DescriptorWriteType { Empty = 0, ImageInfo = 1, BufferInfo = 2, BufferView = 3, InlineUniformBlock = 4, AccelerationStructure = 5, }; struct DescriptorWrite { DescriptorWriteType type; VkDescriptorType descriptorType; uint32_t dstArrayElement; // Only used for inlineUniformBlock and accelerationStructure. union { VkDescriptorImageInfo imageInfo; VkDescriptorBufferInfo bufferInfo; VkBufferView bufferView; VkWriteDescriptorSetInlineUniformBlockEXT inlineUniformBlock; VkWriteDescriptorSetAccelerationStructureKHR accelerationStructure; }; std::vector inlineUniformBlockBuffer; }; using DescriptorWriteTable = std::vector>; struct DescriptorWriteArrayRange { uint32_t begin; uint32_t count; }; using DescriptorWriteDstArrayRangeTable = std::vector>; struct ReifiedDescriptorSet { VkDescriptorPool pool; VkDescriptorSetLayout setLayout; uint64_t poolId; bool allocationPending; // Indexed first by binding number DescriptorWriteTable allWrites; // Indexed first by binding number DescriptorWriteDstArrayRangeTable pendingWriteArrayRanges; // Indexed by binding number std::vector bindingIsImmutableSampler; // Copied from the descriptor set layout std::vector bindings; }; struct DescriptorPoolAllocationInfo { VkDevice device; VkDescriptorPoolCreateFlags createFlags; // TODO: This should be in a single fancy data structure of some kind. std::vector freePoolIds; std::unordered_set allocedPoolIds; std::unordered_set allocedSets; uint32_t maxSets; uint32_t usedSets; // Fine-grained tracking of descriptor counts in individual pools struct DescriptorCountInfo { VkDescriptorType type; uint32_t descriptorCount; uint32_t used; }; std::vector descriptorCountInfo; }; struct DescriptorSetLayoutInfo { std::vector bindings; uint32_t refcount; }; void clearReifiedDescriptorSet(ReifiedDescriptorSet* set); void initDescriptorWriteTable(const std::vector& layoutBindings, DescriptorWriteTable& table); bool isDescriptorTypeImageInfo(VkDescriptorType descType); bool isDescriptorTypeBufferInfo(VkDescriptorType descType); bool isDescriptorTypeBufferView(VkDescriptorType descType); bool isDescriptorTypeInlineUniformBlock(VkDescriptorType descType); bool isDescriptorTypeAccelerationStructure(VkDescriptorType descType); void doEmulatedDescriptorWrite(const VkWriteDescriptorSet* write, ReifiedDescriptorSet* toWrite); void doEmulatedDescriptorCopy(const VkCopyDescriptorSet* copy, const ReifiedDescriptorSet* src, ReifiedDescriptorSet* dst); void doEmulatedDescriptorImageInfoWriteFromTemplate( VkDescriptorType descType, uint32_t binding, uint32_t dstArrayElement, uint32_t count, const VkDescriptorImageInfo* imageInfos, ReifiedDescriptorSet* set); void doEmulatedDescriptorBufferInfoWriteFromTemplate( VkDescriptorType descType, uint32_t binding, uint32_t dstArrayElement, uint32_t count, const VkDescriptorBufferInfo* bufferInfos, ReifiedDescriptorSet* set); void doEmulatedDescriptorBufferViewWriteFromTemplate( VkDescriptorType descType, uint32_t binding, uint32_t dstArrayElement, uint32_t count, const VkBufferView* bufferViews, ReifiedDescriptorSet* set); void applyDescriptorSetAllocation(VkDescriptorPool pool, VkDescriptorSetLayout setLayout); void fillDescriptorSetInfoForPool(VkDescriptorPool pool, VkDescriptorSetLayout setLayout, VkDescriptorSet set); VkResult validateAndApplyVirtualDescriptorSetAllocation(const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pSets); // Returns false if set wasn't found in its pool. bool removeDescriptorSetFromPool(VkDescriptorSet set, bool usePoolIds); std::vector clearDescriptorPool(VkDescriptorPool pool, bool usePoolIds); } // namespace goldfish_vk