Skip to content

Commit

Permalink
Multi-threaded Asset Loading + More (#6)
Browse files Browse the repository at this point in the history
* Moving around some ideas for a new texture system

* Getting the first phase of async texture loading working

* Setting up texture descriptor pool for texture system 2

* Making progress at getting the new texture system in and working. Replaced usage in the view system and it works. Next we replace the old texture system entirely.

* Replacing the old texture system

* Fixing log to actually print

* Vulkan debugging breakpoint

* Adding missing config.h.in changes

* Lots of little texture load fixes

* Fixing sync problems

* memory mapped io for faster asset loading

* Adding the concept of a thread local allocator

* Fixing build for posix platforms

* Texture loading no longer blocks the main thread

* Fixing silly error

* Another attempt to fix build

* I swear I can fix this

* Refactoring queues

* Some deduplication

* Sketching out the new material system and a couple other quality of life and bug fixes

* More sketching async material loads

* Loading materials that load textures

* Making progress on figuring out how to get materials to chain load textures

* Materials go through the new loading process

* _Thread_local to thread_local

* A bit of renaming

* Fixing some material sizing issues

* Progress. Just need to fix bistro

* Fixing materials not loading

* Some misc fixups

* Fixing static windows build

* allocator.h to tb_allocator.h

* Renaming and trimming files

* Sketching out the new mesh system

* Some mesh systems

* tb_engine_config

* New mesh descriptor update system

* Sketching mesh load system and fixing string dependency in material->texture loading

* Fixing system not running

* Sketching out some ideas for scene loading as well as getting async mesh loading to get data into driver owned memory

* Handling submesh loading

* Refactoring cmake presets to be a bit more flexible

* Fixing presets

* New loading strategy and descriptor write flow

The new mesh system is invoked which is sadly very slow due to descriptor pool thrashing during load. The solution will be to only resize the descriptor pool when a scene has finished parsing all of its resources

* Textures now load in phases to reduce descriptor thrash

* Similar phasing strategy for material loading

* Scene2 drives mesh loading

* The new mesh system is plumbed for rendering but meshes aren't drawn properly yet

* Fixing problem of how to identify meshes across multiple sources

* Fixing failure to deduplicate material entities

* Pinned tasks are now a way for systems to exfiltrate work outside of a readonly system

* Removing more of the old mesh asset loading systems

* Reorganizing a bit of the water systems

* Meshes render again though with some problems

* Some instrumentation and profiling fixes

* Finally figured out why we'd get validation failures with tracy

* Fixing meshes

* Fixing obvious warning

* Fixing a small issue in FINAL builds

* Rough but functional improvement to gltf loading

* Fixing build

* Major progress on async scene loading. Still working on getting entities loading correctly

* Fixed rendering but parents are screwed

* Scene waits for entities to have components report readiness

* Fixing parenting issues

* Making sure entire scene gets parsed properly

* Removing log and fixing crash with bistro

* Improving scene loading. Can't load bistro yet but making progress

* Progress on making sure loading completes. Smaller systems like the ocean test work but bistro isn't there yet

* More loading UI and making sure not to overrun descriptor pool

* Adding a progress bar for my own sake

* Removing an unused variable and making sure that entities popped off the queue are loaded

* Fixing some loading problems. GPU timeout remains

* Sketching out descriptor buffer structure and API

* Initializing descriptor buffer in the texture system

* Making sure the descriptor buffer can be replaced inline

* Cleaning up some of the buffer address access pattern

* Migrating the render object system to descriptor buffers

* Working on getting the descriptor buffer up to meeting the needs of the view system

* Fixing build

* More progress on descriptor buffers

* Migrating mesh systems to descriptor buffers

* Descriptor Buffer code path compiles + some refactoring

* Validation layers stopped screaming but loading never finishes

* Loads and runs but doesn't render yet

* Fixing silly issue with buffer indices not being set properly

* Fixing sky

* Defining TbShader also sketching out what an update to the sky system would look like

* An attempt to get the sky system to work with descriptor buffers that doesn't work but doesn't crash

* Fixed the sky Descriptor Buffer not working

* Small fix to make sure that the mesh and material systems don't try to write more descriptors than available

* Some cleanup and improvements to reduce crashiness

* Some extra cleanup

* Working on a better descriptor access pattern

* Updating material descriptor approach

* Updating mesh descriptor system. Doesn't work lmao

* Fixing the dyn desc pool not writing the correct resources. Still have a GPU crash

* Making some of the descriptor API a bit more ergonomic to rule out crash sources

* Seems less crashy when we remove some complexity

* No more crashes

* Time slicing mesh uploading

* Fixing minor warning

* Smoother loading by breaking up scene loading

* Separating shader optimization flags from debug info flags

* Moving the concept of a free list to its own module so I can reuse it

* Reducing per-frame work that has to be done by the render object system
  • Loading branch information
Honeybunch authored Aug 27, 2024
1 parent 1f240f1 commit a497360
Show file tree
Hide file tree
Showing 170 changed files with 7,595 additions and 4,389 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
{preset: x64-windows-static-ninja-llvm},
]

