ACMX 2.136.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
interface_control.hpp
Go to the documentation of this file.
1#ifndef ACMXVK_INTERFACE_CONTROL_HPP
2#define ACMXVK_INTERFACE_CONTROL_HPP
3
4#include <cstddef>
5#include <cstdint>
6#include <type_traits>
7#if defined(__linux__) || defined(__APPLE__)
8#include <cerrno>
9#include <semaphore.h>
10#elif defined(_WIN32)
11#ifndef NOMINMAX
12#define NOMINMAX
13#endif
14#include <windows.h>
15#endif
16
17namespace acmxvk::ipc {
18 // This layout intentionally mirrors ACMX2/shader_selection_shm.hpp version
19 // 11. Keeping a local protocol declaration lets ACMXVK remain buildable as
20 // a standalone source tree while sharing the Qt launcher's control block.
21 inline constexpr const char *SHADER_SELECTION_SHM_NAME =
22 "/acmx2_shader_selection_v11";
23 inline constexpr const char *SHADER_SELECTION_SEMAPHORE_NAME =
24 "/acmx2_shm_v11";
25#ifdef _WIN32
26 inline constexpr const wchar_t *SHADER_SELECTION_MAPPING_NAME_WINDOWS =
27 L"Local\\ACMX2ShaderSelectionV11";
28 inline constexpr const wchar_t *SHADER_SELECTION_MUTEX_NAME_WINDOWS =
29 L"Local\\ACMX2ShaderSelectionMutexV11";
30#endif
31 inline constexpr std::uint32_t SHADER_SELECTION_MAGIC = 0x41434D58;
32 inline constexpr std::uint32_t SHADER_SELECTION_VERSION = 11;
33 inline constexpr std::uint32_t MAX_PASS_COUNT = 64;
34 inline constexpr std::uint32_t MAX_GPU_FILTER_COUNT = 64;
35 inline constexpr std::uint32_t MAX_WATERMARK_TEXT = 256;
36 inline constexpr std::uint32_t MAX_RELOAD_PATH = 1024;
37 inline constexpr std::uint32_t MAX_CUSTOM_UNIFORMS = 64;
38 inline constexpr std::uint32_t MAX_UNIFORM_NAME = 64;
39 inline constexpr std::uint32_t MAX_AUDIO_FILE_PATH = 4096;
40 inline constexpr std::uint32_t MAX_DREAM_MODEL_PATH = 4096;
41 inline constexpr std::uint32_t MAX_DREAM_LAYER = 128;
42 inline constexpr std::uint32_t MAX_SHADER_NAME = 1024;
43 inline constexpr std::size_t SHADER_SELECTION_DATA_SIZE = 81136;
44#ifdef _WIN32
45 inline constexpr DWORD INTERFACE_LOCK_TIMEOUT_MS = 1000;
46#endif
47
51 std::int32_t selected_index = -1;
52 std::uint32_t shader_pass_count = 0;
53 std::uint8_t shader_pass_enabled = 0;
54 std::uint8_t repeat_enabled = 0;
55 std::uint8_t display_filter_enabled = 0;
56 std::uint8_t watermark_enabled = 0;
57 std::uint8_t normalized_time_enabled = 0;
58 std::uint8_t reserved_flags[3] = {0, 0, 0};
61 std::uint32_t gpu_filter_count = 0;
62 std::uint8_t gpu_filter_enabled = 0;
63 std::uint8_t gpu_buffer_size = 8;
64 std::uint8_t watermark_r = 255;
65 std::uint8_t watermark_g = 0;
66 std::uint8_t watermark_b = 150;
67 std::uint8_t reserved[3] = {0, 0, 0};
70 std::int32_t reload_shader_index = -1;
72 std::uint32_t reload_sequence = 0;
73 std::uint32_t custom_uniform_count = 0;
77 std::int32_t audio_output_device = -1;
78 std::uint8_t audio_pass_through = 0;
79 std::uint8_t audio_trunc = 0;
80 std::uint8_t audio_repeat = 0;
81 std::uint8_t audio_reserved = 0;
82 std::uint32_t audio_file_sequence = 0;
83 std::uint8_t dream_enabled = 0;
84 std::uint8_t dream_fp16 = 0;
85 std::uint8_t dream_gpu_filter_first = 0;
86 std::uint8_t dream_reserved = 0;
87 std::int32_t dream_iterations = 1;
88 std::int32_t dream_maximum_dimension = 512;
89 std::int32_t dream_channel = -1;
90 std::int32_t dream_octaves = 1;
91 std::int32_t dream_jitter = 0;
92 std::int32_t dream_smoothing = 0;
93 float dream_strength = 0.05F;
94 float dream_feedback = 0.9F;
95 float dream_zoom = 1.01F;
96 float dream_rotation = 0.1F;
97 float dream_octave_scale = 1.4F;
101 std::uint32_t sequence = 0;
102 };
103
104 static_assert(std::is_standard_layout_v<ShaderSelectionData>);
105 static_assert(std::is_trivially_copyable_v<ShaderSelectionData>);
106 static_assert(sizeof(ShaderSelectionData) == SHADER_SELECTION_DATA_SIZE);
107
108#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32)
109 class InterfaceLock {
110 public:
111#if defined(__linux__) || defined(__APPLE__)
112 explicit InterfaceLock(sem_t *value) : semaphore(value) {
113 if (semaphore == nullptr || semaphore == SEM_FAILED)
114 return;
115 while (::sem_wait(semaphore) != 0) {
116 if (errno != EINTR)
117 return;
118 }
119 locked = true;
120 }
121#else
122 explicit InterfaceLock(HANDLE value) : mutex(value) {
123 if (mutex == nullptr)
124 return;
125 const DWORD result =
126 ::WaitForSingleObject(mutex, INTERFACE_LOCK_TIMEOUT_MS);
127 locked = result == WAIT_OBJECT_0 || result == WAIT_ABANDONED;
128 }
129#endif
130
131 ~InterfaceLock() {
132 if (!locked)
133 return;
134#if defined(__linux__) || defined(__APPLE__)
135 ::sem_post(semaphore);
136#else
137 ::ReleaseMutex(mutex);
138#endif
139 }
140
141 InterfaceLock(const InterfaceLock &) = delete;
142 InterfaceLock &operator=(const InterfaceLock &) = delete;
143
144 explicit operator bool() const { return locked; }
145
146 private:
147#if defined(__linux__) || defined(__APPLE__)
148 sem_t *semaphore = nullptr;
149#else
150 HANDLE mutex = nullptr;
151#endif
152 bool locked = false;
153 };
154#endif
155} // namespace acmxvk::ipc
156
157#endif
constexpr std::uint32_t MAX_SHADER_NAME
constexpr std::uint32_t MAX_GPU_FILTER_COUNT
constexpr std::uint32_t SHADER_SELECTION_VERSION
constexpr std::uint32_t MAX_UNIFORM_NAME
constexpr const char * SHADER_SELECTION_SEMAPHORE_NAME
constexpr std::uint32_t SHADER_SELECTION_MAGIC
constexpr std::uint32_t MAX_AUDIO_FILE_PATH
constexpr std::uint32_t MAX_CUSTOM_UNIFORMS
constexpr const char * SHADER_SELECTION_SHM_NAME
constexpr std::uint32_t MAX_DREAM_LAYER
constexpr std::uint32_t MAX_RELOAD_PATH
constexpr std::uint32_t MAX_PASS_COUNT
constexpr std::uint32_t MAX_DREAM_MODEL_PATH
constexpr std::uint32_t MAX_WATERMARK_TEXT
constexpr std::size_t SHADER_SELECTION_DATA_SIZE
std::int32_t gpu_filter_indices[MAX_GPU_FILTER_COUNT]
char audio_file_path[MAX_AUDIO_FILE_PATH]
char shader_pass_names[MAX_PASS_COUNT][MAX_SHADER_NAME]
char watermark_text[MAX_WATERMARK_TEXT]
std::int32_t shader_pass_indices[MAX_PASS_COUNT]
float custom_uniform_values[MAX_CUSTOM_UNIFORMS]
char custom_uniform_names[MAX_CUSTOM_UNIFORMS][MAX_UNIFORM_NAME]
char reload_shader_path[MAX_RELOAD_PATH]
char dream_model_path[MAX_DREAM_MODEL_PATH]
char selected_shader_name[MAX_SHADER_NAME]