RavEngine
Loading...
Searching...
No Matches
NvFlowLoader.h
1#pragma once
2
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions
5// are met:
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above copyright
9// notice, this list of conditions and the following disclaimer in the
10// documentation and/or other materials provided with the distribution.
11// * Neither the name of NVIDIA CORPORATION nor the names of its
12// contributors may be used to endorse or promote products derived
13// from this software without specific prior written permission.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
16// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26//
27// Copyright (c) 2014-2022 NVIDIA Corporation. All rights reserved.
28
29#ifndef NV_FLOW_LOADER_H
30#define NV_FLOW_LOADER_H
31
32#if defined(_WIN32)
33#include <Windows.h>
34static void* NvFlowLoadLibrary(const char* winName, const char* linuxName)
35{
36 return (void*)LoadLibraryA(winName);
37}
38static void* NvFlowGetProcAddress(void* module, const char* name)
39{
40 return GetProcAddress((HMODULE)module, name);
41}
42static void NvFlowFreeLibrary(void* module)
43{
44 FreeLibrary((HMODULE)module);
45}
46static const char* NvFlowLoadLibraryError()
47{
48 DWORD lastError = GetLastError();
49 static char buf[1024];
50 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL);
51 return buf;
52}
53#else
54#include <dlfcn.h>
55static void* NvFlowLoadLibrary(const char* winName, const char* linuxName)
56{
57 void* module = dlopen(linuxName, RTLD_NOW);
58 //if (!module)
59 //{
60 // fprintf(stderr, "Module %s failed to load : %s\n", linuxName, dlerror());
61 //}
62 return module;
63}
64static void* NvFlowGetProcAddress(void* module, const char* name)
65{
66 return dlsym(module, name);
67}
68static void NvFlowFreeLibrary(void* module)
69{
70 dlclose(module);
71}
72static const char* NvFlowLoadLibraryError()
73{
74 return dlerror();
75}
76#endif
77
78#include "NvFlowExt.h"
79
81{
82 void* module_nvflow;
83 void* module_nvflowext;
84
85 NvFlowOpList opList;
86 NvFlowExtOpList extOpList;
87 NvFlowGridInterface gridInterface;
88 NvFlowGridParamsInterface gridParamsInterface;
89 NvFlowContextOptInterface contextOptInterface;
90 NvFlowDeviceInterface deviceInterface;
91};
92
93static void NvFlowLoaderInitDeviceAPI(NvFlowLoader* ptr, void(*printError)(const char* str, void* userdata), void* userdata, NvFlowContextApi deviceAPI)
94{
95 NvFlowReflectClear(ptr, sizeof(NvFlowLoader));
96
98 ptr->module_nvflow = NvFlowLoadLibrary("nvflow.dll", "libnvflow.so");
99 if (ptr->module_nvflow)
100 {
101 PFN_NvFlowGetOpList getOpList = (PFN_NvFlowGetOpList)NvFlowGetProcAddress(ptr->module_nvflow, "NvFlowGetOpList");
102
103 if (getOpList) { NvFlowOpList_duplicate(&ptr->opList, getOpList()); }
104 }
105 else if (printError)
106 {
107 printError(NvFlowLoadLibraryError(), userdata);
108 }
109
110 ptr->module_nvflowext = NvFlowLoadLibrary("nvflowext.dll", "libnvflowext.so");
111 if (ptr->module_nvflowext)
112 {
113 PFN_NvFlowGetExtOpList getExtOpList = (PFN_NvFlowGetExtOpList)NvFlowGetProcAddress(ptr->module_nvflowext, "NvFlowGetExtOpList");
114 PFN_NvFlowGetGridInterface getGridInterface = (PFN_NvFlowGetGridInterface)NvFlowGetProcAddress(ptr->module_nvflowext, "NvFlowGetGridInterface");
115 PFN_NvFlowGetGridParamsInterface getGridParamsInterface = (PFN_NvFlowGetGridParamsInterface)NvFlowGetProcAddress(ptr->module_nvflowext, "NvFlowGetGridParamsInterface");
116 PFN_NvFlowGetContextOptInterface getContextOptInterface = (PFN_NvFlowGetContextOptInterface)NvFlowGetProcAddress(ptr->module_nvflowext, "NvFlowGetContextOptInterface");
117 PFN_NvFlowGetDeviceInterface getDeviceInterface = (PFN_NvFlowGetDeviceInterface)NvFlowGetProcAddress(ptr->module_nvflowext, "NvFlowGetDeviceInterface");
118
119 if (getExtOpList) { NvFlowExtOpList_duplicate(&ptr->extOpList, getExtOpList()); }
120 if (getGridInterface) { NvFlowGridInterface_duplicate(&ptr->gridInterface, getGridInterface()); }
121 if (getGridParamsInterface) { NvFlowGridParamsInterface_duplicate(&ptr->gridParamsInterface, getGridParamsInterface()); }
122 if (getContextOptInterface) { NvFlowContextOptInterface_duplicate(&ptr->contextOptInterface, getContextOptInterface()); }
123 if (getDeviceInterface) { NvFlowDeviceInterface_duplicate(&ptr->deviceInterface, getDeviceInterface(deviceAPI)); }
124 }
125 else if (printError)
126 {
127 printError(NvFlowLoadLibraryError(), userdata);
128 }
129}
130
131static void NvFlowLoaderInit(NvFlowLoader* ptr, void(*printError)(const char* str, void* userdata), void* userdata)
132{
133 NvFlowLoaderInitDeviceAPI(ptr, printError, userdata, eNvFlowContextApi_vulkan);
134}
135
136static void NvFlowLoaderDestroy(NvFlowLoader* ptr)
137{
138 NvFlowFreeLibrary(ptr->module_nvflow);
139 NvFlowFreeLibrary(ptr->module_nvflowext);
140}
141
142#endif
Definition NvFlowExt.h:2933
Definition NvFlowExt.h:3031
********************************* NvFlowExtOpList ***************************************
Definition NvFlowExt.h:2381
Definition NvFlowExt.h:2671
Definition NvFlowExt.h:2815
Definition NvFlowLoader.h:81
********************************* NvFlowOpList ***************************************
Definition NvFlow.h:1007