Skip to content

Commit 56a5ea9

Browse files
committed
Refactored getting native buffer for BVH
1 parent f44e29a commit 56a5ea9

12 files changed

+28
-18
lines changed

Calc/src/device_clw.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ namespace Calc
574574
{
575575
m_event_pool.push(e);
576576
}
577-
577+
578578
Buffer* DeviceClw::CreateBuffer(cl_mem buffer)
579579
{
580580
try
@@ -587,6 +587,13 @@ namespace Calc
587587
}
588588
}
589589

590+
cl_mem DeviceClw::GetNativeHandle(Buffer const* buffer)
591+
{
592+
BufferClw const* bufferClw = static_cast<BufferClw const*>(buffer);
593+
if (!bufferClw)
594+
return nullptr;
595+
return bufferClw->GetData();
596+
}
590597

591598
class PrimitivesClw : public Primitives
592599
{

Calc/src/device_clw.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ THE SOFTWARE.
2323

2424
#include "device.h"
2525
#include "device_cl.h"
26-
#include "CLW.h"
26+
#include "../../CLW/CLW.h"
2727

2828
#include <queue>
2929

@@ -89,6 +89,9 @@ namespace Calc
8989

9090
Platform GetPlatform() const override { return Platform::kOpenCL; }
9191

92+
// Unity hack for accessing internal BVH
93+
cl_mem GetNativeHandle(Buffer const* buffer);
94+
9295
protected:
9396
EventClw* CreateEventClw() const;
9497
void ReleaseEventClw(EventClw* e) const;

RadeonRays/include/radeon_rays.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ namespace RadeonRays
288288
Unity hack for accessing internal BVH
289289
******************************************/
290290
// Gets the BVH
291-
virtual Buffer const *GetBvh() const = 0;
291+
virtual void* GetBvh() const = 0;
292292

293293
/******************************************
294294
Utility

RadeonRays/src/api/radeon_rays_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace RadeonRays
145145
m_device->QueryOcclusion(rays, numrays, maxrays, hitresults, waitevent, event);
146146
}
147147

148-
Buffer const* IntersectionApiImpl::GetBvh() const
148+
void* IntersectionApiImpl::GetBvh() const
149149
{
150150
return m_device->GetBvh();
151151
}

RadeonRays/src/api/radeon_rays_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ namespace RadeonRays
125125
Unity hack
126126
******************************************/
127127
// Gets the BVH
128-
Buffer const *GetBvh() const override;
128+
void* GetBvh() const override;
129129

130130
/******************************************
131131
Utility

RadeonRays/src/device/calc_intersection_device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ namespace RadeonRays
336336
}
337337
}
338338

339-
Buffer const* CalcIntersectionDevice::GetBvh() const
339+
void* CalcIntersectionDevice::GetBvh() const
340340
{
341341
return m_intersector->GetBvh();
342342
}

RadeonRays/src/device/calc_intersection_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace RadeonRays
6666

6767
void QueryOcclusion(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitresults, Event const* waitevent, Event** event) const override;
6868

69-
Buffer const* GetBvh() const override;
69+
void* GetBvh() const override;
7070

7171
Calc::Platform GetPlatform() const { return m_device->GetPlatform(); }
7272
protected:

RadeonRays/src/device/intersection_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace RadeonRays
9090
virtual void QueryOcclusion(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hits, Event const* waitevent, Event** event) const = 0;
9191

9292
// Gets the BVH
93-
virtual Buffer const* GetBvh() const = 0;
93+
virtual void* GetBvh() const = 0;
9494

9595
IntersectionDevice(IntersectionDevice const&) = delete;
9696
IntersectionDevice& operator = (IntersectionDevice const&) = delete;

RadeonRays/src/intersector/intersector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace RadeonRays
2929
return true;
3030
}
3131

32-
Buffer const* Intersector::GetBvhImpl() const
32+
void* Intersector::GetBvhImpl() const
3333
{
3434
return nullptr;
3535
}
@@ -62,7 +62,7 @@ namespace RadeonRays
6262
Occluded(queue_idx, rays, num_rays, max_rays, hits, wait_event, event);
6363
}
6464

65-
Buffer const* Intersector::GetBvh() const
65+
void* Intersector::GetBvh() const
6666
{
6767
return GetBvhImpl();
6868
}

RadeonRays/src/intersector/intersector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ namespace RadeonRays
139139
\brief Gets the BVH
140140
\returns The requested BVH
141141
*/
142-
Buffer const* GetBvh() const;
142+
void* GetBvh() const;
143143

144144
// Disallow intersector copies
145145
Intersector(Intersector const&) = delete;
@@ -151,7 +151,7 @@ namespace RadeonRays
151151
// Compatibility check implemetation
152152
virtual bool IsCompatibleImpl(World const& world) const;
153153
// Gets BVH implementation.
154-
virtual Buffer const* GetBvhImpl() const;
154+
virtual void* GetBvhImpl() const;
155155

156156
// Intersection implementation
157157
virtual void Intersect(std::uint32_t queue_idx, Calc::Buffer const *rays, Calc::Buffer const *num_rays,

RadeonRays/src/intersector/intersector_lds.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ THE SOFTWARE.
2828
#include "../primitive/mesh.h"
2929
#include "../primitive/instance.h"
3030
#include "../translator/q_bvh_translator.h"
31+
#include "../../Calc/src/device_clw.h"
3132
#include "../world/world.h"
3233

3334
namespace RadeonRays
@@ -72,8 +73,6 @@ namespace RadeonRays
7273
// Traversal stack
7374
Calc::Buffer *stack;
7475

75-
CalcBufferHolder bvhHolder;
76-
7776
Program *prog;
7877
Program bvh_prog;
7978
Program qbvh_prog;
@@ -82,7 +81,6 @@ namespace RadeonRays
8281
: device(device)
8382
, bvh(nullptr)
8483
, stack(nullptr)
85-
, bvhHolder(device, bvh)
8684
, prog(nullptr)
8785
, bvh_prog(device)
8886
, qbvh_prog(device)
@@ -262,9 +260,11 @@ namespace RadeonRays
262260
}
263261
}
264262

265-
Buffer const* IntersectorLDS::GetBvhImpl() const
263+
void* IntersectorLDS::GetBvhImpl() const
266264
{
267-
return &m_gpudata->bvhHolder;
265+
if (m_device->GetPlatform() == Calc::Platform::kOpenCL)
266+
return static_cast<Calc::DeviceClw *>(m_device)->GetNativeHandle(m_gpudata->bvh);
267+
return NULL;
268268
}
269269

270270
void IntersectorLDS::Intersect(std::uint32_t queue_idx, const Calc::Buffer *rays, const Calc::Buffer *num_rays,

RadeonRays/src/intersector/intersector_lds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace RadeonRays
3737
// World preprocessing implementation
3838
void Process(const World &world) override;
3939
// Gets BVH implementation
40-
Buffer const* GetBvhImpl() const override;
40+
void* GetBvhImpl() const override;
4141
// Intersection implementation
4242
void Intersect(std::uint32_t queue_idx, const Calc::Buffer *rays, const Calc::Buffer *num_rays,
4343
std::uint32_t max_rays, Calc::Buffer *hits,

0 commit comments

Comments
 (0)