diff --git a/dawn.json b/dawn.json index 7cb1f106f7..75ce922d35 100644 --- a/dawn.json +++ b/dawn.json @@ -593,6 +593,10 @@ {"name": "descriptor", "type": "texture descriptor", "annotation": "const*"} ] }, + { + "name": "get default queue", + "returns": "queue" + }, { "name": "inject error", "args": [ diff --git a/examples/Animometer.cpp b/examples/Animometer.cpp index 6657f5199c..04b2ac6274 100644 --- a/examples/Animometer.cpp +++ b/examples/Animometer.cpp @@ -50,7 +50,7 @@ static std::vector shaderData; void init() { device = CreateCppDawnDevice(); - queue = device.CreateQueue(); + queue = device.GetDefaultQueue(); swapchain = GetSwapChain(device); swapchain.Configure(GetPreferredSwapChainTextureFormat(), wgpu::TextureUsage::OutputAttachment, 640, 480); diff --git a/examples/CHelloTriangle.cpp b/examples/CHelloTriangle.cpp index ffd269c5b1..048fba1987 100644 --- a/examples/CHelloTriangle.cpp +++ b/examples/CHelloTriangle.cpp @@ -26,7 +26,7 @@ WGPUTextureFormat swapChainFormat; void init() { device = CreateCppDawnDevice().Release(); - queue = wgpuDeviceCreateQueue(device); + queue = wgpuDeviceGetDefaultQueue(device); { WGPUSwapChainDescriptor descriptor = {}; diff --git a/examples/ComputeBoids.cpp b/examples/ComputeBoids.cpp index 71d7402e17..37bd5940d8 100644 --- a/examples/ComputeBoids.cpp +++ b/examples/ComputeBoids.cpp @@ -289,7 +289,7 @@ wgpu::CommandBuffer createCommandBuffer(const wgpu::TextureView backbufferView, void init() { device = CreateCppDawnDevice(); - queue = device.CreateQueue(); + queue = device.GetDefaultQueue(); swapchain = GetSwapChain(device); swapchain.Configure(GetPreferredSwapChainTextureFormat(), wgpu::TextureUsage::OutputAttachment, 640, 480); diff --git a/examples/CppHelloTriangle.cpp b/examples/CppHelloTriangle.cpp index 78e0cb8bad..a7c24204ff 100644 --- a/examples/CppHelloTriangle.cpp +++ b/examples/CppHelloTriangle.cpp @@ -88,7 +88,7 @@ void initTextures() { void init() { device = CreateCppDawnDevice(); - queue = device.CreateQueue(); + queue = device.GetDefaultQueue(); swapchain = GetSwapChain(device); swapchain.Configure(GetPreferredSwapChainTextureFormat(), wgpu::TextureUsage::OutputAttachment, 640, 480); diff --git a/examples/CubeReflection.cpp b/examples/CubeReflection.cpp index b07f1a1283..61e363c366 100644 --- a/examples/CubeReflection.cpp +++ b/examples/CubeReflection.cpp @@ -117,7 +117,7 @@ struct CameraData { void init() { device = CreateCppDawnDevice(); - queue = device.CreateQueue(); + queue = device.GetDefaultQueue(); swapchain = GetSwapChain(device); swapchain.Configure(GetPreferredSwapChainTextureFormat(), wgpu::TextureUsage::OutputAttachment, 640, 480); diff --git a/examples/ManualSwapChainTest.cpp b/examples/ManualSwapChainTest.cpp index acd0d87ecf..ee924d3dba 100644 --- a/examples/ManualSwapChainTest.cpp +++ b/examples/ManualSwapChainTest.cpp @@ -307,7 +307,7 @@ int main(int argc, const char* argv[]) { dawn::ErrorLog() << errorTypeName << " error: " << message; }, nullptr); - queue = device.CreateQueue(); + queue = device.GetDefaultQueue(); // The hacky pipeline to render a triangle. utils::ComboRenderPipelineDescriptor pipelineDesc(device); diff --git a/src/dawn_native/DawnNative.cpp b/src/dawn_native/DawnNative.cpp index e4f7ab410e..14ae72a407 100644 --- a/src/dawn_native/DawnNative.cpp +++ b/src/dawn_native/DawnNative.cpp @@ -166,6 +166,11 @@ namespace dawn_native { return deviceBase->GetLazyClearCountForTesting(); } + size_t GetDeprecationWarningCountForTesting(WGPUDevice device) { + dawn_native::DeviceBase* deviceBase = reinterpret_cast(device); + return deviceBase->GetDeprecationWarningCountForTesting(); + } + bool IsTextureSubresourceInitialized(WGPUTexture texture, uint32_t baseMipLevel, uint32_t levelCount, diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 7e65b4bacc..3de861fa99 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -45,7 +45,7 @@ namespace dawn_native { - // DeviceBase::Caches + // DeviceBase sub-structures // The caches are unordered_sets of pointers with special hash and compare functions // to compare the value of the objects, instead of the pointers. @@ -73,6 +73,11 @@ namespace dawn_native { ContentLessObjectCache shaderModules; }; + struct DeviceBase::DeprecationWarnings { + std::unordered_set emitted; + size_t count = 0; + }; + // DeviceBase DeviceBase::DeviceBase(AdapterBase* adapter, const DeviceDescriptor* descriptor) @@ -89,7 +94,8 @@ namespace dawn_native { DeviceBase::~DeviceBase() { } - MaybeError DeviceBase::Initialize() { + MaybeError DeviceBase::Initialize(QueueBase* defaultQueue) { + mDefaultQueue = AcquireRef(defaultQueue); mRootErrorScope = AcquireRef(new ErrorScope()); mCurrentErrorScope = mRootErrorScope.Get(); @@ -97,6 +103,7 @@ namespace dawn_native { mErrorScopeTracker = std::make_unique(this); mFenceSignalTracker = std::make_unique(this); mDynamicUploader = std::make_unique(this); + mDeprecationWarnings = std::make_unique(); // Starting from now the backend can start doing reentrant calls so the device is marked as // alive. @@ -567,13 +574,10 @@ namespace dawn_native { return result; } QueueBase* DeviceBase::CreateQueue() { - QueueBase* result = nullptr; - - if (ConsumedError(CreateQueueInternal(&result))) { - return QueueBase::MakeError(this); - } - - return result; + // TODO(dawn:22): Remove this once users use GetDefaultQueue + EmitDeprecationWarning( + "Device::CreateQueue is deprecated, use Device::GetDefaultQueue instead"); + return GetDefaultQueue(); } SamplerBase* DeviceBase::CreateSampler(const SamplerDescriptor* descriptor) { SamplerBase* result = nullptr; @@ -674,6 +678,15 @@ namespace dawn_native { } } + QueueBase* DeviceBase::GetDefaultQueue() { + // Backends gave the default queue during initialization. + ASSERT(mDefaultQueue.Get() != nullptr); + + // Returns a new reference to the queue. + mDefaultQueue->Reference(); + return mDefaultQueue.Get(); + } + void DeviceBase::ApplyExtensions(const DeviceDescriptor* deviceDescriptor) { ASSERT(deviceDescriptor); ASSERT(GetAdapter()->SupportsAllRequestedExtensions(deviceDescriptor->requiredExtensions)); @@ -702,6 +715,17 @@ namespace dawn_native { ++mLazyClearCountForTesting; } + size_t DeviceBase::GetDeprecationWarningCountForTesting() { + return mDeprecationWarnings->count; + } + + void DeviceBase::EmitDeprecationWarning(const char* warning) { + mDeprecationWarnings->count++; + if (mDeprecationWarnings->emitted.insert(warning).second) { + dawn::WarningLog() << warning; + } + } + // Implementation details of object creation MaybeError DeviceBase::CreateBindGroupInternal(BindGroupBase** result, @@ -770,12 +794,6 @@ namespace dawn_native { return {}; } - MaybeError DeviceBase::CreateQueueInternal(QueueBase** result) { - DAWN_TRY(ValidateIsAlive()); - DAWN_TRY_ASSIGN(*result, CreateQueueImpl()); - return {}; - } - MaybeError DeviceBase::CreateRenderBundleEncoderInternal( RenderBundleEncoder** result, const RenderBundleEncoderDescriptor* descriptor) { diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h index 2238037a3e..8bce4aba22 100644 --- a/src/dawn_native/Device.h +++ b/src/dawn_native/Device.h @@ -154,6 +154,8 @@ namespace dawn_native { TextureViewBase* CreateTextureView(TextureBase* texture, const TextureViewDescriptor* descriptor); + QueueBase* GetDefaultQueue(); + void InjectError(wgpu::ErrorType type, const char* message); void Tick(); @@ -207,13 +209,15 @@ namespace dawn_native { bool IsValidationEnabled() const; size_t GetLazyClearCountForTesting(); void IncrementLazyClearCountForTesting(); + size_t GetDeprecationWarningCountForTesting(); + void EmitDeprecationWarning(const char* warning); void LoseForTesting(); protected: void SetToggle(Toggle toggle, bool isEnabled); void ForceSetToggle(Toggle toggle, bool isEnabled); - MaybeError Initialize(); + MaybeError Initialize(QueueBase* defaultQueue); void ShutDownBase(); private: @@ -226,7 +230,6 @@ namespace dawn_native { const ComputePipelineDescriptor* descriptor) = 0; virtual ResultOrError CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) = 0; - virtual ResultOrError CreateQueueImpl() = 0; virtual ResultOrError CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) = 0; virtual ResultOrError CreateSamplerImpl( @@ -255,7 +258,6 @@ namespace dawn_native { const ComputePipelineDescriptor* descriptor); MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result, const PipelineLayoutDescriptor* descriptor); - MaybeError CreateQueueInternal(QueueBase** result); MaybeError CreateRenderBundleEncoderInternal( RenderBundleEncoder** result, const RenderBundleEncoderDescriptor* descriptor); @@ -305,6 +307,10 @@ namespace dawn_native { std::unique_ptr mDynamicUploader; std::unique_ptr mErrorScopeTracker; std::unique_ptr mFenceSignalTracker; + Ref mDefaultQueue; + + struct DeprecationWarnings; + std::unique_ptr mDeprecationWarnings; uint32_t mRefCount = 1; State mState = State::BeingCreated; diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 755c4be4e5..97c09d79a6 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -128,7 +128,7 @@ namespace dawn_native { namespace d3d12 { GetD3D12Device()->CreateCommandSignature(&programDesc, NULL, IID_PPV_ARGS(&mDrawIndexedIndirectSignature)); - return DeviceBase::Initialize(); + return DeviceBase::Initialize(new Queue(this)); } Device::~Device() { @@ -267,9 +267,6 @@ namespace dawn_native { namespace d3d12 { const PipelineLayoutDescriptor* descriptor) { return PipelineLayout::Create(this, descriptor); } - ResultOrError Device::CreateQueueImpl() { - return new Queue(this); - } ResultOrError Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return RenderPipeline::Create(this, descriptor); diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h index 1f3a95827b..a5bff18148 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.h +++ b/src/dawn_native/d3d12/DeviceD3D12.h @@ -132,7 +132,6 @@ namespace dawn_native { namespace d3d12 { const ComputePipelineDescriptor* descriptor) override; ResultOrError CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQueueImpl() override; ResultOrError CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; diff --git a/src/dawn_native/metal/DeviceMTL.h b/src/dawn_native/metal/DeviceMTL.h index 72aa55bd77..4a5195e2a9 100644 --- a/src/dawn_native/metal/DeviceMTL.h +++ b/src/dawn_native/metal/DeviceMTL.h @@ -83,7 +83,6 @@ namespace dawn_native { namespace metal { const ComputePipelineDescriptor* descriptor) override; ResultOrError CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQueueImpl() override; ResultOrError CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index c85feee3a8..341c131d1b 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -64,7 +64,7 @@ namespace dawn_native { namespace metal { InitTogglesFromDriver(); mCommandQueue = [mMtlDevice newCommandQueue]; - return DeviceBase::Initialize(); + return DeviceBase::Initialize(new Queue(this)); } void Device::InitTogglesFromDriver() { @@ -124,9 +124,6 @@ namespace dawn_native { namespace metal { const PipelineLayoutDescriptor* descriptor) { return new PipelineLayout(this, descriptor); } - ResultOrError Device::CreateQueueImpl() { - return new Queue(this); - } ResultOrError Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return RenderPipeline::Create(this, descriptor); diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index 95d3289742..79da48cf10 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -89,7 +89,7 @@ namespace dawn_native { namespace null { } MaybeError Device::Initialize() { - return DeviceBase::Initialize(); + return DeviceBase::Initialize(new Queue(this)); } ResultOrError Device::CreateBindGroupImpl( @@ -116,9 +116,6 @@ namespace dawn_native { namespace null { const PipelineLayoutDescriptor* descriptor) { return new PipelineLayout(this, descriptor); } - ResultOrError Device::CreateQueueImpl() { - return new Queue(this); - } ResultOrError Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return new RenderPipeline(this, descriptor); diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index c14ffffa89..83f09ae360 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -121,7 +121,6 @@ namespace dawn_native { namespace null { const ComputePipelineDescriptor* descriptor) override; ResultOrError CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQueueImpl() override; ResultOrError CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; diff --git a/src/dawn_native/opengl/DeviceGL.cpp b/src/dawn_native/opengl/DeviceGL.cpp index a6b02a4197..38b7123ef7 100644 --- a/src/dawn_native/opengl/DeviceGL.cpp +++ b/src/dawn_native/opengl/DeviceGL.cpp @@ -56,7 +56,7 @@ namespace dawn_native { namespace opengl { InitTogglesFromDriver(); mFormatTable = BuildGLFormatTable(); - return DeviceBase::Initialize(); + return DeviceBase::Initialize(new Queue(this)); } void Device::InitTogglesFromDriver() { @@ -115,9 +115,6 @@ namespace dawn_native { namespace opengl { const PipelineLayoutDescriptor* descriptor) { return new PipelineLayout(this, descriptor); } - ResultOrError Device::CreateQueueImpl() { - return new Queue(this); - } ResultOrError Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return new RenderPipeline(this, descriptor); diff --git a/src/dawn_native/opengl/DeviceGL.h b/src/dawn_native/opengl/DeviceGL.h index f2749932e1..f892a84cfc 100644 --- a/src/dawn_native/opengl/DeviceGL.h +++ b/src/dawn_native/opengl/DeviceGL.h @@ -78,7 +78,6 @@ namespace dawn_native { namespace opengl { const ComputePipelineDescriptor* descriptor) override; ResultOrError CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQueueImpl() override; ResultOrError CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp index 4cbce45efe..7ce2e6c7ba 100644 --- a/src/dawn_native/vulkan/DeviceVk.cpp +++ b/src/dawn_native/vulkan/DeviceVk.cpp @@ -97,7 +97,7 @@ namespace dawn_native { namespace vulkan { // the decision if it is not applicable. ApplyDepth24PlusS8Toggle(); - return DeviceBase::Initialize(); + return DeviceBase::Initialize(new Queue(this)); } Device::~Device() { @@ -127,9 +127,6 @@ namespace dawn_native { namespace vulkan { const PipelineLayoutDescriptor* descriptor) { return PipelineLayout::Create(this, descriptor); } - ResultOrError Device::CreateQueueImpl() { - return Queue::Create(this); - } ResultOrError Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return RenderPipeline::Create(this, descriptor); diff --git a/src/dawn_native/vulkan/DeviceVk.h b/src/dawn_native/vulkan/DeviceVk.h index 40c0e3de27..255971f1c3 100644 --- a/src/dawn_native/vulkan/DeviceVk.h +++ b/src/dawn_native/vulkan/DeviceVk.h @@ -112,7 +112,6 @@ namespace dawn_native { namespace vulkan { const ComputePipelineDescriptor* descriptor) override; ResultOrError CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQueueImpl() override; ResultOrError CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; diff --git a/src/include/dawn_native/DawnNative.h b/src/include/dawn_native/DawnNative.h index 0767e6bcd6..219e53fa94 100644 --- a/src/include/dawn_native/DawnNative.h +++ b/src/include/dawn_native/DawnNative.h @@ -175,6 +175,9 @@ namespace dawn_native { // Backdoor to get the number of lazy clears for testing DAWN_NATIVE_EXPORT size_t GetLazyClearCountForTesting(WGPUDevice device); + // Backdoor to get the number of deprecation warnings for testing + DAWN_NATIVE_EXPORT size_t GetDeprecationWarningCountForTesting(WGPUDevice device); + // Query if texture has been initialized DAWN_NATIVE_EXPORT bool IsTextureSubresourceInitialized(WGPUTexture texture, uint32_t baseMipLevel, diff --git a/src/tests/BUILD.gn b/src/tests/BUILD.gn index 39799187c4..dd4e3acbd1 100644 --- a/src/tests/BUILD.gn +++ b/src/tests/BUILD.gn @@ -50,9 +50,7 @@ if (!build_with_chromium) { static_library("gtest") { testonly = true - sources = [ - "${googletest_dir}/googletest/src/gtest-all.cc", - ] + sources = [ "${googletest_dir}/googletest/src/gtest-all.cc" ] public_configs = [ ":gtest_config" ] } @@ -66,9 +64,7 @@ if (!build_with_chromium) { static_library("gmock") { testonly = true - sources = [ - "${googletest_dir}/googlemock/src/gmock-all.cc", - ] + sources = [ "${googletest_dir}/googlemock/src/gmock-all.cc" ] public_configs = [ ":gmock_config" ] } @@ -241,6 +237,7 @@ source_set("dawn_end2end_tests_sources") { "end2end/CopyTests.cpp", "end2end/CullingTests.cpp", "end2end/DebugMarkerTests.cpp", + "end2end/DeprecatedAPITests.cpp", "end2end/DepthStencilStateTests.cpp", "end2end/DestroyTests.cpp", "end2end/DeviceLostTests.cpp", @@ -257,6 +254,7 @@ source_set("dawn_end2end_tests_sources") { "end2end/ObjectCachingTests.cpp", "end2end/OpArrayLengthTests.cpp", "end2end/PrimitiveTopologyTests.cpp", + "end2end/QueueTests.cpp", "end2end/RenderBundleTests.cpp", "end2end/RenderPassLoadOpTests.cpp", "end2end/RenderPassTests.cpp", @@ -325,9 +323,7 @@ source_set("dawn_white_box_tests_sources") { "${dawn_root}/src/dawn_native:dawn_native_static", ] - sources = [ - "DawnTest.h", - ] + sources = [ "DawnTest.h" ] if (dawn_enable_vulkan) { deps += [ "${dawn_root}/third_party/khronos:vulkan_headers" ] diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp index 0d4a87839e..0ca89ff3a3 100644 --- a/src/tests/DawnTest.cpp +++ b/src/tests/DawnTest.cpp @@ -729,7 +729,7 @@ void DawnTestBase::SetUp() { // the deferred expectations. dawnProcSetProcs(&procs); device = wgpu::Device::Acquire(cDevice); - queue = device.CreateQueue(); + queue = device.GetDefaultQueue(); device.SetUncapturedErrorCallback(OnDeviceError, this); device.SetDeviceLostCallback(OnDeviceLost, this); diff --git a/src/tests/end2end/ClipSpaceTests.cpp b/src/tests/end2end/ClipSpaceTests.cpp index 77f503edf3..80ed9efe06 100644 --- a/src/tests/end2end/ClipSpaceTests.cpp +++ b/src/tests/end2end/ClipSpaceTests.cpp @@ -92,7 +92,6 @@ TEST_P(ClipSpaceTest, ClipSpace) { renderPass.Draw(6); renderPass.EndPass(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, colorTexture, kSize - 1, kSize - 1); diff --git a/src/tests/end2end/CullingTests.cpp b/src/tests/end2end/CullingTests.cpp index 9be2b982ea..060c4918ce 100644 --- a/src/tests/end2end/CullingTests.cpp +++ b/src/tests/end2end/CullingTests.cpp @@ -87,7 +87,6 @@ class CullingTest : public DawnTest { renderPass.Draw(6); renderPass.EndPass(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); const RGBA8 kBackgroundColor = RGBA8::kBlue; diff --git a/src/tests/end2end/DeprecatedAPITests.cpp b/src/tests/end2end/DeprecatedAPITests.cpp new file mode 100644 index 0000000000..ca8ba6b58e --- /dev/null +++ b/src/tests/end2end/DeprecatedAPITests.cpp @@ -0,0 +1,58 @@ +// Copyright 2020 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This file contains test for deprecated parts of Dawn's API while following WebGPU's evolution. +// It contains test for the "old" behavior that will be deleted once users are migrated, tests that +// a deprecation warning is emitted when the "old" behavior is used, and tests that an error is +// emitted when both the old and the new behavior are used (when applicable). + +#include "tests/DawnTest.h" + +class DeprecationTests : public DawnTest {}; + +#define EXPECT_DEPRECATION_WARNING(statement) \ + do { \ + if (UsesWire()) { \ + statement; \ + } else { \ + size_t warningsBefore = \ + dawn_native::GetDeprecationWarningCountForTesting(device.Get()); \ + statement; \ + size_t warningsAfter = \ + dawn_native::GetDeprecationWarningCountForTesting(device.Get()); \ + EXPECT_EQ(warningsAfter, warningsBefore + 1); \ + } \ + } while (0) + +// Tests for Device::CreateQueue -> Device::GetDefaultQueue. + +// Test that using CreateQueue produces a deprecation warning +TEST_P(DeprecationTests, CreateQueueIsDeprecated) { + EXPECT_DEPRECATION_WARNING(device.CreateQueue()); +} + +// Test that queues created from CreateQueue can be used for things +TEST_P(DeprecationTests, CreateQueueReturnsFunctionalQueue) { + wgpu::Queue q; + EXPECT_DEPRECATION_WARNING(q = device.CreateQueue()); + + q.Submit(0, nullptr); +} + +DAWN_INSTANTIATE_TEST(DeprecationTests, + D3D12Backend(), + MetalBackend(), + NullBackend(), + OpenGLBackend(), + VulkanBackend()); diff --git a/src/tests/end2end/MultisampledRenderingTests.cpp b/src/tests/end2end/MultisampledRenderingTests.cpp index 7d2aba65a4..8cd177ffe5 100644 --- a/src/tests/end2end/MultisampledRenderingTests.cpp +++ b/src/tests/end2end/MultisampledRenderingTests.cpp @@ -238,7 +238,6 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTexture) { } wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); VerifyResolveTarget(kGreen, mResolveTexture); @@ -279,7 +278,6 @@ TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) { } wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); // The color of the pixel in the middle of mResolveTexture should be green if MSAA resolve runs @@ -317,7 +315,6 @@ TEST_P(MultisampledRenderingTest, ResolveInAnotherRenderPass) { } wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); VerifyResolveTarget(kGreen, mResolveTexture); @@ -351,7 +348,6 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) { } wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); VerifyResolveTarget(kRed, mResolveTexture); @@ -390,7 +386,6 @@ TEST_P(MultisampledRenderingTest, ResolveOneMultisampledTextureTwice) { } wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); VerifyResolveTarget(kGreen, mResolveTexture); @@ -429,7 +424,6 @@ TEST_P(MultisampledRenderingTest, ResolveIntoOneMipmapLevelOf2DTexture) { } wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); VerifyResolveTarget(kGreen, resolveTexture, kBaseMipLevel, 0); @@ -488,7 +482,6 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) { } wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); VerifyResolveTarget(kRed, resolveTexture1, kBaseMipLevel1, kBaseArrayLayer1); diff --git a/src/tests/end2end/QueueTests.cpp b/src/tests/end2end/QueueTests.cpp new file mode 100644 index 0000000000..242503b0f0 --- /dev/null +++ b/src/tests/end2end/QueueTests.cpp @@ -0,0 +1,36 @@ +// Copyright 2020 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This file contains test for deprecated parts of Dawn's API while following WebGPU's evolution. +// It contains test for the "old" behavior that will be deleted once users are migrated, tests that +// a deprecation warning is emitted when the "old" behavior is used, and tests that an error is +// emitted when both the old and the new behavior are used (when applicable). + +#include "tests/DawnTest.h" + +class QueueTests : public DawnTest {}; + +// Test that GetDefaultQueue always returns the same object. +TEST_P(QueueTests, GetDefaultQueueSameObject) { + wgpu::Queue q1 = device.GetDefaultQueue(); + wgpu::Queue q2 = device.GetDefaultQueue(); + EXPECT_EQ(q1.Get() == q2.Get(), !UsesWire()); +} + +DAWN_INSTANTIATE_TEST(QueueTests, + D3D12Backend(), + MetalBackend(), + NullBackend(), + OpenGLBackend(), + VulkanBackend()); diff --git a/src/tests/end2end/SwapChainValidationTests.cpp b/src/tests/end2end/SwapChainValidationTests.cpp index 444cd359c6..7199a37cf0 100644 --- a/src/tests/end2end/SwapChainValidationTests.cpp +++ b/src/tests/end2end/SwapChainValidationTests.cpp @@ -86,7 +86,6 @@ class SwapChainValidationTests : public DawnTest { pass.EndPass(); wgpu::CommandBuffer commands = encoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); ASSERT_DEVICE_ERROR(queue.Submit(1, &commands)); } }; @@ -244,7 +243,6 @@ TEST_P(SwapChainValidationTests, ReturnedViewCharacteristics) { pass.EndPass(); wgpu::CommandBuffer commands = encoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commands); // Check that view doesn't have extra formats like Sampled. diff --git a/src/tests/end2end/ViewportTests.cpp b/src/tests/end2end/ViewportTests.cpp index e847aaa9fe..d001368314 100644 --- a/src/tests/end2end/ViewportTests.cpp +++ b/src/tests/end2end/ViewportTests.cpp @@ -152,7 +152,6 @@ class ViewportTest : public DawnTest { } wgpu::CommandBuffer commandBuffer = commandEncoder.Finish(); - wgpu::Queue queue = device.CreateQueue(); queue.Submit(1, &commandBuffer); const RGBA8 kColor[ColorTypeCount] = { diff --git a/src/tests/unittests/validation/BufferValidationTests.cpp b/src/tests/unittests/validation/BufferValidationTests.cpp index d9342d3ed1..1bda448c6c 100644 --- a/src/tests/unittests/validation/BufferValidationTests.cpp +++ b/src/tests/unittests/validation/BufferValidationTests.cpp @@ -98,7 +98,7 @@ class BufferValidationTest : public ValidationTest { mockBufferMapReadCallback = std::make_unique(); mockBufferMapWriteCallback = std::make_unique(); - queue = device.CreateQueue(); + queue = device.GetDefaultQueue(); } void TearDown() override { diff --git a/src/tests/unittests/validation/ErrorScopeValidationTests.cpp b/src/tests/unittests/validation/ErrorScopeValidationTests.cpp index 414e07331b..4672247876 100644 --- a/src/tests/unittests/validation/ErrorScopeValidationTests.cpp +++ b/src/tests/unittests/validation/ErrorScopeValidationTests.cpp @@ -134,7 +134,7 @@ TEST_F(ErrorScopeValidationTest, PushPopBalanced) { // Test that error scopes do not call their callbacks until after an enclosed Queue::Submit // completes TEST_F(ErrorScopeValidationTest, CallbackAfterQueueSubmit) { - wgpu::Queue queue = device.CreateQueue(); + wgpu::Queue queue = device.GetDefaultQueue(); device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory); queue.Submit(0, nullptr); @@ -149,7 +149,7 @@ TEST_F(ErrorScopeValidationTest, CallbackAfterQueueSubmit) { // Test that parent error scopes do not call their callbacks until after an enclosed Queue::Submit // completes TEST_F(ErrorScopeValidationTest, CallbackAfterQueueSubmitNested) { - wgpu::Queue queue = device.CreateQueue(); + wgpu::Queue queue = device.GetDefaultQueue(); device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory); device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory); @@ -167,7 +167,7 @@ TEST_F(ErrorScopeValidationTest, CallbackAfterQueueSubmitNested) { // Test a callback that returns asynchronously followed by a synchronous one TEST_F(ErrorScopeValidationTest, AsynchronousThenSynchronous) { - wgpu::Queue queue = device.CreateQueue(); + wgpu::Queue queue = device.GetDefaultQueue(); device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory); queue.Submit(0, nullptr); @@ -187,7 +187,7 @@ TEST_F(ErrorScopeValidationTest, AsynchronousThenSynchronous) { // Test that if the device is destroyed before the callback occurs, it is called with NoError // because all previous operations are waited upon before the destruction returns. TEST_F(ErrorScopeValidationTest, DeviceDestroyedBeforeCallback) { - wgpu::Queue queue = device.CreateQueue(); + wgpu::Queue queue = device.GetDefaultQueue(); device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory); queue.Submit(0, nullptr); diff --git a/src/tests/unittests/validation/FenceValidationTests.cpp b/src/tests/unittests/validation/FenceValidationTests.cpp index dfb96932a0..31a1413fcf 100644 --- a/src/tests/unittests/validation/FenceValidationTests.cpp +++ b/src/tests/unittests/validation/FenceValidationTests.cpp @@ -57,7 +57,7 @@ class FenceValidationTest : public ValidationTest { ValidationTest::SetUp(); mockFenceOnCompletionCallback = std::make_unique(); - queue = device.CreateQueue(); + queue = device.GetDefaultQueue(); } void TearDown() override { @@ -182,8 +182,9 @@ TEST_F(FenceValidationTest, SignalSuccess) { } // Test it is invalid to signal a fence on a different queue than it was created on -TEST_F(FenceValidationTest, SignalWrongQueue) { - wgpu::Queue queue2 = device.CreateQueue(); +// DISABLED until we have support for multiple queues +TEST_F(FenceValidationTest, DISABLED_SignalWrongQueue) { + wgpu::Queue queue2 = device.GetDefaultQueue(); wgpu::FenceDescriptor descriptor; descriptor.initialValue = 1; @@ -193,8 +194,9 @@ TEST_F(FenceValidationTest, SignalWrongQueue) { } // Test that signaling a fence on a wrong queue does not update fence signaled value -TEST_F(FenceValidationTest, SignalWrongQueueDoesNotUpdateValue) { - wgpu::Queue queue2 = device.CreateQueue(); +// DISABLED until we have support for multiple queues +TEST_F(FenceValidationTest, DISABLED_SignalWrongQueueDoesNotUpdateValue) { + wgpu::Queue queue2 = device.GetDefaultQueue(); wgpu::FenceDescriptor descriptor; descriptor.initialValue = 1; diff --git a/src/tests/unittests/validation/QueueSubmitValidationTests.cpp b/src/tests/unittests/validation/QueueSubmitValidationTests.cpp index 4c030141f6..66e0691c79 100644 --- a/src/tests/unittests/validation/QueueSubmitValidationTests.cpp +++ b/src/tests/unittests/validation/QueueSubmitValidationTests.cpp @@ -48,7 +48,7 @@ TEST_F(QueueSubmitValidationTest, SubmitWithMappedBuffer) { commands = encoder.Finish(); } - wgpu::Queue queue = device.CreateQueue(); + wgpu::Queue queue = device.GetDefaultQueue(); // Submitting when the buffer has never been mapped should succeed queue.Submit(1, &commands); diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp index a75c5cfdd7..5976832db0 100644 --- a/src/tests/unittests/validation/TextureValidationTests.cpp +++ b/src/tests/unittests/validation/TextureValidationTests.cpp @@ -23,6 +23,10 @@ namespace { class TextureValidationTest : public ValidationTest { protected: + void SetUp() override { + queue = device.GetDefaultQueue(); + } + wgpu::TextureDescriptor CreateDefaultTextureDescriptor() { wgpu::TextureDescriptor descriptor; descriptor.size.width = kWidth; @@ -37,7 +41,7 @@ class TextureValidationTest : public ValidationTest { return descriptor; } - wgpu::Queue queue = device.CreateQueue(); + wgpu::Queue queue; private: static constexpr uint32_t kWidth = 32; diff --git a/src/tests/unittests/wire/WireArgumentTests.cpp b/src/tests/unittests/wire/WireArgumentTests.cpp index dce472808f..457625a56e 100644 --- a/src/tests/unittests/wire/WireArgumentTests.cpp +++ b/src/tests/unittests/wire/WireArgumentTests.cpp @@ -233,9 +233,9 @@ TEST_F(WireArgumentTests, ObjectsAsPointerArgument) { } // Create queue - WGPUQueue queue = wgpuDeviceCreateQueue(device); + WGPUQueue queue = wgpuDeviceGetDefaultQueue(device); WGPUQueue apiQueue = api.GetNewQueue(); - EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue)); + EXPECT_CALL(api, DeviceGetDefaultQueue(apiDevice)).WillOnce(Return(apiQueue)); // Submit command buffer and check we got a call with both API-side command buffers wgpuQueueSubmit(queue, 2, cmdBufs); diff --git a/src/tests/unittests/wire/WireFenceTests.cpp b/src/tests/unittests/wire/WireFenceTests.cpp index eb33df90ac..ffff49f374 100644 --- a/src/tests/unittests/wire/WireFenceTests.cpp +++ b/src/tests/unittests/wire/WireFenceTests.cpp @@ -44,9 +44,9 @@ class WireFenceTests : public WireTest { std::make_unique>(); { - queue = wgpuDeviceCreateQueue(device); + queue = wgpuDeviceGetDefaultQueue(device); apiQueue = api.GetNewQueue(); - EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue)); + EXPECT_CALL(api, DeviceGetDefaultQueue(apiDevice)).WillOnce(Return(apiQueue)); FlushClient(); } { @@ -228,9 +228,9 @@ TEST_F(WireFenceTests, DestroyBeforeOnCompletionEnd) { // Test that signaling a fence on a wrong queue is invalid TEST_F(WireFenceTests, SignalWrongQueue) { - WGPUQueue queue2 = wgpuDeviceCreateQueue(device); + WGPUQueue queue2 = wgpuDeviceGetDefaultQueue(device); WGPUQueue apiQueue2 = api.GetNewQueue(); - EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2)); + EXPECT_CALL(api, DeviceGetDefaultQueue(apiDevice)).WillOnce(Return(apiQueue2)); FlushClient(); wgpuQueueSignal(queue2, fence, 2u); // error @@ -241,9 +241,9 @@ TEST_F(WireFenceTests, SignalWrongQueue) { // Test that signaling a fence on a wrong queue does not update fence signaled value TEST_F(WireFenceTests, SignalWrongQueueDoesNotUpdateValue) { - WGPUQueue queue2 = wgpuDeviceCreateQueue(device); + WGPUQueue queue2 = wgpuDeviceGetDefaultQueue(device); WGPUQueue apiQueue2 = api.GetNewQueue(); - EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2)); + EXPECT_CALL(api, DeviceGetDefaultQueue(apiDevice)).WillOnce(Return(apiQueue2)); FlushClient(); wgpuQueueSignal(queue2, fence, 2u); // error diff --git a/src/tests/unittests/wire/WireMultipleDeviceTests.cpp b/src/tests/unittests/wire/WireMultipleDeviceTests.cpp index 6791fb2915..da6f1e0d2f 100644 --- a/src/tests/unittests/wire/WireMultipleDeviceTests.cpp +++ b/src/tests/unittests/wire/WireMultipleDeviceTests.cpp @@ -135,14 +135,14 @@ TEST_F(WireMultipleDeviceTests, ValidatesSameDevice) { WireHolder wireB; // Create the objects - WGPUQueue queueA = wgpuDeviceCreateQueue(wireA.ClientDevice()); - WGPUQueue queueB = wgpuDeviceCreateQueue(wireB.ClientDevice()); + WGPUQueue queueA = wgpuDeviceGetDefaultQueue(wireA.ClientDevice()); + WGPUQueue queueB = wgpuDeviceGetDefaultQueue(wireB.ClientDevice()); WGPUFenceDescriptor desc = {}; WGPUFence fenceA = wgpuQueueCreateFence(queueA, &desc); // Flush on wire B. We should see the queue created. - EXPECT_CALL(*wireB.Api(), DeviceCreateQueue(wireB.ServerDevice())) + EXPECT_CALL(*wireB.Api(), DeviceGetDefaultQueue(wireB.ServerDevice())) .WillOnce(Return(wireB.Api()->GetNewQueue())); wireB.FlushClient(); diff --git a/src/tests/white_box/VulkanImageWrappingTestsDmaBuf.cpp b/src/tests/white_box/VulkanImageWrappingTestsDmaBuf.cpp index bb66024031..ca4960511e 100644 --- a/src/tests/white_box/VulkanImageWrappingTestsDmaBuf.cpp +++ b/src/tests/white_box/VulkanImageWrappingTestsDmaBuf.cpp @@ -305,7 +305,7 @@ namespace dawn_native { namespace vulkan { wgpu::CommandBuffer commands = encoder.Finish(); - wgpu::Queue queue = dawnDevice.CreateQueue(); + wgpu::Queue queue = dawnDevice.GetDefaultQueue(); queue.Submit(1, &commands); } @@ -482,7 +482,7 @@ namespace dawn_native { namespace vulkan { ClearImage(secondDevice, copySrcTexture, {1 / 255.0f, 2 / 255.0f, 3 / 255.0f, 4 / 255.0f}); // Copy color B on |secondDevice| - wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue(); + wgpu::Queue secondDeviceQueue = secondDevice.GetDefaultQueue(); SimpleCopyTextureToTexture(secondDevice, secondDeviceQueue, copySrcTexture, secondDeviceWrappedTexture); @@ -578,7 +578,7 @@ namespace dawn_native { namespace vulkan { secondDevice, &defaultDescriptor, nextFd, defaultStride, defaultModifier, {signalFd}); // Copy color B on |secondDevice| - wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue(); + wgpu::Queue secondDeviceQueue = secondDevice.GetDefaultQueue(); // Create a buffer on |secondDevice| wgpu::Buffer copySrcBuffer = @@ -681,8 +681,8 @@ namespace dawn_native { namespace vulkan { wgpu::Device::Acquire(reinterpret_cast(thirdDeviceVk)); // Make queue for device 2 and 3 - wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue(); - wgpu::Queue thirdDeviceQueue = thirdDevice.CreateQueue(); + wgpu::Queue secondDeviceQueue = secondDevice.GetDefaultQueue(); + wgpu::Queue thirdDeviceQueue = thirdDevice.GetDefaultQueue(); // Create BOs for A, B, C gbm_bo* gbmBoA = CreateGbmBo(1, 1, true /* linear */); @@ -773,7 +773,7 @@ namespace dawn_native { namespace vulkan { textures.push_back(device.CreateTexture(&descriptor)); } - wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue(); + wgpu::Queue secondDeviceQueue = secondDevice.GetDefaultQueue(); // Make an image on |secondDevice| gbm_bo* gbmBo = CreateGbmBo(640, 480, false /* linear */); diff --git a/src/tests/white_box/VulkanImageWrappingTestsOpaqueFD.cpp b/src/tests/white_box/VulkanImageWrappingTestsOpaqueFD.cpp index 0862e163a7..fef1338940 100644 --- a/src/tests/white_box/VulkanImageWrappingTestsOpaqueFD.cpp +++ b/src/tests/white_box/VulkanImageWrappingTestsOpaqueFD.cpp @@ -422,7 +422,7 @@ namespace dawn_native { namespace vulkan { wgpu::CommandBuffer commands = encoder.Finish(); - wgpu::Queue queue = dawnDevice.CreateQueue(); + wgpu::Queue queue = dawnDevice.GetDefaultQueue(); queue.Submit(1, &commands); } @@ -618,7 +618,7 @@ namespace dawn_native { namespace vulkan { ClearImage(secondDevice, copySrcTexture, {1 / 255.0f, 2 / 255.0f, 3 / 255.0f, 4 / 255.0f}); // Copy color B on |secondDevice| - wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue(); + wgpu::Queue secondDeviceQueue = secondDevice.GetDefaultQueue(); SimpleCopyTextureToTexture(secondDevice, secondDeviceQueue, copySrcTexture, secondDeviceWrappedTexture); @@ -722,7 +722,7 @@ namespace dawn_native { namespace vulkan { defaultMemoryTypeIndex, {signalFd}); // Copy color B on |secondDevice| - wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue(); + wgpu::Queue secondDeviceQueue = secondDevice.GetDefaultQueue(); // Create a buffer on |secondDevice| wgpu::Buffer copySrcBuffer = @@ -831,8 +831,8 @@ namespace dawn_native { namespace vulkan { wgpu::Device::Acquire(reinterpret_cast(thirdDeviceVk)); // Make queue for device 2 and 3 - wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue(); - wgpu::Queue thirdDeviceQueue = thirdDevice.CreateQueue(); + wgpu::Queue secondDeviceQueue = secondDevice.GetDefaultQueue(); + wgpu::Queue thirdDeviceQueue = thirdDevice.GetDefaultQueue(); // Allocate memory for A, B, C VkImage imageA; @@ -944,7 +944,7 @@ namespace dawn_native { namespace vulkan { textures.push_back(device.CreateTexture(&descriptor)); } - wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue(); + wgpu::Queue secondDeviceQueue = secondDevice.GetDefaultQueue(); // Make an image on |secondDevice| VkImage imageA;