1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
/*
* Copyright (c) 2014-2017, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include "loaderCodeGen.h"
#include "functionDefinitionExtract.h"
LoaderType gLoaderType = eLoaderTypeDynamicLink;
void genLoaderAppGraphCtx()
{
const unsigned int numFunctions = 12u;
const char* functionDefinitions[numFunctions] = {
"AppGraphCtx* AppGraphCtxCreate(int deviceID);",
"bool AppGraphCtxUpdateSize(AppGraphCtx* context, SDL_Window* window, bool fullscreen);",
"void AppGraphCtxReleaseRenderTarget(AppGraphCtx* context);",
"void AppGraphCtxRelease(AppGraphCtx* context);",
"void AppGraphCtxFrameStart(AppGraphCtx* context, AppGraphColor clearColor);",
"void AppGraphCtxFramePresent(AppGraphCtx* context, bool fullsync);",
"void AppGraphCtxWaitForFrames(AppGraphCtx* context, unsigned int maxFramesInFlight);",
"void AppGraphCtxProfileEnable(AppGraphCtx* context, bool enabled);",
"void AppGraphCtxProfileBegin(AppGraphCtx* context, const char* label);",
"void AppGraphCtxProfileEnd(AppGraphCtx* context, const char* label);",
"bool AppGraphCtxProfileGet(AppGraphCtx* context, const char** plabel, float* cpuTime, float* gpuTime, int index);",
"size_t AppGraphCtxDedicatedVideoMemory(AppGraphCtx* context);"
};
StrHeap strHeap = allocateStrHeap(functionDefinitions, numFunctions);
Function functions[numFunctions];
for (unsigned int functionIdx = 0u; functionIdx < numFunctions; functionIdx++)
{
functions[functionIdx] = genFunction(&strHeap, functionDefinitions[functionIdx]);
}
GenerateCodeParams genCodeParams = {};
genCodeParams.loaderType = gLoaderType;
genCodeParams.file = nullptr;
genCodeParams.functions = functions;
genCodeParams.numFunctions = numFunctions;
genCodeParams.filenameTmp = "appGraphCtxLoaderGenerated.tmp.h";
genCodeParams.filenameDst = "appGraphCtxLoaderGenerated.h";
genCodeParams.moduleNameUpperCase = "AppGraphCtx";
genCodeParams.moduleNameLowerCase = "appGraphCtx";
genCodeParams.instName = "gAppGraphCtxLoader";
genCodeParams.apiMarker = "APP_GRAPH_CTX_API";
fopen_s(&genCodeParams.file, genCodeParams.filenameTmp, "w");
generateCode(&genCodeParams);
fclose(genCodeParams.file);
freeStrHeap(&strHeap);
fileDiffAndWriteIfModified(&genCodeParams);
}
void genLoaderComputeContext()
{
const unsigned int numFunctions = 23u;
const char* functionDefinitions[numFunctions] = {
"ComputeContext* ComputeContextCreate(ComputeContextDesc* desc);",
"void ComputeContextUpdate(ComputeContext* context, ComputeContextDesc* desc);",
"void ComputeContextRelease(ComputeContext* context);",
"ComputeShader* ComputeShaderCreate(ComputeContext* context, const ComputeShaderDesc* desc);",
"void ComputeShaderRelease(ComputeShader* shader);",
"ComputeConstantBuffer* ComputeConstantBufferCreate(ComputeContext* context, const ComputeConstantBufferDesc* desc);",
"void ComputeConstantBufferRelease(ComputeConstantBuffer* constantBuffer);",
"void* ComputeConstantBufferMap(ComputeContext* context, ComputeConstantBuffer* constantBuffer);",
"void ComputeConstantBufferUnmap(ComputeContext* context, ComputeConstantBuffer* constantBuffer);",
"ComputeResource* ComputeResourceCreate(ComputeContext* context, const ComputeResourceDesc* desc);",
"void ComputeResourceUpdate(ComputeContext* context, ComputeResource* resource, const ComputeResourceDesc* desc);",
"void ComputeResourceRelease(ComputeResource* resource);",
"ComputeResourceRW* ComputeResourceRWCreate(ComputeContext* context, const ComputeResourceRWDesc* desc);",
"void ComputeResourceRWUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, const ComputeResourceRWDesc* desc);",
"void ComputeResourceRWRelease(ComputeResourceRW* resourceRW);",
"ComputeResource* ComputeResourceRWGetResource(ComputeResourceRW* resourceRW);",
"void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams* params);",
"ComputeContext* ComputeContextNvFlowContextCreate(NvFlowContext* flowContext);",
"void ComputeContextNvFlowContextUpdate(ComputeContext* computeContext, NvFlowContext* flowContext);",
"ComputeResource* ComputeResourceNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource);",
"void ComputeResourceNvFlowUpdate(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource);",
"ComputeResourceRW* ComputeResourceRWNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW);",
"void ComputeResourceRWNvFlowUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW);"
};
StrHeap strHeap = allocateStrHeap(functionDefinitions, numFunctions);
Function functions[numFunctions];
for (unsigned int functionIdx = 0u; functionIdx < numFunctions; functionIdx++)
{
functions[functionIdx] = genFunction(&strHeap, functionDefinitions[functionIdx]);
}
GenerateCodeParams genCodeParams = {};
genCodeParams.loaderType = gLoaderType;
genCodeParams.file = nullptr;
genCodeParams.functions = functions;
genCodeParams.numFunctions = numFunctions;
genCodeParams.filenameTmp = "computeContextLoaderGenerated.tmp.h";
genCodeParams.filenameDst = "computeContextLoaderGenerated.h";
genCodeParams.moduleNameUpperCase = "ComputeContext";
genCodeParams.moduleNameLowerCase = "computeContext";
genCodeParams.instName = "gComputeContextLoader";
genCodeParams.apiMarker = "COMPUTE_API";
fopen_s(&genCodeParams.file, genCodeParams.filenameTmp, "w");
generateCode(&genCodeParams);
fclose(genCodeParams.file);
freeStrHeap(&strHeap);
fileDiffAndWriteIfModified(&genCodeParams);
}
void genLoaderImgui()
{
const unsigned int numFunctions = 18u;
const char* functionDefinitions[numFunctions] = {
"void imguiGraphContextInit(const ImguiGraphDesc* desc);",
"void imguiGraphContextUpdate(const ImguiGraphDesc* desc);",
"void imguiGraphContextDestroy();",
"void imguiGraphRecordBegin();",
"void imguiGraphRecordEnd();",
"void imguiGraphVertex2f(float x, float y);",
"void imguiGraphVertex2fv(const float* v);",
"void imguiGraphTexCoord2f(float u, float v);",
"void imguiGraphColor4ub(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);",
"void imguiGraphColor4ubv(const uint8_t* v);",
"void imguiGraphFontTextureEnable();",
"void imguiGraphFontTextureDisable();",
"void imguiGraphEnableScissor(int x, int y, int width, int height);",
"void imguiGraphDisableScissor();",
"void imguiGraphFontTextureInit(unsigned char* data);",
"void imguiGraphFontTextureRelease();",
"bool imguiInteropGraphInit(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx);",
"void imguiInteropGraphUpdate(imguiGraphUpdate_t func, AppGraphCtx* appctx);"
};
StrHeap strHeap = allocateStrHeap(functionDefinitions, numFunctions);
Function functions[numFunctions];
for (unsigned int functionIdx = 0u; functionIdx < numFunctions; functionIdx++)
{
functions[functionIdx] = genFunction(&strHeap, functionDefinitions[functionIdx]);
}
GenerateCodeParams genCodeParams = {};
genCodeParams.loaderType = gLoaderType;
genCodeParams.file = nullptr;
genCodeParams.functions = functions;
genCodeParams.numFunctions = numFunctions;
genCodeParams.filenameTmp = "imguiGraphLoaderGenerated.tmp.h";
genCodeParams.filenameDst = "imguiGraphLoaderGenerated.h";
genCodeParams.moduleNameUpperCase = "Imgui";
genCodeParams.moduleNameLowerCase = "imgui";
genCodeParams.instName = "gImguiLoader";
genCodeParams.apiMarker = "IMGUI_GRAPH_API";
fopen_s(&genCodeParams.file, genCodeParams.filenameTmp, "w");
generateCode(&genCodeParams);
fclose(genCodeParams.file);
freeStrHeap(&strHeap);
fileDiffAndWriteIfModified(&genCodeParams);
}
void genLoaderMesh()
{
const unsigned int numFunctions = 10u;
const char* functionDefinitions[numFunctions] = {
"MeshContext* MeshContextCreate(const MeshContextDesc* desc);",
"void MeshContextUpdate(MeshContext* context, const MeshContextDesc* desc);",
"void MeshContextRelease(MeshContext* context);",
"MeshIndexBuffer* MeshIndexBufferCreate(MeshContext* context, MeshUint* indices, MeshUint numIndices);",
"void MeshIndexBufferRelease(MeshIndexBuffer* buffer);",
"MeshVertexBuffer* MeshVertexBufferCreate(MeshContext* context, MeshVertex* vertices, MeshUint numVertices);",
"void MeshVertexBufferRelease(MeshVertexBuffer* buffer);",
"void MeshContextDraw(MeshContext* context, const MeshContextDrawParams* params);",
"MeshContext* MeshInteropContextCreate(AppGraphCtx* appctx);",
"void MeshInteropContextUpdate(MeshContext* context, AppGraphCtx* appctx);"
};
StrHeap strHeap = allocateStrHeap(functionDefinitions, numFunctions);
Function functions[numFunctions];
for (unsigned int functionIdx = 0u; functionIdx < numFunctions; functionIdx++)
{
functions[functionIdx] = genFunction(&strHeap, functionDefinitions[functionIdx]);
}
GenerateCodeParams genCodeParams = {};
genCodeParams.loaderType = gLoaderType;
genCodeParams.file = nullptr;
genCodeParams.functions = functions;
genCodeParams.numFunctions = numFunctions;
genCodeParams.filenameTmp = "meshLoaderGenerated.tmp.h";
genCodeParams.filenameDst = "meshLoaderGenerated.h";
genCodeParams.moduleNameUpperCase = "Mesh";
genCodeParams.moduleNameLowerCase = "mesh";
genCodeParams.instName = "gMeshLoader";
genCodeParams.apiMarker = "MESH_API";
fopen_s(&genCodeParams.file, genCodeParams.filenameTmp, "w");
generateCode(&genCodeParams);
fclose(genCodeParams.file);
freeStrHeap(&strHeap);
fileDiffAndWriteIfModified(&genCodeParams);
}
void genNvFlowInteropLoader()
{
const unsigned int numFunctions = 6u;
const char* functionDefinitions[numFunctions] = {
"NvFlowContext* NvFlowInteropCreateContext(AppGraphCtx* appctx);",
"NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilView(AppGraphCtx* appctx, NvFlowContext* flowctx);",
"NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetView(AppGraphCtx* appctx, NvFlowContext* flowctx);",
"void NvFlowInteropUpdateContext(NvFlowContext* context, AppGraphCtx* appctx);",
"void NvFlowInteropUpdateDepthStencilView(NvFlowDepthStencilView* view, AppGraphCtx* appctx, NvFlowContext* flowctx);",
"void NvFlowInteropUpdateRenderTargetView(NvFlowRenderTargetView* view, AppGraphCtx* appctx, NvFlowContext* flowctx);"
};
StrHeap strHeap = allocateStrHeap(functionDefinitions, numFunctions);
Function functions[numFunctions];
for (unsigned int functionIdx = 0u; functionIdx < numFunctions; functionIdx++)
{
functions[functionIdx] = genFunction(&strHeap, functionDefinitions[functionIdx]);
}
GenerateCodeParams genCodeParams = {};
genCodeParams.loaderType = gLoaderType;
genCodeParams.file = nullptr;
genCodeParams.functions = functions;
genCodeParams.numFunctions = numFunctions;
genCodeParams.filenameTmp = "NvFlowInteropLoaderGenerated.tmp.h";
genCodeParams.filenameDst = "NvFlowInteropLoaderGenerated.h";
genCodeParams.moduleNameUpperCase = "NvFlowInterop";
genCodeParams.moduleNameLowerCase = "nvFlowInterop";
genCodeParams.instName = "gNvFlowInteropLoader";
genCodeParams.apiMarker = "NV_FLOW_API";
fopen_s(&genCodeParams.file, genCodeParams.filenameTmp, "w");
generateCode(&genCodeParams);
fclose(genCodeParams.file);
freeStrHeap(&strHeap);
fileDiffAndWriteIfModified(&genCodeParams);
}
int main(int argc, char** argv)
{
genLoaderAppGraphCtx();
genLoaderComputeContext();
genLoaderImgui();
genLoaderMesh();
genNvFlowInteropLoader();
return 0;
}
|