diff --git a/.gitattributes b/.gitattributes index ad73556..e67c8b8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ *.jpg filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text *.gltf filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1845a4f..e675369 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,79 +1,41 @@ variables: - SampleName: SSSRSample - SolutionDirDX12: sample\build\DX12 - SolutionDX12: SSSRSample_DX12.sln + SampleName: SssrSample GIT_SUBMODULE_STRATEGY: normal -before_script: - - 'for /f "usebackq delims=" %%i in (`vswhere.exe -version "[15.0,16.0)" -products Microsoft.VisualStudio.Product.BuildTools -property installationPath`) do set MSBUILD_PATH=%%i' - - 'call "%MSBUILD_PATH%\VC\Auxiliary\Build\vcvars64.bat"' - - 'cd sample\build' - - 'call GenerateSolutions.bat -T v141' - - 'cd ..\..' - stages: - build - deploy -build d3d12 sample release: +build_dx12: tags: - windows - amd64 - stage: deploy - except: - - tags + stage: build script: - - echo Building "%SolutionDX12%" - - cd %SolutionDirDX12% - - 'msbuild.exe "%SolutionDX12%" /p:Configuration=Release /p:Platform=x64' - - cd ../../.. - - mkdir %SampleName% - - copy sample\src\Common bin - - move sample\bin %SampleName% - - move sample\media %SampleName% - - move sample\README.md %SampleName% - - move sample\screenshot.png %SampleName% - - move NOTICES.txt %SampleName% - - echo cd .\%SampleName%\bin\ > %SampleName%_DX12.bat - - echo start %SampleName%_DX12.exe >> %SampleName%_DX12.bat + - 'cmake -S sample -B sample/build/DX12 -G "Visual Studio 15 2017" -A x64 -DGFX_API=DX12' + - 'cmake --build sample/build/DX12 --config Release' artifacts: - name: "%SampleName%-%CI_COMMIT_REF_NAME%-%CI_COMMIT_SHORT_SHA%" paths: - - "%SampleName%/bin/" - - "%SampleName%/media/" - - "%SampleName%/NOTICES.txt" - - "%SampleName%/README.md" - - "%SampleName%/screenshot.png" - - "%SampleName%_DX12.bat" - -build d3d12 sample release tagged: + - sample/bin/ + +package_sample: tags: - windows - amd64 stage: deploy - only: - - tags + dependencies: + - build_dx12 script: - - echo Building "%SolutionDX12%" - - cd %SolutionDirDX12% - - 'msbuild.exe "%SolutionDX12%" /p:Configuration=Release /p:Platform=x64' - - cd ../../.. - - mkdir %SampleName% - - copy sample\src\Common bin - - move sample\bin %SampleName% - - move sample\media %SampleName% - - move sample\README.md %SampleName% - - move sample\screenshot.png %SampleName% - - move NOTICES.txt %SampleName% - - echo cd .\%SampleName%\bin\ > %SampleName%_DX12.bat + - echo "Packaging build" + - echo cd .\sample\bin\ > %SampleName%_DX12.bat - echo start %SampleName%_DX12.exe >> %SampleName%_DX12.bat artifacts: - name: "%SampleName%-%CI_COMMIT_TAG%" + name: "%SampleName%-%CI_COMMIT_TAG%-%CI_COMMIT_REF_NAME%-%CI_COMMIT_SHORT_SHA%" paths: - - "%SampleName%/bin/" - - "%SampleName%/media/" - - "%SampleName%/NOTICES.txt" - - "%SampleName%/README.md" - - "%SampleName%/screenshot.png" - - "%SampleName%_DX12.bat" - + - NOTICES.txt + - sample/README.md + - sample/screenshot.png + - sample/bin/ + - sample/media/ + - docs/ + - "%SampleName%_DX12.bat" \ No newline at end of file diff --git a/docs/FFX_SSSR_API.pdf b/docs/FFX_SSSR_API.pdf new file mode 100644 index 0000000..c56f1e5 Binary files /dev/null and b/docs/FFX_SSSR_API.pdf differ diff --git a/docs/FFX_SSSR_GUI.pdf b/docs/FFX_SSSR_GUI.pdf new file mode 100644 index 0000000..c1538dd Binary files /dev/null and b/docs/FFX_SSSR_GUI.pdf differ diff --git a/docs/FFX_SSSR_Technology.pdf b/docs/FFX_SSSR_Technology.pdf new file mode 100644 index 0000000..61e864d Binary files /dev/null and b/docs/FFX_SSSR_Technology.pdf differ diff --git a/ffx-sssr/CMakeLists.txt b/ffx-sssr/CMakeLists.txt index 49e5678..986bbab 100644 --- a/ffx-sssr/CMakeLists.txt +++ b/ffx-sssr/CMakeLists.txt @@ -4,8 +4,8 @@ project(stochastic-screen-space-reflections) find_package(PythonInterp 3.6 REQUIRED) -option(SSSR_NO_D3D12 "Stochastic Screen Space Reflections - Skip D3D12 backend" OFF) -option(SSSR_NO_VK "Stochastic Screen Space Reflections - Skip VK backend" OFF) +option(FFX_SSSR_NO_D3D12 "Stochastic Screen Space Reflections - Skip D3D12 backend" OFF) +option(FFX_SSSR_NO_VK "Stochastic Screen Space Reflections - Skip VK backend" OFF) set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -15,39 +15,39 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Werror -std=c++17") endif() -file(GLOB SSSR_HEADER_FILES +file(GLOB FFX_SSSR_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/inc/ffx_sssr.h ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) -file(GLOB SSSR_INLINE_FILES +file(GLOB FFX_SSSR_INLINE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.inl) -file(GLOB SSSR_SOURCE_FILES +file(GLOB FFX_SSSR_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) -file(GLOB SSSR_SHADER_FILES +file(GLOB FFX_SSSR_SHADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.hlsl) -if(SSSR_NO_D3D12) +if(FFX_SSSR_NO_D3D12) else() - file(GLOB SSSR_HEADER_FILES_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 SSSR_INLINE_FILES_D3D12 + file(GLOB FFX_SSSR_INLINE_FILES_D3D12 ${CMAKE_CURRENT_SOURCE_DIR}/src/d3d12/*.inl) - file(GLOB SSSR_SOURCE_FILES_D3D12 + file(GLOB FFX_SSSR_SOURCE_FILES_D3D12 ${CMAKE_CURRENT_SOURCE_DIR}/src/d3d12/*.cpp) endif() -if(SSSR_NO_VK) +if(FFX_SSSR_NO_VK) else() - file(GLOB SSSR_HEADER_FILES_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 SSSR_INLINE_FILES_VK + file(GLOB FFX_SSSR_INLINE_FILES_VK ${CMAKE_CURRENT_SOURCE_DIR}/src/vk/*.inl) - file(GLOB SSSR_SOURCE_FILES_VK + file(GLOB FFX_SSSR_SOURCE_FILES_VK ${CMAKE_CURRENT_SOURCE_DIR}/src/vk/*.cpp) endif() -set(SSSR_HEADER_FILES_SHADERS) +set(FFX_SSSR_HEADER_FILES_SHADERS) foreach(shaderfile classify_tiles common @@ -69,15 +69,15 @@ foreach(shaderfile classify_tiles "Generate shader header shader_${shaderfile}.h for ${shaderfile}.hlsl" USES_TERMINAL) - list(APPEND SSSR_HEADER_FILES_SHADERS "${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader_${shaderfile}.h") + list(APPEND FFX_SSSR_HEADER_FILES_SHADERS "${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader_${shaderfile}.h") endforeach() add_library(FFX_SSSR - ${SSSR_SOURCE_FILES} - ${SSSR_SOURCE_FILES_D3D12} - ${SSSR_SOURCE_FILES_VK} - ${SSSR_HEADER_FILES_SHADERS}) + ${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) @@ -87,39 +87,39 @@ target_include_directories(FFX_SSSR PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/external 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(SSSR_NO_D3D12) - target_compile_definitions(FFX_SSSR PRIVATE SSSR_NO_D3D12) +if(FFX_SSSR_NO_D3D12) + target_compile_definitions(FFX_SSSR PRIVATE FFX_SSSR_NO_D3D12) endif() -if(SSSR_NO_VK) - target_compile_definitions(FFX_SSSR PRIVATE SSSR_NO_VK) +if(FFX_SSSR_NO_VK) + target_compile_definitions(FFX_SSSR PRIVATE FFX_SSSR_NO_VK) endif() target_sources(FFX_SSSR PRIVATE - ${SSSR_HEADER_FILES} - ${SSSR_INLINE_FILES} - ${SSSR_SHADER_FILES} - ${SSSR_HEADER_FILES_D3D12} - ${SSSR_INLINE_FILES_D3D12} - ${SSSR_HEADER_FILES_VK} - ${SSSR_INLINE_FILES_VK}) + ${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 ${SSSR_HEADER_FILES_SHADERS}) +source_group("Header Files\\Shaders" FILES ${FFX_SSSR_HEADER_FILES_SHADERS}) -source_group("Inline Files" FILES ${SSSR_INLINE_FILES}) -source_group("Media Files\\Shaders" FILES ${SSSR_SHADER_FILES}) +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 ${SSSR_HEADER_FILES_D3D12}) -source_group("Inline Files\\D3D12" FILES ${SSSR_INLINE_FILES_D3D12}) -source_group("Source Files\\D3D12" FILES ${SSSR_SOURCE_FILES_D3D12}) +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 ${SSSR_HEADER_FILES_VK}) -source_group("Inline Files\\VK" FILES ${SSSR_INLINE_FILES_VK}) -source_group("Source Files\\VK" FILES ${SSSR_SOURCE_FILES_VK}) +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(${SSSR_SHADER_FILES} + set_source_files_properties(${FFX_SSSR_SHADER_FILES} PROPERTIES VS_TOOL_OVERRIDE "None") diff --git a/ffx-sssr/README.md b/ffx-sssr/README.md index a1cf836..319fb3d 100644 --- a/ffx-sssr/README.md +++ b/ffx-sssr/README.md @@ -17,57 +17,57 @@ First the header files must be included. This is `ffx_sssr.h` for Graphics API i Then a context must be created. This usually is done only once per device. ```C++ -SssrCreateContextInfoD3D12 d3d12ContextInfo = {}; +FfxSssrD3D12CreateContextInfo d3d12ContextInfo = {}; d3d12ContextInfo.pDevice = myDevice; d3d12ContextInfo.pUploadCommandList = myCommandList; -SssrLoggingCallbacks loggingCallbacks = {}; +FfxSssrLoggingCallbacks loggingCallbacks = {}; loggingCallbacks.pUserData = myUserData; loggingCallbacks.pfnLogging = myLoggingFunction; -SssrCreateContextInfo contextInfo = {}; -contextInfo.apiVersion = SSSR_API_VERSION; +FfxSssrCreateContextInfo contextInfo = {}; +contextInfo.apiVersion = FFX_SSSR_API_VERSION; contextInfo.maxReflectionViewCount = myMaxViewCount; contextInfo.frameCountBeforeMemoryReuse = myMaxFrameCountInFlight; contextInfo.uploadBufferSize = 8 * 1024 * 1024; contextInfo.pLoggingCallbacks = &loggingCallbacks; -contextInfo.pCreateContextInfoD3D12 = &d3d12ContextInfo; +contextInfo.pD3D12CreateContextInfo = &d3d12ContextInfo; ``` The library requires certain input textures from the application to create a reflection view. Thus, the context requires user specified unpack functions (HLSL) to access the individual attributes. It is recommended to keep these snippets as small as possible to guarantee good performance. -The function headers have to match in order for the shaders to compile. The `SSR_*_TEXTURE_FORMAT` macros hold the definitions provided in the `p*TextureFormat` members of `SssrCreateContextInfo`. The snippets provided below shall serve as a starting point: +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 SssrUnpackRoughness(SSR_ROUGHNESS_TEXTURE_FORMAT packed) { return packed.w; }"; +contextInfo.pUnpackRoughnessSnippet = L"float FfxSssrUnpackRoughness(FFX_SSSR_ROUGHNESS_TEXTURE_FORMAT packed) { return packed.w; }"; contextInfo.pNormalsTextureFormat = L"float4"; -contextInfo.pUnpackNormalsSnippet = L"float3 SssrUnpackNormals(SSR_NORMALS_TEXTURE_FORMAT packed) { return 2 * packed.xyz - 1; }"; +contextInfo.pUnpackNormalsSnippet = L"float3 FfxSssrUnpackNormals(FFX_SSSR_NORMALS_TEXTURE_FORMAT packed) { return 2 * packed.xyz - 1; }"; contextInfo.pSceneTextureFormat = L"float4"; -contextInfo.pUnpackSceneRadianceSnippet = L"float3 SssrUnpackSceneRadiance(SSR_SCENE_TEXTURE_FORMAT packed) { return packed.xyz; }"; +contextInfo.pUnpackSceneRadianceSnippet = L"float3 FfxSssrUnpackSceneRadiance(FFX_SSSR_SCENE_TEXTURE_FORMAT packed) { return packed.xyz; }"; contextInfo.pDepthTextureFormat = L"float"; -contextInfo.pUnpackDepthSnippet = L"float SssrUnpackDepth(SSR_DEPTH_TEXTURE_FORMAT packed) { return packed.x; }"; +contextInfo.pUnpackDepthSnippet = L"float FfxSssrUnpackDepth(FFX_SSSR_DEPTH_TEXTURE_FORMAT packed) { return packed.x; }"; contextInfo.pMotionVectorFormat = L"float2"; -contextInfo.pUnpackMotionVectorsSnippet = L"float2 SssrUnpackMotionVectors(SSR_MOTION_VECTOR_TEXTURE_FORMAT packed) { return packed.xy; }"; +contextInfo.pUnpackMotionVectorsSnippet = L"float2 FfxSssrUnpackMotionVectors(FFX_SSSR_MOTION_VECTOR_TEXTURE_FORMAT packed) { return packed.xy; }"; ``` After that the context can be created: ```C++ -SssrContext myContext; -SssrStatus status = sssrCreateContext(&contextInfo, &myContext); -if (status != SSSR_STATUS_OK) { +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 `SssrCreateContextInfoD3D12` to the queue of your choice to upload the internal resources to the GPU. +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. Once there is no need to render reflections anymore the context should be destroyed to free internal resources: ```C++ -SssrStatus status = sssrDestroyContext(myContext); -if (status != SSSR_STATUS_OK) { +FfxSssrStatus status = ffxSssrDestroyContext(myContext); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` @@ -76,10 +76,10 @@ if (status != SSSR_STATUS_OK) { Reflection views represent the abstraction for the first bounce of indirect light from reflective surfaces as seen from a given camera. -`SssrReflectionView` resources can be created as such: +`FfxSssrReflectionView` resources can be created as such: ```C++ -SssrCreateReflectionViewInfoD3D12 d3d12ReflectionViewInfo = {}; +FfxSssrD3D12CreateReflectionViewInfo d3d12ReflectionViewInfo = {}; d3d12ReflectionViewInfo.depthBufferHierarchySRV; d3d12ReflectionViewInfo.motionBufferSRV; d3d12ReflectionViewInfo.normalBufferSRV; @@ -92,26 +92,26 @@ d3d12ReflectionViewInfo.sceneSRV; d3d12ReflectionViewInfo.environmentMapSRV; d3d12ReflectionViewInfo.pEnvironmentMapSamplerDesc; -SssrCreateReflectionViewInfo reflectionViewInfo = {}; -reflectionViewInfo.flags = SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS | SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_NORMAL_BUFFERS | SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_ROUGHNESS_BUFFERS; +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.pCreateReflectionViewInfoD3D12 = &d3d12ReflectionViewInfo; +reflectionViewInfo.pD3D12CreateReflectionViewInfo = &d3d12ReflectionViewInfo; -SssrReflectionView myReflectionView; -SssrStatus status = sssrCreateReflectionView(myContext, &reflectionViewInfo, &myReflectionView); -if (status != SSSR_STATUS_OK) { +FfxSssrReflectionView myReflectionView; +FfxSssrStatus status = ffxSssrCreateReflectionView(myContext, &reflectionViewInfo, &myReflectionView); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` -All SRVs and UAVs must be allocated from a CPU accessible descriptor heap as they are copied into the descriptor tables of the library. `SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS` can be used if the application intends to query for timings later. The `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. +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++ -SssrStatus status = sssrDestroyReflectionView(myContext, myReflectionView); -if (status != SSSR_STATUS_OK) { +FfxSssrStatus status = ffxSssrDestroyReflectionView(myContext, myReflectionView); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` @@ -119,45 +119,45 @@ if (status != SSSR_STATUS_OK) { 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++ -SssrStatus status = sssrReflectionViewSetCameraParameters(myContext, myReflectionView, &myViewMatrix, &myProjectionMatrix); -if (status != SSSR_STATUS_OK) { +FfxSssrStatus status = ffxSssrReflectionViewSetCameraParameters(myContext, myReflectionView, &myViewMatrix, &myProjectionMatrix); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` ## Reflection View - Resolve -Calling `sssrEncodeResolveReflectionView` dispatches the actual shaders that perform the hierarchical tracing through the depth buffer and optionally also dispatches the denoising passes if the `SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE` flag is set: +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: ```C++ -SssrCommandEncodeInfoD3D12 d3d12EncodeInfo = {}; +FfxSssrD3D12CommandEncodeInfo d3d12EncodeInfo = {}; d3d12EncodeInfo.pCommandList = myCommandList; -SssrResolveReflectionViewInfo resolveInfo = {}; -resolveInfo.flags = SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE | SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING; +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 = SSSR_RAY_SAMPLES_PER_QUAD_1; -resolveInfo.eawPassCount = SSSR_EAW_PASS_COUNT_1; +resolveInfo.samplesPerQuad = FFX_SSSR_RAY_SAMPLES_PER_QUAD_1; +resolveInfo.eawPassCount = FFX_SSSR_EAW_PASS_COUNT_1; resolveInfo.roughnessThreshold = 0.2f; -resolveInfo.pCommandEncodeInfoD3D12 = &d3d12EncodeInfo; -SssrStatus status = sssrEncodeResolveReflectionView(myContext, myReflectionView, &resolveInfo); -if (status != SSSR_STATUS_OK) { +resolveInfo.pD3D12CommandEncodeInfo = &d3d12EncodeInfo; +FfxSssrStatus status = ffxSssrEncodeResolveReflectionView(myContext, myReflectionView, &resolveInfo); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` -* Enabling `SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE` runs the libraries denoisers. Omit that flag if denoising is not required. -* Enabling `SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING` counteracts temporal instabilities by shooting more rays in temporally unstable regions. +* 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 `SSSR_RAY_SAMPLES_PER_QUAD_1`, `SSSR_RAY_SAMPLES_PER_QUAD_2` and `SSSR_RAY_SAMPLES_PER_QUAD_4`. The use of `SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING` dynamically bumps this up to `4` to enforce convergence on a per pixel basis. -* `resolveInfo.eawPassCount` configures the number of Edge-aware á-trous wavelet passes. The only supported values are `SSSR_EAW_PASS_COUNT_1` and `SSSR_EAW_PASS_COUNT_3`. +* `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 `4` to enforce convergence on a per pixel basis. +* `resolveInfo.eawPassCount` configures the number of Edge-aware á-trous wavelet passes. The only supported values are `FFX_SSSR_EAW_PASS_COUNT_1` and `FFX_SSSR_EAW_PASS_COUNT_3`. * `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: @@ -179,10 +179,10 @@ myCommandList->ResourceBarrier(1, &resourceBarrier); ## Reflection View - Performance Profiling -It is possible to query profiling information by enabling the `SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS` flag when creating a reflection view: +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 |= SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS; +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). @@ -193,8 +193,8 @@ The profiling information can then be queried as below for the tile classificati ```C++ uint64_t tileClassificationTime; -SssrStatus status = sssrReflectionViewGetTileClassificationElapsedTime(myContext, myReflectionView, &tileClassificationTime); -if (status != SSSR_STATUS_OK) { +FfxSssrStatus status = ffxSssrReflectionViewGetTileClassificationElapsedTime(myContext, myReflectionView, &tileClassificationTime); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` @@ -203,8 +203,8 @@ For the intersection pass: ```C++ uint64_t intersectionTime; -SssrStatus status = sssrReflectionViewGetIntersectionElapsedTime(myContext, myReflectionView, &intersectionTime); -if (status != SSSR_STATUS_OK) { +FfxSssrStatus status = ffxSssrReflectionViewGetIntersectionElapsedTime(myContext, myReflectionView, &intersectionTime); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` @@ -213,8 +213,8 @@ And the same for the denoising passes: ```C++ uint64_t denoisingTime; -SssrStatus status = sssrReflectionViewGetDenoisingElapsedTime(myContext, myReflectionView, &denoisingTime); -if (status != SSSR_STATUS_OK) { +FfxSssrStatus status = ffxSssrReflectionViewGetDenoisingElapsedTime(myContext, myReflectionView, &denoisingTime); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` @@ -237,14 +237,14 @@ contextInfo.frameCountBeforeMemoryReuse = myMaxFrameCountInFlight; Finally, frame boundaries must be signalled to the library as such: ```C++ -SssrStatus status = sssrAdvanceToNextFrame(myContext); -if (status != SSSR_STATUS_OK) +FfxSssrStatus status = ffxSssrAdvanceToNextFrame(myContext); +if (status != FFX_SSSR_STATUS_OK) { // Error handling } ``` -Note that `sssrAdvanceToNextFrame()` 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. +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 diff --git a/ffx-sssr/inc/ffx_sssr.h b/ffx-sssr/inc/ffx_sssr.h index a169884..5449c0a 100644 --- a/ffx-sssr/inc/ffx_sssr.h +++ b/ffx-sssr/inc/ffx_sssr.h @@ -23,124 +23,124 @@ THE SOFTWARE. #include -#define SSSR_MAKE_VERSION(a,b,c) (((a) << 22) | ((b) << 12) | (c)) +#define FFX_SSSR_MAKE_VERSION(a,b,c) (((a) << 22) | ((b) << 12) | (c)) -#define SSSR_API_VERSION SSSR_MAKE_VERSION(1, 0, 0) +#define FFX_SSSR_API_VERSION FFX_SSSR_MAKE_VERSION(1, 0, 0) -#define SSSR_STATIC_LIBRARY +#define FFX_SSSR_STATIC_LIBRARY -#ifndef SSSR_STATIC_LIBRARY +#ifndef FFX_SSSR_STATIC_LIBRARY #ifdef WIN32 #ifdef EXPORT_API -#define SSSR_API __declspec(dllexport) +#define FFX_SSSR_API __declspec(dllexport) #else -#define SSSR_API __declspec(dllimport) +#define FFX_SSSR_API __declspec(dllimport) #endif #elif defined(__GNUC__) #ifdef EXPORT_API -#define SSSR_API __attribute__((visibility ("default"))) +#define FFX_SSSR_API __attribute__((visibility ("default"))) #else -#define SSSR_API +#define FFX_SSSR_API #endif #endif #else -#define SSSR_API +#define FFX_SSSR_API #endif -typedef uint32_t SssrFlags; +typedef uint32_t FfxSssrFlags; -#define SSSR_DEFINE_HANDLE(object) typedef struct object##_T* object; +#define FFX_SSSR_DEFINE_HANDLE(object) typedef struct object##_T* object; -SSSR_DEFINE_HANDLE(SssrContext) -SSSR_DEFINE_HANDLE(SssrReflectionView) +FFX_SSSR_DEFINE_HANDLE(FfxSssrContext) +FFX_SSSR_DEFINE_HANDLE(FfxSssrReflectionView) /*! Forward declarations. */ -typedef struct SssrCreateContextInfoD3D12 SssrCreateContextInfoD3D12; -typedef struct SssrCreateReflectionViewInfoD3D12 SssrCreateReflectionViewInfoD3D12; -typedef struct SssrCommandEncodeInfoD3D12 SssrCommandEncodeInfoD3D12; +typedef struct FfxSssrD3D12CreateContextInfo FfxSssrD3D12CreateContextInfo; +typedef struct FfxSssrD3D12CreateReflectionViewInfo FfxSssrD3D12CreateReflectionViewInfo; +typedef struct FfxSssrD3D12CommandEncodeInfo FfxSssrD3D12CommandEncodeInfo; /** The return codes for the API functions. */ -enum SssrStatus +enum FfxSssrStatus { - SSSR_STATUS_OK = 0, + FFX_SSSR_STATUS_OK = 0, - SSSR_STATUS_INVALID_VALUE = -1, - SSSR_STATUS_INVALID_OPERATION = -2, - SSSR_STATUS_OUT_OF_MEMORY = -3, - SSSR_STATUS_INCOMPATIBLE_API = -4, - SSSR_STATUS_INTERNAL_ERROR = -5 + 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 SssrRaySamplesPerQuad +enum FfxSssrRaySamplesPerQuad { - SSSR_RAY_SAMPLES_PER_QUAD_1, - SSSR_RAY_SAMPLES_PER_QUAD_2, - SSSR_RAY_SAMPLES_PER_QUAD_4 + FFX_SSSR_RAY_SAMPLES_PER_QUAD_1, + FFX_SSSR_RAY_SAMPLES_PER_QUAD_2, + FFX_SSSR_RAY_SAMPLES_PER_QUAD_4 }; /** The number of passes for Edge-aware �-trous wavelet filtering. */ -enum SssrEawPassCount +enum FfxSssrEawPassCount { - SSSR_EAW_PASS_COUNT_1, - SSSR_EAW_PASS_COUNT_3 + FFX_SSSR_EAW_PASS_COUNT_1, + FFX_SSSR_EAW_PASS_COUNT_3 }; /** The available flags for creating a reflection view. */ -enum SssrCreateReflectionViewFlagBits +enum FfxSssrCreateReflectionViewFlagBits { - 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. - 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. - 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. + 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 SssrFlags SssrCreateReflectionViewFlags; +typedef FfxSssrFlags FfxSssrCreateReflectionViewFlags; /** The available flags for resolving a reflection view. */ -enum SssrResolveReflectionViewFlagBits +enum FfxSssrResolveReflectionViewFlagBits { - SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE = 1 << 0, ///< Run denoiser passes on intersection results. - SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING = 1 << 1, ///< Enforces shooting a ray for temporally unstable pixels. + 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 SssrFlags SssrResolveReflectionViewFlags; +typedef FfxSssrFlags FfxSssrResolveReflectionViewFlags; /** The callback function for logging. \param pMessage The message to be logged. */ -typedef void (*PFN_sssrLoggingFunction)(const char* pMessage, void* pUserData); +typedef void (*PFN_ffxSssrLoggingFunction)(const char* pMessage, void* pUserData); /** The callback information for logging. */ -typedef struct SssrLoggingCallbacks +typedef struct FfxSssrLoggingCallbacks { void* pUserData; - PFN_sssrLoggingFunction pfnLogging; -} SssrLoggingCallbacks; + PFN_ffxSssrLoggingFunction pfnLogging; +} FfxSssrLoggingCallbacks; /** The parameters for creating a context. */ -typedef struct SssrCreateContextInfo +typedef struct FfxSssrCreateContextInfo { uint32_t apiVersion; uint32_t maxReflectionViewCount; uint32_t frameCountBeforeMemoryReuse; size_t uploadBufferSize; - const SssrLoggingCallbacks* pLoggingCallbacks; ///< Can be null. + 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. @@ -153,43 +153,43 @@ typedef struct SssrCreateContextInfo const wchar_t* pUnpackMotionVectorsSnippet; ///< Used in the HLSL files to unpack the motion vectors from the provided resource. union { - const SssrCreateContextInfoD3D12* pCreateContextInfoD3D12; + const FfxSssrD3D12CreateContextInfo* pD3D12CreateContextInfo; }; -} SssrCreateContextInfo; +} FfxSssrCreateContextInfo; /** The parameters for creating a reflection view. */ -typedef struct SssrCreateReflectionViewInfo +typedef struct FfxSssrCreateReflectionViewInfo { - SssrCreateReflectionViewFlags flags; + FfxSssrCreateReflectionViewFlags flags; uint32_t outputWidth; uint32_t outputHeight; union { - const SssrCreateReflectionViewInfoD3D12* pCreateReflectionViewInfoD3D12; + const FfxSssrD3D12CreateReflectionViewInfo* pD3D12CreateReflectionViewInfo; }; -} SssrCreateReflectionViewInfo; +} FfxSssrCreateReflectionViewInfo; /** The parameters for resolving a reflection view. */ -typedef struct SssrResolveReflectionViewInfo +typedef struct FfxSssrResolveReflectionViewInfo { - SssrResolveReflectionViewFlags flags; + 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. - SssrRaySamplesPerQuad samplesPerQuad; ///< Number of samples per 4 pixels in denoised regions. Mirror reflections are not affected by this. - SssrEawPassCount eawPassCount; ///< Number of EAW passes. + FfxSssrRaySamplesPerQuad samplesPerQuad; ///< Number of samples per 4 pixels in denoised regions. Mirror reflections are not affected by this. + FfxSssrEawPassCount eawPassCount; ///< Number of EAW passes. float roughnessThreshold; ///< Shoot reflection rays for roughness values that are lower than this threshold. union { - const SssrCommandEncodeInfoD3D12* pCommandEncodeInfoD3D12; ///< A pointer to the Direct3D12 command encoding parameters. + const FfxSssrD3D12CommandEncodeInfo* pD3D12CommandEncodeInfo; ///< A pointer to the Direct3D12 command encoding parameters. }; -} SssrResolveReflectionViewInfo; +} FfxSssrResolveReflectionViewInfo; // API functions #ifdef __cplusplus @@ -203,7 +203,7 @@ extern "C" \param outContext The context. \return The corresponding error code. */ - SSSR_API SssrStatus sssrCreateContext(const SssrCreateContextInfo* pCreateContextInfo, SssrContext* outContext); + FFX_SSSR_API FfxSssrStatus ffxSssrCreateContext(const FfxSssrCreateContextInfo* pCreateContextInfo, FfxSssrContext* outContext); /** Destroys the context. @@ -211,7 +211,7 @@ extern "C" \param context The context to be destroyed. \return The corresponding error code. */ - SSSR_API SssrStatus sssrDestroyContext(SssrContext context); + FFX_SSSR_API FfxSssrStatus ffxSssrDestroyContext(FfxSssrContext context); /** Creates a new reflection view. @@ -221,7 +221,7 @@ extern "C" \param outReflectionView The reflection view resource. \return The corresponding error code. */ - SSSR_API SssrStatus sssrCreateReflectionView(SssrContext context, const SssrCreateReflectionViewInfo* pCreateReflectionViewInfo, SssrReflectionView* outReflectionView); + FFX_SSSR_API FfxSssrStatus ffxSssrCreateReflectionView(FfxSssrContext context, const FfxSssrCreateReflectionViewInfo* pCreateReflectionViewInfo, FfxSssrReflectionView* outReflectionView); /** Destroys the reflection view. @@ -230,7 +230,7 @@ extern "C" \param reflectionView The reflection view resource. \return The corresponding error code. */ - SSSR_API SssrStatus sssrDestroyReflectionView(SssrContext context, SssrReflectionView reflectionView); + FFX_SSSR_API FfxSssrStatus ffxSssrDestroyReflectionView(FfxSssrContext context, FfxSssrReflectionView reflectionView); /** Encodes the command(s) for resolving the given reflection view. @@ -240,7 +240,7 @@ extern "C" \param pResolveReflectionViewInfo The reflection view information. \return The corresponding error code. */ - SSSR_API SssrStatus sssrEncodeResolveReflectionView(SssrContext context, SssrReflectionView reflectionView, const SssrResolveReflectionViewInfo* pResolveReflectionViewInfo); + FFX_SSSR_API FfxSssrStatus ffxSssrEncodeResolveReflectionView(FfxSssrContext context, FfxSssrReflectionView reflectionView, const FfxSssrResolveReflectionViewInfo* pResolveReflectionViewInfo); /** Advances the frame index. @@ -250,7 +250,7 @@ extern "C" \note Please call this once a frame so the library is able to safely re-use memory blocks after frameCountBeforeMemoryReuse frames have passed. */ - SSSR_API SssrStatus sssrAdvanceToNextFrame(SssrContext context); + FFX_SSSR_API FfxSssrStatus ffxSssrAdvanceToNextFrame(FfxSssrContext context); /** Gets the number of GPU ticks spent in the tile classification pass. @@ -260,10 +260,10 @@ extern "C" \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 SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag. + \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. */ - SSSR_API SssrStatus sssrReflectionViewGetTileClassificationElapsedTime(SssrContext context, SssrReflectionView reflectionView, uint64_t* outTileClassificationElapsedTime); + FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewGetTileClassificationElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outTileClassificationElapsedTime); /** @@ -274,10 +274,10 @@ extern "C" \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 SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag. + \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. */ - SSSR_API SssrStatus sssrReflectionViewGetIntersectionElapsedTime(SssrContext context, SssrReflectionView reflectionView, uint64_t* outIntersectionElapsedTime); + FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewGetIntersectionElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outIntersectionElapsedTime); /** Gets the number of GPU ticks spent denoising. @@ -287,10 +287,10 @@ extern "C" \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 SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag. + \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. */ - SSSR_API SssrStatus sssrReflectionViewGetDenoisingElapsedTime(SssrContext context, SssrReflectionView reflectionView, uint64_t* outDenoisingElapsedTime); + FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewGetDenoisingElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outDenoisingElapsedTime); /** Gets the view and projection matrices for the reflection view. @@ -303,7 +303,7 @@ extern "C" \note The output matrices will be 4x4 row-major matrices. */ - SSSR_API SssrStatus sssrReflectionViewGetCameraParameters(SssrContext context, SssrReflectionView reflectionView, float* outViewMatrix, float* outProjectionMatrix); + FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewGetCameraParameters(FfxSssrContext context, FfxSssrReflectionView reflectionView, float* outViewMatrix, float* outProjectionMatrix); /** Sets the view and projection matrices for the reflection view. @@ -316,7 +316,7 @@ extern "C" \note The input matrices are expected to be 4x4 row-major matrices. */ - SSSR_API SssrStatus sssrReflectionViewSetCameraParameters(SssrContext context, SssrReflectionView reflectionView, const float* pViewMatrix, const float* pProjectionMatrix); + FFX_SSSR_API FfxSssrStatus ffxSssrReflectionViewSetCameraParameters(FfxSssrContext context, FfxSssrReflectionView reflectionView, const float* pViewMatrix, const float* pProjectionMatrix); #ifdef __cplusplus } diff --git a/ffx-sssr/inc/ffx_sssr_d3d12.h b/ffx-sssr/inc/ffx_sssr_d3d12.h index 6ae6d56..7ac8366 100644 --- a/ffx-sssr/inc/ffx_sssr_d3d12.h +++ b/ffx-sssr/inc/ffx_sssr_d3d12.h @@ -27,16 +27,16 @@ THE SOFTWARE. /** The parameters for creating a Direct3D12 context. */ -typedef struct SssrCreateContextInfoD3D12 +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. -} SssrCreateContextInfoD3D12; +} FfxSssrD3D12CreateContextInfo; /** The parameters for creating a Direct3D12 reflection view. */ -typedef struct SssrCreateReflectionViewInfoD3D12 +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. @@ -49,12 +49,12 @@ typedef struct SssrCreateReflectionViewInfoD3D12 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_STATIC_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. -} SssrCreateReflectionViewInfoD3D12; +} FfxSssrD3D12CreateReflectionViewInfo; /** \brief The parameters for encoding Direct3D12 device commands. */ -typedef struct SssrCommandEncodeInfoD3D12 +typedef struct FfxSssrD3D12CommandEncodeInfo { ID3D12GraphicsCommandList* pCommandList; ///< The Direct3D12 command list to be used for command encoding. -} SssrCommandEncodeInfoD3D12; +} FfxSssrD3D12CommandEncodeInfo; diff --git a/ffx-sssr/shaders/classify_tiles.hlsl b/ffx-sssr/shaders/classify_tiles.hlsl index e467610..24239ed 100644 --- a/ffx-sssr/shaders/classify_tiles.hlsl +++ b/ffx-sssr/shaders/classify_tiles.hlsl @@ -20,22 +20,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_CLASSIFY_TILES -#define SSR_CLASSIFY_TILES - -// In: -Texture2D g_roughness : register(t0); - -// Out: -RWBuffer g_tile_list : register(u0); -RWBuffer g_ray_list : register(u1); -globallycoherent RWBuffer g_tile_counter : register(u2); -globallycoherent RWBuffer g_ray_counter : register(u3); -RWTexture2D g_temporally_denoised_reflections : register(u4); -RWTexture2D g_temporally_denoised_reflections_history : register(u5); -RWTexture2D g_ray_lengths : register(u6); -RWTexture2D g_temporal_variance : register(u7); -RWTexture2D g_denoised_reflections : register(u8); +#ifndef FFX_SSSR_CLASSIFY_TILES +#define FFX_SSSR_CLASSIFY_TILES + +Texture2D g_roughness : register(t0); + +RWBuffer g_tile_list : register(u0); +RWBuffer g_ray_list : register(u1); +globallycoherent RWBuffer g_tile_counter : register(u2); +globallycoherent RWBuffer g_ray_counter : register(u3); +RWTexture2D g_temporally_denoised_reflections : register(u4); +RWTexture2D g_temporally_denoised_reflections_history : register(u5); +RWTexture2D g_ray_lengths : register(u6); +RWTexture2D g_temporal_variance : register(u7); +RWTexture2D g_denoised_reflections : register(u8); groupshared uint g_ray_count; groupshared uint g_ray_base_index; @@ -55,8 +53,8 @@ void main(uint2 did : SV_DispatchThreadID, uint group_index : SV_GroupIndex) bool needs_ray = !(did.x >= screen_size.x || did.y >= screen_size.y); // Dont shoot a ray on very rough surfaces. - float roughness = SssrUnpackRoughness(g_roughness.Load(int3(did, 0))); - needs_ray = needs_ray && DoSSR(roughness); + 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); @@ -128,4 +126,4 @@ void main(uint2 did : SV_DispatchThreadID, uint group_index : SV_GroupIndex) 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 // SSR_CLASSIFY_TILES \ No newline at end of file +#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 index abadf49..07ecd77 100644 --- a/ffx-sssr/shaders/common.hlsl +++ b/ffx-sssr/shaders/common.hlsl @@ -20,35 +20,35 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_COMMON -#define SSR_COMMON +#ifndef FFX_SSSR_COMMON +#define FFX_SSSR_COMMON -#define SSR_PI 3.14159265358979f -#define SSR_GOLDEN_RATIO 1.61803398875f +#define FFX_SSSR_PI 3.14159265358979f +#define FFX_SSSR_GOLDEN_RATIO 1.61803398875f -#define SSR_FLOAT_MAX 3.402823466e+38 +#define FFX_SSSR_FLOAT_MAX 3.402823466e+38 -#define SSR_FALSE 0 -#define SSR_TRUE 1 +#define FFX_SSSR_FALSE 0 +#define FFX_SSSR_TRUE 1 -#define SSR_USE_ROUGHNESS_OVERRIDE SSR_FALSE -#define SSR_ROUGHNESS_OVERRIDE 0.1 +#define FFX_SSSR_USE_ROUGHNESS_OVERRIDE FFX_SSSR_FALSE +#define FFX_SSSR_ROUGHNESS_OVERRIDE 0.1 -#define SSR_TEMPORAL_VARIANCE_THRESHOLD 0.0005 +#define FFX_SSSR_TEMPORAL_VARIANCE_THRESHOLD 0.0005 -#if SSR_USE_ROUGHNESS_OVERRIDE -float SssrUnpackRoughness(SSR_ROUGHNESS_TEXTURE_FORMAT packed) { return SSR_ROUGHNESS_OVERRIDE; } +#if FFX_SSSR_USE_ROUGHNESS_OVERRIDE +float FfxSssrUnpackRoughness(FFX_SSSR_ROUGHNESS_TEXTURE_FORMAT packed) { return FFX_SSSR_ROUGHNESS_OVERRIDE; } #else -SSR_ROUGHNESS_UNPACK_FUNCTION +FFX_SSSR_ROUGHNESS_UNPACK_FUNCTION #endif -SSR_NORMALS_UNPACK_FUNCTION -SSR_MOTION_VECTOR_UNPACK_FUNCTION -SSR_DEPTH_UNPACK_FUNCTION -SSR_SCENE_RADIANCE_UNPACK_FUNCTION +FFX_SSSR_NORMALS_UNPACK_FUNCTION +FFX_SSSR_MOTION_VECTOR_UNPACK_FUNCTION +FFX_SSSR_DEPTH_UNPACK_FUNCTION +FFX_SSSR_SCENE_RADIANCE_UNPACK_FUNCTION // Common constants -cbuffer SSRConstants : register(b0) +cbuffer Constants : register(b0) { float4x4 g_inv_view_proj; float4x4 g_proj; @@ -112,17 +112,17 @@ Ray CreateViewSpaceRay(float3 screen_space_pos) return view_space_ray; } -float3 LoadNormal(int2 index, Texture2D tex) +float3 LoadNormal(int2 index, Texture2D tex) { - return SssrUnpackNormals(tex.Load(int3(index, 0))); + return FfxSssrUnpackNormals(tex.Load(int3(index, 0))); } -float LoadRoughness(int2 index, Texture2D tex) +float LoadRoughness(int2 index, Texture2D tex) { - return SssrUnpackRoughness(tex.Load(int3(index, 0))); + return FfxSssrUnpackRoughness(tex.Load(int3(index, 0))); } -bool DoSSR(float roughness) +bool IsGlossy(float roughness) { return roughness < g_roughness_threshold; } @@ -189,17 +189,21 @@ bool IsBaseRay(uint2 did, uint samples_per_quad) } } -// Has to match the calculation in IsBaseRay -uint2 GetBaseIdx(uint2 did, uint samples_per_quad) +// 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 did & ~(0x1); + return lane & (~0b11); // Map to upper left case 2: - return uint2(did.x ^ 1, did.y); // Toggle last bit of x + return lane ^ 0b1; // Toggle horizontal default: // case 4: - return did; + return lane; // Identity } } @@ -216,4 +220,24 @@ min16float2 UnpackFloat16(uint a) return min16float2(tmp); } -#endif // SSR_COMMON \ No newline at end of file + +// 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 index 5fc5d44..19d2d82 100644 --- a/ffx-sssr/shaders/intersect.hlsl +++ b/ffx-sssr/shaders/intersect.hlsl @@ -20,30 +20,27 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_INTERSECT -#define SSR_INTERSECT - -// In: -Texture2D g_lit_scene : register(t0); // scene rendered with lighting and shadows -Texture2D g_depth_buffer_hierarchy : register(t1); -Texture2D g_normal : register(t2); -Texture2D g_roughness : register(t3); -TextureCube g_environment_map : register(t4); -Buffer g_sobol_buffer : register(t5); -Buffer g_ranking_tile_buffer : register(t6); -Buffer g_scrambling_tile_buffer : register(t7); -Buffer g_ray_list : register(t8); - -// Samplers: -SamplerState g_linear_sampler : register(s0); -SamplerState g_environment_map_sampler : register(s1); - -// Out: -RWTexture2D g_intersection_result : register(u0); // reflection colors at the end of the intersect pass. -RWTexture2D g_ray_lengths : register(u1); -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. Returns a value in the range [0, 1]. +#ifndef FFX_SSSR_INTERSECT +#define FFX_SSSR_INTERSECT + +Texture2D g_lit_scene : register(t0); // Scene rendered with lighting and shadows +Texture2D g_depth_buffer_hierarchy : register(t1); +Texture2D g_normal : register(t2); +Texture2D g_roughness : register(t3); +TextureCube g_environment_map : register(t4); +Buffer g_sobol_buffer : register(t5); +Buffer g_ranking_tile_buffer : register(t6); +Buffer g_scrambling_tile_buffer : register(t7); + +SamplerState g_linear_sampler : register(s0); +SamplerState g_environment_map_sampler : register(s1); + +RWTexture2D g_intersection_result : register(u0); // Reflection colors at the end of the intersect pass. +RWTexture2D g_ray_lengths : register(u1); +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. +RWBuffer g_ray_list : register(u3); + +// 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 @@ -69,47 +66,51 @@ 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) * SSR_GOLDEN_RATIO, 1.0f), - fmod(SampleRandomNumber(pixel.x, pixel.y, sample_index, 1u) + (g_frame_index & 0xFFu) * SSR_GOLDEN_RATIO, 1.0f)); + 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 Sample_GGX_VNDF_Ellipsoid(float3 Ve, float alpha_x, float alpha_y, float U1, float U2) +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, Ve.y, alpha_y * Ve.z)); - + 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) - float3 T1 = (Vh.y < 0.9999) ? normalize(cross(float3(0.0, 1.0, 0.0), Vh)) : float3(0.0, 0.0, 1.0); + 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 * SSR_PI * U2; + float phi = 2.0 * M_PI * U2; float t1 = r * cos(phi); float t2 = r * sin(phi); - float s = 0.5 * (1.0 + Vh.y); + 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, clamp(Nh.y, 0, 1), alpha_y * Nh.z)); + 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 CreateTNB(float3 N) +float3x3 CreateTBN(float3 N) { float3 U; if (abs(N.z) > 0.0) @@ -123,28 +124,28 @@ float3x3 CreateTNB(float3 N) U.x = N.y / k; U.y = -N.x / k; U.z = 0.0; } - float3x3 TNB; - TNB[0] = U; - TNB[1] = N; - TNB[2] = cross(N, U); - return transpose(TNB); + 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 tnb_transform = CreateTNB(normal); - float3 view_direction_tnb = mul(-view_direction, tnb_transform); + float3x3 tbn_transform = CreateTBN(normal); + float3 view_direction_tbn = mul(-view_direction, tbn_transform); float2 u = SampleRandomVector2(did); - float3 sampled_normal_tnb = Sample_GGX_VNDF_Hemisphere(view_direction_tnb, roughness, u.x, u.y); - // sampled_normal_tnb = float3(0, 1, 0); // Overwrite normal sample to produce perfect reflection. + 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_tnb = reflect(-view_direction_tnb, sampled_normal_tnb); + float3 reflected_direction_tbn = reflect(-view_direction_tbn, sampled_normal_tbn); // Transform reflected_direction back to the initial space. - float3x3 inv_tnb_transform = transpose(tnb_transform); - return mul(reflected_direction_tnb, inv_tnb_transform); + float3x3 inv_tbn_transform = transpose(tbn_transform); + return mul(reflected_direction_tbn, inv_tbn_transform); } float2 GetMipResolution(float2 screen_dimensions, int mip_level) @@ -154,7 +155,7 @@ float2 GetMipResolution(float2 screen_dimensions, int mip_level) float LoadDepth(float2 idx, int mip) { - return SssrUnpackDepth(g_depth_buffer_hierarchy.Load(int3(idx, 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) @@ -184,7 +185,7 @@ bool AdvanceRay(float3 origin, float3 direction, float3 inv_direction, float2 cu 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 : SSR_FLOAT_MAX; + 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); @@ -209,7 +210,7 @@ float3 HierarchicalRaymarch(float3 origin, float3 direction, bool is_mirror, flo { int most_detailed_mip = is_mirror ? 0 : g_most_detailed_mip; - const float3 inv_direction = direction != 0 ? 1.0 / direction : SSR_FLOAT_MAX; + 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; @@ -321,7 +322,7 @@ void Intersect(int2 did) 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); + 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); @@ -332,7 +333,7 @@ void Intersect(int2 did) if (confidence > 0) { // Found an intersection with the depth buffer -> We can lookup the color from lit scene. - reflection_radiance = SssrUnpackSceneRadiance(g_lit_scene.Load(int3(screen_size * hit.xy, 0))); + reflection_radiance = FfxSssrUnpackSceneRadiance(g_lit_scene.Load(int3(screen_size * hit.xy, 0))); } // Sample environment map. @@ -358,4 +359,4 @@ void main(uint group_index : SV_GroupIndex, uint group_id : SV_GroupID) Intersect((int2)coords); } -#endif // SSR_INTERSECT \ No newline at end of file +#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 index 804ad44..f1f1b2a 100644 --- a/ffx-sssr/shaders/prepare_indirect_args.hlsl +++ b/ffx-sssr/shaders/prepare_indirect_args.hlsl @@ -20,16 +20,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_INDIRECT_ARGS -#define SSR_INDIRECT_ARGS +#ifndef FFX_SSSR_INDIRECT_ARGS +#define FFX_SSSR_INDIRECT_ARGS -// In/Out: -RWBuffer g_tile_counter : register(u0); // scene rendered with lighting and shadows -RWBuffer g_ray_counter : register(u1); - -// Out: -RWBuffer g_intersect_args : register(u2); -RWBuffer g_denoiser_args : register(u3); +RWBuffer g_tile_counter : register(u0); +RWBuffer g_ray_counter : register(u1); +RWBuffer g_intersect_args : register(u2); +RWBuffer g_denoiser_args : register(u3); [numthreads(1, 1, 1)] void main() @@ -49,4 +46,4 @@ void main() g_denoiser_args[2] = 1; } -#endif // SSR_INDIRECT_ARGS \ No newline at end of file +#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 index b911428..4f45d84 100644 --- a/ffx-sssr/shaders/resolve_eaw.hlsl +++ b/ffx-sssr/shaders/resolve_eaw.hlsl @@ -20,19 +20,18 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_EAW_RESOLVE -#define SSR_EAW_RESOLVE +#ifndef FFX_SSSR_EAW_RESOLVE +#define FFX_SSSR_EAW_RESOLVE -// In: -Texture2D g_normal : register(t0); -Texture2D g_roughness : register(t1); -Texture2D g_depth_buffer : register(t2); -Buffer g_tile_list : register(t3); -SamplerState g_linear_sampler : register(s0); +Texture2D g_normal : register(t0); +Texture2D g_roughness : register(t1); +Texture2D g_depth_buffer : register(t2); -// Out: -RWTexture2D g_temporally_denoised_reflections : register(u0); -RWTexture2D g_denoised_reflections : register(u1); // will hold the reflection colors at the end of the resolve pass. +SamplerState g_linear_sampler : register(s0); + +RWTexture2D g_temporally_denoised_reflections : register(u0); +RWTexture2D g_denoised_reflections : register(u1); // Will hold the reflection colors at the end of the resolve pass. +RWBuffer g_tile_list : register(u2); groupshared uint g_shared_0[12][12]; groupshared uint g_shared_1[12][12]; @@ -62,10 +61,9 @@ min16float3 LoadRadiance(int2 idx) min16float LoadRoughnessValue(int2 idx) { - return SssrUnpackRoughness(g_roughness.Load(int3(idx, 0))); + return FfxSssrUnpackRoughness(g_roughness.Load(int3(idx, 0))); } -// Calculates SSR color min16float4 ResolveScreenspaceReflections(int2 gtid, min16float center_roughness) { const min16float roughness_sigma_min = 0.001; @@ -174,7 +172,7 @@ void Resolve(int2 did, int2 gtid) min16float center_roughness; LoadFromGroupSharedMemory(gtid, center_radiance, center_roughness); - if (!DoSSR(center_roughness) || IsMirrorReflection(center_roughness)) + if (!IsGlossy(center_roughness) || IsMirrorReflection(center_roughness)) { return; } @@ -191,4 +189,4 @@ void main(uint2 group_thread_id : SV_GroupThreadID, uint group_id : SV_GroupID) Resolve((int2)coords, (int2)group_thread_id); } -#endif // SSR_EAW_RESOLVE \ No newline at end of file +#endif // FFX_SSSR_EAW_RESOLVE \ No newline at end of file diff --git a/ffx-sssr/shaders/resolve_eaw_stride.hlsl b/ffx-sssr/shaders/resolve_eaw_stride.hlsl index 5671f95..75fa1b5 100644 --- a/ffx-sssr/shaders/resolve_eaw_stride.hlsl +++ b/ffx-sssr/shaders/resolve_eaw_stride.hlsl @@ -20,19 +20,18 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_EAW_RESOLVE -#define SSR_EAW_RESOLVE +#ifndef FFX_SSSR_EAW_RESOLVE +#define FFX_SSSR_EAW_RESOLVE -// In: -Texture2D g_normal : register(t0); -Texture2D g_roughness : register(t1); -Texture2D g_depth_buffer : register(t2); -Buffer g_tile_list : register(t3); -SamplerState g_linear_sampler : register(s0); +Texture2D g_normal : register(t0); +Texture2D g_roughness : register(t1); +Texture2D g_depth_buffer : register(t2); -// Out: -RWTexture2D g_temporally_denoised_reflections : register(u0); -RWTexture2D g_denoised_reflections : register(u1); // will hold the reflection colors at the end of the resolve pass. +SamplerState g_linear_sampler : register(s0); + +RWTexture2D g_temporally_denoised_reflections : register(u0); +RWTexture2D g_denoised_reflections : register(u1); // Will hold the reflection colors at the end of the resolve pass. +RWBuffer g_tile_list : register(u2); min16float3 LoadRadiance(int2 idx) { @@ -41,7 +40,7 @@ min16float3 LoadRadiance(int2 idx) min16float LoadRoughnessValue(int2 idx) { - return SssrUnpackRoughness(g_roughness.Load(int3(idx, 0))); + return FfxSssrUnpackRoughness(g_roughness.Load(int3(idx, 0))); } min16float GetRoughnessRadiusWeight(min16float roughness_p, min16float roughness_q, min16float dist) @@ -49,7 +48,6 @@ min16float GetRoughnessRadiusWeight(min16float roughness_p, min16float roughness return 1.0 - smoothstep(10 * roughness_p, 500 * roughness_p, dist); } -// Calculates SSR color min16float4 ResolveScreenspaceReflections(int2 did, min16float center_roughness) { const min16float roughness_sigma_min = 0.001; @@ -63,7 +61,7 @@ min16float4 ResolveScreenspaceReflections(int2 did, min16float center_roughness) { for (int dx = -radius; dx <= radius; ++dx) { - int2 texel_coords = did + SSR_EAW_STRIDE * int2(dx, dy); + int2 texel_coords = did + FFX_SSSR_EAW_STRIDE * int2(dx, dy); min16float3 radiance = LoadRadiance(texel_coords); min16float roughness = LoadRoughnessValue(texel_coords); @@ -83,7 +81,7 @@ void Resolve(int2 did) { min16float3 center_radiance = LoadRadiance(did); min16float center_roughness = LoadRoughnessValue(did); - if (!DoSSR(center_roughness) || IsMirrorReflection(center_roughness)) + if (!IsGlossy(center_roughness) || IsMirrorReflection(center_roughness)) { return; } @@ -99,4 +97,4 @@ void main(uint2 group_thread_id : SV_GroupThreadID, uint group_id : SV_GroupID) Resolve((int2)coords); } -#endif // SSR_EAW_RESOLVE \ No newline at end of file +#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 index c42a329..604bdd7 100644 --- a/ffx-sssr/shaders/resolve_spatial.hlsl +++ b/ffx-sssr/shaders/resolve_spatial.hlsl @@ -20,23 +20,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_SPATIAL_RESOLVE -#define SSR_SPATIAL_RESOLVE +#ifndef FFX_SSSR_SPATIAL_RESOLVE +#define FFX_SSSR_SPATIAL_RESOLVE -// In: -Texture2D g_depth_buffer : register(t0); -Texture2D g_normal : register(t1); -Texture2D g_roughness : register(t2); -Texture2D g_intersection_result : register(t3); // reflection colors at the end of the intersect pass. -Texture2D g_has_ray : register(t4); -Buffer g_tile_list : register(t5); +Texture2D g_depth_buffer : register(t0); +Texture2D g_normal : register(t1); +Texture2D g_roughness : register(t2); -// Sampler: -SamplerState g_linear_sampler : register(s0); +SamplerState g_linear_sampler : register(s0); -// Out: -RWTexture2D g_spatially_denoised_reflections : register(u0); -RWTexture2D g_ray_lengths : register(u1); +RWTexture2D g_spatially_denoised_reflections : register(u0); +RWTexture2D g_ray_lengths : register(u1); +RWTexture2D g_intersection_result : register(u2); // Reflection colors at the end of the intersect pass. +RWTexture2D g_has_ray : register(u3); +RWBuffer g_tile_list : register(u4); // Only really need 16x16 but 17x17 avoids bank conflicts. @@ -78,7 +75,7 @@ void StoreInGroupSharedMemory(int2 idx, min16float4 radiance, min16float3 normal min16float LoadRayLengthFP16(int2 idx) { - return g_ray_lengths.Load(int3(idx, 0)); + return g_ray_lengths.Load(idx); } min16float3 LoadRadianceFP16(int2 idx) @@ -88,12 +85,12 @@ min16float3 LoadRadianceFP16(int2 idx) min16float3 LoadNormalFP16(int2 idx) { - return (min16float3) SssrUnpackNormals(g_normal.Load(int3(idx, 0))); + return (min16float3) FfxSssrUnpackNormals(g_normal.Load(int3(idx, 0))); } float LoadDepth(int2 idx) { - return SssrUnpackDepth(g_depth_buffer.Load(int3(idx, 0))); + return FfxSssrUnpackDepth(g_depth_buffer.Load(int3(idx, 0))); } bool LoadHasRay(int2 idx) @@ -117,11 +114,6 @@ void StoreWithOffset(int2 gtid, int2 offset, min16float ray_length, min16float3 StoreInGroupSharedMemory(gtid, min16float4(radiance, ray_length), normal, depth); // Pack ray length and radiance together } -int Linearize(int2 gtid) -{ - return (gtid.y * 8 + gtid.x) % WaveGetLaneCount(); // The copy approach works only for machines with at least 16 lanes. -} - void InitializeGroupSharedMemory(int2 did, int2 gtid) { const uint samples_per_quad = g_samples_per_quad; @@ -168,9 +160,9 @@ void InitializeGroupSharedMemory(int2 did, int2 gtid) 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 base_lane_index = Linearize(GetBaseIdx(gtid, samples_per_quad)); // No matter the offset, we always get the same base lane index. - const bool is_base_ray = IsBaseRay(gtid, samples_per_quad); // Same here: no matter the offset, we always get the same result. 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; @@ -193,7 +185,6 @@ void InitializeGroupSharedMemory(int2 did, int2 gtid) StoreWithOffset(gtid, offset_3, ray_length_3, radiance_3, normal_3, depth_3); // C } -// Calculates SSR color min16float3 ResolveScreenspaceReflections(int2 gtid, min16float3 center_radiance, min16float3 center_normal, float center_depth) { float3 accumulated_radiance = center_radiance; @@ -248,7 +239,7 @@ void Resolve(int2 did, int2 gtid) InitializeGroupSharedMemory(did, gtid); GroupMemoryBarrierWithGroupSync(); - if (!DoSSR(center_roughness) || IsMirrorReflection(center_roughness)) + if (!IsGlossy(center_roughness) || IsMirrorReflection(center_roughness)) { return; } @@ -262,13 +253,14 @@ void Resolve(int2 did, int2 gtid) g_ray_lengths[did.xy] = center_radiance.w; // ray_length } -[numthreads(8, 8, 1)] -void main(uint2 group_thread_id : SV_GroupThreadID, uint group_id : SV_GroupID) +[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 coords = base_coords + group_thread_id; - Resolve((int2)coords, (int2)group_thread_id); + 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 // SSR_SPATIAL_RESOLVE \ No newline at end of file +#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 index 90ba54a..3e25b21 100644 --- a/ffx-sssr/shaders/resolve_temporal.hlsl +++ b/ffx-sssr/shaders/resolve_temporal.hlsl @@ -20,27 +20,24 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_TEMPORAL_RESOLVE -#define SSR_TEMPORAL_RESOLVE - -// In: -Texture2D g_normal : register(t0); -Texture2D g_roughness : register(t1); -Texture2D g_normal_history : register(t2); -Texture2D g_roughness_history : register(t3); -Texture2D g_depth_buffer : register(t4); -Texture2D g_motion_vectors : register(t5); -Texture2D g_temporally_denoised_reflections_history : register(t6); // reflection colors at the end of the temporal resolve pass of the previous frame. -Texture2D g_ray_lengths : register(t7); -Buffer g_tile_list : register(t8); - -// Samplers: -SamplerState g_linear_sampler : register(s0); - -// Out: -RWTexture2D g_temporally_denoised_reflections : register(u0); -RWTexture2D g_spatially_denoised_reflections : register(u1); // Technically still an input, but we have to keep it as UAV -RWTexture2D g_temporal_variance : register(u2); +#ifndef FFX_SSSR_TEMPORAL_RESOLVE +#define FFX_SSSR_TEMPORAL_RESOLVE + +Texture2D g_normal : register(t0); +Texture2D g_roughness : register(t1); +Texture2D g_normal_history : register(t2); +Texture2D g_roughness_history : register(t3); +Texture2D g_depth_buffer : register(t4); +Texture2D g_motion_vectors : register(t5); + +SamplerState g_linear_sampler : register(s0); + +RWTexture2D g_temporally_denoised_reflections : register(u0); +RWTexture2D g_spatially_denoised_reflections : register(u1); +RWTexture2D g_temporal_variance : register(u2); +RWTexture2D g_temporally_denoised_reflections_history : register(u3); // Reflection colors at the end of the temporal resolve pass of the previous frame. +RWTexture2D g_ray_lengths : register(u4); +RWBuffer g_tile_list : register(u5); // From "Temporal Reprojection Anti-Aliasing" // https://github.com/playdeadgames/temporal @@ -118,7 +115,7 @@ float3 EstimateStdDeviation(int2 did, RWTexture2D tex) return sqrt(max(color_std, 0.0)); } -float3 SampleRadiance(int2 texel_coords, Texture2D tex) +float3 SampleRadiance(int2 texel_coords, RWTexture2D tex) { return tex.Load(int3(texel_coords, 0)).xyz; } @@ -132,7 +129,7 @@ float2 GetSurfaceReprojection(int2 did, float2 uv, float2 motion_vector) float2 GetHitPositionReprojection(int2 did, float2 uv, float reflected_ray_length) { - float z = SssrUnpackDepth(g_depth_buffer.Load(int3(did, 0))); + 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. @@ -186,11 +183,11 @@ float4 ResolveScreenspaceReflections(int2 did, float2 uv, uint2 image_size, floa { 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)); + float3 radiance_history = g_temporally_denoised_reflections_history.Load(did).xyz; + float ray_length = g_ray_lengths.Load(did); // And clip it to the local neighborhood - float2 motion_vector = SssrUnpackMotionVectors(g_motion_vectors.Load(int3(did, 0))); + 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. @@ -214,14 +211,14 @@ float4 ResolveScreenspaceReflections(int2 did, float2 uv, uint2 image_size, floa } radiance = lerp(radiance, reprojection, weight); - float temporal_variance = ComputeTemporalVariance(radiance_history, radiance) > SSR_TEMPORAL_VARIANCE_THRESHOLD ? 1 : 0; + 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 (!DoSSR(roughness) || IsMirrorReflection(roughness)) + if (!IsGlossy(roughness) || IsMirrorReflection(roughness)) { return; } @@ -244,4 +241,4 @@ void main(uint2 group_thread_id : SV_GroupThreadID, uint group_id : SV_GroupID) Resolve((int2)coords); } -#endif // SSR_TEMPORAL_RESOLVE \ No newline at end of file +#endif // FFX_SSSR_TEMPORAL_RESOLVE \ No newline at end of file diff --git a/ffx-sssr/src/context.cpp b/ffx-sssr/src/context.cpp index b571fe6..b6ead9e 100644 --- a/ffx-sssr/src/context.cpp +++ b/ffx-sssr/src/context.cpp @@ -21,40 +21,40 @@ THE SOFTWARE. ********************************************************************/ #include "context.h" -#ifndef SSSR_NO_D3D12 +#ifndef FFX_SSSR_NO_D3D12 #include "ffx_sssr_d3d12.h" #include "d3d12/context_d3d12.h" -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 -namespace sssr +namespace ffx_sssr { /** The constructor for the Context class. \param create_context_info The context creation information. */ - Context::Context(SssrCreateContextInfo const& create_context_info) + 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_("sssrCreateContext") + , 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) -#ifndef SSSR_NO_D3D12 - if (create_context_info.pCreateContextInfoD3D12) +#ifndef FFX_SSSR_NO_D3D12 + if (create_context_info.pD3D12CreateContextInfo) { - if (!create_context_info.pCreateContextInfoD3D12->pDevice) + if (!create_context_info.pD3D12CreateContextInfo->pDevice) { - throw reflection_error(*this, SSSR_STATUS_INVALID_VALUE, "pDevice must not be nullptr, cannot create Direct3D12 context"); + 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 // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 } /** @@ -85,17 +85,17 @@ namespace sssr reflection_view_view_matrices_.Erase(ID(object_id)); reflection_view_projection_matrices_.Erase(ID(object_id)); -#ifndef SSSR_NO_D3D12 +#ifndef FFX_SSSR_NO_D3D12 if (context_d3d12_) context_d3d12_->reflection_views_.Erase(ID(object_id)); -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 reflection_view_id_dispenser_.FreeId(object_id); } break; default: { - SSSR_ASSERT(0); // should never happen + FFX_SSSR_ASSERT(0); // should never happen } break; } @@ -123,7 +123,7 @@ namespace sssr break; default: { - SSSR_ASSERT(0); // should never happen + FFX_SSSR_ASSERT(0); // should never happen } break; } @@ -137,12 +137,12 @@ namespace sssr \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, SssrCreateReflectionViewInfo const& create_reflection_view_info) + void Context::CreateReflectionView(std::uint64_t reflection_view_id, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info) { -#ifndef SSSR_NO_D3D12 - if (context_d3d12_ && create_reflection_view_info.pCreateReflectionViewInfoD3D12) +#ifndef FFX_SSSR_NO_D3D12 + if (context_d3d12_ && create_reflection_view_info.pD3D12CreateReflectionViewInfo) context_d3d12_->CreateReflectionView(reflection_view_id, create_reflection_view_info); -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 } /** @@ -151,14 +151,14 @@ namespace sssr \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, SssrResolveReflectionViewInfo const& resolve_reflection_view_info) + void Context::ResolveReflectionView(std::uint64_t reflection_view_id, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info) { - SSSR_ASSERT(reflection_view_view_matrices_.At(ID(reflection_view_id))); // not created properly? - SSSR_ASSERT(reflection_view_projection_matrices_.At(ID(reflection_view_id))); + 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))); -#ifndef SSSR_NO_D3D12 +#ifndef FFX_SSSR_NO_D3D12 context_d3d12_->ResolveReflectionView(reflection_view_id, resolve_reflection_view_info); -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 } /** @@ -169,12 +169,12 @@ namespace sssr */ void Context::GetReflectionViewTileClassificationElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const { - SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); + FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); -#ifndef SSSR_NO_D3D12 +#ifndef FFX_SSSR_NO_D3D12 if (context_d3d12_) context_d3d12_->GetReflectionViewTileClassificationElapsedTime(reflection_view_id, elapsed_time); -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 } /** @@ -185,12 +185,12 @@ namespace sssr */ void Context::GetReflectionViewIntersectionElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const { - SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); + FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); -#ifndef SSSR_NO_D3D12 +#ifndef FFX_SSSR_NO_D3D12 if (context_d3d12_) context_d3d12_->GetReflectionViewIntersectionElapsedTime(reflection_view_id, elapsed_time); -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 } /** @@ -201,11 +201,11 @@ namespace sssr */ void Context::GetReflectionViewDenoisingElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const { - SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); + FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); -#ifndef SSSR_NO_D3D12 +#ifndef FFX_SSSR_NO_D3D12 if (context_d3d12_) context_d3d12_->GetReflectionViewDenoisingElapsedTime(reflection_view_id, elapsed_time); -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 } } diff --git a/ffx-sssr/src/context.h b/ffx-sssr/src/context.h index 495a814..d4c5ab8 100644 --- a/ffx-sssr/src/context.h +++ b/ffx-sssr/src/context.h @@ -30,7 +30,7 @@ THE SOFTWARE. #include "reflection_error.h" #include "resources.h" -namespace sssr +namespace ffx_sssr { class ContextD3D12; @@ -44,10 +44,10 @@ namespace sssr */ class Context { - SSSR_NON_COPYABLE(Context); + FFX_SSSR_NON_COPYABLE(Context); public: - Context(SssrCreateContextInfo const& create_context_info); + Context(FfxSssrCreateContextInfo const& create_context_info); ~Context(); inline std::uint32_t& GetFrameIndex(); @@ -70,15 +70,15 @@ namespace sssr inline ContextD3D12* GetContextD3D12(); inline ContextD3D12 const* GetContextD3D12() const; - void CreateReflectionView(std::uint64_t reflection_view_id, SssrCreateReflectionViewInfo const& create_reflection_view_info); - void ResolveReflectionView(std::uint64_t reflection_view_id, SssrResolveReflectionViewInfo const& resolve_reflection_view_info); + 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(SssrStatus error); - inline void Error(SssrStatus error, char const* format, ...); - inline void Error(SssrStatus error, char const* format, va_list args); + inline static char const* GetErrorName(FfxSssrStatus error); + inline void Error(FfxSssrStatus error, char const* format, ...); + inline void Error(FfxSssrStatus error, char const* format, va_list args); inline void AdvanceToNextFrame(); void GetReflectionViewTileClassificationElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const; @@ -103,16 +103,16 @@ namespace sssr // 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_sssrLoggingFunction logging_function_; + 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_; -#ifndef SSSR_NO_D3D12 +#ifndef FFX_SSSR_NO_D3D12 // The Direct3D12 context object. std::unique_ptr context_d3d12_; -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 // The list of reflection view identifiers. IdDispenser reflection_view_id_dispenser_; diff --git a/ffx-sssr/src/context.inl b/ffx-sssr/src/context.inl index 6054bc9..6d75dc7 100644 --- a/ffx-sssr/src/context.inl +++ b/ffx-sssr/src/context.inl @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** Creates a new reflection view. @@ -33,7 +33,7 @@ namespace sssr { if (!CreateObject(object_id, kResourceType_ReflectionView, reflection_view_id_dispenser_)) { - throw reflection_error(*this, SSSR_STATUS_OUT_OF_MEMORY, "Unable to create a new reflection view resource"); + throw reflection_error(*this, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Unable to create a new reflection view resource"); } // Populate the default reflection view properties @@ -111,7 +111,7 @@ namespace sssr return reflection_view_id_dispenser_.GetIdCount(); default: { - SSSR_ASSERT(0); // should never happen + FFX_SSSR_ASSERT(0); // should never happen } break; } @@ -133,7 +133,7 @@ namespace sssr return reflection_view_id_dispenser_.GetMaxIdCount(); default: { - SSSR_ASSERT(0); // should never happen + FFX_SSSR_ASSERT(0); // should never happen } break; } @@ -148,11 +148,11 @@ namespace sssr */ ContextD3D12* Context::GetContextD3D12() { -#ifdef SSSR_NO_D3D12 +#ifdef FFX_SSSR_NO_D3D12 return nullptr; -#else // SSSR_NO_D3D12 +#else // FFX_SSSR_NO_D3D12 return context_d3d12_.get(); -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 } /** @@ -162,11 +162,11 @@ namespace sssr */ ContextD3D12 const* Context::GetContextD3D12() const { -#ifdef SSSR_NO_D3D12 +#ifdef FFX_SSSR_NO_D3D12 return nullptr; -#else // SSSR_NO_D3D12 +#else // FFX_SSSR_NO_D3D12 return context_d3d12_.get(); -#endif // SSSR_NO_D3D12 +#endif // FFX_SSSR_NO_D3D12 } /** @@ -195,21 +195,21 @@ namespace sssr \param error The error code to be queried. \return The name corresponding to the error code. */ - char const* Context::GetErrorName(SssrStatus error) + char const* Context::GetErrorName(FfxSssrStatus error) { switch (error) { - case SSSR_STATUS_OK: + case FFX_SSSR_STATUS_OK: return "OK"; - case SSSR_STATUS_INVALID_VALUE: + case FFX_SSSR_STATUS_INVALID_VALUE: return "Invalid value"; - case SSSR_STATUS_INVALID_OPERATION: + case FFX_SSSR_STATUS_INVALID_OPERATION: return "Invalid operation"; - case SSSR_STATUS_OUT_OF_MEMORY: + case FFX_SSSR_STATUS_OUT_OF_MEMORY: return "Out of memory"; - case SSSR_STATUS_INCOMPATIBLE_API: + case FFX_SSSR_STATUS_INCOMPATIBLE_API: return "Incompatible API"; - case SSSR_STATUS_INTERNAL_ERROR: + case FFX_SSSR_STATUS_INTERNAL_ERROR: return "Internal error"; default: break; @@ -225,7 +225,7 @@ namespace sssr \param format The format for the error message. \param ... The content of the error message. */ - void Context::Error(SssrStatus error, char const* format, ...) + void Context::Error(FfxSssrStatus error, char const* format, ...) { va_list args; va_start(args, format); @@ -240,7 +240,7 @@ namespace sssr \param format The format for the error message. \param args The content of the error message. */ - void Context::Error(SssrStatus error, char const* format, va_list args) + void Context::Error(FfxSssrStatus error, char const* format, va_list args) { char buffer[2048], message[2048]; @@ -268,11 +268,11 @@ namespace sssr */ void Context::GetReflectionViewViewMatrix(std::uint64_t reflection_view_id, matrix4& view_matrix) const { - SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); + 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)); - SSSR_ASSERT(reflection_view_view_matrix); // should never happen + FFX_SSSR_ASSERT(reflection_view_view_matrix); // should never happen view_matrix = *reflection_view_view_matrix; } @@ -285,7 +285,7 @@ namespace sssr */ void Context::SetReflectionViewViewMatrix(std::uint64_t reflection_view_id, matrix4 const& view_matrix) { - SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); + FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); reflection_view_view_matrices_.Insert(ID(reflection_view_id), view_matrix); } @@ -298,11 +298,11 @@ namespace sssr */ void Context::GetReflectionViewProjectionMatrix(std::uint64_t reflection_view_id, matrix4& projection_matrix) const { - SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); + 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)); - SSSR_ASSERT(reflection_view_projection_matrix); // should never happen + FFX_SSSR_ASSERT(reflection_view_projection_matrix); // should never happen projection_matrix = *reflection_view_projection_matrix; } @@ -315,7 +315,7 @@ namespace sssr */ void Context::SetReflectionViewProjectionMatrix(std::uint64_t reflection_view_id, matrix4 const& projection_matrix) { - SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); + FFX_SSSR_ASSERT(IsOfType(reflection_view_id) && IsObjectValid(reflection_view_id)); reflection_view_projection_matrices_.Insert(ID(reflection_view_id), projection_matrix); } @@ -341,7 +341,7 @@ namespace sssr */ void Context::SetResourceType(std::uint64_t& object_id, ResourceType resource_type) { - SSSR_ASSERT(resource_type < kResourceType_Count); + FFX_SSSR_ASSERT(resource_type < kResourceType_Count); object_id |= ((static_cast(resource_type) + 1ull) << 48); } @@ -356,7 +356,7 @@ namespace sssr */ bool Context::CreateObject(std::uint64_t& object_id, ResourceType resource_type, IdDispenser& id_dispenser) { - SSSR_ASSERT(resource_type < kResourceType_Count); + FFX_SSSR_ASSERT(resource_type < kResourceType_Count); if (!id_dispenser.AllocateId(object_id)) { diff --git a/ffx-sssr/src/d3d12/context_d3d12.cpp b/ffx-sssr/src/d3d12/context_d3d12.cpp index 594b2e7..144dbaf 100644 --- a/ffx-sssr/src/d3d12/context_d3d12.cpp +++ b/ffx-sssr/src/d3d12/context_d3d12.cpp @@ -71,7 +71,7 @@ namespace }; } -namespace sssr +namespace ffx_sssr { /** The constructor for the ContextD3D12 class. @@ -79,15 +79,15 @@ namespace sssr \param context The execution context. \param create_context_info The context creation information. */ - ContextD3D12::ContextD3D12(Context& context, SssrCreateContextInfo const& create_context_info) : + ContextD3D12::ContextD3D12(Context& context, FfxSssrCreateContextInfo const& create_context_info) : context_(context) - , device_(GetValidDevice(context, create_context_info.pCreateContextInfoD3D12->pDevice)) + , device_(GetValidDevice(context, create_context_info.pD3D12CreateContextInfo->pDevice)) , shader_compiler_(context) , samplers_were_populated_(false) , upload_buffer_(*this, create_context_info.uploadBufferSize) , reflection_views_(create_context_info.maxReflectionViewCount) { - SSSR_ASSERT(device_ != nullptr); + FFX_SSSR_ASSERT(device_ != nullptr); struct { @@ -104,35 +104,35 @@ namespace sssr { "resolve_spatial", resolve_spatial, "cs_6_0"}, { "resolve_temporal", resolve_temporal, "cs_6_0"}, { "resolve_eaw", resolve_eaw, "cs_6_0"}, - { "resolve_eaw_stride", resolve_eaw_stride, "cs_6_0", {L"SSR_EAW_STRIDE", L"2"}}, - { "resolve_eaw_stride", resolve_eaw_stride, "cs_6_0", {L"SSR_EAW_STRIDE", L"4"}}, + { "resolve_eaw_stride", resolve_eaw_stride, "cs_6_0", {L"FFX_SSSR_EAW_STRIDE", L"2"}}, + { "resolve_eaw_stride", resolve_eaw_stride, "cs_6_0", {L"FFX_SSSR_EAW_STRIDE", L"4"}}, }; auto const common_include = std::string(common); DxcDefine defines[11]; - defines[0].Name = L"SSR_ROUGHNESS_TEXTURE_FORMAT"; + defines[0].Name = L"FFX_SSSR_ROUGHNESS_TEXTURE_FORMAT"; defines[0].Value = create_context_info.pRoughnessTextureFormat; - defines[1].Name = L"SSR_ROUGHNESS_UNPACK_FUNCTION"; + defines[1].Name = L"FFX_SSSR_ROUGHNESS_UNPACK_FUNCTION"; defines[1].Value = create_context_info.pUnpackRoughnessSnippet; - defines[2].Name = L"SSR_NORMALS_TEXTURE_FORMAT"; + defines[2].Name = L"FFX_SSSR_NORMALS_TEXTURE_FORMAT"; defines[2].Value = create_context_info.pNormalsTextureFormat; - defines[3].Name = L"SSR_NORMALS_UNPACK_FUNCTION"; + defines[3].Name = L"FFX_SSSR_NORMALS_UNPACK_FUNCTION"; defines[3].Value = create_context_info.pUnpackNormalsSnippet; - defines[4].Name = L"SSR_MOTION_VECTOR_TEXTURE_FORMAT"; + defines[4].Name = L"FFX_SSSR_MOTION_VECTOR_TEXTURE_FORMAT"; defines[4].Value = create_context_info.pMotionVectorFormat; - defines[5].Name = L"SSR_MOTION_VECTOR_UNPACK_FUNCTION"; + defines[5].Name = L"FFX_SSSR_MOTION_VECTOR_UNPACK_FUNCTION"; defines[5].Value = create_context_info.pUnpackMotionVectorsSnippet; - defines[6].Name = L"SSR_DEPTH_TEXTURE_FORMAT"; + defines[6].Name = L"FFX_SSSR_DEPTH_TEXTURE_FORMAT"; defines[6].Value = create_context_info.pDepthTextureFormat; - defines[7].Name = L"SSR_DEPTH_UNPACK_FUNCTION"; + defines[7].Name = L"FFX_SSSR_DEPTH_UNPACK_FUNCTION"; defines[7].Value = create_context_info.pUnpackDepthSnippet; - defines[8].Name = L"SSR_SCENE_TEXTURE_FORMAT"; + defines[8].Name = L"FFX_SSSR_SCENE_TEXTURE_FORMAT"; defines[8].Value = create_context_info.pSceneTextureFormat; - defines[9].Name = L"SSR_SCENE_RADIANCE_UNPACK_FUNCTION"; + defines[9].Name = L"FFX_SSSR_SCENE_RADIANCE_UNPACK_FUNCTION"; defines[9].Value = create_context_info.pUnpackSceneRadianceSnippet; - static_assert(SSSR_ARRAY_SIZE(shader_source) == kShader_Count, "'kShader_Count' filenames must be provided for building the various shaders"); + 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) { @@ -151,15 +151,15 @@ namespace sssr shader_source[i].shader_name_, shader_source[i].profile_, nullptr, 0, - defines, SSSR_ARRAY_SIZE(defines)); + defines, FFX_SSSR_ARRAY_SIZE(defines)); } - SSSR_ASSERT(shaders_[shader_key]); // should never happen as compile throws in case of failure + FFX_SSSR_ASSERT(shaders_[shader_key]); // should never happen as compile throws in case of failure } // Create our blue noise samplers BlueNoiseSamplerD3D12* blue_noise_samplers[] = { &blue_noise_sampler_1spp_, &blue_noise_sampler_2spp_ }; - static_assert(SSSR_ARRAY_SIZE(blue_noise_samplers) == SSSR_ARRAY_SIZE(g_sampler_states), "Sampler arrays don't match."); - for (auto i = 0u; i < SSSR_ARRAY_SIZE(g_sampler_states); ++i) + 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]; @@ -177,28 +177,28 @@ namespace sssr D3D12_RESOURCE_STATE_COPY_DEST, L"SSSR Scrambling Tile Buffer")) { - throw reflection_error(context_, SSSR_STATUS_OUT_OF_MEMORY, "Unable to create SRV buffer(s) for sampler."); + throw reflection_error(context_, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Unable to create SRV buffer(s) for sampler."); } } - ID3D12GraphicsCommandList * command_list = create_context_info.pCreateContextInfoD3D12->pUploadCommandList; + 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 < SSSR_ARRAY_SIZE(g_sampler_states); ++i) + 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]; - SSSR_ASSERT(sampler->sobol_buffer_); - SSSR_ASSERT(sampler->ranking_tile_buffer_); - SSSR_ASSERT(sampler->scrambling_tile_buffer_); + 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_, SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %llukiB of upload memory, consider increasing uploadBufferSize", RoundedDivide(sizeof(sampler_state.sobol_buffer_), 1024ull)); + 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_)); @@ -210,7 +210,7 @@ namespace sssr if (!upload_buffer_.AllocateBuffer(sizeof(sampler_state.ranking_tile_buffer_), upload_buffer)) { - throw reflection_error(context_, SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %llukiB of upload memory, consider increasing uploadBufferSize", RoundedDivide(sizeof(sampler_state.ranking_tile_buffer_), 1024ull)); + 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_)); @@ -222,7 +222,7 @@ namespace sssr if (!upload_buffer_.AllocateBuffer(sizeof(sampler_state.scrambling_tile_buffer_), upload_buffer)) { - throw reflection_error(context_, SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %llukiB of upload memory, consider increasing uploadBufferSize", RoundedDivide(sizeof(sampler_state.scrambling_tile_buffer_), 1024ull)); + 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_)); @@ -234,10 +234,10 @@ namespace sssr } // Transition the resources for usage - D3D12_RESOURCE_BARRIER resource_barriers[3 * SSSR_ARRAY_SIZE(g_sampler_states)]; + 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 < SSSR_ARRAY_SIZE(g_sampler_states); ++i) + for (auto i = 0u; i < FFX_SSSR_ARRAY_SIZE(g_sampler_states); ++i) { BlueNoiseSamplerD3D12* sampler = blue_noise_samplers[i]; @@ -263,7 +263,7 @@ namespace sssr scrambling_tile_buffer_resource_barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; } - command_list->ResourceBarrier(SSSR_ARRAY_SIZE(resource_barriers), + command_list->ResourceBarrier(FFX_SSSR_ARRAY_SIZE(resource_barriers), resource_barriers); // Flag that the samplers are now ready to use @@ -286,14 +286,14 @@ namespace sssr */ void ContextD3D12::GetReflectionViewTileClassificationElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const { - SSSR_ASSERT(reflection_views_.At(ID(reflection_view_id))); // not created properly? - SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id)); + 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_ & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)) + if (!((reflection_view.flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)) { - throw reflection_error(context_, SSSR_STATUS_INVALID_OPERATION, "Cannot query the tile classification elapsed time of a reflection view that was not created with the SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag"); + 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_; @@ -307,14 +307,14 @@ namespace sssr */ void ContextD3D12::GetReflectionViewIntersectionElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const { - SSSR_ASSERT(reflection_views_.At(ID(reflection_view_id))); // not created properly? - SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id)); + 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_ & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)) + if (!((reflection_view.flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)) { - throw reflection_error(context_, SSSR_STATUS_INVALID_OPERATION, "Cannot query the intersection elapsed time of a reflection view that was not created with the SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag"); + 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_; @@ -328,14 +328,14 @@ namespace sssr */ void ContextD3D12::GetReflectionViewDenoisingElapsedTime(std::uint64_t reflection_view_id, std::uint64_t& elapsed_time) const { - SSSR_ASSERT(reflection_views_.At(ID(reflection_view_id))); // not created properly? - SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id)); + 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_ & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)) + if (!((reflection_view.flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0)) { - throw reflection_error(context_, SSSR_STATUS_INVALID_OPERATION, "Cannot query the denoising elapsed time of a reflection view that was not created with the SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS flag"); + 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_; @@ -347,34 +347,34 @@ namespace sssr \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, SssrCreateReflectionViewInfo const& create_reflection_view_info) + void ContextD3D12::CreateReflectionView(std::uint64_t reflection_view_id, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info) { - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12); - SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id)); + 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_, SSSR_STATUS_INVALID_VALUE, "The outputWidth and outputHeight parameters are required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->depthBufferHierarchySRV.ptr) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The depthBufferHierarchySRV parameter is required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->motionBufferSRV.ptr) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The motionBufferSRV parameter is required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->normalBufferSRV.ptr) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The normalBufferSRV parameter is required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->roughnessBufferSRV.ptr) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The roughnessBufferSRV parameter is required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->normalHistoryBufferSRV.ptr) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The normalHistoryBufferSRV parameter is required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->roughnessHistoryBufferSRV.ptr) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The roughnessHistoryBufferSRV parameter is required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->reflectionViewUAV.ptr) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The reflectionViewUAV parameter is required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->environmentMapSRV.ptr) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The environmentMapSRV parameter is required when creating a reflection view"); - if (!create_reflection_view_info.pCreateReflectionViewInfoD3D12->pEnvironmentMapSamplerDesc) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The pEnvironmentMapSamplerDesc parameter is required when creating a reflection view"); - if(create_reflection_view_info.pCreateReflectionViewInfoD3D12->sceneFormat == DXGI_FORMAT_UNKNOWN) - throw reflection_error(context_, SSSR_STATUS_INVALID_VALUE, "The sceneFormat parameter is required when creating a reflection view"); + 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)); @@ -387,12 +387,12 @@ namespace sssr \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, SssrResolveReflectionViewInfo const& resolve_reflection_view_info) + void ContextD3D12::ResolveReflectionView(std::uint64_t reflection_view_id, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info) { - SSSR_ASSERT(reflection_views_.At(ID(reflection_view_id))); // not created properly? - SSSR_ASSERT(context_.IsOfType(reflection_view_id) && context_.IsObjectValid(reflection_view_id)); - SSSR_ASSERT(context_.reflection_view_view_matrices_.At(ID(reflection_view_id))); - SSSR_ASSERT(context_.reflection_view_projection_matrices_.At(ID(reflection_view_id))); + 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)]; @@ -412,7 +412,7 @@ namespace sssr */ bool ContextD3D12::AllocateSRVBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name) const { - SSSR_ASSERT(resource != nullptr); + FFX_SSSR_ASSERT(resource != nullptr); D3D12_HEAP_PROPERTIES heap_properties = {}; heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT; @@ -457,7 +457,7 @@ namespace sssr */ bool ContextD3D12::AllocateUAVBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name) const { - SSSR_ASSERT(resource != nullptr); + FFX_SSSR_ASSERT(resource != nullptr); D3D12_HEAP_PROPERTIES heap_properties = {}; heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT; @@ -503,7 +503,7 @@ namespace sssr */ bool ContextD3D12::AllocateReadbackBuffer(std::size_t buffer_size, ID3D12Resource** resource, D3D12_RESOURCE_STATES initial_resource_state, wchar_t const* resource_name) const { - SSSR_ASSERT(resource != nullptr); + FFX_SSSR_ASSERT(resource != nullptr); D3D12_HEAP_PROPERTIES heap_properties = {}; heap_properties.Type = D3D12_HEAP_TYPE_READBACK; diff --git a/ffx-sssr/src/d3d12/context_d3d12.h b/ffx-sssr/src/d3d12/context_d3d12.h index f94d486..3d5d4e0 100644 --- a/ffx-sssr/src/d3d12/context_d3d12.h +++ b/ffx-sssr/src/d3d12/context_d3d12.h @@ -30,7 +30,7 @@ THE SOFTWARE. #include "upload_buffer_d3d12.h" #include "shader_compiler_d3d12.h" -namespace sssr +namespace ffx_sssr { class Context; class ReflectionViewD3D12; @@ -40,7 +40,7 @@ namespace sssr */ class ContextD3D12 { - SSSR_NON_COPYABLE(ContextD3D12); + FFX_SSSR_NON_COPYABLE(ContextD3D12); public: /** @@ -60,7 +60,7 @@ namespace sssr kShader_Count }; - ContextD3D12(Context& context, SssrCreateContextInfo const& create_context_info); + ContextD3D12(Context& context, FfxSssrCreateContextInfo const& create_context_info); ~ContextD3D12(); inline Context& GetContext(); @@ -76,8 +76,8 @@ namespace sssr 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, SssrCreateReflectionViewInfo const& create_reflection_view_info); - void ResolveReflectionView(std::uint64_t reflection_view_id, SssrResolveReflectionViewInfo const& resolve_reflection_view_info); + 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); @@ -110,7 +110,7 @@ namespace sssr // The execution context. Context& context_; - // The DXR device to be used. + // The device to be used. ID3D12Device* device_; // The compiled reflections shaders. std::map shaders_; diff --git a/ffx-sssr/src/d3d12/context_d3d12.inl b/ffx-sssr/src/d3d12/context_d3d12.inl index 94fefaa..948a4e4 100644 --- a/ffx-sssr/src/d3d12/context_d3d12.inl +++ b/ffx-sssr/src/d3d12/context_d3d12.inl @@ -22,7 +22,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the ShaderKey class. @@ -118,10 +118,10 @@ namespace sssr */ ShaderD3D12 const& ContextD3D12::GetShader(Shader shader) const { - SSSR_ASSERT(shader < kShader_Count); + FFX_SSSR_ASSERT(shader < kShader_Count); ShaderKey const shader_key(shader, 0ull); auto const it = shaders_.find(shader_key); - SSSR_ASSERT(it != shaders_.end()); + FFX_SSSR_ASSERT(it != shaders_.end()); return (*it).second; } @@ -132,9 +132,9 @@ namespace sssr */ inline BlueNoiseSamplerD3D12 const & ContextD3D12::GetSampler1SPP() const { - SSSR_ASSERT(blue_noise_sampler_1spp_.sobol_buffer_); - SSSR_ASSERT(blue_noise_sampler_1spp_.ranking_tile_buffer_); - SSSR_ASSERT(blue_noise_sampler_1spp_.scrambling_tile_buffer_); + 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_; } @@ -145,9 +145,9 @@ namespace sssr */ inline BlueNoiseSamplerD3D12 const & ContextD3D12::GetSampler2SPP() const { - SSSR_ASSERT(blue_noise_sampler_2spp_.sobol_buffer_); - SSSR_ASSERT(blue_noise_sampler_2spp_.ranking_tile_buffer_); - SSSR_ASSERT(blue_noise_sampler_2spp_.scrambling_tile_buffer_); + 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_; } @@ -161,16 +161,16 @@ namespace sssr ID3D12Device* ContextD3D12::GetValidDevice(Context& context, ID3D12Device* device) { if (!device) - throw reflection_error(context, SSSR_STATUS_INVALID_VALUE, "No device was supplied."); + 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, SSSR_STATUS_INVALID_VALUE, "Unable to check for shader model support on provided device."); + 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, SSSR_STATUS_INVALID_VALUE, "Device does not support shader model 6.2."); + throw reflection_error(context, FFX_SSSR_STATUS_INVALID_VALUE, "Device does not support shader model 6.2."); return device; } @@ -185,7 +185,7 @@ namespace sssr ID3D12GraphicsCommandList* ContextD3D12::GetCommandList(Context& context, ID3D12GraphicsCommandList* command_list) { if (!command_list) - throw reflection_error(context, SSSR_STATUS_INVALID_VALUE, "No command list was supplied, cannot encode device commands"); + throw reflection_error(context, FFX_SSSR_STATUS_INVALID_VALUE, "No command list was supplied, cannot encode device commands"); return command_list; } } diff --git a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.cpp b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.cpp index c60aa3a..9fd625d 100644 --- a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.cpp +++ b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. #include "reflection_error.h" #include "context_d3d12.h" -namespace sssr +namespace ffx_sssr { /** The constructor for the DescriptorHeapD3D12 class. @@ -78,7 +78,7 @@ namespace sssr result = context_.GetContextD3D12()->GetDevice()->CreateDescriptorHeap(&descriptor_heap_desc, IID_PPV_ARGS(&descriptor_heap)); if (!SUCCEEDED(result)) { - throw reflection_error(context_, SSSR_STATUS_INTERNAL_ERROR, "Unable to create descriptor heap"); + throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to create descriptor heap"); } descriptor_heap->SetName(L"SSSR Descriptor Heap"); diff --git a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.h b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.h index baa53d5..bb18d14 100644 --- a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.h +++ b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.h @@ -26,7 +26,7 @@ THE SOFTWARE. #include "context.h" -namespace sssr +namespace ffx_sssr { class DescriptorHeapD3D12; @@ -59,7 +59,7 @@ namespace sssr */ class DescriptorHeapD3D12 { - SSSR_NON_COPYABLE(DescriptorHeapD3D12); + FFX_SSSR_NON_COPYABLE(DescriptorHeapD3D12); public: DescriptorHeapD3D12(Context& context); diff --git a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.inl b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.inl index 7b50ada..37a5ab0 100644 --- a/ffx-sssr/src/d3d12/descriptor_heap_d3d12.inl +++ b/ffx-sssr/src/d3d12/descriptor_heap_d3d12.inl @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the DescriptorD3D12 class. @@ -42,7 +42,7 @@ namespace sssr */ D3D12_CPU_DESCRIPTOR_HANDLE DescriptorD3D12::GetCPUDescriptor(std::uint32_t descriptor_index) const { - SSSR_ASSERT(descriptor_index < descriptor_count_); + 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; @@ -56,7 +56,7 @@ namespace sssr */ D3D12_GPU_DESCRIPTOR_HANDLE DescriptorD3D12::GetGPUDescriptor(std::uint32_t descriptor_index) const { - SSSR_ASSERT(descriptor_index < descriptor_count_); + 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; @@ -164,7 +164,7 @@ namespace sssr while (!dynamic_descriptor_heap_ranges_.empty() && dynamic_descriptor_heap_ranges_.front().Overlap(dynamic_descriptor_heap_range)) { - SSSR_ASSERT(context_.GetFrameIndex() >= dynamic_descriptor_heap_ranges_.front().frame_index_); + FFX_SSSR_ASSERT(context_.GetFrameIndex() >= dynamic_descriptor_heap_ranges_.front().frame_index_); if (context_.GetFrameIndex() - dynamic_descriptor_heap_ranges_.front().frame_index_ < context_.GetFrameCountBeforeReuse()) { diff --git a/ffx-sssr/src/d3d12/reflection_view_d3d12.cpp b/ffx-sssr/src/d3d12/reflection_view_d3d12.cpp index d6c91a9..91f587d 100644 --- a/ffx-sssr/src/d3d12/reflection_view_d3d12.cpp +++ b/ffx-sssr/src/d3d12/reflection_view_d3d12.cpp @@ -111,7 +111,7 @@ namespace } } -namespace sssr +namespace ffx_sssr { /** The constructor for the ReflectionViewD3D12 class. @@ -397,26 +397,26 @@ namespace sssr \param context The context to be used. \param create_reflection_view_info The reflection view creation information. */ - void ReflectionViewD3D12::Create(Context& context, SssrCreateReflectionViewInfo const& create_reflection_view_info) + void ReflectionViewD3D12::Create(Context& context, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info) { - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12 != nullptr); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->sceneFormat != DXGI_FORMAT_UNKNOWN); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->depthBufferHierarchySRV.ptr); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->motionBufferSRV.ptr); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->normalBufferSRV.ptr); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->roughnessBufferSRV.ptr); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->normalHistoryBufferSRV.ptr); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->roughnessHistoryBufferSRV.ptr); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->environmentMapSRV.ptr); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->pEnvironmentMapSamplerDesc); - SSSR_ASSERT(create_reflection_view_info.pCreateReflectionViewInfoD3D12->reflectionViewUAV.ptr); - SSSR_ASSERT(create_reflection_view_info.outputWidth && create_reflection_view_info.outputHeight); + 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.pCreateReflectionViewInfoD3D12->sceneFormat; + scene_format_ = create_reflection_view_info.pD3D12CreateReflectionViewInfo->sceneFormat; // Create reflection view resources CreateRootSignature(context, create_reflection_view_info); @@ -467,7 +467,7 @@ namespace sssr 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, SSSR_ARRAY_SIZE(resource_descs), resource_descs); + 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; @@ -481,7 +481,7 @@ namespace sssr HRESULT hr = device->CreateHeap(&heap_desc, IID_PPV_ARGS(&resource_heap_)); if (!SUCCEEDED(hr)) { - throw reflection_error(context, SSSR_STATUS_OUT_OF_MEMORY, "Failed to create resource heap."); + throw reflection_error(context, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to create resource heap."); } UINT64 heap_offset = 0; @@ -495,7 +495,7 @@ namespace sssr HRESULT hr = device->CreatePlacedResource(resource_heap_, heap_offset, desc, initial_state, nullptr, riidResource, ppvResource); if (!SUCCEEDED(hr)) { - throw reflection_error(context, SSSR_STATUS_OUT_OF_MEMORY, "Failed to create placed resource."); + throw reflection_error(context, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Failed to create placed resource."); } heap_offset += desc->Width; @@ -532,7 +532,7 @@ namespace sssr hr = device->CreateCommandSignature(&desc, nullptr, IID_PPV_ARGS(&indirect_dispatch_command_signature_)); if (!SUCCEEDED(hr)) { - throw reflection_error(context, SSSR_STATUS_INTERNAL_ERROR, "Failed to create command signature for indirect dispatch."); + throw reflection_error(context, FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to create command signature for indirect dispatch."); } } @@ -574,7 +574,7 @@ namespace sssr if (!SUCCEEDED(hr)) { - throw reflection_error(context, SSSR_STATUS_INTERNAL_ERROR, "Failed to create intermediate target."); + throw reflection_error(context, FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to create intermediate target."); } }; @@ -623,21 +623,21 @@ namespace sssr 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.pCreateReflectionViewInfoD3D12->sceneSRV; - D3D12_CPU_DESCRIPTOR_HANDLE depth_hierarchy_srv = create_reflection_view_info.pCreateReflectionViewInfoD3D12->depthBufferHierarchySRV; - D3D12_CPU_DESCRIPTOR_HANDLE motion_buffer_srv = create_reflection_view_info.pCreateReflectionViewInfoD3D12->motionBufferSRV; - D3D12_CPU_DESCRIPTOR_HANDLE normal_buffer_srv = create_reflection_view_info.pCreateReflectionViewInfoD3D12->normalBufferSRV; - D3D12_CPU_DESCRIPTOR_HANDLE roughness_buffer_srv = create_reflection_view_info.pCreateReflectionViewInfoD3D12->roughnessBufferSRV; - D3D12_CPU_DESCRIPTOR_HANDLE normal_history_buffer_srv = create_reflection_view_info.pCreateReflectionViewInfoD3D12->normalHistoryBufferSRV; - D3D12_CPU_DESCRIPTOR_HANDLE roughness_history_buffer_srv = create_reflection_view_info.pCreateReflectionViewInfoD3D12->roughnessHistoryBufferSRV; - D3D12_CPU_DESCRIPTOR_HANDLE environment_map_srv = create_reflection_view_info.pCreateReflectionViewInfoD3D12->environmentMapSRV; - D3D12_CPU_DESCRIPTOR_HANDLE output_buffer_uav = create_reflection_view_info.pCreateReflectionViewInfoD3D12->reflectionViewUAV; + 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; 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 & SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_NORMAL_BUFFERS) != 0; - bool ping_pong_roughness = (create_reflection_view_info.flags & SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_ROUGHNESS_BUFFERS) != 0; + 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) { @@ -746,10 +746,10 @@ namespace sssr 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 + device->CreateUnorderedAccessView(ray_list_, nullptr, &UAV_Buffer(num_pixels), table.GetCPUDescriptor(offset++)); // g_ray_list } // Spatial denoising pass @@ -759,11 +759,11 @@ namespace sssr 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 + device->CreateUnorderedAccessView(temporal_denoiser_result_[i], nullptr, &UAV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_intersection_result + device->CreateUnorderedAccessView(temporal_variance_, nullptr, &UAV_Tex2D(DXGI_FORMAT_R8_UNORM), table.GetCPUDescriptor(offset++)); // g_has_ray + device->CreateUnorderedAccessView(tile_list_, nullptr, &UAV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list } // Temporal denoising pass @@ -776,12 +776,12 @@ namespace sssr 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 + 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(tile_list_, nullptr, &UAV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list } // EAW denoising pass @@ -791,9 +791,9 @@ namespace sssr 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 + device->CreateUnorderedAccessView(tile_list_, nullptr, &UAV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list } // EAW Stride 2 denoising pass (the same as the EAW pass, but input and output buffers flipped) @@ -803,9 +803,9 @@ namespace sssr 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->CopyDescriptorsSimple(1, table.GetCPUDescriptor(offset++), output_buffer_uav, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); // g_denoised_reflections device->CreateUnorderedAccessView(temporal_denoiser_result_[i], nullptr, &UAV_Tex2D(scene_format_), table.GetCPUDescriptor(offset++)); // g_temporally_denoised_reflections + device->CreateUnorderedAccessView(tile_list_, nullptr, &UAV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list } // EAW Stride 4 denoising pass (the very same as the EAW pass) @@ -815,15 +815,15 @@ namespace sssr 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 + device->CreateUnorderedAccessView(tile_list_, nullptr, &UAV_Buffer(num_tiles), table.GetCPUDescriptor(offset++)); // g_tile_list } } } // Create timestamp querying resources if enabled - if ((create_reflection_view_info.flags & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) + 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); @@ -834,7 +834,7 @@ namespace sssr if (!SUCCEEDED(context.GetContextD3D12()->GetDevice()->CreateQueryHeap(&query_heap_desc, IID_PPV_ARGS(×tamp_query_heap_)))) { - throw reflection_error(context, SSSR_STATUS_OUT_OF_MEMORY, "Unable to create timestamp 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, @@ -842,7 +842,7 @@ namespace sssr D3D12_RESOURCE_STATE_COPY_DEST, L"TimestampQueryBuffer")) { - throw reflection_error(context, SSSR_STATUS_OUT_OF_MEMORY, "Unable to allocate readback buffer"); + throw reflection_error(context, FFX_SSSR_STATUS_OUT_OF_MEMORY, "Unable to allocate readback buffer"); } timestamp_queries_.resize(context.GetFrameCountBeforeReuse()); @@ -873,26 +873,26 @@ namespace sssr descriptor_heap_cbv_srv_uav_ = nullptr; -#define SSSR_SAFE_RELEASE(x)\ +#define FFX_SSSR_SAFE_RELEASE(x)\ if(x) { x->Release(); }\ x = nullptr; - SSSR_SAFE_RELEASE(indirect_dispatch_command_signature_); - SSSR_SAFE_RELEASE(timestamp_query_heap_); - SSSR_SAFE_RELEASE(timestamp_query_buffer_); - SSSR_SAFE_RELEASE(temporal_denoiser_result_[0]); - SSSR_SAFE_RELEASE(temporal_denoiser_result_[1]); - SSSR_SAFE_RELEASE(ray_lengths_); - SSSR_SAFE_RELEASE(temporal_variance_); - SSSR_SAFE_RELEASE(tile_list_); - SSSR_SAFE_RELEASE(tile_counter_); - SSSR_SAFE_RELEASE(ray_list_); - SSSR_SAFE_RELEASE(ray_counter_); - SSSR_SAFE_RELEASE(intersection_pass_indirect_args_); - SSSR_SAFE_RELEASE(denoiser_pass_indirect_args_); - SSSR_SAFE_RELEASE(resource_heap_); - -#undef SSSR_SAFE_RELEASE + FFX_SSSR_SAFE_RELEASE(indirect_dispatch_command_signature_); + 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); } @@ -902,7 +902,7 @@ namespace sssr \param context The context to be used. */ - void ReflectionViewD3D12::CreateRootSignature(Context& context, SssrCreateReflectionViewInfo const& create_reflection_view_info) + void ReflectionViewD3D12::CreateRootSignature(Context& context, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info) { auto CreateRootSignature = [&context, &create_reflection_view_info]( ShaderPass& pass @@ -916,7 +916,7 @@ namespace sssr InitAsConstantBufferView(0) }; - D3D12_STATIC_SAMPLER_DESC environment_sampler = *create_reflection_view_info.pCreateReflectionViewInfoD3D12->pEnvironmentMapSamplerDesc; + D3D12_STATIC_SAMPLER_DESC environment_sampler = *create_reflection_view_info.pD3D12CreateReflectionViewInfo->pEnvironmentMapSamplerDesc; environment_sampler.RegisterSpace = 0; environment_sampler.ShaderRegister = 1; environment_sampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; @@ -924,9 +924,9 @@ namespace sssr D3D12_STATIC_SAMPLER_DESC sampler_descs[] = { InitLinearSampler(0), environment_sampler }; // g_linear_sampler D3D12_ROOT_SIGNATURE_DESC rs_desc = {}; - rs_desc.NumParameters = SSSR_ARRAY_SIZE(root); + rs_desc.NumParameters = FFX_SSSR_ARRAY_SIZE(root); rs_desc.pParameters = root; - rs_desc.NumStaticSamplers = SSSR_ARRAY_SIZE(sampler_descs); + rs_desc.NumStaticSamplers = FFX_SSSR_ARRAY_SIZE(sampler_descs); rs_desc.pStaticSamplers = sampler_descs; HRESULT hr; @@ -938,11 +938,11 @@ namespace sssr { std::string const error_message(static_cast(rsError->GetBufferPointer())); rsError->Release(); - throw reflection_error(context, SSSR_STATUS_INTERNAL_ERROR, "Unable to serialize root signature:\r\n> %s", error_message.c_str()); + throw reflection_error(context, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to serialize root signature:\r\n> %s", error_message.c_str()); } else { - throw reflection_error(context, SSSR_STATUS_INTERNAL_ERROR, "Unable to serialize root signature"); + throw reflection_error(context, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to serialize root signature"); } } @@ -950,7 +950,7 @@ namespace sssr rs->Release(); if (FAILED(hr)) { - throw reflection_error(context, SSSR_STATUS_INTERNAL_ERROR, "Failed to create root signature."); + throw reflection_error(context, FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to create root signature."); } pass.root_signature_->SetName(name); @@ -970,8 +970,8 @@ namespace sssr 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", SSSR_ARRAY_SIZE(ranges), ranges); - descriptor_count_tile_classification_ = SSSR_ARRAY_SIZE(ranges); + CreateRootSignature(tile_classification_pass_, L"SSSR Tile Classification Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges); + descriptor_count_tile_classification_ = FFX_SSSR_ARRAY_SIZE(ranges); } // Assemble the shader pass that prepares the indirect arguments @@ -982,8 +982,8 @@ namespace sssr 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", SSSR_ARRAY_SIZE(ranges), ranges); - descriptor_count_indirect_args_ = SSSR_ARRAY_SIZE(ranges); + CreateRootSignature(indirect_args_pass_, L"SSSR Indirect Arguments Pass Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges); + descriptor_count_indirect_args_ = FFX_SSSR_ARRAY_SIZE(ranges); } // Assemble the shader pass for intersecting reflection rays with the depth buffer @@ -997,13 +997,13 @@ namespace sssr 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 + InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 3), // g_ray_list }; - CreateRootSignature(intersection_pass_, L"SSSR Depth Buffer Intersection Root Signature", SSSR_ARRAY_SIZE(ranges), ranges); - descriptor_count_intersection_ = SSSR_ARRAY_SIZE(ranges); + CreateRootSignature(intersection_pass_, L"SSSR Depth Buffer Intersection Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges); + descriptor_count_intersection_ = FFX_SSSR_ARRAY_SIZE(ranges); } // Assemble the shader pass for spatial resolve @@ -1012,14 +1012,14 @@ namespace sssr 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 + InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 2), // g_intersection_result + InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 3), // g_has_ray + InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 4), // g_tile_list }; - CreateRootSignature(spatial_denoising_pass_, L"SSSR Spatial Resolve Root Signature", SSSR_ARRAY_SIZE(ranges), ranges); - descriptor_count_spatial_ = SSSR_ARRAY_SIZE(ranges); + CreateRootSignature(spatial_denoising_pass_, L"SSSR Spatial Resolve Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges); + descriptor_count_spatial_ = FFX_SSSR_ARRAY_SIZE(ranges); } // Assemble the shader pass for temporal resolve @@ -1031,15 +1031,15 @@ namespace sssr 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 + InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 3), // g_temporally_denoised_reflections_history + InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 4), // g_ray_lengths + InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 5), // g_tile_list }; - CreateRootSignature(temporal_denoising_pass_, L"SSSR Temporal Resolve Root Signature", SSSR_ARRAY_SIZE(ranges), ranges); - descriptor_count_temporal_ = SSSR_ARRAY_SIZE(ranges); + CreateRootSignature(temporal_denoising_pass_, L"SSSR Temporal Resolve Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges); + descriptor_count_temporal_ = FFX_SSSR_ARRAY_SIZE(ranges); } // Assemble the shader pass for EAW resolve @@ -1048,18 +1048,18 @@ namespace sssr 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 + InitDescriptorRange(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 2), // g_tile_list }; - CreateRootSignature(eaw_denoising_pass_, L"SSSR EAW Resolve Root Signature", SSSR_ARRAY_SIZE(ranges), ranges); - descriptor_count_eaw_ = SSSR_ARRAY_SIZE(ranges); + CreateRootSignature(eaw_denoising_pass_, L"SSSR EAW Resolve Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges); + descriptor_count_eaw_ = FFX_SSSR_ARRAY_SIZE(ranges); - CreateRootSignature(eaw_stride_2_denoising_pass_, L"SSSR EAW Stride 2 Resolve Root Signature", SSSR_ARRAY_SIZE(ranges), ranges); - descriptor_count_eaw_stride_2_ = SSSR_ARRAY_SIZE(ranges); + CreateRootSignature(eaw_stride_2_denoising_pass_, L"SSSR EAW Stride 2 Resolve Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges); + descriptor_count_eaw_stride_2_ = FFX_SSSR_ARRAY_SIZE(ranges); - CreateRootSignature(eaw_stride_4_denoising_pass_, L"SSSR EAW Stride 4 Resolve Root Signature", SSSR_ARRAY_SIZE(ranges), ranges); - descriptor_count_eaw_stride_4_ = SSSR_ARRAY_SIZE(ranges); + CreateRootSignature(eaw_stride_4_denoising_pass_, L"SSSR EAW Stride 4 Resolve Root Signature", FFX_SSSR_ARRAY_SIZE(ranges), ranges); + descriptor_count_eaw_stride_4_ = FFX_SSSR_ARRAY_SIZE(ranges); } } @@ -1072,7 +1072,7 @@ namespace sssr void ReflectionViewD3D12::CreatePipelineState(Context& context) { auto Compile = [&context](ShaderPass& pass, ContextD3D12::Shader shader, const LPCWSTR name) { - SSSR_ASSERT(pass.root_signature_ != nullptr); + FFX_SSSR_ASSERT(pass.root_signature_ != nullptr); // Create the pipeline state object D3D12_COMPUTE_PIPELINE_STATE_DESC pipeline_state_desc = {}; @@ -1083,7 +1083,7 @@ namespace sssr IID_PPV_ARGS(&pass.pipeline_state_)); if (!SUCCEEDED(hr)) { - throw reflection_error(context, SSSR_STATUS_INTERNAL_ERROR, "Failed to create compute pipeline state"); + throw reflection_error(context, FFX_SSSR_STATUS_INTERNAL_ERROR, "Failed to create compute pipeline state"); } pass.pipeline_state_->SetName(name); @@ -1106,9 +1106,9 @@ namespace sssr */ void ReflectionViewD3D12::CreateDescriptorHeaps(Context& context) { - SSSR_ASSERT(!descriptor_heap_cbv_srv_uav_); + FFX_SSSR_ASSERT(!descriptor_heap_cbv_srv_uav_); descriptor_heap_cbv_srv_uav_ = new DescriptorHeapD3D12(context); - SSSR_ASSERT(descriptor_heap_cbv_srv_uav_ != nullptr); + FFX_SSSR_ASSERT(descriptor_heap_cbv_srv_uav_ != nullptr); std::uint32_t descriptor_count = descriptor_count_tile_classification_ + descriptor_count_indirect_args_ + descriptor_count_intersection_ + descriptor_count_spatial_ + descriptor_count_temporal_ + descriptor_count_eaw_ + descriptor_count_eaw_stride_2_ + descriptor_count_eaw_stride_4_; descriptor_heap_cbv_srv_uav_->Create(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 2 * descriptor_count, 0u); @@ -1144,25 +1144,25 @@ namespace sssr \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, SssrResolveReflectionViewInfo const& resolve_reflection_view_info) + void ReflectionViewD3D12::Resolve(Context& context, ReflectionView const& reflection_view, FfxSssrResolveReflectionViewInfo const& resolve_reflection_view_info) { // Get hold of the command list for recording - SSSR_ASSERT(resolve_reflection_view_info.pCommandEncodeInfoD3D12); - auto const command_list = ContextD3D12::GetCommandList(context, resolve_reflection_view_info.pCommandEncodeInfoD3D12->pCommandList); - SSSR_ASSERT(descriptor_heap_cbv_srv_uav_ && command_list); - SSSR_ASSERT(tile_classification_pass_); - SSSR_ASSERT(indirect_args_pass_); - SSSR_ASSERT(intersection_pass_); - SSSR_ASSERT(spatial_denoising_pass_); - SSSR_ASSERT(temporal_denoising_pass_); - SSSR_ASSERT(eaw_denoising_pass_); - SSSR_ASSERT(eaw_stride_2_denoising_pass_); - SSSR_ASSERT(eaw_stride_4_denoising_pass_); - SSSR_ASSERT(resolve_reflection_view_info.samplesPerQuad == SSSR_RAY_SAMPLES_PER_QUAD_1 || resolve_reflection_view_info.samplesPerQuad == SSSR_RAY_SAMPLES_PER_QUAD_2 || resolve_reflection_view_info.samplesPerQuad == SSSR_RAY_SAMPLES_PER_QUAD_4); - SSSR_ASSERT(resolve_reflection_view_info.eawPassCount == SSSR_EAW_PASS_COUNT_1 || resolve_reflection_view_info.eawPassCount == SSSR_EAW_PASS_COUNT_3); + 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_ && command_list); + FFX_SSSR_ASSERT(tile_classification_pass_); + FFX_SSSR_ASSERT(indirect_args_pass_); + FFX_SSSR_ASSERT(intersection_pass_); + FFX_SSSR_ASSERT(spatial_denoising_pass_); + FFX_SSSR_ASSERT(temporal_denoising_pass_); + FFX_SSSR_ASSERT(eaw_denoising_pass_); + FFX_SSSR_ASSERT(eaw_stride_2_denoising_pass_); + FFX_SSSR_ASSERT(eaw_stride_4_denoising_pass_); + 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); + FFX_SSSR_ASSERT(resolve_reflection_view_info.eawPassCount == FFX_SSSR_EAW_PASS_COUNT_1 || resolve_reflection_view_info.eawPassCount == FFX_SSSR_EAW_PASS_COUNT_3); // Query timestamp value prior to resolving the reflection view - if ((flags_ & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) + if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) { auto& timestamp_queries = timestamp_queries_[timestamp_queries_index_]; @@ -1242,7 +1242,7 @@ namespace sssr PassData* pass_data; if (!upload_buffer.AllocateBuffer(sizeof(PassData), pass_data)) { - throw reflection_error(context, SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %u bytes of upload memory, consider increasing uploadBufferSize", sizeof(PassData)); + 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 @@ -1261,10 +1261,10 @@ namespace sssr 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 == SSSR_RAY_SAMPLES_PER_QUAD_4 ? 4 : (resolve_reflection_view_info.samplesPerQuad == SSSR_RAY_SAMPLES_PER_QUAD_2 ? 2 : 1); - pass_data->temporal_variance_guided_tracing_enabled_ = resolve_reflection_view_info.flags & SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING ? 1 : 0; + 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 & SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE ? 0 : 1; + 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; @@ -1312,7 +1312,7 @@ namespace sssr 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(SSSR_ARRAY_SIZE(classification_results_barriers), classification_results_barriers); + command_list->ResourceBarrier(FFX_SSSR_ARRAY_SIZE(classification_results_barriers), classification_results_barriers); // Indirect Arguments pass { @@ -1324,11 +1324,11 @@ namespace sssr } // Query the amount of time spent in the intersection pass - if ((flags_ & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) + if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) { auto& timestamp_queries = timestamp_queries_[timestamp_queries_index_]; - SSSR_ASSERT(timestamp_queries.size() == 1ull && timestamp_queries[0] == kTimestampQuery_Init); + FFX_SSSR_ASSERT(timestamp_queries.size() == 1ull && timestamp_queries[0] == kTimestampQuery_Init); command_list->EndQuery(timestamp_query_heap_, D3D12_QUERY_TYPE_TIMESTAMP, @@ -1344,7 +1344,7 @@ namespace sssr 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(SSSR_ARRAY_SIZE(indirect_arguments_barriers), indirect_arguments_barriers); + command_list->ResourceBarrier(FFX_SSSR_ARRAY_SIZE(indirect_arguments_barriers), indirect_arguments_barriers); // Intersection pass { @@ -1356,11 +1356,11 @@ namespace sssr } // Query the amount of time spent in the intersection pass - if ((flags_ & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) + if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) { auto& timestamp_queries = timestamp_queries_[timestamp_queries_index_]; - SSSR_ASSERT(timestamp_queries.size() == 2ull && timestamp_queries[1] == kTimestampQuery_TileClassification); + FFX_SSSR_ASSERT(timestamp_queries.size() == 2ull && timestamp_queries[1] == kTimestampQuery_TileClassification); command_list->EndQuery(timestamp_query_heap_, D3D12_QUERY_TYPE_TIMESTAMP, @@ -1369,7 +1369,7 @@ namespace sssr timestamp_queries.push_back(kTimestampQuery_Intersection); } - if (resolve_reflection_view_info.flags & SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE) + 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])); @@ -1407,7 +1407,7 @@ namespace sssr command_list->ExecuteIndirect(indirect_dispatch_command_signature_, 1, denoiser_pass_indirect_args_, 0, nullptr, 0); } - if (resolve_reflection_view_info.eawPassCount == SSSR_EAW_PASS_COUNT_3) + if (resolve_reflection_view_info.eawPassCount == FFX_SSSR_EAW_PASS_COUNT_3) { // Ensure that the prior EAW pass has finished command_list->ResourceBarrier(1, &UAVBarrier(nullptr)); @@ -1430,11 +1430,11 @@ namespace sssr } // Query the amount of time spent in the denoiser passes - if ((flags_ & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) + if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) { auto& timestamp_queries = timestamp_queries_[timestamp_queries_index_]; - SSSR_ASSERT(timestamp_queries.size() == 3ull && timestamp_queries[2] == kTimestampQuery_Intersection); + FFX_SSSR_ASSERT(timestamp_queries.size() == 3ull && timestamp_queries[2] == kTimestampQuery_Intersection); command_list->EndQuery(timestamp_query_heap_, D3D12_QUERY_TYPE_TIMESTAMP, @@ -1445,7 +1445,7 @@ namespace sssr } // Resolve the timestamp query data - if ((flags_ & SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) + if ((flags_ & FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS) != 0) { auto const start_index = timestamp_queries_index_ * kTimestampQuery_Count; diff --git a/ffx-sssr/src/d3d12/reflection_view_d3d12.h b/ffx-sssr/src/d3d12/reflection_view_d3d12.h index d860595..a982617 100644 --- a/ffx-sssr/src/d3d12/reflection_view_d3d12.h +++ b/ffx-sssr/src/d3d12/reflection_view_d3d12.h @@ -30,7 +30,7 @@ THE SOFTWARE. #include "ffx_sssr.h" #include "descriptor_heap_d3d12.h" -namespace sssr +namespace ffx_sssr { class Context; class ReflectionView; @@ -40,13 +40,9 @@ namespace sssr */ class ReflectionViewD3D12 { - SSSR_NON_COPYABLE(ReflectionViewD3D12); + FFX_SSSR_NON_COPYABLE(ReflectionViewD3D12); public: - /** - The type definition for an individual ray counter. - */ - using RayCount = std::pair; /** The available timestamp queries. @@ -71,7 +67,7 @@ namespace sssr */ class ShaderPass { - SSSR_NON_COPYABLE(ShaderPass); + FFX_SSSR_NON_COPYABLE(ShaderPass); public: inline ShaderPass(); @@ -96,23 +92,23 @@ namespace sssr ReflectionViewD3D12(ReflectionViewD3D12&& other) noexcept; ReflectionViewD3D12& operator =(ReflectionViewD3D12&& other) noexcept; - void Create(Context& context, SssrCreateReflectionViewInfo const& create_reflection_view_info); + void Create(Context& context, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info); void Destroy(); - void CreateRootSignature(Context& context, SssrCreateReflectionViewInfo const& create_reflection_view_info); + void CreateRootSignature(Context& context, FfxSssrCreateReflectionViewInfo const& create_reflection_view_info); void CreatePipelineState(Context& context); void CreateDescriptorHeaps(Context& context); std::uint32_t GetTimestampQueryIndex() const; - void Resolve(Context& context, ReflectionView const& reflection_view, SssrResolveReflectionViewInfo const& resolve_reflection_view_info); + 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. - SssrCreateReflectionViewFlags flags_; + FfxSssrCreateReflectionViewFlags flags_; // The descriptor heap for CBVs, SRVs, and UAVs. DescriptorHeapD3D12* descriptor_heap_cbv_srv_uav_; diff --git a/ffx-sssr/src/d3d12/reflection_view_d3d12.inl b/ffx-sssr/src/d3d12/reflection_view_d3d12.inl index 11d9f7e..92b3847 100644 --- a/ffx-sssr/src/d3d12/reflection_view_d3d12.inl +++ b/ffx-sssr/src/d3d12/reflection_view_d3d12.inl @@ -22,7 +22,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the ShaderPass class. diff --git a/ffx-sssr/src/d3d12/sampler_d3d12.cpp b/ffx-sssr/src/d3d12/sampler_d3d12.cpp index d511de1..9d80b3b 100644 --- a/ffx-sssr/src/d3d12/sampler_d3d12.cpp +++ b/ffx-sssr/src/d3d12/sampler_d3d12.cpp @@ -21,10 +21,10 @@ THE SOFTWARE. ********************************************************************/ #include "sampler_d3d12.h" -namespace sssr +namespace ffx_sssr { /** - The constructor for the SamplerD3D12 class. + The constructor for the BlueNoiseSamplerD3D12 class. */ BlueNoiseSamplerD3D12::BlueNoiseSamplerD3D12() : sobol_buffer_(nullptr) @@ -34,7 +34,7 @@ namespace sssr } /** - The constructor for the SamplerD3D12 class. + The constructor for the BlueNoiseSamplerD3D12 class. \param other The sampler to be moved. */ @@ -49,7 +49,7 @@ namespace sssr } /** - The destructor for the SamplerD3D12 class. + The destructor for the BlueNoiseSamplerD3D12 class. */ BlueNoiseSamplerD3D12::~BlueNoiseSamplerD3D12() { diff --git a/ffx-sssr/src/d3d12/sampler_d3d12.h b/ffx-sssr/src/d3d12/sampler_d3d12.h index b48abec..13dc989 100644 --- a/ffx-sssr/src/d3d12/sampler_d3d12.h +++ b/ffx-sssr/src/d3d12/sampler_d3d12.h @@ -26,7 +26,7 @@ THE SOFTWARE. #include "macros.h" #include "ffx_sssr.h" -namespace sssr +namespace ffx_sssr { /** The BlueNoiseSamplerD3D12 class represents a blue-noise sampler to be used for random number generation. @@ -35,7 +35,7 @@ namespace sssr */ class BlueNoiseSamplerD3D12 { - SSSR_NON_COPYABLE(BlueNoiseSamplerD3D12); + FFX_SSSR_NON_COPYABLE(BlueNoiseSamplerD3D12); public: BlueNoiseSamplerD3D12(); diff --git a/ffx-sssr/src/d3d12/shader_compiler_d3d12.cpp b/ffx-sssr/src/d3d12/shader_compiler_d3d12.cpp index 7475374..e3fb705 100644 --- a/ffx-sssr/src/d3d12/shader_compiler_d3d12.cpp +++ b/ffx-sssr/src/d3d12/shader_compiler_d3d12.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. #include "reflection_error.h" #include "utils.h" -namespace sssr +namespace ffx_sssr { /** The constructor for the ShaderCompilerD3D12 class. @@ -70,7 +70,7 @@ namespace sssr 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; - SSSR_ASSERT(filename && profile); + FFX_SSSR_ASSERT(filename && profile); if (!LoadShaderCompiler()) { @@ -82,7 +82,7 @@ namespace sssr auto const shader_filename = StringToWString(filename); result = dxc_library_->CreateBlobFromFile(shader_filename.c_str(), nullptr, &dxc_source); if (FAILED(result)) - throw reflection_error(context_, SSSR_STATUS_INVALID_OPERATION, "Could not create shader blob from %s", filename); + 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); @@ -94,7 +94,7 @@ namespace sssr 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; - SSSR_ASSERT(string && profile); + FFX_SSSR_ASSERT(string && profile); if (!LoadShaderCompiler()) { @@ -104,7 +104,7 @@ namespace sssr IDxcBlobEncoding* dxc_source; result = dxc_library_->CreateBlobWithEncodingFromPinned((LPBYTE)string, string_size, 0, &dxc_source); if (FAILED(result)) - throw reflection_error(context_, SSSR_STATUS_INVALID_OPERATION, "Could not create blob with encoding from pinned for %s", shader_name); + 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); @@ -122,19 +122,19 @@ namespace sssr { HRESULT result = dxc_dll_support_.Initialize(); if (FAILED(result)) - throw reflection_error(context_, SSSR_STATUS_INTERNAL_ERROR, "Unable to initialize dxcompiler.dll support"); + 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_, SSSR_STATUS_INTERNAL_ERROR, "Unable to create DXC compiler instance"); + 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_, SSSR_STATUS_INTERNAL_ERROR, "Unable to create DXC library instance"); + 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_, SSSR_STATUS_INTERNAL_ERROR, "Unable to create DXC include handler"); + throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Unable to create DXC include handler"); } else if (!dxc_compiler_ || !dxc_library_) { @@ -179,7 +179,7 @@ namespace sssr // Check for compilation errors if (FAILED(result)) - throw reflection_error(context_, SSSR_STATUS_INTERNAL_ERROR, "Failed to compile D3D12 shader source code"); + 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; @@ -187,19 +187,19 @@ namespace sssr std::string const error(static_cast(dxc_error->GetBufferPointer())); dxc_result->Release(); dxc_error->Release(); - throw reflection_error(context_, SSSR_STATUS_INTERNAL_ERROR, "Unable to compile shader file:\r\n> %s", error.c_str()); + 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); - SSSR_ASSERT(dxc_program != nullptr); + FFX_SSSR_ASSERT(dxc_program != nullptr); dxc_result->Release(); // Retrieve the shader bytecode shader.BytecodeLength = dxc_program->GetBufferSize(); auto const shader_bytecode = malloc(shader.BytecodeLength); - SSSR_ASSERT(shader_bytecode != nullptr); // out of memory + FFX_SSSR_ASSERT(shader_bytecode != nullptr); // out of memory memcpy(shader_bytecode, dxc_program->GetBufferPointer(), shader.BytecodeLength); shader.pShaderBytecode = shader_bytecode; dxc_program->Release(); diff --git a/ffx-sssr/src/d3d12/shader_compiler_d3d12.h b/ffx-sssr/src/d3d12/shader_compiler_d3d12.h index 03d5084..f711ce1 100644 --- a/ffx-sssr/src/d3d12/shader_compiler_d3d12.h +++ b/ffx-sssr/src/d3d12/shader_compiler_d3d12.h @@ -26,7 +26,7 @@ THE SOFTWARE. #include "macros.h" -namespace sssr +namespace ffx_sssr { class Context; @@ -35,7 +35,7 @@ namespace sssr */ class ShaderD3D12 : public D3D12_SHADER_BYTECODE { - SSSR_NON_COPYABLE(ShaderD3D12); + FFX_SSSR_NON_COPYABLE(ShaderD3D12); public: inline ShaderD3D12(); @@ -52,7 +52,7 @@ namespace sssr */ class ShaderCompilerD3D12 { - SSSR_NON_COPYABLE(ShaderCompilerD3D12); + FFX_SSSR_NON_COPYABLE(ShaderCompilerD3D12); public: ShaderCompilerD3D12(Context& context); diff --git a/ffx-sssr/src/d3d12/shader_compiler_d3d12.inl b/ffx-sssr/src/d3d12/shader_compiler_d3d12.inl index 73b3b75..ef1356b 100644 --- a/ffx-sssr/src/d3d12/shader_compiler_d3d12.inl +++ b/ffx-sssr/src/d3d12/shader_compiler_d3d12.inl @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the ShaderD3D12 class. diff --git a/ffx-sssr/src/d3d12/upload_buffer_d3d12.cpp b/ffx-sssr/src/d3d12/upload_buffer_d3d12.cpp index b52635c..99973eb 100644 --- a/ffx-sssr/src/d3d12/upload_buffer_d3d12.cpp +++ b/ffx-sssr/src/d3d12/upload_buffer_d3d12.cpp @@ -25,7 +25,7 @@ THE SOFTWARE. #include "context.h" #include "context_d3d12.h" -namespace sssr +namespace ffx_sssr { /** The constructor for the UploadBufferD3D12 class. @@ -39,7 +39,7 @@ namespace sssr , buffer_(nullptr) , blocks_(buffer_size) { - SSSR_ASSERT(context.GetDevice()); + FFX_SSSR_ASSERT(context.GetDevice()); D3D12_HEAP_PROPERTIES heap_properties = {}; heap_properties.Type = D3D12_HEAP_TYPE_UPLOAD; @@ -62,7 +62,7 @@ namespace sssr nullptr, IID_PPV_ARGS(&buffer_)))) { - throw reflection_error(context_, SSSR_STATUS_OUT_OF_MEMORY, "Failed to allocate %uMiB for the upload buffer", RoundedDivide(buffer_size, 1024ull * 1024ull)); + 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 = {}; @@ -73,7 +73,7 @@ namespace sssr &range, reinterpret_cast(&data_)))) { - throw reflection_error(context_, SSSR_STATUS_INTERNAL_ERROR, "Cannot map the Direct3D12 upload buffer"); + throw reflection_error(context_, FFX_SSSR_STATUS_INTERNAL_ERROR, "Cannot map the Direct3D12 upload buffer"); } buffer_->SetName(L"UploadBufferRing"); @@ -138,7 +138,7 @@ namespace sssr 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_); - SSSR_ASSERT(buffer_ && data >= data_ && offset + size <= buffer_->GetDesc().Width); // buffer overflow! + 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; @@ -159,7 +159,7 @@ namespace sssr 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_); - SSSR_ASSERT(buffer_ && data >= data_ && offset + size <= buffer_->GetDesc().Width); // buffer overflow! + 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; diff --git a/ffx-sssr/src/d3d12/upload_buffer_d3d12.h b/ffx-sssr/src/d3d12/upload_buffer_d3d12.h index 2353abd..f47c4e7 100644 --- a/ffx-sssr/src/d3d12/upload_buffer_d3d12.h +++ b/ffx-sssr/src/d3d12/upload_buffer_d3d12.h @@ -25,7 +25,7 @@ THE SOFTWARE. #include "memory.h" -namespace sssr +namespace ffx_sssr { class Context; class ContextD3D12; @@ -35,7 +35,7 @@ namespace sssr */ class UploadBufferD3D12 { - SSSR_NON_COPYABLE(UploadBufferD3D12); + FFX_SSSR_NON_COPYABLE(UploadBufferD3D12); public: UploadBufferD3D12(ContextD3D12& context, std::size_t buffer_size); diff --git a/ffx-sssr/src/d3d12/upload_buffer_d3d12.inl b/ffx-sssr/src/d3d12/upload_buffer_d3d12.inl index 02d8d7c..62109ec 100644 --- a/ffx-sssr/src/d3d12/upload_buffer_d3d12.inl +++ b/ffx-sssr/src/d3d12/upload_buffer_d3d12.inl @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the Block class. @@ -40,7 +40,7 @@ namespace sssr */ bool UploadBufferD3D12::Block::CanBeReused() const { - SSSR_ASSERT(frame_index_ && *frame_index_ >= block_index_); + FFX_SSSR_ASSERT(frame_index_ && *frame_index_ >= block_index_); return (*frame_index_ - block_index_ >= frame_count_before_reuse_); } @@ -76,7 +76,7 @@ namespace sssr if (!data) return 0ull; auto const offset = static_cast(data) - static_cast(data_); - SSSR_ASSERT(buffer_ && data >= data_ && static_cast(offset) < buffer_->GetDesc().Width); // buffer overflow! + FFX_SSSR_ASSERT(buffer_ && data >= data_ && static_cast(offset) < buffer_->GetDesc().Width); // buffer overflow! return static_cast(offset); } diff --git a/ffx-sssr/src/float3.h b/ffx-sssr/src/float3.h index c7a784b..10c57a9 100644 --- a/ffx-sssr/src/float3.h +++ b/ffx-sssr/src/float3.h @@ -24,7 +24,7 @@ THE SOFTWARE. #include #include -namespace sssr +namespace ffx_sssr { /** The tfloat3 class represents a generic 3-wide vector. diff --git a/ffx-sssr/src/float3.inl b/ffx-sssr/src/float3.inl index 478683b..fb06f69 100644 --- a/ffx-sssr/src/float3.inl +++ b/ffx-sssr/src/float3.inl @@ -22,7 +22,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the tfloat3 class. diff --git a/ffx-sssr/src/macros.h b/ffx-sssr/src/macros.h index 6e7896a..710e10d 100644 --- a/ffx-sssr/src/macros.h +++ b/ffx-sssr/src/macros.h @@ -39,7 +39,7 @@ THE SOFTWARE. \return The size of the static array. */ -#define SSSR_ARRAY_SIZE(ARRAY) \ +#define FFX_SSSR_ARRAY_SIZE(ARRAY) \ static_cast(sizeof(ARRAY) / sizeof(*(ARRAY))) /** @@ -47,7 +47,7 @@ THE SOFTWARE. \param TYPE - The type to be made non-copyable. */ -#define SSSR_NON_COPYABLE(TYPE) \ +#define FFX_SSSR_NON_COPYABLE(TYPE) \ TYPE(TYPE const&) = delete; \ TYPE& operator =(TYPE const&) = delete @@ -56,7 +56,7 @@ THE SOFTWARE. /** A macro to start a do while loop. */ - #define SSSR_MULTI_LINE_MACRO_BEGIN \ + #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 */ \ @@ -66,7 +66,7 @@ THE SOFTWARE. /** A macro to end a do while loop. */ - #define SSSR_MULTI_LINE_MACRO_END \ + #define FFX_SSSR_MULTI_LINE_MACRO_END \ } \ while (0) \ __pragma(warning(pop)) @@ -74,37 +74,37 @@ THE SOFTWARE. /** Triggers a breakpoint. */ - #define SSSR_BREAKPOINT \ - SSSR_MULTI_LINE_MACRO_BEGIN \ + #define FFX_SSSR_BREAKPOINT \ + FFX_SSSR_MULTI_LINE_MACRO_BEGIN \ if (IsDebuggerPresent()) \ { \ DebugBreak(); \ } \ - SSSR_MULTI_LINE_MACRO_END + FFX_SSSR_MULTI_LINE_MACRO_END #else // _MSC_VER /** A macro to start a do while loop. */ - #define SSSR_MULTI_LINE_MACRO_BEGIN \ + #define FFX_SSSR_MULTI_LINE_MACRO_BEGIN \ do \ { /** A macro to end a do while loop. */ - #define SSSR_MULTI_LINE_MACRO_END \ + #define FFX_SSSR_MULTI_LINE_MACRO_END \ } \ while (0) /** Triggers a breakpoint. */ - #define SSSR_BREAKPOINT \ - SSSR_MULTI_LINE_MACRO_BEGIN \ + #define FFX_SSSR_BREAKPOINT \ + FFX_SSSR_MULTI_LINE_MACRO_BEGIN \ assert(0); \ - SSSR_MULTI_LINE_MACRO_END + FFX_SSSR_MULTI_LINE_MACRO_END #endif // _MSC_VER @@ -115,13 +115,13 @@ THE SOFTWARE. \param expr The expression to evaluate. */ - #define SSSR_ASSERT(expr) \ - SSSR_MULTI_LINE_MACRO_BEGIN \ + #define FFX_SSSR_ASSERT(expr) \ + FFX_SSSR_MULTI_LINE_MACRO_BEGIN \ if (!(expr)) \ { \ - SSSR_BREAKPOINT; \ + FFX_SSSR_BREAKPOINT; \ } \ - SSSR_MULTI_LINE_MACRO_END + FFX_SSSR_MULTI_LINE_MACRO_END #else // _DEBUG @@ -130,9 +130,9 @@ THE SOFTWARE. \param expr The expression to be ignored. */ - #define SSSR_ASSERT(expr) \ - SSSR_MULTI_LINE_MACRO_BEGIN \ + #define FFX_SSSR_ASSERT(expr) \ + FFX_SSSR_MULTI_LINE_MACRO_BEGIN \ sizeof(expr); \ - SSSR_MULTI_LINE_MACRO_END + FFX_SSSR_MULTI_LINE_MACRO_END #endif // _DEBUG diff --git a/ffx-sssr/src/matrix4.h b/ffx-sssr/src/matrix4.h index 6faf165..03934ae 100644 --- a/ffx-sssr/src/matrix4.h +++ b/ffx-sssr/src/matrix4.h @@ -23,7 +23,7 @@ THE SOFTWARE. #include "float3.h" -namespace sssr +namespace ffx_sssr { /** The tmatrix4 class represents a generic 4x4 matrix. diff --git a/ffx-sssr/src/matrix4.inl b/ffx-sssr/src/matrix4.inl index 4c1bae4..6fb96b9 100644 --- a/ffx-sssr/src/matrix4.inl +++ b/ffx-sssr/src/matrix4.inl @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the tmatrix4 class. diff --git a/ffx-sssr/src/memory.h b/ffx-sssr/src/memory.h index bfc5057..c357671 100644 --- a/ffx-sssr/src/memory.h +++ b/ffx-sssr/src/memory.h @@ -29,7 +29,7 @@ THE SOFTWARE. #include "utils.h" #include "reflection_error.h" -namespace sssr +namespace ffx_sssr { /** The marker for an invalid index. @@ -46,7 +46,7 @@ namespace sssr */ class IdDispenser { - SSSR_NON_COPYABLE(IdDispenser); + FFX_SSSR_NON_COPYABLE(IdDispenser); public: inline IdDispenser(std::uint32_t max_id_count); @@ -78,7 +78,7 @@ namespace sssr template class SparseArray { - SSSR_NON_COPYABLE(SparseArray); + FFX_SSSR_NON_COPYABLE(SparseArray); public: /** @@ -177,7 +177,7 @@ namespace sssr template class RingBuffer { - SSSR_NON_COPYABLE(RingBuffer); + FFX_SSSR_NON_COPYABLE(RingBuffer); public: RingBuffer(std::size_t size); diff --git a/ffx-sssr/src/memory.inl b/ffx-sssr/src/memory.inl index 60eff09..d3e4ce0 100644 --- a/ffx-sssr/src/memory.inl +++ b/ffx-sssr/src/memory.inl @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the IdDispenser class. @@ -39,7 +39,7 @@ namespace sssr { free(ids_); - throw reflection_error(SSSR_STATUS_OUT_OF_MEMORY); + throw reflection_error(FFX_SSSR_STATUS_OUT_OF_MEMORY); } // Initialize the freelist @@ -62,11 +62,11 @@ namespace sssr #if 0 auto const leaked_id_count = (max_id_count_ - CalculateFreeIdCount()); - SSSR_ASSERT(leaked_id_count == id_count_); + FFX_SSSR_ASSERT(leaked_id_count == id_count_); if (leaked_id_count) { - SSSR_PRINTLN("%u resource%s %s not destroyed properly; detected memory leak", leaked_id_count, leaked_id_count > 1 ? "s" : "", leaked_id_count > 1 ? "were" : "was"); + FFX_SSSR_PRINTLN("%u resource%s %s not destroyed properly; detected memory leak", leaked_id_count, leaked_id_count > 1 ? "s" : "", leaked_id_count > 1 ? "were" : "was"); } #endif @@ -102,7 +102,7 @@ namespace sssr slot = (static_cast(age) << 32) | static_cast(kInvalidIndex); // Keep track of number of allocated identifiers - SSSR_ASSERT(id_count_ < max_id_count_); + FFX_SSSR_ASSERT(id_count_ < max_id_count_); ++id_count_; return true; @@ -117,7 +117,7 @@ namespace sssr { // Get hold of the freed slot auto const index = static_cast(id & 0xFFFFFFFFull); - SSSR_ASSERT(index < max_id_count_); + FFX_SSSR_ASSERT(index < max_id_count_); auto& slot = ids_[index]; // Check whether this is a valid operation @@ -133,7 +133,7 @@ namespace sssr next_index_ = index; // Keep track of number of allocated identifiers - SSSR_ASSERT(id_count_ > 0u); + FFX_SSSR_ASSERT(id_count_ > 0u); --id_count_; } @@ -167,7 +167,7 @@ namespace sssr { // Get hold of the corresponding slot auto const index = static_cast(id & 0xFFFFFFFFull); - SSSR_ASSERT(index < max_id_count_); + FFX_SSSR_ASSERT(index < max_id_count_); auto const slot = ids_[index]; // Check whether the identifier is still valid @@ -195,7 +195,7 @@ namespace sssr { ++free_id_count; } - SSSR_ASSERT(free_id_count <= max_id_count_); + FFX_SSSR_ASSERT(free_id_count <= max_id_count_); return free_id_count; } @@ -218,7 +218,7 @@ namespace sssr template typename SparseArray::iterator& SparseArray::iterator::operator ++() { - SSSR_ASSERT(array_ && index_ < array_->object_count_); + FFX_SSSR_ASSERT(array_ && index_ < array_->object_count_); ++index_; // iterate to next return *this; } @@ -231,7 +231,7 @@ namespace sssr template TYPE& SparseArray::iterator::operator *() const { - SSSR_ASSERT(array_ && index_ < array_->object_count_); + FFX_SSSR_ASSERT(array_ && index_ < array_->object_count_); return array_->objects_[index_]; } @@ -243,7 +243,7 @@ namespace sssr template SparseArray::iterator::operator std::uint32_t() const { - SSSR_ASSERT(array_ && index_ < array_->object_count_); + FFX_SSSR_ASSERT(array_ && index_ < array_->object_count_); return array_->virtual_indices_[index_]; } @@ -288,7 +288,7 @@ namespace sssr template typename SparseArray::const_iterator& SparseArray::const_iterator::operator ++() { - SSSR_ASSERT(array_ && index_ < array_->object_count_); + FFX_SSSR_ASSERT(array_ && index_ < array_->object_count_); ++index_; // iterate to next return *this; } @@ -301,7 +301,7 @@ namespace sssr template TYPE const& SparseArray::const_iterator::operator *() const { - SSSR_ASSERT(array_ && index_ < array_->object_count_); + FFX_SSSR_ASSERT(array_ && index_ < array_->object_count_); return array_->objects_[index_]; } @@ -313,7 +313,7 @@ namespace sssr template SparseArray::const_iterator::operator std::uint32_t() const { - SSSR_ASSERT(array_ && index_ < array_->object_count_); + FFX_SSSR_ASSERT(array_ && index_ < array_->object_count_); return array_->virtual_indices_[index_]; } @@ -348,7 +348,7 @@ namespace sssr free(virtual_indices_); free(physical_indices_); - throw reflection_error(SSSR_STATUS_OUT_OF_MEMORY); + throw reflection_error(FFX_SSSR_STATUS_OUT_OF_MEMORY); } // Invalidate all virtual entries @@ -368,7 +368,7 @@ namespace sssr if (leaked_object_count) { - SSSR_PRINTLN("%u component%s %s not destroyed properly; detected memory leak", leaked_object_count, leaked_object_count > 1 ? "s" : "", leaked_object_count > 1 ? "were" : "was"); + FFX_SSSR_PRINTLN("%u component%s %s not destroyed properly; detected memory leak", leaked_object_count, leaked_object_count > 1 ? "s" : "", leaked_object_count > 1 ? "were" : "was"); } #endif @@ -391,7 +391,7 @@ namespace sssr TYPE& SparseArray::operator [](std::uint32_t index) { auto const object = At(index); - SSSR_ASSERT(object != nullptr); + FFX_SSSR_ASSERT(object != nullptr); return *object; } @@ -405,7 +405,7 @@ namespace sssr TYPE const& SparseArray::operator [](std::uint32_t index) const { auto const object = At(index); - SSSR_ASSERT(object != nullptr); + FFX_SSSR_ASSERT(object != nullptr); return *object; } @@ -418,7 +418,7 @@ namespace sssr template TYPE* SparseArray::At(std::uint32_t index) { - SSSR_ASSERT(index < max_object_count_); + FFX_SSSR_ASSERT(index < max_object_count_); auto const physical_index = physical_indices_[index]; if (physical_index == kInvalidIndex) return nullptr; // not found @@ -434,7 +434,7 @@ namespace sssr template TYPE const* SparseArray::At(std::uint32_t index) const { - SSSR_ASSERT(index < max_object_count_); + FFX_SSSR_ASSERT(index < max_object_count_); auto const physical_index = physical_indices_[index]; if (physical_index == kInvalidIndex) return nullptr; // not found @@ -450,7 +450,7 @@ namespace sssr template bool SparseArray::Has(std::uint32_t index) const { - SSSR_ASSERT(index < max_object_count_); + FFX_SSSR_ASSERT(index < max_object_count_); return physical_indices_[index] != kInvalidIndex; } @@ -463,14 +463,14 @@ namespace sssr template TYPE& SparseArray::Insert(std::uint32_t index) { - SSSR_ASSERT(index < max_object_count_); + FFX_SSSR_ASSERT(index < max_object_count_); auto const physical_index = physical_indices_[index]; if (physical_index != kInvalidIndex) { (void)objects_[physical_index].~TYPE(); return *new(&objects_[physical_index]) TYPE(); } - SSSR_ASSERT(object_count_ < max_object_count_); + FFX_SSSR_ASSERT(object_count_ < max_object_count_); virtual_indices_[object_count_] = index; physical_indices_[index] = object_count_; return *new(&objects_[object_count_++]) TYPE(); @@ -486,14 +486,14 @@ namespace sssr template TYPE& SparseArray::Insert(std::uint32_t index, TYPE const& object) { - SSSR_ASSERT(index < max_object_count_); + FFX_SSSR_ASSERT(index < max_object_count_); auto const physical_index = physical_indices_[index]; if (physical_index != kInvalidIndex) { (void)objects_[physical_index].~TYPE(); return *new(&objects_[physical_index]) TYPE(object); } - SSSR_ASSERT(object_count_ < max_object_count_); + FFX_SSSR_ASSERT(object_count_ < max_object_count_); virtual_indices_[object_count_] = index; physical_indices_[index] = object_count_; return *new(&objects_[object_count_++]) TYPE(object); @@ -508,11 +508,11 @@ namespace sssr template bool SparseArray::Erase(std::uint32_t index) { - SSSR_ASSERT(index < max_object_count_); + FFX_SSSR_ASSERT(index < max_object_count_); auto const physical_index = physical_indices_[index]; if (physical_index == kInvalidIndex) return false; // nothing to erase here - SSSR_ASSERT(object_count_ > 0u); + FFX_SSSR_ASSERT(object_count_ > 0u); if (physical_index != object_count_ - 1u) { std::swap(objects_[physical_index], objects_[object_count_ - 1u]); @@ -591,7 +591,7 @@ namespace sssr template std::uint32_t SparseArray::GetVirtualIndex(std::uint32_t physical_index) const { - SSSR_ASSERT(physical_index < object_count_); + FFX_SSSR_ASSERT(physical_index < object_count_); return virtual_indices_[physical_index]; } @@ -605,7 +605,7 @@ namespace sssr template std::uint32_t SparseArray::GetPhysicalIndex(std::uint32_t virtual_index) const { - SSSR_ASSERT(virtual_index < max_object_count_); + FFX_SSSR_ASSERT(virtual_index < max_object_count_); return physical_indices_[virtual_index]; } @@ -772,7 +772,7 @@ namespace sssr } while (next_block && size > space_available); } - SSSR_ASSERT(size <= space_available); + FFX_SSSR_ASSERT(size <= space_available); // Insert the new block blocks_.emplace_back(); @@ -814,7 +814,7 @@ namespace sssr std::size_t RingBuffer::CalculateSpaceToNextAvailableBlock(Block const* next_block, std::size_t alignment) const { auto const new_head = Align(head_, alignment); - SSSR_ASSERT(!next_block || next_block->start_ + next_block->size_ > head_); + FFX_SSSR_ASSERT(!next_block || next_block->start_ + next_block->size_ > head_); return std::max(next_block ? next_block->start_ : size_, new_head) - new_head; } diff --git a/ffx-sssr/src/reflection_error.cpp b/ffx-sssr/src/reflection_error.cpp index 9b0a52b..0665610 100644 --- a/ffx-sssr/src/reflection_error.cpp +++ b/ffx-sssr/src/reflection_error.cpp @@ -23,13 +23,13 @@ THE SOFTWARE. #include "context.h" -namespace sssr +namespace ffx_sssr { /** The constructor for the reflection_error class. */ reflection_error::reflection_error() - : error_(SSSR_STATUS_INTERNAL_ERROR) + : error_(FFX_SSSR_STATUS_INTERNAL_ERROR) { } @@ -38,7 +38,7 @@ namespace sssr \param error The error code for this exception. */ - reflection_error::reflection_error(SssrStatus error) + reflection_error::reflection_error(FfxSssrStatus error) : error_(error) { } @@ -49,7 +49,7 @@ namespace sssr \param context The context to be used. \param error The error code for this exception. */ - reflection_error::reflection_error(Context& context, SssrStatus error) + reflection_error::reflection_error(Context& context, FfxSssrStatus error) : error_(error) { (void)&context; @@ -63,7 +63,7 @@ namespace sssr \param format The format for the error message. \param ... The content of the error message. */ - reflection_error::reflection_error(Context& context, SssrStatus error, char const* format, ...) + reflection_error::reflection_error(Context& context, FfxSssrStatus error, char const* format, ...) : error_(error) { va_list args; diff --git a/ffx-sssr/src/reflection_error.h b/ffx-sssr/src/reflection_error.h index aeea67f..c2d17fc 100644 --- a/ffx-sssr/src/reflection_error.h +++ b/ffx-sssr/src/reflection_error.h @@ -25,7 +25,7 @@ THE SOFTWARE. #include "ffx_sssr.h" -namespace sssr +namespace ffx_sssr { class Context; @@ -36,11 +36,11 @@ namespace sssr { public: reflection_error(); - reflection_error(SssrStatus error); - reflection_error(Context& context, SssrStatus error); - reflection_error(Context& context, SssrStatus error, char const* format, ...); + reflection_error(FfxSssrStatus error); + reflection_error(Context& context, FfxSssrStatus error); + reflection_error(Context& context, FfxSssrStatus error, char const* format, ...); // The error code for this exception. - SssrStatus error_; + FfxSssrStatus error_; }; } diff --git a/ffx-sssr/src/reflection_view.h b/ffx-sssr/src/reflection_view.h index 7230132..3ed2d19 100644 --- a/ffx-sssr/src/reflection_view.h +++ b/ffx-sssr/src/reflection_view.h @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The ReflectionView class encapsulates the information for resolving a reflection view. diff --git a/ffx-sssr/src/reflection_view.inl b/ffx-sssr/src/reflection_view.inl index 29c007b..8833b69 100644 --- a/ffx-sssr/src/reflection_view.inl +++ b/ffx-sssr/src/reflection_view.inl @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The constructor for the ReflectionView class. diff --git a/ffx-sssr/src/reflections.cpp b/ffx-sssr/src/reflections.cpp index 0402471..b079a44 100644 --- a/ffx-sssr/src/reflections.cpp +++ b/ffx-sssr/src/reflections.cpp @@ -26,7 +26,7 @@ THE SOFTWARE. /** A define for starting a try block. */ -#define SSSR_TRY \ +#define FFX_SSSR_TRY \ try /** @@ -34,8 +34,8 @@ THE SOFTWARE. \param ERROR The error callback. */ -#define SSSR_CATCH(ERROR) \ - catch (sssr::reflection_error const& error) \ +#define FFX_SSSR_CATCH(ERROR) \ + catch (ffx_sssr::reflection_error const& error) \ { \ ERROR(); \ return error.error_; \ @@ -43,12 +43,12 @@ THE SOFTWARE. catch (std::bad_alloc const&) \ { \ ERROR(); \ - return SSSR_STATUS_OUT_OF_MEMORY; \ + return FFX_SSSR_STATUS_OUT_OF_MEMORY; \ } \ catch (...) \ { \ ERROR(); \ - return SSSR_STATUS_INTERNAL_ERROR; \ + return FFX_SSSR_STATUS_INTERNAL_ERROR; \ } namespace @@ -58,7 +58,7 @@ namespace */ class APICall { - SSSR_NON_COPYABLE(APICall); + FFX_SSSR_NON_COPYABLE(APICall); public: /** @@ -67,7 +67,7 @@ namespace \param context The context to be used. \param api_call The API call that was requested. */ - inline APICall(sssr::Context& context, char const* api_call) + inline APICall(ffx_sssr::Context& context, char const* api_call) : context_(context) { context_.SetAPICall(api_call); @@ -83,7 +83,7 @@ namespace protected: // The context being in use. - sssr::Context& context_; + ffx_sssr::Context& context_; }; /** @@ -92,84 +92,84 @@ namespace \param CTX The context being used. \param API_CALL The API call that was requested. */ - #define SSSR_API_CALL(CTX, API_CALL) \ + #define FFX_SSSR_API_CALL(CTX, API_CALL) \ APICall const _api_call_##API_CALL(*CTX, #API_CALL) } -SssrStatus sssrCreateContext(const SssrCreateContextInfo* pCreateContextInfo, SssrContext* outContext) +FfxSssrStatus ffxSssrCreateContext(const FfxSssrCreateContextInfo* pCreateContextInfo, FfxSssrContext* outContext) { if (!pCreateContextInfo || !outContext) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } - if (pCreateContextInfo->apiVersion != SSSR_API_VERSION) + if (pCreateContextInfo->apiVersion != FFX_SSSR_API_VERSION) { - return SSSR_STATUS_INCOMPATIBLE_API; + return FFX_SSSR_STATUS_INCOMPATIBLE_API; } - sssr::Context* context; + ffx_sssr::Context* context; - SSSR_TRY + FFX_SSSR_TRY { - context = new sssr::Context(*pCreateContextInfo); + context = new ffx_sssr::Context(*pCreateContextInfo); if (!context) { - return SSSR_STATUS_OUT_OF_MEMORY; + return FFX_SSSR_STATUS_OUT_OF_MEMORY; } - *outContext = reinterpret_cast(context); + *outContext = reinterpret_cast(context); } - SSSR_CATCH([](){}) + FFX_SSSR_CATCH([](){}) context->SetAPICall(nullptr); - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrDestroyContext(SssrContext context) +FfxSssrStatus ffxSssrDestroyContext(FfxSssrContext context) { if (!context) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx) { - return SSSR_STATUS_OK; // nothing to destroy + return FFX_SSSR_STATUS_OK; // nothing to destroy } - ctx->SetAPICall("sssrDestroyContext"); + ctx->SetAPICall("ffxSssrDestroyContext"); delete ctx; - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrCreateReflectionView(SssrContext context, const SssrCreateReflectionViewInfo* pCreateReflectionViewInfo, SssrReflectionView* outReflectionView) +FfxSssrStatus ffxSssrCreateReflectionView(FfxSssrContext context, const FfxSssrCreateReflectionViewInfo* pCreateReflectionViewInfo, FfxSssrReflectionView* outReflectionView) { std::uint64_t reflection_view_id = 0ull; - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx || !pCreateReflectionViewInfo || !outReflectionView) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } - SSSR_API_CALL(ctx, sssrCreateReflectionView); + FFX_SSSR_API_CALL(ctx, ffxSssrCreateReflectionView); - SSSR_TRY + FFX_SSSR_TRY { - ctx->CreateObject(reflection_view_id); + ctx->CreateObject(reflection_view_id); ctx->CreateReflectionView(reflection_view_id, *pCreateReflectionViewInfo); - *outReflectionView = reinterpret_cast(reflection_view_id); + *outReflectionView = reinterpret_cast(reflection_view_id); } - SSSR_CATCH([&]() + FFX_SSSR_CATCH([&]() { if (reflection_view_id) { @@ -177,191 +177,191 @@ SssrStatus sssrCreateReflectionView(SssrContext context, const SssrCreateReflect } }) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrDestroyReflectionView(SssrContext context, SssrReflectionView reflectionView) +FfxSssrStatus ffxSssrDestroyReflectionView(FfxSssrContext context, FfxSssrReflectionView reflectionView) { - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } if (!reflectionView) { - return SSSR_STATUS_OK; // nothing to delete + return FFX_SSSR_STATUS_OK; // nothing to delete } auto const reflection_view_id = reinterpret_cast(reflectionView); - if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) + if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) { - return SSSR_STATUS_INVALID_VALUE; // not a valid reflection view + return FFX_SSSR_STATUS_INVALID_VALUE; // not a valid reflection view } - SSSR_API_CALL(ctx, sssrDestroyReflectionView); + FFX_SSSR_API_CALL(ctx, ffxSssrDestroyReflectionView); - SSSR_TRY + FFX_SSSR_TRY { ctx->DestroyObject(reflection_view_id); } - SSSR_CATCH([](){}) + FFX_SSSR_CATCH([](){}) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrEncodeResolveReflectionView(SssrContext context, SssrReflectionView reflectionView, const SssrResolveReflectionViewInfo* pResolveReflectionViewInfo) +FfxSssrStatus ffxSssrEncodeResolveReflectionView(FfxSssrContext context, FfxSssrReflectionView reflectionView, const FfxSssrResolveReflectionViewInfo* pResolveReflectionViewInfo) { - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx || !pResolveReflectionViewInfo) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } auto const reflection_view_id = reinterpret_cast(reflectionView); - if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) + if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) { - return SSSR_STATUS_INVALID_VALUE; // not a valid reflection view + return FFX_SSSR_STATUS_INVALID_VALUE; // not a valid reflection view } - SSSR_API_CALL(ctx, sssrEncodeResolveReflectionView); + FFX_SSSR_API_CALL(ctx, ffxSssrEncodeResolveReflectionView); - SSSR_TRY + FFX_SSSR_TRY { ctx->ResolveReflectionView(reflection_view_id, *pResolveReflectionViewInfo); } - SSSR_CATCH([](){}) + FFX_SSSR_CATCH([](){}) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrAdvanceToNextFrame(SssrContext context) +FfxSssrStatus ffxSssrAdvanceToNextFrame(FfxSssrContext context) { - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } - SSSR_API_CALL(ctx, sssrAdvanceToNextFrame); + FFX_SSSR_API_CALL(ctx, ffxSssrAdvanceToNextFrame); - SSSR_TRY + FFX_SSSR_TRY { ctx->AdvanceToNextFrame(); } - SSSR_CATCH([](){}) + FFX_SSSR_CATCH([](){}) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrReflectionViewGetTileClassificationElapsedTime(SssrContext context, SssrReflectionView reflectionView, uint64_t* outTileClassificationElapsedTime) +FfxSssrStatus ffxSssrReflectionViewGetTileClassificationElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outTileClassificationElapsedTime) { - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx || !outTileClassificationElapsedTime) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } auto const reflection_view_id = reinterpret_cast(reflectionView); - if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) + if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) { - return SSSR_STATUS_INVALID_VALUE; // not a valid reflection view + return FFX_SSSR_STATUS_INVALID_VALUE; // not a valid reflection view } - SSSR_API_CALL(ctx, sssrReflectionViewGetTileClassificationElapsedTime); + FFX_SSSR_API_CALL(ctx, ffxSssrReflectionViewGetTileClassificationElapsedTime); - SSSR_TRY + FFX_SSSR_TRY { ctx->GetReflectionViewTileClassificationElapsedTime(reflection_view_id, *outTileClassificationElapsedTime); } - SSSR_CATCH([]() {}) + FFX_SSSR_CATCH([]() {}) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrReflectionViewGetIntersectionElapsedTime(SssrContext context, SssrReflectionView reflectionView, uint64_t* outIntersectionElapsedTime) +FfxSssrStatus ffxSssrReflectionViewGetIntersectionElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outIntersectionElapsedTime) { - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx || !outIntersectionElapsedTime) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } auto const reflection_view_id = reinterpret_cast(reflectionView); - if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) + if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) { - return SSSR_STATUS_INVALID_VALUE; // not a valid reflection view + return FFX_SSSR_STATUS_INVALID_VALUE; // not a valid reflection view } - SSSR_API_CALL(ctx, sssrReflectionViewGetIntersectionElapsedTime); + FFX_SSSR_API_CALL(ctx, ffxSssrReflectionViewGetIntersectionElapsedTime); - SSSR_TRY + FFX_SSSR_TRY { ctx->GetReflectionViewIntersectionElapsedTime(reflection_view_id, *outIntersectionElapsedTime); } - SSSR_CATCH([](){}) + FFX_SSSR_CATCH([](){}) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrReflectionViewGetDenoisingElapsedTime(SssrContext context, SssrReflectionView reflectionView, uint64_t* outDenoisingElapsedTime) +FfxSssrStatus ffxSssrReflectionViewGetDenoisingElapsedTime(FfxSssrContext context, FfxSssrReflectionView reflectionView, uint64_t* outDenoisingElapsedTime) { - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx || !outDenoisingElapsedTime) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } auto const reflection_view_id = reinterpret_cast(reflectionView); - if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) + if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) { - return SSSR_STATUS_INVALID_VALUE; // not a valid reflection view + return FFX_SSSR_STATUS_INVALID_VALUE; // not a valid reflection view } - SSSR_API_CALL(ctx, sssrReflectionViewGetDenoisingElapsedTime); + FFX_SSSR_API_CALL(ctx, ffxSssrReflectionViewGetDenoisingElapsedTime); - SSSR_TRY + FFX_SSSR_TRY { ctx->GetReflectionViewDenoisingElapsedTime(reflection_view_id, *outDenoisingElapsedTime); } - SSSR_CATCH([](){}) + FFX_SSSR_CATCH([](){}) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrReflectionViewGetCameraParameters(SssrContext context, SssrReflectionView reflectionView, float* outViewMatrix, float* outProjectionMatrix) +FfxSssrStatus ffxSssrReflectionViewGetCameraParameters(FfxSssrContext context, FfxSssrReflectionView reflectionView, float* outViewMatrix, float* outProjectionMatrix) { - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx || !outViewMatrix || !outProjectionMatrix) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } auto const reflection_view_id = reinterpret_cast(reflectionView); - if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) + if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) { - return SSSR_STATUS_INVALID_VALUE; // not a valid reflection view + return FFX_SSSR_STATUS_INVALID_VALUE; // not a valid reflection view } - SSSR_API_CALL(ctx, sssrReflectionViewGetCameraParameters); + FFX_SSSR_API_CALL(ctx, ffxSssrReflectionViewGetCameraParameters); - SSSR_TRY + FFX_SSSR_TRY { - sssr::matrix4 reflection_view_view_matrix, reflection_view_projection_matrix; + ffx_sssr::matrix4 reflection_view_view_matrix, reflection_view_projection_matrix; ctx->GetReflectionViewViewMatrix(reflection_view_id, reflection_view_view_matrix); ctx->GetReflectionViewProjectionMatrix(reflection_view_id, reflection_view_projection_matrix); @@ -374,32 +374,32 @@ SssrStatus sssrReflectionViewGetCameraParameters(SssrContext context, SssrReflec } } } - SSSR_CATCH([](){}) + FFX_SSSR_CATCH([](){}) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } -SssrStatus sssrReflectionViewSetCameraParameters(SssrContext context, SssrReflectionView reflectionView, const float* pViewMatrix, const float* pProjectionMatrix) +FfxSssrStatus ffxSssrReflectionViewSetCameraParameters(FfxSssrContext context, FfxSssrReflectionView reflectionView, const float* pViewMatrix, const float* pProjectionMatrix) { - auto const ctx = reinterpret_cast(context); + auto const ctx = reinterpret_cast(context); if (!ctx || !pViewMatrix || !pProjectionMatrix) { - return SSSR_STATUS_INVALID_VALUE; + return FFX_SSSR_STATUS_INVALID_VALUE; } auto const reflection_view_id = reinterpret_cast(reflectionView); - if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) + if (!ctx->IsOfType(reflection_view_id) || !ctx->IsObjectValid(reflection_view_id)) { - return SSSR_STATUS_INVALID_VALUE; // not a valid reflection view + return FFX_SSSR_STATUS_INVALID_VALUE; // not a valid reflection view } - SSSR_API_CALL(ctx, sssrReflectionViewSetCameraParameters); + FFX_SSSR_API_CALL(ctx, ffxSssrReflectionViewSetCameraParameters); - SSSR_TRY + FFX_SSSR_TRY { - sssr::matrix4 reflection_view_view_matrix, reflection_view_projection_matrix; + ffx_sssr::matrix4 reflection_view_view_matrix, reflection_view_projection_matrix; for (auto row = 0u; row < 4u; ++row) { for (auto col = 0u; col < 4u; ++col) @@ -411,7 +411,7 @@ SssrStatus sssrReflectionViewSetCameraParameters(SssrContext context, SssrReflec ctx->SetReflectionViewViewMatrix(reflection_view_id, reflection_view_view_matrix); ctx->SetReflectionViewProjectionMatrix(reflection_view_id, reflection_view_projection_matrix); } - SSSR_CATCH([](){}) + FFX_SSSR_CATCH([](){}) - return SSSR_STATUS_OK; + return FFX_SSSR_STATUS_OK; } \ No newline at end of file diff --git a/ffx-sssr/src/resources.h b/ffx-sssr/src/resources.h index 9a56d8a..9d9442d 100644 --- a/ffx-sssr/src/resources.h +++ b/ffx-sssr/src/resources.h @@ -21,7 +21,7 @@ THE SOFTWARE. ********************************************************************/ #pragma once -namespace sssr +namespace ffx_sssr { /** The available resource types. diff --git a/ffx-sssr/src/utils.h b/ffx-sssr/src/utils.h index 3994dbd..be3041c 100644 --- a/ffx-sssr/src/utils.h +++ b/ffx-sssr/src/utils.h @@ -22,8 +22,9 @@ THE SOFTWARE. #pragma once #include "macros.h" +#include -namespace sssr +namespace ffx_sssr { /** Checks whether the value is a power of two. @@ -47,7 +48,7 @@ namespace sssr template static inline TYPE Align(TYPE value, TYPE alignment) { - SSSR_ASSERT(IsPowerOfTwo(alignment)); + FFX_SSSR_ASSERT(IsPowerOfTwo(alignment)); return (value + alignment - 1) & (~(alignment - 1)); } diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 7d5fdc6..2b673aa 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.4) set(CMAKE_GENERATOR_PLATFORM x64) -project (SSSRSample_${GFX_API}) +project (SssrSample_${GFX_API}) # ouput exe to bin directory SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin) diff --git a/sample/README.md b/sample/README.md index 58e85b0..c2d5dbe 100644 --- a/sample/README.md +++ b/sample/README.md @@ -17,6 +17,7 @@ To build this sample, the following tools are required: Then follow these steps: +0) This repository makes use of https://git-lfs.github.com/ to store large files. 1) Clone the repository with its submodules: ``` > git clone https://github.com/GPUOpen-Effects/FidelityFX-SSSR.git --recurse-submodules diff --git a/sample/libs/cauldron b/sample/libs/cauldron index 0ae1322..fd91cd7 160000 --- a/sample/libs/cauldron +++ b/sample/libs/cauldron @@ -1 +1 @@ -Subproject commit 0ae1322a8772ce457378e4de5ba6e2226cf9c7c8 +Subproject commit fd91cd744d014505daef1780dceee49fd62ce953 diff --git a/sample/src/Common/config.json b/sample/src/Common/config.json index a1450bd..b2ceb12 100644 --- a/sample/src/Common/config.json +++ b/sample/src/Common/config.json @@ -15,22 +15,6 @@ "distance": 1.0, "lookAt": [ 0, 0, 0 ] } - }, - { - "name": "BusterDrone", - "directory": "..\\media\\buster_drone\\", - "filename": "busterDrone.gltf", - "toneMapper": 2, - "iblFactor": 0.3, - "emmisiveFactor": 30, - "intensity": 50, - "exposure": 1, - "camera": { - "yaw": 0, - "pitch": 0, - "distance": 3.5, - "lookAt": [ 0, 0, 0 ] - } } ] } \ No newline at end of file diff --git a/sample/src/DX12/CMakeLists.txt b/sample/src/DX12/CMakeLists.txt index 7e23ab9..1ab0552 100644 --- a/sample/src/DX12/CMakeLists.txt +++ b/sample/src/DX12/CMakeLists.txt @@ -1,10 +1,10 @@ -project (SSSRSample_DX12) +project (SssrSample_DX12) add_compile_options(/MP) set(Sources_src - Sources/SSSRSample.cpp - Sources/SSSRSample.h + Sources/SssrSample.cpp + Sources/SssrSample.h Sources/SampleRenderer.cpp Sources/SampleRenderer.h Sources/stdafx.cpp diff --git a/sample/src/DX12/Shaders/ApplyReflections.hlsl b/sample/src/DX12/Shaders/ApplyReflections.hlsl index d4cd918..7f03e63 100644 --- a/sample/src/DX12/Shaders/ApplyReflections.hlsl +++ b/sample/src/DX12/Shaders/ApplyReflections.hlsl @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_APPLY -#define SSR_APPLY +#ifndef FFX_SSSR_APPLY +#define FFX_SSSR_APPLY Texture2D reflectionTarget : register(t0); Texture2D normalsTexture : register(t1); @@ -95,4 +95,4 @@ float4 ps_main(VertexOut input) : SV_Target0 } } -#endif // SSR_APPLY \ No newline at end of file +#endif // FFX_SSSR_APPLY \ No newline at end of file diff --git a/sample/src/DX12/Shaders/DepthDownsample.hlsl b/sample/src/DX12/Shaders/DepthDownsample.hlsl index 237ea4d..0ce9f54 100644 --- a/sample/src/DX12/Shaders/DepthDownsample.hlsl +++ b/sample/src/DX12/Shaders/DepthDownsample.hlsl @@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ********************************************************************/ -#ifndef SSR_DEPTH_DOWNSAMPLE -#define SSR_DEPTH_DOWNSAMPLE +#ifndef FFX_SSSR_DEPTH_DOWNSAMPLE +#define FFX_SSSR_DEPTH_DOWNSAMPLE Texture2D g_depth_buffer : register(t0); RWTexture2D g_downsampled_depth_buffer[13] : register(u0); // 12 is the maximum amount of supported mips by the downsampling lib (4096x4096). We copy the depth buffer over for simplicity. @@ -37,17 +37,17 @@ groupshared uint g_group_shared_counter; #define DS_FALLBACK // Define fetch and store functions -AF4 DSLoadSourceImage(ASU2 index) { return g_depth_buffer[index].xxxx; } -AF4 DSLoad(ASU2 index) { return g_downsampled_depth_buffer[6][index].xxxx; } // 5 -> 6 as we store a copy of the depth buffer at index 0 -void DSStore(ASU2 pix, AF4 outValue, AU1 index) { g_downsampled_depth_buffer[index + 1][pix] = outValue.x; } // + 1 as we store a copy of the depth buffer at index 0 -void DSIncreaseAtomicCounter() { InterlockedAdd(g_global_atomic[0], 1, g_group_shared_counter); } -AU1 DSGetAtomicCounter() { return g_group_shared_counter; } -AF4 DSLoadIntermediate(AU1 x, AU1 y) { +AF4 SpdLoadSourceImage(ASU2 index) { return g_depth_buffer[index].xxxx; } +AF4 SpdLoad(ASU2 index) { return g_downsampled_depth_buffer[6][index].xxxx; } // 5 -> 6 as we store a copy of the depth buffer at index 0 +void SpdStore(ASU2 pix, AF4 outValue, AU1 index) { g_downsampled_depth_buffer[index + 1][pix] = outValue.x; } // + 1 as we store a copy of the depth buffer at index 0 +void SpdIncreaseAtomicCounter() { InterlockedAdd(g_global_atomic[0], 1, g_group_shared_counter); } +AU1 SpdGetAtomicCounter() { return g_group_shared_counter; } +AF4 SpdLoadIntermediate(AU1 x, AU1 y) { float f = g_group_shared_depth_values[x][y]; return f.xxxx; } -void DSStoreIntermediate(AU1 x, AU1 y, AF4 value) { g_group_shared_depth_values[x][y] = value.x; } -AF4 DSReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3) { return min(min(v0, v1), min(v2,v3)); } +void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value) { g_group_shared_depth_values[x][y] = value.x; } +AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3) { return min(min(v0, v1), min(v2,v3)); } #include "ffx_spd.h" @@ -89,11 +89,11 @@ void main(uint3 did : SV_DispatchThreadID, uint3 gid : SV_GroupID, uint gi : SV_ float mips_count = GetMipsCount(image_size); uint threadgroup_count = GetThreadgroupCount(image_size); - Downsample( + SpdDownsample( AU2(gid.xy), AU1(gi), AU1(mips_count), AU1(threadgroup_count)); } -#endif // SSR_DEPTH_DOWNSAMPLE \ No newline at end of file +#endif // FFX_SSSR_DEPTH_DOWNSAMPLE \ No newline at end of file diff --git a/sample/src/DX12/Shaders/ffx_spd.h b/sample/src/DX12/Shaders/ffx_spd.h index ec40a44..68c9ef4 100644 --- a/sample/src/DX12/Shaders/ffx_spd.h +++ b/sample/src/DX12/Shaders/ffx_spd.h @@ -1,7 +1,7 @@ //_____________________________________________________________/\_______________________________________________________________ //============================================================================================================================== // -// [DS] Downsampler 0.1 +// [FFX SPD] Single Pass Downsampler 1.0 // //============================================================================================================================== // LICENSE @@ -36,13 +36,16 @@ // INTEGRATION SUMMARY FOR GPU // =========================== -// [SAMPLER] - if you want to use a sampler for loading the source image +// [SAMPLER] - if you want to use a sampler with linear filtering for loading the source image // follow additionally the instructions marked with [SAMPLER] -// this is recommended, as it's the more optimal path +// add following define: +// #SPD_LINEAR_SAMPLER +// this is recommended, as using one sample() with linear filter to reduce 2x2 is faster +// than 4x load() plus manual averaging // // Setup layout. Example below for VK_FORMAT_R16G16B16A16_SFLOAT. // // Note: If you use UNORM/SRGB format, you need to convert to linear space -// // as this is not done automatically via this downsampler approach +// // when using UAV load() and store() // // conversion to linear (load function): x*x // // conversion from linear (store function): sqrt() @@ -57,16 +60,16 @@ // // global atomic counter - MUST be initialized to 0 // // GLSL: -// layout(std430, set=0, binding=2) buffer perThreadgroup +// layout(std430, set=0, binding=2) buffer globalAtomicBuffer // { // uint counter; // } globalAtomic; // // HLSL: -// struct perThreadgroup +// struct globalAtomicBuffer // { // uint counter; // }; -// [[vk::binding(2)]] RWStructuredBuffer globalAtomic; +// [[vk::binding(2)]] RWStructuredBuffer globalAtomic; // // [SAMPLER] add sampler // GLSL: layout(set=0, binding=3) uniform sampler srcSampler; @@ -77,14 +80,14 @@ // // [SAMPLER] when using sampler add inverse source image size // // GLSL: // layout(push_constant) uniform pushConstants { -// uint mips; // needed to opt out earlier if mips are < 12 -// uint numWorkGroups; // number of total thread groups, so numWorkGroupsX * numWorkGroupsY * numWorkGroupsZ -// } myPerMip; +// uint mips; // needed to opt out earlier if mips are < 12 +// uint numWorkGroups; // number of total thread groups, so numWorkGroupsX * numWorkGroupsY * numWorkGroupsZ +// } spdConstants; // // HLSL: // [[vk::push_constant]] -// cbuffer myPerMip { -// uint mips; -// uint numWorkGroups; +// cbuffer spdConstants { +// uint mips; +// uint numWorkGroups; // }; // ... @@ -122,7 +125,9 @@ // // Define the fetch function(s) and the reduction function // // if non-power-of-2 textures, add border controls to the load and store functions -// // to make sure the borders of the mip level look as you it +// // to make sure the borders of the mip level look as you want it +// // if you don't add border controls you'll read zeros past the border +// // if you load with a sampler, this is obv. handled by your sampler :) // // this is also the place where you need to do color space transformation if needed // // E.g. if your texture format is SRGB/UNORM and you use the UAV load and store functions // // no automatic to/from linear conversions are happening @@ -131,111 +136,97 @@ // // conversion from linear (store function): sqrt() // // Load from source image -// GLSL: AF4 DSLoadSourceImage(ASU2 p){return imageLoad(imgSrc, p);} -// HLSL: AF4 DSLoadSourceImage(ASU2 tex){return imgSrc[tex];} -// [SAMPLER] you can also use a sampler, but then you need to modify also -// AF4 ReduceLoadSourceImage4(AU2 base) { ... } to -// AF4 ReduceLoadSourceImage4(AU2 base) -// { -// return DSLoadSourceImage(ASU2(base)); -// } +// GLSL: AF4 SpdLoadSourceImage(ASU2 p){return imageLoad(imgSrc, p);} +// HLSL: AF4 SpdLoadSourceImage(ASU2 tex){return imgSrc[tex];} +// [SAMPLER] don't forget to add the define #SPD_LINEAR_SAMPLER :) // GLSL: -// AF4 DSLoadSourceImage(ASU2 p){ -// AF2 textureCoord = p * invInputSize + invInputSize; -// return texture(sampler2D(imgSrc, srcSampler), textureCoord); -// } +// AF4 SpdLoadSourceImage(ASU2 p){ +// AF2 textureCoord = p * invInputSize + invInputSize; +// return texture(sampler2D(imgSrc, srcSampler), textureCoord); +// } // HLSL: -// AF4 DSLoadSourceImage(ASU2 p){ -// AF2 textureCoord = p * invInputSize + invInputSize; -// return imgSrc.SampleLevel(srcSampler, textureCoord, 0); -// } - -// [SAMPLER] make sure the sampler matches your defined reduction function :) -// [SAMPLER] if you can use a sampler, use one - it's the more optimal path +// AF4 SpdLoadSourceImage(ASU2 p){ +// AF2 textureCoord = p * invInputSize + invInputSize; +// return imgSrc.SampleLevel(srcSampler, textureCoord, 0); +// } -// // DSLoad() takes a 32-bit signed integer 2D coordinate and loads color. +// // SpdLoad() takes a 32-bit signed integer 2D coordinate and loads color. // // Loads the 5th mip level, each value is computed by a different thread group // // last thread group will access all its elements and compute the subsequent mips -// GLSL: AF4 DSLoad(ASU2 p){return imageLoad(imgDst[5],p);} -// HLSL: AF4 DSLoad(ASU2 tex){return imgDst[5][tex];} +// GLSL: AF4 SpdLoad(ASU2 p){return imageLoad(imgDst[5],p);} +// HLSL: AF4 SpdLoad(ASU2 tex){return imgDst[5][tex];} // Define the store function -// GLSL: void DSStore(ASU2 p, AF4 value, AU1 mip){imageStore(imgDst[mip], p, value);} -// HLSL: void DSStore(ASU2 pix, AF4 value, AU1 index){imgDst[index][pix] = value;} +// GLSL: void SpdStore(ASU2 p, AF4 value, AU1 mip){imageStore(imgDst[mip], p, value);} +// HLSL: void SpdStore(ASU2 pix, AF4 value, AU1 index){imgDst[index][pix] = value;} // // Define the atomic counter increase function // // GLSL: -// void DSIncreaseAtomicCounter(){spd_counter = atomicAdd(globalAtomic.counter, 1);} -// AU1 DSGetAtomicCounter() {return spd_counter;} +// void SpdIncreaseAtomicCounter(){spd_counter = atomicAdd(globalAtomic.counter, 1);} +// AU1 SpdGetAtomicCounter() {return spd_counter;} // // HLSL: -// void DSIncreaseAtomicCounter(){InterlockedAdd(globalAtomic[0].counter, 1, spd_counter);} -// AU1 DSGetAtomicCounter(){return spd_counter;} +// void SpdIncreaseAtomicCounter(){InterlockedAdd(globalAtomic[0].counter, 1, spd_counter);} +// AU1 SpdGetAtomicCounter(){return spd_counter;} -// // Define the lds load and store functions +// // Define the LDS load and store functions // // GLSL: -// AF4 DSLoadIntermediate(AU1 x, AU1 y){return spd_intermediate[x][y];} -// void DSStoreIntermediate(AU1 x, AU1 y, AF4 value){spd_intermediate[x][y] = value;} +// AF4 SpdLoadIntermediate(AU1 x, AU1 y){return spd_intermediate[x][y];} +// void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value){spd_intermediate[x][y] = value;} // // HLSL: -// AF4 DSLoadIntermediate(AU1 x, AU1 y){return spd_intermediate[x][y];} -// void DSStoreIntermediate(AU1 x, AU1 y, AF4 value){spd_intermediate[x][y] = value;} +// AF4 SpdLoadIntermediate(AU1 x, AU1 y){return spd_intermediate[x][y];} +// void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value){spd_intermediate[x][y] = value;} // // Define your reduction function: takes as input the four 2x2 values and returns 1 output value // Example below: computes the average value -// AF4 DSReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3){return (v0+v1+v2+v3)*0.25;} +// AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3){return (v0+v1+v2+v3)*0.25;} // // PACKED VERSION // Load from source image -// GLSL: AH4 DSLoadSourceImageH(ASU2 p){return AH4(imageLoad(imgSrc, p));} -// HLSL: AH4 DSLoadSourceImageH(ASU2 tex){return AH4(imgSrc[tex]);} -// [SAMPLER] you can also use a sampler, but then you need to modify also -// AH4 ReduceLoadSourceImage4H(AU2 base) { ... } to -// AH4 ReduceLoadSourceImage4H(AU2 base) -// { -// return DSLoadSourceImageH(ASU2(base)); -// } +// GLSL: AH4 SpdLoadSourceImageH(ASU2 p){return AH4(imageLoad(imgSrc, p));} +// HLSL: AH4 SpdLoadSourceImageH(ASU2 tex){return AH4(imgSrc[tex]);} +// [SAMPLER] // GLSL: -// AH4 DSLoadSourceImageH(ASU2 p){ -// AF2 textureCoord = p * invInputSize + invInputSize; -// return AH4(texture(sampler2D(imgSrc, srcSampler), textureCoord)); -// } +// AH4 SpdLoadSourceImageH(ASU2 p){ +// AF2 textureCoord = p * invInputSize + invInputSize; +// return AH4(texture(sampler2D(imgSrc, srcSampler), textureCoord)); +// } // HLSL: -// AH4 DSLoadSourceImageH(ASU2 p){ -// AF2 textureCoord = p * invInputSize + invInputSize; -// return AH4(imgSrc.SampleLevel(srcSampler, textureCoord, 0)); -// } - -// [SAMPLER] make sure the sampler matches your defined reduction function :) -// [SAMPLER] if you can use a sampler, use one - it's the more optimal path +// AH4 SpdLoadSourceImageH(ASU2 p){ +// AF2 textureCoord = p * invInputSize + invInputSize; +// return AH4(imgSrc.SampleLevel(srcSampler, textureCoord, 0)); +// } -// // DSLoadH() takes a 32-bit signed integer 2D coordinate and loads color. +// // SpdLoadH() takes a 32-bit signed integer 2D coordinate and loads color. // // Loads the 5th mip level, each value is computed by a different thread group // // last thread group will access all its elements and compute the subsequent mips -// GLSL: AH4 DSLoadH(ASU2 p){return AH4(imageLoad(imgDst[5],p));} -// HLSL: AH4 DSLoadH(ASU2 tex){return AH4(imgDst[5][tex]);} +// GLSL: AH4 SpdLoadH(ASU2 p){return AH4(imageLoad(imgDst[5],p));} +// HLSL: AH4 SpdLoadH(ASU2 tex){return AH4(imgDst[5][tex]);} // Define the store function -// GLSL: void DSStoreH(ASU2 p, AH4 value, AU1 mip){imageStore(imgDst[mip], p, AF4(value));} -// HLSL: void DSStoreH(ASU2 pix, AH4 value, AU1 index){imgDst[index][pix] = AF4(value);} +// GLSL: void SpdStoreH(ASU2 p, AH4 value, AU1 mip){imageStore(imgDst[mip], p, AF4(value));} +// HLSL: void SpdStoreH(ASU2 pix, AH4 value, AU1 index){imgDst[index][pix] = AF4(value);} // // Define the atomic counter increase function // // GLSL: -// void DSIncreaseAtomicCounter(){spd_counter = atomicAdd(globalAtomic.counter, 1);} -// AU1 DSGetAtomicCounter() {return spd_counter;} +// void SpdIncreaseAtomicCounter(){spd_counter = atomicAdd(globalAtomic.counter, 1);} +// AU1 SpdGetAtomicCounter() {return spd_counter;} // // HLSL: -// void DSIncreaseAtomicCounter(){InterlockedAdd(globalAtomic[0].counter, 1, spd_counter);} -// AU1 DSGetAtomicCounter(){return spd_counter;} +// void SpdIncreaseAtomicCounter(){InterlockedAdd(globalAtomic[0].counter, 1, spd_counter);} +// AU1 SpdGetAtomicCounter(){return spd_counter;} // // Define the lds load and store functions // // GLSL: -// AH4 DSLoadIntermediateH(AU1 x, AU1 y){return spd_intermediate[x][y];} -// void DSStoreIntermediateH(AU1 x, AU1 y, AH4 value){spd_intermediate[x][y] = value;} +// AH4 SpdLoadIntermediateH(AU1 x, AU1 y){return spd_intermediate[x][y];} +// void SpdStoreIntermediateH(AU1 x, AU1 y, AH4 value){spd_intermediate[x][y] = value;} // // HLSL: -// AH4 DSLoadIntermediate(AU1 x, AU1 y){return spd_intermediate[x][y];} -// void DSStoreIntermediate(AU1 x, AU1 y, AH4 value){spd_intermediate[x][y] = value;} +// AH4 SpdLoadIntermediate(AU1 x, AU1 y){return spd_intermediate[x][y];} +// void SpdStoreIntermediate(AU1 x, AU1 y, AH4 value){spd_intermediate[x][y] = value;} // // Define your reduction function: takes as input the four 2x2 values and returns 1 output value // Example below: computes the average value -// AH4 DSReduce4H(AH4 v0, AH4 v1, AH4 v2, AH4 v3){return (v0+v1+v2+v3)*AH1(0.25);} +// AH4 SpdReduce4H(AH4 v0, AH4 v1, AH4 v2, AH4 v3){return (v0+v1+v2+v3)*AH1(0.25);} + +// // // // If you only use PACKED version // #define SPD_PACKED_ONLY @@ -249,22 +240,22 @@ // layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in; // void main(){ // // Call the downsampling function -// Downsample(AU2(gl_WorkGroupID.xy), AU1(gl_LocalInvocationIndex), -// AU1(myPerMip.mips), AU1(myPerMip.numWorkGroups)); +// SpdDownsample(AU2(gl_WorkGroupID.xy), AU1(gl_LocalInvocationIndex), +// AU1(spdConstants.mips), AU1(spdConstants.numWorkGroups)); // // // PACKED: -// DownsampleH(AU2(gl_WorkGroupID.xy), AU1(gl_LocalInvocationIndex), -// AU1(myPerMip.mips), AU1(myPerMip.numWorkGroups)); +// SpdDownsampleH(AU2(gl_WorkGroupID.xy), AU1(gl_LocalInvocationIndex), +// AU1(spdConstants.mips), AU1(spdConstants.numWorkGroups)); // ... // // HLSL: // [numthreads(256,1,1)] // void main(uint3 WorkGroupId : SV_GroupID, uint LocalThreadIndex : SV_GroupIndex) { -// Downsample(AU2(WorkGroupId.xy), AU1(LocalThreadIndex), -// AU1(mips), AU1(numWorkGroups)); +// SpdDownsample(AU2(WorkGroupId.xy), AU1(LocalThreadIndex), +// AU1(mips), AU1(numWorkGroups)); // // // PACKED: -// DownsampleH(AU2(WorkGroupId.xy), AU1(LocalThreadIndex), -// AU1(mips), AU1(numWorkGroups)); +// SpdDownsampleH(AU2(WorkGroupId.xy), AU1(LocalThreadIndex), +// AU1(mips), AU1(numWorkGroups)); // ... // @@ -278,20 +269,20 @@ #ifdef SPD_PACKED_ONLY // Avoid compiler error - AF4 DSLoadSourceImage(ASU2 p){return AF4(0.0,0.0,0.0,0.0);} - AF4 DSLoad(ASU2 p){return AF4(0.0,0.0,0.0,0.0);} - void DSStore(ASU2 p, AF4 value, AU1 mip){} - AF4 DSLoadIntermediate(AU1 x, AU1 y){return AF4(0.0,0.0,0.0,0.0);} - void DSStoreIntermediate(AU1 x, AU1 y, AF4 value){} - AF4 DSReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3){return AF4(0.0,0.0,0.0,0.0);} +AF4 SpdLoadSourceImage(ASU2 p) { return AF4(0.0, 0.0, 0.0, 0.0); } +AF4 SpdLoad(ASU2 p) { return AF4(0.0, 0.0, 0.0, 0.0); } +void SpdStore(ASU2 p, AF4 value, AU1 mip) {} +AF4 SpdLoadIntermediate(AU1 x, AU1 y) { return AF4(0.0, 0.0, 0.0, 0.0); } +void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value) {} +AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3) { return AF4(0.0, 0.0, 0.0, 0.0); } #endif //_____________________________________________________________/\_______________________________________________________________ #if defined(A_GLSL) && !defined(SPD_NO_WAVE_OPERATIONS) -#extension GL_KHR_shader_subgroup_quad:require +#extension GL_KHR_shader_subgroup_quad : require #endif -void DSWorkgroupShuffleBarrier() { +void SpdWorkgroupShuffleBarrier() { #ifdef A_GLSL barrier(); #endif @@ -301,15 +292,15 @@ void DSWorkgroupShuffleBarrier() { } // Only last active workgroup should proceed -bool DSExitWorkgroup(AU1 numWorkGroups, AU1 localInvocationIndex) +bool SpdExitWorkgroup(AU1 numWorkGroups, AU1 localInvocationIndex) { // global atomic counter if (localInvocationIndex == 0) { - DSIncreaseAtomicCounter(); + SpdIncreaseAtomicCounter(); } - DSWorkgroupShuffleBarrier(); - return (DSGetAtomicCounter() != (numWorkGroups - 1)); + SpdWorkgroupShuffleBarrier(); + return (SpdGetAtomicCounter() != (numWorkGroups - 1)); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -317,22 +308,22 @@ bool DSExitWorkgroup(AU1 numWorkGroups, AU1 localInvocationIndex) // User defined: AF4 DSReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3); -AF4 ReduceQuad(AF4 v) +AF4 SpdReduceQuad(AF4 v) { - #if defined(A_GLSL) && !defined(SPD_NO_WAVE_OPERATIONS) +#if defined(A_GLSL) && !defined(SPD_NO_WAVE_OPERATIONS) AF4 v0 = v; AF4 v1 = subgroupQuadSwapHorizontal(v); AF4 v2 = subgroupQuadSwapVertical(v); AF4 v3 = subgroupQuadSwapDiagonal(v); - return DSReduce4(v0, v1, v2, v3); - #elif defined(A_HLSL) + return SpdReduce4(v0, v1, v2, v3); +#elif defined(A_HLSL) && !defined(SPD_NO_WAVE_OPERATIONS) // requires SM6.0 AU1 quad = WaveGetLaneIndex() & (~0x3); AF4 v0 = v; AF4 v1 = WaveReadLaneAt(v, quad | 1); AF4 v2 = WaveReadLaneAt(v, quad | 2); AF4 v3 = WaveReadLaneAt(v, quad | 3); - return DSReduce4(v0, v1, v2, v3); + return SpdReduce4(v0, v1, v2, v3); /* // if SM6.0 is not available, you can use the AMD shader intrinsics // works for DX11 @@ -352,191 +343,192 @@ AF4 ReduceQuad(AF4 v) v3.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4); v3.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4); v3.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4); - return DSReduce4(v0, v1, v2, v3); + return SpdReduce4(v0, v1, v2, v3); */ - #endif +#endif return AF4_x(0.0); } -AF4 ReduceIntermediate(AU2 i0, AU2 i1, AU2 i2, AU2 i3) +AF4 SpdReduceIntermediate(AU2 i0, AU2 i1, AU2 i2, AU2 i3) { - AF4 v0 = DSLoadIntermediate(i0.x, i0.y); - AF4 v1 = DSLoadIntermediate(i1.x, i1.y); - AF4 v2 = DSLoadIntermediate(i2.x, i2.y); - AF4 v3 = DSLoadIntermediate(i3.x, i3.y); - return DSReduce4(v0, v1, v2, v3); + AF4 v0 = SpdLoadIntermediate(i0.x, i0.y); + AF4 v1 = SpdLoadIntermediate(i1.x, i1.y); + AF4 v2 = SpdLoadIntermediate(i2.x, i2.y); + AF4 v3 = SpdLoadIntermediate(i3.x, i3.y); + return SpdReduce4(v0, v1, v2, v3); } -AF4 ReduceLoad4(AU2 i0, AU2 i1, AU2 i2, AU2 i3) +AF4 SpdReduceLoad4(AU2 i0, AU2 i1, AU2 i2, AU2 i3) { - AF4 v0 = DSLoad(ASU2(i0)); - AF4 v1 = DSLoad(ASU2(i1)); - AF4 v2 = DSLoad(ASU2(i2)); - AF4 v3 = DSLoad(ASU2(i3)); - return DSReduce4(v0, v1, v2, v3); + AF4 v0 = SpdLoad(ASU2(i0)); + AF4 v1 = SpdLoad(ASU2(i1)); + AF4 v2 = SpdLoad(ASU2(i2)); + AF4 v3 = SpdLoad(ASU2(i3)); + return SpdReduce4(v0, v1, v2, v3); } -AF4 ReduceLoad4(AU2 base) +AF4 SpdReduceLoad4(AU2 base) { - return ReduceLoad4( + return SpdReduceLoad4( AU2(base + AU2(0, 0)), - AU2(base + AU2(0, 1)), - AU2(base + AU2(1, 0)), + AU2(base + AU2(0, 1)), + AU2(base + AU2(1, 0)), AU2(base + AU2(1, 1))); } -AF4 ReduceLoadSourceImage4(AU2 i0, AU2 i1, AU2 i2, AU2 i3) +AF4 SpdReduceLoadSourceImage4(AU2 i0, AU2 i1, AU2 i2, AU2 i3) { - AF4 v0 = DSLoadSourceImage(ASU2(i0)); - AF4 v1 = DSLoadSourceImage(ASU2(i1)); - AF4 v2 = DSLoadSourceImage(ASU2(i2)); - AF4 v3 = DSLoadSourceImage(ASU2(i3)); - return DSReduce4(v0, v1, v2, v3); + AF4 v0 = SpdLoadSourceImage(ASU2(i0)); + AF4 v1 = SpdLoadSourceImage(ASU2(i1)); + AF4 v2 = SpdLoadSourceImage(ASU2(i2)); + AF4 v3 = SpdLoadSourceImage(ASU2(i3)); + return SpdReduce4(v0, v1, v2, v3); } -AF4 ReduceLoadSourceImage4(AU2 base) +AF4 SpdReduceLoadSourceImage4(AU2 base) { - // [SAMPLER] use: - return DSLoadSourceImage(ASU2(base)); - // if no sampler use: - /*return ReduceLoadSourceImage4( +#ifdef SPD_LINEAR_SAMPLER + return SpdLoadSourceImage(ASU2(base)); +#else + return SpdReduceLoadSourceImage4( AU2(base + AU2(0, 0)), - AU2(base + AU2(0, 1)), - AU2(base + AU2(1, 0)), - AU2(base + AU2(1, 1)));*/ + AU2(base + AU2(0, 1)), + AU2(base + AU2(1, 0)), + AU2(base + AU2(1, 1))); +#endif } -void DownsampleMips_0_1_Intrinsics(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMips_0_1_Intrinsics(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { AF4 v[4]; ASU2 tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2); ASU2 pix = ASU2(workGroupID.xy * 32) + ASU2(x, y); - v[0] = ReduceLoadSourceImage4(tex); - DSStore(pix, v[0], 0); + v[0] = SpdReduceLoadSourceImage4(tex); + SpdStore(pix, v[0], 0); tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2); pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y); - v[1] = ReduceLoadSourceImage4(tex); - DSStore(pix, v[1], 0); - + v[1] = SpdReduceLoadSourceImage4(tex); + SpdStore(pix, v[1], 0); + tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2 + 32); pix = ASU2(workGroupID.xy * 32) + ASU2(x, y + 16); - v[2] = ReduceLoadSourceImage4(tex); - DSStore(pix, v[2], 0); - + v[2] = SpdReduceLoadSourceImage4(tex); + SpdStore(pix, v[2], 0); + tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2 + 32); pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y + 16); - v[3] = ReduceLoadSourceImage4(tex); - DSStore(pix, v[3], 0); + v[3] = SpdReduceLoadSourceImage4(tex); + SpdStore(pix, v[3], 0); if (mip <= 1) return; - v[0] = ReduceQuad(v[0]); - v[1] = ReduceQuad(v[1]); - v[2] = ReduceQuad(v[2]); - v[3] = ReduceQuad(v[3]); + v[0] = SpdReduceQuad(v[0]); + v[1] = SpdReduceQuad(v[1]); + v[2] = SpdReduceQuad(v[2]); + v[3] = SpdReduceQuad(v[3]); if ((localInvocationIndex % 4) == 0) { - DSStore(ASU2(workGroupID.xy * 16) + - ASU2(x/2, y/2), v[0], 1); - DSStoreIntermediate( - x/2, y/2, v[0]); - - DSStore(ASU2(workGroupID.xy * 16) + - ASU2(x/2 + 8, y/2), v[1], 1); - DSStoreIntermediate( - x/2 + 8, y/2, v[1]); - - DSStore(ASU2(workGroupID.xy * 16) + - ASU2(x/2, y/2 + 8), v[2], 1); - DSStoreIntermediate( - x/2, y/2 + 8, v[2]); - - DSStore(ASU2(workGroupID.xy * 16) + - ASU2(x/2 + 8, y/2 + 8), v[3], 1); - DSStoreIntermediate( - x/2 + 8, y/2 + 8, v[3]); + SpdStore(ASU2(workGroupID.xy * 16) + + ASU2(x / 2, y / 2), v[0], 1); + SpdStoreIntermediate( + x / 2, y / 2, v[0]); + + SpdStore(ASU2(workGroupID.xy * 16) + + ASU2(x / 2 + 8, y / 2), v[1], 1); + SpdStoreIntermediate( + x / 2 + 8, y / 2, v[1]); + + SpdStore(ASU2(workGroupID.xy * 16) + + ASU2(x / 2, y / 2 + 8), v[2], 1); + SpdStoreIntermediate( + x / 2, y / 2 + 8, v[2]); + + SpdStore(ASU2(workGroupID.xy * 16) + + ASU2(x / 2 + 8, y / 2 + 8), v[3], 1); + SpdStoreIntermediate( + x / 2 + 8, y / 2 + 8, v[3]); } } -void DownsampleMips_0_1_LDS(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMips_0_1_LDS(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { AF4 v[4]; ASU2 tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2); ASU2 pix = ASU2(workGroupID.xy * 32) + ASU2(x, y); - v[0] = ReduceLoadSourceImage4(tex); - DSStore(pix, v[0], 0); + v[0] = SpdReduceLoadSourceImage4(tex); + SpdStore(pix, v[0], 0); tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2); pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y); - v[1] = ReduceLoadSourceImage4(tex); - DSStore(pix, v[1], 0); - + v[1] = SpdReduceLoadSourceImage4(tex); + SpdStore(pix, v[1], 0); + tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2 + 32); pix = ASU2(workGroupID.xy * 32) + ASU2(x, y + 16); - v[2] = ReduceLoadSourceImage4(tex); - DSStore(pix, v[2], 0); - + v[2] = SpdReduceLoadSourceImage4(tex); + SpdStore(pix, v[2], 0); + tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2 + 32); pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y + 16); - v[3] = ReduceLoadSourceImage4(tex); - DSStore(pix, v[3], 0); + v[3] = SpdReduceLoadSourceImage4(tex); + SpdStore(pix, v[3], 0); if (mip <= 1) return; for (int i = 0; i < 4; i++) { - DSStoreIntermediate(x, y, v[i]); - DSWorkgroupShuffleBarrier(); + SpdStoreIntermediate(x, y, v[i]); + SpdWorkgroupShuffleBarrier(); if (localInvocationIndex < 64) { - v[i] = ReduceIntermediate( + v[i] = SpdReduceIntermediate( AU2(x * 2 + 0, y * 2 + 0), AU2(x * 2 + 1, y * 2 + 0), AU2(x * 2 + 0, y * 2 + 1), AU2(x * 2 + 1, y * 2 + 1) ); - DSStore(ASU2(workGroupID.xy * 16) + ASU2(x + (i % 2) * 8, y + (i / 2) * 8), v[i], 1); + SpdStore(ASU2(workGroupID.xy * 16) + ASU2(x + (i % 2) * 8, y + (i / 2) * 8), v[i], 1); } - DSWorkgroupShuffleBarrier(); + SpdWorkgroupShuffleBarrier(); } if (localInvocationIndex < 64) { - DSStoreIntermediate(x + 0, y + 0, v[0]); - DSStoreIntermediate(x + 8, y + 0, v[1]); - DSStoreIntermediate(x + 0, y + 8, v[2]); - DSStoreIntermediate(x + 8, y + 8, v[3]); + SpdStoreIntermediate(x + 0, y + 0, v[0]); + SpdStoreIntermediate(x + 8, y + 0, v[1]); + SpdStoreIntermediate(x + 0, y + 8, v[2]); + SpdStoreIntermediate(x + 8, y + 8, v[3]); } } -void DownsampleMips_0_1(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMips_0_1(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS - DownsampleMips_0_1_LDS(x, y, workGroupID, localInvocationIndex, mip); + SpdDownsampleMips_0_1_LDS(x, y, workGroupID, localInvocationIndex, mip); #else - DownsampleMips_0_1_Intrinsics(x, y, workGroupID, localInvocationIndex, mip); + SpdDownsampleMips_0_1_Intrinsics(x, y, workGroupID, localInvocationIndex, mip); #endif } -void DownsampleMip_2(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMip_2(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS if (localInvocationIndex < 64) { - AF4 v = ReduceIntermediate( + AF4 v = SpdReduceIntermediate( AU2(x * 2 + 0 + 0, y * 2 + 0), AU2(x * 2 + 0 + 1, y * 2 + 0), AU2(x * 2 + 0 + 0, y * 2 + 1), AU2(x * 2 + 0 + 1, y * 2 + 1) ); - DSStore(ASU2(workGroupID.xy * 8) + ASU2(x, y), v, mip); + SpdStore(ASU2(workGroupID.xy * 8) + ASU2(x, y), v, mip); // store to LDS, try to reduce bank conflicts // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0 // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 @@ -545,21 +537,21 @@ void DownsampleMip_2(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0 // ... // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0 - DSStoreIntermediate(x * 2 + y % 2, y * 2, v); + SpdStoreIntermediate(x * 2 + y % 2, y * 2, v); } #else - AF4 v = DSLoadIntermediate(x, y); - v = ReduceQuad(v); + AF4 v = SpdLoadIntermediate(x, y); + v = SpdReduceQuad(v); // quad index 0 stores result if (localInvocationIndex % 4 == 0) - { - DSStore(ASU2(workGroupID.xy * 8) + ASU2(x/2, y/2), v, mip); - DSStoreIntermediate(x + (y/2) % 2, y, v); + { + SpdStore(ASU2(workGroupID.xy * 8) + ASU2(x / 2, y / 2), v, mip); + SpdStoreIntermediate(x + (y / 2) % 2, y, v); } #endif } -void DownsampleMip_3(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMip_3(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS if (localInvocationIndex < 16) @@ -568,13 +560,13 @@ void DownsampleMip_3(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU // 0 0 0 0 // 0 x 0 x // 0 0 0 0 - AF4 v = ReduceIntermediate( + AF4 v = SpdReduceIntermediate( AU2(x * 4 + 0 + 0, y * 4 + 0), AU2(x * 4 + 2 + 0, y * 4 + 0), AU2(x * 4 + 0 + 1, y * 4 + 2), AU2(x * 4 + 2 + 1, y * 4 + 2) ); - DSStore(ASU2(workGroupID.xy * 4) + ASU2(x, y), v, mip); + SpdStore(ASU2(workGroupID.xy * 4) + ASU2(x, y), v, mip); // store to LDS // x 0 0 0 x 0 0 0 x 0 0 0 x 0 0 0 // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 @@ -586,24 +578,24 @@ void DownsampleMip_3(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU // ... // 0 0 0 x 0 0 0 x 0 0 0 x 0 0 0 x // ... - DSStoreIntermediate(x * 4 + y, y * 4, v); + SpdStoreIntermediate(x * 4 + y, y * 4, v); } #else if (localInvocationIndex < 64) { - AF4 v = DSLoadIntermediate(x * 2 + y % 2,y * 2); - v = ReduceQuad(v); + AF4 v = SpdLoadIntermediate(x * 2 + y % 2, y * 2); + v = SpdReduceQuad(v); // quad index 0 stores result if (localInvocationIndex % 4 == 0) - { - DSStore(ASU2(workGroupID.xy * 4) + ASU2(x/2, y/2), v, mip); - DSStoreIntermediate(x * 2 + y/2, y * 2, v); + { + SpdStore(ASU2(workGroupID.xy * 4) + ASU2(x / 2, y / 2), v, mip); + SpdStoreIntermediate(x * 2 + y / 2, y * 2, v); } } #endif } -void DownsampleMip_4(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMip_4(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS if (localInvocationIndex < 4) @@ -611,112 +603,112 @@ void DownsampleMip_4(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU // x 0 0 0 x 0 0 0 // ... // 0 x 0 0 0 x 0 0 - AF4 v = ReduceIntermediate( + AF4 v = SpdReduceIntermediate( AU2(x * 8 + 0 + 0 + y * 2, y * 8 + 0), AU2(x * 8 + 4 + 0 + y * 2, y * 8 + 0), AU2(x * 8 + 0 + 1 + y * 2, y * 8 + 4), AU2(x * 8 + 4 + 1 + y * 2, y * 8 + 4) ); - DSStore(ASU2(workGroupID.xy * 2) + ASU2(x, y), v, mip); + SpdStore(ASU2(workGroupID.xy * 2) + ASU2(x, y), v, mip); // store to LDS // x x x x 0 ... // 0 ... - DSStoreIntermediate(x + y * 2, 0, v); + SpdStoreIntermediate(x + y * 2, 0, v); } #else if (localInvocationIndex < 16) { - AF4 v = DSLoadIntermediate(x * 4 + y,y * 4); - v = ReduceQuad(v); + AF4 v = SpdLoadIntermediate(x * 4 + y, y * 4); + v = SpdReduceQuad(v); // quad index 0 stores result if (localInvocationIndex % 4 == 0) - { - DSStore(ASU2(workGroupID.xy * 2) + ASU2(x/2, y/2), v, mip); - DSStoreIntermediate(x / 2 + y, 0, v); + { + SpdStore(ASU2(workGroupID.xy * 2) + ASU2(x / 2, y / 2), v, mip); + SpdStoreIntermediate(x / 2 + y, 0, v); } } #endif } -void DownsampleMip_5(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMip_5(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS if (localInvocationIndex < 1) { // x x x x 0 ... // 0 ... - AF4 v = ReduceIntermediate( + AF4 v = SpdReduceIntermediate( AU2(0, 0), AU2(1, 0), AU2(2, 0), AU2(3, 0) ); - DSStore(ASU2(workGroupID.xy), v, mip); + SpdStore(ASU2(workGroupID.xy), v, mip); } #else if (localInvocationIndex < 4) { - AF4 v = DSLoadIntermediate(localInvocationIndex,0); - v = ReduceQuad(v); + AF4 v = SpdLoadIntermediate(localInvocationIndex, 0); + v = SpdReduceQuad(v); // quad index 0 stores result if (localInvocationIndex % 4 == 0) - { - DSStore(ASU2(workGroupID.xy), v, mip); + { + SpdStore(ASU2(workGroupID.xy), v, mip); } } #endif } -void DownsampleMips_6_7(AU1 x, AU1 y, AU1 mips) +void SpdDownsampleMips_6_7(AU1 x, AU1 y, AU1 mips) { ASU2 tex = ASU2(x * 4 + 0, y * 4 + 0); ASU2 pix = ASU2(x * 2 + 0, y * 2 + 0); - AF4 v0 = ReduceLoad4(tex); - DSStore(pix, v0, 6); + AF4 v0 = SpdReduceLoad4(tex); + SpdStore(pix, v0, 6); tex = ASU2(x * 4 + 2, y * 4 + 0); pix = ASU2(x * 2 + 1, y * 2 + 0); - AF4 v1 = ReduceLoad4(tex); - DSStore(pix, v1, 6); + AF4 v1 = SpdReduceLoad4(tex); + SpdStore(pix, v1, 6); tex = ASU2(x * 4 + 0, y * 4 + 2); pix = ASU2(x * 2 + 0, y * 2 + 1); - AF4 v2 = ReduceLoad4(tex); - DSStore(pix, v2, 6); + AF4 v2 = SpdReduceLoad4(tex); + SpdStore(pix, v2, 6); tex = ASU2(x * 4 + 2, y * 4 + 2); pix = ASU2(x * 2 + 1, y * 2 + 1); - AF4 v3 = ReduceLoad4(tex); - DSStore(pix, v3, 6); + AF4 v3 = SpdReduceLoad4(tex); + SpdStore(pix, v3, 6); if (mips <= 7) return; // no barrier needed, working on values only from the same thread - AF4 v = DSReduce4(v0, v1, v2, v3); - DSStore(ASU2(x, y), v, 7); - DSStoreIntermediate(x, y, v); + AF4 v = SpdReduce4(v0, v1, v2, v3); + SpdStore(ASU2(x, y), v, 7); + SpdStoreIntermediate(x, y, v); } -void DownsampleNextFour(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 baseMip, AU1 mips) +void SpdDownsampleNextFour(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 baseMip, AU1 mips) { if (mips <= baseMip) return; - DSWorkgroupShuffleBarrier(); - DownsampleMip_2(x, y, workGroupID, localInvocationIndex, baseMip); + SpdWorkgroupShuffleBarrier(); + SpdDownsampleMip_2(x, y, workGroupID, localInvocationIndex, baseMip); if (mips <= baseMip + 1) return; - DSWorkgroupShuffleBarrier(); - DownsampleMip_3(x, y, workGroupID, localInvocationIndex, baseMip + 1); + SpdWorkgroupShuffleBarrier(); + SpdDownsampleMip_3(x, y, workGroupID, localInvocationIndex, baseMip + 1); if (mips <= baseMip + 2) return; - DSWorkgroupShuffleBarrier(); - DownsampleMip_4(x, y, workGroupID, localInvocationIndex, baseMip + 2); + SpdWorkgroupShuffleBarrier(); + SpdDownsampleMip_4(x, y, workGroupID, localInvocationIndex, baseMip + 2); if (mips <= baseMip + 3) return; - DSWorkgroupShuffleBarrier(); - DownsampleMip_5(x, y, workGroupID, localInvocationIndex, baseMip + 3); + SpdWorkgroupShuffleBarrier(); + SpdDownsampleMip_5(x, y, workGroupID, localInvocationIndex, baseMip + 3); } -void Downsample( +void SpdDownsample( AU2 workGroupID, AU1 localInvocationIndex, AU1 mips, @@ -725,18 +717,18 @@ void Downsample( AU2 sub_xy = ARmpRed8x8(localInvocationIndex % 64); AU1 x = sub_xy.x + 8 * ((localInvocationIndex >> 6) % 2); AU1 y = sub_xy.y + 8 * ((localInvocationIndex >> 7)); - DownsampleMips_0_1(x, y, workGroupID, localInvocationIndex, mips); + SpdDownsampleMips_0_1(x, y, workGroupID, localInvocationIndex, mips); - DownsampleNextFour(x, y, workGroupID, localInvocationIndex, 2, mips); + SpdDownsampleNextFour(x, y, workGroupID, localInvocationIndex, 2, mips); if (mips <= 6) return; - if (DSExitWorkgroup(numWorkGroups, localInvocationIndex)) return; + if (SpdExitWorkgroup(numWorkGroups, localInvocationIndex)) return; // After mip 6 there is only a single workgroup left that downsamples the remaining up to 64x64 texels. - DownsampleMips_6_7(x, y, mips); + SpdDownsampleMips_6_7(x, y, mips); - DownsampleNextFour(x, y, AU2(0,0), localInvocationIndex, 8, mips); + SpdDownsampleNextFour(x, y, AU2(0, 0), localInvocationIndex, 8, mips); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -749,25 +741,25 @@ void Downsample( #ifdef A_HALF // A_HALF #ifdef A_GLSL -#extension GL_EXT_shader_subgroup_extended_types_float16:require +#extension GL_EXT_shader_subgroup_extended_types_float16 : require #endif -AH4 ReduceQuadH(AH4 v) +AH4 SpdReduceQuadH(AH4 v) { - #if defined(A_GLSL) && !defined(SPD_NO_WAVE_OPERATIONS) +#if defined(A_GLSL) && !defined(SPD_NO_WAVE_OPERATIONS) AH4 v0 = v; AH4 v1 = subgroupQuadSwapHorizontal(v); AH4 v2 = subgroupQuadSwapVertical(v); AH4 v3 = subgroupQuadSwapDiagonal(v); - return DSReduce4H(v0, v1, v2, v3); - #elif defined(A_HLSL) + return SpdReduce4H(v0, v1, v2, v3); +#elif defined(A_HLSL) && !defined(SPD_NO_WAVE_OPERATIONS) // requires SM6.0 AU1 quad = WaveGetLaneIndex() & (~0x3); AH4 v0 = v; AH4 v1 = WaveReadLaneAt(v, quad | 1); AH4 v2 = WaveReadLaneAt(v, quad | 2); AH4 v3 = WaveReadLaneAt(v, quad | 3); - return DSReduce4H(v0, v1, v2, v3); + return SpdReduce4H(v0, v1, v2, v3); /* // if SM6.0 is not available, you can use the AMD shader intrinsics // works for DX11 @@ -787,185 +779,185 @@ AH4 ReduceQuadH(AH4 v) v3.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4); v3.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4); v3.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4); - return DSReduce4H(v0, v1, v2, v3); + return SpdReduce4H(v0, v1, v2, v3); */ - #endif +#endif return AH4(0.0, 0.0, 0.0, 0.0); } -AH4 ReduceIntermediateH(AU2 i0, AU2 i1, AU2 i2, AU2 i3) +AH4 SpdReduceIntermediateH(AU2 i0, AU2 i1, AU2 i2, AU2 i3) { - AH4 v0 = DSLoadIntermediateH(i0.x, i0.y); - AH4 v1 = DSLoadIntermediateH(i1.x, i1.y); - AH4 v2 = DSLoadIntermediateH(i2.x, i2.y); - AH4 v3 = DSLoadIntermediateH(i3.x, i3.y); - return DSReduce4H(v0, v1, v2, v3); + AH4 v0 = SpdLoadIntermediateH(i0.x, i0.y); + AH4 v1 = SpdLoadIntermediateH(i1.x, i1.y); + AH4 v2 = SpdLoadIntermediateH(i2.x, i2.y); + AH4 v3 = SpdLoadIntermediateH(i3.x, i3.y); + return SpdReduce4H(v0, v1, v2, v3); } -AH4 ReduceLoad4H(AU2 i0, AU2 i1, AU2 i2, AU2 i3) +AH4 SpdReduceLoad4H(AU2 i0, AU2 i1, AU2 i2, AU2 i3) { - AH4 v0 = DSLoadH(ASU2(i0)); - AH4 v1 = DSLoadH(ASU2(i1)); - AH4 v2 = DSLoadH(ASU2(i2)); - AH4 v3 = DSLoadH(ASU2(i3)); - return DSReduce4H(v0, v1, v2, v3); + AH4 v0 = SpdLoadH(ASU2(i0)); + AH4 v1 = SpdLoadH(ASU2(i1)); + AH4 v2 = SpdLoadH(ASU2(i2)); + AH4 v3 = SpdLoadH(ASU2(i3)); + return SpdReduce4H(v0, v1, v2, v3); } -AH4 ReduceLoad4H(AU2 base) +AH4 SpdReduceLoad4H(AU2 base) { - return ReduceLoad4H( + return SpdReduceLoad4H( AU2(base + AU2(0, 0)), - AU2(base + AU2(0, 1)), - AU2(base + AU2(1, 0)), + AU2(base + AU2(0, 1)), + AU2(base + AU2(1, 0)), AU2(base + AU2(1, 1))); } -AH4 ReduceLoadSourceImage4H(AU2 i0, AU2 i1, AU2 i2, AU2 i3) +AH4 SpdReduceLoadSourceImage4H(AU2 i0, AU2 i1, AU2 i2, AU2 i3) { - AH4 v0 = DSLoadSourceImageH(ASU2(i0)); - AH4 v1 = DSLoadSourceImageH(ASU2(i1)); - AH4 v2 = DSLoadSourceImageH(ASU2(i2)); - AH4 v3 = DSLoadSourceImageH(ASU2(i3)); - return DSReduce4H(v0, v1, v2, v3); + AH4 v0 = SpdLoadSourceImageH(ASU2(i0)); + AH4 v1 = SpdLoadSourceImageH(ASU2(i1)); + AH4 v2 = SpdLoadSourceImageH(ASU2(i2)); + AH4 v3 = SpdLoadSourceImageH(ASU2(i3)); + return SpdReduce4H(v0, v1, v2, v3); } -AH4 ReduceLoadSourceImage4H(AU2 base) +AH4 SpdReduceLoadSourceImage4H(AU2 base) { - // [SAMPLER] use: - return DSLoadSourceImageH(ASU2(base)); - // if no sampler use: - /*return ReduceLoadSourceImage4H( +#ifdef SPD_LINEAR_SAMPLER + return SpdLoadSourceImageH(ASU2(base)); +#else + return SpdReduceLoadSourceImage4H( AU2(base + AU2(0, 0)), - AU2(base + AU2(0, 1)), - AU2(base + AU2(1, 0)), - AU2(base + AU2(1, 1)));*/ - + AU2(base + AU2(0, 1)), + AU2(base + AU2(1, 0)), + AU2(base + AU2(1, 1))); +#endif } -void DownsampleMips_0_1_IntrinsicsH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips) +void SpdDownsampleMips_0_1_IntrinsicsH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips) { AH4 v[4]; ASU2 tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2); ASU2 pix = ASU2(workGroupID.xy * 32) + ASU2(x, y); - v[0] = ReduceLoadSourceImage4H(tex); - DSStoreH(pix, v[0], 0); + v[0] = SpdReduceLoadSourceImage4H(tex); + SpdStoreH(pix, v[0], 0); tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2); pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y); - v[1] = ReduceLoadSourceImage4H(tex); - DSStoreH(pix, v[1], 0); - + v[1] = SpdReduceLoadSourceImage4H(tex); + SpdStoreH(pix, v[1], 0); + tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2 + 32); pix = ASU2(workGroupID.xy * 32) + ASU2(x, y + 16); - v[2] = ReduceLoadSourceImage4H(tex); - DSStoreH(pix, v[2], 0); - + v[2] = SpdReduceLoadSourceImage4H(tex); + SpdStoreH(pix, v[2], 0); + tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2 + 32); pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y + 16); - v[3] = ReduceLoadSourceImage4H(tex); - DSStoreH(pix, v[3], 0); + v[3] = SpdReduceLoadSourceImage4H(tex); + SpdStoreH(pix, v[3], 0); if (mips <= 1) return; - v[0] = ReduceQuadH(v[0]); - v[1] = ReduceQuadH(v[1]); - v[2] = ReduceQuadH(v[2]); - v[3] = ReduceQuadH(v[3]); + v[0] = SpdReduceQuadH(v[0]); + v[1] = SpdReduceQuadH(v[1]); + v[2] = SpdReduceQuadH(v[2]); + v[3] = SpdReduceQuadH(v[3]); if ((localInvocationIndex % 4) == 0) { - DSStoreH(ASU2(workGroupID.xy * 16) + ASU2(x/2, y/2), v[0], 1); - DSStoreIntermediateH(x/2, y/2, v[0]); + SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x / 2, y / 2), v[0], 1); + SpdStoreIntermediateH(x / 2, y / 2, v[0]); - DSStoreH(ASU2(workGroupID.xy * 16) + ASU2(x/2 + 8, y/2), v[1], 1); - DSStoreIntermediateH(x/2 + 8, y/2, v[1]); + SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x / 2 + 8, y / 2), v[1], 1); + SpdStoreIntermediateH(x / 2 + 8, y / 2, v[1]); - DSStoreH(ASU2(workGroupID.xy * 16) + ASU2(x/2, y/2 + 8), v[2], 1); - DSStoreIntermediateH(x/2, y/2 + 8, v[2]); + SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x / 2, y / 2 + 8), v[2], 1); + SpdStoreIntermediateH(x / 2, y / 2 + 8, v[2]); - DSStoreH(ASU2(workGroupID.xy * 16) + ASU2(x/2 + 8, y/2 + 8), v[3], 1); - DSStoreIntermediateH(x/2 + 8, y/2 + 8, v[3]); + SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x / 2 + 8, y / 2 + 8), v[3], 1); + SpdStoreIntermediateH(x / 2 + 8, y / 2 + 8, v[3]); } } -void DownsampleMips_0_1_LDSH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips) +void SpdDownsampleMips_0_1_LDSH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips) { AH4 v[4]; ASU2 tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2); ASU2 pix = ASU2(workGroupID.xy * 32) + ASU2(x, y); - v[0] = ReduceLoadSourceImage4H(tex); - DSStoreH(pix, v[0], 0); + v[0] = SpdReduceLoadSourceImage4H(tex); + SpdStoreH(pix, v[0], 0); tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2); pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y); - v[1] = ReduceLoadSourceImage4H(tex); - DSStoreH(pix, v[1], 0); - + v[1] = SpdReduceLoadSourceImage4H(tex); + SpdStoreH(pix, v[1], 0); + tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2 + 32); pix = ASU2(workGroupID.xy * 32) + ASU2(x, y + 16); - v[2] = ReduceLoadSourceImage4H(tex); - DSStoreH(pix, v[2], 0); - + v[2] = SpdReduceLoadSourceImage4H(tex); + SpdStoreH(pix, v[2], 0); + tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2 + 32); pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y + 16); - v[3] = ReduceLoadSourceImage4H(tex); - DSStoreH(pix, v[3], 0); + v[3] = SpdReduceLoadSourceImage4H(tex); + SpdStoreH(pix, v[3], 0); if (mips <= 1) return; for (int i = 0; i < 4; i++) { - DSStoreIntermediateH(x, y, v[i]); - DSWorkgroupShuffleBarrier(); + SpdStoreIntermediateH(x, y, v[i]); + SpdWorkgroupShuffleBarrier(); if (localInvocationIndex < 64) { - v[i] = ReduceIntermediateH( + v[i] = SpdReduceIntermediateH( AU2(x * 2 + 0, y * 2 + 0), AU2(x * 2 + 1, y * 2 + 0), AU2(x * 2 + 0, y * 2 + 1), AU2(x * 2 + 1, y * 2 + 1) ); - DSStoreH(ASU2(workGroupID.xy * 16) + ASU2(x + (i % 2) * 8, y + (i / 2) * 8), v[i], 1); + SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x + (i % 2) * 8, y + (i / 2) * 8), v[i], 1); } - DSWorkgroupShuffleBarrier(); + SpdWorkgroupShuffleBarrier(); } if (localInvocationIndex < 64) { - DSStoreIntermediateH(x + 0, y + 0, v[0]); - DSStoreIntermediateH(x + 8, y + 0, v[1]); - DSStoreIntermediateH(x + 0, y + 8, v[2]); - DSStoreIntermediateH(x + 8, y + 8, v[3]); + SpdStoreIntermediateH(x + 0, y + 0, v[0]); + SpdStoreIntermediateH(x + 8, y + 0, v[1]); + SpdStoreIntermediateH(x + 0, y + 8, v[2]); + SpdStoreIntermediateH(x + 8, y + 8, v[3]); } } -void DownsampleMips_0_1H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips) +void SpdDownsampleMips_0_1H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips) { #ifdef SPD_NO_WAVE_OPERATIONS - DownsampleMips_0_1_LDSH(x, y, workGroupID, localInvocationIndex, mips); + SpdDownsampleMips_0_1_LDSH(x, y, workGroupID, localInvocationIndex, mips); #else - DownsampleMips_0_1_IntrinsicsH(x, y, workGroupID, localInvocationIndex, mips); + SpdDownsampleMips_0_1_IntrinsicsH(x, y, workGroupID, localInvocationIndex, mips); #endif } -void DownsampleMip_2H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMip_2H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS if (localInvocationIndex < 64) { - AH4 v = ReduceIntermediateH( + AH4 v = SpdReduceIntermediateH( AU2(x * 2 + 0 + 0, y * 2 + 0), AU2(x * 2 + 0 + 1, y * 2 + 0), AU2(x * 2 + 0 + 0, y * 2 + 1), AU2(x * 2 + 0 + 1, y * 2 + 1) ); - DSStoreH(ASU2(workGroupID.xy * 8) + ASU2(x, y), v, mip); + SpdStoreH(ASU2(workGroupID.xy * 8) + ASU2(x, y), v, mip); // store to LDS, try to reduce bank conflicts // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0 // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 @@ -974,21 +966,21 @@ void DownsampleMip_2H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, A // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0 // ... // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0 - DSStoreIntermediateH(x * 2 + y % 2, y * 2, v); + SpdStoreIntermediateH(x * 2 + y % 2, y * 2, v); } #else - AH4 v = DSLoadIntermediateH(x, y); - v = ReduceQuadH(v); + AH4 v = SpdLoadIntermediateH(x, y); + v = SpdReduceQuadH(v); // quad index 0 stores result if (localInvocationIndex % 4 == 0) - { - DSStoreH(ASU2(workGroupID.xy * 8) + ASU2(x/2, y/2), v, mip); - DSStoreIntermediateH(x + (y/2) % 2, y, v); + { + SpdStoreH(ASU2(workGroupID.xy * 8) + ASU2(x / 2, y / 2), v, mip); + SpdStoreIntermediateH(x + (y / 2) % 2, y, v); } #endif } -void DownsampleMip_3H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMip_3H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS if (localInvocationIndex < 16) @@ -997,13 +989,13 @@ void DownsampleMip_3H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, A // 0 0 0 0 // 0 x 0 x // 0 0 0 0 - AH4 v = ReduceIntermediateH( + AH4 v = SpdReduceIntermediateH( AU2(x * 4 + 0 + 0, y * 4 + 0), AU2(x * 4 + 2 + 0, y * 4 + 0), AU2(x * 4 + 0 + 1, y * 4 + 2), AU2(x * 4 + 2 + 1, y * 4 + 2) ); - DSStoreH(ASU2(workGroupID.xy * 4) + ASU2(x, y), v, mip); + SpdStoreH(ASU2(workGroupID.xy * 4) + ASU2(x, y), v, mip); // store to LDS // x 0 0 0 x 0 0 0 x 0 0 0 x 0 0 0 // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 @@ -1015,24 +1007,24 @@ void DownsampleMip_3H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, A // ... // 0 0 0 x 0 0 0 x 0 0 0 x 0 0 0 x // ... - DSStoreIntermediateH(x * 4 + y, y * 4, v); + SpdStoreIntermediateH(x * 4 + y, y * 4, v); } #else if (localInvocationIndex < 64) { - AH4 v = DSLoadIntermediateH(x * 2 + y % 2,y * 2); - v = ReduceQuadH(v); + AH4 v = SpdLoadIntermediateH(x * 2 + y % 2, y * 2); + v = SpdReduceQuadH(v); // quad index 0 stores result if (localInvocationIndex % 4 == 0) - { - DSStoreH(ASU2(workGroupID.xy * 4) + ASU2(x/2, y/2), v, mip); - DSStoreIntermediateH(x * 2 + y/2, y * 2, v); + { + SpdStoreH(ASU2(workGroupID.xy * 4) + ASU2(x / 2, y / 2), v, mip); + SpdStoreIntermediateH(x * 2 + y / 2, y * 2, v); } } #endif } -void DownsampleMip_4H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMip_4H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS if (localInvocationIndex < 4) @@ -1040,112 +1032,112 @@ void DownsampleMip_4H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, A // x 0 0 0 x 0 0 0 // ... // 0 x 0 0 0 x 0 0 - AH4 v = ReduceIntermediateH( + AH4 v = SpdReduceIntermediateH( AU2(x * 8 + 0 + 0 + y * 2, y * 8 + 0), AU2(x * 8 + 4 + 0 + y * 2, y * 8 + 0), AU2(x * 8 + 0 + 1 + y * 2, y * 8 + 4), AU2(x * 8 + 4 + 1 + y * 2, y * 8 + 4) ); - DSStoreH(ASU2(workGroupID.xy * 2) + ASU2(x, y), v, mip); + SpdStoreH(ASU2(workGroupID.xy * 2) + ASU2(x, y), v, mip); // store to LDS // x x x x 0 ... // 0 ... - DSStoreIntermediateH(x + y * 2, 0, v); + SpdStoreIntermediateH(x + y * 2, 0, v); } #else if (localInvocationIndex < 16) { - AH4 v = DSLoadIntermediateH(x * 4 + y,y * 4); - v = ReduceQuadH(v); + AH4 v = SpdLoadIntermediateH(x * 4 + y, y * 4); + v = SpdReduceQuadH(v); // quad index 0 stores result if (localInvocationIndex % 4 == 0) - { - DSStoreH(ASU2(workGroupID.xy * 2) + ASU2(x/2, y/2), v, mip); - DSStoreIntermediateH(x / 2 + y, 0, v); + { + SpdStoreH(ASU2(workGroupID.xy * 2) + ASU2(x / 2, y / 2), v, mip); + SpdStoreIntermediateH(x / 2 + y, 0, v); } } #endif } -void DownsampleMip_5H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) +void SpdDownsampleMip_5H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip) { #ifdef SPD_NO_WAVE_OPERATIONS if (localInvocationIndex < 1) { // x x x x 0 ... // 0 ... - AH4 v = ReduceIntermediateH( + AH4 v = SpdReduceIntermediateH( AU2(0, 0), AU2(1, 0), AU2(2, 0), AU2(3, 0) ); - DSStoreH(ASU2(workGroupID.xy), v, mip); + SpdStoreH(ASU2(workGroupID.xy), v, mip); } #else if (localInvocationIndex < 4) { - AH4 v = DSLoadIntermediateH(localInvocationIndex,0); - v = ReduceQuadH(v); + AH4 v = SpdLoadIntermediateH(localInvocationIndex, 0); + v = SpdReduceQuadH(v); // quad index 0 stores result if (localInvocationIndex % 4 == 0) - { - DSStoreH(ASU2(workGroupID.xy), v, mip); + { + SpdStoreH(ASU2(workGroupID.xy), v, mip); } } #endif } -void DownsampleMips_6_7H(AU1 x, AU1 y, AU1 mips) +void SpdDownsampleMips_6_7H(AU1 x, AU1 y, AU1 mips) { ASU2 tex = ASU2(x * 4 + 0, y * 4 + 0); ASU2 pix = ASU2(x * 2 + 0, y * 2 + 0); - AH4 v0 = ReduceLoad4H(tex); - DSStoreH(pix, v0, 6); + AH4 v0 = SpdReduceLoad4H(tex); + SpdStoreH(pix, v0, 6); tex = ASU2(x * 4 + 2, y * 4 + 0); pix = ASU2(x * 2 + 1, y * 2 + 0); - AH4 v1 = ReduceLoad4H(tex); - DSStoreH(pix, v1, 6); + AH4 v1 = SpdReduceLoad4H(tex); + SpdStoreH(pix, v1, 6); tex = ASU2(x * 4 + 0, y * 4 + 2); pix = ASU2(x * 2 + 0, y * 2 + 1); - AH4 v2 = ReduceLoad4H(tex); - DSStoreH(pix, v2, 6); + AH4 v2 = SpdReduceLoad4H(tex); + SpdStoreH(pix, v2, 6); tex = ASU2(x * 4 + 2, y * 4 + 2); pix = ASU2(x * 2 + 1, y * 2 + 1); - AH4 v3 = ReduceLoad4H(tex); - DSStoreH(pix, v3, 6); + AH4 v3 = SpdReduceLoad4H(tex); + SpdStoreH(pix, v3, 6); if (mips < 8) return; // no barrier needed, working on values only from the same thread - AH4 v = DSReduce4H(v0, v1, v2, v3); - DSStoreH(ASU2(x, y), v, 7); - DSStoreIntermediateH(x, y, v); + AH4 v = SpdReduce4H(v0, v1, v2, v3); + SpdStoreH(ASU2(x, y), v, 7); + SpdStoreIntermediateH(x, y, v); } -void DownsampleNextFourH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 baseMip, AU1 mips) +void SpdDownsampleNextFourH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 baseMip, AU1 mips) { if (mips <= baseMip) return; - DSWorkgroupShuffleBarrier(); - DownsampleMip_2H(x, y, workGroupID, localInvocationIndex, baseMip); + SpdWorkgroupShuffleBarrier(); + SpdDownsampleMip_2H(x, y, workGroupID, localInvocationIndex, baseMip); if (mips <= baseMip + 1) return; - DSWorkgroupShuffleBarrier(); - DownsampleMip_3H(x, y, workGroupID, localInvocationIndex, baseMip + 1); + SpdWorkgroupShuffleBarrier(); + SpdDownsampleMip_3H(x, y, workGroupID, localInvocationIndex, baseMip + 1); if (mips <= baseMip + 2) return; - DSWorkgroupShuffleBarrier(); - DownsampleMip_4H(x, y, workGroupID, localInvocationIndex, baseMip + 2); + SpdWorkgroupShuffleBarrier(); + SpdDownsampleMip_4H(x, y, workGroupID, localInvocationIndex, baseMip + 2); if (mips <= baseMip + 3) return; - DSWorkgroupShuffleBarrier(); - DownsampleMip_5H(x, y, workGroupID, localInvocationIndex, baseMip + 3); + SpdWorkgroupShuffleBarrier(); + SpdDownsampleMip_5H(x, y, workGroupID, localInvocationIndex, baseMip + 3); } -void DownsampleH( +void SpdDownsampleH( AU2 workGroupID, AU1 localInvocationIndex, AU1 mips, @@ -1155,18 +1147,18 @@ void DownsampleH( AU1 x = sub_xy.x + 8 * ((localInvocationIndex >> 6) % 2); AU1 y = sub_xy.y + 8 * ((localInvocationIndex >> 7)); - DownsampleMips_0_1H(x, y, workGroupID, localInvocationIndex, mips); + SpdDownsampleMips_0_1H(x, y, workGroupID, localInvocationIndex, mips); - DownsampleNextFourH(x, y, workGroupID, localInvocationIndex, 2, mips); + SpdDownsampleNextFourH(x, y, workGroupID, localInvocationIndex, 2, mips); if (mips < 7) return; - if (DSExitWorkgroup(numWorkGroups, localInvocationIndex)) return; + if (SpdExitWorkgroup(numWorkGroups, localInvocationIndex)) return; // After mip 6 there is only a single workgroup left that downsamples the remaining up to 64x64 texels. - DownsampleMips_6_7H(x, y, mips); + SpdDownsampleMips_6_7H(x, y, mips); - DownsampleNextFourH(x, y, AU2(0,0), localInvocationIndex, 8, mips); + SpdDownsampleNextFourH(x, y, AU2(0, 0), localInvocationIndex, 8, mips); } #endif \ No newline at end of file diff --git a/sample/src/DX12/Sources/SampleRenderer.cpp b/sample/src/DX12/Sources/SampleRenderer.cpp index 87eda62..9c14027 100644 --- a/sample/src/DX12/Sources/SampleRenderer.cpp +++ b/sample/src/DX12/Sources/SampleRenderer.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. #undef max #undef min -void SSRLoggingFunction(const char* pMessage, void* pUserData) +void FfxSssrLoggingFunction(const char* pMessage, void* pUserData) { Trace(pMessage); } @@ -41,7 +41,6 @@ void SSRLoggingFunction(const char* pMessage, void* pUserData) void SampleRenderer::OnCreate(Device* pDevice, SwapChain *pSwapChain) { m_pDevice = pDevice; - m_CurrentFrame = 0; // Initialize helpers @@ -134,36 +133,36 @@ void SampleRenderer::OnCreate(Device* pDevice, SwapChain *pSwapChain) ID3D12GraphicsCommandList * cl; ThrowIfFailed(m_pDevice->GetDevice()->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, ca, nullptr, IID_PPV_ARGS(&cl))); - SssrCreateContextInfoD3D12 d3d12ContextInfo = {}; + FfxSssrD3D12CreateContextInfo d3d12ContextInfo = {}; d3d12ContextInfo.pDevice = m_pDevice->GetDevice(); d3d12ContextInfo.pUploadCommandList = cl; - SssrLoggingCallbacks loggingCallbacks = {}; + FfxSssrLoggingCallbacks loggingCallbacks = {}; loggingCallbacks.pUserData = this; - loggingCallbacks.pfnLogging = SSRLoggingFunction; + loggingCallbacks.pfnLogging = FfxSssrLoggingFunction; - SssrCreateContextInfo contextInfo = {}; - contextInfo.apiVersion = SSSR_API_VERSION; - contextInfo.frameCountBeforeMemoryReuse = 2; + FfxSssrCreateContextInfo contextInfo = {}; + contextInfo.apiVersion = FFX_SSSR_API_VERSION; + contextInfo.frameCountBeforeMemoryReuse = backBufferCount; contextInfo.maxReflectionViewCount = 1; - contextInfo.pCreateContextInfoD3D12 = &d3d12ContextInfo; + contextInfo.pD3D12CreateContextInfo = &d3d12ContextInfo; contextInfo.pLoggingCallbacks = &loggingCallbacks; contextInfo.uploadBufferSize = 8 * 1024 * 1024; contextInfo.pRoughnessTextureFormat = L"float4"; - contextInfo.pUnpackRoughnessSnippet = L"float SssrUnpackRoughness(SSR_ROUGHNESS_TEXTURE_FORMAT packed) { return packed.w; }"; + contextInfo.pUnpackRoughnessSnippet = L"float FfxSssrUnpackRoughness(FFX_SSSR_ROUGHNESS_TEXTURE_FORMAT packed) { return packed.w; }"; contextInfo.pNormalsTextureFormat = L"float4"; - contextInfo.pUnpackNormalsSnippet = L"float3 SssrUnpackNormals(SSR_NORMALS_TEXTURE_FORMAT packed) { return 2 * packed.xyz - 1; }"; + contextInfo.pUnpackNormalsSnippet = L"float3 FfxSssrUnpackNormals(FFX_SSSR_NORMALS_TEXTURE_FORMAT packed) { return 2 * packed.xyz - 1; }"; contextInfo.pSceneTextureFormat = L"float4"; - contextInfo.pUnpackSceneRadianceSnippet = L"float3 SssrUnpackSceneRadiance(SSR_SCENE_TEXTURE_FORMAT packed) { return packed.xyz; }"; + contextInfo.pUnpackSceneRadianceSnippet = L"float3 FfxSssrUnpackSceneRadiance(FFX_SSSR_SCENE_TEXTURE_FORMAT packed) { return packed.xyz; }"; contextInfo.pDepthTextureFormat = L"float"; - contextInfo.pUnpackDepthSnippet = L"float SssrUnpackDepth(SSR_DEPTH_TEXTURE_FORMAT packed) { return packed.x; }"; + contextInfo.pUnpackDepthSnippet = L"float FfxSssrUnpackDepth(FFX_SSSR_DEPTH_TEXTURE_FORMAT packed) { return packed.x; }"; contextInfo.pMotionVectorFormat = L"float2"; - contextInfo.pUnpackMotionVectorsSnippet = L"float2 SssrUnpackMotionVectors(SSR_MOTION_VECTOR_TEXTURE_FORMAT packed) { return packed.xy * float2(0.5, -0.5); }"; + contextInfo.pUnpackMotionVectorsSnippet = L"float2 FfxSssrUnpackMotionVectors(FFX_SSSR_MOTION_VECTOR_TEXTURE_FORMAT packed) { return packed.xy * float2(0.5, -0.5); }"; - SssrStatus status = sssrCreateContext(&contextInfo, &m_SssrContext); - if (status != SSSR_STATUS_OK) + FfxSssrStatus status = ffxSssrCreateContext(&contextInfo, &m_SssrContext); + if (status != FFX_SSSR_STATUS_OK) { - Trace("sssrCreateContext failed."); + Trace("ffxSssrCreateContext failed."); } // Wait for the upload to finish; @@ -214,7 +213,7 @@ void SampleRenderer::OnDestroy() m_ShadowMap.OnDestroy(); m_BrdfLut.OnDestroy(); - sssrDestroyContext(m_SssrContext); + ffxSssrDestroyContext(m_SssrContext); if (m_ApplyPipelineState != nullptr) m_ApplyPipelineState->Release(); @@ -315,7 +314,7 @@ void SampleRenderer::OnCreateWindowSizeDependentResources(SwapChain *pSwapChain, m_AtomicCounter.CreateBufferUAV(0, NULL, &m_AtomicCounterUAVGPU); } - // Setup SSR + // Setup resource views // m_HDR.CreateSRV(0, &m_SssrSceneSRV); m_DepthHierarchy.CreateSRV(0, &m_SssrDepthBufferHierarchySRV); @@ -329,7 +328,7 @@ void SampleRenderer::OnCreateWindowSizeDependentResources(SwapChain *pSwapChain, m_SkyDome.SetDescriptorSpec(0, &m_SssrEnvironmentMapSRV, 0, &m_SssrEnvironmentMapSamplerDesc); - SssrCreateReflectionViewInfoD3D12 d3d12ReflectionViewInfo = {}; + FfxSssrD3D12CreateReflectionViewInfo d3d12ReflectionViewInfo = {}; d3d12ReflectionViewInfo.depthBufferHierarchySRV = m_SssrDepthBufferHierarchySRV.GetCPU(); d3d12ReflectionViewInfo.motionBufferSRV = m_SssrMotionBufferSRV.GetCPU(); d3d12ReflectionViewInfo.normalBufferSRV = m_SssrNormalBufferSRV.GetCPU(); @@ -345,18 +344,18 @@ void SampleRenderer::OnCreateWindowSizeDependentResources(SwapChain *pSwapChain, bool pingPongNormalBuffers = false; bool pingPongRoughnessBuffers = false; - SssrCreateReflectionViewInfo reflectionViewInfo = {}; - reflectionViewInfo.flags = SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS; - reflectionViewInfo.flags |= pingPongNormalBuffers ? SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_NORMAL_BUFFERS : 0; - reflectionViewInfo.flags |= pingPongRoughnessBuffers ? SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_ROUGHNESS_BUFFERS : 0; + FfxSssrCreateReflectionViewInfo reflectionViewInfo = {}; + reflectionViewInfo.flags = FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_ENABLE_PERFORMANCE_COUNTERS; + reflectionViewInfo.flags |= pingPongNormalBuffers ? FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_NORMAL_BUFFERS : 0; + reflectionViewInfo.flags |= pingPongRoughnessBuffers ? FFX_SSSR_CREATE_REFLECTION_VIEW_FLAG_PING_PONG_ROUGHNESS_BUFFERS : 0; reflectionViewInfo.outputWidth = m_Width; reflectionViewInfo.outputHeight = m_Height; - reflectionViewInfo.pCreateReflectionViewInfoD3D12 = &d3d12ReflectionViewInfo; + reflectionViewInfo.pD3D12CreateReflectionViewInfo = &d3d12ReflectionViewInfo; - SssrStatus status = sssrCreateReflectionView(m_SssrContext, &reflectionViewInfo, &m_SssrReflectionView); - if (status != SSSR_STATUS_OK) + FfxSssrStatus status = ffxSssrCreateReflectionView(m_SssrContext, &reflectionViewInfo, &m_SssrReflectionView); + if (status != FFX_SSSR_STATUS_OK) { - Trace("sssrCreateReflectionView failed."); + Trace("ffxSssrCreateReflectionView failed."); } m_SssrCreatedReflectionView = true; @@ -386,7 +385,7 @@ void SampleRenderer::OnDestroyWindowSizeDependentResources() if (m_SssrCreatedReflectionView) { - sssrDestroyReflectionView(m_SssrContext, m_SssrReflectionView); + ffxSssrDestroyReflectionView(m_SssrContext, m_SssrReflectionView); } m_HDR.OnDestroy(); @@ -586,11 +585,10 @@ void SampleRenderer::StallFrame(float targetFrametime) void SampleRenderer::BeginFrame() { - m_CurrentFrame = 1 - m_CurrentFrame; - SssrStatus status = sssrAdvanceToNextFrame(m_SssrContext); - if (status != SSSR_STATUS_OK) + FfxSssrStatus status = ffxSssrAdvanceToNextFrame(m_SssrContext); + if (status != FFX_SSSR_STATUS_OK) { - Trace("sssrAdvanceToNextFrame failed."); + Trace("ffxSssrAdvanceToNextFrame failed."); } // Timing values @@ -667,6 +665,8 @@ per_frame * SampleRenderer::FillFrameConstants(State *pState) void SampleRenderer::RenderSpotLights(ID3D12GraphicsCommandList* pCmdLst1, per_frame * pPerFrame) { + UserMarker marker(pCmdLst1, "Shadow Map"); + for (uint32_t i = 0; i < pPerFrame->lightCount; i++) { if (!(pPerFrame->lights[i].type == LightType_Spot || pPerFrame->lights[i].type == LightType_Directional)) @@ -685,12 +685,14 @@ void SampleRenderer::RenderSpotLights(ID3D12GraphicsCommandList* pCmdLst1, per_f m_gltfDepth->Draw(pCmdLst1); - m_GPUTimer.GetTimeStamp(pCmdLst1, "Shadow map"); + m_GPUTimer.GetTimeStamp(pCmdLst1, "Shadow Map"); } } void SampleRenderer::RenderMotionVectors(ID3D12GraphicsCommandList* pCmdLst1, per_frame * pPerFrame, State * pState) { + UserMarker marker(pCmdLst1, "Motion Vectors"); + // Compute motion vectors pCmdLst1->RSSetViewports(1, &m_Viewport); pCmdLst1->RSSetScissorRects(1, &m_Scissor); @@ -709,11 +711,13 @@ void SampleRenderer::RenderMotionVectors(ID3D12GraphicsCommandList* pCmdLst1, pe cbDepthPerFrame->mPrevViewProj = pState->camera.GetPrevView() * pState->camera.GetProjection(); m_gltfMotionVectors->Draw(pCmdLst1); - m_GPUTimer.GetTimeStamp(pCmdLst1, "Motion vectors"); + m_GPUTimer.GetTimeStamp(pCmdLst1, "Motion Vectors"); } void SampleRenderer::RenderSkydome(ID3D12GraphicsCommandList* pCmdLst1, per_frame * pPerFrame, State * pState) { + UserMarker marker(pCmdLst1, "Skydome"); + if (pState->skyDomeType == 1) { XMMATRIX clipToView = XMMatrixInverse(NULL, pPerFrame->mCameraViewProj); @@ -773,7 +777,7 @@ void SampleRenderer::DownsampleDepthBuffer(ID3D12GraphicsCommandList* pCmdLst1) void SampleRenderer::RenderScreenSpaceReflections(ID3D12GraphicsCommandList* pCmdLst1, State * pState) { - UserMarker marker(pCmdLst1, "SSR"); + UserMarker marker(pCmdLst1, "FidelityFX SSSR"); const Camera * camera = &pState->camera; XMMATRIX view = camera->GetView(); @@ -784,44 +788,44 @@ void SampleRenderer::RenderScreenSpaceReflections(ID3D12GraphicsCommandList* pCm XMFLOAT4X4 cameraProj; XMStoreFloat4x4(&cameraProj, XMMatrixTranspose(proj)); - SssrStatus status; - status = sssrReflectionViewSetCameraParameters(m_SssrContext, m_SssrReflectionView, &cameraView.m[0][0], &cameraProj.m[0][0]); - if (status != SSSR_STATUS_OK) + FfxSssrStatus status; + status = ffxSssrReflectionViewSetCameraParameters(m_SssrContext, m_SssrReflectionView, &cameraView.m[0][0], &cameraProj.m[0][0]); + if (status != FFX_SSSR_STATUS_OK) { - Trace("sssrReflectionViewSetCameraParameters failed."); + Trace("ffxSssrReflectionViewSetCameraParameters failed."); } FLOAT clearValues[4] = { 0, 0, 0, 0 }; pCmdLst1->ClearUnorderedAccessViewFloat(m_SssrOutputBufferUAVGPU.GetGPU(), m_SssrOutputBufferUAV.GetCPU(), m_SssrOutputBuffer.GetResource(), clearValues, 0, nullptr); - SssrCommandEncodeInfoD3D12 d3d12EncodeInfo = {}; + FfxSssrD3D12CommandEncodeInfo d3d12EncodeInfo = {}; d3d12EncodeInfo.pCommandList = pCmdLst1; - SssrResolveReflectionViewInfo resolveInfo = {}; - resolveInfo.flags = pState->bShowIntersectionResults ? 0 : SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE; - resolveInfo.flags |= pState->bEnableVarianceGuidedTracing ? SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING : 0; - resolveInfo.pCommandEncodeInfoD3D12 = &d3d12EncodeInfo; + FfxSssrResolveReflectionViewInfo resolveInfo = {}; + resolveInfo.flags = pState->bShowIntersectionResults ? 0 : FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_DENOISE; + resolveInfo.flags |= pState->bEnableVarianceGuidedTracing ? FFX_SSSR_RESOLVE_REFLECTION_VIEW_FLAG_ENABLE_VARIANCE_GUIDED_TRACING : 0; + resolveInfo.pD3D12CommandEncodeInfo = &d3d12EncodeInfo; resolveInfo.temporalStabilityScale = pState->temporalStability; resolveInfo.maxTraversalIterations = pState->maxTraversalIterations; resolveInfo.mostDetailedDepthHierarchyMipLevel = pState->mostDetailedDepthHierarchyMipLevel; resolveInfo.depthBufferThickness = pState->depthBufferThickness; resolveInfo.minTraversalOccupancy = pState->minTraversalOccupancy; - resolveInfo.samplesPerQuad = pState->samplesPerQuad == 4 ? SSSR_RAY_SAMPLES_PER_QUAD_4 : (pState->samplesPerQuad == 2 ? SSSR_RAY_SAMPLES_PER_QUAD_2 : SSSR_RAY_SAMPLES_PER_QUAD_1); - resolveInfo.eawPassCount = pState->eawPassCount == 3 ? SSSR_EAW_PASS_COUNT_3 : SSSR_EAW_PASS_COUNT_1; + resolveInfo.samplesPerQuad = pState->samplesPerQuad == 4 ? FFX_SSSR_RAY_SAMPLES_PER_QUAD_4 : (pState->samplesPerQuad == 2 ? FFX_SSSR_RAY_SAMPLES_PER_QUAD_2 : FFX_SSSR_RAY_SAMPLES_PER_QUAD_1); + resolveInfo.eawPassCount = pState->eawPassCount == 3 ? FFX_SSSR_EAW_PASS_COUNT_3 : FFX_SSSR_EAW_PASS_COUNT_1; resolveInfo.roughnessThreshold = pState->roughnessThreshold; - status = sssrEncodeResolveReflectionView(m_SssrContext, m_SssrReflectionView, &resolveInfo); - if (status != SSSR_STATUS_OK) + status = ffxSssrEncodeResolveReflectionView(m_SssrContext, m_SssrReflectionView, &resolveInfo); + if (status != FFX_SSSR_STATUS_OK) { - Trace("sssrEncodeResolveReflectionView failed."); + Trace("ffxSssrEncodeResolveReflectionView failed."); } // Query timings uint64_t tileClassificationTime; - status = sssrReflectionViewGetTileClassificationElapsedTime(m_SssrContext, m_SssrReflectionView, &tileClassificationTime); - if (status != SSSR_STATUS_OK) + status = ffxSssrReflectionViewGetTileClassificationElapsedTime(m_SssrContext, m_SssrReflectionView, &tileClassificationTime); + if (status != FFX_SSSR_STATUS_OK) { - Trace("sssrReflectionViewGetTileClassificationElapsedTime failed."); + Trace("ffxSssrReflectionViewGetTileClassificationElapsedTime failed."); } static std::deque tileClassificationTimes(100); @@ -835,10 +839,10 @@ void SampleRenderer::RenderScreenSpaceReflections(ID3D12GraphicsCommandList* pCm pState->tileClassificationTime /= tileClassificationTimes.size(); uint64_t intersectionTime; - status = sssrReflectionViewGetIntersectionElapsedTime(m_SssrContext, m_SssrReflectionView, &intersectionTime); - if (status != SSSR_STATUS_OK) + status = ffxSssrReflectionViewGetIntersectionElapsedTime(m_SssrContext, m_SssrReflectionView, &intersectionTime); + if (status != FFX_SSSR_STATUS_OK) { - Trace("sssrReflectionViewGetIntersectionElapsedTime failed."); + Trace("ffxSssrReflectionViewGetIntersectionElapsedTime failed."); } static std::deque intersectionTimes(100); @@ -852,10 +856,10 @@ void SampleRenderer::RenderScreenSpaceReflections(ID3D12GraphicsCommandList* pCm pState->intersectionTime /= intersectionTimes.size(); uint64_t denoisingTime; - status = sssrReflectionViewGetDenoisingElapsedTime(m_SssrContext, m_SssrReflectionView, &denoisingTime); - if (status != SSSR_STATUS_OK) + status = ffxSssrReflectionViewGetDenoisingElapsedTime(m_SssrContext, m_SssrReflectionView, &denoisingTime); + if (status != FFX_SSSR_STATUS_OK) { - Trace("sssrReflectionViewGetDenoisingElapsedTime failed."); + Trace("ffxSssrReflectionViewGetDenoisingElapsedTime failed."); } static std::deque denoisingTimes(100); @@ -868,7 +872,7 @@ void SampleRenderer::RenderScreenSpaceReflections(ID3D12GraphicsCommandList* pCm } pState->denoisingTime /= denoisingTimes.size(); - m_GPUTimer.GetTimeStamp(pCmdLst1, "SSSR Draw"); + m_GPUTimer.GetTimeStamp(pCmdLst1, "FidelityFX SSSR"); } void SampleRenderer::CopyHistorySurfaces(ID3D12GraphicsCommandList* pCmdLst1) @@ -925,42 +929,50 @@ void SampleRenderer::ApplyReflectionTarget(ID3D12GraphicsCommandList* pCmdLst1, void SampleRenderer::DownsampleScene(ID3D12GraphicsCommandList* pCmdLst1) { + UserMarker marker(pCmdLst1, "Downsample Scene"); + D3D12_CPU_DESCRIPTOR_HANDLE renderTargets[] = { m_HDRRTV.GetCPU() }; pCmdLst1->OMSetRenderTargets(ARRAYSIZE(renderTargets), renderTargets, false, NULL); m_DownSample.Draw(pCmdLst1); //m_downSample.Gui(); - m_GPUTimer.GetTimeStamp(pCmdLst1, "Downsample"); + m_GPUTimer.GetTimeStamp(pCmdLst1, "Downsample Scene"); } void SampleRenderer::RenderBloom(ID3D12GraphicsCommandList* pCmdLst1) { + UserMarker marker(pCmdLst1, "Render Bloom"); + D3D12_CPU_DESCRIPTOR_HANDLE renderTargets[] = { m_HDRRTV.GetCPU() }; pCmdLst1->OMSetRenderTargets(ARRAYSIZE(renderTargets), renderTargets, false, NULL); m_Bloom.Draw(pCmdLst1, &m_HDR); - m_GPUTimer.GetTimeStamp(pCmdLst1, "Bloom"); + m_GPUTimer.GetTimeStamp(pCmdLst1, "Render Bloom"); } void SampleRenderer::ApplyTonemapping(ID3D12GraphicsCommandList* pCmdLst2, State * pState, SwapChain *pSwapChain) { + UserMarker marker(pCmdLst2, "Apply Tonemapping"); + pCmdLst2->RSSetViewports(1, &m_Viewport); pCmdLst2->RSSetScissorRects(1, &m_Scissor); pCmdLst2->OMSetRenderTargets(1, pSwapChain->GetCurrentBackBufferRTV(), false, NULL); m_ToneMapping.Draw(pCmdLst2, &m_HDRSRV, pState->exposure, pState->toneMapper); - m_GPUTimer.GetTimeStamp(pCmdLst2, "Tone mapping"); + m_GPUTimer.GetTimeStamp(pCmdLst2, "Apply Tonemapping"); } void SampleRenderer::RenderHUD(ID3D12GraphicsCommandList* pCmdLst2, SwapChain *pSwapChain) { + UserMarker marker(pCmdLst2, "Render HUD"); + pCmdLst2->RSSetViewports(1, &m_Viewport); pCmdLst2->RSSetScissorRects(1, &m_Scissor); pCmdLst2->OMSetRenderTargets(1, pSwapChain->GetCurrentBackBufferRTV(), false, NULL); m_ImGUI.Draw(pCmdLst2); - m_GPUTimer.GetTimeStamp(pCmdLst2, "ImGUI rendering"); + m_GPUTimer.GetTimeStamp(pCmdLst2, "Render HUD"); } void Barriers(ID3D12GraphicsCommandList* pCmdLst, const std::vector& barriers) @@ -1071,21 +1083,23 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain) Barriers(pCmdLst1, { CD3DX12_RESOURCE_BARRIER::UAV(m_DepthHierarchy.GetResource()), + CD3DX12_RESOURCE_BARRIER::Transition(m_DepthHierarchy.GetResource(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE), CD3DX12_RESOURCE_BARRIER::Transition(m_DepthBuffer.GetResource(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_DEPTH_WRITE), CD3DX12_RESOURCE_BARRIER::Transition(m_HDR.GetResource(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, 0), CD3DX12_RESOURCE_BARRIER::Transition(m_NormalBuffer.GetResource(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, 0), CD3DX12_RESOURCE_BARRIER::Transition(m_SpecularRoughness.GetResource(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, 0), - CD3DX12_RESOURCE_BARRIER::Transition(m_MotionVectors.GetResource(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, 0) - }); + CD3DX12_RESOURCE_BARRIER::Transition(m_MotionVectors.GetResource(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, 0), + }); - // Stochastic SSR + // Stochastic Screen Space Reflections if (m_gltfPBR && pPerFrame != NULL) // Only draw reflections if we draw objects { RenderScreenSpaceReflections(pCmdLst1, pState); } Barriers(pCmdLst1, { - CD3DX12_RESOURCE_BARRIER::UAV(m_SssrOutputBuffer.GetResource()), // Wait for reflection target to be written + CD3DX12_RESOURCE_BARRIER::Transition(m_SssrOutputBuffer.GetResource(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE), // Wait for reflection target to be written + CD3DX12_RESOURCE_BARRIER::Transition(m_DepthHierarchy.GetResource(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS), CD3DX12_RESOURCE_BARRIER::Transition(m_NormalBuffer.GetResource(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_SOURCE), CD3DX12_RESOURCE_BARRIER::Transition(m_SpecularRoughness.GetResource(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_SOURCE), CD3DX12_RESOURCE_BARRIER::Transition(m_NormalHistoryBuffer.GetResource(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_DEST), @@ -1095,15 +1109,15 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain) CopyHistorySurfaces(pCmdLst1); // Keep this frames results for next frame Barriers(pCmdLst1, { - CD3DX12_RESOURCE_BARRIER::Transition(m_NormalBuffer.GetResource(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET), - CD3DX12_RESOURCE_BARRIER::Transition(m_SpecularRoughness.GetResource(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET), + CD3DX12_RESOURCE_BARRIER::Transition(m_NormalBuffer.GetResource(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE), + CD3DX12_RESOURCE_BARRIER::Transition(m_SpecularRoughness.GetResource(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE), CD3DX12_RESOURCE_BARRIER::Transition(m_NormalHistoryBuffer.GetResource(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE), CD3DX12_RESOURCE_BARRIER::Transition(m_SpecularRoughnessHistory.GetResource(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE), CD3DX12_RESOURCE_BARRIER::Transition(m_HDR.GetResource(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET, 0), CD3DX12_RESOURCE_BARRIER::Transition(m_MotionVectors.GetResource(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET, 0) }); - // Apply the result of SSR + // Apply the result of SSSR if (m_gltfPBR && pPerFrame != NULL) // only reflect if we draw objects { ApplyReflectionTarget(pCmdLst1, pState); @@ -1111,9 +1125,17 @@ void SampleRenderer::OnRender(State *pState, SwapChain *pSwapChain) // Bloom, takes HDR as input and applies bloom to it. Barriers(pCmdLst1, { - CD3DX12_RESOURCE_BARRIER::Transition(m_HDR.GetResource(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE) + CD3DX12_RESOURCE_BARRIER::Transition(m_HDR.GetResource(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE), + CD3DX12_RESOURCE_BARRIER::Transition(m_SssrOutputBuffer.GetResource(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS), + CD3DX12_RESOURCE_BARRIER::Transition(m_SpecularRoughness.GetResource(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET), + CD3DX12_RESOURCE_BARRIER::Transition(m_NormalBuffer.GetResource(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET) }); - RenderBloom(pCmdLst1); + + if (pState->bDrawBloom) + { + DownsampleScene(pCmdLst1); + RenderBloom(pCmdLst1); + } // Submit command buffer ThrowIfFailed(pCmdLst1->Close()); diff --git a/sample/src/DX12/Sources/SampleRenderer.h b/sample/src/DX12/Sources/SampleRenderer.h index 2dcbfbf..158c385 100644 --- a/sample/src/DX12/Sources/SampleRenderer.h +++ b/sample/src/DX12/Sources/SampleRenderer.h @@ -53,6 +53,7 @@ class SampleRenderer int skyDomeType; bool bDrawBoundingBoxes; bool bDrawLightFrustum; + bool bDrawBloom; bool bDrawScreenSpaceReflections; float targetFrametime; @@ -115,8 +116,6 @@ class SampleRenderer uint32_t m_Width; uint32_t m_Height; - uint32_t m_CurrentFrame; - D3D12_VIEWPORT m_Viewport; D3D12_RECT m_Scissor; @@ -190,9 +189,9 @@ class SampleRenderer std::vector m_TimeStamps; - // SSR Effect - SssrContext m_SssrContext; - SssrReflectionView m_SssrReflectionView; + // FFX SSSR Effect + FfxSssrContext m_SssrContext; + FfxSssrReflectionView m_SssrReflectionView; bool m_SssrCreatedReflectionView = false; CBV_SRV_UAV m_SssrSceneSRV; CBV_SRV_UAV m_SssrDepthBufferHierarchySRV; diff --git a/sample/src/DX12/Sources/SSSRSample.cpp b/sample/src/DX12/Sources/SssrSample.cpp similarity index 93% rename from sample/src/DX12/Sources/SSSRSample.cpp rename to sample/src/DX12/Sources/SssrSample.cpp index 9085fef..066d509 100644 --- a/sample/src/DX12/Sources/SSSRSample.cpp +++ b/sample/src/DX12/Sources/SssrSample.cpp @@ -22,18 +22,18 @@ THE SOFTWARE. #include "stdafx.h" -#include "SSSRSample.h" +#include "SssrSample.h" const bool VALIDATION_ENABLED = false; -SSSRSample::SSSRSample(LPCSTR name) : FrameworkWindows(name) +SssrSample::SssrSample(LPCSTR name) : FrameworkWindows(name) { m_LastFrameTime = MillisecondsNow(); m_Time = 0; m_bPlay = true; m_bShowUI = true; - m_CameraControlSelected = 2; // select cam #0 on start up + m_CameraControlSelected = 0; // select WASD on start up m_pGltfLoader = NULL; } @@ -43,7 +43,7 @@ SSSRSample::SSSRSample(LPCSTR name) : FrameworkWindows(name) // OnCreate // //-------------------------------------------------------------------------------------- -void SSSRSample::OnCreate(HWND hWnd) +void SssrSample::OnCreate(HWND hWnd) { if (!LoadConfiguration()) { @@ -59,7 +59,7 @@ void SSSRSample::OnCreate(HWND hWnd) // Create Device // - m_Device.OnCreate("SSSRSample", "Cauldron", VALIDATION_ENABLED, hWnd); + m_Device.OnCreate("SssrSample", "Cauldron", VALIDATION_ENABLED, hWnd); m_Device.CreatePipelineCache(); //init the shader compiler @@ -93,6 +93,7 @@ void SSSRSample::OnCreate(HWND hWnd) m_State.iblFactor = 1.0f; m_State.bDrawBoundingBoxes = false; m_State.bDrawLightFrustum = false; + m_State.bDrawBloom = false; m_State.camera.LookAt(m_Yaw, m_Pitch, m_Distance, XMVectorSet(0, 0, 0, 0)); m_State.lightIntensity = 10.f; m_State.lightCamera.SetFov(XM_PI / 6.0f, 1024, 1024, 0.1f, 20.0f); @@ -118,7 +119,7 @@ void SSSRSample::OnCreate(HWND hWnd) // OnDestroy // //-------------------------------------------------------------------------------------- -void SSSRSample::OnDestroy() +void SssrSample::OnDestroy() { ImGUI_Shutdown(); @@ -153,7 +154,7 @@ void SSSRSample::OnDestroy() // OnEvent, forward Win32 events to ImGUI // //-------------------------------------------------------------------------------------- -bool SSSRSample::OnEvent(MSG msg) +bool SssrSample::OnEvent(MSG msg) { if (ImGUI_WndProcHandler(msg.hwnd, msg.message, msg.wParam, msg.lParam)) return true; @@ -166,14 +167,14 @@ bool SSSRSample::OnEvent(MSG msg) // SetFullScreen // //-------------------------------------------------------------------------------------- -void SSSRSample::SetFullScreen(bool fullscreen) +void SssrSample::SetFullScreen(bool fullscreen) { m_Device.GPUFlush(); m_Swapchain.SetFullScreen(fullscreen); } -bool SSSRSample::LoadConfiguration() +bool SssrSample::LoadConfiguration() { std::ifstream f("config.json"); if (!f) @@ -190,7 +191,7 @@ bool SSSRSample::LoadConfiguration() return true; } -void SSSRSample::BuildUI() +void SssrSample::BuildUI() { ImGuiStyle& style = ImGui::GetStyle(); style.FrameBorderSize = 1.0f; @@ -291,6 +292,7 @@ void SSSRSample::BuildUI() ImGui::SliderFloat("Emmisive", &m_State.emmisiveFactor, 1.0f, 1000.0f, NULL, 1.0f); ImGui::SliderFloat("Exposure", &m_State.exposure, 0.0f, 4.0f); ImGui::Checkbox("Show Light Frustums", &m_State.bDrawLightFrustum); + ImGui::Checkbox("Draw Bloom", &m_State.bDrawBloom); } if (ImGui::CollapsingHeader("Reflections", ImGuiTreeNodeFlags_DefaultOpen)) @@ -316,9 +318,9 @@ void SSSRSample::BuildUI() ImGui::RadioButton("EAW 1", &m_State.eawPassCount, 1); ImGui::SameLine(); ImGui::RadioButton("EAW 3", &m_State.eawPassCount, 3); - ImGui::Value("Tile Classification Elapsed Time", m_State.tileClassificationTime); - ImGui::Value("Intersection Elapsed Time", m_State.intersectionTime); - ImGui::Value("Denoising Elapsed Time", m_State.denoisingTime); + ImGui::Value("Tile Classification Elapsed Time", 1000 * m_State.tileClassificationTime, "%.1f us"); + ImGui::Value("Intersection Elapsed Time", 1000 * m_State.intersectionTime, "%.1f us"); + ImGui::Value("Denoising Elapsed Time", 1000 * m_State.denoisingTime, "%.1f us"); } if (ImGui::CollapsingHeader("Profiler")) @@ -348,7 +350,7 @@ void SSSRSample::BuildUI() ImGui::End(); } -void SSSRSample::HandleInput() +void SssrSample::HandleInput() { // If the mouse was not used by the GUI then it's for the camera // @@ -396,9 +398,11 @@ void SSSRSample::HandleInput() } else { - // Do WASD controls as well - // - m_State.camera.UpdateCameraWASD(m_Yaw, m_Pitch, io.KeysDown, io.DeltaTime); + // Use a camera from the GLTF + // + m_pGltfLoader->GetCamera(m_CameraControlSelected - 2, &m_State.camera); + m_Yaw = m_State.camera.GetYaw(); + m_Pitch = m_State.camera.GetPitch(); } } } @@ -408,7 +412,7 @@ void SSSRSample::HandleInput() // OnResize // //-------------------------------------------------------------------------------------- -void SSSRSample::OnResize(uint32_t width, uint32_t height) +void SssrSample::OnResize(uint32_t width, uint32_t height) { if (m_Width != width || m_Height != height) { @@ -449,7 +453,7 @@ void SSSRSample::OnResize(uint32_t width, uint32_t height) // OnRender, updates the state from the UI, animates, transforms and renders the scene // //-------------------------------------------------------------------------------------- -void SSSRSample::OnRender() +void SssrSample::OnRender() { // Get timings // @@ -530,5 +534,5 @@ int WINAPI WinMain(HINSTANCE hInstance, uint32_t Height = 1080; // 841; // create new DX sample - return RunFramework(hInstance, lpCmdLine, nCmdShow, Width, Height, new SSSRSample(Name)); + return RunFramework(hInstance, lpCmdLine, nCmdShow, Width, Height, new SssrSample(Name)); } \ No newline at end of file diff --git a/sample/src/DX12/Sources/SSSRSample.h b/sample/src/DX12/Sources/SssrSample.h similarity index 97% rename from sample/src/DX12/Sources/SSSRSample.h rename to sample/src/DX12/Sources/SssrSample.h index 8e4d27b..7438d13 100644 --- a/sample/src/DX12/Sources/SSSRSample.h +++ b/sample/src/DX12/Sources/SssrSample.h @@ -39,10 +39,10 @@ THE SOFTWARE. // - uses the SampleRenderer to update all the state to the GPU and do the rendering // -class SSSRSample : public FrameworkWindows +class SssrSample : public FrameworkWindows { public: - SSSRSample(LPCSTR name); + SssrSample(LPCSTR name); void OnCreate(HWND hWnd); void OnDestroy(); void OnRender();