Free Electron
SurfaceAccessibleOpenCL.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __opencl_SurfaceAccessibleOpenCL_h__
8 #define __opencl_SurfaceAccessibleOpenCL_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief OpenCL Surface Binding
17 
18  @ingroup opencl
19 *//***************************************************************************/
20 class FE_DL_EXPORT SurfaceAccessibleOpenCL:
21  public SurfaceAccessibleBase,
22  public CastableAs<SurfaceAccessibleOpenCL>
23 {
24  public:
26 virtual ~SurfaceAccessibleOpenCL(void);
27 
28 static void updateDrawBuffer(
29  sp<DrawBufferI> a_spDrawBuffer,
30  sp<Master> a_spMaster,
32  a_spSurfaceAccessibleI,
33  I32 a_vertCount);
34 
35  //* As Protectable
36 virtual Protectable* clone(Protectable* pInstance=NULL);
37 
38  //* as SurfaceAccessibleI
39 virtual BWORD isBound(void) { return TRUE; }
40 
41  //* TODO guard the allocations
42 virtual BWORD threadable(void) { return FALSE; }
43 
45 
46 virtual I32 count(String a_nodeName,
47  SurfaceAccessibleI::Element
48  a_element) const;
49 
50  using SurfaceAccessibleBase::attributeSpecs;
51 
52 virtual void attributeSpecs(
54  a_rSpecs,
55  String a_node,
56  SurfaceAccessibleI::Element
57  a_element) const;
58 
60 
61 virtual sp<SurfaceAccessorI> accessor(String a_node,
62  SurfaceAccessibleI::Element a_element,
63  String a_name,
64  SurfaceAccessibleI::Creation a_create,
65  SurfaceAccessibleI::Writable
66  a_writable);
67 virtual sp<SurfaceAccessorI> accessor(String a_node,
68  SurfaceAccessibleI::Element a_element,
69  SurfaceAccessibleI::Attribute
70  a_attribute,
71  SurfaceAccessibleI::Creation a_create,
72  SurfaceAccessibleI::Writable
73  a_writable);
74 
75  using SurfaceAccessibleBase::discard;
76 
77 virtual BWORD discard(SurfaceAccessibleI::Element a_element,
78  String a_name);
79 
81 
82 virtual sp<SurfaceI> surface(String a_group,
83  SurfaceI::Restrictions a_restrictions);
84 
85 virtual sp<MultiGroup> generateGroup(
86  SurfaceAccessibleI::Element a_element,
87  String a_groupString);
88 
89  //* OpenCL specific
90 
91  class ClMem:
92  public Counted,
93  public CastableAs<ClMem>
94  {
95  public:
96  ClMem(void):
97  m_clMem(NULL) {}
98 
99  ~ClMem(void)
100  { clReleaseMemObject(m_clMem); }
101 
102  cl_mem m_clMem;
103  };
104 
105  class Bridge:
106  public ObjectSafeShared<Bridge>,
107  public Protectable,
108  public CastableAs<Bridge>
109  {
110  public:
111  Bridge(cl_context a_clContext):
112  m_bufferData(NULL),
113  m_elementCount(0),
114  m_allocated(0),
115  m_sizeof(0),
116  m_clContext(a_clContext),
117  m_cpuCurrent(TRUE),
118  m_gpuCurrent(TRUE) {}
119 
120  ~Bridge(void);
121 
122  //* As Protectable
123  virtual Protectable* clone(Protectable* pInstance=NULL);
124 
125  //* will copy CPU data to GPU,
126  //* if GPU data not current
127  sp<ClMem> getClMem(void);
128 
129  //* copy GPU data to CPU, if CPU data not current
130  void refresh(void);
131 
132 
133  String m_name;
134  String m_type;
135  String m_rate;
136 
137  std::set<I32> m_groupSet;
138  void* m_bufferData;
139  I32 m_elementCount;
140  I32 m_allocated;
141  I32 m_sizeof;
142 
143  cl_context m_clContext;
144  sp<ClMem> m_spClMem;
145  sp<ClMem> m_spClMemPrevious;
146 
147  sp<Master> m_spMaster;
148  BWORD m_cpuCurrent;
149  BWORD m_gpuCurrent;
150  };
151 
152  cp<Bridge>& lookupBridge(String a_name,BWORD a_create);
153 
154  protected:
155 virtual void reset(void);
156 
157  private:
158  void updateContext(void);
159 
160  sp<SurfaceAccessorI> createAccessor(void);
161 
162  std::map< String, cp<Bridge> > m_bridgeMap;
163  cp<Bridge> m_bridgeNull;
164 
165  cl_context m_clContext;
166 };
167 
168 } /* namespace ext */
169 } /* namespace fe */
170 
171 #endif /* __opencl_SurfaceAccessibleOpenCL_h__ */
Common Functionality for Accessible Surface.
Definition: SurfaceAccessibleBase.h:20
virtual sp< SurfaceI > surface(void)
Return current underlying SurfaceI.
Definition: SurfaceAccessibleBase.h:143
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
Base class providing protection counting for cp<>
Definition: Protectable.h:28
kernel
Definition: namespace.dox:3
virtual BWORD threadable(void)
Indicate whether an implementation can be accessed from multiple threads.
Definition: SurfaceAccessibleOpenCL.h:42
virtual BWORD isBound(void)
Return true if surface is available.
Definition: SurfaceAccessibleOpenCL.h:39
OpenCL Surface Binding.
Definition: SurfaceAccessibleOpenCL.h:20
Automatically reference-counted string container.
Definition: String.h:128
int count(void) const
Return the count of references.
Definition: Counted.h:156
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192
Object level locking for thread safety.
Definition: SafeShared.h:220
virtual sp< SurfaceAccessorI > accessor(String a_node, Element a_element, String a_name, Creation a_create, Writable a_writable)
Return access to an attribute.
Definition: SurfaceAccessibleBase.h:87