/// <summary>
        /// Initializes a new instance of the <see cref="EngineAdapterInfo" /> class.
        /// </summary>
        internal EngineAdapterInfo(int adapterIndex, IDXGIAdapter1 adapter)
        {
            this.Outputs      = new List <EngineOutputInfo>();
            this.AdapterIndex = adapterIndex;

            _adapterDescription    = adapter.Description;
            this.IsSoftwareAdapter =
                _adapterDescription.Description == "Microsoft Basic Render Driver" ||
                !string.IsNullOrEmpty(_adapterDescription.Description) && _adapterDescription.Description.Contains("Software") ||
                !string.IsNullOrEmpty(_adapterDescription.Description) && _adapterDescription.Description.Contains("Microsoft Basic Render Driver");
            _d3d11FeatureLevel = D3D11.D3D11.GetSupportedFeatureLevel(adapter);

            //Query for output information
            var lastResult = Result.Ok;
            var actIndex   = 0;

            do
            {
                lastResult = adapter.EnumOutputs(actIndex, out var actOutput);
                if (lastResult.Success)
                {
                    this.Outputs.Add(new EngineOutputInfo(adapterIndex, actIndex, actOutput));
                }
                actIndex++;
            }while (lastResult.Success);
        }
Exemple #2
0
        /// <summary>
        /// Unloads all resources.
        /// </summary>
        public void UnloadResources()
        {
            _immediateContext  = SeeingSharpUtil.DisposeObject(_immediateContext);
            _immediateContext3 = SeeingSharpUtil.DisposeObject(_immediateContext3);
            _device1           = SeeingSharpUtil.DisposeObject(_device1);
            _device3           = SeeingSharpUtil.DisposeObject(_device3);

            _creationFlags = D3D11.DeviceCreationFlags.None;
            _featureLevel  = D3D.FeatureLevel.Level_11_0;
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceHandlerD3D11"/> class.
        /// </summary>
        internal DeviceHandlerD3D11(GraphicsDeviceConfiguration deviceConfig, IDXGIAdapter1 dxgiAdapter)
        {
            _dxgiAdapter = dxgiAdapter;

            // Define possible create flags
            var createFlags = D3D11.DeviceCreationFlags.BgraSupport;

            if (deviceConfig.CoreConfiguration.DebugEnabled)
            {
                createFlags |= D3D11.DeviceCreationFlags.Debug;
            }

            // Define all steps on which we try to initialize Direct3D
            var initParameterQueue =
                new List <Tuple <D3D.FeatureLevel, D3D11.DeviceCreationFlags, HardwareDriverLevel> >();

            // Define all tries for hardware initialization
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_11_1, createFlags, HardwareDriverLevel.Direct3D11));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_11_0, createFlags, HardwareDriverLevel.Direct3D11));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_10_0, createFlags, HardwareDriverLevel.Direct3D10));

            // Try to create the device, each defined configuration step by step
            foreach (var(actFeatureLevel, actCreateFlags, actDriverLevel) in initParameterQueue)
            {
                try
                {
                    // Try to create the device using current parameters
                    var result = D3D11CreateDevice(
                        dxgiAdapter, D3D.DriverType.Unknown, createFlags,
                        new D3D.FeatureLevel[] { actFeatureLevel }, out var device);
                    if (!result.Success)
                    {
                        continue;
                    }
                    if (device == null)
                    {
                        continue;
                    }

                    try
                    {
                        _device1 = device.QueryInterface <D3D11.ID3D11Device1>();
                        _device3 = SeeingSharpUtil.TryExecute(() => _device1.QueryInterface <D3D11.ID3D11Device3>());

                        if (_device3 != null)
                        {
                            _immediateContext3 = _device3.ImmediateContext3;
                        }
                    }
                    finally
                    {
                        SeeingSharpUtil.SafeDispose(ref device);
                    }

                    // Device successfully created, save all parameters and break this loop
                    _featureLevel    = actFeatureLevel;
                    _creationFlags   = actCreateFlags;
                    this.DriverLevel = actDriverLevel;
                    break;
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            // Throw exception on failure
            if (_device1 == null)
            {
                throw new SeeingSharpGraphicsException("Unable to initialize d3d11 device!");
            }

            // Get immediate context from the device
            _immediateContext = _device1.ImmediateContext;
        }