Skip to content

Commit 01aa95a

Browse files
committed
Added program selection step
1 parent c5cfdb8 commit 01aa95a

File tree

2 files changed

+520
-18
lines changed

2 files changed

+520
-18
lines changed

RadeonRays/src/intersector/intersector_lds.cpp

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,55 @@ namespace RadeonRays
3737

3838
struct IntersectorLDS::GpuData
3939
{
40+
struct Program
41+
{
42+
Program(Calc::Device *device)
43+
: device(device)
44+
, executable(nullptr)
45+
, isect_func(nullptr)
46+
, occlude_func(nullptr)
47+
{
48+
}
49+
50+
~Program()
51+
{
52+
executable->DeleteFunction(isect_func);
53+
executable->DeleteFunction(occlude_func);
54+
device->DeleteExecutable(executable);
55+
}
56+
57+
Calc::Device *device;
58+
59+
Calc::Executable *executable;
60+
Calc::Function *isect_func;
61+
Calc::Function *occlude_func;
62+
};
63+
4064
// Device
4165
Calc::Device *device;
4266
// BVH nodes
4367
Calc::Buffer *bvh;
4468
// Traversal stack
4569
Calc::Buffer *stack;
4670

47-
Calc::Executable *executable;
48-
Calc::Function *isect_func;
49-
Calc::Function *occlude_func;
71+
Program *prog;
72+
Program bvh_prog;
73+
Program qbvh_prog;
5074

5175
GpuData(Calc::Device *device)
5276
: device(device)
5377
, bvh(nullptr)
5478
, stack(nullptr)
55-
, executable(nullptr)
56-
, isect_func(nullptr)
57-
, occlude_func(nullptr)
79+
, prog(nullptr)
80+
, bvh_prog(device)
81+
, qbvh_prog(device)
5882
{
5983
}
6084

6185
~GpuData()
6286
{
6387
device->DeleteBuffer(bvh);
6488
device->DeleteBuffer(stack);
65-
executable->DeleteFunction(isect_func);
66-
executable->DeleteFunction(occlude_func);
67-
device->DeleteExecutable(executable);
6889
}
6990
};
7091

@@ -87,32 +108,40 @@ namespace RadeonRays
87108

88109
int numheaders = sizeof(headers) / sizeof(const char *);
89110

90-
m_gpuData->executable = m_device->CompileExecutable("../RadeonRays/src/kernels/CL/intersect_bvh2_lds.cl", headers, numheaders, buildopts.c_str());
111+
m_gpuData->bvh_prog.executable = m_device->CompileExecutable("../RadeonRays/src/kernels/CL/intersect_bvh2_lds.cl", headers, numheaders, buildopts.c_str());
112+
m_gpuData->qbvh_prog.executable = m_device->CompileExecutable("../RadeonRays/src/kernels/CL/intersect_bvh2_lds_fp16.cl", headers, numheaders, buildopts.c_str());
91113
}
92114
else
93115
{
94116
// TODO: implement (gboisse)
95117
assert(device->GetPlatform() == Calc::Platform::kVulkan);
96-
m_gpuData->executable = m_device->CompileExecutable("../RadeonRays/src/kernels/GLSL/bvh2.comp", nullptr, 0, buildopts.c_str());
118+
m_gpuData->bvh_prog.executable = m_device->CompileExecutable("../RadeonRays/src/kernels/GLSL/bvh2.comp", nullptr, 0, buildopts.c_str());
119+
m_gpuData->qbvh_prog.executable = m_device->CompileExecutable("../RadeonRays/src/kernels/GLSL/bvh2_fp16.comp", nullptr, 0, buildopts.c_str());
97120
}
98121
#else
99122
#if USE_OPENCL
100123
if (device->GetPlatform() == Calc::Platform::kOpenCL)
101124
{
102-
m_gpuData->executable = m_device->CompileExecutable(g_intersect_bvh2_lds_opencl, std::strlen(g_intersect_bvh2_lds_opencl), buildopts.c_str());
125+
m_gpuData->bvh_prog.executable = m_device->CompileExecutable(g_intersect_bvh2_lds_opencl, std::strlen(g_intersect_bvh2_lds_opencl), buildopts.c_str());
126+
m_gpuData->qbvh_prog.executable = m_device->CompileExecutable(g_intersect_bvh2_lds_fp16_opencl, std::strlen(g_intersect_bvh2_lds_opencl), buildopts.c_str());
103127
}
104128
#endif
105129
#if USE_VULKAN
106-
if (m_gpudata->executable == nullptr && device->GetPlatform() == Calc::Platform::kVulkan)
130+
if (device->GetPlatform() == Calc::Platform::kVulkan)
107131
{
108132
// TODO: implement (gboisse)
109-
m_gpuData->executable = m_device->CompileExecutable(g_bvh2_vulkan, std::strlen(g_bvh2_vulkan), buildopts.c_str());
133+
if (m_gpudata->bvh_prog.executable == nullptr)
134+
m_gpuData->executable = m_device->CompileExecutable(g_bvh2_vulkan, std::strlen(g_bvh2_vulkan), buildopts.c_str());
135+
if (m_gpuData->qbvh_prog.executable == nullptr)
136+
m_gpuData->executable = m_device->CompileExecutable(g_bvh2_fp16_vulkan, std::strlen(g_bvh2_fp16_vulkan), buildopts.c_str());
110137
}
111138
#endif
112139
#endif
113140

114-
m_gpuData->isect_func = m_gpuData->executable->CreateFunction("intersect_main");
115-
m_gpuData->occlude_func = m_gpuData->executable->CreateFunction("occluded_main");
141+
m_gpuData->bvh_prog.isect_func = m_gpuData->bvh_prog.executable->CreateFunction("intersect_main");
142+
m_gpuData->qbvh_prog.isect_func = m_gpuData->qbvh_prog.executable->CreateFunction("intersect_main");
143+
m_gpuData->bvh_prog.occlude_func = m_gpuData->bvh_prog.executable->CreateFunction("occluded_main");
144+
m_gpuData->qbvh_prog.occlude_func = m_gpuData->qbvh_prog.executable->CreateFunction("occluded_main");
116145
}
117146

118147
void IntersectorLDS::Process(const World &world)
@@ -185,6 +214,9 @@ namespace RadeonRays
185214

186215
e->Wait();
187216
m_device->DeleteEvent(e);
217+
218+
// Select intersection program
219+
m_gpuData->prog = &m_gpuData->bvh_prog;
188220
}
189221
else
190222
{
@@ -214,6 +246,9 @@ namespace RadeonRays
214246

215247
e->Wait();
216248
m_device->DeleteEvent(e);
249+
250+
// Select intersection program
251+
m_gpuData->prog = &m_gpuData->qbvh_prog;
217252
}
218253

219254
// Make sure everything is committed
@@ -234,7 +269,8 @@ namespace RadeonRays
234269
m_gpuData->stack = m_device->CreateBuffer(stack_size, Calc::BufferType::kWrite);
235270
}
236271

237-
auto &func = m_gpuData->isect_func;
272+
assert(m_gpuData->prog);
273+
auto &func = m_gpuData->prog->isect_func;
238274

239275
// Set args
240276
int arg = 0;
@@ -264,7 +300,8 @@ namespace RadeonRays
264300
m_gpuData->stack = m_device->CreateBuffer(stack_size, Calc::BufferType::kWrite);
265301
}
266302

267-
auto &func = m_gpuData->occlude_func;
303+
assert(m_gpuData->prog);
304+
auto &func = m_gpuData->prog->occlude_func;
268305

269306
// Set args
270307
int arg = 0;

0 commit comments

Comments
 (0)