From 852c395fb770e10b8787fa9a76ff4957b090ad6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 9 Aug 2022 16:00:41 +0200 Subject: [PATCH] Texcoord attrs must be called a_texcoord0, this should be fixed. Oh well. Also small fix for depth in float-depal. --- Common/GPU/ShaderWriter.cpp | 2 ++ GPU/Common/DepalettizeShaderCommon.cpp | 22 ++++++++++++++++------ GPU/Common/TextureCacheCommon.cpp | 3 +-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Common/GPU/ShaderWriter.cpp b/Common/GPU/ShaderWriter.cpp index da3a48e5c3..1671d5d6a5 100644 --- a/Common/GPU/ShaderWriter.cpp +++ b/Common/GPU/ShaderWriter.cpp @@ -14,6 +14,7 @@ const char * const vulkan_glsl_preamble_fs = "#extension GL_ARB_shader_image_load_store : enable\n" "#define splat3(x) vec3(x)\n" "#define DISCARD discard\n" +"precision lowp float;\n" "precision highp int;\n" "\n"; @@ -131,6 +132,7 @@ void ShaderWriter::Preamble(const char **gl_extensions, size_t num_gl_extensions case ShaderStage::Fragment: C("#define DISCARD discard\n"); if (lang_.gles) { + C("precision lowp float;\n"); if (lang_.glslES30) { C("precision highp int;\n"); } diff --git a/GPU/Common/DepalettizeShaderCommon.cpp b/GPU/Common/DepalettizeShaderCommon.cpp index ad53268760..45e6dba76e 100644 --- a/GPU/Common/DepalettizeShaderCommon.cpp +++ b/GPU/Common/DepalettizeShaderCommon.cpp @@ -31,7 +31,7 @@ static const InputDef vsInputs[2] = { { "vec2", "a_position", Draw::SEM_POSITION, }, - { "vec2", "a_texcoord", Draw::SEM_TEXCOORD0, }, + { "vec2", "a_texcoord0", Draw::SEM_TEXCOORD0, }, }; // TODO: Deduplicate with DepalettizeCommon.cpp @@ -135,6 +135,12 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config, c const int shift = config.shift; const int mask = config.mask; + if (config.pixelFormat == GE_FORMAT_DEPTH16) { + DepthScaleFactors factors = GetDepthScaleFactors(); + writer.ConstFloat("z_scale", factors.scale); + writer.ConstFloat("z_offset", factors.offset); + } + float index_multiplier = 1.0f; // pixelformat is the format of the texture we are sampling. bool formatOK = true; @@ -216,9 +222,14 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config, c case GE_FORMAT_DEPTH16: { // TODO: I think we can handle most scenarios here, but texturing from depth buffers requires an extension on ES 2.0 anyway. - if ((mask & (mask + 1)) == 0 && shift < 16) { + if (shift < 16) { index_multiplier = 1.0f / (float)(1 << shift); - truncate_cpy(lookupMethod, "index.r"); + truncate_cpy(lookupMethod, "((index.x - z_offset) * z_scale)"); + + if ((mask & (mask + 1)) != 0) { + // But we'll try with the above anyway. + formatOK = false; + } } else { formatOK = false; } @@ -262,12 +273,11 @@ void GenerateDepalFs(char *buffer, const DepalConfig &config, const ShaderLangua case GLSL_1xx: GenerateDepalShaderFloat(writer, config, lang); break; - case GLSL_3xx: case GLSL_VULKAN: + case GLSL_3xx: case HLSL_D3D11: GenerateDepalShader300(writer, config, lang); break; - break; default: _assert_msg_(false, "Depal shader language not supported: %d", (int)lang.shaderLanguage); } @@ -277,7 +287,7 @@ void GenerateDepalFs(char *buffer, const DepalConfig &config, const ShaderLangua void GenerateDepalVs(char *buffer, const ShaderLanguageDesc &lang) { ShaderWriter writer(buffer, lang, ShaderStage::Vertex, nullptr, 0); writer.BeginVSMain(vsInputs, Slice::empty(), varyings); - writer.C(" v_texcoord = a_texcoord;\n"); + writer.C(" v_texcoord = a_texcoord0;\n"); writer.C(" gl_Position = vec4(a_position, 0.0, 1.0);\n"); if (strlen(lang.viewportYSign)) { writer.F(" gl_Position.y *= %s1.0;\n", lang.viewportYSign); diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 979f4740fb..81741ed3f4 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1897,7 +1897,6 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer draw_->InvalidateCachedState(); InvalidateLastTexture(); - return; } @@ -1922,10 +1921,10 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer shaderApply.Use(); draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); + draw_->BindTexture(1, clutTexture); Draw::SamplerState *nearest = depalShaderCache_->GetSampler(); draw_->BindSamplerStates(0, 1, &nearest); draw_->BindSamplerStates(1, 1, &nearest); - draw_->BindTexture(1, clutTexture); shaderApply.Shade(); draw_->BindTexture(0, nullptr);