xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/wgpu/DisplayWgpu.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2024 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // DisplayWgpu.cpp:
7*8975f5c5SAndroid Build Coastguard Worker //    Implements the class methods for DisplayWgpu.
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker 
10*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/wgpu/DisplayWgpu.h"
11*8975f5c5SAndroid Build Coastguard Worker 
12*8975f5c5SAndroid Build Coastguard Worker #include <dawn/dawn_proc.h>
13*8975f5c5SAndroid Build Coastguard Worker 
14*8975f5c5SAndroid Build Coastguard Worker #include "common/debug.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "common/platform.h"
16*8975f5c5SAndroid Build Coastguard Worker 
17*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Display.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/wgpu/ContextWgpu.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/wgpu/DeviceWgpu.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/wgpu/DisplayWgpu_api.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/wgpu/ImageWgpu.h"
22*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/wgpu/SurfaceWgpu.h"
23*8975f5c5SAndroid Build Coastguard Worker 
24*8975f5c5SAndroid Build Coastguard Worker namespace rx
25*8975f5c5SAndroid Build Coastguard Worker {
26*8975f5c5SAndroid Build Coastguard Worker 
DisplayWgpu(const egl::DisplayState & state)27*8975f5c5SAndroid Build Coastguard Worker DisplayWgpu::DisplayWgpu(const egl::DisplayState &state) : DisplayImpl(state) {}
28*8975f5c5SAndroid Build Coastguard Worker 
~DisplayWgpu()29*8975f5c5SAndroid Build Coastguard Worker DisplayWgpu::~DisplayWgpu() {}
30*8975f5c5SAndroid Build Coastguard Worker 
initialize(egl::Display * display)31*8975f5c5SAndroid Build Coastguard Worker egl::Error DisplayWgpu::initialize(egl::Display *display)
32*8975f5c5SAndroid Build Coastguard Worker {
33*8975f5c5SAndroid Build Coastguard Worker     ANGLE_TRY(createWgpuDevice());
34*8975f5c5SAndroid Build Coastguard Worker 
35*8975f5c5SAndroid Build Coastguard Worker     mQueue = mDevice.GetQueue();
36*8975f5c5SAndroid Build Coastguard Worker     mFormatTable.initialize();
37*8975f5c5SAndroid Build Coastguard Worker 
38*8975f5c5SAndroid Build Coastguard Worker     wgpu::SupportedLimits supportedLimits;
39*8975f5c5SAndroid Build Coastguard Worker     mDevice.GetLimits(&supportedLimits);
40*8975f5c5SAndroid Build Coastguard Worker     mLimitsWgpu = supportedLimits.limits;
41*8975f5c5SAndroid Build Coastguard Worker 
42*8975f5c5SAndroid Build Coastguard Worker     webgpu::GenerateCaps(mLimitsWgpu, &mGLCaps, &mGLTextureCaps, &mGLExtensions, &mGLLimitations,
43*8975f5c5SAndroid Build Coastguard Worker                          &mEGLCaps, &mEGLExtensions, &mMaxSupportedClientVersion);
44*8975f5c5SAndroid Build Coastguard Worker 
45*8975f5c5SAndroid Build Coastguard Worker     return egl::NoError();
46*8975f5c5SAndroid Build Coastguard Worker }
47*8975f5c5SAndroid Build Coastguard Worker 
terminate()48*8975f5c5SAndroid Build Coastguard Worker void DisplayWgpu::terminate() {}
49*8975f5c5SAndroid Build Coastguard Worker 
makeCurrent(egl::Display * display,egl::Surface * drawSurface,egl::Surface * readSurface,gl::Context * context)50*8975f5c5SAndroid Build Coastguard Worker egl::Error DisplayWgpu::makeCurrent(egl::Display *display,
51*8975f5c5SAndroid Build Coastguard Worker                                     egl::Surface *drawSurface,
52*8975f5c5SAndroid Build Coastguard Worker                                     egl::Surface *readSurface,
53*8975f5c5SAndroid Build Coastguard Worker                                     gl::Context *context)
54*8975f5c5SAndroid Build Coastguard Worker {
55*8975f5c5SAndroid Build Coastguard Worker     // Ensure that the correct global DebugAnnotator is installed when the end2end tests change
56*8975f5c5SAndroid Build Coastguard Worker     // the ANGLE back-end (done frequently).
57*8975f5c5SAndroid Build Coastguard Worker     display->setGlobalDebugAnnotator();
58*8975f5c5SAndroid Build Coastguard Worker 
59*8975f5c5SAndroid Build Coastguard Worker     return egl::NoError();
60*8975f5c5SAndroid Build Coastguard Worker }
61*8975f5c5SAndroid Build Coastguard Worker 
generateConfigs()62*8975f5c5SAndroid Build Coastguard Worker egl::ConfigSet DisplayWgpu::generateConfigs()
63*8975f5c5SAndroid Build Coastguard Worker {
64*8975f5c5SAndroid Build Coastguard Worker     egl::Config config;
65*8975f5c5SAndroid Build Coastguard Worker     config.renderTargetFormat    = GL_BGRA8_EXT;
66*8975f5c5SAndroid Build Coastguard Worker     config.depthStencilFormat    = GL_DEPTH24_STENCIL8;
67*8975f5c5SAndroid Build Coastguard Worker     config.bufferSize            = 32;
68*8975f5c5SAndroid Build Coastguard Worker     config.redSize               = 8;
69*8975f5c5SAndroid Build Coastguard Worker     config.greenSize             = 8;
70*8975f5c5SAndroid Build Coastguard Worker     config.blueSize              = 8;
71*8975f5c5SAndroid Build Coastguard Worker     config.alphaSize             = 8;
72*8975f5c5SAndroid Build Coastguard Worker     config.alphaMaskSize         = 0;
73*8975f5c5SAndroid Build Coastguard Worker     config.bindToTextureRGB      = EGL_TRUE;
74*8975f5c5SAndroid Build Coastguard Worker     config.bindToTextureRGBA     = EGL_TRUE;
75*8975f5c5SAndroid Build Coastguard Worker     config.colorBufferType       = EGL_RGB_BUFFER;
76*8975f5c5SAndroid Build Coastguard Worker     config.configCaveat          = EGL_NONE;
77*8975f5c5SAndroid Build Coastguard Worker     config.conformant            = EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT;
78*8975f5c5SAndroid Build Coastguard Worker     config.depthSize             = 24;
79*8975f5c5SAndroid Build Coastguard Worker     config.level                 = 0;
80*8975f5c5SAndroid Build Coastguard Worker     config.matchNativePixmap     = EGL_NONE;
81*8975f5c5SAndroid Build Coastguard Worker     config.maxPBufferWidth       = 0;
82*8975f5c5SAndroid Build Coastguard Worker     config.maxPBufferHeight      = 0;
83*8975f5c5SAndroid Build Coastguard Worker     config.maxPBufferPixels      = 0;
84*8975f5c5SAndroid Build Coastguard Worker     config.maxSwapInterval       = 1;
85*8975f5c5SAndroid Build Coastguard Worker     config.minSwapInterval       = 1;
86*8975f5c5SAndroid Build Coastguard Worker     config.nativeRenderable      = EGL_TRUE;
87*8975f5c5SAndroid Build Coastguard Worker     config.nativeVisualID        = 0;
88*8975f5c5SAndroid Build Coastguard Worker     config.nativeVisualType      = EGL_NONE;
89*8975f5c5SAndroid Build Coastguard Worker     config.renderableType        = EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT;
90*8975f5c5SAndroid Build Coastguard Worker     config.sampleBuffers         = 0;
91*8975f5c5SAndroid Build Coastguard Worker     config.samples               = 0;
92*8975f5c5SAndroid Build Coastguard Worker     config.stencilSize           = 8;
93*8975f5c5SAndroid Build Coastguard Worker     config.surfaceType           = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
94*8975f5c5SAndroid Build Coastguard Worker     config.optimalOrientation    = 0;
95*8975f5c5SAndroid Build Coastguard Worker     config.transparentType       = EGL_NONE;
96*8975f5c5SAndroid Build Coastguard Worker     config.transparentRedValue   = 0;
97*8975f5c5SAndroid Build Coastguard Worker     config.transparentGreenValue = 0;
98*8975f5c5SAndroid Build Coastguard Worker     config.transparentBlueValue  = 0;
99*8975f5c5SAndroid Build Coastguard Worker 
100*8975f5c5SAndroid Build Coastguard Worker     egl::ConfigSet configSet;
101*8975f5c5SAndroid Build Coastguard Worker     configSet.add(config);
102*8975f5c5SAndroid Build Coastguard Worker     return configSet;
103*8975f5c5SAndroid Build Coastguard Worker }
104*8975f5c5SAndroid Build Coastguard Worker 
testDeviceLost()105*8975f5c5SAndroid Build Coastguard Worker bool DisplayWgpu::testDeviceLost()
106*8975f5c5SAndroid Build Coastguard Worker {
107*8975f5c5SAndroid Build Coastguard Worker     return false;
108*8975f5c5SAndroid Build Coastguard Worker }
109*8975f5c5SAndroid Build Coastguard Worker 
restoreLostDevice(const egl::Display * display)110*8975f5c5SAndroid Build Coastguard Worker egl::Error DisplayWgpu::restoreLostDevice(const egl::Display *display)
111*8975f5c5SAndroid Build Coastguard Worker {
112*8975f5c5SAndroid Build Coastguard Worker     return egl::NoError();
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker 
isValidNativeWindow(EGLNativeWindowType window) const115*8975f5c5SAndroid Build Coastguard Worker bool DisplayWgpu::isValidNativeWindow(EGLNativeWindowType window) const
116*8975f5c5SAndroid Build Coastguard Worker {
117*8975f5c5SAndroid Build Coastguard Worker     return true;
118*8975f5c5SAndroid Build Coastguard Worker }
119*8975f5c5SAndroid Build Coastguard Worker 
getRendererDescription()120*8975f5c5SAndroid Build Coastguard Worker std::string DisplayWgpu::getRendererDescription()
121*8975f5c5SAndroid Build Coastguard Worker {
122*8975f5c5SAndroid Build Coastguard Worker     return "Wgpu";
123*8975f5c5SAndroid Build Coastguard Worker }
124*8975f5c5SAndroid Build Coastguard Worker 
getVendorString()125*8975f5c5SAndroid Build Coastguard Worker std::string DisplayWgpu::getVendorString()
126*8975f5c5SAndroid Build Coastguard Worker {
127*8975f5c5SAndroid Build Coastguard Worker     return "Wgpu";
128*8975f5c5SAndroid Build Coastguard Worker }
129*8975f5c5SAndroid Build Coastguard Worker 
getVersionString(bool includeFullVersion)130*8975f5c5SAndroid Build Coastguard Worker std::string DisplayWgpu::getVersionString(bool includeFullVersion)
131*8975f5c5SAndroid Build Coastguard Worker {
132*8975f5c5SAndroid Build Coastguard Worker     return std::string();
133*8975f5c5SAndroid Build Coastguard Worker }
134*8975f5c5SAndroid Build Coastguard Worker 
createDevice()135*8975f5c5SAndroid Build Coastguard Worker DeviceImpl *DisplayWgpu::createDevice()
136*8975f5c5SAndroid Build Coastguard Worker {
137*8975f5c5SAndroid Build Coastguard Worker     return new DeviceWgpu();
138*8975f5c5SAndroid Build Coastguard Worker }
139*8975f5c5SAndroid Build Coastguard Worker 
waitClient(const gl::Context * context)140*8975f5c5SAndroid Build Coastguard Worker egl::Error DisplayWgpu::waitClient(const gl::Context *context)
141*8975f5c5SAndroid Build Coastguard Worker {
142*8975f5c5SAndroid Build Coastguard Worker     return egl::NoError();
143*8975f5c5SAndroid Build Coastguard Worker }
144*8975f5c5SAndroid Build Coastguard Worker 
waitNative(const gl::Context * context,EGLint engine)145*8975f5c5SAndroid Build Coastguard Worker egl::Error DisplayWgpu::waitNative(const gl::Context *context, EGLint engine)
146*8975f5c5SAndroid Build Coastguard Worker {
147*8975f5c5SAndroid Build Coastguard Worker     return egl::NoError();
148*8975f5c5SAndroid Build Coastguard Worker }
149*8975f5c5SAndroid Build Coastguard Worker 
getMaxSupportedESVersion() const150*8975f5c5SAndroid Build Coastguard Worker gl::Version DisplayWgpu::getMaxSupportedESVersion() const
151*8975f5c5SAndroid Build Coastguard Worker {
152*8975f5c5SAndroid Build Coastguard Worker     return mMaxSupportedClientVersion;
153*8975f5c5SAndroid Build Coastguard Worker }
154*8975f5c5SAndroid Build Coastguard Worker 
getMaxConformantESVersion() const155*8975f5c5SAndroid Build Coastguard Worker gl::Version DisplayWgpu::getMaxConformantESVersion() const
156*8975f5c5SAndroid Build Coastguard Worker {
157*8975f5c5SAndroid Build Coastguard Worker     return mMaxSupportedClientVersion;
158*8975f5c5SAndroid Build Coastguard Worker }
159*8975f5c5SAndroid Build Coastguard Worker 
createWindowSurface(const egl::SurfaceState & state,EGLNativeWindowType window,const egl::AttributeMap & attribs)160*8975f5c5SAndroid Build Coastguard Worker SurfaceImpl *DisplayWgpu::createWindowSurface(const egl::SurfaceState &state,
161*8975f5c5SAndroid Build Coastguard Worker                                               EGLNativeWindowType window,
162*8975f5c5SAndroid Build Coastguard Worker                                               const egl::AttributeMap &attribs)
163*8975f5c5SAndroid Build Coastguard Worker {
164*8975f5c5SAndroid Build Coastguard Worker     return CreateWgpuWindowSurface(state, window);
165*8975f5c5SAndroid Build Coastguard Worker }
166*8975f5c5SAndroid Build Coastguard Worker 
createPbufferSurface(const egl::SurfaceState & state,const egl::AttributeMap & attribs)167*8975f5c5SAndroid Build Coastguard Worker SurfaceImpl *DisplayWgpu::createPbufferSurface(const egl::SurfaceState &state,
168*8975f5c5SAndroid Build Coastguard Worker                                                const egl::AttributeMap &attribs)
169*8975f5c5SAndroid Build Coastguard Worker {
170*8975f5c5SAndroid Build Coastguard Worker     return new OffscreenSurfaceWgpu(state);
171*8975f5c5SAndroid Build Coastguard Worker }
172*8975f5c5SAndroid Build Coastguard Worker 
createPbufferFromClientBuffer(const egl::SurfaceState & state,EGLenum buftype,EGLClientBuffer buffer,const egl::AttributeMap & attribs)173*8975f5c5SAndroid Build Coastguard Worker SurfaceImpl *DisplayWgpu::createPbufferFromClientBuffer(const egl::SurfaceState &state,
174*8975f5c5SAndroid Build Coastguard Worker                                                         EGLenum buftype,
175*8975f5c5SAndroid Build Coastguard Worker                                                         EGLClientBuffer buffer,
176*8975f5c5SAndroid Build Coastguard Worker                                                         const egl::AttributeMap &attribs)
177*8975f5c5SAndroid Build Coastguard Worker {
178*8975f5c5SAndroid Build Coastguard Worker     UNIMPLEMENTED();
179*8975f5c5SAndroid Build Coastguard Worker     return nullptr;
180*8975f5c5SAndroid Build Coastguard Worker }
181*8975f5c5SAndroid Build Coastguard Worker 
createPixmapSurface(const egl::SurfaceState & state,NativePixmapType nativePixmap,const egl::AttributeMap & attribs)182*8975f5c5SAndroid Build Coastguard Worker SurfaceImpl *DisplayWgpu::createPixmapSurface(const egl::SurfaceState &state,
183*8975f5c5SAndroid Build Coastguard Worker                                               NativePixmapType nativePixmap,
184*8975f5c5SAndroid Build Coastguard Worker                                               const egl::AttributeMap &attribs)
185*8975f5c5SAndroid Build Coastguard Worker {
186*8975f5c5SAndroid Build Coastguard Worker     UNIMPLEMENTED();
187*8975f5c5SAndroid Build Coastguard Worker     return nullptr;
188*8975f5c5SAndroid Build Coastguard Worker }
189*8975f5c5SAndroid Build Coastguard Worker 
createImage(const egl::ImageState & state,const gl::Context * context,EGLenum target,const egl::AttributeMap & attribs)190*8975f5c5SAndroid Build Coastguard Worker ImageImpl *DisplayWgpu::createImage(const egl::ImageState &state,
191*8975f5c5SAndroid Build Coastguard Worker                                     const gl::Context *context,
192*8975f5c5SAndroid Build Coastguard Worker                                     EGLenum target,
193*8975f5c5SAndroid Build Coastguard Worker                                     const egl::AttributeMap &attribs)
194*8975f5c5SAndroid Build Coastguard Worker {
195*8975f5c5SAndroid Build Coastguard Worker     return new ImageWgpu(state);
196*8975f5c5SAndroid Build Coastguard Worker }
197*8975f5c5SAndroid Build Coastguard Worker 
createContext(const gl::State & state,gl::ErrorSet * errorSet,const egl::Config * configuration,const gl::Context * shareContext,const egl::AttributeMap & attribs)198*8975f5c5SAndroid Build Coastguard Worker rx::ContextImpl *DisplayWgpu::createContext(const gl::State &state,
199*8975f5c5SAndroid Build Coastguard Worker                                             gl::ErrorSet *errorSet,
200*8975f5c5SAndroid Build Coastguard Worker                                             const egl::Config *configuration,
201*8975f5c5SAndroid Build Coastguard Worker                                             const gl::Context *shareContext,
202*8975f5c5SAndroid Build Coastguard Worker                                             const egl::AttributeMap &attribs)
203*8975f5c5SAndroid Build Coastguard Worker {
204*8975f5c5SAndroid Build Coastguard Worker     return new ContextWgpu(state, errorSet, this);
205*8975f5c5SAndroid Build Coastguard Worker }
206*8975f5c5SAndroid Build Coastguard Worker 
createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,const egl::AttributeMap & attribs)207*8975f5c5SAndroid Build Coastguard Worker StreamProducerImpl *DisplayWgpu::createStreamProducerD3DTexture(
208*8975f5c5SAndroid Build Coastguard Worker     egl::Stream::ConsumerType consumerType,
209*8975f5c5SAndroid Build Coastguard Worker     const egl::AttributeMap &attribs)
210*8975f5c5SAndroid Build Coastguard Worker {
211*8975f5c5SAndroid Build Coastguard Worker     UNIMPLEMENTED();
212*8975f5c5SAndroid Build Coastguard Worker     return nullptr;
213*8975f5c5SAndroid Build Coastguard Worker }
214*8975f5c5SAndroid Build Coastguard Worker 
createShareGroup(const egl::ShareGroupState & state)215*8975f5c5SAndroid Build Coastguard Worker ShareGroupImpl *DisplayWgpu::createShareGroup(const egl::ShareGroupState &state)
216*8975f5c5SAndroid Build Coastguard Worker {
217*8975f5c5SAndroid Build Coastguard Worker     return new ShareGroupWgpu(state);
218*8975f5c5SAndroid Build Coastguard Worker }
219*8975f5c5SAndroid Build Coastguard Worker 
getWindowSystem() const220*8975f5c5SAndroid Build Coastguard Worker angle::NativeWindowSystem DisplayWgpu::getWindowSystem() const
221*8975f5c5SAndroid Build Coastguard Worker {
222*8975f5c5SAndroid Build Coastguard Worker #if defined(ANGLE_PLATFORM_LINUX)
223*8975f5c5SAndroid Build Coastguard Worker #    if defined(ANGLE_USE_X11)
224*8975f5c5SAndroid Build Coastguard Worker     return angle::NativeWindowSystem::X11;
225*8975f5c5SAndroid Build Coastguard Worker #    elif defined(ANGLE_USE_WAYLAND)
226*8975f5c5SAndroid Build Coastguard Worker     return angle::NativeWindowSystem::Wayland;
227*8975f5c5SAndroid Build Coastguard Worker #    endif
228*8975f5c5SAndroid Build Coastguard Worker #else
229*8975f5c5SAndroid Build Coastguard Worker     return angle::NativeWindowSystem::Other;
230*8975f5c5SAndroid Build Coastguard Worker #endif
231*8975f5c5SAndroid Build Coastguard Worker }
232*8975f5c5SAndroid Build Coastguard Worker 
generateExtensions(egl::DisplayExtensions * outExtensions) const233*8975f5c5SAndroid Build Coastguard Worker void DisplayWgpu::generateExtensions(egl::DisplayExtensions *outExtensions) const
234*8975f5c5SAndroid Build Coastguard Worker {
235*8975f5c5SAndroid Build Coastguard Worker     *outExtensions = mEGLExtensions;
236*8975f5c5SAndroid Build Coastguard Worker }
237*8975f5c5SAndroid Build Coastguard Worker 
generateCaps(egl::Caps * outCaps) const238*8975f5c5SAndroid Build Coastguard Worker void DisplayWgpu::generateCaps(egl::Caps *outCaps) const
239*8975f5c5SAndroid Build Coastguard Worker {
240*8975f5c5SAndroid Build Coastguard Worker     *outCaps = mEGLCaps;
241*8975f5c5SAndroid Build Coastguard Worker }
242*8975f5c5SAndroid Build Coastguard Worker 
createWgpuDevice()243*8975f5c5SAndroid Build Coastguard Worker egl::Error DisplayWgpu::createWgpuDevice()
244*8975f5c5SAndroid Build Coastguard Worker {
245*8975f5c5SAndroid Build Coastguard Worker     dawnProcSetProcs(&dawn::native::GetProcs());
246*8975f5c5SAndroid Build Coastguard Worker 
247*8975f5c5SAndroid Build Coastguard Worker     dawn::native::DawnInstanceDescriptor dawnInstanceDescriptor;
248*8975f5c5SAndroid Build Coastguard Worker 
249*8975f5c5SAndroid Build Coastguard Worker     wgpu::InstanceDescriptor instanceDescriptor;
250*8975f5c5SAndroid Build Coastguard Worker     instanceDescriptor.features.timedWaitAnyEnable = true;
251*8975f5c5SAndroid Build Coastguard Worker     instanceDescriptor.nextInChain                 = &dawnInstanceDescriptor;
252*8975f5c5SAndroid Build Coastguard Worker     mInstance                                      = wgpu::CreateInstance(&instanceDescriptor);
253*8975f5c5SAndroid Build Coastguard Worker 
254*8975f5c5SAndroid Build Coastguard Worker     struct RequestAdapterResult
255*8975f5c5SAndroid Build Coastguard Worker     {
256*8975f5c5SAndroid Build Coastguard Worker         WGPURequestAdapterStatus status;
257*8975f5c5SAndroid Build Coastguard Worker         wgpu::Adapter adapter;
258*8975f5c5SAndroid Build Coastguard Worker         std::string message;
259*8975f5c5SAndroid Build Coastguard Worker     };
260*8975f5c5SAndroid Build Coastguard Worker     RequestAdapterResult adapterResult;
261*8975f5c5SAndroid Build Coastguard Worker 
262*8975f5c5SAndroid Build Coastguard Worker     wgpu::RequestAdapterOptions requestAdapterOptions;
263*8975f5c5SAndroid Build Coastguard Worker 
264*8975f5c5SAndroid Build Coastguard Worker     wgpu::RequestAdapterCallbackInfo callbackInfo;
265*8975f5c5SAndroid Build Coastguard Worker     callbackInfo.mode     = wgpu::CallbackMode::WaitAnyOnly;
266*8975f5c5SAndroid Build Coastguard Worker     callbackInfo.callback = [](WGPURequestAdapterStatus status, WGPUAdapter adapter,
267*8975f5c5SAndroid Build Coastguard Worker                                char const *message, void *userdata) {
268*8975f5c5SAndroid Build Coastguard Worker         RequestAdapterResult *result = reinterpret_cast<RequestAdapterResult *>(userdata);
269*8975f5c5SAndroid Build Coastguard Worker         result->status               = status;
270*8975f5c5SAndroid Build Coastguard Worker         result->adapter              = wgpu::Adapter::Acquire(adapter);
271*8975f5c5SAndroid Build Coastguard Worker         result->message              = message ? message : "";
272*8975f5c5SAndroid Build Coastguard Worker     };
273*8975f5c5SAndroid Build Coastguard Worker     callbackInfo.userdata = &adapterResult;
274*8975f5c5SAndroid Build Coastguard Worker 
275*8975f5c5SAndroid Build Coastguard Worker     wgpu::FutureWaitInfo futureWaitInfo;
276*8975f5c5SAndroid Build Coastguard Worker     futureWaitInfo.future = mInstance.RequestAdapter(&requestAdapterOptions, callbackInfo);
277*8975f5c5SAndroid Build Coastguard Worker 
278*8975f5c5SAndroid Build Coastguard Worker     wgpu::WaitStatus status = mInstance.WaitAny(1, &futureWaitInfo, -1);
279*8975f5c5SAndroid Build Coastguard Worker     if (webgpu::IsWgpuError(status))
280*8975f5c5SAndroid Build Coastguard Worker     {
281*8975f5c5SAndroid Build Coastguard Worker         return egl::EglBadAlloc() << "Failed to get WebGPU adapter: " << adapterResult.message;
282*8975f5c5SAndroid Build Coastguard Worker     }
283*8975f5c5SAndroid Build Coastguard Worker 
284*8975f5c5SAndroid Build Coastguard Worker     mAdapter = adapterResult.adapter;
285*8975f5c5SAndroid Build Coastguard Worker 
286*8975f5c5SAndroid Build Coastguard Worker     std::vector<wgpu::FeatureName> requiredFeatures;  // empty for now
287*8975f5c5SAndroid Build Coastguard Worker 
288*8975f5c5SAndroid Build Coastguard Worker     wgpu::DeviceDescriptor deviceDesc;
289*8975f5c5SAndroid Build Coastguard Worker     deviceDesc.requiredFeatureCount = requiredFeatures.size();
290*8975f5c5SAndroid Build Coastguard Worker     deviceDesc.requiredFeatures     = requiredFeatures.data();
291*8975f5c5SAndroid Build Coastguard Worker 
292*8975f5c5SAndroid Build Coastguard Worker     mDevice = mAdapter.CreateDevice(&deviceDesc);
293*8975f5c5SAndroid Build Coastguard Worker     mDevice.SetUncapturedErrorCallback(
294*8975f5c5SAndroid Build Coastguard Worker         [](WGPUErrorType type, const char *message, void *userdata) {
295*8975f5c5SAndroid Build Coastguard Worker             ERR() << "Error: " << type << " - message: " << message;
296*8975f5c5SAndroid Build Coastguard Worker         },
297*8975f5c5SAndroid Build Coastguard Worker         nullptr);
298*8975f5c5SAndroid Build Coastguard Worker     return egl::NoError();
299*8975f5c5SAndroid Build Coastguard Worker }
300*8975f5c5SAndroid Build Coastguard Worker 
CreateWgpuDisplay(const egl::DisplayState & state)301*8975f5c5SAndroid Build Coastguard Worker DisplayImpl *CreateWgpuDisplay(const egl::DisplayState &state)
302*8975f5c5SAndroid Build Coastguard Worker {
303*8975f5c5SAndroid Build Coastguard Worker     return new DisplayWgpu(state);
304*8975f5c5SAndroid Build Coastguard Worker }
305*8975f5c5SAndroid Build Coastguard Worker 
306*8975f5c5SAndroid Build Coastguard Worker }  // namespace rx
307