예제 #1
0
        /// <summary>
        /// Loads all adapter information and builds up all needed view models in a background thread.
        /// </summary>
        private void LoadAdapterInformation()
        {
            m_adapters = new List <EngineAdapterInfo>();

            int adapterCount = m_dxgiFactory.GetAdapterCount1();

            for (int loop = 0; loop < adapterCount; loop++)
            {
                try
                {
                    DXGI.Adapter1 actAdapter = m_dxgiFactory.GetAdapter1(loop);
                    m_adapters.Add(new EngineAdapterInfo(loop, actAdapter));
                }
                catch (Exception)
                {
                    //No exception handling needed here
                    // .. adapter information simply can not be gathered
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes all adapters with the specified factory.
        /// </summary>
        /// <param name="factory1">The factory1.</param>
        internal static void Initialize(Factory1 factory1)
        {
            if (staticCollector != null)
            {
                staticCollector.Dispose();
            }

            staticCollector = new DisposeCollector();
            Factory = factory1;
            staticCollector.Collect(Factory);

            int countAdapters = Factory.GetAdapterCount1();
            var adapters = new List<GraphicsAdapter>();
            for (int i = 0; i < countAdapters; i++)
            {
                var adapter = new GraphicsAdapter(i);
                staticCollector.Collect(adapter);
                adapters.Add(adapter);
            }

            Default = adapters[0];
            Adapters = adapters.ToArray();
        }
예제 #3
0
 public WinformsEye()
 {
     factory = new Factory1();
     adapters = Enumerable.Range(0, factory.GetAdapterCount1()).Select(i => new CAdapter(factory.GetAdapter1(i), i)).ToArray();
     windows = new List<ControlWindow>();
 }
예제 #4
0
        public DemoApplication()
        {
            //SharpDX.Configuration.EnableObjectTracking = true;

            _Form = new RenderForm();
            _Timer = new Stopwatch();

            _Form.Width = 1280;
            _Form.Height = 720;

            _Form.MaximumSize = new System.Drawing.Size(1280, 720);
            _Form.MinimumSize = new System.Drawing.Size(1280, 720);

            _Form.MaximizeBox = false;
            _Form.SizeGripStyle = SizeGripStyle.Hide;

            _Form.KeyPress += HandleKeyPress;
            _Form.ClientSizeChanged += HandleClientSizeChanged;
            _Form.KeyDown += HandleKeyDown;

            ModeDescription displayMode = new ModeDescription
            {
                Width = _Form.ClientSize.Width,
                Height = _Form.ClientSize.Height,
                RefreshRate = new Rational(60, 1),
                Format = Format.R8G8B8A8_UNorm
            };

            SwapChainDescription chainDescription = new SwapChainDescription
            {
                ModeDescription = displayMode,
                SampleDescription = new SampleDescription(1, 0),
                BufferCount = 2,
                IsWindowed = true,
                OutputHandle = _Form.Handle,
                SwapEffect = SwapEffect.Sequential,
                Usage = Usage.BackBuffer | Usage.RenderTargetOutput
            };

            _Factory = new Factory1();

            int availableAdapters = _Factory.GetAdapterCount1();

            if(availableAdapters == 0)
            {
                throw new Exception("no adapters are available");
            }

            for(int i = 0; i < availableAdapters; ++i)
            {
            #if DEBUG
                using(Adapter1 dxgiSurfaceAdapter = _Factory.GetAdapter1(i))
                {
                    try
                    {
                    Device1.CreateWithSwapChain(
                        dxgiSurfaceAdapter,
                        DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug,
                        chainDescription,
                        out _Device,
                        out _SwapChain);
                    }
                    catch(SharpDXException)
                    {
                        continue;
                    }

                    _Device2D = new Device2D(dxgiSurfaceAdapter);
                }
            #else
                using (Adapter1 dxgiSurfaceAdapter = _Factory.GetAdapter1(i))
                {
                    try
                    {
                        Device1.CreateWithSwapChain(
                            dxgiSurfaceAdapter,
                            DeviceCreationFlags.BgraSupport,
                            chainDescription,
                            out _Device,
                            out _SwapChain);

                    }
                    catch(SharpDXException)
                    {
                        continue;
                    }

                    _Device2D = new Device2D(dxgiSurfaceAdapter);
                }
            #endif
            }

            _Device2D.Diagnostics.Query("Composition", "FrameBatchCount", out _CompositionFrameBatchCount);
            _Device2D.Diagnostics.Query("Composition", "FrameDuration", out _CompositionFrameDuration);
            _Device2D.Diagnostics.Query("Painting", "FrameDuration", out _PaintingFrameDuration);

            _Timer.Start();

            _Renderer = new D3D10Renderer(_Device);

            HandleClientSizeChanged(null, null);

            _IsResetQueued = true;
        }
예제 #5
0
        /// <summary>
        /// Initializes all adapters with the specified factory.
        /// </summary>
        /// <param name="factory1">The factory1.</param>
        internal static void Initialize(Factory1 factory1)
        {
            if (staticCollector != null)
            {
                staticCollector.Dispose();
            }

            staticCollector = new DisposeCollector();
            defaultFactory = factory1;
            staticCollector.Collect(defaultFactory);

            int countAdapters = defaultFactory.GetAdapterCount1();
            var adapterList = new List<GraphicsAdapter>();
            for (int i = 0; i < countAdapters; i++)
            {
                var adapter = new GraphicsAdapter(i);
                staticCollector.Collect(adapter);
                adapterList.Add(adapter);
            }

            defaultAdapter = adapterList.Count > 0 ? adapterList[0] : null;
            adapters = adapterList.ToArray();
        }
예제 #6
0
        public D3D11GraphicsDevice(bool validation, PresentationParameters presentationParameters)
            : base(GraphicsBackend.Direct3D11, presentationParameters)
        {
#if DEBUG
            SharpDX.Configuration.EnableObjectTracking      = true;
            SharpDX.Configuration.ThrowOnShaderCompileError = false;
#endif
            // Create factory first.
            using (var dxgifactory = new DXGI.Factory1())
            {
                var adapterCount = dxgifactory.GetAdapterCount1();
                for (var i = 0; i < adapterCount; i++)
                {
                    var adapter = dxgifactory.GetAdapter1(i);
                    var desc    = adapter.Description1;

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

                    var creationFlags = DeviceCreationFlags.BgraSupport /* | DeviceCreationFlags.VideoSupport*/;

                    if (validation)
                    {
                        creationFlags |= DeviceCreationFlags.Debug;
                    }

                    try
                    {
                        D3DDevice = new Device(adapter, creationFlags, s_featureLevels);
                    }
                    catch (SharpDXException)
                    {
                        // Remove debug flag not being supported.
                        creationFlags &= ~DeviceCreationFlags.Debug;

                        D3DDevice = new Device(adapter, creationFlags, s_featureLevels);
                    }

                    Features.VendorId   = desc.VendorId;
                    Features.DeviceId   = desc.DeviceId;
                    Features.DeviceName = desc.Description;
                    Log.Debug($"Direct3D Adapter ({i}): VID:{desc.VendorId}, PID:{desc.DeviceId} - {desc.Description}");
                    break;
                }
            }

            FeatureLevel = D3DDevice.FeatureLevel;
            D3DContext   = D3DDevice.ImmediateContext;
            D3DDevice1   = D3DDevice.QueryInterfaceOrNull <Device1>();
            if (D3DDevice1 != null)
            {
                D3DContext1   = D3DContext.QueryInterface <DeviceContext1>();
                D3DAnnotation = D3DContext.QueryInterface <UserDefinedAnnotation>();
            }

            // Detect multithreading
            D3DDevice1.CheckThreadingSupport(out _supportsConcurrentResources, out _supportsCommandLists);
            if (_supportsConcurrentResources &&
                _supportsCommandLists)
            {
                Features.Multithreading = true;
            }

            // Create queue's
            GraphicsQueue = new D3D11CommandQueue(this);

            //ImmediateContext = new D3D11CommandContext(this, Device.ImmediateContext1);
            _mainSwapchain = new D3D11Swapchain(this, presentationParameters);
        }