Browse Source
Merge pull request #1264 from bunnei/fragment-lighting-hw
Merge pull request #1264 from bunnei/fragment-lighting-hw
Fragment lighting support in the HW rendererpull/15/merge
15 changed files with 1167 additions and 160 deletions
-
1src/video_core/CMakeLists.txt
-
10src/video_core/clipper.cpp
-
34src/video_core/command_processor.cpp
-
401src/video_core/pica.h
-
146src/video_core/pica_types.h
-
313src/video_core/renderer_opengl/gl_rasterizer.cpp
-
147src/video_core/renderer_opengl/gl_rasterizer.h
-
219src/video_core/renderer_opengl/gl_shader_gen.cpp
-
2src/video_core/renderer_opengl/gl_shader_util.h
-
8src/video_core/renderer_opengl/gl_state.cpp
-
4src/video_core/renderer_opengl/gl_state.h
-
12src/video_core/renderer_opengl/pica_to_gl.h
-
4src/video_core/renderer_opengl/renderer_opengl.cpp
-
6src/video_core/shader/shader.cpp
-
8src/video_core/shader/shader.h
@ -0,0 +1,146 @@ |
|||
// Copyright 2015 Citra Emulator Project |
|||
// Licensed under GPLv2 or any later version |
|||
// Refer to the license.txt file included. |
|||
|
|||
#pragma once |
|||
|
|||
#include <cstring> |
|||
|
|||
#include "common/common_types.h" |
|||
|
|||
namespace Pica { |
|||
|
|||
/** |
|||
* Template class for converting arbitrary Pica float types to IEEE 754 32-bit single-precision |
|||
* floating point. |
|||
* |
|||
* When decoding, format is as follows: |
|||
* - The first `M` bits are the mantissa |
|||
* - The next `E` bits are the exponent |
|||
* - The last bit is the sign bit |
|||
* |
|||
* @todo Verify on HW if this conversion is sufficiently accurate. |
|||
*/ |
|||
template<unsigned M, unsigned E> |
|||
struct Float { |
|||
public: |
|||
static Float<M, E> FromFloat32(float val) { |
|||
Float<M, E> ret; |
|||
ret.value = val; |
|||
return ret; |
|||
} |
|||
|
|||
static Float<M, E> FromRaw(u32 hex) { |
|||
Float<M, E> res; |
|||
|
|||
const int width = M + E + 1; |
|||
const int bias = 128 - (1 << (E - 1)); |
|||
const int exponent = (hex >> M) & ((1 << E) - 1); |
|||
const unsigned mantissa = hex & ((1 << M) - 1); |
|||
|
|||
if (hex & ((1 << (width - 1)) - 1)) |
|||
hex = ((hex >> (E + M)) << 31) | (mantissa << (23 - M)) | ((exponent + bias) << 23); |
|||
else |
|||
hex = ((hex >> (E + M)) << 31); |
|||
|
|||
std::memcpy(&res.value, &hex, sizeof(float)); |
|||
|
|||
return res; |
|||
} |
|||
|
|||
static Float<M, E> Zero() { |
|||
return FromFloat32(0.f); |
|||
} |
|||
|
|||
// Not recommended for anything but logging |
|||
float ToFloat32() const { |
|||
return value; |
|||
} |
|||
|
|||
Float<M, E> operator * (const Float<M, E>& flt) const { |
|||
if ((this->value == 0.f && !std::isnan(flt.value)) || |
|||
(flt.value == 0.f && !std::isnan(this->value))) |
|||
// PICA gives 0 instead of NaN when multiplying by inf |
|||
return Zero(); |
|||
return Float<M, E>::FromFloat32(ToFloat32() * flt.ToFloat32()); |
|||
} |
|||
|
|||
Float<M, E> operator / (const Float<M, E>& flt) const { |
|||
return Float<M, E>::FromFloat32(ToFloat32() / flt.ToFloat32()); |
|||
} |
|||
|
|||
Float<M, E> operator + (const Float<M, E>& flt) const { |
|||
return Float<M, E>::FromFloat32(ToFloat32() + flt.ToFloat32()); |
|||
} |
|||
|
|||
Float<M, E> operator - (const Float<M, E>& flt) const { |
|||
return Float<M, E>::FromFloat32(ToFloat32() - flt.ToFloat32()); |
|||
} |
|||
|
|||
Float<M, E>& operator *= (const Float<M, E>& flt) { |
|||
if ((this->value == 0.f && !std::isnan(flt.value)) || |
|||
(flt.value == 0.f && !std::isnan(this->value))) |
|||
// PICA gives 0 instead of NaN when multiplying by inf |
|||
*this = Zero(); |
|||
else value *= flt.ToFloat32(); |
|||
return *this; |
|||
} |
|||
|
|||
Float<M, E>& operator /= (const Float<M, E>& flt) { |
|||
value /= flt.ToFloat32(); |
|||
return *this; |
|||
} |
|||
|
|||
Float<M, E>& operator += (const Float<M, E>& flt) { |
|||
value += flt.ToFloat32(); |
|||
return *this; |
|||
} |
|||
|
|||
Float<M, E>& operator -= (const Float<M, E>& flt) { |
|||
value -= flt.ToFloat32(); |
|||
return *this; |
|||
} |
|||
|
|||
Float<M, E> operator - () const { |
|||
return Float<M, E>::FromFloat32(-ToFloat32()); |
|||
} |
|||
|
|||
bool operator < (const Float<M, E>& flt) const { |
|||
return ToFloat32() < flt.ToFloat32(); |
|||
} |
|||
|
|||
bool operator > (const Float<M, E>& flt) const { |
|||
return ToFloat32() > flt.ToFloat32(); |
|||
} |
|||
|
|||
bool operator >= (const Float<M, E>& flt) const { |
|||
return ToFloat32() >= flt.ToFloat32(); |
|||
} |
|||
|
|||
bool operator <= (const Float<M, E>& flt) const { |
|||
return ToFloat32() <= flt.ToFloat32(); |
|||
} |
|||
|
|||
bool operator == (const Float<M, E>& flt) const { |
|||
return ToFloat32() == flt.ToFloat32(); |
|||
} |
|||
|
|||
bool operator != (const Float<M, E>& flt) const { |
|||
return ToFloat32() != flt.ToFloat32(); |
|||
} |
|||
|
|||
private: |
|||
static const unsigned MASK = (1 << (M + E + 1)) - 1; |
|||
static const unsigned MANTISSA_MASK = (1 << M) - 1; |
|||
static const unsigned EXPONENT_MASK = (1 << E) - 1; |
|||
|
|||
// Stored as a regular float, merely for convenience |
|||
// TODO: Perform proper arithmetic on this! |
|||
float value; |
|||
}; |
|||
|
|||
using float24 = Float<16, 7>; |
|||
using float20 = Float<12, 7>; |
|||
using float16 = Float<10, 5>; |
|||
|
|||
} // namespace Pica |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue