Skip to content

Hlsl path tracer example #863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 158 commits into
base: hlsl_bxdfs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
995f170
HLSL RayTracing Compilation
Jan 21, 2025
1f3b397
Ray Tracing Pipeline creation
Jan 21, 2025
3ce37d1
Implement binding Ray Tracing Pipeline command
Jan 21, 2025
e44b8d5
Implement trace rays command
Jan 21, 2025
aa31421
Fix specializatio for ray tracing shaders
Jan 21, 2025
3592cb5
Add Validation to ray tracing pipeline creation
Jan 21, 2025
7757888
Implement Intersection Shader
Jan 21, 2025
d207add
Change order of shader groups in params to be consistent with TraceRays
Jan 24, 2025
26f4c3f
Fix buffer creation log
Jan 24, 2025
8595c88
Add more validation to ray tracing pipeline creation
Jan 25, 2025
02d6d0f
initial example
keptsecret Feb 4, 2025
b027bde
Remove unnecessarry command
Feb 5, 2025
53f27f0
Refactor casting pipeline bind point
Feb 5, 2025
ee5bcf9
Use static constexpr for shaderGroupHandleSize
Feb 5, 2025
64792a8
Fix indentation.
Feb 5, 2025
19dfc84
Remove unnecessary colon
Feb 5, 2025
c9bd800
Refactor SShaderGroupParams to use span and remove it from SCachedParams
Feb 5, 2025
98c29b5
Remove SStridedBufferRegion. Use SBufferRange + stride instead.
Feb 6, 2025
129b50e
use bxdf creation params struct
keptsecret Feb 6, 2025
98025d3
Add more validation to TraceRays
Feb 6, 2025
74261dc
triangle and rectangle shapes
keptsecret Feb 7, 2025
ab3ae20
more sampling methods
keptsecret Feb 10, 2025
355cfec
spherical rectangle
keptsecret Feb 11, 2025
e9ed9e2
Implement set ray tracing pipeline stack size
Feb 11, 2025
64a8760
Implement TraceRaysIndirect
Feb 11, 2025
889ebe3
Fix TraceRays command parameter
Feb 11, 2025
ebf8fca
merge pcg fix from upstream
keptsecret Feb 12, 2025
32b6af7
Remove unnecessary include
Feb 12, 2025
62974ca
windows isDebuggerAttached variant
YasInvolved Feb 12, 2025
a8586e7
linux variant of nbl::system::isDebuggerAttached
YasInvolved Feb 14, 2025
11180f4
fix aniso cache bug
keptsecret Feb 17, 2025
4516051
init func to modify bxdf params directly
keptsecret Feb 18, 2025
fe75310
move definition and implementation to ISystem.h and ISystem.cpp
YasInvolved Feb 19, 2025
bede820
correct spotted copy/paste errors from older code
YasInvolved Feb 19, 2025
1ed7353
fix other mistakes in linux implementation (lack of 2nd argument in o…
YasInvolved Feb 19, 2025
4b8faf0
removed testing std::cout
YasInvolved Feb 19, 2025
d9a00c9
bug fixes
keptsecret Feb 20, 2025
ffe9029
fix sampling bugs #2
keptsecret Feb 21, 2025
cee192e
update to master
keptsecret Feb 21, 2025
b207312
fix rank type trait for matrix/vector
keptsecret Feb 21, 2025
5839ddf
added -fconstexpr-ops-limit for gcc
YasInvolved Feb 21, 2025
673f788
merge hlsl bxdfs, resolve conflict
keptsecret Feb 25, 2025
5effecd
Fix indentation
Feb 25, 2025
b5b9a7b
Fix bound pipeline don't disturb each other.
Feb 25, 2025
69a257d
temporary fix for dxc bug issue 7154
keptsecret Feb 25, 2025
fc9917d
Remove pipeline binding point from Pipeline class
Feb 25, 2025
98e1ef4
Move SShaderGroupParams to IRayTracingPipelineBase
Feb 25, 2025
4bed175
Rename parameter named binding to indirectBinding
Feb 25, 2025
bc968dc
Use ShaderGroupHandle instead of span of uint_t
Feb 25, 2025
6fe78d1
Merge branch 'master' into raytracing_pipeline
Feb 25, 2025
a60dbc6
Remove unnecessary include
Feb 25, 2025
c9b2fc6
Remove replay flag from ray tracing pipeline
Feb 25, 2025
866e6d7
some bug fixes again
keptsecret Feb 26, 2025
85e955f
fix wrong template usage
keptsecret Feb 27, 2025
d480405
Move SShaderGroupHandle to IGPURayTracingPipeline
Feb 27, 2025
3b167ab
merge changes from hlsl_bxdf
keptsecret Feb 28, 2025
19e3a35
merge master/bxdf fixes, resolve conflicts
keptsecret Mar 3, 2025
6c6b709
Remove shader handles query in CVulkanRayTracingPipeline
Mar 3, 2025
5114b09
Add space between group params and cached creation params for better …
Mar 3, 2025
3f0962c
Improve ShaderGroupParams naming
Mar 3, 2025
a03701f
Improve checking for shader stage
Mar 3, 2025
44b450e
Improve get group count method
Mar 3, 2025
9286a71
Fix maxShaderGroup calculation
Mar 3, 2025
cc34962
Check that shaders is not empty
Mar 3, 2025
41ffc50
Check for maxShaderGroupStride compliance
Mar 3, 2025
6b5bf06
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 4, 2025
7b574da
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 4, 2025
1c773d9
fix typo
keptsecret Mar 4, 2025
78e14d3
New lock draft
Fletterio Mar 4, 2025
6b7bf1f
Use lock-free atomics
Fletterio Mar 4, 2025
326c885
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 5, 2025
6132a4e
Merge branch 'revert-some-device-limits' into hlsl_path_tracer_example
keptsecret Mar 6, 2025
0bd26c7
Merge branch 'master' into hlsl_path_tracer_example
keptsecret Mar 6, 2025
ebb1b15
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 7, 2025
7cb977d
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 7, 2025
2660db4
Add sanity checks to new locks, address PR review comments
Fletterio Mar 7, 2025
67c525e
Merge branch 'master' into hlsl_path_tracer_example
keptsecret Mar 10, 2025
cff672c
Add more validation for trace ray dimensions.
Mar 10, 2025
1db0c8f
Fix shader group buffer alignment validation.
Mar 10, 2025
b502404
Remove unecessary raygenGroupStride parameter.
Mar 10, 2025
85114be
Fix set stack size dynamic state handling.
Mar 10, 2025
20ab6d6
Add setRayTracingStackSize validation
Mar 10, 2025
8294f83
Convert traceRaysIndirect to use vkCmdTraceRaysIndirect2KHR.
Mar 10, 2025
e9ea6b9
Refactor to use a single generic loop
Fletterio Mar 11, 2025
a8f209e
Merge branch 'hlsl_bxdfs' into hlsl_path_tracer_example
keptsecret Mar 11, 2025
3a996fe
Checkpoint before adding debug callback to locks
Fletterio Mar 11, 2025
a6e2ffa
Add debug callbacks to new locks
Fletterio Mar 11, 2025
bb39dfb
Change some names to explicit when a debug callback is provided
Fletterio Mar 12, 2025
1a4d0e6
Add Skip triangles bit and skip aabbs bit as common flag.
Mar 12, 2025
b2188dc
Fix setRayTracingStackSize validation.
Mar 12, 2025
93405e9
Merge branch 'master' into raytracing_pipeline
Mar 12, 2025
ee1af5d
Improve some flags naming
Mar 12, 2025
1912cd2
Fix merging bug
Mar 12, 2025
240cfa1
Fix indirect Trace ray validation.
Mar 12, 2025
f22c4c0
Make the indirect buffer size check clearer.
Mar 12, 2025
1ed9fd7
Add Motion Blur validation.
Mar 12, 2025
7750418
Add comment on some validations
Mar 12, 2025
0fc7954
Add type alias for lock
Fletterio Mar 13, 2025
e8d2ed8
fixed some func usage to nbl ver
keptsecret Mar 14, 2025
3a18b05
Move creation flags to IRayTracingPipeline
Mar 14, 2025
82e0727
Comment out some flags and add some documentation on pipeline flags.
Mar 14, 2025
42b43a5
Add rayTracingValidation feature
Mar 14, 2025
52a636d
Add validation that rayTraversalPrimitiveCulling feaature is enabled …
Mar 14, 2025
14f5d35
Add more validation.
Mar 14, 2025
c47f446
specify template args
keptsecret Mar 17, 2025
642e46d
fix merge conflicts
keptsecret Mar 17, 2025
1137b6b
update to latest example
keptsecret Mar 17, 2025
9ed0945
Remove dead code
Mar 17, 2025
94cb188
Improve naming of hit group
Mar 17, 2025
266d0eb
Fix validation on raygen shaderGroup
Mar 17, 2025
bbcff69
Implement get ray tracing stack size api
Mar 17, 2025
67b5181
Change get shader group handle api to return span
Mar 17, 2025
2904e3e
Fix ray tracing capture replay feature enable logic
Mar 17, 2025
d79fe20
Remove unused code
Mar 17, 2025
c09154b
Fix ray tracing pipeline creation, by not skipping null shader instea…
Mar 17, 2025
c35d01a
Fix stack size calculation when the shader group is empty
Mar 18, 2025
3fd2e14
Add tea, lcg and pcg into nb::hlsl::random
Mar 18, 2025
5cd4e6c
merge math, fix conflict
keptsecret Mar 19, 2025
7e8dd81
latest example
keptsecret Mar 19, 2025
89e4340
Hide debug stages, fix callback creation and calling
Fletterio Mar 19, 2025
be5ef6b
use spirv intrinsic for dot
keptsecret Mar 20, 2025
cc5644c
Added dot HLSL specialization
Przemog1 Mar 20, 2025
95287fd
Moved fma function
Przemog1 Mar 20, 2025
f86dd0c
Merge remote-tracking branch 'origin/intrinsics_adjustments' into hls…
keptsecret Mar 21, 2025
b154638
fix use of static const in func
keptsecret Mar 21, 2025
abce704
Fix circular dependency in concepts/type_traits by pulling common stu…
Fletterio Mar 21, 2025
3bd30c9
Add new file to CMakeLists, register as builtin
Fletterio Mar 21, 2025
ec6a8d4
Merge pull request #857 from Devsh-Graphics-Programming/concepts_fix
devshgraphicsprogramming Mar 21, 2025
88a2228
LLVM_INCLUDE_UTILS OFF
AnastaZIuk Mar 23, 2025
7892563
added more morton order stuff
keptsecret Mar 24, 2025
1ae0d58
Fix make_unsigned
Fletterio Mar 24, 2025
ada51fa
build_info target
YasInvolved Mar 27, 2025
1ececaf
add missing include
YasInvolved Mar 27, 2025
b21b789
latest example
keptsecret Mar 28, 2025
22d9518
check if vulkan driver is present in the system, check if NBL_ROOT_PA…
YasInvolved Mar 28, 2025
957a726
Merge pull request #835 from Devsh-Graphics-Programming/yas_is_debugg…
AnastaZIuk Mar 31, 2025
a3d3675
Merge pull request #838 from Devsh-Graphics-Programming/yas_fconstexp…
AnastaZIuk Mar 31, 2025
44c507d
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla …
AnastaZIuk Mar 31, 2025
28ba56f
Merge pull request #803 from Devsh-Graphics-Programming/maths_for_bxd…
devshgraphicsprogramming Mar 31, 2025
679304c
Merge pull request #820 from kevyuu/raytracing_pipeline
devshgraphicsprogramming Mar 31, 2025
2b338b7
post merge submodule update
Mar 31, 2025
5e4ece7
update build info logic, generate caps info at configure time & git i…
AnastaZIuk Mar 31, 2025
3d2835e
Merge pull request #859 from Devsh-Graphics-Programming/yas_buildinfo
AnastaZIuk Mar 31, 2025
ff527f9
post merge correct docker/compiler-explorer submodule pointer
AnastaZIuk Mar 31, 2025
fb9d777
resolve my own comments on #820 and https://github.com/Devsh-Graphics…
Mar 31, 2025
f23f32f
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla
Mar 31, 2025
cca5e09
try to use inline SPIR-V for termination instructions but run into ht…
Mar 31, 2025
4322084
so we need a mutex per TLAS, a pending build counter and a completed …
Mar 31, 2025
b84fae1
BLASes referenced during a TLAS build (if provided) are recorded into…
Apr 1, 2025
5fc0da6
make the Host Acceleration Structure builds set
Apr 1, 2025
0264eac
Finish the TLAS->BLAS tracking for device builds.
Apr 1, 2025
4e43183
Merge pull request #861 from Devsh-Graphics-Programming/tlas_blas_tra…
devshgraphicsprogramming Apr 1, 2025
f6a69fe
Use FMA for unspecialized dot product in intrinsics_impl.hlsl
devshgraphicsprogramming Apr 1, 2025
3604d2c
Merge pull request #856 from Devsh-Graphics-Programming/intrinsics_ad…
devshgraphicsprogramming Apr 1, 2025
e4ab255
Merge pull request #845 from Devsh-Graphics-Programming/new_lock
Fletterio Apr 1, 2025
75c5b9f
added new dot partial spec
keptsecret Apr 2, 2025
23124c5
Merge pull request #864 from Devsh-Graphics-Programming/fix_dot_for_ints
devshgraphicsprogramming Apr 2, 2025
1f461ff
merge master, fix conflicts
keptsecret Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 3rdparty/dxc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCLANG_ENABLE_STATIC_ANALYZER:BOOL=OFF")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCLANG_INCLUDE_TESTS:BOOL=Off")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DLLVM_INCLUDE_TESTS:BOOL=Off")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DHLSL_INCLUDE_TESTS:BOOL=OFF")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DLLVM_INCLUDE_UTILS:BOOL=OFF")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DLLVM_TARGETS_TO_BUILD:STRING=None")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DLLVM_INCLUDE_DOCS:BOOL=OFF")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DLLVM_INCLUDE_TESTS:BOOL=OFF")
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ endif()

