Skip to content

Commit

Permalink
Cleaned up Vulkan VK_NV_low_latency2 code 11/05/2024 | 24w45a2
Browse files Browse the repository at this point in the history
  • Loading branch information
GamesTrap committed Nov 5, 2024
1 parent 5f27dcc commit 1573373
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 44 deletions.
4 changes: 4 additions & 0 deletions SITREPS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5360,3 +5360,7 @@ SITREP 11/03/2024|24w44c1
SITREP 11/04/2024|24w45a1
- Changed TRAP Engine version to 24w45a1(0.11.36)
- Migrated NVIDIA Reflex code to use Vulkan VK_NV_low_latency2 extension ~>60 mins

SITREP 11/05/2024|24w45a2
- Changed TRAP Engine version to 24w45a2(0.11.37)
- Cleaned up Vulkan VK_NV_low_latency2 code ~<10 mins
2 changes: 1 addition & 1 deletion TRAP/src/Core/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
//-------------------------------------------------------------------------------------------------------------------//

/// @brief TRAP version number created with TRAP_MAKE_VERSION
inline constexpr TRAP::SemanticVersion<0, 11, 36> TRAP_VERSION{};
inline constexpr TRAP::SemanticVersion<0, 11, 37> TRAP_VERSION{};

//-------------------------------------------------------------------------------------------------------------------//

Expand Down
104 changes: 87 additions & 17 deletions TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,6 @@ namespace TRAP::Graphics::API::VulkanInits

//-------------------------------------------------------------------------------------------------------------------//

/// @brief Create a Vulkan latency submission present ID.
/// @param presentID Present ID to set for the submission.
/// @return VkLatencySubmissionPresentIdNV
[[nodiscard]] constexpr VkLatencySubmissionPresentIdNV LatencySubmissionPresentID(u64 presentID) noexcept;

/// @brief Create a Vulkan submit info.
/// @param waitSemaphores Vulkan semaphore(s) to wait on.
/// @param waitMasks Vulkan pipeline stage(s) to wait on.
Expand Down Expand Up @@ -607,6 +602,38 @@ namespace TRAP::Graphics::API::VulkanInits
//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] constexpr VkClearColorValue ClearColorValue(const RendererAPI::Color& color, ImageFormat format);

//-------------------------------------------------------------------------------------------------------------------//

/// @brief Create a Vulkan latency submission present ID.
/// @param presentID Present ID to set for the submission.
/// This is used to associate the vkQueueSubmit with the presentID used for a given
/// vkQueuePresentKHR via VkPresentIdKHR::pPresentIds.
/// @return VkLatencySubmissionPresentIdNV.
[[nodiscard]] constexpr VkLatencySubmissionPresentIdNV LatencySubmissionPresentID(u64 presentID) noexcept;

/// @brief Create a Vulkan set latency marker info.
/// @param presentID Present ID for the presentation.
/// presentID is an application provided value that is used to assocaite the timestamp with a
/// vkQueuePresentKHR command using VkPresentIdKHR::pPresentIds for a given present.
/// @param marker Marker/Timestamp to record.
/// @return VkSetLatencyMarkerInfoNV.
[[nodiscard]] constexpr VkSetLatencyMarkerInfoNV SetLatencyMarkerInfo(u64 presentID,
RendererAPI::NVIDIAReflexLatencyMarker marker) noexcept;

/// @brief Create a Vulkan latency sleep mode info.
/// @param latencyMode Latency mode to use.
/// @param fpsLimit Optional: FPS limiter. Set 0 to disable limiter.
/// @win32 FPS limiting of the engine will be done with this extension, instead of TRAP::Application, if the VK_NV_low_latency2 is supported by the used GPU.
/// @return VkLatencySleepModeInfoNV.
[[nodiscard]] constexpr VkLatencySleepModeInfoNV LatencySleepModeInfo(RendererAPI::NVIDIAReflexLatencyMode latencyMode, u32 fpsLimit = 0u) noexcept;

/// @brief Create a Vulkan latency sleep info.
/// @param semaphore A semaphore that gets signaled to indicate that the application *should* resume input sampling work.
/// Note: semaphore *must* be a timeline semaphore.
/// @param signalValue The value that semaphore is set to for resuming sampling work.
/// @return VkLatencySleepInfoNV.
[[nodiscard]] constexpr VkLatencySleepInfoNV LatencySleepInfo(VkSemaphore semaphore, u64 signalValue) noexcept;
}

