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 2019 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 
81 
83 template<typename T>
84 struct tct_deriv
85 {
86  T val, dx, dy;
87 };
88 
90 template<bool with_derivatives>
91 struct tct_traits;
92 
93 template<>
94 struct tct_traits<false>
95 {
96  typedef tct_float tct_derivable_float;
97  typedef tct_float2 tct_derivable_float2;
98  typedef tct_float3 tct_derivable_float3;
99  typedef tct_float4 tct_derivable_float4;
100  typedef tct_float const tct_coord2_type[2];
101 };
102 
103 template<>
104 struct tct_traits<true>
105 {
106  typedef tct_deriv<tct_float> tct_derivable_float;
107  typedef tct_deriv<tct_float2> tct_derivable_float2;
108  typedef tct_deriv<tct_float3> tct_derivable_float3;
109  typedef tct_deriv<tct_float4> tct_derivable_float4;
110  typedef tct_derivable_float2 const * tct_coord2_type;
111 };
112 
115 
118 
121 
124 
125 
143 };
144 
145 
173 template<bool with_derivatives = false>
176 
182 
186 
190 
194 
198  typename traits::tct_derivable_float3 const *text_coords;
199 
206 
213 
221 
235  char const *ro_data_segment;
236 
243 
250 
256 };
257 
260 
263 
264 
271 
275 
279 
283 };
284 
287 {
290 
293 };
294 
295 
296 // Forward declaration of texture handler structure.
297 struct Texture_handler_base;
298 
299 
302 template<bool with_derivatives = false>
305 
307  void (*m_tex_lookup_float4_2d)(
308  tct_float result[4],
309  Texture_handler_base const *self,
310  tct_uint texture_idx,
311  typename traits::tct_coord2_type coord,
312  Tex_wrap_mode wrap_u,
313  Tex_wrap_mode wrap_v,
314  tct_float const crop_u[2],
315  tct_float const crop_v[2]);
316 
318  void (*m_tex_lookup_float3_2d)(
319  tct_float result[3],
320  Texture_handler_base const *self,
321  tct_uint texture_idx,
322  typename traits::tct_coord2_type coord,
323  Tex_wrap_mode wrap_u,
324  Tex_wrap_mode wrap_v,
325  tct_float const crop_u[2],
326  tct_float const crop_v[2]);
327 
329  void (*m_tex_texel_float4_2d)(
330  tct_float result[4],
331  Texture_handler_base const *self,
332  tct_uint texture_idx,
333  tct_int const coord[2],
334  tct_int const uv_tile[2]);
335 
337  void (*m_tex_lookup_float4_3d)(
338  tct_float result[4],
339  Texture_handler_base const *self,
340  tct_uint texture_idx,
341  tct_float const coord[3],
342  Tex_wrap_mode wrap_u,
343  Tex_wrap_mode wrap_v,
344  Tex_wrap_mode wrap_w,
345  tct_float const crop_u[2],
346  tct_float const crop_v[2],
347  tct_float const crop_w[2]);
348 
350  void (*m_tex_lookup_float3_3d)(
351  tct_float result[3],
352  Texture_handler_base const *self,
353  tct_uint texture_idx,
354  tct_float const coord[3],
355  Tex_wrap_mode wrap_u,
356  Tex_wrap_mode wrap_v,
357  Tex_wrap_mode wrap_w,
358  tct_float const crop_u[2],
359  tct_float const crop_v[2],
360  tct_float const crop_w[2]);
361 
363  void (*m_tex_texel_float4_3d)(
364  tct_float result[4],
365  Texture_handler_base const *self,
366  tct_uint texture_idx,
367  tct_int const coord[3]);
368 
370  void (*m_tex_lookup_float4_cube)(
371  tct_float result[4],
372  Texture_handler_base const *self,
373  tct_uint texture_idx,
374  tct_float const coord[3]);
375 
377  void (*m_tex_lookup_float3_cube)(
378  tct_float result[3],
379  Texture_handler_base const *self,
380  tct_uint texture_idx,
381  tct_float const coord[3]);
382 
385  void (*m_tex_resolution_2d)(
386  tct_int result[2],
387  Texture_handler_base const *self,
388  tct_uint texture_idx,
389  tct_int const uv_tile[2]);
390 
392  tct_float (*m_df_light_profile_evaluate)(
393  Texture_handler_base const *self,
394  tct_uint resource_idx,
395  tct_float const theta_phi[2]);
396 
398  void (*m_df_light_profile_sample)(
399  tct_float result[3],
401  Texture_handler_base const *self,
402  tct_uint resource_idx,
403  tct_float const xi[3]);
404 
406  tct_float (*m_df_light_profile_pdf)(
407  Texture_handler_base const *self,
408  tct_uint resource_idx,
409  tct_float const theta_phi[2]);
410 
415  void (*m_df_bsdf_measurement_resolution)(
416  tct_uint result[3],
417  Texture_handler_base const *self,
418  tct_uint resource_idx,
419  Mbsdf_part part);
420 
422  void (*m_df_bsdf_measurement_evaluate)(
423  tct_float result[3],
424  Texture_handler_base const *self,
425  tct_uint resource_idx,
426  tct_float const theta_phi_in[2],
427  tct_float const theta_phi_out[2],
428  Mbsdf_part part);
429 
431  void (*m_df_bsdf_measurement_sample)(
432  tct_float result[3],
434  Texture_handler_base const *self,
435  tct_uint resource_idx,
436  tct_float const theta_phi_out[2],
437  tct_float const xi[3],
438  Mbsdf_part part);
439 
441  tct_float (*m_df_bsdf_measurement_pdf)(
442  Texture_handler_base const *self,
443  tct_uint resource_idx,
444  tct_float const theta_phi_in[2],
445  tct_float const theta_phi_out[2],
446  Mbsdf_part part);
447 
449  void (*m_df_bsdf_measurement_albedos)(
450  tct_float result[4],
456  Texture_handler_base const *self,
457  tct_uint resource_idx,
458  tct_float const theta_phi[2]);
459 };
460 
463 
466 
474 };
475 
483 };
484 
485 
488  void const *shared_data;
490 };
492 
495  BSDF_EVENT_ABSORB = 0,
496 
497  BSDF_EVENT_DIFFUSE = 1,
498  BSDF_EVENT_GLOSSY = 1 << 1,
499  BSDF_EVENT_SPECULAR = 1 << 2,
500  BSDF_EVENT_REFLECTION = 1 << 3,
501  BSDF_EVENT_TRANSMISSION = 1 << 4,
502 
503  BSDF_EVENT_DIFFUSE_REFLECTION = BSDF_EVENT_DIFFUSE | BSDF_EVENT_REFLECTION,
504  BSDF_EVENT_DIFFUSE_TRANSMISSION = BSDF_EVENT_DIFFUSE | BSDF_EVENT_TRANSMISSION,
505  BSDF_EVENT_GLOSSY_REFLECTION = BSDF_EVENT_GLOSSY | BSDF_EVENT_REFLECTION,
506  BSDF_EVENT_GLOSSY_TRANSMISSION = BSDF_EVENT_GLOSSY | BSDF_EVENT_TRANSMISSION,
507  BSDF_EVENT_SPECULAR_REFLECTION = BSDF_EVENT_SPECULAR | BSDF_EVENT_REFLECTION,
508  BSDF_EVENT_SPECULAR_TRANSMISSION = BSDF_EVENT_SPECULAR | BSDF_EVENT_TRANSMISSION,
509 
510  BSDF_EVENT_FORCE_32_BIT = 0xffffffffU
511 };
512 
516 #define MI_NEURAYLIB_BSDF_USE_MATERIAL_IOR (-1.0f)
517 
520  // Input fields
525 
526  // Output fields
531 };
532 
535  // Input fields
540 
541  // Output fields
544 };
545 
548  // Input fields
553 
554  // Output fields
556 };
557 
558 
559 // Signatures for generated target code functions.
560 
570 typedef void (Environment_function)(
571  void *result,
572  Shading_state_environment const *state,
573  Resource_data const *res_data,
574  void const *exception_state,
575  char const *arg_block_data);
576 
577 
587 typedef void (Material_expr_function)(
588  void *result,
589  Shading_state_material const *state,
590  Resource_data const *res_data,
591  void const *exception_state,
592  char const *arg_block_data);
593 
594 
605  void *result,
607  Resource_data const *res_data,
608  void const *exception_state,
609  char const *arg_block_data);
610 
611 
624 typedef void (Bsdf_init_function)(
625  Shading_state_material *state,
626  Resource_data const *res_data,
627  void const *exception_state,
628  char const *arg_block_data);
629 
630 
645  Resource_data const *res_data,
646  void const *exception_state,
647  char const *arg_block_data);
648 
649 
659 typedef void (Bsdf_sample_function)(
660  Bsdf_sample_data *data,
661  Shading_state_material const *state,
662  Resource_data const *res_data,
663  void const *exception_state,
664  char const *arg_block_data);
665 
666 
677  Bsdf_sample_data *data,
679  Resource_data const *res_data,
680  void const *exception_state,
681  char const *arg_block_data);
682 
683 
693 typedef void (Bsdf_evaluate_function)(
694  Bsdf_evaluate_data *data,
695  Shading_state_material const *state,
696  Resource_data const *res_data,
697  void const *exception_state,
698  char const *arg_block_data);
699 
700 
711  Bsdf_evaluate_data *data,
713  Resource_data const *res_data,
714  void const *exception_state,
715  char const *arg_block_data);
716 
717 
727 typedef void (Bsdf_pdf_function)(
728  Bsdf_pdf_data *data,
729  Shading_state_material const *state,
730  Resource_data const *res_data,
731  void const *exception_state,
732  char const *arg_block_data);
733 
734 
745  Bsdf_pdf_data *data,
747  Resource_data const *res_data,
748  void const *exception_state,
749  char const *arg_block_data);
750 
751 
752 
755 {
756  EDF_EVENT_NONE = 0,
757  EDF_EVENT_EMISSION = 1,
758 
759  EDF_EVENT_FORCE_32_BIT = 0xffffffffU
760 };
761 
762 
765 {
766  // Input fields
768 
769  // Output fields
774 };
775 
778 {
779  // Input fields
781 
782  // Output fields
786 };
787 
790 {
791  // Input fields
793 
794  // Output fields
796 };
797 
798 
811 typedef void (Edf_init_function)(
812  Shading_state_material *state,
813  Resource_data const *res_data,
814  void const *exception_state,
815  char const *arg_block_data);
816 
817 
832  Resource_data const *res_data,
833  void const *exception_state,
834  char const *arg_block_data);
835 
836 
846 typedef void (Edf_sample_function)(
847  Edf_sample_data *data,
848  Shading_state_material const *state,
849  Resource_data const *res_data,
850  void const *exception_state,
851  char const *arg_block_data);
852 
853 
864  Edf_sample_data *data,
866  Resource_data const *res_data,
867  void const *exception_state,
868  char const *arg_block_data);
869 
870 
880 typedef void (Edf_evaluate_function)(
881  Edf_evaluate_data *data,
882  Shading_state_material const *state,
883  Resource_data const *res_data,
884  void const *exception_state,
885  char const *arg_block_data);
886 
887 
898  Edf_evaluate_data *data,
900  Resource_data const *res_data,
901  void const *exception_state,
902  char const *arg_block_data);
903 
904 
914 typedef void (Edf_pdf_function)(
915  Edf_pdf_data *data,
916  Shading_state_material const *state,
917  Resource_data const *res_data,
918  void const *exception_state,
919  char const *arg_block_data);
920 
921 
932  Edf_pdf_data *data,
934  Resource_data const *res_data,
935  void const *exception_state,
936  char const *arg_block_data);
937  // end group mi_neuray_mdl_compiler
939 
940 } // namespace neuraylib
941 
942 } // namespace mi
943 
944 #endif // MI_NEURAYLIB_TARGET_CODE_TYPES_H