The open source OpenXR runtime

st/oxr: Turn compositor create macro into function

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2647>

authored by Christoph Haag and committed by Jakob Bornecrantz 1f6da677 802c066e

Changed files
+82 -44
src
xrt
state_trackers
+82 -44
src/xrt/state_trackers/oxr/oxr_session.c
··· 1105 1105 } \ 1106 1106 } while (false) 1107 1107 1108 - #define OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(LOG, XSI, SESS) \ 1108 + #define OXR_CHECK_XR_SUCCESS(LOG, FUNC, MSG) \ 1109 1109 do { \ 1110 - if ((SESS)->sys->xsysc == NULL) { \ 1111 - return oxr_error((LOG), XR_ERROR_RUNTIME_FAILURE, \ 1112 - "The system compositor wasn't created, can't create native compositor!"); \ 1113 - } \ 1114 - xrt_result_t xret = xrt_system_create_session((SESS)->sys->xsys, (XSI), &(SESS)->xs, &(SESS)->xcn); \ 1115 - if (xret == XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED) { \ 1116 - return oxr_error((LOG), XR_ERROR_LIMIT_REACHED, "Per instance multi-session not supported."); \ 1117 - } \ 1118 - if (xret != XRT_SUCCESS) { \ 1119 - return oxr_error((LOG), XR_ERROR_RUNTIME_FAILURE, \ 1120 - "Failed to create xrt_session and xrt_compositor_native! '%i'", xret); \ 1121 - } \ 1122 - if ((SESS)->sys->xsysc->xmcc != NULL) { \ 1123 - xrt_syscomp_set_state((SESS)->sys->xsysc, &(SESS)->xcn->base, true, true); \ 1124 - xrt_syscomp_set_z_order((SESS)->sys->xsysc, &(SESS)->xcn->base, 0); \ 1110 + XrResult _xr_result = FUNC; \ 1111 + if (_xr_result != XR_SUCCESS) { \ 1112 + return oxr_error(LOG, _xr_result, MSG); \ 1125 1113 } \ 1126 1114 } while (false) 1127 1115 1128 - #define OXR_SESSION_ALLOCATE_AND_INIT(LOG, SYS, GFX_TYPE, OUT) \ 1129 - do { \ 1130 - XrResult ret = oxr_session_allocate_and_init(LOG, SYS, GFX_TYPE, &OUT); \ 1131 - if (ret != XR_SUCCESS) { \ 1132 - return ret; \ 1133 - } \ 1134 - } while (0) 1116 + 1117 + 1118 + static XrResult 1119 + oxr_create_xrt_session_and_native_compositor(struct oxr_logger *log, 1120 + const struct xrt_session_info *xsi, 1121 + struct oxr_session *sess) 1122 + { 1123 + if (sess->sys->xsysc == NULL) { 1124 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, 1125 + "The system compositor wasn't created, can't create native compositor!"); 1126 + } 1127 + xrt_result_t xret = xrt_system_create_session(sess->sys->xsys, xsi, &sess->xs, &sess->xcn); 1128 + if (xret == XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED) { 1129 + return oxr_error(log, XR_ERROR_LIMIT_REACHED, "Per instance multi-session not supported."); 1130 + } 1131 + if (xret != XRT_SUCCESS) { 1132 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, 1133 + "Failed to create xrt_session and xrt_compositor_native! '%i'", xret); 1134 + } 1135 + if (sess->sys->xsysc->xmcc != NULL) { 1136 + xrt_syscomp_set_state(sess->sys->xsysc, &sess->xcn->base, true, true); 1137 + xrt_syscomp_set_z_order(sess->sys->xsysc, &sess->xcn->base, 0); 1138 + } 1139 + return XR_SUCCESS; 1140 + } 1141 + 1135 1142 1136 1143 1137 1144 /* ··· 1145 1152 const struct xrt_session_info *xsi, 1146 1153 struct oxr_session **out_session) 1147 1154 { 1155 + XrResult ret = XR_SUCCESS; 1156 + 1148 1157 #if defined(XR_USE_PLATFORM_XLIB) && defined(XR_USE_GRAPHICS_API_OPENGL) 1149 1158 XrGraphicsBindingOpenGLXlibKHR const *opengl_xlib = OXR_GET_INPUT_FROM_CHAIN( 1150 1159 createInfo, XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR, XrGraphicsBindingOpenGLXlibKHR); ··· 1157 1166 "xrGetOpenGL[ES]GraphicsRequirementsKHR"); 1158 1167 } 1159 1168 1160 - OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_XLIB_GL, *out_session); 1161 - OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session); 1169 + ret = oxr_session_allocate_and_init(log, sys, OXR_SESSION_GRAPHICS_EXT_XLIB_GL, out_session); 1170 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to allocate session"); 1171 + 1172 + ret = oxr_create_xrt_session_and_native_compositor(log, xsi, *out_session); 1173 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to create session/compositor"); 1174 + 1162 1175 return oxr_session_populate_gl_xlib(log, sys, opengl_xlib, *out_session); 1163 1176 } 1164 1177 #endif ··· 1176 1189 "xrGetOpenGLESGraphicsRequirementsKHR"); 1177 1190 } 1178 1191 1179 - OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_ANDROID_GLES, *out_session); 1180 - OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session); 1192 + ret = oxr_session_allocate_and_init(log, sys, OXR_SESSION_GRAPHICS_EXT_ANDROID_GLES, out_session); 1193 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to allocate session"); 1194 + 1195 + ret = oxr_create_xrt_session_and_native_compositor(log, xsi, *out_session); 1196 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to create session/compositor"); 1197 + 1181 1198 return oxr_session_populate_gles_android(log, sys, opengles_android, *out_session); 1182 1199 } 1183 1200 #endif ··· 1193 1210 "Has not called xrGetOpenGLGraphicsRequirementsKHR"); 1194 1211 } 1195 1212 1196 - OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_WIN32_GL, *out_session); 1197 - OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session); 1213 + ret = oxr_session_allocate_and_init(log, sys, OXR_SESSION_GRAPHICS_EXT_WIN32_GL, out_session); 1214 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to allocate session"); 1215 + 1216 + ret = oxr_create_xrt_session_and_native_compositor(log, xsi, *out_session); 1217 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to create session/compositor"); 1218 + 1198 1219 return oxr_session_populate_gl_win32(log, sys, opengl_win32, *out_session); 1199 1220 } 1200 1221 #endif ··· 1232 1253 (void *)vulkan->physicalDevice, (void *)sys->suggested_vulkan_physical_device, fn); 1233 1254 } 1234 1255 1235 - OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_VULKAN, *out_session); 1236 - OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session); 1256 + ret = oxr_session_allocate_and_init(log, sys, OXR_SESSION_GRAPHICS_EXT_VULKAN, out_session); 1257 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to allocate session"); 1258 + 1259 + ret = oxr_create_xrt_session_and_native_compositor(log, xsi, *out_session); 1260 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to create session/compositor"); 1261 + 1237 1262 return oxr_session_populate_vk(log, sys, vulkan, *out_session); 1238 1263 } 1239 1264 #endif ··· 1250 1275 "xrGetOpenGL[ES]GraphicsRequirementsKHR"); 1251 1276 } 1252 1277 1253 - OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_EGL, *out_session); 1254 - OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session); 1278 + ret = oxr_session_allocate_and_init(log, sys, OXR_SESSION_GRAPHICS_EXT_EGL, out_session); 1279 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to allocate session"); 1280 + 1281 + ret = oxr_create_xrt_session_and_native_compositor(log, xsi, *out_session); 1282 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to create session/compositor"); 1283 + 1255 1284 return oxr_session_populate_egl(log, sys, egl, *out_session); 1256 1285 } 1257 1286 #endif ··· 1268 1297 return oxr_error(log, XR_ERROR_GRAPHICS_REQUIREMENTS_CALL_MISSING, 1269 1298 "Has not called xrGetD3D11GraphicsRequirementsKHR"); 1270 1299 } 1271 - XrResult result = oxr_d3d11_check_device(log, sys, d3d11->device); 1300 + ret = oxr_d3d11_check_device(log, sys, d3d11->device); 1272 1301 1273 - if (!XR_SUCCEEDED(result)) { 1274 - return result; 1302 + if (!XR_SUCCEEDED(ret)) { 1303 + return ret; 1275 1304 } 1276 1305 1306 + ret = oxr_session_allocate_and_init(log, sys, OXR_SESSION_GRAPHICS_EXT_D3D11, out_session); 1307 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to allocate session"); 1277 1308 1278 - OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_D3D11, *out_session); 1279 - OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session); 1309 + ret = oxr_create_xrt_session_and_native_compositor(log, xsi, *out_session); 1310 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to create session/compositor"); 1311 + 1280 1312 return oxr_session_populate_d3d11(log, sys, d3d11, *out_session); 1281 1313 } 1282 1314 #endif ··· 1293 1325 return oxr_error(log, XR_ERROR_GRAPHICS_REQUIREMENTS_CALL_MISSING, 1294 1326 "Has not called xrGetD3D12GraphicsRequirementsKHR"); 1295 1327 } 1296 - XrResult result = oxr_d3d12_check_device(log, sys, d3d12->device); 1328 + ret = oxr_d3d12_check_device(log, sys, d3d12->device); 1297 1329 1298 - if (!XR_SUCCEEDED(result)) { 1299 - return result; 1330 + if (!XR_SUCCEEDED(ret)) { 1331 + return ret; 1300 1332 } 1301 1333 1334 + ret = oxr_session_allocate_and_init(log, sys, OXR_SESSION_GRAPHICS_EXT_D3D12, out_session); 1335 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to allocate session"); 1302 1336 1303 - OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_D3D12, *out_session); 1304 - OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session); 1337 + ret = oxr_create_xrt_session_and_native_compositor(log, xsi, *out_session); 1338 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to create session/compositor"); 1339 + 1305 1340 return oxr_session_populate_d3d12(log, sys, d3d12, *out_session); 1306 1341 } 1307 1342 #endif ··· 1315 1350 1316 1351 #ifdef OXR_HAVE_MND_headless 1317 1352 if (sys->inst->extensions.MND_headless) { 1318 - OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_HEADLESS, *out_session); 1353 + 1354 + ret = oxr_session_allocate_and_init(log, sys, OXR_SESSION_GRAPHICS_EXT_HEADLESS, out_session); 1355 + OXR_CHECK_XR_SUCCESS(log, ret, "Failed to allocate session"); 1356 + 1319 1357 (*out_session)->compositor = NULL; 1320 1358 (*out_session)->create_swapchain = NULL; 1321 1359