From f839f1944e5a64caac97be7fea5c3fcfebb6d3fe Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 19 Feb 2017 23:07:00 +0100 Subject: [PATCH] Work towards unifying ApplyTexture --- GPU/Common/TextureCacheCommon.h | 2 ++ GPU/D3D11/TextureCacheD3D11.cpp | 14 +++++++++----- GPU/D3D11/TextureCacheD3D11.h | 1 + GPU/Directx9/TextureCacheDX9.cpp | 14 +++++++++----- GPU/Directx9/TextureCacheDX9.h | 1 + GPU/GLES/TextureCacheGLES.cpp | 12 ++++++++---- GPU/GLES/TextureCacheGLES.h | 1 + GPU/Vulkan/DrawEngineVulkan.cpp | 4 ++-- GPU/Vulkan/TextureCacheVulkan.cpp | 14 +++++++++----- GPU/Vulkan/TextureCacheVulkan.h | 9 +++++---- 10 files changed, 47 insertions(+), 25 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 60242b251f..2fe2e9cfda 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -179,6 +179,7 @@ public: void Invalidate(u32 addr, int size, GPUInvalidationType type); void InvalidateAll(GPUInvalidationType type); void ClearNextFrame(); + virtual void ForgetLastTexture() = 0; virtual void Clear(bool delete_them); @@ -198,6 +199,7 @@ public: } protected: + virtual void BindTexture(TexCacheEntry *entry) = 0; virtual void Unbind() = 0; virtual void ReleaseTexture(TexCacheEntry *entry) = 0; void DeleteTexture(TexCache::iterator it); diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index d2fee8f3ff..c669b42d7e 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -312,6 +312,14 @@ void TextureCacheD3D11::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBa clutLastFormat_ = gstate.clutformat; } +void TextureCacheD3D11::BindTexture(TexCacheEntry *entry) { + ID3D11ShaderResourceView *textureView = DxView(entry); + if (textureView != lastBoundTexture) { + context_->PSSetShaderResources(0, 1, &textureView); + lastBoundTexture = textureView; + } +} + void TextureCacheD3D11::Unbind() { ID3D11ShaderResourceView *nullView = nullptr; context_->PSSetShaderResources(0, 1, &nullView); @@ -363,11 +371,7 @@ void TextureCacheD3D11::ApplyTexture() { if (entry->framebuffer) { ApplyTextureFramebuffer(entry, entry->framebuffer); } else { - ID3D11ShaderResourceView *textureView = DxView(entry); - if (textureView != lastBoundTexture) { - context_->PSSetShaderResources(0, 1, &textureView); - lastBoundTexture = textureView; - } + BindTexture(entry); SamplerCacheKey key; UpdateSamplingParams(*entry, key); ID3D11SamplerState *state = samplerCache_.GetOrCreateSampler(device_, key); diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index df63052820..824fafe657 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -68,6 +68,7 @@ public: void ApplyTexture(); protected: + void BindTexture(TexCacheEntry *entry) override; void Unbind() override; void ReleaseTexture(TexCacheEntry *entry) override; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index d1deefb5d6..572425f8f7 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -332,6 +332,14 @@ void TextureCacheDX9::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase clutLastFormat_ = gstate.clutformat; } +void TextureCacheDX9::BindTexture(TexCacheEntry *entry) { + LPDIRECT3DTEXTURE9 texture = DxTex(entry); + if (texture != lastBoundTexture) { + pD3Ddevice->SetTexture(0, texture); + lastBoundTexture = texture; + } +} + void TextureCacheDX9::Unbind() { pD3Ddevice->SetTexture(0, NULL); } @@ -382,11 +390,7 @@ void TextureCacheDX9::ApplyTexture() { if (entry->framebuffer) { ApplyTextureFramebuffer(entry, entry->framebuffer); } else { - LPDIRECT3DTEXTURE9 texture = DxTex(entry); - if (texture != lastBoundTexture) { - pD3Ddevice->SetTexture(0, texture); - lastBoundTexture = texture; - } + BindTexture(entry); UpdateSamplingParams(*entry, false); gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL; diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index 4edae8f3d5..dc3ef86183 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -61,6 +61,7 @@ public: void ApplyTexture(); protected: + void BindTexture(TexCacheEntry *entry) override; void Unbind() override; void ReleaseTexture(TexCacheEntry *entry) override; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 97cc9282a7..c79401742c 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -385,6 +385,13 @@ bool SetDebugTexture() { } #endif +void TextureCacheGLES::BindTexture(TexCacheEntry *entry) { + if (entry->textureName != lastBoundTexture) { + glBindTexture(GL_TEXTURE_2D, entry->textureName); + lastBoundTexture = entry->textureName; + } +} + void TextureCacheGLES::Unbind() { glBindTexture(GL_TEXTURE_2D, 0); } @@ -434,10 +441,7 @@ void TextureCacheGLES::ApplyTexture() { if (entry->framebuffer) { ApplyTextureFramebuffer(entry, entry->framebuffer); } else { - if (entry->textureName != lastBoundTexture) { - glBindTexture(GL_TEXTURE_2D, entry->textureName); - lastBoundTexture = entry->textureName; - } + BindTexture(entry); UpdateSamplingParams(*entry, false); gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL; diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index 06111ca3b8..4993322f98 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -77,6 +77,7 @@ public: void ApplyTexture(); protected: + void BindTexture(TexCacheEntry *entry) override; void Unbind() override; void ReleaseTexture(TexCacheEntry *entry) override; diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index b6f445a95c..4db14a367c 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -668,7 +668,7 @@ void DrawEngineVulkan::DoFlush(VkCommandBuffer cmd) { } if (textureNeedsApply) { - textureCache_->ApplyTexture(frame->pushUBO, imageView, sampler); + textureCache_->ApplyTexture(imageView, sampler); if (imageView == VK_NULL_HANDLE) imageView = nullTexture_->GetImageView(); if (sampler == VK_NULL_HANDLE) @@ -768,7 +768,7 @@ void DrawEngineVulkan::DoFlush(VkCommandBuffer cmd) { // to use a "pre-clear" render pass, for high efficiency on tilers. if (result.action == SW_DRAW_PRIMITIVES) { if (textureNeedsApply) { - textureCache_->ApplyTexture(frame->pushUBO, imageView, sampler); + textureCache_->ApplyTexture(imageView, sampler); if (imageView == VK_NULL_HANDLE) imageView = nullTexture_->GetImageView(); if (sampler == VK_NULL_HANDLE) diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index d992c479a9..4c6e0138fe 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -397,10 +397,14 @@ void TextureCacheVulkan::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutB clutLastFormat_ = gstate.clutformat; } +void TextureCacheVulkan::BindTexture(TexCacheEntry *entry) { + +} + void TextureCacheVulkan::Unbind() { } -void TextureCacheVulkan::ApplyTexture(VulkanPushBuffer *uploadBuffer, VkImageView &imageView, VkSampler &sampler) { +void TextureCacheVulkan::ApplyTexture(VkImageView &imageView, VkSampler &sampler) { TexCacheEntry *entry = nextTexture_; if (entry == nullptr) { imageView = VK_NULL_HANDLE; @@ -440,7 +444,7 @@ void TextureCacheVulkan::ApplyTexture(VulkanPushBuffer *uploadBuffer, VkImageVie // Okay, now actually rebuild the texture if needed. if (nextNeedsRebuild_) { - BuildTexture(entry, uploadBuffer); + BuildTexture(entry); } entry->lastFrame = gpuStats.numFlips; @@ -538,7 +542,7 @@ void TextureCacheVulkan::ApplyTextureFramebuffer(VkCommandBuffer cmd, TexCacheEn uv[3] = UV(uvleft, uvtop); } - shaderManager_->DirtyLastShader(); + shaderManagerVulkan_->DirtyLastShader(); //depalFBO->EndPass(cmd); //depalFBO->TransitionToTexture(cmd); @@ -901,7 +905,7 @@ bool TextureCacheVulkan::HandleTextureChange(TexCacheEntry *const entry, const c return false; } -void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry, VulkanPushBuffer *uploadBuffer) { +void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { entry->status &= ~TexCacheEntry::STATUS_ALPHA_MASK; // For the estimate, we assume cluts always point to 8888 for simplicity. @@ -1079,7 +1083,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry, VulkanPushBuff int size = stride * mipHeight; uint32_t bufferOffset; VkBuffer texBuf; - void *data = uploadBuffer->Push(size, &bufferOffset, &texBuf); + void *data = drawEngine_->GetPushBufferForTextureData()->Push(size, &bufferOffset, &texBuf); if (replaced.Valid()) { replaced.Load(i, data, stride); } else { diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index a85034618e..c7163516f2 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -79,7 +79,7 @@ public: depalShaderCache_ = dpCache; } void SetShaderManager(ShaderManagerVulkan *sm) { - shaderManager_ = sm; + shaderManagerVulkan_ = sm; } void SetDrawEngine(DrawEngineVulkan *td) { drawEngine_ = td; @@ -90,9 +90,10 @@ public: gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } - void ApplyTexture(VulkanPushBuffer *uploadBuffer, VkImageView &imageView, VkSampler &sampler); + void ApplyTexture(VkImageView &imageView, VkSampler &sampler); protected: + void BindTexture(TexCacheEntry *entry) override; void Unbind() override; void ReleaseTexture(TexCacheEntry *entry) override; @@ -109,7 +110,7 @@ private: bool CheckFullHash(TexCacheEntry *const entry, bool &doDelete); bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete); - void BuildTexture(TexCacheEntry *const entry, VulkanPushBuffer *uploadBuffer); + void BuildTexture(TexCacheEntry *const entry); VulkanContext *vulkan_; VulkanDeviceAllocator *allocator_; @@ -126,7 +127,7 @@ private: FramebufferManagerVulkan *framebufferManagerVulkan_; DepalShaderCacheVulkan *depalShaderCache_; - ShaderManagerVulkan *shaderManager_; + ShaderManagerVulkan *shaderManagerVulkan_; DrawEngineVulkan *drawEngine_; };