VertexLoaderBase.h 2.1 KB

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