Use the Graphics Debugger in Microsoft Visual Studio (2012 version or later) to capture individual frames of applications for debugging purposes, from platforms like Unity Editor, Windows Standalone or Universal Windows PlatformAn IAP feature that supports Microsoft’s In App Purchase simulator, which allows you to test IAP purchase flows on devices before publishing your application. More info
See in Glossary.
To install the Graphics Debugger in Visual Studio:
Go to Tools > Get Tools and Features
On the Individual components tab, scroll to Games and Graphics and check the box for Graphics debugger and GPU profiler__ for DirectX__
Click Modify
Wait for installation, then follow the instructions to restart your computer
You should use a built version of your Unity application to capture frames, rather than a version running in the Unity Editor. This is because the Editor might have multiple child windows open at once, and the Graphics Debugger might capture a frame from an unintended window.
To use the Graphics Debugger on either of these two platforms, you need to create a dummy Visual Studio Project:
Launch Visual Studio 2017
Go to File > New > ProjectIn Unity, you use a project to design and develop a game. A project stores all of the files that are related to a game, such as the asset and Scene files. More info
See in Glossary > Visual C++ > Empty Project
Go to Project > Properties > Configuration Properties > Debugging
In the Command field, replace $(TargetPath) with the path to the Unity Editor or Windows Standalone (for example, C:\MyApp\MyApp.exe)
If you want to force Windows Standalone or Unity Editor to run under DirectX 11, select Command Arguments and type -force-d3d11.
Go to Debug > Graphics > Start Graphics Debugging
If everything is configured correctly, Unity displays the following text in the top-left corner of the application:
To capture a frame, use the Print Screen key on your keyboard, or click the Capture Frame box on the left side of the Visual Studio interface.
To debug a shader, you have to compile with debug symbols. To do that, you need to insert #pragma enable_d3d11_debug_symbols.
Your shader should look something like this:
Shader "Custom/NewShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
#pragma enable_d3d11_debug_symbols
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Let’s create a basic example to show the entire process:
Create a new Unity project (see documentation on Getting Started).
In the top menu, go to AssetsAny media or data that can be used in your game or project. An asset may come from a file created outside of Unity, such as a 3D Model, an audio file or an image. You can also create some asset types in Unity, such as an Animator Controller, an Audio Mixer or a Render Texture. More info
See in Glossary > Create > ShaderA small script that contains the mathematical calculations and algorithms for calculating the Color of each pixel rendered, based on the lighting input and the Material configuration. More info
See in Glossary > Standard Surface Shader. This creates a new shader file in your Project folder.
Select the shader file, and in the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary window, click Open. This opens the shader file in your scripting editor. Insert #pragma enable_d3d11_debug_symbols
into the shader code, underneath the other #pragma
lines.
Create a new Material (menu: Assets > Create > MaterialAn asset that defines how a surface should be rendered, by including references to the Textures it uses, tiling information, Color tints and more. The available options for a Material depend on which Shader the Material is using. More info
See in Glossary).
In the Material’s Inspector window, select the Shader dropdown, go to Custom, and select the shader you just created.
Create a 3D cube GameObject (menu: GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary > 3D ObjectA 3D GameObject such as a cube, terrain or ragdoll. More info
See in Glossary > Cube).
Assign your new Material to your new GameObject. To do this, drag the Material from the Project window to the 3D cube.
Build the project for Windows Standalone. Note that real projects might be so large that building them every time you want to debug a shader becomes inefficient; in that case, debug in the Editor, but make sure your capture has profiled the correct window.
Capture a frame, using the steps described above in the section Capture DirectX shaders with Visual Studio.
Your captured frame appears in Visual Studio. Right-click it, and select Pixel.
Click the play button next to the Vertex ShaderA program that runs on each vertex of a 3D model when the model is being rendered. More info
See in Glossary (highlighted in the screenshot above). This opens the vertex shader file:
There is a known issues while working with DirectX 12, in which the play buttons are not available, and the following error appears: This draw call uses system-value semantics that interfere with pixel history computation. If you experience this, use PIX to debug your shaders instead.
When you debug for Universal Windows Platform, you don’t need to create a dummy Visual Studio project, because Unity creates it for you.
Steps to capture a frame and begin shader debugging are the same as they are for the Unity Editor or Windows Standalone.
You can also use RenderDoc to debug shaders. In RenderDoc, you capture the SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary from within the Editor, then use the standalone tool for debugging.
PIX works in a similar way to Visual Studio’s Graphics Debugger. Use PIX instead of the Graphics Debugger to debug DirectX 12 projects.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.