• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_CREATEPIPELINEASYNCTASK_H_
16 #define DAWNNATIVE_CREATEPIPELINEASYNCTASK_H_
17 
18 #include "common/RefCounted.h"
19 #include "dawn/webgpu.h"
20 #include "dawn_native/CallbackTaskManager.h"
21 #include "dawn_native/Error.h"
22 
23 namespace dawn_native {
24 
25     class ComputePipelineBase;
26     class DeviceBase;
27     class PipelineLayoutBase;
28     class RenderPipelineBase;
29     class ShaderModuleBase;
30     struct FlatComputePipelineDescriptor;
31 
32     struct CreatePipelineAsyncCallbackTaskBase : CallbackTask {
33         CreatePipelineAsyncCallbackTaskBase(std::string errorMessage, void* userData);
34 
35       protected:
36         std::string mErrorMessage;
37         void* mUserData;
38     };
39 
40     struct CreateComputePipelineAsyncCallbackTask : CreatePipelineAsyncCallbackTaskBase {
41         CreateComputePipelineAsyncCallbackTask(Ref<ComputePipelineBase> pipeline,
42                                                std::string errorMessage,
43                                                WGPUCreateComputePipelineAsyncCallback callback,
44                                                void* userdata);
45 
46         void Finish() override;
47         void HandleShutDown() final;
48         void HandleDeviceLoss() final;
49 
50       protected:
51         Ref<ComputePipelineBase> mPipeline;
52         WGPUCreateComputePipelineAsyncCallback mCreateComputePipelineAsyncCallback;
53     };
54 
55     struct CreateRenderPipelineAsyncCallbackTask : CreatePipelineAsyncCallbackTaskBase {
56         CreateRenderPipelineAsyncCallbackTask(Ref<RenderPipelineBase> pipeline,
57                                               std::string errorMessage,
58                                               WGPUCreateRenderPipelineAsyncCallback callback,
59                                               void* userdata);
60 
61         void Finish() override;
62         void HandleShutDown() final;
63         void HandleDeviceLoss() final;
64 
65       protected:
66         Ref<RenderPipelineBase> mPipeline;
67         WGPUCreateRenderPipelineAsyncCallback mCreateRenderPipelineAsyncCallback;
68     };
69 
70     // CreateComputePipelineAsyncTask defines all the inputs and outputs of
71     // CreateComputePipelineAsync() tasks, which are the same among all the backends.
72     class CreateComputePipelineAsyncTask {
73       public:
74         CreateComputePipelineAsyncTask(Ref<ComputePipelineBase> nonInitializedComputePipeline,
75                                        WGPUCreateComputePipelineAsyncCallback callback,
76                                        void* userdata);
77 
78         void Run();
79 
80         static void RunAsync(std::unique_ptr<CreateComputePipelineAsyncTask> task);
81 
82       private:
83         Ref<ComputePipelineBase> mComputePipeline;
84         WGPUCreateComputePipelineAsyncCallback mCallback;
85         void* mUserdata;
86     };
87 
88     // CreateRenderPipelineAsyncTask defines all the inputs and outputs of
89     // CreateRenderPipelineAsync() tasks, which are the same among all the backends.
90     class CreateRenderPipelineAsyncTask {
91       public:
92         CreateRenderPipelineAsyncTask(Ref<RenderPipelineBase> nonInitializedRenderPipeline,
93                                       WGPUCreateRenderPipelineAsyncCallback callback,
94                                       void* userdata);
95 
96         void Run();
97 
98         static void RunAsync(std::unique_ptr<CreateRenderPipelineAsyncTask> task);
99 
100       private:
101         Ref<RenderPipelineBase> mRenderPipeline;
102         WGPUCreateRenderPipelineAsyncCallback mCallback;
103         void* mUserdata;
104     };
105 
106 }  // namespace dawn_native
107 
108 #endif  // DAWNNATIVE_CREATEPIPELINEASYNCTASK_H_
109