summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-05-29 07:53:32 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:36 +0200
commit7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c (patch)
treecaf39be4349d41c6992691d2d4660501827ed6b0
parentglsl: Implement TEX ImageSample functions (diff)
downloadyuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.tar
yuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.tar.gz
yuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.tar.bz2
yuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.tar.lz
yuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.tar.xz
yuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.tar.zst
yuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.zip
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp24
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_image.cpp26
2 files changed, 46 insertions, 4 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index eb1d8266f..94ba9af7c 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -21,7 +21,26 @@ std::string_view InterpDecorator(Interpolation interp) {
throw InvalidArgument("Invalid interpolation {}", interp);
}
-std::string_view SamplerType(TextureType type) {
+std::string_view SamplerType(TextureType type, bool is_depth) {
+ if (is_depth) {
+ switch (type) {
+ case TextureType::Color1D:
+ return "sampler1DShadow";
+ case TextureType::ColorArray1D:
+ return "sampler1DArrayShadow";
+ case TextureType::Color2D:
+ return "sampler2DShadow";
+ case TextureType::ColorArray2D:
+ return "sampler2DArrayShadow";
+ case TextureType::ColorCube:
+ return "samplerCubeShadow";
+ case TextureType::ColorArrayCube:
+ return "samplerCubeArrayShadow";
+ default:
+ fmt::print("Texture type: {}", type);
+ throw NotImplementedException("Texture type: {}", type);
+ }
+ }
switch (type) {
case TextureType::Color1D:
return "sampler1D";
@@ -110,6 +129,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
void EmitContext::SetupExtensions(std::string&) {
header += "#extension GL_ARB_separate_shader_objects : enable\n";
header += "#extension GL_ARB_sparse_texture2 : enable\n";
+ header += "#extension GL_EXT_texture_shadow_lod : enable\n";
// header += "#extension GL_ARB_texture_cube_map_array : enable\n";
if (info.uses_int64) {
header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
@@ -227,7 +247,7 @@ void EmitContext::SetupImages(Bindings& bindings) {
}
texture_bindings.reserve(info.texture_descriptors.size());
for (const auto& desc : info.texture_descriptors) {
- const auto sampler_type{SamplerType(desc.type)};
+ const auto sampler_type{SamplerType(desc.type, desc.is_depth)};
texture_bindings.push_back(bindings.texture);
const auto indices{bindings.texture + desc.count};
for (u32 index = bindings.texture; index < indices; ++index) {
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
index 71eb3ac2b..4381ed351 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
@@ -120,7 +120,17 @@ void EmitImageSampleDrefImplicitLod([[maybe_unused]] EmitContext& ctx,
[[maybe_unused]] std::string_view dref,
[[maybe_unused]] std::string_view bias_lc,
[[maybe_unused]] const IR::Value& offset) {
- throw NotImplementedException("GLSL Instruction");
+ const auto info{inst.Flags<IR::TextureInstInfo>()};
+ if (info.has_bias) {
+ throw NotImplementedException("Bias texture samples");
+ }
+ if (info.has_lod_clamp) {
+ throw NotImplementedException("Lod clamp samples");
+ }
+ const auto bias{info.has_bias ? fmt::format(",{}", bias_lc) : ""};
+ const auto texture{Texture(ctx, info, index)};
+ const auto vec_cast{info.type == TextureType::ColorArrayCube ? "vec4" : "vec3"};
+ ctx.AddF32("{}=texture({},{}({},{}){});", inst, texture, vec_cast, dref, coords, bias);
}
void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx,
@@ -130,7 +140,19 @@ void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx,
[[maybe_unused]] std::string_view dref,
[[maybe_unused]] std::string_view lod_lc,
[[maybe_unused]] const IR::Value& offset) {
- throw NotImplementedException("GLSL Instruction");
+ const auto info{inst.Flags<IR::TextureInstInfo>()};
+ if (info.has_bias) {
+ throw NotImplementedException("Bias texture samples");
+ }
+ if (info.has_lod_clamp) {
+ throw NotImplementedException("Lod clamp samples");
+ }
+ const auto texture{Texture(ctx, info, index)};
+ if (info.type == TextureType::ColorArrayCube) {
+ ctx.AddF32("{}=textureLod({},{},{},{});", inst, texture, coords, dref, lod_lc);
+ } else {
+ ctx.AddF32("{}=textureLod({},vec3({},{}),{});", inst, texture, coords, dref, lod_lc);
+ }
}
void EmitImageGather([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,