Skip to content

Commit

Permalink
v1.125:
Browse files Browse the repository at this point in the history
HIGHLIGHTS:

- added "NRILowLatency" extension offering latency reduction via REFLEX (D3D and VK supported)
- added "NRIStreamer" extension offering comfortable constant, buffer and texture data streaming functionality
- added COPY timestamps support
- explicit "waitable" SwapChain (it improves behavior in multi-threaded environment, allowing to "wait for present" in one place and "acquire next image" in another)
- bug fixes and improvements

BREAKING CHANGES:

- "SwapChainPresent" => "QueuePresent" to emphasize that it's a queue command
- "QueueWait" and "QueueSignal" merged (again!) into "QueueSubmit": it maps better on "VK_KHR_synchronization2" and needed for "low latency" extension

DETAILS:
- Core: "QueueWait" and "QueueSignal" merged (again!) into "QueueSubmit"
- Core: exposed "QueryType::TIMESTAMP_COPY_QUEUE" needed for timestamps issued in COPY queue
- Core: slightly reworked "DeviceDesc", explicitly exposed NRI extension support status
- SwapChain: added "SwapChainDesc::waitable" swapchain support for all APIs
- SwapChain: explicitly exposed "WaitForPresent", which implicitly improves multi-threading behavior allowing to "wait" in one place and "acquire" in another
- SwapChain: added "SwapChainDesc::allowLowLatency"
- SwapChain: added "SwapChainDesc::queuedFrameNum" (use 0 for auto mode)
- Wrappers: minor tweaks
- D3D12: hooked up NVAPI and AMDAGS
- D3D12: updated Agility SDK
- VK: all CORE functions get queried by CORE or KHR names to improve compatibility with VK 1.2
- VK: VK_KHR_swapchain is an optional extension now
- VK: command queues gathering improved by introducing a score system
- VK: removed EXT suffixes from VK entities, which have been promoted to VK 1.2
- Validation: fixed a rare SwapChain related memory leak
- Validation: hooked up Streamer
- bug fixes and improvements
- improved .clang-format
  • Loading branch information
dzhdanNV committed Mar 20, 2024
1 parent f00dbbc commit 919412b
Show file tree
Hide file tree
Showing 183 changed files with 3,244 additions and 1,610 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
BasedOnStyle: Google
AccessModifierOffset: -2
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Expand Down Expand Up @@ -77,7 +77,7 @@ BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: Always
# BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakConstructorInitializers: AfterColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 180
Expand Down
17 changes: 12 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ option (NRI_ENABLE_WAYLAND_SUPPORT "Enable 'wayland' support" ON)
# Options: D3D12 specific
option (NRI_ENABLE_AGILITY_SDK_SUPPORT "Enable Agility SDK suupport to unlock access to recent D3D12 features" OFF)
set (NRI_AGILITY_SDK_PATH "C:/AgilitySDK" CACHE STRING "Path to a directory containing Agility SDK (contents of '.nupkg/build/native/')")
set (NRI_AGILITY_SDK_VERSION "711" CACHE STRING "Agility SDK version")
set (NRI_AGILITY_SDK_VERSION "613" CACHE STRING "Agility SDK version")
set (NRI_AGILITY_SDK_DIR "AgilitySDK" CACHE STRING "Directory where Agility SDK binaries will be copied to relative to 'CMAKE_RUNTIME_OUTPUT_DIRECTORY'")

