PerfStudio 2.5 introduces shader editing as a new feature to help the developer author and debug shaders from inside a running applications. The user is able to edit 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 be 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.
Shader Editing Features
- All DirectX11 shader types are editable including ID3D11ComputeShader, ID3D11VertexShader, ID3D11HullShader, ID3D11DomainShader, ID3D11GeometryShader, and ID3D11PixelShader.
- The compiler flags used in a shader’s re-compilation can be edited in the Shader Compiler Options window (see below).
- Edits can be reverted back to the original application shader.
- PerfStudio keeps a copy of all currently edited shader files in PerfStudio server directory (in a sub-directory named “shaderCache”).
- Includes are supported if the user copies the dependency files into the shaderCache directory. The user is prompted for this if the dependency files are not located.
Can I edit all shaders?
Currently, shader editing is supported 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 therefor support shader editing.
What about pre-compiled shaders?
PerfStudio 2 does not support the editing of pre-compiled shaders at the moment.
The Shader Editing Operating Model
Currently, shader editing operates on a per shader object basis. How this works is as follows:
- PerfStudio tracks all function calls to D3DCompile and records the compile arguments including the shader source.
- PerfStudio also tracks all function calls to create shader functions e.g. CreateComputeShader, CreateVertexShader, CreateHullShader, CreateDomainShader, CreateGeometryShader, CreatePixelShader.
- The user selects a shader for editing, makes changes, and clicks on the Compile Shader button. A new shader object is created and is mapped to the applications original shader.
- When the application calls a set shader function (e.g. CSSetShader, VSSetShader, HSSetShader, DSSetShader, GSSetShader, PSSetShader) PerfStudio replaces the application’s shader object pointer with PerfStudio’s currently edited version.
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. Along the top of the Code Window there is a new 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.
|Enables or disables shader editing|
The following image shows the state of the shader code window when the shader is first loaded.
When shader editing is enabled four more buttons become active:
|Compiles the current shader and inserts it into the running application|
|Reverts all edits and switched back to the apps original shader|
|Opens the Compiler Options window|
|Save the current shader to disk|
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. After your edits have been made click on the compile shader button to open the shader compiler options.
The following image shows the shader compiler options user interface. Make changes to the compiler options prior to compiling your shader. Please note that some compiler options are mutually exclusive and selecting all options may result in a compile error. Compile errors are reported by a popup dialog on the client.
After selecting the options click the Compile button to compile and insert your modified shader.
Click on the revert button to revert back to the original shader.