RavEngine
Loading...
Searching...
No Matches
EditorCommon.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2014-2022 NVIDIA Corporation. All rights reserved.
26
27#pragma once
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <stdarg.h>
33
34#include <math.h>
35
36#include "imgui.h"
37#include "Loader.h"
38#include "ImguiRenderer.h"
39#include "ShapeRenderer.h"
40#include "FrameCapture.h"
41
42#include "NvFlowArray.h"
43#include "NvFlowString.h"
44
45#include "NvFlowUploadBuffer.h"
46
47#include "Camera.h"
48#include "Timer.h"
49
50#include "NvFlowDatabase.h"
51
52#include "NvFlowStringHash.h"
53
54// Editor stage API
55
56struct EditorFlow;
57
58void editorFlow_clearStage(EditorFlow* ptr);
59
60void editorFlow_definePrim(EditorFlow* ptr, const char* type, const char* path, const char* name);
61
62void editorFlow_setAttribute(EditorFlow* ptr, const char* primPath, const char* name, const void* data, NvFlowUint64 sizeInBytes);
63void editorFlow_setAttributeFloat(EditorFlow* ptr, const char* primPath, const char* name, float value);
64void editorFlow_setAttributeInt(EditorFlow* ptr, const char* primPath, const char* name, int value);
65void editorFlow_setAttributeUint(EditorFlow* ptr, const char* primPath, const char* name, NvFlowUint value);
66void editorFlow_setAttributeBool(EditorFlow* ptr, const char* primPath, const char* name, NvFlowBool32 value);
67void editorFlow_setAttributeFloat3(EditorFlow* ptr, const char* primPath, const char* name, NvFlowFloat3 value);
68void editorFlow_setAttributeFloat3Array(EditorFlow* ptr, const char* primPath, const char* name, const NvFlowFloat3* values, NvFlowUint64 elementCount);
69void editorFlow_setAttributeFloat4Array(EditorFlow* ptr, const char* primPath, const char* name, const NvFlowFloat4* values, NvFlowUint64 elementCount);
70void editorFlow_setAttributeIntArray(EditorFlow* ptr, const char* primPath, const char* name, const int* values, NvFlowUint64 elementCount);
71
72// Builtin Scenes
73
75{
76 const char* stageName;
77 void*(*init)(EditorFlow* ptr);
78 void(*update)(EditorFlow* ptr, void* userdata, double time, float deltaTime);
79 void(*destroy)(EditorFlow* ptr, void* userdata);
80};
81
82void editorFlowStage_getBuiltinStages(const EditorFlowStage*** pStages, NvFlowUint64* pStageCount);
83
84void editorFlowStage_applyOverrides(EditorFlow* ptr, float cellsizeOverride, NvFlowBool32 smallBlocksOverride);
85
86// Editor subsystems
87
88struct App;
89
90void printError(const char* str, void* userdata);
91
93{
94 // compute config
95 NvFlowContextApi contextApi = eNvFlowContextApi_vulkan;
96 NvFlowUint threadCount = 0u;
97 NvFlowBool32 headless = NV_FLOW_FALSE;
98 NvFlowBool32 vsync = NV_FLOW_TRUE;
99
100 // loader/compute foundation
101 void* nvFlowModule = nullptr;
102 void* nvFlowExtModule = nullptr;
103 NvFlowLoader loader = {};
104 NvFlowContextInterface contextInterface = {};
105 NvFlowDeviceManager* deviceManager = nullptr;
106 NvFlowDevice* device = nullptr;
107 NvFlowDeviceQueue* deviceQueue = nullptr;
108 NvFlowSwapchain* swapchain = nullptr;
109
110 // benchmarking
111 FILE* perflog = nullptr;
112 NvFlowArray<const char*> statEntries_label;
113 NvFlowArray<NvFlowBool32> statEntries_active;
114 NvFlowArray<float> statEntries_cpuDeltaTime_sum;
115 NvFlowArray<float> statEntries_cpuDeltaTime_count;
116 NvFlowArray<float> statEntries_gpuDeltaTime_sum;
117 NvFlowArray<float> statEntries_gpuDeltaTime_count;
118
119 NvFlowArray<const char*> statOut_label;
120 NvFlowArray<float> statOut_cpu;
121 NvFlowArray<float> statOut_gpu;
122
123 const char* outputFilename = "benchmark.csv";
124 FILE* outputFile = nullptr;
125 NvFlowUint benchmarkFrameCount = 0u;
126 NvFlowUint benchmarkFrameID = 0u;
127 bool benchmarkShouldRun = true;
128 NvFlowUint benchmarkActiveBlockCount = 0u;
129
130 AppTimer benchmarkTimerCPU = {};
131};
132
133void editorCompute_init(EditorCompute* ptr, const NvFlowSwapchainDesc* swapchainDesc, NvFlowBool32 headless);
134void editorCompute_destroy(EditorCompute* ptr);
135void editorCompute_reportEntries(void* userdata, NvFlowUint64 captureID, NvFlowUint numEntries, NvFlowProfilerEntry* entries);
136void editorCompute_logPrint(NvFlowLogLevel level, const char* format, ...);
137
139{
140 const char* cmd;
141 const char* path;
142 const char* name;
143 const char* type;
144 const NvFlowUint8* data;
145 NvFlowUint64 dataSize;
146};
147
149{
150 // flow editor config
151 NvFlowUint maxLocations = 4096u;
152 NvFlowUint targetMaxLocations = 4096u;
153 NvFlowBool32 simonly = NV_FLOW_FALSE;
154 NvFlowBool32 smallBlocksOverride = NV_FLOW_FALSE;
155 float cellsizeOverride = 0.f;
156
157 const char* cmdStage = nullptr;
159 NvFlowUint64 targetStageIdx = 0llu;
160 const EditorFlowStage* currentStage = nullptr;
161 void* stageUserdata = nullptr;
162
163 // active state
164 double absoluteSimTime = 0.0;
165 double animationTime = 0.0;
166 NvFlowUint activeBlockCount = 0u;
167 NvFlowUint3 activeBlockDim = { 0u, 0u, 0u };
168 NvFlowUint activeBlockCountIsosurface = 0u;
169 NvFlowUint3 activeBlockDimIsosurface = { 32u, 16u, 16u };
170
171 // flow grid
172 NvFlowGrid* grid = nullptr;
173 NvFlowGridParamsNamed* gridParamsServer = nullptr;
174 NvFlowGridParamsNamed* gridParamsClient = nullptr;
175 NvFlowGridParams* gridParams = nullptr;
176 NvFlowDatabase gridParamsSet;
177 NvFlowArray<const char*> typenames;
178 NvFlowArray<const char*> displayTypenames;
181 NvFlowArray<NvFlowDatabaseInstance*> abstractParamsList;
182
183 // dynamic grid params
184 NvFlowGridParamsDesc gridParamsDesc = {};
185 NvFlowGridParams* clientGridParams = nullptr;
186 NvFlowGridParamsSnapshot* paramsSnapshot = nullptr;
187
189 NvFlowStringPool* commandStringPool = nullptr;
191};
192
193void editorFlow_init(EditorCompute* ctx, EditorFlow* ptr);
194void editorFlow_presimulate(EditorCompute* ctx, EditorFlow* ptr, float deltaTime, NvFlowBool32 isPaused);
195void editorFlow_simulate(EditorCompute* ctx, EditorFlow* ptr, float deltaTime, NvFlowBool32 isPaused);
196void editorFlow_offscreen(EditorCompute* ctx, EditorFlow* ptr);
197void editorFlow_render(EditorCompute* ctx, EditorFlow* ptr,
198 NvFlowTextureTransient** colorFrontTransient,
199 NvFlowTextureTransient* offscreenDepthTransient,
200 NvFlowUint windowWidth,
201 NvFlowUint windowHeight,
202 const NvFlowFloat4x4* view,
203 const NvFlowFloat4x4* projection
204);
205void editorFlow_unmap(EditorCompute* ctx, EditorFlow* ptr);
206void editorFlow_destroy(EditorCompute* ctx, EditorFlow* ptr);
207
209{
210 NvFlowImguiRendererInterface imguiRendererInterface = {};
211 NvFlowImguiRenderer* imguiRenderer = nullptr;
212};
213
214void editorImgui_init(EditorImgui* ptr, NvFlowContextInterface* contextInterface, NvFlowContext* context);
215void editorImgui_update(
216 EditorImgui* ptr,
217 App* app,
218 EditorCompute* compute,
219 EditorFlow* flow
220);
221void editorImgui_render(
222 EditorImgui* ptr,
223 NvFlowContext* context,
224 NvFlowTextureTransient* colorIn,
225 NvFlowTextureTransient* colorOut,
226 NvFlowUint windowWidth,
227 NvFlowUint windowHeight
228);
229void editorImgui_destroy(EditorImgui* ptr, NvFlowContext* context);
230
231struct App
232{
233 NvFlowUint windowWidth = 1280u;
234 NvFlowUint windowHeight = 800u;
235 NvFlowUint windowWidthOld = 1280u;
236 NvFlowUint windowHeightOld = 800u;
237
238 GLFWwindow* window = nullptr;
239 NvFlowBool32 headless = NV_FLOW_FALSE;
240 NvFlowBool32 isPaused = NV_FLOW_FALSE;
241 NvFlowBool32 overlayEnabled = NV_FLOW_FALSE;
242 NvFlowBool32 editorEnabled = NV_FLOW_TRUE;
243 NvFlowBool32 sphereEnabled = NV_FLOW_FALSE;
244 NvFlowBool32 captureEnabled = NV_FLOW_FALSE;
245
246 int fullscreenState = 0;
247 NvFlowBool32 shouldRun = NV_FLOW_TRUE;
248 int mouseX = 0;
249 int mouseY = 0;
250 int mouseYInv = 0;
251 NvFlowBool32 mouseJustPressed[5u];
252
253 NvFlowShapeRendererInterface shapeRendererInterface = {};
254 NvFlowShapeRenderer* shapeRenderer = nullptr;
255
256 NvFlowFrameCaptureInterface frameCaptureInterface = {};
257 NvFlowFrameCapture* frameCapture = nullptr;
258
259 EditorImgui imgui = {};
260
261 EditorCompute compute = {};
262 EditorFlow flow = {};
263
264 NvFlowCamera* camera = nullptr;
265
266 AppTimer flowTimerCPU = {};
267 AppTimer imguiTimerCPU = {};
268 AppTimer presentTimerCPU = {};
269};
270
271int editorGlfw_init(App* ptr);
272void editorGlfw_getSwapchainDesc(App* ptr, NvFlowSwapchainDesc* outDesc);
273void editorGlfw_newFrame(App* ptr, float deltaTime);
274int editorGlfw_processEvents(App* ptr);
275void editorGlfw_destroy(App* ptr);
276
277#if !defined(_WIN32)
278NV_FLOW_INLINE void fopen_s(FILE** streamptr, const char* filename, const char* mode)
279{
280 *streamptr = fopen(filename, mode);
281}
282#endif
283
Definition base.h:1940
Definition Timer.h:38
Definition EditorCommon.h:232
Definition EditorCommon.h:93
Definition EditorCommon.h:139
Definition EditorCommon.h:75
Definition EditorCommon.h:149
Definition EditorCommon.h:209
Definition NvFlowArray.h:36
Definition Camera.cpp:32
Definition NvFlowContext.h:362
Definition NvFlowDatabase.h:582
Definition FrameCapture.h:34
Definition NvFlowExt.h:2646
Definition ImguiRenderer.h:32
Definition NvFlowLoader.h:81
Definition NvFlowExt.h:3024
Definition ShapeRenderer.h:38
Definition NvFlowStringHash.h:50
Definition NvFlowString.cpp:35