xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/wgpu/DisplayWgpu.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2024 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // DisplayWgpu.h:
7 //    Defines the class interface for DisplayWgpu, implementing DisplayImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_WGPU_DISPLAYWGPU_H_
11 #define LIBANGLE_RENDERER_WGPU_DISPLAYWGPU_H_
12 
13 #include <dawn/native/DawnNative.h>
14 #include <dawn/webgpu_cpp.h>
15 
16 #include "libANGLE/renderer/DisplayImpl.h"
17 #include "libANGLE/renderer/ShareGroupImpl.h"
18 #include "libANGLE/renderer/wgpu/wgpu_format_utils.h"
19 
20 namespace rx
21 {
22 class ShareGroupWgpu : public ShareGroupImpl
23 {
24   public:
ShareGroupWgpu(const egl::ShareGroupState & state)25     ShareGroupWgpu(const egl::ShareGroupState &state) : ShareGroupImpl(state) {}
26 };
27 
28 class AllocationTrackerWgpu;
29 
30 class DisplayWgpu : public DisplayImpl
31 {
32   public:
33     DisplayWgpu(const egl::DisplayState &state);
34     ~DisplayWgpu() override;
35 
36     egl::Error initialize(egl::Display *display) override;
37     void terminate() override;
38 
39     egl::Error makeCurrent(egl::Display *display,
40                            egl::Surface *drawSurface,
41                            egl::Surface *readSurface,
42                            gl::Context *context) override;
43 
44     egl::ConfigSet generateConfigs() override;
45 
46     bool testDeviceLost() override;
47     egl::Error restoreLostDevice(const egl::Display *display) override;
48 
49     bool isValidNativeWindow(EGLNativeWindowType window) const override;
50 
51     std::string getRendererDescription() override;
52     std::string getVendorString() override;
53     std::string getVersionString(bool includeFullVersion) override;
54 
55     DeviceImpl *createDevice() override;
56 
57     egl::Error waitClient(const gl::Context *context) override;
58     egl::Error waitNative(const gl::Context *context, EGLint engine) override;
59     gl::Version getMaxSupportedESVersion() const override;
60     gl::Version getMaxConformantESVersion() const override;
61 
62     SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
63                                      EGLNativeWindowType window,
64                                      const egl::AttributeMap &attribs) override;
65     SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state,
66                                       const egl::AttributeMap &attribs) override;
67     SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state,
68                                                EGLenum buftype,
69                                                EGLClientBuffer buffer,
70                                                const egl::AttributeMap &attribs) override;
71     SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state,
72                                      NativePixmapType nativePixmap,
73                                      const egl::AttributeMap &attribs) override;
74 
75     ImageImpl *createImage(const egl::ImageState &state,
76                            const gl::Context *context,
77                            EGLenum target,
78                            const egl::AttributeMap &attribs) override;
79 
80     ContextImpl *createContext(const gl::State &state,
81                                gl::ErrorSet *errorSet,
82                                const egl::Config *configuration,
83                                const gl::Context *shareContext,
84                                const egl::AttributeMap &attribs) override;
85 
86     StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
87                                                        const egl::AttributeMap &attribs) override;
88 
89     ShareGroupImpl *createShareGroup(const egl::ShareGroupState &state) override;
90 
populateFeatureList(angle::FeatureList * features)91     void populateFeatureList(angle::FeatureList *features) override {}
92 
93     angle::NativeWindowSystem getWindowSystem() const override;
94 
getAdapter()95     wgpu::Adapter &getAdapter() { return mAdapter; }
getDevice()96     wgpu::Device &getDevice() { return mDevice; }
getQueue()97     wgpu::Queue &getQueue() { return mQueue; }
getInstance()98     wgpu::Instance &getInstance() { return mInstance; }
99 
getLimitsWgpu()100     const wgpu::Limits getLimitsWgpu() const { return mLimitsWgpu; }
101 
getGLCaps()102     const gl::Caps &getGLCaps() const { return mGLCaps; }
getGLTextureCaps()103     const gl::TextureCapsMap &getGLTextureCaps() const { return mGLTextureCaps; }
getGLExtensions()104     const gl::Extensions &getGLExtensions() const { return mGLExtensions; }
getGLLimitations()105     const gl::Limitations &getGLLimitations() const { return mGLLimitations; }
getPLSOptions()106     const ShPixelLocalStorageOptions &getPLSOptions() const { return mPLSOptions; }
107 
getSurfaceCache()108     std::map<EGLNativeWindowType, wgpu::Surface> &getSurfaceCache() { return mSurfaceCache; }
109 
getFormat(GLenum internalFormat)110     const webgpu::Format &getFormat(GLenum internalFormat) const
111     {
112         return mFormatTable[internalFormat];
113     }
114 
115   private:
116     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
117     void generateCaps(egl::Caps *outCaps) const override;
118 
119     egl::Error createWgpuDevice();
120 
121     wgpu::Adapter mAdapter;
122     wgpu::Instance mInstance;
123     wgpu::Device mDevice;
124     wgpu::Queue mQueue;
125 
126     wgpu::Limits mLimitsWgpu;
127 
128     gl::Caps mGLCaps;
129     gl::TextureCapsMap mGLTextureCaps;
130     gl::Extensions mGLExtensions;
131     gl::Limitations mGLLimitations;
132     egl::Caps mEGLCaps;
133     egl::DisplayExtensions mEGLExtensions;
134     gl::Version mMaxSupportedClientVersion;
135     ShPixelLocalStorageOptions mPLSOptions;
136 
137     // http://anglebug.com/342213844
138     // Dawn currently holds references to the internal swap chains for an unknown amount of time
139     // after destroying a surface and can fail to create a new swap chain for the same window.
140     // ANGLE tests re-create EGL surfaces for the same window each test. As a workaround, cache the
141     // wgpu::Surface created for each window for the lifetime of the display.
142     std::map<EGLNativeWindowType, wgpu::Surface> mSurfaceCache;
143 
144     webgpu::FormatTable mFormatTable;
145 };
146 
147 }  // namespace rx
148 
149 #endif  // LIBANGLE_RENDERER_WGPU_DISPLAYWGPU_H_
150