//-------------------------------------------------------------------------------------------------------------------//
Expand Down Expand Up @@ -1049,18 +1076,6 @@ namespace TRAP::Graphics::API::VulkanInits

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] constexpr VkLatencySubmissionPresentIdNV TRAP::Graphics::API::VulkanInits::LatencySubmissionPresentID(const u64 presentID) noexcept
{
return VkLatencySubmissionPresentIdNV
{
.sType = VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV,
.pNext = nullptr,
.presentID = presentID
};
}

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] constexpr VkSubmitInfo TRAP::Graphics::API::VulkanInits::SubmitInfo(const std::span<const VkSemaphore> waitSemaphores,
const std::span<const VkPipelineStageFlags> waitMasks,
const std::span<const VkCommandBuffer> cmds,
Expand Down Expand Up @@ -1201,6 +1216,61 @@ namespace TRAP::Graphics::API::VulkanInits

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] constexpr VkLatencySubmissionPresentIdNV TRAP::Graphics::API::VulkanInits::LatencySubmissionPresentID(const u64 presentID) noexcept
{
return VkLatencySubmissionPresentIdNV
{
.sType = VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV,
.pNext = nullptr,
.presentID = presentID
};
}

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] constexpr VkSetLatencyMarkerInfoNV TRAP::Graphics::API::VulkanInits::SetLatencyMarkerInfo(const u64 presentID,
const RendererAPI::NVIDIAReflexLatencyMarker marker) noexcept
{
return VkSetLatencyMarkerInfoNV
{
.sType = VK_STRUCTURE_TYPE_SET_LATENCY_MARKER_INFO_NV,
.pNext = nullptr,
.presentID = presentID,
.marker = static_cast<VkLatencyMarkerNV>(marker)
};
}

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] constexpr VkLatencySleepModeInfoNV TRAP::Graphics::API::VulkanInits::LatencySleepModeInfo(const RendererAPI::NVIDIAReflexLatencyMode latencyMode,

Check failure on line 1245 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

no return statement in constexpr function

Check failure on line 1245 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

no return statement in constexpr function

Check failure on line 1245 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

no return statement in constexpr function
const u32 fpsLimit) noexcept
{
return VkLatencySleepModeInfoNV
{
.sType = VK_STRUCTURE_TYPE_LATENCY_SLEEP_MODE_INFO_NV,
.pNext = nullptr,
.lowLatencyMode = static_cast<VkBool32>(latencyMode != RendererAPI::NVIDIAReflexLatencyMode::Disabled),

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

incomplete type 'TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode' named in nested name specifier

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

incomplete type 'TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode' named in nested name specifier

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

incomplete type 'TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode' named in nested name specifier

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

incomplete type 'TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode' named in nested name specifier

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘Disabled’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘Disabled’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘Disabled’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘Disabled’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’

Check failure on line 1252 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘Disabled’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’
.lowLatencyBoost = static_cast<VkBool32>(latencyMode == RendererAPI::NVIDIAReflexLatencyMode::EnabledBoost),

Check failure on line 1253 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

incomplete type 'TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode' named in nested name specifier

Check failure on line 1253 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

incomplete type 'TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode' named in nested name specifier

Check failure on line 1253 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux Clang 19

incomplete type 'TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode' named in nested name specifier

Check failure on line 1253 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘EnabledBoost’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’

Check failure on line 1253 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘EnabledBoost’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’

Check failure on line 1253 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘EnabledBoost’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’

Check failure on line 1253 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘EnabledBoost’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’

Check failure on line 1253 in TRAP/src/Graphics/API/Vulkan/Objects/VulkanInits.h

View workflow job for this annotation

GitHub Actions / Build Linux GCC 14

‘EnabledBoost’ is not a member of ‘TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode’
.minimumIntervalUs = (fpsLimit == 0u) ? fpsLimit : NumericCast<u32>(((1000.0f / NumericCast<f32>(fpsLimit)) * 1000.0f)) //Convert fpsLimit to microseconds if not 0.
};
}

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] constexpr VkLatencySleepInfoNV TRAP::Graphics::API::VulkanInits::LatencySleepInfo(VkSemaphore semaphore,
const u64 signalValue) noexcept
{
return VkLatencySleepInfoNV
{
.sType = VK_STRUCTURE_TYPE_LATENCY_SLEEP_INFO_NV,
.pNext = nullptr,
.signalSemaphore = semaphore,
.value = signalValue
};
}