find_package(Vulkan)
if (Vulkan_FOUND)
message(STATUS "Building with Vulkan driver")
message(STATUS "Found Vulkan SDK")
cmake_path(GET Vulkan_INCLUDE_DIR PARENT_PATH VULKAN_SDK)
else()
message(STATUS "Vulkan driver is not enabled")
message(STATUS "Vulkan SDK is not found")
endif()

option(NBL_COMPILE_WITH_CUDA "Compile with CUDA interop?" OFF)
Expand Down Expand Up @@ -280,5 +281,5 @@ add_subdirectory(artifacts)

option(NBL_CPACK_INCLUDE_EXAMPLES "CPack with examples and media" ON)
include(cpack/package)

include(build/info)
export(TARGETS ${_NBL_3RDPARTY_TARGETS_} Nabla NAMESPACE Nabla:: APPEND FILE ${NBL_ROOT_PATH_BINARY}/NablaExport.cmake)
38 changes: 38 additions & 0 deletions cmake/build/info.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
include_guard(GLOBAL)

if (NOT DEFINED NBL_ROOT_PATH_BINARY)
message(FATAL_ERROR "NBL_ROOT_PATH_BINARY is not defined or it's empty")
endif()

if(NOT TARGET gtml)
message(FATAL_ERROR "gtml target not defined!")
endif()

