summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl
diff options
context:
space:
mode:
authorGravatar ameerj2021-05-29 01:53:32 -0400
committerGravatar ameerj2021-07-22 21:51:36 -0400
commit7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c (patch)
treecaf39be4349d41c6992691d2d4660501827ed6b0 /src/shader_recompiler/backend/glsl
parentglsl: Implement TEX ImageSample functions (diff)
downloadyuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.tar.gz
yuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.tar.xz
yuzu-7619b7d427437cb58df0f9fc57a7d6b3f5c45f9c.zip
glsl: Implement TEX depth functions
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-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) {
21 throw InvalidArgument("Invalid interpolation {}", interp); 21 throw InvalidArgument("Invalid interpolation {}", interp);
22} 22}
23 23
24std::string_view SamplerType(TextureType type) { 24std::string_view SamplerType(TextureType type, bool is_depth) {
25 if (is_depth) {
26 switch (type) {
27 case TextureType::Color1D:
28 return "sampler1DShadow";
29 case TextureType::ColorArray1D:
30 return "sampler1DArrayShadow";
31 case TextureType::Color2D:
32 return "sampler2DShadow";
33 case TextureType::ColorArray2D:
34 return "sampler2DArrayShadow";
35 case TextureType::ColorCube:
36 return "samplerCubeShadow";
37 case TextureType::ColorArrayCube:
38 return "samplerCubeArrayShadow";
39 default:
40 fmt::print("Texture type: {}", type);
41 throw NotImplementedException("Texture type: {}", type);
42 }
43 }
25 switch (type) { 44 switch (type) {
26 case TextureType::Color1D: 45 case TextureType::Color1D:
27 return "sampler1D"; 46 return "sampler1D";
@@ -110,6 +129,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
110void EmitContext::SetupExtensions(std::string&) { 129void EmitContext::SetupExtensions(std::string&) {
111 header += "#extension GL_ARB_separate_shader_objects : enable\n"; 130 header += "#extension GL_ARB_separate_shader_objects : enable\n";
112 header += "#extension GL_ARB_sparse_texture2 : enable\n"; 131 header += "#extension GL_ARB_sparse_texture2 : enable\n";
132 header += "#extension GL_EXT_texture_shadow_lod : enable\n";
113 // header += "#extension GL_ARB_texture_cube_map_array : enable\n"; 133 // header += "#extension GL_ARB_texture_cube_map_array : enable\n";
114 if (info.uses_int64) { 134 if (info.uses_int64) {
115 header += "#extension GL_ARB_gpu_shader_int64 : enable\n"; 135 header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
@@ -227,7 +247,7 @@ void EmitContext::SetupImages(Bindings& bindings) {
227 } 247 }
228 texture_bindings.reserve(info.texture_descriptors.size()); 248 texture_bindings.reserve(info.texture_descriptors.size());
229 for (const auto& desc : info.texture_descriptors) { 249 for (const auto& desc : info.texture_descriptors) {
230 const auto sampler_type{SamplerType(desc.type)}; 250 const auto sampler_type{SamplerType(desc.type, desc.is_depth)};
231 texture_bindings.push_back(bindings.texture); 251 texture_bindings.push_back(bindings.texture);
232 const auto indices{bindings.texture + desc.count}; 252 const auto indices{bindings.texture + desc.count};
233 for (u32 index = bindings.texture; index < indices; ++index) { 253 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,
120 [[maybe_unused]] std::string_view dref, 120 [[maybe_unused]] std::string_view dref,
121 [[maybe_unused]] std::string_view bias_lc, 121 [[maybe_unused]] std::string_view bias_lc,
122 [[maybe_unused]] const IR::Value& offset) { 122 [[maybe_unused]] const IR::Value& offset) {
123 throw NotImplementedException("GLSL Instruction"); 123 const auto info{inst.Flags<IR::TextureInstInfo>()};
124 if (info.has_bias) {
125 throw NotImplementedException("Bias texture samples");
126 }
127 if (info.has_lod_clamp) {
128 throw NotImplementedException("Lod clamp samples");
129 }
130 const auto bias{info.has_bias ? fmt::format(",{}", bias_lc) : ""};
131 const auto texture{Texture(ctx, info, index)};
132 const auto vec_cast{info.type == TextureType::ColorArrayCube ? "vec4" : "vec3"};
133 ctx.AddF32("{}=texture({},{}({},{}){});", inst, texture, vec_cast, dref, coords, bias);
124} 134}
125 135
126void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx, 136void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx,
@@ -130,7 +140,19 @@ void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx,
130 [[maybe_unused]] std::string_view dref, 140 [[maybe_unused]] std::string_view dref,
131 [[maybe_unused]] std::string_view lod_lc, 141 [[maybe_unused]] std::string_view lod_lc,
132 [[maybe_unused]] const IR::Value& offset) { 142 [[maybe_unused]] const IR::Value& offset) {
133 throw NotImplementedException("GLSL Instruction"); 143 const auto info{inst.Flags<IR::TextureInstInfo>()};
144 if (info.has_bias) {
145 throw NotImplementedException("Bias texture samples");
146 }
147 if (info.has_lod_clamp) {
148 throw NotImplementedException("Lod clamp samples");
149 }
150 const auto texture{Texture(ctx, info, index)};
151 if (info.type == TextureType::ColorArrayCube) {
152 ctx.AddF32("{}=textureLod({},{},{},{});", inst, texture, coords, dref, lod_lc);
153 } else {
154 ctx.AddF32("{}=textureLod({},vec3({},{}),{});", inst, texture, coords, dref, lod_lc);
155 }
134} 156}
135 157
136void EmitImageGather([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 158void EmitImageGather([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,