-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathoptix_util.h
More file actions
2586 lines (2240 loc) · 118 KB
/
optix_util.h
File metadata and controls
2586 lines (2240 loc) · 118 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2026 Shin Watanabe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
/*
Note:
JP:
- 現状ではあらゆるAPIに破壊的変更が入る可能性がある。
- (少なくともホスト側コンパイラーがMSVC 16.8.2の場合は)"-std=c++17"をptxのコンパイル時に設定する必要あり。
EN:
- It is likely for now that any API will have breaking changes.
- Setting "-std=c++17" is required for ptx compilation (at least for the case the host compiler is MSVC 16.8.2).
変更履歴 / Update History:
- JP: - OptiX 9.1.0をサポート。
- Pipeline::writeSymbolFromHostAsync(), Pipeline::writeSymbolFromDeviceAsync(),
Pipeline::readSymbolToHostAsync(), Pipeline::readSymbolToDeviceAsync()を追加。
EN: - Supported OptiX 9.1.0.
- Added Pipeline::writeSymbolFromHostAsync(), Pipeline::writeSymbolFromDeviceAsync(),
Pipeline::readSymbolToHostAsync(), Pipeline::readSymbolToDeviceAsync().
- JP: - インスタンスポインターのサポート。
EN: - Supported instance pointers.
- !!BREAKING
- JP: - 非構造化クラスターをサポート。
具体的にはClusterAccelerationStructure (CLAS), ClusterGeometryAccelerationStructure (CGAS)を追加。
- いくつかのset/getNum...()という関数名をset/get...Count()に変更。
EN: - Supported unstructured clusters.
Specifically added ClusterAccelerationStructure (CLAS) and ClusterGeometryAccelerationStructure (CGAS).
- Changed some set/getNum...() functions to set/get...Count().
- !!BREAKING
- JP: - PipelineのsetPipelineOptions()のパラメターを変更。
EN: - Changed the parameters of Pipeline::setPipelineOptions().
- !!BREAKING
JP: - OptiX 9.0.0のサポートを開始。
- Rocaps型のカーブをサポート。
- DMM APIを削除。
- Clusters APIは未対応。
EN: - Started to support OptiX 9.0.0.
- Supported Rocaps-type curves.
- Removed the DMM API.
- Does not support clusters API yet.
- JP: - OptiX 8.1.0をサポート。
EN: - Supported OptiX 8.1.0.
- JP: - optixReportIntersection()に返り値があることを忘れていたのを修正。
EN: - fixed forgetting that optixReportIntersection has a return value.
- JP: - 各プログラム(グループ)にsetActive()を追加。
EN: - Added setActive() to programs (groups).
- !!BREAKING
JP: - OptiX 8.0.0をサポート。
Context::createDenoiser(), Denoiser::invoke()のパラメターを変更。
EN: - Supported OptiX 8.0.0.
Changed the parameters of Context::createDenoiser(), Denoiser::invoke().
- JP: - Displacement Micro-Mapをサポート。
EN: - Supported displacement micro-map.
- !!BREAKING
JP: - OptiX 7.7.0をサポート。
- Pipeline::link()のパラメターを変更。
- Displaced Micro-Meshは未対応。
EN: - Supported OptiX 7.7.0.
- Changed the parameters of Pipeline::link().
- Does not support displaced micro-mesh yet.
- !!BREAKING
JP: - ProgramGroupをProgram, HitProgramGroup, CallableProgramGroupに分割した。
EN: - Separated ProgramGroup into Program, HitProgramGroup, CallableProgramGroup.
- !!BREAKING
JP: - Opacity Micro-Mapをサポート。
- インデックスサイズ指定用のenum classを定義。
EN: - Supported opacity micro-map.
- Defined an enum class to specify index sizes.
- !!BREAKING
JP: - OptiX 7.6.0をサポート。
- ホスト側APIのbool引数それぞれの個別の型を定義。
- Pipeline::setPipelineOptions()の引数の順序を変更。
EN: - Supported OptiX 7.6.0.
- Defined a dedicated type for each bool parameter of the host-side API.
- Changed the order of parameters of Pipeline::setPipelineOptions().
- !!BREAKING
JP: - AnnotatedPayloadSignatureテンプレート型を定義。ペイロードアノテーションはこの型経由で行う。
PayloadSignature::createPayloadType()を削除。
EN: - Defined AnnotatedPayloadSignature template type. Use this type for payload annotation.
Removed PayloadSignature::createPayloadType().
- !!BREAKING
JP: - Upscaling Denoiserをサポート。
- Denoiserクラスのインターフェースをいくらか変更。
- reportIntersection(), throwException()を削除。
代わりに対応するシグネチャー型経由で値の取得・設定を行う。
- PayloadType::create()を削除、対応するシグネチャー型のstaticメンバー関数として実装。
EN: - Supported upscaling denoisers.
- Changed some interfaces of Denoiser class.
- Removed reportIntersection(), throwException().
Set or get values via corresponding signature types instead.
- Removed PayloadType::create(), implemented as a static member function of
the corresponding signature type instead.
- !!BREAKING
JP: - OptiX 7.5.0をサポート。
Upscaling Denoiserは未対応。
- trace()関数をシグネチャー型のメンバー関数に変更。
EN: - Supported OptiX 7.5.0.
Does not support upscaling denoiser yet.
- Changed the trace() fuction to a member function of the signature type.
- !!BREAKING??
JP: - RT_DEVICE_FUNCTIONからinline属性を削除。RT_INLINEを新設。
__CUDACC__と__CUDA_ARCH__の使い分けを明確に。
EN: - Removed inline qualifier from RT_DEVICE_FUNCTION and added RT_INLINE.
Disambiguate usage of __CUDACC__ and __CUDA_ARCH__.
- !!BREAKING
JP: - getPayloads()/setPayloads(), getAttributes(), getExceptionDetails()を削除。
ペイロードなどの値はシグネチャー型経由で取得・設定を行う。
EN: - Removed getPayloads()/setPayloads(), getAttributes(), getExceptionDetails().
Set or get values like payload via signature types.
- JP: - createModuleFromPTXString(), createMissProgram(),
createHitProgramGroupFor***IS(), createCallableProgramGroup()
がペイロードアノテーションを追加で受け取れるように変更。
詳細については新たなサンプル"payload_annotation"を参照。
EN: - Changed createModuleFromPTXString(), createMissProgram(),
createHitProgramGroupFor***IS(), createCallableProgramGroup()
to be able to additionally take payload annotations.
See a new sample "payload_annotation" for the details.
- !!BREAKING
JP: - OptiX 7.4.0をサポート。
- SBTレコード中のユーザーデータの並び順が逆になった。
!! ユーザーのOptiXカーネルを少し修正する必要があります。
- 三角形プリミティブ、カーブプリミティブ用のヒットグループ作成をそれぞれ
createHitProgramGroupForTriangleIS()とcreateHitProgramGroupForCurveIS()で行うように変更。
EN: - Supported OptiX 7.4.0.
- The order of user data in a SBT record has been reversed.
!! User's OptiX kernels need to be modified a bit.
- Changed hit group creation of triangle and curve primitives to use
createHitProgramGroupForTriangleIS() and createHitProgramGroupForCurveIS() respectively.
- !!BREAKING
JP: - OptiX 7.3.0をサポート。
- InstanceAccelerationStructure::setConfiguration()が一つ多くの引数を受け取るようになった。
- Denoiserの入出力レイヤーをinvoke(), computeIntensity()に直接渡すように変更。setLayers()を削除。
EN: - Supported OptiX 7.3.0.
- InstanceAccelerationStructure::setConfiguration() takes one more additional argument.
- Changed Denoiser's invoke(), computeIntensisty() to directly take input/output layers.
Removed setLayers().
- !!BREAKING
JP: - カーブプリミティブをサポート。
- ヒットグループを生成する関数を変更。三角形とカーブに関してはcreateHitProgramGroupForBuiltinIS()を、
カスタムプリミティブに関してはcreateHitProgramGroupForCustomIS()を使用してください。
EN: - Added support for curve primitives.
- Changed the function to create a hit group. Use createHitProgramGroupForBuiltinIS() for triangles and
curves and createHitProgramGroupForCustomIS() for custom primitives.
- !!BREAKING
JP: - GeometryInstanceとGASをSceneから生成する関数の引数の型をenumに変更。
EN: - Changed the type of argument of the functions to create a GeometryInstance or a GAS from a Scene to enum.
- !!BREAKING
JP: - GAS/IASのremoveChild()を削除。代わりにremoveChildAt()を定義。
GAS/IAS::findChildIndex()を使用すれば目的の子のインデックスを特定できる。
- また、GAS/IAS::clearChildren()を定義。
EN: - Removed GAS/IAS's removeChild(), instead defined removeChildAt().
Use GAS/IAS::findChildIndex() to identify the index of the target child.
- Also, defined GAS/IAS::clearChildren().
- JP: - GASの子ごとのユーザーデータを設定するAPIを追加。
EN: - Added APIs to set per-GAS child user data.
- JP: - 各種パラメターを取得するためのAPIを追加。
EN: - Added APIs to get parameters.
- JP: - マテリアルのユーザーデータのサイズやアラインメントを、シェーダーバインディングテーブルレイアウト生成後に
変更した場合にレイアウトを手動で無効化するためのScene::markShaderBindingTableLayoutDirty()を追加。
- 併せてScene::shaderBindingTableLayoutIsReady()も追加。
EN: - Added Scene::markShaderBindingTableLayoutDirty() to manually invalidate the layout of shader binding table
for the case changing the size and/or alignment of a material's user data after generating the layout.
- Added Scene::shaderBindingTableLayoutIsReady() as well.
- !!BREAKING
JP: - InstanceAccelerationStructure::prepareForBuild()が引数でインスタンス数を返さないように変更。
InstanceAccelerationStructure::getNumChildren()を代わりに使用してください。
EN: - Changed InstanceAccelerationStructure::prepareForBuild() not to return the number of instances as an argument.
Use InstanceAccelerationStructure::getNumChildren() instead.
----------------------------------------------------------------
TODO:
- クラスターテンプレートのサポート。
- グリッドクラスターのサポート。
- HitObjectの新たな機能のサポート。
- Coop Vec APIのラッパー?
- 深いトラバーサルグラフにおけるインスタンスのSBTオフセットの累積サポート。
- NVRTC環境のテスト。
- フローベクターの信頼性についてテスト。
- AOV Denoiserのサンプル作成。
- Linux環境でのテスト。
- モジュールの並列コンパイル。
- ASのRelocationサポート。
- OMMのRelocationサポート。
- Multi GPUs?
- ユニットテスト。
- removeUncompacted再考。(compaction終了待ちとしてとらえる?)
- 途中で各オブジェクトのパラメターを変更した際の処理。
パイプラインのセットアップ順などが現状は暗黙的に固定されている。これを自由な順番で変えられるようにする。
- Assertとexceptionの整理。
検討事項 (Items under author's consideration, ignore this :) ):
- Denoiserの事前設定は画像サイズにも依存するので、各バッファーはinvoke時ではなく事前に渡しておくべき?
- Priv構造体がOptiXの構造体を直接持っていない場合が多々あるのがもったいない?
=> OptixBuildInputは巨大なパディングを含んでいるので好ましくない。
=> IASが直接持っているOptixBuildInputを除去orポインター化?
OptixBuildInputInstanceArrayを持つようにするとrebuildなどの各処理で毎回OptixBuildInputのクリアが必要。
ポインター化はメモリの無駄遣いを本質的には解決しない。
- optixuのenumかOptiXのenum、使い分ける基準について考える。
=> OptiX側のenumが余計なものを含んでいる場合はoptixu側でenumを定義したほうがミスが少ない。
GeometryTypeはOptiX側のでも良い気もするが、OPTIX_PRIMITIVE_TYPE_とOPTIX_PRIMITIVE_TYPE_FLAGS_でミスりそう。
- MaterialのヒットグループのISとGeometryInstanceの一致確認。
=> ついでにプログラムタイプごとの型つくる?
- GeometryInstanceのGASをdirtyにする処理のうち、いくつかは内部的にSBTレイアウトの無効化をスキップできるはず。
- HitGroup以外のProgramGroupにユーザーデータを持たせる。
- Material::setHitGroup()はレイタイプの数値が同じでもヒットグループのパイプラインが違っていれば別個に登録できるが、
これがAPI上からは読み取りづらい。冗長だが敢えてパイプラインの識別情報も引数として受け取るべき?
- Scene::generateShaderBindingTableLayout()はPipelineに依存すべき?
=> その場合はこの関数自体setSceneを使った後に呼ばれるPipelineの関数となるべき?
SBT自体内容はレコードのヘッダーによって必ずパイプラインに依存するので
レイアウトがパイプラインに依存するのは問題ない?
現状の問題点:
- パイプラインごとにマテリアルに設定されているレイタイプ数が異なる場合に、
最大のレイタイプ数をGASに設定すると、SBTレコードを書き込む際にマテリアルがあるレイタイプに対して
設定されていないと言われてしまう。(とりあえず空のHitGroupを作れるようにして対処してある。)
=> GASのレイタイプ数設定をパイプラインに依存させる? => Sceneとパイプラインは切り離したい。
=> 多少Sceneがパイプラインに依存するとしてもパイプラインごとに別のレイタイプ数設定のほうがきれいそう。
=> しかしIASが持つSBTオフセットが絶対的な値なので、IASをパイプライン間で共通化させようと思うと結局無理。
- GASがレイタイプ数設定を持っているのが不自然? => パイプラインがレイタイプ数を持つようにして
SBTレイアウト計算もPipelineに依存させる?
----------------------------------------------------------------
- GAS/IASに関してユーザーが気にするところはAS云々ではなくグループ化なので
名前を変えるべき?GeometryGroup/InstanceGroupのような感じ。
しかしビルドやアップデートを明示的にしているため結局ASであるということをユーザーが意識する必要がある。
- ユーザーがあるSBTレコード中の各データのストライドを意識せずともそれぞれのオフセットを取得する関数。
=> オフセット値を読み取った後にデータを読み取るというindirectionになるため、そもそもあまり好ましくない気も。
- InstanceのsetChildはTraversal Graph Depthに影響しないので名前を変えるべき?setTraversable()?
=> GASのsetChildもDepthに影響しないことを考えるとこのままで良いかも。
*/
#define OPTIXU_STRINGIFY(x) #x
#define OPTIXU_TO_STRING(x) OPTIXU_STRINGIFY(x)
// Platform defines
#if defined(_WIN32) || defined(_WIN64)
# define OPTIXU_Platform_Windows
# if defined(_MSC_VER)
# define OPTIXU_Platform_Windows_MSVC
# if defined(__INTELLISENSE__)
# define OPTIXU_Platform_CodeCompletion
# endif // if defined(__INTELLISENSE__)
# endif // if defined(_MSC_VER)
#elif defined(__APPLE__)
# define OPTIXU_Platform_macOS
#endif // if defined(_WIN32) || defined(_WIN64)
#if defined(__CUDACC_RTC__)
// JP: cstdintやcfloatに対応する定義はユーザーに任せられている。
// EN: Defining things corresponding to cstdint and cfloat is left to the user.
#else // if defined(__CUDACC_RTC__)
#include <cstdint>
#include <cfloat>
#include <string>
#include <vector>
#include <initializer_list>
# if __cplusplus >= 202002L
# include <concepts>
# endif // if __cplusplus >= 202002L
#endif // if defined(__CUDACC_RTC__)
#if defined(OPTIXU_Platform_Windows_MSVC)
# pragma warning(push)
# pragma warning(disable:4819)
#endif // if defined(OPTIXU_Platform_Windows_MSVC)
// JP: NVRTCを使う場合でも「アプリケーション」ユーザーはOptiX SDKのインストールを必要とする。
// EN: Even NVRTC requires the "application" user to install OptiX SDK.
#include <optix.h>
#if !defined(__CUDA_ARCH__)
# include <optix_stubs.h>
#endif // if !defined(__CUDA_ARCH__)
#if defined(OPTIXU_Platform_Windows_MSVC)
# pragma warning(pop)
#endif // if defined(OPTIXU_Platform_Windows_MSVC)
#if !defined(OPTIXU_ENABLE_ASSERT)
# if defined(_DEBUG)
# define OPTIXU_ENABLE_ASSERT 1
# else
# define OPTIXU_ENABLE_ASSERT 0
# endif // if defined(_DEBUG)
#endif // if !defined(OPTIXU_ENABLE_ASSERT)
#if !defined(OPTIXU_DISABLE_RUNTIME_ERROR)
# define OPTIXU_ENABLE_RUNTIME_ERROR 1
#endif // if !defined(OPTIXU_DISABLE_RUNTIME_ERROR)
#if defined(__CUDACC__)
# define RT_CALLABLE_PROGRAM extern "C" __device__
# define RT_INLINE __forceinline__
# define RT_DEVICE_FUNCTION __device__
# define RT_COMMON_FUNCTION __host__ __device__
# if !defined(RT_PIPELINE_LAUNCH_PARAMETERS)
# define RT_PIPELINE_LAUNCH_PARAMETERS extern "C" __constant__
# endif
#else // if defined(__CUDACC__)
# define RT_CALLABLE_PROGRAM
# define RT_INLINE inline
# define RT_DEVICE_FUNCTION
# define RT_COMMON_FUNCTION
# define RT_PIPELINE_LAUNCH_PARAMETERS
#endif // if defined(__CUDACC__)
#define RT_RG_NAME(name) __raygen__ ## name
#define RT_MS_NAME(name) __miss__ ## name
#define RT_EX_NAME(name) __exception__ ## name
#define RT_CH_NAME(name) __closesthit__ ## name
#define RT_AH_NAME(name) __anyhit__ ## name
#define RT_IS_NAME(name) __intersection__ ## name
#define RT_DC_NAME(name) __direct_callable__ ## name
#define RT_CC_NAME(name) __continuation_callable__ ## name
#define RT_RG_NAME_STR(name) "__raygen__" name
#define RT_MS_NAME_STR(name) "__miss__" name
#define RT_EX_NAME_STR(name) "__exception__" name
#define RT_CH_NAME_STR(name) "__closesthit__" name
#define RT_AH_NAME_STR(name) "__anyhit__" name
#define RT_IS_NAME_STR(name) "__intersection__" name
#define RT_DC_NAME_STR(name) "__direct_callable__" name
#define RT_CC_NAME_STR(name) "__continuation_callable__" name
#define OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(Type) \
RT_COMMON_FUNCTION RT_INLINE constexpr Type operator~(Type a) { \
return static_cast<Type>(~static_cast<uint32_t>(a)); \
} \
RT_COMMON_FUNCTION RT_INLINE constexpr Type operator|(Type a, Type b) { \
return static_cast<Type>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b)); \
} \
RT_COMMON_FUNCTION RT_INLINE constexpr Type &operator|=(Type &a, Type b) { \
a = static_cast<Type>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b)); \
return a; \
} \
RT_COMMON_FUNCTION RT_INLINE constexpr Type operator&(Type a, Type b) { \
return static_cast<Type>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b)); \
} \
RT_COMMON_FUNCTION RT_INLINE constexpr Type &operator&=(Type &a, Type b) { \
a = static_cast<Type>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b)); \
return a; \
}
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixGeometryFlags);
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixPrimitiveTypeFlags);
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixInstanceFlags);
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixMotionFlags);
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixRayFlags);
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixTraversableGraphFlags);
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixExceptionFlags);
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixPayloadSemantics);
OPTIXU_DEFINE_OPERATORS_FOR_FLAGS(OptixPayloadTypeID);
#undef OPTIXU_DEFINE_OPERATORS_FOR_FLAGS
#if defined(OPTIXU_Platform_CodeCompletion)
struct float3;
#endif // if defined(OPTIXU_Platform_CodeCompletion)
namespace optixu {
void devPrintf(const char* fmt, ...);
#if 1
# define optixuPrintf(fmt, ...) \
do { \
optixu::devPrintf(fmt, ##__VA_ARGS__); \
printf(fmt, ##__VA_ARGS__); \
} while (0)
#else
# define optixuPrintf(fmt, ...) printf(fmt, ##__VA_ARGS__)
#endif
#if OPTIXU_ENABLE_ASSERT
# if defined(__CUDA_ARCH__)
# define optixuAssert(expr, fmt, ...) \
do { \
if (!(expr)) { \
::printf("%s @%s: %u:\n", #expr, __FILE__, __LINE__); \
::printf(fmt"\n", ##__VA_ARGS__); \
assert(0); \
} \
} while (0)
# else
# define optixuAssert(expr, fmt, ...) \
do { \
if (!(expr)) { \
optixu::devPrintf("%s @%s: %u:\n", #expr, __FILE__, __LINE__); \
optixu::devPrintf(fmt"\n", ##__VA_ARGS__); \
abort(); \
} \
} while (0)
# endif
#else // if OPTIXU_ENABLE_ASSERT
# define optixuAssert(expr, fmt, ...)
#endif // if OPTIXU_ENABLE_ASSERT
#define optixuAssert_ShouldNotBeCalled() optixuAssert(false, "Should not be called!")
#define optixuAssert_NotImplemented() optixuAssert(false, "Not implemented yet!")
// JP: stdのメタ関数の抽象化定義。
// EN: Definitions to abstract std meta functions.
#if defined(__CUDACC_RTC__)
// TODO
#else // if defined(__CUDACC_RTC__)
# if __cplusplus >= 202002L
template <class _From, class _To>
concept convertible_to = std::convertible_to<_From, _To>;
# endif
template <class... _Type>
using tuple = std::tuple<_Type...>;
template <size_t _Index, class _Tuple>
using tuple_element_t = std::tuple_element_t<_Index, _Tuple>;
template <size_t... _Vals>
using index_sequence = std::index_sequence<_Vals...>;
template <size_t _Size>
using make_index_sequence = std::make_index_sequence<_Size>;
#endif // if defined(__CUDACC_RTC__)
namespace detail {
template <typename T>
RT_DEVICE_FUNCTION RT_INLINE constexpr size_t getNumDwords() {
return (sizeof(T) + 3) / 4;
}
template <typename... Types>
RT_DEVICE_FUNCTION RT_INLINE constexpr size_t calcSumDwords() {
return (0 + ... + getNumDwords<Types>());
}
}
#if !defined(__CUDA_ARCH__)
struct PayloadType {
OptixPayloadSemantics semantics[OPTIX_COMPILE_DEFAULT_MAX_PAYLOAD_VALUE_COUNT];
uint32_t numDwords;
PayloadType() : numDwords(0) {
for (uint32_t i = 0; i < OPTIX_COMPILE_DEFAULT_MAX_PAYLOAD_VALUE_COUNT; ++i)
semantics[i] = static_cast<OptixPayloadSemantics>(0);
}
OptixPayloadType getRawType() const {
OptixPayloadType ret;
ret.numPayloadValues = numDwords;
ret.payloadSemantics = reinterpret_cast<const uint32_t*>(semantics);
return ret;
}
};
#endif // if !defined(__CUDA_ARCH__)
// ----------------------------------------------------------------
// JP: ホスト・デバイス共有のクラス定義
// EN: Definitions of Host-/Device-shared classes
template <typename FuncType>
class DirectCallableProgramID;
template <typename ReturnType, typename... ArgTypes>
class DirectCallableProgramID<ReturnType(ArgTypes...)> {
uint32_t m_sbtIndex;
public:
RT_COMMON_FUNCTION RT_INLINE DirectCallableProgramID() {}
RT_COMMON_FUNCTION RT_INLINE explicit DirectCallableProgramID(uint32_t sbtIndex) : m_sbtIndex(sbtIndex) {}
RT_COMMON_FUNCTION RT_INLINE explicit operator uint32_t() const { return m_sbtIndex; }
#if defined(__CUDA_ARCH__) || defined(OPTIXU_Platform_CodeCompletion)
RT_DEVICE_FUNCTION RT_INLINE ReturnType operator()(const ArgTypes &... args) const {
return optixDirectCall<ReturnType, ArgTypes...>(m_sbtIndex, args...);
}
#endif
};
template <typename FuncType>
class ContinuationCallableProgramID;
template <typename ReturnType, typename... ArgTypes>
class ContinuationCallableProgramID<ReturnType(ArgTypes...)> {
uint32_t m_sbtIndex;
public:
RT_COMMON_FUNCTION RT_INLINE ContinuationCallableProgramID() {}
RT_COMMON_FUNCTION RT_INLINE explicit ContinuationCallableProgramID(uint32_t sbtIndex) :
m_sbtIndex(sbtIndex) {}
RT_COMMON_FUNCTION RT_INLINE explicit operator uint32_t() const { return m_sbtIndex; }
#if defined(__CUDA_ARCH__) || defined(OPTIXU_Platform_CodeCompletion)
RT_DEVICE_FUNCTION RT_INLINE ReturnType operator()(const ArgTypes &... args) const {
return optixContinuationCall<ReturnType, ArgTypes...>(m_sbtIndex, args...);
}
#endif
};
#if defined(__CUDA_ARCH__) || defined(OPTIXU_Platform_CodeCompletion)
# if __cplusplus >= 202002L
template <typename T>
concept Has3D = requires(T v) {
{ v.x } -> convertible_to<float>;
{ v.y } -> convertible_to<float>;
{ v.z } -> convertible_to<float>;
};
# define OPTIXU_HAS3D_CONCEPT Has3D
# else // if __cplusplus >= 202002L
# define OPTIXU_HAS3D_CONCEPT typename
# endif // if __cplusplus >= 202002L
template <OPTIXU_HAS3D_CONCEPT T>
RT_DEVICE_FUNCTION RT_INLINE float3 toNative(const T &v) {
return make_float3(
static_cast<float>(v.x),
static_cast<float>(v.y),
static_cast<float>(v.z));
}
#endif // if defined(__CUDA_ARCH__) || defined(OPTIXU_Platform_CodeCompletion)
template <typename... PayloadTypes>
struct PayloadSignature {
using Types = tuple<PayloadTypes...>;
template <uint32_t index>
using TypeAt = tuple_element_t<index, Types>;
static constexpr uint32_t numParameters = sizeof...(PayloadTypes);
static constexpr uint32_t numDwords =
static_cast<uint32_t>(detail::calcSumDwords<PayloadTypes...>());
static_assert(
numDwords <= OPTIX_COMPILE_DEFAULT_MAX_PAYLOAD_VALUE_COUNT,
"Maximum number of payloads is "
OPTIXU_TO_STRING(OPTIX_COMPILE_DEFAULT_MAX_PAYLOAD_VALUE_COUNT)
" in dwords.");
static constexpr uint32_t _arraySize = numParameters > 0 ? numParameters : 1u;
static constexpr uint32_t sizesInDwords[_arraySize] = {
static_cast<uint32_t>(detail::getNumDwords<PayloadTypes>())...
};
#if defined(__CUDA_ARCH__) || defined(OPTIXU_Platform_CodeCompletion)
template <
OptixPayloadTypeID payloadTypeID = OPTIX_PAYLOAD_TYPE_DEFAULT,
OPTIXU_HAS3D_CONCEPT PosType, OPTIXU_HAS3D_CONCEPT DirType>
RT_DEVICE_FUNCTION RT_INLINE static void trace(
OptixTraversableHandle handle,
const PosType &origin, const DirType &direction,
float tmin, float tmax, float rayTime,
OptixVisibilityMask visibilityMask, OptixRayFlags rayFlags,
uint32_t SBToffset, uint32_t SBTstride, uint32_t missSBTIndex,
PayloadTypes &... payloads);
template <
OptixPayloadTypeID payloadTypeID = OPTIX_PAYLOAD_TYPE_DEFAULT,
OPTIXU_HAS3D_CONCEPT PosType, OPTIXU_HAS3D_CONCEPT DirType>
RT_DEVICE_FUNCTION RT_INLINE static void traverse(
OptixTraversableHandle handle,
const PosType &origin, const DirType &direction,
float tmin, float tmax, float rayTime,
OptixVisibilityMask visibilityMask, OptixRayFlags rayFlags,
uint32_t SBToffset, uint32_t SBTstride, uint32_t missSBTIndex,
PayloadTypes &... payloads);
template <OptixPayloadTypeID payloadTypeID = OPTIX_PAYLOAD_TYPE_DEFAULT>
RT_DEVICE_FUNCTION RT_INLINE static void invoke(PayloadTypes &... payloads);
RT_DEVICE_FUNCTION RT_INLINE static void get(PayloadTypes*... payloads);
RT_DEVICE_FUNCTION RT_INLINE static void set(const PayloadTypes*... payloads);
template <uint32_t index>
RT_DEVICE_FUNCTION RT_INLINE static void getAt(TypeAt<index>* payload);
template <uint32_t index>
RT_DEVICE_FUNCTION RT_INLINE static void setAt(const TypeAt<index> &payload);
#endif
};
template <typename T, OptixPayloadSemantics _semantics>
struct AnnotatedPayload {
using Type = T;
static constexpr OptixPayloadSemantics semantics = _semantics;
};
template <typename... AnnotatedPayloadTypes>
struct AnnotatedPayloadSignature :
public PayloadSignature<typename AnnotatedPayloadTypes::Type...> {
using BaseSignature = PayloadSignature<typename AnnotatedPayloadTypes::Type...>;
static constexpr OptixPayloadSemantics semantics[BaseSignature::_arraySize] = {
AnnotatedPayloadTypes::semantics...
};
#if !defined(__CUDA_ARCH__)
static PayloadType getPayloadType() {
PayloadType ret;
ret.numDwords = BaseSignature::numDwords;
uint32_t offset = 0;
for (uint32_t varIdx = 0; varIdx < BaseSignature::numParameters; ++varIdx) {
const uint32_t sizeInDwords = BaseSignature::sizesInDwords[varIdx];
const OptixPayloadSemantics varSem = semantics[varIdx];
for (uint32_t dwIdx = 0; dwIdx < sizeInDwords; ++dwIdx)
ret.semantics[offset + dwIdx] = varSem;
offset += sizeInDwords;
}
return ret;
}
#endif
};
template <typename... AttributeTypes>
struct AttributeSignature {
using Types = tuple<AttributeTypes...>;
template <uint32_t index>
using TypeAt = tuple_element_t<index, Types>;
static constexpr uint32_t numParameters = sizeof...(AttributeTypes);
static constexpr uint32_t numDwords =
static_cast<uint32_t>(detail::calcSumDwords<AttributeTypes...>());
static_assert(numDwords <= 8, "Maximum number of attributes is 8 dwords.");
static constexpr uint32_t sizesInDwords[numParameters] = {
static_cast<uint32_t>(detail::getNumDwords<AttributeTypes>())...
};
#if defined(__CUDA_ARCH__) || defined(OPTIXU_Platform_CodeCompletion)
RT_DEVICE_FUNCTION RT_INLINE static bool reportIntersection(
float hitT, uint32_t hitKind,
const AttributeTypes &... attributes);
RT_DEVICE_FUNCTION RT_INLINE static void get(AttributeTypes*... attributes);
RT_DEVICE_FUNCTION RT_INLINE static void getFromHitObject(AttributeTypes*... attributes);
#endif
};
template <typename... ExceptionDetailTypes>
struct ExceptionDetailSignature {
using Types = tuple<ExceptionDetailTypes...>;
template <uint32_t index>
using TypeAt = tuple_element_t<index, Types>;
static constexpr uint32_t numParameters = sizeof...(ExceptionDetailTypes);
static constexpr uint32_t numDwords =
static_cast<uint32_t>(detail::calcSumDwords<ExceptionDetailTypes...>());
static_assert(numDwords <= 8, "Maximum number of exception details is 8 dwords.");
static constexpr uint32_t sizesInDwords[numParameters] = {
static_cast<uint32_t>(detail::getNumDwords<ExceptionDetailTypes>())...
};
#if defined(__CUDA_ARCH__) || defined(OPTIXU_Platform_CodeCompletion)
RT_DEVICE_FUNCTION RT_INLINE static void throwException(
int32_t exceptionCode,
const ExceptionDetailTypes &... exDetails);
RT_DEVICE_FUNCTION RT_INLINE static void get(ExceptionDetailTypes*... exDetails);
#endif
};
// END: Definitions of Host-/Device-shared classes
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// JP: デバイス関数のラッパー
// EN: Device-side function wrappers
#if defined(__CUDA_ARCH__) || defined(OPTIXU_Platform_CodeCompletion)
namespace detail {
template <uint32_t index, size_t N>
RT_DEVICE_FUNCTION RT_INLINE constexpr uint32_t calcOffset(const uint32_t (&sizes)[N]) {
if constexpr (index == 0)
return 0;
else
return sizes[index - 1] + calcOffset<index - 1>(sizes);
}
template <uint32_t start, typename HeadType, typename... TailTypes>
RT_DEVICE_FUNCTION RT_INLINE void packToUInts(
uint32_t* v, const HeadType &head, const TailTypes &... tails)
{
static_assert(sizeof(HeadType) % sizeof(uint32_t) == 0,
"Value type of size not multiple of Dword is not supported.");
constexpr uint32_t numDwords = sizeof(HeadType) / sizeof(uint32_t);
#pragma unroll
for (int i = 0; i < numDwords; ++i)
v[start + i] = *(reinterpret_cast<const uint32_t*>(&head) + i);
if constexpr (sizeof...(tails) > 0)
packToUInts<start + numDwords>(v, tails...);
}
template <typename Func, typename Type, uint32_t offsetInDst, uint32_t srcSlot>
RT_DEVICE_FUNCTION RT_INLINE void getValue(
Type* value)
{
if (!value) // hope calls for this function are removed when value is compile-time nullptr.
return;
*(reinterpret_cast<uint32_t*>(value) + offsetInDst) = Func::template get<srcSlot>();
if constexpr (offsetInDst + 1 < getNumDwords<Type>())
getValue<Func, Type, offsetInDst + 1, srcSlot + 1>(value);
}
template <typename Func, uint32_t srcStartSlot, typename HeadType, typename... TailTypes>
RT_DEVICE_FUNCTION RT_INLINE void getValues(
HeadType* head, TailTypes*... tails)
{
static_assert(sizeof(HeadType) % sizeof(uint32_t) == 0,
"Value type of size not multiple of Dword is not supported.");
getValue<Func, HeadType, 0, srcStartSlot>(head);
if constexpr (sizeof...(tails) > 0)
getValues<Func, srcStartSlot + getNumDwords<HeadType>()>(tails...);
}
template <typename Func, typename Type, uint32_t offsetInSrc, uint32_t dstSlot>
RT_DEVICE_FUNCTION RT_INLINE void setValue(
const Type* value)
{
if (!value) // hope calls for this function are removed when value is compile-time nullptr.
return;
Func::set<dstSlot>(*(reinterpret_cast<const uint32_t*>(value) + offsetInSrc));
if constexpr (offsetInSrc + 1 < getNumDwords<Type>())
setValue<Func, Type, offsetInSrc + 1, dstSlot + 1>(value);
}
template <typename Func, uint32_t dstStartSlot, typename HeadType, typename... TailTypes>
RT_DEVICE_FUNCTION RT_INLINE void setValues(
const HeadType* head, const TailTypes*... tails)
{
static_assert(sizeof(HeadType) % sizeof(uint32_t) == 0,
"Value type of size not multiple of Dword is not supported.");
setValue<Func, HeadType, 0, dstStartSlot>(head);
if constexpr (sizeof...(tails) > 0)
setValues<Func, dstStartSlot + getNumDwords<HeadType>()>(tails...);
}
template <uint32_t startSlot, typename HeadType, typename... TailTypes>
RT_DEVICE_FUNCTION RT_INLINE void traceSetPayloads(
uint32_t** p, HeadType &headPayload, TailTypes &... tailPayloads)
{
static_assert(sizeof(HeadType) % sizeof(uint32_t) == 0,
"Payload type of size not multiple of Dword is not supported.");
constexpr uint32_t numDwords = getNumDwords<HeadType>();
#pragma unroll
for (int i = 0; i < numDwords; ++i)
p[startSlot + i] = reinterpret_cast<uint32_t*>(&headPayload) + i;
if constexpr (sizeof...(tailPayloads) > 0)
traceSetPayloads<startSlot + numDwords>(p, tailPayloads...);
}
template <bool withInvoke, OptixPayloadTypeID payloadTypeID, size_t... I>
RT_DEVICE_FUNCTION RT_INLINE void traverse(
OptixTraversableHandle handle,
const float3 &origin, const float3 &direction,
float tmin, float tmax, float rayTime,
OptixVisibilityMask visibilityMask, OptixRayFlags rayFlags,
uint32_t SBToffset, uint32_t SBTstride, uint32_t missSBTIndex,
uint32_t* const* payloads,
index_sequence<I...>)
{
if constexpr (withInvoke) {
optixTrace(
payloadTypeID,
handle,
origin, direction,
tmin, tmax, rayTime,
visibilityMask, rayFlags,
SBToffset, SBTstride, missSBTIndex,
*payloads[I]...);
}
else {
optixTraverse(
payloadTypeID,
handle,
origin, direction,
tmin, tmax, rayTime,
visibilityMask, rayFlags,
SBToffset, SBTstride, missSBTIndex,
*payloads[I]...);
}
}
template <OptixPayloadTypeID payloadTypeID, size_t... I>
RT_DEVICE_FUNCTION RT_INLINE void invoke(
uint32_t* const* payloads, index_sequence<I...>)
{
optixInvoke(payloadTypeID, *payloads[I]...);
}
template <size_t... I>
RT_DEVICE_FUNCTION RT_INLINE bool reportIntersection(
float hitT, uint32_t hitKind, const uint32_t* attributes,
index_sequence<I...>)
{
return optixReportIntersection(hitT, hitKind, attributes[I]...);
}
template <size_t... I>
RT_DEVICE_FUNCTION RT_INLINE void throwException(
int32_t exceptionCode, const uint32_t* exDetails,
index_sequence<I...>)
{
optixThrowException(exceptionCode, exDetails[I]...);
}
struct PayloadFunc {
template <uint32_t index>
RT_DEVICE_FUNCTION RT_INLINE static uint32_t get() {
#define OPTIXU_INTRINSIC_GET_PAYLOAD(Index) \
if constexpr (index == Index) return optixGetPayload_##Index()
OPTIXU_INTRINSIC_GET_PAYLOAD(0);
OPTIXU_INTRINSIC_GET_PAYLOAD(1);
OPTIXU_INTRINSIC_GET_PAYLOAD(2);
OPTIXU_INTRINSIC_GET_PAYLOAD(3);
OPTIXU_INTRINSIC_GET_PAYLOAD(4);
OPTIXU_INTRINSIC_GET_PAYLOAD(5);
OPTIXU_INTRINSIC_GET_PAYLOAD(6);
OPTIXU_INTRINSIC_GET_PAYLOAD(7);
OPTIXU_INTRINSIC_GET_PAYLOAD(8);
OPTIXU_INTRINSIC_GET_PAYLOAD(9);
OPTIXU_INTRINSIC_GET_PAYLOAD(10);
OPTIXU_INTRINSIC_GET_PAYLOAD(11);
OPTIXU_INTRINSIC_GET_PAYLOAD(12);
OPTIXU_INTRINSIC_GET_PAYLOAD(13);
OPTIXU_INTRINSIC_GET_PAYLOAD(14);
OPTIXU_INTRINSIC_GET_PAYLOAD(15);
OPTIXU_INTRINSIC_GET_PAYLOAD(16);
OPTIXU_INTRINSIC_GET_PAYLOAD(17);
OPTIXU_INTRINSIC_GET_PAYLOAD(18);
OPTIXU_INTRINSIC_GET_PAYLOAD(19);
OPTIXU_INTRINSIC_GET_PAYLOAD(20);
OPTIXU_INTRINSIC_GET_PAYLOAD(21);
OPTIXU_INTRINSIC_GET_PAYLOAD(22);
OPTIXU_INTRINSIC_GET_PAYLOAD(23);
OPTIXU_INTRINSIC_GET_PAYLOAD(24);
OPTIXU_INTRINSIC_GET_PAYLOAD(25);
OPTIXU_INTRINSIC_GET_PAYLOAD(26);
OPTIXU_INTRINSIC_GET_PAYLOAD(27);
OPTIXU_INTRINSIC_GET_PAYLOAD(28);
OPTIXU_INTRINSIC_GET_PAYLOAD(29);
OPTIXU_INTRINSIC_GET_PAYLOAD(30);
OPTIXU_INTRINSIC_GET_PAYLOAD(31);
#undef OPTIXU_INTRINSIC_GET_PAYLOAD
return 0;
}
template <uint32_t index>
RT_DEVICE_FUNCTION RT_INLINE static void set(uint32_t p) {
#define OPTIXU_INTRINSIC_SET_PAYLOAD(Index) \
if constexpr (index == Index) optixSetPayload_ ##Index(p)
OPTIXU_INTRINSIC_SET_PAYLOAD(0);
OPTIXU_INTRINSIC_SET_PAYLOAD(1);
OPTIXU_INTRINSIC_SET_PAYLOAD(2);
OPTIXU_INTRINSIC_SET_PAYLOAD(3);
OPTIXU_INTRINSIC_SET_PAYLOAD(4);
OPTIXU_INTRINSIC_SET_PAYLOAD(5);
OPTIXU_INTRINSIC_SET_PAYLOAD(6);
OPTIXU_INTRINSIC_SET_PAYLOAD(7);
OPTIXU_INTRINSIC_SET_PAYLOAD(8);
OPTIXU_INTRINSIC_SET_PAYLOAD(9);
OPTIXU_INTRINSIC_SET_PAYLOAD(10);
OPTIXU_INTRINSIC_SET_PAYLOAD(11);
OPTIXU_INTRINSIC_SET_PAYLOAD(12);
OPTIXU_INTRINSIC_SET_PAYLOAD(13);
OPTIXU_INTRINSIC_SET_PAYLOAD(14);
OPTIXU_INTRINSIC_SET_PAYLOAD(15);
OPTIXU_INTRINSIC_SET_PAYLOAD(16);
OPTIXU_INTRINSIC_SET_PAYLOAD(17);
OPTIXU_INTRINSIC_SET_PAYLOAD(18);
OPTIXU_INTRINSIC_SET_PAYLOAD(19);
OPTIXU_INTRINSIC_SET_PAYLOAD(20);
OPTIXU_INTRINSIC_SET_PAYLOAD(21);
OPTIXU_INTRINSIC_SET_PAYLOAD(22);
OPTIXU_INTRINSIC_SET_PAYLOAD(23);
OPTIXU_INTRINSIC_SET_PAYLOAD(24);
OPTIXU_INTRINSIC_SET_PAYLOAD(25);
OPTIXU_INTRINSIC_SET_PAYLOAD(26);
OPTIXU_INTRINSIC_SET_PAYLOAD(27);
OPTIXU_INTRINSIC_SET_PAYLOAD(28);
OPTIXU_INTRINSIC_SET_PAYLOAD(29);
OPTIXU_INTRINSIC_SET_PAYLOAD(30);
OPTIXU_INTRINSIC_SET_PAYLOAD(31);
#undef OPTIXU_INTRINSIC_SET_PAYLOAD
}
};
struct AttributeFunc {
template <uint32_t index>
RT_DEVICE_FUNCTION RT_INLINE static uint32_t get() {
#define OPTIXU_INTRINSIC_GET_ATTRIBUTE(Index) \
if constexpr (index == Index) return optixGetAttribute_##Index()
OPTIXU_INTRINSIC_GET_ATTRIBUTE(0);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(1);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(2);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(3);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(4);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(5);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(6);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(7);
#undef OPTIXU_INTRINSIC_GET_ATTRIBUTE
return 0;
}
};
struct HitObjectAttributeFunc {
template <uint32_t index>
RT_DEVICE_FUNCTION RT_INLINE static uint32_t get() {
#define OPTIXU_INTRINSIC_GET_ATTRIBUTE(Index) \
if constexpr (index == Index) return optixHitObjectGetAttribute_##Index()
OPTIXU_INTRINSIC_GET_ATTRIBUTE(0);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(1);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(2);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(3);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(4);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(5);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(6);
OPTIXU_INTRINSIC_GET_ATTRIBUTE(7);
#undef OPTIXU_INTRINSIC_GET_ATTRIBUTE
return 0;
}
};
struct ExceptionDetailFunc {
template <uint32_t index>
RT_DEVICE_FUNCTION RT_INLINE static uint32_t get() {
#define OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(Index) \
if constexpr (index == Index) return optixGetExceptionDetail_##Index()
OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(0);
OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(1);
OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(2);
OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(3);
OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(4);
OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(5);
OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(6);
OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL(7);
#undef OPTIXU_INTRINSIC_GET_EXCEPTION_DETAIL
return 0;
}
};
}
template <typename... PayloadTypes>
template <OptixPayloadTypeID payloadTypeID, OPTIXU_HAS3D_CONCEPT PosType, OPTIXU_HAS3D_CONCEPT DirType>
RT_DEVICE_FUNCTION RT_INLINE void PayloadSignature<PayloadTypes...>::
trace(
OptixTraversableHandle handle,
const PosType &origin, const DirType &direction,
float tmin, float tmax, float rayTime,
OptixVisibilityMask visibilityMask, OptixRayFlags rayFlags,
uint32_t SBToffset, uint32_t SBTstride, uint32_t missSBTIndex,
PayloadTypes &... payloads)
{