From 8ef858e3c8d137c68bd86e29a89bbf6dfbf1a947 Mon Sep 17 00:00:00 2001 From: Johanness Date: Thu, 21 May 2026 11:35:46 +0300 Subject: [PATCH] Add adaptive feed texture probe --- AppConfig.cpp | 11 +++++++ AppConfig.hpp | 1 + main.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 82 insertions(+), 11 deletions(-) diff --git a/AppConfig.cpp b/AppConfig.cpp index e37127b..1779269 100644 --- a/AppConfig.cpp +++ b/AppConfig.cpp @@ -581,6 +581,10 @@ bool applyConfigFile( { config.v210UploadWorker = boolValue; } + if (jsonBool(objectField(*root, "adaptiveFeedTexture"), boolValue)) + { + config.adaptiveFeedTexture = boolValue; + } if (const std::string* present = jsonString(objectField(*root, "present"))) @@ -814,6 +818,7 @@ void printUsage(const char* executableName) << " --verbose Enable detailed startup and SDK logs\n" << " --pace-uploads Pace v210 uploads by feed frame rate\n" << " --v210-upload-worker Copy direct v210 payloads on a worker thread\n" + << " --adaptive-feed-texture Size feed textures to grid tile size\n" << " --config Load JSON feed configuration\n" << " --grid x Set multiview grid (default 2x2, max 16 feeds)\n" << " --fps-cap Limit render loop FPS (default 60)\n" @@ -966,6 +971,12 @@ ConfigParseResult parseAppConfig( continue; } + if (arg == "--adaptive-feed-texture") + { + result.config.adaptiveFeedTexture = true; + continue; + } + if (arg == "--v210-staging-memory") { if (i + 1 >= argc) diff --git a/AppConfig.hpp b/AppConfig.hpp index bf24cdf..27788ef 100644 --- a/AppConfig.hpp +++ b/AppConfig.hpp @@ -51,6 +51,7 @@ struct AppConfig bool verbose = false; bool paceUploads = false; bool v210UploadWorker = false; + bool adaptiveFeedTexture = false; uint32_t fpsCap = 60; uint32_t maxV210UploadsPerFrame = 0; uint32_t gridCols = DefaultGridCols; diff --git a/main.cpp b/main.cpp index dea4e5b..c83817e 100644 --- a/main.cpp +++ b/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,50 @@ constexpr float TILE_ASPECT = 16.0f / 9.0f; static std::atomic g_running{true}; +struct FeedTextureSize +{ + uint32_t width = TEXTURE_WIDTH; + uint32_t height = TEXTURE_HEIGHT; +}; + +FeedTextureSize chooseFeedTextureSize( + const AppConfig& config, + int windowWidth, + int windowHeight) +{ + if (!config.adaptiveFeedTexture) + { + return {}; + } + + const std::vector rects = + makeGridTileRects( + config.gridCols, + config.gridRows, + static_cast(windowWidth), + static_cast(windowHeight), + TILE_GAP_PIXELS, + TILE_ASPECT); + + if (rects.empty()) + { + return {}; + } + + const TileRect& rect = rects.front(); + const uint32_t tileWidth = + static_cast( + std::max(1.0f, std::ceil(rect.x1 - rect.x0))); + const uint32_t tileHeight = + static_cast( + std::max(1.0f, std::ceil(rect.y1 - rect.y0))); + + return { + std::min(TEXTURE_WIDTH, tileWidth), + std::min(TEXTURE_HEIGHT, tileHeight) + }; +} + struct PerfStats { uint64_t frames = 0; @@ -749,6 +794,19 @@ int main(int argc, char* argv[]) int winWidth, winHeight; SDL_GetWindowSize(window, &winWidth, &winHeight); + const FeedTextureSize feedTextureSize = + chooseFeedTextureSize(config, winWidth, winHeight); + const uint32_t feedTextureWidth = feedTextureSize.width; + const uint32_t feedTextureHeight = feedTextureSize.height; + + std::cout + << "Feed texture size: " + << feedTextureWidth + << "x" + << feedTextureHeight + << (config.adaptiveFeedTexture ? " adaptive" : " fixed") + << std::endl; + Swapchain swapchain( ctx.device(), ctx.physicalDevice(), @@ -841,8 +899,8 @@ int main(int argc, char* argv[]) feeds[i] = createFeed( config.feeds[i], i, - TEXTURE_WIDTH, - TEXTURE_HEIGHT, + feedTextureWidth, + feedTextureHeight, config.verbose ); } @@ -852,7 +910,8 @@ int main(int argc, char* argv[]) // ---------------------------------------- VkDeviceSize imageSize = - TEXTURE_WIDTH * TEXTURE_HEIGHT * 4; + static_cast(feedTextureWidth) * + feedTextureHeight * 4; std::vector feedTextures(feedCount); @@ -960,8 +1019,8 @@ int main(int argc, char* argv[]) v210Decoder.init( ctx.device(), feedCount, - TEXTURE_WIDTH, - TEXTURE_HEIGHT + feedTextureWidth, + feedTextureHeight ); std::vector v210Feeds(feedCount); @@ -1806,8 +1865,8 @@ int main(int argc, char* argv[]) feeds[i]->v210Width(), feeds[i]->v210Height(), feeds[i]->v210Stride(), - TEXTURE_WIDTH, - TEXTURE_HEIGHT, + feedTextureWidth, + feedTextureHeight, config.v210StagingMemoryMode, v210Feeds[i] ); @@ -2084,8 +2143,8 @@ int main(int argc, char* argv[]) feeds[i]->v210Width(), feeds[i]->v210Height(), feeds[i]->v210Stride(), - TEXTURE_WIDTH, - TEXTURE_HEIGHT + feedTextureWidth, + feedTextureHeight ); v210Decoder.recordOutputReadyForSampling( @@ -2098,8 +2157,8 @@ int main(int argc, char* argv[]) recordFeedTextureUpload( uploadCmdBuf, feedTextures[i], - TEXTURE_WIDTH, - TEXTURE_HEIGHT + feedTextureWidth, + feedTextureHeight ); } }