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

View File

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

View File

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

View File

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

View File

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