/// <summary> /// Creates a new <see cref="GraphicsDeviceInfo"/> instance with the specified parameters. /// </summary> /// <param name="dxgiDescription1">The available info for the associated device.</param> internal unsafe GraphicsDeviceInfo(DXGI_ADAPTER_DESC1 *dxgiDescription1) { Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid); Name = new string((char *)dxgiDescription1->Description); DedicatedMemorySize = dxgiDescription1->DedicatedVideoMemory; SharedMemorySize = dxgiDescription1->SharedSystemMemory; IsHardwareAccelerated = (dxgiDescription1->Flags & (uint)DXGI_ADAPTER_FLAG_SOFTWARE) == 0; }
/// <summary> /// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>. /// </summary> /// <param name="d3D12Device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice"/> instance.</param> /// <param name="dxgiAdapter">The <see cref="IDXGIAdapter"/> that <paramref name="d3D12Device"/> was created from.</param> /// <param name="dxgiDescription1">The available info for the new <see cref="GraphicsDevice"/> instance.</param> internal GraphicsDevice(ID3D12Device *d3D12Device, IDXGIAdapter *dxgiAdapter, DXGI_ADAPTER_DESC1 *dxgiDescription1) { this.d3D12Device = new ComPtr <ID3D12Device>(d3D12Device); this.d3D12ComputeCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COMPUTE); this.d3D12CopyCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COPY); this.d3D12ComputeFence = d3D12Device->CreateFence(); this.d3D12CopyFence = d3D12Device->CreateFence(); this.shaderResourceViewDescriptorAllocator = new ID3D12DescriptorHandleAllocator(d3D12Device); this.computeCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COMPUTE); this.copyCommandListPool = new ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE_COPY); Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid); Name = new string((char *)dxgiDescription1->Description); DedicatedMemorySize = dxgiDescription1->DedicatedVideoMemory; SharedMemorySize = dxgiDescription1->SharedSystemMemory; IsHardwareAccelerated = (dxgiDescription1->Flags & (uint)DXGI_ADAPTER_FLAG_SOFTWARE) == 0; var d3D12Options1Data = d3D12Device->CheckFeatureSupport <D3D12_FEATURE_DATA_D3D12_OPTIONS1>(D3D12_FEATURE_D3D12_OPTIONS1); ComputeUnits = d3D12Options1Data.TotalLaneCount; WavefrontSize = d3D12Options1Data.WaveLaneCountMin; var d3D12Architecture1Data = d3D12Device->CheckFeatureSupport <D3D12_FEATURE_DATA_ARCHITECTURE1>(D3D12_FEATURE_ARCHITECTURE1); IsCacheCoherentUMA = d3D12Architecture1Data.CacheCoherentUMA != 0; #if NET6_0_OR_GREATER this.allocator = d3D12Device->CreateAllocator(dxgiAdapter); if (IsCacheCoherentUMA) { this.pool = this.allocator.Get()->CreatePoolForCacheCoherentUMA(); } #endif }
public int GetDesc1([NativeTypeName("DXGI_ADAPTER_DESC1 *")] DXGI_ADAPTER_DESC1 *pDesc) { return(((delegate * stdcall <IDXGIAdapter2 *, DXGI_ADAPTER_DESC1 *, int>)(lpVtbl[10]))((IDXGIAdapter2 *)Unsafe.AsPointer(ref this), pDesc)); }
public HRESULT GetDesc1(DXGI_ADAPTER_DESC1 *pDesc) { return(((delegate * unmanaged[Stdcall] < IDXGIAdapter1 *, DXGI_ADAPTER_DESC1 *, int >)(lpVtbl[10]))((IDXGIAdapter1 *)Unsafe.AsPointer(ref this), pDesc)); }
/// <summary> /// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>. /// </summary> /// <param name="d3D12Device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice"/> instance.</param> /// <param name="dxgiAdapter">The <see cref="IDXGIAdapter"/> that <paramref name="d3D12Device"/> was created from.</param> /// <param name="dxgiDescription1">The available info for the new <see cref="GraphicsDevice"/> instance.</param> internal GraphicsDevice(ID3D12Device *d3D12Device, IDXGIAdapter *dxgiAdapter, DXGI_ADAPTER_DESC1 *dxgiDescription1) { this.d3D12Device = new ComPtr <ID3D12Device>(d3D12Device); this.d3D12ComputeCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COMPUTE); this.d3D12CopyCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COPY); this.d3D12ComputeFence = d3D12Device->CreateFence(); this.d3D12CopyFence = d3D12Device->CreateFence(); this.computeCommandAllocatorPool = new ID3D12CommandAllocatorPool(D3D12_COMMAND_LIST_TYPE_COMPUTE); this.copyCommandAllocatorPool = new ID3D12CommandAllocatorPool(D3D12_COMMAND_LIST_TYPE_COPY); this.shaderResourceViewDescriptorAllocator = new ID3D12DescriptorHandleAllocator(d3D12Device); Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid); Name = new string((char *)dxgiDescription1->Description); DedicatedMemorySize = dxgiDescription1->DedicatedVideoMemory; SharedMemorySize = dxgiDescription1->SharedSystemMemory; IsHardwareAccelerated = (dxgiDescription1->Flags & (uint)DXGI_ADAPTER_FLAG_SOFTWARE) == 0; var d3D12Options1Data = d3D12Device->CheckFeatureSupport <D3D12_FEATURE_DATA_D3D12_OPTIONS1>(D3D12_FEATURE_D3D12_OPTIONS1); ComputeUnits = d3D12Options1Data.TotalLaneCount; WavefrontSize = d3D12Options1Data.WaveLaneCountMin; var d3D12Architecture1Data = d3D12Device->CheckFeatureSupport <D3D12_FEATURE_DATA_ARCHITECTURE1>(D3D12_FEATURE_ARCHITECTURE1); IsCacheCoherentUMA = d3D12Architecture1Data.CacheCoherentUMA != 0; D3D12MA_ALLOCATOR_DESC allocatorDesc = default; allocatorDesc.pDevice = d3D12Device; allocatorDesc.pAdapter = dxgiAdapter; if (!IsCacheCoherentUMA) { fixed(D3D12MA_Allocator **allocator = this.allocator) { D3D12MemAlloc.D3D12MA_CreateAllocator(&allocatorDesc, allocator).Assert(); } } }
/// <summary> /// Tries to check or create a default <see cref="ID3D12Device"/> object. /// </summary> /// <param name="d3D12Device">A pointer to the <see cref="ID3D12Device"/> object to create, or <see langword="null"/>.</param> /// <param name="dxgiAdapter">A pointer to the <see cref="IDXGIAdapter"/> object used to create <paramref name="d3D12Device"/>, or <see langword="null"/>.</param> /// <param name="dxgiDescription1">A pointer to the <see cref="DXGI_ADAPTER_DESC1"/> value for the device found.</param> /// <returns>Whether a default device was found with the requested feature level.</returns> private static unsafe bool TryGetDefaultDevice(ID3D12Device **d3D12Device, IDXGIAdapter **dxgiAdapter, DXGI_ADAPTER_DESC1 *dxgiDescription1) { using ComPtr <IDXGIFactory4> dxgiFactory4 = default; EnableDebugMode(); FX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, FX.__uuidof <IDXGIFactory4>(), dxgiFactory4.GetVoidAddressOf()).Assert(); uint i = 0; while (true) { using ComPtr <IDXGIAdapter1> dxgiAdapter1 = default; HRESULT enumAdapters1Result = dxgiFactory4.Get()->EnumAdapters1(i++, dxgiAdapter1.GetAddressOf()); if (enumAdapters1Result == FX.DXGI_ERROR_NOT_FOUND) { return(false); } enumAdapters1Result.Assert(); dxgiAdapter1.Get()->GetDesc1(dxgiDescription1).Assert(); if (dxgiDescription1->VendorId == MicrosoftVendorId && dxgiDescription1->DeviceId == WarpDeviceId) { continue; } // Explicit paths for when a device is being retrieved or not, with special handling // for the additional check that is required for the SM6 level. This can't be checked // without creating a device first, so the path for when the target device pointer is // null is useful to do an initial filtering using D3D12CreateDevice to avoid creating // a device for adapters that would've failed at the FL11 check already. if (d3D12Device == null) { HRESULT createDeviceResult = FX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, FX.__uuidof <ID3D12Device>(), null); if (FX.SUCCEEDED(createDeviceResult)) { using ComPtr <ID3D12Device> d3D12DeviceCandidate = default; createDeviceResult = FX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, FX.__uuidof <ID3D12Device>(), d3D12DeviceCandidate.GetVoidAddressOf()); if (FX.SUCCEEDED(createDeviceResult) && d3D12DeviceCandidate.Get()->IsShaderModelSupported(D3D_SHADER_MODEL_6_0)) { return(true); } } } else { using ComPtr <ID3D12Device> d3D12DeviceCandidate = default; HRESULT createDeviceResult = FX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, FX.__uuidof <ID3D12Device>(), d3D12DeviceCandidate.GetVoidAddressOf()); if (FX.SUCCEEDED(createDeviceResult) && d3D12DeviceCandidate.Get()->IsShaderModelSupported(D3D_SHADER_MODEL_6_0)) { d3D12DeviceCandidate.CopyTo(d3D12Device); dxgiAdapter1.CopyTo(dxgiAdapter); return(true); } } } }
/// <summary> /// Tries to check or create a warp <see cref="ID3D12Device"/> object. /// </summary> /// <param name="d3D12Device">A pointer to the <see cref="ID3D12Device"/> object to create, or <see langword="null"/>.</param> /// <param name="dxgiAdapter">A pointer to the <see cref="IDXGIAdapter"/> object used to create <paramref name="d3D12Device"/>, or <see langword="null"/>.</param> /// <param name="dxgiDescription1">A pointer to the <see cref="DXGI_ADAPTER_DESC1"/> value for the device found.</param> /// <returns>Whether a warp device was created successfully.</returns> private static unsafe bool TryGetWarpDevice(ID3D12Device **d3D12Device, IDXGIAdapter **dxgiAdapter, DXGI_ADAPTER_DESC1 *dxgiDescription1) { using ComPtr <IDXGIFactory4> dxgiFactory4 = default; EnableDebugMode(); FX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, FX.__uuidof <IDXGIFactory4>(), dxgiFactory4.GetVoidAddressOf()).Assert(); using ComPtr <IDXGIAdapter1> dxgiAdapter1 = default; dxgiFactory4.Get()->EnumWarpAdapter(FX.__uuidof <IDXGIAdapter1>(), dxgiAdapter1.GetVoidAddressOf()).Assert(); dxgiAdapter1.Get()->GetDesc1(dxgiDescription1).Assert(); HRESULT createDeviceResult = FX.D3D12CreateDevice( dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, FX.__uuidof <ID3D12Device>(), (void **)d3D12Device); dxgiAdapter1.CopyTo(dxgiAdapter); return(FX.SUCCEEDED(createDeviceResult)); }
public int GetDesc1(DXGI_ADAPTER_DESC1 *pDesc) { return(((delegate * unmanaged <IDXGIAdapter2 *, DXGI_ADAPTER_DESC1 *, int>)(lpVtbl[10]))((IDXGIAdapter2 *)Unsafe.AsPointer(ref this), pDesc)); }