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

DMLCreateDevice

関数
指定したD3D12デバイス上にDirectMLデバイスを作成する。
DLLDirectML.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

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

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

パラメーター

名前方向説明
d3d12DeviceID3D12Device*inDirectMLデバイスの基盤となるDirect3D 12デバイス。GPU実行リソースを供給する。
flagsDML_CREATE_DEVICE_FLAGSinデバイス生成オプションを指定するDML_CREATE_DEVICE_FLAGSビット値。デバッグ層有効化などを指定する。
riidGUID*in取得するDirectMLデバイスインターフェイスのGUID。通常IID_IDMLDeviceを指す。
ppvvoid**outoptional生成したデバイスインターフェイスポインタを受け取る出力先。voidダブルポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT DMLCreateDevice(
    ID3D12Device* d3d12Device,
    DML_CREATE_DEVICE_FLAGS flags,
    const GUID* riid,
    void** ppv   // optional
);
[DllImport("DirectML.dll", ExactSpelling = true)]
static extern int DMLCreateDevice(
    IntPtr d3d12Device,   // ID3D12Device*
    int flags,   // DML_CREATE_DEVICE_FLAGS
    ref Guid riid,   // GUID*
    IntPtr ppv   // void** optional, out
);
<DllImport("DirectML.dll", ExactSpelling:=True)>
Public Shared Function DMLCreateDevice(
    d3d12Device As IntPtr,   ' ID3D12Device*
    flags As Integer,   ' DML_CREATE_DEVICE_FLAGS
    ByRef riid As Guid,   ' GUID*
    ppv As IntPtr   ' void** optional, out
) As Integer
End Function
' d3d12Device : ID3D12Device*
' flags : DML_CREATE_DEVICE_FLAGS
' riid : GUID*
' ppv : void** optional, out
Declare PtrSafe Function DMLCreateDevice Lib "directml" ( _
    ByVal d3d12Device As LongPtr, _
    ByVal flags 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

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

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

var (
	directml = windows.NewLazySystemDLL("DirectML.dll")
	procDMLCreateDevice = directml.NewProc("DMLCreateDevice")
)

// d3d12Device (ID3D12Device*), flags (DML_CREATE_DEVICE_FLAGS), riid (GUID*), ppv (void** optional, out)
r1, _, err := procDMLCreateDevice.Call(
	uintptr(d3d12Device),
	uintptr(flags),
	uintptr(riid),
	uintptr(ppv),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DMLCreateDevice(
  d3d12Device: Pointer;   // ID3D12Device*
  flags: Integer;   // DML_CREATE_DEVICE_FLAGS
  riid: PGUID;   // GUID*
  ppv: Pointer   // void** optional, out
): Integer; stdcall;
  external 'DirectML.dll' name 'DMLCreateDevice';
result := DllCall("DirectML\DMLCreateDevice"
    , "Ptr", d3d12Device   ; ID3D12Device*
    , "Int", flags   ; DML_CREATE_DEVICE_FLAGS
    , "Ptr", riid   ; GUID*
    , "Ptr", ppv   ; void** optional, out
    , "Int")   ; return: HRESULT
●DMLCreateDevice(d3d12Device, flags, riid, ppv) = DLL("DirectML.dll", "int DMLCreateDevice(void*, int, void*, void*)")
# 呼び出し: DMLCreateDevice(d3d12Device, flags, riid, ppv)
# d3d12Device : ID3D12Device* -> "void*"
# flags : DML_CREATE_DEVICE_FLAGS -> "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 DMLCreateDevice(
    d3d12Device: ?*anyopaque, // ID3D12Device*
    flags: i32, // DML_CREATE_DEVICE_FLAGS
    riid: [*c]GUID, // GUID*
    ppv: ?*anyopaque // void** optional, out
) callconv(std.os.windows.WINAPI) i32;
proc DMLCreateDevice(
    d3d12Device: pointer,  # ID3D12Device*
    flags: int32,  # DML_CREATE_DEVICE_FLAGS
    riid: ptr GUID,  # GUID*
    ppv: pointer  # void** optional, out
): int32 {.importc: "DMLCreateDevice", stdcall, dynlib: "DirectML.dll".}
pragma(lib, "directml");
extern(Windows)
int DMLCreateDevice(
    void* d3d12Device,   // ID3D12Device*
    int flags,   // DML_CREATE_DEVICE_FLAGS
    GUID* riid,   // GUID*
    void** ppv   // void** optional, out
);
ccall((:DMLCreateDevice, "DirectML.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Ptr{GUID}, Ptr{Cvoid}),
      d3d12Device, flags, riid, ppv)
# d3d12Device : ID3D12Device* -> Ptr{Cvoid}
# flags : DML_CREATE_DEVICE_FLAGS -> Int32
# riid : GUID* -> Ptr{GUID}
# ppv : void** optional, out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DMLCreateDevice(
    void* d3d12Device,
    int32_t flags,
    void* riid,
    void** ppv);
]]
local directml = ffi.load("directml")
-- directml.DMLCreateDevice(d3d12Device, flags, riid, ppv)
-- d3d12Device : ID3D12Device*
-- flags : DML_CREATE_DEVICE_FLAGS
-- riid : GUID*
-- ppv : void** optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('DirectML.dll');
const DMLCreateDevice = lib.func('__stdcall', 'DMLCreateDevice', 'int32_t', ['void *', 'int32_t', 'void *', 'void *']);
// DMLCreateDevice(d3d12Device, flags, riid, ppv)
// d3d12Device : ID3D12Device* -> 'void *'
// flags : DML_CREATE_DEVICE_FLAGS -> 'int32_t'
// riid : GUID* -> 'void *'
// ppv : void** optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("DirectML.dll", {
  DMLCreateDevice: { parameters: ["pointer", "i32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.DMLCreateDevice(d3d12Device, flags, riid, ppv)
// d3d12Device : ID3D12Device* -> "pointer"
// flags : DML_CREATE_DEVICE_FLAGS -> "i32"
// riid : GUID* -> "pointer"
// ppv : void** optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DMLCreateDevice(
    void* d3d12Device,
    int32_t flags,
    void* riid,
    void** ppv);
C, "DirectML.dll");
// $ffi->DMLCreateDevice(d3d12Device, flags, riid, ppv);
// d3d12Device : ID3D12Device*
// flags : DML_CREATE_DEVICE_FLAGS
// 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 DMLCreateDevice(
        Pointer d3d12Device,   // ID3D12Device*
        int flags,   // DML_CREATE_DEVICE_FLAGS
        Pointer riid,   // GUID*
        Pointer ppv   // void** optional, out
    );
}
@[Link("directml")]
lib LibDirectML
  fun DMLCreateDevice = DMLCreateDevice(
    d3d12Device : Void*,   # ID3D12Device*
    flags : Int32,   # DML_CREATE_DEVICE_FLAGS
    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 DMLCreateDeviceNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Pointer<Void>);
