Wrap all uses of SPIRV-Cross in #define.
Put all cross-platform code references to Spirv-Cross behind ifdef DAWN_USE_SPIRV_CROSS. Hide build dependencies behind dawn_use_spirv_cross, which itself is set from dawn_enable_opengl, since it is the only backend which is still using SPIRV-Cross. Bug: dawn:1036 Change-Id: Id61512230b50a32c63827a16fece40d7899968d8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/61400 Commit-Queue: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
ec9b81142f
commit
5d17ed6541
|
@ -104,5 +104,9 @@ declare_args() {
|
|||
dawn_supports_glfw_for_windowing =
|
||||
(is_win && !dawn_is_winuwp) || (is_linux && !is_chromeos) || is_mac
|
||||
|
||||
# Much of the backend code is shared, so define a convenience var.
|
||||
# Much of the GL backend code is shared, so define a convenience var.
|
||||
dawn_enable_opengl = dawn_enable_opengles || dawn_enable_desktop_gl
|
||||
|
||||
# The GL backends are the last to use SPIRV-Cross, so only compile it in
|
||||
# if they are enabled.
|
||||
dawn_use_spirv_cross = dawn_enable_opengl
|
||||
|
|
|
@ -85,6 +85,10 @@ config("dawn_internal") {
|
|||
defines += [ "DAWN_USE_X11" ]
|
||||
}
|
||||
|
||||
if (dawn_use_spirv_cross) {
|
||||
defines += [ "DAWN_USE_SPIRV_CROSS" ]
|
||||
}
|
||||
|
||||
if (dawn_enable_error_injection) {
|
||||
defines += [ "DAWN_ENABLE_ERROR_INJECTION" ]
|
||||
}
|
||||
|
|
|
@ -145,11 +145,13 @@ source_set("dawn_native_sources") {
|
|||
":dawn_native_headers",
|
||||
":dawn_native_utils_gen",
|
||||
"${dawn_root}/src/common",
|
||||
"${dawn_root}/third_party/gn/spirv_cross:spirv_cross",
|
||||
"${dawn_spirv_tools_dir}:spvtools_opt",
|
||||
"${dawn_spirv_tools_dir}:spvtools_val",
|
||||
"${dawn_tint_dir}/src:libtint",
|
||||
]
|
||||
if (dawn_use_spirv_cross) {
|
||||
deps += [ "${dawn_root}/third_party/gn/spirv_cross:spirv_cross" ]
|
||||
}
|
||||
defines = []
|
||||
libs = []
|
||||
data_deps = []
|
||||
|
@ -282,8 +284,6 @@ source_set("dawn_native_sources") {
|
|||
"Sampler.h",
|
||||
"ShaderModule.cpp",
|
||||
"ShaderModule.h",
|
||||
"SpirvUtils.cpp",
|
||||
"SpirvUtils.h",
|
||||
"StagingBuffer.cpp",
|
||||
"StagingBuffer.h",
|
||||
"Subresource.cpp",
|
||||
|
@ -313,6 +313,13 @@ source_set("dawn_native_sources") {
|
|||
]
|
||||
}
|
||||
|
||||
if (dawn_use_spirv_cross) {
|
||||
sources += [
|
||||
"SpirvUtils.cpp",
|
||||
"SpirvUtils.h",
|
||||
]
|
||||
}
|
||||
|
||||
# Only win32 app needs to link with user32.lib
|
||||
# In UWP, all availiable APIs are defined in WindowsApp.lib
|
||||
if (is_win && !dawn_is_winuwp) {
|
||||
|
|
|
@ -24,12 +24,16 @@
|
|||
#include "dawn_native/Pipeline.h"
|
||||
#include "dawn_native/PipelineLayout.h"
|
||||
#include "dawn_native/RenderPipeline.h"
|
||||
#if defined(DAWN_USE_SPIRV_CROSS)
|
||||
# include "dawn_native/SpirvUtils.h"
|
||||
#endif
|
||||
#include "dawn_native/TintUtils.h"
|
||||
|
||||
#include <spirv-tools/libspirv.hpp>
|
||||
#include <spirv-tools/optimizer.hpp>
|
||||
#if defined(DAWN_USE_SPIRV_CROSS)
|
||||
# include <spirv_cross.hpp>
|
||||
#endif
|
||||
|
||||
// Tint include must be after spirv_cross.hpp, because spirv-cross has its own
|
||||
// version of spirv_headers. We also need to undef SPV_REVISION because SPIRV-Cross
|
||||
|
@ -529,44 +533,6 @@ namespace dawn_native {
|
|||
return requiredBufferSizes;
|
||||
}
|
||||
|
||||
ResultOrError<std::vector<uint32_t>> RunRobustBufferAccessPass(
|
||||
const std::vector<uint32_t>& spirv) {
|
||||
spvtools::Optimizer opt(SPV_ENV_VULKAN_1_1);
|
||||
|
||||
std::ostringstream errorStream;
|
||||
errorStream << "SPIRV Optimizer failure:" << std::endl;
|
||||
opt.SetMessageConsumer([&errorStream](spv_message_level_t level, const char*,
|
||||
const spv_position_t& position,
|
||||
const char* message) {
|
||||
switch (level) {
|
||||
case SPV_MSG_FATAL:
|
||||
case SPV_MSG_INTERNAL_ERROR:
|
||||
case SPV_MSG_ERROR:
|
||||
errorStream << "error: line " << position.index << ": " << message
|
||||
<< std::endl;
|
||||
break;
|
||||
case SPV_MSG_WARNING:
|
||||
errorStream << "warning: line " << position.index << ": " << message
|
||||
<< std::endl;
|
||||
break;
|
||||
case SPV_MSG_INFO:
|
||||
errorStream << "info: line " << position.index << ": " << message
|
||||
<< std::endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
opt.RegisterPass(spvtools::CreateGraphicsRobustAccessPass());
|
||||
|
||||
std::vector<uint32_t> result;
|
||||
if (!opt.Run(spirv.data(), spirv.size(), &result, spvtools::ValidatorOptions(),
|
||||
false)) {
|
||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||
}
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
MaybeError ValidateCompatibilityWithBindGroupLayout(DeviceBase* device,
|
||||
BindGroupIndex group,
|
||||
const EntryPointMetadata& entryPoint,
|
||||
|
@ -713,6 +679,7 @@ namespace dawn_native {
|
|||
return {};
|
||||
}
|
||||
|
||||
#if defined(DAWN_USE_SPIRV_CROSS)
|
||||
ResultOrError<std::unique_ptr<EntryPointMetadata>> ExtractSpirvInfo(
|
||||
const DeviceBase* device,
|
||||
const spirv_cross::Compiler& compiler,
|
||||
|
@ -956,6 +923,7 @@ namespace dawn_native {
|
|||
|
||||
return {std::move(metadata)};
|
||||
}
|
||||
#endif
|
||||
|
||||
ResultOrError<EntryPointMetadataTable> ReflectShaderUsingTint(
|
||||
DeviceBase*,
|
||||
|
@ -1656,21 +1624,11 @@ namespace dawn_native {
|
|||
mTintSource = std::move(parseResult->tintSource);
|
||||
mSpirv = std::move(parseResult->spirv);
|
||||
|
||||
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
|
||||
DAWN_TRY_ASSIGN(mEntryPoints, ReflectShaderUsingTint(GetDevice(), mTintProgram.get()));
|
||||
} else {
|
||||
// If not using Tint to generate backend code, run the robust buffer access pass now
|
||||
// since all backends will use this SPIR-V. If Tint is used, the robustness pass should
|
||||
// be run per-backend.
|
||||
if (GetDevice()->IsRobustnessEnabled()) {
|
||||
DAWN_TRY_ASSIGN(mSpirv, RunRobustBufferAccessPass(mSpirv));
|
||||
}
|
||||
DAWN_TRY_ASSIGN(mEntryPoints, ReflectShaderUsingSPIRVCross(GetDevice(), mSpirv));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
#if defined(DAWN_USE_SPIRV_CROSS)
|
||||
ResultOrError<EntryPointMetadataTable> ShaderModuleBase::ReflectShaderUsingSPIRVCross(
|
||||
DeviceBase* device,
|
||||
const std::vector<uint32_t>& spirv) {
|
||||
|
@ -1688,6 +1646,7 @@ namespace dawn_native {
|
|||
}
|
||||
return std::move(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t PipelineLayoutEntryPointPairHashFunc::operator()(
|
||||
const PipelineLayoutEntryPointPair& pair) const {
|
||||
|
|
|
@ -240,9 +240,11 @@ namespace dawn_native {
|
|||
|
||||
protected:
|
||||
MaybeError InitializeBase(ShaderModuleParseResult* parseResult);
|
||||
#if defined(DAWN_USE_SPIRV_CROSS)
|
||||
static ResultOrError<EntryPointMetadataTable> ReflectShaderUsingSPIRVCross(
|
||||
DeviceBase* device,
|
||||
const std::vector<uint32_t>& spirv);
|
||||
#endif
|
||||
|
||||
private:
|
||||
ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag);
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
#ifndef DAWNNATIVE_SPIRV_UTILS_H_
|
||||
#define DAWNNATIVE_SPIRV_UTILS_H_
|
||||
|
||||
#if !defined(DAWN_USE_SPIRV_CROSS)
|
||||
# error "SpirvCross.h should not be included if dawn_use_spirv_cross is false"
|
||||
#endif
|
||||
|
||||
#include "dawn_native/Format.h"
|
||||
#include "dawn_native/PerStage.h"
|
||||
#include "dawn_native/VertexFormat.h"
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
#include "dawn_native/Instance.h"
|
||||
#include "dawn_native/Surface.h"
|
||||
|
||||
#include <spirv_cross.hpp>
|
||||
|
||||
namespace dawn_native { namespace null {
|
||||
|
||||
// Implementation of pre-Device objects: the null adapter, null backend connection and Connect()
|
||||
|
|
Loading…
Reference in New Issue