Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Dec 3, 2024
2 parents a425187 + 600cce2 commit e60236d
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 73 deletions.
40 changes: 40 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,43 @@ install(DIRECTORY "${slang_SOURCE_DIR}/docs/" DESTINATION share/doc/slang)
install(DIRECTORY "${slang_SOURCE_DIR}/include" DESTINATION .)

include(CPack)

# Write basic package config version file using standard CMakePackageConfigHelpers utility
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

# Write SlangConfig.cmake which should allow find_pacakage(SLANG) to work correctly
# SlangConfig.cmake will define slang::slang target that can be linked with using
# target_link_libraries. It will also define SLANG_EXECUTABLE export variable that
# should point to slangc if SLANG_ENABLE_SLANGC is ON.
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/SlangConfig.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION cmake
)

# Conditionally handle the case for Emscripten where slang does not create linkable
# targets. In this case do not export the targets. Otherwise, just export the
# slang target, as this is the library that is required to use the compiler. This possibly
# should later be expanded to include slang-rhi targets if some program intends to use them,
# but possibly wait for a future request before expanding this export set.
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
install(TARGETS slang EXPORT SlangExportTarget)
install(
EXPORT SlangExportTarget
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION cmake
)
endif()

install(
FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION cmake
)
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"generators": ["ZIP"],
"variables": {
"CPACK_PACKAGE_FILE_NAME": "slang",
"CPACK_COMPONENTS_ALL": "Unspecified;metadata;slang-llvm"
"CPACK_COMPONENTS_ALL": "Unspecified;metadata;debug-info;slang-llvm"
}
},
{
Expand Down
20 changes: 20 additions & 0 deletions cmake/SlangConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

@PACKAGE_INIT@

if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
include("${CMAKE_CURRENT_LIST_DIR}/slangTargets.cmake")
check_required_components("slang")
endif()

if(@SLANG_ENABLE_SLANGC@)

find_program(SLANGC_EXECUTABLE "slangc" HINTS ENV PATH "${PACKAGE_PREFIX_DIR}/bin")

if (NOT SLANGC_EXECUTABLE)
message(STATUS "slangc executable not found; ensure it is available in your PATH.")
endif()

set(SLANG_EXECUTABLE ${SLANGC_EXECUTABLE} CACHE STRING "Path to the slangc executable")

endif()

26 changes: 26 additions & 0 deletions cmake/SlangTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function(slang_add_target dir type)
DEBUG_DIR
# Install this target as part of a component
INSTALL_COMPONENT
# Don't install debug info by default for this target and use this
# explicit name instead, used for externally built things such as
# slang-glslang and slang-llvm which have large pdb files
DEBUG_INFO_INSTALL_COMPONENT
)
set(multi_value_args
# Use exactly these sources, instead of globbing from the directory
Expand Down Expand Up @@ -415,9 +419,31 @@ function(slang_add_target dir type)
endmacro()
if(ARG_INSTALL)
i()
set(pdb_component "debug-info")
endif()
if(ARG_INSTALL_COMPONENT)
i(EXCLUDE_FROM_ALL COMPONENT ${ARG_INSTALL_COMPONENT})
set(pdb_component "${ARG_INSTALL_COMPONENT}-debug-info")
endif()
if(ARG_DEBUG_INFO_INSTALL_COMPONENT)
set(pdb_component ${ARG_DEBUG_INFO_INSTALL_COMPONENT})
endif()
if(MSVC AND DEFINED pdb_component)
if(
type STREQUAL "EXECUTABLE"
OR type STREQUAL "SHARED"
OR type STREQUAL "MODULE"
)
install(
FILES $<TARGET_PDB_FILE:${target}>
DESTINATION ${runtime_subdir}
# Optional, because if we're building without debug info (like
# a release build) then we don't want to fail here.
OPTIONAL
COMPONENT ${pdb_component}
EXCLUDE_FROM_ALL
)
endif()
endif()
endfunction()

Expand Down
25 changes: 25 additions & 0 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,31 @@ cmake --build --preset emscripten --target slang-wasm
> Note: If the last build step fails, try running the command that `emcmake`
> outputs, directly.
## Installing

Build targets may be installed using cmake:

```bash
cmake --build . --target install
```

This should install `SlangConfig.cmake` that should allow `find_package` to work.
SlangConfig.cmake defines `SLANG_EXECUTABLE` variable that will point to `slangc`
executable and also define `slang::slang` target to be linked to.

For now, `slang::slang` is the only exported target defined in the config which can
be linked to.

Example usage

```cmake
find_package(slang REQUIRED PATHS ${your_cmake_install_prefix_path} NO_DEFAULT_PATH)
# slang_FOUND should be automatically set
target_link_libraries(yourLib PUBLIC
slang::slang
)
```

## Testing

```bash
Expand Down
4 changes: 2 additions & 2 deletions include/slang.h
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ typedef uint32_t SlangSizeT;
enum SlangDebugInfoFormat : SlangDebugInfoFormatIntegral
{
SLANG_DEBUG_INFO_FORMAT_DEFAULT, ///< Use the default debugging format for the target
SLANG_DEBUG_INFO_FORMAT_C7, ///< CodeView C7 format (typically means debugging information is
///< embedded in the binary)
SLANG_DEBUG_INFO_FORMAT_C7, ///< CodeView C7 format (typically means debugging information
///< is embedded in the binary)
SLANG_DEBUG_INFO_FORMAT_PDB, ///< Program database

SLANG_DEBUG_INFO_FORMAT_STABS, ///< Stabs
Expand Down
1 change: 1 addition & 0 deletions source/slang-glslang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if(SLANG_ENABLE_SLANG_GLSLANG)
LINK_WITH_PRIVATE glslang SPIRV SPIRV-Tools-opt
INCLUDE_DIRECTORIES_PRIVATE ${slang_SOURCE_DIR}/include
INSTALL
DEBUG_INFO_INSTALL_COMPONENT slang-glslang-debug-info
)
# Our only interface is through what we define in source/slang-glslang, in the
# interests of hygiene, hide anything else we link in.
Expand Down
88 changes: 18 additions & 70 deletions source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -10275,12 +10275,11 @@ vector<T,N> max3(vector<T,N> x, vector<T,N> y, vector<T,N> z)
}
}

/// Floating-point maximum considering NaN.
/// Floating-point maximum.
/// @param x The first value to compare.
/// @param y The second value to compare.
/// @return The larger of the two values, element-wise if vector typed, considering NaN.
/// @remarks For metal, if either value is NaN, the other value is returned. If both values are NaN, NaN is returned.
/// For other targets, if `x` is NaN, `y` is returned, otherwise the larger of `x` and `y` is returned.
/// @return The larger of the two values, element-wise if vector typed.
/// @remarks Result is `y` if `x` < `y`, either `x` or `y` if both `x` and `y` are zeros, otherwise `x`. Which operand is the result is undefined if one of the operands is a NaN.
/// @category math
__generic<T : __BuiltinFloatingPointType>
[__readNone]
Expand All @@ -10291,7 +10290,6 @@ T fmax(T x, T y)
{
case metal: __intrinsic_asm "fmax";
default:
if (isnan(x)) return y;
return max(x, y);
}
}
Expand All @@ -10309,11 +10307,12 @@ vector<T,N> fmax(vector<T,N> x, vector<T,N> y)
}
}

/// Floating-point maximum of 3 inputs, considering NaN.
/// Floating-point maximum of 3 inputs.
/// @param x The first value to compare.
/// @param y The second value to compare.
/// @param z The third value to compare.
/// @return The largest of the three values, element-wise if vector typed, considering NaN. If all three values are NaN, NaN is returned. If any value is NaN, the largest is returned.
/// @return The largest of the three values, element-wise if vector typed.
/// @remarks If any operand in the 3-way comparison is NaN, it is undefined which operand is returned.
/// @category math
__generic<T : __BuiltinFloatingPointType>
[__readNone]
Expand All @@ -10325,25 +10324,6 @@ T fmax3(T x, T y, T z)
case metal: __intrinsic_asm "fmax3";
default:
{
bool isnanX = isnan(x);
bool isnanY = isnan(y);
bool isnanZ = isnan(z);

if (isnanX)
{
return isnanY ? z : y;
}
else if (isnanY)
{
if (isnanZ)
return x;
return max(x, z);
}
else if (isnanZ)
{
return max(x, y);
}

return max(y, max(x, z));
}
}
Expand Down Expand Up @@ -10522,12 +10502,11 @@ vector<T,N> min3(vector<T,N> x, vector<T,N> y, vector<T,N> z)
}
}

/// Floating-point minimum considering NaN.
/// Floating-point minimum.
/// @param x The first value to compare.
/// @param y The second value to compare.
/// @return The smaller of the two values, element-wise if vector typed, considering NaN.
/// @remarks For metal, if either value is NaN, the other value is returned. If both values are NaN, NaN is returned.
/// For other targets, if `x` is NaN, `y` is returned, otherwise the smaller of `x` and `y` is returned.
/// @return The smaller of the two values, element-wise if vector typed.
/// @remarks Result is `x` if `x` < `y`, either `x` or `y` if both `x` and `y` are zeros, otherwise `y`. Which operand is the result is undefined if one of the operands is a NaN.
/// @category math
__generic<T : __BuiltinFloatingPointType>
[__readNone]
Expand All @@ -10538,7 +10517,6 @@ T fmin(T x, T y)
{
case metal: __intrinsic_asm "fmin";
default:
if (isnan(x)) return y;
return min(x, y);
}
}
Expand All @@ -10556,11 +10534,12 @@ vector<T,N> fmin(vector<T,N> x, vector<T,N> y)
}
}

/// Floating-point minimum of 3 inputs, considering NaN.
/// Floating-point minimum of 3 inputs.
/// @param x The first value to compare.
/// @param y The second value to compare.
/// @param z The third value to compare.
/// @return The smallest of the three values, element-wise if vector typed, considering NaN. If all three values are NaN, NaN is returned. If any value is NaN, the smallest non-NaN value is returned.
/// @return The smallest of the three values, element-wise if vector typed.
/// @remarks If any operand in the 3-way comparison is NaN, it is undefined which operand is returned.
/// @category math
__generic<T : __BuiltinFloatingPointType>
[__readNone]
Expand All @@ -10572,25 +10551,6 @@ T fmin3(T x, T y, T z)
case metal: __intrinsic_asm "fmin3";
default:
{
bool isnanX = isnan(x);
bool isnanY = isnan(y);
bool isnanZ = isnan(z);

if (isnan(x))
{
return isnanY ? z : y;
}
else if (isnanY)
{
if (isnanZ)
return x;
return min(x, z);
}
else if (isnanZ)
{
return min(x, y);
}

return min(x, min(y, z));
}
}
Expand Down Expand Up @@ -10664,12 +10624,13 @@ vector<T,N> median3(vector<T,N> x, vector<T,N> y, vector<T,N> z)
}
}

/// Floating-point median considering NaN.
/// Floating-point median.
/// @param x The first value to compare.
/// @param y The second value to compare.
/// @param z The third value to compare.
/// @return The median of the three values, element-wise if vector typed, considering NaN. If no value is NaN, the median is returned. If any value is NaN, one of the non-NaN values is returned.
/// @return The median of the three values, element-wise if vector typed.
/// @remarks For metal, this is implemented with the fmedian3 intrinsic.
/// If any value is NaN, it is unspecified which operand is returned.
/// @category math
__generic<T : __BuiltinFloatingPointType>
[__readNone]
Expand All @@ -10681,20 +10642,6 @@ T fmedian3(T x, T y, T z)
case metal: __intrinsic_asm "fmedian3";
default:
{
bool isnanX = isnan(x);
bool isnanY = isnan(y);
bool isnanZ = isnan(z);

if (isnanX)
{
return isnanY ? z : y;
}
else if (isnanY || isnanZ)
{
// "the function can return either non-NaN value"
return x;
}

return median3(x, y, z);
}
}
Expand Down Expand Up @@ -11350,6 +11297,7 @@ matrix<T,N,M> pow(matrix<T,N,M> x, matrix<T,N,M> y)
/// @param y The exponent value.
/// @return The value of `x` raised to the power of `y`.
/// @category math
/// @remarks Return value is undefined for non-positive values of `x`.
__generic<T : __BuiltinFloatingPointType>
[__readNone]
[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]
Expand All @@ -11359,7 +11307,7 @@ T powr(T x, T y)
{
case metal: __intrinsic_asm "powr";
default:
return pow(abs(x), y);
return pow(x, y);
}
}

Expand All @@ -11372,7 +11320,7 @@ vector<T, N> powr(vector<T, N> x, vector<T, N> y)
{
case metal: __intrinsic_asm "powr";
default:
return pow(abs(x), y);
return pow(x, y);
}
}

Expand Down

0 comments on commit e60236d

Please sign in to comment.