Remove redundant bind on GL texture build. Improve dirtying of texture state.

This commit is contained in:
Henrik Rydgård 2020-09-20 23:22:54 +02:00
parent eaca9d1b59
commit dcd33a4692
11 changed files with 12 additions and 26 deletions

View file

@ -1644,6 +1644,7 @@ void TextureCacheCommon::ApplyTexture() {
if (nextNeedsRebuild_) { if (nextNeedsRebuild_) {
_assert_(!entry->texturePtr); _assert_(!entry->texturePtr);
BuildTexture(entry); BuildTexture(entry);
InvalidateLastTexture();
} }
entry->lastFrame = gpuStats.numFlips; entry->lastFrame = gpuStats.numFlips;

View file

@ -199,7 +199,6 @@ bool FramebufferManagerD3D11::NotifyStencilUpload(u32 addr, int size, StencilUpl
context_->IASetVertexBuffers(0, 1, &quadBuffer_, &quadStride_, &quadOffset_); context_->IASetVertexBuffers(0, 1, &quadBuffer_, &quadStride_, &quadOffset_);
context_->PSSetSamplers(0, 1, &stockD3D11.samplerPoint2DClamp); context_->PSSetSamplers(0, 1, &stockD3D11.samplerPoint2DClamp);
context_->OMSetDepthStencilState(stockD3D11.depthDisabledStencilWrite, 0xFF); context_->OMSetDepthStencilState(stockD3D11.depthDisabledStencilWrite, 0xFF);
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE);
for (int i = 1; i < values; i += i) { for (int i = 1; i < values; i += i) {
if (!(usedBits & i)) { if (!(usedBits & i)) {
@ -244,5 +243,6 @@ bool FramebufferManagerD3D11::NotifyStencilUpload(u32 addr, int size, StencilUpl
tex->Release(); tex->Release();
RebindFramebuffer("RebindFramebuffer stencil"); RebindFramebuffer("RebindFramebuffer stencil");
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS);
return true; return true;
} }

View file

@ -185,7 +185,6 @@ bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, StencilUploa
dxstate.colorMask.set(false, false, false, true); dxstate.colorMask.set(false, false, false, true);
dxstate.stencilTest.enable(); dxstate.stencilTest.enable();
dxstate.stencilOp.set(D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE); dxstate.stencilOp.set(D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE);
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE);
u16 w = dstBuffer->renderWidth; u16 w = dstBuffer->renderWidth;
u16 h = dstBuffer->renderHeight; u16 h = dstBuffer->renderHeight;
@ -197,7 +196,6 @@ bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, StencilUploa
} }
D3DVIEWPORT9 vp{ 0, 0, w, h, 0.0f, 1.0f }; D3DVIEWPORT9 vp{ 0, 0, w, h, 0.0f, 1.0f };
device_->SetViewport(&vp); device_->SetViewport(&vp);
gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE);
float u1 = 1.0f; float u1 = 1.0f;
float v1 = 1.0f; float v1 = 1.0f;
@ -255,6 +253,7 @@ bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, StencilUploa
dxstate.stencilMask.set(0xFF); dxstate.stencilMask.set(0xFF);
dxstate.viewport.restore(); dxstate.viewport.restore();
RebindFramebuffer("RebindFramebuffer stencil"); RebindFramebuffer("RebindFramebuffer stencil");
gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS);
return true; return true;
} }

View file

@ -92,10 +92,6 @@ void TextureCacheDX9::ReleaseTexture(TexCacheEntry *entry, bool delete_them) {
} }
} }
void TextureCacheDX9::ForgetLastTexture() {
InvalidateLastTexture();
}
void TextureCacheDX9::InvalidateLastTexture() { void TextureCacheDX9::InvalidateLastTexture() {
lastBoundTexture = INVALID_TEX; lastBoundTexture = INVALID_TEX;
} }

View file

