Shader debug should turn off optimizations
Nobody has claimed this yet.
- #2976 by @Ethereal77 — closed without merging
- Dominant language
- C#
- Stars
- 7.8k
- Forks
- 1.2k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 49
Description
Release Type: GitHub source current branch
Version: Latest commit at time of report
Platform(s): Windows
Describe the bug
In shader debug mode (setting by Game.EffectSystem.SetCompilationMode(Stride.CompilationMode.Debug), the compiled shader still has optimizations on.
To Reproduce
Steps to reproduce the behavior:
- In program start, set shader debug mode using game.EffectSystem.SetCompilationMode(Stride.CompilationMode.Debug).
- Launch using RenderDoc, and debug shader.
- It is obvious that the compiled shader is hard to debug as as the optimizations are not turned off.
Expected behavior
The optimizations should be turned off in shader debug mode.
Screenshots
Not applicable.
Log and callstacks
Not applicable.
Additional context
The reason is clear. The main compiler function is Stride.Shaders.Compiler.Direct3D.ShaderCompiler.Compile. In the debug mode, the optimLevel is set to 0, and it calls SharpDX.D3DCompiler.ShaderBytecode.Compile, with flags ShaderFlags.None|ShaderFlags.OptimizationLevel0. In SharpDX, OptimizationLevel0 still has optimizations, to turn off optimization, it should be ShaderFlags.SkipOptimization. So a quick fix can be just a line of code:
Original code in Stride.Shaders.Compiler.Direct3D.ShaderCompiler.Compile:
switch (optimLevel)
{
case 0:
shaderFlags |= ShaderFlags.OptimizationLevel0;
break;
......
}
fixed:
switch (optimLevel)
{
case 0:
shaderFlags |= isDebug ? ShaderFlags.SkipOptimization : ShaderFlags.OptimizationLevel0;
break;
......
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Stride.Shaders.Compiler.Direct3D.ShaderCompiler.Compile and inspect how debug mode selects compiler flags when optimLevel is 0. Reproduce with Game.EffectSystem.SetCompilationMode(Stride.CompilationMode.Debug), launch through RenderDoc, and debug a shader. Done means shader debug mode disables optimizations rather than only selecting optimization level 0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers, computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100