Search Unity

DirectX SDK version Unity 5.3.1 is built with??

Discussion in 'Windows' started by zezba9000, Jan 14, 2016.

  1. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    What version of the DirectX SDK is the Unity3D Windows standalone runtime built with? (June 2010?)
    I need to make a native plugin that gets a ID3D11Resource from a Texture2D / RenderTexture.

    Right now doing anything with the ID3D11Resource* pointer crashes the runtime.
    Do the SDK versions matter, Iv'e never tried to mix / mash before.

    EDIT: Never mind goof in my code on my part...
     
    Last edited: Jan 14, 2016
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    If anyone else wonders: SDK version does not matter for DirectX. All the interfaces are forward compatible.
     
    zezba9000 likes this.
  3. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Are you sure about this? This forum post said switching the D3D SDK version helps: http://forum.unity3d.com/threads/rendering-to-a-texture-from-a-plugin-d3d11.340435/

    Also Unity3D just crashes when trying to run the simple code below invoked from the MonoBehavior "void OnPostRender()" attached to a Camera that renders to a RenderTexture.
    NOTE: It crashes at "OMSetRenderTargets". (I'm just getting the last RenderTarget and Reseting it to the same thing)

    #C CODE
    [DllImport("VR_ExtendedMode", EntryPoint="VR_PostRender")]
    private static extern void VR_PostRender();

    void OnPostRender()
    {
    VR_PostRender();
    }

    C/C++ CODE
    extern "C" __declspec(dllexport) void VR_PostRender()
    {
    const int count = 1;
    ID3D11RenderTargetView *lastRT[count] = {0};
    ID3D11DepthStencilView *lastDepth[count] = { 0 };
    unityDeviceContext->OMGetRenderTargets(count, &lastRT[0], &lastDepth[0]);// works fine
    // TODO: do nothing for now...
    unityDeviceContext->OMSetRenderTargets(count, &lastRT[0], lastDepth[0]);// crashes Unity
    }
     
  4. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    I guess I should ask what method in Unity can we apply a custom render target and clear it?
    OnPostRender seems to almost work but then crashes.
    OnRenderObject just crashes.
    Update just crashes.
     
  5. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    I'm positive. SDK version doesn't matter.

    You cannot do this - you crash due to corrupted D3D11 device context. OnPostRender() is called on the main thread, and you are not allowed to interact with D3D API on it. Call this in your OnPostRender() render function:

    http://docs.unity3d.com/ScriptReference/GL.IssuePluginEvent.html

    It will call your native callback (pass its function pointer to it) on the graphics thread at the point when camera finished rendering.
     
    zezba9000 likes this.
  7. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Awesome tnx, I should be able to get things working now! It felt like a threading error when testing but wasn't sure. This helps answer some of my confusion.