Hash :
9f8d7cc2
Author :
Date :
2025-01-23T13:27:19
WebGPU: Stream incompatible vertex and index data. Support reading back index and vertex buffers to stream incompatible source data. For now this includes: * Non-multiple-of-4 stride vertex data * Stride not a multiple of the type size * Unsigned byte indices Fix fallback formats so that all GLES formats have a fallback. Fix CopyToFloatVertexData writing the alpha channel as Float32One with a static_cast which converted Float32One (an integer) to a float instead of bit-casting. Bug: angleproject:368602384 Change-Id: I7eb1ba7ad1ec4292060c18de22f5948136cbb0a3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6194556 Reviewed-by: Liza Burakova <liza@chromium.org> Commit-Queue: Geoff Lang <geofflang@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 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
//
// 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);
}
angle::FormatID getActualImageFormatID() const { return mActualImageFormatID; }
wgpu::VertexFormat getActualWgpuVertexFormat() const
{
return GetWgpuVertexFormatFromFormatID(mActualBufferFormatID);
}
angle::FormatID getActualVertexFormatID() const { return mActualBufferFormatID; }
// 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);
}
bool vertexLoadRequiresConversion() const { return mVertexLoadRequiresConversion; }
VertexCopyFunction getVertexLoadFunction() const { return mVertexLoadFunction; }
// |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_