What is colorAttachment [n] in Metal?

Very new to graphics in general, starting with Metal for immediate needs, will try OpenGL soon.

I wonder what the question implies in terms of the common man. Also, what is the degree "n", I just used it as 0 in the 2D triangle I made.

+3


source to share


1 answer


In general, color nesting is where rendered images are stored (at least temporarily) during the render run. Usually only one color attachment is used at index 0, so what you are doing is fine. It is also possible to render multiple color attachments at the same time, so there is an array. This is an advanced technique that you don't need to worry about until you see the need, and at that point it should be easy how to do it.

There are two places in metal where colorAttachments[n]

. First is found MTLRenderPipelineDescriptor

. The other is at MTLRenderPassDescriptor

.

In both cases, the extent is listed in the Ad Implementation Limits table under Render Targets under the row labeled Maximum Color Render Targets per Render Pass Descriptor.

For MTLRenderPipelineDescriptor

, colorAttachments[n]

is a link to MTLRenderPipelineColorAttachmentDescriptor

. This is where you set up the pixel format, write mask, and color mixing operation.



For MTLRenderPassDescriptor

, colorAttachments[n]

is a link to MTLRenderPassColorAttachmentDescriptor

. This is a subclass MTLRenderPassAttachmentDescriptor

where most of its properties are defined. This is where you set up which part of the texture you will display, what should happen to this texture data, when the start and end render pass and, if it is cleared, what color it should be cleared.

Color attachment information is split into these two objects based on how expensive the cost is. The render pipeline state object is quite expensive to create from a pipeline handle. Typically, you create all pipeline state objects at runtime and reuse them for the rest of your application.

In contrast, you quite often create render renderers from report transfer descriptors; at least once per frame. They are relatively inexpensive to create, so you can change the descriptor and create a new one for rendering elsewhere.

The attachment pixel format in the conveyed region of the render must match the texture pixel format of the attachment color of the render encoder.

+5


source







All Articles