This is to eventually allow more using swapchain textures as CopySrc and CopyDst. Note that this commit doesn't add any additional usages. Because textures can reflect their creation parameters, swapchains now need to pass in the correct texture descriptor in all code paths. This requires additional handling in dawn::native error swapchains, and dawn::wire::client's SwapChain reservation and Device::CreateSwapChain code. Tests are added for all of these code paths except dawn::wire::client::Device::CreateSwapChain because there is no way to create a Surface in wire tests at the moment (they don't have an instance). Bug: dawn:1551 Change-Id: I22d5e909e1e94d48eb52cae57aabff8a7f0c04c1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133463 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Loko Kung <lokokung@google.com>main
parent
2ef42221d4
commit
943a1a2d7a
@ -0,0 +1,69 @@ |
||||
// Copyright 2023 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "dawn/wire/client/SwapChain.h" |
||||
|
||||
#include "dawn/wire/client/Client.h" |
||||
#include "dawn/wire/client/Device.h" |
||||
#include "dawn/wire/client/Texture.h" |
||||
|
||||
namespace dawn::wire::client { |
||||
|
||||
// static
|
||||
WGPUSwapChain SwapChain::Create(Device* device, |
||||
WGPUSurface surface, |
||||
const WGPUSwapChainDescriptor* descriptor) { |
||||
Client* wireClient = device->GetClient(); |
||||
SwapChain* swapChain = wireClient->Make<SwapChain>(surface, descriptor); |
||||
|
||||
// Send the Device::CreateSwapChain command without modifications.
|
||||
DeviceCreateSwapChainCmd cmd; |
||||
cmd.self = ToAPI(device); |
||||
cmd.selfId = device->GetWireId(); |
||||
cmd.descriptor = descriptor; |
||||
cmd.result = swapChain->GetWireHandle(); |
||||
wireClient->SerializeCommand(cmd); |
||||
|
||||
return ToAPI(swapChain); |
||||
} |
||||
|
||||
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; |
||||
|
||||
WGPUTexture SwapChain::GetCurrentTexture() { |
||||
Client* wireClient = GetClient(); |
||||
Texture* texture = wireClient->Make<Texture>(&mTextureDescriptor); |
||||
|
||||
SwapChainGetCurrentTextureCmd cmd; |
||||
cmd.self = ToAPI(this); |
||||
cmd.selfId = GetWireId(); |
||||
cmd.result = texture->GetWireHandle(); |
||||
wireClient->SerializeCommand(cmd); |
||||
|
||||
return ToAPI(texture); |
||||
} |
||||
|
||||
} // namespace dawn::wire::client
|
@ -0,0 +1,45 @@ |
||||
// Copyright 2023 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_DAWN_WIRE_CLIENT_SWAPCHAIN_H_ |
||||
#define SRC_DAWN_WIRE_CLIENT_SWAPCHAIN_H_ |
||||
|
||||
#include "dawn/webgpu.h" |
||||
|
||||
#include "dawn/wire/client/ObjectBase.h" |
||||
|
||||
namespace dawn::wire::client { |
||||
|
||||
class Device; |
||||
|
||||
class SwapChain final : public ObjectBase { |
||||
public: |
||||
static WGPUSwapChain Create(Device* device, |
||||
WGPUSurface surface, |
||||
const WGPUSwapChainDescriptor* descriptor); |
||||
|
||||
SwapChain(const ObjectBaseParams& params, |
||||
WGPUSurface surface, |
||||
const WGPUSwapChainDescriptor* descriptor); |
||||
~SwapChain() override; |
||||
|
||||
WGPUTexture GetCurrentTexture(); |
||||
|
||||
private: |
||||
WGPUTextureDescriptor mTextureDescriptor; |
||||
}; |
||||
|
||||
} // namespace dawn::wire::client
|
||||
|
||||
#endif // SRC_DAWN_WIRE_CLIENT_SWAPCHAIN_H_
|
Loading…
Reference in new issue