Bytes are being bound at index 0 to a shader argument with write access enabled.

Hi all,

I don't understand the error:

validateFunctionArguments:3487: failed assertion `Fragment Function(MyFunction): Bytes are being bound at index 0 to a shader argument with write access enabled.

Does this error pertain to textures or to buffers?

What am I doing wrong:

Code Block
// set input texture
[commandEncoder setFragmentTexture:srcTexture
atIndex:0];
// set params
[commandEncoder setFragmentBytes:&params
length:sizeof(params)
atIndex:0];
[commandEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip
vertexStart:0
vertexCount:4];


The shader function header looks like this:
Code Block
fragment float4 MyFunction(RasterizerData in [[ stage_in ]], device MyParams& params [[ buffer (0) ]], texture2d<half, access::sample> src [[ texture(0) ]])


MyParams is a struct of several floats and simd_float4 (because it seems that I can't use metal's float4 in a C++/Objective-C file. Texture has RenderTarget, ShaderRead and ShaderWrite usage.

Note, that this code seems to have worked in another project, but here it throws this error.

Any help appreciated.
Blind guess but maybe missing a const in
Code Block
device MyParams& params [[ buffer (0) ]]

?
you need to used a "constant" address space, not a "device"

Code Block
fragment float4 MyFunction(
RasterizerData in [[ stage_in ]],
constant MyParams& params [[ buffer (0) ]],
texture2d<half, access::sample> src [[ texture(0) ]]
)

Bytes are being bound at index 0 to a shader argument with write access enabled.
 
 
Q