GPUDevice: Move size-matches check into ResizeTexture()

This commit is contained in:
Stenzek 2025-01-07 19:05:45 +10:00
parent b9186139d0
commit 4c801c3ff3
No known key found for this signature in database
3 changed files with 30 additions and 50 deletions

View File

@ -1031,19 +1031,14 @@ bool GPUBackend::Deinterlace(u32 field)
const u32 height = m_display_texture_view_height;
const auto copy_to_field_buffer = [&](u32 buffer) {
if (!m_deinterlace_buffers[buffer] || m_deinterlace_buffers[buffer]->GetWidth() != width ||
m_deinterlace_buffers[buffer]->GetHeight() != height ||
m_deinterlace_buffers[buffer]->GetFormat() != src->GetFormat())
if (!g_gpu_device->ResizeTexture(&m_deinterlace_buffers[buffer], width, height, GPUTexture::Type::Texture,
src->GetFormat(), GPUTexture::Flags::None, false)) [[unlikely]]
{
if (!g_gpu_device->ResizeTexture(&m_deinterlace_buffers[buffer], width, height, GPUTexture::Type::Texture,
src->GetFormat(), GPUTexture::Flags::None, false)) [[unlikely]]
{
return false;
}
GL_OBJECT_NAME_FMT(m_deinterlace_buffers[buffer], "Blend Deinterlace Buffer {}", buffer);
return false;
}
GL_OBJECT_NAME_FMT(m_deinterlace_buffers[buffer], "Blend Deinterlace Buffer {}", buffer);
GL_INS_FMT("Copy {}x{} from {},{} to field buffer {}", width, height, x, y, buffer);
g_gpu_device->CopyTextureRegion(m_deinterlace_buffers[buffer].get(), 0, 0, 0, 0, m_display_texture, x, y, 0, 0,
width, height);
@ -1158,18 +1153,13 @@ bool GPUBackend::Deinterlace(u32 field)
bool GPUBackend::DeinterlaceSetTargetSize(u32 width, u32 height, bool preserve)
{
if (!m_deinterlace_texture || m_deinterlace_texture->GetWidth() != width ||
m_deinterlace_texture->GetHeight() != height)
if (!g_gpu_device->ResizeTexture(&m_deinterlace_texture, width, height, GPUTexture::Type::RenderTarget,
GPUTexture::Format::RGBA8, GPUTexture::Flags::None, preserve)) [[unlikely]]
{
if (!g_gpu_device->ResizeTexture(&m_deinterlace_texture, width, height, GPUTexture::Type::RenderTarget,
GPUTexture::Format::RGBA8, GPUTexture::Flags::None, preserve)) [[unlikely]]
{
return false;
}
GL_OBJECT_NAME(m_deinterlace_texture, "Deinterlace target texture");
return false;
}
GL_OBJECT_NAME(m_deinterlace_texture, "Deinterlace target texture");
return true;
}
@ -1179,19 +1169,15 @@ bool GPUBackend::ApplyChromaSmoothing()
const u32 y = m_display_texture_view_y;
const u32 width = m_display_texture_view_width;
const u32 height = m_display_texture_view_height;
if (!m_chroma_smoothing_texture || m_chroma_smoothing_texture->GetWidth() != width ||
m_chroma_smoothing_texture->GetHeight() != height)
if (!g_gpu_device->ResizeTexture(&m_chroma_smoothing_texture, width, height, GPUTexture::Type::RenderTarget,
GPUTexture::Format::RGBA8, GPUTexture::Flags::None, false))
{
if (!g_gpu_device->ResizeTexture(&m_chroma_smoothing_texture, width, height, GPUTexture::Type::RenderTarget,
GPUTexture::Format::RGBA8, GPUTexture::Flags::None, false))
{
ClearDisplayTexture();
return false;
}
GL_OBJECT_NAME(m_chroma_smoothing_texture, "Chroma smoothing texture");
ClearDisplayTexture();
return false;
}
GL_OBJECT_NAME(m_chroma_smoothing_texture, "Chroma smoothing texture");
GL_SCOPE_FMT("ApplyChromaSmoothing({{{},{}}}, {}x{})", x, y, width, height);
m_display_texture->MakeReadyForSampling();

View File

@ -3896,26 +3896,20 @@ void GPU_HW::UpdateDisplay(const GPUBackendUpdateDisplayCommand* cmd)
}
else
{
if (!m_vram_extract_texture || m_vram_extract_texture->GetWidth() != scaled_display_width ||
m_vram_extract_texture->GetHeight() != scaled_display_height)
if (!g_gpu_device->ResizeTexture(&m_vram_extract_texture, scaled_display_width, scaled_display_height,
GPUTexture::Type::RenderTarget, GPUTexture::Format::RGBA8,
GPUTexture::Flags::None)) [[unlikely]]
{
if (!g_gpu_device->ResizeTexture(&m_vram_extract_texture, scaled_display_width, scaled_display_height,
GPUTexture::Type::RenderTarget, GPUTexture::Format::RGBA8,
GPUTexture::Flags::None)) [[unlikely]]
{
ClearDisplayTexture();
return;
}
ClearDisplayTexture();
return;
}
m_vram_texture->MakeReadyForSampling();
g_gpu_device->InvalidateRenderTarget(m_vram_extract_texture.get());
if (depth_source &&
((m_vram_extract_depth_texture && m_vram_extract_depth_texture->GetWidth() == scaled_display_width &&
m_vram_extract_depth_texture->GetHeight() == scaled_display_height) ||
!g_gpu_device->ResizeTexture(&m_vram_extract_depth_texture, scaled_display_width, scaled_display_height,
GPUTexture::Type::RenderTarget, VRAM_DS_COLOR_FORMAT, GPUTexture::Flags::None)))
g_gpu_device->ResizeTexture(&m_vram_extract_depth_texture, scaled_display_width, scaled_display_height,
GPUTexture::Type::RenderTarget, VRAM_DS_COLOR_FORMAT, GPUTexture::Flags::None))
{
depth_source->MakeReadyForSampling();
g_gpu_device->InvalidateRenderTarget(m_vram_extract_depth_texture.get());
@ -4166,14 +4160,8 @@ void GPU_HW::DownsampleFramebufferBoxFilter(GPUTexture* source, u32 left, u32 to
const u32 ds_width = width / m_downsample_scale_or_levels;
const u32 ds_height = height / m_downsample_scale_or_levels;
if (!m_downsample_texture || m_downsample_texture->GetWidth() != ds_width ||
m_downsample_texture->GetHeight() != ds_height)
{
g_gpu_device->RecycleTexture(std::move(m_downsample_texture));
m_downsample_texture = g_gpu_device->FetchTexture(ds_width, ds_height, 1, 1, 1, GPUTexture::Type::RenderTarget,
VRAM_RT_FORMAT, GPUTexture::Flags::None);
}
if (!m_downsample_texture)
if (!g_gpu_device->ResizeTexture(&m_downsample_texture, ds_width, ds_height, GPUTexture::Type::RenderTarget,
VRAM_RT_FORMAT, GPUTexture::Flags::None, false))
{
ERROR_LOG("Failed to create {}x{} RT for box downsampling", width, height);
return;

View File

@ -1222,6 +1222,12 @@ bool GPUDevice::ResizeTexture(std::unique_ptr<GPUTexture>* tex, u32 new_width, u
GPUTexture::Format format, GPUTexture::Flags flags, bool preserve /* = true */)
{
GPUTexture* old_tex = tex->get();
if (old_tex && old_tex->GetWidth() == new_width && old_tex->GetHeight() == new_height && old_tex->GetType() == type &&
old_tex->GetFormat() == format && old_tex->GetFlags() == flags)
{
return true;
}
DebugAssert(!old_tex || (old_tex->GetLayers() == 1 && old_tex->GetLevels() == 1 && old_tex->GetSamples() == 1));
std::unique_ptr<GPUTexture> new_tex = FetchTexture(new_width, new_height, 1, 1, 1, type, format, flags);
if (!new_tex) [[unlikely]]