Skip to content

Commit

Permalink
Add lifetimes to structs
Browse files Browse the repository at this point in the history
  • Loading branch information
KYovchevski committed Jan 31, 2024
1 parent 7c2b0f2 commit a48f732
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
16 changes: 8 additions & 8 deletions src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use super::{
#[derive(Clone, Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXGPU")]
pub struct Gpu(InterfaceImpl);
pub struct Gpu<'lib>(InterfaceImpl<'lib>);

unsafe impl Interface for Gpu {
unsafe impl Interface for Gpu<'_> {
type Impl = ffi::IADLXGPU;
type Vtable = ffi::IADLXGPUVtbl;
const IID: &'static str = "IADLXGPU";
}

impl Gpu {
impl Gpu<'_> {
#[doc(alias = "VendorId")]
pub fn vendor_id(&self) -> Result<&str> {
let mut name = MaybeUninit::uninit();
Expand Down Expand Up @@ -146,24 +146,24 @@ impl Gpu {
#[derive(Clone, Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXGPU1")]
pub struct Gpu1(Gpu);
pub struct Gpu1<'lib>(Gpu<'lib>);

unsafe impl Interface for Gpu1 {
unsafe impl Interface for Gpu1<'_> {
type Impl = ffi::IADLXGPU1;
type Vtable = ffi::IADLXGPU1Vtbl;
const IID: &'static str = "IADLXGPU1";
}

// TODO: Autogenerate interface hierarchy chains?
impl Deref for Gpu1 {
type Target = Gpu;
impl<'lib> Deref for Gpu1<'lib> {
type Target = Gpu<'lib>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl Gpu1 {
impl Gpu1<'_> {
#[doc(alias = "PCIBusType")]
pub fn pci_bus_type(&self) -> Result<ffi::ADLX_PCI_BUS_TYPE> {
let mut pci_bus_type = MaybeUninit::uninit();
Expand Down
24 changes: 12 additions & 12 deletions src/gpu_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ use super::{
#[derive(Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXGPUList")]
pub struct GpuList(List);
pub struct GpuList<'lib>(List<'lib>);

unsafe impl Interface for GpuList {
unsafe impl Interface for GpuList<'_> {
type Impl = ffi::IADLXGPUList;
type Vtable = ffi::IADLXGPUListVtbl;
const IID: &'static str = "IADLXGPUList";
}

impl Deref for GpuList {
type Target = List;
impl<'lib> Deref for GpuList<'lib> {
type Target = List<'lib>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl GpuList {
impl<'lib> GpuList<'lib> {
/// <https://gpuopen.com/manuals/adlx/adlx-_d_o_x__i_a_d_l_x_g_p_u_list__at/>
#[doc(alias = "At_GPUList")]
pub fn at(&self, location: u32) -> Result<Gpu> {
pub fn at(&self, location: u32) -> Result<Gpu<'lib>> {
let mut gpu = MaybeUninit::uninit();
let result = unsafe {
(self.vtable().At_GPUList.unwrap())(self.as_raw(), location, gpu.as_mut_ptr())
Expand All @@ -42,7 +42,7 @@ impl GpuList {
/// <https://gpuopen.com/manuals/adlx/adlx-_d_o_x__i_a_d_l_x_g_p_u_list__add__back/#doxid-d-o-x-i-a-d-l-x-g-p-u-list-add-back>
#[doc(alias = "Add_Back_GPUList")]
// TODO(Marijn): This API does not allow moves of derivatives, such as Gpu1.
pub fn add_back(&self, gpu: Gpu) -> Result<()> {
pub fn add_back(&self, gpu: Gpu<'lib>) -> Result<()> {
let result = unsafe {
// TODO: Assume ownership is consumed here?
(self.vtable().Add_Back_GPUList.unwrap())(self.as_raw(), gpu.into_raw())
Expand All @@ -55,13 +55,13 @@ impl GpuList {
}
}

pub struct GpuIterator<'a> {
list: &'a GpuList,
pub struct GpuIterator<'list, 'lib: 'list> {
list: &'list GpuList<'lib>,
i: u32,
}

impl<'a> Iterator for GpuIterator<'a> {
type Item = Gpu;
impl<'list, 'lib: 'list> Iterator for GpuIterator<'list, 'lib> {
type Item = Gpu<'lib>;

fn next(&mut self) -> Option<Self::Item> {
if self.i < self.list.size() {
Expand All @@ -74,7 +74,7 @@ impl<'a> Iterator for GpuIterator<'a> {
}
}

impl ExactSizeIterator for GpuIterator<'_> {
impl ExactSizeIterator for GpuIterator<'_, '_> {
fn len(&self) -> usize {
self.list.size() as usize
}
Expand Down
22 changes: 11 additions & 11 deletions src/gpu_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use super::{
#[derive(Clone, Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXGPUMetrics")]
pub struct GpuMetrics(InterfaceImpl);
pub struct GpuMetrics<'lib>(InterfaceImpl<'lib>);

unsafe impl Interface for GpuMetrics {
unsafe impl Interface for GpuMetrics<'_> {
type Impl = ffi::IADLXGPUMetrics;
type Vtable = ffi::IADLXGPUMetricsVtbl;
const IID: &'static str = "IADLXGPUMetrics";
}

impl GpuMetrics {
impl GpuMetrics<'_> {
#[doc(alias = "TimeStamp")]
pub fn time_stamp(&self) -> Result<i64> {
let mut time_stamp = MaybeUninit::uninit();
Expand Down Expand Up @@ -146,15 +146,15 @@ impl GpuMetrics {
#[derive(Clone, Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXGPUMetricsList")]
pub struct GpuMetricsList(List);
pub struct GpuMetricsList<'lib>(List<'lib>);

unsafe impl Interface for GpuMetricsList {
unsafe impl Interface for GpuMetricsList<'_> {
type Impl = ffi::IADLXGPUMetricsList;
type Vtable = ffi::IADLXGPUMetricsListVtbl;
const IID: &'static str = "IADLXGpuMetricsList";
}

impl GpuMetricsList {
impl GpuMetricsList<'_> {
/// <https://gpuopen.com/manuals/adlx/adlx-_d_o_x__i_a_d_l_x_g_p_u_list__at/>
#[doc(alias = "At_GPUMetricsList")]
pub fn at(&self, location: u32) -> Result<GpuMetrics> {
Expand All @@ -180,8 +180,8 @@ impl GpuMetricsList {
}
}

impl Deref for GpuMetricsList {
type Target = List;
impl<'lib> Deref for GpuMetricsList<'lib> {
type Target = List<'lib>;

fn deref(&self) -> &Self::Target {
&self.0
Expand All @@ -191,15 +191,15 @@ impl Deref for GpuMetricsList {
#[derive(Clone, Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXGPUMetricsSupport")]
pub struct GpuMetricsSupport(InterfaceImpl);
pub struct GpuMetricsSupport<'lib>(InterfaceImpl<'lib>);

unsafe impl Interface for GpuMetricsSupport {
unsafe impl Interface for GpuMetricsSupport<'_> {
type Impl = ffi::IADLXGPUMetricsSupport;
type Vtable = ffi::IADLXGPUMetricsSupportVtbl;
const IID: &'static str = "IADLXGpuMetricsSupport";
}

impl GpuMetricsSupport {
impl GpuMetricsSupport<'_> {
#[doc(alias = "IsSupportedGPUUsage")]
pub fn is_supported_gpu_usage(&self) -> Result<bool> {
unsafe {
Expand Down
16 changes: 8 additions & 8 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ pub unsafe trait Interface: Sized {
#[derive(Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXInterface")]
pub struct InterfaceImpl(*mut ffi::IADLXInterface);
pub struct InterfaceImpl<'lib>(*mut ffi::IADLXInterface, std::marker::PhantomData<&'lib ()>);

unsafe impl Interface for InterfaceImpl {
unsafe impl Interface for InterfaceImpl<'_> {
type Impl = ffi::IADLXInterface;
type Vtable = ffi::IADLXInterfaceVtbl;
const IID: &'static str = "IADLXInterface";
}

impl InterfaceImpl {
impl InterfaceImpl<'_> {
/// <https://gpuopen.com/manuals/adlx/adlx-_d_o_x__i_a_d_l_x_interface__query_interface/>
#[doc(alias = "QueryInterface")]
pub fn cast<I: Interface>(&self) -> Result<I> {
Expand All @@ -113,22 +113,22 @@ impl InterfaceImpl {
}
}

impl Drop for InterfaceImpl {
impl Drop for InterfaceImpl<'_> {
/// <https://gpuopen.com/manuals/adlx/adlx-_d_o_x__i_a_d_l_x_interface__release/>
#[doc(alias = "Release")]
fn drop(&mut self) {
let _rc = unsafe { (self.vtable().Release.unwrap())(self.0) };
}
}

impl Clone for InterfaceImpl {
impl Clone for InterfaceImpl<'_> {
/// <https://gpuopen.com/manuals/adlx/adlx-_d_o_x__i_a_d_l_x_interface__acquire/>
#[doc(alias = "Acquire")]
fn clone(&self) -> Self {
let _rc = unsafe { (self.vtable().Acquire.unwrap())(self.0) };
Self(self.0)
Self(self.0, std::marker::PhantomData)
}
}

unsafe impl Send for InterfaceImpl {}
unsafe impl Sync for InterfaceImpl {}
unsafe impl Send for InterfaceImpl<'_> {}
unsafe impl Sync for InterfaceImpl<'_> {}
6 changes: 3 additions & 3 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use super::{
#[derive(Clone, Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXList")]
pub struct List(InterfaceImpl);
pub struct List<'lib>(InterfaceImpl<'lib>);

unsafe impl Interface for List {
unsafe impl Interface for List<'_> {
type Impl = ffi::IADLXList;
type Vtable = ffi::IADLXListVtbl;
const IID: &'static str = "IADLXList";
}

impl List {
impl List<'_> {
/// <https://gpuopen.com/manuals/adlx/adlx-_d_o_x__i_a_d_l_x_list__size/#doxid-d-o-x-i-a-d-l-x-list-size>
#[doc(alias = "Size")]
pub fn size(&self) -> u32 {
Expand Down
6 changes: 3 additions & 3 deletions src/performance_monitoring_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use super::{
#[derive(Clone, Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXPerformanceMonitoringServices")]
pub struct PerformanceMonitoringServices(InterfaceImpl);
pub struct PerformanceMonitoringServices<'lib>(InterfaceImpl<'lib>);

unsafe impl Interface for PerformanceMonitoringServices {
unsafe impl Interface for PerformanceMonitoringServices<'_> {
type Impl = ffi::IADLXPerformanceMonitoringServices;
type Vtable = ffi::IADLXPerformanceMonitoringServicesVtbl;
const IID: &'static str = "IADLXPerformanceMonitoringServices";
}

impl PerformanceMonitoringServices {
impl PerformanceMonitoringServices<'_> {
#[doc(alias = "GetCurrentGPUMetrics")]
pub fn current_gpu_metrics(&self, gpu: &Gpu) -> Result<GpuMetrics> {
let mut metrics = MaybeUninit::uninit();
Expand Down
6 changes: 3 additions & 3 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ impl System {
#[derive(Clone, Debug)]
#[repr(transparent)]
#[doc(alias = "IADLXSystem1")]
pub struct System1(InterfaceImpl);
pub struct System1<'lib>(InterfaceImpl<'lib>);

unsafe impl Interface for System1 {
unsafe impl Interface for System1<'_> {
type Impl = ffi::IADLXSystem1;
type Vtable = ffi::IADLXSystem1Vtbl;
const IID: &'static str = "IADLXSystem1";
}

impl System1 {
impl System1<'_> {
// /// <https://gpuopen.com/manuals/adlx/adlx-_d_o_x__i_a_d_l_x_system1__get_power_tuning_services/>
// #[doc(alias = "GetPowerTuningServices")]
// pub fn power_tuning_services(&self) -> Result<PowerTuningServices> {
Expand Down

0 comments on commit a48f732

Please sign in to comment.