From 3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Thu, 19 Nov 2026 16:01:23 -0500 Subject: [PATCH 1/2] test: characterize graphics GPU metadata queries before extraction Refs #5094. RED: the test stops at its seam guard, because libobs/graphics/graphics-gpu-metadata.c.h does not exist yet. Co-Authored-By: Claude Opus 5.5 --- test/cmocka/build/test-graph.json | 19 ++ test/cmocka/test_graphics_gpu_metadata.c | 243 ++++++++++++++++++ .../tests.d/test_graphics_gpu_metadata.cmake | 2 + 3 files changed, 264 insertions(+) create mode 100644 test/cmocka/test_graphics_gpu_metadata.c create mode 100644 test/cmocka/tests.d/test_graphics_gpu_metadata.cmake diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index 7b5dd440da..a3185aed95 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -5284,6 +5284,19 @@ "SIMDe::SIMDe" ] }, + "test_graphics_gpu_metadata": { + "sources": [ + "test/cmocka/test_graphics_gpu_metadata.c" + ], + "libraries": [ + "OBS::libobs", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ] + }, "test_graphics_host_exports": { "sources": [ "test/cmocka/test_graphics_host_exports.c" @@ -24137,6 +24150,12 @@ "${target}" ] }, + "test_graphics_gpu_metadata": { + "target": "test_graphics_gpu_metadata", + "command": [ + "${target}" + ] + }, "test_graphics_host_exports": { "target": "test_graphics_host_exports", "requires": "OS_LINUX" diff --git a/test/cmocka/test_graphics_gpu_metadata.c b/test/cmocka/test_graphics_gpu_metadata.c new file mode 100644 index 0000000000..a2e52b9f08 --- /dev/null +++ b/test/cmocka/test_graphics_gpu_metadata.c @@ -0,0 +1,243 @@ +/* Characterize the public GPU metadata queries against actual libobs without a GPU. */ +#include +#include +#include +#include +#include +#include +#include +#include "graphics/graphics-internal.h" +#include "util/base.h" +#include "util/bmem.h" + +/* The characterization lands with the extraction, before the Rust swap. */ +#if !__has_include("graphics/graphics-gpu-metadata.c.h") +#error "graphics GPU-metadata extraction seam is missing" +#endif + +static struct graphics_subsystem graphics; +static int device_token; +static const char *driver_version, *renderer; +static uint64_t dmem, smem; +static unsigned driver_calls, renderer_calls, dmem_calls, smem_calls, log_count; +static char message[160]; +static log_handler_t previous_handler; +static void *previous_param; + +#ifdef __GNUC__ +__attribute__((format(printf, 2, 0))) +#endif +static void capture(int level, const char *format, va_list args, void *param) +{ + (void)param; + assert_int_equal(level, LOG_DEBUG); + log_count++; + vsnprintf(message, sizeof(message), format, args); +} + +static void context(gs_device_t *device) +{ + assert_ptr_equal(device, &device_token); +} + +static const char *query_driver_version(void) +{ + assert_ptr_equal(gs_get_context(), &graphics); + driver_calls++; + return driver_version; +} + +static const char *query_renderer(void) +{ + assert_ptr_equal(gs_get_context(), &graphics); + renderer_calls++; + return renderer; +} + +static uint64_t query_dmem(void) +{ + assert_ptr_equal(gs_get_context(), &graphics); + dmem_calls++; + return dmem; +} + +static uint64_t query_smem(void) +{ + assert_ptr_equal(gs_get_context(), &graphics); + smem_calls++; + return smem; +} + +static void install_callbacks(void) +{ + graphics.exports.gpu_get_driver_version = query_driver_version; + graphics.exports.gpu_get_renderer = query_renderer; + graphics.exports.gpu_get_dmem = query_dmem; + graphics.exports.gpu_get_smem = query_smem; +} + +static void clear_callbacks(void) +{ + graphics.exports.gpu_get_driver_version = NULL; + graphics.exports.gpu_get_renderer = NULL; + graphics.exports.gpu_get_dmem = NULL; + graphics.exports.gpu_get_smem = NULL; +} + +static void assert_calls(unsigned driver, unsigned render, unsigned d, unsigned s) +{ + assert_int_equal(driver_calls, driver); + assert_int_equal(renderer_calls, render); + assert_int_equal(dmem_calls, d); + assert_int_equal(smem_calls, s); +} + +static int setup(void **state) +{ + (void)state; + assert_null(gs_get_context()); + memset(&graphics, 0, sizeof(graphics)); + driver_calls = renderer_calls = dmem_calls = smem_calls = log_count = 0; + message[0] = '\0'; + driver_version = "driver 1.2.3"; + renderer = "renderer X"; + dmem = 1024; + smem = 2048; + graphics.device = (gs_device_t *)&device_token; + graphics.exports.device_enter_context = context; + graphics.exports.device_leave_context = context; + install_callbacks(); + assert_int_equal(pthread_mutex_init(&graphics.mutex, NULL), 0); + base_get_log_handler(&previous_handler, &previous_param); + base_set_log_handler(capture, NULL); + return 0; +} + +static int teardown(void **state) +{ + (void)state; + if (gs_get_context()) + gs_leave_context(); + base_set_log_handler(previous_handler, previous_param); + assert_int_equal(pthread_mutex_destroy(&graphics.mutex), 0); + return 0; +} + +static void no_context(void **state) +{ + (void)state; + /* With callbacks present or absent, validate context before dispatch. */ + for (unsigned i = 0; i < 2; i++) { + assert_null(gs_get_driver_version()); + assert_string_equal(message, "gs_get_driver_version: called while not in a graphics context"); + assert_int_equal(log_count, 4 * i + 1); + assert_null(gs_get_renderer()); + assert_string_equal(message, "gs_get_renderer: called while not in a graphics context"); + assert_int_equal(log_count, 4 * i + 2); + assert_true(gs_get_gpu_dmem() == 0); + assert_string_equal(message, "gs_get_gpu_dmem: called while not in a graphics context"); + assert_int_equal(log_count, 4 * i + 3); + assert_true(gs_get_gpu_smem() == 0); + assert_string_equal(message, "gs_get_gpu_smem: called while not in a graphics context"); + assert_int_equal(log_count, 4 * i + 4); + assert_calls(0, 0, 0, 0); + clear_callbacks(); + } +} + +static void absent_callbacks(void **state) +{ + (void)state; + gs_enter_context(&graphics); + clear_callbacks(); + /* Each optional backend entry falls back silently to its default. */ + assert_null(gs_get_driver_version()); + assert_null(gs_get_renderer()); + assert_true(gs_get_gpu_dmem() == 0); + assert_true(gs_get_gpu_smem() == 0); + assert_calls(0, 0, 0, 0); + assert_int_equal(log_count, 0); + assert_string_equal(message, ""); +} + +static void each_slot_dispatches_alone(void **state) +{ + (void)state; + gs_enter_context(&graphics); + /* Distinct callbacks prove each entry reads only its own slot, once. */ + assert_ptr_equal(gs_get_driver_version(), driver_version); + assert_calls(1, 0, 0, 0); + assert_ptr_equal(gs_get_renderer(), renderer); + assert_calls(1, 1, 0, 0); + assert_true(gs_get_gpu_dmem() == 1024); + assert_calls(1, 1, 1, 0); + assert_true(gs_get_gpu_smem() == 2048); + assert_calls(1, 1, 1, 1); + + /* Removing one slot leaves the others dispatching. */ + graphics.exports.gpu_get_renderer = NULL; + graphics.exports.gpu_get_dmem = NULL; + assert_ptr_equal(gs_get_driver_version(), driver_version); + assert_null(gs_get_renderer()); + assert_true(gs_get_gpu_dmem() == 0); + assert_true(gs_get_gpu_smem() == 2048); + assert_calls(2, 1, 1, 2); + assert_int_equal(log_count, 0); +} + +static void strings_returned_unchanged(void **state) +{ + (void)state; + static const char empty[] = ""; + char owned[] = "owned by the backend"; + const char *values[] = {NULL, empty, owned, "static renderer"}; + long allocs = bnum_allocs(); + + gs_enter_context(&graphics); + for (unsigned i = 0; i < sizeof(values) / sizeof(values[0]); i++) { + driver_version = values[i]; + renderer = values[i]; + /* The very pointer comes back: no copy, no allocation. */ + assert_ptr_equal(gs_get_driver_version(), values[i]); + assert_ptr_equal(gs_get_renderer(), values[i]); + assert_calls(i + 1, i + 1, 0, 0); + } + assert_string_equal(owned, "owned by the backend"); + assert_true(bnum_allocs() == allocs); + assert_int_equal(log_count, 0); +} + +static void memory_values_bit_for_bit(void **state) +{ + (void)state; + const uint64_t values[] = {0, + 1, + UINT64_C(4294967295), + UINT64_C(4294967296), + UINT64_C(0x8000000000000000), + UINT64_C(0x0123456789abcdef), + UINT64_MAX}; + + gs_enter_context(&graphics); + for (unsigned i = 0; i < sizeof(values) / sizeof(values[0]); i++) { + dmem = values[i]; + smem = ~values[i]; + assert_true(gs_get_gpu_dmem() == values[i]); + assert_true(gs_get_gpu_smem() == ~values[i]); + assert_calls(0, 0, i + 1, i + 1); + } + assert_int_equal(log_count, 0); + assert_string_equal(message, ""); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(no_context, setup, teardown), + cmocka_unit_test_setup_teardown(absent_callbacks, setup, teardown), + cmocka_unit_test_setup_teardown(each_slot_dispatches_alone, setup, teardown), + cmocka_unit_test_setup_teardown(strings_returned_unchanged, setup, teardown), + cmocka_unit_test_setup_teardown(memory_values_bit_for_bit, setup, teardown), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/tests.d/test_graphics_gpu_metadata.cmake b/test/cmocka/tests.d/test_graphics_gpu_metadata.cmake new file mode 100644 index 0000000000..d22c725950 --- /dev/null +++ b/test/cmocka/tests.d/test_graphics_gpu_metadata.cmake @@ -0,0 +1,2 @@ +# Recording-backend GPU metadata characterization; retain through the Rust swap. +# Both target and test are declared in ../build/test-graph.json. From f9c9c9d3196ab2059ec69a5aa827211bb39ff4e2 Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Thu, 19 Nov 2026 16:03:47 -0500 Subject: [PATCH 2/2] graphics: extract GPU metadata entry points without behavior changes Refs #5094. Move gs_get_driver_version, gs_get_renderer, gs_get_gpu_dmem and gs_get_gpu_smem verbatim into graphics-gpu-metadata.c.h in the graphics unity group, keeping the original private context validator. Co-Authored-By: Claude Opus 5.5 Ci-Attestation: {"at":1795123665,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":95,"stamp":"66f650aa204a5b1d2a0a72560ca484e3","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123665,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":95,"stamp":"a733f94becd14dff910cd54208cf9e28","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123665,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":95,"stamp":"07c3aa3e19297f6e59791ee8223a7072","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123665,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":95,"stamp":"5ea3b1330cc74ef636da39f2378f5ef9","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"general/all/client-lint","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"29b201caf596d337174873145caa2e6e","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123665,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":95,"stamp":"a22208a4dc97f895dcb9c2230dec36ec","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123569,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"528eb8827c1ee42cd26af300abc2b0fa","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123569,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"00862b92239ef8617ac46fb5a91ca5c5","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"a9f70b0ccac031554c265f749cc114c3","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"4dba916871db290f8c78ec2025a20dcc","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"448f4b545884afb7853f09326cee1cb2","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"9cabbd0804a451554f2be3003cd33722","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"2034cfcf73dfe0ac9f4782f0e7666ae3","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"e67aea8d158b9d1ff97efa0e4a590437","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"1d404c03e0f77824fbfa481d8ec82961","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"6890d97d0d644648a43f3f1e5a8054dc","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"d52d96b16d169f98e746a4f9e989b995","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123568,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"5d88a23015ce6b87f9b583e29e449f92310bd578bb0c159fe4d89e6c1364c70d","lane":"client-lint","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":65,"stamp":"00fca5a9c4e73fa34146177c70b25c57","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Ci-Attestation: {"at":1795123884,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"3f0335dd4324768b07768642fdea6cb082c55f77badbdaf67527418d24767b43","lane":"client-test-x86_64-unknown-linux-gnu","parents":["3292c1c6ccf3ab08e4d0fc6f78dfc25643c4746e"],"secs":219,"stamp":"0e0383bd4fd5184db0aae036b98df438","tree":"218fa662c803389324529df8bdba792ed5c5974d","v":1,"via":"run"} Client-Checks: {"checks":{"base":"fb7d018d535fabef94fc62230556ce620132f294","coverage":"all-tracked-applicable-files","diff":[".github/workflows/build-project.yaml",".github/workflows/ci.yml","ci/run_base_runner_selector.py","ci/select_mq_runner.py","ci/test_ci_scope.py","ci/test_member_pr_routing.py","ci/test_soldr_cache_report.py","ci/test_tier2_build_setup.py","ci/test_tier2_configure.py","ci/test_tier2_modcache.py","ci/tier2_configure.py","docs/ci-tooling.md","docs/features.md","libobs/audio-monitoring/null/null-audio-monitoring-reference.c.h","libobs/audio-monitoring/null/null-audio-monitoring.c.h","libobs/audio-monitoring/null/null-audio-monitoring.h","libobs/build/libobs-nix.pch.h","libobs/build/libobs-ported-null-audio-monitoring.pch.h","libobs/build/libobs.graphics+.h.c","libobs/build/libobs.ported-null-audio-monitoring+.h.c","libobs/build/ported-source-sets/nix-null-audio-monitoring.json","libobs/cmake/rust-hidden.d/obs-audio-monitoring-null_monitoring.txt","libobs/graphics/graphics-gpu-metadata.c.h","libobs/graphics/graphics.c.h","rust/README.md","rust/obs-audio-monitoring/Cargo.toml","rust/obs-audio-monitoring/src/ffi/mod.rs","rust/obs-audio-monitoring/src/ffi/null_monitoring.rs","rust/obs-audio-monitoring/src/lib.rs","rust/obs-audio-monitoring/src/null_monitoring.rs","rust/obs-audio-monitoring/tests/audio_monitoring/main.rs","rust/obs-audio-monitoring/tests/audio_monitoring/null_monitoring.rs","rust/obs-audio-monitoring/tests/audio_monitoring/null_monitoring_parity.rs","rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_null_audio_monitoring.json","rust/obs-c-oracle/oracle/null_monitoring.c","rust/obs-c-oracle/src/lib.rs","rust/obs-c-oracle/src/null_monitoring.rs","rust/tools/linux-validate/validate.sh","test/cmocka/build/test-graph.json","test/cmocka/test_graphics_gpu_metadata.c","test/cmocka/tests.d/test_graphics_gpu_metadata.cmake"],"head":"cf2e2f4217df51acaccb2ecf051181b88903059e","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"3b10b0c4b8879e960f86b020622c9875a572dfa219aae6f18bde1bafbacfa939","tree":"218fa662c803389324529df8bdba792ed5c5974d"}} --- libobs/build/libobs.graphics+.h.c | 1 + libobs/graphics/graphics-gpu-metadata.c.h | 57 +++++++++++++++++++++++ libobs/graphics/graphics.c.h | 52 --------------------- 3 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 libobs/graphics/graphics-gpu-metadata.c.h diff --git a/libobs/build/libobs.graphics+.h.c b/libobs/build/libobs.graphics+.h.c index 8c40f13883..11973ea70c 100644 --- a/libobs/build/libobs.graphics+.h.c +++ b/libobs/build/libobs.graphics+.h.c @@ -7,6 +7,7 @@ #include "libobs/graphics/effect-parser.c.h" #include "libobs/graphics/graphics-device-load-fields.c.h" #include "libobs/graphics/graphics-device-queries-fields.c.h" +#include "libobs/graphics/graphics-gpu-metadata.c.h" #include "libobs/graphics/graphics-imports.c.h" #include "libobs/graphics/graphics-indexbuffer-maintenance-fields.c.h" #include "libobs/graphics/graphics-render-target-setters-fields.c.h" diff --git a/libobs/graphics/graphics-gpu-metadata.c.h b/libobs/graphics/graphics-gpu-metadata.c.h new file mode 100644 index 0000000000..392998f674 --- /dev/null +++ b/libobs/graphics/graphics-gpu-metadata.c.h @@ -0,0 +1,57 @@ +#include "libobs/build/libobs-graphics.pch.h" + +/* Private dependencies defined in graphics.c.h, later in the unity group. */ +static THREAD_LOCAL graphics_t *thread_graphics; +static inline bool gs_valid(const char *f); + +const char *gs_get_driver_version(void) +{ + graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_get_driver_version")) + return NULL; + + if (graphics->exports.gpu_get_driver_version) + return (graphics->exports.gpu_get_driver_version()); + else + return NULL; +} + +const char *gs_get_renderer(void) +{ + graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_get_renderer")) + return NULL; + + if (graphics->exports.gpu_get_renderer) + return (graphics->exports.gpu_get_renderer()); + else + return NULL; +} + +uint64_t gs_get_gpu_dmem(void) +{ + graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_get_gpu_dmem")) + return 0; + + if (graphics->exports.gpu_get_dmem) + return (graphics->exports.gpu_get_dmem()); + else + return 0; +} + +uint64_t gs_get_gpu_smem(void) +{ + graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_get_gpu_smem")) + return 0; + + if (graphics->exports.gpu_get_smem) + return (graphics->exports.gpu_get_smem()); + else + return 0; +} diff --git a/libobs/graphics/graphics.c.h b/libobs/graphics/graphics.c.h index cd5a4c0ca1..6f434af7a9 100644 --- a/libobs/graphics/graphics.c.h +++ b/libobs/graphics/graphics.c.h @@ -334,58 +334,6 @@ const char *gs_get_device_name(void) return gs_valid("gs_get_device_name") ? thread_graphics->exports.device_get_name() : NULL; } -const char *gs_get_driver_version(void) -{ - graphics_t *graphics = thread_graphics; - - if (!gs_valid("gs_get_driver_version")) - return NULL; - - if (graphics->exports.gpu_get_driver_version) - return (graphics->exports.gpu_get_driver_version()); - else - return NULL; -} - -const char *gs_get_renderer(void) -{ - graphics_t *graphics = thread_graphics; - - if (!gs_valid("gs_get_renderer")) - return NULL; - - if (graphics->exports.gpu_get_renderer) - return (graphics->exports.gpu_get_renderer()); - else - return NULL; -} - -uint64_t gs_get_gpu_dmem(void) -{ - graphics_t *graphics = thread_graphics; - - if (!gs_valid("gs_get_gpu_dmem")) - return 0; - - if (graphics->exports.gpu_get_dmem) - return (graphics->exports.gpu_get_dmem()); - else - return 0; -} - -uint64_t gs_get_gpu_smem(void) -{ - graphics_t *graphics = thread_graphics; - - if (!gs_valid("gs_get_gpu_smem")) - return 0; - - if (graphics->exports.gpu_get_smem) - return (graphics->exports.gpu_get_smem()); - else - return 0; -} - static inline void reset_immediate_arrays(graphics_t *graphics) { da_init(graphics->verts);