Post

Replies

Boosts

Views

Activity

Accessing data in argument buffers when the first field is [[id(n)]]
I’m having trouble with binding an argument buffer. I’m using spirv_cross to produce MSL from GLSL so my shader setup is a bit unusual and I’m not sure if what I’m trying to do is supported or not. If I set up the argument buffer like this: struct spvDescriptorSetBuffer0 {     /* used by the vertex function only */     constant ArgsTransform* transform [[id(0)]];     /* used by the fragment function only */     constant Args* uniform_buffer [[id(1)]]; }; The shader reads the bound values correctly.  However, I have separate vertex and fragment shader MSL files (because I generate from GLSL using spirv_cross). The MSL for the arg buffer looks like this: Separate vertex MSL file struct spvDescriptorSetBuffer0 {     constant ArgsTransform* transform [[id(0)]]; }; Separate fragment MSL file struct spvDescriptorSetBuffer0 {     constant Args* uniform_buffer [[id(1)]]; }; In this case, when the fragment shader reads uniform_buffer, which is [[id(1)]], it gets the “transform” data that was bound at index 0 (that was set by calling setBuffer(_:offset:index:), passing 0 to index. Adding constant ArgsTransform* transform [[id(0)]]; to that struct in the fragment MSL file makes uniform_buffer return expected values. Is this the intended behavior? The documentation for the function is here: https://developer.apple.com/documentation/metal/mtlargumentencoder/2915785-setbuffer The index of the buffer within the argument buffer. This value corresponds to either the index ID of a Metal shading language declaration or the index field of a MTLArgumentDescriptor object. The docs say "either" - it's not clear to me which one is supposed to take effect here. Either way, I think I am setting BOTH the "index ID of a MSL declaration" and the "index field of MTLArgumentDescriptor" My argument descriptors for the arg buffer are here: MTLArgumentDescriptorInternal: 0x122670cc0 dataType = MTLDataTypePointer index = 0 arrayLength = 0 access = MTLArgumentAccessReadOnly textureType = MTLTextureType2D constantBlockAlignment = default, MTLArgumentDescriptorInternal: 0x122670da0 dataType = MTLDataTypePointer index = 1 arrayLength = 0 access = MTLArgumentAccessReadOnly textureType = MTLTextureType2D constantBlockAlignment = default, I was hoping to make this setup work because if it did, then I could treat argument buffers like vulkan descriptor sets.
4
0
981
Feb ’21