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 "common/PackedCLEnums_autogen.h"
12
13 #include "libANGLE/CLMemory.h"
14 #include "libANGLE/cl_utils.h"
15
16 namespace cl
17 {
18
19 class Image final : public Memory
20 {
21 public:
22 // Front end entry functions, only called from OpenCL entry points
23
24 static bool IsTypeValid(MemObjectType imageType);
25 static bool IsValid(const _cl_mem *image);
26
27 angle::Result getInfo(ImageInfo name,
28 size_t valueSize,
29 void *value,
30 size_t *valueSizeRet) const;
31
32 public:
33 ~Image() override;
34
35 MemObjectType getType() const final;
36
37 const cl_image_format &getFormat() const;
38 const ImageDescriptor &getDescriptor() const;
39
40 bool isRegionValid(const cl::MemOffsets &origin, const cl::Coordinate ®ion) const;
41
42 size_t getElementSize() const;
43 size_t getRowSize() const;
44 size_t getSliceSize() const;
getArraySize()45 size_t getArraySize() const { return mDesc.arraySize; }
getWidth()46 size_t getWidth() const { return mDesc.width; }
getHeight()47 size_t getHeight() const { return mDesc.height; }
getDepth()48 size_t getDepth() const { return mDesc.depth; }
49
50 private:
51 Image(Context &context,
52 PropArray &&properties,
53 MemFlags flags,
54 const cl_image_format &format,
55 const ImageDescriptor &desc,
56 Memory *parent,
57 void *hostPtr);
58
59 const cl_image_format mFormat;
60 const ImageDescriptor mDesc;
61
62 friend class Object;
63 };
64
IsValid(const _cl_mem * image)65 inline bool Image::IsValid(const _cl_mem *image)
66 {
67 return Memory::IsValid(image) && IsTypeValid(image->cast<Memory>().getType());
68 }
69
getType()70 inline MemObjectType Image::getType() const
71 {
72 return mDesc.type;
73 }
74
getFormat()75 inline const cl_image_format &Image::getFormat() const
76 {
77 return mFormat;
78 }
79
getDescriptor()80 inline const ImageDescriptor &Image::getDescriptor() const
81 {
82 return mDesc;
83 }
84
getElementSize()85 inline size_t Image::getElementSize() const
86 {
87 return GetElementSize(mFormat);
88 }
89
getRowSize()90 inline size_t Image::getRowSize() const
91 {
92 return mDesc.rowPitch != 0u ? mDesc.rowPitch : GetElementSize(mFormat) * getWidth();
93 }
94
getSliceSize()95 inline size_t Image::getSliceSize() const
96 {
97 return mDesc.slicePitch != 0u ? mDesc.slicePitch : getRowSize() * getHeight();
98 }
99
100 } // namespace cl
101
102 #endif // LIBANGLE_CLIMAGE_H_
103