PIX 是 Microsoft 为 Windows 开发人员提供的性能调优和调试工具。此工具提供了一系列用于分析应用程序性能的模式,并包括从应用程序中捕获 DirectX 项目的帧以进行调试的功能。
使用 PIX 可调查 Windows 64位 (x86_64) 独立平台或通用 Windows 平台应用程序中的问题。
要安装 PIX,请下载并运行 Microsoft PIX 安装程序,按照说明进行操作。
有关 PIX 的更多信息,请参阅 Microsoft 的 PIX 说明 (Introduction) 和 PIX 文档 (Documentation)。
应使用已构建的 Unity 应用程序版本来捕获帧,而不是使用 Unity Editor 中运行的版本。这是因为需要从 PIX 中启动目标应用程序来才能捕获 GPU 帧。
使用开发版可为 PIX 添加额外的信息,从而使得场景捕获操作更加容易。
要在 PIX 中使用源代码调试着色器,必须将以下 pragma 插入到着色器代码中:#pragma enable_d3d11_debug_symbols
以下演练程序使用一个基本示例演示整个操作过程。
Create a new Unity project (see the Hub documentation on Projects).
在顶部菜单中,选择 Assets > Create > Shader > Standard Surface Shader。此时将在 Project 文件夹中创建一个新的着色器文件。
选择着色器文件,然后在 Inspector 窗口中单击 Open。此时将在脚本编辑器中打开着色器文件。将 #pragma enable_d3d11_debug_symbols
插入到着色器代码中的其他 #pragma
行下面。
创建新的材质(菜单:__Assets__ > Create > __Material__)。
在 Material Inspector 窗口中,选择 Shader 下拉选单,选择 __Custom__,然后选择刚创建的着色器。
创建 3D 立方体游戏对象(菜单:__GameObject__ > 3D Object > __Cube__)。
将新材质分配给新的游戏对象。要执行此操作,请将材质从 Project 窗口拖到 3D 立方体上。
Go to File > Build Settings, and under Platform, select Windows, Mac, Linux. Set the Target Platform to Windows, set the Architecture to Intel 64-bit, and click the Development Build checkbox.
单击 Build。
启动 PIX。
单击 Home__,然后单击 Connect__。
选择计算机 localhost 以使用您的 PC 进行捕获,然后单击 Connect。
在 Select Target Process 对话框中,选择 Launch Win32 选项卡,然后使用 Browse 按钮选择应用程序的可执行文件。注意,这里的“Win32”表示非 UWP 应用程序;您的应用程序文件必须是 64 位二进制文件。
启用 Launch for GPU Capture__,然后使用 Launch__ 按钮启动应用程序。
照常使用应用程序,直到准备好捕获帧。要捕获帧,请按键盘上的 Print Screen 键,或单击 GPU Capture 面板上的摄像机图标。在面板中将显示捕获的缩略图。要打开捕获结果,请单击缩略图。
要开始分析捕获结果,请单击突出显示的文本或菜单栏上的小 Play 图标。
选择 Pipeline __ 选项卡,然后使用 Events__ 窗口导航到您感兴趣的绘图调用。
在 Pipeline 选项卡的下半部分,从 OM (Output Merger) 列表中选择一个渲染目标以查看绘制调用的输出。在要调试的对象上选择一个像素。请注意,为了查找感兴趣的绘制调用,一种方法是可以右键单击像素以查看绘制调用历史记录。
在 Pixel Details 面板上选择 Debug Pixel。
在调试面板上,使用 Shader Options 选择要调试的着色器阶段。
使用工具栏或键盘快捷键逐步执行代码。
有关使用 PIX 调试着色器的更多信息,请参阅 Microsoft 的视频系列 Windows 上的 PIX (PIX on Windows),尤其是第 5 部分 - Debug 选项卡 (Part 5 - Debug Tab)。
有关 PIX 中的 GPU 捕获的更多信息,请参阅 Microsoft 的 GPU 捕获 (GPU Captures) 文档。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.