From e4724395f0ddb72c9d99736933edf66956a9e045 Mon Sep 17 00:00:00 2001 From: Johanness Date: Tue, 19 May 2026 20:41:02 +0300 Subject: [PATCH] Add v210 staging memory probe --- AppConfig.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++ AppConfig.hpp | 11 ++++++ V210ComputeDecoder.cpp | 24 +++++++++++- V210ComputeDecoder.hpp | 4 ++ main.cpp | 1 + 5 files changed, 124 insertions(+), 2 deletions(-) diff --git a/AppConfig.cpp b/AppConfig.cpp index ef61f26..634d11b 100644 --- a/AppConfig.cpp +++ b/AppConfig.cpp @@ -15,6 +15,9 @@ std::optional parsePresentMode( std::string_view text); +std::optional parseV210StagingMemoryMode( + std::string_view text); + namespace { struct JsonValue @@ -588,6 +591,20 @@ bool applyConfigFile( config.presentMode = mode.value(); } + if (const std::string* memoryMode = + jsonString(objectField(*root, "v210StagingMemory"))) + { + const std::optional mode = + parseV210StagingMemoryMode(*memoryMode); + if (!mode.has_value()) + { + error = "v210StagingMemory must be default, cached, " + "or device-local"; + return false; + } + config.v210StagingMemoryMode = mode.value(); + } + const JsonValue::Array* feeds = jsonArray(objectField(*root, "feeds")); if (feeds == nullptr) @@ -721,6 +738,27 @@ std::optional parsePresentMode(std::string_view text) return std::nullopt; } +std::optional parseV210StagingMemoryMode( + std::string_view text) +{ + if (text == "default") + { + return V210StagingMemoryMode::Default; + } + + if (text == "cached") + { + return V210StagingMemoryMode::Cached; + } + + if (text == "device-local" || text == "device_local") + { + return V210StagingMemoryMode::DeviceLocal; + } + + return std::nullopt; +} + std::string_view feedKindName(FeedKind kind) { switch (kind) @@ -743,6 +781,23 @@ std::string_view feedKindName(FeedKind kind) } } +std::string_view v210StagingMemoryModeName( + V210StagingMemoryMode mode) +{ + switch (mode) + { + case V210StagingMemoryMode::Cached: + return "cached"; + + case V210StagingMemoryMode::DeviceLocal: + return "device-local"; + + case V210StagingMemoryMode::Default: + default: + return "default"; + } +} + void printUsage(const char* executableName) { std::cout @@ -758,6 +813,7 @@ void printUsage(const char* executableName) << " --grid x Set multiview grid (default 2x2, max 16 feeds)\n" << " --fps-cap Limit render loop FPS (default 60)\n" << " --max-v210-uploads Limit v210 uploads per frame (0 = unlimited)\n" + << " --v210-staging-memory Memory: default, cached, device-local\n" << " --present Present mode: fifo, mailbox, immediate (default mailbox)\n" << " --feed Set feed slot kind explicitly\n" << " --domain Set MXL domain for feed slot\n" @@ -899,6 +955,36 @@ ConfigParseResult parseAppConfig( continue; } + if (arg == "--v210-staging-memory") + { + if (i + 1 >= argc) + { + std::cerr << "--v210-staging-memory requires " + << std::endl; + result.shouldExit = true; + result.exitCode = 1; + return result; + } + + const std::optional mode = + parseV210StagingMemoryMode(argv[i + 1]); + + if (!mode.has_value()) + { + std::cerr + << "--v210-staging-memory must be default, cached, " + << "or device-local" + << std::endl; + result.shouldExit = true; + result.exitCode = 1; + return result; + } + + result.config.v210StagingMemoryMode = mode.value(); + ++i; + continue; + } + if (arg == "--grid") { ++i; diff --git a/AppConfig.hpp b/AppConfig.hpp index 05fc600..d8c6018 100644 --- a/AppConfig.hpp +++ b/AppConfig.hpp @@ -30,6 +30,13 @@ enum class PresentModeConfig Immediate }; +enum class V210StagingMemoryMode +{ + Default, + Cached, + DeviceLocal +}; + struct FeedConfig { FeedKind kind = FeedKind::NoSignal; @@ -48,11 +55,15 @@ struct AppConfig uint32_t gridCols = DefaultGridCols; uint32_t gridRows = DefaultGridRows; PresentModeConfig presentMode = PresentModeConfig::Mailbox; + V210StagingMemoryMode v210StagingMemoryMode = + V210StagingMemoryMode::Default; std::vector feeds; }; std::optional parseFeedKind(std::string_view text); std::string_view feedKindName(FeedKind kind); +std::string_view v210StagingMemoryModeName( + V210StagingMemoryMode mode); void printUsage(const char* executableName); diff --git a/V210ComputeDecoder.cpp b/V210ComputeDecoder.cpp index 4a0b73b..864ec27 100644 --- a/V210ComputeDecoder.cpp +++ b/V210ComputeDecoder.cpp @@ -216,6 +216,7 @@ void V210ComputeDecoder::createFeedResources( uint32_t srcStride, uint32_t dstWidth, uint32_t dstHeight, + V210StagingMemoryMode stagingMemoryMode, V210ComputeFeed& feed) { feed.srcWidth = srcWidth; @@ -224,15 +225,27 @@ void V210ComputeDecoder::createFeedResources( VkDeviceSize v210Size = static_cast(srcStride) * srcHeight; - createBuffer( + VkMemoryPropertyFlags preferredProperties = 0; + if (stagingMemoryMode == V210StagingMemoryMode::Cached) + { + preferredProperties = VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + } + else if (stagingMemoryMode == V210StagingMemoryMode::DeviceLocal) + { + preferredProperties = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + } + + createBufferWithPreferredMemory( m_device, physicalDevice, v210Size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + preferredProperties, feed.v210Buffer, - feed.v210BufferMemory); + feed.v210BufferMemory, + feed.v210MemoryProperties); if (vkMapMemory( m_device, @@ -246,6 +259,13 @@ void V210ComputeDecoder::createFeedResources( "Failed to map v210 buffer memory"); } + std::cout + << "Feed " << (feedIndex + 1) + << ": v210 staging memory mode=" + << v210StagingMemoryModeName(stagingMemoryMode) + << " flags=0x" << std::hex << feed.v210MemoryProperties + << std::dec << std::endl; + createImage( m_device, physicalDevice, diff --git a/V210ComputeDecoder.hpp b/V210ComputeDecoder.hpp index 5fcad91..f9946c5 100644 --- a/V210ComputeDecoder.hpp +++ b/V210ComputeDecoder.hpp @@ -1,5 +1,7 @@ #pragma once +#include "AppConfig.hpp" + #include #include @@ -10,6 +12,7 @@ struct V210ComputeFeed VkBuffer v210Buffer = VK_NULL_HANDLE; VkDeviceMemory v210BufferMemory = VK_NULL_HANDLE; void* v210MappedData = nullptr; + VkMemoryPropertyFlags v210MemoryProperties = 0; VkImage image = VK_NULL_HANDLE; VkDeviceMemory imageMemory = VK_NULL_HANDLE; @@ -44,6 +47,7 @@ public: uint32_t srcStride, uint32_t dstWidth, uint32_t dstHeight, + V210StagingMemoryMode stagingMemoryMode, V210ComputeFeed& feed); void destroyFeedResources(V210ComputeFeed& feed); diff --git a/main.cpp b/main.cpp index 09bf958..ebe2155 100644 --- a/main.cpp +++ b/main.cpp @@ -1587,6 +1587,7 @@ int main(int argc, char* argv[]) feeds[i]->v210Stride(), TEXTURE_WIDTH, TEXTURE_HEIGHT, + config.v210StagingMemoryMode, v210Feeds[i] );