pub const ext = @import("ext.zig");
const cudagst = @This();

const std = @import("std");
const compat = @import("compat");
pub const array = *anyopaque;

pub const context = *anyopaque;

pub const device = c_int;

pub const deviceptr = usize;

pub const event = *anyopaque;

pub const externalMemory = *anyopaque;

pub const externalSemaphore = *anyopaque;

pub const function = *anyopaque;

pub const graphicsResource = *anyopaque;

pub const memGenericAllocationHandle = c_ulonglong;

pub const memoryPool = *anyopaque;

pub const mipmappedArray = *anyopaque;

pub const module = *anyopaque;

pub const stream = *anyopaque;

pub const texObject = u64;

pub const DA_ARRAY3D_DESCRIPTOR = extern struct {
    f_Width: usize,
    f_Height: usize,
    f_Depth: usize,
    f_Format: cudagst.array_format,
    f_NumChannels: c_uint,
    f_Flags: c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_EXTERNAL_MEMORY_BUFFER_DESC = extern struct {
    f_offset: c_ulonglong,
    f_size: c_ulonglong,
    f_flags: c_uint,
    f_reserved: [16]c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_EXTERNAL_MEMORY_HANDLE_DESC = extern struct {
    f_type: cudagst.externalMemoryHandleType,
    anon0: extern union {
        f_fd: c_int,
        anon0: extern struct {
            f_handle: ?*anyopaque,
            f_name: ?*anyopaque,
        },
        f_nvSciBufObject: ?*anyopaque,
    },
    f_size: c_ulonglong,
    f_flags: c_uint,
    f_reserved: [16]c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_EXTERNAL_MEMORY_MIPMAPPED_ARRAY_DESC = extern struct {
    f_offset: c_ulonglong,
    f_arrayDesc: cudagst.DA_ARRAY3D_DESCRIPTOR,
    f_numLevels: c_uint,
    f_reserved: [16]c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_EXTERNAL_SEMAPHORE_HANDLE_DESC = extern struct {
    f_type: cudagst.externalSemaphoreHandleType,
    anon0: extern union {
        f_fd: c_int,
        anon0: extern struct {
            f_handle: ?*anyopaque,
            f_name: ?*anyopaque,
        },
        f_nvSciSyncObj: ?*anyopaque,
    },
    f_flags: c_uint,
    f_reserved: [16]c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS = extern struct {
    anon0: extern struct {
        anon0: extern struct {
            f_value: c_ulonglong,
        },
        anon1: extern union {
            f_fence: ?*anyopaque,
            f_reserved: c_ulonglong,
        },
        anon2: extern struct {
            f_key: c_ulonglong,
        },
        f_reserved: [12]c_uint,
    },
    f_flags: c_uint,
    f_reserved: [16]c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_EXTERNAL_SEMAPHORE_WAIT_PARAMS = extern struct {
    anon0: extern struct {
        anon0: extern struct {
            f_value: c_ulonglong,
        },
        anon1: extern union {
            f_fence: ?*anyopaque,
            f_reserved: c_ulonglong,
        },
        anon2: extern struct {
            f_key: c_ulonglong,
            f_timeoutMs: c_uint,
        },
        f_reserved: [10]c_uint,
    },
    f_flags: c_uint,
    f_reserved: [16]c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_MEMCPY2D = extern struct {
    f_srcXInBytes: usize,
    f_srcY: usize,
    f_srcMemoryType: cudagst.memorytype,
    f_srcHost: ?*const anyopaque,
    f_srcDevice: cudagst.deviceptr,
    f_srcArray: cudagst.array,
    f_srcPitch: usize,
    f_dstXInBytes: usize,
    f_dstY: usize,
    f_dstMemoryType: cudagst.memorytype,
    f_dstHost: ?*anyopaque,
    f_dstDevice: cudagst.deviceptr,
    f_dstArray: cudagst.array,
    f_dstPitch: usize,
    f_WidthInBytes: usize,
    f_Height: usize,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_RESOURCE_DESC = extern struct {
    f_resType: cudagst.resourcetype,
    anon0: extern union {
        anon0: extern struct {
            f_hArray: cudagst.array,
        },
        anon1: extern struct {
            f_hMipmappedArray: cudagst.mipmappedArray,
        },
        anon2: extern struct {
            f_devPtr: cudagst.deviceptr,
            f_format: cudagst.array_format,
            f_numChannels: c_uint,
            f_sizeInBytes: usize,
        },
        anon3: extern struct {
            f_devPtr: cudagst.deviceptr,
            f_format: cudagst.array_format,
            f_numChannels: c_uint,
            f_width: usize,
            f_height: usize,
            f_pitchInBytes: usize,
        },
        anon4: extern struct {
            f_reserved: [32]c_int,
        },
    },
    f_flags: c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_RESOURCE_VIEW_DESC = extern struct {
    f_format: cudagst.resourceViewFormat,
    f_width: usize,
    f_height: usize,
    f_depth: usize,
    f_firstMipmapLevel: c_uint,
    f_lastMipmapLevel: c_uint,
    f_firstLayer: c_uint,
    f_lastLayer: c_uint,
    f_reserved: [16]c_uint,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const DA_TEXTURE_DESC = extern struct {
    f_addressMode: [3]cudagst.address_mode,
    f_filterMode: cudagst.filter_mode,
    f_flags: c_uint,
    f_maxAnisotropy: c_uint,
    f_mipmapFilterMode: cudagst.filter_mode,
    f_mipmapLevelBias: f32,
    f_minMipmapLevelClamp: f32,
    f_maxMipmapLevelClamp: f32,
    f_borderColor: [4]f32,
    f_reserved: [12]c_int,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const ipcEventHandle = extern struct {
    f_reserved: [64]u8,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const ipcMemHandle = extern struct {
    f_reserved: [64]u8,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memAccessDesc = extern struct {
    f_location: cudagst.memLocation,
    f_flags: cudagst.memAccess_flags,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memAllocationProp = extern struct {
    f_type: cudagst.memAllocationType,
    f_requestedHandleTypes: cudagst.memAllocationHandleType,
    f_location: cudagst.memLocation,
    f_win32HandleMetaData: ?*anyopaque,
    f_allocFlags: cudagst.memAllocationPropAllocFlags,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memAllocationPropAllocFlags = extern struct {
    f_compressionType: u8,
    f_gpuDirectRDMACapable: u8,
    f_usage: c_ushort,
    f_reserved: [4]u8,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memLocation = extern struct {
    f_type: cudagst.memLocationType,
    f_id: c_int,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memPoolProps = extern struct {
    f_allocType: cudagst.memAllocationType,
    f_handleTypes: cudagst.memAllocationHandleType,
    f_location: cudagst.memLocation,
    f_win32SecurityAttributes: ?*anyopaque,
    f_maxSize: usize,
    f_reserved: [56]u8,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const GLDeviceList = enum(c_int) {
    gl_device_list_all = 1,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const address_mode = enum(c_int) {
    wrap = 0,
    clamp = 1,
    mirror = 2,
    border = 3,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const array_format = enum(c_int) {
    int8 = 1,
    int16 = 2,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const device_attribute = enum(c_int) {
    texture_alignment = 14,
    unified_addressing = 41,
    compute_capability_major = 75,
    compute_capability_minor = 76,
    virtual_memory_management_supported = 102,
    handle_type_posix_file_descriptor_supported = 103,
    handle_type_win32_handle_supported = 104,
    handle_type_win32_kmt_handle_supported = 105,
    memory_pools_supported = 115,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const event_flags = enum(c_int) {
    default = 0,
    blocking_sync = 1,
    disable_timing = 2,
    interprocess = 4,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const externalMemoryHandleType = enum(c_int) {
    opaque_fd = 1,
    opaque_win32 = 2,
    opaque_win32_kmt = 3,
    d3d12_heap = 4,
    d3d12_resource = 5,
    d3d11_resource = 6,
    d3d11_resource_kmt = 7,
    nvscibuf = 8,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const externalSemaphoreHandleType = enum(c_int) {
    opaque_fd = 1,
    opaque_win32 = 2,
    opaque_win32_kmt = 3,
    d3d12_fence = 4,
    d3d11_fence = 5,
    nvscisync = 6,
    d3d11_keyed_mutex = 7,
    d3d11_keyed_mutex_kmt = 8,
    timeline_semaphore_fd = 9,
    timeline_semaphore_win32 = 10,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const filter_mode = enum(c_int) {
    point = 0,
    linear = 1,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const graphicsMapResourceFlags = enum(c_int) {
    none = 0,
    read_only = 1,
    write_discard = 2,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const graphicsRegisterFlags = enum(c_int) {
    none = 0,
    read_only = 1,
    write_discard = 2,
    surface_load_store = 4,
    texture_gather = 8,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const ipcMem_flags = enum(c_int) {
    ipc_mem_lazy_enable_peer_access = 1,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const limit = enum(c_int) {
    stack_size = 0,
    printf_fifo_size = 1,
    malloc_heap_size = 2,
    dev_runtime_sync_depth = 3,
    dev_runtime_pending_launch_count = 4,
    max_l2_fetch_granularity = 5,
    persisting_l2_cache_size = 6,
    shmem_size = 7,
    cig_enabled = 8,
    cig_shmem_fallback_enabled = 9,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memAccess_flags = enum(c_int) {
    none = 0,
    read = 1,
    readwrite = 3,
    max = 2147483647,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memAllocationGranularity_flags = enum(c_int) {
    minimum = 0,
    recommended = 1,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memAllocationHandleType = enum(c_int) {
    none = 0,
    posix_file_descriptor = 1,
    win32 = 2,
    win32_kmt = 4,
    max = 2147483647,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memAllocationType = enum(c_int) {
    invalid = 0,
    pinned = 1,
    max = 2147483647,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memLocationType = enum(c_int) {
    invalid = 0,
    device = 1,
    max = 2147483647,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memPool_attribute = enum(c_int) {
    reuse_follow_event_dependencies = 1,
    reuse_allow_opportunistic = 2,
    reuse_allow_internal_dependencies = 3,
    release_threshold = 4,
    reserved_mem_current = 5,
    reserved_mem_high = 6,
    used_mem_current = 7,
    used_mem_high = 8,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const memorytype = enum(c_int) {
    host = 1,
    device = 2,
    array = 3,
    unified = 4,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const resourceViewFormat = enum(c_int) {
    res_view_format_none = 0,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const resourcetype = enum(c_int) {
    array = 0,
    mipmapped_array = 1,
    linear = 2,
    pitch2d = 3,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const result = enum(c_int) {
    success = 0,
    error_no_device = 100,
    error_already_mapped = 208,
    error_not_supported = 801,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const stream_flags = enum(c_int) {
    default = 0,
    non_blocking = 1,
    _,

    test {
        @setEvalBranchQuota(100_000);
        std.testing.refAllDecls(@This());
    }
};

pub const IPC_HANDLE_SIZE = 64;
pub const TRSF_READ_AS_INTEGER = 1;
pub const VERSION = 10000;

test {
    @setEvalBranchQuota(100_000);
    std.testing.refAllDecls(@This());
    std.testing.refAllDecls(ext);
}
