summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/spirv
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-06-21 01:07:10 -0300
committerGravatar ameerj2021-07-22 21:51:39 -0400
commit808ef97a086e7cc58a3ceded1de516ad6a6be5d3 (patch)
treeb79be02801ddadb44940d2c77fa0ae5c571dc557 /src/shader_recompiler/backend/spirv
parentgl_graphics_pipeline: Fix assembly shaders check for transform feedbacks (diff)
downloadyuzu-808ef97a086e7cc58a3ceded1de516ad6a6be5d3.tar.gz
yuzu-808ef97a086e7cc58a3ceded1de516ad6a6be5d3.tar.xz
yuzu-808ef97a086e7cc58a3ceded1de516ad6a6be5d3.zip
shader: Move loop safety tests to code emission
Diffstat (limited to 'src/shader_recompiler/backend/spirv')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv.cpp19
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp8
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_instructions.h2
3 files changed, 18 insertions, 11 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.cpp b/src/shader_recompiler/backend/spirv/emit_spirv.cpp
index fd59b4d0a..278c262f8 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_spirv.cpp
@@ -8,6 +8,7 @@
8#include <utility> 8#include <utility>
9#include <vector> 9#include <vector>
10 10
11#include "common/settings.h"
11#include "shader_recompiler/backend/spirv/emit_spirv.h" 12#include "shader_recompiler/backend/spirv/emit_spirv.h"
12#include "shader_recompiler/backend/spirv/emit_spirv_instructions.h" 13#include "shader_recompiler/backend/spirv/emit_spirv_instructions.h"
13#include "shader_recompiler/frontend/ir/basic_block.h" 14#include "shader_recompiler/frontend/ir/basic_block.h"
@@ -151,9 +152,25 @@ void Traverse(EmitContext& ctx, IR::Program& program) {
151 } 152 }
152 break; 153 break;
153 case IR::AbstractSyntaxNode::Type::Repeat: { 154 case IR::AbstractSyntaxNode::Type::Repeat: {
155 Id cond{ctx.Def(node.data.repeat.cond)};
156 if (!Settings::values.disable_shader_loop_safety_checks) {
157 const Id pointer_type{ctx.TypePointer(spv::StorageClass::Private, ctx.U32[1])};
158 const Id safety_counter{ctx.AddGlobalVariable(
159 pointer_type, spv::StorageClass::Private, ctx.Const(0x2000u))};
160 if (ctx.profile.supported_spirv >= 0x00010400) {
161 ctx.interfaces.push_back(safety_counter);
162 }
163 const Id old_counter{ctx.OpLoad(ctx.U32[1], safety_counter)};
164 const Id new_counter{ctx.OpISub(ctx.U32[1], old_counter, ctx.Const(1u))};
165 ctx.OpStore(safety_counter, new_counter);
166
167 const Id safety_cond{
168 ctx.OpSGreaterThanEqual(ctx.U1, new_counter, ctx.u32_zero_value)};
169 cond = ctx.OpLogicalAnd(ctx.U1, cond, safety_cond);
170 }
154 const Id loop_header_label{node.data.repeat.loop_header->Definition<Id>()}; 171 const Id loop_header_label{node.data.repeat.loop_header->Definition<Id>()};
155 const Id merge_label{node.data.repeat.merge->Definition<Id>()}; 172 const Id merge_label{node.data.repeat.merge->Definition<Id>()};
156 ctx.OpBranchConditional(ctx.Def(node.data.repeat.cond), loop_header_label, merge_label); 173 ctx.OpBranchConditional(cond, loop_header_label, merge_label);
157 break; 174 break;
158 } 175 }
159 case IR::AbstractSyntaxNode::Type::Return: 176 case IR::AbstractSyntaxNode::Type::Return:
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
index 2e364baec..85bd72389 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
@@ -198,14 +198,6 @@ void EmitGetIndirectBranchVariable(EmitContext&) {
198 throw LogicError("Unreachable instruction"); 198 throw LogicError("Unreachable instruction");
199} 199}
200 200
201void EmitSetLoopSafetyVariable(EmitContext&) {
202 throw LogicError("Unreachable instruction");
203}
204
205void EmitGetLoopSafetyVariable(EmitContext&) {
206 throw LogicError("Unreachable instruction");
207}
208
209Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { 201Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) {
210 if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) { 202 if (ctx.profile.support_descriptor_aliasing && ctx.profile.support_int8) {
211 const Id load{GetCbuf(ctx, ctx.U8, &UniformDefinitions::U8, sizeof(u8), binding, offset)}; 203 const Id load{GetCbuf(ctx, ctx.U8, &UniformDefinitions::U8, sizeof(u8), binding, offset)};
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
index e3e5b03fe..1181e7b4f 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h
@@ -43,8 +43,6 @@ void EmitSetGotoVariable(EmitContext& ctx);
43void EmitGetGotoVariable(EmitContext& ctx); 43void EmitGetGotoVariable(EmitContext& ctx);
44void EmitSetIndirectBranchVariable(EmitContext& ctx); 44void EmitSetIndirectBranchVariable(EmitContext& ctx);
45void EmitGetIndirectBranchVariable(EmitContext& ctx); 45void EmitGetIndirectBranchVariable(EmitContext& ctx);
46void EmitSetLoopSafetyVariable(EmitContext& ctx);
47void EmitGetLoopSafetyVariable(EmitContext& ctx);
48Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); 46Id EmitGetCbufU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset);
49Id EmitGetCbufS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); 47Id EmitGetCbufS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset);
50Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); 48Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset);