計劃 DirectX 移植Plan your DirectX port

總結Summary

計劃從 DirectX 9 到 DirectX 11 與通用 Windows 平台 (UWP) 的遊戲移植專案:升級您的圖形程式碼,並將遊戲放置於 Windows 執行階段環境中。Plan your game porting project from DirectX 9 to DirectX 11 and Universal Windows Platform (UWP): upgrade your graphics code, and put your game in the Windows Runtime environment.

計劃移植圖形程式碼Plan to port graphics code

在您開始將遊戲移植到 UWP 之前,請務必確認您的遊戲不含任何來自 Direct3D 8 的保留功能。Before you begin porting your game to UWP, it's important to ensure that your game does not have any holdovers from Direct3D 8. 請確定您的遊戲未殘留任何固定函式管線。Ensure that your game doesn't have any remnants of the fixed function pipeline. 如需過時功能的完整清單 (包含固定管線功能),請參閱過時的功能For a complete list of deprecated features, including fixed pipeline functionality, see Deprecated Features.

從 Direct3D 9 升級到 Direct3D 11 不只是搜尋與取代的變更。Upgrading from Direct3D 9 to Direct3D 11 is more than a search-and-replace change. 您需要知道 Direct3D 裝置、裝置上下文及圖形基礎結構之間的差異,並了解 Direct3D 9 之後的其他重要變更。You need to know the difference between the Direct3D device, device context, and graphics infrastructure, and learn about other important changes since Direct3D 9. 您可以藉由閱讀本節的其他主題來開始進行這個程序。You can start this process by reading the other topics in this section.

您必須使用自己的協助程式庫或社群工具來取代 D3DX 與 DXUT 協助程式庫。You must replace the D3DX and DXUT helper libraries with your own helper libraries, or with community tools. 如需詳細資訊,請參閱功能對應一節。See the Feature mapping section for more info.

注意   您可以使用DirectX 工具套件DirectXTex來取代先前由 D3DX 和 DXUT 所提供的一些功能。Note   You can use the DirectX Tool Kit or DirectXTex to replace some functionality that was formerly provided by D3DX and DXUT.

 

以組合語言撰寫的著色器應該升級為使用著色器模型4層級 9 _ 1 或 9 _ 3 功能的 HLSL,而針對效果程式庫所撰寫的著色器必須更新為較新版本的 HLSL 語法。Shaders written in assembly language should be upgraded to HLSL using shader model 4 level 9_1 or 9_3 functionality, and shaders written for the Effects library will need to be updated to a more recent version of HLSL syntax. 如需詳細資訊,請參閱功能對應一節。See the Feature mapping section for more info.

熟悉不同的 Direct3D 功能層級Get familiar with the different Direct3D feature levels. 功能層級可以藉由定義已知的功能組合,將範圍廣泛的視訊硬體分類。Feature levels classify a wide range of video hardware by defining sets of known functionality. 每一組大致上都會對應到 Direct3D 版本 (從 9.1 到 11.2)。Each set roughly corresponds to versions of Direct3D, from 9.1 through 11.2. 所有功能層級都使用 DirectX 11 API。All feature levels use the DirectX 11 API.

計劃將 Win32 UI 程式碼移植到 CoreWindowPlan to port Win32 UI code to CoreWindow

UWP app 會在針對名稱為 CoreWindow 的 app 容器所建立的視窗中執行。UWP apps run in a window created for an app container, called a CoreWindow. 您的遊戲可以藉由從 IFrameworkView 繼承以控制視窗,這樣所需的實作細節會比桌面視窗來得少。Your game controls the window by inheriting from IFrameworkView, which requires less implementation details than a desktop window. 遊戲的主迴圈將位於 IFrameworkView::Run 方法內。Your game's main loop will be in the IFrameworkView::Run method.

UWP app 的週期與傳統型 app 的週期有很大的差別。The lifecycle of a UWP app is very different from a desktop app. 您將需要經常儲存遊戲,因為在發生暫停事件時,app 能夠用來停止執行程式碼的時間有限,而且您想要確認當 app 繼續執行時,玩家能夠立即回到他們原先所在的位置。You'll need to save the game often, because when a suspend event happens your app only has a limited amount of time to stop running code, and you want to make sure the player can get back to where they were right away when your app resumes. 遊戲的儲存頻率必須足以維持繼續進行遊戲之後有持續進行遊戲的使用經驗,但不要讓遊戲儲存頻率高到影響畫面播放速率或導致遊戲間斷。Games should save just often enough to maintain a continuous gameplay experience from resume, but not so often that the game saves impact framerate or cause the game to stutter. 當遊戲從終止狀態繼續執行時,該遊戲可能需要載入遊戲狀態。Your game will potentially need to load game state when the game resumes from a terminated state.

DirectXMath 可以用來做為 D3DXMath 與 XNAMath 的替代項目,而且如果您需要數學程式庫,它就可以派上用場。DirectXMath can be used as a replacement for D3DXMath and XNAMath, and it can come in handy if you need a math library. DirectXMath 含有快速的可攜式資料類型,以及已對齊且封裝來與著色器搭配使用的類型。DirectXMath has fast, portable data types, and types that are aligned and packed for use with shaders.

已將像是連鎖 API 的原生程式庫加以延伸,以支援 ARM 內建函式。Native libraries such as the Interlocked API have been expanded to support ARM intrinsics. 如果遊戲使用連鎖 API,則可持續在 DirectX 11 與 UWP 中使用它們。If your game uses interlocked APIs, you can keep using them in DirectX 11 and UWP.

我們的範本和程式碼範例會使用您可能還不熟悉的 C++ 新功能。Our templates and code samples use new C++ features that you might not be familiar with yet. 例如,將非同步方法搭配 lambda expressions 用來載入 Direct3D 資源,而不需封鎖 UI 執行緒。For example, asynchronous methods are used with lambda expressions to load Direct3D resources without blocking the UI thread.

您通常會使用的概念有兩種:There are two concepts you'll use often:

  • Managed 參考 (^ 運算子) 和 Managed 類別 (ref 類別) 都是 Windows 執行階段的基本部分。Managed references (^ operator) and managed classes (ref classes) are a fundamental part of the Windows Runtime. 您需要為含有 Windows 執行階段元件的介面使用 Managed ref 類別,例如 IFrameworkView (逐步解說中將提供更多相關資訊)。You will need to use managed ref classes to interface with Windows Runtime components, for example IFrameworkView (more on that in the walkthrough).
  • 使用 Direct3D 11 COM 介面時,請使用 Microsoft::WRL::ComPtr 範本類型,讓 COM 指標更容易使用。When working with Direct3D 11 COM interfaces, use the Microsoft::WRL::ComPtr template type to make COM pointers easier to use.