@ -49,7 +49,9 @@ public:
shaderManager_ = sm; shaderManager_ = sm;
} }
void ForgetLastTexture() override; void ForgetLastTexture() override {
InvalidateLastTexture();
}
void InvalidateLastTexture() override; void InvalidateLastTexture() override;
bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override; bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override;

View file

@ -129,7 +129,6 @@ void FramebufferManagerGLES::PackDepthbuffer(VirtualFramebuffer *vfb, int x, int
auto *blitFBO = GetTempFBO(TempFBO::COPY, vfb->renderWidth, vfb->renderHeight, Draw::FBO_8888); auto *blitFBO = GetTempFBO(TempFBO::COPY, vfb->renderWidth, vfb->renderHeight, Draw::FBO_8888);
draw_->BindFramebufferAsRenderTarget(blitFBO, { Draw::RPAction::CLEAR, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "PackDepthbuffer"); draw_->BindFramebufferAsRenderTarget(blitFBO, { Draw::RPAction::CLEAR, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "PackDepthbuffer");
render_->SetViewport({ 0, 0, (float)vfb->renderWidth, (float)vfb->renderHeight, 0.0f, 1.0f }); render_->SetViewport({ 0, 0, (float)vfb->renderWidth, (float)vfb->renderHeight, 0.0f, 1.0f });
textureCacheGL_->ForgetLastTexture();
// We must bind the program after starting the render pass, and set the color mask after clearing. // We must bind the program after starting the render pass, and set the color mask after clearing.
render_->SetScissor({ 0, 0, vfb->renderWidth, vfb->renderHeight }); render_->SetScissor({ 0, 0, vfb->renderWidth, vfb->renderHeight });
@ -156,6 +155,8 @@ void FramebufferManagerGLES::PackDepthbuffer(VirtualFramebuffer *vfb, int x, int
DrawActiveTexture(x, y, w, h, vfb->renderWidth, vfb->renderHeight, 0.0f, 0.0f, u1, v1, ROTATION_LOCKED_HORIZONTAL, DRAWTEX_NEAREST); DrawActiveTexture(x, y, w, h, vfb->renderWidth, vfb->renderHeight, 0.0f, 0.0f, u1, v1, ROTATION_LOCKED_HORIZONTAL, DRAWTEX_NEAREST);
draw_->CopyFramebufferToMemorySync(blitFBO, Draw::FB_COLOR_BIT, 0, y, packWidth, h, Draw::DataFormat::R8G8B8A8_UNORM, convBuf_, vfb->z_stride, "PackDepthbuffer"); draw_->CopyFramebufferToMemorySync(blitFBO, Draw::FB_COLOR_BIT, 0, y, packWidth, h, Draw::DataFormat::R8G8B8A8_UNORM, convBuf_, vfb->z_stride, "PackDepthbuffer");
textureCacheGL_->ForgetLastTexture();
// TODO: Use 4444 so we can copy lines directly? // TODO: Use 4444 so we can copy lines directly?
format16Bit = true; format16Bit = true;
} else { } else {
@ -197,5 +198,5 @@ void FramebufferManagerGLES::PackDepthbuffer(VirtualFramebuffer *vfb, int x, int
} }
} }
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE); gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS);
} }

View file

@ -218,7 +218,7 @@ bool FramebufferManagerGLES::NotifyStencilUpload(u32 addr, int size, StencilUplo
} }
tex->Release(); tex->Release();
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
RebindFramebuffer("RebindFramebuffer - Stencil"); RebindFramebuffer("RebindFramebuffer - Stencil");
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS);
return true; return true;
} }

View file

