private void LoadResolutions(MyAdapterInfo adapter)
        {
            var duplicateFilter = new HashSet <Vector2I>(Vector2I.Comparer);

            foreach (var displayMode in adapter.SupportedDisplayModes)
            {
                duplicateFilter.Add(new Vector2I(displayMode.Width, displayMode.Height));
            }

            m_resolutions.Clear();
            m_resolutions.AddHashset(duplicateFilter);
            m_resolutions.Sort((a, b) =>
            { // Sort by width, then height.
                if (a.X != b.X)
                {
                    return(a.X.CompareTo(b.X));
                }
                return(a.Y.CompareTo(b.Y));
            });

            // Also show any extra display modes we have (there shouldn't be any on official builds).
            foreach (var mode in MyVideoSettingsManager.DebugDisplayModes)
            {
                m_resolutions.Add(new Vector2I(mode.Width, mode.Height));
            }
        }
        private static MyAdapterInfo[] GetAdaptersList(Direct3D d3d)
        {
            MyAdapterInfo[] result = new MyAdapterInfo[d3d.AdapterCount];
            for (var i = 0; i < result.Length; i++)
            {
                result[i] = new MyAdapterInfo();
                var details = d3d.GetAdapterIdentifier(i);

                var currentDisplayMode = d3d.GetAdapterDisplayMode(i);
                result[i].CurrentDisplayMode = new MyDisplayMode { Height = currentDisplayMode.Height, Width = currentDisplayMode.Width, RefreshRate = currentDisplayMode.RefreshRate, AspectRatio = currentDisplayMode.AspectRatio };
                result[i].DeviceName = details.DeviceName;
                result[i].VendorId = details.VendorId;
                result[i].DeviceId = details.DeviceId;
                result[i].Description = details.Description;
                result[i].Name = details.Description + " (" + details.DeviceName.Replace("\\", "").Replace(".", "") + ")";
                result[i].SupportedDisplayModes = new MyDisplayMode[0];

                bool retry = false;
                try
                {
                    result[i].SupportedDisplayModes = GetSupportedDisplayModes(d3d, i);
                }
                catch (SharpDXException dxgiException)
                {
                    if (dxgiException.ResultCode != ResultCode.NotAvailable)
                    {
                        throw;
                    }

                    m_backbufferFormat = Format.A8B8G8R8;
                    retry = true;
                }

                if (retry)
                {
                    try
                    {
                        result[i].SupportedDisplayModes = GetSupportedDisplayModes(d3d, i);
                    }
                    catch (SharpDXException dxgiException)
                    {
                        if (dxgiException.ResultCode != ResultCode.NotAvailable)
                        {
                            throw;
                        }
                    }
                }
            }

            MyGraphicTest test = new MyGraphicTest();
            test.TestDX(d3d, ref result);

            return result;
        }
 static void LogAdapterInfoBegin(ref MyAdapterInfo info)
 {
     MyRender11.Log.WriteLine("AdapterInfo = {");
     MyRender11.Log.IncreaseIndent();
     MyRender11.Log.WriteLine("Name = " + info.Name);
     MyRender11.Log.WriteLine("Device name = " + info.DeviceName);
     MyRender11.Log.WriteLine("Description = " + info.Description);
     MyRender11.Log.WriteLine("DXGIAdapter id = " + info.AdapterDeviceId);
     MyRender11.Log.WriteLine("SUPPORTED = " + info.IsSupported);
     MyRender11.Log.WriteLine("VRAM = " + info.VRAM);
     MyRender11.Log.WriteLine("Multithreaded rendering supported = " + info.MultithreadedRenderingSupported);
 }
