mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
Making SPIR-V ingestion and validation optional
Browsers won't be exposing the ability to pass SPIR-V shaders, and the ability to consume and validate them is adding a non-trivial amount to the browser binary size on platforms like Android. To avoid that overhead, this change puts those features behind a flag so that browser usage can easily omit them. Bug: dawn:286 Change-Id: Idf70683f2c4ccf479b723c00ba6914e27e4f765f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117241 Commit-Queue: Brandon Jones <bajones@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
0f72763efd
commit
61d2cf297a
@@ -151,6 +151,9 @@ source_set("sources") {
|
||||
":utils_gen",
|
||||
"${dawn_root}/src/dawn/common",
|
||||
"${dawn_root}/src/tint:libtint",
|
||||
|
||||
# TODO(dawn:286): These should only be necessary if SPIR-V validation is
|
||||
# enabled with dawn_enable_spirv_validation
|
||||
"${dawn_spirv_tools_dir}:spvtools_opt",
|
||||
"${dawn_spirv_tools_dir}:spvtools_val",
|
||||
]
|
||||
@@ -158,7 +161,10 @@ source_set("sources") {
|
||||
libs = []
|
||||
data_deps = []
|
||||
|
||||
configs += [ ":internal" ]
|
||||
configs += [
|
||||
":internal",
|
||||
"${dawn_root}/src/tint:tint_public_config",
|
||||
]
|
||||
|
||||
# Enable -Wglobal-constructors here only, instead of in internal_config,
|
||||
# because gtest and some other targets don't build with it.
|
||||
@@ -527,7 +533,8 @@ source_set("sources") {
|
||||
]
|
||||
}
|
||||
|
||||
if (dawn_enable_opengl || dawn_enable_vulkan) {
|
||||
if ((dawn_enable_opengl || dawn_enable_vulkan) &&
|
||||
dawn_enable_spirv_validation) {
|
||||
sources += [
|
||||
"SpirvValidation.cpp",
|
||||
"SpirvValidation.h",
|
||||
@@ -726,6 +733,9 @@ source_set("sources") {
|
||||
[ "${dawn_swiftshader_dir}/src/Vulkan:swiftshader_libvulkan" ]
|
||||
defines += [ "DAWN_ENABLE_SWIFTSHADER" ]
|
||||
}
|
||||
if (dawn_enable_spirv_validation) {
|
||||
defines += [ "DAWN_ENABLE_SPIRV_VALIDATION" ]
|
||||
}
|
||||
}
|
||||
|
||||
if (use_angle) {
|
||||
|
||||
@@ -619,8 +619,9 @@ BlobCache* DeviceBase::GetBlobCache() {
|
||||
// generate cache keys. We can lift the dependency once we also cache frontend parsing,
|
||||
// transformations, and reflection.
|
||||
return mAdapter->GetInstance()->GetBlobCache(!IsToggleEnabled(Toggle::DisableBlobCache));
|
||||
#endif
|
||||
#else
|
||||
return mAdapter->GetInstance()->GetBlobCache(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
Blob DeviceBase::LoadCachedBlob(const CacheKey& key) {
|
||||
|
||||
@@ -311,9 +311,9 @@ ResultOrError<tint::Program> ParseWGSL(const tint::Source::File* file,
|
||||
#endif
|
||||
}
|
||||
|
||||
#if TINT_BUILD_SPV_READER
|
||||
ResultOrError<tint::Program> ParseSPIRV(const std::vector<uint32_t>& spirv,
|
||||
OwnedCompilationMessages* outMessages) {
|
||||
#if TINT_BUILD_SPV_READER
|
||||
tint::Program program = tint::reader::spirv::Parse(spirv);
|
||||
if (outMessages != nullptr) {
|
||||
DAWN_TRY(outMessages->AddMessages(program.Diagnostics()));
|
||||
@@ -324,11 +324,8 @@ ResultOrError<tint::Program> ParseSPIRV(const std::vector<uint32_t>& spirv,
|
||||
}
|
||||
|
||||
return std::move(program);
|
||||
#else
|
||||
return DAWN_VALIDATION_ERROR("TINT_BUILD_SPV_READER is not defined.");
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif // TINT_BUILD_SPV_READER
|
||||
|
||||
std::vector<uint64_t> GetBindGroupMinBufferSizes(const BindingGroupInfoMap& shaderBindings,
|
||||
const BindGroupLayoutBase* layout) {
|
||||
@@ -903,17 +900,23 @@ MaybeError ValidateAndParseShaderModule(DeviceBase* device,
|
||||
DAWN_INVALID_IF(chainedDescriptor == nullptr,
|
||||
"Shader module descriptor missing chained descriptor");
|
||||
|
||||
// For now only a single SPIRV or WGSL subdescriptor is allowed.
|
||||
// For now only a single WGSL (or SPIRV, if enabled) subdescriptor is allowed.
|
||||
#if TINT_BUILD_SPV_READER
|
||||
DAWN_TRY(ValidateSingleSType(chainedDescriptor, wgpu::SType::ShaderModuleSPIRVDescriptor,
|
||||
wgpu::SType::ShaderModuleWGSLDescriptor));
|
||||
#else
|
||||
DAWN_TRY(ValidateSingleSType(chainedDescriptor, wgpu::SType::ShaderModuleWGSLDescriptor));
|
||||
#endif
|
||||
|
||||
ScopedTintICEHandler scopedICEHandler(device);
|
||||
|
||||
const ShaderModuleSPIRVDescriptor* spirvDesc = nullptr;
|
||||
FindInChain(chainedDescriptor, &spirvDesc);
|
||||
const ShaderModuleWGSLDescriptor* wgslDesc = nullptr;
|
||||
FindInChain(chainedDescriptor, &wgslDesc);
|
||||
|
||||
#if TINT_BUILD_SPV_READER
|
||||
const ShaderModuleSPIRVDescriptor* spirvDesc = nullptr;
|
||||
FindInChain(chainedDescriptor, &spirvDesc);
|
||||
|
||||
// We have a temporary toggle to force the SPIRV ingestion to go through a WGSL
|
||||
// intermediate step. It is done by switching the spirvDesc for a wgslDesc below.
|
||||
ShaderModuleWGSLDescriptor newWgslDesc;
|
||||
@@ -937,7 +940,7 @@ MaybeError ValidateAndParseShaderModule(DeviceBase* device,
|
||||
device->EmitLog(
|
||||
WGPULoggingType_Info,
|
||||
"Toggle::ForceWGSLStep skipped because TINT_BUILD_WGSL_WRITER is not defined\n");
|
||||
#endif
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
}
|
||||
|
||||
if (spirvDesc) {
|
||||
@@ -947,20 +950,25 @@ MaybeError ValidateAndParseShaderModule(DeviceBase* device,
|
||||
tint::Program program;
|
||||
DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv, outMessages));
|
||||
parseResult->tintProgram = std::make_unique<tint::Program>(std::move(program));
|
||||
} else if (wgslDesc) {
|
||||
auto tintSource = std::make_unique<TintSource>("", wgslDesc->source);
|
||||
|
||||
if (device->IsToggleEnabled(Toggle::DumpShaders)) {
|
||||
std::ostringstream dumpedMsg;
|
||||
dumpedMsg << "// Dumped WGSL:" << std::endl << wgslDesc->source;
|
||||
device->EmitLog(WGPULoggingType_Info, dumpedMsg.str().c_str());
|
||||
}
|
||||
|
||||
tint::Program program;
|
||||
DAWN_TRY_ASSIGN(program, ParseWGSL(&tintSource->file, outMessages));
|
||||
parseResult->tintProgram = std::make_unique<tint::Program>(std::move(program));
|
||||
parseResult->tintSource = std::move(tintSource);
|
||||
return {};
|
||||
}
|
||||
#endif // TINT_BUILD_SPV_READER
|
||||
|
||||
ASSERT(wgslDesc != nullptr);
|
||||
|
||||
auto tintSource = std::make_unique<TintSource>("", wgslDesc->source);
|
||||
|
||||
if (device->IsToggleEnabled(Toggle::DumpShaders)) {
|
||||
std::ostringstream dumpedMsg;
|
||||
dumpedMsg << "// Dumped WGSL:" << std::endl << wgslDesc->source;
|
||||
device->EmitLog(WGPULoggingType_Info, dumpedMsg.str().c_str());
|
||||
}
|
||||
|
||||
tint::Program program;
|
||||
DAWN_TRY_ASSIGN(program, ParseWGSL(&tintSource->file, outMessages));
|
||||
parseResult->tintProgram = std::make_unique<tint::Program>(std::move(program));
|
||||
parseResult->tintSource = std::move(tintSource);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -84,14 +84,13 @@ MaybeError ValidateCanViewTextureAs(const DeviceBase* device,
|
||||
"The formats must be compatible, and the view format "
|
||||
"must be passed in the list of view formats on texture creation.",
|
||||
viewFormat.format, format.format);
|
||||
} else {
|
||||
// The view format is compatible, but not in the list.
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"%s was not created with the texture view format (%s) "
|
||||
"in the list of compatible view formats.",
|
||||
texture, viewFormat.format);
|
||||
}
|
||||
return {};
|
||||
|
||||
// The view format is compatible, but not in the list.
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"%s was not created with the texture view format (%s) "
|
||||
"in the list of compatible view formats.",
|
||||
texture, viewFormat.format);
|
||||
}
|
||||
|
||||
bool IsTextureViewDimensionCompatibleWithTextureDimension(
|
||||
|
||||
@@ -360,8 +360,10 @@ ResultOrError<ShaderModule::ModuleAndSpirv> ShaderModule::GetHandleAndSpirv(
|
||||
return result;
|
||||
});
|
||||
|
||||
#ifdef DAWN_ENABLE_SPIRV_VALIDATION
|
||||
DAWN_TRY(ValidateSpirv(GetDevice(), compilation->spirv.data(), compilation->spirv.size(),
|
||||
GetDevice()->IsToggleEnabled(Toggle::DumpShaders)));
|
||||
#endif
|
||||
|
||||
VkShaderModuleCreateInfo createInfo;
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
|
||||
Reference in New Issue
Block a user