Skip to content

Swift utility for managing CPU/GPU synchronization of per-frame data resulting in 2x performance in some cases

Notifications You must be signed in to change notification settings

CalebKierum/Multi-Buffer-Access-Management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Triple Buffer Generic Class

Tripple Buffering

Due to confusion around memory management in Swift it may often be difficult for developers to implement the suggested practices that allow for significantly better CPU and GPU usage and 2x the performance when involving dynamic data structures.

I have the suggested practices into a generic class that will allow you to easily implement this in your design.

Here is how you use it:

//On init
let buff = BasicMB<Int>(type: Int.self, maxBuffers: 3, count: 5, device: self.device) else {return nil}

//In update loop

//Wait for GPU to finish reading a slot (recommend usage of a semaphore)
buff.prepareForUpdatePostSemaphore()
for i in 0..<4
{
   // Where 'c' is the data you want to update at that index
   uniformInts.update(dataIn: c, index: i)
}
//Let the GPU know what offset to read from
encoder.setVertexBuffer(trippleBuffer.buffer(), offset: trippleBuffer.offset(), index: 0)

About

Swift utility for managing CPU/GPU synchronization of per-frame data resulting in 2x performance in some cases

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages