| 16 | using namespace std::chrono_literals; |
| 17 | |
| 18 | ovrResult ovrHmdStruct::InitSession(XrInstance instance) |
| 19 | { |
| 20 | XR_FUNCTION(instance, GetD3D11GraphicsRequirementsKHR); |
| 21 | |
| 22 | memset(FrameStats, 0, sizeof(FrameStats)); |
| 23 | for (int i = 0; i < ovrMaxProvidedFrameStats; i++) |
| 24 | FrameStats[i].type = XR_TYPE_FRAME_STATE; |
| 25 | CurrentFrame = FrameStats; |
| 26 | Instance = instance; |
| 27 | TrackingOrigin = ovrTrackingOrigin_EyeLevel; |
| 28 | SystemProperties = XR_TYPE(SYSTEM_PROPERTIES); |
| 29 | SystemColorSpace = XR_TYPE(SYSTEM_COLOR_SPACE_PROPERTIES_FB); |
| 30 | |
| 31 | // Initialize view structures |
| 32 | for (int i = 0; i < ovrEye_Count; i++) |
| 33 | { |
| 34 | ViewConfigs[i] = XR_TYPE(VIEW_CONFIGURATION_VIEW); |
| 35 | ViewFov[i] = XR_TYPE(VIEW_CONFIGURATION_VIEW_FOV_EPIC); |
| 36 | ViewPoses[i] = XR_TYPE(VIEW); |
| 37 | ViewConfigs[i].next = &ViewFov[i]; |
| 38 | } |
| 39 | |
| 40 | XrSystemGetInfo systemInfo = XR_TYPE(SYSTEM_GET_INFO); |
| 41 | systemInfo.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY; |
| 42 | CHK_XR(xrGetSystem(Instance, &systemInfo, &System)); |
| 43 | if (Runtime::Get().ColorSpace) |
| 44 | SystemProperties.next = &SystemColorSpace; |
| 45 | CHK_XR(xrGetSystemProperties(Instance, System, &SystemProperties)); |
| 46 | |
| 47 | uint32_t numViews; |
| 48 | CHK_XR(xrEnumerateViewConfigurationViews(Instance, System, XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, ovrEye_Count, &numViews, ViewConfigs)); |
| 49 | assert(numViews == ovrEye_Count); |
| 50 | |
| 51 | XrGraphicsRequirementsD3D11KHR graphicsReq = XR_TYPE(GRAPHICS_REQUIREMENTS_D3D11_KHR); |
| 52 | CHK_XR(GetD3D11GraphicsRequirementsKHR(Instance, System, &graphicsReq)); |
| 53 | |
| 54 | // Copy the LUID into the structure |
| 55 | static_assert(sizeof(graphicsReq.adapterLuid) == sizeof(ovrGraphicsLuid), |
| 56 | "The adapter LUID needs to fit in ovrGraphicsLuid"); |
| 57 | memcpy(&Adapter, &graphicsReq.adapterLuid, sizeof(ovrGraphicsLuid)); |
| 58 | |
| 59 | // Create a temporary session to retrieve the headset field-of-view |
| 60 | Microsoft::WRL::ComPtr<IDXGIFactory1> pFactory = NULL; |
| 61 | if (Runtime::Get().MinorVersion >= 17 && Runtime::Get().Supports(XR_EPIC_VIEW_CONFIGURATION_FOV_EXTENSION_NAME) && |
| 62 | !Runtime::Get().UseHack(Runtime::HACK_FORCE_FOV_FALLBACK)) |
| 63 | { |
| 64 | for (int i = 0; i < ovrEye_Count; i++) |
| 65 | { |
| 66 | ViewPoses[i].fov = ViewFov[i].recommendedFov; |
| 67 | ViewPoses[i].pose = XR::Posef::Identity(); |
| 68 | } |
| 69 | } |
| 70 | else if (SUCCEEDED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))) |
| 71 | { |
| 72 | Microsoft::WRL::ComPtr<IDXGIAdapter1> pAdapter; |
| 73 | Microsoft::WRL::ComPtr<ID3D11Device> pDevice; |
| 74 | |
| 75 | for (UINT i = 0; pFactory->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i) |
no test coverage detected