OWL
Loading...
Searching...
No Matches
InstanceGroup.h
1// ======================================================================== //
2// Copyright 2019-2020 Ingo Wald //
3// //
4// Licensed under the Apache License, Version 2.0 (the "License"); //
5// you may not use this file except in compliance with the License. //
6// You may obtain a copy of the License at //
7// //
8// http://www.apache.org/licenses/LICENSE-2.0 //
9// //
10// Unless required by applicable law or agreed to in writing, software //
11// distributed under the License is distributed on an "AS IS" BASIS, //
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
13// See the License for the specific language governing permissions and //
14// limitations under the License. //
15// ======================================================================== //
16
17#pragma once
18
19#include "Group.h"
20
21namespace owl {
22
24 struct InstanceGroup : public Group {
25 typedef std::shared_ptr<InstanceGroup> SP;
26
29 struct DeviceData : public Group::DeviceData {
30 typedef std::shared_ptr<DeviceData> SP;
31
33 DeviceData(const DeviceContext::SP &device);
34
35 DeviceMemory optixInstanceBuffer;
36
39 DeviceMemory outputBuffer;
40
43 CUfunction instanceFuncKernel = 0;
44
48 };
49
51 InstanceGroup(Context *const context,
52 size_t numChildren,
53 Group::SP *groups,
54 unsigned int buildFlags,
56
58 std::string toString() const override;
59
61 void setChild(size_t childID, Group::SP child);
62
64 void setTransform(size_t childID, const affine3f &xfm);
65
67 void setTransforms(uint32_t timeStep,
68 const float *floatsForThisStimeStep,
69 OWLMatrixFormat matrixFormat);
70
71 /* set instance IDs to use for the children - MUST be an array of
72 children.size() items */
73 void setInstanceIDs(const uint32_t *instanceIDs);
74
75 /* set visibility masks to use for the children - MUST be an array of
76 children.size() items */
77 void setVisibilityMasks(const uint8_t *visibilityMasks);
78
80 void setInstanceProg(Module::SP module,
81 const std::string &progName);
82
84 void setMotionInstanceProg(Module::SP module,
85 const std::string &progName);
86
89
92
93 void buildAccel(LaunchParams::SP launchParams = nullptr) override;
94 void refitAccel(LaunchParams::SP launchParams = nullptr) override;
95
97 RegisteredObject::DeviceData::SP createOn(const DeviceContext::SP &device) override;
98
100 inline DeviceData &getDD(const DeviceContext::SP &device) const;
101
102 template<bool FULL_REBUILD>
103 void staticBuildOn(const DeviceContext::SP &device);
104 template<bool FULL_REBUILD>
105 void motionBlurBuildOn(const DeviceContext::SP &device);
106
107 template<bool FULL_REBUILD>
108 void staticDeviceBuildOn(const DeviceContext::SP &device, LaunchParams::SP launchParams);
109 template<bool FULL_REBUILD>
110 void motionBlurDeviceBuildOn(const DeviceContext::SP &device, LaunchParams::SP launchParams);
111
114 int getSBTOffset() const override { return 0; }
115
118
122 std::vector<Group::SP> children;
123
126 std::vector<affine3f> transforms[2];
127
131 std::vector<uint32_t> instanceIDs;
132
136 std::vector<uint8_t> visibilityMasks;
137
138 constexpr static unsigned int defaultBuildFlags =
139 OPTIX_BUILD_FLAG_PREFER_FAST_TRACE;
140
141 protected:
142 const unsigned int buildFlags;
143
146
149
152 };
153
154 // ------------------------------------------------------------------
155 // implementation section
156 // ------------------------------------------------------------------
157
159 inline InstanceGroup::DeviceData &InstanceGroup::getDD(const DeviceContext::SP &device) const
160 {
161 assert(device && device->ID < (int)deviceData.size());
162 return deviceData[device->ID]->as<DeviceData>();
163 }
164
165} // ::owl
Definition: Context.h:32
Definition: DeviceMemory.h:23
Definition: Group.h:36
Definition: Group.h:29
Definition: InstanceGroup.h:29
CUfunction instanceFuncKernel
Definition: InstanceGroup.h:43
CUfunction motionInstanceFuncKernel
Definition: InstanceGroup.h:47
DeviceData(const DeviceContext::SP &device)
DeviceMemory motionTransformsBuffer
Definition: InstanceGroup.h:38
Definition: InstanceGroup.h:24
std::vector< affine3f > transforms[2]
Definition: InstanceGroup.h:126
InstanceGroup(Context *const context, size_t numChildren, Group::SP *groups, unsigned int buildFlags, bool useInstanceProgram)
ProgramDesc instanceProg
Definition: InstanceGroup.h:148
std::vector< Group::SP > children
Definition: InstanceGroup.h:122
void setMotionInstanceProg(Module::SP module, const std::string &progName)
size_t numChildren
Definition: InstanceGroup.h:117
std::string toString() const override
void setInstanceProg(Module::SP module, const std::string &progName)
std::vector< uint32_t > instanceIDs
Definition: InstanceGroup.h:131
void buildAccel(LaunchParams::SP launchParams=nullptr) override
RegisteredObject::DeviceData::SP createOn(const DeviceContext::SP &device) override
ProgramDesc motionInstanceProg
Definition: InstanceGroup.h:151
void setTransform(size_t childID, const affine3f &xfm)
void setTransforms(uint32_t timeStep, const float *floatsForThisStimeStep, OWLMatrixFormat matrixFormat)
void setChild(size_t childID, Group::SP child)
void buildMotionInstanceProg()
void refitAccel(LaunchParams::SP launchParams=nullptr) override
std::vector< uint8_t > visibilityMasks
Definition: InstanceGroup.h:136
int getSBTOffset() const override
Definition: InstanceGroup.h:114
DeviceData & getDD(const DeviceContext::SP &device) const
Definition: InstanceGroup.h:159
bool useInstanceProgram
Definition: InstanceGroup.h:145
std::vector< DeviceData::SP > deviceData
Definition: Object.h:86
Definition: Geometry.h:31
Definition: AffineSpace.h:52