Search code examples
metal

Is it possible to use a bicubic sampler in metal?


In the compute shader, I can see that bicubic is an option but only if __HAVE_BICUBIC_FILTERING__ is defined. When I set bicubic as the filtering option, I get a syntax error. Linear or Nearest compile fine. I'm building for metal 2 on MacOS.

Another method would be to define the sampler on the CPU with a sampler descriptor but there is no option for bicubic there either.

The comments in this thread discuss their inability to set bicubic.

I've searched the metal shading language specification, and bicubic is not mentioned there at all. Any help would be appreciated.


Solution

  • It depends on the type of device, operating system (version and type), and processor architecture. The code below can be easy compiled on the following configurations: iOS 15, iPhone 12 / 13, Xcode 13.

    #if defined(__HAVE_BICUBIC_FILTERING__)
        constexpr sampler textureSampler (mag_filter::bicubic, min_filter::bicubic);
        const half4 colorSample = colorTexture.sample (textureSampler, in.textureCoordinate);
        return float4(colorSample);
    #endif