Add v210 staging memory probe

This commit is contained in:
Johanness
2026-05-19 20:41:02 +03:00
parent b096f32d75
commit e4724395f0
5 changed files with 124 additions and 2 deletions
+86
View File
@@ -15,6 +15,9 @@
std::optional<PresentModeConfig> parsePresentMode( std::optional<PresentModeConfig> parsePresentMode(
std::string_view text); std::string_view text);
std::optional<V210StagingMemoryMode> parseV210StagingMemoryMode(
std::string_view text);
namespace namespace
{ {
struct JsonValue struct JsonValue
@@ -588,6 +591,20 @@ bool applyConfigFile(
config.presentMode = mode.value(); config.presentMode = mode.value();
} }
if (const std::string* memoryMode =
jsonString(objectField(*root, "v210StagingMemory")))
{
const std::optional<V210StagingMemoryMode> 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 = const JsonValue::Array* feeds =
jsonArray(objectField(*root, "feeds")); jsonArray(objectField(*root, "feeds"));
if (feeds == nullptr) if (feeds == nullptr)
@@ -721,6 +738,27 @@ std::optional<PresentModeConfig> parsePresentMode(std::string_view text)
return std::nullopt; return std::nullopt;
} }
std::optional<V210StagingMemoryMode> 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) std::string_view feedKindName(FeedKind kind)
{ {
switch (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) void printUsage(const char* executableName)
{ {
std::cout std::cout
@@ -758,6 +813,7 @@ void printUsage(const char* executableName)
<< " --grid <cols>x<rows> Set multiview grid (default 2x2, max 16 feeds)\n" << " --grid <cols>x<rows> Set multiview grid (default 2x2, max 16 feeds)\n"
<< " --fps-cap <fps> Limit render loop FPS (default 60)\n" << " --fps-cap <fps> Limit render loop FPS (default 60)\n"
<< " --max-v210-uploads <n> Limit v210 uploads per frame (0 = unlimited)\n" << " --max-v210-uploads <n> Limit v210 uploads per frame (0 = unlimited)\n"
<< " --v210-staging-memory <mode> Memory: default, cached, device-local\n"
<< " --present <mode> Present mode: fifo, mailbox, immediate (default mailbox)\n" << " --present <mode> Present mode: fifo, mailbox, immediate (default mailbox)\n"
<< " --feed <idx> <kind> Set feed slot kind explicitly\n" << " --feed <idx> <kind> Set feed slot kind explicitly\n"
<< " --domain <idx> <path> Set MXL domain for feed slot\n" << " --domain <idx> <path> Set MXL domain for feed slot\n"
@@ -899,6 +955,36 @@ ConfigParseResult parseAppConfig(
continue; continue;
} }
if (arg == "--v210-staging-memory")
{
if (i + 1 >= argc)
{
std::cerr << "--v210-staging-memory requires <mode>"
<< std::endl;
result.shouldExit = true;
result.exitCode = 1;
return result;
}
const std::optional<V210StagingMemoryMode> 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") if (arg == "--grid")
{ {
++i; ++i;
+11
View File
@@ -30,6 +30,13 @@ enum class PresentModeConfig
Immediate Immediate
}; };
enum class V210StagingMemoryMode
{
Default,
Cached,
DeviceLocal
};
struct FeedConfig struct FeedConfig
{ {
FeedKind kind = FeedKind::NoSignal; FeedKind kind = FeedKind::NoSignal;
@@ -48,11 +55,15 @@ struct AppConfig
uint32_t gridCols = DefaultGridCols; uint32_t gridCols = DefaultGridCols;
uint32_t gridRows = DefaultGridRows; uint32_t gridRows = DefaultGridRows;
PresentModeConfig presentMode = PresentModeConfig::Mailbox; PresentModeConfig presentMode = PresentModeConfig::Mailbox;
V210StagingMemoryMode v210StagingMemoryMode =
V210StagingMemoryMode::Default;
std::vector<FeedConfig> feeds; std::vector<FeedConfig> feeds;
}; };
std::optional<FeedKind> parseFeedKind(std::string_view text); std::optional<FeedKind> parseFeedKind(std::string_view text);
std::string_view feedKindName(FeedKind kind); std::string_view feedKindName(FeedKind kind);
std::string_view v210StagingMemoryModeName(
V210StagingMemoryMode mode);
void printUsage(const char* executableName); void printUsage(const char* executableName);
+22 -2
View File
@@ -216,6 +216,7 @@ void V210ComputeDecoder::createFeedResources(
uint32_t srcStride, uint32_t srcStride,
uint32_t dstWidth, uint32_t dstWidth,
uint32_t dstHeight, uint32_t dstHeight,
V210StagingMemoryMode stagingMemoryMode,
V210ComputeFeed& feed) V210ComputeFeed& feed)
{ {
feed.srcWidth = srcWidth; feed.srcWidth = srcWidth;
@@ -224,15 +225,27 @@ void V210ComputeDecoder::createFeedResources(
VkDeviceSize v210Size = static_cast<VkDeviceSize>(srcStride) * srcHeight; VkDeviceSize v210Size = static_cast<VkDeviceSize>(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, m_device,
physicalDevice, physicalDevice,
v210Size, v210Size,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
preferredProperties,
feed.v210Buffer, feed.v210Buffer,
feed.v210BufferMemory); feed.v210BufferMemory,
feed.v210MemoryProperties);
if (vkMapMemory( if (vkMapMemory(
m_device, m_device,
@@ -246,6 +259,13 @@ void V210ComputeDecoder::createFeedResources(
"Failed to map v210 buffer memory"); "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( createImage(
m_device, m_device,
physicalDevice, physicalDevice,
+4
View File
@@ -1,5 +1,7 @@
#pragma once #pragma once
#include "AppConfig.hpp"
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <cstdint> #include <cstdint>
@@ -10,6 +12,7 @@ struct V210ComputeFeed
VkBuffer v210Buffer = VK_NULL_HANDLE; VkBuffer v210Buffer = VK_NULL_HANDLE;
VkDeviceMemory v210BufferMemory = VK_NULL_HANDLE; VkDeviceMemory v210BufferMemory = VK_NULL_HANDLE;
void* v210MappedData = nullptr; void* v210MappedData = nullptr;
VkMemoryPropertyFlags v210MemoryProperties = 0;
VkImage image = VK_NULL_HANDLE; VkImage image = VK_NULL_HANDLE;
VkDeviceMemory imageMemory = VK_NULL_HANDLE; VkDeviceMemory imageMemory = VK_NULL_HANDLE;
@@ -44,6 +47,7 @@ public:
uint32_t srcStride, uint32_t srcStride,
uint32_t dstWidth, uint32_t dstWidth,
uint32_t dstHeight, uint32_t dstHeight,
V210StagingMemoryMode stagingMemoryMode,
V210ComputeFeed& feed); V210ComputeFeed& feed);
void destroyFeedResources(V210ComputeFeed& feed); void destroyFeedResources(V210ComputeFeed& feed);
+1
View File
@@ -1587,6 +1587,7 @@ int main(int argc, char* argv[])
feeds[i]->v210Stride(), feeds[i]->v210Stride(),
TEXTURE_WIDTH, TEXTURE_WIDTH,
TEXTURE_HEIGHT, TEXTURE_HEIGHT,
config.v210StagingMemoryMode,
v210Feeds[i] v210Feeds[i]
); );