16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 15:09:19 +02:00

Some renaming

This commit is contained in:
2025-04-15 01:32:56 +02:00
parent 12d6a1578d
commit a39d972126
864 changed files with 29 additions and 34 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,318 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/// @defgroup DX12Backend DX12 Backend
/// FidelityFX SDK native backend implementation for DirectX 12.
///
/// @ingroup Backends
/// @defgroup DX12FrameInterpolation DX12 FrameInterpolation
/// FidelityFX SDK native frame interpolation implementation for DirectX 12 backend.
///
/// @ingroup DX12Backend
#pragma once
#include <d3d12.h>
#include <dxgi1_6.h>
#include <FidelityFX/host/ffx_interface.h>
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// Query how much memory is required for the DirectX 12 backend's scratch buffer.
///
/// @param [in] maxContexts The maximum number of simultaneous effect contexts that will share the backend.
/// (Note that some effects contain internal contexts which count towards this maximum)
///
/// @returns
/// The size (in bytes) of the required scratch memory buffer for the DX12 backend.
/// @ingroup DX12Backend
FFX_API size_t ffxGetScratchMemorySizeDX12(size_t maxContexts);
/// Create a <c><i>FfxDevice</i></c> from a <c><i>ID3D12Device</i></c>.
///
/// @param [in] device A pointer to the DirectX12 device.
///
/// @returns
/// An abstract FidelityFX device.
///
/// @ingroup DX12Backend
FFX_API FfxDevice ffxGetDeviceDX12(ID3D12Device* device);
/// Populate an interface with pointers for the DX12 backend.
///
/// @param [out] backendInterface A pointer to a <c><i>FfxInterface</i></c> structure to populate with pointers.
/// @param [in] device A pointer to the DirectX12 device.
/// @param [in] scratchBuffer A pointer to a buffer of memory which can be used by the DirectX(R)12 backend.
/// @param [in] scratchBufferSize The size (in bytes) of the buffer pointed to by <c><i>scratchBuffer</i></c>.
/// @param [in] maxContexts The maximum number of simultaneous effect contexts that will share the backend.
/// (Note that some effects contain internal contexts which count towards this maximum)
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_INVALID_POINTER The <c><i>interface</i></c> pointer was <c><i>NULL</i></c>.
///
/// @ingroup DX12Backend
FFX_API FfxErrorCode ffxGetInterfaceDX12(
FfxInterface* backendInterface,
FfxDevice device,
void* scratchBuffer,
size_t scratchBufferSize,
size_t maxContexts);
/// Create a <c><i>FfxCommandList</i></c> from a <c><i>ID3D12CommandList</i></c>.
///
/// @param [in] cmdList A pointer to the DirectX12 command list.
///
/// @returns
/// An abstract FidelityFX command list.
///
/// @ingroup DX12Backend
FFX_API FfxCommandList ffxGetCommandListDX12(ID3D12CommandList* cmdList);
/// Create a <c><i>FfxPipeline</i></c> from a <c><i>ID3D12PipelineState</i></c>.
///
/// @param [in] pipelineState A pointer to the DirectX12 pipeline state.
///
/// @returns
/// An abstract FidelityFX pipeline.
///
/// @ingroup DX12Backend
FFX_API FfxPipeline ffxGetPipelineDX12(ID3D12PipelineState* pipelineState);
/// Fetch a <c><i>FfxResource</i></c> from a <c><i>GPUResource</i></c>.
///
/// @param [in] dx12Resource A pointer to the DX12 resource.
/// @param [in] ffxResDescription An <c><i>FfxResourceDescription</i></c> for the resource representation.
/// @param [in] ffxResName (optional) A name string to identify the resource in debug mode.
/// @param [in] state The state the resource is currently in.
///
/// @returns
/// An abstract FidelityFX resources.
///
/// @ingroup DX12Backend
FFX_API FfxResource ffxGetResourceDX12(const ID3D12Resource* dx12Resource,
FfxResourceDescription ffxResDescription,
const wchar_t* ffxResName,
FfxResourceStates state = FFX_RESOURCE_STATE_COMPUTE_READ);
/// Loads PIX runtime dll to allow SDK calls to show up in Microsoft PIX.
///
/// @param [in] pixDllPath The path to the DLL to load.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_PATH Could not load the DLL using the provided path.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR Could not get proc addresses for PIXBeginEvent and/or PIXEndEvent
///
/// @ingroup DX12Backend
FFX_API FfxErrorCode ffxLoadPixDll(const wchar_t* pixDllPath);
/// Fetch a <c><i>FfxSurfaceFormat</i></c> from a DXGI_FORMAT.
///
/// @param [in] format The DXGI_FORMAT to convert to <c><i>FfxSurfaceFormat</i></c>.
///
/// @returns
/// An <c><i>FfxSurfaceFormat</i></c>.
///
/// @ingroup DX12Backend
FFX_API FfxSurfaceFormat ffxGetSurfaceFormatDX12(DXGI_FORMAT format);
/// Fetch a DXGI_FORMAT from a <c><i>FfxSurfaceFormat</i></c>.
///
/// @param [in] surfaceFormat The <c><i>FfxSurfaceFormat</i></c> to convert to DXGI_FORMAT.
///
/// @returns
/// An DXGI_FORMAT.
///
/// @ingroup DX12Backend
FFX_API DXGI_FORMAT ffxGetDX12FormatFromSurfaceFormat(FfxSurfaceFormat surfaceFormat);
/// Fetch a <c><i>FfxResourceDescription</i></c> from an existing ID3D12Resource.
///
/// @param [in] pResource The ID3D12Resource resource to create a <c><i>FfxResourceDescription</i></c> for.
/// @param [in] additionalUsages Optional <c><i>FfxResourceUsage</i></c> flags needed for select resource mapping.
///
/// @returns
/// An <c><i>FfxResourceDescription</i></c>.
///
/// @ingroup DX12Backend
FFX_API FfxResourceDescription ffxGetResourceDescriptionDX12(const ID3D12Resource* pResource, FfxResourceUsage additionalUsages = FFX_RESOURCE_USAGE_READ_ONLY);
/// Fetch a <c><i>FfxCommandQueue</i></c> from an existing ID3D12CommandQueue.
///
/// @param [in] pCommandQueue The ID3D12CommandQueue to create a <c><i>FfxCommandQueue</i></c> from.
///
/// @returns
/// An <c><i>FfxCommandQueue</i></c>.
///
/// @ingroup DX12Backend
FFX_API FfxCommandQueue ffxGetCommandQueueDX12(ID3D12CommandQueue* pCommandQueue);
/// Fetch a <c><i>FfxSwapchain</i></c> from an existing IDXGISwapChain4.
///
/// @param [in] pSwapchain The IDXGISwapChain4 to create a <c><i>FfxSwapchain</i></c> from.
///
/// @returns
/// An <c><i>FfxSwapchain</i></c>.
///
/// @ingroup DX12Backend
FFX_API FfxSwapchain ffxGetSwapchainDX12(IDXGISwapChain4* pSwapchain);
/// Fetch a IDXGISwapChain4 from an existing <c><i>FfxSwapchain</i></c>.
///
/// @param [in] ffxSwapchain The <c><i>FfxSwapchain</i></c> to fetch an IDXGISwapChain4 from.
///
/// @returns
/// An IDXGISwapChain4 object.
///
/// @ingroup DX12Backend
FFX_API IDXGISwapChain4* ffxGetDX12SwapchainPtr(FfxSwapchain ffxSwapchain);
/// Replaces the current swapchain with the provided <c><i>FfxSwapchain</i></c>.
///
/// @param [in] gameQueue The <c><i>FfxCommandQueue</i></c> presentation will occur on.
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to use for frame interpolation presentation.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT One of the parameters is invalid.
///
/// @ingroup DX12FrameInterpolation
FFX_API FfxErrorCode ffxReplaceSwapchainForFrameinterpolationDX12(FfxCommandQueue gameQueue, FfxSwapchain& gameSwapChain);
/// Creates a <c><i>FfxSwapchain</i></c> from passed in parameters.
///
/// @param [in] desc The DXGI_SWAP_CHAIN_DESC describing the swapchain creation parameters from the calling application.
/// @param [in] queue The ID3D12CommandQueue to use for frame interpolation presentation.
/// @param [in] dxgiFactory The IDXGIFactory to use for DX12 swapchain creation.
/// @param [out] outGameSwapChain The created <c><i>FfxSwapchain</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT One of the parameters is invalid.
/// FFX_ERROR_OUT_OF_MEMORY Insufficient memory available to allocate <c><i>FfxSwapchain</i></c> or underlying component.
///
/// @ingroup DX12FrameInterpolation
FFX_API FfxErrorCode ffxCreateFrameinterpolationSwapchainDX12(const DXGI_SWAP_CHAIN_DESC* desc,
ID3D12CommandQueue* queue,
IDXGIFactory* dxgiFactory,
FfxSwapchain& outGameSwapChain);
/// Creates a <c><i>FfxSwapchain</i></c> from passed in parameters.
///
/// @param [in] hWnd The HWND handle for the calling application.
/// @param [in] desc1 The DXGI_SWAP_CHAIN_DESC1 describing the swapchain creation parameters from the calling application.
/// @param [in] fullscreenDesc The DXGI_SWAP_CHAIN_FULLSCREEN_DESC describing the full screen swapchain creation parameters from the calling application.
/// @param [in] queue The ID3D12CommandQueue to use for frame interpolation presentation.
/// @param [in] dxgiFactory The IDXGIFactory to use for DX12 swapchain creation.
/// @param [out] outGameSwapChain The created <c><i>FfxSwapchain</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT One of the parameters is invalid.
/// FFX_ERROR_OUT_OF_MEMORY Insufficient memory available to allocate <c><i>FfxSwapchain</i></c> or underlying component.
///
/// @ingroup DX12FrameInterpolation
FFX_API FfxErrorCode ffxCreateFrameinterpolationSwapchainForHwndDX12(HWND hWnd,
const DXGI_SWAP_CHAIN_DESC1* desc1,
const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* fullscreenDesc,
ID3D12CommandQueue* queue,
IDXGIFactory* dxgiFactory,
FfxSwapchain& outGameSwapChain);
/// Waits for the <c><i>FfxSwapchain</i></c> to complete presentation.
///
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to wait on.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Could not query the interface for the frame interpolation swap chain.
///
/// @ingroup DX12FrameInterpolation
FFX_API FfxErrorCode ffxWaitForPresents(FfxSwapchain gameSwapChain);
/// Registers a <c><i>FfxResource</i></c> to use for UI with the provided <c><i>FfxSwapchain</i></c>.
///
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to to register the UI resource with.
/// @param [in] uiResource The <c><i>FfxResource</i></c> representing the UI resource.
/// @param [in] flags A set of <c><i>FfxUiCompositionFlags</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Could not query the interface for the frame interpolation swap chain.
///
/// @ingroup DX12FrameInterpolation
FFX_API FfxErrorCode ffxRegisterFrameinterpolationUiResourceDX12(FfxSwapchain gameSwapChain, FfxResource uiResource, uint32_t flags);
/// Fetches a <c><i>FfxCommandList</i></c> from the <c><i>FfxSwapchain</i></c>.
///
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to get a <c><i>FfxCommandList</i></c> from.
/// @param [out] gameCommandlist The <c><i>FfxCommandList</i></c> from the provided <c><i>FfxSwapchain</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Could not query the interface for the frame interpolation swap chain.
///
/// @ingroup DX12FrameInterpolation
FFX_API FfxErrorCode ffxGetFrameinterpolationCommandlistDX12(FfxSwapchain gameSwapChain, FfxCommandList& gameCommandlist);
/// Fetches a <c><i>FfxResource</i></c> representing the backbuffer from the <c><i>FfxSwapchain</i></c>.
///
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to get a <c><i>FfxResource</i></c> backbuffer from.
///
/// @returns
/// An abstract FidelityFX resources for the swapchain backbuffer.
///
/// @ingroup DX12FrameInterpolation
FFX_API FfxResource ffxGetFrameinterpolationTextureDX12(FfxSwapchain gameSwapChain);
/// Sets a <c><i>FfxFrameGenerationConfig</i></c> to the internal FrameInterpolationSwapChain (in the backend).
///
/// @param [in] config The <c><i>FfxFrameGenerationConfig</i></c> to set.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Could not query the interface for the frame interpolation swap chain.
///
/// @ingroup DX12FrameInterpolation
FFX_API FfxErrorCode ffxSetFrameGenerationConfigToSwapchainDX12(FfxFrameGenerationConfig const* config);
struct FfxFrameInterpolationContext;
typedef FfxErrorCode (*FfxCreateFiSwapchain)(FfxFrameInterpolationContext* fiContext, FfxDevice device, FfxCommandQueue gameQueue, FfxSwapchain& swapchain);
typedef FfxErrorCode (*FfxReleaseFiSwapchain)(FfxFrameInterpolationContext* fiContext, FfxSwapchain* outRealSwapchain);
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2024 Microsoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,327 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/// @defgroup VKBackend Vulkan Backend
/// FidelityFX SDK native backend implementation for Vulkan.
///
/// @ingroup Backends
#pragma once
#include <vulkan/vulkan.h>
#include <FidelityFX/host/ffx_interface.h>
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// FFX specific callback type when submitting a command buffer to a queue.
typedef VkResult (*PFN_vkQueueSubmitFFX)(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence);
typedef struct VkQueueInfoFFX
{
VkQueue queue;
uint32_t familyIndex;
PFN_vkQueueSubmitFFX submitFunc;
} VkQueueInfoFFX;
/// Structure holding additional information to effectively replace the game swapchain by the frame interpolation one.
/// Some notes on the queues:
/// - please pass the queue, its family (for queue family ownership transfer purposes) and an optional function if you want to control concurrent submissions
/// - game queue: the queue where the replacement of vkQueuePresentKHR is called. This queue should have Graphics and Compute capabilities (Transfer is implied as per Vulkan specification).
/// It can be shared with the engine. No Submit function is necessary.
/// The code assumes that the UI texture is owned by that queue family when present is called.
/// - async compute queue: optional queue with Compute capability (Transfer is implied as per Vulkan specification). If used by the engine, prefer not to enable the async compute path of FSR3 Frame interpolation.
/// - present queue: queue with Graphics, Compute or Transfer capability, and Present support. This queue cannot be used by the engine. Otherwise, some deadlock can occur.
/// - image acquire queue: this one doesn't need any capability. Strongly prefer a queue not used by the engine. The main graphics queue can work too but it might delay the signaling of the semaphore/fence when acquiring a new image, negatively impacting the performance.
typedef struct VkFrameInterpolationInfoFFX
{
VkPhysicalDevice physicalDevice;
VkDevice device;
VkQueueInfoFFX gameQueue;
VkQueueInfoFFX asyncComputeQueue;
VkQueueInfoFFX presentQueue;
VkQueueInfoFFX imageAcquireQueue;
const VkAllocationCallbacks* pAllocator;
} VkFrameInterpolationInfoFFX;
/// Query how much memory is required for the Vulkan backend's scratch buffer.
///
/// @param [in] physicalDevice A pointer to the VkPhysicalDevice device.
/// @param [in] maxContexts The maximum number of simultaneous effect contexts that will share the backend.
/// (Note that some effects contain internal contexts which count towards this maximum)
///
/// @returns
/// The size (in bytes) of the required scratch memory buffer for the VK backend.
///
/// @ingroup VKBackend
FFX_API size_t ffxGetScratchMemorySizeVK(VkPhysicalDevice physicalDevice, size_t maxContexts);
/// Convenience structure to hold all VK-related device information
typedef struct VkDeviceContext {
VkDevice vkDevice; /// The Vulkan device
VkPhysicalDevice vkPhysicalDevice; /// The Vulkan physical device
PFN_vkGetDeviceProcAddr vkDeviceProcAddr; /// The device's function address table
} VkDeviceContext;
/// Create a <c><i>FfxDevice</i></c> from a <c><i>VkDevice</i></c>.
///
/// @param [in] vkDeviceContext A pointer to a VKDeviceContext that holds all needed information
///
/// @returns
/// An abstract FidelityFX device.
///
/// @ingroup VKBackend
FFX_API FfxDevice ffxGetDeviceVK(VkDeviceContext* vkDeviceContext);
/// Populate an interface with pointers for the VK backend.
///
/// @param [out] backendInterface A pointer to a <c><i>FfxInterface</i></c> structure to populate with pointers.
/// @param [in] device A pointer to the VkDevice device.
/// @param [in] scratchBuffer A pointer to a buffer of memory which can be used by the DirectX(R)12 backend.
/// @param [in] scratchBufferSize The size (in bytes) of the buffer pointed to by <c><i>scratchBuffer</i></c>.
/// @param [in] maxContexts The maximum number of simultaneous effect contexts that will share the backend.
/// (Note that some effects contain internal contexts which count towards this maximum)
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_INVALID_POINTER The <c><i>interface</i></c> pointer was <c><i>NULL</i></c>.
///
/// @ingroup VKBackend
FFX_API FfxErrorCode ffxGetInterfaceVK(
FfxInterface* backendInterface,
FfxDevice device,
void* scratchBuffer,
size_t scratchBufferSize,
size_t maxContexts);
/// Create a <c><i>FfxCommandList</i></c> from a <c><i>VkCommandBuffer</i></c>.
///
/// @param [in] cmdBuf A pointer to the Vulkan command buffer.
///
/// @returns
/// An abstract FidelityFX command list.
///
/// @ingroup VKBackend
FFX_API FfxCommandList ffxGetCommandListVK(VkCommandBuffer cmdBuf);
/// Create a <c><i>FfxPipeline</i></c> from a <c><i>VkPipeline</i></c>.
///
/// @param [in] pipeline A pointer to the Vulkan pipeline.
///
/// @returns
/// An abstract FidelityFX pipeline.
///
/// @ingroup VKBackend
FFX_API FfxPipeline ffxGetPipelineVK(VkPipeline pipeline);
/// Fetch a <c><i>FfxResource</i></c> from a <c><i>GPUResource</i></c>.
///
/// @param [in] vkResource A pointer to the (agnostic) VK resource.
/// @param [in] ffxResDescription An <c><i>FfxResourceDescription</i></c> for the resource representation.
/// @param [in] ffxResName (optional) A name string to identify the resource in debug mode.
/// @param [in] state The state the resource is currently in.
///
/// @returns
/// An abstract FidelityFX resources.
///
/// @ingroup VKBackend
FFX_API FfxResource ffxGetResourceVK(void* vkResource,
FfxResourceDescription ffxResDescription,
const wchar_t* ffxResName,
FfxResourceStates state = FFX_RESOURCE_STATE_COMPUTE_READ);
/// Fetch a <c><i>FfxSurfaceFormat</i></c> from a VkFormat.
///
/// @param [in] format The VkFormat to convert to <c><i>FfxSurfaceFormat</i></c>.
///
/// @returns
/// An <c><i>FfxSurfaceFormat</i></c>.
///
/// @ingroup VKBackend
FFX_API FfxSurfaceFormat ffxGetSurfaceFormatVK(VkFormat format);
/// Fetch a <c><i>FfxResourceDescription</i></c> from an existing VkBuffer.
///
/// @param [in] buffer The VkBuffer resource to create a <c><i>FfxResourceDescription</i></c> for.
/// @param [in] createInfo The VkBufferCreateInfo of the buffer
/// @param [in] additionalUsages Optional <c><i>FfxResourceUsage</i></c> flags needed for select resource mapping.
///
/// @returns
/// An <c><i>FfxResourceDescription</i></c>.
///
/// @ingroup VKBackend
FFX_API FfxResourceDescription ffxGetBufferResourceDescriptionVK(const VkBuffer buffer,
const VkBufferCreateInfo createInfo,
FfxResourceUsage additionalUsages = FFX_RESOURCE_USAGE_READ_ONLY);
/// Fetch a <c><i>FfxResourceDescription</i></c> from an existing VkImage.
///
/// @param [in] image The VkImage resource to create a <c><i>FfxResourceDescription</i></c> for.
/// @param [in] createInfo The VkImageCreateInfo of the buffer
/// @param [in] additionalUsages Optional <c><i>FfxResourceUsage</i></c> flags needed for select resource mapping.
///
/// @returns
/// An <c><i>FfxResourceDescription</i></c>.
///
/// @ingroup VKBackend
FFX_API FfxResourceDescription ffxGetImageResourceDescriptionVK(const VkImage image,
const VkImageCreateInfo createInfo,
FfxResourceUsage additionalUsages = FFX_RESOURCE_USAGE_READ_ONLY);
/// Fetch a <c><i>FfxCommandQueue</i></c> from an existing VkQueue.
///
/// @param [in] commandQueue The VkQueue to create a <c><i>FfxCommandQueue</i></c> from.
///
/// @returns
/// An <c><i>FfxCommandQueue</i></c>.
///
/// @ingroup VKBackend
FFX_API FfxCommandQueue ffxGetCommandQueueVK(VkQueue commandQueue);
/// Fetch a <c><i>FfxSwapchain</i></c> from an existing VkSwapchainKHR.
///
/// @param [in] pSwapchain The VkSwapchainKHR to create a <c><i>FfxSwapchain</i></c> from.
///
/// @returns
/// An <c><i>FfxSwapchain</i></c>.
///
/// @ingroup VKBackend
FFX_API FfxSwapchain ffxGetSwapchainVK(VkSwapchainKHR swapchain);
/// Fetch a VkSwapchainKHR from an existing <c><i>FfxSwapchain</i></c>.
///
/// @param [in] ffxSwapchain The <c><i>FfxSwapchain</i></c> to fetch an VkSwapchainKHR from.
///
/// @returns
/// An VkSwapchainKHR object.
///
/// @ingroup VKBackend
FFX_API VkSwapchainKHR ffxGetVKSwapchain(FfxSwapchain ffxSwapchain);
/// Replaces the current swapchain with the provided <c><i>FfxSwapchain</i></c>.
///
/// @param [in] gameQueue The <c><i>FfxCommandQueue</i></c> presentation will occur on.
/// @param [in,out] gameSwapChain The current <c><i>FfxSwapchain</i></c> to replace, optional. If not NULL, the swapchain will be destroyed. On return, it will hold the <c><i>FfxSwapchain</i></c> to use for frame interpolation presentation.
/// @param [in] swapchainCreateInfo The <c><i>VkSwapchainCreateInfoKHR</i></c> of the current swapchain. Its oldSwapchain member should be VK_NULL_HANDLE or the same as gameSwapChain.
/// @param [in] frameInterpolationInfo The <c><i>VkFrameInterpolationInfoFFX</i></c> containing additional information for swapchain replacement.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT One of the parameters is invalid. If the returned <c><i>gameSwapChain</i></c> is NULL, the old swapchain has been destroyed.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR Internal generic error. If the returned <c><i>gameSwapChain</i></c> is NULL, the old swapchain has been destroyed.
///
/// @ingroup VKFrameInterpolation
FFX_API FfxErrorCode ffxReplaceSwapchainForFrameinterpolationVK(FfxCommandQueue gameQueue,
FfxSwapchain& gameSwapChain,
const VkSwapchainCreateInfoKHR* swapchainCreateInfo,
const VkFrameInterpolationInfoFFX* frameInterpolationInfo);
/// Waits for the <c><i>FfxSwapchain</i></c> to complete presentation.
///
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to wait on.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Could not query the interface for the frame interpolation swap chain.
///
/// @ingroup VKFrameInterpolation
FFX_API FfxErrorCode ffxWaitForPresents(FfxSwapchain gameSwapChain);
/// Registers a <c><i>FfxResource</i></c> to use for UI with the provided <c><i>FfxSwapchain</i></c>.
///
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to to register the UI resource with.
/// @param [in] uiResource The <c><i>FfxResource</i></c> representing the UI resource.
/// @param [in] flags A set of <c><i>FfxUiCompositionFlags</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Could not query the interface for the frame interpolation swap chain.
///
/// @ingroup VKFrameInterpolation
FFX_API FfxErrorCode ffxRegisterFrameinterpolationUiResourceVK(FfxSwapchain gameSwapChain, FfxResource uiResource, uint32_t flags);
/// Fetches a <c><i>FfxCommandList</i></c> from the <c><i>FfxSwapchain</i></c>.
///
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to get a <c><i>FfxCommandList</i></c> from.
/// @param [out] gameCommandlist The <c><i>FfxCommandList</i></c> from the provided <c><i>FfxSwapchain</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Could not query the interface for the frame interpolation swap chain.
///
/// @ingroup VKFrameInterpolation
FFX_API FfxErrorCode ffxGetFrameinterpolationCommandlistVK(FfxSwapchain gameSwapChain, FfxCommandList& gameCommandlist);
/// Fetches a <c><i>FfxResource</i></c> representing the backbuffer from the <c><i>FfxSwapchain</i></c>.
///
/// @param [in] gameSwapChain The <c><i>FfxSwapchain</i></c> to get a <c><i>FfxResource</i></c> backbuffer from.
///
/// @returns
/// An abstract FidelityFX resources for the swapchain backbuffer.
///
/// @ingroup VKFrameInterpolation
FFX_API FfxResource ffxGetFrameinterpolationTextureVK(FfxSwapchain gameSwapChain);
/// Sets a <c><i>FfxFrameGenerationConfig</i></c> to the internal FrameInterpolationSwapChain (in the backend).
///
/// @param [in] config The <c><i>FfxFrameGenerationConfig</i></c> to set.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Could not query the interface for the frame interpolation swap chain.
///
/// @ingroup VKFrameInterpolation
FFX_API FfxErrorCode ffxSetFrameGenerationConfigToSwapchainVK(FfxFrameGenerationConfig const* config);
typedef VkResult (*PFN_vkCreateSwapchainFFX)(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain, const VkFrameInterpolationInfoFFX* pFrameInterpolationInfo);
/// Function to get he number of presents. This is useful when using frame interpolation
typedef uint64_t (*PFN_getLastPresentCountFFX)(VkSwapchainKHR);
/// Structure holding the replacement function pointers for frame interpolation to work
/// Not all extensions are supported for now
/// Regarding specific functions:
/// - queuePresentKHR: when using this one, the presenting image should be in VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL state
/// - getLastPresentCount: this function isn't part of Vulkan but the engine can use it to get the real number of presented frames since the swapchain creation
struct FfxSwapchainReplacementFunctions
{
PFN_vkCreateSwapchainFFX createSwapchainFFX;
PFN_vkDestroySwapchainKHR destroySwapchainKHR;
PFN_vkGetSwapchainImagesKHR getSwapchainImagesKHR;
PFN_vkAcquireNextImageKHR acquireNextImageKHR;
PFN_vkQueuePresentKHR queuePresentKHR;
PFN_vkSetHdrMetadataEXT setHdrMetadataEXT;
PFN_getLastPresentCountFFX getLastPresentCountFFX;
};
FFX_API FfxErrorCode ffxGetSwapchainReplacementFunctionsVK(FfxDevice device, FfxSwapchainReplacementFunctions* functions);
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,151 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <FidelityFX/host/ffx_types.h>
#include <FidelityFX/host/ffx_util.h>
#ifdef __cplusplus
extern "C" {
#endif // #ifdef __cplusplus
/// @defgroup Asserts Asserts
/// Asserts used by FidelityFX SDK functions
///
/// @ingroup ffxHost
#ifdef _DEBUG
#ifdef _WIN32
#ifdef DISABLE_FFX_DEBUG_BREAK
#define FFX_DEBUG_BREAK \
{ \
}
#else
/// Macro to force the debugger to break at this point in the code.
///
/// @ingroup Asserts
#define FFX_DEBUG_BREAK __debugbreak();
#endif
#else
#define FFX_DEBUG_BREAK \
{ \
}
#endif
#else
// don't allow debug break in release builds.
#define FFX_DEBUG_BREAK
#endif
/// A typedef for the callback function for assert printing.
///
/// This can be used to re-route printing of assert messages from the FFX backend
/// to another destination. For example instead of the default behaviour of printing
/// the assert messages to the debugger's TTY the message can be re-routed to a
/// MessageBox in a GUI application.
///
/// @param [in] message The message generated by the assert.
///
/// @ingroup Asserts
typedef void (*FfxAssertCallback)(const char* message);
/// Function to report an assert.
///
/// @param [in] file The name of the file as a string.
/// @param [in] line The index of the line in the file.
/// @param [in] condition The boolean condition that was tested.
/// @param [in] msg The optional message to print.
///
/// @returns
/// Always returns true.
///
/// @ingroup Asserts
FFX_API bool ffxAssertReport(const char* file, int32_t line, const char* condition, const char* msg);
/// Provides the ability to set a callback for assert messages.
///
/// @param [in] callback The callback function that will receive assert messages.
///
/// @ingroup Asserts
FFX_API void ffxAssertSetPrintingCallback(FfxAssertCallback callback);
#ifdef _DEBUG
/// Standard assert macro.
///
/// @ingroup Asserts
#define FFX_ASSERT(condition) \
do \
{ \
if (!(condition) && ffxAssertReport(__FILE__, __LINE__, #condition, NULL)) \
FFX_DEBUG_BREAK \
} while (0)
/// Assert macro with message.
///
/// @ingroup Asserts
#define FFX_ASSERT_MESSAGE(condition, msg) \
do \
{ \
if (!(condition) && ffxAssertReport(__FILE__, __LINE__, #condition, msg)) \
FFX_DEBUG_BREAK \
} while (0)
/// Assert macro that always fails.
///
/// @ingroup Asserts
#define FFX_ASSERT_FAIL(message) \
do \
{ \
ffxAssertReport(__FILE__, __LINE__, NULL, message); \
FFX_DEBUG_BREAK \
} while (0)
#else
// asserts disabled
#define FFX_ASSERT(condition) \
do \
{ \
FFX_UNUSED(condition); \
} while (0)
#define FFX_ASSERT_MESSAGE(condition, message) \
do \
{ \
FFX_UNUSED(condition); \
FFX_UNUSED(message); \
} while (0)
#define FFX_ASSERT_FAIL(message) \
do \
{ \
FFX_UNUSED(message); \
} while (0)
#endif // #if _DEBUG
/// Simple static assert.
///
/// @ingroup Asserts
#define FFX_STATIC_ASSERT(condition) static_assert(condition, #condition)
#ifdef __cplusplus
}
#endif // #ifdef __cplusplus

View File

@@ -0,0 +1,200 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/// @defgroup ffxBlur FidelityFX Blur
/// FidelityFX Blur runtime library
///
/// @ingroup SDKComponents
//------------------------------------------------------------------------------------------------------------------------------
//
// ABOUT
// =====
// AMD FidelityFX Blur is a collection of blurring effects implemented on compute shaders, hand-optimized for maximum performance.
// FFX-Blur includes
// - Gaussian Blur w/ large kernel support (up to 21x21)
//
//==============================================================================================================================
#pragma once
#include <FidelityFX/host/ffx_interface.h>
/// FidelityFX Blur major version.
///
/// @ingroup ffxBlur
#define FFX_BLUR_VERSION_MAJOR (1)
/// FidelityFX Blur minor version.
///
/// @ingroup ffxBlur
#define FFX_BLUR_VERSION_MINOR (1)
/// FidelityFX Blur patch version.
///
/// @ingroup ffxBlur
#define FFX_BLUR_VERSION_PATCH (0)
/// FidelityFX Blur context count
///
/// Defines the number of internal effect contexts required by Blur
///
/// @ingroup ffxBlur
#define FFX_BLUR_CONTEXT_COUNT 1
/// The size of the context specified in uint32_t units.
///
/// @ingroup ffxBlur
#define FFX_BLUR_CONTEXT_SIZE (1024)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// Enum to specify which blur pass (currently only one).
///
/// @ingroup ffxBlur
typedef enum FfxBlurPass
{
FFX_BLUR_PASS_BLUR = 0, ///< A pass which which blurs the input
FFX_BLUR_PASS_COUNT ///< The number of passes in the Blur effect
} FfxBlurPass;
/// Use this macro for FfxBlurContextDescription::kernelSizes to enable all kernel sizes.
///
/// @ingroup ffxBlur
#define FFX_BLUR_KERNEL_SIZE_ALL ((1 << FFX_BLUR_KERNEL_SIZE_COUNT) - 1)
typedef enum FfxBlurKernelPermutation
{
FFX_BLUR_KERNEL_PERMUTATION_0 = (1 << 0), ///< Sigma value of 1.6 used for generation of Gaussian kernel.
FFX_BLUR_KERNEL_PERMUTATION_1 = (1 << 1), ///< Sigma value of 2.8 used for generation of Gaussian kernel.
FFX_BLUR_KERNEL_PERMUTATION_2 = (1 << 2), ///< Sigma value of 4.0 used for generation of Gaussian kernel.
} FfxBlurKernelPermutation;
#define FFX_BLUR_KERNEL_PERMUTATION_COUNT 3
/// Use this macro for FfxBlurContextDescription::sigmaPermutations to enable all sigma permutations.
///
/// @ingroup ffxBlur
#define FFX_BLUR_KERNEL_PERMUTATIONS_ALL ((1 << FFX_BLUR_KERNEL_PERMUTATION_COUNT) - 1)
/// Enum to specify the size of the blur kernel. Use logical OR to enable multiple kernels
/// when setting the FfxBlurContextDescription::kernelSizes parameter prior to calling
/// ffxBlurContextCreate.
///
/// @ingroup ffxBlur
typedef enum FfxBlurKernelSize
{
FFX_BLUR_KERNEL_SIZE_3x3 = (1 << 0),
FFX_BLUR_KERNEL_SIZE_5x5 = (1 << 1),
FFX_BLUR_KERNEL_SIZE_7x7 = (1 << 2),
FFX_BLUR_KERNEL_SIZE_9x9 = (1 << 3),
FFX_BLUR_KERNEL_SIZE_11x11 = (1 << 4),
FFX_BLUR_KERNEL_SIZE_13x13 = (1 << 5),
FFX_BLUR_KERNEL_SIZE_15x15 = (1 << 6),
FFX_BLUR_KERNEL_SIZE_17x17 = (1 << 7),
FFX_BLUR_KERNEL_SIZE_19x19 = (1 << 8),
FFX_BLUR_KERNEL_SIZE_21x21 = (1 << 9)
} FfxBlurKernelSize;
#define FFX_BLUR_KERNEL_SIZE_COUNT 10
/// Enum to specify whether to initialize the FP32 or FP16 bit permutation of the blur shader(s).
/// Use this when setting the FfxBlurContextDescription::floatPrecision parameter prior to calling
/// ffxBlurContextCreate.
///
/// @ingroup ffxBlur
typedef enum FfxBlurFloatPrecision
{
FFX_BLUR_FLOAT_PRECISION_32BIT = 0,
FFX_BLUR_FLOAT_PRECISION_16BIT = 1,
FFX_BLUR_FLOAT_PRECISION_COUNT = 2
} FfxBlurFloatPrecision;
typedef uint32_t FfxBlurKernelPermutations;
typedef uint32_t FfxBlurKernelSizes;
/// FfxBlurContextDescription struct is used to create/initialize an FfxBlurContext.
///
/// @ingroup ffxBlur
typedef struct FfxBlurContextDescription
{
FfxBlurKernelPermutations kernelPermutations; ///< A bit mask of FfxBlurKernelPermutation values to indicate which kernels to enable for use.
FfxBlurKernelSizes kernelSizes; ///< A bit mask of FfxBlurKernelSize values to indicated which kernel sizes to enable for use.
FfxBlurFloatPrecision floatPrecision; ///< A flag indicating the desired floating point precision for use in ffxBlurContextDispatch
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX.
} FfxBlurContextDescription;
/// FfxBlurContext must be created via ffxBlurContextCreate to use the FFX Blur effect.
///
/// @ingroup ffxBlur
typedef struct FfxBlurContext
{
uint32_t data[FFX_BLUR_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxBlurContext;
/// Create and initialize the FfxBlurContext.
///
/// @param [out] pContext The FfxBlurContext to create and initialize.
/// @param [in] pContextDescription The initialization configuration parameters.
///
/// @ingroup ffxBlur
FFX_API FfxErrorCode ffxBlurContextCreate(FfxBlurContext* pContext, const FfxBlurContextDescription* pContextDescription);
/// Destroy and free resources associated with the FfxBlurContext.
///
/// @param [inout] pContext The FfxBlurContext to destroy.
///
/// @ingroup ffxBlur
FFX_API FfxErrorCode ffxBlurContextDestroy(FfxBlurContext* pContext);
/// FfxBlurDispatchDescription struct defines configuration of a blur dispatch (see ffxBlurContextDispatch).
///
/// @ingroup ffxBlur
typedef struct FfxBlurDispatchDescription
{
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record rendering commands into.
FfxBlurKernelPermutation kernelPermutation; ///< The permutation of the kernel (must be the one specified in FfxBlurContextDescription::kernelPermutations).
FfxBlurKernelSize kernelSize; ///< The kernel size to use for blurring (must be one specified in FfxBlurContextDescription::kernelSizes).
FfxDimensions2D inputAndOutputSize; ///< The width and height in pixels of the input and output resources.
FfxResource input; ///< The <c><i>FfxResource</i></c> to blur.
FfxResource output; ///< The <c><i>FfxResource</i></c> containing the output buffer for the blurred output.
} FfxBlurDispatchDescription;
/// Create and initialize the FfxBlurContext.
///
/// @param [in] pContext The FfxBlurContext to use for the dispatch.
/// @param [in] pDispatchDescription The dispatch configuration parameters (see FfxBlurDispatchDescription).
///
/// @ingroup ffxBlur
FFX_API FfxErrorCode ffxBlurContextDispatch(FfxBlurContext* pContext, const FfxBlurDispatchDescription* pDispatchDescription);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxBlur
FFX_API FfxVersionNumber ffxBlurGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus

View File

@@ -0,0 +1,483 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup BREADCRUMBS
#pragma once
// Include the interface for the backend of the Breadcrumbs API.
#include <FidelityFX/host/ffx_interface.h>
/// FidelityFX Breadcrumbs major version.
///
/// @ingroup BREADCRUMBS
#define FFX_BREADCRUMBS_VERSION_MAJOR (1)
/// FidelityFX Breadcrumbs minor version.
///
/// @ingroup BREADCRUMBS
#define FFX_BREADCRUMBS_VERSION_MINOR (0)
/// FidelityFX Breadcrumbs patch version.
///
/// @ingroup BREADCRUMBS
#define FFX_BREADCRUMBS_VERSION_PATCH (0)
/// FidelityFX Breadcrumbs context count
///
/// Defines the number of internal effect contexts required by Breadcrumbs
///
/// @ingroup BREADCRUMBS
#define FFX_BREADCRUMBS_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup BREADCRUMBS
#define FFX_BREADCRUMBS_CONTEXT_SIZE (128)
/// Maximal number of markers that can be written into single memory block.
///
/// @ingroup BREADCRUMBS
#define FFX_BREADCRUMBS_MAX_MARKERS_PER_BLOCK ((1U << 31) - 1U)
/// List of marker types to be used in X() macro.
///
/// @ingroup BREADCRUMBS
#define FFX_BREADCRUMBS_MARKER_LIST \
X(BEGIN_EVENT) \
X(BEGIN_QUERY) \
X(CLEAR_DEPTH_STENCIL) \
X(CLEAR_RENDER_TARGET) \
X(CLEAR_STATE) \
X(CLEAR_UNORDERED_ACCESS_FLOAT) \
X(CLEAR_UNORDERED_ACCESS_UINT) \
X(CLOSE) \
X(COPY_BUFFER_REGION) \
X(COPY_RESOURCE) \
X(COPY_TEXTURE_REGION) \
X(COPY_TILES) \
X(DISCARD_RESOURCE) \
X(DISPATCH) \
X(DRAW_INDEXED_INSTANCED) \
X(DRAW_INSTANCED) \
X(END_EVENT) \
X(END_QUERY) \
X(EXECUTE_BUNDLE) \
X(EXECUTE_INDIRECT) \
X(RESET) \
X(RESOLVE_QUERY_DATA) \
X(RESOLVE_SUBRESOURCE) \
X(RESOURCE_BARRIER) \
X(SET_COMPUTE_ROOT_SIGNATURE) \
X(SET_DESCRIPTORS_HEAP) \
X(SET_GRAPHICS_ROOT_SIGNATURE) \
X(SET_PIPELINE_STATE) \
X(SET_PREDICATION) \
X(ATOMIC_COPY_BUFFER_UINT) \
X(ATOMIC_COPY_BUFFER_UINT64) \
X(RESOLVE_SUBRESOURCE_REGION) \
X(SET_SAMPLE_POSITION) \
X(SET_VIEW_INSTANCE_MASK) \
X(WRITE_BUFFER_IMMEDIATE) \
X(SET_PROTECTED_RESOURCE_SESSION) \
X(BEGIN_RENDER_PASS) \
X(BUILD_RAY_TRACING_ACCELERATION_STRUCTURE) \
X(COPY_RAY_TRACING_ACCELERATION_STRUCTURE) \
X(DISPATCH_RAYS) \
X(EMIT_RAY_TRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO) \
X(END_RENDER_PASS) \
X(EXECUTE_META_COMMANDS) \
X(INITIALIZE_META_COMMANDS) \
X(SET_RAY_TRACING_STATE) \
X(SET_SHADING_RATE) \
X(SET_SHADING_RATE_IMAGE) \
X(BEGIN_CONDITIONAL_RENDERING_EXT) \
X(BEGIN_DEBUG_UTILS_LABEL_EXT) \
X(BEGIN_QUERY_INDEXED_EXT) \
X(BEGIN_RENDER_PASS_2) \
X(BEGIN_TRANSFORM_FEEDBACK_EXT) \
X(BIND_DESCRIPTOR_SETS) \
X(BIND_PIPELINES) \
X(BIND_SHADING_RATE_IMAGE_NV) \
X(BLIT_IMAGE) \
X(BUILD_ACCELERATION_STRUCTURE_NV) \
X(CLEAR_ATTACHMENTS) \
X(CLEAR_COLOR_IMAGE) \
X(CLEAR_DEPTH_STENCIL_IMAGE) \
X(COPY_ACCELERATION_STRUCTURE_NV) \
X(COPY_BUFFER) \
X(COPY_BUFFER_TO_IMAGE) \
X(COPY_IMAGE) \
X(COPY_IMAGE_TO_BUFFER) \
X(DEBUG_MARKER_BEGIN_EXT) \
X(DEBUG_MARKER_END_EXT) \
X(DEBUG_MARKER_INSERT_EXT) \
X(DISPATCH_BASE) \
X(DISPATCH_INDIRECT) \
X(DRAW) \
X(DRAW_INDEXED) \
X(DRAW_INDEXED_INDIRECT) \
X(DRAW_INDEXED_INDIRECT_COUNT) \
X(DRAW_INDIRECT) \
X(DRAW_INDIRECT_BYTE_COUNT_EXT) \
X(DRAW_INDIRECT_COUNT) \
X(DRAW_MESH_TASKS_INDIRECT_COUNT_NV) \
X(DRAW_MESH_TASKS_INDIRECT_NV) \
X(DRAW_MESH_TASKS_NV) \
X(END_CONDITIONAL_RENDERING_EXT) \
X(END_DEBUG_UTILS_LABEL_EXT) \
X(END_QUERY_INDEXED_EXT) \
X(END_RENDER_PASS_2) \
X(END_TRANSFORM_FEEDBACK_EXT) \
X(EXECUTE_COMMANDS) \
X(FILL_BUFFER) \
X(INSERT_DEBUG_UTILS_LABEL_EXT) \
X(NEXT_SUBPASS) \
X(NEXT_SUBPASS_2) \
X(PIPELINE_BARRIER) \
X(PROCESS_COMMANDS_NVX) \
X(RESERVE_SPACE_FOR_COMMANDS_NVX) \
X(RESET_EVENT) \
X(RESET_QUERY_POOL) \
X(RESOLVE_IMAGE) \
X(SET_CHECKPOINT_NV) \
X(SET_EVENT) \
X(SET_PERFORMANCE_MARKER_INTEL) \
X(SET_PERFORMANCE_OVERRIDE_INTEL) \
X(SET_PERFORMANCE_STREAM_MARKER_INTEL) \
X(SET_SAMPLE_LOCATIONS_EXT) \
X(SET_VIEWPORT_SHADING_RATE_PALETTE_NV) \
X(TRACE_RAYS_NV) \
X(UPDATE_BUFFER) \
X(WAIT_EVENTS) \
X(WRITE_ACCELERATION_STRUCTURES_PROPERTIES_NV) \
X(WRITE_BUFFER_MARKER_AMD) \
X(WRITE_BUFFER_MARKER_2_AMD) \
X(WRITE_TIMESTAMP)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of bit flags used when creating a
/// <c><i>FfxBreadcrumbsContext</i></c>. See <c><i>FfxBreadcrumbsContextDescription</i></c>.
///
/// @ingroup BREADCRUMBS
typedef enum FfxBreadcrumbsInitializationFlagBits {
FFX_BREADCRUMBS_PRINT_FINISHED_LISTS = (1<<0), ///< A bit indicating that fully finished command lists will be expanded during status printing (otherwise their entries will be collapsed).
FFX_BREADCRUMBS_PRINT_NOT_STARTED_LISTS = (1<<1), ///< A bit indicating that command lists that haven't started execution on GPU yet will be expanded during status printing (otherwise their entries will be collapsed).
FFX_BREADCRUMBS_PRINT_FINISHED_NODES = (1<<3), ///< A bit indicating that nested markers which already have finished execution will be expanded during status printing (otherwise they will merged into top level marker).
FFX_BREADCRUMBS_PRINT_NOT_STARTED_NODES = (1<<4), ///< A bit indicating that nested markers which haven't started execution yet will be expanded during status printing (otherwise they will merged into top level marker).
FFX_BREADCRUMBS_PRINT_EXTENDED_DEVICE_INFO = (1<<5), ///< A bit indicating that additional info about active GPU will be printed into output status.
FFX_BREADCRUMBS_PRINT_SKIP_DEVICE_INFO = (1<<6), ///< A bit indicating that no info about active GPU will be printed into outpus status.
FFX_BREADCRUMBS_PRINT_SKIP_PIPELINE_INFO = (1<<7), ///< A bit indicating no info about pipelines used for commands recorded between markers will be printed into output status.
FFX_BREADCRUMBS_ENABLE_THREAD_SYNCHRONIZATION = (1<<8), ///< A bit indicating if internal synchronization should be applied (when using Breadcrumbs concurrently from multiple threads).
} FfxBreadcrumbsInitializationFlagBits;
/// Type of currently recorded marker, purely informational.
///
/// based on available methods of `ID3D12GraphicsCommandListX`, values of `D3D12_AUTO_BREADCRUMB_OP` and Vulkan `vkCmd*()` functions.
/// When using <c><i>FFX_BREADCRUMBS_MARKER_PASS</i></c> it is required to supply custom name for recording this type of marker. Otherwise it can
/// be left out as <c><i>NULL</i></c> and the Breadcrumbs will use default tag for this marker. It can be useful when recording multiple similar
/// commands in a row. Breadcrumbs will automatically add numbering to them so it's not needed to create your own numbered dynamic string.
///
/// @ingroup BREADCRUMBS
typedef enum FfxBreadcrumbsMarkerType {
FFX_BREADCRUMBS_MARKER_PASS, ///< Marker for grouping sets of commands. It is required to supply custom name for this type.
#define X(marker) FFX_BREADCRUMBS_MARKER_##marker,
FFX_BREADCRUMBS_MARKER_LIST
#undef X
} FfxBreadcrumbsMarkerType;
/// A structure encapsulating the parameters required to initialize FidelityFX Breadcrumbs.
///
/// @ingroup BREADCRUMBS
typedef struct FfxBreadcrumbsContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxBreadcrumbsInitializationFlagBits</i></c>.
uint32_t frameHistoryLength; ///< Number of frames to records markers for. Have to be larger than 0.
uint32_t maxMarkersPerMemoryBlock; ///< Controls the number of markers saved in single memory block. Have to be in range of [1..<c><i>FFX_BREADCRUMBS_MAX_MARKERS_PER_BLOCK</i></c>].
uint32_t usedGpuQueuesCount; ///< Number of entries in <c><i>pUsedGpuQueues</i></c>. Have to be larger than 0.
uint32_t* pUsedGpuQueues; ///< Pointer to an array of unique indices representing GPU queues used for command lists used with AMD FidelityFX Breadcrumbs Library.
FfxAllocationCallbacks allocCallbacks; ///< Callbacks for managing memory in the library.
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX SDK.
} FfxBreadcrumbsContextDescription;
/// Wrapper for custom Breadcrumbs name tags with indicator whether to perform copy on them.
///
/// When custom name is supplied <c><i>isNameExternallyOwned</i></c> field controls whether to perform copy on the string.
/// If string memory is managed by the application (ex. static string) the copy can be omitted to save memory.
///
/// @ingroup BREADCRUMBS
typedef struct FfxBreadcrumbsNameTag
{
const char* pName; ///< Custom name for the object. By default optional, can be left to <c><i>NULL</i></c>.
bool isNameExternallyOwned; ///< Controls if AMD FidelityFX Breadcrumbs Library should copy a custom name with backed-up memory.
} FfxBreadcrumbsNameTag;
/// Description for new command list to be enabled for writing AMD FidelityFX Breadcrumbs Library markers.
///
/// @ingroup BREADCRUMBS
typedef struct FfxBreadcrumbsCommandListDescription {
FfxCommandList commandList; ///< Handle to the command list that will be used with breadcrumbs operations.
uint32_t queueType; ///< Type of queue that list is used on.
FfxBreadcrumbsNameTag name; ///< Custom name for the command list.
FfxPipeline pipeline; ///< Optional pipeline state to associate with newly registered command list (can be set later).
uint16_t submissionIndex; ///< Information about submit number that command list is sent to GPU. Purely informational to help in analysing output later.
} FfxBreadcrumbsCommandListDescription;
/// Description for pipeline state that will be used to tag breadcrumbs markers.
///
/// @ingroup BREADCRUMBS
typedef struct FfxBreadcrumbsPipelineStateDescription
{
FfxPipeline pipeline; ///< Pipeline state that will be associated with set of Breadcrumbs markers.
FfxBreadcrumbsNameTag name; ///< Custom name for the pipeline state.
FfxBreadcrumbsNameTag vertexShader; ///< Name of used Vertex Shader. Part of classic geometry processing pipeline, cannot be set together with compute, ray tracing or new mesh processing pipeline.
FfxBreadcrumbsNameTag hullShader; ///< Name of used Hull Shader. Part of classic geometry processing pipeline, cannot be set together with compute, ray tracing or new mesh processing pipeline.
FfxBreadcrumbsNameTag domainShader; ///< Name of used Domain Shader. Part of classic geometry processing pipeline, cannot be set together with compute, ray tracing or new mesh processing pipeline.
FfxBreadcrumbsNameTag geometryShader; ///< Name of used Geometry Shader. Part of classic geometry processing pipeline, cannot be set together with compute, ray tracing or new mesh processing pipeline.
FfxBreadcrumbsNameTag meshShader; ///< Name of used Mesh Shader. Part of new mesh processing pipeline, cannot be set together with compute, ray tracing or classic geometry processing pipeline.
FfxBreadcrumbsNameTag amplificationShader; ///< Name of used Amplification Shader. Part of new mesh processing pipeline, cannot be set together with compute, ray tracing or classic geometry processing pipeline.
FfxBreadcrumbsNameTag pixelShader; ///< Name of used Pixel Shader. Cannot be set together with <c><i>computeShader</i></c> or <c><i>rayTracingShader</i></c>.
FfxBreadcrumbsNameTag computeShader; ///< Name of used Compute Shader. Have to be set exclusively to other shader names (indicates compute pipeline).
FfxBreadcrumbsNameTag rayTracingShader; ///< Name of used Ray Tracing Shader. Have to be set exclusively to other shader names (indicates ray tracing pipeline).
} FfxBreadcrumbsPipelineStateDescription;
/// Output with current AMD FidelityFX Breadcrumbs Library markers log for post-mortem analysis.
///
/// @ingroup BREADCRUMBS
typedef struct FfxBreadcrumbsMarkersStatus
{
size_t bufferSize; ///< Size of the status buffer.
char* pBuffer; ///< UTF-8 encoded buffer with log about markers execution. Have to be released with <c><i>FFX_FREE</i></c>.
} FfxBreadcrumbsMarkersStatus;
/// A structure encapsulating the FidelityFX Breadcrumbs context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by AMD FidelityFX Breadcrumbs Library.
///
/// The <c><i>FfxBreadcrumbsContext</i></c> object should have a lifetime matching
/// your use of Breadcrumbs. Before destroying the Breadcrumbs context care should be taken
/// to ensure the GPU is not accessing the resources created or used by Breadcrumbs.
/// It is therefore recommended that the GPU is idle before destroying the
/// Breadcrumbs context.
///
/// @ingroup BREADCRUMBS
typedef struct FfxBreadcrumbsContext
{
uint32_t data[FFX_BREADCRUMBS_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxBreadcrumbsContext;
/// Create a FidelityFX Breadcrumbs context from the parameters
/// programmed to the <c><i>FfxBreadcrumbsContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the Breadcrumbs
/// API, and is responsible for the management of the internal buffers used
/// by the Breadcrumbs algorithm. For each provided queue there will be created
/// a buffer that will hold contents of the saved markers, awaiting for retrieval
/// per call to <c><i>ffxBreadcrumbsPrintStatus()</i></c>
///
/// When choosing the number of frames to save markers for,
/// specified in the <c><i>frameHistoryLength</i></c> field of
/// <c><i>FfxBreadcrumbsContextDescription</i></c>, typically can be set to the number of
/// frames in flight in the application, but for longer history it can be increased.
///
/// Buffers for markers are allocated at fixed size, allowing for certain
/// number of markers to be saved in them. The size of this buffers are
/// determined by <c><i>maxMarkersPerMemoryBlock</i></c> field of
/// <c><i>FfxBreadcrumbsContextDescription</i></c>. When needed new ones are created but to avoid
/// multiple allocations you can estimate how many markers will be used in single frame.
///
/// The <c><i>FfxBreadcrumbsContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded. To destroy the Breadcrumbs context
/// you should call <c><i>ffxBreadcrumbsContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxBreadcrumbsContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>pContext</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxBreadcrumbsContextDescription.backendInterface</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsContextCreate(FfxBreadcrumbsContext* pContext, const FfxBreadcrumbsContextDescription* pContextDescription);
/// Destroy the FidelityFX Breadcrumbs context.
///
/// Should always be called from a single thread for same context.
///
/// @param [out] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>pContext</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsContextDestroy(FfxBreadcrumbsContext* pContext);
/// Begins new frame of execution for FidelityFX Breadcrumbs.
///
/// Should always be called from a single thread for same context.
///
/// @param [in] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>pContext</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsStartFrame(FfxBreadcrumbsContext* pContext);
/// Register new command list for current frame FidelityFX Breadcrumbs operations.
///
/// After call to <c><i>ffxBreadcrumbsStartFrame()</i></c> every previously used list has to be registered again.
///
/// @param [in] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure.
/// @param [in] pCommandListDescription A pointer to a <c><i>FfxBreadcrumbsCommandListDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>pContext</i></c> or <c><i>pCommandListDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT The operation failed because given command list has been already registered.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsRegisterCommandList(FfxBreadcrumbsContext* pContext, const FfxBreadcrumbsCommandListDescription* pCommandListDescription);
/// Register new pipeline state to associate later with FidelityFX Breadcrumbs operations.
///
/// Information about pipeline is preserved across frames so only single call after creation of pipeline is needed.
///
/// @param [in] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure.
/// @param [in] pPipelineDescription A pointer to a <c><i>FfxBreadcrumbsPipelineStateDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>pContext</i></c> or <c><i>pPipelineDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT The operation failed because given pipeline has been already registered or <c><i>pPipelineDescription</i></c> contains incorrect data.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsRegisterPipeline(FfxBreadcrumbsContext* pContext, const FfxBreadcrumbsPipelineStateDescription* pPipelineDescription);
/// Associate specific pipeline state with following FidelityFX Breadcrumbs markers.
///
/// When recorded commands use specific pipelines you can save this information, associating said pipelines
/// with recorded markers, so later on additional information can be displayed when using <c><i>ffxBreadcrumbsPrintStatus()</i></c>.
/// To reset currently used pipeline just pass <c><i>NULL</i></c> as <c><i>pipeline</i></c> param.
///
/// @param [in] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure.
/// @param [in] commandList Previously registered command list.
/// @param [in] pipeline Previously registered pipeline.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>context</i></c> or <c><i>commandList</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT The operation failed because given pipeline or command list has not been registered yet.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsSetPipeline(FfxBreadcrumbsContext* pContext, FfxCommandList commandList, FfxPipeline pipeline);
/// Begin new FidelityFX Breadcrumbs marker section.
///
/// New section has to be ended with <c><i>ffxBreadcrumbsEndMarker()</i></c>
/// but multiple <c><i>ffxBreadcrumbsBeginMarker()</i></c> nesting calls are possible.
///
/// @param [in] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure.
/// @param [in] commandList Previously registered command list.
/// @param [in] type Type of the marker section.
/// @param [in] pName Custom name for the marker section. Have to contain correct string if <c><i>type</i></c> is <c><i>FFX_BREADCRUMBS_MARKER_PASS()</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>pContext</i></c> or <c><i>pName</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT The operation failed because given command list has not been registered yet or <c><i>pName</i></c> doesn't contain correct string.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsBeginMarker(FfxBreadcrumbsContext* pContext, FfxCommandList commandList, FfxBreadcrumbsMarkerType type, const FfxBreadcrumbsNameTag* pName);
/// End FidelityFX Breadcrumbs marker section.
///
/// Has to be preceeded by <c><i>ffxBreadcrumbsBeginMarker()</i></c>.
///
/// @param [in] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure.
/// @param [in] commandList Previously registered command list.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>pContext</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT The operation failed because given command list has not been registered yet.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsEndMarker(FfxBreadcrumbsContext* pContext, FfxCommandList commandList);
/// Gather information about current FidelityFX Breadcrumbs markers status.
///
/// After receiving device lost error on GPU you can use this method to print post-mortem log of markers execution
/// to determine which commands in which frame were in flight during the crash.
/// Should always be called from a single thread.
///
/// @param [in] pContext A pointer to a <c><i>FfxBreadcrumbsContext</i></c> structure.
/// @param [out] pMarkersStatus Buffer with post-mortem log of Breadcrumbs markers.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>pContext</i></c> or <c><i>pMarkersStatus</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup BREADCRUMBS
FFX_API FfxErrorCode ffxBreadcrumbsPrintStatus(FfxBreadcrumbsContext* pContext, FfxBreadcrumbsMarkersStatus* pMarkersStatus);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup BREADCRUMBS
FFX_API FfxVersionNumber ffxBreadcrumbsGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,339 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <FidelityFX/host/ffx_brixelizer_raw.h>
/// The size of the context specified in 32bit values.
///
/// @ingroup Brixelizer
#define FFX_BRIXELIZER_CONTEXT_SIZE (5938838)
/// The size of the update description specified in 32bit values.
///
/// @ingroup Brixelizer
#define FFX_BRIXELIZER_UPDATE_DESCRIPTION_SIZE 2099376
#ifdef __cplusplus
extern "C" {
#endif
/// A structure encapsulating the FidelityFX Brixelizer context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by Brixelizer.
///
/// The <c><i>FfxBrixelizerContext</i></c> object should have a lifetime matching
/// your use of Brixelizer. Before destroying the Brixelizer context care
/// should be taken to ensure the GPU is not accessing the resources created
/// or used by Brixelizer. It is therefore recommended that the GPU is idle
/// before destroying the Brixelizer context.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerContext {
uint32_t data[FFX_BRIXELIZER_CONTEXT_SIZE];
} FfxBrixelizerContext;
/// A structure representing an axis aligned bounding box for use with Brixelizer.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerAABB {
float min[3]; ///< The minimum bounds of the AABB.
float max[3]; ///< The maximum bounds of the AABB.
} FfxBrixelizerAABB;
/// Flags used for cascade creation. A cascade may be specified
/// as having static geometry, dynamic geometry, or both by combining these flags.
///
/// @ingroup Brixelizer
typedef enum FfxBrixelizerCascadeFlag {
FFX_BRIXELIZER_CASCADE_STATIC = (1 << 0),
FFX_BRIXELIZER_CASCADE_DYNAMIC = (1 << 1),
} FfxBrixelizerCascadeFlag;
/// A structure encapsulating the parameters for cascade creation.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerCascadeDescription {
FfxBrixelizerCascadeFlag flags; ///< Flags for cascade creation. See <c><i>FfxBrixelizerCascadeFlag</i></c>.
float voxelSize; ///< The edge size of voxels in world space for the cascade.
} FfxBrixelizerCascadeDescription;
/// A structure encapsulating the parameters for creating a Brixelizer context.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerContextDescription {
float sdfCenter[3]; ///< The point in world space around which to center the cascades.
uint32_t numCascades; ///< The number of cascades managed by the Brixelizer context.
FfxBrixelizerContextFlags flags; ///< A combination of <c><i>FfxBrixelizerContextFlags</i></c> specifying options for the context.
FfxBrixelizerCascadeDescription cascadeDescs[FFX_BRIXELIZER_MAX_CASCADES]; ///< Parameters describing each of the cascades, see <c><i>FfxBrixelizerCascadeDescription</i></c>.
FfxInterface backendInterface; ///< An implementation of the FidelityFX backend for use with Brixelizer.
} FfxBrixelizerContextDescription;
/// Flags used for setting which AABBs to draw in a debug visualization of Brixelizer
///
/// @ingroup Brixelizer
typedef enum FfxBrixelizerPopulateDebugAABBsFlags {
FFX_BRIXELIZER_POPULATE_AABBS_NONE = 0, ///< Draw no AABBs.
FFX_BRIXELIZER_POPULATE_AABBS_STATIC_INSTANCES = 1 << 0, ///< Draw AABBs for all static instances.
FFX_BRIXELIZER_POPULATE_AABBS_DYNAMIC_INSTANCES = 1 << 1, ///< Draw AABBs for all dynamic instances.
FFX_BRIXELIZER_POPULATE_AABBS_INSTANCES = FFX_BRIXELIZER_POPULATE_AABBS_STATIC_INSTANCES | FFX_BRIXELIZER_POPULATE_AABBS_DYNAMIC_INSTANCES, ///< Draw AABBs for all instances.
FFX_BRIXELIZER_POPULATE_AABBS_CASCADE_AABBS = 1 << 2, ///< Draw AABBs for all cascades.
} FfxBrixelizerPopulateDebugAABBsFlags;
/// A structure containing the statistics for a Brixelizer context readable after an update of the Brixelizer API.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerContextStats {
uint32_t brickAllocationsAttempted; ///< Total number of brick allocations attempted this frame.
uint32_t brickAllocationsSucceeded; ///< Total number of brick allocations succeeded this frame.
uint32_t bricksCleared; ///< Total number of bricks cleared in SDF atlas at the beginning of this frame.
uint32_t bricksMerged; ///< Total number of bricks merged this frame.
uint32_t freeBricks; ///< The number of free bricks in the Brixelizer context.
} FfxBrixelizerContextStats;
/// A structure containing the statistics for a Brixelizer cascade readable after an update of the Brixelizer API.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerCascadeStats {
uint32_t trianglesAllocated; ///< The number of triangle allocations that were attempted to the cascade in a given frame.
uint32_t referencesAllocated; ///< The number of reference allocations that were attempted to the cascade in a given frame.
uint32_t bricksAllocated; ///< The number of brick allocations that were attempted to the cascade in a given frame.
} FfxBrixelizerCascadeStats;
/// A structure containing the statistics readable after an update of the Brixelizer API.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerStats {
uint32_t cascadeIndex; ///< The index of the cascade that the statisticss have been collected for.
FfxBrixelizerCascadeStats staticCascadeStats; ///< The statistics for the static cascade.
FfxBrixelizerCascadeStats dynamicCascadeStats; ///< The statistics for the dynamic cascade.
FfxBrixelizerContextStats contextStats; ///< The statistics for the Brixelizer context.
} FfxBrixelizerStats;
/// A structure encapsulating the parameters used for computing an update by the
/// Brixelizer context.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerUpdateDescription {
FfxBrixelizerResources resources; ///< Structure containing all resources to be used by the Brixelizer context.
uint32_t frameIndex; ///< The index of the current frame.
float sdfCenter[3]; ///< The center of the cascades.
FfxBrixelizerPopulateDebugAABBsFlags populateDebugAABBsFlags; ///< Flags determining which AABBs to draw in a debug visualization. See <c><i>FfxBrixelizerPopulateDebugAABBsFlag</i></c>.
FfxBrixelizerDebugVisualizationDescription *debugVisualizationDesc; ///< An optional debug visualization description. If this parameter is set to <c><i>NULL</i></c> no debug visualization is drawn.
uint32_t maxReferences; ///< The maximum number of triangle voxel references to be stored in the update.
uint32_t triangleSwapSize; ///< The size of the swap space available to be used for storing triangles in the update.
uint32_t maxBricksPerBake; ///< The maximum number of bricks to be updated.
size_t *outScratchBufferSize; ///< An optional pointer to a <c><i>size_t</i></c> to receive the size of the GPU scratch buffer needed to process the update.
FfxBrixelizerStats *outStats; ///< An optional pointer to an <c><i>FfxBrixelizerStats</i></c> struct to receive statistics for the update. Note, stats read back after a call to update do not correspond to the same frame that the stats were requested, as reading of stats requires readback from GPU buffers which is performed with a delay.
} FfxBrixelizerUpdateDescription;
/// A structure generated by Brixelizer from an <c><i>FfxBrixelizerUpdateDescription</i></c> structure
/// used for storing parameters necessary for an update with the underlying raw Brixelizer API.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerBakedUpdateDescription {
uint32_t data[FFX_BRIXELIZER_UPDATE_DESCRIPTION_SIZE];
} FfxBrixelizerBakedUpdateDescription;
/// Flags used for specifying instance properties.
///
/// @ingroup Brixelizer
typedef enum FfxBrixelizerInstanceFlags {
FFX_BRIXELIZER_INSTANCE_FLAG_NONE = 0, ///< No instance flags set.
FFX_BRIXELIZER_INSTANCE_FLAG_DYNAMIC = 1 << 0, ///< This flag is set for any instance which should be added to the dynamic cascade. Indicates that this instance will be resubmitted every frame.
} FfxBrixelizerInstanceFlags;
/// A structure encapsulating the parameters necessary to create an instance with Brixelizer.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerInstanceDescription {
uint32_t maxCascade; ///< The index of the highest cascade this instance will be submitted to. This helps avoid submitting many small objects to least detailed cascades.
FfxBrixelizerAABB aabb; ///< An AABB surrounding the instance.
FfxFloat32x3x4 transform; ///< A transform of the instance into world space. The transform is in row major order.
FfxIndexFormat indexFormat; ///< The format of the index buffer. Accepted formats are FFX_INDEX_UINT16 or FFX_INDEX_UINT32.
uint32_t indexBuffer; ///< The index of the index buffer set with ffxBrixelizerContextSetBuffer.
uint32_t indexBufferOffset; ///< An offset into the index buffer.
uint32_t triangleCount; ///< The count of triangles in the index buffer.
uint32_t vertexBuffer; ///< The index of the vertex buffer set with ffxBrixelizerContextSetBuffer.
uint32_t vertexStride; ///< The stride of the vertex buffer in bytes.
uint32_t vertexBufferOffset; ///< An offset into the vertex buffer.
uint32_t vertexCount; ///< The count of vertices in the vertex buffer.
FfxSurfaceFormat vertexFormat; ///< The format of vertices in the vertex buffer. Accepted values are FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT and FFX_SURFACE_FORMAT_R32G32B32_FLOAT.
FfxBrixelizerInstanceFlags flags; ///< Flags specifying properties of the instance. See <c><i>FfxBrixelizerInstanceFlags</i></c>.
FfxBrixelizerInstanceID *outInstanceID; ///< A pointer to an <c><i>FfxBrixelizerInstanceID</i></c> storing the ID of the created instance.
} FfxBrixelizerInstanceDescription;
/// Get the size in bytes needed for an <c><i>FfxBrixelizerContext</i></c> struct.
/// Note that this function is provided for consistency, and the size of the
/// <c><i>FfxBrixelizerContext</i></c> is a known compile time value which can be
/// obtained using <c><i>sizeof(FfxBrixelizerContext)</i></c>.
///
/// @return The size in bytes of an <c><i>FfxBrixelizerContext</i></c> struct.
///
/// @ingroup Brixelizer
inline size_t ffxBrixelizerGetContextSize()
{
return sizeof(FfxBrixelizerContext);
}
/// Create a FidelityFX Brixelizer context from the parameters
/// specified to the <c><i>FfxBrixelizerContextDesc</i></c> struct.
///
/// The context structure is the main object used to interact with the Brixelizer
/// API, and is responsible for the management of the internal resources used by the
/// Brixelizer algorithm. When this API is called, multiple calls will be made via
/// the pointers contained in the <b><i>backendInterface</i></b> structure. This
/// backend will attempt to retrieve the device capabilities, and create the internal
/// resources, and pipelines required by Brixelizer.
///
/// Depending on the parameters passed in via the <b><i>contextDescription</b></i> a
/// different set of resources and pipelines may be requested by the callback functions.
///
/// The <c><i>FfxBrixelizerContext</i></c> should be destroyed when use of it is completed.
/// To destroy the context you should call <c><i>ffxBrixelizerContextDestroy</i></c>.
///
/// @param [in] desc An <c><i>FfxBrixelizerContextDescription</i></c> structure with the parameters for context creation.
/// @param [out] outContext An <c><i>FfxBrixelizerContext</i></c> structure for receiving the initialized Brixelizer context.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerContextCreate(const FfxBrixelizerContextDescription* desc, FfxBrixelizerContext* outContext);
/// Delete the Brixelizer context associated with the <c><i>FfxBrixelizerContext</i></c> struct.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerContextDestroy(FfxBrixelizerContext* context);
/// Fill in an <c><i>FfxBrixelizerContextInfo</i></c> struct for necessary for updating a constant buffer for use
/// by Brixelizer when ray marching.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
/// @param [out] contextInfo An <c><i>FfxBrixelizerContextInfo</i></c> struct to be filled.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerGetContextInfo(FfxBrixelizerContext* context, FfxBrixelizerContextInfo* contextInfo);
/// Build an <c><i>FfxBrixelizerBakedUpdateDescription</i></c> struct from an <c><i>FfxBrixelizerUpdateDescription</i></c> struct
/// for use in doing a Brixelizer update.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
/// @param [in] desc An <c><i>FfxBrixelizerUpdateDescription</i></c> struct containing the parameters for the update.
/// @param [out] outDesc An <c><i>FfxBrixelizerBakedUpdateDescription</i></c> struct to be filled in.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerBakeUpdate(FfxBrixelizerContext* context, const FfxBrixelizerUpdateDescription* desc, FfxBrixelizerBakedUpdateDescription* outDesc);
/// Perform an update of Brixelizer, recording GPU commands to a command list.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
/// @param [in] desc An <c><i>FfxBrixelizerBakedUpdateDescription</i></c> describing the update to compute.
/// @param [out] scratchBuffer An <c><i>FfxResource</i></c> to be used as scratch space by the update.
/// @param [out] commandList An <c><i>FfxCommandList</i></c> to write GPU commands to.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerUpdate(FfxBrixelizerContext* context, FfxBrixelizerBakedUpdateDescription* desc, FfxResource scratchBuffer, FfxCommandList commandList);
/// Register a vertex or index buffer to use with Brixelizer.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
/// @param [in] buffer An <c><i>FfxResource</i></c> of the vertex or index buffer.
/// @param [out] index The index of the registered buffer.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRegisterBuffers(FfxBrixelizerContext* context, const FfxBrixelizerBufferDescription* bufferDescs, uint32_t numBufferDescs);
/// Unregister a previously registered vertex or index buffer.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
/// @param [in] index The index of the buffer to unregister.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerUnregisterBuffers(FfxBrixelizerContext* context, const uint32_t* indices, uint32_t numIndices);
/// Create a static instance for a Brixelizer context.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
/// @param [in] descs An array of <c><i>FfxBrixelizerInstanceDescription</i></c> structs with the parameters for instance creation.
/// @param [in] numDescs The number of entries in the array passed in by <c><i>descs</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerCreateInstances(FfxBrixelizerContext* context, const FfxBrixelizerInstanceDescription* descs, uint32_t numDescs);
/// Delete a static instance from a Brixelizer context.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
/// @param [in] instanceIDs An array of <c><i>FfxBrixelizerInstanceID</i></c>s corresponding to instances to be destroyed.
/// @param [in] numInstnaceIDs The number of elements in the array passed in by <c><i>instanceIDs</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerDeleteInstances(FfxBrixelizerContext* context, const FfxBrixelizerInstanceID* instanceIDs, uint32_t numInstanceIDs);
/// Get a pointer to the underlying Brixelizer raw context from a Brixelizer context.
///
/// @param [inout] context An <c><i>FfxBrixelizerContext</i></c> containing the Brixelizer context.
/// @param [out] outContext A <c><i>FfxBrixelizerRawContext</i></c> representing the underlying Brixelizer raw context.
///
/// @return
/// FFX_ERROR_INVALID_POINTER The pointer given was invalid.
/// @return
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerGetRawContext(FfxBrixelizerContext* context, FfxBrixelizerRawContext** outContext);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,675 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
// Include the interface for the backend of the Brixelizer API.
#include <FidelityFX/host/ffx_interface.h>
#include <FidelityFX/gpu/brixelizer/ffx_brixelizer_host_gpu_shared.h>
/// FidelityFX Brixelizer major version.
///
/// @ingroup Brixelizer
#define FFX_BRIXELIZER_VERSION_MAJOR (1)
/// FidelityFX Brixelizer minor version.
///
/// @ingroup Brixelizer
#define FFX_BRIXELIZER_VERSION_MINOR (0)
/// FidelityFX Brixelizer patch version.
///
/// @ingroup Brixelizer
#define FFX_BRIXELIZER_VERSION_PATCH (0)
/// FidelityFX Brixelizer context count
///
/// Defines the number of internal effect contexts required by Brixelizer
///
/// @ingroup Brixelizer
#define FFX_BRIXELIZER_CONTEXT_COUNT 1
/// The size of the raw context specified in 32bit values.
///
/// @ingroup Brixelizer
#define FFX_BRIXELIZER_RAW_CONTEXT_SIZE (2924058)
#ifdef __cplusplus
extern "C" {
#endif
/// An enumeration of all the passes which constitute the Brixelizer algorithm.
///
/// Brixelizer is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxBrixelizerScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxBrixelizerPass</i></c>. For a
/// more comprehensive description of each pass, please refer to the Brixelizer
/// reference documentation.
///
/// @ingroup Brixelizer
typedef enum FfxBrixelizerPass
{
FFX_BRIXELIZER_PASS_CONTEXT_CLEAR_COUNTERS,
FFX_BRIXELIZER_PASS_CONTEXT_COLLECT_CLEAR_BRICKS,
FFX_BRIXELIZER_PASS_CONTEXT_PREPARE_CLEAR_BRICKS,
FFX_BRIXELIZER_PASS_CONTEXT_CLEAR_BRICK,
FFX_BRIXELIZER_PASS_CONTEXT_COLLECT_DIRTY_BRICKS,
FFX_BRIXELIZER_PASS_CONTEXT_PREPARE_EIKONAL_ARGS,
FFX_BRIXELIZER_PASS_CONTEXT_EIKONAL,
FFX_BRIXELIZER_PASS_CONTEXT_MERGE_CASCADES,
FFX_BRIXELIZER_PASS_CONTEXT_PREPARE_MERGE_BRICKS_ARGS,
FFX_BRIXELIZER_PASS_CONTEXT_MERGE_BRICKS,
FFX_BRIXELIZER_PASS_CASCADE_CLEAR_BUILD_COUNTERS,
FFX_BRIXELIZER_PASS_CASCADE_RESET_CASCADE,
FFX_BRIXELIZER_PASS_CASCADE_SCROLL_CASCADE,
FFX_BRIXELIZER_PASS_CASCADE_CLEAR_REF_COUNTERS,
FFX_BRIXELIZER_PASS_CASCADE_CLEAR_JOB_COUNTER,
FFX_BRIXELIZER_PASS_CASCADE_INVALIDATE_JOB_AREAS,
FFX_BRIXELIZER_PASS_CASCADE_COARSE_CULLING,
FFX_BRIXELIZER_PASS_CASCADE_SCAN_JOBS,
FFX_BRIXELIZER_PASS_CASCADE_VOXELIZE,
FFX_BRIXELIZER_PASS_CASCADE_SCAN_REFERENCES,
FFX_BRIXELIZER_PASS_CASCADE_COMPACT_REFERENCES,
FFX_BRIXELIZER_PASS_CASCADE_CLEAR_BRICK_STORAGE,
FFX_BRIXELIZER_PASS_CASCADE_EMIT_SDF,
FFX_BRIXELIZER_PASS_CASCADE_COMPRESS_BRICK,
FFX_BRIXELIZER_PASS_CASCADE_INITIALIZE_CASCADE,
FFX_BRIXELIZER_PASS_CASCADE_MARK_UNINITIALIZED,
FFX_BRIXELIZER_PASS_CASCADE_BUILD_TREE_AABB,
FFX_BRIXELIZER_PASS_CASCADE_FREE_CASCADE,
FFX_BRIXELIZER_PASS_DEBUG_VISUALIZATION,
FFX_BRIXELIZER_PASS_DEBUG_INSTANCE_AABBS,
FFX_BRIXELIZER_PASS_DEBUG_AABB_TREE,
FFX_BRIXELIZER_PASS_COUNT ///< The number of passes performed by Brixelizer.
} FfxBrixelizerPass;
/// An ID value for an instance created with Brixelizer.
///
/// @ingroup Brixelizer
typedef uint32_t FfxBrixelizerInstanceID;
/// A structure representing the external resources needed for a Brixelizer cascade.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerCascadeResources
{
FfxResource aabbTree; ///< An FfxResource for storing the AABB tree of the cascade. This should be a structured buffer of size FFX_BRIXELIZER_CASCADE_AABB_TREE_SIZE and stride FFX_BRIXELIZER_CASCADE_AABB_TREE_STRIDE.
FfxResource brickMap; ///< An FfxResource for storing the brick map of the cascade. This should be a structured buffer of size FFX_BRIXELIZER_CASCADE_BRICK_MAP_SIZE and stride FFX_BRIXELIZER_CASCADE_BRICK_MAP_STRIDE.
} FfxBrixelizerCascadeResources;
/// A structure representing all external resources for use with Brixelizer.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerResources
{
FfxResource sdfAtlas; ///< An FfxResource for storing the SDF atlas. This should be a 512x512x512 3D texture of 8-bit unorm values.
FfxResource brickAABBs; ///< An FfxResource for storing the brick AABBs. This should be a structured buffer containing 64*64*64 32-bit values.
FfxBrixelizerCascadeResources cascadeResources[FFX_BRIXELIZER_MAX_CASCADES]; ///< Cascade resources.
} FfxBrixelizerResources;
/// A structure encapsulating the parameters necessary to register a buffer with
/// the Brixelizer API.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerBufferDescription {
FfxResource buffer; ///< An <c><i>FfxResource</i></c> of the buffer.
uint32_t *outIndex; ///< A pointer to a <c><i>uint32_t</i></c> to receive the index assigned to the buffer.
} FfxBrixelizerBufferDescription;
/// Flags used for specifying debug drawing of AABBs.
///
/// @ingroup Brixelizer
typedef enum FfxBrixelizerCascadeDebugAABB {
FFX_BRIXELIZER_CASCADE_DEBUG_AABB_NONE,
FFX_BRIXELIZER_CASCADE_DEBUG_AABB_BOUNDING_BOX,
FFX_BRIXELIZER_CASCADE_DEBUG_AABB_AABB_TREE,
} FfxBrixelizerCascadeDebugAABB;
/// A structure encapsulating the parameters for drawing a debug visualization.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerDebugVisualizationDescription
{
float inverseViewMatrix[16]; ///< Inverse view matrix for the scene in row major order.
float inverseProjectionMatrix[16]; ///< Inverse projection matrix for the scene in row major order.
FfxBrixelizerTraceDebugModes debugState; ///< An FfxBrixelizerTraceDebugModes determining what kind of debug output to draw.
uint32_t startCascadeIndex; ///< The index of the most detailed cascade in the cascade chain.
uint32_t endCascadeIndex; ///< The index of the least detailed cascade in the cascade chain.
float sdfSolveEps; ///< The epsilon value used in SDF ray marching.
float tMin; ///< The tMin value for minimum ray intersection.
float tMax; ///< The tMax value for maximum ray intersection.
uint32_t renderWidth; ///< The width of the output resource.
uint32_t renderHeight; ///< The height of the output resource.
FfxResource output; ///< An FfxResource to draw the debug visualization to.
FfxCommandList commandList; ///< An FfxCommandList to write the draw commands to.
uint32_t numDebugAABBInstanceIDs; ///< The number of FfxBrixelizerInstanceIDs in the debugAABBInstanceIDs array.
const FfxBrixelizerInstanceID *debugAABBInstanceIDs; ///< An array of FfxBrixelizerInstanceIDs for instances to draw the bounding boxes of.
FfxBrixelizerCascadeDebugAABB cascadeDebugAABB[FFX_BRIXELIZER_MAX_CASCADES]; ///< An array of flags showing what AABB debug output to draw for each cascade.
} FfxBrixelizerDebugVisualizationDescription;
/// Flags for options for Brixelizer context creation.
///
/// @ingroup Brixelizer
typedef enum FfxBrixelizerContextFlags
{
FFX_BRIXELIZER_CONTEXT_FLAG_DEBUG_CONTEXT_READBACK_BUFFERS = (1 << 0), ///< Create a context with context readback buffers enabled. Needed to use <c><i>ffxBrixelizerContextGetDebugCounters</i></c>.
FFX_BRIXELIZER_CONTEXT_FLAG_DEBUG_CASCADE_READBACK_BUFFERS = (1 << 1), ///< Create a context with cascade readback buffers enabled. Needed to use <c><i>ffxBrixelizerContextGetCascadeCounters</i></c>.
FFX_BRIXELIZER_CONTEXT_FLAG_DEBUG_AABBS = (1 << 2), ///< Create a context with debug AABBs enabled.
FFX_BRIXELIZER_CONTEXT_FLAG_ALL_DEBUG = FFX_BRIXELIZER_CONTEXT_FLAG_DEBUG_CONTEXT_READBACK_BUFFERS | FFX_BRIXELIZER_CONTEXT_FLAG_DEBUG_CASCADE_READBACK_BUFFERS | FFX_BRIXELIZER_CONTEXT_FLAG_DEBUG_AABBS, ///< Create a context with all debugging features enabled.
} FfxBrixelizerContextFlags;
/// Flags used for creating Brixelizer jobs. Determines whether a job is a submission of geometry or invalidating
/// an area described by an AABB.
///
/// @ingroup Brixelizer
typedef enum FfxBrixelizerRawJobFlags {
FFX_BRIXELIZER_RAW_JOB_FLAG_NONE = 0u,
FFX_BRIXELIZER_RAW_JOB_FLAG_INVALIDATE = 1u << 2u,
} FfxBrixelizerRawJobFlags;
/// Flags used for creating Brixelizer instances.
///
/// @ingroup Brixelizer
typedef enum FfxBrixelizerRawInstanceFlags {
FFX_BRIXELIZER_RAW_INSTANCE_FLAG_NONE = 0u,
FFX_BRIXELIZER_RAW_INSTANCE_FLAG_USE_INDEXLESS_QUAD_LIST = 1u << 1u,
} FfxBrixelizerRawInstanceFlags;
/// A structure encapsulating the FidelityFX Brixelizer context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by Brixelizer.
///
/// The <c><i>FfxBrixelizerRawContext</i></c> object should have a lifetime matching
/// your use of Brixelizer. Before destroying the Brixelizer context care
/// should be taken to ensure the GPU is not accessing the resources created
/// or used by Brixelizer. It is therefore recommended that the GPU is idle
/// before destroying the Brixelizer context.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerRawContext
{
uint32_t data[FFX_BRIXELIZER_RAW_CONTEXT_SIZE];
} FfxBrixelizerRawContext;
/// A structure encapsulating the parameters for creating a Brixelizer context.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerRawContextDescription
{
size_t maxDebugAABBs; ///< The maximum number of AABBs that can be drawn in debug mode. Note to use debug AABBs the flag <c><i>FFX_BRIXELIZER_CONTEXT_FLAG</i></c> must be passed at context creation.
FfxBrixelizerContextFlags flags; ///< A combination of <c><i>FfxBrixelizerContextFlags</i></c> specifying options for the context.
FfxInterface backendInterface; ///< An FfxInterface representing the FidelityFX backend interface.
} FfxBrixelizerRawContextDescription;
/// A structure encapsulating the parameters for creating a Brixelizer cascade.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerRawCascadeDescription
{
float brickSize; ///< The edge size of a brick in world units.
float cascadeMin[3]; ///< Corner of the first brick.
uint32_t index; ///< Index of the cascade.
} FfxBrixelizerRawCascadeDescription;
/// A structure describing a Brixelizer job.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerRawJobDescription
{
float aabbMin[3]; ///< The mimimum corner of the AABB of the job.
float aabbMax[3]; ///< The maximum corner of the AABB of the job.
uint32_t flags; ///< Flags for the job (to be set from FfxBrixelizerRawJobFlags).
uint32_t instanceIdx; ///< The ID for an instance for the job.
} FfxBrixelizerRawJobDescription;
/// A structure encapsulating the parameters for updating a Brixelizer cascade.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerRawCascadeUpdateDescription
{
uint32_t maxReferences; ///< storage for triangle->voxel references
uint32_t triangleSwapSize; ///< scratch storage for triangles
uint32_t maxBricksPerBake; ///< max SDF brick baked per update
int32_t cascadeIndex; ///< Target Cascade
const FfxBrixelizerRawJobDescription *jobs; ///< A pointer to an array of jobs.
size_t numJobs; ///< The number of jobs in the array pointed to by jobs.
float cascadeMin[3]; ///< Lower corner of the first brick in world space.
int32_t clipmapOffset[3]; ///< Changing that invalidates portion of the cascade. it's an offset in the voxel->brick table.
uint32_t flags; ///< See FfxBrixelizerCascadeUpdateFlags.
} FfxBrixelizerRawCascadeUpdateDescription;
/// A structure encapsulating the parameters for an instance to be added to a
/// Brixelizer context.
///
/// @ingroup Brixelizer
typedef struct FfxBrixelizerRawInstanceDescription
{
float aabbMin[3]; ///< The minimum coordinates of an AABB surrounding the instance.
float aabbMax[3]; ///< The maximum coordinates of an AABB surrounding the instance.
FfxFloat32x3x4 transform; ///< A tranform of the instance into world space. The transform is in row major order.
FfxIndexFormat indexFormat; ///< The format of the index buffer. Accepted formats are FFX_INDEX_UINT16 or FFX_INDEX_UINT32.
uint32_t indexBuffer; ///< The index of the index buffer set with ffxBrixelizerContextSetBuffer.
uint32_t indexBufferOffset; ///< An offset into the index buffer.
uint32_t triangleCount; ///< The count of triangles in the index buffer.
uint32_t vertexBuffer; ///< The index of the vertex buffer set with ffxBrixelizerContextSetBuffer.
uint32_t vertexStride; ///< The stride of the vertex buffer in bytes.
uint32_t vertexBufferOffset; ///< An offset into the vertex buffer.
uint32_t vertexCount; ///< The count of vertices in the vertex buffer.
FfxSurfaceFormat vertexFormat; ///< The format of vertices in the vertex buffer. Accepted values are FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT and FFX_SURFACE_FORMAT_R32G32B32A32_FLOAT.
uint32_t flags; ///< Flags for the instance. See <c><i>FfxBrixelizerRawInstanceFlags</i></c>.
FfxBrixelizerInstanceID *outInstanceID; ///< A pointer to an <c><i>FfxBrixelizerInstanceID</i></c> to be filled with the instance ID assigned for the instance.
} FfxBrixelizerRawInstanceDescription;
/// Get the size in bytes needed for an <c><i>FfxBrixelizerRawContext</i></c> struct.
/// Note that this function is provided for consistency, and the size of the
/// <c><i>FfxBrixelizerRawContext</i></c> is a known compile time value which can be
/// obtained using <c><i>sizeof(FfxBrixelizerRawContext)</i></c>.
///
/// @return The size in bytes of an <c><i>FfxBrixelizerRawContext</i></c> struct.
///
/// @ingroup Brixelizer
inline size_t ffxBrixelizerRawGetContextSize()
{
return sizeof(FfxBrixelizerRawContext);
}
/// Create a FidelityFX Brixelizer context from the parameters
/// specified to the <c><i>FfxBrixelizerRawContextDescription</i></c> struct.
///
/// The context structure is the main object used to interact with the Brixelizer API,
/// and is responsible for the management of the internal resources used by the
/// Brixelizer algorithm. When this API is called, multiple calls will be made via
/// the pointers contained in the <b><i>backendInterface</i></b> structure. This
/// backend will attempt to retrieve the device capabilities, and create the internal
/// resources, and pipelines required by Brixelizer.
///
/// Depending on the parameters passed in via the <b><i>contextDescription</b></i> a
/// different set of resources and pipelines may be requested by the callback functions.
///
/// The <c><i>FfxBrixelizerRawContext</i></c> should be destroyed when use of it is completed.
/// To destroy the context you should call <c><i>ffxBrixelizerContextDestroy</i></c>.
///
/// @param [out] context A pointer to a <c><i>FfxBrixelizerRawContext</i></c> to populate.
/// @param [in] contextDescription A pointer to a <c><i>FfxBrixelizerRawContextDescription</i></c> specifying the parameters for context creation.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because <c><i>contextDescription->backendInterface</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error from the backend.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextCreate(FfxBrixelizerRawContext* context, const FfxBrixelizerRawContextDescription* contextDescription);
/// Destroy the FidelityFX Brixelizer context.
///
/// @param [out] context A pointer to a <c><i>FfxBrixelizerRawContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The <c><i>context</i></c> pointer provided was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextDestroy(FfxBrixelizerRawContext* context);
/// Get an <c><i>FfxBrixelizerContextInfo</i></c> structure with the details for <c><i>context</i></c>.
/// This call is intended to be used to fill in a constant buffer necessary for making ray
/// queries.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to receive the <c><i>FfxBrixelizerContextInfo</i></c> of.
/// @param [out] contextInfo A <c><i>FfxBrixelizerContextInfo</i></c> struct to be filled in.
///
/// @retval
/// FFX_OK The operation was successful.
/// @retval
/// FFX_ERROR_INVALID_POINTER The <c><i>context</i></c> pointer provided was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextGetInfo(FfxBrixelizerRawContext* context, FfxBrixelizerContextInfo* contextInfo);
/// Create a cascade for use with Brixelizer.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to create a cascade for.
/// @param [in] cascadeDescription A <c><i>FfxBrixelizerRawCascadeDescription</i></c> struct specifying the parameters for cascade creation.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because one of <c><i>context</i></c>, <c><i>cascadeDescription</i></c>, c><i>cascadeDescription->aabbTree</i></c> or c><i>cascadeDescription->brickMap</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation encountered an error in the backend.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextCreateCascade(FfxBrixelizerRawContext* context, const FfxBrixelizerRawCascadeDescription* cascadeDescription);
/// Destroy a cascade previously created with <c><i>ffxBrixelizerContextCreateCascade</i></c>.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to delete a cascade for.
/// @param [in] cascadeIndex The index of the cascade to delete.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextDestroyCascade(FfxBrixelizerRawContext* context, uint32_t cascadeIndex);
/// Reset a cascade previously created with <c><i>ffxBrixelizerContextCreateCascade</i></c>.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to reset a cascade for.
/// @param [in] cascadeIndex The index of the cascade to reset.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT No cascade with index <c><i>cascadeIndex</i></c> exists.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextResetCascade(FfxBrixelizerRawContext* context, uint32_t cascadeIndex);
/// Begin constructing GPU commands for updating SDF acceleration structures with Brixelizer.
/// Must be called between calls to <c><i>ffxBrixelizerContextBegin</i></c> and <c><i>ffxBrixelizerContextEnd</i></c>.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to begin a frame for.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the <c><i>FfxDevice</i></c> provided to the <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextBegin(FfxBrixelizerRawContext* context, FfxBrixelizerResources resources);
/// End construcring GPU commands for updating the SDF acceleration structures with Brixelizer.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to end a frame for.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the <c><i>FfxDevice</i></c> provided to the <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextEnd(FfxBrixelizerRawContext* context);
/// Record GPU commands to a <c><i>FfxCommandList</i></c> for updating acceleration structures with Brixelizer.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to record GPU commands from.
/// @param [out] cmdList The <c><i>FfxCommandList</i></c> to record commands to.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the <c><i>FfxDevice</i></c> provided to the <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextSubmit(FfxBrixelizerRawContext* context, FfxCommandList cmdList);
/// Get the size in bytes needed from a <c><i>FfxResource</i></c> to be used as a scratch buffer in a cascade update.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to calculate the required scratch buffer size for.
/// @param [in] cascadeUpdateDescription A <c><i>FfxBrixelizerRawCascadeUpdateDescription</i></c> struct with the parameters for the cascade update.
/// @param [out] size A <c><i>size_t</i></c> to store the required scratch buffer size to.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> or <c><i>cascadeUpdateDescription</c></i> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the <c><i>FfxDevice</i></c> provided to the <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextGetScratchMemorySize(FfxBrixelizerRawContext* context, const FfxBrixelizerRawCascadeUpdateDescription* cascadeUpdateDescription, size_t* size);
/// Update a cascade in a Brixelizer context.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to perform the cascade update on.
/// @param [in] cascadeUpdateDescription A <c><i>FfxBrixelizerRawCascadeUpdateDescription</i></c> struct with the parameters for the cascade update.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> or <c><i>cascadeUpdateDescription</c></i> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the <c><i>FfxDevice</i></c> provided to the <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextUpdateCascade(FfxBrixelizerRawContext* context, const FfxBrixelizerRawCascadeUpdateDescription* cascadeUpdateDescription);
/// Merge two cascades in a Brixelizer context.
/// Must be called between calls to <c><i>ffxBrixelizerRawContextBegin</i></c> and <c><i>ffxBrixelizerRawContextEnd</i></c>.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to merge cascades for.
/// @param [in] srcCascadeAIdx The index of the first source cascade.
/// @param [in] srcCascadeBIdx A <c><i>FfxResource</i></c> to store the required scratch buffer size to.
/// @param [in] dstCascadeIdx A <c><i>FfxResource</i></c> to store the required scratch buffer size to.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the <c><i>FfxDevice</i></c> provided to the <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextMergeCascades(FfxBrixelizerRawContext* context, uint32_t src_cascade_A_idx, uint32_t src_cascade_B_idx, uint32_t dst_cascade_idx);
/// Build an AABB tree for a cascade in a Brixelizer context.
/// Must be called between calls to <c><i>ffxBrixelizerRawContextBegin</i></c> and <c><i>ffxBrixelizerRawContextEnd</i></c>.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to build an AABB tree for.
/// @param [in] cascadeIndex The index of the cascade to build the AABB tree of.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the <c><i>FfxDevice</i></c> provided to the <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextBuildAABBTree(FfxBrixelizerRawContext* context, uint32_t cascadeIndex);
/// Create a debug visualization output of a Brixelizer context.
/// Must be called between calls to <c><i>ffxBrixelizerRawContextBegin</i></c> and <c><i>ffxBrixelizerRawContextEnd</i></c>.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to create a debug visualization for.
/// @param [in] debugVisualizationDescription A <c><i>FfxBrixelizerDebugVisualizationDescription</i></c> providing the parameters for the debug visualization.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> or <c><i>debugVisualizationDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the <c><i>FfxDevice</i></c> provided to the <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextDebugVisualization(FfxBrixelizerRawContext* context, const FfxBrixelizerDebugVisualizationDescription* debugVisualizationDescription);
/// Get the debug counters from a Brixelizer context.
/// Note to use this function the flag <c><i>FFX_BRIXELIZER_CONTEXT_FLAG_DEBUG_CONTEXT_READBACK_BUFFERS</i></c> must
/// be passed at context creation.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to read the debug counters of.
/// @param [out] debugCounters A <c><i>FfxBrixelizerDebugCounters</i></c> struct to read the debug counters to.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> or <c><i>debugCounters</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextGetDebugCounters(FfxBrixelizerRawContext* context, FfxBrixelizerDebugCounters* debugCounters);
/// Get the cascade counters from a Brixelizer context.
/// Note to use this function the flag <c><i>FFX_BRIXELIZER_CONTEXT_FLAG_DEBUG_CASCADE_READBACK_BUFFERS</i></c> must
/// be passed at context creation.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to read the cascade counters of.
/// @param [in] cascadeIndex The index of the cascade to read the cascade counters of.
/// @param [out] counters A <c><i>FfxBrixelizerScratchCounters</i></c> struct to read the cascade counters to.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> or <c><i>counters</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextGetCascadeCounters(FfxBrixelizerRawContext* context, uint32_t cascadeIndex, FfxBrixelizerScratchCounters* counters);
/// Create an instance in a Brixelizer context.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to create an instance for.
/// @param [in] instanceDescription A <c><i>FfxBrixelizerRawInstanceDescription</i></c> struct with the parameters for the instance to create.
/// @param [out] numInstanceDescriptions A <c><i>FfxBrixelizerInstanceID</i></c> to read the instance ID to.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> or <c><i>instanceDescription</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextCreateInstances(FfxBrixelizerRawContext* context, const FfxBrixelizerRawInstanceDescription* instanceDescriptions, uint32_t numInstanceDescriptions);
/// Destroy an instance in a Brixelizer context.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to delete an instance for.
/// @param [in] instanceId The <c><i>FfxBrixelizerInstanceID</i></c> of the instance to delete.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextDestroyInstances(FfxBrixelizerRawContext* context, const FfxBrixelizerInstanceID* instanceIDs, uint32_t numInstanceIDs);
/// Flush all instances added to the Brixelizer context with <c><i>ffxBrixelizerRawContextCreateInstance</i></c> to the GPU.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to flush the instances for.
/// @param [in] cmdList An <c><i>FfxCommandList</i></c> to record GPU commands to.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextFlushInstances(FfxBrixelizerRawContext* context, FfxCommandList cmdList);
/// Register a vertex or index buffer for use with Brixelizer.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to register a buffer for.
/// @param [in] buffer An <c><i>FfxResource</i></c> with the buffer to be set.
/// @param [out] index The index of the registered buffer.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextRegisterBuffers(FfxBrixelizerRawContext* context, const FfxBrixelizerBufferDescription* bufferDescs, uint32_t numBufferDescs);
/// Unregister a previously registered vertex or index buffer.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to unregister the buffer from
/// @param [in] index The index of the buffer to unregister.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextUnregisterBuffers(FfxBrixelizerRawContext* context, const uint32_t* indices, uint32_t numIndices);
/// Get the index of the recommended cascade to update given the total number of cascades and current frame.
/// Follows the pattern 0 1 0 2 0 1 0 3 0 etc. If 0 is the most detailed cascade and <c><i>maxCascades - 1</i></c>
/// is the least detailed cascade this ordering updates more detailed cascades more often.
///
/// @param [out] context The <c><i>FfxBrixelizerRawContext</i></c> to set a buffer for.
/// @param [in] scratchBuffer A <c><i>FfxResource</i></c> for use as a scratch buffer.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer
FFX_API FfxErrorCode ffxBrixelizerRawContextRegisterScratchBuffer(FfxBrixelizerRawContext* context, FfxResource scratchBuffer);
/// Get the index of the recommended cascade to update given the total number of cascades and current frame.
/// Follows the pattern 0 1 0 2 0 1 0 3 0 etc. If 0 is the most detailed cascade and <c><i>maxCascades - 1</i></c>
/// is the least detailed cascade this ordering updates more detailed cascades more often.
///
/// @param [in] frameIndex The current frame index.
/// @param [in] maxCascades The total number of cascades.
///
/// @retval The index of the cascade to update.
///
/// @ingroup Brixelizer
FFX_API uint32_t ffxBrixelizerRawGetCascadeToUpdate(uint32_t frameIndex, uint32_t maxCascades);
/// Check whether an <c><i>FfxResource</i></c> is <c><i>NULL</i></c>.
///
/// @param [in] resource An <c><i>FfxResource</i></c> to check for nullness.
///
/// @retval <c><i>true</c></i> if <c><i>resource</i></c> is <c><i>NULL</i></c> else <c><i>false</i></c>.
///
/// @ingroup Brixelizer
FFX_API bool ffxBrixelizerRawResourceIsNull(FfxResource resource);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup Brixelizer
FFX_API FfxVersionNumber ffxBrixelizerGetEffectVersion();
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,323 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
// Include the interface for the backend of the Brixelizer GI API.
#include <FidelityFX/host/ffx_interface.h>
#include <FidelityFX/host/ffx_brixelizer_raw.h>
/// FidelityFX Brixelizer GI major version.
///
/// @ingroup Brixelizer GI
#define FFX_BRIXELIZER_GI_VERSION_MAJOR (1)
/// FidelityFX Brixelizer GI minor version.
///
/// @ingroup Brixelizer GI
#define FFX_BRIXELIZER_GI_VERSION_MINOR (0)
/// FidelityFX Brixelizer GI patch version.
///
/// @ingroup Brixelizer GI
#define FFX_BRIXELIZER_GI_VERSION_PATCH (0)
/// The size of the context specified in 32bit values.
///
/// @ingroup Brixelizer GI
#define FFX_BRIXELIZER_GI_CONTEXT_SIZE (210000)
/// FidelityFX Brixelizer GI context count
///
/// Defines the number of internal effect contexts required by Brixelizer
///
/// @ingroup Brixelizer GI
#define FFX_BRIXELIZER_GI_CONTEXT_COUNT 1
#ifdef __cplusplus
extern "C" {
#endif
/// A structure encapsulating the FidelityFX Brixelizer GI context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by Brixelizer GI.
///
/// The <c><i>FfxBrixelizerGIContext</i></c> object should have a lifetime matching
/// your use of Brixelizer GI. Before destroying the Brixelizer GI context care
/// should be taken to ensure the GPU is not accessing the resources created
/// or used by Brixelizer GI. It is therefore recommended that the GPU is idle
/// before destroying the Brixelizer GI context.
///
/// @ingroup Brixelizer GI
typedef struct FfxBrixelizerGIContext
{
uint32_t data[FFX_BRIXELIZER_GI_CONTEXT_SIZE];
} FfxBrixelizerGIContext;
/// An enumeration of flag bits used when creating an <c><i>FfxBrixelizerGIContext</i></c>.
/// See <c><i>FfxBrixelizerGIContextDescription</i></c>.
///
/// @ingroup Brixelizer GI
typedef enum FfxBrixelizerGIFlags
{
FFX_BRIXELIZER_GI_FLAG_DEPTH_INVERTED = (1 << 0), ///< Indicates input resources were generated with inverted depth.
FFX_BRIXELIZER_GI_FLAG_DISABLE_SPECULAR = (1 << 1), ///< Disable specular GI.
FFX_BRIXELIZER_GI_FLAG_DISABLE_DENOISER = (1 << 2), ///< Disable denoising. Only allowed at native resolution.
} FfxBrixelizerGIFlags;
/// An enumeration of the quality modes supported by FidelityFX Brixelizer GI.
///
/// @ingroup Brixelizer GI
typedef enum FfxBrixelizerGIInternalResolution
{
FFX_BRIXELIZER_GI_INTERNAL_RESOLUTION_NATIVE, ///< Output GI at native resolution.
FFX_BRIXELIZER_GI_INTERNAL_RESOLUTION_75_PERCENT, ///< Output GI at 75% of native resolution.
FFX_BRIXELIZER_GI_INTERNAL_RESOLUTION_50_PERCENT, ///< Output GI at 50% of native resolution.
FFX_BRIXELIZER_GI_INTERNAL_RESOLUTION_25_PERCENT, ///< Output GI at 25% of native resolution.
} FfxBrixelizerGIInternalResolution;
/// A structure encapsulating the parameters used for creating an
/// <c><i>FfxBrixelizerGIContext</i></c>.
///
/// @ingroup Brixelizer GI
typedef struct FfxBrixelizerGIContextDescription
{
FfxBrixelizerGIFlags flags; ///< A bit field representings various options.
FfxBrixelizerGIInternalResolution internalResolution; ///< The scale at which Brixelizer GI will output GI at internally. The output will be internally upscaled to the specified displaySize.
FfxDimensions2D displaySize; ///< The size of the presentation resolution targeted by the upscaling process.
FfxInterface backendInterface; ///< An implementation of the FidelityFX backend for use with Brixelizer.
} FfxBrixelizerGIContextDescription;
/// A structure encapsulating the parameters used for computing a dispatch by the
/// Brixelizer GI context.
///
/// @ingroup Brixelizer GI
typedef struct FfxBrixelizerGIDispatchDescription
{
FfxFloat32x4x4 view; ///< The view matrix for the scene in row major order.
FfxFloat32x4x4 projection; ///< The projection matrix for the scene in row major order.
FfxFloat32x4x4 prevView; ///< The view matrix for the previous frame of the scene in row major order.
FfxFloat32x4x4 prevProjection; ///< The projection matrix for the scene in row major order.
FfxFloat32x3 cameraPosition; ///< A 3-dimensional vector representing the position of the camera.
FfxUInt32 startCascade; ///< The index of the start cascade for use with ray marching with Brixelizer.
FfxUInt32 endCascade; ///< The index of the end cascade for use with ray marching with Brixelizer.
FfxFloat32 rayPushoff; ///< The distance from a surface along the normal vector to offset the diffuse ray origin.
FfxFloat32 sdfSolveEps; ///< The epsilon value for ray marching to be used with Brixelizer for diffuse rays.
FfxFloat32 specularRayPushoff; ///< The distance from a surface along the normal vector to offset the specular ray origin.
FfxFloat32 specularSDFSolveEps; ///< The epsilon value for ray marching to be used with Brixelizer for specular rays.
FfxFloat32 tMin; ///< The TMin value for use with Brixelizer.
FfxFloat32 tMax; ///< The TMax value for use with Brixelizer.
FfxResource environmentMap; ///< The environment map.
FfxResource prevLitOutput; ///< The lit output from the previous frame.
FfxResource depth; ///< The input depth buffer.
FfxResource historyDepth; ///< The previous frame input depth buffer.
FfxResource normal; ///< The input normal buffer.
FfxResource historyNormal; ///< The previous frame input normal buffer.
FfxResource roughness; ///< The resource containing roughness information.
FfxResource motionVectors; ///< The input motion vectors texture.
FfxResource noiseTexture; ///< The input blue noise texture.
FfxFloat32 normalsUnpackMul; ///< A multiply factor to transform the normal to the space expected by Brixelizer GI.
FfxFloat32 normalsUnpackAdd; ///< An offset to transform the normal to the space expected by Brixelizer GI.
FfxBoolean isRoughnessPerceptual; ///< A boolean to describe the space used to store roughness in the materialParameters texture. If false, we assume roughness squared was stored in the Gbuffer.
FfxUInt32 roughnessChannel; ///< The channel to read the roughness from the roughness texture
FfxFloat32 roughnessThreshold; ///< Regions with a roughness value greater than this threshold won't spawn specular rays.
FfxFloat32 environmentMapIntensity;///< The value to scale the contribution from the environment map.
FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors.
FfxResource sdfAtlas; ///< The SDF Atlas resource used by Brixelizer.
FfxResource bricksAABBs; ///< The brick AABBs resource used by Brixelizer.
FfxResource cascadeAABBTrees[24]; ///< The cascade AABB tree resources used by Brixelizer.
FfxResource cascadeBrickMaps[24]; ///< The cascade brick map resources used by Brixelizer.
FfxResource outputDiffuseGI; ///< A texture to write the output diffuse GI calculated by Brixelizer GI.
FfxResource outputSpecularGI; ///< A texture to write the output specular GI calculated by Brixelizer GI.
FfxBrixelizerRawContext *brixelizerContext; ///< A pointer to the Brixelizer context for use with Brixelizer GI.
} FfxBrixelizerGIDispatchDescription;
/// An enumeration of which output mode to be used by Brixelizer GI debug visualization.
/// See <c><i>FfxBrixelizerGIDebugDescription</i></c>.
///
/// @ingroup Brixelizer GI
typedef enum FfxBrixelizerGIDebugMode
{
FFX_BRIXELIZER_GI_DEBUG_MODE_RADIANCE_CACHE, ///< Draw the radiance cache.
FFX_BRIXELIZER_GI_DEBUG_MODE_IRRADIANCE_CACHE, ///< Draw the irradiance cache.
} FfxBrixelizerGIDebugMode;
/// A structure encapsulating the parameters for drawing a debug visualization.
///
/// @ingroup Brixelizer GI
typedef struct FfxBrixelizerGIDebugDescription
{
FfxFloat32x4x4 view; ///< The view matrix for the scene in row major order.
FfxFloat32x4x4 projection; ///< The projection matrix for the scene in row major order.
FfxUInt32 startCascade; ///< The index of the start cascade for use with ray marching with Brixelizer.
FfxUInt32 endCascade; ///< The index of the end cascade for use with ray marching with Brixelizer.
FfxUInt32 outputSize[2]; ///< The dimensions of the output texture.
FfxBrixelizerGIDebugMode debugMode; ///< The mode for the debug visualization. See <c><i>FfxBrixelizerGIDebugMode</i></c>.
FfxFloat32 normalsUnpackMul; ///< A multiply factor to transform the normal to the space expected by Brixelizer GI.
FfxFloat32 normalsUnpackAdd; ///< An offset to transform the normal to the space expected by Brixelizer GI.
FfxResource depth; ///< The input depth buffer.
FfxResource normal; ///< The input normal buffer.
FfxResource sdfAtlas; ///< The SDF Atlas resource used by Brixelizer.
FfxResource bricksAABBs; ///< The brick AABBs resource used by Brixelizer.
FfxResource cascadeAABBTrees[24]; ///< The cascade AABB tree resources used by Brixelizer.
FfxResource cascadeBrickMaps[24]; ///< The cascade brick map resources used by Brixelizer.
FfxResource outputDebug; ///< The output texture for the debug visualization.
FfxBrixelizerRawContext* brixelizerContext; ///< A pointer to the Brixelizer context for use with Brixelizer GI.
} FfxBrixelizerGIDebugDescription;
/// An enumeration of all the passes which constitute the Brixelizer algorithm.
///
/// Brixelizer GI is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxBrixelizerScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxBrixelizerPass</i></c>. For a
/// more comprehensive description of each pass, please refer to the Brixelizer
/// reference documentation.
///
/// @ingroup Brixelizer GI
typedef enum FfxBrixelizerGIPass
{
FFX_BRIXELIZER_GI_PASS_BLUR_X,
FFX_BRIXELIZER_GI_PASS_BLUR_Y,
FFX_BRIXELIZER_GI_PASS_CLEAR_CACHE,
FFX_BRIXELIZER_GI_PASS_EMIT_IRRADIANCE_CACHE,
FFX_BRIXELIZER_GI_PASS_EMIT_PRIMARY_RAY_RADIANCE,
FFX_BRIXELIZER_GI_PASS_FILL_SCREEN_PROBES,
FFX_BRIXELIZER_GI_PASS_INTERPOLATE_SCREEN_PROBES,
FFX_BRIXELIZER_GI_PASS_PREPARE_CLEAR_CACHE,
FFX_BRIXELIZER_GI_PASS_PROJECT_SCREEN_PROBES,
FFX_BRIXELIZER_GI_PASS_PROPAGATE_SH,
FFX_BRIXELIZER_GI_PASS_REPROJECT_GI,
FFX_BRIXELIZER_GI_PASS_REPROJECT_SCREEN_PROBES,
FFX_BRIXELIZER_GI_PASS_SPAWN_SCREEN_PROBES,
FFX_BRIXELIZER_GI_PASS_SPECULAR_PRE_TRACE,
FFX_BRIXELIZER_GI_PASS_SPECULAR_TRACE,
FFX_BRIXELIZER_GI_PASS_DEBUG_VISUALIZATION,
FFX_BRIXELIZER_GI_PASS_GENERATE_DISOCCLUSION_MASK,
FFX_BRIXELIZER_GI_PASS_DOWNSAMPLE,
FFX_BRIXELIZER_GI_PASS_UPSAMPLE,
FFX_BRIXELIZER_GI_PASS_COUNT ///< The number of passes performed by Brixelizer GI.
} FfxBrixelizerGIPass;
/// Get the size in bytes needed for an <c><i>FfxBrixelizerGIContext</i></c> struct.
/// Note that this function is provided for consistency, and the size of the
/// <c><i>FfxBrixelizerGIContext</i></c> is a known compile time value which can be
/// obtained using <c><i>sizeof(FfxBrixelizerGIContext)</i></c>.
///
/// @return The size in bytes of an <c><i>FfxBrixelizerGIContext</i></c> struct.
///
/// @ingroup Brixelizer GI
inline size_t ffxBrixelizerGIGetContextSize()
{
return sizeof(FfxBrixelizerGIContext);
}
/// Create a FidelityFX Brixelizer GI context from the parameters
/// specified to the <c><i>FfxBrixelizerGIContextDescription</i></c> struct.
///
/// The context structure is the main object used to interact with the Brixelizer GI API,
/// and is responsible for the management of the internal resources used by the
/// Brixelizer GI algorithm. When this API is called, multiple calls will be made via
/// the pointers contained in the <b><i>backendInterface</i></b> structure. This
/// backend will attempt to retrieve the device capabilities, and create the internal
/// resources, and pipelines required by Brixelizer GI.
///
/// Depending on the parameters passed in via the <b><i>pContextDescription</b></i> a
/// different set of resources and pipelines may be requested by the callback functions.
///
/// The <c><i>FfxBrixelizerGIContext</i></c> should be destroyed when use of it is completed.
/// To destroy the context you should call <c><i>ffxBrixelizerGIContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxBrixelizerGIContext</i></c> to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxBrixelizerGIContextDescription</i></c> specifying the parameters for context creation.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The operation failed because either <c><i>pContext</i></c> or <c><i>pContextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because <c><i>pContextDescription->backendInterface</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error from the backend.
///
/// @ingroup Brixelizer GI
FFX_API FfxErrorCode ffxBrixelizerGIContextCreate(FfxBrixelizerGIContext* pContext, const FfxBrixelizerGIContextDescription* pContextDescription);
/// Destroy the FidelityFX Brixelizer GI context.
///
/// @param [out] pContext A pointer to a <c><i>FfxBrixelizerGIContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER The <c><i>pContext</i></c> pointer provided was <c><i>NULL</i></c>.
///
/// @ingroup Brixelizer GI
FFX_API FfxErrorCode ffxBrixelizerGIContextDestroy(FfxBrixelizerGIContext* pContext);
/// Perform an update of Brixelizer GI, recording GPU commands to a command list.
///
/// @param [inout] context An <c><i>FfxBrixelizerGIContext</i></c> containing the Brixelizer GI context.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxBrixelizerGIDispatchDescription</i></c> describing the dispatch to compute.
/// @param [inout] pCommandList An <c><i>FfxCommandList</i></c> to write GPU commands to.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer GI
FFX_API FfxErrorCode ffxBrixelizerGIContextDispatch(FfxBrixelizerGIContext* pContext, const FfxBrixelizerGIDispatchDescription* pDispatchDescription, FfxCommandList pCommandList);
/// Make a debug visualization from the <c><i>FfxBrixelizerGIContext</i></c>.
///
/// @param [inout] context An <c><i>FfxBrixelizerGIContext</i></c> containing the Brixelizer GI context.
/// @param [in] pDebugDescription A pointer to a <c><i>FfxBrixelizerGIDebugDescription</i></c> describing the debug visualization to draw.
/// @param [inout] pCommandList An <c><i>FfxCommandList</i></c> to write GPU commands to.
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup Brixelizer GI
FFX_API FfxErrorCode ffxBrixelizerGIContextDebugVisualization(FfxBrixelizerGIContext* pContext, const FfxBrixelizerGIDebugDescription* pDebugDescription, FfxCommandList pCommandList);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup Brixelizer GI
FFX_API FfxVersionNumber ffxBrixelizerGIGetEffectVersion();
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,533 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <stdint.h>
///Include the interface for the backend of the API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup FfxCacao FidelityFX CACAO
/// FidelityFX Combined Adaptive Compute Ambient Occlusion runtime library.
///
/// @ingroup SDKComponents
/// FidelityFX CACAO major version.
///
/// @ingroup FfxCacao
#define FFX_CACAO_VERSION_MAJOR (1)
/// FidelityFX CACAO minor version.
///
/// @ingroup FfxCacao
#define FFX_CACAO_VERSION_MINOR (4)
/// FidelityFX CACAO patch version.
///
/// @ingroup FfxCacao
#define FFX_CACAO_VERSION_PATCH (0)
// ============================================================================
// Prepare
/// Width of the PREPARE_DEPTHS_AND_MIPS pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_PREPARE_DEPTHS_AND_MIPS_WIDTH 8
/// Height of the PREPARE_DEPTHS_AND_MIPS pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_PREPARE_DEPTHS_AND_MIPS_HEIGHT 8
/// Width of the PREPARE_DEPTHS pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_PREPARE_DEPTHS_WIDTH 8
/// Height of the PREPARE_DEPTHS pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_PREPARE_DEPTHS_HEIGHT 8
/// Width of the PREPARE_DEPTHS_HALF pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_PREPARE_DEPTHS_HALF_WIDTH 8
/// Height of the PREPARE_DEPTHS_HALF pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_PREPARE_DEPTHS_HALF_HEIGHT 8
/// Width of the PREPARE_NORMALS pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_PREPARE_NORMALS_WIDTH 8
/// Height of the PREPARE_NORMALS pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_PREPARE_NORMALS_HEIGHT 8
/// Width of the PREPARE_NORMALS_FROM_INPUT_NORMALS pass tile size.
///
/// @ingroup FfxCacao
#define PREPARE_NORMALS_FROM_INPUT_NORMALS_WIDTH 8
/// Height of the PREPARE_NORMALS_FROM_INPUT_NORMALS pass tile size.
///
/// @ingroup FfxCacao
#define PREPARE_NORMALS_FROM_INPUT_NORMALS_HEIGHT 8
// ============================================================================
// SSAO Generation
/// Width of the GENERATE_SPARSE pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_GENERATE_SPARSE_WIDTH 4
/// Height of the GENERATE_SPARSE pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_GENERATE_SPARSE_HEIGHT 16
/// Width of the GENERATE pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_GENERATE_WIDTH 8
/// Height of the GENERATE pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_GENERATE_HEIGHT 8
// ============================================================================
// Importance Map
/// Width of the IMPORTANCE_MAP pass tile size.
///
/// @ingroup FfxCacao
#define IMPORTANCE_MAP_WIDTH 8
/// Height of the IMPORTANCE_MAP pass tile size.
///
/// @ingroup FfxCacao
#define IMPORTANCE_MAP_HEIGHT 8
/// Width of the IMPORTANCE_MAP_A pass tile size.
///
/// @ingroup FfxCacao
#define IMPORTANCE_MAP_A_WIDTH 8
/// Height of the IMPORTANCE_MAP_A pass tile size.
///
/// @ingroup FfxCacao
#define IMPORTANCE_MAP_A_HEIGHT 8
/// Width of the IMPORTANCE_MAP_B pass tile size.
///
/// @ingroup FfxCacao
#define IMPORTANCE_MAP_B_WIDTH 8
/// Height of the IMPORTANCE_MAP_B pass tile size.
///
/// @ingroup FfxCacao
#define IMPORTANCE_MAP_B_HEIGHT 8
// ============================================================================
// Edge Sensitive Blur
/// Width of the BLUR pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_BLUR_WIDTH 16
/// Height of the BLUR pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_BLUR_HEIGHT 16
// ============================================================================
// Apply
/// Width of the APPLY pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_APPLY_WIDTH 8
/// Height of the APPLY pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_APPLY_HEIGHT 8
// ============================================================================
// Bilateral Upscale
/// Width of the BILATERAL_UPSCALE pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_BILATERAL_UPSCALE_WIDTH 8
/// Height of the BILATERAL_UPSCALE pass tile size.
///
/// @ingroup FfxCacao
#define FFX_CACAO_BILATERAL_UPSCALE_HEIGHT 8
/// The size of the context specified in 32bit values.
///
/// @ingroup FfxCacao
#define FFX_CACAO_CONTEXT_SIZE (300988)
/// FidelityFX CACAO context count.
///
/// Defines the number of internal effect contexts required by CACAO.
///
/// @ingroup FfxCacao
#define FFX_CACAO_CONTEXT_COUNT 1
/// An enumeration of the passes which constitutes the CACAO algorithm.
///
/// @ingroup FfxCacao
typedef enum FfxCacaoPass
{
FFX_CACAO_PASS_CLEAR_LOAD_COUNTER = 0, ///<
FFX_CACAO_PASS_PREPARE_DOWNSAMPLED_DEPTHS = 1, ///<
FFX_CACAO_PASS_PREPARE_NATIVE_DEPTHS = 2, ///<
FFX_CACAO_PASS_PREPARE_DOWNSAMPLED_DEPTHS_AND_MIPS = 3, ///<
FFX_CACAO_PASS_PREPARE_NATIVE_DEPTHS_AND_MIPS = 4, ///<
FFX_CACAO_PASS_PREPARE_DOWNSAMPLED_NORMALS = 5, ///<
FFX_CACAO_PASS_PREPARE_NATIVE_NORMALS = 6, ///<
FFX_CACAO_PASS_PREPARE_DOWNSAMPLED_NORMALS_FROM_INPUT_NORMALS = 7, ///<
FFX_CACAO_PASS_PREPARE_NATIVE_NORMALS_FROM_INPUT_NORMALS = 8, ///<
FFX_CACAO_PASS_PREPARE_DOWNSAMPLED_DEPTHS_HALF = 9, ///<
FFX_CACAO_PASS_PREPARE_NATIVE_DEPTHS_HALF = 10, ///<
FFX_CACAO_PASS_GENERATE_Q0 = 11, ///<
FFX_CACAO_PASS_GENERATE_Q1 = 12, ///<
FFX_CACAO_PASS_GENERATE_Q2 = 13, ///<
FFX_CACAO_PASS_GENERATE_Q3 = 14, ///<
FFX_CACAO_PASS_GENERATE_Q3_BASE = 15, ///<
FFX_CACAO_PASS_GENERATE_IMPORTANCE_MAP = 16, ///<
FFX_CACAO_PASS_POST_PROCESS_IMPORTANCE_MAP_A = 17, ///<
FFX_CACAO_PASS_POST_PROCESS_IMPORTANCE_MAP_B = 18, ///<
FFX_CACAO_PASS_EDGE_SENSITIVE_BLUR_1 = 19, ///<
FFX_CACAO_PASS_EDGE_SENSITIVE_BLUR_2 = 20, ///<
FFX_CACAO_PASS_EDGE_SENSITIVE_BLUR_3 = 21, ///<
FFX_CACAO_PASS_EDGE_SENSITIVE_BLUR_4 = 22, ///<
FFX_CACAO_PASS_EDGE_SENSITIVE_BLUR_5 = 23, ///<
FFX_CACAO_PASS_EDGE_SENSITIVE_BLUR_6 = 24, ///<
FFX_CACAO_PASS_EDGE_SENSITIVE_BLUR_7 = 25, ///<
FFX_CACAO_PASS_EDGE_SENSITIVE_BLUR_8 = 26, ///<
FFX_CACAO_PASS_APPLY_NON_SMART_HALF = 27, ///<
FFX_CACAO_PASS_APPLY_NON_SMART = 28, ///<
FFX_CACAO_PASS_APPLY = 29, ///<
FFX_CACAO_PASS_UPSCALE_BILATERAL_5X5 = 30,
FFX_CACAO_PASS_COUNT ///< The number of passes in CACAO
} FfxCacaoPass;
/// The quality levels that FidelityFX CACAO can generate SSAO at. This affects the number of samples taken for generating SSAO.
///
/// @ingroup FfxCacao
typedef enum FfxCacaoQuality {
FFX_CACAO_QUALITY_LOWEST = 0,
FFX_CACAO_QUALITY_LOW = 1,
FFX_CACAO_QUALITY_MEDIUM = 2,
FFX_CACAO_QUALITY_HIGH = 3,
FFX_CACAO_QUALITY_HIGHEST = 4,
} FfxCacaoQuality;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxCacaoContext</i></c>. See <c><i>FfxCacaoContextDescription</i></c>.
///
/// @ingroup FfxCacao
typedef enum FfxCacaoInitializationFlagBits {
FFX_CACAO_ENABLE_APPLY_SMART = (1<<0), ///< A bit indicating to use smart application
} FfxCacaoInitializationFlagBits;
/// A structure for the settings used by FidelityFX CACAO. These settings may be updated with each draw call.
///
/// @ingroup FfxCacao
typedef struct FfxCacaoSettings {
float radius; ///< [0.0, ~ ] World (view) space size of the occlusion sphere.
float shadowMultiplier; ///< [0.0, 5.0] Effect strength linear multiplier.
float shadowPower; ///< [0.5, 5.0] Effect strength pow modifier.
float shadowClamp; ///< [0.0, 1.0] Effect max limit (applied after multiplier but before blur).
float horizonAngleThreshold; ///< [0.0, 0.2] Limits self-shadowing (makes the sampling area less of a hemisphere, more of a spherical cone, to avoid self-shadowing and various artifacts due to low tessellation and depth buffer imprecision, etc.).
float fadeOutFrom; ///< [0.0, ~ ] Distance to start fading out the effect.
float fadeOutTo; ///< [0.0, ~ ] Distance at which the effect is faded out.
FfxCacaoQuality qualityLevel; ///< Effect quality, affects number of taps etc.
float adaptiveQualityLimit; ///< [0.0, 1.0] (only for quality level FFX_CACAO_QUALITY_HIGHEST).
uint32_t blurPassCount; ///< [ 0, 8] Number of edge-sensitive smart blur passes to apply.
float sharpness; ///< [0.0, 1.0] How much to bleed over edges; 1: not at all, 0.5: half-half; 0.0: completely ignore edges.
float temporalSupersamplingAngleOffset; ///< [0.0, PI] Used to rotate sampling kernel; If using temporal AA / supersampling, suggested to rotate by ( (frame%3)/3.0*PI ) or similar. Kernel is already symmetrical, which is why we use PI and not 2*PI.
float temporalSupersamplingRadiusOffset; ///< [0.0, 2.0] Used to scale sampling kernel; If using temporal AA / supersampling, suggested to scale by ( 1.0f + (((frame%3)-1.0)/3.0)*0.1 ) or similar.
float detailShadowStrength; ///< [0.0, 5.0] Used for high-res detail AO using neighboring depth pixels: adds a lot of detail but also reduces temporal stability (adds aliasing).
bool generateNormals; ///< This option should be set to FFX_CACAO_TRUE if FidelityFX-CACAO should reconstruct a normal buffer from the depth buffer. It is required to be FFX_CACAO_TRUE if no normal buffer is provided.
float bilateralSigmaSquared; ///< [0.0, ~ ] Sigma squared value for use in bilateral upsampler giving Gaussian blur term. Should be greater than 0.0.
float bilateralSimilarityDistanceSigma; ///< [0.0, ~ ] Sigma squared value for use in bilateral upsampler giving similarity weighting for neighbouring pixels. Should be greater than 0.0.
} FfxCacaoSettings;
/// The default settings used by FidelityFX CACAO.
///
/// @ingroup FfxCacao
static const FfxCacaoSettings FFX_CACAO_DEFAULT_SETTINGS = {
/* radius */ 1.2f,
/* shadowMultiplier */ 1.0f,
/* shadowPower */ 1.50f,
/* shadowClamp */ 0.98f,
/* horizonAngleThreshold */ 0.06f,
/* fadeOutFrom */ 50.0f,
/* fadeOutTo */ 300.0f,
/* qualityLevel */ FFX_CACAO_QUALITY_HIGHEST,
/* adaptiveQualityLimit */ 0.45f,
/* blurPassCount */ 2,
/* sharpness */ 0.98f,
/* temporalSupersamplingAngleOffset */ 0.0f,
/* temporalSupersamplingRadiusOffset */ 0.0f,
/* detailShadowStrength */ 0.5f,
/* generateNormals */ false,
/* bilateralSigmaSquared */ 5.0f,
/* bilateralSimilarityDistanceSigma */ 0.01f,
};
/// A structure for the constant buffer used by FidelityFX CACAO.
///
/// @ingroup FfxCacao
typedef struct FfxCacaoConstants {
float DepthUnpackConsts[2]; /// Multiply and add values for clip to view depth conversion.
float CameraTanHalfFOV[2]; /// tan(fov/2) for the x and y dimensions.
float NDCToViewMul[2]; /// Multiplication value for normalized device coordinates (NDC) to View conversion.
float NDCToViewAdd[2]; /// Addition value for NDC to view conversion.
float DepthBufferUVToViewMul[2]; /// Multiplication value for the depth buffer's UV to View conversion.
float DepthBufferUVToViewAdd[2]; /// Addition value for the depth buffer's UV to view conversion.
float EffectRadius; /// The radius in world space of the occlusion sphere. A larger radius will make further objects contribute to the ambient occlusion of a point.
float EffectShadowStrength; /// The linear multiplier for shadows. Higher values intensify the shadow.
float EffectShadowPow; /// The exponent for shadow values. Larger values create darker shadows.
float EffectShadowClamp; /// Clamps the shadow values to be within a certain range.
float EffectFadeOutMul; /// Multiplication value for effect fade out.
float EffectFadeOutAdd; /// Addition value for effect fade out.
float EffectHorizonAngleThreshold; /// Minimum angle necessary between geometry and a point to create occlusion. Adjusting this value helps reduce self-shadowing.
float EffectSamplingRadiusNearLimitRec; /// Default: EffectRadius1.2. Used to set limit on the sampling disk size when near.
float DepthPrecisionOffsetMod; /// Default: 0.9992. Offset used to prevent artifacts due to imprecision.
float NegRecEffectRadius; /// Negative reciprocal of the effect radius.
float LoadCounterAvgDiv; /// Multiplier value to get average from loadcounter value.
float AdaptiveSampleCountLimit; /// Limits the total number of samples taken at adaptive quality levels.
float InvSharpness; /// The sharpness controls how much blur should bleed over edges.
int BlurNumPasses; /// Number of blur passes. Default uses 4, with lowest quality using 2.
float BilateralSigmaSquared; /// Only affects downsampled SSAO. Higher values create a larger blur.
float BilateralSimilarityDistanceSigma; /// Only affects downsampled SSAO. Lower values create sharper edges.
float PatternRotScaleMatrices[4][5][4]; /// Sampling pattern rotation/scale matrices.
float NormalsUnpackMul; /// Multiplication value to unpack normals. Set to 1 if normals are already in [1,1] range.
float NormalsUnpackAdd; /// Addition value to unpack normals. Set to 0 if normals are already in [1,1]range.
float DetailAOStrength; /// Adds in more detailed shadows based on edges. These are less temporally stable.
float Dummy0;
float SSAOBufferDimensions[2]; /// Dimensions of SSAO buffer.
float SSAOBufferInverseDimensions[2];
float DepthBufferDimensions[2]; /// Dimensions of the depth buffer.
float DepthBufferInverseDimensions[2];
int DepthBufferOffset[2]; /// Default is (0,0). Read offset for depth buffer.
int Pad[2];
float PerPassFullResUVOffset[4*4]; /// UV Offsets used in adaptive approach.
float InputOutputBufferDimensions[2]; /// Dimensions of the output AO buffer.
float InputOutputBufferInverseDimensions[2];
float ImportanceMapDimensions[2]; /// Dimensions of the importance map.
float ImportanceMapInverseDimensions[2];
float DeinterleavedDepthBufferDimensions[2]; /// Dimensions of the deinterleaved depth buffer.
float DeinterleavedDepthBufferInverseDimensions[2];
float DeinterleavedDepthBufferOffset[2]; /// Default is (0,0). Read offset for the deinterleaved depth buffer.
float DeinterleavedDepthBufferNormalisedOffset[2]; /// Default is (0,0). Normalized read offset for the deinterleaved depth buffer.
FfxFloat32x4x4 NormalsWorldToViewspaceMatrix; /// Normal matrix.
} FfxCacaoConstants;
/// A structure encapsulating the parameters required to initialize FidelityFX CACAO.
///
/// @ingroup FfxCacao
typedef struct FfxCacaoContextDescription
{
uint32_t width; ///< width of the input/output buffers
uint32_t height; ///< height of the input/output buffers
bool useDownsampledSsao; ///< Whether SSAO should be generated at native resolution or half resolution. It is recommended to enable this setting for improved performance.
FfxInterface backendInterface;
} FfxCacaoContextDescription;
/// A structure encapsulating the parameters and resources required to dispatch FidelityFX CACAO.
///
/// @ingroup FfxCacao
typedef struct FfxCacaoDispatchDescription
{
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record CACAO rendering commands into.
FfxResource depthBuffer; ///< A <c><i>FfxResource</i></c> containing the depth buffer for the current frame.
FfxResource normalBuffer; ///< A <c><i>FfxResource</i></c> containing the normal buffer for the current frame.
FfxResource outputBuffer; ///< A <c><i>FfxResource</i></c> containing the output color buffer for CACAO.
FfxFloat32x4x4* proj; ///< A <c><i>FfxFloat32x4x4</i></c> containing the projection matrix for the current frame.
FfxFloat32x4x4* normalsToView; ///< A <c><i>FfxFloat32x4x4</i></c> containing the normal matrix for the current frame.
float normalUnpackMul; /// Multiplication value to unpack normals. Set to 1 if normals are already in [1,1] range.
float normalUnpackAdd; /// Addition value to unpack normals. Set to 0 if normals are already in [1,1]range.
} FfxCacaoDispatchDescription;
/// A structure containing sizes of each of the buffers used by FidelityFX CACAO.
///
/// @ingroup FfxCacao
typedef struct FfxCacaoBufferSizeInfo {
uint32_t inputOutputBufferWidth; ///< width of the input/output buffers
uint32_t inputOutputBufferHeight; ///< height of the input/output buffers
uint32_t ssaoBufferWidth; ///< width of the ssao buffer
uint32_t ssaoBufferHeight; ///< height of the ssao buffer
uint32_t depthBufferXOffset; ///< x-offset to use when sampling depth buffer
uint32_t depthBufferYOffset; ///< y-offset to use when sampling depth buffer
uint32_t depthBufferWidth; ///< width of the passed in depth buffer
uint32_t depthBufferHeight; ///< height of the passed in depth buffer
uint32_t deinterleavedDepthBufferXOffset; ///< x-offset to use when sampling de-interleaved depth buffer
uint32_t deinterleavedDepthBufferYOffset; ///< y-offset to use when sampling de-interleaved depth buffer
uint32_t deinterleavedDepthBufferWidth; ///< width of the de-interleaved depth buffer
uint32_t deinterleavedDepthBufferHeight; ///< height of the de-interleaved depth buffer
uint32_t importanceMapWidth; ///< width of the importance map buffer
uint32_t importanceMapHeight; ///< height of the importance map buffer
uint32_t downsampledSsaoBufferWidth; ///< width of the downsampled ssao buffer
uint32_t downsampledSsaoBufferHeight; ///< height of the downsampled ssao buffer
} FfxCacaoBufferSizeInfo;
/// An enumeration of bit flags used when dispatching FidelityFX CACAO
///
/// @ingroup FfxCacao
typedef enum FfxCacaoDispatchFlagsBits {
FFX_CACAO_SRV_SSAO_REMAP_TO_PONG = (1<<0), ///< A bit indicating the SRV maps to pong texture
FFX_CACAO_UAV_SSAO_REMAP_TO_PONG = (1<<1), ///< A bit indicating the UAV maps to pong texture
} FfxCacaoDispatchFlagsBits;
/// A structure encapsulating the FidelityFX CACAO context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by CACAO.
///
/// The <c><i>FfxCacaoContext</i></c> object should have a lifetime matching
/// your use of CACAO. Before destroying the CACAO context care should be taken
/// to ensure the GPU is not accessing the resources created or used by CACAO.
/// It is therefore recommended that the GPU is idle before destroying the
/// CACAO context.
///
/// @ingroup FfxCacao
typedef struct FfxCacaoContext
{
uint32_t data[FFX_CACAO_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxCacaoContext;
/// Create a FidelityFX CACAO context from the parameters
/// programmed to the <c><i>FfxCacaoContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the CACAO
/// API, and is responsible for the management of the internal resources
/// used by the CACAO algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>backendInterface</i></c>
/// structure. This backend will attempt to retrieve the device capabilities,
/// and create the internal resources, and pipelines required by CACAO to function.
/// Depending on the precise configuration used when
/// creating the <c><i>FfxCacaoContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxCacaoContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or CACAO
/// upscaling is disabled by a user. To destroy the CACAO context you
/// should call <c><i>ffxCacaoContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxCacaoContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxCacaoContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxCacaoContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxCacao
FFX_API FfxErrorCode ffxCacaoContextCreate(FfxCacaoContext* context, const FfxCacaoContextDescription* contextDescription);
/// Dispatches work to the FidelityFX CACAO context
///
/// @param [out] pContext A pointer to a <c><i>FfxCacaoContext</i></c> structure to populate.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxCacaoDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxCacao
FFX_API FfxErrorCode ffxCacaoContextDispatch(FfxCacaoContext* context, const FfxCacaoDispatchDescription* dispatchDescription);
/// Destroy the FidelityFX CACAO context.
///
/// @param [out] pContext A pointer to a <c><i>FfxCacaoContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FfxCacao
FFX_API FfxErrorCode ffxCacaoContextDestroy(FfxCacaoContext* context);
/// Updates the settings used by CACAO.
/// @param [in] context A pointer to a <c><i>FfxCacaoContext</i></c> structure to change settings for.
/// @param [in] settings A pointer to a <c><i>FfxCacaoSettings</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>settings</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FfxCacao
FFX_API FfxErrorCode ffxCacaoUpdateSettings(FfxCacaoContext* context, const FfxCacaoSettings* settings, const bool useDownsampledSsao);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FfxCacao
FFX_API FfxVersionNumber ffxCacaoGetEffectVersion();

View File

@@ -0,0 +1,209 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup CAS
#pragma once
// Include the interface for the backend of the CAS API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup ffxCas FidelityFX Cas
/// FidelityFX Contrast Adaptive Sharpening runtime library
///
/// @ingroup SDKComponents
/// Contrast Adaptive Sharpening major version.
///
/// @ingroup ffxCas
#define FFX_CAS_VERSION_MAJOR (1)
/// Contrast Adaptive Sharpening minor version.
///
/// @ingroup ffxCas
#define FFX_CAS_VERSION_MINOR (2)
/// Contrast Adaptive Sharpening patch version.
///
/// @ingroup ffxCas
#define FFX_CAS_VERSION_PATCH (0)
/// FidelityFX CAS context count
///
/// Defines the number of internal effect contexts required by CAS
///
/// @ingroup ffxCas
#define FFX_CAS_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup ffxCas
#define FFX_CAS_CONTEXT_SIZE (9204)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of all the passes which constitute the CAS algorithm.
///
/// CAS has only one pass. For a more comprehensive description
/// of this pass, please refer to the CAS reference documentation.
///
/// @ingroup ffxCas
typedef enum FfxCasPass
{
FFX_CAS_PASS_SHARPEN = 0, ///< A pass which sharpens only or upscales the color buffer.
FFX_CAS_PASS_COUNT ///< The number of passes performed by CAS.
} FfxCasPass;
/// An enumeration of color space conversions used when creating a
/// <c><i>FfxCASContext</i></c>. See <c><i>FfxCASContextDescription</i></c>.
///
/// @ingroup ffxCas
typedef enum FfxCasColorSpaceConversion
{
FFX_CAS_COLOR_SPACE_LINEAR = 0, ///< Linear color space, will do nothing.
FFX_CAS_COLOR_SPACE_GAMMA20 = 1, ///< Convert gamma 2.0 to linear for input and linear to gamma 2.0 for output.
FFX_CAS_COLOR_SPACE_GAMMA22 = 2, ///< Convert gamma 2.2 to linear for input and linear to gamma 2.2 for output.
FFX_CAS_COLOR_SPACE_SRGB_OUTPUT = 3, ///< Only do sRGB conversion for output (input conversion will be done automatically).
FFX_CAS_COLOR_SPACE_SRGB_INPUT_OUTPUT = 4 ///< Convert sRGB to linear for input and linear to sRGB for output.
} FfxCasColorSpaceConversion;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxCASContext</i></c>. See <c><i>FfxCASContextDescription</i></c>.
///
/// @ingroup ffxCas
typedef enum FfxCasInitializationFlagBits
{
FFX_CAS_SHARPEN_ONLY = (1 << 0) ///< A bit indicating if we sharpen only.
} FfxCasInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX CAS
///
/// @ingroup ffxCas
typedef struct FfxCasContextDescription
{
uint32_t flags; ///< A collection of <c><i>FfxCasInitializationFlagBits</i></c>.
FfxCasColorSpaceConversion colorSpaceConversion; ///< An enumeration indicates which color space conversion is used.
FfxDimensions2D maxRenderSize; ///< The maximum size that rendering will be performed at.
FfxDimensions2D displaySize; ///< The size of the presentation resolution targeted by the upscaling process.
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for CAS.
} FfxCasContextDescription;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX CAS
///
/// @ingroup ffxCas
typedef struct FfxCasDispatchDescription
{
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record CAS rendering commands into.
FfxResource color; ///< A <c><i>FfxResource</i></c> containing the color buffer for the current frame (at render resolution).
FfxResource output; ///< A <c><i>FfxResource</i></c> containing the output color buffer for the current frame (at presentation resolution).
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resource.
float sharpness; ///< The sharpness value between 0 and 1, where 0 is no additional sharpness and 1 is maximum additional sharpness.
} FfxCasDispatchDescription;
/// A structure encapsulating the FidelityFX CAS context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by CAS.
///
/// The <c><i>FfxCasContext</i></c> object should have a lifetime matching
/// your use of CAS. Before destroying the CAS context care should be taken
/// to ensure the GPU is not accessing the resources created or used by CAS.
/// It is therefore recommended that the GPU is idle before destroying the
/// CAS context.
///
/// @ingroup ffxCas
typedef struct FfxCasContext
{
uint32_t data[FFX_CAS_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxCasContext;
/// Create a FidelityFX CAS context from the parameters
/// programmed to the <c><i>FfxCasContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the CAS,
/// and is responsible for the management of the internal resources
/// used by the CAS algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>callbacks</i></c>
/// structure. These callbacks will attempt to retreive the device capabilities,
/// , and pipelines required by CAS frame-to-frame function. Depending on configuration
/// used when creating the <c><i>FfxCasContext</i></c> a different set of pipelines
/// might be requested via the callback functions.
///
/// The <c><i>FfxCasContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or CAS is disabled by a user.
/// To destroy the CAS context you should call <c><i>ffxCasContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxCasContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxCasContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxCasContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxCas
FFX_API FfxErrorCode ffxCasContextCreate(FfxCasContext* pContext, const FfxCasContextDescription* pContextDescription);
/// @param [out] pContext A pointer to a <c><i>FfxCasContext</i></c> structure to populate.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxCasDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxCas
FFX_API FfxErrorCode ffxCasContextDispatch(FfxCasContext* pContext, const FfxCasDispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX CAS context.
///
/// @param [out] pContext A pointer to a <c><i>FfxCasContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup ffxCas
FFX_API FfxErrorCode ffxCasContextDestroy(FfxCasContext* pContext);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxCas
FFX_API FfxVersionNumber ffxCasGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,288 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup Classifier
#pragma once
#define FFX_CLASSIFIER_MAX_SHADOW_MAP_TEXTURES_COUNT 4
// Include the interface for the backend of the FSR2 API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup ffxClassifier FidelityFX Classifier
/// FidelityFX Classifier runtime library
///
/// @ingroup SDKComponents
/// FidelityFX Classifier major version.
///
/// @ingroup ffxClassifier
#define FFX_CLASSIFIER_VERSION_MAJOR (1)
/// FidelityFX Classifier minor version.
///
/// @ingroup ffxClassifier
#define FFX_CLASSIFIER_VERSION_MINOR (3)
/// FidelityFX Classifier patch version.
///
/// @ingroup ffxClassifier
#define FFX_CLASSIFIER_VERSION_PATCH (0)
/// FidelityFX Classifier context count
///
/// Defines the number of internal effect contexts required by Classifier
///
/// @ingroup ffxClassifier
#define FFX_CLASSIFIER_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup ffxClassifier
#define FFX_CLASSIFIER_CONTEXT_SIZE (18500)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// Enum to specify which blur pass (currently only one).
///
/// @ffxClassifier
typedef enum FfxClassifierPass
{
FFX_CLASSIFIER_SHADOW_PASS_CLASSIFIER = 0, ///< The Tile Classification Pass
FFX_CLASSIFIER_REFLECTION_PASS_TILE_CLASSIFIER = 1, ///< Reflections tile classification pass
FFX_CLASSIFIER_PASS_COUNT ///< The number of passes in the Classifier effect
} FfxClassifierPass;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxClassifierContext</i></c>. See <c><i>FfxClassifierContextDescription</i></c>.
/// Currently, no flags exist.
///
/// @ingroup ffxClassifier
typedef enum FfxClassifierInitializationFlagBits {
FFX_CLASSIFIER_SHADOW = (1 << 0), ///< A bit indicating the intent is to classify shadows
FFX_CLASSIFIER_CLASSIFY_BY_NORMALS = (1 << 1), ///< A bit indicating the intent is to classify by normals
FFX_CLASSIFIER_CLASSIFY_BY_CASCADES = (1 << 2), ///< A bit indicating the intent is to classify by cascades
FFX_CLASSIFIER_ENABLE_DEPTH_INVERTED = (1 << 3), ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
FFX_CLASSIFIER_REFLECTION = (1 << 4), ///< A bit indicating the intent is to classify reflections
} FfxClassifierInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Classifier.
///
/// @ingroup ffxClassifier
typedef struct FfxClassifierContextDescription {
uint32_t flags; ///< A collection of @ref FfxClassifierInitializationFlagBits
FfxDimensions2D resolution; ///< Resolution of the shadow dispatch call
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX Classifier
} FfxClassifierContextDescription;
/// A structure encapsulating the parameters for dispatching
/// of FidelityFX Classifier for shadows
///
/// @ingroup ffxClassifier
typedef struct FfxClassifierShadowDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record Classifier rendering commands into.
FfxResource depth; ///< The <c><i>FfxResource</i></c> (SRV Texture 0)containing depth information
FfxResource normals; ///< The <c><i>FfxResource</i></c> (SRV Texture 1)containing normals information
FfxResource shadowMaps[FFX_CLASSIFIER_MAX_SHADOW_MAP_TEXTURES_COUNT]; ///< The <c><i>FfxResource</i></c> (SRV Texture 2)containing shadowMap(s) information
FfxResource workQueue; ///< The <c><i>FfxResource</i></c> (UAV Buffer 0)Work Queue: rwsb_tiles.
FfxResource workQueueCount; ///< The <c><i>FfxResource</i></c> (UAV Buffer 1)Work Queue Counter: rwb_tileCount
FfxResource rayHitTexture; ///< The <c><i>FfxResource</i></c> (UAV Texture 0)Ray Hit Texture
FfxFloat32 normalsUnPackMul; ///< A multiply factor to transform the normal to the space expected by the Classifier
FfxFloat32 normalsUnPackAdd; ///< An offset to transform the normal to the space expected by the Classifier
// Constant Data
FfxFloat32x3 lightDir; ///< The light direction
FfxFloat32 sunSizeLightSpace; ///< The sun size
FfxUInt32 tileCutOff; ///< The tile cutoff
FfxBoolean bRejectLitPixels; ///< UI Setting, selects wheter to reject lit pixels in the shadows maps
FfxUInt32 cascadeCount; ///< The number of cascades
FfxFloat32 blockerOffset; ///< UI Setting, the blocker offsett
FfxBoolean bUseCascadesForRayT; ///< UI Setting, selects whether to use the classifier to save ray intervals
FfxFloat32 cascadeSize; ///< The cascade size
FfxFloat32x4 cascadeScale[4]; ///< A multiply factor for each cascade
FfxFloat32x4 cascadeOffset[4]; ///< An offeset factor for each cascade
// Matrices
FfxFloat32 viewToWorld[16];
FfxFloat32 lightView[16];
FfxFloat32 inverseLightView[16];
} FfxClassifierShadowDispatchDescription;
/// A structure encapsulating the parameters for dispatching
/// of FidelityFX Classifier for reflections
///
/// @ingroup ffxClassifier
typedef struct FfxClassifierReflectionDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record Hybrid Reflections rendering commands into.
FfxResource depth; ///< A <c><i>FfxResource</i></c> containing the depth buffer for the current frame (at render resolution).
FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing the motion vectors buffer for the current frame (at render resolution).
FfxResource normal; ///< A <c><i>FfxResource</i></c> containing the normal buffer for the current frame (at render resolution).
FfxResource materialParameters; ///< A <c><i>FfxResource</i></c> containing the aoRoughnessMetallic buffer for the current frame (at render resolution).
FfxResource environmentMap; ///< A <c><i>FfxResource</i></c> containing the environment map to fallback to when screenspace data is not sufficient
FfxResource radiance;
FfxResource varianceHistory;
FfxResource hitCounter;
FfxResource hitCounterHistory;
FfxResource rayList;
FfxResource rayListHW;
FfxResource extractedRoughness;
FfxResource rayCounter;
FfxResource denoiserTileList;
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
float invViewProjection[16]; ///< An array containing the inverse of the view projection matrix in column major layout.
float projection[16]; ///< An array containing the projection matrix in column major layout.
float invProjection[16]; ///< An array containing the inverse of the projection matrix in column major layout.
float view[16]; ///< An array containing the view matrix in column major layout.
float invView[16]; ///< An array containing the inverse of the view matrix in column major layout.
float prevViewProjection[16]; ///< An array containing the previous frame's view projection matrix in column major layout.
float iblFactor; ///< A factor to control the intensity of the image based lighting. Set to 1 for an HDR probe.
uint32_t frameIndex;
uint32_t samplesPerQuad;
uint32_t temporalVarianceGuidedTracingEnabled;
float globalRoughnessThreshold;
float rtRoughnessThreshold;
uint32_t mask;
uint32_t reflectionWidth;
uint32_t reflectionHeight;
float hybridMissWeight;
float hybridSpawnRate;
float vrtVarianceThreshold;
float reflectionsBackfacingThreshold;
uint32_t randomSamplesPerPixel;
float motionVectorScale[2];
float normalsUnpackMul;
float normalsUnpackAdd;
uint32_t roughnessChannel;
bool isRoughnessPerceptual;
} FfxClassifierReflectionDispatchDescription;
/// A structure encapsulating the FidelityFX Classifier context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by the Classifier.
///
/// The <c><i>FfxClassifierContext</i></c> object should have a lifetime matching
/// your use of the Classifier. Before destroying the Classifier context care should be taken
/// to ensure the GPU is not accessing the resources created or used by the Classifier.
/// It is therefore recommended that the GPU is idle before destroying the
/// Classifier context.
///
/// @ingroup ffxClassifier
typedef struct FfxClassifierContext {
uint32_t data[FFX_CLASSIFIER_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxClassifierContext;
/// Create a FidelityFX Classifier context from the parameters
/// programmed to the <c><i>FfxClassifierContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the Classifier
/// API, and is responsible for the management of the internal resources
/// used by the Classifier. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>backendInterface</i></c>
/// structure. This backend will attempt to retrieve the device capabilities,
/// and create the internal resources, and pipelines required by the Classifier to function.
/// Depending on the precise configuration used when
/// creating the <c><i>FfxClassifierContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxClassifierContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or the Classifier
/// is disabled by a user. To destroy the Classifier context you
/// should call <c><i>FfxClassifierContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxClassifierContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxClassifierContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxClassifierContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxClassifier
FFX_API FfxErrorCode ffxClassifierContextCreate(FfxClassifierContext* pContext, const FfxClassifierContextDescription* pContextDescription);
/// Dispatches work to the FidelityFX Classifier context for shadows
///
/// @param [in] pContext A pointer to a <c><i>FfxClassifierContext</i></c> structure.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxClassifierShadowDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxClassifier
FFX_API FfxErrorCode ffxClassifierContextShadowDispatch(FfxClassifierContext* pContext, const FfxClassifierShadowDispatchDescription* pDispatchDescription);
/// Dispatches work to the FidelityFX Classifier context for reflections
///
/// @param [in] pContext A pointer to a <c><i>FfxClassifierContext</i></c> structure.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxClassifierReflectionDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxClassifier
FFX_API FfxErrorCode ffxClassifierContextReflectionDispatch(FfxClassifierContext* pContext, const FfxClassifierReflectionDispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX Classifier context.
///
/// @param [out] pContext A pointer to a <c><i>FfxClassifierContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup ffxClassifier
FFX_API FfxErrorCode ffxClassifierContextDestroy(FfxClassifierContext* pContext);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxClassifier
FFX_API FfxVersionNumber ffxClassifierGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,266 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
// Include the interface for the backend of the Denoiser API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup FfxDenoiser FidelityFX Denoiser
/// FidelityFX Denoiser runtime library
///
/// @ingroup SDKComponents
/// FidelityFX Denoiser major version.
///
/// @ingroup FfxDenoiser
#define FFX_DENOISER_VERSION_MAJOR (1)
/// FidelityFX Denoiser minor version.
///
/// @ingroup FfxDenoiser
#define FFX_DENOISER_VERSION_MINOR (3)
/// FidelityFX Denoiser patch version.
///
/// @ingroup FfxDenoiser
#define FFX_DENOISER_VERSION_PATCH (0)
/// FidelityFX denoiser context count
///
/// Defines the number of internal effect contexts required by the denoiser
///
/// @ingroup FfxDenoiser
#define FFX_DENOISER_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup Denoiser
#define FFX_DENOISER_CONTEXT_SIZE (73076)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of the pass which constitutes the Denoiser algorithm.
///
/// @ingroup Denoiser
typedef enum FfxDenoiserPass
{
FFX_DENOISER_PASS_PREPARE_SHADOW_MASK = 0,
FFX_DENOISER_PASS_SHADOWS_TILE_CLASSIFICATION = 1,
FFX_DENOISER_PASS_FILTER_SOFT_SHADOWS_0 = 2,
FFX_DENOISER_PASS_FILTER_SOFT_SHADOWS_1 = 3,
FFX_DENOISER_PASS_FILTER_SOFT_SHADOWS_2 = 4,
FFX_DENOISER_PASS_REPROJECT_REFLECTIONS = 5, ///< A pass which reprojects and estimates the variance.
FFX_DENOISER_PASS_PREFILTER_REFLECTIONS = 6, ///< A pass which spatially filters the reflections.
FFX_DENOISER_PASS_RESOLVE_TEMPORAL_REFLECTIONS = 7, ///< A pass which temporally filters the reflections.
FFX_DENOISER_PASS_COUNT ///< The number of passes in Denoiser
} FfxDenoiserPass;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxDenoiserContext</i></c>. See <c><i>FfxDenoiserContextDescription</i></c>.
///
/// @ingroup FfxDenoiser
typedef enum FfxDenoiserInitializationFlagBits {
FFX_DENOISER_SHADOWS = (1 << 0), ///< A bit indicating that the denoiser is used for denoising shadows
FFX_DENOISER_REFLECTIONS = (1 << 1), ///< A bit indicating that the denoiser is used for denoising reflections
FFX_DENOISER_ENABLE_DEPTH_INVERTED = (1 << 2), ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
} FfxDenoiserInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX Denoiser
///
/// @ingroup FfxDenoiser
typedef struct FfxDenoiserContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxDenoiserInitializationFlagBits</i></c>
FfxDimensions2D windowSize; ///< The resolution that was used for rendering the input resource.
FfxSurfaceFormat normalsHistoryBufferFormat; ///< The format used by the reflections denoiser to store the normals buffer history
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX.
} FfxDenoiserContextDescription;
/// A structure encapsulating the parameters for dispatching
/// of FidelityFX Denoiser
///
/// @ingroup FfxDenoiser
typedef struct FfxDenoiserShadowsDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record Denoiser rendering commands into.
FfxResource hitMaskResults; ///< A <c><i>FfxResource</i></c> containing the raytracing results where every pixel represents a 8x4 tile.
FfxResource depth; ///< A <c><i>FfxResource</i></c> containing 32bit depth values for the current frame.
FfxResource velocity; ///< A <c><i>FfxResource</i></c> containing 2-dimensional motion vectors.
FfxResource normal; ///< A <c><i>FfxResource</i></c> containing the normals.
FfxResource shadowMaskOutput; ///< A <c><i>FfxResource</i></c> which is used to store the fullscreen raytracing output.
FfxFloat32x2 motionVectorScale; ///< A multiply factor to transform the motion vectors to the space expected by the shadow denoiser.
FfxFloat32 normalsUnpackMul; ///< A multiply factor to transform the normal to the space expected by the shadow denoiser.
FfxFloat32 normalsUnpackAdd; ///< An offset to transform the normal to the space expected by the shadow denoiser.
FfxFloat32x3 eye; ///< The camera position
uint32_t frameIndex; ///< The current frame index
FfxFloat32 projectionInverse[16]; ///< The inverse of the camera projection matrix
FfxFloat32 reprojectionMatrix[16]; ///< The result of multiplying the projection matrix of the current frame by the result of the multiplication between the camera previous's frame view matrix by the inverse of the view-projection matrix
FfxFloat32 viewProjectionInverse[16]; ///< The inverse of the camera view-projection matrix
FfxFloat32 depthSimilaritySigma; ///< A constant factor used in the denoising filters, defaults to 1.0f
} FfxDenoiserShadowsDispatchDescription;
/// A structure encapsulating the parameters for dispatching
/// of FidelityFX Denoiser
///
/// @ingroup FfxDenoiser
typedef struct FfxDenoiserReflectionsDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record Denoiser rendering commands into.
FfxResource depthHierarchy; ///< A <c><i>FfxResource</i></c> containing the depth buffer with full mip maps for the current frame.
FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing the motion vectors buffer for the current frame.
FfxResource normal; ///< A <c><i>FfxResource</i></c> containing the normal buffer for the current frame.
FfxResource radianceA; ///< A <c><i>FfxResource</i></c> containing the ping-pong radiance buffers to filter.
FfxResource radianceB; ///< A <c><i>FfxResource</i></c> containing the ping-pong radiance buffers to filter.
FfxResource varianceA; ///< A <c><i>FfxResource</i></c> containing the ping-pong variance buffers used to filter and guide reflections.
FfxResource varianceB; ///< A <c><i>FfxResource</i></c> containing the ping-pong variance buffers used to filter and guide reflections.
FfxResource extractedRoughness; ///< A <c><i>FfxResource</i></c> containing the roughness of the current frame.
FfxResource denoiserTileList; ///< A <c><i>FfxResource</i></c> containing the tiles to be denoised.
FfxResource indirectArgumentsBuffer; ///< A <c><i>FfxResource</i></c> containing the indirect arguments used by the indirect dispatch calls tha compose the denoiser.
FfxResource output; ///< A <c><i>FfxResource</i></c> to store the denoised reflections.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors.
float invProjection[16]; ///< An array containing the inverse of the projection matrix in column major layout.
float invView[16]; ///< An array containing the inverse of the view matrix in column major layout.
float prevViewProjection[16]; ///< An array containing the view projection matrix of the previous frame in column major layout.
float normalsUnpackMul; ///< A multiply factor to transform the normal to the space expected by SSSR.
float normalsUnpackAdd; ///< An offset to transform the normal to the space expected by SSSR.
bool isRoughnessPerceptual; ///< A boolean to describe the space used to store roughness in the materialParameters texture. If false, we assume roughness squared was stored in the Gbuffer.
uint32_t roughnessChannel; ///< The channel to read the roughness from the materialParameters texture
float temporalStabilityFactor; ///< A boolean to describe the space used to store roughness in the materialParameters texture. If false, we assume roughness squared was stored in the Gbuffer.
float roughnessThreshold; ///< Regions with a roughness value greater than this threshold won't spawn rays.
uint32_t frameIndex; ///< The index of the current frame.
bool reset;
} FfxDenoiserReflectionsDispatchDescription;
/// A structure encapsulating the FidelityFX denoiser context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by Denoiser.
///
/// The <c><i>FfxDenoiserContext</i></c> object should have a lifetime matching
/// your use of Denoiser. Before destroying the Denoiser context care should be taken
/// to ensure the GPU is not accessing the resources created or used by Denoiser.
/// It is therefore recommended that the GPU is idle before destroying the
/// Denoiser context.
///
/// @ingroup FfxDenoiser
typedef struct FfxDenoiserContext {
uint32_t data[FFX_DENOISER_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxDenoiserContext;
/// Create a FidelityFX Denoiser context from the parameters
/// programmed to the <c><i>FfxDenoiserContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the
/// Denoiser API, and is responsible for the management of the internal resources
/// used by the Denoiser algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>backendInterface</i></c>
/// structure. This backend will attempt to retrieve the device capabilities,
/// and create the internal resources, and pipelines required by Denoiser to function.
/// Depending on the precise configuration used when
/// creating the <c><i>FfxDenoiserContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxDenoiserContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or shadow
/// denoising is disabled by a user. To destroy the Denoiser context you
/// should call <c><i>ffxDenoiserContextDestroy</i></c>.
///
/// @param [out] context A pointer to a <c><i>FfxDenoiserContext</i></c> structure to populate.
/// @param [in] contextDescription A pointer to a <c><i>FfxDenoiserContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxDenoiserContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxDenoiser
FFX_API FfxErrorCode ffxDenoiserContextCreate(FfxDenoiserContext* pContext, const FfxDenoiserContextDescription* pContextDescription);
/// Dispatches work to the FidelityFX Denoiser context
///
/// @param [out] context A pointer to a <c><i>FfxDenoiserContext</i></c> structure to populate.
/// @param [in] dispatchDescription A pointer to a <c><i>FfxDenoiserShadowsDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxDenoiser
FFX_API FfxErrorCode ffxDenoiserContextDispatchShadows(FfxDenoiserContext* context, const FfxDenoiserShadowsDispatchDescription* dispatchDescription);
/// Dispatches work to the FidelityFX Denoiser context
///
/// @param [out] context A pointer to a <c><i>FfxDenoiserContext</i></c> structure to populate.
/// @param [in] dispatchDescription A pointer to a <c><i>FfxDenoiserReflectionsDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxDenoiser
FFX_API FfxErrorCode ffxDenoiserContextDispatchReflections(FfxDenoiserContext* context, const FfxDenoiserReflectionsDispatchDescription* dispatchDescription);
/// Destroy the FidelityFX Denoiser context.
///
/// @param [out] context A pointer to a <c><i>FfxDenoiserContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FfxDenoiser
FFX_API FfxErrorCode ffxDenoiserContextDestroy(FfxDenoiserContext* context);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FfxDenoiser
FFX_API FfxVersionNumber ffxDenoiserGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,263 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup DOF
#pragma once
// Include the interface for the backend of the FSR2 API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup ffxDof FidelityFX DoF
/// FidelityFX Depth of Field runtime library
///
/// @ingroup SDKComponents
/// FidelityFX DOF major version.
///
/// @ingroup ffxDof
#define FFX_DOF_VERSION_MAJOR (1)
/// FidelityFX DOF minor version.
///
/// @ingroup ffxDof
#define FFX_DOF_VERSION_MINOR (1)
/// FidelityFX DOF patch version.
///
/// @ingroup ffxDof
#define FFX_DOF_VERSION_PATCH (0)
/// FidelityFX DOF context count
///
/// Defines the number of internal effect contexts required by DOF
///
/// @ingroup ffxDof
#define FFX_DOF_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup ffxDof
#define FFX_DOF_CONTEXT_SIZE (45664)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of the passes which constitute the DoF algorithm.
///
/// DOF is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxDofScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxDofPass</i></c>. For a
/// more comprehensive description of each pass, please refer to the DoF
/// reference documentation.
///
/// @ingroup ffxDof
typedef enum FfxDofPass {
FFX_DOF_PASS_DOWNSAMPLE_DEPTH = 0, ///< A pass which downsamples the depth buffer
FFX_DOF_PASS_DOWNSAMPLE_COLOR = 1, ///< A pass which downsamples the color buffer
FFX_DOF_PASS_DILATE = 2, ///< A pass which dilates the depth tile buffer
FFX_DOF_PASS_BLUR = 3, ///< A pass which performs the depth of field blur
FFX_DOF_PASS_COMPOSITE = 4, ///< A pass which combines the blurred images with the sharp input
FFX_DOF_PASS_COUNT ///< The number of passes in DOF
} FfxDofPass;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxDofContext</i></c>. See <c><i>FfxDofContextDescription</i></c>.
/// Curently, no flags exist.
///
/// @ingroup ffxDof
typedef enum FfxDofInitializationFlagBits {
FFX_DOF_REVERSE_DEPTH = (1 << 0), ///< A bit indicating whether input depth is reversed (1 is closest)
FFX_DOF_OUTPUT_PRE_INIT = (1 << 1), ///< A bit indicating whether the output is pre-initialized with the input color (e.g. it is the same texture)
FFX_DOF_DISABLE_RING_MERGE = (1 << 2), ///< A bit indicating whether to disable merging kernel rings
} FfxDofInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Depth of Field.
///
/// @ingroup ffxDof
typedef struct FfxDofContextDescription {
uint32_t flags; ///< A collection of @ref FfxDofInitializationFlagBits
uint32_t quality; ///< The number of rings to be used in the DoF blur kernel
FfxDimensions2D resolution; ///< Resolution of the input and output textures
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX
float cocLimitFactor; ///< The limit to apply to circle of confusion size as a factor for resolution height
} FfxDofContextDescription;
/// A structure encapsulating the parameters for dispatching
/// of FidelityFX Depth of Field
///
/// @ingroup ffxDof
typedef struct FfxDofDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record DoF rendering commands into.
FfxResource color; ///< The <c><i>FfxResource</i></c> containing color information
FfxResource depth; ///< The <c><i>FfxResource</i></c> containing depth information
FfxResource output; ///< The <c><i>FfxResource</i></c> to output into. Can be the same as the color input.
float cocScale; ///< The factor converting depth to circle of confusion size. Can be calculated using ffxDofCalculateCocScale.
float cocBias; ///< The bias to apply to circle of confusion size. Can be calculated using ffxDofCalculateCocBias.
} FfxDofDispatchDescription;
/// A structure encapsulating the FidelityFX Depth of Field context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by DoF.
///
/// The <c><i>FfxDofContext</i></c> object should have a lifetime matching
/// your use of DoF. Before destroying the DoF context care should be taken
/// to ensure the GPU is not accessing the resources created or used by DoF.
/// It is therefore recommended that the GPU is idle before destroying the
/// DoF context.
///
/// @ingroup ffxDof
typedef struct FfxDofContext {
uint32_t data[FFX_DOF_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxDofContext;
/// Create a FidelityFX Depth of Field context from the parameters
/// programmed to the <c><i>FfxDofContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the Depth of
/// Field API, and is responsible for the management of the internal resources
/// used by the DoF algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>backendInterface</i></c>
/// structure. This backend will attempt to retrieve the device capabilities,
/// and create the internal resources, and pipelines required by DoF to function.
/// Depending on the precise configuration used when
/// creating the <c><i>FfxDofContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxDofContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or DoF
/// is disabled by a user. To destroy the DoF context you
/// should call <c><i>ffxDofContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxDofContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxDofContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxDofContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxDof
FFX_API FfxErrorCode ffxDofContextCreate(FfxDofContext* pContext, const FfxDofContextDescription* pContextDescription);
/// Dispatches work to the FidelityFX DoF context
///
/// @param [in] pContext A pointer to a <c><i>FfxDofContext</i></c> structure.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxDofDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxDof
FFX_API FfxErrorCode ffxDofContextDispatch(FfxDofContext* pContext, const FfxDofDispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX DoF context.
///
/// @param [out] pContext A pointer to a <c><i>FfxDofContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup ffxDof
FFX_API FfxErrorCode ffxDofContextDestroy(FfxDofContext* pContext);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxDof
FFX_API FfxVersionNumber ffxDofGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)
/// Calculates the scale parameter in the thin lens model according to lens and projection parameters.
/// @param aperture Aperture radius in view space units
/// @param focus Distance to focus plane in view space units
/// @param focalLength Lens focal length in view space units
/// @param conversion Conversion factor for view units to pixels (i.e. image width in pixels / sensor size)
/// @param proj33 Element (3,3) of the projection matrix (z range scale)
/// @param proj34 Element (3,4) of the projection matrix (z range offset)
/// @param proj43 Element (4,3) of the projection matrix (typically 1 or -1)
///
/// @ingroup ffxDof
static inline float ffxDofCalculateCocScale(float aperture, float focus, float focalLength, float conversion,
float proj33, float proj34, float proj43)
{
(void)proj33;
// z = (vd * proj33 + proj34) / (vd * proj43) = proj33/proj43 + proj34/(vd*proj43)
// => view depth = proj34 / (z*proj43 - proj33)
// C = (A * L * (F - D)) / (D * (F - L))
// = AL/(F-L) * (F/D - 1)
// = AL/(F-L) * (F(z*p43-p33)/p34 - 1) ignore non-factor terms
// = AL/(F-L) * (F(z*p43-.)/p34 - .)
// = AL/(F-L) * (F(z*p43-.)/p34 - .)
// = AL/(F-L) * F*z*p43/p34 + .
// = z * AL/(F-L) * F*p43/p34 + .
float absFocus = focus < 0 ? -focus : focus;
float commonFactor = conversion * aperture * focalLength / (absFocus - focalLength);
return commonFactor * focus * (proj43 / proj34);
}
/// Calculates the bias parameter in the thin lens model according to lens and projection parameters.
/// @param aperture Aperture radius in view space units
/// @param focus Distance to focus plane in view space units
/// @param focalLength Lens focal length in view space units
/// @param conversion Conversion factor for view units to pixels (i.e. image width in pixels / sensor size)
/// @param proj33 Element (3,3) of the projection matrix (a.k.a. z range scale)
/// @param proj34 Element (3,4) of the projection matrix (a.k.a. z range offset)
/// @param proj43 Element (4,3) of the projection matrix (typically 1 or -1)
///
/// @ingroup ffxDof
static inline float ffxDofCalculateCocBias(float aperture, float focus, float focalLength, float conversion,
float proj33, float proj34, float proj43)
{
(void)proj43;
// z = (D * proj33 + proj34) / (D * proj43) = proj33/proj43 + proj34/(D*proj43)
// => view depth D = proj34 / (z*proj43 - proj33)
// C = (A * L * (F - D)) / (D * (F - L))
// = AL/(F-L) * (F/D - 1)
// = AL/(F-L) * (F(z*p43-p33)/p34 - 1) ignore factor terms
// = AL/(F-L) * (F(0*p43-p33)/p34 - 1)
// = AL/(F-L) * (-F*p33/p34 - 1)
float absFocus = focus < 0 ? -focus : focus;
float commonFactor = conversion * aperture * focalLength / (absFocus - focalLength);
return commonFactor * (-focus * (proj33 / proj34) - 1);
}

View File

@@ -0,0 +1,78 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <FidelityFX/host/ffx_types.h>
/// @defgroup Errors Error Codes
/// Error codes returned from FidelityFX SDK functions
///
/// @ingroup ffxHost
/// Typedef for error codes returned from functions in the FidelityFX SDK.
///
/// @ingroup Errors
typedef int32_t FfxErrorCode;
/// Error codes and their meaning
///
/// @ingroup Errors
typedef enum FfxErrorCodes {
FFX_OK = 0, ///< The operation completed successfully.
FFX_ERROR_INVALID_POINTER = 0x80000000, ///< The operation failed due to an invalid pointer.
FFX_ERROR_INVALID_ALIGNMENT = 0x80000001, ///< The operation failed due to an invalid alignment.
FFX_ERROR_INVALID_SIZE = 0x80000002, ///< The operation failed due to an invalid size.
FFX_EOF = 0x80000003, ///< The end of the file was encountered.
FFX_ERROR_INVALID_PATH = 0x80000004, ///< The operation failed because the specified path was invalid.
FFX_ERROR_EOF = 0x80000005, ///< The operation failed because end of file was reached.
FFX_ERROR_MALFORMED_DATA = 0x80000006, ///< The operation failed because of some malformed data.
FFX_ERROR_OUT_OF_MEMORY = 0x80000007, ///< The operation failed because it ran out memory.
FFX_ERROR_INCOMPLETE_INTERFACE = 0x80000008, ///< The operation failed because the interface was not fully configured.
FFX_ERROR_INVALID_ENUM = 0x80000009, ///< The operation failed because of an invalid enumeration value.
FFX_ERROR_INVALID_ARGUMENT = 0x8000000a, ///< The operation failed because an argument was invalid.
FFX_ERROR_OUT_OF_RANGE = 0x8000000b, ///< The operation failed because a value was out of range.
FFX_ERROR_NULL_DEVICE = 0x8000000c, ///< The operation failed because a device was null.
FFX_ERROR_BACKEND_API_ERROR = 0x8000000d, ///< The operation failed because the backend API returned an error code.
FFX_ERROR_INSUFFICIENT_MEMORY = 0x8000000e, ///< The operation failed because there was not enough memory.
FFX_ERROR_INVALID_VERSION = 0x8000000f, ///< The operation failed because the wrong backend was linked.
}FfxErrorCodes;
/// Helper macro to return error code y from a function when a specific condition, x, is not met.
///
/// @ingroup Errors
#define FFX_RETURN_ON_ERROR(x, y) \
if (!(x)) \
{ \
return (y); \
}
/// Helper macro to return error code x from a function when it is not FFX_OK.
///
/// @ingroup Errors
#define FFX_VALIDATE(x) \
{ \
FfxErrorCode ret = x; \
FFX_RETURN_ON_ERROR(ret == FFX_OK, ret); \
}

View File

@@ -0,0 +1,274 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup FRAMEINTERPOLATION
#pragma once
// Include the interface for the backend of the Frameinterpolation API.
#include <FidelityFX/host/ffx_interface.h>
/// FidelityFX Frameinterpolation major version.
///
/// @ingroup FRAMEINTERPOLATIONFRAMEINTERPOLATION
#define FFX_FRAMEINTERPOLATION_VERSION_MAJOR (1)
/// FidelityFX Frameinterpolation minor version.
///
/// @ingroup FRAMEINTERPOLATIONFRAMEINTERPOLATION
#define FFX_FRAMEINTERPOLATION_VERSION_MINOR (1)
/// FidelityFX Frameinterpolation patch version.
///
/// @ingroup FRAMEINTERPOLATIONFRAMEINTERPOLATION
#define FFX_FRAMEINTERPOLATION_VERSION_PATCH (0)
/// FidelityFX Frame Interpolation context count
///
/// Defines the number of internal effect contexts required by Frame Interpolation
///
/// @ingroup ffxFrameInterpolation
#define FFX_FRAMEINTERPOLATION_CONTEXT_COUNT (1)
/// The size of the context specified in 32bit values.
///
/// @ingroup FRAMEINTERPOLATIONFRAMEINTERPOLATION
#define FFX_FRAMEINTERPOLATION_CONTEXT_SIZE (FFX_SDK_DEFAULT_CONTEXT_SIZE)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of all the passes which constitute the FSR3 algorithm.
///
/// FSR3 is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxFsr3ScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxFsr3Pass</i></c>. For a
/// more comprehensive description of each pass, please refer to the FSR3
/// reference documentation.
///
/// Please note in some cases e.g.: <c><i>FFX_FSR3_PASS_ACCUMULATE</i></c>
/// and <c><i>FFX_FSR3_PASS_ACCUMULATE_SHARPEN</i></c> either one pass or the
/// other will be used (they are mutually exclusive). The choice of which will
/// depend on the way the <c><i>FfxFsr3Context</i></c> is created and the
/// precise contents of <c><i>FfxFsr3DispatchParamters</i></c> each time a call
/// is made to <c><i>ffxFsr3ContextDispatch</i></c>.
///
/// @ingroup FRAMEINTERPOLATIONFRAMEINTERPOLATION
typedef enum FfxFrameInterpolationPass
{
FFX_FRAMEINTERPOLATION_PASS_RECONSTRUCT_AND_DILATE,
FFX_FRAMEINTERPOLATION_PASS_SETUP,
FFX_FRAMEINTERPOLATION_PASS_RECONSTRUCT_PREV_DEPTH,
FFX_FRAMEINTERPOLATION_PASS_GAME_MOTION_VECTOR_FIELD,
FFX_FRAMEINTERPOLATION_PASS_OPTICAL_FLOW_VECTOR_FIELD,
FFX_FRAMEINTERPOLATION_PASS_DISOCCLUSION_MASK,
FFX_FRAMEINTERPOLATION_PASS_INTERPOLATION,
FFX_FRAMEINTERPOLATION_PASS_INPAINTING_PYRAMID,
FFX_FRAMEINTERPOLATION_PASS_INPAINTING,
FFX_FRAMEINTERPOLATION_PASS_GAME_VECTOR_FIELD_INPAINTING_PYRAMID,
FFX_FRAMEINTERPOLATION_PASS_DEBUG_VIEW,
FFX_FRAMEINTERPOLATION_PASS_COUNT ///< The number of passes performed by FrameInterpolation.
} FfxFrameInterpolationPass;
// forward declarations
struct FfxFrameInterpolationContext;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxFrameInterpolationContext</i></c>. See <c><i>FfxFrameInterpolationContextDescription</i></c>.
///
/// @ingroup FRAMEINTERPOLATIONFRAMEINTERPOLATION
typedef enum FfxFrameInterpolationInitializationFlagBits {
FFX_FRAMEINTERPOLATION_ENABLE_DEPTH_INVERTED = (1<<0), ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
FFX_FRAMEINTERPOLATION_ENABLE_DEPTH_INFINITE = (1<<1), ///< A bit indicating that the input depth buffer data provided is using an infinite far plane.
FFX_FRAMEINTERPOLATION_ENABLE_TEXTURE1D_USAGE = (1<<2), ///< A bit indicating that the backend should use 1D textures.
FFX_FRAMEINTERPOLATION_ENABLE_HDR_COLOR_INPUT = (1<<3), ///< A bit indicating that HDR values are present in the imaging pipeline.
FFX_FRAMEINTERPOLATION_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS = (1<<4), ///< A bit indicating if the motion vectors are rendered at display resolution.
FFX_FRAMEINTERPOLATION_ENABLE_JITTER_MOTION_VECTORS = (1<<5),
FFX_FRAMEINTERPOLATION_ENABLE_ASYNC_SUPPORT = (1<<6),
} FfxFrameInterpolationInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize
/// FidelityFX Frameinterpolation upscaling.
///
/// @ingroup FRAMEINTERPOLATION
typedef struct FfxFrameInterpolationContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxFrameInterpolationInitializationFlagBits</i></c>.
FfxDimensions2D maxRenderSize; ///< The maximum size that rendering will be performed at.
FfxDimensions2D displaySize; ///< The size of the presentation resolution
FfxSurfaceFormat backBufferFormat;
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX SDK
} FfxFrameInterpolationContextDescription;
/// A structure encapsulating the FidelityFX Super Resolution 2 context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by FSR3.
///
/// The <c><i>FfxFsr3Context</i></c> object should have a lifetime matching
/// your use of FSR3. Before destroying the FSR3 context care should be taken
/// to ensure the GPU is not accessing the resources created or used by FSR3.
/// It is therefore recommended that the GPU is idle before destroying the
/// FSR3 context.
///
/// @ingroup FRAMEINTERPOLATION
typedef struct FfxFrameInterpolationContext
{
uint32_t data[FFX_FRAMEINTERPOLATION_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxFrameInterpolationContext;
/// Create a FidelityFX Super Resolution 2 context from the parameters
/// programmed to the <c><i>FfxFsr3CreateParams</i></c> structure.
///
/// The context structure is the main object used to interact with the FSR3
/// API, and is responsible for the management of the internal resources used
/// by the FSR3 algorithm. When this API is called, multiple calls will be
/// made via the pointers contained in the <c><i>callbacks</i></c> structure.
/// These callbacks will attempt to retreive the device capabilities, and
/// create the internal resources, and pipelines required by FSR3's
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxFsr3Context</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The flags included in the <c><i>flags</i></c> field of
/// <c><i>FfxFsr3Context</i></c> how match the configuration of your
/// application as well as the intended use of FSR3. It is important that these
/// flags are set correctly (as well as a correct programmed
/// <c><i>FfxFsr3DispatchDescription</i></c>) to ensure correct operation. It is
/// recommended to consult the overview documentation for further details on
/// how FSR3 should be integerated into an application.
///
/// When the <c><i>FfxFsr3Context</i></c> is created, you should use the
/// <c><i>ffxFsr3ContextDispatch</i></c> function each frame where FSR3
/// upscaling should be applied. See the documentation of
/// <c><i>ffxFsr3ContextDispatch</i></c> for more details.
///
/// The <c><i>FfxFsr3Context</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or FSR3 upscaling is
/// disabled by a user. To destroy the FSR3 context you should call
/// <c><i>ffxFsr3ContextDestroy</i></c>.
///
/// @param [out] context A pointer to a <c><i>FfxFsr3Context</i></c> structure to populate.
/// @param [in] contextDescription A pointer to a <c><i>FfxFsr3ContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxFsr3ContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FRAMEINTERPOLATION
FFX_API FfxErrorCode ffxFrameInterpolationContextCreate(FfxFrameInterpolationContext* context, FfxFrameInterpolationContextDescription* contextDescription);
FFX_API FfxErrorCode ffxFrameInterpolationContextGetGpuMemoryUsage(FfxFrameInterpolationContext* pContext, FfxEffectMemoryUsage* vramUsage);
typedef struct FfxFrameInterpolationPrepareDescription
{
uint32_t flags; ///< combination of FfxFrameInterpolationDispatchFlags
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record frame interpolation commands into.
FfxDimensions2D renderSize; ///< The dimensions used to render game content, dilatedDepth, dilatedMotionVectors are expected to be of ths size.
FfxFloatCoords2D jitterOffset; ///< The subpixel jitter offset applied to the camera. jitter;
FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors. motionVectorScale;
float frameTimeDelta;
float cameraNear;
float cameraFar;
float viewSpaceToMetersFactor;
float cameraFovAngleVertical;
FfxResource depth; ///< The depth buffer data
FfxResource motionVectors; ///< The motion vector data
uint64_t frameID;
} FfxFrameInterpolationPrepareDescription;
FFX_API FfxErrorCode ffxFrameInterpolationPrepare(FfxFrameInterpolationContext* context, const FfxFrameInterpolationPrepareDescription* params);
typedef enum FfxFrameInterpolationDispatchFlags
{
FFX_FRAMEINTERPOLATION_DISPATCH_DRAW_DEBUG_TEAR_LINES = (1 << 0), ///< A bit indicating that the debug tear lines will be drawn to the interpolated output.
FFX_FRAMEINTERPOLATION_DISPATCH_DRAW_DEBUG_RESET_INDICATORS = (1 << 1), ///< A bit indicating that the debug reset indicators will be drawn to the generated output.
FFX_FRAMEINTERPOLATION_DISPATCH_DRAW_DEBUG_VIEW = (1 << 2), ///< A bit indicating that the interpolated output resource will contain debug views with relevant information.
} FfxFrameInterpolationDispatchFlags;
typedef struct FfxFrameInterpolationDispatchDescription {
uint32_t flags; ///< combination of FfxFrameInterpolationDispatchFlags
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record frame interpolation commands into.
FfxDimensions2D displaySize; ///< The destination output dimensions
FfxDimensions2D renderSize; ///< The dimensions used to render game content, dilatedDepth, dilatedMotionVectors are expected to be of ths size.
FfxResource currentBackBuffer; ///< The current presentation color, if currentBackBuffer_HUDLess is not used, this will be used as interpolation source data.
FfxResource currentBackBuffer_HUDLess; ///< The current presentation color without HUD content, when use it will be used as interpolation source data.
FfxResource output; ///< The output resource where to store the interpolated result.
FfxRect2D interpolationRect; ///< The area of the backbuffer that should be used for interpolation in case only a part of the screen is used e.g. due to movie bars
FfxResource opticalFlowVector; ///< The optical flow motion vectors (see example computation in the FfxOpticalFlow effect)
FfxResource opticalFlowSceneChangeDetection; ///< The optical flow scene change detection data
FfxDimensions2D opticalFlowBufferSize; ///< The optical flow motion vector resource dimensions
FfxFloatCoords2D opticalFlowScale; ///< The optical flow motion vector scale factor, used to scale resoure values into [0.0,1.0] range.
int opticalFlowBlockSize; ///< The optical flow block dimension size
float cameraNear; ///< The distance to the near plane of the camera.
float cameraFar; ///< The distance to the far plane of the camera. This is used only used in case of non infinite depth.
float cameraFovAngleVertical; ///< The camera angle field of view in the vertical direction (expressed in radians).
float viewSpaceToMetersFactor; ///< The unit to scale view space coordinates to meters.
float frameTimeDelta; ///< The time elapsed since the last frame (expressed in milliseconds).
bool reset; ///< A boolean value which when set to true, indicates the camera has moved discontinuously.
FfxBackbufferTransferFunction backBufferTransferFunction; ///< The transfer function use to convert interpolation source color data to linear RGB.
float minMaxLuminance[2]; ///< Min and max luminance values, used when converting HDR colors to linear RGB
uint64_t frameID; ///< Identifier used to select internal resources when async support is enabled. Must increment by exactly one (1) for each frame. Any non-exactly-one difference will reset the frame generation logic.
} FfxFrameInterpolationDispatchDescription;
FFX_API FfxErrorCode ffxFrameInterpolationDispatch(FfxFrameInterpolationContext* context, const FfxFrameInterpolationDispatchDescription* params);
/// Destroy the FidelityFX Super Resolution context.
///
/// @param [out] context A pointer to a <c><i>FfxFsr3Context</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FRAMEINTERPOLATION
FFX_API FfxErrorCode ffxFrameInterpolationContextDestroy(FfxFrameInterpolationContext* context);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FRAMEINTERPOLATION
FFX_API FfxVersionNumber ffxFrameInterpolationGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,297 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/// @defgroup ffxFsr1 FidelityFX FSR1
/// FidelityFX Super Resolution 1 runtime library
///
/// @ingroup SDKComponents
#pragma once
/// Include the interface for the backend of the FSR 1.0 API.
///
/// @ingroup ffxFsr1
#include <FidelityFX/host/ffx_interface.h>
/// FidelityFX Super Resolution 1.0 major version.
///
/// @ingroup ffxFsr1
#define FFX_FSR1_VERSION_MAJOR (1)
/// FidelityFX Super Resolution 1.0 minor version.
///
/// @ingroup ffxFsr1
#define FFX_FSR1_VERSION_MINOR (2)
/// FidelityFX Super Resolution 1.0 patch version.
///
/// @ingroup ffxFsr1
#define FFX_FSR1_VERSION_PATCH (0)
/// FidelityFX Super Resolution 1.0 context count
///
/// Defines the number of internal effect contexts required by FSR1
///
/// @ingroup ffxFsr1
#define FFX_FSR1_CONTEXT_COUNT 2
/// The size of the context specified in 32bit values.
///
/// @ingroup ffxFsr1
#define FFX_FSR1_CONTEXT_SIZE (27442)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of all the passes which constitute the FSR1 algorithm.
///
/// FSR1 is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxFsr1ScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxFsr1Pass</i></c>. For a
/// more comprehensive description of each pass, please refer to the FSR1
/// reference documentation.
///
/// @ingroup ffxFsr1
typedef enum FfxFsr1Pass
{
FFX_FSR1_PASS_EASU = 0, ///< A pass which upscales the color buffer using easu.
FFX_FSR1_PASS_EASU_RCAS = 1, ///< A pass which upscales the color buffer in preparation for rcas
FFX_FSR1_PASS_RCAS = 2, ///< A pass which performs rcas sharpening on the upscaled image.
FFX_FSR1_PASS_COUNT ///< The number of passes performed by FSR2.
} FfxFsr1Pass;
/// An enumeration of all the quality modes supported by FidelityFX Super
/// Resolution 1 upscaling.
///
/// In order to provide a consistent user experience across multiple
/// applications which implement FSR1. It is strongly recommended that the
/// following preset scaling factors are made available through your
/// application's user interface.
///
/// If your application does not expose the notion of preset scaling factors
/// for upscaling algorithms (perhaps instead implementing a fixed ratio which
/// is immutable) or implementing a more dynamic scaling scheme (such as
/// dynamic resolution scaling), then there is no need to use these presets.
///
/// @ingroup ffxFsr1
typedef enum FfxFsr1QualityMode {
FFX_FSR1_QUALITY_MODE_ULTRA_QUALITY = 0, ///< Perform upscaling with a per-dimension upscaling ratio of 1.3x.
FFX_FSR1_QUALITY_MODE_QUALITY = 1, ///< Perform upscaling with a per-dimension upscaling ratio of 1.5x.
FFX_FSR1_QUALITY_MODE_BALANCED = 2, ///< Perform upscaling with a per-dimension upscaling ratio of 1.7x.
FFX_FSR1_QUALITY_MODE_PERFORMANCE = 3 ///< Perform upscaling with a per-dimension upscaling ratio of 2.0x.
} FfxFsr1QualityMode;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxFsr1Context</i></c>. See <c><i>FfxFsr1ContextDescription</i></c>.
///
/// @ingroup ffxFsr1
typedef enum FfxFsr1InitializationFlagBits {
FFX_FSR1_ENABLE_RCAS = (1 << 0), ///< A bit indicating if we should use rcas.
FFX_FSR1_RCAS_PASSTHROUGH_ALPHA = (1 << 1), ///< A bit indicating if we should use passthrough alpha during rcas.
FFX_FSR1_RCAS_DENOISE = (1 << 2), ///< A bit indicating if denoising is invoked during rcas.
FFX_FSR1_ENABLE_HIGH_DYNAMIC_RANGE = (1 << 3), ///< A bit indicating if the input color data provided is using a high-dynamic range.
FFX_FSR1_ENABLE_SRGB_CONVERSIONS = (1 << 4), ///< A bit indicating that input/output resources require gamma conversions
} FfxFsr1InitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Super Resolution 1.0
///
/// @ingroup ffxFsr1
typedef struct FfxFsr1ContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxFsr1InitializationFlagBits</i></c>.
FfxSurfaceFormat outputFormat; ///< Format of the output target used for creation of the internal upscale resource
FfxDimensions2D maxRenderSize; ///< The maximum size that rendering will be performed at.
FfxDimensions2D displaySize; ///< The size of the presentation resolution targeted by the upscaling process.
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FSR1.
} FfxFsr1ContextDescription;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX Super Resolution 1.0
///
/// @ingroup ffxFsr1
typedef struct FfxFsr1DispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR1 rendering commands into.
FfxResource color; ///< A <c><i>FfxResource</i></c> containing the color buffer for the current frame (at render resolution).
FfxResource output; ///< A <c><i>FfxResource</i></c> containing the output color buffer for the current frame (at presentation resolution).
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resource.
bool enableSharpening; ///< Enable an additional sharpening pass.
float sharpness; ///< The sharpness value between 0 and 1, where 0 is no additional sharpness and 1 is maximum additional sharpness.
} FfxFsr1DispatchDescription;
/// A structure encapsulating the FidelityFX Super Resolution 1.0 context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by FSR1.
///
/// The <c><i>FfxFsr1Context</i></c> object should have a lifetime matching
/// your use of FSR1. Before destroying the FSR1 context care should be taken
/// to ensure the GPU is not accessing the resources created or used by FSR1.
/// It is therefore recommended that the GPU is idle before destroying the
/// FSR1 context.
///
/// @ingroup ffxFsr1
typedef struct FfxFsr1Context {
uint32_t data[FFX_FSR1_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxFsr1Context;
/// Create a FidelityFX Super Resolution 1.0 context from the parameters
/// programmed to the <c><i>FfxFsr1ContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the Super
/// Resoution 1.0 API, and is responsible for the management of the internal resources
/// used by the FSR1 algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>callbacks</i></c>
/// structure. These callbacks will attempt to retreive the device capabilities,
/// and create the internal resources, and pipelines required by FSR1
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxFsr1Context</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxParallelSortContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or FSR1
/// upscaling is disabled by a user. To destroy the FSR1 context you
/// should call <c><i>ffxFsr1ContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxFsr1Context</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxFsr1ContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxFsr1ContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxFsr1
FFX_API FfxErrorCode ffxFsr1ContextCreate(FfxFsr1Context* pContext, const FfxFsr1ContextDescription* pContextDescription);
/// Get GPU memory usage of the FidelityFX Super Resolution context.
///
/// @param [in] pContext A pointer to a <c><i>FfxFsr1Context</i></c> structure.
/// @param [out] pVramUsage A pointer to a <c><i>FfxEffectMemoryUsage</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>vramUsage</i></c> were <c><i>NULL</i></c>.
///
/// @ingroup ffxFsr1
FFX_API FfxErrorCode ffxFsr1ContextGetGpuMemoryUsage(FfxFsr1Context* pContext, FfxEffectMemoryUsage* pVramUsage);
/// @param [out] pContext A pointer to a <c><i>FfxFsr1Context</i></c> structure to populate.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxFsr1DispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxFsr1
FFX_API FfxErrorCode ffxFsr1ContextDispatch(FfxFsr1Context* pContext, const FfxFsr1DispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX FSR 1 context.
///
/// @param [out] pContext A pointer to a <c><i>FfxFsr1Context</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup ffxFsr1
FFX_API FfxErrorCode ffxFsr1ContextDestroy(FfxFsr1Context* pContext);
/// Get the upscale ratio from the quality mode.
///
/// The following table enumerates the mapping of the quality modes to
/// per-dimension scaling ratios.
///
/// Quality preset | Scale factor
/// ----------------------------------------------------- | -------------
/// <c><i>FFX_FSR1_QUALITY_MODE_ULTRA_QUALITY</i></c> | 1.3x
/// <c><i>FFX_FSR1_QUALITY_MODE_QUALITY</i></c> | 1.5x
/// <c><i>FFX_FSR1_QUALITY_MODE_BALANCED</i></c> | 1.7x
/// <c><i>FFX_FSR1_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x
///
/// Passing an invalid <c><i>qualityMode</i></c> will return 0.0f.
///
/// @param [in] qualityMode The quality mode preset.
///
/// @returns
/// The upscaling the per-dimension upscaling ratio for
/// <c><i>qualityMode</i></c> according to the table above.
///
/// @ingroup ffxFsr1
FFX_API float ffxFsr1GetUpscaleRatioFromQualityMode(FfxFsr1QualityMode qualityMode);
/// A helper function to calculate the rendering resolution from a target
/// resolution and desired quality level.
///
/// This function applies the scaling factor returned by
/// <c><i>ffxFsr1GetUpscaleRatioFromQualityMode</i></c> to each dimension.
///
/// @param [out] pRenderWidth A pointer to a <c>uint32_t</c> which will hold the calculated render resolution width.
/// @param [out] pRenderHeight A pointer to a <c>uint32_t</c> which will hold the calculated render resolution height.
/// @param [in] displayWidth The target display resolution width.
/// @param [in] displayHeight The target display resolution height.
/// @param [in] qualityMode The desired quality mode for FSR1 upscaling.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER Either <c><i>renderWidth</i></c> or <c><i>renderHeight</i></c> was <c>NULL</c>.
/// @retval
/// FFX_ERROR_INVALID_ENUM An invalid quality mode was specified.
///
/// @ingroup ffxFsr1
FFX_API FfxErrorCode ffxFsr1GetRenderResolutionFromQualityMode(
uint32_t* pRenderWidth,
uint32_t* pRenderHeight,
uint32_t displayWidth,
uint32_t displayHeight,
FfxFsr1QualityMode qualityMode);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxFsr1
FFX_API FfxVersionNumber ffxFsr1GetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,530 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
// Include the interface for the backend of the FSR2 API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup ffxFsr2 FidelityFX FSR2
/// FidelityFX Super Resolution 2 runtime library
///
/// @ingroup SDKComponents
/// FidelityFX Super Resolution 2 major version.
///
/// @ingroup ffxFsr2
#define FFX_FSR2_VERSION_MAJOR (2)
/// FidelityFX Super Resolution 2 minor version.
///
/// @ingroup ffxFsr2
#define FFX_FSR2_VERSION_MINOR (3)
/// FidelityFX Super Resolution 2 patch version.
///
/// @ingroup ffxFsr2
#define FFX_FSR2_VERSION_PATCH (2)
/// FidelityFX Super Resolution 2 context count
///
/// Defines the number of internal effect contexts required by FSR2
///
/// @ingroup ffxFsr2
#define FFX_FSR2_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup ffxFsr2
#define FFX_FSR2_CONTEXT_SIZE (FFX_SDK_DEFAULT_CONTEXT_SIZE)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of all the passes which constitute the FSR2 algorithm.
///
/// FSR2 is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxFsr2ScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxFsr2Pass</i></c>. For a
/// more comprehensive description of each pass, please refer to the FSR2
/// reference documentation.
///
/// Please note in some cases e.g.: <c><i>FFX_FSR2_PASS_ACCUMULATE</i></c>
/// and <c><i>FFX_FSR2_PASS_ACCUMULATE_SHARPEN</i></c> either one pass or the
/// other will be used (they are mutually exclusive). The choice of which will
/// depend on the way the <c><i>FfxFsr2Context</i></c> is created and the
/// precise contents of <c><i>FfxFsr2DispatchParamters</i></c> each time a call
/// is made to <c><i>ffxFsr2ContextDispatch</i></c>.
///
/// @ingroup ffxFsr2
typedef enum FfxFsr2Pass
{
FFX_FSR2_PASS_DEPTH_CLIP = 0, ///< A pass which performs depth clipping.
FFX_FSR2_PASS_RECONSTRUCT_PREVIOUS_DEPTH = 1, ///< A pass which performs reconstruction of previous frame's depth.
FFX_FSR2_PASS_LOCK = 2, ///< A pass which calculates pixel locks.
FFX_FSR2_PASS_ACCUMULATE = 3, ///< A pass which performs upscaling.
FFX_FSR2_PASS_ACCUMULATE_SHARPEN = 4, ///< A pass which performs upscaling when sharpening is used.
FFX_FSR2_PASS_RCAS = 5, ///< A pass which performs sharpening.
FFX_FSR2_PASS_COMPUTE_LUMINANCE_PYRAMID = 6, ///< A pass which generates the luminance mipmap chain for the current frame.
FFX_FSR2_PASS_GENERATE_REACTIVE = 7, ///< An optional pass to generate a reactive mask.
FFX_FSR2_PASS_TCR_AUTOGENERATE = 8, ///< An optional pass to automatically generate transparency/composition and reactive masks.
FFX_FSR2_PASS_COUNT ///< The number of passes performed by FSR2.
} FfxFsr2Pass;
/// An enumeration of all the quality modes supported by FidelityFX Super
/// Resolution 2 upscaling.
///
/// In order to provide a consistent user experience across multiple
/// applications which implement FSR2. It is strongly recommended that the
/// following preset scaling factors are made available through your
/// application's user interface.
///
/// If your application does not expose the notion of preset scaling factors
/// for upscaling algorithms (perhaps instead implementing a fixed ratio which
/// is immutable) or implementing a more dynamic scaling scheme (such as
/// dynamic resolution scaling), then there is no need to use these presets.
///
/// Please note that <c><i>FFX_FSR2_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> is
/// an optional mode which may introduce significant quality degradation in the
/// final image. As such it is recommended that you evaluate the final results
/// of using this scaling mode before deciding if you should include it in your
/// application.
///
/// @ingroup ffxFsr2
typedef enum FfxFsr2QualityMode {
FFX_FSR2_QUALITY_MODE_QUALITY = 1, ///< Perform upscaling with a per-dimension upscaling ratio of 1.5x.
FFX_FSR2_QUALITY_MODE_BALANCED = 2, ///< Perform upscaling with a per-dimension upscaling ratio of 1.7x.
FFX_FSR2_QUALITY_MODE_PERFORMANCE = 3, ///< Perform upscaling with a per-dimension upscaling ratio of 2.0x.
FFX_FSR2_QUALITY_MODE_ULTRA_PERFORMANCE = 4 ///< Perform upscaling with a per-dimension upscaling ratio of 3.0x.
} FfxFsr2QualityMode;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxFsr2Context</i></c>. See <c><i>FfxFsr2ContextDescription</i></c>.
///
/// @ingroup ffxFsr2
typedef enum FfxFsr2InitializationFlagBits {
FFX_FSR2_ENABLE_HIGH_DYNAMIC_RANGE = (1<<0), ///< A bit indicating if the input color data provided is using a high-dynamic range.
FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS = (1<<1), ///< A bit indicating if the motion vectors are rendered at display resolution.
FFX_FSR2_ENABLE_MOTION_VECTORS_JITTER_CANCELLATION = (1<<2), ///< A bit indicating that the motion vectors have the jittering pattern applied to them.
FFX_FSR2_ENABLE_DEPTH_INVERTED = (1<<3), ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
FFX_FSR2_ENABLE_DEPTH_INFINITE = (1<<4), ///< A bit indicating that the input depth buffer data provided is using an infinite far plane.
FFX_FSR2_ENABLE_AUTO_EXPOSURE = (1<<5), ///< A bit indicating if automatic exposure should be applied to input color data.
FFX_FSR2_ENABLE_DYNAMIC_RESOLUTION = (1<<6), ///< A bit indicating that the application uses dynamic resolution scaling.
FFX_FSR2_ENABLE_TEXTURE1D_USAGE = (1<<7), ///< A bit indicating that the backend should use 1D textures.
FFX_FSR2_ENABLE_DEBUG_CHECKING = (1<<8), ///< A bit indicating that the runtime should check some API values and report issues.
} FfxFsr2InitializationFlagBits;
/// Pass a string message
///
/// Used for debug messages.
///
/// @param [in] type The type of message.
/// @param [in] message A string message to pass.
///
///
/// @ingroup ffxFsr2
typedef void(*FfxFsr2Message)(
FfxMsgType type,
const wchar_t* message);
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Super Resolution 2 upscaling.
///
/// @ingroup ffxFsr2
typedef struct FfxFsr2ContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxFsr2InitializationFlagBits</i></c>.
FfxDimensions2D maxRenderSize; ///< The maximum size that rendering will be performed at.
FfxDimensions2D displaySize; ///< The size of the presentation resolution targeted by the upscaling process.
FfxFsr2Message fpMessage; ///< A pointer to a function that can receive messages from the runtime.
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX SDK
} FfxFsr2ContextDescription;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX Super Resolution 2.
///
/// @ingroup ffxFsr2
typedef struct FfxFsr2DispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR2 rendering commands into.
FfxResource color; ///< A <c><i>FfxResource</i></c> containing the color buffer for the current frame (at render resolution).
FfxResource depth; ///< A <c><i>FfxResource</i></c> containing 32bit depth values for the current frame (at render resolution).
FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing 2-dimensional motion vectors (at render resolution if <c><i>FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS</i></c> is not set).
FfxResource exposure; ///< A optional <c><i>FfxResource</i></c> containing a 1x1 exposure value.
FfxResource reactive; ///< A optional <c><i>FfxResource</i></c> containing alpha value of reactive objects in the scene.
FfxResource transparencyAndComposition; ///< A optional <c><i>FfxResource</i></c> containing alpha value of special objects in the scene.
FfxResource output; ///< A <c><i>FfxResource</i></c> containing the output color buffer for the current frame (at presentation resolution).
FfxFloatCoords2D jitterOffset; ///< The subpixel jitter offset applied to the camera.
FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
bool enableSharpening; ///< Enable an additional sharpening pass.
float sharpness; ///< The sharpness value between 0 and 1, where 0 is no additional sharpness and 1 is maximum additional sharpness.
float frameTimeDelta; ///< The time elapsed since the last frame (expressed in milliseconds).
float preExposure; ///< The pre exposure value (must be > 0.0f)
bool reset; ///< A boolean value which when set to true, indicates the camera has moved discontinuously.
float cameraNear; ///< The distance to the near plane of the camera.
float cameraFar; ///< The distance to the far plane of the camera.
float cameraFovAngleVertical; ///< The camera angle field of view in the vertical direction (expressed in radians).
float viewSpaceToMetersFactor; ///< The scale factor to convert view space units to meters
// EXPERIMENTAL reactive mask generation parameters
bool enableAutoReactive; ///< A boolean value to indicate internal reactive autogeneration should be used
FfxResource colorOpaqueOnly; ///< A <c><i>FfxResource</i></c> containing the opaque only color buffer for the current frame (at render resolution).
float autoTcThreshold; ///< Cutoff value for TC
float autoTcScale; ///< A value to scale the transparency and composition mask
float autoReactiveScale; ///< A value to scale the reactive mask
float autoReactiveMax; ///< A value to clamp the reactive mask
} FfxFsr2DispatchDescription;
/// A structure encapsulating the parameters for automatic generation of a reactive mask
///
/// @ingroup ffxFsr2
typedef struct FfxFsr2GenerateReactiveDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR2 rendering commands into.
FfxResource colorOpaqueOnly; ///< A <c><i>FfxResource</i></c> containing the opaque only color buffer for the current frame (at render resolution).
FfxResource colorPreUpscale; ///< A <c><i>FfxResource</i></c> containing the opaque+translucent color buffer for the current frame (at render resolution).
FfxResource outReactive; ///< A <c><i>FfxResource</i></c> containing the surface to generate the reactive mask into.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
float scale; ///< A value to scale the output
float cutoffThreshold; ///< A threshold value to generate a binary reactive mask
float binaryValue; ///< A value to set for the binary reactive mask
uint32_t flags; ///< Flags to determine how to generate the reactive mask
} FfxFsr2GenerateReactiveDescription;
/// A structure encapsulating the FidelityFX Super Resolution 2 context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by FSR2.
///
/// The <c><i>FfxFsr2Context</i></c> object should have a lifetime matching
/// your use of FSR2. Before destroying the FSR2 context care should be taken
/// to ensure the GPU is not accessing the resources created or used by FSR2.
/// It is therefore recommended that the GPU is idle before destroying the
/// FSR2 context.
///
/// @ingroup ffxFsr2
typedef struct FfxFsr2Context
{
uint32_t data[FFX_FSR2_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxFsr2Context;
/// Create a FidelityFX Super Resolution 2 context from the parameters
/// programmed to the <c><i>FfxFsr2CreateParams</i></c> structure.
///
/// The context structure is the main object used to interact with the FSR2
/// API, and is responsible for the management of the internal resources used
/// by the FSR2 algorithm. When this API is called, multiple calls will be
/// made via the pointers contained in the <c><i>callbacks</i></c> structure.
/// These callbacks will attempt to retreive the device capabilities, and
/// create the internal resources, and pipelines required by FSR2's
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxFsr2Context</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The flags included in the <c><i>flags</i></c> field of
/// <c><i>FfxFsr2Context</i></c> how match the configuration of your
/// application as well as the intended use of FSR2. It is important that these
/// flags are set correctly (as well as a correct programmed
/// <c><i>FfxFsr2DispatchDescription</i></c>) to ensure correct operation. It is
/// recommended to consult the overview documentation for further details on
/// how FSR2 should be integerated into an application.
///
/// When the <c><i>FfxFsr2Context</i></c> is created, you should use the
/// <c><i>ffxFsr2ContextDispatch</i></c> function each frame where FSR2
/// upscaling should be applied. See the documentation of
/// <c><i>ffxFsr2ContextDispatch</i></c> for more details.
///
/// The <c><i>FfxFsr2Context</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or FSR2 upscaling is
/// disabled by a user. To destroy the FSR2 context you should call
/// <c><i>ffxFsr2ContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxFsr2Context</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxFsr2ContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxFsr2ContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxFsr2
FFX_API FfxErrorCode ffxFsr2ContextCreate(FfxFsr2Context* pContext, const FfxFsr2ContextDescription* pContextDescription);
/// Get GPU memory usage of the FidelityFX Super Resolution context.
///
/// @param [in] pContext A pointer to a <c><i>FfxFsr2Context</i></c> structure.
/// @param [out] pVramUsage A pointer to a <c><i>FfxEffectMemoryUsage</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>vramUsage</i></c> were <c><i>NULL</i></c>.
///
/// @ingroup ffxFsr2
FFX_API FfxErrorCode ffxFsr2ContextGetGpuMemoryUsage(FfxFsr2Context* pContext, FfxEffectMemoryUsage* pVramUsage);
/// Dispatch the various passes that constitute FidelityFX Super Resolution 2.
///
/// FSR2 is a composite effect, meaning that it is compromised of multiple
/// constituent passes (implemented as one or more clears, copies and compute
/// dispatches). The <c><i>ffxFsr2ContextDispatch</i></c> function is the
/// function which (via the use of the functions contained in the
/// <c><i>callbacks</i></c> field of the <c><i>FfxFsr2Context</i></c>
/// structure) utlimately generates the sequence of graphics API calls required
/// each frame.
///
/// As with the creation of the <c><i>FfxFsr2Context</i></c> correctly
/// programming the <c><i>FfxFsr2DispatchDescription</i></c> is key to ensuring
/// the correct operation of FSR2. It is particularly important to ensure that
/// camera jitter is correctly applied to your application's projection matrix
/// (or camera origin for raytraced applications). FSR2 provides the
/// <c><i>ffxFsr2GetJitterPhaseCount</i></c> and
/// <c><i>ffxFsr2GetJitterOffset</i></c> entry points to help applications
/// correctly compute the camera jitter. Whatever jitter pattern is used by the
/// application it should be correctly programmed to the
/// <c><i>jitterOffset</i></c> field of the <c><i>dispatchDescription</i></c>
/// structure. For more guidance on camera jitter please consult the
/// documentation for <c><i>ffxFsr2GetJitterOffset</i></c> as well as the
/// accompanying overview documentation for FSR2.
///
/// @param [in] pContext A pointer to a <c><i>FfxFsr2Context</i></c> structure.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxFsr2DispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_OUT_OF_RANGE The operation failed because <c><i>dispatchDescription.renderSize</i></c> was larger than the maximum render resolution.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the device inside the context was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxFsr2
FFX_API FfxErrorCode ffxFsr2ContextDispatch(FfxFsr2Context* pContext, const FfxFsr2DispatchDescription* pDispatchDescription);
/// A helper function generate a Reactive mask from an opaque only texure and one containing translucent objects.
///
/// @param [in] pContext A pointer to a <c><i>FfxFsr2Context</i></c> structure.
/// @param [in] pParams A pointer to a <c><i>FfxFsr2GenerateReactiveDescription</i></c> structure
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup ffxFsr2
FFX_API FfxErrorCode ffxFsr2ContextGenerateReactiveMask(FfxFsr2Context* pContext, const FfxFsr2GenerateReactiveDescription* pParams);
/// Destroy the FidelityFX Super Resolution context.
///
/// @param [out] pContext A pointer to a <c><i>FfxFsr2Context</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup ffxFsr2
FFX_API FfxErrorCode ffxFsr2ContextDestroy(FfxFsr2Context* pContext);
/// Get the upscale ratio from the quality mode.
///
/// The following table enumerates the mapping of the quality modes to
/// per-dimension scaling ratios.
///
/// Quality preset | Scale factor
/// ----------------------------------------------------- | -------------
/// <c><i>FFX_FSR2_QUALITY_MODE_QUALITY</i></c> | 1.5x
/// <c><i>FFX_FSR2_QUALITY_MODE_BALANCED</i></c> | 1.7x
/// <c><i>FFX_FSR2_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x
/// <c><i>FFX_FSR2_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> | 3.0x
///
/// Passing an invalid <c><i>qualityMode</i></c> will return 0.0f.
///
/// @param [in] qualityMode The quality mode preset.
///
/// @returns
/// The upscaling the per-dimension upscaling ratio for
/// <c><i>qualityMode</i></c> according to the table above.
///
/// @ingroup ffxFsr2
FFX_API float ffxFsr2GetUpscaleRatioFromQualityMode(FfxFsr2QualityMode qualityMode);
/// A helper function to calculate the rendering resolution from a target
/// resolution and desired quality level.
///
/// This function applies the scaling factor returned by
/// <c><i>ffxFsr2GetUpscaleRatioFromQualityMode</i></c> to each dimension.
///
/// @param [out] pRenderWidth A pointer to a <c>uint32_t</c> which will hold the calculated render resolution width.
/// @param [out] pRenderHeight A pointer to a <c>uint32_t</c> which will hold the calculated render resolution height.
/// @param [in] displayWidth The target display resolution width.
/// @param [in] displayHeight The target display resolution height.
/// @param [in] qualityMode The desired quality mode for FSR 2 upscaling.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER Either <c><i>renderWidth</i></c> or <c><i>renderHeight</i></c> was <c>NULL</c>.
/// @retval
/// FFX_ERROR_INVALID_ENUM An invalid quality mode was specified.
///
/// @ingroup ffxFsr2
FFX_API FfxErrorCode ffxFsr2GetRenderResolutionFromQualityMode(
uint32_t* pRenderWidth,
uint32_t* pRenderHeight,
uint32_t displayWidth,
uint32_t displayHeight,
FfxFsr2QualityMode qualityMode);
/// A helper function to calculate the jitter phase count from display
/// resolution.
///
/// For more detailed information about the application of camera jitter to
/// your application's rendering please refer to the
/// <c><i>ffxFsr2GetJitterOffset</i></c> function.
///
/// The table below shows the jitter phase count which this function
/// would return for each of the quality presets.
///
/// Quality preset | Scale factor | Phase count
/// ----------------------------------------------------- | ------------- | ---------------
/// <c><i>FFX_FSR2_QUALITY_MODE_QUALITY</i></c> | 1.5x | 18
/// <c><i>FFX_FSR2_QUALITY_MODE_BALANCED</i></c> | 1.7x | 23
/// <c><i>FFX_FSR2_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x | 32
/// <c><i>FFX_FSR2_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> | 3.0x | 72
/// Custom | [1..n]x | ceil(8*n^2)
///
/// @param [in] renderWidth The render resolution width.
/// @param [in] displayWidth The display resolution width.
///
/// @returns
/// The jitter phase count for the scaling factor between <c><i>renderWidth</i></c> and <c><i>displayWidth</i></c>.
///
/// @ingroup ffxFsr2
FFX_API int32_t ffxFsr2GetJitterPhaseCount(int32_t renderWidth, int32_t displayWidth);
/// A helper function to calculate the subpixel jitter offset.
///
/// FSR2 relies on the application to apply sub-pixel jittering while rendering.
/// This is typically included in the projection matrix of the camera. To make
/// the application of camera jitter simple, the FSR2 API provides a small set
/// of utility function which computes the sub-pixel jitter offset for a
/// particular frame within a sequence of separate jitter offsets. To begin, the
/// index within the jitter phase must be computed. To calculate the
/// sequence's length, you can call the <c><i>ffxFsr2GetJitterPhaseCount</i></c>
/// function. The index should be a value which is incremented each frame modulo
/// the length of the sequence computed by <c><i>ffxFsr2GetJitterPhaseCount</i></c>.
/// The index within the jitter phase is passed to
/// <c><i>ffxFsr2GetJitterOffset</i></c> via the <c><i>index</i></c> parameter.
///
/// This function uses a Halton(2,3) sequence to compute the jitter offset.
/// The ultimate index used for the sequence is <c><i>index</i></c> %
/// <c><i>phaseCount</i></c>.
///
/// It is important to understand that the values returned from the
/// <c><i>ffxFsr2GetJitterOffset</i></c> function are in unit pixel space, and
/// in order to composite this correctly into a projection matrix we must
/// convert them into projection offsets. This is done as per the pseudo code
/// listing which is shown below.
///
/// const int32_t jitterPhaseCount = ffxFsr2GetJitterPhaseCount(renderWidth, displayWidth);
///
/// float jitterX = 0;
/// float jitterY = 0;
/// ffxFsr2GetJitterOffset(&jitterX, &jitterY, index, jitterPhaseCount);
///
/// const float jitterX = 2.0f * jitterX / (float)renderWidth;
/// const float jitterY = -2.0f * jitterY / (float)renderHeight;
/// const Matrix4 jitterTranslationMatrix = translateMatrix(Matrix3::identity, Vector3(jitterX, jitterY, 0));
/// const Matrix4 jitteredProjectionMatrix = jitterTranslationMatrix * projectionMatrix;
///
/// Jitter should be applied to all rendering. This includes opaque, alpha
/// transparent, and raytraced objects. For rasterized objects, the sub-pixel
/// jittering values calculated by the <c><i>iffxFsr2GetJitterOffset</i></c>
/// function can be applied to the camera projection matrix which is ultimately
/// used to perform transformations during vertex shading. For raytraced
/// rendering, the sub-pixel jitter should be applied to the ray's origin,
/// often the camera's position.
///
/// Whether you elect to use the <c><i>ffxFsr2GetJitterOffset</i></c> function
/// or your own sequence generator, you must program the
/// <c><i>jitterOffset</i></c> field of the
/// <c><i>FfxFsr2DispatchParameters</i></c> structure in order to inform FSR2
/// of the jitter offset that has been applied in order to render each frame.
///
/// If not using the recommended <c><i>ffxFsr2GetJitterOffset</i></c> function,
/// care should be taken that your jitter sequence never generates a null vector;
/// that is value of 0 in both the X and Y dimensions.
///
/// @param [out] pOutX A pointer to a <c>float</c> which will contain the subpixel jitter offset for the x dimension.
/// @param [out] pOutY A pointer to a <c>float</c> which will contain the subpixel jitter offset for the y dimension.
/// @param [in] index The index within the jitter sequence.
/// @param [in] phaseCount The length of jitter phase. See <c><i>ffxFsr2GetJitterPhaseCount</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER Either <c><i>outX</i></c> or <c><i>outY</i></c> was <c>NULL</c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Argument <c><i>phaseCount</i></c> must be greater than 0.
///
/// @ingroup ffxFsr2
FFX_API FfxErrorCode ffxFsr2GetJitterOffset(float* pOutX, float* pOutY, int32_t index, int32_t phaseCount);
/// A helper function to check if a resource is
/// <c><i>FFX_FSR2_RESOURCE_IDENTIFIER_NULL</i></c>.
///
/// @param [in] resource A <c><i>FfxResource</i></c>.
///
/// @returns
/// true The <c><i>resource</i></c> was not <c><i>FFX_FSR2_RESOURCE_IDENTIFIER_NULL</i></c>.
/// @returns
/// false The <c><i>resource</i></c> was <c><i>FFX_FSR2_RESOURCE_IDENTIFIER_NULL</i></c>.
///
/// @ingroup ffxFsr2
FFX_API bool ffxFsr2ResourceIsNull(FfxResource resource);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxFsr2
FFX_API FfxVersionNumber ffxFsr2GetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,537 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup FSR3
#pragma once
// Include the interface for the backend of the FSR3 API.
#include <FidelityFX/host/ffx_interface.h>
#include <FidelityFX/host/ffx_fsr3upscaler.h>
#include <FidelityFX/host/ffx_frameinterpolation.h>
#include <FidelityFX/host/ffx_opticalflow.h>
/// FidelityFX Super Resolution 3 major version.
///
/// @ingroup FSR3
#define FFX_FSR3_VERSION_MAJOR (3)
/// FidelityFX Super Resolution 0 minor version.
///
/// @ingroup FSR3
#define FFX_FSR3_VERSION_MINOR (1)
/// FidelityFX Super Resolution 0 patch version.
///
/// @ingroup FSR3
#define FFX_FSR3_VERSION_PATCH (0)
/// FidelityFX Super Resolution 3 context count
///
/// Defines the number of internal effect contexts required by FSR3 (+1 for proxy swapchain)
///
/// @ingroup ffxFsr3
#define FFX_FSR3_CONTEXT_COUNT (FFX_FSR3UPSCALER_CONTEXT_COUNT + FFX_OPTICALFLOW_CONTEXT_COUNT + FFX_FRAMEINTERPOLATION_CONTEXT_COUNT + 1)
/// The size of the context specified in 32bit values.
///
/// @ingroup FSR3
#define FFX_FSR3_CONTEXT_SIZE (FFX_FSR3UPSCALER_CONTEXT_SIZE + FFX_OPTICALFLOW_CONTEXT_SIZE + FFX_FRAMEINTERPOLATION_CONTEXT_SIZE + FFX_SDK_DEFAULT_CONTEXT_SIZE)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
///// An enumeration of all the passes which constitute the FSR3 algorithm.
/////
///// FSR3 is implemented as a composite of several compute passes each
///// computing a key part of the final result. Each call to the
///// <c><i>FfxFsr3ScheduleGpuJobFunc</i></c> callback function will
///// correspond to a single pass included in <c><i>FfxFsr3Pass</i></c>. For a
///// more comprehensive description of each pass, please refer to the FSR3
///// reference documentation.
/////
///// Please note in some cases e.g.: <c><i>FFX_FSR3_PASS_ACCUMULATE</i></c>
///// and <c><i>FFX_FSR3_PASS_ACCUMULATE_SHARPEN</i></c> either one pass or the
///// other will be used (they are mutually exclusive). The choice of which will
///// depend on the way the <c><i>FfxFsr3Context</i></c> is created and the
///// precise contents of <c><i>FfxFsr3DispatchParamters</i></c> each time a call
///// is made to <c><i>ffxFsr3ContextDispatch</i></c>.
/////
///// @ingroup FSR3
//typedef enum FfxFsr3Pass
//{
// // no special FSR3 pipelines
//
// FFX_FSR3_PASS_COUNT ///< The number of passes performed by FSR3.
//} FfxFsr3Pass;
/// An enumeration of all the quality modes supported by FidelityFX Super
/// Resolution 2 upscaling.
///
/// In order to provide a consistent user experience across multiple
/// applications which implement FSR3. It is strongly recommended that the
/// following preset scaling factors are made available through your
/// application's user interface.
///
/// If your application does not expose the notion of preset scaling factors
/// for upscaling algorithms (perhaps instead implementing a fixed ratio which
/// is immutable) or implementing a more dynamic scaling scheme (such as
/// dynamic resolution scaling), then there is no need to use these presets.
///
/// Please note that <c><i>FFX_FSR3_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> is
/// an optional mode which may introduce significant quality degradation in the
/// final image. As such it is recommended that you evaluate the final results
/// of using this scaling mode before deciding if you should include it in your
/// application.
///
/// @ingroup FSR3
typedef enum FfxFsr3QualityMode {
FFX_FSR3_QUALITY_MODE_QUALITY = 1, ///< Perform upscaling with a per-dimension upscaling ratio of 1.5x.
FFX_FSR3_QUALITY_MODE_BALANCED = 2, ///< Perform upscaling with a per-dimension upscaling ratio of 1.7x.
FFX_FSR3_QUALITY_MODE_PERFORMANCE = 3, ///< Perform upscaling with a per-dimension upscaling ratio of 2.0x.
FFX_FSR3_QUALITY_MODE_ULTRA_PERFORMANCE = 4 ///< Perform upscaling with a per-dimension upscaling ratio of 3.0x.
} FfxFsr3QualityMode;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxFsr3Context</i></c>. See <c><i>FfxFsr3ContextDescription</i></c>.
///
/// @ingroup FSR3
typedef enum FfxFsr3InitializationFlagBits {
FFX_FSR3_ENABLE_HIGH_DYNAMIC_RANGE = (1<<0), ///< A bit indicating if the input color data provided to all inputs is using a high-dynamic range.
FFX_FSR3_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS = (1<<1), ///< A bit indicating if the motion vectors are rendered at display resolution.
FFX_FSR3_ENABLE_MOTION_VECTORS_JITTER_CANCELLATION = (1<<2), ///< A bit indicating that the motion vectors have the jittering pattern applied to them.
FFX_FSR3_ENABLE_DEPTH_INVERTED = (1<<3), ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
FFX_FSR3_ENABLE_DEPTH_INFINITE = (1<<4), ///< A bit indicating that the input depth buffer data provided is using an infinite far plane.
FFX_FSR3_ENABLE_AUTO_EXPOSURE = (1<<5), ///< A bit indicating if automatic exposure should be applied to input color data.
FFX_FSR3_ENABLE_DYNAMIC_RESOLUTION = (1<<6), ///< A bit indicating that the application uses dynamic resolution scaling.
FFX_FSR3_ENABLE_TEXTURE1D_USAGE = (1<<7), ///< This value is deprecated, but remains in order to aid upgrading from older versions of FSR3.
FFX_FSR3_ENABLE_DEBUG_CHECKING = (1<<8), ///< A bit indicating that the runtime should check some API values and report issues.
FFX_FSR3_ENABLE_UPSCALING_ONLY = (1<<9), ///, A bit indicating that the context will only be used for upscaling
FFX_FSR3_ENABLE_HDR_UPSCALE_SDR_FINALOUTPUT = (1<<10), ///, A bit indicating if the input color data provided to UPSCALE is using a high-dynamic range, final output SDR.
FFX_FSR3_ENABLE_SDR_UPSCALE_HDR_FINALOUTPUT = (1<<11), ///, A bit indicating if the input color data provided to UPSCALE is using SDR, final output is high-dynamic range.
FFX_FSR3_ENABLE_ASYNC_WORKLOAD_SUPPORT = (1<<12),
FFX_FSR3_ENABLE_INTERPOLATION_ONLY = (1<<13),
} FfxFsr3InitializationFlagBits;
typedef enum FfxFsr3FrameGenerationFlags
{
FFX_FSR3_FRAME_GENERATION_FLAG_DRAW_DEBUG_TEAR_LINES = FFX_FRAMEINTERPOLATION_DISPATCH_DRAW_DEBUG_TEAR_LINES, ///< A bit indicating that the debug tear lines will be drawn to the interpolated output.
FFX_FSR3_FRAME_GENERATION_FLAG_DRAW_DEBUG_VIEW = FFX_FRAMEINTERPOLATION_DISPATCH_DRAW_DEBUG_VIEW, ///< A bit indicating that the interpolated output resource will contain debug views with relevant information.
} FfxFsr3FrameGenerationFlags;
typedef enum FfxFsr3UpscalingFlags
{
FFX_FSR3_UPSCALER_FLAG_DRAW_DEBUG_VIEW = FFX_FSR3UPSCALER_DISPATCH_DRAW_DEBUG_VIEW, ///< A bit indicating that the upscaled output resource will contain debug views with relevant information.
} FfxFsr3UpscalingFlags;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Super Resolution 3 upscaling.
///
/// @ingroup FSR3
typedef struct FfxFsr3ContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxFsr3InitializationFlagBits</i></c>.
FfxDimensions2D maxRenderSize; ///< The maximum size that rendering will be performed at.
FfxDimensions2D maxUpscaleSize; ///< The size of the presentation resolution targeted by the upscaling process.
FfxDimensions2D displaySize; ///< The size of the presentation resolution targeted by the frame interpolation process.
FfxInterface backendInterfaceUpscaling; ///< A set of pointers to the backend implementation for FidelityFX SDK
FfxInterface backendInterfaceFrameInterpolation; ///< A set of pointers to the backend implementation for FidelityFX SDK
FfxFsr3UpscalerMessage fpMessage; ///< A pointer to a function that can receive messages from the runtime.
FfxSurfaceFormat backBufferFormat; ///< The format of the swapchain surface
} FfxFsr3ContextDescription;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX Super Resolution 3.
///
/// @ingroup FSR3
typedef struct FfxFsr3DispatchUpscaleDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR2 rendering commands into.
FfxResource color; ///< A <c><i>FfxResource</i></c> containing the color buffer for the current frame (at render resolution).
FfxResource depth; ///< A <c><i>FfxResource</i></c> containing 32bit depth values for the current frame (at render resolution).
FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing 2-dimensional motion vectors (at render resolution if <c><i>FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS</i></c> is not set).
FfxResource exposure; ///< A optional <c><i>FfxResource</i></c> containing a 1x1 exposure value.
FfxResource reactive; ///< A optional <c><i>FfxResource</i></c> containing alpha value of reactive objects in the scene.
FfxResource transparencyAndComposition; ///< A optional <c><i>FfxResource</i></c> containing alpha value of special objects in the scene.
FfxResource upscaleOutput; ///< A <c><i>FfxResource</i></c> containing the output color buffer for the current frame (at presentation resolution).
FfxFloatCoords2D jitterOffset; ///< The subpixel jitter offset applied to the camera.
FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
FfxDimensions2D upscaleSize; ///< The resolution that the upscaler will output.
bool enableSharpening; ///< Enable an additional sharpening pass.
float sharpness; ///< The sharpness value between 0 and 1, where 0 is no additional sharpness and 1 is maximum additional sharpness.
float frameTimeDelta; ///< The time elapsed since the last frame (expressed in milliseconds).
float preExposure; ///< The pre exposure value (must be > 0.0f)
bool reset; ///< A boolean value which when set to true, indicates the camera has moved discontinuously.
float cameraNear; ///< The distance to the near plane of the camera.
float cameraFar; ///< The distance to the far plane of the camera. This is used only used in case of non infinite depth.
float cameraFovAngleVertical; ///< The camera angle field of view in the vertical direction (expressed in radians).
float viewSpaceToMetersFactor; ///< The scale factor to convert view space units to meters
uint32_t flags; ///< combination of FfxFsr3UpscalingFlags
} FfxFsr3DispatchUpscaleDescription;
typedef struct FfxFsr3DispatchFrameGenerationPrepareDescription
{
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR2 rendering commands into.
FfxResource depth; ///< A <c><i>FfxResource</i></c> containing 32bit depth values for the current frame (at render resolution).
FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing 2-dimensional motion vectors (at render resolution if <c><i>FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS</i></c> is not set).
FfxFloatCoords2D jitterOffset; ///< The subpixel jitter offset applied to the camera.
FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
float frameTimeDelta;
float cameraNear;
float cameraFar;
float viewSpaceToMetersFactor;
float cameraFovAngleVertical;
uint64_t frameID;
} FfxFsr3DispatchFrameGenerationPrepareDescription;
FFX_API FfxErrorCode ffxFsr3DispatchFrameGeneration(const FfxFrameGenerationDispatchDescription* desc);
/// A structure encapsulating the parameters for automatic generation of a reactive mask
///
/// @ingroup FSR3
typedef struct FfxFsr3GenerateReactiveDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR3 rendering commands into.
FfxResource colorOpaqueOnly; ///< A <c><i>FfxResource</i></c> containing the opaque only color buffer for the current frame (at render resolution).
FfxResource colorPreUpscale; ///< A <c><i>FfxResource</i></c> containing the opaque+translucent color buffer for the current frame (at render resolution).
FfxResource outReactive; ///< A <c><i>FfxResource</i></c> containing the surface to generate the reactive mask into.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
float scale; ///< A value to scale the output
float cutoffThreshold; ///< A threshold value to generate a binary reactive mask
float binaryValue;
uint32_t flags; ///< Flags to determine how to generate the reactive mask
} FfxFsr3GenerateReactiveDescription;
/// A structure encapsulating the FidelityFX Super Resolution 3 context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by FSR3.
///
/// The <c><i>FfxFsr3Context</i></c> object should have a lifetime matching
/// your use of FSR3. Before destroying the FSR3 context care should be taken
/// to ensure the GPU is not accessing the resources created or used by FSR3.
/// It is therefore recommended that the GPU is idle before destroying the
/// FSR3 context.
///
/// @ingroup FSR3
typedef struct FfxFsr3Context
{
uint32_t data[FFX_FSR3_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxFsr3Context;
/// Create a FidelityFX Super Resolution 3 context from the parameters
/// programmed to the <c><i>FfxFsr3CreateParams</i></c> structure.
///
/// The context structure is the main object used to interact with the FSR3
/// API, and is responsible for the management of the internal resources used
/// by the FSR3 algorithm. When this API is called, multiple calls will be
/// made via the pointers contained in the <c><i>callbacks</i></c> structure.
/// These callbacks will attempt to retreive the device capabilities, and
/// create the internal resources, and pipelines required by FSR3's
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxFsr3Context</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The flags included in the <c><i>flags</i></c> field of
/// <c><i>FfxFsr3Context</i></c> how match the configuration of your
/// application as well as the intended use of FSR3. It is important that these
/// flags are set correctly (as well as a correct programmed
/// <c><i>FfxFsr3DispatchDescription</i></c>) to ensure correct operation. It is
/// recommended to consult the overview documentation for further details on
/// how FSR3 should be integerated into an application.
///
/// When the <c><i>FfxFsr3Context</i></c> is created, you should use the
/// <c><i>ffxFsr3ContextDispatch</i></c> function each frame where FSR3
/// upscaling should be applied. See the documentation of
/// <c><i>ffxFsr3ContextDispatch</i></c> for more details.
///
/// The <c><i>FfxFsr3Context</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or FSR3 upscaling is
/// disabled by a user. To destroy the FSR3 context you should call
/// <c><i>ffxFsr3ContextDestroy</i></c>.
///
/// @param [out] context A pointer to a <c><i>FfxFsr3Context</i></c> structure to populate.
/// @param [in] contextDescription A pointer to a <c><i>FfxFsr3ContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxFsr3ContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FSR3
FFX_API FfxErrorCode ffxFsr3ContextCreate(FfxFsr3Context* context, FfxFsr3ContextDescription* contextDescription);
FFX_API FfxErrorCode ffxFsr3ContextGetGpuMemoryUsage(FfxFsr3Context* pContext,
FfxEffectMemoryUsage* pUpscalerUsage,
FfxEffectMemoryUsage* pOpticalFlowUsage,
FfxEffectMemoryUsage* pFrameGenerationUsage);
/// Dispatch the various passes that constitute FidelityFX Super Resolution 3 Upscaling.
///
/// FSR3 is a composite effect, meaning that it is compromised of multiple
/// constituent passes (implemented as one or more clears, copies and compute
/// dispatches). The <c><i>ffxFsr3ContextDispatchUpscale</i></c> function is the
/// function which (via the use of the functions contained in the
/// <c><i>callbacks</i></c> field of the <c><i>FfxFsr3Context</i></c>
/// structure) utlimately generates the sequence of graphics API calls required
/// each frame.
///
/// As with the creation of the <c><i>FfxFsr3Context</i></c> correctly
/// programming the <c><i>dispatchParams</i></c> is key to ensuring
/// the correct operation of FSR3. It is particularly important to ensure that
/// camera jitter is correctly applied to your application's projection matrix
/// (or camera origin for raytraced applications). FSR3 provides the
/// <c><i>ffxFsr3GetJitterPhaseCount</i></c> and
/// <c><i>ffxFsr3GetJitterOffset</i></c> entry points to help applications
/// correctly compute the camera jitter. Whatever jitter pattern is used by the
/// application it should be correctly programmed to the
/// <c><i>jitterOffset</i></c> field of the <c><i>dispatchParams</i></c>
/// structure. For more guidance on camera jitter please consult the
/// documentation for <c><i>ffxFsr3GetJitterOffset</i></c> as well as the
/// accompanying overview documentation for FSR3.
///
/// @param [in] context A pointer to a <c><i>FfxFsr3Context</i></c> structure.
/// @param [in] dispatchParams A pointer to a <c><i>FfxFsr3DispatchUpscaleDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchParams</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_OUT_OF_RANGE The operation failed because <c><i>dispatchParams.renderSize</i></c> was larger than the maximum render resolution.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the device inside the context was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FSR3
FFX_API FfxErrorCode ffxFsr3ContextDispatchUpscale(FfxFsr3Context* context, const FfxFsr3DispatchUpscaleDescription* dispatchParams);
FFX_API FfxErrorCode ffxFsr3ContextDispatchFrameGenerationPrepare(FfxFsr3Context* context, const FfxFsr3DispatchFrameGenerationPrepareDescription* dispatchParams);
FFX_API FfxErrorCode ffxFsr3SkipPresent(FfxFsr3Context* context);
/// A helper function generate a Reactive mask from an opaque only texure and one containing translucent objects.
///
/// @param [in] context A pointer to a <c><i>FfxFsr3Context</i></c> structure.
/// @param [in] params A pointer to a <c><i>FfxFsr3GenerateReactiveDescription</i></c> structure
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup FSR3
FFX_API FfxErrorCode ffxFsr3ContextGenerateReactiveMask(FfxFsr3Context* context, const FfxFsr3GenerateReactiveDescription* params);
FFX_API FfxErrorCode ffxFsr3ConfigureFrameGeneration(FfxFsr3Context* context, const FfxFrameGenerationConfig* config);
/// Destroy the FidelityFX Super Resolution context.
///
/// @param [out] context A pointer to a <c><i>FfxFsr3Context</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FSR3
FFX_API FfxErrorCode ffxFsr3ContextDestroy(FfxFsr3Context* context);
/// Get the upscale ratio from the quality mode.
///
/// The following table enumerates the mapping of the quality modes to
/// per-dimension scaling ratios.
///
/// Quality preset | Scale factor
/// ----------------------------------------------------- | -------------
/// <c><i>FFX_FSR3_QUALITY_MODE_NATIVEAA</i></c> | 1.0x
/// <c><i>FFX_FSR3_QUALITY_MODE_QUALITY</i></c> | 1.5x
/// <c><i>FFX_FSR3_QUALITY_MODE_BALANCED</i></c> | 1.7x
/// <c><i>FFX_FSR3_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x
/// <c><i>FFX_FSR3_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> | 3.0x
///
/// Passing an invalid <c><i>qualityMode</i></c> will return 0.0f.
///
/// @param [in] qualityMode The quality mode preset.
///
/// @returns
/// The upscaling the per-dimension upscaling ratio for
/// <c><i>qualityMode</i></c> according to the table above.
///
/// @ingroup FSR3
FFX_API float ffxFsr3GetUpscaleRatioFromQualityMode(FfxFsr3QualityMode qualityMode);
/// A helper function to calculate the rendering resolution from a target
/// resolution and desired quality level.
///
/// This function applies the scaling factor returned by
/// <c><i>ffxFsr3GetUpscaleRatioFromQualityMode</i></c> to each dimension.
///
/// @param [out] renderWidth A pointer to a <c>uint32_t</c> which will hold the calculated render resolution width.
/// @param [out] renderHeight A pointer to a <c>uint32_t</c> which will hold the calculated render resolution height.
/// @param [in] displayWidth The target display resolution width.
/// @param [in] displayHeight The target display resolution height.
/// @param [in] qualityMode The desired quality mode for FSR 2 upscaling.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER Either <c><i>renderWidth</i></c> or <c><i>renderHeight</i></c> was <c>NULL</c>.
/// @retval
/// FFX_ERROR_INVALID_ENUM An invalid quality mode was specified.
///
/// @ingroup FSR3
FFX_API FfxErrorCode ffxFsr3GetRenderResolutionFromQualityMode(
uint32_t* renderWidth,
uint32_t* renderHeight,
uint32_t displayWidth,
uint32_t displayHeight,
FfxFsr3QualityMode qualityMode);
/// A helper function to calculate the jitter phase count from display
/// resolution.
///
/// For more detailed information about the application of camera jitter to
/// your application's rendering please refer to the
/// <c><i>ffxFsr3GetJitterOffset</i></c> function.
///
/// The table below shows the jitter phase count which this function
/// would return for each of the quality presets.
///
/// Quality preset | Scale factor | Phase count
/// ----------------------------------------------------- | ------------- | ---------------
/// <c><i>FFX_FSR3_QUALITY_MODE_QUALITY</i></c> | 1.5x | 18
/// <c><i>FFX_FSR3_QUALITY_MODE_BALANCED</i></c> | 1.7x | 23
/// <c><i>FFX_FSR3_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x | 32
/// <c><i>FFX_FSR3_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> | 3.0x | 72
/// Custom | [1..n]x | ceil(8*n^2)
///
/// @param [in] renderWidth The render resolution width.
/// @param [in] displayWidth The display resolution width.
///
/// @returns
/// The jitter phase count for the scaling factor between <c><i>renderWidth</i></c> and <c><i>displayWidth</i></c>.
///
/// @ingroup FSR3
FFX_API int32_t ffxFsr3GetJitterPhaseCount(int32_t renderWidth, int32_t displayWidth);
/// A helper function to calculate the subpixel jitter offset.
///
/// FSR3 relies on the application to apply sub-pixel jittering while rendering.
/// This is typically included in the projection matrix of the camera. To make
/// the application of camera jitter simple, the FSR3 API provides a small set
/// of utility function which computes the sub-pixel jitter offset for a
/// particular frame within a sequence of separate jitter offsets. To begin, the
/// index within the jitter phase must be computed. To calculate the
/// sequence's length, you can call the <c><i>ffxFsr3GetJitterPhaseCount</i></c>
/// function. The index should be a value which is incremented each frame modulo
/// the length of the sequence computed by <c><i>ffxFsr3GetJitterPhaseCount</i></c>.
/// The index within the jitter phase is passed to
/// <c><i>ffxFsr3GetJitterOffset</i></c> via the <c><i>index</i></c> parameter.
///
/// This function uses a Halton(2,3) sequence to compute the jitter offset.
/// The ultimate index used for the sequence is <c><i>index</i></c> %
/// <c><i>phaseCount</i></c>.
///
/// It is important to understand that the values returned from the
/// <c><i>ffxFsr3GetJitterOffset</i></c> function are in unit pixel space, and
/// in order to composite this correctly into a projection matrix we must
/// convert them into projection offsets. This is done as per the pseudo code
/// listing which is shown below.
///
/// const int32_t jitterPhaseCount = ffxFsr3GetJitterPhaseCount(renderWidth, displayWidth);
///
/// float jitterX = 0;
/// float jitterY = 0;
/// ffxFsr3GetJitterOffset(&jitterX, &jitterY, index, jitterPhaseCount);
///
/// const float jitterX = 2.0f * jitterX / (float)renderWidth;
/// const float jitterY = -2.0f * jitterY / (float)renderHeight;
/// const Matrix4 jitterTranslationMatrix = translateMatrix(Matrix3::identity, Vector3(jitterX, jitterY, 0));
/// const Matrix4 jitteredProjectionMatrix = jitterTranslationMatrix * projectionMatrix;
///
/// Jitter should be applied to all rendering. This includes opaque, alpha
/// transparent, and raytraced objects. For rasterized objects, the sub-pixel
/// jittering values calculated by the <c><i>iffxFsr3GetJitterOffset</i></c>
/// function can be applied to the camera projection matrix which is ultimately
/// used to perform transformations during vertex shading. For raytraced
/// rendering, the sub-pixel jitter should be applied to the ray's origin,
/// often the camera's position.
///
/// Whether you elect to use the <c><i>ffxFsr3GetJitterOffset</i></c> function
/// or your own sequence generator, you must program the
/// <c><i>jitterOffset</i></c> field of the
/// <c><i>FfxFsr3DispatchParameters</i></c> structure in order to inform FSR3
/// of the jitter offset that has been applied in order to render each frame.
///
/// If not using the recommended <c><i>ffxFsr3GetJitterOffset</i></c> function,
/// care should be taken that your jitter sequence never generates a null vector;
/// that is value of 0 in both the X and Y dimensions.
///
/// @param [out] outX A pointer to a <c>float</c> which will contain the subpixel jitter offset for the x dimension.
/// @param [out] outY A pointer to a <c>float</c> which will contain the subpixel jitter offset for the y dimension.
/// @param [in] index The index within the jitter sequence.
/// @param [in] phaseCount The length of jitter phase. See <c><i>ffxFsr3GetJitterPhaseCount</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER Either <c><i>outX</i></c> or <c><i>outY</i></c> was <c>NULL</c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Argument <c><i>phaseCount</i></c> must be greater than 0.
///
/// @ingroup FSR3
FFX_API FfxErrorCode ffxFsr3GetJitterOffset(float* outX, float* outY, int32_t index, int32_t phaseCount);
/// A helper function to check if a resource is
/// <c><i>FFX_FSR3_RESOURCE_IDENTIFIER_NULL</i></c>.
///
/// @param [in] resource A <c><i>FfxResource</i></c>.
///
/// @returns
/// true The <c><i>resource</i></c> was not <c><i>FFX_FSR3_RESOURCE_IDENTIFIER_NULL</i></c>.
/// @returns
/// false The <c><i>resource</i></c> was <c><i>FFX_FSR3_RESOURCE_IDENTIFIER_NULL</i></c>.
///
/// @ingroup FSR3
FFX_API bool ffxFsr3ResourceIsNull(FfxResource resource);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FSR3
FFX_API FfxVersionNumber ffxFsr3GetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,541 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
// Include the interface for the backend of the FSR3 API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup ffxFsr3Upscaler FidelityFX FSR3
/// FidelityFX Super Resolution 3 runtime library
///
/// @ingroup SDKComponents
/// FidelityFX Super Resolution 3 major version.
///
/// @ingroup ffxFsr3Upscaler
#define FFX_FSR3UPSCALER_VERSION_MAJOR (3)
/// FidelityFX Super Resolution 3 minor version.
///
/// @ingroup ffxFsr3Upscaler
#define FFX_FSR3UPSCALER_VERSION_MINOR (1)
/// FidelityFX Super Resolution 3 patch version.
///
/// @ingroup ffxFsr3Upscaler
#define FFX_FSR3UPSCALER_VERSION_PATCH (0)
/// FidelityFX Super Resolution 3 context count
///
/// Defines the number of internal effect contexts required by FSR3
///
/// @ingroup ffxFsr3Upscaler
#define FFX_FSR3UPSCALER_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup ffxFsr3Upscaler
#define FFX_FSR3UPSCALER_CONTEXT_SIZE (FFX_SDK_DEFAULT_CONTEXT_SIZE)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of all the passes which constitute the FSR3 algorithm.
///
/// FSR3 is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxFsr3UpscalerScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxFsr3UpscalerPass</i></c>. For a
/// more comprehensive description of each pass, please refer to the FSR3
/// reference documentation.
///
/// Please note in some cases e.g.: <c><i>FFX_FSR3UPSCALER_PASS_ACCUMULATE</i></c>
/// and <c><i>FFX_FSR3UPSCALER_PASS_ACCUMULATE_SHARPEN</i></c> either one pass or the
/// other will be used (they are mutually exclusive). The choice of which will
/// depend on the way the <c><i>FfxFsr3UpscalerContext</i></c> is created and the
/// precise contents of <c><i>FfxFsr3UpscalerDispatchParamters</i></c> each time a call
/// is made to <c><i>ffxFsr3UpscalerContextDispatch</i></c>.
///
/// @ingroup ffxFsr3Upscaler
typedef enum FfxFsr3UpscalerPass
{
FFX_FSR3UPSCALER_PASS_PREPARE_INPUTS, ///< A pass which prepares game inputs for later passes
FFX_FSR3UPSCALER_PASS_LUMA_PYRAMID, ///< A pass which generates the luminance mipmap chain for the current frame.
FFX_FSR3UPSCALER_PASS_SHADING_CHANGE_PYRAMID, ///< A pass which generates the shading change detection mipmap chain for the current frame.
FFX_FSR3UPSCALER_PASS_SHADING_CHANGE, ///< A pass which estimates shading changes for the current frame
FFX_FSR3UPSCALER_PASS_PREPARE_REACTIVITY, ///< A pass which prepares accumulation relevant information
FFX_FSR3UPSCALER_PASS_LUMA_INSTABILITY, ///< A pass which estimates temporal instability of the luminance changes.
FFX_FSR3UPSCALER_PASS_ACCUMULATE, ///< A pass which performs upscaling.
FFX_FSR3UPSCALER_PASS_ACCUMULATE_SHARPEN, ///< A pass which performs upscaling when sharpening is used.
FFX_FSR3UPSCALER_PASS_RCAS, ///< A pass which performs sharpening.
FFX_FSR3UPSCALER_PASS_DEBUG_VIEW, ///< A pass which draws some internal resources, for debugging purposes
FFX_FSR3UPSCALER_PASS_GENERATE_REACTIVE, ///< An optional pass to generate a reactive mask.
FFX_FSR3UPSCALER_PASS_TCR_AUTOGENERATE, ///< DEPRECATED - NO LONGER SUPPORTED
FFX_FSR3UPSCALER_PASS_COUNT ///< The number of passes performed by FSR3.
} FfxFsr3UpscalerPass;
/// An enumeration of all the quality modes supported by FidelityFX Super
/// Resolution 3 upscaling.
///
/// In order to provide a consistent user experience across multiple
/// applications which implement FSR3. It is strongly recommended that the
/// following preset scaling factors are made available through your
/// application's user interface.
///
/// If your application does not expose the notion of preset scaling factors
/// for upscaling algorithms (perhaps instead implementing a fixed ratio which
/// is immutable) or implementing a more dynamic scaling scheme (such as
/// dynamic resolution scaling), then there is no need to use these presets.
///
/// Please note that <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> is
/// an optional mode which may introduce significant quality degradation in the
/// final image. As such it is recommended that you evaluate the final results
/// of using this scaling mode before deciding if you should include it in your
/// application.
///
/// @ingroup ffxFsr3Upscaler
typedef enum FfxFsr3UpscalerQualityMode {
FFX_FSR3UPSCALER_QUALITY_MODE_NATIVEAA = 0, ///< Perform upscaling with a per-dimension upscaling ratio of 1.0x.
FFX_FSR3UPSCALER_QUALITY_MODE_QUALITY = 1, ///< Perform upscaling with a per-dimension upscaling ratio of 1.5x.
FFX_FSR3UPSCALER_QUALITY_MODE_BALANCED = 2, ///< Perform upscaling with a per-dimension upscaling ratio of 1.7x.
FFX_FSR3UPSCALER_QUALITY_MODE_PERFORMANCE = 3, ///< Perform upscaling with a per-dimension upscaling ratio of 2.0x.
FFX_FSR3UPSCALER_QUALITY_MODE_ULTRA_PERFORMANCE = 4 ///< Perform upscaling with a per-dimension upscaling ratio of 3.0x.
} FfxFsr3UpscalerQualityMode;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxFsr3UpscalerContext</i></c>. See <c><i>FfxFsr3UpscalerContextDescription</i></c>.
///
/// @ingroup ffxFsr3Upscaler
typedef enum FfxFsr3UpscalerInitializationFlagBits {
FFX_FSR3UPSCALER_ENABLE_HIGH_DYNAMIC_RANGE = (1<<0), ///< A bit indicating if the input color data provided is using a high-dynamic range.
FFX_FSR3UPSCALER_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS = (1<<1), ///< A bit indicating if the motion vectors are rendered at display resolution.
FFX_FSR3UPSCALER_ENABLE_MOTION_VECTORS_JITTER_CANCELLATION = (1<<2), ///< A bit indicating that the motion vectors have the jittering pattern applied to them.
FFX_FSR3UPSCALER_ENABLE_DEPTH_INVERTED = (1<<3), ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
FFX_FSR3UPSCALER_ENABLE_DEPTH_INFINITE = (1<<4), ///< A bit indicating that the input depth buffer data provided is using an infinite far plane.
FFX_FSR3UPSCALER_ENABLE_AUTO_EXPOSURE = (1<<5), ///< A bit indicating if automatic exposure should be applied to input color data.
FFX_FSR3UPSCALER_ENABLE_DYNAMIC_RESOLUTION = (1<<6), ///< A bit indicating that the application uses dynamic resolution scaling.
FFX_FSR3UPSCALER_ENABLE_TEXTURE1D_USAGE = (1<<7), ///< This value is deprecated, but remains in order to aid upgrading from older versions of FSR3.
FFX_FSR3UPSCALER_ENABLE_DEBUG_CHECKING = (1<<8), ///< A bit indicating that the runtime should check some API values and report issues.
} FfxFsr3UpscalerInitializationFlagBits;
/// Pass a string message
///
/// Used for debug messages.
///
/// @param [in] type The type of message.
/// @param [in] message A string message to pass.
///
///
/// @ingroup ffxFsr3Upscaler
typedef void(*FfxFsr3UpscalerMessage)(
FfxMsgType type,
const wchar_t* message);
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Super Resolution 3 upscaling.
///
/// @ingroup ffxFsr3Upscaler
typedef struct FfxFsr3UpscalerContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxFsr3UpscalerInitializationFlagBits</i></c>.
FfxDimensions2D maxRenderSize; ///< The maximum size that rendering will be performed at.
FfxDimensions2D maxUpscaleSize; ///< The size of the output resolution targeted by the upscaling process.
FfxFsr3UpscalerMessage fpMessage; ///< A pointer to a function that can receive messages from the runtime.
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX SDK
} FfxFsr3UpscalerContextDescription;
typedef enum FfxFsr3UpscalerDispatchFlags
{
FFX_FSR3UPSCALER_DISPATCH_DRAW_DEBUG_VIEW = (1 << 0), ///< A bit indicating that the interpolated output resource will contain debug views with relevant information.
} FfxFsr3UpscalerDispatchFlags;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX Super Resolution 3.
///
/// @ingroup ffxFsr3Upscaler
typedef struct FfxFsr3UpscalerDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR3 rendering commands into.
FfxResource color; ///< A <c><i>FfxResource</i></c> containing the color buffer for the current frame (at render resolution).
FfxResource depth; ///< A <c><i>FfxResource</i></c> containing 32bit depth values for the current frame (at render resolution).
FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing 2-dimensional motion vectors (at render resolution if <c><i>FFX_FSR3UPSCALER_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS</i></c> is not set).
FfxResource exposure; ///< A optional <c><i>FfxResource</i></c> containing a 1x1 exposure value.
FfxResource reactive; ///< A optional <c><i>FfxResource</i></c> containing alpha value of reactive objects in the scene.
FfxResource transparencyAndComposition; ///< A optional <c><i>FfxResource</i></c> containing alpha value of special objects in the scene.
FfxResource output; ///< A <c><i>FfxResource</i></c> containing the output color buffer for the current frame (at presentation resolution).
FfxFloatCoords2D jitterOffset; ///< The subpixel jitter offset applied to the camera.
FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
FfxDimensions2D upscaleSize; ///< The resolution that the upscaler will output.
bool enableSharpening; ///< Enable an additional sharpening pass.
float sharpness; ///< The sharpness value between 0 and 1, where 0 is no additional sharpness and 1 is maximum additional sharpness.
float frameTimeDelta; ///< The time elapsed since the last frame (expressed in milliseconds).
float preExposure; ///< The pre exposure value (must be > 0.0f)
bool reset; ///< A boolean value which when set to true, indicates the camera has moved discontinuously.
float cameraNear; ///< The distance to the near plane of the camera.
float cameraFar; ///< The distance to the far plane of the camera.
float cameraFovAngleVertical; ///< The camera angle field of view in the vertical direction (expressed in radians).
float viewSpaceToMetersFactor; ///< The scale factor to convert view space units to meters
uint32_t flags; ///< combination of FfxFsr3UpscalerDispatchFlags
} FfxFsr3UpscalerDispatchDescription;
/// A structure encapsulating the parameters for automatic generation of a reactive mask
///
/// @ingroup ffxFsr3Upscaler
typedef struct FfxFsr3UpscalerGenerateReactiveDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR3 rendering commands into.
FfxResource colorOpaqueOnly; ///< A <c><i>FfxResource</i></c> containing the opaque only color buffer for the current frame (at render resolution).
FfxResource colorPreUpscale; ///< A <c><i>FfxResource</i></c> containing the opaque+translucent color buffer for the current frame (at render resolution).
FfxResource outReactive; ///< A <c><i>FfxResource</i></c> containing the surface to generate the reactive mask into.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
float scale; ///< A value to scale the output
float cutoffThreshold; ///< A threshold value to generate a binary reactive mask
float binaryValue; ///< A value to set for the binary reactive mask
uint32_t flags; ///< Flags to determine how to generate the reactive mask
} FfxFsr3UpscalerGenerateReactiveDescription;
/// A structure encapsulating the resource descriptions for shared resources for this effect.
///
/// @ingroup ffxFsr3Upscaler
typedef struct FfxFsr3UpscalerSharedResourceDescriptions {
FfxCreateResourceDescription reconstructedPrevNearestDepth; ///< The <c><i>FfxCreateResourceDescription</i></c> for allocating the <c><i>reconstructedPrevNearestDepth</i></c> shared resource.
FfxCreateResourceDescription dilatedDepth; ///< The <c><i>FfxCreateResourceDescription</i></c> for allocating the <c><i>dilatedDepth</i></c> shared resource.
FfxCreateResourceDescription dilatedMotionVectors; ///< The <c><i>FfxCreateResourceDescription</i></c> for allocating the <c><i>dilatedMotionVectors</i></c> shared resource.
} FfxFsr3UpscalerSharedResourceDescriptions;
/// A structure encapsulating the FidelityFX Super Resolution 3 context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by FSR3.
///
/// The <c><i>FfxFsr3UpscalerContext</i></c> object should have a lifetime matching
/// your use of FSR3. Before destroying the FSR3 context care should be taken
/// to ensure the GPU is not accessing the resources created or used by FSR3.
/// It is therefore recommended that the GPU is idle before destroying the
/// FSR3 context.
///
/// @ingroup ffxFsr3Upscaler
typedef struct FfxFsr3UpscalerContext
{
uint32_t data[FFX_FSR3UPSCALER_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxFsr3UpscalerContext;
/// Create a FidelityFX Super Resolution 3 context from the parameters
/// programmed to the <c><i>FfxFsr3UpscalerCreateParams</i></c> structure.
///
/// The context structure is the main object used to interact with the FSR3
/// API, and is responsible for the management of the internal resources used
/// by the FSR3 algorithm. When this API is called, multiple calls will be
/// made via the pointers contained in the <c><i>callbacks</i></c> structure.
/// These callbacks will attempt to retreive the device capabilities, and
/// create the internal resources, and pipelines required by FSR3's
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxFsr3UpscalerContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The flags included in the <c><i>flags</i></c> field of
/// <c><i>FfxFsr3UpscalerContext</i></c> how match the configuration of your
/// application as well as the intended use of FSR3. It is important that these
/// flags are set correctly (as well as a correct programmed
/// <c><i>FfxFsr3UpscalerDispatchDescription</i></c>) to ensure correct operation. It is
/// recommended to consult the overview documentation for further details on
/// how FSR3 should be integerated into an application.
///
/// When the <c><i>FfxFsr3UpscalerContext</i></c> is created, you should use the
/// <c><i>ffxFsr3UpscalerContextDispatch</i></c> function each frame where FSR3
/// upscaling should be applied. See the documentation of
/// <c><i>ffxFsr3UpscalerContextDispatch</i></c> for more details.
///
/// The <c><i>FfxFsr3UpscalerContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or FSR3 upscaling is
/// disabled by a user. To destroy the FSR3 context you should call
/// <c><i>ffxFsr3UpscalerContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxFsr3UpscalerContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxFsr3UpscalerContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxFsr3UpscalerContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxFsr3Upscaler
FFX_API FfxErrorCode ffxFsr3UpscalerContextCreate(FfxFsr3UpscalerContext* pContext, const FfxFsr3UpscalerContextDescription* pContextDescription);
/// Get GPU memory usage of the FidelityFX Super Resolution context.
///
/// @param [in] pContext A pointer to a <c><i>FfxFsr3UpscalerContext</i></c> structure.
/// @param [out] pVramUsage A pointer to a <c><i>FfxEffectMemoryUsage</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>vramUsage</i></c> were <c><i>NULL</i></c>.
///
/// @ingroup ffxFsr3Upscaler
FFX_API FfxErrorCode ffxFsr3UpscalerContextGetGpuMemoryUsage(FfxFsr3UpscalerContext* pContext, FfxEffectMemoryUsage* pVramUsage);
/// Dispatch the various passes that constitute FidelityFX Super Resolution 3.
///
/// FSR3 is a composite effect, meaning that it is compromised of multiple
/// constituent passes (implemented as one or more clears, copies and compute
/// dispatches). The <c><i>ffxFsr3UpscalerContextDispatch</i></c> function is the
/// function which (via the use of the functions contained in the
/// <c><i>callbacks</i></c> field of the <c><i>FfxFsr3UpscalerContext</i></c>
/// structure) utlimately generates the sequence of graphics API calls required
/// each frame.
///
/// As with the creation of the <c><i>FfxFsr3UpscalerContext</i></c> correctly
/// programming the <c><i>FfxFsr3UpscalerDispatchDescription</i></c> is key to ensuring
/// the correct operation of FSR3. It is particularly important to ensure that
/// camera jitter is correctly applied to your application's projection matrix
/// (or camera origin for raytraced applications). FSR3 provides the
/// <c><i>ffxFsr3UpscalerGetJitterPhaseCount</i></c> and
/// <c><i>ffxFsr3UpscalerGetJitterOffset</i></c> entry points to help applications
/// correctly compute the camera jitter. Whatever jitter pattern is used by the
/// application it should be correctly programmed to the
/// <c><i>jitterOffset</i></c> field of the <c><i>dispatchDescription</i></c>
/// structure. For more guidance on camera jitter please consult the
/// documentation for <c><i>ffxFsr3UpscalerGetJitterOffset</i></c> as well as the
/// accompanying overview documentation for FSR3.
///
/// @param [in] pContext A pointer to a <c><i>FfxFsr3UpscalerContext</i></c> structure.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxFsr3UpscalerDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_OUT_OF_RANGE The operation failed because <c><i>dispatchDescription.renderSize</i></c> was larger than the maximum render resolution.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the device inside the context was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxFsr3Upscaler
FFX_API FfxErrorCode ffxFsr3UpscalerContextDispatch(FfxFsr3UpscalerContext* pContext, const FfxFsr3UpscalerDispatchDescription* pDispatchDescription);
/// A helper function generate a Reactive mask from an opaque only texure and one containing translucent objects.
///
/// @param [in] pContext A pointer to a <c><i>FfxFsr3UpscalerContext</i></c> structure.
/// @param [in] pParams A pointer to a <c><i>FfxFsr3UpscalerGenerateReactiveDescription</i></c> structure
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup ffxFsr3Upscaler
FFX_API FfxErrorCode ffxFsr3UpscalerContextGenerateReactiveMask(FfxFsr3UpscalerContext* pContext, const FfxFsr3UpscalerGenerateReactiveDescription* pParams);
/// Destroy the FidelityFX Super Resolution context.
///
/// @param [out] pContext A pointer to a <c><i>FfxFsr3UpscalerContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup ffxFsr3Upscaler
FFX_API FfxErrorCode ffxFsr3UpscalerContextDestroy(FfxFsr3UpscalerContext* pContext);
/// Get the upscale ratio from the quality mode.
///
/// The following table enumerates the mapping of the quality modes to
/// per-dimension scaling ratios.
///
/// Quality preset | Scale factor
/// ----------------------------------------------------- | -------------
/// <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_QUALITY</i></c> | 1.5x
/// <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_BALANCED</i></c> | 1.7x
/// <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x
/// <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> | 3.0x
///
/// Passing an invalid <c><i>qualityMode</i></c> will return 0.0f.
///
/// @param [in] qualityMode The quality mode preset.
///
/// @returns
/// The upscaling the per-dimension upscaling ratio for
/// <c><i>qualityMode</i></c> according to the table above.
///
/// @ingroup ffxFsr3Upscaler
FFX_API float ffxFsr3UpscalerGetUpscaleRatioFromQualityMode(FfxFsr3UpscalerQualityMode qualityMode);
/// A helper function to calculate the rendering resolution from a target
/// resolution and desired quality level.
///
/// This function applies the scaling factor returned by
/// <c><i>ffxFsr3UpscalerGetUpscaleRatioFromQualityMode</i></c> to each dimension.
///
/// @param [out] pRenderWidth A pointer to a <c>uint32_t</c> which will hold the calculated render resolution width.
/// @param [out] pRenderHeight A pointer to a <c>uint32_t</c> which will hold the calculated render resolution height.
/// @param [in] displayWidth The target display resolution width.
/// @param [in] displayHeight The target display resolution height.
/// @param [in] qualityMode The desired quality mode for FSR 2 upscaling.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER Either <c><i>renderWidth</i></c> or <c><i>renderHeight</i></c> was <c>NULL</c>.
/// @retval
/// FFX_ERROR_INVALID_ENUM An invalid quality mode was specified.
///
/// @ingroup ffxFsr3Upscaler
FFX_API FfxErrorCode ffxFsr3UpscalerGetRenderResolutionFromQualityMode(
uint32_t* pRenderWidth,
uint32_t* pRenderHeight,
uint32_t displayWidth,
uint32_t displayHeight,
FfxFsr3UpscalerQualityMode qualityMode);
/// A helper function to calculate the jitter phase count from display
/// resolution.
///
/// For more detailed information about the application of camera jitter to
/// your application's rendering please refer to the
/// <c><i>ffxFsr3UpscalerGetJitterOffset</i></c> function.
///
/// The table below shows the jitter phase count which this function
/// would return for each of the quality presets.
///
/// Quality preset | Scale factor | Phase count
/// ----------------------------------------------------- | ------------- | ---------------
/// <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_QUALITY</i></c> | 1.5x | 18
/// <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_BALANCED</i></c> | 1.7x | 23
/// <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x | 32
/// <c><i>FFX_FSR3UPSCALER_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> | 3.0x | 72
/// Custom | [1..n]x | ceil(8*n^2)
///
/// @param [in] renderWidth The render resolution width.
/// @param [in] displayWidth The display resolution width.
///
/// @returns
/// The jitter phase count for the scaling factor between <c><i>renderWidth</i></c> and <c><i>displayWidth</i></c>.
///
/// @ingroup ffxFsr3Upscaler
FFX_API int32_t ffxFsr3UpscalerGetJitterPhaseCount(int32_t renderWidth, int32_t displayWidth);
/// A helper function to calculate the subpixel jitter offset.
///
/// FSR3 relies on the application to apply sub-pixel jittering while rendering.
/// This is typically included in the projection matrix of the camera. To make
/// the application of camera jitter simple, the FSR3 API provides a small set
/// of utility function which computes the sub-pixel jitter offset for a
/// particular frame within a sequence of separate jitter offsets. To begin, the
/// index within the jitter phase must be computed. To calculate the
/// sequence's length, you can call the <c><i>ffxFsr3UpscalerGetJitterPhaseCount</i></c>
/// function. The index should be a value which is incremented each frame modulo
/// the length of the sequence computed by <c><i>ffxFsr3UpscalerGetJitterPhaseCount</i></c>.
/// The index within the jitter phase is passed to
/// <c><i>ffxFsr3UpscalerGetJitterOffset</i></c> via the <c><i>index</i></c> parameter.
///
/// This function uses a Halton(2,3) sequence to compute the jitter offset.
/// The ultimate index used for the sequence is <c><i>index</i></c> %
/// <c><i>phaseCount</i></c>.
///
/// It is important to understand that the values returned from the
/// <c><i>ffxFsr3UpscalerGetJitterOffset</i></c> function are in unit pixel space, and
/// in order to composite this correctly into a projection matrix we must
/// convert them into projection offsets. This is done as per the pseudo code
/// listing which is shown below.
///
/// const int32_t jitterPhaseCount = ffxFsr3UpscalerGetJitterPhaseCount(renderWidth, displayWidth);
///
/// float jitterX = 0;
/// float jitterY = 0;
/// ffxFsr3UpscalerGetJitterOffset(&jitterX, &jitterY, index, jitterPhaseCount);
///
/// const float jitterX = 2.0f * jitterX / (float)renderWidth;
/// const float jitterY = -2.0f * jitterY / (float)renderHeight;
/// const Matrix4 jitterTranslationMatrix = translateMatrix(Matrix3::identity, Vector3(jitterX, jitterY, 0));
/// const Matrix4 jitteredProjectionMatrix = jitterTranslationMatrix * projectionMatrix;
///
/// Jitter should be applied to all rendering. This includes opaque, alpha
/// transparent, and raytraced objects. For rasterized objects, the sub-pixel
/// jittering values calculated by the <c><i>iffxFsr3UpscalerGetJitterOffset</i></c>
/// function can be applied to the camera projection matrix which is ultimately
/// used to perform transformations during vertex shading. For raytraced
/// rendering, the sub-pixel jitter should be applied to the ray's origin,
/// often the camera's position.
///
/// Whether you elect to use the <c><i>ffxFsr3UpscalerGetJitterOffset</i></c> function
/// or your own sequence generator, you must program the
/// <c><i>jitterOffset</i></c> field of the
/// <c><i>FfxFsr3UpscalerDispatchParameters</i></c> structure in order to inform FSR3
/// of the jitter offset that has been applied in order to render each frame.
///
/// If not using the recommended <c><i>ffxFsr3UpscalerGetJitterOffset</i></c> function,
/// care should be taken that your jitter sequence never generates a null vector;
/// that is value of 0 in both the X and Y dimensions.
///
/// @param [out] pOutX A pointer to a <c>float</c> which will contain the subpixel jitter offset for the x dimension.
/// @param [out] pOutY A pointer to a <c>float</c> which will contain the subpixel jitter offset for the y dimension.
/// @param [in] index The index within the jitter sequence.
/// @param [in] phaseCount The length of jitter phase. See <c><i>ffxFsr3UpscalerGetJitterPhaseCount</i></c>.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER Either <c><i>outX</i></c> or <c><i>outY</i></c> was <c>NULL</c>.
/// @retval
/// FFX_ERROR_INVALID_ARGUMENT Argument <c><i>phaseCount</i></c> must be greater than 0.
///
/// @ingroup ffxFsr3Upscaler
FFX_API FfxErrorCode ffxFsr3UpscalerGetJitterOffset(float* pOutX, float* pOutY, int32_t index, int32_t phaseCount);
/// A helper function to check if a resource is
/// <c><i>FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_NULL</i></c>.
///
/// @param [in] resource A <c><i>FfxResource</i></c>.
///
/// @returns
/// true The <c><i>resource</i></c> was not <c><i>FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_NULL</i></c>.
/// @returns
/// false The <c><i>resource</i></c> was <c><i>FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_NULL</i></c>.
///
/// @ingroup ffxFsr3Upscaler
FFX_API bool ffxFsr3UpscalerResourceIsNull(FfxResource resource);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxFsr3Upscaler
FFX_API FfxVersionNumber ffxFsr3UpscalerGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,44 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
/// @defgroup SDKComponents Effect Components
/// Runtime FidelityFX Effect Components that compile and link to calling effect libraries
///
/// @ingroup ffxSDK
#include <FidelityFX/host/ffx_fsr3.h>
#include <FidelityFX/host/ffx_fsr3upscaler.h>
#include <FidelityFX/host/ffx_frameinterpolation.h>
#include <FidelityFX/host/ffx_opticalflow.h>
#include <FidelityFX/host/ffx_fsr2.h>
#include <FidelityFX/host/ffx_fsr1.h>
#include <FidelityFX/host/ffx_spd.h>
#include <FidelityFX/host/ffx_lpm.h>
#include <FidelityFX/host/ffx_vrs.h>
#include <FidelityFX/host/ffx_dof.h>
#include <FidelityFX/host/ffx_blur.h>
#include <FidelityFX/host/ffx_cas.h>
#include <FidelityFX/host/ffx_lens.h>
#include <FidelityFX/host/ffx_denoiser.h>
#include <FidelityFX/host/ffx_sssr.h>
#include <FidelityFX/host/ffx_breadcrumbs.h>

View File

@@ -0,0 +1,659 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <FidelityFX/host/ffx_assert.h>
#include <FidelityFX/host/ffx_types.h>
#include <FidelityFX/host/ffx_error.h>
#if defined(__cplusplus)
#define FFX_CPU
extern "C" {
#endif // #if defined(__cplusplus)
/// @defgroup Backends Backends
/// Core interface declarations and natively supported backends
///
/// @ingroup ffxSDK
/// @defgroup FfxInterface FfxInterface
/// FidelityFX SDK function signatures and core defines requiring
/// overrides for backend implementation.
///
/// @ingroup Backends
FFX_FORWARD_DECLARE(FfxInterface);
/// FidelityFX SDK major version.
///
/// @ingroup FfxInterface
#define FFX_SDK_VERSION_MAJOR (1)
/// FidelityFX SDK minor version.
///
/// @ingroup FfxInterface
#define FFX_SDK_VERSION_MINOR (1)
/// FidelityFX SDK patch version.
///
/// @ingroup FfxInterface
#define FFX_SDK_VERSION_PATCH (0)
/// Macro to pack a FidelityFX SDK version id together.
///
/// @ingroup FfxInterface
#define FFX_SDK_MAKE_VERSION( major, minor, patch ) ( ( major << 22 ) | ( minor << 12 ) | patch )
/// Stand in type for FfxPass
///
/// These will be defined for each effect individually (i.e. FfxFsr2Pass).
/// They are used to fetch the proper blob index to build effect shaders
///
/// @ingroup FfxInterface
typedef uint32_t FfxPass;
/// Get the SDK version of the backend context.
///
/// @param [in] backendInterface A pointer to the backend interface.
///
/// @returns
/// The SDK version a backend was built with.
///
/// @ingroup FfxInterface
typedef FfxVersionNumber(*FfxGetSDKVersionFunc)(
FfxInterface* backendInterface);
/// Get effect VRAM usage.
///
/// Newer effects may require support that legacy versions of the SDK will not be
/// able to provide. A version query is thus required to ensure an effect component
/// will always be paired with a backend which will support all needed functionality.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] effectContextId The context space to be used for the effect in question.
/// @param [out] outVramUsage The effect memory usage structure to fill out.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxGetEffectGpuMemoryUsageFunc)(FfxInterface* backendInterface, FfxUInt32 effectContextId, FfxEffectMemoryUsage* outVramUsage);
/// Create and initialize the backend context.
///
/// The callback function sets up the backend context for rendering.
/// It will create or reference the device and create required internal data structures.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] bindlessConfig A pointer to the bindless configuration, if required by the effect.
/// @param [out] effectContextId The context space to be used for the effect in question.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxCreateBackendContextFunc)(
FfxInterface* backendInterface,
FfxEffectBindlessConfig* bindlessConfig,
FfxUInt32* effectContextId);
/// Get a list of capabilities of the device.
///
/// When creating an <c><i>FfxEffectContext</i></c> it is desirable for the FFX
/// core implementation to be aware of certain characteristics of the platform
/// that is being targetted. This is because some optimizations which FFX SDK
/// attempts to perform are more effective on certain classes of hardware than
/// others, or are not supported by older hardware. In order to avoid cases
/// where optimizations actually have the effect of decreasing performance, or
/// reduce the breadth of support provided by FFX SDK, the FFX interface queries the
/// capabilities of the device to make such decisions.
///
/// For target platforms with fixed hardware support you need not implement
/// this callback function by querying the device, but instead may hardcore
/// what features are available on the platform.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [out] outDeviceCapabilities The device capabilities structure to fill out.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode(*FfxGetDeviceCapabilitiesFunc)(
FfxInterface* backendInterface,
FfxDeviceCapabilities* outDeviceCapabilities);
/// Destroy the backend context and dereference the device.
///
/// This function is called when the <c><i>FfxEffectContext</i></c> is destroyed.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] effectContextId The context space to be used for the effect in question.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode(*FfxDestroyBackendContextFunc)(
FfxInterface* backendInterface,
FfxUInt32 effectContextId);
/// Create a resource.
///
/// This callback is intended for the backend to create internal resources.
///
/// Please note: It is also possible that the creation of resources might
/// itself cause additional resources to be created by simply calling the
/// <c><i>FfxCreateResourceFunc</i></c> function pointer again. This is
/// useful when handling the initial creation of resources which must be
/// initialized. The flow in such a case would be an initial call to create the
/// CPU-side resource, another to create the GPU-side resource, and then a call
/// to schedule a copy render job to move the data between the two. Typically
/// this type of function call flow is only seen during the creation of an
/// <c><i>FfxEffectContext</i></c>.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] createResourceDescription A pointer to a <c><i>FfxCreateResourceDescription</i></c>.
/// @param [in] effectContextId The context space to be used for the effect in question.
/// @param [out] outResource A pointer to a <c><i>FfxResource</i></c> object.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxCreateResourceFunc)(
FfxInterface* backendInterface,
const FfxCreateResourceDescription* createResourceDescription,
FfxUInt32 effectContextId,
FfxResourceInternal* outResource);
/// Register a resource in the backend for the current frame.
///
/// Since the FfxInterface and the backends are not aware how many different
/// resources will get passed in over time, it's not safe
/// to register all resources simultaneously in the backend.
/// Also passed resources may not be valid after the dispatch call.
/// As a result it's safest to register them as FfxResourceInternal
/// and clear them at the end of the dispatch call.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] inResource A pointer to a <c><i>FfxResource</i></c>.
/// @param [in] effectContextId The context space to be used for the effect in question.
/// @param [out] outResource A pointer to a <c><i>FfxResourceInternal</i></c> object.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode(*FfxRegisterResourceFunc)(
FfxInterface* backendInterface,
const FfxResource* inResource,
FfxUInt32 effectContextId,
FfxResourceInternal* outResource);
/// Get an FfxResource from an FfxResourceInternal resource.
///
/// At times it is necessary to create an FfxResource representation
/// of an internally created resource in order to register it with a
/// child effect context. This function sets up the FfxResource needed
/// to register.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] resource The <c><i>FfxResourceInternal</i></c> for which to setup an FfxResource.
///
/// @returns
/// An FfxResource built from the internal resource
///
/// @ingroup FfxInterface
typedef FfxResource(*FfxGetResourceFunc)(
FfxInterface* backendInterface,
FfxResourceInternal resource);
/// Unregister all temporary FfxResourceInternal from the backend.
///
/// Unregister FfxResourceInternal referencing resources passed to
/// a function as a parameter.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] commandList A pointer to a <c><i>FfxCommandList</i></c> structure.
/// @param [in] effectContextId The context space to be used for the effect in question.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode(*FfxUnregisterResourcesFunc)(
FfxInterface* backendInterface,
FfxCommandList commandList,
FfxUInt32 effectContextId);
/// Register a resource in the static bindless table of the backend.
///
/// A static resource will persist in their respective bindless table until it is
/// overwritten by a different resource at the same index.
/// The calling code must take care not to immediately register a new resource at an index
/// that might be in use by an in-flight frame.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] desc A pointer to an <c><i>FfxStaticResourceDescription</i></c>.
/// @param [in] effectContextId The context space to be used for the effect in question.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxRegisterStaticResourceFunc)(FfxInterface* backendInterface,
const FfxStaticResourceDescription* desc,
FfxUInt32 effectContextId);
/// Retrieve a <c><i>FfxResourceDescription</i></c> matching a
/// <c><i>FfxResource</i></c> structure.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] resource A pointer to a <c><i>FfxResource</i></c> object.
///
/// @returns
/// A description of the resource.
///
/// @ingroup FfxInterface
typedef FfxResourceDescription (*FfxGetResourceDescriptionFunc)(
FfxInterface* backendInterface,
FfxResourceInternal resource);
/// Destroy a resource
///
/// This callback is intended for the backend to release an internal resource.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] resource A pointer to a <c><i>FfxResource</i></c> object.
/// @param [in] effectContextId The context space to be used for the effect in question.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxDestroyResourceFunc)(
FfxInterface* backendInterface,
FfxResourceInternal resource,
FfxUInt32 effectContextId);
/// Map resource memory
///
/// Maps the memory of the resource to a pointer and returns it.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] resource A pointer to a <c><i>FfxResource</i></c> object.
/// @param [out] ptr A pointer to the mapped memory.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxMapResourceFunc)(FfxInterface* backendInterface, FfxResourceInternal resource, void** ptr);
/// Unmap resource memory
///
/// Unmaps previously mapped memory of a resource.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] resource A pointer to a <c><i>FfxResource</i></c> object.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxUnmapResourceFunc)(FfxInterface* backendInterface, FfxResourceInternal resource);
/// Destroy a resource
///
/// This callback is intended for the backend to release an internal resource.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] resource A pointer to a <c><i>FfxResource</i></c> object.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxStageConstantBufferDataFunc)(
FfxInterface* backendInterface,
void* data,
FfxUInt32 size,
FfxConstantBuffer* constantBuffer);
/// Create a render pipeline.
///
/// A rendering pipeline contains the shader as well as resource bindpoints
/// and samplers.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] pass The identifier for the pass.
/// @param [in] pipelineDescription A pointer to a <c><i>FfxPipelineDescription</i></c> describing the pipeline to be created.
/// @param [in] effectContextId The context space to be used for the effect in question.
/// @param [out] outPipeline A pointer to a <c><i>FfxPipelineState</i></c> structure which should be populated.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxCreatePipelineFunc)(
FfxInterface* backendInterface,
FfxEffect effect,
FfxPass pass,
uint32_t permutationOptions,
const FfxPipelineDescription* pipelineDescription,
FfxUInt32 effectContextId,
FfxPipelineState* outPipeline);
typedef FfxErrorCode(*FfxGetPermutationBlobByIndexFunc)(FfxEffect effectId,
FfxPass passId,
FfxBindStage bindStage,
uint32_t permutationOptions,
FfxShaderBlob* outBlob);
/// Destroy a render pipeline.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] effectContextId The context space to be used for the effect in question.
/// @param [out] pipeline A pointer to a <c><i>FfxPipelineState</i></c> structure which should be released.
/// @param [in] effectContextId The context space to be used for the effect in question.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxDestroyPipelineFunc)(
FfxInterface* backendInterface,
FfxPipelineState* pipeline,
FfxUInt32 effectContextId);
/// Schedule a render job to be executed on the next call of
/// <c><i>FfxExecuteGpuJobsFunc</i></c>.
///
/// Render jobs can perform one of three different tasks: clear, copy or
/// compute dispatches.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] job A pointer to a <c><i>FfxGpuJobDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxScheduleGpuJobFunc)(
FfxInterface* backendInterface,
const FfxGpuJobDescription* job);
/// Execute scheduled render jobs on the <c><i>comandList</i></c> provided.
///
/// The recording of the graphics API commands should take place in this
/// callback function, the render jobs which were previously enqueued (via
/// callbacks made to <c><i>FfxScheduleGpuJobFunc</i></c>) should be
/// processed in the order they were received. Advanced users might choose to
/// reorder the rendering jobs, but should do so with care to respect the
/// resource dependencies.
///
/// Depending on the precise contents of <c><i>FfxDispatchDescription</i></c> a
/// different number of render jobs might have previously been enqueued (for
/// example if sharpening is toggled on and off).
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] commandList A pointer to a <c><i>FfxCommandList</i></c> structure.
/// @param [in] effectContextId The context space to be used for the effect in question.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxExecuteGpuJobsFunc)(
FfxInterface* backendInterface,
FfxCommandList commandList,
FfxUInt32 effectContextId);
typedef enum FfxUiCompositionFlags
{
FFX_UI_COMPOSITION_FLAG_USE_PREMUL_ALPHA = (1 << 0), ///< A bit indicating that we use premultiplied alpha for UI composition
FFX_UI_COMPOSITION_FLAG_ENABLE_INTERNAL_UI_DOUBLE_BUFFERING = (1 << 1), ///< A bit indicating that the swapchain should doublebuffer the UI resource
} FfxUiCompositionFlags;
typedef FfxErrorCode(*FfxPresentCallbackFunc)(const FfxPresentCallbackDescription* params, void*);
typedef FfxErrorCode(*FfxFrameGenerationDispatchFunc)(const FfxFrameGenerationDispatchDescription* params, void*);
/// A structure representing the configuration options to pass to FfxFrameInterpolation.
///
/// @ingroup FfxInterface
typedef struct FfxFrameGenerationConfig
{
FfxSwapchain swapChain; ///< The <c><i>FfxSwapchain</i></c> to use with frame interpolation
FfxPresentCallbackFunc presentCallback; ///< A UI composition callback to call when finalizing the frame image
void* presentCallbackContext; ///< A pointer to be passed to the UI composition callback
FfxFrameGenerationDispatchFunc frameGenerationCallback; ///< The frame generation callback to use to generate the interpolated frame
void* frameGenerationCallbackContext; ///< A pointer to be passed to the frame generation callback
bool frameGenerationEnabled; ///< Sets the state of frame generation. Set to false to disable frame generation
bool allowAsyncWorkloads; ///< Sets the state of async workloads. Set to true to enable interpolation work on async compute
bool allowAsyncPresent; ///< Sets the state of async presentation (console only). Set to true to enable present from async command queue
FfxResource HUDLessColor; ///< The hudless back buffer image to use for UI extraction from backbuffer resource
FfxUInt32 flags; ///< Flags
bool onlyPresentInterpolated; ///< Set to true to only present interpolated frame
FfxRect2D interpolationRect; ///< Set the area in the backbuffer that will be interpolated
uint64_t frameID; ///< A frame identifier used to synchronize resource usage in workloads
} FfxFrameGenerationConfig;
typedef FfxErrorCode (*FfxSwapChainConfigureFrameGenerationFunc)(FfxFrameGenerationConfig const* config);
/// Allocate AMD FidelityFX Breadcrumbs Library markers buffer.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] blockBytes Size in bytes of the buffer to be allocated.
/// @param [out] blockData Output information about allocated AMD FidelityFX Breadcrumbs Library buffer. Filled only on success of operation.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// Anything else The operation failed.
///
/// @ingroup FfxInterface
typedef FfxErrorCode (*FfxBreadcrumbsAllocBlockFunc)(
FfxInterface* backendInterface,
uint64_t blockBytes,
FfxBreadcrumbsBlockData* blockData
);
/// Deallocate AMD FidelityFX Breadcrumbs Library markers buffer.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [out] blockData Information about buffer to be freed. All resource handles are cleared after this operation.
///
/// @ingroup FfxInterface
typedef void (*FfxBreadcrumbsFreeBlockFunc)(
FfxInterface* backendInterface,
FfxBreadcrumbsBlockData* blockData
);
/// Write marker to AMD FidelityFX Breadcrumbs Library buffer on the <c><i>comandList</i></c> provided.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] commandList GPU command list to record marker writing command.
/// @param [in] value Marker value to be written.
/// @param [in] gpuLocation GPU destination address where marker will be written.
/// @param [in] gpuBuffer Destination AMD FidelityFX Breadcrumbs Library buffer.
/// @param [in] isBegin <c><i>true</i></c> for writing opening marker and <c><i>false</i></c> for ending marker.
///
/// @ingroup FfxInterface
typedef void (*FfxBreadcrumbsWriteFunc)(
FfxInterface* backendInterface,
FfxCommandList commandList,
uint32_t value,
uint64_t gpuLocation,
void* gpuBuffer,
bool isBegin
);
/// Printing GPU specific info to the AMD FidelityFX Breadcrumbs Library status buffer.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] allocs A pointer to the allocation callbacks.
/// @param [in] extendedInfo <c><i>true</i></c> if should print more verbose device info and <c><i>false</i></c> for standard output.
/// @param [out] printBuffer String buffer for writing GPU info.
/// @param [out] printSize Size of string buffer for writing GPU info.
///
/// @ingroup FfxInterface
typedef void (*FfxBreadcrumbsPrintDeviceInfoFunc)(
FfxInterface* backendInterface,
FfxAllocationCallbacks* allocs,
bool extendedInfo,
char** printBuffer,
size_t* printSize
);
/// Register a <b>Thread Safe</b> constant buffer allocator to be used by the backend.
///
/// @param [in] backendInterface A pointer to the backend interface.
/// @param [in] constantAllocator An <c><i>FfxConstantBufferAllocator</i></c> callback to be used by the backend.
///
/// @ingroup FfxInterface
typedef void(*FfxRegisterConstantBufferAllocatorFunc)(FfxInterface* backendInterface,
FfxConstantBufferAllocator constantAllocator);
/// A structure encapsulating the interface between the core implementation of
/// the FfxInterface and any graphics API that it should ultimately call.
///
/// This set of functions serves as an abstraction layer between FfxInterfae and the
/// API used to implement it. While the FidelityFX SDK ships with backends for DirectX12 and
/// Vulkan, it is possible to implement your own backend for other platforms
/// which sit on top of your engine's own abstraction layer. For details on the
/// expectations of what each function should do you should refer the
/// description of the following function pointer types:
/// - <c><i>FfxCreateDeviceFunc</i></c>
/// - <c><i>FfxGetDeviceCapabilitiesFunc</i></c>
/// - <c><i>FfxDestroyDeviceFunc</i></c>
/// - <c><i>FfxCreateResourceFunc</i></c>
/// - <c><i>FfxRegisterResourceFunc</i></c>
/// - <c><i>FfxGetResourceFunc</i></c>
/// - <c><i>FfxUnregisterResourcesFunc</i></c>
/// - <c><i>FfxGetResourceDescriptionFunc</i></c>
/// - <c><i>FfxDestroyResourceFunc</i></c>
/// - <c><i>FfxCreatePipelineFunc</i></c>
/// - <c><i>FfxDestroyPipelineFunc</i></c>
/// - <c><i>FfxScheduleGpuJobFunc</i></c>
/// - <c><i>FfxExecuteGpuJobsFunc</i></c>
/// - <c><i>FfxBeginMarkerFunc</i></c>
/// - <c><i>FfxEndMarkerFunc</i></c>
/// - <c><i>FfxRegisterConstantBufferAllocatorFunc</i></c>
///
/// Depending on the graphics API that is abstracted by the backend, it may be
/// required that the backend is to some extent stateful. To ensure that
/// applications retain full control to manage the memory used by the FidelityFX SDK, the
/// <c><i>scratchBuffer</i></c> and <c><i>scratchBufferSize</i></c> fields are
/// provided. A backend should provide a means of specifying how much scratch
/// memory is required for its internal implementation (e.g: via a function
/// or constant value). The application is then responsible for allocating that
/// memory and providing it when setting up the SDK backend. Backends provided
/// with the FidelityFX SDK do not perform dynamic memory allocations, and instead
/// sub-allocate all memory from the scratch buffers provided.
///
/// The <c><i>scratchBuffer</i></c> and <c><i>scratchBufferSize</i></c> fields
/// should be populated according to the requirements of each backend. For
/// example, if using the DirectX 12 backend you should call the
/// <c><i>ffxGetScratchMemorySizeDX12</i></c> function. It is not required
/// that custom backend implementations use a scratch buffer.
///
/// Any functional addition to this interface mandates a version
/// bump to ensure full functionality across effects and backends.
///
/// @ingroup FfxInterface
typedef struct FfxInterface {
// FidelityFX SDK 1.0 callback handles
FfxGetSDKVersionFunc fpGetSDKVersion; ///< A callback function to query the SDK version.
FfxGetEffectGpuMemoryUsageFunc fpGetEffectGpuMemoryUsage; ///< A callback function to query effect Gpu memory usage
FfxCreateBackendContextFunc fpCreateBackendContext; ///< A callback function to create and initialize the backend context.
FfxGetDeviceCapabilitiesFunc fpGetDeviceCapabilities; ///< A callback function to query device capabilites.
FfxDestroyBackendContextFunc fpDestroyBackendContext; ///< A callback function to destroy the backendcontext. This also dereferences the device.
FfxCreateResourceFunc fpCreateResource; ///< A callback function to create a resource.
FfxRegisterResourceFunc fpRegisterResource; ///< A callback function to register an external resource.
FfxGetResourceFunc fpGetResource; ///< A callback function to convert an internal resource to external resource type
FfxUnregisterResourcesFunc fpUnregisterResources; ///< A callback function to unregister external resource.
FfxRegisterStaticResourceFunc fpRegisterStaticResource; ///< A callback function to register a static resource.
FfxGetResourceDescriptionFunc fpGetResourceDescription; ///< A callback function to retrieve a resource description.
FfxDestroyResourceFunc fpDestroyResource; ///< A callback function to destroy a resource.
FfxMapResourceFunc fpMapResource; ///< A callback function to map a resource.
FfxUnmapResourceFunc fpUnmapResource; ///< A callback function to unmap a resource.
FfxStageConstantBufferDataFunc fpStageConstantBufferDataFunc; ///< A callback function to copy constant buffer data into staging memory.
FfxCreatePipelineFunc fpCreatePipeline; ///< A callback function to create a render or compute pipeline.
FfxDestroyPipelineFunc fpDestroyPipeline; ///< A callback function to destroy a render or compute pipeline.
FfxScheduleGpuJobFunc fpScheduleGpuJob; ///< A callback function to schedule a render job.
FfxExecuteGpuJobsFunc fpExecuteGpuJobs; ///< A callback function to execute all queued render jobs.
// FidelityFX SDK 1.1 callback handles
FfxBreadcrumbsAllocBlockFunc fpBreadcrumbsAllocBlock; ///< A callback function to allocate block of memory for AMD FidelityFX Breadcrumbs Library buffer.
FfxBreadcrumbsFreeBlockFunc fpBreadcrumbsFreeBlock; ///< A callback function to free AMD FidelityFX Breadcrumbs Library buffer.
FfxBreadcrumbsWriteFunc fpBreadcrumbsWrite; ///< A callback function to write marker into AMD FidelityFX Breadcrumbs Library.
FfxBreadcrumbsPrintDeviceInfoFunc fpBreadcrumbsPrintDeviceInfo; ///< A callback function to print active GPU info for AMD FidelityFX Breadcrumbs Library log.
FfxGetPermutationBlobByIndexFunc fpGetPermutationBlobByIndex;
FfxSwapChainConfigureFrameGenerationFunc fpSwapChainConfigureFrameGeneration; ///< A callback function to configure swap chain present callback.
FfxRegisterConstantBufferAllocatorFunc fpRegisterConstantBufferAllocator; ///< A callback function to register a custom <b>Thread Safe</b> constant buffer allocator.
void* scratchBuffer; ///< A preallocated buffer for memory utilized internally by the backend.
size_t scratchBufferSize; ///< Size of the buffer pointed to by <c><i>scratchBuffer</i></c>.
FfxDevice device; ///< A backend specific device
} FfxInterface;
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,216 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup Lens
#pragma once
// Include the interface for the backend of the Lens API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup FfxLens FidelityFX Lens
/// FidelityFX Lens runtime library
///
/// @ingroup SDKComponents
/// FidelityFX Lens major version.
///
/// @ingroup FfxLens
#define FFX_LENS_VERSION_MAJOR (1)
/// FidelityFX Lens minor version.
///
/// @ingroup FfxLens
#define FFX_LENS_VERSION_MINOR (1)
/// FidelityFX Lens patch version.
///
/// @ingroup FfxLens
#define FFX_LENS_VERSION_PATCH (0)
/// FidelityFX Lens context count
///
/// Defines the number of internal effect contexts required by Lens
///
/// @ingroup FfxLens
#define FFX_LENS_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup FfxLens
#define FFX_LENS_CONTEXT_SIZE (9200)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of the pass which constitutes the Lens algorithm.
///
/// Lens is implemented as a single pass algorithm. Each call to the
/// <c><i>FfxLensScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single lens effect compute job. For a
/// more comprehensive description of Lens's inner workings, please
/// refer to the Lens reference documentation.
///
/// @ingroup FfxLens
typedef enum FfxLensPass
{
FFX_LENS_PASS_MAIN_PASS = 0, ///< A pass which which applies the lens effect
FFX_LENS_PASS_COUNT ///< The number of passes in Lens
} FfxLensPass;
typedef enum FfxLensFloatPrecision
{
FFX_LENS_FLOAT_PRECISION_32BIT = 0,
FFX_LENS_FLOAT_PRECISION_16BIT = 1,
FFX_LENS_FLOAT_PRECISION_COUNT = 2
} FfxLensFloatPrecision;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxLensContext</i></c>. See <c><i>FfxLensContextDescription</i></c>.
///
/// @ingroup FfxLens
typedef enum FfxLensInitializationFlagBits {
FFX_LENS_MATH_NONPACKED = (1 << 0), ///< A bit indicating if we should use floating point math
FFX_LENS_MATH_PACKED = (1 << 1) ///< A bit indicating if we should use 16-bit half precision floating point math (favored)
} FfxLensInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Lens.
///
/// @ingroup FfxLens
typedef struct FfxLensContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxLensInitializationFlagBits</i></c>
FfxSurfaceFormat outputFormat; ///< Format of the output target used for creation of output resource.
FfxLensFloatPrecision floatPrecision; ///< A flag indicating the desired floating point precision for use in ffxBlurContextDispatch
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX.
} FfxLensContextDescription;
/// A structure encapsulating the parameters for dispatching
/// of FidelityFX Lens
///
/// @ingroup FfxLens
typedef struct FfxLensDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record Lens rendering commands into.
FfxResource resource; ///< The <c><i>FfxResource</i></c> to run Lens on.
FfxResource resourceOutput; ///< The <c><i>FfxResource</i></c> to write Lens output to.
FfxDimensions2D renderSize; ///< The resolution used for rendering the scene.
float grainScale; ///< Artistic tweaking constant for grain scale..
float grainAmount; ///< Artistic tweaking constant for how intense the grain is.
uint32_t grainSeed; ///< The seed for grain RNG.
float chromAb; ///< Artistic tweaking constant for chromatic aberration intensity.
float vignette; ///< Artistic tweaking constant for vignette intensity.
} FfxLensDispatchDescription;
/// A structure encapsulating the FidelityFX Lens context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by Lens.
///
/// The <c><i>FfxLensContext</i></c> object should have a lifetime matching
/// your use of Lens. Before destroying the Lens context care should be taken
/// to ensure the GPU is not accessing the resources created or used by Lens.
/// It is therefore recommended that the GPU is idle before destroying the
/// Lens context.
///
/// @ingroup FfxLens
typedef struct FfxLensContext {
uint32_t data[FFX_LENS_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxLensContext;
/// Create a FidelityFX Lens Downsampler context from the parameters
/// programmed to the <c><i>FfxLensContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the Lens
/// API, and is responsible for the management of the internal resources
/// used by the Lens algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>backendInterface</i></c>
/// structure. This backend will attempt to retrieve the device capabilities,
/// and create the internal resources, and pipelines required by Lens to function.
/// Depending on the precise configuration used when
/// creating the <c><i>FfxLensContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxLensContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or Lens
/// upscaling is disabled by a user. To destroy the Lens context you
/// should call <c><i>ffxLensContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxLensContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxLensContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxLensContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxLens
FFX_API FfxErrorCode ffxLensContextCreate(FfxLensContext* pContext, const FfxLensContextDescription* pContextDescription);
/// Dispatches work to the FidelityFX Lens context
///
/// @param [out] pContext A pointer to a <c><i>FfxLensContext</i></c> structure to populate.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxLensDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxLens
FFX_API FfxErrorCode ffxLensContextDispatch(FfxLensContext* pContext, const FfxLensDispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX Lens context.
///
/// @param [out] pContext A pointer to a <c><i>FfxLensContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FfxLens
FFX_API FfxErrorCode ffxLensContextDestroy(FfxLensContext* pContext);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FfxLens
FFX_API FfxVersionNumber ffxLensGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,273 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup LPM
#pragma once
// Include the interface for the backend of the LPM 1.0 API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup FfxLpm FidelityFX LPM
/// FidelityFX Luma Preserving Mapper runtime library
///
/// @ingroup SDKComponents
/// FidelityFX Luma Preserving Mapper 1.3 major version.
///
/// @ingroup FfxLpm
#define FFX_LPM_VERSION_MAJOR (1)
/// FidelityFX Luma Preserving Mapper 1.3 minor version.
///
/// @ingroup FfxLpm
#define FFX_LPM_VERSION_MINOR (4)
/// FidelityFX Luma Preserving Mapper 1.3 patch version.
///
/// @ingroup FfxLpm
#define FFX_LPM_VERSION_PATCH (0)
/// FidelityFX Luma Preserving Mapper context count
///
/// Defines the number of internal effect contexts required by LPM
///
/// @ingroup FfxLpm
#define FFX_LPM_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup FfxLpm
#define FFX_LPM_CONTEXT_SIZE (9300)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of all the passes which constitute the LPM algorithm.
///
/// LPM is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxLPMScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxLPMPass</i></c>. For a
/// more comprehensive description of each pass, please refer to the LPM
/// reference documentation.
///
/// @ingroup FfxLpm
typedef enum FfxLpmPass
{
FFX_LPM_PASS_FILTER = 0, ///< A pass which filters the color buffer using LPM's tone and gamut mapping solution.
FFX_LPM_PASS_COUNT ///< The number of passes performed by LPM.
} FfxLpmPass;
/// An enumeration of monitor display modes supported by LPM
/// FFX_LPM_DISPLAYMODE_LDR tagets low or standard dynamic range monitor using 8bit back buffer
/// FFX_LPM_DISPLAYMODE_HDR10_2084 targets HDR10 perceptual quantizer (PQ) transfer function using 10bit backbuffer
/// FFX_LPM_DISPLAYMODE_HDR10_SCRGB targets HDR10 linear output with no transfer function using 16bit backbuffer
/// FFX_LPM_DISPLAYMODE_FSHDR_2084 targets freesync premium pro hdr thorugh PQ transfer function using 10bit backbuffer
/// FFX_LPM_DISPLAYMODE_FSHDR_SCRGB targets linear output with no transfer function using 16bit backbuffer
/// @ingroup LPM
typedef enum class FfxLpmDisplayMode
{
FFX_LPM_DISPLAYMODE_LDR = 0,
FFX_LPM_DISPLAYMODE_HDR10_2084 = 1,
FFX_LPM_DISPLAYMODE_HDR10_SCRGB = 2,
FFX_LPM_DISPLAYMODE_FSHDR_2084 = 3,
FFX_LPM_DISPLAYMODE_FSHDR_SCRGB = 4
} FfxLpmDisplayMode;
/// An enumeration of colourspaces supported by LPM
/// FFX_LPM_ColorSpace_REC709 uses rec709 colour primaries used for FFX_LPM_DISPLAYMODE_LDR, FFX_LPM_DISPLAYMODE_HDR10_SCRGB and FFX_LPM_DISPLAYMODE_FSHDR_SCRGB modes
/// FFX_LPM_ColorSpace_P3 uses P3 colour primaries
/// FFX_LPM_ColorSpace_REC2020 uses rec2020 colour primaries used for FFX_LPM_DISPLAYMODE_HDR10_2084 and FFX_LPM_DISPLAYMODE_FSHDR_2084 modes
/// FFX_LPM_ColorSapce_Display uses custom primaries queried from display
/// @ingroup LPM
typedef enum class FfxLpmColorSpace
{
FFX_LPM_ColorSpace_REC709 = 0,
FFX_LPM_ColorSpace_P3 = 1,
FFX_LPM_ColorSpace_REC2020 = 2,
FFX_LPM_ColorSapce_Display = 3,
} FfxLpmColorSpace;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxLpmContext</i></c>. See <c><i>FfxLpmContextDescription</i></c>.
///
/// @ingroup FfxLpm
typedef enum FfxLpmInitializationFlagBits
{
} FfxLpmInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Luma Preserving Mapper
///
/// @ingroup FfxLpm
typedef struct FfxLpmContextDescription
{
uint32_t flags;
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for LPM.
} FfxLpmContextDescription;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX Luma Preserving Mapper 1.0
///
/// @ingroup FfxLpm
typedef struct FfxLpmDispatchDescription
{
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record LPM rendering commands into.
FfxResource inputColor; ///< A <c><i>FfxResource</i></c> containing the color buffer for the current frame.
FfxResource outputColor; ///< A <c><i>FfxResource</i></c> containing the tone and gamut mapped output color buffer for the current frame.
bool shoulder;
float softGap;
float hdrMax;
float lpmExposure;
float contrast;
float shoulderContrast;
float saturation[3];
float crosstalk[3];
FfxLpmColorSpace colorSpace;
FfxLpmDisplayMode displayMode;
float displayRedPrimary[2];
float displayGreenPrimary[2];
float displayBluePrimary[2];
float displayWhitePoint[2];
float displayMinLuminance;
float displayMaxLuminance;
} FfxLpmDispatchDescription;
/// A structure encapsulating the FidelityFX Luma Preserving 1.0 context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by LPM.
///
/// The <c><i>FfxLpmContext</i></c> object should have a lifetime matching
/// your use of LPM. Before destroying the LPM context care should be taken
/// to ensure the GPU is not accessing the resources created or used by LPM.
/// It is therefore recommended that the GPU is idle before destroying the
/// LPM context.
///
/// @ingroup FfxLpm
typedef struct FfxLpmContext
{
uint32_t data[FFX_LPM_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxLpmContext;
/// Create a FidelityFX Luma Preserving 1.0 context from the parameters
/// programmed to the <c><i>FfxLpmContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the Luma Preserving
/// Mapper 1.0 API, and is responsible for the management of the internal resources
/// used by the LPM algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>callbacks</i></c>
/// structure. These callbacks will attempt to retreive the device capabilities,
/// and create the internal resources, and pipelines required by LPM
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxLpmContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxLpmContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or LPM
/// tone and gamut mapping is disabled by a user. To destroy the LPM context you
/// should call <c><i>ffxLpmContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxLpmContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxLpmContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxLpmContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxLpm
FFX_API FfxErrorCode ffxLpmContextCreate(FfxLpmContext* pContext, const FfxLpmContextDescription* pContextDescription);
/// Dispatches work to the FidelityFX LPM context
/// @param [out] pContext A pointer to a <c><i>FfxLpmContext</i></c> structure to populate.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxLpmDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxLpm
FFX_API FfxErrorCode ffxLpmContextDispatch(FfxLpmContext* pContext, const FfxLpmDispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX LPM context.
///
/// @param [out] pContext A pointer to a <c><i>FfxLpmContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FfxLpm
FFX_API FfxErrorCode ffxLpmContextDestroy(FfxLpmContext* pContext);
/// Sets up the constant buffer data necessary for LPM compute
///
/// @param [in] incon
/// @param [in] insoft
/// @param [in] incon2
/// @param [in] inclip
/// @param [in] inscaleOnly
/// @param [out] outcon
/// @param [out] outsoft
/// @param [out] outcon2
/// @param [out] outclip
/// @param [out] outscaleOnly
///
/// @retval
/// FFX_OK The operation completed successfully.
///
/// @ingroup FfxLpm
FFX_API FfxErrorCode FfxPopulateLpmConsts(bool incon,
bool insoft,
bool incon2,
bool inclip,
bool inscaleOnly,
uint32_t& outcon,
uint32_t& outsoft,
uint32_t& outcon2,
uint32_t& outclip,
uint32_t& outscaleOnly);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FfxLpm
FFX_API FfxVersionNumber ffxLpmGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,212 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup OpticalFlow
#pragma once
// Include the interface for the backend of the OpticalFlow API.
#include <FidelityFX/host/ffx_interface.h>
/// FidelityFX OpticalFlow major version.
///
/// @ingroup ffxOpticalflow
#define FFX_OPTICALFLOW_VERSION_MAJOR (1)
/// FidelityFX OpticalFlow minor version.
///
/// @ingroup ffxOpticalflow
#define FFX_OPTICALFLOW_VERSION_MINOR (1)
/// FidelityFX OpticalFlow patch version.
///
/// @ingroup ffxOpticalflow
#define FFX_OPTICALFLOW_VERSION_PATCH (1)
/// FidelityFX Optical Flow context count
///
/// Defines the number of internal effect contexts required by Optical Flow
///
/// @ingroup ffxOpticalFlow
#define FFX_OPTICALFLOW_CONTEXT_COUNT (1)
/// The size of the context specified in 32bit size units.
///
/// @ingroup ffxOpticalflow
#define FFX_OPTICALFLOW_CONTEXT_SIZE (FFX_SDK_DEFAULT_CONTEXT_SIZE)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of all the passes which constitute the OpticalFlow algorithm.
///
/// @ingroup ffxOpticalflow
typedef enum FfxOpticalflowPass
{
FFX_OPTICALFLOW_PASS_PREPARE_LUMA = 0,
FFX_OPTICALFLOW_PASS_GENERATE_OPTICAL_FLOW_INPUT_PYRAMID,
FFX_OPTICALFLOW_PASS_GENERATE_SCD_HISTOGRAM,
FFX_OPTICALFLOW_PASS_COMPUTE_SCD_DIVERGENCE,
FFX_OPTICALFLOW_PASS_COMPUTE_OPTICAL_FLOW_ADVANCED_V5,
FFX_OPTICALFLOW_PASS_FILTER_OPTICAL_FLOW_V5,
FFX_OPTICALFLOW_PASS_SCALE_OPTICAL_FLOW_ADVANCED_V5,
FFX_OPTICALFLOW_PASS_COUNT
} FfxOpticalflowPass;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxOpticalflowContext</i></c>. See <c><i>FfxOpticalflowDispatchDescription</i></c>.
///
/// @ingroup ffxOpticalflow
typedef enum FfxOpticalflowInitializationFlagBits
{
FFX_OPTICALFLOW_ENABLE_TEXTURE1D_USAGE = (1 << 0),
} FfxOpticalflowInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize
/// FidelityFX OpticalFlow.
///
/// @ingroup ffxOpticalflow
typedef struct FfxOpticalflowContextDescription {
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX SDK
uint32_t flags; ///< A collection of <c><i>FfxOpticalflowInitializationFlagBits</i></c>.
FfxDimensions2D resolution;
} FfxOpticalflowContextDescription;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX Opticalflow.
///
/// @ingroup ffxOpticalflow
typedef struct FfxOpticalflowDispatchDescription
{
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record rendering commands into.
FfxResource color; ///< A <c><i>FfxResource</i></c> containing the input color buffer
FfxResource opticalFlowVector; ///< A <c><i>FfxResource</i></c> containing the output motion buffer
FfxResource opticalFlowSCD; ///< A <c><i>FfxResource</i></c> containing the output scene change detection buffer
bool reset; ///< A boolean value which when set to true, indicates the camera has moved discontinuously.
int backbufferTransferFunction;
FfxFloatCoords2D minMaxLuminance;
} FfxOpticalflowDispatchDescription;
typedef struct FfxOpticalflowSharedResourceDescriptions {
FfxCreateResourceDescription opticalFlowVector;
FfxCreateResourceDescription opticalFlowSCD;
} FfxOpticalflowSharedResourceDescriptions;
/// A structure encapsulating the FidelityFX OpticalFlow context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by OpticalFlow.
///
/// The <c><i>FfxOpticalflowContext</i></c> object should have a lifetime matching
/// your use of OpticalFlow. Before destroying the OpticalFlow context care should be taken
/// to ensure the GPU is not accessing the resources created or used by OpticalFlow.
/// It is therefore recommended that the GPU is idle before destroying OpticalFlow
/// OpticalFlow context.
///
/// @ingroup ffxOpticalflow
typedef struct FfxOpticalflowContext
{
uint32_t data[FFX_OPTICALFLOW_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxOpticalflowContext;
/// Create a FidelityFX OpticalFlow context from the parameters
/// programmed to the <c><i>FfxOpticalflowContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the OpticalFlow
/// API, and is responsible for the management of the internal resources used
/// by the OpticalFlow algorithm. When this API is called, multiple calls will be
/// made via the pointers contained in the <c><i>callbacks</i></c> structure.
/// These callbacks will attempt to retreive the device capabilities, and
/// create the internal resources, and pipelines required by OpticalFlow's
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxOpticalflowContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The flags included in the <c><i>flags</i></c> field of
/// <c><i>FfxOpticalflowContext</i></c> how match the configuration of your
/// application as well as the intended use of OpticalFlow. It is important that these
/// flags are set correctly (as well as a correct programmed
/// <c><i>FfxOpticalflowContextDescription</i></c>) to ensure correct operation. It is
/// recommended to consult the overview documentation for further details on
/// how OpticalFlow should be integerated into an application.
///
/// When the <c><i>FfxOpticalflowContext</i></c> is created, you should use the
/// <c><i>ffxOpticalflowContextDispatch</i></c> function each frame where FSR3
/// upscaling should be applied. See the documentation of
/// <c><i>ffxOpticalflowContextDispatch</i></c> for more details.
///
/// The <c><i>FfxOpticalflowContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or OpticalFlow is
/// disabled by a user. To destroy the OpticalFlow context you should call
/// <c><i>ffxOpticalflowContextDestroy</i></c>.
///
/// @param [out] context A pointer to a <c><i>FfxOpticalflowContext</i></c> structure to populate.
/// @param [in] contextDescription A pointer to a <c><i>FfxOpticalflowContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxOpticalflowContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxOpticalflow
FFX_API FfxErrorCode ffxOpticalflowContextCreate(FfxOpticalflowContext* context, FfxOpticalflowContextDescription* contextDescription);
FFX_API FfxErrorCode ffxOpticalflowContextGetGpuMemoryUsage(FfxOpticalflowContext* pContext, FfxEffectMemoryUsage* vramUsage);
FFX_API FfxErrorCode ffxOpticalflowGetSharedResourceDescriptions(FfxOpticalflowContext* context, FfxOpticalflowSharedResourceDescriptions* SharedResources);
FFX_API FfxErrorCode ffxOpticalflowContextDispatch(FfxOpticalflowContext* context, const FfxOpticalflowDispatchDescription* dispatchDescription);
/// Destroy the FidelityFX OpticalFlow context.
///
/// @param [out] context A pointer to a <c><i>FfxOpticalflowContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup ffxOpticalflow
FFX_API FfxErrorCode ffxOpticalflowContextDestroy(FfxOpticalflowContext* context);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxOpticalflow
FFX_API FfxVersionNumber ffxOpticalflowGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,210 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup PARALLEL_SORT
#pragma once
// Include the interface for the backend of the FSR2 API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup FfxParallelSort FidelityFX Parallel Sort
/// FidelityFX Single Pass Downsampler runtime library
///
/// @ingroup SDKComponents
/// FidelityFX Parallel Sort major version.
///
/// @ingroup FfxParallelSort
#define FFX_PARALLELSORT_VERSION_MAJOR (1)
/// FidelityFX Parallel Sort minor version.
///
/// @ingroup FfxParallelSort
#define FFX_PARALLELSORT_VERSION_MINOR (3)
/// FidelityFX Parallel Sort patch version.
///
/// @ingroup FfxParallelSort
#define FFX_PARALLELSORT_VERSION_PATCH (0)
/// FidelityFX SPD context count
///
/// Defines the number of internal effect contexts required by SPD
///
/// @ingroup FfxParallelSort
#define FFX_PARALLELSORT_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup FfxParallelSort
#define FFX_PARALLELSORT_CONTEXT_SIZE (373712)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of the passes which constitute the Parallel Sort algorithm.
///
/// Parallel Sort is implemented as a multi-pass algorithm that is invoked over
/// a number of successive iterations until all bits in the key are sorted.
/// For a more comprehensive description of Parallel Sort's inner workings, please
/// refer to the Parallel Sort reference documentation.
///
/// @ingroup FfxParallelSort
typedef enum FfxParallelSortPass
{
FFX_PARALLELSORT_PASS_SETUP_INDIRECT_ARGS = 0, ///< A pass which sets up indirect params to invoke sorting when <c><i>FFX_PARALLEL_SORT_INDIRECT</i></c> flag bit is set.
FFX_PARALLELSORT_PASS_SUM, ///< A pass which counts the number of occurrences of each value in the data set.
FFX_PARALLELSORT_PASS_REDUCE, ///< A pass which further reduces the counts across thread groups for faster offset calculations in large data sets.
FFX_PARALLELSORT_PASS_SCAN, ///< A pass which prefixes the count totals into global offsets.
FFX_PARALLELSORT_PASS_SCAN_ADD, ///< A pass which does a second prefix add the global offsets to each local thread group offset.
FFX_PARALLELSORT_PASS_SCATTER, ///< A pass which performs a local sort of all values in the thread group and outputs to new global offset
FFX_PARALLELSORT_PASS_COUNT ///< The number of passes in Parallel Sort
} FfxParallelSortPass;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxParallelSortContextDescription</i></c>. See <c><i>FfxParallelSortContextDescription</i></c>.
///
/// @ingroup FfxParallelSort
typedef enum FfxParallelSortInitializationFlagBits {
FFX_PARALLELSORT_INDIRECT_SORT = (1 << 0), ///< A bit indicating if we should use indirect version of sort algorithm
FFX_PARALLELSORT_PAYLOAD_SORT = (1 << 1), ///< A bit indicating if we should sort a payload buffer
} FfxParallelSortInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Parallel Sort.
///
/// @ingroup FfxParallelSort
typedef struct FfxParallelSortContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxParallelSortInitializationFlagBits</i></c>.
uint32_t maxEntries; ///< Maximum number of entries to sort
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX.
} FfxParallelSortContextDescription;
/// A structure encapsulating the parameters needed to sort
/// the buffer(s) provided
///
/// @ingroup FfxParallelSort
typedef struct FfxParallelSortDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record parallel sort compute commands into.
FfxResource keyBuffer; ///< The buffer resource containing the keys to sort
FfxResource payloadBuffer; ///< The (optional) payload buffer to sort (requires <c><i>FFX_PARALLELSORT_PAYLOAD_SORT</i></c> be set)
uint32_t numKeysToSort; ///< The number of keys in the buffer requiring sorting
} FfxParallelSortDispatchDescription;
/// A structure encapsulating the FidelityFX Parallel Sort context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by parallel sort.
///
/// The <c><i>FfxParallelSortContext</i></c> object should have a lifetime matching
/// your use of parallel sort. Before destroying the parallel sort context care
/// should be taken to ensure the GPU is not accessing the resources created or
/// used by parallel sort. It is therefore recommended that the GPU is idle
/// before destroying the parallel sort context.
///
/// @ingroup FfxParallelSort
typedef struct FfxParallelSortContext {
uint32_t data[FFX_PARALLELSORT_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxParallelSortContext;
/// Create a FidelityFX Parallel Sort context from the parameters
/// programmed to the <c><i>FfxParallelSortContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the parallel
/// sort API, and is responsible for the management of the internal resources
/// used by the parallel sort algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>callbacks</i></c>
/// structure. These callbacks will attempt to retreive the device capabilities,
/// and create the internal resources, and pipelines required by parallel sorts'
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxParallelSortContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxParallelSortContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or parallel sort
/// upscaling is disabled by a user. To destroy the parallel sort context you
/// should call <c><i>ffxParallelSortContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxParallelSortContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxParallelSortContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxFsr2ContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxParallelSort
FFX_API FfxErrorCode ffxParallelSortContextCreate(FfxParallelSortContext* pContext, const FfxParallelSortContextDescription* pContextDescription);
/// Execute a FidelityFX Parallel Sort context to sort the provided data
/// according to the passed in dispatch description.
///
/// @param [out] pContext A pointer to a <c><i>FfxParallelSortContext</i></c> structure to populate.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxParallelSortDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>sortDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxParallelSort
FFX_API FfxErrorCode ffxParallelSortContextDispatch(FfxParallelSortContext* pContext, const FfxParallelSortDispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX Parallel Sort context.
///
/// @param [out] pContext A pointer to a <c><i>FfxParallelSortContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FfxParallelSort
FFX_API FfxErrorCode ffxParallelSortContextDestroy(FfxParallelSortContext* pContext);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FfxParallelSort
FFX_API FfxVersionNumber ffxParallelSortGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,222 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup FSR2
#pragma once
// Include the interface for the backend of the FSR2 API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup FfxSpd FidelityFX SPD
/// FidelityFX Single Pass Downsampler runtime library
///
/// @ingroup SDKComponents
/// FidelityFX SPD major version.
///
/// @ingroup FfxSpd
#define FFX_SPD_VERSION_MAJOR (2)
/// FidelityFX SPD minor version.
///
/// @ingroup FfxSpd
#define FFX_SPD_VERSION_MINOR (2)
/// FidelityFX SPD patch version.
///
/// @ingroup FfxSpd
#define FFX_SPD_VERSION_PATCH (0)
/// FidelityFX SPD context count
///
/// Defines the number of internal effect contexts required by SPD
///
/// @ingroup FfxSpd
#define FFX_SPD_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup FfxSpd
#define FFX_SPD_CONTEXT_SIZE (9300)
/// If this ever changes, need to also reflect a change in number
/// of resources in ffx_spd_resources.h
///
/// @ingroup FfxSpd
#define SPD_MAX_MIP_LEVELS 12
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of the pass which constitutes the SPD algorithm.
///
/// SPD is implemented as a single pass algorithm. Each call to the
/// <c><i>FfxSPDScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single downsample job. For a
/// more comprehensive description of SPD's inner workings, please
/// refer to the SPD reference documentation.
///
/// @ingroup FfxSpd
typedef enum FfxSpdPass
{
FFX_SPD_PASS_DOWNSAMPLE = 0, ///< A pass which which downsamples all mips
FFX_SPD_PASS_COUNT ///< The number of passes in SPD
} FfxSpdPass;
typedef enum FfxSpdDownsampleFilter
{
FFX_SPD_DOWNSAMPLE_FILTER_MEAN = 0,
FFX_SPD_DOWNSAMPLE_FILTER_MIN,
FFX_SPD_DOWNSAMPLE_FILTER_MAX,
FFX_SPD_DOWNSAMPLE_FILTER_COUNT
} FfxSpdDownsampleFilter;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxSpdContext</i></c>. See <c><i>FfxSpdContextDescription</i></c>.
///
/// @ingroup FfxSpd
typedef enum FfxSpdInitializationFlagBits {
FFX_SPD_SAMPLER_LOAD = (1 << 0), ///< A bit indicating if we should use resource loads (favor loads over sampler)
FFX_SPD_SAMPLER_LINEAR = (1 << 1), ///< A bit indicating if we should use sampler to load resources.
FFX_SPD_WAVE_INTEROP_LDS = (1 << 2), ///< A bit indicating if we should use LDS
FFX_SPD_WAVE_INTEROP_WAVE_OPS = (1 << 3), ///< A bit indicating if we should use WAVE OPS (favor wave ops over LDS)
FFX_SPD_MATH_NONPACKED = (1 << 4), ///< A bit indicating if we should use floating point math
FFX_SPD_MATH_PACKED = (1 << 5) ///< A bit indicating if we should use 16-bit half precision floating point math (favored)
} FfxSpdInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Single Pass Downsampler.
///
/// @ingroup FfxSpd
typedef struct FfxSpdContextDescription {
uint32_t flags; ///< A collection of <c><i>FfxSpdInitializationFlagBits</i></c>
FfxSpdDownsampleFilter downsampleFilter;
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX.
} FfxSpdContextDescription;
/// A structure encapsulating the parameters for dispatching
/// of FidelityFX Single Pass Downsampler
///
/// @ingroup FfxSpd
typedef struct FfxSpdDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record rendering commands into.
FfxResource resource; ///< The <c><i>FfxResource</i></c> to downsample
} FfxSpdDispatchDescription;
/// A structure encapsulating the FidelityFX single pass downsampler context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by SPD.
///
/// The <c><i>FfxSpdContext</i></c> object should have a lifetime matching
/// your use of FSR1. Before destroying the SPD context care should be taken
/// to ensure the GPU is not accessing the resources created or used by SPD.
/// It is therefore recommended that the GPU is idle before destroying the
/// SPD context.
///
/// @ingroup FfxSpd
typedef struct FfxSpdContext {
uint32_t data[FFX_SPD_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxSpdContext;
/// Create a FidelityFX Single Pass Downsampler context from the parameters
/// programmed to the <c><i>FfxSpdContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the Single
/// Pass Downsampler API, and is responsible for the management of the internal resources
/// used by the SPD algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>backendInterface</i></c>
/// structure. This backend will attempt to retrieve the device capabilities,
/// and create the internal resources, and pipelines required by SPD to function.
/// Depending on the precise configuration used when
/// creating the <c><i>FfxSpdContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxSpdContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or SPD
/// upscaling is disabled by a user. To destroy the SPD context you
/// should call <c><i>ffxSpdContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxSpdContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxSpdContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxSpdContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxSpd
FFX_API FfxErrorCode ffxSpdContextCreate(FfxSpdContext* pContext, const FfxSpdContextDescription* pContextDescription);
/// Dispatches work to the FidelityFX SPD context
///
/// @param [out] pContext A pointer to a <c><i>FfxSpdContext</i></c> structure to populate.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxSpdDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxSpd
FFX_API FfxErrorCode ffxSpdContextDispatch(FfxSpdContext* pContext, const FfxSpdDispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX SPD context.
///
/// @param [out] pContext A pointer to a <c><i>FfxSpdContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FfxSpd
FFX_API FfxErrorCode ffxSpdContextDestroy(FfxSpdContext* pContext);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FfxSpd
FFX_API FfxVersionNumber ffxSpdGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

View File

@@ -0,0 +1,260 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
// Include the interface for the backend of the SSSR API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup FfxSssr FidelityFX SSSR
/// FidelityFX Stochastic Screen Space Reflections runtime library
///
/// @ingroup SDKComponents
/// FidelityFX Stochastic Screen Space Reflections major version.
///
/// @ingroup FfxSssr
#define FFX_SSSR_VERSION_MAJOR (1)
/// FidelityFX Stochastic Screen Space Reflections minor version.
///
/// @ingroup FfxSssr
#define FFX_SSSR_VERSION_MINOR (5)
/// FidelityFX Stochastic Screen Space Reflections patch version.
///
/// @ingroup FfxSssr
#define FFX_SSSR_VERSION_PATCH (0)
/// FidelityFX SSSR context count
///
/// Defines the number of internal effect contexts required by SSSR
/// We need 2, one for the SSSR context and one for the FidelityFX Denoiser
///
/// @ingroup FfxSssr
#define FFX_SSSR_CONTEXT_COUNT 2
/// The size of the context specified in 32bit values.
///
/// @ingroup FfxSssr
#define FFX_SSSR_CONTEXT_SIZE (118882)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of all the passes which constitute the SSSR algorithm.
///
/// SSSR is implemented as a composite of several compute passes each
/// computing a key part of the final result. Each call to the
/// <c><i>FfxSssrScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single pass included in <c><i>FfxSssrPass</i></c>. For a
/// more comprehensive description of each pass, please refer to the SSSR
/// reference documentation.
///
/// @ingroup FfxSssr
typedef enum FfxSssrPass
{
FFX_SSSR_PASS_DEPTH_DOWNSAMPLE = 0, ///< A pass which performs the hierarchical depth buffer generation
FFX_SSSR_PASS_CLASSIFY_TILES = 1, ///< A pass which classifies which pixels require screen space ray marching
FFX_SSSR_PASS_PREPARE_BLUE_NOISE_TEXTURE = 2, ///< A pass which generates an optimized blue noise texture
FFX_SSSR_PASS_PREPARE_INDIRECT_ARGS = 3, ///< A pass which generates the indirect arguments for the intersection pass.
FFX_SSSR_PASS_INTERSECTION = 4, ///< A pass which performs the actual hierarchical depth ray marching.
FFX_SSSR_PASS_COUNT
} FfxSssrPass;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxSssrContext</i></c>. See <c><i>FfxSssrContextDescription</i></c>.
///
/// @ingroup FfxSssr
typedef enum FfxSssrInitializationFlagBits {
FFX_SSSR_ENABLE_DEPTH_INVERTED = (1 << 0) ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
} FfxSssrInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Stochastic Screen Space Reflections.
///
/// @ingroup ffxSssr
typedef struct FfxSssrContextDescription
{
uint32_t flags; ///< A collection of <c><i>FfxSssrInitializationFlagBits</i></c>.
FfxDimensions2D renderSize; ///< The resolution we are currently rendering at
FfxSurfaceFormat normalsHistoryBufferFormat; ///< The format used by the reflections denoiser to store the normals buffer history
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX SDK
} FfxSssrContextDescription;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX Stochastic Screen Space Reflections.
///
/// @ingroup ffxSssr
typedef struct FfxSssrDispatchDescription {
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record SSSR rendering commands into.
FfxResource color; ///< A <c><i>FfxResource</i></c> containing the color buffer for the current frame.
FfxResource depth; ///< A <c><i>FfxResource</i></c> containing the depth buffer for the current frame.
FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing the motion vectors buffer for the current frame.
FfxResource normal; ///< A <c><i>FfxResource</i></c> containing the normal buffer for the current frame.
FfxResource materialParameters; ///< A <c><i>FfxResource</i></c> containing the roughness buffer for the current frame.
FfxResource environmentMap; ///< A <c><i>FfxResource</i></c> containing the environment map to fallback to when screenspace data is not sufficient.
FfxResource brdfTexture; ///< A <c><i>FfxResource</i></c> containing the precomputed brdf LUT.
FfxResource output; ///< A <c><i>FfxResource</i></c> to store the result of the SSSR algorithm into.
float invViewProjection[16]; ///< An array containing the inverse of the view projection matrix in column major layout.
float projection[16]; ///< An array containing the projection matrix in column major layout.
float invProjection[16]; ///< An array containing the inverse of the projection matrix in column major layout.
float view[16]; ///< An array containing the view matrix in column major layout.
float invView[16]; ///< An array containing the inverse of the view matrix in column major layout.
float prevViewProjection[16]; ///< An array containing the previous frame's view projection matrix in column major layout.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors.
float iblFactor; ///< A factor to control the intensity of the image based lighting. Set to 1 for an HDR probe.
float normalUnPackMul; ///< A multiply factor to transform the normal to the space expected by SSSR.
float normalUnPackAdd; ///< An offset to transform the normal to the space expected by SSSR.
uint32_t roughnessChannel; ///< The channel to read the roughness from the materialParameters texture
bool isRoughnessPerceptual; ///< A boolean to describe the space used to store roughness in the materialParameters texture. If false, we assume roughness squared was stored in the Gbuffer.
float temporalStabilityFactor; ///< A factor to control the accmulation of history values. Higher values reduce noise, but are more likely to exhibit ghosting artefacts.
float depthBufferThickness; ///< A bias for accepting hits. Larger values can cause streaks, lower values can cause holes.
float roughnessThreshold; ///< Regions with a roughness value greater than this threshold won't spawn rays.
float varianceThreshold; ///< Luminance differences between history results will trigger an additional ray if they are greater than this threshold value.
uint32_t maxTraversalIntersections; ///< Caps the maximum number of lookups that are performed from the depth buffer hierarchy. Most rays should terminate after approximately 20 lookups.
uint32_t minTraversalOccupancy; ///< Exit the core loop early if less than this number of threads are running.
uint32_t mostDetailedMip; ///< The most detailed MIP map level in the depth hierarchy. Perfect mirrors always use 0 as the most detailed level.
uint32_t samplesPerQuad; ///< The minimum number of rays per quad. Variance guided tracing can increase this up to a maximum of 4.
uint32_t temporalVarianceGuidedTracingEnabled; ///< A boolean controlling whether a ray should be spawned on pixels where a temporal variance is detected or not.
} FfxSssrDispatchDescription;
/// A structure encapsulating the FidelityFX Stochastic Screen Space Reflections context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by SSSR.
///
/// The <c><i>FfxSssrContext</i></c> object should have a lifetime matching
/// your use of SSSR. Before destroying the SSSR context care should be taken
/// to ensure the GPU is not accessing the resources created or used by SSSR.
/// It is therefore recommended that the GPU is idle before destroying the
/// SSSR context.
///
/// @ingroup ffxSssr
typedef struct FfxSssrContext
{
uint32_t data[FFX_SSSR_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxSssrContext;
/// Create a FidelityFX Stochastic Screen Space Reflections context from the parameters
/// programmed to the <c><i>FfxSssrCreateParams</i></c> structure.
///
/// The context structure is the main object used to interact with the SSSR
/// API, and is responsible for the management of the internal resources used
/// by the SSSR algorithm. When this API is called, multiple calls will be
/// made via the pointers contained in the <c><i>callbacks</i></c> structure.
/// These callbacks will attempt to retreive the device capabilities, and
/// create the internal resources, and pipelines required by SSSR's
/// frame-to-frame function. Depending on the precise configuration used when
/// creating the <c><i>FfxSssrContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The flags included in the <c><i>flags</i></c> field of
/// <c><i>FfxSssrContext</i></c> how match the configuration of your
/// application as well as the intended use of SSSR. It is important that these
/// flags are set correctly (as well as a correct programmed
/// <c><i>FfxSssrDispatchDescription</i></c>) to ensure correct operation. It is
/// recommended to consult the overview documentation for further details on
/// how SSSR should be integerated into an application.
///
/// When the <c><i>FfxSssrContext</i></c> is created, you should use the
/// <c><i>ffxSssrContextDispatch</i></c> function each frame where SSSR
/// algorithm should be applied. See the documentation of
/// <c><i>ffxSssrContextDispatch</i></c> for more details.
///
/// The <c><i>FfxSssrContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or SSSR upscaling is
/// disabled by a user. To destroy the SSSR context you should call
/// <c><i>ffxSssrContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxSssrContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxSssrContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxSssrContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxSssr
FFX_API FfxErrorCode ffxSssrContextCreate(FfxSssrContext* context, const FfxSssrContextDescription* contextDescription);
/// Dispatch the various passes that constitute the FidelityFX Stochastic Screen Space Reflections.
///
/// SSSR is a composite effect, meaning that it is compromised of multiple
/// constituent passes (implemented as one or more clears, copies and compute
/// dispatches). The <c><i>ffxSssrContextDispatch</i></c> function is the
/// function which (via the use of the functions contained in the
/// <c><i>callbacks</i></c> field of the <c><i>FfxSssrContext</i></c>
/// structure) utlimately generates the sequence of graphics API calls required
/// each frame.
///
/// As with the creation of the <c><i>FfxSssrContext</i></c> correctly
/// programming the <c><i>FfxSssrDispatchDescription</i></c> is key to ensuring
/// the correct operation of SSSR.
///
/// @param [in] pContext A pointer to a <c><i>FfxSssrContext</i></c> structure.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxSssrDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_NULL_DEVICE The operation failed because the device inside the context was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup ffxSssr
FFX_API FfxErrorCode ffxSssrContextDispatch(FfxSssrContext* context, const FfxSssrDispatchDescription* dispatchDescription);
/// Destroy the FidelityFX Stochastic Screen Space Reflections context.
///
/// @param [out] pContext A pointer to a <c><i>FfxSssrContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup ffxSssr
FFX_API FfxErrorCode ffxSssrContextDestroy(FfxSssrContext* context);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup ffxSssr
FFX_API FfxVersionNumber ffxSssrGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,190 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <FidelityFX/host/ffx_types.h>
/// @defgroup Utils Utilities
/// Utility Macros used by the FidelityFX SDK
///
/// @ingroup ffxHost
/// The value of Pi.
///
/// @ingroup Utils
const float FFX_PI = 3.141592653589793f;
/// An epsilon value for floating point numbers.
///
/// @ingroup Utils
const float FFX_EPSILON = 1e-06f;
/// Helper macro to create the version number.
///
/// @ingroup Utils
#define FFX_MAKE_VERSION(major, minor, patch) ((major << 22) | (minor << 12) | patch)
///< Use this to specify no version.
///
/// @ingroup Utils
#define FFX_UNSPECIFIED_VERSION 0xFFFFAD00
/// Helper macro to avoid warnings about unused variables.
///
/// @ingroup Utils
#define FFX_UNUSED(x) ((void)(x))
/// Helper macro to align an integer to the specified power of 2 boundary
///
/// @ingroup Utils
#define FFX_ALIGN_UP(x, y) (((x) + ((y)-1)) & ~((y)-1))
/// Helper macro to check if a value is aligned.
///
/// @ingroup Utils
#define FFX_IS_ALIGNED(x) (((x) != 0) && ((x) & ((x)-1)))
/// Helper macro to compute the rounded-up integer division of two unsigned integers
///
/// @ingroup Utils
#define FFX_DIVIDE_ROUNDING_UP(x, y) ((x + y - 1) / y)
/// Helper macro to stringify a value.
///
/// @ingroup Utils
#define FFX_STR(s) FFX_XSTR(s)
#define FFX_XSTR(s) #s
/// Helper macro to forward declare a structure.
///
/// @ingroup Utils
#define FFX_FORWARD_DECLARE(x) typedef struct x x
/// Helper macro to return the maximum of two values.
///
/// @ingroup Utils
#define FFX_MAXIMUM(x, y) (((x) > (y)) ? (x) : (y))
/// Helper macro to return the minimum of two values.
///
/// @ingroup Utils
#define FFX_MINIMUM(x, y) (((x) < (y)) ? (x) : (y))
/// Helper macro to do safe free on a pointer.
///
/// @ingroup Utils
#define FFX_SAFE_FREE(x, freeFunc) \
do { \
if (x) \
{ \
freeFunc(x); \
x = nullptr; \
} \
} while (false)
/// Helper macro to return the abs of an integer value.
///
/// @ingroup Utils
#define FFX_ABSOLUTE(x) (((x) < 0) ? (-(x)) : (x))
/// Helper macro to return sign of a value.
///
/// @ingroup Utils
#define FFX_SIGN(x) (((x) < 0) ? -1 : 1)
/// Helper macro to work out the number of elements in an array.
///
/// @ingroup Utils
#define FFX_ARRAY_ELEMENTS(x) (int32_t)((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x])))))
/// The maximum length of a path that can be specified to the FidelityFX API.
///
/// @ingroup Utils
#define FFX_MAXIMUM_PATH (260)
/// Helper macro to check if the specified key is set in a bitfield.
///
/// @ingroup Utils
#define FFX_CONTAINS_FLAG(options, key) (((options) & key) == key)
#if defined(FFX_MUTEX_IMPL_SHARED)
/// Lock mutex exclusively.
///
/// @ingroup Utils
#define FFX_MUTEX_LOCK(x) x.lock()
/// Lock mutex for shared access.
///
/// @ingroup Utils
#define FFX_MUTEX_LOCK_SHARED(x) x.lock_shared()
/// Unlock exclusive mutex lock.
///
/// @ingroup Utils
#define FFX_MUTEX_UNLOCK(x) x.unlock()
/// Unlock shared mutex lock.
///
/// @ingroup Utils
#define FFX_MUTEX_UNLOCK_SHARED(x) x.unlock_shared()
#elif defined(FFX_MUTEX_IMPL_STANDARD)
/// Lock mutex exclusively.
///
/// @ingroup Utils
#define FFX_MUTEX_LOCK(x) x.lock()
/// Lock mutex for shared access.
///
/// @ingroup Utils
#define FFX_MUTEX_LOCK_SHARED(x) FFX_MUTEX_LOCK(x)
/// Unlock exclusive mutex lock.
///
/// @ingroup Utils
#define FFX_MUTEX_UNLOCK(x) x.unlock()
/// Unlock shared mutex lock.
///
/// @ingroup Utils
#define FFX_MUTEX_UNLOCK_SHARED(x) FFX_MUTEX_UNLOCK(x)
#elif !defined(FFX_MUTEX_LOCK) || !defined(FFX_MUTEX_LOCK_SHARED) || !defined(FFX_MUTEX_UNLOCK) || !defined(FFX_MUTEX_UNLOCK_SHARED)
#error When using custom mutex you have to provide all following operations too: FFX_MUTEX_LOCK, FFX_MUTEX_LOCK_SHARED, FFX_MUTEX_UNLOCK, FFX_MUTEX_UNLOCK_SHARED!
#endif // #if defined(FFX_MUTEX_IMPL_SHARED)
/// Computes the number of bits set to 1 in a integer.
///
/// @param [in] val Integer mask.
///
/// @return Number of bits set to 1 in provided val.
///
/// @ingroup Utils
inline uint8_t ffxCountBitsSet(uint32_t val) noexcept
{
#if __cplusplus >= 202002L
return static_cast<uint8_t>(std::popcount(val));
#elif defined(_MSVC_LANG)
return static_cast<uint8_t>(__popcnt(val));
#elif defined(__GNUC__) || defined(__clang__)
return static_cast<uint8_t>(__builtin_popcount(val));
#else
uint32_t c = val - ((val >> 1) & 0x55555555);
c = ((c >> 2) & 0x33333333) + (c & 0x33333333);
c = ((c >> 4) + c) & 0x0F0F0F0F;
c = ((c >> 8) + c) & 0x00FF00FF;
return static_cast<uint8_t>(((c >> 16) + c) & 0x0000FFFF);
#endif
}

View File

@@ -0,0 +1,224 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// @defgroup VRS
#pragma once
// Include the interface for the backend of the FSR 2.0 API.
#include <FidelityFX/host/ffx_interface.h>
/// @defgroup FfxVrs FidelityFX VRS
/// FidelityFX Variable Rate Shading runtime library
///
/// @ingroup SDKComponents
/// FidelityFX VRS major version.
///
/// @ingroup FfxVrs
#define FFX_VRS_VERSION_MAJOR (1)
/// FidelityFX VRS minor version.
///
/// @ingroup FfxVrs
#define FFX_VRS_VERSION_MINOR (2)
/// FidelityFX VRS patch version.
///
/// @ingroup FfxVrs
#define FFX_VRS_VERSION_PATCH (0)
/// FidelityFX VRS context count
///
/// Defines the number of internal effect contexts required by VRS
///
/// @ingroup FfxVrs
#define FFX_VRS_CONTEXT_COUNT 1
/// The size of the context specified in 32bit values.
///
/// @ingroup FfxVrs
#define FFX_VRS_CONTEXT_SIZE (16536)
#if defined(__cplusplus)
extern "C" {
#endif // #if defined(__cplusplus)
/// An enumeration of the pass which constitutes the ShadingRateImage
/// generation algorithm.
///
/// VRS is implemented as a single pass algorithm. Each call to the
/// <c><i>FfxScheduleGpuJobFunc</i></c> callback function will
/// correspond to a single image generation job. For a
/// more comprehensive description of VRS's inner workings, please
/// refer to the VRS reference documentation.
///
/// @ingroup FfxVrs
typedef enum FfxVrsPass
{
FFX_VRS_PASS_IMAGEGEN = 0, ///< A pass which generates a ShadingRateImage.
FFX_VRS_PASS_COUNT ///< The number of passes performed by VRS.
} FfxVrsPass;
/// An enumeration of bit flags used when creating a
/// <c><i>FfxVrsContext</i></c>. See <c><i>FfxVrsContextDescription</i></c>.
///
/// @ingroup FfxVrs
typedef enum FfxVrsInitializationFlagBits
{
FFX_VRS_ALLOW_ADDITIONAL_SHADING_RATES = (1 << 0), ///< A bit indicating if we should enable additional shading rates.
} FfxVrsInitializationFlagBits;
/// A structure encapsulating the parameters required to initialize FidelityFX
/// Variable Shading
///
/// @ingroup FfxVrs
typedef struct FfxVrsContextDescription
{
uint32_t flags; ///< A collection of <c><i>FfxVrsInitializationFlagBits</i></c>
uint32_t shadingRateImageTileSize; ///< ShadingRateImage tile size.
FfxInterface backendInterface; ///< A set of pointers to the backend implementation for FidelityFX.
} FfxVrsContextDescription;
/// A structure encapsulating the parameters for dispatching the various passes
/// of FidelityFX Variable Shading
///
/// @ingroup FfxVrs
typedef struct FfxVrsDispatchDescription
{
FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record VRS rendering commands into.
FfxResource historyColor; ///< A <c><i>FfxResource</i></c> containing the color buffer for the previous frame (at presentation resolution).
FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing the velocity buffer for the current frame (at presentation resolution).
FfxResource output; ///< A <c><i>FfxResource</i></c> containing the ShadingRateImage buffer for the current frame.
FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resource.
float varianceCutoff; ///< This value specifies how much variance in luminance is acceptable to reduce shading rate.
float motionFactor; ///< The lower this value, the faster a pixel has to move to get the shading rate reduced.
uint32_t tileSize; ///< ShadingRateImage tile size.
FfxFloatCoords2D motionVectorScale; ///< Scale motion vectors to different format
} FfxVrsDispatchDescription;
/// A structure encapsulating the FidelityFX Variable Shading context.
///
/// This sets up an object which contains all persistent internal data and
/// resources that are required by VRS.
///
/// The <c><i>FfxVrsContext</i></c> object should have a lifetime matching
/// your use of VRS. Before destroying the VRS context care should be taken
/// to ensure the GPU is not accessing the resources created or used by VRS.
/// It is therefore recommended that the GPU is idle before destroying the
/// VRS context.
///
/// @ingroup FfxVrs
typedef struct FfxVrsContext
{
uint32_t data[FFX_VRS_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
} FfxVrsContext;
/// Create a FidelityFX Variable Shading context from the parameters
/// programmed to the <c><i>FfxVrsContextDescription</i></c> structure.
///
/// The context structure is the main object used to interact with the Variable
/// Shading API, and is responsible for the management of the internal resources
/// used by the VRS algorithm. When this API is called, multiple calls
/// will be made via the pointers contained in the <c><i>backendInterface</i></c>
/// structure. This backend will attempt to retrieve the device capabilities,
/// and create the internal resources, and pipelines required by VRS to function.
/// Depending on the precise configuration used when
/// creating the <c><i>FfxVrsContext</i></c> a different set of resources and
/// pipelines might be requested via the callback functions.
///
/// The <c><i>FfxVrsContext</i></c> should be destroyed when use of it is
/// completed, typically when an application is unloaded or Variable
/// Shading is disabled by a user. To destroy the VRS context you
/// should call <c><i>ffxVrsContextDestroy</i></c>.
///
/// @param [out] pContext A pointer to a <c><i>FfxVrsContext</i></c> structure to populate.
/// @param [in] pContextDescription A pointer to a <c><i>FfxVrsContextDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxVrsContextDescription.callbacks</i></c> was not fully specified.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxVrs
FFX_API FfxErrorCode ffxVrsContextCreate(FfxVrsContext* pContext, const FfxVrsContextDescription* pContextDescription);
/// Dispatches work to the FidelityFX VRS context
///
/// @param [in] pContext A pointer to a <c><i>FfxVrsContext</i></c> structure to populate.
/// @param [in] pDispatchDescription A pointer to a <c><i>FfxVrsDispatchDescription</i></c> structure.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
/// @retval
/// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
///
/// @ingroup FfxVrs
FFX_API FfxErrorCode ffxVrsContextDispatch(FfxVrsContext* pContext, const FfxVrsDispatchDescription* pDispatchDescription);
/// Destroy the FidelityFX VRS context.
///
/// @param [in] pContext A pointer to a <c><i>FfxVrsContext</i></c> structure to destroy.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
///
/// @ingroup FfxVrs
FFX_API FfxErrorCode ffxVrsContextDestroy(FfxVrsContext* pContext);
/// A helper function to calculate the ShadingRateImage size from a target
/// resolution.
///
///
/// @param [out] pImageWidth A pointer to a <c>uint32_t</c> which will hold the calculated image width.
/// @param [out] pImageHeight A pointer to a <c>uint32_t</c> which will hold the calculated image height.
/// @param [in] renderWidth The render resolution width.
/// @param [in] renderHeight The render resolution height.
/// @param [in] shadingRateImageTileSize The ShadingRateImage tile size.
///
/// @retval
/// FFX_OK The operation completed successfully.
/// @retval
/// FFX_ERROR_INVALID_POINTER Either <c><i>imageWidth</i></c> or <c><i>imageHeight</i></c> was <c>NULL</c>.
///
/// @ingroup FfxVrs
FFX_API FfxErrorCode ffxVrsGetImageSizeFromeRenderResolution(uint32_t* pImageWidth, uint32_t* pImageHeight, uint32_t renderWidth, uint32_t renderHeight, uint32_t shadingRateImageTileSize);
/// Queries the effect version number.
///
/// @returns
/// The SDK version the effect was built with.
///
/// @ingroup FfxVrs
FFX_API FfxVersionNumber ffxVrsGetEffectVersion();
#if defined(__cplusplus)
}
#endif // #if defined(__cplusplus)