상세 컨텐츠

본문 제목

Metal의 Color Attachment란?

Graphics

by Arlo 2019. 5. 26. 01:44

본문

원본글 링크

(https://stackoverflow.com/questions/44118942/what-is-colorattachmentn-in-metal)

 

Color Attachment는 Rendering Pass에서 일시적으로 렌더링된 이미지가 저장되는 공간을 말한다. 일반적으로는 하나의 Color Attachment를 사용하므로 0번 인덱스만 사용하는 경우가 많다. 또한 동시에 여러 개의 Color Attachment를 가질 수도 있다. 그렇기 때문에 배열로서 존재하는 것이다. 여러 개의 Attachment를 사용하는 것은 고급 기술로서, 앰비언트 오클루전과 같은 기술을 사용할 수 있다.

 

메탈에서 colorAttachment를 볼 수 있는 곳이 두 군데 있다. MTLRenderPipelineDescriptor와 MTLRenderPassDescriptor이다. 두 경우 모두, 가질 수 있는 Color Attachment의 갯수가 Metal의 Limits Table에 나와있다.

 

MTLRenderPipelineDescriptor에서의 colorAttachments[n]는 MTLRenderPipelineColorAttachmentDescriptor의 오브젝트를 나타내며, 여기에서 픽셀 포맷, Write Mask, 컬러 블렌딩 동작과 같은 설정을 할 수 있다.

 

MTLRenderPassDescriptor에서의 colorAttachments[n]는 MTLRenderPassAttachmentDescriptor의 서브클래스인 MTLRenderPassColorAttachmentDescriptor의 오브젝트를 나타내며, 렌더링 패스에서 어떤 텍스처에 렌더링할 것인지, 텍스쳐의 어떤 영역을 렌더링할 것인지에 대한 설정을 할 수 있다. clear 모드로 설정되어 있다면 어떤 컬러로 clear할 것인지에 대한 것도 지정해줄 수 있다.

 

Render Pipeline State는 생성할 때 비용이 많이 드는 오브젝트이므로 앱의 생명주기에서 필요한 파이프라인 오브젝트들을 단 한 번 생성하여 재사용하며, Render Pass Descriptor를 통해 생성하게 되는 Render Command Encoder는 생성할 때 비용이 적게 드는 오브젝트이므로, 드로잉 사이클 마다 생성하여 사용하게 된다.

 

Render Pipeline State의 Color Attachment Pixel Format은 Render Command Encoder에 넘겨주는 Render Pass Descriptor의 Color Attachment Pixel Format과 반드시 일치해야 한다.