Hash :
6eaaad7c
Author :
Date :
2024-02-27T21:24:59
Create ImageHelper. This CL adds a helper class ImageHelper, which acts as a wrapper on webgpu textures that will be used by TextureWgpu. Bug: angleproject:8547 Change-Id: Ia796534c9d3ff0dd24797cc483677cfcbedb1f8c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5317864 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@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
//
// 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_helpers.h"
namespace webgpu
{
ImageHelper::ImageHelper() {}
ImageHelper::~ImageHelper() {}
angle::Result ImageHelper::initImage(wgpu::TextureUsage usage,
wgpu::TextureDimension dimension,
wgpu::Extent3D size,
wgpu::TextureFormat format,
std::uint32_t mipLevelCount,
std::uint32_t sampleCount,
std::size_t viewFormatCount)
{
mUsage = usage;
mDimension = dimension;
mSize = size;
mFormat = format;
mMipLevelCount = mipLevelCount;
mSampleCount = sampleCount;
mViewFormatCount = viewFormatCount;
return angle::Result::Continue;
}
void ImageHelper::flushStagedUpdates(wgpu::Device device)
{
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::ImageCopyTexture dst;
for (const QueuedDataUpload &src : mBufferQueue)
{
if (src.targetLevel < mFirstAllocatedLevel ||
src.targetLevel >= (mFirstAllocatedLevel + mMipLevelCount))
{
continue;
}
LevelIndex targetLevelWgpu = toWgpuLevel(src.targetLevel);
dst.texture = mTexture;
dst.mipLevel = targetLevelWgpu.get();
encoder.CopyBufferToTexture(&src.copyBuffer, &dst, &mSize);
}
}
LevelIndex ImageHelper::toWgpuLevel(gl::LevelIndex levelIndexGl) const
{
return gl_wgpu::getLevelIndex(levelIndexGl, mFirstAllocatedLevel);
}
gl::LevelIndex ImageHelper::toGlLevel(LevelIndex levelIndexWgpu) const
{
return wgpu_gl::getLevelIndex(levelIndexWgpu, mFirstAllocatedLevel);
}
} // namespace webgpu
namespace wgpu_gl
{
gl::LevelIndex getLevelIndex(webgpu::LevelIndex levelWgpu, gl::LevelIndex baseLevel)
{
return gl::LevelIndex(levelWgpu.get() + baseLevel.get());
}
} // 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());
}
} // namespace gl_wgpu