@ -47,7 +47,6 @@
TextureCacheGLES::TextureCacheGLES(Draw::DrawContext *draw) TextureCacheGLES::TextureCacheGLES(Draw::DrawContext *draw)
: TextureCacheCommon(draw) { : TextureCacheCommon(draw) {
timesInvalidatedAllThisFrame_ = 0; timesInvalidatedAllThisFrame_ = 0;
lastBoundTexture = nullptr;
render_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); render_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
SetupTextureDecoder(); SetupTextureDecoder();
@ -537,8 +536,6 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
texelsScaledThisFrame_ += w * h; texelsScaledThisFrame_ += w * h;
} }
} }
lastBoundTexture = entry->textureName;
// GLES2 doesn't have support for a "Max lod" which is critical as PSP games often // GLES2 doesn't have support for a "Max lod" which is critical as PSP games often
// don't specify mips all the way down. As a result, we either need to manually generate // don't specify mips all the way down. As a result, we either need to manually generate
@ -595,13 +592,6 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
} }
render_->FinalizeTexture(entry->textureName, texMaxLevel, genMips); render_->FinalizeTexture(entry->textureName, texMaxLevel, genMips);
// This will rebind it, but that's okay.
// Need to actually bind it now - it might only have gotten bound in the init phase.
render_->BindTexture(TEX_SLOT_PSP_TEXTURE, entry->textureName);
SamplerCacheKey samplerKey = GetSamplingParams(entry->maxLevel, entry->addr);
ApplySamplingParams(samplerKey);
} }
Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const { Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const {

View file

@ -85,7 +85,7 @@ private:
TextureScalerGLES scaler; TextureScalerGLES scaler;
GLRTexture *lastBoundTexture; GLRTexture *lastBoundTexture = nullptr;
FramebufferManagerGLES *framebufferManagerGL_; FramebufferManagerGLES *framebufferManagerGL_;
DepalShaderCacheGLES *depalShaderCache_; DepalShaderCacheGLES *depalShaderCache_;

View file

@ -183,7 +183,6 @@ bool FramebufferManagerVulkan::NotifyStencilUpload(u32 addr, int size, StencilUp
renderManager->BindPipeline(pipeline); renderManager->BindPipeline(pipeline);
renderManager->SetViewport({ 0.0f, 0.0f, (float)w, (float)h, 0.0f, 1.0f }); renderManager->SetViewport({ 0.0f, 0.0f, (float)w, (float)h, 0.0f, 1.0f });
renderManager->SetScissor({ { 0, 0, },{ (uint32_t)w, (uint32_t)h } }); renderManager->SetScissor({ { 0, 0, },{ (uint32_t)w, (uint32_t)h } });
gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE);
draw_->BindTextures(0, 1, &tex); draw_->BindTextures(0, 1, &tex);
VkImageView drawPixelsImageView = (VkImageView)draw_->GetNativeObject(Draw::NativeObject::BOUND_TEXTURE0_IMAGEVIEW); VkImageView drawPixelsImageView = (VkImageView)draw_->GetNativeObject(Draw::NativeObject::BOUND_TEXTURE0_IMAGEVIEW);
@ -225,5 +224,6 @@ bool FramebufferManagerVulkan::NotifyStencilUpload(u32 addr, int size, StencilUp
tex->Release(); tex->Release();
RebindFramebuffer("RebindFramebuffer - NotifyStencilUpload"); RebindFramebuffer("RebindFramebuffer - NotifyStencilUpload");
gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS);
return true; return true;
} }

View file

@ -872,7 +872,6 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
entry->vkTex = nullptr; entry->vkTex = nullptr;
} }
} }
lastBoundTexture = entry->vkTex;
ReplacedTextureDecodeInfo replacedInfo; ReplacedTextureDecodeInfo replacedInfo;
if (replacer_.Enabled() && !replaced.Valid()) { if (replacer_.Enabled() && !replaced.Valid()) {
@ -997,8 +996,6 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
} }
entry->vkTex->EndCreate(cmdInit, false, computeUpload ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); entry->vkTex->EndCreate(cmdInit, false, computeUpload ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
} }
gstate_c.SetTextureFullAlpha(entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL);
} }
VkFormat TextureCacheVulkan::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const { VkFormat TextureCacheVulkan::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const {