| 128 | } |
| 129 | |
| 130 | OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateTextureSwapChainDX(ovrSession session, |
| 131 | IUnknown* d3dPtr, |
| 132 | const ovrTextureSwapChainDesc* desc, |
| 133 | ovrTextureSwapChain* out_TextureSwapChain) |
| 134 | { |
| 135 | REV_TRACE(ovr_CreateTextureSwapChainDX); |
| 136 | |
| 137 | if (!session) |
| 138 | return ovrError_InvalidSession; |
| 139 | |
| 140 | if (!d3dPtr || !desc || !out_TextureSwapChain || desc->Type == ovrTexture_2D_External) |
| 141 | return ovrError_InvalidParameter; |
| 142 | |
| 143 | ComPtr<ID3D11Device> pDevice = nullptr; |
| 144 | ComPtr<ID3D12CommandQueue> pQueue = nullptr; |
| 145 | if (FAILED(d3dPtr->QueryInterface(IID_PPV_ARGS(&pDevice)))) |
| 146 | { |
| 147 | if (FAILED(d3dPtr->QueryInterface(IID_PPV_ARGS(&pQueue)))) |
| 148 | return ovrError_InvalidParameter; |
| 149 | } |
| 150 | |
| 151 | if (!session->Session) |
| 152 | { |
| 153 | if (pDevice) |
| 154 | { |
| 155 | XR_FUNCTION(session->Instance, GetD3D11GraphicsRequirementsKHR); |
| 156 | XrGraphicsRequirementsD3D11KHR graphicsReq = XR_TYPE(GRAPHICS_REQUIREMENTS_D3D11_KHR); |
| 157 | CHK_XR(GetD3D11GraphicsRequirementsKHR(session->Instance, session->System, &graphicsReq)); |
| 158 | |
| 159 | if (pDevice->GetFeatureLevel() < graphicsReq.minFeatureLevel) |
| 160 | return ovrError_IncompatibleGPU; |
| 161 | |
| 162 | DetourTransactionBegin(); |
| 163 | DetourUpdateThread(GetCurrentThread()); |
| 164 | // Hook D3D11 functions so we can ensure NULL descriptors keep working on typeless formats |
| 165 | // This fixes Echo Arena, among others. |
| 166 | DetourVirtual(pDevice.Get(), 7, (PVOID*)&TrueCreateShaderResourceView, HookCreateShaderResourceView); |
| 167 | session->HookedFunctions.insert(std::make_pair((PVOID*)&TrueCreateShaderResourceView, HookCreateShaderResourceView)); |
| 168 | DetourVirtual(pDevice.Get(), 9, (PVOID*)&TrueCreateRenderTargetView, HookCreateRenderTargetView); |
| 169 | session->HookedFunctions.insert(std::make_pair((PVOID*)&TrueCreateRenderTargetView, HookCreateRenderTargetView)); |
| 170 | DetourTransactionCommit(); |
| 171 | |
| 172 | XrGraphicsBindingD3D11KHR graphicsBinding = XR_TYPE(GRAPHICS_BINDING_D3D11_KHR); |
| 173 | graphicsBinding.device = pDevice.Get(); |
| 174 | session->StartSession(&graphicsBinding); |
| 175 | } |
| 176 | else if (pQueue) |
| 177 | { |
| 178 | if (!Runtime::Get().Supports(XR_KHR_D3D12_ENABLE_EXTENSION_NAME)) |
| 179 | return ovrError_Unsupported; |
| 180 | |
| 181 | ComPtr<ID3D12Device> pDevice12 = nullptr; |
| 182 | if (FAILED(pQueue->GetDevice(IID_PPV_ARGS(&pDevice12)))) |
| 183 | return ovrError_RuntimeException; |
| 184 | |
| 185 | XR_FUNCTION(session->Instance, GetD3D12GraphicsRequirementsKHR); |
| 186 | XrGraphicsRequirementsD3D12KHR graphicsReq = XR_TYPE(GRAPHICS_REQUIREMENTS_D3D12_KHR); |
| 187 | CHK_XR(GetD3D12GraphicsRequirementsKHR(session->Instance, session->System, &graphicsReq)); |
no test coverage detected