Skip to content

Shader debug should turn off optimizations #2972

@zgxnet

Description

@zgxnet

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:

  1. In program start, set shader debug mode using game.EffectSystem.SetCompilationMode(Stride.CompilationMode.Debug).
  2. Launch using RenderDoc, and debug shader.
  3. 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;
......
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions