Hash :
657c8c0a
Author :
Date :
2024-06-04T15:16:20
Add optimization to defer clear calls. This change adds a new SubresourceUpdate struct that will hold either an update for a clear call or a texture upload in an ImageHelper's update queue. It also adds logic to defer clear calls similar to Vulkan's, where clears are deferred if there is not an active render pass. Draw based clears are not yet supported, so the optimization does not handle those yet. Bug: angleproject:8582 Change-Id: I3ee010fa64745871835d53ce0ccb56e3fdd74550 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5554984 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Matthew Denton <mpdenton@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
//
// 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.
//
#include "libANGLE/renderer/wgpu/wgpu_utils.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/wgpu/ContextWgpu.h"
#include "libANGLE/renderer/wgpu/DisplayWgpu.h"
namespace rx
{
namespace webgpu
{
ContextWgpu *GetImpl(const gl::Context *context)
{
return GetImplAs<ContextWgpu>(context);
}
DisplayWgpu *GetDisplay(const gl::Context *context)
{
ContextWgpu *contextWgpu = GetImpl(context);
return contextWgpu->getDisplay();
}
wgpu::Device GetDevice(const gl::Context *context)
{
DisplayWgpu *display = GetDisplay(context);
return display->getDevice();
}
wgpu::Instance GetInstance(const gl::Context *context)
{
DisplayWgpu *display = GetDisplay(context);
return display->getInstance();
}
wgpu::RenderPassColorAttachment CreateNewClearColorAttachment(wgpu::Color clearValue,
uint32_t depthSlice,
wgpu::TextureView textureView)
{
wgpu::RenderPassColorAttachment colorAttachment;
colorAttachment.view = textureView;
colorAttachment.depthSlice = depthSlice;
colorAttachment.loadOp = wgpu::LoadOp::Clear;
colorAttachment.storeOp = wgpu::StoreOp::Store;
colorAttachment.clearValue = clearValue;
return colorAttachment;
}
bool IsWgpuError(wgpu::WaitStatus waitStatus)
{
return waitStatus != wgpu::WaitStatus::Success;
}
bool IsWgpuError(WGPUBufferMapAsyncStatus mapBufferStatus)
{
return mapBufferStatus != WGPUBufferMapAsyncStatus_Success;
}
ClearValuesArray::ClearValuesArray() : mValues{}, mEnabled{} {}
ClearValuesArray::~ClearValuesArray() = default;
ClearValuesArray::ClearValuesArray(const ClearValuesArray &other) = default;
ClearValuesArray &ClearValuesArray::operator=(const ClearValuesArray &rhs) = default;
void ClearValuesArray::store(uint32_t index, ClearValues clearValues)
{
mValues[index] = clearValues;
mEnabled.set(index);
}
gl::DrawBufferMask ClearValuesArray::getColorMask() const
{
return gl::DrawBufferMask(mEnabled.bits() & kUnpackedColorBuffersMask);
}
void EnsureCapsInitialized(const wgpu::Device &device, gl::Caps *nativeCaps)
{
wgpu::SupportedLimits limitsWgpu = {};
device.GetLimits(&limitsWgpu);
nativeCaps->maxElementIndex = std::numeric_limits<GLuint>::max() - 1;
nativeCaps->max3DTextureSize = rx::LimitToInt(limitsWgpu.limits.maxTextureDimension3D);
nativeCaps->max2DTextureSize = rx::LimitToInt(limitsWgpu.limits.maxTextureDimension2D);
nativeCaps->maxArrayTextureLayers = rx::LimitToInt(limitsWgpu.limits.maxTextureArrayLayers);
nativeCaps->maxCubeMapTextureSize = rx::LimitToInt(limitsWgpu.limits.maxTextureDimension2D);
nativeCaps->maxRenderbufferSize = rx::LimitToInt(limitsWgpu.limits.maxTextureDimension2D);
nativeCaps->maxDrawBuffers = rx::LimitToInt(limitsWgpu.limits.maxColorAttachments);
nativeCaps->maxFramebufferWidth = rx::LimitToInt(limitsWgpu.limits.maxTextureDimension2D);
nativeCaps->maxFramebufferHeight = rx::LimitToInt(limitsWgpu.limits.maxTextureDimension2D);
nativeCaps->maxColorAttachments = rx::LimitToInt(limitsWgpu.limits.maxColorAttachments);
nativeCaps->maxVertexAttribStride =
rx::LimitToInt(limitsWgpu.limits.maxVertexBufferArrayStride);
nativeCaps->maxVertexAttributes = rx::LimitToInt(limitsWgpu.limits.maxVertexAttributes);
nativeCaps->maxTextureBufferSize = rx::LimitToInt(limitsWgpu.limits.maxBufferSize);
}
} // namespace webgpu
namespace wgpu_gl
{
gl::LevelIndex getLevelIndex(webgpu::LevelIndex levelWgpu, gl::LevelIndex baseLevel)
{
return gl::LevelIndex(levelWgpu.get() + baseLevel.get());
}
gl::Extents getExtents(wgpu::Extent3D wgpuExtent)
{
gl::Extents glExtent;
glExtent.width = wgpuExtent.width;
glExtent.height = wgpuExtent.height;
glExtent.depth = wgpuExtent.depthOrArrayLayers;
return glExtent;
}
} // namespace wgpu_gl
namespace gl_wgpu
{
webgpu::LevelIndex getLevelIndex(gl::LevelIndex levelGl, gl::LevelIndex baseLevel)
{
ASSERT(baseLevel <= levelGl);
return webgpu::LevelIndex(levelGl.get() - baseLevel.get());
}
wgpu::Extent3D getExtent3D(const gl::Extents &glExtent)
{
wgpu::Extent3D wgpuExtent;
wgpuExtent.width = glExtent.width;
wgpuExtent.height = glExtent.height;
wgpuExtent.depthOrArrayLayers = glExtent.depth;
return wgpuExtent;
}
wgpu::TextureDimension getWgpuTextureDimension(gl::TextureType glTextureType)
{
wgpu::TextureDimension dimension = {};
switch (glTextureType)
{
case gl::TextureType::_2D:
case gl::TextureType::_2DMultisample:
case gl::TextureType::Rectangle:
case gl::TextureType::External:
case gl::TextureType::Buffer:
dimension = wgpu::TextureDimension::e2D;
break;
case gl::TextureType::_2DArray:
case gl::TextureType::_2DMultisampleArray:
case gl::TextureType::_3D:
case gl::TextureType::CubeMap:
case gl::TextureType::CubeMapArray:
case gl::TextureType::VideoImage:
dimension = wgpu::TextureDimension::e3D;
break;
default:
break;
}
return dimension;
}
} // namespace gl_wgpu
} // namespace rx