-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathradeon_rays_impl.cpp
More file actions
215 lines (171 loc) · 6.78 KB
/
radeon_rays_impl.cpp
File metadata and controls
215 lines (171 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/**********************************************************************
Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
********************************************************************/
#include "radeon_rays.h"
#include "radeon_rays_impl.h"
#include "../primitive/mesh.h"
#include "../primitive/instance.h"
#include "../except/except.h"
#include "../device/intersection_device.h"
#if USE_OPENCL
#include "../device/calc_intersection_device_cl.h"
#endif
#if USE_VULKAN
#include "../device/calc_intersection_device_vk.h"
#include <wrappers/buffer.h>
#endif
#include <vector>
#include <cfloat>
namespace RadeonRays
{
IntersectionApiImpl::IntersectionApiImpl(IntersectionDevice* device)
: nextid_(1)
, m_device(device)
{
world_.hint_ = 0;
}
void IntersectionApiImpl::SetOption(char const* name, char const* value)
{
world_.options_.SetValue(name, value);
}
void IntersectionApiImpl::SetOption(char const* name, float value)
{
world_.options_.SetValue(name, value);
}
Shape* IntersectionApiImpl::CreateMesh(
// Position data
float const * vertices, int vnum, int vstride,
// Index data for vertices
int const * indices, int istride,
// Numbers of vertices per face
int const * numfacevertices,
// Number of faces
int numface
) const
{
Mesh* mesh = new Mesh(vertices, vnum, vstride, indices, istride, numfacevertices, numface);
mesh->SetId(nextid_++);
return mesh;
}
Shape* IntersectionApiImpl::CreateInstance(Shape const* shape) const
{
Mesh const* mesh = static_cast<Mesh const*>(shape);
Instance* instance = new Instance(mesh);
instance->SetId(nextid_++);
return instance;
}
void IntersectionApiImpl::DeleteShape(Shape const* shape)
{
delete shape;
}
void IntersectionApiImpl::AttachShape(Shape const* shape)
{
world_.AttachShape(shape);
}
void IntersectionApiImpl::DetachShape(Shape const* shape)
{
world_.DetachShape(shape);
}
void IntersectionApiImpl::DetachAll()
{
world_.DetachAll();
}
void IntersectionApiImpl::Commit()
{
ThrowIf(world_.shapes_.empty(), "Scene is empty.");
m_device->Preprocess(world_);
world_.OnCommit();
}
void IntersectionApiImpl::DeleteBuffer(Buffer* buffer) const
{
m_device->DeleteBuffer(buffer);
}
void IntersectionApiImpl::QueryIntersection(Buffer const* rays, int numrays, Buffer* hitinfos, Event const* waitevent, Event** event) const
{
m_device->QueryIntersection(rays, numrays, hitinfos, waitevent, event);
}
void IntersectionApiImpl::QueryOcclusion(Buffer const* rays, int numrays, Buffer* hitresults, Event const* waitevent, Event** event) const
{
m_device->QueryOcclusion(rays, numrays, hitresults, waitevent, event);
}
void IntersectionApiImpl::QueryOccluded2dSumLinear2(Buffer const* origins, Buffer const* directions, Buffer const* koeffs, Buffer const* offset_directions, Buffer const* offset_koeffs, int numorigins, int numdirections, Buffer* hitresults, Event const* waitevent, Event** event) const
{
m_device->QueryOccluded2dSumLinear2(origins, directions, koeffs, offset_directions, offset_koeffs, numorigins, numdirections, hitresults, waitevent, event);
}
void IntersectionApiImpl::QueryIntersection(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitinfos, Event const* waitevent, Event** event) const
{
m_device->QueryIntersection(rays, numrays, maxrays, hitinfos, waitevent, event);
}
void IntersectionApiImpl::QueryOcclusion(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitresults, Event const* waitevent, Event** event) const
{
m_device->QueryOcclusion(rays, numrays, maxrays, hitresults, waitevent, event);
}
void IntersectionApiImpl::DeleteEvent(Event* event) const
{
m_device->DeleteEvent(event);
}
Buffer* IntersectionApiImpl::CreateBuffer(size_t size, void* initdata) const
{
return m_device->CreateBuffer(size, initdata);
}
void IntersectionApiImpl::MapBuffer(Buffer* buffer, MapType type, size_t offset, size_t size, void** data, Event** event) const
{
return m_device->MapBuffer(buffer, type, offset, size, data, event);
}
void IntersectionApiImpl::UnmapBuffer(Buffer* buffer, void* ptr, Event** event) const
{
return m_device->UnmapBuffer(buffer, ptr, event);
}
void IntersectionApiImpl::ResetIdCounter()
{
nextid_ = 1;
}
bool IntersectionApiImpl::IsWorldEmpty()
{
return world_.shapes_.empty();
}
#ifdef USE_OPENCL
RRAPI Buffer* CreateFromOpenClBuffer(RadeonRays::IntersectionApi* api, cl_mem buffer)
{
auto apii = static_cast<IntersectionApiImpl*>(api);
// we use dynamic cast (internal only) because otherwise have to
// expose platform to intersection api which feel wrong esp. in future
// if we support multi backend unified intersection api
auto cldev = dynamic_cast<CalcIntersectionDeviceCl*>(apii->GetDevice());
if (cldev)
{
return cldev->CreateBuffer(buffer);
}
Throw("CL interop not supported");
return nullptr;
}
#endif
#ifdef USE_VULKAN
RRAPI Buffer* CreateFromVulkanBuffer(RadeonRays::IntersectionApi* api, Anvil::Buffer* buffer)
{
auto apii = static_cast<IntersectionApiImpl*>(api);
auto cldev = dynamic_cast<CalcIntersectionDeviceVK*>(apii->GetDevice());
if (cldev)
{
return cldev->AdoptBuffer(buffer);
}
Throw("Vulkan interop not supported");
return nullptr;
}
#endif
}