Win32 API 日本語リファレンス
ホームAI.MachineLearning.DirectML › DMLCreateDevice1

DMLCreateDevice1

関数
機能レベルを指定してDirectMLデバイスを作成する。
DLLDirectML.dll呼出規約winapi

シグネチャ

// DirectML.dll
#include <windows.h>

HRESULT DMLCreateDevice1(
    ID3D12Device* d3d12Device,
    DML_CREATE_DEVICE_FLAGS flags,
    DML_FEATURE_LEVEL minimumFeatureLevel,
    const GUID* riid,
    void** ppv   // optional
);

パラメーター

名前方向
d3d12DeviceID3D12Device*in
flagsDML_CREATE_DEVICE_FLAGSin
minimumFeatureLevelDML_FEATURE_LEVELin
riidGUID*in
ppvvoid**outoptional

戻り値の型: HRESULT

各言語での呼び出し定義

// DirectML.dll
#include <windows.h>

HRESULT DMLCreateDevice1(
    ID3D12Device* d3d12Device,
    DML_CREATE_DEVICE_FLAGS flags,
    DML_FEATURE_LEVEL minimumFeatureLevel,
    const GUID* riid,
    void** ppv   // optional
);
[DllImport("DirectML.dll", ExactSpelling = true)]
static extern int DMLCreateDevice1(
    IntPtr d3d12Device,   // ID3D12Device*
    int flags,   // DML_CREATE_DEVICE_FLAGS
    int minimumFeatureLevel,   // DML_FEATURE_LEVEL
    ref Guid riid,   // GUID*
    IntPtr ppv   // void** optional, out
);
<DllImport("DirectML.dll", ExactSpelling:=True)>
Public Shared Function DMLCreateDevice1(
    d3d12Device As IntPtr,   ' ID3D12Device*
    flags As Integer,   ' DML_CREATE_DEVICE_FLAGS
    minimumFeatureLevel As Integer,   ' DML_FEATURE_LEVEL
    ByRef riid As Guid,   ' GUID*
    ppv As IntPtr   ' void** optional, out
) As Integer
End Function
' d3d12Device : ID3D12Device*
' flags : DML_CREATE_DEVICE_FLAGS
' minimumFeatureLevel : DML_FEATURE_LEVEL
' riid : GUID*
' ppv : void** optional, out
Declare PtrSafe Function DMLCreateDevice1 Lib "directml" ( _
    ByVal d3d12Device As LongPtr, _
    ByVal flags As Long, _
    ByVal minimumFeatureLevel As Long, _
    ByVal riid As LongPtr, _
    ByVal ppv As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DMLCreateDevice1 = ctypes.windll.directml.DMLCreateDevice1
DMLCreateDevice1.restype = ctypes.c_int
DMLCreateDevice1.argtypes = [
    ctypes.c_void_p,  # d3d12Device : ID3D12Device*
    ctypes.c_int,  # flags : DML_CREATE_DEVICE_FLAGS
    ctypes.c_int,  # minimumFeatureLevel : DML_FEATURE_LEVEL
    ctypes.c_void_p,  # riid : GUID*
    ctypes.c_void_p,  # ppv : void** optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DirectML.dll')
DMLCreateDevice1 = Fiddle::Function.new(
  lib['DMLCreateDevice1'],
  [
    Fiddle::TYPE_VOIDP,  # d3d12Device : ID3D12Device*
    Fiddle::TYPE_INT,  # flags : DML_CREATE_DEVICE_FLAGS
    Fiddle::TYPE_INT,  # minimumFeatureLevel : DML_FEATURE_LEVEL
    Fiddle::TYPE_VOIDP,  # riid : GUID*
    Fiddle::TYPE_VOIDP,  # ppv : void** optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "directml")]
extern "system" {
    fn DMLCreateDevice1(
        d3d12Device: *mut core::ffi::c_void,  // ID3D12Device*
        flags: i32,  // DML_CREATE_DEVICE_FLAGS
        minimumFeatureLevel: i32,  // DML_FEATURE_LEVEL
        riid: *const GUID,  // GUID*
        ppv: *mut *mut ()  // void** optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DirectML.dll")]
public static extern int DMLCreateDevice1(IntPtr d3d12Device, int flags, int minimumFeatureLevel, ref Guid riid, IntPtr ppv);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DirectML_DMLCreateDevice1' -Namespace Win32 -PassThru
# $api::DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv)
#uselib "DirectML.dll"
#func global DMLCreateDevice1 "DMLCreateDevice1" sptr, sptr, sptr, sptr, sptr
; DMLCreateDevice1 d3d12Device, flags, minimumFeatureLevel, varptr(riid), ppv   ; 戻り値は stat
; d3d12Device : ID3D12Device* -> "sptr"
; flags : DML_CREATE_DEVICE_FLAGS -> "sptr"
; minimumFeatureLevel : DML_FEATURE_LEVEL -> "sptr"
; riid : GUID* -> "sptr"
; ppv : void** optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "DirectML.dll"
#cfunc global DMLCreateDevice1 "DMLCreateDevice1" sptr, int, int, var, sptr
; res = DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv)
; d3d12Device : ID3D12Device* -> "sptr"
; flags : DML_CREATE_DEVICE_FLAGS -> "int"
; minimumFeatureLevel : DML_FEATURE_LEVEL -> "int"
; riid : GUID* -> "var"
; ppv : void** optional, out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT DMLCreateDevice1(ID3D12Device* d3d12Device, DML_CREATE_DEVICE_FLAGS flags, DML_FEATURE_LEVEL minimumFeatureLevel, GUID* riid, void** ppv)
#uselib "DirectML.dll"
#cfunc global DMLCreateDevice1 "DMLCreateDevice1" intptr, int, int, var, intptr
; res = DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv)
; d3d12Device : ID3D12Device* -> "intptr"
; flags : DML_CREATE_DEVICE_FLAGS -> "int"
; minimumFeatureLevel : DML_FEATURE_LEVEL -> "int"
; riid : GUID* -> "var"
; ppv : void** optional, out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	directml = windows.NewLazySystemDLL("DirectML.dll")
	procDMLCreateDevice1 = directml.NewProc("DMLCreateDevice1")
)

// d3d12Device (ID3D12Device*), flags (DML_CREATE_DEVICE_FLAGS), minimumFeatureLevel (DML_FEATURE_LEVEL), riid (GUID*), ppv (void** optional, out)
r1, _, err := procDMLCreateDevice1.Call(
	uintptr(d3d12Device),
	uintptr(flags),
	uintptr(minimumFeatureLevel),
	uintptr(riid),
	uintptr(ppv),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DMLCreateDevice1(
  d3d12Device: Pointer;   // ID3D12Device*
  flags: Integer;   // DML_CREATE_DEVICE_FLAGS
  minimumFeatureLevel: Integer;   // DML_FEATURE_LEVEL
  riid: PGUID;   // GUID*
  ppv: Pointer   // void** optional, out
): Integer; stdcall;
  external 'DirectML.dll' name 'DMLCreateDevice1';
result := DllCall("DirectML\DMLCreateDevice1"
    , "Ptr", d3d12Device   ; ID3D12Device*
    , "Int", flags   ; DML_CREATE_DEVICE_FLAGS
    , "Int", minimumFeatureLevel   ; DML_FEATURE_LEVEL
    , "Ptr", riid   ; GUID*
    , "Ptr", ppv   ; void** optional, out
    , "Int")   ; return: HRESULT
●DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv) = DLL("DirectML.dll", "int DMLCreateDevice1(void*, int, int, void*, void*)")
# 呼び出し: DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv)
# d3d12Device : ID3D12Device* -> "void*"
# flags : DML_CREATE_DEVICE_FLAGS -> "int"
# minimumFeatureLevel : DML_FEATURE_LEVEL -> "int"
# riid : GUID* -> "void*"
# ppv : void** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。