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
//
// 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();
}
bool IsError(wgpu::WaitStatus waitStatus)
{
return waitStatus != wgpu::WaitStatus::Success;
}
bool IsError(WGPUBufferMapAsyncStatus mapBufferStatus)
{
return mapBufferStatus != WGPUBufferMapAsyncStatus_Success;
}
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