Remove SwapChain from webgpu.h
This has been completely replaced by WGPUSurface.
Also removes tests, wire support, and dawn::native support for
swapchains. The SwapChain objects stays in dawn::native's implementation
details as folding it in surface would be a lot of changes for this CL.
It is a low-priority cleanup to do so and the current set-up might even
be a good long-term one if we rename SwapChain to SurfaceConnection for
example.
Bug: 42241264
Change-Id: I8e32e9ccceec0a353edd5ac8f0983a9faaff1396
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/208994
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/docs/dawn/features/surface_capabilities.md b/docs/dawn/features/surface_capabilities.md
deleted file mode 100644
index e5c8435..0000000
--- a/docs/dawn/features/surface_capabilities.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# Surface Capabilities
-
-The `surface-capabilities` feature allows querying a surface's capabilities and creating a swap chain with additional usage flags.
-
-Additional functionality:
- - Adds `wgpu::Device::GetSupportedSurfaceUsage(wgpu::Surface)` method for querying the surface's supported usage flags. One or the combination of these flags can be used to create a swap chain.
-
-Example Usage:
-```
-wgpu::TextureUsage supportedUsage = device.GetSupportedSurfaceUsage(surface);
-
-wgpu::SwapChainDescriptor desc = {};
-// set usage flags.
-desc.usage = supportedUsage;
-
-device.CreateSwapChain(surface, &desc);
-```
-
-Notes:
- - If this feature is not enabled, only `wgpu::TextureUsage::RenderAttachment` flag is allowed to be used in `wgpu::SwapChainDescriptor::usage`.
diff --git a/include/dawn/wire/WireClient.h b/include/dawn/wire/WireClient.h
index e578b5f..01aebbd 100644
--- a/include/dawn/wire/WireClient.h
+++ b/include/dawn/wire/WireClient.h
@@ -56,12 +56,6 @@
Handle deviceHandle;
};
-struct ReservedSwapChain {
- WGPUSwapChain swapchain;
- Handle deviceHandle;
- Handle handle;
-};
-
struct ReservedSurface {
WGPUSurface surface;
Handle instanceHandle;
@@ -87,15 +81,12 @@
ReservedBuffer ReserveBuffer(WGPUDevice device, const WGPUBufferDescriptor* descriptor);
ReservedTexture ReserveTexture(WGPUDevice device, const WGPUTextureDescriptor* descriptor);
- ReservedSwapChain ReserveSwapChain(WGPUDevice device,
- const WGPUSwapChainDescriptor* descriptor);
ReservedSurface ReserveSurface(WGPUInstance instance,
const WGPUSurfaceCapabilities* capabilities);
ReservedInstance ReserveInstance(const WGPUInstanceDescriptor* descriptor = nullptr);
void ReclaimBufferReservation(const ReservedBuffer& reservation);
void ReclaimTextureReservation(const ReservedTexture& reservation);
- void ReclaimSwapChainReservation(const ReservedSwapChain& reservation);
void ReclaimSurfaceReservation(const ReservedSurface& reservation);
void ReclaimInstanceReservation(const ReservedInstance& reservation);
diff --git a/include/dawn/wire/WireServer.h b/include/dawn/wire/WireServer.h
index e5b153a..c4c3f01 100644
--- a/include/dawn/wire/WireServer.h
+++ b/include/dawn/wire/WireServer.h
@@ -56,7 +56,6 @@
bool InjectBuffer(WGPUBuffer buffer, const Handle& handle, const Handle& deviceHandle);
bool InjectTexture(WGPUTexture texture, const Handle& handle, const Handle& deviceHandle);
- bool InjectSwapChain(WGPUSwapChain swapchain, const Handle& handle, const Handle& deviceHandle);
bool InjectSurface(WGPUSurface surface, const Handle& handle, const Handle& instanceHandle);
bool InjectInstance(WGPUInstance instance, const Handle& handle);
diff --git a/src/dawn/dawn.json b/src/dawn/dawn.json
index 3858e16..4a9c945 100644
--- a/src/dawn/dawn.json
+++ b/src/dawn/dawn.json
@@ -1587,15 +1587,6 @@
]
},
{
- "name": "create swap chain",
- "tags": ["art", "dawn", "emscripten"],
- "returns": "swap chain",
- "args": [
- {"name": "surface", "type": "surface"},
- {"name": "descriptor", "type": "swap chain descriptor", "annotation": "const*"}
- ]
- },
- {
"name": "create texture",
"returns": "texture",
"args": [
@@ -4064,13 +4055,6 @@
]
},
{
- "name": "get preferred format",
- "returns": "texture format",
- "args": [
- {"name": "adapter", "type": "adapter"}
- ]
- },
- {
"name": "present",
"returns": "void",
"args": []
@@ -4223,28 +4207,6 @@
{"name": "swap chain panel", "type": "void", "annotation": "*"}
]
},
- "swap chain": {
- "category": "object",
- "tags": ["art", "dawn", "emscripten"],
- "methods": [
- {"name": "get current texture view", "returns": "texture view"},
- {"name": "get current texture", "returns": "texture", "tags": ["dawn"]},
- {"name": "present"}
- ]
- },
- "swap chain descriptor": {
- "category": "structure",
- "tags": ["art", "dawn", "emscripten"],
- "extensible": "in",
- "members": [
- {"name": "label", "type": "string view", "optional": true},
- {"name": "usage", "type": "texture usage"},
- {"name": "format", "type": "texture format"},
- {"name": "width", "type": "uint32_t"},
- {"name": "height", "type": "uint32_t"},
- {"name": "present mode", "type": "present mode"}
- ]
- },
"surface texture": {
"category": "structure",
"members": [
diff --git a/src/dawn/dawn_wire.json b/src/dawn/dawn_wire.json
index 6742701..3ca1755 100644
--- a/src/dawn/dawn_wire.json
+++ b/src/dawn/dawn_wire.json
@@ -292,8 +292,7 @@
"InstanceProcessEvents",
"InstanceWaitAny",
"SurfaceConfigure",
- "SurfaceUnconfigure",
- "SwapChainGetCurrentTexture"
+ "SurfaceUnconfigure"
],
"client_special_objects": [
"Adapter",
@@ -305,7 +304,6 @@
"ShaderModule",
"Surface",
"SurfaceCapabilities",
- "SwapChain",
"Texture"
],
"server_custom_pre_handler_commands": [
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index 682d944..467678d 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -584,7 +584,6 @@
ObjectType::RenderPipeline,
ObjectType::ComputePipeline,
ObjectType::PipelineLayout,
- ObjectType::SwapChain,
ObjectType::BindGroup,
ObjectType::BindGroupLayout,
ObjectType::ShaderModule,
@@ -1622,26 +1621,6 @@
return ReturnToAPI(std::move(result));
}
-SwapChainBase* DeviceBase::APICreateSwapChain(Surface* surface,
- const SwapChainDescriptor* descriptor) {
- Ref<SwapChainBase> result;
- if (ConsumedError(CreateSwapChain(surface, descriptor), &result,
- "calling %s.CreateSwapChain(%s).", this, descriptor)) {
- SurfaceConfiguration config;
- config.nextInChain = descriptor->nextInChain;
- config.device = this;
- config.width = descriptor->width;
- config.height = descriptor->height;
- config.format = descriptor->format;
- config.usage = descriptor->usage;
- config.presentMode = descriptor->presentMode;
- config.viewFormatCount = 0;
- config.viewFormats = nullptr;
- config.alphaMode = wgpu::CompositeAlphaMode::Opaque;
- result = SwapChainBase::MakeError(this, &config);
- }
- return ReturnToAPI(std::move(result));
-}
TextureBase* DeviceBase::APICreateTexture(const TextureDescriptor* descriptor) {
Ref<TextureBase> result;
if (ConsumedError(CreateTexture(descriptor), &result, InternalErrorType::OutOfMemory,
@@ -2341,47 +2320,6 @@
return GetOrCreateShaderModule(unpacked, internalExtensions, &parseResult, compilationMessages);
}
-ResultOrError<Ref<SwapChainBase>> DeviceBase::CreateSwapChain(
- Surface* surface,
- const SwapChainDescriptor* descriptor) {
- GetInstance()->EmitDeprecationWarning(
- "The explicit creation of a SwapChain object is deprecated and should be replaced by "
- "Surface configuration.");
-
- DAWN_TRY(ValidateIsAlive());
- if (IsValidationEnabled()) {
- DAWN_TRY_CONTEXT(ValidateSwapChainDescriptor(this, surface, descriptor), "validating %s",
- descriptor);
- }
-
- SurfaceConfiguration config;
- config.nextInChain = descriptor->nextInChain;
- config.device = this;
- config.width = descriptor->width;
- config.height = descriptor->height;
- config.format = descriptor->format;
- config.usage = descriptor->usage;
- config.presentMode = descriptor->presentMode;
- config.viewFormatCount = 0;
- config.viewFormats = nullptr;
- config.alphaMode = wgpu::CompositeAlphaMode::Opaque;
-
- SwapChainBase* previousSwapChain = surface->GetAttachedSwapChain();
- ResultOrError<Ref<SwapChainBase>> maybeNewSwapChain =
- CreateSwapChainImpl(surface, previousSwapChain, &config);
-
- if (previousSwapChain != nullptr) {
- previousSwapChain->DetachFromSurface();
- }
-
- Ref<SwapChainBase> newSwapChain;
- DAWN_TRY_ASSIGN(newSwapChain, std::move(maybeNewSwapChain));
-
- newSwapChain->SetIsAttached();
- surface->SetAttachedSwapChain(newSwapChain.Get());
- return newSwapChain;
-}
-
ResultOrError<Ref<SwapChainBase>> DeviceBase::CreateSwapChain(Surface* surface,
SwapChainBase* previousSwapChain,
const SurfaceConfiguration* config) {
diff --git a/src/dawn/native/Device.h b/src/dawn/native/Device.h
index 1408924..9c1419a 100644
--- a/src/dawn/native/Device.h
+++ b/src/dawn/native/Device.h
@@ -226,10 +226,6 @@
const ShaderModuleDescriptor* descriptor,
const std::vector<tint::wgsl::Extension>& internalExtensions = {},
std::unique_ptr<OwnedCompilationMessages>* compilationMessages = nullptr);
- // Deprecated: this was the way to create a SwapChain when it was explicitly manipulated by the
- // end user.
- ResultOrError<Ref<SwapChainBase>> CreateSwapChain(Surface* surface,
- const SwapChainDescriptor* descriptor);
ResultOrError<Ref<SwapChainBase>> CreateSwapChain(Surface* surface,
SwapChainBase* previousSwapChain,
const SurfaceConfiguration* config);
@@ -282,8 +278,6 @@
}
ShaderModuleBase* APICreateErrorShaderModule2(const ShaderModuleDescriptor* descriptor,
StringView errorMessage);
- // TODO(crbug.com/dawn/2320): Remove after deprecation.
- SwapChainBase* APICreateSwapChain(Surface* surface, const SwapChainDescriptor* descriptor);
TextureBase* APICreateTexture(const TextureDescriptor* descriptor);
wgpu::TextureUsage APIGetSupportedSurfaceUsage(Surface* surface);
diff --git a/src/dawn/native/Surface.cpp b/src/dawn/native/Surface.cpp
index 62924fb..8f4e823 100644
--- a/src/dawn/native/Surface.cpp
+++ b/src/dawn/native/Surface.cpp
@@ -349,23 +349,6 @@
}
}
-SwapChainBase* Surface::GetAttachedSwapChain() {
- DAWN_ASSERT(!IsError());
- DAWN_ASSERT(mIsSwapChainManagedBySurface == ManagesSwapChain::Unknown ||
- mIsSwapChainManagedBySurface == ManagesSwapChain::No);
- mIsSwapChainManagedBySurface = ManagesSwapChain::No;
-
- return mSwapChain.Get();
-}
-void Surface::SetAttachedSwapChain(SwapChainBase* swapChain) {
- DAWN_ASSERT(!IsError());
- DAWN_ASSERT(mIsSwapChainManagedBySurface == ManagesSwapChain::Unknown ||
- mIsSwapChainManagedBySurface == ManagesSwapChain::No);
- mIsSwapChainManagedBySurface = ManagesSwapChain::No;
-
- mSwapChain = swapChain;
-}
-
InstanceBase* Surface::GetInstance() const {
return mInstance.Get();
}
@@ -448,11 +431,6 @@
SurfaceConfiguration config = *configIn;
mCurrentDevice = config.device; // next errors are routed to the new device
- DAWN_INVALID_IF(mIsSwapChainManagedBySurface == ManagesSwapChain::No,
- "%s cannot be configured because it is used by legacy swapchain %s.", this,
- mSwapChain.Get());
-
- mIsSwapChainManagedBySurface = ManagesSwapChain::Yes;
DAWN_TRY(mCapabilityCache->WithAdapterCapabilities(
GetCurrentDevice()->GetAdapter(), this,
@@ -499,15 +477,11 @@
DAWN_INVALID_IF(!mSwapChain.Get(), "%s is not configured.", this);
if (mSwapChain != nullptr) {
- if (mIsSwapChainManagedBySurface == ManagesSwapChain::Yes) {
- if (mRecycledSwapChain != nullptr) {
- mRecycledSwapChain->DetachFromSurface();
- mRecycledSwapChain = nullptr;
- }
- mRecycledSwapChain = mSwapChain;
- } else {
- mSwapChain->DetachFromSurface();
+ if (mRecycledSwapChain != nullptr) {
+ mRecycledSwapChain->DetachFromSurface();
+ mRecycledSwapChain = nullptr;
}
+ mRecycledSwapChain = mSwapChain;
mSwapChain = nullptr;
}
@@ -561,30 +535,12 @@
return {};
}
-ResultOrError<wgpu::TextureFormat> Surface::GetPreferredFormat(AdapterBase* adapter) const {
- GetInstance()->EmitDeprecationWarning(
- "GetPreferredFormat is deprecated, use GetCapabilities().format[0] instead as the "
- "preferred format.");
-
- wgpu::TextureFormat format = wgpu::TextureFormat::Undefined;
-
- DAWN_TRY(mCapabilityCache->WithAdapterCapabilities(
- adapter, this, [&](const PhysicalDeviceSurfaceCapabilities& caps) -> MaybeError {
- DAWN_INVALID_IF(caps.formats.empty(), "No format is supported by %s for %s.", adapter,
- this);
- format = caps.formats.front();
- return {};
- }));
-
- return format;
-}
-
MaybeError Surface::Present() {
DAWN_INVALID_IF(IsError(), "%s is invalid.", this);
DAWN_INVALID_IF(!mSwapChain.Get(), "%s is not configured.", this);
auto deviceLock(GetCurrentDevice()->GetScopedLock());
- mSwapChain->APIPresent();
+ DAWN_TRY(mSwapChain->Present());
return {};
}
@@ -626,21 +582,6 @@
}
}
-wgpu::TextureFormat Surface::APIGetPreferredFormat(AdapterBase* adapter) const {
- ResultOrError<wgpu::TextureFormat> resultOrError = GetPreferredFormat(adapter);
- wgpu::TextureFormat format;
- if (!GetCurrentDevice()) {
- if (mInstance->ConsumedError(std::move(resultOrError), &format)) {
- return wgpu::TextureFormat::Undefined;
- }
- } else if (GetCurrentDevice()->ConsumedError(std::move(resultOrError), &format,
- "calling %s.GetPreferredFormat(%s).", this,
- adapter)) {
- return wgpu::TextureFormat::Undefined;
- }
- return format;
-}
-
void Surface::APIPresent() {
MaybeError maybeError = Present();
if (!GetCurrentDevice()) {
diff --git a/src/dawn/native/Surface.h b/src/dawn/native/Surface.h
index 4f8f8e6..401e3d0 100644
--- a/src/dawn/native/Surface.h
+++ b/src/dawn/native/Surface.h
@@ -114,18 +114,12 @@
void* GetXDisplay() const;
uint32_t GetXWindow() const;
- // TODO(dawn:2320): Remove these 2 accessors once the deprecation period is finished and
- // Device::APICreateSwapChain gets dropped
- SwapChainBase* GetAttachedSwapChain();
- void SetAttachedSwapChain(SwapChainBase* swapChain);
-
const std::string& GetLabel() const;
// Dawn API
void APIConfigure(const SurfaceConfiguration* config);
wgpu::Status APIGetCapabilities(AdapterBase* adapter, SurfaceCapabilities* capabilities) const;
void APIGetCurrentTexture(SurfaceTexture* surfaceTexture) const;
- wgpu::TextureFormat APIGetPreferredFormat(AdapterBase* adapter) const;
void APIPresent();
void APIUnconfigure();
// TODO(crbug.com/42241188): Remove const char* version of the method.
@@ -141,7 +135,6 @@
MaybeError GetCapabilities(AdapterBase* adapter, SurfaceCapabilities* capabilities) const;
MaybeError GetCurrentTexture(SurfaceTexture* surfaceTexture) const;
- ResultOrError<wgpu::TextureFormat> GetPreferredFormat(AdapterBase* adapter) const;
MaybeError Present();
Ref<InstanceBase> mInstance;
@@ -157,17 +150,6 @@
// We keep on storing the previous swap chain after Unconfigure in case we could reuse it
Ref<SwapChainBase> mRecycledSwapChain;
- // This ensures that the user does not mix the legacy API (ManagesSwapChain::No, i.e., explicit
- // call to CreateSwapChain) with the new API (ManagesSwapChain::Yes, i.e., surface.configure).
- // TODO(dawn:2320): Remove and consider it is always Yes once Device::APICreateSwapChain gets
- // dropped
- enum class ManagesSwapChain {
- Yes,
- No,
- Unknown,
- };
- ManagesSwapChain mIsSwapChainManagedBySurface = ManagesSwapChain::Unknown;
-
// A cache is mutable because potentially modified in const-qualified getters
std::unique_ptr<AdapterSurfaceCapCache> mCapabilityCache;
diff --git a/src/dawn/native/SwapChain.cpp b/src/dawn/native/SwapChain.cpp
index 32c7a0c..55fc1bb 100644
--- a/src/dawn/native/SwapChain.cpp
+++ b/src/dawn/native/SwapChain.cpp
@@ -40,73 +40,6 @@
namespace dawn::native {
-namespace {
-
-class ErrorSwapChain final : public SwapChainBase {
- public:
- explicit ErrorSwapChain(DeviceBase* device, const SurfaceConfiguration* config)
- : SwapChainBase(device, config, ObjectBase::kError) {}
-
- private:
- ResultOrError<SwapChainTextureInfo> GetCurrentTextureImpl() override { DAWN_UNREACHABLE(); }
- MaybeError PresentImpl() override { DAWN_UNREACHABLE(); }
- void DetachFromSurfaceImpl() override { DAWN_UNREACHABLE(); }
-};
-
-} // anonymous namespace
-
-MaybeError ValidateSwapChainDescriptor(const DeviceBase* device,
- const Surface* surface,
- const SwapChainDescriptor* descriptor) {
- DAWN_INVALID_IF(surface->IsError(), "[Surface] is invalid.");
-
- DAWN_TRY(ValidatePresentMode(descriptor->presentMode));
-
-// TODO(crbug.com/dawn/160): Lift this restriction once wgpu::Instance::GetPreferredSurfaceFormat is
-// implemented.
-// TODO(dawn:286):
-#if DAWN_PLATFORM_IS(ANDROID)
- constexpr wgpu::TextureFormat kRequireSwapChainFormat = wgpu::TextureFormat::RGBA8Unorm;
-#else
- constexpr wgpu::TextureFormat kRequireSwapChainFormat = wgpu::TextureFormat::BGRA8Unorm;
-#endif // !DAWN_PLATFORM_IS(ANDROID)
- DAWN_INVALID_IF(descriptor->format != kRequireSwapChainFormat,
- "Format (%s) is not %s, which is (currently) the only accepted format.",
- descriptor->format, kRequireSwapChainFormat);
-
- if (device->HasFeature(Feature::SurfaceCapabilities)) {
- PhysicalDeviceSurfaceCapabilities caps;
- DAWN_TRY_ASSIGN(caps, device->GetPhysicalDevice()->GetSurfaceCapabilities(
- device->GetInstance(), surface));
- wgpu::TextureUsage validUsage = caps.usages;
-
- DAWN_INVALID_IF(
- (descriptor->usage | validUsage) != validUsage,
- "Usage (%s) is not supported, %s are (currently) the only accepted usage flags.",
- descriptor->usage, validUsage);
- } else {
- DAWN_INVALID_IF(descriptor->usage != wgpu::TextureUsage::RenderAttachment,
- "Usage (%s) is not %s, which is (currently) the only accepted usage. Other "
- "usage flags require enabling %s",
- descriptor->usage, wgpu::TextureUsage::RenderAttachment,
- wgpu::FeatureName::SurfaceCapabilities);
- }
-
- DAWN_INVALID_IF(descriptor->width == 0 || descriptor->height == 0,
- "Swap Chain size (width: %u, height: %u) is empty.", descriptor->width,
- descriptor->height);
-
- DAWN_INVALID_IF(
- descriptor->width > device->GetLimits().v1.maxTextureDimension2D ||
- descriptor->height > device->GetLimits().v1.maxTextureDimension2D,
- "Swap Chain size (width: %u, height: %u) is greater than the maximum 2D texture "
- "size (width: %u, height: %u).",
- descriptor->width, descriptor->height, device->GetLimits().v1.maxTextureDimension2D,
- device->GetLimits().v1.maxTextureDimension2D);
-
- return {};
-}
-
TextureDescriptor GetSwapChainBaseTextureDescriptor(SwapChainBase* swapChain) {
TextureDescriptor desc;
desc.usage = swapChain->GetUsage();
@@ -124,7 +57,7 @@
SwapChainBase::SwapChainBase(DeviceBase* device,
Surface* surface,
const SurfaceConfiguration* config)
- : ApiObjectBase(device, kLabelNotImplemented),
+ : mDevice(device),
mWidth(config->width),
mHeight(config->height),
mFormat(config->format),
@@ -132,7 +65,6 @@
mPresentMode(config->presentMode),
mAlphaMode(config->alphaMode),
mSurface(surface) {
- GetObjectTrackingList()->Track(this);
for (uint32_t i = 0; i < config->viewFormatCount; ++i) {
if (config->viewFormats[i] == config->format) {
// Skip our own format, like texture creations does.
@@ -158,29 +90,6 @@
DAWN_ASSERT(!mAttached);
}
-SwapChainBase::SwapChainBase(DeviceBase* device,
- const SurfaceConfiguration* config,
- ObjectBase::ErrorTag tag)
- : ApiObjectBase(device, tag),
- mWidth(config->width),
- mHeight(config->height),
- mFormat(config->format),
- mUsage(config->usage),
- mPresentMode(config->presentMode),
- mAlphaMode(config->alphaMode) {}
-
-// static
-Ref<SwapChainBase> SwapChainBase::MakeError(DeviceBase* device,
- const SurfaceConfiguration* config) {
- return AcquireRef(new ErrorSwapChain(device, config));
-}
-
-void SwapChainBase::DestroyImpl() {}
-
-ObjectType SwapChainBase::GetType() const {
- return ObjectType::SwapChain;
-}
-
void SwapChainBase::DetachFromSurface() {
if (mAttached) {
DetachFromSurfaceImpl();
@@ -193,38 +102,7 @@
mAttached = true;
}
-void SwapChainBase::APIConfigure(wgpu::TextureFormat format,
- wgpu::TextureUsage allowedUsage,
- uint32_t width,
- uint32_t height) {
- GetDevice()->HandleError(
- DAWN_VALIDATION_ERROR("Configure is invalid for surface-based swapchains."));
-}
-
-TextureBase* SwapChainBase::APIGetCurrentTexture() {
- SurfaceTexture result;
- if (GetDevice()->ConsumedError(GetCurrentTexture(), &result, "calling %s.GetCurrentTexture()",
- this)) {
- TextureDescriptor desc = GetSwapChainBaseTextureDescriptor(this);
- Ref<TextureBase> errorTexture = TextureBase::MakeError(GetDevice(), &desc);
- SetChildLabel(errorTexture.Get());
- result.texture = ReturnToAPI(std::move(errorTexture));
- }
- return result.texture;
-}
-
-TextureViewBase* SwapChainBase::APIGetCurrentTextureView() {
- Ref<TextureViewBase> result;
- if (GetDevice()->ConsumedError(GetCurrentTextureView(), &result,
- "calling %s.GetCurrentTextureView()", this)) {
- result = TextureViewBase::MakeError(GetDevice());
- SetChildLabel(result.Get());
- }
- return ReturnToAPI(std::move(result));
-}
-
ResultOrError<SurfaceTexture> SwapChainBase::GetCurrentTexture() {
- DAWN_TRY(ValidateGetCurrentTexture());
SurfaceTexture surfaceTexture;
if (mCurrentTextureInfo.texture == nullptr) {
@@ -249,25 +127,18 @@
return surfaceTexture;
}
-ResultOrError<Ref<TextureViewBase>> SwapChainBase::GetCurrentTextureView() {
- SurfaceTexture surfaceTexture;
- DAWN_TRY_ASSIGN(surfaceTexture, GetCurrentTexture());
- return surfaceTexture.texture->CreateView();
-}
-
-void SwapChainBase::APIPresent() {
- if (GetDevice()->ConsumedError(ValidatePresent())) {
- return;
- }
-
- if (GetDevice()->ConsumedError(PresentImpl())) {
- return;
- }
+MaybeError SwapChainBase::Present() {
+ DAWN_TRY(ValidatePresent());
+ DAWN_TRY(PresentImpl());
DAWN_ASSERT(mCurrentTextureInfo.texture->IsDestroyed());
mCurrentTextureInfo.texture = nullptr;
+ return {};
}
+DeviceBase* SwapChainBase::GetDevice() const {
+ return mDevice.Get();
+}
uint32_t SwapChainBase::GetWidth() const {
return mWidth;
}
@@ -310,28 +181,24 @@
MaybeError SwapChainBase::ValidatePresent() const {
DAWN_TRY(GetDevice()->ValidateIsAlive());
- DAWN_TRY(GetDevice()->ValidateObject(this));
-
- DAWN_INVALID_IF(!mAttached, "Cannot call Present called on detached %s.", this);
+ DAWN_ASSERT(mAttached);
DAWN_INVALID_IF(mCurrentTextureInfo.texture == nullptr,
"GetCurrentTexture was not called on %s this frame prior to calling Present.",
- this);
+ this->GetSurface());
return {};
}
MaybeError SwapChainBase::ValidateGetCurrentTexture() const {
DAWN_TRY(GetDevice()->ValidateIsAlive());
- DAWN_TRY(GetDevice()->ValidateObject(this));
-
- DAWN_INVALID_IF(!mAttached, "Cannot call GetCurrentTexture on detached %s.", this);
+ DAWN_ASSERT(mAttached);
return {};
}
void SwapChainBase::SetChildLabel(ApiObjectBase* child) const {
- child->SetLabel(absl::StrFormat("of %s", this));
+ child->SetLabel(absl::StrFormat("of %s", this->GetSurface()));
}
} // namespace dawn::native
diff --git a/src/dawn/native/SwapChain.h b/src/dawn/native/SwapChain.h
index 86460d1..c53fe12 100644
--- a/src/dawn/native/SwapChain.h
+++ b/src/dawn/native/SwapChain.h
@@ -39,12 +39,6 @@
namespace dawn::native {
-// TODO(dawn:2320): Remove the SwapChainDescriptor once the deprecation period is finished and
-// APICreateSwapChain gets dropped
-MaybeError ValidateSwapChainDescriptor(const DeviceBase* device,
- const Surface* surface,
- const SwapChainDescriptor* descriptor);
-
TextureDescriptor GetSwapChainBaseTextureDescriptor(SwapChainBase* swapChain);
struct SwapChainTextureInfo {
@@ -53,13 +47,10 @@
wgpu::SurfaceGetCurrentTextureStatus status;
};
-class SwapChainBase : public ApiObjectBase {
+class SwapChainBase : public RefCounted {
public:
SwapChainBase(DeviceBase* device, Surface* surface, const SurfaceConfiguration* config);
- static Ref<SwapChainBase> MakeError(DeviceBase* device, const SurfaceConfiguration* config);
- ObjectType GetType() const override;
-
// This is called when the swapchain is detached when one of the following happens:
//
// - The surface it is attached to is being destroyed.
@@ -79,15 +70,6 @@
void SetIsAttached();
- // Dawn API
- void APIConfigure(wgpu::TextureFormat format,
- wgpu::TextureUsage allowedUsage,
- uint32_t width,
- uint32_t height);
- TextureBase* APIGetCurrentTexture();
- TextureViewBase* APIGetCurrentTextureView();
- void APIPresent();
-
// TODO(crbug.com/dawn/831):
// APIRelease() can be called without any synchronization guarantees so we need to use a Release
// method that will call LockAndDeleteThis() on destruction.
@@ -96,6 +78,7 @@
// yet.
void APIRelease() { ReleaseAndLockBeforeDestroy(); }
+ DeviceBase* GetDevice() const;
uint32_t GetWidth() const;
uint32_t GetHeight() const;
wgpu::TextureFormat GetFormat() const;
@@ -109,11 +92,10 @@
// The returned texture must match the swapchain descriptor exactly.
ResultOrError<SurfaceTexture> GetCurrentTexture();
+ MaybeError Present();
protected:
- SwapChainBase(DeviceBase* device, const SurfaceConfiguration* config, ObjectBase::ErrorTag tag);
~SwapChainBase() override;
- void DestroyImpl() override;
private:
void SetChildLabel(ApiObjectBase* child) const;
@@ -121,6 +103,8 @@
// current texture)
FormatSet ComputeViewFormatSet() const;
+ Ref<DeviceBase> mDevice;
+
bool mAttached = false;
uint32_t mWidth;
uint32_t mHeight;
@@ -142,11 +126,8 @@
// GetCurrentTextureImpl and PresentImpl are guaranteed to be called in an interleaved manner,
// starting with GetCurrentTextureImpl.
-
virtual ResultOrError<SwapChainTextureInfo> GetCurrentTextureImpl() = 0;
- ResultOrError<Ref<TextureViewBase>> GetCurrentTextureView();
-
// The call to present must destroy the current texture so further access to it are invalid.
virtual MaybeError PresentImpl() = 0;
diff --git a/src/dawn/native/d3d/SwapChainD3D.cpp b/src/dawn/native/d3d/SwapChainD3D.cpp
index 168bb73..e5a436b 100644
--- a/src/dawn/native/d3d/SwapChainD3D.cpp
+++ b/src/dawn/native/d3d/SwapChainD3D.cpp
@@ -103,11 +103,6 @@
SwapChain::~SwapChain() = default;
-void SwapChain::DestroyImpl() {
- SwapChainBase::DestroyImpl();
- DetachFromSurface();
-}
-
// Initializes the swapchain on the surface. Note that `previousSwapChain` may or may not be
// nullptr. If it is not nullptr it means that it is the swapchain previously in use on the
// surface and that we have a chance to reuse it's underlying IDXGISwapChain and "buffers".
diff --git a/src/dawn/native/d3d/SwapChainD3D.h b/src/dawn/native/d3d/SwapChainD3D.h
index a4d078c..57ede12 100644
--- a/src/dawn/native/d3d/SwapChainD3D.h
+++ b/src/dawn/native/d3d/SwapChainD3D.h
@@ -50,8 +50,6 @@
using SwapChainBase::SwapChainBase;
~SwapChain() override;
- void DestroyImpl() override;
-
MaybeError Initialize(SwapChainBase* previousSwapChain);
virtual IUnknown* GetD3DDeviceForCreatingSwapChain() = 0;
diff --git a/src/dawn/native/metal/SwapChainMTL.h b/src/dawn/native/metal/SwapChainMTL.h
index 7786310..e23c3df 100644
--- a/src/dawn/native/metal/SwapChainMTL.h
+++ b/src/dawn/native/metal/SwapChainMTL.h
@@ -51,8 +51,6 @@
~SwapChain() override;
private:
- void DestroyImpl() override;
-
using SwapChainBase::SwapChainBase;
MaybeError Initialize(SwapChainBase* previousSwapChain);
diff --git a/src/dawn/native/metal/SwapChainMTL.mm b/src/dawn/native/metal/SwapChainMTL.mm
index 478f726..349949a 100644
--- a/src/dawn/native/metal/SwapChainMTL.mm
+++ b/src/dawn/native/metal/SwapChainMTL.mm
@@ -51,11 +51,6 @@
SwapChain::~SwapChain() = default;
-void SwapChain::DestroyImpl() {
- SwapChainBase::DestroyImpl();
- DetachFromSurface();
-}
-
MaybeError SwapChain::Initialize(SwapChainBase* previousSwapChain) {
DAWN_ASSERT(GetSurface()->GetType() == Surface::Type::MetalLayer);
diff --git a/src/dawn/native/opengl/SwapChainEGL.cpp b/src/dawn/native/opengl/SwapChainEGL.cpp
index 42d9488..887e872 100644
--- a/src/dawn/native/opengl/SwapChainEGL.cpp
+++ b/src/dawn/native/opengl/SwapChainEGL.cpp
@@ -54,11 +54,6 @@
SwapChainEGL::~SwapChainEGL() = default;
-void SwapChainEGL::DestroyImpl() {
- SwapChainBase::DestroyImpl();
- DetachFromSurface();
-}
-
MaybeError SwapChainEGL::Initialize(SwapChainBase* previousSwapChain) {
const Device* device = ToBackend(GetDevice());
diff --git a/src/dawn/native/opengl/SwapChainEGL.h b/src/dawn/native/opengl/SwapChainEGL.h
index bcb36aa..cc230f9 100644
--- a/src/dawn/native/opengl/SwapChainEGL.h
+++ b/src/dawn/native/opengl/SwapChainEGL.h
@@ -49,8 +49,6 @@
~SwapChainEGL() override;
private:
- void DestroyImpl() override;
-
using SwapChainBase::SwapChainBase;
MaybeError Initialize(SwapChainBase* previousSwapChain);
diff --git a/src/dawn/native/vulkan/SwapChainVk.cpp b/src/dawn/native/vulkan/SwapChainVk.cpp
index 5e52789..a0d407a 100644
--- a/src/dawn/native/vulkan/SwapChainVk.cpp
+++ b/src/dawn/native/vulkan/SwapChainVk.cpp
@@ -120,11 +120,6 @@
SwapChain::~SwapChain() = default;
-void SwapChain::DestroyImpl() {
- SwapChainBase::DestroyImpl();
- DetachFromSurface();
-}
-
// Note that when we need to re-create the swapchain because it is out of date,
// previousSwapChain can be set to `this`.
MaybeError SwapChain::Initialize(SwapChainBase* previousSwapChain) {
diff --git a/src/dawn/native/vulkan/SwapChainVk.h b/src/dawn/native/vulkan/SwapChainVk.h
index eda9886..4185633 100644
--- a/src/dawn/native/vulkan/SwapChainVk.h
+++ b/src/dawn/native/vulkan/SwapChainVk.h
@@ -55,7 +55,6 @@
private:
using SwapChainBase::SwapChainBase;
MaybeError Initialize(SwapChainBase* previousSwapChain);
- void DestroyImpl() override;
struct Config {
// Information that's passed to vulkan swapchain creation.
diff --git a/src/dawn/tests/BUILD.gn b/src/dawn/tests/BUILD.gn
index b5442c8..95566b5 100644
--- a/src/dawn/tests/BUILD.gn
+++ b/src/dawn/tests/BUILD.gn
@@ -274,8 +274,6 @@
"unittests/native/mocks/SamplerMock.h",
"unittests/native/mocks/ShaderModuleMock.cpp",
"unittests/native/mocks/ShaderModuleMock.h",
- "unittests/native/mocks/SwapChainMock.cpp",
- "unittests/native/mocks/SwapChainMock.h",
"unittests/native/mocks/TextureMock.cpp",
"unittests/native/mocks/TextureMock.h",
]
@@ -443,7 +441,6 @@
"unittests/wire/WireInjectBufferTests.cpp",
"unittests/wire/WireInjectInstanceTests.cpp",
"unittests/wire/WireInjectSurfaceTests.cpp",
- "unittests/wire/WireInjectSwapChainTests.cpp",
"unittests/wire/WireInjectTextureTests.cpp",
"unittests/wire/WireInstanceTests.cpp",
"unittests/wire/WireMemoryTransferServiceTests.cpp",
@@ -722,8 +719,6 @@
sources += [
"end2end/SurfaceConfigurationValidationTests.cpp",
"end2end/SurfaceTests.cpp",
- "end2end/SwapChainTests.cpp",
- "end2end/SwapChainValidationTests.cpp",
"end2end/WindowSurfaceTests.cpp",
]
}
diff --git a/src/dawn/tests/end2end/SwapChainTests.cpp b/src/dawn/tests/end2end/SwapChainTests.cpp
deleted file mode 100644
index ad626ee..0000000
--- a/src/dawn/tests/end2end/SwapChainTests.cpp
+++ /dev/null
@@ -1,495 +0,0 @@
-// Copyright 2020 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <memory>
-#include <vector>
-
-#include "dawn/common/Constants.h"
-#include "dawn/common/Log.h"
-#include "dawn/tests/DawnTest.h"
-#include "dawn/utils/ComboRenderPipelineDescriptor.h"
-#include "dawn/utils/WGPUHelpers.h"
-#include "webgpu/webgpu_glfw.h"
-
-#include "GLFW/glfw3.h"
-
-namespace dawn {
-namespace {
-
-struct GLFWindowDestroyer {
- void operator()(GLFWwindow* ptr) { glfwDestroyWindow(ptr); }
-};
-
-class SwapChainTests : public DawnTest {
- public:
- void SetUp() override {
- DawnTest::SetUp();
- DAWN_TEST_UNSUPPORTED_IF(UsesWire());
-
- // TODO(crbug.com/dawn/2492): Crashing on Ubuntu 22 (Mesa 23.2.1) + Intel UHD 630. Crash
- // happens in SetUp code, so we cannot skip individual tests.
- DAWN_TEST_UNSUPPORTED_IF(IsLinux() && IsIntel() && IsVulkan() && IsMesa("23.2.1"));
-
- glfwSetErrorCallback([](int code, const char* message) {
- ErrorLog() << "GLFW error " << code << " " << message;
- });
-
- // GLFW can fail to start in headless environments, in which SwapChainTests are
- // inapplicable. Skip this cases without producing a test failure.
- if (glfwInit() == GLFW_FALSE) {
- GTEST_SKIP();
- }
-
- // Set GLFW_NO_API to avoid GLFW bringing up a GL context that we won't use.
- glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
- window.reset(
- glfwCreateWindow(400, 400, "SwapChainValidationTests window", nullptr, nullptr));
-
- int width;
- int height;
- glfwGetFramebufferSize(window.get(), &width, &height);
-
- surface = wgpu::glfw::CreateSurfaceForWindow(GetInstance(), window.get());
- ASSERT_NE(surface, nullptr);
-
- baseDescriptor.width = width;
- baseDescriptor.height = height;
- baseDescriptor.usage = wgpu::TextureUsage::RenderAttachment;
- baseDescriptor.format = wgpu::TextureFormat::BGRA8Unorm;
- baseDescriptor.presentMode = wgpu::PresentMode::Mailbox;
- }
-
- void TearDown() override {
- // Destroy the surface before the window as required by webgpu-native.
- surface = wgpu::Surface();
- window.reset();
- DawnTest::TearDown();
- }
-
- wgpu::SwapChain CreateSwapChain(wgpu::Surface const& otherSurface,
- wgpu::SwapChainDescriptor const* descriptor) {
- wgpu::SwapChain swapchain;
- EXPECT_DEPRECATION_WARNING(swapchain = device.CreateSwapChain(otherSurface, descriptor));
- return swapchain;
- }
-
- void ClearTexture(wgpu::Texture texture, wgpu::Color color) {
- utils::ComboRenderPassDescriptor desc({texture.CreateView()});
- desc.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
- desc.cColorAttachments[0].clearValue = color;
-
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&desc);
- pass.End();
-
- wgpu::CommandBuffer commands = encoder.Finish();
- queue.Submit(1, &commands);
- }
-
- protected:
- std::unique_ptr<GLFWwindow, GLFWindowDestroyer> window = nullptr;
- wgpu::Surface surface;
-
- wgpu::SwapChainDescriptor baseDescriptor;
-};
-
-// Basic test for creating a swapchain and presenting one frame.
-TEST_P(SwapChainTests, Basic) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &baseDescriptor);
- ClearTexture(swapchain.GetCurrentTexture(), {1.0, 0.0, 0.0, 1.0});
- swapchain.Present();
-}
-
-// Test replacing the swapchain
-TEST_P(SwapChainTests, ReplaceBasic) {
- wgpu::SwapChain swapchain1 = CreateSwapChain(surface, &baseDescriptor);
- ClearTexture(swapchain1.GetCurrentTexture(), {1.0, 0.0, 0.0, 1.0});
- swapchain1.Present();
-
- wgpu::SwapChain swapchain2 = CreateSwapChain(surface, &baseDescriptor);
- ClearTexture(swapchain2.GetCurrentTexture(), {0.0, 1.0, 0.0, 1.0});
- swapchain2.Present();
-}
-
-// Test replacing the swapchain after GetCurrentTexture
-TEST_P(SwapChainTests, ReplaceAfterGet) {
- wgpu::SwapChain swapchain1 = CreateSwapChain(surface, &baseDescriptor);
- ClearTexture(swapchain1.GetCurrentTexture(), {1.0, 0.0, 0.0, 1.0});
-
- wgpu::SwapChain swapchain2 = CreateSwapChain(surface, &baseDescriptor);
- ClearTexture(swapchain2.GetCurrentTexture(), {0.0, 1.0, 0.0, 1.0});
- swapchain2.Present();
-}
-
-// Test destroying the swapchain after GetCurrentTexture
-TEST_P(SwapChainTests, DestroyAfterGet) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &baseDescriptor);
- ClearTexture(swapchain.GetCurrentTexture(), {1.0, 0.0, 0.0, 1.0});
-}
-
-// Test destroying the surface before the swapchain
-TEST_P(SwapChainTests, DestroySurface) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &baseDescriptor);
- surface = nullptr;
-}
-
-// Test destroying the surface before the swapchain but after GetCurrentTexture
-TEST_P(SwapChainTests, DestroySurfaceAfterGet) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &baseDescriptor);
- ClearTexture(swapchain.GetCurrentTexture(), {1.0, 0.0, 0.0, 1.0});
- surface = nullptr;
-}
-
-// Test switching between present modes.
-TEST_P(SwapChainTests, SwitchPresentMode) {
- // Fails with "internal drawable creation failed" on the Windows NVIDIA CQ builders but not
- // locally.
- DAWN_SUPPRESS_TEST_IF(IsWindows() && IsVulkan() && IsNvidia());
-
- // TODO(jiawei.shao@intel.com): find out why this test sometimes hangs on the latest Linux Intel
- // Vulkan drivers.
- DAWN_SUPPRESS_TEST_IF(IsLinux() && IsVulkan() && IsIntel());
-
- constexpr wgpu::PresentMode kAllPresentModes[] = {
- wgpu::PresentMode::Immediate,
- wgpu::PresentMode::Fifo,
- wgpu::PresentMode::Mailbox,
- };
-
- for (wgpu::PresentMode mode1 : kAllPresentModes) {
- for (wgpu::PresentMode mode2 : kAllPresentModes) {
- wgpu::SwapChainDescriptor desc = baseDescriptor;
-
- desc.presentMode = mode1;
- wgpu::SwapChain swapchain1 = CreateSwapChain(surface, &desc);
- ClearTexture(swapchain1.GetCurrentTexture(), {0.0, 0.0, 0.0, 1.0});
- swapchain1.Present();
-
- desc.presentMode = mode2;
- wgpu::SwapChain swapchain2 = CreateSwapChain(surface, &desc);
- ClearTexture(swapchain2.GetCurrentTexture(), {0.0, 0.0, 0.0, 1.0});
- swapchain2.Present();
- }
- }
-}
-
-// Test resizing the swapchain and without resizing the window.
-TEST_P(SwapChainTests, ResizingSwapChainOnly) {
- for (int i = 0; i < 10; i++) {
- wgpu::SwapChainDescriptor desc = baseDescriptor;
- desc.width += i * 10;
- desc.height -= i * 10;
-
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &desc);
- ClearTexture(swapchain.GetCurrentTexture(), {0.05f * i, 0.0f, 0.0f, 1.0f});
- swapchain.Present();
- }
-}
-
-// Test resizing the window but not the swapchain.
-TEST_P(SwapChainTests, ResizingWindowOnly) {
- // TODO(crbug.com/1503912): Failing new ValidateImageAcquireWait in Vulkan Validation Layer.
- DAWN_SUPPRESS_TEST_IF(IsBackendValidationEnabled() && IsWindows() && IsVulkan() && IsIntel());
-
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &baseDescriptor);
-
- for (int i = 0; i < 10; i++) {
- glfwSetWindowSize(window.get(), 400 - 10 * i, 400 + 10 * i);
- glfwPollEvents();
-
- ClearTexture(swapchain.GetCurrentTexture(), {0.05f * i, 0.0f, 0.0f, 1.0f});
- swapchain.Present();
- }
-}
-
-// Test resizing both the window and the swapchain at the same time.
-TEST_P(SwapChainTests, ResizingWindowAndSwapChain) {
- // TODO(crbug.com/dawn/1205) Currently failing on new NVIDIA GTX 1660s on Linux/Vulkan.
- DAWN_SUPPRESS_TEST_IF(IsLinux() && IsVulkan() && IsNvidia());
- for (int i = 0; i < 10; i++) {
- glfwSetWindowSize(window.get(), 400 - 10 * i, 400 + 10 * i);
- glfwPollEvents();
-
- int width;
- int height;
- glfwGetFramebufferSize(window.get(), &width, &height);
-
- wgpu::SwapChainDescriptor desc = baseDescriptor;
- desc.width = width;
- desc.height = height;
-
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &desc);
- ClearTexture(swapchain.GetCurrentTexture(), {0.05f * i, 0.0f, 0.0f, 1.0f});
- swapchain.Present();
- }
-}
-
-// Test switching devices on the same adapter.
-TEST_P(SwapChainTests, SwitchingDevice) {
- // TODO(https://crbug.com/dawn/2116): Disabled due to new Validation Layer failures.
- DAWN_SUPPRESS_TEST_IF(IsVulkan());
-
- wgpu::Device device1 = CreateDevice();
- wgpu::Device device2 = CreateDevice();
-
- for (int i = 0; i < 3; i++) {
- wgpu::Device deviceToUse;
- if (i % 2 == 0) {
- deviceToUse = device1;
- } else {
- deviceToUse = device2;
- }
-
- wgpu::SwapChain swapchain;
- EXPECT_DEPRECATION_WARNING(swapchain =
- deviceToUse.CreateSwapChain(surface, &baseDescriptor));
- swapchain.GetCurrentTexture();
- swapchain.Present();
- }
-}
-
-// Test that calling Device.GetSupportedSurfaceUsage() will throw an error because
-// SurfaceCapabilities is not enabled.
-TEST_P(SwapChainTests, ErrorGetSurfaceSupportedUsage) {
- DAWN_TEST_UNSUPPORTED_IF(HasToggleEnabled("skip_validation"));
- EXPECT_FALSE(device.HasFeature(wgpu::FeatureName::SurfaceCapabilities));
-
- ASSERT_DEVICE_ERROR_MSG(
- {
- wgpu::TextureUsage usageFlags;
- EXPECT_DEPRECATION_WARNING(usageFlags = device.GetSupportedSurfaceUsage(surface));
- EXPECT_EQ(usageFlags, wgpu::TextureUsage::None);
- },
- testing::HasSubstr("FeatureName::SurfaceCapabilities is not enabled"));
-}
-
-// Test that creating swapchain with TextureBinding usage without enabling SurfaceCapabilities
-// feature should fail.
-TEST_P(SwapChainTests, ErrorCreateWithTextureBindingUsage) {
- DAWN_TEST_UNSUPPORTED_IF(HasToggleEnabled("skip_validation"));
- EXPECT_FALSE(device.HasFeature(wgpu::FeatureName::SurfaceCapabilities));
-
- auto desc = baseDescriptor;
- desc.usage = wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::RenderAttachment;
-
- ASSERT_DEVICE_ERROR_MSG(
- { auto swapchain = CreateSwapChain(surface, &desc); },
- testing::HasSubstr("require enabling FeatureName::SurfaceCapabilities"));
-}
-
-class SwapChainWithAdditionalUsageTests : public SwapChainTests {
- protected:
- std::vector<wgpu::FeatureName> GetRequiredFeatures() override {
- std::vector<wgpu::FeatureName> features;
- if (!UsesWire() && SupportsFeatures({wgpu::FeatureName::SurfaceCapabilities})) {
- features.push_back(wgpu::FeatureName::SurfaceCapabilities);
- }
- return features;
- }
-
- void SetUp() override {
- SwapChainTests::SetUp();
-
- // If parent class skipped the test, we should skip as well.
- if (surface == nullptr) {
- GTEST_SKIP();
- }
-
- DAWN_TEST_UNSUPPORTED_IF(!SupportsFeatures({wgpu::FeatureName::SurfaceCapabilities}));
- }
-
- void SampleTexture(wgpu::Texture texture, utils::RGBA8 expectedColor) {
- wgpu::TextureDescriptor texDescriptor;
- texDescriptor.size = {texture.GetWidth(), texture.GetHeight(), 1};
- texDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
- texDescriptor.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc |
- wgpu::TextureUsage::CopyDst;
- texDescriptor.mipLevelCount = 1;
- texDescriptor.sampleCount = 1;
-
- wgpu::Texture dstTexture = device.CreateTexture(&texDescriptor);
- wgpu::TextureView dstView = dstTexture.CreateView();
-
- // Create a render pipeline to blit |view| into |dstView|.
- utils::ComboRenderPipelineDescriptor pipelineDesc;
- pipelineDesc.vertex.module = utils::CreateShaderModule(device, R"(
- @vertex
- fn main(@builtin(vertex_index) VertexIndex : u32) -> @builtin(position) vec4f {
- var pos = array(
- vec2f(-1.0, -1.0),
- vec2f(-1.0, 1.0),
- vec2f( 1.0, -1.0),
- vec2f(-1.0, 1.0),
- vec2f( 1.0, -1.0),
- vec2f( 1.0, 1.0));
- return vec4f(pos[VertexIndex], 0.0, 1.0);
- }
- )");
- pipelineDesc.cFragment.module = utils::CreateShaderModule(device, R"(
- @group(0) @binding(0) var texture : texture_2d<f32>;
-
- @fragment
- fn main(@builtin(position) coord: vec4f) -> @location(0) vec4f {
- return textureLoad(texture, vec2i(coord.xy), 0);
- }
- )");
- pipelineDesc.cTargets[0].format = texDescriptor.format;
-
- // Submit a render pass to perform the blit from |view| to |dstView|.
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- {
- wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&pipelineDesc);
-
- wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
- {{0, texture.CreateView()}});
-
- utils::ComboRenderPassDescriptor renderPassInfo({dstView});
-
- wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassInfo);
- pass.SetPipeline(pipeline);
- pass.SetBindGroup(0, bindGroup);
- pass.Draw(6);
- pass.End();
- }
-
- wgpu::CommandBuffer commands = encoder.Finish();
- queue.Submit(1, &commands);
-
- EXPECT_TEXTURE_EQ(expectedColor, dstTexture, {0, 0});
- EXPECT_TEXTURE_EQ(expectedColor, dstTexture,
- {texture.GetWidth() - 1, texture.GetHeight() - 1});
- }
-
- void WriteTexture(wgpu::Texture texture, const utils::RGBA8& data) {
- wgpu::Extent3D writeSize = {1, 1, 1};
- wgpu::ImageCopyTexture dest = {};
- dest.texture = texture;
- wgpu::TextureDataLayout dataLayout = {};
- queue.WriteTexture(&dest, &data, sizeof(utils::RGBA8), &dataLayout, &writeSize);
- }
-};
-
-TEST_P(SwapChainWithAdditionalUsageTests, GetSurfaceSupportedUsage) {
- wgpu::TextureUsage usageFlags;
- EXPECT_DEPRECATION_WARNING(usageFlags = device.GetSupportedSurfaceUsage(surface));
- EXPECT_NE(usageFlags, wgpu::TextureUsage::None);
-}
-
-// Test that sampling from swapchain is supported.
-TEST_P(SwapChainWithAdditionalUsageTests, SamplingFromSwapChain) {
- wgpu::TextureUsage supportedUsages;
- EXPECT_DEPRECATION_WARNING(supportedUsages = device.GetSupportedSurfaceUsage(surface));
-
- // Skip all tests if readable surface doesn't support texture binding
- DAWN_TEST_UNSUPPORTED_IF(!(supportedUsages & wgpu::TextureUsage::TextureBinding));
-
- auto desc = baseDescriptor;
- desc.usage = wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::RenderAttachment;
-
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &desc);
- ClearTexture(swapchain.GetCurrentTexture(), {1.0, 0.0, 0.0, 1.0});
-
- SampleTexture(swapchain.GetCurrentTexture(), utils::RGBA8::kRed);
-
- swapchain.Present();
-}
-
-// Test that including unsupported usage flag will result in error.
-TEST_P(SwapChainWithAdditionalUsageTests, ErrorIncludeUnsupportedUsage) {
- DAWN_TEST_UNSUPPORTED_IF(HasToggleEnabled("skip_validation"));
-
- wgpu::TextureUsage supportedUsages;
- EXPECT_DEPRECATION_WARNING(supportedUsages = device.GetSupportedSurfaceUsage(surface));
-
- // Assuming StorageBinding is not supported.
- DAWN_TEST_UNSUPPORTED_IF(supportedUsages & wgpu::TextureUsage::StorageBinding);
-
- auto desc = baseDescriptor;
- desc.usage = supportedUsages | wgpu::TextureUsage::StorageBinding;
-
- ASSERT_DEVICE_ERROR_MSG(
- { auto swapchain = CreateSwapChain(surface, &desc); },
- testing::HasSubstr("is not supported"));
-}
-
-// Test copying to a swapchain texture when it is supported.
-TEST_P(SwapChainWithAdditionalUsageTests, CopyingToSwapChain) {
- wgpu::TextureUsage supportedUsages;
- EXPECT_DEPRECATION_WARNING(supportedUsages = device.GetSupportedSurfaceUsage(surface));
-
- // We need the swapchain to support copying to the texture and at least one readback method.
- DAWN_TEST_UNSUPPORTED_IF(!(supportedUsages & wgpu::TextureUsage::CopyDst));
- DAWN_TEST_UNSUPPORTED_IF(
- !(supportedUsages & (wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding)));
-
- wgpu::SwapChainDescriptor desc = baseDescriptor;
- desc.usage = supportedUsages & (wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
- wgpu::TextureUsage::TextureBinding);
- desc.width = 1;
- desc.height = 1;
-
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &desc);
- wgpu::Texture texture = swapchain.GetCurrentTexture();
- WriteTexture(texture, utils::RGBA8::kRed);
-
- if (supportedUsages & wgpu::TextureUsage::CopySrc) {
- EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, swapchain.GetCurrentTexture(), 0, 0);
- } else {
- // kBlue because the texture is actually BGRA
- SampleTexture(texture, utils::RGBA8::kBlue);
- }
-}
-
-// Test copying from a swapchain texture when it is supported.
-TEST_P(SwapChainWithAdditionalUsageTests, CopyingFromSwapChain) {
- wgpu::TextureUsage supportedUsages;
- EXPECT_DEPRECATION_WARNING(supportedUsages = device.GetSupportedSurfaceUsage(surface));
-
- // We need the swapchain to support copying from the texture
- DAWN_TEST_UNSUPPORTED_IF(!(supportedUsages & wgpu::TextureUsage::CopySrc));
-
- wgpu::SwapChainDescriptor desc = baseDescriptor;
- desc.usage |= wgpu::TextureUsage::CopySrc;
-
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &desc);
- wgpu::Texture texture = swapchain.GetCurrentTexture();
-
- ClearTexture(swapchain.GetCurrentTexture(), {1.0, 0.0, 0.0, 1.0});
- // kBlue because the texture is actually BGRA8
- EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kBlue, swapchain.GetCurrentTexture(), 0, 0);
-}
-
-DAWN_INSTANTIATE_TEST(SwapChainTests, MetalBackend(), VulkanBackend());
-DAWN_INSTANTIATE_TEST(SwapChainWithAdditionalUsageTests,
- D3D11Backend(),
- D3D12Backend(),
- MetalBackend(),
- NullBackend(),
- VulkanBackend());
-
-} // anonymous namespace
-} // namespace dawn
diff --git a/src/dawn/tests/end2end/SwapChainValidationTests.cpp b/src/dawn/tests/end2end/SwapChainValidationTests.cpp
deleted file mode 100644
index a902e25..0000000
--- a/src/dawn/tests/end2end/SwapChainValidationTests.cpp
+++ /dev/null
@@ -1,417 +0,0 @@
-// Copyright 2020 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <memory>
-
-#include "GLFW/glfw3.h"
-#include "dawn/common/Constants.h"
-#include "dawn/common/Log.h"
-#include "dawn/tests/DawnTest.h"
-#include "dawn/utils/ComboRenderPipelineDescriptor.h"
-#include "dawn/utils/WGPUHelpers.h"
-#include "webgpu/webgpu_glfw.h"
-
-namespace dawn {
-namespace {
-
-struct GLFWindowDestroyer {
- void operator()(GLFWwindow* ptr) { glfwDestroyWindow(ptr); }
-};
-
-class SwapChainValidationTests : public DawnTest {
- public:
- void SetUp() override {
- DawnTest::SetUp();
- DAWN_TEST_UNSUPPORTED_IF(UsesWire());
- DAWN_TEST_UNSUPPORTED_IF(HasToggleEnabled("skip_validation"));
-
- glfwSetErrorCallback([](int code, const char* message) {
- ErrorLog() << "GLFW error " << code << " " << message;
- });
- DAWN_TEST_UNSUPPORTED_IF(!glfwInit());
-
- // Set GLFW_NO_API to avoid GLFW bringing up a GL context that we won't use.
- glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
- window.reset(
- glfwCreateWindow(400, 400, "SwapChainValidationTests window", nullptr, nullptr));
-
- surface = wgpu::glfw::CreateSurfaceForWindow(GetInstance(), window.get());
- ASSERT_NE(surface, nullptr);
-
- goodDescriptor.width = 1;
- goodDescriptor.height = 1;
- goodDescriptor.usage = wgpu::TextureUsage::RenderAttachment;
- goodDescriptor.format = wgpu::TextureFormat::BGRA8Unorm;
- goodDescriptor.presentMode = wgpu::PresentMode::Mailbox;
-
- badDescriptor = goodDescriptor;
- badDescriptor.width = 0;
- }
-
- void TearDown() override {
- // Destroy the surface before the window as required by webgpu-native.
- surface = wgpu::Surface();
- window.reset();
- DawnTest::TearDown();
- }
-
- wgpu::SwapChain CreateSwapChain(wgpu::Surface const& otherSurface,
- wgpu::SwapChainDescriptor const* descriptor) {
- wgpu::SwapChain swapchain;
- EXPECT_DEPRECATION_WARNING(swapchain = device.CreateSwapChain(otherSurface, descriptor));
- return swapchain;
- }
-
- protected:
- std::unique_ptr<GLFWwindow, GLFWindowDestroyer> window = nullptr;
- wgpu::Surface surface;
- wgpu::SwapChainDescriptor goodDescriptor;
- wgpu::SwapChainDescriptor badDescriptor;
-
- // Checks that a RenderAttachment view is an error by trying to create a render pass on it.
- void CheckTextureIsError(wgpu::Texture texture) { CheckTexture(texture, true, false); }
-
- // Checks that a RenderAttachment view is an error by trying to submit a render pass on it.
- void CheckTextureIsDestroyed(wgpu::Texture texture) { CheckTexture(texture, false, true); }
-
- // Checks that a RenderAttachment view is valid by submitting a render pass on it.
- void CheckTextureIsValid(wgpu::Texture texture) { CheckTexture(texture, false, false); }
-
- private:
- void CheckTexture(wgpu::Texture texture, bool error, bool destroyed) {
- wgpu::TextureView view;
- if (error) {
- ASSERT_DEVICE_ERROR(view = texture.CreateView());
- } else {
- view = texture.CreateView();
- }
- utils::ComboRenderPassDescriptor renderPassDesc({view});
-
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
- pass.End();
-
- if (error) {
- ASSERT_DEVICE_ERROR(encoder.Finish());
- } else {
- wgpu::CommandBuffer commands = encoder.Finish();
-
- if (destroyed) {
- ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
- } else {
- queue.Submit(1, &commands);
- }
- }
- }
-};
-
-void CheckTextureMatchesDescriptor(const wgpu::Texture& tex,
- const wgpu::SwapChainDescriptor& desc) {
- EXPECT_EQ(desc.width, tex.GetWidth());
- EXPECT_EQ(desc.height, tex.GetHeight());
- EXPECT_EQ(desc.usage, tex.GetUsage());
- EXPECT_EQ(desc.format, tex.GetFormat());
- EXPECT_EQ(1u, tex.GetDepthOrArrayLayers());
- EXPECT_EQ(1u, tex.GetMipLevelCount());
- EXPECT_EQ(1u, tex.GetSampleCount());
- EXPECT_EQ(wgpu::TextureDimension::e2D, tex.GetDimension());
-}
-
-// Control case for a successful swapchain creation and presenting.
-TEST_P(SwapChainValidationTests, CreationSuccess) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &goodDescriptor);
- swapchain.GetCurrentTexture();
- swapchain.Present();
-}
-
-// Test that creating a swapchain with an invalid surface is an error.
-TEST_P(SwapChainValidationTests, InvalidSurface) {
- wgpu::SurfaceDescriptor surface_desc = {};
- wgpu::Surface surface = GetInstance().CreateSurface(&surface_desc);
-
- ASSERT_DEVICE_ERROR_MSG(CreateSwapChain(surface, &goodDescriptor),
- testing::HasSubstr("[Surface] is invalid"));
-}
-
-// Checks that the creation size must be a valid 2D texture size.
-TEST_P(SwapChainValidationTests, InvalidCreationSize) {
- wgpu::Limits supportedLimits = GetSupportedLimits().limits;
- // A width of 0 is invalid.
- {
- wgpu::SwapChainDescriptor desc = goodDescriptor;
- desc.width = 0;
- ASSERT_DEVICE_ERROR(CreateSwapChain(surface, &desc));
- }
- // A height of 0 is invalid.
- {
- wgpu::SwapChainDescriptor desc = goodDescriptor;
- desc.height = 0;
- ASSERT_DEVICE_ERROR(CreateSwapChain(surface, &desc));
- }
-
- // A width of maxTextureDimension2D is valid but maxTextureDimension2D + 1 isn't.
- {
- wgpu::SwapChainDescriptor desc = goodDescriptor;
- desc.width = supportedLimits.maxTextureDimension2D;
- CreateSwapChain(surface, &desc);
-
- desc.width = supportedLimits.maxTextureDimension2D + 1;
- ASSERT_DEVICE_ERROR(CreateSwapChain(surface, &desc));
- }
-
- // A height of maxTextureDimension2D is valid but maxTextureDimension2D + 1 isn't.
- {
- wgpu::SwapChainDescriptor desc = goodDescriptor;
- desc.height = supportedLimits.maxTextureDimension2D;
- CreateSwapChain(surface, &desc);
-
- desc.height = supportedLimits.maxTextureDimension2D + 1;
- ASSERT_DEVICE_ERROR(CreateSwapChain(surface, &desc));
- }
-}
-
-// Checks that the creation usage must be RenderAttachment
-TEST_P(SwapChainValidationTests, InvalidCreationUsage) {
- wgpu::SwapChainDescriptor desc = goodDescriptor;
- desc.usage = wgpu::TextureUsage::TextureBinding;
- ASSERT_DEVICE_ERROR(CreateSwapChain(surface, &desc));
-}
-
-// Checks that the creation format must (currently) be BGRA8Unorm
-TEST_P(SwapChainValidationTests, InvalidCreationFormat) {
- wgpu::SwapChainDescriptor desc = goodDescriptor;
- desc.format = wgpu::TextureFormat::RGBA8Unorm;
- ASSERT_DEVICE_ERROR(CreateSwapChain(surface, &desc));
-}
-
-// Check swapchain operations with an error swapchain are errors
-TEST_P(SwapChainValidationTests, OperationsOnErrorSwapChain) {
- wgpu::SwapChain swapchain;
- ASSERT_DEVICE_ERROR(swapchain = CreateSwapChain(surface, &badDescriptor));
-
- wgpu::Texture texture;
- ASSERT_DEVICE_ERROR(texture = swapchain.GetCurrentTexture());
- CheckTextureIsError(texture);
-
- ASSERT_DEVICE_ERROR(swapchain.Present());
-}
-
-// Check it is invalid to call present without getting a current texture.
-TEST_P(SwapChainValidationTests, PresentWithoutCurrentTexture) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &goodDescriptor);
-
- // Check it is invalid if we never called GetCurrentTexture
- ASSERT_DEVICE_ERROR(swapchain.Present());
-
- // Check it is invalid if we never called since the last present.
- swapchain.GetCurrentTexture();
- swapchain.Present();
- ASSERT_DEVICE_ERROR(swapchain.Present());
-}
-
-// Check that the current texture isn't destroyed when the ref to the swapchain is lost because the
-// swapchain is kept alive by the surface. Also check after we lose all refs to the surface, the
-// texture is destroyed.
-TEST_P(SwapChainValidationTests, TextureValidAfterSwapChainRefLost) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &goodDescriptor);
- wgpu::Texture texture = swapchain.GetCurrentTexture();
-
- swapchain = nullptr;
- CheckTextureIsValid(texture);
-
- surface = nullptr;
- CheckTextureIsDestroyed(texture);
-}
-
-// Check that the current texture is the destroyed state after present.
-TEST_P(SwapChainValidationTests, TextureDestroyedAfterPresent) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &goodDescriptor);
- wgpu::Texture texture = swapchain.GetCurrentTexture();
- swapchain.Present();
-
- CheckTextureIsDestroyed(texture);
-}
-
-// Check that returned texture is of the current format / usage / dimension / size / sample count
-TEST_P(SwapChainValidationTests, ReturnedTextureCharacteristics) {
- utils::ComboRenderPipelineDescriptor pipelineDesc;
- pipelineDesc.vertex.module = utils::CreateShaderModule(device, R"(
- @vertex fn main() -> @builtin(position) vec4f {
- return vec4f(0.0, 0.0, 0.0, 1.0);
- })");
- pipelineDesc.cFragment.module = utils::CreateShaderModule(device, R"(
- struct FragmentOut {
- @location(0) target0 : vec4f,
- @location(1) target1 : f32,
- }
- @fragment fn main() -> FragmentOut {
- var out : FragmentOut;
- out.target0 = vec4f(0.0, 1.0, 0.0, 1.0);
- out.target1 = 0.5;
- return out;
- })");
- // Validation will check that the sample count of the view matches this format.
- pipelineDesc.multisample.count = 1;
- pipelineDesc.cFragment.targetCount = 2;
- // Validation will check that the format of the view matches this format.
- pipelineDesc.cTargets[0].format = wgpu::TextureFormat::BGRA8Unorm;
- pipelineDesc.cTargets[1].format = wgpu::TextureFormat::R8Unorm;
- device.CreateRenderPipeline(&pipelineDesc);
-
- // Create a second texture to be used as render pass attachment. Validation will check that the
- // size of the view matches the size of this texture.
- wgpu::TextureDescriptor textureDesc;
- textureDesc.usage = wgpu::TextureUsage::RenderAttachment;
- textureDesc.dimension = wgpu::TextureDimension::e2D;
- textureDesc.size = {1, 1, 1};
- textureDesc.format = wgpu::TextureFormat::R8Unorm;
- textureDesc.sampleCount = 1;
- wgpu::Texture secondTexture = device.CreateTexture(&textureDesc);
-
- // Get the swapchain view and try to use it in the render pass to trigger all the validation.
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &goodDescriptor);
- wgpu::TextureView view = swapchain.GetCurrentTexture().CreateView();
-
- // Validation will also check the dimension of the view is 2D, and it's usage contains
- // RenderAttachment
- utils::ComboRenderPassDescriptor renderPassDesc({view, secondTexture.CreateView()});
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
- pass.End();
- wgpu::CommandBuffer commands = encoder.Finish();
-
- queue.Submit(1, &commands);
-
- // Check that view doesn't have an extra Sampled usage.
- wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
- device, {{0, wgpu::ShaderStage::Fragment, wgpu::TextureSampleType::Float}});
- ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, bgl, {{0, view}}));
-
- // Check that view doesn't have an extra Storage usage.
- bgl = utils::MakeBindGroupLayout(
- device, {{0, wgpu::ShaderStage::Fragment, wgpu::StorageTextureAccess::WriteOnly,
- wgpu::TextureFormat::R32Uint}});
- ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, bgl, {{0, view}}));
-}
-
-// Check the reflection of textures returned by GetCurrentTexture on valid swapchain.
-TEST_P(SwapChainValidationTests, ReflectionValidGetCurrentTexture) {
- // Check with the goodDescriptor.
- {
- wgpu::SwapChain swapChain = CreateSwapChain(surface, &goodDescriptor);
- CheckTextureMatchesDescriptor(swapChain.GetCurrentTexture(), goodDescriptor);
- }
- // Check with properties that can be changed while keeping a valid descriptor.
- {
- wgpu::SwapChainDescriptor otherDescriptor = goodDescriptor;
- otherDescriptor.width = 2;
- otherDescriptor.height = 7;
- wgpu::SwapChain swapChain = CreateSwapChain(surface, &goodDescriptor);
- CheckTextureMatchesDescriptor(swapChain.GetCurrentTexture(), goodDescriptor);
- }
-}
-
-// Check the reflection of textures returned by GetCurrentTexture on valid swapchain.
-TEST_P(SwapChainValidationTests, ReflectionErrorGetCurrentTexture) {
- wgpu::SwapChain swapChain;
- ASSERT_DEVICE_ERROR(swapChain = CreateSwapChain(surface, &badDescriptor));
- wgpu::Texture texture;
- ASSERT_DEVICE_ERROR(texture = swapChain.GetCurrentTexture());
- CheckTextureMatchesDescriptor(texture, badDescriptor);
-}
-
-// Check that failing to create a new swapchain doesn't replace the previous one.
-TEST_P(SwapChainValidationTests, ErrorSwapChainDoesntReplacePreviousOne) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &goodDescriptor);
- ASSERT_DEVICE_ERROR(CreateSwapChain(surface, &badDescriptor));
-
- swapchain.GetCurrentTexture();
- swapchain.Present();
-}
-
-// Check that after replacement, all swapchain operations are errors and the texture is destroyed.
-TEST_P(SwapChainValidationTests, ReplacedSwapChainIsInvalid) {
- {
- wgpu::SwapChain replacedSwapChain = CreateSwapChain(surface, &goodDescriptor);
- CreateSwapChain(surface, &goodDescriptor);
- ASSERT_DEVICE_ERROR(replacedSwapChain.GetCurrentTexture());
- }
-
- {
- wgpu::SwapChain replacedSwapChain = CreateSwapChain(surface, &goodDescriptor);
- wgpu::Texture texture = replacedSwapChain.GetCurrentTexture();
- CreateSwapChain(surface, &goodDescriptor);
-
- CheckTextureIsDestroyed(texture);
- ASSERT_DEVICE_ERROR(replacedSwapChain.Present());
- }
-}
-
-// Check that after surface destruction, all swapchain operations are errors and the texture is
-// destroyed. The test is split in two to reset the wgpu::Surface in the middle.
-TEST_P(SwapChainValidationTests, SwapChainIsInvalidAfterSurfaceDestruction_GetTexture) {
- wgpu::SwapChain replacedSwapChain = CreateSwapChain(surface, &goodDescriptor);
- surface = nullptr;
- ASSERT_DEVICE_ERROR(replacedSwapChain.GetCurrentTexture());
-}
-TEST_P(SwapChainValidationTests, SwapChainIsInvalidAfterSurfaceDestruction_AfterGetTexture) {
- wgpu::SwapChain replacedSwapChain = CreateSwapChain(surface, &goodDescriptor);
- wgpu::Texture texture = replacedSwapChain.GetCurrentTexture();
- surface = nullptr;
-
- CheckTextureIsDestroyed(texture);
- ASSERT_DEVICE_ERROR(replacedSwapChain.Present());
-}
-
-// Test that new swap chain present after device is lost
-TEST_P(SwapChainValidationTests, SwapChainPresentAfterDeviceLost) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &goodDescriptor);
- swapchain.GetCurrentTexture();
-
- LoseDeviceForTesting();
- swapchain.Present();
-}
-
-// Test that new swap chain get current texture fails after device is lost
-TEST_P(SwapChainValidationTests, SwapChainGetCurrentTextureFailsAfterDevLost) {
- wgpu::SwapChain swapchain = CreateSwapChain(surface, &goodDescriptor);
-
- LoseDeviceForTesting();
- EXPECT_TRUE(dawn::native::CheckIsErrorForTesting(swapchain.GetCurrentTexture().Get()));
-}
-
-// Test that creation of a new swapchain fails after device is lost
-TEST_P(SwapChainValidationTests, CreateSwapChainFailsAfterDevLost) {
- LoseDeviceForTesting();
- EXPECT_TRUE(
- dawn::native::CheckIsErrorForTesting(CreateSwapChain(surface, &goodDescriptor).Get()));
-}
-
-DAWN_INSTANTIATE_TEST(SwapChainValidationTests, MetalBackend(), NullBackend());
-
-} // anonymous namespace
-} // namespace dawn
diff --git a/src/dawn/tests/unittests/native/DestroyObjectTests.cpp b/src/dawn/tests/unittests/native/DestroyObjectTests.cpp
index 06fffec..78e400f 100644
--- a/src/dawn/tests/unittests/native/DestroyObjectTests.cpp
+++ b/src/dawn/tests/unittests/native/DestroyObjectTests.cpp
@@ -51,7 +51,6 @@
#include "mocks/RenderPipelineMock.h"
#include "mocks/SamplerMock.h"
#include "mocks/ShaderModuleMock.h"
-#include "mocks/SwapChainMock.h"
#include "mocks/TextureMock.h"
#include "partition_alloc/pointers/raw_ptr.h"
diff --git a/src/dawn/tests/unittests/native/mocks/SwapChainMock.cpp b/src/dawn/tests/unittests/native/mocks/SwapChainMock.cpp
deleted file mode 100644
index 6a459cc..0000000
--- a/src/dawn/tests/unittests/native/mocks/SwapChainMock.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2022 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "dawn/tests/unittests/native/mocks/SwapChainMock.h"
-
-namespace dawn::native {
-
-SwapChainMock::SwapChainMock(DeviceBase* device,
- Surface* surface,
- const SurfaceConfiguration* config)
- : SwapChainBase(device, surface, config) {
- ON_CALL(*this, DestroyImpl).WillByDefault([this] { this->SwapChainBase::DestroyImpl(); });
-}
-
-SwapChainMock::~SwapChainMock() = default;
-
-} // namespace dawn::native
diff --git a/src/dawn/tests/unittests/native/mocks/SwapChainMock.h b/src/dawn/tests/unittests/native/mocks/SwapChainMock.h
deleted file mode 100644
index 4a0ed0c..0000000
--- a/src/dawn/tests/unittests/native/mocks/SwapChainMock.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_DAWN_TESTS_UNITTESTS_NATIVE_MOCKS_SWAPCHAINMOCK_H_
-#define SRC_DAWN_TESTS_UNITTESTS_NATIVE_MOCKS_SWAPCHAINMOCK_H_
-
-#include "gmock/gmock.h"
-
-#include "dawn/native/Device.h"
-#include "dawn/native/SwapChain.h"
-
-namespace dawn::native {
-
-class SwapChainMock : public SwapChainBase {
- public:
- SwapChainMock(DeviceBase* device, Surface* surface, const SurfaceConfiguration* config);
- ~SwapChainMock() override;
-
- MOCK_METHOD(void, DestroyImpl, (), (override));
-
- MOCK_METHOD(ResultOrError<SwapChainTextureInfo>, GetCurrentTextureImpl, (), (override));
- MOCK_METHOD(MaybeError, PresentImpl, (), (override));
- MOCK_METHOD(void, DetachFromSurfaceImpl, (), (override));
-};
-
-} // namespace dawn::native
-
-#endif // SRC_DAWN_TESTS_UNITTESTS_NATIVE_MOCKS_SWAPCHAINMOCK_H_
diff --git a/src/dawn/tests/unittests/wire/WireInjectSwapChainTests.cpp b/src/dawn/tests/unittests/wire/WireInjectSwapChainTests.cpp
deleted file mode 100644
index e64b4c6..0000000
--- a/src/dawn/tests/unittests/wire/WireInjectSwapChainTests.cpp
+++ /dev/null
@@ -1,174 +0,0 @@
-// Copyright 2021 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <utility>
-
-#include "dawn/tests/unittests/wire/WireTest.h"
-#include "dawn/wire/WireClient.h"
-#include "dawn/wire/WireServer.h"
-
-namespace dawn::wire {
-namespace {
-
-using testing::Mock;
-using testing::Return;
-
-class WireInjectSwapChainTests : public WireTest {
- public:
- WireInjectSwapChainTests() {
- swapChainDesc.usage = wgpu::TextureUsage::RenderAttachment;
- swapChainDesc.format = wgpu::TextureFormat::RGBA8Unorm;
- swapChainDesc.width = 17;
- swapChainDesc.height = 42;
- swapChainDesc.presentMode = wgpu::PresentMode::Mailbox;
- }
- ~WireInjectSwapChainTests() override = default;
-
- std::pair<ReservedSwapChain, wgpu::SwapChain> ReserveSwapChain(
- const wgpu::SwapChainDescriptor* desc = nullptr) {
- if (desc == nullptr) {
- desc = &swapChainDesc;
- }
-
- auto reservation = GetWireClient()->ReserveSwapChain(
- device.Get(), reinterpret_cast<const WGPUSwapChainDescriptor*>(desc));
- return {reservation, wgpu::SwapChain::Acquire(reservation.swapchain)};
- }
-
- wgpu::SwapChainDescriptor swapChainDesc;
-};
-
-// Test that reserving and injecting a swapchain makes calls on the client object forward to the
-// server object correctly.
-TEST_F(WireInjectSwapChainTests, CallAfterReserveInject) {
- auto [reservation, swapchain] = ReserveSwapChain();
-
- WGPUSwapChain apiSwapchain = api.GetNewSwapChain();
- EXPECT_CALL(api, SwapChainAddRef(apiSwapchain));
- ASSERT_TRUE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
- reservation.deviceHandle));
-
- swapchain.Present();
- EXPECT_CALL(api, SwapChainPresent(apiSwapchain));
- FlushClient();
-}
-
-// Test that reserve correctly returns different IDs each time.
-TEST_F(WireInjectSwapChainTests, ReserveDifferentIDs) {
- auto [reservation1, swapchain1] = ReserveSwapChain();
- auto [reservation2, swapchain2] = ReserveSwapChain();
-
- ASSERT_NE(reservation1.handle.id, reservation2.handle.id);
- ASSERT_NE(swapchain1.Get(), swapchain2.Get());
-}
-
-// Test that injecting the same id without a destroy first fails.
-TEST_F(WireInjectSwapChainTests, InjectExistingID) {
- auto [reservation, swapchain] = ReserveSwapChain();
-
- WGPUSwapChain apiSwapchain = api.GetNewSwapChain();
- EXPECT_CALL(api, SwapChainAddRef(apiSwapchain));
- ASSERT_TRUE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
- reservation.deviceHandle));
-
- // ID already in use, call fails.
- ASSERT_FALSE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
- reservation.deviceHandle));
-}
-
-// Test that the server only borrows the swapchain and does a single addref-release
-TEST_F(WireInjectSwapChainTests, InjectedSwapChainLifetime) {
- auto [reservation, swapchain] = ReserveSwapChain();
-
- // Injecting the swapchain adds a reference
- WGPUSwapChain apiSwapchain = api.GetNewSwapChain();
- EXPECT_CALL(api, SwapChainAddRef(apiSwapchain));
- ASSERT_TRUE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
- reservation.deviceHandle));
-
- // Releasing the swapchain removes a single reference.
- swapchain = nullptr;
- EXPECT_CALL(api, SwapChainRelease(apiSwapchain));
- FlushClient();
-
- // Deleting the server doesn't release a second reference.
- DeleteServer();
- Mock::VerifyAndClearExpectations(&api);
-}
-
-// Test that a swapchain reservation can be reclaimed. This is necessary to
-// avoid leaking ObjectIDs for reservations that are never injected.
-TEST_F(WireInjectSwapChainTests, ReclaimSwapChainReservation) {
- // Test that doing a reservation and full release is an error.
- {
- auto [reservation, swapchain] = ReserveSwapChain();
- swapchain = nullptr;
- FlushClient(false);
- }
-
- // Test that doing a reservation and then reclaiming it recycles the ID.
- {
- auto [reservation1, swapchain1] = ReserveSwapChain();
- GetWireClient()->ReclaimSwapChainReservation(reservation1);
-
- auto [reservation2, swapchain2] = ReserveSwapChain();
-
- // The ID is the same, but the generation is still different.
- ASSERT_EQ(reservation1.handle.id, reservation2.handle.id);
- ASSERT_NE(reservation1.handle.generation, reservation2.handle.generation);
-
- // No errors should occur.
- FlushClient();
- }
-}
-
-// Test that the texture's reflection is correct for injected swapchains in the wire.
-TEST_F(WireInjectSwapChainTests, SwapChainTextureReflection) {
- auto [reservation, swapchain] = ReserveSwapChain();
-
- WGPUSwapChain apiSwapchain = api.GetNewSwapChain();
- EXPECT_CALL(api, SwapChainAddRef(apiSwapchain));
- ASSERT_TRUE(GetWireServer()->InjectSwapChain(apiSwapchain, reservation.handle,
- reservation.deviceHandle));
-
- wgpu::Texture tex = swapchain.GetCurrentTexture();
- WGPUTexture apiTex = api.GetNewTexture();
- EXPECT_CALL(api, SwapChainGetCurrentTexture(apiSwapchain)).WillOnce(Return(apiTex));
- FlushClient();
-
- EXPECT_EQ(swapChainDesc.width, tex.GetWidth());
- EXPECT_EQ(swapChainDesc.height, tex.GetHeight());
- EXPECT_EQ(swapChainDesc.usage, tex.GetUsage());
- EXPECT_EQ(swapChainDesc.format, tex.GetFormat());
- EXPECT_EQ(1u, tex.GetDepthOrArrayLayers());
- EXPECT_EQ(1u, tex.GetMipLevelCount());
- EXPECT_EQ(1u, tex.GetSampleCount());
- EXPECT_EQ(wgpu::TextureDimension::e2D, tex.GetDimension());
-}
-
-} // anonymous namespace
-} // namespace dawn::wire
diff --git a/src/dawn/utils/WireHelper.cpp b/src/dawn/utils/WireHelper.cpp
index 63f96d7..41147ce 100644
--- a/src/dawn/utils/WireHelper.cpp
+++ b/src/dawn/utils/WireHelper.cpp
@@ -92,9 +92,7 @@
class WireHelperDirect : public WireHelper {
public:
- explicit WireHelperDirect(const DawnProcTable& procs) : mProcs(procs) {
- dawnProcSetProcs(&procs);
- }
+ explicit WireHelperDirect(const DawnProcTable& procs) { dawnProcSetProcs(&procs); }
wgpu::Instance RegisterInstance(WGPUInstance backendInstance,
const WGPUInstanceDescriptor* wireDesc) override {
@@ -102,16 +100,6 @@
return wgpu::Instance(backendInstance);
}
- wgpu::SwapChain CreateSwapChain(WGPUSurface backendSurface,
- WGPUDevice backendDevice,
- WGPUDevice apiDevice,
- const WGPUSwapChainDescriptor* descriptor) override {
- DAWN_ASSERT(backendDevice == apiDevice);
- WGPUSwapChain cSwapChain =
- mProcs.deviceCreateSwapChain(backendDevice, backendSurface, descriptor);
- return wgpu::SwapChain::Acquire(cSwapChain);
- }
-
void BeginWireTrace(const char* name) override {}
bool FlushClient() override { return true; }
@@ -119,15 +107,11 @@
bool FlushServer() override { return true; }
bool IsIdle() override { return true; }
-
- private:
- const DawnProcTable& mProcs;
};
class WireHelperProxy : public WireHelper {
public:
- explicit WireHelperProxy(const char* wireTraceDir, const DawnProcTable& procs)
- : mBackendProcs(procs) {
+ explicit WireHelperProxy(const char* wireTraceDir, const DawnProcTable& procs) {
mC2sBuf = std::make_unique<dawn::utils::TerribleCommandBuffer>();
mS2cBuf = std::make_unique<dawn::utils::TerribleCommandBuffer>();
@@ -166,19 +150,6 @@
return wgpu::Instance::Acquire(reserved.instance);
}
- wgpu::SwapChain CreateSwapChain(WGPUSurface backendSurface,
- WGPUDevice backendDevice,
- WGPUDevice apiDevice,
- const WGPUSwapChainDescriptor* descriptor) override {
- WGPUSwapChain cSwapChain =
- mBackendProcs.deviceCreateSwapChain(backendDevice, backendSurface, descriptor);
-
- auto reservation = mWireClient->ReserveSwapChain(apiDevice, descriptor);
- mWireServer->InjectSwapChain(cSwapChain, reservation.handle, reservation.deviceHandle);
-
- return wgpu::SwapChain::Acquire(reservation.swapchain);
- }
-
void BeginWireTrace(const char* name) override {
if (mWireServerTraceLayer) {
return mWireServerTraceLayer->BeginWireTrace(name);
@@ -192,7 +163,6 @@
bool IsIdle() override { return mC2sBuf->Empty() && mS2cBuf->Empty(); }
private:
- const DawnProcTable& mBackendProcs;
std::unique_ptr<dawn::utils::TerribleCommandBuffer> mC2sBuf;
std::unique_ptr<dawn::utils::TerribleCommandBuffer> mS2cBuf;
std::unique_ptr<dawn::wire::WireServer> mWireServer;
diff --git a/src/dawn/utils/WireHelper.h b/src/dawn/utils/WireHelper.h
index 8ef80f6..a56166a 100644
--- a/src/dawn/utils/WireHelper.h
+++ b/src/dawn/utils/WireHelper.h
@@ -59,12 +59,6 @@
const wgpu::InstanceDescriptor* nativeDesc = nullptr,
const wgpu::InstanceDescriptor* wireDesc = nullptr);
- // Creates a swap chain given a native device and surface.
- virtual wgpu::SwapChain CreateSwapChain(WGPUSurface backendSurface,
- WGPUDevice backendDevice,
- WGPUDevice apiDevice,
- const WGPUSwapChainDescriptor* descriptor) = 0;
-
virtual void BeginWireTrace(const char* name) = 0;
virtual bool FlushClient() = 0;
diff --git a/src/dawn/wire/BUILD.gn b/src/dawn/wire/BUILD.gn
index e638da5..fd5c870 100644
--- a/src/dawn/wire/BUILD.gn
+++ b/src/dawn/wire/BUILD.gn
@@ -133,8 +133,6 @@
"client/ShaderModule.h",
"client/Surface.cpp",
"client/Surface.h",
- "client/SwapChain.cpp",
- "client/SwapChain.h",
"client/Texture.cpp",
"client/Texture.h",
"server/ObjectStorage.h",
diff --git a/src/dawn/wire/CMakeLists.txt b/src/dawn/wire/CMakeLists.txt
index 51ad05e..a5c17bc 100644
--- a/src/dawn/wire/CMakeLists.txt
+++ b/src/dawn/wire/CMakeLists.txt
@@ -59,7 +59,6 @@
"client/Queue.h"
"client/ShaderModule.h"
"client/Surface.h"
- "client/SwapChain.h"
"client/Texture.h"
"ObjectHandle.h"
"server/ObjectStorage.h"
@@ -88,7 +87,6 @@
"client/Queue.cpp"
"client/ShaderModule.cpp"
"client/Surface.cpp"
- "client/SwapChain.cpp"
"client/Texture.cpp"
"ObjectHandle.cpp"
"server/Server.cpp"
diff --git a/src/dawn/wire/WireClient.cpp b/src/dawn/wire/WireClient.cpp
index b46633f..e9db3b0 100644
--- a/src/dawn/wire/WireClient.cpp
+++ b/src/dawn/wire/WireClient.cpp
@@ -51,11 +51,6 @@
return mImpl->ReserveTexture(device, descriptor);
}
-ReservedSwapChain WireClient::ReserveSwapChain(WGPUDevice device,
- const WGPUSwapChainDescriptor* descriptor) {
- return mImpl->ReserveSwapChain(device, descriptor);
-}
-
ReservedSurface WireClient::ReserveSurface(WGPUInstance instance,
const WGPUSurfaceCapabilities* capabilities) {
return mImpl->ReserveSurface(instance, capabilities);
@@ -73,10 +68,6 @@
mImpl->ReclaimTextureReservation(reservation);
}
-void WireClient::ReclaimSwapChainReservation(const ReservedSwapChain& reservation) {
- mImpl->ReclaimSwapChainReservation(reservation);
-}
-
void WireClient::ReclaimSurfaceReservation(const ReservedSurface& reservation) {
mImpl->ReclaimSurfaceReservation(reservation);
}
diff --git a/src/dawn/wire/WireServer.cpp b/src/dawn/wire/WireServer.cpp
index c0a6f9b..c608f38 100644
--- a/src/dawn/wire/WireServer.cpp
+++ b/src/dawn/wire/WireServer.cpp
@@ -53,12 +53,6 @@
return mImpl->InjectTexture(texture, handle, deviceHandle) == WireResult::Success;
}
-bool WireServer::InjectSwapChain(WGPUSwapChain swapchain,
- const Handle& handle,
- const Handle& deviceHandle) {
- return mImpl->InjectSwapChain(swapchain, handle, deviceHandle) == WireResult::Success;
-}
-
bool WireServer::InjectSurface(WGPUSurface surface,
const Handle& handle,
const Handle& instanceHandle) {
diff --git a/src/dawn/wire/client/ApiObjects.h b/src/dawn/wire/client/ApiObjects.h
index fdd57cd..7a71269 100644
--- a/src/dawn/wire/client/ApiObjects.h
+++ b/src/dawn/wire/client/ApiObjects.h
@@ -38,7 +38,6 @@
#include "dawn/wire/client/Queue.h"
#include "dawn/wire/client/ShaderModule.h"
#include "dawn/wire/client/Surface.h"
-#include "dawn/wire/client/SwapChain.h"
#include "dawn/wire/client/Texture.h"
#include "dawn/wire/client/ApiObjects_autogen.h"
diff --git a/src/dawn/wire/client/Client.cpp b/src/dawn/wire/client/Client.cpp
index e8d1567..56f20b9 100644
--- a/src/dawn/wire/client/Client.cpp
+++ b/src/dawn/wire/client/Client.cpp
@@ -99,17 +99,6 @@
return result;
}
-ReservedSwapChain Client::ReserveSwapChain(WGPUDevice device,
- const WGPUSwapChainDescriptor* descriptor) {
- Ref<SwapChain> swapChain = Make<SwapChain>(nullptr, descriptor);
-
- ReservedSwapChain result;
- result.handle = swapChain->GetWireHandle();
- result.deviceHandle = FromAPI(device)->GetWireHandle();
- result.swapchain = ReturnToAPI(std::move(swapChain));
- return result;
-}
-
ReservedSurface Client::ReserveSurface(WGPUInstance instance,
const WGPUSurfaceCapabilities* capabilities) {
Ref<Surface> surface = Make<Surface>(capabilities);
@@ -145,10 +134,6 @@
ReclaimReservation(FromAPI(reservation.texture));
}
-void Client::ReclaimSwapChainReservation(const ReservedSwapChain& reservation) {
- ReclaimReservation(FromAPI(reservation.swapchain));
-}
-
void Client::ReclaimSurfaceReservation(const ReservedSurface& reservation) {
ReclaimReservation(FromAPI(reservation.surface));
}
diff --git a/src/dawn/wire/client/Client.h b/src/dawn/wire/client/Client.h
index 18823e3..cc7a802 100644
--- a/src/dawn/wire/client/Client.h
+++ b/src/dawn/wire/client/Client.h
@@ -86,15 +86,12 @@
ReservedBuffer ReserveBuffer(WGPUDevice device, const WGPUBufferDescriptor* descriptor);
ReservedTexture ReserveTexture(WGPUDevice device, const WGPUTextureDescriptor* descriptor);
- ReservedSwapChain ReserveSwapChain(WGPUDevice device,
- const WGPUSwapChainDescriptor* descriptor);
ReservedSurface ReserveSurface(WGPUInstance instance,
const WGPUSurfaceCapabilities* capabilities);
ReservedInstance ReserveInstance(const WGPUInstanceDescriptor* descriptor);
void ReclaimBufferReservation(const ReservedBuffer& reservation);
void ReclaimTextureReservation(const ReservedTexture& reservation);
- void ReclaimSwapChainReservation(const ReservedSwapChain& reservation);
void ReclaimSurfaceReservation(const ReservedSurface& reservation);
void ReclaimInstanceReservation(const ReservedInstance& reservation);
diff --git a/src/dawn/wire/client/SwapChain.cpp b/src/dawn/wire/client/SwapChain.cpp
deleted file mode 100644
index 4eb4970..0000000
--- a/src/dawn/wire/client/SwapChain.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2023 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "dawn/wire/client/SwapChain.h"
-
-#include <utility>
-
-#include "dawn/wire/client/Client.h"
-#include "dawn/wire/client/Device.h"
-#include "dawn/wire/client/Texture.h"
-
-namespace dawn::wire::client {
-
-SwapChain::SwapChain(const ObjectBaseParams& params,
- WGPUSurface,
- const WGPUSwapChainDescriptor* descriptor)
- : ObjectBase(params) {
- mTextureDescriptor = {};
- mTextureDescriptor.size = {descriptor->width, descriptor->height, 1};
- mTextureDescriptor.format = descriptor->format;
- mTextureDescriptor.usage = descriptor->usage;
- mTextureDescriptor.dimension = WGPUTextureDimension_2D;
- mTextureDescriptor.mipLevelCount = 1;
- mTextureDescriptor.sampleCount = 1;
-}
-
-SwapChain::~SwapChain() = default;
-
-ObjectType SwapChain::GetObjectType() const {
- return ObjectType::SwapChain;
-}
-
-WGPUTexture SwapChain::GetCurrentTexture() {
- Client* wireClient = GetClient();
- Ref<Texture> texture = wireClient->Make<Texture>(&mTextureDescriptor);
-
- SwapChainGetCurrentTextureCmd cmd;
- cmd.self = ToAPI(this);
- cmd.selfId = GetWireId();
- cmd.result = texture->GetWireHandle();
- wireClient->SerializeCommand(cmd);
-
- return ReturnToAPI(std::move(texture));
-}
-
-} // namespace dawn::wire::client
diff --git a/src/dawn/wire/client/SwapChain.h b/src/dawn/wire/client/SwapChain.h
deleted file mode 100644
index eae3741..0000000
--- a/src/dawn/wire/client/SwapChain.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2023 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_DAWN_WIRE_CLIENT_SWAPCHAIN_H_
-#define SRC_DAWN_WIRE_CLIENT_SWAPCHAIN_H_
-
-#include <webgpu/webgpu.h>
-
-#include "dawn/wire/client/ObjectBase.h"
-
-namespace dawn::wire::client {
-
-class Device;
-
-class SwapChain final : public ObjectBase {
- public:
- SwapChain(const ObjectBaseParams& params,
- WGPUSurface surface,
- const WGPUSwapChainDescriptor* descriptor);
- ~SwapChain() override;
-
- ObjectType GetObjectType() const override;
-
- WGPUTexture GetCurrentTexture();
-
- private:
- WGPUTextureDescriptor mTextureDescriptor;
-};
-
-} // namespace dawn::wire::client
-
-#endif // SRC_DAWN_WIRE_CLIENT_SWAPCHAIN_H_
diff --git a/src/dawn/wire/server/Server.cpp b/src/dawn/wire/server/Server.cpp
index b469e0c..1859055 100644
--- a/src/dawn/wire/server/Server.cpp
+++ b/src/dawn/wire/server/Server.cpp
@@ -109,30 +109,6 @@
return WireResult::Success;
}
-WireResult Server::InjectSwapChain(WGPUSwapChain swapchain,
- const Handle& handle,
- const Handle& deviceHandle) {
- DAWN_ASSERT(swapchain != nullptr);
- Known<WGPUDevice> device;
- WIRE_TRY(Objects<WGPUDevice>().Get(deviceHandle.id, &device));
- if (device->generation != deviceHandle.generation) {
- return WireResult::FatalError;
- }
-
- Reserved<WGPUSwapChain> data;
- WIRE_TRY(Objects<WGPUSwapChain>().Allocate(&data, handle));
-
- data->handle = swapchain;
- data->generation = handle.generation;
- data->state = AllocationState::Allocated;
-
- // The swapchain is externally owned so it shouldn't be destroyed when we receive a destroy
- // message from the client. Add a reference to counterbalance the eventual release.
- mProcs.swapChainAddRef(swapchain);
-
- return WireResult::Success;
-}
-
WireResult Server::InjectSurface(WGPUSurface surface,
const Handle& handle,
const Handle& instanceHandle) {
diff --git a/src/dawn/wire/server/Server.h b/src/dawn/wire/server/Server.h
index 7b9109b..179a8cd 100644
--- a/src/dawn/wire/server/Server.h
+++ b/src/dawn/wire/server/Server.h
@@ -200,9 +200,6 @@
WireResult InjectBuffer(WGPUBuffer buffer, const Handle& handle, const Handle& deviceHandle);
WireResult InjectTexture(WGPUTexture texture, const Handle& handle, const Handle& deviceHandle);
- WireResult InjectSwapChain(WGPUSwapChain swapchain,
- const Handle& handle,
- const Handle& deviceHandle);
WireResult InjectSurface(WGPUSurface surface,
const Handle& handle,
const Handle& instanceHandle);
diff --git a/tools/android/BUILD.gn b/tools/android/BUILD.gn
index a9b454a..b25225b 100644
--- a/tools/android/BUILD.gn
+++ b/tools/android/BUILD.gn
@@ -190,8 +190,6 @@
"java/android/dawn/SurfaceGetCurrentTextureStatus.kt",
"java/android/dawn/SurfaceSourceAndroidNativeWindow.kt",
"java/android/dawn/SurfaceTexture.kt",
- "java/android/dawn/SwapChain.kt",
- "java/android/dawn/SwapChainDescriptor.kt",
"java/android/dawn/Texture.kt",
"java/android/dawn/TextureAspect.kt",
"java/android/dawn/TextureBindingLayout.kt",