예제 #1
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.");
        }