ADR-014: Cross-Platform Architecture
Status
Accepted
Context
VR creators use both Windows and Linux systems. SteamVR supports both platforms. Many users dual-boot or have mixed environments. We need consistent behavior across platforms while leveraging platform-specific optimizations.
Decision
Implement a Platform Abstraction Layer (PAL) with trait-based interfaces:
- All platform-specific code isolated in
platformcrate - Compile-time platform selection via cfg attributes
- Consistent API across platforms
- Platform-specific optimizations allowed
Primary platforms:
- Windows 10/11: Full support from day one
- Linux: Ubuntu 20.04+, Fedora 35+, SteamOS 3.0+
- macOS: Future support when Apple adds VR
Consequences
Positive
- Single codebase for all platforms
- Platform-specific optimizations possible
- Easier testing with trait mocking
- Clear separation of concerns
- Community can add platform support
Negative
- Additional abstraction layer complexity
- Must test on multiple platforms
- Platform-specific bugs possible
- Some features may not have equivalents
Alternatives Considered
- Windows-only: Would exclude Linux VR users (growing segment)
- Lowest common denominator: Would sacrifice performance
- Separate codebases: Maintenance nightmare
- Web-based only: Can't access VR APIs properly
Implementation
Platform traits cover:
- Window management
- GPU access (DirectX 12 / Vulkan)
- File system paths
- Process management
- Network interfaces
- System tray integration
Example:
pub trait GpuDevice: Send + Sync {
type Texture: GpuTexture;
type CommandList: GpuCommandList;
fn create_texture(&self, desc: &TextureDesc) -> Result<Self::Texture>;
fn submit(&self, commands: Self::CommandList) -> Result<()>;
}
#[cfg(target_os = "windows")]
pub type PlatformGpuDevice = crate::dx12::Dx12Device;
#[cfg(target_os = "linux")]
pub type PlatformGpuDevice = crate::vulkan::VulkanDevice;