diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dd04311..481b2a9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -39,6 +39,7 @@ package_sample:
- build_dx12
- build_vk
script:
+ - xcopy .\ffx-dnsr\docs\*.pdf .\docs /sy
- echo "Packaging build"
- echo cd .\sample\bin\ > %SampleName%_DX12.bat
- echo start %SampleName%_DX12.exe >> %SampleName%_DX12.bat
diff --git a/.gitmodules b/.gitmodules
index 0c66215..5547136 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
[submodule "sample/libs/cauldron"]
path = sample/libs/cauldron
url = ../../GPUOpen-LibrariesAndSDKs/Cauldron.git
+[submodule "ffx-dnsr"]
+ path = ffx-dnsr
+ url = ../../GPUOpen-Effects/FidelityFX-Denoiser.git
diff --git a/docs/FFX_SSSR_GUI.pdf b/docs/FFX_SSSR_GUI.pdf
index fbc0435..5f67404 100644
Binary files a/docs/FFX_SSSR_GUI.pdf and b/docs/FFX_SSSR_GUI.pdf differ
diff --git a/docs/FFX_SSSR_Technology.pdf b/docs/FFX_SSSR_Technology.pdf
index aed2649..cf53fc9 100644
Binary files a/docs/FFX_SSSR_Technology.pdf and b/docs/FFX_SSSR_Technology.pdf differ
diff --git a/ffx-dnsr b/ffx-dnsr
new file mode 160000
index 0000000..670c76e
--- /dev/null
+++ b/ffx-dnsr
@@ -0,0 +1 @@
+Subproject commit 670c76e340b80b17dd9018f320d328821825cf80
diff --git a/sample/src/DX12/Shaders/ffx_a.h b/ffx-spd/ffx_a.h
similarity index 100%
rename from sample/src/DX12/Shaders/ffx_a.h
rename to ffx-spd/ffx_a.h
diff --git a/sample/src/DX12/Shaders/ffx_spd.h b/ffx-spd/ffx_spd.h
similarity index 100%
rename from sample/src/DX12/Shaders/ffx_spd.h
rename to ffx-spd/ffx_spd.h
diff --git a/ffx-sssr/.gitignore b/ffx-sssr/.gitignore
deleted file mode 100644
index 62f5258..0000000
--- a/ffx-sssr/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-shaders/*.h
diff --git a/ffx-sssr/CMakeLists.txt b/ffx-sssr/CMakeLists.txt
deleted file mode 100644
index 93d9090..0000000
--- a/ffx-sssr/CMakeLists.txt
+++ /dev/null
@@ -1,134 +0,0 @@
-cmake_minimum_required(VERSION 3.10.0)
-
-project(stochastic-screen-space-reflections)
-
-find_package(PythonInterp 3.6 REQUIRED)
-
-# ensure that only one option is enabled
-if(FFX_SSSR_VK AND FFX_SSSR_D3D12)
- message(FATAL_ERROR "FFX_SSSR_VK and FFX_SSSR_D3D12 are enabled. Please make sure to enable only one at a time.")
-endif()
-
-if(FFX_SSSR_VK)
- find_package(Vulkan REQUIRED)
-endif()
-
-set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-
-if (MSVC)
- add_compile_options(/W3 /WX)
-else()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Werror -std=c++17")
-endif()
-
-file(GLOB FFX_SSSR_HEADER_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/inc/ffx_sssr.h
- ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h)
-file(GLOB FFX_SSSR_INLINE_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/src/*.inl)
-file(GLOB FFX_SSSR_SOURCE_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
-file(GLOB FFX_SSSR_SHADER_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.hlsl)
-
-if(FFX_SSSR_D3D12)
- file(GLOB FFX_SSSR_HEADER_FILES_D3D12
- ${CMAKE_CURRENT_SOURCE_DIR}/inc/ffx_sssr_d3d12.h
- ${CMAKE_CURRENT_SOURCE_DIR}/src/d3d12/*.h)
- file(GLOB FFX_SSSR_INLINE_FILES_D3D12
- ${CMAKE_CURRENT_SOURCE_DIR}/src/d3d12/*.inl)
- file(GLOB FFX_SSSR_SOURCE_FILES_D3D12
- ${CMAKE_CURRENT_SOURCE_DIR}/src/d3d12/*.cpp)
-endif()
-
-if(FFX_SSSR_VK)
- file(GLOB FFX_SSSR_HEADER_FILES_VK
- ${CMAKE_CURRENT_SOURCE_DIR}/inc/ffx_sssr_vk.h
- ${CMAKE_CURRENT_SOURCE_DIR}/src/vk/*.h)
- file(GLOB FFX_SSSR_INLINE_FILES_VK
- ${CMAKE_CURRENT_SOURCE_DIR}/src/vk/*.inl)
- file(GLOB FFX_SSSR_SOURCE_FILES_VK
- ${CMAKE_CURRENT_SOURCE_DIR}/src/vk/*.cpp)
-endif()
-
-set(FFX_SSSR_HEADER_FILES_SHADERS)
-
-foreach(shaderfile classify_tiles
- common
- intersect
- prepare_indirect_args
- resolve_eaw
- resolve_spatial
- resolve_temporal)
-
- add_custom_command(
- OUTPUT
- ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader_${shaderfile}.h
- DEPENDS
- ${CMAKE_CURRENT_SOURCE_DIR}/shaders/${shaderfile}.hlsl
- COMMAND
- ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/sourceToHeader.py ${CMAKE_CURRENT_SOURCE_DIR}/shaders/${shaderfile}.hlsl ${shaderfile} > ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader_${shaderfile}.h
- COMMENT
- "Generate shader header shader_${shaderfile}.h for ${shaderfile}.hlsl"
- USES_TERMINAL)
-
- list(APPEND FFX_SSSR_HEADER_FILES_SHADERS "${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader_${shaderfile}.h")
-
-endforeach()
-
-add_library(FFX_SSSR
- ${FFX_SSSR_SOURCE_FILES}
- ${FFX_SSSR_SOURCE_FILES_D3D12}
- ${FFX_SSSR_SOURCE_FILES_VK}
- ${FFX_SSSR_HEADER_FILES_SHADERS})
-
-target_include_directories(FFX_SSSR PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc)
-target_include_directories(FFX_SSSR PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
-target_include_directories(FFX_SSSR PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/shaders)
-
-target_include_directories(FFX_SSSR PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/externals)
-target_include_directories(FFX_SSSR PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/externals/dxc)
-target_include_directories(FFX_SSSR PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/externals/samplerCPP)
-
-if(FFX_SSSR_D3D12)
- target_compile_definitions(FFX_SSSR PRIVATE FFX_SSSR_D3D12)
-endif()
-
-if(FFX_SSSR_VK)
- target_compile_definitions(FFX_SSSR PRIVATE FFX_SSSR_VK)
-endif()
-
-target_sources(FFX_SSSR PRIVATE
- ${FFX_SSSR_HEADER_FILES}
- ${FFX_SSSR_INLINE_FILES}
- ${FFX_SSSR_SHADER_FILES}
- ${FFX_SSSR_HEADER_FILES_D3D12}
- ${FFX_SSSR_INLINE_FILES_D3D12}
- ${FFX_SSSR_HEADER_FILES_VK}
- ${FFX_SSSR_INLINE_FILES_VK})
-
-source_group("Header Files\\Shaders" FILES ${FFX_SSSR_HEADER_FILES_SHADERS})
-
-source_group("Inline Files" FILES ${FFX_SSSR_INLINE_FILES})
-source_group("Media Files\\Shaders" FILES ${FFX_SSSR_SHADER_FILES})
-
-
-source_group("Header Files\\D3D12" FILES ${FFX_SSSR_HEADER_FILES_D3D12})
-source_group("Inline Files\\D3D12" FILES ${FFX_SSSR_INLINE_FILES_D3D12})
-source_group("Source Files\\D3D12" FILES ${FFX_SSSR_SOURCE_FILES_D3D12})
-
-source_group("Header Files\\VK" FILES ${FFX_SSSR_HEADER_FILES_VK})
-source_group("Inline Files\\VK" FILES ${FFX_SSSR_INLINE_FILES_VK})
-source_group("Source Files\\VK" FILES ${FFX_SSSR_SOURCE_FILES_VK})
-
-if(MSVC)
- set_source_files_properties(${FFX_SSSR_SHADER_FILES}
- PROPERTIES
- VS_TOOL_OVERRIDE
- "None")
-endif()
-
-
-if(FFX_SSSR_VK)
- target_link_libraries (FFX_SSSR Vulkan::Vulkan)
-endif()
diff --git a/ffx-sssr/README.md b/ffx-sssr/README.md
deleted file mode 100644
index 3e9bf7e..0000000
--- a/ffx-sssr/README.md
+++ /dev/null
@@ -1,278 +0,0 @@
-# FidelityFX SSSR
-
-The **FidelityFX SSSR** library provides the means to render stochastic screen space reflections for the use in real-time applications.
-A full sample running the library can be found on the [FidelityFX SSSR GitHub page](https://github.com/GPUOpen-Effects/FidelityFX-SSSR.git).
-
-The library supports D3D12 and Vulkan.
-
-## Prerequisits
-
-The library relies on [dxcompiler.dll](https://github.com/microsoft/DirectXShaderCompiler) to generate DXIL/SPIRV from HLSL at runtime.
-Use the version built for SPIRV from the [DirectXShaderCompiler GitHub repository](https://github.com/microsoft/DirectXShaderCompiler) or the one that comes with the [Vulkan SDK 1.2.141.2 (or later)](https://www.lunarg.com/vulkan-sdk/) if you are planning to use the Vulkan version of **FidelityFX SSSR**.
-
-## Device Creation
-
-Vulkan version only: The library relies on [VK_EXT_subgroup_size_control](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_EXT_subgroup_size_control.html) for optimal performance on RDNA. Make sure the extension is enabled at device creation by adding `VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME` to `ppEnabledExtensionNames` if it is available.
-Also enable `subgroupSizeControl` in `VkPhysicalDeviceSubgroupSizeControlFeaturesEXT` and chain it into the `pNext` chain of `VkDeviceCreateInfo` if the extension name is available. It is fine to run **FidelityFX SSSR** if the extension is not supported.
-
-## Context - Initialization and Shutdown
-
-First the header files must be included. This is `ffx_sssr.h` for Graphics API independent definitions and `ffx_sssr_d3d12.h` for D3D12 specific definitions:
-
-```C++
-#include "ffx_sssr.h"
-#include "ffx_sssr_d3d12.h"
-```
-
-or `ffx_sssr_vk.h` for Vulkan specific definitions:
-
-```C++
-#include "ffx_sssr.h"
-#include "ffx_sssr_vk.h"
-```
-
-Then a context must be created. This usually is done only once per device. Depending on the preferred API, populate either `FfxSssrD3D12CreateContextInfo` or `FfxSssrVkCreateContextInfo`.
-
-```C++
-FfxSssrD3D12CreateContextInfo d3d12ContextInfo = {};
-d3d12ContextInfo.pDevice = myDevice;
-d3d12ContextInfo.pUploadCommandList = myCommandList;
-
-FfxSssrVkCreateContextInfo vkContextInfo = {};
-vkContextInfo.device = myDeviceHandle;
-vkContextInfo.physicalDevice = myPhysicalDeviceHandle;
-vkContextInfo.uploadCommandBuffer = myUploadCommandBufferHandle;
-
-FfxSssrLoggingCallbacks loggingCallbacks = {};
-loggingCallbacks.pUserData = myUserData;
-loggingCallbacks.pfnLogging = myLoggingFunction;
-
-FfxSssrCreateContextInfo contextInfo = {};
-contextInfo.apiVersion = FFX_SSSR_API_VERSION;
-contextInfo.maxReflectionViewCount = myMaxViewCount;
-contextInfo.frameCountBeforeMemoryReuse = myMaxFrameCountInFlight;
-contextInfo.uploadBufferSize = 8 * 1024 * 1024;
-contextInfo.pLoggingCallbacks = &loggingCallbacks;
-contextInfo.pD3D12CreateContextInfo = &d3d12ContextInfo;
-contextInfo.pVkCreateContextInfo = &vkContextInfo;
-```
-
-The library requires certain input textures from the application to create a reflection view.
-Thus, the context requires user specified unpack functions (HLSL SM 6.0) to access the individual attributes. It is recommended to keep these snippets as small as possible to achieve good performance.
-The function headers have to match in order for the shaders to compile. The `FFX_SSSR_*_TEXTURE_FORMAT` macros hold the definitions provided in the `p*TextureFormat` members of `FfxSssrCreateContextInfo`. The snippets provided below shall serve as a starting point:
-
-```C++
-contextInfo.pRoughnessTextureFormat = L"float4";
-contextInfo.pUnpackRoughnessSnippet = L"float FfxSssrUnpackRoughness(FFX_SSSR_ROUGHNESS_TEXTURE_FORMAT packed) { return packed.w; }";
-contextInfo.pNormalsTextureFormat = L"float4";
-contextInfo.pUnpackNormalsSnippet = L"float3 FfxSssrUnpackNormals(FFX_SSSR_NORMALS_TEXTURE_FORMAT packed) { return 2 * packed.xyz - 1; }";
-contextInfo.pSceneTextureFormat = L"float4";
-contextInfo.pUnpackSceneRadianceSnippet = L"float3 FfxSssrUnpackSceneRadiance(FFX_SSSR_SCENE_TEXTURE_FORMAT packed) { return packed.xyz; }";
-contextInfo.pDepthTextureFormat = L"float";
-contextInfo.pUnpackDepthSnippet = L"float FfxSssrUnpackDepth(FFX_SSSR_DEPTH_TEXTURE_FORMAT packed) { return packed.x; }";
-contextInfo.pMotionVectorFormat = L"float2";
-contextInfo.pUnpackMotionVectorsSnippet = L"float2 FfxSssrUnpackMotionVectors(FFX_SSSR_MOTION_VECTOR_TEXTURE_FORMAT packed) { return packed.xy; }";
-```
-
-After that the context can be created:
-
-```C++
-FfxSssrContext myContext;
-FfxSssrStatus status = ffxSssrCreateContext(&contextInfo, &myContext);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-
-Finally, submit the command list provided to the `pUploadCommandList` member of `FfxSssrCreateContextInfoD3D12` to the queue of your choice to upload the internal resources to the GPU. The same is required on Vulkan for the `uploadCommandBuffer` member of `FfxSssrVkCreateContextInfo`.
-
-Once there is no need to render reflections anymore the context should be destroyed to free internal resources:
-
-```C++
-FfxSssrStatus status = ffxSssrDestroyContext(myContext);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-
-## Reflection View - Creation and Update
-
-Reflection views represent the abstraction for the first bounce of indirect light from reflective surfaces as seen from a given camera.
-
-`FfxSssrReflectionView` resources can be created as such. Depending on the API fill either `FfxSssrD3D12CreateReflectionViewInfo` or `FfxSssrVkCreateReflectionViewInfo`:
-
-```C++
-FfxSssrD3D12CreateReflectionViewInfo d3d12ReflectionViewInfo = {};
-d3d12ReflectionViewInfo.depthBufferHierarchySRV;
-d3d12ReflectionViewInfo.motionBufferSRV;
-d3d12ReflectionViewInfo.normalBufferSRV;
-d3d12ReflectionViewInfo.roughnessBufferSRV;
-d3d12ReflectionViewInfo.normalHistoryBufferSRV;
-d3d12ReflectionViewInfo.roughnessHistoryBufferSRV;
-d3d12ReflectionViewInfo.outputBufferUAV;
-d3d12ReflectionViewInfo.sceneFormat;
-d3d12ReflectionViewInfo.sceneSRV;
-d3d12ReflectionViewInfo.environmentMapSRV;
-d3d12ReflectionViewInfo.pEnvironmentMapSamplerDesc;
-
-FfxSssrVkCreateReflectionViewInfo vkReflectionViewInfo = {};
-vkReflectionViewInfo.depthBufferHierarchySRV;
-vkReflectionViewInfo.motionBufferSRV;
-vkReflectionViewInfo.normalBufferSRV;
-vkReflectionViewInfo.roughnessBufferSRV;
-vkReflectionViewInfo.normalHistoryBufferSRV;
-vkReflectionViewInfo.roughnessHistoryBufferSRV;
-vkReflectionViewInfo.reflectionViewUAV;
-vkReflectionViewInfo.sceneFormat;
-vkReflectionViewInfo.sceneSRV;
-vkReflectionViewInfo.environmentMapSRV;
-vkReflectionViewInfo.environmentMapSampler;
-vkReflectionViewInfo.uploadCommandBuffer;
-
-FfxSssrCreateReflectionViewInfo reflectionViewInfo = {};
-reflectionViewInfo.flags = FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS | FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_NORMAL_BUFFERS | FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_ROUGHNESS_BUFFERS;
-reflectionViewInfo.outputWidth = width;
-reflectionViewInfo.outputHeight = height;
-reflectionViewInfo.pD3D12CreateReflectionViewInfo = &d3d12ReflectionViewInfo;
-reflectionViewInfo.pVkCreateReflectionViewInfo = &vkReflectionViewInfo;
-
-FfxSssrReflectionView myReflectionView;
-FfxSssrStatus status = ffxSssrCreateReflectionView(myContext, &reflectionViewInfo, &myReflectionView);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-
-On D3D12 all SRVs and UAVs must be allocated from a CPU accessible descriptor heap as they are copied into the descriptor tables of the library. `FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS` can be used if the application intends to query for timings later. The `FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_*` flags should be set if the normal or roughness surfaces are written in an alternating fashion. Don't set the flags if the surfaces are copied each frame.
-
-The reflection view depends on the screen size. It is recommended to destroy the reflection view on resize and create a new one:
-
-```C++
-FfxSssrStatus status = ffxSssrDestroyReflectionView(myContext, myReflectionView);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-
-Finally, the camera properties can be specified via the view and projection matrices. Each matrix is defined in row-major layout (i.e. the last 4 values in the float array of the view matrix are expected to be `(0, 0, 0, 1)` == the last row of the matrix):
-
-```C++
-FfxSssrStatus status = ffxSssrReflectionViewSetCameraParameters(myContext, myReflectionView, &myViewMatrix, &myProjectionMatrix);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-
-## Reflection View - Resolve
-
-Calling `ffxSssrEncodeResolveReflectionView` dispatches the actual shaders that perform the hierarchical tracing through the depth buffer and optionally also dispatches the denoising passes if the `FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE` flag is set. Depending on the API populate either `FfxSssrD3D12CommandEncodeInfo` or `FfxSssrVkCommandEncodeInfo`:
-
-```C++
-FfxSssrD3D12CommandEncodeInfo d3d12EncodeInfo = {};
-d3d12EncodeInfo.pCommandList = myCommandList;
-
-FfxSssrVkCommandEncodeInfo vkEncodeInfo = {};
-vkEncodeInfo.commandBuffer = myCommandBufferHandle;
-
-FfxSssrResolveReflectionViewInfo resolveInfo = {};
-resolveInfo.flags = FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE | FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING;
-resolveInfo.temporalStabilityScale = 0.99f;
-resolveInfo.maxTraversalIterations = 128;
-resolveInfo.mostDetailedDepthHierarchyMipLevel = 1;
-resolveInfo.depthBufferThickness = 0.015f;
-resolveInfo.minTraversalOccupancy = 4;
-resolveInfo.samplesPerQuad = FFX_SSSR_RAY_SAMPLES_PER_QUAD_1;
-resolveInfo.roughnessThreshold = 0.2f;
-resolveInfo.pD3D12CommandEncodeInfo = &d3d12EncodeInfo;
-resolveInfo.pVkCommandEncodeInfo = &vkEncodeInfo;
-FfxSssrStatus status = ffxSssrEncodeResolveReflectionView(myContext, myReflectionView, &resolveInfo);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-* Enabling `FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE` runs the libraries denoisers. Omit that flag if denoising is not required.
-* Enabling `FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING` counteracts temporal instabilities by shooting more rays in temporally unstable regions.
-* `resolveInfo.temporalStabilityScale` serves as a mean to trade noise with temporal stability (implies more ghosting).
-* `resolveInfo.maxTraversalIterations` limits the maximum number of intersections with the depth buffer hierarchy
-* `resolveInfo.mostDetailedDepthHierarchyMipLevel` limits the most detailed mipmap for depth buffer lookups when tracing non-mirror reflection rays.
-* `resolveInfo.depthBufferThickness` configures the accepted hit distance behind the depth buffer in view space.
-* `resolveInfo.minTraversalOccupancy` limits the number of threads in the depth traversal loop. If less than that number of threads remain present they exit the intersection loop early even if they did not find a depth buffer intersection yet. This only affects non-mirror reflection rays.
-* `resolveInfo.samplesPerQuad` serves as a starting point how many rays are spawned in glossy regions. The only supported values are `FFX_SSSR_RAY_SAMPLES_PER_QUAD_1`, `FFX_SSSR_RAY_SAMPLES_PER_QUAD_2` and `FFX_SSSR_RAY_SAMPLES_PER_QUAD_4`. The use of `FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING` dynamically bumps this up to a maximum of `4` to enforce convergence on a per pixel basis.
-* `resolveInfo.roughnessThreshold` determines the roughness value below which reflection rays are spawned. Any roughness values higher are considered not reflective and the reflection view will contain `(0, 0, 0, 0)`.
-
-When resolving a reflection view, the following operations take place:
-
-- Reflect the view rays at the surface normal and spawn reflection rays from the depth buffer.
-- Glossy reflections are supported by randomly jittering the ray based on surface roughness.
-- The resulting radiance information is denoised using spatio-temporal filtering.
-- The shading values are written out to the output buffer supplied at creation time.
-
-Note that the application is responsible for issuing the required barrier to synchronize the writes to the output buffer.
-
-## Reflection View - Performance Profiling
-
-It is possible to query profiling information by enabling the `FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS` flag when creating a reflection view:
-
-```
-d3d12ReflectionViewInfo.flags |= FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS;
-```
-
-This enables the scheduling of GPU timestamp queries to track the amount of time spent in the individual passes (these are tile classification, intersection and denoising).
-
-Note that these flags add additional runtime overhead and should be used for debugging/profiling purposes only. Set the flag to `0` to disable any timestamp queries.
-
-The profiling information can then be queried as below for the tile classification pass:
-
-```C++
-uint64_t tileClassificationTime;
-FfxSssrStatus status = ffxSssrReflectionViewGetTileClassificationElapsedTime(myContext, myReflectionView, &tileClassificationTime);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-
-For the intersection pass:
-
-```C++
-uint64_t intersectionTime;
-FfxSssrStatus status = ffxSssrReflectionViewGetIntersectionElapsedTime(myContext, myReflectionView, &intersectionTime);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-
-And the same for the denoising passes:
-
-```C++
-uint64_t denoisingTime;
-FfxSssrStatus status = ffxSssrReflectionViewGetDenoisingElapsedTime(myContext, myReflectionView, &denoisingTime);
-if (status != FFX_SSSR_STATUS_OK) {
- // Error handling
-}
-```
-
-The retrieved times are expressed in GPU ticks and can be converted using the timestamp frequency of the queue used to execute the encoded command list on D3D12 (`GetTimestampFrequency`). On Vulkan the `timestampPeriod` member of `VkPhysicalDeviceLimits` can be used to convert the times from GPU ticks to nanoseconds.
-
-## Frame management
-
-The **FidelityFX SSSR** library manages its own upload buffer internally that is used as a ring to transfer constant buffer data from the CPU to the GPU. The user must specify the number of frames the library should wait for before it can safely start re-using memory blocks:
-
-```
-contextInfo.frameCountBeforeMemoryReuse = myMaxFrameCountInFlight;
-```
-
-Finally, frame boundaries must be signalled to the library as such:
-
-```C++
-FfxSssrStatus status = ffxSssrAdvanceToNextFrame(myContext);
-if (status != FFX_SSSR_STATUS_OK)
-{
- // Error handling
-}
-```
-
-Note that `ffxSssrAdvanceToNextFrame()` can be called either at the beginning or the end of a frame, but should not be called in the middle of performing work for a given frame.
-
-## Limitations
-
-The library assumes that the depth buffer values range from `0 --> 1` with 0 being at the near plane and 1 being at the far plane. This implies that the depth buffer hierarchy is built with the `minimum` operator.
\ No newline at end of file
diff --git a/ffx-sssr/externals/dxc/dxcapi.h b/ffx-sssr/externals/dxc/dxcapi.h
deleted file mode 100644
index fd9a996..0000000
--- a/ffx-sssr/externals/dxc/dxcapi.h
+++ /dev/null
@@ -1,384 +0,0 @@
-
-///////////////////////////////////////////////////////////////////////////////
-// //
-// dxcapi.h //
-// Copyright (C) Microsoft Corporation. All rights reserved. //
-// This file is distributed under the University of Illinois Open Source //
-// License. See LICENSE.TXT for details. //
-// //
-// Provides declarations for the DirectX Compiler API entry point. //
-// //
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef __DXC_API__
-#define __DXC_API__
-
-#ifndef DXC_API_IMPORT
-#define DXC_API_IMPORT __declspec(dllimport)
-#endif
-
-struct IMalloc;
-struct IDxcIncludeHandler;
-
-///
-/// Creates a single uninitialized object of the class associated with a specified CLSID.
-///
-///
-/// The CLSID associated with the data and code that will be used to create the object.
-///
-///
-/// A reference to the identifier of the interface to be used to communicate
-/// with the object.
-///
-///
-/// Address of pointer variable that receives the interface pointer requested
-/// in riid. Upon successful return, *ppv contains the requested interface
-/// pointer. Upon failure, *ppv contains NULL.
-///
-/// While this function is similar to CoCreateInstance, there is no COM involvement.
-///
-typedef HRESULT (__stdcall *DxcCreateInstanceProc)(
- _In_ REFCLSID rclsid,
- _In_ REFIID riid,
- _Out_ LPVOID* ppv
-);
-
-typedef HRESULT(__stdcall *DxcCreateInstance2Proc)(
- _In_ IMalloc *pMalloc,
- _In_ REFCLSID rclsid,
- _In_ REFIID riid,
- _Out_ LPVOID* ppv
- );
-
-///
-/// Creates a single uninitialized object of the class associated with a specified CLSID.
-///
-///
-/// The CLSID associated with the data and code that will be used to create the object.
-///
-///
-/// A reference to the identifier of the interface to be used to communicate
-/// with the object.
-///
-///
-/// Address of pointer variable that receives the interface pointer requested
-/// in riid. Upon successful return, *ppv contains the requested interface
-/// pointer. Upon failure, *ppv contains NULL.
-///
-/// While this function is similar to CoCreateInstance, there is no COM involvement.
-///
-DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance(
- _In_ REFCLSID rclsid,
- _In_ REFIID riid,
- _Out_ LPVOID* ppv
- );
-
-DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance2(
- _In_ IMalloc *pMalloc,
- _In_ REFCLSID rclsid,
- _In_ REFIID riid,
- _Out_ LPVOID* ppv
-);
-
-
-// IDxcBlob is an alias of ID3D10Blob and ID3DBlob
-struct __declspec(uuid("8BA5FB08-5195-40e2-AC58-0D989C3A0102"))
-IDxcBlob : public IUnknown {
-public:
- virtual LPVOID STDMETHODCALLTYPE GetBufferPointer(void) = 0;
- virtual SIZE_T STDMETHODCALLTYPE GetBufferSize(void) = 0;
-};
-
-struct __declspec(uuid("7241d424-2646-4191-97c0-98e96e42fc68"))
-IDxcBlobEncoding : public IDxcBlob {
-public:
- virtual HRESULT STDMETHODCALLTYPE GetEncoding(_Out_ BOOL *pKnown,
- _Out_ UINT32 *pCodePage) = 0;
-};
-
-struct __declspec(uuid("e5204dc7-d18c-4c3c-bdfb-851673980fe7"))
-IDxcLibrary : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE SetMalloc(_In_opt_ IMalloc *pMalloc) = 0;
- virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(
- _In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE CreateBlobFromFile(
- LPCWSTR pFileName, _In_opt_ UINT32* codePage,
- _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
- virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingFromPinned(
- LPBYTE pText, UINT32 size, UINT32 codePage,
- _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
- virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnHeapCopy(
- _In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
- _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
- virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnMalloc(
- _In_bytecount_(size) LPCVOID pText, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,
- _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
- virtual HRESULT STDMETHODCALLTYPE CreateIncludeHandler(
- _COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE CreateStreamFromBlobReadOnly(
- _In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(
- _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf16(
- _In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
-};
-
-struct __declspec(uuid("CEDB484A-D4E9-445A-B991-CA21CA157DC2"))
-IDxcOperationResult : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE GetStatus(_Out_ HRESULT *pStatus) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetResult(_COM_Outptr_result_maybenull_ IDxcBlob **pResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetErrorBuffer(_COM_Outptr_result_maybenull_ IDxcBlobEncoding **pErrors) = 0;
-};
-
-struct __declspec(uuid("7f61fc7d-950d-467f-b3e3-3c02fb49187c"))
-IDxcIncludeHandler : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE LoadSource(
- _In_ LPCWSTR pFilename, // Candidate filename.
- _COM_Outptr_result_maybenull_ IDxcBlob **ppIncludeSource // Resultant source object for included file, nullptr if not found.
- ) = 0;
-};
-
-struct DxcDefine {
- LPCWSTR Name;
- _Maybenull_ LPCWSTR Value;
-};
-
-struct __declspec(uuid("8c210bf3-011f-4422-8d70-6f9acb8db617"))
-IDxcCompiler : public IUnknown {
- // Compile a single entry point to the target shader model
- virtual HRESULT STDMETHODCALLTYPE Compile(
- _In_ IDxcBlob *pSource, // Source text to compile
- _In_opt_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
- _In_ LPCWSTR pEntryPoint, // entry point name
- _In_ LPCWSTR pTargetProfile, // shader profile to compile
- _In_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
- _In_ UINT32 argCount, // Number of arguments
- _In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
- _In_ UINT32 defineCount, // Number of defines
- _In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
- _COM_Outptr_ IDxcOperationResult **ppResult // Compiler output status, buffer, and errors
- ) = 0;
-
- // Preprocess source text
- virtual HRESULT STDMETHODCALLTYPE Preprocess(
- _In_ IDxcBlob *pSource, // Source text to preprocess
- _In_opt_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
- _In_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
- _In_ UINT32 argCount, // Number of arguments
- _In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
- _In_ UINT32 defineCount, // Number of defines
- _In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
- _COM_Outptr_ IDxcOperationResult **ppResult // Preprocessor output status, buffer, and errors
- ) = 0;
-
- // Disassemble a program.
- virtual HRESULT STDMETHODCALLTYPE Disassemble(
- _In_ IDxcBlob *pSource, // Program to disassemble.
- _COM_Outptr_ IDxcBlobEncoding **ppDisassembly // Disassembly text.
- ) = 0;
-};
-
-struct __declspec(uuid("A005A9D9-B8BB-4594-B5C9-0E633BEC4D37"))
-IDxcCompiler2 : public IDxcCompiler {
- // Compile a single entry point to the target shader model with debug information.
- virtual HRESULT STDMETHODCALLTYPE CompileWithDebug(
- _In_ IDxcBlob *pSource, // Source text to compile
- _In_opt_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
- _In_ LPCWSTR pEntryPoint, // Entry point name
- _In_ LPCWSTR pTargetProfile, // Shader profile to compile
- _In_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
- _In_ UINT32 argCount, // Number of arguments
- _In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
- _In_ UINT32 defineCount, // Number of defines
- _In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
- _COM_Outptr_ IDxcOperationResult **ppResult, // Compiler output status, buffer, and errors
- _Outptr_opt_result_z_ LPWSTR *ppDebugBlobName,// Suggested file name for debug blob.
- _COM_Outptr_opt_ IDxcBlob **ppDebugBlob // Debug blob
- ) = 0;
-};
-
-struct __declspec(uuid("F1B5BE2A-62DD-4327-A1C2-42AC1E1E78E6"))
-IDxcLinker : public IUnknown {
-public:
- // Register a library with name to ref it later.
- virtual HRESULT RegisterLibrary(
- _In_opt_ LPCWSTR pLibName, // Name of the library.
- _In_ IDxcBlob *pLib // Library blob.
- ) = 0;
-
- // Links the shader and produces a shader blob that the Direct3D runtime can
- // use.
- virtual HRESULT STDMETHODCALLTYPE Link(
- _In_opt_ LPCWSTR pEntryName, // Entry point name
- _In_ LPCWSTR pTargetProfile, // shader profile to link
- _In_count_(libCount)
- const LPCWSTR *pLibNames, // Array of library names to link
- UINT32 libCount, // Number of libraries to link
- _In_count_(argCount)
- const LPCWSTR *pArguments, // Array of pointers to arguments
- _In_ UINT32 argCount, // Number of arguments
- _COM_Outptr_ IDxcOperationResult *
- *ppResult // Linker output status, buffer, and errors
- ) = 0;
- // Links the shader with export and produces a shader blob that the Direct3D
- // runtime can use.
- virtual HRESULT STDMETHODCALLTYPE LinkWithExports(
- _In_opt_ LPCWSTR pEntryName, // Entry point name
- _In_ LPCWSTR pTargetProfile, // shader profile to link
- _In_count_(libCount)
- const LPCWSTR *pLibNames, // Array of library names to link
- UINT32 libCount, // Number of libraries to link
- _In_count_(argCount)
- const LPCWSTR *pArguments, // Array of pointers to arguments
- _In_ UINT32 argCount, // Number of arguments
- _In_count_(exportCount) const DxcDefine *pExports, // Array of exports
- _In_ UINT32 exportCount, // Number of exports
- _COM_Outptr_ IDxcOperationResult *
- *ppResult // Linker output status, buffer, and errors
- ) = 0;
-};
-
-static const UINT32 DxcValidatorFlags_Default = 0;
-static const UINT32 DxcValidatorFlags_InPlaceEdit = 1; // Validator is allowed to update shader blob in-place.
-static const UINT32 DxcValidatorFlags_RootSignatureOnly = 2;
-static const UINT32 DxcValidatorFlags_ModuleOnly = 4;
-static const UINT32 DxcValidatorFlags_ValidMask = 0x7;
-
-struct __declspec(uuid("A6E82BD2-1FD7-4826-9811-2857E797F49A"))
-IDxcValidator : public IUnknown {
- // Validate a shader.
- virtual HRESULT STDMETHODCALLTYPE Validate(
- _In_ IDxcBlob *pShader, // Shader to validate.
- _In_ UINT32 Flags, // Validation flags.
- _COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors
- ) = 0;
-};
-
-struct __declspec(uuid("334b1f50-2292-4b35-99a1-25588d8c17fe"))
-IDxcContainerBuilder : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) = 0; // Loads DxilContainer to the builder
- virtual HRESULT STDMETHODCALLTYPE AddPart(_In_ UINT32 fourCC, _In_ IDxcBlob *pSource) = 0; // Part to add to the container
- virtual HRESULT STDMETHODCALLTYPE RemovePart(_In_ UINT32 fourCC) = 0; // Remove the part with fourCC
- virtual HRESULT STDMETHODCALLTYPE SerializeContainer(_Out_ IDxcOperationResult **ppResult) = 0; // Builds a container of the given container builder state
-};
-
-struct __declspec(uuid("091f7a26-1c1f-4948-904b-e6e3a8a771d5"))
-IDxcAssembler : public IUnknown {
- // Assemble dxil in ll or llvm bitcode to DXIL container.
- virtual HRESULT STDMETHODCALLTYPE AssembleToContainer(
- _In_ IDxcBlob *pShader, // Shader to assemble.
- _COM_Outptr_ IDxcOperationResult **ppResult // Assembly output status, buffer, and errors
- ) = 0;
-};
-
-struct __declspec(uuid("d2c21b26-8350-4bdc-976a-331ce6f4c54c"))
-IDxcContainerReflection : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pContainer) = 0; // Container to load.
- virtual HRESULT STDMETHODCALLTYPE GetPartCount(_Out_ UINT32 *pResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetPartKind(UINT32 idx, _Out_ UINT32 *pResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetPartContent(UINT32 idx, _COM_Outptr_ IDxcBlob **ppResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE FindFirstPartKind(UINT32 kind, _Out_ UINT32 *pResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetPartReflection(UINT32 idx, REFIID iid, void **ppvObject) = 0;
-};
-
-struct __declspec(uuid("AE2CD79F-CC22-453F-9B6B-B124E7A5204C"))
-IDxcOptimizerPass : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE GetOptionName(_COM_Outptr_ LPWSTR *ppResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetDescription(_COM_Outptr_ LPWSTR *ppResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetOptionArgCount(_Out_ UINT32 *pCount) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetOptionArgName(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetOptionArgDescription(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;
-};
-
-struct __declspec(uuid("25740E2E-9CBA-401B-9119-4FB42F39F270"))
-IDxcOptimizer : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE GetAvailablePassCount(_Out_ UINT32 *pCount) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetAvailablePass(UINT32 index, _COM_Outptr_ IDxcOptimizerPass** ppResult) = 0;
- virtual HRESULT STDMETHODCALLTYPE RunOptimizer(IDxcBlob *pBlob,
- _In_count_(optionCount) LPCWSTR *ppOptions, UINT32 optionCount,
- _COM_Outptr_ IDxcBlob **pOutputModule,
- _COM_Outptr_opt_ IDxcBlobEncoding **ppOutputText) = 0;
-};
-
-static const UINT32 DxcVersionInfoFlags_None = 0;
-static const UINT32 DxcVersionInfoFlags_Debug = 1; // Matches VS_FF_DEBUG
-static const UINT32 DxcVersionInfoFlags_Internal = 2; // Internal Validator (non-signing)
-
-struct __declspec(uuid("b04f5b50-2059-4f12-a8ff-a1e0cde1cc7e"))
-IDxcVersionInfo : public IUnknown {
- virtual HRESULT STDMETHODCALLTYPE GetVersion(_Out_ UINT32 *pMajor, _Out_ UINT32 *pMinor) = 0;
- virtual HRESULT STDMETHODCALLTYPE GetFlags(_Out_ UINT32 *pFlags) = 0;
-};
-
-// {73e22d93-e6ce-47f3-b5bf-f0664f39c1b0}
-__declspec(selectany) extern const CLSID CLSID_DxcCompiler = {
- 0x73e22d93,
- 0xe6ce,
- 0x47f3,
- { 0xb5, 0xbf, 0xf0, 0x66, 0x4f, 0x39, 0xc1, 0xb0 }
-};
-
-// {EF6A8087-B0EA-4D56-9E45-D07E1A8B7806}
-__declspec(selectany) extern const GUID CLSID_DxcLinker = {
- 0xef6a8087,
- 0xb0ea,
- 0x4d56,
- {0x9e, 0x45, 0xd0, 0x7e, 0x1a, 0x8b, 0x78, 0x6}
-};
-
-// {CD1F6B73-2AB0-484D-8EDC-EBE7A43CA09F}
-__declspec(selectany) extern const CLSID CLSID_DxcDiaDataSource = {
- 0xcd1f6b73,
- 0x2ab0,
- 0x484d,
- { 0x8e, 0xdc, 0xeb, 0xe7, 0xa4, 0x3c, 0xa0, 0x9f }
-};
-
-// {6245D6AF-66E0-48FD-80B4-4D271796748C}
-__declspec(selectany) extern const GUID CLSID_DxcLibrary = {
- 0x6245d6af,
- 0x66e0,
- 0x48fd,
- { 0x80, 0xb4, 0x4d, 0x27, 0x17, 0x96, 0x74, 0x8c }
-};
-
-// {8CA3E215-F728-4CF3-8CDD-88AF917587A1}
-__declspec(selectany) extern const GUID CLSID_DxcValidator = {
- 0x8ca3e215,
- 0xf728,
- 0x4cf3,
- { 0x8c, 0xdd, 0x88, 0xaf, 0x91, 0x75, 0x87, 0xa1 }
-};
-
-// {D728DB68-F903-4F80-94CD-DCCF76EC7151}
-__declspec(selectany) extern const GUID CLSID_DxcAssembler = {
- 0xd728db68,
- 0xf903,
- 0x4f80,
- { 0x94, 0xcd, 0xdc, 0xcf, 0x76, 0xec, 0x71, 0x51 }
-};
-
-// {b9f54489-55b8-400c-ba3a-1675e4728b91}
-__declspec(selectany) extern const GUID CLSID_DxcContainerReflection = {
- 0xb9f54489,
- 0x55b8,
- 0x400c,
- { 0xba, 0x3a, 0x16, 0x75, 0xe4, 0x72, 0x8b, 0x91 }
-};
-
-// {AE2CD79F-CC22-453F-9B6B-B124E7A5204C}
-__declspec(selectany) extern const GUID CLSID_DxcOptimizer = {
- 0xae2cd79f,
- 0xcc22,
- 0x453f,
- {0x9b, 0x6b, 0xb1, 0x24, 0xe7, 0xa5, 0x20, 0x4c}
-};
-
-// {94134294-411f-4574-b4d0-8741e25240d2}
-__declspec(selectany) extern const GUID CLSID_DxcContainerBuilder = {
- 0x94134294,
- 0x411f,
- 0x4574,
- { 0xb4, 0xd0, 0x87, 0x41, 0xe2, 0x52, 0x40, 0xd2 }
-};
-#endif
diff --git a/ffx-sssr/externals/dxc/dxcapi.use.h b/ffx-sssr/externals/dxc/dxcapi.use.h
deleted file mode 100644
index d502de2..0000000
--- a/ffx-sssr/externals/dxc/dxcapi.use.h
+++ /dev/null
@@ -1,162 +0,0 @@
-//*********************************************************
-//
-// Copyright (c) Microsoft. All rights reserved.
-// This code is licensed under the MIT License (MIT).
-// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
-// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
-// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
-// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
-//
-//*********************************************************
-//////////////////////////////////////////////////////////////////////////////
-// //
-// dxcapi.use.h //
-// Copyright (C) Microsoft Corporation. All rights reserved. //
-// This file is distributed under the University of Illinois Open Source //
-// License. See LICENSE.TXT for details. //
-// //
-// Provides support for DXC API users. //
-// //
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef __DXCAPI_USE_H__
-#define __DXCAPI_USE_H__
-
-#include "dxc/dxcapi.h"
-
-namespace dxc {
-
-// Helper class to dynamically load the dxcompiler or a compatible libraries.
-class DxcDllSupport {
-protected:
- HMODULE m_dll;
- DxcCreateInstanceProc m_createFn;
- DxcCreateInstance2Proc m_createFn2;
-
- HRESULT InitializeInternal(LPCWSTR dllName, LPCSTR fnName) {
- if (m_dll != nullptr) return S_OK;
- m_dll = LoadLibraryW(dllName);
-
- if (m_dll == nullptr) return HRESULT_FROM_WIN32(GetLastError());
- m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName);
-
- if (m_createFn == nullptr) {
- HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
- FreeLibrary(m_dll);
- m_dll = nullptr;
- return hr;
- }
-
- // Only basic functions used to avoid requiring additional headers.
- m_createFn2 = nullptr;
- char fnName2[128];
- size_t s = strlen(fnName);
- if (s < sizeof(fnName2) - 2) {
- memcpy(fnName2, fnName, s);
- fnName2[s] = '2';
- fnName2[s + 1] = '\0';
- m_createFn2 = (DxcCreateInstance2Proc)GetProcAddress(m_dll, fnName2);
- }
-
- return S_OK;
- }
-
-public:
- DxcDllSupport() : m_dll(nullptr), m_createFn(nullptr), m_createFn2(nullptr) {
- }
-
- DxcDllSupport(DxcDllSupport&& other) {
- m_dll = other.m_dll; other.m_dll = nullptr;
- m_createFn = other.m_createFn; other.m_createFn = nullptr;
- m_createFn2 = other.m_createFn2; other.m_createFn2 = nullptr;
- }
-
- ~DxcDllSupport() {
- Cleanup();
- }
-
- HRESULT Initialize() {
- return InitializeInternal(L"dxcompiler.dll", "DxcCreateInstance");
- }
-
- HRESULT InitializeForDll(_In_z_ const wchar_t* dll, _In_z_ const char* entryPoint) {
- return InitializeInternal(dll, entryPoint);
- }
-
- template
- HRESULT CreateInstance(REFCLSID clsid, _Outptr_ TInterface** pResult) {
- return CreateInstance(clsid, __uuidof(TInterface), (IUnknown**)pResult);
- }
-
- HRESULT CreateInstance(REFCLSID clsid, REFIID riid, _Outptr_ IUnknown **pResult) {
- if (pResult == nullptr) return E_POINTER;
- if (m_dll == nullptr) return E_FAIL;
- HRESULT hr = m_createFn(clsid, riid, (LPVOID*)pResult);
- return hr;
- }
-
- template
- HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, _Outptr_ TInterface** pResult) {
- return CreateInstance2(pMalloc, clsid, __uuidof(TInterface), (IUnknown**)pResult);
- }
-
- HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid, _Outptr_ IUnknown **pResult) {
- if (pResult == nullptr) return E_POINTER;
- if (m_dll == nullptr) return E_FAIL;
- if (m_createFn2 == nullptr) return E_FAIL;
- HRESULT hr = m_createFn2(pMalloc, clsid, riid, (LPVOID*)pResult);
- return hr;
- }
-
- bool HasCreateWithMalloc() const {
- return m_createFn2 != nullptr;
- }
-
- bool IsEnabled() const {
- return m_dll != nullptr;
- }
-
- void Cleanup() {
- if (m_dll != nullptr) {
- m_createFn = nullptr;
- m_createFn2 = nullptr;
- FreeLibrary(m_dll);
- m_dll = nullptr;
- }
- }
-
- HMODULE Detach() {
- HMODULE module = m_dll;
- m_dll = nullptr;
- return module;
- }
-};
-
-inline DxcDefine GetDefine(_In_ LPCWSTR name, LPCWSTR value) {
- DxcDefine result;
- result.Name = name;
- result.Value = value;
- return result;
-}
-
-// Checks an HRESULT and formats an error message with the appended data.
-void IFT_Data(HRESULT hr, _In_opt_ LPCWSTR data);
-
-void EnsureEnabled(DxcDllSupport &dxcSupport);
-void ReadFileIntoBlob(DxcDllSupport &dxcSupport, _In_ LPCWSTR pFileName,
- _Outptr_ IDxcBlobEncoding **ppBlobEncoding);
-void WriteBlobToConsole(_In_opt_ IDxcBlob *pBlob, DWORD streamType = STD_OUTPUT_HANDLE);
-void WriteBlobToFile(_In_opt_ IDxcBlob *pBlob, _In_ LPCWSTR pFileName);
-void WriteBlobToHandle(_In_opt_ IDxcBlob *pBlob, HANDLE hFile, _In_opt_ LPCWSTR pFileName);
-void WriteUtf8ToConsole(_In_opt_count_(charCount) const char *pText,
- int charCount, DWORD streamType = STD_OUTPUT_HANDLE);
-void WriteUtf8ToConsoleSizeT(_In_opt_count_(charCount) const char *pText,
- size_t charCount, DWORD streamType = STD_OUTPUT_HANDLE);
-void WriteOperationErrorsToConsole(_In_ IDxcOperationResult *pResult,
- bool outputWarnings);
-void WriteOperationResultToConsole(_In_ IDxcOperationResult *pRewriteResult,
- bool outputWarnings);
-
-} // namespace dxc
-
-#endif
diff --git a/ffx-sssr/ffx_sssr.h b/ffx-sssr/ffx_sssr.h
new file mode 100644
index 0000000..37ade0e
--- /dev/null
+++ b/ffx-sssr/ffx_sssr.h
@@ -0,0 +1,173 @@
+/**********************************************************************
+Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+********************************************************************/
+
+#ifndef FFX_SSSR
+#define FFX_SSSR
+#define FFX_SSSR_FLOAT_MAX 3.402823466e+38
+
+void FFX_SSSR_InitialAdvanceRay(float3 origin, float3 direction, float3 inv_direction, float2 current_mip_resolution, float2 current_mip_resolution_inv, float2 floor_offset, float2 uv_offset, out float3 position, out float current_t) {
+ float2 current_mip_position = current_mip_resolution * origin.xy;
+
+ // Intersect ray with the half box that is pointing away from the ray origin.
+ float2 xy_plane = floor(current_mip_position) + floor_offset;
+ xy_plane = xy_plane * current_mip_resolution_inv + uv_offset;
+
+ // o + d * t = p' => t = (p' - o) / d
+ float2 t = (xy_plane - origin.xy) * inv_direction.xy;
+ current_t = min(t.x, t.y);
+ position = origin + current_t * direction;
+}
+
+bool FFX_SSSR_AdvanceRay(float3 origin, float3 direction, float3 inv_direction, float2 current_mip_position, float2 current_mip_resolution_inv, float2 floor_offset, float2 uv_offset, float surface_z, inout float3 position, inout float current_t) {
+ // Create boundary planes
+ float2 xy_plane = floor(current_mip_position) + floor_offset;
+ xy_plane = xy_plane * current_mip_resolution_inv + uv_offset;
+ float3 boundary_planes = float3(xy_plane, surface_z);
+
+ // Intersect ray with the half box that is pointing away from the ray origin.
+ // o + d * t = p' => t = (p' - o) / d
+ float3 t = (boundary_planes - origin) * inv_direction;
+
+ // Prevent using z plane when shooting out of the depth buffer.
+#ifdef FFX_SSSR_INVERTED_DEPTH_RANGE
+ t.z = direction.z < 0 ? t.z : FFX_SSSR_FLOAT_MAX;
+#else
+ t.z = direction.z > 0 ? t.z : FFX_SSSR_FLOAT_MAX;
+#endif
+
+ // Choose nearest intersection with a boundary.
+ float t_min = min(min(t.x, t.y), t.z);
+
+#ifdef FFX_SSSR_INVERTED_DEPTH_RANGE
+ // Larger z means closer to the camera.
+ bool above_surface = surface_z < position.z;
+#else
+ // Smaller z means closer to the camera.
+ bool above_surface = surface_z > position.z;
+#endif
+
+ // Decide whether we are able to advance the ray until we hit the xy boundaries or if we had to clamp it at the surface.
+ bool skipped_tile = t_min != t.z && above_surface;
+
+ // Make sure to only advance the ray if we're still above the surface.
+ current_t = above_surface ? t_min : current_t;
+
+ // Advance ray
+ position = origin + current_t * direction;
+
+ return skipped_tile;
+}
+
+float2 FFX_SSSR_GetMipResolution(float2 screen_dimensions, int mip_level) {
+ return screen_dimensions * pow(0.5, mip_level);
+}
+
+// Requires origin and direction of the ray to be in screen space [0, 1] x [0, 1]
+float3 FFX_SSSR_HierarchicalRaymarch(float3 origin, float3 direction, bool is_mirror, float2 screen_size, int most_detailed_mip, uint min_traversal_occupancy, uint max_traversal_intersections, out bool valid_hit) {
+ const float3 inv_direction = direction != 0 ? 1.0 / direction : FFX_SSSR_FLOAT_MAX;
+
+ // Start on mip with highest detail.
+ int current_mip = most_detailed_mip;
+
+ // Could recompute these every iteration, but it's faster to hoist them out and update them.
+ float2 current_mip_resolution = FFX_SSSR_GetMipResolution(screen_size, current_mip);
+ float2 current_mip_resolution_inv = rcp(current_mip_resolution);
+
+ // Offset to the bounding boxes uv space to intersect the ray with the center of the next pixel.
+ // This means we ever so slightly over shoot into the next region.
+ float2 uv_offset = 0.005 * exp2(most_detailed_mip) / screen_size;
+ uv_offset = direction.xy < 0 ? -uv_offset : uv_offset;
+
+ // Offset applied depending on current mip resolution to move the boundary to the left/right upper/lower border depending on ray direction.
+ float2 floor_offset = direction.xy < 0 ? 0 : 1;
+
+ // Initially advance ray to avoid immediate self intersections.
+ float current_t;
+ float3 position;
+ FFX_SSSR_InitialAdvanceRay(origin, direction, inv_direction, current_mip_resolution, current_mip_resolution_inv, floor_offset, uv_offset, position, current_t);
+
+ bool exit_due_to_low_occupancy = false;
+ int i = 0;
+ while (i < max_traversal_intersections && current_mip >= most_detailed_mip && !exit_due_to_low_occupancy) {
+ float2 current_mip_position = current_mip_resolution * position.xy;
+ float surface_z = FFX_SSSR_LoadDepth(current_mip_position, current_mip);
+ bool skipped_tile = FFX_SSSR_AdvanceRay(origin, direction, inv_direction, current_mip_position, current_mip_resolution_inv, floor_offset, uv_offset, surface_z, position, current_t);
+ current_mip += skipped_tile ? 1 : -1;
+ current_mip_resolution *= skipped_tile ? 0.5 : 2;
+ current_mip_resolution_inv *= skipped_tile ? 2 : 0.5;
+ ++i;
+
+ exit_due_to_low_occupancy = !is_mirror && WaveActiveCountBits(true) <= min_traversal_occupancy;
+ }
+
+ valid_hit = (i <= max_traversal_intersections);
+
+ return position;
+}
+
+float FFX_SSSR_ValidateHit(float3 hit, float2 uv, float3 world_space_ray_direction, float2 screen_size, float depth_buffer_thickness) {
+ // Reject hits outside the view frustum
+ if (any(hit.xy < 0) || any(hit.xy > 1)) {
+ return 0;
+ }
+
+ // Reject the hit if we didnt advance the ray significantly to avoid immediate self reflection
+ float2 manhattan_dist = abs(hit.xy - uv);
+ if(all(manhattan_dist < (2 / screen_size))) {
+ return 0;
+ }
+
+ // Don't lookup radiance from the background.
+ int2 texel_coords = int2(screen_size * hit.xy);
+ float surface_z = FFX_SSSR_LoadDepth(texel_coords / 2, 1);
+#ifdef FFX_SSSR_INVERTED_DEPTH_RANGE
+ if (surface_z == 0.0) {
+#else
+ if (surface_z == 1.0) {
+#endif
+ return 0;
+ }
+
+ // We check if we hit the surface from the back, these should be rejected.
+ float3 hit_normal = FFX_SSSR_LoadNormal(texel_coords);
+ if (dot(hit_normal, world_space_ray_direction) > 0) {
+ return 0;
+ }
+
+ float3 view_space_surface = FFX_SSSR_ScreenSpaceToViewSpace(float3(hit.xy, surface_z));
+ float3 view_space_hit = FFX_SSSR_ScreenSpaceToViewSpace(hit);
+ float distance = length(view_space_surface - view_space_hit);
+
+ // Fade out hits near the screen borders
+ float2 fov = 0.05 * float2(screen_size.y / screen_size.x, 1);
+ float2 border = smoothstep(0, fov, hit.xy) * (1 - smoothstep(1 - fov, 1, hit.xy));
+ float vignette = border.x * border.y;
+
+ // We accept all hits that are within a reasonable minimum distance below the surface.
+ // Add constant in linear space to avoid growing of the reflections toward the reflected objects.
+ float confidence = 1 - smoothstep(0, depth_buffer_thickness, distance);
+ confidence *= confidence;
+
+ return vignette * confidence;
+}
+
+#endif //FFX_SSSR
diff --git a/ffx-sssr/inc/ffx_sssr.h b/ffx-sssr/inc/ffx_sssr.h
deleted file mode 100644
index 1d3d572..0000000
--- a/ffx-sssr/inc/ffx_sssr.h
+++ /dev/null
@@ -1,319 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-
-#define FFX_SSSR_MAKE_VERSION(a,b,c) (((a) << 22) | ((b) << 12) | (c))
-
-#define FFX_SSSR_API_VERSION FFX_SSSR_MAKE_VERSION(1, 1, 0)
-
-#define FFX_SSSR_STATIC_LIBRARY
-
-#ifndef FFX_SSSR_STATIC_LIBRARY
-#ifdef WIN32
-#ifdef EXPORT_API
-#define FFX_SSSR_API __declspec(dllexport)
-#else
-#define FFX_SSSR_API __declspec(dllimport)
-#endif
-#elif defined(__GNUC__)
-#ifdef EXPORT_API
-#define FFX_SSSR_API __attribute__((visibility ("default")))
-#else
-#define FFX_SSSR_API
-#endif
-#endif
-#else
-#define FFX_SSSR_API
-#endif
-
-typedef uint32_t FfxSssrFlags;
-
-#define FFX_SSSR_DEFINE_HANDLE(object) typedef struct object##_T* object;
-
-FFX_SSSR_DEFINE_HANDLE(FfxSssrContext)
-FFX_SSSR_DEFINE_HANDLE(FfxSssrReflectionView)
-
-/*!
- Forward declarations.
-*/
-typedef struct FfxSssrD3D12CreateContextInfo FfxSssrD3D12CreateContextInfo;
-typedef struct FfxSssrD3D12CreateReflectionViewInfo FfxSssrD3D12CreateReflectionViewInfo;
-typedef struct FfxSssrD3D12CommandEncodeInfo FfxSssrD3D12CommandEncodeInfo;
-typedef struct FfxSssrVkCreateContextInfo FfxSssrVkCreateContextInfo;
-typedef struct FfxSssrVkCreateReflectionViewInfo FfxSssrVkCreateReflectionViewInfo;
-typedef struct FfxSssrVkCommandEncodeInfo FfxSssrVkCommandEncodeInfo;
-
-/**
- The return codes for the API functions.
-*/
-enum FfxSssrStatus
-{
- FFX_SSSR_STATUS_OK = 0,
-
- FFX_SSSR_STATUS_INVALID_VALUE = -1,
- FFX_SSSR_STATUS_INVALID_OPERATION = -2,
- FFX_SSSR_STATUS_OUT_OF_MEMORY = -3,
- FFX_SSSR_STATUS_INCOMPATIBLE_API = -4,
- FFX_SSSR_STATUS_INTERNAL_ERROR = -5
-};
-
-/**
- The minimum number of ray samples per quad for variable rate tracing.
-*/
-enum FfxSssrRaySamplesPerQuad
-{
- FFX_SSSR_RAY_SAMPLES_PER_QUAD_1,
- FFX_SSSR_RAY_SAMPLES_PER_QUAD_2,
- FFX_SSSR_RAY_SAMPLES_PER_QUAD_4
-};
-
-/**
- The available flags for creating a reflection view.
-*/
-enum FfxSssrCreateReflectionViewFlagBits
-{
- FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS = 1 << 0, ///< Set this flag if the application wishes to retrieve timing results. Don't set this flag in release builds.
- FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_NORMAL_BUFFERS = 1 << 1, ///< Set this flag if the application writes to alternate surfaces. Don't set this flag to signal that the application copies the provided normal surfaces each frame.
- FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_ROUGHNESS_BUFFERS = 1 << 2 ///< Set this flag if the application writes to alternate surfaces. Don't set this flag to signal that the application copies the provided roughness surfaces each frame.
-};
-typedef FfxSssrFlags FfxSssrCreateReflectionViewFlags;
-
-/**
- The available flags for resolving a reflection view.
-*/
-enum FfxSssrResolveReflectionViewFlagBits
-{
- FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE = 1 << 0, ///< Run denoiser passes on intersection results.
- FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING = 1 << 1, ///< Enforces shooting a ray for temporally unstable pixels.
-};
-typedef FfxSssrFlags FfxSssrResolveReflectionViewFlags;
-
-/**
- The callback function for logging.
-
- \param pMessage The message to be logged.
-*/
-typedef void (*PFN_ffxSssrLoggingFunction)(const char* pMessage, void* pUserData);
-
-/**
- The callback information for logging.
-*/
-typedef struct FfxSssrLoggingCallbacks
-{
- void* pUserData;
- PFN_ffxSssrLoggingFunction pfnLogging;
-} FfxSssrLoggingCallbacks;
-
-/**
- The parameters for creating a context.
-*/
-typedef struct FfxSssrCreateContextInfo
-{
- uint32_t apiVersion;
- uint32_t maxReflectionViewCount;
- uint32_t frameCountBeforeMemoryReuse;
- size_t uploadBufferSize;
- const FfxSssrLoggingCallbacks* pLoggingCallbacks; ///< Can be null.
- const wchar_t* pRoughnessTextureFormat; ///< Used in the HLSL files to define the format of the resource containing surface roughness.
- const wchar_t* pUnpackRoughnessSnippet; ///< Used in the HLSL files to unpack the roughness from the provided resource.
- const wchar_t* pNormalsTextureFormat; ///< Used in the HLSL files to define the format of the resource containing the normals.
- const wchar_t* pUnpackNormalsSnippet; ///< Used in the HLSL files to unpack the normals from the provided resource.
- const wchar_t* pSceneTextureFormat; ///< Used in the HLSL files to define the format of the resource containing the rendered scene.
- const wchar_t* pUnpackSceneRadianceSnippet; ///< Used in the HLSL files to unpack the rendered scene from the provided resource.
- const wchar_t* pDepthTextureFormat; ///< Used in the HLSL files to define the format of the resource containing depth.
- const wchar_t* pUnpackDepthSnippet; ///< Used in the HLSL files to unpack the depth values from the provided resource.
- const wchar_t* pMotionVectorFormat; ///< Used in the HLSL files to define the format of the resource containing the motion vectors.
- const wchar_t* pUnpackMotionVectorsSnippet; ///< Used in the HLSL files to unpack the motion vectors from the provided resource.
- union
- {
- const FfxSssrD3D12CreateContextInfo* pD3D12CreateContextInfo;
- const FfxSssrVkCreateContextInfo* pVkCreateContextInfo;
- };
-} FfxSssrCreateContextInfo;
-
-/**
- The parameters for creating a reflection view.
-*/
-typedef struct FfxSssrCreateReflectionViewInfo
-{
- FfxSssrCreateReflectionViewFlags flags;
- uint32_t outputWidth;
- uint32_t outputHeight;
- union
- {
- const FfxSssrD3D12CreateReflectionViewInfo* pD3D12CreateReflectionViewInfo;
- const FfxSssrVkCreateReflectionViewInfo* pVkCreateReflectionViewInfo;
- };
-} FfxSssrCreateReflectionViewInfo;
-
-/**
- The parameters for resolving a reflection view.
-*/
-typedef struct FfxSssrResolveReflectionViewInfo
-{
- FfxSssrResolveReflectionViewFlags flags;
- float temporalStabilityScale; ///< Value between 0 and 1. High values prioritize temporal stability wheras low values avoid ghosting.
- uint32_t maxTraversalIterations; ///< Maximum number of iterations to find the intersection with the depth buffer.
- uint32_t mostDetailedDepthHierarchyMipLevel; ///< Applies only to non-mirror reflections. Mirror reflections always use 0 as most detailed mip.
- uint32_t minTraversalOccupancy; ///< Minimum number of threads per wave to keep the intersection kernel running.
- float depthBufferThickness; ///< Unit in view space. Any intersections further behind the depth buffer are rejected as invalid hits.
- FfxSssrRaySamplesPerQuad samplesPerQuad; ///< Number of samples per 4 pixels in denoised regions. Mirror reflections are not affected by this.
- float roughnessThreshold; ///< Shoot reflection rays for roughness values that are lower than this threshold.
- union
- {
- const FfxSssrD3D12CommandEncodeInfo* pD3D12CommandEncodeInfo; ///< A pointer to the Direct3D12 command encoding parameters.
- const FfxSssrVkCommandEncodeInfo* pVkCommandEncodeInfo; ///< A pointer to the Vulkan command encoding parameters.
- };
-} FfxSssrResolveReflectionViewInfo;
-
-// API functions
-#ifdef __cplusplus
-extern "C"
-{
-#endif
- /**
- Creates a new context.
-
- \param pCreateContextInfo The context creation information.
- \param outContext The context.
- \return The corresponding error code.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrCreateContext(const FfxSssrCreateContextInfo* pCreateContextInfo, FfxSssrContext* outContext);
-
- /**
- Destroys the context.
-
- \param context The context to be destroyed.
- \return The corresponding error code.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrDestroyContext(FfxSssrContext context);
-
- /**
- Creates a new reflection view.
-
- \param context The context to be used.
- \param pCreateReflectionViewInfo The reflection view creation information.
- \param outReflectionView The reflection view resource.
- \return The corresponding error code.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrCreateReflectionView(FfxSssrContext context, const FfxSssrCreateReflectionViewInfo* pCreateReflectionViewInfo, FfxSssrReflectionView* outReflectionView);
-
- /**
- Destroys the reflection view.
-
- \param context The context to be used.
- \param reflectionView The reflection view resource.
- \return The corresponding error code.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrDestroyReflectionView(FfxSssrContext context, FfxSssrReflectionView reflectionView);
-
- /**
- Encodes the command(s) for resolving the given reflection view.
-
- \param context The context to be used.
- \param reflectionView The resource for the reflection view.
- \param pResolveReflectionViewInfo The reflection view information.
- \return The corresponding error code.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrEncodeResolveReflectionView(FfxSssrContext context, FfxSssrReflectionView reflectionView, const FfxSssrResolveReflectionViewInfo* pResolveReflectionViewInfo);
-
- /**
- Advances the frame index.
-
- \param context The context to be used.
- \return The corresponding error code.
-
- \note Please call this once a frame so the library is able to safely re-use memory blocks after frameCountBeforeMemoryReuse frames have passed.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrAdvanceToNextFrame(FfxSssrContext context);
-
- /**
- Gets the number of GPU ticks spent in the tile classification pass.
-
- \param context The context to be used.
- \param reflectionView The resource for the reflection view.
- \param outTileClassificationElapsedTime The number of GPU ticks spent in the tile classification pass.
- \return The corresponding error code.
-
- \note This method will only function if the reflection view was created with the FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag.
- Also, note that it will actually return the time that was spent in the tile classification pass frameCountBeforeMemoryReuse frames ago.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewGetTileClassificationElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outTileClassificationElapsedTime);
-
-
- /**
- Gets the number of GPU ticks spent intersecting reflection rays with the depth buffer.
-
- \param context The context to be used.
- \param reflectionView The resource for the reflection view.
- \param outIntersectionElapsedTime The number of GPU ticks spent intersecting reflection rays with the depth buffer.
- \return The corresponding error code.
-
- \note This method will only function if the reflection view was created with the FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag.
- Also, note that it will actually return the time that was spent resolving frameCountBeforeMemoryReuse frames ago.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewGetIntersectionElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outIntersectionElapsedTime);
-
- /**
- Gets the number of GPU ticks spent denoising.
-
- \param context The context to be used.
- \param reflectionView The resource for the reflection view.
- \param outDenoisingElapsedTime The number of GPU ticks spent denoising.
- \return The corresponding error code.
-
- \note This method will only function if the reflection view was created with the FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag.
- Also, note that it will actually return the time that was spent denoising frameCountBeforeMemoryReuse frames ago.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewGetDenoisingElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outDenoisingElapsedTime);
-
- /**
- Gets the view and projection matrices for the reflection view.
-
- \param context The context to be used.
- \param reflectionView The resource for the reflection view.
- \param outViewMatrix The output value for the view matrix.
- \param outProjectionMatrix The output value for the projection matrix.
- \return The corresponding error code.
-
- \note The output matrices will be 4x4 row-major matrices.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewGetCameraParameters(FfxSssrContext context, FfxSssrReflectionView reflectionView, float* outViewMatrix, float* outProjectionMatrix);
-
- /**
- Sets the view and projection matrices for the reflection view.
-
- \param context The context to be used.
- \param reflectionView The resource for the reflection view.
- \param pViewMatrix The input value for the view matrix.
- \param pProjectionMatrix The input value for the projection matrix.
- \return The corresponding error code.
-
- \note The input matrices are expected to be 4x4 row-major matrices.
- */
- FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewSetCameraParameters(FfxSssrContext context, FfxSssrReflectionView reflectionView, const float* pViewMatrix, const float* pProjectionMatrix);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/ffx-sssr/inc/ffx_sssr_d3d12.h b/ffx-sssr/inc/ffx_sssr_d3d12.h
deleted file mode 100644
index a3a938b..0000000
--- a/ffx-sssr/inc/ffx_sssr_d3d12.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-#include
-
-/**
- The parameters for creating a Direct3D12 context.
-*/
-typedef struct FfxSssrD3D12CreateContextInfo
-{
- ID3D12Device* pDevice;
- ID3D12GraphicsCommandList* pUploadCommandList; ///< Command list to upload static resources. The application has to synchronize to make sure the uploads are done.
-} FfxSssrD3D12CreateContextInfo;
-
-/**
- The parameters for creating a Direct3D12 reflection view.
-*/
-typedef struct FfxSssrD3D12CreateReflectionViewInfo
-{
- DXGI_FORMAT sceneFormat; ///< The format of the sceneSRV to allow creating matching internal resources.
- D3D12_CPU_DESCRIPTOR_HANDLE sceneSRV; ///< The rendered scene without reflections. The descriptor handle must be allocated on a heap allowing CPU reads.
- D3D12_CPU_DESCRIPTOR_HANDLE depthBufferHierarchySRV; ///< Full downsampled depth buffer. Each lower detail mip containing the minimum values of the higher detailed mip. The descriptor handle must be allocated on a heap allowing CPU reads.
- D3D12_CPU_DESCRIPTOR_HANDLE motionBufferSRV; ///< The per pixel motion vectors. The descriptor handle must be allocated on a heap allowing CPU reads.
- D3D12_CPU_DESCRIPTOR_HANDLE normalBufferSRV; ///< The surface normals in world space. Each channel mapped to [0, 1]. The descriptor handle must be allocated on a heap allowing CPU reads.
- D3D12_CPU_DESCRIPTOR_HANDLE roughnessBufferSRV; ///< Perceptual roughness squared per pixel. The descriptor handle must be allocated on a heap allowing CPU reads.
- D3D12_CPU_DESCRIPTOR_HANDLE normalHistoryBufferSRV; ///< Last frames normalBufferSRV. The descriptor handle must be allocated on a heap allowing CPU reads.
- D3D12_CPU_DESCRIPTOR_HANDLE roughnessHistoryBufferSRV; ///< Last frames roughnessHistoryBufferSRV. The descriptor handle must be allocated on a heap allowing CPU reads.
- D3D12_CPU_DESCRIPTOR_HANDLE environmentMapSRV; ///< Environment cube map serving as a fallback for ray misses. The descriptor handle must be allocated on a heap allowing CPU reads.
- const D3D12_SAMPLER_DESC * pEnvironmentMapSamplerDesc; ///< Description for the environment map sampler.
- D3D12_CPU_DESCRIPTOR_HANDLE reflectionViewUAV; ///< The fully resolved reflection view. Make sure to synchronize for UAV writes. The descriptor handle must be allocated on a heap allowing CPU reads.
-} FfxSssrD3D12CreateReflectionViewInfo;
-
-/**
- \brief The parameters for encoding Direct3D12 device commands.
-*/
-typedef struct FfxSssrD3D12CommandEncodeInfo
-{
- ID3D12GraphicsCommandList* pCommandList; ///< The Direct3D12 command list to be used for command encoding.
-} FfxSssrD3D12CommandEncodeInfo;
diff --git a/ffx-sssr/inc/ffx_sssr_vk.h b/ffx-sssr/inc/ffx_sssr_vk.h
deleted file mode 100644
index e0ba2ed..0000000
--- a/ffx-sssr/inc/ffx_sssr_vk.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-
-/**
- The parameters for creating a Vulkan context.
-*/
-typedef struct FfxSssrVkCreateContextInfo
-{
- VkDevice device;
- VkPhysicalDevice physicalDevice;
- VkCommandBuffer uploadCommandBuffer; ///< Vulkan command buffer to upload static resources. The application has to begin the command buffer and has to handle synchronization to make sure the uploads are done.
-} FfxSssrVkCreateContextInfo;
-
-/**
- The parameters for creating a Vulkan reflection view.
-*/
-typedef struct FfxSssrVkCreateReflectionViewInfo
-{
- VkFormat sceneFormat; ///< The format of the sceneSRV to allow creating matching internal resources.
- VkImageView sceneSRV; ///< The rendered scene without reflections.
- VkImageView depthBufferHierarchySRV; ///< Full downsampled depth buffer. Each lower detail mip containing the minimum values of the higher detailed mip.
- VkImageView motionBufferSRV; ///< The per pixel motion vectors.
- VkImageView normalBufferSRV; ///< The surface normals in world space. Each channel mapped to [0, 1].
- VkImageView roughnessBufferSRV; ///< Perceptual roughness squared per pixel.
- VkImageView normalHistoryBufferSRV; ///< Last frames normalBufferSRV.
- VkImageView roughnessHistoryBufferSRV; ///< Last frames roughnessHistoryBufferSRV.
- VkSampler environmentMapSampler; ///< Environment map sampler used when looking up the fallback for ray misses.
- VkImageView environmentMapSRV; ///< Environment map serving as a fallback for ray misses.
- VkImageView reflectionViewUAV; ///< The fully resolved reflection view. Make sure to synchronize for UAV writes.
- VkCommandBuffer uploadCommandBuffer; ///< Vulkan command buffer to upload static resources. The application has to begin the command buffer and has to handle synchronization to make sure the uploads are done.
-} FfxSssrVkCreateReflectionViewInfo;
-
-/**
- \brief The parameters for encoding Vulkan device commands.
-*/
-typedef struct FfxSssrVkCommandEncodeInfo
-{
- VkCommandBuffer commandBuffer; ///< The Vulkan command buffer to be used for command encoding.
-} FfxSssrVkCommandEncodeInfo;
diff --git a/ffx-sssr/shaders/classify_tiles.hlsl b/ffx-sssr/shaders/classify_tiles.hlsl
deleted file mode 100644
index 7202541..0000000
--- a/ffx-sssr/shaders/classify_tiles.hlsl
+++ /dev/null
@@ -1,131 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-
-#ifndef FFX_SSSR_CLASSIFY_TILES
-#define FFX_SSSR_CLASSIFY_TILES
-
-// In:
-[[vk::binding(0, 1)]] Texture2D g_roughness : register(t0);
-
-// Out:
-[[vk::binding(1, 1)]] RWBuffer g_tile_list : register(u0);
-[[vk::binding(2, 1)]] RWBuffer g_ray_list : register(u1);
-[[vk::binding(3, 1)]] globallycoherent RWBuffer g_tile_counter : register(u2);
-[[vk::binding(4, 1)]] globallycoherent RWBuffer g_ray_counter : register(u3);
-[[vk::binding(5, 1)]] RWTexture2D g_temporally_denoised_reflections : register(u4);
-[[vk::binding(6, 1)]] RWTexture2D g_temporally_denoised_reflections_history : register(u5);
-[[vk::binding(7, 1)]] RWTexture2D g_ray_lengths : register(u6);
-[[vk::binding(8, 1)]] RWTexture2D g_temporal_variance : register(u7);
-[[vk::binding(9, 1)]] RWTexture2D g_denoised_reflections : register(u8);
-
-groupshared uint g_ray_count;
-groupshared uint g_ray_base_index;
-groupshared uint g_denoise_count;
-
-[numthreads(8, 8, 1)]
-void main(uint2 did : SV_DispatchThreadID, uint group_index : SV_GroupIndex)
-{
- bool is_first_lane_of_wave = WaveIsFirstLane();
- bool is_first_lane_of_threadgroup = group_index == 0;
-
- // First we figure out on a per thread basis if we need to shoot a reflection ray.
- uint2 screen_size;
- g_roughness.GetDimensions(screen_size.x, screen_size.y);
-
- // Disable offscreen pixels
- bool needs_ray = !(did.x >= screen_size.x || did.y >= screen_size.y);
-
- // Dont shoot a ray on very rough surfaces.
- float roughness = FfxSssrUnpackRoughness(g_roughness.Load(int3(did, 0)));
- needs_ray = needs_ray && IsGlossy(roughness);
-
- // Also we dont need to run the denoiser on mirror reflections.
- bool needs_denoiser = needs_ray && !IsMirrorReflection(roughness);
-
- // Decide which ray to keep
- bool is_base_ray = IsBaseRay(did, g_samples_per_quad);
- needs_ray = needs_ray && (!needs_denoiser || is_base_ray); // Make sure to not deactivate mirror reflection rays.
-
- if (g_temporal_variance_guided_tracing_enabled && needs_denoiser && !needs_ray)
- {
- float temporal_variance = g_temporal_variance.Load(did);
- bool has_temporal_variance = temporal_variance != 0.0;
-
- // If temporal variance is too high, we enforce a ray anyway.
- needs_ray = needs_ray || has_temporal_variance;
- }
-
- // Now we know for each thread if it needs to shoot a ray and wether or not a denoiser pass has to run on this pixel.
- // Thus, we need to compact the rays and append them all at once to the ray list.
- // Also, if there is at least one pixel in that tile that needs a denoiser, we have to append that tile to the tile list.
-
- if (is_first_lane_of_threadgroup)
- {
- g_ray_count = 0;
- g_denoise_count = 0;
- }
- GroupMemoryBarrierWithGroupSync(); // Wait for reset to finish
-
- uint local_ray_index_in_wave = WavePrefixCountBits(needs_ray);
- uint wave_ray_count = WaveActiveCountBits(needs_ray);
- bool wave_needs_denoiser = WaveActiveAnyTrue(needs_denoiser);
- uint wave_count = wave_needs_denoiser ? 1 : 0;
-
- uint local_ray_index_of_wave;
- if (is_first_lane_of_wave)
- {
- InterlockedAdd(g_ray_count, wave_ray_count, local_ray_index_of_wave);
- InterlockedAdd(g_denoise_count, wave_count);
- }
- local_ray_index_of_wave = WaveReadLaneFirst(local_ray_index_of_wave);
-
- GroupMemoryBarrierWithGroupSync(); // Wait for ray compaction to finish
-
- if (is_first_lane_of_threadgroup)
- {
- bool must_denoise = g_denoise_count > 0;
- uint denoise_count = must_denoise ? 1 : 0;
- uint ray_count = g_ray_count;
-
- uint tile_index;
- uint ray_base_index = 0;
-
- InterlockedAdd(g_tile_counter[0], denoise_count, tile_index);
- InterlockedAdd(g_ray_counter[0], ray_count, ray_base_index);
-
- int cleaned_index = must_denoise ? tile_index : -1;
- g_tile_list[cleaned_index] = Pack(did); // Write out pixel coords of upper left pixel
- g_ray_base_index = ray_base_index;
- }
- GroupMemoryBarrierWithGroupSync(); // Wait for ray base index to become available
-
- int2 target = needs_ray ? int2(-1, -1) : did;
- int ray_index = needs_ray ? g_ray_base_index + local_ray_index_of_wave + local_ray_index_in_wave : -1;
-
- g_ray_list[ray_index] = Pack(did); // Write out pixel to trace
- // Clear intersection targets as there wont be any ray that overwrites them
- g_temporally_denoised_reflections[target] = 0;
- g_ray_lengths[target] = 0;
- g_temporal_variance[did] = needs_ray ? (1 - g_skip_denoiser) : 0; // Re-purpose g_temporal_variance to hold the information for the spatial pass if a ray has been shot. Always write 0 if no denoiser is running.
-}
-
-#endif // FFX_SSSR_CLASSIFY_TILES
\ No newline at end of file
diff --git a/ffx-sssr/shaders/common.hlsl b/ffx-sssr/shaders/common.hlsl
deleted file mode 100644
index c882630..0000000
--- a/ffx-sssr/shaders/common.hlsl
+++ /dev/null
@@ -1,243 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-
-#ifndef FFX_SSSR_COMMON
-#define FFX_SSSR_COMMON
-
-#define FFX_SSSR_PI 3.14159265358979f
-#define FFX_SSSR_GOLDEN_RATIO 1.61803398875f
-
-#define FFX_SSSR_FLOAT_MAX 3.402823466e+38
-
-#define FFX_SSSR_FALSE 0
-#define FFX_SSSR_TRUE 1
-
-#define FFX_SSSR_USE_ROUGHNESS_OVERRIDE FFX_SSSR_FALSE
-#define FFX_SSSR_ROUGHNESS_OVERRIDE 0.1
-
-#define FFX_SSSR_TEMPORAL_VARIANCE_THRESHOLD 0.0005
-
-#if FFX_SSSR_USE_ROUGHNESS_OVERRIDE
-float FfxSssrUnpackRoughness(FFX_SSSR_ROUGHNESS_TEXTURE_FORMAT packed) { return FFX_SSSR_ROUGHNESS_OVERRIDE; }
-#else
-FFX_SSSR_ROUGHNESS_UNPACK_FUNCTION
-#endif
-
-FFX_SSSR_NORMALS_UNPACK_FUNCTION
-FFX_SSSR_MOTION_VECTOR_UNPACK_FUNCTION
-FFX_SSSR_DEPTH_UNPACK_FUNCTION
-FFX_SSSR_SCENE_RADIANCE_UNPACK_FUNCTION
-
-// Common constants
-[[vk::binding(0, 0)]] cbuffer Constants : register(b0)
-{
- float4x4 g_inv_view_proj;
- float4x4 g_proj;
- float4x4 g_inv_proj;
- float4x4 g_view;
- float4x4 g_inv_view;
- float4x4 g_prev_view_proj;
-
- uint g_frame_index;
- uint g_max_traversal_intersections;
- uint g_min_traversal_occupancy;
- uint g_most_detailed_mip;
- float g_temporal_stability_factor;
- float g_depth_buffer_thickness;
- uint g_samples_per_quad;
- uint g_temporal_variance_guided_tracing_enabled;
- float g_roughness_threshold;
- uint g_skip_denoiser;
-};
-
-// Mat must be able to transform origin from its current space into screen space.
-float3 ProjectPosition(float3 origin, float4x4 mat)
-{
- float4 projected = mul(float4(origin, 1), mat);
- projected.xyz /= projected.w;
- projected.xy = 0.5 * projected.xy + 0.5;
- projected.y = (1 - projected.y);
- return projected.xyz;
-}
-
-// Mat must be able to transform origin from screen space to a linear space.
-float3 InvProjectPosition(float3 origin, float4x4 mat)
-{
- origin.y = (1 - origin.y);
- origin.xy = 2 * origin.xy - 1;
- float4 projected = mul(float4(origin, 1), mat);
- projected.xyz /= projected.w;
- return projected.xyz;
-}
-
-// Origin and direction must be in the same space and mat must be able to transform from that space into screen space.
-float3 ProjectDirection(float3 origin, float3 direction, float3 screen_space_origin, float4x4 mat)
-{
- float3 offsetted = ProjectPosition(origin + direction, mat);
- return offsetted - screen_space_origin;
-}
-
-struct Ray
-{
- float3 origin;
- float3 direction;
-};
-
-// Create a ray that originates at the depth buffer surface and points away from the camera.
-Ray CreateViewSpaceRay(float3 screen_space_pos)
-{
- float3 view_space_pos = InvProjectPosition(screen_space_pos, g_inv_proj);
- Ray view_space_ray;
- view_space_ray.origin = view_space_pos;
- view_space_ray.direction = view_space_pos;
- return view_space_ray;
-}
-
-float3 LoadNormal(int2 index, Texture2D tex)
-{
- return FfxSssrUnpackNormals(tex.Load(int3(index, 0)));
-}
-
-float LoadRoughness(int2 index, Texture2D tex)
-{
- return FfxSssrUnpackRoughness(tex.Load(int3(index, 0)));
-}
-
-bool IsGlossy(float roughness)
-{
- return roughness < g_roughness_threshold;
-}
-
-bool IsMirrorReflection(float roughness)
-{
- return roughness < 0.0001;
-}
-
-float GetEdgeStoppingNormalWeight(float3 normal_p, float3 normal_q, float sigma)
-{
- return pow(max(dot(normal_p, normal_q), 0.0), sigma);
-}
-
-float GetEdgeStoppingRoughnessWeight(float roughness_p, float roughness_q, float sigma_min, float sigma_max)
-{
- return 1.0 - smoothstep(sigma_min, sigma_max, abs(roughness_p - roughness_q));
-}
-
-min16float GetEdgeStoppingRoughnessWeightFP16(min16float roughness_p, min16float roughness_q, min16float sigma_min, min16float sigma_max)
-{
- return 1.0 - smoothstep(sigma_min, sigma_max, abs(roughness_p - roughness_q));
-}
-
-// Roughness weight to prevent ghosting on pure mirror reflections
-float GetRoughnessAccumulationWeight(float roughness)
-{
- float near_singular_roughness = 0.00001;
- return smoothstep(0.0, near_singular_roughness, roughness);
-}
-
-float Gaussian(float x, float m, float sigma)
-{
- float a = length(x - m) / sigma;
- a *= a;
- return exp(-0.5 * a);
-}
-
-float Luminance(float3 clr)
-{
- return max(dot(clr, float3(0.299, 0.587, 0.114)), 0.00001);
-}
-
-uint Pack(uint2 coord)
-{
- return (coord.x & 0xFFFF) | (coord.y & 0xFFFF) << 16;
-}
-
-uint2 Unpack(uint packed)
-{
- return uint2(packed & 0xFFFF, packed >> 16);
-}
-
-bool IsBaseRay(uint2 did, uint samples_per_quad)
-{
- switch (samples_per_quad)
- {
- case 1:
- return ((did.x & 1) | (did.y & 1)) == 0; // Deactivates 3 out of 4 rays
- case 2:
- return (did.x & 1) == (did.y & 1); // Deactivates 2 out of 4 rays. Keeps diagonal.
- default: // case 4:
- return true;
- }
-}
-
-// Has to match the calculation in IsBaseRay. Assumes lane is in Z order.
-// i.e. 4 consecutive lanes 0 1 2 3
-// are remapped to
-// 0 1
-// 2 3
-uint GetBaseLane(uint lane, uint samples_per_quad)
-{
- switch (samples_per_quad)
- {
- case 1:
- return lane & (~0b11); // Map to upper left
- case 2:
- return lane ^ 0b1; // Toggle horizontal
- default: // case 4:
- return lane; // Identity
- }
-}
-
-uint PackFloat16(min16float2 v)
-{
- uint2 p = f32tof16(float2(v));
- return p.x | (p.y << 16);
-}
-
-min16float2 UnpackFloat16(uint a)
-{
- float2 tmp = f16tof32(
- uint2(a & 0xFFFF, a >> 16));
- return min16float2(tmp);
-}
-
-
-// From ffx_a.h
-
-
-
-uint BitfieldExtract(uint src, uint off, uint bits) { uint mask = (1 << bits) - 1; return (src >> off) & mask; } // ABfe
-uint BitfieldInsert(uint src, uint ins, uint bits) { uint mask = (1 << bits) - 1; return (ins & mask) | (src & (~mask)); } // ABfiM
-
-// LANE TO 8x8 MAPPING
-// ===================
-// 00 01 08 09 10 11 18 19
-// 02 03 0a 0b 12 13 1a 1b
-// 04 05 0c 0d 14 15 1c 1d
-// 06 07 0e 0f 16 17 1e 1f
-// 20 21 28 29 30 31 38 39
-// 22 23 2a 2b 32 33 3a 3b
-// 24 25 2c 2d 34 35 3c 3d
-// 26 27 2e 2f 36 37 3e 3f
-uint2 RemapLane8x8(uint lane) { return uint2(BitfieldInsert(BitfieldExtract(lane, 2u, 3u), lane, 1u), BitfieldInsert(BitfieldExtract(lane, 3u, 3u), BitfieldExtract(lane, 1u, 2u), 2u)); } // ARmpRed8x8
-
-#endif // FFX_SSSR_COMMON
\ No newline at end of file
diff --git a/ffx-sssr/shaders/intersect.hlsl b/ffx-sssr/shaders/intersect.hlsl
deleted file mode 100644
index 92a1a5a..0000000
--- a/ffx-sssr/shaders/intersect.hlsl
+++ /dev/null
@@ -1,365 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-
-#ifndef FFX_SSSR_INTERSECT
-#define FFX_SSSR_INTERSECT
-
-// In:
-[[vk::binding(0, 1)]] Texture2D g_lit_scene : register(t0); // scene rendered with lighting and shadows
-[[vk::binding(1, 1)]] Texture2D g_depth_buffer_hierarchy : register(t1);
-[[vk::binding(2, 1)]] Texture2D g_normal : register(t2);
-[[vk::binding(3, 1)]] Texture2D g_roughness : register(t3);
-[[vk::binding(4, 1)]] TextureCube g_environment_map : register(t4);
-[[vk::binding(5, 1)]] Buffer g_sobol_buffer : register(t5);
-[[vk::binding(6, 1)]] Buffer g_ranking_tile_buffer : register(t6);
-[[vk::binding(7, 1)]] Buffer g_scrambling_tile_buffer : register(t7);
-[[vk::binding(8, 1)]] Buffer g_ray_list : register(t8);
-
-// Samplers:
-[[vk::binding(9, 1)]] SamplerState g_linear_sampler : register(s0);
-[[vk::binding(10, 1)]] SamplerState g_environment_map_sampler : register(s1);
-
-// Out:
-[[vk::binding(11, 1)]] RWTexture2D g_intersection_result : register(u0); // reflection colors at the end of the intersect pass.
-[[vk::binding(12, 1)]] RWTexture2D g_ray_lengths : register(u1);
-[[vk::binding(13, 1)]] RWTexture2D g_denoised_reflections : register(u2); // Mirror reflections don't need to be denoised, the intersection pass can just write them to the final target.
-
-// Blue Noise Sampler by Eric Heitz. Returns a value in the range [0, 1].
-float SampleRandomNumber(in uint pixel_i, in uint pixel_j, in uint sample_index, in uint sample_dimension)
-{
- // Wrap arguments
- pixel_i = pixel_i & 127u;
- pixel_j = pixel_j & 127u;
- sample_index = sample_index & 255u;
- sample_dimension = sample_dimension & 255u;
-
- // xor index based on optimized ranking
- const uint ranked_sample_index = sample_index ^ g_ranking_tile_buffer[sample_dimension + (pixel_i + pixel_j * 128u) * 8u];
-
- // Fetch value in sequence
- uint value = g_sobol_buffer[sample_dimension + ranked_sample_index * 256u];
-
- // If the dimension is optimized, xor sequence value based on optimized scrambling
- value = value ^ g_scrambling_tile_buffer[(sample_dimension % 8u) + (pixel_i + pixel_j * 128u) * 8u];
-
- // Convert to float and return
- return (value + 0.5f) / 256.0f;
-}
-
-float2 SampleRandomVector2(uint2 pixel)
-{
- const uint sample_index = 0;
- float2 u = float2(
- fmod(SampleRandomNumber(pixel.x, pixel.y, sample_index, 0u) + (g_frame_index & 0xFFu) * FFX_SSSR_GOLDEN_RATIO, 1.0f),
- fmod(SampleRandomNumber(pixel.x, pixel.y, sample_index, 1u) + (g_frame_index & 0xFFu) * FFX_SSSR_GOLDEN_RATIO, 1.0f));
- return u;
-}
-
-#define M_PI FFX_SSSR_PI
-
-// http://jcgt.org/published/0007/04/01/paper.pdf by Eric Heitz
-// Input Ve: view direction
-// Input alpha_x, alpha_y: roughness parameters
-// Input U1, U2: uniform random numbers
-// Output Ne: normal sampled with PDF D_Ve(Ne) = G1(Ve) * max(0, dot(Ve, Ne)) * D(Ne) / Ve.z
-float3 sampleGGXVNDF(float3 Ve, float alpha_x, float alpha_y, float U1, float U2)
-{
- // Section 3.2: transforming the view direction to the hemisphere configuration
- float3 Vh = normalize(float3(alpha_x * Ve.x, alpha_y * Ve.y, Ve.z));
- // Section 4.1: orthonormal basis (with special case if cross product is zero)
- float lensq = Vh.x * Vh.x + Vh.y * Vh.y;
- float3 T1 = lensq > 0 ? float3(-Vh.y, Vh.x, 0) * rsqrt(lensq) : float3(1, 0, 0);
- float3 T2 = cross(Vh, T1);
- // Section 4.2: parameterization of the projected area
- float r = sqrt(U1);
- float phi = 2.0 * M_PI * U2;
- float t1 = r * cos(phi);
- float t2 = r * sin(phi);
- float s = 0.5 * (1.0 + Vh.z);
- t2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2;
- // Section 4.3: reprojection onto hemisphere
- float3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * Vh;
- // Section 3.4: transforming the normal back to the ellipsoid configuration
- float3 Ne = normalize(float3(alpha_x * Nh.x, alpha_y * Nh.y, max(0.0, Nh.z)));
- return Ne;
-}
-
-float3 Sample_GGX_VNDF_Ellipsoid(float3 Ve, float alpha_x, float alpha_y, float U1, float U2)
-{
- return sampleGGXVNDF(Ve, alpha_x, alpha_y, U1, U2);
-}
-
-float3 Sample_GGX_VNDF_Hemisphere(float3 Ve, float alpha, float U1, float U2)
-{
- return Sample_GGX_VNDF_Ellipsoid(Ve, alpha, alpha, U1, U2);
-}
-
-float3x3 CreateTBN(float3 N)
-{
- float3 U;
- if (abs(N.z) > 0.0)
- {
- float k = sqrt(N.y * N.y + N.z * N.z);
- U.x = 0.0; U.y = -N.z / k; U.z = N.y / k;
- }
- else
- {
- float k = sqrt(N.x * N.x + N.y * N.y);
- U.x = N.y / k; U.y = -N.x / k; U.z = 0.0;
- }
-
- float3x3 TBN;
- TBN[0] = U;
- TBN[1] = cross(N, U);
- TBN[2] = N;
- return transpose(TBN);
-}
-
-float3 SampleReflectionVector(float3 view_direction, float3 normal, float roughness, int2 did)
-{
- float3x3 tbn_transform = CreateTBN(normal);
- float3 view_direction_tbn = mul(-view_direction, tbn_transform);
-
- float2 u = SampleRandomVector2(did);
-
- float3 sampled_normal_tbn = Sample_GGX_VNDF_Hemisphere(view_direction_tbn, roughness, u.x, u.y);
- // sampled_normal_tbn = float3(0, 0, 1); // Overwrite normal sample to produce perfect reflection.
-
- float3 reflected_direction_tbn = reflect(-view_direction_tbn, sampled_normal_tbn);
-
- // Transform reflected_direction back to the initial space.
- float3x3 inv_tbn_transform = transpose(tbn_transform);
- return mul(reflected_direction_tbn, inv_tbn_transform);
-}
-
-float2 GetMipResolution(float2 screen_dimensions, int mip_level)
-{
- return screen_dimensions * pow(0.5, mip_level);
-}
-
-float LoadDepth(float2 idx, int mip)
-{
- return FfxSssrUnpackDepth(g_depth_buffer_hierarchy.Load(int3(idx, mip)));
-}
-
-void InitialAdvanceRay(float3 origin, float3 direction, float3 inv_direction, float2 current_mip_resolution, float2 current_mip_resolution_inv, float2 floor_offset, float2 uv_offset, out float3 position, out float current_t)
-{
- float2 current_mip_position = current_mip_resolution * origin.xy;
-
- // Intersect ray with the half box that is pointing away from the ray origin.
- float2 xy_plane = floor(current_mip_position) + floor_offset;
- xy_plane = xy_plane * current_mip_resolution_inv + uv_offset;
-
- // o + d * t = p' => t = (p' - o) / d
- float2 t = (xy_plane - origin.xy) * inv_direction.xy;
- current_t = min(t.x, t.y);
- position = origin + current_t * direction;
-}
-
-
-bool AdvanceRay(float3 origin, float3 direction, float3 inv_direction, float2 current_mip_position, float2 current_mip_resolution_inv, float2 floor_offset, float2 uv_offset, float surface_z, inout float3 position, inout float current_t)
-{
- // Create boundary planes
- float2 xy_plane = floor(current_mip_position) + floor_offset;
- xy_plane = xy_plane * current_mip_resolution_inv + uv_offset;
- float3 boundary_planes = float3(xy_plane, surface_z);
-
- // Intersect ray with the half box that is pointing away from the ray origin.
- // o + d * t = p' => t = (p' - o) / d
- float3 t = (boundary_planes - origin) * inv_direction;
-
- // Prevent using z plane when shooting out of the depth buffer.
- t.z = direction.z > 0 ? t.z : FFX_SSSR_FLOAT_MAX;
-
- // Choose nearest intersection with a boundary.
- float t_min = min(min(t.x, t.y), t.z);
-
- // Smaller z means closer to the camera.
- bool above_surface = surface_z > position.z;
-
- // Decide whether we are able to advance the ray until we hit the xy boundaries or if we had to clamp it at the surface.
- bool skipped_tile = t_min != t.z && above_surface;
-
- // Make sure to only advance the ray if we're still above the surface.
- current_t = above_surface ? t_min : current_t;
-
- // Advance ray
- position = origin + current_t * direction;
-
- return skipped_tile;
-}
-
-// Requires origin and direction of the ray to be in screen space [0, 1] x [0, 1]
-float3 HierarchicalRaymarch(float3 origin, float3 direction, bool is_mirror, float2 screen_size, out bool valid_hit)
-{
- int most_detailed_mip = is_mirror ? 0 : g_most_detailed_mip;
-
- const float3 inv_direction = direction != 0 ? 1.0 / direction : FFX_SSSR_FLOAT_MAX;
-
- // Start on mip with highest detail.
- int current_mip = most_detailed_mip;
-
- // Could recompute these every iteration, but it's faster to hoist them out and update them.
- float2 current_mip_resolution = GetMipResolution(screen_size, current_mip);
- float2 current_mip_resolution_inv = rcp(current_mip_resolution);
-
- // Offset to the bounding boxes in uv space to intersect the ray with the center of the next pixel.
- // This means we ever so slightly over shoot into the next region.
- float2 uv_offset = 0.005 * exp2(most_detailed_mip) / screen_size;
- uv_offset = direction.xy < 0 ? -uv_offset : uv_offset;
-
- // Offset applied depending on current mip resolution to move the boundary to the left/right upper/lower border depending on ray direction.
- float2 floor_offset = direction.xy < 0 ? 0 : 1;
-
- // Initially advance ray to avoid immediate self intersections.
- float current_t;
- float3 position;
- InitialAdvanceRay(origin, direction, inv_direction, current_mip_resolution, current_mip_resolution_inv, floor_offset, uv_offset, position, current_t);
-
- const uint min_traversal_occupancy = g_min_traversal_occupancy;
- const uint max_traversal_intersections = g_max_traversal_intersections;
-
- bool exit_due_to_low_occupancy = false;
- int i = 0;
- while (i < max_traversal_intersections && current_mip >= most_detailed_mip && !exit_due_to_low_occupancy)
- {
- float2 current_mip_position = current_mip_resolution * position.xy;
- float surface_z = LoadDepth(current_mip_position, current_mip);
- bool skipped_tile = AdvanceRay(origin, direction, inv_direction, current_mip_position, current_mip_resolution_inv, floor_offset, uv_offset, surface_z, position, current_t);
- current_mip += skipped_tile ? 1 : -1;
- current_mip_resolution *= skipped_tile ? 0.5 : 2;
- current_mip_resolution_inv *= skipped_tile ? 2 : 0.5;
- ++i;
-
- exit_due_to_low_occupancy = !is_mirror && WaveActiveCountBits(true) <= min_traversal_occupancy;
- }
-
- valid_hit = (i < max_traversal_intersections);
-
- return position;
-}
-
-float ValidateHit(float3 hit, Ray reflected_ray, float3 world_space_ray_direction, float2 screen_size)
-{
- // Reject hits outside the view frustum
- if (any(hit.xy < 0) || any(hit.xy > 1))
- {
- return 0;
- }
-
- // Don't lookup radiance from the background.
- int2 texel_coords = int2(screen_size * hit.xy);
- float surface_z = LoadDepth(texel_coords / 2, 1);
- if (surface_z == 1.0)
- {
- return 0;
- }
-
- // We check if we hit the surface from the back, these should be rejected.
- float3 hit_normal = LoadNormal(texel_coords, g_normal);
- if (dot(hit_normal, world_space_ray_direction) > 0)
- {
- return 0;
- }
-
- float3 view_space_surface = CreateViewSpaceRay(float3(hit.xy, surface_z)).origin;
- float3 view_space_hit = CreateViewSpaceRay(hit).origin;
- float distance = length(view_space_surface - view_space_hit);
-
- // Fade out hits near the screen borders
- float2 fov = 0.05 * float2(screen_size.y / screen_size.x, 1);
- float2 border = smoothstep(0, fov, hit.xy) * (1 - smoothstep(1 - fov, 1, hit.xy));
- float vignette = border.x * border.y;
-
- // We accept all hits that are within a reasonable minimum distance below the surface.
- // Add constant in linear space to avoid growing of the reflections toward the reflected objects.
- float confidence = 1 - smoothstep(0, g_depth_buffer_thickness, distance);
- confidence *= confidence;
-
- return vignette * confidence;
-}
-
-void Intersect(int2 did)
-{
- uint2 screen_size;
- g_intersection_result.GetDimensions(screen_size.x, screen_size.y);
-
- const uint skip_denoiser = g_skip_denoiser;
-
- float2 uv = (did + 0.5) / screen_size;
- float3 world_space_normal = LoadNormal(did, g_normal);
- float roughness = LoadRoughness(did, g_roughness);
- bool is_mirror = IsMirrorReflection(roughness);
-
- int most_detailed_mip = is_mirror ? 0 : g_most_detailed_mip;
- float2 mip_resolution = GetMipResolution(screen_size, most_detailed_mip);
- float z = LoadDepth(uv * mip_resolution, most_detailed_mip);
-
- Ray screen_space_ray;
- screen_space_ray.origin = float3(uv, z);
-
- Ray view_space_ray = CreateViewSpaceRay(screen_space_ray.origin);
-
- float3 view_space_surface_normal = mul(float4(normalize(world_space_normal), 0), g_view).xyz;
- float3 view_space_reflected_direction = SampleReflectionVector(view_space_ray.direction, view_space_surface_normal, roughness, did);
- screen_space_ray.direction = ProjectDirection(view_space_ray.origin, view_space_reflected_direction, screen_space_ray.origin, g_proj);
-
- bool valid_hit;
- float3 hit = HierarchicalRaymarch(screen_space_ray.origin, screen_space_ray.direction, is_mirror, screen_size, valid_hit);
- float3 world_space_reflected_direction = mul(float4(view_space_reflected_direction, 0), g_inv_view).xyz;
- float confidence = valid_hit ? ValidateHit(hit, screen_space_ray, world_space_reflected_direction, screen_size) : 0;
-
- float3 world_space_origin = InvProjectPosition(screen_space_ray.origin, g_inv_view_proj);
- float3 world_space_hit = InvProjectPosition(hit, g_inv_view_proj);
- float3 world_space_ray = world_space_hit - world_space_origin.xyz;
-
- float3 reflection_radiance = 0;
- if (confidence > 0)
- {
- // Found an intersection with the depth buffer -> We can lookup the color from lit scene.
- reflection_radiance = FfxSssrUnpackSceneRadiance(g_lit_scene.Load(int3(screen_size * hit.xy, 0)));
- }
-
- // Sample environment map.
- float3 environment_lookup = g_environment_map.SampleLevel(g_environment_map_sampler, world_space_reflected_direction, 0).xyz;
- reflection_radiance = confidence * reflection_radiance + (1 - confidence) * environment_lookup;
-
- g_intersection_result[did] = float4(reflection_radiance, 1);
- g_ray_lengths[did] = length(world_space_ray);
-
- // The denoisers won't copy the value of a mirror reflection, so we write it out to the final target
- int2 idx = (is_mirror || skip_denoiser) ? did : int2(-1, -1);
- g_denoised_reflections[idx] = float4(reflection_radiance.xyz, 1);
-}
-
-[numthreads(8, 8, 1)]
-void main(uint group_index : SV_GroupIndex, uint group_id : SV_GroupID)
-{
- // We can encounter some remainders here.
- // Worst case is that they are tracing a few more rays than necessary but they can't produce artifacts.
- uint ray_index = group_id * 64 + group_index;
- uint packed_coords = g_ray_list[ray_index];
- uint2 coords = Unpack(packed_coords);
- Intersect((int2)coords);
-}
-
-#endif // FFX_SSSR_INTERSECT
\ No newline at end of file
diff --git a/ffx-sssr/shaders/prepare_indirect_args.hlsl b/ffx-sssr/shaders/prepare_indirect_args.hlsl
deleted file mode 100644
index e6afa0e..0000000
--- a/ffx-sssr/shaders/prepare_indirect_args.hlsl
+++ /dev/null
@@ -1,52 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-
-#ifndef FFX_SSSR_INDIRECT_ARGS
-#define FFX_SSSR_INDIRECT_ARGS
-
-// In/Out:
-[[vk::binding(0, 1)]] RWBuffer g_tile_counter : register(u0);
-[[vk::binding(1, 1)]] RWBuffer g_ray_counter : register(u1);
-
-// Out:
-[[vk::binding(2, 1)]] RWBuffer g_intersect_args : register(u2);
-[[vk::binding(3, 1)]] RWBuffer g_denoiser_args : register(u3);
-
-[numthreads(1, 1, 1)]
-void main()
-{
- uint tile_counter = g_tile_counter[0];
- uint ray_counter = g_ray_counter[0];
-
- g_tile_counter[0] = 0;
- g_ray_counter[0] = 0;
-
- g_intersect_args[0] = (ray_counter + 63) / 64;
- g_intersect_args[1] = 1;
- g_intersect_args[2] = 1;
-
- g_denoiser_args[0] = tile_counter;
- g_denoiser_args[1] = 1;
- g_denoiser_args[2] = 1;
-}
-
-#endif // FFX_SSSR_INDIRECT_ARGS
\ No newline at end of file
diff --git a/ffx-sssr/shaders/resolve_eaw.hlsl b/ffx-sssr/shaders/resolve_eaw.hlsl
deleted file mode 100644
index 20a4e44..0000000
--- a/ffx-sssr/shaders/resolve_eaw.hlsl
+++ /dev/null
@@ -1,192 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-
-#ifndef FFX_SSSR_EAW_RESOLVE
-#define FFX_SSSR_EAW_RESOLVE
-
-// In:
-[[vk::binding(0, 1)]] Texture2D g_normal : register(t0);
-[[vk::binding(1, 1)]] Texture2D g_roughness : register(t1);
-[[vk::binding(2, 1)]] Texture2D g_depth_buffer : register(t2);
-[[vk::binding(3, 1)]] Buffer g_tile_list : register(t3);
-
-// Out:
-[[vk::binding(4, 1)]] RWTexture2D g_temporally_denoised_reflections : register(u0);
-[[vk::binding(5, 1)]] RWTexture2D g_denoised_reflections : register(u1); // will hold the reflection colors at the end of the resolve pass.
-
-groupshared uint g_shared_0[12][12];
-groupshared uint g_shared_1[12][12];
-
-void LoadFromGroupSharedMemory(int2 idx, out min16float3 radiance, out min16float roughness)
-{
- uint2 tmp;
- tmp.x = g_shared_0[idx.x][idx.y];
- tmp.y = g_shared_1[idx.x][idx.y];
-
- min16float4 min16tmp = min16float4(UnpackFloat16(tmp.x), UnpackFloat16(tmp.y));
- radiance = min16tmp.xyz;
- roughness = min16tmp.w;
-}
-
-void StoreInGroupSharedMemory(int2 idx, min16float3 radiance, min16float roughness)
-{
- min16float4 tmp = min16float4(radiance, roughness);
- g_shared_0[idx.x][idx.y] = PackFloat16(tmp.xy);
- g_shared_1[idx.x][idx.y] = PackFloat16(tmp.zw);
-}
-
-min16float3 LoadRadiance(int2 idx)
-{
- return g_temporally_denoised_reflections.Load(int3(idx, 0)).xyz;
-}
-
-min16float LoadRoughnessValue(int2 idx)
-{
- return FfxSssrUnpackRoughness(g_roughness.Load(int3(idx, 0)));
-}
-
-min16float4 ResolveScreenspaceReflections(int2 gtid, min16float center_roughness)
-{
- const min16float roughness_sigma_min = 0.001;
- const min16float roughness_sigma_max = 0.01;
-
- min16float3 sum = 0.0;
- min16float total_weight = 0.0;
-
- const int radius = 2;
- for (int dy = -radius; dy <= radius; ++dy)
- {
- for (int dx = -radius; dx <= radius; ++dx)
- {
- int2 texel_coords = gtid + int2(dx, dy);
-
- min16float3 radiance;
- min16float roughness;
- LoadFromGroupSharedMemory(texel_coords, radiance, roughness);
-
- min16float weight = GetEdgeStoppingRoughnessWeightFP16(center_roughness, roughness, roughness_sigma_min, roughness_sigma_max);
- sum += weight * radiance;
- total_weight += weight;
- }
- }
-
- sum /= max(total_weight, 0.0001);
- return min16float4(sum, 1);
-}
-
-void LoadWithOffset(int2 did, int2 offset, out min16float3 radiance, out min16float roughness)
-{
- did += offset;
- radiance = LoadRadiance(did);
- roughness = LoadRoughnessValue(did);
-}
-
-void StoreWithOffset(int2 gtid, int2 offset, min16float3 radiance, min16float roughness)
-{
- gtid += offset;
- StoreInGroupSharedMemory(gtid, radiance, roughness);
-}
-
-void InitializeGroupSharedMemory(int2 did, int2 gtid)
-{
- int2 offset_0 = 0;
- if (gtid.x < 4)
- {
- offset_0 = int2(8, 0);
- }
- else if (gtid.y >= 4)
- {
- offset_0 = int2(4, 4);
- }
- else
- {
- offset_0 = -gtid; // map all threads to the same memory location to guarantee cache hits.
- }
-
- int2 offset_1 = 0;
- if (gtid.y < 4)
- {
- offset_1 = int2(0, 8);
- }
- else
- {
- offset_1 = -gtid; // map all threads to the same memory location to guarantee cache hits.
- }
-
- min16float3 radiance_0;
- min16float roughness_0;
-
- min16float3 radiance_1;
- min16float roughness_1;
-
- min16float3 radiance_2;
- min16float roughness_2;
-
- /// XXA
- /// XXA
- /// BBC
-
- did -= 2;
- LoadWithOffset(did, int2(0, 0), radiance_0, roughness_0); // X
- LoadWithOffset(did, offset_0, radiance_1, roughness_1); // A & C
- LoadWithOffset(did, offset_1, radiance_2, roughness_2); // B
-
- StoreWithOffset(gtid, int2(0, 0), radiance_0, roughness_0); // X
- if (gtid.x < 4 || gtid.y >= 4)
- {
- StoreWithOffset(gtid, offset_0, radiance_1, roughness_1); // A & C
- }
- if (gtid.y < 4)
- {
- StoreWithOffset(gtid, offset_1, radiance_2, roughness_2); // B
- }
-}
-
-void Resolve(int2 did, int2 gtid)
-{
- InitializeGroupSharedMemory(did, gtid);
- GroupMemoryBarrierWithGroupSync();
-
- gtid += 2; // Center threads in groupshared memory
-
- min16float3 center_radiance;
- min16float center_roughness;
- LoadFromGroupSharedMemory(gtid, center_radiance, center_roughness);
-
- if (!IsGlossy(center_roughness) || IsMirrorReflection(center_roughness))
- {
- return;
- }
-
- g_denoised_reflections[did.xy] = ResolveScreenspaceReflections(gtid, center_roughness);
-}
-
-[numthreads(8, 8, 1)]
-void main(uint2 group_thread_id : SV_GroupThreadID, uint group_id : SV_GroupID)
-{
- uint packed_base_coords = g_tile_list[group_id];
- uint2 base_coords = Unpack(packed_base_coords);
- uint2 coords = base_coords + group_thread_id;
- Resolve((int2)coords, (int2)group_thread_id);
-}
-
-#endif // FFX_SSSR_EAW_RESOLVE
\ No newline at end of file
diff --git a/ffx-sssr/shaders/resolve_spatial.hlsl b/ffx-sssr/shaders/resolve_spatial.hlsl
deleted file mode 100644
index d40f823..0000000
--- a/ffx-sssr/shaders/resolve_spatial.hlsl
+++ /dev/null
@@ -1,265 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-
-#ifndef FFX_SSSR_SPATIAL_RESOLVE
-#define FFX_SSSR_SPATIAL_RESOLVE
-
-// In:
-[[vk::binding(0, 1)]] Texture2D g_depth_buffer : register(t0);
-[[vk::binding(1, 1)]] Texture2D g_normal : register(t1);
-[[vk::binding(2, 1)]] Texture2D g_roughness : register(t2);
-[[vk::binding(3, 1)]] Texture2D g_intersection_result : register(t3); // reflection colors at the end of the intersect pass.
-[[vk::binding(4, 1)]] Texture2D g_has_ray : register(t4);
-[[vk::binding(5, 1)]] Buffer g_tile_list : register(t5);
-
-// Out:
-[[vk::binding(6, 1)]] RWTexture2D g_spatially_denoised_reflections : register(u0);
-[[vk::binding(7, 1)]] RWTexture2D g_ray_lengths : register(u1);
-
-// Only really need 16x16 but 17x17 avoids bank conflicts.
-groupshared uint g_shared_0[17][17];
-groupshared uint g_shared_1[17][17];
-groupshared uint g_shared_2[17][17];
-groupshared uint g_shared_3[17][17];
-groupshared float g_shared_depth[17][17];
-
-min16float4 LoadRadianceFromGroupSharedMemory(int2 idx)
-{
- uint2 tmp;
- tmp.x = g_shared_0[idx.x][idx.y];
- tmp.y = g_shared_1[idx.x][idx.y];
- return min16float4(UnpackFloat16(tmp.x), UnpackFloat16(tmp.y));
-}
-
-min16float3 LoadNormalFromGroupSharedMemory(int2 idx)
-{
- uint2 tmp;
- tmp.x = g_shared_2[idx.x][idx.y];
- tmp.y = g_shared_3[idx.x][idx.y];
- return min16float4(UnpackFloat16(tmp.x), UnpackFloat16(tmp.y)).xyz;
-}
-
-float LoadDepthFromGroupSharedMemory(int2 idx)
-{
- return g_shared_depth[idx.x][idx.y];
-}
-
-void StoreInGroupSharedMemory(int2 idx, min16float4 radiance, min16float3 normal, float depth)
-{
- g_shared_0[idx.x][idx.y] = PackFloat16(radiance.xy);
- g_shared_1[idx.x][idx.y] = PackFloat16(radiance.zw);
- g_shared_2[idx.x][idx.y] = PackFloat16(normal.xy);
- g_shared_3[idx.x][idx.y] = PackFloat16(min16float2(normal.z, 0));
- g_shared_depth[idx.x][idx.y] = depth;
-}
-
-min16float LoadRayLengthFP16(int2 idx)
-{
- return g_ray_lengths.Load(idx);
-}
-
-min16float3 LoadRadianceFP16(int2 idx)
-{
- return g_intersection_result.Load(int3(idx, 0)).xyz;
-}
-
-min16float3 LoadNormalFP16(int2 idx)
-{
- return (min16float3) FfxSssrUnpackNormals(g_normal.Load(int3(idx, 0)));
-}
-
-float LoadDepth(int2 idx)
-{
- return FfxSssrUnpackDepth(g_depth_buffer.Load(int3(idx, 0)));
-}
-
-bool LoadHasRay(int2 idx)
-{
- return g_has_ray.Load(int3(idx, 0));
-}
-
-void LoadWithOffset(int2 did, int2 offset, out min16float ray_length, out min16float3 radiance, out min16float3 normal, out float depth, out bool has_ray)
-{
- did += offset;
- ray_length = LoadRayLengthFP16(did);
- radiance = LoadRadianceFP16(did);
- normal = LoadNormalFP16(did);
- depth = LoadDepth(did);
- has_ray = LoadHasRay(did);
-}
-
-void StoreWithOffset(int2 gtid, int2 offset, min16float ray_length, min16float3 radiance, min16float3 normal, float depth)
-{
- gtid += offset;
- StoreInGroupSharedMemory(gtid, min16float4(radiance, ray_length), normal, depth); // Pack ray length and radiance together
-}
-
-void InitializeGroupSharedMemory(int2 did, int2 gtid)
-{
- const uint samples_per_quad = g_samples_per_quad;
-
- // First pass, load (1 + 3 + 8 + 3 + 1) = (16x16) region into shared memory.
- // That is a guard band of 3, the inner region of 8 plus one additional band to catch base pixels if we didn't shoot rays for the respective edges/corners of the loaded region.
-
- int2 offset_0 = 0;
- int2 offset_1 = int2(8, 0);
- int2 offset_2 = int2(0, 8);
- int2 offset_3 = int2(8, 8);
-
- min16float ray_length_0;
- min16float3 radiance_0;
- min16float3 normal_0;
- float depth_0;
- bool has_ray_0;
-
- min16float ray_length_1;
- min16float3 radiance_1;
- min16float3 normal_1;
- float depth_1;
- bool has_ray_1;
-
- min16float ray_length_2;
- min16float3 radiance_2;
- min16float3 normal_2;
- float depth_2;
- bool has_ray_2;
-
- min16float ray_length_3;
- min16float3 radiance_3;
- min16float3 normal_3;
- float depth_3;
- bool has_ray_3;
-
- /// XA
- /// BC
-
- did -= 4; // 1 + 3 => additional band + left band
- LoadWithOffset(did, offset_0, ray_length_0, radiance_0, normal_0, depth_0, has_ray_0); // X
- LoadWithOffset(did, offset_1, ray_length_1, radiance_1, normal_1, depth_1, has_ray_1); // A
- LoadWithOffset(did, offset_2, ray_length_2, radiance_2, normal_2, depth_2, has_ray_2); // B
- LoadWithOffset(did, offset_3, ray_length_3, radiance_3, normal_3, depth_3, has_ray_3); // C
-
- // If own values are invalid, because no ray created them, lookup the values from the neighboring threads
- const int lane_index = WaveGetLaneIndex();
- const int base_lane_index = GetBaseLane(lane_index, samples_per_quad); // As offsets are multiples of 8, we always get the same base lane index no matter the offset.
- const bool is_base_ray = base_lane_index == lane_index;
-
- const int lane_index_0 = (has_ray_0 || is_base_ray) ? lane_index : base_lane_index;
- const int lane_index_1 = (has_ray_1 || is_base_ray) ? lane_index : base_lane_index;
- const int lane_index_2 = (has_ray_2 || is_base_ray) ? lane_index : base_lane_index;
- const int lane_index_3 = (has_ray_3 || is_base_ray) ? lane_index : base_lane_index;
-
- radiance_0 = WaveReadLaneAt(radiance_0, lane_index_0);
- radiance_1 = WaveReadLaneAt(radiance_1, lane_index_1);
- radiance_2 = WaveReadLaneAt(radiance_2, lane_index_2);
- radiance_3 = WaveReadLaneAt(radiance_3, lane_index_3);
-
- ray_length_0 = WaveReadLaneAt(ray_length_0, lane_index_0);
- ray_length_1 = WaveReadLaneAt(ray_length_1, lane_index_1);
- ray_length_2 = WaveReadLaneAt(ray_length_2, lane_index_2);
- ray_length_3 = WaveReadLaneAt(ray_length_3, lane_index_3);
-
- StoreWithOffset(gtid, offset_0, ray_length_0, radiance_0, normal_0, depth_0); // X
- StoreWithOffset(gtid, offset_1, ray_length_1, radiance_1, normal_1, depth_1); // A
- StoreWithOffset(gtid, offset_2, ray_length_2, radiance_2, normal_2, depth_2); // B
- StoreWithOffset(gtid, offset_3, ray_length_3, radiance_3, normal_3, depth_3); // C
-}
-
-min16float3 ResolveScreenspaceReflections(int2 gtid, min16float3 center_radiance, min16float3 center_normal, float center_depth)
-{
- float3 accumulated_radiance = center_radiance;
- float accumulated_weight = 1;
-
- const float normal_sigma = 64.0;
- const float depth_sigma = 0.02;
-
- // First 15 numbers of Halton(2,3) streteched to [-3,3]
- const int2 reuse_offsets[] = {
- 0, 1,
- -2, 1,
- 2, -3,
- -3, 0,
- 1, 2,
- -1, -2,
- 3, 0,
- -3, 3,
- 0, -3,
- -1, -1,
- 2, 1,
- -2, -2,
- 1, 0,
- 0, 2,
- 3, -1
- };
- const uint sample_count = 15;
-
- for (int i = 0; i < sample_count; ++i)
- {
- int2 new_idx = gtid + reuse_offsets[i];
- min16float3 normal = LoadNormalFromGroupSharedMemory(new_idx);
- float depth = LoadDepthFromGroupSharedMemory(new_idx);
- min16float4 radiance = LoadRadianceFromGroupSharedMemory(new_idx);
- float weight = 1
- * GetEdgeStoppingNormalWeight((float3)center_normal, (float3)normal, normal_sigma)
- * Gaussian(center_depth, depth, depth_sigma)
- ;
-
- // Accumulate all contributions.
- accumulated_weight += weight;
- accumulated_radiance += weight * radiance.xyz;
- }
-
- accumulated_radiance /= max(accumulated_weight, 0.00001);
- return accumulated_radiance;
-}
-
-void Resolve(int2 did, int2 gtid)
-{
- float center_roughness = LoadRoughness(did, g_roughness);
- InitializeGroupSharedMemory(did, gtid);
- GroupMemoryBarrierWithGroupSync();
-
- if (!IsGlossy(center_roughness) || IsMirrorReflection(center_roughness))
- {
- return;
- }
-
- gtid += 4; // Center threads in groupshared memory
-
- min16float4 center_radiance = LoadRadianceFromGroupSharedMemory(gtid);
- min16float3 center_normal = LoadNormalFromGroupSharedMemory(gtid);
- float center_depth = LoadDepthFromGroupSharedMemory(gtid);
- g_spatially_denoised_reflections[did.xy] = min16float4(ResolveScreenspaceReflections(gtid, center_radiance.xyz, center_normal, center_depth), 1);
- g_ray_lengths[did.xy] = center_radiance.w; // ray_length
-}
-
-[numthreads(64, 1, 1)]
-void main(uint group_thread_id_linear : SV_GroupThreadID, uint group_id : SV_GroupID)
-{
- uint packed_base_coords = g_tile_list[group_id];
- uint2 base_coords = Unpack(packed_base_coords);
- uint2 group_thread_id_2d = RemapLane8x8(group_thread_id_linear);
- uint2 coords = base_coords + group_thread_id_2d;
- Resolve((int2)coords, (int2)group_thread_id_2d);
-}
-
-#endif // FFX_SSSR_SPATIAL_RESOLVE
\ No newline at end of file
diff --git a/ffx-sssr/shaders/resolve_temporal.hlsl b/ffx-sssr/shaders/resolve_temporal.hlsl
deleted file mode 100644
index 9ea6137..0000000
--- a/ffx-sssr/shaders/resolve_temporal.hlsl
+++ /dev/null
@@ -1,244 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-
-#ifndef FFX_SSSR_TEMPORAL_RESOLVE
-#define FFX_SSSR_TEMPORAL_RESOLVE
-
-// In:
-[[vk::binding(0, 1)]] Texture2D g_normal : register(t0);
-[[vk::binding(1, 1)]] Texture2D g_roughness : register(t1);
-[[vk::binding(2, 1)]] Texture2D g_normal_history : register(t2);
-[[vk::binding(3, 1)]] Texture2D g_roughness_history : register(t3);
-[[vk::binding(4, 1)]] Texture2D g_depth_buffer : register(t4);
-[[vk::binding(5, 1)]] Texture2D g_motion_vectors : register(t5);
-[[vk::binding(6, 1)]] Texture2D g_temporally_denoised_reflections_history : register(t6); // reflection colors at the end of the temporal resolve pass of the previous frame.
-[[vk::binding(7, 1)]] Texture2D g_ray_lengths : register(t7);
-[[vk::binding(8, 1)]] Buffer g_tile_list : register(t8);
-
-// Out:
-[[vk::binding(9, 1)]] RWTexture2D g_temporally_denoised_reflections : register(u0);
-[[vk::binding(10, 1)]] RWTexture2D g_spatially_denoised_reflections : register(u1); // Technically still an input, but we have to keep it as UAV
-[[vk::binding(11, 1)]] RWTexture2D g_temporal_variance : register(u2);
-
-// From "Temporal Reprojection Anti-Aliasing"
-// https://github.com/playdeadgames/temporal
-/**********************************************************************
-Copyright (c) [2015] [Playdead]
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-********************************************************************/
-float3 ClipAABB(float3 aabb_min, float3 aabb_max, float3 prev_sample)
-{
- // Main idea behind clipping - it prevents clustering when neighbor color space
- // is distant from history sample
-
- // Here we find intersection between color vector and aabb color box
-
- // Note: only clips towards aabb center
- float3 aabb_center = 0.5 * (aabb_max + aabb_min);
- float3 extent_clip = 0.5 * (aabb_max - aabb_min) + 0.001;
-
- // Find color vector
- float3 color_vector = prev_sample - aabb_center;
- // Transform into clip space
- float3 color_vector_clip = color_vector / extent_clip;
- // Find max absolute component
- color_vector_clip = abs(color_vector_clip);
- float max_abs_unit = max(max(color_vector_clip.x, color_vector_clip.y), color_vector_clip.z);
-
- if (max_abs_unit > 1.0)
- {
- return aabb_center + color_vector / max_abs_unit; // clip towards color vector
- }
- else
- {
- return prev_sample; // point is inside aabb
- }
-}
-
-// Estimates spatial reflection radiance standard deviation
-float3 EstimateStdDeviation(int2 did, RWTexture2D tex)
-{
- float3 color_sum = 0.0;
- float3 color_sum_squared = 0.0;
-
- int radius = 1;
- float weight = (radius * 2.0 + 1.0) * (radius * 2.0 + 1.0);
-
- for (int dx = -radius; dx <= radius; dx++)
- {
- for (int dy = -radius; dy <= radius; dy++)
- {
- int2 texel_coords = did + int2(dx, dy);
- float3 value = tex.Load(texel_coords).xyz;
- color_sum += value;
- color_sum_squared += value * value;
- }
- }
-
- float3 color_std = (color_sum_squared - color_sum * color_sum / weight) / (weight - 1.0);
- return sqrt(max(color_std, 0.0));
-}
-
-float3 SampleRadiance(int2 texel_coords, Texture2D tex)
-{
- return tex.Load(int3(texel_coords, 0)).xyz;
-}
-
-float2 GetSurfaceReprojection(int2 did, float2 uv, float2 motion_vector)
-{
- // Reflector position reprojection
- float2 history_uv = uv - motion_vector;
- return history_uv;
-}
-
-float2 GetHitPositionReprojection(int2 did, float2 uv, float reflected_ray_length)
-{
- float z = FfxSssrUnpackDepth(g_depth_buffer.Load(int3(did, 0)));
- float3 view_space_ray = CreateViewSpaceRay(float3(uv, z)).direction;
-
- // We start out with reconstructing the ray length in view space.
- // This includes the portion from the camera to the reflecting surface as well as the portion from the surface to the hit position.
- float surface_depth = length(view_space_ray);
- float ray_length = surface_depth + reflected_ray_length;
-
- // We then perform a parallax correction by shooting a ray
- // of the same length "straight through" the reflecting surface
- // and reprojecting the tip of that ray to the previous frame.
- view_space_ray /= surface_depth; // == normalize(view_space_ray)
- view_space_ray *= ray_length;
- float3 world_hit_position = mul(float4(view_space_ray, 1), g_inv_view).xyz; // This is the "fake" hit position if we would follow the ray straight through the surface.
- float3 prev_hit_position = ProjectPosition(world_hit_position, g_prev_view_proj);
- float2 history_uv = prev_hit_position.xy;
- return history_uv;
-}
-
-float SampleHistory(float2 uv, uint2 image_size, float3 normal, float roughness, float3 radiance_min, float3 radiance_max, out float3 radiance)
-{
- int2 texel_coords = int2(image_size * uv);
- radiance = SampleRadiance(texel_coords, g_temporally_denoised_reflections_history);
- radiance = ClipAABB(radiance_min, radiance_max, radiance);
-
- float3 history_normal = LoadNormal(texel_coords, g_normal_history);
- float history_roughness = LoadRoughness(texel_coords, g_roughness_history);
-
- const float normal_sigma = 8.0;
- const float roughness_sigma_min = 0.01;
- const float roughness_sigma_max = 0.1;
- const float main_accumulation_factor = 0.90 + 0.1 * g_temporal_stability_factor;
-
- float accumulation_speed = main_accumulation_factor
- * GetEdgeStoppingNormalWeight(normal, history_normal, normal_sigma)
- * GetEdgeStoppingRoughnessWeight(roughness, history_roughness, roughness_sigma_min, roughness_sigma_max)
- * GetRoughnessAccumulationWeight(roughness)
- ;
-
- return saturate(accumulation_speed);
-}
-
-float ComputeTemporalVariance(float3 history_radiance, float3 radiance)
-{
- // Check temporal variance.
- float history_luminance = Luminance(history_radiance);
- float luminance = Luminance(radiance);
- return abs(history_luminance - luminance) / max(max(history_luminance, luminance), 0.00001);
-}
-
-float4 ResolveScreenspaceReflections(int2 did, float2 uv, uint2 image_size, float roughness)
-{
- float3 normal = LoadNormal(did, g_normal);
- float3 radiance = g_spatially_denoised_reflections.Load(did).xyz;
- float3 radiance_history = g_temporally_denoised_reflections_history.Load(int3(did, 0)).xyz;
- float ray_length = g_ray_lengths.Load(int3(did, 0));
-
- // And clip it to the local neighborhood
- float2 motion_vector = FfxSssrUnpackMotionVectors(g_motion_vectors.Load(int3(did, 0)));
- float3 color_std = EstimateStdDeviation(did, g_spatially_denoised_reflections);
- color_std *= (dot(motion_vector, motion_vector) == 0) ? 8 : 2.2; // Allow more accumulation if the surface did not move.
-
- float3 radiance_min = radiance.xyz - color_std;
- float3 radiance_max = radiance + color_std;
-
- // Reproject point on the reflecting surface
- float2 surface_reprojection_uv = GetSurfaceReprojection(did, uv, motion_vector);
-
- // Reproject hit point
- float2 hit_reprojection_uv = GetHitPositionReprojection(did, uv, ray_length);
-
- float2 reprojection_uv;
- reprojection_uv = (roughness < 0.05) ? hit_reprojection_uv : surface_reprojection_uv;
-
- float3 reprojection = 0;
- float weight = 0;
- if (all(reprojection_uv > 0.0) && all(reprojection_uv < 1.0))
- {
- weight = SampleHistory(reprojection_uv, image_size, normal, roughness, radiance_min, radiance_max, reprojection);
- }
-
- radiance = lerp(radiance, reprojection, weight);
- float temporal_variance = ComputeTemporalVariance(radiance_history, radiance) > FFX_SSSR_TEMPORAL_VARIANCE_THRESHOLD ? 1 : 0;
- return float4(radiance.xyz, temporal_variance);
-}
-
-void Resolve(int2 did)
-{
- float roughness = LoadRoughness(did, g_roughness);
- if (!IsGlossy(roughness) || IsMirrorReflection(roughness))
- {
- return;
- }
-
- uint2 image_size;
- g_temporally_denoised_reflections.GetDimensions(image_size.x, image_size.y);
- float2 uv = float2(did.x + 0.5, did.y + 0.5) / image_size;
-
- float4 resolve = ResolveScreenspaceReflections(did.xy, uv, image_size, roughness);
- g_temporally_denoised_reflections[did.xy] = float4(resolve.xyz, 1);
- g_temporal_variance[did.xy] = resolve.w;
-}
-
-[numthreads(8, 8, 1)]
-void main(uint2 group_thread_id : SV_GroupThreadID, uint group_id : SV_GroupID)
-{
- uint packed_base_coords = g_tile_list[group_id];
- uint2 base_coords = Unpack(packed_base_coords);
- uint2 coords = base_coords + group_thread_id;
- Resolve((int2)coords);
-}
-
-#endif // FFX_SSSR_TEMPORAL_RESOLVE
\ No newline at end of file
diff --git a/ffx-sssr/sourceToHeader.py b/ffx-sssr/sourceToHeader.py
deleted file mode 100644
index 30c79e5..0000000
--- a/ffx-sssr/sourceToHeader.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import sys
-
-def escape(line):
- line = line.replace ('"', '\\"')
- line = line.replace ('\n', '\\n')
- return line
-
-if __name__=='__main__':
- print ('const char {}[] = '.format (sys.argv[2]))
- for l in open(sys.argv[1], 'r').readlines():
- print ('"{}"'.format (escape (l)))
- print (';')
\ No newline at end of file
diff --git a/ffx-sssr/src/context.cpp b/ffx-sssr/src/context.cpp
deleted file mode 100644
index d0f2c53..0000000
--- a/ffx-sssr/src/context.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#include "context.h"
-
-#ifdef FFX_SSSR_D3D12
- #include "ffx_sssr_d3d12.h"
- #include "d3d12/context_d3d12.h"
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- #include "ffx_sssr_vk.h"
- #include "vk/context_vk.h"
-#endif // FFX_SSSR_VK
-
-namespace ffx_sssr
-{
- /**
- The constructor for the Context class.
-
- \param create_context_info The context creation information.
- */
- Context::Context(FfxSssrCreateContextInfo const& create_context_info)
- : frame_index_(0u)
- , frame_count_before_reuse_(create_context_info.frameCountBeforeMemoryReuse)
- , logging_function_(create_context_info.pLoggingCallbacks ? create_context_info.pLoggingCallbacks->pfnLogging : nullptr)
- , logging_function_user_data_(create_context_info.pLoggingCallbacks ? create_context_info.pLoggingCallbacks->pUserData : nullptr)
- , api_call_("ffxSssrCreateContext")
- , reflection_view_id_dispenser_(create_context_info.maxReflectionViewCount)
- , reflection_view_view_matrices_(create_context_info.maxReflectionViewCount)
- , reflection_view_projection_matrices_(create_context_info.maxReflectionViewCount)
- {
- // Create platform-specific context(s)
-#ifdef FFX_SSSR_D3D12
- if (create_context_info.pD3D12CreateContextInfo)
- {
- if (!create_context_info.pD3D12CreateContextInfo->pDevice)
- {
- throw reflection_error(*this, FFX_SSSR_STATUS_INVALID_VALUE, "pDevice must not be nullptr, cannot create Direct3D12 context");
- }
-
- context_d3d12_ = std::make_unique(*this, create_context_info);
- }
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- if (create_context_info.pVkCreateContextInfo)
- {
- if (!create_context_info.pVkCreateContextInfo->device)
- {
- throw reflection_error(*this, FFX_SSSR_STATUS_INVALID_VALUE, "device must not be VK_NULL_HANDLE, cannot create Vulkan context");
- }
-
- context_vk_ = std::make_unique(*this, create_context_info);
- }
-#endif // FFX_SSSR_VK
- }
-
- /**
- The destructor for the Context class.
- */
- Context::~Context()
- {
- }
-
- /**
- Destroys the object.
-
- \param object_id The identifier of the object to be destroyed.
- */
- void Context::DestroyObject(std::uint64_t object_id)
- {
- if (!IsObjectValid(object_id))
- {
- return; // object was already destroyed
- }
-
- auto const resource_type = GetResourceType(object_id);
-
- switch (resource_type)
- {
- case kResourceType_ReflectionView:
- {
- reflection_view_view_matrices_.Erase(ID(object_id));
- reflection_view_projection_matrices_.Erase(ID(object_id));
-
-#ifdef FFX_SSSR_D3D12
- if (context_d3d12_)
- context_d3d12_->reflection_views_.Erase(ID(object_id));
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- if (context_vk_)
- context_vk_->reflection_views_.Erase(ID(object_id));
-#endif // FFX_SSSR_VK
-
- reflection_view_id_dispenser_.FreeId(object_id);
- }
- break;
- default:
- {
- FFX_SSSR_ASSERT(0); // should never happen
- }
- break;
- }
- }
-
- /**
- Checks whether the object is valid.
-
- \param object_id The identifier of the object to be checked.
- \return true if the object is still valid, false otherwise.
- */
- bool Context::IsObjectValid(std::uint64_t object_id) const
- {
- auto const resource_type = GetResourceType(object_id);
-
- switch (resource_type)
- {
- case kResourceType_ReflectionView:
- {
- if (reflection_view_id_dispenser_.IsValid(object_id))
- {
- return true;
- }
- }
- break;
- default:
- {
- FFX_SSSR_ASSERT(0); // should never happen
- }
- break;
- }
-
- return false;
- }
-
- /**
- Creates the reflection view.
-
- \param reflection_view_id The identifier of the reflection view object.
- \param create_reflection_view_info The reflection view creation information.
- */
- void Context::CreateReflectionView(std::uint64_t reflection_view_id, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info)
- {
-#ifdef FFX_SSSR_D3D12
- if (context_d3d12_ && create_reflection_view_info.pD3D12CreateReflectionViewInfo)
- context_d3d12_->CreateReflectionView(reflection_view_id, create_reflection_view_info);
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- if (context_vk_ && create_reflection_view_info.pVkCreateReflectionViewInfo)
- context_vk_->CreateReflectionView(reflection_view_id, create_reflection_view_info);
-#endif // FFX_SSSR_VK
- }
-
- /**
- Resolves the reflection view.
-
- \param reflection_view_id The identifier of the reflection view object.
- \param resolve_reflection_view_info The reflection view resolve information.
- */
- void Context::ResolveReflectionView(std::uint64_t reflection_view_id, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info)
- {
- FFX_SSSR_ASSERT(reflection_view_view_matrices_.At(ID(reflection_view_id))); // not created properly?
- FFX_SSSR_ASSERT(reflection_view_projection_matrices_.At(ID(reflection_view_id)));
-
-#ifdef FFX_SSSR_D3D12
- context_d3d12_->ResolveReflectionView(reflection_view_id, resolve_reflection_view_info);
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- context_vk_->ResolveReflectionView(reflection_view_id, resolve_reflection_view_info);
-#endif // FFX_SSSR_VK
- }
-
- /**
- Gets the number of GPU ticks spent in the tile classification pass when resolving the reflection view.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param elapsed_time The number of GPU ticks spent in the tile classification pass when resolving the view.
- */
- void Context::GetReflectionViewTileClassificationElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const
- {
- FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id));
-
-#ifdef FFX_SSSR_D3D12
- if (context_d3d12_)
- context_d3d12_->GetReflectionViewTileClassificationElapsedTime(reflection_view_id, elapsed_time);
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- if (context_vk_)
- context_vk_->GetReflectionViewTileClassificationElapsedTime(reflection_view_id, elapsed_time);
-#endif // FFX_SSSR_VK
- }
-
- /**
- Gets the number of GPU ticks spent resolving the reflection view.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param elapsed_time The number of GPU ticks spent resolving the view.
- */
- void Context::GetReflectionViewIntersectionElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const
- {
- FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id));
-
-#ifdef FFX_SSSR_D3D12
- if (context_d3d12_)
- context_d3d12_->GetReflectionViewIntersectionElapsedTime(reflection_view_id, elapsed_time);
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- if (context_vk_)
- context_vk_->GetReflectionViewIntersectionElapsedTime(reflection_view_id, elapsed_time);
-#endif // FFX_SSSR_VK
- }
-
- /**
- Gets the number of GPU ticks spent denoising for the reflection view.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param elapsed_time The number of GPU ticks spent denoising.
- */
- void Context::GetReflectionViewDenoisingElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const
- {
- FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id));
-
-#ifdef FFX_SSSR_D3D12
- if (context_d3d12_)
- context_d3d12_->GetReflectionViewDenoisingElapsedTime(reflection_view_id, elapsed_time);
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- if (context_vk_)
- context_vk_->GetReflectionViewDenoisingElapsedTime(reflection_view_id, elapsed_time);
-#endif // FFX_SSSR_VK
- }
-}
diff --git a/ffx-sssr/src/context.h b/ffx-sssr/src/context.h
deleted file mode 100644
index d5b7454..0000000
--- a/ffx-sssr/src/context.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-#include
-
-#include "float3.h"
-#include "memory.h"
-#include "matrix4.h"
-#include "reflection_error.h"
-#include "resources.h"
-
-namespace ffx_sssr
-{
- class ContextD3D12;
- class ContextVK;
-
- /**
- The Context class encapsulates the data for a single execution context.
-
- \note An object identifier possesses the following structure:
- - top 16 bits: resource identifier (see kResourceType_Xxx).
- - next 16 bits: generational identifier (so deleting twice does not crash).
- - bottom 32 bits: object index (for looking up attached components).
- */
- class Context
- {
- FFX_SSSR_NON_COPYABLE(Context);
-
- public:
- Context(FfxSssrCreateContextInfo const& create_context_info);
- ~Context();
-
- inline std::uint32_t& GetFrameIndex();
- inline std::uint32_t GetFrameIndex() const;
- inline std::uint32_t GetFrameCountBeforeReuse() const;
-
- template
- void CreateObject(std::uint64_t& object_id);
- void DestroyObject(std::uint64_t object_id);
-
- template
- bool IsOfType(std::uint64_t object_id) const;
- bool IsObjectValid(std::uint64_t object_id) const;
-
- template
- inline std::uint32_t GetObjectCount() const;
- template
- inline std::uint32_t GetMaxObjectCount() const;
-
- inline ContextD3D12* GetContextD3D12();
- inline ContextD3D12 const* GetContextD3D12() const;
-
- inline ContextVK* GetContextVK();
- inline ContextVK const* GetContextVK() const;
-
- void CreateReflectionView(std::uint64_t reflection_view_id, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info);
- void ResolveReflectionView(std::uint64_t reflection_view_id, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info);
-
- inline char const* GetAPICall() const;
- inline void SetAPICall(char const* api_call);
-
- inline static char const* GetErrorName(FfxSssrStatus error);
- inline void Error(FfxSssrStatus error, char const* format, ...) const;
- inline void Error(FfxSssrStatus error, char const* format, va_list args) const;
- inline void AdvanceToNextFrame();
-
- void GetReflectionViewTileClassificationElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const;
- void GetReflectionViewIntersectionElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const;
- void GetReflectionViewDenoisingElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const;
-
- inline void GetReflectionViewViewMatrix(std::uint64_t reflection_view_id, matrix4& view_matrix) const;
- inline void SetReflectionViewViewMatrix(std::uint64_t reflection_view_id, matrix4 const& view_matrix);
- inline void GetReflectionViewProjectionMatrix(std::uint64_t reflection_view_id, matrix4& projection_matrix) const;
- inline void SetReflectionViewProjectionMatrix(std::uint64_t reflection_view_id, matrix4 const& projection_matrix);
-
- protected:
- friend class ContextD3D12;
- friend class ContextVK;
-
- static inline ResourceType GetResourceType(std::uint64_t object_id);
- static inline void SetResourceType(std::uint64_t& object_id, ResourceType resource_type);
-
- inline bool CreateObject(std::uint64_t& object_id, ResourceType resource_type, IdDispenser& id_dispenser);
-
- // The index of the current frame.
- std::uint32_t frame_index_;
- // The number of frames before memory can be re-used.
- std::uint32_t const frame_count_before_reuse_;
- // The logging function to be used to print out messages.
- PFN_ffxSssrLoggingFunction logging_function_;
- // The user data to be supplied to the logging function.
- void* logging_function_user_data_;
- // The API call that is currently being executed.
- char const* api_call_;
-
-#ifdef FFX_SSSR_D3D12
- // The Direct3D12 context object.
- std::unique_ptr context_d3d12_;
-#endif // FFX_SSSR_D3D12
-
-#ifdef FFX_SSSR_VK
- // The Direct3D12 context object.
- std::unique_ptr context_vk_;
-#endif // FFX_SSSR_VK
-
- // The list of reflection view identifiers.
- IdDispenser reflection_view_id_dispenser_;
-
- // The array of per reflection view view matrices.
- SparseArray reflection_view_view_matrices_;
- // The array of per reflection view projection matrices.
- SparseArray reflection_view_projection_matrices_;
- };
-}
-
-#include "context.inl"
diff --git a/ffx-sssr/src/context.inl b/ffx-sssr/src/context.inl
deleted file mode 100644
index 5150f6f..0000000
--- a/ffx-sssr/src/context.inl
+++ /dev/null
@@ -1,399 +0,0 @@
-#include "context.h"
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-namespace ffx_sssr
-{
- /**
- Creates a new reflection view.
-
- \param object_id The identifier of the new reflection view.
- */
- template<>
- inline void Context::CreateObject(std::uint64_t& object_id)
- {
- if (!CreateObject(object_id, kResourceType_ReflectionView, reflection_view_id_dispenser_))
- {
- throw reflection_error(*this, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Unable to create a new reflection view resource");
- }
-
- // Populate the default reflection view properties
- matrix4 const identity_matrix;
- SetReflectionViewViewMatrix(object_id, identity_matrix);
- SetReflectionViewProjectionMatrix(object_id, identity_matrix);
- }
-
- /**
- Creates a new object.
-
- \param object_id The identifier of the new object.
- */
- template
- void Context::CreateObject(std::uint64_t& object_id)
- {
- (void)object_id;
-
- static_assert(0, "An unsupported resource type was supplied");
- }
-
- /**
- Gets the index of the current frame.
-
- \return The index of the current frame.
- */
- std::uint32_t& Context::GetFrameIndex()
- {
- return frame_index_;
- }
-
- /**
- Gets the index of the current frame.
-
- \return The index of the current frame.
- */
- std::uint32_t Context::GetFrameIndex() const
- {
- return frame_index_;
- }
-
- /**
- Gets the number of frames before memory can be re-used.
-
- \return The number of frames before memory can be re-used.
- */
- std::uint32_t Context::GetFrameCountBeforeReuse() const
- {
- return frame_count_before_reuse_;
- }
-
- /**
- Checks whether the object is of the given type.
-
- \param object_id The identifier of the object to be checked.
- \return true if the object is of the given type, false otherwise.
- */
- template
- bool Context::IsOfType(std::uint64_t object_id) const
- {
- return (GetResourceType(object_id) == RESOURCE_TYPE ? true : false);
- }
-
- /**
- Gets the number of objects for the given type.
-
- \return The number of created objects.
- */
- template
- std::uint32_t Context::GetObjectCount() const
- {
- switch (RESOURCE_TYPE)
- {
- case kResourceType_ReflectionView:
- return reflection_view_id_dispenser_.GetIdCount();
- default:
- {
- FFX_SSSR_ASSERT(0); // should never happen
- }
- break;
- }
-
- return 0u;
- }
-
- /**
- Gets the maximum number of objects for the given type.
-
- \return The maximum number of objects.
- */
- template
- std::uint32_t Context::GetMaxObjectCount() const
- {
- switch (RESOURCE_TYPE)
- {
- case kResourceType_ReflectionView:
- return reflection_view_id_dispenser_.GetMaxIdCount();
- default:
- {
- FFX_SSSR_ASSERT(0); // should never happen
- }
- break;
- }
-
- return 0u;
- }
-
- /**
- Gets the Direct3D12 context.
-
- \return The Direct3D12 context.
- */
- ContextD3D12* Context::GetContextD3D12()
- {
-#ifdef FFX_SSSR_D3D12
- return context_d3d12_.get();
-#endif // FFX_SSSR_D3D12
-
- return nullptr;
- }
-
- /**
- Gets the Direct3D12 context.
-
- \return The Direct3D12 context.
- */
- ContextD3D12 const* Context::GetContextD3D12() const
- {
-#ifdef FFX_SSSR_D3D12
- return context_d3d12_.get();
-#endif // FFX_SSSR_D3D12
-
- return nullptr;
- }
-
- /**
- Gets the Vulkan context.
-
- \return The Vulkan context.
- */
- inline ContextVK * Context::GetContextVK()
- {
-#ifdef FFX_SSSR_VK
- return context_vk_.get();
-#endif // FFX_SSSR_VK
-
- return nullptr;
- }
-
- /**
- Gets the Vulkan context.
-
- \return The Vulkan context.
- */
- inline ContextVK const * Context::GetContextVK() const
- {
-#ifdef FFX_SSSR_VK
- return context_vk_.get();
-#endif // FFX_SSSR_VK
-
- return nullptr;
- }
-
- /**
- Gets the current API call.
-
- \return The current API call.
- */
- char const* Context::GetAPICall() const
- {
- return (api_call_ ? api_call_ : "");
- }
-
- /**
- Sets the current API call.
-
- \param api_call The current API call.
- */
- void Context::SetAPICall(char const* api_call)
- {
- api_call_ = api_call;
- }
-
- /**
- Gets the error name.
-
- \param error The error code to be queried.
- \return The name corresponding to the error code.
- */
- char const* Context::GetErrorName(FfxSssrStatus error)
- {
- switch (error)
- {
- case FFX_SSSR_STATUS_OK:
- return "OK";
- case FFX_SSSR_STATUS_INVALID_VALUE:
- return "Invalid value";
- case FFX_SSSR_STATUS_INVALID_OPERATION:
- return "Invalid operation";
- case FFX_SSSR_STATUS_OUT_OF_MEMORY:
- return "Out of memory";
- case FFX_SSSR_STATUS_INCOMPATIBLE_API:
- return "Incompatible API";
- case FFX_SSSR_STATUS_INTERNAL_ERROR:
- return "Internal error";
- default:
- break;
- }
-
- return "";
- }
-
- /**
- Signals the error.
-
- \param error The error to be signalled.
- \param format The format for the error message.
- \param ... The content of the error message.
- */
- void Context::Error(FfxSssrStatus error, char const* format, ...) const
- {
- va_list args;
- va_start(args, format);
- Error(error, format, args);
- va_end(args);
- }
-
- /**
- Signals the error.
-
- \param error The error to be signalled.
- \param format The format for the error message.
- \param args The content of the error message.
- */
- void Context::Error(FfxSssrStatus error, char const* format, va_list args) const
- {
- char buffer[2048], message[2048];
-
- if (logging_function_)
- {
- snprintf(buffer, sizeof(buffer), "%s: %s (%d: %s)", GetAPICall(), format, static_cast(error), GetErrorName(error));
- vsnprintf(message, sizeof(message), buffer, args);
- logging_function_(message, logging_function_user_data_);
- }
- }
-
- /**
- Advances the frame index.
- */
- void Context::AdvanceToNextFrame()
- {
- ++frame_index_;
- }
-
- /**
- Gets the view matrix for the reflection view.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param view_matrix The output value for the view matrix.
- */
- void Context::GetReflectionViewViewMatrix(std::uint64_t reflection_view_id, matrix4& view_matrix) const
- {
- FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id));
-
- auto const reflection_view_view_matrix = reflection_view_view_matrices_.At(ID(reflection_view_id));
-
- FFX_SSSR_ASSERT(reflection_view_view_matrix); // should never happen
-
- view_matrix = *reflection_view_view_matrix;
- }
-
- /**
- Sets the view matrix for the reflection view.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param view_matrix The input value for the view matrix.
- */
- void Context::SetReflectionViewViewMatrix(std::uint64_t reflection_view_id, matrix4 const& view_matrix)
- {
- FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id));
-
- reflection_view_view_matrices_.Insert(ID(reflection_view_id), view_matrix);
- }
-
- /**
- Gets the projection matrix for the reflection view.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param projection_matrix The output value for the projection matrix.
- */
- void Context::GetReflectionViewProjectionMatrix(std::uint64_t reflection_view_id, matrix4& projection_matrix) const
- {
- FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id));
-
- auto const reflection_view_projection_matrix = reflection_view_projection_matrices_.At(ID(reflection_view_id));
-
- FFX_SSSR_ASSERT(reflection_view_projection_matrix); // should never happen
-
- projection_matrix = *reflection_view_projection_matrix;
- }
-
- /**
- Sets the projection matrix for the reflection view.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param projection_matrix The input value for the projection matrix.
- */
- void Context::SetReflectionViewProjectionMatrix(std::uint64_t reflection_view_id, matrix4 const& projection_matrix)
- {
- FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id));
-
- reflection_view_projection_matrices_.Insert(ID(reflection_view_id), projection_matrix);
- }
-
- /**
- Decodes the resource type from the object identifier.
-
- \param object_id The object identifier to be decoded.
- \return The resource type corresponding to the object.
- */
- ResourceType Context::GetResourceType(std::uint64_t object_id)
- {
- auto const resource_type = static_cast(object_id >> 48);
-
- return static_cast(std::min(resource_type - 1u, static_cast(kResourceType_Count)));
- }
-
- /**
- Encodes the resource type into the object identifier.
-
- \param object_id The object identifier to be encoded.
- \param resource_type The resource type for the object.
- */
- void Context::SetResourceType(std::uint64_t& object_id, ResourceType resource_type)
- {
- FFX_SSSR_ASSERT(resource_type < kResourceType_Count);
-
- object_id |= ((static_cast(resource_type) + 1ull) << 48);
- }
-
- /**
- Creates a new object.
-
- \param object_id The identifier of the new object.
- \param resource_type The resource type of the new object.
- \param id_dispenser The dispenser for allocating the object identifier.
- \return true if the object was created properly, false otherwise.
- */
- bool Context::CreateObject(std::uint64_t& object_id, ResourceType resource_type, IdDispenser& id_dispenser)
- {
- FFX_SSSR_ASSERT(resource_type < kResourceType_Count);
-
- if (!id_dispenser.AllocateId(object_id))
- {
- return false;
- }
-
- SetResourceType(object_id, resource_type);
-
- return true;
- }
-}
diff --git a/ffx-sssr/src/d3d12/context_d3d12.cpp b/ffx-sssr/src/d3d12/context_d3d12.cpp
deleted file mode 100644
index 1c550f1..0000000
--- a/ffx-sssr/src/d3d12/context_d3d12.cpp
+++ /dev/null
@@ -1,856 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#include "context_d3d12.h"
-
-#include
-#include
-
-#include "utils.h"
-#include "context.h"
-#include "reflection_view.h"
-#include "ffx_sssr_d3d12.h"
-
-#include "shader_common.h"
-#include "shader_classify_tiles.h"
-#include "shader_intersect.h"
-#include "shader_prepare_indirect_args.h"
-#include "shader_resolve_eaw.h"
-#include "shader_resolve_spatial.h"
-#include "shader_resolve_temporal.h"
-
-namespace
-{
- auto constexpr D3D12_VENDOR_ID_AMD = 0x1002u;
- auto constexpr D3D12_VENDOR_ID_INTEL = 0x8086u;
- auto constexpr D3D12_VENDOR_ID_NVIDIA = 0x10DEu;
-
-
- namespace _1
- {
- #include "samplerBlueNoiseErrorDistribution_128x128_OptimizedFor_2d2d2d2d_1spp.cpp"
- }
-
- namespace _2
- {
- #include "samplerBlueNoiseErrorDistribution_128x128_OptimizedFor_2d2d2d2d_2spp.cpp"
- }
-
- /**
- The available blue noise samplers for various sampling modes.
- */
- struct
- {
- std::int32_t const (&sobol_buffer_)[256 * 256];
- std::int32_t const (&ranking_tile_buffer_)[128 * 128 * 8];
- std::int32_t const (&scrambling_tile_buffer_)[128 * 128 * 8];
- }
- const g_sampler_states[] =
- {
- { _1::sobol_256spp_256d, _1::rankingTile, _1::scramblingTile },
- { _2::sobol_256spp_256d, _2::rankingTile, _2::scramblingTile },
- };
-
- /**
- Initializes the descriptor range.
-
- \param range_type The type of the descriptor range.
- \param num_descriptors The number of descriptors in the range.
- \param base_shader_register The base descriptor for the range in shader code.
- \return The resulting descriptor range.
- */
- inline D3D12_DESCRIPTOR_RANGE InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE range_type, std::uint32_t num_descriptors, std::uint32_t base_shader_register)
- {
- D3D12_DESCRIPTOR_RANGE descriptor_range = {};
- descriptor_range.RangeType = range_type;
- descriptor_range.NumDescriptors = num_descriptors;
- descriptor_range.BaseShaderRegister = base_shader_register;
- descriptor_range.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
- return descriptor_range;
- }
-
- /**
- Initializes the root parameter as descriptor table.
-
- \param num_descriptor_ranges The number of descriptor ranges for this parameter.
- \param descriptor_ranges The array of descriptor ranges for this parameter.
- \return The resulting root parameter.
- */
- inline D3D12_ROOT_PARAMETER InitAsDescriptorTable(std::uint32_t num_descriptor_ranges, D3D12_DESCRIPTOR_RANGE const* descriptor_ranges)
- {
- D3D12_ROOT_PARAMETER root_parameter = {};
- root_parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
- root_parameter.DescriptorTable.NumDescriptorRanges = num_descriptor_ranges;
- root_parameter.DescriptorTable.pDescriptorRanges = descriptor_ranges;
- root_parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; // CS
- return root_parameter;
- }
-
- /**
- Initializes the root parameter as constant buffer view.
-
- \param shader_register The slot of this constant buffer view.
- \return The resulting root parameter.
- */
- inline D3D12_ROOT_PARAMETER InitAsConstantBufferView(std::uint32_t shader_register)
- {
- D3D12_ROOT_PARAMETER root_parameter = {};
- root_parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
- root_parameter.Descriptor.RegisterSpace = 0;
- root_parameter.Descriptor.ShaderRegister = shader_register;
- root_parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; // CS
- return root_parameter;
- }
-
- /**
- Initializes a linear sampler for a static sampler description.
-
- \param shader_register The slot of this sampler.
- \return The resulting sampler description.
- */
- inline D3D12_STATIC_SAMPLER_DESC InitLinearSampler(std::uint32_t shader_register)
- {
- D3D12_STATIC_SAMPLER_DESC samplerDesc = {};
- samplerDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
- samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
- samplerDesc.BorderColor = D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK;
- samplerDesc.MinLOD = 0.0f;
- samplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
- samplerDesc.MipLODBias = 0;
- samplerDesc.MaxAnisotropy = 1;
- samplerDesc.ShaderRegister = shader_register;
- samplerDesc.RegisterSpace = 0;
- samplerDesc.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; // Compute
- return samplerDesc;
- }
-}
-
-namespace ffx_sssr
-{
- /**
- The constructor for the ContextD3D12 class.
-
- \param context The execution context.
- \param create_context_info The context creation information.
- */
- ContextD3D12::ContextD3D12(Context& context, FfxSssrCreateContextInfo const& create_context_info) :
- context_(context)
- , device_(GetValidDevice(context, create_context_info.pD3D12CreateContextInfo->pDevice))
- , shader_compiler_(context)
- , samplers_were_populated_(false)
- , upload_buffer_(*this, create_context_info.uploadBufferSize)
- , tile_classification_pass_()
- , indirect_args_pass_()
- , intersection_pass_()
- , spatial_denoising_pass_()
- , temporal_denoising_pass_()
- , eaw_denoising_pass_()
- , indirect_dispatch_command_signature_(nullptr)
- , reflection_views_(create_context_info.maxReflectionViewCount)
- {
- FFX_SSSR_ASSERT(device_ != nullptr);
- CompileShaders(create_context_info);
- CreateRootSignatures();
- CreatePipelineStates();
-
- // Create command signature for indirect arguments
- {
- D3D12_INDIRECT_ARGUMENT_DESC dispatch = {};
- dispatch.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH;
-
- D3D12_COMMAND_SIGNATURE_DESC desc = {};
- desc.ByteStride = sizeof(D3D12_DISPATCH_ARGUMENTS);
- desc.NodeMask = 0;
- desc.NumArgumentDescs = 1;
- desc.pArgumentDescs = &dispatch;
-
- HRESULT hr;
- hr = device_->CreateCommandSignature(&desc, nullptr, IID_PPV_ARGS(&indirect_dispatch_command_signature_));
- if (!SUCCEEDED(hr))
- {
- throw reflection_error(context, FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to create command signature for indirect dispatch.");
- }
- }
-
- // Create our blue noise samplers
- BlueNoiseSamplerD3D12* blue_noise_samplers[] = { &blue_noise_sampler_1spp_, &blue_noise_sampler_2spp_ };
- static_assert(FFX_SSSR_ARRAY_SIZE(blue_noise_samplers) == FFX_SSSR_ARRAY_SIZE(g_sampler_states), "Sampler arrays don't match.");
- for (auto i = 0u; i < FFX_SSSR_ARRAY_SIZE(g_sampler_states); ++i)
- {
- auto const& sampler_state = g_sampler_states[i];
- BlueNoiseSamplerD3D12* sampler = blue_noise_samplers[i];
-
- if (!AllocateSRVBuffer(sizeof(sampler_state.sobol_buffer_),
- &sampler->sobol_buffer_,
- D3D12_RESOURCE_STATE_COPY_DEST,
- L"SSSR Sobol Buffer") ||
- !AllocateSRVBuffer(sizeof(sampler_state.ranking_tile_buffer_),
- &sampler->ranking_tile_buffer_,
- D3D12_RESOURCE_STATE_COPY_DEST,
- L"SSSR Ranking Tile Buffer") ||
- !AllocateSRVBuffer(sizeof(sampler_state.scrambling_tile_buffer_),
- &sampler->scrambling_tile_buffer_,
- D3D12_RESOURCE_STATE_COPY_DEST,
- L"SSSR Scrambling Tile Buffer"))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Unable to create SRV buffer(s) for sampler.");
- }
- }
-
- ID3D12GraphicsCommandList * command_list = create_context_info.pD3D12CreateContextInfo->pUploadCommandList;
- if (!samplers_were_populated_)
- {
- std::int32_t* upload_buffer;
-
- // Upload the relevant data to the various samplers
- for (auto i = 0u; i < FFX_SSSR_ARRAY_SIZE(g_sampler_states); ++i)
- {
- auto const& sampler_state = g_sampler_states[i];
- BlueNoiseSamplerD3D12* sampler = blue_noise_samplers[i];
-
- FFX_SSSR_ASSERT(sampler->sobol_buffer_);
- FFX_SSSR_ASSERT(sampler->ranking_tile_buffer_);
- FFX_SSSR_ASSERT(sampler->scrambling_tile_buffer_);
-
- if (!upload_buffer_.AllocateBuffer(sizeof(sampler_state.sobol_buffer_), upload_buffer))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %llukiB of upload memory, consider increasing uploadBufferSize", RoundedDivide(sizeof(sampler_state.sobol_buffer_), 1024ull));
- }
- memcpy(upload_buffer, sampler_state.sobol_buffer_, sizeof(sampler_state.sobol_buffer_));
-
- command_list->CopyBufferRegion(sampler->sobol_buffer_,
- 0ull,
- upload_buffer_.GetResource(),
- static_cast(upload_buffer_.GetOffset(upload_buffer)),
- sizeof(sampler_state.sobol_buffer_));
-
- if (!upload_buffer_.AllocateBuffer(sizeof(sampler_state.ranking_tile_buffer_), upload_buffer))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %llukiB of upload memory, consider increasing uploadBufferSize", RoundedDivide(sizeof(sampler_state.ranking_tile_buffer_), 1024ull));
- }
- memcpy(upload_buffer, sampler_state.ranking_tile_buffer_, sizeof(sampler_state.ranking_tile_buffer_));
-
- command_list->CopyBufferRegion(sampler->ranking_tile_buffer_,
- 0ull,
- upload_buffer_.GetResource(),
- static_cast(upload_buffer_.GetOffset(upload_buffer)),
- sizeof(sampler_state.ranking_tile_buffer_));
-
- if (!upload_buffer_.AllocateBuffer(sizeof(sampler_state.scrambling_tile_buffer_), upload_buffer))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %llukiB of upload memory, consider increasing uploadBufferSize", RoundedDivide(sizeof(sampler_state.scrambling_tile_buffer_), 1024ull));
- }
- memcpy(upload_buffer, sampler_state.scrambling_tile_buffer_, sizeof(sampler_state.scrambling_tile_buffer_));
-
- command_list->CopyBufferRegion(sampler->scrambling_tile_buffer_,
- 0ull,
- upload_buffer_.GetResource(),
- static_cast(upload_buffer_.GetOffset(upload_buffer)),
- sizeof(sampler_state.scrambling_tile_buffer_));
- }
-
- // Transition the resources for usage
- D3D12_RESOURCE_BARRIER resource_barriers[3 * FFX_SSSR_ARRAY_SIZE(g_sampler_states)];
- memset(resource_barriers, 0, sizeof(resource_barriers));
-
- for (auto i = 0u; i < FFX_SSSR_ARRAY_SIZE(g_sampler_states); ++i)
- {
- BlueNoiseSamplerD3D12* sampler = blue_noise_samplers[i];
-
- auto& sobol_buffer_resource_barrier = resource_barriers[3u * i + 0u];
- sobol_buffer_resource_barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
- sobol_buffer_resource_barrier.Transition.pResource = sampler->sobol_buffer_;
- sobol_buffer_resource_barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
- sobol_buffer_resource_barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- sobol_buffer_resource_barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
-
- auto& ranking_tile_buffer_resource_barrier = resource_barriers[3u * i + 1u];
- ranking_tile_buffer_resource_barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
- ranking_tile_buffer_resource_barrier.Transition.pResource = sampler->ranking_tile_buffer_;
- ranking_tile_buffer_resource_barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
- ranking_tile_buffer_resource_barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- ranking_tile_buffer_resource_barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
-
- auto& scrambling_tile_buffer_resource_barrier = resource_barriers[3u * i + 2u];
- scrambling_tile_buffer_resource_barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
- scrambling_tile_buffer_resource_barrier.Transition.pResource = sampler->scrambling_tile_buffer_;
- scrambling_tile_buffer_resource_barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
- scrambling_tile_buffer_resource_barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- scrambling_tile_buffer_resource_barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
- }
-
- command_list->ResourceBarrier(FFX_SSSR_ARRAY_SIZE(resource_barriers),
- resource_barriers);
-
- // Flag that the samplers are now ready to use
- samplers_were_populated_ = true;
- }
- }
-
- /**
- The destructor for the ContextD3D12 class.
- */
- ContextD3D12::~ContextD3D12()
- {
- if (indirect_dispatch_command_signature_)
- indirect_dispatch_command_signature_->Release();
- indirect_dispatch_command_signature_ = nullptr;
- }
-
- /**
- Gets the number of GPU ticks spent in the tile classification pass.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param elapsed_time The number of GPU ticks spent in the tile classification pass.
- */
- void ContextD3D12::GetReflectionViewTileClassificationElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const
- {
- FFX_SSSR_ASSERT(reflection_views_.At(ID(reflection_view_id))); // not created properly?
- FFX_SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id));
-
- auto const& reflection_view = reflection_views_[ID(reflection_view_id)];
-
- if (!((reflection_view.flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_OPERATION, "Cannot query the tile classification elapsed time of a reflection view that was not created with the FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag");
- }
-
- elapsed_time = reflection_view.tile_classification_elapsed_time_;
- }
-
- /**
- Gets the number of GPU ticks spent intersecting the depth buffer.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param elapsed_time The number of GPU ticks spent intersecting the depth buffer.
- */
- void ContextD3D12::GetReflectionViewIntersectionElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const
- {
- FFX_SSSR_ASSERT(reflection_views_.At(ID(reflection_view_id))); // not created properly?
- FFX_SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id));
-
- auto const& reflection_view = reflection_views_[ID(reflection_view_id)];
-
- if (!((reflection_view.flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_OPERATION, "Cannot query the intersection elapsed time of a reflection view that was not created with the FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag");
- }
-
- elapsed_time = reflection_view.intersection_elapsed_time_;
- }
-
- /**
- Gets the number of GPU ticks spent denoising the Direct3D12 reflection view.
-
- \param reflection_view_id The identifier for the reflection view object.
- \param elapsed_time The number of GPU ticks spent denoising.
- */
- void ContextD3D12::GetReflectionViewDenoisingElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const
- {
- FFX_SSSR_ASSERT(reflection_views_.At(ID(reflection_view_id))); // not created properly?
- FFX_SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id));
-
- auto const& reflection_view = reflection_views_[ID(reflection_view_id)];
-
- if (!((reflection_view.flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_OPERATION, "Cannot query the denoising elapsed time of a reflection view that was not created with the FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag");
- }
-
- elapsed_time = reflection_view.denoising_elapsed_time_;
- }
-
- /**
- Creates the Direct3D12 reflection view.
-
- \param reflection_view_id The identifier of the reflection view object.
- \param create_reflection_view_info The reflection view creation information.
- */
- void ContextD3D12::CreateReflectionView(std::uint64_t reflection_view_id, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info)
- {
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo);
- FFX_SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id));
-
- // Check user arguments
- if (!create_reflection_view_info.outputWidth || !create_reflection_view_info.outputHeight)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The outputWidth and outputHeight parameters are required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->depthBufferHierarchySRV.ptr)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The depthBufferHierarchySRV parameter is required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->motionBufferSRV.ptr)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The motionBufferSRV parameter is required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->normalBufferSRV.ptr)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The normalBufferSRV parameter is required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->roughnessBufferSRV.ptr)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The roughnessBufferSRV parameter is required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->normalHistoryBufferSRV.ptr)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The normalHistoryBufferSRV parameter is required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->roughnessHistoryBufferSRV.ptr)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The roughnessHistoryBufferSRV parameter is required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->reflectionViewUAV.ptr)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The reflectionViewUAV parameter is required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->environmentMapSRV.ptr)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The environmentMapSRV parameter is required when creating a reflection view");
- if (!create_reflection_view_info.pD3D12CreateReflectionViewInfo->pEnvironmentMapSamplerDesc)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The pEnvironmentMapSamplerDesc parameter is required when creating a reflection view");
- if(create_reflection_view_info.pD3D12CreateReflectionViewInfo->sceneFormat == DXGI_FORMAT_UNKNOWN)
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_VALUE, "The sceneFormat parameter is required when creating a reflection view");
-
- // Create the reflection view
- auto& reflection_view = reflection_views_.Insert(ID(reflection_view_id));
- reflection_view.Create(context_, create_reflection_view_info);
- }
-
- /**
- Resolves the Direct3D12 reflection view.
-
- \param reflection_view_id The identifier of the reflection view object.
- \param resolve_reflection_view_info The reflection view resolve information.
- */
- void ContextD3D12::ResolveReflectionView(std::uint64_t reflection_view_id, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info)
- {
- FFX_SSSR_ASSERT(reflection_views_.At(ID(reflection_view_id))); // not created properly?
- FFX_SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id));
- FFX_SSSR_ASSERT(context_.reflection_view_view_matrices_.At(ID(reflection_view_id)));
- FFX_SSSR_ASSERT(context_.reflection_view_projection_matrices_.At(ID(reflection_view_id)));
-
- ReflectionView reflection_view;
- reflection_view.view_matrix_ = context_.reflection_view_view_matrices_[ID(reflection_view_id)];
- reflection_view.projection_matrix_ = context_.reflection_view_projection_matrices_[ID(reflection_view_id)];
-
- reflection_views_[ID(reflection_view_id)].Resolve(context_, reflection_view, resolve_reflection_view_info);
- }
-
- void ContextD3D12::CompileShaders(FfxSssrCreateContextInfo const& create_context_info)
- {
- struct
- {
- char const* shader_name_ = nullptr;
- char const* content_ = nullptr;
- char const* profile_ = nullptr;
- }
- const shader_source[] =
- {
- { "prepare_indirect_args", prepare_indirect_args, "cs_6_0"},
- { "classify_tiles", classify_tiles, "cs_6_0"},
- { "intersect", intersect, "cs_6_0"},
- { "resolve_spatial", resolve_spatial, "cs_6_0"},
- { "resolve_temporal", resolve_temporal, "cs_6_0"},
- { "resolve_eaw", resolve_eaw, "cs_6_0"},
- };
-
- auto const common_include = std::string(common);
-
- DxcDefine defines[10];
- defines[0].Name = L"FFX_SSSR_ROUGHNESS_TEXTURE_FORMAT";
- defines[0].Value = create_context_info.pRoughnessTextureFormat;
- defines[1].Name = L"FFX_SSSR_ROUGHNESS_UNPACK_FUNCTION";
- defines[1].Value = create_context_info.pUnpackRoughnessSnippet;
- defines[2].Name = L"FFX_SSSR_NORMALS_TEXTURE_FORMAT";
- defines[2].Value = create_context_info.pNormalsTextureFormat;
- defines[3].Name = L"FFX_SSSR_NORMALS_UNPACK_FUNCTION";
- defines[3].Value = create_context_info.pUnpackNormalsSnippet;
- defines[4].Name = L"FFX_SSSR_MOTION_VECTOR_TEXTURE_FORMAT";
- defines[4].Value = create_context_info.pMotionVectorFormat;
- defines[5].Name = L"FFX_SSSR_MOTION_VECTOR_UNPACK_FUNCTION";
- defines[5].Value = create_context_info.pUnpackMotionVectorsSnippet;
- defines[6].Name = L"FFX_SSSR_DEPTH_TEXTURE_FORMAT";
- defines[6].Value = create_context_info.pDepthTextureFormat;
- defines[7].Name = L"FFX_SSSR_DEPTH_UNPACK_FUNCTION";
- defines[7].Value = create_context_info.pUnpackDepthSnippet;
- defines[8].Name = L"FFX_SSSR_SCENE_TEXTURE_FORMAT";
- defines[8].Value = create_context_info.pSceneTextureFormat;
- defines[9].Name = L"FFX_SSSR_SCENE_RADIANCE_UNPACK_FUNCTION";
- defines[9].Value = create_context_info.pUnpackSceneRadianceSnippet;
-
- static_assert(FFX_SSSR_ARRAY_SIZE(shader_source) == kShader_Count, "'kShader_Count' filenames must be provided for building the various shaders");
- std::stringstream shader_content;
- for (auto i = 0u; i < kShader_Count; ++i)
- {
- // Append common includes
- shader_content.str(std::string());
- shader_content.clear();
- shader_content << common << std::endl << shader_source[i].content_;
-
- shaders_[i] = shader_compiler_.CompileShaderString(
- shader_content.str().c_str(),
- static_cast(shader_content.str().size()),
- shader_source[i].shader_name_,
- shader_source[i].profile_,
- nullptr, 0,
- defines, FFX_SSSR_ARRAY_SIZE(defines));
- }
- }
-
- void ContextD3D12::CreateRootSignatures()
- {
- auto CreateRootSignature = [this](
- ShaderPass& pass
- , const LPCWSTR name
- , std::uint32_t num_descriptor_ranges
- , D3D12_DESCRIPTOR_RANGE const* descriptor_ranges
- ) {
-
- D3D12_DESCRIPTOR_RANGE environment_map_sampler_range = {};
- environment_map_sampler_range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
- environment_map_sampler_range.NumDescriptors = 1;
- environment_map_sampler_range.BaseShaderRegister = 1;
- environment_map_sampler_range.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
-
- D3D12_ROOT_PARAMETER root[] = {
- InitAsDescriptorTable(num_descriptor_ranges, descriptor_ranges),
- InitAsConstantBufferView(0),
- InitAsDescriptorTable(1, &environment_map_sampler_range), // g_environment_map_sampler
- };
-
- D3D12_STATIC_SAMPLER_DESC sampler_descs[] = { InitLinearSampler(0) }; // g_linear_sampler
-
- D3D12_ROOT_SIGNATURE_DESC rs_desc = {};
- rs_desc.NumParameters = FFX_SSSR_ARRAY_SIZE(root);
- rs_desc.pParameters = root;
- rs_desc.NumStaticSamplers = FFX_SSSR_ARRAY_SIZE(sampler_descs);
- rs_desc.pStaticSamplers = sampler_descs;
-
- HRESULT hr;
- ID3DBlob* rs, * rsError;
- hr = D3D12SerializeRootSignature(&rs_desc, D3D_ROOT_SIGNATURE_VERSION_1, &rs, &rsError);
- if (FAILED(hr))
- {
- if (rsError)
- {
- std::string const error_message(static_cast(rsError->GetBufferPointer()));
- rsError->Release();
- throw reflection_error(GetContext(), FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to serialize root signature:\r\n> %s", error_message.c_str());
- }
- else
- {
- throw reflection_error(GetContext(), FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to serialize root signature");
- }
- }
-
- hr = GetDevice()->CreateRootSignature(0, rs->GetBufferPointer(), rs->GetBufferSize(), IID_PPV_ARGS(&pass.root_signature_));
- rs->Release();
- if (FAILED(hr))
- {
- throw reflection_error(GetContext(), FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to create root signature.");
- }
-
- pass.root_signature_->SetName(name);
- pass.descriptor_count_ = num_descriptor_ranges;
- };
-
- // Assemble the shader pass for tile classification
- {
- D3D12_DESCRIPTOR_RANGE ranges[] = {
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0), // g_roughness
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0), // g_tile_list
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1), // g_ray_list
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 2), // g_tile_counter
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 3), // g_ray_counter
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 4), // g_temporally_denoised_reflections
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 5), // g_temporally_denoised_reflections_history
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 6), // g_ray_lengths
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 7), // g_temporal_variance
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 8), // g_denoised_reflections
- };
- CreateRootSignature(tile_classification_pass_, L"SSSR Tile Classification Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges);
- }
-
- // Assemble the shader pass that prepares the indirect arguments
- {
- D3D12_DESCRIPTOR_RANGE ranges[] = {
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0), // g_tile_counter
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1), // g_ray_counter
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 2), // g_intersect_args
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 3), // g_denoiser_args
- };
- CreateRootSignature(indirect_args_pass_, L"SSSR Indirect Arguments Pass Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges);
- }
-
- // Assemble the shader pass for intersecting reflection rays with the depth buffer
- {
- D3D12_DESCRIPTOR_RANGE ranges[] = {
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0), // g_lit_scene
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1), // g_depth_buffer_hierarchy
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 2), // g_normal
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 3), // g_roughness
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 4), // g_environment_map
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 5), // g_sobol_buffer
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 6), // g_ranking_tile_buffer
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 7), // g_scrambling_tile_buffer
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 8), // g_ray_list
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0), // g_intersection_result
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1), // g_ray_lengths
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 2), // g_denoised_reflections
-
- };
- CreateRootSignature(intersection_pass_, L"SSSR Depth Buffer Intersection Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges);
- }
-
- // Assemble the shader pass for spatial resolve
- {
- D3D12_DESCRIPTOR_RANGE ranges[] = {
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0), // g_depth_buffer
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1), // g_normal
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 2), // g_roughness
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 3), // g_intersection_result
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 4), // g_has_ray
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 5), // g_tile_list
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0), // g_spatially_denoised_reflections
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1), // g_ray_lengths
- };
- CreateRootSignature(spatial_denoising_pass_, L"SSSR Spatial Resolve Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges);
- }
-
- // Assemble the shader pass for temporal resolve
- {
- D3D12_DESCRIPTOR_RANGE ranges[] = {
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0), // g_normal
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1), // g_roughness
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 2), // g_normal_history
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 3), // g_roughness_history
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 4), // g_depth_buffer
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 5), // g_motion_vectors
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 6), // g_temporally_denoised_reflections_history
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 7), // g_ray_lengths
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 8), // g_tile_list
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0), // g_temporally_denoised_reflections
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1), // g_spatially_denoised_reflections
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 2), // g_temporal_variance
- };
- CreateRootSignature(temporal_denoising_pass_, L"SSSR Temporal Resolve Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges);
- }
-
- // Assemble the shader pass for EAW resolve
- {
- D3D12_DESCRIPTOR_RANGE ranges[] = {
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0), // g_normal
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 1), // g_roughness
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 2), // g_depth_buffer
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 3), // g_tile_list
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0), // g_temporally_denoised_reflections
- InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1), // g_denoised_reflections
- };
- CreateRootSignature(eaw_denoising_pass_, L"SSSR EAW Resolve Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges);
- }
- }
-
- void ContextD3D12::CreatePipelineStates()
- {
- auto Compile = [this](ShaderPass& pass, ContextD3D12::Shader shader, const LPCWSTR name) {
- FFX_SSSR_ASSERT(pass.root_signature_ != nullptr);
-
- // Create the pipeline state object
- D3D12_COMPUTE_PIPELINE_STATE_DESC pipeline_state_desc = {};
- pipeline_state_desc.pRootSignature = pass.root_signature_;
- pipeline_state_desc.CS = GetShader(shader);
-
- HRESULT hr = GetDevice()->CreateComputePipelineState(&pipeline_state_desc,
- IID_PPV_ARGS(&pass.pipeline_state_));
- if (!SUCCEEDED(hr))
- {
- throw reflection_error(GetContext(), FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to create compute pipeline state");
- }
-
- pass.pipeline_state_->SetName(name);
- };
-
- Compile(tile_classification_pass_, ContextD3D12::kShader_TileClassification, L"SSSR Tile Classification Pipeline");
- Compile(indirect_args_pass_, ContextD3D12::kShader_IndirectArguments, L"SSSR Indirect Arguments Pipeline");
- Compile(intersection_pass_, ContextD3D12::kShader_Intersection, L"SSSR Intersect Pipeline");
- Compile(spatial_denoising_pass_, ContextD3D12::kShader_SpatialResolve, L"SSSR Spatial Resolve Pipeline");
- Compile(temporal_denoising_pass_, ContextD3D12::kShader_TemporalResolve, L"SSSR Temporal Resolve Pipeline");
- Compile(eaw_denoising_pass_, ContextD3D12::kShader_EAWResolve, L"SSSR EAW Resolve Pipeline");
- }
-
- const ContextD3D12::ShaderPass& ContextD3D12::GetTileClassificationPass() const
- {
- return tile_classification_pass_;
- }
-
- const ContextD3D12::ShaderPass& ContextD3D12::GetIndirectArgsPass() const
- {
- return indirect_args_pass_;
- }
-
- const ContextD3D12::ShaderPass& ContextD3D12::GetIntersectionPass() const
- {
- return intersection_pass_;
- }
-
- const ContextD3D12::ShaderPass& ContextD3D12::GetSpatialDenoisingPass() const
- {
- return spatial_denoising_pass_;
- }
-
- const ContextD3D12::ShaderPass& ContextD3D12::GetTemporalDenoisingPass() const
- {
- return temporal_denoising_pass_;
- }
-
- const ContextD3D12::ShaderPass& ContextD3D12::GetEawDenoisingPass() const
- {
- return eaw_denoising_pass_;
- }
-
- ID3D12CommandSignature* ContextD3D12::GetIndirectDispatchCommandSignature()
- {
- return indirect_dispatch_command_signature_;
- }
-
- /**
- Allocate a buffer resource to use as a shader resource view.
-
- \param buffer_size The size of the buffer (in bytes).
- \param resource The created SRV buffer resource.
- \param initial_resource_state The initial resource state.
- \param resource_name An optional name for the resource.
- \return true if the resource was allocated successfully.
- */
- bool ContextD3D12::AllocateSRVBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name) const
- {
- FFX_SSSR_ASSERT(resource != nullptr);
-
- D3D12_HEAP_PROPERTIES heap_properties = {};
- heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT;
- heap_properties.CreationNodeMask = 1u;
- heap_properties.VisibleNodeMask = 1u;
-
- D3D12_RESOURCE_DESC resource_desc = {};
- resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- resource_desc.Width = static_cast(buffer_size);
- resource_desc.Height = 1u;
- resource_desc.DepthOrArraySize = 1u;
- resource_desc.MipLevels = 1u;
- resource_desc.SampleDesc.Count = 1u;
- resource_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
-
- if (!SUCCEEDED(device_->CreateCommittedResource(&heap_properties,
- D3D12_HEAP_FLAG_NONE,
- &resource_desc,
- initial_resource_state,
- nullptr,
- IID_PPV_ARGS(resource))))
- {
- return false; // failed to create committed resource
- }
-
- if (resource_name)
- {
- (*resource)->SetName(resource_name);
- }
-
- return true;
- }
-
- /**
- Allocate a buffer resource to use as an unordered access view.
-
- \param buffer_size The size of the buffer (in bytes).
- \param resource The created UAV buffer resource.
- \param initial_resource_state The initial resource state.
- \param resource_name An optional name for the resource.
- \return true if the resource was allocated successfully.
- */
- bool ContextD3D12::AllocateUAVBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name) const
- {
- FFX_SSSR_ASSERT(resource != nullptr);
-
- D3D12_HEAP_PROPERTIES heap_properties = {};
- heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT;
- heap_properties.CreationNodeMask = 1u;
- heap_properties.VisibleNodeMask = 1u;
-
- D3D12_RESOURCE_DESC resource_desc = {};
- resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- resource_desc.Width = static_cast(buffer_size);
- resource_desc.Height = 1u;
- resource_desc.DepthOrArraySize = 1u;
- resource_desc.MipLevels = 1u;
- resource_desc.SampleDesc.Count = 1u;
- resource_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
- resource_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
-
- if (!SUCCEEDED(device_->CreateCommittedResource(&heap_properties,
- D3D12_HEAP_FLAG_NONE,
- &resource_desc,
- initial_resource_state,
- nullptr,
- IID_PPV_ARGS(resource))))
- {
- return false; // failed to create committed resource
- }
-
- if (resource_name)
- {
- (*resource)->SetName(resource_name);
- }
-
- return true;
- }
-
- /**
- Allocate a buffer resource to use as a readback resource.
-
- \param buffer_size The size of the buffer (in bytes).
- \param resource The created readback buffer resource.
- \param initial_resource_state The initial resource state.
- \param resource_name An optional name for the resource.
- \return true if the resource was allocated successfully.
- */
- bool ContextD3D12::AllocateReadbackBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name) const
- {
- FFX_SSSR_ASSERT(resource != nullptr);
-
- D3D12_HEAP_PROPERTIES heap_properties = {};
- heap_properties.Type = D3D12_HEAP_TYPE_READBACK;
- heap_properties.CreationNodeMask = 1u;
- heap_properties.VisibleNodeMask = 1u;
-
- D3D12_RESOURCE_DESC resource_desc = {};
- resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- resource_desc.Width = static_cast(buffer_size);
- resource_desc.Height = 1u;
- resource_desc.DepthOrArraySize = 1u;
- resource_desc.MipLevels = 1u;
- resource_desc.SampleDesc.Count = 1u;
- resource_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
-
- if (!SUCCEEDED(device_->CreateCommittedResource(&heap_properties,
- D3D12_HEAP_FLAG_NONE,
- &resource_desc,
- initial_resource_state,
- nullptr,
- IID_PPV_ARGS(resource))))
- {
- return false; // failed to create committed resource
- }
-
- if (resource_name)
- {
- (*resource)->SetName(resource_name);
- }
-
- return true;
- }
-}
diff --git a/ffx-sssr/src/d3d12/context_d3d12.h b/ffx-sssr/src/d3d12/context_d3d12.h
deleted file mode 100644
index 49fc0e7..0000000
--- a/ffx-sssr/src/d3d12/context_d3d12.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-#include
-#include
-
-#include "sampler_d3d12.h"
-#include "reflection_view_d3d12.h"
-#include "upload_buffer_d3d12.h"
-#include "shader_compiler_d3d12.h"
-
-namespace ffx_sssr
-{
- class Context;
- class ReflectionViewD3D12;
-
- /**
- The ContextD3D12 class encapsulates the data for a single Direct3D12 stochastic screen space reflections execution context.
- */
- class ContextD3D12
- {
- FFX_SSSR_NON_COPYABLE(ContextD3D12);
-
- public:
- /**
- The available shaders.
- */
- enum Shader
- {
- kShader_IndirectArguments,
- kShader_TileClassification,
- kShader_Intersection,
- kShader_SpatialResolve,
- kShader_TemporalResolve,
- kShader_EAWResolve,
-
- kShader_Count
- };
-
- ContextD3D12(Context& context, FfxSssrCreateContextInfo const& create_context_info);
- ~ContextD3D12();
-
- inline Context& GetContext();
- inline ID3D12Device* GetDevice() const;
- inline Context const& GetContext() const;
- inline UploadBufferD3D12& GetUploadBuffer();
-
- inline ShaderD3D12 const& GetShader(Shader shader) const;
- inline BlueNoiseSamplerD3D12 const& GetSampler1SPP() const;
- inline BlueNoiseSamplerD3D12 const& GetSampler2SPP() const;
-
- void GetReflectionViewTileClassificationElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const;
- void GetReflectionViewIntersectionElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const;
- void GetReflectionViewDenoisingElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const;
-
- void CreateReflectionView(std::uint64_t reflection_view_id, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info);
- void ResolveReflectionView(std::uint64_t reflection_view_id, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info);
-
- static inline ID3D12Device* GetValidDevice(Context& context, ID3D12Device* device);
- static inline ID3D12GraphicsCommandList* GetCommandList(Context& context, ID3D12GraphicsCommandList* command_list);
-
- protected:
- friend class Context;
- friend class ReflectionViewD3D12;
-
- /**
- The ShaderPass class holds the data for an individual shader pass.
- */
- class ShaderPass
- {
- FFX_SSSR_NON_COPYABLE(ShaderPass);
-
- public:
- inline ShaderPass();
- inline ~ShaderPass();
-
- inline operator bool() const;
-
- inline ShaderPass(ShaderPass&& other) noexcept;
- inline ShaderPass& operator =(ShaderPass&& other) noexcept;
-
- inline void SafeRelease();
-
- // The pipeline state object.
- ID3D12PipelineState* pipeline_state_;
- // The root signature to be used.
- ID3D12RootSignature* root_signature_;
- // The number of descriptors in the root signature.
- std::uint32_t descriptor_count_;
- };
-
- void CompileShaders(FfxSssrCreateContextInfo const& create_context_info);
- void CreateRootSignatures();
- void CreatePipelineStates();
-
- const ShaderPass& GetTileClassificationPass() const;
- const ShaderPass& GetIndirectArgsPass() const;
- const ShaderPass& GetIntersectionPass() const;
- const ShaderPass& GetSpatialDenoisingPass() const;
- const ShaderPass& GetTemporalDenoisingPass() const;
- const ShaderPass& GetEawDenoisingPass() const;
-
- ID3D12CommandSignature* GetIndirectDispatchCommandSignature();
-
- bool AllocateSRVBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name = nullptr) const;
- bool AllocateUAVBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name = nullptr) const;
- bool AllocateReadbackBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name = nullptr) const;
-
- // The execution context.
- Context& context_;
- // The device to be used.
- ID3D12Device* device_;
- // The compiled reflections shaders.
- std::array shaders_;
- // The compiler to be used for building the Direct3D12 shaders.
- ShaderCompilerD3D12 shader_compiler_;
- // The Blue Noise sampler optimized for 1 sample per pixel.
- BlueNoiseSamplerD3D12 blue_noise_sampler_1spp_;
- // The Blue Noise sampler optimized for 2 samples per pixel.
- BlueNoiseSamplerD3D12 blue_noise_sampler_2spp_;
- // The flag for whether the samplers were populated.
- bool samplers_were_populated_;
- // The buffer to be used for uploading memory from the CPU to the GPU.
- UploadBufferD3D12 upload_buffer_;
- // The array of reflection views to be resolved.
- SparseArray reflection_views_;
-
- // The shader pass that classifies tiles.
- ShaderPass tile_classification_pass_;
- // The shader pass that prepares the indirect arguments.
- ShaderPass indirect_args_pass_;
- // The shader pass intersecting reflection rays with the depth buffer.
- ShaderPass intersection_pass_;
- // The shader pass that does spatial denoising.
- ShaderPass spatial_denoising_pass_;
- // The shader pass that does temporal denoising.
- ShaderPass temporal_denoising_pass_;
- // The shader pass that does the second spatial denoising.
- ShaderPass eaw_denoising_pass_;
-
- // The command signature for the indirect dispatches.
- ID3D12CommandSignature* indirect_dispatch_command_signature_;
- };
-}
-
-#include "context_d3d12.inl"
diff --git a/ffx-sssr/src/d3d12/context_d3d12.inl b/ffx-sssr/src/d3d12/context_d3d12.inl
deleted file mode 100644
index a88bb65..0000000
--- a/ffx-sssr/src/d3d12/context_d3d12.inl
+++ /dev/null
@@ -1,225 +0,0 @@
-#include "context_d3d12.h"
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-namespace ffx_sssr
-{
-
- /**
- Gets the context.
-
- \return The context.
- */
- Context& ContextD3D12::GetContext()
- {
- return context_;
- }
-
- /**
- Gets the Direct3D12 device.
-
- \return The Direct3D12 device.
- */
- ID3D12Device* ContextD3D12::GetDevice() const
- {
- return device_;
- }
-
- /**
- Gets the context.
-
- \return The context.
- */
- Context const& ContextD3D12::GetContext() const
- {
- return context_;
- }
-
- /**
- Gets hold of the upload buffer.
-
- \return The upload buffer.
- */
- UploadBufferD3D12& ContextD3D12::GetUploadBuffer()
- {
- return upload_buffer_;
- }
-
- /**
- Gets the shader.
-
- \param shader The shader to be retrieved.
- \return The requested shader.
- */
- ShaderD3D12 const& ContextD3D12::GetShader(Shader shader) const
- {
- FFX_SSSR_ASSERT(shader < kShader_Count);
- return shaders_[shader];
- }
-
- /**
- Gets a blue noise sampler with 1 sample per pixel.
-
- \return The requested sampler.
- */
- inline BlueNoiseSamplerD3D12 const & ContextD3D12::GetSampler1SPP() const
- {
- FFX_SSSR_ASSERT(blue_noise_sampler_1spp_.sobol_buffer_);
- FFX_SSSR_ASSERT(blue_noise_sampler_1spp_.ranking_tile_buffer_);
- FFX_SSSR_ASSERT(blue_noise_sampler_1spp_.scrambling_tile_buffer_);
- return blue_noise_sampler_1spp_;
- }
-
- /**
- Gets a blue noise sampler with 2 samples per pixel.
-
- \return The requested sampler.
- */
- inline BlueNoiseSamplerD3D12 const & ContextD3D12::GetSampler2SPP() const
- {
- FFX_SSSR_ASSERT(blue_noise_sampler_2spp_.sobol_buffer_);
- FFX_SSSR_ASSERT(blue_noise_sampler_2spp_.ranking_tile_buffer_);
- FFX_SSSR_ASSERT(blue_noise_sampler_2spp_.scrambling_tile_buffer_);
- return blue_noise_sampler_2spp_;
- }
-
- /**
- Gets a valid device.
-
- \param context The context to be used.
- \param device The Direct3D12 device.
- \return The device.
- */
- ID3D12Device* ContextD3D12::GetValidDevice(Context& context, ID3D12Device* device)
- {
- if (!device)
- throw reflection_error(context, FFX_SSSR_STATUS_INVALID_VALUE, "No device was supplied.");
-
- D3D12_FEATURE_DATA_SHADER_MODEL supportedShaderModel = {};
- supportedShaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_2;
- HRESULT hr = device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &supportedShaderModel, sizeof(D3D12_FEATURE_DATA_SHADER_MODEL));
- if(!SUCCEEDED(hr))
- throw reflection_error(context, FFX_SSSR_STATUS_INVALID_VALUE, "Unable to check for shader model support on provided device.");
-
- if(supportedShaderModel.HighestShaderModel < D3D_SHADER_MODEL_6_2)
- throw reflection_error(context, FFX_SSSR_STATUS_INVALID_VALUE, "Device does not support shader model 6.2.");
-
- return device;
- }
-
- /**
- Gets the command list.
-
- \param context The context to be used.
- \param command_list The Direct3D12 command list.
- \return The command list.
- */
- ID3D12GraphicsCommandList* ContextD3D12::GetCommandList(Context& context, ID3D12GraphicsCommandList* command_list)
- {
- if (!command_list)
- throw reflection_error(context, FFX_SSSR_STATUS_INVALID_VALUE, "No command list was supplied, cannot encode device commands");
- return command_list;
- }
-
-
- /**
- The constructor for the ShaderPass class.
- */
- ContextD3D12::ShaderPass::ShaderPass()
- : pipeline_state_(nullptr)
- , root_signature_(nullptr)
- , descriptor_count_(0)
- {
- }
-
- /**
- The constructor for the ShaderPass class.
-
- \param other The shader pass to be moved.
- */
- ContextD3D12::ShaderPass::ShaderPass(ShaderPass&& other) noexcept
- : pipeline_state_(other.pipeline_state_)
- , root_signature_(other.root_signature_)
- , descriptor_count_(other.descriptor_count_)
- {
- other.pipeline_state_ = nullptr;
- other.root_signature_ = nullptr;
- other.descriptor_count_ = 0;
- }
-
- /**
- The destructor for the ShaderPass class.
- */
- ContextD3D12::ShaderPass::~ShaderPass()
- {
- SafeRelease();
- }
-
- /**
- Assigns the shader pass.
-
- \param other The shader pass to be moved.
- \return The assigned shader pass.
- */
- ContextD3D12::ShaderPass& ContextD3D12::ShaderPass::operator =(ShaderPass&& other) noexcept
- {
- if (this != &other)
- {
- pipeline_state_ = other.pipeline_state_;
- root_signature_ = other.root_signature_;
- descriptor_count_ = other.descriptor_count_;
-
- other.pipeline_state_ = nullptr;
- other.root_signature_ = nullptr;
- descriptor_count_ = 0;
- }
-
- return *this;
- }
-
- /**
- Releases the shader pass.
- */
- inline void ContextD3D12::ShaderPass::SafeRelease()
- {
- if (pipeline_state_)
- pipeline_state_->Release();
- pipeline_state_ = nullptr;
-
- if (root_signature_)
- root_signature_->Release();
- root_signature_ = nullptr;
-
- descriptor_count_ = 0;
- }
-
- /**
- Checks whether the shader pass is valid.
-
- \return true if the shader pass is valid, false otherwise.
- */
- ContextD3D12::ShaderPass::operator bool() const
- {
- return (pipeline_state_ && root_signature_);
- }
-}
diff --git a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.cpp b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.cpp
deleted file mode 100644
index 9fd625d..0000000
--- a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#include "descriptor_heap_d3d12.h"
-
-#include "reflection_error.h"
-#include "context_d3d12.h"
-
-namespace ffx_sssr
-{
- /**
- The constructor for the DescriptorHeapD3D12 class.
-
- \param context The context to be used.
- */
- DescriptorHeapD3D12::DescriptorHeapD3D12(Context& context)
- : context_(context)
- , descriptor_heap_(nullptr)
- , descriptor_handle_size_(0u)
- , static_descriptor_heap_size_(0u)
- , static_descriptor_heap_cursor_(0u)
- , dynamic_descriptor_heap_size_(0u)
- , dynamic_descriptor_heap_cursor_(0u)
- {
- }
-
- /**
- The destructor for the DescriptorHeapD3D12 class.
- */
- DescriptorHeapD3D12::~DescriptorHeapD3D12()
- {
- Destroy();
- }
-
- /**
- Creates the Direct3D12 descriptor heap.
-
- \param descriptor_heap_type The type of descriptor heap to be created.
- \param static_descriptor_count The number of static descriptors to be allocated.
- \param dynamic_descriptor_count The number of dynamic descriptors to be allocated.
- */
- void DescriptorHeapD3D12::Create(D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heap_type, std::uint32_t static_descriptor_count, std::uint32_t dynamic_descriptor_count)
- {
- HRESULT result;
-
- // Populate the allocation ranges
- auto const static_descriptor_heap_size = static_descriptor_count;
- auto const dynamic_descriptor_heap_size = dynamic_descriptor_count * context_.GetFrameCountBeforeReuse();
-
- // Create the descriptor heap
- auto const descriptor_count = static_descriptor_heap_size + dynamic_descriptor_heap_size;
- auto const descriptor_handle_size = context_.GetContextD3D12()->GetDevice()->GetDescriptorHandleIncrementSize(descriptor_heap_type);
-
- D3D12_DESCRIPTOR_HEAP_DESC descriptor_heap_desc = {};
- descriptor_heap_desc.Type = descriptor_heap_type;
- descriptor_heap_desc.NumDescriptors = descriptor_count;
- descriptor_heap_desc.Flags = (descriptor_heap_type == D3D12_DESCRIPTOR_HEAP_TYPE_RTV || descriptor_heap_type == D3D12_DESCRIPTOR_HEAP_TYPE_DSV ? D3D12_DESCRIPTOR_HEAP_FLAG_NONE : D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE);
-
- ID3D12DescriptorHeap* descriptor_heap;
- result = context_.GetContextD3D12()->GetDevice()->CreateDescriptorHeap(&descriptor_heap_desc, IID_PPV_ARGS(&descriptor_heap));
- if (!SUCCEEDED(result))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to create descriptor heap");
- }
- descriptor_heap->SetName(L"SSSR Descriptor Heap");
-
- // Assign the base members
- if (descriptor_heap_)
- descriptor_heap_->Release();
- descriptor_heap_ = descriptor_heap;
- descriptor_handle_size_ = descriptor_handle_size;
- static_descriptor_heap_size_ = static_descriptor_heap_size;
- static_descriptor_heap_cursor_ = 0u;
- dynamic_descriptor_heap_size_ = dynamic_descriptor_heap_size;
- dynamic_descriptor_heap_cursor_ = 0u;
- }
-
- /**
- Destroys the Direct3D12 descriptor heap.
- */
- void DescriptorHeapD3D12::Destroy()
- {
- if (descriptor_heap_)
- descriptor_heap_->Release();
- descriptor_heap_ = nullptr;
- }
-}
diff --git a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.h b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.h
deleted file mode 100644
index bb18d14..0000000
--- a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-#include
-
-#include "context.h"
-
-namespace ffx_sssr
-{
- class DescriptorHeapD3D12;
-
- /**
- The DescriptorD3D12 class represents an individual Direct3D12 descriptor handle.
- */
- class DescriptorD3D12
- {
- public:
- inline DescriptorD3D12();
-
- inline D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptor(std::uint32_t descriptor_index = 0u) const;
- inline D3D12_GPU_DESCRIPTOR_HANDLE GetGPUDescriptor(std::uint32_t descriptor_index = 0u) const;
-
- protected:
- friend class DescriptorHeapD3D12;
-
- // The number of descriptors available.
- std::uint32_t descriptor_count_;
- // The size of an individual descriptor handle.
- std::uint32_t descriptor_handle_size_;
- // The CPU-side descriptor handle.
- D3D12_CPU_DESCRIPTOR_HANDLE cpu_descriptor_handle_;
- // The GPU-side descriptor handle.
- D3D12_GPU_DESCRIPTOR_HANDLE gpu_descriptor_handle_;
- };
-
- /**
- The DescriptorHeapD3D12 class represents a Direct3D12 heap for allocating descriptors of a given type.
- */
- class DescriptorHeapD3D12
- {
- FFX_SSSR_NON_COPYABLE(DescriptorHeapD3D12);
-
- public:
- DescriptorHeapD3D12(Context& context);
- ~DescriptorHeapD3D12();
-
- inline ID3D12DescriptorHeap* const& GetDescriptorHeap() const;
-
- inline bool AllocateStaticDescriptor(DescriptorD3D12& descriptor, std::uint32_t descriptor_count = 1u);
- inline bool AllocateDynamicDescriptor(DescriptorD3D12& descriptor, std::uint32_t descriptor_count = 1u);
-
- void Create(D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heap_type, std::uint32_t static_descriptor_count, std::uint32_t dynamic_descriptor_count);
- void Destroy();
-
- protected:
- /**
- The Range class describes an allocated range within a descriptor heap.
- */
- class Range
- {
- public:
- inline Range();
- inline Range(std::uint32_t range_start, std::uint32_t range_size);
-
- inline bool Overlap(Range const& other) const;
-
- // The index of the allocation frame for this range.
- std::uint32_t frame_index_;
- // The start of the range in the heap.
- std::uint32_t range_start_;
- // The size of the allocation range.
- std::uint32_t range_size_;
- };
-
- // The context to be used.
- Context& context_;
- // The Direct3D12 descriptor heap.
- ID3D12DescriptorHeap* descriptor_heap_;
- // The size of an individual descriptor handle.
- std::uint32_t descriptor_handle_size_;
- // The size of the heap for allocating static descriptors.
- std::uint32_t static_descriptor_heap_size_;
- // The cursor of the heap for allocating static descriptors.
- std::uint32_t static_descriptor_heap_cursor_;
- // The size of the heap for allocating dynamic descriptors.
- std::uint32_t dynamic_descriptor_heap_size_;
- // The cursor of the heap for allocating dynamic descriptors.
- std::uint32_t dynamic_descriptor_heap_cursor_;
- // The allocated ranges with the dynamic descriptor heap.
- std::deque dynamic_descriptor_heap_ranges_;
- };
-}
-
-#include "descriptor_heap_d3d12.inl"
diff --git a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.inl b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.inl
deleted file mode 100644
index 37a5ab0..0000000
--- a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.inl
+++ /dev/null
@@ -1,192 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-namespace ffx_sssr
-{
- /**
- The constructor for the DescriptorD3D12 class.
- */
- DescriptorD3D12::DescriptorD3D12()
- : descriptor_count_(0u)
- , descriptor_handle_size_(0u)
- , cpu_descriptor_handle_{0ull}
- , gpu_descriptor_handle_{0ull}
- {
- }
-
- /**
- Gets the CPU descriptor.
-
- \param descriptor_index The index of the descriptor.
- \return The CPU descriptor handle.
- */
- D3D12_CPU_DESCRIPTOR_HANDLE DescriptorD3D12::GetCPUDescriptor(std::uint32_t descriptor_index) const
- {
- FFX_SSSR_ASSERT(descriptor_index < descriptor_count_);
- auto cpu_descriptor_handle = cpu_descriptor_handle_;
- cpu_descriptor_handle.ptr += static_cast(descriptor_index) * static_cast(descriptor_handle_size_);
- return cpu_descriptor_handle;
- }
-
- /**
- Gets the GPU descriptor.
-
- \param descriptor_index The index of the descriptor.
- \return The GPU descriptor handle.
- */
- D3D12_GPU_DESCRIPTOR_HANDLE DescriptorD3D12::GetGPUDescriptor(std::uint32_t descriptor_index) const
- {
- FFX_SSSR_ASSERT(descriptor_index < descriptor_count_);
- auto gpu_descriptor_handle = gpu_descriptor_handle_;
- gpu_descriptor_handle.ptr += static_cast(descriptor_index) * static_cast(descriptor_handle_size_);
- return gpu_descriptor_handle;
- }
-
- /**
- The constructor for the Range class.
- */
- DescriptorHeapD3D12::Range::Range()
- : frame_index_(0u)
- , range_start_(0u)
- , range_size_(0u)
- {
- }
-
- /**
- The constructor for the Range class.
-
- \param range_start The start of the range in the heap.
- \param range_size The size of the allocation range.
- */
- DescriptorHeapD3D12::Range::Range(std::uint32_t range_start, std::uint32_t range_size)
- : frame_index_(0u)
- , range_start_(range_start)
- , range_size_(range_size)
- {
- }
-
- /**
- Checks whether the ranges overlap.
-
- \param other The range to be checked for overlap.
- \return true if the ranges overlap, false otherwise.
- */
- bool DescriptorHeapD3D12::Range::Overlap(Range const& other) const
- {
- return (range_start_ < other.range_start_ + other.range_size_ && other.range_start_ < range_start_ + range_size_);
- }
-
- /**
- Gets the Direct3D12 descriptor heap.
-
- \return The Direct3D12 descriptor heap.
- */
- ID3D12DescriptorHeap* const& DescriptorHeapD3D12::GetDescriptorHeap() const
- {
- return descriptor_heap_;
- }
-
- /**
- Allocates a static descriptor.
-
- \param descriptor The allocated descriptor.
- \param descriptor_count The number of descriptors to be allocated.
- \return true if the descriptor was allocated successfully, false otherwise.
- */
- bool DescriptorHeapD3D12::AllocateStaticDescriptor(DescriptorD3D12& descriptor, std::uint32_t descriptor_count)
- {
- // Calculate the new cursor position
- auto const static_descriptor_heap_cursor = static_descriptor_heap_cursor_ + descriptor_count;
-
- if (static_descriptor_heap_cursor > static_descriptor_heap_size_)
- {
- return false; // out of memory
- }
-
- // Populate the descriptor handles
- descriptor.descriptor_count_ = descriptor_count;
- descriptor.descriptor_handle_size_ = descriptor_handle_size_;
- descriptor.cpu_descriptor_handle_ = descriptor_heap_->GetCPUDescriptorHandleForHeapStart();
- descriptor.cpu_descriptor_handle_.ptr += static_cast(static_descriptor_heap_cursor_) * static_cast(descriptor_handle_size_);
- descriptor.gpu_descriptor_handle_ = descriptor_heap_->GetGPUDescriptorHandleForHeapStart();
- descriptor.gpu_descriptor_handle_.ptr += static_cast(static_descriptor_heap_cursor_) * static_cast(descriptor_handle_size_);
-
- // Advance the allocation cursor
- static_descriptor_heap_cursor_ = static_descriptor_heap_cursor;
-
- return true;
- }
-
- /**
- Allocates a dynamic descriptor.
-
- \param descriptor The allocated descriptor.
- \param descriptor_count The number of descriptors to be allocated.
- \return true if the descriptor was allocated successfully, false otherwise.
- */
- bool DescriptorHeapD3D12::AllocateDynamicDescriptor(DescriptorD3D12& descriptor, std::uint32_t descriptor_count)
- {
- // Calculate the new cursor position
- auto dynamic_descriptor_heap_cursor = dynamic_descriptor_heap_cursor_ + descriptor_count;
-
- if (dynamic_descriptor_heap_cursor > dynamic_descriptor_heap_size_)
- {
- dynamic_descriptor_heap_cursor_ = 0u; // loop back
- dynamic_descriptor_heap_cursor = descriptor_count;
- }
- if (dynamic_descriptor_heap_cursor > dynamic_descriptor_heap_size_)
- {
- return false; // not enough memory available
- }
-
- // Check whether we can safely reuse the allocation range
- Range dynamic_descriptor_heap_range(dynamic_descriptor_heap_cursor_, descriptor_count);
-
- while (!dynamic_descriptor_heap_ranges_.empty() && dynamic_descriptor_heap_ranges_.front().Overlap(dynamic_descriptor_heap_range))
- {
- FFX_SSSR_ASSERT(context_.GetFrameIndex() >= dynamic_descriptor_heap_ranges_.front().frame_index_);
-
- if (context_.GetFrameIndex() - dynamic_descriptor_heap_ranges_.front().frame_index_ < context_.GetFrameCountBeforeReuse())
- {
- return false; // next available range is still in flight!
- }
-
- dynamic_descriptor_heap_ranges_.pop_front();
- }
-
- // Populate the descriptor handles
- descriptor.descriptor_count_ = descriptor_count;
- descriptor.descriptor_handle_size_ = descriptor_handle_size_;
- descriptor.cpu_descriptor_handle_ = descriptor_heap_->GetCPUDescriptorHandleForHeapStart();
- descriptor.cpu_descriptor_handle_.ptr += (static_cast(static_descriptor_heap_size_) + static_cast(dynamic_descriptor_heap_cursor_)) * static_cast(descriptor_handle_size_);
- descriptor.gpu_descriptor_handle_ = descriptor_heap_->GetGPUDescriptorHandleForHeapStart();
- descriptor.gpu_descriptor_handle_.ptr += (static_cast(static_descriptor_heap_size_) + static_cast(dynamic_descriptor_heap_cursor_)) * static_cast(descriptor_handle_size_);
-
- // Advance the allocation cursor
- dynamic_descriptor_heap_range.frame_index_ = context_.GetFrameIndex();
- dynamic_descriptor_heap_ranges_.push_back(dynamic_descriptor_heap_range);
- dynamic_descriptor_heap_cursor_ = dynamic_descriptor_heap_cursor;
-
- return true;
- }
-}
diff --git a/ffx-sssr/src/d3d12/reflection_view_d3d12.cpp b/ffx-sssr/src/d3d12/reflection_view_d3d12.cpp
deleted file mode 100644
index 221c98a..0000000
--- a/ffx-sssr/src/d3d12/reflection_view_d3d12.cpp
+++ /dev/null
@@ -1,1013 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#include "reflection_view_d3d12.h"
-
-#include
-#include
-
-#include "context.h"
-#include "reflection_error.h"
-#include "reflection_view.h"
-#include "context_d3d12.h"
-#include "ffx_sssr_d3d12.h"
-#include "descriptor_heap_d3d12.h"
-
-namespace ffx_sssr
-{
- /**
- The constructor for the ReflectionViewD3D12 class.
- */
- ReflectionViewD3D12::ReflectionViewD3D12()
- : width_(0)
- , height_(0)
- , flags_(0)
- , descriptor_heap_cbv_srv_uav_(nullptr)
- , descriptor_heap_samplers_(nullptr)
- , resource_heap_(nullptr)
- , tile_list_(nullptr)
- , tile_counter_(nullptr)
- , ray_list_(nullptr)
- , ray_counter_(nullptr)
- , intersection_pass_indirect_args_(nullptr)
- , denoiser_pass_indirect_args_(nullptr)
- , temporal_denoiser_result_()
- , ray_lengths_(nullptr)
- , temporal_variance_(nullptr)
- , tile_classification_elapsed_time_(0)
- , intersection_elapsed_time_(0)
- , denoising_elapsed_time_(0)
- , timestamp_query_heap_(nullptr)
- , timestamp_query_buffer_(nullptr)
- , timestamp_queries_()
- , timestamp_queries_index_(0)
- , scene_format_(DXGI_FORMAT_UNKNOWN)
- , tile_classification_descriptor_table_()
- , indirect_args_descriptor_table_()
- , intersection_descriptor_table_()
- , spatial_denoising_descriptor_table_()
- , temporal_denoising_descriptor_table_()
- , eaw_denoising_descriptor_table_()
- , sampler_descriptor_table_()
- , prev_view_projection_()
- {
- }
-
- /**
- The constructor for the ReflectionViewD3D12 class.
-
- \param other The reflection view to be moved.
- */
- ReflectionViewD3D12::ReflectionViewD3D12(ReflectionViewD3D12&& other) noexcept
- : width_(other.width_)
- , height_(other.height_)
- , flags_(other.flags_)
- , descriptor_heap_cbv_srv_uav_(other.descriptor_heap_cbv_srv_uav_)
- , descriptor_heap_samplers_(other.descriptor_heap_samplers_)
- , tile_classification_elapsed_time_(other.tile_classification_elapsed_time_)
- , intersection_elapsed_time_(other.intersection_elapsed_time_)
- , denoising_elapsed_time_(other.denoising_elapsed_time_)
- , timestamp_query_heap_(other.timestamp_query_heap_)
- , timestamp_query_buffer_(other.timestamp_query_buffer_)
- , timestamp_queries_(std::move(other.timestamp_queries_))
- , timestamp_queries_index_(other.timestamp_queries_index_)
- , resource_heap_(other.resource_heap_)
- , tile_list_(other.tile_list_)
- , tile_counter_(other.tile_counter_)
- , ray_list_(other.ray_list_)
- , ray_counter_(other.ray_counter_)
- , intersection_pass_indirect_args_(other.intersection_pass_indirect_args_)
- , denoiser_pass_indirect_args_(other.denoiser_pass_indirect_args_)
- , ray_lengths_(other.ray_lengths_)
- , temporal_variance_(other.temporal_variance_)
- , scene_format_(other.scene_format_)
- , prev_view_projection_(other.prev_view_projection_)
- {
- other.timestamp_query_heap_ = nullptr;
- other.timestamp_query_buffer_ = nullptr;
- other.descriptor_heap_cbv_srv_uav_ = nullptr;
- other.descriptor_heap_samplers_ = nullptr;
-
- for (int i = 0; i < 2; ++i)
- {
- temporal_denoiser_result_[i] = other.temporal_denoiser_result_[i];
- tile_classification_descriptor_table_[i] = other.tile_classification_descriptor_table_[i];
- indirect_args_descriptor_table_[i] = other.indirect_args_descriptor_table_[i];
- intersection_descriptor_table_[i] = other.intersection_descriptor_table_[i];
- spatial_denoising_descriptor_table_[i] = other.spatial_denoising_descriptor_table_[i];
- temporal_denoising_descriptor_table_[i] = other.temporal_denoising_descriptor_table_[i];
- eaw_denoising_descriptor_table_[i] = other.eaw_denoising_descriptor_table_[i];
- other.temporal_denoiser_result_[i] = nullptr;
- }
- sampler_descriptor_table_ = other.sampler_descriptor_table_;
-
- other.resource_heap_ = nullptr;
- other.tile_list_ = nullptr;
- other.tile_counter_ = nullptr;
- other.ray_list_ = nullptr;
- other.ray_counter_ = nullptr;
- other.intersection_pass_indirect_args_ = nullptr;
- other.denoiser_pass_indirect_args_ = nullptr;
- other.ray_lengths_ = nullptr;
- other.temporal_variance_ = nullptr;
- other.timestamp_query_buffer_ = nullptr;
- other.timestamp_query_heap_ = nullptr;
- }
-
- /**
- The destructor for the ReflectionViewD3D12 class.
- */
- ReflectionViewD3D12::~ReflectionViewD3D12()
- {
- Destroy();
- }
-
- /**
- Assigns the reflection view.
-
- \param other The reflection view to be moved.
- \return The assigned reflection view.
- */
- ReflectionViewD3D12& ReflectionViewD3D12::operator =(ReflectionViewD3D12&& other) noexcept
- {
- if (this != &other)
- {
- width_ = other.width_;
- height_ = other.height_;
- flags_ = other.flags_;
-
- descriptor_heap_cbv_srv_uav_ = other.descriptor_heap_cbv_srv_uav_;
- descriptor_heap_samplers_ = other.descriptor_heap_samplers_;
- tile_classification_elapsed_time_ = other.tile_classification_elapsed_time_;
- intersection_elapsed_time_ = other.intersection_elapsed_time_;
- denoising_elapsed_time_ = other.denoising_elapsed_time_;
- timestamp_query_heap_ = other.timestamp_query_heap_;
- timestamp_query_buffer_ = other.timestamp_query_buffer_;
- timestamp_queries_ = other.timestamp_queries_;;
- timestamp_queries_index_ = other.timestamp_queries_index_;
- resource_heap_ = other.resource_heap_;
- tile_list_ = other.tile_list_;
- tile_counter_ = other.tile_counter_;
- ray_list_ = other.ray_list_;
- ray_counter_ = other.ray_counter_;
- intersection_pass_indirect_args_ = other.intersection_pass_indirect_args_;
- denoiser_pass_indirect_args_ = other.denoiser_pass_indirect_args_;
- ray_lengths_ = other.ray_lengths_;
- temporal_variance_ = other.temporal_variance_;
- scene_format_ = other.scene_format_;
- prev_view_projection_ = other.prev_view_projection_;
-
- other.timestamp_query_heap_ = nullptr;
- other.timestamp_query_buffer_ = nullptr;
- other.descriptor_heap_cbv_srv_uav_ = nullptr;
- other.descriptor_heap_samplers_ = nullptr;
-
- for (int i = 0; i < 2; ++i)
- {
- temporal_denoiser_result_[i] = other.temporal_denoiser_result_[i];
- tile_classification_descriptor_table_[i] = other.tile_classification_descriptor_table_[i];
- indirect_args_descriptor_table_[i] = other.indirect_args_descriptor_table_[i];
- intersection_descriptor_table_[i] = other.intersection_descriptor_table_[i];
- spatial_denoising_descriptor_table_[i] = other.spatial_denoising_descriptor_table_[i];
- temporal_denoising_descriptor_table_[i] = other.temporal_denoising_descriptor_table_[i];
- eaw_denoising_descriptor_table_[i] = other.eaw_denoising_descriptor_table_[i];
-
- other.temporal_denoiser_result_[i] = nullptr;
- }
- sampler_descriptor_table_ = other.sampler_descriptor_table_;
-
- other.resource_heap_ = nullptr;
- other.tile_list_ = nullptr;
- other.tile_counter_ = nullptr;
- other.ray_list_ = nullptr;
- other.ray_counter_ = nullptr;
- other.intersection_pass_indirect_args_ = nullptr;
- other.denoiser_pass_indirect_args_ = nullptr;
- other.ray_lengths_ = nullptr;
- other.temporal_variance_ = nullptr;
- other.timestamp_query_buffer_ = nullptr;
- other.timestamp_query_heap_ = nullptr;
- }
-
- return *this;
- }
-
- /**
- Creates the reflection view.
-
- \param context The context to be used.
- \param create_reflection_view_info The reflection view creation information.
- */
- void ReflectionViewD3D12::Create(Context& context, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info)
- {
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo != nullptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->sceneFormat != DXGI_FORMAT_UNKNOWN);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->depthBufferHierarchySRV.ptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->motionBufferSRV.ptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->normalBufferSRV.ptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->roughnessBufferSRV.ptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->normalHistoryBufferSRV.ptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->roughnessHistoryBufferSRV.ptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->environmentMapSRV.ptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->pEnvironmentMapSamplerDesc);
- FFX_SSSR_ASSERT(create_reflection_view_info.pD3D12CreateReflectionViewInfo->reflectionViewUAV.ptr);
- FFX_SSSR_ASSERT(create_reflection_view_info.outputWidth && create_reflection_view_info.outputHeight);
-
- // Populate the reflection view properties
- width_ = create_reflection_view_info.outputWidth;
- height_ = create_reflection_view_info.outputHeight;
- flags_ = create_reflection_view_info.flags;
- scene_format_ = create_reflection_view_info.pD3D12CreateReflectionViewInfo->sceneFormat;
-
- // Create reflection view resources
- CreateDescriptorHeaps(context);
-
- // Create tile classification-related buffers
- {
- ID3D12Device * device = context.GetContextD3D12()->GetDevice();
-
- uint32_t num_tiles = RoundedDivide(width_, 8u) * RoundedDivide(height_, 8u);
- uint32_t num_pixels = width_ * height_;
-
- uint32_t tile_list_element_count = num_tiles;
- uint32_t tile_counter_element_count = 1;
- uint32_t ray_list_element_count = num_pixels;
- uint32_t ray_counter_element_count = 1;
- uint32_t intersection_pass_indirect_args_element_count = 3;
- uint32_t denoiser_pass_indirect_args_element_count = 3;
-
- // Helper function to create resource descriptions for 1D Buffers
- auto BufferDesc = [](uint32_t num_elements) {
- D3D12_RESOURCE_DESC desc = {};
- desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- desc.Alignment = 0;
- desc.Width = num_elements * 4;
- desc.Height = 1;
- desc.DepthOrArraySize = 1;
- desc.MipLevels = 1;
- desc.Format = DXGI_FORMAT_UNKNOWN;
- desc.SampleDesc.Count = 1;
- desc.SampleDesc.Quality = 0;
- desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
- desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
- return desc;
- };
-
- D3D12_RESOURCE_DESC tile_list_desc = BufferDesc(num_tiles);
- D3D12_RESOURCE_DESC tile_counter_desc = BufferDesc(1);
- D3D12_RESOURCE_DESC ray_list_desc = BufferDesc(num_pixels);
- D3D12_RESOURCE_DESC ray_counter_desc = BufferDesc(1);
- constexpr uint32_t indirect_arguments_member_count = 3;
- static_assert(sizeof(D3D12_DISPATCH_ARGUMENTS) == indirect_arguments_member_count * 4, "Size of indirect arguments buffer does not match D3D12_DISPATCH_ARGUMENTS.");
- D3D12_RESOURCE_DESC intersection_pass_indirect_args_desc = BufferDesc(3);
- D3D12_RESOURCE_DESC denoiser_pass_indirect_args_desc = BufferDesc(3);
-
- D3D12_RESOURCE_DESC resource_descs[] = {
- tile_list_desc, tile_counter_desc, ray_list_desc, ray_counter_desc, intersection_pass_indirect_args_desc, denoiser_pass_indirect_args_desc
- };
-
- D3D12_RESOURCE_ALLOCATION_INFO allocation_info = device->GetResourceAllocationInfo(0, FFX_SSSR_ARRAY_SIZE(resource_descs), resource_descs);
- D3D12_HEAP_DESC heap_desc = {};
- heap_desc.Alignment = allocation_info.Alignment;
- heap_desc.SizeInBytes = allocation_info.SizeInBytes;
- heap_desc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS;
- heap_desc.Properties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
- heap_desc.Properties.CreationNodeMask = 0;
- heap_desc.Properties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
- heap_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT;
- heap_desc.Properties.VisibleNodeMask = 0;
-
- HRESULT hr = device->CreateHeap(&heap_desc, IID_PPV_ARGS(&resource_heap_));
- if (!SUCCEEDED(hr))
- {
- throw reflection_error(context, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to create resource heap.");
- }
-
- UINT64 heap_offset = 0;
- auto CreatePlacedResource = [this, &context, &heap_offset, &allocation_info](
- D3D12_RESOURCE_DESC * desc
- , D3D12_RESOURCE_STATES initial_state
- , REFIID riidResource
- , _COM_Outptr_opt_ void **ppvResource)
- {
- ID3D12Device * device = context.GetContextD3D12()->GetDevice();
- HRESULT hr = device->CreatePlacedResource(resource_heap_, heap_offset, desc, initial_state, nullptr, riidResource, ppvResource);
- if (!SUCCEEDED(hr))
- {
- throw reflection_error(context, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to create placed resource.");
- }
-
- heap_offset += desc->Width;
- heap_offset = RoundedDivide(heap_offset, allocation_info.Alignment) * allocation_info.Alignment;
- };
-
- CreatePlacedResource(&tile_list_desc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, IID_PPV_ARGS(&tile_list_));
- CreatePlacedResource(&tile_counter_desc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, IID_PPV_ARGS(&tile_counter_));
- CreatePlacedResource(&ray_list_desc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, IID_PPV_ARGS(&ray_list_));
- CreatePlacedResource(&ray_counter_desc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, IID_PPV_ARGS(&ray_counter_));
- CreatePlacedResource(&intersection_pass_indirect_args_desc, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT, IID_PPV_ARGS(&intersection_pass_indirect_args_));
- CreatePlacedResource(&denoiser_pass_indirect_args_desc, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT, IID_PPV_ARGS(&denoiser_pass_indirect_args_));
-
- tile_list_->SetName(L"SSSR Tile List");
- tile_counter_->SetName(L"SSSR Tile Counter");
- ray_list_->SetName(L"SSSR Ray List");
- ray_counter_->SetName(L"SSSR Ray Counter");
- intersection_pass_indirect_args_->SetName(L"SSSR Intersect Indirect Args");
- denoiser_pass_indirect_args_->SetName(L"SSSR Denoiser Indirect Args");
- }
-
- // Create denoising-related resources
- {
- auto CreateCommittedResource = [this, &context](
- DXGI_FORMAT format
- , REFIID riidResource
- , _COM_Outptr_opt_ void **ppvResource) {
- HRESULT hr;
- ID3D12Device * device = context.GetContextD3D12()->GetDevice();
- D3D12_HEAP_PROPERTIES default_heap = {};
- default_heap.Type = D3D12_HEAP_TYPE_DEFAULT;
- default_heap.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
- default_heap.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
- default_heap.CreationNodeMask = 1;
- default_heap.VisibleNodeMask = 1;
-
- D3D12_RESOURCE_DESC desc = {};
- desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
- desc.Alignment = 0;
- desc.Width = width_;
- desc.Height = height_;
- desc.DepthOrArraySize = 1;
- desc.MipLevels = 0;
- desc.Format = format;
- desc.SampleDesc.Count = 1;
- desc.SampleDesc.Quality = 0;
- desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
- desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
-
- hr = device->CreateCommittedResource(
- &default_heap,
- D3D12_HEAP_FLAG_NONE,
- &desc,
- D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
- NULL,
- riidResource, ppvResource);
-
- if (!SUCCEEDED(hr))
- {
- throw reflection_error(context, FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to create intermediate target.");
- }
- };
-
- CreateCommittedResource(scene_format_, IID_PPV_ARGS(&temporal_denoiser_result_[0]));
- CreateCommittedResource(scene_format_, IID_PPV_ARGS(&temporal_denoiser_result_[1]));
- CreateCommittedResource(DXGI_FORMAT_R16_FLOAT, IID_PPV_ARGS(&ray_lengths_));
- CreateCommittedResource(DXGI_FORMAT_R8_UNORM, IID_PPV_ARGS(&temporal_variance_));
-
- temporal_denoiser_result_[0]->SetName(L"SSSR Temporal Denoised Result 0");
- temporal_denoiser_result_[1]->SetName(L"SSSR Temporal Denoised Result 1");
- ray_lengths_->SetName(L"SSSR Ray Lengths");
- temporal_variance_->SetName(L"SSSR Temporal Variance");
- }
-
- ContextD3D12* d3d12_context = context.GetContextD3D12();
-
- // Setup the descriptor tables
- {
- descriptor_heap_samplers_->AllocateStaticDescriptor(sampler_descriptor_table_, 1);
-
- // Suballocate descriptor heap for descriptor tables
- for (int i = 0; i < 2; ++i)
- {
- DescriptorD3D12 table;
- descriptor_heap_cbv_srv_uav_->AllocateStaticDescriptor(table, d3d12_context->GetTileClassificationPass().descriptor_count_);
- tile_classification_descriptor_table_[i] = table;
-
- descriptor_heap_cbv_srv_uav_->AllocateStaticDescriptor(table, d3d12_context->GetIndirectArgsPass().descriptor_count_);
- indirect_args_descriptor_table_[i] = table;
-
- descriptor_heap_cbv_srv_uav_->AllocateStaticDescriptor(table, d3d12_context->GetIntersectionPass().descriptor_count_);
- intersection_descriptor_table_[i] = table;
-
- descriptor_heap_cbv_srv_uav_->AllocateStaticDescriptor(table, d3d12_context->GetSpatialDenoisingPass().descriptor_count_);
- spatial_denoising_descriptor_table_[i] = table;
-
- descriptor_heap_cbv_srv_uav_->AllocateStaticDescriptor(table, d3d12_context->GetTemporalDenoisingPass().descriptor_count_);
- temporal_denoising_descriptor_table_[i] = table;
-
- descriptor_heap_cbv_srv_uav_->AllocateStaticDescriptor(table, d3d12_context->GetEawDenoisingPass().descriptor_count_);
- eaw_denoising_descriptor_table_[i] = table;
- }
-
- ID3D12Device * device = context.GetContextD3D12()->GetDevice();
- UINT descriptor_size = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
-
- D3D12_CPU_DESCRIPTOR_HANDLE scene_srv = create_reflection_view_info.pD3D12CreateReflectionViewInfo->sceneSRV;
- D3D12_CPU_DESCRIPTOR_HANDLE depth_hierarchy_srv = create_reflection_view_info.pD3D12CreateReflectionViewInfo->depthBufferHierarchySRV;
- D3D12_CPU_DESCRIPTOR_HANDLE motion_buffer_srv = create_reflection_view_info.pD3D12CreateReflectionViewInfo->motionBufferSRV;
- D3D12_CPU_DESCRIPTOR_HANDLE normal_buffer_srv = create_reflection_view_info.pD3D12CreateReflectionViewInfo->normalBufferSRV;
- D3D12_CPU_DESCRIPTOR_HANDLE roughness_buffer_srv = create_reflection_view_info.pD3D12CreateReflectionViewInfo->roughnessBufferSRV;
- D3D12_CPU_DESCRIPTOR_HANDLE normal_history_buffer_srv = create_reflection_view_info.pD3D12CreateReflectionViewInfo->normalHistoryBufferSRV;
- D3D12_CPU_DESCRIPTOR_HANDLE roughness_history_buffer_srv = create_reflection_view_info.pD3D12CreateReflectionViewInfo->roughnessHistoryBufferSRV;
- D3D12_CPU_DESCRIPTOR_HANDLE environment_map_srv = create_reflection_view_info.pD3D12CreateReflectionViewInfo->environmentMapSRV;
- D3D12_CPU_DESCRIPTOR_HANDLE output_buffer_uav = create_reflection_view_info.pD3D12CreateReflectionViewInfo->reflectionViewUAV;
- const D3D12_SAMPLER_DESC* environment_map_sampler_desc = create_reflection_view_info.pD3D12CreateReflectionViewInfo->pEnvironmentMapSamplerDesc;
-
- D3D12_CPU_DESCRIPTOR_HANDLE normal_buffers[] = { normal_buffer_srv, normal_history_buffer_srv };
- D3D12_CPU_DESCRIPTOR_HANDLE roughness_buffers[] = { roughness_buffer_srv, roughness_history_buffer_srv };
-
- bool ping_pong_normal = (create_reflection_view_info.flags & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_NORMAL_BUFFERS) != 0;
- bool ping_pong_roughness = (create_reflection_view_info.flags & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_ROUGHNESS_BUFFERS) != 0;
-
- // Helper function to create a default shader resource view for a Texture2D
- auto SRV_Tex2D = [](DXGI_FORMAT format) {
- D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {};
- shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- shader_resource_view_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- shader_resource_view_desc.Texture2D.MipLevels = -1;
- shader_resource_view_desc.Texture2D.MostDetailedMip = 0;
- shader_resource_view_desc.Texture2D.PlaneSlice = 0;
- shader_resource_view_desc.Texture2D.ResourceMinLODClamp = 0;
- shader_resource_view_desc.Format = format;
- return shader_resource_view_desc;
- };
-
- // Helper function to create a default unordered access view for a Texture2D
- auto UAV_Tex2D = [](DXGI_FORMAT format) {
- D3D12_UNORDERED_ACCESS_VIEW_DESC unordered_access_view_desc = {};
- unordered_access_view_desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
- unordered_access_view_desc.Texture2D.MipSlice = 0;
- unordered_access_view_desc.Texture2D.PlaneSlice = 0;
- unordered_access_view_desc.Format = format;
- return unordered_access_view_desc;
- };
-
- // Helper function to create a default unordered access view for a Buffer
- auto UAV_Buffer = [](uint32_t num_elements) {
- D3D12_UNORDERED_ACCESS_VIEW_DESC unordered_access_view_desc = {};
- unordered_access_view_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
- unordered_access_view_desc.Buffer.CounterOffsetInBytes = 0;
- unordered_access_view_desc.Buffer.FirstElement = 0;
- unordered_access_view_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
- unordered_access_view_desc.Buffer.NumElements = num_elements;
- unordered_access_view_desc.Buffer.StructureByteStride = 4;
- unordered_access_view_desc.Format = DXGI_FORMAT_UNKNOWN;
- return unordered_access_view_desc;
- };
-
- auto SRV_Buffer = [](uint32_t num_elements) {
- D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {};
- shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
- shader_resource_view_desc.Buffer.FirstElement = 0;
- shader_resource_view_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
- shader_resource_view_desc.Buffer.NumElements = num_elements;
- shader_resource_view_desc.Buffer.StructureByteStride = 4;
- shader_resource_view_desc.Format = DXGI_FORMAT_UNKNOWN;
- shader_resource_view_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- return shader_resource_view_desc;
- };
-
- // Place the descriptors
- device->CreateSampler(environment_map_sampler_desc, sampler_descriptor_table_.GetCPUDescriptor(0)); // g_environment_map_sampler
- for (int i = 0; i < 2; ++i)
- {
- uint32_t num_tiles = RoundedDivide(width_, 8u) * RoundedDivide(height_, 8u);
- uint32_t num_pixels = width_ * height_;
-
- // Tile Classifier pass
- {
- DescriptorD3D12 table = tile_classification_descriptor_table_[i];
- uint32_t offset = 0;
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_roughness ? roughness_buffers[i] : roughness_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_roughness
- device->CreateUnorderedAccessView(tile_list_, nullptr, &UAV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list
- device->CreateUnorderedAccessView(ray_list_, nullptr, &UAV_Buffer(num_pixels), table.GetCPUDescriptor(offset++)); // g_ray_list
- device->CreateUnorderedAccessView(tile_counter_, nullptr, &UAV_Buffer(1), table.GetCPUDescriptor(offset++)); // g_tile_counter
- device->CreateUnorderedAccessView(ray_counter_, nullptr, &UAV_Buffer(1), table.GetCPUDescriptor(offset++)); // g_ray_counter
- device->CreateUnorderedAccessView(temporal_denoiser_result_[i], nullptr, &UAV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_temporally_denoised_reflections
- device->CreateUnorderedAccessView(temporal_denoiser_result_[1 - i], nullptr, &UAV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_temporally_denoised_reflections_history
- device->CreateUnorderedAccessView(ray_lengths_, nullptr, &UAV_Tex2D(DXGI_FORMAT_R16_FLOAT), table.GetCPUDescriptor(offset++)); // g_ray_lengths
- device->CreateUnorderedAccessView(temporal_variance_, nullptr, &UAV_Tex2D(DXGI_FORMAT_R8_UNORM), table.GetCPUDescriptor(offset++)); // g_temporal_variance
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), output_buffer_uav, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_denoised_reflections
- }
-
- // Indirect args pass
- {
- DescriptorD3D12 table = indirect_args_descriptor_table_[i];
- uint32_t offset = 0;
- device->CreateUnorderedAccessView(tile_counter_, nullptr, &UAV_Buffer(1), table.GetCPUDescriptor(offset++)); // g_tile_counter
- device->CreateUnorderedAccessView(ray_counter_, nullptr, &UAV_Buffer(1), table.GetCPUDescriptor(offset++)); // g_ray_counter
-
- constexpr uint32_t indirect_arguments_member_count = 3;
- static_assert(sizeof(D3D12_DISPATCH_ARGUMENTS) == indirect_arguments_member_count * 4, "Size of indirect arguments buffer does not match D3D12_DISPATCH_ARGUMENTS.");
- device->CreateUnorderedAccessView(intersection_pass_indirect_args_, nullptr, &UAV_Buffer(indirect_arguments_member_count), table.GetCPUDescriptor(offset++)); // g_intersect_args
- device->CreateUnorderedAccessView(denoiser_pass_indirect_args_, nullptr, &UAV_Buffer(indirect_arguments_member_count), table.GetCPUDescriptor(offset++)); // g_denoiser_args
- }
-
- // Intersection pass
- {
- DescriptorD3D12 table = intersection_descriptor_table_[i];
- uint32_t offset = 0;
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), scene_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_lit_scene
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), depth_hierarchy_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_depth_buffer_hierarchy
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_normal ? normal_buffers[i] : normal_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_normal
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_roughness ? roughness_buffers[i] : roughness_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_roughness
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), environment_map_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_environment_map
-
- // Blue noise sampler
- D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {};
- shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
- shader_resource_view_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- auto const& sampler = context.GetContextD3D12()->GetSampler2SPP();
- shader_resource_view_desc.Buffer.NumElements = static_cast(sampler.sobol_buffer_->GetDesc().Width / sizeof(std::int32_t));
- shader_resource_view_desc.Buffer.StructureByteStride = static_cast(sizeof(std::int32_t));
- device->CreateShaderResourceView(sampler.sobol_buffer_, &shader_resource_view_desc, table.GetCPUDescriptor(offset++)); // g_sobol_buffer
- shader_resource_view_desc.Buffer.NumElements = static_cast(sampler.ranking_tile_buffer_->GetDesc().Width / sizeof(std::int32_t));
- shader_resource_view_desc.Buffer.StructureByteStride = static_cast(sizeof(std::int32_t));
- device->CreateShaderResourceView(sampler.ranking_tile_buffer_, &shader_resource_view_desc, table.GetCPUDescriptor(offset++)); // g_ranking_tile_buffer
- shader_resource_view_desc.Buffer.NumElements = static_cast(sampler.scrambling_tile_buffer_->GetDesc().Width / sizeof(std::int32_t));
- shader_resource_view_desc.Buffer.StructureByteStride = static_cast(sizeof(std::int32_t));
- device->CreateShaderResourceView(sampler.scrambling_tile_buffer_, &shader_resource_view_desc, table.GetCPUDescriptor(offset++)); // g_scrambling_tile_buffer
-
- device->CreateShaderResourceView(ray_list_, &SRV_Buffer(num_pixels), table.GetCPUDescriptor(offset++)); // g_ray_list
- device->CreateUnorderedAccessView(temporal_denoiser_result_[i], nullptr, &UAV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_intersection_result
- device->CreateUnorderedAccessView(ray_lengths_, nullptr, &UAV_Tex2D(DXGI_FORMAT_R16_FLOAT), table.GetCPUDescriptor(offset++)); // g_ray_lengths
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), output_buffer_uav, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_denoised_reflections
- }
-
- // Spatial denoising pass
- {
- DescriptorD3D12 table = spatial_denoising_descriptor_table_[i];
- uint32_t offset = 0;
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), depth_hierarchy_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_depth_buffer
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_normal ? normal_buffers[i] : normal_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_normal
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_roughness ? roughness_buffers[i] : roughness_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_roughness
- device->CreateShaderResourceView(temporal_denoiser_result_[i], &SRV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_intersection_result
- device->CreateShaderResourceView(temporal_variance_, &SRV_Tex2D(DXGI_FORMAT_R8_UNORM), table.GetCPUDescriptor(offset++)); // g_has_ray
- device->CreateShaderResourceView(tile_list_, &SRV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), output_buffer_uav, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_spatially_denoised_reflections
- device->CreateUnorderedAccessView(ray_lengths_, nullptr, &UAV_Tex2D(DXGI_FORMAT_R16_FLOAT), table.GetCPUDescriptor(offset++)); // g_ray_lengths
- }
-
- // Temporal denoising pass
- {
- DescriptorD3D12 table = temporal_denoising_descriptor_table_[i];
- uint32_t offset = 0;
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_normal ? normal_buffers[i] : normal_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_normal
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_roughness ? roughness_buffers[i] : roughness_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_roughness
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_normal ? normal_buffers[1 - i] : normal_history_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_normal_history
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_roughness ? roughness_buffers[1 - i] : roughness_history_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_roughness_history
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), depth_hierarchy_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_depth_buffer
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), motion_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_motion_vectors
- device->CreateShaderResourceView(temporal_denoiser_result_[1 - i], &SRV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_temporally_denoised_reflections_history
- device->CreateShaderResourceView(ray_lengths_, &SRV_Tex2D(DXGI_FORMAT_R16_FLOAT), table.GetCPUDescriptor(offset++)); // g_ray_lengths
- device->CreateShaderResourceView(tile_list_, &SRV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list
- device->CreateUnorderedAccessView(temporal_denoiser_result_[i], nullptr, &UAV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_temporally_denoised_reflections
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), output_buffer_uav, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_spatially_denoised_reflections
- device->CreateUnorderedAccessView(temporal_variance_, nullptr, &UAV_Tex2D(DXGI_FORMAT_R8_UNORM), table.GetCPUDescriptor(offset++)); // g_temporal_variance
- }
-
- // EAW denoising pass
- {
- DescriptorD3D12 table = eaw_denoising_descriptor_table_[i];
- uint32_t offset = 0;
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_normal ? normal_buffers[i] : normal_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_normal
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), ping_pong_roughness ? roughness_buffers[i] : roughness_buffer_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_roughness
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), depth_hierarchy_srv, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_depth_buffer
- device->CreateShaderResourceView(tile_list_, &SRV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list
- device->CreateUnorderedAccessView(temporal_denoiser_result_[i], nullptr, &UAV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_temporally_denoised_reflections
- device->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), output_buffer_uav, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_denoised_reflections
- }
- }
- }
-
- // Create timestamp querying resources if enabled
- if ((create_reflection_view_info.flags & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)
- {
- auto const query_heap_size = kTimestampQuery_Count * context.GetFrameCountBeforeReuse() * sizeof(std::uint64_t);
-
- D3D12_QUERY_HEAP_DESC query_heap_desc = {};
- query_heap_desc.Type = D3D12_QUERY_HEAP_TYPE_TIMESTAMP;
- query_heap_desc.Count = static_cast(query_heap_size);
-
- if (!SUCCEEDED(context.GetContextD3D12()->GetDevice()->CreateQueryHeap(&query_heap_desc,
- IID_PPV_ARGS(×tamp_query_heap_))))
- {
- throw reflection_error(context, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Unable to create timestamp query heap");
- }
-
- if (!context.GetContextD3D12()->AllocateReadbackBuffer(query_heap_size,
- ×tamp_query_buffer_,
- D3D12_RESOURCE_STATE_COPY_DEST,
- L"TimestampQueryBuffer"))
- {
- throw reflection_error(context, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Unable to allocate readback buffer");
- }
-
- timestamp_queries_.resize(context.GetFrameCountBeforeReuse());
-
- for (auto& timestamp_queries : timestamp_queries_)
- {
- timestamp_queries.reserve(kTimestampQuery_Count);
- }
- }
- }
-
- /**
- Destroys the reflection view.
- */
- void ReflectionViewD3D12::Destroy()
- {
- if (descriptor_heap_cbv_srv_uav_)
- delete descriptor_heap_cbv_srv_uav_;
- descriptor_heap_cbv_srv_uav_ = nullptr;
-
- if (descriptor_heap_samplers_)
- delete descriptor_heap_samplers_;
- descriptor_heap_samplers_ = nullptr;
-
-#define FFX_SSSR_SAFE_RELEASE(x)\
- if(x) { x->Release(); }\
- x = nullptr;
-
- FFX_SSSR_SAFE_RELEASE(timestamp_query_heap_);
- FFX_SSSR_SAFE_RELEASE(timestamp_query_buffer_);
- FFX_SSSR_SAFE_RELEASE(temporal_denoiser_result_[0]);
- FFX_SSSR_SAFE_RELEASE(temporal_denoiser_result_[1]);
- FFX_SSSR_SAFE_RELEASE(ray_lengths_);
- FFX_SSSR_SAFE_RELEASE(temporal_variance_);
- FFX_SSSR_SAFE_RELEASE(tile_list_);
- FFX_SSSR_SAFE_RELEASE(tile_counter_);
- FFX_SSSR_SAFE_RELEASE(ray_list_);
- FFX_SSSR_SAFE_RELEASE(ray_counter_);
- FFX_SSSR_SAFE_RELEASE(intersection_pass_indirect_args_);
- FFX_SSSR_SAFE_RELEASE(denoiser_pass_indirect_args_);
- FFX_SSSR_SAFE_RELEASE(resource_heap_);
-
-#undef FFX_SSSR_SAFE_RELEASE
-
- timestamp_queries_.resize(0u);
- }
-
- /**
- Creates the descriptor heaps.
-
- \param context The context to be used.
- */
- void ReflectionViewD3D12::CreateDescriptorHeaps(Context& context)
- {
- ContextD3D12* d3d12_context = context.GetContextD3D12();
-
- FFX_SSSR_ASSERT(!descriptor_heap_cbv_srv_uav_);
- FFX_SSSR_ASSERT(!descriptor_heap_samplers_);
-
- descriptor_heap_cbv_srv_uav_ = new DescriptorHeapD3D12(context);
- FFX_SSSR_ASSERT(descriptor_heap_cbv_srv_uav_ != nullptr);
- std::uint32_t descriptor_count
- = d3d12_context->GetTileClassificationPass().descriptor_count_
- + d3d12_context->GetIndirectArgsPass().descriptor_count_
- + d3d12_context->GetIntersectionPass().descriptor_count_
- + d3d12_context->GetSpatialDenoisingPass().descriptor_count_
- + d3d12_context->GetTemporalDenoisingPass().descriptor_count_
- + d3d12_context->GetEawDenoisingPass().descriptor_count_;
- descriptor_heap_cbv_srv_uav_->Create(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 2 * descriptor_count, 0u);
-
- descriptor_heap_samplers_ = new DescriptorHeapD3D12(context);
- FFX_SSSR_ASSERT(descriptor_heap_samplers_ != nullptr);
- descriptor_heap_samplers_->Create(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, 1, 0u); // g_environment_map_sampler
- }
-
- /**
- Gets the index of the current timestamp query.
-
- \return The index of the current timestamp query.
- */
- std::uint32_t ReflectionViewD3D12::GetTimestampQueryIndex() const
- {
- return timestamp_queries_index_ * kTimestampQuery_Count + static_cast(timestamp_queries_[timestamp_queries_index_].size());
- }
-
- float Clamp(float value, float min, float max)
- {
- if (value < min)
- {
- return min;
- }
- else if (value > max)
- {
- return max;
- }
- return value;
- }
-
- /**
- Resolves the Direct3D12 reflection view.
-
- \param context The context to be used.
- \param reflection_view The reflection view to be resolved.
- \param resolve_reflection_view_info The reflection view resolve information.
- */
- void ReflectionViewD3D12::Resolve(Context& context, ReflectionView const& reflection_view, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info)
- {
- // Get hold of the command list for recording
- FFX_SSSR_ASSERT(resolve_reflection_view_info.pD3D12CommandEncodeInfo);
- auto const command_list = ContextD3D12::GetCommandList(context, resolve_reflection_view_info.pD3D12CommandEncodeInfo->pCommandList);
- FFX_SSSR_ASSERT(descriptor_heap_cbv_srv_uav_ && descriptor_heap_samplers_ && command_list);
- FFX_SSSR_ASSERT(resolve_reflection_view_info.samplesPerQuad == FFX_SSSR_RAY_SAMPLES_PER_QUAD_1 || resolve_reflection_view_info.samplesPerQuad == FFX_SSSR_RAY_SAMPLES_PER_QUAD_2 || resolve_reflection_view_info.samplesPerQuad == FFX_SSSR_RAY_SAMPLES_PER_QUAD_4);
-
- // Query timestamp value prior to resolving the reflection view
- if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)
- {
- auto& timestamp_queries = timestamp_queries_[timestamp_queries_index_];
-
- if (!timestamp_queries.empty())
- {
- std::uint64_t* data;
-
- // Reset performance counters
- tile_classification_elapsed_time_ = 0ull;
- denoising_elapsed_time_ = 0ull;
- intersection_elapsed_time_ = 0ull;
-
- auto const start_index = timestamp_queries_index_ * kTimestampQuery_Count;
-
- D3D12_RANGE read_range = {};
- read_range.Begin = start_index * sizeof(std::uint64_t);
- read_range.End = (start_index + timestamp_queries.size()) * sizeof(std::uint64_t);
-
- timestamp_query_buffer_->Map(0u,
- &read_range,
- reinterpret_cast(&data));
-
- for (auto i = 0u, j = 1u; j < timestamp_queries.size(); ++i, ++j)
- {
- auto const elapsed_time = (data[j] - data[i]);
-
- switch (timestamp_queries[j])
- {
- case kTimestampQuery_TileClassification:
- tile_classification_elapsed_time_ = elapsed_time;
- break;
- case kTimestampQuery_Intersection:
- intersection_elapsed_time_ = elapsed_time;
- break;
- case kTimestampQuery_Denoising:
- denoising_elapsed_time_ = elapsed_time;
- break;
- default:
- // unrecognized timestamp query
- break;
- }
- }
-
- timestamp_query_buffer_->Unmap(0u, nullptr);
- }
-
- timestamp_queries.clear();
-
- command_list->EndQuery(timestamp_query_heap_,
- D3D12_QUERY_TYPE_TIMESTAMP,
- GetTimestampQueryIndex());
-
- timestamp_queries.push_back(kTimestampQuery_Init);
- }
-
- // Encode the relevant pass data
- struct PassData
- {
- matrix4 inv_view_projection_;
- matrix4 projection_;
- matrix4 inv_projection_;
- matrix4 view_;
- matrix4 inv_view_;
- matrix4 prev_view_projection_;
- std::uint32_t frame_index_;
- std::uint32_t max_traversal_intersections_;
- std::uint32_t min_traversal_occupancy_;
- std::uint32_t most_detailed_mip_;
- float temporal_stability_factor_;
- float depth_buffer_thickness_;
- std::uint32_t samples_per_quad_;
- std::uint32_t temporal_variance_guided_tracing_enabled_;
- float roughness_threshold_;
- std::uint32_t skip_denoiser_;
- };
- auto& upload_buffer = context.GetContextD3D12()->GetUploadBuffer();
- PassData* pass_data;
- if (!upload_buffer.AllocateBuffer(sizeof(PassData), pass_data))
- {
- throw reflection_error(context, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %u bytes of upload memory, consider increasing uploadBufferSize", sizeof(PassData));
- }
-
- // Fill constant buffer
- matrix4 view_projection = reflection_view.projection_matrix_ * reflection_view.view_matrix_;
- pass_data->inv_view_projection_ = matrix4::inverse(view_projection);
- pass_data->projection_ = reflection_view.projection_matrix_;
- pass_data->inv_projection_ = matrix4::inverse(reflection_view.projection_matrix_);
- pass_data->view_ = reflection_view.view_matrix_;
- pass_data->inv_view_ = matrix4::inverse(reflection_view.view_matrix_);
- pass_data->prev_view_projection_ = prev_view_projection_;
- pass_data->frame_index_ = context.GetFrameIndex();
-
- float temporal_stability_scale = Clamp(resolve_reflection_view_info.temporalStabilityScale, 0, 1);
- pass_data->max_traversal_intersections_ = resolve_reflection_view_info.maxTraversalIterations;
- pass_data->min_traversal_occupancy_ = resolve_reflection_view_info.minTraversalOccupancy;
- pass_data->most_detailed_mip_ = resolve_reflection_view_info.mostDetailedDepthHierarchyMipLevel;
- pass_data->temporal_stability_factor_ = temporal_stability_scale * temporal_stability_scale;
- pass_data->depth_buffer_thickness_ = resolve_reflection_view_info.depthBufferThickness;
- pass_data->samples_per_quad_ = resolve_reflection_view_info.samplesPerQuad == FFX_SSSR_RAY_SAMPLES_PER_QUAD_4 ? 4 : (resolve_reflection_view_info.samplesPerQuad == FFX_SSSR_RAY_SAMPLES_PER_QUAD_2 ? 2 : 1);
- pass_data->temporal_variance_guided_tracing_enabled_ = resolve_reflection_view_info.flags & FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING ? 1 : 0;
- pass_data->roughness_threshold_ = resolve_reflection_view_info.roughnessThreshold;
- pass_data->skip_denoiser_ = resolve_reflection_view_info.flags & FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE ? 0 : 1;
- prev_view_projection_ = view_projection;
-
- std::uint32_t current_frame = context.GetFrameIndex() & 1u;
- ID3D12DescriptorHeap *descriptor_heaps[] = { descriptor_heap_cbv_srv_uav_->GetDescriptorHeap(), descriptor_heap_samplers_->GetDescriptorHeap() };
- command_list->SetDescriptorHeaps(FFX_SSSR_ARRAY_SIZE(descriptor_heaps), descriptor_heaps);
-
- ID3D12Resource * cb_resource = upload_buffer.GetResource();
- size_t offset = upload_buffer.GetOffset(pass_data);
-
- auto UAVBarrier = [](ID3D12Resource * resource) {
- D3D12_RESOURCE_BARRIER barrier = {};
- barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
- barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
- barrier.UAV.pResource = resource;
- return barrier;
- };
-
- auto Transition = [](ID3D12Resource * resource, D3D12_RESOURCE_STATES from, D3D12_RESOURCE_STATES to)
- {
- D3D12_RESOURCE_BARRIER barrier = {};
- barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
- barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
- barrier.Transition.pResource = resource;
- barrier.Transition.StateBefore = from;
- barrier.Transition.StateAfter = to;
- barrier.Transition.Subresource = 0;
- return barrier;
- };
-
- ContextD3D12* d3d12_context = context.GetContextD3D12();
-
- // Tile Classification pass
- {
- command_list->SetComputeRootSignature(d3d12_context->GetTileClassificationPass().root_signature_);
- command_list->SetComputeRootDescriptorTable(0, tile_classification_descriptor_table_[current_frame].GetGPUDescriptor());
- command_list->SetComputeRootConstantBufferView(1, cb_resource->GetGPUVirtualAddress() + offset);
- command_list->SetPipelineState(d3d12_context->GetTileClassificationPass().pipeline_state_);
- uint32_t dim_x = RoundedDivide(width_, 8u);
- uint32_t dim_y = RoundedDivide(height_, 8u);
- command_list->Dispatch(dim_x, dim_y, 1);
- }
-
- // Ensure that the tile classification pass finished
- D3D12_RESOURCE_BARRIER classification_results_barriers[] = {
- UAVBarrier(ray_list_),
- UAVBarrier(tile_list_),
- Transition(intersection_pass_indirect_args_, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
- Transition(denoiser_pass_indirect_args_, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT, D3D12_RESOURCE_STATE_UNORDERED_ACCESS)
- };
- command_list->ResourceBarrier(FFX_SSSR_ARRAY_SIZE(classification_results_barriers), classification_results_barriers);
-
- // Indirect Arguments pass
- {
- command_list->SetComputeRootSignature(d3d12_context->GetIndirectArgsPass().root_signature_);
- command_list->SetComputeRootDescriptorTable(0, indirect_args_descriptor_table_[current_frame].GetGPUDescriptor());
- command_list->SetComputeRootConstantBufferView(1, cb_resource->GetGPUVirtualAddress() + offset);
- command_list->SetPipelineState(d3d12_context->GetIndirectArgsPass().pipeline_state_);
- command_list->Dispatch(1, 1, 1);
- }
-
- // Query the amount of time spent in the intersection pass
- if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)
- {
- auto& timestamp_queries = timestamp_queries_[timestamp_queries_index_];
-
- FFX_SSSR_ASSERT(timestamp_queries.size() == 1ull && timestamp_queries[0] == kTimestampQuery_Init);
-
- command_list->EndQuery(timestamp_query_heap_,
- D3D12_QUERY_TYPE_TIMESTAMP,
- GetTimestampQueryIndex());
-
- timestamp_queries.push_back(kTimestampQuery_TileClassification);
- }
-
- // Ensure that the arguments are written
- D3D12_RESOURCE_BARRIER indirect_arguments_barriers[] = {
- UAVBarrier(intersection_pass_indirect_args_),
- UAVBarrier(denoiser_pass_indirect_args_),
- Transition(intersection_pass_indirect_args_, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT),
- Transition(denoiser_pass_indirect_args_, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT)
- };
- command_list->ResourceBarrier(FFX_SSSR_ARRAY_SIZE(indirect_arguments_barriers), indirect_arguments_barriers);
-
- // Intersection pass
- {
- command_list->SetComputeRootSignature(d3d12_context->GetIntersectionPass().root_signature_);
- command_list->SetComputeRootDescriptorTable(0, intersection_descriptor_table_[current_frame].GetGPUDescriptor());
- command_list->SetComputeRootConstantBufferView(1, cb_resource->GetGPUVirtualAddress() + offset);
- command_list->SetComputeRootDescriptorTable(2, sampler_descriptor_table_.GetGPUDescriptor());
- command_list->SetPipelineState(d3d12_context->GetIntersectionPass().pipeline_state_);
- command_list->ExecuteIndirect(d3d12_context->GetIndirectDispatchCommandSignature(), 1, intersection_pass_indirect_args_, 0, nullptr, 0);
- }
-
- // Query the amount of time spent in the intersection pass
- if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)
- {
- auto& timestamp_queries = timestamp_queries_[timestamp_queries_index_];
-
- FFX_SSSR_ASSERT(timestamp_queries.size() == 2ull && timestamp_queries[1] == kTimestampQuery_TileClassification);
-
- command_list->EndQuery(timestamp_query_heap_,
- D3D12_QUERY_TYPE_TIMESTAMP,
- GetTimestampQueryIndex());
-
- timestamp_queries.push_back(kTimestampQuery_Intersection);
- }
-
- if (resolve_reflection_view_info.flags & FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE)
- {
- // Ensure that the intersection pass finished
- command_list->ResourceBarrier(1, &UAVBarrier(temporal_denoiser_result_[current_frame]));
-
- // Spatial denoiser passes
- {
- command_list->SetComputeRootSignature(d3d12_context->GetSpatialDenoisingPass().root_signature_);
- command_list->SetComputeRootDescriptorTable(0, spatial_denoising_descriptor_table_[current_frame].GetGPUDescriptor());
- command_list->SetComputeRootConstantBufferView(1, cb_resource->GetGPUVirtualAddress() + offset);
- command_list->SetPipelineState(d3d12_context->GetSpatialDenoisingPass().pipeline_state_);
- command_list->ExecuteIndirect(d3d12_context->GetIndirectDispatchCommandSignature(), 1, denoiser_pass_indirect_args_, 0, nullptr, 0);
- }
-
- // Ensure that the spatial denoising pass finished. We don't have the resource for the final result available, thus we have to wait for any UAV access to finish.
- command_list->ResourceBarrier(1, &UAVBarrier(nullptr));
-
- // Temporal denoiser passes
- {
- command_list->SetComputeRootSignature(d3d12_context->GetTemporalDenoisingPass().root_signature_);
- command_list->SetComputeRootDescriptorTable(0, temporal_denoising_descriptor_table_[current_frame].GetGPUDescriptor());
- command_list->SetComputeRootConstantBufferView(1, cb_resource->GetGPUVirtualAddress() + offset);
- command_list->SetPipelineState(d3d12_context->GetTemporalDenoisingPass().pipeline_state_);
- command_list->ExecuteIndirect(d3d12_context->GetIndirectDispatchCommandSignature(), 1, denoiser_pass_indirect_args_, 0, nullptr, 0);
- }
-
- // Ensure that the temporal denoising pass finished
- command_list->ResourceBarrier(1, &UAVBarrier(temporal_denoiser_result_[current_frame]));
-
- // EAW denoiser passes
- {
- command_list->SetComputeRootSignature(d3d12_context->GetEawDenoisingPass().root_signature_);
- command_list->SetComputeRootDescriptorTable(0, eaw_denoising_descriptor_table_[current_frame].GetGPUDescriptor());
- command_list->SetComputeRootConstantBufferView(1, cb_resource->GetGPUVirtualAddress() + offset);
- command_list->SetPipelineState(d3d12_context->GetEawDenoisingPass().pipeline_state_);
- command_list->ExecuteIndirect(d3d12_context->GetIndirectDispatchCommandSignature(), 1, denoiser_pass_indirect_args_, 0, nullptr, 0);
- }
-
- // Query the amount of time spent in the denoiser passes
- if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)
- {
- auto& timestamp_queries = timestamp_queries_[timestamp_queries_index_];
-
- FFX_SSSR_ASSERT(timestamp_queries.size() == 3ull && timestamp_queries[2] == kTimestampQuery_Intersection);
-
- command_list->EndQuery(timestamp_query_heap_,
- D3D12_QUERY_TYPE_TIMESTAMP,
- GetTimestampQueryIndex());
-
- timestamp_queries.push_back(kTimestampQuery_Denoising);
- }
- }
-
- // Resolve the timestamp query data
- if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)
- {
- auto const start_index = timestamp_queries_index_ * kTimestampQuery_Count;
-
- command_list->ResolveQueryData(timestamp_query_heap_,
- D3D12_QUERY_TYPE_TIMESTAMP,
- start_index,
- static_cast(timestamp_queries_[timestamp_queries_index_].size()),
- timestamp_query_buffer_,
- start_index * sizeof(std::uint64_t));
-
- timestamp_queries_index_ = (timestamp_queries_index_ + 1u) % context.GetFrameCountBeforeReuse();
- }
- }
-}
diff --git a/ffx-sssr/src/d3d12/reflection_view_d3d12.h b/ffx-sssr/src/d3d12/reflection_view_d3d12.h
deleted file mode 100644
index 423be51..0000000
--- a/ffx-sssr/src/d3d12/reflection_view_d3d12.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-#include
-#include
-
-#include "macros.h"
-#include "matrix4.h"
-#include "ffx_sssr.h"
-#include "descriptor_heap_d3d12.h"
-
-namespace ffx_sssr
-{
- class Context;
- class ReflectionView;
-
- /**
- The ReflectionViewD3D12 class encapsulates the data required for resolving an individual reflection view.
- */
- class ReflectionViewD3D12
- {
- FFX_SSSR_NON_COPYABLE(ReflectionViewD3D12);
-
- public:
-
- /**
- The available timestamp queries.
- */
- enum TimestampQuery
- {
- kTimestampQuery_Init,
- kTimestampQuery_TileClassification,
- kTimestampQuery_Intersection,
- kTimestampQuery_Denoising,
-
- kTimestampQuery_Count
- };
-
- /**
- The type definition for an array of timestamp queries.
- */
- using TimestampQueries = std::vector;
-
- ReflectionViewD3D12();
- ~ReflectionViewD3D12();
-
- ReflectionViewD3D12(ReflectionViewD3D12&& other) noexcept;
- ReflectionViewD3D12& operator =(ReflectionViewD3D12&& other) noexcept;
-
- void Create(Context& context, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info);
- void Destroy();
-
- void CreateDescriptorHeaps(Context& context);
-
- std::uint32_t GetTimestampQueryIndex() const;
-
- void Resolve(Context& context, ReflectionView const& reflection_view, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info);
-
- // The width of the reflection view (in texels).
- std::uint32_t width_;
- // The height of the reflection view (in texels).
- std::uint32_t height_;
- // The reflection view creation flags.
- FfxSssrCreateReflectionViewFlags flags_;
-
- // The descriptor heap for CBVs, SRVs, and UAVs.
- DescriptorHeapD3D12* descriptor_heap_cbv_srv_uav_;
-
- // The descriptor heap for samplers.
- DescriptorHeapD3D12* descriptor_heap_samplers_;
-
- // Single heap containing all resources.
- ID3D12Heap * resource_heap_;
-
- // Containing all tiles that need at least one ray.
- ID3D12Resource * tile_list_;
- ID3D12Resource * tile_counter_;
- // Containing all rays that need to be traced.
- ID3D12Resource * ray_list_;
- ID3D12Resource * ray_counter_;
- // Indirect arguments for intersection pass.
- ID3D12Resource * intersection_pass_indirect_args_;
- // Indirect arguments for denoiser pass.
- ID3D12Resource * denoiser_pass_indirect_args_;
- // Intermediate result of the temporal denoising pass - double buffered to keep history and aliases the intersection result.
- ID3D12Resource * temporal_denoiser_result_[2];
- // Holds the length of each reflection ray - used for temporal reprojection.
- ID3D12Resource * ray_lengths_;
- // Holds the temporal variance of the last two frames.
- ID3D12Resource * temporal_variance_;
-
- // The number of GPU ticks spent in the tile classification pass.
- std::uint64_t tile_classification_elapsed_time_;
- // The number of GPU ticks spent in depth buffer intersection.
- std::uint64_t intersection_elapsed_time_;
- // The number of GPU ticks spent denoising.
- std::uint64_t denoising_elapsed_time_;
- // The query heap for the recorded timestamps.
- ID3D12QueryHeap * timestamp_query_heap_;
- // The buffer for reading the timestamp queries.
- ID3D12Resource * timestamp_query_buffer_;
- // The array of timestamp that were queried.
- std::vector timestamp_queries_;
- // The index of the active set of timestamp queries.
- std::uint32_t timestamp_queries_index_;
-
- // Format of the resolved scene.
- DXGI_FORMAT scene_format_;
-
- // The descriptor tables. One per shader pass per frame.
- // Even with more than 2 frames in flight we only swap between the last two
- // as we keep only one frame of history.
-
- // Descriptor tables of the tile classification pass.
- DescriptorD3D12 tile_classification_descriptor_table_[2];
- // Descriptor tables of the indirect arguments pass.
- DescriptorD3D12 indirect_args_descriptor_table_[2];
- // Descriptor tables of the depth buffer intersection pass.
- DescriptorD3D12 intersection_descriptor_table_[2];
- // Descriptor tables of the spatial denoising pass.
- DescriptorD3D12 spatial_denoising_descriptor_table_[2];
- // Descriptor tables of the temporal denoising pass.
- DescriptorD3D12 temporal_denoising_descriptor_table_[2];
- // Descriptor tables of the eaw denoising pass.
- DescriptorD3D12 eaw_denoising_descriptor_table_[2];
- // Descriptor tables for the environment map sampler.
- DescriptorD3D12 sampler_descriptor_table_;
-
- // The view projection matrix of the last frame.
- matrix4 prev_view_projection_;
- };
-}
diff --git a/ffx-sssr/src/d3d12/sampler_d3d12.cpp b/ffx-sssr/src/d3d12/sampler_d3d12.cpp
deleted file mode 100644
index 9d80b3b..0000000
--- a/ffx-sssr/src/d3d12/sampler_d3d12.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#include "sampler_d3d12.h"
-
-namespace ffx_sssr
-{
- /**
- The constructor for the BlueNoiseSamplerD3D12 class.
- */
- BlueNoiseSamplerD3D12::BlueNoiseSamplerD3D12()
- : sobol_buffer_(nullptr)
- , ranking_tile_buffer_(nullptr)
- , scrambling_tile_buffer_(nullptr)
- {
- }
-
- /**
- The constructor for the BlueNoiseSamplerD3D12 class.
-
- \param other The sampler to be moved.
- */
- BlueNoiseSamplerD3D12::BlueNoiseSamplerD3D12(BlueNoiseSamplerD3D12&& other) noexcept
- : sobol_buffer_(other.sobol_buffer_)
- , ranking_tile_buffer_(other.ranking_tile_buffer_)
- , scrambling_tile_buffer_(other.scrambling_tile_buffer_)
- {
- other.sobol_buffer_ = nullptr;
- other.ranking_tile_buffer_ = nullptr;
- other.scrambling_tile_buffer_ = nullptr;
- }
-
- /**
- The destructor for the BlueNoiseSamplerD3D12 class.
- */
- BlueNoiseSamplerD3D12::~BlueNoiseSamplerD3D12()
- {
- if (sobol_buffer_)
- sobol_buffer_->Release();
- if (ranking_tile_buffer_)
- ranking_tile_buffer_->Release();
- if (scrambling_tile_buffer_)
- scrambling_tile_buffer_->Release();
- }
-
- /**
- Assigns the sampler.
-
- \param other The sampler to be moved.
- \return The assigned sampler.
- */
- BlueNoiseSamplerD3D12& BlueNoiseSamplerD3D12::operator =(BlueNoiseSamplerD3D12&& other) noexcept
- {
- if (this != &other)
- {
- sobol_buffer_ = other.sobol_buffer_;
- ranking_tile_buffer_ = other.ranking_tile_buffer_;
- scrambling_tile_buffer_ = other.scrambling_tile_buffer_;
-
- other.sobol_buffer_ = nullptr;
- other.ranking_tile_buffer_ = nullptr;
- other.scrambling_tile_buffer_ = nullptr;
- }
-
- return *this;
- }
-}
diff --git a/ffx-sssr/src/d3d12/sampler_d3d12.h b/ffx-sssr/src/d3d12/sampler_d3d12.h
deleted file mode 100644
index 13dc989..0000000
--- a/ffx-sssr/src/d3d12/sampler_d3d12.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-
-#include "macros.h"
-#include "ffx_sssr.h"
-
-namespace ffx_sssr
-{
- /**
- The BlueNoiseSamplerD3D12 class represents a blue-noise sampler to be used for random number generation.
-
- \note Original implementation can be found here: https://eheitzresearch.wordpress.com/762-2/
- */
- class BlueNoiseSamplerD3D12
- {
- FFX_SSSR_NON_COPYABLE(BlueNoiseSamplerD3D12);
-
- public:
- BlueNoiseSamplerD3D12();
- ~BlueNoiseSamplerD3D12();
-
- BlueNoiseSamplerD3D12(BlueNoiseSamplerD3D12&& other) noexcept;
- BlueNoiseSamplerD3D12& BlueNoiseSamplerD3D12::operator =(BlueNoiseSamplerD3D12&& other) noexcept;
-
- // The Sobol sequence buffer.
- ID3D12Resource* sobol_buffer_;
- // The ranking tile buffer for sampling.
- ID3D12Resource* ranking_tile_buffer_;
- // The scrambling tile buffer for sampling.
- ID3D12Resource* scrambling_tile_buffer_;
- };
-}
diff --git a/ffx-sssr/src/d3d12/shader_compiler_d3d12.cpp b/ffx-sssr/src/d3d12/shader_compiler_d3d12.cpp
deleted file mode 100644
index cd01097..0000000
--- a/ffx-sssr/src/d3d12/shader_compiler_d3d12.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#include "shader_compiler_d3d12.h"
-
-#include
-#include
-#include
-
-#if FFX_SSSR_DUMP_SHADERS
-#include
-#endif // FFX_SSSR_DUMP_SHADERS
-
-#include "reflection_error.h"
-#include "utils.h"
-
-namespace ffx_sssr
-{
- /**
- The constructor for the ShaderCompilerD3D12 class.
-
- \param context The context to be used.
- */
- ShaderCompilerD3D12::ShaderCompilerD3D12(Context& context)
- : context_(context)
- , dxc_include_handler_(nullptr)
- , dxc_compiler_(nullptr)
- , dxc_library_(nullptr)
- {
- }
-
- /**
- The destructor for the ShaderCompilerD3D12 class.
- */
- ShaderCompilerD3D12::~ShaderCompilerD3D12()
- {
- if (dxc_compiler_)
- dxc_compiler_->Release();
- if (dxc_library_)
- dxc_library_->Release();
- if (dxc_include_handler_)
- dxc_include_handler_->Release();
-
- dxc_dll_support_.Cleanup();
- }
-
- /**
- Compiles the shader file.
-
- \param filename The location of the shader file.
- \param profile The targeted shader model.
- \param defines The list of defines to be used.
- \param define_count The number of defines.
- \return The compiled shader.
- */
- ShaderD3D12 ShaderCompilerD3D12::CompileShaderFile(char const* filename, char const* profile, LPCWSTR* arguments, std::uint32_t argument_count, DxcDefine* defines, std::uint32_t define_count)
- {
- HRESULT result;
- FFX_SSSR_ASSERT(filename && profile);
-
- if (!LoadShaderCompiler())
- {
- return ShaderD3D12();
- }
-
- // Compile the shader code from source
- IDxcBlobEncoding* dxc_source;
- auto const shader_filename = StringToWString(filename);
- result = dxc_library_->CreateBlobFromFile(shader_filename.c_str(), nullptr, &dxc_source);
- if (FAILED(result))
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_OPERATION, "Could not create shader blob from %s", filename);
-
- ShaderD3D12 shader = CompileShaderBlob(dxc_source, shader_filename.c_str(), profile, arguments, argument_count, defines, define_count);
-
- dxc_source->Release();
-
- return shader;
- }
-
- ShaderD3D12 ShaderCompilerD3D12::CompileShaderString(char const * string, std::uint32_t string_size, char const* shader_name, char const * profile, LPCWSTR * arguments, std::uint32_t argument_count, DxcDefine * defines, std::uint32_t define_count)
- {
- HRESULT result;
- FFX_SSSR_ASSERT(string && profile);
-
- if (!LoadShaderCompiler())
- {
- return ShaderD3D12();
- }
-
- IDxcBlobEncoding* dxc_source;
- result = dxc_library_->CreateBlobWithEncodingFromPinned((LPBYTE)string, string_size, 0, &dxc_source);
- if (FAILED(result))
- throw reflection_error(context_, FFX_SSSR_STATUS_INVALID_OPERATION, "Could not create blob with encoding from pinned for %s", shader_name);
-
- auto const wc_shader_name = StringToWString(shader_name);
-
- ShaderD3D12 shader = CompileShaderBlob(dxc_source, wc_shader_name.c_str(), profile, arguments, argument_count, defines, define_count);
-
- dxc_source->Release();
-
- return shader;
- }
-
- bool ShaderCompilerD3D12::LoadShaderCompiler()
- {
- // Load shader compiler
- if (!dxc_dll_support_.IsEnabled())
- {
- HRESULT result = dxc_dll_support_.Initialize();
- if (FAILED(result))
- throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to initialize dxcompiler.dll support");
-
- result = dxc_dll_support_.CreateInstance(CLSID_DxcCompiler, &dxc_compiler_);
- if (FAILED(result))
- throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to create DXC compiler instance");
-
- result = dxc_dll_support_.CreateInstance(CLSID_DxcLibrary, &dxc_library_);
- if (FAILED(result))
- throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to create DXC library instance");
-
- result = dxc_library_->CreateIncludeHandler(&dxc_include_handler_);
- if (FAILED(result))
- throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to create DXC include handler");
- }
- else if (!dxc_compiler_ || !dxc_library_)
- {
- return false; // failed to create DXC instances
- }
-
- return true;
- }
-
- ShaderD3D12 ShaderCompilerD3D12::CompileShaderBlob(IDxcBlob * dxc_source, wchar_t const * shader_name, char const * profile, LPCWSTR * arguments, std::uint32_t argument_count, DxcDefine * defines, std::uint32_t define_count)
- {
- HRESULT result;
-
- std::vector resolved_defines;
- resolved_defines.reserve(define_count);
-
- for (uint32_t i = 0; i < define_count; ++i)
- {
- if (defines[i].Name != nullptr)
- {
- resolved_defines.push_back(defines[i]);
- if (resolved_defines.back().Value == nullptr)
- {
- resolved_defines.back().Value = L"1";
- }
- }
- }
-
- ShaderD3D12 shader;
- IDxcOperationResult* dxc_result;
- auto const target_profile = StringToWString(profile);
- result = dxc_compiler_->Compile(dxc_source,
- shader_name,
- L"main",
- target_profile.c_str(),
- arguments,
- argument_count,
- resolved_defines.data(),
- static_cast(resolved_defines.size()),
- dxc_include_handler_,
- &dxc_result);
-
- // Check for compilation errors
- if (FAILED(result))
- throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to compile D3D12 shader source code");
- if (FAILED(dxc_result->GetStatus(&result)) || FAILED(result))
- {
- IDxcBlobEncoding* dxc_error;
- dxc_result->GetErrorBuffer(&dxc_error);
- std::string const error(static_cast(dxc_error->GetBufferPointer()));
- dxc_result->Release();
- dxc_error->Release();
- throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to compile shader file:\r\n> %s", error.c_str());
- }
-
- // Get hold of the program blob
- IDxcBlob* dxc_program = nullptr;
- dxc_result->GetResult(&dxc_program);
- FFX_SSSR_ASSERT(dxc_program != nullptr);
- dxc_result->Release();
-
-#if FFX_SSSR_DUMP_SHADERS
- IDxcBlobEncoding* disasm;
- HRESULT hr = dxc_compiler_->Disassemble(dxc_program, &disasm);
- if (SUCCEEDED(hr))
- {
- std::wstring path = shader_name + std::wstring(L".dxil.disasm");
- std::ofstream filestream(path.c_str());
- filestream.write((const char*)disasm->GetBufferPointer(), disasm->GetBufferSize());
- filestream.close();
- disasm->Release();
- }
-#endif // FFX_SSSR_DUMP_SHADERS
-
- // Retrieve the shader bytecode
- shader.BytecodeLength = dxc_program->GetBufferSize();
- auto const shader_bytecode = malloc(shader.BytecodeLength);
- FFX_SSSR_ASSERT(shader_bytecode != nullptr); // out of memory
- memcpy(shader_bytecode, dxc_program->GetBufferPointer(), shader.BytecodeLength);
- shader.pShaderBytecode = shader_bytecode;
- dxc_program->Release();
-
-#if FFX_SSSR_DUMP_SHADERS
- std::wstring path = shader_name + std::wstring(L".dxil");
- std::ofstream filestream(path.c_str(), std::ios::binary | std::ios::out);
- filestream.write((const char*)shader.pShaderBytecode, shader.BytecodeLength);
- filestream.close();
-#endif // FFX_SSSR_DUMP_SHADERS
-
- return shader;
- }
-}
diff --git a/ffx-sssr/src/d3d12/shader_compiler_d3d12.h b/ffx-sssr/src/d3d12/shader_compiler_d3d12.h
deleted file mode 100644
index f711ce1..0000000
--- a/ffx-sssr/src/d3d12/shader_compiler_d3d12.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-#include
-
-#include "macros.h"
-
-namespace ffx_sssr
-{
- class Context;
-
- /**
- The ShaderD3D12 class is a simple helper for freeing the shader bytecode upon destruction.
- */
- class ShaderD3D12 : public D3D12_SHADER_BYTECODE
- {
- FFX_SSSR_NON_COPYABLE(ShaderD3D12);
-
- public:
- inline ShaderD3D12();
- inline ~ShaderD3D12();
-
- inline operator bool() const;
-
- inline ShaderD3D12(ShaderD3D12&& other) noexcept;
- inline ShaderD3D12& operator =(ShaderD3D12&& other) noexcept;
- };
-
- /**
- The ShaderCompilerD3D12 class is a utility for compiling Direct3D12 shader code.
- */
- class ShaderCompilerD3D12
- {
- FFX_SSSR_NON_COPYABLE(ShaderCompilerD3D12);
-
- public:
- ShaderCompilerD3D12(Context& context);
- ~ShaderCompilerD3D12();
-
- ShaderD3D12 CompileShaderFile(char const* filename, char const* profile, LPCWSTR* arguments = nullptr, std::uint32_t argument_count = 0, DxcDefine* defines = nullptr, std::uint32_t define_count = 0u);
- ShaderD3D12 CompileShaderString(char const* string, std::uint32_t string_size, char const* shader_name, char const* profile, LPCWSTR* arguments = nullptr, std::uint32_t argument_count = 0, DxcDefine* defines = nullptr, std::uint32_t define_count = 0u);
-
- protected:
- bool LoadShaderCompiler();
- ShaderD3D12 CompileShaderBlob(IDxcBlob* dxc_source, wchar_t const* shader_name, char const* profile, LPCWSTR* arguments = nullptr, std::uint32_t argument_count = 0, DxcDefine* defines = nullptr, std::uint32_t define_count = 0u);
-
- // The context to be used.
- Context& context_;
- // A helper for loading the dxcompiler library.
- dxc::DxcDllSupport dxc_dll_support_;
- // The Direct3D12 include handler.
- IDxcIncludeHandler* dxc_include_handler_;
- // The Direct3D12 shader compiler.
- IDxcCompiler2* dxc_compiler_;
- // The Direct3D12 shader library.
- IDxcLibrary* dxc_library_;
- };
-}
-
-#include "shader_compiler_d3d12.inl"
diff --git a/ffx-sssr/src/d3d12/shader_compiler_d3d12.inl b/ffx-sssr/src/d3d12/shader_compiler_d3d12.inl
deleted file mode 100644
index ef1356b..0000000
--- a/ffx-sssr/src/d3d12/shader_compiler_d3d12.inl
+++ /dev/null
@@ -1,83 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-namespace ffx_sssr
-{
- /**
- The constructor for the ShaderD3D12 class.
- */
- ShaderD3D12::ShaderD3D12()
- {
- memset(this, 0, sizeof(*this));
- }
-
- /**
- The destructor for the ShaderD3D12 class.
- */
- ShaderD3D12::~ShaderD3D12()
- {
- free(const_cast(pShaderBytecode));
- }
-
- /**
- The constructor for the ShaderD3D12 class.
-
- \param other The shader to be moved.
- */
- ShaderD3D12::ShaderD3D12(ShaderD3D12&& other) noexcept
- {
- pShaderBytecode = other.pShaderBytecode;
- BytecodeLength = other.BytecodeLength;
-
- other.pShaderBytecode = nullptr;
- }
-
- /**
- Assigns the shader.
-
- \param other The shader to be moved.
- \return The assigned shader.
- */
- ShaderD3D12& ShaderD3D12::operator =(ShaderD3D12&& other) noexcept
- {
- if (this != &other)
- {
- pShaderBytecode = other.pShaderBytecode;
- BytecodeLength = other.BytecodeLength;
-
- other.pShaderBytecode = nullptr;
- }
-
- return *this;
- }
-
- /**
- Checks whether the shader is valid.
-
- \return true if the shader is valid, false otherwise.
- */
- ShaderD3D12::operator bool() const
- {
- return pShaderBytecode != nullptr;
- }
-}
diff --git a/ffx-sssr/src/d3d12/upload_buffer_d3d12.cpp b/ffx-sssr/src/d3d12/upload_buffer_d3d12.cpp
deleted file mode 100644
index 99973eb..0000000
--- a/ffx-sssr/src/d3d12/upload_buffer_d3d12.cpp
+++ /dev/null
@@ -1,175 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#include "upload_buffer_d3d12.h"
-
-#include "utils.h"
-#include "context.h"
-#include "context_d3d12.h"
-
-namespace ffx_sssr
-{
- /**
- The constructor for the UploadBufferD3D12 class.
-
- \param context The Direct3D12 context to be used.
- \param buffer_size The size of the upload buffer (in bytes).
- */
- UploadBufferD3D12::UploadBufferD3D12(ContextD3D12& context, std::size_t buffer_size)
- : data_(nullptr)
- , context_(context.GetContext())
- , buffer_(nullptr)
- , blocks_(buffer_size)
- {
- FFX_SSSR_ASSERT(context.GetDevice());
-
- D3D12_HEAP_PROPERTIES heap_properties = {};
- heap_properties.Type = D3D12_HEAP_TYPE_UPLOAD;
- heap_properties.CreationNodeMask = 1u;
- heap_properties.VisibleNodeMask = 1u;
-
- D3D12_RESOURCE_DESC resource_desc = {};
- resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- resource_desc.Width = static_cast(buffer_size);
- resource_desc.Height = 1u;
- resource_desc.DepthOrArraySize = 1u;
- resource_desc.MipLevels = 1u;
- resource_desc.SampleDesc.Count = 1u;
- resource_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
-
- if (!SUCCEEDED(context.GetDevice()->CreateCommittedResource(&heap_properties,
- D3D12_HEAP_FLAG_NONE,
- &resource_desc,
- D3D12_RESOURCE_STATE_GENERIC_READ,
- nullptr,
- IID_PPV_ARGS(&buffer_))))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %uMiB for the upload buffer", RoundedDivide(buffer_size, 1024ull * 1024ull));
- }
-
- D3D12_RANGE range = {};
- range.Begin = 0u;
- range.End = static_cast(buffer_size);
-
- if (!SUCCEEDED(buffer_->Map(0u,
- &range,
- reinterpret_cast(&data_))))
- {
- throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Cannot map the Direct3D12 upload buffer");
- }
-
- buffer_->SetName(L"UploadBufferRing");
- }
-
- /**
- The destructor for the UploadBufferD3D12 class.
- */
- UploadBufferD3D12::~UploadBufferD3D12()
- {
- if (buffer_)
- {
- if (data_)
- {
- D3D12_RANGE range = {};
- range.Begin = 0u;
- range.End = static_cast(buffer_->GetDesc().Width);
-
- buffer_->Unmap(0u, &range);
- }
-
- buffer_->Release();
- }
- }
-
- /**
- Allocates a buffer.
-
- \param size The size of the buffer (in bytes).
- \param gpu_address The GPU virtual address.
- \param data The pointer to the pinned memory.
- \return true if the buffer was allocated successfully, false otherwise.
- */
- bool UploadBufferD3D12::AllocateBuffer(std::size_t size, D3D12_GPU_VIRTUAL_ADDRESS& gpu_address, void*& data)
- {
- std::size_t start;
-
- auto const memory_block = blocks_.AcquireBlock(start, size, 256u);
-
- if (!memory_block)
- {
- return false;
- }
-
- data = static_cast(data_) + start;
- gpu_address = buffer_->GetGPUVirtualAddress() + start;
-
- memory_block->block_index_ = context_.GetFrameIndex();
- memory_block->frame_index_ = &context_.GetFrameIndex();
- memory_block->frame_count_before_reuse_ = context_.GetFrameCountBeforeReuse();
-
- return true;
- }
-
- /**
- Creates a constant buffer view for the allocated range.
-
- \param data The pointer to the allocated memory.
- \param size The size of the allocated range (in bytes).
- \param cpu_descriptor The CPU descriptor to be used.
- */
- void UploadBufferD3D12::CreateConstantBufferView(void const* data, std::size_t size, D3D12_CPU_DESCRIPTOR_HANDLE cpu_descriptor) const
- {
- auto const offset = static_cast(data) - static_cast(data_);
- FFX_SSSR_ASSERT(buffer_ && data >= data_ && offset + size <= buffer_->GetDesc().Width); // buffer overflow!
-
- D3D12_CONSTANT_BUFFER_VIEW_DESC constant_buffer_view_desc = {};
- constant_buffer_view_desc.BufferLocation = buffer_->GetGPUVirtualAddress() + offset;
- constant_buffer_view_desc.SizeInBytes = static_cast(Align(size, 256ull));
-
- context_.GetContextD3D12()->GetDevice()->CreateConstantBufferView(&constant_buffer_view_desc,
- cpu_descriptor);
- }
-
- /**
- Creates a shader resource view for the allocated range.
-
- \param data The pointer to the allocated memory.
- \param size The size of the allocated range (in bytes).
- \param stride The size of an individual element (in bytes).
- \param cpu_descriptor The CPU descriptor to be used.
- */
- void UploadBufferD3D12::CreateShaderResourceView(void const* data, std::size_t size, std::size_t stride, D3D12_CPU_DESCRIPTOR_HANDLE cpu_descriptor) const
- {
- auto const offset = static_cast(data) - static_cast(data_);
- FFX_SSSR_ASSERT(buffer_ && data >= data_ && offset + size <= buffer_->GetDesc().Width); // buffer overflow!
-
- D3D12_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {};
- shader_resource_view_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
- shader_resource_view_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- shader_resource_view_desc.Buffer.FirstElement = static_cast(offset / stride);
- shader_resource_view_desc.Buffer.NumElements = static_cast(size / stride);
- shader_resource_view_desc.Buffer.StructureByteStride = static_cast(stride);
-
- context_.GetContextD3D12()->GetDevice()->CreateShaderResourceView(buffer_,
- &shader_resource_view_desc,
- cpu_descriptor);
- }
-}
diff --git a/ffx-sssr/src/d3d12/upload_buffer_d3d12.h b/ffx-sssr/src/d3d12/upload_buffer_d3d12.h
deleted file mode 100644
index f47c4e7..0000000
--- a/ffx-sssr/src/d3d12/upload_buffer_d3d12.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-
-#include "memory.h"
-
-namespace ffx_sssr
-{
- class Context;
- class ContextD3D12;
-
- /**
- The UploadBufferD3D12 class allows to transfer some memory from the CPU to the GPU.
- */
- class UploadBufferD3D12
- {
- FFX_SSSR_NON_COPYABLE(UploadBufferD3D12);
-
- public:
- UploadBufferD3D12(ContextD3D12& context, std::size_t buffer_size);
- ~UploadBufferD3D12();
-
- inline std::size_t GetSize() const;
- inline ID3D12Resource* GetResource() const;
- inline std::size_t GetOffset(void *data) const;
-
- template
- bool AllocateBuffer(std::size_t size, TYPE*& data);
- template
- bool AllocateBuffer(std::size_t size, TYPE*& data, D3D12_GPU_VIRTUAL_ADDRESS& gpu_address);
-
- void CreateConstantBufferView(void const* data, std::size_t size, D3D12_CPU_DESCRIPTOR_HANDLE cpu_descriptor) const;
- void CreateShaderResourceView(void const* data, std::size_t size, std::size_t stride, D3D12_CPU_DESCRIPTOR_HANDLE cpu_descriptor) const;
-
- protected:
- bool AllocateBuffer(std::size_t size, D3D12_GPU_VIRTUAL_ADDRESS& gpu_address, void*& data);
-
- /**
- The Block class represents an individual synchronizable block to be upload for memory upload.
- */
- class Block
- {
- public:
- inline Block();
-
- inline bool CanBeReused() const;
-
- // The index of the currently calculated frame.
- std::uint32_t* frame_index_;
- // The frame at which this block was created.
- std::uint32_t block_index_;
- // The number of elapsed frames before re-use.
- std::uint32_t frame_count_before_reuse_;
- };
-
- // The pointer to the mapped data.
- void* data_;
- // The context to be used.
- Context& context_;
- // The resource to the upload buffer.
- ID3D12Resource* buffer_;
- // The available blocks for memory upload.
- RingBuffer blocks_;
- };
-}
-
-#include "upload_buffer_d3d12.inl"
diff --git a/ffx-sssr/src/d3d12/upload_buffer_d3d12.inl b/ffx-sssr/src/d3d12/upload_buffer_d3d12.inl
deleted file mode 100644
index 62109ec..0000000
--- a/ffx-sssr/src/d3d12/upload_buffer_d3d12.inl
+++ /dev/null
@@ -1,128 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-namespace ffx_sssr
-{
- /**
- The constructor for the Block class.
- */
- UploadBufferD3D12::Block::Block()
- : frame_index_(nullptr)
- , block_index_(0u)
- , frame_count_before_reuse_(0u)
- {
- }
-
- /**
- Checks whether the memory block can now be re-used.
-
- \return true if the memory block can be re-used, false otherwise.
- */
- bool UploadBufferD3D12::Block::CanBeReused() const
- {
- FFX_SSSR_ASSERT(frame_index_ && *frame_index_ >= block_index_);
-
- return (*frame_index_ - block_index_ >= frame_count_before_reuse_);
- }
-
- /**
- Gets the size of the upload buffer.
-
- \return The size of the upload buffer (in bytes).
- */
- std::size_t UploadBufferD3D12::GetSize() const
- {
- return static_cast(buffer_ ? buffer_->GetDesc().Width : 0ull);
- }
-
- /**
- Gets the resource for the upload buffer.
-
- \return The resource for the upload buffer.
- */
- ID3D12Resource* UploadBufferD3D12::GetResource() const
- {
- return buffer_;
- }
-
- /**
- Gets the offset for the allocate range of memory.
-
- \param data The allocated range of memory.
- \return The offset within the upload buffer (in bytes).
- */
- std::size_t UploadBufferD3D12::GetOffset(void* data) const
- {
- if (!data)
- return 0ull;
- auto const offset = static_cast(data) - static_cast(data_);
- FFX_SSSR_ASSERT(buffer_ && data >= data_ && static_cast(offset) < buffer_->GetDesc().Width); // buffer overflow!
- return static_cast(offset);
- }
-
- /**
- Allocates a buffer.
-
- \param size The size of the buffer (in bytes).
- \param data The pointer to the pinned memory.
- \return true if the buffer was allocated successfully, false otherwise.
- */
- template
- bool UploadBufferD3D12::AllocateBuffer(std::size_t size, TYPE*& data)
- {
- void* data_internal;
- D3D12_GPU_VIRTUAL_ADDRESS gpu_address_unused;
-
- if (!AllocateBuffer(Align(size, 256ull), gpu_address_unused, data_internal))
- {
- return false;
- }
-
- data = static_cast(data_internal);
-
- return true;
- }
-
- /**
- Allocates a buffer.
-
- \param size The size of the buffer (in bytes).
- \param data The pointer to the pinned memory.
- \param gpu_address The GPU virtual address.
- \return true if the buffer was allocated successfully, false otherwise.
- */
- template
- bool UploadBufferD3D12::AllocateBuffer(std::size_t size, TYPE*& data, D3D12_GPU_VIRTUAL_ADDRESS& gpu_address)
- {
- void* data_internal;
-
- if (!AllocateBuffer(size, gpu_address, data_internal))
- {
- return false;
- }
-
- data = static_cast(data_internal);
-
- return true;
- }
-}
diff --git a/ffx-sssr/src/float3.h b/ffx-sssr/src/float3.h
deleted file mode 100644
index 10c57a9..0000000
--- a/ffx-sssr/src/float3.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-#include
-
-namespace ffx_sssr
-{
- /**
- The tfloat3 class represents a generic 3-wide vector.
- */
- template
- class tfloat3
- {
- public:
- inline tfloat3();
- inline tfloat3(TYPE v);
- inline tfloat3(TYPE x, TYPE y, TYPE z, TYPE w = static_cast(0));
- template
- inline tfloat3(tfloat3 const& other);
-
- inline tfloat3 operator -() const;
- inline tfloat3 operator /(TYPE f) const;
- inline TYPE& operator [](std::uint32_t i);
- inline TYPE operator [](std::uint32_t i) const;
-
- inline TYPE sqnorm() const;
- inline TYPE norm() const;
-
- static inline tfloat3 normalize(tfloat3 const& v);
-
- // The vector X component.
- TYPE x;
- // The vector Y component.
- TYPE y;
- // The vector Z component.
- TYPE z;
- // The vector W component.
- TYPE w;
- };
-
- /**
- A type definition for a single precision floating-point 3-wide vector.
- */
- typedef tfloat3 float3;
-
- /**
- A type definition for a double precision floating-point 3-wide vector.
- */
- typedef tfloat3 double3;
-
- /**
- A type definition for a single precision floating-point 4-wide vector.
- */
- typedef float3 float4;
-
- /**
- A type definition for a double precision floating-point 4-wide vector.
- */
- typedef double3 double4;
-}
-
-#include "float3.inl"
diff --git a/ffx-sssr/src/float3.inl b/ffx-sssr/src/float3.inl
deleted file mode 100644
index fb06f69..0000000
--- a/ffx-sssr/src/float3.inl
+++ /dev/null
@@ -1,170 +0,0 @@
-#include "float3.h"
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-namespace ffx_sssr
-{
- /**
- The constructor for the tfloat3 class.
- */
- template
- tfloat3::tfloat3()
- : x(static_cast(0))
- , y(static_cast(0))
- , z(static_cast(0))
- , w(static_cast(0))
- {
- }
-
- /**
- The constructor for the tfloat3 class.
-
- \param v The value for initializing the vector.
- */
- template
- tfloat3::tfloat3(TYPE v)
- : x(v)
- , y(v)
- , z(v)
- , w(v)
- {
- }
-
- /**
- The constructor for the tfloat3 class.
-
- \param x The vector X component.
- \param y The vector Y component.
- \param z The vector Z component.
- \param w The vector W component.
- */
- template
- tfloat3::tfloat3(TYPE x, TYPE y, TYPE z, TYPE w)
- : x(x)
- , y(y)
- , z(z)
- , w(w)
- {
- }
-
- /**
- The constructor for the tfloat3 class.
-
- \param other The vector to be constructing from.
- */
- template
- template
- tfloat3::tfloat3(tfloat3 const& other)
- : x(static_cast(other.x))
- , y(static_cast(other.y))
- , z(static_cast(other.z))
- , w(static_cast(other.w))
- {
- }
-
- /**
- Gets the negative vector.
-
- \return The negative vector.
- */
- template
- tfloat3 tfloat3::operator -() const
- {
- return tfloat3(-x, -y, -z);
- }
-
- /**
- Divides each component by the provided number.
-
- \return The resulting vector.
- */
- template
- inline tfloat3 tfloat3::operator/(TYPE f) const
- {
- return tfloat3(x / f, y / f, z / f, w / f);
- }
-
- /**
- Gets the given vector component.
-
- \param i The index of the vector component.
- \return The requested vector component.
- */
- template
- TYPE& tfloat3::operator [](std::uint32_t i)
- {
- return *(&x + i);
- }
-
- /**
- Gets the given vector component.
-
- \param i The index of the vector component.
- \return The requested vector component.
- */
- template
- TYPE tfloat3::operator [](std::uint32_t i) const
- {
- return *(&x + i);
- }
-
- /**
- Calculates the squared norm of the vector.
-
- \return The squared norm of the vector.
- */
- template
- TYPE tfloat3::sqnorm() const
- {
- return x * x + y * y + z * z;
- }
-
- /**
- Calculates the norm of the vector.
-
- \return The norm of the vector.
- */
- template
- TYPE tfloat3::norm() const
- {
- return std::sqrt(sqnorm());
- }
-
- /**
- Normalizes the input vector.
-
- \param v The vector to be normalized.
- \return The normalized vector.
- */
- template
- tfloat3 tfloat3::normalize(tfloat3 const& v)
- {
- auto result = v;
- auto const norm_inv = static_cast(1) / v.norm();
- result.x *= norm_inv;
- result.y *= norm_inv;
- result.z *= norm_inv;
- result.w *= norm_inv;
- return result;
- }
-}
diff --git a/ffx-sssr/src/macros.h b/ffx-sssr/src/macros.h
deleted file mode 100644
index 710e10d..0000000
--- a/ffx-sssr/src/macros.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include
-#include
-
-#ifdef _MSC_VER
-
- #define WIN32_LEAN_AND_MEAN
- #include
-
- #undef max
- #undef min
-
-#endif // _MSC_VER
-
-/**
- Gets the size of a static array.
-
- \return The size of the static array.
-*/
-#define FFX_SSSR_ARRAY_SIZE(ARRAY) \
- static_cast(sizeof(ARRAY) / sizeof(*(ARRAY)))
-
-/**
- Makes the type non-copyable.
-
- \param TYPE - The type to be made non-copyable.
-*/
-#define FFX_SSSR_NON_COPYABLE(TYPE) \
- TYPE(TYPE const&) = delete; \
- TYPE& operator =(TYPE const&) = delete
-
-#ifdef _MSC_VER
-
- /**
- A macro to start a do while loop.
- */
- #define FFX_SSSR_MULTI_LINE_MACRO_BEGIN \
- __pragma(warning(push)) \
- __pragma(warning(disable:4127)) /* conditional expression is constant */ \
- __pragma(warning(disable:4390)) /* empty controlled statement found */ \
- do \
- {
-
- /**
- A macro to end a do while loop.
- */
- #define FFX_SSSR_MULTI_LINE_MACRO_END \
- } \
- while (0) \
- __pragma(warning(pop))
-
- /**
- Triggers a breakpoint.
- */
- #define FFX_SSSR_BREAKPOINT \
- FFX_SSSR_MULTI_LINE_MACRO_BEGIN \
- if (IsDebuggerPresent()) \
- { \
- DebugBreak(); \
- } \
- FFX_SSSR_MULTI_LINE_MACRO_END
-
-#else // _MSC_VER
-
- /**
- A macro to start a do while loop.
- */
- #define FFX_SSSR_MULTI_LINE_MACRO_BEGIN \
- do \
- {
-
- /**
- A macro to end a do while loop.
- */
- #define FFX_SSSR_MULTI_LINE_MACRO_END \
- } \
- while (0)
-
- /**
- Triggers a breakpoint.
- */
- #define FFX_SSSR_BREAKPOINT \
- FFX_SSSR_MULTI_LINE_MACRO_BEGIN \
- assert(0); \
- FFX_SSSR_MULTI_LINE_MACRO_END
-
-#endif // _MSC_VER
-
-#ifdef _DEBUG
-
- /**
- Defines a condition breakpoint that only triggers if the expression evaluates to false.
-
- \param expr The expression to evaluate.
- */
- #define FFX_SSSR_ASSERT(expr) \
- FFX_SSSR_MULTI_LINE_MACRO_BEGIN \
- if (!(expr)) \
- { \
- FFX_SSSR_BREAKPOINT; \
- } \
- FFX_SSSR_MULTI_LINE_MACRO_END
-
-#else // _DEBUG
-
- /**
- Ignores the breakpoint condition in a Release build.
-
- \param expr The expression to be ignored.
- */
- #define FFX_SSSR_ASSERT(expr) \
- FFX_SSSR_MULTI_LINE_MACRO_BEGIN \
- sizeof(expr); \
- FFX_SSSR_MULTI_LINE_MACRO_END
-
-#endif // _DEBUG
diff --git a/ffx-sssr/src/matrix4.h b/ffx-sssr/src/matrix4.h
deleted file mode 100644
index 03934ae..0000000
--- a/ffx-sssr/src/matrix4.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-#include "float3.h"
-
-namespace ffx_sssr
-{
- /**
- The tmatrix4 class represents a generic 4x4 matrix.
- */
- template
- class tmatrix4
- {
- public:
- inline tmatrix4();
- template
- inline tmatrix4(tmatrix4 const& other);
-
- inline tmatrix4 transpose() const;
- inline tmatrix4 operator -() const;
-
- inline tmatrix4& operator +=(tmatrix4 const& other);
- inline tmatrix4& operator -=(tmatrix4 const& other);
- inline tmatrix4& operator *=(tmatrix4 const& other);
- inline tmatrix4& operator *=(TYPE value);
-
- static inline tmatrix4 inverse(tmatrix4 const& m);
-
- // The underlying matrix data.
- union
- {
- TYPE m[4][4];
- struct
- {
- TYPE m00, m01, m02, m03;
- TYPE m10, m11, m12, m13;
- TYPE m20, m21, m22, m23;
- TYPE m30, m31, m32, m33;
- };
- };
- };
-
- /**
- A type definition for a single precision floating-point 4x4 matrix.
- */
- typedef tmatrix4 matrix4;
-
- /**
- A type definition for a double precision floating-point 4x4 matrix.
- */
- typedef tmatrix4 dmatrix4;
-}
-
-#include "matrix4.inl"
diff --git a/ffx-sssr/src/matrix4.inl b/ffx-sssr/src/matrix4.inl
deleted file mode 100644
index 6fb96b9..0000000
--- a/ffx-sssr/src/matrix4.inl
+++ /dev/null
@@ -1,321 +0,0 @@
-/**********************************************************************
-Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-********************************************************************/
-#pragma once
-
-namespace ffx_sssr
-{
- /**
- The constructor for the tmatrix4 class.
- */
- template
- tmatrix4::tmatrix4()
- : m00(static_cast(1)), m01(static_cast(0)), m02(static_cast(0)), m03(static_cast(0))
- , m10(static_cast(0)), m11(static_cast(1)), m12(static_cast(0)), m13(static_cast(0))
- , m20(static_cast(0)), m21(static_cast(0)), m22(static_cast(1)), m23(static_cast(0))
- , m30(static_cast(0)), m31(static_cast(0)), m32(static_cast