Debian Codegraph @

Source/Core/VideoCommon/VertexShaderManager.h

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <span>
8 #include <string>
9
10 #include "Common/CommonTypes.h"
11 #include "Common/Matrix.h"
12 #include "VideoCommon/ConstantManager.h"
13 #include "VideoCommon/NativeVertexFormat.h"
14
15 class PointerWrap;
16 struct PortableVertexDeclaration;
17 class XFStateManager;
18
19 // The non-API dependent parts.
20 class alignas(16) VertexShaderManager
21 {
22 public:
23 void Init();
24 void DoState(PointerWrap& p);
25
26 // constant management
27 void SetProjectionMatrix(XFStateManager& xf_state_manager);
28 void SetConstants(std::span<const std::string> textures, XFStateManager& xf_state_manager);
29
30 // data: 3 floats representing the X, Y and Z vertex model coordinates and the posmatrix index.
31 // out: 4 floats which will be initialized with the corresponding clip space coordinates
32 // NOTE: m_projection_matrix must be up to date when this is called
33 // (i.e. VertexShaderManager::SetConstants needs to be called before using this!)
34 void TransformToClipSpace(const float* data, float* out, u32 mtxIdx);
35
36 static bool UseVertexDepthRange();
37
38 VertexShaderConstants constants{};
39 bool dirty = false;
40
41 static DOLPHIN_FORCE_INLINE void UpdateValue(bool* dirty, u32* old_value, u32 new_value)
42 {
43 if (*old_value == new_value)
44 return;
45 *old_value = new_value;
46 *dirty = true;
47 }
48
49 static DOLPHIN_FORCE_INLINE void UpdateOffset(bool* dirty, bool include_components,
50 u32* old_value, const AttributeFormat& attribute)
51 {
52 if (!attribute.enable)
53 return;
54 u32 new_value = attribute.offset / 4; // GPU uses uint offsets
55 if (include_components)
56 new_value |= attribute.components << 16;
57 UpdateValue(dirty, old_value, new_value);
58 }
59
60 template <size_t N>
61 static DOLPHIN_FORCE_INLINE void UpdateOffsets(bool* dirty, bool include_components,
62 std::array<u32, N>* old_value,
63 const std::array<AttributeFormat, N>& attribute)
64 {
65 for (size_t i = 0; i < N; i++)
66 UpdateOffset(dirty, include_components, &(*old_value)[i], attribute[i]);
67 }
68
69 DOLPHIN_FORCE_INLINE void SetVertexFormat(u32 components, const PortableVertexDeclaration& format)
70 {
71 UpdateValue(&dirty, &constants.components, components);
72 UpdateValue(&dirty, &constants.vertex_stride, format.stride / 4);
73 UpdateOffset(&dirty, true, &constants.vertex_offset_position, format.position);
74 UpdateOffset(&dirty, false, &constants.vertex_offset_posmtx, format.posmtx);
75 UpdateOffsets(&dirty, true, &constants.vertex_offset_texcoords, format.texcoords);
76 UpdateOffsets(&dirty, false, &constants.vertex_offset_colors, format.colors);
77 UpdateOffsets(&dirty, false, &constants.vertex_offset_normals, format.normals);
78 }
79
80 private:
81 alignas(16) std::array<float, 16> m_projection_matrix;
82
83 // track changes
84 bool m_projection_graphics_mod_change = false;
85
86 Common::Matrix44 LoadProjectionMatrix();
87 };