name: ${{matrix.toolsets.preset}} on Windows}
name: ${{matrix.toolsets.preset}} on Windows
runs-on: [Windows, X64, self-hosted]

steps:
Expand Down
35 changes: 23 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,28 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/TargetArch.cmake)
target_architecture(arch)

# Platform detection
set(tb_windows 0)
set(tb_macos 0)
set(tb_linux 0)
set(tb_android 0)
set(tb_ios 0)
if(WIN32)
set(platform "windows")
set(tb_windows 1)
elseif(APPLE)
if(IOS)
set(platform "ios")
set(tb_ios 1)
else()
set(platform "macos")
set(tb_macos 1)
endif()
elseif(ANDROID)
set(platform "android")
set(tb_android 1)
elseif(UNIX)
set(platform "linux")
set(tb_linux 1)
else()
message(FATAL_ERROR "Unknown platform")
endif()
Expand All @@ -62,14 +72,20 @@ else()
message(FATAL_ERROR "Unknown host")
endif()

set(tb_x64 0)
set(tb_arm64 0)
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
set(host_arch "x64")
set(tb_x64 1)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(host_arch "x64")
set(tb_x64 1)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set(host_arch "arm64")
set(tb_arm64 1)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(host_arch "arm64")
set(tb_arm64 1)
else()
message(FATAL_ERROR "Unknown host arch: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
Expand Down Expand Up @@ -171,8 +187,8 @@ function(cook_shaders out_shader_sources out_shader_headers)
add_custom_command(
OUTPUT ${out_paths}
COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path}
COMMAND ${DXC} -T vs_6_5 -E vert -Vn ${filename}_vert $<$<CONFIG:Debug>:-O0> $<$<CONFIG:Debug>:-Zi> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<CONFIG:Debug>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${vert_out_path}
COMMAND ${DXC} -T ps_6_5 -E frag -Vn ${filename}_frag $<$<CONFIG:Debug>:-O0> $<$<CONFIG:Debug>:-Zi> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<CONFIG:Debug>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${frag_out_path}
COMMAND ${DXC} -T vs_6_5 -E vert -Vn ${filename}_vert $<$<CONFIG:Debug>:-O0> $<$<NOT:$<CONFIG:Release>>:-Zi> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<NOT:$<CONFIG:Release>>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${vert_out_path}
COMMAND ${DXC} -T ps_6_5 -E frag -Vn ${filename}_frag $<$<CONFIG:Debug>:-O0> $<$<NOT:$<CONFIG:Release>>:-Zi> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<NOT:$<CONFIG:Release>>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${frag_out_path}
MAIN_DEPENDENCY ${shader}
DEPENDS ${shader_includes}
)
Expand All @@ -193,8 +209,8 @@ function(cook_shaders out_shader_sources out_shader_headers)
add_custom_command(
OUTPUT ${out_paths}
COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path}
COMMAND ${DXC} -T ms_6_5 -E mesh -Vn ${filename}_mesh $<$<CONFIG:Debug>:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<CONFIG:Debug>:-Zi> $<$<CONFIG:Debug>:-Qembed_debug> -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${mesh_out_path}
COMMAND ${DXC} -T ps_6_5 -E frag -Vn ${filename}_frag $<$<CONFIG:Debug>:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<CONFIG:Debug>:-Zi> $<$<CONFIG:Debug>:-Qembed_debug> -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${frag_out_path}
COMMAND ${DXC} -T ms_6_5 -E mesh -Vn ${filename}_mesh $<$<CONFIG:Debug>:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<NOT:$<CONFIG:Release>>:-Zi> $<$<NOT:$<CONFIG:Release>>:-Qembed_debug> -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${mesh_out_path}
COMMAND ${DXC} -T ps_6_5 -E frag -Vn ${filename}_frag $<$<CONFIG:Debug>:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<NOT:$<CONFIG:Release>>:-Zi> $<$<NOT:$<CONFIG:Release>>:-Qembed_debug> -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${frag_out_path}
MAIN_DEPENDENCY ${shader}
DEPENDS ${shader_includes}
)
Expand All @@ -214,7 +230,7 @@ function(cook_shaders out_shader_sources out_shader_headers)
add_custom_command(
OUTPUT ${out_paths}
COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path}
COMMAND ${DXC} -T cs_6_5 -E comp -Vn ${filename}_comp $<$<CONFIG:Debug>:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<CONFIG:Debug>:-Zi> $<$<CONFIG:Debug>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${comp_out_path}
COMMAND ${DXC} -T cs_6_5 -E comp -Vn ${filename}_comp $<$<CONFIG:Debug>:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$<NOT:$<CONFIG:Release>>:-Zi> $<$<NOT:$<CONFIG:Release>>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${comp_out_path}
MAIN_DEPENDENCY ${shader}
DEPENDS ${shader_includes}
)
Expand Down Expand Up @@ -257,7 +273,7 @@ function(cook_assets target_name out_assets_path)
add_custom_command(
OUTPUT ${packed_scene}
COMMAND ${CMAKE_COMMAND} -E make_directory assets/${relpath}
COMMAND ${GLTFPACK} -cc -mi -kn -km -ke -tc -i ${scene} -o ${packed_scene}
COMMAND ${GLTFPACK} -cc -kn -km -ke -tc -i ${scene} -o ${packed_scene}
MAIN_DEPENDENCY ${scene}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>
)
Expand Down Expand Up @@ -357,9 +373,6 @@ add_library(toybox OBJECT ${lib_source})
# We provide a cross platform blocks runtime so we can use this
target_compile_options(toybox PUBLIC -fblocks)

