| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <array> |
| 7 |
#include <memory> |
| 8 |
#include <string> |
| 9 |
#include <unordered_map> |
| 10 |
|
| 11 |
#include "Common/CommonTypes.h" |
| 12 |
#include "Common/EnumMap.h" |
| 13 |
#include "VideoCommon/CPMemory.h" |
| 14 |
|
| 15 |
class NativeVertexFormat; |
| 16 |
struct PortableVertexDeclaration; |
| 17 |
|
| 18 |
namespace OpcodeDecoder |
| 19 |
{ |
| 20 |
enum class Primitive : u8; |
| 21 |
} |
| 22 |
|
| 23 |
namespace VertexLoaderManager |
| 24 |
{ |
| 25 |
using NativeVertexFormatMap = |
| 26 |
std::unordered_map<PortableVertexDeclaration, std::unique_ptr<NativeVertexFormat>>; |
| 27 |
|
| 28 |
void Init(); |
| 29 |
void Clear(); |
| 30 |
|
| 31 |
void MarkAllDirty(); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
NativeVertexFormat* GetOrCreateMatchingFormat(const PortableVertexDeclaration& decl); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
NativeVertexFormat* GetUberVertexFormat(const PortableVertexDeclaration& decl); |
| 42 |
|
| 43 |
|
| 44 |
template <bool IsPreprocess = false> |
| 45 |
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, const u8* src); |
| 46 |
|
| 47 |
namespace detail |
| 48 |
{ |
| 49 |
|
| 50 |
|
| 51 |
template <bool IsPreprocess = false> |
| 52 |
VertexLoaderBase* GetOrCreateLoader(int vtx_attr_group); |
| 53 |
} |
| 54 |
|
| 55 |
NativeVertexFormat* GetCurrentVertexFormat(); |
| 56 |
|
| 57 |
|
| 58 |
extern Common::EnumMap<u8*, CPArray::TexCoord7> cached_arraybases; |
| 59 |
void UpdateVertexArrayPointers(); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
extern std::array<std::array<float, 4>, 3> position_cache; |
| 64 |
extern std::array<u32, 3> position_matrix_index_cache; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
extern std::array<float, 4> normal_cache; |
| 69 |
|
| 70 |
|
| 71 |
extern std::array<float, 4> tangent_cache; |
| 72 |
extern std::array<float, 4> binormal_cache; |
| 73 |
|
| 74 |
|
| 75 |
extern u32 g_current_components; |
| 76 |
|
| 77 |
extern BitSet8 g_main_vat_dirty; |
| 78 |
extern BitSet8 g_preprocess_vat_dirty; |
| 79 |
extern bool g_bases_dirty; |
| 80 |
extern std::array<VertexLoaderBase*, CP_NUM_VAT_REG> g_main_vertex_loaders; |
| 81 |
extern std::array<VertexLoaderBase*, CP_NUM_VAT_REG> g_preprocess_vertex_loaders; |
| 82 |
extern bool g_needs_cp_xf_consistency_check; |
| 83 |
|
| 84 |
template <bool IsPreprocess = false> |
| 85 |
VertexLoaderBase* RefreshLoader(int vtx_attr_group) |
| 86 |
{ |
| 87 |
constexpr const BitSet8& attr_dirty = IsPreprocess ? g_preprocess_vat_dirty : g_main_vat_dirty; |
| 88 |
constexpr const auto& vertex_loaders = |
| 89 |
IsPreprocess ? g_preprocess_vertex_loaders : g_main_vertex_loaders; |
| 90 |
|
| 91 |
VertexLoaderBase* loader; |
| 92 |
if (!attr_dirty[vtx_attr_group]) [[likely]] |
| 93 |
{ |
| 94 |
loader = vertex_loaders[vtx_attr_group]; |
| 95 |
} |
| 96 |
else [[unlikely]] |
| 97 |
{ |
| 98 |
loader = detail::GetOrCreateLoader<IsPreprocess>(vtx_attr_group); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
if constexpr (!IsPreprocess) |
| 103 |
UpdateVertexArrayPointers(); |
| 104 |
|
| 105 |
return loader; |
| 106 |
} |
| 107 |
|
| 108 |
} |