Use correct Initialize call to spvc for Metal backend

BUG=dawn:292

Change-Id: I91d315d2f071cb8a25acb0d5379944ac8049deea
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14340
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Ryan Harrison 2019-12-10 18:38:28 +00:00 committed by Commit Bot service account
parent f15fc26d5b
commit 652fd5a416
1 changed files with 24 additions and 18 deletions

View File

@ -38,6 +38,25 @@ namespace dawn_native { namespace metal {
UNREACHABLE();
}
}
shaderc_spvc::CompileOptions GetMSLCompileOptions() {
// If these options are changed, the values in DawnSPIRVCrossGLSLFastFuzzer.cpp need to
// be updated.
shaderc_spvc::CompileOptions options;
// Disable PointSize builtin for https://bugs.chromium.org/p/dawn/issues/detail?id=146
// Because Metal will reject PointSize builtin if the shader is compiled into a render
// pipeline that uses a non-point topology.
// TODO (hao.x.li@intel.com): Remove this once WebGPU requires there is no
// gl_PointSize builtin (https://github.com/gpuweb/gpuweb/issues/332).
options.SetMSLEnablePointSizeBuiltIn(false);
// Always use vertex buffer 30 (the last one in the vertex buffer table) to contain
// the shader storage buffer lengths.
options.SetMSLBufferSizeBufferIndex(kBufferLengthBufferSlot);
return options;
}
} // namespace
// static
@ -57,9 +76,8 @@ 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::CompileOptions options;
shaderc_spvc_status status =
mSpvcContext.InitializeForGlsl(descriptor->code, descriptor->codeSize, options);
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");
}
@ -80,21 +98,9 @@ namespace dawn_native { namespace metal {
std::unique_ptr<spirv_cross::CompilerMSL> compiler_impl;
spirv_cross::CompilerMSL* compiler;
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
// If these options are changed, the values in DawnSPIRVCrossGLSLFastFuzzer.cpp need to
// be updated.
shaderc_spvc::CompileOptions options;
// Disable PointSize builtin for https://bugs.chromium.org/p/dawn/issues/detail?id=146
// Because Metal will reject PointSize builtin if the shader is compiled into a render
// pipeline that uses a non-point topology.
// TODO (hao.x.li@intel.com): Remove this once WebGPU requires there is no
// gl_PointSize builtin (https://github.com/gpuweb/gpuweb/issues/332).
options.SetMSLEnablePointSizeBuiltIn(false);
// Always use vertex buffer 30 (the last one in the vertex buffer table) to contain
// the shader storage buffer lengths.
options.SetMSLBufferSizeBufferIndex(kBufferLengthBufferSlot);
mSpvcContext.InitializeForMsl(mSpirv.data(), mSpirv.size(), options);
// Initializing the compiler is needed every call, because this method uses reflection
// to mutate the compiler's IR.
mSpvcContext.InitializeForMsl(mSpirv.data(), mSpirv.size(), GetMSLCompileOptions());
// TODO(rharrison): Handle initialize failing
compiler = reinterpret_cast<spirv_cross::CompilerMSL*>(mSpvcContext.GetCompiler());