static public Dev GetDev(uint reg_id, uint gen_id,
                                 uint fill_light_id, uint gas_id)
        {
            Dev ret;

            if (RegList[reg_id] is DebugReg)
            {
                ret = new DeviceDebug();
            }
            else
            {
                if (RegList[reg_id] is MLRegDev)
                {
                    return(new MLDevice(RegList[reg_id], GenList[gen_id],
                                        DevFillLightList[fill_light_id],
                                        DevGasList[gas_id]));
                }
                else
                {
                    if (RegList[reg_id] is USBConRegDev)
                    {
                        return(new USBConDev(RegList[reg_id], GenList[gen_id],
                                             DevFillLightList[fill_light_id],
                                             DevGasList[gas_id]));
                    }
                    else
                    {
                        throw new Exception("Not supported registrator id");
                    }
                }
            }
            return(ret);
        }
Beispiel #2
0
        public Renderer()
        {
            SharpDX.Configuration.EnableReleaseOnFinalizer = true;

            this.Factory = ToDispose(new SharpDX.DXGI.Factory2());
            using (var adapter = this.Factory.Adapters[0])
            {
#if DEBUG
                try
                {
                    this.Device      = ToDispose(new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.Debug, FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3));
                    this.DeviceDebug = ToDispose(new DeviceDebug(this.Device));
                }
                catch (SharpDX.SharpDXException ex)
                {
                    if (ex.ResultCode.Code == -2005270483)
                    {
                        IgnitionDX.Utilities.Logger.LogWarning(this, "The D3D Debug-Runtime not installed. Creating device without debug flag.");
                        this.Device = ToDispose(new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.None, FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3));
                    }
                }
#else
                this.Device = ToDispose(new SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.None, FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3));
#endif
                this.DeviceContext = ToDispose(this.Device.ImmediateContext);
            }
        }
Beispiel #3
0
        internal Renderer(LoopWindow Window)
        {
            var Levels = new[]
            {
                FeatureLevel.Level_11_0,
                FeatureLevel.Level_10_1,
                FeatureLevel.Level_10_0,
                FeatureLevel.Level_9_3,
                FeatureLevel.Level_9_2,
                FeatureLevel.Level_9_1,
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport | (Program.DebugMode ? DeviceCreationFlags.Debug : DeviceCreationFlags.None), Levels, new SwapChainDescription
            {
                BufferCount     = 1,
                Flags           = SwapChainFlags.AllowModeSwitch,
                IsWindowed      = true,
                ModeDescription = new ModeDescription
                {
                    Format = FormatRGB
                },
                OutputHandle      = Window.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            }, out Device, out SwapChain);


            var Bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;

            using (var Factory = SwapChain.GetParent <Factory>())
            {
                foreach (var Output in Factory.Adapters.First().Outputs)
                {
                    foreach (var PossibleResolution in Output.GetDisplayModeList(FormatRGB, 0))
                    {
                        if (PossibleResolution.Width == Bounds.Width && PossibleResolution.Height == Bounds.Height)
                        {
                            Resolution = PossibleResolution;
                        }
                    }
                }
            }

            Window.Borderless(Resolution.Width, Resolution.Height);
            ResizeBuffers();

            Depth.InitStencilRasterState(Device);
            LoadWithAA(1);

            Device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            if (Program.DebugMode)
            {
                Debug = new DeviceDebug(Device);
            }
        }
Beispiel #4
0
        internal static void DisposeDevice()
        {
            ForceWindowed();

            OnDeviceEnd();

            m_initialized = false;

            MyHBAO.ReleaseScreenResources();

            if (MyGBuffer.Main != null)
            {
                MyGBuffer.Main.Release();
                MyGBuffer.Main = null;
            }

            if (Backbuffer != null)
            {
                Backbuffer.Release();
                Backbuffer = null;
            }

            if (m_swapchain != null)
            {
                m_swapchain.Dispose();
                m_swapchain = null;
            }

            if (RC != null)
            {
                RC.Dispose();
                RC = null;
            }

            if (Device != null)
            {
#if DEBUG
                if (VRage.MyCompilationSymbols.DX11Debug)
                {
                    var deviceDebug = new DeviceDebug(Device);
                    deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail | ReportingLevel.Summary);
                    deviceDebug.Dispose();
                }
#endif

                Device.Dispose();
                Device = null;
                WIC    = null;
            }

            if (m_factory != null)
            {
                m_factory.Dispose();
                m_factory = null;
            }
        }
        protected override void PlatformDispose()
        {
            DeviceDebug deviceDebug = _device.QueryInterfaceOrNull <DeviceDebug>();

            if (deviceDebug != null)
            {
                deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Summary);
                deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail);
            }
        }
        /// <summary>
        /// Helps finding any remaining unreleased references via console output, which can be
        /// enabled by using Dx Control Panel and adding the app there (DX11) and also enabling
        /// native debugging output in the properties of the project to debug. Then see Output window.
        /// </summary>
        private void OutputRefCountOfLiveObjectsToFindMemoryLeaksInDebugMode()
        {
#if DEBUG
            var deviceDebug = new DeviceDebug(nativeDevice);
            // http://sharpdx.org/forum/4-general/1241-reportliveobjects
            // Contains several Refcount: 0 lines. This cannot be avoided, but is still be useful to
            // find memory leaks (all objects should have Refcount=0, the device still has RefCount=3)
            deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail);
            deviceDebug.Dispose();
#endif
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">Device</param>
        /// <param name="breakOnWarning">Generate an error on warning</param>
        public SharpDebugger(SharpDevice device, bool breakOnWarning)
        {
            _device = device;
            //init the debug device
            Debug = new DeviceDebug(device.Device);
            //init the queue interface
            Queue = Debug.QueryInterface <InfoQueue>();

            if (breakOnWarning)
            {
                Queue.SetBreakOnSeverity(MessageSeverity.Warning, true);
            }
        }
        internal static void DisposeDevice()
        {
            ForceWindowed();

            OnDeviceEnd();

            if (MyGBuffer.Main != null)
            {
                MyGBuffer.Main.Release();
                MyGBuffer.Main = null;
            }

            if (Backbuffer != null)
            {
                Backbuffer.Release();
                Backbuffer = null;
            }

            if (m_swapchain != null)
            {
                m_swapchain.Dispose();
                m_swapchain = null;
            }

            if (DeviceContext != null)
            {
                DeviceContext.Dispose();
                DeviceContext = null;
            }

            if (Device != null)
            {
#if DEBUG
                if (VRage.MyCompilationSymbols.DX11Debug)
                {
                    var deviceDebug = new DeviceDebug(Device);
                    deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail | ReportingLevel.Summary);
                    deviceDebug.Dispose();
                }
#endif

                Device.Dispose();
                Device = null;
            }

            if (m_factory != null)
            {
                m_factory.Dispose();
                m_factory = null;
            }
        }
Beispiel #9
0
        public bool Save([FromBody] DeviceDebug devicedebug)
        {
            DeviceDebug temp = db.dbdao.GetById <DeviceDebug>(devicedebug.id.ToString());

            if (temp != null)
            {
                return(dbdao.DbUpdate(devicedebug));
            }
            else
            {
                return(dbdao.DbInsert(devicedebug));
            }
            //return device.id;
        }
        internal static void DisposeDevice()
        {
            ForceWindowed();

            OnDeviceEnd();

            if (MyGBuffer.Main != null)
            {
                MyGBuffer.Main.Release();
                MyGBuffer.Main = null;
            }

            if (Backbuffer != null)
            {
                Backbuffer.Release();
                Backbuffer = null;
            }

            if (m_swapchain != null)
            {
                m_swapchain.Dispose();
                m_swapchain = null;
            }

            if (ImmediateContext != null)
            {
                ImmediateContext.Dispose();
                ImmediateContext = null;
            }

            if (Device != null)
            {
    #if DEBUG_DEVICE
                var deviceDebug = new DeviceDebug(Device);
                deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail);
                deviceDebug.Dispose();
    #endif

                Device.Dispose();
                Device = null;
            }

            if (m_factory != null)
            {
                m_factory.Dispose();
                m_factory = null;
            }
        }
