Using the Shader Editor

Shader Editing

GPU PerfStudio supports shader editing to help the developer author and debug shaders from inside a running application. The user is able to edit OpenGL GLSL code and DirectX11 HLSL code in the shader Code Window , re-compile it using the original or modified compiler flags, and insert the new shader into the application being debugged. This can significantly speed up the edit/save/app-restart cycle as multiple edits can applied in one debug session without having to restart the app or the debug tools. Re-insertion of the modified shader into the running application allows the user to immediately see the results of their edits and quickly assess their impact. Coupled with the profiler it is possible to measure the performance impact of an edit by doing before and after edit profiles and comparing the results.

Key Features

Can I edit all shaders?

Currently, shader editing is supported in OpenGL and only in DX11 with one shader usage scenario: when the shaders are compiled at runtime using D3DCompile() and the DX11 create shader functions (CreateComputeShader etc.). Please note that D3DCompileFromFile(), D3DCompileFromMemory(), and D3DCompileFromResource() eventually call D3DCompile() and therefore support shader editing.

What about pre-compiled shaders?

GPU PerfStudio supports the editing of pre-compiled HLSL shaders, however, you may need to supply the entry point and any macro definitions.

The Shader Editing Operating Model

Currently, for DirectX11 shader editing operates on a per shader object basis. How this works is as follows:

For OpenGL, shader editing operates on a per program object basis. How this works is as follows:

What this means in practice is that if the app re-uses a shader object pointer in multiple draw calls then all instances of that shader will be replaced with the edited version. This is useful if the task is to optimize an application as a single shader edit can be applied to many draw calls in the frame allowing the user to see the overall performance impact in the scene.

When editing a shader you are not editing the original HLSL file, you are editing that shader object itself - so if the HLSL file gets compiled multiple times (for instance to use a different entrypoint or set different preprocessor definitions), then you may need to make the changes several times - once for each of the different shader objects that were originally compiled.

How to Edit a Shader

Shader editing is supported in the Code Window . The image below shows the code window for a DX11 pixel shader.

The following image shows the state of the shader code window when the shader is first loaded.

HLSLShaderEditing1.png

Along the top of the Code Window there is a button showing a pen and paper in blue. Clicking this button will enable the user to make changes to the shader code in the window.

Edit.png
Enables or disables shader editing

When shader editing is enabled four more buttons become active:

DocumentExport.png
Compiles the current shader and inserts it into the running application
DocumentImport.png
Reverts all edits and switches back to the app's original shader
Floppy.png
Saves the current shader to disk

The content of the constant table can be saved to a file by moving mouse cursor over the table and right clicking.

The following image shows the state of the shader code window when shader editing is enabled. It is now possible to change the shader code. Note in the image below the return value from the shader function has been multiplied by 8.0f. When you have completed your changes click the compile button.

HLSLShaderEditing2.png

Clicking on the compile button will bring up the compiler options user interface (see screen shot below). It is possible to set the compiler flags, code entry point, shader model, and macro definitions. Click on the compile button to insert the shader into your app. Compile errors are reported by a popup dialog on the client.

HLSLShaderEditing3.png

Below is a screen shot after the compilation has taken place. Notice that the swap chain image has been updated to show the effect of the edited shader.

HLSLShaderEditing4.png

Reverting your shader changes

To revert your changes click on the Revert button
Floppy.png