ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
shader_selection_shm.hpp
Go to the documentation of this file.
1#ifndef ACMX2_SHADER_SELECTION_SHM_HPP
2#define ACMX2_SHADER_SELECTION_SHM_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 acmx2::ipc {
18
19 inline constexpr const char *kShaderSelectionShmName = "/acmx2_shader_selection_v11";
20 inline constexpr const char *kShaderSelectionSemaphoreName = "/acmx2_shm_v11";
21#ifdef _WIN32
22 inline constexpr const wchar_t *kShaderSelectionMappingNameWindows = L"Local\\ACMX2ShaderSelectionV11";
23 inline constexpr const wchar_t *kShaderSelectionMutexNameWindows = L"Local\\ACMX2ShaderSelectionMutexV11";
24#endif
25 inline constexpr std::uint32_t kShaderSelectionMagic = 0x41434D58; // 'ACMX'
26 inline constexpr std::uint32_t kShaderSelectionVersion = 11;
27 inline constexpr std::uint32_t kShaderSelectionMaxPassCount = 64;
28 inline constexpr std::uint32_t kShaderSelectionMaxGpuFilterCount = 64;
29 inline constexpr std::uint32_t kShaderSelectionMaxWatermarkText = 256;
30 inline constexpr std::uint32_t kShaderSelectionMaxReloadPath = 1024;
31 inline constexpr std::uint32_t kShaderSelectionMaxCustomUniforms = 64;
32 inline constexpr std::uint32_t kShaderSelectionMaxUniformName = 64;
33 inline constexpr std::uint32_t kShaderSelectionMaxAudioFilePath = 4096;
34 inline constexpr std::uint32_t kShaderSelectionMaxDreamModelPath = 4096;
35 inline constexpr std::uint32_t kShaderSelectionMaxDreamLayer = 128;
36 inline constexpr std::uint32_t kShaderSelectionMaxShaderName = 1024;
37 inline constexpr std::size_t kShaderSelectionDataSize = 81136;
38#ifdef _WIN32
39 inline constexpr DWORD kShaderSelectionLockTimeoutMs = 1000;
40#endif
41
45 std::int32_t selected_index = -1;
46 std::uint32_t shader_pass_count = 0;
47 std::uint8_t shader_pass_enabled = 0;
48 std::uint8_t repeat_enabled = 0;
49 std::uint8_t display_filter_enabled = 0;
50 std::uint8_t watermark_enabled = 0;
51 std::uint8_t normalized_time_enabled = 0;
52 std::uint8_t reserved_flags[3] = {0, 0, 0};
55 std::uint32_t gpu_filter_count = 0;
56 std::uint8_t gpu_filter_enabled = 0;
57 std::uint8_t gpu_buffer_size = 8;
58 std::uint8_t watermark_r = 255;
59 std::uint8_t watermark_g = 0;
60 std::uint8_t watermark_b = 150;
61 std::uint8_t reserved[3] = {0, 0, 0};
64 std::int32_t reload_shader_index = -1;
66 std::uint32_t reload_sequence = 0;
67 std::uint32_t custom_uniform_count = 0;
71 std::int32_t audio_output_device = -1;
72 std::uint8_t audio_pass_through = 0;
73 std::uint8_t audio_trunc = 0;
74 std::uint8_t audio_repeat = 0;
75 std::uint8_t audio_reserved = 0;
76 std::uint32_t audio_file_sequence = 0;
77 std::uint8_t dream_enabled = 0;
78 std::uint8_t dream_fp16 = 0;
79 std::uint8_t dream_gpu_filter_first = 0;
80 std::uint8_t dream_reserved = 0;
81 std::int32_t dream_iterations = 1;
82 std::int32_t dream_maximum_dimension = 512;
83 std::int32_t dream_channel = -1;
84 std::int32_t dream_octaves = 1;
85 std::int32_t dream_jitter = 0;
86 std::int32_t dream_smoothing = 0;
87 float dream_strength = 0.05F;
88 float dream_feedback = 0.9F;
89 float dream_zoom = 1.01F;
90 float dream_rotation = 0.1F;
91 float dream_octave_scale = 1.4F;
95 std::uint32_t sequence = 0;
96 };
97
98 static_assert(std::is_standard_layout_v<ShaderSelectionShmData>);
99 static_assert(std::is_trivially_copyable_v<ShaderSelectionShmData>);
100 static_assert(sizeof(ShaderSelectionShmData) == kShaderSelectionDataSize);
101
102#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32)
103 class ShaderSelectionLock {
104 public:
105#if defined(__linux__) || defined(__APPLE__)
106 explicit ShaderSelectionLock(sem_t *semaphoreValue) : semaphore(semaphoreValue) {
107 if (semaphore == nullptr || semaphore == SEM_FAILED)
108 return;
109 while (::sem_wait(semaphore) != 0) {
110 if (errno != EINTR)
111 return;
112 }
113 locked = true;
114 }
115#else
116 explicit ShaderSelectionLock(HANDLE mutexValue) : mutex(mutexValue) {
117 if (mutex == nullptr)
118 return;
119 const DWORD result = ::WaitForSingleObject(mutex, kShaderSelectionLockTimeoutMs);
120 locked = result == WAIT_OBJECT_0 || result == WAIT_ABANDONED;
121 }
122#endif
123
124 ~ShaderSelectionLock() {
125 if (!locked)
126 return;
127#if defined(__linux__) || defined(__APPLE__)
128 ::sem_post(semaphore);
129#else
130 ::ReleaseMutex(mutex);
131#endif
132 }
133
134 ShaderSelectionLock(const ShaderSelectionLock &) = delete;
135 ShaderSelectionLock &operator=(const ShaderSelectionLock &) = delete;
136
137 explicit operator bool() const { return locked; }
138
139 private:
140#if defined(__linux__) || defined(__APPLE__)
141 sem_t *semaphore = nullptr;
142#else
143 HANDLE mutex = nullptr;
144#endif
145 bool locked = false;
146 };
147#endif
148
149} // namespace acmx2::ipc
150
151#endif
constexpr std::uint32_t kShaderSelectionMaxDreamLayer
constexpr std::uint32_t kShaderSelectionMagic
constexpr std::size_t kShaderSelectionDataSize
constexpr std::uint32_t kShaderSelectionMaxShaderName
constexpr std::uint32_t kShaderSelectionMaxPassCount
constexpr std::uint32_t kShaderSelectionMaxUniformName
constexpr std::uint32_t kShaderSelectionVersion
constexpr std::uint32_t kShaderSelectionMaxWatermarkText
constexpr std::uint32_t kShaderSelectionMaxReloadPath
constexpr const char * kShaderSelectionShmName
constexpr const char * kShaderSelectionSemaphoreName
constexpr std::uint32_t kShaderSelectionMaxGpuFilterCount
constexpr std::uint32_t kShaderSelectionMaxCustomUniforms
constexpr std::uint32_t kShaderSelectionMaxDreamModelPath
constexpr std::uint32_t kShaderSelectionMaxAudioFilePath
char selected_shader_name[kShaderSelectionMaxShaderName]
std::int32_t gpu_filter_indices[kShaderSelectionMaxGpuFilterCount]
char audio_file_path[kShaderSelectionMaxAudioFilePath]
char shader_pass_names[kShaderSelectionMaxPassCount][kShaderSelectionMaxShaderName]
char dream_model_path[kShaderSelectionMaxDreamModelPath]
char custom_uniform_names[kShaderSelectionMaxCustomUniforms][kShaderSelectionMaxUniformName]
char dream_layer[kShaderSelectionMaxDreamLayer]
char reload_shader_path[kShaderSelectionMaxReloadPath]
std::int32_t shader_pass_indices[kShaderSelectionMaxPassCount]
char watermark_text[kShaderSelectionMaxWatermarkText]
float custom_uniform_values[kShaderSelectionMaxCustomUniforms]