No matching member function for call to ‘write’ Candidate disabled: ‘lod’ argument must be known at compile-time.

We are using the write function in our Compute Kernel like this to write to the specific mipmap level.

destTexture.write(colorResult, gid, mipmapLevel);


This works nicely on iOS but on Mac it gives me a compile error saying: (No matching member function for call to ‘write’) Candidate disabled: ‘lod’ argument must be known at compile-time.


Do you have any insight into what this means and how we could fix it?

We are on Xcode 8.3 (8E161) and tried Xcode 8.2.1, running 10.12.3.


Thank you,

Replies

Hello


I am not 100% sure, but it brings back memories of trying to use variable texture offset when sampling. Because what (I think) compiler is trying to tell you is that you can't use variable for "lod" argument - that it would accept only a constant there. I looked up Metal Shading Language Specification, and it says nothing about such restrictions of "write" function. But then, it also isn't saying anything about "offset" parameter as used in texture "sample" function, and I believe that similar restrictions _do_ apply there.


So, in short: seems that your hardware/metal version doesn't allow you to write to arbitrary level of texture from compute shader. Or perhaps you're only allowed to write to one level in one shader execution? I believe that options to work around that are as follows:

1) Change shader so that it writes to one fixed lod, and do multiple versions of said shader using #defines (or function constants)

2) Change compute shader to vertex/fragment pair, and compute pipeline to render pipeline, and then bind various levels of texture as render target.


Hope that helps

Michal