Skip to content

Commit c8bd5d9

Browse files
authored
Resize in CICD + Cleanups (#72)
- `ci-` flags eg. `--ci-trigger-resize-after` `x frames` to test resize during CI (wont catch all issues) - Use options `struct` for the online/offline renderer - Other minor fixes and cleanups
1 parent 25ebfa3 commit c8bd5d9

File tree

6 files changed

+142
-45
lines changed

6 files changed

+142
-45
lines changed

.github/workflows/linux-smoke-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ jobs:
6565
- name: Vulkan 100 frame smoke test
6666
run: |
6767
xvfb-run -s "-screen 0 1024x768x24" \
68-
./build/vsdf --toy shaders/testtoyshader.frag --frames 100 --headless --log-level info
68+
./build/vsdf --toy shaders/testtoyshader.frag --frames 100 --headless --log-level info --ci-resize-after 50

include/offline_sdf_renderer.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ inline constexpr uint32_t OFFSCREEN_DEFAULT_WIDTH = 1280;
1717
inline constexpr uint32_t OFFSCREEN_DEFAULT_HEIGHT = 720;
1818
inline constexpr uint32_t OFFSCREEN_DEFAULT_RING_SIZE = 2;
1919

20+
struct OfflineRenderOptions {
21+
uint32_t maxFrames = 1;
22+
std::optional<std::filesystem::path> debugDumpPPMDir = std::nullopt;
23+
uint32_t width = OFFSCREEN_DEFAULT_WIDTH;
24+
uint32_t height = OFFSCREEN_DEFAULT_HEIGHT;
25+
uint32_t ringSize = OFFSCREEN_DEFAULT_RING_SIZE;
26+
ffmpeg_utils::EncodeSettings encodeSettings = {};
27+
};
28+
2029
// Offline SDF Renderer
2130
// This basis will be used for FFMPEG integration
2231
class OfflineSDFRenderer : public SDFRenderer {
@@ -84,13 +93,8 @@ class OfflineSDFRenderer : public SDFRenderer {
8493
OfflineSDFRenderer(const OfflineSDFRenderer &) = delete;
8594
OfflineSDFRenderer &operator=(const OfflineSDFRenderer &) = delete;
8695
OfflineSDFRenderer(
87-
const std::string &fragShaderPath, uint32_t maxFrames,
88-
bool useToyTemplate = false,
89-
std::optional<std::filesystem::path> debugDumpPPMDir = std::nullopt,
90-
uint32_t width = OFFSCREEN_DEFAULT_WIDTH,
91-
uint32_t height = OFFSCREEN_DEFAULT_HEIGHT,
92-
uint32_t ringSize = OFFSCREEN_DEFAULT_RING_SIZE,
93-
ffmpeg_utils::EncodeSettings encodeSettings = {});
96+
const std::string &fragShaderPath, bool useToyTemplate = false,
97+
OfflineRenderOptions options = {});
9498
void setup();
9599
void renderFrames();
96100
};

include/online_sdf_renderer.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ struct GLFWApplication {
1313
bool framebufferResized = false;
1414
};
1515

16+
struct OnlineRenderOptions {
17+
std::optional<uint32_t> maxFrames = std::nullopt;
18+
bool headless = false;
19+
bool noFocus = false;
20+
std::optional<std::filesystem::path> debugDumpPPMDir = std::nullopt;
21+
// For CI to test resize
22+
std::optional<uint32_t> ciResizeAfter = std::nullopt;
23+
std::optional<uint32_t> ciResizeWidth = std::nullopt;
24+
std::optional<uint32_t> ciResizeHeight = std::nullopt;
25+
};
26+
1627
// Online renderer: Vulkan + swapchain -- meant to be displayed.
1728
class OnlineSDFRenderer : public SDFRenderer {
1829
private:
@@ -34,9 +45,10 @@ class OnlineSDFRenderer : public SDFRenderer {
3445
vkutils::SwapchainImages swapchainImages;
3546
vkutils::SwapchainImageViews swapchainImageViews;
3647
vkutils::FrameBuffers frameBuffers;
37-
bool headless = false;
38-
bool noFocus = false;
39-
std::optional<uint32_t> maxFrames;
48+
OnlineRenderOptions options{};
49+
50+
// For CI to test resize
51+
bool ciResizeTriggered = false;
4052

4153
// Timing
4254
std::chrono::time_point<std::chrono::high_resolution_clock> cpuStartFrame,
@@ -59,11 +71,9 @@ class OnlineSDFRenderer : public SDFRenderer {
5971
public:
6072
OnlineSDFRenderer(const OnlineSDFRenderer &) = delete;
6173
OnlineSDFRenderer &operator=(const OnlineSDFRenderer &) = delete;
62-
OnlineSDFRenderer(
63-
const std::string &fragShaderPath, bool useToyTemplate = false,
64-
std::optional<uint32_t> maxFrames = std::nullopt, bool headless = false,
65-
std::optional<std::filesystem::path> debugDumpPPMDir = std::nullopt,
66-
bool noFocus = false);
74+
OnlineSDFRenderer(const std::string &fragShaderPath,
75+
bool useToyTemplate = false,
76+
OnlineRenderOptions options = {});
6777
void setup();
6878
void gameLoop();
6979
};

src/main.cpp

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ int run(int argc, char **argv) {
142142
bool headless = false;
143143
bool noFocus = false;
144144
std::optional<std::filesystem::path> debugDumpPPMDir;
145+
// For CI to test resize
146+
std::optional<uint32_t> ciResizeAfter;
147+
std::optional<uint32_t> ciResizeWidth;
148+
std::optional<uint32_t> ciResizeHeight;
145149
#if defined(VSDF_ENABLE_FFMPEG)
146150
uint32_t offlineRingSize = OFFSCREEN_DEFAULT_RING_SIZE;
147151
uint32_t offlineWidth = OFFSCREEN_DEFAULT_WIDTH;
@@ -324,6 +328,63 @@ int run(int argc, char **argv) {
324328
}
325329
#endif
326330

331+
// CI-only flags (intentionally undocumented).
332+
if (arg == "--ci-resize-after") {
333+
if (i + 1 >= argc) {
334+
throw CLIError(
335+
"--ci-resize-after requires a positive integer value");
336+
}
337+
try {
338+
ciResizeAfter = static_cast<uint32_t>(std::stoul(argv[++i]));
339+
} catch (const std::invalid_argument &) {
340+
throw CLIError("--ci-resize-after requires a valid positive "
341+
"integer value");
342+
} catch (const std::out_of_range &) {
343+
throw CLIError("--ci-resize-after value is out of range "
344+
"for a positive integer");
345+
}
346+
continue;
347+
} else if (arg == "--ci-resize-width") {
348+
if (i + 1 >= argc) {
349+
throw CLIError(
350+
"--ci-resize-width requires a positive integer value");
351+
}
352+
try {
353+
ciResizeWidth = static_cast<uint32_t>(std::stoul(argv[++i]));
354+
} catch (const std::invalid_argument &) {
355+
throw CLIError("--ci-resize-width requires a valid positive "
356+
"integer value");
357+
} catch (const std::out_of_range &) {
358+
throw CLIError("--ci-resize-width value is out of range "
359+
"for a positive integer");
360+
}
361+
if (*ciResizeWidth == 0) {
362+
throw CLIError(
363+
"--ci-resize-width requires a positive integer value");
364+
}
365+
continue;
366+
} else if (arg == "--ci-resize-height") {
367+
if (i + 1 >= argc) {
368+
throw CLIError(
369+
"--ci-resize-height requires a positive integer value");
370+
}
371+
try {
372+
ciResizeHeight = static_cast<uint32_t>(std::stoul(argv[++i]));
373+
} catch (const std::invalid_argument &) {
374+
throw CLIError("--ci-resize-height requires a valid positive "
375+
"integer value");
376+
} catch (const std::out_of_range &) {
377+
throw CLIError("--ci-resize-height value is out of range "
378+
"for a positive integer");
379+
}
380+
if (*ciResizeHeight == 0) {
381+
throw CLIError(
382+
"--ci-resize-height requires a positive integer value");
383+
}
384+
continue;
385+
}
386+
// END CI-only flags (intentionally undocumented).
387+
327388
if (arg.substr(0, 2) != "--") {
328389
if (shaderFile.empty()) {
329390
shaderFile = arg;
@@ -355,28 +416,39 @@ int run(int argc, char **argv) {
355416
spdlog::info("Setting things up...");
356417
spdlog::default_logger()->set_pattern("[%H:%M:%S] [%l] %v");
357418

419+
bool shouldRunOnline = true;
358420
#if defined(VSDF_ENABLE_FFMPEG)
359421
if (useFfmpeg) {
360-
OfflineSDFRenderer renderer{shaderFile.string(), *maxFrames,
361-
useToyTemplate, debugDumpPPMDir,
362-
offlineWidth, offlineHeight,
363-
offlineRingSize, encodeSettings};
422+
shouldRunOnline = false;
423+
OfflineRenderOptions offlineOptions{
424+
.maxFrames = *maxFrames,
425+
.debugDumpPPMDir = debugDumpPPMDir,
426+
.width = offlineWidth,
427+
.height = offlineHeight,
428+
.ringSize = offlineRingSize,
429+
.encodeSettings = encodeSettings,
430+
};
431+
OfflineSDFRenderer renderer{shaderFile.string(), useToyTemplate,
432+
std::move(offlineOptions)};
364433
renderer.setup();
365434
renderer.renderFrames();
366-
} else {
435+
}
436+
#endif
437+
if (shouldRunOnline) {
438+
OnlineRenderOptions onlineOptions{
439+
.maxFrames = maxFrames,
440+
.headless = headless,
441+
.noFocus = noFocus,
442+
.debugDumpPPMDir = debugDumpPPMDir,
443+
.ciResizeAfter = ciResizeAfter,
444+
.ciResizeWidth = ciResizeWidth,
445+
.ciResizeHeight = ciResizeHeight,
446+
};
367447
OnlineSDFRenderer renderer{shaderFile.string(), useToyTemplate,
368-
maxFrames, headless,
369-
debugDumpPPMDir, noFocus};
448+
std::move(onlineOptions)};
370449
renderer.setup();
371450
renderer.gameLoop();
372451
}
373-
#else
374-
OnlineSDFRenderer renderer{shaderFile.string(), useToyTemplate,
375-
maxFrames, headless,
376-
debugDumpPPMDir, noFocus};
377-
renderer.setup();
378-
renderer.gameLoop();
379-
#endif
380452
return 0;
381453
}
382454

src/offline_sdf_renderer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
#include <stdexcept>
99

1010
OfflineSDFRenderer::OfflineSDFRenderer(
11-
const std::string &fragShaderPath, uint32_t maxFrames, bool useToyTemplate,
12-
std::optional<std::filesystem::path> debugDumpPPMDir, uint32_t width,
13-
uint32_t height, uint32_t ringSize,
14-
ffmpeg_utils::EncodeSettings encodeSettings)
15-
: SDFRenderer(fragShaderPath, useToyTemplate, debugDumpPPMDir),
16-
imageSize({width, height}), ringSize(validateRingSize(ringSize)),
17-
maxFrames(maxFrames), encodeSettings(std::move(encodeSettings)) {}
11+
const std::string &fragShaderPath, bool useToyTemplate,
12+
OfflineRenderOptions options)
13+
: SDFRenderer(fragShaderPath, useToyTemplate, options.debugDumpPPMDir),
14+
imageSize({options.width, options.height}),
15+
ringSize(validateRingSize(options.ringSize)),
16+
maxFrames(options.maxFrames),
17+
encodeSettings(std::move(options.encodeSettings)) {}
1818

1919
uint32_t OfflineSDFRenderer::validateRingSize(uint32_t value) {
2020
if (value == 0 || value > MAX_FRAME_SLOTS) {

src/online_sdf_renderer.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ void framebufferResizeCallback(GLFWwindow *window, int width,
1717

1818
OnlineSDFRenderer::OnlineSDFRenderer(
1919
const std::string &fragShaderPath, bool useToyTemplate,
20-
std::optional<uint32_t> maxFrames, bool headless,
21-
std::optional<std::filesystem::path> debugDumpPPMDir, bool noFocus)
22-
: SDFRenderer(fragShaderPath, useToyTemplate, debugDumpPPMDir),
23-
headless(headless), noFocus(noFocus), maxFrames(maxFrames) {}
20+
OnlineRenderOptions options)
21+
: SDFRenderer(fragShaderPath, useToyTemplate, options.debugDumpPPMDir),
22+
options(std::move(options)) {}
2423

2524
void OnlineSDFRenderer::setup() {
2625
glfwSetup();
@@ -33,8 +32,8 @@ void OnlineSDFRenderer::setup() {
3332
void OnlineSDFRenderer::glfwSetup() {
3433
// GLFW Setup
3534
glfwutils::initGLFW();
36-
glfwWindowHint(GLFW_VISIBLE, headless ? GLFW_FALSE : GLFW_TRUE);
37-
if (noFocus) {
35+
glfwWindowHint(GLFW_VISIBLE, options.headless ? GLFW_FALSE : GLFW_TRUE);
36+
if (options.noFocus) {
3837
glfwWindowHint(GLFW_FLOATING, GLFW_TRUE); // Always on top
3938
glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
4039
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
@@ -195,8 +194,9 @@ void OnlineSDFRenderer::gameLoop() {
195194
pipelineUpdated.store(true, std::memory_order_relaxed);
196195
});
197196
while (!glfwWindowShouldClose(window)) {
198-
if (maxFrames && currentFrame >= *maxFrames) {
199-
spdlog::info("Reached max frames {}, exiting.", *maxFrames);
197+
if (options.maxFrames && currentFrame >= *options.maxFrames) {
198+
spdlog::info("Reached max frames {}, exiting.",
199+
*options.maxFrames);
200200
break;
201201
}
202202
cpuStartFrame = std::chrono::high_resolution_clock::now();
@@ -213,6 +213,17 @@ void OnlineSDFRenderer::gameLoop() {
213213
spdlog::info("Recreating pipeline");
214214
tryRecreatePipeline();
215215
}
216+
if (options.ciResizeAfter && !ciResizeTriggered &&
217+
currentFrame >= *options.ciResizeAfter) {
218+
const uint32_t targetWidth = options.ciResizeWidth.value_or(1024);
219+
const uint32_t targetHeight =
220+
options.ciResizeHeight.value_or(768);
221+
spdlog::info("CI resize at frame {} to {}x{}", currentFrame,
222+
targetWidth, targetHeight);
223+
glfwSetWindowSize(window, static_cast<int>(targetWidth),
224+
static_cast<int>(targetHeight));
225+
ciResizeTriggered = true;
226+
}
216227

217228
VK_CHECK(vkWaitForFences(logicalDevice, 1, &fences.fences[frameIndex],
218229
VK_TRUE, UINT64_MAX));

0 commit comments

Comments
 (0)