0

Im creating some OpenXR Layer for ValveIndex HMD. As standard specifies i have created .dll with exported entry point (xrNegotiateLoaderApiLayerInterface function).

I also delegated OpenXR functions to my own implementations inside "_xrCreateApiLayerInstance" (where the XrInstance is created for Layers??? probably im doing something wrong exactly there):

static XrResult XRAPI_PTR
_xrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
                          const XrApiLayerCreateInfo *apiLayerInfo,
                          XrInstance *instance)
{
    _nextXrGetInstanceProcAddr = apiLayerInfo->nextInfo->nextGetInstanceProcAddr;
    XrResult result;


    result = apiLayerInfo->nextInfo->nextCreateApiLayerInstance(info, apiLayerInfo, instance);
    if (XR_FAILED(result)) {
        log << "Failed to create instance for next layer (?)" << std::endl;
        return result;
    }

    result = _nextXrGetInstanceProcAddr(*instance, "xrEndFrame", (PFN_xrVoidFunction *)&_nextxrEndFrame);
    if (XR_FAILED(result)) {
        log << "Failed to load xrEndFrame" << std::endl;
        return result;
    }

    result = _nextXrGetInstanceProcAddr(*instance, "xrWaitSwapchainImage",
                                        (PFN_xrVoidFunction *)&_nextxrWaitSwapchainImage);
    if (XR_FAILED(result)) {
        log << "Failed to load xrWaitSwapchainImage" << std::endl;
        return result;
    }

    instanceInfo = *info;
    xrInstance = *instance;
    return result;
}

...but for delegating purposes this function works good, and OpenXR is delegating xrEndFrame to my implementation, where i can for example print frames timestamps. (xrWaitSwapchainImage is also delegated to my implementation).

The problem occures when i try to do anything with provided "XrSwapchain" handle in my overwritten xrWaitSwapchainImage. This is the function:

static XRAPI_ATTR XrResult XRAPI_CALL
_xrWaitSwapchainImage(XrSwapchain swapchain, const XrSwapchainImageWaitInfo* waitInfo)
{
    // Get the number of swapchain images
    if (swapchain) {
        uint32_t imageCount;
        XrResult result = xrEnumerateSwapchainImages(swapchain, 0, &imageCount, nullptr);
        if (result != XR_SUCCESS) {
            log << "[ERROR] xrEnumerateSwapchainImages count." << std::endl;
            //return XR_ERROR_RUNTIME_FAILURE;
        }
    }
    XrResult res = _nextxrWaitSwapchainImage(swapchain, waitInfo);
    return res;
}

And this is the error I constantly get:

Error [GENERAL | xrEnumerateSwapchainImages | OpenXR-Loader] : No active XrInstance handle.

I tried to save XrInstance pointer from "_xrCreateApiLayerInstance" function, and use it to get swapchain handles that way, but i suppose "that" XrInstance handle belongs to other layers/apps and it is also not working.

So my questions are:

a) How to handle that XrInstance bug?

b) Maybe i'm using XrSwapchain wrongly - so how to use it properly?

I tried different ways to get valid handle to XrInstance but no success. In addition, i tried to use other handler types that were passed to the overwritten functions, also without success.

Xoliper
  • 1
  • 2
  • Ok i probably solved the issue. Function "_xrCreateApiLayerInstance" will be called two times by the runtime, in first run we can create XrInstance, in second run we can do stuff like in the posted code. – Xoliper Jul 03 '23 at 15:30

0 Answers0