diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_image.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp index a62e2b181..6cf0300ab 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" | 8 | #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" |
| 9 | #include "shader_recompiler/frontend/ir/modifiers.h" | 9 | #include "shader_recompiler/frontend/ir/modifiers.h" |
| 10 | #include "shader_recompiler/frontend/ir/value.h" | 10 | #include "shader_recompiler/frontend/ir/value.h" |
| 11 | #include "shader_recompiler/profile.h" | ||
| 11 | 12 | ||
| 12 | namespace Shader::Backend::GLSL { | 13 | namespace Shader::Backend::GLSL { |
| 13 | namespace { | 14 | namespace { |
| @@ -67,14 +68,14 @@ std::string TexelFetchCastToInt(std::string_view value, const IR::TextureInstInf | |||
| 67 | } | 68 | } |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 70 | std::string ShadowSamplerVecCast(TextureType type) { | 71 | bool NeedsShadowLodExt(TextureType type) { |
| 71 | switch (type) { | 72 | switch (type) { |
| 72 | case TextureType::ColorArray2D: | 73 | case TextureType::ColorArray2D: |
| 73 | case TextureType::ColorCube: | 74 | case TextureType::ColorCube: |
| 74 | case TextureType::ColorArrayCube: | 75 | case TextureType::ColorArrayCube: |
| 75 | return "vec4"; | 76 | return true; |
| 76 | default: | 77 | default: |
| 77 | return "vec3"; | 78 | return false; |
| 78 | } | 79 | } |
| 79 | } | 80 | } |
| 80 | 81 | ||
| @@ -221,7 +222,22 @@ void EmitImageSampleDrefImplicitLod([[maybe_unused]] EmitContext& ctx, | |||
| 221 | } | 222 | } |
| 222 | const auto texture{Texture(ctx, info, index)}; | 223 | const auto texture{Texture(ctx, info, index)}; |
| 223 | const auto bias{info.has_bias ? fmt::format(",{}", bias_lc) : ""}; | 224 | const auto bias{info.has_bias ? fmt::format(",{}", bias_lc) : ""}; |
| 224 | const auto cast{ShadowSamplerVecCast(info.type)}; | 225 | const bool needs_shadow_ext{NeedsShadowLodExt(info.type)}; |
| 226 | const auto cast{needs_shadow_ext ? "vec4" : "vec3"}; | ||
| 227 | const bool use_grad{!ctx.profile.support_gl_texture_shadow_lod && | ||
| 228 | ctx.stage != Stage::Fragment && needs_shadow_ext}; | ||
| 229 | if (use_grad) { | ||
| 230 | // LOG_WARNING(..., "Device lacks GL_EXT_texture_shadow_lod. Using textureGrad fallback"); | ||
| 231 | if (info.type == TextureType::ColorArrayCube) { | ||
| 232 | // LOG_WARNING(..., "textureGrad does not support ColorArrayCube. Stubbing"); | ||
| 233 | ctx.AddF32("{}=0.0f;", inst); | ||
| 234 | return; | ||
| 235 | } | ||
| 236 | const auto d_cast{info.type == TextureType::ColorArray2D ? "vec2" : "vec3"}; | ||
| 237 | ctx.AddF32("{}=textureGrad({},{}({},{}),{}(0),{}(0));", inst, texture, cast, coords, dref, | ||
| 238 | d_cast, d_cast); | ||
| 239 | return; | ||
| 240 | } | ||
| 225 | if (!offset.IsEmpty()) { | 241 | if (!offset.IsEmpty()) { |
| 226 | const auto offset_str{GetOffsetVec(ctx, offset)}; | 242 | const auto offset_str{GetOffsetVec(ctx, offset)}; |
| 227 | if (ctx.stage == Stage::Fragment) { | 243 | if (ctx.stage == Stage::Fragment) { |
| @@ -263,15 +279,29 @@ void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx, | |||
| 263 | throw NotImplementedException("EmitImageSampleDrefExplicitLod Lod clamp samples"); | 279 | throw NotImplementedException("EmitImageSampleDrefExplicitLod Lod clamp samples"); |
| 264 | } | 280 | } |
| 265 | const auto texture{Texture(ctx, info, index)}; | 281 | const auto texture{Texture(ctx, info, index)}; |
| 266 | const auto cast{ShadowSamplerVecCast(info.type)}; | 282 | const bool needs_shadow_ext{NeedsShadowLodExt(info.type)}; |
| 283 | const bool use_grad{!ctx.profile.support_gl_texture_shadow_lod && needs_shadow_ext}; | ||
| 284 | const auto cast{needs_shadow_ext ? "vec4" : "vec3"}; | ||
| 285 | if (use_grad) { | ||
| 286 | // LOG_WARNING(..., "Device lacks GL_EXT_texture_shadow_lod. Using textureGrad fallback"); | ||
| 287 | if (info.type == TextureType::ColorArrayCube) { | ||
| 288 | // LOG_WARNING(..., "textureGrad does not support ColorArrayCube. Stubbing"); | ||
| 289 | ctx.AddF32("{}=0.0f;", inst); | ||
| 290 | return; | ||
| 291 | } | ||
| 292 | const auto d_cast{info.type == TextureType::ColorArray2D ? "vec2" : "vec3"}; | ||
| 293 | ctx.AddF32("{}=textureGrad({},{}({},{}),{}(0),{}(0));", inst, texture, cast, coords, dref, | ||
| 294 | d_cast, d_cast); | ||
| 295 | return; | ||
| 296 | } | ||
| 267 | if (!offset.IsEmpty()) { | 297 | if (!offset.IsEmpty()) { |
| 268 | const auto offset_str{GetOffsetVec(ctx, offset)}; | 298 | const auto offset_str{GetOffsetVec(ctx, offset)}; |
| 269 | if (info.type == TextureType::ColorArrayCube) { | 299 | if (info.type == TextureType::ColorArrayCube) { |
| 270 | ctx.AddF32("{}=textureLodOffset({},{},{},{},{});", inst, texture, coords, dref, lod_lc, | 300 | ctx.AddF32("{}=textureLodOffset({},{},{},{},{});", inst, texture, coords, dref, lod_lc, |
| 271 | offset_str); | 301 | offset_str); |
| 272 | } else { | 302 | } else { |
| 273 | ctx.AddF32("{}=textureLodOffset({},vec3({},{}),{},{});", inst, texture, coords, dref, | 303 | ctx.AddF32("{}=textureLodOffset({},{}({},{}),{},{});", inst, texture, cast, coords, |
| 274 | lod_lc, offset_str); | 304 | dref, lod_lc, offset_str); |
| 275 | } | 305 | } |
| 276 | } else { | 306 | } else { |
| 277 | if (info.type == TextureType::ColorArrayCube) { | 307 | if (info.type == TextureType::ColorArrayCube) { |