From 17c4b2387e891b3fa876a8d8c2a7109f4e783f52 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 29 Mar 2016 17:04:21 +0200 Subject: [PATCH] gl: Fix unnormalized coord sampling. --- Vulkan/Vulkan-LoaderAndValidationLayers | 2 +- rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp | 6 +++--- rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp | 24 +++++++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Vulkan/Vulkan-LoaderAndValidationLayers b/Vulkan/Vulkan-LoaderAndValidationLayers index ec513f89f9..1affe90f0e 160000 --- a/Vulkan/Vulkan-LoaderAndValidationLayers +++ b/Vulkan/Vulkan-LoaderAndValidationLayers @@ -1 +1 @@ -Subproject commit ec513f89f9354394fec465448a2838f106777640 +Subproject commit 1affe90f0ec7f9bccb6841a56a2a5b66861efe6a diff --git a/rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp b/rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp index 539a0a3b64..aa01e6bc06 100644 --- a/rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp +++ b/rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp @@ -47,11 +47,11 @@ std::string getFunctionImpl(FUNCTION f) case FUNCTION::FUNCTION_TEXTURE_SAMPLE1D_LOD: return "textureLod($t, $0.x, $1)"; case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D: - return "texture($t, $0.xy)"; + return "texture($t, $0.xy * $t_coord_scale)"; case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_PROJ: - return "textureProj($t, $0.xyz, $1.x)"; // Note: $1.x is bias + return "textureProj($t, $0.xyz * vec3($t_coord_scale, 1.) , $1.x)"; // Note: $1.x is bias case FUNCTION::FUNCTION_TEXTURE_SAMPLE2D_LOD: - return "textureLod($t, $0.xy, $1.x)"; + return "textureLod($t, $0.xy * $t_coord_scale, $1.x)"; case FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE: return "texture($t, $0.xyz)"; case FUNCTION::FUNCTION_TEXTURE_SAMPLECUBE_PROJ: diff --git a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp index da1427c91a..a77e9fe28e 100644 --- a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp @@ -85,9 +85,6 @@ void GLFragmentDecompilerThread::insertConstants(std::stringstream & OS) std::string samplerType = PT.type; int index = atoi(&PI.name.data()[3]); - if (m_prog.unnormalized_coords & (1 << index)) - samplerType = "sampler2DRect"; - OS << "uniform " << samplerType << " " << PI.name << ";" << std::endl; } } @@ -163,6 +160,27 @@ void GLFragmentDecompilerThread::insertMainStart(std::stringstream & OS) OS << " vec4 ssa = gl_FrontFacing ? vec4(1.) : vec4(-1.);\n"; + for (const ParamType& PT : m_parr.params[PF_PARAM_UNIFORM]) + { + if (PT.type != "sampler2D") + continue; + + for (const ParamItem& PI : PT.items) + { + std::string samplerType = PT.type; + int index = atoi(&PI.name.data()[3]); + + if (m_prog.unnormalized_coords & (1 << index)) + { + OS << "vec2 tex" << index << "_coord_scale = 1. / textureSize(" << PI.name << ", 0);\n"; + } + else + { + OS << "vec2 tex" << index << "_coord_scale = vec2(1.);\n"; + } + } + } + // search if there is fogc in inputs for (const ParamType& PT : m_parr.params[PF_PARAM_IN]) {