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>
This commit is contained in:
Kai Ninomiya 2022-05-17 01:41:41 +00:00 committed by Dawn LUCI CQ
parent 34d2d1ba02
commit 5eeef7c47f
3 changed files with 21 additions and 15 deletions

View File

@ -155,7 +155,13 @@ source_set("sources") {
libs = [] libs = []
data_deps = [] 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 # Dependencies that are needed to compile dawn native entry points in
# FooBackend.cpp need to be public deps so they are propagated to the # FooBackend.cpp need to be public deps so they are propagated to the

View File

@ -72,8 +72,8 @@ struct AspectInfo {
TexelBlockInfo block; TexelBlockInfo block;
// TODO(crbug.com/dawn/367): Replace TextureComponentType with TextureSampleType, or make it // TODO(crbug.com/dawn/367): Replace TextureComponentType with TextureSampleType, or make it
// an internal Dawn enum. // an internal Dawn enum.
wgpu::TextureComponentType baseType; wgpu::TextureComponentType baseType{};
SampleTypeBit supportedSampleTypes; SampleTypeBit supportedSampleTypes{};
wgpu::TextureFormat format = wgpu::TextureFormat::Undefined; wgpu::TextureFormat format = wgpu::TextureFormat::Undefined;
}; };
@ -88,19 +88,19 @@ using FormatTable = ityp::array<FormatIndex, Format, kKnownFormatCount>;
// A wgpu::TextureFormat along with all the information about it necessary for validation. // A wgpu::TextureFormat along with all the information about it necessary for validation.
struct Format { 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. // TODO(crbug.com/dawn/1332): These members could be stored in a Format capability matrix.
bool isRenderable; bool isRenderable = false;
bool isCompressed; bool isCompressed = false;
// A format can be known but not supported because it is part of a disabled extension. // A format can be known but not supported because it is part of a disabled extension.
bool isSupported; bool isSupported = false;
bool supportsStorageUsage; bool supportsStorageUsage = false;
bool supportsMultisample; bool supportsMultisample = false;
bool supportsResolveTarget; bool supportsResolveTarget = false;
Aspect aspects; Aspect aspects{};
// Only used for renderable color formats, number of color channels. // Only used for renderable color formats, number of color channels.
uint8_t componentCount; uint8_t componentCount = 0;
bool IsColor() const; bool IsColor() const;
bool HasDepth() const; bool HasDepth() const;
@ -121,7 +121,7 @@ struct Format {
// baseFormat represents the memory layout of the 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 // 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. // 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. // Returns true if the formats are copy compatible.
// Currently means they differ only in sRGB-ness. // 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 // 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, // info is depth and the second aspect info is stencil. For multi-planar formats,
// aspectInfo[i] is the ith plane. // aspectInfo[i] is the ith plane.
std::array<AspectInfo, kMaxPlanesPerFormat> aspectInfo; std::array<AspectInfo, kMaxPlanesPerFormat> aspectInfo{};
friend FormatTable BuildFormatTable(const DeviceBase* device); friend FormatTable BuildFormatTable(const DeviceBase* device);
}; };

View File

@ -548,7 +548,7 @@ TextureBase::TextureBase(DeviceBase* device,
TextureBase::~TextureBase() = default; TextureBase::~TextureBase() = default;
static Format kUnusedFormat; static constexpr Format kUnusedFormat;
TextureBase::TextureBase(DeviceBase* device, TextureState state) TextureBase::TextureBase(DeviceBase* device, TextureState state)
: ApiObjectBase(device, kLabelNotImplemented), mFormat(kUnusedFormat), mState(state) { : ApiObjectBase(device, kLabelNotImplemented), mFormat(kUnusedFormat), mState(state) {