/// <summary> /// Initializes a new instance of the HardwareAdapterCapabilities class with the specifed Adapter. /// </summary> /// <param name="adapter">DirectX Adapter</param> public HardwareAdapterCapabilities(Adapter1 adapter) : base(adapter: adapter) { string adapterDescription = AdapterDescription1.Description.Trim(); int pos = adapterDescription.IndexOf('\0'); // UH: In SharpDX 3.1, some adapters report description with many zero characters if (pos >= 0) { adapterDescription = adapterDescription.Substring(0, pos); } DisplayName = adapterDescription; try { DeviceCapabilities = DeviceCapabilities.QueryAdapter(adapter); DeviceInfoText = string.Format("Feature level: {0}; Video memory: {1:#,##0} MB", GetFeatureLevelText(DeviceCapabilities.FeatureLevel), AdapterDescription1.DedicatedVideoMemory / (1024 * 1024)); IsSupported = this.DeviceCapabilities.FeatureLevel >= FeatureLevel.Level_10_0; if (!IsSupported) { UnsupportedReason = "Adapter not supported because it does not supported feature level 10.0 or higher"; } } catch (Exception ex) { IsSupported = false; UnsupportedReason = "Error checking device capabilities:\r\n" + ex.Message; } }
public static string GetFullSystemInfo() { var sb = new StringBuilder(); var entryAssembly = System.Reflection.Assembly.GetEntryAssembly(); string entryAssemblyName, entryAssemblyTargetFramework; Version entryAssemblyVersion; if (entryAssembly != null) { entryAssemblyName = entryAssembly.GetName().Name; entryAssemblyVersion = entryAssembly.GetName().Version; entryAssemblyTargetFramework = ""; // NOTE: .Net 4.0 does not have entryAssembly.GetCustomAttribute<TargetFrameworkAttribute>() method var customAttributes = entryAssembly.GetCustomAttributes(true); if (customAttributes != null) { for (int i = 0; i < customAttributes.Length; i++) { var targetFrameworkAttribute = customAttributes[i] as TargetFrameworkAttribute; if (targetFrameworkAttribute != null) { entryAssemblyTargetFramework = targetFrameworkAttribute.FrameworkName; break; } } } } else { entryAssemblyName = "(no EntryAssembly)"; entryAssemblyVersion = new Version(); entryAssemblyTargetFramework = ""; } // Do not use strng type reference for DXDevice, so that this class can be used without DXEngine assembly (for example in SystemInfo console application) string dxEngineVersion; try { var dxDeviceType = Type.GetType("Ab3d.DirectX.DXDevice, Ab3d.DXEngine", throwOnError: false); if (dxDeviceType != null) { dxEngineVersion = dxDeviceType.Assembly.GetName().Version.ToString(); } else { dxEngineVersion = ""; } } catch { dxEngineVersion = ""; } sb.AppendFormat("<SystemInfo ApplicationName=\"{0}\" ApplicationVersion=\"{1}\" TargetFramework=\"{2}\" DXEngineVersion=\"{3}\" Date=\"{4:yyyy-MM-dd}\" />\r\n", entryAssemblyName, entryAssemblyVersion, entryAssemblyTargetFramework, dxEngineVersion, DateTime.Now); string systemName = GetOSName(); if (systemName.Length > 0) { systemName = string.Format("OSName=\"{0}\" ", systemName); } bool isDirectXDebugLayerAvailable = CheckDebugSdkAvailable(); string cpuInfo; try { cpuInfo = System.Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER"); if (!string.IsNullOrEmpty(cpuInfo)) { cpuInfo = string.Format("CPU=\"{0}\" ", cpuInfo); } } catch { cpuInfo = ""; } sb.AppendFormat(" <GeneralInfo {0}OSVersion=\"{1}\" Is64BitOS=\"{2}\" Is64BitProcess=\"{3}\" ProcessorCount=\"{4}\" {5}IsDirectXDebugLayerAvailable=\"{6}\" />\r\n", systemName, Environment.OSVersion.Version, Environment.Is64BitOperatingSystem, Environment.Is64BitProcess, Environment.ProcessorCount, cpuInfo, isDirectXDebugLayerAvailable); #if NETCOREAPP || NET5_0 try { sb.AppendFormat(" <RuntimeInformation FrameworkDescription=\"{0}\" OSDescription=\"{1}\" OSArchitecture=\"{2}\" ProcessArchitecture=\"{3}\" />\r\n", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription, System.Runtime.InteropServices.RuntimeInformation.OSDescription, System.Runtime.InteropServices.RuntimeInformation.OSArchitecture, System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture); } catch (Exception ex) { AppendError(sb, "Error getting RuntimeInformation info", ex, indent: 4); } #else try { sb.AppendFormat(" <NetRuntime Versions=\"{0}\" />\r\n", GetNetVersionsFromRegistry()); } catch (Exception ex) { AppendError(sb, "Error getting NetRuntime info", ex, indent: 4); } #endif sb.AppendLine(" <Adapters>"); Adapter1[] allSystemAdapters = null; try { allSystemAdapters = DXDevice.GetAllSystemAdapters(); foreach (var oneSystemAdapter in allSystemAdapters) { // Skip "Microsoft Basic Render Driver" that is identified by specified VendorId and DeviceId - it is the same as Software rendered (WARP) so we do not want to show it 2 times if (!IsSoftwareRenderingAdapter(oneSystemAdapter)) { var deviceCapabilities = DeviceCapabilities.QueryAdapter(oneSystemAdapter); var adapterDetailsText = GetAdapterDetailsText(oneSystemAdapter, deviceCapabilities, indent: 8); sb.Append(adapterDetailsText); } } } catch (Exception ex) { AppendError(sb, "Error getting adapters info", ex, indent: 4); } finally { if (allSystemAdapters != null) { foreach (var oneSystemAdapter in allSystemAdapters) { oneSystemAdapter.Dispose(); } } } sb.AppendLine(" </Adapters>"); #if !NETCOREAPP && !NET5_0 try { string adapterDetailsText = GetVideoControllerDetailsText(indent: 4); sb.AppendLine(adapterDetailsText); } catch (Exception ex) { AppendError(sb, "Error getting Video Controller details", ex, indent: 4); } #endif // Add all Ab3d and SharpDX assemblies sb.AppendLine(" <Assemblies>"); try { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { bool writeAssemblyInfo = true; try { writeAssemblyInfo = assembly.FullName.StartsWith("Ab3d.") || assembly.FullName.StartsWith("SharpDX."); } catch { } if (!writeAssemblyInfo) { continue; } sb.AppendFormat(" <Assembly FullName=\"{0}\" />\r\n", assembly.FullName); } } catch (Exception ex) { AppendError(sb, "Error getting assemblies info", ex, indent: 4); } finally { if (allSystemAdapters != null) { foreach (var oneSystemAdapter in allSystemAdapters) { oneSystemAdapter.Dispose(); } } } sb.AppendLine(" </Assemblies>"); sb.AppendLine("</SystemInfo>"); return(sb.ToString()); }