From 97ad405216b228451af785cb0f1605a709b686d2 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 30 Jan 2023 14:49:27 +0000 Subject: [PATCH] Fix MSVC 14.29 errors: - It doens't know which operator == to use when there is using EnumClassBitmask that looks like (a & b) == 0. Instead use just the form (a & b). - It doesn't do automatic capture of constexpr variables in lambdas so turn a couple constexpr into regular const. - It (correctly) warns that if constexpr (std::is_constant_evaluated()) is always true, so remove the constexpr keyword. Bug: None Change-Id: If7857abd1c30acb0736557844ff13f32a19d54cf Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117888 Commit-Queue: Corentin Wallez Reviewed-by: Ben Clayton Kokoro: Corentin Wallez --- src/dawn/native/BindGroup.cpp | 2 +- src/dawn/native/Format.cpp | 10 +++++----- src/dawn/native/ShaderModule.cpp | 4 ++-- src/dawn/native/Texture.cpp | 2 +- src/dawn/native/opengl/TextureGL.cpp | 2 +- src/tint/resolver/const_eval.cc | 2 +- src/tint/transform/preserve_padding.cc | 4 ++-- src/tint/utils/math.h | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/dawn/native/BindGroup.cpp b/src/dawn/native/BindGroup.cpp index 7417144391..c2819b848b 100644 --- a/src/dawn/native/BindGroup.cpp +++ b/src/dawn/native/BindGroup.cpp @@ -149,7 +149,7 @@ MaybeError ValidateTextureBinding(DeviceBase* device, texture->GetSampleCount(), texture, bindingInfo.texture.multisampled); DAWN_INVALID_IF( - (supportedTypes & requiredType) == 0, + !(supportedTypes & requiredType), "None of the supported sample types (%s) of %s match the expected sample " "types (%s).", supportedTypes, texture, requiredType); diff --git a/src/dawn/native/Format.cpp b/src/dawn/native/Format.cpp index 7969515315..bfffd978ee 100644 --- a/src/dawn/native/Format.cpp +++ b/src/dawn/native/Format.cpp @@ -69,19 +69,19 @@ bool Format::IsColor() const { } bool Format::HasDepth() const { - return (aspects & Aspect::Depth) != 0; + return aspects & Aspect::Depth; } bool Format::HasStencil() const { - return (aspects & Aspect::Stencil) != 0; + return aspects & Aspect::Stencil; } bool Format::HasDepthOrStencil() const { - return (aspects & (Aspect::Depth | Aspect::Stencil)) != 0; + return aspects & (Aspect::Depth | Aspect::Stencil); } bool Format::IsMultiPlanar() const { - return (aspects & (Aspect::Plane0 | Aspect::Plane1)) != 0; + return aspects & (Aspect::Plane0 | Aspect::Plane1); } bool Format::CopyCompatibleWith(const Format& format) const { @@ -212,7 +212,7 @@ FormatTable BuildFormatTable(const DeviceBase* device) { UNREACHABLE(); } } else { - ASSERT((sampleTypes & SampleTypeBit::Float) != 0); + ASSERT(sampleTypes & SampleTypeBit::Float); firstAspect->baseType = wgpu::TextureComponentType::Float; } firstAspect->supportedSampleTypes = sampleTypes; diff --git a/src/dawn/native/ShaderModule.cpp b/src/dawn/native/ShaderModule.cpp index 9a94846d2a..c2ea13efdf 100644 --- a/src/dawn/native/ShaderModule.cpp +++ b/src/dawn/native/ShaderModule.cpp @@ -415,8 +415,8 @@ MaybeError ValidateCompatibilityOfSingleBindingWithLayout(const DeviceBase* devi layoutInfo.texture.multisampled, shaderInfo.texture.multisampled); // TODO(dawn:563): Provide info about the sample types. - DAWN_INVALID_IF((SampleTypeToSampleTypeBit(layoutInfo.texture.sampleType) & - shaderInfo.texture.compatibleSampleTypes) == 0, + DAWN_INVALID_IF(!(SampleTypeToSampleTypeBit(layoutInfo.texture.sampleType) & + shaderInfo.texture.compatibleSampleTypes), "The sample type in the shader is not compatible with the " "sample type of the layout."); diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp index 1ac38edba9..ad57774100 100644 --- a/src/dawn/native/Texture.cpp +++ b/src/dawn/native/Texture.cpp @@ -371,7 +371,7 @@ MaybeError ValidateTextureDescriptor(const DeviceBase* device, // Depth/stencil formats are valid for 2D textures only. Metal has this limit. And D3D12 // doesn't support depth/stencil formats on 3D textures. DAWN_INVALID_IF(descriptor->dimension != wgpu::TextureDimension::e2D && - (format->aspects & (Aspect::Depth | Aspect::Stencil)) != 0, + (format->aspects & (Aspect::Depth | Aspect::Stencil)), "The dimension (%s) of a texture with a depth/stencil format (%s) is not 2D.", descriptor->dimension, format->format); diff --git a/src/dawn/native/opengl/TextureGL.cpp b/src/dawn/native/opengl/TextureGL.cpp index 1b4783d1ca..95f7f99bb2 100644 --- a/src/dawn/native/opengl/TextureGL.cpp +++ b/src/dawn/native/opengl/TextureGL.cpp @@ -246,7 +246,7 @@ MaybeError Texture::ClearTexture(const SubresourceRange& range, float fClearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0.f : 1.f; if (GetFormat().isRenderable) { - if ((range.aspects & (Aspect::Depth | Aspect::Stencil)) != 0) { + if (range.aspects & (Aspect::Depth | Aspect::Stencil)) { GLfloat depth = fClearColor; GLint stencil = clearColor; if (range.aspects & Aspect::Depth) { diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc index 7fa435c40d..9164276b99 100644 --- a/src/tint/resolver/const_eval.cc +++ b/src/tint/resolver/const_eval.cc @@ -1854,7 +1854,7 @@ ConstEval::Result ConstEval::OpShiftRight(const type::Type* ty, using NumberT = decltype(e1); using T = UnwrapNumber; using UT = std::make_unsigned_t; - constexpr size_t bit_width = BitWidth; + const size_t bit_width = BitWidth; const UT e1u = static_cast(e1); const UT e2u = static_cast(e2); diff --git a/src/tint/transform/preserve_padding.cc b/src/tint/transform/preserve_padding.cc index 0e26d27e29..c5c0d1bb41 100644 --- a/src/tint/transform/preserve_padding.cc +++ b/src/tint/transform/preserve_padding.cc @@ -112,8 +112,8 @@ struct PreservePadding::State { // // Since this requires passing pointers to the storage address space, this will also enable // the chromium_experimental_full_ptr_parameters extension. - constexpr const char* kDestParamName = "dest"; - constexpr const char* kValueParamName = "value"; + const char* kDestParamName = "dest"; + const char* kValueParamName = "value"; auto call_helper = [&](auto&& body) { EnableExtension(); auto helper = helpers.GetOrCreate(ty, [&]() { diff --git a/src/tint/utils/math.h b/src/tint/utils/math.h index 8bbbcc89cb..d882b3403c 100644 --- a/src/tint/utils/math.h +++ b/src/tint/utils/math.h @@ -46,7 +46,7 @@ inline constexpr uint32_t Log2(uint64_t value) { #elif defined(_MSC_VER) && !defined(__clang__) && __cplusplus >= 202002L // MSVC and C++20+ // note: std::is_constant_evaluated() added in C++20 // required here as _BitScanReverse64 is not constexpr - if constexpr (!std::is_constant_evaluated()) { + if (!std::is_constant_evaluated()) { // NOLINTNEXTLINE(runtime/int) if constexpr (sizeof(unsigned long) == 8) { // 64-bit // NOLINTNEXTLINE(runtime/int)