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
1 change: 0 additions & 1 deletion libobs/build/libobs.graphics+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "libobs/graphics/graphics-device-queries-fields.c.h"
#include "libobs/graphics/graphics-imports.c.h"
#include "libobs/graphics/graphics-indexbuffer-maintenance-fields.c.h"
#include "libobs/graphics/graphics-planar-capability-queries.c.h"
#include "libobs/graphics/graphics-render-target-setters-fields.c.h"
#include "libobs/graphics/graphics-samplerstate-lifecycle-fields.c.h"
#include "libobs/graphics/graphics-shader-matrix-queries-fields.c.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Unity group (BUILD.md): original planar capability queries for the C reference. */
#include "libobs/build/libobs-graphics.pch.h"

#include "libobs/graphics/graphics-planar-capability-queries.c.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-graphics-planar-capability-queries+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gs_nv12_available
gs_p010_available
24 changes: 24 additions & 0 deletions libobs/graphics/graphics-device-queries-fields.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,27 @@ uint32_t obs_graphics_device_queries_count(graphics_t *graphics)
{
return graphics->exports.gs_get_adapter_count();
}

bool obs_graphics_device_queries_has_nv12(graphics_t *graphics);
bool obs_graphics_device_queries_has_nv12(graphics_t *graphics)
{
return graphics->exports.device_nv12_available != NULL;
}

bool obs_graphics_device_queries_nv12(graphics_t *graphics);
bool obs_graphics_device_queries_nv12(graphics_t *graphics)
{
return graphics->exports.device_nv12_available(graphics->device);
}

bool obs_graphics_device_queries_has_p010(graphics_t *graphics);
bool obs_graphics_device_queries_has_p010(graphics_t *graphics)
{
return graphics->exports.device_p010_available != NULL;
}

bool obs_graphics_device_queries_p010(graphics_t *graphics);
bool obs_graphics_device_queries_p010(graphics_t *graphics)
{
return graphics->exports.device_p010_available(graphics->device);
}
20 changes: 17 additions & 3 deletions libobs/graphics/graphics-planar-capability-queries.c.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#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);
/* Reference-only: read the existing TLS context without owning another one. */
#define thread_graphics gs_get_context()

static inline bool planar_capability_ref_valid(const char *f)
{
if (!thread_graphics) {
blog(LOG_DEBUG, "%s: called while not in a graphics context", f);
return false;
}

return true;
}

#define gs_valid planar_capability_ref_valid

bool gs_nv12_available(void)
{
Expand All @@ -25,3 +36,6 @@ bool gs_p010_available(void)

return thread_graphics->exports.device_p010_available(thread_graphics->device);
}

