Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libobs/build/libobs.graphics+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#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"
#include "libobs/graphics/graphics-samplerstate-lifecycle.c.h"
#include "libobs/graphics/graphics-samplerstate-lifecycle-fields.c.h"
#include "libobs/graphics/graphics-shader-params-adapter.c.h"
#include "libobs/graphics/graphics-target-size-fields.c.h"
#include "libobs/graphics/graphics-texture-copy-fields.c.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Unity group (BUILD.md): original sampler lifecycle for the C reference. */
#include "libobs/build/libobs-graphics.pch.h"

#include "libobs/graphics/graphics-samplerstate-lifecycle.c.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-graphics-samplerstate-lifecycle+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gs_samplerstate_create
gs_samplerstate_destroy
23 changes: 23 additions & 0 deletions libobs/graphics/graphics-samplerstate-lifecycle-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "libobs/build/libobs-graphics.pch.h"

/* Native layout and vtable dispatch only; Rust guards context before access. */
graphics_t *obs_graphics_samplerstate_context(void);
graphics_t *obs_graphics_samplerstate_context(void)
{
return gs_get_context();
}
void obs_graphics_samplerstate_debug(const char *function, const char *reason);
void obs_graphics_samplerstate_debug(const char *function, const char *reason)
{
blog(LOG_DEBUG, "%s: %s", function, reason);
}
gs_samplerstate_t *obs_graphics_samplerstate_create(graphics_t *graphics, const struct gs_sampler_info *info);
gs_samplerstate_t *obs_graphics_samplerstate_create(graphics_t *graphics, const struct gs_sampler_info *info)
{
return graphics->exports.device_samplerstate_create(graphics->device, info);
}
void obs_graphics_samplerstate_destroy(graphics_t *graphics, gs_samplerstate_t *samplerstate);
void obs_graphics_samplerstate_destroy(graphics_t *graphics, gs_samplerstate_t *samplerstate)
{
graphics->exports.gs_samplerstate_destroy(samplerstate);
}
28 changes: 23 additions & 5 deletions libobs/graphics/graphics-samplerstate-lifecycle.c.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#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);
static inline bool gs_obj_valid(const void *obj, const char *f, const char *name);

/* Reference-only original bodies over the C-owned TLS context getter. */
#define thread_graphics gs_get_context()
static inline bool samplerstate_ref_valid(const char *f)
{
if (!thread_graphics) {
blog(LOG_DEBUG, "%s: called while not in a graphics context", f);
return false;
}
return true;
}
static inline bool samplerstate_ref_obj_valid(const void *obj, const char *f, const char *name)
{
if (!obj) {
blog(LOG_DEBUG, "%s: Null '%s' parameter", f, name);
return false;
}
return true;
}
#define gs_valid samplerstate_ref_valid
#define gs_obj_valid samplerstate_ref_obj_valid
#define gs_valid_p(func, param1) (gs_valid(func) && gs_obj_valid(param1, func, #param1))

gs_samplerstate_t *gs_samplerstate_create(const struct gs_sampler_info *info)
Expand All @@ -28,3 +43,6 @@ void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate)
}

#undef gs_valid_p
#undef gs_obj_valid
#undef gs_valid
#undef thread_graphics
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ and compares their exported symbols. `OBS_LIBOBS_BACKEND=C` is temporary rollbac
| `libobs/graphics/graphics-device-queries.c.h` | `obs-graphics::device_queries` | Swapped in hybrid `libobs` (Refs #5070; prerequisite #5068). Safe Rust checks context before private C field/dispatch adapters, distinguishes missing context from backend -1/zero, and preserves the optional adapter-count callback fallback and exact diagnostics. Original bodies remain reference-only and in a verbatim legacy oracle. Tier 1 mirrors unchanged `test_graphics_device_queries`; Tier 3 compares signed/unsigned boundaries and bounded random queries through the real adapters in the existing graphics binary. |
| `libobs/graphics/graphics-indexbuffer-maintenance.c.h` | `obs-graphics::indexbuffer_maintenance` | Swapped in hybrid `libobs` (#5049; prerequisite #5046, Refs #5039). The four maintenance entry points preserve context-before-pointer guards, silent NULL destroy in context, direct-data rejection order, exact diagnostics, pointer identity and full `size_t` forwarding. Safe Rust owns validation; private C adapters own layout and dispatch. Original C remains in a reference-only group and a verbatim legacy oracle copy. Tier 1 mirrors unchanged `test_graphics_indexbuffer_maintenance`; Tier 3 compares boundary matrices and bounded random inputs through the Rust ABI in the existing Graphics category binary. No intentional differences; Tier 4 does not apply. |
| `libobs/graphics/graphics-render-target-setters.c.h` | `obs-graphics::render_target_setters` | Swapped in hybrid `libobs` (#5076; prerequisite #5058 / #5048). Safe Rust guards the context before private C layout/dispatch adapters; both nullable target/depth handles and every cube face value reach the backend unchanged. Exact diagnostics, device/pointer identity and single dispatch are preserved. Original C remains reference-only and in a verbatim legacy oracle. Tier 1 mirrors unchanged `test_graphics_render_target_setters`; Tier 3 compares boundary matrices and bounded random sequences through the Rust ABI in the existing Graphics category binary. No intentional differences; Tier 4 does not apply. |
| `libobs/graphics/graphics-samplerstate-lifecycle.c.h` | `obs-graphics::samplerstate_lifecycle` | Swapped in hybrid `libobs` (Refs #5149; prerequisite #5128/#5148). Safe Rust preserves context-before-argument validation, exact LOG_DEBUG diagnostics, silent NULL destruction in context, settings/opaque-handle identity and backend failure returns. Private C adapters retain TLS, native layouts and exact device-vtable dispatch; sampler objects stay backend-owned without wrapper allocation or tracking. Tier 1 mirrors all four unchanged C characterization cases; Tier 3 compares the original C and real Rust ABI/adapters over boundary and bounded random sequences in the Graphics category. No intentional differences; Tier 4 does not apply. |
| `libobs/graphics/graphics-target-size.c.h` | `obs-graphics::target_size` | Swapped in hybrid `libobs` (Refs #5100; prerequisite #5087/#5107). Safe Rust checks context before private C layout/dispatch adapters, preserves zero scalar defaults and untouched outputs without context, and forwards nullable/aliased outputs unchanged. Exact LOG_DEBUG messages, device/output identities and single matching callbacks agree with the reference-only C and verbatim legacy oracle. Tier 1 mirrors unchanged `test_graphics_target_size`; Tier 3 covers boundary and bounded random queries in the existing Graphics category binary. No intentional differences; Tier 4 does not apply. |
| `libobs/graphics/graphics-texture-copy.c.h` | `obs-graphics::texture_copy` | Swapped in hybrid `libobs` (Refs #5062; prerequisite #5074/#5059). Safe Rust preserves context-before-pointer validation, whole-copy destination-then-source guards and region-copy destination-only validation, including NULL sources, aliasing and all six unchanged offsets/extents. Private C adapters own layout and backend dispatch. Exact LOG_DEBUG messages, device and texture identity match the reference-only original C and verbatim Tier 3 legacy oracle. Tier 1 mirrors unchanged `test_graphics_texture_copy`; Tier 3 compares boundary matrices and bounded random inputs through the real ABI and adapters in the existing Graphics category binary. No intentional differences; Tier 4 does not apply. |
| `libobs/graphics/graphics-viewport.c.h` | `obs-graphics::viewport` | Full-target viewport, pixel-space projection and optional maximum-texture capability policy (#4429). Context validation and backend dispatch remain C; callback zero overrides API fallbacks. Unchanged public-API C characterization, safe-core tests and exact original-C differential traces. No intentional differences. |
Expand Down
2 changes: 2 additions & 0 deletions rust/obs-build/tests/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod canonical_graphics_device_queries_swap_is_registered;
mod canonical_graphics_indexbuffer_maintenance_swap_is_registered;
#[path = "native/registration/canonical_graphics_render_target_setters_swap_is_registered.rs"]
mod canonical_graphics_render_target_setters_swap_is_registered;
#[path = "native/registration/canonical_graphics_samplerstate_lifecycle_swap_is_registered.rs"]
mod canonical_graphics_samplerstate_lifecycle_swap_is_registered;
#[path = "native/registration/canonical_graphics_target_size_swap_is_registered.rs"]
mod canonical_graphics_target_size_swap_is_registered;
#[path = "native/registration/canonical_graphics_texture_copy_swap_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use super::*;

#[test]
fn canonical_graphics_samplerstate_lifecycle_swap_is_registered() {
use obs_build::validation::graph::{Graph, Source};
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let mut graph = Graph::load(&root.join("test/cmocka/build/test-graph.json")).unwrap();
let name = "test_samplerstate_lifecycle";
graph.targets.retain(|key, _| key == name);
graph.tests.retain(|key, _| key == name);
for os in ["OS_LINUX", "OS_MACOS", "OS_WINDOWS"] {
let selected = graph.select(&[(os.into(), true)].into()).unwrap();
assert!(
matches!(selected.targets[name].sources.as_slice(), [Source::Path(path)]
if path == "test/cmocka/test_samplerstate_lifecycle.c")
);
assert_eq!(selected.tests[name].target, name);
}
let ported = fs::read_to_string(
root.join("libobs/build/ported-source-sets/graphics-samplerstate-lifecycle.json"),
)
.unwrap();
assert!(ported.contains("build/libobs.ported-graphics-samplerstate-lifecycle+.h.c"));
let group = fs::read_to_string(
root.join("libobs/build/libobs.ported-graphics-samplerstate-lifecycle+.h.c"),
)
.unwrap();
assert!(group.contains("#include \"libobs/graphics/graphics-samplerstate-lifecycle.c.h\""));
let hybrid = fs::read_to_string(root.join("libobs/build/libobs.graphics+.h.c")).unwrap();
assert!(!hybrid.contains("#include \"libobs/graphics/graphics-samplerstate-lifecycle.c.h\""));
assert!(
hybrid.contains("#include \"libobs/graphics/graphics-samplerstate-lifecycle-fields.c.h\"")
);
}
30 changes: 30 additions & 0 deletions rust/obs-c-oracle/legacy/graphics-samplerstate-lifecycle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#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);
static inline bool gs_obj_valid(const void *obj, const char *f, const char *name);

#define gs_valid_p(func, param1) (gs_valid(func) && gs_obj_valid(param1, func, #param1))

gs_samplerstate_t *gs_samplerstate_create(const struct gs_sampler_info *info)
{
graphics_t *graphics = thread_graphics;

if (!gs_valid_p("gs_samplerstate_create", info))
return NULL;

return graphics->exports.device_samplerstate_create(graphics->device, info);
}

void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate)
{
if (!gs_valid("gs_samplerstate_destroy"))
return;
if (!samplerstate)
return;

thread_graphics->exports.gs_samplerstate_destroy(samplerstate);
}

#undef gs_valid_p
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graphics-samplerstate-lifecycle-fields.inc|libobs/graphics/graphics-samplerstate-lifecycle-fields.c.h|auto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graphics-samplerstate-lifecycle.inc|rust/obs-c-oracle/legacy/graphics-samplerstate-lifecycle.c|auto
165 changes: 165 additions & 0 deletions rust/obs-c-oracle/oracle/samplerstate_lifecycle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* Original C and real adapter over a thread-local recording backend. */
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#define gs_samplerstate_create oracle_gs_samplerstate_create
#define gs_samplerstate_destroy oracle_gs_samplerstate_destroy
#include "graphics/graphics-internal.h"
#include "util/base.h"

gs_samplerstate_t *oracle_gs_samplerstate_create(const struct gs_sampler_info *info);
void oracle_gs_samplerstate_destroy(gs_samplerstate_t *samplerstate);
static THREAD_LOCAL struct graphics_subsystem sl_graphics;
static THREAD_LOCAL int sl_device, sl_tokens[2];
static THREAD_LOCAL struct gs_sampler_info sl_infos[2], sl_before[2];
static THREAD_LOCAL const struct gs_sampler_info *sl_expected_info;
static THREAD_LOCAL gs_samplerstate_t *sl_result, *sl_expected_sampler;
static THREAD_LOCAL unsigned sl_calls[2], sl_logs, sl_event_count;
static THREAD_LOCAL int sl_level;
static THREAD_LOCAL char sl_log[160], sl_events[128];
static void sl_record(char event)
{
assert(sl_event_count + 1 < sizeof(sl_events));
sl_events[sl_event_count++] = event;
sl_events[sl_event_count] = '\0';
}
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
static void sl_blog(int level, const char *format, ...)
{
va_list args;
va_start(args, format);
sl_logs++;
sl_level = level;
vsnprintf(sl_log, sizeof(sl_log), format, args);
va_end(args);
sl_record('L');
}
#define blog sl_blog
#include "graphics-samplerstate-lifecycle.inc"
/* Original validators from graphics.c.h, verbatim. */
static inline bool gs_valid(const char *f)
{
if (!thread_graphics) {
blog(LOG_DEBUG, "%s: called while not in a graphics context", f);
return false;
}

return true;
}
static inline bool gs_obj_valid(const void *obj, const char *f, const char *name)
{
if (!obj) {
blog(LOG_DEBUG, "%s: Null '%s' parameter", f, name);
return false;
}

return true;
}
static graphics_t *sl_context(void)
{
return thread_graphics;
}
#define gs_get_context sl_context
#include "graphics-samplerstate-lifecycle-fields.inc"
#undef gs_get_context
#undef blog

static gs_samplerstate_t *sl_create(gs_device_t *device, const struct gs_sampler_info *info)
{
assert(thread_graphics == &sl_graphics);
assert(device == (gs_device_t *)&sl_device);
assert(info == sl_expected_info);
sl_calls[0]++;
sl_record('C');
return sl_result;
}
static void sl_destroy(gs_samplerstate_t *sampler)
{
assert(thread_graphics == &sl_graphics);
assert(sampler == sl_expected_sampler);
sl_calls[1]++;
sl_record('D');
}
void oracle_samplerstate_reset(void);
void oracle_samplerstate_reset(void)
{
memset(&sl_graphics, 0, sizeof(sl_graphics));
sl_graphics.device = (gs_device_t *)&sl_device;
memset(sl_infos, 0, sizeof(sl_infos));
memset(sl_before, 0, sizeof(sl_before));
memset(sl_calls, 0, sizeof(sl_calls));
sl_logs = sl_event_count = 0;
sl_level = 0;
sl_log[0] = sl_events[0] = '\0';
thread_graphics = NULL;
}
const struct gs_sampler_info *oracle_samplerstate_info(unsigned slot, unsigned filter, unsigned u, unsigned v,
unsigned w, int anisotropy, uint32_t border);
const struct gs_sampler_info *oracle_samplerstate_info(unsigned slot, unsigned filter, unsigned u, unsigned v,
unsigned w, int anisotropy, uint32_t border)
{
assert(slot < 2 && filter <= GS_FILTER_MIN_MAG_LINEAR_MIP_POINT);
assert(u <= GS_ADDRESS_MIRRORONCE && v <= GS_ADDRESS_MIRRORONCE && w <= GS_ADDRESS_MIRRORONCE);
sl_infos[slot] = (struct gs_sampler_info){(enum gs_sample_filter)filter,
(enum gs_address_mode)u,
(enum gs_address_mode)v,
(enum gs_address_mode)w,
anisotropy,
border};
memcpy(&sl_before[slot], &sl_infos[slot], sizeof(sl_infos[slot]));
return &sl_infos[slot];
}
gs_samplerstate_t *oracle_samplerstate_token(unsigned slot);
gs_samplerstate_t *oracle_samplerstate_token(unsigned slot)
{
assert(slot < 2);
return (gs_samplerstate_t *)&sl_tokens[slot];
}
void oracle_samplerstate_configure(bool context, unsigned callbacks, const struct gs_sampler_info *info,
gs_samplerstate_t *result, gs_samplerstate_t *sampler);
void oracle_samplerstate_configure(bool context, unsigned callbacks, const struct gs_sampler_info *info,
gs_samplerstate_t *result, gs_samplerstate_t *sampler)
{
thread_graphics = context ? &sl_graphics : NULL;
sl_graphics.exports.device_samplerstate_create = (callbacks & 1) ? sl_create : NULL;
sl_graphics.exports.gs_samplerstate_destroy = (callbacks & 2) ? sl_destroy : NULL;
sl_expected_info = info;
sl_result = result;
sl_expected_sampler = sampler;
}
unsigned oracle_samplerstate_calls(unsigned index);
unsigned oracle_samplerstate_calls(unsigned index)
{
assert(index < 2);
return sl_calls[index];
}
unsigned oracle_samplerstate_logs(void);
unsigned oracle_samplerstate_logs(void)
{
return sl_logs;
}
int oracle_samplerstate_level(void);
int oracle_samplerstate_level(void)
{
return sl_level;
}
const char *oracle_samplerstate_log(void);
const char *oracle_samplerstate_log(void)
{
return sl_log;
}
const char *oracle_samplerstate_events(void);
const char *oracle_samplerstate_events(void)
{
return sl_events;
}
bool oracle_samplerstate_unchanged(void);
bool oracle_samplerstate_unchanged(void)
{
return memcmp(sl_infos, sl_before, sizeof(sl_infos)) == 0;
}
#undef gs_samplerstate_create
#undef gs_samplerstate_destroy
1 change: 1 addition & 0 deletions rust/obs-graphics/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod present_entrypoints;
pub mod quat;
pub mod raster_entrypoints;
pub mod render_target_setters;
pub mod samplerstate_lifecycle;
pub mod shader_file;
pub mod shader_param_introspection;
pub mod shader_param_names;
Expand Down
Loading
Loading