Skip to content

Commit

Permalink
Improve shader profile extension to be more compatible with bgfx (#247)
Browse files Browse the repository at this point in the history
* remove profile extension incompatible with those listed under examples/runtime/shaders; fix incorrect parameter names; enforce consistent syntax when appending to CLI.

* remove dx9

* add separate profile extension for paths vs profile extension
  • Loading branch information
Andrewfeng123 authored Nov 5, 2024
1 parent b135fa3 commit 1139067
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions cmake/bgfxToolUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ if(TARGET bgfx::texturec)
add_custom_command(
OUTPUT ${ARG_OUTPUT} #
COMMAND bgfx::texturec ${CLI} #
MAIN_DEPENDENCY ${ARG_INPUT} #
MAIN_DEPENDENCY ${ARG_FILE} #
)
endfunction()
endif()
Expand Down Expand Up @@ -279,12 +279,12 @@ if(TARGET bgfx::geometryc)

# --packnormal
if(ARG_PACKNORMAL)
list(APPEND CLI "--packnormal ${ARG_PACKNORMAL}")
list(APPEND CLI "--packnormal" "${ARG_PACKNORMAL}")
endif()

# --packuv
if(ARG_PACKUV)
list(APPEND CLI "--packuv" ${ARG_PACKUV})
list(APPEND CLI "--packuv" "${ARG_PACKUV}")
endif()

# --tangent
Expand Down Expand Up @@ -352,7 +352,7 @@ if(TARGET bgfx::geometryc)
add_custom_command(
OUTPUT ${ARG_OUTPUT} #
COMMAND bgfx::geometryc ${CLI} #
MAIN_DEPENDENCY ${ARG_INPUT} #
MAIN_DEPENDENCY ${ARG_FILE} #
)
endfunction()
endif()
Expand Down Expand Up @@ -539,15 +539,23 @@ if(TARGET bgfx::shaderc)
set(${ARG_OUT} ${CLI} PARENT_SCOPE)
endfunction()

# extensions consistent with those listed under bgfx/runtime/shaders
function(_bgfx_get_profile_path_ext PROFILE PROFILE_PATH_EXT)
string(REPLACE 300_es essl PROFILE ${PROFILE})
string(REPLACE 120 glsl PROFILE ${PROFILE})
string(REPLACE s_4_0 dx10 PROFILE ${PROFILE})
string(REPLACE s_5_0 dx11 PROFILE ${PROFILE})
set(${PROFILE_PATH_EXT} ${PROFILE} PARENT_SCOPE)
endfunction()

# extensions consistent with embedded_shader.h
function(_bgfx_get_profile_ext PROFILE PROFILE_EXT)
string(REPLACE 300_es essl PROFILE ${PROFILE})
string(REPLACE 120 glsl PROFILE ${PROFILE})
string(REPLACE spirv spv PROFILE ${PROFILE})
string(REPLACE metal mtl PROFILE ${PROFILE})
string(REPLACE s_3_0 dx9 PROFILE ${PROFILE})
string(REPLACE s_4_0 dx10 PROFILE ${PROFILE})
string(REPLACE s_5_0 dx11 PROFILE ${PROFILE})

set(${PROFILE_EXT} ${PROFILE} PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -602,11 +610,12 @@ if(TARGET bgfx::shaderc)
set(COMMANDS "")
set(MKDIR_COMMANDS "")
foreach(PROFILE ${PROFILES})
_bgfx_get_profile_path_ext(${PROFILE} PROFILE_PATH_EXT)
_bgfx_get_profile_ext(${PROFILE} PROFILE_EXT)
if(ARGS_AS_HEADERS)
set(HEADER_PREFIX .h)
endif()
set(OUTPUT ${ARGS_OUTPUT_DIR}/${PROFILE_EXT}/${SHADER_FILE_BASENAME}.bin${HEADER_PREFIX})
set(OUTPUT ${ARGS_OUTPUT_DIR}/${PROFILE_PATH_EXT}/${SHADER_FILE_BASENAME}.bin${HEADER_PREFIX})
set(PLATFORM_I ${PLATFORM})
if(PROFILE STREQUAL "spirv")
set(PLATFORM_I LINUX)
Expand Down Expand Up @@ -635,7 +644,7 @@ if(TARGET bgfx::shaderc)
${CMAKE_COMMAND}
-E
make_directory
${ARGS_OUTPUT_DIR}/${PROFILE_EXT}
${ARGS_OUTPUT_DIR}/${PROFILE_PATH_EXT}
)
list(APPEND COMMANDS COMMAND bgfx::shaderc ${CLI})
endforeach()
Expand Down

0 comments on commit 1139067

Please sign in to comment.