-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathradeon_rays_impl.h
More file actions
156 lines (130 loc) · 7.02 KB
/
radeon_rays_impl.h
File metadata and controls
156 lines (130 loc) · 7.02 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
/**********************************************************************
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.
********************************************************************/
#ifndef INTERSECTIONAPI_IMPL
#define INTERSECTIONAPI_IMPL
#include <atomic>
#include "radeon_rays.h"
#include "../world/world.h"
namespace RadeonRays
{
class IntersectionDevice;
/// IntersectionApi is designed to provide fast means for ray-scene intersection
/// for AMD architectures. It effectively absracts underlying AMD hardware and
/// software stack and allows user to issue low-latency batched ray queries.
/// The API has 2 major workflows:
/// - Fast path: the data is expected to be in host memory as well as the returned result is put there
/// - Complete path: the data can be put into remote memory allocated with API and can be accessed.
/// by the app directly in remote memory space.
///
class IntersectionApiImpl : public IntersectionApi
{
public:
/******************************************
Geometry manipulation
******************************************/
// Fast path functions to create entities from host memory
// The mesh might be mixed quad\triangle mesh which is determined
// by numfacevertices array containing numfaces entries describing
// the number of vertices for current face (3 or 4)
// The call is blocking, so the returned value is ready upon return.
Shape* 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 numfaces
) const override;
// Create an instance of a shape with its own transform (set via Shape interface).
// The call is blocking, so the returned value is ready upon return.
Shape* CreateInstance(Shape const* shape) const override;
// Delete the shape (to simplify DLL boundary crossing
void DeleteShape(Shape const* shape) override;
// Attach shape to participate in intersection process
void AttachShape(Shape const* shape) override;
// Detach shape, i.e. it is not going to be considered part of the scene anymore
void DetachShape(Shape const* shape) override;
// Detach all objects
void DetachAll() override;
// Commit all geometry creations/changes
void Commit() override;
//Sets the shape id allocator to its default value (1)
void ResetIdCounter() override;
//Returns true if no shapes are in the world
bool IsWorldEmpty() override;
/******************************************
Memory management
******************************************/
Buffer* CreateBuffer(size_t size, void* initdata) const override;
// Delete the buffer
void DeleteBuffer(Buffer* buffer) const override;
// Map buffer. Event pointer might be nullptr.
// The call is asynchronous.
void MapBuffer(Buffer* buffer, MapType type, size_t offset, size_t size, void** data, Event** event) const override;
// Unmap buffer
void UnmapBuffer(Buffer* buffer, void* ptr, Event** event) const override;
/******************************************
Events handling
*******************************************/
void DeleteEvent(Event* event) const override;
/******************************************
Ray casting
******************************************/
// Complete path:
// Find closest intersection
// TODO: do we need to modify rays' intersection range?
// TODO: SoA vs AoS?
// The call is asynchronous. Event pointers might be nullptrs.
void QueryIntersection(Buffer const* rays, int numrays, Buffer* hitinfos, Event const* waitevent, Event** event) const override;
// Find any intersection.
// The call is asynchronous. Event pointer mights be nullptrs.
void QueryOcclusion(Buffer const* rays, int numrays, Buffer* hitresults, Event const* waitevent, Event** event) const override;
void 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 override;
// Find closest intersection, number of rays is in remote memory
// TODO: do we need to modify rays' intersection range?
// TODO: SoA vs AoS?
// The call is asynchronous. Event pointers might be nullptrs.
void QueryIntersection(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitinfos, Event const* waitevent, Event** event) const override;
// Find any intersection.
// The call is asynchronous. Event pointer mights be nullptrs.
void QueryOcclusion(Buffer const* rays, Buffer const* numrays, int maxrays, Buffer* hitresults, Event const* waitevent, Event** event) const override;
/******************************************
Utility
******************************************/
// Set API global option: string
void SetOption(char const* name, char const* value) override;
// Set API global option: float
void SetOption(char const* name, float value) override;
IntersectionDevice* GetDevice() const { return m_device.get(); }
IntersectionApiImpl(IntersectionDevice* device);
protected:
friend class IntersectionApi;
~IntersectionApiImpl() = default;
private:
// Container for all shapes
World world_;
// Shape ID tracker
mutable std::atomic<Id> nextid_;
// Intersection device
std::unique_ptr<IntersectionDevice> m_device;
};
}
#endif