diff --git a/GPU/Common/FramebufferCommon.h b/GPU/Common/FramebufferCommon.h index 79e141df76..205120f31f 100644 --- a/GPU/Common/FramebufferCommon.h +++ b/GPU/Common/FramebufferCommon.h @@ -229,6 +229,9 @@ public: return true; } + VirtualFramebuffer *GetCurrentRenderVFB() const { + return currentRenderVfb_; + } // TODO: Break out into some form of FBO manager VirtualFramebuffer *GetVFBAt(u32 addr); VirtualFramebuffer *GetDisplayVFB() { diff --git a/GPU/D3D11/FramebufferManagerD3D11.cpp b/GPU/D3D11/FramebufferManagerD3D11.cpp index 1903fa3298..e843bd11d7 100644 --- a/GPU/D3D11/FramebufferManagerD3D11.cpp +++ b/GPU/D3D11/FramebufferManagerD3D11.cpp @@ -405,11 +405,7 @@ void FramebufferManagerD3D11::BlitFramebufferDepth(VirtualFramebuffer *src, Virt } } -void FramebufferManagerD3D11::BindFramebufferColor(int stage, VirtualFramebuffer *framebuffer, int flags) { - if (framebuffer == NULL) { - framebuffer = currentRenderVfb_; - } - +void FramebufferManagerD3D11::BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags) { if (!framebuffer->fbo || !useBufferedRendering_) { ID3D11ShaderResourceView *view = nullptr; context_->PSSetShaderResources(stage, 1, &view); @@ -424,7 +420,7 @@ void FramebufferManagerD3D11::BindFramebufferColor(int stage, VirtualFramebuffer skipCopy = true; } // Currently rendering to this framebuffer. Need to make a copy. - if (!skipCopy && currentRenderVfb_ && framebuffer->fb_address == gstate.getFrameBufRawAddress()) { + if (!skipCopy && framebuffer == currentRenderVfb_) { // TODO: Maybe merge with bvfbs_? Not sure if those could be packing, and they're created at a different size. Draw::Framebuffer *renderCopy = GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, (Draw::FBColorDepth)framebuffer->colorDepth); if (renderCopy) { @@ -458,8 +454,14 @@ void FramebufferManagerD3D11::BindFramebufferColor(int stage, VirtualFramebuffer } else { draw_->BindFramebufferAsTexture(framebuffer->fbo, stage, Draw::FB_COLOR_BIT, 0); } - } else { + } else if (framebuffer != currentRenderVfb_) { draw_->BindFramebufferAsTexture(framebuffer->fbo, stage, Draw::FB_COLOR_BIT, 0); + } else { + // Badness on D3D11 to bind the currently rendered-to framebuffer as a texture. + ID3D11ShaderResourceView *view = nullptr; + context_->PSSetShaderResources(stage, 1, &view); + gstate_c.skipDrawReason |= SKIPDRAW_BAD_FB_TEXTURE; + return; } } diff --git a/GPU/D3D11/FramebufferManagerD3D11.h b/GPU/D3D11/FramebufferManagerD3D11.h index 101736a029..a77bf53efa 100644 --- a/GPU/D3D11/FramebufferManagerD3D11.h +++ b/GPU/D3D11/FramebufferManagerD3D11.h @@ -60,7 +60,7 @@ public: void BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst) override; - void BindFramebufferColor(int stage, VirtualFramebuffer *framebuffer, int flags); + void BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags); void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h) override; void DownloadFramebufferForClut(u32 fb_address, u32 loadBytes) override; diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index 0d40715cd2..b8e2888a96 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -421,7 +421,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef) { if (!gstate.isModeClear()) { if (fboTexNeedBind_) { - framebufferManager_->BindFramebufferColor(1, nullptr, BINDFBCOLOR_MAY_COPY); + framebufferManager_->BindFramebufferAsColorTexture(1, framebufferManager_->GetCurrentRenderVFB(), BINDFBCOLOR_MAY_COPY); // No sampler required, we do a Load in the pixel shader // context_->PSSetSamplers(1, 1, &stockD3D11.samplerPoint2DClamp); fboTexBound_ = true; diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 9b6364cf0d..8fde78162b 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -173,6 +173,8 @@ void TextureCacheD3D11::DeleteTexture(TexCache::iterator it) { void TextureCacheD3D11::ForgetLastTexture() { lastBoundTexture = INVALID_TEX; gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); + ID3D11ShaderResourceView *nullTex = nullptr; + context_->PSSetShaderResources(0, 1, &nullTex); } // Removes old textures. @@ -534,7 +536,6 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFra ID3D11ShaderResourceView *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_); Draw::Framebuffer *depalFBO = framebufferManagerD3D11_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, Draw::FBO_8888); - draw_->BindFramebufferAsRenderTarget(depalFBO); shaderManager_->DirtyLastShader(); draw_->BindPipeline(nullptr); @@ -547,10 +548,12 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFra context_->PSSetShaderResources(1, 1, &clutTexture); context_->PSSetSamplers(1, 1, &stockD3D11.samplerPoint2DWrap); - framebufferManagerD3D11_->BindFramebufferColor(0, framebuffer, BINDFBCOLOR_SKIP_COPY); + framebufferManagerD3D11_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY); context_->PSSetSamplers(0, 1, &stockD3D11.samplerPoint2DWrap); + draw_->BindFramebufferAsRenderTarget(depalFBO); shaderApply.Shade(); + framebufferManagerD3D11_->RebindFramebuffer(); draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0); const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); @@ -562,13 +565,12 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFra } else { entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; - framebufferManagerD3D11_->BindFramebufferColor(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); + framebufferManagerD3D11_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; + framebufferManagerD3D11_->RebindFramebuffer(); } - - framebufferManagerD3D11_->RebindFramebuffer(); SamplerCacheKey samplerKey; SetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight, samplerKey); ID3D11SamplerState *state = samplerCache_.GetOrCreateSampler(device_, samplerKey); diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index 9f11103590..4a2e13be47 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -507,7 +507,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float return offscreen; } - void FramebufferManagerDX9::BindFramebufferColor(int stage, VirtualFramebuffer *framebuffer, int flags) { + void FramebufferManagerDX9::BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags) { if (framebuffer == NULL) { framebuffer = currentRenderVfb_; } diff --git a/GPU/Directx9/FramebufferDX9.h b/GPU/Directx9/FramebufferDX9.h index 3f75c9d364..e86e0632b9 100644 --- a/GPU/Directx9/FramebufferDX9.h +++ b/GPU/Directx9/FramebufferDX9.h @@ -62,7 +62,7 @@ public: void BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst) override; - void BindFramebufferColor(int stage, VirtualFramebuffer *framebuffer, int flags); + void BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags); void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h) override; void DownloadFramebufferForClut(u32 fb_address, u32 loadBytes) override; diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index 0f97c19b0b..c38928266a 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -287,7 +287,7 @@ void DrawEngineDX9::ApplyDrawStateLate() { if (fboTexNeedBind_) { // Note that this is positions, not UVs, that we need the copy from. - framebufferManager_->BindFramebufferColor(1, nullptr, BINDFBCOLOR_MAY_COPY); + framebufferManager_->BindFramebufferAsColorTexture(1, framebufferManager_->GetCurrentRenderVFB(), BINDFBCOLOR_MAY_COPY); // If we are rendering at a higher resolution, linear is probably best for the dest color. pD3Ddevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); pD3Ddevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index c7e7e438ea..db6b5924de 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -561,7 +561,7 @@ void TextureCacheDX9::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFrame pD3Ddevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT); pD3Ddevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE); - framebufferManagerDX9_->BindFramebufferColor(0, framebuffer, BINDFBCOLOR_SKIP_COPY); + framebufferManagerDX9_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY); pD3Ddevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); pD3Ddevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); pD3Ddevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); @@ -579,7 +579,7 @@ void TextureCacheDX9::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFrame } else { entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; - framebufferManagerDX9_->BindFramebufferColor(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); + framebufferManagerDX9_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index 7eabfc6b5b..cdd4add39a 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -493,11 +493,7 @@ void FramebufferManagerGLES::BlitFramebufferDepth(VirtualFramebuffer *src, Virtu } } -void FramebufferManagerGLES::BindFramebufferColor(int stage, VirtualFramebuffer *framebuffer, int flags) { - if (framebuffer == NULL) { - framebuffer = currentRenderVfb_; - } - +void FramebufferManagerGLES::BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags) { if (!framebuffer->fbo || !useBufferedRendering_) { glBindTexture(GL_TEXTURE_2D, 0); gstate_c.skipDrawReason |= SKIPDRAW_BAD_FB_TEXTURE; diff --git a/GPU/GLES/FramebufferManagerGLES.h b/GPU/GLES/FramebufferManagerGLES.h index 0a37494ebd..b98ccd52ed 100644 --- a/GPU/GLES/FramebufferManagerGLES.h +++ b/GPU/GLES/FramebufferManagerGLES.h @@ -77,7 +77,7 @@ public: void BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst) override; // For use when texturing from a framebuffer. May create a duplicate if target. - void BindFramebufferColor(int stage, VirtualFramebuffer *framebuffer, int flags); + void BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags); // Reads a rectangular subregion of a framebuffer to the right position in its backing memory. void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h) override; diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index 440469e4f4..5931db7ee8 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -352,7 +352,7 @@ void DrawEngineGLES::ApplyDrawStateLate() { if (!gstate.isModeClear()) { if (fboTexNeedBind_) { // Note that this is positions, not UVs, that we need the copy from. - framebufferManager_->BindFramebufferColor(1, nullptr, BINDFBCOLOR_MAY_COPY); + framebufferManager_->BindFramebufferAsColorTexture(1, nullptr, BINDFBCOLOR_MAY_COPY); framebufferManager_->RebindFramebuffer(); glActiveTexture(GL_TEXTURE1); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 4e06a517f6..58a4a1ea43 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -625,7 +625,7 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram glBindTexture(GL_TEXTURE_2D, clutTexture); glActiveTexture(GL_TEXTURE0); - framebufferManagerGL_->BindFramebufferColor(0, framebuffer, BINDFBCOLOR_SKIP_COPY); + framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -642,7 +642,7 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram } else { entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; - framebufferManagerGL_->BindFramebufferColor(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); + framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index 47c4fc111e..b6f445a95c 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -606,10 +606,8 @@ void DrawEngineVulkan::DirtyAllUBOs() { if (fboTexNeedBind_) { // Note that this is positions, not UVs, that we need the copy from. - framebufferManager_->BindFramebufferColor(1, nullptr, BINDFBCOLOR_MAY_COPY); + framebufferManager_->BindFramebufferAsColorTexture(1, framebufferManager_->GetCurrentRenderVFB(), BINDFBCOLOR_MAY_COPY); // If we are rendering at a higher resolution, linear is probably best for the dest color. - pD3Ddevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - pD3Ddevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); fboTexBound_ = true; fboTexNeedBind_ = false; } diff --git a/Windows/GPU/D3D11Context.cpp b/Windows/GPU/D3D11Context.cpp index d4a9286193..ce679c7e41 100644 --- a/Windows/GPU/D3D11Context.cpp +++ b/Windows/GPU/D3D11Context.cpp @@ -78,7 +78,7 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { if (SUCCEEDED(d3dDebug_->QueryInterface(__uuidof(ID3D11InfoQueue), (void**)&d3dInfoQueue_))) { d3dInfoQueue_->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true); d3dInfoQueue_->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true); - //d3dInfoQueue_->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true); + d3dInfoQueue_->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true); } } #endif