Work towards unifying ApplyTexture

This commit is contained in:
Henrik Rydgard 2017-02-19 23:07:00 +01:00
parent 665ffe34ab
commit f839f1944e
10 changed files with 47 additions and 25 deletions

View file

@ -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);

View file

@ -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);

View file

@ -68,6 +68,7 @@ public:
void ApplyTexture();
protected:
void BindTexture(TexCacheEntry *entry) override;
void Unbind() override;
void ReleaseTexture(TexCacheEntry *entry) override;

View file

@ -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;

View file

@ -61,6 +61,7 @@ public:
void ApplyTexture();
protected:
void BindTexture(TexCacheEntry *entry) override;
void Unbind() override;
void ReleaseTexture(TexCacheEntry *entry) override;

View file

@ -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;

View file

@ -77,6 +77,7 @@ public:
void ApplyTexture();
protected:
void BindTexture(TexCacheEntry *entry) override;
void Unbind() override;
void ReleaseTexture(TexCacheEntry *entry) override;

View file

@ -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)

View file

@ -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 {

View file

@ -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_;
};