Hash :
0add1163
Author :
Date :
2024-03-25T11:39:41
Move extent and dimension conversions to wgpu_utils. This change moves some helper methods out of the ImageHelper and wgpu_helpers and into wgpu_utils. Bug: angleproject:8457 Change-Id: I1cc641e4a48eec30519e331b6150e2432d3bc3c4 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5392380 Reviewed-by: Matthew Denton <mpdenton@chromium.org> Commit-Queue: Liza Burakova <liza@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@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
//
// 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::Device &device,
wgpu::TextureUsage usage,
wgpu::TextureDimension dimension,
wgpu::Extent3D size,
wgpu::TextureFormat format,
std::uint32_t mipLevelCount,
std::uint32_t sampleCount,
std::size_t viewFormatCount)
{
mTextureDescriptor.usage = usage;
mTextureDescriptor.dimension = dimension;
mTextureDescriptor.size = size;
mTextureDescriptor.format = format;
mTextureDescriptor.mipLevelCount = mipLevelCount;
mTextureDescriptor.sampleCount = sampleCount;
mTextureDescriptor.viewFormatCount = viewFormatCount;
mTexture = device.CreateTexture(&mTextureDescriptor);
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 + mTextureDescriptor.mipLevelCount))
{
continue;
}
LevelIndex targetLevelWgpu = toWgpuLevel(src.targetLevel);
dst.texture = mTexture;
dst.mipLevel = targetLevelWgpu.get();
encoder.CopyBufferToTexture(&src.copyBuffer, &dst, &mTextureDescriptor.size);
}
}
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);
}
TextureInfo ImageHelper::getWgpuTextureInfo(const gl::ImageIndex &index)
{
TextureInfo textureInfo;
textureInfo.dimension = gl_wgpu::getWgpuTextureDimension(index.getType());
textureInfo.mipLevelCount = index.getLayerCount();
return textureInfo;
}
} // namespace webgpu