@@ -17,6 +17,26 @@ namespace ext
17
17
namespace RadeonRays
18
18
{
19
19
20
+ // this is a really bad mock (do not take inspiration from it for the real API)
21
+ class MockSceneManager
22
+ {
23
+ public:
24
+ using MeshBufferGUID = uint32_t ;
25
+ using ObjectGUID = uint32_t ;
26
+
27
+ struct ObjectData
28
+ {
29
+ core::matrix3x4SIMD tform;
30
+ core::smart_refctd_ptr<video::IGPUMesh> mesh;
31
+ core::vector<MeshBufferGUID> meshbufferIDs;
32
+ };
33
+
34
+ const ObjectData& getObjectData (const ObjectGUID guid) const {return m_objectData[guid];}
35
+
36
+ // mocks
37
+ core::vector<ObjectData> m_objectData;
38
+ };
39
+
20
40
21
41
class Manager final : public core::IReferenceCounted
22
42
{
@@ -31,23 +51,27 @@ class Manager final : public core::IReferenceCounted
31
51
}
32
52
33
53
34
- using MeshBufferRRShapeCache = core::unordered_map<const asset::ICPUMeshBuffer*,::RadeonRays::Shape*>;
35
- #ifdef TODO
36
- using MeshNodeRRInstanceCache = core::unordered_map<scene::IMeshSceneNode*, core::smart_refctd_dynamic_array<::RadeonRays::Shape*> >;
37
- #endif
54
+ struct MeshBufferRRShapeCache
55
+ {
56
+ core::unordered_map<const asset::ICPUMeshBuffer*,::RadeonRays::Shape*> m_cpuAssociative;
57
+ core::unordered_map<const video::IGPUMeshBuffer*,::RadeonRays::Shape*> m_gpuAssociative;
58
+ };
59
+ using NblInstanceRRInstanceCache = core::unordered_map<MockSceneManager::ObjectGUID,core::smart_refctd_dynamic_array<::RadeonRays::Shape*>>;
38
60
39
61
template <typename Iterator>
40
62
inline void makeRRShapes (MeshBufferRRShapeCache& shapeCache, Iterator _begin, Iterator _end)
41
63
{
42
- shapeCache.reserve (std::distance (_begin,_end));
64
+ auto & cpuCache = shapeCache.m_cpuAssociative ;
65
+ cpuCache.reserve (cpuCache.size ()+std::distance (_begin,_end));
66
+ shapeCache.m_gpuAssociative .reserve (cpuCache.size ());
43
67
44
68
for (auto it=_begin; it!=_end; it++)
45
69
{
46
70
auto * mb = static_cast <irr::asset::ICPUMeshBuffer*>(*it);
47
- auto found = shapeCache .find (mb);
48
- if (found!=shapeCache .end ())
71
+ auto found = cpuCache .find (mb);
72
+ if (found!=cpuCache .end ())
49
73
continue ;
50
- shapeCache .insert ({mb,nullptr });
74
+ cpuCache .insert ({mb,nullptr });
51
75
52
76
53
77
const auto posAttrID = mb->getPositionAttributeIx ();
@@ -59,37 +83,28 @@ class Manager final : public core::IReferenceCounted
59
83
}
60
84
61
85
for (auto it=_begin; it!=_end; it++)
62
- makeShape (shapeCache ,static_cast <irr::asset::ICPUMeshBuffer*>(*it));
86
+ makeShape (cpuCache ,static_cast <irr::asset::ICPUMeshBuffer*>(*it));
63
87
}
64
88
65
89
template <typename Iterator>
66
90
inline void deleteShapes (Iterator _begin, Iterator _end)
67
91
{
68
92
for (auto it = _begin; it != _end; it++)
93
+ {
69
94
rr->DeleteShape (std::get<::RadeonRays::Shape*>(*it));
95
+ }
70
96
}
71
97
72
- # ifdef TODO
98
+
73
99
template <typename Iterator>
74
- inline void makeRRInstances (MeshNodeRRInstanceCache& instanceCache, const MeshBufferRRShapeCache& shapeCache,
75
- asset::IAssetManager* _assetManager, Iterator _begin, Iterator _end, const int32_t * _id_begin=nullptr )
100
+ inline void makeRRInstances (NblInstanceRRInstanceCache& instanceCache, MockSceneManager* mock_smgr,
101
+ const MeshBufferRRShapeCache& shapeCache, asset::IAssetManager* _assetManager,
102
+ Iterator _objectsBegin, Iterator _objectsEnd)
76
103
{
77
- core::unordered_map<const video::IGPUMeshBuffer*,MeshBufferRRShapeCache::value_type> GPU2CPUTable;
78
- GPU2CPUTable.reserve (shapeCache.size ());
79
- for (auto record : shapeCache)
80
- {
81
- auto gpumesh = dynamic_cast <video::IGPUMeshBuffer*>(_assetManager->findGPUObject (record.first ).get ());
82
- if (!gpumesh)
83
- continue ;
84
-
85
- GPU2CPUTable.insert ({gpumesh,record});
86
- }
87
-
88
- auto * id_it = _id_begin;
89
- for (auto it=_begin; it!=_end; it++,id_it++)
104
+ for (auto it=_objectsBegin; it!=_objectsEnd; it++)
90
105
{
91
- irr::scene::IMeshSceneNode* node = *it;
92
- makeInstance (instanceCache,GPU2CPUTable,node,_id_begin ? id_it: nullptr );
106
+ const MockSceneManager::ObjectGUID objectGUID = *it;
107
+ makeInstance (instanceCache,mock_smgr,shapeCache,_assetManager,objectGUID );
93
108
}
94
109
}
95
110
@@ -127,37 +142,43 @@ class Manager final : public core::IReferenceCounted
127
142
}
128
143
129
144
130
- inline void update (const MeshNodeRRInstanceCache& instances)
145
+ template <typename Iterator>
146
+ inline void update (const MockSceneManager* mock_smgr, Iterator _instancesBegin, Iterator _instancesEnd)
131
147
{
132
148
bool needToCommit = false ;
133
- for (const auto & instance : instances )
149
+ for (auto it=_instancesBegin; it!=_instancesEnd; it++ )
134
150
{
135
- auto absoluteTForm = core::matrix3x4SIMD ().set (instance.first ->getAbsoluteTransformation ());
136
- auto * shapes = instance.second .get ();
151
+ const MockSceneManager::ObjectGUID objectID = it->first ;
152
+ const auto * shapeArray = it->second .get ();
153
+
154
+ const auto firstShape = shapeArray->operator [](0 );
137
155
156
+ // TODO: when actually implemented smgr, need a way to pull absolute transforms from GPU or CPU for RR to use
157
+ const auto & absoluteTForm = mock_smgr->getObjectData (objectID).tform ;
138
158
// check if moved
139
159
{
140
- core::matrix4SIMD oldTForm,dummy;
141
- shapes-> operator []( 0 )-> GetTransform (reinterpret_cast <::RadeonRays::matrix&>(oldTForm),reinterpret_cast <::RadeonRays::matrix&>(dummy));
142
- if (absoluteTForm== oldTForm.extractSub3x4 ())
160
+ core::matrix4SIMD oldTForm, dummy;
161
+ firstShape-> GetTransform (reinterpret_cast <::RadeonRays::matrix&>(oldTForm), reinterpret_cast <::RadeonRays::matrix&>(dummy));
162
+ if (absoluteTForm == oldTForm.extractSub3x4 ())
143
163
continue ;
164
+
165
+ needToCommit = true ;
144
166
}
145
167
146
- needToCommit = true ;
168
+
147
169
core::matrix4SIMD world (absoluteTForm);
148
170
149
171
core::matrix3x4SIMD tmp;
150
172
absoluteTForm.getInverse (tmp);
151
173
core::matrix4SIMD worldinv (tmp);
152
174
153
- for (auto it=shapes-> begin (); it!=shapes-> end (); it++ )
154
- (*it) ->SetTransform (reinterpret_cast <::RadeonRays::matrix&>(world),reinterpret_cast <::RadeonRays::matrix&>(worldinv));
175
+ for (auto shape : *shapeArray )
176
+ shape ->SetTransform (reinterpret_cast <::RadeonRays::matrix&>(world),reinterpret_cast <::RadeonRays::matrix&>(worldinv));
155
177
}
156
178
157
179
if (needToCommit)
158
180
rr->Commit ();
159
181
}
160
- #endif
161
182
162
183
inline bool hasImplicitCL2GLSync () const { return m_automaticOpenCLSync; }
163
184
@@ -170,12 +191,10 @@ class Manager final : public core::IReferenceCounted
170
191
Manager (video::IVideoDriver* _driver, cl_context context, bool automaticOpenCLSync);
171
192
~Manager ();
172
193
173
- void makeShape (MeshBufferRRShapeCache& shapeCache, const asset::ICPUMeshBuffer* mb);
174
- #ifdef TODO
175
- void makeInstance ( MeshNodeRRInstanceCache& instanceCache,
176
- const core::unordered_map<const video::IGPUMeshBuffer*,MeshBufferRRShapeCache::value_type>& GPU2CPUTable,
177
- scene::IMeshSceneNode* node, const int32_t * id_it);
178
- #endif
194
+ void makeShape (core::unordered_map<const asset::ICPUMeshBuffer*,::RadeonRays::Shape*>& cpuCache, const asset::ICPUMeshBuffer* mb);
195
+ void makeInstance ( NblInstanceRRInstanceCache& instanceCache, MockSceneManager* mock_smgr,
196
+ MeshBufferRRShapeCache& shapeCache, asset::IAssetManager* _assetManager,
197
+ MockSceneManager::ObjectGUID objectID);
179
198
180
199
video::IVideoDriver* driver;
181
200
::RadeonRays::IntersectionApi* rr;
0 commit comments