1 | /* |
2 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(WEBGPU) |
29 | |
30 | #include "GPUQueue.h" |
31 | #include "GPUSwapChain.h" |
32 | #include <wtf/RefCounted.h> |
33 | #include <wtf/RetainPtr.h> |
34 | #include <wtf/WeakPtr.h> |
35 | |
36 | OBJC_PROTOCOL(MTLDevice); |
37 | |
38 | namespace WebCore { |
39 | |
40 | class GPUBindGroupLayout; |
41 | class GPUBuffer; |
42 | class GPUCommandBuffer; |
43 | class GPUComputePipeline; |
44 | class GPUPipelineLayout; |
45 | class GPURenderPipeline; |
46 | class GPUSampler; |
47 | class GPUShaderModule; |
48 | class GPUTexture; |
49 | |
50 | struct GPUBindGroupLayoutDescriptor; |
51 | struct GPUBufferDescriptor; |
52 | struct GPUComputePipelineDescriptor; |
53 | struct GPUPipelineLayoutDescriptor; |
54 | struct GPURenderPipelineDescriptor; |
55 | struct GPURequestAdapterOptions; |
56 | struct GPUSamplerDescriptor; |
57 | struct GPUShaderModuleDescriptor; |
58 | struct GPUSwapChainDescriptor; |
59 | struct GPUTextureDescriptor; |
60 | |
61 | using PlatformDevice = MTLDevice; |
62 | using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>; |
63 | |
64 | class GPUDevice : public RefCounted<GPUDevice>, public CanMakeWeakPtr<GPUDevice> { |
65 | public: |
66 | static RefPtr<GPUDevice> tryCreate(const Optional<GPURequestAdapterOptions>&); |
67 | |
68 | RefPtr<GPUBuffer> tryCreateBuffer(const GPUBufferDescriptor&); |
69 | RefPtr<GPUTexture> tryCreateTexture(const GPUTextureDescriptor&) const; |
70 | RefPtr<GPUSampler> tryCreateSampler(const GPUSamplerDescriptor&) const; |
71 | |
72 | RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(const GPUBindGroupLayoutDescriptor&) const; |
73 | Ref<GPUPipelineLayout> createPipelineLayout(GPUPipelineLayoutDescriptor&&) const; |
74 | |
75 | RefPtr<GPUShaderModule> tryCreateShaderModule(const GPUShaderModuleDescriptor&) const; |
76 | RefPtr<GPURenderPipeline> tryCreateRenderPipeline(const GPURenderPipelineDescriptor&) const; |
77 | RefPtr<GPUComputePipeline> tryCreateComputePipeline(const GPUComputePipelineDescriptor&) const; |
78 | |
79 | RefPtr<GPUCommandBuffer> tryCreateCommandBuffer() const; |
80 | |
81 | RefPtr<GPUQueue> tryGetQueue() const; |
82 | |
83 | PlatformDevice* platformDevice() const { return m_platformDevice.get(); } |
84 | GPUSwapChain* swapChain() const { return m_swapChain.get(); } |
85 | void setSwapChain(RefPtr<GPUSwapChain>&&); |
86 | |
87 | private: |
88 | explicit GPUDevice(PlatformDeviceSmartPtr&&); |
89 | |
90 | PlatformDeviceSmartPtr m_platformDevice; |
91 | mutable RefPtr<GPUQueue> m_queue; |
92 | RefPtr<GPUSwapChain> m_swapChain; |
93 | }; |
94 | |
95 | } // namespace WebCore |
96 | |
97 | #endif // ENABLE(WEBGPU) |
98 | |