2
0

DescriptorSet.cpp 31 KB

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