Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple GLSL and MSL "libraries" location. #1980

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 123 additions & 22 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,129 @@
if (MATERIALX_OSL_LEGACY_CLOSURES)
set(PBRLIB_SUFFIX "legacy")
else()
set(PBRLIB_SUFFIX "mtlx")
endif()

function(mx_copy_files FILE_LIST DESTINATION_DIR)
set(options "")
set(oneValueArgs
INSTALLED_FILES_LIST)
set(multiValueArgs
SRC_DEST_REPLACE_RULE)
cmake_parse_arguments(args
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN})

string(COMPARE NOTEQUAL "${args_SRC_DEST_REPLACE_RULE}" "" HAS_REPLACE_RULE)
string(COMPARE NOTEQUAL "${args_INSTALLED_FILES_LIST}" "" HAS_INSTALLED_FILES_LIST)

foreach (F ${${FILE_LIST}})
set(SOURCE_FILE ${F})
set(DESTINATION_FILE ${F})
if (HAS_REPLACE_RULE)
list(GET args_SRC_DEST_REPLACE_RULE 0 SRC_RULE)
list(GET args_SRC_DEST_REPLACE_RULE 1 DST_RULE)
string(REPLACE ${SRC_RULE} ${DST_RULE} DESTINATION_FILE ${DESTINATION_FILE})
endif ()

get_filename_component(BUILD_DIR ${DESTINATION_DIR}/${DESTINATION_FILE} DIRECTORY)

add_custom_command(OUTPUT ${DESTINATION_DIR}/${DESTINATION_FILE}
COMMAND ${CMAKE_COMMAND} -E make_directory ${BUILD_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE} ${DESTINATION_DIR}/${DESTINATION_FILE}
DEPENDS ${SOURCE_FILE}
)

if (HAS_INSTALLED_FILES_LIST)
list(APPEND ${args_INSTALLED_FILES_LIST} ${DESTINATION_DIR}/${DESTINATION_FILE})
endif ()
endforeach ()
if (HAS_INSTALLED_FILES_LIST)
set(${args_INSTALLED_FILES_LIST} ${${args_INSTALLED_FILES_LIST}} PARENT_SCOPE)
endif ()
endfunction()


set(LIBRARIES_BUILD_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/build)

set(SKIP_FILES
"CMakeLists.txt"
"pbrlib/genosl/pbrlib_genosl_impl.mtlx"
"pbrlib/genosl/pbrlib_genosl_impl.legacy")

file(GLOB_RECURSE ALL_FILES CONFIGURE_DEPENDS *.*)
foreach (F ${ALL_FILES})
cmake_path(RELATIVE_PATH F OUTPUT_VARIABLE RELATIVE_FILE)

if (${RELATIVE_FILE} IN_LIST SKIP_FILES)
continue()
endif ()

# convert to a list of path parts.
string(REPLACE "/" ";" PATH_LIST ${RELATIVE_FILE})

if ("genosl" IN_LIST PATH_LIST)
list(APPEND GENOSL_FILES ${RELATIVE_FILE})
elseif ("genmdl" IN_LIST PATH_LIST)
list(APPEND GENMDL_FILES ${RELATIVE_FILE})
elseif ("genglsl" IN_LIST PATH_LIST)
list(APPEND GENGLSL_FILES ${RELATIVE_FILE})
elseif ("genmsl" IN_LIST PATH_LIST)
list(APPEND GENMSL_FILES ${RELATIVE_FILE})
elseif ("_hwCommon" IN_LIST PATH_LIST)
list(APPEND GENGLSL_FILES ${RELATIVE_FILE})
list(APPEND GENMSL_FILES ${RELATIVE_FILE})
else ()
list(APPEND COMMON_FILES ${RELATIVE_FILE})
endif ()
endforeach ()

# Stage each file set in to the build location
set(ALL_INSTALLED_LIBRARY_FILES "")

mx_copy_files(COMMON_FILES ${LIBRARIES_BUILD_FOLDER}
INSTALLED_FILES_LIST ALL_INSTALLED_LIBRARY_FILES)

