diff --git a/Cargo.lock b/Cargo.lock index 38dc7b0..47cc2c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -558,6 +558,7 @@ dependencies = [ "paste", "safer-ffi", "thiserror", + "windows", ] [[package]] diff --git a/librashader-capi/Cargo.toml b/librashader-capi/Cargo.toml index 6bc76b7..3603571 100644 --- a/librashader-capi/Cargo.toml +++ b/librashader-capi/Cargo.toml @@ -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" diff --git a/librashader-capi/librashader.h b/librashader-capi/librashader.h index beaa6e2..3abf8a9 100644 --- a/librashader-capi/librashader.h +++ b/librashader-capi/librashader.h @@ -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,8 +107,8 @@ 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_shader_preset_t *out); +libra_error_t libra_preset_create(const char *filename, + libra_shader_preset_t *out); /// Free the preset. /// diff --git a/librashader-capi/src/ctypes.rs b/librashader-capi/src/ctypes.rs index ae85cbc..cd2cd08 100644 --- a/librashader-capi/src/ctypes.rs +++ b/librashader-capi/src/ctypes.rs @@ -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>; #[cfg(feature = "runtime-opengl")] pub type libra_gl_filter_chain_t = Option>; +#[cfg(feature = "runtime-d3d11")] +pub type libra_d3d11_filter_chain_t = Option>; + /// Parameters for the output viewport. #[repr(C)] pub struct libra_viewport_t { diff --git a/librashader-capi/src/error.rs b/librashader-capi/src/error.rs index 4781b13..822c9b2 100644 --- a/librashader-capi/src/error.rs +++ b/librashader-capi/src/error.rs @@ -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; diff --git a/librashader-capi/src/presets.rs b/librashader-capi/src/presets.rs index c1c65d2..7d206c6 100644 --- a/librashader-capi/src/presets.rs +++ b/librashader-capi/src/presets.rs @@ -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_error_t; +pub type PFN_lbr_preset_create = unsafe extern "C" fn (*const c_char, *mut MaybeUninit) -> 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_error_t { +pub unsafe extern "C" fn libra_preset_create(filename: *const c_char, out: *mut MaybeUninit) -> libra_error_t { ffi_body!({ assert_non_null!(filename); assert_non_null!(out); diff --git a/librashader-capi/src/runtime/d3d11.rs b/librashader-capi/src/runtime/d3d11/filter_chain.rs similarity index 100% rename from librashader-capi/src/runtime/d3d11.rs rename to librashader-capi/src/runtime/d3d11/filter_chain.rs diff --git a/librashader-capi/src/runtime/d3d11/mod.rs b/librashader-capi/src/runtime/d3d11/mod.rs new file mode 100644 index 0000000..f5cc5ab --- /dev/null +++ b/librashader-capi/src/runtime/d3d11/mod.rs @@ -0,0 +1,4 @@ +//! C API for the librashader OpenGL Runtime (`libra_d3d11_*`) + +mod filter_chain; +pub use filter_chain::*; \ No newline at end of file diff --git a/librashader-capi/src/runtime/gl/mod.rs b/librashader-capi/src/runtime/gl/mod.rs index d28780f..f3d1186 100644 --- a/librashader-capi/src/runtime/gl/mod.rs +++ b/librashader-capi/src/runtime/gl/mod.rs @@ -1 +1,4 @@ -pub mod filter_chain; +//! C API for the librashader OpenGL Runtime (`libra_gl_*`) + +mod filter_chain; +pub use filter_chain::*; \ No newline at end of file diff --git a/librashader-capi/src/runtime/mod.rs b/librashader-capi/src/runtime/mod.rs index 2f89d9f..a5a21a6 100644 --- a/librashader-capi/src/runtime/mod.rs +++ b/librashader-capi/src/runtime/mod.rs @@ -1,2 +1,6 @@ +//! librashader runtime C APIs #[cfg(feature = "runtime-opengl")] -mod gl; \ No newline at end of file +pub mod gl; + +#[cfg(feature = "runtime-d3d11")] +pub mod d3d11; \ No newline at end of file diff --git a/librashader-runtime-d3d11/src/options.rs b/librashader-runtime-d3d11/src/options.rs index 571cdb2..83b0cff 100644 --- a/librashader-runtime-d3d11/src/options.rs +++ b/librashader-runtime-d3d11/src/options.rs @@ -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, } diff --git a/librashader-runtime-gl/src/options.rs b/librashader-runtime-gl/src/options.rs index 2bf869d..0f60f1c 100644 --- a/librashader-runtime-gl/src/options.rs +++ b/librashader-runtime-gl/src/options.rs @@ -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, }