Skip to content

Conversation

@erikaharrison-adsk
Copy link
Contributor

Description of Change(s)

  • Fix usage of Hgi in UsdImagingGLEngine.
    • It was mostly ignoring a user provided Hgi instance.
  • Add HgiDeviceFilter which lets you hook into the Hgi instance and/or device selection and creation.
    • This can be used implementation agnostic, but limits you information exposed by the HgiCapabilities API.
      • If you link against a specific Hgi implementation, then you can downcast to the backend class, which might expose more API specific information (especially the case with Vulkan).
    • To hook into the creation arguments, you insteead need to implement the backend specific subinterface of HgiDeviceFilter. Those unlock the full power of the API.
    • Since the OpenGL context (the closest thing it has to a device) is created externally, it ignores the device filter result (with a warning). It only ever enumerates a single device, and it should have already been setup by the application.

Examples:

class UmaHgiDeviceFilter : public HgiDeviceFilter
{
public:
   ~UmaHgiDeviceFilter() override = default;

   bool FilterDevice(const HgiCapabilities& capabilities) override
   {
      return capabilities.IsSet(HgiDeviceCapabilitiesBitsUnifiedMemory);
   }
};

class SoftwareVkHgiDeviceFilter : public HgiDeviceFilter
{
public:
   ~SoftwareVkHgiDeviceFilter() override = default;

   const TfToken& GetTargetHgiName() const override
   {
      return HgiTokens->Vulkan;
   }

   bool FilterDevice(const HgiCapabilities& capabilities) override
   {
      return dynamic_cast<const HgiVulkanCapabilities*>(&capabilities)->vkDeviceProperties2.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU;
   }
};

class FixMoltenVkHgiDeviceFitler : public HgiVulkanDeviceFilter
{
public:
   ~FixMoltenVkHgiDeviceFitler() override = default;

   bool FilterDevice(const HgiVulkanCapabilities& capabilities,
        VkPhysicalDevice device, VkDeviceCreateInfo& info) override
   {
      static constexpr uint32_t appleVendorID = 0x106B;
      if (capabilities.vkDeviceProperties2.properties.vendorID == appleVendorID) {
         // Disable host image copy on MoltenVK because it's bugged and crashes
         auto next = reinterpret_cast<const VkBaseOutStructure*>(info.pNext);
         while (next != nullptr) {
            switch (next->sType) {
               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES_EXT:
                  {
                     auto hostImageCopyFeatures = reinterpret_cast<const VkPhysicalDeviceHostImageCopyFeaturesEXT*>(next);
                     const_cast<VkPhysicalDeviceHostImageCopyFeaturesEXT*>(hostImageCopyFeatures)->hostImageCopy = false;
                  }
                  break;
               default:
                  break;
            }

            next = reinterpret_cast<VkBaseOutStructure*>(next->pNext);
         }
      }

      return true;
   }
};

Link to proposal (if applicable)

  • N/A

Fixes Issue(s)

  • N/A

Checklist

@DDoS DDoS force-pushed the adsk/feature/hgi-device-filter branch from a33db63 to bed83b2 Compare December 3, 2025 18:27
@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-11686

(This is an automated message. See here for more information.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants