How to test in a shader if a texture is null

The setTexture() method of a MTLComputeCommandEncoder allows us to use nil as a parameter.

How can I check in the kernel function if the texture parameter is nil or not?


In the documentation I see there is a function called 'is_null_texture'. But the compiler does not know this function. I included already all the header files like <metal_stdlib>, <metal_texture>, <metal_relational>, <metal_common> hoping this would solve the problem.

Is this function maybe wrong in the documentation and has another syntax or does it not exist?

Replies

I got the same problem ! the complier does not kown the function !

Came across this question when I also got stuck on this compiler error.

I figured out that it's because of the deployment target version. iOS 8 is delivered with Metal 1.0, iOS 9 with Metal 1.1, iOS 10 with Metal 1.2. As stated in Metal Shading Language Specification, null texture functions are supported since Metal 1.2. So if the deployment target version is iOS 9.x or older, is_null_texture is not included in building process.

I got the same error for float2x2(float, float, float, float) which is included since Metal 2.0 (iOS 11).