wined3d: Move memory allocation into a separate function.