In my Swift iOS Metal App, I would like to have a Metal Shading Language (MSL) kernel like so:
kernel void someKernel(device atomic_uint &counter [[buffer(0)]], ...)
{
...
}
I have 2 questions:
Thank your for help
To answer your initial question:
atomic_uint
maps to a UInt32
type in Swift. MemoryLayout<UInt32>.stride
to allocate. And to add: atomics aren't going to be atomic between CPU and GPU. Meaning, you can't change memory atomically on CPU and see this change atomically on GPU and vice versa. So in the end, this is why it maps to just a UInt32
. To guarantee that CPU sees GPU changes you will need to wait for a buffer to complete by either adding a completion handler or by signaling MTLSharedEvent
on a GPU timeline and making a listener for that event in CPU code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.