if (MATERIALX_BUILD_GEN_OSL)
if (MATERIALX_OSL_LEGACY_CLOSURES)
list(APPEND GENOSL_FILES "pbrlib/genosl/pbrlib_genosl_impl.legacy")
else ()
list(APPEND GENOSL_FILES "pbrlib/genosl/pbrlib_genosl_impl.mtlx")
endif ()
mx_copy_files(GENOSL_FILES ${LIBRARIES_BUILD_FOLDER}
SRC_DEST_REPLACE_RULE ".legacy;.mtlx"
INSTALLED_FILES_LIST ALL_INSTALLED_LIBRARY_FILES)
endif ()

if (MATERIALX_BUILD_GEN_MDL)
mx_copy_files(GENMDL_FILES ${LIBRARIES_BUILD_FOLDER}
INSTALLED_FILES_LIST ALL_INSTALLED_LIBRARY_FILES)
endif ()

if (MATERIALX_BUILD_GEN_GLSL)
mx_copy_files(GENGLSL_FILES ${LIBRARIES_BUILD_FOLDER}
SRC_DEST_REPLACE_RULE "/_hwCommon/;/genglsl/"
INSTALLED_FILES_LIST ALL_INSTALLED_LIBRARY_FILES)
endif ()

if (MATERIALX_BUILD_GEN_MSL)
mx_copy_files(GENMSL_FILES ${LIBRARIES_BUILD_FOLDER}
SRC_DEST_REPLACE_RULE "/_hwCommon/;/genmsl/"
INSTALLED_FILES_LIST ALL_INSTALLED_LIBRARY_FILES)
endif ()

add_custom_target(MaterialX_Library_Files ALL
DEPENDS ${ALL_INSTALLED_LIBRARY_FILES})

## Finally install the staged files
if(NOT SKBUILD)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}"
PATTERN "CMakeLists.txt" EXCLUDE
PATTERN "pbrlib_genosl_impl.*" EXCLUDE)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pbrlib/genosl/pbrlib_genosl_impl.${PBRLIB_SUFFIX}"
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx)
install(DIRECTORY ${LIBRARIES_BUILD_FOLDER}/
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}")
endif()

set(MATERIALX_PYTHON_LIBRARIES_PATH "${MATERIALX_PYTHON_FOLDER_NAME}/${MATERIALX_INSTALL_STDLIB_PATH}")
if(SKBUILD)
set(MATERIALX_PYTHON_LIBRARIES_PATH "${SKBUILD_PLATLIB_DIR}/MaterialX/libraries")
endif()
if (MATERIALX_BUILD_PYTHON)
set(MATERIALX_PYTHON_LIBRARIES_PATH "${MATERIALX_PYTHON_FOLDER_NAME}/${MATERIALX_INSTALL_STDLIB_PATH}")
if (SKBUILD)
set(MATERIALX_PYTHON_LIBRARIES_PATH "${SKBUILD_PLATLIB_DIR}/MaterialX/libraries")
endif ()

if(MATERIALX_BUILD_PYTHON)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "${MATERIALX_PYTHON_LIBRARIES_PATH}"
PATTERN "CMakeLists.txt" EXCLUDE
PATTERN "pbrlib_genosl_impl.*" EXCLUDE)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pbrlib/genosl/pbrlib_genosl_impl.${PBRLIB_SUFFIX}"
DESTINATION "${MATERIALX_PYTHON_LIBRARIES_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx)
install(DIRECTORY ${LIBRARIES_BUILD_FOLDER}/
DESTINATION "${MATERIALX_PYTHON_LIBRARIES_PATH}")
endif()
52 changes: 36 additions & 16 deletions libraries/pbrlib/genmsl/pbrlib_genmsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,44 @@
<materialx version="1.39">

<!-- <oren_nayar_diffuse_bsdf> -->
<implementation name="IM_oren_nayar_diffuse_bsdf_genmsl" nodedef="ND_oren_nayar_diffuse_bsdf" file="../genglsl/mx_oren_nayar_diffuse_bsdf.glsl" function="mx_oren_nayar_diffuse_bsdf" target="genmsl" />
<implementation name="IM_oren_nayar_diffuse_bsdf_genmsl" nodedef="ND_oren_nayar_diffuse_bsdf"
file="mx_oren_nayar_diffuse_bsdf.glsl" function="mx_oren_nayar_diffuse_bsdf" target="genmsl"/>

