| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <algorithm> |
| 7 |
#include <bit> |
| 8 |
|
| 9 |
#include "Common/BitUtils.h" |
| 10 |
#include "Common/CommonTypes.h" |
| 11 |
|
| 12 |
#include "VideoCommon/BPMemory.h" |
| 13 |
|
| 14 |
|
| 15 |
constexpr u32 EFB_WIDTH = 640u; |
| 16 |
constexpr u32 EFB_HEIGHT = 528u; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
constexpr float MAX_EFB_DEPTH = 16777215.0f / 16777216.0f; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
constexpr u32 MAX_XFB_WIDTH = 720u; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
constexpr u32 MAX_XFB_HEIGHT = 576u; |
| 33 |
|
| 34 |
#define PRIM_LOG(t, ...) DEBUG_LOG_FMT(VIDEO, t __VA_OPT__(, ) __VA_ARGS__) |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#define LOG_VTX() |
| 43 |
|
| 44 |
enum class APIType |
| 45 |
{ |
| 46 |
OpenGL, |
| 47 |
D3D, |
| 48 |
Vulkan, |
| 49 |
Metal, |
| 50 |
Nothing |
| 51 |
}; |
| 52 |
|
| 53 |
inline u32 RGBA8ToRGBA6ToRGBA8(u32 src) |
| 54 |
{ |
| 55 |
u32 color = src; |
| 56 |
color &= 0xFCFCFCFC; |
| 57 |
color |= (color >> 6) & 0x03030303; |
| 58 |
return color; |
| 59 |
} |
| 60 |
|
| 61 |
inline u32 RGBA8ToRGB565ToRGBA8(u32 src) |
| 62 |
{ |
| 63 |
u32 color = (src & 0xF8FCF8); |
| 64 |
color |= (color >> 5) & 0x070007; |
| 65 |
color |= (color >> 6) & 0x000300; |
| 66 |
color |= 0xFF000000; |
| 67 |
return color; |
| 68 |
} |
| 69 |
|
| 70 |
inline u32 Z24ToZ16ToZ24(u32 src) |
| 71 |
{ |
| 72 |
return (src & 0xFFFF00) | (src >> 16); |
| 73 |
} |
| 74 |
|
| 75 |
inline u32 CompressZ16(u32 z24depth, DepthFormat format) |
| 76 |
{ |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
if (format == DepthFormat::ZLINEAR) |
| 81 |
{ |
| 82 |
|
| 83 |
return z24depth >> 8; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
u32 leading_ones = static_cast<u32>(std::countl_one(z24depth << 8)); |
| 93 |
bool next_bit_is_one = false; |
| 94 |
u32 exp_bits; |
| 95 |
|
| 96 |
switch (format) |
| 97 |
{ |
| 98 |
case DepthFormat::ZNEAR: |
| 99 |
exp_bits = 2; |
| 100 |
if (leading_ones >= 3u) |
| 101 |
{ |
| 102 |
leading_ones = 3u; |
| 103 |
next_bit_is_one = true; |
| 104 |
} |
| 105 |
break; |
| 106 |
case DepthFormat::ZMID: |
| 107 |
exp_bits = 3; |
| 108 |
if (leading_ones >= 7u) |
| 109 |
{ |
| 110 |
leading_ones = 7u; |
| 111 |
next_bit_is_one = true; |
| 112 |
} |
| 113 |
break; |
| 114 |
case DepthFormat::ZFAR: |
| 115 |
exp_bits = 4; |
| 116 |
if (leading_ones >= 12u) |
| 117 |
{ |
| 118 |
|
| 119 |
leading_ones = 12u; |
| 120 |
next_bit_is_one = true; |
| 121 |
} |
| 122 |
break; |
| 123 |
default: |
| 124 |
return z24depth >> 8; |
| 125 |
} |
| 126 |
|
| 127 |
u32 mantissa_bits = 16 - exp_bits; |
| 128 |
|
| 129 |
|
| 130 |
u32 top = std::max<u32>(24 - leading_ones, mantissa_bits); |
| 131 |
if (!next_bit_is_one) |
| 132 |
{ |
| 133 |
top -= 1; |
| 134 |
} |
| 135 |
u32 bottom = top - mantissa_bits; |
| 136 |
|
| 137 |
u32 exponent = leading_ones << mantissa_bits; |
| 138 |
u32 mantissa = Common::ExtractBits(z24depth, bottom, top - 1); |
| 139 |
|
| 140 |
return exponent | mantissa; |
| 141 |
} |