ACMX 2.139.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 = "/acmx2_shader_selection_v11";
22 inline constexpr const char *SHADER_SELECTION_SEMAPHORE_NAME = "/acmx2_shm_v11";
23#ifdef _WIN32
24 inline constexpr const wchar_t *SHADER_SELECTION_MAPPING_NAME_WINDOWS = L"Local\\ACMX2ShaderSelectionV11";
25 inline constexpr const wchar_t *SHADER_SELECTION_MUTEX_NAME_WINDOWS = L"Local\\ACMX2ShaderSelectionMutexV11";
26#endif
27 inline constexpr std::uint32_t SHADER_SELECTION_MAGIC = 0x41434D58;
28 inline constexpr std::uint32_t SHADER_SELECTION_VERSION = 11;
29 inline constexpr std::uint32_t MAX_PASS_COUNT = 64;
30 inline constexpr std::uint32_t MAX_GPU_FILTER_COUNT = 64;
31 inline constexpr std::uint32_t MAX_WATERMARK_TEXT = 256;
32 inline constexpr std::uint32_t MAX_RELOAD_PATH = 1024;
33 inline constexpr std::uint32_t MAX_CUSTOM_UNIFORMS = 64;
34 inline constexpr std::uint32_t MAX_UNIFORM_NAME = 64;
35 inline constexpr std::uint32_t MAX_AUDIO_FILE_PATH = 4096;
36 inline constexpr std::uint32_t MAX_DREAM_MODEL_PATH = 4096;
37 inline constexpr std::uint32_t MAX_DREAM_LAYER = 128;
38 inline constexpr std::uint32_t MAX_SHADER_NAME = 1024;
39 inline constexpr std::size_t SHADER_SELECTION_DATA_SIZE = 81136;
40#ifdef _WIN32
41 inline constexpr DWORD INTERFACE_LOCK_TIMEOUT_MS = 1000;
42#endif
43
47 std::int32_t selected_index = -1;
48 std::uint32_t shader_pass_count = 0;
49 std::uint8_t shader_pass_enabled = 0;
50 std::uint8_t repeat_enabled = 0;
51 std::uint8_t display_filter_enabled = 0;
52 std::uint8_t watermark_enabled = 0;
53 std::uint8_t normalized_time_enabled = 0;
54 std::uint8_t reserved_flags[3] = {0, 0, 0};
57 std::uint32_t gpu_filter_count = 0;
58 std::uint8_t gpu_filter_enabled = 0;
59 std::uint8_t gpu_buffer_size = 8;
60 std::uint8_t watermark_r = 255;
61 std::uint8_t watermark_g = 0;
62 std::uint8_t watermark_b = 150;
63 std::uint8_t reserved[3] = {0, 0, 0};
66 std::int32_t reload_shader_index = -1;
68 std::uint32_t reload_sequence = 0;
69 std::uint32_t custom_uniform_count = 0;
73 std::int32_t audio_output_device = -1;
74 std::uint8_t audio_pass_through = 0;
75 std::uint8_t audio_trunc = 0;
76 std::uint8_t audio_repeat = 0;
77 std::uint8_t audio_reserved = 0;
78 std::uint32_t audio_file_sequence = 0;
79 std::uint8_t dream_enabled = 0;
80 std::uint8_t dream_fp16 = 0;
81 std::uint8_t dream_gpu_filter_first = 0;
82 std::uint8_t dream_reserved = 0;
83 std::int32_t dream_iterations = 1;
84 std::int32_t dream_maximum_dimension = 512;
85 std::int32_t dream_channel = -1;
86 std::int32_t dream_octaves = 1;
87 std::int32_t dream_jitter = 0;
88 std::int32_t dream_smoothing = 0;
89 float dream_strength = 0.05F;
90 float dream_feedback = 0.9F;
91 float dream_zoom = 1.01F;
92 float dream_rotation = 0.1F;
93 float dream_octave_scale = 1.4F;
97 std::uint32_t sequence = 0;
98 };
99
100 static_assert(std::is_standard_layout_v<ShaderSelectionData>);
101 static_assert(std::is_trivially_copyable_v<ShaderSelectionData>);
102 static_assert(sizeof(ShaderSelectionData) == SHADER_SELECTION_DATA_SIZE);
103
104#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32)
105 class InterfaceLock {
106 public:
107#if defined(__linux__) || defined(__APPLE__)
108 explicit InterfaceLock(sem_t *value) : semaphore(value) {
109 if (semaphore == nullptr || semaphore == SEM_FAILED)
110 return;
111 while (::sem_wait(semaphore) != 0) {
112 if (errno != EINTR)
113 return;
114 }
115 locked = true;
116 }
117#else
118 explicit InterfaceLock(HANDLE value) : mutex(value) {
119 if (mutex == nullptr)
120 return;
121 const DWORD result = ::WaitForSingleObject(mutex, INTERFACE_LOCK_TIMEOUT_MS);
122 locked = result == WAIT_OBJECT_0 || result == WAIT_ABANDONED;
123 }
124#endif
125
126 ~InterfaceLock() {
127 if (!locked)
128 return;
129#if defined(__linux__) || defined(__APPLE__)
130 ::sem_post(semaphore);
131#else
132 ::ReleaseMutex(mutex);
133#endif
134 }
135
136 InterfaceLock(const InterfaceLock &) = delete;
137 InterfaceLock &operator=(const InterfaceLock &) = delete;
138
139 explicit operator bool() const { return locked; }
140
141 private:
142#if defined(__linux__) || defined(__APPLE__)
143 sem_t *semaphore = nullptr;
144#else
145 HANDLE mutex = nullptr;
146#endif
147 bool locked = false;
148 };
149#endif
150} // namespace acmxvk::ipc
151
152#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]