<!-- <burley_diffuse_bsdf> -->
<implementation name="IM_burley_diffuse_bsdf_genmsl" nodedef="ND_burley_diffuse_bsdf" file="../genglsl/mx_burley_diffuse_bsdf.glsl" function="mx_burley_diffuse_bsdf" target="genmsl" />
<implementation name="IM_burley_diffuse_bsdf_genmsl" nodedef="ND_burley_diffuse_bsdf"
file="mx_burley_diffuse_bsdf.glsl" function="mx_burley_diffuse_bsdf" target="genmsl"/>

<!-- <translucent_bsdf> -->
<implementation name="IM_translucent_bsdf_genmsl" nodedef="ND_translucent_bsdf" file="../genglsl/mx_translucent_bsdf.glsl" function="mx_translucent_bsdf" target="genmsl" />
<implementation name="IM_translucent_bsdf_genmsl" nodedef="ND_translucent_bsdf" file="mx_translucent_bsdf.glsl"
function="mx_translucent_bsdf" target="genmsl"/>

<!-- <dielectric_bsdf> -->
<implementation name="IM_dielectric_bsdf_genmsl" nodedef="ND_dielectric_bsdf" file="../genglsl/mx_dielectric_bsdf.glsl" function="mx_dielectric_bsdf" target="genmsl" />
<implementation name="IM_dielectric_bsdf_genmsl" nodedef="ND_dielectric_bsdf" file="mx_dielectric_bsdf.glsl"
function="mx_dielectric_bsdf" target="genmsl"/>

<!-- <conductor_bsdf> -->
<implementation name="IM_conductor_bsdf_genmsl" nodedef="ND_conductor_bsdf" file="../genglsl/mx_conductor_bsdf.glsl" function="mx_conductor_bsdf" target="genmsl" />
<implementation name="IM_conductor_bsdf_genmsl" nodedef="ND_conductor_bsdf" file="mx_conductor_bsdf.glsl"
function="mx_conductor_bsdf" target="genmsl"/>

<!-- <generalized_schlick_bsdf> -->
<implementation name="IM_generalized_schlick_bsdf_genmsl" nodedef="ND_generalized_schlick_bsdf" file="../genglsl/mx_generalized_schlick_bsdf.glsl" function="mx_generalized_schlick_bsdf" target="genmsl" />
<implementation name="IM_generalized_schlick_bsdf_genmsl" nodedef="ND_generalized_schlick_bsdf"
file="mx_generalized_schlick_bsdf.glsl" function="mx_generalized_schlick_bsdf" target="genmsl"/>

<!-- <generalized_schlick_edf> -->
<implementation name="IM_generalized_schlick_edf_genmsl" nodedef="ND_generalized_schlick_edf"
file="mx_generalized_schlick_edf.glsl" function="mx_generalized_schlick_edf" target="genmsl"/>

<!-- <subsurface_bsdf> -->
<implementation name="IM_subsurface_bsdf_genmsl" nodedef="ND_subsurface_bsdf" file="../genglsl/mx_subsurface_bsdf.glsl" function="mx_subsurface_bsdf" target="genmsl" />
<implementation name="IM_subsurface_bsdf_genmsl" nodedef="ND_subsurface_bsdf" file="mx_subsurface_bsdf.glsl"
function="mx_subsurface_bsdf" target="genmsl"/>

<!-- <sheen_bsdf> -->
<implementation name="IM_sheen_bsdf_genmsl" nodedef="ND_sheen_bsdf" file="../genglsl/mx_sheen_bsdf.glsl" function="mx_sheen_bsdf" target="genmsl" />
<implementation name="IM_sheen_bsdf_genmsl" nodedef="ND_sheen_bsdf" file="mx_sheen_bsdf.glsl" function="mx_sheen_bsdf"
target="genmsl"/>

