diff --git a/src/common/RefBase.h b/src/common/RefBase.h index a1db6a973e..495a24f830 100644 --- a/src/common/RefBase.h +++ b/src/common/RefBase.h @@ -134,10 +134,6 @@ class RefBase { return mValue != other; } - operator bool() { - return mValue != kNullValue; - } - const T operator->() const { return mValue; } diff --git a/src/dawn_native/BindGroup.cpp b/src/dawn_native/BindGroup.cpp index db46993cc0..546b618e5f 100644 --- a/src/dawn_native/BindGroup.cpp +++ b/src/dawn_native/BindGroup.cpp @@ -278,7 +278,7 @@ namespace dawn_native { // next loop iteration. if (entry.buffer != nullptr) { - ASSERT(mBindingData.bindings[bindingIndex].Get() == nullptr); + ASSERT(mBindingData.bindings[bindingIndex] == nullptr); mBindingData.bindings[bindingIndex] = entry.buffer; mBindingData.bufferData[bindingIndex].offset = entry.offset; uint64_t bufferSize = (entry.size == wgpu::kWholeSize) @@ -289,13 +289,13 @@ namespace dawn_native { } if (entry.textureView != nullptr) { - ASSERT(mBindingData.bindings[bindingIndex].Get() == nullptr); + ASSERT(mBindingData.bindings[bindingIndex] == nullptr); mBindingData.bindings[bindingIndex] = entry.textureView; continue; } if (entry.sampler != nullptr) { - ASSERT(mBindingData.bindings[bindingIndex].Get() == nullptr); + ASSERT(mBindingData.bindings[bindingIndex] == nullptr); mBindingData.bindings[bindingIndex] = entry.sampler; continue; } @@ -313,7 +313,7 @@ namespace dawn_native { } BindGroupBase::~BindGroupBase() { - if (mLayout) { + if (mLayout != nullptr) { ASSERT(!IsError()); for (BindingIndex i{0}; i < mLayout->GetBindingCount(); ++i) { mBindingData.bindings[i].~Ref(); diff --git a/src/dawn_native/CommandBuffer.cpp b/src/dawn_native/CommandBuffer.cpp index f5deec1b0b..b9c47058f9 100644 --- a/src/dawn_native/CommandBuffer.cpp +++ b/src/dawn_native/CommandBuffer.cpp @@ -89,7 +89,7 @@ namespace dawn_native { IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) { auto& attachmentInfo = renderPass->colorAttachments[i]; TextureViewBase* view = attachmentInfo.view.Get(); - bool hasResolveTarget = attachmentInfo.resolveTarget.Get() != nullptr; + bool hasResolveTarget = attachmentInfo.resolveTarget != nullptr; ASSERT(view->GetLayerCount() == 1); ASSERT(view->GetLevelCount() == 1); diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index b2c15a34b7..5214564874 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -190,7 +190,7 @@ namespace dawn_native { mState = State::Disconnected; // mCurrentErrorScope can be null if we failed device initialization. - if (mCurrentErrorScope.Get() != nullptr) { + if (mCurrentErrorScope != nullptr) { mCurrentErrorScope->UnlinkForShutdown(); } mErrorScopeTracker = nullptr; @@ -295,7 +295,7 @@ namespace dawn_native { } ErrorScope* DeviceBase::GetCurrentErrorScope() { - ASSERT(mCurrentErrorScope.Get() != nullptr); + ASSERT(mCurrentErrorScope != nullptr); return mCurrentErrorScope.Get(); } @@ -459,7 +459,7 @@ namespace dawn_native { } BindGroupLayoutBase* DeviceBase::GetEmptyBindGroupLayout() { - ASSERT(mEmptyBindGroupLayout); + ASSERT(mEmptyBindGroupLayout != nullptr); return mEmptyBindGroupLayout.Get(); } @@ -639,7 +639,7 @@ namespace dawn_native { BufferBase* DeviceBase::CreateBuffer(const BufferDescriptor* descriptor) { Ref result = nullptr; if (ConsumedError(CreateBufferInternal(descriptor), &result)) { - ASSERT(result.Get() == nullptr); + ASSERT(result == nullptr); return BufferBase::MakeError(this, descriptor); } @@ -837,7 +837,7 @@ namespace dawn_native { QueueBase* DeviceBase::GetDefaultQueue() { // Backends gave the default queue during initialization. - ASSERT(mDefaultQueue.Get() != nullptr); + ASSERT(mDefaultQueue != nullptr); // Returns a new reference to the queue. mDefaultQueue->Reference(); diff --git a/src/dawn_native/ErrorScope.cpp b/src/dawn_native/ErrorScope.cpp index 45036278cb..674bb7a0d3 100644 --- a/src/dawn_native/ErrorScope.cpp +++ b/src/dawn_native/ErrorScope.cpp @@ -23,7 +23,7 @@ namespace dawn_native { ErrorScope::ErrorScope(wgpu::ErrorFilter errorFilter, ErrorScope* parent) : RefCounted(), mErrorFilter(errorFilter), mParent(parent), mIsRoot(false) { - ASSERT(mParent.Get() != nullptr); + ASSERT(mParent != nullptr); } ErrorScope::~ErrorScope() { @@ -124,9 +124,9 @@ namespace dawn_native { Ref parentScope = nullptr; for (; !currentScope->IsRoot(); currentScope = parentScope.Get()) { ASSERT(!currentScope->IsRoot()); - ASSERT(currentScope.Get() != nullptr); + ASSERT(currentScope != nullptr); parentScope = std::move(currentScope->mParent); - ASSERT(parentScope.Get() != nullptr); + ASSERT(parentScope != nullptr); // On shutdown, error scopes that have yet to have a status get Unknown. if (currentScope->mErrorType == wgpu::ErrorType::NoError) { diff --git a/src/dawn_native/SwapChain.cpp b/src/dawn_native/SwapChain.cpp index 0d73efaf28..69ad3646b7 100644 --- a/src/dawn_native/SwapChain.cpp +++ b/src/dawn_native/SwapChain.cpp @@ -167,7 +167,7 @@ namespace dawn_native { ASSERT(!IsError()); // Return the same current texture view until Present is called. - if (mCurrentTextureView.Get() != nullptr) { + if (mCurrentTextureView != nullptr) { // Calling GetCurrentTextureView always returns a new reference so add it even when // reuse the existing texture view. mCurrentTextureView->Reference(); @@ -247,7 +247,7 @@ namespace dawn_native { DAWN_TRY(GetDevice()->ValidateIsAlive()); DAWN_TRY(GetDevice()->ValidateObject(this)); - if (mCurrentTextureView.Get() == nullptr) { + if (mCurrentTextureView == nullptr) { return DAWN_VALIDATION_ERROR( "Cannot call present without a GetCurrentTextureView call for this frame"); } @@ -271,7 +271,7 @@ namespace dawn_native { } NewSwapChainBase::~NewSwapChainBase() { - if (mCurrentTextureView.Get() != nullptr) { + if (mCurrentTextureView != nullptr) { ASSERT(mCurrentTextureView->GetTexture()->GetTextureState() == TextureBase::TextureState::Destroyed); } @@ -304,7 +304,7 @@ namespace dawn_native { return TextureViewBase::MakeError(GetDevice()); } - if (mCurrentTextureView.Get() != nullptr) { + if (mCurrentTextureView != nullptr) { // Calling GetCurrentTextureView always returns a new reference so add it even when // reusing the existing texture view. mCurrentTextureView->Reference(); @@ -384,7 +384,7 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("Presenting on detached swapchain"); } - if (mCurrentTextureView.Get() == nullptr) { + if (mCurrentTextureView == nullptr) { return DAWN_VALIDATION_ERROR("Presenting without prior GetCurrentTextureView"); } diff --git a/src/dawn_native/d3d12/BindGroupD3D12.cpp b/src/dawn_native/d3d12/BindGroupD3D12.cpp index 6e3e26c37b..08d8159654 100644 --- a/src/dawn_native/d3d12/BindGroupD3D12.cpp +++ b/src/dawn_native/d3d12/BindGroupD3D12.cpp @@ -182,13 +182,13 @@ namespace dawn_native { namespace d3d12 { } D3D12_GPU_DESCRIPTOR_HANDLE BindGroup::GetBaseSamplerDescriptor() const { - ASSERT(mSamplerAllocationEntry.Get() != nullptr); + ASSERT(mSamplerAllocationEntry != nullptr); return mSamplerAllocationEntry->GetBaseDescriptor(); } bool BindGroup::PopulateSamplers(Device* device, ShaderVisibleDescriptorAllocator* samplerAllocator) { - if (mSamplerAllocationEntry.Get() == nullptr) { + if (mSamplerAllocationEntry == nullptr) { return true; } return mSamplerAllocationEntry->Populate(device, samplerAllocator); diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index ff8bec2b9c..804c4e106b 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -1102,7 +1102,7 @@ namespace dawn_native { namespace d3d12 { i, attachmentInfo.loadOp, attachmentInfo.clearColor, view->GetD3D12Format()); // Set color store operation. - if (attachmentInfo.resolveTarget.Get() != nullptr) { + if (attachmentInfo.resolveTarget != nullptr) { TextureView* resolveDestinationView = ToBackend(attachmentInfo.resolveTarget.Get()); Texture* resolveDestinationTexture = ToBackend(resolveDestinationView->GetTexture()); diff --git a/src/dawn_native/d3d12/CommandRecordingContext.cpp b/src/dawn_native/d3d12/CommandRecordingContext.cpp index 131e7a25ad..cae9e2a1c1 100644 --- a/src/dawn_native/d3d12/CommandRecordingContext.cpp +++ b/src/dawn_native/d3d12/CommandRecordingContext.cpp @@ -102,7 +102,7 @@ namespace dawn_native { namespace d3d12 { // the device before calling. ID3D12GraphicsCommandList4* CommandRecordingContext::GetCommandList4() const { ASSERT(IsOpen()); - ASSERT(mD3d12CommandList.Get() != nullptr); + ASSERT(mD3d12CommandList != nullptr); return mD3d12CommandList4.Get(); } diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index 69782250e2..fc0cc5ca82 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -83,7 +83,7 @@ namespace dawn_native { namespace metal { descriptor.colorAttachments[i].level = attachmentInfo.view->GetBaseMipLevel(); descriptor.colorAttachments[i].slice = attachmentInfo.view->GetBaseArrayLayer(); - bool hasResolveTarget = attachmentInfo.resolveTarget.Get() != nullptr; + bool hasResolveTarget = attachmentInfo.resolveTarget != nullptr; switch (attachmentInfo.storeOp) { case wgpu::StoreOp::Store: diff --git a/src/dawn_native/metal/SwapChainMTL.mm b/src/dawn_native/metal/SwapChainMTL.mm index d6d57a968f..7abb8decd3 100644 --- a/src/dawn_native/metal/SwapChainMTL.mm +++ b/src/dawn_native/metal/SwapChainMTL.mm @@ -133,9 +133,9 @@ namespace dawn_native { namespace metal { } void SwapChain::DetachFromSurfaceImpl() { - ASSERT((mTexture.Get() == nullptr) == (mCurrentDrawable == nullptr)); + ASSERT((mTexture == nullptr) == (mCurrentDrawable == nullptr)); - if (mTexture.Get() != nullptr) { + if (mTexture != nullptr) { mTexture->Destroy(); mTexture = nullptr; diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index d8ddfffa36..05320a2f2a 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -387,7 +387,7 @@ namespace dawn_native { namespace null { } void SwapChain::DetachFromSurfaceImpl() { - if (mTexture.Get() != nullptr) { + if (mTexture != nullptr) { mTexture->Destroy(); mTexture = nullptr; } diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp index 6e3476e6c4..7244621e90 100644 --- a/src/dawn_native/opengl/CommandBufferGL.cpp +++ b/src/dawn_native/opengl/CommandBufferGL.cpp @@ -381,7 +381,7 @@ namespace dawn_native { namespace opengl { for (ColorAttachmentIndex i : IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) { - if (renderPass->colorAttachments[i].resolveTarget.Get() != nullptr) { + if (renderPass->colorAttachments[i].resolveTarget != nullptr) { if (readFbo == 0) { ASSERT(writeFbo == 0); gl.GenFramebuffers(1, &readFbo); diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp index fe210950e5..106d7751bd 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.cpp +++ b/src/dawn_native/vulkan/CommandBufferVk.cpp @@ -273,7 +273,7 @@ namespace dawn_native { namespace vulkan { IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) { const auto& attachmentInfo = renderPass->colorAttachments[i]; - bool hasResolveTarget = attachmentInfo.resolveTarget.Get() != nullptr; + bool hasResolveTarget = attachmentInfo.resolveTarget != nullptr; wgpu::LoadOp loadOp = attachmentInfo.loadOp; query.SetColor(i, attachmentInfo.view->GetFormat().format, loadOp, @@ -355,7 +355,7 @@ namespace dawn_native { namespace vulkan { for (ColorAttachmentIndex i : IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) { - if (renderPass->colorAttachments[i].resolveTarget.Get() != nullptr) { + if (renderPass->colorAttachments[i].resolveTarget != nullptr) { TextureView* view = ToBackend(renderPass->colorAttachments[i].resolveTarget.Get()); diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp index 926a9f6f97..fb107af832 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp @@ -26,8 +26,9 @@ namespace dawn_native { namespace vulkan { ResultOrError ShaderModule::Create(Device* device, const ShaderModuleDescriptor* descriptor) { Ref module = AcquireRef(new ShaderModule(device, descriptor)); - if (!module) + if (module == nullptr) { return DAWN_VALIDATION_ERROR("Unable to create ShaderModule"); + } DAWN_TRY(module->Initialize()); return module.Detach(); } diff --git a/src/dawn_native/vulkan/SwapChainVk.cpp b/src/dawn_native/vulkan/SwapChainVk.cpp index 03dda5c694..614901111e 100644 --- a/src/dawn_native/vulkan/SwapChainVk.cpp +++ b/src/dawn_native/vulkan/SwapChainVk.cpp @@ -602,12 +602,12 @@ namespace dawn_native { namespace vulkan { } void SwapChain::DetachFromSurfaceImpl() { - if (mTexture) { + if (mTexture != nullptr) { mTexture->Destroy(); mTexture = nullptr; } - if (mBlitTexture) { + if (mBlitTexture != nullptr) { mBlitTexture->Destroy(); mBlitTexture = nullptr; } diff --git a/src/tests/unittests/RefCountedTests.cpp b/src/tests/unittests/RefCountedTests.cpp index 236dd160fc..18b3b47c4b 100644 --- a/src/tests/unittests/RefCountedTests.cpp +++ b/src/tests/unittests/RefCountedTests.cpp @@ -129,17 +129,6 @@ TEST(Ref, DefaultsToNull) { EXPECT_EQ(test->GetThis(), nullptr); } -// Test Refs can be used inside ifs -TEST(Ref, BoolConversion) { - Ref empty; - Ref full(new RCTest); - full->Release(); - - if (!full || empty) { - EXPECT_TRUE(false); - } -} - // Test Ref's copy constructor TEST(Ref, CopyConstructor) { bool deleted = false;