From 7bc467e8725c6751eb44ea45ff2203af8692cda1 Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 28 Jun 2017 12:34:16 -0500 Subject: SwRasterizer/Lighting: Do not use global state in LookupLightingLut. --- src/video_core/pica_state.h | 2 +- src/video_core/swrasterizer/rasterizer.cpp | 33 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/video_core/pica_state.h b/src/video_core/pica_state.h index 2d23d34e6..864a2c9e6 100644 --- a/src/video_core/pica_state.h +++ b/src/video_core/pica_state.h @@ -79,7 +79,7 @@ struct State { std::array color_diff_table; } proctex; - struct { + struct Lighting { union LutEntry { // Used for raw access u32 raw; diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index 48ed8ccbf..b69f7b692 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp @@ -115,12 +115,15 @@ static std::tuple ConvertCubeCoord(float24 u, float24 v return std::make_tuple(x / z * half + half, y / z * half + half, addr); } -float LookupLightingLut(size_t lut_index, u8 index, float delta) { - ASSERT_MSG(lut_index < g_state.lighting.luts.size(), "Out of range lut"); - ASSERT_MSG(index < g_state.lighting.luts[0].size(), "Out of range index"); +static float LookupLightingLut(const Pica::State::Lighting& lighting, size_t lut_index, u8 index, + float delta) { + ASSERT_MSG(lut_index < lighting.luts.size(), "Out of range lut"); + ASSERT_MSG(index < lighting.luts[0].size(), "Out of range index"); - float lut_value = g_state.lighting.luts[lut_index][index].ToFloat(); - float lut_diff = g_state.lighting.luts[lut_index][index].DiffToFloat(); + const auto& lut = lighting.luts[lut_index][index]; + + float lut_value = lut.ToFloat(); + float lut_diff = lut.DiffToFloat(); return lut_value + lut_diff * delta; } @@ -184,7 +187,7 @@ std::tuple, Math::Vec4> ComputeFragmentsColors( u8 lutindex = static_cast(MathUtil::Clamp(std::floor(sample_loc * 256.f), 0.0f, 255.0f)); float delta = sample_loc * 256 - lutindex; - dist_atten = LookupLightingLut(lut, lutindex, delta); + dist_atten = LookupLightingLut(g_state.lighting, lut, lutindex, delta); } float clamp_highlights = 1.0f; @@ -260,7 +263,8 @@ std::tuple, Math::Vec4> ComputeFragmentsColors( d0_lut_value = scale * - LookupLightingLut(static_cast(LightingRegs::LightingSampler::Distribution0), + LookupLightingLut(g_state.lighting, + static_cast(LightingRegs::LightingSampler::Distribution0), index, delta); } @@ -280,7 +284,8 @@ std::tuple, Math::Vec4> ComputeFragmentsColors( refl_value.x = scale * - LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectRed), + LookupLightingLut(g_state.lighting, + static_cast(LightingRegs::LightingSampler::ReflectRed), index, delta); } else { refl_value.x = 1.0f; @@ -300,7 +305,8 @@ std::tuple, Math::Vec4> ComputeFragmentsColors( refl_value.y = scale * - LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectGreen), + LookupLightingLut(g_state.lighting, + static_cast(LightingRegs::LightingSampler::ReflectGreen), index, delta); } else { refl_value.y = refl_value.x; @@ -320,7 +326,8 @@ std::tuple, Math::Vec4> ComputeFragmentsColors( refl_value.z = scale * - LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectBlue), + LookupLightingLut(g_state.lighting, + static_cast(LightingRegs::LightingSampler::ReflectBlue), index, delta); } else { refl_value.z = refl_value.x; @@ -341,7 +348,8 @@ std::tuple, Math::Vec4> ComputeFragmentsColors( d1_lut_value = scale * - LookupLightingLut(static_cast(LightingRegs::LightingSampler::Distribution1), + LookupLightingLut(g_state.lighting, + static_cast(LightingRegs::LightingSampler::Distribution1), index, delta); } @@ -362,7 +370,8 @@ std::tuple, Math::Vec4> ComputeFragmentsColors( float lut_value = scale * - LookupLightingLut(static_cast(LightingRegs::LightingSampler::Fresnel), + LookupLightingLut(g_state.lighting, + static_cast(LightingRegs::LightingSampler::Fresnel), index, delta); // Enabled for diffuse lighting alpha component -- cgit v1.2.3