Skip to content

Commit 8aa95c1

Browse files
authored
Merge pull request #186 from gboisse/expose_bvh
Unity hack for BVH access
2 parents 95b4e28 + 24bed60 commit 8aa95c1

19 files changed

+93
-10
lines changed

Calc/inc/device.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ namespace Calc
7777
virtual Buffer* CreateBuffer(std::size_t size, std::uint32_t flags, void* initdata) = 0;
7878
virtual void DeleteBuffer(Buffer* buffer) = 0;
7979

80+
// Unity hack for accessing internal BVH
81+
virtual void* GetNativeHandle(Buffer const* buffer) const = 0;
82+
8083
// Data movement
8184
// Calls are blocking if passed nullptr for an event, otherwise use Event to sync
8285
virtual void ReadBuffer(Buffer const* buffer, std::uint32_t queue, std::size_t offset, std::size_t size, void* dst, Event** e) const = 0;

Calc/src/device_clw.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ namespace Calc
295295
delete buffer;
296296
}
297297

298+
void* DeviceClw::GetNativeHandle(Buffer const* buffer) const
299+
{
300+
BufferClw const* bufferClw = static_cast<BufferClw const*>(buffer);
301+
if (!bufferClw)
302+
return nullptr;
303+
return bufferClw->GetData();
304+
}
305+
298306
void DeviceClw::ReadBuffer(Buffer const* buffer, std::uint32_t queue, std::size_t offset, std::size_t size, void* dst, Event** e) const
299307
{
300308
auto buffer_clw = static_cast<BufferClw const*>(buffer);
@@ -574,7 +582,7 @@ namespace Calc
574582
{
575583
m_event_pool.push(e);
576584
}
577-
585+
578586
Buffer* DeviceClw::CreateBuffer(cl_mem buffer)
579587
{
580588
try
@@ -587,7 +595,6 @@ namespace Calc
587595
}
588596
}
589597

590-
591598
class PrimitivesClw : public Primitives
592599
{
593600
public:

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

@@ -48,6 +48,9 @@ namespace Calc
4848
Buffer* CreateBuffer(std::size_t size, std::uint32_t flags, void* initdata) override;
4949
void DeleteBuffer(Buffer* buffer) override;
5050

51+
// Unity hack for accessing internal BVH
52+
void* GetNativeHandle(Buffer const* buffer) const override;
53+
5154
// Data movement
5255
void ReadBuffer(Buffer const* buffer, std::uint32_t queue, std::size_t offset, std::size_t size, void* dst, Event** e) const override;
5356
void WriteBuffer(Buffer const* buffer, std::uint32_t queue, std::size_t offset, std::size_t size, void* src, Event** e) override;

Calc/src/device_vkw.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ namespace Calc
173173
}
174174
}
175175

176+
void* DeviceVulkanw::GetNativeHandle(Buffer const* buffer) const
177+
{
178+
return nullptr;
179+
}
180+
176181
// Data movement
177182
void DeviceVulkanw::ReadBuffer( Buffer const* buffer, std::uint32_t queue, std::size_t offset, std::size_t size, void* dst, Event** e ) const
178183
{

Calc/src/device_vkw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ namespace Calc
5454
Buffer* CreateBuffer( std::size_t size, std::uint32_t flags, void* initdata ) override;
5555
void DeleteBuffer( Buffer* buffer ) override;
5656

57+
// Unity hack for accessing internal BVH
58+
void* GetNativeHandle(Buffer const* buffer) const override;
59+
5760
// Data movement
5861
void ReadBuffer( Buffer const* buffer, std::uint32_t queue, std::size_t offset, std::size_t size, void* dst, Event** e ) const override;
5962
void WriteBuffer( Buffer const* buffer, std::uint32_t queue, std::size_t offset, std::size_t size, void* src, Event** e ) override;

RadeonRays/include/radeon_rays.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ THE SOFTWARE.
2929
#include "math/ray.h"
3030
#include "math/mathutils.h"
3131
#include <cstdint>
32-
32+
3333
#define RADEONRAYS_API_VERSION 2.0
3434

3535
#if !RR_STATIC_LIBRARY
@@ -280,6 +280,12 @@ namespace RadeonRays
280280
// The call is asynchronous. Event pointer mights be nullptrs.
281281
virtual void QueryOcclusion(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitresults, Event const* waitevent, Event** event) const = 0;
282282

283+
/******************************************
284+
Unity hack for accessing internal BVH
285+
******************************************/
286+
// Gets the BVH
287+
virtual void* GetBvh() const = 0;
288+
283289
/******************************************
284290
Utility
285291
******************************************/

RadeonRays/src/api/radeon_rays_impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ namespace RadeonRays
145145
m_device->QueryOcclusion(rays, numrays, maxrays, hitresults, waitevent, event);
146146
}
147147

