Skip to content

Instantly share code, notes, and snippets.

@trfd
Created October 8, 2016 18:59
Show Gist options
  • Save trfd/1564183d6f4c7f17fb322a8d4238a36c to your computer and use it in GitHub Desktop.
Save trfd/1564183d6f4c7f17fb322a8d4238a36c to your computer and use it in GitHub Desktop.
public class GraphicsDiagnostics : UnityEngine.MonoBehaviour
{
// Useful to keep the generated XML to see the content for debug purpose.
public bool RemoveDxDiagFile = true;
public string DxDiagTempFile = @"C:\Users\trfd\Desktop\dxdiag.xml";
private bool didRunDxDiagProcessing = false;
private System.Diagnostics.Process dxdiagProcess;
public GraphicDevice[] GraphicDevices
{
get;
private set;
}
protected virtual void Start()
{
this.dxdiagProcess = new System.Diagnostics.Process();
this.dxdiagProcess.StartInfo.FileName = "dxdiag.exe";
this.dxdiagProcess.StartInfo.Arguments = "/dontskip /whql:off /64bit /x " + this.DxDiagTempFile;
// Doesn't work!!! use update to check if the process has exited
// dxdiagProcess.Exited += new System.EventHandler(this.DxDiagExited);
this.dxdiagProcess.Start();
}
protected virtual void Update()
{
if (!this.didRunDxDiagProcessing && this.dxdiagProcess.HasExited)
{
ProcessDxDiag();
this.didRunDxDiagProcessing = true;
if (this.RemoveDxDiagFile)
{
// TODO: Actually remove the XML file
}
}
}
protected virtual void ProcessDxDiag()
{
System.Xml.XmlDocument dxDiagXMLDoc = new System.Xml.XmlDocument();
dxDiagXMLDoc.Load(this.DxDiagTempFile);
System.Xml.XmlNodeList nodes = dxDiagXMLDoc.SelectNodes("/DxDiag/DisplayDevices/DisplayDevice");
System.Collections.Generic.List<GraphicDevice> devices = new System.Collections.Generic.List<GraphicDevice>();
for (int idx = 0; idx < nodes.Count; ++idx)
{
System.Xml.XmlNode node = nodes[idx];
GraphicDevice device = new GraphicDevice();
device.CardName = node.SelectSingleNode("CardName").InnerText;
device.Manufacturer = node.SelectSingleNode("Manufacturer").InnerText;
device.ChipType = node.SelectSingleNode("ChipType").InnerText;
device.DACType = node.SelectSingleNode("DACType").InnerText;
device.DeviceType = node.SelectSingleNode("DeviceType").InnerText;
device.DriverVersion = node.SelectSingleNode("DriverVersion").InnerText;
device.DDIVersion = node.SelectSingleNode("DDIVersion").InnerText;
device.FeatureLevels = node.SelectSingleNode("FeatureLevels").InnerText;
device.DriverModel = node.SelectSingleNode("DriverModel").InnerText;
device.DriverDate = node.SelectSingleNode("DriverDate").InnerText;
device.VendorID = node.SelectSingleNode("VendorID").InnerText;
device.DeviceID = node.SelectSingleNode("DeviceID").InnerText;
device.SubSysID = node.SelectSingleNode("SubSysID").InnerText;
device.RevisionID = node.SelectSingleNode("RevisionID").InnerText;
devices.Add(device);
}
this.GraphicDevices = devices.ToArray();
// Debug Only
UnityEngine.Debug.Log("Graphic Devices Found:");
for (int idx = 0; idx < this.GraphicDevices.Length; ++idx)
{
UnityEngine.Debug.Log(this.GraphicDevices[idx].ToString());
}
}
public struct GraphicDevice
{
// Example:
//<DisplayDevice>
// <CardName>NVIDIA GeForce GTX 960</CardName>
// <Manufacturer>NVIDIA</Manufacturer>
// <ChipType>GeForce GTX 960</ChipType>
// <DACType>Integrated RAMDAC</DACType>
// <DeviceType>Full Device</DeviceType>
// <DriverVersion>10.18.13.6472</DriverVersion>
// <DDIVersion>12</DDIVersion>
// <FeatureLevels>12.1,12.0,11.1,11.0,10.1,10.0,9.3,9.2,9.1</FeatureLevels>
// <DriverModel>WDDM 2.0</DriverModel>
// <DriverDate>21/03/2016 00:00:00</DriverDate>
// <VendorID>0x10DE</VendorID>
// <DeviceID>0x1401</DeviceID>
// <SubSysID>0x32021462</SubSysID>
// <RevisionID>0x00A1</RevisionID>
//</DisplayDevice>
public string CardName;
public string Manufacturer;
public string ChipType;
public string DACType;
public string DeviceType;
public string DriverVersion;
public string DDIVersion;
public string FeatureLevels;
public string DriverModel;
public string DriverDate;
public string VendorID;
public string DeviceID;
public string SubSysID;
public string RevisionID;
public override string ToString()
{
System.Reflection.FieldInfo[] fields = this.GetType().GetFields();
string result = "";
for (int idx = 0; idx < fields.Length; ++idx)
{
result += string.Format("{0}:{1}", fields[idx].Name, fields[idx].GetValue(this).ToString());
if (idx < fields.Length - 1)
{
result += ", ";
}
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment