MDL SDK API nvidia_logo_transpbg.gif Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
target_code_types.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright 2022 NVIDIA Corporation. All rights reserved.
3  **************************************************************************************************/
6 
7 #ifndef MI_NEURAYLIB_TARGET_CODE_TYPES_H
8 #define MI_NEURAYLIB_TARGET_CODE_TYPES_H
9 
10 
11 // If neither TARGET_CODE_USE_CUDA_TYPES nor TARGET_CODE_USE_NEURAY_TYPES is set,
12 // it will default to CUDA types when compiled by a CUDA compiler and use Neuray types otherwise.
13 
14 #if defined(TARGET_CODE_USE_CUDA_TYPES) && defined(TARGET_CODE_USE_NEURAY_TYPES)
15 #error "Only one of TARGET_CODE_USE_CUDA_TYPES and TARGET_CODE_USE_NEURAY_TYPES may be defined."
16 #endif
17 
18 #if !defined(TARGET_CODE_USE_NEURAY_TYPES) && \
19  (defined(TARGET_CODE_USE_CUDA_TYPES) || defined(__CUDA_ARCH__))
20 
21 #include <vector_types.h>
22 
23 namespace mi {
24 
25 namespace neuraylib {
26 
31 typedef float tct_float;
33 
35 typedef float2 tct_float2;
36 
38 typedef float3 tct_float3;
39 
41 typedef float4 tct_float4;
42 
44 typedef int tct_int;
45 
47 typedef unsigned tct_uint;
48 
49 #else
50 
51 #include <mi/neuraylib/typedefs.h>
52 
53 namespace mi {
54 
55 namespace neuraylib {
56 
61 typedef float tct_float;
63 
66 
69 
72 
75 
78 
79 #endif
80 
82 typedef bool tct_bool;
83 
84 
86 template<typename T>
87 struct tct_deriv
88 {
89  T val, dx, dy;
90 };
91 
93 template<bool with_derivatives>
94 struct tct_traits;
95 
96 template<>
97 struct tct_traits<false>
98 {
99  typedef tct_float tct_derivable_float;
100  typedef tct_float2 tct_derivable_float2;
101  typedef tct_float3 tct_derivable_float3;
102  typedef tct_float4 tct_derivable_float4;
103  typedef tct_float const tct_coord2_type[2];
104 };
105 
106 template<>
107 struct tct_traits<true>
108 {
109  typedef tct_deriv<tct_float> tct_derivable_float;
110  typedef tct_deriv<tct_float2> tct_derivable_float2;
111  typedef tct_deriv<tct_float3> tct_derivable_float3;
112  typedef tct_deriv<tct_float4> tct_derivable_float4;
113  typedef tct_derivable_float2 const * tct_coord2_type;
114 };
115 
118 
121 
124 
127 
130 
133 
136 
137 
155 
169  char const *ro_data_segment;
170 };
171 
172 
200 template<bool with_derivatives = false>
203 
209 
213 
216  typename traits::tct_derivable_float3 position;
217 
221 
225  typename traits::tct_derivable_float3 const *text_coords;
226 
233 
240 
248 
262  char const *ro_data_segment;
263 
270 
277 
283 
288 };
289 
292 
295 
296 
303 
307 
311 
315 };
316 
319 {
322 
325 };
326 
327 
328 // Forward declaration of texture handler structure.
329 struct Texture_handler_base;
330 
331 
334 template<bool with_derivatives = false>
337 
339  void (*m_tex_lookup_float4_2d)(
340  tct_float result[4],
341  Texture_handler_base const *self,
342  tct_uint texture_idx,
343  typename traits::tct_coord2_type coord,
344  Tex_wrap_mode wrap_u,
345  Tex_wrap_mode wrap_v,
346  tct_float const crop_u[2],
347  tct_float const crop_v[2],
348  tct_float frame);
349 
351  void (*m_tex_lookup_float3_2d)(
352  tct_float result[3],
353  Texture_handler_base const *self,
354  tct_uint texture_idx,
355  typename traits::tct_coord2_type coord,
356  Tex_wrap_mode wrap_u,
357  Tex_wrap_mode wrap_v,
358  tct_float const crop_u[2],
359  tct_float const crop_v[2],
360  tct_float frame);
361 
363  void (*m_tex_texel_float4_2d)(
364  tct_float result[4],
365  Texture_handler_base const *self,
366  tct_uint texture_idx,
367  tct_int const coord[2],
368  tct_int const uv_tile[2],
369  tct_float frame);
370 
372  void (*m_tex_lookup_float4_3d)(
373  tct_float result[4],
374  Texture_handler_base const *self,
375  tct_uint texture_idx,
376  tct_float const coord[3],
377  Tex_wrap_mode wrap_u,
378  Tex_wrap_mode wrap_v,
379  Tex_wrap_mode wrap_w,
380  tct_float const crop_u[2],
381  tct_float const crop_v[2],
382  tct_float const crop_w[2],
383  tct_float frame);
384 
386  void (*m_tex_lookup_float3_3d)(
387  tct_float result[3],
388  Texture_handler_base const *self,
389  tct_uint texture_idx,
390  tct_float const coord[3],
391  Tex_wrap_mode wrap_u,
392  Tex_wrap_mode wrap_v,
393  Tex_wrap_mode wrap_w,
394  tct_float const crop_u[2],
395  tct_float const crop_v[2],
396  tct_float const crop_w[2],
397  tct_float frame);
398 
400  void (*m_tex_texel_float4_3d)(
401  tct_float result[4],
402  Texture_handler_base const *self,
403  tct_uint texture_idx,
404  tct_int const coord[3],
405  tct_float frame);
406 
408  void (*m_tex_lookup_float4_cube)(
409  tct_float result[4],
410  Texture_handler_base const *self,
411  tct_uint texture_idx,
412  tct_float const coord[3]);
413 
415  void (*m_tex_lookup_float3_cube)(
416  tct_float result[3],
417  Texture_handler_base const *self,
418  tct_uint texture_idx,
419  tct_float const coord[3]);
420 
424  void (*m_tex_resolution_2d)(
425  tct_int result[2],
426  Texture_handler_base const *self,
427  tct_uint texture_idx,
428  tct_int const uv_tile[2],
429  tct_float frame);
430 
434  void (*m_tex_resolution_3d)(
435  tct_int result[3],
436  Texture_handler_base const *self,
437  tct_uint texture_idx,
438  tct_float frame);
439 
441  tct_bool (*m_tex_texture_isvalid)(
442  Texture_handler_base const *self,
443  tct_uint texture_idx);
444 
447  void (*m_tex_frame)(
448  tct_int result[2],
449  Texture_handler_base const *self,
450  tct_uint texture_idx);
451 
453  tct_float (*m_df_light_profile_power)(
454  Texture_handler_base const *self,
455  tct_uint light_profile_index);
456 
458  tct_float (*m_df_light_profile_maximum)(
459  Texture_handler_base const *self,
460  tct_uint light_profile_index);
461 
463  tct_bool (*m_df_light_profile_isvalid)(
464  Texture_handler_base const *self,
465  tct_uint light_profile_index);
466 
468  tct_float (*m_df_light_profile_evaluate)(
469  Texture_handler_base const *self,
470  tct_uint light_profile_index,
471  tct_float const theta_phi[2]);
472 
474  void (*m_df_light_profile_sample)(
475  tct_float result[3],
477  Texture_handler_base const *self,
478  tct_uint light_profile_index,
479  tct_float const xi[3]);
480 
482  tct_float (*m_df_light_profile_pdf)(
483  Texture_handler_base const *self,
484  tct_uint light_profile_index,
485  tct_float const theta_phi[2]);
486 
488  tct_bool (*m_df_bsdf_measurement_isvalid)(
489  Texture_handler_base const *self,
490  tct_uint bsdf_measurement_index);
491 
496  void (*m_df_bsdf_measurement_resolution)(
497  tct_uint result[3],
498  Texture_handler_base const *self,
499  tct_uint bsdf_measurement_index,
500  Mbsdf_part part);
501 
503  void (*m_df_bsdf_measurement_evaluate)(
504  tct_float result[3],
505  Texture_handler_base const *self,
506  tct_uint bsdf_measurement_index,
507  tct_float const theta_phi_in[2],
508  tct_float const theta_phi_out[2],
509  Mbsdf_part part);
510 
512  void (*m_df_bsdf_measurement_sample)(
513  tct_float result[3],
515  Texture_handler_base const *self,
516  tct_uint bsdf_measurement_index,
517  tct_float const theta_phi_out[2],
518  tct_float const xi[3],
519  Mbsdf_part part);
520 
522  tct_float (*m_df_bsdf_measurement_pdf)(
523  Texture_handler_base const *self,
524  tct_uint bsdf_measurement_index,
525  tct_float const theta_phi_in[2],
526  tct_float const theta_phi_out[2],
527  Mbsdf_part part);
528 
530  void (*m_df_bsdf_measurement_albedos)(
531  tct_float result[4],
537  Texture_handler_base const *self,
538  tct_uint bsdf_measurement_index,
539  tct_float const theta_phi[2]);
540 
542  void (*m_adapt_normal)(
543  tct_float result[3],
544  Texture_handler_base const *self_base,
545  Shading_state_material *state,
546  tct_float const normal[3]);
547 
549  tct_bool (*m_scene_data_isvalid)(
550  Texture_handler_base const *self_base,
551  Shading_state_material *state,
552  tct_uint scene_data_id);
553 
555  tct_float (*m_scene_data_lookup_float)(
556  Texture_handler_base const *self_base,
557  Shading_state_material *state,
558  tct_uint scene_data_id,
559  tct_float default_value,
560  tct_bool uniform_lookup);
561 
563  void (*m_scene_data_lookup_float2)(
564  tct_float result[2],
565  Texture_handler_base const *self_base,
566  Shading_state_material *state,
567  tct_uint scene_data_id,
568  tct_float const default_value[2],
569  tct_bool uniform_lookup);
570 
572  void (*m_scene_data_lookup_float3)(
573  tct_float result[3],
574  Texture_handler_base const *self_base,
575  Shading_state_material *state,
576  tct_uint scene_data_id,
577  tct_float const default_value[3],
578  tct_bool uniform_lookup);
579 
581  void (*m_scene_data_lookup_float4)(
582  tct_float result[4],
583  Texture_handler_base const *self_base,
584  Shading_state_material *state,
585  tct_uint scene_data_id,
586  tct_float const default_value[4],
587  tct_bool uniform_lookup);
588 
590  tct_int (*m_scene_data_lookup_int)(
591  Texture_handler_base const *self_base,
592  Shading_state_material *state,
593  tct_uint scene_data_id,
594  tct_int default_value,
595  tct_bool uniform_lookup);
596 
598  void (*m_scene_data_lookup_int2)(
599  tct_int result[2],
600  Texture_handler_base const *self_base,
601  Shading_state_material *state,
602  tct_uint scene_data_id,
603  tct_int const default_value[2],
604  tct_bool uniform_lookup);
605 
607  void (*m_scene_data_lookup_int3)(
608  tct_int result[3],
609  Texture_handler_base const *self_base,
610  Shading_state_material *state,
611  tct_uint scene_data_id,
612  tct_int const default_value[3],
613  tct_bool uniform_lookup);
614 
616  void (*m_scene_data_lookup_int4)(
617  tct_int result[4],
618  Texture_handler_base const *self_base,
619  Shading_state_material *state,
620  tct_uint scene_data_id,
621  tct_int const default_value[4],
622  tct_bool uniform_lookup);
623 
625  void (*m_scene_data_lookup_color)(
626  tct_float result[3],
627  Texture_handler_base const *self_base,
628  Shading_state_material *state,
629  tct_uint scene_data_id,
630  tct_float const default_value[3],
631  tct_bool uniform_lookup);
632 
633  //
634  // The following functions are only used in the derivative variant,
635  // and can be nullptr in the non-derivative variant
636  //
637 
639  void (*m_scene_data_lookup_deriv_float)(
640  tct_deriv_float *result,
641  Texture_handler_base const *self_base,
643  tct_uint scene_data_id,
644  tct_deriv_float const *default_value,
645  tct_bool uniform_lookup);
646 
648  void (*m_scene_data_lookup_deriv_float2)(
649  tct_deriv_arr_float_2 *result,
650  Texture_handler_base const *self_base,
652  tct_uint scene_data_id,
653  tct_deriv_arr_float_2 const *default_value,
654  tct_bool uniform_lookup);
655 
657  void (*m_scene_data_lookup_deriv_float3)(
658  tct_deriv_arr_float_3 *result,
659  Texture_handler_base const *self_base,
661  tct_uint scene_data_id,
662  tct_deriv_arr_float_3 const *default_value,
663  tct_bool uniform_lookup);
664 
666  void (*m_scene_data_lookup_deriv_float4)(
667  tct_deriv_arr_float_4 *result,
668  Texture_handler_base const *self_base,
670  tct_uint scene_data_id,
671  tct_deriv_arr_float_4 const *default_value,
672  tct_bool uniform_lookup);
673 
675  void (*m_scene_data_lookup_deriv_color)(
676  tct_deriv_arr_float_3 *result,
677  Texture_handler_base const *self_base,
679  tct_uint scene_data_id,
680  tct_deriv_arr_float_3 const *default_value,
681  tct_bool uniform_lookup);
682 };
683 
686 
689 
697 };
698 
706 };
707 
708 
711  void const *shared_data;
713 };
715 
718  BSDF_EVENT_ABSORB = 0,
719 
720  BSDF_EVENT_DIFFUSE = 1,
721  BSDF_EVENT_GLOSSY = 1 << 1,
722  BSDF_EVENT_SPECULAR = 1 << 2,
723  BSDF_EVENT_REFLECTION = 1 << 3,
724  BSDF_EVENT_TRANSMISSION = 1 << 4,
725 
726  BSDF_EVENT_DIFFUSE_REFLECTION = BSDF_EVENT_DIFFUSE | BSDF_EVENT_REFLECTION,
727  BSDF_EVENT_DIFFUSE_TRANSMISSION = BSDF_EVENT_DIFFUSE | BSDF_EVENT_TRANSMISSION,
728  BSDF_EVENT_GLOSSY_REFLECTION = BSDF_EVENT_GLOSSY | BSDF_EVENT_REFLECTION,
729  BSDF_EVENT_GLOSSY_TRANSMISSION = BSDF_EVENT_GLOSSY | BSDF_EVENT_TRANSMISSION,
730  BSDF_EVENT_SPECULAR_REFLECTION = BSDF_EVENT_SPECULAR | BSDF_EVENT_REFLECTION,
731  BSDF_EVENT_SPECULAR_TRANSMISSION = BSDF_EVENT_SPECULAR | BSDF_EVENT_TRANSMISSION,
732 
733  BSDF_EVENT_FORCE_32_BIT = 0xffffffffU
734 };
735 
739 #define MI_NEURAYLIB_BSDF_USE_MATERIAL_IOR (-1.0f)
740 
746 
753 };
754 
757 {
759  DF_HSM_NONE = -1,
764 };
765 
768 
769 template<Df_handle_slot_mode N>
770 struct Bsdf_evaluate_data : public Bsdf_evaluate_data_base
771 {
772  tct_float3 ior1;
773  tct_float3 ior2;
774  tct_float3 k1;
775 
776  tct_float3 k2;
777  tct_int handle_offset;
778  tct_float3 bsdf_diffuse[static_cast<size_t>(N)];
780  tct_float3 bsdf_glossy[static_cast<size_t>(N)];
782  tct_float pdf;
784 };
785 
786 template<>
787 struct Bsdf_evaluate_data<DF_HSM_POINTER> : public Bsdf_evaluate_data_base
788 {
789  tct_float3 ior1;
790  tct_float3 ior2;
791  tct_float3 k1;
792 
793  tct_float3 k2;
794  tct_int handle_offset;
795  tct_int handle_count;
797  tct_float3* bsdf_diffuse;
798  tct_float3* bsdf_glossy;
799  tct_float pdf;
800 };
801 
802 template<>
803 struct Bsdf_evaluate_data<DF_HSM_NONE> : public Bsdf_evaluate_data_base
804 {
805  tct_float3 ior1;
806  tct_float3 ior2;
807  tct_float3 k1;
808 
809  tct_float3 k2;
810  tct_float3 bsdf_diffuse;
811  tct_float3 bsdf_glossy;
812  tct_float pdf;
813 };
814 
820 
823 };
824 
827 
828 template<Df_handle_slot_mode N>
829 struct Bsdf_auxiliary_data : public Bsdf_auxiliary_data_base
830 {
831  tct_float3 ior1;
832  tct_float3 ior2;
833  tct_float3 k1;
834 
835  tct_int handle_offset;
836  tct_float3 albedo[static_cast<size_t>(N)];
839  tct_float3 normal[static_cast<size_t>(N)];
840 };
841 
842 template<>
843 struct Bsdf_auxiliary_data<DF_HSM_POINTER> : public Bsdf_auxiliary_data_base
844 {
845  tct_float3 ior1;
846  tct_float3 ior2;
847  tct_float3 k1;
848 
849  tct_int handle_offset;
850  tct_int handle_count;
853  tct_float3* albedo;
854  tct_float3* normal;
855 };
856 
857 template<>
858 struct Bsdf_auxiliary_data<DF_HSM_NONE> : public Bsdf_auxiliary_data_base
859 {
860  tct_float3 ior1;
861  tct_float3 ior2;
862  tct_float3 k1;
863 
864  tct_float3 albedo;
865  tct_float3 normal;
866 };
867 
868 // Signatures for generated target code functions.
869 
879 typedef void (Environment_function)(
880  void *result,
881  Shading_state_environment const *state,
882  Resource_data const *res_data,
883  void const *exception_state,
884  char const *arg_block_data);
885 
886 
896 typedef void (Material_expr_function)(
897  void *result,
898  Shading_state_material const *state,
899  Resource_data const *res_data,
900  void const *exception_state,
901  char const *arg_block_data);
902 
903 
914  void *result,
916  Resource_data const *res_data,
917  void const *exception_state,
918  char const *arg_block_data);
919 
920 
933 typedef void (Bsdf_init_function)(
934  Shading_state_material *state,
935  Resource_data const *res_data,
936  void const *exception_state,
937  char const *arg_block_data);
938 
939 
954  Resource_data const *res_data,
955  void const *exception_state,
956  char const *arg_block_data);
957 
958 
968 typedef void (Bsdf_sample_function)(
969  Bsdf_sample_data *data,
970  Shading_state_material const *state,
971  Resource_data const *res_data,
972  void const *exception_state,
973  char const *arg_block_data);
974 
975 
986  Bsdf_sample_data *data,
988  Resource_data const *res_data,
989  void const *exception_state,
990  char const *arg_block_data);
991 
992 
1002 typedef void (Bsdf_evaluate_function)(
1004  Shading_state_material const *state,
1005  Resource_data const *res_data,
1006  void const *exception_state,
1007  char const *arg_block_data);
1008 
1009 
1022  Resource_data const *res_data,
1023  void const *exception_state,
1024  char const *arg_block_data);
1025 
1026 
1036 typedef void (Bsdf_pdf_function)(
1037  Bsdf_pdf_data *data,
1038  Shading_state_material const *state,
1039  Resource_data const *res_data,
1040  void const *exception_state,
1041  char const *arg_block_data);
1042 
1043 
1054  Bsdf_pdf_data *data,
1056  Resource_data const *res_data,
1057  void const *exception_state,
1058  char const *arg_block_data);
1059 
1071  Shading_state_material const *state,
1072  Resource_data const *res_data,
1073  void const *exception_state,
1074  char const *arg_block_data);
1075 
1076 
1089  Resource_data const *res_data,
1090  void const *exception_state,
1091  char const *arg_block_data);
1092 
1095 {
1096  EDF_EVENT_NONE = 0,
1097  EDF_EVENT_EMISSION = 1,
1098 
1099  EDF_EVENT_FORCE_32_BIT = 0xffffffffU
1100 };
1101 
1102 
1105 {
1112 };
1113 
1116 
1117 template<Df_handle_slot_mode N>
1118 struct Edf_evaluate_data : public Edf_evaluate_data_base
1119 {
1120  tct_float3 k1;
1121  tct_int handle_offset;
1122  tct_float cos;
1124  tct_float3 edf[static_cast<size_t>(N)];
1125  tct_float pdf;
1126 };
1127 
1128 template<>
1129 struct Edf_evaluate_data<DF_HSM_POINTER> : public Edf_evaluate_data_base
1130 {
1131  tct_float3 k1;
1132  tct_int handle_offset;
1133  tct_int handle_count;
1135  tct_float cos;
1136  tct_float3* edf;
1137  tct_float pdf;
1138 };
1139 
1140 template<>
1141 struct Edf_evaluate_data<DF_HSM_NONE> : public Edf_evaluate_data_base
1142 {
1143  tct_float3 k1;
1144  tct_float cos;
1145  tct_float3 edf;
1146  tct_float pdf;
1147 };
1148 
1151 {
1154 };
1155 
1158 
1159 template<Df_handle_slot_mode N>
1160 struct Edf_auxiliary_data : public Edf_auxiliary_data_base
1161 {
1162  tct_float3 k1;
1163  tct_int handle_offset;
1164  // reserved for future use
1166 };
1167 
1168 template<>
1169 struct Edf_auxiliary_data<DF_HSM_POINTER> : public Edf_auxiliary_data_base
1170 {
1171  tct_float3 k1;
1172  tct_int handle_offset;
1173  tct_int handle_count;
1175 
1176  // reserved for future use
1177 };
1178 
1179 template<>
1180 struct Edf_auxiliary_data<DF_HSM_NONE> : public Edf_auxiliary_data_base
1181 {
1182  tct_float3 k1;
1183 
1184  // reserved for future use
1185 };
1186 
1199 typedef void (Edf_init_function)(
1200  Shading_state_material *state,
1201  Resource_data const *res_data,
1202  void const *exception_state,
1203  char const *arg_block_data);
1204 
1205 
1220  Resource_data const *res_data,
1221  void const *exception_state,
1222  char const *arg_block_data);
1223 
1224 
1234 typedef void (Edf_sample_function)(
1235  Edf_sample_data *data,
1236  Shading_state_material const *state,
1237  Resource_data const *res_data,
1238  void const *exception_state,
1239  char const *arg_block_data);
1240 
1241 
1252  Edf_sample_data *data,
1254  Resource_data const *res_data,
1255  void const *exception_state,
1256  char const *arg_block_data);
1257 
1258 
1268 typedef void (Edf_evaluate_function)(
1269  Edf_evaluate_data_base *data,
1270  Shading_state_material const *state,
1271  Resource_data const *res_data,
1272  void const *exception_state,
1273  char const *arg_block_data);
1274 
1275 
1286  Edf_evaluate_data_base *data,
1288  Resource_data const *res_data,
1289  void const *exception_state,
1290  char const *arg_block_data);
1291 
1292 
1302 typedef void (Edf_pdf_function)(
1303  Edf_pdf_data *data,
1304  Shading_state_material const *state,
1305  Resource_data const *res_data,
1306  void const *exception_state,
1307  char const *arg_block_data);
1308 
1309 
1320  Edf_pdf_data *data,
1322  Resource_data const *res_data,
1323  void const *exception_state,
1324  char const *arg_block_data);
1325 
1335 typedef void (Edf_auxiliary_function)(
1337  Shading_state_material const *state,
1338  Resource_data const *res_data,
1339  void const *exception_state,
1340  char const *arg_block_data);
1341 
1342 
1355  Resource_data const *res_data,
1356  void const *exception_state,
1357  char const *arg_block_data);
1358  // end group mi_neuray_mdl_compiler
1360 
1361 } // namespace neuraylib
1362 
1363 } // namespace mi
1364 
1365 #endif // MI_NEURAYLIB_TARGET_CODE_TYPES_H