set(OUTPUT_DIR "${NBL_ROOT_PATH_BINARY}")

if(Vulkan_FOUND)
set(VKSDK_INFO_CMD "${VULKAN_SDK}/bin/vulkaninfoSDK" -j -o "${OUTPUT_DIR}/vulkan-info.json")
else()
set(VKSDK_INFO_CMD "${CMAKE_COMMAND}" -E touch "${OUTPUT_DIR}/vulkan-info.json")
endif()

execute_process(COMMAND ${VKSDK_INFO_CMD})
execute_process(COMMAND "${CMAKE_COMMAND}" -E capabilities OUTPUT_VARIABLE PIPE)
file(WRITE "${OUTPUT_DIR}/cmake-caps.json" "${PIPE}")

get_target_property(GTML_SOURCES gtml SOURCES)
list(FILTER GTML_SOURCES INCLUDE REGEX "git_info\\.cpp$")

set(BUILD_INFO_DEPENDENCIES
"${OUTPUT_DIR}/vulkan-info.json"
"${OUTPUT_DIR}/cmake-caps.json"
CMakeCache.txt
CMakeFiles/CMakeConfigureLog.yaml
${GTML_SOURCES}
)

add_custom_target(nbl_build_info
DEPENDS ${BUILD_INFO_DEPENDENCIES} gtml
COMMAND "${CMAKE_COMMAND}" -E tar c build_info.zip --format=zip ${BUILD_INFO_DEPENDENCIES}
COMMENT "Generating \"${NBL_ROOT_PATH_BINARY}/build_info.zip\", attach this within your issue"
)
2 changes: 1 addition & 1 deletion examples_tests
Submodule examples_tests updated 45 files
+37 −0 31_HLSLPathTracer/CMakeLists.txt
+837 −0 31_HLSLPathTracer/app_resources/glsl/common.glsl
+182 −0 31_HLSLPathTracer/app_resources/glsl/litByRectangle.comp
+60 −0 31_HLSLPathTracer/app_resources/glsl/litBySphere.comp
+105 −0 31_HLSLPathTracer/app_resources/glsl/litByTriangle.comp
+356 −0 31_HLSLPathTracer/app_resources/hlsl/common.hlsl
+88 −0 31_HLSLPathTracer/app_resources/hlsl/intersector.hlsl
+173 −0 31_HLSLPathTracer/app_resources/hlsl/material_system.hlsl
+446 −0 31_HLSLPathTracer/app_resources/hlsl/next_event_estimator.hlsl
+319 −0 31_HLSLPathTracer/app_resources/hlsl/pathtracer.hlsl
+19 −0 31_HLSLPathTracer/app_resources/hlsl/present.frag.hlsl
+38 −0 31_HLSLPathTracer/app_resources/hlsl/rand_gen.hlsl
+82 −0 31_HLSLPathTracer/app_resources/hlsl/ray_gen.hlsl
+227 −0 31_HLSLPathTracer/app_resources/hlsl/render.comp.hlsl
+23 −0 31_HLSLPathTracer/app_resources/hlsl/render_common.hlsl
+111 −0 31_HLSLPathTracer/app_resources/hlsl/scene.hlsl
+28 −0 31_HLSLPathTracer/config.json.template
+17 −0 31_HLSLPathTracer/include/nbl/this_example/common.hpp
+1,431 −0 31_HLSLPathTracer/main.cpp
+50 −0 31_HLSLPathTracer/pipeline.groovy
+10 −14 66_HLSLBxDFTests/CMakeLists.txt
+0 −20 66_HLSLBxDFTests/app_resources/config.json
+0 −93 66_HLSLBxDFTests/app_resources/test_compile.comp.hlsl
+62 −984 66_HLSLBxDFTests/app_resources/tests.hlsl
+33 −229 66_HLSLBxDFTests/main.cpp
+37 −0 71_RayTracingPipeline/CMakeLists.txt
+11 −0 71_RayTracingPipeline/Readme.md
+396 −0 71_RayTracingPipeline/app_resources/common.hlsl
+11 −0 71_RayTracingPipeline/app_resources/light_directional.rcall.hlsl
+13 −0 71_RayTracingPipeline/app_resources/light_point.rcall.hlsl
+16 −0 71_RayTracingPipeline/app_resources/light_spot.rcall.hlsl
+19 −0 71_RayTracingPipeline/app_resources/present.frag.hlsl
+14 −0 71_RayTracingPipeline/app_resources/raytrace.rahit.hlsl
+20 −0 71_RayTracingPipeline/app_resources/raytrace.rchit.hlsl
+130 −0 71_RayTracingPipeline/app_resources/raytrace.rgen.hlsl
+47 −0 71_RayTracingPipeline/app_resources/raytrace.rint.hlsl
+7 −0 71_RayTracingPipeline/app_resources/raytrace.rmiss.hlsl
+16 −0 71_RayTracingPipeline/app_resources/raytrace_procedural.rchit.hlsl
+20 −0 71_RayTracingPipeline/app_resources/raytrace_shadow.rahit.hlsl
+8 −0 71_RayTracingPipeline/app_resources/raytrace_shadow.rmiss.hlsl
+ 71_RayTracingPipeline/docs/Images/final_result.png
+ 71_RayTracingPipeline/docs/Images/shader_binding_table.png
+97 −0 71_RayTracingPipeline/include/common.hpp
+1,865 −0 71_RayTracingPipeline/main.cpp
+3 −0 CMakeLists.txt
2 changes: 1 addition & 1 deletion include/nbl/asset/ECommonEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum E_PIPELINE_BIND_POINT : uint8_t
{
EPBP_GRAPHICS = 0,
EPBP_COMPUTE,

EPBP_RAY_TRACING,
EPBP_COUNT
};