148+
void* IntersectionApiImpl::GetBvh() const
149+
{
150+
return m_device->GetBvh();
151+
}
152+
148153
void IntersectionApiImpl::DeleteEvent(Event* event) const
149154
{
150155
m_device->DeleteEvent(event);

RadeonRays/src/api/radeon_rays_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ namespace RadeonRays
121121
// The call is asynchronous. Event pointer mights be nullptrs.
122122
void QueryOcclusion(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitresults, Event const* waitevent, Event** event) const override;
123123

124+
/******************************************
125+
Unity hack
126+
******************************************/
127+
// Gets the BVH
128+
void* GetBvh() const override;
129+
124130
/******************************************
125131
Utility
126132
******************************************/

RadeonRays/src/device/calc_intersection_device.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ namespace RadeonRays
334334
{
335335
m_intersector->QueryOcclusion(0, ray_buffer, numrays_buffer, maxrays, hit_buffer, e, nullptr);
336336
}
337+
}
337338

339+
void* CalcIntersectionDevice::GetBvh() const
340+
{
341+
return m_intersector->GetBvh();
338342
}
339343

340344
CalcEventHolder* CalcIntersectionDevice::CreateEventHolder() const

RadeonRays/src/device/calc_intersection_device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ 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+
void* GetBvh() const override;
70+
6971
Calc::Platform GetPlatform() const { return m_device->GetPlatform(); }
7072
protected:
7173
CalcEventHolder* CreateEventHolder() const;

RadeonRays/src/device/embree_intersection_device.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ namespace RadeonRays
496496
Throw("Not implemented for embree device.");
497497
}
498498

499+
void* EmbreeIntersectionDevice::GetBvh() const
500+
{
501+
return nullptr;
502+
}
503+
499504
RTCScene EmbreeIntersectionDevice::GetEmbreeMesh(const RadeonRays::Mesh* mesh)
500505
{
501506
if (m_meshes.count(mesh))

RadeonRays/src/device/embree_intersection_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace RadeonRays
5353
void QueryOcclusion(Buffer const* rays, int numrays, Buffer* hitresults, Event const* waitevent, Event** event) const override;
5454
void QueryIntersection(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitinfos, Event const* waitevent, Event** event) const override;
5555
void QueryOcclusion(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitresults, Event const* waitevent, Event** event) const override;
56+
void* GetBvh() const override;
5657

5758
protected:
5859
RTCScene GetEmbreeMesh(const Mesh*);

RadeonRays/src/device/intersection_device.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ namespace RadeonRays
8888
// The call waits until waitevent is resolved (on a target device) if waitevent != nullptr.
8989
// The call is non-blocking if event is passed it, otherwise (event == nullptr) it is blocking.
9090
virtual void QueryOcclusion(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hits, Event const* waitevent, Event** event) const = 0;
91-
91+
92+
// Gets the BVH
93+
virtual void* GetBvh() const = 0;
94+
9295
IntersectionDevice(IntersectionDevice const&) = delete;
9396
IntersectionDevice& operator = (IntersectionDevice const&) = delete;
9497
};

RadeonRays/src/intersector/intersector.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ namespace RadeonRays
2828
{
2929
return true;
3030
}
31-
31+
32+
void* Intersector::GetBvhImpl() const
33+
{
34+
return nullptr;
35+
}
36+
3237
void Intersector::QueryIntersection(std::uint32_t queue_idx, Calc::Buffer const *rays, std::uint32_t num_rays,
3338
Calc::Buffer *hits, Calc::Event const *wait_event, Calc::Event **event) const
3439
{
@@ -56,4 +61,9 @@ namespace RadeonRays
5661
{
5762
Occluded(queue_idx, rays, num_rays, max_rays, hits, wait_event, event);
5863
}
64+
65+
void* Intersector::GetBvh() const
66+
{
67+
return GetBvhImpl();
68+
}
5969
}

RadeonRays/src/intersector/intersector.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ namespace RadeonRays
135135
void QueryOcclusion(std::uint32_t queue_idx, Calc::Buffer const* rays, Calc::Buffer const* num_rays,
136136
std::uint32_t max_rays, Calc::Buffer* hits, Calc::Event const* wait_event, Calc::Event** event) const;
137137

