From d4b3506e6cb687d8fc8fa7c64e4fc6538e78331e Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 20 Jul 2026 05:09:43 +0000 Subject: [PATCH] [common] lgmp: separate transport configuration Move LGMP queue tunables into LGMPConfig.h and keep compatibility aliases in KVMFR.h. Promote color-transform, SDR white-level, and damage-limit definitions to transport-neutral common types so non-LGMP transports do not depend on the KVMFR wire format. --- common/include/common/KVMFR.h | 27 +++++------------ common/include/common/LGMPConfig.h | 30 +++++++++++++++++++ common/include/common/stringutils.h | 4 +++ common/include/common/types.h | 20 +++++++++++++ common/src/stringutils.c | 14 +++++++++ host/platform/Windows/capture/DXGI/src/dxgi.c | 1 + .../Windows/capture/NVFBC/src/nvfbc.c | 1 + host/src/app.c | 1 + idd/LGIdd/CPostProcessor.h | 3 +- obs/lg.c | 1 + profile/client/src/main.c | 1 + 11 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 common/include/common/LGMPConfig.h diff --git a/common/include/common/KVMFR.h b/common/include/common/KVMFR.h index 26354e34..3e485484 100644 --- a/common/include/common/KVMFR.h +++ b/common/include/common/KVMFR.h @@ -26,22 +26,16 @@ #include #include #include "types.h" +#include "LGMPConfig.h" #define KVMFR_MAGIC "KVMFR---" #define KVMFR_VERSION 23 // Fallback used by producers that cannot report the source display's SDR // white level. IDD frames override this with IDDCX_METADATA2::SdrWhiteLevel. -#define KVMFR_SDR_WHITE_LEVEL_DEFAULT 203 - -#define KVMFR_MAX_DAMAGE_RECTS 64 - -#define LGMP_Q_POINTER 1 -#define LGMP_Q_FRAME 2 - -#define LGMP_Q_FRAME_LEN 2 -#define LGMP_Q_POINTER_LEN 32 +#define KVMFR_SDR_WHITE_LEVEL_DEFAULT LG_SDR_WHITE_LEVEL_DEFAULT +#define KVMFR_MAX_DAMAGE_RECTS LG_MAX_FRAME_DAMAGE_RECTS #ifdef _MSC_VER // don't warn on zero length arrays @@ -144,25 +138,18 @@ KVMFRCursor; enum { - KVMFR_COLOR_TRANSFORM_MATRIX = 0x1, - KVMFR_COLOR_TRANSFORM_LUT = 0x2, + KVMFR_COLOR_TRANSFORM_MATRIX = LG_COLOR_TRANSFORM_MATRIX, + KVMFR_COLOR_TRANSFORM_LUT = LG_COLOR_TRANSFORM_LUT, }; -typedef uint32_t KVMFRColorTransformFlags; +typedef LGColorTransformFlags KVMFRColorTransformFlags; // Optional payload appended to KVMFRCursor when // CURSOR_FLAG_COLOR_TRANSFORM is present. The matrix is an XYZ-to-XYZ // adjustment; the LUT is applied after encoding to the active wire transfer // function. Four LUT components keep the payload directly uploadable as an // RGBA32F texture, with alpha reserved and set to 1.0. -typedef struct KVMFRColorTransform -{ - KVMFRColorTransformFlags flags; - float matrix[3][4]; - float scalar; - float lut[4096][4]; -} -KVMFRColorTransform; +typedef LGColorTransform KVMFRColorTransform; enum { diff --git a/common/include/common/LGMPConfig.h b/common/include/common/LGMPConfig.h new file mode 100644 index 00000000..6039e9be --- /dev/null +++ b/common/include/common/LGMPConfig.h @@ -0,0 +1,30 @@ +/** + * Looking Glass + * Copyright © 2017-2026 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _H_LG_COMMON_LGMP_CONFIG_ +#define _H_LG_COMMON_LGMP_CONFIG_ + +#define LGMP_Q_POINTER 1 +#define LGMP_Q_FRAME 2 + +#define LGMP_Q_FRAME_LEN 2 +#define LGMP_Q_POINTER_LEN 32 + +#endif diff --git a/common/include/common/stringutils.h b/common/include/common/stringutils.h index d1d9c00b..6cc85ecf 100644 --- a/common/include/common/stringutils.h +++ b/common/include/common/stringutils.h @@ -22,6 +22,7 @@ #define _H_LG_COMMON_STRINGUTILS #include +#include // vsprintf but with buffer allocation int valloc_sprintf(char ** str, const char * format, va_list ap) @@ -37,6 +38,9 @@ bool str_containsValue(const char * list, char delimiter, const char * value); // Local implementation of strdup char * lg_strdup(const char *s); +// copy a potentially unterminated string into a null-terminated buffer +void str_copy(char * dst, size_t dstSize, const char * src, size_t srcSize); + // search a non null terminated buffer for a value const char * memsearch( const char * haystack, size_t haystackSize, diff --git a/common/include/common/types.h b/common/include/common/types.h index af0f8570..2bf7be34 100644 --- a/common/include/common/types.h +++ b/common/include/common/types.h @@ -89,6 +89,26 @@ typedef enum CursorType } CursorType; +enum +{ + LG_COLOR_TRANSFORM_MATRIX = 0x1, + LG_COLOR_TRANSFORM_LUT = 0x2, +}; + +typedef uint32_t LGColorTransformFlags; + +#define LG_SDR_WHITE_LEVEL_DEFAULT 203 +#define LG_MAX_FRAME_DAMAGE_RECTS 64 + +typedef struct LGColorTransform +{ + LGColorTransformFlags flags; + float matrix[3][4]; + float scalar; + float lut[4096][4]; +} +LGColorTransform; + typedef struct StringPair { const char * name; diff --git a/common/src/stringutils.c b/common/src/stringutils.c index 6bcdecc7..4526e274 100644 --- a/common/src/stringutils.c +++ b/common/src/stringutils.c @@ -112,6 +112,20 @@ char * lg_strdup(const char *s) return out; } +void str_copy(char * dst, size_t dstSize, const char * src, size_t srcSize) +{ + if (!dstSize) + return; + + const char * end = memchr(src, 0, srcSize); + const size_t srcLength = end ? (size_t)(end - src) : srcSize; + const size_t copySize = srcLength < dstSize - 1 ? + srcLength : dstSize - 1; + + memcpy(dst, src, copySize); + dst[copySize] = 0; +} + const char * memsearch( const char * haystack, size_t haystackSize, const char * needle , size_t needleSize , diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index f8a99497..b03f2992 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -30,6 +30,7 @@ #include "common/rects.h" #include "common/runningavg.h" #include "common/KVMFR.h" +#include "common/LGMPConfig.h" #include "common/vector.h" #include diff --git a/host/platform/Windows/capture/NVFBC/src/nvfbc.c b/host/platform/Windows/capture/NVFBC/src/nvfbc.c index bf03dc53..b8aa4f9d 100644 --- a/host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -31,6 +31,7 @@ #include "common/rects.h" #include "common/thread.h" #include "common/KVMFR.h" +#include "common/LGMPConfig.h" #include "common/vector.h" #include #include diff --git a/host/src/app.c b/host/src/app.c index 8f70094d..ca4e4be2 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -26,6 +26,7 @@ #include "common/option.h" #include "common/locking.h" #include "common/KVMFR.h" +#include "common/LGMPConfig.h" #include "common/crash.h" #include "common/thread.h" #include "common/ivshmem.h" diff --git a/idd/LGIdd/CPostProcessor.h b/idd/LGIdd/CPostProcessor.h index cba37028..7df3c572 100644 --- a/idd/LGIdd/CPostProcessor.h +++ b/idd/LGIdd/CPostProcessor.h @@ -30,7 +30,6 @@ struct CD3D12Device; extern "C" { - #include "common/KVMFR.h" #include "common/types.h" } @@ -63,7 +62,7 @@ struct D12FrameFormat bool hdr = false; bool hdrPQ = false; bool hdrMetadata = false; - uint32_t sdrWhiteLevel = KVMFR_SDR_WHITE_LEVEL_DEFAULT; + uint32_t sdrWhiteLevel = LG_SDR_WHITE_LEVEL_DEFAULT; std::shared_ptr colorTransform; // HDR static metadata (SMPTE ST 2086) diff --git a/obs/lg.c b/obs/lg.c index aa909c1c..0950999d 100644 --- a/obs/lg.c +++ b/obs/lg.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/profile/client/src/main.c b/profile/client/src/main.c index 3ced64db..dfcf5f01 100644 --- a/profile/client/src/main.c +++ b/profile/client/src/main.c @@ -22,6 +22,7 @@ #include "common/option.h" #include "common/crash.h" #include "common/KVMFR.h" +#include "common/LGMPConfig.h" #include "common/locking.h" #include "common/stringutils.h" #include "common/ivshmem.h"