summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glasm/emit_glasm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm.cpp')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
index f39b02f77..79314f130 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
@@ -6,6 +6,8 @@
6#include <string> 6#include <string>
7#include <tuple> 7#include <tuple>
8 8
9#include "common/div_ceil.h"
10#include "common/settings.h"
9#include "shader_recompiler/backend/bindings.h" 11#include "shader_recompiler/backend/bindings.h"
10#include "shader_recompiler/backend/glasm/emit_context.h" 12#include "shader_recompiler/backend/glasm/emit_context.h"
11#include "shader_recompiler/backend/glasm/emit_glasm.h" 13#include "shader_recompiler/backend/glasm/emit_glasm.h"
@@ -222,6 +224,14 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) {
222 ctx.Add("REP;"); 224 ctx.Add("REP;");
223 break; 225 break;
224 case IR::AbstractSyntaxNode::Type::Repeat: 226 case IR::AbstractSyntaxNode::Type::Repeat:
227 if (!Settings::values.disable_shader_loop_safety_checks) {
228 const u32 loop_index{ctx.num_safety_loop_vars++};
229 const u32 vector_index{loop_index / 4};
230 const char component{"xyzw"[loop_index % 4]};
231 ctx.Add("SUB.S.CC loop{}.{},loop{}.{},1;"
232 "BRK(LT.{});",
233 vector_index, component, vector_index, component, component);
234 }
225 if (node.data.repeat.cond.IsImmediate()) { 235 if (node.data.repeat.cond.IsImmediate()) {
226 if (node.data.repeat.cond.U1()) { 236 if (node.data.repeat.cond.U1()) {
227 ctx.Add("ENDREP;"); 237 ctx.Add("ENDREP;");
@@ -425,6 +435,10 @@ std::string EmitGLASM(const Profile& profile, const RuntimeInfo& runtime_info, I
425 if (program.info.uses_fswzadd) { 435 if (program.info.uses_fswzadd) {
426 header += "FSWZA[4],FSWZB[4],"; 436 header += "FSWZA[4],FSWZB[4],";
427 } 437 }
438 const u32 num_safety_loop_vectors{Common::DivCeil(ctx.num_safety_loop_vars, 4u)};
439 for (u32 index = 0; index < num_safety_loop_vectors; ++index) {
440 header += fmt::format("loop{},", index);
441 }
428 header += "RC;" 442 header += "RC;"
429 "LONG TEMP "; 443 "LONG TEMP ";
430 for (size_t index = 0; index < ctx.reg_alloc.NumUsedLongRegisters(); ++index) { 444 for (size_t index = 0; index < ctx.reg_alloc.NumUsedLongRegisters(); ++index) {
@@ -441,6 +455,9 @@ std::string EmitGLASM(const Profile& profile, const RuntimeInfo& runtime_info, I
441 "MOV.F FSWZB[2],1;" 455 "MOV.F FSWZB[2],1;"
442 "MOV.F FSWZB[3],-1;"; 456 "MOV.F FSWZB[3],-1;";
443 } 457 }
458 for (u32 index = 0; index < num_safety_loop_vectors; ++index) {
459 header += fmt::format("MOV.S loop{},{{0x2000,0x2000,0x2000,0x2000}};", index);
460 }
444 if (ctx.uses_y_direction) { 461 if (ctx.uses_y_direction) {
445 header += "PARAM y_direction[1]={state.material.front.ambient};"; 462 header += "PARAM y_direction[1]={state.material.front.ambient};";
446 } 463 }