StreamingImageContext.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/RPI.Public/Image/StreamingImageContext.h>
  9. #include <Atom/RPI.Public/Image/StreamingImageController.h>
  10. namespace AZ
  11. {
  12. namespace RPI
  13. {
  14. StreamingImage* StreamingImageContext::TryGetImage() const
  15. {
  16. return m_streamingImage;
  17. }
  18. uint16_t StreamingImageContext::GetTargetMip() const
  19. {
  20. return m_mipLevelTarget;
  21. }
  22. size_t StreamingImageContext::GetLastAccessTimestamp() const
  23. {
  24. return m_lastAccessTimestamp;
  25. }
  26. void StreamingImageContext::UpdateMipStats()
  27. {
  28. m_mipLevelTargetAdjusted = m_streamingImage->m_streamingController->GetImageTargetMip(m_streamingImage);
  29. m_residentMip = m_streamingImage->GetResidentMipLevel();
  30. if (m_residentMip > m_mipLevelTargetAdjusted)
  31. {
  32. m_missingMips = m_residentMip - m_mipLevelTargetAdjusted;
  33. }
  34. else
  35. {
  36. m_missingMips = 0;
  37. }
  38. const size_t mipChainTailIndex = m_streamingImage->m_imageAsset->GetMipChainCount() - 1;
  39. size_t tailMip = m_streamingImage->m_imageAsset->GetMipLevel(mipChainTailIndex);
  40. if (tailMip > m_residentMip)
  41. {
  42. m_evictableMips = aznumeric_cast<uint16_t>(tailMip) - m_residentMip;
  43. }
  44. else
  45. {
  46. m_evictableMips = 0;
  47. }
  48. // get the length of the resident mip
  49. RHI::Size mipSize = m_streamingImage->m_imageAsset->GetImageDescriptor().m_size.GetReducedMip(aznumeric_cast<uint32_t>(m_residentMip));
  50. m_residentMipSize = mipSize.m_width > mipSize.m_height? mipSize.m_width : mipSize.m_height;
  51. }
  52. }
  53. }