diff options
author | bunnei <bunneidev@gmail.com> | 2015-09-10 04:39:43 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2016-02-05 23:17:28 +0100 |
commit | b0030755708849eb27fe2bf1cc481c5ab905468e (patch) | |
tree | 966520312f4a1db78c4d36181782793d5ee62ce2 /src/video_core/pica_types.h | |
parent | pica: Implement fragment lighting LUTs. (diff) | |
download | yuzu-b0030755708849eb27fe2bf1cc481c5ab905468e.tar yuzu-b0030755708849eb27fe2bf1cc481c5ab905468e.tar.gz yuzu-b0030755708849eb27fe2bf1cc481c5ab905468e.tar.bz2 yuzu-b0030755708849eb27fe2bf1cc481c5ab905468e.tar.lz yuzu-b0030755708849eb27fe2bf1cc481c5ab905468e.tar.xz yuzu-b0030755708849eb27fe2bf1cc481c5ab905468e.tar.zst yuzu-b0030755708849eb27fe2bf1cc481c5ab905468e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/pica_types.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/video_core/pica_types.h b/src/video_core/pica_types.h index de798aa81..a34421c5d 100644 --- a/src/video_core/pica_types.h +++ b/src/video_core/pica_types.h @@ -121,4 +121,60 @@ private: static_assert(sizeof(float24) == sizeof(float), "Shader JIT assumes float24 is implemented as a 32-bit float"); +struct float16 { + // 10 bit mantissa, 5 bit exponent, 1 bit sign + // TODO: No idea if this works as intended + static float16 FromRawFloat16(u32 hex) { + float16 ret; + if ((hex & 0xFFFF) == 0) { + ret.value = 0; + } else { + u32 mantissa = hex & 0x3FF; + u32 exponent = (hex >> 10) & 0x1F; + u32 sign = (hex >> 15) & 1; + ret.value = std::pow(2.0f, (float)exponent - 15.0f) * (1.0f + mantissa * std::pow(2.0f, -10.f)); + if (sign) + ret.value = -ret.value; + } + return ret; + } + + float ToFloat32() const { + return value; + } + +private: + // Stored as a regular float, merely for convenience + // TODO: Perform proper arithmetic on this! + float value; +}; + +struct float20 { + // 12 bit mantissa, 7 bit exponent, 1 bit sign + // TODO: No idea if this works as intended + static float20 FromRawFloat20(u32 hex) { + float20 ret; + if ((hex & 0xFFFFF) == 0) { + ret.value = 0; + } else { + u32 mantissa = hex & 0xFFF; + u32 exponent = (hex >> 12) & 0x7F; + u32 sign = (hex >> 19) & 1; + ret.value = std::pow(2.0f, (float)exponent - 63.0f) * (1.0f + mantissa * std::pow(2.0f, -12.f)); + if (sign) + ret.value = -ret.value; + } + return ret; + } + + float ToFloat32() const { + return value; + } + +private: + // Stored as a regular float, merely for convenience + // TODO: Perform proper arithmetic on this! + float value; +}; + } // namespace Pica |