NVIDIA OptiX 7.7 nvidia_logo_transpbg.gif Up
optix_stack_size.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 NVIDIA Corporation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
32
33#ifndef OPTIX_OPTIX_STACK_SIZE_H
34#define OPTIX_OPTIX_STACK_SIZE_H
35
36#include "optix.h"
37
38#include <algorithm>
39#include <cstring>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
55{
56 if( !stackSizes )
58
59 OptixStackSizes localStackSizes;
60 OptixResult result = optixProgramGroupGetStackSize( programGroup, &localStackSizes, pipeline );
61 if( result != OPTIX_SUCCESS )
62 return result;
63
64 stackSizes->cssRG = std::max( stackSizes->cssRG, localStackSizes.cssRG );
65 stackSizes->cssMS = std::max( stackSizes->cssMS, localStackSizes.cssMS );
66 stackSizes->cssCH = std::max( stackSizes->cssCH, localStackSizes.cssCH );
67 stackSizes->cssAH = std::max( stackSizes->cssAH, localStackSizes.cssAH );
68 stackSizes->cssIS = std::max( stackSizes->cssIS, localStackSizes.cssIS );
69 stackSizes->cssCC = std::max( stackSizes->cssCC, localStackSizes.cssCC );
70 stackSizes->dssDC = std::max( stackSizes->dssDC, localStackSizes.dssDC );
71
72 return OPTIX_SUCCESS;
73}
74
89 unsigned int maxTraceDepth,
90 unsigned int maxCCDepth,
91 unsigned int maxDCDepth,
92 unsigned int* directCallableStackSizeFromTraversal,
93 unsigned int* directCallableStackSizeFromState,
94 unsigned int* continuationStackSize )
95{
96 if( !stackSizes )
98
99 const unsigned int cssRG = stackSizes->cssRG;
100 const unsigned int cssMS = stackSizes->cssMS;
101 const unsigned int cssCH = stackSizes->cssCH;
102 const unsigned int cssAH = stackSizes->cssAH;
103 const unsigned int cssIS = stackSizes->cssIS;
104 const unsigned int cssCC = stackSizes->cssCC;
105 const unsigned int dssDC = stackSizes->dssDC;
106
107 if( directCallableStackSizeFromTraversal )
108 *directCallableStackSizeFromTraversal = maxDCDepth * dssDC;
109 if( directCallableStackSizeFromState )
110 *directCallableStackSizeFromState = maxDCDepth * dssDC;
111
112 // upper bound on continuation stack used by call trees of continuation callables
113 unsigned int cssCCTree = maxCCDepth * cssCC;
114
115 // upper bound on continuation stack used by CH or MS programs including the call tree of
116 // continuation callables
117 unsigned int cssCHOrMSPlusCCTree = std::max( cssCH, cssMS ) + cssCCTree;
118
119 // clang-format off
120 if( continuationStackSize )
121 *continuationStackSize
122 = cssRG + cssCCTree
123 + ( std::max( maxTraceDepth, 1u ) - 1 ) * cssCHOrMSPlusCCTree
124 + std::min( maxTraceDepth, 1u ) * std::max( cssCHOrMSPlusCCTree, cssIS + cssAH );
125 // clang-format on
126
127 return OPTIX_SUCCESS;
128}
129
154 unsigned int dssDCFromTraversal,
155 unsigned int dssDCFromState,
156 unsigned int maxTraceDepth,
157 unsigned int maxCCDepth,
158 unsigned int maxDCDepthFromTraversal,
159 unsigned int maxDCDepthFromState,
160 unsigned int* directCallableStackSizeFromTraversal,
161 unsigned int* directCallableStackSizeFromState,
162 unsigned int* continuationStackSize )
163{
164 if( !stackSizes )
166
167 const unsigned int cssRG = stackSizes->cssRG;
168 const unsigned int cssMS = stackSizes->cssMS;
169 const unsigned int cssCH = stackSizes->cssCH;
170 const unsigned int cssAH = stackSizes->cssAH;
171 const unsigned int cssIS = stackSizes->cssIS;
172 const unsigned int cssCC = stackSizes->cssCC;
173 // use dssDCFromTraversal and dssDCFromState instead of stackSizes->dssDC
174
175 if( directCallableStackSizeFromTraversal )
176 *directCallableStackSizeFromTraversal = maxDCDepthFromTraversal * dssDCFromTraversal;
177 if( directCallableStackSizeFromState )
178 *directCallableStackSizeFromState = maxDCDepthFromState * dssDCFromState;
179
180 // upper bound on continuation stack used by call trees of continuation callables
181 unsigned int cssCCTree = maxCCDepth * cssCC;
182
183 // upper bound on continuation stack used by CH or MS programs including the call tree of
184 // continuation callables
185 unsigned int cssCHOrMSPlusCCTree = std::max( cssCH, cssMS ) + cssCCTree;
186
187 // clang-format off
188 if( continuationStackSize )
189 *continuationStackSize
190 = cssRG + cssCCTree
191 + ( std::max( maxTraceDepth, 1u ) - 1 ) * cssCHOrMSPlusCCTree
192 + std::min( maxTraceDepth, 1u ) * std::max( cssCHOrMSPlusCCTree, cssIS + cssAH );
193 // clang-format on
194
195 return OPTIX_SUCCESS;
196}
197
215 unsigned int cssCCTree,
216 unsigned int maxTraceDepth,
217 unsigned int maxDCDepth,
218 unsigned int* directCallableStackSizeFromTraversal,
219 unsigned int* directCallableStackSizeFromState,
220 unsigned int* continuationStackSize )
221{
222 if( !stackSizes )
224
225 const unsigned int cssRG = stackSizes->cssRG;
226 const unsigned int cssMS = stackSizes->cssMS;
227 const unsigned int cssCH = stackSizes->cssCH;
228 const unsigned int cssAH = stackSizes->cssAH;
229 const unsigned int cssIS = stackSizes->cssIS;
230 // use cssCCTree instead of stackSizes->cssCC and maxCCDepth
231 const unsigned int dssDC = stackSizes->dssDC;
232
233 if( directCallableStackSizeFromTraversal )
234 *directCallableStackSizeFromTraversal = maxDCDepth * dssDC;
235 if( directCallableStackSizeFromState )
236 *directCallableStackSizeFromState = maxDCDepth * dssDC;
237
238 // upper bound on continuation stack used by CH or MS programs including the call tree of
239 // continuation callables
240 unsigned int cssCHOrMSPlusCCTree = std::max( cssCH, cssMS ) + cssCCTree;
241
242 // clang-format off
243 if( continuationStackSize )
244 *continuationStackSize
245 = cssRG + cssCCTree
246 + ( std::max( maxTraceDepth, 1u ) - 1 ) * cssCHOrMSPlusCCTree
247 + std::min( maxTraceDepth, 1u ) * std::max( cssCHOrMSPlusCCTree, cssIS + cssAH );
248 // clang-format on
249
250 return OPTIX_SUCCESS;
251}
252
269 OptixProgramGroup programGroupMS1,
270 const OptixProgramGroup* programGroupCH1,
271 unsigned int programGroupCH1Count,
272 OptixProgramGroup programGroupMS2,
273 const OptixProgramGroup* programGroupCH2,
274 unsigned int programGroupCH2Count,
275 unsigned int* directCallableStackSizeFromTraversal,
276 unsigned int* directCallableStackSizeFromState,
277 unsigned int* continuationStackSize,
278 OptixPipeline pipeline )
279{
280 if( !programGroupCH1 && ( programGroupCH1Count > 0 ) )
282 if( !programGroupCH2 && ( programGroupCH2Count > 0 ) )
284
285 OptixResult result;
286
287 OptixStackSizes stackSizesRG = {};
288 result = optixProgramGroupGetStackSize( programGroupRG, &stackSizesRG, pipeline );
289 if( result != OPTIX_SUCCESS )
290 return result;
291
292 OptixStackSizes stackSizesMS1 = {};
293 result = optixProgramGroupGetStackSize( programGroupMS1, &stackSizesMS1, pipeline );
294 if( result != OPTIX_SUCCESS )
295 return result;
296
297 OptixStackSizes stackSizesCH1 = {};
298 for( unsigned int i = 0; i < programGroupCH1Count; ++i )
299 {
300 result = optixUtilAccumulateStackSizes( programGroupCH1[i], &stackSizesCH1, pipeline );
301 if( result != OPTIX_SUCCESS )
302 return result;
303 }
304
305 OptixStackSizes stackSizesMS2 = {};
306 result = optixProgramGroupGetStackSize( programGroupMS2, &stackSizesMS2, pipeline );
307 if( result != OPTIX_SUCCESS )
308 return result;
309
310 OptixStackSizes stackSizesCH2 = {};
311 memset( &stackSizesCH2, 0, sizeof( OptixStackSizes ) );
312 for( unsigned int i = 0; i < programGroupCH2Count; ++i )
313 {
314 result = optixUtilAccumulateStackSizes( programGroupCH2[i], &stackSizesCH2, pipeline );
315 if( result != OPTIX_SUCCESS )
316 return result;
317 }
318
319 const unsigned int cssRG = stackSizesRG.cssRG;
320 const unsigned int cssMS1 = stackSizesMS1.cssMS;
321 const unsigned int cssCH1 = stackSizesCH1.cssCH;
322 const unsigned int cssMS2 = stackSizesMS2.cssMS;
323 const unsigned int cssCH2 = stackSizesCH2.cssCH;
324 // no AH, IS, CC, or DC programs
325
326 if( directCallableStackSizeFromTraversal )
327 *directCallableStackSizeFromTraversal = 0;
328 if( directCallableStackSizeFromState )
329 *directCallableStackSizeFromState = 0;
330
331 if( continuationStackSize )
332 *continuationStackSize = cssRG + std::max( cssMS1, cssCH1 + std::max( cssMS2, cssCH2 ) );
333
334 return OPTIX_SUCCESS;
335}
336 // end group optix_utilities
338
339#ifdef __cplusplus
340}
341#endif
342
343#endif // OPTIX_OPTIX_STACK_SIZE_H
struct OptixProgramGroup_t * OptixProgramGroup
Opaque type representing a program group.
Definition: optix_types.h:65
OptixResult
Result codes returned from API functions.
Definition: optix_types.h:152
struct OptixPipeline_t * OptixPipeline
Opaque type representing a pipeline.
Definition: optix_types.h:68
@ OPTIX_SUCCESS
Definition: optix_types.h:153
@ OPTIX_ERROR_INVALID_VALUE
Definition: optix_types.h:154
OptixResult optixUtilComputeStackSizesSimplePathTracer(OptixProgramGroup programGroupRG, OptixProgramGroup programGroupMS1, const OptixProgramGroup *programGroupCH1, unsigned int programGroupCH1Count, OptixProgramGroup programGroupMS2, const OptixProgramGroup *programGroupCH2, unsigned int programGroupCH2Count, unsigned int *directCallableStackSizeFromTraversal, unsigned int *directCallableStackSizeFromState, unsigned int *continuationStackSize, OptixPipeline pipeline)
Computes the stack size values needed to configure a pipeline.
Definition: optix_stack_size.h:268
OptixResult optixUtilComputeStackSizes(const OptixStackSizes *stackSizes, unsigned int maxTraceDepth, unsigned int maxCCDepth, unsigned int maxDCDepth, unsigned int *directCallableStackSizeFromTraversal, unsigned int *directCallableStackSizeFromState, unsigned int *continuationStackSize)
Computes the stack size values needed to configure a pipeline.
Definition: optix_stack_size.h:88
OptixResult optixUtilComputeStackSizesCssCCTree(const OptixStackSizes *stackSizes, unsigned int cssCCTree, unsigned int maxTraceDepth, unsigned int maxDCDepth, unsigned int *directCallableStackSizeFromTraversal, unsigned int *directCallableStackSizeFromState, unsigned int *continuationStackSize)
Computes the stack size values needed to configure a pipeline.
Definition: optix_stack_size.h:214
OptixResult optixUtilAccumulateStackSizes(OptixProgramGroup programGroup, OptixStackSizes *stackSizes, OptixPipeline pipeline)
Retrieves direct and continuation stack sizes for each program in the program group and accumulates t...
Definition: optix_stack_size.h:54
OptixResult optixUtilComputeStackSizesDCSplit(const OptixStackSizes *stackSizes, unsigned int dssDCFromTraversal, unsigned int dssDCFromState, unsigned int maxTraceDepth, unsigned int maxCCDepth, unsigned int maxDCDepthFromTraversal, unsigned int maxDCDepthFromState, unsigned int *directCallableStackSizeFromTraversal, unsigned int *directCallableStackSizeFromState, unsigned int *continuationStackSize)
Computes the stack size values needed to configure a pipeline.
Definition: optix_stack_size.h:153
OptiX public API header.
OptixResult optixProgramGroupGetStackSize(OptixProgramGroup programGroup, OptixStackSizes *stackSizes, OptixPipeline pipeline)
Returns the stack sizes for the given program group. When programs in this programGroup are relying o...
Describes the stack size requirements of a program group.
Definition: optix_types.h:2395
unsigned int cssRG
Continuation stack size of RG programs in bytes.
Definition: optix_types.h:2397
unsigned int cssAH
Continuation stack size of AH programs in bytes.
Definition: optix_types.h:2403
unsigned int cssCH
Continuation stack size of CH programs in bytes.
Definition: optix_types.h:2401
unsigned int cssCC
Continuation stack size of CC programs in bytes.
Definition: optix_types.h:2407
unsigned int cssIS
Continuation stack size of IS programs in bytes.
Definition: optix_types.h:2405
unsigned int dssDC
Direct stack size of DC programs in bytes.
Definition: optix_types.h:2409
unsigned int cssMS
Continuation stack size of MS programs in bytes.
Definition: optix_types.h:2399