doc(capi): document all C API members

This commit is contained in:
chyyran 2024-09-21 01:41:18 -04:00
parent 7d0b135710
commit 72a98272f3
4 changed files with 56 additions and 1 deletions

View file

@ -18,7 +18,9 @@ pub type libra_error_t = Option<NonNull<LibrashaderError>>;
#[repr(u32)] #[repr(u32)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum LIBRA_PRESET_CTX_ORIENTATION { pub enum LIBRA_PRESET_CTX_ORIENTATION {
/// Context parameter for vertical orientation.
Vertical = 0, Vertical = 0,
/// Context parameter for horizontal orientation.
Horizontal, Horizontal,
} }
impl From<LIBRA_PRESET_CTX_ORIENTATION> for Orientation { impl From<LIBRA_PRESET_CTX_ORIENTATION> for Orientation {
@ -30,15 +32,21 @@ impl From<LIBRA_PRESET_CTX_ORIENTATION> for Orientation {
} }
} }
// An enum representing graphics runtimes (video drivers) for use in preset contexts. /// An enum representing graphics runtimes (video drivers) for use in preset contexts.
#[repr(u32)] #[repr(u32)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum LIBRA_PRESET_CTX_RUNTIME { pub enum LIBRA_PRESET_CTX_RUNTIME {
/// No runtime.
None = 0, None = 0,
/// OpenGL 3.3+
GlCore, GlCore,
/// Vulkan
Vulkan, Vulkan,
/// Direct3D 11
D3D11, D3D11,
/// Direct3D 12
D3D12, D3D12,
/// Metal
Metal, Metal,
} }
@ -120,6 +128,8 @@ pub type libra_vk_filter_chain_t = Option<NonNull<FilterChainVulkan>>;
#[cfg(all(target_os = "macos", feature = "runtime-metal"))] #[cfg(all(target_os = "macos", feature = "runtime-metal"))]
use librashader::runtime::mtl::FilterChain as FilterChainMetal; use librashader::runtime::mtl::FilterChain as FilterChainMetal;
/// A handle to a Vulkan filter chain.
#[cfg_attr( #[cfg_attr(
feature = "docsrs", feature = "docsrs",
doc(cfg(all(target_vendor = "apple", feature = "runtime-metal"))) doc(cfg(all(target_vendor = "apple", feature = "runtime-metal")))

View file

