pub mod arena;
pub mod backend;
pub mod containers;
pub mod error;
pub mod file;
pub mod io;
pub mod mipmap;
pub mod parallel;
pub mod parameters;
pub mod parser;
pub mod sampling;
pub mod strings;
pub mod upload;

pub use error::FileLoc;
pub use file::{read_float_file, resolve_filename};
pub use parameters::{
    ParameterDictionary, ParsedParameter, ParsedParameterVector, TextureParameterDictionary,
};
pub use strings::*;
pub use upload::{Upload, ArenaUpload};

#[cfg(feature = "vulkan")]
pub type Arena = arena::Arena<backend::vulkan::VulkanAllocator>;

#[cfg(all(feature = "cuda", not(feature = "vulkan")))]
pub type Arena = arena::Arena<backend::cuda::CudaAllocator>;

#[cfg(not(any(feature = "cuda", feature = "vulkan")))]
pub type Arena = arena::Arena<backend::SystemAllocator>;

use half::f16;

#[inline(always)]
pub fn f16_to_f32(bits: u16) -> f32 {
    #[cfg(feature = "cuda")]
    {
        // Use hardware intrinsic on CUDA
        // Cast bits to cuda_f16, then cast to f32
        let half_val = unsafe { core::mem::transmute::<u16, cuda_std::f16>(bits) };
        half_val.to_f32()
    }

    #[cfg(feature = "vulkan")]
    {
        // Use shared logic or spirv-std intrinsics if available.
        // Keep an eye on rust-gpu
        f16_to_f32_software(bits)
    }

    #[cfg(not(any(feature = "cuda", feature = "vulkan")))]
    {
        f16::from_bits(bits).to_f32()
    }
}
