-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Disable optimizations in debug when compiling shaders #2976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
* Only for GraphicsProfile 10.0 and above
|
This needs a documentation change to inform about this? And if it does, where and how would be the most appropriate place? |
| // Add debug info if needed | ||
| if (effectParameters.Debug) | ||
| { | ||
| args += " -g"; // Generate debug information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String concatenation creates garbage that needs to be cleaned up by the GC. Let's try to avoid that.
It can be achieved in multiple ways: either with a StringBuilder or with string interpolation (which the compiler can optimize).
For instance (pseudo code):
bool isDebug = ...;
var str = $"{isDebug ? "-D" : ""} some literal {filename}";There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did write it with string concatenation because the function already allocates a lot (to start, two Dictionarys at the top, the ShaderBytecodeResult, the ShaderBytecode, BinarySerializationWriter, MemoryStream, and even calls Encoding.ASCII.GetBytes() several times) 😢.
Also, I tried interpolation, but I think it obfuscates the logic a bit:
string args = $"-V { // Generate SPIR-V binary
(effectParameters.Debug
? effectParameters.Profile < GraphicsProfile.Level_10_0
? "-g" // Generate debug information
: "-g -Od" // Generate debug and disable optimizations (only for level 10.0+)
: "")
} -o {outputFileName} {inputFileName}";This is the version with StringBuilder:
var argsBuilder = new StringBuilder();
argsBuilder.Append("-V"); // Generate SPIR-V binary
if (effectParameters.Debug)
{
argsBuilder.Append(" -g"); // Generate debug information
if (effectParameters.Profile >= GraphicsProfile.Level_10_0)
{
argsBuilder.Append(" -Od"); // Disable optimizations
}
}
argsBuilder.Append($" -o {outputFileName} {inputFileName}");
string args = argsBuilder.ToString();What do you think? Obviously, interpolation just allocates once (the final string), but reads worse, while StringBuilder allocates twice (hopefully, not counting internal buffers), and reads better.
Somewhere here? https://doc.stride3d.net/latest/en/manual/graphics/effects-and-shaders/index.html |
|
Thanks, Vaclav. If needed I'll add to the docs. 😀 But the question was more in the sense of: this change affects very old platforms. Platforms that we may phase out soon anyway. And it is a very specific thing affecting only people who restrict themselves to compile with those low So... do we document it? And if yes, how do we explain this without going into too much low-level depths? |
PR Details
When compiling shaders in debug mode,
ShaderCompilernow disables any optimizations made to the output bytecode. This, however, is not done if shaders are being compiled onGraphicsProfile.Level_9_3or below, as platforms that fall into those categories / graphics APIs had pretty severe limitations in instruction slots, bytecode size, etc., and it makes the compilation fail in those cases.Related Issue
As discussed in issue #2972
Types of changes
Checklist