138+
/*
139+
\brief Gets the BVH
140+
\returns The requested BVH
141+
*/
142+
void* GetBvh() const;
143+
138144
// Disallow intersector copies
139145
Intersector(Intersector const&) = delete;
140146
Intersector& operator = (Intersector const&) = delete;
@@ -144,6 +150,9 @@ namespace RadeonRays
144150
virtual void Process(World const& world) = 0;
145151
// Compatibility check implemetation
146152
virtual bool IsCompatibleImpl(World const& world) const;
153+
// Gets BVH implementation.
154+
virtual void* GetBvhImpl() const;
155+
147156
// Intersection implementation
148157
virtual void Intersect(std::uint32_t queue_idx, Calc::Buffer const *rays, Calc::Buffer const *num_rays,
149158
std::uint32_t max_rays, Calc::Buffer *hits,

RadeonRays/src/intersector/intersector_lds.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ THE SOFTWARE.
2424
#include "calc.h"
2525
#include "executable.h"
2626
#include "../accelerator/bvh2.h"
27+
#include "../device/calc_holder.h"
2728
#include "../primitive/mesh.h"
2829
#include "../primitive/instance.h"
2930
#include "../translator/q_bvh_translator.h"
31+
#include "../../Calc/src/device_clw.h"
3032
#include "../world/world.h"
3133

3234
namespace RadeonRays
@@ -258,6 +260,13 @@ namespace RadeonRays
258260
}
259261
}
260262

263+
void* IntersectorLDS::GetBvhImpl() const
264+
{
265+
if (m_device->GetPlatform() == Calc::Platform::kOpenCL)
266+
return static_cast<Calc::DeviceClw *>(m_device)->GetNativeHandle(m_gpudata->bvh);
267+
return NULL;
268+
}
269+
261270
void IntersectorLDS::Intersect(std::uint32_t queue_idx, const Calc::Buffer *rays, const Calc::Buffer *num_rays,
262271
std::uint32_t max_rays, Calc::Buffer *hits,
263272
const Calc::Event *wait_event, Calc::Event **event) const

RadeonRays/src/intersector/intersector_lds.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace RadeonRays
3636
private:
3737
// World preprocessing implementation
3838
void Process(const World &world) override;
39+
// Gets BVH implementation
40+
void* GetBvhImpl() const override;
3941
// Intersection implementation
4042
void Intersect(std::uint32_t queue_idx, const Calc::Buffer *rays, const Calc::Buffer *num_rays,
4143
std::uint32_t max_rays, Calc::Buffer *hits,

RadeonRays/src/kernels/CL/intersect_bvh2_lds.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ INLINE float2 fast_intersect_bbox2(float3 pmin, float3 pmax, float3 invdir, floa
6262
return (float2)(t0, t1);
6363
}
6464

65-
__attribute__((reqd_work_group_size(64, 1, 1)))
65+
__attribute__((reqd_work_group_size(GROUP_SIZE, 1, 1)))
6666
KERNEL void intersect_main(
6767
// Bvh nodes
6868
GLOBAL const bvh_node *restrict nodes,
@@ -218,7 +218,7 @@ KERNEL void intersect_main(
218218
}
219219
}
220220

221-
__attribute__((reqd_work_group_size(64, 1, 1)))
221+
__attribute__((reqd_work_group_size(GROUP_SIZE, 1, 1)))
222222
KERNEL void occluded_main(
223223
// Bvh nodes
224224
GLOBAL const bvh_node *restrict nodes,

RadeonRays/src/kernels/CL/intersect_bvh2_lds_fp16.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ INLINE void stack_push(
127127
*lds_sptr = *lds_sptr + 1;
128128
}
129129

130-
__attribute__((reqd_work_group_size(64, 1, 1)))
130+
__attribute__((reqd_work_group_size(GROUP_SIZE, 1, 1)))
131131
KERNEL void intersect_main(
132132
// Bvh nodes
133133
GLOBAL const bvh_node *restrict nodes,
@@ -306,7 +306,7 @@ KERNEL void intersect_main(
306306
}
307307
}
308308

309-
__attribute__((reqd_work_group_size(64, 1, 1)))
309+
__attribute__((reqd_work_group_size(GROUP_SIZE, 1, 1)))
310310
KERNEL void occluded_main(
311311
// Bvh nodes
312312
GLOBAL const bvh_node *restrict nodes,

0 commit comments

Comments
 (0)