Skip to content

Commit

Permalink
feat(shaders): backport __SHADER_TARGET_MAJOR and __SHADER_TARGET_MINOR
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Dec 26, 2024
1 parent f33fbd1 commit dc68399
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function(build_shader_target ADDON ADDON_PATH)
set(EMBED_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/${ADDON}.include/embed)
unset(SHADER_BINARIES)

file(GLOB_RECURSE SHADER_SOURCES ${ADDON_PATH}/*.hlsl )
file(GLOB_RECURSE SHADER_SOURCES ${ADDON_PATH}/*.hlsl)
foreach(FILE ${SHADER_SOURCES})
cmake_path(GET FILE FILENAME FILENAME)
cmake_path(GET FILE PARENT_PATH TARGET_PATH)
Expand All @@ -93,17 +93,22 @@ function(build_shader_target ADDON ADDON_PATH)

if(SHADER_TARGET AND (SHADER_HASH OR SHADER_NAME))
string(SUBSTRING ${SHADER_TARGET} 3 1 SHADER_TARGET_MAJOR)
string(SUBSTRING ${SHADER_TARGET} 5 1 SHADER_TARGET_MINOR)
set(SHADER_COMPILER ${FXC_BIN})
unset(SHADER_FLAGS)
if(SHADER_TARGET_MAJOR EQUAL "6")
if(SHADER_TARGET_MAJOR GREATER_EQUAL "6")
set(SHADER_COMPILER ${DXC_BIN})
set(SHADER_FLAGS "/HV 2021")
elseif(SHADER_TARGET_MAJOR EQUAL "5")
if(SHADER_TARGET_MINOR EQUAL "0")
set(SHADER_FLAGS "/Gec")
endif()
set(SHADER_FLAGS "/HV 2021") # Ovewrite flags
else()
set(SHADER_FLAGS "/Gec") # Compatibility mode
set(SHADER_FLAGS ${SHADER_FLAGS} /D __SHADER_TARGET_MAJOR=${SHADER_TARGET_MAJOR})
set(SHADER_FLAGS ${SHADER_FLAGS} /D __SHADER_TARGET_MINOR=${SHADER_TARGET_MINOR})
if(SHADER_TARGET_MAJOR EQUAL "5")
if(SHADER_TARGET_MINOR EQUAL "0")
set(SHADER_FLAGS ${SHADER_FLAGS} /Gec)
endif()
else()
set(SHADER_FLAGS ${SHADER_FLAGS} /Gec)
endif()
endif()

unset(HLSL_DEPENDENCIES)
Expand Down
12 changes: 6 additions & 6 deletions src/shaders/math.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ static const float FLT10_MAX = 64512.f;
static const float FLT11_MAX = 65024.f;
static const float FLT16_MAX = 65504.f;

#if __SHADER_TARGET_MAJOR >= 6
#define SIGN_FUNCTION_GENERATOR(T) \
T Sign(T x) { \
return sign(x); \
}
#else
#if __SHADER_TARGET_MAJOR <= 5
#define SIGN_FUNCTION_GENERATOR(T) \
T Sign(T x) { \
return mad(saturate(mad(x, FLT_MAX, 0.5f)), 2.f, -1.f); \
}
#else
#define SIGN_FUNCTION_GENERATOR(T) \
T Sign(T x) { \
return sign(x); \
}
#endif

SIGN_FUNCTION_GENERATOR(float);
Expand Down

0 comments on commit dc68399

Please sign in to comment.