stride3d / stride3d/stride

Shader debug should turn off optimizations

Open
#2,972 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #2976 by @Ethereal77 — closed without merging
area-Shaders bug
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:

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.