summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-05-28 02:31:03 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:36 +0200
commita752ec88d06c6bcfb13605447a164c6b6915ed6e (patch)
tree5e0bb8f30120199ed4955d402ff0b554db257e2c
parentglsl: Fix non-immediate buffer access (diff)
downloadyuzu-a752ec88d06c6bcfb13605447a164c6b6915ed6e.tar
yuzu-a752ec88d06c6bcfb13605447a164c6b6915ed6e.tar.gz
yuzu-a752ec88d06c6bcfb13605447a164c6b6915ed6e.tar.bz2
yuzu-a752ec88d06c6bcfb13605447a164c6b6915ed6e.tar.lz
yuzu-a752ec88d06c6bcfb13605447a164c6b6915ed6e.tar.xz
yuzu-a752ec88d06c6bcfb13605447a164c6b6915ed6e.tar.zst
yuzu-a752ec88d06c6bcfb13605447a164c6b6915ed6e.zip
-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) {
}
} // namespace
-EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_)
- : info{program.info}, profile{profile_} {
- std::string header = "#version 450\n";
+EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
+ const RuntimeInfo& runtime_info_)
+ : info{program.info}, profile{profile_}, runtime_info{runtime_info_} {
+ std::string header = "";
SetupExtensions(header);
stage = program.stage;
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 @@
namespace Shader {
struct Info;
struct Profile;
+struct RuntimeInfo;
} // namespace Shader
namespace Shader::Backend {
@@ -31,7 +32,8 @@ namespace Shader::Backend::GLSL {
class EmitContext {
public:
- explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_);
+ explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
+ const RuntimeInfo& runtime_info_);
template <Type type, typename... Args>
void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
@@ -121,6 +123,7 @@ public:
RegAlloc reg_alloc;
const Info& info;
const Profile& profile;
+ const RuntimeInfo& runtime_info;
Stage stage{};
std::string_view stage_name = "invalid";
@@ -131,6 +134,8 @@ public:
std::vector<u32> texture_bindings;
std::vector<u32> image_bindings;
+ bool uses_y_direction{};
+
private:
void SetupExtensions(std::string& header);
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
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
}
-void EmitCompositeInsertU32x2([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertU32x2(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
-void EmitCompositeInsertU32x3([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertU32x3(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
-void EmitCompositeInsertU32x4([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertU32x4(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
@@ -153,25 +147,19 @@ void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_vie
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
}
-void EmitCompositeInsertF32x2([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertF32x2(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
-void EmitCompositeInsertF32x3([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertF32x3(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
-void EmitCompositeInsertF32x4([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertF32x4(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
@@ -198,24 +186,18 @@ void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
throw NotImplementedException("GLSL Instruction");
}
-void EmitCompositeInsertF64x2([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
-void EmitCompositeInsertF64x3([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
-void EmitCompositeInsertF64x4([[maybe_unused]] EmitContext& ctx,
- [[maybe_unused]] std::string_view composite,
- [[maybe_unused]] std::string_view object,
- [[maybe_unused]] u32 index) {
- throw NotImplementedException("GLSL Instruction");
+void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
+ u32 index) {
+ ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
}
} // 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) {
}
void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
- ctx.AddF32("{}=1/{};", inst, value);
+ ctx.AddF32("{}=(1.0f)/{};", inst, value);
}
void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
- ctx.AddF64("{}=1/{};", inst, value);
+ ctx.AddF64("{}=1.0/{};", inst, value);
}
void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view value) {
- ctx.AddF32("{}=1/sqrt({});", inst, value);
+ ctx.AddF32("{}=(1.0f)/sqrt({});", inst, value);
}
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
if (!offset.IsEmpty()) {
throw NotImplementedException("Offset");
}
+ if (info.type != TextureType::Color2D) {
+ throw NotImplementedException("Texture type: {}", info.type.Value());
+ }
const auto texture{Texture(ctx, info, index)};
ctx.AddF32x4("{}=texture({},{});", inst, texture, coords);
}
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);
void EmitInvocationId(EmitContext& ctx);
void EmitSampleId(EmitContext& ctx);
void EmitIsHelperInvocation(EmitContext& ctx);
-void EmitYDirection(EmitContext& ctx);
+void EmitYDirection(EmitContext& ctx, IR::Inst& inst);
void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset);
void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value);
void EmitUndefU1(EmitContext& ctx, IR::Inst& inst);
@@ -692,11 +692,11 @@ void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
std::string_view index, std::string_view clamp,
std::string_view segmentation_mask);
-void EmitFSwizzleAdd(EmitContext& ctx, std::string_view op_a, std::string_view op_b,
+void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
std::string_view swizzle);
-void EmitDPdxFine(EmitContext& ctx, std::string_view op_a);
-void EmitDPdyFine(EmitContext& ctx, std::string_view op_a);
-void EmitDPdxCoarse(EmitContext& ctx, std::string_view op_a);
-void EmitDPdyCoarse(EmitContext& ctx, std::string_view op_a);
+void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
+void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
+void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
+void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
} // 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) {
NotImplemented();
}
-void EmitYDirection(EmitContext& ctx) {
- NotImplemented();
+void EmitYDirection(EmitContext& ctx, IR::Inst& inst) {
+ ctx.uses_y_direction = true;
+ ctx.AddF32("{}=gl_FrontMaterial.ambient.a;", inst);
}
void EmitLoadLocal(EmitContext& ctx, std::string_view word_offset) {
@@ -650,25 +651,4 @@ void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view val
NotImplemented();
}
-void EmitFSwizzleAdd(EmitContext& ctx, std::string_view op_a, std::string_view op_b,
- std::string_view swizzle) {
- NotImplemented();
-}
-
-void EmitDPdxFine(EmitContext& ctx, std::string_view op_a) {
- NotImplemented();
-}
-
-void EmitDPdyFine(EmitContext& ctx, std::string_view op_a) {
- NotImplemented();
-}
-
-void EmitDPdxCoarse(EmitContext& ctx, std::string_view op_a) {
- NotImplemented();
-}
-
-void EmitDPdyCoarse(EmitContext& ctx, std::string_view op_a) {
- NotImplemented();
-}
-
} // 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 @@
+// 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/modifiers.h"
+#include "shader_recompiler/frontend/ir/value.h"
+#include "shader_recompiler/profile.h"
+
+namespace Shader::Backend::GLSL {
+void EmitFSwizzleAdd([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
+ [[maybe_unused]] std::string_view op_a, [[maybe_unused]] std::string_view op_b,
+ [[maybe_unused]] std::string_view swizzle) {
+ throw NotImplementedException("GLSL Instruction");
+}
+
+void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
+ ctx.AddF32("{}=dFdxFine({});", inst, op_a);
+}
+
+void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
+ ctx.AddF32("{}=dFdyFine({});", inst, op_a);
+}
+
+void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
+ ctx.AddF32("{}=dFdxCoarse({});", inst, op_a);
+}
+
+void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
+ ctx.AddF32("{}=dFdyCoarse({});", inst, op_a);
+}
+} // namespace Shader::Backend::GLSL