summaryrefslogtreecommitdiff
path: root/src/video_core/macro
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2022-12-24 19:19:41 -0500
committerGravatar Fernando Sahmkow2023-01-01 16:43:58 -0500
commitd09aa0182f18d1ac338ab47009b42fdeb67497a8 (patch)
tree1b3ae726f7aaa465b30fba795cfca0ae88d2140b /src/video_core/macro
parentRasterizer: Setup skeleton for Host Conditional rendering (diff)
downloadyuzu-d09aa0182f18d1ac338ab47009b42fdeb67497a8.tar.gz
yuzu-d09aa0182f18d1ac338ab47009b42fdeb67497a8.tar.xz
yuzu-d09aa0182f18d1ac338ab47009b42fdeb67497a8.zip
MacroHLE: Final cleanup and fixes.
Diffstat (limited to 'src/video_core/macro')
-rw-r--r--src/video_core/macro/macro_hle.cpp98
1 files changed, 28 insertions, 70 deletions
diff --git a/src/video_core/macro/macro_hle.cpp b/src/video_core/macro/macro_hle.cpp
index 294a338d2..3481fcd41 100644
--- a/src/video_core/macro/macro_hle.cpp
+++ b/src/video_core/macro/macro_hle.cpp
@@ -47,21 +47,7 @@ public:
47 explicit HLEMacroImpl(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} {} 47 explicit HLEMacroImpl(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} {}
48 48
49protected: 49protected:
50 void advanceCheck() {
51 current_value = (current_value + 1) % fibonacci_post;
52 check_limit = current_value == 0;
53 if (check_limit) {
54 const u32 new_fibonacci = fibonacci_pre + fibonacci_post;
55 fibonacci_pre = fibonacci_post;
56 fibonacci_post = new_fibonacci;
57 }
58 }
59
60 Engines::Maxwell3D& maxwell3d; 50 Engines::Maxwell3D& maxwell3d;
61 u32 fibonacci_pre{89};
62 u32 fibonacci_post{144};
63 u32 current_value{fibonacci_post - 1};
64 bool check_limit{};
65}; 51};
66 52
67class HLE_771BB18C62444DA0 final : public HLEMacroImpl { 53class HLE_771BB18C62444DA0 final : public HLEMacroImpl {
@@ -124,12 +110,13 @@ private:
124 maxwell3d.RefreshParameters(); 110 maxwell3d.RefreshParameters();
125 const u32 instance_count = (maxwell3d.GetRegisterValue(0xD1B) & parameters[2]); 111 const u32 instance_count = (maxwell3d.GetRegisterValue(0xD1B) & parameters[2]);
126 112
113 auto topology = static_cast<Maxwell::Regs::PrimitiveTopology>(parameters[0]);
127 const u32 vertex_first = parameters[3]; 114 const u32 vertex_first = parameters[3];
128 const u32 vertex_count = parameters[1]; 115 const u32 vertex_count = parameters[1];
129
130 116
131 if (maxwell3d.AnyParametersDirty() && 117 if (!IsTopologySafe(topology) &&
132 maxwell3d.GetMaxCurrentVertices() < vertex_first + vertex_count) { 118 static_cast<size_t>(maxwell3d.GetMaxCurrentVertices()) <
119 static_cast<size_t>(vertex_first) + static_cast<size_t>(vertex_count)) {
133 ASSERT_MSG(false, "Faulty draw!"); 120 ASSERT_MSG(false, "Faulty draw!");
134 return; 121 return;
135 } 122 }
@@ -141,9 +128,8 @@ private:
141 maxwell3d.setHLEReplacementName(0, 0x640, Maxwell::HLEReplaceName::BaseInstance); 128 maxwell3d.setHLEReplacementName(0, 0x640, Maxwell::HLEReplaceName::BaseInstance);
142 } 129 }
143 130
144 maxwell3d.draw_manager->DrawArray( 131 maxwell3d.draw_manager->DrawArray(topology, vertex_first, vertex_count, base_instance,
145 static_cast<Tegra::Engines::Maxwell3D::Regs::PrimitiveTopology>(parameters[0]), 132 instance_count);
146 vertex_first, vertex_count, base_instance, instance_count);
147 133
148 if (extended) { 134 if (extended) {
149 maxwell3d.regs.global_base_instance_index = 0; 135 maxwell3d.regs.global_base_instance_index = 0;
@@ -166,13 +152,7 @@ public:
166 return; 152 return;
167 } 153 }
168 154
169 advanceCheck();
170 if (check_limit) {
171 maxwell3d.RefreshParameters();
172 minimum_limit = std::max(parameters[3], minimum_limit);
173 }
174 const u32 estimate = static_cast<u32>(maxwell3d.EstimateIndexBufferSize()); 155 const u32 estimate = static_cast<u32>(maxwell3d.EstimateIndexBufferSize());
175 const u32 base_size = std::max<u32>(minimum_limit, estimate);
176 const u32 element_base = parameters[4]; 156 const u32 element_base = parameters[4];
177 const u32 base_instance = parameters[5]; 157 const u32 base_instance = parameters[5];
178 maxwell3d.regs.vertex_id_base = element_base; 158 maxwell3d.regs.vertex_id_base = element_base;
@@ -191,7 +171,7 @@ public:
191 params.max_draw_counts = 1; 171 params.max_draw_counts = 1;
192 params.stride = 0; 172 params.stride = 0;
193 maxwell3d.dirty.flags[VideoCommon::Dirty::IndexBuffer] = true; 173 maxwell3d.dirty.flags[VideoCommon::Dirty::IndexBuffer] = true;
194 maxwell3d.draw_manager->DrawIndexedIndirect(topology, 0, base_size); 174 maxwell3d.draw_manager->DrawIndexedIndirect(topology, 0, estimate);
195 maxwell3d.engine_state = Maxwell::EngineHint::None; 175 maxwell3d.engine_state = Maxwell::EngineHint::None;
196 maxwell3d.replace_table.clear(); 176 maxwell3d.replace_table.clear();
197 maxwell3d.regs.vertex_id_base = 0x0; 177 maxwell3d.regs.vertex_id_base = 0x0;
@@ -223,8 +203,6 @@ private:
223 maxwell3d.engine_state = Maxwell::EngineHint::None; 203 maxwell3d.engine_state = Maxwell::EngineHint::None;
224 maxwell3d.replace_table.clear(); 204 maxwell3d.replace_table.clear();
225 } 205 }
226
227 u32 minimum_limit{1 << 18};
228}; 206};
229 207
230class HLE_MultiLayerClear final : public HLEMacroImpl { 208class HLE_MultiLayerClear final : public HLEMacroImpl {
@@ -257,10 +235,6 @@ public:
257 return; 235 return;
258 } 236 }
259 237
260 advanceCheck();
261 if (check_limit) {
262 maxwell3d.RefreshParameters();
263 }
264 const u32 start_indirect = parameters[0]; 238 const u32 start_indirect = parameters[0];
265 const u32 end_indirect = parameters[1]; 239 const u32 end_indirect = parameters[1];
266 if (start_indirect >= end_indirect) { 240 if (start_indirect >= end_indirect) {
@@ -274,20 +248,7 @@ public:
274 const u32 indirect_words = 5 + padding; 248 const u32 indirect_words = 5 + padding;
275 const u32 stride = indirect_words * sizeof(u32); 249 const u32 stride = indirect_words * sizeof(u32);
276 const std::size_t draw_count = end_indirect - start_indirect; 250 const std::size_t draw_count = end_indirect - start_indirect;
277 u32 lowest_first = std::numeric_limits<u32>::max();
278 u32 highest_limit = std::numeric_limits<u32>::min();
279 for (std::size_t index = 0; index < draw_count; index++) {
280 const std::size_t base = index * indirect_words + 5;
281 const u32 count = parameters[base];
282 const u32 first_index = parameters[base + 2];
283 lowest_first = std::min(lowest_first, first_index);
284 highest_limit = std::max(highest_limit, first_index + count);
285 }
286 if (check_limit) {
287 minimum_limit = std::max(highest_limit, minimum_limit);
288 }
289 const u32 estimate = static_cast<u32>(maxwell3d.EstimateIndexBufferSize()); 251 const u32 estimate = static_cast<u32>(maxwell3d.EstimateIndexBufferSize());
290 const u32 base_size = std::max(minimum_limit, estimate);
291 maxwell3d.dirty.flags[VideoCommon::Dirty::IndexBuffer] = true; 252 maxwell3d.dirty.flags[VideoCommon::Dirty::IndexBuffer] = true;
292 auto& params = maxwell3d.draw_manager->GetIndirectParams(); 253 auto& params = maxwell3d.draw_manager->GetIndirectParams();
293 params.is_indexed = true; 254 params.is_indexed = true;
@@ -301,7 +262,7 @@ public:
301 maxwell3d.engine_state = Maxwell::EngineHint::OnHLEMacro; 262 maxwell3d.engine_state = Maxwell::EngineHint::OnHLEMacro;
302 maxwell3d.setHLEReplacementName(0, 0x640, Maxwell::HLEReplaceName::BaseVertex); 263 maxwell3d.setHLEReplacementName(0, 0x640, Maxwell::HLEReplaceName::BaseVertex);
303 maxwell3d.setHLEReplacementName(0, 0x644, Maxwell::HLEReplaceName::BaseInstance); 264 maxwell3d.setHLEReplacementName(0, 0x644, Maxwell::HLEReplaceName::BaseInstance);
304 maxwell3d.draw_manager->DrawIndexedIndirect(topology, 0, base_size); 265 maxwell3d.draw_manager->DrawIndexedIndirect(topology, 0, estimate);
305 maxwell3d.engine_state = Maxwell::EngineHint::None; 266 maxwell3d.engine_state = Maxwell::EngineHint::None;
306 maxwell3d.replace_table.clear(); 267 maxwell3d.replace_table.clear();
307 } 268 }
@@ -323,7 +284,6 @@ private:
323 return; 284 return;
324 } 285 }
325 const auto topology = static_cast<Maxwell::Regs::PrimitiveTopology>(parameters[2]); 286 const auto topology = static_cast<Maxwell::Regs::PrimitiveTopology>(parameters[2]);
326 maxwell3d.regs.draw.topology.Assign(topology);
327 const u32 padding = parameters[3]; 287 const u32 padding = parameters[3];
328 const std::size_t max_draws = parameters[4]; 288 const std::size_t max_draws = parameters[4];
329 289
@@ -345,8 +305,6 @@ private:
345 base_vertex, base_instance, parameters[base + 1]); 305 base_vertex, base_instance, parameters[base + 1]);
346 } 306 }
347 } 307 }
348
349 u32 minimum_limit{1 << 12};
350}; 308};
351 309
352class HLE_C713C83D8F63CCF3 final : public HLEMacroImpl { 310class HLE_C713C83D8F63CCF3 final : public HLEMacroImpl {
@@ -431,53 +389,53 @@ public:
431HLEMacro::HLEMacro(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} { 389HLEMacro::HLEMacro(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} {
432 builders.emplace(0x771BB18C62444DA0ULL, 390 builders.emplace(0x771BB18C62444DA0ULL,
433 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 391 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
434 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 392 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
435 return std::make_unique<HLE_771BB18C62444DA0>(maxwell3d); 393 return std::make_unique<HLE_771BB18C62444DA0>(maxwell3d__);
436 })); 394 }));
437 builders.emplace(0x0D61FC9FAAC9FCADULL, 395 builders.emplace(0x0D61FC9FAAC9FCADULL,
438 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 396 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
439 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 397 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
440 return std::make_unique<HLE_DrawArraysIndirect>(maxwell3d); 398 return std::make_unique<HLE_DrawArraysIndirect>(maxwell3d__);
441 })); 399 }));
442 builders.emplace(0x8A4D173EB99A8603ULL, 400 builders.emplace(0x8A4D173EB99A8603ULL,
443 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 401 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
444 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 402 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
445 return std::make_unique<HLE_DrawArraysIndirect>(maxwell3d, true); 403 return std::make_unique<HLE_DrawArraysIndirect>(maxwell3d__, true);
446 })); 404 }));
447 builders.emplace(0x0217920100488FF7ULL, 405 builders.emplace(0x0217920100488FF7ULL,
448 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 406 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
449 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 407 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
450 return std::make_unique<HLE_DrawIndexedIndirect>(maxwell3d); 408 return std::make_unique<HLE_DrawIndexedIndirect>(maxwell3d__);
451 })); 409 }));
452 builders.emplace(0x3F5E74B9C9A50164ULL, 410 builders.emplace(0x3F5E74B9C9A50164ULL,
453 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 411 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
454 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 412 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
455 return std::make_unique<HLE_MultiDrawIndexedIndirectCount>(maxwell3d); 413 return std::make_unique<HLE_MultiDrawIndexedIndirectCount>(maxwell3d__);
456 })); 414 }));
457 builders.emplace(0xEAD26C3E2109B06BULL, 415 builders.emplace(0xEAD26C3E2109B06BULL,
458 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 416 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
459 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 417 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
460 return std::make_unique<HLE_MultiLayerClear>(maxwell3d); 418 return std::make_unique<HLE_MultiLayerClear>(maxwell3d__);
461 })); 419 }));
462 builders.emplace(0xC713C83D8F63CCF3ULL, 420 builders.emplace(0xC713C83D8F63CCF3ULL,
463 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 421 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
464 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 422 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
465 return std::make_unique<HLE_C713C83D8F63CCF3>(maxwell3d); 423 return std::make_unique<HLE_C713C83D8F63CCF3>(maxwell3d__);
466 })); 424 }));
467 builders.emplace(0xD7333D26E0A93EDEULL, 425 builders.emplace(0xD7333D26E0A93EDEULL,
468 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 426 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
469 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 427 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
470 return std::make_unique<HLE_D7333D26E0A93EDE>(maxwell3d); 428 return std::make_unique<HLE_D7333D26E0A93EDE>(maxwell3d__);
471 })); 429 }));
472 builders.emplace(0xEB29B2A09AA06D38ULL, 430 builders.emplace(0xEB29B2A09AA06D38ULL,
473 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 431 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
474 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 432 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
475 return std::make_unique<HLE_BindShader>(maxwell3d); 433 return std::make_unique<HLE_BindShader>(maxwell3d__);
476 })); 434 }));
477 builders.emplace(0xDB1341DBEB4C8AF7ULL, 435 builders.emplace(0xDB1341DBEB4C8AF7ULL,
478 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>( 436 std::function<std::unique_ptr<CachedMacro>(Engines::Maxwell3D&)>(
479 [](Engines::Maxwell3D& maxwell3d) -> std::unique_ptr<CachedMacro> { 437 [](Engines::Maxwell3D& maxwell3d__) -> std::unique_ptr<CachedMacro> {
480 return std::make_unique<HLE_SetRasterBoundingBox>(maxwell3d); 438 return std::make_unique<HLE_SetRasterBoundingBox>(maxwell3d__);
481 })); 439 }));
482} 440}
483 441