2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-06-22 09:31:30 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/BPMemory.h"
|
2009-06-22 09:31:30 +00:00
|
|
|
|
2022-08-06 04:10:17 +00:00
|
|
|
#include <bit>
|
2017-01-23 20:48:14 +00:00
|
|
|
|
2009-07-26 09:52:35 +00:00
|
|
|
// BP state
|
2009-06-22 09:31:30 +00:00
|
|
|
// STATE_TO_SAVE
|
|
|
|
BPMemory bpmem;
|
2017-01-23 20:48:14 +00:00
|
|
|
|
2017-09-03 06:32:37 +00:00
|
|
|
bool BlendMode::UseLogicOp() const
|
|
|
|
{
|
2023-11-12 05:47:22 +00:00
|
|
|
// Blending overrides the logicop bit.
|
|
|
|
if (blendenable || !logicopenable)
|
2017-09-03 06:32:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Fast path for Kirby's Return to Dreamland, they use it with dstAlpha.
|
2021-02-11 02:11:31 +00:00
|
|
|
if (logicmode == LogicOp::NoOp)
|
2017-09-03 06:32:37 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-01 07:36:30 +00:00
|
|
|
bool FogParams::IsNaNCase() const
|
2017-01-23 20:48:14 +00:00
|
|
|
{
|
2018-02-01 07:36:30 +00:00
|
|
|
// Check for the case where both a and c are infinity or NaN.
|
|
|
|
// On hardware, this results in the following colors:
|
|
|
|
//
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// | A | C | Result | A | C | Result |
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// | inf | inf | Fogged | inf | nan | Fogged |
|
|
|
|
// | inf | -inf | Unfogged | inf | -nan | Unfogged |
|
|
|
|
// | -inf | inf | Unfogged | -inf | nan | Unfogged |
|
|
|
|
// | -inf | -inf | Unfogged | -inf | -nan | Unfogged |
|
|
|
|
// -------------------------------------------------------
|
|
|
|
// | nan | inf | Fogged | nan | nan | Fogged |
|
|
|
|
// | nan | -inf | Unfogged | nan | -nan | Unfogged |
|
|
|
|
// | -nan | inf | Unfogged | -nan | nan | Unfogged |
|
|
|
|
// | -nan | -inf | Unfogged | -nan | -nan | Unfogged |
|
|
|
|
// -------------------------------------------------------
|
|
|
|
//
|
|
|
|
// We replicate this by returning A=0, and C=inf for the inf/inf case, otherwise -inf.
|
|
|
|
// This ensures we do not pass a NaN to the GPU, and -inf/inf clamp to 0/1 respectively.
|
|
|
|
return a.exp == 255 && c_proj_fsel.c_exp == 255;
|
|
|
|
}
|
|
|
|
|
2021-02-12 06:38:07 +00:00
|
|
|
float FogParam0::FloatValue() const
|
|
|
|
{
|
|
|
|
// scale mantissa from 11 to 23 bits
|
|
|
|
const u32 integral = (sign << 31) | (exp << 23) | (mant << 12);
|
2022-08-06 04:10:17 +00:00
|
|
|
return std::bit_cast<float>(integral);
|
2021-02-12 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float FogParam3::FloatValue() const
|
|
|
|
{
|
|
|
|
// scale mantissa from 11 to 23 bits
|
|
|
|
const u32 integral = (c_sign << 31) | (c_exp << 23) | (c_mant << 12);
|
2022-08-06 04:10:17 +00:00
|
|
|
return std::bit_cast<float>(integral);
|
2021-02-12 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 07:36:30 +00:00
|
|
|
float FogParams::GetA() const
|
|
|
|
{
|
|
|
|
if (IsNaNCase())
|
|
|
|
return 0.0f;
|
|
|
|
|
2021-02-12 06:38:07 +00:00
|
|
|
return a.FloatValue();
|
2017-01-23 20:48:14 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 07:36:30 +00:00
|
|
|
float FogParams::GetC() const
|
2017-01-23 20:48:14 +00:00
|
|
|
{
|
2018-02-01 07:36:30 +00:00
|
|
|
if (IsNaNCase())
|
|
|
|
{
|
|
|
|
constexpr float inf = std::numeric_limits<float>::infinity();
|
|
|
|
return !a.sign && !c_proj_fsel.c_sign ? -inf : inf;
|
|
|
|
}
|
|
|
|
|
2021-02-12 06:38:07 +00:00
|
|
|
return c_proj_fsel.FloatValue();
|
2017-01-23 20:48:14 +00:00
|
|
|
}
|