GPUDevice: Pool textures
This commit is contained in:
@@ -257,7 +257,6 @@ static std::shared_ptr<GPUTexture> s_fallback_disc_texture;
|
||||
static std::shared_ptr<GPUTexture> s_fallback_exe_texture;
|
||||
static std::shared_ptr<GPUTexture> s_fallback_psf_texture;
|
||||
static std::shared_ptr<GPUTexture> s_fallback_playlist_texture;
|
||||
static std::vector<std::unique_ptr<GPUTexture>> s_cleanup_textures;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Landing
|
||||
@@ -745,9 +744,6 @@ void FullscreenUI::Render()
|
||||
if (!s_initialized)
|
||||
return;
|
||||
|
||||
for (std::unique_ptr<GPUTexture>& tex : s_cleanup_textures)
|
||||
tex.reset();
|
||||
s_cleanup_textures.clear();
|
||||
ImGuiFullscreen::UploadAsyncTextures();
|
||||
|
||||
ImGuiFullscreen::BeginLayout();
|
||||
@@ -867,8 +863,6 @@ void FullscreenUI::DestroyResources()
|
||||
s_fallback_disc_texture.reset();
|
||||
for (auto& tex : s_game_compatibility_textures)
|
||||
tex.reset();
|
||||
for (auto& tex : s_cleanup_textures)
|
||||
tex.reset();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -5089,16 +5083,15 @@ void FullscreenUI::PopulateSaveStateScreenshot(SaveStateListEntry* li, const Ext
|
||||
li->preview_texture.reset();
|
||||
if (ssi && !ssi->screenshot_data.empty())
|
||||
{
|
||||
li->preview_texture = g_gpu_device->CreateTexture(
|
||||
li->preview_texture = g_gpu_device->FetchTexture(
|
||||
ssi->screenshot_width, ssi->screenshot_height, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
|
||||
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width, false);
|
||||
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width);
|
||||
}
|
||||
else
|
||||
{
|
||||
li->preview_texture = g_gpu_device->CreateTexture(
|
||||
li->preview_texture = g_gpu_device->FetchTexture(
|
||||
Resources::PLACEHOLDER_ICON_WIDTH, Resources::PLACEHOLDER_ICON_HEIGHT, 1, 1, 1, GPUTexture::Type::Texture,
|
||||
GPUTexture::Format::RGBA8, Resources::PLACEHOLDER_ICON_DATA, sizeof(u32) * Resources::PLACEHOLDER_ICON_WIDTH,
|
||||
false);
|
||||
GPUTexture::Format::RGBA8, Resources::PLACEHOLDER_ICON_DATA, sizeof(u32) * Resources::PLACEHOLDER_ICON_WIDTH);
|
||||
}
|
||||
|
||||
if (!li->preview_texture)
|
||||
@@ -5110,7 +5103,7 @@ void FullscreenUI::ClearSaveStateEntryList()
|
||||
for (SaveStateListEntry& entry : s_save_state_selector_slots)
|
||||
{
|
||||
if (entry.preview_texture)
|
||||
s_cleanup_textures.push_back(std::move(entry.preview_texture));
|
||||
g_gpu_device->RecycleTexture(std::move(entry.preview_texture));
|
||||
}
|
||||
s_save_state_selector_slots.clear();
|
||||
}
|
||||
|
||||
+2
-2
@@ -2054,8 +2054,8 @@ bool GPU::RenderScreenshotToBuffer(u32 width, u32 height, const Common::Rectangl
|
||||
const GPUTexture::Format hdformat =
|
||||
g_gpu_device->HasSurface() ? g_gpu_device->GetWindowFormat() : GPUTexture::Format::RGBA8;
|
||||
|
||||
std::unique_ptr<GPUTexture> render_texture =
|
||||
g_gpu_device->CreateTexture(width, height, 1, 1, 1, GPUTexture::Type::RenderTarget, hdformat);
|
||||
auto render_texture =
|
||||
g_gpu_device->FetchAutoRecycleTexture(width, height, 1, 1, 1, GPUTexture::Type::RenderTarget, hdformat);
|
||||
if (!render_texture)
|
||||
return false;
|
||||
|
||||
|
||||
+29
-29
@@ -290,8 +290,8 @@ bool GPU_HW::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_di
|
||||
|
||||
tex =
|
||||
g_gpu_device
|
||||
->CreateTexture(m_vram_texture->GetWidth(), m_vram_texture->GetHeight(), 1, 1, m_vram_texture->GetSamples(),
|
||||
GPUTexture::Type::RenderTarget, GPUTexture::Format::RGBA8, nullptr, 0, false)
|
||||
->FetchTexture(m_vram_texture->GetWidth(), m_vram_texture->GetHeight(), 1, 1, m_vram_texture->GetSamples(),
|
||||
GPUTexture::Type::RenderTarget, GPUTexture::Format::RGBA8, nullptr, 0)
|
||||
.release();
|
||||
*host_texture = tex;
|
||||
if (!tex)
|
||||
@@ -627,18 +627,18 @@ bool GPU_HW::CreateBuffers()
|
||||
GPUTexture::Type::RWTexture :
|
||||
GPUTexture::Type::Texture;
|
||||
|
||||
if (!(m_vram_texture = g_gpu_device->CreateTexture(texture_width, texture_height, 1, 1, samples,
|
||||
GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)) ||
|
||||
!(m_vram_depth_texture = g_gpu_device->CreateTexture(texture_width, texture_height, 1, 1, samples,
|
||||
GPUTexture::Type::DepthStencil, VRAM_DS_FORMAT)) ||
|
||||
if (!(m_vram_texture = g_gpu_device->FetchTexture(texture_width, texture_height, 1, 1, samples,
|
||||
GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)) ||
|
||||
!(m_vram_depth_texture = g_gpu_device->FetchTexture(texture_width, texture_height, 1, 1, samples,
|
||||
GPUTexture::Type::DepthStencil, VRAM_DS_FORMAT)) ||
|
||||
!(m_vram_read_texture =
|
||||
g_gpu_device->CreateTexture(texture_width, texture_height, 1, 1, 1, read_texture_type, VRAM_RT_FORMAT)) ||
|
||||
!(m_display_private_texture = g_gpu_device->CreateTexture(
|
||||
g_gpu_device->FetchTexture(texture_width, texture_height, 1, 1, 1, read_texture_type, VRAM_RT_FORMAT)) ||
|
||||
!(m_display_private_texture = g_gpu_device->FetchTexture(
|
||||
((m_downsample_mode == GPUDownsampleMode::Adaptive) ? VRAM_WIDTH : GPU_MAX_DISPLAY_WIDTH) *
|
||||
m_resolution_scale,
|
||||
GPU_MAX_DISPLAY_HEIGHT * m_resolution_scale, 1, 1, 1, GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)) ||
|
||||
!(m_vram_readback_texture = g_gpu_device->CreateTexture(VRAM_WIDTH / 2, VRAM_HEIGHT, 1, 1, 1,
|
||||
GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)))
|
||||
!(m_vram_readback_texture = g_gpu_device->FetchTexture(VRAM_WIDTH / 2, VRAM_HEIGHT, 1, 1, 1,
|
||||
GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -661,13 +661,13 @@ bool GPU_HW::CreateBuffers()
|
||||
{
|
||||
const u32 levels = GetAdaptiveDownsamplingMipLevels();
|
||||
|
||||
if (!(m_downsample_texture = g_gpu_device->CreateTexture(texture_width, texture_height, 1, levels, 1,
|
||||
GPUTexture::Type::Texture, VRAM_RT_FORMAT)) ||
|
||||
!(m_downsample_render_texture = g_gpu_device->CreateTexture(texture_width, texture_height, 1, 1, 1,
|
||||
GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)) ||
|
||||
if (!(m_downsample_texture = g_gpu_device->FetchTexture(texture_width, texture_height, 1, levels, 1,
|
||||
GPUTexture::Type::Texture, VRAM_RT_FORMAT)) ||
|
||||
!(m_downsample_render_texture = g_gpu_device->FetchTexture(texture_width, texture_height, 1, 1, 1,
|
||||
GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)) ||
|
||||
!(m_downsample_weight_texture =
|
||||
g_gpu_device->CreateTexture(texture_width >> (levels - 1), texture_height >> (levels - 1), 1, 1, 1,
|
||||
GPUTexture::Type::RenderTarget, GPUTexture::Format::R8)))
|
||||
g_gpu_device->FetchTexture(texture_width >> (levels - 1), texture_height >> (levels - 1), 1, 1, 1,
|
||||
GPUTexture::Type::RenderTarget, GPUTexture::Format::R8)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -676,8 +676,8 @@ bool GPU_HW::CreateBuffers()
|
||||
{
|
||||
const u32 downsample_scale = GetBoxDownsampleScale(m_resolution_scale);
|
||||
if (!(m_downsample_render_texture =
|
||||
g_gpu_device->CreateTexture(VRAM_WIDTH * downsample_scale, VRAM_HEIGHT * downsample_scale, 1, 1, 1,
|
||||
GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)))
|
||||
g_gpu_device->FetchTexture(VRAM_WIDTH * downsample_scale, VRAM_HEIGHT * downsample_scale, 1, 1, 1,
|
||||
GPUTexture::Type::RenderTarget, VRAM_RT_FORMAT)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -702,14 +702,14 @@ void GPU_HW::DestroyBuffers()
|
||||
ClearDisplayTexture();
|
||||
|
||||
m_vram_upload_buffer.reset();
|
||||
m_downsample_weight_texture.reset();
|
||||
m_downsample_render_texture.reset();
|
||||
m_downsample_texture.reset();
|
||||
m_vram_read_texture.reset();
|
||||
m_vram_depth_texture.reset();
|
||||
m_vram_texture.reset();
|
||||
m_vram_readback_texture.reset();
|
||||
m_display_private_texture.reset();
|
||||
g_gpu_device->RecycleTexture(std::move(m_downsample_weight_texture));
|
||||
g_gpu_device->RecycleTexture(std::move(m_downsample_render_texture));
|
||||
g_gpu_device->RecycleTexture(std::move(m_downsample_texture));
|
||||
g_gpu_device->RecycleTexture(std::move(m_vram_read_texture));
|
||||
g_gpu_device->RecycleTexture(std::move(m_vram_depth_texture));
|
||||
g_gpu_device->RecycleTexture(std::move(m_vram_texture));
|
||||
g_gpu_device->RecycleTexture(std::move(m_vram_readback_texture));
|
||||
g_gpu_device->RecycleTexture(std::move(m_display_private_texture));
|
||||
}
|
||||
|
||||
bool GPU_HW::CompilePipelines()
|
||||
@@ -2018,11 +2018,11 @@ bool GPU_HW::BlitVRAMReplacementTexture(const TextureReplacementTexture* tex, u3
|
||||
if (!m_vram_replacement_texture || m_vram_replacement_texture->GetWidth() < tex->GetWidth() ||
|
||||
m_vram_replacement_texture->GetHeight() < tex->GetHeight())
|
||||
{
|
||||
m_vram_replacement_texture.reset();
|
||||
g_gpu_device->RecycleTexture(std::move(m_vram_replacement_texture));
|
||||
|
||||
if (!(m_vram_replacement_texture =
|
||||
g_gpu_device->CreateTexture(tex->GetWidth(), tex->GetHeight(), 1, 1, 1, GPUTexture::Type::Texture,
|
||||
GPUTexture::Format::RGBA8, tex->GetPixels(), tex->GetPitch(), true)))
|
||||
g_gpu_device->FetchTexture(tex->GetWidth(), tex->GetHeight(), 1, 1, 1, GPUTexture::Type::DynamicTexture,
|
||||
GPUTexture::Format::RGBA8, tex->GetPixels(), tex->GetPitch())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
+3
-2
@@ -31,6 +31,7 @@ GPU_SW::GPU_SW()
|
||||
|
||||
GPU_SW::~GPU_SW()
|
||||
{
|
||||
g_gpu_device->RecycleTexture(std::move(m_private_display_texture));
|
||||
m_backend.Shutdown();
|
||||
}
|
||||
|
||||
@@ -98,9 +99,9 @@ GPUTexture* GPU_SW::GetDisplayTexture(u32 width, u32 height, GPUTexture::Format
|
||||
m_private_display_texture->GetHeight() != height || m_private_display_texture->GetFormat() != format)
|
||||
{
|
||||
ClearDisplayTexture();
|
||||
m_private_display_texture.reset();
|
||||
g_gpu_device->RecycleTexture(std::move(m_private_display_texture));
|
||||
m_private_display_texture =
|
||||
g_gpu_device->CreateTexture(width, height, 1, 1, 1, GPUTexture::Type::Texture, format, nullptr, 0, true);
|
||||
g_gpu_device->FetchTexture(width, height, 1, 1, 1, GPUTexture::Type::DynamicTexture, format, nullptr, 0);
|
||||
if (!m_private_display_texture)
|
||||
Log_ErrorPrintf("Failed to create %ux%u %u texture", width, height, static_cast<u32>(format));
|
||||
}
|
||||
|
||||
+20
-11
@@ -717,7 +717,13 @@ void SaveStateSelectorUI::Close(bool reset_slot)
|
||||
|
||||
void SaveStateSelectorUI::RefreshList()
|
||||
{
|
||||
for (ListEntry& entry : s_slots)
|
||||
{
|
||||
if (entry.preview_texture)
|
||||
g_gpu_device->RecycleTexture(std::move(entry.preview_texture));
|
||||
}
|
||||
s_slots.clear();
|
||||
|
||||
if (System::IsShutdown())
|
||||
return;
|
||||
|
||||
@@ -761,7 +767,10 @@ void SaveStateSelectorUI::DestroyTextures()
|
||||
Close();
|
||||
|
||||
for (ListEntry& entry : s_slots)
|
||||
entry.preview_texture.reset();
|
||||
{
|
||||
if (entry.preview_texture)
|
||||
g_gpu_device->RecycleTexture(std::move(entry.preview_texture));
|
||||
}
|
||||
}
|
||||
|
||||
void SaveStateSelectorUI::RefreshHotkeyLegend()
|
||||
@@ -815,23 +824,22 @@ void SaveStateSelectorUI::InitializeListEntry(ListEntry* li, ExtendedSaveStateIn
|
||||
li->slot = slot;
|
||||
li->global = global;
|
||||
|
||||
li->preview_texture.reset();
|
||||
|
||||
// Might not have a display yet, we're called at startup..
|
||||
if (g_gpu_device)
|
||||
{
|
||||
g_gpu_device->RecycleTexture(std::move(li->preview_texture));
|
||||
|
||||
if (ssi && !ssi->screenshot_data.empty())
|
||||
{
|
||||
li->preview_texture = g_gpu_device->CreateTexture(
|
||||
li->preview_texture = g_gpu_device->FetchTexture(
|
||||
ssi->screenshot_width, ssi->screenshot_height, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
|
||||
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width, false);
|
||||
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width);
|
||||
}
|
||||
else
|
||||
{
|
||||
li->preview_texture = g_gpu_device->CreateTexture(
|
||||
li->preview_texture = g_gpu_device->FetchTexture(
|
||||
Resources::PLACEHOLDER_ICON_WIDTH, Resources::PLACEHOLDER_ICON_HEIGHT, 1, 1, 1, GPUTexture::Type::Texture,
|
||||
GPUTexture::Format::RGBA8, Resources::PLACEHOLDER_ICON_DATA, sizeof(u32) * Resources::PLACEHOLDER_ICON_WIDTH,
|
||||
false);
|
||||
GPUTexture::Format::RGBA8, Resources::PLACEHOLDER_ICON_DATA, sizeof(u32) * Resources::PLACEHOLDER_ICON_WIDTH);
|
||||
}
|
||||
|
||||
if (!li->preview_texture)
|
||||
@@ -850,10 +858,11 @@ void SaveStateSelectorUI::InitializePlaceholderListEntry(ListEntry* li, std::str
|
||||
|
||||
if (g_gpu_device)
|
||||
{
|
||||
li->preview_texture = g_gpu_device->CreateTexture(
|
||||
g_gpu_device->RecycleTexture(std::move(li->preview_texture));
|
||||
|
||||
li->preview_texture = g_gpu_device->FetchTexture(
|
||||
Resources::PLACEHOLDER_ICON_WIDTH, Resources::PLACEHOLDER_ICON_HEIGHT, 1, 1, 1, GPUTexture::Type::Texture,
|
||||
GPUTexture::Format::RGBA8, Resources::PLACEHOLDER_ICON_DATA, sizeof(u32) * Resources::PLACEHOLDER_ICON_WIDTH,
|
||||
false);
|
||||
GPUTexture::Format::RGBA8, Resources::PLACEHOLDER_ICON_DATA, sizeof(u32) * Resources::PLACEHOLDER_ICON_WIDTH);
|
||||
if (!li->preview_texture)
|
||||
Log_ErrorPrintf("Failed to upload save state image to GPU");
|
||||
}
|
||||
|
||||
@@ -3894,6 +3894,7 @@ bool System::LoadRewindState(u32 skip_saves /*= 0*/, bool consume_state /*=true
|
||||
{
|
||||
while (skip_saves > 0 && !s_rewind_states.empty())
|
||||
{
|
||||
g_gpu_device->RecycleTexture(std::move(s_rewind_states.front().vram_texture));
|
||||
s_rewind_states.pop_back();
|
||||
skip_saves--;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user