From bc0bf4d3d283bdb979bc0daf2a745d894243c6ce Mon Sep 17 00:00:00 2001 From: GPUCode <47210458+GPUCode@users.noreply.github.com> Date: Thu, 17 Aug 2023 23:16:28 +0300 Subject: [PATCH] (gl/vk)_shader_gen: Use floor instead of int cast (#6885) --- src/video_core/renderer_opengl/gl_shader_gen.cpp | 4 ++-- src/video_core/renderer_vulkan/vk_shader_gen.cpp | 4 ++-- src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 128137d52..733453158 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -1246,13 +1246,13 @@ float LookupLightingLUT(int lut_index, int index, float delta) { } float LookupLightingLUTUnsigned(int lut_index, float pos) { - int index = clamp(int(pos * 256.0), 0, 255); + int index = int(clamp(floor(pos * 256.0), 0.f, 255.f)); float delta = pos * 256.0 - float(index); return LookupLightingLUT(lut_index, index, delta); } float LookupLightingLUTSigned(int lut_index, float pos) { - int index = clamp(int(pos * 128.0), -128, 127); + int index = int(clamp(floor(pos * 128.0), -128.f, 127.f)); float delta = pos * 128.0 - float(index); if (index < 0) index += 256; return LookupLightingLUT(lut_index, index, delta); diff --git a/src/video_core/renderer_vulkan/vk_shader_gen.cpp b/src/video_core/renderer_vulkan/vk_shader_gen.cpp index 555b17b5b..8ad0eb4d8 100644 --- a/src/video_core/renderer_vulkan/vk_shader_gen.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_gen.cpp @@ -1247,13 +1247,13 @@ float LookupLightingLUT(int lut_index, int index, float delta) { } float LookupLightingLUTUnsigned(int lut_index, float pos) { - int index = clamp(int(pos * 256.0), 0, 255); + int index = int(clamp(floor(pos * 256.0), 0.f, 255.f)); float delta = pos * 256.0 - float(index); return LookupLightingLUT(lut_index, index, delta); } float LookupLightingLUTSigned(int lut_index, float pos) { - int index = clamp(int(pos * 128.0), -128, 127); + int index = int(clamp(floor(pos * 128.0), -128.f, 127.f)); float delta = pos * 128.0 - float(index); if (index < 0) index += 256; return LookupLightingLUT(lut_index, index, delta); diff --git a/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp b/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp index 0b9647e3f..cf26a927f 100644 --- a/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp @@ -291,16 +291,18 @@ void FragmentModule::WriteLighting() { } const auto lookup_lighting_lut_unsigned = [this](Id lut_index, Id pos) -> Id { - const Id pos_int{OpConvertFToS(i32_id, OpFMul(f32_id, pos, ConstF32(256.f)))}; - const Id index{OpSClamp(i32_id, pos_int, ConstS32(0), ConstS32(255))}; + const Id pos_floor{OpFloor(f32_id, OpFMul(f32_id, pos, ConstF32(256.f)))}; + const Id index_float{OpFClamp(f32_id, pos_floor, ConstF32(0.f), ConstF32(255.f))}; + const Id index{OpConvertFToS(i32_id, index_float)}; const Id neg_index{OpFNegate(f32_id, OpConvertSToF(f32_id, index))}; const Id delta{OpFma(f32_id, pos, ConstF32(256.f), neg_index)}; return LookupLightingLUT(lut_index, index, delta); }; const auto lookup_lighting_lut_signed = [this](Id lut_index, Id pos) -> Id { - const Id pos_int{OpConvertFToS(i32_id, OpFMul(f32_id, pos, ConstF32(128.f)))}; - const Id index{OpSClamp(i32_id, pos_int, ConstS32(-128), ConstS32(127))}; + const Id pos_floor{OpFloor(f32_id, OpFMul(f32_id, pos, ConstF32(128.f)))}; + const Id index_float{OpFClamp(f32_id, pos_floor, ConstF32(-128.f), ConstF32(127.f))}; + const Id index{OpConvertFToS(i32_id, index_float)}; const Id neg_index{OpFNegate(f32_id, OpConvertSToF(f32_id, index))}; const Id delta{OpFma(f32_id, pos, ConstF32(128.f), neg_index)}; const Id increment{