OWL
Loading...
Searching...
No Matches
SBTObject.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 "RegisteredObject.h"
20#include "Variable.h"
21
22namespace owl {
23
33 {
34 typedef std::shared_ptr<SBTObjectType> SP;
35
36 SBTObjectType(Context *const context,
38 size_t varStructSize,
39 const std::vector<OWLVarDecl> &varDecls);
40
42 virtual ~SBTObjectType();
43
45 int getVariableIdx(const std::string &varName);
46
49 bool hasVariable(const std::string &varName);
50
52 std::string toString() const override;
53
56 void declareVariable(const std::string &varName,
57 OWLDataType type,
58 size_t offset);
59
63 std::vector<Variable::SP> instantiateVariables();
64
66 const size_t varStructSize;
67
70 const std::vector<OWLVarDecl> varDecls;
71 };
72
73
74
81 {
84 SBTObjectBase(Context *const context,
86 std::shared_ptr<SBTObjectType> type);
87
89 inline bool hasVariable(const std::string &name);
90
93 inline Variable::SP getVariable(const std::string &name);
94
101 void writeVariables(uint8_t *sbtEntry,
102 const DeviceContext::SP &device) const;
103
106 std::shared_ptr<SBTObjectType> const type;
107
109 const std::vector<Variable::SP> variables;
110 };
111
112
116 template<typename ObjectType>
117 struct SBTObject : public SBTObjectBase
118 {
119 typedef std::shared_ptr<SBTObject> SP;
120
123 SBTObject(Context *const context,
125 std::shared_ptr<ObjectType> type)
126 : SBTObjectBase(context,registry,type),
127 type(type)
128 {}
129
130 virtual std::string toString() const { return "SBTObject<"+type->toString()+">"; }
131
134 std::shared_ptr<ObjectType> const type;
135 };
136
137
138
139 // ------------------------------------------------------------------
140 // implementation section
141 // ------------------------------------------------------------------
142
144 inline bool SBTObjectBase::hasVariable(const std::string &name)
145 {
146 return type->hasVariable(name);
147 }
148
151 inline Variable::SP SBTObjectBase::getVariable(const std::string &name)
152 {
153 int varID = type->getVariableIdx(name);
154 assert(varID >= 0);
155 assert(varID < (int)variables.size());
156 Variable::SP var = variables[varID];
157 assert(var);
158 return var;
159 }
160
161} // ::owl
162
Definition: Context.h:32
Definition: ObjectRegistry.h:30
Definition: RegisteredObject.h:30
ObjectRegistry & registry
Definition: RegisteredObject.h:42
Definition: SBTObject.h:81
std::shared_ptr< SBTObjectType > const type
Definition: SBTObject.h:106
void writeVariables(uint8_t *sbtEntry, const DeviceContext::SP &device) const
Definition: SBTObject.cpp:113
const std::vector< Variable::SP > variables
Definition: SBTObject.h:109
bool hasVariable(const std::string &name)
Definition: SBTObject.h:144
Variable::SP getVariable(const std::string &name)
Definition: SBTObject.h:151
Definition: SBTObject.h:33
std::string toString() const override
Definition: SBTObject.cpp:88
const std::vector< OWLVarDecl > varDecls
Definition: SBTObject.h:70
virtual ~SBTObjectType()
Definition: SBTObject.cpp:54
const size_t varStructSize
Definition: SBTObject.h:66
bool hasVariable(const std::string &varName)
Definition: SBTObject.cpp:71
std::vector< Variable::SP > instantiateVariables()
Definition: SBTObject.cpp:77
int getVariableIdx(const std::string &varName)
Definition: SBTObject.cpp:61
void declareVariable(const std::string &varName, OWLDataType type, size_t offset)
Definition: SBTObject.h:118
SBTObject(Context *const context, ObjectRegistry &registry, std::shared_ptr< ObjectType > type)
Definition: SBTObject.h:123
std::shared_ptr< ObjectType > const type
Definition: SBTObject.h:134
virtual std::string toString() const
Definition: SBTObject.h:130