Use Tint/WGSL unconditionally

Bug: dawn:706
Change-Id: I102c37e67e7833bb7441ed8a355a4411bd7b9fb9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/45421
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2021-03-22 21:23:36 +00:00 committed by Commit Bot service account
parent b00de7f8e8
commit a9439199b7
18 changed files with 16 additions and 130 deletions

View File

@ -69,7 +69,6 @@ option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_META
option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
option(DAWN_ENABLE_OPENGL "Enable compilation of the OpenGL backend" ${ENABLE_OPENGL})
option(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
option(DAWN_ENABLE_WGSL "Enable WGSL support" ON)
option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
option(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
@ -125,9 +124,6 @@ endif()
if (DAWN_ENABLE_VULKAN)
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
endif()
if (DAWN_ENABLE_WGSL)
target_compile_definitions(dawn_internal_config INTERFACE "-DDAWN_ENABLE_WGSL=1")
endif()
if (DAWN_USE_X11)
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
endif()

View File

@ -65,9 +65,6 @@ declare_args() {
dawn_enable_vulkan = is_linux || is_chromeos || is_win || is_fuchsia ||
is_android || dawn_use_swiftshader
# Enable support WGSL for shaders.
dawn_enable_wgsl = true
# Enable use of reflection compiler in spirv-cross. This is needed
# if performing reflection on systems that the platform language
# shader is SPIR-V, since there isn't an instance of the

View File

@ -75,10 +75,6 @@ config("dawn_internal") {
defines += [ "DAWN_ENABLE_BACKEND_VULKAN" ]
}
if (dawn_enable_wgsl) {
defines += [ "DAWN_ENABLE_WGSL" ]
}
if (dawn_use_x11) {
defines += [ "DAWN_USE_X11" ]
}

View File

@ -146,6 +146,7 @@ source_set("dawn_native_sources") {
"${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",
]
defines = []
libs = []
@ -625,10 +626,6 @@ source_set("dawn_native_sources") {
"${dawn_angle_dir}:libGLESv2",
]
}
if (dawn_enable_wgsl) {
deps += [ "${dawn_tint_dir}/src:libtint" ]
}
}
# The static and shared libraries for dawn_native. Most of the files are

View File

@ -25,10 +25,6 @@ if(BUILD_SHARED_LIBS)
target_compile_definitions(dawn_native PRIVATE "DAWN_NATIVE_SHARED_LIBRARY")
endif()
if(DAWN_ENABLE_WGSL)
target_link_libraries(dawn_native PRIVATE libtint)
endif()
target_sources(dawn_native PRIVATE
"${DAWN_INCLUDE_DIR}/dawn_native/DawnNative.h"
"${DAWN_INCLUDE_DIR}/dawn_native/dawn_native_export.h"
@ -169,6 +165,7 @@ target_link_libraries(dawn_native
PRIVATE dawn_common
dawn_platform
dawn_internal_config
libtint
spirv-cross-core
spirv-cross-glsl
spirv-cross-hlsl

View File

@ -27,13 +27,11 @@
#include <spirv-tools/optimizer.hpp>
#include <spirv_cross.hpp>
#ifdef DAWN_ENABLE_WGSL
// 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
// is at 3 while spirv-headers is at 4.
# undef SPV_REVISION
# include <tint/tint.h>
#endif // DAWN_ENABLE_WGSL
#undef SPV_REVISION
#include <tint/tint.h>
#include <sstream>
@ -48,7 +46,6 @@ namespace dawn_native {
return ostream.str();
}
#ifdef DAWN_ENABLE_WGSL
tint::transform::VertexFormat ToTintVertexFormat(wgpu::VertexFormat format) {
format = dawn::NormalizeVertexFormat(format);
switch (format) {
@ -191,8 +188,6 @@ namespace dawn_native {
"Attempted to convert unexpected component type from Tint");
}
#endif // DAWN_ENABLE_WGSL
MaybeError ValidateSpirv(const uint32_t* code, uint32_t codeSize) {
spvtools::SpirvTools spirvTools(SPV_ENV_VULKAN_1_1);
@ -235,7 +230,6 @@ namespace dawn_native {
return {};
}
#ifdef DAWN_ENABLE_WGSL
ResultOrError<tint::Program> ParseWGSL(const tint::Source::File* file) {
std::ostringstream errorStream;
errorStream << "Tint WGSL reader failure:" << std::endl;
@ -293,7 +287,6 @@ namespace dawn_native {
std::vector<uint32_t> spirv = generator.result();
return std::move(spirv);
}
#endif // DAWN_ENABLE_WGSL
std::vector<uint64_t> GetBindGroupMinBufferSizes(
const EntryPointMetadata::BindingGroupInfoMap& shaderBindings,
@ -722,7 +715,6 @@ namespace dawn_native {
return {std::move(metadata)};
}
#ifdef DAWN_ENABLE_WGSL
// Currently only partially populated the reflection data, needs to be
// completed using PopulateMetadataUsingSPIRVCross. In the future, once
// this function is complete, ReflectShaderUsingSPIRVCross and
@ -835,7 +827,6 @@ namespace dawn_native {
}
return std::move(result);
}
#endif // DAWN_ENABLE_WGSL
// Uses SPIRV-Cross, which is planned for removal, but until
// ReflectShaderUsingTint is completed, will be kept as a
@ -860,7 +851,6 @@ namespace dawn_native {
return std::move(result);
}
#ifdef DAWN_ENABLE_WGSL
// Temporary utility method that allows for polyfilling like behaviour,
// specifically data missing from the Tint implementation is filled in
// using the SPIRV-Cross implementation. Once the Tint implementation is
@ -933,7 +923,6 @@ namespace dawn_native {
}
return {};
}
#endif // DAWN_ENABLE_WGSL
} // anonymous namespace
@ -965,16 +954,12 @@ namespace dawn_native {
static_cast<const ShaderModuleSPIRVDescriptor*>(chainedDescriptor);
std::vector<uint32_t> spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize);
if (device->IsToggleEnabled(Toggle::UseTintGenerator)) {
#ifdef DAWN_ENABLE_WGSL
tint::Program program;
DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv));
if (device->IsValidationEnabled()) {
DAWN_TRY(ValidateModule(&program));
}
parseResult.tintProgram = std::make_unique<tint::Program>(std::move(program));
#else
return DAWN_VALIDATION_ERROR("Using Tint is not enabled in this build.");
#endif // DAWN_ENABLE_WGSL
} else {
if (device->IsValidationEnabled()) {
DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size()));
@ -985,7 +970,6 @@ namespace dawn_native {
}
case wgpu::SType::ShaderModuleWGSLDescriptor: {
#ifdef DAWN_ENABLE_WGSL
const auto* wgslDesc =
static_cast<const ShaderModuleWGSLDescriptor*>(chainedDescriptor);
@ -1017,9 +1001,6 @@ namespace dawn_native {
parseResult.spirv = std::move(spirv);
}
break;
#else
return DAWN_VALIDATION_ERROR("Using Tint is not enabled in this build.");
#endif // DAWN_ENABLE_WGSL
}
default:
return DAWN_VALIDATION_ERROR("Unsupported sType");
@ -1039,7 +1020,6 @@ namespace dawn_native {
return bufferSizes;
}
#ifdef DAWN_ENABLE_WGSL
ResultOrError<tint::Program> RunTransforms(tint::transform::Transform* transform,
const tint::Program* program) {
tint::transform::Transform::Output output = transform->Run(program);
@ -1077,7 +1057,6 @@ namespace dawn_native {
}
return std::make_unique<tint::transform::VertexPulling>(cfg);
}
#endif
MaybeError ValidateCompatibilityWithPipelineLayout(DeviceBase* device,
const EntryPointMetadata& entryPoint,
@ -1167,7 +1146,6 @@ namespace dawn_native {
return mSpirv;
}
#ifdef DAWN_ENABLE_WGSL
const tint::Program* ShaderModuleBase::GetTintProgram() const {
ASSERT(GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator));
return mTintProgram.get();
@ -1214,12 +1192,9 @@ namespace dawn_native {
DAWN_TRY(ValidateSpirv(spirv.data(), spirv.size()));
return std::move(spirv);
}
#endif
MaybeError ShaderModuleBase::InitializeBase(ShaderModuleParseResult* parseResult) {
#ifdef DAWN_ENABLE_WGSL
mTintProgram = std::move(parseResult->tintProgram);
#endif
mSpirv = std::move(parseResult->spirv);
// If not using Tint to generate backend code, run the robust buffer access pass now since
@ -1231,7 +1206,6 @@ namespace dawn_native {
}
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
#ifdef DAWN_ENABLE_WGSL
// We still need the spirv for reflection. Remove this when we use the Tint inspector
// completely.
std::vector<uint32_t> reflectionSpirv;
@ -1242,9 +1216,6 @@ namespace dawn_native {
DAWN_TRY_ASSIGN(table, ReflectShaderUsingTint(GetDevice(), mTintProgram.get()));
DAWN_TRY(PopulateMetadataUsingSPIRVCross(GetDevice(), reflectionSpirv, &table));
mEntryPoints = std::move(table);
#else
UNREACHABLE();
#endif
} else {
DAWN_TRY_ASSIGN(mEntryPoints, ReflectShaderUsingSPIRVCross(GetDevice(), mSpirv));
}

View File

@ -60,9 +60,7 @@ namespace dawn_native {
ShaderModuleParseResult(ShaderModuleParseResult&& rhs);
ShaderModuleParseResult& operator=(ShaderModuleParseResult&& rhs);
#ifdef DAWN_ENABLE_WGSL
std::unique_ptr<tint::Program> tintProgram;
#endif
std::vector<uint32_t> spirv;
};
@ -75,7 +73,6 @@ namespace dawn_native {
RequiredBufferSizes ComputeRequiredBufferSizesForLayout(const EntryPointMetadata& entryPoint,
const PipelineLayoutBase* layout);
#ifdef DAWN_ENABLE_WGSL
ResultOrError<tint::Program> RunTransforms(tint::transform::Transform* transform,
const tint::Program* program);
@ -83,7 +80,6 @@ namespace dawn_native {
const VertexStateDescriptor& vertexState,
const std::string& entryPoint,
BindGroupIndex pullingBufferBindingSet);
#endif
// Contains all the reflection data for a valid (ShaderModule, entryPoint, stage). They are
// stored in the ShaderModuleBase and destroyed only when the shader program is destroyed so
@ -145,8 +141,6 @@ namespace dawn_native {
};
const std::vector<uint32_t>& GetSpirv() const;
#ifdef DAWN_ENABLE_WGSL
const tint::Program* GetTintProgram() const;
ResultOrError<std::vector<uint32_t>> GeneratePullingSpirv(
@ -160,7 +154,6 @@ namespace dawn_native {
const VertexStateDescriptor& vertexState,
const std::string& entryPoint,
BindGroupIndex pullingBufferBindingSet) const;
#endif
protected:
MaybeError InitializeBase(ShaderModuleParseResult* parseResult);
@ -178,9 +171,7 @@ namespace dawn_native {
// mTintProgram is set iff UseTintGenerator.
EntryPointMetadataTable mEntryPoints;
std::vector<uint32_t> mSpirv;
#ifdef DAWN_ENABLE_WGSL
std::unique_ptr<tint::Program> mTintProgram;
#endif
};
} // namespace dawn_native

View File

@ -29,13 +29,11 @@
#include <spirv_hlsl.hpp>
#ifdef DAWN_ENABLE_WGSL
// Tint include must be after spirv_hlsl.hpp, because spirv-cross has its own
// version of spirv_headers. We also need to undef SPV_REVISION because SPIRV-Cross
// is at 3 while spirv-headers is at 4.
# undef SPV_REVISION
# include <tint/tint.h>
#endif // DAWN_ENABLE_WGSL
#undef SPV_REVISION
#include <tint/tint.h>
namespace dawn_native { namespace d3d12 {
@ -197,7 +195,6 @@ namespace dawn_native { namespace d3d12 {
FirstOffsetInfo* firstOffsetInfo) const {
ASSERT(!IsError());
#ifdef DAWN_ENABLE_WGSL
std::ostringstream errorStream;
errorStream << "Tint HLSL failure:" << std::endl;
@ -249,9 +246,6 @@ namespace dawn_native { namespace d3d12 {
}
return generator.result();
#else
return DAWN_VALIDATION_ERROR("Using Tint to generate HLSL is not supported.");
#endif // DAWN_ENABLE_WGSL
}
ResultOrError<std::string> ShaderModule::TranslateToHLSLWithSPIRVCross(

View File

@ -22,13 +22,11 @@
#include <spirv_msl.hpp>
#ifdef DAWN_ENABLE_WGSL
// Tint include must be after spirv_msl.hpp, because spirv-cross has its own
// version of spirv_headers. We also need to undef SPV_REVISION because SPIRV-Cross
// is at 3 while spirv-headers is at 4.
# undef SPV_REVISION
# include <tint/tint.h>
#endif // DAWN_ENABLE_WGSL
#undef SPV_REVISION
#include <tint/tint.h>
#include <sstream>
@ -60,7 +58,6 @@ namespace dawn_native { namespace metal {
const RenderPipeline* renderPipeline,
std::string* remappedEntryPointName,
bool* needsStorageBufferLength) {
#if DAWN_ENABLE_WGSL
// TODO(crbug.com/tint/256): Set this accordingly if arrayLength(..) is used.
*needsStorageBufferLength = false;
@ -113,9 +110,6 @@ namespace dawn_native { namespace metal {
std::string msl = generator.result();
return std::move(msl);
#else
UNREACHABLE();
#endif
}
ResultOrError<std::string> ShaderModule::TranslateToMSLWithSPIRVCross(
@ -129,7 +123,6 @@ namespace dawn_native { namespace metal {
const std::vector<uint32_t>* spirv = &GetSpirv();
spv::ExecutionModel executionModel = ShaderStageToExecutionModel(stage);
#ifdef DAWN_ENABLE_WGSL
std::vector<uint32_t> pullingSpirv;
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&
stage == SingleShaderStage::Vertex) {
@ -146,7 +139,6 @@ namespace dawn_native { namespace metal {
}
spirv = &pullingSpirv;
}
#endif
// If these options are changed, the values in DawnSPIRVCrossMSLFastFuzzer.cpp need to
// be updated.
@ -202,7 +194,6 @@ namespace dawn_native { namespace metal {
}
}
#ifdef DAWN_ENABLE_WGSL
// Add vertex buffers bound as storage buffers
if (GetDevice()->IsToggleEnabled(Toggle::MetalEnableVertexPulling) &&
stage == SingleShaderStage::Vertex) {
@ -219,7 +210,6 @@ namespace dawn_native { namespace metal {
compiler.add_msl_resource_binding(mslBinding);
}
}
#endif
// SPIRV-Cross also supports re-ordering attributes but it seems to do the correct thing
// by default.

View File

@ -23,13 +23,11 @@
#include <spirv_glsl.hpp>
#ifdef DAWN_ENABLE_WGSL
// Tint include must be after spirv_glsl.hpp, because spirv-cross has its own
// version of spirv_headers. We also need to undef SPV_REVISION because SPIRV-Cross
// is at 3 while spirv-headers is at 4.
# undef SPV_REVISION
# include <tint/tint.h>
#endif // DAWN_ENABLE_WGSL
#undef SPV_REVISION
#include <tint/tint.h>
#include <sstream>
@ -80,7 +78,6 @@ namespace dawn_native { namespace opengl {
MaybeError ShaderModule::Initialize(ShaderModuleParseResult* parseResult) {
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
#ifdef DAWN_ENABLE_WGSL
std::ostringstream errorStream;
errorStream << "Tint SPIR-V (for GLSL) writer failure:" << std::endl;
@ -107,9 +104,6 @@ namespace dawn_native { namespace opengl {
transformedParseResult.spirv = mSpirv;
DAWN_TRY(InitializeBase(&transformedParseResult));
#else
UNREACHABLE();
#endif
} else {
DAWN_TRY(InitializeBase(parseResult));
}

View File

@ -20,13 +20,11 @@
#include <spirv_cross.hpp>
#ifdef DAWN_ENABLE_WGSL
// Tint include must be after spirv_hlsl.hpp, because spirv-cross has its own
// version of spirv_headers. We also need to undef SPV_REVISION because SPIRV-Cross
// is at 3 while spirv-headers is at 4.
# undef SPV_REVISION
# include <tint/tint.h>
#endif // DAWN_ENABLE_WGSL
#undef SPV_REVISION
#include <tint/tint.h>
namespace dawn_native { namespace vulkan {
@ -51,7 +49,6 @@ namespace dawn_native { namespace vulkan {
const std::vector<uint32_t>* spirvPtr;
if (GetDevice()->IsToggleEnabled(Toggle::UseTintGenerator)) {
#ifdef DAWN_ENABLE_WGSL
std::ostringstream errorStream;
errorStream << "Tint SPIR-V writer failure:" << std::endl;
@ -79,9 +76,6 @@ namespace dawn_native { namespace vulkan {
transformedParseResult.spirv = spirv;
DAWN_TRY(InitializeBase(&transformedParseResult));
#else
UNREACHABLE();
#endif
} else {
DAWN_TRY(InitializeBase(parseResult));
spirvPtr = &GetSpirv();

View File

@ -337,6 +337,7 @@ source_set("dawn_end2end_tests_sources") {
"end2end/TextureSubresourceTests.cpp",
"end2end/TextureViewTests.cpp",
"end2end/TextureZeroInitTests.cpp",
"end2end/VertexBufferRobustnessTests.cpp",
"end2end/VertexFormatTests.cpp",
"end2end/VertexStateTests.cpp",
"end2end/ViewportOrientationTests.cpp",
@ -368,10 +369,6 @@ source_set("dawn_end2end_tests_sources") {
frameworks = [ "IOSurface.framework" ]
}
if (dawn_enable_wgsl) {
sources += [ "end2end/VertexBufferRobustnessTests.cpp" ]
}
if (dawn_enable_opengl) {
assert(dawn_supports_glfw_for_windowing)
}

View File

@ -788,14 +788,6 @@ bool DawnTestBase::IsBackendValidationEnabled() const {
return gTestEnv->GetBackendValidationLevel() != dawn_native::BackendValidationLevel::Disabled;
}
bool DawnTestBase::HasWGSL() const {
#ifdef DAWN_ENABLE_WGSL
return true;
#else
return false;
#endif
}
bool DawnTestBase::IsAsan() const {
#if defined(ADDRESS_SANITIZER)
return true;

View File

@ -281,7 +281,6 @@ class DawnTestBase {
bool UsesWire() const;
bool IsBackendValidationEnabled() const;
bool HasWGSL() const;
bool IsAsan() const;

View File

@ -555,8 +555,6 @@ TEST_F(RenderPipelineValidationTest, StripIndexFormatRequired) {
// Test that the entryPoint names must be present for the correct stage in the shader module.
TEST_F(RenderPipelineValidationTest, EntryPointNameValidation) {
DAWN_SKIP_TEST_IF(!HasWGSL());
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[builtin(position)]] var<out> position : vec4<f32>;
[[stage(vertex)]] fn vertex_main() -> void {
@ -607,8 +605,6 @@ TEST_F(RenderPipelineValidationTest, EntryPointNameValidation) {
// Test that vertex attrib validation is for the correct entryPoint
TEST_F(RenderPipelineValidationTest, VertexAttribCorrectEntryPoint) {
DAWN_SKIP_TEST_IF(!HasWGSL());
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[builtin(position)]] var<out> position : vec4<f32>;
[[location(0)]] var<in> attrib0 : vec4<f32>;
@ -655,8 +651,6 @@ TEST_F(RenderPipelineValidationTest, VertexAttribCorrectEntryPoint) {
// Test that fragment output validation is for the correct entryPoint
TEST_F(RenderPipelineValidationTest, FragmentOutputCorrectEntryPoint) {
DAWN_SKIP_TEST_IF(!HasWGSL());
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<out> colorFloat : vec4<f32>;
[[location(0)]] var<out> colorUint : vec4<u32>;
@ -697,8 +691,6 @@ TEST_F(RenderPipelineValidationTest, FragmentOutputCorrectEntryPoint) {
// Test that fragment output validation is for the correct entryPoint
// TODO(dawn:216): Re-enable when we correctly reflect which bindings are used for an entryPoint.
TEST_F(RenderPipelineValidationTest, DISABLED_BindingsFromCorrectEntryPoint) {
DAWN_SKIP_TEST_IF(!HasWGSL());
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[block]] struct Uniforms {
data : vec4<f32>;

View File

@ -148,14 +148,6 @@ void ValidationTest::WaitForAllOperations(const wgpu::Device& device) {
FlushWire();
}
bool ValidationTest::HasWGSL() const {
#ifdef DAWN_ENABLE_WGSL
return true;
#else
return false;
#endif
}
bool ValidationTest::HasToggleEnabled(const char* toggle) const {
auto toggles = dawn_native::GetTogglesUsed(backendDevice);
return std::find_if(toggles.begin(), toggles.end(), [toggle](const char* name) {

View File

@ -92,7 +92,6 @@ class ValidationTest : public testing::Test {
wgpu::RenderPassColorAttachmentDescriptor mColorAttachment;
};
bool HasWGSL() const;
bool HasToggleEnabled(const char* toggle) const;
protected:

View File

@ -78,11 +78,9 @@ if (DAWN_BUILD_EXAMPLES)
endif()
endif()
if (DAWN_ENABLE_WGSL)
if (NOT TARGET libtint)
message(STATUS "Dawn: using Tint at ${DAWN_TINT_DIR}")
add_subdirectory(${DAWN_TINT_DIR})
endif()
if (NOT TARGET libtint)
message(STATUS "Dawn: using Tint at ${DAWN_TINT_DIR}")
add_subdirectory(${DAWN_TINT_DIR})
endif()
# Header-only library for khrplatform.h