Material Definition Language 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 2020 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 
128 
146 
160  char const *ro_data_segment;
161 };
162 
163 
191 template<bool with_derivatives = false>
194 
200 
204 
207  typename traits::tct_derivable_float3 position;
208 
212 
216  typename traits::tct_derivable_float3 const *text_coords;
217 
224 
231 
239 
253  char const *ro_data_segment;
254 
261 
268 
274 };
275 
278 
281 
282 
289 
293 
297 
301 };
302 
305 {
308 
311 };
312 
313 
314 // Forward declaration of texture handler structure.
315 struct Texture_handler_base;
316 
317 
320 template<bool with_derivatives = false>
323 
325  void (*m_tex_lookup_float4_2d)(
326  tct_float result[4],
327  Texture_handler_base const *self,
328  tct_uint texture_idx,
329  typename traits::tct_coord2_type coord,
330  Tex_wrap_mode wrap_u,
331  Tex_wrap_mode wrap_v,
332  tct_float const crop_u[2],
333  tct_float const crop_v[2]);
334 
336  void (*m_tex_lookup_float3_2d)(
337  tct_float result[3],
338  Texture_handler_base const *self,
339  tct_uint texture_idx,
340  typename traits::tct_coord2_type coord,
341  Tex_wrap_mode wrap_u,
342  Tex_wrap_mode wrap_v,
343  tct_float const crop_u[2],
344  tct_float const crop_v[2]);
345 
347  void (*m_tex_texel_float4_2d)(
348  tct_float result[4],
349  Texture_handler_base const *self,
350  tct_uint texture_idx,
351  tct_int const coord[2],
352  tct_int const uv_tile[2]);
353 
355  void (*m_tex_lookup_float4_3d)(
356  tct_float result[4],
357  Texture_handler_base const *self,
358  tct_uint texture_idx,
359  tct_float const coord[3],
360  Tex_wrap_mode wrap_u,
361  Tex_wrap_mode wrap_v,
362  Tex_wrap_mode wrap_w,
363  tct_float const crop_u[2],
364  tct_float const crop_v[2],
365  tct_float const crop_w[2]);
366 
368  void (*m_tex_lookup_float3_3d)(
369  tct_float result[3],
370  Texture_handler_base const *self,
371  tct_uint texture_idx,
372  tct_float const coord[3],
373  Tex_wrap_mode wrap_u,
374  Tex_wrap_mode wrap_v,
375  Tex_wrap_mode wrap_w,
376  tct_float const crop_u[2],
377  tct_float const crop_v[2],
378  tct_float const crop_w[2]);
379 
381  void (*m_tex_texel_float4_3d)(
382  tct_float result[4],
383  Texture_handler_base const *self,
384  tct_uint texture_idx,
385  tct_int const coord[3]);
386 
388  void (*m_tex_lookup_float4_cube)(
389  tct_float result[4],
390  Texture_handler_base const *self,
391  tct_uint texture_idx,
392  tct_float const coord[3]);
393 
395  void (*m_tex_lookup_float3_cube)(
396  tct_float result[3],
397  Texture_handler_base const *self,
398  tct_uint texture_idx,
399  tct_float const coord[3]);
400 
404  void (*m_tex_resolution_2d)(
405  tct_int result[2],
406  Texture_handler_base const *self,
407  tct_uint texture_idx,
408  tct_int const uv_tile[2]);
409 
413  void (*m_tex_resolution_3d)(
414  tct_int result[3],
415  Texture_handler_base const *self,
416  tct_uint texture_idx);
417 
419  tct_bool (*m_tex_texture_isvalid)(
420  Texture_handler_base const *self,
421  tct_uint texture_idx);
422 
424  tct_float (*m_df_light_profile_power)(
425  Texture_handler_base const *self,
426  tct_uint light_profile_index);
427 
429  tct_float (*m_df_light_profile_maximum)(
430  Texture_handler_base const *self,
431  tct_uint light_profile_index);
432 
434  tct_bool (*m_df_light_profile_isvalid)(
435  Texture_handler_base const *self,
436  tct_uint light_profile_index);
437 
439  tct_float (*m_df_light_profile_evaluate)(
440  Texture_handler_base const *self,
441  tct_uint light_profile_index,
442  tct_float const theta_phi[2]);
443 
445  void (*m_df_light_profile_sample)(
446  tct_float result[3],
448  Texture_handler_base const *self,
449  tct_uint light_profile_index,
450  tct_float const xi[3]);
451 
453  tct_float (*m_df_light_profile_pdf)(
454  Texture_handler_base const *self,
455  tct_uint light_profile_index,
456  tct_float const theta_phi[2]);
457 
459  tct_bool (*m_df_bsdf_measurement_isvalid)(
460  Texture_handler_base const *self,
461  tct_uint bsdf_measurement_index);
462 
467  void (*m_df_bsdf_measurement_resolution)(
468  tct_uint result[3],
469  Texture_handler_base const *self,
470  tct_uint bsdf_measurement_index,
471  Mbsdf_part part);
472 
474  void (*m_df_bsdf_measurement_evaluate)(
475  tct_float result[3],
476  Texture_handler_base const *self,
477  tct_uint bsdf_measurement_index,
478  tct_float const theta_phi_in[2],
479  tct_float const theta_phi_out[2],
480  Mbsdf_part part);
481 
483  void (*m_df_bsdf_measurement_sample)(
484  tct_float result[3],
486  Texture_handler_base const *self,
487  tct_uint bsdf_measurement_index,
488  tct_float const theta_phi_out[2],
489  tct_float const xi[3],
490  Mbsdf_part part);
491 
493  tct_float (*m_df_bsdf_measurement_pdf)(
494  Texture_handler_base const *self,
495  tct_uint bsdf_measurement_index,
496  tct_float const theta_phi_in[2],
497  tct_float const theta_phi_out[2],
498  Mbsdf_part part);
499 
501  void (*m_df_bsdf_measurement_albedos)(
502  tct_float result[4],
508  Texture_handler_base const *self,
509  tct_uint bsdf_measurement_index,
510  tct_float const theta_phi[2]);
511 };
512 
515 
518 
526 };
527 
535 };
536 
537 
540  void const *shared_data;
542 };
544 
547  BSDF_EVENT_ABSORB = 0,
548 
549  BSDF_EVENT_DIFFUSE = 1,
550  BSDF_EVENT_GLOSSY = 1 << 1,
551  BSDF_EVENT_SPECULAR = 1 << 2,
552  BSDF_EVENT_REFLECTION = 1 << 3,
553  BSDF_EVENT_TRANSMISSION = 1 << 4,
554 
555  BSDF_EVENT_DIFFUSE_REFLECTION = BSDF_EVENT_DIFFUSE | BSDF_EVENT_REFLECTION,
556  BSDF_EVENT_DIFFUSE_TRANSMISSION = BSDF_EVENT_DIFFUSE | BSDF_EVENT_TRANSMISSION,
557  BSDF_EVENT_GLOSSY_REFLECTION = BSDF_EVENT_GLOSSY | BSDF_EVENT_REFLECTION,
558  BSDF_EVENT_GLOSSY_TRANSMISSION = BSDF_EVENT_GLOSSY | BSDF_EVENT_TRANSMISSION,
559  BSDF_EVENT_SPECULAR_REFLECTION = BSDF_EVENT_SPECULAR | BSDF_EVENT_REFLECTION,
560  BSDF_EVENT_SPECULAR_TRANSMISSION = BSDF_EVENT_SPECULAR | BSDF_EVENT_TRANSMISSION,
561 
562  BSDF_EVENT_FORCE_32_BIT = 0xffffffffU
563 };
564 
568 #define MI_NEURAYLIB_BSDF_USE_MATERIAL_IOR (-1.0f)
569 
575 
582 };
583 
586 {
588  DF_HSM_NONE = -1,
593 };
594 
597 
598 template<Df_handle_slot_mode N>
599 struct Bsdf_evaluate_data : public Bsdf_evaluate_data_base
600 {
601  tct_float3 ior1;
602  tct_float3 ior2;
603  tct_float3 k1;
604 
605  tct_float3 k2;
606  tct_int handle_offset;
607  tct_float3 bsdf_diffuse[static_cast<size_t>(N)];
609  tct_float3 bsdf_glossy[static_cast<size_t>(N)];
611  tct_float pdf;
613 };
614 
615 template<>
616 struct Bsdf_evaluate_data<DF_HSM_POINTER> : public Bsdf_evaluate_data_base
617 {
618  tct_float3 ior1;
619  tct_float3 ior2;
620  tct_float3 k1;
621 
622  tct_float3 k2;
623  tct_int handle_offset;
624  tct_int handle_count;
626  tct_float3* bsdf_diffuse;
627  tct_float3* bsdf_glossy;
628  tct_float pdf;
629 };
630 
631 template<>
632 struct Bsdf_evaluate_data<DF_HSM_NONE> : public Bsdf_evaluate_data_base
633 {
634  tct_float3 ior1;
635  tct_float3 ior2;
636  tct_float3 k1;
637 
638  tct_float3 k2;
639  tct_float3 bsdf_diffuse;
640  tct_float3 bsdf_glossy;
641  tct_float pdf;
642 };
643 
649 
652 };
653 
656 
657 template<Df_handle_slot_mode N>
658 struct Bsdf_auxiliary_data : public Bsdf_auxiliary_data_base
659 {
660  tct_float3 ior1;
661  tct_float3 ior2;
662  tct_float3 k1;
663 
664  tct_int handle_offset;
665  tct_float3 albedo[static_cast<size_t>(N)];
667  tct_float3 normal[static_cast<size_t>(N)];
668 };
669 
670 template<>
671 struct Bsdf_auxiliary_data<DF_HSM_POINTER> : public Bsdf_auxiliary_data_base
672 {
673  tct_float3 ior1;
674  tct_float3 ior2;
675  tct_float3 k1;
676 
677  tct_int handle_offset;
678  tct_int handle_count;
680  tct_float3* albedo;
681  tct_float3* normal;
682 };
683 
684 template<>
685 struct Bsdf_auxiliary_data<DF_HSM_NONE> : public Bsdf_auxiliary_data_base
686 {
687  tct_float3 ior1;
688  tct_float3 ior2;
689  tct_float3 k1;
690 
691  tct_float3 albedo;
692  tct_float3 normal;
693 };
694 
695 // Signatures for generated target code functions.
696 
706 typedef void (Environment_function)(
707  void *result,
708  Shading_state_environment const *state,
709  Resource_data const *res_data,
710  void const *exception_state,
711  char const *arg_block_data);
712 
713 
723 typedef void (Material_expr_function)(
724  void *result,
725  Shading_state_material const *state,
726  Resource_data const *res_data,
727  void const *exception_state,
728  char const *arg_block_data);
729 
730 
741  void *result,
743  Resource_data const *res_data,
744  void const *exception_state,
745  char const *arg_block_data);
746 
747 
760 typedef void (Bsdf_init_function)(
761  Shading_state_material *state,
762  Resource_data const *res_data,
763  void const *exception_state,
764  char const *arg_block_data);
765 
766 
781  Resource_data const *res_data,
782  void const *exception_state,
783  char const *arg_block_data);
784 
785 
795 typedef void (Bsdf_sample_function)(
796  Bsdf_sample_data *data,
797  Shading_state_material const *state,
798  Resource_data const *res_data,
799  void const *exception_state,
800  char const *arg_block_data);
801 
802 
813  Bsdf_sample_data *data,
815  Resource_data const *res_data,
816  void const *exception_state,
817  char const *arg_block_data);
818 
819 
829 typedef void (Bsdf_evaluate_function)(
831  Shading_state_material const *state,
832  Resource_data const *res_data,
833  void const *exception_state,
834  char const *arg_block_data);
835 
836 
849  Resource_data const *res_data,
850  void const *exception_state,
851  char const *arg_block_data);
852 
853 
863 typedef void (Bsdf_pdf_function)(
864  Bsdf_pdf_data *data,
865  Shading_state_material const *state,
866  Resource_data const *res_data,
867  void const *exception_state,
868  char const *arg_block_data);
869 
870 
881  Bsdf_pdf_data *data,
883  Resource_data const *res_data,
884  void const *exception_state,
885  char const *arg_block_data);
886 
896 typedef void (Bsdf_auxiliary_function)(
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 
916  Resource_data const *res_data,
917  void const *exception_state,
918  char const *arg_block_data);
919 
922 {
923  EDF_EVENT_NONE = 0,
924  EDF_EVENT_EMISSION = 1,
925 
926  EDF_EVENT_FORCE_32_BIT = 0xffffffffU
927 };
928 
929 
932 {
939 };
940 
943 
944 template<Df_handle_slot_mode N>
945 struct Edf_evaluate_data : public Edf_evaluate_data_base
946 {
947  tct_float3 k1;
948  tct_int handle_offset;
949  tct_float cos;
951  tct_float3 edf[static_cast<size_t>(N)];
952  tct_float pdf;
953 };
954 
955 template<>
956 struct Edf_evaluate_data<DF_HSM_POINTER> : public Edf_evaluate_data_base
957 {
958  tct_float3 k1;
959  tct_int handle_offset;
960  tct_int handle_count;
962  tct_float cos;
963  tct_float3* edf;
964  tct_float pdf;
965 };
966 
967 template<>
968 struct Edf_evaluate_data<DF_HSM_NONE> : public Edf_evaluate_data_base
969 {
970  tct_float3 k1;
971  tct_float cos;
972  tct_float3 edf;
973  tct_float pdf;
974 };
975 
978 {
981 };
982 
985 
986 template<Df_handle_slot_mode N>
987 struct Edf_auxiliary_data : public Edf_auxiliary_data_base
988 {
989  tct_float3 k1;
990  tct_int handle_offset;
991  // reserved for future use
993 };
994 
995 template<>
996 struct Edf_auxiliary_data<DF_HSM_POINTER> : public Edf_auxiliary_data_base
997 {
998  tct_float3 k1;
999  tct_int handle_offset;
1000  tct_int handle_count;
1002 
1003  // reserved for future use
1004 };
1005 
1006 template<>
1007 struct Edf_auxiliary_data<DF_HSM_NONE> : public Edf_auxiliary_data_base
1008 {
1009  tct_float3 k1;
1010 
1011  // reserved for future use
1012 };
1013 
1026 typedef void (Edf_init_function)(
1027  Shading_state_material *state,
1028  Resource_data const *res_data,
1029  void const *exception_state,
1030  char const *arg_block_data);
1031 
1032 
1047  Resource_data const *res_data,
1048  void const *exception_state,
1049  char const *arg_block_data);
1050 
1051 
1061 typedef void (Edf_sample_function)(
1062  Edf_sample_data *data,
1063  Shading_state_material const *state,
1064  Resource_data const *res_data,
1065  void const *exception_state,
1066  char const *arg_block_data);
1067 
1068 
1079  Edf_sample_data *data,
1081  Resource_data const *res_data,
1082  void const *exception_state,
1083  char const *arg_block_data);
1084 
1085 
1095 typedef void (Edf_evaluate_function)(
1096  Edf_evaluate_data_base *data,
1097  Shading_state_material const *state,
1098  Resource_data const *res_data,
1099  void const *exception_state,
1100  char const *arg_block_data);
1101 
1102 
1113  Edf_evaluate_data_base *data,
1115  Resource_data const *res_data,
1116  void const *exception_state,
1117  char const *arg_block_data);
1118 
1119 
1129 typedef void (Edf_pdf_function)(
1130  Edf_pdf_data *data,
1131  Shading_state_material const *state,
1132  Resource_data const *res_data,
1133  void const *exception_state,
1134  char const *arg_block_data);
1135 
1136 
1147  Edf_pdf_data *data,
1149  Resource_data const *res_data,
1150  void const *exception_state,
1151  char const *arg_block_data);
1152 
1162 typedef void (Edf_auxiliary_function)(
1164  Shading_state_material const *state,
1165  Resource_data const *res_data,
1166  void const *exception_state,
1167  char const *arg_block_data);
1168 
1169 
1182  Resource_data const *res_data,
1183  void const *exception_state,
1184  char const *arg_block_data);
1185  // end group mi_neuray_mdl_compiler
1187 
1188 } // namespace neuraylib
1189 
1190 } // namespace mi
1191 
1192 #endif // MI_NEURAYLIB_TARGET_CODE_TYPES_H