# We rely on gnu statement expressions
target_compile_options(toybox PUBLIC -Wno-gnu-statement-expression)

if(WIN32)
# This really only matters for clang-cl
# ${CMAKE_C_COMPILER_ID} being MSVC would fail the above check
Expand All @@ -376,8 +389,6 @@ if(WIN32)
# We use anonymous structs
target_compile_options(toybox PUBLIC -Wno-gnu-anonymous-struct)
target_compile_options(toybox PUBLIC -Wno-nested-anon-types)
# Flecs uses '$' in identifiers as part of a DSL so this gets in the way
target_compile_options(toybox PUBLIC -Wno-dollar-in-identifier-extension)

elseif(ANDROID)
if(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "arm")
Expand Down Expand Up @@ -407,7 +418,7 @@ execute_process(COMMAND git log -1 --format=%h

# Generate config header
set(engine_config_include_dir ${CMAKE_CURRENT_BINARY_DIR}/config)
configure_file(source/config.h.in ${engine_config_include_dir}/tbengineconfig.h @ONLY)
configure_file(source/config.h.in ${engine_config_include_dir}/tb_engine_config.h @ONLY)

target_include_directories(toybox PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include")
target_include_directories(toybox PUBLIC "source/" "${CGLTF_INCLUDE_DIRS}" "${engine_config_include_dir}")
Expand Down
Loading

0 comments on commit a497360

Please sign in to comment.