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.
- All OpenGL shader types are editable including Tessellation Control shader, Tessellation Evaluation shader, Geometry Shader, Vertex Shader, Fragment Shader, Compute Shader
- 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.
- GPU PerfStudio keeps a copy of all currently edited shader files in the GPU 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.
- After editing a shader and recompiling it, a single draw call profile or a PerfMarker profile can be obtained.
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.
GPU PerfStudio supports the editing of pre-compiled HLSL shaders, however, you may need to supply the entry point and any macro definitions.
Currently, for DirectX11 shader editing operates on a per shader object basis. How this works is as follows:
- GPU PerfStudio tracks all function calls to D3DCompile and records the compile arguments including the shader source.
- GPU 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 application's 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 GPU PerfStudio's currently edited version.
For OpenGL, shader editing operates on a per program object basis. How this works is as follows:
- GPU PerfStudio tracks all function calls to glUseProgram
- The user selects a shader for editing, makes changes, and clicks on the Compile Shader button. A new program object is created and is mapped to the application's original shader.
- When the application calls a UseProgram function GPU PerfStudio replaces the application's program object 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.
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.
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.
| Enables or disables shader editing |
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 switches back to the app's original shader |
| 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.
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.
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.
To revert your changes click on the Revert button |
|