Residency Set vs storage mode

What's the point of residency sets if you can just make a buffer accessible to the GPU through storage mode in metal?

Answered by DTS Engineer in 901909022

A residency set tells Metal which resources to keep resident for improved memory management. Storage mode does not do that.

Shaders can only use resources that are resident. From "Simplifying GPU resource management with residency sets" (https://developer.apple.com/documentation/metal/simplifying-gpu-resource-management-with-residency-sets): "These resources need to be in memory that's accessible to the GPU, or resident, so the shaders can access their data." Storage mode describes something else. It says where the memory lives and how the CPU can reach it, and you set it once at creation.

There are two ways to say what should be resident. From the same article: "A residency set is one way you tell Metal which resources your app needs to make resident. The other way to tell Metal which resources it needs to make resident is by calling a command encoder's methods."

The encoder methods are useResource(_:usage:stages:) and its relatives. The article also gives the reason to prefer a set: "these methods can impact an app's runtime performance because each call incurs some CPU overhead. Additionally, Metal makes those resources resident right after your app commits the command buffer, which can delay when the GPU starts working on it."

A residency set tells Metal which resources to keep resident for improved memory management. Storage mode does not do that.

Shaders can only use resources that are resident. From "Simplifying GPU resource management with residency sets" (https://developer.apple.com/documentation/metal/simplifying-gpu-resource-management-with-residency-sets): "These resources need to be in memory that's accessible to the GPU, or resident, so the shaders can access their data." Storage mode describes something else. It says where the memory lives and how the CPU can reach it, and you set it once at creation.

There are two ways to say what should be resident. From the same article: "A residency set is one way you tell Metal which resources your app needs to make resident. The other way to tell Metal which resources it needs to make resident is by calling a command encoder's methods."

The encoder methods are useResource(_:usage:stages:) and its relatives. The article also gives the reason to prefer a set: "these methods can impact an app's runtime performance because each call incurs some CPU overhead. Additionally, Metal makes those resources resident right after your app commits the command buffer, which can delay when the GPU starts working on it."

Residency Set vs storage mode
 
 
Q