TextureViewImpl.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/TextureViewImpl.h>
  6. #include <AnKi/Gr/Vulkan/TextureImpl.h>
  7. #include <AnKi/Gr/Vulkan/GrManagerImpl.h>
  8. namespace anki {
  9. TextureViewImpl::~TextureViewImpl()
  10. {
  11. }
  12. Error TextureViewImpl::init(const TextureViewInitInfo& inf)
  13. {
  14. ANKI_ASSERT(inf.isValid());
  15. // Store some stuff
  16. m_subresource = inf;
  17. m_tex = inf.m_texture;
  18. const TextureImpl& tex = static_cast<const TextureImpl&>(*m_tex);
  19. ANKI_ASSERT(tex.isSubresourceValid(inf));
  20. // Ask the texture for a view
  21. m_microImageView = &tex.getOrCreateView(inf);
  22. m_handle = m_microImageView->getHandle();
  23. m_texType = m_microImageView->getDerivedTextureType();
  24. // Create the hash
  25. Array<U64, 2> toHash = {tex.getUuid(), ptrToNumber(m_handle)};
  26. m_hash = computeHash(&toHash[0], sizeof(toHash));
  27. return Error::NONE;
  28. }
  29. U32 TextureViewImpl::getOrCreateBindlessIndex(VkImageLayout layout)
  30. {
  31. const U32 arrayIdx = (layout == VK_IMAGE_LAYOUT_GENERAL) ? 1 : 0;
  32. U32& bindlessIdx = m_bindlessIndices[arrayIdx];
  33. if(bindlessIdx == MAX_U32)
  34. {
  35. bindlessIdx = m_microImageView->getOrCreateBindlessIndex(layout, getGrManagerImpl());
  36. }
  37. return bindlessIdx;
  38. }
  39. } // end namespace anki