mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-22 17:31:52 +01:00
Delete expired weak_ptr
s for Texture/Buffer views
A large amount of Texture/Buffer views would expire before reuse could occur in `Texture::GetView`/`Buffer::GetView`. These can lead to a substantial memory allocation given enough time and they are now deleted during the lookup while iterating on all entries. It should be noted that there are a lot of duplicate views that don't live long enough to be reused and the ultimate solution here is to make those views live long enough to be reused.
This commit is contained in:
parent
881bb969c4
commit
77e2797219
@ -172,10 +172,14 @@ namespace skyline::gpu {
|
||||
}
|
||||
|
||||
std::shared_ptr<BufferView> Buffer::GetView(vk::DeviceSize offset, vk::DeviceSize range, vk::Format format) {
|
||||
for (const auto &viewWeak : views) {
|
||||
auto view{viewWeak.lock()};
|
||||
for (auto viewIt{views.begin()}; viewIt != views.end();) {
|
||||
auto view{viewIt->lock()};
|
||||
if (view && view->offset == offset && view->range == range && view->format == format)
|
||||
return view;
|
||||
else if (!view)
|
||||
viewIt = views.erase(viewIt);
|
||||
else
|
||||
++viewIt;
|
||||
}
|
||||
|
||||
auto view{std::make_shared<BufferView>(shared_from_this(), offset, range, format)};
|
||||
|
@ -515,10 +515,14 @@ namespace skyline::gpu {
|
||||
}
|
||||
|
||||
std::shared_ptr<TextureView> Texture::GetView(vk::ImageViewType type, vk::ImageSubresourceRange range, texture::Format pFormat, vk::ComponentMapping mapping) {
|
||||
for (const auto &viewWeak : views) {
|
||||
auto view{viewWeak.lock()};
|
||||
for (auto viewIt{views.begin()}; viewIt != views.end();) {
|
||||
auto view{viewIt->lock()};
|
||||
if (view && type == view->type && pFormat == view->format && range == view->range && mapping == view->mapping)
|
||||
return view;
|
||||
else if (!view)
|
||||
viewIt = views.erase(viewIt);
|
||||
else
|
||||
++viewIt;
|
||||
}
|
||||
|
||||
auto view{std::make_shared<TextureView>(shared_from_this(), type, range, pFormat, mapping)};
|
||||
|
Loading…
Reference in New Issue
Block a user