diff options
Diffstat (limited to 'src/shader_recompiler/backend')
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 | ||
| 25 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_) | 25 | EmitContext::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 @@ | |||
| 16 | namespace Shader { | 16 | namespace Shader { |
| 17 | struct Info; | 17 | struct Info; |
| 18 | struct Profile; | 18 | struct Profile; |
| 19 | struct RuntimeInfo; | ||
| 19 | } // namespace Shader | 20 | } // namespace Shader |
| 20 | 21 | ||
| 21 | namespace Shader::Backend { | 22 | namespace Shader::Backend { |
| @@ -31,7 +32,8 @@ namespace Shader::Backend::GLSL { | |||
| 31 | 32 | ||
| 32 | class EmitContext { | 33 | class EmitContext { |
| 33 | public: | 34 | public: |
| 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 | |||
| 134 | private: | 139 | private: |
| 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 | ||
| 45 | void EmitCompositeInsertU32x2([[maybe_unused]] EmitContext& ctx, | 45 | void 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 | ||
| 52 | void EmitCompositeInsertU32x3([[maybe_unused]] EmitContext& ctx, | 50 | void 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 | ||
| 59 | void EmitCompositeInsertU32x4([[maybe_unused]] EmitContext& ctx, | 55 | void 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 | ||
| 66 | void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx, | 60 | void 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 | ||
| 156 | void EmitCompositeInsertF32x2([[maybe_unused]] EmitContext& ctx, | 150 | void 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 | ||
| 163 | void EmitCompositeInsertF32x3([[maybe_unused]] EmitContext& ctx, | 155 | void 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 | ||
| 170 | void EmitCompositeInsertF32x4([[maybe_unused]] EmitContext& ctx, | 160 | void 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 | ||
| 177 | void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) { | 165 | void 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 | ||
| 201 | void EmitCompositeInsertF64x2([[maybe_unused]] EmitContext& ctx, | 189 | void 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 | ||
| 208 | void EmitCompositeInsertF64x3([[maybe_unused]] EmitContext& ctx, | 194 | void 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 | ||
| 215 | void EmitCompositeInsertF64x4([[maybe_unused]] EmitContext& ctx, | 199 | void 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 | ||
| 126 | void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 126 | void 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 | ||
| 130 | void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 130 | void 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 | ||
| 134 | void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 134 | void 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 | ||
| 139 | void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 139 | void 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); | |||
| 87 | void EmitInvocationId(EmitContext& ctx); | 87 | void EmitInvocationId(EmitContext& ctx); |
| 88 | void EmitSampleId(EmitContext& ctx); | 88 | void EmitSampleId(EmitContext& ctx); |
| 89 | void EmitIsHelperInvocation(EmitContext& ctx); | 89 | void EmitIsHelperInvocation(EmitContext& ctx); |
| 90 | void EmitYDirection(EmitContext& ctx); | 90 | void EmitYDirection(EmitContext& ctx, IR::Inst& inst); |
| 91 | void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset); | 91 | void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset); |
| 92 | void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value); | 92 | void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value); |
| 93 | void EmitUndefU1(EmitContext& ctx, IR::Inst& inst); | 93 | void EmitUndefU1(EmitContext& ctx, IR::Inst& inst); |
| @@ -692,11 +692,11 @@ void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value, | |||
| 692 | void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value, | 692 | void 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); |
| 695 | void EmitFSwizzleAdd(EmitContext& ctx, std::string_view op_a, std::string_view op_b, | 695 | void 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); |
| 697 | void EmitDPdxFine(EmitContext& ctx, std::string_view op_a); | 697 | void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a); |
| 698 | void EmitDPdyFine(EmitContext& ctx, std::string_view op_a); | 698 | void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a); |
| 699 | void EmitDPdxCoarse(EmitContext& ctx, std::string_view op_a); | 699 | void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a); |
| 700 | void EmitDPdyCoarse(EmitContext& ctx, std::string_view op_a); | 700 | void 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 | ||
| 227 | void EmitYDirection(EmitContext& ctx) { | 227 | void 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 | ||
| 231 | void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset) { | 232 | void 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 | ||
| 653 | void EmitFSwizzleAdd(EmitContext& ctx, std::string_view op_a, std::string_view op_b, | ||
| 654 | std::string_view swizzle) { | ||
| 655 | NotImplemented(); | ||
| 656 | } | ||
| 657 | |||
| 658 | void EmitDPdxFine(EmitContext& ctx, std::string_view op_a) { | ||
| 659 | NotImplemented(); | ||
| 660 | } | ||
| 661 | |||
| 662 | void EmitDPdyFine(EmitContext& ctx, std::string_view op_a) { | ||
| 663 | NotImplemented(); | ||
| 664 | } | ||
| 665 | |||
| 666 | void EmitDPdxCoarse(EmitContext& ctx, std::string_view op_a) { | ||
| 667 | NotImplemented(); | ||
| 668 | } | ||
| 669 | |||
| 670 | void 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 | |||
| 13 | namespace Shader::Backend::GLSL { | ||
| 14 | void 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 | |||
| 20 | void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) { | ||
| 21 | ctx.AddF32("{}=dFdxFine({});", inst, op_a); | ||
| 22 | } | ||
| 23 | |||
| 24 | void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) { | ||
| 25 | ctx.AddF32("{}=dFdyFine({});", inst, op_a); | ||
| 26 | } | ||
| 27 | |||
| 28 | void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) { | ||
| 29 | ctx.AddF32("{}=dFdxCoarse({});", inst, op_a); | ||
| 30 | } | ||
| 31 | |||
| 32 | void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) { | ||
| 33 | ctx.AddF32("{}=dFdyCoarse({});", inst, op_a); | ||
| 34 | } | ||
| 35 | } // namespace Shader::Backend::GLSL | ||