aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/instructions/extension.cpp
blob: 07cc37e05aa7592d37d5cf5dee1e2a2362b7fa4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* This file is part of the sirit project.
 * Copyright (c) 2018 ReinUsesLisp
 * This software may be used and distributed according to the terms of the GNU
 * Lesser General Public License version 3 or any later version.
 */

#include <memory>
#include <spirv/unified1/GLSL.std.450.h>
#include "common_types.h"
#include "op.h"
#include "sirit/sirit.h"

namespace Sirit {

Id Module::OpExtInst(Id result_type, Id set, u32 instruction, const std::vector<Id>& operands) {
    auto op{std::make_unique<Op>(spv::Op::OpExtInst, bound++, result_type)};
    op->Add(set);
    op->Add(instruction);
    op->Add(operands);
    return AddCode(std::move(op));
}

#define DEFINE_UNARY(funcname, opcode)                                                             \
    Id Module::funcname(Id result_type, Id operand) {                                              \
        return OpExtInst(result_type, GetGLSLstd450(), opcode, operand);                           \
    }

#define DEFINE_BINARY(funcname, opcode)                                                            \
    Id Module::funcname(Id result_type, Id operand_1, Id operand_2) {                              \
        return OpExtInst(result_type, GetGLSLstd450(), opcode, operand_1, operand_2);              \
    }

#define DEFINE_TRINARY(funcname, opcode)                                                           \
    Id Module::funcname(Id result_type, Id operand_1, Id operand_2, Id operand_3) {                \
        return OpExtInst(result_type, GetGLSLstd450(), opcode, operand_1, operand_2, operand_3);   \
    }

DEFINE_UNARY(OpFAbs, GLSLstd450FAbs)
DEFINE_UNARY(OpSAbs, GLSLstd450SAbs)
DEFINE_UNARY(OpRound, GLSLstd450Round)
DEFINE_UNARY(OpRoundEven, GLSLstd450RoundEven)
DEFINE_UNARY(OpTrunc, GLSLstd450Trunc)
DEFINE_UNARY(OpFSign, GLSLstd450FSign)
DEFINE_UNARY(OpSSign, GLSLstd450SSign)
DEFINE_UNARY(OpFloor, GLSLstd450Floor)
DEFINE_UNARY(OpCeil, GLSLstd450Ceil)
DEFINE_UNARY(OpFract, GLSLstd450Fract)
DEFINE_UNARY(OpSin, GLSLstd450Sin)
DEFINE_UNARY(OpCos, GLSLstd450Cos)
DEFINE_UNARY(OpAsin, GLSLstd450Asin)
DEFINE_UNARY(OpAcos, GLSLstd450Acos)
DEFINE_BINARY(OpPow, GLSLstd450Pow)
DEFINE_UNARY(OpExp, GLSLstd450Exp)
DEFINE_UNARY(OpLog, GLSLstd450Log)
DEFINE_UNARY(OpExp2, GLSLstd450Exp2)
DEFINE_UNARY(OpLog2, GLSLstd450Log2)
DEFINE_UNARY(OpSqrt, GLSLstd450Sqrt)
DEFINE_UNARY(OpInverseSqrt, GLSLstd450InverseSqrt)
DEFINE_BINARY(OpFMin, GLSLstd450FMin)
DEFINE_BINARY(OpUMin, GLSLstd450UMin)
DEFINE_BINARY(OpSMin, GLSLstd450SMin)
DEFINE_BINARY(OpFMax, GLSLstd450FMax)
DEFINE_BINARY(OpUMax, GLSLstd450UMax)
DEFINE_BINARY(OpSMax, GLSLstd450SMax)
DEFINE_TRINARY(OpFClamp, GLSLstd450FClamp)
DEFINE_TRINARY(OpUClamp, GLSLstd450UClamp)
DEFINE_TRINARY(OpSClamp, GLSLstd450SClamp)
DEFINE_TRINARY(OpFma, GLSLstd450Fma)
DEFINE_UNARY(OpPackHalf2x16, GLSLstd450PackHalf2x16)
DEFINE_UNARY(OpUnpackHalf2x16, GLSLstd450UnpackHalf2x16)
DEFINE_UNARY(OpFindILsb, GLSLstd450FindILsb)
DEFINE_UNARY(OpFindSMsb, GLSLstd450FindSMsb)
DEFINE_UNARY(OpFindUMsb, GLSLstd450FindUMsb)
DEFINE_UNARY(OpInterpolateAtCentroid, GLSLstd450InterpolateAtCentroid)
DEFINE_BINARY(OpInterpolateAtSample, GLSLstd450InterpolateAtSample)
DEFINE_BINARY(OpInterpolateAtOffset, GLSLstd450InterpolateAtOffset)
} // namespace Sirit