xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/wgpu/wgpu_format_utils.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2024 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #include "libANGLE/renderer/wgpu/wgpu_format_utils.h"
7 
8 #include "libANGLE/renderer/load_functions_table.h"
9 namespace rx
10 {
11 namespace
12 {
FillTextureCaps(const angle::Format & angleFormat,angle::FormatID formatID,gl::TextureCaps * outTextureCaps)13 void FillTextureCaps(const angle::Format &angleFormat,
14                      angle::FormatID formatID,
15                      gl::TextureCaps *outTextureCaps)
16 {
17     if (formatID != angle::FormatID::NONE)
18     {
19         outTextureCaps->texturable = true;
20     }
21     outTextureCaps->filterable   = true;
22     outTextureCaps->renderbuffer = true;
23     outTextureCaps->blendable    = true;
24 }
25 }  // namespace
26 
27 namespace webgpu
28 {
Format()29 Format::Format()
30     : mIntendedFormatID(angle::FormatID::NONE),
31       mIntendedGLFormat(GL_NONE),
32       mActualImageFormatID(angle::FormatID::NONE),
33       mActualBufferFormatID(angle::FormatID::NONE),
34       mImageInitializerFunction(nullptr),
35       mIsRenderable(false)
36 {}
initImageFallback(const ImageFormatInitInfo * info,int numInfo)37 void Format::initImageFallback(const ImageFormatInitInfo *info, int numInfo)
38 {
39     UNIMPLEMENTED();
40 }
41 
initBufferFallback(const BufferFormatInitInfo * fallbackInfo,int numInfo)42 void Format::initBufferFallback(const BufferFormatInitInfo *fallbackInfo, int numInfo)
43 {
44     UNIMPLEMENTED();
45 }
46 
FormatTable()47 FormatTable::FormatTable() {}
~FormatTable()48 FormatTable::~FormatTable() {}
49 
initialize()50 void FormatTable::initialize()
51 {
52     for (size_t formatIndex = 0; formatIndex < angle::kNumANGLEFormats; ++formatIndex)
53     {
54         Format &format                           = mFormatData[formatIndex];
55         const auto intendedFormatID              = static_cast<angle::FormatID>(formatIndex);
56         const angle::Format &intendedAngleFormat = angle::Format::Get(intendedFormatID);
57 
58         format.initialize(intendedAngleFormat);
59         format.mIntendedFormatID = intendedFormatID;
60 
61         gl::TextureCaps textureCaps;
62         FillTextureCaps(format.getActualImageFormat(), format.mActualImageFormatID, &textureCaps);
63         if (textureCaps.texturable)
64         {
65             format.mTextureLoadFunctions =
66                 GetLoadFunctionsMap(format.mIntendedGLFormat, format.mActualImageFormatID);
67         }
68     }
69 }
70 }  // namespace webgpu
71 }  // namespace rx
72