Ejemplo n.º 4
0
        protected virtual Dictionary <string, object> GetSessionData()
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            try
            {
                dictionary["game_version"] = MyPerGameSettings.BasicGameInfo.GameVersion.ToString();
                dictionary["game_branch"]  = MyGameService.BranchNameFriendly;
                string str = new ManagementObjectSearcher(@"root\CIMV2", "SELECT Name FROM Win32_Processor").Get().Cast <ManagementObject>().First <ManagementObject>()["Name"].ToString();
                dictionary["cpu_info"]            = str;
                dictionary["cpu_number_of_cores"] = Environment.ProcessorCount;
                WinApi.MEMORYSTATUSEX lpBuffer = new WinApi.MEMORYSTATUSEX();
                WinApi.GlobalMemoryStatusEx(lpBuffer);
                dictionary["ram_size"] = (lpBuffer.ullTotalPhys / ((ulong)0x400L)) / ((ulong)0x400L);
                if (!Sandbox.Engine.Platform.Game.IsDedicated)
                {
                    MyAdapterInfo info = MyVideoSettingsManager.Adapters[MyVideoSettingsManager.CurrentDeviceSettings.AdapterOrdinal];
                    dictionary["gpu_name"]           = info.Name;
                    dictionary["gpu_memory"]         = (info.VRAM / ((ulong)0x400L)) / ((ulong)0x400L);
                    dictionary["gpu_driver_version"] = info.DriverVersion;
                }
                dictionary["os_info"]      = Environment.OSVersion.VersionString;
                dictionary["os_platform"]  = Environment.Is64BitOperatingSystem ? "64bit" : "32bit";
                dictionary["dx11_support"] = Sandbox.Engine.Platform.Game.IsDedicated ? ((object)1) : ((object)MyDirectXHelper.IsDx11Supported());
                dictionary["is_first_run"] = this.m_firstRun;
                dictionary["is_dedicated"] = Sandbox.Engine.Platform.Game.IsDedicated;
                if (!Sandbox.Engine.Platform.Game.IsDedicated)
                {
                    dictionary["display_resolution"]                  = MySandboxGame.Config.ScreenWidth.ToString() + " x " + MySandboxGame.Config.ScreenHeight.ToString();
                    dictionary["display_window_mode"]                 = MyVideoSettingsManager.CurrentDeviceSettings.WindowMode.ToString();
                    dictionary["graphics_anisotropic_filtering"]      = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.AnisotropicFiltering.ToString();
                    dictionary["graphics_antialiasing_mode"]          = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.AntialiasingMode.ToString();
                    dictionary["graphics_shadow_quality"]             = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.ShadowQuality.ToString();
                    dictionary["graphics_texture_quality"]            = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.TextureQuality.ToString();
                    dictionary["graphics_voxel_quality"]              = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.VoxelQuality.ToString();
                    dictionary["graphics_grass_density_factor"]       = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.GrassDensityFactor;
                    dictionary["graphics_grass_draw_distance"]        = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.GrassDrawDistance;
                    dictionary["graphics_flares_intensity"]           = MyVideoSettingsManager.CurrentGraphicsSettings.FlaresIntensity;
                    dictionary["graphics_voxel_shader_quality"]       = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.VoxelShaderQuality;
                    dictionary["graphics_alphamasked_shader_quality"] = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.AlphaMaskedShaderQuality;
                    dictionary["graphics_atmosphere_shader_quality"]  = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.AtmosphereShaderQuality;
                    dictionary["graphics_distance_fade"]              = MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.DistanceFade;
                    dictionary["audio_music_volume"]                  = MySandboxGame.Config.MusicVolume;
                    dictionary["audio_sound_volume"]                  = MySandboxGame.Config.GameVolume;
                    dictionary["audio_mute_when_not_in_focus"]        = MySandboxGame.Config.EnableMuteWhenNotInFocus;
                }
            }
            catch (Exception exception)
            {
                dictionary["failed_to_get_data"] = exception.Message + "\n" + exception.StackTrace;
            }
            return(dictionary);
        }
Ejemplo n.º 5
0
 internal static void OnVideoAdaptersResponse(MyRenderMessageVideoAdaptersResponse message)
 {
     MyRenderProxy.Log.WriteLine("MyVideoSettingsManager.OnVideoAdaptersResponse");
     using (MyRenderProxy.Log.IndentUsing(LoggingOptions.NONE))
     {
         MyAdapterInfo info;
         m_adapters = message.Adapters;
         int index = -1;
         info.Priority = 0x3e8;
         try
         {
             index           = MySandboxGame.Static.GameRenderComponent.RenderThread.CurrentAdapter;
             info            = m_adapters[index];
             GpuUnderMinimum = !info.Has512MBRam;
         }
         catch
         {
         }
         m_recommendedAspectRatio = new Dictionary <int, MyAspectRatio>();
         if (m_adapters.Length == 0)
         {
             MyRenderProxy.Log.WriteLine("ERROR: Adapters count is 0!");
         }
         for (int i = 0; i < m_adapters.Length; i++)
         {
             MyAdapterInfo info2 = m_adapters[i];
             MyRenderProxy.Log.WriteLine($"Adapter {info2}");
             using (MyRenderProxy.Log.IndentUsing(LoggingOptions.NONE))
             {
                 m_recommendedAspectRatio.Add(i, GetAspectRatio(GetClosestAspectRatio(((float)info2.DesktopBounds.Width) / ((float)info2.DesktopBounds.Height))));
                 if (info2.SupportedDisplayModes.Length == 0)
                 {
                     MyRenderProxy.Log.WriteLine($"WARNING: Adapter {i} count of supported display modes is 0!");
                 }
                 int maxTextureSize = info2.MaxTextureSize;
                 foreach (MyDisplayMode mode in info2.SupportedDisplayModes)
                 {
                     MyRenderProxy.Log.WriteLine(mode.ToString());
                     if ((mode.Width > maxTextureSize) || (mode.Height > maxTextureSize))
                     {
                         MyRenderProxy.Log.WriteLine($"WARNING: Display mode {mode} requires texture size which is not supported by this HW (this HW supports max {maxTextureSize})");
                     }
                 }
             }
             MySandboxGame.ShowIsBetterGCAvailableNotification |= (index != i) && (info.Priority < info2.Priority);
         }
     }
 }
Ejemplo n.º 6
0
        private static MyProcessStartAnalytics GetProcessStartAnalyticsData()
        {
            MyProcessStartAnalytics data = new MyProcessStartAnalytics();

            try
            {
                var cpus = new ManagementObjectSearcher("root\\CIMV2", "SELECT Name FROM Win32_Processor").Get();
                // We're just reporting the first
                var cpuName = cpus.Cast <ManagementObject>().First()["Name"].ToString();

                var memoryInfo = new WinApi.MEMORYSTATUSEX();
                WinApi.GlobalMemoryStatusEx(memoryInfo);

                MyAdapterInfo gpu        = MyVideoSettingsManager.Adapters[MyVideoSettingsManager.CurrentDeviceSettings.AdapterOrdinal];
                var           deviceName = gpu.Name;

                data.ProcessorCount               = (byte)Environment.ProcessorCount;
                data.OsVersion                    = Environment.OSVersion.VersionString;
                data.CpuInfo                      = cpuName;
                data.OsPlatform                   = Environment.Is64BitOperatingSystem ? "64bit" : "32bit";
                data.HasDX11                      = MyDirectXHelper.IsDx11Supported();
                data.GameVersion                  = MyFinalBuildConstants.APP_VERSION_STRING.ToString();
                data.TotalPhysMemBytes            = memoryInfo.ullTotalPhys;
                data.GpuInfo                      = new MyGraphicsInfo();
                data.GpuInfo.AnisotropicFiltering = MyVideoSettingsManager.CurrentGraphicsSettings.Render.AnisotropicFiltering.ToString();
                data.GpuInfo.AntialiasingMode     = MyVideoSettingsManager.CurrentGraphicsSettings.Render.AntialiasingMode.ToString();
                data.GpuInfo.FoliageDetails       = MyVideoSettingsManager.CurrentGraphicsSettings.Render.FoliageDetails.ToString();
                data.GpuInfo.ShadowQuality        = MyVideoSettingsManager.CurrentGraphicsSettings.Render.ShadowQuality.ToString();
                data.GpuInfo.TextureQuality       = MyVideoSettingsManager.CurrentGraphicsSettings.Render.TextureQuality.ToString();
                data.GpuInfo.VoxelQuality         = MyVideoSettingsManager.CurrentGraphicsSettings.Render.VoxelQuality.ToString();
                data.GpuInfo.GrassDensityFactor   = MyVideoSettingsManager.CurrentGraphicsSettings.Render.GrassDensityFactor;
                data.GpuInfo.GPUModelName         = gpu.DeviceName;
                data.GpuInfo.GPUMemory            = gpu.VRAM;
                data.AudioInfo.MusicVolume        = MySandboxGame.Config.MusicVolume;
                data.AudioInfo.SoundVolume        = MySandboxGame.Config.GameVolume;
                data.AudioInfo.HudWarnings        = MySandboxGame.Config.HudWarnings;
                data.AudioInfo.MuteWhenNotInFocus = MySandboxGame.Config.EnableMuteWhenNotInFocus;
                data.Fullscreen                   = MyVideoSettingsManager.CurrentDeviceSettings.WindowMode.ToString();
                data.Resolution                   = MySandboxGame.Config.ScreenWidth.ToString() + " x " + MySandboxGame.Config.ScreenHeight.ToString();
            }
            catch (Exception exception)
            {
                MyLog.Default.WriteLine(exception);
            }

            return(data);
        }
Ejemplo n.º 7
0
 public static void SendVideoAdapters(MyAdapterInfo[] adapters)
 {
     var message = MessagePool.Get<MyRenderMessageVideoAdaptersResponse>(MyRenderMessageEnum.VideoAdaptersResponse);
     message.Adapters = adapters;
     EnqueueOutputMessage(message);
 }
Ejemplo n.º 8
0
        unsafe static MyAdapterInfo[] CreateAdaptersList()
        {
            List<MyAdapterInfo> adaptersList = new List<MyAdapterInfo>();

            var factory = GetFactory();
            FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0 };

            int adapterIndex = 0;

            LogInfoFromWMI();

            for(int i=0; i<factory.Adapters.Length; i++)
            {
                var adapter = factory.Adapters[i];
                Device adapterTestDevice = null;
                try
                {
                    adapterTestDevice = new Device(adapter, DeviceCreationFlags.None, featureLevels);
                }
                catch(SharpDXException e)
                {

                }

                bool supportedDevice = adapterTestDevice != null;

                bool supportsConcurrentResources = false;
                bool supportsCommandLists = false;
                if (supportedDevice)
                {
                    adapterTestDevice.CheckThreadingSupport(out supportsConcurrentResources, out supportsCommandLists);
                }

                // DedicatedSystemMemory = bios or DVMT preallocated video memory, that cannot be used by OS - need retest on pc with only cpu/chipset based graphic
                // DedicatedVideoMemory = discrete graphic video memory
                // SharedSystemMemory = aditional video memory, that can be taken from OS RAM when needed
                void * vramptr = ((IntPtr)(adapter.Description.DedicatedSystemMemory != 0 ? adapter.Description.DedicatedSystemMemory : adapter.Description.DedicatedVideoMemory)).ToPointer();
                UInt64 vram = (UInt64)vramptr;
                void * svramptr = ((IntPtr)adapter.Description.SharedSystemMemory).ToPointer();
                UInt64 svram = (UInt64)svramptr;

                // microsoft software renderer allocates 256MB shared memory, cpu integrated graphic on notebooks has 0 preallocated, all shared
                supportedDevice = supportedDevice && (vram > 500000000 || svram > 500000000);

                var deviceDesc = String.Format("{0}, dev id: {1}, mem: {2}, shared mem: {3}, Luid: {4}, rev: {5}, subsys id: {6}, vendor id: {7}",
                    adapter.Description.Description,
                    adapter.Description.DeviceId,
                    vram,
                    svram,
                    adapter.Description.Luid,
                    adapter.Description.Revision,
                    adapter.Description.SubsystemId,
                    adapter.Description.VendorId
                    );

                var info = new MyAdapterInfo
                {
                    Name = adapter.Description.Description,
                    DeviceName = adapter.Description.Description,
                    Description = deviceDesc,
                    IsDx11Supported = supportedDevice,
                    AdapterDeviceId = i,
                    Priority = VendorPriority(adapter.Description.VendorId),
                    HDRSupported = true,
                    MaxTextureSize = SharpDX.Direct3D11.Texture2D.MaximumTexture2DSize,
                    VRAM = vram > 0 ? vram : svram,
                    Has512MBRam = (vram > 500000000 || svram > 500000000),
                    MultithreadedRenderingSupported = supportsCommandLists
                };

                if(info.VRAM >= 2000000000)
                {
                    info.MaxTextureQualitySupported = MyTextureQuality.HIGH;
                }
                else if (info.VRAM >= 1000000000)
                {
                    info.MaxTextureQualitySupported = MyTextureQuality.MEDIUM;
                }
                else
                { 
                    info.MaxTextureQualitySupported = MyTextureQuality.LOW;
                }

                info.MaxAntialiasingModeSupported = MyAntialiasingMode.FXAA;
                if (supportedDevice)
                {
                    if (adapterTestDevice.CheckMultisampleQualityLevels(Format.R11G11B10_Float, 2) > 0)
                    {
                        info.MaxAntialiasingModeSupported = MyAntialiasingMode.MSAA_2;
                    }
                    if (adapterTestDevice.CheckMultisampleQualityLevels(Format.R11G11B10_Float, 4) > 0)
                    {
                        info.MaxAntialiasingModeSupported = MyAntialiasingMode.MSAA_4;
                    }
                    if (adapterTestDevice.CheckMultisampleQualityLevels(Format.R11G11B10_Float, 8) > 0)
                    {
                        info.MaxAntialiasingModeSupported = MyAntialiasingMode.MSAA_8;
                    }
                }

                LogAdapterInfoBegin(ref info);

                if(supportedDevice)
                {
                    bool outputsAttached = adapter.Outputs.Length > 0;

                    if (outputsAttached)
                    {
                        for (int j = 0; j < adapter.Outputs.Length; j++)
                        {
                            var output = adapter.Outputs[j];

                            info.Name = String.Format("{0} + {1}", adapter.Description.Description, output.Description.DeviceName);
                            info.OutputName = output.Description.DeviceName;
                            info.OutputId = j;

                            var displayModeList = output.GetDisplayModeList(MyRender11Constants.BACKBUFFER_FORMAT, DisplayModeEnumerationFlags.Interlaced);
                            var adapterDisplayModes = new MyDisplayMode[displayModeList.Length];
                            for (int k = 0; k < displayModeList.Length; k++)
                            {
                                var displayMode = displayModeList[k];

                                adapterDisplayModes[k] = new MyDisplayMode
                                {
                                    Height = displayMode.Height,
                                    Width = displayMode.Width,
                                    RefreshRate = displayMode.RefreshRate.Numerator,
                                    RefreshRateDenominator = displayMode.RefreshRate.Denominator
                                };
                            }
                            Array.Sort(adapterDisplayModes, m_refreshRatePriorityComparer);

                            info.SupportedDisplayModes = adapterDisplayModes;
                            info.CurrentDisplayMode = adapterDisplayModes[adapterDisplayModes.Length - 1];
                            LogOutputDisplayModes(ref info);

                            m_adapterModes[adapterIndex] = displayModeList;

                            // add one entry per every adapter-output pair
                            adaptersList.Add(info);
                            adapterIndex++;
                        }
                    }
                    else
                    {
                        // FALLBACK MODES

                        MyDisplayMode[] fallbackDisplayModes = new MyDisplayMode[] {
                            new MyDisplayMode(640, 480, 60000, 1000),
                            new MyDisplayMode(720, 576, 60000, 1000),
                            new MyDisplayMode(800, 600, 60000, 1000),
                            new MyDisplayMode(1024, 768, 60000, 1000),
                            new MyDisplayMode(1152, 864, 60000, 1000),
                            new MyDisplayMode(1280, 720, 60000, 1000),
                            new MyDisplayMode(1280, 768, 60000, 1000),
                            new MyDisplayMode(1280, 800, 60000, 1000),
                            new MyDisplayMode(1280, 960, 60000, 1000),
                            new MyDisplayMode(1280, 1024, 60000, 1000),
                            new MyDisplayMode(1360, 768, 60000, 1000),
                            new MyDisplayMode(1360, 1024, 60000, 1000),
                            new MyDisplayMode(1440, 900, 60000, 1000),
                            new MyDisplayMode(1600, 900, 60000, 1000),
                            new MyDisplayMode(1600, 1024, 60000, 1000),
                            new MyDisplayMode(1600, 1200, 60000, 1000),
                            new MyDisplayMode(1680, 1200, 60000, 1000),
                            new MyDisplayMode(1680, 1050, 60000, 1000),
                            new MyDisplayMode(1920, 1080, 60000, 1000),
                            new MyDisplayMode(1920, 1200, 60000, 1000),
                        };

                        info.OutputName = "FallbackOutput";
                        info.Name = String.Format("{0}", adapter.Description.Description);
                        info.OutputId = 0;
                        info.CurrentDisplayMode = fallbackDisplayModes[fallbackDisplayModes.Length - 1];

                        info.SupportedDisplayModes = fallbackDisplayModes;
                        info.FallbackDisplayModes = true;

                        // add one entry for adapter-fallback output pair
                        adaptersList.Add(info);
                        adapterIndex++;
                    }
                }
                else
                {
                    info.SupportedDisplayModes = new MyDisplayMode[0];
                }

                MyRender11.Log.WriteLine("Fallback display modes = " + info.FallbackDisplayModes);

                LogAdapterInfoEnd();

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

            return adaptersList.ToArray();
        }
Ejemplo n.º 9
0
 static void LogOutputDisplayModes(ref MyAdapterInfo info)
 {
     MyRender11.Log.WriteLine("Display modes = {");
     MyRender11.Log.IncreaseIndent();
     MyRender11.Log.WriteLine("DXGIOutput id = " + info.OutputId);
     for(int i=0; i< info.SupportedDisplayModes.Length; i++)
     {
         MyRender11.Log.WriteLine(info.SupportedDisplayModes[i].ToString());
     }
     MyRender11.Log.DecreaseIndent();
     MyRender11.Log.WriteLine("}");
 }
Ejemplo n.º 10
0
        unsafe static MyAdapterInfo[] CreateAdaptersList()
        {
            List<MyAdapterInfo> adaptersList = new List<MyAdapterInfo>();

            var factory = GetFactory();
            FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0 };

            int adapterIndex = 0;

            LogInfoFromWMI();

            for(int i=0; i<factory.Adapters.Length; i++)
            {
                var adapter = factory.Adapters[i];
                Device adapterTestDevice = null;
                try
                {
                    adapterTestDevice = new Device(adapter, DeviceCreationFlags.None, featureLevels);
                }
                catch(SharpDXException e)
                {

                }

                bool supportedDevice = adapterTestDevice != null;

                bool supportsConcurrentResources = false;
                bool supportsCommandLists = false;
                if (supportedDevice)
                {
                    adapterTestDevice.CheckThreadingSupport(out supportsConcurrentResources, out supportsCommandLists);
                }

                void* ptr = ((IntPtr)adapter.Description.DedicatedVideoMemory).ToPointer();
                ulong vram = (ulong)ptr;

                var deviceDesc = String.Format("{0}, dev id: {1}, shared mem: {2}, Luid: {3}, rev: {4}, subsys id: {5}, vendor id: {6}",
                    adapter.Description.Description,
                    adapter.Description.DeviceId,
                    vram,
                    adapter.Description.Luid,
                    adapter.Description.Revision,
                    adapter.Description.SubsystemId,
                    adapter.Description.VendorId
                    );

                var info = new MyAdapterInfo
                {
                    Name = adapter.Description.Description,
                    DeviceName = adapter.Description.Description,
                    Description = deviceDesc,
                    IsSupported = supportedDevice,
                    AdapterDeviceId = i,

                    Has512MBRam = vram > 500000000,
                    HDRSupported = true,
                    MaxTextureSize = SharpDX.Direct3D11.Texture2D.MaximumTexture2DSize,

                    VRAM = vram,
                    MultithreadedRenderingSupported = supportsCommandLists
                };

                if(vram >= 2000000000)
                {
                    info.MaxTextureQualitySupported = MyTextureQuality.HIGH;
                }
                else if (vram >= 1000000000)
                {
                    info.MaxTextureQualitySupported = MyTextureQuality.MEDIUM;
                }
                else
                { 
                    info.MaxTextureQualitySupported = MyTextureQuality.LOW;
                }

                info.MaxAntialiasingModeSupported = MyAntialiasingMode.FXAA;
                if (supportedDevice)
                {
                    if (adapterTestDevice.CheckMultisampleQualityLevels(Format.R11G11B10_Float, 2) > 0)
                    {
                        info.MaxAntialiasingModeSupported = MyAntialiasingMode.MSAA_2;
                    }
                    if (adapterTestDevice.CheckMultisampleQualityLevels(Format.R11G11B10_Float, 4) > 0)
                    {
                        info.MaxAntialiasingModeSupported = MyAntialiasingMode.MSAA_4;
                    }
                    if (adapterTestDevice.CheckMultisampleQualityLevels(Format.R11G11B10_Float, 8) > 0)
                    {
                        info.MaxAntialiasingModeSupported = MyAntialiasingMode.MSAA_8;
                    }
                }

                LogAdapterInfoBegin(ref info);

                if(supportedDevice)
                {
                    for(int j=0; j<factory.Adapters[i].Outputs.Length; j++)
                    {
                        var output = factory.Adapters[i].Outputs[j];

                        info.Name = String.Format("{0} + {1}", adapter.Description.Description, output.Description.DeviceName);
                        info.OutputName = output.Description.DeviceName;
                        info.OutputId = j;

                        var displayModeList = factory.Adapters[i].Outputs[j].GetDisplayModeList(MyRender11Constants.BACKBUFFER_FORMAT, DisplayModeEnumerationFlags.Interlaced);
                        var adapterDisplayModes = new MyDisplayMode[displayModeList.Length];
                        for (int k = 0; k < displayModeList.Length; k++)
                        {
                            var displayMode = displayModeList[k];

                            adapterDisplayModes[k] = new MyDisplayMode 
                            { 
                                Height = displayMode.Height, 
                                Width = displayMode.Width, 
                                RefreshRate = displayMode.RefreshRate.Numerator, 
                                RefreshRateDenominator = displayMode.RefreshRate.Denominator 
                            }; 
                        }
                        Array.Sort(adapterDisplayModes, m_refreshRatePriorityComparer);

                        info.SupportedDisplayModes = adapterDisplayModes;
                        info.CurrentDisplayMode = adapterDisplayModes[adapterDisplayModes.Length - 1];


                        adaptersList.Add(info);
                        m_adapterModes[adapterIndex] = displayModeList;
                        adapterIndex++;

                        LogOutputDisplayModes(ref info);
                    }
                }
                else
                {
                    info.SupportedDisplayModes = new MyDisplayMode[0];
                    adaptersList.Add(info);
                    adapterIndex++;
                }

                LogAdapterInfoEnd();

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

            return adaptersList.ToArray();
        }
Ejemplo n.º 11
0
        unsafe static MyAdapterInfo[] GetAdapters()
        {
            List<MyAdapterInfo> adaptersList = new List<MyAdapterInfo>();

            var factory = GetFactory();
            FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0 };

            int adapterIndex = 0;

            LogInfoFromWMI(Log);
            LogInfoFromWMI(MyLog.Default);

            for (int i = 0; i < factory.Adapters.Length; i++)
            {
                var adapter = factory.Adapters[i];
                Device adapterTestDevice = null;
                try
                {
                    adapterTestDevice = new Device(adapter, DeviceCreationFlags.None, featureLevels);
                }
                catch (SharpDXException)
                {

                }

                bool supportedDevice = adapterTestDevice != null;

                bool supportsConcurrentResources = false;
                bool supportsCommandLists = false;
                if (supportedDevice)
                {
                    adapterTestDevice.CheckThreadingSupport(out supportsConcurrentResources, out supportsCommandLists);
                }

                // DedicatedSystemMemory = bios or DVMT preallocated video memory, that cannot be used by OS - need retest on pc with only cpu/chipset based graphic
                // DedicatedVideoMemory = discrete graphic video memory
                // SharedSystemMemory = aditional video memory, that can be taken from OS RAM when needed
                void* vramptr =
                    ((IntPtr)
                        (adapter.Description.DedicatedSystemMemory != 0
                            ? adapter.Description.DedicatedSystemMemory
                            : adapter.Description.DedicatedVideoMemory)).ToPointer();
                UInt64 vram = (UInt64) vramptr;
                void* svramptr = ((IntPtr) adapter.Description.SharedSystemMemory).ToPointer();
                UInt64 svram = (UInt64) svramptr;

                // microsoft software renderer allocates 256MB shared memory, cpu integrated graphic on notebooks has 0 preallocated, all shared
                supportedDevice = supportedDevice && (vram > 500000000 || svram > 500000000);

                var deviceDesc =
                    String.Format(
                        "{0}, dev id: {1}, mem: {2}, shared mem: {3}, Luid: {4}, rev: {5}, subsys id: {6}, vendor id: {7}",
                        adapter.Description.Description,
                        adapter.Description.DeviceId,
                        vram,
                        svram,
                        adapter.Description.Luid,
                        adapter.Description.Revision,
                        adapter.Description.SubsystemId,
                        adapter.Description.VendorId
                        );

                var info = new MyAdapterInfo
                {
                    Name = adapter.Description.Description,
                    DeviceName = adapter.Description.Description,
                    VendorId = adapter.Description.VendorId,
                    DeviceId = adapter.Description.DeviceId,
                    Description = deviceDesc,
                    IsDx11Supported = supportedDevice,
                    AdapterDeviceId = i,
                    Priority = VendorPriority(adapter.Description.VendorId),
                    HDRSupported = true,
                    MaxTextureSize = SharpDX.Direct3D11.Texture2D.MaximumTexture2DSize,
                    VRAM = vram > 0 ? vram : svram,
                    Has512MBRam = (vram > 500000000 || svram > 500000000),
                    MultithreadedRenderingSupported = supportsCommandLists
                };

                adaptersList.Add(info);
                adapterIndex++;
            }

            return adaptersList.ToArray();
        }
        // Testing function call - creates DX9 device & present test:
        public bool TestDX(Direct3D d3dh, ref MyAdapterInfo[] infos)
        {
#if !XB1
            bool isAnyGraphicsSupported = false;
            MyLog.Default.WriteLine("MyGraphicTest.TestDX() - START");
            MyLog.Default.IncreaseIndent();

            LogInfoFromWMI();

            bool isAnyGoodGCinWMI = IsAnyGoodGCinList(m_WMIGraphicsCards);
            MyLog.Default.WriteLine("Good graphics in WMI detected: " + isAnyGoodGCinWMI);

            //Check debug runtime
            MyLog.Default.WriteLine("Debug runtime enabled: " + IsDebugRuntimeEnabled);

            PresentParameters newPresentParameters;

            try
            {
                MyLog.Default.WriteLine("Adapter count: " + d3dh.AdapterCount);
                for (int i = 0; i < d3dh.AdapterCount; i++)
                {
                    var info = d3dh.GetAdapterIdentifier(i);
                    MyLog.Default.WriteLine(String.Format("Found adapter: {0} ({1})", info.Description, info.DeviceName));
                }
                MyLog.Default.WriteLine("Adapter count: " + d3dh.AdapterCount);

                // DX:
                newPresentParameters = new PresentParameters();
                newPresentParameters.InitDefaults();
                newPresentParameters.Windowed = true;
                newPresentParameters.AutoDepthStencilFormat = Format.D24S8;
                newPresentParameters.EnableAutoDepthStencil = true;
                newPresentParameters.SwapEffect = SwapEffect.Discard;
                newPresentParameters.PresentFlags = PresentFlags.DiscardDepthStencil;

                m_DXGraphicsCards.Clear();

                // Write adapter information to the LOG file:
                MyLog.Default.WriteLine("Adapters count: " + d3dh.AdapterCount);
                MyLog.Default.WriteLine("Adapter array count: " + d3dh.Adapters.Count);

                for (int adapter = 0; adapter < d3dh.AdapterCount; adapter++)
                {
                    bool adapterSupported = false;

                    var adapterIdentifier = d3dh.GetAdapterIdentifier(adapter);
                    MyLog.Default.WriteLine("Adapter " + adapterIdentifier.Description + ": " + adapterIdentifier.DeviceName);

                    Device d3d = null;
                    Form testForm = null;

                    try
                    {
                        //Create window, because other this fails on some ATIs..
                        testForm = new Form();
                        testForm.ClientSize = new System.Drawing.Size(64, 64);
                        testForm.StartPosition = FormStartPosition.CenterScreen;
                        testForm.FormBorderStyle = FormBorderStyle.None;
                        testForm.BackColor = System.Drawing.Color.Black;
                        testForm.Show();

                        newPresentParameters.DeviceWindowHandle = testForm.Handle;
                        d3d = new Device(d3dh, adapter, DeviceType.Hardware, testForm.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve, newPresentParameters);

                        if (d3d == null)
                        {
                            throw new Exception("Cannot create Direct3D Device");
                        }
                        else
                            MyLog.Default.WriteLine("d3d handle ok ");
                    }
                    catch (Exception e)
                    {
                        if (testForm != null)
                            testForm.Close();

                        MyLog.Default.WriteLine("Direct3D Device create fail");
                        MyLog.Default.WriteLine(e.ToString());

                        Write(newPresentParameters, MyLog.Default.WriteLine);
                        continue;
                    }

                    adapterSupported |= !TestCapabilities(d3d, d3dh, adapter);

                    infos[adapter].MaxTextureSize = d3d.Capabilities.MaxTextureWidth;

                    bool Rgba1010102Supported = d3dh.CheckDeviceFormat(adapter, DeviceType.Hardware, Format.X8R8G8B8, Usage.RenderTarget, ResourceType.Surface, Format.A2R10G10B10);
                    MyLog.Default.WriteLine("Rgba1010102Supported: " + Rgba1010102Supported);

                    bool MipmapNonPow2Supported = !d3d.Capabilities.TextureCaps.HasFlag(TextureCaps.Pow2) &&
                        !d3d.Capabilities.TextureCaps.HasFlag(TextureCaps.NonPow2Conditional) &&
                        d3d.Capabilities.TextureCaps.HasFlag(TextureCaps.MipMap);
                    MyLog.Default.WriteLine("MipmapNonPow2Supported: " + MipmapNonPow2Supported);

                    infos[adapter].HDRSupported = Rgba1010102Supported && MipmapNonPow2Supported;
                    MyLog.Default.WriteLine("HDRSupported: " + infos[adapter].HDRSupported);

                    bool QueriesSupported = false;
                    try
                    {
                        MyLog.Default.WriteLine("Create query");
                        Query query = new Query(d3d, QueryType.Event);
                        MyLog.Default.WriteLine("Dispose query");
                        query.Dispose();
                        QueriesSupported = true;
                    }
                    catch
                    {
                        QueriesSupported = false;
                    }

                    //Test sufficient video memory (512MB)
                    bool Has512AvailableVRAM = TestAvailable512VRAM(d3d);

                    //We require queries
                    adapterSupported &= QueriesSupported;

                    infos[adapter].IsDx9Supported = adapterSupported;
                    infos[adapter].Has512MBRam = Has512AvailableVRAM;

                    isAnyGraphicsSupported |= adapterSupported;

                    MyLog.Default.WriteLine("Queries supported: " + QueriesSupported.ToString());

                    m_DXGraphicsCards.Add(adapterIdentifier.VendorId);

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

                    if (testForm != null)
                        testForm.Close();
                }
            }
            catch (Exception ex)
            {
                MyLog.Default.WriteLine("Exception throwed by DX test. Source: " + ex.Source);
                MyLog.Default.WriteLine("Message: " + ex.Message);
                MyLog.Default.WriteLine("Inner exception: " + ex.InnerException);
                MyLog.Default.WriteLine("Exception details" + ex.ToString());
            }

            bool isAnyGoodGCinDX = IsAnyGoodGCinList(m_DXGraphicsCards);
            MyLog.Default.WriteLine("Good graphics in DX detected: " + isAnyGoodGCinDX);

            IsBetterGCAvailable = isAnyGoodGCinWMI && !isAnyGoodGCinDX;
            MyLog.Default.WriteLine("Is better graphics available: " + IsBetterGCAvailable);

            MyLog.Default.DecreaseIndent();
            MyLog.Default.WriteLine("MyGraphicTest.TestDX() - END");

            return isAnyGraphicsSupported;
#else // XB1
            System.Diagnostics.Debug.Assert(false, "XB1 TOOD?");
            return false;
#endif // XB1
        }