Exemple #1
0
        public static int AldAdapterGetInfo(int numberOfAdapters, out AdlAdapterInfo[] info)
        {
            var typeSize = Marshal.SizeOf(typeof(AdlAdapterInfo));
            var ptr      = Marshal.AllocHGlobal(typeSize * numberOfAdapters);
            var result   = _aldAdapterGetInfo(ptr, typeSize * numberOfAdapters);

            info = new AdlAdapterInfo[numberOfAdapters];
            for (var i = 0; i < info.Length; i++)
            {
                info[i] = (AdlAdapterInfo)Marshal.PtrToStructure((IntPtr)((long)ptr + i * typeSize), typeof(AdlAdapterInfo));
            }

            Marshal.FreeHGlobal(ptr);

            // Maybe wrong on Windows subsystem (parsing error)
            FixAdvAdapterVendorInfo(ref info);

            return(result);
        }
Exemple #2
0
 public bool IsSameDeviceAs(AdlAdapterInfo info)
 {
     return(info.DeviceNumber == _adapterInfo.DeviceNumber &&
            info.BusNumber == _adapterInfo.BusNumber);
 }
Exemple #3
0
 public RadeonGpu(AdlAdapterInfo info)
 {
     _adapterInfo       = info;
     _hardwareIdentifer = new RadeonGpuIdentifer(this);
 }
        public void Init()
        {
            displays = new List <Display>();
            disposer = new Disposer();

            int numberOfAdapters = 0;

            Adl.AdlMainControlCreate(Adl.AdlMainMemoryAlloc, 1);

            if (Adl.AdlAdapterNumberOfAdaptersGet != null)
            {
                Adl.AdlAdapterNumberOfAdaptersGet(ref numberOfAdapters);
            }

            Adl.AdlMainControlCreate(Adl.AdlMainMemoryAlloc, 1);

            if (numberOfAdapters > 0)
            {
                AdlAdapterInfoArray osAdapterInfoData = new AdlAdapterInfoArray();

                if (Adl.AdlAdapterAdapterInfoGet != null)
                {
                    int    size          = Marshal.SizeOf(osAdapterInfoData);
                    IntPtr adapterBuffer = Marshal.AllocCoTaskMem(size);
                    Marshal.StructureToPtr(osAdapterInfoData, adapterBuffer, false);

                    int adlRet = Adl.AdlAdapterAdapterInfoGet(adapterBuffer, size);
                    if (adlRet == Adl.AdlSuccess)
                    {
                        osAdapterInfoData = (AdlAdapterInfoArray)Marshal.PtrToStructure(adapterBuffer, osAdapterInfoData.GetType());
                        int isActive = 0;

                        for (int i = 0; i < numberOfAdapters; i++)
                        {
                            AdlAdapterInfo adlAdapterInfo = osAdapterInfoData.ADLAdapterInfo[i];

                            int adapterIndex = adlAdapterInfo.AdapterIndex;

                            if (Adl.AdlAdapterActiveGet != null)
                            {
                                adlRet = Adl.AdlAdapterActiveGet(adlAdapterInfo.AdapterIndex, ref isActive);
                            }

                            if (Adl.AdlSuccess == adlRet)
                            {
                                AdlDisplayInfo oneDisplayInfo = new AdlDisplayInfo();

                                if (Adl.AdlDisplayDisplayInfoGet != null)
                                {
                                    IntPtr displayBuffer = IntPtr.Zero;

                                    int numberOfDisplays = 0;
                                    adlRet = Adl.AdlDisplayDisplayInfoGet(adlAdapterInfo.AdapterIndex, ref numberOfDisplays, out displayBuffer, 1);
                                    if (Adl.AdlSuccess == adlRet)
                                    {
                                        List <AdlDisplayInfo> displayInfoData = new List <AdlDisplayInfo>();
                                        for (int j = 0; j < numberOfDisplays; j++)
                                        {
                                            oneDisplayInfo = (AdlDisplayInfo)Marshal.PtrToStructure(new IntPtr(displayBuffer.ToInt64() + j * Marshal.SizeOf(oneDisplayInfo)), oneDisplayInfo.GetType());
                                            displayInfoData.Add(oneDisplayInfo);
                                        }

                                        for (int j = 0; j < numberOfDisplays; j++)
                                        {
                                            AdlDisplayInfo adlDisplayInfo = displayInfoData[j];

                                            if (adlDisplayInfo.DisplayID.DisplayLogicalAdapterIndex == -1)
                                            {
                                                continue;
                                            }

                                            displays.Add(new Display
                                            {
                                                DisplayInfo = adlDisplayInfo,
                                                AdapterInfo = adlAdapterInfo,
                                                Index       = adapterIndex,
                                            });
                                        }
                                    }

                                    disposer.DisplayBufferList.Add(displayBuffer);
                                }
                            }
                        }
                    }

                    disposer.AdapterBuffer = adapterBuffer;
                }
            }
        }