Hash :
4a835cf2
Author :
Date :
2024-11-01T13:31:00
WebGPU: send uniforms to GPU for use in shader Basic uniforms should now be accessible in the shader during a draw call, rather than just via glGetUniform*(). This is unoptimized and creates a new GPU-side copy of all the uniforms, every time any uniform changes. This sets up the bind group layout for a pipeline and sets the bind groups in the renderer pass. Right now these bind groups only contain the default uniform blocks, but in the future will need to contain textures, samplers, and non-default uniform blocks (UBOs). Bug: angleproject:376553328 Change-Id: I50891b81ab2ee374d674213257f76319c0222120 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5980972 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Liza Burakova <liza@chromium.org> Commit-Queue: Matthew Denton <mpdenton@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
//
// 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"
namespace rx
{
DisplayWgpu::DisplayWgpu(const egl::DisplayState &state) : DisplayImpl(state) {}
DisplayWgpu::~DisplayWgpu() {}
egl::Error DisplayWgpu::initialize(egl::Display *display)
{
ANGLE_TRY(createWgpuDevice());
mQueue = mDevice.GetQueue();
mFormatTable.initialize();
wgpu::SupportedLimits supportedLimits;
mDevice.GetLimits(&supportedLimits);
mLimitsWgpu = supportedLimits.limits;
webgpu::GenerateCaps(mLimitsWgpu, &mGLCaps, &mGLTextureCaps, &mGLExtensions, &mGLLimitations,
&mEGLCaps, &mEGLExtensions, &mMaxSupportedClientVersion);
return egl::NoError();
}
void DisplayWgpu::terminate() {}
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_TRUE;
config.bindToTextureRGBA = EGL_TRUE;
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_WINDOW_BIT | EGL_PBUFFER_BIT;
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();
}
bool DisplayWgpu::isValidNativeWindow(EGLNativeWindowType window) const
{
return true;
}
std::string DisplayWgpu::getRendererDescription()
{
return "Wgpu";
}
std::string DisplayWgpu::getVendorString()
{
return "Wgpu";
}
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);
}
SurfaceImpl *DisplayWgpu::createPbufferFromClientBuffer(const egl::SurfaceState &state,
EGLenum buftype,
EGLClientBuffer buffer,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return nullptr;
}
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);
}
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);
}
angle::NativeWindowSystem DisplayWgpu::getWindowSystem() const
{
#if defined(ANGLE_PLATFORM_LINUX)
# if defined(ANGLE_USE_X11)
return angle::NativeWindowSystem::X11;
# elif defined(ANGLE_USE_WAYLAND)
return angle::NativeWindowSystem::Wayland;
# endif
#else
return angle::NativeWindowSystem::Other;
#endif
}
void DisplayWgpu::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
*outExtensions = mEGLExtensions;
}
void DisplayWgpu::generateCaps(egl::Caps *outCaps) const
{
*outCaps = mEGLCaps;
}
egl::Error DisplayWgpu::createWgpuDevice()
{
dawnProcSetProcs(&dawn::native::GetProcs());
dawn::native::DawnInstanceDescriptor dawnInstanceDescriptor;
wgpu::InstanceDescriptor instanceDescriptor;
instanceDescriptor.features.timedWaitAnyEnable = true;
instanceDescriptor.nextInChain = &dawnInstanceDescriptor;
mInstance = wgpu::CreateInstance(&instanceDescriptor);
struct RequestAdapterResult
{
WGPURequestAdapterStatus status;
wgpu::Adapter adapter;
std::string message;
};
RequestAdapterResult adapterResult;
wgpu::RequestAdapterOptions requestAdapterOptions;
wgpu::RequestAdapterCallbackInfo callbackInfo;
callbackInfo.mode = wgpu::CallbackMode::WaitAnyOnly;
callbackInfo.callback = [](WGPURequestAdapterStatus status, WGPUAdapter adapter,
char const *message, void *userdata) {
RequestAdapterResult *result = reinterpret_cast<RequestAdapterResult *>(userdata);
result->status = status;
result->adapter = wgpu::Adapter::Acquire(adapter);
result->message = message ? message : "";
};
callbackInfo.userdata = &adapterResult;
wgpu::FutureWaitInfo futureWaitInfo;
futureWaitInfo.future = mInstance.RequestAdapter(&requestAdapterOptions, callbackInfo);
wgpu::WaitStatus status = mInstance.WaitAny(1, &futureWaitInfo, -1);
if (webgpu::IsWgpuError(status))
{
return egl::EglBadAlloc() << "Failed to get WebGPU adapter: " << adapterResult.message;
}
mAdapter = adapterResult.adapter;
std::vector<wgpu::FeatureName> requiredFeatures; // empty for now
wgpu::DeviceDescriptor deviceDesc;
deviceDesc.requiredFeatureCount = requiredFeatures.size();
deviceDesc.requiredFeatures = requiredFeatures.data();
mDevice = mAdapter.CreateDevice(&deviceDesc);
mDevice.SetUncapturedErrorCallback(
[](WGPUErrorType type, const char *message, void *userdata) {
ERR() << "Error: " << type << " - message: " << message;
},
nullptr);
return egl::NoError();
}
DisplayImpl *CreateWgpuDisplay(const egl::DisplayState &state)
{
return new DisplayWgpu(state);
}
} // namespace rx