Skip to content

Unity with DX11 texture can't be registered in CUDA #2

Closed

Description

@davidAlgis

When I try to register in CUDA a texture DX11 that has been created in Unity, I get the following error : ErrorCuda error: 1 invalid argument.

Activity

  1. davidAlgis commented on Mar 7, 2023

    @davidAlgis
    OwnerAuthor

    The texture that has been created in Unity with DX11 API, will have the type DXGI_FORMAT_R32G32B32A32_TYPELESS in native plugin. Therefore, they can't be used like that to be registered in CUDA with cudaGraphicsD3D11RegisterResource, because it doesn't accept this format.

  2. davidAlgis commented on Mar 7, 2023

    @davidAlgis
    OwnerAuthor

    I use this code to see that :

        ID3D11Texture2D *d3dtex = (ID3D11Texture2D *)_textureHandle;
        assert(d3dtex);
        D3D11_TEXTURE2D_DESC texDesc;
        d3dtex->GetDesc(&texDesc);
    
        DXGI_FORMAT format = texDesc.Format;
        Log::log().debugLog(std::to_string(format));
  3. davidAlgis commented on Mar 7, 2023

    @davidAlgis
    OwnerAuthor

    This issue was already reported here : see issue tracker

  4. davidAlgis commented on Mar 7, 2023

    @davidAlgis
    OwnerAuthor

    To solve this issue I have to create another texture and copy the content of the texture created in Unity into it. This will cause an overhead...

  5. changed the title [-]Unity with DX11 texture can't be register in CUDA[/-] [+]Unity with DX11 texture can't be registered in CUDA[/+] on Mar 8, 2023
  6. deibich commented on Mar 8, 2023

    @deibich

    Hello @davidAlgis,

    we also plan to use Unity with Cuda and got some code working. During my research I stumbled over your project which looks very promising.

    Because we focus on windows + directx I started to implement d3d11.
    https://github.com/deibich/InteropUnityCUDA/commits/d3d11

    As you can see I used Texture2D and Texture2DArray instead of RenderTexture to get rid of the problem with format ..._TYPLESS.

    To solve this issue I have to create another texture and copy the content of the texture created in Unity into it. This will cause an overhead...

    Does the "action_sample_texture_array" work with this workaround?

  7. davidAlgis commented on Mar 9, 2023

    @davidAlgis
    OwnerAuthor

    Hi @deibich,
    Nice to see that my work is being useful to someone.
    Thanks for the tips to change RenderTexture to Texture2D, after I saw the issue tracker, I had completely given up to make it work without a copy.
    This morning I push a first version that work for texture 2D with this copy, but as I except it cause a big overhead. Thanks to you, I push another version that work for texture 2D without a copy and the performances are better ! Now I will tackle the problem of the texture 2D array.

    To solve this issue I have to create another texture and copy the content of the texture created in Unity into it. This will cause an overhead...

    Does the "action_sample_texture_array" work with this workaround?

    On OpenGL, I could registered directly the texture array into a cuda surface object, that was then written with surf3DWrite. Therefore, no copy was needed. I hope to find a similar solution for dx11. Do not hesitate if you have any questions.

  8. davidAlgis commented on Mar 9, 2023

    @davidAlgis
    OwnerAuthor

    One drawback of using Texture2D instead of RenderTexture is that a Texture2D cannot be written in a compute shader. You get the following error if you try :

    Attempting to bind texture as UAV but the texture wasn't created with the UAV usage flag set!
    

    I think I will let the 2 options (with and without copy), just in case.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions