8.1 Cross-Platform Rendering Thread : Design and Implementation
shader study http://cafe.naver.com/shader
ohyecloudy http://ohyecloudy.com
2011.01.17
ShaderX7
• Motivation
• Overview
• Implementation
• Going Further
• Conclusion
• 프로세서 코어 퍼포먼스는 향상
–하지만 CPU bottleneck 해결은 여전히 문제
• GPU 퍼포먼스는 향상
–플랫폼 그래픽스 API 호출에 여전히 CPU 파워가 필요.
• 렌더링 작업을 decoupling.
– CPU bottleneck 최소화
– GPU 퍼포먼스 낭비를 최소화
• Motivation
• Overview
• Implementation
• Going Further
• Conclusion
Threading Design
Client
Game
Server
API (OpenGL, DirectX, ...)
Command Buffer
DRIV
ER
Server Thread
Game Thread
Server-Client Model
Abstraction Design
• platform-specific 구현을 숨김
• rendering pipeline stage 전체를 커버
Command Objects
• client side
–실제 동작은 없음. request 역할.
• server side
1. server-API 를 사용하는 오브젝트로 빌드.
2. command가 예약된 만큼 실행
• 재생성 필요 없음
Command Buffer
• client와 server를 연결
– client, server는 각 쓰레드가 돌고 있음.
• multi-threading issue가 발생하는 곳
State Machine
• state cache – rendering pipeline 추상화
• binding
– render target state – camera state – light state – material state – transform state – ...
Macro State Objects
• one-to-many 관계 – client state와 server state
• client state – RenderTarget
• server state – clear information and operation (color, flags, ...)
– render buffer characteristics (size, ...)
– post-effects parameters and execution (blur,...)
Driver Execution Process
DirectX
OpenGL
PS3
XDK
...
Game Engine
Client State Cache
Command Buffer
Server Platform Graphics API
State
Command
Build & Dispatch
Bind
Queue
Queue
Queue
Swap
• Motivation
• Overview
• Implementation
• Going Further
• Conclusion
Driver Objects Pattern
Command<<interface>>
+Queue()+Build = 0()+Dispatch = 0()
Client Draw Command<<interface>>
+SetColor()
Server Draw Command
+Build()+Dispatch()
Client Command<<interface>>
+Queue()
Server Command<<interface>>
+Build = 0()+Dispatch = 0()
Client Draw Command Server Draw Command
Command Data<<interface>>
Draw Command Data
+SetColor()
A B
Driver Objects Pattern
Client Command<<interface>>
+Queue()
Server Command<<interface>>
+Build = 0()+Dispatch = 0()
Client Draw Command Server Draw Command
Command Data<<interface>>
Draw Command Data
+SetColor()
• one-to-one X
• client code
• server code
• lifetime이 client, server 분리
Three Command Objects
• client command – queuing
– lifetime management
• command data – server code 실행에 인자로 사용
• server command – platform graphics API-specific code
synchronization : command buffer
• double buffering
– client가 하나를 채우는 동안
– server는 하나를 실행하고 비움
• synchronization points
– client frame end
– server frame end
Thread Safety : Command Data Sharing Policy
• command data에 접근 – client, server 둘 다
– 퍼포먼스가 중요
– thread safe를 보장하지 않음
• 수정이 필요하면 재생성
• refcount > 0 – 수정하려면 재생성.
Thread Safety : Command Locking Strategy
// RAII Object sxCScopeLocker oLock(rCommand); sxCCommandData& rCommandData = oLock.GetData(); if (TestSomething()) { return; }
• Motivation
• Overview
• Implementation
• Going Further
• Conclusion
Optimization : Triple Buffering
Client
Server
Buffer 2
Buffer 2 Buffer 3 Buffer 3
Buffer 3 Buffer 1 Buffer 1
Command Buffer Serialization-Based
• 전체 rendering command sequence 저장
• debugging에 유용하게 사용할 수 있다.
• Motivation
• Overview
• Implementation
• Going Further
• Conclusion
• wait-free rendering thread 구현
• one-to-many 관계
– client, server state
• client-server 접근으로 decoupling
– platform 종속적인 코드는 server에만
Top Related