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;
......
}
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:
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:
fixed: