Skip to content

Commit 29d0bac

Browse files
ShaderC dependencies Remove and Shader Compilation Refactor (JeanPhilippeKernel#504)
- We remove the use of the shaderc download, which was only being used for compiling shaders. - We instead use the glslang compiler that we we're compiling anyway. - This way we can extract the glslang compiler that we have compiled and do the shader compilation as part of the CMake Scripting. - This should reduce the compilation times and/or storage requirements. - 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 Co-authored-by: Mathew Benson <mathew@benson.co.ke>
1 parent 27ab2f4 commit 29d0bac

File tree

7 files changed

+47
-254
lines changed

7 files changed

+47
-254
lines changed

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)

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

dependencies.cmake

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ FetchContent_Declare(
102102

103103
)
104104

105-
106105
FetchContent_Declare(
107106
SPIRV-Tools
108107
GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Tools.git
@@ -179,14 +178,14 @@ FetchContent_MakeAvailable(
179178
yaml-cpp
180179
VulkanMemoryAllocator
181180
SPIRV-Headers
182-
SPIRV-Tools
183-
glslang
184181
spirv_cross_core
185-
GTest
186182
nlohmann_json
187183
tlsf
188184
CLI11
189185
rapidhash
186+
SPIRV-Tools
187+
glslang
188+
GTest
190189
)
191190

192191
set(IMGUIDIR ${FETCHCONTENT_BASE_DIR}/imgui)
@@ -240,7 +239,6 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
240239
target_link_libraries(External_libs INTERFACE SPIRV-Tools-static)
241240
else()
242241
target_link_libraries(External_libs INTERFACE SPIRV-Tools)
243-
244242
endif()
245243

246244

@@ -261,7 +259,6 @@ target_link_libraries(External_libs
261259
glslang::glslang
262260
glslang::glslang-default-resource-limits
263261
glslang::SPIRV
264-
glslang::SPVRemapper
265262
GPUOpen::VulkanMemoryAllocator
266263
nlohmann_json::nlohmann_json
267264
)

0 commit comments

Comments
 (0)