Sign in to follow this  

Maya 2017 Viewport 2.0: Forcing D3D11_CREATE_DEVICE_SINGLETHREADED off

This topic is 394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

Background: I am currently migrating our game engine from Maya 2012 and OpenGL Viewport 1.0 renderer to Maya 2017 and Viewport 2.0 DirectX11. I am using ID3D11Device created by Maya so that our MPxGeometryOverrides used for selection and engine render loop (which is blitted to viewport by MUserRenderOperation) can share DX resources. Unfortunately it turns out that Maya creates the ID3D11Device with D3D11_CREATE_DEVICE_SINGLETHREADED flag, causing our asynchronous resource loading to crash:

ID3D11Device* device = (ID3D11Device*)MHWRender::MRenderer::theRenderer()->GPUDeviceHandle();

UINT flags = device->GetCreationFlags();

bool isDeviceMultithreaded = (flags & D3D11_CREATE_DEVICE_SINGLETHREADED) == 0;

assert( isDeviceMultithreaded ); // This fails

AFAIK there is no real reason for multithreaded device to be off (apart from minor single thread performance gains). I could rewrite our resource loading to use spinlocks on ID3D11Device creation methods, while deffering the actual calls to the time when I have the main thread (so that Maya itself won't interfere); but it seems like a hassle and I would like to avoid duplicating code or writing core engine's functionalities around Maya's quirks.

 

So does anyone know of any way to force D3D11_CREATE_DEVICE_SINGLETHREADED flag off? Can't really find anything in Maya's preferences and DirectX Control Panel doesn't provide this option. I have also tried to write a hook on D3D11CreateDeviceAndSwapChain using MinHook library, but I can't really figure out how to properly attach it with Maya's start so that I don't miss the device initialization.

 

Thanks in advance for all your help.

 

Update: I wrote a small exe that starts maya and injects dll with dllMain that injects my hooks (based on rederdoc code), but if I call CreateRemoteThread on Maya process, Maya shows empty "Command Window", halts, and immediately exits when I close this window. I am guessing that this maybe some kind of anti-piracy measure. Anyway, I am still stuck.

Edited by olej

Share this post


Link to post
Share on other sites

What we do at work is we create our own device instead of using Maya's device. If you do this you can create the device however you like, which means you can also turn on the debug layer for validation (which was my main motivation for doing this in the first place). The tricky part is that your color and depth data ultimately need to end up in textures that Maya creates using its own device, which means you have to do some cross-device sharing and copying. I set it up like this:

 

1. Create a render target texture on my device with sharing flags enabled

2. Open the shared texture on Maya's device using the shared handle

3. Every time we render a frame:

   A. Have our engine rendering everything to an internal render target using our device

   B. Lock the shared texture using the keyed mutex

   C. Use our device to copy data to the shared texture

   D. Use Maya's device to copy the data from the shared texture to the viewport's render target texture

 

The shared resource API's are a little annoying to use, but not impossible. If you decide to go down this route and get stuck, I can try to help you through it.

Edited by MJP

Share this post


Link to post
Share on other sites

This topic is 394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this