Skip to content

Commit

Permalink
Add compat flag for reinterpret shader, also disable on platforms tha…
Browse files Browse the repository at this point in the history
…t can't support it yet
  • Loading branch information
hrydgard committed Nov 8, 2020
1 parent b0bb3dc commit c75ed17
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Common/GPU/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ShaderLanguageDesc::Init(ShaderLanguage lang) {
bitwiseOps = lang == HLSL_D3D11;
framebufferFetchExtension = nullptr;
gles = false;
glslES30 = true;
glslES30 = true; // Hm, D3D9 too?
glslVersionNumber = 0;
lastFragData = nullptr;
texture = "texture";
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct ShaderLanguageDesc {
const char *framebufferFetchExtension = nullptr;
const char *vsOutPrefix = "";
const char *viewportYSign = "";
bool glslES30 = false;
bool glslES30 = false; // really glslES30Features. TODO: Clean this up.
bool bitwiseOps = false;
bool forceMatrix4x4 = false;
bool coefsFromBuffers = false;
Expand Down
1 change: 1 addition & 0 deletions Core/Compatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) {
CheckSetting(iniFile, gameID, "ReportSmallMemstick", &flags_.ReportSmallMemstick);
CheckSetting(iniFile, gameID, "MemstickFixedFree", &flags_.MemstickFixedFree);
CheckSetting(iniFile, gameID, "DateLimited", &flags_.DateLimited);
CheckSetting(iniFile, gameID, "ReinterpretFramebuffers", &flags_.ReinterpretFramebuffers);
}

void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag) {
Expand Down
1 change: 1 addition & 0 deletions Core/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct CompatFlags {
bool ReportSmallMemstick;
bool MemstickFixedFree;
bool DateLimited;
bool ReinterpretFramebuffers;
};

class IniFile;
Expand Down
28 changes: 23 additions & 5 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ void FramebufferManagerCommon::NotifyRenderFramebufferUpdated(VirtualFramebuffer
if (vfbFormatChanged) {
textureCache_->NotifyFramebuffer(vfb, NOTIFY_FB_UPDATED);
if (vfb->drawnFormat != vfb->format) {
ReformatFramebufferFrom(vfb, vfb->drawnFormat);
ReinterpretFramebufferFrom(vfb, vfb->drawnFormat);
}
}

Expand All @@ -517,10 +517,28 @@ void FramebufferManagerCommon::NotifyRenderFramebufferUpdated(VirtualFramebuffer
}
}

void FramebufferManagerCommon::ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat oldFormat) {
void FramebufferManagerCommon::ReinterpretFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat oldFormat) {
if (!useBufferedRendering_ || !vfb->fbo) {
return;
}

ShaderLanguage lang = draw_->GetShaderLanguageDesc().shaderLanguage;

bool doReinterpret = PSP_CoreParameter().compat.flags().ReinterpretFramebuffers &&
(lang == HLSL_D3D11 || lang == GLSL_VULKAN || lang == GLSL_3xx);
if (!doReinterpret) {
// Fake reinterpret - just clear the way we always did on Vulkan. Just clear color and stencil.
if (oldFormat == GE_FORMAT_565) {
// We have to bind here instead of clear, since it can be that no framebuffer is bound.
// The backend can sometimes directly optimize it to a clear.
draw_->BindFramebufferAsRenderTarget(vfb->fbo, { Draw::RPAction::CLEAR, Draw::RPAction::KEEP, Draw::RPAction::CLEAR }, "FakeReinterpret");
// Need to dirty anything that has command buffer dynamic state, in case we started a new pass above.
// Should find a way to feed that information back, maybe... Or simply correct the issue in the rendermanager.
gstate_c.Dirty(DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE);
}
return;
}

GEBufferFormat newFormat = vfb->format;

_assert_(newFormat != oldFormat);
Expand Down Expand Up @@ -595,12 +613,13 @@ void FramebufferManagerCommon::ReformatFramebufferFrom(VirtualFramebuffer *vfb,
draw_->SetScissorRect(0, 0, vfb->renderWidth, vfb->renderHeight);
Draw::Viewport vp = Draw::Viewport{ 0.0f, 0.0f, (float)vfb->renderWidth, (float)vfb->renderHeight, 0.0f, 1.0f };
draw_->SetViewports(1, &vp);
// No vertex buffer - generate vertices in shader. TODO: Switch to a vertex buffer for GLES2/D3D9 compat.
draw_->Draw(3, 0);
draw_->InvalidateCachedState();

// Unbind.
draw_->BindTexture(0, nullptr);
RebindFramebuffer("RebindFramebuffer - After reinterpret");
RebindFramebuffer("After reinterpret");

shaderManager_->DirtyLastShader();
textureCache_->ForgetLastTexture();
Expand Down Expand Up @@ -639,8 +658,7 @@ void FramebufferManagerCommon::NotifyRenderFramebufferSwitched(VirtualFramebuffe
}
}
if (vfb->drawnFormat != vfb->format) {
// TODO: Might ultimately combine this with the resize step in DoSetRenderFrameBuffer().
ReformatFramebufferFrom(vfb, vfb->drawnFormat);
ReinterpretFramebufferFrom(vfb, vfb->drawnFormat);
}

if (useBufferedRendering_) {
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/FramebufferManagerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class FramebufferManagerCommon {
const std::vector<VirtualFramebuffer *> &Framebuffers() {
return vfbs_;
}
void ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old);
void ReinterpretFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old);

protected:
virtual void PackFramebufferSync_(VirtualFramebuffer *vfb, int x, int y, int w, int h);
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/TextureCacheCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ void TextureCacheCommon::SetTextureFramebuffer(const AttachCandidate &candidate)
// TODO: Kinda ugly, maybe switch direction of the call?
GEBufferFormat oldFormat = candidate.fb->format;
candidate.fb->format = candidate.match.reinterpretTo;
framebufferManager_->ReformatFramebufferFrom(candidate.fb, oldFormat);
framebufferManager_->ReinterpretFramebufferFrom(candidate.fb, oldFormat);
}

_dbg_assert_msg_(framebuffer != nullptr, "Framebuffer must not be null.");
Expand Down
5 changes: 2 additions & 3 deletions GPU/D3D11/TextureCacheD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,9 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
TexCacheEntry::TexStatus alphaStatus = CheckAlpha(clutBuf_, GetClutDestFormatD3D11(clutFormat), clutTotalColors, clutTotalColors, 1);
gstate_c.SetTextureFullAlpha(alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL);
} else {
framebufferManagerD3D11_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);

gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650);
framebufferManagerD3D11_->RebindFramebuffer("RebindFramebuffer - ApplyTextureFramebuffer"); // Probably not necessary.
framebufferManagerD3D11_->RebindFramebuffer("RebindFramebuffer - ApplyTextureFramebuffer");
framebufferManagerD3D11_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
}

SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight);
Expand Down
8 changes: 8 additions & 0 deletions assets/compat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -794,3 +794,11 @@ ULUS10455 = true
# Car Jack Streets - issue #12698
NPUZ00043 = true
NPEZ00198 = true

# This setting will go away in the near future, hopefully we can enable it
# for all games.
[ReinterpretFramebuffers]
# Outrun - issue #11358
ULES00262 = true
ULUS10064 = true
ULKS46087 = true

0 comments on commit c75ed17

Please sign in to comment.