xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/wgpu/TextureWgpu.h (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 // TextureWgpu.h:
7 //    Defines the class interface for TextureWgpu, implementing TextureImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_WGPU_TEXTUREWGPU_H_
11 #define LIBANGLE_RENDERER_WGPU_TEXTUREWGPU_H_
12 
13 #include "libANGLE/renderer/TextureImpl.h"
14 #include "libANGLE/renderer/wgpu/ContextWgpu.h"
15 #include "libANGLE/renderer/wgpu/RenderTargetWgpu.h"
16 #include "libANGLE/renderer/wgpu/wgpu_helpers.h"
17 
18 namespace rx
19 {
20 class TextureWgpu : public TextureImpl
21 {
22   public:
23     TextureWgpu(const gl::TextureState &state);
24     ~TextureWgpu() override;
25 
26     angle::Result setImage(const gl::Context *context,
27                            const gl::ImageIndex &index,
28                            GLenum internalFormat,
29                            const gl::Extents &size,
30                            GLenum format,
31                            GLenum type,
32                            const gl::PixelUnpackState &unpack,
33                            gl::Buffer *unpackBuffer,
34                            const uint8_t *pixels) override;
35     angle::Result setSubImage(const gl::Context *context,
36                               const gl::ImageIndex &index,
37                               const gl::Box &area,
38                               GLenum format,
39                               GLenum type,
40                               const gl::PixelUnpackState &unpack,
41                               gl::Buffer *unpackBuffer,
42                               const uint8_t *pixels) override;
43 
44     angle::Result setCompressedImage(const gl::Context *context,
45                                      const gl::ImageIndex &index,
46                                      GLenum internalFormat,
47                                      const gl::Extents &size,
48                                      const gl::PixelUnpackState &unpack,
49                                      size_t imageSize,
50                                      const uint8_t *pixels) override;
51     angle::Result setCompressedSubImage(const gl::Context *context,
52                                         const gl::ImageIndex &index,
53                                         const gl::Box &area,
54                                         GLenum format,
55                                         const gl::PixelUnpackState &unpack,
56                                         size_t imageSize,
57                                         const uint8_t *pixels) override;
58 
59     angle::Result copyImage(const gl::Context *context,
60                             const gl::ImageIndex &index,
61                             const gl::Rectangle &sourceArea,
62                             GLenum internalFormat,
63                             gl::Framebuffer *source) override;
64     angle::Result copySubImage(const gl::Context *context,
65                                const gl::ImageIndex &index,
66                                const gl::Offset &destOffset,
67                                const gl::Rectangle &sourceArea,
68                                gl::Framebuffer *source) override;
69 
70     angle::Result copyTexture(const gl::Context *context,
71                               const gl::ImageIndex &index,
72                               GLenum internalFormat,
73                               GLenum type,
74                               GLint sourceLevel,
75                               bool unpackFlipY,
76                               bool unpackPremultiplyAlpha,
77                               bool unpackUnmultiplyAlpha,
78                               const gl::Texture *source) override;
79     angle::Result copySubTexture(const gl::Context *context,
80                                  const gl::ImageIndex &index,
81                                  const gl::Offset &destOffset,
82                                  GLint sourceLevel,
83                                  const gl::Box &sourceBox,
84                                  bool unpackFlipY,
85                                  bool unpackPremultiplyAlpha,
86                                  bool unpackUnmultiplyAlpha,
87                                  const gl::Texture *source) override;
88 
89     angle::Result copyRenderbufferSubData(const gl::Context *context,
90                                           const gl::Renderbuffer *srcBuffer,
91                                           GLint srcLevel,
92                                           GLint srcX,
93                                           GLint srcY,
94                                           GLint srcZ,
95                                           GLint dstLevel,
96                                           GLint dstX,
97                                           GLint dstY,
98                                           GLint dstZ,
99                                           GLsizei srcWidth,
100                                           GLsizei srcHeight,
101                                           GLsizei srcDepth) override;
102 
103     angle::Result copyTextureSubData(const gl::Context *context,
104                                      const gl::Texture *srcTexture,
105                                      GLint srcLevel,
106                                      GLint srcX,
107                                      GLint srcY,
108                                      GLint srcZ,
109                                      GLint dstLevel,
110                                      GLint dstX,
111                                      GLint dstY,
112                                      GLint dstZ,
113                                      GLsizei srcWidth,
114                                      GLsizei srcHeight,
115                                      GLsizei srcDepth) override;
116 
117     angle::Result copyCompressedTexture(const gl::Context *context,
118                                         const gl::Texture *source) override;
119 
120     angle::Result setStorage(const gl::Context *context,
121                              gl::TextureType type,
122                              size_t levels,
123                              GLenum internalFormat,
124                              const gl::Extents &size) override;
125 
126     angle::Result setStorageExternalMemory(const gl::Context *context,
127                                            gl::TextureType type,
128                                            size_t levels,
129                                            GLenum internalFormat,
130                                            const gl::Extents &size,
131                                            gl::MemoryObject *memoryObject,
132                                            GLuint64 offset,
133                                            GLbitfield createFlags,
134                                            GLbitfield usageFlags,
135                                            const void *imageCreateInfoPNext) override;
136 
137     angle::Result setEGLImageTarget(const gl::Context *context,
138                                     gl::TextureType type,
139                                     egl::Image *image) override;
140 
141     angle::Result setImageExternal(const gl::Context *context,
142                                    gl::TextureType type,
143                                    egl::Stream *stream,
144                                    const egl::Stream::GLTextureDescription &desc) override;
145 
146     angle::Result generateMipmap(const gl::Context *context) override;
147 
148     angle::Result setBaseLevel(const gl::Context *context, GLuint baseLevel) override;
149 
150     angle::Result bindTexImage(const gl::Context *context, egl::Surface *surface) override;
151     angle::Result releaseTexImage(const gl::Context *context) override;
152 
153     angle::Result syncState(const gl::Context *context,
154                             const gl::Texture::DirtyBits &dirtyBits,
155                             gl::Command source) override;
156 
157     angle::Result setStorageMultisample(const gl::Context *context,
158                                         gl::TextureType type,
159                                         GLsizei samples,
160                                         GLint internalformat,
161                                         const gl::Extents &size,
162                                         bool fixedSampleLocations) override;
163 
164     angle::Result initializeContents(const gl::Context *context,
165                                      GLenum binding,
166                                      const gl::ImageIndex &imageIndex) override;
167 
168     angle::Result getAttachmentRenderTarget(const gl::Context *context,
169                                             GLenum binding,
170                                             const gl::ImageIndex &imageIndex,
171                                             GLsizei samples,
172                                             FramebufferAttachmentRenderTarget **rtOut) override;
173 
getImage()174     webgpu::ImageHelper *getImage() { return mImage; }
175 
176   private:
177     angle::Result setImageImpl(const gl::Context *context,
178                                GLenum internalFormat,
179                                GLenum type,
180                                const gl::ImageIndex &index,
181                                const gl::Extents &size,
182                                const gl::PixelUnpackState &unpack,
183                                const uint8_t *pixels);
184 
185     angle::Result setSubImageImpl(const gl::Context *context,
186                                   const webgpu::Format &webgpuFormat,
187                                   GLenum type,
188                                   const gl::ImageIndex &index,
189                                   const gl::Box &area,
190                                   const gl::PixelUnpackState &unpack,
191                                   const uint8_t *pixels);
192 
193     angle::Result initializeImage(ContextWgpu *contextWgpu, ImageMipLevels mipLevels);
194 
195     angle::Result redefineLevel(const gl::Context *context,
196                                 const webgpu::Format &webgpuFormat,
197                                 const gl::ImageIndex &index,
198                                 const gl::Extents &size);
199 
200     uint32_t getMipLevelCount(ImageMipLevels mipLevels) const;
201 
202     uint32_t getMaxLevelCount() const;
203     angle::Result respecifyImageStorageIfNecessary(ContextWgpu *contextWgpu, gl::Command source);
204     void prepareForGenerateMipmap(ContextWgpu *contextWgpu);
205     angle::Result maybeUpdateBaseMaxLevels(ContextWgpu *contextWgpu);
206     angle::Result initSingleLayerRenderTargets(ContextWgpu *contextWgpu,
207                                                GLuint layerCount,
208                                                gl::LevelIndex levelIndex,
209                                                gl::RenderToTextureImageIndex renderToTextureIndex);
210     const webgpu::Format &getBaseLevelFormat(ContextWgpu *contextWgpu) const;
211 
212     webgpu::ImageHelper *mImage;
213     gl::LevelIndex mCurrentBaseLevel;
214     gl::LevelIndex mCurrentMaxLevel;
215     gl::CubeFaceArray<gl::TexLevelMask> mRedefinedLevels;
216 
217     // Render targets stored as array of vector of vectors
218     //
219     // - First dimension: only RenderToTextureImageIndex::Default for now.
220     // - Second dimension: level
221     // - Third dimension: layer
222     gl::RenderToTextureImageMap<std::vector<std::vector<RenderTargetWgpu>>>
223         mSingleLayerRenderTargets;
224 };
225 
226 }  // namespace rx
227 
228 #endif  // LIBANGLE_RENDERER_WGPU_TEXTUREWGPU_H_
229