25
8.1 Cross-Platform Rendering Thread : Design and Implementation shader study http://cafe.naver.com/shader ohyecloudy http://ohyecloudy.com 2011.01.17 ShaderX 7

[shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

  • Upload
    -

  • View
    1.190

  • Download
    3

Embed Size (px)

Citation preview

Page 1: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

8.1 Cross-Platform Rendering Thread : Design and Implementation

shader study http://cafe.naver.com/shader

ohyecloudy http://ohyecloudy.com

2011.01.17

ShaderX7

Page 2: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

• Motivation

• Overview

• Implementation

• Going Further

• Conclusion

Page 3: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

• 프로세서 코어 퍼포먼스는 향상

–하지만 CPU bottleneck 해결은 여전히 문제

• GPU 퍼포먼스는 향상

–플랫폼 그래픽스 API 호출에 여전히 CPU 파워가 필요.

Page 4: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

• 렌더링 작업을 decoupling.

– CPU bottleneck 최소화

– GPU 퍼포먼스 낭비를 최소화

Page 5: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

• Motivation

• Overview

• Implementation

• Going Further

• Conclusion

Page 6: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Threading Design

Client

Game

Server

API (OpenGL, DirectX, ...)

Command Buffer

DRIV

ER

Server Thread

Game Thread

Server-Client Model

Page 7: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Abstraction Design

• platform-specific 구현을 숨김

• rendering pipeline stage 전체를 커버

Page 8: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Command Objects

• client side

–실제 동작은 없음. request 역할.

• server side

1. server-API 를 사용하는 오브젝트로 빌드.

2. command가 예약된 만큼 실행

• 재생성 필요 없음

Page 9: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Command Buffer

• client와 server를 연결

– client, server는 각 쓰레드가 돌고 있음.

• multi-threading issue가 발생하는 곳

Page 10: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

State Machine

• state cache – rendering pipeline 추상화

• binding

– render target state – camera state – light state – material state – transform state – ...

Page 11: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

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,...)

Page 12: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

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

Page 13: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

• Motivation

• Overview

• Implementation

• Going Further

• Conclusion

Page 14: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

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

Page 15: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

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 분리

Page 16: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Three Command Objects

• client command – queuing

– lifetime management

• command data – server code 실행에 인자로 사용

• server command – platform graphics API-specific code

Page 17: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

synchronization : command buffer

• double buffering

– client가 하나를 채우는 동안

– server는 하나를 실행하고 비움

• synchronization points

– client frame end

– server frame end

Page 18: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Thread Safety : Command Data Sharing Policy

• command data에 접근 – client, server 둘 다

– 퍼포먼스가 중요

– thread safe를 보장하지 않음

• 수정이 필요하면 재생성

• refcount > 0 – 수정하려면 재생성.

Page 19: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Thread Safety : Command Locking Strategy

// RAII Object sxCScopeLocker oLock(rCommand); sxCCommandData& rCommandData = oLock.GetData(); if (TestSomething()) { return; }

Page 20: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

• Motivation

• Overview

• Implementation

• Going Further

• Conclusion

Page 21: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Optimization : Triple Buffering

Client

Server

Buffer 2

Buffer 2 Buffer 3 Buffer 3

Buffer 3 Buffer 1 Buffer 1

Page 22: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

Command Buffer Serialization-Based

• 전체 rendering command sequence 저장

• debugging에 유용하게 사용할 수 있다.

Page 23: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

• Motivation

• Overview

• Implementation

• Going Further

• Conclusion

Page 24: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation

• wait-free rendering thread 구현

• one-to-many 관계

– client, server state

• client-server 접근으로 decoupling

– platform 종속적인 코드는 server에만

Page 25: [shaderx7] 8.1 Cross-Platform Rendering Thread : Design and Implementation