Search Unity

Bug A word with Unity Devs about Native Unity SDK

Discussion in 'Editor & General Support' started by rossetagotstoned, Feb 6, 2022.

  1. rossetagotstoned

    rossetagotstoned

    Joined:
    Jan 12, 2020
    Posts:
    8
    Hi,
    I'm a c++ programmer and I'm developing a plugin for unity.

    There's a question in my pipeline that I didn't find the answer anywhere so I want to ask from unity developers to make sure.

    Facts :
    1. I make the plugin for DirectX 11 & 12.
    2. In D3D11 & D3D12 interfaces there's a key based value named as UnityTextureID
    3. In unity documintation this is noted that result of GetNativeTextureID is only working on OpenGL devices.
    4. API function SRVFromNativeTexture not works with result of GetNativeTextureID.
    5. I ran this test and made sure SRVFromNativeTexture is working fine and it did.
    Code (CSharp):
    1. for (UnityTextureID i = 0; i < 1048575; i++)
    2.     {
    3.         ID3D11ShaderResourceView* in_srv = _Interface->SRVFromNativeTexture(i);
    4.         if (!in_srv) continue;
    5.         LOG(DEBUG) << "Texture " << std::dec << i << " SRV Ptr : " << std::hex << in_srv;
    6.     }
    Questions :
    1. Why are there SRVFromNativeTexture & TextureFromNativeTexture in DirectX SDK when UnityTextureID is only usable on OpenGL devices?

    2. How can I obtain the valid ID to get the SRV from a texture in native backend?

    3. Is this all deprecated?


    Regards
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Hi,

    looks like Texture.GetNativeTextureID returned a fake "texture id" on D3D11 and D3D12, which could later be used with SRVFromNativeTexture to retrieve ID3D11ShaderResourceView on D3D11 and TextureFromNativeTexture to retrieve ID3D12Resource on D3D12. However, doing it that was clunky as you needed a 2 step process. Texture.GetNativeTextureID API was deprecated a while back, but it seems the native plugin equivalents were not (to me this looks like an oversight).

    To retrieve a native texture pointer, you can use Texture.GetNativeTexturePtr instead.
     
  3. rossetagotstoned

    rossetagotstoned

    Joined:
    Jan 12, 2020
    Posts:
    8
    Thanks, So there's no way to get existing srv for the texture and I need to create it myself?
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Correct. Fortunately, SRVs are lightweight so creating additional ones shouldn't be a performance concern.
     
    rossetagotstoned likes this.