일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- github
- AR Foundation
- ARProgect
- 인터페이스
- ar
- 확장메서드
- 게임
- 병맛게임
- callbyvalue
- 게임제작
- 게임개발
- 레이캐스트
- AR게임
- 리듬게임에디터
- ExtensionMethod
- 1인개발
- Unity
- 로케트
- 깃허브
- Euler
- raycast
- 리듬게임
- 델리게이트
- Quaternion
- 유니티
- AR세팅
- C#
- 소규모프로젝트
- callbyreference
- 짐벌락
- Today
- Total
Ssssong += Dev
[그래픽스] CBuffer, SRP Batching과 GPU Instancing 본문
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-constants
Shader Constants (HLSL) - Win32 apps
In Shader Model 4, shader constants are stored in one or more buffer resources in memory.
learn.microsoft.com
https://catlikecoding.com/unity/tutorials/scriptable-render-pipeline/custom-shaders/
Custom Shaders
A Unity Scriptable Render Pipeline tutorial about creating custom shaders, supporting batching and GPU instancing.
catlikecoding.com
https://forum.unity.com/threads/srp-batcher-and-gpu-instancing.833362/
SRP Batcher and GPU Instancing?
So I am playing with the SRP Batcher a bit and don't understand how it relates to instancing. For one the 'Batch' and 'Save by batches' numbers seem...
forum.unity.com
Constant Buffer
셰이더 변수를 constant buffer에 등록해두면 같은 버퍼의 데이터 변경이 더 효율적으로 이뤄진다.
유니티는 VP(view, processing) 행렬을 UnityPerFrame 버퍼에 두고 M(model) 행렬을 unityPerDraw 행렬에 둔다.
constant buffer는 cbuffer 키워드를 사용한 구조체처럼 정의된다.
cbuffer UnityPerFrame {
float4x4 unity_MatrixVP;
};
cbuffer UnityPerDraw {
float4x4 unity_ObjectToWorld;
}
유니티에서 constant buffer의 사용은 CBUFFER_START / CBUFFER_END 매크로를 이용한다.
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
CBUFFER_START(UnityPerFrame)
float4x4 unity_MatrixVP;
CBUFFER_END
Batching
한 Drawcall에 묶음으로 그릴 수 있게 하는 것이 Batching이다.
GPU Instancing
동일 메시의 여러 복제본을 한 번에 그리거나 렌더링 할 수 있게 한다.
CPU가 GPU에게 특정 매시 머티리얼 조합을 한 draw call에 여러번 그릴 수 있도록 한다.
같은 메시와 머티리얼을 가진 그룹 오브젝트를 새 메시를 생성하지 않고도 그릴 수 있다.
SRP Batcher와 GPU Instancing
SRP 배칭은 static 배칭처럼 메시들을 합치지 않기 때문에 드로우 콜이 높게 나오지만 각 드로우 콜의 상태 변화에는
빠른 성능을 보여준다.
constant buffer의 이점으로 각기 다른 드로우 콜이 많을 경우의 성능을 올린다.
따라서 SRP batch는 GPU에 상주하는 각 셰이더 배리언트를 사용한 드로우 콜을 뜻하고
각각의 드로우 콜의 코스트를 크게 줄이는 것은 아니다.
SRP 배칭은 모든 지오메트리를 GPU에 보내고 각 메시를 각각의 드로우 콜로 렌더하며
각기 다른 메시들이 같은 셰이더 베리언트를 사용할 때 하나의 배치로 만들 수 있다.
머티리얼마다의 데이터를 시작 시 올린다.
각 draw마다 올라가는 데이터가 줄어들고 CPU와 GPU 간의 통신을 줄일 수 있다.
데이터가 미리 CBUFFER에 올라가 있기 때문에 상태 변화에 유연하다.
GPU Instancing은 SRP 배칭과는 사용하는 버퍼가 다르다.
GPU Instancing은 메시 하나가 GPU로 전송되면 matrices와 MaterialPropertyBlock을 사용하며 여러 번 렌더된다.
같은 머테리얼과 셰이더 베리언트를 사용하는 같은 메시에 대해 한 batch가 될 수 있다.
instance ID로 인덱스된 메시 데이터를 시작 시 한번 올리게 된다. DrawMeshInstanced를 사용해서 수동으로 올리거나
MaterialPropertyBlock을 설정할 수 있다.
많은 양의 같은 오브젝트를 처리하는 CPU에는 빠르다. 다만 인덱스 데이터를 처리해야 하는 GPU 동작은 다소 느리다.
수천 가지의 오브젝트를 그릴 때 GPU는 CPU가 다음에 무엇을 렌더할 지 처리하는 것을 대기하고 있기 때문에
전반적으로 빠르다고 볼 수 있다.
>>GPU Instancing은 Cumpute Buffer를 사용하는데 이건 어떤 버퍼인가?
따라서 각기 다른 여러 종류의 메시가 있을 경우 SRP 배칭을,
같은 종류의 메시가 반복해서 많이 나타날 경우 GPU Instancing이 적용되는 셰이더를 사용하는 것이 좋다.