Hash :
4f498eaa
Author :
Date :
2024-07-24T14:31:23
WebGPU: Add more format support This CL adds a new FormatTable class that initializes webgpu texture and vertex formats. It also adds this class to the display so it can be used in the ImageHelper. This CL changes the previously hardcoded RGBA8 texture format that was initially used when creating textures to use the format passed into the methods. Bug: angleproject:344814096 Change-Id: I768b85335329116496dbf721aac54d1137aaae9f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5660397 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 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
//
// 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.
//
// wgpu_format_utils:
// Helper for WebGPU format code.
#ifndef LIBANGLE_RENDERER_WGPU_WGPU_FORMAT_UTILS_H_
#define LIBANGLE_RENDERER_WGPU_WGPU_FORMAT_UTILS_H_
#include <dawn/webgpu_cpp.h>
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/Format.h"
#include "libANGLE/renderer/copyvertex.h"
namespace rx
{
namespace webgpu
{
struct ImageFormatInitInfo final
{
angle::FormatID format;
InitializeTextureDataFunction initializer;
};
struct BufferFormatInitInfo final
{
angle::FormatID format;
VertexCopyFunction VertexLoadFunction;
bool VertexLoadRequiresConversion;
};
wgpu::TextureFormat GetWgpuTextureFormatFromFormatID(angle::FormatID formatID);
angle::FormatID GetFormatIDFromWgpuTextureFormat(wgpu::TextureFormat wgpuFormat);
wgpu::VertexFormat GetWgpuVertexFormatFromFormatID(angle::FormatID formatID);
angle::FormatID GetFormatIDFromWgpuBufferFormat(wgpu::VertexFormat wgpuFormat);
// Describes a WebGPU format. WebGPU has separate formats for images and vertex buffers, this class
// describes both.
class Format final : private angle::NonCopyable
{
public:
Format();
bool valid() const { return mIntendedGLFormat != 0; }
// The intended format is the front-end format. For Textures this usually correponds to a
// GLenum in the headers. Buffer formats don't always have a corresponding GLenum type.
// Some Surface formats and unsized types also don't have a corresponding GLenum.
angle::FormatID getIntendedFormatID() const { return mIntendedFormatID; }
const angle::Format &getIntendedFormat() const { return angle::Format::Get(mIntendedFormatID); }
// The actual Image format is used to implement the front-end format for Texture/Renderbuffers.
const angle::Format &getActualImageFormat() const
{
return angle::Format::Get(getActualImageFormatID());
}
LoadImageFunctionInfo getTextureLoadFunction(GLenum type) const
{
return mTextureLoadFunctions(type);
}
wgpu::TextureFormat getActualWgpuTextureFormat() const
{
return GetWgpuTextureFormatFromFormatID(mActualImageFormatID);
}
wgpu::VertexFormat getActualWgpuVertexFormat() const
{
return GetWgpuVertexFormatFromFormatID(mActualBufferFormatID);
}
angle::FormatID getActualImageFormatID() const { return mActualImageFormatID; }
// The actual Buffer format is used to implement the front-end format for Buffers. This format
// is used by vertex buffers as well as texture buffers.
const angle::Format &getActualBufferFormat() const
{
return angle::Format::Get(mActualBufferFormatID);
}
// |intendedGLFormat| always correponds to a valid GLenum type. For types that don't have a
// corresponding GLenum we do our best to specify a GLenum that is "close".
const gl::InternalFormat &getInternalFormatInfo(GLenum type) const
{
return gl::GetInternalFormatInfo(mIntendedGLFormat, type);
}
private:
friend class FormatTable;
// This is an auto-generated method in vk_format_table_autogen.cpp.
void initialize(const angle::Format &intendedAngleFormat);
// These are used in the format table init.
void initImageFallback(const ImageFormatInitInfo *info, int numInfo);
void initBufferFallback(const BufferFormatInitInfo *fallbackInfo, int numInfo);
angle::FormatID mIntendedFormatID;
GLenum mIntendedGLFormat;
angle::FormatID mActualImageFormatID;
angle::FormatID mActualBufferFormatID;
InitializeTextureDataFunction mImageInitializerFunction;
LoadFunctionMap mTextureLoadFunctions;
VertexCopyFunction mVertexLoadFunction;
bool mVertexLoadRequiresConversion;
bool mIsRenderable;
};
bool operator==(const Format &lhs, const Format &rhs);
bool operator!=(const Format &lhs, const Format &rhs);
class FormatTable final : angle::NonCopyable
{
public:
FormatTable();
~FormatTable();
void initialize();
ANGLE_INLINE const Format &operator[](GLenum internalFormat) const
{
angle::FormatID formatID = angle::Format::InternalFormatToID(internalFormat);
return mFormatData[static_cast<size_t>(formatID)];
}
ANGLE_INLINE const Format &operator[](angle::FormatID formatID) const
{
return mFormatData[static_cast<size_t>(formatID)];
}
private:
// The table data is indexed by angle::FormatID.
std::array<Format, angle::kNumANGLEFormats> mFormatData;
};
} // namespace webgpu
} // namespace rx
#endif // LIBANGLE_RENDERER_WGPU_WGPU_FORMAT_UTILS_H_