TextureViewImpl.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (C) 2009-2020, 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/TextureViewImpl.h>
  6. #include <anki/gr/vulkan/TextureImpl.h>
  7. #include <anki/gr/vulkan/GrManagerImpl.h>
  8. namespace anki
  9. {
  10. TextureViewImpl::~TextureViewImpl()
  11. {
  12. }
  13. Error TextureViewImpl::init(const TextureViewInitInfo& inf)
  14. {
  15. ANKI_ASSERT(inf.isValid());
  16. // Store some stuff
  17. m_subresource = inf;
  18. m_tex = inf.m_texture;
  19. const TextureImpl& tex = static_cast<const TextureImpl&>(*m_tex);
  20. ANKI_ASSERT(tex.isSubresourceValid(inf));
  21. // Ask the texture for a view
  22. m_microImageView = &tex.getOrCreateView(inf);
  23. m_handle = m_microImageView->m_handle;
  24. m_texType = m_microImageView->m_derivedTextureType;
  25. // Create the hash
  26. Array<U64, 2> toHash = {tex.getUuid(), ptrToNumber(m_handle)};
  27. m_hash = computeHash(&toHash[0], sizeof(toHash));
  28. return Error::NONE;
  29. }
  30. U32 TextureViewImpl::getOrCreateBindlessIndex(VkImageLayout layout, DescriptorType resourceType)
  31. {
  32. ANKI_ASSERT(layout == VK_IMAGE_LAYOUT_GENERAL || layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
  33. ANKI_ASSERT(resourceType == DescriptorType::TEXTURE || resourceType == DescriptorType::IMAGE);
  34. if(resourceType == DescriptorType::IMAGE)
  35. {
  36. ANKI_ASSERT(layout == VK_IMAGE_LAYOUT_GENERAL);
  37. }
  38. else
  39. {
  40. ANKI_ASSERT(layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
  41. }
  42. ANKI_ASSERT(m_microImageView);
  43. const U32 arrayIdx = (resourceType == DescriptorType::IMAGE) ? 1 : 0;
  44. LockGuard<SpinLock> lock(m_microImageView->m_lock);
  45. U32 outIdx;
  46. if(m_microImageView->m_bindlessIndices[arrayIdx] != MAX_U32)
  47. {
  48. outIdx = m_microImageView->m_bindlessIndices[arrayIdx];
  49. }
  50. else
  51. {
  52. // Needs binding to the bindless descriptor set
  53. if(resourceType == DescriptorType::TEXTURE)
  54. {
  55. outIdx = getGrManagerImpl().getDescriptorSetFactory().bindBindlessTexture(m_handle, layout);
  56. }
  57. else
  58. {
  59. outIdx = getGrManagerImpl().getDescriptorSetFactory().bindBindlessImage(m_handle);
  60. }
  61. m_microImageView->m_bindlessIndices[arrayIdx] = outIdx;
  62. }
  63. return outIdx;
  64. }
  65. } // end namespace anki