iosmetalfragment-shadervertex-shader

Is there a way to bind assets once instead of with every command encoder?


I'm rendering a vertex/frag shader with a compute kernel.

Every frame I am binding large assets (such as a 450MB texture) in the usual way:

computeEncoder.setTexture(highResTexture, index: 0)
computeEncoder.setBuffer(largeBuffer, offset: 0, index: 0)
...
renderEncoder.setVertexTexture(highResTexture, index: 0)
renderEncoder.setVertexBuffer(largeBuffer, offset: 0, index: 0)

So that is close to 1GB in bandwidth for a single texture, and I have many more assets totaling a few hundred megs, so that is about 1.5GB that I bind for every frame.

Is there anyway to bind textures/buffers to the GPU once so that they would then be available in the kernel and vertex functions without binding every frame?

I could be wrong, but I thought something was introduced in the one of the last couple WWDCs so thought I would ask to make sure I'm not missing anything.

EDIT:

By simply binding a texture in the vertex function that I have already bound in the compute encoder it does indeed show more texture bandwidth used, even though I am not using it for the capture.

GPU Read Bandwidth:

Without binding the texture: enter image description here

With binding the texture but not using it in any way: enter image description here

Also, if it works as you describe, why does using multiple command encoders warn about wasted bandwidth? If I use more than one emitter, each with a separate encoder, even though they bind identical resources, I get the performance warning:

enter image description here


Solution

  • If you can target a platform that supports residency sets, e.g. iOS18+or equivalent, you can further optimize resource usage by making resources "resident" ahead of time, as opposed to after you commit the command buffer(which is the case when calling a command encoder's methods). It also allows you to keep resources resident indefinitely, as well as making allocations, or multiple resources, resident all at the same time. This will reduce the CPU overhead, especially if you have a lot of resources. Combined with argument buffers and heaps the overhead can be cut substantially.
    Apple documentations on residency sets