capi: more docs

This commit is contained in:
chyyran 2022-12-04 22:48:57 -05:00
parent 45913c32bf
commit 6ab03ecc99
12 changed files with 58 additions and 9 deletions

1
Cargo.lock generated
View file

@ -558,6 +558,7 @@ dependencies = [
"paste",
"safer-ffi",
"thiserror",
"windows",
]
[[package]]

View file

@ -16,8 +16,9 @@ publish = false
crate-type = [ "cdylib", "staticlib", "lib" ]
[features]
#default = ["runtime-opengl"]
default = ["runtime-opengl", "runtime-d3d11"]
runtime-opengl = ["gl", "librashader/gl"]
runtime-d3d11 = ["windows", "librashader/d3d11"]
headers = ["safer-ffi/headers"]
[dependencies]
@ -27,5 +28,23 @@ paste = "1.0.9"
gl = { version = "0.14.0", optional = true }
safer-ffi = { version = "0.0.10", repository = "https://github.com/getditto/safer_ffi" }
[dependencies.windows]
version = "0.43.0"
features = [
"Win32_Foundation",
"Win32_Graphics_Dxgi_Common",
"Win32_Graphics_Direct3D",
"Win32_Graphics_Direct3D11",
"Win32_Graphics_Direct3D_Fxc",
"Win32_Graphics_Gdi",
"Win32_Security",
"Win32_System_LibraryLoader",
"Win32_System_Threading",
"Win32_System_WindowsProgramming",
"Win32_UI_WindowsAndMessaging",
]
optional = true
[build-dependencies]
cbindgen = "0.24.3"

View file

@ -86,8 +86,6 @@ typedef struct frame_gl_opt_t {
int32_t frame_direction;
} frame_gl_opt_t;
typedef libra_error_t (*PFN_lbr_load_preset)(const char*, libra_shader_preset_t*);
typedef libra_error_t (*PFN_lbr_preset_free)(libra_shader_preset_t*);
typedef libra_error_t (*PFN_lbr_preset_set_param)(libra_shader_preset_t*, const char*, float);
@ -109,7 +107,7 @@ extern "C" {
/// - `out` must be either null, or an aligned pointer to an uninitialized or invalid `libra_shader_preset_t`.
/// ## Returns
/// - If any parameters are null, `out` is unchanged, and this function returns `LIBRA_ERR_INVALID_PARAMETER`.
libra_error_t libra_load_preset(const char *filename,
libra_error_t libra_preset_create(const char *filename,
libra_shader_preset_t *out);
/// Free the preset.

View file

@ -1,3 +1,4 @@
//! Binding types for the librashader C API.
use std::ptr::NonNull;
use librashader::presets::ShaderPreset;
use crate::error::LibrashaderError;
@ -8,6 +9,9 @@ pub type libra_error_t = Option<NonNull<LibrashaderError>>;
#[cfg(feature = "runtime-opengl")]
pub type libra_gl_filter_chain_t = Option<NonNull<librashader::runtime::gl::FilterChainGL>>;
#[cfg(feature = "runtime-d3d11")]
pub type libra_d3d11_filter_chain_t = Option<NonNull<librashader::runtime::d3d11::FilterChainD3D11>>;
/// Parameters for the output viewport.
#[repr(C)]
pub struct libra_viewport_t {

View file

@ -1,3 +1,4 @@
//! The librashader error C API. (`libra_error_*`).
use std::any::Any;
use std::ffi::{c_char, CStr, CString};
use std::mem::MaybeUninit;

View file

@ -1,3 +1,4 @@
//! The librashader preset C API (`libra_preset_*`).
use std::ffi::{c_char, CStr, CString};
use std::mem::{MaybeUninit};
use librashader::presets::ShaderPreset;
@ -32,7 +33,7 @@ use std::ptr::NonNull;
// }
// }
pub type PFN_lbr_load_preset = unsafe extern "C" fn (*const c_char, *mut MaybeUninit<libra_shader_preset_t>) -> libra_error_t;
pub type PFN_lbr_preset_create = unsafe extern "C" fn (*const c_char, *mut MaybeUninit<libra_shader_preset_t>) -> libra_error_t;
/// Load a preset.
///
@ -42,7 +43,7 @@ pub type PFN_lbr_load_preset = unsafe extern "C" fn (*const c_char, *mut MaybeUn
/// ## Returns
/// - If any parameters are null, `out` is unchanged, and this function returns `LIBRA_ERR_INVALID_PARAMETER`.
#[no_mangle]
pub unsafe extern "C" fn libra_load_preset(filename: *const c_char, out: *mut MaybeUninit<libra_shader_preset_t>) -> libra_error_t {
pub unsafe extern "C" fn libra_preset_create(filename: *const c_char, out: *mut MaybeUninit<libra_shader_preset_t>) -> libra_error_t {
ffi_body!({
assert_non_null!(filename);
assert_non_null!(out);

View file

@ -0,0 +1,4 @@
//! C API for the librashader OpenGL Runtime (`libra_d3d11_*`)
mod filter_chain;
pub use filter_chain::*;

View file

@ -1 +1,4 @@
pub mod filter_chain;
//! C API for the librashader OpenGL Runtime (`libra_gl_*`)
mod filter_chain;
pub use filter_chain::*;

View file

@ -1,2 +1,6 @@
//! librashader runtime C APIs
#[cfg(feature = "runtime-opengl")]
mod gl;
pub mod gl;
#[cfg(feature = "runtime-d3d11")]
pub mod d3d11;

View file

@ -1,12 +1,20 @@
/// Options for each Direct3D11 shader frame.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FrameOptionsD3D11 {
/// Whether or not to clear the history buffers.
pub clear_history: bool,
/// The direction of the frame. 1 should be vertical.
pub frame_direction: i32,
}
/// Options for Direct3D11 filter chain creation.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FilterChainOptionsD3D11 {
/// Use a deferred context to record shader rendering state.
///
/// The deferred context will be executed on the immediate context
/// with `RenderContextState = true`.
pub use_deferred_context: bool,
}

View file

@ -1,13 +1,19 @@
/// Options for each OpenGL shader frame.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FrameOptionsGL {
/// Whether or not to clear the history buffers.
pub clear_history: bool,
/// The direction of the frame. 1 should be vertical.
pub frame_direction: i32,
}
/// Options for filter chain creation.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FilterChainOptionsGL {
/// The GLSL version. Should be at least `330`.
pub gl_version: u16,
/// Whether or not to use the Direct State Access APIs. Only available on OpenGL 4.5+.
pub use_dsa: bool,
}