Skip to content

Commit 2b1afa1

Browse files
ShaderC dependencies and Shader Compilation Refactor
- To reduce compile times, we setup the downloading of the ShaderC library to be handled in the CMake workflow - This way we can extract the glslang compiler that we have downloaded and do the shader compilation as part of the CMake Scripting. - Also We can avoid doing the duplicate work of compiling the glslang, SPIRV-Tools and gtest libraries as they are already pre-compiled in the ShaderC package. - This should reduce the compilation times. - As Currently configured the Shaders will be compiled in each build, however, we can improve on this and ensure that compilation is only done as required at a later stage
1 parent c939ac6 commit 2b1afa1

9 files changed

Lines changed: 73 additions & 257 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ if (NOT LAUNCHER_ONLY)
4343
## Setup Dependencies
4444
include(dependencies.cmake)
4545

46+
## Compile Shaders
47+
48+
add_subdirectory (Resources)
49+
4650
# Core engine lib is here
4751
#
4852
add_subdirectory (ZEngine)

CMakePresets.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
"architecture": "x64",
6565
"cacheVariables": {
6666
"CMAKE_CONFIGURATION_TYPES": "Debug",
67-
"CMAKE_INSTALL_PREFIX": "Result.Windows.x64.MultiConfig"
67+
"CMAKE_INSTALL_PREFIX": "Result.Windows.x64.MultiConfig",
68+
"SHADERC_URL": "https://storage.googleapis.com/shaderc/artifacts/prod/graphics_shader_compiler/shaderc/windows/vs2022_amd64_release_continuous/29/20260112-140346/install.zip"
6869
}
6970

7071
},
@@ -100,7 +101,8 @@
100101
"cacheVariables": {
101102
"BUILD_FRAMEWORK": "ON",
102103
"CMAKE_INSTALL_PREFIX": "Result.Darwin.x64.Debug",
103-
"CMAKE_CONFIGURATION_TYPES": "Debug"
104+
"CMAKE_CONFIGURATION_TYPES": "Debug",
105+
"SHADERC_URL": "https://storage.googleapis.com/shaderc/artifacts/prod/graphics_shader_compiler/shaderc/macos/continuous_clang_release/519/20260112-140351/install.tgz"
104106
}
105107
},
106108
{
@@ -142,7 +144,8 @@
142144
"binaryDir": "Result.Linux.x64.Debug",
143145
"generator": "Ninja",
144146
"cacheVariables": {
145-
"CMAKE_INSTALL_PREFIX": "Result.Linux.x64.Debug"
147+
"CMAKE_INSTALL_PREFIX": "Result.Linux.x64.Debug",
148+
"SHADERC_URL": "https://storage.googleapis.com/shaderc/artifacts/prod/graphics_shader_compiler/shaderc/linux/continuous_clang_release/510/20260112-140346/install.tgz"
146149
}
147150
},
148151
{

Obelisk/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ install(TARGETS ${TARGET_NAME}
5353
DESTINATION bin
5454
)
5555

56-
install(DIRECTORY ../Resources/Editor/Settings DESTINATION bin)
57-
58-
install(DIRECTORY ../Resources/Shaders DESTINATION bin)
5956

6057

6158

Resources/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
set(ShaderPath ${CMAKE_CURRENT_SOURCE_DIR}/Shaders)
2+
set(ShaderOutputPath "${ShaderPath}/Cache")
3+
4+
file (MAKE_DIRECTORY "${ShaderOutputPath}")
5+
6+
file (GLOB VertexShaders CONFIGURE_DEPENDS "${ShaderPath}/*.vert")
7+
file (GLOB FragmentShaders CONFIGURE_DEPENDS "${ShaderPath}/*.frag")
8+
9+
foreach(VertexShader ${VertexShaders})
10+
11+
cmake_path(GET VertexShader STEM shaderfilename)
12+
cmake_path(APPEND_STRING shaderfilename "_vertex.spv" OUTPUT_VARIABLE VertexShaderOutputFileName )
13+
cmake_path(APPEND ShaderOutputPath ${VertexShaderOutputFileName} OUTPUT_VARIABLE VertexShaderOutputPath)
14+
15+
add_custom_target("Compile-${shaderfilename}-vertex" ALL COMMAND glslang::glslang-standalone "-I${ShaderPath}" "-V" "-o" "${VertexShaderOutputPath}" "${VertexShader}")
16+
17+
18+
endforeach()
19+
20+
foreach(FragmentShader ${FragmentShaders})
21+
22+
cmake_path(GET FragmentShader STEM shaderfilename)
23+
cmake_path(APPEND_STRING shaderfilename "_fragment.spv" OUTPUT_VARIABLE FragmentShaderOutputFileName )
24+
cmake_path(APPEND ShaderOutputPath ${FragmentShaderOutputFileName} OUTPUT_VARIABLE FragmentShaderOutputPath)
25+
26+
27+
add_custom_target("Compile-${shaderfilename}-fragment" ALL COMMAND glslang::glslang-standalone "-V" "-I${ShaderPath}" "-o" "${FragmentShaderOutputPath}" "${FragmentShader}")
28+
29+
endforeach()
30+
31+
install(DIRECTORY Editor/Settings DESTINATION bin)
32+
33+
install(DIRECTORY Shaders/Cache DESTINATION bin/Shaders)

Scripts/BuildEngine.ps1

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ function Build([string]$configuration, [int]$VsVersion , [bool]$runBuild) {
174174
}
175175
}
176176

177-
178177
if(-Not $LauncherOnly) {
179178

180179
# Run Clang format
@@ -195,13 +194,6 @@ if(-Not $LauncherOnly) {
195194
}
196195
}
197196

198-
199-
# Run Shader Compilation
200-
foreach ($config in $Configurations) {
201-
$shaderCompileScript = Join-Path $PSScriptRoot -ChildPath "ShaderCompile.ps1"
202-
& pwsh -File $shaderCompileScript -Configuration:$config -ForceRebuild:$true
203-
}
204-
205197
if ($LASTEXITCODE -ne 0) {
206198
Write-Error "Stopped build process..." -ErrorAction Stop
207199
}

Scripts/PostBuild.ps1

Lines changed: 0 additions & 137 deletions
This file was deleted.

Scripts/ShaderCompile.ps1

Lines changed: 0 additions & 100 deletions
This file was deleted.

ZEngine/ZEngine/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
file (GLOB_RECURSE HEADER_FILES_LIST CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
22
file (GLOB_RECURSE CPP_FILES_LIST CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
3-
file (GLOB_RECURSE RESOURCE_FILES_LIST CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/../Resources/Shaders/*.*)
43

54
source_group (TREE ${PROJECT_SOURCE_DIR}/ZEngine PREFIX "Source Files" FILES ${HEADER_FILES_LIST} ${CPP_FILES_LIST})
6-
source_group (TREE ${PROJECT_SOURCE_DIR}/../Resources PREFIX "Resources Files" FILES ${RESOURCE_FILES_LIST})
75

86
# ZEngine source files
97
#

0 commit comments

Comments
 (0)