summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader/node_helper.h
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2019-06-05 03:44:06 +0200
committerReinUsesLisp <reinuseslisp@airmail.cc>2019-06-06 01:41:52 +0200
commitbf4dfb3ad4c6419216e8154c970f5577bc1bc475 (patch)
treefc03ece18cae31f3a855d6702878027bd1f6134a /src/video_core/shader/node_helper.h
parentMerge pull request #2520 from ReinUsesLisp/vulkan-refresh (diff)
downloadyuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.tar
yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.tar.gz
yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.tar.bz2
yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.tar.lz
yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.tar.xz
yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.tar.zst
yuzu-bf4dfb3ad4c6419216e8154c970f5577bc1bc475.zip
Diffstat (limited to 'src/video_core/shader/node_helper.h')
-rw-r--r--src/video_core/shader/node_helper.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/video_core/shader/node_helper.h b/src/video_core/shader/node_helper.h
new file mode 100644
index 000000000..70547a03d
--- /dev/null
+++ b/src/video_core/shader/node_helper.h
@@ -0,0 +1,60 @@
+// Copyright 2019 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <tuple>
+#include <type_traits>
+#include <utility>
+#include <vector>
+
+#include "common/common_types.h"
+#include "video_core/shader/shader_ir.h"
+
+namespace VideoCommon::Shader {
+
+/// Creates a conditional node
+Node Conditional(Node condition, std::vector<Node> code);
+
+/// Creates a commentary node
+Node Comment(std::string text);
+
+/// Creates an u32 immediate
+Node Immediate(u32 value);
+
+/// Creates a s32 immediate
+Node Immediate(s32 value);
+
+/// Creates a f32 immediate
+Node Immediate(f32 value);
+
+/// Converts an signed operation code to an unsigned operation code
+OperationCode SignedToUnsignedCode(OperationCode operation_code, bool is_signed);
+
+template <typename T, typename... Args>
+Node MakeNode(Args&&... args) {
+ static_assert(std::is_convertible_v<T, NodeData>);
+ return std::make_shared<NodeData>(T(std::forward<Args>(args)...));
+}
+
+template <typename... Args>
+Node Operation(OperationCode code, Args&&... args) {
+ if constexpr (sizeof...(args) == 0) {
+ return MakeNode<OperationNode>(code);
+ } else if constexpr (std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>,
+ Meta>) {
+ return MakeNode<OperationNode>(code, std::forward<Args>(args)...);
+ } else {
+ return MakeNode<OperationNode>(code, Meta{}, std::forward<Args>(args)...);
+ }
+}
+
+template <typename... Args>
+Node SignedOperation(OperationCode code, bool is_signed, Args&&... args) {
+ return Operation(SignedToUnsignedCode(code, is_signed), std::forward<Args>(args)...);
+}
+
+} // namespace VideoCommon::Shader