11 [[nodiscard]] std::string
format_bitrate(std::uint64_t bytes_written,
double duration_seconds) {
12 if (duration_seconds <= 0.0 || !std::isfinite(duration_seconds)) {
15 const double bitrate_kbits = (
static_cast<double>(bytes_written) * 8.0) / duration_seconds / 1000.0;
16 std::ostringstream text;
17 text << std::fixed << std::setprecision(1) << bitrate_kbits <<
" kbits/s";
22 constexpr float M1 = 2610.0F / 16384.0F;
23 constexpr float M2 = 2523.0F / 32.0F;
24 constexpr float C1 = 3424.0F / 4096.0F;
25 constexpr float C2 = 2413.0F / 128.0F;
26 constexpr float C3 = 2392.0F / 128.0F;
27 const float power_value = std::pow(std::clamp(encoded, 0.0F, 1.0F), 1.0F / M2);
28 const float numerator = std::max(power_value - C1, 0.0F);
29 const float denominator = std::max(C2 - C3 * power_value, 1.0e-6F);
30 return std::pow(numerator / denominator, 1.0F / M1);
34 constexpr float A = 0.17883277F;
35 constexpr float B = 0.28466892F;
36 constexpr float C = 0.55991073F;
37 encoded = std::max(encoded, 0.0F);
38 if (encoded <= 0.5F) {
39 return encoded * encoded / 3.0F;
41 return (std::exp((encoded - C) / A) + B) / 12.0F;
45 if (rgba.empty() || (rgba.type() != CV_8UC4 && rgba.type() != CV_16UC4)) {
48 cv::Mat linear(rgba.rows, rgba.cols, CV_16UC4);
49 const float scale = rgba.type() == CV_16UC4 ? 1.0F / 65535.0F : 1.0F / 255.0F;
50 for (
int row = 0; row < rgba.rows; ++row) {
51 auto *destination = linear.ptr<std::uint16_t>(row);
52 for (
int column = 0; column < rgba.cols; ++column) {
53 for (
int channel = 0; channel < 3; ++channel) {
54 const std::size_t offset =
static_cast<std::size_t
>(column) * 4U +
static_cast<std::size_t
>(channel);
55 const float encoded = rgba.type() == CV_16UC4 ?
static_cast<float>(rgba.ptr<std::uint16_t>(row)[offset]) * scale :
static_cast<float>(rgba.ptr<std::uint8_t>(row)[offset]) * scale;
57 destination[offset] =
static_cast<std::uint16_t
>(std::lround(std::clamp(decoded, 0.0F, 1.0F) * 65535.0F));
59 const std::size_t alpha_offset =
static_cast<std::size_t
>(column) * 4U + 3U;
60 destination[alpha_offset] = rgba.type() == CV_16UC4 ? rgba.ptr<std::uint16_t>(row)[alpha_offset] :
static_cast<std::uint16_t
>(rgba.ptr<std::uint8_t>(row)[alpha_offset] * 257U);
67 if (rgba.empty() || rgba.type() != CV_16UC4) {
71 rgba.convertTo(converted, CV_8UC4, 1.0 / 257.0);
76 value = std::max(value, 0.0F);
77 return std::clamp((value * (2.51F * value + 0.03F)) / (value * (2.43F * value + 0.59F) + 0.14F), 0.0F, 1.0F);
81 value = std::clamp(value, 0.0F, 1.0F);
82 return value <= 0.0031308F ? 12.92F * value : 1.055F * std::pow(value, 1.0F / 2.4F) - 0.055F;
85 [[nodiscard]] std::vector<std::uint8_t>
tone_map_hdr_rgba16(
const std::vector<std::uint16_t> &rgba,
bool hlg) {
86 std::vector<std::uint8_t> converted(rgba.size());
87 const float reference_scale = hlg ? 1000.0F / 203.0F : 10000.0F / 203.0F;
88 for (std::size_t offset = 0; offset + 3U < rgba.size(); offset += 4U) {
89 const auto decode = [hlg](std::uint16_t sample) {
90 const float encoded =
static_cast<float>(sample) / 65535.0F;
93 const float red = decode(rgba[offset]) * reference_scale;
94 const float green = decode(rgba[offset + 1U]) * reference_scale;
95 const float blue = decode(rgba[offset + 2U]) * reference_scale;
96 const float bt709_red = 1.660491F * red - 0.587641F * green - 0.072850F * blue;
97 const float bt709_green = -0.124550F * red + 1.132900F * green - 0.008349F * blue;
98 const float bt709_blue = -0.018151F * red - 0.100579F * green + 1.118730F * blue;
102 converted[offset + 3U] =
static_cast<std::uint8_t
>((
static_cast<std::uint32_t
>(rgba[offset + 3U]) + 128U) / 257U);
113 std::cout <<
"acmxvk: headless mode enabled: surface-free Vulkan "
114 "rendering without an SDL window\n";
116 setClearColor(0.0F, 0.0F, 0.0F, 1.0F);
127 std::cout <<
"acmxvk: audio-reactive shader time enabled at "
128 "startup (--audio-time)\n";
130 std::cerr <<
"acmxvk: --audio-time requested but no audio source "
131 "is active; shader time remains on its normal clock\n";
160 flushFrameReadbacks();
161 }
catch (
const std::exception &error) {
162 std::cerr <<
"acmxvk: unable to flush pending frame readbacks: " << error.what() <<
'\n';
168 vkDeviceWaitIdle(getDevice());
171 std::cout <<
"acmxvk: released 3D model resources\n";
188 std::cout <<
"acmxvk: recording closed after " <<
output_frame_count <<
" rendered frames";
195 std::cout <<
"acmxvk: PNG sequence closed after " <<
png_frame_count <<
" frames\n";
203#ifdef MXVK_WITH_FFMPEG_CAPTURE
204 if (ffmpeg_capture.is_open()) {
205 ffmpeg_capture.close();
208 if (should_copy_audio) {
213 if (should_mux_file_audio) {
214 const double video_duration =
writer.get_duration();
216 std::cerr <<
"acmxvk: file-audio mux failed; preserving the "
217 "encoded video without audio\n";
220 if (should_write_live_audio) {
221 if (live_audio_recording.
empty()) {
222 std::cerr <<
"acmxvk: standalone audio recording was empty; "
223 "no WAV file was written\n";
230 if (should_mux_live_audio) {
231 const double video_duration =
writer.get_duration();
232 if (live_audio_recording.
empty()) {
233 std::cerr <<
"acmxvk: live audio recording was empty; preserving "
234 "the encoded video without audio\n";
236 std::cerr <<
"acmxvk: live-audio mux failed; preserving the "
237 "encoded video without audio\n";
245 mxvk::VK_Window::event(
event);
246 if (
event.type == SDL_EVENT_KEY_DOWN &&
event.key.key == SDLK_PAGEUP) {
248 }
else if (
event.type == SDL_EVENT_KEY_DOWN &&
event.key.key == SDLK_PAGEDOWN) {
252 if (
event.type == SDL_EVENT_KEY_DOWN && !
event.key.repeat) {
253 switch (
event.key.key) {
278 std::cout <<
"acmxvk: shader effects " << (
effects_enabled ?
"enabled" :
"bypassed") <<
'\n';
285 std::cout <<
"acmxvk: playlist " << (
playlist_enabled ?
"enabled" :
"disabled") <<
'\n';
299 std::cout <<
"acmxvk: shader time " << (
shader_time_active ?
"enabled" :
"disabled") <<
'\n';
306 std::cout <<
"acmxvk: audio-reactive shader time " << (
audio_time_active ?
"enabled" :
"disabled") <<
'\n';
314 std::cout <<
"acmxvk: audio delta-time scaling " << (
audio_delta_time ?
"enabled" :
"disabled") <<
'\n';
342 std::cout <<
"acmxvk: runtime HUD " << (
counter_disabled ?
"hidden" :
"shown") <<
" (F9)\n";
347 std::cout <<
"acmxvk: watermark " << (
watermark_enabled ?
"enabled" :
"disabled") <<
'\n';
361 std::cout <<
"acmxvk: multipass " << (
multipass_enabled ?
"enabled" :
"disabled") <<
'\n';
373 std::cout <<
"acmxvk: shader lock " << (
shader_locked ?
"enabled" :
"disabled") <<
'\n';
381 std::cout <<
"acmxvk: " << (
model_3d_active ?
"3D model" :
"2D sprite") <<
" rendering enabled\n";
387 std::cout <<
"acmxvk: 3D view rotation " << (
model_auto_rotate ?
"enabled" :
"disabled") <<
'\n';
393 std::cout <<
"acmxvk: 3D wave effect " << (
model_wave_active ?
"enabled" :
"disabled") <<
'\n';
412 std::cout <<
"acmxvk: model view reset\n";
415 case SDLK_LEFTBRACKET:
418 case SDLK_RIGHTBRACKET:
422 case SDLK_UNDERSCORE:
424 if ((
event.key.mod & SDL_KMOD_SHIFT) != 0) {
431 if ((
event.key.mod & SDL_KMOD_SHIFT) != 0) {
465 }
else if (
event.type == SDL_EVENT_MOUSE_MOTION) {
469 const int x =
static_cast<int>(
event.motion.x);
470 const int y =
static_cast<int>(
event.motion.y);
476 }
else if (
event.type == SDL_EVENT_MOUSE_BUTTON_DOWN &&
event.button.button == SDL_BUTTON_LEFT) {
483 }
else if (
event.type == SDL_EVENT_MOUSE_BUTTON_UP &&
event.button.button == SDL_BUTTON_LEFT) {
489 const float wheel =
event.wheel.y != 0.0F ?
event.wheel.y :
static_cast<float>(
event.wheel.integer_y);
513 recordModel(command_buffer, image_index, VK_NULL_HANDLE);
520 recordModel(command_buffer, image_index, texture_view);
528 const auto now = std::chrono::steady_clock::now();
531 delta = std::clamp(delta, 0.0F, 0.1F);
533 float animation_delta = delta;
534 std::uint64_t animation_steps = 1U;
535 double video_timeline = 0.0;
536 std::uint64_t video_frame_index = 0U;
552 animation_delta = 0.0F;
553 animation_steps = 0U;
557 animation_delta =
static_cast<float>(
static_cast<double>(animation_steps) /
video_source_fps);
570 const auto advance_amplitude = [](
float &litude,
float &direction, std::uint64_t steps) {
571 constexpr float AMPLITUDE_RANGE = 0.5F;
572 constexpr float AMPLITUDE_PERIOD = AMPLITUDE_RANGE * 2.0F;
573 float phase = direction >= 0.0F ? amplitude : AMPLITUDE_PERIOD - amplitude;
574 phase = std::fmod(phase + 0.005F *
static_cast<float>(steps), AMPLITUDE_PERIOD);
575 if (phase < AMPLITUDE_RANGE) {
579 amplitude = AMPLITUDE_PERIOD - phase;
591 const bool *keyboard = SDL_GetKeyboardState(
nullptr);
592 const bool model_scale_modifier = (SDL_GetModState() & SDL_KMOD_SHIFT) != 0;
606 if (keyboard[SDL_SCANCODE_W]) {
609 if (keyboard[SDL_SCANCODE_S]) {
616 if (keyboard[SDL_SCANCODE_A]) {
619 if (keyboard[SDL_SCANCODE_D]) {
628 const VkExtent2D extent = getRenderExtent();
629 const float aspect = extent.height > 0U ?
static_cast<float>(extent.width) /
static_cast<float>(extent.height) : 1.0F;
631 mxvk::UniformBufferObject uniforms{};
636 uniforms.model = glm::translate(uniforms.model,
input_model.modelCenterOffset());
638 glm::vec3 look_direction{};
639 glm::vec3 camera_up(0.0F, 1.0F, 0.0F);
642 look_direction = glm::vec3(0.48F * std::sin(rotation), 0.48F * std::sin(rotation * 0.7F), 0.48F * std::cos(rotation));
646 look_direction = glm::normalize(glm::vec3(std::cos(pitch) * std::cos(yaw), std::sin(pitch), std::cos(pitch) * std::sin(yaw))) * 0.48F;
647 camera_up = glm::vec3(-std::sin(pitch) * std::cos(yaw), std::cos(pitch), -std::sin(pitch) * std::sin(yaw));
650 const glm::vec3 camera_position = -glm::normalize(look_direction) * camera_offset;
651 uniforms.view = glm::lookAt(camera_position, camera_position + look_direction, camera_up);
652 uniforms.proj = glm::perspective(glm::radians(120.0F), aspect, 0.01F, 1000.0F);
653 uniforms.proj[1][1] *= -1.0F;
658 mxvk::ModelFragmentPushConstants fragment_constants{};
659 fragment_constants.screenWidth =
static_cast<float>(extent.width);
660 fragment_constants.screenHeight =
static_cast<float>(extent.height);
661 fragment_constants.spriteSizeW =
static_cast<float>(extent.width);
662 fragment_constants.spriteSizeH =
static_cast<float>(extent.height);
664 fragment_constants.params = glm::vec4(1.0F, 1.0F, 1.0F,
static_cast<float>(
shader_time));
665 input_model.setFragmentPushConstants(fragment_constants);
667 if (texture_view != VK_NULL_HANDLE) {
668 input_model.renderWithExternalTexture(command_buffer, image_index, texture_view, uniforms,
false);
670 input_model.renderWithPushConstants(command_buffer, image_index, 0U, uniforms,
false);
675 if (HEADLESS_SHUTDOWN_REQUESTED != 0) {
677 std::cout <<
"acmxvk: shutdown requested; draining rendered "
678 "frames and closing output\n";
681 setFrameReadbackEnabled(
false);
701 bool clocked_video_handled =
false;
710 double clock_seconds = 0.0;
712 clocked_video_handled =
true;
734 double clock_seconds = 0.0;
737 const std::uint64_t target_frame =
static_cast<std::uint64_t
>(std::floor(std::max(clock_seconds, 0.0) * rate));
745 std::cout <<
"acmxvk: camera recording uses real-time "
746 "PTS; slow frames preserve capture duration\n";
758 const VkExtent2D extent = getRenderExtent();
759 const int target_width = extent.width > 0U ?
static_cast<int>(extent.width) :
options.
width;
760 const int target_height = extent.height > 0U ?
static_cast<int>(extent.height) :
options.
height;
766 frame_sprite->drawSpriteRect(0, 0, target_width, target_height);
779 std::cout <<
"acmxvk: audio shader warmup disabled\n";
804#ifdef ACMXVK_WITH_DNN
807 std::cout <<
"acmxvk: PP-HumanSeg enabled: " <<
options.
human_model <<
" (" << (
options.
human_background ?
"background-only shader composition" :
"foreground isolation") <<
", automatic CPU/CUDA backend selection)\n";
811 std::cout <<
"acmxvk: DexiNed edge detection enabled: " <<
options.
edge_model <<
" (automatic CPU/CUDA backend selection)\n";
815 std::cout <<
"acmxvk: generic ONNX processing enabled: " <<
options.
onnx_configuration <<
" (automatic CPU/CUDA backend selection)\n";
821#ifdef ACMXVK_WITH_DEEP_DREAM
829 throw std::runtime_error(
"--dream-channel is outside the selected layer's channel range");
841 <<
"; output feeds the existing Vulkan shader chain\n";
847 <<
" Deep Dream video mode: "
848 "independent source frames, temporal feedback/zoom/"
849 "rotation disabled, no-drop output\n";
855#ifdef ACMXVK_WITH_STABLE_DIFFUSION
862 if (!fs::is_regular_file(model)) {
863 throw std::runtime_error(
"Stable Diffusion model is not a regular file: " + model.string());
867 throw std::runtime_error(
"Stable Diffusion video preview currently supports SDR input only");
871 settings.
model = model;
875 const fs::path lora_model = fs::absolute(configured_lora.
file).lexically_normal();
876 if (!fs::is_regular_file(lora_model)) {
877 throw std::runtime_error(
"Stable Diffusion LoRA model is not a regular file: " + lora_model.string());
882 throw std::runtime_error(
"all Stable Diffusion LoRA models must be in the same "
885 settings.
loras.push_back({lora_model.filename(), configured_lora.
multiplier});
889 if (!fs::is_regular_file(upscale_model)) {
890 throw std::runtime_error(
"Stable Diffusion upscale model is not a regular file: " + upscale_model.string());
911 const std::shared_ptr<std::atomic_bool> cancelled = stable_diffusion_cancelled;
912 settings.
cancelled = [cancelled] {
return cancelled->load(std::memory_order_relaxed) || HEADLESS_SHUTDOWN_REQUESTED != 0; };
913 std::cout <<
"acmxvk: loading " << (settings.
upscale_only ?
"Stable Diffusion ESRGAN upscaler" :
"Stable Diffusion model") <<
" asynchronously; the preview will begin when it is ready\n";
914 stable_diffusion_initialization = std::async(std::launch::async, [settings = std::move(settings)]()
mutable {
return std::make_unique<stable_diffusion::Server>(std::move(settings)); });
915 stable_diffusion_initialization_pending =
true;
920#ifdef ACMXVK_WITH_STABLE_DIFFUSION
921 if (!stable_diffusion_initialization_pending) {
924 if (stable_diffusion_initialization.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
927 stable_diffusion_server = stable_diffusion_initialization.get();
928 stable_diffusion_initialization_pending =
false;
929 if (stable_diffusion_initial_frame_deferred) {
930 stable_diffusion_initial_frame_deferred =
false;
932 throw std::runtime_error(
"capture did not provide an initial frame after Stable "
933 "Diffusion startup");
938 std::cout <<
"acmxvk: Stable Diffusion frame processing enabled after "
939 "the Vulkan shader chain; MXWrite CFR output enabled\n";
941 std::cout <<
"acmxvk: Stable Diffusion frame processing enabled before "
942 "the Vulkan shader chain"
947 << (
options.
output_file.empty() ?
"; windowed preview mode\n" :
"; MXWrite CFR output enabled\n");
956#ifdef ACMXVK_WITH_STABLE_DIFFUSION
957 stable_diffusion_cancelled->store(
true, std::memory_order_relaxed);
958 if (!stable_diffusion_initialization.valid()) {
962 std::unique_ptr<stable_diffusion::Server> pending_server = stable_diffusion_initialization.get();
963 }
catch (
const std::exception &error) {
964 std::cerr <<
"acmxvk: Stable Diffusion startup stopped: " << error.what() <<
'\n';
966 stable_diffusion_initialization_pending =
false;
971#ifdef ACMXVK_WITH_STABLE_DIFFUSION
975 rgba = stable_diffusion_server->process(rgba);
977 static_cast<void>(rgba);
982#ifdef ACMXVK_WITH_CUDA
991#ifdef ACMXVK_WITH_CUDA
1000 static_cast<void>(direction);
1009 midi_input = std::make_unique<midi::MidiInput>();
1012 throw std::runtime_error(
"could not open MIDI input port " + std::to_string(port));
1024 for (
int slider = 0; slider < 4; ++slider) {
1025 const int action = 600 + slider * 2;
1030 const std::string name =
"slider" + std::to_string(slider + 1);
1033 std::cerr <<
"acmxvk: MIDI " << name
1034 <<
" mapping has no matching custom uniform in "
1039 std::cout <<
"acmxvk: MIDI Slider " << (slider + 1) <<
" -> " << name <<
" [" << uniform->minimum <<
", " << uniform->maximum <<
"]\n";
1042 std::size_t active_mappings = 0;
1047 std::cerr <<
"acmxvk: MIDI map action unavailable in this build: " << mapping.primary_action <<
':' << mapping.secondary_action <<
'\n';
1050 std::cout <<
"acmxvk: MIDI map has " << active_mappings <<
" active mapping(s)";
1052 std::cout <<
" and " << (
midi_action_mappings.size() - active_mappings) <<
" mapping(s) reserved for unported ACMX2 controls";
1058 const std::size_t equals = mapping_text.find(
'=');
1059 if (equals == std::string::npos || equals == 0 || equals + 1 >= mapping_text.size() || mapping_text.find(
'=', equals + 1) != std::string::npos) {
1060 throw std::runtime_error(
"--midi-cc requires [channel:]CC=uniform: " + mapping_text);
1063 const std::string source =
trim(mapping_text.substr(0, equals));
1064 const std::string uniform_name =
trim(mapping_text.substr(equals + 1));
1066 throw std::runtime_error(
"--midi-cc contains an invalid uniform name: " + uniform_name);
1071 const std::size_t colon = source.find(
':');
1072 if (colon == std::string::npos) {
1075 if (colon == 0 || colon + 1 >= source.size() || source.find(
':', colon + 1) != std::string::npos) {
1076 throw std::runtime_error(
"--midi-cc requires [channel:]CC=uniform: " + mapping_text);
1078 channel =
parseInteger(std::string_view(source).substr(0, colon),
"--midi-cc");
1079 controller =
parseInteger(std::string_view(source).substr(colon + 1),
"--midi-cc");
1080 if (channel < 1 || channel > 16) {
1081 throw std::runtime_error(
"--midi-cc channel must be between 1 and 16");
1085 if (controller < 0 || controller > 127) {
1086 throw std::runtime_error(
"--midi-cc controller must be between 0 and 127");
1091 throw std::runtime_error(
"--midi-cc target is not defined in library.json: " + uniform_name);
1093 const std::size_t uniform_index =
static_cast<std::size_t
>(std::distance(
custom_uniforms.begin(), uniform));
1096 throw std::runtime_error(
"custom uniform has more than one --midi-cc mapping: " + uniform_name);
1099 midi_cc_mappings.push_back({channel, controller, uniform_index, uniform_name});
1100 std::cout <<
"acmxvk: MIDI " << (channel < 0 ? std::string(
"any channel") :
"channel " + std::to_string(channel + 1)) <<
" CC " << controller <<
" -> " << uniform_name <<
" [" << uniform->minimum <<
", " << uniform->maximum <<
"]\n";
1107 if (message.
bytes.size() < 3 || (message.
bytes[0] & 0xF0U) != 0xB0U) {
1110 const int channel = message.
bytes[0] & 0x0FU;
1111 const int controller = message.
bytes[1] & 0x7FU;
1112 const int value = message.
bytes[2] & 0x7FU;
1113 bool changed =
false;
1115 if (mapping.controller != controller || (mapping.channel >= 0 && mapping.channel != channel)) {
1119 const double normalized =
static_cast<double>(value) / 127.0;
1120 const float mapped =
static_cast<float>(uniform.
minimum + normalized * (uniform.
maximum - uniform.
minimum));
1124 std::cout <<
"acmxvk: MIDI CC " << controller <<
" -> " << mapping.uniform_name <<
'=' << mapped <<
'\n';
1133#ifdef ACMXVK_WITH_CUDA
1134 return gpu_filter_engine !=
nullptr ? SDLK_RIGHT : SDLK_UNKNOWN;
1136 return SDLK_UNKNOWN;
1139#ifdef ACMXVK_WITH_CUDA
1140 return gpu_filter_engine !=
nullptr ? SDLK_LEFT : SDLK_UNKNOWN;
1142 return SDLK_UNKNOWN;
1153 return SDLK_PAGEDOWN;
1158 return SDLK_UNKNOWN;
1164 return SDLK_UNKNOWN;
1216 return SDLK_UNKNOWN;
1235 return SDLK_UNKNOWN;
1255 return primary_supported && secondary_supported;
1261 return "select next CUDA filter";
1263 return "select previous CUDA filter";
1265 return "next shader or playlist node";
1267 return "previous shader or playlist node";
1270 return "increase shader time speed";
1273 return "decrease shader time speed";
1275 return "toggle audio delta-time scaling";
1277 return "toggle spectrum sensitivity scaling";
1279 return "increase audio sensitivity";
1281 return "decrease audio sensitivity";
1283 return "step shader time forward";
1285 return "step shader time backward";
1287 return "rotate model X forward";
1289 return "rotate model X backward";
1291 return "rotate model Y forward";
1293 return "rotate model Y backward";
1295 return "increase 3D manual rotation speed";
1297 return "decrease 3D manual rotation speed";
1299 return "rotate model Z forward";
1301 return "rotate model Z backward";
1303 return "increase model scale";
1305 return "decrease model scale";
1307 return "toggle runtime HUD";
1309 return "toggle shader bypass";
1311 return "decrease 3D view rotation speed";
1313 return "increase 3D view rotation speed";
1315 return "toggle 2D/3D rendering";
1317 return "take TIFF snapshot";
1319 return "take WebP snapshot";
1321 return "take raw RGBA snapshot";
1323 return "toggle 3D wave effect";
1325 return "toggle 3D scale oscillation";
1327 return "decrease model scale";
1329 return "increase model scale";
1331 return "toggle watermark";
1333 return "toggle random autopilot";
1335 return "toggle random autopilot crossfade";
1337 return "toggle shader lock";
1339 return "toggle rendering freeze";
1341 return "toggle multipass";
1343 return "toggle playlist or input pause";
1345 return "toggle audio-reactive shader time";
1347 return "toggle fullscreen";
1349 return "step shader time backward";
1351 return "toggle shader time";
1353 return "step shader time forward";
1355 return "toggle 3D view rotation";
1357 return "reset model view";
1359 return "toggle sequential autopilot";
1361 return "take screenshot";
1363 return "unsupported action";
1372 const auto rotate = [](
float °rees,
float amount) {
1373 degrees = std::fmod(degrees + amount, 360.0F);
1374 if (degrees < 0.0F) {
1419 std::cout <<
"acmxvk: MIDI action: " <<
midiActionName(action) <<
'\n';
1425 if (key == SDLK_UNKNOWN) {
1429 std::cout <<
"acmxvk: MIDI action: " <<
midiActionName(action) <<
'\n';
1431 SDL_Event midi_event{};
1432 midi_event.type = SDL_EVENT_KEY_DOWN;
1433 midi_event.key.type = SDL_EVENT_KEY_DOWN;
1434 midi_event.key.key = key;
1435 midi_event.key.mod = action == 91 || action == 93 ? SDL_KMOD_SHIFT : SDL_KMOD_NONE;
1436 midi_event.key.repeat =
false;
1445 const double normalized =
static_cast<double>(value) / 127.0;
1446 const float mapped =
static_cast<float>(uniform.
minimum + normalized * (uniform.
maximum - uniform.
minimum));
1449 std::cout <<
"acmxvk: MIDI " << label <<
" -> " << uniform.
name <<
'=' << mapped <<
'\n';
1455 if (message.
bytes.size() < 3) {
1458 bool changed =
false;
1464 const int value = message.
bytes[2] & 0x7FU;
1475 if (uniform_index >= 0) {
1476 changed =
setMidiUniform(
static_cast<std::size_t
>(uniform_index), value,
"Slider " + std::to_string(slider + 1)) || changed;
1486 state.
value = value;
1487 state.
active = value != 64;
1503 const int distance = std::abs(state.
value - 64);
1504 const int frame_skip = std::max(1, 17 - (distance * 16 / 63));
1535 const std::vector<midi::MidiMessage> messages =
midi_input->poll_messages();
1536 bool custom_uniforms_changed =
false;
1538 custom_uniforms_changed =
applyMidiCc(message) || custom_uniforms_changed;
1539 custom_uniforms_changed =
applyMidiMap(message) || custom_uniforms_changed;
1542 if (custom_uniforms_changed) {
1547 std::ostringstream text;
1548 text <<
"acmxvk: MIDI #" << message.sequence <<
" +" << std::fixed << std::setprecision(6) << message.delta_seconds <<
"s [";
1549 for (std::size_t index = 0; index < message.bytes.size(); ++index) {
1553 text << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << static_cast<unsigned int>(message.bytes[index]);
1556 std::cout << text.str() <<
'\n';
1559 const std::uint64_t dropped =
midi_input->dropped_message_count();
1561 std::cerr <<
"acmxvk: MIDI queue dropped " << dropped <<
" message(s) total\n";
1578 std::cerr <<
"acmxvk: source video has no decodable audio "
1579 "track; continuing with silent audio-reactive "
1582 std::cerr <<
" and pass-through disabled";
1588 throw std::runtime_error(
"could not decode --audio-file: " +
options.
audio_file);
1591 std::cout <<
"acmxvk: source video audio drives shader "
1594 std::cout <<
"acmxvk: offline source-audio synchronization: "
1595 "analysis follows each decoded video frame\n";
1600 std::cerr <<
"acmxvk: file audio output could not be "
1601 "initialized; continuing with silent analysis\n";
1616 std::cerr <<
"acmxvk: audio input could not be initialized; "
1617 "continuing with zero-valued audio metrics\n";
1631 throw std::runtime_error(
"--record-audio requires an active live audio input");
1637 throw std::runtime_error(
"could not start standalone microphone recording");
1651 static_cast<void>(amount);
1653 std::cout <<
"acmxvk: audio input is not active\n";
1670 std::cerr <<
"acmxvk: could not start live audio recording; "
1671 "continuing with video-only output\n";
1692 std::cout <<
"acmxvk: media timeline started on first source frame\n";
1700 const auto now = std::chrono::steady_clock::now();
1727 seconds = std::max(0.0, std::chrono::duration<double>(active_time).count());
1740 const std::string label = compute ?
"compute shader" :
"fragment shader";
1741 if (shader.extension() !=
".spv" || !fs::is_regular_file(shader)) {
1742 throw std::runtime_error(label +
" is not a readable .spv file: " + shader.string());
1745 const mxvk::ShaderModuleInfo module_info = mxvk::inspect_spirv(mxvk::load_spv(shader.string()));
1746 const mxvk::ShaderStage expected_stage = compute ? mxvk::ShaderStage::Compute : mxvk::ShaderStage::Fragment;
1747 if (module_info.stage != expected_stage) {
1748 throw std::runtime_error(label +
" SPIR-V entry point has the wrong shader stage: " + shader.string());
1763 for (
const std::string &entry : manifest.
entries) {
1765 if (!shader.empty()) {
1767 const mxvk::ShaderModuleInfo module_info = mxvk::inspect_spirv(mxvk::load_spv(shader.string()));
1772 std::sort(
shaders.begin(),
shaders.end(), [](
const fs::path &left,
const fs::path &right) {
1773 std::string left_text = left.generic_string();
1774 std::string right_text = right.generic_string();
1775 std::transform(left_text.begin(), left_text.end(), left_text.begin(), [](unsigned char character) { return static_cast<char>(std::tolower(character)); });
1776 std::transform(right_text.begin(), right_text.end(), right_text.begin(), [](
unsigned char character) { return static_cast<char>(std::tolower(character)); });
1777 return left_text < right_text;
1779 if (shaders.empty()) {
1780 throw std::runtime_error(
"shader manifest contains no readable SPIR-V files: " + shader_manifest_path.string());
1782 std::cout <<
"acmxvk: loaded " << shaders.size() <<
" shaders from " << shader_manifest_path.string() <<
'\n';
1783 printCustomUniforms();
1785 if (!options.shader_file.empty()) {
1786 const auto selected = std::find_if(shaders.begin(), shaders.end(), [&](
const fs::path &path) {
1787 fs::path requested(options.shader_file);
1788 if (requested.extension() !=
".spv") {
1789 requested.replace_extension(
".spv");
1791 return path.filename() == requested.filename() || path.lexically_relative(shader_library_directory) == requested;
1793 if (selected == shaders.end()) {
1794 throw std::runtime_error(
"shader file is not listed in the manifest: " + options.shader_file);
1796 shader_index =
static_cast<std::size_t
>(std::distance(shaders.begin(), selected));
1798 const int count =
static_cast<int>(shaders.size());
1799 const int wrapped_index = ((options.shader_index % count) + count) % count;
1800 shader_index =
static_cast<std::size_t
>(wrapped_index);
1805 for (
const std::string &override_text :
options.custom_uniform_overrides) {
1806 const std::size_t separator = override_text.find(
'=');
1807 if (separator == std::string::npos || separator == 0 || separator + 1 >= override_text.size()) {
1808 throw std::runtime_error(
"--uniform requires name=value: " + override_text);
1810 const std::string name =
trim(override_text.substr(0, separator));
1811 const double value =
parseNumber(
trim(override_text.substr(separator + 1)),
"--uniform");
1814 throw std::runtime_error(
"custom uniform is not defined in library.json: " + name);
1816 match->value = std::clamp(value, match->minimum, match->maximum);
1830 constexpr std::string_view COMPONENTS =
"xyzw";
1831 std::cout <<
"acmxvk: custom uniforms (binding 1):\n";
1832 for (std::size_t index = 0; index <
custom_uniforms.size(); ++index) {
1834 std::cout <<
" " << uniform.
name <<
'=' << uniform.
value <<
" -> custom_uniforms[" << (index / 4) <<
"]." << COMPONENTS[index % 4] <<
'\n';
1841 std::error_code error;
1842 const fs::path canonical = fs::weakly_canonical(shader, error);
1843 const std::string key = (error ? shader.lexically_normal() : canonical).string();
1853 std::cout <<
"acmxvk: enabled shared history for " << source <<
" binding 2\n";
1857 std::cout <<
"acmxvk: enabled spectrum descriptor for " << source <<
" binding 3\n";
1861 if (
options.audio_buffers == 0) {
1864 std::cout <<
"acmxvk: enabled " <<
options.audio_buffers <<
" spectrum-history layers for " << source <<
" binding 4\n";
1891 const auto now = std::chrono::steady_clock::now();
1903 std::cerr <<
"acmxvk: could not read compatible interface "
1904 "control state; retrying\n";
1922 std::cout <<
"acmxvk: interface live shader, multipass, playback, "
1923 "overlay, GPU-filter, Deep Dream, and audio-file control "
1925 << (reconnected ?
" (reconnected)" :
"") <<
'\n';
1940 std::cerr <<
"acmxvk: interface control connection lost; "
1973 std::cout <<
"acmxvk: interface video repeat " << (
options.repeat ?
"enabled" :
"disabled") <<
'\n';
1979 std::cout <<
"acmxvk: interface normalized time " << (
options.normalized_time ?
"enabled" :
"disabled") <<
'\n';
1988 std::cout <<
"acmxvk: interface display-filter overlay " << (
options.display_filter ?
"enabled" :
"disabled") <<
'\n';
1994 }
catch (
const std::exception &error) {
1995 std::cerr <<
"acmxvk: rejected interface watermark: " << error.what() <<
'\n';
2013 std::cout <<
"acmxvk: interface watermark " << (
watermark_enabled ?
"enabled" :
"disabled");
2015 std::cout <<
" (color=" <<
static_cast<int>(
options.watermark_color[0]) <<
',' <<
static_cast<int>(
options.watermark_color[1]) <<
',' <<
static_cast<int>(
options.watermark_color[2]) <<
')';
2022#ifdef ACMXVK_WITH_CUDA
2024 const bool currently_enabled = gpu_filter_engine !=
nullptr;
2025 const std::vector<int> effective_indices = requested_enabled ? requested.
filter_indices : std::vector<int>{};
2026 if (requested_enabled == currently_enabled &&
options.gpu_filter_indices == effective_indices && (!requested_enabled ||
options.gpu_frame_buffer_size == requested.
frame_buffer_size)) {
2031 std::cerr <<
"acmxvk: rejected enabled interface GPU-filter "
2032 "state without any filter indices\n";
2036 std::unique_ptr<gpu::FilterEngine> replacement;
2037 if (requested_enabled) {
2040 }
catch (
const std::exception &error) {
2041 std::cerr <<
"acmxvk: rejected interface GPU-filter state: " << error.what() <<
'\n';
2046 gpu_filter_engine = std::move(replacement);
2047 options.gpu_filter_indices = effective_indices;
2048 if (requested_enabled) {
2061 std::cout <<
"acmxvk: interface CUDA filter chain " << (requested_enabled ?
"enabled" :
"disabled");
2062 if (requested_enabled) {
2068 if (announce && requested.
enabled) {
2069 std::cerr <<
"acmxvk: ignored interface GPU-filter state: this "
2070 "build does not include acidcam-gpu\n";
2076#ifdef ACMXVK_WITH_DEEP_DREAM
2079 if (!currently_enabled) {
2083#ifdef ACMXVK_WITH_MXVK_CUDA
2084 cuda_dream_rgba.release();
2088 options.gpu_filter_before_dream =
false;
2091 std::cout <<
"acmxvk: interface Deep Dream disabled\n";
2100 throw std::runtime_error(
"iterations must be between 1 and 100");
2103 throw std::runtime_error(
"strength must be greater than 0 and no more than 10");
2106 throw std::runtime_error(
"feedback must be between 0 and 0.99");
2108 if (!std::isfinite(requested.
zoom) || requested.
zoom < 0.9F || requested.
zoom > 1.1F) {
2109 throw std::runtime_error(
"zoom must be between 0.9 and 1.1");
2112 throw std::runtime_error(
"rotation must be between -5 and 5 degrees");
2115 throw std::runtime_error(
"maximum dimension must be 0 or between 64 and 4096");
2118 throw std::runtime_error(
"channel must be all channels or between 0 and 65535");
2121 throw std::runtime_error(
"octaves must be between 1 and 8");
2124 throw std::runtime_error(
"octave scale must be between 1.1 and 3.0");
2127 throw std::runtime_error(
"jitter must be between 0 and 64");
2130 throw std::runtime_error(
"smoothing must be between 0 and 16");
2133#ifdef ACMXVK_WITH_CUDA
2134 if (gpu_filter_engine ==
nullptr) {
2135 throw std::runtime_error(
"acidcam-gpu-first requires an enabled GPU filter chain");
2138 throw std::runtime_error(
"acidcam-gpu-first requires acidcam-gpu support");
2141 throw std::runtime_error(
"acidcam-gpu-first cannot be used with maximize FPS");
2144 throw std::runtime_error(
"acidcam-gpu-first supports camera and video input");
2146 if (!
options.edge_model.empty() || !
options.human_model.empty() || !
options.onnx_configuration.empty()) {
2147 throw std::runtime_error(
"acidcam-gpu-first cannot be combined with DNN input effects");
2150 throw std::runtime_error(
"acidcam-gpu-first cannot be enabled for HDR input");
2155 if (!settings_changed) {
2160 std::unique_ptr<dream::Model> replacement;
2164 validated_model = replacement.get();
2167 throw std::runtime_error(
"channel is outside the selected layer's channel range");
2170 if (replacement !=
nullptr) {
2172#ifdef ACMXVK_WITH_MXVK_CUDA
2173 cuda_dream_rgba.release();
2194 std::cout <<
"acmxvk: interface Deep Dream settings applied: " << requested.
layer <<
", " << requested.
iterations <<
" iteration(s), strength " << requested.
strength <<
", feedback " << requested.
feedback <<
", zoom " << requested.
zoom <<
", rotation " << requested.
rotation <<
" degrees, " << (requested.
gpu_filter_first ?
"acidcam-gpu first" :
"Deep Dream first") << (reload_model ?
" (model reloaded)" :
"") <<
'\n';
2196 }
catch (
const std::exception &error) {
2197 std::cerr <<
"acmxvk: rejected interface Deep Dream settings: " << error.what() <<
'\n';
2200 if (announce && requested.
enabled) {
2201 std::cerr <<
"acmxvk: ignored interface Deep Dream settings: this "
2202 "build does not include Deep Dream support\n";
2210 std::cerr <<
"acmxvk: ignored live audio-file change because this "
2211 "process was not started in audio-file mode\n";
2214 if (requested.
path.empty()) {
2215 std::cerr <<
"acmxvk: rejected empty interface audio-file request\n";
2219 auto replacement = std::make_unique<audio::FileAudioSource>();
2221 if (!replacement->open(requested.
path)) {
2222 std::cerr <<
"acmxvk: could not switch file audio to: " << requested.
path <<
'\n';
2225 }
catch (
const std::exception &error) {
2226 std::cerr <<
"acmxvk: rejected interface audio-file request: " << error.what() <<
'\n';
2230 replacement->set_repeat(requested.
repeat);
2232 std::cerr <<
"acmxvk: live audio-file output could not be opened; "
2233 "continuing with visual reactivity only\n";
2245 std::cout <<
"acmxvk: switched file audio to: " <<
file_audio_source->path() <<
" (repeat=" << (
options.audio_repeat ?
"on" :
"off") <<
", trunc=" << (
options.audio_trunc ?
"on" :
"off") <<
", pass-through=" << (
options.audio_pass_through ?
"on" :
"off") <<
")\n";
2247 static_cast<void>(requested);
2248 std::cerr <<
"acmxvk: ignored interface audio-file request: this "
2249 "build does not include audio support\n";
2254 if (requested.
path.empty()) {
2255 std::cerr <<
"acmxvk: rejected empty interface shader reload\n";
2261 }
catch (
const std::exception &error) {
2262 std::cerr <<
"acmxvk: rejected interface shader reload: " << error.what() <<
'\n';
2266 std::error_code error;
2267 const fs::path requested_path = fs::weakly_canonical(requested.
path, error);
2268 if (error || requested_path.empty() || !fs::is_regular_file(requested_path)) {
2269 std::cerr <<
"acmxvk: interface shader reload file is not "
2271 << requested.
path <<
'\n';
2275 std::size_t logical_index =
shaders.size();
2276 const auto shader_match = std::find_if(
shaders.begin(),
shaders.end(), [&](
const fs::path &shader) {
2277 std::error_code shader_error;
2278 const fs::path canonical_shader = fs::weakly_canonical(shader, shader_error);
2279 return !shader_error && canonical_shader == requested_path;
2281 if (shader_match !=
shaders.end()) {
2282 logical_index =
static_cast<std::size_t
>(std::distance(
shaders.begin(), shader_match));
2284 logical_index =
static_cast<std::size_t
>(requested.
shader_index);
2286 if (logical_index >=
shaders.size()) {
2287 std::cerr <<
"acmxvk: interface shader reload does not identify "
2288 "a shader in the active runtime library: "
2289 << requested_path.string() <<
'\n';
2293 const fs::path logical_shader =
shaders[logical_index];
2294 std::error_code logical_error;
2295 const fs::path canonical_logical = fs::weakly_canonical(logical_shader, logical_error);
2296 if (logical_error || canonical_logical.empty()) {
2297 std::cerr <<
"acmxvk: interface shader reload could not resolve "
2298 "its runtime-library shader\n";
2301 const std::string logical_key = canonical_logical.string();
2304 mxvk::ShaderModuleInfo module_info;
2307 module_info = mxvk::inspect_spirv(mxvk::load_spv(requested_path.string()));
2308 }
catch (
const std::exception &reload_error) {
2309 std::cerr <<
"acmxvk: rejected compiled shader reload: " << reload_error.what() <<
'\n';
2320 std::error_code active_error;
2321 const fs::path canonical_previous = fs::weakly_canonical(previously_resolved, active_error);
2322 const bool active = !active_error && std::any_of(active_pipeline.begin(), active_pipeline.end(), [&](
const fs::path &shader) {
2323 std::error_code shader_error;
2324 return fs::weakly_canonical(shader, shader_error) == canonical_previous && !shader_error;
2326 if (requested_path == canonical_logical)
2332 if (resources_grew) {
2338 std::cout <<
"acmxvk: live reloaded active " << (module_info.stage == mxvk::ShaderStage::Compute ?
"compute" :
"fragment") <<
" shader: " << requested_path.string() <<
'\n';
2340 std::cout <<
"acmxvk: live compiled shader ready for its next "
2342 << requested_path.string() <<
'\n';
2347 std::vector<fs::path> requested_passes;
2350 std::cerr <<
"acmxvk: rejected enabled interface multipass "
2351 "state without any shader passes\n";
2354 requested_passes.reserve(requested.
shader_names.size());
2355 for (
const std::string &name : requested.
shader_names) {
2356 const fs::path requested_path(name);
2357 const bool has_parent_reference = std::any_of(requested_path.begin(), requested_path.end(), [](
const fs::path &part) { return part ==
".."; });
2358 if (requested_path.is_absolute() || has_parent_reference) {
2359 std::cerr <<
"acmxvk: rejected unsafe interface "
2360 "multipass shader name: "
2365 if (shader.empty()) {
2366 std::cerr <<
"acmxvk: interface multipass shader is not "
2367 "in the active library: "
2371 requested_passes.push_back(shader);
2375 const bool requested_enabled = requested.
enabled && !requested_passes.empty();
2380 std::cerr <<
"acmxvk: interface multipass update ignored while "
2381 "shader switching is locked\n";
2397 std::cout <<
"acmxvk: interface multipass enabled (" <<
configured_passes.size() <<
" passes)";
2399 std::cout <<
"\n " << shader.filename().string();
2403 std::cout <<
"acmxvk: interface multipass disabled\n";
2408 if (requested_name.empty()) {
2412 const fs::path requested(requested_name);
2413 const bool has_parent_reference = std::any_of(requested.begin(), requested.end(), [](
const fs::path &part) { return part ==
".."; });
2414 if (requested.is_absolute() || has_parent_reference) {
2415 std::cerr <<
"acmxvk: rejected unsafe interface shader name: " << requested_name <<
'\n';
2420 const auto match = std::find(
shaders.begin(),
shaders.end(), shader);
2421 if (shader.empty() || match ==
shaders.end()) {
2422 std::cerr <<
"acmxvk: interface shader is not in the active "
2424 << requested_name <<
'\n';
2428 const std::size_t next_index =
static_cast<std::size_t
>(std::distance(
shaders.begin(), match));
2433 std::cerr <<
"acmxvk: interface shader selection ignored while "
2434 "shader switching is locked\n";
2447 if (uniform_values.empty()) {
2451 std::size_t changed_count = 0;
2452 std::size_t ignored_count = 0;
2463 const std::size_t index =
static_cast<std::size_t
>(std::distance(
custom_uniforms.begin(), match));
2468 const float value =
static_cast<float>(std::clamp(
static_cast<double>(incoming.value), match->minimum, match->maximum));
2476 if (changed_count > 0) {
2478 std::cout <<
"acmxvk: interface updated " << changed_count <<
" custom uniform(s)\n";
2480 if (ignored_count > 0) {
2481 std::cerr <<
"acmxvk: interface ignored " << ignored_count <<
" unknown or invalid custom uniform(s)\n";
2486 for (
const int index :
options.shader_pass_indices) {
2487 if (index < 0 || index >=
static_cast<int>(
shaders.size())) {
2488 throw std::runtime_error(
"shader pass index is out of range: " + std::to_string(index));
2492 for (
const std::string &name :
options.shader_pass_files) {
2494 if (shader.empty()) {
2495 throw std::runtime_error(
"shader pass file is not listed in the manifest: " + name);
2503 if (
options.playlist_file.empty()) {
2510 std::uniform_int_distribution<std::size_t> distribution(0,
playlist.size() - 1);
2519 const auto resolve = [&](std::string &path,
const fs::path &resource_subdirectory, std::string_view label) {
2520 if (path.empty() || fs::is_regular_file(path) || fs::path(path).is_absolute()) {
2524 if (resolved.empty()) {
2527 if (!resolved.empty()) {
2528 path = resolved.string();
2529 std::cout <<
"acmxvk: " << label <<
" (resource path): " << path <<
'\n';
2532 resolve(
options.playlist_file,
"playlists",
"playlist");
2533 resolve(
options.midi_map_file,
"midi-examples",
"MIDI map");
2535 if (
options.model_file.empty()) {
2537 std::cout <<
"acmxvk: 3D model (default): " <<
options.model_file <<
'\n';
2539 resolve(
options.model_file,
"models",
"3D model");
2542 std::string model_name = fs::path(
options.model_file).filename().string();
2543 std::transform(model_name.begin(), model_name.end(), model_name.begin(), [](
unsigned char character) { return static_cast<char>(std::tolower(character)); });
2544 if (!model_name.ends_with(
".obj") && !model_name.ends_with(
".mxmod") && !model_name.ends_with(
".mxmod.z")) {
2545 throw std::runtime_error(
"--model requires an .obj, .mxmod, or .mxmod.z file");
2547 if (!fs::is_regular_file(
options.model_file)) {
2548 throw std::runtime_error(
"3D model was not found: " +
options.model_file);
2550 constexpr std::uintmax_t MAX_MODEL_BYTES = 1024U * 1024U * 1024U;
2561 if (!fs::is_regular_file(font)) {
2562 throw std::runtime_error(
"overlay font was not found: " + font.string());
2564 const VkExtent2D preview_extent = getSwapchainExtent();
2565 const int preview_height = preview_extent.height > 0U ?
static_cast<int>(preview_extent.height) :
options.height;
2566 constexpr int FONT_HEIGHT_DIVISOR = 60;
2571 std::cout <<
"acmxvk: window-scaled output/HUD font " << font.string() <<
" at " <<
overlay_font_size <<
" points\n";
2575 constexpr std::size_t MAX_OVERLAY_CHARACTERS = 120;
2591 return passes !=
nullptr && !passes->empty() ?
"Post-shader" :
"Shader";
2596 if (passes ==
nullptr || passes->empty()) {
2600 std::string description =
"Multipass: ";
2601 for (std::size_t index = 0; index < passes->size(); ++index) {
2603 description +=
", ";
2605 description += (*passes)[index].filename().string();
2614 std::ostringstream description;
2620 const double finite_seconds = std::isfinite(seconds_value) ? seconds_value : 0.0;
2621 const auto elapsed =
static_cast<std::uint64_t
>(std::floor(std::max(0.0, finite_seconds)));
2622 const std::uint64_t hours = elapsed / 3600U;
2623 const std::uint64_t minutes = (elapsed / 60U) % 60U;
2624 const std::uint64_t seconds = elapsed % 60U;
2625 std::ostringstream text;
2626 text << std::setfill(
'0') << std::setw(2) << hours <<
':' << std::setw(2) << minutes <<
':' << std::setw(2) << seconds;
2631 SDL_Window *window = getSDLWindow();
2632 if (window ==
nullptr) {
2636 const auto now = std::chrono::steady_clock::now();
2637 constexpr auto UPDATE_INTERVAL = std::chrono::milliseconds(500);
2643 const bool recording =
writer.is_open() ||
options.png_output;
2654 std::ostringstream title;
2656 title <<
"ACMXVK - Graphics Mode - " <<
formatHudTime(elapsed_seconds) <<
" [" << displayed_frames <<
" frames]";
2660 if (total_frames > 0U) {
2661 title << total_frames;
2665 title <<
"] - " <<
formatHudTime(elapsed_seconds) <<
" - Video Mode";
2667 title <<
"ACMXVK - Capture Mode - " <<
formatHudTime(elapsed_seconds) <<
" [" << displayed_frames <<
" frames]";
2671 title <<
" (Recording)";
2673 constexpr double BYTES_PER_MEGABYTE = 1024.0 * 1024.0;
2674 const double file_size_mb =
static_cast<double>(
writer.get_bytes_written()) / BYTES_PER_MEGABYTE;
2675 title <<
" [File: " << std::fixed << std::setprecision(2) << file_size_mb <<
" MB]";
2676 const std::string bitrate = format_bitrate(
writer.get_bytes_written(), elapsed_seconds);
2677 if (!bitrate.empty()) {
2678 title <<
" [Bitrate: " << bitrate <<
']';
2682 title <<
" (Preview)";
2685 const std::string text = title.str();
2686 SDL_SetWindowTitle(window, text.c_str());
2694 std::uint64_t expected_frames = 0U;
2696 const auto duration_frames =
static_cast<std::uint64_t
>(std::ceil(
options.duration *
recording_fps));
2697 expected_frames = std::max<std::uint64_t>(1U, duration_frames);
2698 }
else if (
options.duration > 0.0) {
2699 const auto duration_frames =
static_cast<std::uint64_t
>(std::ceil(
options.duration *
recording_fps));
2700 expected_frames = std::max<std::uint64_t>(1U, duration_frames);
2704 if (expected_frames == 0U) {
2705 expected_frames = source_frames;
2707 expected_frames = std::min(expected_frames, source_frames);
2710 if (complete && expected_frames == 0U) {
2714 const auto now = std::chrono::steady_clock::now();
2716 if (expected_frames > 0U) {
2717 const std::uint64_t processed_frames = complete ? expected_frames : std::min(
output_frame_count, expected_frames);
2718 percent =
static_cast<int>((
static_cast<double>(processed_frames) /
static_cast<double>(expected_frames)) * 100.0);
2720 percent = std::min(percent, 99);
2726 if (!complete && !percent_changed && !time_elapsed) {
2732 const std::uint64_t processed_frames = complete && expected_frames > 0U ? expected_frames :
output_frame_count;
2733 const std::uint64_t written_frames =
writer.is_open() ?
static_cast<std::uint64_t
>(std::max<std::int64_t>(0,
writer.get_frame_count())) :
png_frame_count;
2734 const double elapsed_seconds =
static_cast<double>(processed_frames) /
recording_fps;
2736 const bool estimate_available = expected_frames > 0U && processed_frames > 0U;
2737 double estimated_remaining_seconds = 0.0;
2738 if (estimate_available && !complete) {
2739 const double average_seconds_per_frame = wall_elapsed_seconds /
static_cast<double>(processed_frames);
2740 estimated_remaining_seconds = average_seconds_per_frame *
static_cast<double>(expected_frames - processed_frames);
2743 std::cout <<
"acmxvk: [";
2745 std::cout << std::setw(3) << percent <<
'%';
2749 std::cout <<
"] Frame " << processed_frames <<
'/';
2750 if (expected_frames > 0U) {
2751 std::cout << expected_frames;
2755 std::cout <<
" | Written: " << written_frames <<
" | Time: " <<
formatHudTime(elapsed_seconds) <<
" | Elapsed: " <<
formatHudTime(wall_elapsed_seconds) <<
" | Estimated: ";
2756 if (estimate_available) {
2759 std::cout <<
"--:--:--";
2762 constexpr double BYTES_PER_MEGABYTE = 1024.0 * 1024.0;
2763 const std::uint64_t bytes_written =
writer.get_bytes_written();
2764 const double file_size_mb =
static_cast<double>(bytes_written) / BYTES_PER_MEGABYTE;
2765 std::ostringstream size_text;
2766 size_text << std::fixed << std::setprecision(2) << file_size_mb;
2767 std::cout <<
" | Size: " << size_text.str() <<
" MB";
2768 const std::string bitrate = format_bitrate(bytes_written, elapsed_seconds);
2769 if (!bitrate.empty()) {
2770 std::cout <<
" | Bitrate: " << bitrate;
2773 std::cout <<
'\n' << std::flush;
2784 if (frame_index !=
nullptr) {
2785 *frame_index = index;
2791 double position = 0.0;
2798 return std::max(0.0, position);
2811 const auto now = std::chrono::steady_clock::now();
2812 const double elapsed = std::chrono::duration<double>(now -
hud_fps_last_tick).count();
2813 if (elapsed < 0.5) {
2826 const auto interval = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(1.0 /
options.requested_fps));
2827 const auto now = std::chrono::steady_clock::now();
2850 const auto now = std::chrono::steady_clock::now();
2859 if (elapsed < 1.0) {
2869 std::ostringstream status;
2870 status <<
"acmxvk: camera delivery: " << std::fixed << std::setprecision(1) <<
camera_delivered_fps <<
" FPS measured";
2874 std::cout << status.str() <<
'\n';
2885 const SDL_Color shader_color{0U, 96U, 255U, 255U};
2888 shader +=
" [locked]";
2893 const SDL_Color crossfade_color{255U, 192U, 0U, 255U};
2894 std::ostringstream crossfade_status;
2896 printPreviewText(
clipOverlayText(crossfade_status.str()), 10, y, crossfade_color);
2900 if (!playlist_description.empty()) {
2901 const SDL_Color playlist_color{255U, 0U, 255U, 255U};
2902 printPreviewText(playlist_description, 10, y, playlist_color);
2907 if (passes !=
nullptr && !passes->empty()) {
2908 constexpr std::size_t MAX_HUD_PASS_LINES = 8U;
2909 const std::size_t displayed_passes = std::min(passes->size(), MAX_HUD_PASS_LINES);
2910 for (std::size_t index = 0; index < displayed_passes; ++index) {
2911 std::ostringstream pass;
2912 pass <<
"Pass [" << (index + 1) <<
'/' << passes->size() <<
"]: " << (*passes)[index].filename().string();
2916 if (displayed_passes < passes->size()) {
2917 const std::string remaining =
"Passes: +" + std::to_string(passes->size() - displayed_passes) +
" more";
2918 printPreviewText(remaining, 10, y, shader_color);
2924 const SDL_Color model_color{0U, 220U, 180U, 255U};
2925 std::string model_status =
model_3d_active ?
"Model: " :
"Model (2D bypass): ";
2926 model_status += fs::path(
options.model_file).filename().string();
2928 model_status +=
" [wave]";
2931 model_status +=
" [oscillate]";
2933 printPreviewText(
clipOverlayText(std::move(model_status)), 10, y, model_color);
2937#ifdef ACMXVK_WITH_DNN
2938 const SDL_Color dnn_color{64U, 220U, 128U, 255U};
2939 if (human_segmenter !=
nullptr) {
2940 printPreviewText(
options.human_background ?
"DNN: PP-HumanSeg [background]" :
"DNN: PP-HumanSeg [foreground]", 10, y, dnn_color);
2943 if (edge_detector !=
nullptr) {
2944 printPreviewText(
"DNN: DexiNed edge", 10, y, dnn_color);
2947 if (generic_onnx_processor !=
nullptr) {
2948 printPreviewText(
clipOverlayText(
"DNN: ONNX " + fs::path(
options.onnx_configuration).filename().string()), 10, y, dnn_color);
2955 const std::string track = fs::path(
file_audio_source->current_track_path()).filename().string();
2956 if (!track.empty()) {
2957 const SDL_Color track_color{255U, 0U, 255U, 255U};
2958 printPreviewText(
clipOverlayText(
"Track: " + track), 10, y, track_color);
2964#ifdef ACMXVK_WITH_CUDA
2965 if (gpu_filter_engine !=
nullptr) {
2966 const SDL_Color gpu_color{255U, 0U, 255U, 255U};
2967 printPreviewText(
clipOverlayText(
"GPU: " + gpu_filter_engine->active_filter_description()), 10, y, gpu_color);
2974 std::ostringstream status;
2976 if (
options.autopilot_random_timeout > 0) {
2981 status <<
" next=" << remaining <<
"f";
2985 const SDL_Color autopilot_color{0U, 255U, 255U, 255U};
2986 printPreviewText(
clipOverlayText(status.str()), 10, y, autopilot_color);
2990 const SDL_Color status_color{255U, 255U, 255U, 255U};
2999 const std::string bitrate = format_bitrate(
writer.get_bytes_written(), duration_seconds);
3000 if (!bitrate.empty()) {
3001 printPreviewText(
"Bitrate: " + bitrate, 10, y, status_color);
3005 std::ostringstream fps;
3006 fps <<
"Render: " << std::fixed << std::setprecision(1) <<
hud_display_fps <<
" FPS";
3007 printPreviewText(fps.str(), 10, y, status_color);
3010 std::ostringstream camera_fps;
3011 camera_fps <<
"Camera: ";
3015 camera_fps <<
"measuring...";
3017 printPreviewText(camera_fps.str(), 10, y, status_color);
3020 const SDL_Color hint_color{128U, 128U, 128U, 255U};
3021 printPreviewText(
"F9: Toggle overlay", 10, y, hint_color);
3030 constexpr int LEFT_MARGIN = 10;
3031 constexpr int TOP_MARGIN = 10;
3038 const SDL_Color filter_color{255U, 0U, 255U, 255U};
3048 if (!passes.empty()) {
3049 printText(passes, LEFT_MARGIN, y, filter_color);
3052#ifdef ACMXVK_WITH_CUDA
3053 if (gpu_filter_engine !=
nullptr) {
3054 printText(
clipOverlayText(
"GPU: " + gpu_filter_engine->active_filter_description()), LEFT_MARGIN, y, filter_color);
3061 const SDL_Color watermark_color{
options.watermark_color[0],
options.watermark_color[1],
options.watermark_color[2], 255U};
3067 if (!std::isfinite(value) || value <= 0.0 || value >
static_cast<double>(std::numeric_limits<std::uint32_t>::max())) {
3070 const auto fourcc =
static_cast<std::uint32_t
>(std::llround(value));
3071 std::string name(4,
' ');
3072 for (std::size_t index = 0; index < name.size(); ++index) {
3073 const auto byte =
static_cast<unsigned char>((fourcc >> (index * 8U)) & 0xffU);
3074 if (!std::isprint(
byte)) {
3077 name[index] =
static_cast<char>(byte);
3083#ifdef ACMXVK_WITH_STABLE_DIFFUSION
3088#ifdef ACMXVK_WITH_DEEP_DREAM
3093#ifdef ACMXVK_WITH_DNN
3094 return edge_detector !=
nullptr || human_segmenter !=
nullptr || generic_onnx_processor !=
nullptr;
3101#ifdef ACMXVK_WITH_DEEP_DREAM
3106 double timeline = 0.0;
3110 if (!std::isfinite(timeline) || timeline < 0.0) {
3119 const auto period =
static_cast<std::uint64_t
>(std::floor(timeline /
options.random_dream_interval));
3125 std::uniform_int_distribution<int> iterations(1, 3);
3126 std::uniform_real_distribution<double> strength(0.01, 0.05);
3127 std::uniform_real_distribution<double> zoom(0.985, 1.015);
3128 std::uniform_real_distribution<double> rotation_magnitude(0.5, 3.0);
3129 std::uniform_real_distribution<double> octave_scale(1.2, 1.6);
3130 std::uniform_int_distribution<int> rotation_direction(0, 1);
3131 std::uniform_int_distribution<int> octaves(1, 8);
3132 std::uniform_int_distribution<int> jitter(0, 4);
3133 std::uniform_int_distribution<int> smoothing(0, 3);
3134 static constexpr std::array<int, 4> RANDOM_DIMENSIONS = {256, 384, 512, 640};
3135 std::uniform_int_distribution<std::size_t> dimension(0, RANDOM_DIMENSIONS.size() - 1);
3137 if (!
options.dream_iterations_specified) {
3140 if (!
options.dream_strength_specified) {
3143 if (!
options.dream_zoom_specified) {
3146 if (!
options.dream_rotation_specified) {
3150 if (!
options.dream_size_specified) {
3153 if (!
options.dream_octaves_specified) {
3156 if (!
options.dream_octave_scale_specified) {
3159 if (!
options.dream_jitter_specified) {
3162 if (!
options.dream_smoothing_specified) {
3166 std::cout <<
"acmxvk: random dream settings: iterations " <<
options.dream_iterations <<
", strength " <<
options.dream_strength <<
", zoom " <<
options.dream_zoom <<
", rotation " <<
options.dream_rotation <<
", octaves " <<
options.dream_octaves <<
", octave scale " <<
options.dream_octave_scale <<
", size " <<
options.dream_size <<
", jitter " <<
options.dream_jitter <<
", smoothing " <<
options.dream_smoothing <<
'\n';
3171#ifdef ACMXVK_WITH_DEEP_DREAM
3175 if (rgba.type() == CV_16UC4) {
3176 cv::Mat compatible = rgba16ToRgba8(rgba);
3178 std::cout <<
"acmxvk: Deep Dream uses an RGBA8 compatibility "
3179 "copy for HDR input\n";
3183 compatible.convertTo(rgba, CV_16UC4, 257.0);
3189 result =
deep_dream_model->apply_gradient_ascent(rgba,
dream::GradientAscentOptions{
options.dream_iterations,
static_cast<float>(
options.dream_strength),
static_cast<float>(
options.dream_feedback),
static_cast<float>(
options.dream_zoom),
static_cast<float>(
options.dream_rotation),
options.dream_size,
options.dream_channel,
options.dream_octaves,
static_cast<float>(
options.dream_octave_scale),
options.dream_jitter,
options.dream_smoothing});
3190 }
catch (
const std::exception &error) {
3203 static_cast<void>(rgba);
3208#ifdef ACMXVK_WITH_DEEP_DREAM
3209 std::cerr <<
"acmxvk: Deep Dream frame failed: " << message <<
"; disabling Deep Dream while keeping ACMXVK running\n";
3211#ifdef ACMXVK_WITH_MXVK_CUDA
3212 cuda_dream_rgba.release();
3216 options.gpu_filter_before_dream =
false;
3219 static_cast<void>(message);
3224#ifdef ACMXVK_WITH_DNN
3225 if (rgba.type() == CV_16UC4 && (human_segmenter !=
nullptr || edge_detector !=
nullptr || generic_onnx_processor !=
nullptr)) {
3226 cv::Mat compatible = rgba16ToRgba8(rgba);
3228 std::cout <<
"acmxvk: HDR increment 2: DNN preprocessing uses an "
3229 "RGBA8 compatibility copy before RGBA16 upload\n";
3233 compatible.convertTo(rgba, CV_16UC4, 257.0);
3236 if (human_segmenter !=
nullptr && !rgba.empty()) {
3238 cv::cvtColor(rgba, bgr, cv::COLOR_RGBA2BGR);
3239 const cv::Mat mask = human_segmenter->infer(bgr);
3241 throw std::runtime_error(
"PP-HumanSeg produced an empty person mask");
3243 const float black_point =
static_cast<float>(
options.human_black_point);
3244 const float white_point =
static_cast<float>(
options.human_white_point);
3245 if (
options.human_background) {
3248 std::vector<cv::Mat> overlay_channels;
3250 alpha.copyTo(overlay_channels[3]);
3253 const cv::Mat foreground =
dnn::isolateBody(bgr, mask, black_point, white_point);
3255 cv::subtract(bgr, foreground, background);
3256 cv::cvtColor(background, rgba, cv::COLOR_BGR2RGBA);
3258 const cv::Mat foreground =
dnn::isolateBody(bgr, mask, black_point, white_point);
3259 cv::cvtColor(foreground, rgba, cv::COLOR_BGR2RGBA);
3262 if (edge_detector !=
nullptr && !rgba.empty()) {
3266 cv::cvtColor(rgba, bgr, cv::COLOR_RGBA2BGR);
3267 edge_detector->process(bgr, edge);
3269 throw std::runtime_error(
"DexiNed produced an empty edge frame");
3271 if (edge.channels() == 1) {
3272 cv::cvtColor(edge, rgba, cv::COLOR_GRAY2RGBA);
3274 cv::cvtColor(edge, rgba, cv::COLOR_BGR2RGBA);
3276 }
catch (
const std::exception &error) {
3277 std::cerr <<
"acmxvk: edge inference failed; disabling DNN "
3279 << error.what() <<
'\n';
3280 edge_detector.reset();
3283 if (generic_onnx_processor !=
nullptr && !rgba.empty()) {
3287 cv::cvtColor(rgba, bgr, cv::COLOR_RGBA2BGR);
3288 generic_onnx_processor->process(bgr, processed);
3289 if (processed.empty()) {
3290 throw std::runtime_error(
"generic ONNX model produced an empty frame");
3292 if (processed.channels() == 1) {
3293 cv::cvtColor(processed, rgba, cv::COLOR_GRAY2RGBA);
3295 cv::cvtColor(processed, rgba, cv::COLOR_BGR2RGBA);
3297 }
catch (
const std::exception &error) {
3298 std::cerr <<
"acmxvk: generic ONNX inference failed; disabling "
3300 << error.what() <<
'\n';
3301 generic_onnx_processor.reset();
3305 static_cast<void>(rgba);
3310#ifdef ACMXVK_WITH_DNN
3324 human_overlay_sprite->updateHistoryTexture(upload.ptr(), upload.cols, upload.rows,
static_cast<int>(upload.step));
3329 if (!
options.graphic_file.empty()) {
3342 bool opened =
false;
3350 throw std::runtime_error(
"unable to open capture source: " + source);
3356#ifdef MXVK_WITH_FFMPEG_CAPTURE
3362 throw std::runtime_error(
"--gpu-filter-before-dream does not support HDR input");
3368 std::ostringstream timeline;
3369 timeline <<
"acmxvk: video timeline: " << std::fixed << std::setprecision(3) <<
video_source_fps <<
" FPS";
3373 timeline <<
", duration unavailable";
3375 std::cout << timeline.str() <<
'\n';
3377 std::cout <<
"acmxvk: HDR input metadata detected\n";
3380 std::cout <<
"acmxvk: HDR processing active: native "
3381 "RGBA16 input, RGBA16F effects/history, and "
3382 "normalized RGBA16 Vulkan readback\n";
3385 <<
" decoded to linear BT.2020 before effects and "
3386 "encoded after effects\n";
3388 std::cout <<
"acmxvk: HDR preview: presentation-only "
3389 "BT.2020-to-BT.709 SDR tone mapping active; "
3390 "Main10 recording remains unchanged\n";
3393 std::cerr <<
"acmxvk: HDR transfer " <<
video_hdr_info.color_transfer
3394 <<
" is not PQ or HLG; preserving transfer-encoded "
3395 "values through the precision path\n";
3398 std::cout <<
"acmxvk: HDR precision path unavailable because this "
3399 "build is not using MXVK FFmpeg capture; falling "
3404 std::cout <<
"acmxvk: source-FPS playback enabled at " <<
video_source_fps <<
" FPS; early frames wait and late frames are skipped\n";
3411 capture.set(cv::CAP_PROP_BUFFERSIZE, 1.0);
3414 const int requested_fourcc =
options.use_yuv ? cv::VideoWriter::fourcc(
'Y',
'U',
'Y',
'V') : cv::VideoWriter::fourcc(
'M',
'J',
'P',
'G');
3415 capture.set(cv::CAP_PROP_FOURCC,
static_cast<double>(requested_fourcc));
3416 if (
options.requested_fps > 0.0) {
3432 std::cout <<
" at an unreported frame rate";
3434 std::cout <<
", format=" << reported_fourcc <<
'\n';
3440 std::cerr <<
"acmxvk: camera mode warning: requested " <<
options.requested_fps <<
" FPS but driver reports " <<
camera_reported_fps <<
" FPS\n";
3442 const std::string requested_format =
options.use_yuv ?
"YUYV" :
"MJPG";
3443 if (reported_fourcc !=
"unknown" && reported_fourcc != requested_format) {
3444 std::cerr <<
"acmxvk: camera mode warning: requested " << requested_format <<
" but driver reports " << reported_fourcc <<
'\n';
3448 std::cout <<
"acmxvk: maximize FPS active: asynchronous camera "
3449 "capture, Vulkan render target "
3450 <<
options.requested_fps <<
" FPS\n";
3452 std::cout <<
"acmxvk: maximize FPS note: VSync may cap the "
3453 "render rate to the display refresh\n";
3460 int source_width =
options.width;
3461 int source_height =
options.height;
3466#ifdef MXVK_WITH_FFMPEG_CAPTURE
3467 if (using_ffmpeg_capture) {
3468 source_width = ffmpeg_capture.width();
3469 source_height = ffmpeg_capture.height();
3477 source_width =
static_cast<int>(std::lround(
capture.get(cv::CAP_PROP_FRAME_WIDTH)));
3478 source_height =
static_cast<int>(std::lround(
capture.get(cv::CAP_PROP_FRAME_HEIGHT)));
3481 if (source_width <= 0 || source_height <= 0) {
3486 std::swap(source_width, source_height);
3489 return {source_width, source_height};
3493 int render_width =
options.width;
3494 int render_height =
options.height;
3495 if (!
options.resolution_specified) {
3498 throw std::runtime_error(
"input source dimensions are outside the supported range");
3501 render_width = source_width;
3502 render_height = source_height;
3504 options.height = render_height;
3506 std::cout <<
"acmxvk: automatic output resolution: " << render_width <<
'x' << render_height <<
" from " << source_name;
3508 std::cout <<
" after input rotation";
3512 std::cout <<
"acmxvk: requested output resolution: " << render_width <<
'x' << render_height <<
'\n';
3514 setRenderExtent(
static_cast<std::uint32_t
>(render_width),
static_cast<std::uint32_t
>(render_height));
3517 std::cout <<
"acmxvk: headless output resolution: " << render_width <<
'x' << render_height <<
'\n';
3522 std::cout <<
"acmxvk: fullscreen presentation uses the display "
3523 "extent without changing the output resolution\n";
3527 SDL_Window *window = getSDLWindow();
3528 if (window ==
nullptr) {
3529 throw std::runtime_error(
"unable to configure preview without an SDL window");
3532 int preview_width = render_width;
3533 int preview_height = render_height;
3534 SDL_Rect usable_bounds{};
3535 SDL_DisplayID display = SDL_GetDisplayForWindow(window);
3537 display = SDL_GetPrimaryDisplay();
3539 if (display != 0 && SDL_GetDisplayUsableBounds(display, &usable_bounds) && usable_bounds.w > 0 && usable_bounds.h > 0) {
3540 constexpr double PREVIEW_DISPLAY_FRACTION = 0.9;
3541 const double width_scale = (
static_cast<double>(usable_bounds.w) * PREVIEW_DISPLAY_FRACTION) / render_width;
3542 const double height_scale = (
static_cast<double>(usable_bounds.h) * PREVIEW_DISPLAY_FRACTION) / render_height;
3543 const double preview_scale = std::min({1.0, width_scale, height_scale});
3544 preview_width = std::max(1,
static_cast<int>(std::lround(render_width * preview_scale)));
3545 preview_height = std::max(1,
static_cast<int>(std::lround(render_height * preview_scale)));
3548 const float render_aspect =
static_cast<float>(render_width) /
static_cast<float>(render_height);
3549 if (!SDL_SetWindowAspectRatio(window, render_aspect, render_aspect)) {
3550 std::cerr <<
"acmxvk: unable to lock preview aspect ratio: " << SDL_GetError() <<
'\n';
3552 if (!SDL_SetWindowSize(window, preview_width, preview_height)) {
3553 throw std::runtime_error(std::string(
"unable to apply preview resolution: ") + SDL_GetError());
3555 SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
3556 if (!SDL_SyncWindow(window)) {
3557 std::cerr <<
"acmxvk: window resize sync warning: " << SDL_GetError() <<
'\n';
3560 int actual_width = 0;
3561 int actual_height = 0;
3562 SDL_GetWindowSizeInPixels(window, &actual_width, &actual_height);
3563 std::cout <<
"acmxvk: preview resolution: " << actual_width <<
'x' << actual_height;
3564 if (preview_width != render_width || preview_height != render_height) {
3565 std::cout <<
" (" << render_width <<
'x' << render_height <<
" output, preview fitted to display)";
3571 if (
options.requested_fps > 0.0) {
3575 double source_fps = 0.0;
3576#ifdef MXVK_WITH_FFMPEG_CAPTURE
3577 if (using_ffmpeg_capture) {
3578 source_fps = ffmpeg_capture.fps();
3582 source_fps =
capture.get(cv::CAP_PROP_FPS);
3584 if (std::isfinite(source_fps) && source_fps > 0.0) {
3592#ifndef ACMXVK_WITH_TIFF
3594 std::cerr <<
"acmxvk: TIFF snapshots require a build configured "
3599#ifndef ACMXVK_WITH_WEBP
3601 std::cerr <<
"acmxvk: WebP snapshots require a build configured "
3610 std::cerr <<
"acmxvk: snapshot queue is full; request ignored\n";
3613 std::error_code error;
3614 const fs::path directory(
options.snapshot_directory);
3615 fs::create_directories(directory, error);
3616 if (error || !fs::is_directory(directory)) {
3617 std::cerr <<
"acmxvk: unable to create snapshot directory: " << directory.string() <<
'\n';
3625 setFrameReadbackEnabled(
true);
3636 const VkExtent2D extent = getRenderExtent();
3637 if (
options.resolution_specified) {
3649 const int png_interval = std::max(1,
options.generate_interval);
3651 if (png_interval > 1) {
3652 std::cout <<
" (every " << png_interval <<
"th frame)";
3658 EncodeOptions encode_options;
3659 encode_options.preset =
options.encode_preset;
3660 encode_options.tune =
options.encode_tune;
3661 encode_options.crf =
options.encode_crf;
3662 encode_options.bit_rate =
options.encode_bitrate;
3663 encode_options.codec =
options.encode_codec;
3664 encode_options.ffmpeg_options =
options.encode_params;
3665 encode_options.realtime =
options.encode_realtime;
3666 encode_options.block_when_full =
options.no_drop ||
options.fill_pts_gaps;
3670 throw std::runtime_error(
"HDR Main10 output requires even width and height");
3672 encode_options.hdr.enabled =
true;
3673 encode_options.hdr.color_primaries =
video_hdr_info.color_primaries;
3677 encode_options.hdr.mastering_display =
video_hdr_info.mastering_display;
3679 std::cout <<
"acmxvk: HDR output: HEVC Main10 with captured " << (
hdr_transfer_hlg ?
"BT.2020/HLG" :
"BT.2020/PQ") <<
" color metadata (software libx265)\n";
3682 if (
options.encode_bitrate > 0) {
3683 std::cout <<
"acmxvk: encoder rate control: target VBR " <<
options.encode_bitrate <<
" bits/s\n";
3685 std::cout <<
"acmxvk: encoder rate control: CRF/CQ " <<
options.encode_crf <<
'\n';
3689 throw std::runtime_error(
"unable to open output video: " +
options.output_file);
3693 if (
options.constant_frame_rate) {
3694 std::cout <<
"acmxvk: constant-frame-rate encoding active; rendered "
3695 "video frames use sequential output timestamps\n";
3698 std::cout <<
"acmxvk: PTS gap filling active; held frames will be "
3699 "duplicated for editing-compatible constant frame rate\n";
3702 std::cout <<
"acmxvk: recorded video audio disabled (--mute-output); "
3703 "reactivity and pass-through remain active\n";
3707 setFrameReadbackEnabled(
true);
3722 if (!request.continuous) {
3723 setFrameReadbackEnabled(
false);
3732 std::cerr <<
"acmxvk: received frame readback without queued metadata\n";
3738 if (request.snapshot) {
3745 job.
format = request.snapshot_format;
3749 if (request.continuous) {
3752 job.
rgba = std::move(rgba);
3756 std::cout <<
"acmxvk: queued " <<
SnapshotWriter::formatName(request.snapshot_format) <<
" snapshot: " << path.string() <<
'\n';
3763 std::uint8_t *output_pixels = rgba.data();
3765 const std::uint16_t *hdr_output_pixels = rgba16 !=
nullptr ? rgba16->data() :
nullptr;
3766 cv::Mat hdr_resized;
3768 const cv::Mat source(
static_cast<int>(height),
static_cast<int>(width), CV_8UC4, rgba.data());
3770 output_pixels = resized.ptr();
3771 if (rgba16 !=
nullptr) {
3772 const cv::Mat hdr_source(
static_cast<int>(height),
static_cast<int>(width), CV_16UC4,
const_cast<std::uint16_t *
>(rgba16->data()));
3774 hdr_output_pixels = hdr_resized.ptr<std::uint16_t>();
3778#ifdef ACMXVK_WITH_STABLE_DIFFUSION
3779 cv::Mat stable_diffusion_output;
3783 if (stable_diffusion_output.empty() || stable_diffusion_output.type() != CV_8UC4 || stable_diffusion_output.cols !=
recording_width || stable_diffusion_output.rows !=
recording_height) {
3784 throw std::runtime_error(
"Stable Diffusion returned an incompatible output frame");
3786 output_pixels = stable_diffusion_output.ptr<std::uint8_t>();
3792 throw std::runtime_error(
"HDR Main10 recording did not receive an RGBA16 "
3796 const auto write_sequential_frame = [
this](std::uint8_t *rgba_pixels,
const std::uint16_t *rgba16_pixels) {
3798 writer.write_hdr_rgba16(
const_cast<std::uint16_t *
>(rgba16_pixels));
3800 writer.write(rgba_pixels);
3809 write_sequential_frame(output_pixels, hdr_output_pixels);
3814 write_sequential_frame(output_pixels, hdr_output_pixels);
3824 }
else if (
options.fill_pts_gaps && !request.has_pts) {
3825 write_sequential_frame(output_pixels, hdr_output_pixels);
3826 }
else if (!
options.fill_pts_gaps) {
3828 if (request.has_pts) {
3829 writer.write_hdr_rgba16_at_pts(
const_cast<std::uint16_t *
>(hdr_output_pixels),
static_cast<std::int64_t
>(request.pts));
3831 writer.write_hdr_rgba16(
const_cast<std::uint16_t *
>(hdr_output_pixels));
3833 }
else if (request.has_pts) {
3834 writer.write_at_pts(output_pixels,
static_cast<std::int64_t
>(request.pts));
3836 writer.write(output_pixels);
3841 const int png_interval = std::max(1,
options.generate_interval);
3842 if ((
png_frame_count %
static_cast<std::uint64_t
>(png_interval)) == 0U) {
3844 if (png_interval > 1) {
3856 double output_duration = 0.0;
3857 if (request.has_pts) {
3858 output_duration =
static_cast<double>(request.pts + 1) /
recording_fps;
3859 }
else if (
writer.is_open()) {
3860 output_duration =
writer.get_duration();
3864 if (output_duration >=
options.duration) {
3872 const double maximum_bytes =
options.max_size_mb * 1024.0 * 1024.0;
3873 if (
static_cast<double>(
writer.get_bytes_written()) >= maximum_bytes) {
3874 std::cout <<
"acmxvk: maximum output size reached (" <<
options.max_size_mb <<
" MB)\n";
3883 std::cout <<
"acmxvk: HDR readback: normalized RGBA16 received from "
3884 "the final Vulkan HDR intermediate"
3885 << (
hdr_output_enabled ?
"; feeding MXWrite's HEVC Main10 encoder\n" :
"; converting to RGBA8 for snapshots/output\n");
3888 std::vector<std::uint8_t> rgba8 = tone_map_hdr_rgba16(rgba,
hdr_transfer_hlg);
3906 std::cout <<
"acmxvk: loaded 3D model: " <<
options.model_file <<
" (" <<
input_model.model().vertices().size() <<
" vertices, " <<
input_model.model().indexCount() <<
" indices; skybox camera centered; view rotation " << (
model_auto_rotate ?
"enabled" :
"disabled") <<
")\n";
3908 if (getDevice() != VK_NULL_HANDLE) {
3909 vkDeviceWaitIdle(getDevice());
3917 if (!ensureRenderResources()) {
3918 throw std::runtime_error(
"MXVK failed to initialize render resources");
3924 frame_sprite = createSprite(source_width, source_height);
3935 int history_width = source_width;
3936 int history_height = source_height;
3937 if (
options.stable_diffusion_upscale || !
options.stable_diffusion_upscale_model.empty()) {
3938 history_width =
options.stable_diffusion_width;
3939 history_height =
options.stable_diffusion_height;
3940 if (!
options.stable_diffusion_upscale_model.empty()) {
3941 history_width =
options.width;
3942 history_height =
options.height;
3945 std::swap(history_width, history_height);
3949 frame_sprite->enableHistoryTextureRgba16Float(history_width, history_height,
static_cast<uint32_t
>(
options.texture_cache_size));
3951 frame_sprite->enableHistoryTexture(history_width, history_height,
static_cast<uint32_t
>(
options.texture_cache_size));
3963 human_overlay_sprite->enableHistoryTexture(
static_cast<std::uint32_t
>(source_width),
static_cast<std::uint32_t
>(source_height), 1U);
3964 const cv::Mat transparent(source_height, source_width, CV_8UC4, cv::Scalar::all(0));
3965 human_overlay_sprite->updateHistoryTexture(transparent.ptr(), transparent.cols, transparent.rows,
static_cast<int>(transparent.step));
3970#ifdef ACMXVK_WITH_STABLE_DIFFUSION
3971 if (stable_diffusion_initialization_pending) {
3972 stable_diffusion_initial_frame_deferred =
true;
3981 std::cerr <<
"acmxvk: capture did not provide an initial frame\n";
4001 if (
options.cross_fade_duration <= 0.0 ||
frame_count == 0 || getDevice() == VK_NULL_HANDLE) {
4009 std::vector<std::uint8_t> captured;
4010 std::uint32_t captured_width = 0;
4011 std::uint32_t captured_height = 0;
4012 captureSnapshotPixels(captured, captured_width, captured_height);
4013 const VkExtent2D extent = getRenderExtent();
4014 if (captured.empty() || captured_width == 0U || captured_height == 0U || extent.width == 0U || extent.height == 0U) {
4015 throw std::runtime_error(
"the previous rendered frame is unavailable");
4018 cv::Mat captured_rgba(
static_cast<int>(captured_height),
static_cast<int>(captured_width), CV_8UC4, captured.data());
4019 cv::Mat previous_rgba;
4020 if (captured_width == extent.width && captured_height == extent.height) {
4021 previous_rgba = captured_rgba;
4023 const double captured_aspect =
static_cast<double>(captured_width) / captured_height;
4024 const double target_aspect =
static_cast<double>(extent.width) / extent.height;
4025 cv::Rect crop(0, 0,
static_cast<int>(captured_width),
static_cast<int>(captured_height));
4026 if (captured_aspect > target_aspect) {
4027 crop.width = std::max(1,
static_cast<int>(std::lround(captured_height * target_aspect)));
4028 crop.x = (
static_cast<int>(captured_width) - crop.width) / 2;
4029 }
else if (captured_aspect < target_aspect) {
4030 crop.height = std::max(1,
static_cast<int>(std::lround(captured_width / target_aspect)));
4031 crop.y = (
static_cast<int>(captured_height) - crop.height) / 2;
4033 cv::resize(captured_rgba(crop), previous_rgba, cv::Size(
static_cast<int>(extent.width),
static_cast<int>(extent.height)), 0.0, 0.0, cv::INTER_LINEAR);
4045 const cv::Mat linear_previous = decode_hdr_transfer(previous_rgba,
hdr_transfer_hlg);
4046 crossfade_previous_sprite->updateHistoryTextureRgba16(linear_previous.ptr<std::uint16_t>(),
static_cast<int>(extent.width),
static_cast<int>(extent.height),
static_cast<int>(linear_previous.step));
4048 crossfade_previous_sprite->updateHistoryTexture(previous_rgba.ptr(),
static_cast<int>(extent.width),
static_cast<int>(extent.height),
static_cast<int>(previous_rgba.step));
4054 }
catch (
const std::exception &error) {
4058 std::cerr <<
"acmxvk: crossfade snapshot unavailable: " << error.what() <<
"; switching immediately\n";
4066 double elapsed = 0.0;
4067 double video_timeline = 0.0;
4085 const auto count =
static_cast<std::ptrdiff_t
>(
CROSSFADE_NAMES.size());
4087 index = (index % count + count) % count;
4097 std::cout <<
"acmxvk: model scale " <<
model_scale <<
'\n';
4104 std::uniform_int_distribution<std::size_t> distribution(0,
CROSSFADE_NAMES.size() - 1);
4114 std::cout <<
"acmxvk: pause is available for video and graphic input\n";
4119 std::cout <<
"acmxvk: input pause " << (
input_paused ?
"enabled" :
"disabled") <<
'\n';
4124 std::cout <<
"acmxvk: freeze is available for video and graphic input\n";
4130 std::cout <<
"acmxvk: rendering freeze " << (
rendering_frozen ?
"enabled" :
"disabled") <<
'\n';
4135 std::cout <<
"acmxvk: shader time stepped to " <<
shader_time <<
'\n';
4140 if (std::abs(
options.time_speed) < 0.01) {
4143 std::cout <<
"acmxvk: shader time speed " <<
options.time_speed <<
'\n';
4147 SDL_Window *window = getSDLWindow();
4148 if (window ==
nullptr) {
4151 const bool fullscreen = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0;
4152 if (!SDL_SetWindowFullscreen(window, !fullscreen)) {
4153 std::cerr <<
"acmxvk: unable to toggle fullscreen: " << SDL_GetError() <<
'\n';
4156 std::cout <<
"acmxvk: fullscreen " << (!fullscreen ?
"enabled" :
"disabled") <<
'\n';
4160 if (
options.autopilot_random_timeout > 0) {
4161 std::uniform_int_distribution<int> distribution(4, std::max(4,
options.autopilot_random_timeout));
4176 double video_timeline = 0.0;
4177 std::uint64_t video_frame_index = 0U;
4196 std::cout <<
"acmxvk: " << (sequential ?
"sequential autopilot" :
"autopilot") <<
" requires playlist mode (press P first)\n";
4200 std::cout <<
"acmxvk: autopilot has no playlist entries\n";
4207 std::cout <<
"acmxvk: autopilot disabled\n";
4215 if (
options.autopilot_random_timeout <= 0 &&
options.autopilot_frames <= 0) {
4216 options.autopilot_frames = 300;
4219 std::cout <<
"acmxvk: " << (sequential ?
"sequential " :
"random ") <<
"autopilot enabled (";
4220 if (
options.autopilot_random_timeout > 0) {
4234 if (frame_advance < remaining) {
4245 std::uniform_int_distribution<std::size_t> distribution(0,
playlist.size() - 1);
4248 next = (next + 1) %
playlist.size();
4255 if (
options.autopilot_random_timeout > 0) {
4265 const auto count =
static_cast<std::ptrdiff_t
>(
shaders.size());
4267 auto index =
static_cast<std::ptrdiff_t
>(
shader_index) + direction;
4268 index = (index % count + count) % count;
4281 const auto count =
static_cast<std::ptrdiff_t
>(
playlist.size());
4283 auto index =
static_cast<std::ptrdiff_t
>(
playlist_index) + direction;
4284 index = (index % count + count) % count;
4293 std::vector<fs::path> pipeline;
4304 if (
options.stable_diffusion_upscale) {
4313 if (pipeline.empty()) {
4316 if (
options.human_background) {
4319 for (fs::path &shader : pipeline)
4330 const mxvk::ShaderModuleInfo module_info = mxvk::inspect_spirv(mxvk::load_spv(shader.string()));
4331 if (module_info.stage != mxvk::ShaderStage::Fragment || module_info.usesHistoryTexture || module_info.usesSpectrumTexture || module_info.usesSpectrumHistoryTexture) {
4338 if (getDevice() == VK_NULL_HANDLE) {
4341 vkDeviceWaitIdle(getDevice());
4342 detachPostProcessingShader();
4360 if (!direct_model_shader.empty()) {
4361 const auto selected = std::find(pipeline.begin(), pipeline.end(), direct_model_shader);
4362 if (selected != pipeline.end()) {
4363 pipeline.erase(selected);
4365 if (pipeline.empty()) {
4368 std::cout <<
"acmxvk: 3D texture effect: " << direct_model_shader.filename().string() <<
" [fragment, evaluated on model UVs]\n";
4370 std::cout <<
"acmxvk: 3D texture prepass: fragment/compute "
4371 "chain output mapped onto model UVs\n";
4377 if (pipeline.empty()) {
4381 std::vector<PostProcessingEffect> effects;
4382 effects.reserve(pipeline.size());
4384 for (std::size_t index = 0; index < pipeline.size(); ++index) {
4385 const fs::path &shader = pipeline[index];
4386 PostProcessingEffect effect{shader.string(), {1.0F, 1.0F, 1.0F, 0.0F},
false};
4400 effect.spectrumHistoryLayerCount =
static_cast<std::uint32_t
>(
options.audio_buffers);
4402 effects.push_back(effect);
4406 sprite->enableExtendedUBO();
4416 std::cout <<
"acmxvk: Vulkan shader pipeline (" << pipeline.size() <<
" passes):\n";
4417 for (std::size_t index = 0; index < pipeline.size(); ++index) {
4418 const bool compute = index < post_process_effect_stages.size() && post_process_effect_stages[index] == mxvk::ShaderStage::Compute;
4419 std::cout <<
" " << (index + 1) <<
": " << pipeline[index].filename().string() <<
" [" << (compute ?
"compute" :
"fragment") <<
"]\n";
4440 bool skipped =
false;
4441#ifdef MXVK_WITH_FFMPEG_CAPTURE
4442 if (using_ffmpeg_capture) {
4443 skipped = ffmpeg_capture.skip();
4461 setFrameReadbackEnabled(
false);
4467#ifdef MXVK_WITH_FFMPEG_CAPTURE
4468 if (using_ffmpeg_capture && ffmpeg_capture.seek_start()) {
4472 if (!ffmpeg_seek_repeat_logged) {
4473 std::cout <<
"acmxvk: video repeat: in-place FFmpeg seek; " << (ffmpeg_capture.using_hardware_decode() ?
"NVDEC decoder and CUDA device preserved\n" :
"software decoder preserved\n");
4474 ffmpeg_seek_repeat_logged =
true;
4478 std::cerr <<
"acmxvk: in-place FFmpeg repeat did not produce a "
4479 "frame; reopening the input\n";
4484 throw std::runtime_error(
"unable to restart video input: " +
options.input_file);
4491 if (!std::isfinite(rate) || rate <= 0.0) {
4495 std::uint64_t target_frame =
static_cast<std::uint64_t
>(std::floor(std::max(clock_seconds, 0.0) * rate));
4498 const double wait_seconds = next_frame_time - clock_seconds;
4499 if (wait_seconds > 0.0) {
4500 std::this_thread::sleep_for(std::chrono::duration<double>(wait_seconds));
4502 double updated_clock = 0.0;
4504 target_frame =
static_cast<std::uint64_t
>(std::floor(std::max(updated_clock, 0.0) * rate));
4512 for (std::uint64_t frame = 0; frame < frames_to_advance; ++frame) {
4513 const bool discard = frame + 1 < frames_to_advance;
4528 std::cout <<
"acmxvk: media-clock synchronization active; "
4529 "late video frames will be skipped and encoded "
4530 "with timeline PTS\n";
4537#ifdef MXVK_WITH_FFMPEG_CAPTURE
4538 if (ffmpeg_capture.is_open()) {
4539 ffmpeg_capture.close();
4541 using_ffmpeg_capture =
false;
4551#ifdef MXVK_WITH_FFMPEG_CAPTURE
4552 if (ffmpeg_capture.open(
options.input_file,
options.cuda_device)) {
4553 using_ffmpeg_capture =
true;
4555 std::cout <<
"acmxvk: video capture: FFmpeg ";
4556 if (ffmpeg_capture.using_hardware_decode()) {
4557 std::cout <<
"with CUDA/NVDEC";
4558 if (ffmpeg_capture.hardware_decode_device() >= 0) {
4559 std::cout <<
" on device " << ffmpeg_capture.hardware_decode_device();
4563 std::cout <<
"software decode\n";
4571 std::cout <<
"acmxvk: video capture: OpenCV fallback\n";
4580#ifdef MXVK_WITH_FFMPEG_CAPTURE
4581 if (using_ffmpeg_capture) {
4586 if (!ffmpeg_capture.readRgba16(ffmpeg_rgba16, width, height, pitch,
false) || ffmpeg_rgba16.empty() || width <= 0 || height <= 0 || pitch < width * 8) {
4589 rgba = cv::Mat(height, width, CV_16UC4, ffmpeg_rgba16.data(),
static_cast<std::size_t
>(pitch));
4592 if (!ffmpeg_capture.readRgba(ffmpeg_rgba, width, height, pitch,
false) || ffmpeg_rgba.empty() || width <= 0 || height <= 0 || pitch < width * 4) {
4595 rgba = cv::Mat(height, width, CV_8UC4, ffmpeg_rgba.data(),
static_cast<std::size_t
>(pitch));
4599 return capture.readRgba(rgba,
false);
4606 for (uint32_t layer = 0; layer <
frame_sprite->getHistoryLayerCount(); ++layer) {
4612 std::cout <<
"acmxvk: initialized " <<
frame_sprite->getHistoryLayerCount() <<
" Vulkan history-cache layers (delay " <<
options.cache_delay <<
")\n";
4616#ifdef ACMXVK_WITH_CUDA
4617 if (gpu_filter_engine !=
nullptr && rgba.type() == CV_8UC4) {
4618 updateFilteredCudaHistoryFrame();
4622 if (rgba.type() == CV_16UC4) {
4624 const cv::Mat linear_history = decode_hdr_transfer(rgba,
hdr_transfer_hlg);
4625 frame_sprite->updateHistoryTextureRgba16(linear_history.ptr<std::uint16_t>(), linear_history.cols, linear_history.rows,
static_cast<int>(linear_history.step));
4628 frame_sprite->updateHistoryTextureRgba16(rgba.ptr<uint16_t>(), rgba.cols, rgba.rows,
static_cast<int>(rgba.step));
4631 frame_sprite->updateHistoryTexture(rgba.ptr(), rgba.cols, rgba.rows,
static_cast<int>(rgba.step));
4640 if (!std::isfinite(rate) || rate <= 0.0) {
4643 const auto interval = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(
static_cast<double>(
options.cache_delay + 1) / rate));
4644 const auto now = std::chrono::steady_clock::now();
4654 bool history_updated =
false;
4655#if defined(ACMXVK_WITH_CUDA) && defined(ACMXVK_WITH_DEEP_DREAM) && defined(ACMXVK_WITH_MXVK_CUDA)
4656 if (
options.gpu_filter_before_dream &&
deep_dream_model !=
nullptr && gpu_filter_engine !=
nullptr && !cuda_dream_rgba.empty()) {
4658 updateCudaHistoryFrame(history_input, gpu_filter_engine->stream());
4659 history_updated =
true;
4662#ifdef ACMXVK_WITH_CUDA
4663 if (!history_updated && gpu_filter_engine !=
nullptr) {
4664 updateFilteredCudaHistoryFrame();
4665 history_updated =
true;
4670 history_updated =
true;
4672 if (!history_updated) {
4682#ifdef ACMXVK_WITH_MXVK_CUDA
4683 void MainWindow::updateModelTextureCuda(
const cv::cuda::GpuMat &rgba, cv::cuda::Stream &source_stream) {
4684 if (!model_initialized) {
4687 if (input_model.updatePrimaryTextureCuda(rgba, source_stream)) {
4691 rgba.download(cuda_model_fallback_rgba, source_stream);
4692 source_stream.waitForCompletion();
4693 if (!cuda_model_fallback_logged) {
4694 std::cerr <<
"acmxvk: direct CUDA model-texture upload "
4695 "unavailable; using host staging\n";
4696 cuda_model_fallback_logged =
true;
4698 if (!input_model.updatePrimaryTexture(cuda_model_fallback_rgba.ptr(), cuda_model_fallback_rgba.cols, cuda_model_fallback_rgba.rows,
static_cast<int>(cuda_model_fallback_rgba.step))) {
4699 throw std::runtime_error(
"MXVK could not update the 3D model texture");
4703 void MainWindow::updateCudaHistoryFrame(
const cv::cuda::GpuMat &rgba, cv::cuda::Stream &source_stream) {
4704 if (frame_sprite->updateHistoryTextureCuda(rgba, source_stream)) {
4708 rgba.download(cuda_history_fallback_rgba, source_stream);
4709 source_stream.waitForCompletion();
4710 if (!cuda_history_fallback_logged) {
4711 std::cerr <<
"acmxvk: direct CUDA history upload unavailable; "
4712 "using a host-staging fallback\n";
4713 cuda_history_fallback_logged =
true;
4715 frame_sprite->updateHistoryTexture(cuda_history_fallback_rgba.ptr(), cuda_history_fallback_rgba.cols, cuda_history_fallback_rgba.rows,
static_cast<int>(cuda_history_fallback_rgba.step));
4718#ifdef ACMXVK_WITH_CUDA
4719 void MainWindow::updateFilteredCudaHistoryFrame() { updateCudaHistoryFrame(gpu_filter_engine->output(), gpu_filter_engine->stream()); }
4722 void MainWindow::initializeCudaHistory(
const cv::cuda::GpuMat &rgba, cv::cuda::Stream &source_stream,
bool filtered) {
4723 if (!historyCacheEnabled() || history_initialized) {
4726 for (uint32_t layer = 0; layer < frame_sprite->getHistoryLayerCount(); ++layer) {
4727 updateCudaHistoryFrame(rgba, source_stream);
4729 history_initialized =
true;
4730 history_delay_counter = 0;
4731 camera_history_clock_started =
false;
4732 std::cout <<
"acmxvk: initialized " << frame_sprite->getHistoryLayerCount() << (filtered ?
" filtered" :
" NVDEC") <<
" Vulkan history-cache layers (delay " << options.cache_delay <<
")\n";
4735#ifdef ACMXVK_WITH_CUDA
4736 void MainWindow::uploadInputFrame(
const cv::cuda::GpuMat &rgba, cv::cuda::Stream &source_stream) {
4737 if (!gpu_filter_engine->process(rgba, source_stream)) {
4738 throw std::runtime_error(
"acidcam-gpu rejected the CUDA RGBA input frame");
4740 if (!frame_sprite->updateTextureCuda(gpu_filter_engine->output(), gpu_filter_engine->stream())) {
4741 throw std::runtime_error(
"MXVK could not upload the CUDA-filtered frame");
4743 updateModelTextureCuda(gpu_filter_engine->output(), gpu_filter_engine->stream());
4747 [[nodiscard]]
const cv::cuda::GpuMat &MainWindow::rotateCudaFrame(
const cv::cuda::GpuMat &rgba, cv::cuda::Stream &source_stream) {
4748 switch (options.frame_rotation) {
4752 cv::cuda::transpose(rgba, cuda_rotation_transpose, source_stream);
4753 cv::cuda::flip(cuda_rotation_transpose, cuda_rotated_rgba, 1, source_stream);
4756 cv::cuda::flip(rgba, cuda_rotated_rgba, -1, source_stream);
4759 cv::cuda::transpose(rgba, cuda_rotation_transpose, source_stream);
4760 cv::cuda::flip(cuda_rotation_transpose, cuda_rotated_rgba, 0, source_stream);
4763 return cuda_rotated_rgba;
4768#ifdef ACMXVK_WITH_CUDA
4769 if (gpu_filter_engine !=
nullptr && rgba.type() == CV_8UC4) {
4770 if (!gpu_filter_engine->process(rgba)) {
4771 throw std::runtime_error(
"acidcam-gpu rejected the RGBA input frame");
4773 if (!
frame_sprite->updateTextureCuda(gpu_filter_engine->output(), gpu_filter_engine->stream())) {
4774 throw std::runtime_error(
"MXVK could not upload the CUDA-filtered frame");
4776 updateModelTextureCuda(gpu_filter_engine->output(), gpu_filter_engine->stream());
4780 std::cout <<
"acmxvk: HDR increment 2: bypassing RGBA8 CUDA filters to "
4781 "preserve the 16-bit source texture\n";
4785 if (rgba.type() == CV_16UC4) {
4786 frame_sprite->updateTextureRgba16(rgba.ptr<std::uint16_t>(), rgba.cols, rgba.rows,
static_cast<int>(rgba.step));
4788 std::cout <<
"acmxvk: uploaded first RGBA16 HDR source frame "
4793 frame_sprite->updateTexture(rgba.ptr(), rgba.cols, rgba.rows,
static_cast<int>(rgba.step));
4796 cv::Mat model_compatible;
4797 const cv::Mat *model_input = &rgba;
4799 model_compatible = rgba16ToRgba8(rgba);
4800 model_input = &model_compatible;
4802 if (
model_initialized && !
input_model.updatePrimaryTexture(model_input->ptr(), model_input->cols, model_input->rows,
static_cast<int>(model_input->step))) {
4803 throw std::runtime_error(
"MXVK could not update the 3D model texture");
4816 cv::cvtColor(bgr, rgba, cv::COLOR_BGR2RGBA);
4828#ifdef ACMXVK_WITH_CUDA
4829 if (gpu_filter_engine !=
nullptr) {
4830 initializeCudaHistory(gpu_filter_engine->output(), gpu_filter_engine->stream(),
true);
4839#if defined(ACMXVK_WITH_MXVK_CUDA) && defined(ACMXVK_WITH_DEEP_DREAM)
4840 [[nodiscard]]
bool MainWindow::readCudaDeepDreamFrame() {
4841 cv::cuda::Stream *capture_stream =
nullptr;
4842#ifdef MXVK_WITH_FFMPEG_CAPTURE
4843 if (using_ffmpeg_capture) {
4844 if (!ffmpeg_capture.readGpuRgba(cuda_input_rgba, ffmpeg_cuda_stream,
false)) {
4847 capture_stream = &ffmpeg_cuda_stream;
4851 if (!capture.readGpuRgba(cuda_input_rgba,
false)) {
4854 capture_stream = &capture.cudaStream();
4857 const cv::cuda::GpuMat *dream_input = &cuda_input_rgba;
4858 cv::cuda::Stream *dream_stream = capture_stream;
4859 bool filtered =
false;
4860 const bool filter_before_dream = options.gpu_filter_before_dream;
4861#ifdef ACMXVK_WITH_CUDA
4862 if (filter_before_dream && gpu_filter_engine !=
nullptr) {
4863 if (!gpu_filter_engine->process(cuda_input_rgba, *capture_stream)) {
4864 throw std::runtime_error(
"acidcam-gpu rejected the pre-dream CUDA frame");
4866 dream_input = &gpu_filter_engine->output();
4867 dream_stream = &gpu_filter_engine->stream();
4872 updateRandomDreamSettings();
4873 dream::GradientAscentResult dream_result;
4874 const cv::cuda::GpuMat *processed_input = dream_input;
4875 bool dream_processed =
false;
4877 dream_result =
deep_dream_model->apply_gradient_ascent_cuda(*dream_input, cuda_dream_rgba, *dream_stream, dream::GradientAscentOptions{options.dream_iterations,
static_cast<float>(options.dream_strength),
static_cast<float>(options.dream_feedback),
static_cast<float>(options.dream_zoom),
static_cast<float>(options.dream_rotation), options.dream_size, options.dream_channel, options.dream_octaves,
static_cast<float>(options.dream_octave_scale), options.dream_jitter, options.dream_smoothing});
4878 dream_processed = std::isfinite(dream_result.mean_pixel_change);
4879 if (dream_processed) {
4880 processed_input = &cuda_dream_rgba;
4882 handleDeepDreamRuntimeError(
"Deep Dream returned a non-finite CUDA frame");
4884 }
catch (
const std::exception &error) {
4885 handleDeepDreamRuntimeError(error.what());
4888 const cv::cuda::GpuMat &render_input = rotateCudaFrame(*processed_input, *dream_stream);
4889 const cv::cuda::GpuMat *final_input = &render_input;
4890 cv::cuda::Stream *final_stream = dream_stream;
4891#ifdef ACMXVK_WITH_CUDA
4892 if (!filtered && gpu_filter_engine !=
nullptr) {
4893 if (!gpu_filter_engine->process(render_input, *dream_stream)) {
4894 throw std::runtime_error(
"acidcam-gpu rejected the post-dream CUDA frame");
4896 final_input = &gpu_filter_engine->output();
4897 final_stream = &gpu_filter_engine->stream();
4901 if (!frame_sprite->updateTextureCuda(*final_input, *final_stream)) {
4902 final_input->download(cuda_input_fallback_rgba, *final_stream);
4903 final_stream->waitForCompletion();
4904 if (!cuda_input_fallback_logged) {
4905 std::cerr <<
"acmxvk: direct Deep Dream/Vulkan upload "
4906 "unavailable; using host staging\n";
4907 cuda_input_fallback_logged =
true;
4909 frame_sprite->updateTexture(cuda_input_fallback_rgba.ptr(), cuda_input_fallback_rgba.cols, cuda_input_fallback_rgba.rows,
static_cast<int>(cuda_input_fallback_rgba.step));
4911 updateModelTextureCuda(*final_input, *final_stream);
4913 if (dream_processed && !dream_processing_logged) {
4914 std::cout <<
"acmxvk: Deep Dream CUDA working frame: " << dream_result.processed_width <<
'x' << dream_result.processed_height <<
" -> " << render_input.cols <<
'x' << render_input.rows <<
" Vulkan texture (" << dream_result.processed_octaves <<
" octave(s))\n";
4915 dream_processing_logged =
true;
4917 if (!cuda_input_path_logged) {
4918 std::cout <<
"acmxvk: CUDA interop path active: capture/NVDEC -> ";
4919 if (filter_before_dream && filtered) {
4920 std::cout <<
"acidcam-gpu -> ";
4922 if (dream_processed) {
4923 std::cout <<
"LibTorch Deep Dream -> ";
4926 std::cout <<
"CUDA rotation -> ";
4928 if (!filter_before_dream && filtered) {
4929 std::cout <<
"acidcam-gpu -> ";
4931 std::cout <<
"Vulkan texture";
4932 if (cuda_input_fallback_logged) {
4933 std::cout <<
" (host-staging upload fallback)";
4936 cuda_input_path_logged =
true;
4939 const bool history_was_initialized = history_initialized;
4940 initializeCudaHistory(*final_input, *final_stream, filtered);
4941 if (source_kind != SourceKind::Camera && history_was_initialized && ++history_delay_counter > options.cache_delay) {
4942 updateCudaHistoryFrame(*final_input, *final_stream);
4943 history_delay_counter = 0;
4945 if (source_kind == SourceKind::Camera) {
4946 camera_history_clock_started =
false;
4956#if defined(ACMXVK_WITH_MXVK_CUDA) && defined(ACMXVK_WITH_DEEP_DREAM)
4958#ifdef ACMXVK_WITH_DNN
4959 && edge_detector ==
nullptr && human_segmenter ==
nullptr && generic_onnx_processor ==
nullptr
4961#ifdef ACMXVK_WITH_STABLE_DIFFUSION
4965 return readCudaDeepDreamFrame();
4968#ifdef ACMXVK_WITH_CUDA
4970 cv::cuda::Stream *capture_stream =
nullptr;
4971#ifdef MXVK_WITH_FFMPEG_CAPTURE
4972 if (using_ffmpeg_capture) {
4973 if (!ffmpeg_capture.readGpuRgba(cuda_input_rgba, ffmpeg_cuda_stream,
false)) {
4976 capture_stream = &ffmpeg_cuda_stream;
4980 if (!
capture.readGpuRgba(cuda_input_rgba,
false)) {
4983 capture_stream = &
capture.cudaStream();
4985 const cv::cuda::GpuMat &filter_input = rotateCudaFrame(cuda_input_rgba, *capture_stream);
4987 if (!cuda_input_path_logged) {
4988#ifdef MXVK_WITH_FFMPEG_CAPTURE
4989 if (using_ffmpeg_capture) {
4990 std::cout <<
"acmxvk: CUDA input path active: FFmpeg " << (ffmpeg_capture.using_hardware_decode() ?
"NVDEC -> CUDA RGBA -> " :
"software decode -> CUDA upload -> ");
4994 std::cout <<
"acmxvk: CUDA input path active: MXVK capture -> ";
4997 std::cout <<
"CUDA rotation -> ";
4999 std::cout <<
"acidcam-gpu temporal buffer -> Vulkan texture\n";
5000 cuda_input_path_logged =
true;
5003 initializeCudaHistory(gpu_filter_engine->output(), gpu_filter_engine->stream(),
true);
5005 updateFilteredCudaHistoryFrame();
5011#ifdef ACMXVK_WITH_MXVK_CUDA
5012#if defined(MXVK_WITH_FFMPEG_CAPTURE)
5014 if (!ffmpeg_capture.readGpuRgba(cuda_input_rgba, ffmpeg_cuda_stream,
false)) {
5017 const cv::cuda::GpuMat &render_input = rotateCudaFrame(cuda_input_rgba, ffmpeg_cuda_stream);
5018 if (!
frame_sprite->updateTextureCuda(render_input, ffmpeg_cuda_stream)) {
5019 render_input.download(cuda_input_fallback_rgba, ffmpeg_cuda_stream);
5020 ffmpeg_cuda_stream.waitForCompletion();
5021 if (!cuda_input_fallback_logged) {
5022 std::cerr <<
"acmxvk: direct NVDEC/Vulkan upload unavailable; "
5023 "using host staging\n";
5024 cuda_input_fallback_logged =
true;
5026 frame_sprite->updateTexture(cuda_input_fallback_rgba.ptr(), cuda_input_fallback_rgba.cols, cuda_input_fallback_rgba.rows,
static_cast<int>(cuda_input_fallback_rgba.step));
5028 updateModelTextureCuda(render_input, ffmpeg_cuda_stream);
5029 if (!cuda_input_path_logged) {
5030 std::cout <<
"acmxvk: CUDA input path active: FFmpeg "
5031 "NVDEC -> CUDA RGBA -> ";
5033 std::cout <<
"CUDA rotation -> ";
5035 std::cout <<
"Vulkan texture";
5036 if (cuda_input_fallback_logged) {
5037 std::cout <<
" (host-staging fallback)";
5040 cuda_input_path_logged =
true;
5043 initializeCudaHistory(render_input, ffmpeg_cuda_stream,
false);
5045 updateCudaHistoryFrame(render_input, ffmpeg_cuda_stream);
5054 if (!requires_host_frame
5055#ifdef MXVK_WITH_FFMPEG_CAPTURE
5056 && !using_ffmpeg_capture
5088 const auto now = std::chrono::steady_clock::now();
5090 const float wall_delta = std::chrono::duration<float>(now -
previous_frame).count();
5094 double video_timeline = 0.0;
5096 float delta = wall_delta;
5097 if (video_timeline_available) {
5099 std::cout <<
"acmxvk: shader clock: decoded video timeline; "
5100 "effects are independent of processing speed\n";
5114 }
else if (
options.normalized_time) {
5117 const float frame_rate = video_timeline_available ?
static_cast<float>(
video_source_fps) : (delta > 0.0F ? 1.0F / delta : 0.0F);
5118 float raw_audio_amplitude = 0.0F;
5119 float audio_sensitivity = 1.0F;
5120 float audio_amplitude = 0.0F;
5121 float audio_frequency = 0.0F;
5122 float audio_peak = 0.0F;
5123 float audio_rms = 0.0F;
5124 float audio_smooth = 0.0F;
5125 float audio_low = 0.0F;
5126 float audio_mid = 0.0F;
5127 float audio_high = 0.0F;
5128 float audio_sample_rate = 44100.0F;
5130 std::vector<float> spectrum_values;
5132 double source_audio_time = 0.0;
5135 if (source_audio_timeline) {
5141 std::cout <<
"acmxvk: audio source finished, stopping "
5142 "(--audio-trunc)\n";
5149 raw_audio_amplitude = metrics.
amplitude;
5152 const float sense = audio_sensitivity * 4.0F * warmup;
5153 audio_amplitude = raw_audio_amplitude * audio_sensitivity *
static_cast<float>(
options.time_speed) * delta_scale * warmup;
5155 audio_peak = std::sqrt(std::max(metrics.
peak, 0.0F)) * sense;
5156 audio_rms = std::sqrt(std::max(metrics.
rms, 0.0F)) * sense;
5157 audio_smooth = std::sqrt(std::max(metrics.
smooth, 0.0F)) * sense;
5158 audio_low = std::sqrt(std::max(metrics.
low, 0.0F)) * sense;
5159 audio_mid = std::sqrt(std::max(metrics.
mid, 0.0F)) * sense;
5160 audio_high = std::sqrt(std::max(metrics.
high, 0.0F)) * sense;
5161 audio_sample_rate =
static_cast<float>(
audio_engine->sample_rate());
5164 for (
float &value : spectrum_values) {
5165 value *= spectrum_scale;
5171 shader_time +=
static_cast<double>(raw_audio_amplitude) *
static_cast<double>(audio_sensitivity) *
options.time_speed *
static_cast<double>(delta_scale);
5179 if (video_timeline_available) {
5181 if (source_frame <= 58U) {
5182 legacy_alpha = 0.2F + 0.1F *
static_cast<float>(source_frame);
5184 const std::uint64_t phase = (source_frame - 59U) % 100U;
5185 legacy_alpha = phase < 50U ? 5.9F - 0.1F *
static_cast<float>(phase) : 1.1F + 0.1F *
static_cast<float>(phase - 50U);
5200 const float elapsed =
static_cast<float>(
shader_time);
5201 const float compatibility_time = video_timeline_available ?
static_cast<float>(video_timeline) : std::chrono::duration<float>(now -
compatibility_clock_start).count();
5203 frame_sprite->setShaderParams(1.0F, 1.0F, 1.0F, elapsed);
5205 frame_sprite->setUniform0(
legacy_alpha, compatibility_time,
static_cast<float>(width),
static_cast<float>(height));
5206 frame_sprite->setUniform1(delta, audio_amplitude, audio_frequency, frame_rate);
5207 frame_sprite->setUniform2(shader_frame, elapsed, audio_sample_rate, audio_peak);
5209 frame_sprite->setAudioBands(audio_low, audio_mid, audio_high);
5225 setPostProcessingShaderParams(index,
crossfade_alpha, 0.0F, 0.0F, 0.0F);
5227 setPostProcessingShaderParams(index, 1.0F, 1.0F, 1.0F, elapsed);
5230 sprite->setUniform0(
legacy_alpha, compatibility_time,
static_cast<float>(width),
static_cast<float>(height));
5231 sprite->setUniform1(delta, audio_amplitude, audio_frequency, frame_rate);
5232 sprite->setUniform2(shader_frame, elapsed, audio_sample_rate, audio_peak);
5233 sprite->setUniform3(
static_cast<float>(
frame_sprite->getHistoryHead()),
static_cast<float>(
frame_sprite->getHistoryLayerCount()), audio_rms, audio_smooth);
5234 sprite->setAudioBands(audio_low, audio_mid, audio_high);
5237 if (!spectrum_values.empty()) {
5238 frame_sprite->updateSpectrumTexture(spectrum_values.data(),
static_cast<std::uint32_t
>(spectrum_values.size()));
5239 if (
options.audio_buffers > 0) {
5240 frame_sprite->updateSpectrumHistoryTexture(spectrum_values.data(),
static_cast<std::uint32_t
>(spectrum_values.size()));
5243 sprite->updateSpectrumTexture(spectrum_values.data(),
static_cast<std::uint32_t
>(spectrum_values.size()));
5244 if (
options.audio_buffers > 0) {
5245 sprite->updateSpectrumHistoryTexture(spectrum_values.data(),
static_cast<std::uint32_t
>(spectrum_values.size()));
void transfer_audio(std::string_view, std::string_view)
Copy the audio track from one media file to another via FFmpeg.
QString stable_diffusion_server
std::chrono::steady_clock::duration source_playback_paused_duration
bool render_pacing_started
std::unordered_map< std::string, fs::path > shader_reload_overrides
std::unique_ptr< midi::MidiInput > midi_input
std::unique_ptr< audio::FileAudioSource > file_audio_source
float model_rotation_y_degrees
fs::path shader_library_directory
InterfaceClient interface_client
void applyStableDiffusionEffect(cv::Mat &rgba)
void configureMidiMappings()
void requestSnapshot(SnapshotFormat format)
bool shader_history_required
std::vector< std::uint16_t > gap_fill_previous_rgba16
mxvk::ModelFragmentUniforms model_fragment_uniforms
std::uint64_t previous_autopilot_video_frame
void updateCrossfade(const std::chrono::steady_clock::time_point now)
std::chrono::steady_clock::time_point hud_session_start
bool async_camera_initial_wait_completed
bool model_video_timeline_initialized
fs::path resolvedShaderPath(const fs::path &shader) const
std::uint64_t hud_fps_frame_count
void queueRuntimeHud(int &y, int line_height)
std::mt19937 autopilot_rng
std::vector< mxvk::VK_Sprite * > post_process_sprites
double camera_last_logged_fps
bool random_dream_timeline_initialized
void paceMaximizedRendering()
std::uint64_t output_frame_count
int camera_reported_width
void event(SDL_Event &event) override
bool shader_spectrum_history_required
void setSourcePlaybackClockPaused(bool paused)
std::chrono::steady_clock::time_point source_playback_clock_start
std::chrono::steady_clock::time_point source_playback_pause_start
bool model_mouse_dragging
mxvk::VK_Sprite * crossfade_previous_sprite
bool recording_frame_has_pts
void adjustAudioSensitivity(float amount)
float model_wave_direction_y
std::chrono::steady_clock::time_point camera_fps_last_tick
bool legacy_alpha_increasing
void cycleCrossfade(int direction)
float audio_warmup_envelope
void adjustModelScale(float amount)
double crossfade_start_video_timeline
void dispatchMidiAction(int action)
const std::vector< fs::path > * activePasses() const
void updateHumanOverlayTexture()
float model_rotation_z_degrees
bool mediaClockSeconds(double &seconds) const
double previous_random_dream_timeline
std::vector< float > custom_uniform_values
bool hdr_input_precision_enabled
void onSwapchainRecreated() override
std::chrono::steady_clock::time_point audio_warmup_last_tick
std::string activePassDescription() const
bool media_clock_sync_logged
double hudVideoPositionSeconds() const
fs::path model_effect_shader
std::chrono::steady_clock::time_point window_title_last_update
std::deque< ReadbackRequest > readback_requests
MainWindow(Options options)
std::uint64_t generated_frame_count
std::uint64_t png_frame_count
float model_camera_distance
void applyCustomUniformOverrides()
float model_camera_movement_speed
void onRecordPostProcessingTexture(VkCommandBuffer command_buffer, std::uint32_t image_index, VkImageView texture_view, VkExtent2D texture_extent) override
void apply_interface_gpu_filter_state(const InterfaceGpuFilterState &requested, bool announce)
void apply_interface_audio_file_state(const InterfaceAudioFileState &requested)
int history_delay_counter
void updateCameraHistory()
double camera_reported_fps
fs::path shader_manifest_path
std::vector< MidiKnobState > midi_knob_states
void apply_interface_shader_reload(const InterfaceReloadState &requested)
std::uint64_t gap_fill_duplicate_count
bool crossfade_uses_video_timeline
void updateWindowTitle(bool force=false)
bool continuousReadbackEnabled() const
void applyDnnEffects(cv::Mat &rgba)
std::array< int, 4 > midi_slider_uniform_indices
std::string_view activeShaderRole() const
float updateAudioWarmup(std::chrono::steady_clock::time_point now)
float model_wave_audio_step
fs::path directModelFragmentShader() const
std::uint64_t recording_frame_pts
int preview_overlay_font_size
mxvk::VK_Sprite * frame_sprite
void handleFrameReadback(std::vector< std::uint8_t > &rgba, const std::vector< std::uint16_t > *rgba16, uint32_t width, uint32_t height)
fs::path png_output_directory
std::vector< std::uint8_t > gap_fill_previous_rgba
std::chrono::steady_clock::time_point interface_next_connect_attempt
bool audio_warmup_started
std::uint64_t observed_midi_drops
void onRecordCustomRendering(VkCommandBuffer command_buffer, std::uint32_t image_index) override
bool readLatestCameraFrame()
void onFrameReadbackRgba16(std::vector< std::uint16_t > &rgba, uint32_t width, uint32_t height) override
bool readTrackedInputFrame()
std::uint64_t gap_fill_next_pts
bool isMidiModelAction(int action) const
bool isMidiMappingSupported(const midi::MidiMapping &mapping) const
void selectGpuFilter(int direction)
bool model_scale_oscillation_active
void apply_interface_deep_dream_state(const InterfaceDeepDreamState &requested, bool announce)
void resolveConfiguredResourcePaths()
bool spectrumHistoryEnabledForShaders() const
std::uint64_t next_clock_output_frame
std::chrono::steady_clock::time_point crossfade_start_time
bool camera_recording_clock_logged
float model_view_rotation_degrees
static std::string formatHudTime(double seconds_value)
bool applyMidiCc(const midi::MidiMessage &message)
void startMediaTimelineIfReady()
bool video_shader_timeline_initialized
void updateRandomDreamSettings()
void apply_interface_overlay_state(const InterfaceOverlayState &requested, bool announce)
std::chrono::steady_clock::time_point previous_frame
bool initial_frame_pending
double previous_video_shader_timeline
void apply_interface_playback_state(const InterfacePlaybackState &requested, bool announce)
std::chrono::steady_clock::time_point hud_fps_last_tick
int autopilot_interval_frames
bool offlineSourceAudioEnabled() const
static bool usesMidiDeltaDirection(const midi::MidiMapping &mapping)
bool async_camera_frame_uploaded
std::string hudVideoTimeString() const
int headless_progress_last_percent
bool autopilot_random_crossfade
bool readHostRgba(cv::Mat &rgba)
void toggleAutopilot(bool sequential)
bool audioSourceOpen() const
float model_pitch_degrees
std::uint32_t interface_last_reload_sequence
bool hdr_transfer_processing_enabled
void recordModel(VkCommandBuffer command_buffer, std::uint32_t image_index, VkImageView texture_view)
void applyShaderPipeline()
bool hdr_cuda_filter_bypass_logged
void logSelectedPlaylistNode(std::string_view action) const
std::unique_ptr< audio::AudioEngine > audio_engine
double video_duration_seconds
bool hdr_dream_compatibility_logged
std::vector< MidiCcMapping > midi_cc_mappings
bool spectrum_scale_by_sensitivity
mxvk::VK_Sprite * human_overlay_sprite
bool historyCacheEnabled() const
bool headless_shutdown_logged
void apply_interface_uniform_values(const std::vector< InterfaceUniformValue > &uniform_values)
std::vector< fs::path > activeShaderPipeline() const
std::size_t crossfade_shader_index
std::chrono::steady_clock::time_point next_render_tick
void stepShaderTime(double amount)
std::uint64_t previous_model_video_frame
bool source_playback_clock_paused
double camera_delivered_fps
VideoHdrInfo video_hdr_info
std::uint64_t frame_count
void updateCameraFrameRate()
void initializeGpuFilters()
void onFrameReadbackScheduled() override
bool hostPreprocessingEnabled() const
float model_wave_amplitude_z
double hudWallElapsedSeconds() const
std::string activePlaylistDescription() const
bool autopilot_sequential
void handleDeepDreamRuntimeError(std::string_view message)
int camera_reported_height
SnapshotFormat pending_snapshot_format
void startLiveAudioRecordingIfNeeded()
std::string hudElapsedTimeString() const
std::pair< int, int > source_dimensions()
void apply_interface_multipass_state(const InterfaceMultipassState &requested)
std::uint64_t camera_fps_frame_count
void initializeDeepDream()
static std::string captureFourccName(double value)
float model_wave_direction_z
void uploadCustomUniforms()
void initializeHistory(const cv::Mat &rgba)
float model_scale_oscillation_phase
float model_wave_direction_x
std::uint32_t spectrumBinCount() const
std::size_t playlist_index
void applyDeepDreamEffect(cv::Mat &rgba)
std::chrono::steady_clock::time_point camera_history_next_update
bool handleCaptureEnd(bool discard=false)
bool source_frame_received
void configureRenderResolution()
std::uint32_t interface_last_audio_file_sequence
void adjustTimeSpeed(double amount)
void uploadInputFrame(const cv::Mat &rgba)
void cancelStableDiffusionInitialization() noexcept
SDL_Keycode midiActionKey(int action) const
float model_camera_rotation_speed
bool autopilot_video_timeline_initialized
bool readClockedVideoFrame(double clock_seconds)
bool currentVideoTimeline(double &timeline, std::uint64_t *frame_index=nullptr) const
float model_rotation_speed
void updateShaderUniforms(int width, int height)
LatestCameraFrame latest_camera_frame
std::chrono::steady_clock::time_point headless_progress_last_emit
bool headless_progress_complete
std::vector< fs::path > configured_passes
bool applyMidiMap(const midi::MidiMessage &message)
void maybeRandomizeCrossfade()
bool spectrumTextureEnabledForShaders() const
std::vector< midi::MidiMapping > midi_action_mappings
bool gap_fill_previous_valid
void apply_interface_shader_selection(const std::string &requested_name)
bool isMidiSliderMapping(const midi::MidiMapping &mapping) const
bool hdr_dnn_compatibility_logged
void resetAutopilotInterval()
bool video_shader_clock_logged
cv::Mat human_overlay_rgba
bool interface_connection_warning_reported
void recordShaderResources(const mxvk::ShaderModuleInfo &module_info, std::string_view source)
bool pollStableDiffusionInitialization()
float model_rotation_x_degrees
bool camera_history_clock_started
bool dream_processing_logged
void sync_interface_control()
void initializeOverlayFont()
std::vector< PlaylistNode > playlist
bool model_texture_prepass_active
static std::string clipOverlayText(std::string text)
static constexpr std::uint32_t COMPATIBILITY_SPECTRUM_BIN_COUNT
bool setMidiUniform(std::size_t uniform_index, int value, std::string_view label)
std::uint64_t snapshot_count
std::uint64_t autopilotFrameAdvance()
mxvk::VKAbstractModel input_model
void emitHeadlessProgress(bool complete)
std::chrono::steady_clock::time_point compatibility_clock_start
std::vector< fs::path > shaders
void onFrameReadback(std::vector< std::uint8_t > &rgba, uint32_t width, uint32_t height) override
bool shader_spectrum_required
std::vector< ShaderManifest::CustomUniform > custom_uniforms
bool hdr_input_upload_logged
void updateHudFrameRate()
std::uint32_t interface_last_sequence
void start_requested_audio_recording()
std::string_view midiActionName(int action) const
void updateHistoryFrame(const cv::Mat &rgba)
cv::Mat latest_camera_history_rgba
bool media_timeline_started
std::size_t crossfade_post_process_index
std::mt19937 random_dream_rng
void initialize_interface_control()
std::uint64_t video_source_frame_count
std::chrono::steady_clock::time_point model_last_render_time
std::string currentShader() const
SnapshotWriter snapshot_writer
void dispatchMidiModelAction(int action)
void selectShader(int direction)
void printCustomUniforms() const
float model_wave_amplitude_y
void initializeStableDiffusion()
std::uint64_t decoded_video_frame_count
std::uint64_t random_dream_period
void selectPlaylistNode(int direction)
float model_wave_amplitude_x
static std::string_view formatName(SnapshotFormat format) noexcept
static void savePng(const fs::path &path, std::uint8_t *rgba, int width, int height, int png_level)
static constexpr std::uint32_t spectrum_bin_count()
static bool mux_recording_into_video(std::vector< float > samples, unsigned int sample_rate, const std::string &video_path, double video_duration)
std::size_t selected_channels() const
static Model load(std::string_view filename, int cuda_device, std::string_view layer={}, bool use_half=false)
cv::Mat decode_hdr_transfer(const cv::Mat &rgba, bool hlg)
float encode_srgb(float value)
std::string format_bitrate(std::uint64_t bytes_written, double duration_seconds)
constexpr int COLOR_TRANSFER_ARIB_STD_B67
constexpr int COLOR_TRANSFER_SMPTE2084
float tone_map_channel(float value)
cv::Mat rgba16ToRgba8(const cv::Mat &rgba)
volatile std::sig_atomic_t HEADLESS_SHUTDOWN_REQUESTED
float decode_pq(float encoded)
float decode_hlg(float encoded)
std::vector< std::uint8_t > tone_map_hdr_rgba16(const std::vector< std::uint16_t > &rgba, bool hlg)
bool write_wav_file(const AudioRecording &recording, const std::string &filename)
cv::Mat hardenedAlphaMask(const cv::Mat &image, const cv::Mat &mask, float black_point, float white_point)
cv::Mat isolateBody(const cv::Mat &image, const cv::Mat &mask, float black_point, float white_point)
std::vector< MidiMapping > load_mapping_file(const std::string &filename)
std::vector< PlaylistNode > load_playlist(const fs::path &playlist_path, const std::vector< fs::path > &available_shaders, const fs::path &library_directory, std::ostream &warning_output)
fs::path resolveShaderManifestEntry(const fs::path &directory, std::string entry)
cv::Mat loadRgbaImage(const std::string &filename)
bool rotationSwapsDimensions(FrameRotation rotation)
fs::path default_model_path(const Options &options)
fs::path snapshot_path(const fs::path &directory, std::uint32_t width, std::uint32_t height, std::uint64_t &counter, SnapshotFormat format, std::chrono::system_clock::time_point timestamp)
std::size_t playlist_shader_count(const std::vector< PlaylistNode > &playlist) noexcept
fs::path echo_cache_shader_path(const Options &options)
double probeVideoDuration(const std::string &filename)
std::string trim(std::string text)
fs::path human_composite_shader_path(const Options &options)
ShaderManifest loadShaderManifest(const fs::path &directory)
fs::path model_fragment_shader_path(const Options &options)
void printVideoHdrInfo(const VideoHdrInfo &info, std::ostream &output)
fs::path model_vertex_shader_path(const Options &options)
void request_headless_shutdown(int signal_number) noexcept
int parseInteger(std::string_view text, std::string_view option)
bool dimensions_supported(int width, int height)
void rotateFrame(cv::Mat &frame, FrameRotation rotation)
fs::path passthrough_shader_path(const Options &options)
fs::path frame_path(const fs::path &directory, std::uint64_t index)
VideoHdrInfo probeVideoHdrInfo(const std::string &filename)
fs::path hdr_preview_shader_path(const Options &options, bool hlg)
fs::path find_shader_path(const std::vector< fs::path > &available_shaders, const fs::path &library_directory, std::string name)
fs::path crossfade_shader_path(const Options &options, std::size_t shader_index)
fs::path stable_diffusion_upscale_shader_path(const Options &options)
fs::path sprite_vertex_shader_path(const Options &options)
fs::path hdr_transfer_shader_path(const Options &options, bool hlg, bool encode)
double parseNumber(std::string_view text, std::string_view option)
void create_output_directory(const fs::path &directory)
bool isValidCustomUniformName(const std::string &name)
constexpr std::array< std::string_view, 35 > CROSSFADE_NAMES
fs::path overlay_font_path(const Options &options)
fs::path flip_shader_path(const Options &options)
fs::path find_resource(const Options &options, const fs::path &relative_path)
std::uint32_t request_sequence
std::vector< int > filter_indices
std::vector< std::string > shader_names
std::array< std::uint8_t, 3 > watermark_color
std::string watermark_text
std::uint32_t request_sequence
std::int32_t shader_index
std::string selected_shader_name
InterfaceOverlayState overlay
std::vector< InterfaceUniformValue > uniform_values
InterfaceAudioFileState audio_file
InterfaceMultipassState multipass
InterfaceGpuFilterState gpu_filters
InterfaceReloadState reload
InterfacePlaybackState playback
InterfaceDeepDreamState deep_dream
int stable_diffusion_upscale_working_width
bool stable_diffusion_after_shaders
bool midi_device_specified
bool stable_diffusion_quiet
double audio_recording_gain
std::string stable_diffusion_model
double dream_octave_scale
std::string stable_diffusion_server
double random_dream_interval
std::string stable_diffusion_scheduler
bool gpu_filter_before_dream
int stable_diffusion_server_port
double audio_pass_through_gain
std::vector< std::string > stable_diffusion_server_arguments
std::vector< StableDiffusionLora > stable_diffusion_loras
std::string fragment_shader
bool random_dream_specified
std::string midi_map_file
double stable_diffusion_strength
int stable_diffusion_height
std::vector< int > gpu_filter_indices
std::string watermark_text
int stable_diffusion_width
std::vector< std::string > midi_cc_mappings
std::string stable_diffusion_upscale_model
bool stable_diffusion_upscale
int stable_diffusion_upscale_working_height
double stable_diffusion_cfg_scale
std::string shader_directory
std::string onnx_configuration
std::string record_audio_file
std::string stable_diffusion_sampler
std::string stable_diffusion_negative_prompt
int gpu_frame_buffer_size
int stable_diffusion_steps
bool stable_diffusion_upscale_only
int stable_diffusion_seed
bool enable_random_autopilot
std::string compute_shader
std::string stable_diffusion_prompt
std::vector< std::string > entries
std::vector< CustomUniform > custom_uniforms
std::vector< std::uint16_t > rgba16
std::vector< std::uint8_t > rgba
double duration_seconds() const
std::vector< float > samples
std::vector< unsigned char > bytes
int upscale_working_width
std::filesystem::path upscale_model
std::filesystem::path server_executable
std::vector< Lora > loras
std::vector< std::string > server_arguments
std::string negative_prompt
std::filesystem::path model
int upscale_working_height
std::function< bool()> cancelled
std::filesystem::path lora_directory