• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_OPENGL_DEVICEGL_H_
16 #define DAWNNATIVE_OPENGL_DEVICEGL_H_
17 
18 #include "dawn_native/dawn_platform.h"
19 
20 #include "common/Platform.h"
21 #include "dawn_native/Device.h"
22 #include "dawn_native/QuerySet.h"
23 #include "dawn_native/opengl/Forward.h"
24 #include "dawn_native/opengl/GLFormat.h"
25 #include "dawn_native/opengl/OpenGLFunctions.h"
26 
27 #include <queue>
28 
29 // Remove windows.h macros after glad's include of windows.h
30 #if defined(DAWN_PLATFORM_WINDOWS)
31 #    include "common/windows_with_undefs.h"
32 #endif
33 
34 typedef void* EGLImage;
35 
36 namespace dawn_native { namespace opengl {
37 
38     class Device final : public DeviceBase {
39       public:
40         static ResultOrError<Device*> Create(AdapterBase* adapter,
41                                              const DawnDeviceDescriptor* descriptor,
42                                              const OpenGLFunctions& functions);
43         ~Device() override;
44 
45         MaybeError Initialize();
46 
47         // Contains all the OpenGL entry points, glDoFoo is called via device->gl.DoFoo.
48         const OpenGLFunctions gl;
49 
50         const GLFormat& GetGLFormat(const Format& format);
51 
52         void SubmitFenceSync();
53 
54         MaybeError ValidateEGLImageCanBeWrapped(const TextureDescriptor* descriptor,
55                                                 ::EGLImage image);
56         TextureBase* CreateTextureWrappingEGLImage(const ExternalImageDescriptor* descriptor,
57                                                    ::EGLImage image);
58 
59         ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
60             CommandEncoder* encoder,
61             const CommandBufferDescriptor* descriptor) override;
62 
63         MaybeError TickImpl() override;
64 
65         ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) override;
66         MaybeError CopyFromStagingToBuffer(StagingBufferBase* source,
67                                            uint64_t sourceOffset,
68                                            BufferBase* destination,
69                                            uint64_t destinationOffset,
70                                            uint64_t size) override;
71 
72         MaybeError CopyFromStagingToTexture(const StagingBufferBase* source,
73                                             const TextureDataLayout& src,
74                                             TextureCopy* dst,
75                                             const Extent3D& copySizePixels) override;
76 
77         uint32_t GetOptimalBytesPerRowAlignment() const override;
78         uint64_t GetOptimalBufferToTextureCopyOffsetAlignment() const override;
79 
80         float GetTimestampPeriodInNS() const override;
81 
82       private:
83         Device(AdapterBase* adapter,
84                const DawnDeviceDescriptor* descriptor,
85                const OpenGLFunctions& functions);
86 
87         ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
88             const BindGroupDescriptor* descriptor) override;
89         ResultOrError<Ref<BindGroupLayoutBase>> CreateBindGroupLayoutImpl(
90             const BindGroupLayoutDescriptor* descriptor,
91             PipelineCompatibilityToken pipelineCompatibilityToken) override;
92         ResultOrError<Ref<BufferBase>> CreateBufferImpl(
93             const BufferDescriptor* descriptor) override;
94         ResultOrError<Ref<PipelineLayoutBase>> CreatePipelineLayoutImpl(
95             const PipelineLayoutDescriptor* descriptor) override;
96         ResultOrError<Ref<QuerySetBase>> CreateQuerySetImpl(
97             const QuerySetDescriptor* descriptor) override;
98         ResultOrError<Ref<SamplerBase>> CreateSamplerImpl(
99             const SamplerDescriptor* descriptor) override;
100         ResultOrError<Ref<ShaderModuleBase>> CreateShaderModuleImpl(
101             const ShaderModuleDescriptor* descriptor,
102             ShaderModuleParseResult* parseResult) override;
103         ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
104             const SwapChainDescriptor* descriptor) override;
105         ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
106             Surface* surface,
107             NewSwapChainBase* previousSwapChain,
108             const SwapChainDescriptor* descriptor) override;
109         ResultOrError<Ref<TextureBase>> CreateTextureImpl(
110             const TextureDescriptor* descriptor) override;
111         ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
112             TextureBase* texture,
113             const TextureViewDescriptor* descriptor) override;
114         Ref<ComputePipelineBase> CreateUninitializedComputePipelineImpl(
115             const ComputePipelineDescriptor* descriptor) override;
116         Ref<RenderPipelineBase> CreateUninitializedRenderPipelineImpl(
117             const RenderPipelineDescriptor* descriptor) override;
118 
119         void InitTogglesFromDriver();
120         ResultOrError<ExecutionSerial> CheckAndUpdateCompletedSerials() override;
121         void DestroyImpl() override;
122         MaybeError WaitForIdleForDestruction() override;
123 
124         std::queue<std::pair<GLsync, ExecutionSerial>> mFencesInFlight;
125 
126         GLFormatTable mFormatTable;
127     };
128 
129 }}  // namespace dawn_native::opengl
130 
131 #endif  // DAWNNATIVE_OPENGL_DEVICEGL_H_
132