-
Notifications
You must be signed in to change notification settings - Fork 109
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
Fixed bgfx_compile_shaders incorrectly generating output path, and generat quality of life update for all tool util functions #255
base: master
Are you sure you want to change the base?
Conversation
…om bgfx_compile_shaders
…h if it doesnt exist
…oesnt exist and fixed bgfx_compile_binary_to_header not creatign output path if it doesnt exist
…doesnt exist and written mention of it in readme
get_filename_component(OUTPUT_DIR "${ARG_OUTPUT_FILE}" DIRECTORY) | ||
file(MAKE_DIRECTORY ${OUTPUT_DIR}) # create output path if it does not exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
get_filename_component(OUTPUT_DIR "${ARG_OUTPUT_FILE}" DIRECTORY) | |
file(MAKE_DIRECTORY ${OUTPUT_DIR}) # create output path if it does not exist | |
get_filename_component(OUTPUT_DIR "${ARG_OUTPUT_FILE}" DIRECTORY) | |
file(MAKE_DIRECTORY ${OUTPUT_DIR}) # create output path if it does not exist |
file(RELATIVE_PATH INPUT_FILE_RELATIVE ${CMAKE_BINARY_DIR} ${ARG_INPUT_FILE}) | ||
file(RELATIVE_PATH OUTPUT_FILE_RELATIVE ${CMAKE_BINARY_DIR} ${ARG_OUTPUT_FILE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
file(RELATIVE_PATH INPUT_FILE_RELATIVE ${CMAKE_BINARY_DIR} ${ARG_INPUT_FILE}) | |
file(RELATIVE_PATH OUTPUT_FILE_RELATIVE ${CMAKE_BINARY_DIR} ${ARG_OUTPUT_FILE}) | |
file(RELATIVE_PATH INPUT_FILE_RELATIVE ${CMAKE_BINARY_DIR} ${ARG_INPUT_FILE}) | |
file(RELATIVE_PATH OUTPUT_FILE_RELATIVE ${CMAKE_BINARY_DIR} ${ARG_OUTPUT_FILE}) |
string(REPLACE " " "_" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${OUTPUT_FILE_RELATIVE}) | ||
string(REPLACE "/" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) | ||
string(REPLACE "\\" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) # probably need this for windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
string(REPLACE " " "_" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${OUTPUT_FILE_RELATIVE}) | |
string(REPLACE "/" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) | |
string(REPLACE "\\" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) # probably need this for windows | |
string(REPLACE " " "_" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${OUTPUT_FILE_RELATIVE}) | |
string(REPLACE "/" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) | |
string(REPLACE "\\" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH} | |
)# probably need this for windows |
COMMAND bgfx::bin2c ${CLI} > bgfx_tool_logs/binary_to_header_compile_output_${FILE_NAME_APPROPRIATE_OUTPUT_PATH}.log # | ||
COMMENT "Compiling ${INPUT_FILE_RELATIVE} as header" # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
COMMAND bgfx::bin2c ${CLI} > bgfx_tool_logs/binary_to_header_compile_output_${FILE_NAME_APPROPRIATE_OUTPUT_PATH}.log # | |
COMMENT "Compiling ${INPUT_FILE_RELATIVE} as header" # | |
COMMAND bgfx::bin2c ${CLI} > | |
bgfx_tool_logs/binary_to_header_compile_output_${FILE_NAME_APPROPRIATE_OUTPUT_PATH}.log # | |
COMMENT "Compiling ${INPUT_FILE_RELATIVE} as header" # |
add_custom_target( | ||
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL # | ||
DEPENDS ${ARG_OUTPUT_FILE} # | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
add_custom_target( | |
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL # | |
DEPENDS ${ARG_OUTPUT_FILE} # | |
) | |
add_custom_target( | |
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL # | |
DEPENDS ${ARG_OUTPUT_FILE} # | |
) |
file(RELATIVE_PATH OUTPUT_RELATIVE ${CMAKE_BINARY_DIR} ${OUTPUT}) | ||
|
||
string(REPLACE " " "_" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${OUTPUT_RELATIVE}) | ||
string(REPLACE "/" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) | ||
string(REPLACE "\\" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) # probably need this for windows | ||
|
||
list(APPEND COMMANDS COMMAND bgfx::shaderc ${CLI} > bgfx_tool_logs/shader_compile_output_${FILE_NAME_APPROPRIATE_OUTPUT_PATH}.log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
file(RELATIVE_PATH OUTPUT_RELATIVE ${CMAKE_BINARY_DIR} ${OUTPUT}) | |
string(REPLACE " " "_" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${OUTPUT_RELATIVE}) | |
string(REPLACE "/" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) | |
string(REPLACE "\\" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) # probably need this for windows | |
list(APPEND COMMANDS COMMAND bgfx::shaderc ${CLI} > bgfx_tool_logs/shader_compile_output_${FILE_NAME_APPROPRIATE_OUTPUT_PATH}.log) | |
file(RELATIVE_PATH OUTPUT_RELATIVE ${CMAKE_BINARY_DIR} ${OUTPUT}) | |
string(REPLACE " " "_" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${OUTPUT_RELATIVE}) | |
string(REPLACE "/" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH}) | |
string(REPLACE "\\" "-" FILE_NAME_APPROPRIATE_OUTPUT_PATH ${FILE_NAME_APPROPRIATE_OUTPUT_PATH} | |
)# probably need this for windows | |
list( | |
APPEND | |
COMMANDS | |
COMMAND | |
bgfx::shaderc | |
${CLI} | |
> | |
bgfx_tool_logs/shader_compile_output_${FILE_NAME_APPROPRIATE_OUTPUT_PATH}.log | |
) |
endforeach() | ||
|
||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bgfx_tool_logs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bgfx_tool_logs) | |
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bgfx_tool_logs) |
# This is to prevent error if compiling as binary and header in same output path | ||
set(TARGET_NAME "${SHADER_FILE_RELATIVE}") | ||
if(ARGS_AS_HEADERS) | ||
set(TARGET_NAME "${SHADER_FILE_RELATIVE} as header") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
# This is to prevent error if compiling as binary and header in same output path | |
set(TARGET_NAME "${SHADER_FILE_RELATIVE}") | |
if(ARGS_AS_HEADERS) | |
set(TARGET_NAME "${SHADER_FILE_RELATIVE} as header") | |
endif() | |
# This is to prevent error if compiling as binary and header in same output path | |
set(TARGET_NAME "${SHADER_FILE_RELATIVE}") | |
if(ARGS_AS_HEADERS) | |
set(TARGET_NAME "${SHADER_FILE_RELATIVE} as header") | |
endif() |
OUTPUT ${OUTPUTS} # | ||
COMMAND ${COMMANDS} # | ||
MAIN_DEPENDENCY ${SHADER_FILE_ABSOLUTE} # | ||
COMMENT "Compiling ${TARGET_NAME}" # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
COMMENT "Compiling ${TARGET_NAME}" # | |
COMMENT "Compiling ${TARGET_NAME}" # |
add_custom_target( | ||
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL # | ||
DEPENDS ${OUTPUTS} # | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cmake-format] reported by reviewdog 🐶
add_custom_target( | |
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL # | |
DEPENDS ${OUTPUTS} # | |
) | |
add_custom_target( | |
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL # | |
DEPENDS ${OUTPUTS} # | |
) |
Apply this patch to fix the failing format test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing the change locally, it immediately fails to compile shaders with:
[build] [1/24] Compiling ../../assets/shaders/imgui/vs_imgui_image.sc as header
[build] FAILED: include/generated/shaders/imgui/glsl/vs_imgui_image.sc.bin.h include/generated/shaders/imgui/essl/vs_imgui_image.sc.bin.h include/generated/shaders/imgui/spirv/vs_imgui_image.sc.bin.h code/openblack/cmake-build-presets/ninja-multi-vcpkg/include/generated/shaders/imgui/glsl/vs_imgui_image.sc.bin.h code/openblack/cmake-build-presets/ninja-multi-vcpkg/include/generated/shaders/imgui/essl/vs_imgui_image.sc.bin.h code/openblack/cmake-build-presets/ninja-multi-vcpkg/include/generated/shaders/imgui/spirv/vs_imgui_image.sc.bin.h
[build] cd code/openblack/cmake-build-presets/ninja-multi-vcpkg/src && code/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x64-linux/tools/bgfx/shaderc -f code/openblack/assets/shaders/imgui/vs_imgui_image.sc -i code/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x64-linux/include/bgfx -o code/openblack/cmake-build-presets/ninja-multi-vcpkg/include/generated/shaders/imgui/glsl/vs_imgui_image.sc.bin.h --bin2c vs_imgui_image_glsl --type vertex --varyingdef code/openblack/assets/shaders/imgui/varying.def.sc --profile 120 -O 0 --Werror > bgfx_tool_logs/shader_compile_output_include-generated-shaders-imgui-glsl-vs_imgui_image.sc.bin.h.log && code/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x64-linux/tools/bgfx/shaderc -f code/openblack/assets/shaders/imgui/vs_imgui_image.sc -i code/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x64-linux/include/bgfx -o code/openblack/cmake-build-presets/ninja-multi-vcpkg/include/generated/shaders/imgui/essl/vs_imgui_image.sc.bin.h --bin2c vs_imgui_image_essl --type vertex --varyingdef code/openblack/assets/shaders/imgui/varying.def.sc --profile 300_es -O 0 --Werror > bgfx_tool_logs/shader_compile_output_include-generated-shaders-imgui-essl-vs_imgui_image.sc.bin.h.log && code/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x64-linux/tools/bgfx/shaderc -f code/openblack/assets/shaders/imgui/vs_imgui_image.sc -i code/openblack/cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x64-linux/include/bgfx -o code/openblack/cmake-build-presets/ninja-multi-vcpkg/include/generated/shaders/imgui/spirv/vs_imgui_image.sc.bin.h --bin2c vs_imgui_image_spv --type vertex --varyingdef code/openblack/assets/shaders/imgui/varying.def.sc --profile spirv -O 0 --Werror > bgfx_tool_logs/shader_compile_output_include-generated-shaders-imgui-spirv-vs_imgui_image.sc.bin.h.log
[build] /bin/sh: line 1: bgfx_tool_logs/shader_compile_output_include-generated-shaders-imgui-glsl-vs_imgui_image.sc.bin.h.log: No such file or directory
Looking at my directory structure code/openblack/cmake-build-presets/ninja-multi-vcpkg/bgfx_tool_logs
was created but I think you're not taking into account ${CMAKE_BINARY_DIR}
at some step.
add_custom_command( | ||
OUTPUT ${ARG_OUTPUT_FILE} # | ||
COMMAND bgfx::bin2c ${CLI} # | ||
COMMAND bgfx::bin2c ${CLI} > bgfx_tool_logs/binary_to_header_compile_output_${FILE_NAME_APPROPRIATE_OUTPUT_PATH}.log # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this work on windows?
I don't really see the advantage of logging build output to a file. |
ok i will remove logging in to file and figure out the error. logging probably is going to be hinder rather than helpful. |
could you give me your local test cmakelists.txt to test if its working as you expect it to? also file structure. |
changes in 'bgfx_compile_geometry', 'bgfx_compile_texture', 'bgfx_compile_binary_to_header' and 'bgfx_compile_shaders':
If path doesnt exist to output path, it will be generated on build system generation. (fix for bgfx_compile_shaders, adition to rest of functions)
All these functions create log file in 'bgfx_tool_logs' directory in root of build directory.
ex:
also i added mention in readme for 'bgfx_compile_geometry' which was missing for some reason
i have only tested this on linux. i have no access windows or others atm
i also had to call add_custom_target for each functions else it didnt run