<!-- <anisotropic_vdf> -->
<implementation name="IM_anisotropic_vdf_genmsl" nodedef="ND_anisotropic_vdf" file="../genglsl/mx_anisotropic_vdf.glsl" function="mx_anisotropic_vdf" target="genmsl" />
<implementation name="IM_anisotropic_vdf_genmsl" nodedef="ND_anisotropic_vdf" file="mx_anisotropic_vdf.glsl"
function="mx_anisotropic_vdf" target="genmsl"/>

<!-- <layer> -->
<implementation name="IM_layer_bsdf_genmsl" nodedef="ND_layer_bsdf" target="genmsl" />
Expand All @@ -47,28 +60,35 @@
<implementation name="IM_multiply_edfF_genmsl" nodedef="ND_multiply_edfF" target="genmsl" />

<!-- <uniform_edf> -->
<implementation name="IM_uniform_edf_genmsl" nodedef="ND_uniform_edf" file="../genglsl/mx_uniform_edf.glsl" function="mx_uniform_edf" target="genmsl" />
<implementation name="IM_uniform_edf_genmsl" nodedef="ND_uniform_edf" file="mx_uniform_edf.glsl"
function="mx_uniform_edf" target="genmsl"/>

<!-- <surface> -->
<implementation name="IM_surface_genmsl" nodedef="ND_surface" target="genmsl" />

<!-- <displacement> -->
<implementation name="IM_displacement_float_genmsl" nodedef="ND_displacement_float" file="../genglsl/mx_displacement_float.glsl" function="mx_displacement_float" target="genmsl" />
<implementation name="IM_displacement_vector3_genmsl" nodedef="ND_displacement_vector3" file="../genglsl/mx_displacement_vector3.glsl" function="mx_displacement_vector3" target="genmsl" />
<implementation name="IM_displacement_float_genmsl" nodedef="ND_displacement_float" file="mx_displacement_float.glsl"
function="mx_displacement_float" target="genmsl"/>
<implementation name="IM_displacement_vector3_genmsl" nodedef="ND_displacement_vector3"
file="mx_displacement_vector3.glsl" function="mx_displacement_vector3" target="genmsl"/>

<!-- <light> -->
<implementation name="IM_light_genmsl" nodedef="ND_light" target="genmsl" />

<!-- <roughness_anisotropy> -->
<implementation name="IM_roughness_anisotropy_genmsl" nodedef="ND_roughness_anisotropy" file="../genglsl/mx_roughness_anisotropy.glsl" function="mx_roughness_anisotropy" target="genmsl" />
<implementation name="IM_roughness_anisotropy_genmsl" nodedef="ND_roughness_anisotropy"
file="mx_roughness_anisotropy.glsl" function="mx_roughness_anisotropy" target="genmsl"/>

<!-- <roughness_dual> -->
<implementation name="IM_roughness_dual_genmsl" nodedef="ND_roughness_dual" file="../genglsl/mx_roughness_dual.glsl" function="mx_roughness_dual" target="genmsl" />
<implementation name="IM_roughness_dual_genmsl" nodedef="ND_roughness_dual" file="mx_roughness_dual.glsl"
function="mx_roughness_dual" target="genmsl"/>

<!-- <artistic_ior> -->
<implementation name="IM_artistic_ior_genmsl" nodedef="ND_artistic_ior" file="../genglsl/mx_artistic_ior.glsl" function="mx_artistic_ior" target="genmsl" />
<implementation name="IM_artistic_ior_genmsl" nodedef="ND_artistic_ior" file="mx_artistic_ior.glsl"
function="mx_artistic_ior" target="genmsl"/>

<!-- <blackbody> -->
<implementation name="IM_blackbody_genmsl" nodedef="ND_blackbody" file="../genglsl/mx_blackbody.glsl" function="mx_blackbody" target="genmsl" />
<implementation name="IM_blackbody_genmsl" nodedef="ND_blackbody" file="mx_blackbody.glsl" function="mx_blackbody"
target="genmsl"/>

</materialx>
Loading