From bf4dfb3ad4c6419216e8154c970f5577bc1bc475 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Tue, 4 Jun 2019 22:44:06 -0300 Subject: shader: Use shared_ptr to store nodes and move initialization to file Instead of having a vector of unique_ptr stored in a vector and returning star pointers to this, use shared_ptr. While changing initialization code, move it to a separate file when possible. This is a first step to allow code analysis and node generation beyond the ShaderIR class. --- src/video_core/shader/node_helper.h | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/video_core/shader/node_helper.h (limited to 'src/video_core/shader/node_helper.h') 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 +#include +#include +#include +#include +#include + +#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 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 +Node MakeNode(Args&&... args) { + static_assert(std::is_convertible_v); + return std::make_shared(T(std::forward(args)...)); +} + +template +Node Operation(OperationCode code, Args&&... args) { + if constexpr (sizeof...(args) == 0) { + return MakeNode(code); + } else if constexpr (std::is_convertible_v>, + Meta>) { + return MakeNode(code, std::forward(args)...); + } else { + return MakeNode(code, Meta{}, std::forward(args)...); + } +} + +template +Node SignedOperation(OperationCode code, bool is_signed, Args&&... args) { + return Operation(SignedToUnsignedCode(code, is_signed), std::forward(args)...); +} + +} // namespace VideoCommon::Shader -- cgit v1.2.3