Hash :
041b0a4d
Author :
Date :
2024-04-15T13:42:17
Begin initializing caps for webgpu Bug: angleproject:8457 Change-Id: Idde0673297ec675a13bd3e4fd4d220ec47392153 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5391987 Reviewed-by: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Liza Burakova <liza@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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
//
// 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.
//
// ContextWgpu.cpp:
// Implements the class methods for ContextWgpu.
//
#include "libANGLE/renderer/wgpu/ContextWgpu.h"
#include "common/debug.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/OverlayImpl.h"
#include "libANGLE/renderer/wgpu/BufferWgpu.h"
#include "libANGLE/renderer/wgpu/CompilerWgpu.h"
#include "libANGLE/renderer/wgpu/DisplayWgpu.h"
#include "libANGLE/renderer/wgpu/FenceNVWgpu.h"
#include "libANGLE/renderer/wgpu/FramebufferWgpu.h"
#include "libANGLE/renderer/wgpu/ImageWgpu.h"
#include "libANGLE/renderer/wgpu/ProgramExecutableWgpu.h"
#include "libANGLE/renderer/wgpu/ProgramPipelineWgpu.h"
#include "libANGLE/renderer/wgpu/ProgramWgpu.h"
#include "libANGLE/renderer/wgpu/QueryWgpu.h"
#include "libANGLE/renderer/wgpu/RenderbufferWgpu.h"
#include "libANGLE/renderer/wgpu/SamplerWgpu.h"
#include "libANGLE/renderer/wgpu/ShaderWgpu.h"
#include "libANGLE/renderer/wgpu/SyncWgpu.h"
#include "libANGLE/renderer/wgpu/TextureWgpu.h"
#include "libANGLE/renderer/wgpu/TransformFeedbackWgpu.h"
#include "libANGLE/renderer/wgpu/VertexArrayWgpu.h"
#include "libANGLE/renderer/wgpu/wgpu_utils.h"
namespace rx
{
namespace
{
constexpr angle::PackedEnumMap<webgpu::RenderPassClosureReason, const char *>
kRenderPassClosureReason = {{
{webgpu::RenderPassClosureReason::NewRenderPass,
"Render pass closed due to starting a new render pass"},
}};
bool RenderPassColorAttachmentEqual(const wgpu::RenderPassColorAttachment &attachment1,
const wgpu::RenderPassColorAttachment &attachment2)
{
if (attachment1.nextInChain != nullptr || attachment2.nextInChain != nullptr)
{
return false;
}
return attachment1.view.Get() == attachment2.view.Get() &&
attachment1.depthSlice == attachment2.depthSlice &&
attachment1.resolveTarget.Get() == attachment2.resolveTarget.Get() &&
attachment1.loadOp == attachment2.loadOp && attachment1.storeOp == attachment2.storeOp &&
attachment1.clearValue.r == attachment2.clearValue.r &&
attachment1.clearValue.g == attachment2.clearValue.g &&
attachment1.clearValue.b == attachment2.clearValue.b &&
attachment1.clearValue.a == attachment2.clearValue.a;
}
bool RenderPassDepthStencilAttachmentEqual(
const wgpu::RenderPassDepthStencilAttachment &attachment1,
const wgpu::RenderPassDepthStencilAttachment &attachment2)
{
return attachment1.view.Get() == attachment2.view.Get() &&
attachment1.depthLoadOp == attachment2.depthLoadOp &&
attachment1.depthStoreOp == attachment2.depthStoreOp &&
attachment1.depthClearValue == attachment2.depthClearValue &&
attachment1.stencilLoadOp == attachment2.stencilLoadOp &&
attachment1.stencilStoreOp == attachment2.stencilStoreOp &&
attachment1.stencilClearValue == attachment2.stencilClearValue &&
attachment1.stencilReadOnly == attachment2.stencilReadOnly;
}
bool RenderPassDescEqual(const wgpu::RenderPassDescriptor &desc1,
const wgpu::RenderPassDescriptor &desc2)
{
if (desc1.nextInChain != nullptr || desc2.nextInChain != nullptr)
{
return false;
}
if (desc1.colorAttachmentCount != desc2.colorAttachmentCount)
{
return false;
}
for (uint32_t i = 0; i < desc1.colorAttachmentCount; ++i)
{
if (!RenderPassColorAttachmentEqual(desc1.colorAttachments[i], desc2.colorAttachments[i]))
{
return false;
}
}
// TODO(anglebug.com/8582): for now ignore `occlusionQuerySet` and `timestampWrites`.
return RenderPassDepthStencilAttachmentEqual(*desc1.depthStencilAttachment,
*desc2.depthStencilAttachment);
}
} // namespace
ContextWgpu::ContextWgpu(const gl::State &state, gl::ErrorSet *errorSet, DisplayWgpu *display)
: ContextImpl(state, errorSet), mDisplay(display)
{
mExtensions = gl::Extensions();
mExtensions.blendEquationAdvancedKHR = true;
mExtensions.blendFuncExtendedEXT = true;
mExtensions.copyCompressedTextureCHROMIUM = true;
mExtensions.copyTextureCHROMIUM = true;
mExtensions.debugMarkerEXT = true;
mExtensions.drawBuffersIndexedOES = true;
mExtensions.fenceNV = true;
mExtensions.framebufferBlitANGLE = true;
mExtensions.framebufferBlitNV = true;
mExtensions.instancedArraysANGLE = true;
mExtensions.instancedArraysEXT = true;
mExtensions.mapBufferRangeEXT = true;
mExtensions.mapbufferOES = true;
mExtensions.pixelBufferObjectNV = true;
mExtensions.shaderPixelLocalStorageANGLE = state.getClientVersion() >= gl::Version(3, 0);
mExtensions.shaderPixelLocalStorageCoherentANGLE = mExtensions.shaderPixelLocalStorageANGLE;
mExtensions.textureRectangleANGLE = true;
mExtensions.textureUsageANGLE = true;
mExtensions.translatedShaderSourceANGLE = true;
mExtensions.vertexArrayObjectOES = true;
mExtensions.textureStorageEXT = true;
mExtensions.rgb8Rgba8OES = true;
mExtensions.textureCompressionDxt1EXT = true;
mExtensions.textureCompressionDxt3ANGLE = true;
mExtensions.textureCompressionDxt5ANGLE = true;
mExtensions.textureCompressionS3tcSrgbEXT = true;
mExtensions.textureCompressionAstcHdrKHR = true;
mExtensions.textureCompressionAstcLdrKHR = true;
mExtensions.textureCompressionAstcOES = true;
mExtensions.compressedETC1RGB8TextureOES = true;
mExtensions.compressedETC1RGB8SubTextureEXT = true;
mExtensions.lossyEtcDecodeANGLE = true;
mExtensions.geometryShaderEXT = true;
mExtensions.geometryShaderOES = true;
mExtensions.multiDrawIndirectEXT = true;
mExtensions.EGLImageOES = true;
mExtensions.EGLImageExternalOES = true;
mExtensions.EGLImageExternalEssl3OES = true;
mExtensions.EGLImageArrayEXT = true;
mExtensions.EGLStreamConsumerExternalNV = true;
const gl::Version maxClientVersion(3, 1);
mCaps = GenerateMinimumCaps(maxClientVersion, mExtensions);
InitMinimumTextureCapsMap(maxClientVersion, mExtensions, &mTextureCaps);
webgpu::EnsureCapsInitialized(mDisplay->getDevice(), &mCaps);
if (mExtensions.shaderPixelLocalStorageANGLE)
{
mPLSOptions.type = ShPixelLocalStorageType::FramebufferFetch;
mPLSOptions.fragmentSyncType = ShFragmentSynchronizationType::Automatic;
}
}
ContextWgpu::~ContextWgpu() {}
void ContextWgpu::onDestroy(const gl::Context *context)
{
mImageLoadContext = {};
}
angle::Result ContextWgpu::initialize(const angle::ImageLoadContext &imageLoadContext)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::flush(const gl::Context *context)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::finish(const gl::Context *context)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawArrays(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawArraysInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawArraysInstancedBaseInstance(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count,
GLsizei instanceCount,
GLuint baseInstance)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawElementsBaseVertex(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLint baseVertex)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawElementsInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLsizei instances)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawElementsInstancedBaseVertex(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLsizei instances,
GLint baseVertex)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLsizei instances,
GLint baseVertex,
GLuint baseInstance)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawRangeElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
gl::DrawElementsType type,
const void *indices)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawRangeElementsBaseVertex(const gl::Context *context,
gl::PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLint baseVertex)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawArraysIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
const void *indirect)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::drawElementsIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
gl::DrawElementsType type,
const void *indirect)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::multiDrawArrays(const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
GLsizei drawcount)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::multiDrawArraysInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
const GLsizei *instanceCounts,
GLsizei drawcount)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::multiDrawArraysIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
const void *indirect,
GLsizei drawcount,
GLsizei stride)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::multiDrawElements(const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
GLsizei drawcount)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::multiDrawElementsInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
const GLsizei *instanceCounts,
GLsizei drawcount)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::multiDrawElementsIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
gl::DrawElementsType type,
const void *indirect,
GLsizei drawcount,
GLsizei stride)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::multiDrawArraysInstancedBaseInstance(const gl::Context *context,
gl::PrimitiveMode mode,
const GLint *firsts,
const GLsizei *counts,
const GLsizei *instanceCounts,
const GLuint *baseInstances,
GLsizei drawcount)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::multiDrawElementsInstancedBaseVertexBaseInstance(
const gl::Context *context,
gl::PrimitiveMode mode,
const GLsizei *counts,
gl::DrawElementsType type,
const GLvoid *const *indices,
const GLsizei *instanceCounts,
const GLint *baseVertices,
const GLuint *baseInstances,
GLsizei drawcount)
{
return angle::Result::Continue;
}
gl::GraphicsResetStatus ContextWgpu::getResetStatus()
{
return gl::GraphicsResetStatus::NoError;
}
angle::Result ContextWgpu::insertEventMarker(GLsizei length, const char *marker)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::pushGroupMarker(GLsizei length, const char *marker)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::popGroupMarker()
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::pushDebugGroup(const gl::Context *context,
GLenum source,
GLuint id,
const std::string &message)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::popDebugGroup(const gl::Context *context)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::syncState(const gl::Context *context,
const gl::state::DirtyBits dirtyBits,
const gl::state::DirtyBits bitMask,
const gl::state::ExtendedDirtyBits extendedDirtyBits,
const gl::state::ExtendedDirtyBits extendedBitMask,
gl::Command command)
{
return angle::Result::Continue;
}
GLint ContextWgpu::getGPUDisjoint()
{
return 0;
}
GLint64 ContextWgpu::getTimestamp()
{
return 0;
}
angle::Result ContextWgpu::onMakeCurrent(const gl::Context *context)
{
return angle::Result::Continue;
}
gl::Caps ContextWgpu::getNativeCaps() const
{
return mCaps;
}
const gl::TextureCapsMap &ContextWgpu::getNativeTextureCaps() const
{
return mTextureCaps;
}
const gl::Extensions &ContextWgpu::getNativeExtensions() const
{
return mExtensions;
}
const gl::Limitations &ContextWgpu::getNativeLimitations() const
{
return mLimitations;
}
const ShPixelLocalStorageOptions &ContextWgpu::getNativePixelLocalStorageOptions() const
{
return mPLSOptions;
}
CompilerImpl *ContextWgpu::createCompiler()
{
return new CompilerWgpu();
}
ShaderImpl *ContextWgpu::createShader(const gl::ShaderState &data)
{
return new ShaderWgpu(data);
}
ProgramImpl *ContextWgpu::createProgram(const gl::ProgramState &data)
{
return new ProgramWgpu(data);
}
ProgramExecutableImpl *ContextWgpu::createProgramExecutable(const gl::ProgramExecutable *executable)
{
return new ProgramExecutableWgpu(executable);
}
FramebufferImpl *ContextWgpu::createFramebuffer(const gl::FramebufferState &data)
{
return new FramebufferWgpu(data);
}
TextureImpl *ContextWgpu::createTexture(const gl::TextureState &state)
{
return new TextureWgpu(state);
}
RenderbufferImpl *ContextWgpu::createRenderbuffer(const gl::RenderbufferState &state)
{
return new RenderbufferWgpu(state);
}
BufferImpl *ContextWgpu::createBuffer(const gl::BufferState &state)
{
return new BufferWgpu(state);
}
VertexArrayImpl *ContextWgpu::createVertexArray(const gl::VertexArrayState &data)
{
return new VertexArrayWgpu(data);
}
QueryImpl *ContextWgpu::createQuery(gl::QueryType type)
{
return new QueryWgpu(type);
}
FenceNVImpl *ContextWgpu::createFenceNV()
{
return new FenceNVWgpu();
}
SyncImpl *ContextWgpu::createSync()
{
return new SyncWgpu();
}
TransformFeedbackImpl *ContextWgpu::createTransformFeedback(const gl::TransformFeedbackState &state)
{
return new TransformFeedbackWgpu(state);
}
SamplerImpl *ContextWgpu::createSampler(const gl::SamplerState &state)
{
return new SamplerWgpu(state);
}
ProgramPipelineImpl *ContextWgpu::createProgramPipeline(const gl::ProgramPipelineState &state)
{
return new ProgramPipelineWgpu(state);
}
MemoryObjectImpl *ContextWgpu::createMemoryObject()
{
UNREACHABLE();
return nullptr;
}
SemaphoreImpl *ContextWgpu::createSemaphore()
{
UNREACHABLE();
return nullptr;
}
OverlayImpl *ContextWgpu::createOverlay(const gl::OverlayState &state)
{
return new OverlayImpl(state);
}
angle::Result ContextWgpu::dispatchCompute(const gl::Context *context,
GLuint numGroupsX,
GLuint numGroupsY,
GLuint numGroupsZ)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::memoryBarrier(const gl::Context *context, GLbitfield barriers)
{
return angle::Result::Continue;
}
angle::Result ContextWgpu::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
{
return angle::Result::Continue;
}
void ContextWgpu::handleError(GLenum errorCode,
const char *message,
const char *file,
const char *function,
unsigned int line)
{
std::stringstream errorStream;
errorStream << "Internal Wgpu back-end error: " << message << ".";
mErrors->handleError(errorCode, errorStream.str().c_str(), file, function, line);
}
angle::Result ContextWgpu::ensureRenderPassStarted(const wgpu::RenderPassDescriptor &desc)
{
if (!mCurrentCommandEncoder)
{
mCurrentCommandEncoder = getDevice().CreateCommandEncoder(nullptr);
}
if (mCurrentRenderPass)
{
// TODO(anglebug.com/8582): this should eventually ignore load and store operations so we
// can avoid starting a new render pass in more situations.
if (RenderPassDescEqual(mCurrentRenderPassDesc, desc))
{
return angle::Result::Continue;
}
ANGLE_TRY(endRenderPass(webgpu::RenderPassClosureReason::NewRenderPass));
}
mCurrentRenderPass = mCurrentCommandEncoder.BeginRenderPass(&desc);
mCurrentRenderPassDesc = desc;
return angle::Result::Continue;
}
angle::Result ContextWgpu::endRenderPass(webgpu::RenderPassClosureReason closure_reason)
{
const char *reasonText = kRenderPassClosureReason[closure_reason];
INFO() << reasonText;
mCurrentRenderPass.End();
mCurrentRenderPass = nullptr;
return angle::Result::Continue;
}
angle::Result ContextWgpu::flush()
{
wgpu::CommandBuffer command_buffer = mCurrentCommandEncoder.Finish();
getQueue().Submit(1, &command_buffer);
mCurrentCommandEncoder = nullptr;
return angle::Result::Continue;
}
} // namespace rx