Search Unity

Video Conflict between Spatializer plugins and Low-level graphics plugin.

Discussion in 'Audio & Video' started by hanseuljun, Dec 12, 2018.

  1. hanseuljun

    hanseuljun

    Joined:
    Sep 16, 2017
    Posts:
    2
    I'm using low-level graphics plugin for HoloLens. The problem is, using any spatializer included in Unity breaks the low-level graphics code. The following is code relevant to the problem.

    static IUnityInterfaces* unity_interfaces_ = 0;
    static IUnityGraphics* unity_graphics_ = 0;
    static ID3D11Device* d3d11_device_ = 0;
    static ID3D11DeviceContext* d3d11_device_context_ = 0;

    // Function that gets called by Unity.
    extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* interfaces)
    {
    print_debug("UnityPluginLoad");
    unity_interfaces_ = interfaces;
    unity_graphics_ = unity_interfaces_->Get<IUnityGraphics>();
    unity_graphics_->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);

    // Run OnGraphicsDeviceEvent(initialize) manually on plugin load
    // to not miss the event in case the graphics device is already initialized
    #ifdef _WIN64
    OnGraphicsDeviceEvent(kUnityGfxDeviceEventInitialize);
    #endif
    }

    // Callback function to handle UnityGfxDeviceEvents.
    static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType)
    {
    switch(eventType)
    {
    case kUnityGfxDeviceEventInitialize:
    {
    IUnityGraphicsD3D11* d3d = unity_interfaces_->Get<IUnityGraphicsD3D11>();
    d3d11_device_ = d3d->GetDevice();
    d3d11_device_->GetImmediateContext(&d3d11_device_context_);
    break;
    }
    case kUnityGfxDeviceEventShutdown:
    {
    d3d11_device_ = 0;
    d3d11_device_context_ = 0;
    break;
    }
    };
    }

    In the code above, OnGraphicsDeviceEvent gets called with kUnityGfxDeviceEventInitialize at the beginning of the application. However, d3d->GetDevice() returns nullptr instead of a IUnityGraphicsD3D11* when any spatializer plugin is included to the application. By any, I mean MS/Oculus/Resonance. This is a bug which I want to detour. Is there anybody who knows how to access to Unity's IUnityGraphicsD3D11* in a different way?
     
  2. hanseuljun

    hanseuljun

    Joined:
    Sep 16, 2017
    Posts:
    2
    In the above, I mean ID3D11Device's instead of IUnityGraphicsD3D11's in the last paragraph. I can't edit it since this website considers me as a spammer.