ホーム › AI.MachineLearning.DirectML › DMLCreateDevice1
DMLCreateDevice1
関数機能レベルを指定してDirectMLデバイスを作成する。
シグネチャ
// DirectML.dll
#include <windows.h>
HRESULT DMLCreateDevice1(
ID3D12Device* d3d12Device,
DML_CREATE_DEVICE_FLAGS flags,
DML_FEATURE_LEVEL minimumFeatureLevel,
const GUID* riid,
void** ppv // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| d3d12Device | ID3D12Device* | in | DirectMLデバイスの基盤となるDirect3D 12デバイス。GPU実行リソースを供給する。 |
| flags | DML_CREATE_DEVICE_FLAGS | in | デバイス生成オプションを指定するDML_CREATE_DEVICE_FLAGSビット値。デバッグ層有効化などを指定する。 |
| minimumFeatureLevel | DML_FEATURE_LEVEL | in | 要求する最小機能レベルを示すDML_FEATURE_LEVEL。これ未満なら生成が失敗する。 |
| riid | GUID* | in | 取得するDirectMLデバイスインターフェイスのGUID。通常IID_IDMLDevice1を指す。 |
| ppv | void** | outoptional | 生成したデバイスインターフェイスポインタを受け取る出力先。voidダブルポインタ。 |
戻り値の型: 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 方式にも切替可。#uselib "DirectML.dll" #cfunc global DMLCreateDevice1 "DMLCreateDevice1" sptr, int, int, sptr, sptr ; res = DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, varptr(riid), ppv) ; d3d12Device : ID3D12Device* -> "sptr" ; flags : DML_CREATE_DEVICE_FLAGS -> "int" ; minimumFeatureLevel : DML_FEATURE_LEVEL -> "int" ; riid : GUID* -> "sptr" ; ppv : void** optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, intptr ; res = DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, varptr(riid), ppv) ; d3d12Device : ID3D12Device* -> "intptr" ; flags : DML_CREATE_DEVICE_FLAGS -> "int" ; minimumFeatureLevel : DML_FEATURE_LEVEL -> "int" ; riid : GUID* -> "intptr" ; ppv : void** optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // HRESULTfunction 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)。const std = @import("std");
extern "directml" fn DMLCreateDevice1(
d3d12Device: ?*anyopaque, // ID3D12Device*
flags: i32, // DML_CREATE_DEVICE_FLAGS
minimumFeatureLevel: i32, // DML_FEATURE_LEVEL
riid: [*c]GUID, // GUID*
ppv: ?*anyopaque // void** optional, out
) callconv(std.os.windows.WINAPI) i32;proc DMLCreateDevice1(
d3d12Device: pointer, # ID3D12Device*
flags: int32, # DML_CREATE_DEVICE_FLAGS
minimumFeatureLevel: int32, # DML_FEATURE_LEVEL
riid: ptr GUID, # GUID*
ppv: pointer # void** optional, out
): int32 {.importc: "DMLCreateDevice1", stdcall, dynlib: "DirectML.dll".}pragma(lib, "directml");
extern(Windows)
int DMLCreateDevice1(
void* d3d12Device, // ID3D12Device*
int flags, // DML_CREATE_DEVICE_FLAGS
int minimumFeatureLevel, // DML_FEATURE_LEVEL
GUID* riid, // GUID*
void** ppv // void** optional, out
);ccall((:DMLCreateDevice1, "DirectML.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Int32, Ptr{GUID}, Ptr{Cvoid}),
d3d12Device, flags, minimumFeatureLevel, riid, ppv)
# d3d12Device : ID3D12Device* -> Ptr{Cvoid}
# flags : DML_CREATE_DEVICE_FLAGS -> Int32
# minimumFeatureLevel : DML_FEATURE_LEVEL -> Int32
# riid : GUID* -> Ptr{GUID}
# ppv : void** optional, out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t DMLCreateDevice1(
void* d3d12Device,
int32_t flags,
int32_t minimumFeatureLevel,
void* riid,
void** ppv);
]]
local directml = ffi.load("directml")
-- directml.DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv)
-- d3d12Device : ID3D12Device*
-- flags : DML_CREATE_DEVICE_FLAGS
-- minimumFeatureLevel : DML_FEATURE_LEVEL
-- riid : GUID*
-- ppv : void** optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DirectML.dll');
const DMLCreateDevice1 = lib.func('__stdcall', 'DMLCreateDevice1', 'int32_t', ['void *', 'int32_t', 'int32_t', 'void *', 'void *']);
// DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv)
// d3d12Device : ID3D12Device* -> 'void *'
// flags : DML_CREATE_DEVICE_FLAGS -> 'int32_t'
// minimumFeatureLevel : DML_FEATURE_LEVEL -> 'int32_t'
// riid : GUID* -> 'void *'
// ppv : void** optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DirectML.dll", {
DMLCreateDevice1: { parameters: ["pointer", "i32", "i32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv)
// d3d12Device : ID3D12Device* -> "pointer"
// flags : DML_CREATE_DEVICE_FLAGS -> "i32"
// minimumFeatureLevel : DML_FEATURE_LEVEL -> "i32"
// riid : GUID* -> "pointer"
// ppv : void** optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t DMLCreateDevice1(
void* d3d12Device,
int32_t flags,
int32_t minimumFeatureLevel,
void* riid,
void** ppv);
C, "DirectML.dll");
// $ffi->DMLCreateDevice1(d3d12Device, flags, minimumFeatureLevel, riid, ppv);
// d3d12Device : ID3D12Device*
// flags : DML_CREATE_DEVICE_FLAGS
// minimumFeatureLevel : DML_FEATURE_LEVEL
// riid : GUID*
// ppv : void** optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Directml extends StdCallLibrary {
Directml INSTANCE = Native.load("directml", Directml.class);
int DMLCreateDevice1(
Pointer d3d12Device, // ID3D12Device*
int flags, // DML_CREATE_DEVICE_FLAGS
int minimumFeatureLevel, // DML_FEATURE_LEVEL
Pointer riid, // GUID*
Pointer ppv // void** optional, out
);
}@[Link("directml")]
lib LibDirectML
fun DMLCreateDevice1 = DMLCreateDevice1(
d3d12Device : Void*, # ID3D12Device*
flags : Int32, # DML_CREATE_DEVICE_FLAGS
minimumFeatureLevel : Int32, # DML_FEATURE_LEVEL
riid : GUID*, # GUID*
ppv : Void** # void** optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DMLCreateDevice1Native = Int32 Function(Pointer<Void>, Int32, Int32, Pointer<Void>, Pointer<Void>);
typedef DMLCreateDevice1Dart = int Function(Pointer<Void>, int, int, Pointer<Void>, Pointer<Void>);
final DMLCreateDevice1 = DynamicLibrary.open('DirectML.dll')
.lookupFunction<DMLCreateDevice1Native, DMLCreateDevice1Dart>('DMLCreateDevice1');
// d3d12Device : ID3D12Device* -> Pointer<Void>
// flags : DML_CREATE_DEVICE_FLAGS -> Int32
// minimumFeatureLevel : DML_FEATURE_LEVEL -> Int32
// riid : GUID* -> Pointer<Void>
// ppv : void** optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DMLCreateDevice1"
c_DMLCreateDevice1 :: Ptr () -> Int32 -> Int32 -> Ptr () -> Ptr () -> IO Int32
-- d3d12Device : ID3D12Device* -> Ptr ()
-- flags : DML_CREATE_DEVICE_FLAGS -> Int32
-- minimumFeatureLevel : DML_FEATURE_LEVEL -> Int32
-- riid : GUID* -> Ptr ()
-- ppv : void** optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dmlcreatedevice1 =
foreign "DMLCreateDevice1"
((ptr void) @-> int32_t @-> int32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* d3d12Device : ID3D12Device* -> (ptr void) *)
(* flags : DML_CREATE_DEVICE_FLAGS -> int32_t *)
(* minimumFeatureLevel : DML_FEATURE_LEVEL -> int32_t *)
(* riid : GUID* -> (ptr void) *)
(* ppv : void** optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library directml (t "DirectML.dll"))
(cffi:use-foreign-library directml)
(cffi:defcfun ("DMLCreateDevice1" dmlcreate-device1 :convention :stdcall) :int32
(d3d12-device :pointer) ; ID3D12Device*
(flags :int32) ; DML_CREATE_DEVICE_FLAGS
(minimum-feature-level :int32) ; DML_FEATURE_LEVEL
(riid :pointer) ; GUID*
(ppv :pointer)) ; void** optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DMLCreateDevice1 = Win32::API::More->new('DirectML',
'int DMLCreateDevice1(LPVOID d3d12Device, int flags, int minimumFeatureLevel, LPVOID riid, LPVOID ppv)');
# my $ret = $DMLCreateDevice1->Call($d3d12Device, $flags, $minimumFeatureLevel, $riid, $ppv);
# d3d12Device : ID3D12Device* -> LPVOID
# flags : DML_CREATE_DEVICE_FLAGS -> int
# minimumFeatureLevel : DML_FEATURE_LEVEL -> int
# riid : GUID* -> LPVOID
# ppv : void** optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f DMLCreateDevice — 指定したD3D12デバイス上にDirectMLデバイスを作成する。