Expand Down
49 changes: 31 additions & 18 deletions include/nbl/asset/IPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,57 @@ class IPipeline
// Compute Pipelines only
//DISPATCH_BASE = 1<<4,

// Weird extension
// This is for NV-raytracing extension. Now this is done via IDeferredOperation
//DEFER_COMPILE_NV = 1<<5,

CAPTURE_STATISTICS = 1<<6,
CAPTURE_INTERNAL_REPRESENTATIONS = 1<<7,
// We use Renderdoc to take care of this for us,
// we won't be parsing the statistics and internal representation ourselves.
//CAPTURE_STATISTICS = 1<<6,
//CAPTURE_INTERNAL_REPRESENTATIONS = 1<<7,

// We require Pipeline Cache Control feature so those are satisfied:
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkComputePipelineCreateInfo.html#VUID-VkComputePipelineCreateInfo-pipelineCreationCacheControl-02875
// Will soon be deprecated due to
// https://github.com/Devsh-Graphics-Programming/Nabla/issues/854
FAIL_ON_PIPELINE_COMPILE_REQUIRED = 1<<8,
EARLY_RETURN_ON_FAILURE = 1<<9,

LINK_TIME_OPTIMIZATION = 1<<10,
// Will be exposed later with the IPipelineLibrary asset implementation
// https://github.com/Devsh-Graphics-Programming/Nabla/issues/853
//LINK_TIME_OPTIMIZATION = 1<<10,

