2019-06-05 03:44:06 +02:00
|
|
|
// 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) {
|
2019-07-16 16:37:11 +02:00
|
|
|
return MakeNode<ConditionalNode>(std::move(condition), std::move(code));
|
2019-06-05 03:44:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2020-03-13 06:50:32 +01:00
|
|
|
case OperationCode::IBitfieldExtract:
|
|
|
|
return OperationCode::UBitfieldExtract;
|
2019-06-05 03:44:06 +02:00
|
|
|
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;
|
2020-03-30 13:47:50 +02:00
|
|
|
case OperationCode::AtomicIExchange:
|
|
|
|
return OperationCode::AtomicUExchange;
|
|
|
|
case OperationCode::AtomicIAdd:
|
|
|
|
return OperationCode::AtomicUAdd;
|
|
|
|
case OperationCode::AtomicIMin:
|
|
|
|
return OperationCode::AtomicUMin;
|
|
|
|
case OperationCode::AtomicIMax:
|
|
|
|
return OperationCode::AtomicUMax;
|
|
|
|
case OperationCode::AtomicIAnd:
|
|
|
|
return OperationCode::AtomicUAnd;
|
|
|
|
case OperationCode::AtomicIOr:
|
|
|
|
return OperationCode::AtomicUOr;
|
|
|
|
case OperationCode::AtomicIXor:
|
|
|
|
return OperationCode::AtomicUXor;
|
2019-06-05 03:44:06 +02:00
|
|
|
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:
|
2020-12-07 06:41:47 +01:00
|
|
|
UNREACHABLE_MSG("Unknown signed operation with code={}", operation_code);
|
2019-06-05 03:44:06 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace VideoCommon::Shader
|