Beispiel #11
0
        protected override void PlatformDispose()
        {
            _d3d11ResourceFactory.Dispose();
            _mainSwapchain?.Dispose();
            _immediateContext.Dispose();

            DeviceDebug deviceDebug = _device.QueryInterfaceOrNull <DeviceDebug>();

            _device.Dispose();

            if (deviceDebug != null)
            {
                deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Summary);
                deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail);
                deviceDebug.Dispose();
            }
        }
Beispiel #12
0
        private void ReleaseDevice()
        {
            // Display D3D11 ref counting info
            ClearState();
            NativeDevice.ImmediateContext.Flush();
            NativeDevice.ImmediateContext.Dispose();

            if (IsDebugMode)
            {
                var deviceDebug = new DeviceDebug(NativeDevice);
                deviceDebug.ReportLiveDeviceObjects(ReportingLevel.Detail);
            }

            currentInputLayout          = null;
            currentEffectInputSignature = null;
            currentVertexArrayObject    = null;
            currentVertexArrayLayout    = null;
            nativeDevice.Dispose();
        }
Beispiel #13
0
        public async Task Execute(dynamic[] Args)
        {
            if (Args.Length == 0 || (Args.Length == 1 && Args[0] == 0))
            {
                Base.Exit();
            }
            else if (Args.Length == 1 && Args[0] == 1)
            {
                var debug = new DeviceDebug(Base.DXDevice);
                debug.ReportLiveDeviceObjects(ReportingLevel.Detail | ReportingLevel.Summary);
                debug.Dispose();

                Base.Exit();
                Render.Elements.AllElements.Clear();
                Base.WaitForTheBox();

                Environment.Exit(0);
            }
        }
Beispiel #14
0
        public override void Cleanup()
        {
            DeviceDebug device3DDebug = null;

            if (IsDebugMode)
            {
                device3DDebug = new DeviceDebug(DeviceRef);
            }

            SwapChainRef?.Dispose();
            SwapChainRef = null;
            base.Cleanup();

            if (IsDebugMode && device3DDebug != null)
            {
                device3DDebug.ReportLiveDeviceObjects(ReportingLevel.Detail);
                System.Diagnostics.Debug.Write(SharpDX.Diagnostics.ObjectTracker.ReportActiveObjects());
            }
        }
Beispiel #15
0
        public void DisposeFrames()
        {
            DrawContext.Dispose();
            Brush?.Dispose();
            DeviceContext.Target = null;
            DeviceContext3D.OutputMerger.SetRenderTargets((RenderTargetView)null);
            DeviceContext3D.ClearState();

            foreach (var resource in FrameResources)
            {
                resource.Bitmap.Dispose();
                resource.Surface.Dispose();
                resource.WrappedBackBuffer.Dispose();
                resource.RenderTarget.Dispose();
            }

            DeviceContext3D.Flush();

#if false
            DeviceDebug debug = Device3D11.QueryInterface <DeviceDebug>();
            debug.ReportLiveDeviceObjects(ReportingLevel.Detail);
            debug.Dispose();
#endif
        }
Beispiel #16
0
        public bool Initialize(GameForm pForm, bool pFullScreen)
        {
            _form = pForm;
            try
            {
#if DEBUG
                Device defaultDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport);
                _debug = defaultDevice.QueryInterface <DeviceDebug>();
#else
                Device defaultDevice = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport);
#endif
                Device = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>();

                var dxgiDevice2  = Device.QueryInterface <SharpDX.DXGI.Device2>();
                var dxgiFactory2 = dxgiDevice2.Adapter.GetParent <SharpDX.DXGI.Factory2>();

                // SwapChain description
                var desc = new SwapChainDescription1()
                {
                    Width             = 0,
                    Height            = 0,
                    Format            = Format.B8G8R8A8_UNorm,
                    Stereo            = false,
                    SampleDescription = new SampleDescription(1, 0),
                    BufferCount       = BUFFER_COUNT,
                    Scaling           = Scaling.None,
                    SwapEffect        = SwapEffect.FlipSequential,
                    Usage             = Usage.RenderTargetOutput
                };

                _swapChain       = new SwapChain1(dxgiFactory2, Device, pForm.Handle, ref desc, null);
                _2dDevice        = new SharpDX.Direct2D1.Device(dxgiDevice2);
                Context          = new SharpDX.Direct2D1.DeviceContext(_2dDevice, DeviceContextOptions.EnableMultithreadedOptimizations);
                SecondaryContext = new SharpDX.Direct2D1.DeviceContext(_2dDevice, DeviceContextOptions.None);
#if DEBUG
                Factory2D = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded, DebugLevel.Information);
#else
                Factory2D = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded);
#endif
                var dpi  = Factory2D.DesktopDpi;
                var prop = new BitmapProperties1(new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), dpi.Height, dpi.Width, BitmapOptions.CannotDraw | BitmapOptions.Target);
                _backBuffer    = _swapChain.GetBackBuffer <Surface>(0);
                _renderTarget  = new Bitmap1(Context, _backBuffer, prop);
                Context.Target = _renderTarget;

                // Ignore all windows events
                using (Factory factory = _swapChain.GetParent <Factory>())
                {
                    factory.MakeWindowAssociation(pForm.Handle, WindowAssociationFlags.IgnoreAll);
                }

                FactoryDWrite = new SharpDX.DirectWrite.Factory();

                return(true);
            }
            catch (System.Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error creating render target: " + e.Message);
                return(false);
            }
        }
        internal static MyRenderDeviceSettings CreateDevice(IntPtr windowHandle, MyRenderDeviceSettings?settingsToTry)
        {
            if (Device != null)
            {
                Device.Dispose();
                Device = null;
            }

            FeatureLevel[]      featureLevels = { FeatureLevel.Level_11_0 };
            DeviceCreationFlags flags         = DeviceCreationFlags.None;

    #if DEBUG_DEVICE
            flags |= DeviceCreationFlags.Debug;
    #endif

            WinApi.DEVMODE mode = new WinApi.DEVMODE();
            WinApi.EnumDisplaySettings(null, WinApi.ENUM_REGISTRY_SETTINGS, ref mode);

            var adapters = GetAdaptersList();

            int adapterIndex = settingsToTry.HasValue ? settingsToTry.Value.AdapterOrdinal : -1;
            adapterIndex = ValidateAdapterIndex(adapterIndex);

            if (adapterIndex == -1)
            {
                throw new MyRenderException("No supporting device detected!", MyRenderExceptionEnum.GpuNotSupported);
            }

            var settings = settingsToTry ?? new MyRenderDeviceSettings()
            {
                AdapterOrdinal   = adapterIndex,
                BackBufferHeight = mode.dmPelsHeight,
                BackBufferWidth  = mode.dmPelsWidth,
                WindowMode       = MyWindowModeEnum.Fullscreen,
                RefreshRate      = 60000,
                VSync            = false,
            };
            m_settings = settings;

            Device = new Device(GetFactory().Adapters[adapters[m_settings.AdapterOrdinal].AdapterDeviceId], flags, FeatureLevel.Level_11_0);

            // HACK: This is required for Steam overlay to work. Apparently they hook only CreateDevice methods with DriverType argument.
            try
            {
                using (new Device(DriverType.Hardware, flags, FeatureLevel.Level_11_0)){}
            }
            catch { }

            if (flags.HasFlag(DeviceCreationFlags.Debug))
            {
                if (DebugDevice != null)
                {
                    DebugDevice.Dispose();
                    DebugDevice = null;
                }

                DebugDevice    = new DeviceDebug(Device);
                DebugInfoQueue = DebugDevice.QueryInterface <InfoQueue>();

                new System.Threading.Thread(ProcessDebugOutput).Start();
            }

            if (ImmediateContext != null)
            {
                ImmediateContext.Dispose();
                ImmediateContext = null;
            }

            ImmediateContext = Device.ImmediateContext;

            m_windowHandle = windowHandle;

            m_resolution = new Vector2I(m_settings.BackBufferWidth, m_settings.BackBufferHeight);

            if (!m_initialized)
            {
                InitSubsystems();
                m_initialized = true;
            }


            if (m_swapchain != null)
            {
                m_swapchain.Dispose();
                m_swapchain = null;
            }

            if (m_swapchain == null)
            {
                SharpDX.DXGI.Device d = Device.QueryInterface <SharpDX.DXGI.Device>();
                Adapter             a = d.GetParent <Adapter>();
                var factory           = a.GetParent <Factory>();

                var scDesc = new SwapChainDescription();
                scDesc.BufferCount            = MyRender11Constants.BUFFER_COUNT;
                scDesc.Flags                  = SwapChainFlags.AllowModeSwitch;
                scDesc.IsWindowed             = true;
                scDesc.ModeDescription.Format = MyRender11Constants.BACKBUFFER_FORMAT;
                scDesc.ModeDescription.Height = m_settings.BackBufferHeight;
                scDesc.ModeDescription.Width  = m_settings.BackBufferWidth;
                scDesc.ModeDescription.RefreshRate.Numerator   = m_settings.RefreshRate;
                scDesc.ModeDescription.RefreshRate.Denominator = 1000;
                scDesc.ModeDescription.Scaling          = DisplayModeScaling.Unspecified;
                scDesc.ModeDescription.ScanlineOrdering = DisplayModeScanlineOrder.Progressive;
                scDesc.SampleDescription.Count          = 1;
                scDesc.SampleDescription.Quality        = 0;
                scDesc.OutputHandle = m_windowHandle;
                scDesc.Usage        = Usage.RenderTargetOutput;
                scDesc.SwapEffect   = SwapEffect.Discard;

                m_swapchain = new SwapChain(factory, Device, scDesc);

                m_swapchain.GetParent <Factory>().MakeWindowAssociation(m_windowHandle, WindowAssociationFlags.IgnoreAll);
            }

            // we start with window always (DXGI recommended)
            m_settings.WindowMode = MyWindowModeEnum.Window;
            ApplySettings(settings);

            return(m_settings);
        }
Beispiel #18
0
        private static void CreateDevices(int graphicsAdapter)
        {
            var deviceCreationFlags = DeviceCreationFlags.BgraSupport;

#if DEBUG
            deviceCreationFlags |= DeviceCreationFlags.Debug;
#endif

            Logger.Info("Attempting to create device.");

            var adapter = Factory.GetAdapter(graphicsAdapter);

            var levels = new[]
            {
                FeatureLevel.Level_11_1,
                FeatureLevel.Level_11_0,
                FeatureLevel.Level_10_1,
                FeatureLevel.Level_10_0,
                FeatureLevel.Level_9_3
            };

            var device = new SharpDX.Direct3D11.Device(adapter, deviceCreationFlags, levels)
            {
                DebugName = adapter.Description.Description
            };

            Logger.Info(
                $"GPU{graphicsAdapter}: {device.DebugName} ({((long)adapter.Description.DedicatedVideoMemory).ToPrettySize()} VRAM)");

            Device           = device.QueryInterface <DeviceD3D>();
            Device.DebugName = device.DebugName;
            Logger.Info("D3D Device created.");
            if (deviceCreationFlags.HasFlag(DeviceCreationFlags.Debug))
            {
                DeviceDebug = new DeviceDebug(Device);
                Logger.Info("Debug device created.");
            }

            DxgiDevice = Device.QueryInterface <Device>();
            Context    = Device.ImmediateContext;

            Device2D = new DeviceD2D(Factory2D, DxgiDevice);

            Context2D = new ContextD2D(Device2D,
                                       DeviceContextOptions.EnableMultithreadedOptimizations)
            {
                TextAntialiasMode =
                    RenderSettings.UseClearTypeRendering
                        ? TextAntialiasMode.Cleartype
                        : (RenderSettings.GuiAntiAliasing ? TextAntialiasMode.Grayscale : TextAntialiasMode.Aliased),
                AntialiasMode = RenderSettings.GuiAntiAliasing ? AntialiasMode.PerPrimitive : AntialiasMode.Aliased,
                UnitMode      = UnitMode.Pixels
            };
            Logger.Info("D2D Device created.");

            Logger.Info("Filling out DebugSettings GPU info.");
            DebugSettings.FillGpuInfo(adapter);

#if DEBUG
            try
            {
                DeviceDebug = new DeviceDebug(Device);
                Logger.Info("Debug device created.");
            }
            catch (SharpDXException)
            {
                Logger.Warn("DeviceDebug not supported.");
            }
#endif

            Logger.Info("Renderer initialized.");
        }