From 8f8098ed2442ab9d259b35d43c3aa5f8affeb76d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 17 May 2020 10:47:39 -0700 Subject: [PATCH] GPU: Add sampler1 for postshader orig source. --- GPU/Common/PresentationCommon.cpp | 14 +++++++++----- GPU/Common/PresentationCommon.h | 2 +- GPU/Common/ShaderTranslation.cpp | 9 ++++++++- GPU/GLES/DepalettizeShaderGLES.cpp | 7 ++++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/GPU/Common/PresentationCommon.cpp b/GPU/Common/PresentationCommon.cpp index 337a26d83c..4df4b43716 100644 --- a/GPU/Common/PresentationCommon.cpp +++ b/GPU/Common/PresentationCommon.cpp @@ -491,11 +491,11 @@ void PresentationCommon::SourceFramebuffer(Draw::Framebuffer *fb, int bufferWidt srcHeight_ = bufferHeight; } -void PresentationCommon::BindSource() { +void PresentationCommon::BindSource(int binding) { if (srcTexture_) { - draw_->BindTexture(0, srcTexture_); + draw_->BindTexture(binding, srcTexture_); } else if (srcFramebuffer_) { - draw_->BindFramebufferAsTexture(srcFramebuffer_, 0, Draw::FB_COLOR_BIT, 0); + draw_->BindFramebufferAsTexture(srcFramebuffer_, binding, Draw::FB_COLOR_BIT, 0); } else { assert(false); } @@ -611,8 +611,9 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u if (usePostShaderOutput) { draw_->BindFramebufferAsTexture(postShaderFramebuffers_[i - 1], 0, Draw::FB_COLOR_BIT, 0); } else { - BindSource(); + BindSource(0); } + BindSource(1); int nextWidth, nextHeight; draw_->GetFramebufferDimensions(postShaderFramebuffer, &nextWidth, &nextHeight); @@ -628,6 +629,7 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u Draw::SamplerState *sampler = useNearest || shaderInfo->isUpscalingFilter ? samplerNearest_ : samplerLinear_; draw_->BindSamplerStates(0, 1, &sampler); + draw_->BindSamplerStates(1, 1, &sampler); draw_->BindVertexBuffers(0, 1, &vdata_, &postVertsOffset); draw_->BindIndexBuffer(idata_, 0); @@ -658,8 +660,9 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u if (usePostShaderOutput) { draw_->BindFramebufferAsTexture(postShaderFramebuffers_.back(), 0, Draw::FB_COLOR_BIT, 0); } else { - BindSource(); + BindSource(0); } + BindSource(1); if (isFinalAtOutputResolution) { PostShaderUniforms uniforms; @@ -676,6 +679,7 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u Draw::SamplerState *sampler = useNearest ? samplerNearest_ : samplerLinear_; draw_->BindSamplerStates(0, 1, &sampler); + draw_->BindSamplerStates(1, 1, &sampler); auto setViewport = [&](float x, float y, float w, float h) { Draw::Viewport viewport{ x, y, w, h, 0.0f, 1.0f }; diff --git a/GPU/Common/PresentationCommon.h b/GPU/Common/PresentationCommon.h index 13b89f4ca7..ee0822ea0a 100644 --- a/GPU/Common/PresentationCommon.h +++ b/GPU/Common/PresentationCommon.h @@ -114,7 +114,7 @@ protected: bool BuildPostShader(const ShaderInfo *shaderInfo, const ShaderInfo *next); bool AllocateFramebuffer(int w, int h); - void BindSource(); + void BindSource(int binding); void GetCardboardSettings(CardboardSettings *cardboardSettings); void CalculatePostShaderUniforms(int bufferWidth, int bufferHeight, int targetWidth, int targetHeight, const ShaderInfo *shaderInfo, PostShaderUniforms *uniforms); diff --git a/GPU/Common/ShaderTranslation.cpp b/GPU/Common/ShaderTranslation.cpp index 192e59f186..2361ba9e11 100644 --- a/GPU/Common/ShaderTranslation.cpp +++ b/GPU/Common/ShaderTranslation.cpp @@ -140,6 +140,10 @@ std::string Postprocess(std::string code, ShaderLanguage lang, Draw::ShaderStage out << "sampler2D sampler0 : register(s0);\n"; continue; } + if (line == "uniform sampler2D sampler1;" && lang == HLSL_DX9) { + out << "sampler2D sampler1 : register(s1);\n"; + continue; + } if (line.find("uniform float") != std::string::npos) { continue; } @@ -181,7 +185,10 @@ bool ConvertToVulkanGLSL(std::string *dest, TranslatedShaderMetadata *destMetada if (line.find("uniform bool") != std::string::npos) { continue; } else if (line.find("uniform sampler2D") == 0) { - line = "layout(set = 0, binding = 1) " + line; + if (line.find("sampler0") != line.npos) + line = "layout(set = 0, binding = 1) " + line; + else + line = "layout(set = 0, binding = 2) " + line; } else if (line.find("uniform ") != std::string::npos) { continue; } else if (2 == sscanf(line.c_str(), "varying vec%d v_texcoord%d;", &vecSize, &num)) { diff --git a/GPU/GLES/DepalettizeShaderGLES.cpp b/GPU/GLES/DepalettizeShaderGLES.cpp index 5abe33d77c..348411e082 100644 --- a/GPU/GLES/DepalettizeShaderGLES.cpp +++ b/GPU/GLES/DepalettizeShaderGLES.cpp @@ -21,7 +21,8 @@ #include "Common/Log.h" #include "Common/StringUtils.h" #include "Core/Reporting.h" -#include "DepalettizeShaderGLES.h" +#include "GPU/GLES/DepalettizeShaderGLES.h" +#include "GPU/GLES/DrawEngineGLES.h" #include "GPU/GLES/TextureCacheGLES.h" #include "GPU/Common/DepalettizeShaderCommon.h" @@ -178,8 +179,8 @@ DepalShader *DepalShaderCacheGLES::GetDepalettizeShader(uint32_t clutMode, GEBuf queries.push_back({ &depal->u_pal, "pal" }); std::vector initializer; - initializer.push_back({ &depal->u_tex, 0, 0 }); - initializer.push_back({ &depal->u_pal, 0, 3 }); + initializer.push_back({ &depal->u_tex, 0, TEX_SLOT_PSP_TEXTURE }); + initializer.push_back({ &depal->u_pal, 0, TEX_SLOT_CLUT }); std::vector shaders{ vertexShader_, fragShader };