summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp7
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.h7
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp72
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp6
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_image.cpp3
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_instructions.h12
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp26
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp35
8 files changed, 87 insertions, 81 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index 2bf0def82..0ddc0443b 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -22,9 +22,10 @@ std::string_view InterpDecorator(Interpolation interp) {
22} 22}
23} // namespace 23} // namespace
24 24
25EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_) 25EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
26 : info{program.info}, profile{profile_} { 26 const RuntimeInfo& runtime_info_)
27 std::string header = "#version 450\n"; 27 : info{program.info}, profile{profile_}, runtime_info{runtime_info_} {
28 std::string header = "";
28 SetupExtensions(header); 29 SetupExtensions(header);
29 stage = program.stage; 30 stage = program.stage;
30 switch (program.stage) { 31 switch (program.stage) {
diff --git a/src/shader_recompiler/backend/glsl/emit_context.h b/src/shader_recompiler/backend/glsl/emit_context.h
index 66f70d355..07dad6e57 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.h
+++ b/src/shader_recompiler/backend/glsl/emit_context.h
@@ -16,6 +16,7 @@
16namespace Shader { 16namespace Shader {
17struct Info; 17struct Info;
18struct Profile; 18struct Profile;
19struct RuntimeInfo;
19} // namespace Shader 20} // namespace Shader
20 21
21namespace Shader::Backend { 22namespace Shader::Backend {
@@ -31,7 +32,8 @@ namespace Shader::Backend::GLSL {
31 32
32class EmitContext { 33class EmitContext {
33public: 34public:
34 explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_); 35 explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
36 const RuntimeInfo& runtime_info_);
35 37
36 template <Type type, typename... Args> 38 template <Type type, typename... Args>
37 void Add(const char* format_str, IR::Inst& inst, Args&&... args) { 39 void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
@@ -121,6 +123,7 @@ public:
121 RegAlloc reg_alloc; 123 RegAlloc reg_alloc;
122 const Info& info; 124 const Info& info;
123 const Profile& profile; 125 const Profile& profile;
126 const RuntimeInfo& runtime_info;
124 127
125 Stage stage{}; 128 Stage stage{};
126 std::string_view stage_name = "invalid"; 129 std::string_view stage_name = "invalid";
@@ -131,6 +134,8 @@ public:
131 std::vector<u32> texture_bindings; 134 std::vector<u32> texture_bindings;
132 std::vector<u32> image_bindings; 135 std::vector<u32> image_bindings;
133 136
137 bool uses_y_direction{};
138
134private: 139private:
135 void SetupExtensions(std::string& header); 140 void SetupExtensions(std::string& header);
136 void DefineConstantBuffers(); 141 void DefineConstantBuffers();
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
index aa966a304..22e489aa9 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
@@ -42,25 +42,19 @@ void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie
42 ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]); 42 ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
43} 43}
44 44
45void EmitCompositeInsertU32x2([[maybe_unused]] EmitContext& ctx, 45void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object,
46 [[maybe_unused]] std::string_view composite, 46 u32 index) {
47 [[maybe_unused]] std::string_view object, 47 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
48 [[maybe_unused]] u32 index) {
49 throw NotImplementedException("GLSL Instruction");
50} 48}
51 49
52void EmitCompositeInsertU32x3([[maybe_unused]] EmitContext& ctx, 50void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object,
53 [[maybe_unused]] std::string_view composite, 51 u32 index) {
54 [[maybe_unused]] std::string_view object, 52 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
55 [[maybe_unused]] u32 index) {
56 throw NotImplementedException("GLSL Instruction");
57} 53}
58 54
59void EmitCompositeInsertU32x4([[maybe_unused]] EmitContext& ctx, 55void EmitCompositeInsertU32x4(EmitContext& ctx, std::string_view composite, std::string_view object,
60 [[maybe_unused]] std::string_view composite, 56 u32 index) {
61 [[maybe_unused]] std::string_view object, 57 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
62 [[maybe_unused]] u32 index) {
63 throw NotImplementedException("GLSL Instruction");
64} 58}
65 59
66void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx, 60void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
@@ -153,25 +147,19 @@ void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie
153 ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]); 147 ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
154} 148}
155 149
156void EmitCompositeInsertF32x2([[maybe_unused]] EmitContext& ctx, 150void EmitCompositeInsertF32x2(EmitContext& ctx, std::string_view composite, std::string_view object,
157 [[maybe_unused]] std::string_view composite, 151 u32 index) {
158 [[maybe_unused]] std::string_view object, 152 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
159 [[maybe_unused]] u32 index) {
160 throw NotImplementedException("GLSL Instruction");
161} 153}
162 154
163void EmitCompositeInsertF32x3([[maybe_unused]] EmitContext& ctx, 155void EmitCompositeInsertF32x3(EmitContext& ctx, std::string_view composite, std::string_view object,
164 [[maybe_unused]] std::string_view composite, 156 u32 index) {
165 [[maybe_unused]] std::string_view object, 157 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
166 [[maybe_unused]] u32 index) {
167 throw NotImplementedException("GLSL Instruction");
168} 158}
169 159
170void EmitCompositeInsertF32x4([[maybe_unused]] EmitContext& ctx, 160void EmitCompositeInsertF32x4(EmitContext& ctx, std::string_view composite, std::string_view object,
171 [[maybe_unused]] std::string_view composite, 161 u32 index) {
172 [[maybe_unused]] std::string_view object, 162 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
173 [[maybe_unused]] u32 index) {
174 throw NotImplementedException("GLSL Instruction");
175} 163}
176 164
177void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) { 165void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
@@ -198,24 +186,18 @@ void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
198 throw NotImplementedException("GLSL Instruction"); 186 throw NotImplementedException("GLSL Instruction");
199} 187}
200 188
201void EmitCompositeInsertF64x2([[maybe_unused]] EmitContext& ctx, 189void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
202 [[maybe_unused]] std::string_view composite, 190 u32 index) {
203 [[maybe_unused]] std::string_view object, 191 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
204 [[maybe_unused]] u32 index) {
205 throw NotImplementedException("GLSL Instruction");
206} 192}
207 193
208void EmitCompositeInsertF64x3([[maybe_unused]] EmitContext& ctx, 194void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
209 [[maybe_unused]] std::string_view composite, 195 u32 index) {
210 [[maybe_unused]] std::string_view object, 196 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
211 [[maybe_unused]] u32 index) {
212 throw NotImplementedException("GLSL Instruction");
213} 197}
214 198
215void EmitCompositeInsertF64x4([[maybe_unused]] EmitContext& ctx, 199void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
216 [[maybe_unused]] std::string_view composite, 200 u32 index) {
217 [[maybe_unused]] std::string_view object, 201 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
218 [[maybe_unused]] u32 index) {
219 throw NotImplementedException("GLSL Instruction");
220} 202}
221} // namespace Shader::Backend::GLSL 203} // namespace Shader::Backend::GLSL
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp
index 33aba9fef..6a9b95eca 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp
@@ -124,16 +124,16 @@ void EmitFPLog2(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
124} 124}
125 125
126void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { 126void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
127 ctx.AddF32("{}=1/{};", inst, value); 127 ctx.AddF32("{}=(1.0f)/{};", inst, value);
128} 128}
129 129
130void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { 130void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
131 ctx.AddF64("{}=1/{};", inst, value); 131 ctx.AddF64("{}=1.0/{};", inst, value);
132} 132}
133 133
134void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 134void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
135 [[maybe_unused]] std::string_view value) { 135 [[maybe_unused]] std::string_view value) {
136 ctx.AddF32("{}=1/sqrt({});", inst, value); 136 ctx.AddF32("{}=(1.0f)/sqrt({});", inst, value);
137} 137}
138 138
139void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 139void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
index cc5afc048..1a348b117 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
@@ -37,6 +37,9 @@ void EmitImageSampleImplicitLod([[maybe_unused]] EmitContext& ctx, [[maybe_unuse
37 if (!offset.IsEmpty()) { 37 if (!offset.IsEmpty()) {
38 throw NotImplementedException("Offset"); 38 throw NotImplementedException("Offset");
39 } 39 }
40 if (info.type != TextureType::Color2D) {
41 throw NotImplementedException("Texture type: {}", info.type.Value());
42 }
40 const auto texture{Texture(ctx, info, index)}; 43 const auto texture{Texture(ctx, info, index)};
41 ctx.AddF32x4("{}=texture({},{});", inst, texture, coords); 44 ctx.AddF32x4("{}=texture({},{});", inst, texture, coords);
42} 45}
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
index 295b7a8c4..f08ed0ece 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
@@ -87,7 +87,7 @@ void EmitLocalInvocationId(EmitContext& ctx);
87void EmitInvocationId(EmitContext& ctx); 87void EmitInvocationId(EmitContext& ctx);
88void EmitSampleId(EmitContext& ctx); 88void EmitSampleId(EmitContext& ctx);
89void EmitIsHelperInvocation(EmitContext& ctx); 89void EmitIsHelperInvocation(EmitContext& ctx);
90void EmitYDirection(EmitContext& ctx); 90void EmitYDirection(EmitContext& ctx, IR::Inst& inst);
91void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset); 91void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset);
92void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value); 92void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value);
93void EmitUndefU1(EmitContext& ctx, IR::Inst& inst); 93void EmitUndefU1(EmitContext& ctx, IR::Inst& inst);
@@ -692,11 +692,11 @@ void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
692void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value, 692void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
693 std::string_view index, std::string_view clamp, 693 std::string_view index, std::string_view clamp,
694 std::string_view segmentation_mask); 694 std::string_view segmentation_mask);
695void EmitFSwizzleAdd(EmitContext& ctx, std::string_view op_a, std::string_view op_b, 695void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
696 std::string_view swizzle); 696 std::string_view swizzle);
697void EmitDPdxFine(EmitContext& ctx, std::string_view op_a); 697void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
698void EmitDPdyFine(EmitContext& ctx, std::string_view op_a); 698void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
699void EmitDPdxCoarse(EmitContext& ctx, std::string_view op_a); 699void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
700void EmitDPdyCoarse(EmitContext& ctx, std::string_view op_a); 700void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
701 701
702} // namespace Shader::Backend::GLSL 702} // namespace Shader::Backend::GLSL
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp
index 761145a5d..4dfc0c896 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp
@@ -224,8 +224,9 @@ void EmitIsHelperInvocation(EmitContext& ctx) {
224 NotImplemented(); 224 NotImplemented();
225} 225}
226 226
227void EmitYDirection(EmitContext& ctx) { 227void EmitYDirection(EmitContext& ctx, IR::Inst& inst) {
228 NotImplemented(); 228 ctx.uses_y_direction = true;
229 ctx.AddF32("{}=gl_FrontMaterial.ambient.a;", inst);
229} 230}
230 231
231void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset) { 232void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset) {
@@ -650,25 +651,4 @@ void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view val
650 NotImplemented(); 651 NotImplemented();
651} 652}
652 653
653void EmitFSwizzleAdd(EmitContext& ctx, std::string_view op_a, std::string_view op_b,
654 std::string_view swizzle) {
655 NotImplemented();
656}
657
658void EmitDPdxFine(EmitContext& ctx, std::string_view op_a) {
659 NotImplemented();
660}
661
662void EmitDPdyFine(EmitContext& ctx, std::string_view op_a) {
663 NotImplemented();
664}
665
666void EmitDPdxCoarse(EmitContext& ctx, std::string_view op_a) {
667 NotImplemented();
668}
669
670void EmitDPdyCoarse(EmitContext& ctx, std::string_view op_a) {
671 NotImplemented();
672}
673
674} // namespace Shader::Backend::GLSL 654} // namespace Shader::Backend::GLSL
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp
index e69de29bb..187677878 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp
@@ -0,0 +1,35 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <string_view>
6
7#include "shader_recompiler/backend/glsl/emit_context.h"
8#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
9#include "shader_recompiler/frontend/ir/modifiers.h"
10#include "shader_recompiler/frontend/ir/value.h"
11#include "shader_recompiler/profile.h"
12
13namespace Shader::Backend::GLSL {
14void EmitFSwizzleAdd([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
15 [[maybe_unused]] std::string_view op_a, [[maybe_unused]] std::string_view op_b,
16 [[maybe_unused]] std::string_view swizzle) {
17 throw NotImplementedException("GLSL Instruction");
18}
19
20void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
21 ctx.AddF32("{}=dFdxFine({});", inst, op_a);
22}
23
24void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
25 ctx.AddF32("{}=dFdyFine({});", inst, op_a);
26}
27
28void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
29 ctx.AddF32("{}=dFdxCoarse({});", inst, op_a);
30}
31
32void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
33 ctx.AddF32("{}=dFdyCoarse({});", inst, op_a);
34}
35} // namespace Shader::Backend::GLSL