Skip to content

Commit

Permalink
[Release] Feature/raytracing (#208)
Browse files Browse the repository at this point in the history
* added basic raytracing husk

* base top level structure

* buildable acceleration structures

* rewritten descriptor storage to become more flexible

* write acceleration structure
write RW texture

* pipeline creation

* sbt

* RT works with DX12!

* RT works with Vulkan

* first triangle in RT, API beta wrapup

* Compute pipelines (untested)

* more compute commands, added proxies for vulkan

* typo

* small fix to flags

* flags

* desc storage fix

* test for srv buffers

* ok, they have to be raw

* ->structured buffers

* recursion depth, compiler flags for DXC

* fix for DXC

* finalized version

* Restyled Feature/raytracing (#209)

* Restyled by astyle

* Restyled by clang-format

* Restyled by cmake-format

* Restyled by prettier-markdown

* Restyled by whitespace

---------

Co-authored-by: Restyled.io <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2025
1 parent 8823a44 commit 4b315fb
Show file tree
Hide file tree
Showing 66 changed files with 5,304 additions and 1,216 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

cmake_minimum_required(VERSION 3.22)

set(WISDOM_VERSION "0.5.0")
set(WISDOM_VERSION "0.6.0")
project("Wisdom" VERSION ${WISDOM_VERSION})

set(CMAKE_DEBUG_POSTFIX d)
Expand Down
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Version History

- 0.6.0 Raytracing
- BREAKING: Revisited root signature and descriptor storage. Now it is possible to create roots with several same types of descriptors, binding tables are ordered accordingly.
- BREAKING: Root signature compatibility is now based on the input `DescriptorBindingDesc`. It is possible to create a root signature with different descriptor types, but that may result in incompatibility between root and descriptor storage.
- Added Raytracing support for DXR and VK_KHR_ray_tracing
- Added compute pipeline and compute functions to the device and command list
- Added more bindings to the Descriptor storage
- 0.5.0 API stabilization

- Most of the API is now stable and will not change
Expand Down
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

https://www.nuget.org/packages/Wisdom/

# Features

- [x] Raytracing support
- [x] Compute pipeline, Basic rendering and Multiview
- [x] Embedded DXC shader compiler and standard HLSL language
- [x] Inline API with no virtual functions.
- [x] Extensibility with internal state access
- [x] Advanced memory allocations
- [x] DMA copy support and ability to share memory between APIs

# Why?

A lot of old OpenGL solutions are scratching the ceiling of OpenGL potential, and Vulkan is too low-level for most of the tasks. DirectX 12 is a good alternative, but it's not cross-platform.
Expand Down Expand Up @@ -110,16 +120,3 @@ This type of project does not support Vulkan, since Vulkan does not have UWP sur
- Vulkan 1.3.2xx+

Video card driver should have Descriptor buffer support. Tested on NVIDIA RTX A4000.

# Roadmap

The project has Gitub projects enabled, so you can see the progress on the project.
For the roadmap, the following features are planned:

- [x] SDL3 examples
- [ ] UWP example
- [ ] Elaborate documentation
- [x] C API generation
- [ ] Debugging tools
- [ ] Small game engine
- [x] Lower CMake version requirement to 3.22
144 changes: 114 additions & 30 deletions bindings/wisdom.cpp

Large diffs are not rendered by default.

989 changes: 795 additions & 194 deletions bindings/wisdom.h

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ endfunction()
function(wis_compile_shader)
set(options )
set(oneValueArgs TARGET ENTRY SHADER OUTPUT TYPE SHADER_MODEL)
set(multiValueArgs INCLUDE_DIRS DEFINITIONS)
set(multiValueArgs INCLUDE_DIRS DEFINITIONS FLAGS)
cmake_parse_arguments(wis_compile_shader "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

Expand Down Expand Up @@ -152,7 +152,14 @@ function(wis_compile_shader)
list(APPEND DEFINES "-D${DEFINITION} ")
endforeach()

foreach(FLAG ${wis_compile_shader_FLAGS})
list(APPEND FLAGS "${FLAG} ")
endforeach()

#remove trailing space
string(STRIP "${INCLUDES}" INCLUDES)
string(STRIP "${DEFINES}" DEFINES)
string(STRIP "${FLAGS}" FLAGS)

set(SHADER ${wis_compile_shader_SHADER})
set(TARGET ${wis_compile_shader_TARGET})
Expand All @@ -178,15 +185,15 @@ function(wis_compile_shader)

if(WISDOM_WINDOWS)
add_custom_command(TARGET ${TARGET}
COMMAND "${dxc_EXECUTABLE}" -E${ENTRY} -T${TYPE}_${SHADER_MODEL} -Zi $<IF:$<CONFIG:DEBUG>,-Od,-O3> -Wno-ignored-attributes ${INCLUDES} ${DEFINES} -DDXIL=1 -Fo${OUTPUT_DXIL} -Fd${OUTPUT_PDB} ${SHADER}
COMMAND "${dxc_EXECUTABLE}" -E${ENTRY} -T${TYPE}_${SHADER_MODEL} -Zi $<IF:$<CONFIG:DEBUG>,-Od,-O3> -Wno-ignored-attributes ${FLAGS} ${INCLUDES} ${DEFINES} -DDXIL=1 -Fo${OUTPUT_DXIL} -Fd${OUTPUT_PDB} ${SHADER}
MAIN_DEPENDENCY ${SHADER}
COMMENT "HLSL ${SHADER}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM)
endif()

add_custom_command(TARGET ${TARGET}
COMMAND "${dxc_EXECUTABLE}" -E${ENTRY} -T${TYPE}_${SHADER_MODEL} -Zi $<IF:$<CONFIG:DEBUG>,-Od,-O3> -spirv -Wno-ignored-attributes -fspv-target-env=vulkan1.3 ${INCLUDES} ${DEFINES} -DSPIRV=1 -Fo${OUTPUT_SPV} ${SHADER}
COMMAND "${dxc_EXECUTABLE}" -E${ENTRY} -T${TYPE}_${SHADER_MODEL} -Zi $<IF:$<CONFIG:DEBUG>,-Od,-O3> -spirv -Wno-ignored-attributes ${FLAGS} -fspv-target-env=vulkan1.3 ${INCLUDES} ${DEFINES} -DSPIRV=1 -Fo${OUTPUT_SPV} ${SHADER}
MAIN_DEPENDENCY ${SHADER}
COMMENT "SPV ${SHADER}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
14 changes: 11 additions & 3 deletions cmake/wisdom-deps.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ endfunction()
function(wis_compile_shader)
set(options )
set(oneValueArgs DXC TARGET ENTRY SHADER OUTPUT TYPE SHADER_MODEL)
set(multiValueArgs INCLUDE_DIRS DEFINITIONS)
set(multiValueArgs INCLUDE_DIRS DEFINITIONS FLAGS)
cmake_parse_arguments(wis_compile_shader "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

Expand Down Expand Up @@ -145,6 +145,14 @@ function(wis_compile_shader)
list(APPEND DEFINES "-D${DEFINITION} ")
endforeach()

foreach(FLAG ${wis_compile_shader_FLAGS})
list(APPEND FLAGS "${FLAG} ")
endforeach()

#remove trailing space
string(STRIP "${INCLUDES}" INCLUDES)
string(STRIP "${DEFINES}" DEFINES)
string(STRIP "${FLAGS}" FLAGS)


set(SHADER ${wis_compile_shader_SHADER})
Expand All @@ -171,15 +179,15 @@ function(wis_compile_shader)

if(WIN32)
add_custom_command(TARGET ${TARGET}
COMMAND "${wis_compile_shader_DXC}" -E${ENTRY} -T${TYPE}_${SHADER_MODEL} -Zi $<IF:$<CONFIG:DEBUG>,-Od,-O3> -Wno-ignored-attributes ${INCLUDES} ${DEFINES} -DDXIL=1 -Fo${OUTPUT_DXIL} -Fd${OUTPUT_PDB} ${SHADER}
COMMAND "${wis_compile_shader_DXC}" -E${ENTRY} -T${TYPE}_${SHADER_MODEL} -Zi $<IF:$<CONFIG:DEBUG>,-Od,-O3> -Wno-ignored-attributes ${FLAGS} ${INCLUDES} ${DEFINES} -DDXIL=1 -Fo${OUTPUT_DXIL} -Fd${OUTPUT_PDB} ${SHADER}
MAIN_DEPENDENCY ${SHADER}
COMMENT "HLSL ${SHADER}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM)
endif()

add_custom_command(TARGET ${TARGET}
COMMAND "${wis_compile_shader_DXC}" -E${ENTRY} -T${TYPE}_${SHADER_MODEL} -Zi $<IF:$<CONFIG:DEBUG>,-Od,-O3> -spirv -Wno-ignored-attributes -fspv-target-env=vulkan1.3 ${INCLUDES} ${DEFINES} -DSPIRV=1 -Fo${OUTPUT_SPV} ${SHADER}
COMMAND "${wis_compile_shader_DXC}" -E${ENTRY} -T${TYPE}_${SHADER_MODEL} -Zi $<IF:$<CONFIG:DEBUG>,-Od,-O3> -spirv -Wno-ignored-attributes ${FLAGS} -fspv-target-env=vulkan1.3 ${INCLUDES} ${DEFINES} -DSPIRV=1 -Fo${OUTPUT_SPV} ${SHADER}
MAIN_DEPENDENCY ${SHADER}
COMMENT "SPV ${SHADER}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
2 changes: 1 addition & 1 deletion cmake/wisdom.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ClCompile>

<Link>
<AdditionalDependencies Condition="'$(WisdomLinkage)' == 'static'">$(MSBuildThisFileDirectory)..\..\lib\wisdom-debug$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\wisdom-windows$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\wisdom-extended-allocation$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\wisdom-dx12$(LP).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(WisdomLinkage)' == 'static'">$(MSBuildThisFileDirectory)..\..\lib\wisdom-debug$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\wisdom-windows$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\wisdom-extended-allocation$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\wisdom-dx12$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\wisdom-raytacing$(LP).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(WisdomVulkanEnabled)' == 'true'"> $(MSBuildThisFileDirectory)..\..\lib\VKAllocator$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\wisdom-vk$(LP).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies> $(MSBuildThisFileDirectory)..\..\lib\DX12Allocator$(LP).lib;$(MSBuildThisFileDirectory)..\..\lib\DX12Agility$(LP).lib;dxguid.lib;DXGI.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
Expand Down
1 change: 1 addition & 0 deletions examples/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ add_subdirectory(shaders)
add_example(lut)
add_example(multiview)
add_example(descriptor_storage)
add_example(raytracing)
18 changes: 9 additions & 9 deletions examples/basic/descriptor_storage/entry_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ class App
std::construct_at(&swap, setup.device, std::move(swapx), w, h);
cmd_list = setup.CreateLists();

// Only a single descriptor table with 1 descriptor
wis::DescriptorStorageDesc desc{
.cbuffer_count = ex::flight_frames * 2, // one cbuffer per frame
.memory = wis::DescriptorMemory::ShaderVisible, // visible to shaders
wis::DescriptorBindingDesc bindings[] = {
{ .binding_type = wis::DescriptorType::ConstantBuffer, .binding_space = 1, .binding_count = ex::flight_frames * 2 },
};
desc_storage = setup.device.CreateDescriptorStorage(result, desc);
desc_storage = setup.device.CreateDescriptorStorage(result, bindings, std::size(bindings));
}

public:
Expand Down Expand Up @@ -189,8 +187,10 @@ class App
wis::PushConstant root_constants[]{
{ .stage = wis::ShaderStages::All, .size_bytes = 2 * sizeof(uint32_t) }
};
root = ex::Unwrap(setup.device.CreateRootSignature(root_constants, std::size(root_constants), nullptr, 0, 2));
// Note the 2 in the CreateRootSignature call. This is the space overlap count, which is 2 in this case.
wis::DescriptorBindingDesc bindings[] = {
{ .binding_type = wis::DescriptorType::ConstantBuffer, .binding_space = 1, .space_overlap_count = 2, .binding_count = ex::flight_frames * 2 },
};
root = ex::Unwrap(setup.device.CreateRootSignature(root_constants, std::size(root_constants), nullptr, 0, bindings, std::size(bindings)));

// Create pipeline
{
Expand Down Expand Up @@ -233,8 +233,8 @@ class App
for (size_t i = 0; i < ex::flight_frames; i++) {
constant_buffersx[i] = ex::Unwrap(setup.allocator.CreateBuffer(sizeof(float), wis::BufferUsage::CopySrc | wis::BufferUsage::ConstantBuffer, wis::MemoryType::Upload, wis::MemoryFlags::Mapped));
constant_buffersy[i] = ex::Unwrap(setup.allocator.CreateBuffer(sizeof(float), wis::BufferUsage::CopySrc | wis::BufferUsage::ConstantBuffer, wis::MemoryType::Upload, wis::MemoryFlags::Mapped));
desc_storage.WriteConstantBuffer(i, constant_buffersx[i], sizeof(float));
desc_storage.WriteConstantBuffer(ex::flight_frames + i, constant_buffersy[i], sizeof(float));
desc_storage.WriteConstantBuffer(0, i, constant_buffersx[i], sizeof(float));
desc_storage.WriteConstantBuffer(0, ex::flight_frames + i, constant_buffersy[i], sizeof(float));
constant_datax[i] = static_cast<float*>(constant_buffersx[i].Map());
constant_datax[i][0] = 0.0f;

Expand Down
19 changes: 13 additions & 6 deletions examples/basic/multiview/entry_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ class App
cmd_list = setup.CreateLists();
cmd_list2 = setup.CreateLists();

desc_storage = ex::Unwrap(setup.device.CreateDescriptorStorage({ .sampler_count = 1,
.texture_count = ex::flight_frames,
.memory = wis::DescriptorMemory::ShaderVisible }));
wis::DescriptorBindingDesc bindings[] = {
{ .binding_type = wis::DescriptorType::Texture, .binding_space = 1, .binding_count = ex::flight_frames },
{ .binding_type = wis::DescriptorType::Sampler, .binding_space = 2, .binding_count = 1 },
};
desc_storage = setup.device.CreateDescriptorStorage(result, bindings, std::size(bindings));
}

public:
Expand Down Expand Up @@ -287,10 +289,15 @@ class App

// Create root signature with
{
wis::Result result = wis::success;
wis::PushConstant root_constants[]{
{ .stage = wis::ShaderStages::Pixel, .size_bytes = sizeof(uint32_t) }
};
root = ex::Unwrap(setup.device.CreateRootSignature(root_constants, 1, nullptr, 0, 2));
wis::DescriptorBindingDesc bindings[] = {
{ .binding_type = wis::DescriptorType::Texture, .binding_space = 1, .binding_count = ex::flight_frames }, // space 0 is for root constants
{ .binding_type = wis::DescriptorType::Sampler, .binding_space = 2, .binding_count = 1 },
};
root = setup.device.CreateRootSignature(result, root_constants, 1, nullptr, 0, bindings, std::size(bindings));
}

// Create pipeline
Expand Down Expand Up @@ -376,13 +383,13 @@ class App
.comparison_op = wis::Compare::None,
};
sampler = ex::Unwrap(setup.device.CreateSampler(sample_desc));
desc_storage.WriteSampler(0, sampler);
desc_storage.WriteSampler(1, 0, sampler);
}

// fill desc buffer
{
for (uint32_t i = 0; i < ex::flight_frames; i++) {
desc_storage.WriteTexture(i, srvs[i]);
desc_storage.WriteTexture(0, i, srvs[i]);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions examples/basic/raytracing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project(raytracing-${POSTFIX})

set(HEADERS)
set(SOURCES entry_main.cpp)

add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PUBLIC common-${POSTFIX})
add_dependencies(${PROJECT_NAME} compile_shaders_basic)
set_target_properties(
${PROJECT_NAME} PROPERTIES CXX_STANDARD 20 RUNTIME_OUTPUT_DIRECTORY
${EXAMPLE_BIN_OUTPUT})

if(POSTFIX STREQUAL "dx12")
wis_make_exports_dx(${PROJECT_NAME}) # install the d3d12 agility sdk, for
# examples this is enough
# for the main project, use wis_installdeps(${PROJECT_NAME}) instead
endif()
Loading

0 comments on commit 4b315fb

Please sign in to comment.