# Is submodule?
Expand Down Expand Up @@ -137,7 +137,7 @@ if (WIN32 AND NRI_ENABLE_D3D11_SUPPORT)
target_include_directories (NRI_D3D11 PRIVATE "Include" "Source/Shared" "External")
target_compile_definitions (NRI_D3D11 PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options (NRI_D3D11 PRIVATE ${COMPILE_OPTIONS})
target_link_libraries (NRI_D3D11 PRIVATE NRI_Shared ${INPUT_LIBS_D3D11} ${INPUT_LIB_DXGUID} ${INPUT_LIB_NVAPI})
target_link_libraries (NRI_D3D11 PRIVATE NRI_Shared ${INPUT_LIBS_D3D11} ${INPUT_LIB_NVAPI} ${INPUT_LIB_DXGUID})
set_property (TARGET NRI_D3D11 PROPERTY FOLDER ${PROJECT_NAME})
endif ()

Expand All @@ -147,13 +147,20 @@ if (WIN32 AND NRI_ENABLE_D3D12_SUPPORT)
set (COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NRI_USE_D3D12=1)
set (INPUT_LIBS_D3D12 ${INPUT_LIB_D3D12} ${INPUT_LIB_DXGI})

find_library (INPUT_LIB_NVAPI NAMES nvapi64 nvapi PATHS "External/nvapi/${NVAPI_BIN_ARCHITECTURE}" REQUIRED)
find_library (INPUT_LIB_AGS NAMES amd_ags_${BIN_ARCHITECTURE} PATHS "External/amdags/ags_lib/lib" REQUIRED)

file (GLOB D3D12_SOURCE "Source/D3D12/*.cpp" "Source/D3D12/*.h" "Source/D3D12/*.hpp")
source_group ("" FILES ${D3D12_SOURCE})
add_library (NRI_D3D12 STATIC ${D3D12_SOURCE})
target_include_directories (NRI_D3D12 PRIVATE "Include" "Source/Shared")
file (GLOB D3D12_NVAPI "External/nvapi/*.h")
source_group ("External/nvapi" FILES ${D3D12_NVAPI})
file (GLOB D3D12_AMDAGS "External/amdags/ags_lib/inc/*.h")
source_group ("External/amdags" FILES ${D3D12_AMDAGS})
add_library (NRI_D3D12 STATIC ${D3D12_SOURCE} ${D3D12_NVAPI} ${D3D12_AMDAGS})
target_include_directories (NRI_D3D12 PRIVATE "Include" "Source/Shared" "External")
target_compile_definitions (NRI_D3D12 PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options (NRI_D3D12 PRIVATE ${COMPILE_OPTIONS})
target_link_libraries (NRI_D3D12 PRIVATE NRI_Shared ${INPUT_LIBS_D3D12})
target_link_libraries (NRI_D3D12 PRIVATE NRI_Shared ${INPUT_LIBS_D3D12} ${INPUT_LIB_NVAPI})
set_property (TARGET NRI_D3D12 PROPERTY FOLDER ${PROJECT_NAME})

if (NRI_ENABLE_AGILITY_SDK_SUPPORT)
Expand Down
51 changes: 39 additions & 12 deletions Include/Extensions/NRIHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ NRI_STRUCT(ResourceGroupDesc)

NRI_STRUCT(HelperInterface)
{
// Optimized memory allocation for a group of resources
uint32_t (NRI_CALL *CalculateAllocationNumber)(NRI_NAME_REF(Device) device, const NRI_NAME_REF(ResourceGroupDesc) resourceGroupDesc);
NRI_NAME(Result) (NRI_CALL *AllocateAndBindMemory)(NRI_NAME_REF(Device) device, const NRI_NAME_REF(ResourceGroupDesc) resourceGroupDesc, NRI_NAME(Memory)** allocations);
NRI_NAME(Result) (NRI_CALL *UploadData)(NRI_NAME_REF(CommandQueue) commandQueue, const NRI_NAME(TextureUploadDesc)* textureUploadDescs, uint32_t textureUploadDescNum,
const NRI_NAME(BufferUploadDesc)* bufferUploadDescs, uint32_t bufferUploadDescNum);

// Populate resources with data (not for streaming data)
NRI_NAME(Result) (NRI_CALL *UploadData)(NRI_NAME_REF(CommandQueue) commandQueue, const NRI_NAME(TextureUploadDesc)* textureUploadDescs, uint32_t textureUploadDescNum, const NRI_NAME(BufferUploadDesc)* bufferUploadDescs, uint32_t bufferUploadDescNum);

// WFI
NRI_NAME(Result) (NRI_CALL *WaitForIdle)(NRI_NAME_REF(CommandQueue) commandQueue);
};

Expand Down Expand Up @@ -97,7 +101,11 @@ static inline NRI_NAME(Format) NRI_FUNC_NAME(GetSupportedDepthFormat)(const NRI_
return NRI_ENUM_MEMBER(Format, UNKNOWN);
}

static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture1D)(NRI_NAME(Format) format, uint16_t width, NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(1), NRI_NAME(Dim_t) arraySize NRI_DEFAULT_VALUE(1),
// "TextureDesc" constructors
static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture1D)(NRI_NAME(Format) format,
uint16_t width,
NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(1),
NRI_NAME(Dim_t) arraySize NRI_DEFAULT_VALUE(1),
NRI_NAME(TextureUsageBits) usageMask NRI_DEFAULT_VALUE(NRI_ENUM_MEMBER(TextureUsageBits, SHADER_RESOURCE)))
{
NRI_NAME(TextureDesc) textureDesc = NRI_ZERO_INIT;
Expand All @@ -114,8 +122,13 @@ static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture1D)(NRI_NAME(Format) fo
return textureDesc;
}

static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture2D)(NRI_NAME(Format) format, NRI_NAME(Dim_t) width, NRI_NAME(Dim_t) height, NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(1), NRI_NAME(Dim_t) arraySize NRI_DEFAULT_VALUE(1),
NRI_NAME(TextureUsageBits) usageMask NRI_DEFAULT_VALUE(NRI_ENUM_MEMBER(TextureUsageBits, SHADER_RESOURCE)), NRI_NAME(Sample_t) sampleNum NRI_DEFAULT_VALUE(1))
static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture2D)(NRI_NAME(Format) format,
NRI_NAME(Dim_t) width,
NRI_NAME(Dim_t) height,
NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(1),
NRI_NAME(Dim_t) arraySize NRI_DEFAULT_VALUE(1),
NRI_NAME(TextureUsageBits) usageMask NRI_DEFAULT_VALUE(NRI_ENUM_MEMBER(TextureUsageBits, SHADER_RESOURCE)),
NRI_NAME(Sample_t) sampleNum NRI_DEFAULT_VALUE(1))
{
NRI_NAME(TextureDesc) textureDesc = NRI_ZERO_INIT;
textureDesc.type = NRI_ENUM_MEMBER(TextureType, TEXTURE_2D);
Expand All @@ -131,7 +144,11 @@ static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture2D)(NRI_NAME(Format) fo
return textureDesc;
}

