Disable "all" warnings when compiling MSL code

Hopefully works around an issue where some Metal drivers treat warnings
as errors.

Bug: dawn:493
Change-Id: Ia535502a14fd4215ff74eee2662dfbde7e01bc4b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/25841
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Kai Ninomiya 2020-07-28 18:51:28 +00:00 committed by Commit Bot service account
parent 0811ecc775
commit a390d7f84f
1 changed files with 14 additions and 5 deletions

View File

@ -187,18 +187,27 @@ namespace dawn_native { namespace metal {
// SPIRV-Cross also supports re-ordering attributes but it seems to do the correct thing // SPIRV-Cross also supports re-ordering attributes but it seems to do the correct thing
// by default. // by default.
NSString* mslSource; NSString* mslSource;
std::string msl;
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) { if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
shaderc_spvc::CompilationResult result; shaderc_spvc::CompilationResult result;
DAWN_TRY(CheckSpvcSuccess(mSpvcContext.CompileShader(&result), DAWN_TRY(CheckSpvcSuccess(mSpvcContext.CompileShader(&result),
"Unable to compile MSL shader")); "Unable to compile MSL shader"));
std::string result_str; DAWN_TRY(CheckSpvcSuccess(result.GetStringOutput(&msl),
DAWN_TRY(CheckSpvcSuccess(result.GetStringOutput(&result_str),
"Unable to get MSL shader text")); "Unable to get MSL shader text"));
mslSource = [[NSString alloc] initWithUTF8String:result_str.c_str()];
} else { } else {
std::string msl = compiler->compile(); msl = compiler->compile();
mslSource = [[NSString alloc] initWithUTF8String:msl.c_str()];
} }
// Metal uses Clang to compile the shader as C++14. Disable everything in the -Wall
// category. -Wunused-variable in particular comes up a lot in generated code, and some
// (old?) Metal drivers accidentally treat it as a MTLLibraryErrorCompileError instead
// of a warning.
msl = R"(\
#ifdef __clang__
#pragma clang diagnostic ignored "-Wall"
#endif
)" + msl;
mslSource = [[NSString alloc] initWithUTF8String:msl.c_str()];
auto mtlDevice = ToBackend(GetDevice())->GetMTLDevice(); auto mtlDevice = ToBackend(GetDevice())->GetMTLDevice();
NSError* error = nil; NSError* error = nil;
id<MTLLibrary> library = [mtlDevice newLibraryWithSource:mslSource id<MTLLibrary> library = [mtlDevice newLibraryWithSource:mslSource