From 2d69a9b8bf232fdd9e3bbb2a9c624ee9dd6ec637 Mon Sep 17 00:00:00 2001 From: Subv Date: Tue, 13 Jun 2017 12:31:28 -0500 Subject: [PATCH] SwRasterizer: Run clang-format --- src/video_core/swrasterizer/rasterizer.cpp | 128 +++++++++++++-------- 1 file changed, 83 insertions(+), 45 deletions(-) diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index 76f793c86..382b5927b 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp @@ -125,11 +125,12 @@ float LookupLightingLut(size_t lut_index, u8 index, float delta) { return lut_value + lut_diff * delta; } -std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Quaternion& normquat, const Math::Vec3& view) { +std::tuple, Math::Vec4> ComputeFragmentsColors( + const Math::Quaternion& normquat, const Math::Vec3& view) { const auto& lighting = g_state.regs.lighting; if (lighting.disable) - return {{}, {}}; + return {Math::MakeVec(0, 0, 0, 0), Math::MakeVec(0, 0, 0, 0)}; // TODO(Subv): Bump mapping Math::Vec3 surface_normal = {0.0f, 0.0f, 1.0f}; @@ -151,7 +152,9 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu unsigned num = lighting.light_enable.GetNum(light_index); const auto& light_config = g_state.regs.lighting.light[num]; - Math::Vec3 position = {float16::FromRaw(light_config.x).ToFloat32(), float16::FromRaw(light_config.y).ToFloat32(), float16::FromRaw(light_config.z).ToFloat32()}; + Math::Vec3 position = {float16::FromRaw(light_config.x).ToFloat32(), + float16::FromRaw(light_config.y).ToFloat32(), + float16::FromRaw(light_config.z).ToFloat32()}; if (light_config.config.directional) light_vector = position; @@ -173,11 +176,13 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu auto distance = (-view - position).Length(); float scale = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32(); float bias = Pica::float20::FromRaw(light_config.dist_atten_scale).ToFloat32(); - size_t lut = static_cast(LightingRegs::LightingSampler::DistanceAttenuation) + num; + size_t lut = + static_cast(LightingRegs::LightingSampler::DistanceAttenuation) + num; float sample_loc = scale * distance + bias; - u8 lutindex = MathUtil::Clamp(std::floor(sample_loc * 256.f), 0.0f, 255.0f); + 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); } @@ -192,7 +197,7 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu } auto GetLutIndex = [&](unsigned num, LightingRegs::LightingLutInput input, - bool abs) -> std::tuple { + bool abs) -> std::tuple { Math::Vec3 norm_view = view.Normalized(); Math::Vec3 half_angle = (norm_view + light_vector).Normalized(); @@ -216,7 +221,7 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu break; default: - LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %d\n", (int)input); + LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast(input)); UNIMPLEMENTED(); result = 0.f; } @@ -227,14 +232,15 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu else result = std::max(result, 0.0f); - u8 lutindex = MathUtil::Clamp(std::floor(result * 256.f), 0.0f, 255.0f); + float flr = std::floor(result * 256.f); + u8 lutindex = static_cast(MathUtil::Clamp(flr, 0.0f, 255.0f)); float delta = result * 256 - lutindex; - return { lutindex, delta }; + return {lutindex, delta}; } else { float flr = std::floor(result * 128.f); - s8 tmpi = MathUtil::Clamp(flr, -128.0f, 127.0f); - float delta = result * 128.f - tmpi; - return { tmpi & 0xFF, delta }; + s8 lutindex = static_cast(MathUtil::Clamp(flr, -128.0f, 127.0f)); + float delta = result * 128.f - lutindex; + return {static_cast(lutindex), delta}; } }; @@ -247,11 +253,15 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu // Lookup specular "distribution 0" LUT value u8 index; float delta; - std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d0.Value(), lighting.abs_lut_input.disable_d0 == 0); + std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d0.Value(), + lighting.abs_lut_input.disable_d0 == 0); float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d0); - d0_lut_value = scale * LookupLightingLut(static_cast(LightingRegs::LightingSampler::Distribution0), index, delta); + d0_lut_value = + scale * + LookupLightingLut(static_cast(LightingRegs::LightingSampler::Distribution0), + index, delta); } Math::Vec3 specular_0 = d0_lut_value * light_config.specular_0.ToVec3f(); @@ -263,11 +273,15 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu u8 index; float delta; - std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0); + std::tie(index, delta) = + GetLutIndex(num, lighting.lut_input.rr, lighting.abs_lut_input.disable_rr == 0); float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rr); - refl_value.x = scale * LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectRed), index, delta); + refl_value.x = + scale * + LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectRed), + index, delta); } else { refl_value.x = 1.0f; } @@ -279,11 +293,15 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu u8 index; float delta; - std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0); + std::tie(index, delta) = + GetLutIndex(num, lighting.lut_input.rg, lighting.abs_lut_input.disable_rg == 0); float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rg); - refl_value.y = scale * LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectGreen), index, delta); + refl_value.y = + scale * + LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectGreen), + index, delta); } else { refl_value.y = refl_value.x; } @@ -295,11 +313,15 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu u8 index; float delta; - std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0); + std::tie(index, delta) = + GetLutIndex(num, lighting.lut_input.rb, lighting.abs_lut_input.disable_rb == 0); float scale = lighting.lut_scale.GetScale(lighting.lut_scale.rb); - refl_value.z = scale * LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectBlue), index, delta); + refl_value.z = + scale * + LookupLightingLut(static_cast(LightingRegs::LightingSampler::ReflectBlue), + index, delta); } else { refl_value.z = refl_value.x; } @@ -312,54 +334,72 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu // Lookup specular "distribution 1" LUT value u8 index; float delta; - std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d1.Value(), lighting.abs_lut_input.disable_d1 == 0); + std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.d1.Value(), + lighting.abs_lut_input.disable_d1 == 0); float scale = lighting.lut_scale.GetScale(lighting.lut_scale.d1); - d1_lut_value = scale * LookupLightingLut(static_cast(LightingRegs::LightingSampler::Distribution1), index, delta); + d1_lut_value = + scale * + LookupLightingLut(static_cast(LightingRegs::LightingSampler::Distribution1), + index, delta); } - Math::Vec3 specular_1 = d1_lut_value * refl_value * light_config.specular_1.ToVec3f(); + Math::Vec3 specular_1 = + d1_lut_value * refl_value * light_config.specular_1.ToVec3f(); if (lighting.config1.disable_lut_fr == 0 && - LightingRegs::IsLightingSamplerSupported( - lighting.config0.config, LightingRegs::LightingSampler::Fresnel)) { + LightingRegs::IsLightingSamplerSupported(lighting.config0.config, + LightingRegs::LightingSampler::Fresnel)) { // Lookup fresnel LUT value u8 index; float delta; - std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.fr.Value(), lighting.abs_lut_input.disable_fr == 0); + std::tie(index, delta) = GetLutIndex(num, lighting.lut_input.fr.Value(), + lighting.abs_lut_input.disable_fr == 0); float scale = lighting.lut_scale.GetScale(lighting.lut_scale.fr); - float lut_value = scale * LookupLightingLut(static_cast(LightingRegs::LightingSampler::Fresnel), index, delta); + float lut_value = + scale * + LookupLightingLut(static_cast(LightingRegs::LightingSampler::Fresnel), + index, delta); - // Enabled for difffuse lighting alpha component - if (lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::PrimaryAlpha || + // Enabled for diffuse lighting alpha component + if (lighting.config0.fresnel_selector == + LightingRegs::LightingFresnelSelector::PrimaryAlpha || lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) { diffuse_sum.a() *= lut_value; } // Enabled for the specular lighting alpha component if (lighting.config0.fresnel_selector == - LightingRegs::LightingFresnelSelector::SecondaryAlpha || + LightingRegs::LightingFresnelSelector::SecondaryAlpha || lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) { specular_sum.a() *= lut_value; } } - - auto diffuse = light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); + auto diffuse = + light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f(); diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f); - specular_sum += Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.f); + specular_sum += + Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.f); } diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f); - return { - Math::MakeVec(MathUtil::Clamp(diffuse_sum.x, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.y, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.z, 0.0f, 1.0f) * 255, MathUtil::Clamp(diffuse_sum.w, 0.0f, 1.0f) * 255).Cast(), - Math::MakeVec(MathUtil::Clamp(specular_sum.x, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.y, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255, MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255).Cast() - }; + + return {Math::MakeVec(MathUtil::Clamp(diffuse_sum.x, 0.0f, 1.0f) * 255, + MathUtil::Clamp(diffuse_sum.y, 0.0f, 1.0f) * 255, + MathUtil::Clamp(diffuse_sum.z, 0.0f, 1.0f) * 255, + MathUtil::Clamp(diffuse_sum.w, 0.0f, 1.0f) * 255) + .Cast(), + Math::MakeVec(MathUtil::Clamp(specular_sum.x, 0.0f, 1.0f) * 255, + MathUtil::Clamp(specular_sum.y, 0.0f, 1.0f) * 255, + MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255, + MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255) + .Cast()}; } MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240)); @@ -554,19 +594,16 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve }; Math::Quaternion normquat{ - { - GetInterpolatedAttribute(v0.quat.x, v1.quat.x, v2.quat.x).ToFloat32(), - GetInterpolatedAttribute(v0.quat.y, v1.quat.y, v2.quat.y).ToFloat32(), - GetInterpolatedAttribute(v0.quat.z, v1.quat.z, v2.quat.z).ToFloat32() - }, + {GetInterpolatedAttribute(v0.quat.x, v1.quat.x, v2.quat.x).ToFloat32(), + GetInterpolatedAttribute(v0.quat.y, v1.quat.y, v2.quat.y).ToFloat32(), + GetInterpolatedAttribute(v0.quat.z, v1.quat.z, v2.quat.z).ToFloat32()}, GetInterpolatedAttribute(v0.quat.w, v1.quat.w, v2.quat.w).ToFloat32(), }; Math::Vec3 fragment_position{ GetInterpolatedAttribute(v0.view.x, v1.view.x, v2.view.x).ToFloat32(), GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(), - GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32() - }; + GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32()}; Math::Vec2 uv[3]; uv[0].u() = GetInterpolatedAttribute(v0.tc0.u(), v1.tc0.u(), v2.tc0.u()); @@ -685,7 +722,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve Math::Vec4 primary_fragment_color; Math::Vec4 secondary_fragment_color; - std::tie(primary_fragment_color, secondary_fragment_color) = ComputeFragmentsColors(normquat, fragment_position); + std::tie(primary_fragment_color, secondary_fragment_color) = + ComputeFragmentsColors(normquat, fragment_position); for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size(); ++tev_stage_index) {