├── .gitignore ├── .gitattributes ├── resources ├── _BlueNoiseTexture.rc └── BN_128x128x64_R8.bin ├── .gitmodules ├── signatures └── CLA.json ├── .github └── workflows │ └── cla.yaml ├── src ├── Component.h ├── common │ ├── Arch.h │ ├── ShaderBlobEntry.h │ ├── SDKDefines.h │ ├── ShaderBlob.h │ ├── CRC.h │ └── CRC.cpp ├── Log.h ├── RenderTaskValidator.h ├── DenoisingContext.cpp ├── SceneContainer.cpp ├── DenoisingContext.h ├── TaskTracker.h ├── GraphicsAPI │ └── GraphicsAPI_Utils.h ├── Platform.h ├── DLLMain.cpp ├── ShaderTableRT.h ├── WinResFS.h ├── Handle.h ├── Geometry.cpp ├── Component.cpp ├── OS.h ├── SharedCPUDescriptorHeap.h ├── SceneContainer.h ├── SharedCPUDescriptorHeap.cpp ├── TaskWorkingSet.h ├── RenderPass_DirectLightingCacheAllocation.h ├── VirtualFS.h ├── ExecuteContext.h ├── Scene.h ├── TaskTracker.cpp ├── RenderPass_Denoising.h ├── ResourceLogger.h ├── TaskContainer.cpp ├── Geometry.h ├── RenderPass_DirectLightingCacheInjection.h └── Utils.cpp ├── interop_d3d11 ├── src │ ├── Component.h │ ├── Log.h │ ├── Platform.h │ ├── TaskContainer.h │ ├── DLLMain.cpp │ ├── Component.cpp │ └── ExecuteContext.h └── CMakeLists.txt ├── shaders ├── DirectLightingCache │ ├── Shadows_rt_CS.hlsl │ ├── Shadows_rt_LIB.hlsl │ ├── Transfer_rt_CS.hlsl │ ├── Transfer_rt_LIB.hlsl │ ├── Injection_rt_CS.hlsl │ ├── Reflection_rt_CS.hlsl │ ├── Reflection_rt_LIB.hlsl │ ├── Injection_rt_LIB.hlsl │ ├── Reflection_AO_rt_CS.hlsl │ ├── Reflection_GI_rt_CS.hlsl │ ├── Reflection_AO_rt_LIB.hlsl │ ├── Reflection_GI_rt_LIB.hlsl │ ├── Reflection_DebugVis_rt_CS.hlsl │ ├── Reflection_DebugVis_rt_LIB.hlsl │ ├── CTA_Swizzle.hlsli │ ├── Injection_Clear_CS.hlsl │ └── GBuffer_functions.hlsli ├── Shared │ └── Binding.hlsli ├── Denoising │ └── NRD │ │ └── Placeholder │ │ └── NRD.hlsli ├── shaders.cfg ├── _ShaderResource_SPIRV.rc └── CMakeLists.txt ├── thirdparty └── CMakeLists.txt ├── LICENSE.txt ├── tools └── ShaderCompiler │ ├── Options.h │ ├── CMakeLists.txt │ └── Options.cpp └── include ├── KickstartRT.h ├── KickstartRT_Interop_layer_d3d11.h └── KickstartRT_native_layer_d3d12.h /.gitignore: -------------------------------------------------------------------------------- 1 | build* 2 | .vscode* 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | resources/BN_128x128x64_R8.bin binary 2 | 3 | -------------------------------------------------------------------------------- /resources/_BlueNoiseTexture.rc: -------------------------------------------------------------------------------- 1 | Texture/BN_128x128x64_R8.bin BINARY "${BN_R8_TexturePath}" 2 | -------------------------------------------------------------------------------- /resources/BN_128x128x64_R8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/KickstartRT/HEAD/resources/BN_128x128x64_R8.bin -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/cxxopts"] 2 | path = thirdparty/cxxopts 3 | url = https://github.com/jarro2783/cxxopts.git 4 | [submodule "thirdparty/RayTracingDenoiser"] 5 | path = thirdparty/RayTracingDenoiser 6 | url = https://github.com/NVIDIAGameWorks/RayTracingDenoiser.git 7 | -------------------------------------------------------------------------------- /signatures/CLA.json: -------------------------------------------------------------------------------- 1 | { 2 | "signedContributors": [ 3 | { 4 | "name": "tksgmsy", 5 | "id": 5753935, 6 | "comment_id": 1109356109, 7 | "created_at": "2022-04-26T05:21:13Z", 8 | "repoId": 463356813, 9 | "pullRequestNo": 9 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /.github/workflows/cla.yaml: -------------------------------------------------------------------------------- 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/blob/main/NVIDIA_CLA_v1.0.1.txt' 21 | branch: 'main' 22 | allowlist: nobody 23 | -------------------------------------------------------------------------------- /src/Component.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #include 25 | 26 | -------------------------------------------------------------------------------- /interop_d3d11/src/Component.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #include 25 | 26 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Shadows_rt_CS.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 1 23 | #include "Shadows_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Shadows_rt_LIB.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 0 23 | #include "Shadows_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Transfer_rt_CS.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 1 23 | #include "Transfer_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Transfer_rt_LIB.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 0 23 | #include "Transfer_rt.hlsli" 24 | 25 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Injection_rt_CS.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 1 23 | #include "Injection_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Reflection_rt_CS.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 1 23 | #include "Reflection_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Reflection_rt_LIB.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 0 23 | #include "Reflection_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Injection_rt_LIB.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 0 23 | #include "Injection_rt.hlsli" 24 | 25 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Reflection_AO_rt_CS.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 1 23 | #include "Reflection_AO_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Reflection_GI_rt_CS.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 1 23 | #include "Reflection_GI_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Reflection_AO_rt_LIB.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 0 23 | #include "Reflection_AO_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Reflection_GI_rt_LIB.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 0 23 | #include "Reflection_GI_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Reflection_DebugVis_rt_CS.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 1 23 | #include "Reflection_DebugVis_rt.hlsli" 24 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Reflection_DebugVis_rt_LIB.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define INLINE_RAY_TRACING 0 23 | #include "Reflection_DebugVis_rt.hlsli" 24 | -------------------------------------------------------------------------------- /thirdparty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # 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 THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | if (NOT TARGET cxxopts) 23 | option(CXXOPTS_BUILD_EXAMPLES OFF) 24 | option(CXXOPTS_BUILD_TESTS OFF) 25 | option(CXXOPTS_ENABLE_INSTALL OFF) 26 | add_subdirectory(cxxopts) 27 | endif() 28 | 29 | -------------------------------------------------------------------------------- /shaders/Shared/Binding.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #if !defined(SHARED_BINDING_HLSLI) 23 | #define SHARED_BINDING_HLSLI 24 | 25 | #if defined(GRAPHICS_API_VK) 26 | #define KS_VK_BINDING(index, set) [[vk::binding(index, set)]] 27 | #else 28 | #define KS_VK_BINDING(index, set) 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/common/Arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #undef ARCH_X86 25 | #define ARCH_X86 26 | 27 | #if __GNUC__ 28 | #if defined(__arm__) || defined(__aarch64__) 29 | #undef ARCH_ARM 30 | #define ARCH_ARM 31 | #undef ARCH_X86 32 | #endif 33 | #endif 34 | 35 | #ifdef _MSC_VER 36 | #ifdef _M_ARM 37 | #undef ARCH_ARM 38 | #define ARCH_ARM 39 | #undef ARCH_X86 40 | #endif 41 | #endif 42 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License (https://opensource.org/licenses/MIT) 2 | Copyright (c) 2022, NVIDIA CORPORATION. 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 | This software links to the Nvidia Real-Time Denoisers (NRD) 24 | library which is not licensed under the above license text. For details on the NRD license, 25 | please refer to its license document at the following location: 26 | https://github.com/NVIDIAGameWorks/RayTracingDenoiser/blob/master/LICENSE.txt 27 | -------------------------------------------------------------------------------- /src/Log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace KickstartRT_NativeLayer::Log 28 | { 29 | std::wstring ToWideString(const std::string& src); 30 | 31 | void Message(Severity severity, const wchar_t* fmt...); 32 | void Info(const wchar_t* fmt...); 33 | void Warning(const wchar_t* fmt...); 34 | void Error(const wchar_t* fmt...); 35 | void Fatal(const wchar_t* fmt...); 36 | } 37 | -------------------------------------------------------------------------------- /interop_d3d11/src/Log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace KickstartRT_ExportLayer::Log 28 | { 29 | std::wstring ToWideString(const std::string& src); 30 | 31 | void Message(Severity severity, const wchar_t* fmt...); 32 | void Info(const wchar_t* fmt...); 33 | void Warning(const wchar_t* fmt...); 34 | void Error(const wchar_t* fmt...); 35 | void Fatal(const wchar_t* fmt...); 36 | } 37 | -------------------------------------------------------------------------------- /src/RenderTaskValidator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | 25 | namespace KickstartRT_NativeLayer 26 | { 27 | class Scene; 28 | 29 | class RenderTaskValidator { 30 | friend class Scene; 31 | 32 | public: 33 | static Status DirectLightingInjectionTask(const RenderTask::DirectLightingInjectionTask* input); 34 | static Status DirectLightTransferTask(const RenderTask::DirectLightTransferTask* input); 35 | static Status TraceTask(const RenderTask::Task* task); 36 | static Status DenoisingTask(const RenderTask::Task* task); 37 | }; 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /src/DenoisingContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace KickstartRT_NativeLayer 29 | { 30 | DenoisingContext::DenoisingContext(uint64_t id, const DenoisingContextInput* input) :m_id(id), m_input(*input) { 31 | 32 | } 33 | 34 | DenoisingContext::~DenoisingContext() { 35 | assert(m_RP == nullptr); 36 | } 37 | 38 | void DenoisingContext::DeferredRelease(PersistentWorkingSet* pws) { 39 | if (m_RP) { 40 | m_RP->DeferredRelease(pws); 41 | m_RP.reset(); 42 | } 43 | } 44 | }; 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/common/ShaderBlobEntry.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 | #pragma once 23 | #include 24 | #include 25 | 26 | namespace KickstartRT::ShaderBlob { 27 | 28 | struct BlobHeader { 29 | char signature[4]; 30 | uint32_t hash; 31 | }; 32 | 33 | struct ShaderBlobEntry 34 | { 35 | uint32_t hashKeySize; 36 | uint32_t dataSize; 37 | uint32_t dataCrc; 38 | uint32_t defineHash; 39 | }; 40 | 41 | static constexpr const char *kBlobSignature = "KSSH"; 42 | static constexpr const size_t kBlobSignatureSize = 4; 43 | static constexpr const size_t kBlobHeaderSize = sizeof(BlobHeader); 44 | }; 45 | -------------------------------------------------------------------------------- /shaders/Denoising/NRD/Placeholder/NRD.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | /* 24 | This file exists because the KickStart Shader Compiler is parsing all hlsl source files for the #inlude directive to manual construct an include tree that's used to keep track of source changes 25 | that may need to trigger a rebuild. 26 | 27 | When we compile with NRD disabled, this file will be included. If the NRD include directive survies the preprocessor step this file is still included -> we have an error. 28 | 29 | When NRD is enabled the include path will be redirected to the real NRD.hlsli. 30 | */ 31 | 32 | #error "This file can be included, but is not meant to survive the preprocessor." 33 | -------------------------------------------------------------------------------- /interop_d3d11/src/Platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #define WIN32_LEAN_AND_MEAN 25 | #define NOMINMAX 26 | #include 27 | #include 28 | 29 | #if !defined(GRAPHICS_API_D3D12) 30 | #error "KickstartRT D3D11 interop layer requires D3D12 layer." 31 | #endif 32 | 33 | // Always enable 12 layer. 34 | #if defined(GRAPHICS_API_D3D12) 35 | #define KickstartRT_Graphics_API_D3D12 36 | #endif 37 | 38 | // always enable 11 interop layer. 39 | #define KickstartRT_Graphics_API_D3D11 40 | 41 | #include "KickstartRT.h" 42 | 43 | #if defined(GRAPHICS_API_D3D12) 44 | #define KickstartRT_NativeLayer KickstartRT::D3D12 45 | #endif 46 | 47 | #define KickstartRT_ExportLayer KickstartRT::D3D11 48 | -------------------------------------------------------------------------------- /src/SceneContainer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace KickstartRT_NativeLayer 28 | { 29 | SceneContainer::~SceneContainer() 30 | { 31 | std::scoped_lock mtx(m_mutex); 32 | 33 | // delete relationship between instance and geometry. 34 | for (auto&& itr : m_instances) { 35 | auto* iPtr = itr.second.get(); 36 | assert(iPtr != nullptr); 37 | if (iPtr != nullptr) { 38 | assert(iPtr->m_geometry != nullptr); 39 | if (iPtr->m_geometry != nullptr) { 40 | iPtr->m_geometry->m_instances.remove(iPtr); 41 | // invalidate the geometry reference. 42 | iPtr->m_geometry = nullptr; 43 | } 44 | } 45 | } 46 | 47 | for (auto&& dc : m_denoisingContexts) { 48 | // Request to immediate release for device objects. 49 | dc->DeferredRelease(nullptr); 50 | } 51 | } 52 | }; -------------------------------------------------------------------------------- /src/DenoisingContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | namespace KickstartRT_NativeLayer 30 | { 31 | class PersistentWorkingSet; 32 | struct RenderPass_Denoising; 33 | 34 | struct DenoisingContext 35 | { 36 | const uint64_t m_id; 37 | DenoisingContextInput m_input; 38 | std::unique_ptr m_RP; 39 | 40 | DenoisingContext(uint64_t id, const DenoisingContextInput *input); 41 | ~DenoisingContext(); 42 | void DeferredRelease(PersistentWorkingSet* pws); 43 | 44 | static DenoisingContext* ToPtr(DenoisingContextHandle handle) 45 | { 46 | return ToPtr_s(handle); 47 | } 48 | 49 | DenoisingContextHandle ToHandle() 50 | { 51 | return ToHandle_s(this); 52 | }; 53 | }; 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /interop_d3d11/src/TaskContainer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | 25 | namespace KickstartRT_ExportLayer 26 | { 27 | class InteropCacheSet; 28 | 29 | struct TaskContainer_impl : public TaskContainer { 30 | friend class ExecuteContext_impl; 31 | 32 | protected: 33 | InteropCacheSet* m_interopCacheSet; 34 | D3D12::TaskContainer* m_taskContainer_12; 35 | 36 | public: 37 | TaskContainer_impl(InteropCacheSet *cs, D3D12::TaskContainer* container_12) : 38 | m_interopCacheSet(cs), 39 | m_taskContainer_12(container_12) 40 | {}; 41 | virtual ~TaskContainer_impl(); 42 | 43 | Status ScheduleRenderTask(const RenderTask::Task* renderTask) override; 44 | Status ScheduleRenderTasks(const RenderTask::Task* const* renderTaskPtrArr, uint32_t nbTasks) override; 45 | Status ScheduleBVHTask(const BVHTask::Task* bvhTask) override; 46 | Status ScheduleBVHTasks(const BVHTask::Task* const* bvhTaskPtrArr, uint32_t nbTasks) override; 47 | }; 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /tools/ShaderCompiler/Options.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 | #include 23 | #include 24 | 25 | enum class Platform 26 | { 27 | UNKNOWN, 28 | DXIL, 29 | SPIRV 30 | }; 31 | 32 | struct CommandLineOptions 33 | { 34 | std::string inputFile; 35 | std::string outputPath; 36 | std::string resourceFilePath; 37 | std::vector definitions; 38 | std::vector includePaths; 39 | std::vector additionalCompilerOptions; 40 | std::string compilerPath; 41 | Platform platform = Platform::UNKNOWN; 42 | bool parallel = false; 43 | bool verbose = false; 44 | bool force = false; 45 | bool help = false; 46 | bool keep = false; 47 | int vulkanBindingsPerResourceType = 128; 48 | int vulkanBindingsPerStage = 512; 49 | 50 | std::string errorMessage; 51 | 52 | bool parse(int argc, char** argv); 53 | }; 54 | 55 | struct CompilerOptions 56 | { 57 | std::string shaderName; 58 | std::string entryPoint; 59 | std::string target; 60 | std::vector definitions; 61 | 62 | std::string errorMessage; 63 | 64 | bool parse(std::string line); 65 | }; 66 | -------------------------------------------------------------------------------- /tools/ShaderCompiler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # 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 THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | set(CMAKE_CXX_STANDARD 17) 23 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 24 | set(CMAKE_CXX_EXTENSIONS ON) 25 | 26 | set(SRC_FILES 27 | "ShaderCompiler.cpp" 28 | "Options.cpp" 29 | "Options.h" 30 | ) 31 | 32 | set(COMMON_SRC_FILES 33 | "${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/CRC.cpp" 34 | "${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/CRC.h" 35 | "${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/ShaderBlobEntry.h" 36 | ) 37 | 38 | set(THREADS_PREFER_PTHREAD_FLAG ON) 39 | find_package(Threads REQUIRED) 40 | 41 | add_executable(${SDK_NAME}_ShaderCompiler "${SRC_FILES}" "${COMMON_SRC_FILES}") 42 | target_include_directories(${SDK_NAME}_ShaderCompiler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include) 43 | target_include_directories(${SDK_NAME}_ShaderCompiler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../src) 44 | 45 | target_link_libraries(${SDK_NAME}_ShaderCompiler cxxopts Threads::Threads) 46 | 47 | if(MSVC) 48 | target_compile_definitions(${SDK_NAME}_ShaderCompiler PRIVATE _CRT_SECURE_NO_WARNINGS) 49 | endif() 50 | 51 | set_property(TARGET ${SDK_NAME}_ShaderCompiler PROPERTY FOLDER "Tools") 52 | -------------------------------------------------------------------------------- /src/common/SDKDefines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #if !defined(KICKSTARTRT_SDK_DEFINES_H) 23 | #define KICKSTARTRT_SDK_DEFINES_H 24 | 25 | // This file is also referred from HLSL shaders. 26 | #define KICKSTARTRT_ENABLE_SHARED_BUFFERS_FOR_PERSISTENT_DEVICE_RESOURCES 1 27 | #define KICKSTARTRT_ENABLE_SHARED_BUFFERS_FOR_TEMPORAL_DEVICE_RESOURCES 1 28 | #define KICKSTARTRT_ENABLE_SHARED_BUFFERS_FOR_READBACK_AND_COUNTER_RESOURCES 1 29 | 30 | // This enables indirection table to refer Direct Lighting Cache in shaders, and it will reduce the number of descriptor table entry while ray tracing. 31 | // This required to enable shared buffers. 32 | // that this is also referred in shader codes, so you need to recompile them after changing the sate. 33 | #define KICKSTARTRT_ENABLE_DIRECT_LIGHTING_CACHE_INDIRECTION_TABLE (0 & KICKSTARTRT_SDK_ENABLE_SHARED_BUFFERS_FOR_PERSISTENT_DEVICE_RESOURCES & KICKSTARTRT_SDK_ENABLE_SHARED_BUFFERS_FOR_TEMPORAL_DEVICE_RESOURCES) 34 | 35 | #if !defined(KickstartRT_SDK_WITH_NRD) 36 | #error "KickstartRT_SDK_WITH_NRD must be defined as either 0 or 1." 37 | #endif 38 | 39 | #define KICKSTARTRT_USE_BYTEADDRESSBUFFER_FOR_DLC 0 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /shaders/shaders.cfg: -------------------------------------------------------------------------------- 1 | DirectLightingCache/Allocation_TrianglesIndexed_cs.hlsl -T cs_6_3 -D BUILD_OP={0,1,2,3} -D USE_VERTEX_INDEX_INPUTS={0,1} 2 | DirectLightingCache/Injection_Clear_CS.hlsl -T cs_6_3 3 | DirectLightingCache/Injection_rt_CS.hlsl -T cs_6_5 4 | DirectLightingCache/Injection_rt_LIB.hlsl -T lib_6_3 5 | DirectLightingCache/Transfer_rt_CS.hlsl -T cs_6_5 6 | DirectLightingCache/Transfer_rt_LIB.hlsl -T lib_6_3 7 | DirectLightingCache/Reflection_rt_CS.hlsl -T cs_6_5 -D ENABLE_SPECULAR_TEX={0,1} -D ENABLE_ROUGHNESS_TEX={0,1} -D ENABLE_ENV_MAP_TEX={0,1} -D DEMODULATE_SPECULAR={0,1} -D ENABLE_HALF_RESOLUTION={0,1} -D ENABLE_INPUT_MASK={0,1} 8 | DirectLightingCache/Reflection_rt_LIB.hlsl -T lib_6_3 -D ENABLE_SPECULAR_TEX={0,1} -D ENABLE_ROUGHNESS_TEX={0,1} -D ENABLE_ENV_MAP_TEX={0,1} -D DEMODULATE_SPECULAR={0,1} -D ENABLE_HALF_RESOLUTION={0,1} -D ENABLE_INPUT_MASK={0,1} 9 | DirectLightingCache/Reflection_GI_rt_CS.hlsl -T cs_6_5 -D ENABLE_SPECULAR_TEX={0} -D ENABLE_ROUGHNESS_TEX={0,1} -D ENABLE_ENV_MAP_TEX={0,1} -D ENABLE_HALF_RESOLUTION={0,1} -D ENABLE_INPUT_MASK={0,1} -D USE_NORMALIZED_DIFFUSE={0,1} 10 | DirectLightingCache/Reflection_GI_rt_LIB.hlsl -T lib_6_3 -D ENABLE_SPECULAR_TEX={0} -D ENABLE_ROUGHNESS_TEX={0,1} -D ENABLE_ENV_MAP_TEX={0,1} -D ENABLE_HALF_RESOLUTION={0,1} -D ENABLE_INPUT_MASK={0,1} -D USE_NORMALIZED_DIFFUSE={0,1} 11 | DirectLightingCache/Reflection_DebugVis_rt_CS.hlsl -T cs_6_5 -D ENABLE_SPECULAR_TEX={0} -D ENABLE_ROUGHNESS_TEX={0} -D ENABLE_ENV_MAP_TEX={0} 12 | DirectLightingCache/Reflection_DebugVis_rt_LIB.hlsl -T lib_6_3 -D ENABLE_SPECULAR_TEX={0} -D ENABLE_ROUGHNESS_TEX={0} -D ENABLE_ENV_MAP_TEX={0} 13 | DirectLightingCache/Reflection_AO_rt_CS.hlsl -T cs_6_5 -D ENABLE_SPECULAR_TEX={0} -D ENABLE_ROUGHNESS_TEX={0} -D ENABLE_ENV_MAP_TEX={0} -D ENABLE_HALF_RESOLUTION={0,1} -D ENABLE_INPUT_MASK={0,1} 14 | DirectLightingCache/Reflection_AO_rt_LIB.hlsl -T lib_6_3 -D ENABLE_SPECULAR_TEX={0} -D ENABLE_ROUGHNESS_TEX={0} -D ENABLE_ENV_MAP_TEX={0} -D ENABLE_HALF_RESOLUTION={0,1} -D ENABLE_INPUT_MASK={0,1} 15 | DirectLightingCache/Shadows_rt_CS.hlsl -T cs_6_5 -D ENABLE_HALF_RESOLUTION={0,1} -D ENABLE_INPUT_MASK={0,1} -D ENABLE_MULTI_SHADOW={0,1} -D ENABLE_ACCEPT_FIRST_HIT_AND_END_SEARCH={0,1} 16 | DirectLightingCache/Shadows_rt_LIB.hlsl -T lib_6_3 -D ENABLE_HALF_RESOLUTION={0,1} -D ENABLE_INPUT_MASK={0,1} -D ENABLE_MULTI_SHADOW={0,1} -D ENABLE_ACCEPT_FIRST_HIT_AND_END_SEARCH={0,1} 17 | Denoising/NRD/ConversionLayer_CS.hlsl -T cs_6_3 18 | -------------------------------------------------------------------------------- /shaders/_ShaderResource_SPIRV.rc: -------------------------------------------------------------------------------- 1 | # This is a proxy resource file for Linux as resource files are not fully supported. 2 | # 3 | # The support is done through some CMakefile processing where the output binary files 4 | # are turned into binary objects by the linker and linked into the target process. 5 | # An accompanying header file is autogenerated by CMake, by processing all rc files, upon configuration. 6 | # 7 | # When the project is first configured, this file will be used to seed the resource binary creation. 8 | # When the project is first built, the 'real' shader rc file will be created and used 9 | # instead of this one. 10 | # 11 | # If a new shader file is added to the project, it should also be added to this file. 12 | # 13 | DirectLightingCache/Allocation_TrianglesIndexed_cs.bin BINARY "@SHADER_PATH@/DirectLightingCache/Allocation_TrianglesIndexed_cs.bin" 14 | DirectLightingCache/Injection_Clear_CS.bin BINARY "@SHADER_PATH@/DirectLightingCache/Injection_Clear_CS.bin" 15 | DirectLightingCache/Injection_rt_CS.bin BINARY "@SHADER_PATH@/DirectLightingCache/Injection_rt_CS.bin" 16 | DirectLightingCache/Injection_rt_LIB.bin BINARY "@SHADER_PATH@/DirectLightingCache/Injection_rt_LIB.bin" 17 | DirectLightingCache/Reflection_rt_CS.bin BINARY "@SHADER_PATH@/DirectLightingCache/Reflection_rt_CS.bin" 18 | DirectLightingCache/Reflection_rt_LIB.bin BINARY "@SHADER_PATH@/DirectLightingCache/Reflection_rt_LIB.bin" 19 | DirectLightingCache/Reflection_GI_rt_CS.bin BINARY "@SHADER_PATH@/DirectLightingCache/Reflection_GI_rt_CS.bin" 20 | DirectLightingCache/Reflection_GI_rt_LIB.bin BINARY "@SHADER_PATH@/DirectLightingCache/Reflection_GI_rt_LIB.bin" 21 | DirectLightingCache/Reflection_DebugVis_rt_CS.bin BINARY "@SHADER_PATH@/DirectLightingCache/Reflection_DebugVis_rt_CS.bin" 22 | DirectLightingCache/Reflection_DebugVis_rt_LIB.bin BINARY "@SHADER_PATH@/DirectLightingCache/Reflection_DebugVis_rt_LIB.bin" 23 | DirectLightingCache/Reflection_AO_rt_CS.bin BINARY "@SHADER_PATH@/DirectLightingCache/Reflection_AO_rt_CS.bin" 24 | DirectLightingCache/Reflection_AO_rt_LIB.bin BINARY "@SHADER_PATH@/DirectLightingCache/Reflection_AO_rt_LIB.bin" 25 | DirectLightingCache/Shadows_rt_CS.bin BINARY "@SHADER_PATH@/DirectLightingCache/Shadows_rt_CS.bin" 26 | DirectLightingCache/Shadows_rt_LIB.bin BINARY "@SHADER_PATH@/DirectLightingCache/Shadows_rt_LIB.bin" 27 | Denoising/NRD/ConversionLayer_CS.bin BINARY "@SHADER_PATH@/Denoising/NRD/ConversionLayer_CS.bin" 28 | -------------------------------------------------------------------------------- /shaders/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # 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 THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | 23 | include(../cmake/${SDK_NAME}-compileshaders.cmake) 24 | 25 | file(GLOB ${SDK_NAME}_shared_group_shaders 26 | "Shared/*.h" 27 | "Shared/*.hlsl" 28 | "Shared/*.hlsli" 29 | ) 30 | source_group("Shared" FILES ${${SDK_NAME}_shared_group_shaders}) 31 | 32 | file(GLOB ${SDK_NAME}_denoising_group_shaders 33 | "Denoising/*.h" 34 | "Denoising/*.hlsl" 35 | "Denoising/*.hlsli" 36 | "Denoising/NRD/*.h" 37 | "Denoising/NRD/*.hlsl" 38 | "Denoising/NRD/*.hlsli" 39 | ) 40 | source_group("Denoising" FILES ${${SDK_NAME}_denoising_group_shaders}) 41 | 42 | file(GLOB ${SDK_NAME}_DirectLightingCache_group_shaders 43 | "DirectLightingCache/*.h" 44 | "DirectLightingCache/*.hlsl" 45 | "DirectLightingCache/*.hlsli" 46 | ) 47 | source_group("DirectLightingCache" FILES ${${SDK_NAME}_DirectLightingCache_group_shaders}) 48 | 49 | cmake_language(CALL ${SDK_NAME}_compile_shaders_all_platforms 50 | EXCLUDE_FROM_ALL 51 | TARGET ${SDK_NAME}_shaders 52 | CONFIG ${CMAKE_CURRENT_LIST_DIR}/shaders.cfg 53 | FOLDER ${SDK_NAME} 54 | OUTPUT_BASE ${CMAKE_CURRENT_BINARY_DIR} 55 | RESOURCEFILE ${CMAKE_CURRENT_BINARY_DIR}/ShaderResource 56 | SOURCES shaders.cfg ${${SDK_NAME}_shared_group_shaders} ${${SDK_NAME}_denoising_group_shaders} ${${SDK_NAME}_DirectLightingCache_group_shaders} 57 | ) 58 | -------------------------------------------------------------------------------- /src/TaskTracker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace KickstartRT_NativeLayer 33 | { 34 | class PersistentWorkingSet; 35 | class TaskWorkingSet; 36 | 37 | // task tracker is separated from Scene or PersistentWorkingSet, as it need to be updated from user side anytime (e.g. during task building.) 38 | // otherwise it can be dead locked. 39 | struct TaskTracker { 40 | protected: 41 | std::mutex m_mutex; 42 | uint64_t m_currentTaskIndex = 0ull; 43 | uint64_t m_finishedTaskIndex = 0ull; 44 | 45 | std::vector> m_taskWorkingSets; 46 | std::vector m_taskIndicesForWorkingSets; 47 | 48 | public: 49 | TaskTracker(); 50 | ~TaskTracker(); 51 | 52 | Status Init(PersistentWorkingSet* pws, const ExecuteContext_InitSettings* initSettings); 53 | 54 | uint64_t CurrentTaskIndex(); 55 | uint64_t FinishedTaskIndex(); 56 | 57 | bool TaskWorkingSetIsAvailable(); 58 | Status UpdateFinishedTaskIndex(uint64_t finishedTaskIndex); 59 | Status AllocateTaskWorkingSet(TaskWorkingSet** ret_tws, uint64_t *ret_taskIndex); 60 | }; 61 | }; 62 | 63 | -------------------------------------------------------------------------------- /interop_d3d11/src/DLLMain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #define WIN32_LEAN_AND_MEAN 23 | #define NOMINMAX 24 | #include 25 | 26 | #include 27 | 28 | namespace KickstartRT { 29 | namespace D3D11 { 30 | HINSTANCE g_ModuleHandle = nullptr; 31 | std::mutex g_APIInterfaceMutex; 32 | }; 33 | }; 34 | 35 | BOOL WINAPI DllMain( 36 | HINSTANCE hinstDLL, // handle to DLL module 37 | DWORD fdwReason, // reason for calling function 38 | LPVOID lpReserved) // reserved 39 | { 40 | (void)lpReserved; 41 | 42 | // Perform actions based on the reason for calling. 43 | switch (fdwReason) 44 | { 45 | case DLL_PROCESS_ATTACH: 46 | KickstartRT::D3D11::g_ModuleHandle = hinstDLL; 47 | 48 | // Initialize once for each new process. 49 | // Return FALSE to fail DLL load. 50 | break; 51 | 52 | case DLL_THREAD_ATTACH: 53 | // Do thread-specific initialization. 54 | break; 55 | 56 | case DLL_THREAD_DETACH: 57 | // Do thread-specific cleanup. 58 | break; 59 | 60 | case DLL_PROCESS_DETACH: 61 | // Perform any necessary cleanup. 62 | KickstartRT::D3D11::g_ModuleHandle = nullptr; 63 | break; 64 | } 65 | return TRUE; // Successful DLL_PROCESS_ATTACH. 66 | } 67 | -------------------------------------------------------------------------------- /src/GraphicsAPI/GraphicsAPI_Utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #include "Platform.h" 25 | #include "Log.h" 26 | 27 | #define enum_class_operators(e_) \ 28 | inline e_ operator& (e_ a, e_ b) { return static_cast(static_cast(a)& static_cast(b)); } \ 29 | inline e_ operator| (e_ a, e_ b) { return static_cast(static_cast(a)| static_cast(b)); } \ 30 | inline e_& operator|= (e_& a, e_ b) { a = a | b; return a; }; \ 31 | inline e_& operator&= (e_& a, e_ b) { a = a & b; return a; }; \ 32 | inline e_ operator~ (e_ a) { return static_cast(~static_cast(a)); } \ 33 | inline bool is_set(e_ val, e_ flag) { return (val & flag) != static_cast(0); } \ 34 | inline void flip_bit(e_& val, e_ flag) { val = is_set(val, flag) ? (val & (~flag)) : (val | flag); } 35 | 36 | namespace KickstartRT_NativeLayer::GraphicsAPI 37 | { 38 | template 39 | inline T ALIGN(const T alignment, const T val) 40 | { 41 | return ((val + alignment - 1) / alignment) * alignment; 42 | } 43 | 44 | template 45 | inline T ROUND_UP(const T val, const T denom) 46 | { 47 | return ((val + denom - 1) / denom); 48 | } 49 | 50 | namespace Utils { 51 | #if defined(GRAPHICS_API_D3D12) 52 | std::wstring GetName(ID3D12Object* obj); 53 | #endif 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /src/Platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #ifdef WIN32 25 | #define WIN32_LEAN_AND_MEAN 26 | #define NOMINMAX 27 | #include 28 | #include 29 | #else 30 | #include 31 | #endif 32 | 33 | #include 34 | 35 | #if defined(GRAPHICS_API_D3D12) 36 | #include 37 | 38 | #if defined(USE_PIX) 39 | #pragma warning( push ) 40 | #pragma warning( disable : 6101 ) 41 | #pragma warning( disable : 26812 ) 42 | 43 | #include 44 | #pragma warning( pop ) 45 | #endif 46 | 47 | #elif defined(GRAPHICS_API_VK) 48 | #ifdef WIN32 49 | #pragma warning( push ) 50 | // non class enum warnings. 51 | #pragma warning( disable : 26812 ) 52 | #include 53 | #pragma warning( pop ) 54 | #else 55 | #include 56 | #endif 57 | #else 58 | #error "Either GRAPHICS_API_D3D12 or GRAPHICS_API_VK must be defined." 59 | #endif 60 | 61 | #if defined(GRAPHICS_API_D3D12) 62 | #define KickstartRT_Graphics_API_D3D12 63 | #elif defined(GRAPHICS_API_VK) 64 | #define KickstartRT_Graphics_API_Vulkan 65 | #endif 66 | 67 | #include "KickstartRT.h" 68 | 69 | #if defined(GRAPHICS_API_D3D12) 70 | #define KickstartRT_NativeLayer KickstartRT::D3D12 71 | #elif defined(GRAPHICS_API_VK) 72 | #define KickstartRT_NativeLayer KickstartRT::VK 73 | #endif 74 | 75 | #include "common/SDKDefines.h" 76 | 77 | -------------------------------------------------------------------------------- /src/DLLMain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #ifdef WIN32 23 | #define WIN32_LEAN_AND_MEAN 24 | #define NOMINMAX 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | #ifdef WIN32 31 | namespace KickstartRT { 32 | HINSTANCE g_ModuleHandle = nullptr; 33 | std::mutex g_APIInterfaceMutex; 34 | }; 35 | 36 | BOOL WINAPI DllMain( 37 | HINSTANCE hinstDLL, // handle to DLL module 38 | DWORD fdwReason, // reason for calling function 39 | LPVOID lpReserved) // reserved 40 | { 41 | (void)lpReserved; 42 | 43 | // Perform actions based on the reason for calling. 44 | switch (fdwReason) 45 | { 46 | case DLL_PROCESS_ATTACH: 47 | KickstartRT::g_ModuleHandle = hinstDLL; 48 | 49 | // Initialize once for each new process. 50 | // Return FALSE to fail DLL load. 51 | break; 52 | 53 | case DLL_THREAD_ATTACH: 54 | // Do thread-specific initialization. 55 | break; 56 | 57 | case DLL_THREAD_DETACH: 58 | // Do thread-specific cleanup. 59 | break; 60 | 61 | case DLL_PROCESS_DETACH: 62 | // Perform any necessary cleanup. 63 | KickstartRT::g_ModuleHandle = nullptr; 64 | break; 65 | } 66 | return TRUE; // Successful DLL_PROCESS_ATTACH. 67 | } 68 | 69 | #else 70 | namespace KickstartRT { 71 | void* g_ModuleHandle = nullptr; 72 | std::mutex g_APIInterfaceMutex; 73 | }; 74 | #endif -------------------------------------------------------------------------------- /src/ShaderTableRT.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | namespace KickstartRT_NativeLayer 31 | { 32 | // This supports only a simple case of shader table RT. 33 | 34 | class ShaderTableRT : public GraphicsAPI::DeviceObject { 35 | public: 36 | std::unique_ptr m_rtPSO; 37 | std::unique_ptr m_uploadBuf; 38 | std::unique_ptr m_deviceBuf; 39 | bool m_needToCoyBuffer = false; 40 | #if defined(GRAPHICS_API_D3D12) 41 | D3D12_GPU_VIRTUAL_ADDRESS_RANGE m_RG_Addr = {}; 42 | D3D12_GPU_VIRTUAL_ADDRESS_RANGE_AND_STRIDE m_MS_Addr = {}; 43 | D3D12_GPU_VIRTUAL_ADDRESS_RANGE_AND_STRIDE m_HG_Addr = {}; 44 | #elif defined(GRAPHICS_API_VK) 45 | VkStridedDeviceAddressRegionKHR m_RG_Addr = {}; 46 | VkStridedDeviceAddressRegionKHR m_MS_Addr = {}; 47 | VkStridedDeviceAddressRegionKHR m_HG_Addr = {}; 48 | VkStridedDeviceAddressRegionKHR m_CL_Addr = {}; 49 | #endif 50 | public: 51 | virtual ~ShaderTableRT(); 52 | static std::unique_ptr Init(PersistentWorkingSet* pws, const GraphicsAPI::RootSignature* globalRootSig, std::shared_ptr blob); 53 | static Status BatchCopy(GraphicsAPI::CommandList* cmdList, std::vector stArr); 54 | 55 | void DispatchRays(GraphicsAPI::CommandList* cmdList, uint32_t width, uint32_t height); 56 | }; 57 | }; 58 | -------------------------------------------------------------------------------- /include/KickstartRT.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #ifdef WIN32 25 | #if !defined(WIN32_LEAN_AND_MEAN) 26 | #define WIN32_LEAN_AND_MEAN 27 | #endif 28 | #if !defined(NOMINMAX) 29 | #define NOMINMAX 30 | #endif 31 | #include 32 | #include 33 | #endif 34 | 35 | // Linux complains heavily about the Status enum. Must be already defined 36 | #ifdef Status 37 | #undef Status 38 | #endif 39 | 40 | // This is defined in X.h 41 | #ifdef None 42 | #undef None 43 | #endif 44 | 45 | #ifdef WIN32 46 | #define STDCALL __stdcall 47 | #else 48 | #define STDCALL 49 | #endif 50 | 51 | #include "KickstartRT_common.h" 52 | 53 | #if !defined(KickstartRT_Graphics_API_D3D12) && !defined(KickstartRT_Graphics_API_Vulkan) && !defined(KickstartRT_Graphics_API_D3D11) 54 | #error "You have to define either of KickstartRT_Graphics_API_D3D12, 11 or Vulkan." 55 | #endif 56 | 57 | #if !defined(KickstartRT_DECLSPEC) 58 | #if defined(WIN32) 59 | #define KickstartRT_DECLSPEC __declspec(dllimport) 60 | #else 61 | #define KickstartRT_DECLSPEC 62 | #endif 63 | #endif 64 | 65 | #if defined (KickstartRT_Graphics_API_D3D12) 66 | #include "KickstartRT_native_layer_d3d12.h" 67 | #endif 68 | 69 | #if defined(KickstartRT_Graphics_API_Vulkan) 70 | #include "KickstartRT_native_layer_vk.h" 71 | #endif 72 | 73 | #if ! defined(KickstartRT_Interop_D3D11_DECLSPEC) && defined(WIN32) 74 | #define KickstartRT_Interop_D3D11_DECLSPEC __declspec(dllimport) 75 | #endif 76 | 77 | #if defined (KickstartRT_Graphics_API_D3D11) 78 | #include "KickstartRT_interop_layer_d3d11.h" 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /src/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 | #pragma once 23 | #include "common/ShaderBlob.h" 24 | #include "VirtualFS.h" 25 | 26 | namespace KickstartRT::VirtualFS 27 | { 28 | /* 29 | 30 | File system interface for Windows module (EXE or DLL) resources. 31 | Automatically included into the builds for WIN32. 32 | 33 | Supports enumerating and reading resources of a given type, "BINARY" by default. 34 | Resource names are case insensitive, and all resource names are stored in the 35 | modules in uppercase, and reported by enumerate(...) also in uppercase. 36 | 37 | To add a resource to the application, use a .rc file, with lines like this one: 38 | 39 | resource_name BINARY "real_file_path" 40 | 41 | The part is interpreted by this interface as a virtual file path, 42 | and it can include slashes. The part is path to the actual file to 43 | be embedded, and it should be enclosed in quotes. 44 | 45 | */ 46 | class WinResFileSystem : public IFileSystem 47 | { 48 | private: 49 | const void* m_hModule; 50 | std::wstring m_Type; 51 | std::vector m_ResourceNames; 52 | 53 | public: 54 | WinResFileSystem(const void* hModule = nullptr, const wchar_t* type = L"BINARY"); 55 | 56 | virtual bool folderExists(const std::filesystem::path& name) override; 57 | virtual bool fileExists(const std::filesystem::path& name) override; 58 | virtual std::shared_ptr readFile(const std::filesystem::path& name) override; 59 | virtual bool writeFile(const std::filesystem::path& name, const void* data, size_t size) override; 60 | virtual bool enumerate(const std::filesystem::path& pattern, bool directories, std::vector& results) override; 61 | }; 62 | } -------------------------------------------------------------------------------- /shaders/DirectLightingCache/CTA_Swizzle.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | // It starts a new line by BlockSize_X(), instead of full width of screen. 24 | 25 | #if defined(ENABLE_CTA_SWIZZLING) 26 | 27 | uint2 LocalGroupThreadSize() 28 | { 29 | return uint2(8, 16); 30 | } 31 | 32 | uint BlockSize_X() 33 | { 34 | return 8; 35 | } 36 | 37 | uint2 GroupDimension() 38 | { 39 | return uint2(CB.m_CTA_Swizzle_GroupDimension_X, CB.m_CTA_Swizzle_GroupDimension_Y); 40 | } 41 | 42 | uint PerfectBlockSize() 43 | { 44 | return BlockSize_X() * GroupDimension().y; 45 | } 46 | 47 | uint NumPerfectBlocks() 48 | { 49 | return GroupDimension().x / BlockSize_X(); 50 | } 51 | 52 | uint BorderBlockSize_X() 53 | { 54 | return GroupDimension().x - NumPerfectBlocks() * BlockSize_X(); 55 | } 56 | 57 | // This function will return swizzled pixel position 58 | uint2 CTASwizzle_GetPixelPosition(in uint2 _GroupID, in uint2 _GroupThreadID, in uint2 _DispatchThreadID) 59 | { 60 | uint flattenGroupID = _GroupID.x + _GroupID.y * GroupDimension().x; 61 | 62 | uint blockID = flattenGroupID / PerfectBlockSize(); 63 | 64 | uint blockSize_X = BlockSize_X(); // Perfect Block 65 | if (blockID == NumPerfectBlocks()) { 66 | blockSize_X = BorderBlockSize_X(); // Border Block 67 | } 68 | 69 | uint localGroupID = flattenGroupID - blockID * PerfectBlockSize(); 70 | uint2 localGroupPos = uint2(localGroupID % blockSize_X, localGroupID / blockSize_X); 71 | 72 | uint2 groupOffset = (uint2(BlockSize_X(), 0) * blockID) + localGroupPos; 73 | 74 | uint2 pixelPos = groupOffset * LocalGroupThreadSize() + _GroupThreadID.xy; 75 | 76 | return pixelPos; 77 | } 78 | 79 | #else 80 | // Disabled CTA swizzling. 81 | uint2 CTASwizzle_GetPixelPosition(in uint2 _GroupID, in uint2 _GroupThreadID, in uint2 _DispatchThreadID) 82 | { 83 | return _DispatchThreadID.xy; 84 | } 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /src/Handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | template 25 | inline PType* ToPtr_s(HType handle) 26 | { 27 | static_assert(sizeof(PType*) == sizeof(uint64_t)); 28 | static_assert(sizeof(HType) == sizeof(uint64_t)); 29 | static_assert(sizeof(PType::m_id) == sizeof(uint64_t)); 30 | 31 | static_assert(((uint64_t)0xFFFF'FFFF'FFFF'FFFFull) >> 1 == (uint64_t)0x7FFF'FFFF'FFFF'FFFF); 32 | static_assert(((int64_t)0xFFFF'FFFF'FFFF'FFFFull) >> 1 == (int64_t)0xFFFF'FFFF'FFFF'FFFF); 33 | 34 | constexpr int HandleIDBits = 14; // upper 14 bit is used as a handle id space. 35 | constexpr int64_t AddressMask = static_cast(0xFFFF'FFFF'FFFF'FFFFull >> HandleIDBits); 36 | constexpr uint64_t IDMask = static_cast(~AddressMask); 37 | 38 | // Sign extend first to make the pointer canonical 39 | PType* p = reinterpret_cast(((static_cast(handle) & AddressMask) << HandleIDBits) >> HandleIDBits); 40 | if (p->m_id != (static_cast(handle) & IDMask)) 41 | return nullptr; 42 | 43 | return p; 44 | }; 45 | 46 | template 47 | inline HType ToHandle_s(PType* p) 48 | { 49 | static_assert(sizeof(PType*) == sizeof(uint64_t)); 50 | static_assert(sizeof(HType) == sizeof(uint64_t)); 51 | static_assert(sizeof(PType::m_id) == sizeof(uint64_t)); 52 | 53 | constexpr int HandleIDBits = 14; // upper 14 bit is used as a handle id space. 54 | constexpr uint64_t AddressMask = 0xFFFF'FFFF'FFFF'FFFFull >> HandleIDBits; 55 | constexpr uint64_t AddressMask_N1 = ~(0xFFFF'FFFF'FFFF'FFFFull >> (HandleIDBits + 1)); 56 | (void)(AddressMask_N1); 57 | 58 | // Upper (14+1) bits need to be all set or zero. 59 | assert( 60 | (reinterpret_cast(p) & AddressMask_N1) == 0 || 61 | (reinterpret_cast(p) & AddressMask_N1) == AddressMask_N1); 62 | 63 | return static_cast((reinterpret_cast(p) & AddressMask) | p->m_id); 64 | }; 65 | 66 | -------------------------------------------------------------------------------- /shaders/DirectLightingCache/Injection_Clear_CS.hlsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma pack_matrix(row_major) 23 | 24 | #include "Shared/Binding.hlsli" 25 | 26 | // bindings and functions for tiled lighting cache 27 | #include "DirectLightingCache.hlsli" 28 | 29 | // ---[ Structures ]--- 30 | struct CB_Clear 31 | { 32 | uint m_instanceIndex; 33 | uint m_numberOfTiles; 34 | uint m_resourceOffset; 35 | uint m_pad_u1; 36 | 37 | float3 m_clearColor; 38 | float m_pad_f0; 39 | }; 40 | 41 | // ---[ Resources ]--- 42 | //[[vk::binding(0, 0)]] 43 | KS_VK_BINDING(0, 0) 44 | ConstantBuffer CB : register(b0); 45 | 46 | [numthreads(64, 1, 1)] 47 | void main( 48 | uint2 groupIdx : SV_GroupID, 49 | uint2 globalIdx : SV_DispatchThreadID, 50 | uint2 threadIdx : SV_GroupThreadID) 51 | { 52 | uint sampleBufferSlot, sampleBufferBaseOffset; 53 | #if KICKSTARTRT_ENABLE_DIRECT_LIGHTING_CACHE_INDIRECTION_TABLE 54 | { 55 | uint2 u2 = u_directLightingCacheIndirectionTable[CB.m_instanceIndex].zw; 56 | sampleBufferSlot = u2.x; 57 | sampleBufferBaseOffset = u2.y; 58 | } 59 | #else 60 | sampleBufferSlot = CB.m_instanceIndex * 2 + CB.m_resourceOffset; 61 | sampleBufferBaseOffset = 0; 62 | #endif 63 | 64 | DLCBufferType tileBuffer = u_directLightingCacheBuffer[sampleBufferSlot]; 65 | 66 | uint2 clearColor = fromRGBToYCoCg(CB.m_clearColor, true /*SetClearTag*/); 67 | 68 | // fill 4 tiless per thread. 69 | uint tileOffset = globalIdx.x * 4; 70 | if (tileOffset < CB.m_numberOfTiles) { 71 | DLCBuffer::Store2(tileBuffer, sampleBufferBaseOffset + tileOffset * 2, clearColor); 72 | } 73 | tileOffset++; 74 | if (tileOffset < CB.m_numberOfTiles) { 75 | DLCBuffer::Store2(tileBuffer, sampleBufferBaseOffset + tileOffset * 2, clearColor); 76 | } 77 | tileOffset++; 78 | if (tileOffset < CB.m_numberOfTiles) { 79 | DLCBuffer::Store2(tileBuffer, sampleBufferBaseOffset + tileOffset * 2, clearColor); 80 | } 81 | tileOffset++; 82 | if (tileOffset < CB.m_numberOfTiles) { 83 | DLCBuffer::Store2(tileBuffer, sampleBufferBaseOffset + tileOffset * 2, clearColor); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Geometry.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace KickstartRT_NativeLayer 29 | { 30 | namespace BVHTask { 31 | Geometry::~Geometry() 32 | { 33 | if (m_instances.size() > 0) { 34 | Log::Warning(L"~GeometryHandle called but it was referenced from (%d) instances.", m_instances.size()); 35 | //assert(false); 36 | } 37 | }; 38 | 39 | void Geometry::DeferredRelease(PersistentWorkingSet* pws) 40 | { 41 | pws->DeferredRelease(std::move(m_index_vertexBuffer)); 42 | 43 | pws->DeferredRelease(std::move(m_directLightingCacheCounter)); 44 | pws->DeferredRelease(std::move(m_directLightingCacheCounter_Readback)); 45 | pws->DeferredRelease(std::move(m_directLightingCacheIndices)); 46 | 47 | pws->DeferredRelease(std::move(m_BLASScratchBuffer)); 48 | pws->DeferredRelease(std::move(m_BLASBuffer)); 49 | 50 | #if defined(GRAPHICS_API_D3D12) 51 | pws->DeferredRelease(std::move(m_BLASCompactionSizeBuffer)); 52 | pws->DeferredRelease(std::move(m_BLASCompactionSizeBuffer_Readback)); 53 | #elif defined(GRAPHICS_API_VK) 54 | pws->DeferredRelease(std::move(m_BLASCompactionSizeQueryPool)); 55 | #endif 56 | 57 | pws->DeferredRelease(std::move(m_edgeTableBuffer)); 58 | } 59 | 60 | // calling dtor with valid geometry handle is prohibited. 61 | Instance::~Instance() 62 | { 63 | if (m_geometry != nullptr) { 64 | Log::Fatal(L"Geometry handle was not null when destructing an InstanceHandle."); 65 | assert(false); 66 | } 67 | }; 68 | 69 | void Instance::DeferredRelease(PersistentWorkingSet* pws) 70 | { 71 | // remove reference from GeometryHandle here. 72 | if (m_geometry != nullptr) { 73 | Log::Fatal(L"Relation between instance and geometry shoudl have been removed before deferred release."); 74 | assert(false); 75 | } 76 | 77 | #if KICKSTARTRT_ENABLE_DIRECT_LIGHTING_CACHE_INDIRECTION_TABLE 78 | #else 79 | // allocated CPU desc heap is released here immediately. 80 | m_cpuDescTableAllocation.reset(); 81 | #endif 82 | 83 | pws->DeferredRelease(std::move(m_dynamicTileBuffer)); 84 | } 85 | }; 86 | }; 87 | 88 | -------------------------------------------------------------------------------- /src/common/ShaderBlob.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 | #pragma once 23 | #include "common/ShaderBlobEntry.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace KickstartRT::ShaderBlob { 31 | struct ShaderConstant 32 | { 33 | const char* name; 34 | const char* value; 35 | }; 36 | 37 | uint32_t GetShaderConstantCRC(const ShaderConstant* constants, uint32_t numConstants); 38 | 39 | bool FindPermutationInBlob(const void* blob, size_t blobSize, std::optional shaderMacroCRC, size_t* offset, size_t* pSize); 40 | bool FindPermutationInBlob(const void* blob, size_t blobSize, const ShaderConstant* constants, uint32_t numConstants, const void** pBinary, size_t* pSize); 41 | void EnumeratePermutationsInBlob(const void* blob, size_t blobSize, std::vector& permutations); 42 | std::wstring FormatShaderNotFoundMessage(const void* blob, size_t blobSize, std::optional shaderMacroCRC); 43 | std::wstring FormatShaderNotFoundMessage(const void* blob, size_t blobSize, const ShaderConstant* constants, uint32_t numConstants); 44 | 45 | class IBlob 46 | { 47 | public: 48 | virtual ~IBlob() { } 49 | virtual const void* data() const = 0; 50 | virtual size_t size() const = 0; 51 | }; 52 | 53 | class Blob : public IBlob 54 | { 55 | private: 56 | void* m_data; 57 | size_t m_size; 58 | 59 | public: 60 | Blob(void* data, size_t size); 61 | virtual ~Blob() override; 62 | virtual const void* data() const override; 63 | virtual size_t size() const override; 64 | }; 65 | 66 | class SubBlob : public IBlob 67 | { 68 | private: 69 | const size_t m_offset; 70 | const size_t m_size; 71 | std::shared_ptr m_parent; 72 | 73 | public: 74 | SubBlob(); 75 | SubBlob(std::shared_ptr parent, size_t offset, size_t size); 76 | virtual ~SubBlob() override; 77 | virtual const void* data() const override; 78 | virtual size_t size() const override; 79 | }; 80 | 81 | class NonOwningBlob : public IBlob 82 | { 83 | private: 84 | void* m_data; 85 | size_t m_size; 86 | 87 | public: 88 | NonOwningBlob(void* data, size_t size) : m_data(data), m_size(size) { } 89 | virtual const void* data() const override { return m_data; } 90 | virtual size_t size() const override { return m_size; } 91 | }; 92 | }; 93 | -------------------------------------------------------------------------------- /src/Component.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | 24 | namespace KickstartRT_NativeLayer::Component 25 | { 26 | template 27 | Vector::Vector() 28 | { 29 | m_data = new T[4]; 30 | m_capacity = 4; 31 | m_size = 0; 32 | } 33 | 34 | template 35 | Vector::~Vector() 36 | { 37 | if (m_data != nullptr) 38 | delete[] m_data; 39 | } 40 | 41 | // move op 42 | template 43 | Vector& Vector::operator=(Vector&& other) 44 | { 45 | if (this == &other) 46 | return *this; 47 | 48 | delete[] m_data; 49 | m_data = other.m_data; 50 | m_size = other.m_size; 51 | m_capacity = other.m_capacity; 52 | 53 | other.m_data = nullptr; 54 | other.m_size = 0; 55 | other.m_capacity = 0; 56 | 57 | return *this; 58 | } 59 | 60 | template 61 | void Vector::reserve(size_t newCapacity) 62 | { 63 | if (newCapacity > m_capacity) { 64 | T* newData = new T[newCapacity]; 65 | 66 | // use = op. 67 | for (size_t i = 0; i < m_size; ++i) 68 | newData[i] = m_data[i]; 69 | 70 | delete[] m_data; 71 | m_data = newData; 72 | m_capacity = newCapacity; 73 | } 74 | } 75 | 76 | template 77 | void Vector::resize(size_t newSize) 78 | { 79 | if (newSize > m_size) { 80 | if (newSize > m_capacity) 81 | reserve(newSize); 82 | m_size = newSize; 83 | } 84 | else if (newSize < m_size) { 85 | // clear elements with = op. 86 | for (size_t i = newSize; i < m_size; ++i) 87 | m_data[i] = T(); 88 | m_size = newSize; 89 | } 90 | } 91 | 92 | // copy op 93 | template 94 | Vector& Vector::operator=(const Vector& other) 95 | { 96 | if (this == &other) 97 | return *this; 98 | 99 | resize(other.m_size); 100 | for (size_t i = 0; i < other.m_size; ++i) 101 | m_data[i] = other.m_data[i]; 102 | 103 | return *this; 104 | } 105 | 106 | template 107 | void Vector::push_back(T newElm) 108 | { 109 | if (m_size == m_capacity) 110 | reserve(m_capacity * 2); 111 | 112 | m_data[m_size++] = newElm; 113 | } 114 | } 115 | 116 | namespace KickstartRT_NativeLayer::Component 117 | { 118 | template class Vector; 119 | } 120 | -------------------------------------------------------------------------------- /interop_d3d11/src/Component.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | 24 | namespace KickstartRT_ExportLayer::Component 25 | { 26 | template 27 | Vector::Vector() 28 | { 29 | m_data = new T[4]; 30 | m_capacity = 4; 31 | m_size = 0; 32 | } 33 | 34 | template 35 | Vector::~Vector() 36 | { 37 | if (m_data != nullptr) 38 | delete[] m_data; 39 | } 40 | 41 | // move op 42 | template 43 | Vector& Vector::operator=(Vector&& other) 44 | { 45 | if (this == &other) 46 | return *this; 47 | 48 | delete[] m_data; 49 | m_data = other.m_data; 50 | m_size = other.m_size; 51 | m_capacity = other.m_capacity; 52 | 53 | other.m_data = nullptr; 54 | other.m_size = 0; 55 | other.m_capacity = 0; 56 | 57 | return *this; 58 | } 59 | 60 | template 61 | void Vector::reserve(size_t newCapacity) 62 | { 63 | if (newCapacity > m_capacity) { 64 | T* newData = new T[newCapacity]; 65 | 66 | // use = op. 67 | for (size_t i = 0; i < m_size; ++i) 68 | newData[i] = m_data[i]; 69 | 70 | delete[] m_data; 71 | m_data = newData; 72 | m_capacity = newCapacity; 73 | } 74 | } 75 | 76 | template 77 | void Vector::resize(size_t newSize) 78 | { 79 | if (newSize > m_size) { 80 | if (newSize > m_capacity) 81 | reserve(newSize); 82 | m_size = newSize; 83 | } 84 | else if (newSize < m_size) { 85 | // clear elements with = op. 86 | for (size_t i = newSize; i < m_size; ++i) 87 | m_data[i] = T(); 88 | m_size = newSize; 89 | } 90 | } 91 | 92 | // copy op 93 | template 94 | Vector& Vector::operator=(const Vector& other) 95 | { 96 | if (this == &other) 97 | return *this; 98 | 99 | resize(other.m_size); 100 | for (size_t i = 0; i < other.m_size; ++i) 101 | m_data[i] = other.m_data[i]; 102 | 103 | return *this; 104 | } 105 | 106 | template 107 | void Vector::push_back(T newElm) 108 | { 109 | if (m_size == m_capacity) 110 | reserve(m_capacity * 2); 111 | 112 | m_data[m_size++] = newElm; 113 | } 114 | } 115 | 116 | namespace KickstartRT_ExportLayer::Component 117 | { 118 | template class Vector; 119 | } 120 | -------------------------------------------------------------------------------- /src/common/CRC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #include "Arch.h" 25 | #include 26 | #ifndef ARCH_ARM 27 | #include 28 | #endif 29 | #include 30 | 31 | #ifdef _MSC_VER 32 | #define CRC_H_FORCEINLINE __forceinline 33 | #else 34 | #define CRC_H_FORCEINLINE __attribute__((__always_inline__)) 35 | #endif 36 | 37 | namespace KickstartRT::CRC { 38 | extern const bool CpuSupportsSSE42; 39 | extern const uint32_t CrcTable[]; 40 | 41 | class CrcHash 42 | { 43 | private: 44 | uint32_t crc; 45 | public: 46 | CrcHash() 47 | : crc(~0u) 48 | { 49 | } 50 | 51 | uint32_t Get() 52 | { 53 | return ~crc; 54 | } 55 | #ifndef ARCH_ARM 56 | template CRC_H_FORCEINLINE void AddBytesSSE42(const void* p) 57 | { 58 | static_assert(size % 4 == 0, "Size of hashable types must be multiple of 4"); 59 | 60 | const uint32_t* data = (const uint32_t*)p; 61 | 62 | const size_t numIterations = size / sizeof(uint32_t); 63 | for (size_t i = 0; i < numIterations; i++) 64 | { 65 | crc = _mm_crc32_u32(crc, data[i]); 66 | } 67 | } 68 | #endif 69 | CRC_H_FORCEINLINE void AddBytes(const char* p, size_t size) 70 | { 71 | for (size_t idx = 0; idx < size; idx++) 72 | crc = CrcTable[(crc ^ *p++) & 0xFF] ^ (crc >> 8); 73 | } 74 | 75 | template void Add(const T& value) 76 | { 77 | #ifndef ARCH_ARM 78 | if (CpuSupportsSSE42) 79 | AddBytesSSE42((void*)&value); 80 | else 81 | #endif 82 | AddBytes((char*)&value, sizeof(value)); 83 | } 84 | 85 | void Add(const void* p, size_t size) 86 | { 87 | #ifndef ARCH_ARM 88 | if (CpuSupportsSSE42) 89 | { 90 | uint32_t* data = (uint32_t*)p; 91 | const size_t numIterations = size / sizeof(uint32_t); 92 | for (size_t i = 0; i < numIterations; i++) 93 | { 94 | crc = _mm_crc32_u32(crc, data[i]); 95 | } 96 | 97 | if (size % sizeof(uint32_t)) 98 | { 99 | AddBytes((char*)&data[numIterations], size % sizeof(uint32_t)); 100 | } 101 | } 102 | else 103 | #endif 104 | { 105 | AddBytes((char*)p, size); 106 | } 107 | } 108 | 109 | template void AddVector(const std::vector& vec) 110 | { 111 | Add(vec.data(), vec.size() * sizeof(T)); 112 | } 113 | }; 114 | }; 115 | 116 | #undef CRC_H_FORCEINLINE 117 | -------------------------------------------------------------------------------- /interop_d3d11/src/ExecuteContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace KickstartRT_ExportLayer 33 | { 34 | extern std::mutex g_APIInterfaceMutex; // DLLMain 35 | }; 36 | 37 | struct ID3D12Fence; 38 | 39 | namespace KickstartRT_ExportLayer 40 | { 41 | class PersistentWorkingSet; 42 | struct TaskContainer; 43 | struct TaskContainer_impl; 44 | 45 | class ExecuteContext_impl : public ExecuteContext { 46 | std::mutex m_mutex; 47 | uint32_t m_numberOfWorkingSets = 0; 48 | uint64_t m_taskIndex = 1; 49 | 50 | public: 51 | std::unique_ptr m_persistentWorkingSet; 52 | 53 | public: 54 | ExecuteContext_impl(); 55 | ~ExecuteContext_impl(); 56 | 57 | Status Init(const ExecuteContext_InitSettings* settings); 58 | 59 | TaskContainer* CreateTaskContainer() override; 60 | 61 | DenoisingContextHandle CreateDenoisingContextHandle(const DenoisingContextInput* input) override; 62 | Status DestroyDenoisingContextHandle(DenoisingContextHandle handle) override; 63 | Status DestroyAllDenoisingContextHandles() override; 64 | 65 | GeometryHandle CreateGeometryHandle() override; 66 | Status CreateGeometryHandles(GeometryHandle* handles, uint32_t nbHandles) override; 67 | Status DestroyGeometryHandle(GeometryHandle handle) override; 68 | Status DestroyGeometryHandles(const GeometryHandle* handles, uint32_t nbHandles) override; 69 | Status DestroyAllGeometryHandles() override; 70 | 71 | InstanceHandle CreateInstanceHandle() override; 72 | Status CreateInstanceHandles(InstanceHandle* handles, uint32_t nbHandles) override; 73 | Status DestroyInstanceHandle(InstanceHandle handle) override; 74 | Status DestroyInstanceHandles(const InstanceHandle* handles, uint32_t nbHandles) override; 75 | Status DestroyAllInstanceHandles() override; 76 | 77 | Status InvokeGPUTask(TaskContainer* container, const BuildGPUTaskInput* input) override; 78 | Status ReleaseDeviceResourcesImmediately() override; 79 | 80 | Status GetLoadedShaderList(uint32_t* loadedListBuffer, size_t bufferSize, size_t* retListSize) override; 81 | 82 | Status GetCurrentResourceAllocations(ResourceAllocations* retStatus) override; 83 | Status BeginLoggingResourceAllocations(const wchar_t * filePath) override; 84 | Status EndLoggingResourceAllocations() override; 85 | }; 86 | }; 87 | 88 | -------------------------------------------------------------------------------- /src/OS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #if !defined WIN32 29 | #include 30 | #endif 31 | 32 | namespace KickstartRT 33 | { 34 | namespace OS 35 | { 36 | class SyncObject 37 | { 38 | public: 39 | SyncObject() : m_Signalled(false), m_Valid(false){} 40 | ~SyncObject() {} 41 | 42 | enum { 43 | Infinite = 0xFFFFFFFF, 44 | }; 45 | 46 | bool Init() 47 | { 48 | m_Valid = true; 49 | return true; 50 | } 51 | 52 | bool Cleanup() 53 | { 54 | m_Valid = false; 55 | m_CV.notify_all(); 56 | return true; 57 | } 58 | 59 | bool WaitForSignal(uint32_t timeout = Infinite) 60 | { 61 | std::unique_lock lock(m_Mutex); 62 | auto t = std::chrono::system_clock::now() + std::chrono::milliseconds{ timeout }; 63 | m_CV.wait_until(lock, t, [&]() {return IsSignalled() || !IsValid(); }); 64 | return IsSignalled(); 65 | } 66 | 67 | bool Signal() 68 | { 69 | std::unique_lock lock(m_Mutex); 70 | m_Signalled = true; 71 | lock.unlock(); 72 | m_CV.notify_all(); 73 | return true; 74 | } 75 | 76 | bool Reset() 77 | { 78 | std::unique_lock lock(m_Mutex); 79 | m_Signalled = false; 80 | lock.unlock(); 81 | return true; 82 | } 83 | 84 | bool IsValid() 85 | { 86 | return m_Valid; 87 | } 88 | 89 | bool IsSignalled() 90 | { 91 | return m_Signalled; 92 | } 93 | 94 | private: 95 | std::mutex m_Mutex; 96 | std::condition_variable m_CV; 97 | bool m_Signalled; 98 | std::atomic m_Valid; 99 | }; 100 | 101 | inline uint64_t SetThreadAffinityMask(std::thread* pThread, uint64_t mask) 102 | { 103 | #ifdef WIN32 104 | return ::SetThreadAffinityMask(pThread->native_handle(), mask); 105 | #else 106 | cpu_set_t cpuset; 107 | CPU_ZERO(&cpuset); 108 | for (int j = 0; j < 64; j++) 109 | if (j & mask) 110 | CPU_SET(j, &cpuset); 111 | return (pthread_setaffinity_np(pThread->native_handle(), sizeof(cpu_set_t), &cpuset) == 0); 112 | #endif 113 | } 114 | 115 | inline uint32_t SetThreadName(std::thread* pThread, std::wstring& name) 116 | { 117 | #ifdef WIN32 118 | return ::SetThreadDescription(pThread->native_handle(), name.c_str()); 119 | #else 120 | std::string str(name.begin(), name.end()); 121 | return pthread_setname_np(pThread->native_handle(), str.c_str()); 122 | #endif 123 | } 124 | } 125 | 126 | } -------------------------------------------------------------------------------- /shaders/DirectLightingCache/GBuffer_functions.hlsli: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | // applying viewport offset. 23 | uint2 ToSamplePos(uint2 idx) 24 | { 25 | uint x = idx.x + CB.m_Viewport_TopLeftX; 26 | uint y = idx.y + CB.m_Viewport_TopLeftY; 27 | return uint2(x, y); 28 | } 29 | 30 | uint2 getCheckerboardCoordinates(uint2 pixelIndex, bool invertCheckerboard) { 31 | 32 | pixelIndex.x *= 2; 33 | 34 | if (invertCheckerboard == (pixelIndex.y & 1)) { 35 | pixelIndex.x += 1; 36 | } 37 | 38 | return pixelIndex; 39 | } 40 | 41 | #if defined(GBUFFER_DEPTH_TEXTURE_AVAILABLE) 42 | float3 GetWorldPositionFromDepth(uint2 launchIndex, uint2 samplePos, out bool isValid) 43 | { 44 | float4 depthInput = t_DepthTex[samplePos]; 45 | float3 worldPos = depthInput.xyz; 46 | 47 | isValid = false; 48 | 49 | if ((DepthType)CB.m_depthType == DepthType::RGB_WorldSpace) { 50 | // depth tex holds world position. 51 | // nothing to do 52 | 53 | // use 4th channel to tell if pixel is valid or not 54 | isValid = (depthInput.a != 0); 55 | } 56 | else if ((DepthType)CB.m_depthType == DepthType::R_ClipSpace) { 57 | // depth tex hold clips space z. 58 | float2 fLaunchIndex = (float2)launchIndex; 59 | 60 | float clipZ = worldPos.x; // Rch holds clip depth. 61 | clipZ = ((CB.m_Viewport_MaxDepth - CB.m_Viewport_MinDepth) * clipZ) + CB.m_Viewport_MinDepth; 62 | float2 clipXY = ((fLaunchIndex.xy + 0.5) / float2(CB.m_Viewport_Width, CB.m_Viewport_Height)) * 2.0 - 1.0; 63 | 64 | #if defined(GRAPHICS_API_D3D) 65 | clipXY.y = -clipXY.y; // D3D always flip Y direction between viewport and NDC. 66 | #elif defined(GRAPHICS_API_VK) 67 | #else 68 | #error "GRAPHICS_API_XXX undefined." 69 | #endif 70 | 71 | float4 clipPos = float4(clipXY, clipZ, 1.0); 72 | 73 | float4 viewPos = mul(clipPos, CB.m_clipToViewMatrix); 74 | viewPos.xyz /= viewPos.w; 75 | viewPos.w = 1.0; 76 | float4 wPos = mul(viewPos, CB.m_viewToWorldMatrix); 77 | worldPos.xyz = wPos.xyz / wPos.w; 78 | 79 | // In clip space, 0.0 and 1.0 are usually don't have valid pixels that hits BVH 80 | if (clipZ > 0.0 && clipZ < 1.0) 81 | isValid = true; 82 | } 83 | 84 | return worldPos; 85 | } 86 | 87 | #endif 88 | 89 | #if defined(GBUFFER_NORMAL_TEXTURE_AVAILABLE) 90 | float3 GetNormal(uint2 samplePos, out bool isValid) 91 | { 92 | float4 normalTex = t_NormalTex.Load(int3(samplePos, 0)).xyzw; 93 | return GetWorldNormal(normalTex, CB.m_normalType, CB.m_normalNormalizationFactor, CB.m_normalChMask1, CB.m_normalChMask2, (float3x3)CB.m_normalToWorldMatrix, isValid); 94 | } 95 | #endif 96 | 97 | 98 | -------------------------------------------------------------------------------- /src/SharedCPUDescriptorHeap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | namespace KickstartRT_NativeLayer 31 | { 32 | class SharedCPUDescriptorHeap 33 | { 34 | protected: 35 | GraphicsAPI::DescriptorHeap::Type m_descType; 36 | GraphicsAPI::DescriptorTableLayout m_fixedLayout; 37 | size_t m_fixedAllocationSize; 38 | size_t m_totalNumberOfDescTableInHeapBlock = 0; 39 | 40 | struct SharedHeapBlock 41 | { 42 | GraphicsAPI::DescriptorHeap m_heap; 43 | size_t m_totalCreated = 0; 44 | std::list m_availableTables; 45 | std::set m_usingTables; 46 | }; 47 | std::deque> m_heapBlocks; 48 | 49 | public: 50 | struct SharedTableEntry 51 | { 52 | protected: 53 | SharedCPUDescriptorHeap* const m_manager; 54 | SharedHeapBlock* const m_heapBlock; 55 | 56 | public: 57 | GraphicsAPI::DescriptorTable* const m_table; 58 | 59 | public: 60 | SharedTableEntry(SharedCPUDescriptorHeap* manager, SharedHeapBlock* heapBlock, GraphicsAPI::DescriptorTable* table) : 61 | m_manager(manager), 62 | m_heapBlock(heapBlock), 63 | m_table(table) 64 | {}; 65 | 66 | ~SharedTableEntry() 67 | { 68 | auto itr = m_heapBlock->m_usingTables.find(m_table); 69 | 70 | // invalid desctable 71 | if (itr == m_heapBlock->m_usingTables.end()) { 72 | Log::Fatal(L"Failed to release a descriptor heap entry"); 73 | } 74 | else { 75 | // remove from used entry and put it to the tail of available list. 76 | m_heapBlock->m_usingTables.erase(itr); 77 | m_heapBlock->m_availableTables.push_back(m_table); 78 | } 79 | }; 80 | }; 81 | 82 | public: 83 | Status Init(GraphicsAPI::Device* dev, 84 | GraphicsAPI::DescriptorHeap::Type type, size_t fixeAllocationSize, size_t heapBlockSize); 85 | std::unique_ptr Allocate(GraphicsAPI::Device* dev); 86 | }; 87 | }; 88 | -------------------------------------------------------------------------------- /src/SceneContainer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace KickstartRT_NativeLayer 34 | { 35 | class SceneContainer { 36 | friend class Scene; 37 | 38 | // mutex for all operations. 39 | std::mutex m_mutex; 40 | 41 | // all registered geometry, not removed yet, should be in this map. 42 | std::unordered_map> m_geometries; 43 | // Removed geometries that are hidden from external APIs, but still alive. Once it's m_refCount become '0'. Geometry is moved to ready to destruct. 44 | std::unordered_map> m_removedGeometries; 45 | // This list is cleared every frame after actual destruction process. 46 | std::list> m_readyToDestructGeometries; 47 | 48 | // This list acts as a task queue for building BVH. Mostry comming from added geometries. 49 | std::deque m_buildBVHQueue; 50 | 51 | // This lists geometries after transformations and before tile allocation due to readback latency. 52 | std::deque> m_waitingForTileAllocationGeometries; 53 | 54 | // This lists geometries after building BVH and before compaction due to readback latency. 55 | std::deque> m_waitingForBVHCompactionGeometries; 56 | 57 | // all registered instances, not removed yet, should be in this map. 58 | std::unordered_map> m_instances; 59 | 60 | // Valid instance list for TLAS and desctable. Updated during TLAS build process, and referred during desc table update. 61 | std::list m_TLASInstanceList; 62 | 63 | // This list is cleared every frame after actual destruction process. 64 | std::list> m_readyToDestructInstances; 65 | 66 | // need to update direct lighting cache, requested from referencing geometry. This list is created/deleted every frame during BVH build process. 67 | std::deque m_needToUpdateDirectLightingCache; 68 | 69 | // All the currently alive denoising contexts. 70 | std::deque > m_denoisingContexts; 71 | 72 | using GeomMapIterator = typename std::unordered_map>::iterator; 73 | using InsMapIterator = typename std::unordered_map>::iterator; 74 | 75 | ~SceneContainer(); 76 | }; 77 | }; 78 | -------------------------------------------------------------------------------- /src/SharedCPUDescriptorHeap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | 25 | namespace KickstartRT_NativeLayer 26 | { 27 | Status SharedCPUDescriptorHeap::Init(GraphicsAPI::Device* dev, 28 | GraphicsAPI::DescriptorHeap::Type type, size_t fixeAllocationSize, size_t heapBlockSize) 29 | { 30 | m_descType = type; 31 | m_fixedAllocationSize = fixeAllocationSize; 32 | m_totalNumberOfDescTableInHeapBlock = GraphicsAPI::ALIGN(m_fixedAllocationSize, heapBlockSize); 33 | 34 | // create desc layout 35 | m_fixedLayout.AddRange(m_descType, 0, (uint32_t)m_fixedAllocationSize, 0); 36 | m_fixedLayout.SetAPIData(dev); 37 | 38 | return Status::OK; 39 | }; 40 | 41 | std::unique_ptr SharedCPUDescriptorHeap::Allocate(GraphicsAPI::Device* dev) 42 | { 43 | SharedHeapBlock* availableH = nullptr; 44 | 45 | // try to find a entry form exisitng pools 46 | for (auto&& h : m_heapBlocks) { 47 | if (h->m_availableTables.size() == 0 && h->m_totalCreated >= m_totalNumberOfDescTableInHeapBlock) 48 | continue; 49 | availableH = h.get(); 50 | break; 51 | } 52 | 53 | if (availableH == nullptr) { 54 | // create a new CPU desc heap. 55 | using DH = GraphicsAPI::DescriptorHeap; 56 | DH::Desc desc = {}; 57 | desc.m_totalDescCount = (uint32_t)m_totalNumberOfDescTableInHeapBlock; 58 | desc.m_descCount[DH::value(m_descType)] = desc.m_totalDescCount; 59 | 60 | auto newH = std::make_unique(); 61 | if (!newH->m_heap.Create(dev, desc, false)) { 62 | Log::Fatal(L"Failed to create descriptor heap pool"); 63 | return std::unique_ptr(); 64 | } 65 | newH->m_heap.SetName(DebugName(L"Shared CPU Descriptor.")); 66 | 67 | availableH = newH.get(); 68 | m_heapBlocks.push_back(std::move(newH)); 69 | } 70 | 71 | GraphicsAPI::DescriptorTable* retTable = nullptr; 72 | 73 | if (availableH->m_availableTables.size() > 0) { 74 | // reuse an available entry. 75 | retTable = availableH->m_availableTables.front(); 76 | availableH->m_availableTables.pop_front(); 77 | } 78 | else 79 | { 80 | // create new entry. 81 | auto dt = std::make_unique(); 82 | if (!dt->Allocate(&availableH->m_heap, &m_fixedLayout, 0)) { 83 | Log::Fatal(L"Failed to allocate descriptor table from a pool."); 84 | return std::unique_ptr(); 85 | } 86 | retTable = dt.release(); 87 | availableH->m_totalCreated += m_fixedAllocationSize; 88 | } 89 | availableH->m_usingTables.insert(retTable); 90 | 91 | return std::make_unique(this, availableH, retTable); 92 | } 93 | }; 94 | -------------------------------------------------------------------------------- /src/TaskWorkingSet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace KickstartRT_NativeLayer 33 | { 34 | class PersistentWorkingSet; 35 | 36 | class TaskWorkingSet 37 | { 38 | public: 39 | struct VolatileConstantBuffer 40 | { 41 | GraphicsAPI::Buffer m_cb; 42 | uint64_t m_currentOffsetInBytes; 43 | intptr_t m_cpuPtr; 44 | 45 | VolatileConstantBuffer() 46 | { 47 | m_currentOffsetInBytes = 0; 48 | m_cpuPtr = 0; 49 | }; 50 | Status BeginMapping(GraphicsAPI::Device* dev); 51 | void EndMapping(GraphicsAPI::Device* dev); 52 | 53 | Status Allocate(uint32_t allocationSizeInByte, GraphicsAPI::ConstantBufferView* cbv, void** ptrForWrite); 54 | }; 55 | 56 | PersistentWorkingSet* const m_persistentWorkingSet; 57 | 58 | std::unique_ptr m_CBVSRVUAVHeap; 59 | VolatileConstantBuffer m_volatileConstantBuffer; 60 | 61 | public: 62 | std::unique_ptr m_TLASUploadBuffer; 63 | #if KICKSTARTRT_ENABLE_DIRECT_LIGHTING_CACHE_INDIRECTION_TABLE 64 | std::unique_ptr m_directLightingCacheIndirectionTableUploadBuffer; 65 | #endif 66 | 67 | TaskWorkingSet(PersistentWorkingSet* pws) : 68 | m_persistentWorkingSet(pws) 69 | { 70 | }; 71 | 72 | Status Init(const KickstartRT_NativeLayer::ExecuteContext_InitSettings* const settings); 73 | Status Begin(); 74 | Status End(); 75 | }; 76 | 77 | class TaskWorkingSetCommandList { 78 | public: 79 | Status m_sts; 80 | TaskWorkingSet* m_set; 81 | GraphicsAPI::CommandList* m_commandList = nullptr; 82 | 83 | TaskWorkingSetCommandList(TaskWorkingSet* set, GraphicsAPI::CommandList *userPorvidedCmdList) : 84 | m_set(set) 85 | { 86 | m_sts = m_set->Begin(); 87 | if (m_sts != Status::OK) { 88 | Log::Fatal(L"TaskWorkignSet::Begin() failed."); 89 | return; 90 | } 91 | m_commandList = userPorvidedCmdList; 92 | 93 | m_sts = m_set->m_persistentWorkingSet->InitWithCommandList(m_commandList); 94 | if (m_sts != Status::OK) { 95 | Log::Fatal(L"Failed to do init with command list."); 96 | return; 97 | } 98 | 99 | // Setting fws desc heap. 100 | m_commandList->SetDescriptorHeap(m_set->m_CBVSRVUAVHeap.get()); 101 | }; 102 | 103 | ~TaskWorkingSetCommandList() 104 | { 105 | if (m_set->End() != Status::OK) { 106 | Log::Fatal(L"TaskWorkignSet::End() failed."); 107 | return; 108 | } 109 | m_commandList = nullptr; 110 | } 111 | }; 112 | 113 | }; 114 | -------------------------------------------------------------------------------- /interop_d3d11/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # 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 THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | cmake_minimum_required(VERSION 3.20) 23 | set(CMAKE_CXX_STANDARD 17) 24 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 25 | set(CMAKE_CXX_EXTENSIONS ON) 26 | 27 | # -------------------------------------- 28 | # D3D11 Interop Project 29 | # -------------------------------------- 30 | 31 | if (KickstartRT_SDK_WITH_DX12) 32 | 33 | # Setup the project 34 | project(${SDK_NAME}_Interop_D3D11) 35 | 36 | set (KickstartRT_SDK_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) 37 | 38 | file(GLOB ${SDK_NAME}_Interop_D3D11_SOURCE 39 | src/*.cpp 40 | ) 41 | 42 | file(GLOB ${SDK_NAME}_Interop_D3D11_INCLUDE 43 | src/*.h 44 | ) 45 | 46 | file(GLOB ${SDK_NAME}_core_interface 47 | ${KickstartRT_SDK_ROOT}/include/*.h 48 | ) 49 | 50 | add_library(${SDK_NAME}_Interop_D3D11 SHARED 51 | ${${SDK_NAME}_Interop_D3D11_SOURCE} 52 | ${${SDK_NAME}_Interop_D3D11_INCLUDE} 53 | ${${SDK_NAME}_Interop_D3D11_COMMON_SOURCE} 54 | ${${SDK_NAME}_Interop_D3D11_COMMON_INCLUDE} 55 | ${${SDK_NAME}_core_interface} 56 | ) 57 | source_group("Header Files\\Interface" FILES ${${SDK_NAME}_core_interface}) 58 | source_group("Header Files\\Common" FILES ${${SDK_NAME}_Interop_D3D11_COMMON_INCLUDE}) 59 | source_group("Source Files\\Common" FILES ${${SDK_NAME}_Interop_D3D11_COMMON_SOURCE}) 60 | 61 | set_target_properties(${SDK_NAME}_Interop_D3D11 PROPERTIES PUBLIC_HEADER "${${SDK_NAME}_core_interface}") 62 | set_target_properties(${SDK_NAME}_Interop_D3D11 PROPERTIES OUTPUT_NAME ${SDK_NAME}_Interop_D3D11) 63 | set_target_properties(${SDK_NAME}_Interop_D3D11 PROPERTIES CXX_STANDARD 17) 64 | 65 | target_link_libraries(${SDK_NAME}_Interop_D3D11 PRIVATE 66 | "d3d11.lib" 67 | "d3d12.lib" 68 | "dxguid.lib" 69 | ${SDK_NAME}_core_DX12 70 | ) 71 | 72 | 73 | target_include_directories(${SDK_NAME}_Interop_D3D11 PRIVATE 74 | src 75 | include 76 | ${KickstartRT_SDK_ROOT}/include 77 | ${KickstartRT_SDK_ROOT}/common/src 78 | ) 79 | target_compile_definitions(${SDK_NAME}_Interop_D3D11 PRIVATE GRAPHICS_API_D3D12) 80 | 81 | target_compile_options(${SDK_NAME}_Interop_D3D11 PRIVATE "$<$:/MT>") 82 | target_compile_options(${SDK_NAME}_Interop_D3D11 PRIVATE "$<$:/MTd>") 83 | target_compile_options(${SDK_NAME}_Interop_D3D11 PRIVATE "$<$:/Zi>") 84 | target_link_options(${SDK_NAME}_Interop_D3D11 PRIVATE "$<$:/DEBUG>") 85 | target_link_options(${SDK_NAME}_Interop_D3D11 PRIVATE "$<$:/OPT:REF>") 86 | target_link_options(${SDK_NAME}_Interop_D3D11 PRIVATE "$<$:/OPT:ICF>") 87 | 88 | add_dependencies(${SDK_NAME}_Interop_D3D11 ${SDK_NAME}_core_DX12) 89 | 90 | target_compile_options(${SDK_NAME}_Interop_D3D11 PRIVATE 91 | -D KickstartRT_Interop_D3D11_DECLSPEC=__declspec\(dllexport\) 92 | ) 93 | target_compile_options(${SDK_NAME}_Interop_D3D11 PRIVATE /W4) 94 | 95 | set_target_properties(${SDK_NAME}_Interop_D3D11 PROPERTIES FOLDER ${SDK_NAME}) 96 | endif() 97 | -------------------------------------------------------------------------------- /src/RenderPass_DirectLightingCacheAllocation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace KickstartRT_NativeLayer 32 | { 33 | namespace BVHTask { 34 | struct Geometry; 35 | }; 36 | class TaskWorkingSet; 37 | 38 | struct RenderPass_DirectLightingCacheAllocation 39 | { 40 | static constexpr uint32_t m_threadDim_X = 96; 41 | 42 | enum class AllocationShaderPermutationBits : uint32_t { 43 | e_BUILD_OP = 0b0000'0011, 44 | e_USE_VERTEX_INDEX_INPUTS = 0b0000'0100, 45 | e_NumberOfPermutations = 0b0000'1000, 46 | }; 47 | 48 | enum DescTableLayout : uint32_t { 49 | e_CB_CBV = 0, 50 | e_VertexBuffer_SRV, 51 | e_IndexBuffer_SRV, 52 | e_Index_VertexBuffer_UAV, 53 | e_TileCounterBuffer_UAV, 54 | e_TileIndexBuffer_UAV, 55 | 56 | e_DescTableSize, 57 | }; 58 | 59 | struct CB { 60 | uint32_t m_vertexStride; 61 | uint32_t m_nbVertices; 62 | uint32_t m_nbIndices; 63 | uint32_t m_dstVertexBufferOffsetIdx; 64 | 65 | uint32_t m_indexRangeMin; 66 | uint32_t m_indexRangeMax; 67 | uint32_t m_tileResolutionLimit; 68 | float m_tileUnitLength; 69 | 70 | uint32_t m_enableTransformation; 71 | uint32_t m_nbDispatchThreads; 72 | uint32_t m_nbHashTableElemsNum; 73 | uint32_t m_allocationOffset; 74 | 75 | uint32_t m_vtxSRVOffsetElm; 76 | uint32_t m_idxSRVOffsetElm; 77 | uint32_t m_vtxComponentOffset; 78 | uint32_t m_idxComponentOffset; 79 | 80 | Math::Float_4x4 m_transformationMatrix; 81 | }; 82 | 83 | GraphicsAPI::DescriptorTableLayout m_descTableLayout; 84 | 85 | GraphicsAPI::RootSignature m_rootSignature; 86 | std::array m_pso_allocate_itr; 87 | 88 | protected: 89 | // Must match .hlsl 90 | enum class BuildOp { 91 | TileCacheBuild, 92 | 93 | MeshColorBuild, 94 | MeshColorPostBuild, 95 | // 96 | VertexUpdate, 97 | }; 98 | Status BuildCommandList(BuildOp op, TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, GraphicsAPI::ComputePipelineState **currentPSO, BVHTask::Geometry* gp); 99 | 100 | public: 101 | Status Init(GraphicsAPI::Device *dev, ShaderFactory::Factory *sf); 102 | Status BuildCommandListForAdd(TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, std::deque& addedGeometries); 103 | Status BuildCommandListForUpdate(TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, std::deque& updatedGeometries); 104 | 105 | static Status CheckInputs(const BVHTask::GeometryInput& input); 106 | static Status CheckUpdateInputs(const BVHTask::GeometryInput& oldInput, const BVHTask::GeometryInput& input); 107 | static Status AllocateResourcesForGeometry(TaskWorkingSet* fws, std::deque& addedGeometries); 108 | }; 109 | }; 110 | -------------------------------------------------------------------------------- /include/KickstartRT_Interop_layer_d3d11.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #if !defined(WIN32_LEAN_AND_MEAN) 25 | #define WIN32_LEAN_AND_MEAN 26 | #endif 27 | #if !defined(NOMINMAX) 28 | #define NOMINMAX 29 | #endif 30 | #include 31 | #include 32 | #include 33 | 34 | #include "KickstartRT_common.h" 35 | 36 | #if defined (KickstartRT_Graphics_API_D3D11) 37 | 38 | #include 39 | 40 | namespace KickstartRT { 41 | namespace D3D11 { 42 | struct BuildGPUTaskInput { 43 | // If true, update BLAS and TLAS before doing any rendering task. 44 | bool geometryTaskFirst = true; 45 | // The max number of BLASes to be built from the build queue. 46 | uint32_t maxBlasBuildCount = 4u; 47 | 48 | ID3D11Fence* waitFence; 49 | uint64_t waitFenceValue = (uint64_t)-1; 50 | ID3D11Fence* signalFence; 51 | uint64_t signalFenceValue = (uint64_t)-1; 52 | }; 53 | 54 | // ============================================================== 55 | // RenderTask 56 | // ============================================================== 57 | namespace RenderTask { 58 | struct ShaderResourceTex { 59 | D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; 60 | ID3D11Resource* resource = nullptr; 61 | }; 62 | 63 | struct UnorderedAccessTex { 64 | D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc = {}; 65 | ID3D11Resource* resource = nullptr; 66 | }; 67 | 68 | struct CombinedAccessTex { 69 | D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; 70 | D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc = {}; 71 | ID3D11Resource* resource = nullptr; 72 | }; 73 | }; 74 | 75 | // ============================================================== 76 | // BVHTask 77 | // ============================================================== 78 | // These data structures are for geometry inputs. 79 | // ============================================================== 80 | namespace BVHTask { 81 | struct VertexBufferInput { 82 | ID3D11Resource* resource = nullptr; 83 | DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; 84 | UINT64 offsetInBytes = 0ull; 85 | UINT strideInBytes = 0u; 86 | UINT count = 0u; 87 | }; 88 | struct IndexBufferInput { 89 | ID3D11Resource* resource = nullptr; 90 | DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; 91 | UINT64 offsetInBytes = 0ull; 92 | UINT count = 0u; 93 | }; 94 | }; 95 | 96 | struct ExecuteContext_InitSettings { 97 | IDXGIAdapter1* DXGIAdapter = nullptr; 98 | ID3D11Device* D3D11Device = nullptr; 99 | 100 | enum class UsingCommandQueue : uint32_t { 101 | Direct, 102 | Compute, 103 | }; 104 | 105 | UsingCommandQueue usingCommandQueue = UsingCommandQueue::Direct; 106 | uint32_t supportedWorkingSet = 4u; 107 | uint32_t descHeapSize = 8192u; 108 | uint32_t uploadHeapSizeForVolatileConstantBuffers = 64u * 1024u; 109 | 110 | uint32_t* coldLoadShaderList = nullptr; 111 | uint32_t coldLoadShaderListSize = 0u; 112 | }; 113 | 114 | #define KickstartRT_DECLSPEC_INL KickstartRT_Interop_D3D11_DECLSPEC 115 | #define KickstartRT_ExecutionContext_Interop 116 | #include "KickstartRT_inl.h" 117 | #undef KickstartRT_ExecutionContext_Interop 118 | #undef KickstartRT_DECLSPEC_INL 119 | }; 120 | }; 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /src/VirtualFS.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 | #pragma once 23 | #include "common/ShaderBlob.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | namespace KickstartRT::VirtualFS 32 | { 33 | class IFileSystem 34 | { 35 | public: 36 | virtual bool folderExists(const std::filesystem::path& name) = 0; 37 | virtual bool fileExists(const std::filesystem::path& name) = 0; 38 | virtual std::shared_ptr readFile(const std::filesystem::path& name) = 0; 39 | virtual bool writeFile(const std::filesystem::path& name, const void* data, size_t size) = 0; 40 | virtual bool enumerate(const std::filesystem::path& pattern, bool directories, std::vector& results) = 0; 41 | }; 42 | 43 | class NativeFileSystem : public IFileSystem 44 | { 45 | public: 46 | virtual bool folderExists(const std::filesystem::path& name) override; 47 | virtual bool fileExists(const std::filesystem::path& name) override; 48 | virtual std::shared_ptr readFile(const std::filesystem::path& name) override; 49 | virtual bool writeFile(const std::filesystem::path& name, const void* data, size_t size) override; 50 | virtual bool enumerate(const std::filesystem::path& pattern, bool directories, std::vector& results) override; 51 | }; 52 | 53 | class RelativeFileSystem : public IFileSystem 54 | { 55 | private: 56 | std::shared_ptr m_Parent; 57 | std::filesystem::path m_BasePath; 58 | public: 59 | RelativeFileSystem(std::shared_ptr parent, const std::filesystem::path& basePath); 60 | 61 | std::filesystem::path const& GetBasePath() const { return m_BasePath; } 62 | 63 | virtual bool folderExists(const std::filesystem::path& name) override; 64 | virtual bool fileExists(const std::filesystem::path& name) override; 65 | virtual std::shared_ptr readFile(const std::filesystem::path& name) override; 66 | virtual bool writeFile(const std::filesystem::path& name, const void* data, size_t size) override; 67 | virtual bool enumerate(const std::filesystem::path& pattern, bool directories, std::vector& results) override; 68 | }; 69 | 70 | class RootFileSystem : public IFileSystem 71 | { 72 | private: 73 | std::vector>> m_MountPoints; 74 | 75 | bool findMountPoint(const std::filesystem::path& path, std::filesystem::path* pRelativePath, IFileSystem** ppFS); 76 | public: 77 | void mount(const std::filesystem::path& path, std::shared_ptr fs); 78 | void mount(const std::filesystem::path& path, const std::filesystem::path& nativePath); 79 | bool unmount(const std::filesystem::path& path); 80 | 81 | virtual bool folderExists(const std::filesystem::path& name) override; 82 | virtual bool fileExists(const std::filesystem::path& name) override; 83 | virtual std::shared_ptr readFile(const std::filesystem::path& name) override; 84 | virtual bool writeFile(const std::filesystem::path& name, const void* data, size_t size) override; 85 | virtual bool enumerate(const std::filesystem::path& pattern, bool directories, std::vector& wresults) override; 86 | }; 87 | 88 | }; 89 | -------------------------------------------------------------------------------- /src/ExecuteContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace KickstartRT_NativeLayer 40 | { 41 | class PersistentWorkingSet; 42 | class TaskWorkingSet; 43 | class Scene; 44 | }; 45 | 46 | namespace KickstartRT 47 | { 48 | extern std::mutex g_APIInterfaceMutex; // DLLMain 49 | }; 50 | 51 | namespace KickstartRT_NativeLayer 52 | { 53 | struct UpdateFromExecuteContext { 54 | std::deque> m_createdGeometries; 55 | std::deque> m_createdInstances; 56 | std::deque> m_createdDenoisingContexts; 57 | std::deque m_destroyedGeometries; 58 | std::deque m_destroyedInstances; 59 | std::deque m_destroyedDenoisingContexts; 60 | bool m_destroyAllGeometries = false; 61 | bool m_destroyAllInstances = false; 62 | bool m_destroyAllDenoisingContexts = false; 63 | }; 64 | 65 | class ExecuteContext_impl : public ExecuteContext { 66 | protected: 67 | std::unique_ptr m_taskTracker; 68 | 69 | ExecuteContext_InitSettings m_initSettings; 70 | 71 | std::unique_ptr m_scene; 72 | std::unique_ptr m_persistentWorkingSet; 73 | 74 | std::mutex m_updateFromExecuteContextMutex; 75 | UpdateFromExecuteContext m_updateFromExecuteContext; 76 | 77 | public: 78 | ExecuteContext_impl(); 79 | virtual ~ExecuteContext_impl(); 80 | 81 | Status Init(const ExecuteContext_InitSettings *settings); 82 | 83 | TaskContainer* CreateTaskContainer() override; 84 | 85 | DenoisingContextHandle CreateDenoisingContextHandle(const DenoisingContextInput* input) override; 86 | Status DestroyDenoisingContextHandle(DenoisingContextHandle handle) override; 87 | Status DestroyAllDenoisingContextHandles() override; 88 | 89 | GeometryHandle CreateGeometryHandle() override; 90 | Status CreateGeometryHandles(GeometryHandle* handles, uint32_t nbHandles) override; 91 | Status DestroyGeometryHandle(GeometryHandle handle) override; 92 | Status DestroyGeometryHandles(const GeometryHandle* handles, uint32_t nbHandles) override; 93 | Status DestroyAllGeometryHandles() override; 94 | 95 | InstanceHandle CreateInstanceHandle() override; 96 | Status CreateInstanceHandles(InstanceHandle* handles, uint32_t nbHandles) override; 97 | Status DestroyInstanceHandle(InstanceHandle handle) override; 98 | Status DestroyInstanceHandles(const InstanceHandle* handles, uint32_t nbHandles) override; 99 | Status DestroyAllInstanceHandles() override; 100 | 101 | Status BuildGPUTask(GPUTaskHandle *retHandle, TaskContainer *container, const BuildGPUTaskInput* input) override; 102 | Status MarkGPUTaskAsCompleted(GPUTaskHandle handle) override; 103 | Status ReleaseDeviceResourcesImmediately() override; 104 | 105 | Status GetLoadedShaderList(uint32_t* loadedListBuffer, size_t bufferSize, size_t* retListSize) override; 106 | 107 | Status GetCurrentResourceAllocations(ResourceAllocations* retStatus) override; 108 | Status BeginLoggingResourceAllocations(const wchar_t * filePath) override; 109 | Status EndLoggingResourceAllocations() override; 110 | }; 111 | }; 112 | -------------------------------------------------------------------------------- /src/Scene.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | namespace KickstartRT_NativeLayer 42 | { 43 | class Scene { 44 | public: 45 | protected: 46 | const bool m_enableInfoLog = false; 47 | 48 | SceneContainer m_container; 49 | 50 | bool m_TLASisDrity = false; 51 | std::unique_ptr m_TLASScratchBuffer; 52 | std::unique_ptr m_TLASBuffer; 53 | std::unique_ptr m_TLASBufferSrv; 54 | 55 | #if KICKSTARTRT_ENABLE_DIRECT_LIGHTING_CACHE_INDIRECTION_TABLE 56 | std::unique_ptr m_directLightingCacheIndirectionTableBuffer; 57 | std::unique_ptr m_directLightingCacheIndirectionTableBufferUAV; 58 | std::deque m_directLightingCacheIndirectionTableSharedBlockEntries; 59 | #else 60 | struct CPULightCacheDescs { 61 | size_t m_allocatedDescTableSize = 0; 62 | std::unique_ptr m_descLayout; 63 | std::unique_ptr m_descHeap; 64 | std::unique_ptr m_descTable; 65 | std::vector m_instanceList; 66 | }; 67 | CPULightCacheDescs m_cpuLightCacheDescs; 68 | #endif 69 | 70 | Status UpdateScenegraphFromBVHTask(PersistentWorkingSet* pws, BVHTasks *bvhTasks, 71 | std::deque& addedGeometryPtrs, 72 | std::deque& updatedGeometryPtrs, 73 | std::deque& addedInstancePtrs, 74 | std::deque& updatedInstancePtrs, 75 | bool& isSceneChanged); 76 | 77 | Status DoReadbackAndTileAllocation(PersistentWorkingSet* pws, bool& AllocationHappened); 78 | Status DoAllocationForAddedInstances(PersistentWorkingSet* pws, std::deque& addedInstancePtrs, bool& AllocationHappened); 79 | 80 | Status DoReadbackAndCompactBLASBuffers(PersistentWorkingSet* pws, GraphicsAPI::CommandList* cmdList, bool& BLASChanged); 81 | 82 | Status BuildTransformAndTileAllocationCommands(TaskWorkingSet* tws, GraphicsAPI::CommandList* cmdList, 83 | std::deque& addedGeometries, 84 | std::deque& updatedGeometries); 85 | 86 | Status BuildBLASCommands(TaskWorkingSet* tws, GraphicsAPI::CommandList* cmdList, 87 | std::deque& updatedGeometryPtrs, 88 | uint32_t maxBlasBuildTasks, bool& BLASChanged); 89 | 90 | Status BuildTLASCommands(TaskWorkingSet* tws, GraphicsAPI::CommandList* cmdList); 91 | 92 | Status BuildDirectLightingCacheDescriptorTable(TaskWorkingSet* tws, GraphicsAPI::DescriptorTableLayout* srcLayout, GraphicsAPI::DescriptorTable* destDescTable, std::deque& retInstances); 93 | 94 | Status UpdateDenoisingContext(PersistentWorkingSet* pws, UpdateFromExecuteContext* updateFromExc); 95 | Status UpdateScenegraphFromExecuteContext(PersistentWorkingSet* pws, UpdateFromExecuteContext* updateFromExc, bool& isSceneChanged); 96 | 97 | public: 98 | Status BuildTask(GPUTaskHandle *retHandle, TaskTracker *taskTracker, PersistentWorkingSet* pws, TaskContainer_impl* arg_taskContainer, UpdateFromExecuteContext *updateFromExc, const BuildGPUTaskInput *input); 99 | Status ReleaseDeviceResourcesImmediately(TaskTracker* taskTracker, PersistentWorkingSet* pws, UpdateFromExecuteContext* updateFromExc); 100 | }; 101 | }; 102 | 103 | -------------------------------------------------------------------------------- /src/TaskTracker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace KickstartRT_NativeLayer 31 | { 32 | TaskTracker::TaskTracker() 33 | { 34 | }; 35 | 36 | TaskTracker::~TaskTracker() 37 | { 38 | }; 39 | 40 | Status TaskTracker::Init(PersistentWorkingSet* pws, const ExecuteContext_InitSettings* initSettings) 41 | { 42 | std::scoped_lock mtx(m_mutex); 43 | 44 | for (size_t i = 0; i < initSettings->supportedWorkingsets; ++i) { 45 | std::unique_ptr tws = std::make_unique(pws); 46 | auto sts = tws->Init(initSettings); 47 | if (sts != Status::OK) { 48 | Log::Fatal(L"Failed to init task working set."); 49 | m_taskWorkingSets.clear(); 50 | return sts; 51 | } 52 | m_taskWorkingSets.emplace_back(std::move(tws)); 53 | } 54 | 55 | // all working sets are now idling. 56 | m_taskIndicesForWorkingSets.resize(m_taskWorkingSets.size(), 0ull); 57 | 58 | return Status::OK; 59 | } 60 | 61 | uint64_t TaskTracker::CurrentTaskIndex() 62 | { 63 | std::scoped_lock mtx(m_mutex); 64 | 65 | return m_currentTaskIndex; 66 | } 67 | 68 | uint64_t TaskTracker::FinishedTaskIndex() 69 | { 70 | std::scoped_lock mtx(m_mutex); 71 | 72 | return m_finishedTaskIndex; 73 | } 74 | 75 | Status TaskTracker::UpdateFinishedTaskIndex(uint64_t finishedTaskIndex) 76 | { 77 | std::scoped_lock mtx(m_mutex); 78 | 79 | if (finishedTaskIndex == 0) 80 | return Status::OK; 81 | 82 | auto itr = std::find(m_taskIndicesForWorkingSets.begin(), m_taskIndicesForWorkingSets.end(), finishedTaskIndex); 83 | if (itr == m_taskIndicesForWorkingSets.end()) { 84 | Log::Fatal(L"Invalid finished task index (GPUTaskHandle) detected. :%" PRIu64, finishedTaskIndex); 85 | return Status::ERROR_INVALID_PARAM; 86 | } 87 | *itr = 0ull; 88 | 89 | // update finished task index. 90 | uint64_t minInFlightIdx = 0xFFFF'FFFF'FFFF'FFFFull; 91 | std::for_each(m_taskIndicesForWorkingSets.begin(), m_taskIndicesForWorkingSets.end(), 92 | [&minInFlightIdx](auto&& i) { if (i != 0ull && i < minInFlightIdx) minInFlightIdx= i; }); 93 | 94 | if (minInFlightIdx == 0xFFFF'FFFF'FFFF'FFFFull) { 95 | // If thre is no in-flight index, currentTask index has been finished. 96 | m_finishedTaskIndex = m_currentTaskIndex; 97 | } 98 | else { 99 | // If threre are in-flight indices, finished inidex should be (minimum of in-flight indices) - 1 100 | m_finishedTaskIndex = minInFlightIdx - 1; 101 | } 102 | 103 | return Status::OK; 104 | } 105 | 106 | bool TaskTracker::TaskWorkingSetIsAvailable() 107 | { 108 | std::scoped_lock mtx(m_mutex); 109 | 110 | auto itr = std::find(m_taskIndicesForWorkingSets.begin(), m_taskIndicesForWorkingSets.end(), 0ull); 111 | if (itr == m_taskIndicesForWorkingSets.end()) 112 | return false; 113 | 114 | return true; 115 | } 116 | 117 | Status TaskTracker::AllocateTaskWorkingSet(TaskWorkingSet **ret_tws, uint64_t *ret_taskIndex) 118 | { 119 | std::scoped_lock mtx(m_mutex); 120 | 121 | *ret_tws = nullptr; 122 | *ret_taskIndex = 0xFFFF'FFFF'FFFF'FFFF; 123 | 124 | auto itr = std::find(m_taskIndicesForWorkingSets.begin(), m_taskIndicesForWorkingSets.end(), 0ull); 125 | if (itr == m_taskIndicesForWorkingSets.end()) { 126 | Log::Fatal(L"Failed to allocate TaskWorkingSet. All tasks are in-flight."); 127 | return Status::ERROR_INTERNAL; 128 | } 129 | size_t idx = itr - m_taskIndicesForWorkingSets.begin(); 130 | 131 | // Advance the current task index. 132 | ++m_currentTaskIndex; 133 | 134 | m_taskIndicesForWorkingSets[idx] = m_currentTaskIndex; 135 | 136 | *ret_tws = m_taskWorkingSets[idx].get(); 137 | *ret_taskIndex = m_currentTaskIndex; 138 | 139 | return Status::OK; 140 | } 141 | }; 142 | 143 | -------------------------------------------------------------------------------- /src/common/CRC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include "CRC.h" 23 | 24 | #ifdef ARCH_X86 25 | #ifndef __GNUC__ 26 | #include 27 | #endif // __GNUC__ 28 | #endif 29 | 30 | namespace KickstartRT::CRC { 31 | 32 | static bool GetSSE42Support() 33 | { 34 | #ifdef ARCH_X86 35 | #ifdef __GNUC__ // gcc or clang 36 | return __builtin_cpu_supports("sse4.2"); 37 | #else // __GNUC__ 38 | int cpui[4]; 39 | __cpuidex(cpui, 1, 0); 40 | return !!(cpui[2] & 0x100000); 41 | #endif // __GNUC__ 42 | #else 43 | return false; 44 | #endif 45 | } 46 | 47 | const bool CpuSupportsSSE42 = GetSSE42Support(); 48 | 49 | const uint32_t CrcTable[] = { 50 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 51 | 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 52 | 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 53 | 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 54 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 55 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 56 | 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 57 | 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 58 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 59 | 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 60 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 61 | 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 62 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 63 | 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 64 | 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 65 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 66 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 67 | 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 68 | 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 69 | 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 70 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 71 | 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 72 | 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 73 | 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 74 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 75 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 76 | 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 77 | 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 78 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 79 | 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 80 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 81 | 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 82 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 83 | 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 84 | 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 85 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 86 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 87 | 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 88 | 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 89 | 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 90 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 91 | 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 92 | 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 93 | }; 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/RenderPass_Denoising.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | 26 | namespace KickstartRT_NativeLayer 27 | { 28 | class TaskWorkingSet; 29 | struct RenderPass_ResourceRegistry; 30 | 31 | namespace RenderTask { 32 | struct ShadowParams { 33 | 34 | // Global Light list 35 | LightInfo lightInfos[32]; 36 | uint32_t numLights = 0; 37 | 38 | // Input mask can be used to control which lights will be traced against on a per-pixel granularity. 39 | // uint-uint4 for managing up to 128 scene lights. 40 | // (Not implemented) 41 | ShaderResourceTex lightSelectionMask; 42 | 43 | // Enabling usually results in more efficient shadow tracing. 44 | // While it may resut in less accurate results for the denoiser that may require an accurate and stable hit distance 45 | bool enableFirstHitAndEndSearch = true; 46 | }; 47 | 48 | struct DenoisingOutput { 49 | 50 | enum class Mode : uint32_t { 51 | // (Default) Regular history accumulation mode 52 | Continue, 53 | 54 | // Discard and clear the history buffer 55 | DiscardHistory 56 | }; 57 | 58 | // Required. 59 | DenoisingContextHandle context = DenoisingContextHandle::Null; 60 | Mode mode = Mode::Continue; 61 | 62 | HalfResolutionMode halfResolutionMode = HalfResolutionMode::OFF; 63 | 64 | // Required for all signal types 65 | Viewport viewport; 66 | DepthInput depth; 67 | NormalInput normal; 68 | RoughnessInput roughness; 69 | // Motion is required for high quality denoising. Optional for debug purposes only 70 | MotionInput motion; 71 | 72 | Math::Float_4x4 clipToViewMatrix = Math::Float_4x4::Identity(); // (Pos_View) = (Pos_CliP) * (M) 73 | Math::Float_4x4 viewToClipMatrix = Math::Float_4x4::Identity(); // (Pos_CliP) = (Pos_View) * (M) 74 | Math::Float_4x4 viewToClipMatrixPrev = Math::Float_4x4::Identity(); // (Pos_CliP) = (Pos_View) * (M) 75 | Math::Float_4x4 worldToViewMatrix = Math::Float_4x4::Identity(); // (Pos_View) = (Pos_World) * (M) 76 | Math::Float_4x4 worldToViewMatrixPrev = Math::Float_4x4::Identity(); // (Pos_View) = (Pos_World) * (M) 77 | Math::Float_2 cameraJitter = { 0.f, 0.f }; 78 | 79 | // Required for SignalType DiffuseOcclusion 80 | Math::Float_4 occlusionHitTMask; 81 | 82 | // Required when running SignalType::Shadows. 83 | ShadowParams shadow; 84 | 85 | // Optional 86 | InputMaskInput inputMask; 87 | 88 | // Required for SignalType Specular and SpecularAndDiffuse 89 | ShaderResourceTex inSpecular; 90 | // Required for SignalType Specular and SpecularAndDiffuse 91 | CombinedAccessTex inOutSpecular; 92 | 93 | // Required for SignalType Diffuse and SpecularAndDiffuse 94 | ShaderResourceTex inDiffuse; 95 | // Required for SignalType Diffuse and SpecularAndDiffuse 96 | CombinedAccessTex inOutDiffuse; 97 | 98 | // Required for SignalType DiffuseOcclusion 99 | ShaderResourceTex inHitT; 100 | // Required for SignalType DiffuseOcclusion 101 | CombinedAccessTex inOutOcclusion; 102 | 103 | // Required for SignalType Shadow and MultiShadow 104 | // RG16f+ - Opaque NRD denoising data. 105 | ShaderResourceTex inShadow0; 106 | // Required for SignalType MultiShadow 107 | // RGBA8+ - Opaque NRD denoising data. 108 | ShaderResourceTex inShadow1; 109 | // Required for SignalType Shadow and MultiShadow 110 | // Shadow - R8+, R - Shadow value 111 | // MultiShadow - RGBA8+, R - Shadow value. GBA - Opaque history data 112 | CombinedAccessTex inOutShadow; 113 | 114 | Status ConvertFromRenderTask(const RenderTask::Task* task); 115 | }; 116 | }; 117 | }; 118 | 119 | namespace KickstartRT_NativeLayer 120 | { 121 | class RenderPass_NRDDenoising; 122 | 123 | struct RenderPass_Denoising 124 | { 125 | #if (KickstartRT_SDK_WITH_NRD) 126 | std::unique_ptr m_nrd; 127 | #endif 128 | public: 129 | RenderPass_Denoising(); 130 | ~RenderPass_Denoising(); 131 | RenderPass_Denoising(RenderPass_Denoising&&); 132 | RenderPass_Denoising& operator=(RenderPass_Denoising&& other); 133 | Status Init(PersistentWorkingSet* pws, const DenoisingContextInput& context, ShaderFactory::Factory* sf); 134 | Status DeferredRelease(PersistentWorkingSet* pws); 135 | Status BuildCommandList(TaskWorkingSet* tws, GraphicsAPI::CommandList* cmdList, RenderPass_ResourceRegistry* resources, const RenderTask::DenoisingOutput& reflectionOutputs); 136 | }; 137 | }; 138 | -------------------------------------------------------------------------------- /src/ResourceLogger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | namespace KickstartRT_NativeLayer 31 | { 32 | template struct ClassifiedDeviceObject; 33 | 34 | // this class simply try to understand the current allocation by SDK, not meant to track all resources precisely. 35 | class ResourceLogger { 36 | template friend struct ClassifiedDeviceObject; 37 | 38 | friend class PersistentWorkingSet; 39 | 40 | public: 41 | using ResourceKind = KickstartRT::ResourceAllocations::ResourceKind; 42 | 43 | protected: 44 | KickstartRT::ResourceAllocations m_allocationInfo; 45 | std::deque>> m_deferredReleasedDeviceObjects; 46 | 47 | bool m_isLogging; 48 | std::wstring m_logFilePath; 49 | static constexpr size_t m_logFlushFrames = 600; 50 | size_t m_flushTimes; 51 | std::deque> m_frameLogs; 52 | 53 | void DeferredRelease(uint64_t fenceValue, std::unique_ptr trackedObj) 54 | { 55 | if (trackedObj) { 56 | m_deferredReleasedDeviceObjects.push_back( 57 | { 58 | fenceValue, 59 | std::move(trackedObj) 60 | }); 61 | } 62 | } 63 | 64 | void ReleaseDeferredReleasedDeviceObjects(uint64_t completedFenceValue) 65 | { 66 | while (!m_deferredReleasedDeviceObjects.empty()) { 67 | if (m_deferredReleasedDeviceObjects.begin()->first > completedFenceValue) 68 | break; 69 | 70 | // destruct unique_ptr<> and it incurs dtor of the device object. 71 | m_deferredReleasedDeviceObjects.pop_front(); 72 | } 73 | } 74 | 75 | void CheckLeaks(); 76 | void LogResource(uint64_t frameIndex); 77 | 78 | void FlushLog(); 79 | public: 80 | ResourceLogger() 81 | { 82 | using RA = KickstartRT::ResourceAllocations; 83 | 84 | for (size_t i = 0; i < (size_t)RA::ResourceKind::e_Num_Kinds; ++i) { 85 | m_allocationInfo.m_numResources[i] = 0; 86 | m_allocationInfo.m_totalRequestedBytes[i] = 0; 87 | } 88 | 89 | m_isLogging = false; 90 | m_flushTimes = 0; 91 | } 92 | 93 | ~ResourceLogger() 94 | { 95 | // to flush incomplete log. 96 | EndLoggingResourceAllocations(); 97 | } 98 | 99 | 100 | Status BeginLoggingResourceAllocations(const wchar_t* filePath); 101 | Status EndLoggingResourceAllocations(); 102 | 103 | Status GetResourceAllocations(KickstartRT::ResourceAllocations* retAllocation); 104 | }; 105 | 106 | template 107 | struct ClassifiedDeviceObject : public T { 108 | protected: 109 | ResourceLogger* m_logger = {}; 110 | ResourceLogger::ResourceKind m_kind = (ResourceLogger::ResourceKind)-1; 111 | size_t m_loggedSizeInBytes = 0; 112 | 113 | public: 114 | ClassifiedDeviceObject(ResourceLogger *logger, ResourceLogger::ResourceKind kind, size_t loggedSizeInBytes) 115 | { 116 | m_logger = logger; 117 | m_kind = kind; 118 | m_loggedSizeInBytes = loggedSizeInBytes; 119 | 120 | if (m_kind < ResourceLogger::ResourceKind::e_Num_Kinds) { 121 | ++m_logger->m_allocationInfo.m_numResources[(size_t)m_kind]; 122 | m_logger->m_allocationInfo.m_totalRequestedBytes[(size_t)m_kind] += m_loggedSizeInBytes; 123 | } 124 | else { 125 | Log::Fatal(L"Failed to create classified device object. Invalid resource kind detected."); 126 | } 127 | }; 128 | 129 | virtual ~ClassifiedDeviceObject() 130 | { 131 | --m_logger->m_allocationInfo.m_numResources[(size_t)m_kind]; 132 | m_logger->m_allocationInfo.m_totalRequestedBytes[(size_t)m_kind] -= m_loggedSizeInBytes; 133 | }; 134 | }; 135 | }; 136 | 137 | -------------------------------------------------------------------------------- /src/TaskContainer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace KickstartRT_NativeLayer 29 | { 30 | static const char* GetRenderTaskName(RenderTask::Task::Type type) { 31 | switch (type) { 32 | case RenderTask::Task::Type::DirectLightInjection: return "DirectLightInjection"; 33 | case RenderTask::Task::Type::TraceSpecular: return "TraceSpecular"; 34 | case RenderTask::Task::Type::TraceDiffuse: return "TraceDiffuse"; 35 | case RenderTask::Task::Type::TraceAmbientOcclusion: return "TraceAmbientOcclusion"; 36 | case RenderTask::Task::Type::TraceShadow: return "TraceShadow"; 37 | case RenderTask::Task::Type::TraceMultiShadow: return "TraceMultiShadow"; 38 | case RenderTask::Task::Type::DenoiseSpecular: return "DenoiseSpecular"; 39 | case RenderTask::Task::Type::DenoiseDiffuse: return "DenoiseDiffuse"; 40 | case RenderTask::Task::Type::DenoiseSpecularAndDiffuse: return "DenoiseSpecularAndDiffuse"; 41 | case RenderTask::Task::Type::DenoiseDiffuseOcclusion: return "DenoiseDiffuseOcclusion"; 42 | case RenderTask::Task::Type::DenoiseShadow: return "DenoiseShadow"; 43 | case RenderTask::Task::Type::DenoiseMultiShadow: return "DenoiseMultiShadow"; 44 | default: 45 | return "Unknown"; 46 | } 47 | } 48 | 49 | TaskContainer::TaskContainer() 50 | { 51 | }; 52 | 53 | TaskContainer::~TaskContainer() 54 | { 55 | }; 56 | 57 | TaskContainer_impl::TaskContainer_impl() 58 | { 59 | m_bvhTask = std::make_unique(); 60 | m_renderTask = std::make_unique(); 61 | // m_sceneDenoising = std::make_unique(); 62 | }; 63 | 64 | TaskContainer_impl::~TaskContainer_impl() 65 | { 66 | std::scoped_lock mtx(m_mutex); 67 | 68 | m_bvhTask.reset(); 69 | m_renderTask.reset(); 70 | // m_sceneDenoising.reset(); 71 | }; 72 | 73 | Status TaskContainer_impl::ScheduleRenderTask(const RenderTask::Task* task) 74 | { 75 | std::scoped_lock mtx(m_mutex); 76 | 77 | return m_renderTask->ScheduleRenderTasks(&task, 1); 78 | } 79 | 80 | Status TaskContainer_impl::ScheduleRenderTasks(const RenderTask::Task* const *tasks, uint32_t nbTasks) 81 | { 82 | std::scoped_lock mtx(m_mutex); 83 | 84 | return m_renderTask->ScheduleRenderTasks(tasks, nbTasks); 85 | } 86 | 87 | Status TaskContainer_impl::ScheduleBVHTask(const BVHTask::Task* task) 88 | { 89 | return ScheduleBVHTasks(&task, 1); 90 | } 91 | 92 | Status TaskContainer_impl::ScheduleBVHTasks(const BVHTask::Task* const* tasks, uint32_t nbTasks) 93 | { 94 | std::scoped_lock mtx(m_mutex); 95 | 96 | Status sts = Status::OK; 97 | 98 | for (size_t i = 0; i < nbTasks; ++i) { 99 | const auto* t(tasks[i]); 100 | 101 | if (t->type == BVHTask::Task::Type::Geometry) { 102 | const BVHTask::GeometryTask* gt = static_cast(t); 103 | switch (gt->taskOperation) { 104 | case BVHTask::TaskOperation::Register: 105 | { 106 | sts = m_bvhTask->RegisterGeometry(gt->handle, >->input); 107 | } 108 | break; 109 | case BVHTask::TaskOperation::Update: 110 | { 111 | sts = m_bvhTask->UpdateGeometry(gt->handle, >->input); 112 | } 113 | break; 114 | default: 115 | Log::Fatal(L"Unknown task kingd detected."); 116 | sts = Status::ERROR_INVALID_GEOMETRY_INPUTS; 117 | } 118 | } 119 | else if (t->type == BVHTask::Task::Type::Instance) { 120 | const BVHTask::InstanceTask* it = static_cast(t); 121 | switch (it->taskOperation) { 122 | case BVHTask::TaskOperation::Register: 123 | { 124 | sts = m_bvhTask->RegisterInstance(it->handle, &it->input); 125 | } 126 | break; 127 | case BVHTask::TaskOperation::Update: 128 | { 129 | sts = m_bvhTask->UpdateInstance(it->handle, &it->input); 130 | } 131 | break; 132 | default: 133 | Log::Fatal(L"Unknown task kingd detected."); 134 | sts = Status::ERROR_INVALID_GEOMETRY_INPUTS; 135 | } 136 | } 137 | else if (t->type == BVHTask::Task::Type::BVHBuild) { 138 | const BVHTask::BVHBuildTask* bt = static_cast(t); 139 | sts = m_bvhTask->SetBVHBuildTask(bt); 140 | } 141 | else { 142 | Log::Fatal(L"Unknown task type detected."); 143 | sts = Status::ERROR_INVALID_PARAM; 144 | } 145 | if (sts != Status::OK) 146 | break; 147 | } 148 | if (sts != Status::OK) { 149 | Log::Fatal(L"Failed to ScheduleBVHTask."); 150 | } 151 | 152 | return sts; 153 | } 154 | }; -------------------------------------------------------------------------------- /src/Geometry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace KickstartRT_NativeLayer 37 | { 38 | class PersistentWorkingSet; 39 | 40 | static constexpr uint32_t kInvalidNumTiles = 0xFFFF'FFFF; 41 | 42 | namespace BVHTask { 43 | enum class RegisterStatus { 44 | NotRegistered, 45 | Registering, 46 | Registered 47 | }; 48 | 49 | struct Instance; 50 | 51 | struct Geometry { 52 | const uint64_t m_id; 53 | BVHTask::GeometryInput m_input = {}; 54 | uint32_t m_totalNbIndices = 0; 55 | uint32_t m_totalNbVertices = 0; 56 | std::vector m_vertexOffsets; 57 | std::vector m_indexOffsets; 58 | 59 | RegisterStatus m_registerStatus = RegisterStatus::NotRegistered; 60 | 61 | std::unique_ptr m_edgeTableBuffer; 62 | 63 | std::unique_ptr m_index_vertexBuffer; 64 | 65 | //size_t m_nbVertexIndices = 0; 66 | //size_t m_nbVertices = 0; 67 | size_t m_vertexBufferOffsetInBytes = (size_t)-1; 68 | 69 | std::unique_ptr m_directLightingCacheCounter; 70 | std::unique_ptr m_directLightingCacheCounter_Readback; 71 | 72 | uint32_t m_numberOfTiles = kInvalidNumTiles; 73 | 74 | std::unique_ptr m_directLightingCacheIndices; // store tileOffset and nbTiles of U and V direction for each triangle primitive. No packed format for now. 75 | 76 | std::unique_ptr m_BLASScratchBuffer; 77 | std::unique_ptr m_BLASBuffer; 78 | 79 | #if defined(GRAPHICS_API_D3D12) 80 | std::unique_ptr m_BLASCompactionSizeBuffer; 81 | std::unique_ptr m_BLASCompactionSizeBuffer_Readback; 82 | 83 | #elif defined(GRAPHICS_API_VK) 84 | std::unique_ptr m_BLASCompactionSizeQueryPool; 85 | #endif 86 | 87 | bool m_directTileMapping = false; 88 | std::wstring m_name; 89 | std::list m_instances; // weak reference of instances. 90 | 91 | static Geometry* ToPtr(GeometryHandle handle) 92 | { 93 | return ToPtr_s(handle); 94 | } 95 | 96 | GeometryHandle ToHandle() 97 | { 98 | return ToHandle_s(this); 99 | }; 100 | 101 | public: 102 | Geometry(uint64_t id) : m_id(id) {}; 103 | ~Geometry(); 104 | void DeferredRelease(PersistentWorkingSet* pws); 105 | 106 | // Returns the vertex count after transforming process in the SDK. 107 | inline uint32_t GetVertexCountAfterTransform() 108 | { 109 | uint32_t cnt = 0; 110 | 111 | for (auto&& cmp : m_input.components) { 112 | if (cmp.indexRange.isEnabled) 113 | cnt += cmp.indexRange.maxIndex - cmp.indexRange.minIndex + 1; 114 | else 115 | cnt += cmp.vertexBuffer.count; 116 | } 117 | 118 | return cnt; 119 | } 120 | }; 121 | 122 | struct Instance { 123 | const uint64_t m_id; 124 | RegisterStatus m_registerStatus = RegisterStatus::NotRegistered; 125 | 126 | Geometry* m_geometry = nullptr; 127 | BVHTask::InstanceInput m_input = {}; 128 | std::wstring m_name; 129 | uint32_t m_numberOfTiles = kInvalidNumTiles; 130 | 131 | // MeshColors: [vertex colors][edge/face colors] 132 | // TileCache: tile samples per face. 133 | std::unique_ptr m_dynamicTileBuffer; 134 | bool m_tileIsCleared = false; 135 | 136 | #if KICKSTARTRT_ENABLE_DIRECT_LIGHTING_CACHE_INDIRECTION_TABLE 137 | #else 138 | std::unique_ptr m_cpuDescTableAllocation; 139 | bool m_needToUpdateUAV = false; 140 | #endif 141 | 142 | std::optional::iterator> m_TLASInstanceListItr; 143 | 144 | static Instance* ToPtr(InstanceHandle handle) 145 | { 146 | return ToPtr_s(handle); 147 | } 148 | InstanceHandle ToHandle() 149 | { 150 | return ToHandle_s(this); 151 | }; 152 | 153 | public: 154 | Instance(uint64_t id) : m_id(id) {}; 155 | ~Instance(); 156 | void DeferredRelease(PersistentWorkingSet* pws); 157 | }; 158 | }; 159 | }; 160 | 161 | -------------------------------------------------------------------------------- /src/RenderPass_DirectLightingCacheInjection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace KickstartRT_NativeLayer 32 | { 33 | class PersistentWorkingSet; 34 | class TaskWorkingSet; 35 | struct RenderPass_ResourceRegistry; 36 | }; 37 | 38 | namespace KickstartRT_NativeLayer 39 | { 40 | struct RenderPass_DirectLightingCacheInjection 41 | { 42 | static constexpr uint32_t m_threadDim_XY[2] = { 8, 16 }; 43 | 44 | static inline std::atomic s_seed = 0; // Used to generate unique injection offset. 45 | 46 | enum DescTableLayout : uint32_t { 47 | e_CB_CBV = 0, 48 | e_DepthTex_SRV, 49 | e_LightingTex_SRV, 50 | e_DescTableSize, 51 | }; 52 | 53 | struct CB { 54 | uint32_t m_Viewport_TopLeftX; 55 | uint32_t m_Viewport_TopLeftY; 56 | uint32_t m_Viewport_Width; 57 | uint32_t m_Viewport_Height; 58 | 59 | float m_Viewport_MinDepth; 60 | float m_Viewport_MaxDepth; 61 | uint32_t m_CTA_Swizzle_GroupDimension_X; 62 | uint32_t m_CTA_Swizzle_GroupDimension_Y; 63 | 64 | float m_rayOrigin[3]; 65 | uint32_t m_depthType; 66 | 67 | float m_averageWindow; 68 | uint32_t m_pad0; 69 | float m_subPixelJitterOffsetX; 70 | float m_subPixelJitterOffsetY; 71 | 72 | uint32_t m_strideX; 73 | uint32_t m_strideY; 74 | uint32_t m_strideOffsetX; 75 | uint32_t m_strideOffsetY; 76 | 77 | Math::Float_4x4 m_clipToViewMatrix; 78 | Math::Float_4x4 m_viewToWorldMatrix; 79 | }; 80 | 81 | struct CB_Transfer { 82 | uint32_t m_triangleCount; 83 | uint32_t m_targetInstanceIndex; 84 | uint32_t m_dstVertexBufferOffsetIdx; // Dest indices and vertices buffers are now unified. It needs the offset. 85 | uint32_t m_pad; 86 | 87 | Math::Float_4x4 m_targetInstanceTransform; 88 | }; 89 | 90 | struct CB_clear { 91 | uint32_t m_instanceIndex; 92 | uint32_t m_numberOfTiles; 93 | uint32_t m_resourceIndex; 94 | uint32_t m_pad_u1; 95 | float m_clearColor[3]; 96 | float m_pad_f0; 97 | }; 98 | 99 | bool m_enableInlineRaytracing = false; 100 | bool m_enableShaderTableRaytracing = false; 101 | 102 | GraphicsAPI::DescriptorTableLayout m_descTableLayout1; 103 | GraphicsAPI::DescriptorTableLayout m_descTableLayout2; 104 | 105 | GraphicsAPI::RootSignature m_rootSignature; 106 | 107 | 108 | GraphicsAPI::DescriptorTableLayout m_descTableLayoutTransfer1; 109 | GraphicsAPI::DescriptorTableLayout m_descTableLayoutTransfer2; 110 | 111 | GraphicsAPI::RootSignature m_rootSignatureTransfer; 112 | 113 | ShaderFactory::ShaderDictEntry* m_shaderTable = nullptr; 114 | ShaderFactory::ShaderDictEntry* m_pso = nullptr; 115 | ShaderFactory::ShaderDictEntry* m_pso_clear = nullptr; 116 | ShaderFactory::ShaderDictEntry* m_shaderTableTransfer = nullptr; 117 | ShaderFactory::ShaderDictEntry* m_psoTransfer = nullptr; 118 | public: 119 | struct TransferParams 120 | { 121 | uint32_t targetInstanceIndex; 122 | uint32_t sourceInstanceIndex; 123 | }; 124 | private: 125 | 126 | Status DispatchInject(TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, RenderPass_ResourceRegistry* resources, const RenderTask::DirectLightingInjectionTask* input); 127 | Status DispatchTransfer(TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, RenderPass_ResourceRegistry* resources, const RenderTask::DirectLightTransferTask* input, const TransferParams& params); 128 | 129 | public: 130 | Status Init(PersistentWorkingSet *pws, bool enableInlineRaytracing, bool enableShaderTableRaytracing); 131 | 132 | Status BuildCommandListInject(TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, 133 | RenderPass_ResourceRegistry* resources, 134 | GraphicsAPI::DescriptorTable *lightingCache_descTable, const RenderTask::DirectLightingInjectionTask* directLightingInjection); 135 | 136 | Status BuildCommandListTransfer(TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, 137 | RenderPass_ResourceRegistry* resources, 138 | GraphicsAPI::DescriptorTable* lightingCache_descTable, const RenderTask::DirectLightTransferTask* directLightingTransfer, const TransferParams& params); 139 | 140 | Status DispatchClear(TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, const CB_clear& clCB); 141 | Status BuildCommandListClear(TaskWorkingSet* fws, GraphicsAPI::CommandList* cmdList, 142 | GraphicsAPI::DescriptorTable* lightingCache_descTable, const std::deque& clearList); 143 | }; 144 | }; 145 | -------------------------------------------------------------------------------- /tools/ShaderCompiler/Options.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 | License for cxxopts 24 | 25 | Copyright (c) 2014 Jarryd Beck 26 | 27 | Permission is hereby granted, free of charge, to any person obtaining a copy 28 | of this software and associated documentation files (the "Software"), to deal 29 | in the Software without restriction, including without limitation the rights 30 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 31 | copies of the Software, and to permit persons to whom the Software is 32 | furnished to do so, subject to the following conditions: 33 | 34 | The above copyright notice and this permission notice shall be included in 35 | all copies or substantial portions of the Software. 36 | 37 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 38 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 39 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 40 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 41 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 42 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 43 | THE SOFTWARE. 44 | */ 45 | #include 46 | #include 47 | 48 | #include "Options.h" 49 | 50 | using namespace std; 51 | using namespace cxxopts; 52 | 53 | bool CommandLineOptions::parse(int argc, char** argv) 54 | { 55 | Options options("shaderCompiler", "Batch shader compiler for KickStartRTX"); 56 | 57 | string platformName; 58 | 59 | options.add_options() 60 | ("i,infile", "File with the list of shaders to compiler", value(inputFile)) 61 | ("o,out", "Output directory", value(outputPath)) 62 | ("p,parallel", "Compile shaders in multiple CPU threads", value(parallel)) 63 | ("v,verbose", "Print commands before executing them", value(verbose)) 64 | ("f,force", "Treat all source files as modified", value(force)) 65 | ("k,keep", "Keep intermediate files", value(keep)) 66 | ("r,res", "Write Resource file", value(resourceFilePath)) 67 | ("c,compiler", "Path to the compiler executable (FXC or DXC)", value(compilerPath)) 68 | ("I,include", "Include paths", value(includePaths)) 69 | ("D,definition", "Definitions", value(definitions)) 70 | ("cflags", "Additional compiler command line options", value(additionalCompilerOptions)) 71 | ("P,platform", "Target shader bytecode type, one of: DXBC, DXIL, SPIRV", value(platformName)) 72 | ("h,help", "Print the help message", value(help)); 73 | 74 | try 75 | { 76 | options.parse(argc, argv); 77 | 78 | if (help) 79 | { 80 | errorMessage = options.help(); 81 | return false; 82 | } 83 | 84 | if (compilerPath.empty()) 85 | throw OptionException("Compiler path not specified"); 86 | 87 | if(!filesystem::exists(compilerPath)) 88 | throw OptionException("Specified compiler executable (" + compilerPath + ") does not exist"); 89 | 90 | if (inputFile.empty()) 91 | throw OptionException("Input file not specified"); 92 | 93 | if (!filesystem::exists(inputFile)) 94 | throw OptionException("Specified input file (" + inputFile + ") does not exist"); 95 | 96 | if (outputPath.empty()) 97 | throw OptionException("Output path not specified"); 98 | 99 | if(platformName.empty()) 100 | throw OptionException("Platform not specified"); 101 | 102 | for (char& c : platformName) 103 | c = toupper(c); 104 | if (platformName == "DXIL") 105 | platform = Platform::DXIL; 106 | else if (platformName == "SPIRV" || platformName == "SPIR-V") 107 | platform = Platform::SPIRV; 108 | else 109 | throw OptionException("Unrecognized platform: " + platformName); 110 | 111 | return true; 112 | } 113 | catch (const OptionException& e) 114 | { 115 | errorMessage = e.what(); 116 | return false; 117 | } 118 | } 119 | 120 | bool CompilerOptions::parse(std::string line) 121 | { 122 | std::vector tokens; 123 | 124 | const char* delimiters = " \t"; 125 | char* name = strtok(const_cast(line.c_str()), delimiters); 126 | tokens.push_back(name); // argv[0] 127 | 128 | shaderName = name; 129 | 130 | while (char* token = strtok(NULL, delimiters)) 131 | tokens.push_back(token); 132 | 133 | Options options("shaderCompilerConfig", "Configuration options for a shader"); 134 | 135 | options.add_options() 136 | ("E", "Entry point", value(entryPoint)) 137 | ("T", "Shader target", value(target)) 138 | ("D", "Definitions", value(definitions)); 139 | 140 | try 141 | { 142 | int argc = (int)tokens.size(); 143 | char** argv = tokens.data(); 144 | options.parse(argc, argv); 145 | 146 | if (target.empty()) 147 | throw OptionException("Shader target not specified"); 148 | 149 | } 150 | catch (const OptionException& e) 151 | { 152 | errorMessage = e.what(); 153 | return false; 154 | } 155 | 156 | return true; 157 | } 158 | -------------------------------------------------------------------------------- /include/KickstartRT_native_layer_d3d12.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #pragma once 23 | 24 | #if !defined(WIN32_LEAN_AND_MEAN) 25 | #define WIN32_LEAN_AND_MEAN 26 | #endif 27 | #if !defined(NOMINMAX) 28 | #define NOMINMAX 29 | #endif 30 | #include 31 | #include 32 | 33 | #include "KickstartRT_common.h" 34 | 35 | #if defined (KickstartRT_Graphics_API_D3D12) 36 | 37 | #include 38 | 39 | namespace KickstartRT { 40 | namespace D3D12 { 41 | struct BuildGPUTaskInput { 42 | // If true, update BLAS and TLAS before doing any rendering task. 43 | bool geometryTaskFirst = true; 44 | 45 | // Users always need to provide a opened commandlist and SDK doesn't close the commandlist. Users cannot touch the command list unti it recieves a GPUTaskHandle from the SDK. 46 | ID3D12CommandList* commandList = nullptr; 47 | }; 48 | 49 | // ============================================================== 50 | // RenderTask 51 | // ============================================================== 52 | // These data structures are for lighting inputs and reflection output. 53 | // ============================================================== 54 | namespace RenderTask { 55 | struct ShaderResourceTex { 56 | // SDK doesn't change the resource state in it and SDK always expects that ShaderResourceTex is readable from compute shaders and raytracing shaders during SDK commandlist's execution. 57 | // So, its state should be either D3D12_RESOURCE_STATE_COMMON or NON_PIXEL_SHADER_RESOURCE. 58 | D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; 59 | ID3D12Resource* resource = nullptr; 60 | }; 61 | 62 | struct UnorderedAccessTex { 63 | // SDK doesn't change the resource state in it and SDK always expects that UnorderedAccessTex is writable from compute shaders and raytracing shaders during SDK commandlist's execution. 64 | // So, its state should be D3D12_RESOURCE_STATE_UNORDERED_ACCESS. 65 | D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {}; 66 | ID3D12Resource* resource = nullptr; 67 | }; 68 | 69 | struct CombinedAccessTex { 70 | // SDK doesn't change the resource state in it and SDK always expects that CombinedAccessTex is readable from compute shaders and raytracing shaders during SDK commandlist's execution. 71 | // So, its state should be either D3D12_RESOURCE_STATE_COMMON or NON_PIXEL_SHADER_RESOURCE. 72 | // The SDK may alter the resource state during execution, but will return it in the same state it arrived. 73 | D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; 74 | D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {}; 75 | ID3D12Resource* resource = nullptr; 76 | }; 77 | }; 78 | 79 | // ============================================================== 80 | // BVHTask 81 | // ============================================================== 82 | // These data structures are for geometry inputs to construct BVHs. 83 | // ============================================================== 84 | namespace BVHTask { 85 | struct VertexBufferInput { 86 | // SDK doesn't change the resource state in it and SDK always expects that s_VertexBuffer is readable from compute shaders and raytracing shaders during SDK commandlist's execution. 87 | // So, its state should be any one of D3D12_RESOURCE_STATE_COMMON, NON_PIXEL_SHADER_RESOURCE or GENERIC_READ. 88 | ID3D12Resource* resource = nullptr; 89 | DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; 90 | UINT64 offsetInBytes = 0ull; 91 | UINT strideInBytes = 0u; 92 | UINT count = 0u; 93 | }; 94 | struct IndexBufferInput { 95 | // SDK doesn't change the resource state in it and SDK always expects that s_IndexBuffer is readable from compute shaders and raytracing shaders during SDK commandlist's execution. 96 | // So, its state should be any one of D3D12_RESOURCE_STATE_COMMON, NON_PIXEL_SHADER_RESOURCE or GENERIC_READ. 97 | ID3D12Resource* resource = nullptr; 98 | DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; 99 | UINT64 offsetInBytes = 0ull; 100 | UINT count = 0u; 101 | }; 102 | }; 103 | 104 | struct ExecuteContext_InitSettings { 105 | ID3D12Device* D3D12Device = nullptr; 106 | 107 | bool useInlineRaytracing = true; 108 | bool useShaderTableRaytracing = true; 109 | 110 | uint32_t supportedWorkingsets = 2u; 111 | uint32_t descHeapSize = 8192u; 112 | uint32_t uploadHeapSizeForVolatileConstantBuffers = 64u * 1024u; 113 | 114 | uint32_t* coldLoadShaderList = nullptr; 115 | uint32_t coldLoadShaderListSize = 0u; 116 | }; 117 | 118 | #define KickstartRT_DECLSPEC_INL KickstartRT_DECLSPEC 119 | #define KickstartRT_ExecutionContext_Native 120 | #include "KickStartRT_inl.h" 121 | #undef KickstartRT_ExecutionContext_Native 122 | #undef KickstartRT_DECLSPEC_INL 123 | }; 124 | }; 125 | 126 | #endif -------------------------------------------------------------------------------- /src/Utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * 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 THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | #include 23 | #include 24 | 25 | namespace KickstartRT_NativeLayer { 26 | 27 | namespace Utils { 28 | void LogGeometryInput(const BVHTask::GeometryInput *input) 29 | { 30 | Log::Info(L"Name: %s", input->name ? input->name : L"Null"); 31 | 32 | for (auto&& cmp : input->components) { 33 | Log::Info(L"VertexBuffer: Offset: %d, Stride : %d, Count: %d", 34 | cmp.vertexBuffer.offsetInBytes, cmp.vertexBuffer.strideInBytes, cmp.vertexBuffer.count); 35 | Log::Info(L"IndexBuffer: Offset: %d, Count: %d", 36 | cmp.indexBuffer.offsetInBytes, cmp.indexBuffer.count); 37 | Log::Info(L"IndexRange: Enabled: %s, Min: %d, Max: %d", 38 | cmp.indexRange.isEnabled ? L"True" : L"False", 39 | cmp.indexRange.minIndex, cmp.indexRange.maxIndex); 40 | } 41 | }; 42 | 43 | bool CheckInputTextureState(GraphicsAPI::CommandList* cmdList, const RenderTask::ShaderResourceTex* inputTex, GraphicsAPI::ResourceState::State expectedState) 44 | { 45 | #if defined(GRAPHICS_API_D3D12) 46 | auto SRVToSubResRange = [](const D3D12_SHADER_RESOURCE_VIEW_DESC& srvDesc) -> GraphicsAPI::SubresourceRange { 47 | switch (srvDesc.ViewDimension) { 48 | case D3D12_SRV_DIMENSION_TEXTURE2D: 49 | { 50 | const auto& desc(srvDesc.Texture2D); 51 | return GraphicsAPI::SubresourceRange(0, 1, (uint8_t)desc.MostDetailedMip, (uint8_t)desc.MipLevels); 52 | } 53 | case D3D12_SRV_DIMENSION_TEXTURE2DARRAY: 54 | { 55 | const auto& desc(srvDesc.Texture2DArray); 56 | return GraphicsAPI::SubresourceRange((uint8_t)desc.FirstArraySlice, (uint8_t)desc.ArraySize, (uint8_t)desc.MostDetailedMip, (uint8_t)desc.MipLevels); 57 | } 58 | default: 59 | return GraphicsAPI::SubresourceRange(0, 1, 0, 1); 60 | } 61 | }; 62 | 63 | GraphicsAPI::Texture t; 64 | { 65 | GraphicsAPI::Texture::ApiData initData; 66 | initData.m_resource = inputTex->resource; 67 | t.InitFromApiData(initData, GraphicsAPI::ResourceState::State::Common); // dummy state. 68 | } 69 | 70 | GraphicsAPI::SubresourceRange subResRange = SRVToSubResRange(inputTex->srvDesc); 71 | GraphicsAPI::Resource* tArr[1] = { &t }; 72 | return cmdList->AssertResourceStates(tArr, &subResRange, 1, &expectedState); 73 | #else 74 | // VK doesn't have resource state. 75 | (void)cmdList; (void)inputTex; (void)expectedState; 76 | return true; 77 | #endif 78 | }; 79 | 80 | bool CheckInputTextureState(GraphicsAPI::CommandList* cmdList, const RenderTask::UnorderedAccessTex* inputTex, GraphicsAPI::ResourceState::State expectedState) 81 | { 82 | #if defined(GRAPHICS_API_D3D12) 83 | auto UAVToSubResRange = [](const D3D12_UNORDERED_ACCESS_VIEW_DESC& uavDesc) -> GraphicsAPI::SubresourceRange { 84 | switch (uavDesc.ViewDimension) { 85 | case D3D12_UAV_DIMENSION_TEXTURE2D: 86 | { 87 | // Depth stencil plance slice is not supported. 88 | const auto& desc(uavDesc.Texture2D); 89 | return GraphicsAPI::SubresourceRange(0, 1, (uint8_t)desc.MipSlice, 1); 90 | } 91 | case D3D12_SRV_DIMENSION_TEXTURE2DARRAY: 92 | { 93 | const auto& desc(uavDesc.Texture2DArray); 94 | return GraphicsAPI::SubresourceRange((uint8_t)desc.FirstArraySlice, (uint8_t)desc.ArraySize, (uint8_t)desc.MipSlice, 1); 95 | } 96 | default: 97 | return GraphicsAPI::SubresourceRange(0, 1, 0, 1); 98 | } 99 | }; 100 | 101 | GraphicsAPI::Texture t; 102 | { 103 | GraphicsAPI::Texture::ApiData initData; 104 | initData.m_resource = inputTex->resource; 105 | t.InitFromApiData(initData, GraphicsAPI::ResourceState::State::Common); // dummy state. 106 | } 107 | 108 | GraphicsAPI::SubresourceRange subResRange = UAVToSubResRange(inputTex->uavDesc); 109 | GraphicsAPI::Resource* tArr[1] = { &t }; 110 | return cmdList->AssertResourceStates(tArr, &subResRange, 1, &expectedState); 111 | #else 112 | // VK doesn't have resource state. 113 | (void)cmdList; (void)inputTex; (void)expectedState; 114 | return true; 115 | #endif 116 | }; 117 | 118 | }; 119 | }; 120 | --------------------------------------------------------------------------------