#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 @@ -155,6 +155,7 @@ and compares their exported symbols. `OBS_LIBOBS_BACKEND=C` is temporary rollbac
| `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-planar-capability-queries.c.h` | `obs-graphics::planar_capability_queries` | Swapped in hybrid `libobs` (Refs #5218; prerequisite #5217). Safe Rust checks context and optional NV12/P010 callbacks before dispatch through the existing device-query seam and shared demand-linked support archive. Unchanged fake-device Tier 2 characterization, Tier 1 mirrors and Tier 3 original-C differential sequences preserve exact diagnostics, independent dispatch, results and device identity. No host GPU assumptions or intentional differences; Tier 4 does not apply. |
| `libobs/graphics/graphics-shader-matrix-queries.c.h` | `obs-graphics::shader_matrix_queries` | Swapped in hybrid `libobs` (Refs #5185; prerequisite #5132/#5184). Safe Rust checks context before shader, then private C adapters dispatch the viewproj/world callback with the exact shader pointer and return the borrowed parameter unchanged, NULL included. Exact LOG_DEBUG messages and single dispatch agree with the reference-only C and a verbatim legacy oracle. Tier 1 mirrors unchanged `test_shader_matrix_queries`; Tier 3 compares boundary matrices and bounded random sequences through the real ABI and adapters in the existing Graphics category binary. 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. |
Expand Down
27 changes: 27 additions & 0 deletions rust/obs-c-oracle/legacy/graphics-planar-capability-queries.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#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);

bool gs_nv12_available(void)
{
if (!gs_valid("gs_nv12_available"))
return false;

if (!thread_graphics->exports.device_nv12_available)
return false;

return thread_graphics->exports.device_nv12_available(thread_graphics->device);
}

bool gs_p010_available(void)
{
if (!gs_valid("gs_p010_available"))
return false;

if (!thread_graphics->exports.device_p010_available)
return false;

return thread_graphics->exports.device_p010_available(thread_graphics->device);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graphics-planar-capability-queries.inc|rust/obs-c-oracle/legacy/graphics-planar-capability-queries.c|auto
59 changes: 59 additions & 0 deletions rust/obs-c-oracle/oracle/device_queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ static void dq_blog(int level, const char *format, ...)
#define blog dq_blog
#include "graphics-device-queries.inc"

#define gs_nv12_available oracle_gs_nv12_available
#define gs_p010_available oracle_gs_p010_available
bool oracle_gs_nv12_available(void);
bool oracle_gs_p010_available(void);
#include "graphics-planar-capability-queries.inc"
#undef gs_p010_available
#undef gs_nv12_available

/* Original graphics.c.h context validator, verbatim. */
static inline bool gs_valid(const char *f)
{
Expand Down Expand Up @@ -114,3 +122,54 @@ const char *oracle_device_queries_log(void)

#undef gs_get_adapter_count
#undef gs_get_device_type

/* Planar queries share the real device-query TLS/logging adapters above. */
static THREAD_LOCAL int dq_planar_devices[2];
static THREAD_LOCAL bool dq_planar_results[2];
static THREAD_LOCAL unsigned dq_planar_calls[2], dq_planar_last_device;

static bool dq_planar_nv12(gs_device_t *device)
{
assert(thread_graphics == &dq_graphics);
assert(device == dq_graphics.device);
assert(device == (gs_device_t *)&dq_planar_devices[0] || device == (gs_device_t *)&dq_planar_devices[1]);
dq_planar_last_device = device == (gs_device_t *)&dq_planar_devices[1] ? 1u : 0u;
dq_planar_calls[0]++;
return dq_planar_results[0];
}

static bool dq_planar_p010(gs_device_t *device)
{
assert(thread_graphics == &dq_graphics);
assert(device == dq_graphics.device);
assert(device == (gs_device_t *)&dq_planar_devices[0] || device == (gs_device_t *)&dq_planar_devices[1]);
dq_planar_last_device = device == (gs_device_t *)&dq_planar_devices[1] ? 1u : 0u;
dq_planar_calls[1]++;
return dq_planar_results[1];
}

void oracle_planar_capability_reset(bool context, bool nv12, bool p010, bool nv12_result, bool p010_result,
bool device);
void oracle_planar_capability_reset(bool context, bool nv12, bool p010, bool nv12_result, bool p010_result, bool device)
{
oracle_device_queries_reset(context, false, false, 0, 0);
dq_graphics.device = (gs_device_t *)&dq_planar_devices[device ? 1 : 0];
dq_graphics.exports.device_nv12_available = nv12 ? dq_planar_nv12 : NULL;
dq_graphics.exports.device_p010_available = p010 ? dq_planar_p010 : NULL;
dq_planar_results[0] = nv12_result;
dq_planar_results[1] = p010_result;
dq_planar_calls[0] = dq_planar_calls[1] = 0;
dq_planar_last_device = 2;
}

unsigned oracle_planar_capability_calls(bool p010);
unsigned oracle_planar_capability_calls(bool p010)
{
return dq_planar_calls[p010 ? 1 : 0];
}

unsigned oracle_planar_capability_last_device(void);
unsigned oracle_planar_capability_last_device(void)
{
return dq_planar_last_device;
}
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 @@ -39,6 +39,7 @@ pub mod matrix3;
pub mod matrix4;
pub mod matrix_entrypoints;
pub mod perspective;
pub mod planar_capability_queries;
pub mod plane;
pub mod present_entrypoints;
pub mod quat;
Expand Down
67 changes: 67 additions & 0 deletions rust/obs-graphics/src/ffi/planar_capability_queries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//! Thin ABI shims using the existing device-query TLS/logging/field seam.
use crate::planar_capability_queries::{self as core, Entry, Host};
use std::ffi::{c_char, c_void};

unsafe extern "C" {
fn obs_graphics_device_queries_context() -> *mut c_void;
fn obs_graphics_device_queries_debug(function: *const c_char);
fn obs_graphics_device_queries_has_nv12(context: *mut c_void) -> bool;
fn obs_graphics_device_queries_nv12(context: *mut c_void) -> bool;
fn obs_graphics_device_queries_has_p010(context: *mut c_void) -> bool;
fn obs_graphics_device_queries_p010(context: *mut c_void) -> bool;
}

struct Context(*mut c_void);

fn current() -> Context {
// SAFETY: reads the calling thread's context without dereferencing it.
Context(unsafe { obs_graphics_device_queries_context() })
}

impl Host for Context {
fn has_context(&self) -> bool {
!self.0.is_null()
}
fn debug(&mut self, entry: Entry) {
let name = match entry {
Entry::Nv12 => c"gs_nv12_available",
Entry::P010 => c"gs_p010_available",
};
// SAFETY: the function name is static and NUL-terminated.
unsafe { obs_graphics_device_queries_debug(name.as_ptr()) }
}
fn has_callback(&self, entry: Entry) -> bool {
// SAFETY: the core checked the context before any field projection.
unsafe {
match entry {
Entry::Nv12 => obs_graphics_device_queries_has_nv12(self.0),
Entry::P010 => obs_graphics_device_queries_has_p010(self.0),
}
}
}
fn dispatch(&mut self, entry: Entry) -> bool {
// SAFETY: the core checked context and the matching callback first.
unsafe {
match entry {
Entry::Nv12 => obs_graphics_device_queries_nv12(self.0),
Entry::P010 => obs_graphics_device_queries_p010(self.0),
}
}
}
}

/// Query the optional NV12 backend capability.
/// # Safety
/// A current context and any supplied backend callback must be live.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn gs_nv12_available() -> bool {
core::available(&mut current(), Entry::Nv12)
}

/// Query the optional P010 backend capability.
/// # Safety
/// A current context and any supplied backend callback must be live.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn gs_p010_available() -> bool {
core::available(&mut current(), Entry::P010)
}
1 change: 1 addition & 0 deletions rust/obs-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub mod matrix3;
pub mod matrix4;
pub mod matrix_entrypoints;
pub mod perspective;
pub mod planar_capability_queries;
pub mod plane;
mod platform;
pub mod present_entrypoints;
Expand Down
32 changes: 32 additions & 0 deletions rust/obs-graphics/src/planar_capability_queries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! Optional planar capability queries over a caller-owned graphics context.

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Entry {
Nv12,
P010,
}

impl Entry {
pub const fn name(self) -> &'static str {
match self {
Self::Nv12 => "gs_nv12_available",
Self::P010 => "gs_p010_available",
}
}
}

/// Field access and dispatch are reached only after the corresponding checks.
pub trait Host {
fn has_context(&self) -> bool;
fn debug(&mut self, entry: Entry);
fn has_callback(&self, entry: Entry) -> bool;
fn dispatch(&mut self, entry: Entry) -> bool;
}

pub fn available<H: Host>(host: &mut H, entry: Entry) -> bool {
if !host.has_context() {
host.debug(entry);
return false;
}
host.has_callback(entry) && host.dispatch(entry)
}
2 changes: 2 additions & 0 deletions rust/obs-graphics/tests/render/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ mod matrix_entrypoints;
mod matrix_entrypoints_parity;
mod perspective;
mod perspective_parity;
mod planar_capability_queries;
mod planar_capability_queries_parity;
mod present_entrypoints;
mod present_entrypoints_parity;
mod raster_entrypoints;
Expand Down
Loading
Loading