@ -9,26 +9,45 @@ use thiserror::Error;
#[non_exhaustive] #[non_exhaustive]
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum LibrashaderError { pub enum LibrashaderError {
/// An unknown error or panic occurred.
#[error("There was an unknown error.")] #[error("There was an unknown error.")]
UnknownError(Box<dyn Any + Send + 'static>), UnknownError(Box<dyn Any + Send + 'static>),
/// An invalid parameter (likely null), was passed.
#[error("The parameter was null or invalid.")] #[error("The parameter was null or invalid.")]
InvalidParameter(&'static str), InvalidParameter(&'static str),
/// The string provided was not valid UTF-8.
#[error("The provided string was not valid UTF8.")] #[error("The provided string was not valid UTF8.")]
InvalidString(#[from] std::str::Utf8Error), InvalidString(#[from] std::str::Utf8Error),
/// An error occurred in the preset parser.
#[error("There was an error parsing the preset.")] #[error("There was an error parsing the preset.")]
PresetError(#[from] librashader::presets::ParsePresetError), PresetError(#[from] librashader::presets::ParsePresetError),
/// An error occurred in the shader preprocessor.
#[error("There was an error preprocessing the shader source.")] #[error("There was an error preprocessing the shader source.")]
PreprocessError(#[from] librashader::preprocess::PreprocessError), PreprocessError(#[from] librashader::preprocess::PreprocessError),
/// An error occurred in the shader compiler.
#[error("There was an error compiling the shader source.")] #[error("There was an error compiling the shader source.")]
ShaderCompileError(#[from] librashader::reflect::ShaderCompileError), ShaderCompileError(#[from] librashader::reflect::ShaderCompileError),
/// An error occrred when validating and reflecting the shader.
#[error("There was an error reflecting the shader source.")] #[error("There was an error reflecting the shader source.")]
ShaderReflectError(#[from] librashader::reflect::ShaderReflectError), ShaderReflectError(#[from] librashader::reflect::ShaderReflectError),
/// An invalid shader parameter name was provided.
#[error("The provided parameter name was invalid.")] #[error("The provided parameter name was invalid.")]
UnknownShaderParameter(*const c_char), UnknownShaderParameter(*const c_char),
/// An error occurred with the OpenGL filter chain.
#[cfg(feature = "runtime-opengl")] #[cfg(feature = "runtime-opengl")]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "runtime-opengl")))] #[cfg_attr(feature = "docsrs", doc(cfg(feature = "runtime-opengl")))]
#[error("There was an error in the OpenGL filter chain.")] #[error("There was an error in the OpenGL filter chain.")]
OpenGlFilterError(#[from] librashader::runtime::gl::error::FilterChainError), OpenGlFilterError(#[from] librashader::runtime::gl::error::FilterChainError),
/// An error occurred with the Direct3D 11 filter chain.
#[cfg(all(target_os = "windows", feature = "runtime-d3d11"))] #[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
#[cfg_attr( #[cfg_attr(
feature = "docsrs", feature = "docsrs",
@ -36,6 +55,8 @@ pub enum LibrashaderError {
)] )]
#[error("There was an error in the D3D11 filter chain.")] #[error("There was an error in the D3D11 filter chain.")]
D3D11FilterError(#[from] librashader::runtime::d3d11::error::FilterChainError), D3D11FilterError(#[from] librashader::runtime::d3d11::error::FilterChainError),
/// An error occurred with the Direct3D 12 filter chain.
#[cfg(all(target_os = "windows", feature = "runtime-d3d12"))] #[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
#[cfg_attr( #[cfg_attr(
feature = "docsrs", feature = "docsrs",
@ -43,6 +64,8 @@ pub enum LibrashaderError {
)] )]
#[error("There was an error in the D3D12 filter chain.")] #[error("There was an error in the D3D12 filter chain.")]
D3D12FilterError(#[from] librashader::runtime::d3d12::error::FilterChainError), D3D12FilterError(#[from] librashader::runtime::d3d12::error::FilterChainError),
/// An error occurred with the Direct3D 9 filter chain.
#[cfg(all(target_os = "windows", feature = "runtime-d3d9"))] #[cfg(all(target_os = "windows", feature = "runtime-d3d9"))]
#[cfg_attr( #[cfg_attr(
feature = "docsrs", feature = "docsrs",
@ -50,10 +73,15 @@ pub enum LibrashaderError {
)] )]
#[error("There was an error in the D3D9 filter chain.")] #[error("There was an error in the D3D9 filter chain.")]
D3D9FilterError(#[from] librashader::runtime::d3d9::error::FilterChainError), D3D9FilterError(#[from] librashader::runtime::d3d9::error::FilterChainError),
/// An error occurred with the Vulkan filter chain.
#[cfg(feature = "runtime-vulkan")] #[cfg(feature = "runtime-vulkan")]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "runtime-vulkan")))] #[cfg_attr(feature = "docsrs", doc(cfg(feature = "runtime-vulkan")))]
#[error("There was an error in the Vulkan filter chain.")] #[error("There was an error in the Vulkan filter chain.")]
VulkanFilterError(#[from] librashader::runtime::vk::error::FilterChainError), VulkanFilterError(#[from] librashader::runtime::vk::error::FilterChainError),
/// An error occurred with the Metal filter chain.
#[cfg_attr( #[cfg_attr(
feature = "docsrs", feature = "docsrs",
doc(cfg(all(target_vendor = "apple", feature = "runtime-metal"))) doc(cfg(all(target_vendor = "apple", feature = "runtime-metal")))
@ -66,13 +94,28 @@ pub enum LibrashaderError {
/// Error codes for librashader error types. /// Error codes for librashader error types.
#[repr(i32)] #[repr(i32)]
pub enum LIBRA_ERRNO { pub enum LIBRA_ERRNO {
/// Error code for an unknown error.
UNKNOWN_ERROR = 0, UNKNOWN_ERROR = 0,
/// Error code for an invalid parameter.
INVALID_PARAMETER = 1, INVALID_PARAMETER = 1,
/// Error code for an invalid (non-UTF8) string.
INVALID_STRING = 2, INVALID_STRING = 2,
/// Error code for a preset parser error.
PRESET_ERROR = 3, PRESET_ERROR = 3,
/// Error code for a preprocessor error.
PREPROCESS_ERROR = 4, PREPROCESS_ERROR = 4,
/// Error code for a shader parameter error.
SHADER_PARAMETER_ERROR = 5, SHADER_PARAMETER_ERROR = 5,
/// Error code for a reflection error.
REFLECT_ERROR = 6, REFLECT_ERROR = 6,
/// Error code for a runtime error.
RUNTIME_ERROR = 7, RUNTIME_ERROR = 7,
} }

View file

@ -1,3 +1,4 @@
#![forbid(missing_docs)]
//! The C API for [librashader](https://docs.rs/librashader/). //! The C API for [librashader](https://docs.rs/librashader/).
//! //!
//! The librashader C API is designed to be loaded dynamically via `librashader_ld.h`, but static usage is also //! The librashader C API is designed to be loaded dynamically via `librashader_ld.h`, but static usage is also

View file

@ -2,6 +2,7 @@
/// API version type alias. /// API version type alias.
pub type LIBRASHADER_API_VERSION = usize; pub type LIBRASHADER_API_VERSION = usize;
/// ABI version type alias.
pub type LIBRASHADER_ABI_VERSION = usize; pub type LIBRASHADER_ABI_VERSION = usize;
/// The current version of the librashader API. /// The current version of the librashader API.