diff --git a/src/dawn_native/BindGroupLayout.cpp b/src/dawn_native/BindGroupLayout.cpp index 04473d009c..b8a56568df 100644 --- a/src/dawn_native/BindGroupLayout.cpp +++ b/src/dawn_native/BindGroupLayout.cpp @@ -144,7 +144,7 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("Binding type cannot be dynamic."); } - if ((entry.visibility & allowedStages) != entry.visibility) { + if (!IsSubset(entry.visibility, allowedStages)) { return DAWN_VALIDATION_ERROR("Binding type cannot be used with this visibility."); } diff --git a/src/dawn_native/CommandBufferStateTracker.cpp b/src/dawn_native/CommandBufferStateTracker.cpp index 4e5b54fad3..43e0c55018 100644 --- a/src/dawn_native/CommandBufferStateTracker.cpp +++ b/src/dawn_native/CommandBufferStateTracker.cpp @@ -121,7 +121,7 @@ namespace dawn_native { const ityp::bitset& requiredVertexBuffers = mLastRenderPipeline->GetVertexBufferSlotsUsed(); - if ((mVertexBufferSlotsUsed & requiredVertexBuffers) == requiredVertexBuffers) { + if (IsSubset(requiredVertexBuffers, mVertexBufferSlotsUsed)) { mAspects.set(VALIDATION_ASPECT_VERTEX_BUFFERS); } } diff --git a/src/dawn_native/CommandValidation.cpp b/src/dawn_native/CommandValidation.cpp index 08ab6d747a..0cbfdcb5c4 100644 --- a/src/dawn_native/CommandValidation.cpp +++ b/src/dawn_native/CommandValidation.cpp @@ -308,7 +308,7 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("Buffer missing usage for the pass"); } - bool readOnly = (usage & kReadOnlyBufferUsages) == usage; + bool readOnly = IsSubset(usage, kReadOnlyBufferUsages); bool singleUse = wgpu::HasZeroOrOneBits(usage); if (pass.passType == PassType::Render && !readOnly && !singleUse) { @@ -332,7 +332,7 @@ namespace dawn_native { // The usage variable for the whole texture is a fast path for texture usage tracking. // Because in most cases a texture (with or without subresources) is used as // single-write or multiple read, then we can skip iterating the subresources' usages. - bool readOnly = (usage & kReadOnlyTextureUsages) == usage; + bool readOnly = IsSubset(usage, kReadOnlyTextureUsages); bool singleUse = wgpu::HasZeroOrOneBits(usage); if (pass.passType != PassType::Render || readOnly || singleUse) { continue; @@ -340,7 +340,7 @@ namespace dawn_native { // Inspect the subresources if the usage of the whole texture violates usage validation. // Every single subresource can only be used as single-write or multiple read. for (wgpu::TextureUsage subresourceUsage : textureUsage.subresourceUsages) { - bool readOnly = (subresourceUsage & kReadOnlyTextureUsages) == subresourceUsage; + bool readOnly = IsSubset(subresourceUsage, kReadOnlyTextureUsages); bool singleUse = wgpu::HasZeroOrOneBits(subresourceUsage); if (!readOnly && !singleUse) { return DAWN_VALIDATION_ERROR( diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp index 25e0a05b1f..3c2fe10ada 100644 --- a/src/dawn_native/RenderPipeline.cpp +++ b/src/dawn_native/RenderPipeline.cpp @@ -332,7 +332,7 @@ namespace dawn_native { const EntryPointMetadata& vertexMetadata = descriptor->vertexStage.module->GetEntryPoint(descriptor->vertexStage.entryPoint); - if ((vertexMetadata.usedVertexAttributes & ~attributesSetMask).any()) { + if (!IsSubset(vertexMetadata.usedVertexAttributes, attributesSetMask)) { return DAWN_VALIDATION_ERROR( "Pipeline vertex stage uses vertex buffers not in the vertex state"); } diff --git a/src/dawn_native/SwapChain.cpp b/src/dawn_native/SwapChain.cpp index b0e03ef23c..0d73efaf28 100644 --- a/src/dawn_native/SwapChain.cpp +++ b/src/dawn_native/SwapChain.cpp @@ -318,7 +318,7 @@ namespace dawn_native { // Check that the return texture view matches exactly what was given for this descriptor. ASSERT(view->GetTexture()->GetFormat().format == mFormat); - ASSERT((view->GetTexture()->GetUsage() & mUsage) == mUsage); + ASSERT(IsSubset(mUsage, view->GetTexture()->GetUsage())); ASSERT(view->GetLevelCount() == 1); ASSERT(view->GetLayerCount() == 1); ASSERT(view->GetDimension() == wgpu::TextureViewDimension::e2D); diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index 253541ae4a..fc751dcc3f 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -192,7 +192,7 @@ namespace dawn_native { constexpr wgpu::TextureUsage kValidCompressedUsages = wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst; - if (format->isCompressed && (descriptor->usage & (~kValidCompressedUsages))) { + if (format->isCompressed && !IsSubset(descriptor->usage, kValidCompressedUsages)) { return DAWN_VALIDATION_ERROR( "Compressed texture format is incompatible with the texture usage"); } diff --git a/src/dawn_native/d3d12/BufferD3D12.cpp b/src/dawn_native/d3d12/BufferD3D12.cpp index e31a545dd1..2d445be872 100644 --- a/src/dawn_native/d3d12/BufferD3D12.cpp +++ b/src/dawn_native/d3d12/BufferD3D12.cpp @@ -221,7 +221,7 @@ namespace dawn_native { namespace d3d12 { } // We can skip transitions to already current usages. - if ((mLastUsage & newUsage) == newUsage) { + if (IsSubset(newUsage, mLastUsage)) { return false; } diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index 4877e5cf91..a1909f96a9 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -650,7 +650,7 @@ namespace dawn_native { namespace d3d12 { D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; if (lastState == D3D12_RESOURCE_STATE_COMMON) { - if (newState == (newState & kD3D12PromotableReadOnlyStates)) { + if (IsSubset(newState, kD3D12PromotableReadOnlyStates)) { // Implicit texture state decays can only occur when the texture was implicitly // transitioned to a read-only state. isValidToDecay is needed to differentiate // between resources that were implictly or explicitly transitioned to a diff --git a/src/dawn_native/metal/UtilsMetal.mm b/src/dawn_native/metal/UtilsMetal.mm index 689204e7ea..953deb9261 100644 --- a/src/dawn_native/metal/UtilsMetal.mm +++ b/src/dawn_native/metal/UtilsMetal.mm @@ -169,8 +169,7 @@ namespace dawn_native { namespace metal { ASSERT(HasOneBit(aspect)); ASSERT(format.aspects & aspect); - constexpr Aspect kDepthStencil = Aspect::Depth | Aspect::Stencil; - if ((format.aspects & kDepthStencil) == kDepthStencil) { + if (IsSubset(Aspect::Depth | Aspect::Stencil, format.aspects)) { // We only provide a blit option if the format has both depth and stencil. // It is invalid to provide a blit option otherwise. switch (aspect) { diff --git a/src/dawn_native/vulkan/BufferVk.cpp b/src/dawn_native/vulkan/BufferVk.cpp index c31db7af60..9e3a67bfd7 100644 --- a/src/dawn_native/vulkan/BufferVk.cpp +++ b/src/dawn_native/vulkan/BufferVk.cpp @@ -214,8 +214,8 @@ namespace dawn_native { namespace vulkan { VkBufferMemoryBarrier* barrier, VkPipelineStageFlags* srcStages, VkPipelineStageFlags* dstStages) { - bool lastIncludesTarget = (mLastUsage & usage) == usage; - bool lastReadOnly = (mLastUsage & kReadOnlyBufferUsages) == mLastUsage; + bool lastIncludesTarget = IsSubset(usage, mLastUsage); + bool lastReadOnly = IsSubset(mLastUsage, kReadOnlyBufferUsages); // We can skip transitions to already current read-only usages. if (lastIncludesTarget && lastReadOnly) { diff --git a/src/dawn_native/vulkan/SwapChainVk.cpp b/src/dawn_native/vulkan/SwapChainVk.cpp index 372397bbf9..03dda5c694 100644 --- a/src/dawn_native/vulkan/SwapChainVk.cpp +++ b/src/dawn_native/vulkan/SwapChainVk.cpp @@ -340,7 +340,7 @@ namespace dawn_native { namespace vulkan { VkImageUsageFlags targetUsages = VulkanImageUsage(GetUsage(), GetDevice()->GetValidInternalFormat(GetFormat())); VkImageUsageFlags supportedUsages = surfaceInfo.capabilities.supportedUsageFlags; - if ((supportedUsages & targetUsages) != targetUsages) { + if (!IsSubset(targetUsages, supportedUsages)) { config.needsBlit = true; } else { config.usage = targetUsages; diff --git a/src/dawn_native/vulkan/TextureVk.cpp b/src/dawn_native/vulkan/TextureVk.cpp index a708efdb9d..97a20a4c88 100644 --- a/src/dawn_native/vulkan/TextureVk.cpp +++ b/src/dawn_native/vulkan/TextureVk.cpp @@ -802,7 +802,7 @@ namespace dawn_native { namespace vulkan { bool Texture::CanReuseWithoutBarrier(wgpu::TextureUsage lastUsage, wgpu::TextureUsage usage) { // Reuse the texture directly and avoid encoding barriers when it isn't needed. - bool lastReadOnly = (lastUsage & kReadOnlyTextureUsages) == lastUsage; + bool lastReadOnly = IsSubset(lastUsage, kReadOnlyTextureUsages); if (lastReadOnly && lastUsage == usage && mLastExternalState == mExternalState) { return true; } diff --git a/src/dawn_native/vulkan/external_semaphore/SemaphoreServiceOpaqueFD.cpp b/src/dawn_native/vulkan/external_semaphore/SemaphoreServiceOpaqueFD.cpp index aecc893500..44529d0d55 100644 --- a/src/dawn_native/vulkan/external_semaphore/SemaphoreServiceOpaqueFD.cpp +++ b/src/dawn_native/vulkan/external_semaphore/SemaphoreServiceOpaqueFD.cpp @@ -44,8 +44,7 @@ namespace dawn_native { namespace vulkan { namespace external_semaphore { VkFlags requiredFlags = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR | VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR; mSupported = - mSupported && - ((semaphoreProperties.externalSemaphoreFeatures & requiredFlags) == requiredFlags); + mSupported && IsSubset(requiredFlags, semaphoreProperties.externalSemaphoreFeatures); } Service::~Service() = default; diff --git a/src/dawn_native/vulkan/external_semaphore/SemaphoreServiceZirconHandle.cpp b/src/dawn_native/vulkan/external_semaphore/SemaphoreServiceZirconHandle.cpp index b4e3a62e5e..20ffbad6d1 100644 --- a/src/dawn_native/vulkan/external_semaphore/SemaphoreServiceZirconHandle.cpp +++ b/src/dawn_native/vulkan/external_semaphore/SemaphoreServiceZirconHandle.cpp @@ -44,8 +44,7 @@ namespace dawn_native { namespace vulkan { namespace external_semaphore { VkFlags requiredFlags = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR | VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR; mSupported = - mSupported && - ((semaphoreProperties.externalSemaphoreFeatures & requiredFlags) == requiredFlags); + mSupported && IsSubset(requiredFlags, semaphoreProperties.externalSemaphoreFeatures); } Service::~Service() = default;