-
Notifications
You must be signed in to change notification settings - Fork 116
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
Improve invalid shader handling #2880
Improve invalid shader handling #2880
Conversation
8ae925f
to
c1021ac
Compare
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.
Thanks. We're generally quite liberal with crashing on invalid SPIR-V input, and many cases just use an assert
. But for catching some early issues like that it may be useful.
llpc/util/llpcShaderModuleHelper.cpp
Outdated
auto codeOrErr = getShaderCode(shaderInfo, codeBuffer); | ||
if (Error err = codeOrErr.takeError()) { | ||
return errorToResult(std::move(err)); | ||
} |
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.
No braces necessary
} | ||
} else { | ||
// Allocator is not specified | ||
return Result::ErrorInvalidPointer; |
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.
This could also be turned into an early-out.
Test summary for commit c1021acCTS tests (Failed: 0/138443)
Ubuntu navi3x, SrdcvkUbuntu navi2x, Srdcvk |
Validation might fail e.g. because the shader entry point is missing. This change allows the error to bubble up through the call stack until vkCreateComputePipelines, instead of killing the app later on with exit code 1. BuildComputePipeline is converted to early-return style.
An invalid SPIR-V binary might contain data that does not match any opCode, and yields a wordCount of zero, triggering an infinite loop. trimSpirvDebugInfo now returns Expected<unsigned> and will give an error in such a situation. Caller functions getShaderCode and getCodeSize (as well as their callers BuildShaderModule and getModuleData) have been updated to handle the error.
c1021ac
to
c7656ef
Compare
Test summary for commit c7656efCTS tests (Failed: 0/138378)
Ubuntu navi3x, SrdcvkUbuntu navi2x, Srdcvk |
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.
Thanks, LGTM
* Make BuildComputePipeline fail if the shader does not pass validation Validation might fail e.g. because the shader entry point is missing. This change allows the error to bubble up through the call stack until vkCreateComputePipelines, instead of killing the app later on with exit code 1. BuildComputePipeline is converted to early-return style. * Prevent trimSpirvDebugInfo from looping indefinitely on invalid input An invalid SPIR-V binary might contain data that does not match any opCode, and yields a wordCount of zero, triggering an infinite loop. trimSpirvDebugInfo now returns Expected<unsigned> and will give an error in such a situation. Caller functions getShaderCode and getCodeSize (as well as their callers BuildShaderModule and getModuleData) have been updated to handle the error.
Prevent
trimSpirvDebugInfo
from looping indefinitely on invalid inputAn invalid SPIR-V binary might contain data that does not match any opCode, and yields a
wordCount
of zero, triggering an infinite loop.trimSpirvDebugInfo
now returnsExpected<unsigned>
and will give an error in such a situation. Caller functionsgetShaderCode
andgetCodeSize
(as well as their callersBuildShaderModule
andgetModuleData
) have been updated to handle the error.Make
BuildComputePipeline
fail if the shader does not pass validationValidation might fail e.g. because the shader entry point is missing. This change allows the error to bubble up through the call stack until
vkCreateComputePipelines
, instead of killing the app later on with exit code 1.BuildComputePipeline
is converted to early-return style.I did not add any test for these conditions, but I could do so if it's considered valuable.