[shaderx6]8.2 3d engine tools with c++cli

22
8.2 3D Engine Tools with C++/CLI ohyecloudyhttp://ohyecloudy.com shader studyhttp://cafe.naver.com/shader 2010.12.06 ShaderX 6

Transcript of [shaderx6]8.2 3d engine tools with c++cli

Page 1: [shaderx6]8.2 3d engine tools with c++cli

8.2 3D Engine Tools with C++/CLI

ohyecloudyhttp://ohyecloudy.com

shader studyhttp://cafe.naver.com/shader

2010.12.06

ShaderX6

Page 2: [shaderx6]8.2 3d engine tools with c++cli

Introduction

What Is C++/CLI?

General Programming Considerations

Page 3: [shaderx6]8.2 3d engine tools with c++cli

MS에서 .NET platform을 밀고 있음.

툴 작성이 더 편리해짐. GUI 쪽이 많이 편함.

Windows Forms

WPF Windows Presentation Foundation

작성했던 C++ 코드를 다 버려야 하나?

C++/CLI C++, .NET framework 징검다리 역할.

Page 4: [shaderx6]8.2 3d engine tools with c++cli

Introduction

What Is C++/CLI?

General Programming Considerations

Page 5: [shaderx6]8.2 3d engine tools with c++cli

http://en.wikipedia.org/wiki/Common_Language_Infrastructure

C++ /CLI

Compiler

Page 6: [shaderx6]8.2 3d engine tools with c++cli

가능한 애플리케이션

3D object visualization tools

Level editors

Conversion tools and plug-ins

Page 7: [shaderx6]8.2 3d engine tools with c++cli

어떻게 달라졌나?

heap이 두 종류 pure c++ heap garbage collected heap

pure c++ heap control * ctrl = new button();

garbage collected heap

control ^ ctrl = gcnew button();

Page 8: [shaderx6]8.2 3d engine tools with c++cli

어떻게 달라졌나?

소멸자에서 Dispose() 호출

키워드 추가 property, delegate, event

Language Features for Targeting the CLR

http://goo.gl/cPq7b

Page 9: [shaderx6]8.2 3d engine tools with c++cli

장점

DLLImport 필요 없다. Win32 바로 호출

C++ 컴파일러 최적화 젂략 여젂히 유효. .NET, C++ 라이브러리를 사용 가능. 다른 .NET 언어에서 사용 가능

C++/CLI로 만든 컴포넌트를

Page 10: [shaderx6]8.2 3d engine tools with c++cli

단점

컴파일러가 상대적으로 최근에 만들어짐

몇 가지 제한 DLLMain에서 .NET 코드를 호출하지 못함

managed 와 unmanaged

컨텍스트 스위칭에 비용이 크다.

Page 11: [shaderx6]8.2 3d engine tools with c++cli

Introduction

What Is C++/CLI?

General Programming Considerations

Page 12: [shaderx6]8.2 3d engine tools with c++cli

Minimize Context Switches

컨텍스트 스위칭 비용 native와 managed code 사이

50~300 cycles

Page 13: [shaderx6]8.2 3d engine tools with c++cli

Minimize Context Switches

컨텍스트 스위칭이 빈번 List<Vector3>^ : managed

DrawInstance : native

이런 경우엔 native array를 사용

List<Vector3>^ instancePos = world->GetTreeInstances(); for each (Vector3 pos in instancePos) pRenderer->DrawInstance(pGeo, pos.x, pos.y, pos.z);

Page 14: [shaderx6]8.2 3d engine tools with c++cli

Force Time-Critical Functions to Be Native

컴파일러 동작 과정 먼저 C++ 함수를 MSIL로 컴파일

실패하면 native로 컴파일

바로 native로 컴파일 inline, naked, #pragma unmanaged

Page 15: [shaderx6]8.2 3d engine tools with c++cli

Double Thunking

managed와 native가 섞인 코드 모듈이

컴파일됐을 때 entry point를 두 개 생성.

두 개 다 검사하는 double thunking 발생.

Page 16: [shaderx6]8.2 3d engine tools with c++cli

Exchanging Data

heap이 두 종류 pure c++ heap

garbage collected heap

간단한 타입은 잘 동작

복잡한 타입인 경우 바로 접근은 불가능 arrays, strings

Page 17: [shaderx6]8.2 3d engine tools with c++cli

Exchanging Data

// native function call int adaptersCount = pD3D->GetAdapterCount(); this->adaptersTextBox->Text = adaptersCount.ToString();

fwrite( textBox->Text, sizeof(char), textbox->Text->Length, pFile);

컴파일 성공

컴파일 실패

Page 18: [shaderx6]8.2 3d engine tools with c++cli

Pointers and Keeping References

가능

ref class WorldEntity // A managed class { ... private: CMesh* m_graphicalRep; // native pointer };

Page 19: [shaderx6]8.2 3d engine tools with c++cli

Pointers and Keeping References

Marshal 클래스가 가능하게 해준다.

native VARIANT 구조체를 대신 사용 16 bytes

class CMesh : public CPlacable3D { ... private: WorldEntity^ m_properties // reference managed object };

Page 20: [shaderx6]8.2 3d engine tools with c++cli

Introduction

What Is C++/CLI?

General Programming Considerations

Page 21: [shaderx6]8.2 3d engine tools with c++cli
Page 22: [shaderx6]8.2 3d engine tools with c++cli