+static AVOnce functions_loaded = AV_ONCE_INIT;
+
+static PFN_CREATE_DXGI_FACTORY mCreateDXGIFactory;
+static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
+
+static av_cold void load_functions(void)
+{
+#if HAVE_LOADLIBRARY
+ // We let these "leak" - this is fine, as unloading has no great benefit, and
+ // Windows will mark a DLL as loaded forever if its internal refcount overflows
+ // from too many LoadLibrary calls.
+ HANDLE d3dlib, dxgilib;
+
+ d3dlib = LoadLibrary("d3d11.dll");
+ dxgilib = LoadLibrary("dxgi.dll");
+ if (!d3dlib || !dxgilib)
+ return;
+
+ mD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE) GetProcAddress(d3dlib, "D3D11CreateDevice");
+ mCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY) GetProcAddress(dxgilib, "CreateDXGIFactory");
+#else
+ // In UWP (which lacks LoadLibrary), CreateDXGIFactory isn't available,
+ // only CreateDXGIFactory1
+ mD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE) D3D11CreateDevice;
+ mCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY) CreateDXGIFactory1;
+#endif
+}
+