//-------------------------------------------------------------------------------------------------------------------//

[[nodiscard]] constexpr VkPipelineVertexInputStateCreateInfo TRAP::Graphics::API::VulkanInits::PipelineVertexInputStateCreateInfo(const std::span<const VkVertexInputBindingDescription> inputBindings,
const std::span<const VkVertexInputAttributeDescription> inputAttributes) noexcept
{
Expand Down
28 changes: 3 additions & 25 deletions TRAP/src/Graphics/API/Vulkan/Objects/VulkanSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,7 @@ void TRAP::Graphics::API::VulkanSwapChain::ReflexSetMarker(const TRAP::Graphics:
if(!RendererAPI::GPUSettings.ReflexSupported)
return;

const VkSetLatencyMarkerInfoNV markerInfoNV
{
.sType = VK_STRUCTURE_TYPE_SET_LATENCY_MARKER_INFO_NV,
.pNext = nullptr,
.presentID = m_presentCounter,
.marker = static_cast<VkLatencyMarkerNV>(marker)
};
const VkSetLatencyMarkerInfoNV markerInfoNV = VulkanInits::SetLatencyMarkerInfo(m_presentCounter, marker);
vkSetLatencyMarkerNV(m_device->GetVkDevice(), m_swapChain, &markerInfoNV);

if(marker == TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMarker::SimulationEnd)
Expand All @@ -660,17 +654,7 @@ void TRAP::Graphics::API::VulkanSwapChain::ReflexSetMarker(const TRAP::Graphics:
void TRAP::Graphics::API::VulkanSwapChain::ReflexSetLatencyMode(const TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode latencyMode,
u32 fpsLimit) const
{
if(fpsLimit != 0u)
fpsLimit = NumericCast<u32>(((1000.0f / NumericCast<f32>(fpsLimit)) * 1000.0f));

const VkLatencySleepModeInfoNV latencySleepModeInfoNV
{
.sType = VK_STRUCTURE_TYPE_LATENCY_SLEEP_MODE_INFO_NV,
.pNext = nullptr,
.lowLatencyMode = static_cast<VkBool32>(latencyMode != TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode::Disabled),
.lowLatencyBoost = static_cast<VkBool32>(latencyMode == TRAP::Graphics::RendererAPI::NVIDIAReflexLatencyMode::EnabledBoost),
.minimumIntervalUs = fpsLimit
};
const VkLatencySleepModeInfoNV latencySleepModeInfoNV = TRAP::Graphics::API::VulkanInits::LatencySleepModeInfo(latencyMode, fpsLimit);
VkCall(vkSetLatencySleepModeNV(m_device->GetVkDevice(), m_swapChain, &latencySleepModeInfoNV));
}

Expand All @@ -684,13 +668,7 @@ void TRAP::Graphics::API::VulkanSwapChain::ReflexSleep(const Semaphore& reflexSe
VkCall(vkGetSemaphoreCounterValueKHR(m_device->GetVkDevice(), vkReflexSemaphore->GetVkSemaphore(), &signalValue));
++signalValue;

const VkLatencySleepInfoNV latencySleepInfoNV
{
.sType = VK_STRUCTURE_TYPE_LATENCY_SLEEP_INFO_NV,
.pNext = nullptr,
.signalSemaphore = vkReflexSemaphore->GetVkSemaphore(),
.value = signalValue
};
const VkLatencySleepInfoNV latencySleepInfoNV = VulkanInits::LatencySleepInfo(vkReflexSemaphore->GetVkSemaphore(), signalValue);
VkCall(vkLatencySleepNV(m_device->GetVkDevice(), m_swapChain, &latencySleepInfoNV));

const VkSemaphoreWaitInfoKHR waitInfo = VulkanInits::SemaphoreWaitInfo(vkReflexSemaphore->GetVkSemaphore(), signalValue);
Expand Down
2 changes: 1 addition & 1 deletion TRAP/src/Log/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace TRAP
/// @threadsafe
void Clear() noexcept;

static constexpr auto WindowVersion = "[24w45a1]";
static constexpr auto WindowVersion = "[24w45a2]";
static constexpr auto WindowPrefix = "[Window] ";
static constexpr auto WindowIconPrefix = "[Window][Icon] ";
static constexpr auto ConfigPrefix = "[Config] ";
Expand Down

0 comments on commit 1573373

Please sign in to comment.