SDFMetalDemo
SDFMetalDemo copied to clipboard
Use function constants for passing mutable data to compute functions.
Passing mutable data to the compute function causes catastrophic degradation in rendering performance.
This is likely due to the data access pattern being unrelated to the pixel position, resulting in a lot of memory flushing.
The latest iOS and OSX releases of metal support function constants in compute functions.
Library compilation is split into two phases, the first phase compiles the library and is run once.
The second phase returns a specific kernel function with the function constants baked in, this is run every time the function constants change, which may be in response to user input.
Using function constants reduces the time to compile a custom version of a kernel to approx 100ms from approx 600ms on an iPhone6+