Use IsSubset in more places.

This helper function makes the code easier to read because the name
encodes the semantic of the operation compared to the bit-twiddling that
it replaces.

Bug: None
Change-Id: Iab587e04a91cf60acf8920de1f20bb55f3ea3816
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/31668
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2020-11-06 17:11:50 +00:00 committed by Commit Bot service account
parent a701961ad3
commit 3317374395
14 changed files with 17 additions and 20 deletions

View File

@ -144,7 +144,7 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("Binding type cannot be dynamic."); 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."); return DAWN_VALIDATION_ERROR("Binding type cannot be used with this visibility.");
} }

View File

@ -121,7 +121,7 @@ namespace dawn_native {
const ityp::bitset<VertexBufferSlot, kMaxVertexBuffers>& requiredVertexBuffers = const ityp::bitset<VertexBufferSlot, kMaxVertexBuffers>& requiredVertexBuffers =
mLastRenderPipeline->GetVertexBufferSlotsUsed(); mLastRenderPipeline->GetVertexBufferSlotsUsed();
if ((mVertexBufferSlotsUsed & requiredVertexBuffers) == requiredVertexBuffers) { if (IsSubset(requiredVertexBuffers, mVertexBufferSlotsUsed)) {
mAspects.set(VALIDATION_ASPECT_VERTEX_BUFFERS); mAspects.set(VALIDATION_ASPECT_VERTEX_BUFFERS);
} }
} }

View File