static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture3D)(NRI_NAME(Format) format, NRI_NAME(Dim_t) width, NRI_NAME(Dim_t) height, uint16_t depth, NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(1),
static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture3D)(NRI_NAME(Format) format,
NRI_NAME(Dim_t) width,
NRI_NAME(Dim_t) height,
uint16_t depth,
NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(1),
NRI_NAME(TextureUsageBits) usageMask NRI_DEFAULT_VALUE(NRI_ENUM_MEMBER(TextureUsageBits, SHADER_RESOURCE)))
{
NRI_NAME(TextureDesc) textureDesc = NRI_ZERO_INIT;
Expand All @@ -148,8 +165,13 @@ static inline NRI_NAME(TextureDesc) NRI_FUNC_NAME(Texture3D)(NRI_NAME(Format) fo
return textureDesc;
}

static inline NRI_NAME(TextureBarrierDesc) NRI_FUNC_NAME(TextureBarrier)(NRI_NAME(Texture)* texture, NRI_NAME(AccessLayoutStage) before, NRI_NAME(AccessLayoutStage) after,
NRI_NAME(Mip_t) mipOffset NRI_DEFAULT_VALUE(0), NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(NRI_NAME(REMAINING_MIP_LEVELS)), NRI_NAME(Dim_t) arrayOffset NRI_DEFAULT_VALUE(0),
// "TextureBarrierDesc" constructors
static inline NRI_NAME(TextureBarrierDesc) NRI_FUNC_NAME(TextureBarrier)(NRI_NAME(Texture)* texture,
NRI_NAME(AccessLayoutStage) before,
NRI_NAME(AccessLayoutStage) after,
NRI_NAME(Mip_t) mipOffset NRI_DEFAULT_VALUE(0),
NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(NRI_NAME(REMAINING_MIP_LEVELS)),
NRI_NAME(Dim_t) arrayOffset NRI_DEFAULT_VALUE(0),
NRI_NAME(Dim_t) arraySize NRI_DEFAULT_VALUE(NRI_NAME(REMAINING_ARRAY_LAYERS)))
{
NRI_NAME(TextureBarrierDesc) textureBarrierDesc = NRI_ZERO_INIT;
Expand All @@ -164,8 +186,11 @@ static inline NRI_NAME(TextureBarrierDesc) NRI_FUNC_NAME(TextureBarrier)(NRI_NAM
return textureBarrierDesc;
}

static inline NRI_NAME(TextureBarrierDesc) NRI_FUNC_NAME(TextureBarrierFromUnknown)(NRI_NAME(Texture)* texture, NRI_NAME(AccessLayoutStage) after,
NRI_NAME(Mip_t) mipOffset NRI_DEFAULT_VALUE(0), NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(NRI_NAME(REMAINING_MIP_LEVELS)), NRI_NAME(Dim_t) arrayOffset NRI_DEFAULT_VALUE(0),
static inline NRI_NAME(TextureBarrierDesc) NRI_FUNC_NAME(TextureBarrierFromUnknown)(NRI_NAME(Texture)* texture,
NRI_NAME(AccessLayoutStage) after,
NRI_NAME(Mip_t) mipOffset NRI_DEFAULT_VALUE(0),
NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(NRI_NAME(REMAINING_MIP_LEVELS)),
NRI_NAME(Dim_t) arrayOffset NRI_DEFAULT_VALUE(0),
NRI_NAME(Dim_t) arraySize NRI_DEFAULT_VALUE(NRI_NAME(REMAINING_ARRAY_LAYERS)))
{
NRI_NAME(TextureBarrierDesc) textureBarrierDesc = NRI_ZERO_INIT;
Expand All @@ -182,8 +207,10 @@ static inline NRI_NAME(TextureBarrierDesc) NRI_FUNC_NAME(TextureBarrierFromUnkno
return textureBarrierDesc;
}

static inline NRI_NAME(TextureBarrierDesc) NRI_FUNC_NAME(TextureBarrierFromState)(NRI_NAME_REF(TextureBarrierDesc) prevState, NRI_NAME(AccessLayoutStage) after,
NRI_NAME(Mip_t) mipOffset NRI_DEFAULT_VALUE(0), NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(NRI_NAME(REMAINING_MIP_LEVELS)))
static inline NRI_NAME(TextureBarrierDesc) NRI_FUNC_NAME(TextureBarrierFromState)(NRI_NAME_REF(TextureBarrierDesc) prevState,
NRI_NAME(AccessLayoutStage) after,
NRI_NAME(Mip_t) mipOffset NRI_DEFAULT_VALUE(0),
NRI_NAME(Mip_t) mipNum NRI_DEFAULT_VALUE(NRI_NAME(REMAINING_MIP_LEVELS)))
{
NRI_REF_ACCESS(prevState)->mipOffset = mipOffset;
NRI_REF_ACCESS(prevState)->mipNum = mipNum;
Expand Down
63 changes: 63 additions & 0 deletions Include/Extensions/NRILowLatency.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// © 2024 NVIDIA Corporation

#pragma once

NRI_NAMESPACE_BEGIN

NRI_FORWARD_STRUCT(SwapChain);
NRI_FORWARD_STRUCT(CommandQueue);

// us = microseconds

NRI_ENUM
(
LatencyMarker, uint8_t,

// Should be called:
SIMULATION_START = 0, // at the start of the simulation execution each frame, but after the call to "LatencySleep"
SIMULATION_END = 1, // at the end of the simulation execution each frame
RENDER_SUBMIT_START = 2, // at the beginning of the render submission execution each frame (must not span into asynchronous rendering)
RENDER_SUBMIT_END = 3, // at the end of the render submission execution each frame
INPUT_SAMPLE = 6, // just before the application gathers input data, but between SIMULATION_START and SIMULATION_END (yes, 6!)

MAX_NUM
);

NRI_STRUCT(LatencySleepMode)
{
uint32_t minIntervalUs; // minimum allowed frame interval (0 - no frame rate limit)
bool lowLatencyMode; // low latency mode enablement
bool lowLatencyBoost; // hint to increase performance to provide additional latency savings at a cost of increased power consumption
};

NRI_STRUCT(LatencyReport)
{
// The time stamp written:
uint64_t inputSampleTimeUs; // when "SetLatencyMarker(INPUT_SAMPLE)" is called
uint64_t simulationStartTimeUs; // when "SetLatencyMarker(SIMULATION_START)" is called
uint64_t simulationEndTimeUs; // when "SetLatencyMarker(SIMULATION_END)" is called
uint64_t renderSubmitStartTimeUs; // when "SetLatencyMarker(RENDER_SUBMIT_START)" is called
uint64_t renderSubmitEndTimeUs; // when "SetLatencyMarker(RENDER_SUBMIT_END)" is called
uint64_t presentStartTimeUs; // right before "Present"
uint64_t presentEndTimeUs; // right after "Present"
uint64_t driverStartTimeUs; // when the first "QueueSubmitTrackable" is called
uint64_t driverEndTimeUs; // when the final "QueueSubmitTrackable" hands off from the driver
uint64_t osRenderQueueStartTimeUs;
uint64_t osRenderQueueEndTimeUs;
uint64_t gpuRenderStartTimeUs; // when the first submission reaches the GPU
uint64_t gpuRenderEndTimeUs; // when the final submission finishes on the GPU
};

// Multi-swapchain is supported only by VK
NRI_STRUCT(LowLatencyInterface)
{
NRI_NAME(Result) (NRI_CALL *SetLatencySleepMode)(NRI_NAME_REF(SwapChain) swapChain, const NRI_NAME_REF(LatencySleepMode) latencySleepMode);
NRI_NAME(Result) (NRI_CALL *SetLatencyMarker)(NRI_NAME_REF(SwapChain) swapChain, NRI_NAME(LatencyMarker) latencyMarker);
NRI_NAME(Result) (NRI_CALL *LatencySleep)(NRI_NAME_REF(SwapChain) swapChain); // call once before INPUT_SAMPLE
NRI_NAME(Result) (NRI_CALL *GetLatencyReport)(const NRI_NAME_REF(SwapChain) swapChain, NRI_NAME_REF(LatencyReport) latencyReport);

// This function must be used in "low latency" mode instead of "QueueSubmit"
void (NRI_CALL *QueueSubmitTrackable)(NRI_NAME_REF(CommandQueue) commandQueue, const NRI_NAME_REF(QueueSubmitDesc) queueSubmitDesc, const NRI_NAME_REF(SwapChain) swapChain);
};

NRI_NAMESPACE_END
67 changes: 67 additions & 0 deletions Include/Extensions/NRIStreamer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// © 2024 NVIDIA Corporation

#pragma once

NRI_NAMESPACE_BEGIN

NRI_FORWARD_STRUCT(Streamer);

NRI_STRUCT(StreamerDesc)
{
// Statically allocated ring-buffer for dynamic constants (optional)
NRI_NAME(MemoryLocation) constantBufferMemoryLocation; // UPLOAD or DEVICE_UPLOAD
uint64_t constantBufferSize;

// Dynamically (re)allocated ring-buffer for copying and rendering (mandatory)
NRI_NAME(MemoryLocation) dynamicBufferMemoryLocation; // UPLOAD or DEVICE_UPLOAD
NRI_NAME(BufferUsageBits) dynamicBufferUsageBits;
uint32_t frameInFlightNum;
};

NRI_STRUCT(BufferUpdateRequestDesc)
{
// Data to upload
const void* data; // pointer must be valid until "CopyStreamerUpdateRequests" call
uint64_t dataSize;

// Destination (optional, ignored for constants)
NRI_NAME(Buffer)* dstBuffer;
uint64_t dstBufferOffset;
};

NRI_STRUCT(TextureUpdateRequestDesc)
{
// Data to upload
const void* data; // pointer must be valid until "CopyStreamerUpdateRequests" call
uint32_t dataRowPitch;
uint32_t dataSlicePitch;

// Destination (mandatory)
NRI_NAME(Texture)* dstTexture;
NRI_NAME(TextureRegionDesc) dstRegionDesc;
};

NRI_STRUCT(StreamerInterface)
{
NRI_NAME(Result) (NRI_CALL *CreateStreamer)(NRI_NAME_REF(Device) device, const NRI_NAME_REF(StreamerDesc) streamerDesc, NRI_NAME_REF(Streamer*) streamer);
void (NRI_CALL *DestroyStreamer)(NRI_NAME_REF(Streamer) streamer);

// Get internal buffers
NRI_NAME(Buffer*) (NRI_CALL *GetStreamerConstantBuffer)(NRI_NAME_REF(Streamer) streamer); // Never changes
NRI_NAME(Buffer*) (NRI_CALL *GetStreamerDynamicBuffer)(NRI_NAME_REF(Streamer) streamer); // Valid only after "CopyStreamerUpdateRequests"

// Add an update request. Return the offset in the ring buffer and don't invoke any work
uint64_t (NRI_CALL *AddStreamerBufferUpdateRequest)(NRI_NAME_REF(Streamer) streamer, const NRI_NAME_REF(BufferUpdateRequestDesc) bufferUpdateRequestDesc);
uint64_t (NRI_CALL *AddStreamerTextureUpdateRequest)(NRI_NAME_REF(Streamer) streamer, const NRI_NAME_REF(TextureUpdateRequestDesc) textureUpdateRequestDesc);

// (HOST) Copy data and get the offset in the dedicated ring buffer (for dynamic constant buffers)
uint32_t (NRI_CALL *UpdateStreamerConstantBuffer)(NRI_NAME_REF(Streamer) streamer, const void* data, uint32_t dataSize);

// (HOST) Copy gathered requests to the internal buffer, potentially a new one if the capacity exceeded. Must be called once per frame
NRI_NAME(Result) (NRI_CALL *CopyStreamerUpdateRequests)(NRI_NAME_REF(Streamer) streamer);

// (DEVICE) Copy data to destinations (if any), barriers are externally controlled. Must be called after "CopyStreamerUpdateRequests"
void (NRI_CALL *CmdUploadStreamerUpdateRequests)(NRI_NAME_REF(CommandBuffer) commandBuffer, NRI_NAME_REF(Streamer) streamer);
};

NRI_NAMESPACE_END
36 changes: 22 additions & 14 deletions Include/Extensions/NRISwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ NRI_NAMESPACE_BEGIN

NRI_FORWARD_STRUCT(SwapChain);

static const uint32_t NRI_CONST_NAME(OUT_OF_DATE) = (uint32_t)(-1); // VK only: swap chain is out of date

// Color space:
// - BT.709 - LDR https://en.wikipedia.org/wiki/Rec._709
// - BT.2020 - HDR https://en.wikipedia.org/wiki/Rec._2020
Expand Down Expand Up @@ -58,7 +60,9 @@ NRI_UNION(Window)
NRI_NAME(WaylandWindow) wayland;
};

// SwapChain buffers will be created as "color attachment" resources
// SwapChain textures will be created as "color attachment" resources
// queuedFrameNum = 0 - auto-selection between 1 (for waitable) or 2 (otherwise)
// queuedFrameNum = 2 - recommended if the GPU frame time is less than the desired frame time, but the sum of 2 frames is greater
NRI_STRUCT(SwapChainDesc)
{
NRI_NAME(Window) window;
Expand All @@ -67,32 +71,35 @@ NRI_STRUCT(SwapChainDesc)
NRI_NAME(Dim_t) height;
uint8_t textureNum;
NRI_NAME(SwapChainFormat) format;
uint8_t verticalSyncInterval;
uint8_t verticalSyncInterval; // 0 - vsync off
uint8_t queuedFrameNum; // aka "max frame latency", aka "number of frames in flight" (mostly for D3D11)
bool waitable; // allows to use "WaitForPresent", which helps to reduce latency
bool allowLowLatency; // unlocks "NRILowLatency" functionality (requires "isLowLatencySupported")
};

NRI_STRUCT(ChromaticityCoords)
{
float x, y; // [0; 1]
};

// Describes color settings and capabilities of the closest display
// nit = cd/m2
// SDR = standard dynamic range
// LDR = low dynamic range (in many cases LDR == SDR)
// HDR = high dynamic range, assumes G2084:
// Describes color settings and capabilities of the closest display:
// - Luminance provided in nits (cd/m2)
// - SDR = standard dynamic range
// - LDR = low dynamic range (in many cases LDR == SDR)
// - HDR = high dynamic range, assumes G2084:
// - BT709_G10_16BIT: HDR gets enabled and applied implicitly if Windows HDR is enabled
// - BT2020_G2084_10BIT: HDR requires explicit color conversions and enabled HDR in Windows
// "SDR scale in HDR mode" = sdrLuminance / 80
// - "SDR scale in HDR mode" = sdrLuminance / 80
NRI_STRUCT(DisplayDesc)
{
NRI_NAME(ChromaticityCoords) redPrimary;
NRI_NAME(ChromaticityCoords) greenPrimary;
NRI_NAME(ChromaticityCoords) bluePrimary;
NRI_NAME(ChromaticityCoords) whitePoint;
float minLuminance; // nits
float maxLuminance; // nits
float maxFullFrameLuminance; // nits
float sdrLuminance; // nits
float minLuminance;
float maxLuminance;
float maxFullFrameLuminance;
float sdrLuminance;
bool isHDR;
};

Expand All @@ -102,8 +109,9 @@ NRI_STRUCT(SwapChainInterface)
void (NRI_CALL *DestroySwapChain)(NRI_NAME_REF(SwapChain) swapChain);
void (NRI_CALL *SetSwapChainDebugName)(NRI_NAME_REF(SwapChain) swapChain, const char* name);
NRI_NAME(Texture)* const* (NRI_CALL *GetSwapChainTextures)(const NRI_NAME_REF(SwapChain) swapChain, uint32_t NRI_REF textureNum);
uint32_t (NRI_CALL *AcquireNextSwapChainTexture)(NRI_NAME_REF(SwapChain) swapChain); // IMPORTANT: return OUT_OF_DATE index to indicate "out of date" swap chain status (VK only)
NRI_NAME(Result) (NRI_CALL *SwapChainPresent)(NRI_NAME_REF(SwapChain) swapChain);
uint32_t (NRI_CALL *AcquireNextSwapChainTexture)(NRI_NAME_REF(SwapChain) swapChain); // can return OUT_OF_DATE (VK only)
NRI_NAME(Result) (NRI_CALL *WaitForPresent)(NRI_NAME_REF(SwapChain) swapChain); // call once right before input sampling (must be called starting from the 1st frame)
NRI_NAME(Result) (NRI_CALL *QueuePresent)(NRI_NAME_REF(SwapChain) swapChain);
NRI_NAME(Result) (NRI_CALL *GetDisplayDesc)(NRI_NAME_REF(SwapChain) swapChain, NRI_NAME_REF(DisplayDesc) displayDesc); // returns FAILURE if window is outside of all monitors
};

Expand Down
Loading

0 comments on commit 919412b

Please sign in to comment.