TextureViewImpl.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. {
  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->getHandle();
  24. m_texType = m_microImageView->getDerivedTextureType();
  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)
  31. {
  32. const U32 arrayIdx = (layout == VK_IMAGE_LAYOUT_GENERAL) ? 1 : 0;
  33. U32& bindlessIdx = m_bindlessIndices[arrayIdx];
  34. if(bindlessIdx == MAX_U32)
  35. {
  36. bindlessIdx = m_microImageView->getOrCreateBindlessIndex(layout, getGrManagerImpl());
  37. }
  38. return bindlessIdx;
  39. }
  40. } // end namespace anki