openvr icon indicating copy to clipboard operation
openvr copied to clipboard

Possible bug when using IVRDriverDirectModeComponent driver

Open TheDeveloperGuy opened this issue 9 years ago • 10 comments

When debugging my IVRDriverDirectModeComponent driver, I've found the following issue:

OpenVR will always draw in and submit the texture for index 0 of the swap set when submitting images for the right eye, regardless of the index returned by GetNextSwapTextureSetIndex() for the right eye swap set. Everything works as expected for the left eye (ie. OpenVR will use the index returned for the swap set). I have double- and triple-checked that this is not a bug in my driver.

In my driver this doesn't affect anything (and it's possible the same is true for the Oculus drivers), and maybe this is by design? However, it seems that OpenVR should use the index returned by GetNextSwapTextureSetIndex() otherwise what is the point in asking for it?

TheDeveloperGuy avatar Jan 10 '17 14:01 TheDeveloperGuy

Are you using the syncTexture passed into Present?

For example:

// Open sync texture only when it changes.
if ( m_syncTexture != syncTexture )
{
	m_syncTexture = syncTexture;

	SAFE_RELEASE( m_pSyncTexture );

	if ( m_syncTexture )
	{
		m_pD3D11Device->OpenSharedResource( ( HANDLE )m_syncTexture, __uuidof( ID3D11Texture2D ), ( void ** )&m_pSyncTexture );
	}
}

IDXGIKeyedMutex *pSyncMutex = NULL;
if ( m_pSyncTexture != NULL &&
	SUCCEEDED( m_pSyncTexture->QueryInterface( __uuidof( IDXGIKeyedMutex ), ( void ** )&pSyncMutex ) ) )
{
	pSyncMutex->AcquireSync( 0, 10 );
}

// Do stuff with scene textures

if ( pSyncMutex )
{
	pSyncMutex->ReleaseSync( 0 );
	pSyncMutex->Release();
}

aleiby avatar Jan 12 '17 23:01 aleiby

I wasn't, I am now (thanks!), but it doesn't affect this issue. If you run SteamVR without running any title, you will see this issue. In this case, there will never be a syncTexture passed to Present().

TheDeveloperGuy avatar Jan 13 '17 03:01 TheDeveloperGuy

@aleiby Maybe there's some other setup (that I can't think of) that needs to be done? If I mirror the HMD using SteamVR then I will get a flickering image for the right eye in the mirrored display. The actual HMD shows the correct image. Note this only happens when running a VR app, not in the SteamVR environment, or the dashboard.

Needless to say this doesn't happen with Oculus, so I must be doing something wrong, but I don't know what that is. I create 3 swap textures for each eye, and return the correct "next" index for both swap sets. However, I can see that the textures being presented are always from index 0 for the right eye.

TheDeveloperGuy avatar Feb 15 '17 08:02 TheDeveloperGuy

@aleiby So it seems that the mirror is flipping between all 3 swap textures, but the app is only rendering in the first (for the right eye). I don't know how else I can tell the app that it needs to be using a different swap set index for the right eye. AFAIK that is what I'm doing in GetNextSwapTextureSetIndex(). I also don't understand how the SteamVR UI renders correctly in the mirror.

GetNextSwapTextureSetIndex() should always set an index in the range 0-2 for both left and right eyes, right?

TheDeveloperGuy avatar Feb 16 '17 07:02 TheDeveloperGuy

@JoeLudwig @aleiby Really want to get to the bottom of this. Flickering mirror window is not fun! I'm at the stage of considering writing a shim to watch the Oculus driver, but would prefer to avoid reverse-engineering.

I'm using the same logic for left and right eyes, and am definitely returning a non-zero index for the right eye, but the texture passed for right eye to Present() is always texture index 0 (of the right eye swap set). Left eye works as expected. Indices for both eyes are always in the range 0-2.

TheDeveloperGuy avatar Mar 04 '17 06:03 TheDeveloperGuy

@TheDeveloperGuy did you resolve the issue yet? When you return the index values with GetNextSwapTextureSetIndex() you need to make sure your return them using the dereference array like this: (*pIndices)[0] And not: *pIndices[0]

It maybe obvious, but I believe it's worth double checking.

dperox avatar Mar 15 '17 05:03 dperox

@dperox Ahem, good catch! Schoolboy error.... :/

TheDeveloperGuy avatar Mar 15 '17 09:03 TheDeveloperGuy

@TheDeveloperGuy Curiosity, as I'm playing a bit here as well. How are you returning multiple textures in each shared handled sent to CreateSwapTextureSet? Is it a single texture with multiple subresources?

benbuzbee avatar Mar 15 '17 19:03 benbuzbee

@benbuzbee There is only 1 texture per handle. You're supposed to create 3 textures, get shared handles to them and pass them back via the array of handle pointers: vr::SharedTextureHandle_t(*pSharedTextureHandles)[3]

TheDeveloperGuy avatar Mar 16 '17 00:03 TheDeveloperGuy

Much appreciate for aleiby's help! It's really useful to me!

LoSealL avatar May 27 '17 10:05 LoSealL