Page MenuHome

Fix T103635: Fix failing EEVEE and OCIO shader compilations in Metal.
ClosedPublic

Authored by Jason Fielder (jason_apple) on Jan 5 2023, 2:50 PM.

Details

Summary

Affecting render output preview when tone mapping is used, and EEVEE scenes such as Mr Elephant rendering in pink due to missing shaders.

Authored by Apple: Michael Parkin-White

Ref T103635
Ref T96261

Diff Detail

Repository
rB Blender
Branch
viewport_commits/Fix_T103635
Build Status
Buildable 25252
Build 25252: arc lint + arc unit

Event Timeline

Jason Fielder (jason_apple) requested review of this revision.Jan 5 2023, 2:50 PM

Somehow the bug already seems to be fixed in the newest builds.

Clément Foucault (fclem) requested changes to this revision.Jan 7 2023, 5:34 PM
Clément Foucault (fclem) added inline comments.
source/blender/gpu/shaders/metal/mtl_shader_defines.msl
213

If you make offset non optional, you need to change #define texelFetch _texelFetch_internal into #define texelFetch(__tex, __texel, __lod) _texelFetch_internal(__tex, __texel, __lod).

This revision now requires changes to proceed.Jan 7 2023, 5:34 PM
source/blender/gpu/shaders/metal/mtl_shader_defines.msl
213

Thanks for the feedback!

I believe this shouldn't be required, as the first overload variant (with optional LOD) still provides coverage for this case. The purpose of this patch was to remove a redundant, conflicting, definition of the function which utilised Vec<T, n> syntax for the 1D case, which was intended to add support for implicit casts from float to integer coordinates, though these variants are not needed as scalar type T can be used directly.

The second case, was also caused by ambiguity when 3 integer arguments were passed in, as this could either refer to the first function (with optional LOD), or equally, the variant with default offset was also valid. So making the offset non-default ensures that the first two cases (2 and 3 arguments) always default to the first function, and the 4-argument case defaults to second function.

Function 1):

template<typename S, typename T, access A>
inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d<S, A> tex,
                                      T texel,
                                      uint lod = 0)
{
  float w = tex.texture->get_width();
  if (texel >= 0 && texel < w) {
    return tex.texture->read(uint(texel));
  }
  else {
    return vec<S, 4>(0);
  }
}

Provides an overload for
2 arguments texelFetch(Texture, TexelCoord)
3 arguments texelFetch(Texture, TexelCoord, LOD)

The second function (with default offset removed):

template<typename S, typename T, access A>
inline vec<S, 4> _texelFetch_internal(thread _mtl_combined_image_sampler_1d<S, A> tex,
                                      T texel,
                                      uint lod,
                                      T offset)
{
  float w = tex.texture->get_width();
  if ((texel + offset) >= 0 && (texel + offset) < w) {
    /* LODs not supported for 1d textures. This must be zero. */
    return tex.texture->read(uint(texel + offset), 0);
  }
  else {
    return vec<S, 4>(0);
  }
}

Provides coverage for the texelFetchOffset(Tex, TexelCoord, LOD, Offset) case with 4 arguments.

Adding in the macro arguments would always force 3 arguments to be used, which makes sense for the sampler 1D/2D/3D cases, however, for samplerBuffer, texelFetch in GLSL does not expose an LOD parameter, so this could cause secondary issues. The LOD parameter could however be made non-optional for the other cases, if this is preferred.

But please let me know if I've misunderstood!

Clément Foucault (fclem) added inline comments.
source/blender/gpu/shaders/metal/mtl_shader_defines.msl
213

My bad! I understand now. This is all fine.

This revision is now accepted and ready to land.Mon, Jan 16, 1:33 AM
NOTE: this patch should not have any other dependencies and should be able to land directly in master. Subsequent patches for texture sampling optimization and Compute shader support for viewport compositor may need rebasing after this patch has landed.