Debian Codegraph @

Source/Core/VideoCommon/VertexLoaderBase.h

raw symbols SCIP
1 // Copyright 2014 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 #include "Common/CommonTypes.h"
12 #include "VideoCommon/CPMemory.h"
13 #include "VideoCommon/NativeVertexFormat.h"
14
15 class VertexLoaderUID
16 {
17 std::array<u32, 5> vid{};
18 size_t hash = 0;
19
20 public:
21 VertexLoaderUID() {}
22 VertexLoaderUID(const TVtxDesc& vtx_desc, const VAT& vat)
23 {
24 vid[0] = vtx_desc.low.Hex;
25 vid[1] = vtx_desc.high.Hex;
26 vid[2] = vat.g0.Hex;
27 vid[3] = vat.g1.Hex;
28 vid[4] = vat.g2.Hex;
29 hash = CalculateHash();
30 }
31
32 bool operator==(const VertexLoaderUID& rh) const { return vid == rh.vid; }
33 size_t GetHash() const { return hash; }
34
35 private:
36 size_t CalculateHash() const
37 {
38 size_t h = SIZE_MAX;
39
40 for (auto word : vid)
41 {
42 h = h * 137 + word;
43 }
44
45 return h;
46 }
47 };
48
49 template <>
50 struct std::hash<VertexLoaderUID>
51 {
52 size_t operator()(const VertexLoaderUID& uid) const noexcept { return uid.GetHash(); }
53 };
54
55 class VertexLoaderBase
56 {
57 public:
58 static u32 GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
59 static u32 GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
60 static std::unique_ptr<VertexLoaderBase> CreateVertexLoader(const TVtxDesc& vtx_desc,
61 const VAT& vtx_attr);
62 virtual ~VertexLoaderBase() {}
63 virtual int RunVertices(const u8* src, u8* dst, int count) = 0;
64
65 // per loader public state
66 PortableVertexDeclaration m_native_vtx_decl{};
67 const u32 m_vertex_size; // number of bytes of a raw GC vertex
68 const u32 m_native_components;
69
70 // used by VertexLoaderManager
71 NativeVertexFormat* m_native_vertex_format = nullptr;
72 int m_numLoadedVertices = 0;
73
74 protected:
75 VertexLoaderBase(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
76 : m_vertex_size{GetVertexSize(vtx_desc, vtx_attr)},
77 m_native_components{GetVertexComponents(vtx_desc, vtx_attr)}, m_VtxAttr{vtx_attr},
78 m_VtxDesc{vtx_desc}
79 {
80 }
81
82 // GC vertex format
83 const VAT m_VtxAttr;
84 const TVtxDesc m_VtxDesc;
85 };