diff options
| -rw-r--r-- | .gitattributes | 10 | ||||
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | premake5.lua | 77 | ||||
| -rwxr-xr-x | tools/compile-shaders.sh | 11 | ||||
| -rwxr-xr-x | tools/fetch-slang.sh | 4 |
5 files changed, 80 insertions, 26 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..71d4c7b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +* text=auto +*.spv binary +*.hdr binary +*.ttf binary +*.png binary +*.jpg binary +*.glsl text eol=lf +*.slang text eol=lf +*.sh text eol=lf +*.lua text eol=lf @@ -28,5 +28,7 @@ Makefile *.vcxproj.* tools/slang/ -assets/shaders/generated/ +assets/shaders/generated/*.metal +assets/shaders/generated/.err +assets/shaders/generated/.stage.glsl exports/ diff --git a/premake5.lua b/premake5.lua index 27a11e2..88cf22a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,5 +1,12 @@ output_dir = "%{cfg.buildcfg}-%{cfg.system}" +-- the LunarG installer sets this on windows. without it the vulkan backend is +-- left out of the build (DONUT_NO_VULKAN) and the app runs opengl only. +vulkan_sdk = os.getenv("VULKAN_SDK") +if os.target() == "windows" and not vulkan_sdk then + print("VULKAN_SDK is not set: building without the Vulkan backend (OpenGL only)") +end + include_dir = { glm = "ext/glm", glfw = "ext/glfw/include", @@ -38,19 +45,21 @@ function setup_c_target() runtime "Debug" symbols "On" - filter { "system:macosx or system:linux" } - buildoptions { - "-g", - "-fno-omit-frame-pointer", - "-fsanitize=address,undefined", - } + -- premake filters don't nest: this one has to name debug again, or the + -- sanitizers end up in every config + filter { "configurations:debug", "system:macosx or system:linux" } + buildoptions { + "-g", + "-fno-omit-frame-pointer", + "-fsanitize=address,undefined", + } - linkoptions { - "-fsanitize=address,undefined", - } - filter {} + linkoptions { + "-fsanitize=address,undefined", + } + filter {} - filter { "configurations:release", "configurations:dist" } + filter "configurations:release or dist" runtime "Release" optimize "Speed" filter {} @@ -78,19 +87,21 @@ function setup_cpp_target() runtime "Debug" symbols "On" - filter { "system:macosx or system:linux" } - buildoptions { - "-g", - "-fno-omit-frame-pointer", - "-fsanitize=address,undefined", - } + -- premake filters don't nest: this one has to name debug again, or the + -- sanitizers end up in every config + filter { "configurations:debug", "system:macosx or system:linux" } + buildoptions { + "-g", + "-fno-omit-frame-pointer", + "-fsanitize=address,undefined", + } - linkoptions { - "-fsanitize=address,undefined", - } - filter {} + linkoptions { + "-fsanitize=address,undefined", + } + filter {} - filter { "configurations:release", "configurations:dist" } + filter "configurations:release or dist" runtime "Release" optimize "Speed" filter {} @@ -335,6 +346,10 @@ project "imgui" externalincludedirs "/opt/homebrew/include" filter "system:windows" systemversion "latest" + if vulkan_sdk then + files "ext/imgui/backends/imgui_impl_vulkan.cpp" + externalincludedirs (vulkan_sdk .. "/Include") + end filter {} project "imguizmo" @@ -387,6 +402,7 @@ project "donut" } includedirs "src" + debugdir "%{wks.location}" -- every asset path is relative to the repo root externalincludedirs { "%{include_dir.glm}", @@ -413,7 +429,22 @@ project "donut" filter "system:windows" systemversion "latest" - links "opengl32.lib" + defines "NOMINMAX" -- glad drags in windows.h, whose min/max macros eat std::min/std::max + usestandardpreprocessor "On" -- msvc only knows __VA_OPT__ (log.h) with its conforming preprocessor + conformancemode "On" + buildoptions "/utf-8" + links "opengl32" + if vulkan_sdk then + externalincludedirs (vulkan_sdk .. "/Include") + libdirs (vulkan_sdk .. "/Lib") + -- delay-loaded, so a box without a Vulkan driver still starts (on OpenGL) + -- instead of the loader refusing to run the exe at all + links { "vulkan-1", "delayimp" } + linkoptions "/DELAYLOAD:vulkan-1.dll" + else + defines "DONUT_NO_VULKAN" + removefiles "src/platform/vulkan/**" + end filter "system:macosx" files "src/**.mm" diff --git a/tools/compile-shaders.sh b/tools/compile-shaders.sh index 5da5d9a..a5d786e 100755 --- a/tools/compile-shaders.sh +++ b/tools/compile-shaders.sh @@ -14,8 +14,15 @@ set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" -SLANGC="${SLANGC:-$ROOT/tools/slang/bin/slangc}" -SPIRV_CROSS="${SPIRV_CROSS:-$(command -v spirv-cross || echo spirv-cross)}" +# the vulkan sdk ships both tools (git bash on windows); tools/slang + brew otherwise. +if [ -z "${SLANGC:-}" ]; then + if [ -n "${VULKAN_SDK:-}" ] && [ -x "$VULKAN_SDK/Bin/slangc.exe" ]; then SLANGC="$VULKAN_SDK/Bin/slangc.exe" + else SLANGC="$ROOT/tools/slang/bin/slangc"; fi +fi +if [ -z "${SPIRV_CROSS:-}" ]; then + if [ -n "${VULKAN_SDK:-}" ] && [ -x "$VULKAN_SDK/Bin/spirv-cross.exe" ]; then SPIRV_CROSS="$VULKAN_SDK/Bin/spirv-cross.exe" + else SPIRV_CROSS="$(command -v spirv-cross || echo spirv-cross)"; fi +fi SRC="$ROOT/assets/shaders" OUT="$SRC/generated" diff --git a/tools/fetch-slang.sh b/tools/fetch-slang.sh index 5229bf7..d94a63b 100755 --- a/tools/fetch-slang.sh +++ b/tools/fetch-slang.sh @@ -16,6 +16,10 @@ case "$(uname -s)-$(uname -m)" in Darwin-x86_64) ASSET="macos-x86_64" ;; Linux-x86_64) ASSET="linux-x86_64" ;; Linux-aarch64|Linux-arm64) ASSET="linux-aarch64" ;; + MINGW*|MSYS*|CYGWIN*) + # git bash on windows: the Vulkan SDK already ships slangc.exe and + # spirv-cross.exe, and compile-shaders.sh picks them up from $VULKAN_SDK/Bin + echo "fetch-slang: nothing to fetch on windows, the Vulkan SDK's slangc.exe is used"; exit 0 ;; *) echo "fetch-slang: unsupported platform $(uname -s)-$(uname -m)"; exit 1 ;; esac |
