1
0
mirror of https://github.com/fumiama/gozel.git synced 2026-06-23 03:50:30 +08:00

feat: add all other needs

This commit is contained in:
源文雨
2026-03-25 23:25:56 +08:00
parent 32ada81b80
commit 64de25bd44
28 changed files with 4678 additions and 416 deletions

View File

@@ -2,6 +2,7 @@ package ze
import (
"math"
"runtime"
"unsafe"
"github.com/fumiama/gozel"
@@ -11,11 +12,11 @@ import (
type CommandQueueHandle gozel.ZeCommandQueueHandle
// CommandQueueCreate creates a command queue on the given device with default mode and normal priority.
func (h ContextHandle) CommandQueueCreate(hDevice gozel.ZeDeviceHandle) (
func (h ContextHandle) CommandQueueCreate(hDevice DeviceHandle) (
CommandQueueHandle, error,
) {
var q gozel.ZeCommandQueueHandle
_, err := gozel.ZeCommandQueueCreate(gozel.ZeContextHandle(h), hDevice, &gozel.ZeCommandQueueDesc{
_, err := gozel.ZeCommandQueueCreate(gozel.ZeContextHandle(h), gozel.ZeDeviceHandle(hDevice), &gozel.ZeCommandQueueDesc{
Stype: gozel.ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC,
Mode: gozel.ZE_COMMAND_QUEUE_MODE_DEFAULT,
Priority: gozel.ZE_COMMAND_QUEUE_PRIORITY_NORMAL,
@@ -24,9 +25,12 @@ func (h ContextHandle) CommandQueueCreate(hDevice gozel.ZeDeviceHandle) (
}
// ExecuteCommandLists submits the command list for execution on the command queue.
func (h CommandQueueHandle) ExecuteCommandLists(hCommandList CommandListHandle) error {
cl := gozel.ZeCommandListHandle(hCommandList)
_, err := gozel.ZeCommandQueueExecuteCommandLists(gozel.ZeCommandQueueHandle(h), 1, &cl, 0)
func (h CommandQueueHandle) ExecuteCommandLists(hCommandList ...CommandListHandle) error {
_, err := gozel.ZeCommandQueueExecuteCommandLists(
gozel.ZeCommandQueueHandle(h), uint32(len(hCommandList)),
(*gozel.ZeCommandListHandle)(&hCommandList[0]), 0,
)
runtime.KeepAlive(hCommandList)
return err
}
@@ -46,11 +50,11 @@ func (h CommandQueueHandle) Destroy() error {
type CommandListHandle gozel.ZeCommandListHandle
// CommandListCreate creates a command list on the given device.
func (h ContextHandle) CommandListCreate(hDevice gozel.ZeDeviceHandle) (
func (h ContextHandle) CommandListCreate(hDevice DeviceHandle) (
CommandListHandle, error,
) {
var cl gozel.ZeCommandListHandle
_, err := gozel.ZeCommandListCreate(gozel.ZeContextHandle(h), hDevice, &gozel.ZeCommandListDesc{
_, err := gozel.ZeCommandListCreate(gozel.ZeContextHandle(h), gozel.ZeDeviceHandle(hDevice), &gozel.ZeCommandListDesc{
Stype: gozel.ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC,
}, &cl)
return CommandListHandle(cl), err

View File

@@ -2,8 +2,11 @@ package ze
import "github.com/fumiama/gozel"
// DeviceHandle is a handle to a Level Zero driver's device object.
type DeviceHandle gozel.ZeDeviceHandle
// DeviceGet retrieves all devices within the driver.
func (h DriverHandle) DeviceGet() ([]gozel.ZeDeviceHandle, error) {
func (h DriverHandle) DeviceGet() ([]DeviceHandle, error) {
var count uint32
_, err := gozel.ZeDeviceGet(gozel.ZeDriverHandle(h), &count, nil)
if err != nil {
@@ -12,10 +15,24 @@ func (h DriverHandle) DeviceGet() ([]gozel.ZeDeviceHandle, error) {
if count == 0 {
return nil, nil
}
devices := make([]gozel.ZeDeviceHandle, count)
_, err = gozel.ZeDeviceGet(gozel.ZeDriverHandle(h), &count, &devices[0])
devices := make([]DeviceHandle, count)
_, err = gozel.ZeDeviceGet(gozel.ZeDriverHandle(h), &count, (*gozel.ZeDeviceHandle)(&devices[0]))
if err != nil {
return nil, err
}
return devices, nil
}
// DeviceGetProperties retrieves properties of the device.
func (h DeviceHandle) DeviceGetProperties() (prop gozel.ZeDeviceProperties, err error) {
prop.Stype = gozel.ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES
_, err = gozel.ZeDeviceGetProperties(gozel.ZeDeviceHandle(h), &prop)
return
}
// DeviceGetComputeProperties retrieves compute properties of the device.
func (h DeviceHandle) DeviceGetComputeProperties() (prop gozel.ZeDeviceComputeProperties, err error) {
prop.Stype = gozel.ZE_STRUCTURE_TYPE_DEVICE_COMPUTE_PROPERTIES
_, err = gozel.ZeDeviceGetComputeProperties(gozel.ZeDeviceHandle(h), &prop)
return
}

View File

@@ -7,13 +7,13 @@ import (
)
// MemAllocDevice allocates device memory on the given device with the specified size and alignment.
func (h ContextHandle) MemAllocDevice(hDevice gozel.ZeDeviceHandle, size uintptr, alignment uintptr) (
func (h ContextHandle) MemAllocDevice(hDevice DeviceHandle, size uintptr, alignment uintptr) (
unsafe.Pointer, error,
) {
var p unsafe.Pointer
_, err := gozel.ZeMemAllocDevice(gozel.ZeContextHandle(h), &gozel.ZeDeviceMemAllocDesc{
Stype: gozel.ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC,
}, size, alignment, hDevice, &p)
}, size, alignment, gozel.ZeDeviceHandle(hDevice), &p)
return p, err
}

View File

@@ -12,14 +12,14 @@ import (
type ModuleHandle gozel.ZeModuleHandle
// ModuleCreate creates a module from SPIR-V binary data on the given device.
func (h ContextHandle) ModuleCreate(hDevice gozel.ZeDeviceHandle, data []byte) (
func (h ContextHandle) ModuleCreate(hDevice DeviceHandle, data []byte) (
ModuleHandle, error,
) {
var (
m gozel.ZeModuleHandle
lg gozel.ZeModuleBuildLogHandle
)
_, err := gozel.ZeModuleCreate(gozel.ZeContextHandle(h), hDevice, &gozel.ZeModuleDesc{
_, err := gozel.ZeModuleCreate(gozel.ZeContextHandle(h), gozel.ZeDeviceHandle(hDevice), &gozel.ZeModuleDesc{
Stype: gozel.ZE_STRUCTURE_TYPE_MODULE_DESC,
Format: gozel.ZE_MODULE_FORMAT_IL_SPIRV,
Inputsize: uintptr(len(data)),