Hash :
3f170c17
Author :
Date :
2025-07-11T15:35:01
Roll third_party/dawn/ (1684 commits) and clean up WGPU_BREAKING_CHANGEs With this roll, Dawn has completed the WGPU_BREAKING_CHANGE_* changes, so the old paths are no longer used. The roll: https://dawn.googlesource.com/dawn.git/+log/7a8946456d49..d85fc050fef7 Created with: roll-dep third_party/dawn Bug: chromium:427242889 Change-Id: Ia17fbc1447944e7bcea20d5004367d94cf7be10e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6729918 Commit-Queue: Geoff Lang <geofflang@chromium.org> Auto-Submit: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayWgpu.cpp:
// Implements the class methods for DisplayWgpu.
//
#include "libANGLE/renderer/wgpu/DisplayWgpu.h"
#include <dawn/dawn_proc.h>
#include "common/debug.h"
#include "common/platform.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/wgpu/ContextWgpu.h"
#include "libANGLE/renderer/wgpu/DeviceWgpu.h"
#include "libANGLE/renderer/wgpu/DisplayWgpu_api.h"
#include "libANGLE/renderer/wgpu/ImageWgpu.h"
#include "libANGLE/renderer/wgpu/SurfaceWgpu.h"
#include "libANGLE/renderer/wgpu/wgpu_proc_utils.h"
#if defined(ANGLE_PLATFORM_LINUX)
# if defined(ANGLE_USE_X11)
# define ANGLE_WEBGPU_HAS_WINDOW_SURFACE_TYPE 1
# define ANGLE_WEBGPU_WINDOW_SYSTEM angle::NativeWindowSystem::X11
# elif defined(ANGLE_USE_WAYLAND)
# define ANGLE_WEBGPU_HAS_WINDOW_SURFACE_TYPE 1
# define ANGLE_WEBGPU_WINDOW_SYSTEM angle::NativeWindowSystem::Wayland
# else
# define ANGLE_WEBGPU_HAS_WINDOW_SURFACE_TYPE 0
# define ANGLE_WEBGPU_WINDOW_SYSTEM angle::NativeWindowSystem::Other
# endif
#else
# define ANGLE_WEBGPU_HAS_WINDOW_SURFACE_TYPE 1
# define ANGLE_WEBGPU_WINDOW_SYSTEM angle::NativeWindowSystem::Other
#endif
namespace rx
{
#if !ANGLE_WEBGPU_HAS_WINDOW_SURFACE_TYPE
WindowSurfaceWgpu *CreateWgpuWindowSurface(const egl::SurfaceState &surfaceState,
EGLNativeWindowType window)
{
UNIMPLEMENTED();
return nullptr;
}
#endif
DisplayWgpu::DisplayWgpu(const egl::DisplayState &state) : DisplayImpl(state) {}
DisplayWgpu::~DisplayWgpu() {}
egl::Error DisplayWgpu::initialize(egl::Display *display)
{
const egl::AttributeMap &attribs = display->getAttributeMap();
mProcTable = *reinterpret_cast<DawnProcTable *>(
attribs.get(EGL_PLATFORM_ANGLE_DAWN_PROC_TABLE_ANGLE,
reinterpret_cast<EGLAttrib>(&webgpu::GetDefaultProcTable())));
WGPUDevice providedDevice =
reinterpret_cast<WGPUDevice>(attribs.get(EGL_PLATFORM_ANGLE_WEBGPU_DEVICE_ANGLE, 0));
if (providedDevice)
{
mProcTable.deviceAddRef(providedDevice);
mDevice = webgpu::DeviceHandle::Acquire(&mProcTable, providedDevice);
mAdapter =
webgpu::AdapterHandle::Acquire(&mProcTable, mProcTable.deviceGetAdapter(mDevice.get()));
mInstance = webgpu::InstanceHandle::Acquire(&mProcTable,
mProcTable.adapterGetInstance(mAdapter.get()));
}
else
{
ANGLE_TRY(createWgpuDevice());
}
mQueue = webgpu::QueueHandle::Acquire(&mProcTable, mProcTable.deviceGetQueue(mDevice.get()));
mFormatTable.initialize();
mLimitsWgpu = WGPU_LIMITS_INIT;
mProcTable.deviceGetLimits(mDevice.get(), &mLimitsWgpu);
initializeFeatures();
webgpu::GenerateCaps(mLimitsWgpu, &mGLCaps, &mGLTextureCaps, &mGLExtensions, &mGLLimitations,
&mEGLCaps, &mEGLExtensions, &mMaxSupportedClientVersion);
return egl::NoError();
}
void DisplayWgpu::terminate()
{
mAdapter = nullptr;
mInstance = nullptr;
mDevice = nullptr;
mQueue = nullptr;
}
egl::Error DisplayWgpu::makeCurrent(egl::Display *display,
egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context)
{
// Ensure that the correct global DebugAnnotator is installed when the end2end tests change
// the ANGLE back-end (done frequently).
display->setGlobalDebugAnnotator();
return egl::NoError();
}
egl::ConfigSet DisplayWgpu::generateConfigs()
{
egl::Config config;
config.renderTargetFormat = GL_BGRA8_EXT;
config.depthStencilFormat = GL_DEPTH24_STENCIL8;
config.bufferSize = 32;
config.redSize = 8;
config.greenSize = 8;
config.blueSize = 8;
config.alphaSize = 8;
config.alphaMaskSize = 0;
config.bindToTextureRGB = EGL_FALSE;
config.bindToTextureRGBA = EGL_FALSE;
config.colorBufferType = EGL_RGB_BUFFER;
config.configCaveat = EGL_NONE;
config.conformant = EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT;
config.depthSize = 24;
config.level = 0;
config.matchNativePixmap = EGL_NONE;
config.maxPBufferWidth = 0;
config.maxPBufferHeight = 0;
config.maxPBufferPixels = 0;
config.maxSwapInterval = 1;
config.minSwapInterval = 1;
config.nativeRenderable = EGL_TRUE;
config.nativeVisualID = 0;
config.nativeVisualType = EGL_NONE;
config.renderableType = EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT;
config.sampleBuffers = 0;
config.samples = 0;
config.stencilSize = 8;
config.surfaceType = EGL_PBUFFER_BIT;
#if ANGLE_WEBGPU_HAS_WINDOW_SURFACE_TYPE
config.surfaceType |= EGL_WINDOW_BIT;
#endif
config.optimalOrientation = 0;
config.transparentType = EGL_NONE;
config.transparentRedValue = 0;
config.transparentGreenValue = 0;
config.transparentBlueValue = 0;
egl::ConfigSet configSet;
configSet.add(config);
return configSet;
}
bool DisplayWgpu::testDeviceLost()
{
return false;
}
egl::Error DisplayWgpu::restoreLostDevice(const egl::Display *display)
{
return egl::NoError();
}
egl::Error DisplayWgpu::validateClientBuffer(const egl::Config *configuration,
EGLenum buftype,
EGLClientBuffer clientBuffer,
const egl::AttributeMap &attribs) const
{
switch (buftype)
{
case EGL_WEBGPU_TEXTURE_ANGLE:
return validateExternalWebGPUTexture(clientBuffer, attribs);
default:
return DisplayImpl::validateClientBuffer(configuration, buftype, clientBuffer, attribs);
}
}
egl::Error DisplayWgpu::validateImageClientBuffer(const gl::Context *context,
EGLenum target,
EGLClientBuffer clientBuffer,
const egl::AttributeMap &attribs) const
{
switch (target)
{
case EGL_WEBGPU_TEXTURE_ANGLE:
return validateExternalWebGPUTexture(clientBuffer, attribs);
default:
return DisplayImpl::validateImageClientBuffer(context, target, clientBuffer, attribs);
}
}
egl::Error DisplayWgpu::validateExternalWebGPUTexture(EGLClientBuffer buffer,
const egl::AttributeMap &attribs) const
{
WGPUTexture externalTexture = reinterpret_cast<WGPUTexture>(buffer);
if (externalTexture == nullptr)
{
return egl::Error(EGL_BAD_PARAMETER, "NULL Buffer");
}
WGPUTextureFormat externalTextureFormat = mProcTable.textureGetFormat(externalTexture);
const webgpu::Format *webgpuFormat =
getFormatForImportedTexture(attribs, externalTextureFormat);
if (webgpuFormat == nullptr)
{
return egl::Error(EGL_BAD_PARAMETER, "Invalid format.");
}
return egl::NoError();
}
bool DisplayWgpu::isValidNativeWindow(EGLNativeWindowType window) const
{
return true;
}
std::string DisplayWgpu::getRendererDescription()
{
return "WebGPU";
}
std::string DisplayWgpu::getVendorString()
{
return "WebGPU";
}
std::string DisplayWgpu::getVersionString(bool includeFullVersion)
{
return std::string();
}
DeviceImpl *DisplayWgpu::createDevice()
{
return new DeviceWgpu();
}
egl::Error DisplayWgpu::waitClient(const gl::Context *context)
{
return egl::NoError();
}
egl::Error DisplayWgpu::waitNative(const gl::Context *context, EGLint engine)
{
return egl::NoError();
}
gl::Version DisplayWgpu::getMaxSupportedESVersion() const
{
return mMaxSupportedClientVersion;
}
gl::Version DisplayWgpu::getMaxConformantESVersion() const
{
return mMaxSupportedClientVersion;
}
SurfaceImpl *DisplayWgpu::createWindowSurface(const egl::SurfaceState &state,
EGLNativeWindowType window,
const egl::AttributeMap &attribs)
{
return CreateWgpuWindowSurface(state, window);
}
SurfaceImpl *DisplayWgpu::createPbufferSurface(const egl::SurfaceState &state,
const egl::AttributeMap &attribs)
{
return new OffscreenSurfaceWgpu(state, EGL_NONE, nullptr);
}
SurfaceImpl *DisplayWgpu::createPbufferFromClientBuffer(const egl::SurfaceState &state,
EGLenum buftype,
EGLClientBuffer buffer,
const egl::AttributeMap &attribs)
{
return new OffscreenSurfaceWgpu(state, buftype, buffer);
}
SurfaceImpl *DisplayWgpu::createPixmapSurface(const egl::SurfaceState &state,
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return nullptr;
}
ImageImpl *DisplayWgpu::createImage(const egl::ImageState &state,
const gl::Context *context,
EGLenum target,
const egl::AttributeMap &attribs)
{
return new ImageWgpu(state, context);
}
ExternalImageSiblingImpl *DisplayWgpu::createExternalImageSibling(const gl::Context *context,
EGLenum target,
EGLClientBuffer buffer,
const egl::AttributeMap &attribs)
{
switch (target)
{
case EGL_WEBGPU_TEXTURE_ANGLE:
return new WebGPUTextureImageSiblingWgpu(buffer, attribs);
default:
return DisplayImpl::createExternalImageSibling(context, target, buffer, attribs);
}
}
rx::ContextImpl *DisplayWgpu::createContext(const gl::State &state,
gl::ErrorSet *errorSet,
const egl::Config *configuration,
const gl::Context *shareContext,
const egl::AttributeMap &attribs)
{
return new ContextWgpu(state, errorSet, this);
}
StreamProducerImpl *DisplayWgpu::createStreamProducerD3DTexture(
egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return nullptr;
}
ShareGroupImpl *DisplayWgpu::createShareGroup(const egl::ShareGroupState &state)
{
return new ShareGroupWgpu(state);
}
void DisplayWgpu::populateFeatureList(angle::FeatureList *features)
{
mFeatures.populateFeatureList(features);
}
angle::NativeWindowSystem DisplayWgpu::getWindowSystem() const
{
return ANGLE_WEBGPU_WINDOW_SYSTEM;
}
const webgpu::Format *DisplayWgpu::getFormatForImportedTexture(const egl::AttributeMap &attribs,
WGPUTextureFormat wgpuFormat) const
{
GLenum requestedGLFormat = attribs.getAsInt(EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, GL_NONE);
GLenum requestedGLType = attribs.getAsInt(EGL_TEXTURE_TYPE_ANGLE, GL_NONE);
if (requestedGLFormat != GL_NONE)
{
const gl::InternalFormat &internalFormat =
gl::GetInternalFormatInfo(requestedGLFormat, requestedGLType);
if (internalFormat.internalFormat == GL_NONE)
{
return nullptr;
}
const webgpu::Format &format = mFormatTable[internalFormat.sizedInternalFormat];
if (format.getActualWgpuTextureFormat() != wgpuFormat)
{
return nullptr;
}
return &format;
}
else
{
return mFormatTable.findClosestTextureFormat(wgpuFormat);
}
}
void DisplayWgpu::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
*outExtensions = mEGLExtensions;
}
void DisplayWgpu::generateCaps(egl::Caps *outCaps) const
{
*outCaps = mEGLCaps;
}
void DisplayWgpu::initializeFeatures()
{
ApplyFeatureOverrides(&mFeatures, getState().featureOverrides);
if (mState.featureOverrides.allDisabled)
{
return;
}
// Disabled by default. Gets explicitly enabled by ANGLE embedders.
ANGLE_FEATURE_CONDITION((&mFeatures), avoidWaitAny, false);
}
egl::Error DisplayWgpu::createWgpuDevice()
{
WGPUInstanceDescriptor instanceDescriptor = WGPU_INSTANCE_DESCRIPTOR_INIT;
static constexpr auto kTimedWaitAny = WGPUInstanceFeatureName_TimedWaitAny;
instanceDescriptor.requiredFeatureCount = 1;
instanceDescriptor.requiredFeatures = &kTimedWaitAny;
mInstance = webgpu::InstanceHandle::Acquire(&mProcTable,
mProcTable.createInstance(&instanceDescriptor));
struct RequestAdapterResult
{
WGPURequestAdapterStatus status;
webgpu::AdapterHandle adapter;
std::string message;
};
RequestAdapterResult adapterResult;
WGPURequestAdapterOptions requestAdapterOptions = WGPU_REQUEST_ADAPTER_OPTIONS_INIT;
WGPURequestAdapterCallbackInfo requestAdapterCallback = WGPU_REQUEST_ADAPTER_CALLBACK_INFO_INIT;
requestAdapterCallback.mode = WGPUCallbackMode_WaitAnyOnly;
requestAdapterCallback.callback = [](WGPURequestAdapterStatus status, WGPUAdapter adapter,
struct WGPUStringView message, void *userdata1,
void *userdata2) {
RequestAdapterResult *result = reinterpret_cast<RequestAdapterResult *>(userdata1);
const DawnProcTable *wgpu = reinterpret_cast<const DawnProcTable *>(userdata2);
result->status = status;
result->adapter = webgpu::AdapterHandle::Acquire(wgpu, adapter);
result->message = std::string(message.data, message.length);
};
requestAdapterCallback.userdata1 = &adapterResult;
requestAdapterCallback.userdata2 = &mProcTable;
WGPUFutureWaitInfo futureWaitInfo;
futureWaitInfo.future = mProcTable.instanceRequestAdapter(
mInstance.get(), &requestAdapterOptions, requestAdapterCallback);
WGPUWaitStatus status = mProcTable.instanceWaitAny(mInstance.get(), 1, &futureWaitInfo, -1);
if (webgpu::IsWgpuError(status))
{
std::ostringstream err;
err << "Failed to get WebGPU adapter: " << adapterResult.message;
return egl::Error(EGL_BAD_ALLOC, err.str());
}
mAdapter = adapterResult.adapter;
std::vector<WGPUFeatureName> requiredFeatures; // empty for now
WGPUDeviceDescriptor deviceDesc = WGPU_DEVICE_DESCRIPTOR_INIT;
deviceDesc.requiredFeatureCount = requiredFeatures.size();
deviceDesc.requiredFeatures = requiredFeatures.data();
deviceDesc.uncapturedErrorCallbackInfo.callback =
[](WGPUDevice const *device, WGPUErrorType type, struct WGPUStringView message,
void *userdata1, void *userdata2) {
ASSERT(userdata1 == nullptr);
ASSERT(userdata2 == nullptr);
ERR() << "Error: " << static_cast<std::underlying_type<WGPUErrorType>::type>(type)
<< " - message: " << std::string(message.data, message.length);
};
mDevice = webgpu::DeviceHandle::Acquire(
&mProcTable, mProcTable.adapterCreateDevice(mAdapter.get(), &deviceDesc));
return egl::NoError();
}
DisplayImpl *CreateWgpuDisplay(const egl::DisplayState &state)
{
return new DisplayWgpu(state);
}
} // namespace rx