Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Yashiz · Oct 11, 2017 at 03:42 PM · crashtexture2dpluginopengldirectx 11

How Texture2D.CreateExternalTexture works with Direct3D11?

on Unity 2017.1.1 and 2017.1.2

Texture2D.CreateExternalTexture works well on OpenGL Mode, but it crashes if I use Direct3D11 Mode. Here is the crash stack:

 Unity.exe!TexturesD3D11Base::TextureFromShaderResourceView(struct ID3D11ShaderResourceView *,struct ID3D11Texture2D * *)    Unknown
  Unity.exe!TexturesD3D11Base::RegisterNativeTexture(struct ID3D11ShaderResourceView *)    Unknown
  Unity.exe!GfxDeviceD3D11Base::RegisterNativeTexture(struct TextureID,__int64,enum TextureDimension)    Unknown
  Unity.exe!GfxDeviceWorker::RunCommand(class ThreadedStreamBuffer &)    Unknown
  Unity.exe!GfxDeviceWorker::Run(void)    Unknown
  Unity.exe!GfxDeviceWorker::RunGfxDeviceWorker(void *)    Unknown
  Unity.exe!Thread::RunThreadWrapper(void *)    Unknown
  kernel32.dll!00000000777e59cd()    Unknown
  ntdll.dll!0000000077a1a561()    Unknown

I would like to know how to make it use with Direct3D11 Mode and if there are some examples I could follow ?

Code below is how I try to make CreateExternalTexture work with Direct3D11.

In my native plugin, I create a texture2D as this:

 D3D11_TEXTURE2D_DESC textureDesc;
 ZeroMemory(&textureDesc, sizeof(textureDesc));

 textureDesc.Width = _width;
 textureDesc.Height = _height;
 textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
 textureDesc.MipLevels = textureDesc.ArraySize = 1;
 textureDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
 textureDesc.SampleDesc.Count = 1;
 textureDesc.Usage = D3D11_USAGE_DEFAULT;
 textureDesc.CPUAccessFlags = 0;
 textureDesc.MiscFlags = 0;

 auto hr = _d3d11Device->CreateTexture2D(&textureDesc, NULL, &_outputTexture);
 assert(hr == S_OK);

 return _outputTexture

Where _outputTexture is interpreted as void* and passed to Unity as IntPtr. In debug mode, I could see the IntPtr I get from Unity seems OK (not a crazy or zero number).

Then In Unity I get the IntPtr and create:

 // I get my _outputTexture
 nativeTex = NativeD3D11PluginWrapper.GetOutputTexture((uint)Screen.width, (uint)Screen.height);
 texture = Texture2D.CreateExternalTexture(Screen.width, Screen.height, format, false, false, nativeTex); <----- crash here (see the crash stack above).

If I do the similar thing in OpenGL, it doesn't crash and it works. Of course you know in OpenGL mode, the IntPtr I get is a texture "name" not an address...

Thanks for any answers,

yashiz

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by HeqiLu · Oct 12, 2017 at 07:55 AM

In doc it says: Native texture object on Direct3D-like devices is a pointer to the base type, from which a texture can be created (IDirect3DBaseTexture9 on D3D9, ID3D11ShaderResourceView on D3D11). On OpenGL/OpenGL ES it is GLuint. On Metal it is id.

Literally, ID3D11ShaderResourceView needs to be passed, not the texture itself.

The function crashed TexturesD3D11Base::TextureFromShaderResourceView makes sense.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

83 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating a Texture or Texture2D from a plugin. 0 Answers

How does Texture2D.CreateExternalTexture work? 1 Answer

How should I release a DirectX11 texture created in a native plugin? 1 Answer

Issue with glDrawArrays in plugin 2 Answers

5.0.1 mesh crash, Fatal signal 11, SetVertexStateGLES 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges