From 5eeef7c47fd263b5aa13d6e1245dd16d4fc8b98d Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Tue, 17 May 2022 01:41:41 +0000 Subject: [PATCH] Enable -Wglobal-constructors for dawn/native Eliminates a static initializer in kUnusedFormat (in Texture.cpp) by making dawn::native::Format constexpr-constructible. kUnusedFormat doesn't actually have to be constexpr to fix this, but it adds explicit enforcement that it's constexpr-constructible. Includes some extra initializers as a workaround for a bug in the old version of MSVC (14.26) that's on Kokoro. amaiorano figured out how to reproduce it locally, with a local install of VS2019 and this magic CMake incantation: $ cmake -G "Visual Studio 16 2019" -T v142,version=14.26 .. Bug: dawn:1405 Change-Id: Ic94324fc624fd720671dec35dcc5ea8ad77ee46d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89863 Reviewed-by: Dan Sinclair Commit-Queue: Kai Ninomiya --- src/dawn/native/BUILD.gn | 8 +++++++- src/dawn/native/Format.h | 26 +++++++++++++------------- src/dawn/native/Texture.cpp | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index 409d847e47..c919a4f090 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -155,7 +155,13 @@ source_set("sources") { libs = [] data_deps = [] - configs += [ ":internal" ] + configs += [ + ":internal", + + # Enable -Wglobal-constructors here only, instead of in internal_config, + # because gtest and some other targets don't build with it. + "//build/config/compiler:wglobal_constructors", + ] # Dependencies that are needed to compile dawn native entry points in # FooBackend.cpp need to be public deps so they are propagated to the diff --git a/src/dawn/native/Format.h b/src/dawn/native/Format.h index b48e998f1d..8f750da25b 100644 --- a/src/dawn/native/Format.h +++ b/src/dawn/native/Format.h @@ -72,8 +72,8 @@ struct AspectInfo { TexelBlockInfo block; // TODO(crbug.com/dawn/367): Replace TextureComponentType with TextureSampleType, or make it // an internal Dawn enum. - wgpu::TextureComponentType baseType; - SampleTypeBit supportedSampleTypes; + wgpu::TextureComponentType baseType{}; + SampleTypeBit supportedSampleTypes{}; wgpu::TextureFormat format = wgpu::TextureFormat::Undefined; }; @@ -88,19 +88,19 @@ using FormatTable = ityp::array; // A wgpu::TextureFormat along with all the information about it necessary for validation. struct Format { - wgpu::TextureFormat format; + wgpu::TextureFormat format = wgpu::TextureFormat::Undefined; // TODO(crbug.com/dawn/1332): These members could be stored in a Format capability matrix. - bool isRenderable; - bool isCompressed; + bool isRenderable = false; + bool isCompressed = false; // A format can be known but not supported because it is part of a disabled extension. - bool isSupported; - bool supportsStorageUsage; - bool supportsMultisample; - bool supportsResolveTarget; - Aspect aspects; + bool isSupported = false; + bool supportsStorageUsage = false; + bool supportsMultisample = false; + bool supportsResolveTarget = false; + Aspect aspects{}; // Only used for renderable color formats, number of color channels. - uint8_t componentCount; + uint8_t componentCount = 0; bool IsColor() const; bool HasDepth() const; @@ -121,7 +121,7 @@ struct Format { // baseFormat represents the memory layout of the format. // If two formats has the same baseFormat, they could copy to and be viewed as the other // format. Currently two formats have the same baseFormat if they differ only in sRGB-ness. - wgpu::TextureFormat baseFormat; + wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined; // Returns true if the formats are copy compatible. // Currently means they differ only in sRGB-ness. @@ -136,7 +136,7 @@ struct Format { // only the first aspect info or aspectInfo[0] is valid. For depth-stencil, the first aspect // info is depth and the second aspect info is stencil. For multi-planar formats, // aspectInfo[i] is the ith plane. - std::array aspectInfo; + std::array aspectInfo{}; friend FormatTable BuildFormatTable(const DeviceBase* device); }; diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp index 457e76d91e..0d750431ed 100644 --- a/src/dawn/native/Texture.cpp +++ b/src/dawn/native/Texture.cpp @@ -548,7 +548,7 @@ TextureBase::TextureBase(DeviceBase* device, TextureBase::~TextureBase() = default; -static Format kUnusedFormat; +static constexpr Format kUnusedFormat; TextureBase::TextureBase(DeviceBase* device, TextureState state) : ApiObjectBase(device, kLabelNotImplemented), mFormat(kUnusedFormat), mState(state) {