Debian Codegraph @

Source/Core/VideoCommon/GeometryShaderManager.cpp

raw symbols SCIP
1 // Copyright 2014 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "VideoCommon/GeometryShaderManager.h"
5
6 #include "Common/ChunkFile.h"
7 #include "Common/CommonTypes.h"
8 #include "VideoCommon/BPMemory.h"
9 #include "VideoCommon/RenderState.h"
10 #include "VideoCommon/VideoConfig.h"
11 #include "VideoCommon/XFMemory.h"
12
13 static constexpr int LINE_PT_TEX_OFFSETS[8] = {0, 16, 8, 4, 2, 1, 1, 1};
14
15 void GeometryShaderManager::Init()
16 {
17 constants = {};
18
19 // Init any initial constants which aren't zero when bpmem is zero.
20 SetViewportChanged();
21 SetProjectionChanged();
22
23 dirty = true;
24 }
25
26 void GeometryShaderManager::Dirty()
27 {
28 // This function is called after a savestate is loaded.
29 // Any constants that can changed based on settings should be re-calculated
30 m_projection_changed = true;
31
32 // Uses EFB scale config
33 SetLinePtWidthChanged();
34
35 dirty = true;
36 }
37
38 void GeometryShaderManager::SetVSExpand(VSExpand expand)
39 {
40 if (constants.vs_expand != expand)
41 {
42 constants.vs_expand = expand;
43 dirty = true;
44 }
45 }
46
47 void GeometryShaderManager::SetConstants(PrimitiveType prim)
48 {
49 if (m_projection_changed && g_ActiveConfig.stereo_mode != StereoMode::Off)
50 {
51 m_projection_changed = false;
52
53 if (xfmem.projection.type == ProjectionType::Perspective)
54 {
55 const float offset = g_ActiveConfig.stereo_depth;
56 constants.stereoparams[0] = g_ActiveConfig.bStereoSwapEyes ? offset : -offset;
57 constants.stereoparams[1] = g_ActiveConfig.bStereoSwapEyes ? -offset : offset;
58 }
59 else
60 {
61 constants.stereoparams[0] = constants.stereoparams[1] = 0;
62 }
63
64 constants.stereoparams[2] = g_ActiveConfig.stereo_convergence;
65
66 dirty = true;
67 }
68
69 if (g_ActiveConfig.UseVSForLinePointExpand())
70 {
71 if (prim == PrimitiveType::Points)
72 SetVSExpand(VSExpand::Point);
73 else if (prim == PrimitiveType::Lines)
74 SetVSExpand(VSExpand::Line);
75 else
76 SetVSExpand(VSExpand::None);
77 }
78
79 if (m_viewport_changed)
80 {
81 m_viewport_changed = false;
82
83 constants.lineptparams[0] = 2.0f * xfmem.viewport.wd;
84 constants.lineptparams[1] = -2.0f * xfmem.viewport.ht;
85
86 dirty = true;
87 }
88 }
89
90 void GeometryShaderManager::SetViewportChanged()
91 {
92 m_viewport_changed = true;
93 }
94
95 void GeometryShaderManager::SetProjectionChanged()
96 {
97 m_projection_changed = true;
98 }
99
100 void GeometryShaderManager::SetLinePtWidthChanged()
101 {
102 constants.lineptparams[2] = bpmem.lineptwidth.linesize / 6.f;
103 constants.lineptparams[3] = bpmem.lineptwidth.pointsize / 6.f;
104 constants.texoffset[2] = LINE_PT_TEX_OFFSETS[bpmem.lineptwidth.lineoff];
105 constants.texoffset[3] = LINE_PT_TEX_OFFSETS[bpmem.lineptwidth.pointoff];
106 dirty = true;
107 }
108
109 void GeometryShaderManager::SetTexCoordChanged(u8 texmapid)
110 {
111 TCoordInfo& tc = bpmem.texcoords[texmapid];
112 int bitmask = 1 << texmapid;
113 constants.texoffset[0] &= ~bitmask;
114 constants.texoffset[0] |= tc.s.line_offset << texmapid;
115 constants.texoffset[1] &= ~bitmask;
116 constants.texoffset[1] |= tc.s.point_offset << texmapid;
117 dirty = true;
118 }
119
120 void GeometryShaderManager::DoState(PointerWrap& p)
121 {
122 p.Do(m_projection_changed);
123 p.Do(m_viewport_changed);
124
125 p.Do(constants);
126
127 if (p.IsReadMode())
128 {
129 // Fixup the current state from global GPU state
130 // NOTE: This requires that all GPU memory has been loaded already.
131 Dirty();
132 }
133 }