xref: /aosp_15_r20/external/angle/src/libANGLE/CLSampler.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 // CLSampler.h: Defines the cl::Sampler class, which describes how to sample an OpenCL Image.
7 
8 #ifndef LIBANGLE_CLSAMPLER_H_
9 #define LIBANGLE_CLSAMPLER_H_
10 
11 #include "libANGLE/CLObject.h"
12 #include "libANGLE/renderer/CLSamplerImpl.h"
13 
14 namespace cl
15 {
16 
17 class Sampler final : public _cl_sampler, public Object
18 {
19   public:
20     // Front end entry functions, only called from OpenCL entry points
21 
22     angle::Result getInfo(SamplerInfo name,
23                           size_t valueSize,
24                           void *value,
25                           size_t *valueSizeRet) const;
26 
27   public:
28     using PropArray = std::vector<cl_sampler_properties>;
29 
30     ~Sampler() override;
31 
32     const Context &getContext() const;
33     const PropArray &getProperties() const;
34     cl_bool getNormalizedCoords() const;
35     AddressingMode getAddressingMode() const;
36     FilterMode getFilterMode() const;
37 
38     template <typename T = rx::CLSamplerImpl>
39     T &getImpl() const;
40 
41     static Sampler *Cast(cl_sampler sampler);
42 
43   private:
44     Sampler(Context &context,
45             PropArray &&properties,
46             cl_bool normalizedCoords,
47             AddressingMode addressingMode,
48             FilterMode filterMode);
49 
50     const ContextPtr mContext;
51     const PropArray mProperties;
52     const cl_bool mNormalizedCoords;
53     const AddressingMode mAddressingMode;
54     const FilterMode mFilterMode;
55     rx::CLSamplerImpl::Ptr mImpl;
56 
57     friend class Object;
58 };
59 
getContext()60 inline const Context &Sampler::getContext() const
61 {
62     return *mContext;
63 }
64 
getProperties()65 inline const Sampler::PropArray &Sampler::getProperties() const
66 {
67     return mProperties;
68 }
69 
getNormalizedCoords()70 inline cl_bool Sampler::getNormalizedCoords() const
71 {
72     return mNormalizedCoords;
73 }
74 
getAddressingMode()75 inline AddressingMode Sampler::getAddressingMode() const
76 {
77     return mAddressingMode;
78 }
79 
getFilterMode()80 inline FilterMode Sampler::getFilterMode() const
81 {
82     return mFilterMode;
83 }
84 
85 template <typename T>
getImpl()86 inline T &Sampler::getImpl() const
87 {
88     return static_cast<T &>(*mImpl);
89 }
90 
Cast(cl_sampler sampler)91 inline Sampler *Sampler::Cast(cl_sampler sampler)
92 {
93     return static_cast<Sampler *>(sampler);
94 }
95 
96 }  // namespace cl
97 
98 #endif  // LIBANGLE_CLSAMPLER_H_
99