summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
blob: 3697e1a3429715747ca0eabbb0e775ef32a7a6c0 (plain) (blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <string_view>

#include "shader_recompiler/backend/glsl/emit_context.h"
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
#include "shader_recompiler/frontend/ir/value.h"

namespace Shader::Backend::GLSL {
namespace {
static constexpr std::string_view SWIZZLE{"xyzw"};
void CompositeInsert(EmitContext& ctx, std::string_view result, std::string_view composite,
                     std::string_view object, u32 index) {
    ctx.Add("{}={};", result, composite);
    ctx.Add("{}.{}={};", result, SWIZZLE[index], object);
}
} // namespace
void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
                                 std::string_view e2) {
    ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2);
}

void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
                                 std::string_view e2, std::string_view e3) {
    ctx.AddU32x3("{}=uvec3({},{},{});", inst, e1, e2, e3);
}

void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
                                 std::string_view e2, std::string_view e3, std::string_view e4) {
    ctx.AddU32x4("{}=uvec4({},{},{},{});", inst, e1, e2, e3, e4);
}

void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                               u32 index) {
    ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
}

void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                               u32 index) {
    ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
}

void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                               u32 index) {
    ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
}

void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                              std::string_view object, u32 index) {
    const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)};
    CompositeInsert(ctx, ret, composite, object, index);
}

void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                              std::string_view object, u32 index) {
    const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x3)};
    CompositeInsert(ctx, ret, composite, object, index);
}

void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                              std::string_view object, u32 index) {
    const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x4)};
    CompositeInsert(ctx, ret, composite, object, index);
}

void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
                                 [[maybe_unused]] std::string_view e1,
                                 [[maybe_unused]] std::string_view e2) {
    NotImplemented();
}

void EmitCompositeConstructF16x3([[maybe_unused]] EmitContext& ctx,
                                 [[maybe_unused]] std::string_view e1,
                                 [[maybe_unused]] std::string_view e2,
                                 [[maybe_unused]] std::string_view e3) {
    NotImplemented();
}

void EmitCompositeConstructF16x4([[maybe_unused]] EmitContext& ctx,
                                 [[maybe_unused]] std::string_view e1,
                                 [[maybe_unused]] std::string_view e2,
                                 [[maybe_unused]] std::string_view e3,
                                 [[maybe_unused]] std::string_view e4) {
    NotImplemented();
}

void EmitCompositeExtractF16x2([[maybe_unused]] EmitContext& ctx,
                               [[maybe_unused]] std::string_view composite,
                               [[maybe_unused]] u32 index) {
    NotImplemented();
}

void EmitCompositeExtractF16x3([[maybe_unused]] EmitContext& ctx,
                               [[maybe_unused]] std::string_view composite,
                               [[maybe_unused]] u32 index) {
    NotImplemented();
}

void EmitCompositeExtractF16x4([[maybe_unused]] EmitContext& ctx,
                               [[maybe_unused]] std::string_view composite,
                               [[maybe_unused]] u32 index) {
    NotImplemented();
}

void EmitCompositeInsertF16x2([[maybe_unused]] EmitContext& ctx,
                              [[maybe_unused]] std::string_view composite,
                              [[maybe_unused]] std::string_view object,
                              [[maybe_unused]] u32 index) {
    NotImplemented();
}

void EmitCompositeInsertF16x3([[maybe_unused]] EmitContext& ctx,
                              [[maybe_unused]] std::string_view composite,
                              [[maybe_unused]] std::string_view object,
                              [[maybe_unused]] u32 index) {
    NotImplemented();
}

void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx,
                              [[maybe_unused]] std::string_view composite,
                              [[maybe_unused]] std::string_view object,
                              [[maybe_unused]] u32 index) {
    NotImplemented();
}

void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
                                 std::string_view e2) {
    ctx.AddF32x2("{}=vec2({},{});", inst, e1, e2);
}

void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
                                 std::string_view e2, std::string_view e3) {
    ctx.AddF32x3("{}=vec3({},{},{});", inst, e1, e2, e3);
}

void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
                                 std::string_view e2, std::string_view e3, std::string_view e4) {
    ctx.AddF32x4("{}=vec4({},{},{},{});", inst, e1, e2, e3, e4);
}

void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                               u32 index) {
    ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
}

void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                               u32 index) {
    ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
}

void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                               u32 index) {
    ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
}

void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                              std::string_view object, u32 index) {
    const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x2)};
    CompositeInsert(ctx, ret, composite, object, index);
}

void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                              std::string_view object, u32 index) {
    const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x3)};
    CompositeInsert(ctx, ret, composite, object, index);
}

void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
                              std::string_view object, u32 index) {
    const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
    CompositeInsert(ctx, ret, composite, object, index);
}

void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
    NotImplemented();
}

void EmitCompositeConstructF64x3([[maybe_unused]] EmitContext& ctx) {
    NotImplemented();
}

void EmitCompositeConstructF64x4([[maybe_unused]] EmitContext& ctx) {
    NotImplemented();
}

void EmitCompositeExtractF64x2([[maybe_unused]] EmitContext& ctx) {
    NotImplemented();
}

void EmitCompositeExtractF64x3([[maybe_unused]] EmitContext& ctx) {
    NotImplemented();
}

void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
    NotImplemented();
}

void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
                              u32 index) {
    ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}

void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
                              u32 index) {
    ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}

void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
                              u32 index) {
    ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
} // namespace Shader::Backend::GLSL