• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2021 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 // CLImage.h: Defines the cl::Image class, which stores a texture, frame-buffer or image.
7 
8 #ifndef LIBANGLE_CLIMAGE_H_
9 #define LIBANGLE_CLIMAGE_H_
10 
11 #include "libANGLE/CLMemory.h"
12 
13 #include "libANGLE/cl_utils.h"
14 
15 namespace cl
16 {
17 
18 class Image final : public Memory
19 {
20   public:
21     // Front end entry functions, only called from OpenCL entry points
22 
23     static bool IsTypeValid(MemObjectType imageType);
24     static bool IsValid(const _cl_mem *image);
25 
26     angle::Result getInfo(ImageInfo name,
27                           size_t valueSize,
28                           void *value,
29                           size_t *valueSizeRet) const;
30 
31   public:
32     ~Image() override;
33 
34     MemObjectType getType() const final;
35 
36     const cl_image_format &getFormat() const;
37     const ImageDescriptor &getDescriptor() const;
38 
39     bool isRegionValid(const cl::MemOffsets &origin, const cl::Coordinate &region) const;
40 
41     size_t getElementSize() const;
42     size_t getRowSize() const;
43     size_t getSliceSize() const;
44 
45   private:
46     Image(Context &context,
47           PropArray &&properties,
48           MemFlags flags,
49           const cl_image_format &format,
50           const ImageDescriptor &desc,
51           Memory *parent,
52           void *hostPtr);
53 
54     const cl_image_format mFormat;
55     const ImageDescriptor mDesc;
56 
57     friend class Object;
58 };
59 
IsValid(const _cl_mem * image)60 inline bool Image::IsValid(const _cl_mem *image)
61 {
62     return Memory::IsValid(image) && IsTypeValid(image->cast<Memory>().getType());
63 }
64 
getType()65 inline MemObjectType Image::getType() const
66 {
67     return mDesc.type;
68 }
69 
getFormat()70 inline const cl_image_format &Image::getFormat() const
71 {
72     return mFormat;
73 }
74 
getDescriptor()75 inline const ImageDescriptor &Image::getDescriptor() const
76 {
77     return mDesc;
78 }
79 
getElementSize()80 inline size_t Image::getElementSize() const
81 {
82     return GetElementSize(mFormat);
83 }
84 
getRowSize()85 inline size_t Image::getRowSize() const
86 {
87     return GetElementSize(mFormat) * mDesc.width;
88 }
89 
getSliceSize()90 inline size_t Image::getSliceSize() const
91 {
92     return GetElementSize(mFormat) * mDesc.width * mDesc.height;
93 }
94 
95 }  // namespace cl
96 
97 #endif  // LIBANGLE_CLIMAGE_H_
98