Switch over to using CheckSpvcSuccess where possible

BUG=dawn:274

Change-Id: Ia7bfc96a2a85bff5b30065e7b985e0d84c8dcd4b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15120
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Ryan Harrison 2020-01-15 16:58:23 +00:00 committed by Commit Bot service account
parent 5dc07d1b1b
commit 855a24b150
5 changed files with 27 additions and 40 deletions

View File

@ -82,6 +82,8 @@ namespace dawn_native {
};
protected:
static MaybeError CheckSpvcSuccess(shaderc_spvc_status status, const char* error_msg);
shaderc_spvc::Context mSpvcContext;
private:
@ -94,8 +96,6 @@ namespace dawn_native {
MaybeError ExtractSpirvInfoWithSpvc();
MaybeError ExtractSpirvInfoWithSpirvCross(const spirv_cross::Compiler& compiler);
MaybeError CheckSpvcSuccess(shaderc_spvc_status status, const char* error_msg);
// TODO(cwallez@chromium.org): The code is only stored for deduplication. We could maybe
// store a cryptographic hash of the code instead?
std::vector<uint32_t> mCode;

View File

@ -52,11 +52,9 @@ namespace dawn_native { namespace d3d12 {
options.SetHLSLPointCoordCompat(true);
options.SetHLSLPointSizeCompat(true);
shaderc_spvc_status status =
mSpvcContext.InitializeForHlsl(descriptor->code, descriptor->codeSize, options);
if (status != shaderc_spvc_status_success) {
return DAWN_VALIDATION_ERROR("Unable to initialize instance of spvc");
}
DAWN_TRY(CheckSpvcSuccess(
mSpvcContext.InitializeForHlsl(descriptor->code, descriptor->codeSize, options),
"Unable to initialize instance of spvc"));
spirv_cross::Compiler* compiler =
reinterpret_cast<spirv_cross::Compiler*>(mSpvcContext.GetCompiler());
@ -102,13 +100,11 @@ namespace dawn_native { namespace d3d12 {
if (bindingInfo.used) {
uint32_t bindingOffset = bindingOffsets[binding];
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
if (mSpvcContext.SetDecoration(
bindingInfo.id, SHADERC_SPVC_DECORATION_BINDING, bindingOffset) !=
shaderc_spvc_status_success) {
return DAWN_VALIDATION_ERROR(
DAWN_TRY(CheckSpvcSuccess(
mSpvcContext.SetDecoration(
bindingInfo.id, SHADERC_SPVC_DECORATION_BINDING, bindingOffset),
"Unable to set decorating binding before generating HLSL shader w/ "
"spvc");
}
"spvc"));
} else {
compiler->set_decoration(bindingInfo.id, spv::DecorationBinding,
bindingOffset);
@ -118,9 +114,8 @@ namespace dawn_native { namespace d3d12 {
}
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
shaderc_spvc::CompilationResult result;
if (mSpvcContext.CompileShader(&result) != shaderc_spvc_status_success) {
return DAWN_VALIDATION_ERROR("Unable to generate HLSL shader w/ spvc");
}
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.CompileShader(&result),
"Unable to generate HLSL shader w/ spvc"));
std::string result_string =
result.GetStringOutput(); // Stripping const for ResultOrError
return result_string;

View File

@ -76,11 +76,10 @@ namespace dawn_native { namespace metal {
MaybeError ShaderModule::Initialize(const ShaderModuleDescriptor* descriptor) {
mSpirv.assign(descriptor->code, descriptor->code + descriptor->codeSize);
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
shaderc_spvc_status status = mSpvcContext.InitializeForMsl(
descriptor->code, descriptor->codeSize, GetMSLCompileOptions());
if (status != shaderc_spvc_status_success) {
return DAWN_VALIDATION_ERROR("Unable to initialize instance of spvc");
}
DAWN_TRY(CheckSpvcSuccess(
mSpvcContext.InitializeForMsl(descriptor->code, descriptor->codeSize,
GetMSLCompileOptions()),
"Unable to initialize instance of spvc"));
spirv_cross::CompilerMSL* compiler =
reinterpret_cast<spirv_cross::CompilerMSL*>(mSpvcContext.GetCompiler());
@ -103,11 +102,9 @@ namespace dawn_native { namespace metal {
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
// Initializing the compiler is needed every call, because this method uses reflection
// to mutate the compiler's IR.
if (mSpvcContext.InitializeForMsl(mSpirv.data(), mSpirv.size(),
GetMSLCompileOptions()) !=
shaderc_spvc_status_success) {
return DAWN_DEVICE_LOST_ERROR("Unable to initialize instance of spvc");
}
DAWN_TRY(CheckSpvcSuccess(
mSpvcContext.InitializeForMsl(mSpirv.data(), mSpirv.size(), GetMSLCompileOptions()),
"Unable to initialize instance of spvc"));
compiler = reinterpret_cast<spirv_cross::CompilerMSL*>(mSpvcContext.GetCompiler());
} else {
// If these options are changed, the values in DawnSPIRVCrossMSLFastFuzzer.cpp need to

View File

@ -91,11 +91,9 @@ namespace dawn_native { namespace opengl {
#else
options.SetGLSLLanguageVersion(440);
#endif
shaderc_spvc_status status =
mSpvcContext.InitializeForGlsl(descriptor->code, descriptor->codeSize, options);
if (status != shaderc_spvc_status_success) {
return DAWN_VALIDATION_ERROR("Unable to initialize instance of spvc");
}
DAWN_TRY(CheckSpvcSuccess(
mSpvcContext.InitializeForGlsl(descriptor->code, descriptor->codeSize, options),
"Unable to initialize instance of spvc"));
compiler = reinterpret_cast<spirv_cross::CompilerGLSL*>(mSpvcContext.GetCompiler());
} else {
// If these options are changed, the values in DawnSPIRVCrossGLSLFastFuzzer.cpp need to
@ -193,9 +191,8 @@ namespace dawn_native { namespace opengl {
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
shaderc_spvc::CompilationResult result;
shaderc_spvc_status status = mSpvcContext.CompileShader(&result);
if (status != shaderc_spvc_status_success)
return DAWN_VALIDATION_ERROR("Unable to compile shader using spvc");
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.CompileShader(&result),
"Unable to compile shader using spvc"));
mGlslSource = result.GetStringOutput();
} else {
mGlslSource = compiler->compile();

View File

@ -41,11 +41,9 @@ namespace dawn_native { namespace vulkan {
// have a translation step eventually anyway.
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
shaderc_spvc::CompileOptions options;
shaderc_spvc_status status =
mSpvcContext.InitializeForGlsl(descriptor->code, descriptor->codeSize, options);
if (status != shaderc_spvc_status_success) {
return DAWN_VALIDATION_ERROR("Unable to initialize instance of spvc");
}
DAWN_TRY(CheckSpvcSuccess(
mSpvcContext.InitializeForGlsl(descriptor->code, descriptor->codeSize, options),
"Unable to initialize instance of spvc"));
spirv_cross::Compiler* compiler =
reinterpret_cast<spirv_cross::Compiler*>(mSpvcContext.GetCompiler());