//Not Supported Yet
// Won't be exposed because we'll introduce Libraries as a separate object/asset-type
// https://github.com/Devsh-Graphics-Programming/Nabla/issues/853
//CREATE_LIBRARY = 1<<11,

// Ray Tracing Pipelines only
//RAY_TRACING_SKIP_TRIANGLES_BIT_KHR = 1<<12,
//RAY_TRACING_SKIP_AABBS_BIT_KHR = 1<<13,
//RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR = 1<<14,
//RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR = 1<<15,
//RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR = 1<<16,
//RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR = 1<<17,

// Not Supported Yet
//SKIP_BUILT_IN_PRIMITIVES = 1<<12,
//SKIP_AABBS = 1<<13,
//NO_NULL_ANY_HIT_SHADERS = 1<<14,
//NO_NULL_CLOSEST_HIT_SHADERS = 1<<15,
//NO_NULL_MISS_SHADERS = 1<<16,
//NO_NULL_INTERSECTION_SHADERS = 1<<17,

// There is a new Device Generated Commands extension with its own flag that will deprecate this
//INDIRECT_BINDABLE_NV = 1<<18,

// Ray Tracing Pipelines only
// For debug tools
//RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR = 1<<19,
//RAY_TRACING_ALLOW_MOTION_BIT_NV = 1<<20,

// Ray Tracing Pipelines only
//ALLOW_MOTION = 1<<20,

// Graphics Pipelineonly (we don't support subpass shading)
//RENDERING_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR = 1<<21,
//RENDERING_FRAGMENT_DENSITY_MAP_ATTACHMENT_BIT_EXT = 1<<22,

RETAIN_LINK_TIME_OPTIMIZATION_INFO = 1<<23,
// Will be exposed later with the IPipelineLibrary asset implementation
// https://github.com/Devsh-Graphics-Programming/Nabla/issues/853
//RETAIN_LINK_TIME_OPTIMIZATION_INFO = 1<<23,

// Ray Tracing Pipelines only
//RAY_TRACING_OPACITY_MICROMAP_BIT_EXT = 1<<24,

// Not supported yet, and we will move to dynamic rendering, so this might never be supported
//COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT = 1<<25,
//DEPTH_STENCIL_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT = 1<<26,

Expand All @@ -107,7 +119,8 @@ class IPipeline
inline const PipelineLayout* getLayout() const {return m_layout.get();}

protected:
inline IPipeline(core::smart_refctd_ptr<const PipelineLayout>&& _layout) : m_layout(std::move(_layout)) {}
inline IPipeline(core::smart_refctd_ptr<const PipelineLayout>&& _layout)
: m_layout(std::move(_layout)) {}

core::smart_refctd_ptr<const PipelineLayout> m_layout;
};
Expand Down
207 changes: 207 additions & 0 deletions include/nbl/asset/IRayTracingPipeline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
#ifndef _NBL_ASSET_I_RAY_TRACING_PIPELINE_H_INCLUDED_
#define _NBL_ASSET_I_RAY_TRACING_PIPELINE_H_INCLUDED_

#include "nbl/asset/IShader.h"
#include "nbl/asset/IPipeline.h"

#include <span>
#include <bit>
#include <type_traits>

namespace nbl::asset
{

class IRayTracingPipelineBase : public virtual core::IReferenceCounted
{
public:
struct SShaderGroupsParams
{
struct SIndex
{
constexpr static inline uint32_t Unused = 0xffFFffFFu;
uint32_t index = Unused;
};

struct SHitGroup
{
uint32_t closestHit = SIndex::Unused;
uint32_t anyHit = SIndex::Unused;
uint32_t intersection = SIndex::Unused;
};

SIndex raygen;
std::span<SIndex> misses;
std::span<SHitGroup> hits;
std::span<SIndex> callables;

inline uint32_t getShaderGroupCount() const
{
return 1 + hits.size() + misses.size() + callables.size();
}

};
using SGeneralShaderGroup = SShaderGroupsParams::SIndex;
using SHitShaderGroup = SShaderGroupsParams::SHitGroup;

struct SCachedCreationParams final
{
uint32_t maxRecursionDepth : 6 = 0;
uint32_t dynamicStackSize : 1 = false;
};
};

template<typename PipelineLayoutType, typename ShaderType>
class IRayTracingPipeline : public IPipeline<PipelineLayoutType>, public IRayTracingPipelineBase
{
using base_creation_params_t = IPipeline<PipelineLayoutType>::SCreationParams;
public:

using SGeneralShaderGroupContainer = core::smart_refctd_dynamic_array<SGeneralShaderGroup>;
using SHitShaderGroupContainer = core::smart_refctd_dynamic_array<SHitShaderGroup>;

struct SCreationParams : base_creation_params_t
{
public:
#define base_flag(F) static_cast<uint64_t>(base_creation_params_t::FLAGS::F)
enum class FLAGS : uint64_t
{
NONE = base_flag(NONE),
DISABLE_OPTIMIZATIONS = base_flag(DISABLE_OPTIMIZATIONS),
ALLOW_DERIVATIVES = base_flag(ALLOW_DERIVATIVES),
FAIL_ON_PIPELINE_COMPILE_REQUIRED = base_flag(FAIL_ON_PIPELINE_COMPILE_REQUIRED),
EARLY_RETURN_ON_FAILURE = base_flag(EARLY_RETURN_ON_FAILURE),
SKIP_BUILT_IN_PRIMITIVES = 1<<12,
SKIP_AABBS = 1<<13,
NO_NULL_ANY_HIT_SHADERS = 1<<14,
NO_NULL_CLOSEST_HIT_SHADERS = 1<<15,
NO_NULL_MISS_SHADERS = 1<<16,
NO_NULL_INTERSECTION_SHADERS = 1<<17,
ALLOW_MOTION = 1<<20,
};
#undef base_flag

protected:
using SpecInfo = ShaderType::SSpecInfo;
template<typename ExtraLambda>
inline bool impl_valid(ExtraLambda&& extra) const
{
if (!IPipeline<PipelineLayoutType>::SCreationParams::layout)
return false;

for (const auto info : shaders)
{
if (info.shader)
{
if (!extra(info))
return false;
const auto stage = info.shader->getStage();
if ((stage & ~ICPUShader::E_SHADER_STAGE::ESS_ALL_RAY_TRACING) != 0)
return false;
if (!std::has_single_bit<std::underlying_type_t<ICPUShader::E_SHADER_STAGE>>(stage))
return false;
}
else
{
// every shader must not be null. use SIndex::Unused to represent unused shader.
return false;
}
}

auto getShaderStage = [this](size_t index) -> ICPUShader::E_SHADER_STAGE
{
return shaders[index].shader->getStage();
};

auto isValidShaderIndex = [this, getShaderStage](size_t index, ICPUShader::E_SHADER_STAGE expectedStage, bool is_unused_shader_forbidden) -> bool
{
if (index == SShaderGroupsParams::SIndex::Unused)
return !is_unused_shader_forbidden;
if (index >= shaders.size())
return false;
if (getShaderStage(index) != expectedStage)
return false;
return true;
};

if (!isValidShaderIndex(shaderGroups.raygen.index, ICPUShader::E_SHADER_STAGE::ESS_RAYGEN, true))
{
return false;
}

for (const auto& shaderGroup : shaderGroups.hits)
{
// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkRayTracingPipelineCreateInfoKHR-flags-03470
if (!isValidShaderIndex(shaderGroup.anyHit,
ICPUShader::E_SHADER_STAGE::ESS_ANY_HIT,
bool(flags & FLAGS::NO_NULL_ANY_HIT_SHADERS)))
return false;

// https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkRayTracingPipelineCreateInfoKHR-flags-03471
if (!isValidShaderIndex(shaderGroup.closestHit,
ICPUShader::E_SHADER_STAGE::ESS_CLOSEST_HIT,
bool(flags & FLAGS::NO_NULL_CLOSEST_HIT_SHADERS)))
return false;

if (!isValidShaderIndex(shaderGroup.intersection,
ICPUShader::E_SHADER_STAGE::ESS_INTERSECTION,
false))
return false;
}

for (const auto& shaderGroup : shaderGroups.misses)
{
if (!isValidShaderIndex(shaderGroup.index,
ICPUShader::E_SHADER_STAGE::ESS_MISS,
false))
return false;
}

for (const auto& shaderGroup : shaderGroups.callables)
{
if (!isValidShaderIndex(shaderGroup.index, ICPUShader::E_SHADER_STAGE::ESS_CALLABLE, false))
return false;
}
return true;
}

public:
inline bool valid() const
{
return impl_valid([](const SpecInfo& info)->bool
{
if (!info.valid())
return false;
return false;
});
}

std::span<const SpecInfo> shaders = {};
SShaderGroupsParams shaderGroups;
SCachedCreationParams cached = {};
// TODO: Could guess the required flags from SPIR-V introspection of declared caps
core::bitflag<FLAGS> flags = FLAGS::NONE;
};

inline const SCachedCreationParams& getCachedCreationParams() const { return m_params; }

protected:
explicit IRayTracingPipeline(const SCreationParams& _params) :
IPipeline<PipelineLayoutType>(core::smart_refctd_ptr<const PipelineLayoutType>(_params.layout)),
m_params(_params.cached),
m_raygenShaderGroup(_params.shaderGroups.raygen),
m_missShaderGroups(core::make_refctd_dynamic_array<SGeneralShaderGroupContainer>(_params.shaderGroups.misses)),
m_hitShaderGroups(core::make_refctd_dynamic_array<SHitShaderGroupContainer>(_params.shaderGroups.hits)),
m_callableShaderGroups(core::make_refctd_dynamic_array<SGeneralShaderGroupContainer>(_params.shaderGroups.callables))
{}

SCachedCreationParams m_params;
SGeneralShaderGroup m_raygenShaderGroup;
SGeneralShaderGroupContainer m_missShaderGroups;
SHitShaderGroupContainer m_hitShaderGroups;
SGeneralShaderGroupContainer m_callableShaderGroups;

};

}

#endif
Loading