Exemplo n.º 1
0
        public ID3D12Device5 CreateDevice(IDXGIFactory4 pDxgiFactory)
        {
            // Find the HW adapter
            IDXGIAdapter1 pAdapter;

            var adapters = pDxgiFactory.EnumAdapters1();

            for (uint i = 0; i < adapters.Length; i++)
            {
                pAdapter = adapters[i];
                AdapterDescription1 desc = pAdapter.Description1;

                // Skip SW adapters
                if (desc.Flags.HasFlag(AdapterFlags.Software))
                {
                    continue;
                }
#if DEBUG
                if (D3D12.D3D12GetDebugInterface <ID3D12Debug>(out var pDx12Debug).Success)
                {
                    pDx12Debug.EnableDebugLayer();
                }
#endif
                var res = D3D12.D3D12CreateDevice(pAdapter, Vortice.Direct3D.FeatureLevel.Level_12_0, out ID3D12Device pDevice);
                FeatureDataD3D12Options5 features5 = pDevice.CheckFeatureSupport <FeatureDataD3D12Options5>(Vortice.Direct3D12.Feature.Options5);
                if (features5.RaytracingTier == RaytracingTier.NotSupported)
                {
                    throw new NotSupportedException("Raytracing is not supported on this device.Make sure your GPU supports DXR(such as Nvidia's Volta or Turing RTX) and you're on the latest drivers.The DXR fallback layer is not supported.");
                }

                return(pDevice.QueryInterface <ID3D12Device5>());
            }

            return(null);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsAdapter" /> class.
        /// </summary>
        /// <param name="defaultFactory">The default factory.</param>
        /// <param name="adapterOrdinal">The adapter ordinal.</param>
        internal GraphicsAdapter(Factory1 defaultFactory, int adapterOrdinal)
        {
            this.adapterOrdinal = adapterOrdinal;
            adapter = defaultFactory.GetAdapter1(adapterOrdinal).DisposeBy(this);
            description = adapter.Description1;
            //var nativeOutputs = adapter.Outputs;

            var count = adapter.GetOutputCount();
            outputs = new GraphicsOutput[count];
            for (var i = 0; i < outputs.Length; i++)
                outputs[i] = new GraphicsOutput(this, i).DisposeBy(this);
        }
Exemplo n.º 3
0
        private IDXGIAdapter1?GetHardwareAdapter()
        {
            IDXGIAdapter1?adapter  = null;
            IDXGIFactory6 factory6 = Factory.QueryInterfaceOrNull <IDXGIFactory6>();

            if (factory6 != null)
            {
                for (int adapterIndex = 0;
                     factory6.EnumAdapterByGpuPreference(adapterIndex, GpuPreference.HighPerformance, out adapter).Success;
                     adapterIndex++)
                {
                    if (adapter == null)
                    {
                        continue;
                    }

                    AdapterDescription1 desc = adapter.Description1;

                    if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
                    {
                        // Don't select the Basic Render Driver adapter.
                        adapter.Dispose();
                        continue;
                    }

                    return(adapter);
                }


                factory6.Dispose();
            }

            if (adapter == null)
            {
                for (int adapterIndex = 0;
                     Factory.EnumAdapters1(adapterIndex, out adapter).Success;
                     adapterIndex++)
                {
                    AdapterDescription1 desc = adapter.Description1;

                    if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
                    {
                        // Don't select the Basic Render Driver adapter.
                        adapter.Dispose();
                        continue;
                    }

                    return(adapter);
                }
            }

            return(adapter);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsAdapter" /> class.
        /// </summary>
        /// <param name="defaultFactory">The default factory.</param>
        /// <param name="adapterOrdinal">The adapter ordinal.</param>
        internal GraphicsAdapter(Factory1 defaultFactory, int adapterOrdinal)
        {
            this.adapterOrdinal = adapterOrdinal;
            adapter             = defaultFactory.GetAdapter1(adapterOrdinal).DisposeBy(this);
            description         = adapter.Description1;
            //var nativeOutputs = adapter.Outputs;

            var count = adapter.GetOutputCount();

            outputs = new GraphicsOutput[count];
            for (var i = 0; i < outputs.Length; i++)
            {
                outputs[i] = new GraphicsOutput(this, i).DisposeBy(this);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsAdapter" /> class.
        /// </summary>
        /// <param name="defaultFactory">The default factory.</param>
        /// <param name="adapterOrdinal">The adapter ordinal.</param>
        internal GraphicsAdapter(Factory1 defaultFactory, int adapterOrdinal)
        {
            this.adapterOrdinal     = adapterOrdinal;
            adapter                 = defaultFactory.GetAdapter1(adapterOrdinal).DisposeBy(this);
            description             = adapter.Description1;
            description.Description = description.Description.TrimEnd('\0'); // for some reason sharpDX returns an adaptater name of fixed size filled with trailing '\0'
            //var nativeOutputs = adapter.Outputs;

            var count = adapter.GetOutputCount();

            outputs = new GraphicsOutput[count];
            for (var i = 0; i < outputs.Length; i++)
            {
                outputs[i] = new GraphicsOutput(this, i).DisposeBy(this);
            }

            AdapterUid = adapter.Description1.Luid.ToString();
        }
Exemplo n.º 6
0
        internal void InitializeFromImpl()
        {
            if (CreateDXGIFactory2(true, out IDXGIFactory4 tempDXGIFactory4).Failure)
            {
                throw new InvalidOperationException("Cannot create IDXGIFactory4");
            }


            NativeFactory = tempDXGIFactory4;


            NativeFactory.EnumAdapters1(1, out var adapter);

            AdapterDescription1 desc = adapter.Description1;



            Adapters.Add(adapter);
            Description.Add(adapter.Description.Description);
            VendorId.Add(adapter.Description.DeviceId);


            Adapter = Adapters[0]; // TODO:
        }
Exemplo n.º 7
0
    public HelloDml()
    {
        if (!IsSupported())
        {
            throw new InvalidOperationException("Direct3D12 is not supported on current OS");
        }

        bool validation = false;

#if DEBUG
        if (D3D12.D3D12GetDebugInterface(out ID3D12Debug? debug).Success)
        {
            debug !.EnableDebugLayer();
            debug !.Dispose();
            validation = true;
        }
#endif

        DXGIFactory = DXGI.CreateDXGIFactory2 <IDXGIFactory4>(validation);

        ID3D12Device2?device = default;

        for (int adapterIndex = 0; DXGIFactory.EnumAdapters1(adapterIndex, out IDXGIAdapter1 adapter).Success; adapterIndex++)
        {
            AdapterDescription1 desc = adapter.Description1;

            // Don't select the Basic Render Driver adapter.
            if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
            {
                adapter.Dispose();

                continue;
            }

            if (D3D12.D3D12CreateDevice(adapter, Vortice.Direct3D.FeatureLevel.Level_11_0, out device).Success)
            {
                adapter.Dispose();

                break;
            }
        }

        if (device == null)
        {
            throw new InvalidOperationException("Direct3D12 device could not be created");
        }

        D3D12Device = device !;

        CommandQueueDescription commandQueueDesc = new()
        {
            Type  = CommandListType.Direct,
            Flags = CommandQueueFlags.None,
        };

        D3D12CommandQueue     = D3D12Device.CreateCommandQueue(commandQueueDesc);
        D3D12CommandAllocator = D3D12Device.CreateCommandAllocator(CommandListType.Direct);
        D3D12CommandList      = D3D12Device.CreateCommandList <ID3D12GraphicsCommandList4>(CommandListType.Direct, D3D12CommandAllocator);

        var createFlags = CreateDeviceFlags.None;

#if DEBUG
        createFlags |= CreateDeviceFlags.Debug;
#endif
        DMLDevice = DMLCreateDevice(D3D12Device, createFlags);

        Console.WriteLine($"Highest supported feature level: {DMLDevice.HighestFeatureLevel}");
    }