17#if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
18#include <sanitizer/lsan_interface.h>
34 for (
int i = 0 ;
i < uniformHandler.numSamplers(); ++
i) {
35 visibilities.
push_back(uniformHandler.samplerVisibility(
i));
36 immutableSamplers.
push_back(uniformHandler.immutableSampler(
i));
38 return Create(gpu,
type, visibilities, immutableSamplers);
70 VkDescriptorSetLayout* descSetLayout,
71 uint32_t* descCountPerSet) {
74 uint32_t numBindings = visibilities.
size();
75 std::unique_ptr<VkDescriptorSetLayoutBinding[]> dsSamplerBindings(
78 for (uint32_t
i = 0;
i < numBindings; ++
i) {
79 uint32_t visibility = visibilities[
i];
80 dsSamplerBindings[
i].binding =
i;
81 dsSamplerBindings[
i].descriptorType =
type;
82 dsSamplerBindings[
i].descriptorCount = 1;
85 if (immutableSamplers[
i]) {
87 dsSamplerBindings[
i].pImmutableSamplers = immutableSamplers[
i]->samplerPtr();
90 dsSamplerBindings[
i].pImmutableSamplers =
nullptr;
98 dsSamplerLayoutCreateInfo.
pNext =
nullptr;
99 dsSamplerLayoutCreateInfo.
flags = 0;
104 dsSamplerLayoutCreateInfo.
pBindings = numBindings ? dsSamplerBindings.get() :
nullptr;
106#if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
108 __lsan::ScopedDisabler lsanDisabler;
112 CreateDescriptorSetLayout(gpu->
device(),
113 &dsSamplerLayoutCreateInfo,
120 static constexpr int kUniformDescPerSet = 1;
132 uniformLayoutCreateInfo.
pNext =
nullptr;
133 uniformLayoutCreateInfo.
flags = 0;
135 uniformLayoutCreateInfo.
pBindings = &dsUniBinding;
137#if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
139 __lsan::ScopedDisabler lsanDisabler;
143 &uniformLayoutCreateInfo,
150 *descCountPerSet = kUniformDescPerSet;
153 static constexpr int kInputDescPerSet = 1;
167 inputLayoutCreateInfo.
pNext =
nullptr;
168 inputLayoutCreateInfo.
flags = 0;
170 inputLayoutCreateInfo.
pBindings = &dsInpuBinding;
172#if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
174 __lsan::ScopedDisabler lsanDisabler;
178 &inputLayoutCreateInfo,
179 nullptr, descSetLayout));
184 *descCountPerSet = kInputDescPerSet;
201 VkDescriptorSetLayout descSetLayout;
202 uint32_t descCountPerSet;
211GrVkDescriptorSetManager::GrVkDescriptorSetManager(
215 : fPoolManager(descSetLayout,
type, descCountPerSet) {
216 for (
int i = 0;
i < visibilities.
size(); ++
i) {
217 fBindingVisibilities.push_back(visibilities[
i]);
219 for (
int i = 0;
i < immutableSamplers.
size(); ++
i) {
224 fImmutableSamplers.push_back(sampler);
229 const Handle& handle) {
233 ds = fFreeSets[
count - 1];
236 VkDescriptorSet vkDS;
237 if (!fPoolManager.getNewDescriptorSet(gpu, &vkDS)) {
253 fPoolManager.freeGPUResources(gpu);
255 for (
int i = 0;
i < fFreeSets.
size(); ++
i) {
256 fFreeSets[
i]->unref();
260 for (
int i = 0;
i < fImmutableSamplers.
size(); ++
i) {
261 if (fImmutableSamplers[
i]) {
262 fImmutableSamplers[
i]->unref();
265 fImmutableSamplers.
clear();
271 if (
type != fPoolManager.fDescType) {
276 if (fBindingVisibilities.
size() != uniHandler->numSamplers()) {
279 for (
int i = 0;
i < uniHandler->numSamplers(); ++
i) {
280 if (uniHandler->samplerVisibility(
i) != fBindingVisibilities[
i] ||
281 uniHandler->immutableSampler(
i) != fImmutableSamplers[
i]) {
292 if (!fBindingVisibilities.
empty()) {
300GrVkDescriptorSetManager::DescriptorPoolManager::DescriptorPoolManager(
301 VkDescriptorSetLayout layout,
303 uint32_t descCountPerSet)
304 : fDescLayout(layout)
306 , fDescCountPerSet(descCountPerSet)
307 , fMaxDescriptors(kStartNumDescriptors)
308 , fCurrentDescriptorCount(0)
312bool GrVkDescriptorSetManager::DescriptorPoolManager::getNewPool(
GrVkGpu* gpu) {
315 uint32_t newPoolSize = fMaxDescriptors + ((fMaxDescriptors + 1) >> 1);
316 if (newPoolSize < kMaxDescriptors) {
317 fMaxDescriptors = newPoolSize;
319 fMaxDescriptors = kMaxDescriptors;
328bool GrVkDescriptorSetManager::DescriptorPoolManager::getNewDescriptorSet(
GrVkGpu* gpu,
329 VkDescriptorSet* ds) {
330 if (!fMaxDescriptors) {
333 fCurrentDescriptorCount += fDescCountPerSet;
334 if (!fPool || fCurrentDescriptorCount > fMaxDescriptors) {
335 if (!this->getNewPool(gpu) ) {
338 fCurrentDescriptorCount = fDescCountPerSet;
344 dsAllocateInfo.
pNext =
nullptr;
355void GrVkDescriptorSetManager::DescriptorPoolManager::freeGPUResources(
GrVkGpu* gpu) {
VkShaderStageFlags visibility_to_vk_stage_flags(uint32_t visibility)
static bool get_layout_and_desc_count(GrVkGpu *gpu, VkDescriptorType type, const TArray< uint32_t > &visibilities, const TArray< const GrVkSampler * > &immutableSamplers, VkDescriptorSetLayout *descSetLayout, uint32_t *descCountPerSet)
#define GR_VK_CALL(IFACE, X)
#define GR_VK_CALL_RESULT(GPU, RESULT, X)
static constexpr bool SkToBool(const T &x)
uint32_t ycbcrCombinedImageSamplerDescriptorCount() const
void recycleDescriptorSet(const GrVkDescriptorSet *)
static GrVkDescriptorSetManager * CreateZeroSamplerManager(GrVkGpu *gpu)
void release(GrVkGpu *gpu)
bool isZeroSampler() const
const GrVkDescriptorSet * getDescriptorSet(GrVkGpu *gpu, const Handle &handle)
static GrVkDescriptorSetManager * CreateSamplerManager(GrVkGpu *gpu, VkDescriptorType type, const GrVkUniformHandler &)
bool isCompatible(VkDescriptorType type, const GrVkUniformHandler *) const
static GrVkDescriptorSetManager * CreateInputManager(GrVkGpu *gpu)
static GrVkDescriptorSetManager * CreateUniformManager(GrVkGpu *gpu)
const GrVkCaps & vkCaps() const
const skgpu::VulkanInterface * vkInterface() const
GrVkResourceProvider & resourceProvider()
GrVkDescriptorPool * findOrCreateCompatibleDescriptorPool(VkDescriptorType type, uint32_t count)
void removeShuffle(int n)
FlutterSemanticsFlag flags
uint32_t descriptorSetCount
VkDescriptorPool descriptorPool
const VkDescriptorSetLayout * pSetLayouts
VkDescriptorType descriptorType
const VkSampler * pImmutableSamplers
VkShaderStageFlags stageFlags
const VkDescriptorSetLayoutBinding * pBindings
VkDescriptorSetLayoutCreateFlags flags
@ VK_SHADER_STAGE_VERTEX_BIT
@ VK_SHADER_STAGE_FRAGMENT_BIT
VkFlags VkShaderStageFlags
@ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
@ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
@ VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
@ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
@ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
@ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO