Пример #1
0
        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 LogOutputDisplayModes(ref MyAdapterInfo info)
 {
     Log.WriteLine("Display modes = {");
     Log.IncreaseIndent();
     Log.WriteLine("DXGIOutput id = " + info.OutputId);
     for (int i = 0; i < info.SupportedDisplayModes.Length; i++)
     {
         Log.WriteLine(info.SupportedDisplayModes[i].ToString());
     }
     Log.DecreaseIndent();
     Log.WriteLine("}");
 }
Пример #3
0
 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);
 }
        unsafe static MyAdapterInfo[] CreateAdaptersList()
        {
            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
                };

                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.DX11_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];
                }

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

                LogAdapterInfoEnd();

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

            return(adaptersList.ToArray());
        }
        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());
        }
Пример #6
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());
        }