PhysicalDeviceDescriptor.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/RHI.Reflect/PhysicalDeviceDescriptor.h>
  9. #include <Atom/RHI.Reflect/PhysicalDeviceDriverInfoSerializer.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Serialization/Json/RegistrationContext.h>
  12. #include <AzCore/Preprocessor/EnumReflectUtils.h>
  13. #include <sstream>
  14. namespace AZ::RHI
  15. {
  16. AZ_ENUM_DEFINE_REFLECT_UTILITIES(VendorId);
  17. void ReflectVendorIdEnums(ReflectContext* context)
  18. {
  19. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  20. {
  21. VendorIdReflect(*serializeContext);
  22. }
  23. }
  24. void PhysicalDeviceDescriptor::Reflect(AZ::ReflectContext* context)
  25. {
  26. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  27. {
  28. serializeContext->Class<PhysicalDeviceDescriptor>()
  29. ->Version(1)
  30. ->Field("m_description", &PhysicalDeviceDescriptor::m_description)
  31. ->Field("m_type", &PhysicalDeviceDescriptor::m_type)
  32. ->Field("m_vendorId", &PhysicalDeviceDescriptor::m_vendorId)
  33. ->Field("m_deviceId", &PhysicalDeviceDescriptor::m_deviceId)
  34. ->Field("m_driverVersion", &PhysicalDeviceDescriptor::m_driverVersion)
  35. ->Field("m_heapSizePerLevel", &PhysicalDeviceDescriptor::m_heapSizePerLevel);
  36. }
  37. }
  38. void PhysicalDeviceDriverInfo::Reflect(AZ::ReflectContext* context)
  39. {
  40. if (JsonRegistrationContext* jsonContext = azrtti_cast<JsonRegistrationContext*>(context))
  41. {
  42. jsonContext->Serializer<JsonPhysicalDeviceDriverInfoSerializer>()->HandlesType<PhysicalDeviceDriverInfo>();
  43. }
  44. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  45. {
  46. serializeContext->Class<PhysicalDeviceDriverInfo>()
  47. ->Version(1);
  48. }
  49. }
  50. void PhysicalDeviceDriverInfo::PrintRequiredDiverInfo() const
  51. {
  52. std::stringstream ss;
  53. ss << "Vendor " << ToString(m_vendorId).data() << " must have a minimum version of " << m_minVersion.m_readableVersion.c_str();
  54. auto badVersionIter = m_versionsWithIssues.begin();
  55. if (badVersionIter != m_versionsWithIssues.end())
  56. {
  57. ss << ".\nAnd the following versions are known to have issues with Atom: " << badVersionIter->m_readableVersion.c_str();
  58. ++badVersionIter;
  59. }
  60. while (badVersionIter != m_versionsWithIssues.end())
  61. {
  62. ss << ", " << badVersionIter->m_readableVersion.c_str();
  63. ++badVersionIter;
  64. }
  65. ss << ".\n";
  66. AZ_Printf("RHISystem", ss.str().c_str());
  67. }
  68. void PhysicalDeviceDriverValidator::Reflect(AZ::ReflectContext* context)
  69. {
  70. PhysicalDeviceDriverInfo::Reflect(context);
  71. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  72. {
  73. serializeContext->Class<PhysicalDeviceDriverValidator>()->Version(1)->Field(
  74. "driverInfo", &PhysicalDeviceDriverValidator::m_driverInfo);
  75. }
  76. }
  77. PhysicalDeviceDriverValidator::ValidationResult PhysicalDeviceDriverValidator::ValidateDriverVersion(const PhysicalDeviceDescriptor& descriptor) const
  78. {
  79. // [GFX TODO] Add driver info for other platforms besides Windows. Currently, avoid spamming warnings.
  80. // ATOM-14967 [RHI][Metal] - Address driver version validator for Mac
  81. if (m_driverInfo.size() == 0)
  82. {
  83. return ValidationResult::MissingInfo;
  84. }
  85. auto iter = m_driverInfo.find(descriptor.m_vendorId);
  86. if (iter == m_driverInfo.end())
  87. {
  88. AZ_Warning(
  89. "PhysicalDeviceDriverValidator", false,
  90. "Unable to verify driver versions. Vendor %s infomation is not provided in PhysicalDeviceDriverInfo.setreg.",
  91. ToString(descriptor.m_vendorId).data());
  92. return ValidationResult::MissingInfo;
  93. }
  94. const PhysicalDeviceDriverInfo& driverInfo = iter->second;
  95. if (descriptor.m_driverVersion < driverInfo.m_minVersion.m_encodedVersion)
  96. {
  97. AZ_Warning(
  98. "PhysicalDeviceDriverValidator", false, "Vendor %s should use a driver version higher than or equal to %s.",
  99. ToString(descriptor.m_vendorId).data(), driverInfo.m_minVersion.m_readableVersion.c_str());
  100. driverInfo.PrintRequiredDiverInfo();
  101. return ValidationResult::Unsupported;
  102. }
  103. else
  104. {
  105. for (const auto& badVersion : driverInfo.m_versionsWithIssues)
  106. {
  107. if (badVersion.m_encodedVersion == descriptor.m_driverVersion)
  108. {
  109. AZ_Warning(
  110. "PhysicalDeviceDriverValidator", false, "Vendor %s driver version %s is known to have some issues with Atom.",
  111. ToString(descriptor.m_vendorId).data(), badVersion.m_readableVersion.c_str());
  112. driverInfo.PrintRequiredDiverInfo();
  113. return ValidationResult::SupportedWithIssues;
  114. }
  115. }
  116. }
  117. return ValidationResult::Supported;
  118. }
  119. }