OWL
Loading...
Searching...
No Matches
Context.h
1// ======================================================================== //
2// Copyright 2019-2021 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 "DeviceContext.h"
20#include "ObjectRegistry.h"
21#include "Buffer.h"
22#include "Texture.h"
23#include "Group.h"
24#include "RayGen.h"
25#include "LaunchParams.h"
26#include "MissProg.h"
27
28namespace owl {
29
32 struct Context : public Object {
33
34 typedef std::shared_ptr<Context> SP;
35
37 inline static bool logging()
38 {
39#ifdef NDEBUG
40 return false;
41#else
42 return true;
43#endif
44 }
45
47 virtual std::string toString() const override { return "owl::Context"; }
48
53 Context(int32_t *requestedDeviceIDs,
54 int numRequestedDevices);
55
57 virtual ~Context();
58
59 size_t deviceCount() const { return getDevices().size(); }
60 const std::vector<DeviceContext::SP> &getDevices() const { return devices; }
61 DeviceContext::SP getDevice(int ID) const
62 { assert(ID >= 0 && ID < (int)devices.size()); return devices[ID]; }
63
65 void buildHitGroupRecordsOn(const DeviceContext::SP &device);
67 void buildRayGenRecordsOn(const DeviceContext::SP &device);
69 void buildMissProgRecordsOn(const DeviceContext::SP &device);
70
74 void setRayTypeCount(size_t rayTypeCount);
75
76 void setBoundLaunchParamValues(const std::vector<OWLBoundValueDecl> &boundValues);
77
80 void enableMotionBlur();
81
85 void enableCurves();
86
90 void enableSpheres();
91
96
115 void setMaxInstancingDepth(int32_t maxInstanceDepth);
116
117 /* Set number of attributes for passing data from custom Intersection programs
118 to ClosestHit programs. Default 2. Has no effect once programs are built.*/
119 void setNumAttributeValues(size_t numAttributeValues);
120
121 /* Set number of payload values for passing data between programs. Default 2.
122 Has no effect once programs are built.*/
123 void setNumPayloadValues(size_t numPayloadValues);
124
125 // ------------------------------------------------------------------
126 // internal mechanichs/plumbling that do the actual work
127 // ------------------------------------------------------------------
128
129 void buildSBT(OWLBuildSBTFlags flags);
130 void buildPipeline();
131 void buildPrograms(bool debug = false);
133 void destroyPrograms();
134 void buildModules(bool debug = false);
136 void destroyModules();
137
138
139 // ------------------------------------------------------------------
140 // factory methods to create objects within this context
141 // ------------------------------------------------------------------
142
146 Texture::SP
147 texture2DCreate(OWLTexelFormat texelFormat,
148 OWLTextureFilterMode filterMode,
149 OWLTextureAddressMode addressMode,
150 OWLTextureColorSpace colorSpace,
151 const vec2i size,
152 uint32_t linePitchInBytes,
153 const void *texels);
154
161 GeomGroup::SP
162 trianglesGeomGroupCreate(size_t numChildren, unsigned int buildFlags);
163
170 GeomGroup::SP
171 curvesGeomGroupCreate(size_t numChildren, unsigned int buildFlags);
172
178 GeomGroup::SP
179 userGeomGroupCreate(size_t numChildren, unsigned int buildFlags);
180
186 GeomGroup::SP
187 sphereGeomGroupCreate(size_t numChildren, unsigned int buildFlags);
188
194 Buffer::SP
195 deviceBufferCreate(OWLDataType type,
196 size_t count,
197 const void *init);
198
202 Buffer::SP
203 hostPinnedBufferCreate(OWLDataType type,
204 size_t count);
205
209 Buffer::SP
210 managedMemoryBufferCreate(OWLDataType type,
211 size_t count,
212 const void *init);
213
216 Buffer::SP
217 graphicsBufferCreate(OWLDataType type,
218 size_t count,
219 cudaGraphicsResource_t resource);
220
221
225 RayGenType::SP
226 createRayGenType(Module::SP module,
227 const std::string &progName,
228 size_t varStructSize,
229 const std::vector<OWLVarDecl> &varDecls);
230
232 RayGen::SP
233 createRayGen(const std::shared_ptr<RayGenType> &type);
234
238 LaunchParamsType::SP
239 createLaunchParamsType(size_t varStructSize,
240 const std::vector<OWLVarDecl> &varDecls);
241
243 LaunchParams::SP
244 createLaunchParams(const std::shared_ptr<LaunchParamsType> &type);
245
249 MissProgType::SP
250 createMissProgType(Module::SP module,
251 const std::string &progName,
252 size_t varStructSize,
253 const std::vector<OWLVarDecl> &varDecls);
254
256 MissProg::SP
257 createMissProg(const std::shared_ptr<MissProgType> &type);
258
260 void setMissProg(int rayTypeToSet, MissProg::SP missProgToUse);
261
263 GeomType::SP
264 createGeomType(OWLGeomKind kind,
265 size_t varStructSize,
266 const std::vector<OWLVarDecl> &varDecls);
267
269 Module::SP
270 createModule(const std::string &ptxCode);
271
273 Module::SP
274 createModule(const std::vector<uint8_t> &IR);
275
276 // ------------------------------------------------------------------
277 // member variables
278 // ------------------------------------------------------------------
279
286 ObjectRegistryT<RayGenType> rayGenTypes;
288 ObjectRegistryT<MissProgType> missProgTypes;
293 ObjectRegistryT<LaunchParamsType> launchParamTypes;
303
305 std::vector<MissProg::SP> missProgPerRayType;
306
310
317
319 int numRayTypes { 1 };
320
321#if OPTIX_VERSION >= 70200
323 std::vector<OptixModuleCompileBoundValueEntry> boundLaunchParamValues;
324#endif
325
328 bool motionBlurEnabled = false;
329
332 bool curvesEnabled = false;
333
336 bool spheresEnabled = false;
337
338 /* Number of attributes for writing data between Intersection and ClosestHit */
339 int numAttributeValues = 2;
340
341 /* Number of payload values to request for passing data between RT programs */
342 int numPayloadValues = 2;
343
347 LaunchParams::SP dummyLaunchParams;
348
349 private:
350 void enablePeerAccess();
351 std::vector<DeviceContext::SP> devices;
352 };
353
354} // ::owl
355
Definition: Context.h:32
void buildMissProgRecordsOn(const DeviceContext::SP &device)
Definition: Context.cpp:446
RangeAllocator sbtRangeAllocator
Definition: Context.h:302
MissProg::SP createMissProg(const std::shared_ptr< MissProgType > &type)
Definition: Context.cpp:225
bool motionBlurEnabled
Definition: Context.h:328
void enableMotionBlur()
Definition: Context.cpp:613
std::vector< MissProg::SP > missProgPerRayType
Definition: Context.h:305
GeomGroup::SP userGeomGroupCreate(size_t numChildren, unsigned int buildFlags)
Definition: Context.cpp:311
void disablePerGeometrySBTRecords()
Definition: Context.cpp:618
LaunchParamsType::SP createLaunchParamsType(size_t varStructSize, const std::vector< OWLVarDecl > &varDecls)
Definition: Context.cpp:267
void enableSpheres()
Definition: Context.cpp:628
int maxInstancingDepth
Definition: Context.h:309
Buffer::SP hostPinnedBufferCreate(OWLDataType type, size_t count)
Definition: Context.cpp:132
GeomGroup::SP trianglesGeomGroupCreate(size_t numChildren, unsigned int buildFlags)
Definition: Context.cpp:295
void setMaxInstancingDepth(int32_t maxInstanceDepth)
Definition: Context.cpp:596
GeomType::SP createGeomType(OWLGeomKind kind, size_t varStructSize, const std::vector< OWLVarDecl > &varDecls)
Definition: Context.cpp:328
static bool logging()
Definition: Context.h:37
virtual ~Context()
Definition: Context.cpp:72
void setMissProg(int rayTypeToSet, MissProg::SP missProgToUse)
Definition: Context.cpp:243
void destroyPrograms()
Definition: Context.cpp:672
bool perGeometrySBTRecordsDisabled
Definition: Context.h:316
RayGenType::SP createRayGenType(Module::SP module, const std::string &progName, size_t varStructSize, const std::vector< OWLVarDecl > &varDecls)
Definition: Context.cpp:252
Buffer::SP graphicsBufferCreate(OWLDataType type, size_t count, cudaGraphicsResource_t resource)
Definition: Context.cpp:194
Texture::SP texture2DCreate(OWLTexelFormat texelFormat, OWLTextureFilterMode filterMode, OWLTextureAddressMode addressMode, OWLTextureColorSpace colorSpace, const vec2i size, uint32_t linePitchInBytes, const void *texels)
Definition: Context.cpp:176
void enableCurves()
Definition: Context.cpp:623
void buildHitGroupRecordsOn(const DeviceContext::SP &device)
Definition: Context.cpp:369
Buffer::SP deviceBufferCreate(OWLDataType type, size_t count, const void *init)
Definition: Context.cpp:161
MissProgType::SP createMissProgType(Module::SP module, const std::string &progName, size_t varStructSize, const std::vector< OWLVarDecl > &varDecls)
Definition: Context.cpp:280
Module::SP createModule(const std::string &ptxCode)
Definition: Context.cpp:353
int numRayTypes
Definition: Context.h:319
Buffer::SP managedMemoryBufferCreate(OWLDataType type, size_t count, const void *init)
Definition: Context.cpp:146
GeomGroup::SP curvesGeomGroupCreate(size_t numChildren, unsigned int buildFlags)
Definition: Context.cpp:303
LaunchParams::SP dummyLaunchParams
Definition: Context.h:347
RayGen::SP createRayGen(const std::shared_ptr< RayGenType > &type)
Definition: Context.cpp:209
virtual std::string toString() const override
Definition: Context.h:47
GeomGroup::SP sphereGeomGroupCreate(size_t numChildren, unsigned int buildFlags)
Definition: Context.cpp:319
void buildRayGenRecordsOn(const DeviceContext::SP &device)
Definition: Context.cpp:493
void destroyModules()
Definition: Context.cpp:662
LaunchParams::SP createLaunchParams(const std::shared_ptr< LaunchParamsType > &type)
Definition: Context.cpp:217
bool spheresEnabled
Definition: Context.h:336
bool curvesEnabled
Definition: Context.h:332
ObjectRegistryT< Buffer > buffers
Definition: Context.h:283
void setRayTypeCount(size_t rayTypeCount)
Definition: Context.cpp:555
Definition: ObjectRegistry.h:64
Definition: Object.h:31
Definition: DeviceContext.h:30