@@ -71,7 +71,6 @@ namespace RadeonRays
71
71
IntersectorLDS::IntersectorLDS (Calc::Device *device)
72
72
: Intersector(device)
73
73
, m_gpuData(new GpuData(device))
74
- , m_bvh(nullptr )
75
74
{
76
75
std::string buildopts;
77
76
#ifdef RR_RAY_MASK
@@ -119,30 +118,36 @@ namespace RadeonRays
119
118
void IntersectorLDS::Process (const World &world)
120
119
{
121
120
// If something has been changed we need to rebuild BVH
122
- if (!m_bvh || world.has_changed () || world.GetStateChange () != ShapeImpl::kStateChangeNone )
121
+ if (!m_gpuData-> bvh || world.has_changed () || world.GetStateChange () != ShapeImpl::kStateChangeNone )
123
122
{
124
123
// Free previous data
125
- if (m_bvh )
124
+ if (m_gpuData-> bvh )
126
125
{
127
126
m_device->DeleteBuffer (m_gpuData->bvh );
128
127
}
129
128
130
129
// Look up build options for world
130
+ auto type = world.options_ .GetOption (" bvh.type" );
131
131
auto builder = world.options_ .GetOption (" bvh.builder" );
132
132
auto nbins = world.options_ .GetOption (" bvh.sah.num_bins" );
133
133
auto tcost = world.options_ .GetOption (" bvh.sah.traversal_cost" );
134
134
135
- bool use_sah = false ;
135
+ bool use_qbvh = true , use_sah = false ;
136
136
int num_bins = (nbins ? static_cast <int >(nbins->AsFloat ()) : 64 );
137
137
float traversal_cost = (tcost ? tcost->AsFloat () : 10 .0f );
138
138
139
+ if (type && type->AsString () == " qbvh" )
140
+ {
141
+ use_qbvh = true ;
142
+ }
143
+
139
144
if (builder && builder->AsString () == " sah" )
140
145
{
141
146
use_sah = true ;
142
147
}
143
148
144
149
// Create the bvh
145
- m_bvh. reset ( new Bvh2 (traversal_cost, num_bins, use_sah) );
150
+ Bvh2 bvh (traversal_cost, num_bins, use_sah);
146
151
147
152
// Partition the array into meshes and instances
148
153
std::vector<const Shape *> shapes (world.shapes_ );
@@ -154,34 +159,62 @@ namespace RadeonRays
154
159
});
155
160
156
161
// TODO: deal with the instance stuff (gboisse)
157
- m_bvh-> Build (shapes.begin (), firstinst);
162
+ bvh. Build (shapes.begin (), firstinst);
158
163
159
- QBvhTranslator translator;
160
- translator.Process (*m_bvh);
164
+ // Upload BVH data to GPU memory
165
+ if (!use_qbvh)
166
+ {
167
+ auto bvh_size_in_bytes = bvh.GetSizeInBytes ();
168
+ m_gpuData->bvh = m_device->CreateBuffer (bvh_size_in_bytes, Calc::BufferType::kRead );
161
169
162
- // Update GPU data
163
- auto bvh_size_in_bytes = translator. GetSizeInBytes () ;
164
- m_gpuData-> bvh = m_device-> CreateBuffer (bvh_size_in_bytes, Calc::BufferType:: kRead ) ;
170
+ // Get the pointer to mapped data
171
+ Calc::Event *e = nullptr ;
172
+ Bvh2::Node *bvhdata = nullptr ;
165
173
166
- // Get the pointer to mapped data
167
- Calc::Event *e = nullptr ;
168
- QBvhTranslator::Node *bvhdata = nullptr ;
174
+ m_device->MapBuffer (m_gpuData->bvh , 0 , 0 , bvh_size_in_bytes, Calc::MapType::kMapWrite , (void **)&bvhdata, &e);
169
175
170
- m_device->MapBuffer (m_gpuData->bvh , 0 , 0 , bvh_size_in_bytes, Calc::MapType::kMapWrite , (void **)&bvhdata, &e);
176
+ e->Wait ();
177
+ m_device->DeleteEvent (e);
171
178
172
- e->Wait ();
173
- m_device->DeleteEvent (e);
179
+ // Copy BVH data
180
+ for (std::size_t i = 0 ; i < bvh.m_nodecount ; ++i)
181
+ bvhdata[i++] = bvh.m_nodes [i];
174
182
175
- // Copy BVH data
176
- std::size_t i = 0 ;
177
- for (auto it = translator.nodes_ .begin (); it != translator.nodes_ .end (); ++it)
178
- bvhdata[i++] = *it;
183
+ // Unmap gpu data
184
+ m_device->UnmapBuffer (m_gpuData->bvh , 0 , bvhdata, &e);
185
+
186
+ e->Wait ();
187
+ m_device->DeleteEvent (e);
188
+ }
189
+ else
190
+ {
191
+ QBvhTranslator translator;
192
+ translator.Process (bvh);
179
193
180
- // Unmap gpu data
181
- m_device->UnmapBuffer (m_gpuData->bvh , 0 , bvhdata, &e);
194
+ // Update GPU data
195
+ auto bvh_size_in_bytes = translator.GetSizeInBytes ();
196
+ m_gpuData->bvh = m_device->CreateBuffer (bvh_size_in_bytes, Calc::BufferType::kRead );
182
197
183
- e->Wait ();
184
- m_device->DeleteEvent (e);
198
+ // Get the pointer to mapped data
199
+ Calc::Event *e = nullptr ;
200
+ QBvhTranslator::Node *bvhdata = nullptr ;
201
+
202
+ m_device->MapBuffer (m_gpuData->bvh , 0 , 0 , bvh_size_in_bytes, Calc::MapType::kMapWrite , (void **)&bvhdata, &e);
203
+
204
+ e->Wait ();
205
+ m_device->DeleteEvent (e);
206
+
207
+ // Copy BVH data
208
+ std::size_t i = 0 ;
209
+ for (auto it = translator.nodes_ .begin (); it != translator.nodes_ .end (); ++it)
210
+ bvhdata[i++] = *it;
211
+
212
+ // Unmap gpu data
213
+ m_device->UnmapBuffer (m_gpuData->bvh , 0 , bvhdata, &e);
214
+
215
+ e->Wait ();
216
+ m_device->DeleteEvent (e);
217
+ }
185
218
186
219
// Make sure everything is committed
187
220
m_device->Finish (0 );
0 commit comments