diff --git a/src/dxvk/dxvk_image.cpp b/src/dxvk/dxvk_image.cpp index 439488ae..a703b02a 100644 --- a/src/dxvk/dxvk_image.cpp +++ b/src/dxvk/dxvk_image.cpp @@ -125,11 +125,30 @@ namespace dxvk { } + void DxvkImage::addView(DxvkImageView* view) { + m_viewList.push_back(view); + } + + + void DxvkImage::removeView(DxvkImageView* view) { + for (size_t i = 0; i < m_viewList.size(); i++) { + if (m_viewList[i] == view) { + m_viewList[i] = m_viewList.back(); + m_viewList.pop_back(); + return; + } + } + } + + DxvkImageView::DxvkImageView( const Rc& vkd, const Rc& image, const DxvkImageViewCreateInfo& info) : m_vkd(vkd), m_image(image), m_info(info) { + std::lock_guard lock(m_image->m_viewLock); + m_image->addView(this); + createViews(); } @@ -137,6 +156,9 @@ namespace dxvk { DxvkImageView::~DxvkImageView() { for (uint32_t i = 0; i < ViewCount; i++) m_vkd->vkDestroyImageView(m_vkd->device(), m_views[i], nullptr); + + std::lock_guard lock(m_image->m_viewLock); + m_image->removeView(this); } diff --git a/src/dxvk/dxvk_image.h b/src/dxvk/dxvk_image.h index 259e3381..db6dd8b9 100644 --- a/src/dxvk/dxvk_image.h +++ b/src/dxvk/dxvk_image.h @@ -7,6 +7,8 @@ #include "dxvk_util.h" namespace dxvk { + + class DxvkImageView; /** * \brief Image create info @@ -104,7 +106,7 @@ namespace dxvk { * memory type and if created with the linear tiling option. */ class DxvkImage : public DxvkResource { - + friend class DxvkImageView; public: DxvkImage( @@ -283,6 +285,12 @@ namespace dxvk { small_vector m_viewFormats; + sync::Spinlock m_viewLock; + small_vector m_viewList; + + void addView(DxvkImageView* view); + void removeView(DxvkImageView* view); + }; @@ -290,6 +298,7 @@ namespace dxvk { * \brief DXVK image view */ class DxvkImageView : public DxvkResource { + friend class DxvkImage; constexpr static uint32_t ViewCount = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY + 1; public: