Material Definition Language API nvidia_logo_transpbg.gif Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
imdl_compiler.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright 2020 NVIDIA Corporation. All rights reserved.
3  **************************************************************************************************/
6 
7 #ifndef MI_NEURAYLIB_IMDL_COMPILER_H
8 #define MI_NEURAYLIB_IMDL_COMPILER_H
9 
12 #include <mi/neuraylib/typedefs.h>
13 #include <mi/neuraylib/ivalue.h>
15 #include <mi/neuraylib/version.h>
16 
17 namespace mi {
18 
19 namespace base { class ILogger; }
20 
21 class IMap;
22 class IString;
23 
24 namespace mdl { class IEntity_resolver; }
25 
26 namespace neuraylib {
27 
28 class IBsdf_isotropic_data;
29 class ICanvas;
30 class ICompiled_material;
31 class ILightprofile;
32 class IFunction_call;
33 class ILink_unit;
34 class IMdl_backend;
35 class IMdl_execution_context;
36 class IMdl_entity_resolver;
37 class ITarget_code;
38 class ITarget_argument_block;
39 class ITransaction;
40 
41 struct Target_function_description;
42 
43 
46  DFK_NONE,
47  DFK_INVALID,
48  DFK_SIMPLE_GLOSSY_MULTISCATTER,
49  DFK_BACKSCATTERING_GLOSSY_MULTISCATTER,
50  DFK_BECKMANN_SMITH_MULTISCATTER,
51  DFK_BECKMANN_VC_MULTISCATTER,
52  DFK_GGX_SMITH_MULTISCATTER,
53  DFK_GGX_VC_MULTISCATTER,
54  DFK_WARD_GEISLER_MORODER_MULTISCATTER,
55  DFK_SHEEN_MULTISCATTER,
56  DFK_FORCE_32_BIT = 0xffffffffU
57 };
58 
59 mi_static_assert(sizeof(Df_data_kind) == sizeof(Uint32));
60 
81 class IMdl_compiler : public
87  mi::base::Interface_declare<0x8fff0a2d,0x7df7,0x4552,0x92,0xf7,0x36,0x1d,0x31,0xc6,0x30,0x08>
88 {
89 public:
91 
92 
101  virtual void set_logger( base::ILogger* logger) = 0;
102 
107  virtual base::ILogger* get_logger() = 0;
108 
110 
112 
123  virtual Sint32 add_module_path( const char* path) = 0;
124 
135  virtual Sint32 remove_module_path( const char* path) = 0;
136 
141  virtual void clear_module_paths() = 0;
142 
149  virtual Size get_module_paths_length() const = 0;
150 
157  virtual const IString* get_module_path( Size index) const = 0;
158 
160 
162 
175  virtual Sint32 add_resource_path( const char* path) = 0;
176 
189  virtual Sint32 remove_resource_path( const char* path) = 0;
190 
197  virtual void clear_resource_paths() = 0;
198 
207  virtual Size get_resource_paths_length() const = 0;
208 
217  virtual const IString* get_resource_path( Size index) const = 0;
218 
220 
222 
232  virtual Sint32 load_plugin_library( const char* path) = 0;
233 
235 
237 
269  virtual Sint32 load_module(
270  ITransaction* transaction, const char* module_name, IMdl_execution_context* context = 0) = 0;
271 
295  virtual const char* get_module_db_name(
296  ITransaction* transaction, const char* module_name, IMdl_execution_context* context = 0) = 0;
297 
328  ITransaction* transaction,
329  const char* module_name,
330  const char* module_source,
331  IMdl_execution_context* context = 0) = 0;
332 
349  virtual Sint32 add_builtin_module( const char* module_name, const char* module_source) = 0;
350 
379  virtual Sint32 export_module(
380  ITransaction* transaction,
381  const char* module_name,
382  const char* filename,
383  IMdl_execution_context* context = 0) = 0;
384 
414  ITransaction* transaction,
415  const char* module_name,
416  IString* exported_module,
417  IMdl_execution_context* context = 0) = 0;
418 
450  virtual Sint32 export_canvas(
451  const char* filename, const ICanvas* canvas, Uint32 quality = 100) const = 0;
452 
462  virtual Sint32 export_lightprofile(
463  const char* filename, const ILightprofile* lightprofile) const = 0;
464 
474  virtual Sint32 export_bsdf_data(
475  const char* filename,
476  const IBsdf_isotropic_data* reflection,
477  const IBsdf_isotropic_data* transmission) const = 0;
478 
480 
482 
490  virtual const IString* uvtile_marker_to_string(
491  const char* marker,
492  Sint32 u,
493  Sint32 v) const = 0;
494 
501  virtual const IString* uvtile_string_to_marker(
502  const char* str, const char* marker) const = 0;
503 
505 
507 
515  MB_FORCE_32_BIT = 0xffffffffU // Undocumented, for alignment only
516  };
517 
523  virtual IMdl_backend* get_backend( Mdl_backend_kind kind) = 0;
524 
526 
527  virtual IMdl_entity_resolver* get_entity_resolver() const = 0;
528 
529  virtual void set_external_resolver(mdl::IEntity_resolver *resolver) const = 0;
530 
539  virtual const Float32* get_df_data_texture(
540  Df_data_kind kind,
541  Size &rx,
542  Size &ry,
543  Size &rz) const = 0;
544 };
545 
547 
549 class IMdl_backend : public
550  mi::base::Interface_declare<0x9ecdd747,0x20b8,0x4a8a,0xb1,0xe2,0x62,0xb2,0x62,0x30,0xd3,0x67>
551 {
552 public:
585 #if !defined(MDL_SOURCE_RELEASE) && defined(MDL_ENABLE_INTERPRETER)
586 #endif
592 #ifndef MDL_SOURCE_RELEASE
650 #endif // MDL_SOURCE_RELEASE
790  virtual Sint32 set_option( const char* name, const char* value) = 0;
798 
813  virtual Sint32 set_option_binary(
814  const char* name,
815  const char* data,
816  Size size) = 0;
817 
822  virtual const Uint8* get_device_library( Size &size) const = 0;
823 
863  virtual const ITarget_code* translate_environment(
864  ITransaction* transaction,
865  const IFunction_call* call,
866  const char* fname,
867  IMdl_execution_context* context) = 0;
868 
908  ITransaction* transaction,
909  const ICompiled_material* material,
910  const char* path,
911  const char* fname,
912  IMdl_execution_context* context) = 0;
913 
949  virtual const ITarget_code* translate_material_df(
950  ITransaction* transaction,
951  const ICompiled_material* material,
952  const char* path,
953  const char* base_fname,
954  IMdl_execution_context* context) = 0;
955 
982  virtual const ITarget_code* translate_material(
983  ITransaction* transaction,
984  const ICompiled_material* material,
985  Target_function_description* function_descriptions,
986  Size description_count,
987  IMdl_execution_context* context) = 0;
988 
1003  virtual ILink_unit* create_link_unit(
1004  ITransaction* transaction,
1005  IMdl_execution_context* context) = 0;
1006 
1022  virtual const ITarget_code* translate_link_unit(
1023  const ILink_unit* lu, IMdl_execution_context* context) = 0;
1024 
1025 };
1026 
1031  mi::base::Interface_declare<0xe7559a88,0x9a9a,0x41d8,0xa1,0x9c,0x4a,0x52,0x4e,0x4b,0x7b,0x66>
1032 {
1033 public:
1050 #ifndef MDL_SOURCE_RELEASE
1051 #endif // MDL_SOURCE_RELEASE
1054  virtual Uint32 get_resource_index(IValue_resource const *resource) = 0;
1059 
1065  virtual Uint32 get_string_index(IValue_string const *s) = 0;
1066 };
1067 
1075  mi::base::Interface_declare<0xf2a5db20,0x85ab,0x4c41,0x8c,0x5f,0x49,0xc8,0x29,0x4a,0x73,0x65>
1076 {
1077 public:
1079  virtual const char* get_data() const = 0;
1080 
1082  virtual char* get_data() = 0;
1083 
1085  virtual Size get_size() const = 0;
1086 
1088  virtual ITarget_argument_block *clone() const = 0;
1089 };
1090 
1093  Target_value_layout_state(mi::Uint32 state_offs = 0, mi::Uint32 data_offs = 0)
1094  : m_state_offs(state_offs)
1095  , m_data_offs(data_offs)
1096  {}
1097 
1100 
1103 };
1104 
1114 class ITarget_value_layout : public
1115  mi::base::Interface_declare<0x1003351f,0x0c31,0x4a9d,0xb9,0x99,0x90,0xb5,0xe4,0xb4,0x71,0xe3>
1116 {
1117 public:
1119  virtual Size get_size() const = 0;
1120 
1125  virtual Size get_num_elements(
1127 
1138  virtual Size get_layout(
1139  IValue::Kind &kind,
1140  Size &arg_size,
1142 
1153  Size i,
1155 
1172  virtual Sint32 set_value(
1173  char *block,
1174  IValue const *value,
1175  ITarget_resource_callback *resource_callback,
1177 };
1178 
1180 class ITarget_code : public
1181  mi::base::Interface_declare<0xefca46ae,0xd530,0x4b97,0x9d,0xab,0x3a,0xdb,0x0c,0x58,0xc3,0xac>
1182 {
1183 public:
1186  SU_POSITION = 0x0001u,
1187  SU_NORMAL = 0x0002u,
1189  SU_MOTION = 0x0008u,
1192  SU_TANGENT_SPACE = 0x0040u,
1194  SU_DIRECTION = 0x0100u,
1195  SU_ANIMATION_TIME = 0x0200u,
1197 
1199 
1200  SU_TRANSFORMS = 0x0800u,
1201  SU_OBJECT_ID = 0x1000u,
1202 
1204 
1205  SU_FORCE_32_BIT = 0xFFFFFFFFu // Undocumented, for alignment only
1206  }; // can be or'ed
1207 
1215  Texture_shape_FORCE_32_BIT = 0xFFFFFFFFu // Undocumented, for alignment only
1217  };
1218 
1221  SL_CUDA,
1222  SL_PTX,
1223  SL_HLSL,
1224  SL_GLSL, // \if MDL_SOURCE_RELEASE Reserved\else GLSL\endif.
1225  SL_NUM_LANGUAGES
1226  };
1227 
1230  {
1231  DK_NONE,
1232  DK_BSDF,
1233  DK_HAIR_BSDF,
1234  DK_EDF,
1235  DK_INVALID
1236  };
1237 
1240  FK_INVALID,
1241  FK_LAMBDA,
1242  FK_SWITCH_LAMBDA,
1243  FK_ENVIRONMENT,
1244  FK_CONST,
1245  FK_DF_INIT,
1246  FK_DF_SAMPLE,
1247  FK_DF_EVALUATE,
1248  FK_DF_PDF,
1249  FK_DF_AUXILIARY
1250  };
1251 
1253  enum Gamma_mode {
1254  GM_GAMMA_DEFAULT,
1255  GM_GAMMA_LINEAR,
1256  GM_GAMMA_SRGB,
1257  GM_GAMMA_UNKNOWN
1258  };
1259 
1260  typedef Uint32 State_usage;
1261 
1263  virtual const char* get_code() const = 0;
1264 
1266  virtual Size get_code_size() const = 0;
1267 
1269  virtual Size get_callable_function_count() const = 0;
1270 
1280  virtual const char* get_callable_function( Size index) const = 0;
1281 
1283  virtual Size get_texture_count() const = 0;
1284 
1291  virtual const char* get_texture( Size index) const = 0;
1292 
1298  virtual const char* get_texture_url(Size index) const = 0;
1299 
1306  virtual const char* get_texture_owner_module(Size index) const = 0;
1307 
1313  virtual Gamma_mode get_texture_gamma(Size index) const = 0;
1314 
1320  virtual Texture_shape get_texture_shape( Size index) const = 0;
1321 
1333  virtual const Float32* get_texture_df_data(
1334  Size index,
1335  Size &rx,
1336  Size &ry,
1337  Size &rz) const = 0;
1338 
1340  virtual Size get_ro_data_segment_count() const = 0;
1341 
1347  virtual const char* get_ro_data_segment_name( Size index) const = 0;
1348 
1353  virtual Size get_ro_data_segment_size( Size index) const = 0;
1354 
1360  virtual const char* get_ro_data_segment_data( Size index) const = 0;
1361 
1363  virtual Size get_code_segment_count() const = 0;
1364 
1369  virtual const char* get_code_segment( Size index) const = 0;
1370 
1375  virtual Size get_code_segment_size( Size index) const = 0;
1376 
1381  virtual const char* get_code_segment_description( Size index) const = 0;
1382 
1387  virtual State_usage get_render_state_usage() const = 0;
1388 
1390  virtual Size get_argument_block_count() const = 0;
1391 
1398  virtual const ITarget_argument_block *get_argument_block(Size index) const = 0;
1399 
1411  Size index,
1412  const ICompiled_material *material,
1413  ITarget_resource_callback *resource_callback) const = 0;
1414 
1420  virtual const ITarget_value_layout *get_argument_block_layout(Size index) const = 0;
1421 
1423  virtual Size get_light_profile_count() const = 0;
1424 
1430  virtual const char* get_light_profile(Size index) const = 0;
1431 
1433  virtual Size get_bsdf_measurement_count() const = 0;
1434 
1440  virtual const char* get_bsdf_measurement(Size index) const = 0;
1441 
1443  virtual Size get_string_constant_count() const = 0;
1444 
1450  virtual const char* get_string_constant(Size index) const = 0;
1451 
1458  ITransaction* transaction,
1459  IValue_resource const *resource) const = 0;
1460 
1468  virtual const char* get_callable_function_prototype( Size index, Prototype_language lang)
1469  const = 0;
1470 
1478 
1484  virtual Function_kind get_callable_function_kind( Size index) const = 0;
1485 
1492  virtual Size get_callable_function_argument_block_index( Size index) const = 0;
1493 
1510  virtual Sint32 execute_environment(
1511  Size index,
1512  const Shading_state_environment& state,
1513  Texture_handler_base* tex_handler,
1514  Spectrum_struct* result) const = 0;
1515 
1536  virtual Sint32 execute(
1537  Size index,
1538  const Shading_state_material& state,
1539  Texture_handler_base* tex_handler,
1540  const ITarget_argument_block *cap_args,
1541  void* result) const = 0;
1542 
1563  virtual Sint32 execute_bsdf_init(
1564  Size index,
1565  Shading_state_material& state,
1566  Texture_handler_base* tex_handler,
1567  const ITarget_argument_block *cap_args) const = 0;
1568 
1586  virtual Sint32 execute_bsdf_sample(
1587  Size index,
1588  Bsdf_sample_data *data,
1589  const Shading_state_material& state,
1590  Texture_handler_base* tex_handler,
1591  const ITarget_argument_block *cap_args) const = 0;
1592 
1611  virtual Sint32 execute_bsdf_evaluate(
1612  Size index,
1614  const Shading_state_material& state,
1615  Texture_handler_base* tex_handler,
1616  const ITarget_argument_block *cap_args) const = 0;
1617 
1636  virtual Sint32 execute_bsdf_pdf(
1637  Size index,
1638  Bsdf_pdf_data *data,
1639  const Shading_state_material& state,
1640  Texture_handler_base* tex_handler,
1641  const ITarget_argument_block *cap_args) const = 0;
1642 
1643 
1663  Size index,
1665  const Shading_state_material& state,
1666  Texture_handler_base* tex_handler,
1667  const ITarget_argument_block *cap_args) const = 0;
1668 
1669 
1690  virtual Sint32 execute_edf_init(
1691  Size index,
1692  Shading_state_material& state,
1693  Texture_handler_base* tex_handler,
1694  const ITarget_argument_block *cap_args) const = 0;
1695 
1713  virtual Sint32 execute_edf_sample(
1714  Size index,
1715  Edf_sample_data *data,
1716  const Shading_state_material& state,
1717  Texture_handler_base* tex_handler,
1718  const ITarget_argument_block *cap_args) const = 0;
1719 
1738  virtual Sint32 execute_edf_evaluate(
1739  Size index,
1740  Edf_evaluate_data_base *data,
1741  const Shading_state_material& state,
1742  Texture_handler_base* tex_handler,
1743  const ITarget_argument_block *cap_args) const = 0;
1744 
1763  virtual Sint32 execute_edf_pdf(
1764  Size index,
1765  Edf_pdf_data *data,
1766  const Shading_state_material& state,
1767  Texture_handler_base* tex_handler,
1768  const ITarget_argument_block *cap_args) const = 0;
1769 
1770 
1789  virtual Sint32 execute_edf_auxiliary(
1790  Size index,
1792  const Shading_state_material& state,
1793  Texture_handler_base* tex_handler,
1794  const ITarget_argument_block *cap_args) const = 0;
1795 
1802  virtual Size get_callable_function_df_handle_count( Size func_index) const = 0;
1803 
1811  virtual const char* get_callable_function_df_handle( Size func_index, Size handle_index)
1812  const = 0;
1813 
1820  virtual Df_data_kind get_texture_df_data_kind(Size index) const = 0;
1821 
1828  virtual Size get_body_texture_count() const = 0;
1829 
1836  virtual Size get_body_light_profile_count() const = 0;
1837 
1844  virtual Size get_body_bsdf_measurement_count() const = 0;
1845 };
1846 
1848 class ILink_unit : public
1849  mi::base::Interface_declare<0x1df9bbb0,0x5d96,0x475f,0x9a,0xf4,0x07,0xed,0x8c,0x2d,0xfd,0xdb>
1850 {
1851 public:
1880  virtual Sint32 add_environment(
1881  const IFunction_call *call,
1882  const char *fname,
1883  IMdl_execution_context *context = 0) = 0;
1884 
1913  const ICompiled_material* inst,
1914  const char* path,
1915  const char* fname,
1916  IMdl_execution_context* context) = 0;
1917 
1955  virtual Sint32 add_material_df(
1956  const ICompiled_material* material,
1957  const char* path,
1958  const char* base_fname,
1959  IMdl_execution_context* context) = 0;
1960 
1989  virtual Sint32 add_material(
1990  const ICompiled_material* material,
1991  Target_function_description* function_descriptions,
1992  Size description_count,
1993  IMdl_execution_context* context) = 0;
1994 };
1995 
1996 struct Target_function_description
1997 {
1998  Target_function_description(
1999  const char* expression_path = NULL,
2000  const char* base_function_name = NULL)
2001  : path(expression_path)
2002  , base_fname(base_function_name)
2003  , argument_block_index(Size(~0))
2004  , function_index(Size(~0))
2005  , distribution_kind(ITarget_code::DK_INVALID)
2006  , return_code(Sint32(~0)) // not processed
2007  {
2008  }
2009 
2012  const char* path;
2013 
2018  const char* base_fname;
2019 
2024  Size argument_block_index;
2025 
2034  Size function_index;
2035 
2038  ITarget_code::Distribution_kind distribution_kind;
2039 
2068  Sint32 return_code;
2069 };
2070 
2071 
2073  // end group mi_neuray_mdl_compiler
2075 
2076 } // namespace neuraylib
2077 
2078 } // namespace mi
2079 
2080 #endif // MI_NEURAYLIB_IMDL_COMPILER_H