@ -308,7 +308,7 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("Buffer missing usage for the pass"); 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); bool singleUse = wgpu::HasZeroOrOneBits(usage);
if (pass.passType == PassType::Render && !readOnly && !singleUse) { 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. // 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 // 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. // 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); bool singleUse = wgpu::HasZeroOrOneBits(usage);
if (pass.passType != PassType::Render || readOnly || singleUse) { if (pass.passType != PassType::Render || readOnly || singleUse) {
continue; continue;
@ -340,7 +340,7 @@ namespace dawn_native {
// Inspect the subresources if the usage of the whole texture violates usage validation. // 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. // Every single subresource can only be used as single-write or multiple read.
for (wgpu::TextureUsage subresourceUsage : textureUsage.subresourceUsages) { for (wgpu::TextureUsage subresourceUsage : textureUsage.subresourceUsages) {
bool readOnly = (subresourceUsage & kReadOnlyTextureUsages) == subresourceUsage; bool readOnly = IsSubset(subresourceUsage, kReadOnlyTextureUsages);
bool singleUse = wgpu::HasZeroOrOneBits(subresourceUsage); bool singleUse = wgpu::HasZeroOrOneBits(subresourceUsage);
if (!readOnly && !singleUse) { if (!readOnly && !singleUse) {
return DAWN_VALIDATION_ERROR( return DAWN_VALIDATION_ERROR(

View File

@ -332,7 +332,7 @@ namespace dawn_native {
const EntryPointMetadata& vertexMetadata = const EntryPointMetadata& vertexMetadata =
descriptor->vertexStage.module->GetEntryPoint(descriptor->vertexStage.entryPoint); descriptor->vertexStage.module->GetEntryPoint(descriptor->vertexStage.entryPoint);
if ((vertexMetadata.usedVertexAttributes & ~attributesSetMask).any()) { if (!IsSubset(vertexMetadata.usedVertexAttributes, attributesSetMask)) {
return DAWN_VALIDATION_ERROR( return DAWN_VALIDATION_ERROR(
"Pipeline vertex stage uses vertex buffers not in the vertex state"); "Pipeline vertex stage uses vertex buffers not in the vertex state");
} }

View File

@ -318,7 +318,7 @@ namespace dawn_native {
// Check that the return texture view matches exactly what was given for this descriptor. // Check that the return texture view matches exactly what was given for this descriptor.
ASSERT(view->GetTexture()->GetFormat().format == mFormat); ASSERT(view->GetTexture()->GetFormat().format == mFormat);
ASSERT((view->GetTexture()->GetUsage() & mUsage) == mUsage); ASSERT(IsSubset(mUsage, view->GetTexture()->GetUsage()));
ASSERT(view->GetLevelCount() == 1); ASSERT(view->GetLevelCount() == 1);
ASSERT(view->GetLayerCount() == 1); ASSERT(view->GetLayerCount() == 1);
ASSERT(view->GetDimension() == wgpu::TextureViewDimension::e2D); ASSERT(view->GetDimension() == wgpu::TextureViewDimension::e2D);

View File

@ -192,7 +192,7 @@ namespace dawn_native {
constexpr wgpu::TextureUsage kValidCompressedUsages = wgpu::TextureUsage::Sampled | constexpr wgpu::TextureUsage kValidCompressedUsages = wgpu::TextureUsage::Sampled |
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopySrc |
wgpu::TextureUsage::CopyDst; wgpu::TextureUsage::CopyDst;
if (format->isCompressed && (descriptor->usage & (~kValidCompressedUsages))) { if (format->isCompressed && !IsSubset(descriptor->usage, kValidCompressedUsages)) {
return DAWN_VALIDATION_ERROR( return DAWN_VALIDATION_ERROR(
"Compressed texture format is incompatible with the texture usage"); "Compressed texture format is incompatible with the texture usage");
} }

View File

@ -221,7 +221,7 @@ namespace dawn_native { namespace d3d12 {
} }
// We can skip transitions to already current usages. // We can skip transitions to already current usages.
if ((mLastUsage & newUsage) == newUsage) { if (IsSubset(newUsage, mLastUsage)) {
return false; return false;
} }

View File

@ -650,7 +650,7 @@ namespace dawn_native { namespace d3d12 {
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
if (lastState == D3D12_RESOURCE_STATE_COMMON) { 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 // Implicit texture state decays can only occur when the texture was implicitly
// transitioned to a read-only state. isValidToDecay is needed to differentiate // transitioned to a read-only state. isValidToDecay is needed to differentiate
// between resources that were implictly or explicitly transitioned to a // between resources that were implictly or explicitly transitioned to a

View File

@ -169,8 +169,7 @@ namespace dawn_native { namespace metal {
ASSERT(HasOneBit(aspect)); ASSERT(HasOneBit(aspect));
ASSERT(format.aspects & aspect); ASSERT(format.aspects & aspect);
constexpr Aspect kDepthStencil = Aspect::Depth | Aspect::Stencil; if (IsSubset(Aspect::Depth | Aspect::Stencil, format.aspects)) {
if ((format.aspects & kDepthStencil) == kDepthStencil) {
// We only provide a blit option if the format has both depth and stencil. // We only provide a blit option if the format has both depth and stencil.
// It is invalid to provide a blit option otherwise. // It is invalid to provide a blit option otherwise.
switch (aspect) { switch (aspect) {

View File

@ -214,8 +214,8 @@ namespace dawn_native { namespace vulkan {
VkBufferMemoryBarrier* barrier, VkBufferMemoryBarrier* barrier,
VkPipelineStageFlags* srcStages, VkPipelineStageFlags* srcStages,
VkPipelineStageFlags* dstStages) { VkPipelineStageFlags* dstStages) {
bool lastIncludesTarget = (mLastUsage & usage) == usage; bool lastIncludesTarget = IsSubset(usage, mLastUsage);
bool lastReadOnly = (mLastUsage & kReadOnlyBufferUsages) == mLastUsage; bool lastReadOnly = IsSubset(mLastUsage, kReadOnlyBufferUsages);
// We can skip transitions to already current read-only usages. // We can skip transitions to already current read-only usages.
if (lastIncludesTarget && lastReadOnly) { if (lastIncludesTarget && lastReadOnly) {

View File

@ -340,7 +340,7 @@ namespace dawn_native { namespace vulkan {
VkImageUsageFlags targetUsages = VkImageUsageFlags targetUsages =
VulkanImageUsage(GetUsage(), GetDevice()->GetValidInternalFormat(GetFormat())); VulkanImageUsage(GetUsage(), GetDevice()->GetValidInternalFormat(GetFormat()));
VkImageUsageFlags supportedUsages = surfaceInfo.capabilities.supportedUsageFlags; VkImageUsageFlags supportedUsages = surfaceInfo.capabilities.supportedUsageFlags;
if ((supportedUsages & targetUsages) != targetUsages) { if (!IsSubset(targetUsages, supportedUsages)) {
config.needsBlit = true; config.needsBlit = true;
} else { } else {
config.usage = targetUsages; config.usage = targetUsages;

View File

@ -802,7 +802,7 @@ namespace dawn_native { namespace vulkan {
bool Texture::CanReuseWithoutBarrier(wgpu::TextureUsage lastUsage, wgpu::TextureUsage usage) { bool Texture::CanReuseWithoutBarrier(wgpu::TextureUsage lastUsage, wgpu::TextureUsage usage) {
// Reuse the texture directly and avoid encoding barriers when it isn't needed. // 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) { if (lastReadOnly && lastUsage == usage && mLastExternalState == mExternalState) {
return true; return true;
} }

View File

@ -44,8 +44,7 @@ namespace dawn_native { namespace vulkan { namespace external_semaphore {
VkFlags requiredFlags = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR | VkFlags requiredFlags = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR |
VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR; VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR;
mSupported = mSupported =
mSupported && mSupported && IsSubset(requiredFlags, semaphoreProperties.externalSemaphoreFeatures);
((semaphoreProperties.externalSemaphoreFeatures & requiredFlags) == requiredFlags);
} }
Service::~Service() = default; Service::~Service() = default;

View File

@ -44,8 +44,7 @@ namespace dawn_native { namespace vulkan { namespace external_semaphore {
VkFlags requiredFlags = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR | VkFlags requiredFlags = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR |
VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR; VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR;
mSupported = mSupported =
mSupported && mSupported && IsSubset(requiredFlags, semaphoreProperties.externalSemaphoreFeatures);
((semaphoreProperties.externalSemaphoreFeatures & requiredFlags) == requiredFlags);
} }
Service::~Service() = default; Service::~Service() = default;