aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/instructions/memory.cpp
blob: 68f0154bbae869d37195eaeeb907972501c16fff (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
/* This file is part of the sirit project.
 * Copyright (c) 2019 sirit
 * This software may be used and distributed according to the terms of the
 * 3-Clause BSD License
 */

#include <cassert>

#include "sirit/sirit.h"

#include "stream.h"

namespace Sirit {

Id Module::OpImageTexelPointer(Id result_type, Id image, Id coordinate, Id sample) {
    code->Reserve(6);
    return *code << OpId{spv::Op::OpImageTexelPointer, result_type} << image << coordinate << sample
                 << EndOp{};
}

Id Module::OpLoad(Id result_type, Id pointer, std::optional<spv::MemoryAccessMask> memory_access) {
    code->Reserve(5);
    return *code << OpId{spv::Op::OpLoad, result_type} << pointer << memory_access << EndOp{};
}

Id Module::OpStore(Id pointer, Id object, std::optional<spv::MemoryAccessMask> memory_access) {
    code->Reserve(4);
    return *code << spv::Op::OpStore << pointer << object << memory_access << EndOp{};
}

Id Module::OpAccessChain(Id result_type, Id base, std::span<const Id> indexes) {
    assert(!indexes.empty());
    code->Reserve(4 + indexes.size());
    return *code << OpId{spv::Op::OpAccessChain, result_type} << base << indexes << EndOp{};
}

Id Module::OpVectorExtractDynamic(Id result_type, Id vector, Id index) {
    code->Reserve(5);
    return *code << OpId{spv::Op::OpVectorExtractDynamic, result_type} << vector << index
                 << EndOp{};
}

Id Module::OpVectorInsertDynamic(Id result_type, Id vector, Id component, Id index) {
    code->Reserve(6);
    return *code << OpId{spv::Op::OpVectorInsertDynamic, result_type} << vector << component
                 << index << EndOp{};
}

Id Module::OpVectorShuffle(Id result_type, Id vector_1, Id vector_2, std::span<const Literal> components) {
    code->Reserve(5 + components.size());
    return *code << OpId{spv::Op::OpVectorShuffle, result_type} << vector_1 << vector_2
                 << components << EndOp{};
}

Id Module::OpCompositeInsert(Id result_type, Id object, Id composite,
                             std::span<const Literal> indexes) {
    code->Reserve(5 + indexes.size());
    return *code << OpId{spv::Op::OpCompositeInsert, result_type} << object << composite << indexes
                 << EndOp{};
}

Id Module::OpCompositeExtract(Id result_type, Id composite, std::span<const Literal> indexes) {
    code->Reserve(4 + indexes.size());
    return *code << OpId{spv::Op::OpCompositeExtract, result_type} << composite << indexes
                 << EndOp{};
}

Id Module::OpCompositeConstruct(Id result_type, std::span<const Id> ids) {
    assert(ids.size() >= 1);
    code->Reserve(3 + ids.size());
    return *code << OpId{spv::Op::OpCompositeConstruct, result_type} << ids << EndOp{};
}

} // namespace Sirit