@@ -23,6 +23,41 @@ namespace vrperfkit {
2323 }
2424 }
2525
26+ ovrTextureFormat DetermineOutputFormat (const ovrTextureSwapChainDesc &desc) {
27+ if (desc.MiscFlags & ovrTextureMisc_DX_Typeless) {
28+ // if the incoming texture is physically in a typeless state, then we don't need to care
29+ // about whether or not it's SRGB
30+ return desc.Format ;
31+ }
32+
33+ // if the texture is not typeless, then if it is SRGB, applying upscaling will automatically unwrap
34+ // the SRGB values in our shader and thus produce non-SRGB values, so we need to use a non-SRGB
35+ // output format in these instances
36+ switch (desc.Format ) {
37+ case OVR_FORMAT_B8G8R8A8_UNORM_SRGB:
38+ return OVR_FORMAT_B8G8R8A8_UNORM;
39+ case OVR_FORMAT_B8G8R8X8_UNORM_SRGB:
40+ return OVR_FORMAT_B8G8R8X8_UNORM;
41+ case OVR_FORMAT_R8G8B8A8_UNORM_SRGB:
42+ return OVR_FORMAT_R8G8B8A8_UNORM;
43+ default :
44+ return desc.Format ;
45+ }
46+ }
47+
48+ bool ShouldCreateTypelessSwapchain (ovrTextureFormat format) {
49+ switch (format) {
50+ case OVR_FORMAT_B8G8R8A8_UNORM_SRGB:
51+ case OVR_FORMAT_B8G8R8A8_UNORM:
52+ case OVR_FORMAT_B8G8R8X8_UNORM_SRGB:
53+ case OVR_FORMAT_B8G8R8X8_UNORM:
54+ case OVR_FORMAT_R8G8B8A8_UNORM_SRGB:
55+ case OVR_FORMAT_R8G8B8A8_UNORM:
56+ return true ;
57+ default :
58+ return false ;
59+ }
60+ }
2661 }
2762
2863 OculusManager g_oculus;
@@ -146,6 +181,8 @@ namespace vrperfkit {
146181
147182 ovrTextureSwapChainDesc chainDesc;
148183 Check (" getting swapchain description" , ovr_GetTextureSwapChainDesc (session, submittedEyeChains[eye], &chainDesc));
184+ LOG_INFO << " Swap chain has format " << chainDesc.Format << " , bind flags " << chainDesc.BindFlags << " and misc flags " << chainDesc.MiscFlags ;
185+ ovrTextureFormat outputFormat = DetermineOutputFormat (chainDesc);
149186 if (chainDesc.SampleCount > 1 ) {
150187 LOG_INFO << " Submitted textures are multi-sampled, creating resolve texture" ;
151188 d3d11Res->resolveTexture [eye] = CreateResolveTexture (d3d11Res->device .Get (), d3d11Res->submittedTextures [0 ][0 ].Get ());
@@ -163,13 +200,16 @@ namespace vrperfkit {
163200 chainDesc.SampleCount = 1 ;
164201 chainDesc.MipLevels = 1 ;
165202 chainDesc.BindFlags = ovrTextureBind_DX_UnorderedAccess;
166- // fixme: may need some adjustments from actual types
167- chainDesc.MiscFlags = ovrTextureMisc_DX_Typeless;
168- chainDesc.Format = OVR_FORMAT_R8G8B8A8_UNORM;
203+ chainDesc.MiscFlags = ovrTextureMisc_AutoGenerateMips;
204+ if (ShouldCreateTypelessSwapchain (outputFormat)) {
205+ chainDesc.MiscFlags = chainDesc.MiscFlags | ovrTextureMisc_DX_Typeless;
206+ }
207+ chainDesc.Format = outputFormat;
169208 chainDesc.StaticImage = false ;
170209 LOG_INFO << " Eye " << eye << " : submitted textures have resolution " << chainDesc.Width << " x" << chainDesc.Height ;
171210 AdjustOutputResolution (chainDesc.Width , chainDesc.Height );
172211 LOG_INFO << " Eye " << eye << " : output resolution is " << chainDesc.Width << " x" << chainDesc.Height ;
212+ LOG_INFO << " Creating output swapchain in format " << chainDesc.Format ;
173213 Check (" creating output swapchain" , ovr_CreateTextureSwapChainDX (session, d3d11Res->device .Get (), &chainDesc, &outputEyeChains[eye]));
174214
175215 Check (" getting texture swapchain length" , ovr_GetTextureSwapChainLength (session, outputEyeChains[eye], &length));
0 commit comments