コード例 #1
0
        /// <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));
        }
コード例 #2
0
 public int CreateSoftwareAdapter([NativeTypeName("HMODULE")] IntPtr Module, [NativeTypeName("IDXGIAdapter **")] IDXGIAdapter **ppAdapter)
 {
     return(((delegate * unmanaged <IDXGIFactory1 *, IntPtr, IDXGIAdapter **, int>)(lpVtbl[11]))((IDXGIFactory1 *)Unsafe.AsPointer(ref this), Module, ppAdapter));
 }
コード例 #3
0
 public int EnumAdapters([NativeTypeName("UINT")] uint Adapter, [NativeTypeName("IDXGIAdapter **")] IDXGIAdapter **ppAdapter)
 {
     return(((delegate * unmanaged <IDXGIFactory1 *, uint, IDXGIAdapter **, int>)(lpVtbl[7]))((IDXGIFactory1 *)Unsafe.AsPointer(ref this), Adapter, ppAdapter));
 }
コード例 #4
0
 public HRESULT GetAdapter(IDXGIAdapter **pAdapter)
 {
     return(((delegate * unmanaged <IDXGIDevice4 *, IDXGIAdapter **, int>)(lpVtbl[7]))((IDXGIDevice4 *)Unsafe.AsPointer(ref this), pAdapter));
 }
コード例 #5
0
 public HRESULT EnumAdapters(uint Adapter, IDXGIAdapter **ppAdapter)
 {
     return(((delegate * unmanaged <IDXGIFactory4 *, uint, IDXGIAdapter **, int>)(lpVtbl[7]))((IDXGIFactory4 *)Unsafe.AsPointer(ref this), Adapter, ppAdapter));
 }
コード例 #6
0
 public HRESULT CreateSoftwareAdapter(HMODULE Module, IDXGIAdapter **ppAdapter)
 {
     return(((delegate * unmanaged <IDXGIFactory4 *, HMODULE, IDXGIAdapter **, int>)(lpVtbl[11]))((IDXGIFactory4 *)Unsafe.AsPointer(ref this), Module, ppAdapter));
 }
コード例 #7
0
        /// <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);
                    }
                }
            }
        }
コード例 #8
0
 public int GetAdapter([NativeTypeName("IDXGIAdapter **")] IDXGIAdapter **pAdapter)
 {
     return(((delegate * unmanaged <IDXGIDevice4 *, IDXGIAdapter **, int>)(lpVtbl[7]))((IDXGIDevice4 *)Unsafe.AsPointer(ref this), pAdapter));
 }