Browse Source
Merge pull request #2552 from ReinUsesLisp/shader-shared-ptr
Merge pull request #2552 from ReinUsesLisp/shader-shared-ptr
shader: Use shared_ptr to store nodes and move initialization to filepull/15/merge
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 296 additions and 248 deletions
-
2src/video_core/CMakeLists.txt
-
62src/video_core/renderer_opengl/gl_shader_decompiler.cpp
-
50src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
-
1src/video_core/shader/decode.cpp
-
1src/video_core/shader/decode/arithmetic.cpp
-
1src/video_core/shader/decode/arithmetic_half.cpp
-
1src/video_core/shader/decode/arithmetic_half_immediate.cpp
-
1src/video_core/shader/decode/arithmetic_immediate.cpp
-
1src/video_core/shader/decode/arithmetic_integer.cpp
-
1src/video_core/shader/decode/arithmetic_integer_immediate.cpp
-
1src/video_core/shader/decode/bfe.cpp
-
1src/video_core/shader/decode/bfi.cpp
-
1src/video_core/shader/decode/conversion.cpp
-
1src/video_core/shader/decode/ffma.cpp
-
1src/video_core/shader/decode/float_set.cpp
-
1src/video_core/shader/decode/float_set_predicate.cpp
-
1src/video_core/shader/decode/half_set.cpp
-
1src/video_core/shader/decode/half_set_predicate.cpp
-
1src/video_core/shader/decode/hfma2.cpp
-
1src/video_core/shader/decode/integer_set.cpp
-
1src/video_core/shader/decode/integer_set_predicate.cpp
-
9src/video_core/shader/decode/memory.cpp
-
1src/video_core/shader/decode/other.cpp
-
1src/video_core/shader/decode/predicate_set_predicate.cpp
-
1src/video_core/shader/decode/predicate_set_register.cpp
-
1src/video_core/shader/decode/register_set_predicate.cpp
-
1src/video_core/shader/decode/shift.cpp
-
9src/video_core/shader/decode/texture.cpp
-
1src/video_core/shader/decode/video.cpp
-
1src/video_core/shader/decode/xmad.cpp
-
99src/video_core/shader/node_helper.cpp
-
60src/video_core/shader/node_helper.h
-
102src/video_core/shader/shader_ir.cpp
-
108src/video_core/shader/shader_ir.h
-
18src/video_core/shader/track.cpp
@ -0,0 +1,99 @@ |
|||||
|
// Copyright 2019 yuzu Emulator Project
|
||||
|
// Licensed under GPLv2 or any later version
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#include <cstring>
|
||||
|
#include <vector>
|
||||
|
|
||||
|
#include "common/common_types.h"
|
||||
|
#include "video_core/shader/node_helper.h"
|
||||
|
#include "video_core/shader/shader_ir.h"
|
||||
|
|
||||
|
namespace VideoCommon::Shader { |
||||
|
|
||||
|
Node Conditional(Node condition, std::vector<Node> code) { |
||||
|
return MakeNode<ConditionalNode>(condition, std::move(code)); |
||||
|
} |
||||
|
|
||||
|
Node Comment(std::string text) { |
||||
|
return MakeNode<CommentNode>(std::move(text)); |
||||
|
} |
||||
|
|
||||
|
Node Immediate(u32 value) { |
||||
|
return MakeNode<ImmediateNode>(value); |
||||
|
} |
||||
|
|
||||
|
Node Immediate(s32 value) { |
||||
|
return Immediate(static_cast<u32>(value)); |
||||
|
} |
||||
|
|
||||
|
Node Immediate(f32 value) { |
||||
|
u32 integral; |
||||
|
std::memcpy(&integral, &value, sizeof(u32)); |
||||
|
return Immediate(integral); |
||||
|
} |
||||
|
|
||||
|
OperationCode SignedToUnsignedCode(OperationCode operation_code, bool is_signed) { |
||||
|
if (is_signed) { |
||||
|
return operation_code; |
||||
|
} |
||||
|
switch (operation_code) { |
||||
|
case OperationCode::FCastInteger: |
||||
|
return OperationCode::FCastUInteger; |
||||
|
case OperationCode::IAdd: |
||||
|
return OperationCode::UAdd; |
||||
|
case OperationCode::IMul: |
||||
|
return OperationCode::UMul; |
||||
|
case OperationCode::IDiv: |
||||
|
return OperationCode::UDiv; |
||||
|
case OperationCode::IMin: |
||||
|
return OperationCode::UMin; |
||||
|
case OperationCode::IMax: |
||||
|
return OperationCode::UMax; |
||||
|
case OperationCode::ICastFloat: |
||||
|
return OperationCode::UCastFloat; |
||||
|
case OperationCode::ICastUnsigned: |
||||
|
return OperationCode::UCastSigned; |
||||
|
case OperationCode::ILogicalShiftLeft: |
||||
|
return OperationCode::ULogicalShiftLeft; |
||||
|
case OperationCode::ILogicalShiftRight: |
||||
|
return OperationCode::ULogicalShiftRight; |
||||
|
case OperationCode::IArithmeticShiftRight: |
||||
|
return OperationCode::UArithmeticShiftRight; |
||||
|
case OperationCode::IBitwiseAnd: |
||||
|
return OperationCode::UBitwiseAnd; |
||||
|
case OperationCode::IBitwiseOr: |
||||
|
return OperationCode::UBitwiseOr; |
||||
|
case OperationCode::IBitwiseXor: |
||||
|
return OperationCode::UBitwiseXor; |
||||
|
case OperationCode::IBitwiseNot: |
||||
|
return OperationCode::UBitwiseNot; |
||||
|
case OperationCode::IBitfieldInsert: |
||||
|
return OperationCode::UBitfieldInsert; |
||||
|
case OperationCode::IBitCount: |
||||
|
return OperationCode::UBitCount; |
||||
|
case OperationCode::LogicalILessThan: |
||||
|
return OperationCode::LogicalULessThan; |
||||
|
case OperationCode::LogicalIEqual: |
||||
|
return OperationCode::LogicalUEqual; |
||||
|
case OperationCode::LogicalILessEqual: |
||||
|
return OperationCode::LogicalULessEqual; |
||||
|
case OperationCode::LogicalIGreaterThan: |
||||
|
return OperationCode::LogicalUGreaterThan; |
||||
|
case OperationCode::LogicalINotEqual: |
||||
|
return OperationCode::LogicalUNotEqual; |
||||
|
case OperationCode::LogicalIGreaterEqual: |
||||
|
return OperationCode::LogicalUGreaterEqual; |
||||
|
case OperationCode::INegate: |
||||
|
UNREACHABLE_MSG("Can't negate an unsigned integer"); |
||||
|
return {}; |
||||
|
case OperationCode::IAbsolute: |
||||
|
UNREACHABLE_MSG("Can't apply absolute to an unsigned integer"); |
||||
|
return {}; |
||||
|
default: |
||||
|
UNREACHABLE_MSG("Unknown signed operation with code={}", static_cast<u32>(operation_code)); |
||||
|
return {}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} // namespace VideoCommon::Shader
|
||||
@ -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 |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue