├── .github └── workflows │ └── cla.yml ├── .gitignore ├── .gitmodules ├── CLA.txt ├── CMakeLists.txt ├── KickstartRT_demo ├── CMakeLists.txt ├── KickstartRT_Composite.cpp ├── KickstartRT_Composite.h └── KickstartRT_Sample_Main.cpp ├── LICENSE.txt ├── README.md ├── ThirdPartyLicenses.txt ├── cmake ├── FindDXCdxil.cmake ├── FindDXCspirv.cmake └── FindFXC.cmake ├── compileshaders.cmake ├── donut-app.cmake ├── donut-core.cmake ├── donut-engine.cmake ├── donut-render.cmake ├── donut.natvis ├── include └── donut │ ├── app │ ├── ApplicationBase.h │ ├── Camera.h │ ├── DeviceManager.h │ ├── MediaFileSystem.h │ ├── Timer.h │ ├── UserInterfaceUtils.h │ ├── imgui_console.h │ ├── imgui_nvrhi.h │ └── imgui_renderer.h │ ├── core │ ├── chunk │ │ ├── chunk.h │ │ └── chunkFile.h │ ├── circular_buffer.h │ ├── json.h │ ├── log.h │ ├── math │ │ ├── affine.h │ │ ├── basics.h │ │ ├── box.h │ │ ├── color.h │ │ ├── frustum.h │ │ ├── math.h │ │ ├── matrix.h │ │ ├── quat.h │ │ ├── sphere.h │ │ └── vector.h │ ├── string_utils.h │ └── vfs │ │ ├── Compression.h │ │ ├── TarFile.h │ │ ├── VFS.h │ │ ├── WinResFS.h │ │ └── ZipFile.h │ ├── engine │ ├── AudioCache.h │ ├── AudioEngine.h │ ├── BindingCache.h │ ├── CommonRenderPasses.h │ ├── ConsoleInterpreter.h │ ├── ConsoleObjects.h │ ├── DDSFile.h │ ├── DescriptorTableManager.h │ ├── FramebufferFactory.h │ ├── GltfImporter.h │ ├── IesProfile.h │ ├── KeyframeAnimation.h │ ├── MaterialBindingCache.h │ ├── Scene.h │ ├── SceneGraph.h │ ├── SceneTypes.h │ ├── ShaderFactory.h │ ├── ShadowMap.h │ ├── TextureCache.h │ └── View.h │ ├── render │ ├── BloomPass.h │ ├── CascadedShadowMap.h │ ├── DeferredLightingPass.h │ ├── DepthPass.h │ ├── DrawStrategy.h │ ├── EnvironmentMapPass.h │ ├── ForwardShadingPass.h │ ├── GBuffer.h │ ├── GBufferFillPass.h │ ├── GeometryPasses.h │ ├── JointsRenderPass.h │ ├── LightProbeProcessingPass.h │ ├── MipMapGenPass.h │ ├── PixelReadbackPass.h │ ├── PlanarShadowMap.h │ ├── SkyPass.h │ ├── SsaoPass.h │ ├── TemporalAntiAliasingPass.h │ └── ToneMappingPasses.h │ └── shaders │ ├── bindless.h │ ├── blit_cb.h │ ├── bloom_cb.h │ ├── brdf.hlsli │ ├── deferred_lighting_cb.h │ ├── depth_cb.h │ ├── forward_cb.h │ ├── forward_vertex.hlsli │ ├── gbuffer.hlsli │ ├── gbuffer_cb.h │ ├── light_cb.h │ ├── light_probe_cb.h │ ├── light_types.h │ ├── lighting.hlsli │ ├── material_bindings.hlsli │ ├── material_cb.h │ ├── mipmapgen_cb.h │ ├── motion_vectors.hlsli │ ├── packing.hlsli │ ├── pixel_readback_cb.h │ ├── scene_material.hlsli │ ├── shadows.hlsli │ ├── skinning_cb.h │ ├── sky.hlsli │ ├── sky_cb.h │ ├── ssao_cb.h │ ├── surface.hlsli │ ├── taa_cb.h │ ├── tonemapping_cb.h │ ├── utils.hlsli │ ├── view_cb.h │ └── vulkan.hlsli ├── scripts ├── lz4_tar.py └── mat_to_gltf.py ├── shaders ├── CMakeLists.txt ├── DonutShaders.cfg ├── app │ └── KickStart_Composite_cs.hlsl ├── blit_ps.hlsl ├── fullscreen_vs.hlsl ├── ies_profile_cs.hlsl ├── imgui_pixel.hlsl ├── imgui_vertex.hlsl ├── passes │ ├── bloom_ps.hlsl │ ├── cubemap_gs.hlsl │ ├── deferred_lighting_cs.hlsl │ ├── depth_ps.hlsl │ ├── depth_vs.hlsl │ ├── environment_map_ps.hlsl │ ├── exposure_cs.hlsl │ ├── forward_ps.hlsl │ ├── forward_vs.hlsl │ ├── gbuffer_ps.hlsl │ ├── gbuffer_vs.hlsl │ ├── histogram_cs.hlsl │ ├── joints.hlsl │ ├── light_probe.hlsl │ ├── material_id_ps.hlsl │ ├── mipmapgen_cs.hlsl │ ├── motion_vectors_ps.hlsl │ ├── pixel_readback_cs.hlsl │ ├── sky_ps.hlsl │ ├── ssao_blur_cs.hlsl │ ├── ssao_compute_cs.hlsl │ ├── ssao_deinterleave_cs.hlsl │ ├── taa_cs.hlsl │ └── tonemapping_ps.hlsl ├── rect_vs.hlsl ├── sharpen_ps.hlsl └── skinning_cs.hlsl ├── signatures └── CLA.json ├── src ├── app │ ├── ApplicationBase.cpp │ ├── Camera.cpp │ ├── DeviceManager.cpp │ ├── MediaFileSystem.cpp │ ├── UserInterfaceUtils.cpp │ ├── dx11 │ │ └── DeviceManager_DX11.cpp │ ├── dx12 │ │ └── DeviceManager_DX12.cpp │ ├── imgui_console.cpp │ ├── imgui_nvrhi.cpp │ ├── imgui_renderer.cpp │ └── vulkan │ │ └── DeviceManager_VK.cpp ├── core │ ├── chunk │ │ ├── chunkDescs.h │ │ ├── chunkFile.cpp │ │ ├── chunkReader.cpp │ │ └── chunkWriter.cpp │ ├── json.cpp │ ├── log.cpp │ ├── math │ │ ├── color.cpp │ │ ├── frustum.cpp │ │ ├── matrix.cpp │ │ └── vector.cpp │ ├── string_utils.cpp │ └── vfs │ │ ├── Compression.cpp │ │ ├── TarFile.cpp │ │ ├── VFS.cpp │ │ ├── WinResFS.cpp │ │ └── ZipFile.cpp ├── engine │ ├── AudioCache.cpp │ ├── AudioEngine.cpp │ ├── BindingCache.cpp │ ├── CommonRenderPasses.cpp │ ├── ConsoleInterpreter.cpp │ ├── ConsoleObjects.cpp │ ├── DDSFile.cpp │ ├── DescriptorTableManager.cpp │ ├── FramebufferFactory.cpp │ ├── GltfImporter.cpp │ ├── IesProfile.cpp │ ├── KeyframeAnimation.cpp │ ├── Material.cpp │ ├── MaterialBindingCache.cpp │ ├── Scene.cpp │ ├── SceneGraph.cpp │ ├── SceneTypes.cpp │ ├── ShaderFactory.cpp │ ├── TextureCache.cpp │ ├── View.cpp │ ├── dds.h │ └── stb_impl.c └── render │ ├── BloomPass.cpp │ ├── CascadedShadowMap.cpp │ ├── DeferredLightingPass.cpp │ ├── DepthPass.cpp │ ├── DrawStrategy.cpp │ ├── EnvironmentMapPass.cpp │ ├── ForwardShadingPass.cpp │ ├── GBuffer.cpp │ ├── GBufferFillPass.cpp │ ├── GeometryPasses.cpp │ ├── JointsRenderPass.cpp │ ├── LightProbeProcessingPass.cpp │ ├── MipMapGenPass.cpp │ ├── PixelReadbackPass.cpp │ ├── PlanarShadowMap.cpp │ ├── SkyPass.cpp │ ├── SsaoPass.cpp │ ├── TemporalAntiAliasingPass.cpp │ └── ToneMappingPasses.cpp ├── tests ├── CMakeLists.txt ├── include │ └── donut │ │ └── tests │ │ └── utils.h ├── src │ ├── core │ │ ├── test_circular_buffer.cpp │ │ ├── test_string_utils.cpp │ │ └── test_vfs.cpp │ ├── engine │ │ ├── test_console_interpreter.cpp │ │ └── test_console_objects.cpp │ └── utils.cpp ├── test-core.cmake └── test-engine.cmake └── thirdparty ├── CMakeLists.txt ├── imgui.cmake ├── jsoncpp.cmake ├── lz4.cmake ├── taskflow ├── LICENSE ├── README.txt └── taskflow │ ├── core │ ├── algorithm │ │ ├── critical.hpp │ │ ├── for_each.hpp │ │ ├── reduce.hpp │ │ └── sort.hpp │ ├── declarations.hpp │ ├── environment.hpp │ ├── error.hpp │ ├── executor.hpp │ ├── flow_builder.hpp │ ├── graph.hpp │ ├── notifier.hpp │ ├── observer.hpp │ ├── semaphore.hpp │ ├── task.hpp │ ├── taskflow.hpp │ ├── topology.hpp │ ├── tsq.hpp │ └── worker.hpp │ ├── cublasflow.hpp │ ├── cuda │ ├── cublas │ │ ├── cublas_error.hpp │ │ ├── cublas_flow.hpp │ │ ├── cublas_handle.hpp │ │ ├── cublas_helper.hpp │ │ ├── cublas_level1.hpp │ │ ├── cublas_level2.hpp │ │ └── cublas_level3.hpp │ ├── cuda_algorithm │ │ ├── cuda_for_each.hpp │ │ ├── cuda_matmul.hpp │ │ ├── cuda_reduce.hpp │ │ ├── cuda_transform.hpp │ │ └── cuda_transpose.hpp │ ├── cuda_capturer.hpp │ ├── cuda_device.hpp │ ├── cuda_error.hpp │ ├── cuda_flow.hpp │ ├── cuda_graph.hpp │ ├── cuda_memory.hpp │ ├── cuda_optimizer.hpp │ ├── cuda_pool.hpp │ ├── cuda_stream.hpp │ └── cuda_task.hpp │ ├── cudaflow.hpp │ ├── dsl │ ├── connection.hpp │ ├── dsl.hpp │ ├── meta_macro.hpp │ ├── task_analyzer.hpp │ ├── task_dsl.hpp │ ├── task_trait.hpp │ ├── tuple_utils.hpp │ └── type_list.hpp │ ├── sycl │ ├── sycl_algorithm │ │ ├── sycl_for_each.hpp │ │ ├── sycl_reduce.hpp │ │ └── sycl_transform.hpp │ ├── sycl_flow.hpp │ ├── sycl_graph.hpp │ └── sycl_task.hpp │ ├── syclflow.hpp │ ├── taskflow.hpp │ ├── tensorframe │ ├── tensor.hpp │ ├── tensor_expr.hpp │ ├── tensor_graph.hpp │ ├── tensor_ops.hpp │ └── tensorframe.hpp │ └── utility │ ├── iterator.hpp │ ├── math.hpp │ ├── object_pool.hpp │ ├── os.hpp │ ├── passive_vector.hpp │ ├── serializer.hpp │ ├── singleton.hpp │ ├── stream.hpp │ ├── traits.hpp │ └── uuid.hpp └── tinyexr └── tinyexr.h /.github/workflows/cla.yml: -------------------------------------------------------------------------------- 1 | name: "CLA Assistant" 2 | on: 3 | issue_comment: 4 | types: [created] 5 | pull_request_target: 6 | types: [opened,closed,synchronize] 7 | 8 | jobs: 9 | CLAssistant: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: "CLA Assistant" 13 | if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' 14 | uses: contributor-assistant/github-action@v2.1.3-beta 15 | env: 16 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 17 | PERSONAL_ACCESS_TOKEN : ${{ secrets.CLA_ACCESS_TOKEN }} 18 | with: 19 | path-to-signatures: 'signatures/CLA.json' 20 | path-to-document: 'https://github.com/NVIDIAGameWorks/KickstartRT_demo/blob/main/CLA.txt' 21 | branch: 'main' 22 | allowlist: nobody 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build*/ 2 | .vscode/ 3 | *.tlog 4 | **/Debug 5 | CMakeCache.txt 6 | **/CMakeFiles 7 | **/cmake_install.cmake 8 | #**/spirv/*.bin 9 | **/dxil/*.bin 10 | **/dxbc/*.bin 11 | *.sln 12 | *.vcxproj 13 | *.vcxproj.filters 14 | *.vcxproj.user 15 | .gitattributes 16 | .vs/donut/*/.suo 17 | /.vs 18 | **/*_d3d11.dir/* 19 | **/*_d3d12.dir/* 20 | **/*_vk.dir/* 21 | **/Release/* 22 | bin/* 23 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "nvrhi"] 2 | path = nvrhi 3 | url = https://github.com/NVIDIAGameWorks/nvrhi.git 4 | [submodule "thirdparty/imgui"] 5 | path = thirdparty/imgui 6 | url = https://github.com/ocornut/imgui 7 | [submodule "thirdparty/jsoncpp"] 8 | path = thirdparty/jsoncpp 9 | url = https://github.com/open-source-parsers/jsoncpp 10 | [submodule "thirdparty/stb"] 11 | path = thirdparty/stb 12 | url = https://github.com/nothings/stb.git 13 | [submodule "thirdparty/lz4"] 14 | path = thirdparty/lz4 15 | url = https://github.com/lz4/lz4.git 16 | [submodule "thirdparty/glfw"] 17 | path = thirdparty/glfw 18 | url = https://github.com/glfw/glfw.git 19 | [submodule "thirdparty/cgltf"] 20 | path = thirdparty/cgltf 21 | url = https://github.com/jkuhlmann/cgltf 22 | [submodule "thirdparty/miniz"] 23 | path = thirdparty/miniz 24 | url = https://github.com/richgel999/miniz.git 25 | [submodule "media/glTF-Sample-Models"] 26 | path = media/glTF-Sample-Models 27 | url = https://github.com/KhronosGroup/glTF-Sample-Models.git 28 | [submodule "KickstartRT"] 29 | path = KickstartRT 30 | url = https://github.com/NVIDIAGameWorks/KickstartRT.git 31 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /cmake/FindDXCdxil.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a 4 | # copy of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | # DEALINGS IN THE SOFTWARE. 20 | 21 | 22 | find_package(PackageHandleStandardArgs) 23 | 24 | if (WIN32 AND NOT DEFINED DXC_DXIL_EXECUTABLE) 25 | 26 | # locate Win 10 kits 27 | get_filename_component(kit10_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" REALPATH) 28 | file(GLOB W10SDK_VERSIONS RELATIVE ${kit10_dir}/Include ${kit10_dir}/Include/10.*) # enumerate pre-release and not yet known release versions 29 | list(APPEND W10SDK_VERSIONS "10.0.18362.0" "10.0.19041.0") # enumerate well known release versions 30 | list(REMOVE_DUPLICATES W10SDK_VERSIONS) 31 | list(SORT W10SDK_VERSIONS) # sort from low to high 32 | list(REVERSE W10SDK_VERSIONS) # reverse to start from high 33 | 34 | foreach(W10SDK_VER ${W10SDK_VERSIONS}) 35 | 36 | set(WINSDK_PATHS "${kit10_dir}/bin/${W10SDK_VER}/x64" "C:/Program Files (x86)/Windows Kits/10/bin/${W10SDK_VER}/x64" "C:/Program Files/Windows Kits/10/bin/${W10SDK_VER}/x64") 37 | 38 | find_program(DXC_DXIL_EXECUTABLE dxc PATHS ${WINSDK_PATHS} NO_DEFAULT_PATH) 39 | 40 | if (EXISTS ${DXC_DXIL_EXECUTABLE}) 41 | 42 | set(DXC_DXIL_VERSION "${W10SDK_VER}") 43 | break() 44 | endif() 45 | 46 | endforeach() 47 | endif() 48 | 49 | include(FindPackageHandleStandardArgs) 50 | 51 | find_package_handle_standard_args(DXCdxil 52 | REQUIRED_VARS 53 | DXC_DXIL_EXECUTABLE 54 | VERSION_VAR 55 | DXC_DXIL_VERSION 56 | ) 57 | -------------------------------------------------------------------------------- /cmake/FindDXCspirv.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a 4 | # copy of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | # DEALINGS IN THE SOFTWARE. 20 | 21 | 22 | find_package(PackageHandleStandardArgs) 23 | 24 | if (NOT DXC_SPIRV_EXECUTABLE) 25 | if (WIN32) 26 | find_program(DXC_SPIRV_EXECUTABLE dxc PATHS 27 | "$ENV{VULKAN_SDK}/Bin" 28 | NO_DEFAULT_PATH) 29 | else() 30 | find_program(DXC_SPIRV_EXECUTABLE dxc PATHS 31 | /usr/bin 32 | /usr/local/bin) 33 | endif() 34 | 35 | if (DXC_SPIRV_EXECUTABLE) 36 | message(STATUS "Found DXC for SPIR-V generation: ${DXC_SPIRV_EXECUTABLE}.") 37 | message(STATUS "Please note that older versions of the compiler may result in shader compilation errors.") 38 | endif() 39 | endif() 40 | 41 | find_package_handle_standard_args(DXCspirv 42 | REQUIRED_VARS DXC_SPIRV_EXECUTABLE 43 | VERSION_VAR DXC_SPIRV_VERSION 44 | FAIL_MESSAGE "Cannot find a SPIR-V capable DXC executable. Please provide a valid path through the DXC_SPIRV_EXECUTABLE variable." 45 | ) 46 | -------------------------------------------------------------------------------- /cmake/FindFXC.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a 4 | # copy of this software and associated documentation files (the "Software"), 5 | # to deal in the Software without restriction, including without limitation 6 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | # and/or sell copies of the Software, and to permit persons to whom the 8 | # Software is furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | # DEALINGS IN THE SOFTWARE. 20 | 21 | 22 | find_package(PackageHandleStandardArgs) 23 | 24 | if (WIN32 AND NOT DEFINED FXC_EXECUTABLE) 25 | 26 | # locate Win 10 kits 27 | get_filename_component(kit10_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" REALPATH) 28 | file(GLOB W10SDK_VERSIONS RELATIVE ${kit10_dir}/Include ${kit10_dir}/Include/10.*) # enumerate pre-release and not yet known release versions 29 | list(APPEND W10SDK_VERSIONS "10.0.15063.0" "10.0.16299.0" "10.0.17134.0") # enumerate well known release versions 30 | list(REMOVE_DUPLICATES W10SDK_VERSIONS) 31 | list(SORT W10SDK_VERSIONS) # sort from low to high 32 | list(REVERSE W10SDK_VERSIONS) # reverse to start from high 33 | 34 | foreach(W10SDK_VER ${W10SDK_VERSIONS}) 35 | 36 | set(WINSDK_PATHS "${kit10_dir}/bin/${W10SDK_VER}/x64" "C:/Program Files (x86)/Windows Kits/10/bin/${W10SDK_VER}/x64" "C:/Program Files/Windows Kits/10/bin/${W10SDK_VER}/x64") 37 | 38 | find_program(FXC_EXECUTABLE fxc PATHS ${WINSDK_PATHS} NO_DEFAULT_PATH) 39 | 40 | if (EXISTS ${FXC_EXECUTABLE}) 41 | 42 | set(FXC_VERSION "${W10SDK_VER}") 43 | break() 44 | endif() 45 | 46 | endforeach() 47 | endif() 48 | 49 | include(FindPackageHandleStandardArgs) 50 | 51 | find_package_handle_standard_args(FXC 52 | REQUIRED_VARS 53 | FXC_EXECUTABLE 54 | VERSION_VAR 55 | FXC_VERSION 56 | ) 57 | 58 | -------------------------------------------------------------------------------- /donut-app.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | file(GLOB donut_app_src 24 | LIST_DIRECTORIES false 25 | include/donut/app/*.h 26 | src/app/*.cpp 27 | ) 28 | 29 | file(GLOB donut_app_vr_src 30 | include/donut/app/vr/*.h 31 | src/app/vr/*.cpp 32 | ) 33 | 34 | add_library(donut_app STATIC EXCLUDE_FROM_ALL ${donut_app_src}) 35 | target_include_directories(donut_app PUBLIC include) 36 | target_link_libraries(donut_app donut_core donut_engine glfw imgui) 37 | 38 | if(DONUT_WITH_DX11) 39 | target_sources(donut_app PRIVATE src/app/dx11/DeviceManager_DX11.cpp) 40 | target_compile_definitions(donut_app PUBLIC USE_DX11=1) 41 | target_link_libraries(donut_app nvrhi_d3d11) 42 | endif() 43 | 44 | if(DONUT_WITH_DX12) 45 | target_sources(donut_app PRIVATE src/app/dx12/DeviceManager_DX12.cpp) 46 | target_compile_definitions(donut_app PUBLIC USE_DX12=1) 47 | target_link_libraries(donut_app nvrhi_d3d12) 48 | endif() 49 | 50 | if(DONUT_USE_DXIL_ON_DX12) 51 | target_compile_definitions(donut_app PRIVATE DONUT_USE_DXIL_ON_DX12=1) 52 | endif() 53 | 54 | if(DONUT_WITH_VULKAN) 55 | target_sources(donut_app PRIVATE src/app/vulkan/DeviceManager_VK.cpp) 56 | target_compile_definitions(donut_app PUBLIC USE_VK=1) 57 | target_link_libraries(donut_app nvrhi_vk) 58 | endif() 59 | 60 | target_link_libraries(donut_app nvrhi) # needs to come after nvrhi_d3d11 etc. for link order 61 | 62 | add_dependencies(donut_app donut_shaders) 63 | 64 | set_target_properties(donut_app PROPERTIES FOLDER Donut) 65 | -------------------------------------------------------------------------------- /donut-core.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | file(GLOB donut_core_src 24 | include/donut/core/chunk/*.h 25 | include/donut/core/math/*.h 26 | include/donut/core/vfs/Compression.h 27 | include/donut/core/vfs/TarFile.h 28 | include/donut/core/vfs/VFS.h 29 | include/donut/core/*.h 30 | src/core/chunk/*.cpp 31 | src/core/math/*.cpp 32 | src/core/vfs/Compression.cpp 33 | src/core/vfs/TarFile.cpp 34 | src/core/vfs/VFS.cpp 35 | src/core/*.cpp 36 | ) 37 | 38 | add_library(donut_core STATIC EXCLUDE_FROM_ALL ${donut_core_src}) 39 | target_include_directories(donut_core PUBLIC include) 40 | target_link_libraries(donut_core jsoncpp_static) 41 | 42 | if(NOT WIN32) 43 | target_link_libraries(donut_core stdc++fs dl pthread) 44 | endif() 45 | 46 | if(WIN32) 47 | target_sources(donut_core PRIVATE 48 | include/donut/core/vfs/WinResFS.h 49 | src/core/vfs/WinResFS.cpp 50 | ) 51 | target_compile_definitions(donut_core PUBLIC NOMINMAX _CRT_SECURE_NO_WARNINGS) 52 | endif() 53 | 54 | if(DONUT_WITH_LZ4) 55 | target_link_libraries(donut_core lz4) 56 | target_compile_definitions(donut_core PUBLIC DONUT_WITH_LZ4) 57 | endif() 58 | 59 | if(DONUT_WITH_MINIZ) 60 | target_link_libraries(donut_core miniz) 61 | target_sources(donut_core PRIVATE 62 | include/donut/core/vfs/ZipFile.h 63 | src/core/vfs/ZipFile.cpp 64 | ) 65 | target_compile_definitions(donut_core PUBLIC DONUT_WITH_MINIZ) 66 | endif() 67 | 68 | set_target_properties(donut_core PROPERTIES FOLDER Donut) 69 | -------------------------------------------------------------------------------- /donut-engine.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | file(GLOB donut_engine_src 24 | include/donut/engine/*.h 25 | src/engine/*.cpp 26 | src/engine/*.c 27 | src/engine/*.h 28 | ) 29 | 30 | if (MSVC) 31 | list (APPEND donut_engine_src donut.natvis) 32 | endif() 33 | 34 | add_library(donut_engine STATIC EXCLUDE_FROM_ALL ${donut_engine_src}) 35 | target_include_directories(donut_engine PUBLIC include) 36 | 37 | target_link_libraries(donut_engine donut_core nvrhi jsoncpp_static stb tinyexr cgltf) 38 | 39 | if (DONUT_WITH_TASKFLOW) 40 | target_link_libraries(donut_engine taskflow) 41 | target_compile_definitions(donut_engine PUBLIC DONUT_WITH_TASKFLOW) 42 | endif() 43 | 44 | if(WIN32) 45 | target_compile_definitions(donut_engine PUBLIC NOMINMAX) 46 | endif() 47 | 48 | if (DONUT_WITH_AUDIO) 49 | target_link_libraries(donut_engine Xaudio2) 50 | target_compile_definitions(donut_engine PUBLIC DONUT_WITH_AUDIO) 51 | endif() 52 | 53 | if (DONUT_WITH_TINYEXR) 54 | target_link_libraries(donut_engine tinyexr) 55 | target_compile_definitions(donut_engine PUBLIC DONUT_WITH_TINYEXR) 56 | endif() 57 | 58 | set_target_properties(donut_engine PROPERTIES FOLDER Donut) 59 | -------------------------------------------------------------------------------- /donut-render.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | file(GLOB donut_render_src 24 | LIST_DIRECTORIES false 25 | include/donut/render/*.h 26 | src/render/*.cpp 27 | ) 28 | 29 | add_library(donut_render STATIC EXCLUDE_FROM_ALL ${donut_render_src}) 30 | target_include_directories(donut_render PUBLIC include) 31 | target_link_libraries(donut_render donut_core donut_engine) 32 | 33 | add_dependencies(donut_render donut_shaders) 34 | 35 | if(DONUT_WITH_DX11) 36 | target_compile_definitions(donut_render PUBLIC USE_DX11=1) 37 | endif() 38 | 39 | if(DONUT_WITH_DX12) 40 | target_compile_definitions(donut_render PUBLIC USE_DX12=1) 41 | endif() 42 | 43 | if(DONUT_WITH_VULKAN) 44 | target_compile_definitions(donut_render PUBLIC USE_VK=1) 45 | endif() 46 | 47 | set_target_properties(donut_render PROPERTIES FOLDER Donut) 48 | -------------------------------------------------------------------------------- /donut.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | empty 7 | {*_Ptr} 8 | 9 | _Ptr 10 | 11 | 12 | 13 | 14 | empty 15 | {*_Ptr} 16 | 17 | _Ptr 18 | 19 | 20 | 21 | 22 | {m_Name} 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /include/donut/app/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | #include 25 | 26 | namespace donut::app 27 | { 28 | class HiResTimer 29 | { 30 | public: 31 | 32 | std::chrono::time_point startTime; 33 | std::chrono::time_point stopTime; 34 | 35 | HiResTimer() 36 | { 37 | } 38 | 39 | void Start() 40 | { 41 | startTime = std::chrono::high_resolution_clock::now(); 42 | } 43 | 44 | void Stop() 45 | { 46 | stopTime = std::chrono::high_resolution_clock::now(); 47 | } 48 | 49 | double Seconds() 50 | { 51 | auto duration = stopTime - startTime; 52 | return std::chrono::duration_cast(duration).count() * 1e-9; 53 | } 54 | 55 | double Milliseconds() 56 | { 57 | return Seconds() * 1e3; 58 | } 59 | }; 60 | } -------------------------------------------------------------------------------- /include/donut/app/UserInterfaceUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | namespace donut::engine 29 | { 30 | struct Material; 31 | class Light; 32 | class DirectionalLight; 33 | class PointLight; 34 | class SpotLight; 35 | } 36 | 37 | namespace donut::app 38 | { 39 | bool FileDialog(bool bOpen, const char* pFilters, std::string& fileName); 40 | 41 | bool MaterialEditor(engine::Material* material, bool allowMaterialDomainChanges); 42 | 43 | bool LightEditor_Directional(engine::DirectionalLight& light); 44 | bool LightEditor_Point(engine::PointLight& light); 45 | bool LightEditor_Spot(engine::SpotLight& light); 46 | bool LightEditor(engine::Light& light); 47 | 48 | bool AzimuthElevationSliders(math::double3& direction, bool negative = false); 49 | } 50 | -------------------------------------------------------------------------------- /include/donut/core/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace donut::log 28 | { 29 | enum class Severity 30 | { 31 | None = 0, 32 | Debug, 33 | Info, 34 | Warning, 35 | Error, 36 | Fatal 37 | }; 38 | 39 | typedef std::function Callback; 40 | 41 | void SetMinSeverity(Severity severity); 42 | void SetCallback(Callback func); 43 | Callback GetCallback(); 44 | void ResetCallback(); 45 | void SetErrorMessageCaption(const char* caption); 46 | 47 | void message(Severity severity, const char* fmt...); 48 | void debug(const char* fmt...); 49 | void info(const char* fmt...); 50 | void warning(const char* fmt...); 51 | void error(const char* fmt...); 52 | void fatal(const char* fmt...); 53 | } 54 | -------------------------------------------------------------------------------- /include/donut/core/math/math.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace donut::math {} 26 | namespace dm = donut::math; 27 | 28 | #include "basics.h" 29 | #include "vector.h" 30 | #include "matrix.h" 31 | #include "affine.h" 32 | #include "box.h" 33 | #include "color.h" 34 | #include "quat.h" 35 | #include "sphere.h" 36 | #include "frustum.h" 37 | -------------------------------------------------------------------------------- /include/donut/core/vfs/TarFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace donut::vfs 31 | { 32 | /* 33 | A read-only file system that provides access to files in a tar archive. 34 | The archive is partially read to enumerate the files when TarFile is created. 35 | TarFile can only operate on real files, i.e. underlying virtual file systems are not supported. 36 | Designed to work in combination with CompressionLayer to store packaged assets. 37 | */ 38 | class TarFile : public IFileSystem 39 | { 40 | private: 41 | std::string m_ArchivePath; 42 | std::mutex m_Mutex; 43 | FILE* m_ArchiveFile = nullptr; 44 | 45 | struct FileEntry 46 | { 47 | size_t offset = 0; 48 | size_t size = 0; 49 | }; 50 | 51 | std::unordered_map m_Files; 52 | std::unordered_set m_Directories; 53 | 54 | public: 55 | TarFile(const std::filesystem::path& archivePath); 56 | ~TarFile() override; 57 | 58 | [[nodiscard]] bool isOpen() const; 59 | 60 | bool folderExists(const std::filesystem::path& name) override; 61 | bool fileExists(const std::filesystem::path& name) override; 62 | std::shared_ptr readFile(const std::filesystem::path& name) override; 63 | bool writeFile(const std::filesystem::path& name, const void* data, size_t size) override; 64 | int enumerateFiles(const std::filesystem::path& path, const std::vector& extensions, enumerate_callback_t callback, bool allowDuplicates = false) override; 65 | int enumerateDirectories(const std::filesystem::path& path, enumerate_callback_t callback, bool allowDuplicates = false) override; 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /include/donut/core/vfs/WinResFS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace donut::vfs 28 | { 29 | /* 30 | 31 | File system interface for Windows module (EXE or DLL) resources. 32 | Automatically included into Donut builds for WIN32. 33 | 34 | Supports enumerating and reading resources of a given type, "BINARY" by default. 35 | Resource names are case insensitive, and all resource names are stored in the 36 | modules in uppercase, and reported by enumerate(...) also in uppercase. 37 | 38 | To add a resource to the application, use a .rc file, with lines like this one: 39 | 40 | resource_name BINARY "real_file_path" 41 | 42 | The part is interpreted by this interface as a virtual file path, 43 | and it can include slashes. The part is path to the actual file to 44 | be embedded, and it should be enclosed in quotes. 45 | 46 | */ 47 | class WinResFileSystem : public IFileSystem 48 | { 49 | private: 50 | const void* m_hModule; 51 | std::string m_Type; 52 | std::vector m_ResourceNames; 53 | 54 | public: 55 | WinResFileSystem(const void* hModule, const char* type = "BINARY"); 56 | 57 | bool folderExists(const std::filesystem::path& name) override; 58 | bool fileExists(const std::filesystem::path& name) override; 59 | std::shared_ptr readFile(const std::filesystem::path& name) override; 60 | bool writeFile(const std::filesystem::path& name, const void* data, size_t size) override; 61 | int enumerateFiles(const std::filesystem::path& path, const std::vector& extensions, enumerate_callback_t callback, bool allowDuplicates = false) override; 62 | int enumerateDirectories(const std::filesystem::path& path, enumerate_callback_t callback, bool allowDuplicates = false) override; 63 | }; 64 | } -------------------------------------------------------------------------------- /include/donut/engine/BindingCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace donut::engine 30 | { 31 | /* 32 | BindingCache maintains a dictionary that maps binding set descriptors 33 | into actual binding set objects. The binding sets are created on demand when 34 | GetOrCreateBindingSet(...) is called and the requested binding set does not exist. 35 | Created binding sets are stored for the lifetime of BindingCache, or until 36 | Clear() is called. 37 | 38 | All BindingCache methods are thread-safe. 39 | */ 40 | class BindingCache 41 | { 42 | private: 43 | nvrhi::DeviceHandle m_Device; 44 | std::unordered_map m_BindingSets; 45 | std::shared_mutex m_Mutex; 46 | 47 | public: 48 | BindingCache(nvrhi::IDevice* device) 49 | : m_Device(device) 50 | { } 51 | 52 | nvrhi::BindingSetHandle GetCachedBindingSet(const nvrhi::BindingSetDesc& desc, nvrhi::IBindingLayout* layout); 53 | nvrhi::BindingSetHandle GetOrCreateBindingSet(const nvrhi::BindingSetDesc& desc, nvrhi::IBindingLayout* layout); 54 | void Clear(); 55 | }; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /include/donut/engine/ConsoleInterpreter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace donut::engine 31 | { 32 | class TextureCache; 33 | 34 | namespace console 35 | { 36 | // Commnad-line lexer (splits a command line into a vector of tokens) 37 | // 38 | // Valid tokens: 39 | // - identifiers: none 40 | // - keywords : none 41 | // - separator : none 42 | // - operator : none 43 | // - literals : strings 44 | // 45 | // Lexical grammar: 46 | // 47 | // - strings: valid strings are sequences of characters separated by 48 | // white-space characters. Single quotes (') and double quotes (") 49 | // can be used as delimiters. Backslash (\) can be used to escape 50 | // quotes and space. 51 | // 52 | 53 | enum class TokenType 54 | { 55 | INVALID = 0, 56 | STRING 57 | }; 58 | 59 | struct Token 60 | { 61 | TokenType type = TokenType::INVALID; 62 | std::string value; 63 | }; 64 | 65 | class Lexer; 66 | 67 | // Command-line interpreter 68 | 69 | class Interpreter 70 | { 71 | public: 72 | 73 | Interpreter(); 74 | 75 | struct Result 76 | { 77 | bool status = false; 78 | std::string output; 79 | }; 80 | 81 | Result Execute(std::string_view const cmdline); 82 | 83 | // parse incomplete command line & return auto-completion suggestions 84 | std::vector Suggest(std::string_view const cmdline, size_t cursor_pos); 85 | 86 | bool RegisterCommands(std::shared_ptr textureCache); 87 | 88 | private: 89 | 90 | std::shared_ptr m_TextureCache; 91 | }; 92 | 93 | } // end namespace console 94 | 95 | } // end namespace donut::engine 96 | -------------------------------------------------------------------------------- /include/donut/engine/DDSFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace donut::vfs 30 | { 31 | class IBlob; 32 | } 33 | 34 | namespace donut::engine 35 | { 36 | struct TextureData; 37 | 38 | // Initialized the TextureInfo from the 'data' array, which must be populated with DDS data 39 | bool LoadDDSTextureFromMemory(TextureData& textureInfo); 40 | 41 | // Creates a texture based on DDS data in memory 42 | nvrhi::TextureHandle CreateDDSTextureFromMemory(nvrhi::IDevice* device, nvrhi::ICommandList* commandList, std::shared_ptr data, const char* debugName = nullptr, bool forceSRGB = false); 43 | 44 | std::shared_ptr SaveStagingTextureAsDDS(nvrhi::IDevice* device, nvrhi::IStagingTexture* stagingTexture); 45 | } -------------------------------------------------------------------------------- /include/donut/engine/FramebufferFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace donut::engine 30 | { 31 | class IView; 32 | 33 | class FramebufferFactory 34 | { 35 | private: 36 | nvrhi::DeviceHandle m_Device; 37 | std::unordered_map m_FramebufferCache; 38 | 39 | public: 40 | FramebufferFactory(nvrhi::IDevice* device) : m_Device(device) {} 41 | 42 | std::vector RenderTargets; 43 | nvrhi::TextureHandle DepthTarget; 44 | nvrhi::TextureHandle ShadingRateSurface; 45 | 46 | virtual nvrhi::IFramebuffer* GetFramebuffer(const nvrhi::TextureSubresourceSet& subresources); 47 | nvrhi::IFramebuffer* GetFramebuffer(const IView& view); 48 | }; 49 | } -------------------------------------------------------------------------------- /include/donut/engine/GltfImporter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | namespace donut::vfs 29 | { 30 | class IBlob; 31 | class IFileSystem; 32 | } 33 | 34 | namespace donut::engine 35 | { 36 | struct SceneImportResult; 37 | struct SceneLoadingStats; 38 | class TextureCache; 39 | class SceneGraphNode; 40 | class SceneTypeFactory; 41 | class SceneGraphAnimation; 42 | } 43 | 44 | namespace tf 45 | { 46 | class Executor; 47 | } 48 | 49 | namespace donut::engine 50 | { 51 | class GltfImporter 52 | { 53 | protected: 54 | std::shared_ptr m_fs; 55 | std::shared_ptr m_SceneTypeFactory; 56 | 57 | public: 58 | explicit GltfImporter(std::shared_ptr fs, std::shared_ptr sceneTypeFactory); 59 | 60 | bool Load( 61 | const std::filesystem::path& fileName, 62 | TextureCache& textureCache, 63 | SceneLoadingStats& stats, 64 | tf::Executor* executor, 65 | SceneImportResult& result) const; 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /include/donut/engine/IesProfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace donut::vfs 30 | { 31 | class IFileSystem; 32 | } 33 | 34 | namespace donut::engine 35 | { 36 | class ShaderFactory; 37 | class DescriptorTableManager; 38 | 39 | struct IesProfile 40 | { 41 | std::string name; 42 | std::vector rawData; 43 | nvrhi::TextureHandle texture; 44 | int textureIndex; 45 | }; 46 | 47 | class IesProfileLoader 48 | { 49 | nvrhi::DeviceHandle m_Device; 50 | nvrhi::ShaderHandle m_ComputeShader; 51 | nvrhi::ComputePipelineHandle m_ComputePipeline; 52 | nvrhi::BindingLayoutHandle m_BindingLayout; 53 | 54 | std::shared_ptr m_ShaderFactory; 55 | std::shared_ptr m_DescriptorTableManager; 56 | 57 | public: 58 | IesProfileLoader( 59 | nvrhi::IDevice* device, 60 | std::shared_ptr shaderFactory, 61 | std::shared_ptr descriptorTableManager); 62 | 63 | std::shared_ptr LoadIesProfile(donut::vfs::IFileSystem& fs, const std::filesystem::path& path); 64 | 65 | void BakeIesProfile(IesProfile& profile, nvrhi::ICommandList* commandList); 66 | }; 67 | 68 | } -------------------------------------------------------------------------------- /include/donut/engine/MaterialBindingCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace donut::engine 31 | { 32 | enum class MaterialResource 33 | { 34 | ConstantBuffer, 35 | Sampler, 36 | DiffuseTexture, 37 | SpecularTexture, 38 | NormalTexture, 39 | EmissiveTexture, 40 | OcclusionTexture, 41 | TransmissionTexture 42 | }; 43 | 44 | struct MaterialResourceBinding 45 | { 46 | MaterialResource resource; 47 | uint32_t slot; // type depends on resource 48 | }; 49 | 50 | class MaterialBindingCache 51 | { 52 | private: 53 | nvrhi::DeviceHandle m_Device; 54 | nvrhi::BindingLayoutHandle m_BindingLayout; 55 | std::unordered_map m_BindingSets; 56 | nvrhi::ShaderType m_ShaderType; 57 | std::vector m_BindingDesc; 58 | nvrhi::TextureHandle m_FallbackTexture; 59 | nvrhi::SamplerHandle m_Sampler; 60 | std::mutex m_Mutex; 61 | bool m_TrackLiveness; 62 | 63 | nvrhi::BindingSetHandle CreateMaterialBindingSet(const Material* material); 64 | nvrhi::BindingSetItem GetTextureBindingSetItem(uint32_t slot, const std::shared_ptr& texture) const; 65 | 66 | public: 67 | MaterialBindingCache( 68 | nvrhi::IDevice* device, 69 | nvrhi::ShaderType shaderType, 70 | uint32_t registerSpace, 71 | const std::vector& bindings, 72 | nvrhi::ISampler* sampler, 73 | nvrhi::ITexture* fallbackTexture, 74 | bool trackLiveness = true); 75 | 76 | nvrhi::IBindingLayout* GetLayout() const; 77 | nvrhi::IBindingSet* GetMaterialBindingSet(const Material* material); 78 | void Clear(); 79 | }; 80 | } -------------------------------------------------------------------------------- /include/donut/engine/ShaderFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | namespace donut::vfs 34 | { 35 | class IBlob; 36 | class IFileSystem; 37 | } 38 | 39 | namespace donut::engine 40 | { 41 | struct ShaderMacro 42 | { 43 | std::string name; 44 | std::string definition; 45 | 46 | ShaderMacro(const std::string& _name, const std::string& _definition) 47 | : name(_name) 48 | , definition(_definition) 49 | { } 50 | }; 51 | 52 | class ShaderFactory 53 | { 54 | private: 55 | nvrhi::DeviceHandle m_Device; 56 | std::unordered_map> m_BytecodeCache; 57 | std::shared_ptr m_fs; 58 | std::filesystem::path m_basePath; 59 | 60 | public: 61 | ShaderFactory( 62 | nvrhi::DeviceHandle rendererInterface, 63 | std::shared_ptr fs, 64 | const std::filesystem::path& basePath); 65 | 66 | void ClearCache(); 67 | 68 | nvrhi::ShaderHandle CreateShader(const char* fileName, const char* entryName, const std::vector* pDefines, nvrhi::ShaderType shaderType); 69 | nvrhi::ShaderHandle CreateShader(const char* fileName, const char* entryName, const std::vector* pDefines, const nvrhi::ShaderDesc& desc); 70 | nvrhi::ShaderLibraryHandle CreateShaderLibrary(const char* fileName, const std::vector* pDefines); 71 | 72 | std::shared_ptr GetBytecode(const char* fileName, const char* entryName); 73 | }; 74 | } -------------------------------------------------------------------------------- /include/donut/engine/ShadowMap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | struct ShadowConstants; 29 | 30 | namespace donut::engine 31 | { 32 | class IShadowMap 33 | { 34 | public: 35 | virtual dm::float4x4 GetWorldToUvzwMatrix() const = 0; 36 | virtual const class ICompositeView& GetView() const = 0; 37 | virtual nvrhi::ITexture* GetTexture() const = 0; 38 | virtual uint32_t GetNumberOfCascades() const = 0; 39 | virtual const IShadowMap* GetCascade(uint32_t index) const = 0; 40 | virtual uint32_t GetNumberOfPerObjectShadows() const = 0; 41 | virtual const IShadowMap* GetPerObjectShadow(uint32_t index) const = 0; 42 | virtual dm::int2 GetTextureSize() const = 0; 43 | virtual dm::box2 GetUVRange() const = 0; 44 | virtual dm::float2 GetFadeRangeInTexels() const = 0; 45 | virtual bool IsLitOutOfBounds() const = 0; 46 | virtual void FillShadowConstants(ShadowConstants& constants) const = 0; 47 | }; 48 | } -------------------------------------------------------------------------------- /include/donut/render/EnvironmentMapPass.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | 26 | #include 27 | #include 28 | 29 | namespace donut::engine 30 | { 31 | class ShaderFactory; 32 | class CommonRenderPasses; 33 | class FramebufferFactory; 34 | class ICompositeView; 35 | } 36 | 37 | 38 | namespace donut::render 39 | { 40 | class EnvironmentMapPass 41 | { 42 | private: 43 | nvrhi::ShaderHandle m_PixelShader; 44 | nvrhi::BufferHandle m_SkyCB; 45 | nvrhi::BindingLayoutHandle m_RenderBindingLayout; 46 | nvrhi::BindingSetHandle m_RenderBindingSet; 47 | nvrhi::GraphicsPipelineHandle m_RenderPso; 48 | 49 | std::shared_ptr m_CommonPasses; 50 | std::shared_ptr m_FramebufferFactory; 51 | 52 | public: 53 | EnvironmentMapPass( 54 | nvrhi::IDevice* device, 55 | std::shared_ptr shaderFactory, 56 | std::shared_ptr commonPasses, 57 | std::shared_ptr framebufferFactory, 58 | const engine::ICompositeView& compositeView, 59 | nvrhi::ITexture* environmentMap); 60 | 61 | void Render( 62 | nvrhi::ICommandList* commandList, 63 | const engine::ICompositeView& compositeView); 64 | }; 65 | 66 | } -------------------------------------------------------------------------------- /include/donut/render/JointsRenderPass.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | namespace donut::engine 32 | { 33 | class ShaderFactory; 34 | class SceneGraph; 35 | } 36 | 37 | namespace donut::render 38 | { 39 | // A rasterization pass that draws lines for each joint 40 | // of all the animated skeletons in a SceneGraph 41 | // (debugging feature) 42 | 43 | class JointsRenderPass 44 | { 45 | protected: 46 | nvrhi::DeviceHandle m_Device; 47 | 48 | nvrhi::BufferHandle m_VertexBuffer; 49 | nvrhi::BufferHandle m_ConstantsBuffer; 50 | 51 | nvrhi::ShaderHandle m_VertexShader; 52 | nvrhi::ShaderHandle m_PixelShader; 53 | 54 | nvrhi::InputLayoutHandle m_InputLayout; 55 | nvrhi::BindingSetHandle m_BindingSet; 56 | nvrhi::BindingLayoutHandle m_BindingLayout; 57 | nvrhi::GraphicsPipelineHandle m_Pipeline; 58 | 59 | nvrhi::BufferHandle CreateVertexBuffer(uint32_t numVertices) const; 60 | 61 | protected: 62 | 63 | struct Vertex { 64 | dm::float3 position; 65 | uint32_t color; 66 | }; 67 | 68 | std::vector m_Vertices; 69 | 70 | void UpdateVertices(const engine::SceneGraph& sceneGraph); 71 | 72 | public: 73 | 74 | JointsRenderPass(nvrhi::IDevice* device); 75 | 76 | void Init(donut::engine::ShaderFactory& shaderFactory); 77 | 78 | void ResetCaches(); 79 | 80 | void RenderView( 81 | nvrhi::ICommandList* commandList, 82 | const engine::IView* view, 83 | nvrhi::IFramebuffer* framebuffer, 84 | std::shared_ptr sceneGraph); 85 | }; 86 | } // end namespace donut::render -------------------------------------------------------------------------------- /include/donut/render/PixelReadbackPass.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | namespace donut::engine 32 | { 33 | class ShaderFactory; 34 | class CommonRenderPasses; 35 | class FramebufferFactory; 36 | class ICompositeView; 37 | } 38 | 39 | namespace donut::render 40 | { 41 | class PixelReadbackPass 42 | { 43 | private: 44 | nvrhi::DeviceHandle m_Device; 45 | nvrhi::ShaderHandle m_Shader; 46 | nvrhi::ComputePipelineHandle m_Pipeline; 47 | nvrhi::BindingLayoutHandle m_BindingLayout; 48 | nvrhi::BindingSetHandle m_BindingSet; 49 | nvrhi::BufferHandle m_ConstantBuffer; 50 | nvrhi::BufferHandle m_IntermediateBuffer; 51 | nvrhi::BufferHandle m_ReadbackBuffer; 52 | 53 | public: 54 | PixelReadbackPass( 55 | nvrhi::IDevice* device, 56 | std::shared_ptr shaderFactory, 57 | nvrhi::ITexture* inputTexture, 58 | nvrhi::Format format, 59 | uint32_t arraySlice = 0, 60 | uint32_t mipLevel = 0); 61 | 62 | void Capture(nvrhi::ICommandList* commandList, dm::uint2 pixelPosition); 63 | 64 | dm::float4 ReadFloats(); 65 | dm::uint4 ReadUInts(); 66 | dm::int4 ReadInts(); 67 | }; 68 | } -------------------------------------------------------------------------------- /include/donut/shaders/blit_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef BLIT_CB_H 24 | #define BLIT_CB_H 25 | 26 | struct BlitConstants 27 | { 28 | float2 sourceOrigin; 29 | float2 sourceSize; 30 | 31 | float2 targetOrigin; 32 | float2 targetSize; 33 | 34 | float sharpenFactor; 35 | }; 36 | 37 | #endif // BLIT_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/bloom_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef BLOOM_CB_H 24 | #define BLOOM_CB_H 25 | 26 | struct BloomConstants 27 | { 28 | float2 pixstep; 29 | float argumentScale; 30 | float normalizationScale; 31 | 32 | float3 padding; 33 | float numSamples; 34 | }; 35 | 36 | #endif // BLOOM_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/deferred_lighting_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef DEFERRED_LIGHTING_CB_H 24 | #define DEFERRED_LIGHTING_CB_H 25 | 26 | #include "light_cb.h" 27 | #include "view_cb.h" 28 | 29 | #define DEFERRED_MAX_LIGHTS 16 30 | #define DEFERRED_MAX_SHADOWS 16 31 | #define DEFERRED_MAX_LIGHT_PROBES 16 32 | 33 | struct DeferredLightingConstants 34 | { 35 | PlanarViewConstants view; 36 | 37 | float2 shadowMapTextureSize; 38 | int enableAmbientOcclusion; 39 | int enableRTShadows; 40 | 41 | float4 ambientColorTop; 42 | float4 ambientColorBottom; 43 | 44 | uint numLights; 45 | uint numLightProbes; 46 | float indirectDiffuseScale; 47 | float indirectSpecularScale; 48 | 49 | float2 randomOffset; 50 | float2 padding2; 51 | 52 | float4 noisePattern[4]; 53 | 54 | LightConstants lights[DEFERRED_MAX_LIGHTS]; 55 | ShadowConstants shadows[DEFERRED_MAX_SHADOWS]; 56 | LightProbeConstants lightProbes[DEFERRED_MAX_LIGHT_PROBES]; 57 | }; 58 | 59 | #endif // DEFERRED_LIGHTING_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/depth_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef DEPTH_CB_H 24 | #define DEPTH_CB_H 25 | 26 | struct DepthPassConstants 27 | { 28 | float4x4 matWorldToClip; 29 | }; 30 | 31 | #endif // DEPTH_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/forward_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef FORWARD_CB_H 24 | #define FORWARD_CB_H 25 | 26 | #include "light_cb.h" 27 | #include "view_cb.h" 28 | 29 | #define FORWARD_MAX_LIGHTS 16 30 | #define FORWARD_MAX_SHADOWS 16 31 | #define FORWARD_MAX_LIGHT_PROBES 16 32 | 33 | struct ForwardShadingViewConstants 34 | { 35 | PlanarViewConstants view; 36 | }; 37 | 38 | struct ForwardShadingLightConstants 39 | { 40 | float2 shadowMapTextureSize; 41 | float2 shadowMapTextureSizeInv; 42 | float4 ambientColorTop; 43 | float4 ambientColorBottom; 44 | 45 | uint2 padding; 46 | uint numLights; 47 | uint numLightProbes; 48 | 49 | LightConstants lights[FORWARD_MAX_LIGHTS]; 50 | ShadowConstants shadows[FORWARD_MAX_SHADOWS]; 51 | LightProbeConstants lightProbes[FORWARD_MAX_LIGHT_PROBES]; 52 | }; 53 | 54 | #endif // FORWARD_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/forward_vertex.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | struct SceneVertex 24 | { 25 | float3 pos : POS; 26 | float3 prevPos : PREV_POS; 27 | float2 texCoord : TEXCOORD; 28 | centroid float3 normal : NORMAL; 29 | centroid float4 tangent : TANGENT; 30 | }; 31 | -------------------------------------------------------------------------------- /include/donut/shaders/gbuffer_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef GBUFFER_CB_H 24 | #define GBUFFER_CB_H 25 | 26 | #include "view_cb.h" 27 | 28 | struct GBufferFillConstants 29 | { 30 | PlanarViewConstants view; 31 | PlanarViewConstants viewPrev; 32 | }; 33 | 34 | #endif // GBUFFER_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/light_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LIGHT_CB_H 24 | #define LIGHT_CB_H 25 | 26 | #include "light_types.h" 27 | 28 | struct ShadowConstants 29 | { 30 | float4x4 matWorldToUvzwShadow; 31 | 32 | float2 shadowFadeScale; 33 | float2 shadowFadeBias; 34 | 35 | float2 shadowMapCenterUV; 36 | float shadowFalloffDistance; 37 | int shadowMapArrayIndex; 38 | 39 | float2 shadowMapSizeTexels; 40 | float2 shadowMapSizeTexelsInv; 41 | }; 42 | 43 | struct LightConstants 44 | { 45 | float3 direction; 46 | int lightType; 47 | 48 | float3 position; 49 | float radius; 50 | 51 | float3 color; 52 | float intensity; // illuminance (lm/m2) for directional lights, luminous intensity (lm/sr) for positional lights 53 | 54 | float angularSizeOrInvRange; // angular size for directional lights, 1/range for spot and point lights 55 | float innerAngle; 56 | float outerAngle; 57 | float outOfBoundsShadow; 58 | 59 | int4 shadowCascades; 60 | int4 perObjectShadows; 61 | 62 | int4 shadowChannel; 63 | }; 64 | 65 | struct LightProbeConstants 66 | { 67 | float diffuseScale; 68 | float specularScale; 69 | float mipLevels; 70 | float padding1; 71 | 72 | uint diffuseArrayIndex; 73 | uint specularArrayIndex; 74 | uint2 padding2; 75 | 76 | float4 frustumPlanes[6]; 77 | }; 78 | 79 | #endif // LIGHT_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/light_probe_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LIGHT_PROBE_CB_H 24 | #define LIGHT_PROBE_CB_H 25 | 26 | struct LightProbeConstants 27 | { 28 | uint sampleCount; 29 | float lodBias; 30 | float roughness; 31 | float inputCubeSize; 32 | }; 33 | 34 | #endif // LIGHT_PROBE_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/light_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef LIGHT_TYPES_H 24 | #define LIGHT_TYPES_H 25 | 26 | #ifdef __cplusplus 27 | constexpr int LightType_None = 0; 28 | constexpr int LightType_Directional = 1; 29 | constexpr int LightType_Spot = 2; 30 | constexpr int LightType_Point = 3; 31 | #else 32 | static const int LightType_None = 0; 33 | static const int LightType_Directional = 1; 34 | static const int LightType_Spot = 2; 35 | static const int LightType_Point = 3; 36 | #endif 37 | 38 | #endif // LIGHT_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/mipmapgen_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef MIPMAP_GEN_CB_H 24 | #define MIPMAP_GEN_CB_H 25 | 26 | #define GROUP_SIZE 16 27 | #define LOD0_TILE_SIZE 8 28 | #define NUM_LODS 4 29 | 30 | // Number of compute dispatches needed to reduce all the 31 | // mip-levels at a maximum resolution of 16k : 32 | // (uint)(std::ceil(std::log2f(16384)/NUM_LODS)) = 4 33 | #define MAX_PASSES 4 34 | 35 | #define MODE_COLOR 0 36 | #define MODE_MIN 1 37 | #define MODE_MAX 2 38 | #define MODE_MINMAX 3 39 | 40 | struct MipmmapGenConstants 41 | { 42 | uint dispatch; 43 | uint numLODs; 44 | uint padding[2]; 45 | }; 46 | 47 | #endif // MIPMAP_GEN_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/motion_vectors.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include "view_cb.h" 24 | 25 | float3 GetMotionVector(float3 svPosition, float3 prevWorldPos, PlanarViewConstants view, PlanarViewConstants viewPrev) 26 | { 27 | float4 clipPos = mul(float4(prevWorldPos, 1), viewPrev.matWorldToClip); 28 | if (clipPos.w <= 0) 29 | return 0; 30 | 31 | clipPos.xyz /= clipPos.w; 32 | float2 prevWindowPos = clipPos.xy * view.clipToWindowScale + view.clipToWindowBias; 33 | 34 | float3 motion; 35 | motion.xy = (prevWindowPos - svPosition.xy);// +(view.pixelOffset - viewPrev.pixelOffset); 36 | motion.z = clipPos.z - svPosition.z; 37 | return motion; 38 | } 39 | -------------------------------------------------------------------------------- /include/donut/shaders/pixel_readback_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PIXEL_READBACK_CB_H 24 | #define PIXEL_READBACK_CB_H 25 | 26 | struct PixelReadbackConstants 27 | { 28 | int2 pixelPosition; 29 | int2 dummy; 30 | }; 31 | 32 | #endif // PIXEL_READBACK_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/skinning_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SKINNING_CB_H 24 | #define SKINNING_CB_H 25 | 26 | #define SkinningFlag_FirstFrame 0x01 27 | #define SkinningFlag_Normals 0x02 28 | #define SkinningFlag_Tangents 0x04 29 | #define SkinningFlag_TexCoord1 0x08 30 | #define SkinningFlag_TexCoord2 0x10 31 | 32 | struct SkinningConstants 33 | { 34 | uint numVertices; 35 | uint flags; 36 | uint inputPositionOffset; 37 | uint inputNormalOffset; 38 | 39 | uint inputTangentOffset; 40 | uint inputTexCoord1Offset; 41 | uint inputTexCoord2Offset; 42 | uint inputJointIndexOffset; 43 | 44 | uint inputJointWeightOffset; 45 | uint outputPositionOffset; 46 | uint outputPrevPositionOffset; 47 | uint outputNormalOffset; 48 | 49 | uint outputTangentOffset; 50 | uint outputTexCoord1Offset; 51 | uint outputTexCoord2Offset; 52 | }; 53 | 54 | #endif // SKINNING_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/sky.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | 27 | float3 ProceduralSky(ProceduralSkyShaderParameters params, float3 direction, float angularSizeOfPixel) 28 | { 29 | float elevation = asin(clamp(dot(direction, params.directionUp), -1.0, 1.0)); 30 | float top = smoothstep(0.f, params.horizonSize, elevation); 31 | float bottom = smoothstep(0.f, params.horizonSize, -elevation); 32 | float3 environment = lerp(lerp(params.horizonColor, params.groundColor, bottom), params.skyColor, top); 33 | 34 | float angleToLight = acos(saturate(dot(direction, params.directionToLight))); 35 | float halfAngularSize = params.angularSizeOfLight * 0.5; 36 | float lightIntensity = saturate(1.0 - smoothstep(halfAngularSize - angularSizeOfPixel * 2, halfAngularSize + angularSizeOfPixel * 2, angleToLight)); 37 | lightIntensity = pow(lightIntensity, 4.0); 38 | float glowInput = saturate(2.0 * (1.0 - smoothstep(halfAngularSize - params.glowSize, halfAngularSize + params.glowSize, angleToLight))); 39 | float glowIntensity = params.glowIntensity * pow(glowInput, params.glowSharpness); 40 | float3 light = max(lightIntensity, glowIntensity) * params.lightColor; 41 | 42 | return environment + light; 43 | } 44 | -------------------------------------------------------------------------------- /include/donut/shaders/sky_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SKY_CB_H 24 | #define SKY_CB_H 25 | 26 | struct ProceduralSkyShaderParameters 27 | { 28 | float3 directionToLight; 29 | float angularSizeOfLight; 30 | 31 | float3 lightColor; 32 | float glowSize; 33 | 34 | float3 skyColor; 35 | float glowIntensity; 36 | 37 | float3 horizonColor; 38 | float horizonSize; 39 | 40 | float3 groundColor; 41 | float glowSharpness; 42 | 43 | float3 directionUp; 44 | float pad1; 45 | }; 46 | 47 | struct SkyConstants 48 | { 49 | float4x4 matClipToTranslatedWorld; 50 | 51 | ProceduralSkyShaderParameters params; 52 | }; 53 | 54 | #endif // SKY_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/ssao_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SSAO_CB_H 24 | #define SSAO_CB_H 25 | 26 | #include 27 | 28 | struct SsaoConstants 29 | { 30 | PlanarViewConstants view; 31 | 32 | float2 clipToView; 33 | float2 invQuantizedGbufferSize; 34 | 35 | int2 quantizedViewportOrigin; 36 | float amount; 37 | float invBackgroundViewDepth; 38 | float radiusWorld; 39 | float surfaceBias; 40 | 41 | float radiusToScreen; 42 | float powerExponent; 43 | }; 44 | 45 | #endif // SSAO_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/surface.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SURFACE_HLSLI 24 | #define SURFACE_HLSLI 25 | 26 | struct MaterialSample 27 | { 28 | float3 shadingNormal; 29 | float3 geometryNormal; 30 | float3 diffuseAlbedo; // BRDF input Cdiff 31 | float3 specularF0; // BRDF input F0 32 | float3 emissiveColor; 33 | float opacity; 34 | float occlusion; 35 | float roughness; 36 | float3 baseColor; // native in metal-rough, derived in spec-gloss 37 | float metalness; // native in metal-rough, derived in spec-gloss 38 | float transmission; 39 | bool hasMetalRoughParams; // indicates that 'baseColor' and 'metalness' are valid 40 | }; 41 | 42 | MaterialSample DefaultMaterialSample() 43 | { 44 | MaterialSample result; 45 | result.shadingNormal = 0; 46 | result.geometryNormal = 0; 47 | result.diffuseAlbedo = 0; 48 | result.specularF0 = 0; 49 | result.emissiveColor = 0; 50 | result.opacity = 1; 51 | result.occlusion = 1; 52 | result.roughness = 0; 53 | result.baseColor = 0; 54 | result.metalness = 0; 55 | result.transmission = 0; 56 | result.hasMetalRoughParams = false; 57 | return result; 58 | } 59 | 60 | #endif // SURFACE_HLSLI 61 | -------------------------------------------------------------------------------- /include/donut/shaders/taa_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef TAA_CB_H 24 | #define TAA_CB_H 25 | 26 | struct TemporalAntiAliasingConstants 27 | { 28 | float4x4 reprojectionMatrix; 29 | 30 | float2 inputViewOrigin; 31 | float2 inputViewSize; 32 | 33 | float2 outputViewOrigin; 34 | float2 outputViewSize; 35 | 36 | float2 inputPixelOffset; 37 | float2 outputTextureSizeInv; 38 | 39 | float2 inputOverOutputViewSize; 40 | float2 outputOverInputViewSize; 41 | 42 | float clampingFactor; 43 | float newFrameWeight; 44 | float pqC; 45 | float invPqC; 46 | 47 | uint stencilMask; 48 | }; 49 | 50 | #endif // TAA_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/tonemapping_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef DEPTH_CB_H 24 | #define DEPTH_CB_H 25 | 26 | struct ToneMappingConstants 27 | { 28 | uint2 viewOrigin; 29 | uint2 viewSize; 30 | 31 | float logLuminanceScale; 32 | float logLuminanceBias; 33 | float histogramLowPercentile; 34 | float histogramHighPercentile; 35 | 36 | float eyeAdaptationSpeedUp; 37 | float eyeAdaptationSpeedDown; 38 | float minAdaptedLuminance; 39 | float maxAdaptedLuminance; 40 | 41 | float frameTime; 42 | float exposureScale; 43 | float whitePointInvSquared; 44 | uint sourceSlice; 45 | 46 | float2 colorLUTTextureSize; 47 | float2 colorLUTTextureSizeInv; 48 | }; 49 | 50 | #endif // DEPTH_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/view_cb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef VIEW_CB_H 24 | #define VIEW_CB_H 25 | 26 | struct PlanarViewConstants 27 | { 28 | float4x4 matWorldToView; 29 | float4x4 matViewToClip; 30 | float4x4 matWorldToClip; 31 | float4x4 matClipToView; 32 | float4x4 matViewToWorld; 33 | float4x4 matClipToWorld; 34 | 35 | float2 viewportOrigin; 36 | float2 viewportSize; 37 | 38 | float2 viewportSizeInv; 39 | float2 pixelOffset; 40 | 41 | float2 clipToWindowScale; 42 | float2 clipToWindowBias; 43 | 44 | float2 windowToClipScale; 45 | float2 windowToClipBias; 46 | 47 | float4 cameraDirectionOrPosition; 48 | }; 49 | 50 | #endif // VIEW_CB_H -------------------------------------------------------------------------------- /include/donut/shaders/vulkan.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef VULKAN_HLSLI 24 | #define VULKAN_HLSLI 25 | 26 | #ifdef SPIRV 27 | #define VK_PUSH_CONSTANT [[vk::push_constant]] 28 | #define VK_BINDING(reg,dset) [[vk::binding(reg,dset)]] 29 | #define VK_DESCRIPTOR_SET(dset) ,space##dset 30 | #else 31 | #define VK_PUSH_CONSTANT 32 | #define VK_BINDING(reg,dset) 33 | #define VK_DESCRIPTOR_SET(dset) 34 | #endif 35 | 36 | #endif // VULKAN_HLSLI -------------------------------------------------------------------------------- /shaders/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | include(../compileshaders.cmake) 24 | 25 | file(GLOB donut_shaders 26 | "*.hlsl" 27 | "passes/*.hlsl" 28 | "../include/donut/shaders/*.hlsli" 29 | "../include/donut/shaders/*.h" 30 | ) 31 | 32 | if(DONUT_SHADERS_OUTPUT_DIR) 33 | set(output_base ${DONUT_SHADERS_OUTPUT_DIR}) 34 | else() 35 | set(output_base ${CMAKE_CURRENT_BINARY_DIR}) 36 | endif() 37 | 38 | donut_compile_shaders_all_platforms( 39 | TARGET donut_shaders 40 | CONFIG ${CMAKE_CURRENT_LIST_DIR}/DonutShaders.cfg 41 | FOLDER Donut 42 | OUTPUT_BASE ${output_base} 43 | SOURCES ${donut_shaders} 44 | ) 45 | -------------------------------------------------------------------------------- /shaders/DonutShaders.cfg: -------------------------------------------------------------------------------- 1 | 2 | fullscreen_vs.hlsl -T vs_5_0 -D QUAD_Z={0,1} 3 | rect_vs.hlsl -T vs_5_0 4 | blit_ps.hlsl -T ps_5_0 -D TEXTURE_ARRAY={0,1} 5 | sharpen_ps.hlsl -T ps_5_0 -D TEXTURE_ARRAY={0,1} 6 | imgui_pixel.hlsl -T ps_5_0 7 | imgui_vertex.hlsl -T vs_5_0 8 | ies_profile_cs.hlsl -T cs_5_0 -E main 9 | skinning_cs.hlsl -T cs_5_0 -E main 10 | 11 | passes/depth_vs.hlsl -T vs_5_0 12 | passes/depth_ps.hlsl -T ps_5_0 13 | passes/forward_vs.hlsl -T vs_5_0 14 | passes/forward_ps.hlsl -T ps_5_0 -D TRANSMISSIVE_MATERIAL={0,1} 15 | passes/cubemap_gs.hlsl -T gs_5_0 16 | passes/gbuffer_vs.hlsl -T vs_5_0 -D MOTION_VECTORS={0,1} 17 | passes/gbuffer_ps.hlsl -T ps_5_0 -D MOTION_VECTORS={0,1} -D ALPHA_TESTED={0,1} 18 | passes/joints.hlsl -T vs_5_0 -E main_vs 19 | passes/joints.hlsl -T ps_5_0 -E main_ps 20 | passes/deferred_lighting_cs.hlsl -T cs_5_0 21 | passes/material_id_ps.hlsl -T ps_5_0 -D ALPHA_TESTED={0,1} 22 | passes/mipmapgen_cs.hlsl -T cs_5_0 -D MODE={0,1,2,3} 23 | passes/pixel_readback_cs.hlsl -T cs_5_0 -D TYPE={float4,int4,uint4} -D INPUT_MSAA={0,1} 24 | passes/taa_cs.hlsl -T cs_5_0 -D SAMPLE_COUNT={1,2,4,8} -D USE_CATMULL_ROM_FILTER={0,1} 25 | passes/sky_ps.hlsl -T ps_5_0 26 | passes/ssao_blur_cs.hlsl -T cs_5_0 -D DIRECTIONAL_OCCLUSION={0,1} 27 | passes/ssao_compute_cs.hlsl -T cs_5_0 -D OCT_ENCODED_NORMALS={0,1} -D DIRECTIONAL_OCCLUSION={0,1} 28 | passes/ssao_deinterleave_cs.hlsl -T cs_5_0 -D LINEAR_DEPTH={0,1} 29 | passes/motion_vectors_ps.hlsl -T ps_5_0 -D USE_STENCIL={0,1} 30 | passes/histogram_cs.hlsl -T cs_5_0 -D HISTOGRAM_BINS=256 -D SOURCE_ARRAY={0,1} 31 | passes/exposure_cs.hlsl -T cs_5_0 -D HISTOGRAM_BINS=256 -D SOURCE_ARRAY={0,1} 32 | passes/tonemapping_ps.hlsl -T ps_5_0 -D HISTOGRAM_BINS=256 -D SOURCE_ARRAY={0,1} 33 | passes/bloom_ps.hlsl -T ps_5_0 34 | passes/environment_map_ps.hlsl -T ps_5_0 -D LATLONG_TEXTURE={0,1} 35 | passes/light_probe.hlsl -E cubemap_gs -T gs_5_0 36 | passes/light_probe.hlsl -E mip_ps -T ps_5_0 37 | passes/light_probe.hlsl -E diffuse_probe_ps -T ps_5_0 38 | passes/light_probe.hlsl -E specular_probe_ps -T ps_5_0 39 | passes/light_probe.hlsl -E environment_brdf_ps -T ps_5_0 40 | 41 | app/KickStart_Composite_cs.hlsl -T cs_5_0 42 | -------------------------------------------------------------------------------- /shaders/blit_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #if TEXTURE_ARRAY 24 | Texture2DArray tex : register(t0); 25 | #else 26 | Texture2D tex : register(t0); 27 | #endif 28 | SamplerState samp : register(s0); 29 | 30 | void main( 31 | in float4 pos : SV_Position, 32 | in float2 uv : UV, 33 | out float4 o_rgba : SV_Target) 34 | { 35 | #if TEXTURE_ARRAY 36 | o_rgba = tex.Sample(samp, float3(uv, 0)); 37 | #else 38 | o_rgba = tex.Sample(samp, uv); 39 | #endif 40 | } 41 | -------------------------------------------------------------------------------- /shaders/fullscreen_vs.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | void main( 24 | in uint iVertex : SV_VertexID, 25 | out float4 o_posClip : SV_Position, 26 | out float2 o_uv : UV) 27 | { 28 | uint u = iVertex & 1; 29 | uint v = (iVertex >> 1) & 1; 30 | 31 | o_posClip = float4(float(u) * 2 - 1, 1 - float(v) * 2, QUAD_Z, 1); 32 | o_uv = float2(u, v); 33 | } 34 | -------------------------------------------------------------------------------- /shaders/imgui_pixel.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | 24 | struct PS_INPUT 25 | { 26 | float4 pos : SV_POSITION; 27 | float4 col : COLOR0; 28 | float2 uv : TEXCOORD0; 29 | }; 30 | 31 | sampler sampler0 : register(s0); 32 | Texture2D texture0 : register(t0); 33 | 34 | float4 main(PS_INPUT input) : SV_Target 35 | { 36 | float4 out_col = input.col * texture0.Sample(sampler0, input.uv); 37 | return out_col; 38 | } 39 | -------------------------------------------------------------------------------- /shaders/imgui_vertex.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | struct Constants 24 | { 25 | float2 invDisplaySize; 26 | }; 27 | 28 | #ifdef SPIRV 29 | 30 | [[vk::push_constant]] ConstantBuffer g_Const; 31 | 32 | #else 33 | 34 | cbuffer g_Const : register(b0) { Constants g_Const; } 35 | 36 | #endif 37 | 38 | struct VS_INPUT 39 | { 40 | float2 pos : POSITION; 41 | float2 uv : TEXCOORD0; 42 | float4 col : COLOR0; 43 | }; 44 | 45 | struct PS_INPUT 46 | { 47 | float4 out_pos : SV_POSITION; 48 | float4 out_col : COLOR0; 49 | float2 out_uv : TEXCOORD0; 50 | }; 51 | 52 | PS_INPUT main(VS_INPUT input) 53 | { 54 | PS_INPUT output; 55 | output.out_pos.xy = input.pos.xy * g_Const.invDisplaySize * float2(2.0, -2.0) + float2(-1.0, 1.0); 56 | output.out_pos.zw = float2(0, 1); 57 | output.out_col = input.col; 58 | output.out_uv = input.uv; 59 | return output; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /shaders/passes/bloom_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | 27 | cbuffer c_Bloom : register(b0) 28 | { 29 | BloomConstants g_Bloom; 30 | }; 31 | 32 | SamplerState s_Sampler : register(s0); 33 | Texture2D t_Src : register(t0); 34 | 35 | float square(float x) { return x * x; } 36 | 37 | void main( 38 | in float4 pos : SV_Position, 39 | in float2 uv : UV, 40 | out float4 o_rgba : SV_Target 41 | ) 42 | { 43 | float3 result = t_Src[pos.xy].rgb; 44 | 45 | for (float x = 1; x < g_Bloom.numSamples; x += 2) 46 | { 47 | float w1 = exp(square(x) * g_Bloom.argumentScale); 48 | float w2 = exp(square(x + 1) * g_Bloom.argumentScale); 49 | 50 | float w12 = w1 + w2; 51 | float p = w2 / w12; 52 | float2 offset = g_Bloom.pixstep * (x + p); 53 | 54 | result += t_Src.SampleLevel(s_Sampler, uv + offset, 0).rgb * w12; 55 | result += t_Src.SampleLevel(s_Sampler, uv - offset, 0).rgb * w12; 56 | } 57 | 58 | result *= g_Bloom.normalizationScale; 59 | 60 | o_rgba = float4(result, 1.0); 61 | } 62 | -------------------------------------------------------------------------------- /shaders/passes/cubemap_gs.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | struct VSOutput 26 | { 27 | float4 posClip : SV_Position; 28 | SceneVertex vtx; 29 | }; 30 | 31 | struct GSOutput 32 | { 33 | VSOutput Passthrough; 34 | uint ViewportMask : SV_ViewportArrayIndex; 35 | }; 36 | 37 | #define USE_CULLING 1 38 | 39 | int GetVertexPlaneMask(float3 v) 40 | { 41 | return int(v.x < v.y) | 42 | (int(v.x < -v.y) << 1) | 43 | (int(v.x < v.z) << 2) | 44 | (int(v.x < -v.z) << 3) | 45 | (int(v.z < v.y) << 4) | 46 | (int(v.z < -v.y) << 5) | 47 | (int(v.x < 1) << 8) | 48 | (int(v.x > -1) << 9) | 49 | (int(v.y < 1) << 10) | 50 | (int(v.y > -1) << 11) | 51 | (int(v.z < 1) << 12) | 52 | (int(v.z > -1) << 13); 53 | } 54 | 55 | [maxvertexcount(1)] 56 | void main( 57 | triangle VSOutput Input[3], 58 | inout TriangleStream Output) 59 | { 60 | GSOutput OutputVertex; 61 | 62 | OutputVertex.Passthrough = Input[0]; 63 | 64 | #if USE_CULLING 65 | int pm0 = GetVertexPlaneMask(Input[0].posClip.xyz); 66 | int pm1 = GetVertexPlaneMask(Input[1].posClip.xyz); 67 | int pm2 = GetVertexPlaneMask(Input[2].posClip.xyz); 68 | int prim_plane_mask_0 = pm0 & pm1 & pm2; 69 | int prim_plane_mask_1 = ~pm0 & ~pm1 & ~pm2; 70 | int combined_mask = prim_plane_mask_0 | (prim_plane_mask_1 << 16); 71 | 72 | int face_mask = 0; 73 | if((combined_mask & 0x00010f) == 0) face_mask |= 0x01; 74 | if((combined_mask & 0x0f0200) == 0) face_mask |= 0x02; 75 | if((combined_mask & 0x110422) == 0) face_mask |= 0x04; 76 | if((combined_mask & 0x220811) == 0) face_mask |= 0x08; 77 | if((combined_mask & 0x041038) == 0) face_mask |= 0x10; 78 | if((combined_mask & 0x382004) == 0) face_mask |= 0x20; 79 | 80 | OutputVertex.ViewportMask = face_mask; 81 | #else 82 | OutputVertex.ViewportMask = 0x3f; 83 | #endif 84 | 85 | Output.Append(OutputVertex); 86 | } 87 | -------------------------------------------------------------------------------- /shaders/passes/depth_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | Texture2D t_BaseOrDiffuse : register(t0 VK_DESCRIPTOR_SET(1)); 30 | SamplerState s_MaterialSampler : register(s0 VK_DESCRIPTOR_SET(1)); 31 | 32 | cbuffer c_Material : register(b1 VK_DESCRIPTOR_SET(1)) 33 | { 34 | MaterialConstants g_Material; 35 | }; 36 | 37 | void main( 38 | in float4 i_position : SV_Position, 39 | in float2 i_texCoord : TEXCOORD 40 | ) 41 | { 42 | MaterialTextureSample textures = DefaultMaterialTextures(); 43 | textures.baseOrDiffuse = t_BaseOrDiffuse.Sample(s_MaterialSampler, i_texCoord); 44 | 45 | MaterialSample materialSample = EvaluateSceneMaterial(/* normal = */ float3(1, 0, 0), 46 | /* tangent = */ float4(0, 1, 0, 0), g_Material, textures); 47 | 48 | clip(materialSample.opacity - g_Material.alphaCutoff); 49 | } 50 | -------------------------------------------------------------------------------- /shaders/passes/depth_vs.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | #include 25 | 26 | cbuffer c_Depth : register(b0) 27 | { 28 | DepthPassConstants g_Depth; 29 | }; 30 | 31 | void main( 32 | in float3 i_pos : POSITION, 33 | in float2 i_texCoord : TEXCOORD, 34 | in float3x4 i_instanceMatrix : TRANSFORM, 35 | in uint i_instance : SV_InstanceID, 36 | out float4 o_position : SV_Position, 37 | out float2 o_texCoord : TEXCOORD) 38 | { 39 | float3x4 instanceMatrix = i_instanceMatrix; 40 | 41 | float4 worldPos = float4(mul(instanceMatrix, float4(i_pos, 1.0)), 1.0); 42 | o_position = mul(worldPos, g_Depth.matWorldToClip); 43 | 44 | o_texCoord = i_texCoord; 45 | } 46 | -------------------------------------------------------------------------------- /shaders/passes/environment_map_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | 27 | cbuffer c_Sky : register(b0) 28 | { 29 | SkyConstants g_Sky; 30 | }; 31 | 32 | #if LATLONG_TEXTURE 33 | Texture2D t_EnvironmentMap : register(t0); 34 | #else 35 | TextureCube t_EnvironmentMap : register(t0); 36 | #endif 37 | SamplerState s_Sampler : register(s0); 38 | 39 | void main( 40 | in float4 i_position : SV_Position, 41 | in float2 i_uv : UV, 42 | out float4 o_color : SV_Target0 43 | ) 44 | { 45 | float4 clipPos; 46 | clipPos.x = i_uv.x * 2 - 1; 47 | clipPos.y = 1 - i_uv.y * 2; 48 | clipPos.z = 0.5; 49 | clipPos.w = 1; 50 | float4 translatedWorldPos = mul(clipPos, g_Sky.matClipToTranslatedWorld); 51 | float3 direction = normalize(translatedWorldPos.xyz / translatedWorldPos.w); 52 | 53 | #if LATLONG_TEXTURE 54 | float elevation = asin(direction.y); 55 | float azimuth = 0; 56 | if (abs(direction.y) < 1) 57 | azimuth = atan2(direction.z, direction.x); 58 | 59 | const float PI = 3.14159265; 60 | float2 uv; 61 | uv.x = azimuth / (2 * PI) - 0.25; 62 | uv.y = 0.5 - elevation / PI; 63 | 64 | o_color = t_EnvironmentMap.SampleLevel(s_Sampler, uv, 0); 65 | #else 66 | o_color = t_EnvironmentMap.Sample(s_Sampler, float3(direction.x, direction.y, -direction.z)); 67 | #endif 68 | } 69 | -------------------------------------------------------------------------------- /shaders/passes/forward_vs.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | cbuffer c_ForwardView : register(b1 VK_DESCRIPTOR_SET(1)) 30 | { 31 | ForwardShadingViewConstants g_ForwardView; 32 | }; 33 | 34 | void main( 35 | in SceneVertex i_vtx, 36 | in float4 i_instanceMatrix0 : TRANSFORM0, 37 | in float4 i_instanceMatrix1 : TRANSFORM1, 38 | in float4 i_instanceMatrix2 : TRANSFORM2, 39 | in uint i_instance : SV_InstanceID, 40 | out float4 o_position : SV_Position, 41 | out SceneVertex o_vtx 42 | ) 43 | { 44 | float3x4 instanceMatrix = float3x4(i_instanceMatrix0, i_instanceMatrix1, i_instanceMatrix2); 45 | 46 | o_vtx = i_vtx; 47 | o_vtx.pos = mul(instanceMatrix, float4(i_vtx.pos, 1.0)).xyz; 48 | o_vtx.normal = mul(instanceMatrix, float4(i_vtx.normal, 0)).xyz; 49 | o_vtx.tangent.xyz = mul(instanceMatrix, float4(i_vtx.tangent.xyz, 0)).xyz; 50 | o_vtx.tangent.w = i_vtx.tangent.w; 51 | 52 | float4 worldPos = float4(o_vtx.pos, 1.0); 53 | o_position = mul(worldPos, g_ForwardView.view.matWorldToClip); 54 | } 55 | -------------------------------------------------------------------------------- /shaders/passes/gbuffer_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | cbuffer c_GBuffer : register(b1 VK_DESCRIPTOR_SET(1)) 33 | { 34 | GBufferFillConstants c_GBuffer; 35 | }; 36 | 37 | void main( 38 | in float4 i_position : SV_Position, 39 | in SceneVertex i_vtx, 40 | #if MOTION_VECTORS 41 | in float3 i_prevWorldPos : PREV_WORLD_POS, 42 | #endif 43 | in bool i_isFrontFace : SV_IsFrontFace, 44 | out float4 o_channel0 : SV_Target0, 45 | out float4 o_channel1 : SV_Target1, 46 | out float4 o_channel2 : SV_Target2, 47 | out float4 o_channel3 : SV_Target3, 48 | out float4 o_channel4 : SV_Target4 49 | #if MOTION_VECTORS 50 | , out float3 o_motion : SV_Target5 51 | #endif 52 | ) 53 | { 54 | MaterialTextureSample textures = SampleMaterialTexturesAuto(i_vtx.texCoord); 55 | 56 | MaterialSample surface = EvaluateSceneMaterial(i_vtx.normal, i_vtx.tangent, g_Material, textures); 57 | 58 | #if ALPHA_TESTED 59 | if (g_Material.domain != MaterialDomain_Opaque) 60 | clip(surface.opacity - g_Material.alphaCutoff); 61 | #endif 62 | 63 | if (!i_isFrontFace) 64 | surface.shadingNormal = -surface.shadingNormal; 65 | 66 | o_channel0.xyz = surface.diffuseAlbedo; 67 | o_channel0.w = surface.opacity; 68 | o_channel1.xyz = surface.specularF0; 69 | o_channel1.w = surface.occlusion; 70 | o_channel2.xyz = surface.shadingNormal; 71 | o_channel2.w = surface.roughness; 72 | o_channel3.xyz = surface.emissiveColor; 73 | o_channel3.w = 0; 74 | 75 | o_channel4.xyz = i_vtx.pos.xyz; 76 | o_channel4.w = 1.0; 77 | 78 | #if MOTION_VECTORS 79 | o_motion = GetMotionVector(i_position.xyz, i_prevWorldPos, c_GBuffer.view, c_GBuffer.viewPrev); 80 | #endif 81 | } 82 | -------------------------------------------------------------------------------- /shaders/passes/gbuffer_vs.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | cbuffer c_GBuffer : register(b1 VK_DESCRIPTOR_SET(1)) 30 | { 31 | GBufferFillConstants c_GBuffer; 32 | }; 33 | 34 | void main( 35 | in SceneVertex i_vtx, 36 | in float4 i_instanceMatrix0 : TRANSFORM0, 37 | in float4 i_instanceMatrix1 : TRANSFORM1, 38 | in float4 i_instanceMatrix2 : TRANSFORM2, 39 | #if MOTION_VECTORS 40 | in float4 i_prevInstanceMatrix0 : PREV_TRANSFORM0, 41 | in float4 i_prevInstanceMatrix1 : PREV_TRANSFORM1, 42 | in float4 i_prevInstanceMatrix2 : PREV_TRANSFORM2, 43 | #endif 44 | in uint i_instance : SV_InstanceID, 45 | out float4 o_position : SV_Position, 46 | out SceneVertex o_vtx, 47 | #if MOTION_VECTORS 48 | out float3 o_prevWorldPos : PREV_WORLD_POS, 49 | #endif 50 | out uint o_instance : INSTANCE 51 | ) 52 | { 53 | float3x4 instanceMatrix = float3x4(i_instanceMatrix0, i_instanceMatrix1, i_instanceMatrix2); 54 | 55 | o_vtx = i_vtx; 56 | o_vtx.pos = mul(instanceMatrix, float4(i_vtx.pos, 1.0)).xyz; 57 | o_vtx.normal = mul(instanceMatrix, float4(i_vtx.normal, 0)).xyz; 58 | o_vtx.tangent.xyz = mul(instanceMatrix, float4(i_vtx.tangent.xyz, 0)).xyz; 59 | o_vtx.tangent.w = i_vtx.tangent.w; 60 | #if MOTION_VECTORS 61 | float3x4 prevInstanceMatrix = float3x4(i_prevInstanceMatrix0, i_prevInstanceMatrix1, i_prevInstanceMatrix2); 62 | o_prevWorldPos = mul(prevInstanceMatrix, float4(i_vtx.prevPos, 1.0)).xyz; 63 | #endif 64 | 65 | float4 worldPos = float4(o_vtx.pos, 1.0); 66 | float4 viewPos = mul(worldPos, c_GBuffer.view.matWorldToView); 67 | o_position = mul(viewPos, c_GBuffer.view.matViewToClip); 68 | o_instance = i_instance; 69 | } 70 | -------------------------------------------------------------------------------- /shaders/passes/joints.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | // simple line drawing shader for the joints render pass 28 | 29 | cbuffer c_Constants : register(b0 VK_DESCRIPTOR_SET(0)) 30 | { 31 | PlanarViewConstants g_Constants; 32 | }; 33 | 34 | struct VertexAttributes 35 | { 36 | float3 position : POSITION; 37 | uint color : COLOR; 38 | }; 39 | 40 | void main_vs( 41 | in VertexAttributes i_vtx 42 | , in uint i_instanceID : SV_InstanceID 43 | , out float4 o_position : SV_Position 44 | , out float3 o_color : COLOR 45 | ) 46 | { 47 | o_position = mul(float4(i_vtx.position, 1), g_Constants.matWorldToClip); 48 | 49 | o_color = Unpack_RGB8_SNORM(i_vtx.color); 50 | } 51 | 52 | void main_ps( 53 | in float4 i_position : SV_Position 54 | , in float3 i_color : COLOR 55 | , out float4 o_color : SV_Target0 56 | ) 57 | { 58 | o_color = float4(i_color, 1); 59 | } -------------------------------------------------------------------------------- /shaders/passes/material_id_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | struct Constants { 29 | uint instanceOffset; 30 | }; 31 | 32 | #ifdef SPIRV 33 | 34 | VK_PUSH_CONSTANT ConstantBuffer g_Const : register(b2); 35 | 36 | #else 37 | 38 | cbuffer c_Instance : register(b2) 39 | { 40 | Constants g_Const; 41 | }; 42 | 43 | #endif 44 | 45 | void main( 46 | in float4 i_position : SV_Position, 47 | in SceneVertex i_vtx, 48 | in uint i_instance : INSTANCE, 49 | out uint4 o_output : SV_Target0 50 | ) 51 | { 52 | #if ALPHA_TESTED 53 | MaterialTextureSample textures = SampleMaterialTexturesAuto(i_vtx.texCoord); 54 | 55 | MaterialSample surface = EvaluateSceneMaterial(i_vtx.normal, i_vtx.tangent, g_Material, textures); 56 | 57 | clip(surface.opacity - g_Material.alphaCutoff); 58 | #endif 59 | 60 | o_output.x = uint(g_Material.materialID); 61 | o_output.y = g_Const.instanceOffset + i_instance; 62 | o_output.zw = 0; 63 | } 64 | -------------------------------------------------------------------------------- /shaders/passes/motion_vectors_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | 27 | cbuffer c_TemporalAA : register(b0) 28 | { 29 | TemporalAntiAliasingConstants g_TemporalAA; 30 | }; 31 | 32 | Texture2D t_GBufferDepth : register(t0); 33 | #if USE_STENCIL 34 | Texture2D t_GBufferStencil : register(t1); 35 | #endif 36 | 37 | void main( 38 | in float4 i_position : SV_Position, 39 | in float2 i_uv : UV, 40 | out float4 o_color : SV_Target0 41 | ) 42 | { 43 | o_color = 0; 44 | 45 | #if USE_STENCIL 46 | uint stencil = t_GBufferStencil[i_position.xy].y; 47 | if ((stencil & g_TemporalAA.stencilMask) == g_TemporalAA.stencilMask) 48 | discard; 49 | #endif 50 | float depth = t_GBufferDepth[i_position.xy].x; 51 | 52 | float4 clipPos; 53 | clipPos.x = i_uv.x * 2 - 1; 54 | clipPos.y = 1 - i_uv.y * 2; 55 | clipPos.z = depth; 56 | clipPos.w = 1; 57 | 58 | float4 prevClipPos = mul(clipPos, g_TemporalAA.reprojectionMatrix); 59 | 60 | if (prevClipPos.w <= 0) 61 | return; 62 | 63 | prevClipPos.xyz /= prevClipPos.w; 64 | float2 prevUV; 65 | prevUV.x = 0.5 + prevClipPos.x * 0.5; 66 | prevUV.y = 0.5 - prevClipPos.y * 0.5; 67 | 68 | float2 prevWindowPos = prevUV * g_TemporalAA.inputViewSize + g_TemporalAA.inputViewOrigin; 69 | 70 | o_color.xy = prevWindowPos.xy - i_position.xy; 71 | } 72 | -------------------------------------------------------------------------------- /shaders/passes/pixel_readback_cs.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | cbuffer c_PixelReadback : register(b0) 26 | { 27 | PixelReadbackConstants g_PixelReadback; 28 | }; 29 | 30 | #if INPUT_MSAA 31 | Texture2DMS t_Source : register(t0); 32 | #else 33 | Texture2D t_Source : register(t0); 34 | #endif 35 | RWBuffer u_Dest : register(u0); 36 | 37 | [numthreads(1, 1, 1)] 38 | void main() 39 | { 40 | u_Dest[0] = t_Source[g_PixelReadback.pixelPosition.xy]; 41 | } 42 | -------------------------------------------------------------------------------- /shaders/passes/sky_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | 27 | cbuffer c_Sky : register(b0) 28 | { 29 | SkyConstants g_Sky; 30 | }; 31 | 32 | void main( 33 | in float4 i_position : SV_Position, 34 | in float2 i_uv : UV, 35 | out float4 o_color : SV_Target0 36 | ) 37 | { 38 | float4 clipPos; 39 | clipPos.x = i_uv.x * 2 - 1; 40 | clipPos.y = 1 - i_uv.y * 2; 41 | clipPos.z = 0.5; 42 | clipPos.w = 1; 43 | float4 translatedWorldPos = mul(clipPos, g_Sky.matClipToTranslatedWorld); 44 | float3 direction = normalize(translatedWorldPos.xyz / translatedWorldPos.w); 45 | 46 | // length(ddx(dir)) is an approximation for acos(dot(dir, normalize(dir + ddx(dir))) for unit vectors with small derivatives 47 | float angularSizeOfPixel = max(length(ddx(direction)), length(ddy(direction))); 48 | 49 | o_color.rgb = ProceduralSky(g_Sky.params, direction, angularSizeOfPixel); 50 | o_color.a = 0; 51 | } 52 | -------------------------------------------------------------------------------- /shaders/passes/ssao_deinterleave_cs.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma pack_matrix(row_major) 24 | 25 | #include 26 | 27 | Texture2D t_InputDepth : register(t0); 28 | RWTexture2DArray u_DeinterleavedDepth : register(u0); 29 | 30 | cbuffer c_Ssao : register(b0) 31 | { 32 | SsaoConstants g_Ssao; 33 | }; 34 | 35 | [numthreads(8, 8, 1)] 36 | void main(uint3 globalId : SV_DispatchThreadID) 37 | { 38 | float depths[16]; 39 | uint2 groupBase = globalId.xy * 4 + g_Ssao.quantizedViewportOrigin; 40 | 41 | [unroll] 42 | for (uint y = 0; y < 4; y++) 43 | { 44 | [unroll] 45 | for (uint x = 0; x < 4; x++) 46 | { 47 | uint2 gbufferSamplePos = groupBase + uint2(x, y); 48 | float depth = t_InputDepth[gbufferSamplePos]; 49 | 50 | #if LINEAR_DEPTH 51 | float linearDepth = depth; 52 | #else 53 | float4 clipPos = float4(0, 0, depth, 1); 54 | float4 viewPos = mul(clipPos, g_Ssao.view.matClipToView); 55 | float linearDepth = viewPos.z / viewPos.w; 56 | #endif 57 | 58 | depths[y * 4 + x] = linearDepth; 59 | } 60 | } 61 | 62 | uint2 quarterResPos = groupBase >> 2; 63 | 64 | [unroll] 65 | for(uint index = 0; index < 16; index++) 66 | { 67 | float depth = depths[index]; 68 | u_DeinterleavedDepth[uint3(quarterResPos.xy, index)] = depth; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /shaders/rect_vs.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | #ifdef SPIRV 26 | 27 | [[vk::push_constant]] ConstantBuffer g_Blit; 28 | 29 | #else 30 | 31 | cbuffer g_Blit : register(b0) { BlitConstants g_Blit; } 32 | 33 | #endif 34 | 35 | void main( 36 | in uint iVertex : SV_VertexID, 37 | out float4 o_posClip : SV_Position, 38 | out float2 o_uv : UV) 39 | { 40 | uint u = iVertex & 1; 41 | uint v = (iVertex >> 1) & 1; 42 | 43 | float2 src_uv = float2(u, v) * g_Blit.sourceSize + g_Blit.sourceOrigin; 44 | float2 dst_uv = float2(u, v) * g_Blit.targetSize + g_Blit.targetOrigin; 45 | 46 | o_posClip = float4(dst_uv.x * 2 - 1, 1 - dst_uv.y * 2, 0, 1); 47 | o_uv = src_uv; 48 | } 49 | -------------------------------------------------------------------------------- /shaders/sharpen_ps.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | #if TEXTURE_ARRAY 26 | Texture2DArray tex : register(t0); 27 | #else 28 | Texture2D tex : register(t0); 29 | #endif 30 | SamplerState samp : register(s0); 31 | 32 | cbuffer c_Blit : register(b0) 33 | { 34 | BlitConstants g_Blit; 35 | }; 36 | 37 | void main( 38 | in float4 i_pos : SV_Position, 39 | in float2 i_uv : UV, 40 | out float4 o_rgba : SV_Target) 41 | { 42 | #if TEXTURE_ARRAY 43 | float4 x = tex.SampleLevel(samp, float3(i_uv, 0), 0); 44 | 45 | float4 a = tex.SampleLevel(samp, float3(i_uv, 0), 0, int2(-1, 0)); 46 | float4 b = tex.SampleLevel(samp, float3(i_uv, 0), 0, int2( 1, 0)); 47 | float4 c = tex.SampleLevel(samp, float3(i_uv, 0), 0, int2( 0, 1)); 48 | float4 d = tex.SampleLevel(samp, float3(i_uv, 0), 0, int2( 0, -1)); 49 | 50 | float4 e = tex.SampleLevel(samp, float3(i_uv, 0), 0, int2(-1, -1)); 51 | float4 f = tex.SampleLevel(samp, float3(i_uv, 0), 0, int2( 1, 1)); 52 | float4 g = tex.SampleLevel(samp, float3(i_uv, 0), 0, int2(-1, 1)); 53 | float4 h = tex.SampleLevel(samp, float3(i_uv, 0), 0, int2( 1, -1)); 54 | #else 55 | float4 x = tex.SampleLevel(samp, i_uv, 0); 56 | 57 | float4 a = tex.SampleLevel(samp, i_uv, 0, int2(-1, 0)); 58 | float4 b = tex.SampleLevel(samp, i_uv, 0, int2( 1, 0)); 59 | float4 c = tex.SampleLevel(samp, i_uv, 0, int2( 0, 1)); 60 | float4 d = tex.SampleLevel(samp, i_uv, 0, int2( 0, -1)); 61 | 62 | float4 e = tex.SampleLevel(samp, i_uv, 0, int2(-1, -1)); 63 | float4 f = tex.SampleLevel(samp, i_uv, 0, int2( 1, 1)); 64 | float4 g = tex.SampleLevel(samp, i_uv, 0, int2(-1, 1)); 65 | float4 h = tex.SampleLevel(samp, i_uv, 0, int2( 1, -1)); 66 | #endif 67 | 68 | o_rgba = x * (6.828427 * g_Blit.sharpenFactor + 1) 69 | - (a + b + c + d) * g_Blit.sharpenFactor 70 | - (e + g + f + h) * g_Blit.sharpenFactor * 0.7071; 71 | } 72 | -------------------------------------------------------------------------------- /signatures/CLA.json: -------------------------------------------------------------------------------- 1 | { 2 | "signedContributors": [ 3 | { 4 | "name": "tksgmsy", 5 | "id": 5753935, 6 | "comment_id": 1108207514, 7 | "created_at": "2022-04-25T07:55:37Z", 8 | "repoId": 467769186, 9 | "pullRequestNo": 6 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /src/engine/BindingCache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | using namespace donut::engine; 26 | 27 | nvrhi::BindingSetHandle BindingCache::GetCachedBindingSet(const nvrhi::BindingSetDesc& desc, nvrhi::IBindingLayout* layout) 28 | { 29 | size_t hash = 0; 30 | nvrhi::hash_combine(hash, desc); 31 | nvrhi::hash_combine(hash, layout); 32 | 33 | m_Mutex.lock_shared(); 34 | 35 | nvrhi::BindingSetHandle result = nullptr; 36 | auto it = m_BindingSets.find(hash); 37 | if (it != m_BindingSets.end()) 38 | result = it->second; 39 | 40 | m_Mutex.unlock_shared(); 41 | 42 | if (result) 43 | { 44 | assert(result->getDesc()); 45 | assert(*result->getDesc() == desc); 46 | } 47 | 48 | return result; 49 | } 50 | 51 | nvrhi::BindingSetHandle BindingCache::GetOrCreateBindingSet(const nvrhi::BindingSetDesc& desc, nvrhi::IBindingLayout* layout) 52 | { 53 | size_t hash = 0; 54 | nvrhi::hash_combine(hash, desc); 55 | nvrhi::hash_combine(hash, layout); 56 | 57 | m_Mutex.lock_shared(); 58 | 59 | nvrhi::BindingSetHandle result; 60 | auto it = m_BindingSets.find(hash); 61 | if (it != m_BindingSets.end()) 62 | result = it->second; 63 | 64 | m_Mutex.unlock_shared(); 65 | 66 | if (!result) 67 | { 68 | m_Mutex.lock(); 69 | 70 | nvrhi::BindingSetHandle& entry = m_BindingSets[hash]; 71 | if (!entry) 72 | { 73 | result = m_Device->createBindingSet(desc, layout); 74 | entry = result; 75 | } 76 | else 77 | result = entry; 78 | 79 | m_Mutex.unlock(); 80 | } 81 | 82 | if (result) 83 | { 84 | assert(result->getDesc()); 85 | assert(*result->getDesc() == desc); 86 | } 87 | 88 | return result; 89 | } 90 | 91 | void BindingCache::Clear() 92 | { 93 | m_Mutex.lock(); 94 | m_BindingSets.clear(); 95 | m_Mutex.unlock(); 96 | } 97 | -------------------------------------------------------------------------------- /src/engine/FramebufferFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | using namespace donut::engine; 27 | 28 | nvrhi::IFramebuffer* FramebufferFactory::GetFramebuffer(const nvrhi::TextureSubresourceSet& subresources) 29 | { 30 | nvrhi::FramebufferHandle& item = m_FramebufferCache[subresources]; 31 | 32 | if (!item) 33 | { 34 | nvrhi::FramebufferDesc desc; 35 | for (auto renderTarget : RenderTargets) 36 | desc.addColorAttachment(renderTarget, subresources); 37 | 38 | if (DepthTarget) 39 | desc.setDepthAttachment(DepthTarget, subresources); 40 | 41 | if (ShadingRateSurface) 42 | desc.setShadingRateAttachment(ShadingRateSurface, subresources); 43 | 44 | item = m_Device->createFramebuffer(desc); 45 | } 46 | 47 | return item; 48 | } 49 | 50 | nvrhi::IFramebuffer* FramebufferFactory::GetFramebuffer(const IView& view) 51 | { 52 | return GetFramebuffer(view.GetSubresources()); 53 | } 54 | -------------------------------------------------------------------------------- /src/engine/stb_impl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | License for stb 25 | 26 | Public Domain 27 | 28 | This is free and unencumbered software released into the public domain. 29 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 30 | software, either in source code form or as a compiled binary, for any purpose, 31 | commercial or non-commercial, and by any means. 32 | 33 | In jurisdictions that recognize copyright laws, the author or authors of this 34 | software dedicate any and all copyright interest in the software to the public 35 | domain. We make this dedication for the benefit of the public at large and to 36 | the detriment of our heirs and successors. We intend this dedication to be an 37 | overt act of relinquishment in perpetuity of all present and future rights to 38 | this software under copyright law. 39 | 40 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 41 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 42 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 43 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 44 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 45 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 46 | */ 47 | 48 | #define STB_IMAGE_IMPLEMENTATION 49 | #define STB_IMAGE_WRITE_IMPLEMENTATION 50 | 51 | #include "stb_image.h" 52 | #include "stb_image_write.h" 53 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | # build small library of common untilities for tests 24 | 25 | add_library(donut_tests_utils STATIC src/utils.cpp) 26 | target_include_directories(donut_tests_utils PUBLIC "include") 27 | set_property(TARGET donut_tests_utils PROPERTY FOLDER "Donut/donut_tests") 28 | 29 | # XXXX mk : CTest does not create (yet?) a default build target for all tests 30 | add_custom_target(donut_all_tests) 31 | set_property(TARGET donut_all_tests PROPERTY FOLDER "Donut/donut_tests") 32 | 33 | # 34 | # Add tests for each donut module 35 | # 36 | 37 | add_definitions(-DDONUT_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") 38 | add_definitions(-DDONUT_TEST_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}") 39 | 40 | include(test-core.cmake) 41 | 42 | if (DONUT_WITH_NVRHI) 43 | include(test-engine.cmake) 44 | endif() 45 | -------------------------------------------------------------------------------- /tests/include/donut/tests/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | #ifndef __PRETTY_FUNCTION__ 29 | #ifdef _MSC_VER 30 | #define __PRETTY_FUNCTION__ __FUNCSIG__ 31 | #endif 32 | #endif 33 | 34 | #define CHECK(condition) \ 35 | if (!(condition)) { throw std::runtime_error(std::string(__FILE__) + ':' + std::to_string(__LINE__) + ':' + __PRETTY_FUNCTION__); } 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /tests/src/utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | -------------------------------------------------------------------------------- /tests/test-core.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | file(GLOB donut_core_tests src/core/test_*.cpp) 24 | 25 | foreach(test_src ${donut_core_tests}) 26 | 27 | get_filename_component(test_name "${test_src}" NAME_WE) 28 | #message(STATUS "Added test ${test_name}") 29 | 30 | add_executable("${test_name}" "${test_src}") 31 | target_link_libraries("${test_name}" donut_core donut_tests_utils) 32 | 33 | add_dependencies(donut_all_tests "${test_name}") 34 | 35 | add_test("${test_name}" "${test_name}") 36 | 37 | set_property(TARGET "${test_name}" PROPERTY FOLDER "Donut/donut_tests/donut_core_tests") 38 | 39 | endforeach() 40 | 41 | -------------------------------------------------------------------------------- /tests/test-engine.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | file(GLOB donut_engine_tests src/engine/test_*.cpp) 24 | 25 | foreach(test_src ${donut_engine_tests}) 26 | 27 | get_filename_component(test_name "${test_src}" NAME_WE) 28 | #message(STATUS "Added test ${test_name}") 29 | 30 | add_executable("${test_name}" "${test_src}") 31 | target_link_libraries("${test_name}" donut_engine donut_core donut_tests_utils) 32 | 33 | add_dependencies(donut_all_tests "${test_name}") 34 | 35 | add_test("${test_name}" "${test_name}") 36 | 37 | set_property(TARGET "${test_name}" PROPERTY FOLDER "Donut/donut_tests/donut_engine_tests") 38 | 39 | endforeach() 40 | 41 | -------------------------------------------------------------------------------- /thirdparty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | # Required dependencies 24 | set(third_party_folder "Third-Party Libraries") 25 | 26 | set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) 27 | 28 | if (DONUT_WITH_NVRHI AND NOT TARGET imgui) 29 | include(imgui.cmake) 30 | set_target_properties(imgui PROPERTIES FOLDER ${third_party_folder}) 31 | endif() 32 | 33 | if (NOT TARGET jsoncpp_static) 34 | include(jsoncpp.cmake) 35 | set_target_properties(jsoncpp_static PROPERTIES FOLDER ${third_party_folder}) 36 | endif() 37 | 38 | if (NOT TARGET stb) 39 | add_library(stb INTERFACE) 40 | target_include_directories(stb INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/stb) 41 | endif() 42 | 43 | if (NOT TARGET cgltf) 44 | add_library(cgltf INTERFACE) 45 | target_include_directories(cgltf INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/cgltf) 46 | endif() 47 | 48 | # Optional dependencies 49 | 50 | if (DONUT_WITH_TINYEXR AND NOT TARGET tinyexr) 51 | add_library(tinyexr INTERFACE) 52 | target_include_directories(tinyexr INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tinyexr) 53 | endif() 54 | 55 | if (DONUT_WITH_TASKFLOW AND NOT TARGET taskflow) 56 | add_library(taskflow INTERFACE) 57 | target_include_directories(taskflow INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/taskflow) 58 | endif() 59 | 60 | if (DONUT_WITH_NVRHI AND NOT TARGET glfw) 61 | option(GLFW_BUILD_EXAMPLES "" OFF) 62 | option(GLFW_BUILD_TESTS "" OFF) 63 | option(GLFW_BUILD_DOCS "" OFF) 64 | option(GLFW_INSTALL "" OFF) 65 | add_subdirectory(glfw) 66 | set_target_properties(glfw PROPERTIES FOLDER ${third_party_folder}) 67 | endif() 68 | 69 | if (DONUT_WITH_LZ4 AND NOT TARGET lz4) 70 | include(lz4.cmake) 71 | set_target_properties(lz4 PROPERTIES FOLDER ${third_party_folder}) 72 | endif() 73 | 74 | if (DONUT_WITH_MINIZ AND NOT TARGET miniz) 75 | add_subdirectory(miniz) 76 | set_target_properties(miniz PROPERTIES FOLDER ${third_party_folder}) 77 | endif() 78 | -------------------------------------------------------------------------------- /thirdparty/imgui.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | set(imgui_srcs 24 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imconfig.h 25 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_draw.cpp 26 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_tables.cpp 27 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_widgets.cpp 28 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_internal.h 29 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui.cpp 30 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui.h 31 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imstb_rectpack.h 32 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imstb_textedit.h 33 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imstb_truetype.h 34 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_demo.cpp) 35 | 36 | add_library(imgui STATIC ${imgui_srcs}) 37 | target_include_directories(imgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui) 38 | -------------------------------------------------------------------------------- /thirdparty/jsoncpp.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | set(JSONCPP_WITH_TESTS OFF CACHE BOOL "") 24 | set(JSONCPP_WITH_POST_BUILD_UNITTEST OFF CACHE BOOL "") 25 | set(JSONCPP_WITH_PKGCONFIG_SUPPORT OFF CACHE BOOL "") 26 | set(JSONCPP_WITH_CMAKE_PACKAGE OFF CACHE BOOL "") 27 | 28 | set(__tmp_shared_libs ${BUILD_SHARED_LIBS}) 29 | set(__tmp_static_libs ${BUILD_STATIC_LIBS}) 30 | set(__tmp_object_libs ${BUILD_OBJECT_LIBS}) 31 | 32 | # Save the paths because jsoncpp overrides them. 33 | set(__tmp_archive_output_dir ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) 34 | set(__tmp_library_output_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) 35 | set(__tmp_pdb_output_dir ${CMAKE_PDB_OUTPUT_DIRECTORY}) 36 | set(__tmp_runtime_output_dir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 37 | 38 | set(BUILD_SHARED_LIBS OFF) 39 | set(BUILD_STATIC_LIBS ON) 40 | set(BUILD_OBJECT_LIBS OFF) 41 | 42 | add_subdirectory(jsoncpp) 43 | 44 | set(BUILD_SHARED_LIBS ${__tmp_shared_libs}) 45 | set(BUILD_STATIC_LIBS ${__tmp_static_libs}) 46 | set(BUILD_OBJECT_LIBS ${__tmp_object_libs}) 47 | 48 | # Restore the paths. 49 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${__tmp_archive_output_dir} CACHE STRING "" FORCE) 50 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${__tmp_library_output_dir} CACHE STRING "" FORCE) 51 | set(CMAKE_PDB_OUTPUT_DIRECTORY ${__tmp_pdb_output_dir} CACHE STRING "" FORCE) 52 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${__tmp_runtime_output_dir} CACHE STRING "" FORCE) 53 | -------------------------------------------------------------------------------- /thirdparty/lz4.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | # DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | file(GLOB lz4_src 24 | "lz4/lib/*.c" 25 | "lz4/lib/*.h" 26 | ) 27 | 28 | add_library(lz4 STATIC EXCLUDE_FROM_ALL ${lz4_src}) 29 | target_include_directories(lz4 INTERFACE lz4/lib) 30 | -------------------------------------------------------------------------------- /thirdparty/taskflow/LICENSE: -------------------------------------------------------------------------------- 1 | Taskflow LICENSE 2 | 3 | Copyright (c) 2018-2020 T.-W. Huang, C.-X. Lin, G. Guo, and M. Wong 4 | 5 | University of Utah, Salt Lake City, UT, USA 6 | University of Illinois at Urbana-Champaign, IL, USA 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | -------------------------------------------------------------------------------- /thirdparty/taskflow/README.txt: -------------------------------------------------------------------------------- 1 | This is an unmodified copy of the Taskflow implementation from https://github.com/taskflow/taskflow 2 | 3 | We don't include it as a submodule because their git repository includes lots of unnecessary files. 4 | 5 | Original version: v3.1.0 6 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/core/algorithm/critical.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../task.hpp" 4 | 5 | /** 6 | @file critical.hpp 7 | @brief critical include file 8 | */ 9 | 10 | namespace tf { 11 | 12 | // ---------------------------------------------------------------------------- 13 | // CriticalSection 14 | // ---------------------------------------------------------------------------- 15 | 16 | /** 17 | @class CriticalSection 18 | 19 | @brief class to create a critical region of limited workers to run tasks 20 | 21 | tf::CriticalSection is a warpper over tf::Semaphore and is specialized for 22 | limiting the maximum concurrency over a set of tasks. 23 | A critical section starts with an initial count representing that limit. 24 | When a task is added to the critical section, 25 | the task acquires and releases the semaphore internal to the critical section. 26 | This design avoids explicit call of tf::Task::acquire and tf::Task::release. 27 | The following example creates a critical section of one worker and adds 28 | the five tasks to the critical section. 29 | 30 | @code{.cpp} 31 | tf::Executor executor(8); // create an executor of 8 workers 32 | tf::Taskflow taskflow; 33 | 34 | // create a critical section of 1 worker 35 | tf::CriticalSection critical_section(1); 36 | 37 | tf::Task A = taskflow.emplace([](){ std::cout << "A" << std::endl; }); 38 | tf::Task B = taskflow.emplace([](){ std::cout << "B" << std::endl; }); 39 | tf::Task C = taskflow.emplace([](){ std::cout << "C" << std::endl; }); 40 | tf::Task D = taskflow.emplace([](){ std::cout << "D" << std::endl; }); 41 | tf::Task E = taskflow.emplace([](){ std::cout << "E" << std::endl; }); 42 | 43 | critical_section.add(A, B, C, D, E); 44 | 45 | executor.run(taskflow).wait(); 46 | @endcode 47 | 48 | */ 49 | class CriticalSection : public Semaphore { 50 | 51 | public: 52 | 53 | /** 54 | @brief constructs a critical region of a limited number of workers 55 | */ 56 | explicit CriticalSection(int max_workers = 1); 57 | 58 | /** 59 | @brief adds a task into the critical region 60 | */ 61 | template 62 | void add(Tasks...tasks); 63 | }; 64 | 65 | inline CriticalSection::CriticalSection(int max_workers) : 66 | Semaphore {max_workers} { 67 | } 68 | 69 | template 70 | void CriticalSection::add(Tasks... tasks) { 71 | (tasks.acquire(*this), ...); 72 | (tasks.release(*this), ...); 73 | } 74 | 75 | 76 | } // end of namespace tf. --------------------------------------------------- 77 | 78 | 79 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/core/declarations.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace tf { 4 | 5 | // taskflow 6 | class AsyncTopology; 7 | class Node; 8 | class Graph; 9 | class FlowBuilder; 10 | class Semaphore; 11 | class Subflow; 12 | class Task; 13 | class TaskView; 14 | class Taskflow; 15 | class Topology; 16 | class TopologyBase; 17 | class Executor; 18 | class WorkerView; 19 | class ObserverInterface; 20 | class ChromeTracingObserver; 21 | class TFProfObserver; 22 | class TFProfManager; 23 | 24 | template 25 | class Future; 26 | 27 | // cudaFlow 28 | class cudaNode; 29 | class cudaGraph; 30 | class cudaTask; 31 | class cudaFlow; 32 | class cudaFlowCapturer; 33 | class cudaFlowCapturerBase; 34 | class cudaCapturingBase; 35 | class cudaSequentialCapturing; 36 | class cudaRoundRobinCapturing; 37 | class cublasFlowCapturer; 38 | 39 | // syclFlow 40 | class syclNode; 41 | class syclGraph; 42 | class syclTask; 43 | class syclFlow; 44 | 45 | 46 | } // end of namespace tf ----------------------------------------------------- 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/core/environment.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define TF_ENABLE_PROFILER "TF_ENABLE_PROFILER" 4 | 5 | namespace tf { 6 | 7 | } // end of namespace tf ----------------------------------------------------- 8 | 9 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/core/error.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../utility/stream.hpp" 8 | 9 | namespace tf { 10 | 11 | // Procedure: throw_se 12 | // Throws the system error under a given error code. 13 | template 14 | //void throw_se(const char* fname, const size_t line, Error::Code c, ArgsT&&... args) { 15 | void throw_re(const char* fname, const size_t line, ArgsT&&... args) { 16 | std::ostringstream oss; 17 | oss << "[" << fname << ":" << line << "] "; 18 | //ostreamize(oss, std::forward(args)...); 19 | (oss << ... << args); 20 | throw std::runtime_error(oss.str()); 21 | } 22 | 23 | } // ------------------------------------------------------------------------ 24 | 25 | #define TF_THROW(...) tf::throw_re(__FILE__, __LINE__, __VA_ARGS__); 26 | 27 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/core/topology.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace tf { 4 | 5 | // ---------------------------------------------------------------------------- 6 | 7 | // class: TopologyBase 8 | class TopologyBase { 9 | 10 | friend class Executor; 11 | friend class Node; 12 | 13 | template 14 | friend class Future; 15 | 16 | protected: 17 | 18 | bool _is_cancelled { false }; 19 | }; 20 | 21 | // ---------------------------------------------------------------------------- 22 | 23 | // class: AsyncTopology 24 | class AsyncTopology : public TopologyBase { 25 | }; 26 | 27 | // ---------------------------------------------------------------------------- 28 | 29 | // class: Topology 30 | class Topology : public TopologyBase { 31 | 32 | friend class Executor; 33 | 34 | public: 35 | 36 | template 37 | Topology(Taskflow&, P&&, C&&); 38 | 39 | private: 40 | 41 | Taskflow& _taskflow; 42 | 43 | std::promise _promise; 44 | 45 | std::vector _sources; 46 | 47 | std::function _pred; 48 | std::function _call; 49 | 50 | std::atomic _join_counter {0}; 51 | }; 52 | 53 | // Constructor 54 | template 55 | Topology::Topology(Taskflow& tf, P&& p, C&& c): 56 | _taskflow(tf), 57 | _pred {std::forward

(p)}, 58 | _call {std::forward(c)} { 59 | } 60 | 61 | } // end of namespace tf. ---------------------------------------------------- 62 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/core/worker.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "declarations.hpp" 4 | #include "tsq.hpp" 5 | #include "notifier.hpp" 6 | 7 | /** 8 | @file worker.hpp 9 | @brief worker include file 10 | */ 11 | 12 | namespace tf { 13 | 14 | /** 15 | @private 16 | */ 17 | struct Worker { 18 | 19 | friend class Executor; 20 | friend class WorkerView; 21 | 22 | private: 23 | 24 | size_t _id; 25 | size_t _vtm; 26 | Executor* _executor; 27 | Notifier::Waiter* _waiter; 28 | std::default_random_engine _rdgen { std::random_device{}() }; 29 | TaskQueue _wsq; 30 | }; 31 | 32 | // ---------------------------------------------------------------------------- 33 | // Class Definition: WorkerView 34 | // ---------------------------------------------------------------------------- 35 | 36 | /** 37 | @class WorkerView 38 | 39 | @brief class to create an immutable view of a worker in an executor 40 | 41 | An executor keeps a set of internal worker threads to run tasks. 42 | A worker view provides users an immutable interface to observe 43 | when a worker runs a task, and the view object is only accessible 44 | from an observer derived from tf::ObserverInterface. 45 | */ 46 | class WorkerView { 47 | 48 | friend class Executor; 49 | 50 | public: 51 | 52 | /** 53 | @brief queries the worker id associated with the executor 54 | 55 | A worker id is a unsigned integer in the range [0, N), 56 | where @c N is the number of workers spawned at the construction 57 | time of the executor. 58 | */ 59 | size_t id() const; 60 | 61 | /** 62 | @brief queries the size of the queue (i.e., number of pending tasks to 63 | run) associated with the worker 64 | */ 65 | size_t queue_size() const; 66 | 67 | /** 68 | @brief queries the current capacity of the queue 69 | */ 70 | size_t queue_capacity() const; 71 | 72 | private: 73 | 74 | WorkerView(const Worker&); 75 | WorkerView(const WorkerView&) = default; 76 | 77 | const Worker& _worker; 78 | 79 | }; 80 | 81 | // Constructor 82 | inline WorkerView::WorkerView(const Worker& w) : _worker{w} { 83 | } 84 | 85 | // function: id 86 | inline size_t WorkerView::id() const { 87 | return _worker._id; 88 | } 89 | 90 | // Function: queue_size 91 | inline size_t WorkerView::queue_size() const { 92 | return _worker._wsq.size(); 93 | } 94 | 95 | // Function: queue_capacity 96 | inline size_t WorkerView::queue_capacity() const { 97 | return static_cast(_worker._wsq.capacity()); 98 | } 99 | 100 | 101 | } // end of namespact tf ----------------------------------------------------- 102 | 103 | 104 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/cublasflow.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // taskflow.hpp 4 | // ^ 5 | // | 6 | // cudaflow.hpp 7 | // ^ 8 | // | 9 | // cublasflow.hpp 10 | 11 | #include "cudaflow.hpp" 12 | 13 | #include "cuda/cublas/cublas_flow.hpp" 14 | #include "cuda/cublas/cublas_helper.hpp" 15 | #include "cuda/cublas/cublas_level1.hpp" 16 | #include "cuda/cublas/cublas_level2.hpp" 17 | #include "cuda/cublas/cublas_level3.hpp" 18 | 19 | /** 20 | @file cublasflow.hpp 21 | @brief main cublasFlow include file 22 | */ 23 | 24 | 25 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/cuda/cublas/cublas_error.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace tf { 6 | 7 | // cuBLAS API errors 8 | constexpr const char* cublas_error_to_string(cublasStatus_t error) { 9 | switch (error) { 10 | case CUBLAS_STATUS_SUCCESS: 11 | return "CUBLAS_STATUS_SUCCESS"; 12 | 13 | case CUBLAS_STATUS_NOT_INITIALIZED: 14 | return "CUBLAS_STATUS_NOT_INITIALIZED"; 15 | 16 | case CUBLAS_STATUS_ALLOC_FAILED: 17 | return "CUBLAS_STATUS_ALLOC_FAILED"; 18 | 19 | case CUBLAS_STATUS_INVALID_VALUE: 20 | return "CUBLAS_STATUS_INVALID_VALUE"; 21 | 22 | case CUBLAS_STATUS_ARCH_MISMATCH: 23 | return "CUBLAS_STATUS_ARCH_MISMATCH"; 24 | 25 | case CUBLAS_STATUS_MAPPING_ERROR: 26 | return "CUBLAS_STATUS_MAPPING_ERROR"; 27 | 28 | case CUBLAS_STATUS_EXECUTION_FAILED: 29 | return "CUBLAS_STATUS_EXECUTION_FAILED"; 30 | 31 | case CUBLAS_STATUS_INTERNAL_ERROR: 32 | return "CUBLAS_STATUS_INTERNAL_ERROR"; 33 | 34 | case CUBLAS_STATUS_NOT_SUPPORTED: 35 | return "CUBLAS_STATUS_NOT_SUPPORTED"; 36 | 37 | case CUBLAS_STATUS_LICENSE_ERROR: 38 | return "CUBLAS_STATUS_LICENSE_ERROR"; 39 | } 40 | 41 | return "unknown cublas error"; 42 | } 43 | 44 | 45 | 46 | #define TF_CHECK_CUBLAS(...) \ 47 | if(TF_CUDA_GET_FIRST(__VA_ARGS__) != CUBLAS_STATUS_SUCCESS) { \ 48 | std::ostringstream oss; \ 49 | auto ev = TF_CUDA_GET_FIRST(__VA_ARGS__); \ 50 | auto error_str = cublas_error_to_string(ev); \ 51 | oss << "[" << __FILE__ << ":" << __LINE__ << " " \ 52 | << error_str << "] "; \ 53 | tf::ostreamize(oss, TF_CUDA_REMOVE_FIRST(__VA_ARGS__)); \ 54 | throw std::runtime_error(oss.str()); \ 55 | } 56 | 57 | 58 | } // end of namespace tf ----------------------------------------------------- 59 | 60 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/cuda/cublas/cublas_helper.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cublas_handle.hpp" 4 | 5 | namespace tf { 6 | 7 | // ---------------------------------------------------------------------------- 8 | // global utility functions 9 | // ---------------------------------------------------------------------------- 10 | // find the tranposed op 11 | template && std::is_same_v, void>* = nullptr 13 | > 14 | constexpr cublasOperation_t cublas_rtran(cublasOperation_t op) { 15 | if(op != CUBLAS_OP_N && op != CUBLAS_OP_T) { 16 | TF_THROW("invalid transposition op for floating data types"); 17 | } 18 | return (op == CUBLAS_OP_N) ? CUBLAS_OP_T : CUBLAS_OP_N; 19 | } 20 | 21 | // find the transposed fill 22 | constexpr cublasFillMode_t cublas_rfill(cublasFillMode_t uplo) { 23 | switch(uplo) { 24 | case CUBLAS_FILL_MODE_LOWER: return CUBLAS_FILL_MODE_UPPER; 25 | case CUBLAS_FILL_MODE_UPPER: return CUBLAS_FILL_MODE_LOWER; 26 | default: return uplo; 27 | } 28 | } 29 | 30 | // find the transposed side 31 | constexpr cublasSideMode_t cublas_rside(cublasSideMode_t side) { 32 | switch(side) { 33 | case CUBLAS_SIDE_LEFT : return CUBLAS_SIDE_RIGHT; 34 | case CUBLAS_SIDE_RIGHT: return CUBLAS_SIDE_LEFT; 35 | default: return side; 36 | } 37 | } 38 | 39 | // ---------------------------------------------------------------------------- 40 | // cublasFlowCapturer helper functions 41 | // ---------------------------------------------------------------------------- 42 | 43 | // Function: vset 44 | template , void>* 46 | > 47 | cudaTask cublasFlowCapturer::vset( 48 | size_t n, const T* h, int inch, T* d, int incd 49 | ) { 50 | return factory()->on([n, h, inch, d, incd] (cudaStream_t stream) mutable { 51 | TF_CHECK_CUBLAS( 52 | cublasSetVectorAsync(n, sizeof(T), h, inch, d, incd, stream), 53 | "failed to run vset_async" 54 | ); 55 | }); 56 | } 57 | 58 | // Function: vget 59 | template , void>* 61 | > 62 | cudaTask cublasFlowCapturer::vget(size_t n, const T* d, int incd, T* h, int inch) { 63 | return factory()->on([n, d, incd, h, inch] (cudaStream_t stream) mutable { 64 | TF_CHECK_CUBLAS( 65 | cublasGetVectorAsync(n, sizeof(T), d, incd, h, inch, stream), 66 | "failed to run vget_async" 67 | ); 68 | }); 69 | } 70 | 71 | } // end of namespace tf ----------------------------------------------------- 72 | 73 | 74 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/cuda/cuda_algorithm/cuda_matmul.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../cuda_error.hpp" 4 | 5 | namespace tf { 6 | 7 | // ---------------------------------------------------------------------------- 8 | // row-major matrix multiplication 9 | // ---------------------------------------------------------------------------- 10 | 11 | template 12 | __global__ void cuda_matmul( 13 | const T* A, 14 | const T* B, 15 | T* C, 16 | size_t M, 17 | size_t K, 18 | size_t N 19 | ) { 20 | __shared__ T A_tile[32][32]; 21 | __shared__ T B_tile[32][32]; 22 | 23 | size_t x = blockIdx.x * blockDim.x + threadIdx.x; 24 | size_t y = blockIdx.y * blockDim.y + threadIdx.y; 25 | 26 | T res = 0; 27 | 28 | for(size_t k = 0; k < K; k += 32) { 29 | if((threadIdx.x + k) < K && y < M) { 30 | A_tile[threadIdx.y][threadIdx.x] = A[y * K + threadIdx.x + k]; 31 | } 32 | else{ 33 | A_tile[threadIdx.y][threadIdx.x] = 0; 34 | } 35 | 36 | if((threadIdx.y + k) < K && x < N) { 37 | B_tile[threadIdx.y][threadIdx.x] = B[(threadIdx.y + k) * N + x]; 38 | } 39 | else{ 40 | B_tile[threadIdx.y][threadIdx.x] = 0; 41 | } 42 | 43 | __syncthreads(); 44 | 45 | for(size_t i = 0; i < 32; ++i) { 46 | res += A_tile[threadIdx.y][i] * B_tile[i][threadIdx.x]; 47 | } 48 | __syncthreads(); 49 | } 50 | 51 | if(x < N && y < M) { 52 | C[y * N + x] = res; 53 | } 54 | 55 | } 56 | 57 | } // end of namespace tf --------------------------------------------------------- 58 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/cuda/cuda_algorithm/cuda_transform.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../cuda_flow.hpp" 4 | #include "../cuda_capturer.hpp" 5 | 6 | namespace tf { 7 | 8 | // ---------------------------------------------------------------------------- 9 | // transform 10 | // ---------------------------------------------------------------------------- 11 | 12 | // Kernel: for_each 13 | template 14 | __global__ void cuda_transform(I first, size_t N, F op, S... srcs) { 15 | size_t i = blockIdx.x*blockDim.x + threadIdx.x; 16 | if (i < N) { 17 | //data[i] = op(src[i]...); 18 | *(first + i) = op((*(srcs+i))...); 19 | } 20 | } 21 | 22 | // ---------------------------------------------------------------------------- 23 | // cudaFlow 24 | // ---------------------------------------------------------------------------- 25 | 26 | // Function: transform 27 | template 28 | cudaTask cudaFlow::transform(I first, I last, C&& c, S... srcs) { 29 | 30 | // TODO: special case when N is 0? 31 | 32 | size_t N = std::distance(first, last); 33 | size_t B = _default_block_size(N); 34 | 35 | return kernel( 36 | (N+B-1) / B, B, 0, cuda_transform, 37 | first, N, std::forward(c), srcs... 38 | ); 39 | } 40 | 41 | // Procedure: update_transform 42 | template 43 | void cudaFlow::update_transform( 44 | cudaTask task, I first, I last, C&& c, S... srcs 45 | ) { 46 | 47 | // TODO: special case when N is 0? 48 | size_t N = std::distance(first, last); 49 | size_t B = _default_block_size(N); 50 | 51 | update_kernel( 52 | task, (N+B-1) / B, B, 0, first, N, std::forward(c), srcs... 53 | ); 54 | } 55 | 56 | // ---------------------------------------------------------------------------- 57 | // cudaFlowCapturer 58 | // ---------------------------------------------------------------------------- 59 | 60 | // Function: transform 61 | template 62 | cudaTask cudaFlowCapturer::transform(I first, I last, C&& c, S... srcs) { 63 | 64 | // TODO: special case when N is 0? 65 | size_t N = std::distance(first, last); 66 | size_t B = _default_block_size(N); 67 | 68 | return on([=, c=std::forward(c)] 69 | (cudaStream_t stream) mutable { 70 | cuda_transform<<<(N+B-1)/B, B, 0, stream>>>(first, N, c, srcs...); 71 | }); 72 | } 73 | 74 | // Function: rebind_transform 75 | template 76 | void cudaFlowCapturer::rebind_transform( 77 | cudaTask task, I first, I last, C&& c, S... srcs 78 | ) { 79 | 80 | // TODO: special case when N is 0? 81 | size_t N = std::distance(first, last); 82 | size_t B = _default_block_size(N); 83 | 84 | rebind_on(task, [=, c=std::forward(c)] 85 | (cudaStream_t stream) mutable { 86 | cuda_transform<<<(N+B-1)/B, B, 0, stream>>>(first, N, c, srcs...); 87 | }); 88 | } 89 | 90 | } // end of namespace tf ----------------------------------------------------- 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/cuda/cuda_algorithm/cuda_transpose.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../cuda_error.hpp" 4 | 5 | namespace tf { 6 | 7 | // ---------------------------------------------------------------------------- 8 | // row-wise matrix transpose 9 | // ---------------------------------------------------------------------------- 10 | // 11 | template 12 | __global__ void cuda_transpose( 13 | const T* d_in, 14 | T* d_out, 15 | size_t rows, 16 | size_t cols 17 | ) { 18 | __shared__ T tile[32][32]; 19 | size_t x = blockIdx.x * 32 + threadIdx.x; 20 | size_t y = blockIdx.y * 32 + threadIdx.y; 21 | 22 | for(size_t i = 0; i < 32; i += 8) { 23 | if(x < cols && (y + i) < rows) { 24 | tile[threadIdx.y + i][threadIdx.x] = d_in[(y + i) * cols + x]; 25 | } 26 | } 27 | 28 | __syncthreads(); 29 | 30 | x = blockIdx.y * 32 + threadIdx.x; 31 | y = blockIdx.x * 32 + threadIdx.y; 32 | 33 | for(size_t i = 0; i < 32; i += 8) { 34 | if(x < rows && (y + i) < cols) { 35 | d_out[(y + i) * rows + x] = tile[threadIdx.x][threadIdx.y + i]; 36 | } 37 | } 38 | } 39 | 40 | } // end of namespace -------------------------------------------------------- 41 | 42 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/cuda/cuda_error.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../utility/stream.hpp" 9 | 10 | #define TF_CUDA_EXPAND( x ) x 11 | #define TF_CUDA_REMOVE_FIRST_HELPER(N, ...) __VA_ARGS__ 12 | #define TF_CUDA_REMOVE_FIRST(...) TF_CUDA_EXPAND(TF_CUDA_REMOVE_FIRST_HELPER(__VA_ARGS__)) 13 | #define TF_CUDA_GET_FIRST_HELPER(N, ...) N 14 | #define TF_CUDA_GET_FIRST(...) TF_CUDA_EXPAND(TF_CUDA_GET_FIRST_HELPER(__VA_ARGS__)) 15 | 16 | #define TF_CHECK_CUDA(...) \ 17 | if(TF_CUDA_GET_FIRST(__VA_ARGS__) != cudaSuccess) { \ 18 | std::ostringstream oss; \ 19 | auto ev = TF_CUDA_GET_FIRST(__VA_ARGS__); \ 20 | oss << "[" << __FILE__ << ":" << __LINE__ << "] " \ 21 | << (cudaGetErrorString(ev)) << " (" \ 22 | << (cudaGetErrorName(ev)) << ") -"; \ 23 | tf::ostreamize(oss, TF_CUDA_REMOVE_FIRST(__VA_ARGS__)); \ 24 | throw std::runtime_error(oss.str()); \ 25 | } 26 | 27 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/cudaflow.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // taskflow.hpp 4 | // ^ 5 | // | 6 | // cudaflow.hpp 7 | 8 | #include "taskflow.hpp" 9 | #include "cuda/cuda_flow.hpp" 10 | #include "cuda/cuda_algorithm/cuda_for_each.hpp" 11 | #include "cuda/cuda_algorithm/cuda_transform.hpp" 12 | #include "cuda/cuda_algorithm/cuda_reduce.hpp" 13 | 14 | /** 15 | @file cudaflow.hpp 16 | @brief main cudaFlow include file 17 | */ 18 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/dsl/connection.hpp: -------------------------------------------------------------------------------- 1 | // 2020/08/28 - Created by netcan: https://github.com/netcan 2 | #pragma once 3 | #include "../core/flow_builder.hpp" 4 | #include "task_trait.hpp" 5 | #include "tuple_utils.hpp" 6 | #include "type_list.hpp" 7 | 8 | namespace tf { 9 | namespace dsl { 10 | template class Connection { 11 | using FROMs = typename TaskTrait::TaskList; 12 | using TOs = typename TaskTrait::TaskList; 13 | 14 | public: 15 | using FromTaskList = Unique_t>; 16 | using ToTaskList = Unique_t>; 17 | }; 18 | 19 | template > struct Chain; 20 | 21 | template struct Chainvoid, OUT> { 22 | using From = F; 23 | using type = OUT; 24 | }; 25 | 26 | template 27 | struct ChainT, OUT> { 28 | private: 29 | using To = typename Chain::From; 30 | 31 | public: 32 | using From = F; 33 | using type = typename Chain< 34 | T, typename OUT::template appendTo>>::type; 35 | }; 36 | 37 | template struct OneToOneLink { 38 | template struct InstanceType { 39 | constexpr void build(TasksCB &tasksCb) { 40 | constexpr size_t TasksCBSize = std::tuple_size::value; 41 | constexpr size_t FromTaskIndex = 42 | TupleElementByF_v::template apply>; 43 | constexpr size_t ToTaskIndex = 44 | TupleElementByF_v::template apply>; 45 | static_assert(FromTaskIndex < TasksCBSize && ToTaskIndex < TasksCBSize, 46 | "fatal: not find TaskCb in TasksCB"); 47 | std::get(tasksCb).task_.precede( 48 | std::get(tasksCb).task_); 49 | } 50 | }; 51 | }; 52 | } // namespace dsl 53 | }; // namespace tf 54 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/dsl/dsl.hpp: -------------------------------------------------------------------------------- 1 | // TaskflowDSL is an experimental project that leverages C++17 to 2 | // provide a dedicated interface for expressive taskflow programming 3 | // 4 | // Created by netcan: https://github.com/netcan 5 | 6 | #pragma once 7 | 8 | #include "dsl/task_dsl.hpp" 9 | 10 | namespace tf { 11 | 12 | 13 | } // end of namespace tf ----------------------------------------------------- 14 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/dsl/task_analyzer.hpp: -------------------------------------------------------------------------------- 1 | // 2020/08/28 - Created by netcan: https://github.com/netcan 2 | #pragma once 3 | #include "connection.hpp" 4 | #include "type_list.hpp" 5 | #include 6 | 7 | namespace tf { 8 | namespace dsl { 9 | template class TaskAnalyzer { 10 | template 11 | struct BuildOneToOneLink; 12 | 13 | template 14 | struct BuildOneToOneLink, Ts> { 15 | using type = Concat_t::type...>; 16 | }; 17 | 18 | template 19 | struct BuildOneToOneLink, 20 | std::enable_if_t>> { 21 | using type = TypeList...>; 22 | }; 23 | 24 | template class OneToOneLinkSetF { 25 | using FromTaskList = typename Link::FromTaskList; 26 | using ToTaskList = typename Link::ToTaskList; 27 | 28 | public: 29 | using type = typename BuildOneToOneLink::type; 30 | }; 31 | 32 | public: 33 | using AllTasks = Unique_t< 34 | Concat_t>; 35 | using OneToOneLinkSet = 36 | Unique_t, OneToOneLinkSetF>>>; 37 | }; 38 | 39 | } // namespace dsl 40 | } // namespace tf 41 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/dsl/task_trait.hpp: -------------------------------------------------------------------------------- 1 | // 2020/08/28 - Created by netcan: https://github.com/netcan 2 | #pragma once 3 | #include "../core/flow_builder.hpp" 4 | #include "../core/task.hpp" 5 | #include "type_list.hpp" 6 | #include 7 | 8 | namespace tf { 9 | namespace dsl { 10 | struct TaskSignature {}; 11 | 12 | template struct TaskCb { 13 | using TaskType = TASK; 14 | void build(FlowBuilder &build, const CONTEXT &context) { 15 | task_ = build.emplace(TaskType{context}()); 16 | } 17 | 18 | Task task_; 19 | }; 20 | 21 | template struct IsTask { 22 | template struct apply { 23 | constexpr static bool value = 24 | std::is_same::value; 25 | }; 26 | }; 27 | 28 | template struct TaskTrait; 29 | 30 | template struct SomeTask { 31 | using TaskList = 32 | Unique_t::TaskList...>>>; 33 | }; 34 | 35 | // a task self 36 | template 37 | struct TaskTrait< 38 | TASK, std::enable_if_t::value>> { 39 | using TaskList = TypeList; 40 | }; 41 | 42 | template struct TaskTrait> { 43 | using TaskList = typename SomeTask::TaskList; 44 | }; 45 | } // namespace dsl 46 | } // namespace tf 47 | -------------------------------------------------------------------------------- /thirdparty/taskflow/taskflow/dsl/tuple_utils.hpp: -------------------------------------------------------------------------------- 1 | // 2020/08/28 - Created by netcan: https://github.com/netcan 2 | #pragma once 3 | #include 4 | #include 5 | 6 | namespace tf { 7 | namespace dsl { 8 | namespace detail { 9 | // get tuple element index by f, if not exists then index >= tuple_size 10 | template class F, typename = void> 11 | struct TupleElementByF { 12 | constexpr static size_t Index = 0; 13 | }; 14 | 15 | template