summaryrefslogtreecommitdiff
path: root/src/video_core/engines
diff options
context:
space:
mode:
authorGravatar bunnei2019-02-27 20:50:08 -0500
committerGravatar GitHub2019-02-27 20:50:08 -0500
commitf15e2dd88112ef6927845f6685c87adf38dccf41 (patch)
tree474b03803432e2824233b368664f2b53ca783ef4 /src/video_core/engines
parentSpeed up memory page mapping (#2141) (diff)
parentmaxwell_3d: Use std::bitset to manage dirty flags (diff)
downloadyuzu-f15e2dd88112ef6927845f6685c87adf38dccf41.tar.gz
yuzu-f15e2dd88112ef6927845f6685c87adf38dccf41.tar.xz
yuzu-f15e2dd88112ef6927845f6685c87adf38dccf41.zip
Merge pull request #2163 from ReinUsesLisp/bitset-dirty
maxwell_3d: Use std::bitset to manage dirty flags
Diffstat (limited to 'src/video_core/engines')
-rw-r--r--src/video_core/engines/maxwell_3d.cpp66
-rw-r--r--src/video_core/engines/maxwell_3d.h15
2 files changed, 40 insertions, 41 deletions
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index 2d2136067..144e7fa82 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -107,21 +107,23 @@ void Maxwell3D::CallMacroMethod(u32 method, std::vector<u32> parameters) {
107void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) { 107void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) {
108 auto debug_context = system.GetGPUDebugContext(); 108 auto debug_context = system.GetGPUDebugContext();
109 109
110 const u32 method = method_call.method;
111
110 // It is an error to write to a register other than the current macro's ARG register before it 112 // It is an error to write to a register other than the current macro's ARG register before it
111 // has finished execution. 113 // has finished execution.
112 if (executing_macro != 0) { 114 if (executing_macro != 0) {
113 ASSERT(method_call.method == executing_macro + 1); 115 ASSERT(method == executing_macro + 1);
114 } 116 }
115 117
116 // Methods after 0xE00 are special, they're actually triggers for some microcode that was 118 // Methods after 0xE00 are special, they're actually triggers for some microcode that was
117 // uploaded to the GPU during initialization. 119 // uploaded to the GPU during initialization.
118 if (method_call.method >= MacroRegistersStart) { 120 if (method >= MacroRegistersStart) {
119 // We're trying to execute a macro 121 // We're trying to execute a macro
120 if (executing_macro == 0) { 122 if (executing_macro == 0) {
121 // A macro call must begin by writing the macro method's register, not its argument. 123 // A macro call must begin by writing the macro method's register, not its argument.
122 ASSERT_MSG((method_call.method % 2) == 0, 124 ASSERT_MSG((method % 2) == 0,
123 "Can't start macro execution by writing to the ARGS register"); 125 "Can't start macro execution by writing to the ARGS register");
124 executing_macro = method_call.method; 126 executing_macro = method;
125 } 127 }
126 128
127 macro_params.push_back(method_call.argument); 129 macro_params.push_back(method_call.argument);
@@ -133,66 +135,62 @@ void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) {
133 return; 135 return;
134 } 136 }
135 137
136 ASSERT_MSG(method_call.method < Regs::NUM_REGS, 138 ASSERT_MSG(method < Regs::NUM_REGS,
137 "Invalid Maxwell3D register, increase the size of the Regs structure"); 139 "Invalid Maxwell3D register, increase the size of the Regs structure");
138 140
139 if (debug_context) { 141 if (debug_context) {
140 debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandLoaded, nullptr); 142 debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandLoaded, nullptr);
141 } 143 }
142 144
143 if (regs.reg_array[method_call.method] != method_call.argument) { 145 if (regs.reg_array[method] != method_call.argument) {
144 regs.reg_array[method_call.method] = method_call.argument; 146 regs.reg_array[method] = method_call.argument;
145 // Color buffers 147 // Color buffers
146 constexpr u32 first_rt_reg = MAXWELL3D_REG_INDEX(rt); 148 constexpr u32 first_rt_reg = MAXWELL3D_REG_INDEX(rt);
147 constexpr u32 registers_per_rt = sizeof(regs.rt[0]) / sizeof(u32); 149 constexpr u32 registers_per_rt = sizeof(regs.rt[0]) / sizeof(u32);
148 if (method_call.method >= first_rt_reg && 150 if (method >= first_rt_reg &&
149 method_call.method < first_rt_reg + registers_per_rt * Regs::NumRenderTargets) { 151 method < first_rt_reg + registers_per_rt * Regs::NumRenderTargets) {
150 const std::size_t rt_index = (method_call.method - first_rt_reg) / registers_per_rt; 152 const std::size_t rt_index = (method - first_rt_reg) / registers_per_rt;
151 dirty_flags.color_buffer |= 1u << static_cast<u32>(rt_index); 153 dirty_flags.color_buffer.set(rt_index);
152 } 154 }
153 155
154 // Zeta buffer 156 // Zeta buffer
155 constexpr u32 registers_in_zeta = sizeof(regs.zeta) / sizeof(u32); 157 constexpr u32 registers_in_zeta = sizeof(regs.zeta) / sizeof(u32);
156 if (method_call.method == MAXWELL3D_REG_INDEX(zeta_enable) || 158 if (method == MAXWELL3D_REG_INDEX(zeta_enable) ||
157 method_call.method == MAXWELL3D_REG_INDEX(zeta_width) || 159 method == MAXWELL3D_REG_INDEX(zeta_width) ||
158 method_call.method == MAXWELL3D_REG_INDEX(zeta_height) || 160 method == MAXWELL3D_REG_INDEX(zeta_height) ||
159 (method_call.method >= MAXWELL3D_REG_INDEX(zeta) && 161 (method >= MAXWELL3D_REG_INDEX(zeta) &&
160 method_call.method < MAXWELL3D_REG_INDEX(zeta) + registers_in_zeta)) { 162 method < MAXWELL3D_REG_INDEX(zeta) + registers_in_zeta)) {
161 dirty_flags.zeta_buffer = true; 163 dirty_flags.zeta_buffer = true;
162 } 164 }
163 165
164 // Shader 166 // Shader
165 constexpr u32 shader_registers_count = 167 constexpr u32 shader_registers_count =
166 sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32); 168 sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32);
167 if (method_call.method >= MAXWELL3D_REG_INDEX(shader_config[0]) && 169 if (method >= MAXWELL3D_REG_INDEX(shader_config[0]) &&
168 method_call.method < MAXWELL3D_REG_INDEX(shader_config[0]) + shader_registers_count) { 170 method < MAXWELL3D_REG_INDEX(shader_config[0]) + shader_registers_count) {
169 dirty_flags.shaders = true; 171 dirty_flags.shaders = true;
170 } 172 }
171 173
172 // Vertex format 174 // Vertex format
173 if (method_call.method >= MAXWELL3D_REG_INDEX(vertex_attrib_format) && 175 if (method >= MAXWELL3D_REG_INDEX(vertex_attrib_format) &&
174 method_call.method < 176 method < MAXWELL3D_REG_INDEX(vertex_attrib_format) + regs.vertex_attrib_format.size()) {
175 MAXWELL3D_REG_INDEX(vertex_attrib_format) + regs.vertex_attrib_format.size()) {
176 dirty_flags.vertex_attrib_format = true; 177 dirty_flags.vertex_attrib_format = true;
177 } 178 }
178 179
179 // Vertex buffer 180 // Vertex buffer
180 if (method_call.method >= MAXWELL3D_REG_INDEX(vertex_array) && 181 if (method >= MAXWELL3D_REG_INDEX(vertex_array) &&
181 method_call.method < MAXWELL3D_REG_INDEX(vertex_array) + 4 * 32) { 182 method < MAXWELL3D_REG_INDEX(vertex_array) + 4 * 32) {
182 dirty_flags.vertex_array |= 183 dirty_flags.vertex_array.set((method - MAXWELL3D_REG_INDEX(vertex_array)) >> 2);
183 1u << ((method_call.method - MAXWELL3D_REG_INDEX(vertex_array)) >> 2); 184 } else if (method >= MAXWELL3D_REG_INDEX(vertex_array_limit) &&
184 } else if (method_call.method >= MAXWELL3D_REG_INDEX(vertex_array_limit) && 185 method < MAXWELL3D_REG_INDEX(vertex_array_limit) + 2 * 32) {
185 method_call.method < MAXWELL3D_REG_INDEX(vertex_array_limit) + 2 * 32) { 186 dirty_flags.vertex_array.set((method - MAXWELL3D_REG_INDEX(vertex_array_limit)) >> 1);
186 dirty_flags.vertex_array |= 187 } else if (method >= MAXWELL3D_REG_INDEX(instanced_arrays) &&
187 1u << ((method_call.method - MAXWELL3D_REG_INDEX(vertex_array_limit)) >> 1); 188 method < MAXWELL3D_REG_INDEX(instanced_arrays) + 32) {
188 } else if (method_call.method >= MAXWELL3D_REG_INDEX(instanced_arrays) && 189 dirty_flags.vertex_array.set(method - MAXWELL3D_REG_INDEX(instanced_arrays));
189 method_call.method < MAXWELL3D_REG_INDEX(instanced_arrays) + 32) {
190 dirty_flags.vertex_array |=
191 1u << (method_call.method - MAXWELL3D_REG_INDEX(instanced_arrays));
192 } 190 }
193 } 191 }
194 192
195 switch (method_call.method) { 193 switch (method) {
196 case MAXWELL3D_REG_INDEX(macros.data): { 194 case MAXWELL3D_REG_INDEX(macros.data): {
197 ProcessMacroUpload(method_call.argument); 195 ProcessMacroUpload(method_call.argument);
198 break; 196 break;
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index 584f51c48..7fbf1026e 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -5,8 +5,10 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <bitset>
8#include <unordered_map> 9#include <unordered_map>
9#include <vector> 10#include <vector>
11
10#include "common/assert.h" 12#include "common/assert.h"
11#include "common/bit_field.h" 13#include "common/bit_field.h"
12#include "common/common_funcs.h" 14#include "common/common_funcs.h"
@@ -1094,19 +1096,18 @@ public:
1094 MemoryManager& memory_manager; 1096 MemoryManager& memory_manager;
1095 1097
1096 struct DirtyFlags { 1098 struct DirtyFlags {
1097 u8 color_buffer = 0xFF; 1099 std::bitset<8> color_buffer{0xFF};
1098 bool zeta_buffer = true; 1100 std::bitset<32> vertex_array{0xFFFFFFFF};
1099
1100 bool shaders = true;
1101 1101
1102 bool vertex_attrib_format = true; 1102 bool vertex_attrib_format = true;
1103 u32 vertex_array = 0xFFFFFFFF; 1103 bool zeta_buffer = true;
1104 bool shaders = true;
1104 1105
1105 void OnMemoryWrite() { 1106 void OnMemoryWrite() {
1106 color_buffer = 0xFF;
1107 zeta_buffer = true; 1107 zeta_buffer = true;
1108 shaders = true; 1108 shaders = true;
1109 vertex_array = 0xFFFFFFFF; 1109 color_buffer.set();
1110 vertex_array.set();
1110 } 1111 }
1111 }; 1112 };
1112 1113