IVRDriverDirectModeComponent Textures aren't accepted by VRCompositor
I am trying to develop a driver with the IVRDriverDirectModeComponent and I am experiencing two issues that I was hoping to get some answers for:
- When I implement the IVRDriverDirectModeComponent I can only get the CreateSwapTextureSet() called when I also implement the IVRDisplayComponent and return the exact height and width of the monitor that is physically connected to the system. I am trying to render to display that isn't connected directly to the system. Can anyone please explain how to bypass this need and use custom resolutions?
I am returning the following properties from my driver:
VRProperties()->SetUint64Property(m_ulPropertyContainer, Prop_CurrentUniverseId_Uint64, 1);
VRProperties()->SetBoolProperty(m_ulPropertyContainer, Prop_IsOnDesktop_Bool, false);
VRProperties()->SetBoolProperty(m_ulPropertyContainer, Prop_UsesDriverDirectMode_Bool, true);
Update: The problem with my implementation was that I was returning true from the IsDisplayRealDisplay() function of the IVRDisplayComponent. Changing the return value to false and marking it as "fictional" display allowed me to change the resolution and still be able to get the calls to CreateSwapTextureSet()
- I am not able to get the textures to be accepted by the vrcompositor. this is how I create the textures and return their handles:
D3D11_TEXTURE2D_DESC Desc;
Desc.ArraySize = 1;
Desc.Width = unWidth;
Desc.Height = unHeight;
MipLevels = 1;
Format = (DXGI_FORMAT)unFormat;
SampleDesc.Count = 1;
SampleDesc.Quality = 0;
Usage = D3D11_USAGE_DEFAULT;
BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
CPUAccessFlags = 0;
Desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
HRESULT hr = S_OK;
for (int i = 0; i < 3; i++) {
g_ppTexture[i] = NULL;
hr = g_pd3dDevice->CreateTexture2D(&Desc, NULL, &(g_ppTexture[i]));
HANDLE handle;
IDXGIResource1* pResource;
g_ppTexture[i]->QueryInterface(__uuidof(IDXGIResource1), (void**)&pResource);
hr=pResource->CreateSharedHandle(NULL,
DXGI_SHARED_RESOURCE_WRITE | DXGI_SHARED_RESOURCE_READ,
NULL,
(HANDLE*)pSharedTextureHandles[i]);
}
from vrcompositor.txt:
Failed to create resolve texture for oculus direct mode (compositor)!
Any tips would be greatly appreciated!
Not sure about the implications, but don't think you should be using universe_id 1 (Oculus). Works fine with custom (2). AFAIK OpenVR uses ID3D11Device::OpenSharedResource on your texture handle, so you need to return one that is compatible with that.
@TheDeveloperGuy - Thanks for the comment! I did try different universe_id but it didn't change much.
I figured that the call that OpenVR does on my supplied texture is ID3D11Device::OpenSharedResource, problem is that I'm not sure why OpenVR doesn't accept them. I am using the method of getting the shared handles of these textures using IDXGIResource::GetSharedHandle() and I also tried the newer dx11_1 CreateSharedHandle() as recommended by Microsoft. Unfortunately, neither of these methods worked. Are there any special flags that have to be set on the textures for them to work?
D3D11_RESOURCE_MISC_SHARED and GetSharedHandle() works fine. Never tried using NTHANDLE or KEYEDMUTEX so don't know if they would or not.
You do need to support an arbitrary number of texture swap sets. It seems like your code is for 1 global swap set, that definitely won't work! I would (did) get the whole texture management process working (look at all the texture APIs you need to support to figure out what you need) before you even start implementing allocating textures. It's quite possible that you will get misleading results otherwise.
Bear in mind this is not a "friendly" interface. It also has no documentation and isn't very well supported outside of internal use at Valve. Your implementation is expected to work and you won't get many clues (from debugging or devs) as to what is going wrong.
DriverLog() is your friend... ;)
@TheDeveloperGuy Thank you so much for your feedback. I did have an issue with my texture management that I fixed and it seem to be working now.
DriverLog is definitely my friend 👍
Is there an IRC channel for OpenVR devs? or even better Slack channel?
Not that I know of (but I haven't looked TBH). Pls let me know if you do/don't run into this (when you get there): https://github.com/ValveSoftware/openvr/issues/359