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 <dsinclair@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn
index 409d847..c919a4f 100644
--- a/src/dawn/native/BUILD.gn
+++ b/src/dawn/native/BUILD.gn
@@ -155,7 +155,13 @@
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 b48e998..8f750da 100644
--- a/src/dawn/native/Format.h
+++ b/src/dawn/native/Format.h
@@ -72,8 +72,8 @@
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 @@
// 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 @@
// 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 @@
// 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, kMaxPlanesPerFormat> aspectInfo;
+ std::array<AspectInfo, kMaxPlanesPerFormat> aspectInfo{};
friend FormatTable BuildFormatTable(const DeviceBase* device);
};
diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp
index 457e76d..0d75043 100644
--- a/src/dawn/native/Texture.cpp
+++ b/src/dawn/native/Texture.cpp
@@ -548,7 +548,7 @@
TextureBase::~TextureBase() = default;
-static Format kUnusedFormat;
+static constexpr Format kUnusedFormat;
TextureBase::TextureBase(DeviceBase* device, TextureState state)
: ApiObjectBase(device, kLabelNotImplemented), mFormat(kUnusedFormat), mState(state) {