Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
davidAlgis opened this issue Mar 7, 2023 · 7 comments
Closed

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

davidAlgis opened this issue Mar 7, 2023 · 7 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@davidAlgis
Copy link
Owner

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.

@davidAlgis
Copy link
Owner Author

davidAlgis commented Mar 7, 2023

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.

@davidAlgis
Copy link
Owner Author

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));

@davidAlgis
Copy link
Owner Author

This issue was already reported here : see issue tracker

@davidAlgis davidAlgis added bug Something isn't working enhancement New feature or request labels Mar 7, 2023
@davidAlgis
Copy link
Owner Author

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...

@davidAlgis davidAlgis changed the title Unity with DX11 texture can't be register in CUDA Unity with DX11 texture can't be registered in CUDA Mar 8, 2023
@deibich
Copy link

deibich commented Mar 8, 2023

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?

davidAlgis added a commit that referenced this issue Mar 9, 2023
For RenderAPI DX11 I add methods to create and copy texture see #2
@davidAlgis
Copy link
Owner Author

davidAlgis commented Mar 9, 2023

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.

@davidAlgis
Copy link
Owner Author

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
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants