diff --git a/src/util/d3d11_device.cpp b/src/util/d3d11_device.cpp index a4eaaa329..b567f888a 100644 --- a/src/util/d3d11_device.cpp +++ b/src/util/d3d11_device.cpp @@ -940,7 +940,17 @@ void D3D11Device::SetRenderTargets(GPUTexture* const* rts, u32 num_rts, GPUTextu void D3D11Device::SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* sampler) { - ID3D11ShaderResourceView* T = texture ? static_cast(texture)->GetD3DSRV() : nullptr; + ID3D11ShaderResourceView* T; + if (texture) + { + static_cast(texture)->CommitClear(m_context.Get()); + T = static_cast(texture)->GetD3DSRV(); + } + else + { + T = nullptr; + } + ID3D11SamplerState* S = sampler ? static_cast(sampler)->GetSamplerState() : nullptr; // Runtime will null these if we don't... diff --git a/src/util/d3d12_device.cpp b/src/util/d3d12_device.cpp index ad59933fa..fbbfe2698 100644 --- a/src/util/d3d12_device.cpp +++ b/src/util/d3d12_device.cpp @@ -1864,6 +1864,7 @@ void D3D12Device::SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* s if (T) { + T->CommitClear(); T->SetUseFenceValue(GetCurrentFenceValue()); if (T->GetResourceState() != D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE) { diff --git a/src/util/metal_device.mm b/src/util/metal_device.mm index 2394a6188..7e87d8c29 100644 --- a/src/util/metal_device.mm +++ b/src/util/metal_device.mm @@ -1408,13 +1408,12 @@ void MetalDevice::InvalidateRenderTarget(GPUTexture* t) void MetalDevice::CommitClear(MetalTexture* tex) { - if (tex->GetState() == GPUTexture::State::Dirty) - return; - DebugAssert(tex->IsRenderTargetOrDepthStencil()); if (tex->GetState() == GPUTexture::State::Cleared) { + tex->SetState(GPUTexture::State::Dirty); + // TODO: We could combine it with the current render pass. if (InRenderPass()) EndRenderPass(); @@ -1655,7 +1654,10 @@ void MetalDevice::SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* s id T = texture ? static_cast(texture)->GetMTLTexture() : nil; if (texture) + { + CommitClear(static_cast(texture)); static_cast(texture)->SetUseFenceCounter(m_current_fence_counter); + } if (m_current_textures[slot] != T) { diff --git a/src/util/opengl_device.cpp b/src/util/opengl_device.cpp index 1fd9eb380..d5c224513 100644 --- a/src/util/opengl_device.cpp +++ b/src/util/opengl_device.cpp @@ -1130,8 +1130,18 @@ void OpenGLDevice::SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* DebugAssert(slot < MAX_TEXTURE_SAMPLERS); auto& sslot = m_last_samplers[slot]; - const OpenGLTexture* T = static_cast(texture); - const GLuint Tid = T ? T->GetGLId() : 0; + OpenGLTexture* T = static_cast(texture); + GLuint Tid; + if (T) + { + Tid = T->GetGLId(); + CommitClear(T); + } + else + { + Tid = 0; + } + if (sslot.first != Tid) { sslot.first = Tid; diff --git a/src/util/vulkan_device.cpp b/src/util/vulkan_device.cpp index 4afd95abd..7cb7f4f48 100644 --- a/src/util/vulkan_device.cpp +++ b/src/util/vulkan_device.cpp @@ -3250,6 +3250,7 @@ void VulkanDevice::SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* if (T) { + T->CommitClear(); T->SetUseFenceCounter(GetCurrentFenceCounter()); if (T->GetLayout() != VulkanTexture::Layout::ShaderReadOnly) {