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

Fixed bgfx_compile_shaders incorrectly generating output path, and generat quality of life update for all tool util functions #255

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tabdroid-1
Copy link

@tabdroid-1 tabdroid-1 commented Nov 15, 2024

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:

    binary_to_header_compile_output_..-assets-bin-compiled-test.h.log
    -------------------------------   ---------------------------------
                      tool used            relative path to asset output
                      
    shader_compile_output_..-assets-shaders-essl-vs.sc.bin.h.log
    ---------------------    ---------------------------------
              tool used         relative path to asset output
    

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

add_custom_command(
	OUTPUT ${OUTPUTS} #
	COMMAND ${COMMANDS} #
	MAIN_DEPENDENCY ${SHADER_FILE_ABSOLUTE} #
        COMMENT "Compiling ${TARGET_NAME}" #
	DEPENDS ${ARGS_VARYING_DEF} #
)

add_custom_target(
        ${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL #
        DEPENDS ${OUTPUTS} #
)

Comment on lines +59 to +60
get_filename_component(OUTPUT_DIR "${ARG_OUTPUT_FILE}" DIRECTORY)
file(MAKE_DIRECTORY ${OUTPUT_DIR}) # create output path if it does not exist

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 🐶

Suggested change
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

Comment on lines +62 to +63
file(RELATIVE_PATH INPUT_FILE_RELATIVE ${CMAKE_BINARY_DIR} ${ARG_INPUT_FILE})
file(RELATIVE_PATH OUTPUT_FILE_RELATIVE ${CMAKE_BINARY_DIR} ${ARG_OUTPUT_FILE})

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 🐶

Suggested change
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})

Comment on lines +65 to +67
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

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 🐶

Suggested change
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

Comment on lines +71 to +72
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" #

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 🐶

Suggested change
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" #

Comment on lines +76 to +79
add_custom_target(
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL #
DEPENDS ${ARG_OUTPUT_FILE} #
)

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 🐶

Suggested change
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} #
)

Comment on lines +694 to +700
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)

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 🐶

Suggested change
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)

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 🐶

Suggested change
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bgfx_tool_logs)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bgfx_tool_logs)

Comment on lines +705 to +709
# 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()

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 🐶

Suggested change
# 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}" #

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 🐶

Suggested change
COMMENT "Compiling ${TARGET_NAME}" #
COMMENT "Compiling ${TARGET_NAME}" #

Comment on lines +719 to +722
add_custom_target(
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL #
DEPENDS ${OUTPUTS} #
)

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 🐶

Suggested change
add_custom_target(
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL #
DEPENDS ${OUTPUTS} #
)
add_custom_target(
${FILE_NAME_APPROPRIATE_OUTPUT_PATH} ALL #
DEPENDS ${OUTPUTS} #
)

@bwrsandman
Copy link
Collaborator

Apply this patch to fix the failing format test
https://github.com/bkaradzic/bgfx.cmake/actions/runs/11849223278/artifacts/2191073664

Copy link
Collaborator

@bwrsandman bwrsandman left a 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 #
Copy link
Collaborator

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?

@bwrsandman
Copy link
Collaborator

I don't really see the advantage of logging build output to a file.
The logical place to put this is in stdout like with c++ compiling, if you you're developing you want to see logs of your build tools in your build logs, not fish around in files...

@tabdroid-1
Copy link
Author

tabdroid-1 commented Nov 17, 2024

ok i will remove logging in to file and figure out the error. logging probably is going to be hinder rather than helpful.

@tabdroid-1
Copy link
Author

tabdroid-1 commented Nov 17, 2024

could you give me your local test cmakelists.txt to test if its working as you expect it to?

also file structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants