2
0

DescriptorSet.cpp 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Gr/Vulkan/DescriptorSet.h>
  6. #include <AnKi/Gr/Buffer.h>
  7. #include <AnKi/Gr/Vulkan/BufferImpl.h>
  8. #include <AnKi/Util/List.h>
  9. #include <AnKi/Util/HashMap.h>
  10. #include <AnKi/Util/Tracer.h>
  11. #include <algorithm>
  12. namespace anki {
  13. /// Wraps a global descriptor set that is used to store bindless textures.
  14. class DescriptorSetFactory::BindlessDescriptorSet
  15. {
  16. public:
  17. ~BindlessDescriptorSet();
  18. Error init(const GrAllocator<U8>& alloc, VkDevice dev, const BindlessLimits& bindlessLimits);
  19. /// Bind a sampled image.
  20. /// @note It's thread-safe.
  21. U32 bindTexture(const VkImageView view, const VkImageLayout layout);
  22. /// Bind a storage image.
  23. /// @note It's thread-safe.
  24. U32 bindImage(const VkImageView view);
  25. /// @note It's thread-safe.
  26. void unbindTexture(U32 idx)
  27. {
  28. unbindCommon(idx, m_freeTexIndices, m_freeTexIndexCount);
  29. }
  30. /// @note It's thread-safe.
  31. void unbindImage(U32 idx)
  32. {
  33. unbindCommon(idx, m_freeImgIndices, m_freeImgIndexCount);
  34. }
  35. DescriptorSet getDescriptorSet() const
  36. {
  37. ANKI_ASSERT(m_dset);
  38. DescriptorSet out;
  39. out.m_handle = m_dset;
  40. return out;
  41. }
  42. VkDescriptorSetLayout getDescriptorSetLayout() const
  43. {
  44. ANKI_ASSERT(m_layout);
  45. return m_layout;
  46. }
  47. private:
  48. GrAllocator<U8> m_alloc;
  49. VkDevice m_dev = VK_NULL_HANDLE;
  50. VkDescriptorSetLayout m_layout = VK_NULL_HANDLE;
  51. VkDescriptorPool m_pool = VK_NULL_HANDLE;
  52. VkDescriptorSet m_dset = VK_NULL_HANDLE;
  53. Mutex m_mtx;
  54. DynamicArray<U16> m_freeTexIndices;
  55. DynamicArray<U16> m_freeImgIndices;
  56. U16 m_freeTexIndexCount ANKI_DEBUG_CODE(= MAX_U16);
  57. U16 m_freeImgIndexCount ANKI_DEBUG_CODE(= MAX_U16);
  58. void unbindCommon(U32 idx, DynamicArray<U16>& freeIndices, U16& freeIndexCount);
  59. };
  60. DescriptorSetFactory::BindlessDescriptorSet::~BindlessDescriptorSet()
  61. {
  62. ANKI_ASSERT(m_freeTexIndexCount == m_freeTexIndices.getSize() && "Forgot to unbind some textures");
  63. ANKI_ASSERT(m_freeImgIndexCount == m_freeImgIndices.getSize() && "Forgot to unbind some images");
  64. if(m_pool)
  65. {
  66. vkDestroyDescriptorPool(m_dev, m_pool, nullptr);
  67. m_pool = VK_NULL_HANDLE;
  68. m_dset = VK_NULL_HANDLE;
  69. }
  70. if(m_layout)
  71. {
  72. vkDestroyDescriptorSetLayout(m_dev, m_layout, nullptr);
  73. m_layout = VK_NULL_HANDLE;
  74. }
  75. m_freeImgIndices.destroy(m_alloc);
  76. m_freeTexIndices.destroy(m_alloc);
  77. }
  78. Error DescriptorSetFactory::BindlessDescriptorSet::init(const GrAllocator<U8>& alloc, VkDevice dev,
  79. const BindlessLimits& bindlessLimits)
  80. {
  81. ANKI_ASSERT(dev);
  82. ANKI_ASSERT(bindlessLimits.m_bindlessTextureCount <= MAX_U16);
  83. ANKI_ASSERT(bindlessLimits.m_bindlessImageCount <= MAX_U16);
  84. m_alloc = alloc;
  85. m_dev = dev;
  86. // Create the layout
  87. {
  88. Array<VkDescriptorSetLayoutBinding, 2> bindings = {};
  89. bindings[0].binding = 0;
  90. bindings[0].stageFlags = VK_SHADER_STAGE_ALL;
  91. bindings[0].descriptorCount = bindlessLimits.m_bindlessTextureCount;
  92. bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
  93. bindings[1].binding = 1;
  94. bindings[1].stageFlags = VK_SHADER_STAGE_ALL;
  95. bindings[1].descriptorCount = bindlessLimits.m_bindlessImageCount;
  96. bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
  97. Array<VkDescriptorBindingFlagsEXT, 2> bindingFlags = {};
  98. bindingFlags[0] = VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT
  99. | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT
  100. | VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT;
  101. bindingFlags[1] = bindingFlags[0];
  102. VkDescriptorSetLayoutBindingFlagsCreateInfoEXT extraInfos = {};
  103. extraInfos.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT;
  104. extraInfos.bindingCount = bindingFlags.getSize();
  105. extraInfos.pBindingFlags = &bindingFlags[0];
  106. VkDescriptorSetLayoutCreateInfo ci = {};
  107. ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
  108. ci.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT;
  109. ci.bindingCount = bindings.getSize();
  110. ci.pBindings = &bindings[0];
  111. ci.pNext = &extraInfos;
  112. ANKI_VK_CHECK(vkCreateDescriptorSetLayout(m_dev, &ci, nullptr, &m_layout));
  113. }
  114. // Create the pool
  115. {
  116. Array<VkDescriptorPoolSize, 2> sizes = {};
  117. sizes[0].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
  118. sizes[0].descriptorCount = bindlessLimits.m_bindlessTextureCount;
  119. sizes[1].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
  120. sizes[1].descriptorCount = bindlessLimits.m_bindlessImageCount;
  121. VkDescriptorPoolCreateInfo ci = {};
  122. ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
  123. ci.maxSets = 1;
  124. ci.poolSizeCount = sizes.getSize();
  125. ci.pPoolSizes = &sizes[0];
  126. ci.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT;
  127. ANKI_VK_CHECK(vkCreateDescriptorPool(m_dev, &ci, nullptr, &m_pool));
  128. }
  129. // Create the descriptor set
  130. {
  131. VkDescriptorSetAllocateInfo ci = {};
  132. ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
  133. ci.descriptorPool = m_pool;
  134. ci.descriptorSetCount = 1;
  135. ci.pSetLayouts = &m_layout;
  136. ANKI_VK_CHECK(vkAllocateDescriptorSets(m_dev, &ci, &m_dset));
  137. }
  138. // Init the free arrays
  139. {
  140. m_freeTexIndices.create(m_alloc, bindlessLimits.m_bindlessTextureCount);
  141. m_freeTexIndexCount = U16(m_freeTexIndices.getSize());
  142. for(U32 i = 0; i < m_freeTexIndices.getSize(); ++i)
  143. {
  144. m_freeTexIndices[i] = U16(m_freeTexIndices.getSize() - i - 1);
  145. }
  146. m_freeImgIndices.create(m_alloc, bindlessLimits.m_bindlessImageCount);
  147. m_freeImgIndexCount = U16(m_freeImgIndices.getSize());
  148. for(U32 i = 0; i < m_freeImgIndices.getSize(); ++i)
  149. {
  150. m_freeImgIndices[i] = U16(m_freeImgIndices.getSize() - i - 1);
  151. }
  152. }
  153. return Error::NONE;
  154. }
  155. U32 DescriptorSetFactory::BindlessDescriptorSet::bindTexture(const VkImageView view, const VkImageLayout layout)
  156. {
  157. ANKI_ASSERT(layout == VK_IMAGE_LAYOUT_GENERAL || layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
  158. ANKI_ASSERT(view);
  159. LockGuard<Mutex> lock(m_mtx);
  160. ANKI_ASSERT(m_freeTexIndexCount > 0 && "Out of indices");
  161. // Get the index
  162. --m_freeTexIndexCount;
  163. const U16 idx = m_freeTexIndices[m_freeTexIndexCount];
  164. ANKI_ASSERT(idx < m_freeTexIndices.getSize());
  165. // Update the set
  166. VkDescriptorImageInfo imageInf = {};
  167. imageInf.imageView = view;
  168. imageInf.imageLayout = layout;
  169. VkWriteDescriptorSet write = {};
  170. write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
  171. write.pNext = nullptr;
  172. write.dstSet = m_dset;
  173. write.dstBinding = 0;
  174. write.descriptorCount = 1;
  175. write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
  176. write.dstArrayElement = idx;
  177. write.pImageInfo = &imageInf;
  178. vkUpdateDescriptorSets(m_dev, 1, &write, 0, nullptr);
  179. return idx;
  180. }
  181. U32 DescriptorSetFactory::BindlessDescriptorSet::bindImage(const VkImageView view)
  182. {
  183. ANKI_ASSERT(view);
  184. LockGuard<Mutex> lock(m_mtx);
  185. ANKI_ASSERT(m_freeImgIndexCount > 0 && "Out of indices");
  186. // Get the index
  187. --m_freeImgIndexCount;
  188. const U32 idx = m_freeImgIndices[m_freeImgIndexCount];
  189. ANKI_ASSERT(idx < m_freeImgIndices.getSize());
  190. // Update the set
  191. VkDescriptorImageInfo imageInf = {};
  192. imageInf.imageView = view;
  193. imageInf.imageLayout = VK_IMAGE_LAYOUT_GENERAL; // Storage images are always in general.
  194. VkWriteDescriptorSet write = {};
  195. write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
  196. write.pNext = nullptr;
  197. write.dstSet = m_dset;
  198. write.dstBinding = 1;
  199. write.descriptorCount = 1;
  200. write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
  201. write.dstArrayElement = idx;
  202. write.pImageInfo = &imageInf;
  203. vkUpdateDescriptorSets(m_dev, 1, &write, 0, nullptr);
  204. return idx;
  205. }
  206. void DescriptorSetFactory::BindlessDescriptorSet::unbindCommon(U32 idx, DynamicArray<U16>& freeIndices,
  207. U16& freeIndexCount)
  208. {
  209. ANKI_ASSERT(idx < freeIndices.getSize());
  210. LockGuard<Mutex> lock(m_mtx);
  211. ANKI_ASSERT(freeIndexCount < freeIndices.getSize());
  212. freeIndices[freeIndexCount] = U16(idx);
  213. ++freeIndexCount;
  214. // Sort the free indices to minimize fragmentation
  215. std::sort(&freeIndices[0], &freeIndices[0] + freeIndexCount, std::greater<U16>());
  216. // Make sure there are no duplicates
  217. for(U32 i = 1; i < freeIndexCount; ++i)
  218. {
  219. ANKI_ASSERT(freeIndices[i] != freeIndices[i - 1]);
  220. }
  221. }
  222. /// Descriptor set internal class.
  223. class DS : public IntrusiveListEnabled<DS>
  224. {
  225. public:
  226. VkDescriptorSet m_handle = {};
  227. U64 m_lastFrameUsed = MAX_U64;
  228. U64 m_hash;
  229. };
  230. /// Per thread allocator.
  231. class alignas(ANKI_CACHE_LINE_SIZE) DSThreadAllocator
  232. {
  233. public:
  234. DSThreadAllocator(const DSThreadAllocator&) = delete; // Non-copyable
  235. DSThreadAllocator& operator=(const DSThreadAllocator&) = delete; // Non-copyable
  236. const DSLayoutCacheEntry* m_layoutEntry; ///< Know your father.
  237. ThreadId m_tid;
  238. DynamicArray<VkDescriptorPool> m_pools;
  239. U32 m_lastPoolDSCount = 0;
  240. U32 m_lastPoolFreeDSCount = 0;
  241. IntrusiveList<DS> m_list; ///< At the left of the list are the least used sets.
  242. HashMap<U64, DS*> m_hashmap;
  243. DSThreadAllocator(const DSLayoutCacheEntry* layout, ThreadId tid)
  244. : m_layoutEntry(layout)
  245. , m_tid(tid)
  246. {
  247. ANKI_ASSERT(m_layoutEntry);
  248. }
  249. ~DSThreadAllocator();
  250. ANKI_USE_RESULT Error init();
  251. ANKI_USE_RESULT Error createNewPool();
  252. ANKI_USE_RESULT Error getOrCreateSet(U64 hash,
  253. const Array<AnyBindingExtended, MAX_BINDINGS_PER_DESCRIPTOR_SET>& bindings,
  254. StackAllocator<U8>& tmpAlloc, const DS*& out)
  255. {
  256. out = tryFindSet(hash);
  257. if(out == nullptr)
  258. {
  259. ANKI_CHECK(newSet(hash, bindings, tmpAlloc, out));
  260. }
  261. return Error::NONE;
  262. }
  263. private:
  264. ANKI_USE_RESULT const DS* tryFindSet(U64 hash);
  265. ANKI_USE_RESULT Error newSet(U64 hash, const Array<AnyBindingExtended, MAX_BINDINGS_PER_DESCRIPTOR_SET>& bindings,
  266. StackAllocator<U8>& tmpAlloc, const DS*& out);
  267. void writeSet(const Array<AnyBindingExtended, MAX_BINDINGS_PER_DESCRIPTOR_SET>& bindings, const DS& set,
  268. StackAllocator<U8>& tmpAlloc);
  269. };
  270. /// Cache entry. It's built around a specific descriptor set layout.
  271. class DSLayoutCacheEntry
  272. {
  273. public:
  274. DescriptorSetFactory* m_factory;
  275. U64 m_hash = 0; ///< Layout hash.
  276. VkDescriptorSetLayout m_layoutHandle = {};
  277. BitSet<MAX_BINDINGS_PER_DESCRIPTOR_SET, U32> m_activeBindings = {false};
  278. Array<U32, MAX_BINDINGS_PER_DESCRIPTOR_SET> m_bindingArraySize = {};
  279. Array<DescriptorType, MAX_BINDINGS_PER_DESCRIPTOR_SET> m_bindingType = {};
  280. U32 m_minBinding = MAX_U32;
  281. U32 m_maxBinding = 0;
  282. // Cache the create info
  283. Array<VkDescriptorPoolSize, U(DescriptorType::COUNT)> m_poolSizesCreateInf = {};
  284. VkDescriptorPoolCreateInfo m_poolCreateInf = {};
  285. DynamicArray<DSThreadAllocator*> m_threadAllocs;
  286. RWMutex m_threadAllocsMtx;
  287. DSLayoutCacheEntry(DescriptorSetFactory* factory)
  288. : m_factory(factory)
  289. {
  290. }
  291. ~DSLayoutCacheEntry();
  292. ANKI_USE_RESULT Error init(const DescriptorBinding* bindings, U32 bindingCount, U64 hash);
  293. /// @note Thread-safe.
  294. ANKI_USE_RESULT Error getOrCreateThreadAllocator(ThreadId tid, DSThreadAllocator*& alloc);
  295. };
  296. DSThreadAllocator::~DSThreadAllocator()
  297. {
  298. auto alloc = m_layoutEntry->m_factory->m_alloc;
  299. while(!m_list.isEmpty())
  300. {
  301. DS* ds = &m_list.getFront();
  302. m_list.popFront();
  303. alloc.deleteInstance(ds);
  304. }
  305. for(VkDescriptorPool pool : m_pools)
  306. {
  307. vkDestroyDescriptorPool(m_layoutEntry->m_factory->m_dev, pool, nullptr);
  308. }
  309. m_pools.destroy(alloc);
  310. m_hashmap.destroy(alloc);
  311. }
  312. Error DSThreadAllocator::init()
  313. {
  314. ANKI_CHECK(createNewPool());
  315. return Error::NONE;
  316. }
  317. Error DSThreadAllocator::createNewPool()
  318. {
  319. m_lastPoolDSCount = (m_lastPoolDSCount != 0) ? U32(F32(m_lastPoolDSCount) * DESCRIPTOR_POOL_SIZE_SCALE)
  320. : DESCRIPTOR_POOL_INITIAL_SIZE;
  321. m_lastPoolFreeDSCount = m_lastPoolDSCount;
  322. // Set the create info
  323. Array<VkDescriptorPoolSize, U(DescriptorType::COUNT)> poolSizes;
  324. memcpy(&poolSizes[0], &m_layoutEntry->m_poolSizesCreateInf[0],
  325. sizeof(poolSizes[0]) * m_layoutEntry->m_poolCreateInf.poolSizeCount);
  326. for(U i = 0; i < m_layoutEntry->m_poolCreateInf.poolSizeCount; ++i)
  327. {
  328. poolSizes[i].descriptorCount *= m_lastPoolDSCount;
  329. ANKI_ASSERT(poolSizes[i].descriptorCount > 0);
  330. }
  331. VkDescriptorPoolCreateInfo ci = m_layoutEntry->m_poolCreateInf;
  332. ci.pPoolSizes = &poolSizes[0];
  333. ci.maxSets = m_lastPoolDSCount;
  334. // Create
  335. VkDescriptorPool pool;
  336. ANKI_VK_CHECK(vkCreateDescriptorPool(m_layoutEntry->m_factory->m_dev, &ci, nullptr, &pool));
  337. ANKI_TRACE_INC_COUNTER(VK_DESCRIPTOR_POOL_CREATE, 1);
  338. // Push back
  339. m_pools.resize(m_layoutEntry->m_factory->m_alloc, m_pools.getSize() + 1);
  340. m_pools[m_pools.getSize() - 1] = pool;
  341. return Error::NONE;
  342. }
  343. const DS* DSThreadAllocator::tryFindSet(U64 hash)
  344. {
  345. ANKI_ASSERT(hash > 0);
  346. auto it = m_hashmap.find(hash);
  347. if(it == m_hashmap.getEnd())
  348. {
  349. return nullptr;
  350. }
  351. else
  352. {
  353. DS* ds = *it;
  354. // Remove from the list and place at the end of the list
  355. m_list.erase(ds);
  356. m_list.pushBack(ds);
  357. ds->m_lastFrameUsed = m_layoutEntry->m_factory->m_frameCount;
  358. return ds;
  359. }
  360. }
  361. Error DSThreadAllocator::newSet(U64 hash, const Array<AnyBindingExtended, MAX_BINDINGS_PER_DESCRIPTOR_SET>& bindings,
  362. StackAllocator<U8>& tmpAlloc, const DS*& out_)
  363. {
  364. DS* out = nullptr;
  365. // First try to see if there are unused to recycle
  366. const U64 crntFrame = m_layoutEntry->m_factory->m_frameCount;
  367. auto it = m_list.getBegin();
  368. const auto end = m_list.getEnd();
  369. while(it != end)
  370. {
  371. DS* set = &(*it);
  372. U64 frameDiff = crntFrame - set->m_lastFrameUsed;
  373. if(frameDiff > DESCRIPTOR_FRAME_BUFFERING)
  374. {
  375. // Found something, recycle
  376. auto it2 = m_hashmap.find(set->m_hash);
  377. ANKI_ASSERT(it2 != m_hashmap.getEnd());
  378. m_hashmap.erase(m_layoutEntry->m_factory->m_alloc, it2);
  379. m_list.erase(set);
  380. m_list.pushBack(set);
  381. m_hashmap.emplace(m_layoutEntry->m_factory->m_alloc, hash, set);
  382. out = set;
  383. break;
  384. }
  385. ++it;
  386. }
  387. if(out == nullptr)
  388. {
  389. // Need to allocate one
  390. if(m_lastPoolFreeDSCount == 0)
  391. {
  392. // Can't allocate one from the current pool, create new
  393. ANKI_CHECK(createNewPool());
  394. }
  395. --m_lastPoolFreeDSCount;
  396. VkDescriptorSetAllocateInfo ci = {};
  397. ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
  398. ci.descriptorPool = m_pools.getBack();
  399. ci.pSetLayouts = &m_layoutEntry->m_layoutHandle;
  400. ci.descriptorSetCount = 1;
  401. VkDescriptorSet handle;
  402. VkResult rez = vkAllocateDescriptorSets(m_layoutEntry->m_factory->m_dev, &ci, &handle);
  403. (void)rez;
  404. ANKI_ASSERT(rez == VK_SUCCESS && "That allocation can't fail");
  405. ANKI_TRACE_INC_COUNTER(VK_DESCRIPTOR_SET_CREATE, 1);
  406. out = m_layoutEntry->m_factory->m_alloc.newInstance<DS>();
  407. out->m_handle = handle;
  408. m_hashmap.emplace(m_layoutEntry->m_factory->m_alloc, hash, out);
  409. m_list.pushBack(out);
  410. }
  411. ANKI_ASSERT(out);
  412. out->m_lastFrameUsed = crntFrame;
  413. out->m_hash = hash;
  414. // Finally, write it
  415. writeSet(bindings, *out, tmpAlloc);
  416. out_ = out;
  417. return Error::NONE;
  418. }
  419. void DSThreadAllocator::writeSet(const Array<AnyBindingExtended, MAX_BINDINGS_PER_DESCRIPTOR_SET>& bindings,
  420. const DS& set, StackAllocator<U8>& tmpAlloc)
  421. {
  422. DynamicArrayAuto<VkWriteDescriptorSet> writeInfos(tmpAlloc);
  423. DynamicArrayAuto<VkDescriptorImageInfo> texInfos(tmpAlloc);
  424. DynamicArrayAuto<VkDescriptorBufferInfo> buffInfos(tmpAlloc);
  425. DynamicArrayAuto<VkWriteDescriptorSetAccelerationStructureKHR> asInfos(tmpAlloc);
  426. // First pass: Populate the VkDescriptorImageInfo and VkDescriptorBufferInfo
  427. for(U bindingIdx = m_layoutEntry->m_minBinding; bindingIdx <= m_layoutEntry->m_maxBinding; ++bindingIdx)
  428. {
  429. if(m_layoutEntry->m_activeBindings.get(bindingIdx))
  430. {
  431. for(U arrIdx = 0; arrIdx < m_layoutEntry->m_bindingArraySize[bindingIdx]; ++arrIdx)
  432. {
  433. ANKI_ASSERT(bindings[bindingIdx].m_arraySize >= m_layoutEntry->m_bindingArraySize[bindingIdx]);
  434. const AnyBinding& b = (bindings[bindingIdx].m_arraySize == 1) ? bindings[bindingIdx].m_single
  435. : bindings[bindingIdx].m_array[arrIdx];
  436. switch(b.m_type)
  437. {
  438. case DescriptorType::COMBINED_TEXTURE_SAMPLER:
  439. {
  440. VkDescriptorImageInfo& info = *texInfos.emplaceBack();
  441. info.sampler = b.m_texAndSampler.m_samplerHandle;
  442. info.imageView = b.m_texAndSampler.m_imgViewHandle;
  443. info.imageLayout = b.m_texAndSampler.m_layout;
  444. break;
  445. }
  446. case DescriptorType::TEXTURE:
  447. {
  448. VkDescriptorImageInfo& info = *texInfos.emplaceBack();
  449. info.sampler = VK_NULL_HANDLE;
  450. info.imageView = b.m_tex.m_imgViewHandle;
  451. info.imageLayout = b.m_tex.m_layout;
  452. break;
  453. }
  454. case DescriptorType::SAMPLER:
  455. {
  456. VkDescriptorImageInfo& info = *texInfos.emplaceBack();
  457. info.sampler = b.m_sampler.m_samplerHandle;
  458. info.imageView = VK_NULL_HANDLE;
  459. info.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
  460. break;
  461. }
  462. case DescriptorType::UNIFORM_BUFFER:
  463. case DescriptorType::STORAGE_BUFFER:
  464. {
  465. VkDescriptorBufferInfo& info = *buffInfos.emplaceBack();
  466. info.buffer = b.m_buff.m_buffHandle;
  467. info.offset = 0;
  468. info.range = (b.m_buff.m_range == MAX_PTR_SIZE) ? VK_WHOLE_SIZE : b.m_buff.m_range;
  469. break;
  470. }
  471. case DescriptorType::IMAGE:
  472. {
  473. VkDescriptorImageInfo& info = *texInfos.emplaceBack();
  474. info.sampler = VK_NULL_HANDLE;
  475. info.imageView = b.m_image.m_imgViewHandle;
  476. info.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
  477. break;
  478. }
  479. case DescriptorType::ACCELERATION_STRUCTURE:
  480. {
  481. VkWriteDescriptorSetAccelerationStructureKHR& info = *asInfos.emplaceBack();
  482. info.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR;
  483. info.pNext = nullptr;
  484. info.accelerationStructureCount = 1;
  485. info.pAccelerationStructures = &b.m_accelerationStructure.m_accelerationStructureHandle;
  486. break;
  487. }
  488. default:
  489. ANKI_ASSERT(0);
  490. }
  491. }
  492. }
  493. }
  494. // Second pass: Populate the VkWriteDescriptorSet with VkDescriptorImageInfo and VkDescriptorBufferInfo
  495. U32 texCounter = 0;
  496. U32 buffCounter = 0;
  497. U32 asCounter = 0;
  498. VkWriteDescriptorSet writeTemplate{};
  499. writeTemplate.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
  500. writeTemplate.pNext = nullptr;
  501. writeTemplate.dstSet = set.m_handle;
  502. writeTemplate.descriptorCount = 1;
  503. for(U32 bindingIdx = m_layoutEntry->m_minBinding; bindingIdx <= m_layoutEntry->m_maxBinding; ++bindingIdx)
  504. {
  505. if(m_layoutEntry->m_activeBindings.get(bindingIdx))
  506. {
  507. for(U32 arrIdx = 0; arrIdx < m_layoutEntry->m_bindingArraySize[bindingIdx]; ++arrIdx)
  508. {
  509. const AnyBinding& b = (bindings[bindingIdx].m_arraySize == 1) ? bindings[bindingIdx].m_single
  510. : bindings[bindingIdx].m_array[arrIdx];
  511. VkWriteDescriptorSet& writeInfo = *writeInfos.emplaceBack(writeTemplate);
  512. writeInfo.descriptorType = convertDescriptorType(b.m_type);
  513. writeInfo.dstArrayElement = arrIdx;
  514. writeInfo.dstBinding = bindingIdx;
  515. switch(b.m_type)
  516. {
  517. case DescriptorType::COMBINED_TEXTURE_SAMPLER:
  518. case DescriptorType::TEXTURE:
  519. case DescriptorType::SAMPLER:
  520. case DescriptorType::IMAGE:
  521. writeInfo.pImageInfo = &texInfos[texCounter++];
  522. break;
  523. case DescriptorType::UNIFORM_BUFFER:
  524. case DescriptorType::STORAGE_BUFFER:
  525. writeInfo.pBufferInfo = &buffInfos[buffCounter++];
  526. break;
  527. case DescriptorType::ACCELERATION_STRUCTURE:
  528. writeInfo.pNext = &asInfos[asCounter++];
  529. break;
  530. default:
  531. ANKI_ASSERT(0);
  532. }
  533. }
  534. }
  535. }
  536. // Write
  537. vkUpdateDescriptorSets(m_layoutEntry->m_factory->m_dev, writeInfos.getSize(),
  538. (writeInfos.getSize() > 0) ? &writeInfos[0] : nullptr, 0, nullptr);
  539. }
  540. DSLayoutCacheEntry::~DSLayoutCacheEntry()
  541. {
  542. auto alloc = m_factory->m_alloc;
  543. for(DSThreadAllocator* a : m_threadAllocs)
  544. {
  545. alloc.deleteInstance(a);
  546. }
  547. m_threadAllocs.destroy(alloc);
  548. if(m_layoutHandle)
  549. {
  550. vkDestroyDescriptorSetLayout(m_factory->m_dev, m_layoutHandle, nullptr);
  551. }
  552. }
  553. Error DSLayoutCacheEntry::init(const DescriptorBinding* bindings, U32 bindingCount, U64 hash)
  554. {
  555. ANKI_ASSERT(bindings);
  556. ANKI_ASSERT(hash > 0);
  557. m_hash = hash;
  558. // Create the VK layout
  559. Array<VkDescriptorSetLayoutBinding, MAX_BINDINGS_PER_DESCRIPTOR_SET> vkBindings;
  560. VkDescriptorSetLayoutCreateInfo ci = {};
  561. ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
  562. for(U i = 0; i < bindingCount; ++i)
  563. {
  564. VkDescriptorSetLayoutBinding& vk = vkBindings[i];
  565. const DescriptorBinding& ak = bindings[i];
  566. vk.binding = ak.m_binding;
  567. vk.descriptorCount = ak.m_arraySizeMinusOne + 1;
  568. vk.descriptorType = convertDescriptorType(ak.m_type);
  569. vk.pImmutableSamplers = nullptr;
  570. vk.stageFlags = convertShaderTypeBit(ak.m_stageMask);
  571. ANKI_ASSERT(m_activeBindings.get(ak.m_binding) == false);
  572. m_activeBindings.set(ak.m_binding);
  573. m_bindingType[ak.m_binding] = ak.m_type;
  574. m_bindingArraySize[ak.m_binding] = ak.m_arraySizeMinusOne + 1;
  575. m_minBinding = min<U32>(m_minBinding, ak.m_binding);
  576. m_maxBinding = max<U32>(m_maxBinding, ak.m_binding);
  577. }
  578. ci.bindingCount = bindingCount;
  579. ci.pBindings = &vkBindings[0];
  580. ANKI_VK_CHECK(vkCreateDescriptorSetLayout(m_factory->m_dev, &ci, nullptr, &m_layoutHandle));
  581. // Create the pool info
  582. U32 poolSizeCount = 0;
  583. for(U i = 0; i < bindingCount; ++i)
  584. {
  585. U j;
  586. for(j = 0; j < poolSizeCount; ++j)
  587. {
  588. if(m_poolSizesCreateInf[j].type == convertDescriptorType(bindings[i].m_type))
  589. {
  590. m_poolSizesCreateInf[j].descriptorCount += bindings[i].m_arraySizeMinusOne + 1;
  591. break;
  592. }
  593. }
  594. if(j == poolSizeCount)
  595. {
  596. m_poolSizesCreateInf[poolSizeCount].type = convertDescriptorType(bindings[i].m_type);
  597. m_poolSizesCreateInf[poolSizeCount].descriptorCount = bindings[i].m_arraySizeMinusOne + 1;
  598. ++poolSizeCount;
  599. }
  600. }
  601. if(poolSizeCount == 0)
  602. {
  603. // If the poolSizeCount it means that the DS layout has 0 descriptors. Since the pool sizes can't be zero put
  604. // something in them
  605. m_poolSizesCreateInf[0].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
  606. m_poolSizesCreateInf[0].descriptorCount = 1;
  607. ++poolSizeCount;
  608. }
  609. ANKI_ASSERT(poolSizeCount > 0);
  610. m_poolCreateInf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
  611. m_poolCreateInf.poolSizeCount = poolSizeCount;
  612. return Error::NONE;
  613. }
  614. Error DSLayoutCacheEntry::getOrCreateThreadAllocator(ThreadId tid, DSThreadAllocator*& alloc)
  615. {
  616. alloc = nullptr;
  617. class Comp
  618. {
  619. public:
  620. Bool operator()(const DSThreadAllocator* a, ThreadId tid) const
  621. {
  622. return a->m_tid < tid;
  623. }
  624. Bool operator()(ThreadId tid, const DSThreadAllocator* a) const
  625. {
  626. return tid < a->m_tid;
  627. }
  628. };
  629. // Find using binary search
  630. {
  631. RLockGuard<RWMutex> lock(m_threadAllocsMtx);
  632. auto it = binarySearch(m_threadAllocs.getBegin(), m_threadAllocs.getEnd(), tid, Comp());
  633. alloc = (it != m_threadAllocs.getEnd()) ? *it : nullptr;
  634. }
  635. if(alloc == nullptr)
  636. {
  637. // Need to create one
  638. WLockGuard<RWMutex> lock(m_threadAllocsMtx);
  639. // Search again
  640. auto it = binarySearch(m_threadAllocs.getBegin(), m_threadAllocs.getEnd(), tid, Comp());
  641. alloc = (it != m_threadAllocs.getEnd()) ? *it : nullptr;
  642. // Create
  643. if(alloc == nullptr)
  644. {
  645. alloc = m_factory->m_alloc.newInstance<DSThreadAllocator>(this, tid);
  646. ANKI_CHECK(alloc->init());
  647. m_threadAllocs.resize(m_factory->m_alloc, m_threadAllocs.getSize() + 1);
  648. m_threadAllocs[m_threadAllocs.getSize() - 1] = alloc;
  649. // Sort for fast find
  650. std::sort(m_threadAllocs.getBegin(), m_threadAllocs.getEnd(),
  651. [](const DSThreadAllocator* a, const DSThreadAllocator* b) {
  652. return a->m_tid < b->m_tid;
  653. });
  654. }
  655. }
  656. ANKI_ASSERT(alloc);
  657. ANKI_ASSERT(alloc->m_tid == tid);
  658. return Error::NONE;
  659. }
  660. void DescriptorSetState::flush(U64& hash, Array<PtrSize, MAX_BINDINGS_PER_DESCRIPTOR_SET>& dynamicOffsets,
  661. U32& dynamicOffsetCount, Bool& bindlessDSet)
  662. {
  663. // Set some values
  664. hash = 0;
  665. dynamicOffsetCount = 0;
  666. bindlessDSet = false;
  667. if(!m_bindlessDSetBound)
  668. {
  669. // Get cache entry
  670. ANKI_ASSERT(m_layout.m_entry);
  671. const DSLayoutCacheEntry& entry = *m_layout.m_entry;
  672. // Early out if nothing happened
  673. const Bool anyActiveBindingDirty = !!(entry.m_activeBindings & m_dirtyBindings);
  674. if(!anyActiveBindingDirty && !m_layoutDirty)
  675. {
  676. return;
  677. }
  678. Bool dynamicOffsetsDirty = false;
  679. // Compute the hash
  680. Array<U64, MAX_BINDINGS_PER_DESCRIPTOR_SET * 2 * 2> toHash;
  681. U toHashCount = 0;
  682. const U minBinding = entry.m_minBinding;
  683. const U maxBinding = entry.m_maxBinding;
  684. for(U i = minBinding; i <= maxBinding; ++i)
  685. {
  686. if(entry.m_activeBindings.get(i))
  687. {
  688. ANKI_ASSERT(m_bindingSet.get(i) && "Forgot to bind");
  689. ANKI_ASSERT(m_bindings[i].m_arraySize >= entry.m_bindingArraySize[i] && "Bound less");
  690. const Bool crntBindingDirty = m_dirtyBindings.get(i);
  691. m_dirtyBindings.unset(i);
  692. for(U arrIdx = 0; arrIdx < entry.m_bindingArraySize[i]; ++arrIdx)
  693. {
  694. ANKI_ASSERT(arrIdx < m_bindings[i].m_arraySize);
  695. if(arrIdx > 1)
  696. {
  697. ANKI_ASSERT(m_bindings[i].m_array[arrIdx].m_type == m_bindings[i].m_array[arrIdx - 1].m_type);
  698. }
  699. const AnyBinding& anyBinding =
  700. (m_bindings[i].m_arraySize == 1) ? m_bindings[i].m_single : m_bindings[i].m_array[arrIdx];
  701. ANKI_ASSERT(anyBinding.m_uuids[0] != 0 && "Forgot to bind");
  702. toHash[toHashCount++] = anyBinding.m_uuids[0];
  703. switch(entry.m_bindingType[i])
  704. {
  705. case DescriptorType::COMBINED_TEXTURE_SAMPLER:
  706. ANKI_ASSERT(anyBinding.m_type == DescriptorType::COMBINED_TEXTURE_SAMPLER
  707. && "Have bound the wrong type");
  708. toHash[toHashCount++] = anyBinding.m_uuids[1];
  709. toHash[toHashCount++] = U64(anyBinding.m_texAndSampler.m_layout);
  710. break;
  711. case DescriptorType::TEXTURE:
  712. ANKI_ASSERT(anyBinding.m_type == DescriptorType::TEXTURE && "Have bound the wrong type");
  713. toHash[toHashCount++] = U64(anyBinding.m_tex.m_layout);
  714. break;
  715. case DescriptorType::SAMPLER:
  716. ANKI_ASSERT(anyBinding.m_type == DescriptorType::SAMPLER && "Have bound the wrong type");
  717. break;
  718. case DescriptorType::UNIFORM_BUFFER:
  719. ANKI_ASSERT(anyBinding.m_type == DescriptorType::UNIFORM_BUFFER && "Have bound the wrong type");
  720. toHash[toHashCount++] = anyBinding.m_buff.m_range;
  721. dynamicOffsets[dynamicOffsetCount++] = anyBinding.m_buff.m_offset;
  722. dynamicOffsetsDirty = dynamicOffsetsDirty || crntBindingDirty;
  723. break;
  724. case DescriptorType::STORAGE_BUFFER:
  725. ANKI_ASSERT(anyBinding.m_type == DescriptorType::STORAGE_BUFFER && "Have bound the wrong type");
  726. toHash[toHashCount++] = anyBinding.m_buff.m_range;
  727. dynamicOffsets[dynamicOffsetCount++] = anyBinding.m_buff.m_offset;
  728. dynamicOffsetsDirty = dynamicOffsetsDirty || crntBindingDirty;
  729. break;
  730. case DescriptorType::IMAGE:
  731. ANKI_ASSERT(anyBinding.m_type == DescriptorType::IMAGE && "Have bound the wrong type");
  732. break;
  733. case DescriptorType::ACCELERATION_STRUCTURE:
  734. ANKI_ASSERT(anyBinding.m_type == DescriptorType::ACCELERATION_STRUCTURE
  735. && "Have bound the wrong type");
  736. break;
  737. default:
  738. ANKI_ASSERT(0);
  739. }
  740. }
  741. }
  742. }
  743. const U64 newHash = computeHash(&toHash[0], toHashCount * sizeof(U64));
  744. if(newHash != m_lastHash || dynamicOffsetsDirty || m_layoutDirty)
  745. {
  746. // DS needs rebind
  747. m_lastHash = newHash;
  748. hash = newHash;
  749. }
  750. else
  751. {
  752. // All clean, keep hash equal to 0
  753. }
  754. m_layoutDirty = false;
  755. }
  756. else
  757. {
  758. // Custom set
  759. if(!m_bindlessDSetDirty && !m_layoutDirty)
  760. {
  761. return;
  762. }
  763. bindlessDSet = true;
  764. hash = 1;
  765. m_bindlessDSetDirty = false;
  766. m_layoutDirty = false;
  767. }
  768. }
  769. DescriptorSetFactory::~DescriptorSetFactory()
  770. {
  771. }
  772. Error DescriptorSetFactory::init(const GrAllocator<U8>& alloc, VkDevice dev, const BindlessLimits& bindlessLimits)
  773. {
  774. m_alloc = alloc;
  775. m_dev = dev;
  776. m_bindless = m_alloc.newInstance<BindlessDescriptorSet>();
  777. ANKI_CHECK(m_bindless->init(alloc, dev, bindlessLimits));
  778. m_bindlessLimits = bindlessLimits;
  779. return Error::NONE;
  780. }
  781. void DescriptorSetFactory::destroy()
  782. {
  783. for(DSLayoutCacheEntry* l : m_caches)
  784. {
  785. m_alloc.deleteInstance(l);
  786. }
  787. m_caches.destroy(m_alloc);
  788. if(m_bindless)
  789. {
  790. m_alloc.deleteInstance(m_bindless);
  791. }
  792. }
  793. Error DescriptorSetFactory::newDescriptorSetLayout(const DescriptorSetLayoutInitInfo& init, DescriptorSetLayout& layout)
  794. {
  795. // Compute the hash for the layout
  796. Array<DescriptorBinding, MAX_BINDINGS_PER_DESCRIPTOR_SET> bindings;
  797. const U32 bindingCount = init.m_bindings.getSize();
  798. U64 hash;
  799. if(init.m_bindings.getSize() > 0)
  800. {
  801. memcpy(bindings.getBegin(), init.m_bindings.getBegin(), init.m_bindings.getSizeInBytes());
  802. std::sort(bindings.getBegin(), bindings.getBegin() + bindingCount,
  803. [](const DescriptorBinding& a, const DescriptorBinding& b) {
  804. return a.m_binding < b.m_binding;
  805. });
  806. hash = computeHash(&bindings[0], init.m_bindings.getSizeInBytes());
  807. ANKI_ASSERT(hash != 1);
  808. }
  809. else
  810. {
  811. hash = 1;
  812. }
  813. // Identify if the DS is the bindless one. It is if there is at least one binding that matches the criteria
  814. Bool isBindless = false;
  815. if(bindingCount > 0)
  816. {
  817. isBindless = true;
  818. for(U32 i = 0; i < bindingCount; ++i)
  819. {
  820. const DescriptorBinding& binding = bindings[i];
  821. if(binding.m_binding == 0 && binding.m_type == DescriptorType::TEXTURE
  822. && binding.m_arraySizeMinusOne == m_bindlessLimits.m_bindlessTextureCount - 1)
  823. {
  824. // All good
  825. }
  826. else if(binding.m_binding == 1 && binding.m_type == DescriptorType::IMAGE
  827. && binding.m_arraySizeMinusOne == m_bindlessLimits.m_bindlessImageCount - 1)
  828. {
  829. // All good
  830. }
  831. else
  832. {
  833. isBindless = false;
  834. }
  835. }
  836. }
  837. // Find or create the cache entry
  838. if(isBindless)
  839. {
  840. layout.m_handle = m_bindless->getDescriptorSetLayout();
  841. layout.m_entry = nullptr;
  842. }
  843. else
  844. {
  845. LockGuard<SpinLock> lock(m_cachesMtx);
  846. DSLayoutCacheEntry* cache = nullptr;
  847. U count = 0;
  848. for(DSLayoutCacheEntry* it : m_caches)
  849. {
  850. if(it->m_hash == hash)
  851. {
  852. cache = it;
  853. break;
  854. }
  855. ++count;
  856. }
  857. if(cache == nullptr)
  858. {
  859. cache = m_alloc.newInstance<DSLayoutCacheEntry>(this);
  860. ANKI_CHECK(cache->init(bindings.getBegin(), bindingCount, hash));
  861. m_caches.resize(m_alloc, m_caches.getSize() + 1);
  862. m_caches[m_caches.getSize() - 1] = cache;
  863. }
  864. // Set the layout
  865. layout.m_handle = cache->m_layoutHandle;
  866. layout.m_entry = cache;
  867. }
  868. return Error::NONE;
  869. }
  870. Error DescriptorSetFactory::newDescriptorSet(ThreadId tid, StackAllocator<U8>& tmpAlloc, DescriptorSetState& state,
  871. DescriptorSet& set, Bool& dirty,
  872. Array<PtrSize, MAX_BINDINGS_PER_DESCRIPTOR_SET>& dynamicOffsets,
  873. U32& dynamicOffsetCount)
  874. {
  875. ANKI_TRACE_SCOPED_EVENT(VK_DESCRIPTOR_SET_GET_OR_CREATE);
  876. U64 hash;
  877. Bool bindlessDSet;
  878. state.flush(hash, dynamicOffsets, dynamicOffsetCount, bindlessDSet);
  879. if(hash == 0)
  880. {
  881. dirty = false;
  882. return Error::NONE;
  883. }
  884. else
  885. {
  886. dirty = true;
  887. if(!bindlessDSet)
  888. {
  889. DescriptorSetLayout layout = state.m_layout;
  890. DSLayoutCacheEntry& entry = *layout.m_entry;
  891. // Get thread allocator
  892. DSThreadAllocator* alloc;
  893. ANKI_CHECK(entry.getOrCreateThreadAllocator(tid, alloc));
  894. // Finally, allocate
  895. const DS* s;
  896. ANKI_CHECK(alloc->getOrCreateSet(hash, state.m_bindings, tmpAlloc, s));
  897. set.m_handle = s->m_handle;
  898. ANKI_ASSERT(set.m_handle != VK_NULL_HANDLE);
  899. }
  900. else
  901. {
  902. set = m_bindless->getDescriptorSet();
  903. }
  904. }
  905. return Error::NONE;
  906. }
  907. U32 DescriptorSetFactory::bindBindlessTexture(const VkImageView view, const VkImageLayout layout)
  908. {
  909. ANKI_ASSERT(m_bindless);
  910. return m_bindless->bindTexture(view, layout);
  911. }
  912. U32 DescriptorSetFactory::bindBindlessImage(const VkImageView view)
  913. {
  914. ANKI_ASSERT(m_bindless);
  915. return m_bindless->bindImage(view);
  916. }
  917. void DescriptorSetFactory::unbindBindlessTexture(U32 idx)
  918. {
  919. ANKI_ASSERT(m_bindless);
  920. m_bindless->unbindTexture(idx);
  921. }
  922. void DescriptorSetFactory::unbindBindlessImage(U32 idx)
  923. {
  924. ANKI_ASSERT(m_bindless);
  925. m_bindless->unbindImage(idx);
  926. }
  927. } // end namespace anki