| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include "Common/BitField.h" |
| 7 |
#include "Common/CommonTypes.h" |
| 8 |
|
| 9 |
struct BPMemory; |
| 10 |
|
| 11 |
enum class AbstractTextureFormat : u32; |
| 12 |
|
| 13 |
enum class CompareMode : u32; |
| 14 |
enum class CullMode : u32; |
| 15 |
enum class DstBlendFactor : u32; |
| 16 |
enum class FilterMode : u32; |
| 17 |
enum class LODType : u32; |
| 18 |
enum class LogicOp : u32; |
| 19 |
enum class PixelFormat : u32; |
| 20 |
enum class SrcBlendFactor : u32; |
| 21 |
enum class WrapMode : u32; |
| 22 |
|
| 23 |
enum class PrimitiveType : u32 |
| 24 |
{ |
| 25 |
Points, |
| 26 |
Lines, |
| 27 |
Triangles, |
| 28 |
TriangleStrip, |
| 29 |
}; |
| 30 |
|
| 31 |
union RasterizationState |
| 32 |
{ |
| 33 |
void Generate(const BPMemory& bp, PrimitiveType primitive_type); |
| 34 |
|
| 35 |
RasterizationState() = default; |
| 36 |
RasterizationState(const RasterizationState&) = default; |
| 37 |
RasterizationState& operator=(const RasterizationState& rhs) |
| 38 |
{ |
| 39 |
hex = rhs.hex; |
| 40 |
return *this; |
| 41 |
} |
| 42 |
RasterizationState(RasterizationState&&) = default; |
| 43 |
RasterizationState& operator=(RasterizationState&& rhs) |
| 44 |
{ |
| 45 |
hex = rhs.hex; |
| 46 |
return *this; |
| 47 |
} |
| 48 |
|
| 49 |
bool operator==(const RasterizationState& rhs) const { return hex == rhs.hex; } |
| 50 |
bool operator<(const RasterizationState& rhs) const { return hex < rhs.hex; } |
| 51 |
|
| 52 |
BitField<0, 2, CullMode> cull_mode; |
| 53 |
BitField<3, 2, PrimitiveType> primitive; |
| 54 |
|
| 55 |
u32 hex = 0; |
| 56 |
}; |
| 57 |
|
| 58 |
union FramebufferState |
| 59 |
{ |
| 60 |
FramebufferState() = default; |
| 61 |
FramebufferState(const FramebufferState&) = default; |
| 62 |
FramebufferState& operator=(const FramebufferState& rhs) |
| 63 |
{ |
| 64 |
hex = rhs.hex; |
| 65 |
return *this; |
| 66 |
} |
| 67 |
FramebufferState(FramebufferState&&) = default; |
| 68 |
FramebufferState& operator=(FramebufferState&& rhs) |
| 69 |
{ |
| 70 |
hex = rhs.hex; |
| 71 |
return *this; |
| 72 |
} |
| 73 |
|
| 74 |
bool operator==(const FramebufferState& rhs) const { return hex == rhs.hex; } |
| 75 |
|
| 76 |
BitField<0, 8, AbstractTextureFormat> color_texture_format; |
| 77 |
BitField<8, 8, AbstractTextureFormat> depth_texture_format; |
| 78 |
BitField<16, 8, u32> samples; |
| 79 |
BitField<24, 1, u32> per_sample_shading; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
BitField<25, 3, u32> additional_color_attachment_count; |
| 86 |
|
| 87 |
u32 hex = 0; |
| 88 |
}; |
| 89 |
|
| 90 |
union DepthState |
| 91 |
{ |
| 92 |
void Generate(const BPMemory& bp); |
| 93 |
|
| 94 |
DepthState() = default; |
| 95 |
DepthState(const DepthState&) = default; |
| 96 |
DepthState& operator=(const DepthState& rhs) |
| 97 |
{ |
| 98 |
hex = rhs.hex; |
| 99 |
return *this; |
| 100 |
} |
| 101 |
DepthState(DepthState&&) = default; |
| 102 |
DepthState& operator=(DepthState&& rhs) |
| 103 |
{ |
| 104 |
hex = rhs.hex; |
| 105 |
return *this; |
| 106 |
} |
| 107 |
|
| 108 |
bool operator==(const DepthState& rhs) const { return hex == rhs.hex; } |
| 109 |
bool operator<(const DepthState& rhs) const { return hex < rhs.hex; } |
| 110 |
|
| 111 |
BitField<0, 1, u32> test_enable; |
| 112 |
BitField<1, 1, u32> update_enable; |
| 113 |
BitField<2, 3, CompareMode> func; |
| 114 |
|
| 115 |
u32 hex = 0; |
| 116 |
}; |
| 117 |
|
| 118 |
union BlendingState |
| 119 |
{ |
| 120 |
void Generate(const BPMemory& bp); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
void ApproximateLogicOpWithBlending(); |
| 125 |
bool LogicOpApproximationIsExact(); |
| 126 |
bool LogicOpApproximationWantsShaderHelp(); |
| 127 |
|
| 128 |
BlendingState() = default; |
| 129 |
BlendingState(const BlendingState&) = default; |
| 130 |
BlendingState& operator=(const BlendingState& rhs) |
| 131 |
{ |
| 132 |
hex = rhs.hex; |
| 133 |
return *this; |
| 134 |
} |
| 135 |
BlendingState(BlendingState&&) = default; |
| 136 |
BlendingState& operator=(BlendingState&& rhs) |
| 137 |
{ |
| 138 |
hex = rhs.hex; |
| 139 |
return *this; |
| 140 |
} |
| 141 |
|
| 142 |
bool operator==(const BlendingState& rhs) const { return hex == rhs.hex; } |
| 143 |
bool operator<(const BlendingState& rhs) const { return hex < rhs.hex; } |
| 144 |
|
| 145 |
BitField<0, 1, u32> blend_enable; |
| 146 |
BitField<1, 1, u32> logic_op_enable; |
| 147 |
BitField<3, 1, u32> color_update; |
| 148 |
BitField<4, 1, u32> alpha_update; |
| 149 |
BitField<5, 1, u32> subtract; |
| 150 |
BitField<6, 1, u32> subtract_alpha; |
| 151 |
BitField<7, 1, u32> use_dual_src; |
| 152 |
BitField<8, 3, DstBlendFactor> dst_factor; |
| 153 |
BitField<11, 3, SrcBlendFactor> src_factor; |
| 154 |
BitField<14, 3, DstBlendFactor> dst_factor_alpha; |
| 155 |
BitField<17, 3, SrcBlendFactor> src_factor_alpha; |
| 156 |
BitField<20, 4, LogicOp> logic_mode; |
| 157 |
|
| 158 |
bool RequiresDualSrc() const; |
| 159 |
|
| 160 |
u32 hex = 0; |
| 161 |
}; |
| 162 |
|
| 163 |
struct SamplerState |
| 164 |
{ |
| 165 |
void Generate(const BPMemory& bp, u32 index); |
| 166 |
|
| 167 |
SamplerState() = default; |
| 168 |
SamplerState(const SamplerState&) = default; |
| 169 |
SamplerState& operator=(const SamplerState& rhs) |
| 170 |
{ |
| 171 |
tm0.hex = rhs.tm0.hex; |
| 172 |
tm1.hex = rhs.tm1.hex; |
| 173 |
return *this; |
| 174 |
} |
| 175 |
SamplerState(SamplerState&&) = default; |
| 176 |
SamplerState& operator=(SamplerState&& rhs) |
| 177 |
{ |
| 178 |
tm0.hex = rhs.tm0.hex; |
| 179 |
tm1.hex = rhs.tm1.hex; |
| 180 |
return *this; |
| 181 |
} |
| 182 |
|
| 183 |
bool operator==(const SamplerState& rhs) const { return Hex() == rhs.Hex(); } |
| 184 |
bool operator<(const SamplerState& rhs) const { return Hex() < rhs.Hex(); } |
| 185 |
|
| 186 |
constexpr u64 Hex() const { return tm0.hex | (static_cast<u64>(tm1.hex) << 32); } |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
union TM0 |
| 191 |
{ |
| 192 |
|
| 193 |
|
| 194 |
BitField<0, 1, FilterMode> min_filter; |
| 195 |
BitField<1, 1, FilterMode> mag_filter; |
| 196 |
BitField<2, 1, FilterMode> mipmap_filter; |
| 197 |
|
| 198 |
BitField<3, 2, WrapMode> wrap_u; |
| 199 |
BitField<5, 2, WrapMode> wrap_v; |
| 200 |
BitField<7, 1, LODType> diag_lod; |
| 201 |
BitField<8, 16, s32> lod_bias; |
| 202 |
BitField<24, 1, bool, u32> lod_clamp; |
| 203 |
BitField<25, 4, u32> anisotropic_filtering; |
| 204 |
u32 hex = 0; |
| 205 |
}; |
| 206 |
union TM1 |
| 207 |
{ |
| 208 |
|
| 209 |
BitField<0, 8, u32> min_lod; |
| 210 |
BitField<8, 8, u32> max_lod; |
| 211 |
u32 hex = 0; |
| 212 |
}; |
| 213 |
|
| 214 |
TM0 tm0; |
| 215 |
TM1 tm1; |
| 216 |
}; |
| 217 |
|
| 218 |
template <> |
| 219 |
struct std::hash<SamplerState> |
| 220 |
{ |
| 221 |
std::size_t operator()(const SamplerState& state) const noexcept |
| 222 |
{ |
| 223 |
return std::hash<u64>{}(state.Hex()); |
| 224 |
} |
| 225 |
}; |
| 226 |
|
| 227 |
namespace RenderState |
| 228 |
{ |
| 229 |
RasterizationState GetInvalidRasterizationState(); |
| 230 |
RasterizationState GetNoCullRasterizationState(PrimitiveType primitive); |
| 231 |
RasterizationState GetCullBackFaceRasterizationState(PrimitiveType primitive); |
| 232 |
DepthState GetInvalidDepthState(); |
| 233 |
DepthState GetNoDepthTestingDepthState(); |
| 234 |
DepthState GetAlwaysWriteDepthState(); |
| 235 |
BlendingState GetInvalidBlendingState(); |
| 236 |
BlendingState GetNoBlendingBlendState(); |
| 237 |
BlendingState GetNoColorWriteBlendState(); |
| 238 |
SamplerState GetInvalidSamplerState(); |
| 239 |
SamplerState GetPointSamplerState(); |
| 240 |
SamplerState GetLinearSamplerState(); |
| 241 |
FramebufferState GetColorFramebufferState(AbstractTextureFormat format); |
| 242 |
FramebufferState GetRGBA8FramebufferState(); |
| 243 |
} |