The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

st/oxr: Wire in D3D12 support

+332 -4
+6
src/xrt/state_trackers/oxr/CMakeLists.txt
··· 80 80 target_sources(st_oxr PRIVATE oxr_session_gfx_d3d11.c oxr_swapchain_d3d11.c oxr_d3d11.cpp) 81 81 endif() 82 82 83 + if(XRT_HAVE_D3D12) 84 + target_compile_definitions(st_oxr PRIVATE XR_USE_GRAPHICS_API_D3D12) 85 + target_sources(st_oxr PRIVATE oxr_session_gfx_d3d12.c oxr_swapchain_d3d12.c oxr_d3d12.cpp) 86 + target_link_libraries(st_oxr PRIVATE aux_d3d) 87 + endif() 88 + 83 89 if(ANDROID) 84 90 target_compile_definitions(st_oxr PRIVATE XR_USE_PLATFORM_ANDROID) 85 91 target_sources(st_oxr PRIVATE oxr_session_gfx_gles_android.c)
+9
src/xrt/state_trackers/oxr/oxr_api_funcs.h
··· 245 245 XrGraphicsRequirementsD3D11KHR *graphicsRequirements); 246 246 #endif // XR_USE_GRAPHICS_API_D3D11 247 247 248 + #ifdef XR_USE_GRAPHICS_API_D3D12 249 + 250 + //! OpenXR API function @ep{xrGetD3D11GraphicsRequirementsKHR} 251 + XRAPI_ATTR XrResult XRAPI_CALL 252 + oxr_xrGetD3D12GraphicsRequirementsKHR(XrInstance instance, 253 + XrSystemId systemId, 254 + XrGraphicsRequirementsD3D12KHR *graphicsRequirements); 255 + #endif // XR_USE_GRAPHICS_API_D3D12 256 + 248 257 /* 249 258 * 250 259 * oxr_api_session.c
+4
src/xrt/state_trackers/oxr/oxr_api_negotiate.c
··· 274 274 ENTRY_IF_EXT(xrGetD3D11GraphicsRequirementsKHR, KHR_D3D11_enable); 275 275 #endif // OXR_HAVE_KHR_D3D11_enable 276 276 277 + #ifdef OXR_HAVE_KHR_D3D12_enable 278 + ENTRY_IF_EXT(xrGetD3D12GraphicsRequirementsKHR, KHR_D3D12_enable); 279 + #endif // OXR_HAVE_KHR_D3D12_enable 280 + 277 281 /* 278 282 * Not logging here because there's no need to loudly advertise 279 283 * which extensions the loader knows about (it calls this on
+27
src/xrt/state_trackers/oxr/oxr_api_system.c
··· 444 444 return oxr_d3d11_get_requirements(&log, sys, graphicsRequirements); 445 445 } 446 446 #endif 447 + 448 + 449 + /* 450 + * 451 + * D3D12 452 + * 453 + */ 454 + 455 + #ifdef XR_USE_GRAPHICS_API_D3D12 456 + 457 + XrResult 458 + oxr_xrGetD3D12GraphicsRequirementsKHR(XrInstance instance, 459 + XrSystemId systemId, 460 + XrGraphicsRequirementsD3D12KHR *graphicsRequirements) 461 + { 462 + 463 + struct oxr_instance *inst; 464 + struct oxr_logger log; 465 + OXR_VERIFY_INSTANCE_AND_INIT_LOG(&log, instance, inst, "xrGetD3D12GraphicsRequirementsKHR"); 466 + OXR_VERIFY_ARG_TYPE_AND_NOT_NULL(&log, graphicsRequirements, XR_TYPE_GRAPHICS_REQUIREMENTS_D3D12_KHR); 467 + OXR_VERIFY_SYSTEM_AND_GET(&log, inst, systemId, sys); 468 + 469 + sys->gotten_requirements = true; 470 + 471 + return oxr_d3d12_get_requirements(&log, sys, graphicsRequirements); 472 + } 473 + #endif
+5 -1
src/xrt/state_trackers/oxr/oxr_api_verify.h
··· 291 291 oxr_verify_XrGraphicsBindingD3D11KHR(struct oxr_logger *, const XrGraphicsBindingD3D11KHR *); 292 292 #endif // defined(XR_USE_GRAPHICS_API_D3D11) 293 293 294 + #if defined(XR_USE_GRAPHICS_API_D3D12) 295 + XrResult 296 + oxr_verify_XrGraphicsBindingD3D12KHR(struct oxr_logger *, const XrGraphicsBindingD3D12KHR *); 297 + #endif // defined(XR_USE_GRAPHICS_API_D3D12) 298 + 294 299 #ifdef XR_EXT_dpad_binding 295 300 XrResult 296 301 oxr_verify_XrInteractionProfileDpadBindingEXT(struct oxr_logger *, 297 302 const XrInteractionProfileDpadBindingEXT *, 298 303 const char *error_prefix); 299 304 #endif // XR_EXT_dpad_binding 300 - 301 305 302 306 /*! 303 307 * @}
+59
src/xrt/state_trackers/oxr/oxr_d3d12.cpp
··· 1 + // Copyright 2021-2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Holds D3D12 related functions that didn't fit somewhere else. 6 + * @author Ryan Pavlik <ryan.pavlik@collabora.com> 7 + * @ingroup oxr_main 8 + */ 9 + 10 + #include "util/u_misc.h" 11 + #include "util/u_debug.h" 12 + #include "d3d/d3d_d3d12_helpers.hpp" 13 + 14 + #include "oxr_objects.h" 15 + #include "oxr_logger.h" 16 + 17 + #include <dxgi1_6.h> 18 + #include <d3d12.h> 19 + #include <wil/com.h> 20 + #include <wil/result.h> 21 + 22 + #include <stdio.h> 23 + #include <string.h> 24 + #include <stdlib.h> 25 + 26 + #define DEFAULT_CATCH(MSG) \ 27 + catch (wil::ResultException const &e) \ 28 + { \ 29 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, MSG ": %s", e.what()); \ 30 + } \ 31 + catch (std::exception const &e) \ 32 + { \ 33 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, MSG ": %s", e.what()); \ 34 + } \ 35 + catch (...) \ 36 + { \ 37 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, MSG); \ 38 + } 39 + 40 + using namespace xrt::auxiliary::d3d; 41 + 42 + XrResult 43 + oxr_d3d12_get_requirements(struct oxr_logger *log, 44 + struct oxr_system *sys, 45 + XrGraphicsRequirementsD3D12KHR *graphicsRequirements) 46 + { 47 + return oxr_d3d_get_requirements(log, sys, &graphicsRequirements->adapterLuid, 48 + &graphicsRequirements->minFeatureLevel); 49 + } 50 + 51 + XrResult 52 + oxr_d3d12_check_device(struct oxr_logger *log, struct oxr_system *sys, ID3D12Device *device) 53 + { 54 + try { 55 + LUID luid = device->GetAdapterLuid(); 56 + return oxr_d3d_check_luid(log, sys, &luid); 57 + } 58 + DEFAULT_CATCH(" failure checking adapter LUID") 59 + }
+38 -1
src/xrt/state_trackers/oxr/oxr_objects.h
··· 1256 1256 1257 1257 /* 1258 1258 * 1259 + * D3D12, located in various files. 1260 + * 1261 + */ 1262 + 1263 + #ifdef XR_USE_GRAPHICS_API_D3D12 1264 + 1265 + XrResult 1266 + oxr_d3d12_get_requirements(struct oxr_logger *log, 1267 + struct oxr_system *sys, 1268 + XrGraphicsRequirementsD3D12KHR *graphicsRequirements); 1269 + 1270 + /** 1271 + * @brief Check to ensure the device provided at session create matches the LUID we returned earlier. 1272 + * 1273 + * @return XR_SUCCESS if the device matches the LUID 1274 + */ 1275 + XrResult 1276 + oxr_d3d12_check_device(struct oxr_logger *log, struct oxr_system *sys, ID3D12Device *device); 1277 + 1278 + 1279 + XrResult 1280 + oxr_session_populate_d3d12(struct oxr_logger *log, 1281 + struct oxr_system *sys, 1282 + XrGraphicsBindingD3D12KHR const *next, 1283 + struct oxr_session *sess); 1284 + 1285 + XrResult 1286 + oxr_swapchain_d3d12_create(struct oxr_logger *, 1287 + struct oxr_session *sess, 1288 + const XrSwapchainCreateInfo *, 1289 + struct oxr_swapchain **out_swapchain); 1290 + 1291 + #endif 1292 + 1293 + /* 1294 + * 1259 1295 * Structs 1260 1296 * 1261 1297 */ ··· 1349 1385 } vk; 1350 1386 1351 1387 #endif 1352 - #ifdef XR_USE_GRAPHICS_API_D3D11 1388 + 1389 + #if defined(XR_USE_GRAPHICS_API_D3D11) || defined(XR_USE_GRAPHICS_API_D3D12) 1353 1390 LUID suggested_d3d_luid; 1354 1391 bool suggested_d3d_luid_valid; 1355 1392 #endif
+24 -1
src/xrt/state_trackers/oxr/oxr_session.c
··· 771 771 XrGraphicsBindingD3D11KHR const *d3d11 = 772 772 OXR_GET_INPUT_FROM_CHAIN(createInfo, XR_TYPE_GRAPHICS_BINDING_D3D11_KHR, XrGraphicsBindingD3D11KHR); 773 773 if (d3d11 != NULL) { 774 - OXR_VERIFY_ARG_NOT_NULL(log, d3d11->device); 774 + // we know the fields of this struct are OK by now since they were checked with XrSessionCreateInfo 775 775 776 776 if (!sys->gotten_requirements) { 777 777 return oxr_error(log, XR_ERROR_GRAPHICS_REQUIREMENTS_CALL_MISSING, ··· 787 787 OXR_SESSION_ALLOCATE_AND_INIT(log, sys, *out_session); 788 788 OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session); 789 789 return oxr_session_populate_d3d11(log, sys, d3d11, *out_session); 790 + } 791 + #endif 792 + 793 + #ifdef XR_USE_GRAPHICS_API_D3D12 794 + XrGraphicsBindingD3D12KHR const *d3d12 = 795 + OXR_GET_INPUT_FROM_CHAIN(createInfo, XR_TYPE_GRAPHICS_BINDING_D3D12_KHR, XrGraphicsBindingD3D12KHR); 796 + if (d3d12 != NULL) { 797 + // we know the fields of this struct are OK by now since they were checked with XrSessionCreateInfo 798 + 799 + if (!sys->gotten_requirements) { 800 + return oxr_error(log, XR_ERROR_GRAPHICS_REQUIREMENTS_CALL_MISSING, 801 + "Has not called xrGetD3D12GraphicsRequirementsKHR"); 802 + } 803 + XrResult result = oxr_d3d12_check_device(log, sys, d3d12->device); 804 + 805 + if (!XR_SUCCEEDED(result)) { 806 + return result; 807 + } 808 + 809 + 810 + OXR_SESSION_ALLOCATE_AND_INIT(log, sys, *out_session); 811 + OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session); 812 + return oxr_session_populate_d3d12(log, sys, d3d12, *out_session); 790 813 } 791 814 #endif 792 815 /*
+44
src/xrt/state_trackers/oxr/oxr_session_gfx_d3d12.c
··· 1 + // Copyright 2018-2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Holds D3D12 specific session functions. 6 + * @author Ryan Pavlik <ryan.pavlik@collabora.com> 7 + * @author Jakob Bornecrantz <jakob@collabora.com> 8 + * @ingroup oxr_main 9 + * @ingroup comp_client 10 + */ 11 + 12 + #include <stdlib.h> 13 + 14 + #include "util/u_misc.h" 15 + 16 + #include "xrt/xrt_instance.h" 17 + #include "xrt/xrt_gfx_d3d12.h" 18 + 19 + #include "oxr_objects.h" 20 + #include "oxr_logger.h" 21 + #include "oxr_two_call.h" 22 + #include "oxr_handle.h" 23 + 24 + 25 + XrResult 26 + oxr_session_populate_d3d12(struct oxr_logger *log, 27 + struct oxr_system *sys, 28 + XrGraphicsBindingD3D12KHR const *next, 29 + struct oxr_session *sess) 30 + { 31 + struct xrt_compositor_native *xcn = sess->xcn; 32 + struct xrt_compositor_d3d12 *xcd3d = xrt_gfx_d3d12_provider_create( // 33 + xcn, // 34 + next->device, next->queue); // 35 + 36 + if (xcd3d == NULL) { 37 + return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED, "Failed to create a d3d12 client compositor"); 38 + } 39 + 40 + sess->compositor = &xcd3d->base; 41 + sess->create_swapchain = oxr_swapchain_d3d12_create; 42 + 43 + return XR_SUCCESS; 44 + }
+86
src/xrt/state_trackers/oxr/oxr_swapchain_d3d12.c
··· 1 + // Copyright 2019-2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Holds D3D12 swapchain related functions. 6 + * @author Ryan Pavlik <ryan.pavlik@collabora.com> 7 + * @author Jakob Bornecrantz <jakob@collabora.com> 8 + * @ingroup oxr_main 9 + * @ingroup comp_client 10 + */ 11 + 12 + #include <stdlib.h> 13 + 14 + #include "xrt/xrt_gfx_d3d12.h" 15 + #include "util/u_debug.h" 16 + 17 + #include "oxr_objects.h" 18 + #include "oxr_logger.h" 19 + #include "oxr_api_verify.h" 20 + 21 + 22 + static XrResult 23 + oxr_swapchain_d3d12_destroy(struct oxr_logger *log, struct oxr_swapchain *sc) 24 + { 25 + // Release any waited image. 26 + if (sc->waited.yes) { 27 + sc->release_image(log, sc, NULL); 28 + } 29 + 30 + // Release any acquired images. 31 + XrSwapchainImageWaitInfo waitInfo = {0}; 32 + while (!u_index_fifo_is_empty(&sc->acquired.fifo)) { 33 + sc->wait_image(log, sc, &waitInfo); 34 + sc->release_image(log, sc, NULL); 35 + } 36 + 37 + // Drop our reference, does NULL checking. 38 + xrt_swapchain_reference(&sc->swapchain, NULL); 39 + 40 + return XR_SUCCESS; 41 + } 42 + 43 + static XrResult 44 + oxr_swapchain_d3d12_enumerate_images(struct oxr_logger *log, 45 + struct oxr_swapchain *sc, 46 + uint32_t count, 47 + XrSwapchainImageBaseHeader *images) 48 + { 49 + struct xrt_swapchain_d3d12 *xscd3d = (struct xrt_swapchain_d3d12 *)sc->swapchain; 50 + XrSwapchainImageD3D12KHR *d3d_imgs = (XrSwapchainImageD3D12KHR *)images; 51 + 52 + for (uint32_t i = 0; i < count; i++) { 53 + d3d_imgs[i].texture = xscd3d->images[i]; 54 + } 55 + 56 + return oxr_session_success_result(sc->sess); 57 + } 58 + 59 + XrResult 60 + oxr_swapchain_d3d12_create(struct oxr_logger *log, 61 + struct oxr_session *sess, 62 + const XrSwapchainCreateInfo *createInfo, 63 + struct oxr_swapchain **out_swapchain) 64 + { 65 + struct oxr_swapchain *sc; 66 + XrResult ret; 67 + 68 + OXR_VERIFY_SWAPCHAIN_USAGE_FLAGS_NOT_MUTUALLY_EXCLUSIVE(log, createInfo->usageFlags, 69 + XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT, 70 + XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); 71 + OXR_VERIFY_SWAPCHAIN_USAGE_FLAGS_NOT_MUTUALLY_EXCLUSIVE(log, createInfo->usageFlags, 72 + XR_SWAPCHAIN_USAGE_UNORDERED_ACCESS_BIT, 73 + XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); 74 + 75 + ret = oxr_create_swapchain(log, sess, createInfo, &sc); 76 + if (ret != XR_SUCCESS) { 77 + return ret; 78 + } 79 + 80 + sc->destroy = oxr_swapchain_d3d12_destroy; 81 + sc->enumerate_images = oxr_swapchain_d3d12_enumerate_images; 82 + 83 + *out_swapchain = sc; 84 + 85 + return XR_SUCCESS; 86 + }
+1 -1
src/xrt/state_trackers/oxr/oxr_system.c
··· 103 103 sys->vulkan_enable2_instance = VK_NULL_HANDLE; 104 104 sys->suggested_vulkan_physical_device = VK_NULL_HANDLE; 105 105 #endif 106 - #ifdef XR_USE_GRAPHICS_API_D3D11 106 + #if defined(XR_USE_GRAPHICS_API_D3D11) || defined(XR_USE_GRAPHICS_API_D3D12) 107 107 U_ZERO(&(sys->suggested_d3d_luid)); 108 108 sys->suggested_d3d_luid_valid = false; 109 109 #endif
+29
src/xrt/state_trackers/oxr/oxr_verify.c
··· 509 509 } 510 510 #endif // XR_USE_GRAPHICS_API_D3D11 511 511 512 + 513 + #if defined(XR_USE_GRAPHICS_API_D3D12) 514 + XrGraphicsBindingD3D12KHR const *d3d12 = 515 + OXR_GET_INPUT_FROM_CHAIN(createInfo, XR_TYPE_GRAPHICS_BINDING_D3D12_KHR, XrGraphicsBindingD3D12KHR); 516 + if (d3d12 != NULL) { 517 + OXR_VERIFY_EXTENSION(log, inst, KHR_D3D12_enable); 518 + return oxr_verify_XrGraphicsBindingD3D12KHR(log, d3d12); 519 + } 520 + #endif // XR_USE_GRAPHICS_API_D3D12 521 + 512 522 /* 513 523 * Add any new graphics binding structs here - before the headless 514 524 * check. (order for non-headless checks not specified in standard.) ··· 633 643 return XR_SUCCESS; 634 644 } 635 645 #endif // defined(XR_USE_GRAPHICS_API_D3D11) 646 + 647 + #if defined(XR_USE_GRAPHICS_API_D3D12) 648 + XrResult 649 + oxr_verify_XrGraphicsBindingD3D12KHR(struct oxr_logger *log, const XrGraphicsBindingD3D12KHR *next) 650 + { 651 + if (next->type != XR_TYPE_GRAPHICS_BINDING_D3D12_KHR) { 652 + return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, "Graphics binding has invalid type"); 653 + } 654 + if (next->device == NULL) { 655 + return oxr_error(log, XR_ERROR_GRAPHICS_DEVICE_INVALID, 656 + "XrGraphicsBindingD3D12KHR::device cannot be NULL"); 657 + } 658 + if (next->queue == NULL) { 659 + // not specified in spec nor cts, so assume it's this 660 + return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, "XrGraphicsBindingD3D12KHR::queue cannot be NULL"); 661 + } 662 + return XR_SUCCESS; 663 + } 664 + #endif // defined(XR_USE_GRAPHICS_API_D3D12) 636 665 637 666 #ifdef XR_EXT_dpad_binding 638 667 XrResult