summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend
diff options
context:
space:
mode:
authorGravatar FernandoS272021-04-02 19:27:30 +0200
committerGravatar ameerj2021-07-22 21:51:26 -0400
commit655f7a570a10218ffb2ed175bb7f0b84530ccae0 (patch)
treebb95bc316718bd5c746a0b28084b3548a4aea222 /src/shader_recompiler/frontend
parentshader: Improve VOTE.VTG stub (diff)
downloadyuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.tar.gz
yuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.tar.xz
yuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.zip
shader: Implement MEMBAR
Diffstat (limited to 'src/shader_recompiler/frontend')
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.cpp4
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.h2
-rw-r--r--src/shader_recompiler/frontend/ir/modifiers.h13
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.inc3
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/barrier_operations.cpp56
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp11
6 files changed, 78 insertions, 11 deletions
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
index ddaa873f2..2fd90303f 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
@@ -82,6 +82,10 @@ void IREmitter::SelectionMerge(Block* merge_block) {
82 Inst(Opcode::SelectionMerge, merge_block); 82 Inst(Opcode::SelectionMerge, merge_block);
83} 83}
84 84
85void IREmitter::MemoryBarrier(BarrierInstInfo info) {
86 Inst(Opcode::MemoryBarrier, Flags{info});
87}
88
85void IREmitter::Return() { 89void IREmitter::Return() {
86 block->SetReturn(); 90 block->SetReturn();
87 Inst(Opcode::Return); 91 Inst(Opcode::Return);
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h
index 6e04eec7f..5bebf66e3 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.h
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.h
@@ -136,6 +136,8 @@ public:
136 [[nodiscard]] Value Select(const U1& condition, const Value& true_value, 136 [[nodiscard]] Value Select(const U1& condition, const Value& true_value,
137 const Value& false_value); 137 const Value& false_value);
138 138
139 [[nodiscard]] void MemoryBarrier(BarrierInstInfo info);
140
139 template <typename Dest, typename Source> 141 template <typename Dest, typename Source>
140 [[nodiscard]] Dest BitCast(const Source& value); 142 [[nodiscard]] Dest BitCast(const Source& value);
141 143
diff --git a/src/shader_recompiler/frontend/ir/modifiers.h b/src/shader_recompiler/frontend/ir/modifiers.h
index 90078f535..7730c25a9 100644
--- a/src/shader_recompiler/frontend/ir/modifiers.h
+++ b/src/shader_recompiler/frontend/ir/modifiers.h
@@ -25,6 +25,14 @@ enum class FpRounding : u8 {
25 RZ, // Round towards zero 25 RZ, // Round towards zero
26}; 26};
27 27
28enum class MemoryScope : u32 {
29 DontCare,
30 Warp,
31 Workgroup,
32 Device,
33 System
34};
35
28struct FpControl { 36struct FpControl {
29 bool no_contraction{false}; 37 bool no_contraction{false};
30 FpRounding rounding{FpRounding::DontCare}; 38 FpRounding rounding{FpRounding::DontCare};
@@ -32,6 +40,11 @@ struct FpControl {
32}; 40};
33static_assert(sizeof(FpControl) <= sizeof(u32)); 41static_assert(sizeof(FpControl) <= sizeof(u32));
34 42
43union BarrierInstInfo {
44 u32 raw;
45 BitField<0, 3, MemoryScope> scope;
46};
47
35union TextureInstInfo { 48union TextureInstInfo {
36 u32 raw; 49 u32 raw;
37 BitField<0, 8, TextureType> type; 50 BitField<0, 8, TextureType> type;
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc
index 702372775..d9e0d5471 100644
--- a/src/shader_recompiler/frontend/ir/opcodes.inc
+++ b/src/shader_recompiler/frontend/ir/opcodes.inc
@@ -16,6 +16,9 @@ OPCODE(Return, Void,
16OPCODE(Unreachable, Void, ) 16OPCODE(Unreachable, Void, )
17OPCODE(DemoteToHelperInvocation, Void, Label, ) 17OPCODE(DemoteToHelperInvocation, Void, Label, )
18 18
19// Barriers
20OPCODE(MemoryBarrier, Void, )
21
19// Special operations 22// Special operations
20OPCODE(Prologue, Void, ) 23OPCODE(Prologue, Void, )
21OPCODE(Epilogue, Void, ) 24OPCODE(Epilogue, Void, )
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/barrier_operations.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/barrier_operations.cpp
new file mode 100644
index 000000000..933af572c
--- /dev/null
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/barrier_operations.cpp
@@ -0,0 +1,56 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "common/bit_field.h"
6#include "common/common_types.h"
7#include "shader_recompiler/frontend/ir/modifiers.h"
8#include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
9#include "shader_recompiler/frontend/maxwell/opcodes.h"
10
11namespace Shader::Maxwell {
12namespace {
13// Seems to be in CUDA terminology.
14enum class LocalScope : u64 {
15 CTG = 0,
16 GL = 1,
17 SYS = 2,
18 VC = 3,
19};
20
21IR::MemoryScope LocalScopeToMemoryScope(LocalScope scope) {
22 switch (scope) {
23 case LocalScope::CTG:
24 return IR::MemoryScope::Warp;
25 case LocalScope::GL:
26 return IR::MemoryScope::Device;
27 case LocalScope::SYS:
28 return IR::MemoryScope::System;
29 case LocalScope::VC:
30 return IR::MemoryScope::Workgroup; // or should be device?
31 default:
32 throw NotImplementedException("Unimplemented Local Scope {}", scope);
33 }
34}
35
36} // namespace
37
38void TranslatorVisitor::MEMBAR(u64 inst) {
39 union {
40 u64 raw;
41 BitField<8, 2, LocalScope> scope;
42 } membar{inst};
43 IR::BarrierInstInfo info{};
44 info.scope.Assign(LocalScopeToMemoryScope(membar.scope));
45 ir.MemoryBarrier(info);
46}
47
48void TranslatorVisitor::DEPBAR() {
49 // DEPBAR is a no-op
50}
51
52void TranslatorVisitor::BAR(u64) {
53 throw NotImplementedException("Instruction {} is not implemented", Opcode::BAR);
54}
55
56} // namespace Shader::Maxwell
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
index 83ed0c0fd..80a6ed578 100644
--- a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
@@ -37,10 +37,6 @@ void TranslatorVisitor::B2R(u64) {
37 ThrowNotImplemented(Opcode::B2R); 37 ThrowNotImplemented(Opcode::B2R);
38} 38}
39 39
40void TranslatorVisitor::BAR(u64) {
41 ThrowNotImplemented(Opcode::BAR);
42}
43
44void TranslatorVisitor::BPT(u64) { 40void TranslatorVisitor::BPT(u64) {
45 ThrowNotImplemented(Opcode::BPT); 41 ThrowNotImplemented(Opcode::BPT);
46} 42}
@@ -73,9 +69,6 @@ void TranslatorVisitor::CS2R(u64) {
73 ThrowNotImplemented(Opcode::CS2R); 69 ThrowNotImplemented(Opcode::CS2R);
74} 70}
75 71
76void TranslatorVisitor::DEPBAR() {
77 // DEPBAR is a no-op
78}
79 72
80void TranslatorVisitor::FCHK_reg(u64) { 73void TranslatorVisitor::FCHK_reg(u64) {
81 ThrowNotImplemented(Opcode::FCHK_reg); 74 ThrowNotImplemented(Opcode::FCHK_reg);
@@ -189,10 +182,6 @@ void TranslatorVisitor::LONGJMP(u64) {
189 ThrowNotImplemented(Opcode::LONGJMP); 182 ThrowNotImplemented(Opcode::LONGJMP);
190} 183}
191 184
192void TranslatorVisitor::MEMBAR(u64) {
193 ThrowNotImplemented(Opcode::MEMBAR);
194}
195
196void TranslatorVisitor::NOP(u64) { 185void TranslatorVisitor::NOP(u64) {
197 ThrowNotImplemented(Opcode::NOP); 186 ThrowNotImplemented(Opcode::NOP);
198} 187}