While trying to set texture (with memory less storage) from a MTLComputeCommandEncoder
, getting an error that Memoryless storage mode cannot be used with MTLComputeCommandEncoder
(parallel computation)
Documentation,(https://developer.apple.com/documentation/metal/setting_resource_storage_modes/choosing_a_resource_storage_mode_in_ios_and_tvos) is not clear regarding this.
Can memoryless storage mode used for this case? If yes, How?
No. You can only set textures using memoryless storage mode as render targets (i.e. attachments in a MTLRenderPassDescriptor). Memoryless textures are implemented as "tile memory" which are never read from or stored to system memory and therefore no allocation is actually necessary. As such, it's really just "scratch memory" whose contents persist only during the render pass. Reads, samples, or compute writes to textures are always made to the system memory allocation, and since those operations are the only things you can do to a texture when set with setTexture
call, it wouldn't makes sense to ever call setTexture
(or setVertexTexture
or setFragmentTexture
) on a memoryless texture.
If you'd like "scratch memory" that you only need to persist during the lifetime of an encoding pass, you may want to consider using a render command encoder and using a tile shader instead of using a compute command encoder and a compute kernel. WIth a tile shader you can store information to an image block backed by a memoryless texture.