typedef DMLCreateDeviceDart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Void>);
final DMLCreateDevice = DynamicLibrary.open('DirectML.dll')
    .lookupFunction<DMLCreateDeviceNative, DMLCreateDeviceDart>('DMLCreateDevice');
// d3d12Device : ID3D12Device* -> Pointer<Void>
// flags : DML_CREATE_DEVICE_FLAGS -> Int32
// riid : GUID* -> Pointer<Void>
// ppv : void** optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DMLCreateDevice(
  d3d12Device: Pointer;   // ID3D12Device*
  flags: Integer;   // DML_CREATE_DEVICE_FLAGS
  riid: PGUID;   // GUID*
  ppv: Pointer   // void** optional, out
): Integer; stdcall;
  external 'DirectML.dll' name 'DMLCreateDevice';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DMLCreateDevice"
  c_DMLCreateDevice :: Ptr () -> Int32 -> Ptr () -> Ptr () -> IO Int32
-- d3d12Device : ID3D12Device* -> Ptr ()
-- flags : DML_CREATE_DEVICE_FLAGS -> Int32
-- riid : GUID* -> Ptr ()
-- ppv : void** optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dmlcreatedevice =
  foreign "DMLCreateDevice"
    ((ptr void) @-> int32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* d3d12Device : ID3D12Device* -> (ptr void) *)
(* flags : DML_CREATE_DEVICE_FLAGS -> 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 ("DMLCreateDevice" dmlcreate-device :convention :stdcall) :int32
  (d3d12-device :pointer)   ; ID3D12Device*
  (flags :int32)   ; DML_CREATE_DEVICE_FLAGS
  (riid :pointer)   ; GUID*
  (ppv :pointer))   ; void** optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DMLCreateDevice = Win32::API::More->new('DirectML',
    'int DMLCreateDevice(LPVOID d3d12Device, int flags, LPVOID riid, LPVOID ppv)');
# my $ret = $DMLCreateDevice->Call($d3d12Device, $flags, $riid, $ppv);
# d3d12Device : ID3D12Device* -> LPVOID
# flags : DML_CREATE_DEVICE_FLAGS -> int
# riid : GUID* -> LPVOID
# ppv : void** optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型