aboutsummaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
Diffstat (limited to 'demo')
-rw-r--r--demo/DemoApp/DemoApp.vcxproj25
-rw-r--r--demo/DemoApp/DemoApp.vcxproj.filters3
-rw-r--r--demo/DemoApp/NvFlowInteropLoader.cpp48
-rw-r--r--demo/DemoApp/NvFlowInteropLoaderGenerated.h96
-rw-r--r--demo/DemoApp/appGraphCtx.h7
-rw-r--r--demo/DemoApp/appGraphCtxLoader.cpp77
-rw-r--r--demo/DemoApp/appGraphCtxLoaderGenerated.h150
-rw-r--r--demo/DemoApp/computeContextLoader.cpp132
-rw-r--r--demo/DemoApp/computeContextLoaderGenerated.h249
-rw-r--r--demo/DemoApp/imguiGraphLoader.cpp109
-rw-r--r--demo/DemoApp/imguiGraphLoaderGenerated.h204
-rw-r--r--demo/DemoApp/loader.h66
-rw-r--r--demo/DemoApp/main.cpp12
-rw-r--r--demo/DemoApp/meshLoader.cpp67
-rw-r--r--demo/DemoApp/meshLoaderGenerated.h132
-rw-r--r--demo/DemoApp/preset0.h4
-rw-r--r--demo/DemoApp/preset1.h4
-rw-r--r--demo/DemoApp/scene.cpp84
-rw-r--r--demo/DemoApp/scene.h80
-rw-r--r--demo/DemoApp/scene2DTextureEmitter.cpp2
-rw-r--r--demo/DemoApp/sceneCustomEmit.cpp2
-rw-r--r--demo/DemoApp/sceneEmitSubStep.cpp204
-rw-r--r--demo/DemoApp/sceneFlow.cpp70
-rw-r--r--demo/DemoApp/sceneSDF.cpp4
-rw-r--r--demo/DemoApp/sceneSimpleFlame.cpp51
-rw-r--r--demo/DemoApp/sceneSimpleSmoke.cpp2
-rw-r--r--demo/DemoAppCodeGen/DemoAppCodeGen.vcxproj280
-rw-r--r--demo/DemoAppCodeGen/DemoAppCodeGen.vcxproj.filters33
-rw-r--r--demo/DemoAppCodeGen/demoAppCodeGen.cpp292
-rw-r--r--demo/DemoAppCodeGen/functionDefinitionExtract.h230
-rw-r--r--demo/DemoAppCodeGen/loaderCodeGen.h335
-rw-r--r--demo/DemoAppD3D11/NvFlowInteropD3D11.cpp36
-rw-r--r--demo/DemoAppD3D11/appD3D11Ctx.cpp129
-rw-r--r--demo/DemoAppD3D11/appD3D11Ctx.h46
-rw-r--r--demo/DemoAppD3D11/computeContextD3D11.cpp218
-rw-r--r--demo/DemoAppD3D11/computeContextD3D11.h86
-rw-r--r--demo/DemoAppD3D11/imguiGraphD3D11.cpp38
-rw-r--r--demo/DemoAppD3D11/imguiGraphD3D11.h46
-rw-r--r--demo/DemoAppD3D11/imguiInteropD3D11.cpp20
-rw-r--r--demo/DemoAppD3D11/meshD3D11.cpp99
-rw-r--r--demo/DemoAppD3D11/meshD3D11.h31
-rw-r--r--demo/DemoAppD3D11/meshInteropD3D11.cpp20
-rw-r--r--demo/DemoAppD3D12/NvFlowInteropD3D12.cpp54
-rw-r--r--demo/DemoAppD3D12/appD3D12Ctx.cpp131
-rw-r--r--demo/DemoAppD3D12/appD3D12Ctx.h44
-rw-r--r--demo/DemoAppD3D12/computeContextD3D12.cpp272
-rw-r--r--demo/DemoAppD3D12/computeContextD3D12.h86
-rw-r--r--demo/DemoAppD3D12/imguiGraphD3D12.cpp40
-rw-r--r--demo/DemoAppD3D12/imguiGraphD3D12.h46
-rw-r--r--demo/DemoAppD3D12/imguiInteropD3D12.cpp22
-rw-r--r--demo/DemoAppD3D12/meshD3D12.cpp105
-rw-r--r--demo/DemoAppD3D12/meshD3D12.h31
-rw-r--r--demo/DemoAppD3D12/meshInteropD3D12.cpp20
53 files changed, 3704 insertions, 970 deletions
diff --git a/demo/DemoApp/DemoApp.vcxproj b/demo/DemoApp/DemoApp.vcxproj
index 4cae61f..ba4e592 100644
--- a/demo/DemoApp/DemoApp.vcxproj
+++ b/demo/DemoApp/DemoApp.vcxproj
@@ -141,6 +141,12 @@ copy "$(SolutionDir)Lib\$(PlatformName)\*.dll" "$(outDir)"</Command>
<CustomBuildStep>
<Outputs>SDL2.dll</Outputs>
</CustomBuildStep>
+ <PreBuildEvent>
+ <Command>"$(outDir)DemoAppCodeGen$(Configuration)_$(PlatformName).exe"</Command>
+ </PreBuildEvent>
+ <PreBuildEvent>
+ <Message>Code Generation</Message>
+ </PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@@ -172,6 +178,12 @@ copy "$(SolutionDir)Lib\$(PlatformName)\*.dll" "$(outDir)"</Command>
<CustomBuildStep>
<Outputs>SDL2.dll</Outputs>
</CustomBuildStep>
+ <PreBuildEvent>
+ <Command>"$(outDir)DemoAppCodeGen$(Configuration)_$(PlatformName).exe"</Command>
+ </PreBuildEvent>
+ <PreBuildEvent>
+ <Message>Code Generation</Message>
+ </PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
@@ -207,6 +219,12 @@ copy "$(SolutionDir)Lib\$(PlatformName)\*.dll" "$(outDir)"</Command>
<CustomBuildStep>
<Outputs>SDL2.dll</Outputs>
</CustomBuildStep>
+ <PreBuildEvent>
+ <Command>"$(outDir)DemoAppCodeGen$(Configuration)_$(PlatformName).exe"</Command>
+ </PreBuildEvent>
+ <PreBuildEvent>
+ <Message>Code Generation</Message>
+ </PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@@ -242,6 +260,12 @@ copy "$(SolutionDir)Lib\$(PlatformName)\*.dll" "$(outDir)"</Command>
<CustomBuildStep>
<Outputs>SDL2.dll</Outputs>
</CustomBuildStep>
+ <PreBuildEvent>
+ <Command>"$(outDir)DemoAppCodeGen$(Configuration)_$(PlatformName).exe"</Command>
+ </PreBuildEvent>
+ <PreBuildEvent>
+ <Message>Code Generation</Message>
+ </PreBuildEvent>
</ItemDefinitionGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
@@ -276,6 +300,7 @@ copy "$(SolutionDir)Lib\$(PlatformName)\*.dll" "$(outDir)"</Command>
<ClCompile Include="scene.cpp" />
<ClCompile Include="scene2DTextureEmitter.cpp" />
<ClCompile Include="sceneCustomEmit.cpp" />
+ <ClCompile Include="sceneEmitSubStep.cpp" />
<ClCompile Include="sceneFlow.cpp" />
<ClCompile Include="sceneSDF.cpp" />
<ClCompile Include="sceneSimpleFlame.cpp" />
diff --git a/demo/DemoApp/DemoApp.vcxproj.filters b/demo/DemoApp/DemoApp.vcxproj.filters
index 94b9d93..b6bfb93 100644
--- a/demo/DemoApp/DemoApp.vcxproj.filters
+++ b/demo/DemoApp/DemoApp.vcxproj.filters
@@ -78,6 +78,9 @@
<ClCompile Include="sceneFlow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="sceneEmitSubStep.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<Manifest Include="app.manifest">
diff --git a/demo/DemoApp/NvFlowInteropLoader.cpp b/demo/DemoApp/NvFlowInteropLoader.cpp
index 6224373..082afcf 100644
--- a/demo/DemoApp/NvFlowInteropLoader.cpp
+++ b/demo/DemoApp/NvFlowInteropLoader.cpp
@@ -14,50 +14,6 @@
#include "NvFlowInterop.h"
-namespace
-{
- ModuleLoader<16u, SDL_LoadObject, SDL_UnloadObject, SDL_LoadFunction> g_loader;
-}
+#include <stdio.h>
-void loadNvFlowInterop(AppGraphCtxType type)
-{
- const char* moduleName = demoAppDLLName(type);
-
- g_loader.loadModule(moduleName);
-}
-
-void unloadNvFlowInterop()
-{
- g_loader.unloadModule();
-}
-
-// Functions
-NvFlowContext* NvFlowInteropCreateContext(AppGraphCtx* appctx)
-{
- return g_loader.function<0>(NvFlowInteropCreateContext, "NvFlowInteropCreateContext", appctx);
-}
-
-NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilView(AppGraphCtx* appctx, NvFlowContext* flowctx)
-{
- return g_loader.function<1>(NvFlowInteropCreateDepthStencilView, "NvFlowInteropCreateDepthStencilView", appctx, flowctx);
-}
-
-NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetView(AppGraphCtx* appctx, NvFlowContext* flowctx)
-{
- return g_loader.function<2>(NvFlowInteropCreateRenderTargetView, "NvFlowInteropCreateRenderTargetView", appctx, flowctx);
-}
-
-void NvFlowInteropUpdateContext(NvFlowContext* context, AppGraphCtx* appctx)
-{
- return g_loader.function<3>(NvFlowInteropUpdateContext, "NvFlowInteropUpdateContext", context, appctx);
-}
-
-void NvFlowInteropUpdateDepthStencilView(NvFlowDepthStencilView* view, AppGraphCtx* appctx, NvFlowContext* flowctx)
-{
- return g_loader.function<4>(NvFlowInteropUpdateDepthStencilView, "NvFlowInteropUpdateDepthStencilView", view, appctx, flowctx);
-}
-
-void NvFlowInteropUpdateRenderTargetView(NvFlowRenderTargetView* view, AppGraphCtx* appctx, NvFlowContext* flowctx)
-{
- return g_loader.function<5>(NvFlowInteropUpdateRenderTargetView, "NvFlowInteropUpdateRenderTargetView", view, appctx, flowctx);
-} \ No newline at end of file
+#include "NvFlowInteropLoaderGenerated.h" \ No newline at end of file
diff --git a/demo/DemoApp/NvFlowInteropLoaderGenerated.h b/demo/DemoApp/NvFlowInteropLoaderGenerated.h
new file mode 100644
index 0000000..dad9989
--- /dev/null
+++ b/demo/DemoApp/NvFlowInteropLoaderGenerated.h
@@ -0,0 +1,96 @@
+/*
+* 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.
+*/
+
+typedef NvFlowContext* (*NvFlowInteropCreateContext_ptr_t)(AppGraphCtx* appctx);
+typedef NvFlowDepthStencilView* (*NvFlowInteropCreateDepthStencilView_ptr_t)(AppGraphCtx* appctx, NvFlowContext* flowctx);
+typedef NvFlowRenderTargetView* (*NvFlowInteropCreateRenderTargetView_ptr_t)(AppGraphCtx* appctx, NvFlowContext* flowctx);
+typedef void (*NvFlowInteropUpdateContext_ptr_t)(NvFlowContext* context, AppGraphCtx* appctx);
+typedef void (*NvFlowInteropUpdateDepthStencilView_ptr_t)(NvFlowDepthStencilView* view, AppGraphCtx* appctx, NvFlowContext* flowctx);
+typedef void (*NvFlowInteropUpdateRenderTargetView_ptr_t)(NvFlowRenderTargetView* view, AppGraphCtx* appctx, NvFlowContext* flowctx);
+
+struct NvFlowInteropLoader
+{
+ void* module = nullptr;
+ const char* suffix = "";
+ char buf[1024u];
+
+ NvFlowInteropCreateContext_ptr_t NvFlowInteropCreateContext_ptr;
+ NvFlowInteropCreateDepthStencilView_ptr_t NvFlowInteropCreateDepthStencilView_ptr;
+ NvFlowInteropCreateRenderTargetView_ptr_t NvFlowInteropCreateRenderTargetView_ptr;
+ NvFlowInteropUpdateContext_ptr_t NvFlowInteropUpdateContext_ptr;
+ NvFlowInteropUpdateDepthStencilView_ptr_t NvFlowInteropUpdateDepthStencilView_ptr;
+ NvFlowInteropUpdateRenderTargetView_ptr_t NvFlowInteropUpdateRenderTargetView_ptr;
+
+}gNvFlowInteropLoader;
+
+NvFlowContext* NvFlowInteropCreateContext(AppGraphCtx* appctx)
+{
+ return gNvFlowInteropLoader.NvFlowInteropCreateContext_ptr(appctx);
+}
+
+NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilView(AppGraphCtx* appctx, NvFlowContext* flowctx)
+{
+ return gNvFlowInteropLoader.NvFlowInteropCreateDepthStencilView_ptr(appctx, flowctx);
+}
+
+NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetView(AppGraphCtx* appctx, NvFlowContext* flowctx)
+{
+ return gNvFlowInteropLoader.NvFlowInteropCreateRenderTargetView_ptr(appctx, flowctx);
+}
+
+void NvFlowInteropUpdateContext(NvFlowContext* context, AppGraphCtx* appctx)
+{
+ return gNvFlowInteropLoader.NvFlowInteropUpdateContext_ptr(context, appctx);
+}
+
+void NvFlowInteropUpdateDepthStencilView(NvFlowDepthStencilView* view, AppGraphCtx* appctx, NvFlowContext* flowctx)
+{
+ return gNvFlowInteropLoader.NvFlowInteropUpdateDepthStencilView_ptr(view, appctx, flowctx);
+}
+
+void NvFlowInteropUpdateRenderTargetView(NvFlowRenderTargetView* view, AppGraphCtx* appctx, NvFlowContext* flowctx)
+{
+ return gNvFlowInteropLoader.NvFlowInteropUpdateRenderTargetView_ptr(view, appctx, flowctx);
+}
+
+void* nvFlowInteropLoaderLoadFunction(NvFlowInteropLoader* inst, const char* name)
+{
+ snprintf(inst->buf, 1024u, "%s%s", name, inst->suffix);
+
+ return SDL_LoadFunction(inst->module, inst->buf);
+}
+
+void loadNvFlowInterop(AppGraphCtxType type)
+{
+ const char* moduleName = demoAppDLLName(type);
+
+ gNvFlowInteropLoader.suffix = demoAppBackendSuffix(type);
+
+ gNvFlowInteropLoader.module = SDL_LoadObject(moduleName);
+
+ gNvFlowInteropLoader.NvFlowInteropCreateContext_ptr = (NvFlowInteropCreateContext_ptr_t)(nvFlowInteropLoaderLoadFunction(&gNvFlowInteropLoader, "NvFlowInteropCreateContext"));
+ gNvFlowInteropLoader.NvFlowInteropCreateDepthStencilView_ptr = (NvFlowInteropCreateDepthStencilView_ptr_t)(nvFlowInteropLoaderLoadFunction(&gNvFlowInteropLoader, "NvFlowInteropCreateDepthStencilView"));
+ gNvFlowInteropLoader.NvFlowInteropCreateRenderTargetView_ptr = (NvFlowInteropCreateRenderTargetView_ptr_t)(nvFlowInteropLoaderLoadFunction(&gNvFlowInteropLoader, "NvFlowInteropCreateRenderTargetView"));
+ gNvFlowInteropLoader.NvFlowInteropUpdateContext_ptr = (NvFlowInteropUpdateContext_ptr_t)(nvFlowInteropLoaderLoadFunction(&gNvFlowInteropLoader, "NvFlowInteropUpdateContext"));
+ gNvFlowInteropLoader.NvFlowInteropUpdateDepthStencilView_ptr = (NvFlowInteropUpdateDepthStencilView_ptr_t)(nvFlowInteropLoaderLoadFunction(&gNvFlowInteropLoader, "NvFlowInteropUpdateDepthStencilView"));
+ gNvFlowInteropLoader.NvFlowInteropUpdateRenderTargetView_ptr = (NvFlowInteropUpdateRenderTargetView_ptr_t)(nvFlowInteropLoaderLoadFunction(&gNvFlowInteropLoader, "NvFlowInteropUpdateRenderTargetView"));
+}
+
+void unloadNvFlowInterop()
+{
+ gNvFlowInteropLoader.NvFlowInteropCreateContext_ptr = nullptr;
+ gNvFlowInteropLoader.NvFlowInteropCreateDepthStencilView_ptr = nullptr;
+ gNvFlowInteropLoader.NvFlowInteropCreateRenderTargetView_ptr = nullptr;
+ gNvFlowInteropLoader.NvFlowInteropUpdateContext_ptr = nullptr;
+ gNvFlowInteropLoader.NvFlowInteropUpdateDepthStencilView_ptr = nullptr;
+ gNvFlowInteropLoader.NvFlowInteropUpdateRenderTargetView_ptr = nullptr;
+
+ SDL_UnloadObject(gNvFlowInteropLoader.module);
+}
diff --git a/demo/DemoApp/appGraphCtx.h b/demo/DemoApp/appGraphCtx.h
index 2f41c36..f1f0f75 100644
--- a/demo/DemoApp/appGraphCtx.h
+++ b/demo/DemoApp/appGraphCtx.h
@@ -16,6 +16,11 @@ struct SDL_Window;
struct AppGraphCtx;
+struct AppGraphColor
+{
+ float r, g, b, a;
+};
+
APP_GRAPH_CTX_API AppGraphCtx* AppGraphCtxCreate(int deviceID);
APP_GRAPH_CTX_API bool AppGraphCtxUpdateSize(AppGraphCtx* context, SDL_Window* window, bool fullscreen);
@@ -24,7 +29,7 @@ APP_GRAPH_CTX_API void AppGraphCtxReleaseRenderTarget(AppGraphCtx* context);
APP_GRAPH_CTX_API void AppGraphCtxRelease(AppGraphCtx* context);
-APP_GRAPH_CTX_API void AppGraphCtxFrameStart(AppGraphCtx* context, float clearColor[4]);
+APP_GRAPH_CTX_API void AppGraphCtxFrameStart(AppGraphCtx* context, AppGraphColor clearColor);
APP_GRAPH_CTX_API void AppGraphCtxFramePresent(AppGraphCtx* context, bool fullsync);
diff --git a/demo/DemoApp/appGraphCtxLoader.cpp b/demo/DemoApp/appGraphCtxLoader.cpp
index f724a93..6aa0f67 100644
--- a/demo/DemoApp/appGraphCtxLoader.cpp
+++ b/demo/DemoApp/appGraphCtxLoader.cpp
@@ -14,79 +14,6 @@
#include "appGraphCtx.h"
-namespace
-{
- ModuleLoader<16u, SDL_LoadObject, SDL_UnloadObject, SDL_LoadFunction> g_loader;
-}
+#include <stdio.h>
-void loadAppGraphCtx(AppGraphCtxType type)
-{
- const char* moduleName = demoAppDLLName(type);
-
- g_loader.loadModule(moduleName);
-}
-
-void unloadAppGraphCtx()
-{
- g_loader.unloadModule();
-}
-
-AppGraphCtx* AppGraphCtxCreate(int deviceID)
-{
- return g_loader.function<0>(AppGraphCtxCreate, "AppGraphCtxCreate", deviceID);
-}
-
-bool AppGraphCtxUpdateSize(AppGraphCtx* context, SDL_Window* window, bool fullscreen)
-{
- return g_loader.function<1>(AppGraphCtxUpdateSize, "AppGraphCtxUpdateSize", context, window, fullscreen);
-}
-
-void AppGraphCtxReleaseRenderTarget(AppGraphCtx* context)
-{
- return g_loader.function<2>(AppGraphCtxReleaseRenderTarget, "AppGraphCtxReleaseRenderTarget", context);
-}
-
-void AppGraphCtxRelease(AppGraphCtx* context)
-{
- return g_loader.function<3>(AppGraphCtxRelease, "AppGraphCtxRelease", context);
-}
-
-void AppGraphCtxFrameStart(AppGraphCtx* context, float clearColor[4])
-{
- return g_loader.function<4>(AppGraphCtxFrameStart, "AppGraphCtxFrameStart", context, clearColor);
-}
-
-void AppGraphCtxFramePresent(AppGraphCtx* context, bool fullsync)
-{
- return g_loader.function<5>(AppGraphCtxFramePresent, "AppGraphCtxFramePresent", context, fullsync);
-}
-
-void AppGraphCtxWaitForFrames(AppGraphCtx* context, unsigned int maxFramesInFlight)
-{
- return g_loader.function<6>(AppGraphCtxWaitForFrames, "AppGraphCtxWaitForFrames", context, maxFramesInFlight);
-}
-
-void AppGraphCtxProfileEnable(AppGraphCtx* context, bool enabled)
-{
- return g_loader.function<7>(AppGraphCtxProfileEnable, "AppGraphCtxProfileEnable", context, enabled);
-}
-
-void AppGraphCtxProfileBegin(AppGraphCtx* context, const char* label)
-{
- return g_loader.function<8>(AppGraphCtxProfileBegin, "AppGraphCtxProfileBegin", context, label);
-}
-
-void AppGraphCtxProfileEnd(AppGraphCtx* context, const char* label)
-{
- return g_loader.function<9>(AppGraphCtxProfileEnd, "AppGraphCtxProfileEnd", context, label);
-}
-
-bool AppGraphCtxProfileGet(AppGraphCtx* context, const char** plabel, float* cpuTime, float* gpuTime, int index)
-{
- return g_loader.function<10>(AppGraphCtxProfileGet, "AppGraphCtxProfileGet", context, plabel, cpuTime, gpuTime, index);
-}
-
-size_t AppGraphCtxDedicatedVideoMemory(AppGraphCtx* context)
-{
- return g_loader.function<11>(AppGraphCtxDedicatedVideoMemory, "AppGraphCtxDedicatedVideoMemory", context);
-} \ No newline at end of file
+#include "appGraphCtxLoaderGenerated.h" \ No newline at end of file
diff --git a/demo/DemoApp/appGraphCtxLoaderGenerated.h b/demo/DemoApp/appGraphCtxLoaderGenerated.h
new file mode 100644
index 0000000..7983c29
--- /dev/null
+++ b/demo/DemoApp/appGraphCtxLoaderGenerated.h
@@ -0,0 +1,150 @@
+/*
+* 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.
+*/
+
+typedef AppGraphCtx* (*AppGraphCtxCreate_ptr_t)(int deviceID);
+typedef bool (*AppGraphCtxUpdateSize_ptr_t)(AppGraphCtx* context, SDL_Window* window, bool fullscreen);
+typedef void (*AppGraphCtxReleaseRenderTarget_ptr_t)(AppGraphCtx* context);
+typedef void (*AppGraphCtxRelease_ptr_t)(AppGraphCtx* context);
+typedef void (*AppGraphCtxFrameStart_ptr_t)(AppGraphCtx* context, AppGraphColor clearColor);
+typedef void (*AppGraphCtxFramePresent_ptr_t)(AppGraphCtx* context, bool fullsync);
+typedef void (*AppGraphCtxWaitForFrames_ptr_t)(AppGraphCtx* context, unsigned int maxFramesInFlight);
+typedef void (*AppGraphCtxProfileEnable_ptr_t)(AppGraphCtx* context, bool enabled);
+typedef void (*AppGraphCtxProfileBegin_ptr_t)(AppGraphCtx* context, const char* label);
+typedef void (*AppGraphCtxProfileEnd_ptr_t)(AppGraphCtx* context, const char* label);
+typedef bool (*AppGraphCtxProfileGet_ptr_t)(AppGraphCtx* context, const char** plabel, float* cpuTime, float* gpuTime, int index);
+typedef size_t (*AppGraphCtxDedicatedVideoMemory_ptr_t)(AppGraphCtx* context);
+
+struct AppGraphCtxLoader
+{
+ void* module = nullptr;
+ const char* suffix = "";
+ char buf[1024u];
+
+ AppGraphCtxCreate_ptr_t AppGraphCtxCreate_ptr;
+ AppGraphCtxUpdateSize_ptr_t AppGraphCtxUpdateSize_ptr;
+ AppGraphCtxReleaseRenderTarget_ptr_t AppGraphCtxReleaseRenderTarget_ptr;
+ AppGraphCtxRelease_ptr_t AppGraphCtxRelease_ptr;
+ AppGraphCtxFrameStart_ptr_t AppGraphCtxFrameStart_ptr;
+ AppGraphCtxFramePresent_ptr_t AppGraphCtxFramePresent_ptr;
+ AppGraphCtxWaitForFrames_ptr_t AppGraphCtxWaitForFrames_ptr;
+ AppGraphCtxProfileEnable_ptr_t AppGraphCtxProfileEnable_ptr;
+ AppGraphCtxProfileBegin_ptr_t AppGraphCtxProfileBegin_ptr;
+ AppGraphCtxProfileEnd_ptr_t AppGraphCtxProfileEnd_ptr;
+ AppGraphCtxProfileGet_ptr_t AppGraphCtxProfileGet_ptr;
+ AppGraphCtxDedicatedVideoMemory_ptr_t AppGraphCtxDedicatedVideoMemory_ptr;
+
+}gAppGraphCtxLoader;
+
+AppGraphCtx* AppGraphCtxCreate(int deviceID)
+{
+ return gAppGraphCtxLoader.AppGraphCtxCreate_ptr(deviceID);
+}
+
+bool AppGraphCtxUpdateSize(AppGraphCtx* context, SDL_Window* window, bool fullscreen)
+{
+ return gAppGraphCtxLoader.AppGraphCtxUpdateSize_ptr(context, window, fullscreen);
+}
+
+void AppGraphCtxReleaseRenderTarget(AppGraphCtx* context)
+{
+ return gAppGraphCtxLoader.AppGraphCtxReleaseRenderTarget_ptr(context);
+}
+
+void AppGraphCtxRelease(AppGraphCtx* context)
+{
+ return gAppGraphCtxLoader.AppGraphCtxRelease_ptr(context);
+}
+
+void AppGraphCtxFrameStart(AppGraphCtx* context, AppGraphColor clearColor)
+{
+ return gAppGraphCtxLoader.AppGraphCtxFrameStart_ptr(context, clearColor);
+}
+
+void AppGraphCtxFramePresent(AppGraphCtx* context, bool fullsync)
+{
+ return gAppGraphCtxLoader.AppGraphCtxFramePresent_ptr(context, fullsync);
+}
+
+void AppGraphCtxWaitForFrames(AppGraphCtx* context, unsigned int maxFramesInFlight)
+{
+ return gAppGraphCtxLoader.AppGraphCtxWaitForFrames_ptr(context, maxFramesInFlight);
+}
+
+void AppGraphCtxProfileEnable(AppGraphCtx* context, bool enabled)
+{
+ return gAppGraphCtxLoader.AppGraphCtxProfileEnable_ptr(context, enabled);
+}
+
+void AppGraphCtxProfileBegin(AppGraphCtx* context, const char* label)
+{
+ return gAppGraphCtxLoader.AppGraphCtxProfileBegin_ptr(context, label);
+}
+
+void AppGraphCtxProfileEnd(AppGraphCtx* context, const char* label)
+{
+ return gAppGraphCtxLoader.AppGraphCtxProfileEnd_ptr(context, label);
+}
+
+bool AppGraphCtxProfileGet(AppGraphCtx* context, const char** plabel, float* cpuTime, float* gpuTime, int index)
+{
+ return gAppGraphCtxLoader.AppGraphCtxProfileGet_ptr(context, plabel, cpuTime, gpuTime, index);
+}
+
+size_t AppGraphCtxDedicatedVideoMemory(AppGraphCtx* context)
+{
+ return gAppGraphCtxLoader.AppGraphCtxDedicatedVideoMemory_ptr(context);
+}
+
+void* appGraphCtxLoaderLoadFunction(AppGraphCtxLoader* inst, const char* name)
+{
+ snprintf(inst->buf, 1024u, "%s%s", name, inst->suffix);
+
+ return SDL_LoadFunction(inst->module, inst->buf);
+}
+
+void loadAppGraphCtx(AppGraphCtxType type)
+{
+ const char* moduleName = demoAppDLLName(type);
+
+ gAppGraphCtxLoader.suffix = demoAppBackendSuffix(type);
+
+ gAppGraphCtxLoader.module = SDL_LoadObject(moduleName);
+
+ gAppGraphCtxLoader.AppGraphCtxCreate_ptr = (AppGraphCtxCreate_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxCreate"));
+ gAppGraphCtxLoader.AppGraphCtxUpdateSize_ptr = (AppGraphCtxUpdateSize_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxUpdateSize"));
+ gAppGraphCtxLoader.AppGraphCtxReleaseRenderTarget_ptr = (AppGraphCtxReleaseRenderTarget_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxReleaseRenderTarget"));
+ gAppGraphCtxLoader.AppGraphCtxRelease_ptr = (AppGraphCtxRelease_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxRelease"));
+ gAppGraphCtxLoader.AppGraphCtxFrameStart_ptr = (AppGraphCtxFrameStart_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxFrameStart"));
+ gAppGraphCtxLoader.AppGraphCtxFramePresent_ptr = (AppGraphCtxFramePresent_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxFramePresent"));
+ gAppGraphCtxLoader.AppGraphCtxWaitForFrames_ptr = (AppGraphCtxWaitForFrames_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxWaitForFrames"));
+ gAppGraphCtxLoader.AppGraphCtxProfileEnable_ptr = (AppGraphCtxProfileEnable_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxProfileEnable"));
+ gAppGraphCtxLoader.AppGraphCtxProfileBegin_ptr = (AppGraphCtxProfileBegin_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxProfileBegin"));
+ gAppGraphCtxLoader.AppGraphCtxProfileEnd_ptr = (AppGraphCtxProfileEnd_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxProfileEnd"));
+ gAppGraphCtxLoader.AppGraphCtxProfileGet_ptr = (AppGraphCtxProfileGet_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxProfileGet"));
+ gAppGraphCtxLoader.AppGraphCtxDedicatedVideoMemory_ptr = (AppGraphCtxDedicatedVideoMemory_ptr_t)(appGraphCtxLoaderLoadFunction(&gAppGraphCtxLoader, "AppGraphCtxDedicatedVideoMemory"));
+}
+
+void unloadAppGraphCtx()
+{
+ gAppGraphCtxLoader.AppGraphCtxCreate_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxUpdateSize_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxReleaseRenderTarget_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxRelease_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxFrameStart_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxFramePresent_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxWaitForFrames_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxProfileEnable_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxProfileBegin_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxProfileEnd_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxProfileGet_ptr = nullptr;
+ gAppGraphCtxLoader.AppGraphCtxDedicatedVideoMemory_ptr = nullptr;
+
+ SDL_UnloadObject(gAppGraphCtxLoader.module);
+}
diff --git a/demo/DemoApp/computeContextLoader.cpp b/demo/DemoApp/computeContextLoader.cpp
index 593b2ce..396f8b5 100644
--- a/demo/DemoApp/computeContextLoader.cpp
+++ b/demo/DemoApp/computeContextLoader.cpp
@@ -14,134 +14,6 @@
#include "computeContext.h"
-namespace
-{
- ModuleLoader<32u, SDL_LoadObject, SDL_UnloadObject, SDL_LoadFunction> g_loader;
-}
+#include <stdio.h>
-void loadComputeContext(AppGraphCtxType type)
-{
- const char* moduleName = demoAppDLLName(type);
-
- g_loader.loadModule(moduleName);
-}
-
-void unloadComputeContext()
-{
- g_loader.unloadModule();
-}
-
-ComputeContext* ComputeContextCreate(ComputeContextDesc* desc)
-{
- return g_loader.function<0>(ComputeContextCreate, "ComputeContextCreate", desc);
-}
-
-void ComputeContextUpdate(ComputeContext* context, ComputeContextDesc* desc)
-{
- return g_loader.function<1>(ComputeContextUpdate, "ComputeContextUpdate", context, desc);
-}
-
-void ComputeContextRelease(ComputeContext* context)
-{
- return g_loader.function<2>(ComputeContextRelease, "ComputeContextRelease", context);
-}
-
-ComputeShader* ComputeShaderCreate(ComputeContext* context, const ComputeShaderDesc* desc)
-{
- return g_loader.function<3>(ComputeShaderCreate, "ComputeShaderCreate", context, desc);
-}
-
-void ComputeShaderRelease(ComputeShader* shader)
-{
- return g_loader.function<4>(ComputeShaderRelease, "ComputeShaderRelease", shader);
-}
-
-ComputeConstantBuffer* ComputeConstantBufferCreate(ComputeContext* context, const ComputeConstantBufferDesc* desc)
-{
- return g_loader.function<5>(ComputeConstantBufferCreate, "ComputeConstantBufferCreate", context, desc);
-}
-
-void ComputeConstantBufferRelease(ComputeConstantBuffer* constantBuffer)
-{
- return g_loader.function<6>(ComputeConstantBufferRelease, "ComputeConstantBufferRelease", constantBuffer);
-}
-
-void* ComputeConstantBufferMap(ComputeContext* context, ComputeConstantBuffer* constantBuffer)
-{
- return g_loader.function<7>(ComputeConstantBufferMap, "ComputeConstantBufferMap", context, constantBuffer);
-}
-
-void ComputeConstantBufferUnmap(ComputeContext* context, ComputeConstantBuffer* constantBuffer)
-{
- return g_loader.function<8>(ComputeConstantBufferUnmap, "ComputeConstantBufferUnmap", context, constantBuffer);
-}
-
-ComputeResource* ComputeResourceCreate(ComputeContext* context, const ComputeResourceDesc* desc)
-{
- return g_loader.function<9>(ComputeResourceCreate, "ComputeResourceCreate", context, desc);
-}
-
-void ComputeResourceUpdate(ComputeContext* context, ComputeResource* resource, const ComputeResourceDesc* desc)
-{
- return g_loader.function<10>(ComputeResourceUpdate, "ComputeResourceUpdate", context, resource, desc);
-}
-
-void ComputeResourceRelease(ComputeResource* resource)
-{
- return g_loader.function<11>(ComputeResourceRelease, "ComputeResourceRelease", resource);
-}
-
-ComputeResourceRW* ComputeResourceRWCreate(ComputeContext* context, const ComputeResourceRWDesc* desc)
-{
- return g_loader.function<12>(ComputeResourceRWCreate, "ComputeResourceRWCreate", context, desc);
-}
-
-void ComputeResourceRWUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, const ComputeResourceRWDesc* desc)
-{
- return g_loader.function<13>(ComputeResourceRWUpdate, "ComputeResourceRWUpdate", context, resourceRW, desc);
-}
-
-void ComputeResourceRWRelease(ComputeResourceRW* resourceRW)
-{
- return g_loader.function<14>(ComputeResourceRWRelease, "ComputeResourceRWRelease", resourceRW);
-}
-
-void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams* params)
-{
- return g_loader.function<15>(ComputeContextDispatch, "ComputeContextDispatch", context, params);
-}
-
-ComputeContext* ComputeContextNvFlowContextCreate(NvFlowContext* flowContext)
-{
- return g_loader.function<16>(ComputeContextNvFlowContextCreate, "ComputeContextNvFlowContextCreate", flowContext);
-}
-
-void ComputeContextNvFlowContextUpdate(ComputeContext* computeContext, NvFlowContext* flowContext)
-{
- return g_loader.function<17>(ComputeContextNvFlowContextUpdate, "ComputeContextNvFlowContextUpdate", computeContext, flowContext);
-}
-
-ComputeResource* ComputeResourceNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource)
-{
- return g_loader.function<18>(ComputeResourceNvFlowCreate, "ComputeResourceNvFlowCreate", context, flowContext, flowResource);
-}
-
-void ComputeResourceNvFlowUpdate(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource)
-{
- return g_loader.function<19>(ComputeResourceNvFlowUpdate, "ComputeResourceNvFlowUpdate", context, resource, flowContext, flowResource);
-}
-
-ComputeResourceRW* ComputeResourceRWNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
-{
- return g_loader.function<20>(ComputeResourceRWNvFlowCreate, "ComputeResourceRWNvFlowCreate", context, flowContext, flowResourceRW);
-}
-
-void ComputeResourceRWNvFlowUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
-{
- return g_loader.function<21>(ComputeResourceRWNvFlowUpdate, "ComputeResourceRWNvFlowUpdate", context, resourceRW, flowContext, flowResourceRW);
-}
-
-ComputeResource* ComputeResourceRWGetResource(ComputeResourceRW* resourceRW)
-{
- return g_loader.function<22>(ComputeResourceRWGetResource, "ComputeResourceRWGetResource", resourceRW);
-} \ No newline at end of file
+#include "computeContextLoaderGenerated.h" \ No newline at end of file
diff --git a/demo/DemoApp/computeContextLoaderGenerated.h b/demo/DemoApp/computeContextLoaderGenerated.h
new file mode 100644
index 0000000..b15775e
--- /dev/null
+++ b/demo/DemoApp/computeContextLoaderGenerated.h
@@ -0,0 +1,249 @@
+/*
+* 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.
+*/
+
+typedef ComputeContext* (*ComputeContextCreate_ptr_t)(ComputeContextDesc* desc);
+typedef void (*ComputeContextUpdate_ptr_t)(ComputeContext* context, ComputeContextDesc* desc);
+typedef void (*ComputeContextRelease_ptr_t)(ComputeContext* context);
+typedef ComputeShader* (*ComputeShaderCreate_ptr_t)(ComputeContext* context, const ComputeShaderDesc* desc);
+typedef void (*ComputeShaderRelease_ptr_t)(ComputeShader* shader);
+typedef ComputeConstantBuffer* (*ComputeConstantBufferCreate_ptr_t)(ComputeContext* context, const ComputeConstantBufferDesc* desc);
+typedef void (*ComputeConstantBufferRelease_ptr_t)(ComputeConstantBuffer* constantBuffer);
+typedef void* (*ComputeConstantBufferMap_ptr_t)(ComputeContext* context, ComputeConstantBuffer* constantBuffer);
+typedef void (*ComputeConstantBufferUnmap_ptr_t)(ComputeContext* context, ComputeConstantBuffer* constantBuffer);
+typedef ComputeResource* (*ComputeResourceCreate_ptr_t)(ComputeContext* context, const ComputeResourceDesc* desc);
+typedef void (*ComputeResourceUpdate_ptr_t)(ComputeContext* context, ComputeResource* resource, const ComputeResourceDesc* desc);
+typedef void (*ComputeResourceRelease_ptr_t)(ComputeResource* resource);
+typedef ComputeResourceRW* (*ComputeResourceRWCreate_ptr_t)(ComputeContext* context, const ComputeResourceRWDesc* desc);
+typedef void (*ComputeResourceRWUpdate_ptr_t)(ComputeContext* context, ComputeResourceRW* resourceRW, const ComputeResourceRWDesc* desc);
+typedef void (*ComputeResourceRWRelease_ptr_t)(ComputeResourceRW* resourceRW);
+typedef ComputeResource* (*ComputeResourceRWGetResource_ptr_t)(ComputeResourceRW* resourceRW);
+typedef void (*ComputeContextDispatch_ptr_t)(ComputeContext* context, const ComputeDispatchParams* params);
+typedef ComputeContext* (*ComputeContextNvFlowContextCreate_ptr_t)(NvFlowContext* flowContext);
+typedef void (*ComputeContextNvFlowContextUpdate_ptr_t)(ComputeContext* computeContext, NvFlowContext* flowContext);
+typedef ComputeResource* (*ComputeResourceNvFlowCreate_ptr_t)(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource);
+typedef void (*ComputeResourceNvFlowUpdate_ptr_t)(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource);
+typedef ComputeResourceRW* (*ComputeResourceRWNvFlowCreate_ptr_t)(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW);
+typedef void (*ComputeResourceRWNvFlowUpdate_ptr_t)(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW);
+
+struct ComputeContextLoader
+{
+ void* module = nullptr;
+ const char* suffix = "";
+ char buf[1024u];
+
+ ComputeContextCreate_ptr_t ComputeContextCreate_ptr;
+ ComputeContextUpdate_ptr_t ComputeContextUpdate_ptr;
+ ComputeContextRelease_ptr_t ComputeContextRelease_ptr;
+ ComputeShaderCreate_ptr_t ComputeShaderCreate_ptr;
+ ComputeShaderRelease_ptr_t ComputeShaderRelease_ptr;
+ ComputeConstantBufferCreate_ptr_t ComputeConstantBufferCreate_ptr;
+ ComputeConstantBufferRelease_ptr_t ComputeConstantBufferRelease_ptr;
+ ComputeConstantBufferMap_ptr_t ComputeConstantBufferMap_ptr;
+ ComputeConstantBufferUnmap_ptr_t ComputeConstantBufferUnmap_ptr;
+ ComputeResourceCreate_ptr_t ComputeResourceCreate_ptr;
+ ComputeResourceUpdate_ptr_t ComputeResourceUpdate_ptr;
+ ComputeResourceRelease_ptr_t ComputeResourceRelease_ptr;
+ ComputeResourceRWCreate_ptr_t ComputeResourceRWCreate_ptr;
+ ComputeResourceRWUpdate_ptr_t ComputeResourceRWUpdate_ptr;
+ ComputeResourceRWRelease_ptr_t ComputeResourceRWRelease_ptr;
+ ComputeResourceRWGetResource_ptr_t ComputeResourceRWGetResource_ptr;
+ ComputeContextDispatch_ptr_t ComputeContextDispatch_ptr;
+ ComputeContextNvFlowContextCreate_ptr_t ComputeContextNvFlowContextCreate_ptr;
+ ComputeContextNvFlowContextUpdate_ptr_t ComputeContextNvFlowContextUpdate_ptr;
+ ComputeResourceNvFlowCreate_ptr_t ComputeResourceNvFlowCreate_ptr;
+ ComputeResourceNvFlowUpdate_ptr_t ComputeResourceNvFlowUpdate_ptr;
+ ComputeResourceRWNvFlowCreate_ptr_t ComputeResourceRWNvFlowCreate_ptr;
+ ComputeResourceRWNvFlowUpdate_ptr_t ComputeResourceRWNvFlowUpdate_ptr;
+
+}gComputeContextLoader;
+
+ComputeContext* ComputeContextCreate(ComputeContextDesc* desc)
+{
+ return gComputeContextLoader.ComputeContextCreate_ptr(desc);
+}
+
+void ComputeContextUpdate(ComputeContext* context, ComputeContextDesc* desc)
+{
+ return gComputeContextLoader.ComputeContextUpdate_ptr(context, desc);
+}
+
+void ComputeContextRelease(ComputeContext* context)
+{
+ return gComputeContextLoader.ComputeContextRelease_ptr(context);
+}
+
+ComputeShader* ComputeShaderCreate(ComputeContext* context, const ComputeShaderDesc* desc)
+{
+ return gComputeContextLoader.ComputeShaderCreate_ptr(context, desc);
+}
+
+void ComputeShaderRelease(ComputeShader* shader)
+{
+ return gComputeContextLoader.ComputeShaderRelease_ptr(shader);
+}
+
+ComputeConstantBuffer* ComputeConstantBufferCreate(ComputeContext* context, const ComputeConstantBufferDesc* desc)
+{
+ return gComputeContextLoader.ComputeConstantBufferCreate_ptr(context, desc);
+}
+
+void ComputeConstantBufferRelease(ComputeConstantBuffer* constantBuffer)
+{
+ return gComputeContextLoader.ComputeConstantBufferRelease_ptr(constantBuffer);
+}
+
+void* ComputeConstantBufferMap(ComputeContext* context, ComputeConstantBuffer* constantBuffer)
+{
+ return gComputeContextLoader.ComputeConstantBufferMap_ptr(context, constantBuffer);
+}
+
+void ComputeConstantBufferUnmap(ComputeContext* context, ComputeConstantBuffer* constantBuffer)
+{
+ return gComputeContextLoader.ComputeConstantBufferUnmap_ptr(context, constantBuffer);
+}
+
+ComputeResource* ComputeResourceCreate(ComputeContext* context, const ComputeResourceDesc* desc)
+{
+ return gComputeContextLoader.ComputeResourceCreate_ptr(context, desc);
+}
+
+void ComputeResourceUpdate(ComputeContext* context, ComputeResource* resource, const ComputeResourceDesc* desc)
+{
+ return gComputeContextLoader.ComputeResourceUpdate_ptr(context, resource, desc);
+}
+
+void ComputeResourceRelease(ComputeResource* resource)
+{
+ return gComputeContextLoader.ComputeResourceRelease_ptr(resource);
+}
+
+ComputeResourceRW* ComputeResourceRWCreate(ComputeContext* context, const ComputeResourceRWDesc* desc)
+{
+ return gComputeContextLoader.ComputeResourceRWCreate_ptr(context, desc);
+}
+
+void ComputeResourceRWUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, const ComputeResourceRWDesc* desc)
+{
+ return gComputeContextLoader.ComputeResourceRWUpdate_ptr(context, resourceRW, desc);
+}
+
+void ComputeResourceRWRelease(ComputeResourceRW* resourceRW)
+{
+ return gComputeContextLoader.ComputeResourceRWRelease_ptr(resourceRW);
+}
+
+ComputeResource* ComputeResourceRWGetResource(ComputeResourceRW* resourceRW)
+{
+ return gComputeContextLoader.ComputeResourceRWGetResource_ptr(resourceRW);
+}
+
+void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams* params)
+{
+ return gComputeContextLoader.ComputeContextDispatch_ptr(context, params);
+}
+
+ComputeContext* ComputeContextNvFlowContextCreate(NvFlowContext* flowContext)
+{
+ return gComputeContextLoader.ComputeContextNvFlowContextCreate_ptr(flowContext);
+}
+
+void ComputeContextNvFlowContextUpdate(ComputeContext* computeContext, NvFlowContext* flowContext)
+{
+ return gComputeContextLoader.ComputeContextNvFlowContextUpdate_ptr(computeContext, flowContext);
+}
+
+ComputeResource* ComputeResourceNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource)
+{
+ return gComputeContextLoader.ComputeResourceNvFlowCreate_ptr(context, flowContext, flowResource);
+}
+
+void ComputeResourceNvFlowUpdate(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource)
+{
+ return gComputeContextLoader.ComputeResourceNvFlowUpdate_ptr(context, resource, flowContext, flowResource);
+}
+
+ComputeResourceRW* ComputeResourceRWNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
+{
+ return gComputeContextLoader.ComputeResourceRWNvFlowCreate_ptr(context, flowContext, flowResourceRW);
+}
+
+void ComputeResourceRWNvFlowUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
+{
+ return gComputeContextLoader.ComputeResourceRWNvFlowUpdate_ptr(context, resourceRW, flowContext, flowResourceRW);
+}
+
+void* computeContextLoaderLoadFunction(ComputeContextLoader* inst, const char* name)
+{
+ snprintf(inst->buf, 1024u, "%s%s", name, inst->suffix);
+
+ return SDL_LoadFunction(inst->module, inst->buf);
+}
+
+void loadComputeContext(AppGraphCtxType type)
+{
+ const char* moduleName = demoAppDLLName(type);
+
+ gComputeContextLoader.suffix = demoAppBackendSuffix(type);
+
+ gComputeContextLoader.module = SDL_LoadObject(moduleName);
+
+ gComputeContextLoader.ComputeContextCreate_ptr = (ComputeContextCreate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeContextCreate"));
+ gComputeContextLoader.ComputeContextUpdate_ptr = (ComputeContextUpdate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeContextUpdate"));
+ gComputeContextLoader.ComputeContextRelease_ptr = (ComputeContextRelease_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeContextRelease"));
+ gComputeContextLoader.ComputeShaderCreate_ptr = (ComputeShaderCreate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeShaderCreate"));
+ gComputeContextLoader.ComputeShaderRelease_ptr = (ComputeShaderRelease_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeShaderRelease"));
+ gComputeContextLoader.ComputeConstantBufferCreate_ptr = (ComputeConstantBufferCreate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeConstantBufferCreate"));
+ gComputeContextLoader.ComputeConstantBufferRelease_ptr = (ComputeConstantBufferRelease_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeConstantBufferRelease"));
+ gComputeContextLoader.ComputeConstantBufferMap_ptr = (ComputeConstantBufferMap_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeConstantBufferMap"));
+ gComputeContextLoader.ComputeConstantBufferUnmap_ptr = (ComputeConstantBufferUnmap_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeConstantBufferUnmap"));
+ gComputeContextLoader.ComputeResourceCreate_ptr = (ComputeResourceCreate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceCreate"));
+ gComputeContextLoader.ComputeResourceUpdate_ptr = (ComputeResourceUpdate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceUpdate"));
+ gComputeContextLoader.ComputeResourceRelease_ptr = (ComputeResourceRelease_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceRelease"));
+ gComputeContextLoader.ComputeResourceRWCreate_ptr = (ComputeResourceRWCreate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceRWCreate"));
+ gComputeContextLoader.ComputeResourceRWUpdate_ptr = (ComputeResourceRWUpdate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceRWUpdate"));
+ gComputeContextLoader.ComputeResourceRWRelease_ptr = (ComputeResourceRWRelease_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceRWRelease"));
+ gComputeContextLoader.ComputeResourceRWGetResource_ptr = (ComputeResourceRWGetResource_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceRWGetResource"));
+ gComputeContextLoader.ComputeContextDispatch_ptr = (ComputeContextDispatch_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeContextDispatch"));
+ gComputeContextLoader.ComputeContextNvFlowContextCreate_ptr = (ComputeContextNvFlowContextCreate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeContextNvFlowContextCreate"));
+ gComputeContextLoader.ComputeContextNvFlowContextUpdate_ptr = (ComputeContextNvFlowContextUpdate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeContextNvFlowContextUpdate"));
+ gComputeContextLoader.ComputeResourceNvFlowCreate_ptr = (ComputeResourceNvFlowCreate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceNvFlowCreate"));
+ gComputeContextLoader.ComputeResourceNvFlowUpdate_ptr = (ComputeResourceNvFlowUpdate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceNvFlowUpdate"));
+ gComputeContextLoader.ComputeResourceRWNvFlowCreate_ptr = (ComputeResourceRWNvFlowCreate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceRWNvFlowCreate"));
+ gComputeContextLoader.ComputeResourceRWNvFlowUpdate_ptr = (ComputeResourceRWNvFlowUpdate_ptr_t)(computeContextLoaderLoadFunction(&gComputeContextLoader, "ComputeResourceRWNvFlowUpdate"));
+}
+
+void unloadComputeContext()
+{
+ gComputeContextLoader.ComputeContextCreate_ptr = nullptr;
+ gComputeContextLoader.ComputeContextUpdate_ptr = nullptr;
+ gComputeContextLoader.ComputeContextRelease_ptr = nullptr;
+ gComputeContextLoader.ComputeShaderCreate_ptr = nullptr;
+ gComputeContextLoader.ComputeShaderRelease_ptr = nullptr;
+ gComputeContextLoader.ComputeConstantBufferCreate_ptr = nullptr;
+ gComputeContextLoader.ComputeConstantBufferRelease_ptr = nullptr;
+ gComputeContextLoader.ComputeConstantBufferMap_ptr = nullptr;
+ gComputeContextLoader.ComputeConstantBufferUnmap_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceCreate_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceUpdate_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceRelease_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceRWCreate_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceRWUpdate_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceRWRelease_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceRWGetResource_ptr = nullptr;
+ gComputeContextLoader.ComputeContextDispatch_ptr = nullptr;
+ gComputeContextLoader.ComputeContextNvFlowContextCreate_ptr = nullptr;
+ gComputeContextLoader.ComputeContextNvFlowContextUpdate_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceNvFlowCreate_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceNvFlowUpdate_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceRWNvFlowCreate_ptr = nullptr;
+ gComputeContextLoader.ComputeResourceRWNvFlowUpdate_ptr = nullptr;
+
+ SDL_UnloadObject(gComputeContextLoader.module);
+}
diff --git a/demo/DemoApp/imguiGraphLoader.cpp b/demo/DemoApp/imguiGraphLoader.cpp
index 155e9f3..f628196 100644
--- a/demo/DemoApp/imguiGraphLoader.cpp
+++ b/demo/DemoApp/imguiGraphLoader.cpp
@@ -15,111 +15,6 @@
#include "imguiGraph.h"
#include "imguiInterop.h"
-namespace
-{
- ModuleLoader<24u, SDL_LoadObject, SDL_UnloadObject, SDL_LoadFunction> g_loader;
-}
+#include <stdio.h>
-void loadImgui(AppGraphCtxType type)
-{
- const char* moduleName = demoAppDLLName(type);
-
- g_loader.loadModule(moduleName);
-}
-
-void unloadImgui()
-{
- g_loader.unloadModule();
-}
-
-// Below are the functions that must be implemented per graphics API
-
-void imguiGraphContextInit(const ImguiGraphDesc* desc)
-{
- return g_loader.function<0>(imguiGraphContextInit, "imguiGraphContextInit", desc);
-}
-
-void imguiGraphContextUpdate(const ImguiGraphDesc* desc)
-{
- return g_loader.function<1>(imguiGraphContextUpdate, "imguiGraphContextUpdate", desc);
-}
-
-void imguiGraphContextDestroy()
-{
- return g_loader.function<2>(imguiGraphContextDestroy, "imguiGraphContextDestroy");
-}
-
-void imguiGraphRecordBegin()
-{
- return g_loader.function<3>(imguiGraphRecordBegin, "imguiGraphRecordBegin");
-}
-
-void imguiGraphRecordEnd()
-{
- return g_loader.function<4>(imguiGraphRecordEnd, "imguiGraphRecordEnd");
-}
-
-void imguiGraphVertex2f(float x, float y)
-{
- return g_loader.function<5>(imguiGraphVertex2f, "imguiGraphVertex2f", x, y);
-}
-
-void imguiGraphVertex2fv(const float* v)
-{
- return g_loader.function<6>(imguiGraphVertex2fv, "imguiGraphVertex2fv", v);
-}
-
-void imguiGraphTexCoord2f(float u, float v)
-{
- return g_loader.function<7>(imguiGraphTexCoord2f, "imguiGraphTexCoord2f", u, v);
-}
-
-void imguiGraphColor4ub(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
-{
- return g_loader.function<8>(imguiGraphColor4ub, "imguiGraphColor4ub", red, green, blue, alpha);
-}
-
-void imguiGraphColor4ubv(const uint8_t* v)
-{
- return g_loader.function<9>(imguiGraphColor4ubv, "imguiGraphColor4ubv", v);
-}
-
-void imguiGraphFontTextureEnable()
-{
- return g_loader.function<10>(imguiGraphFontTextureEnable, "imguiGraphFontTextureEnable");
-}
-
-void imguiGraphFontTextureDisable()
-{
- return g_loader.function<11>(imguiGraphFontTextureDisable, "imguiGraphFontTextureDisable");
-}
-
-void imguiGraphEnableScissor(int x, int y, int width, int height)
-{
- return g_loader.function<12>(imguiGraphEnableScissor, "imguiGraphEnableScissor", x, y, width, height);
-}
-
-void imguiGraphDisableScissor()
-{
- return g_loader.function<13>(imguiGraphDisableScissor, "imguiGraphDisableScissor");
-}
-
-void imguiGraphFontTextureInit(unsigned char* data)
-{
- return g_loader.function<14>(imguiGraphFontTextureInit, "imguiGraphFontTextureInit",data);
-}
-
-void imguiGraphFontTextureRelease()
-{
- return g_loader.function<15>(imguiGraphFontTextureRelease, "imguiGraphFontTextureRelease");
-}
-
-bool imguiInteropGraphInit(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx)
-{
- return g_loader.function<16>(imguiInteropGraphInit, "imguiInteropGraphInit", func, fontpath, appctx);
-}
-
-void imguiInteropGraphUpdate(imguiGraphUpdate_t func, AppGraphCtx* appctx)
-{
- return g_loader.function<17>(imguiInteropGraphUpdate, "imguiInteropGraphUpdate", func, appctx);
-} \ No newline at end of file
+#include "imguiGraphLoaderGenerated.h" \ No newline at end of file
diff --git a/demo/DemoApp/imguiGraphLoaderGenerated.h b/demo/DemoApp/imguiGraphLoaderGenerated.h
new file mode 100644
index 0000000..ab7ae55
--- /dev/null
+++ b/demo/DemoApp/imguiGraphLoaderGenerated.h
@@ -0,0 +1,204 @@
+/*
+* 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.
+*/
+
+typedef void (*imguiGraphContextInit_ptr_t)(const ImguiGraphDesc* desc);
+typedef void (*imguiGraphContextUpdate_ptr_t)(const ImguiGraphDesc* desc);
+typedef void (*imguiGraphContextDestroy_ptr_t)();
+typedef void (*imguiGraphRecordBegin_ptr_t)();
+typedef void (*imguiGraphRecordEnd_ptr_t)();
+typedef void (*imguiGraphVertex2f_ptr_t)(float x, float y);
+typedef void (*imguiGraphVertex2fv_ptr_t)(const float* v);
+typedef void (*imguiGraphTexCoord2f_ptr_t)(float u, float v);
+typedef void (*imguiGraphColor4ub_ptr_t)(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
+typedef void (*imguiGraphColor4ubv_ptr_t)(const uint8_t* v);
+typedef void (*imguiGraphFontTextureEnable_ptr_t)();
+typedef void (*imguiGraphFontTextureDisable_ptr_t)();
+typedef void (*imguiGraphEnableScissor_ptr_t)(int x, int y, int width, int height);
+typedef void (*imguiGraphDisableScissor_ptr_t)();
+typedef void (*imguiGraphFontTextureInit_ptr_t)(unsigned char* data);
+typedef void (*imguiGraphFontTextureRelease_ptr_t)();
+typedef bool (*imguiInteropGraphInit_ptr_t)(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx);
+typedef void (*imguiInteropGraphUpdate_ptr_t)(imguiGraphUpdate_t func, AppGraphCtx* appctx);
+
+struct ImguiLoader
+{
+ void* module = nullptr;
+ const char* suffix = "";
+ char buf[1024u];
+
+ imguiGraphContextInit_ptr_t imguiGraphContextInit_ptr;
+ imguiGraphContextUpdate_ptr_t imguiGraphContextUpdate_ptr;
+ imguiGraphContextDestroy_ptr_t imguiGraphContextDestroy_ptr;
+ imguiGraphRecordBegin_ptr_t imguiGraphRecordBegin_ptr;
+ imguiGraphRecordEnd_ptr_t imguiGraphRecordEnd_ptr;
+ imguiGraphVertex2f_ptr_t imguiGraphVertex2f_ptr;
+ imguiGraphVertex2fv_ptr_t imguiGraphVertex2fv_ptr;
+ imguiGraphTexCoord2f_ptr_t imguiGraphTexCoord2f_ptr;
+ imguiGraphColor4ub_ptr_t imguiGraphColor4ub_ptr;
+ imguiGraphColor4ubv_ptr_t imguiGraphColor4ubv_ptr;
+ imguiGraphFontTextureEnable_ptr_t imguiGraphFontTextureEnable_ptr;
+ imguiGraphFontTextureDisable_ptr_t imguiGraphFontTextureDisable_ptr;
+ imguiGraphEnableScissor_ptr_t imguiGraphEnableScissor_ptr;
+ imguiGraphDisableScissor_ptr_t imguiGraphDisableScissor_ptr;
+ imguiGraphFontTextureInit_ptr_t imguiGraphFontTextureInit_ptr;
+ imguiGraphFontTextureRelease_ptr_t imguiGraphFontTextureRelease_ptr;
+ imguiInteropGraphInit_ptr_t imguiInteropGraphInit_ptr;
+ imguiInteropGraphUpdate_ptr_t imguiInteropGraphUpdate_ptr;
+
+}gImguiLoader;
+
+void imguiGraphContextInit(const ImguiGraphDesc* desc)
+{
+ return gImguiLoader.imguiGraphContextInit_ptr(desc);
+}
+
+void imguiGraphContextUpdate(const ImguiGraphDesc* desc)
+{
+ return gImguiLoader.imguiGraphContextUpdate_ptr(desc);
+}
+
+void imguiGraphContextDestroy()
+{
+ return gImguiLoader.imguiGraphContextDestroy_ptr();
+}
+
+void imguiGraphRecordBegin()
+{
+ return gImguiLoader.imguiGraphRecordBegin_ptr();
+}
+
+void imguiGraphRecordEnd()
+{
+ return gImguiLoader.imguiGraphRecordEnd_ptr();
+}
+
+void imguiGraphVertex2f(float x, float y)
+{
+ return gImguiLoader.imguiGraphVertex2f_ptr(x, y);
+}
+
+void imguiGraphVertex2fv(const float* v)
+{
+ return gImguiLoader.imguiGraphVertex2fv_ptr(v);
+}
+
+void imguiGraphTexCoord2f(float u, float v)
+{
+ return gImguiLoader.imguiGraphTexCoord2f_ptr(u, v);
+}
+
+void imguiGraphColor4ub(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+ return gImguiLoader.imguiGraphColor4ub_ptr(red, green, blue, alpha);
+}
+
+void imguiGraphColor4ubv(const uint8_t* v)
+{
+ return gImguiLoader.imguiGraphColor4ubv_ptr(v);
+}
+
+void imguiGraphFontTextureEnable()
+{
+ return gImguiLoader.imguiGraphFontTextureEnable_ptr();
+}
+
+void imguiGraphFontTextureDisable()
+{
+ return gImguiLoader.imguiGraphFontTextureDisable_ptr();
+}
+
+void imguiGraphEnableScissor(int x, int y, int width, int height)
+{
+ return gImguiLoader.imguiGraphEnableScissor_ptr(x, y, width, height);
+}
+
+void imguiGraphDisableScissor()
+{
+ return gImguiLoader.imguiGraphDisableScissor_ptr();
+}
+
+void imguiGraphFontTextureInit(unsigned char* data)
+{
+ return gImguiLoader.imguiGraphFontTextureInit_ptr(data);
+}
+
+void imguiGraphFontTextureRelease()
+{
+ return gImguiLoader.imguiGraphFontTextureRelease_ptr();
+}
+
+bool imguiInteropGraphInit(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx)
+{
+ return gImguiLoader.imguiInteropGraphInit_ptr(func, fontpath, appctx);
+}
+
+void imguiInteropGraphUpdate(imguiGraphUpdate_t func, AppGraphCtx* appctx)
+{
+ return gImguiLoader.imguiInteropGraphUpdate_ptr(func, appctx);
+}
+
+void* imguiLoaderLoadFunction(ImguiLoader* inst, const char* name)
+{
+ snprintf(inst->buf, 1024u, "%s%s", name, inst->suffix);
+
+ return SDL_LoadFunction(inst->module, inst->buf);
+}
+
+void loadImgui(AppGraphCtxType type)
+{
+ const char* moduleName = demoAppDLLName(type);
+
+ gImguiLoader.suffix = demoAppBackendSuffix(type);
+
+ gImguiLoader.module = SDL_LoadObject(moduleName);
+
+ gImguiLoader.imguiGraphContextInit_ptr = (imguiGraphContextInit_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphContextInit"));
+ gImguiLoader.imguiGraphContextUpdate_ptr = (imguiGraphContextUpdate_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphContextUpdate"));
+ gImguiLoader.imguiGraphContextDestroy_ptr = (imguiGraphContextDestroy_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphContextDestroy"));
+ gImguiLoader.imguiGraphRecordBegin_ptr = (imguiGraphRecordBegin_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphRecordBegin"));
+ gImguiLoader.imguiGraphRecordEnd_ptr = (imguiGraphRecordEnd_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphRecordEnd"));
+ gImguiLoader.imguiGraphVertex2f_ptr = (imguiGraphVertex2f_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphVertex2f"));
+ gImguiLoader.imguiGraphVertex2fv_ptr = (imguiGraphVertex2fv_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphVertex2fv"));
+ gImguiLoader.imguiGraphTexCoord2f_ptr = (imguiGraphTexCoord2f_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphTexCoord2f"));
+ gImguiLoader.imguiGraphColor4ub_ptr = (imguiGraphColor4ub_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphColor4ub"));
+ gImguiLoader.imguiGraphColor4ubv_ptr = (imguiGraphColor4ubv_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphColor4ubv"));
+ gImguiLoader.imguiGraphFontTextureEnable_ptr = (imguiGraphFontTextureEnable_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphFontTextureEnable"));
+ gImguiLoader.imguiGraphFontTextureDisable_ptr = (imguiGraphFontTextureDisable_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphFontTextureDisable"));
+ gImguiLoader.imguiGraphEnableScissor_ptr = (imguiGraphEnableScissor_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphEnableScissor"));
+ gImguiLoader.imguiGraphDisableScissor_ptr = (imguiGraphDisableScissor_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphDisableScissor"));
+ gImguiLoader.imguiGraphFontTextureInit_ptr = (imguiGraphFontTextureInit_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphFontTextureInit"));
+ gImguiLoader.imguiGraphFontTextureRelease_ptr = (imguiGraphFontTextureRelease_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiGraphFontTextureRelease"));
+ gImguiLoader.imguiInteropGraphInit_ptr = (imguiInteropGraphInit_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiInteropGraphInit"));
+ gImguiLoader.imguiInteropGraphUpdate_ptr = (imguiInteropGraphUpdate_ptr_t)(imguiLoaderLoadFunction(&gImguiLoader, "imguiInteropGraphUpdate"));
+}
+
+void unloadImgui()
+{
+ gImguiLoader.imguiGraphContextInit_ptr = nullptr;
+ gImguiLoader.imguiGraphContextUpdate_ptr = nullptr;
+ gImguiLoader.imguiGraphContextDestroy_ptr = nullptr;
+ gImguiLoader.imguiGraphRecordBegin_ptr = nullptr;
+ gImguiLoader.imguiGraphRecordEnd_ptr = nullptr;
+ gImguiLoader.imguiGraphVertex2f_ptr = nullptr;
+ gImguiLoader.imguiGraphVertex2fv_ptr = nullptr;
+ gImguiLoader.imguiGraphTexCoord2f_ptr = nullptr;
+ gImguiLoader.imguiGraphColor4ub_ptr = nullptr;
+ gImguiLoader.imguiGraphColor4ubv_ptr = nullptr;
+ gImguiLoader.imguiGraphFontTextureEnable_ptr = nullptr;
+ gImguiLoader.imguiGraphFontTextureDisable_ptr = nullptr;
+ gImguiLoader.imguiGraphEnableScissor_ptr = nullptr;
+ gImguiLoader.imguiGraphDisableScissor_ptr = nullptr;
+ gImguiLoader.imguiGraphFontTextureInit_ptr = nullptr;
+ gImguiLoader.imguiGraphFontTextureRelease_ptr = nullptr;
+ gImguiLoader.imguiInteropGraphInit_ptr = nullptr;
+ gImguiLoader.imguiInteropGraphUpdate_ptr = nullptr;
+
+ SDL_UnloadObject(gImguiLoader.module);
+}
diff --git a/demo/DemoApp/loader.h b/demo/DemoApp/loader.h
index 3028325..f0c1aaf 100644
--- a/demo/DemoApp/loader.h
+++ b/demo/DemoApp/loader.h
@@ -28,6 +28,13 @@ namespace
"DemoAppD3D11" XDEMOAPP_STR(DLL_SUFFIX) ".dll";
}
+ const char* demoAppBackendSuffix(AppGraphCtxType type)
+ {
+ return (type == APP_CONTEXT_D3D12) ?
+ "D3D12" :
+ "D3D11";
+ }
+
const char* nvFlowDLLName(AppGraphCtxType type)
{
return (type == APP_CONTEXT_D3D12) ?
@@ -52,61 +59,4 @@ void loadImgui(AppGraphCtxType type);
void unloadImgui();
void loadComputeContext(AppGraphCtxType type);
-void unloadComputeContext();
-
-template<unsigned int maxFunctionCount, void* loadobject(const char*), void unloadobject(void*), void* loadfunction(void*,const char*)>
-struct ModuleLoader
-{
- static const int m_functionCount = maxFunctionCount;
- void** m_functionPtrs[m_functionCount] = { nullptr };
- const char* m_functionNames[m_functionCount] = { nullptr };
-
- void* m_module = nullptr;
-
- void* loadFunction(const char* name, int uid, void** ptr)
- {
- m_functionPtrs[uid] = ptr;
- m_functionNames[uid] = name;
- return SDL_LoadFunction(m_module, name);
- }
-
- template <int uid, class ret, class ...Args>
- ret function(ret(*)(Args...args), const char* name, Args...args)
- {
- static void* func = loadFunction(name, uid, &func);
-
- return ((ret(*)(Args...args))func)(args...);
- }
-
- void loadModule(const char* moduleName)
- {
- m_module = loadobject(moduleName);
-
- // load functions with non-null names
- for (int i = 0; i < m_functionCount; i++)
- {
- const char* name = m_functionNames[i];
- void** funcPtr = m_functionPtrs[i];
- if (name && funcPtr)
- {
- *funcPtr = loadfunction(m_module, name);
- }
- }
- }
-
- void unloadModule()
- {
- unloadobject(m_module);
-
- for (int i = 0; i < m_functionCount; i++)
- {
- void** funcPtr = m_functionPtrs[i];
- if (funcPtr)
- {
- *funcPtr = nullptr;
- }
- }
- }
-
- ModuleLoader() {}
-}; \ No newline at end of file
+void unloadComputeContext(); \ No newline at end of file
diff --git a/demo/DemoApp/main.cpp b/demo/DemoApp/main.cpp
index e35ea43..45ccfa8 100644
--- a/demo/DemoApp/main.cpp
+++ b/demo/DemoApp/main.cpp
@@ -67,24 +67,18 @@ bool gImguiActive = false;
bool g_imguiHide = false;
bool gClearDark = false;
-float gClearVal[4] = { 0.33f,0.33f,0.33f,1.f };
+AppGraphColor gClearVal = { 0.33f,0.33f,0.33f,1.f };
void toggleDark()
{
gClearDark = !gClearDark;
if (gClearDark)
{
- gClearVal[0] = 0.f;
- gClearVal[1] = 0.f;
- gClearVal[2] = 0.f;
- gClearVal[3] = 1.f;
+ gClearVal = { 0.f, 0.f, 0.f, 1.f };
}
else
{
- gClearVal[0] = 0.33f;
- gClearVal[1] = 0.33f;
- gClearVal[2] = 0.33f;
- gClearVal[3] = 1.f;
+ gClearVal = { 0.33f, 0.33f, 0.33f, 1.f };
}
}
diff --git a/demo/DemoApp/meshLoader.cpp b/demo/DemoApp/meshLoader.cpp
index 99e5e49..2d70414 100644
--- a/demo/DemoApp/meshLoader.cpp
+++ b/demo/DemoApp/meshLoader.cpp
@@ -15,69 +15,6 @@
#include "mesh.h"
#include "meshInterop.h"
-namespace
-{
- ModuleLoader<16u, SDL_LoadObject, SDL_UnloadObject, SDL_LoadFunction> g_loader;
-}
+#include <stdio.h>
-void loadMesh(AppGraphCtxType type)
-{
- const char* moduleName = demoAppDLLName(type);
-
- g_loader.loadModule(moduleName);
-}
-
-void unloadMesh()
-{
- g_loader.unloadModule();
-}
-
-MeshContext* MeshContextCreate(const MeshContextDesc* desc)
-{
- return g_loader.function<0>(MeshContextCreate, "MeshContextCreate", desc);
-}
-
-void MeshContextUpdate(MeshContext* context, const MeshContextDesc* desc)
-{
- return g_loader.function<1>(MeshContextUpdate, "MeshContextUpdate", context, desc);
-}
-
-void MeshContextRelease(MeshContext* context)
-{
- return g_loader.function<2>(MeshContextRelease, "MeshContextRelease", context);
-}
-
-MeshIndexBuffer* MeshIndexBufferCreate(MeshContext* context, MeshUint* indices, MeshUint numIndices)
-{
- return g_loader.function<3>(MeshIndexBufferCreate, "MeshIndexBufferCreate", context, indices, numIndices);
-}
-
-void MeshIndexBufferRelease(MeshIndexBuffer* buffer)
-{
- return g_loader.function<4>(MeshIndexBufferRelease, "MeshIndexBufferRelease", buffer);
-}
-
-MeshVertexBuffer* MeshVertexBufferCreate(MeshContext* context, MeshVertex* vertices, MeshUint numVertices)
-{
- return g_loader.function<5>(MeshVertexBufferCreate, "MeshVertexBufferCreate", context, vertices, numVertices);
-}
-
-void MeshVertexBufferRelease(MeshVertexBuffer* buffer)
-{
- return g_loader.function<6>(MeshVertexBufferRelease, "MeshVertexBufferRelease", buffer);
-}
-
-void MeshContextDraw(MeshContext* context, const MeshContextDrawParams* params)
-{
- return g_loader.function<7>(MeshContextDraw, "MeshContextDraw", context, params);
-}
-
-MeshContext* MeshInteropContextCreate(AppGraphCtx* appctx)
-{
- return g_loader.function<8>(MeshInteropContextCreate, "MeshInteropContextCreate", appctx);
-}
-
-void MeshInteropContextUpdate(MeshContext* context, AppGraphCtx* appctx)
-{
- return g_loader.function<9>(MeshInteropContextUpdate, "MeshInteropContextUpdate", context, appctx);
-} \ No newline at end of file
+#include "meshLoaderGenerated.h" \ No newline at end of file
diff --git a/demo/DemoApp/meshLoaderGenerated.h b/demo/DemoApp/meshLoaderGenerated.h
new file mode 100644
index 0000000..c931f4f
--- /dev/null
+++ b/demo/DemoApp/meshLoaderGenerated.h
@@ -0,0 +1,132 @@
+/*
+* 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.
+*/
+
+typedef MeshContext* (*MeshContextCreate_ptr_t)(const MeshContextDesc* desc);
+typedef void (*MeshContextUpdate_ptr_t)(MeshContext* context, const MeshContextDesc* desc);
+typedef void (*MeshContextRelease_ptr_t)(MeshContext* context);
+typedef MeshIndexBuffer* (*MeshIndexBufferCreate_ptr_t)(MeshContext* context, MeshUint* indices, MeshUint numIndices);
+typedef void (*MeshIndexBufferRelease_ptr_t)(MeshIndexBuffer* buffer);
+typedef MeshVertexBuffer* (*MeshVertexBufferCreate_ptr_t)(MeshContext* context, MeshVertex* vertices, MeshUint numVertices);
+typedef void (*MeshVertexBufferRelease_ptr_t)(MeshVertexBuffer* buffer);
+typedef void (*MeshContextDraw_ptr_t)(MeshContext* context, const MeshContextDrawParams* params);
+typedef MeshContext* (*MeshInteropContextCreate_ptr_t)(AppGraphCtx* appctx);
+typedef void (*MeshInteropContextUpdate_ptr_t)(MeshContext* context, AppGraphCtx* appctx);
+
+struct MeshLoader
+{
+ void* module = nullptr;
+ const char* suffix = "";
+ char buf[1024u];
+
+ MeshContextCreate_ptr_t MeshContextCreate_ptr;
+ MeshContextUpdate_ptr_t MeshContextUpdate_ptr;
+ MeshContextRelease_ptr_t MeshContextRelease_ptr;
+ MeshIndexBufferCreate_ptr_t MeshIndexBufferCreate_ptr;
+ MeshIndexBufferRelease_ptr_t MeshIndexBufferRelease_ptr;
+ MeshVertexBufferCreate_ptr_t MeshVertexBufferCreate_ptr;
+ MeshVertexBufferRelease_ptr_t MeshVertexBufferRelease_ptr;
+ MeshContextDraw_ptr_t MeshContextDraw_ptr;
+ MeshInteropContextCreate_ptr_t MeshInteropContextCreate_ptr;
+ MeshInteropContextUpdate_ptr_t MeshInteropContextUpdate_ptr;
+
+}gMeshLoader;
+
+MeshContext* MeshContextCreate(const MeshContextDesc* desc)
+{
+ return gMeshLoader.MeshContextCreate_ptr(desc);
+}
+
+void MeshContextUpdate(MeshContext* context, const MeshContextDesc* desc)
+{
+ return gMeshLoader.MeshContextUpdate_ptr(context, desc);
+}
+
+void MeshContextRelease(MeshContext* context)
+{
+ return gMeshLoader.MeshContextRelease_ptr(context);
+}
+
+MeshIndexBuffer* MeshIndexBufferCreate(MeshContext* context, MeshUint* indices, MeshUint numIndices)
+{
+ return gMeshLoader.MeshIndexBufferCreate_ptr(context, indices, numIndices);
+}
+
+void MeshIndexBufferRelease(MeshIndexBuffer* buffer)
+{
+ return gMeshLoader.MeshIndexBufferRelease_ptr(buffer);
+}
+
+MeshVertexBuffer* MeshVertexBufferCreate(MeshContext* context, MeshVertex* vertices, MeshUint numVertices)
+{
+ return gMeshLoader.MeshVertexBufferCreate_ptr(context, vertices, numVertices);
+}
+
+void MeshVertexBufferRelease(MeshVertexBuffer* buffer)
+{
+ return gMeshLoader.MeshVertexBufferRelease_ptr(buffer);
+}
+
+void MeshContextDraw(MeshContext* context, const MeshContextDrawParams* params)
+{
+ return gMeshLoader.MeshContextDraw_ptr(context, params);
+}
+
+MeshContext* MeshInteropContextCreate(AppGraphCtx* appctx)
+{
+ return gMeshLoader.MeshInteropContextCreate_ptr(appctx);
+}
+
+void MeshInteropContextUpdate(MeshContext* context, AppGraphCtx* appctx)
+{
+ return gMeshLoader.MeshInteropContextUpdate_ptr(context, appctx);
+}
+
+void* meshLoaderLoadFunction(MeshLoader* inst, const char* name)
+{
+ snprintf(inst->buf, 1024u, "%s%s", name, inst->suffix);
+
+ return SDL_LoadFunction(inst->module, inst->buf);
+}
+
+void loadMesh(AppGraphCtxType type)
+{
+ const char* moduleName = demoAppDLLName(type);
+
+ gMeshLoader.suffix = demoAppBackendSuffix(type);
+
+ gMeshLoader.module = SDL_LoadObject(moduleName);
+
+ gMeshLoader.MeshContextCreate_ptr = (MeshContextCreate_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshContextCreate"));
+ gMeshLoader.MeshContextUpdate_ptr = (MeshContextUpdate_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshContextUpdate"));
+ gMeshLoader.MeshContextRelease_ptr = (MeshContextRelease_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshContextRelease"));
+ gMeshLoader.MeshIndexBufferCreate_ptr = (MeshIndexBufferCreate_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshIndexBufferCreate"));
+ gMeshLoader.MeshIndexBufferRelease_ptr = (MeshIndexBufferRelease_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshIndexBufferRelease"));
+ gMeshLoader.MeshVertexBufferCreate_ptr = (MeshVertexBufferCreate_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshVertexBufferCreate"));
+ gMeshLoader.MeshVertexBufferRelease_ptr = (MeshVertexBufferRelease_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshVertexBufferRelease"));
+ gMeshLoader.MeshContextDraw_ptr = (MeshContextDraw_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshContextDraw"));
+ gMeshLoader.MeshInteropContextCreate_ptr = (MeshInteropContextCreate_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshInteropContextCreate"));
+ gMeshLoader.MeshInteropContextUpdate_ptr = (MeshInteropContextUpdate_ptr_t)(meshLoaderLoadFunction(&gMeshLoader, "MeshInteropContextUpdate"));
+}
+
+void unloadMesh()
+{
+ gMeshLoader.MeshContextCreate_ptr = nullptr;
+ gMeshLoader.MeshContextUpdate_ptr = nullptr;
+ gMeshLoader.MeshContextRelease_ptr = nullptr;
+ gMeshLoader.MeshIndexBufferCreate_ptr = nullptr;
+ gMeshLoader.MeshIndexBufferRelease_ptr = nullptr;
+ gMeshLoader.MeshVertexBufferCreate_ptr = nullptr;
+ gMeshLoader.MeshVertexBufferRelease_ptr = nullptr;
+ gMeshLoader.MeshContextDraw_ptr = nullptr;
+ gMeshLoader.MeshInteropContextCreate_ptr = nullptr;
+ gMeshLoader.MeshInteropContextUpdate_ptr = nullptr;
+
+ SDL_UnloadObject(gMeshLoader.module);
+}
diff --git a/demo/DemoApp/preset0.h b/demo/DemoApp/preset0.h
index aba3666..5e37ac4 100644
--- a/demo/DemoApp/preset0.h
+++ b/demo/DemoApp/preset0.h
@@ -13,7 +13,9 @@ const ImserNode g_root[] = {
imserNodeValue1f("Velocity", 0.500000f),
imserNodeValue1f("Smoke", 0.500000f),
imserNodeGroupEnd(),
- imserNodeValue1f("Vorticity Strength", 9.000000f),
+ imserNodeGroupBegin("Vorticity Confinement"),
+ imserNodeValue1f("Strength", 9.000000f),
+ imserNodeGroupEnd(),
imserNodeGroupBegin("Combustion"),
imserNodeValue1f("Ignition Temp", 0.050000f),
imserNodeValue1f("Cooling Rate", 1.500000f),
diff --git a/demo/DemoApp/preset1.h b/demo/DemoApp/preset1.h
index dded481..2f502e6 100644
--- a/demo/DemoApp/preset1.h
+++ b/demo/DemoApp/preset1.h
@@ -13,7 +13,9 @@ const ImserNode g_root[] = {
imserNodeValue1f("Velocity", 0.500000f),
imserNodeValue1f("Smoke", 0.500000f),
imserNodeGroupEnd(),
- imserNodeValue1f("Vorticity Strength", 9.000000f),
+ imserNodeGroupBegin("Vorticity Confinement"),
+ imserNodeValue1f("Strength", 9.000000f),
+ imserNodeGroupEnd(),
imserNodeGroupBegin("Combustion"),
imserNodeValue1f("Ignition Temp", 0.050000f),
imserNodeValue1f("Cooling Rate", 1.500000f),
diff --git a/demo/DemoApp/scene.cpp b/demo/DemoApp/scene.cpp
index 3ad7cce..399d4d8 100644
--- a/demo/DemoApp/scene.cpp
+++ b/demo/DemoApp/scene.cpp
@@ -43,8 +43,9 @@ namespace Scenes
SceneSimpleFlameFuelMap sceneSimpleFlameFuelMap;
SceneSimpleFlameParticleSurface sceneParticleSurface;
SceneSimpleFlameBall sceneSimpleFlameBall;
+ SceneEmitSubStep sceneEmitSubStep;
- const int count = 18;
+ const int count = 19;
Scene* list[count] = {
&scene2DTextureEmitter1,
&scene2DTextureEmitter2,
@@ -64,7 +65,8 @@ namespace Scenes
&sceneSimpleFlame2,
&sceneSimpleFlameFuelMap,
&sceneParticleSurface,
- &sceneSimpleFlameBall
+ &sceneSimpleFlameBall,
+ &sceneEmitSubStep
};
};
@@ -115,6 +117,10 @@ void pointsToImage(NvFlowFloat4* image, int imageDim, const CurvePoint* pts, int
void Scene::update(float dt)
{
+ m_deltaTime = dt;
+
+ doFrameUpdate(m_deltaTime);
+
int numSteps = m_timeStepper.getNumSteps(dt);
for (int i = 0; i < numSteps; i++)
@@ -233,6 +239,22 @@ void SceneFluid::imguiDesc()
m_shouldGridReset = true;
}
+ if (imguiCheck("Auto Reset", m_autoResetMode, true))
+ {
+ m_autoResetMode = !m_autoResetMode;
+ m_autoResetTime = 0.f;
+ }
+ if (m_autoResetMode)
+ {
+ m_autoResetTime += m_deltaTime;
+ if (m_autoResetTime > m_autoResetThresh)
+ {
+ m_shouldReset = true;
+ m_autoResetTime = 0.f;
+ m_autoResetThresh = 5.f * (1.f / 255.f) * float((rand() & 255));
+ }
+ }
+
float cellSizeLogf = float(m_flowGridActor.m_cellSizeLogScale);
if (imguiserSlider("Cell Size Log Scale", &cellSizeLogf, -6.f, 6.f, 1.f, true))
{
@@ -271,6 +293,11 @@ void SceneFluid::imguiFluidSim()
imguiserSlider("Fuel", &m_flowGridActor.m_materialParams.fuel.fade, 0.f, 1.f, 0.01f, true);
imguiserEndGroup();
+ if (imguiCheck("Single Pass Advect", m_flowGridActor.m_gridParams.singlePassAdvection, true))
+ {
+ m_flowGridActor.m_gridParams.singlePassAdvection = !m_flowGridActor.m_gridParams.singlePassAdvection;
+ }
+
imguiSeparator();
imguiLabel("MacCormack Correction");
imguiserBeginGroup("MacCormack Correction", nullptr);
@@ -287,8 +314,16 @@ void SceneFluid::imguiFluidSim()
imguiserSlider("Fuel", &m_flowGridActor.m_materialParams.fuel.macCormackBlendThreshold, 0.f, 0.01f, 0.001f, true);
imguiserEndGroup();
- imguiserSlider("Vorticity Strength", &m_flowGridActor.m_materialParams.vorticityStrength, 0.f, 20.f, 0.1f, true);
- imguiserSlider("Vorticity Vel Mask", &m_flowGridActor.m_materialParams.vorticityVelocityMask, 0.f, 1.f, 0.01f, true);
+ imguiSeparator();
+ imguiLabel("Vorticity Confinement");
+ imguiserBeginGroup("Vorticity Confinement", nullptr);
+ imguiserSlider("Strength", &m_flowGridActor.m_materialParams.vorticityStrength, 0.f, 20.f, 0.1f, true);
+ imguiserSlider("Velocity Mask", &m_flowGridActor.m_materialParams.vorticityVelocityMask, -1.f, 1.f, 0.01f, true);
+ imguiserSlider("Temperature Mask", &m_flowGridActor.m_materialParams.vorticityTemperatureMask, -1.f, 1.f, 0.01f, true);
+ imguiserSlider("Smoke Mask", &m_flowGridActor.m_materialParams.vorticitySmokeMask, -1.f, 1.f, 0.01f, true);
+ imguiserSlider("Fuel Mask", &m_flowGridActor.m_materialParams.vorticityFuelMask, -1.f, 1.f, 0.01f, true);
+ imguiserSlider("Constant Mask", &m_flowGridActor.m_materialParams.vorticityConstantMask, -1.f, 1.f, 0.01f, true);
+ imguiserEndGroup();
if (imguiCheck("Legacy Pressure", m_flowGridActor.m_gridParams.pressureLegacyMode, true))
{
@@ -497,6 +532,21 @@ void SceneFluid::imguiFluidRender()
imguiserSlider("Vector Length", &m_flowGridActor.m_crossSectionParams.vectorLengthScale, 0.1f, 2.f, 0.01f, true);
}
+ imguiLabel("Grid Summary");
+ imguiserBeginGroup("Grid Summary", nullptr);
+ if (imguiserCheck("Enabled", m_flowGridActor.m_enableGridSummary, true))
+ {
+ m_flowGridActor.m_enableGridSummary = !m_flowGridActor.m_enableGridSummary;
+ }
+ if (m_flowGridActor.m_enableGridSummary)
+ {
+ if (imguiserCheck("Debug Render", m_flowGridActor.m_enableGridSummaryDebugVis, true))
+ {
+ m_flowGridActor.m_enableGridSummaryDebugVis = !m_flowGridActor.m_enableGridSummaryDebugVis;
+ }
+ }
+ imguiserEndGroup();
+
imguiFluidRenderExtra();
imguiserEndGroup();
}
@@ -549,6 +599,12 @@ void SceneFluid::imguiFluidAlloc()
imguiserSlider("Temp Threshold", &m_flowGridActor.m_materialParams.temperature.allocThreshold, 0.f, 1.f, 0.01f, true);
imguiserSlider("Fuel Threshold", &m_flowGridActor.m_materialParams.fuel.allocThreshold, 0.f, 1.f, 0.01f, true);
+ if (imguiCheck("Translation Test", m_flowGridActor.m_enableTranslationTest, true))
+ {
+ m_flowGridActor.m_enableTranslationTest = !m_flowGridActor.m_enableTranslationTest;
+ }
+ imguiSlider("Test Time Scale", &m_flowGridActor.m_translationTimeScale, 0.25f, 8.f, 0.1f, true);
+
imguiFluidAllocExtra();
imguiserEndGroup();
}
@@ -678,37 +734,45 @@ bool SceneFluid::getStats(int lineIdx, int statIdx, char* buf)
}
case 1:
{
+ float simRate = (1.f / m_flowContext.m_statUpdateDt) *
+ float(m_flowContext.m_statUpdateSuccessCount /
+ m_flowContext.m_statUpdateAttemptCount);
+ snprintf(buf, 79, "SimRate: %.3f Hz", simRate);
+ return true;
+ }
+ case 2:
+ {
NvFlowUint numLayers = m_flowGridActor.m_statNumLayers;
snprintf(buf, 79, "NumLayers: %d layers", numLayers);
return true;
}
- case 2:
+ case 3:
{
NvFlowUint numBlocks = m_flowGridActor.m_statNumDensityBlocks;
NvFlowUint maxBlocks = m_flowGridActor.m_statMaxDensityBlocks;
snprintf(buf, 79, "Density: %d blocks active of %d", numBlocks, maxBlocks);
return true;
}
- case 3:
+ case 4:
{
NvFlowUint numBlocks = m_flowGridActor.m_statNumVelocityBlocks;
NvFlowUint maxBlocks = m_flowGridActor.m_statMaxVelocityBlocks;
snprintf(buf, 79, "Velocity: %d blocks active of %d", numBlocks, maxBlocks);
return true;
}
- case 4:
+ case 5:
{
NvFlowUint numCells = m_flowGridActor.m_statNumDensityCells;
snprintf(buf, 79, "Density: %d cells active", numCells);
return true;
}
- case 5:
+ case 6:
{
NvFlowUint numCells = m_flowGridActor.m_statNumVelocityCells;
snprintf(buf, 79, "Velocity: %d cells active", numCells);
return true;
}
- case 6:
+ case 7:
{
if (m_flowGridActor.m_statVolumeShadowBlocks > 0u)
{
@@ -718,7 +782,7 @@ bool SceneFluid::getStats(int lineIdx, int statIdx, char* buf)
}
return false;
}
- case 7:
+ case 8:
{
if (m_flowGridActor.m_statVolumeShadowCells > 0u)
{
diff --git a/demo/DemoApp/scene.h b/demo/DemoApp/scene.h
index fee39e4..da88e1d 100644
--- a/demo/DemoApp/scene.h
+++ b/demo/DemoApp/scene.h
@@ -31,6 +31,7 @@ struct TimeStepper
float m_timeError = 0.f;
float m_fixedDt = (1.f / 60.f);
int m_maxSteps = 1;
+ int m_numSteps = 0;
TimeStepper() {}
@@ -41,14 +42,15 @@ struct TimeStepper
// compute time steps
m_timeError += m_deltaTime;
- int numSteps = int(m_timeError / m_fixedDt);
- if (numSteps < 0) numSteps = 0;
+ m_numSteps = int(floorf((m_timeError / m_fixedDt)));
- m_timeError -= m_fixedDt * float(numSteps);
+ if (m_numSteps < 0) m_numSteps = 0;
- if (numSteps > m_maxSteps) numSteps = m_maxSteps;
+ m_timeError -= m_fixedDt * float(m_numSteps);
- return numSteps;
+ if (m_numSteps > m_maxSteps) m_numSteps = m_maxSteps;
+
+ return m_numSteps;
}
};
@@ -82,7 +84,10 @@ struct Scene
int m_winw = 0;
int m_winh = 0;
+ float m_deltaTime = 0.f;
+
protected:
+ virtual void doFrameUpdate(float dt) {}
virtual void doUpdate(float dt) = 0;
AppGraphCtx* m_context = nullptr;
@@ -145,13 +150,17 @@ struct FlowContext
int m_maxFramesInFlight = 3u;
int m_framesInFlight = 0;
+ double m_statUpdateAttemptCount = 0.0;
+ double m_statUpdateSuccessCount = 0.0;
+ float m_statUpdateDt = 0.f;
+
FlowContext() {}
~FlowContext() {}
void init(AppGraphCtx* appctx);
void release();
- bool updateBegin();
+ bool updateBegin(float dt);
void updateEnd();
void preDrawBegin();
void preDrawEnd();
@@ -174,6 +183,8 @@ struct FlowGridActor
NvFlowVolumeRender* m_volumeRender = nullptr;
NvFlowVolumeShadow* m_volumeShadow = nullptr;
NvFlowCrossSection* m_crossSection = nullptr;
+ NvFlowGridSummary* m_gridSummary = nullptr;
+ NvFlowGridSummaryStateCPU* m_gridSummaryStateCPU = nullptr;
NvFlowGridDesc m_gridDesc;
NvFlowGridParams m_gridParams;
@@ -216,6 +227,16 @@ struct FlowGridActor
float m_crossSectionBackgroundColor = 0.f;
NvFlowFloat3 m_crossSectionLineColor = { 141.f / 255.f, 199.f / 255.f, 63.f / 255.f };
+ bool m_enableGridSummary = false;
+ bool m_enableGridSummaryDebugVis = false;
+
+ bool m_enableTranslationTest = false;
+ float m_translationTimeScale = 1.f;
+ bool m_enableTranslationTestOld = false;
+ float m_translationTestTime = 0.f;
+ NvFlowFloat3 m_translationOffsetA = { +4.f, 0.f, 0.f };
+ NvFlowFloat3 m_translationOffsetB = { -4.f, 0.f, 0.f };
+
NvFlowUint m_statNumLayers = 0u;
NvFlowUint m_statNumDensityBlocks = 0u;
NvFlowUint m_statNumDensityCells = 0u;
@@ -341,6 +362,10 @@ struct SceneFluid : public Scene
bool m_shouldGridReset = false;
bool m_shouldLoadPreset = false;
+ bool m_autoResetMode = false;
+ float m_autoResetTime = 0.f;
+ float m_autoResetThresh = 0.f;
+
virtual bool shouldReset() { return m_shouldReset; }
virtual void reset();
};
@@ -550,6 +575,22 @@ struct SceneSimpleFlameAnimated : public SceneSimpleFlame
m_emitParams.bounds.w.x = 2.f * cosf(rate * time);
m_emitParams.bounds.w.z = 2.f * sinf(rate * time);
+ // testing hack
+ //static int offset = 0;
+ //offset++;
+ //if (offset > 4)
+ //{
+ // offset = 0;
+ //}
+ //m_emitParams.bounds.w.z += float(offset) - 4.f;
+
+ //NvFlowFloat3 gridLocation = { m_emitParams.bounds.w.x, 0.f, m_emitParams.bounds.w.z };
+ //NvFlowGridSetTargetLocation(m_flowGridActor.m_grid, gridLocation);
+
+ //bool parity = (time - floorf(time)) > 0.5f;
+ //NvFlowFloat3 gridLocation = parity ? NvFlowFloat3{-4.f, 0.f, 0.f} : NvFlowFloat3{+4.f, 0.f, 0.f};
+ //NvFlowGridSetTargetLocation(m_flowGridActor.m_grid, gridLocation);
+
m_emitParams.velocityLinear.x = +8.f * sinf(rate * time);
m_emitParams.velocityLinear.y = -2.f;
m_emitParams.velocityLinear.z = -8.f * cosf(rate * time);
@@ -681,6 +722,8 @@ struct SceneSimpleFlameCapsule : public SceneSimpleFlame
float m_capsuleLength = 0.75f;
float m_distanceScale = 3.5f;
bool m_boxMode = false;
+ bool m_flameSpread = false;
+ bool m_flameSpreadOld = false;
};
struct Scene2DTextureEmitter : public SceneFluid
@@ -831,6 +874,31 @@ struct SceneCustomEmit : public SceneFluid
bool m_fullDomain = false;
};
+struct SceneEmitSubStep : public SceneFluid
+{
+ SceneEmitSubStep() : SceneFluid("Emit Sub Step") {}
+
+ virtual void initParams();
+ virtual void init(AppGraphCtx* context, int winw, int winh);
+ virtual void doFrameUpdate(float dt);
+ virtual void doUpdate(float dt);
+ virtual void preDraw();
+ virtual void draw(DirectX::CXMMATRIX projection, DirectX::CXMMATRIX view);
+ virtual void release();
+ virtual void imgui(int x, int y, int w, int h);
+
+ virtual void imguiFluidEmitterExtra();
+
+ void emitSubSteps(float t_old, float x_old, float t_new, float x_new, float frame_dt);
+ void emitImpulse(float x, float impulse_dt);
+
+ float anim_t = 0.f;
+ float anim_x = -1.f;
+ float anim_x_old = 0.f;
+
+ TimeStepper m_emitterTimeStepper;
+};
+
Scene* getScene(int index);
void pointsToImage(NvFlowFloat4* image, int imageDim, const CurvePoint* pts, int numPts);
diff --git a/demo/DemoApp/scene2DTextureEmitter.cpp b/demo/DemoApp/scene2DTextureEmitter.cpp
index c2d3984..c5b0197 100644
--- a/demo/DemoApp/scene2DTextureEmitter.cpp
+++ b/demo/DemoApp/scene2DTextureEmitter.cpp
@@ -130,7 +130,7 @@ void Scene2DTextureEmitter::init(AppGraphCtx* appctx, int winw, int winh)
void Scene2DTextureEmitter::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
diff --git a/demo/DemoApp/sceneCustomEmit.cpp b/demo/DemoApp/sceneCustomEmit.cpp
index c52db59..8c97150 100644
--- a/demo/DemoApp/sceneCustomEmit.cpp
+++ b/demo/DemoApp/sceneCustomEmit.cpp
@@ -120,7 +120,7 @@ void SceneCustomEmit::init(AppGraphCtx* appctx, int winw, int winh)
void SceneCustomEmit::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
ComputeContextNvFlowContextUpdate(m_customContext, m_flowContext.m_gridContext);
diff --git a/demo/DemoApp/sceneEmitSubStep.cpp b/demo/DemoApp/sceneEmitSubStep.cpp
new file mode 100644
index 0000000..76c0115
--- /dev/null
+++ b/demo/DemoApp/sceneEmitSubStep.cpp
@@ -0,0 +1,204 @@
+/*
+* 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 "loader.h"
+#include "imgui.h"
+#include "imguiser.h"
+
+namespace PresetFlame
+{
+#include "presetFlame.h"
+}
+
+#include "scene.h"
+
+#include <SDL.h>
+
+void SceneEmitSubStep::initParams()
+{
+ m_flowGridActor.initParams(AppGraphCtxDedicatedVideoMemory(m_appctx));
+
+ // set emitter defaults
+ NvFlowGridEmitParamsDefaults(&m_emitParams);
+
+ // configure emitter params
+ m_emitParams.bounds.x.x = 0.25f;
+ m_emitParams.bounds.y.y = 0.25f;
+ m_emitParams.bounds.z.z = 0.25f;
+ m_emitParams.velocityLinear.y = 8.f;
+ m_emitParams.fuel = 1.9f;
+ m_emitParams.smoke = 0.5f;
+
+ m_shouldLoadPreset = true;
+}
+
+void SceneEmitSubStep::init(AppGraphCtx* appctx, int winw, int winh)
+{
+ m_appctx = appctx;
+
+ if (!m_shouldReset || m_isFirstRun)
+ {
+ initParams();
+ m_isFirstRun = false;
+ }
+
+ m_flowContext.init(appctx);
+
+ m_flowGridActor.init(&m_flowContext, appctx);
+
+ // create default color map
+ {
+ const int numPoints = 5;
+ const CurvePoint pts[numPoints] = {
+ { 0.f, 0.f,0.f,0.f,0.f },
+ { 0.05f, 0.f,0.f,0.f,0.5f },
+ { 0.6f, 213.f / 255.f,100.f / 255.f,30.f / 255.f,0.8f },
+ { 0.85f, 255.f / 255.f,240.f / 255.f,0.f,0.8f },
+ { 1.f, 1.f,1.f,1.f,0.7f }
+ };
+
+ auto& colorMap = m_flowGridActor.m_colorMap;
+ colorMap.initColorMap(m_flowContext.m_renderContext, pts, numPoints, (colorMap.m_curvePointsDefault.size() == 0));
+ }
+
+ m_projectile.init(m_appctx, m_flowContext.m_gridContext);
+
+ resize(winw, winh);
+}
+
+void SceneEmitSubStep::emitImpulse(float x, float impulse_dt)
+{
+ NvFlowShapeDesc shapeDesc;
+ shapeDesc.sphere.radius = 0.8f;
+
+ m_emitParams.bounds.w.x = x;
+
+ m_emitParams.localToWorld = m_emitParams.bounds;
+ m_emitParams.shapeType = eNvFlowShapeTypeSphere;
+ m_emitParams.deltaTime = impulse_dt;
+
+ NvFlowGridEmit(m_flowGridActor.m_grid, &shapeDesc, 1u, &m_emitParams, 1u);
+}
+
+void SceneEmitSubStep::emitSubSteps(float t_old, float x_old, float t_new, float x_new, float frame_dt)
+{
+ float emitImpulse_dt = m_emitterTimeStepper.m_fixedDt;
+
+ int numSteps = m_emitterTimeStepper.getNumSteps(frame_dt);
+
+ for (int i = 0; i < numSteps; i++)
+ {
+ int substep_i = numSteps - 1 - i;
+
+ float substep_t = emitImpulse_dt * substep_i + m_emitterTimeStepper.m_timeError;
+
+ float s = (substep_t - t_new) / (t_old - t_new);
+ float x = (1.f - s) * x_new + s * x_old;
+
+ emitImpulse(x, emitImpulse_dt);
+ }
+}
+
+void SceneEmitSubStep::doFrameUpdate(float frame_dt)
+{
+ m_emitterTimeStepper.m_fixedDt = 1.f / 1200.f;
+ m_emitterTimeStepper.m_maxSteps = 1000;
+
+ anim_x_old = anim_x;
+
+ anim_t += frame_dt;
+
+ const float freq = 60.f;
+ const float k = 2.f * freq;
+ const float k_dt = 1.f / freq;
+
+ if (anim_t > (2.f * k_dt))
+ {
+ anim_t -= (2.f * k_dt);
+ }
+
+ anim_x = k * fabs(anim_t - k_dt) - 1.f;
+
+ float t_old = frame_dt;
+ float t_new = 0.f;
+
+ emitSubSteps(t_old, anim_x_old, t_new, anim_x, frame_dt);
+}
+
+void SceneEmitSubStep::doUpdate(float dt)
+{
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
+ if (shouldUpdate)
+ {
+ AppGraphCtxProfileBegin(m_appctx, "Simulate");
+
+ m_flowGridActor.updatePreEmit(&m_flowContext, dt);
+
+ // emit
+ {
+ m_projectile.update(m_flowContext.m_gridContext, m_flowGridActor.m_grid, dt);
+ }
+
+ m_flowGridActor.updatePostEmit(&m_flowContext, dt, shouldUpdate, m_shouldGridReset);
+
+ m_shouldGridReset = false;
+
+ AppGraphCtxProfileEnd(m_appctx, "Simulate");
+ }
+ m_flowContext.updateEnd();
+}
+
+void SceneEmitSubStep::preDraw()
+{
+ m_flowContext.preDrawBegin();
+
+ m_flowGridActor.preDraw(&m_flowContext);
+
+ m_flowContext.preDrawEnd();
+}
+
+void SceneEmitSubStep::draw(DirectX::CXMMATRIX projection, DirectX::CXMMATRIX view)
+{
+ m_projectile.draw(projection, view);
+
+ m_flowContext.drawBegin();
+
+ m_flowGridActor.draw(&m_flowContext, projection, view);
+
+ m_flowContext.drawEnd();
+}
+
+void SceneEmitSubStep::release()
+{
+ m_projectile.release();
+
+ m_flowGridActor.release();
+
+ m_flowContext.release();
+}
+
+void SceneEmitSubStep::imgui(int xIn, int yIn, int wIn, int hIn)
+{
+ SceneFluid::imgui(xIn, yIn, wIn, hIn);
+
+ if (m_shouldLoadPreset)
+ {
+ imguiserLoadC(PresetFlame::g_root, sizeof(PresetFlame::g_root));
+ m_shouldLoadPreset = false;
+ }
+}
+
+void SceneEmitSubStep::imguiFluidEmitterExtra()
+{
+
+} \ No newline at end of file
diff --git a/demo/DemoApp/sceneFlow.cpp b/demo/DemoApp/sceneFlow.cpp
index 80f87b1..5cdb70a 100644
--- a/demo/DemoApp/sceneFlow.cpp
+++ b/demo/DemoApp/sceneFlow.cpp
@@ -205,7 +205,7 @@ void FlowContext::computeContextEnd()
}
}
-bool FlowContext::updateBegin()
+bool FlowContext::updateBegin(float dt)
{
m_framesInFlight = computeContextBegin();
bool shouldFlush = (m_framesInFlight < m_maxFramesInFlight);
@@ -217,6 +217,12 @@ bool FlowContext::updateBegin()
NvFlowContextFlushRequestPush(m_renderCopyContext);
}
+ m_statUpdateAttemptCount += 1.0;
+ if (shouldFlush) m_statUpdateSuccessCount += 1.0;
+ m_statUpdateAttemptCount *= 0.99;
+ m_statUpdateSuccessCount *= 0.99;
+ m_statUpdateDt = dt;
+
return shouldFlush;
}
@@ -357,6 +363,12 @@ void FlowGridActor::init(FlowContext* flowContext, AppGraphCtx* appctx)
m_crossSection = NvFlowCreateCrossSection(flowContext->m_renderContext, &crossSectionDesc);
+ NvFlowGridSummaryDesc gridSummaryDesc = {};
+ gridSummaryDesc.gridExport = gridExport;
+
+ m_gridSummary = NvFlowCreateGridSummary(flowContext->m_gridContext, &gridSummaryDesc);
+ m_gridSummaryStateCPU = NvFlowCreateGridSummaryStateCPU(m_gridSummary);
+
NvFlowRenderMaterialPoolDesc materialPoolDesc = {};
materialPoolDesc.colorMapResolution = 64u;
m_colorMap.m_materialPool = NvFlowCreateRenderMaterialPool(flowContext->m_renderContext, &materialPoolDesc);
@@ -393,6 +405,8 @@ void FlowGridActor::release()
NvFlowReleaseGridProxy(m_gridProxy);
NvFlowReleaseVolumeRender(m_volumeRender);
NvFlowReleaseCrossSection(m_crossSection);
+ NvFlowReleaseGridSummary(m_gridSummary);
+ NvFlowReleaseGridSummaryStateCPU(m_gridSummaryStateCPU);
NvFlowReleaseRenderMaterialPool(m_colorMap.m_materialPool);
if (m_volumeShadow) NvFlowReleaseVolumeShadow(m_volumeShadow);
m_volumeShadow = nullptr;
@@ -405,6 +419,25 @@ void FlowGridActor::updatePreEmit(FlowContext* flowContext, float dt)
NvFlowRenderMaterialUpdate(m_colorMap.m_materialDefault, &m_renderMaterialDefaultParams);
NvFlowRenderMaterialUpdate(m_colorMap.m_material0, &m_renderMaterialMat0Params);
NvFlowRenderMaterialUpdate(m_colorMap.m_material1, &m_renderMaterialMat1Params);
+
+ if (m_enableTranslationTest)
+ {
+ m_enableTranslationTestOld = true;
+
+ m_translationTestTime += m_translationTimeScale * dt;
+ if (m_translationTestTime > 120.f) m_translationTestTime = 0.f;
+
+ bool parity = (m_translationTestTime - floorf(m_translationTestTime)) > 0.5f;
+ NvFlowFloat3 gridLocation = parity ? m_translationOffsetA : m_translationOffsetB;
+ NvFlowGridSetTargetLocation(m_grid, gridLocation);
+ }
+ else if(m_enableTranslationTestOld)
+ {
+ NvFlowFloat3 gridLocation = NvFlowFloat3{ 0.f, 0.f, 0.f };
+ NvFlowGridSetTargetLocation(m_grid, gridLocation);
+
+ m_enableTranslationTestOld = false;
+ }
}
void FlowGridActor::updatePostEmit(FlowContext* flowContext, float dt, bool shouldUpdate, bool shouldReset)
@@ -492,6 +525,27 @@ void FlowGridActor::updatePostEmit(FlowContext* flowContext, float dt, bool shou
}
auto gridExport = NvFlowGridGetGridExport(flowContext->m_gridContext, m_grid);
+
+ if (m_enableGridSummary)
+ {
+ NvFlowGridSummaryUpdateParams updateParams = {};
+ updateParams.gridExport = gridExport;
+ updateParams.stateCPU = m_gridSummaryStateCPU;
+
+ NvFlowGridSummaryUpdate(m_gridSummary, flowContext->m_gridContext, &updateParams);
+
+ NvFlowUint numLayers = NvFlowGridSummaryGetNumLayers(m_gridSummaryStateCPU);
+ for (NvFlowUint layerIdx = 0u; layerIdx < numLayers; layerIdx++)
+ {
+ NvFlowGridSummaryResult* results = nullptr;
+ NvFlowUint numResults = 0u;
+
+ NvFlowGridSummaryGetSummaries(m_gridSummaryStateCPU, &results, &numResults, layerIdx);
+
+ //printf("GridSummary layer(%d) numResults(%d)", layerIdx, numResults);
+ }
+ }
+
NvFlowGridProxyFlushParams flushParams = {};
flushParams.gridContext = flowContext->m_gridContext;
flushParams.gridCopyContext = flowContext->m_gridCopyContext;
@@ -686,6 +740,20 @@ void FlowGridActor::draw(FlowContext* flowContext, DirectX::CXMMATRIX projection
NvFlowVolumeShadowDebugRender(m_volumeShadow, flowContext->m_renderContext, &params);
}
+
+ if (m_enableGridSummary && m_enableGridSummaryDebugVis)
+ {
+ NvFlowGridSummaryDebugRenderParams params = {};
+
+ params.stateCPU = m_gridSummaryStateCPU;
+
+ params.renderTargetView = flowContext->m_rtv;
+
+ memcpy(&params.projectionMatrix, &projection, sizeof(NvFlowFloat4x4));
+ memcpy(&params.viewMatrix, &view, sizeof(NvFlowFloat4x4));
+
+ NvFlowGridSummaryDebugRender(m_gridSummary, flowContext->m_renderContext, &params);
+ }
}
// *********************** Flow Color Map *****************************************
diff --git a/demo/DemoApp/sceneSDF.cpp b/demo/DemoApp/sceneSDF.cpp
index 301e260..1e6ad08 100644
--- a/demo/DemoApp/sceneSDF.cpp
+++ b/demo/DemoApp/sceneSDF.cpp
@@ -138,7 +138,7 @@ void SceneSDFTest::init(AppGraphCtx* appctx, int winw, int winh)
void SceneSDFTest::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
@@ -285,7 +285,7 @@ void SceneCustomLighting::init(AppGraphCtx* context, int winw, int winh)
void SceneCustomLighting::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
ComputeContextNvFlowContextUpdate(m_computeContext, m_flowContext.m_renderContext);
diff --git a/demo/DemoApp/sceneSimpleFlame.cpp b/demo/DemoApp/sceneSimpleFlame.cpp
index 60b134b..5cd69cc 100644
--- a/demo/DemoApp/sceneSimpleFlame.cpp
+++ b/demo/DemoApp/sceneSimpleFlame.cpp
@@ -106,7 +106,7 @@ void SceneSimpleFlame::init(AppGraphCtx* appctx, int winw, int winh)
void SceneSimpleFlame::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
@@ -191,6 +191,7 @@ void SceneSimpleFlameDouble::init(AppGraphCtx* context, int winw, int winh)
materialParams.vorticityStrength = 5.f;
materialParams.vorticityVelocityMask = 0.f;
+ materialParams.vorticityConstantMask = 1.f;
materialParams.velocity.macCormackBlendFactor = 0.f;
materialParams.smoke.macCormackBlendFactor = 0.75f;
materialParams.buoyancyPerTemp *= 5.f;
@@ -203,13 +204,17 @@ void SceneSimpleFlameDouble::init(AppGraphCtx* context, int winw, int winh)
void SceneSimpleFlameDouble::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
m_flowGridActor.updatePreEmit(&m_flowContext, dt);
+ NvFlowGridMaterialHandle emitMaterials[2u] = { m_materialA, m_materialB };
+
+ NvFlowGridUpdateEmitMaterials(m_flowGridActor.m_grid, emitMaterials, 2u);
+
// emit
{
NvFlowShapeDesc shapeDesc;
@@ -220,14 +225,14 @@ void SceneSimpleFlameDouble::doUpdate(float dt)
m_emitParams.deltaTime = dt;
m_emitParamsA = m_emitParams;
- m_emitParamsA.material = m_materialA;
+ m_emitParamsA.emitMaterialIndex = 0u;
m_emitParamsA.bounds.w.x = +0.25f;
m_emitParamsA.localToWorld = m_emitParamsA.bounds;
m_emitParamsA.velocityLinear.x = -8.f;
NvFlowGridEmit(m_flowGridActor.m_grid, &shapeDesc, 1u, &m_emitParamsA, 1u);
m_emitParamsB = m_emitParams;
- m_emitParamsB.material = m_materialB;
+ m_emitParamsB.emitMaterialIndex = 1u;
m_emitParamsB.bounds.w.x = -0.25f;
m_emitParamsB.localToWorld = m_emitParamsB.bounds;
m_emitParamsB.velocityLinear.x = +8.f;
@@ -300,7 +305,7 @@ void SceneSimpleFlameFuelMap::init(AppGraphCtx* context, int winw, int winh)
void SceneSimpleFlameFuelMap::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
@@ -452,7 +457,7 @@ void SceneSimpleFlameParticleSurface::doEmitCustomEmitDensityFunc(NvFlowUint* da
void SceneSimpleFlameParticleSurface::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
// update emit params
@@ -892,7 +897,7 @@ void SceneSimpleFlameCulling::initParams()
void SceneSimpleFlameCulling::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
@@ -1005,7 +1010,7 @@ void SceneSimpleFlameConvex::initParams()
void SceneSimpleFlameConvex::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
@@ -1083,7 +1088,7 @@ void SceneSimpleFlameCapsule::initParams()
void SceneSimpleFlameCapsule::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
@@ -1123,6 +1128,29 @@ void SceneSimpleFlameCapsule::doUpdate(float dt)
shapeDesc[0].box.halfSize.z = 0.5f * m_capsuleRadius;
}
+ if (m_flameSpread && !m_flameSpreadOld)
+ {
+ m_shouldGridReset = true;
+ }
+ m_flameSpreadOld = m_flameSpread;
+
+ if (m_flameSpread)
+ {
+ m_emitParams.fuel = 0.f;
+ m_emitParams.fuelRelease = 2.5f;
+ m_emitParams.temperature = 0.f;
+ m_emitParams.temperatureCoupleRate = 0.f;
+ m_emitParams.velocityLinear.y = 0.f;
+ }
+ else
+ {
+ m_emitParams.fuel = 2.5f;
+ m_emitParams.fuelRelease = 0.f;
+ m_emitParams.temperature = 2.f;
+ m_emitParams.temperatureCoupleRate = 0.5f;
+ m_emitParams.velocityLinear.y = 8.f;
+ }
+
NvFlowGridEmit(m_flowGridActor.m_grid, shapeDesc, 1u, &m_emitParams, 1u);
m_projectile.update(m_flowContext.m_gridContext, m_flowGridActor.m_grid, dt);
@@ -1152,5 +1180,10 @@ void SceneSimpleFlameCapsule::imguiFluidEmitterExtra()
m_boxMode = !m_boxMode;
}
+ if (imguiserCheck("Flame Spread", m_flameSpread, true))
+ {
+ m_flameSpread = !m_flameSpread;
+ }
+
imguiserEndGroup();
} \ No newline at end of file
diff --git a/demo/DemoApp/sceneSimpleSmoke.cpp b/demo/DemoApp/sceneSimpleSmoke.cpp
index da5440d..4c849b9 100644
--- a/demo/DemoApp/sceneSimpleSmoke.cpp
+++ b/demo/DemoApp/sceneSimpleSmoke.cpp
@@ -120,7 +120,7 @@ NvFlowFloat3 SceneSimpleSmoke::velocityFunc(float theta, float rate)
void SceneSimpleSmoke::doUpdate(float dt)
{
- bool shouldUpdate = m_flowContext.updateBegin();
+ bool shouldUpdate = m_flowContext.updateBegin(dt);
if (shouldUpdate)
{
AppGraphCtxProfileBegin(m_appctx, "Simulate");
diff --git a/demo/DemoAppCodeGen/DemoAppCodeGen.vcxproj b/demo/DemoAppCodeGen/DemoAppCodeGen.vcxproj
new file mode 100644
index 0000000..42bb3ae
--- /dev/null
+++ b/demo/DemoAppCodeGen/DemoAppCodeGen.vcxproj
@@ -0,0 +1,280 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="demoAppCodeGen.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="functionDefinitionExtract.h" />
+ <ClInclude Include="loaderCodeGen.h" />
+ </ItemGroup>
+ <PropertyGroup Condition="'$(Platform)'=='Win32'">
+ <PlatformName>win32</PlatformName>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Platform)'=='x64'">
+ <PlatformName>win64</PlatformName>
+ </PropertyGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{15a2730a-1be6-4a99-be96-feb4b8944ac2}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>DemoAppCodeGen</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ <UseOfMfc>Static</UseOfMfc>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <UseOfMfc>Static</UseOfMfc>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ <UseOfMfc>Static</UseOfMfc>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <UseOfMfc>Static</UseOfMfc>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ <IncludePath>$(SolutionDir)\include;$(SolutionDir)\NvFlow;$(SolutionDir)\NvFlowContext;$(SolutionDir)external\SDL2\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
+ <LibraryPath>$(SolutionDir)lib\win32;$(SolutionDir)external\SDL2\lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86</LibraryPath>
+ <CustomBuildBeforeTargets>PostBuildEvent</CustomBuildBeforeTargets>
+ <OutDir>$(SolutionDir)bin\$(PlatformName)\</OutDir>
+ <IntDir>interm\$(Configuration)_$(PlatformName)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LinkIncremental>true</LinkIncremental>
+ <OutDir>$(SolutionDir)bin\$(PlatformName)\</OutDir>
+ <IntDir>interm\$(Configuration)_$(PlatformName)\</IntDir>
+ <IncludePath>$(SolutionDir)\include;$(SolutionDir)\NvFlow;$(SolutionDir)\NvFlowContext;$(SolutionDir)external\SDL2\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
+ <LibraryPath>$(SolutionDir)lib\win64;$(SolutionDir)external\SDL2\lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64</LibraryPath>
+ <CustomBuildBeforeTargets>PostBuildEvent</CustomBuildBeforeTargets>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ <IncludePath>$(SolutionDir)\include;$(SolutionDir)\NvFlow;$(SolutionDir)\NvFlowContext;$(SolutionDir)external\SDL2\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
+ <LibraryPath>$(SolutionDir)lib\win32;$(SolutionDir)external\SDL2\lib\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86</LibraryPath>
+ <CustomBuildBeforeTargets>PostBuildEvent</CustomBuildBeforeTargets>
+ <OutDir>$(SolutionDir)bin\$(PlatformName)\</OutDir>
+ <IntDir>interm\$(Configuration)_$(PlatformName)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ <OutDir>$(SolutionDir)bin\$(PlatformName)\</OutDir>
+ <IntDir>interm\$(Configuration)_$(PlatformName)\</IntDir>
+ <IncludePath>$(SolutionDir)\include;$(SolutionDir)\NvFlow;$(SolutionDir)\NvFlowContext;$(SolutionDir)external\SDL2\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
+ <LibraryPath>$(SolutionDir)lib\win64;$(SolutionDir)external\SDL2\lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64</LibraryPath>
+ <CustomBuildBeforeTargets>PostBuildEvent</CustomBuildBeforeTargets>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>DLL_SUFFIX=$(Configuration)_$(PlatformName);WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
+ </Link>
+ <FxCompile>
+ <EntryPointName>%(filename)</EntryPointName>
+ <ShaderModel>5.0</ShaderModel>
+ <HeaderFileOutput>$(ProjectDir)%(Filename).hlsl.h</HeaderFileOutput>
+ <ObjectFileOutput />
+ </FxCompile>
+ <CustomBuildStep>
+ <Command>
+ </Command>
+ </CustomBuildStep>
+ <CustomBuildStep>
+ <Message>
+ </Message>
+ </CustomBuildStep>
+ <CustomBuildStep>
+ <Outputs>
+ </Outputs>
+ </CustomBuildStep>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>DLL_SUFFIX=$(Configuration)_$(PlatformName);_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
+ </Link>
+ <FxCompile>
+ <EntryPointName>%(filename)</EntryPointName>
+ <ShaderModel>5.0</ShaderModel>
+ <HeaderFileOutput>$(ProjectDir)%(Filename).hlsl.h</HeaderFileOutput>
+ <ObjectFileOutput />
+ </FxCompile>
+ <CustomBuildStep>
+ <Command>
+ </Command>
+ </CustomBuildStep>
+ <CustomBuildStep>
+ <Message>
+ </Message>
+ </CustomBuildStep>
+ <CustomBuildStep>
+ <Outputs>
+ </Outputs>
+ </CustomBuildStep>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>DLL_SUFFIX=$(Configuration)_$(PlatformName);WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
+ </Link>
+ <FxCompile>
+ <EntryPointName>%(filename)</EntryPointName>
+ <ShaderModel>5.0</ShaderModel>
+ <HeaderFileOutput>$(ProjectDir)%(Filename).hlsl.h</HeaderFileOutput>
+ <ObjectFileOutput />
+ </FxCompile>
+ <CustomBuildStep>
+ <Command>
+ </Command>
+ </CustomBuildStep>
+ <CustomBuildStep>
+ <Message>
+ </Message>
+ </CustomBuildStep>
+ <CustomBuildStep>
+ <Outputs>
+ </Outputs>
+ </CustomBuildStep>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>DLL_SUFFIX=$(Configuration)_$(PlatformName);NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
+ </Link>
+ <FxCompile>
+ <EntryPointName>%(filename)</EntryPointName>
+ <ShaderModel>5.0</ShaderModel>
+ <HeaderFileOutput>$(ProjectDir)%(Filename).hlsl.h</HeaderFileOutput>
+ <ObjectFileOutput />
+ </FxCompile>
+ <CustomBuildStep>
+ <Command>
+ </Command>
+ </CustomBuildStep>
+ <CustomBuildStep>
+ <Message>
+ </Message>
+ </CustomBuildStep>
+ <CustomBuildStep>
+ <Outputs>
+ </Outputs>
+ </CustomBuildStep>
+ </ItemDefinitionGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
+ <TargetName>$(ProjectName)$(Configuration)_$(PlatformName)</TargetName>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
+ <TargetName>$(ProjectName)$(Configuration)_$(PlatformName)</TargetName>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
+ <TargetName>$(ProjectName)$(Configuration)_$(PlatformName)</TargetName>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
+ <TargetName>$(ProjectName)$(Configuration)_$(PlatformName)</TargetName>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/demo/DemoAppCodeGen/DemoAppCodeGen.vcxproj.filters b/demo/DemoAppCodeGen/DemoAppCodeGen.vcxproj.filters
new file mode 100644
index 0000000..c648f4f
--- /dev/null
+++ b/demo/DemoAppCodeGen/DemoAppCodeGen.vcxproj.filters
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ <Filter Include="Shaders">
+ <UniqueIdentifier>{12de0363-d75b-4f29-bd10-e8b9832dd449}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="demoAppCodeGen.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="loaderCodeGen.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="functionDefinitionExtract.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/demo/DemoAppCodeGen/demoAppCodeGen.cpp b/demo/DemoAppCodeGen/demoAppCodeGen.cpp
new file mode 100644
index 0000000..103e19f
--- /dev/null
+++ b/demo/DemoAppCodeGen/demoAppCodeGen.cpp
@@ -0,0 +1,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;
+} \ No newline at end of file
diff --git a/demo/DemoAppCodeGen/functionDefinitionExtract.h b/demo/DemoAppCodeGen/functionDefinitionExtract.h
new file mode 100644
index 0000000..ca08253
--- /dev/null
+++ b/demo/DemoAppCodeGen/functionDefinitionExtract.h
@@ -0,0 +1,230 @@
+/*
+* 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.
+*/
+
+#pragma once
+
+struct StrHeap
+{
+ char* data;
+ unsigned int size;
+ unsigned int allocIdx;
+};
+
+StrHeap allocateStrHeap(const char** definitions, unsigned int numFunctions)
+{
+ unsigned int count = 0u;
+ for (unsigned int functionIdx = 0u; functionIdx < numFunctions; functionIdx++)
+ {
+ count += (unsigned int)strlen(definitions[functionIdx]);
+ }
+
+ // offset count to cover null terminators
+ count += numFunctions * (2 * maxFunctionParams + 1 + 1);
+
+ StrHeap heap = {};
+ heap.data = (char*)malloc(count);
+ heap.size = count;
+ heap.allocIdx = 0u;
+ return heap;
+}
+
+void freeStrHeap(StrHeap* heap)
+{
+ free(heap->data);
+ heap->data = nullptr;
+ heap->size = 0u;
+ heap->allocIdx = 0u;
+}
+
+inline bool isSpace(char c)
+{
+ return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v';
+}
+
+inline bool isAlphaNum(char c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_');
+}
+
+void skipSpace(unsigned int* readIdx, const char* definition)
+{
+ while (definition[*readIdx] != '\0')
+ {
+ if (isSpace(definition[*readIdx]))
+ {
+ *readIdx = *readIdx + 1;
+ }
+ else
+ {
+ break;
+ }
+ }
+}
+
+void findChar(unsigned int* readIdx, const char* definition, char c)
+{
+ while (definition[*readIdx] != '\0')
+ {
+ if (definition[*readIdx] == c)
+ {
+ break;
+ }
+ else
+ {
+ *readIdx = *readIdx + 1;
+ }
+ }
+}
+
+unsigned int findParamDelimiter(unsigned int readIdx, const char* definition)
+{
+ while (definition[readIdx] != '\0')
+ {
+ if (definition[readIdx] == ',' || definition[readIdx] == ')')
+ {
+ return readIdx;
+ }
+ else
+ {
+ readIdx = readIdx + 1;
+ }
+ }
+ return readIdx;
+}
+
+unsigned int reverseFindAlphaNum(unsigned int maxReadIdx, const char* definition)
+{
+ int readIdx = (int)maxReadIdx;
+ readIdx--;
+ bool hitAlphaNum = false;
+ while (readIdx >= 0)
+ {
+ if (isAlphaNum(definition[readIdx]))
+ {
+ hitAlphaNum = true;
+ readIdx--;
+ }
+ else if (definition[readIdx] == '(' || definition[readIdx] == ',')
+ {
+ if (hitAlphaNum)
+ {
+ return (unsigned int)(readIdx + 1);
+ }
+ else
+ {
+ return maxReadIdx;
+ };
+ }
+ else if (isSpace(definition[readIdx]))
+ {
+ if (hitAlphaNum)
+ {
+ return (unsigned int)(readIdx + 1);
+ }
+ else
+ {
+ readIdx--;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ return maxReadIdx;
+}
+
+void extractAlphaNum(StrHeap* heap, const char** dstPtr, unsigned int* readIdx, const char* definition)
+{
+ skipSpace(readIdx, definition);
+
+ *dstPtr = heap->data + heap->allocIdx;
+
+ while (heap->allocIdx < heap->size)
+ {
+ if (isAlphaNum(definition[(*readIdx)]))
+ {
+ heap->data[heap->allocIdx++] = definition[(*readIdx)++];
+ }
+ else
+ {
+ break;
+ }
+ }
+ heap->data[heap->allocIdx++] = '\0';
+}
+
+void extractRegion(StrHeap* heap, const char** dstPtr, unsigned char readIdx, unsigned char maxReadIdx, const char* definition)
+{
+ *dstPtr = heap->data + heap->allocIdx;
+
+ while (heap->allocIdx < heap->size)
+ {
+ if (readIdx < maxReadIdx)
+ {
+ heap->data[heap->allocIdx++] = definition[readIdx++];
+ }
+ else
+ {
+ break;
+ }
+ }
+ heap->data[heap->allocIdx++] = '\0';
+}
+
+Function genFunction(StrHeap* heap, const char* definition)
+{
+ Function function = {};
+
+ unsigned int readIdx = 0u;
+ unsigned int tempReadIdx = 0u;
+
+ unsigned int paramStartReadIdx = readIdx;
+ findChar(&paramStartReadIdx, definition, '(');
+
+ unsigned int methodReadIdx = reverseFindAlphaNum(paramStartReadIdx, definition);
+
+ extractRegion(heap, &function.retType, readIdx, methodReadIdx, definition);
+
+ tempReadIdx = methodReadIdx;
+ extractAlphaNum(heap, &function.method, &tempReadIdx, definition);
+
+ readIdx = paramStartReadIdx;
+
+ function.numParams = 0;
+ while (function.numParams < maxFunctionParams)
+ {
+ unsigned int maxReadIdx = findParamDelimiter(readIdx, definition);
+
+ unsigned int instNameReadIdx = reverseFindAlphaNum(maxReadIdx, definition);
+
+ // break if no name found
+ if (instNameReadIdx == maxReadIdx)
+ {
+ break;
+ }
+
+ FunctionParams funcParams = {};
+
+ // extract type name, found on interval readIdx to instNameReadIdx
+ extractRegion(heap, &funcParams.typeName, readIdx + 1, instNameReadIdx, definition);
+
+ // extract inst name, found on interval instNameReadIdx to maxReadIdx
+ tempReadIdx = instNameReadIdx;
+ extractAlphaNum(heap, &funcParams.instName, &tempReadIdx, definition);
+
+ // advance read index
+ readIdx = maxReadIdx + 1;
+
+ function.params[function.numParams++] = funcParams;
+ }
+
+ return function;
+} \ No newline at end of file
diff --git a/demo/DemoAppCodeGen/loaderCodeGen.h b/demo/DemoAppCodeGen/loaderCodeGen.h
new file mode 100644
index 0000000..b92beb1
--- /dev/null
+++ b/demo/DemoAppCodeGen/loaderCodeGen.h
@@ -0,0 +1,335 @@
+/*
+* 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.
+*/
+
+#pragma once
+
+enum LoaderType
+{
+ eLoaderTypeDynamicLink = 0,
+ eLoaderTypeStaticLink = 1
+};
+
+const unsigned int maxFunctionParams = 8u;
+
+struct FunctionParams
+{
+ const char* typeName;
+ const char* instName;
+};
+
+struct Function
+{
+ const char* retType;
+ const char* method;
+ unsigned int numParams;
+ FunctionParams params[maxFunctionParams];
+};
+
+struct GenerateCodeParams
+{
+ LoaderType loaderType;
+ FILE* file;
+ Function* functions;
+ unsigned int numFunctions;
+
+ const char* filenameTmp;
+ const char* filenameDst;
+ const char* moduleNameUpperCase;
+ const char* moduleNameLowerCase;
+ const char* instName;
+ const char* apiMarker;
+};
+
+void typedef_function_ptrs(const GenerateCodeParams* params)
+{
+ for (unsigned int functionIdx = 0u; functionIdx < params->numFunctions; functionIdx++)
+ {
+ auto& function = params->functions[functionIdx];
+
+ fprintf(params->file, "typedef %s (*%s_ptr_t)(", function.retType, function.method);
+
+ for (unsigned int paramIdx = 0u; paramIdx < function.numParams; paramIdx++)
+ {
+ fprintf(params->file, "%s %s", function.params[paramIdx].typeName, function.params[paramIdx].instName);
+
+ if (paramIdx < function.numParams - 1) fprintf(params->file, ", ");
+ }
+
+ fprintf(params->file, ");\n");
+ }
+
+ fprintf(params->file, "\n");
+}
+
+void declare_function_ptrs(const GenerateCodeParams* params)
+{
+ for (unsigned int functionIdx = 0u; functionIdx < params->numFunctions; functionIdx++)
+ {
+ auto& function = params->functions[functionIdx];
+
+ fprintf(params->file, "\t%s_ptr_t %s_ptr;\n", function.method, function.method);
+ }
+}
+
+void implement_pointer_wrappers(const GenerateCodeParams* params)
+{
+ for (unsigned int functionIdx = 0u; functionIdx < params->numFunctions; functionIdx++)
+ {
+ auto& function = params->functions[functionIdx];
+
+ fprintf(params->file, "%s %s(", function.retType, function.method);
+
+ for (unsigned int paramIdx = 0u; paramIdx < function.numParams; paramIdx++)
+ {
+ fprintf(params->file, "%s %s", function.params[paramIdx].typeName, function.params[paramIdx].instName);
+
+ if (paramIdx < function.numParams - 1) fprintf(params->file, ", ");
+ }
+
+ fprintf(params->file, ")\n{\n");
+
+ fprintf(params->file, "\treturn %s.%s_ptr(", params->instName, function.method);
+
+ for (unsigned int paramIdx = 0u; paramIdx < function.numParams; paramIdx++)
+ {
+ fprintf(params->file, "%s", function.params[paramIdx].instName);
+
+ if (paramIdx < function.numParams - 1) fprintf(params->file, ", ");
+ }
+
+ fprintf(params->file, ");\n");
+
+ fprintf(params->file, "}\n\n");
+ }
+}
+
+void load_function_ptrs(const GenerateCodeParams* params)
+{
+ for (unsigned int functionIdx = 0u; functionIdx < params->numFunctions; functionIdx++)
+ {
+ auto& function = params->functions[functionIdx];
+
+ fprintf(params->file, "\t%s.%s_ptr = ", params->instName, function.method);
+
+ fprintf(params->file, "(%s_ptr_t", function.method);
+
+ fprintf(params->file, ")(%sLoaderLoadFunction(&%s, \"%s\")", params->moduleNameLowerCase, params->instName, function.method);
+
+ fprintf(params->file, ");\n");
+ }
+}
+
+void load_function_ptrs_static(const GenerateCodeParams* params, const char* suffix)
+{
+ fprintf(params->file, "\tif (type == APP_CONTEXT_%s)\n\t{\n", suffix);
+
+ for (unsigned int functionIdx = 0u; functionIdx < params->numFunctions; functionIdx++)
+ {
+ auto& function = params->functions[functionIdx];
+
+ fprintf(params->file, "\t\t%s.%s_ptr = ", params->instName, function.method);
+
+ fprintf(params->file, "%s%s;\n", function.method, suffix);
+ }
+
+ fprintf(params->file, "\t}\n\n");
+}
+
+void unload_function_ptrs(const GenerateCodeParams* params)
+{
+ for (unsigned int functionIdx = 0u; functionIdx < params->numFunctions; functionIdx++)
+ {
+ auto& function = params->functions[functionIdx];
+
+ fprintf(params->file, "\t%s.%s_ptr = nullptr;\n", params->instName, function.method);
+ }
+}
+
+void declare_backend_functions(const GenerateCodeParams* params, const char* suffix)
+{
+ for (unsigned int functionIdx = 0u; functionIdx < params->numFunctions; functionIdx++)
+ {
+ auto& function = params->functions[functionIdx];
+
+ fprintf(params->file, "%s %s %s%s(", params->apiMarker, function.retType, function.method, suffix);
+
+ for (unsigned int paramIdx = 0u; paramIdx < function.numParams; paramIdx++)
+ {
+ fprintf(params->file, "%s %s", function.params[paramIdx].typeName, function.params[paramIdx].instName);
+
+ if (paramIdx < function.numParams - 1) fprintf(params->file, ", ");
+ }
+
+ fprintf(params->file, ");\n");
+ }
+
+ fprintf(params->file, "\n");
+}
+
+const char* fileHeader =
+"/*\n"
+"* Copyright (c) 2014-2017, NVIDIA CORPORATION. All rights reserved.\n"
+"*\n"
+"* NVIDIA CORPORATION and its licensors retain all intellectual property\n"
+"* and proprietary rights in and to this software, related documentation\n"
+"* and any modifications thereto. Any use, reproduction, disclosure or\n"
+"* distribution of this software and related documentation without an express\n"
+"* license agreement from NVIDIA CORPORATION is strictly prohibited.\n"
+"*/\n\n";
+
+void generateCode(const GenerateCodeParams* params)
+{
+ fprintf(params->file, fileHeader);
+
+ typedef_function_ptrs(params);
+
+ const char* loaderBegin =
+ "struct %sLoader \n"
+ "{ \n"
+ " void* module = nullptr; \n"
+ " const char* suffix = \"\"; \n"
+ " char buf[1024u]; \n\n";
+ fprintf(params->file, loaderBegin, params->moduleNameUpperCase);
+
+ declare_function_ptrs(params);
+
+ const char* loaderEnd =
+ "\n"
+ "}%s; \n\n";
+ fprintf(params->file, loaderEnd, params->instName);
+
+ implement_pointer_wrappers(params);
+
+ if (params->loaderType == eLoaderTypeDynamicLink)
+ {
+ const char* loaderFunction =
+ "void* %sLoaderLoadFunction(%sLoader* inst, const char* name)\n"
+ "{\n"
+ " snprintf(inst->buf, 1024u, \"%s%s\", name, inst->suffix);\n"
+ "\n"
+ " return SDL_LoadFunction(inst->module, inst->buf);\n"
+ "}\n\n";
+ fprintf(params->file, loaderFunction, params->moduleNameLowerCase, params->moduleNameUpperCase, "%s", "%s");
+
+ const char* loadModule =
+ "void load%s(AppGraphCtxType type)\n"
+ "{\n"
+ " const char* moduleName = demoAppDLLName(type);\n"
+ "\n"
+ " %s.suffix = demoAppBackendSuffix(type);\n"
+ "\n"
+ " %s.module = SDL_LoadObject(moduleName);\n\n";
+ fprintf(params->file, loadModule, params->moduleNameUpperCase, params->instName, params->instName);
+
+ load_function_ptrs(params);
+
+ const char* unloadModule =
+ "}\n"
+ "\n"
+ "void unload%s()\n"
+ "{\n";
+ fprintf(params->file, unloadModule, params->moduleNameUpperCase);
+
+ unload_function_ptrs(params);
+
+ const char* unloadModuleEnd =
+ "\n"
+ " SDL_UnloadObject(%s.module);\n"
+ "}\n";
+ fprintf(params->file, unloadModuleEnd, params->instName);
+ }
+ else if (params->loaderType == eLoaderTypeStaticLink)
+ {
+ const unsigned int suffixCount = 2u;
+ const char* suffix[suffixCount] = { "D3D11", "D3D12" };
+
+ for (unsigned int suffixIdx = 0u; suffixIdx < 2u; suffixIdx++)
+ {
+ declare_backend_functions(params, suffix[suffixIdx]);
+ }
+
+ const char* loadModule =
+ "void load%s(AppGraphCtxType type)\n"
+ "{\n"
+ " %s.suffix = demoAppBackendSuffix(type);\n"
+ "\n";
+ fprintf(params->file, loadModule, params->moduleNameUpperCase, params->instName);
+
+ for (unsigned int suffixIdx = 0u; suffixIdx < 2u; suffixIdx++)
+ {
+ load_function_ptrs_static(params, suffix[suffixIdx]);
+ }
+
+ const char* unloadModule =
+ "}\n"
+ "\n"
+ "void unload%s()\n"
+ "{\n";
+ fprintf(params->file, unloadModule, params->moduleNameUpperCase);
+
+ unload_function_ptrs(params);
+
+ const char* unloadModuleEnd =
+ "\n"
+ "}\n";
+ fprintf(params->file, unloadModuleEnd, params->instName);
+ }
+}
+
+void fileDiffAndWriteIfModified(const GenerateCodeParams* params)
+{
+ FILE* fileTmp = nullptr;
+ FILE* fileDst = nullptr;
+ bool match = true;
+
+ fopen_s(&fileDst, params->filenameDst, "r");
+ if (fileDst)
+ {
+ fopen_s(&fileTmp, params->filenameTmp, "r");
+ if (fileTmp)
+ {
+ while (1)
+ {
+ int a = fgetc(fileTmp);
+ int b = fgetc(fileDst);
+
+ if (a == EOF && b == EOF)
+ {
+ break;
+ }
+ else if (a != b)
+ {
+ match = false;
+ break;
+ }
+ }
+
+ fclose(fileTmp);
+ }
+ else
+ {
+ match = false;
+ }
+ fclose(fileDst);
+ }
+ else
+ {
+ match = false;
+ }
+
+ if (!match)
+ {
+ remove(params->filenameDst);
+ rename(params->filenameTmp, params->filenameDst);
+ }
+
+ // always cleanup temp file
+ remove(params->filenameTmp);
+} \ No newline at end of file
diff --git a/demo/DemoAppD3D11/NvFlowInteropD3D11.cpp b/demo/DemoAppD3D11/NvFlowInteropD3D11.cpp
index 23aaf9c..4f4b1cf 100644
--- a/demo/DemoAppD3D11/NvFlowInteropD3D11.cpp
+++ b/demo/DemoAppD3D11/NvFlowInteropD3D11.cpp
@@ -15,16 +15,32 @@
#include "NvFlowContextD3D11.h"
#include "appD3D11Ctx.h"
-NvFlowContext* NvFlowInteropCreateContext(AppGraphCtx* appctx)
+NV_FLOW_API NvFlowContext* NvFlowInteropCreateContextD3D11(AppGraphCtx* appctx);
+
+NV_FLOW_API NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilViewD3D11(AppGraphCtx* appctx, NvFlowContext* flowctx);
+
+NV_FLOW_API NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetViewD3D11(AppGraphCtx* appctx, NvFlowContext* flowctx);
+
+NV_FLOW_API void NvFlowInteropUpdateContextD3D11(NvFlowContext* context, AppGraphCtx* appctx);
+
+NV_FLOW_API void NvFlowInteropUpdateDepthStencilViewD3D11(NvFlowDepthStencilView* view, AppGraphCtx* appctx, NvFlowContext* flowctx);
+
+NV_FLOW_API void NvFlowInteropUpdateRenderTargetViewD3D11(NvFlowRenderTargetView* view, AppGraphCtx* appctx, NvFlowContext* flowctx);
+
+NvFlowContext* NvFlowInteropCreateContextD3D11(AppGraphCtx* appctxIn)
{
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
NvFlowContextDescD3D11 desc = {};
desc.device = appctx->m_device;
desc.deviceContext = appctx->m_deviceContext;
return NvFlowCreateContextD3D11(NV_FLOW_VERSION, &desc);
}
-NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilView(AppGraphCtx* appctx, NvFlowContext* flowctx)
+NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilViewD3D11(AppGraphCtx* appctxIn, NvFlowContext* flowctx)
{
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
NvFlowDepthStencilViewDescD3D11 desc = {};
desc.dsv = appctx->m_dsv;
desc.srv = appctx->m_depthSRV;
@@ -32,24 +48,30 @@ NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilView(AppGraphCtx* appctx,
return NvFlowCreateDepthStencilViewD3D11(flowctx, &desc);
}
-NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetView(AppGraphCtx* appctx, NvFlowContext* flowctx)
+NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetViewD3D11(AppGraphCtx* appctxIn, NvFlowContext* flowctx)
{
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
NvFlowRenderTargetViewDescD3D11 desc = {};
desc.rtv = appctx->m_rtv;
desc.viewport = appctx->m_viewport;
return NvFlowCreateRenderTargetViewD3D11(flowctx, &desc);
}
-void NvFlowInteropUpdateContext(NvFlowContext* context, AppGraphCtx* appctx)
+void NvFlowInteropUpdateContextD3D11(NvFlowContext* context, AppGraphCtx* appctxIn)
{
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
NvFlowContextDescD3D11 desc = {};
desc.device = appctx->m_device;
desc.deviceContext = appctx->m_deviceContext;
NvFlowUpdateContextD3D11(context, &desc);
}
-void NvFlowInteropUpdateDepthStencilView(NvFlowDepthStencilView* view, AppGraphCtx* appctx, NvFlowContext* flowctx)
+void NvFlowInteropUpdateDepthStencilViewD3D11(NvFlowDepthStencilView* view, AppGraphCtx* appctxIn, NvFlowContext* flowctx)
{
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
NvFlowDepthStencilViewDescD3D11 desc = {};
desc.dsv = appctx->m_dsv;
desc.srv = appctx->m_depthSRV;
@@ -57,8 +79,10 @@ void NvFlowInteropUpdateDepthStencilView(NvFlowDepthStencilView* view, AppGraphC
NvFlowUpdateDepthStencilViewD3D11(flowctx, view, &desc);
}
-void NvFlowInteropUpdateRenderTargetView(NvFlowRenderTargetView* view, AppGraphCtx* appctx, NvFlowContext* flowctx)
+void NvFlowInteropUpdateRenderTargetViewD3D11(NvFlowRenderTargetView* view, AppGraphCtx* appctxIn, NvFlowContext* flowctx)
{
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
NvFlowRenderTargetViewDescD3D11 desc = {};
desc.rtv = appctx->m_rtv;
desc.viewport = appctx->m_viewport;
diff --git a/demo/DemoAppD3D11/appD3D11Ctx.cpp b/demo/DemoAppD3D11/appD3D11Ctx.cpp
index 959614c..dd2bd2c 100644
--- a/demo/DemoAppD3D11/appD3D11Ctx.cpp
+++ b/demo/DemoAppD3D11/appD3D11Ctx.cpp
@@ -45,25 +45,23 @@ namespace
}
}
-AppGraphProfiler* appGraphCreateProfiler(AppGraphCtx* ctx);
-void appGraphProfilerFrameBegin(AppGraphProfiler* profiler);
-void appGraphProfilerFrameEnd(AppGraphProfiler* profiler);
-void appGraphProfilerEnable(AppGraphProfiler* profiler, bool enabled);
-void appGraphProfilerBegin(AppGraphProfiler* profiler, const char* label);
-void appGraphProfilerEnd(AppGraphProfiler* profiler, const char* label);
-bool appGraphProfilerGet(AppGraphProfiler* profiler, const char** plabel, float* cpuTime, float* gpuTime, int index);
-void appGraphReleaseProfiler(AppGraphProfiler* profiler);
-
-void AppGraphCtxInitRenderTarget(AppGraphCtx* context, SDL_Window* window, bool fullscreen);
-
-AppGraphCtx::AppGraphCtx()
+AppGraphProfilerD3D11* appGraphCreateProfilerD3D11(AppGraphCtx* ctx);
+void appGraphProfilerD3D11FrameBegin(AppGraphProfilerD3D11* profiler);
+void appGraphProfilerD3D11FrameEnd(AppGraphProfilerD3D11* profiler);
+void appGraphProfilerD3D11Enable(AppGraphProfilerD3D11* profiler, bool enabled);
+void appGraphProfilerD3D11Begin(AppGraphProfilerD3D11* profiler, const char* label);
+void appGraphProfilerD3D11End(AppGraphProfilerD3D11* profiler, const char* label);
+bool appGraphProfilerD3D11Get(AppGraphProfilerD3D11* profiler, const char** plabel, float* cpuTime, float* gpuTime, int index);
+void appGraphReleaseProfiler(AppGraphProfilerD3D11* profiler);
+
+AppGraphCtxD3D11::AppGraphCtxD3D11()
{
- m_profiler = appGraphCreateProfiler(this);
+ m_profiler = appGraphCreateProfilerD3D11(cast_from_AppGraphCtxD3D11(this));
}
-AppGraphCtx::~AppGraphCtx()
+AppGraphCtxD3D11::~AppGraphCtxD3D11()
{
- AppGraphCtxReleaseRenderTarget(this);
+ AppGraphCtxReleaseRenderTargetD3D11(cast_from_AppGraphCtxD3D11(this));
COMRelease(m_device);
COMRelease(m_deviceContext);
@@ -73,9 +71,9 @@ AppGraphCtx::~AppGraphCtx()
m_profiler = nullptr;
}
-AppGraphCtx* AppGraphCtxCreate(int deviceID)
+AppGraphCtx* AppGraphCtxCreateD3D11(int deviceID)
{
- AppGraphCtx* context = new AppGraphCtx;
+ AppGraphCtxD3D11* context = new AppGraphCtxD3D11;
HRESULT hr = S_OK;
@@ -160,11 +158,15 @@ AppGraphCtx* AppGraphCtxCreate(int deviceID)
return nullptr;
}
- return context;
+ return cast_from_AppGraphCtxD3D11(context);
}
-bool AppGraphCtxUpdateSize(AppGraphCtx* context, SDL_Window* window, bool fullscreen)
+void AppGraphCtxInitRenderTargetD3D11(AppGraphCtx* context, SDL_Window* window, bool fullscreen);
+
+bool AppGraphCtxUpdateSizeD3D11(AppGraphCtx* contextIn, SDL_Window* window, bool fullscreen)
{
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+
// TODO: fix iflip fullscreen support
fullscreen = false;
@@ -204,18 +206,20 @@ bool AppGraphCtxUpdateSize(AppGraphCtx* context, SDL_Window* window, bool fullsc
if (sizeChanged)
{
- AppGraphCtxReleaseRenderTarget(context);
+ AppGraphCtxReleaseRenderTargetD3D11(cast_from_AppGraphCtxD3D11(context));
}
if (sizeChanged && context->m_valid)
{
- AppGraphCtxInitRenderTarget(context, window, fullscreen);
+ AppGraphCtxInitRenderTargetD3D11(cast_from_AppGraphCtxD3D11(context), window, fullscreen);
}
return context->m_valid;
}
-void AppGraphCtxInitRenderTarget(AppGraphCtx* context, SDL_Window* window, bool fullscreen)
+void AppGraphCtxInitRenderTargetD3D11(AppGraphCtx* contextIn, SDL_Window* window, bool fullscreen)
{
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+
HWND hWnd = nullptr;
// get Windows handle to this SDL window
SDL_SysWMinfo winInfo;
@@ -354,8 +358,10 @@ void AppGraphCtxInitRenderTarget(AppGraphCtx* context, SDL_Window* window, bool
}
}
-void AppGraphCtxReleaseRenderTarget(AppGraphCtx* context)
+void AppGraphCtxReleaseRenderTargetD3D11(AppGraphCtx* contextIn)
{
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+
if (context->m_swapChain == nullptr)
{
return;
@@ -376,58 +382,66 @@ void AppGraphCtxReleaseRenderTarget(AppGraphCtx* context)
context->m_winH = 0u;
}
-void AppGraphCtxRelease(AppGraphCtx* context)
+void AppGraphCtxReleaseD3D11(AppGraphCtx* context)
{
if (context == nullptr) return;
- delete context;
+ delete cast_to_AppGraphCtxD3D11(context);
}
-void AppGraphCtxFrameStart(AppGraphCtx* context, float clearColor[4])
+void AppGraphCtxFrameStartD3D11(AppGraphCtx* contextIn, AppGraphColor clearColor)
{
- appGraphProfilerFrameBegin(context->m_profiler);
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+
+ appGraphProfilerD3D11FrameBegin(context->m_profiler);
context->m_deviceContext->RSSetViewports(1, &context->m_viewport);
context->m_deviceContext->RSSetScissorRects(0, nullptr);
context->m_deviceContext->OMSetRenderTargets(1, &context->m_rtv, context->m_dsv);
- context->m_deviceContext->ClearRenderTargetView(context->m_rtv, clearColor);
+ context->m_deviceContext->ClearRenderTargetView(context->m_rtv, &clearColor.r);
context->m_deviceContext->ClearDepthStencilView(context->m_dsv, D3D11_CLEAR_DEPTH, 1.f, 0u);
context->m_deviceContext->OMSetDepthStencilState(context->m_depthState, 0u);
}
-void AppGraphCtxFramePresent(AppGraphCtx* context, bool fullsync)
+void AppGraphCtxFramePresentD3D11(AppGraphCtx* contextIn, bool fullsync)
{
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+
context->m_swapChain->Present(0, 0);
- appGraphProfilerFrameEnd(context->m_profiler);
+ appGraphProfilerD3D11FrameEnd(context->m_profiler);
}
-void AppGraphCtxWaitForFrames(AppGraphCtx* context, unsigned int maxFramesInFlight)
+void AppGraphCtxWaitForFramesD3D11(AppGraphCtx* context, unsigned int maxFramesInFlight)
{
// TODO: Implement
}
-void AppGraphCtxProfileEnable(AppGraphCtx* context, bool enabled)
+void AppGraphCtxProfileEnableD3D11(AppGraphCtx* contextIn, bool enabled)
{
- appGraphProfilerEnable(context->m_profiler, enabled);
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+ appGraphProfilerD3D11Enable(context->m_profiler, enabled);
}
-void AppGraphCtxProfileBegin(AppGraphCtx* context, const char* label)
+void AppGraphCtxProfileBeginD3D11(AppGraphCtx* contextIn, const char* label)
{
- appGraphProfilerBegin(context->m_profiler, label);
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+ appGraphProfilerD3D11Begin(context->m_profiler, label);
}
-void AppGraphCtxProfileEnd(AppGraphCtx* context, const char* label)
+void AppGraphCtxProfileEndD3D11(AppGraphCtx* contextIn, const char* label)
{
- appGraphProfilerEnd(context->m_profiler, label);
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+ appGraphProfilerD3D11End(context->m_profiler, label);
}
-bool AppGraphCtxProfileGet(AppGraphCtx* context, const char** plabel, float* cpuTime, float* gpuTime, int index)
+bool AppGraphCtxProfileGetD3D11(AppGraphCtx* contextIn, const char** plabel, float* cpuTime, float* gpuTime, int index)
{
- return appGraphProfilerGet(context->m_profiler, plabel, cpuTime, gpuTime, index);
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
+ return appGraphProfilerD3D11Get(context->m_profiler, plabel, cpuTime, gpuTime, index);
}
// ******************************* Profiler *********************************
@@ -549,9 +563,9 @@ namespace
};
}
-struct AppGraphProfiler
+struct AppGraphProfilerD3D11
{
- AppGraphCtx* m_context;
+ AppGraphCtxD3D11* m_context;
int m_state = 0;
bool m_enabled = false;
@@ -568,30 +582,30 @@ struct AppGraphProfiler
TimerValue m_timerValues[m_timersCap];
int m_timerValuesSize = 0;
- AppGraphProfiler(AppGraphCtx* context);
- ~AppGraphProfiler();
+ AppGraphProfilerD3D11(AppGraphCtx* context);
+ ~AppGraphProfilerD3D11();
};
-AppGraphProfiler::AppGraphProfiler(AppGraphCtx* context) : m_context(context)
+AppGraphProfilerD3D11::AppGraphProfilerD3D11(AppGraphCtx* context) : m_context(cast_to_AppGraphCtxD3D11(context))
{
}
-AppGraphProfiler::~AppGraphProfiler()
+AppGraphProfilerD3D11::~AppGraphProfilerD3D11()
{
COMRelease(m_disjoint);
}
-AppGraphProfiler* appGraphCreateProfiler(AppGraphCtx* ctx)
+AppGraphProfilerD3D11* appGraphCreateProfilerD3D11(AppGraphCtx* ctx)
{
- return new AppGraphProfiler(ctx);
+ return new AppGraphProfilerD3D11(ctx);
}
-void appGraphReleaseProfiler(AppGraphProfiler* profiler)
+void appGraphReleaseProfiler(AppGraphProfilerD3D11* profiler)
{
delete profiler;
}
-void appGraphProfilerFrameBegin(AppGraphProfiler* p)
+void appGraphProfilerD3D11FrameBegin(AppGraphProfilerD3D11* p)
{
p->m_frameTime = (float)p->m_frameTimer.getDeltaTime();
@@ -616,7 +630,7 @@ void appGraphProfilerFrameBegin(AppGraphProfiler* p)
}
}
-void appGraphProfilerFrameEnd(AppGraphProfiler* p)
+void appGraphProfilerD3D11FrameEnd(AppGraphProfilerD3D11* p)
{
if (p->m_state == 1)
{
@@ -628,12 +642,12 @@ void appGraphProfilerFrameEnd(AppGraphProfiler* p)
}
}
-void appGraphProfilerEnable(AppGraphProfiler* p, bool enabled)
+void appGraphProfilerD3D11Enable(AppGraphProfilerD3D11* p, bool enabled)
{
p->m_enabled = enabled;
}
-void appGraphProfilerBegin(AppGraphProfiler* p, const char* label)
+void appGraphProfilerD3D11Begin(AppGraphProfilerD3D11* p, const char* label)
{
if (p->m_state == 1 && p->m_timersSize < p->m_timersCap)
{
@@ -657,7 +671,7 @@ void appGraphProfilerBegin(AppGraphProfiler* p, const char* label)
}
}
-void appGraphProfilerEnd(AppGraphProfiler* p, const char* label)
+void appGraphProfilerD3D11End(AppGraphProfilerD3D11* p, const char* label)
{
if (p->m_state == 1)
{
@@ -681,7 +695,7 @@ void appGraphProfilerEnd(AppGraphProfiler* p, const char* label)
}
}
-bool appGraphProfilerFlush(AppGraphProfiler* p)
+bool appGraphProfilerD3D11Flush(AppGraphProfilerD3D11* p)
{
if (p->m_state == 2)
{
@@ -740,9 +754,9 @@ bool appGraphProfilerFlush(AppGraphProfiler* p)
return false;
}
-bool appGraphProfilerGet(AppGraphProfiler* p, const char** plabel, float* cpuTime, float* gpuTime, int index)
+bool appGraphProfilerD3D11Get(AppGraphProfilerD3D11* p, const char** plabel, float* cpuTime, float* gpuTime, int index)
{
- appGraphProfilerFlush(p);
+ appGraphProfilerD3D11Flush(p);
{
if (index < p->m_timerValuesSize)
{
@@ -760,7 +774,8 @@ bool appGraphProfilerGet(AppGraphProfiler* p, const char** plabel, float* cpuTim
return false;
}
-size_t AppGraphCtxDedicatedVideoMemory(AppGraphCtx* context)
+size_t AppGraphCtxDedicatedVideoMemoryD3D11(AppGraphCtx* contextIn)
{
+ auto context = cast_to_AppGraphCtxD3D11(contextIn);
return context->m_dedicatedVideoMemory;
} \ No newline at end of file
diff --git a/demo/DemoAppD3D11/appD3D11Ctx.h b/demo/DemoAppD3D11/appD3D11Ctx.h
index 578413c..c811f8b 100644
--- a/demo/DemoAppD3D11/appD3D11Ctx.h
+++ b/demo/DemoAppD3D11/appD3D11Ctx.h
@@ -12,9 +12,9 @@
#include "../DemoApp/appGraphCtx.h"
-struct AppGraphProfiler;
+struct AppGraphProfilerD3D11;
-struct AppGraphCtx
+struct AppGraphCtxD3D11
{
HWND m_hWnd = nullptr;
@@ -36,8 +36,42 @@ struct AppGraphCtx
ID3D11ShaderResourceView* m_depthSRV = nullptr;
ID3D11DepthStencilState* m_depthState = nullptr;
- AppGraphProfiler* m_profiler = nullptr;
+ AppGraphProfilerD3D11* m_profiler = nullptr;
- AppGraphCtx();
- ~AppGraphCtx();
-}; \ No newline at end of file
+ AppGraphCtxD3D11();
+ ~AppGraphCtxD3D11();
+};
+
+inline AppGraphCtxD3D11* cast_to_AppGraphCtxD3D11(AppGraphCtx* appctx)
+{
+ return (AppGraphCtxD3D11*)(appctx);
+}
+
+inline AppGraphCtx* cast_from_AppGraphCtxD3D11(AppGraphCtxD3D11* appctx)
+{
+ return (AppGraphCtx*)(appctx);
+}
+
+APP_GRAPH_CTX_API AppGraphCtx* AppGraphCtxCreateD3D11(int deviceID);
+
+APP_GRAPH_CTX_API bool AppGraphCtxUpdateSizeD3D11(AppGraphCtx* context, SDL_Window* window, bool fullscreen);
+
+APP_GRAPH_CTX_API void AppGraphCtxReleaseRenderTargetD3D11(AppGraphCtx* context);
+
+APP_GRAPH_CTX_API void AppGraphCtxReleaseD3D11(AppGraphCtx* context);
+
+APP_GRAPH_CTX_API void AppGraphCtxFrameStartD3D11(AppGraphCtx* context, AppGraphColor clearColor);
+
+APP_GRAPH_CTX_API void AppGraphCtxFramePresentD3D11(AppGraphCtx* context, bool fullsync);
+
+APP_GRAPH_CTX_API void AppGraphCtxWaitForFramesD3D11(AppGraphCtx* context, unsigned int maxFramesInFlight);
+
+APP_GRAPH_CTX_API void AppGraphCtxProfileEnableD3D11(AppGraphCtx* context, bool enabled);
+
+APP_GRAPH_CTX_API void AppGraphCtxProfileBeginD3D11(AppGraphCtx* context, const char* label);
+
+APP_GRAPH_CTX_API void AppGraphCtxProfileEndD3D11(AppGraphCtx* context, const char* label);
+
+APP_GRAPH_CTX_API bool AppGraphCtxProfileGetD3D11(AppGraphCtx* context, const char** plabel, float* cpuTime, float* gpuTime, int index);
+
+APP_GRAPH_CTX_API size_t AppGraphCtxDedicatedVideoMemoryD3D11(AppGraphCtx* context); \ No newline at end of file
diff --git a/demo/DemoAppD3D11/computeContextD3D11.cpp b/demo/DemoAppD3D11/computeContextD3D11.cpp
index 2f25f95..f4b4c3e 100644
--- a/demo/DemoAppD3D11/computeContextD3D11.cpp
+++ b/demo/DemoAppD3D11/computeContextD3D11.cpp
@@ -21,9 +21,9 @@ void inline COMRelease(T& t)
t = nullptr;
}
-struct ComputeContext
+struct ComputeContextD3D11
{
- ComputeContextDesc m_desc = {};
+ ComputeContextDescD3D11 m_desc = {};
ID3D11SamplerState* m_sampler0 = nullptr;
ID3D11SamplerState* m_sampler1 = nullptr;
@@ -32,8 +32,10 @@ struct ComputeContext
ID3D11SamplerState* m_sampler4 = nullptr;
ID3D11SamplerState* m_sampler5 = nullptr;
- ComputeContext(const ComputeContextDesc* desc)
+ ComputeContextD3D11(const ComputeContextDesc* descIn)
{
+ const auto desc = cast_to_ComputeContextDescD3D11(descIn);
+
m_desc = *desc;
auto createSampler = [&](D3D11_FILTER filter, D3D11_TEXTURE_ADDRESS_MODE mode)
@@ -64,7 +66,7 @@ struct ComputeContext
m_sampler4 = createSampler(D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D11_TEXTURE_ADDRESS_CLAMP);
m_sampler5 = createSampler(D3D11_FILTER_MIN_MAG_MIP_POINT, D3D11_TEXTURE_ADDRESS_CLAMP);
}
- ~ComputeContext()
+ ~ComputeContextD3D11()
{
COMRelease(m_sampler0);
COMRelease(m_sampler1);
@@ -75,43 +77,74 @@ struct ComputeContext
}
};
-struct ComputeShader
+inline ComputeContextD3D11* cast_to_ComputeContextD3D11(ComputeContext* ctx)
+{
+ return (ComputeContextD3D11*)(ctx);
+}
+
+inline ComputeContext* cast_from_ComputeContextD3D11(ComputeContextD3D11* ctx)
+{
+ return (ComputeContext*)(ctx);
+}
+
+struct ComputeShaderD3D11
{
ID3D11ComputeShader* m_shader = nullptr;
- ComputeShader(ID3D11ComputeShader* shader)
+ ComputeShaderD3D11(ID3D11ComputeShader* shader)
{
m_shader = shader;
}
- ~ComputeShader()
+ ~ComputeShaderD3D11()
{
COMRelease(m_shader);
}
};
-struct ComputeConstantBuffer
+inline ComputeShaderD3D11* cast_to_ComputeShaderD3D11(ComputeShader* ctx)
+{
+ return (ComputeShaderD3D11*)(ctx);
+}
+
+inline ComputeShader* cast_from_ComputeShaderD3D11(ComputeShaderD3D11* ctx)
+{
+ return (ComputeShader*)(ctx);
+}
+
+struct ComputeConstantBufferD3D11
{
ID3D11Buffer* m_buffer;
- ComputeConstantBuffer(ID3D11Buffer* buffer)
+ ComputeConstantBufferD3D11(ID3D11Buffer* buffer)
{
m_buffer = buffer;
}
- ~ComputeConstantBuffer()
+ ~ComputeConstantBufferD3D11()
{
COMRelease(m_buffer);
}
};
-struct ComputeResource
+inline ComputeConstantBufferD3D11* cast_to_ComputeConstantBufferD3D11(ComputeConstantBuffer* ctx)
+{
+ return (ComputeConstantBufferD3D11*)(ctx);
+}
+
+inline ComputeConstantBuffer* cast_from_ComputeConstantBufferD3D11(ComputeConstantBufferD3D11* ctx)
+{
+ return (ComputeConstantBuffer*)(ctx);
+}
+
+struct ComputeResourceD3D11
{
protected:
ID3D11ShaderResourceView* m_srv = nullptr;
public:
- void update(const ComputeResourceDesc* desc)
+ void update(const ComputeResourceDesc* descIn)
{
+ const auto desc = cast_to_ComputeResourceDescD3D11(descIn);
m_srv = desc->srv;
}
- ComputeResource(const ComputeResourceDesc* desc)
+ ComputeResourceD3D11(const ComputeResourceDesc* desc)
{
update(desc);
}
@@ -122,20 +155,37 @@ public:
}
};
-struct ComputeResourceRW : public ComputeResource
+inline ComputeResourceD3D11* cast_to_ComputeResourceD3D11(ComputeResource* ctx)
+{
+ return (ComputeResourceD3D11*)(ctx);
+}
+
+inline ComputeResource* cast_from_ComputeResourceD3D11(ComputeResourceD3D11* ctx)
+{
+ return (ComputeResource*)(ctx);
+}
+
+struct ComputeResourceRWD3D11 : public ComputeResourceD3D11
{
protected:
ID3D11UnorderedAccessView* m_uav;
public:
- void update(const ComputeResourceRWDesc* descRW)
+ static const ComputeResourceRWDescD3D11* cast(const ComputeResourceRWDesc* descRW)
{
+ return cast_to_ComputeResourceRWDescD3D11(descRW);
+ }
+
+ void update(const ComputeResourceRWDesc* descRWIn)
+ {
+ const auto descRW = cast(descRWIn);
m_uav = descRW->uav;
- ComputeResource::update(&descRW->resource);
+ ComputeResourceD3D11::update(cast_from_ComputeResourceDescD3D11(&descRW->resource));
}
- ComputeResourceRW(const ComputeResourceRWDesc* descRW):
- ComputeResource(&descRW->resource)
+ ComputeResourceRWD3D11(const ComputeResourceRWDesc* descRWIn):
+ ComputeResourceD3D11(cast_from_ComputeResourceDescD3D11(&cast(descRWIn)->resource))
{
+ const auto descRW = cast(descRWIn);
m_uav = descRW->uav;
}
@@ -145,37 +195,54 @@ public:
}
};
+inline ComputeResourceRWD3D11* cast_to_ComputeResourceRWD3D11(ComputeResourceRW* ctx)
+{
+ return (ComputeResourceRWD3D11*)(ctx);
+}
+
+inline ComputeResourceRW* cast_from_ComputeResourceRWD3D11(ComputeResourceRWD3D11* ctx)
+{
+ return (ComputeResourceRW*)(ctx);
+}
+
// ************* API functions ****************
-ComputeContext* ComputeContextCreate(ComputeContextDesc* desc)
+ComputeContext* ComputeContextCreateD3D11(ComputeContextDesc* desc)
{
- return new ComputeContext(desc);
+ return cast_from_ComputeContextD3D11(new ComputeContextD3D11(desc));
}
-void ComputeContextUpdate(ComputeContext* context, ComputeContextDesc* desc)
+void ComputeContextUpdateD3D11(ComputeContext* contextIn, ComputeContextDesc* descIn)
{
+ auto context = cast_to_ComputeContextD3D11(contextIn);
+ auto desc = cast_to_ComputeContextDescD3D11(descIn);
+
context->m_desc = *desc;
}
-void ComputeContextRelease(ComputeContext* context)
+void ComputeContextReleaseD3D11(ComputeContext* context)
{
- delete context;
+ delete cast_to_ComputeContextD3D11(context);
}
-ComputeShader* ComputeShaderCreate(ComputeContext* context, const ComputeShaderDesc* desc)
+ComputeShader* ComputeShaderCreateD3D11(ComputeContext* contextIn, const ComputeShaderDesc* desc)
{
+ auto context = cast_to_ComputeContextD3D11(contextIn);
+
ID3D11ComputeShader* computeShader = nullptr;
context->m_desc.device->CreateComputeShader(desc->cs, desc->cs_length, nullptr, &computeShader);
- return new ComputeShader(computeShader);
+ return cast_from_ComputeShaderD3D11(new ComputeShaderD3D11(computeShader));
}
-void ComputeShaderRelease(ComputeShader* shader)
+void ComputeShaderReleaseD3D11(ComputeShader* shader)
{
- delete shader;
+ delete cast_to_ComputeShaderD3D11(shader);
}
-ComputeConstantBuffer* ComputeConstantBufferCreate(ComputeContext* context, const ComputeConstantBufferDesc* desc)
+ComputeConstantBuffer* ComputeConstantBufferCreateD3D11(ComputeContext* contextIn, const ComputeConstantBufferDesc* desc)
{
+ auto context = cast_to_ComputeContextD3D11(contextIn);
+
ID3D11Buffer* constantBuffer = nullptr;
{
D3D11_BUFFER_DESC bufDesc;
@@ -187,81 +254,94 @@ ComputeConstantBuffer* ComputeConstantBufferCreate(ComputeContext* context, cons
context->m_desc.device->CreateBuffer(&bufDesc, nullptr, &constantBuffer);
}
- return new ComputeConstantBuffer(constantBuffer);
+ return cast_from_ComputeConstantBufferD3D11(new ComputeConstantBufferD3D11(constantBuffer));
}
-void ComputeConstantBufferRelease(ComputeConstantBuffer* constantBuffer)
+void ComputeConstantBufferReleaseD3D11(ComputeConstantBuffer* constantBuffer)
{
- delete constantBuffer;
+ delete cast_to_ComputeConstantBufferD3D11(constantBuffer);
}
-void* ComputeConstantBufferMap(ComputeContext* context, ComputeConstantBuffer* constantBuffer)
+void* ComputeConstantBufferMapD3D11(ComputeContext* contextIn, ComputeConstantBuffer* constantBufferIn)
{
+ auto context = cast_to_ComputeContextD3D11(contextIn);
+ auto constantBuffer = cast_to_ComputeConstantBufferD3D11(constantBufferIn);
+
D3D11_MAPPED_SUBRESOURCE mapped = {};
context->m_desc.deviceContext->Map(constantBuffer->m_buffer, 0u, D3D11_MAP_WRITE_DISCARD, 0u, &mapped);
return mapped.pData;
}
-void ComputeConstantBufferUnmap(ComputeContext* context, ComputeConstantBuffer* constantBuffer)
+void ComputeConstantBufferUnmapD3D11(ComputeContext* contextIn, ComputeConstantBuffer* constantBufferIn)
{
+ auto context = cast_to_ComputeContextD3D11(contextIn);
+ auto constantBuffer = cast_to_ComputeConstantBufferD3D11(constantBufferIn);
+
context->m_desc.deviceContext->Unmap(constantBuffer->m_buffer, 0u);
}
-ComputeResource* ComputeResourceCreate(ComputeContext* context, const ComputeResourceDesc* desc)
+ComputeResource* ComputeResourceCreateD3D11(ComputeContext* context, const ComputeResourceDesc* desc)
{
- return new ComputeResource(desc);
+ return cast_from_ComputeResourceD3D11(new ComputeResourceD3D11(desc));
}
-void ComputeResourceUpdate(ComputeContext* context, ComputeResource* resource, const ComputeResourceDesc* desc)
+void ComputeResourceUpdateD3D11(ComputeContext* context, ComputeResource* resourceIn, const ComputeResourceDesc* desc)
{
+ auto resource = cast_to_ComputeResourceD3D11(resourceIn);
+
resource->update(desc);
}
-void ComputeResourceRelease(ComputeResource* resource)
+void ComputeResourceReleaseD3D11(ComputeResource* resource)
{
- delete resource;
+ delete cast_to_ComputeResourceD3D11(resource);
}
-ComputeResourceRW* ComputeResourceRWCreate(ComputeContext* context, const ComputeResourceRWDesc* desc)
+ComputeResourceRW* ComputeResourceRWCreateD3D11(ComputeContext* context, const ComputeResourceRWDesc* desc)
{
- return new ComputeResourceRW(desc);
+ return cast_from_ComputeResourceRWD3D11(new ComputeResourceRWD3D11(desc));
}
-void ComputeResourceRWUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, const ComputeResourceRWDesc* desc)
+void ComputeResourceRWUpdateD3D11(ComputeContext* context, ComputeResourceRW* resourceRWIn, const ComputeResourceRWDesc* desc)
{
+ auto resourceRW = cast_to_ComputeResourceRWD3D11(resourceRWIn);
+
resourceRW->update(desc);
}
-void ComputeResourceRWRelease(ComputeResourceRW* resourceRW)
+void ComputeResourceRWReleaseD3D11(ComputeResourceRW* resourceRW)
{
- delete resourceRW;
+ delete cast_to_ComputeResourceRWD3D11(resourceRW);
}
-ComputeResource* ComputeResourceRWGetResource(ComputeResourceRW* resourceRW)
+ComputeResource* ComputeResourceRWGetResourceD3D11(ComputeResourceRW* resourceRWIn)
{
- return static_cast<ComputeResource*>(resourceRW);
+ auto resourceRW = cast_to_ComputeResourceRWD3D11(resourceRWIn);
+ return cast_from_ComputeResourceD3D11(static_cast<ComputeResourceD3D11*>(resourceRW));
}
-void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams* params)
+void ComputeContextDispatchD3D11(ComputeContext* contextIn, const ComputeDispatchParams* params)
{
+ auto context = cast_to_ComputeContextD3D11(contextIn);
+
auto& deviceContext = context->m_desc.deviceContext;
- if (params->shader) deviceContext->CSSetShader(params->shader->m_shader, nullptr, 0u);
+ if (params->shader) deviceContext->CSSetShader(cast_to_ComputeShaderD3D11(params->shader)->m_shader, nullptr, 0u);
ID3D11ShaderResourceView* srvs[ComputeDispatchMaxResources] = { nullptr };
ID3D11UnorderedAccessView* uavs[ComputeDispatchMaxResourcesRW] = { nullptr };
for (unsigned int i = 0u; i < ComputeDispatchMaxResources; i++)
{
- if (params->resources[i]) srvs[i] = params->resources[i]->SRV();
+ if (params->resources[i]) srvs[i] = cast_to_ComputeResourceD3D11(params->resources[i])->SRV();
}
for (unsigned int i = 0u; i < ComputeDispatchMaxResourcesRW; i++)
{
- if (params->resourcesRW[i]) uavs[i] = params->resourcesRW[i]->UAV();
+ if (params->resourcesRW[i]) uavs[i] = cast_to_ComputeResourceRWD3D11(params->resourcesRW[i])->UAV();
}
deviceContext->CSSetShaderResources(0u, ComputeDispatchMaxResources, srvs);
deviceContext->CSSetUnorderedAccessViews(0u, ComputeDispatchMaxResourcesRW, uavs, nullptr);
- if (params->constantBuffer) deviceContext->CSSetConstantBuffers(0u, 1u, &params->constantBuffer->m_buffer);
+ if (params->constantBuffer) deviceContext->CSSetConstantBuffers(0u, 1u, &cast_to_ComputeConstantBufferD3D11(params->constantBuffer)->m_buffer);
ID3D11SamplerState* samplers[] = {
context->m_sampler0, context->m_sampler1, context->m_sampler2,
@@ -282,7 +362,7 @@ void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams
#include "NvFlow.h"
#include "NvFlowContextD3D11.h"
-inline void updateComputeContextDesc(NvFlowContext* flowContext, ComputeContextDesc* desc)
+inline void updateComputeContextDesc(NvFlowContext* flowContext, ComputeContextDescD3D11* desc)
{
NvFlowContextDescD3D11 srcDesc = {};
NvFlowUpdateContextDescD3D11(flowContext, &srcDesc);
@@ -290,54 +370,54 @@ inline void updateComputeContextDesc(NvFlowContext* flowContext, ComputeContextD
desc->deviceContext = srcDesc.deviceContext;
}
-ComputeContext* ComputeContextNvFlowContextCreate(NvFlowContext* flowContext)
+ComputeContext* ComputeContextNvFlowContextCreateD3D11(NvFlowContext* flowContext)
{
- ComputeContextDesc desc = {};
+ ComputeContextDescD3D11 desc = {};
updateComputeContextDesc(flowContext, &desc);
- return ComputeContextCreate(&desc);
+ return ComputeContextCreateD3D11(cast_from_ComputeContextDescD3D11(&desc));
}
-void ComputeContextNvFlowContextUpdate(ComputeContext* computeContext, NvFlowContext* flowContext)
+void ComputeContextNvFlowContextUpdateD3D11(ComputeContext* computeContext, NvFlowContext* flowContext)
{
- ComputeContextDesc desc = {};
+ ComputeContextDescD3D11 desc = {};
updateComputeContextDesc(flowContext, &desc);
- ComputeContextUpdate(computeContext, &desc);
+ ComputeContextUpdateD3D11(computeContext, cast_from_ComputeContextDescD3D11(&desc));
}
-ComputeResource* ComputeResourceNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource)
+ComputeResource* ComputeResourceNvFlowCreateD3D11(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource)
{
NvFlowResourceViewDescD3D11 flowViewDesc = {};
NvFlowUpdateResourceViewDescD3D11(flowContext, flowResource, &flowViewDesc);
- ComputeResourceDesc desc = {};
+ ComputeResourceDescD3D11 desc = {};
desc.srv = flowViewDesc.srv;
- return ComputeResourceCreate(context, &desc);
+ return ComputeResourceCreateD3D11(context, cast_from_ComputeResourceDescD3D11(&desc));
}
-void ComputeResourceNvFlowUpdate(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource)
+void ComputeResourceNvFlowUpdateD3D11(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource)
{
NvFlowResourceViewDescD3D11 flowViewDesc = {};
NvFlowUpdateResourceViewDescD3D11(flowContext, flowResource, &flowViewDesc);
- ComputeResourceDesc desc = {};
+ ComputeResourceDescD3D11 desc = {};
desc.srv = flowViewDesc.srv;
- ComputeResourceUpdate(context, resource, &desc);
+ ComputeResourceUpdateD3D11(context, resource, cast_from_ComputeResourceDescD3D11(&desc));
}
-ComputeResourceRW* ComputeResourceRWNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
+ComputeResourceRW* ComputeResourceRWNvFlowCreateD3D11(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
{
NvFlowResourceRWViewDescD3D11 flowViewDesc = {};
NvFlowUpdateResourceRWViewDescD3D11(flowContext, flowResourceRW, &flowViewDesc);
- ComputeResourceRWDesc desc = {};
+ ComputeResourceRWDescD3D11 desc = {};
desc.resource.srv = flowViewDesc.resourceView.srv;
desc.uav = flowViewDesc.uav;
- return ComputeResourceRWCreate(context, &desc);
+ return ComputeResourceRWCreateD3D11(context, cast_from_ComputeResourceRWDescD3D11(&desc));
}
-void ComputeResourceRWNvFlowUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
+void ComputeResourceRWNvFlowUpdateD3D11(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
{
NvFlowResourceRWViewDescD3D11 flowViewDesc = {};
NvFlowUpdateResourceRWViewDescD3D11(flowContext, flowResourceRW, &flowViewDesc);
- ComputeResourceRWDesc desc = {};
+ ComputeResourceRWDescD3D11 desc = {};
desc.resource.srv = flowViewDesc.resourceView.srv;
desc.uav = flowViewDesc.uav;
- ComputeResourceRWUpdate(context, resourceRW, &desc);
+ ComputeResourceRWUpdateD3D11(context, resourceRW, cast_from_ComputeResourceRWDescD3D11(&desc));
} \ No newline at end of file
diff --git a/demo/DemoAppD3D11/computeContextD3D11.h b/demo/DemoAppD3D11/computeContextD3D11.h
index 43ad5b1..a8a2189 100644
--- a/demo/DemoAppD3D11/computeContextD3D11.h
+++ b/demo/DemoAppD3D11/computeContextD3D11.h
@@ -12,19 +12,95 @@
#include "../DemoApp/computeContext.h"
-struct ComputeContextDesc
+struct ComputeContextDescD3D11
{
ID3D11Device* device;
ID3D11DeviceContext* deviceContext;
};
-struct ComputeResourceDesc
+struct ComputeResourceDescD3D11
{
ID3D11ShaderResourceView* srv;
};
-struct ComputeResourceRWDesc
+struct ComputeResourceRWDescD3D11
{
- ComputeResourceDesc resource;
+ ComputeResourceDescD3D11 resource;
ID3D11UnorderedAccessView* uav;
-}; \ No newline at end of file
+};
+
+inline const ComputeContextDescD3D11* cast_to_ComputeContextDescD3D11(const ComputeContextDesc* desc)
+{
+ return (const ComputeContextDescD3D11*)(desc);
+}
+
+inline ComputeContextDesc* cast_from_ComputeContextDescD3D11(ComputeContextDescD3D11* desc)
+{
+ return (ComputeContextDesc*)(desc);
+}
+
+inline const ComputeResourceDescD3D11* cast_to_ComputeResourceDescD3D11(const ComputeResourceDesc* desc)
+{
+ return (const ComputeResourceDescD3D11*)(desc);
+}
+
+inline const ComputeResourceDesc* cast_from_ComputeResourceDescD3D11(const ComputeResourceDescD3D11* desc)
+{
+ return (const ComputeResourceDesc*)(desc);
+}
+
+inline const ComputeResourceRWDescD3D11* cast_to_ComputeResourceRWDescD3D11(const ComputeResourceRWDesc* desc)
+{
+ return (const ComputeResourceRWDescD3D11*)(desc);
+}
+
+inline ComputeResourceRWDesc* cast_from_ComputeResourceRWDescD3D11(ComputeResourceRWDescD3D11* desc)
+{
+ return (ComputeResourceRWDesc*)(desc);
+}
+
+COMPUTE_API ComputeContext* ComputeContextCreateD3D11(ComputeContextDesc* desc);
+
+COMPUTE_API void ComputeContextUpdateD3D11(ComputeContext* context, ComputeContextDesc* desc);
+
+COMPUTE_API void ComputeContextReleaseD3D11(ComputeContext* context);
+
+COMPUTE_API ComputeShader* ComputeShaderCreateD3D11(ComputeContext* context, const ComputeShaderDesc* desc);
+
+COMPUTE_API void ComputeShaderReleaseD3D11(ComputeShader* shader);
+
+COMPUTE_API ComputeConstantBuffer* ComputeConstantBufferCreateD3D11(ComputeContext* context, const ComputeConstantBufferDesc* desc);
+
+COMPUTE_API void ComputeConstantBufferReleaseD3D11(ComputeConstantBuffer* constantBuffer);
+
+COMPUTE_API void* ComputeConstantBufferMapD3D11(ComputeContext* context, ComputeConstantBuffer* constantBuffer);
+
+COMPUTE_API void ComputeConstantBufferUnmapD3D11(ComputeContext* context, ComputeConstantBuffer* constantBuffer);
+
+COMPUTE_API ComputeResource* ComputeResourceCreateD3D11(ComputeContext* context, const ComputeResourceDesc* desc);
+
+COMPUTE_API void ComputeResourceUpdateD3D11(ComputeContext* context, ComputeResource* resource, const ComputeResourceDesc* desc);
+
+COMPUTE_API void ComputeResourceReleaseD3D11(ComputeResource* resource);
+
+COMPUTE_API ComputeResourceRW* ComputeResourceRWCreateD3D11(ComputeContext* context, const ComputeResourceRWDesc* desc);
+
+COMPUTE_API void ComputeResourceRWUpdateD3D11(ComputeContext* context, ComputeResourceRW* resourceRW, const ComputeResourceRWDesc* desc);
+
+COMPUTE_API void ComputeResourceRWReleaseD3D11(ComputeResourceRW* resourceRW);
+
+COMPUTE_API ComputeResource* ComputeResourceRWGetResourceD3D11(ComputeResourceRW* resourceRW);
+
+COMPUTE_API void ComputeContextDispatchD3D11(ComputeContext* context, const ComputeDispatchParams* params);
+
+COMPUTE_API ComputeContext* ComputeContextNvFlowContextCreateD3D11(NvFlowContext* flowContext);
+
+COMPUTE_API void ComputeContextNvFlowContextUpdateD3D11(ComputeContext* computeContext, NvFlowContext* flowContext);
+
+COMPUTE_API ComputeResource* ComputeResourceNvFlowCreateD3D11(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource);
+
+COMPUTE_API void ComputeResourceNvFlowUpdateD3D11(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource);
+
+COMPUTE_API ComputeResourceRW* ComputeResourceRWNvFlowCreateD3D11(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW);
+
+COMPUTE_API void ComputeResourceRWNvFlowUpdateD3D11(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW); \ No newline at end of file
diff --git a/demo/DemoAppD3D11/imguiGraphD3D11.cpp b/demo/DemoAppD3D11/imguiGraphD3D11.cpp
index a654cf2..0cf619c 100644
--- a/demo/DemoAppD3D11/imguiGraphD3D11.cpp
+++ b/demo/DemoAppD3D11/imguiGraphD3D11.cpp
@@ -77,7 +77,7 @@ namespace
};
}
-void imguiGraphContextDestroy()
+void imguiGraphContextDestroyD3D11()
{
COMRelease(m_rasterizerState);
COMRelease(m_samplerState);
@@ -89,8 +89,10 @@ void imguiGraphContextDestroy()
COMRelease(m_vertexBuffer);
}
-void imguiGraphContextInit(const ImguiGraphDesc* desc)
+void imguiGraphContextInitD3D11(const ImguiGraphDesc* descIn)
{
+ const auto desc = cast_to_imguiGraphDescD3D11(descIn);
+
m_device = desc->device;
m_deviceContext = desc->deviceContext;
m_winW = desc->winW;
@@ -202,15 +204,17 @@ void imguiGraphContextInit(const ImguiGraphDesc* desc)
}
}
-void imguiGraphContextUpdate(const ImguiGraphDesc* desc)
+void imguiGraphContextUpdateD3D11(const ImguiGraphDesc* descIn)
{
+ const auto desc = cast_to_imguiGraphDescD3D11(descIn);
+
m_device = desc->device;
m_deviceContext = desc->deviceContext;
m_winW = desc->winW;
m_winH = desc->winH;
}
-void imguiGraphRecordBegin()
+void imguiGraphRecordBeginD3D11()
{
Params params = {
2.f / float(m_winW), 0.f, 0.f, -1.f,
@@ -318,7 +322,7 @@ static void imguiGraphFlush()
}
}
-void imguiGraphRecordEnd()
+void imguiGraphRecordEndD3D11()
{
ID3D11DeviceContext* context = m_deviceContext;
@@ -340,7 +344,7 @@ void imguiGraphRecordEnd()
context->RSSetState(nullptr);
}
-void imguiGraphEnableScissor(int x, int y, int width, int height)
+void imguiGraphEnableScissorD3D11(int x, int y, int width, int height)
{
// mark end of last region
m_stateScissor.stopIdx = m_stateVertIdx;
@@ -355,7 +359,7 @@ void imguiGraphEnableScissor(int x, int y, int width, int height)
m_stateScissor.height = height;
}
-void imguiGraphDisableScissor()
+void imguiGraphDisableScissorD3D11()
{
if (m_stateVertIdx == 0) return;
@@ -372,13 +376,13 @@ void imguiGraphDisableScissor()
m_stateScissor.height = m_winH;
}
-void imguiGraphVertex2f(float x, float y)
+void imguiGraphVertex2fD3D11(float x, float y)
{
float v[2] = { x,y };
- imguiGraphVertex2fv(v);
+ imguiGraphVertex2fvD3D11(v);
}
-void imguiGraphVertex2fv(const float* v)
+void imguiGraphVertex2fvD3D11(const float* v)
{
// update state
m_stateVert.x = v[0];
@@ -393,13 +397,13 @@ void imguiGraphVertex2fv(const float* v)
}
}
-void imguiGraphTexCoord2f(float u, float v)
+void imguiGraphTexCoord2fD3D11(float u, float v)
{
m_stateVert.u = u;
m_stateVert.v = v;
}
-void imguiGraphColor4ub(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+void imguiGraphColor4ubD3D11(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
{
m_stateVert.rgba[0] = red;
m_stateVert.rgba[1] = green;
@@ -407,7 +411,7 @@ void imguiGraphColor4ub(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
m_stateVert.rgba[3] = alpha;
}
-void imguiGraphColor4ubv(const uint8_t* v)
+void imguiGraphColor4ubvD3D11(const uint8_t* v)
{
m_stateVert.rgba[0] = v[0];
m_stateVert.rgba[1] = v[1];
@@ -415,18 +419,18 @@ void imguiGraphColor4ubv(const uint8_t* v)
m_stateVert.rgba[3] = v[3];
}
-void imguiGraphFontTextureEnable()
+void imguiGraphFontTextureEnableD3D11()
{
}
-void imguiGraphFontTextureDisable()
+void imguiGraphFontTextureDisableD3D11()
{
m_stateVert.u = -1.f;
m_stateVert.v = -1.f;
}
-void imguiGraphFontTextureInit(unsigned char* data)
+void imguiGraphFontTextureInitD3D11(unsigned char* data)
{
ID3D11DeviceContext* context = m_deviceContext;
@@ -465,7 +469,7 @@ void imguiGraphFontTextureInit(unsigned char* data)
}
-void imguiGraphFontTextureRelease()
+void imguiGraphFontTextureReleaseD3D11()
{
COMRelease(m_texture);
COMRelease(m_textureSRV);
diff --git a/demo/DemoAppD3D11/imguiGraphD3D11.h b/demo/DemoAppD3D11/imguiGraphD3D11.h
index 54e022f..cb3f864 100644
--- a/demo/DemoAppD3D11/imguiGraphD3D11.h
+++ b/demo/DemoAppD3D11/imguiGraphD3D11.h
@@ -18,7 +18,7 @@
struct ID3D11Device;
struct ID3D11DeviceContext;
-struct ImguiGraphDesc
+struct ImguiGraphDescD3D11
{
ID3D11Device* device = nullptr;
ID3D11DeviceContext* deviceContext = nullptr;
@@ -27,7 +27,49 @@ struct ImguiGraphDesc
uint32_t maxVertices = 64 * 4096u;
- ImguiGraphDesc() {}
+ ImguiGraphDescD3D11() {}
};
+inline const ImguiGraphDescD3D11* cast_to_imguiGraphDescD3D11(const ImguiGraphDesc* desc)
+{
+ return (const ImguiGraphDescD3D11*)(desc);
+}
+
+inline ImguiGraphDesc* cast_from_imguiGraphDescD3D11(ImguiGraphDescD3D11* desc)
+{
+ return (ImguiGraphDesc*)(desc);
+}
+
+IMGUI_GRAPH_API void imguiGraphContextInitD3D11(const ImguiGraphDesc* desc);
+
+IMGUI_GRAPH_API void imguiGraphContextUpdateD3D11(const ImguiGraphDesc* desc);
+
+IMGUI_GRAPH_API void imguiGraphContextDestroyD3D11();
+
+IMGUI_GRAPH_API void imguiGraphRecordBeginD3D11();
+
+IMGUI_GRAPH_API void imguiGraphRecordEndD3D11();
+
+IMGUI_GRAPH_API void imguiGraphVertex2fD3D11(float x, float y);
+
+IMGUI_GRAPH_API void imguiGraphVertex2fvD3D11(const float* v);
+
+IMGUI_GRAPH_API void imguiGraphTexCoord2fD3D11(float u, float v);
+
+IMGUI_GRAPH_API void imguiGraphColor4ubD3D11(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
+
+IMGUI_GRAPH_API void imguiGraphColor4ubvD3D11(const uint8_t* v);
+
+IMGUI_GRAPH_API void imguiGraphFontTextureEnableD3D11();
+
+IMGUI_GRAPH_API void imguiGraphFontTextureDisableD3D11();
+
+IMGUI_GRAPH_API void imguiGraphEnableScissorD3D11(int x, int y, int width, int height);
+
+IMGUI_GRAPH_API void imguiGraphDisableScissorD3D11();
+
+IMGUI_GRAPH_API void imguiGraphFontTextureInitD3D11(unsigned char* data);
+
+IMGUI_GRAPH_API void imguiGraphFontTextureReleaseD3D11();
+
#endif \ No newline at end of file
diff --git a/demo/DemoAppD3D11/imguiInteropD3D11.cpp b/demo/DemoAppD3D11/imguiInteropD3D11.cpp
index 9989aeb..ba8d740 100644
--- a/demo/DemoAppD3D11/imguiInteropD3D11.cpp
+++ b/demo/DemoAppD3D11/imguiInteropD3D11.cpp
@@ -19,24 +19,32 @@
#include "appD3D11Ctx.h"
#include "imguiGraphD3D11.h"
-bool imguiInteropGraphInit(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx)
+IMGUI_GRAPH_API bool imguiInteropGraphInitD3D11(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx);
+
+IMGUI_GRAPH_API void imguiInteropGraphUpdateD3D11(imguiGraphUpdate_t func, AppGraphCtx* appctx);
+
+bool imguiInteropGraphInitD3D11(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctxIn)
{
- ImguiGraphDesc desc;
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
+ ImguiGraphDescD3D11 desc;
desc.device = appctx->m_device;
desc.deviceContext = appctx->m_deviceContext;
desc.winW = appctx->m_winW;
desc.winH = appctx->m_winH;
- return func(fontpath, &desc);
+ return func(fontpath, cast_from_imguiGraphDescD3D11(&desc));
}
-void imguiInteropGraphUpdate(imguiGraphUpdate_t func, AppGraphCtx* appctx)
+void imguiInteropGraphUpdateD3D11(imguiGraphUpdate_t func, AppGraphCtx* appctxIn)
{
- ImguiGraphDesc desc;
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
+ ImguiGraphDescD3D11 desc;
desc.device = appctx->m_device;
desc.deviceContext = appctx->m_deviceContext;
desc.winW = appctx->m_winW;
desc.winH = appctx->m_winH;
- return func(&desc);
+ return func(cast_from_imguiGraphDescD3D11(&desc));
} \ No newline at end of file
diff --git a/demo/DemoAppD3D11/meshD3D11.cpp b/demo/DemoAppD3D11/meshD3D11.cpp
index 2b119bb..5c84cfa 100644
--- a/demo/DemoAppD3D11/meshD3D11.cpp
+++ b/demo/DemoAppD3D11/meshD3D11.cpp
@@ -31,7 +31,7 @@ namespace
}
}
-struct MeshContext
+struct MeshContextD3D11
{
ID3D11Device* m_device = nullptr;
ID3D11DeviceContext* m_deviceContext = nullptr;
@@ -42,8 +42,8 @@ struct MeshContext
ID3D11Buffer* m_constantBuffer = nullptr;
ID3D11RasterizerState* m_rasterizerStateRH = nullptr;
- MeshContext() {}
- ~MeshContext()
+ MeshContextD3D11() {}
+ ~MeshContextD3D11()
{
COMRelease(m_inputLayout);
COMRelease(m_meshVS);
@@ -53,33 +53,65 @@ struct MeshContext
}
};
-struct MeshIndexBuffer
+inline MeshContextD3D11* cast_to_MeshContextD3D11(MeshContext* ctx)
+{
+ return (MeshContextD3D11*)(ctx);
+}
+
+inline MeshContext* cast_from_MeshContextD3D11(MeshContextD3D11* ctx)
+{
+ return (MeshContext*)(ctx);
+}
+
+struct MeshIndexBufferD3D11
{
ID3D11Buffer* m_buffer = nullptr;
MeshUint m_numElements = 0u;
- MeshIndexBuffer() {}
- ~MeshIndexBuffer()
+ MeshIndexBufferD3D11() {}
+ ~MeshIndexBufferD3D11()
{
COMRelease(m_buffer);
}
};
-struct MeshVertexBuffer
+inline MeshIndexBufferD3D11* cast_to_MeshIndexBufferD3D11(MeshIndexBuffer* buf)
+{
+ return (MeshIndexBufferD3D11*)(buf);
+}
+
+inline MeshIndexBuffer* cast_from_MeshIndexBufferD3D11(MeshIndexBufferD3D11* buf)
+{
+ return (MeshIndexBuffer*)(buf);
+}
+
+struct MeshVertexBufferD3D11
{
ID3D11Buffer* m_buffer = nullptr;
MeshUint m_numElements = 0u;
- MeshVertexBuffer() {}
- ~MeshVertexBuffer()
+ MeshVertexBufferD3D11() {}
+ ~MeshVertexBufferD3D11()
{
COMRelease(m_buffer);
}
};
-MeshContext* MeshContextCreate(const MeshContextDesc* desc)
+inline MeshVertexBufferD3D11* cast_to_MeshVertexBufferD3D11(MeshVertexBuffer* buf)
{
- MeshContext* context = new MeshContext;
+ return (MeshVertexBufferD3D11*)(buf);
+}
+
+inline MeshVertexBuffer* cast_from_MeshVertexBufferD3D11(MeshVertexBufferD3D11* buf)
+{
+ return (MeshVertexBuffer*)(buf);
+}
+
+MeshContext* MeshContextCreateD3D11(const MeshContextDesc* descIn)
+{
+ auto desc = cast_to_MeshContextDescD3D11(descIn);
+
+ MeshContextD3D11* context = new MeshContextD3D11;
context->m_device = desc->device;
context->m_deviceContext = desc->context;
@@ -128,25 +160,30 @@ MeshContext* MeshContextCreate(const MeshContextDesc* desc)
context->m_device->CreateRasterizerState(&desc, &context->m_rasterizerStateRH);
}
- return context;
+ return cast_from_MeshContextD3D11(context);
}
-void MeshContextUpdate(MeshContext* context, const MeshContextDesc* desc)
+void MeshContextUpdateD3D11(MeshContext* contextIn, const MeshContextDesc* descIn)
{
+ auto context = cast_to_MeshContextD3D11(contextIn);
+ auto desc = cast_to_MeshContextDescD3D11(descIn);
+
context->m_device = desc->device;
context->m_deviceContext = desc->context;
}
-void MeshContextRelease(MeshContext* context)
+void MeshContextReleaseD3D11(MeshContext* context)
{
if (context == nullptr) return;
- delete context;
+ delete cast_to_MeshContextD3D11(context);
}
-MeshIndexBuffer* MeshIndexBufferCreate(MeshContext* context, MeshUint* indices, MeshUint numIndices)
+MeshIndexBuffer* MeshIndexBufferCreateD3D11(MeshContext* contextIn, MeshUint* indices, MeshUint numIndices)
{
- MeshIndexBuffer* buffer = new MeshIndexBuffer;
+ auto context = cast_to_MeshContextD3D11(contextIn);
+
+ MeshIndexBufferD3D11* buffer = new MeshIndexBufferD3D11;
buffer->m_numElements = numIndices;
// create an index buffer
@@ -166,19 +203,21 @@ MeshIndexBuffer* MeshIndexBufferCreate(MeshContext* context, MeshUint* indices,
context->m_device->CreateBuffer(&bufDesc, &data, &buffer->m_buffer);
}
- return buffer;
+ return cast_from_MeshIndexBufferD3D11(buffer);
}
-void MeshIndexBufferRelease(MeshIndexBuffer* buffer)
+void MeshIndexBufferReleaseD3D11(MeshIndexBuffer* buffer)
{
if (buffer == nullptr) return;
- delete buffer;
+ delete cast_to_MeshIndexBufferD3D11(buffer);
}
-MeshVertexBuffer* MeshVertexBufferCreate(MeshContext* context, MeshVertex* vertices, MeshUint numVertices)
+MeshVertexBuffer* MeshVertexBufferCreateD3D11(MeshContext* contextIn, MeshVertex* vertices, MeshUint numVertices)
{
- MeshVertexBuffer* buffer = new MeshVertexBuffer;
+ auto context = cast_to_MeshContextD3D11(contextIn);
+
+ MeshVertexBufferD3D11* buffer = new MeshVertexBufferD3D11;
buffer->m_numElements = numVertices;
// create a vertex buffer
@@ -198,18 +237,20 @@ MeshVertexBuffer* MeshVertexBufferCreate(MeshContext* context, MeshVertex* verti
context->m_device->CreateBuffer(&bufDesc, &data, &buffer->m_buffer);
}
- return buffer;
+ return cast_from_MeshVertexBufferD3D11(buffer);
}
-void MeshVertexBufferRelease(MeshVertexBuffer* buffer)
+void MeshVertexBufferReleaseD3D11(MeshVertexBuffer* buffer)
{
if (buffer == nullptr) return;
- delete buffer;
+ delete cast_to_MeshVertexBufferD3D11(buffer);
}
-void MeshContextDraw(MeshContext* context, const MeshContextDrawParams* params)
+void MeshContextDrawD3D11(MeshContext* contextIn, const MeshContextDrawParams* params)
{
+ auto context = cast_to_MeshContextD3D11(contextIn);
+
using namespace DirectX;
XMMATRIX matrix = XMMatrixTranspose(XMMatrixMultiply(XMMatrixMultiply(
@@ -242,8 +283,8 @@ void MeshContextDraw(MeshContext* context, const MeshContextDrawParams* params)
UINT vertexStride = sizeof(MeshVertex);
UINT offset = 0u;
- deviceContext->IASetVertexBuffers(0, 1, &params->vertexBuffer->m_buffer, &vertexStride, &offset);
- deviceContext->IASetIndexBuffer(params->indexBuffer->m_buffer, DXGI_FORMAT_R32_UINT, 0u);
+ deviceContext->IASetVertexBuffers(0, 1, &cast_to_MeshVertexBufferD3D11(params->vertexBuffer)->m_buffer, &vertexStride, &offset);
+ deviceContext->IASetIndexBuffer(cast_to_MeshIndexBufferD3D11(params->indexBuffer)->m_buffer, DXGI_FORMAT_R32_UINT, 0u);
float depthSign = DirectX::XMVectorGetW(params->params->projection.r[2]);
if (depthSign < 0.f)
@@ -251,7 +292,7 @@ void MeshContextDraw(MeshContext* context, const MeshContextDrawParams* params)
deviceContext->RSSetState(context->m_rasterizerStateRH);
}
- deviceContext->DrawIndexed((UINT)params->indexBuffer->m_numElements, 0, 0);
+ deviceContext->DrawIndexed((UINT)cast_to_MeshIndexBufferD3D11(params->indexBuffer)->m_numElements, 0, 0);
if (depthSign < 0.f)
{
diff --git a/demo/DemoAppD3D11/meshD3D11.h b/demo/DemoAppD3D11/meshD3D11.h
index 86efe6b..c756d76 100644
--- a/demo/DemoAppD3D11/meshD3D11.h
+++ b/demo/DemoAppD3D11/meshD3D11.h
@@ -12,8 +12,35 @@
#include "../DemoApp/mesh.h"
-struct MeshContextDesc
+struct MeshContextDescD3D11
{
ID3D11Device* device;
ID3D11DeviceContext* context;
-}; \ No newline at end of file
+};
+
+inline const MeshContextDescD3D11* cast_to_MeshContextDescD3D11(const MeshContextDesc* desc)
+{
+ return (const MeshContextDescD3D11*)(desc);
+}
+
+inline MeshContextDesc* cast_from_MeshContextDescD3D11(MeshContextDescD3D11* desc)
+{
+ return (MeshContextDesc*)(desc);
+}
+
+MESH_API MeshContext* MeshContextCreateD3D11(const MeshContextDesc* desc);
+
+MESH_API void MeshContextUpdateD3D11(MeshContext* context, const MeshContextDesc* desc);
+
+MESH_API void MeshContextReleaseD3D11(MeshContext* context);
+
+
+MESH_API MeshIndexBuffer* MeshIndexBufferCreateD3D11(MeshContext* context, MeshUint* indices, MeshUint numIndices);
+
+MESH_API void MeshIndexBufferReleaseD3D11(MeshIndexBuffer* buffer);
+
+MESH_API MeshVertexBuffer* MeshVertexBufferCreateD3D11(MeshContext* context, MeshVertex* vertices, MeshUint numVertices);
+
+MESH_API void MeshVertexBufferReleaseD3D11(MeshVertexBuffer* buffer);
+
+MESH_API void MeshContextDrawD3D11(MeshContext* context, const MeshContextDrawParams* params); \ No newline at end of file
diff --git a/demo/DemoAppD3D11/meshInteropD3D11.cpp b/demo/DemoAppD3D11/meshInteropD3D11.cpp
index 5ab9a90..40d2473 100644
--- a/demo/DemoAppD3D11/meshInteropD3D11.cpp
+++ b/demo/DemoAppD3D11/meshInteropD3D11.cpp
@@ -19,20 +19,28 @@
#include "appD3D11Ctx.h"
#include "meshD3D11.h"
-MeshContext* MeshInteropContextCreate(AppGraphCtx* appctx)
+MESH_API MeshContext* MeshInteropContextCreateD3D11(AppGraphCtx* appctx);
+
+MESH_API void MeshInteropContextUpdateD3D11(MeshContext* context, AppGraphCtx* appctx);
+
+MeshContext* MeshInteropContextCreateD3D11(AppGraphCtx* appctxIn)
{
- MeshContextDesc desc = {};
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
+ MeshContextDescD3D11 desc = {};
desc.device = appctx->m_device;
desc.context = appctx->m_deviceContext;
- return MeshContextCreate(&desc);
+ return MeshContextCreateD3D11(cast_from_MeshContextDescD3D11(&desc));
}
-void MeshInteropContextUpdate(MeshContext* context, AppGraphCtx* appctx)
+void MeshInteropContextUpdateD3D11(MeshContext* context, AppGraphCtx* appctxIn)
{
- MeshContextDesc desc = {};
+ auto appctx = cast_to_AppGraphCtxD3D11(appctxIn);
+
+ MeshContextDescD3D11 desc = {};
desc.device = appctx->m_device;
desc.context = appctx->m_deviceContext;
- return MeshContextUpdate(context, &desc);
+ return MeshContextUpdateD3D11(context, cast_from_MeshContextDescD3D11(&desc));
} \ No newline at end of file
diff --git a/demo/DemoAppD3D12/NvFlowInteropD3D12.cpp b/demo/DemoAppD3D12/NvFlowInteropD3D12.cpp
index ce79bcc..ecb13d8 100644
--- a/demo/DemoAppD3D12/NvFlowInteropD3D12.cpp
+++ b/demo/DemoAppD3D12/NvFlowInteropD3D12.cpp
@@ -15,9 +15,21 @@
#include "NvFlowContextD3D12.h"
#include "appD3D12Ctx.h"
+NV_FLOW_API NvFlowContext* NvFlowInteropCreateContextD3D12(AppGraphCtx* appctx);
+
+NV_FLOW_API NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilViewD3D12(AppGraphCtx* appctx, NvFlowContext* flowctx);
+
+NV_FLOW_API NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetViewD3D12(AppGraphCtx* appctx, NvFlowContext* flowctx);
+
+NV_FLOW_API void NvFlowInteropUpdateContextD3D12(NvFlowContext* context, AppGraphCtx* appctx);
+
+NV_FLOW_API void NvFlowInteropUpdateDepthStencilViewD3D12(NvFlowDepthStencilView* view, AppGraphCtx* appctx, NvFlowContext* flowctx);
+
+NV_FLOW_API void NvFlowInteropUpdateRenderTargetViewD3D12(NvFlowRenderTargetView* view, AppGraphCtx* appctx, NvFlowContext* flowctx);
+
NvFlowDescriptorReserveHandleD3D12 NvFlowInteropReserveDescriptors(void* userdata, NvFlowUint numDescriptors, NvFlowUint64 lastFenceCompleted, NvFlowUint64 nextFenceValue)
{
- auto appctx = static_cast<AppGraphCtx*>(userdata);
+ auto appctx = cast_to_AppGraphCtxD3D12((AppGraphCtx*)userdata);
auto srcHandle = appctx->m_dynamicHeapCbvSrvUav.reserveDescriptors(numDescriptors, lastFenceCompleted, nextFenceValue);
NvFlowDescriptorReserveHandleD3D12 handle = {};
handle.heap = srcHandle.heap;
@@ -27,8 +39,10 @@ NvFlowDescriptorReserveHandleD3D12 NvFlowInteropReserveDescriptors(void* userdat
return handle;
}
-void NvFlowInteropUpdateContextDesc(NvFlowContextDescD3D12* desc, AppGraphCtx* appctx)
+void NvFlowInteropUpdateContextDesc(NvFlowContextDescD3D12* desc, AppGraphCtx* appctxIn)
{
+ auto appctx = cast_to_AppGraphCtxD3D12(appctxIn);
+
desc->device = appctx->m_device;
desc->commandQueue = appctx->m_commandQueue;
desc->commandQueueFence = appctx->m_fence;
@@ -40,28 +54,36 @@ void NvFlowInteropUpdateContextDesc(NvFlowContextDescD3D12* desc, AppGraphCtx* a
desc->dynamicHeapCbvSrvUav.reserveDescriptors = NvFlowInteropReserveDescriptors;
}
-NvFlowContext* NvFlowInteropCreateContext(AppGraphCtx* appctx)
+NvFlowContext* NvFlowInteropCreateContextD3D12(AppGraphCtx* appctx)
{
NvFlowContextDescD3D12 desc = {};
NvFlowInteropUpdateContextDesc(&desc, appctx);
return NvFlowCreateContextD3D12(NV_FLOW_VERSION, &desc);
}
-NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilView(AppGraphCtx* appctx, NvFlowContext* flowctx)
+NvFlowDepthStencilView* NvFlowInteropCreateDepthStencilViewD3D12(AppGraphCtx* appctxIn, NvFlowContext* flowctx)
{
+ auto appctx = cast_to_AppGraphCtxD3D12(appctxIn);
+
NvFlowDepthStencilViewDescD3D12 desc = {};
desc.dsvHandle = appctx->m_current_dsvHandle;
desc.dsvDesc = appctx->m_current_dsvDesc;
+ desc.dsvResource = appctx->m_depthStencil;
+ desc.dsvCurrentState = D3D12_RESOURCE_STATE_DEPTH_WRITE;
+
desc.srvHandle = appctx->m_current_depth_srvHandle;
desc.srvDesc = appctx->m_current_depth_srvDesc;
- desc.resource = appctx->m_depthStencil;
- desc.currentState = D3D12_RESOURCE_STATE_DEPTH_WRITE;
+ desc.srvResource = appctx->m_depthStencil;
+ desc.srvCurrentState = D3D12_RESOURCE_STATE_DEPTH_WRITE;
+
desc.viewport = appctx->m_viewport;
return NvFlowCreateDepthStencilViewD3D12(flowctx, &desc);
}
-NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetView(AppGraphCtx* appctx, NvFlowContext* flowctx)
+NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetViewD3D12(AppGraphCtx* appctxIn, NvFlowContext* flowctx)
{
+ auto appctx = cast_to_AppGraphCtxD3D12(appctxIn);
+
NvFlowRenderTargetViewDescD3D12 desc = {};
desc.rtvHandle = appctx->m_current_rtvHandle;
desc.rtvDesc = appctx->m_current_rtvDesc;
@@ -72,28 +94,36 @@ NvFlowRenderTargetView* NvFlowInteropCreateRenderTargetView(AppGraphCtx* appctx,
return NvFlowCreateRenderTargetViewD3D12(flowctx, &desc);
}
-void NvFlowInteropUpdateContext(NvFlowContext* context, AppGraphCtx* appctx)
+void NvFlowInteropUpdateContextD3D12(NvFlowContext* context, AppGraphCtx* appctx)
{
NvFlowContextDescD3D12 desc = {};
NvFlowInteropUpdateContextDesc(&desc, appctx);
NvFlowUpdateContextD3D12(context, &desc);
}
-void NvFlowInteropUpdateDepthStencilView(NvFlowDepthStencilView* view, AppGraphCtx* appctx, NvFlowContext* flowctx)
+void NvFlowInteropUpdateDepthStencilViewD3D12(NvFlowDepthStencilView* view, AppGraphCtx* appctxIn, NvFlowContext* flowctx)
{
+ auto appctx = cast_to_AppGraphCtxD3D12(appctxIn);
+
NvFlowDepthStencilViewDescD3D12 desc = {};
desc.dsvHandle = appctx->m_current_dsvHandle;
desc.dsvDesc = appctx->m_current_dsvDesc;
+ desc.dsvResource = appctx->m_depthStencil;
+ desc.dsvCurrentState = D3D12_RESOURCE_STATE_DEPTH_WRITE;
+
desc.srvHandle = appctx->m_current_depth_srvHandle;
desc.srvDesc = appctx->m_current_depth_srvDesc;
- desc.resource = appctx->m_depthStencil;
- desc.currentState = D3D12_RESOURCE_STATE_DEPTH_WRITE;
+ desc.srvResource = appctx->m_depthStencil;
+ desc.srvCurrentState = D3D12_RESOURCE_STATE_DEPTH_WRITE;
+
desc.viewport = appctx->m_viewport;
NvFlowUpdateDepthStencilViewD3D12(flowctx, view, &desc);
}
-void NvFlowInteropUpdateRenderTargetView(NvFlowRenderTargetView* view, AppGraphCtx* appctx, NvFlowContext* flowctx)
+void NvFlowInteropUpdateRenderTargetViewD3D12(NvFlowRenderTargetView* view, AppGraphCtx* appctxIn, NvFlowContext* flowctx)
{
+ auto appctx = cast_to_AppGraphCtxD3D12(appctxIn);
+
NvFlowRenderTargetViewDescD3D12 desc = {};
desc.rtvHandle = appctx->m_current_rtvHandle;
desc.rtvDesc = appctx->m_current_rtvDesc;
diff --git a/demo/DemoAppD3D12/appD3D12Ctx.cpp b/demo/DemoAppD3D12/appD3D12Ctx.cpp
index 8d1d7ff..1779ba1 100644
--- a/demo/DemoAppD3D12/appD3D12Ctx.cpp
+++ b/demo/DemoAppD3D12/appD3D12Ctx.cpp
@@ -45,25 +45,23 @@ namespace
}
}
-AppGraphProfiler* appGraphCreateProfiler(AppGraphCtx* ctx);
-void appGraphProfilerFrameBegin(AppGraphProfiler* profiler);
-void appGraphProfilerFrameEnd(AppGraphProfiler* profiler);
-void appGraphProfilerEnable(AppGraphProfiler* profiler, bool enabled);
-void appGraphProfilerBegin(AppGraphProfiler* profiler, const char* label);
-void appGraphProfilerEnd(AppGraphProfiler* profiler, const char* label);
-bool appGraphProfilerGet(AppGraphProfiler* profiler, const char** plabel, float* cpuTime, float* gpuTime, int index);
-void appGraphReleaseProfiler(AppGraphProfiler* profiler);
-
-void AppGraphCtxInitRenderTarget(AppGraphCtx* context, SDL_Window* window, bool fullscreen);
-
-AppGraphCtx::AppGraphCtx()
+AppGraphProfilerD3D12* appGraphCreateProfilerD3D12(AppGraphCtx* ctx);
+void appGraphProfilerD3D12FrameBegin(AppGraphProfilerD3D12* profiler);
+void appGraphProfilerD3D12FrameEnd(AppGraphProfilerD3D12* profiler);
+void appGraphProfilerD3D12Enable(AppGraphProfilerD3D12* profiler, bool enabled);
+void appGraphProfilerD3D12Begin(AppGraphProfilerD3D12* profiler, const char* label);
+void appGraphProfilerD3D12End(AppGraphProfilerD3D12* profiler, const char* label);
+bool appGraphProfilerD3D12Get(AppGraphProfilerD3D12* profiler, const char** plabel, float* cpuTime, float* gpuTime, int index);
+void appGraphReleaseProfiler(AppGraphProfilerD3D12* profiler);
+
+AppGraphCtxD3D12::AppGraphCtxD3D12()
{
- m_profiler = appGraphCreateProfiler(this);
+ m_profiler = appGraphCreateProfilerD3D12(cast_from_AppGraphCtxD3D12(this));
}
-AppGraphCtx::~AppGraphCtx()
+AppGraphCtxD3D12::~AppGraphCtxD3D12()
{
- AppGraphCtxReleaseRenderTarget(this);
+ AppGraphCtxReleaseRenderTargetD3D12(cast_from_AppGraphCtxD3D12(this));
COMRelease(m_device);
COMRelease(m_commandQueue);
@@ -83,9 +81,9 @@ AppGraphCtx::~AppGraphCtx()
m_profiler = nullptr;
}
-AppGraphCtx* AppGraphCtxCreate(int deviceID)
+AppGraphCtx* AppGraphCtxCreateD3D12(int deviceID)
{
- AppGraphCtx* context = new AppGraphCtx;
+ AppGraphCtxD3D12* context = new AppGraphCtxD3D12;
HRESULT hr = S_OK;
@@ -247,11 +245,15 @@ AppGraphCtx* AppGraphCtxCreate(int deviceID)
}
}
- return context;
+ return cast_from_AppGraphCtxD3D12(context);
}
-bool AppGraphCtxUpdateSize(AppGraphCtx* context, SDL_Window* window, bool fullscreen)
+void AppGraphCtxInitRenderTargetD3D12(AppGraphCtx* context, SDL_Window* window, bool fullscreen);
+
+bool AppGraphCtxUpdateSizeD3D12(AppGraphCtx* contextIn, SDL_Window* window, bool fullscreen)
{
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+
// TODO: fix iflip fullscreen support
fullscreen = false;
@@ -291,18 +293,20 @@ bool AppGraphCtxUpdateSize(AppGraphCtx* context, SDL_Window* window, bool fullsc
if (sizeChanged)
{
- AppGraphCtxReleaseRenderTarget(context);
+ AppGraphCtxReleaseRenderTargetD3D12(cast_from_AppGraphCtxD3D12(context));
}
if (sizeChanged && context->m_valid)
{
- AppGraphCtxInitRenderTarget(context, window, fullscreen);
+ AppGraphCtxInitRenderTargetD3D12(cast_from_AppGraphCtxD3D12(context), window, fullscreen);
}
return context->m_valid;
}
-void AppGraphCtxInitRenderTarget(AppGraphCtx* context, SDL_Window* window, bool fullscreen)
+void AppGraphCtxInitRenderTargetD3D12(AppGraphCtx* contextIn, SDL_Window* window, bool fullscreen)
{
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+
HWND hWnd = nullptr;
// get Windows handle to this SDL window
SDL_SysWMinfo winInfo;
@@ -473,8 +477,10 @@ void AppGraphCtxInitRenderTarget(AppGraphCtx* context, SDL_Window* window, bool
}
}
-void AppGraphCtxReleaseRenderTarget(AppGraphCtx* context)
+void AppGraphCtxReleaseRenderTargetD3D12(AppGraphCtx* contextIn)
{
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+
if (context->m_swapChain == nullptr)
{
return;
@@ -505,15 +511,17 @@ void AppGraphCtxReleaseRenderTarget(AppGraphCtx* context)
context->m_winH = 0u;
}
-void AppGraphCtxRelease(AppGraphCtx* context)
+void AppGraphCtxReleaseD3D12(AppGraphCtx* context)
{
if (context == nullptr) return;
- delete context;
+ delete cast_to_AppGraphCtxD3D12(context);
}
-void AppGraphCtxFrameStart(AppGraphCtx* context, float clearColor[4])
+void AppGraphCtxFrameStartD3D12(AppGraphCtx* contextIn, AppGraphColor clearColor)
{
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+
// Get back render target index
context->m_renderTargetIndex = context->m_swapChain->GetCurrentBackBufferIndex();
@@ -535,7 +543,7 @@ void AppGraphCtxFrameStart(AppGraphCtx* context, float clearColor[4])
// reset command list with this frame's allocator
context->m_commandList->Reset(context->m_commandAllocators[context->m_frameIndex], nullptr);
- appGraphProfilerFrameBegin(context->m_profiler);
+ appGraphProfilerD3D12FrameBegin(context->m_profiler);
context->m_commandList->RSSetViewports(1, &context->m_viewport);
context->m_commandList->RSSetScissorRects(1, &context->m_scissorRect);
@@ -555,7 +563,7 @@ void AppGraphCtxFrameStart(AppGraphCtx* context, float clearColor[4])
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = context->m_dsvHeap->GetCPUDescriptorHandleForHeapStart();
context->m_commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, &dsvHandle);
- context->m_commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr);
+ context->m_commandList->ClearRenderTargetView(rtvHandle, &clearColor.r, 0, nullptr);
context->m_commandList->ClearDepthStencilView(dsvHandle, D3D12_CLEAR_FLAG_DEPTH, 1.f, 0, 0, nullptr);
/// to simplify interop implementation
@@ -565,8 +573,10 @@ void AppGraphCtxFrameStart(AppGraphCtx* context, float clearColor[4])
context->m_current_depth_srvHandle = context->m_depthSrvHeap->GetCPUDescriptorHandleForHeapStart();
}
-void AppGraphCtxFramePresent(AppGraphCtx* context, bool fullsync)
+void AppGraphCtxFramePresentD3D12(AppGraphCtx* contextIn, bool fullsync)
{
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
@@ -590,7 +600,7 @@ void AppGraphCtxFramePresent(AppGraphCtx* context, bool fullsync)
context->m_renderTargetID++;
}
- appGraphProfilerFrameEnd(context->m_profiler);
+ appGraphProfilerD3D12FrameEnd(context->m_profiler);
// signal for this frame id
context->m_frameID++;
@@ -615,8 +625,10 @@ void AppGraphCtxFramePresent(AppGraphCtx* context, bool fullsync)
}
}
-void AppGraphCtxWaitForFrames(AppGraphCtx* context, unsigned int maxFramesInFlight)
+void AppGraphCtxWaitForFramesD3D12(AppGraphCtx* contextIn, unsigned int maxFramesInFlight)
{
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+
unsigned int framesActive = maxFramesInFlight;
while (framesActive >= maxFramesInFlight)
{
@@ -668,24 +680,28 @@ void AppGraphCtxWaitForFrames(AppGraphCtx* context, unsigned int maxFramesInFlig
}
}
-void AppGraphCtxProfileEnable(AppGraphCtx* context, bool enabled)
+void AppGraphCtxProfileEnableD3D12(AppGraphCtx* contextIn, bool enabled)
{
- appGraphProfilerEnable(context->m_profiler, enabled);
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+ appGraphProfilerD3D12Enable(context->m_profiler, enabled);
}
-void AppGraphCtxProfileBegin(AppGraphCtx* context, const char* label)
+void AppGraphCtxProfileBeginD3D12(AppGraphCtx* contextIn, const char* label)
{
- appGraphProfilerBegin(context->m_profiler, label);
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+ appGraphProfilerD3D12Begin(context->m_profiler, label);
}
-void AppGraphCtxProfileEnd(AppGraphCtx* context, const char* label)
+void AppGraphCtxProfileEndD3D12(AppGraphCtx* contextIn, const char* label)
{
- appGraphProfilerEnd(context->m_profiler, label);
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+ appGraphProfilerD3D12End(context->m_profiler, label);
}
-bool AppGraphCtxProfileGet(AppGraphCtx* context, const char** plabel, float* cpuTime, float* gpuTime, int index)
+bool AppGraphCtxProfileGetD3D12(AppGraphCtx* contextIn, const char** plabel, float* cpuTime, float* gpuTime, int index)
{
- return appGraphProfilerGet(context->m_profiler, plabel, cpuTime, gpuTime, index);
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
+ return appGraphProfilerD3D12Get(context->m_profiler, plabel, cpuTime, gpuTime, index);
}
// ******************************* Dynamic descriptor heap ******************************
@@ -889,9 +905,9 @@ namespace
};
}
-struct AppGraphProfiler
+struct AppGraphProfilerD3D12
{
- AppGraphCtx* m_context;
+ AppGraphCtxD3D12* m_context;
int m_state = 0;
bool m_enabled = false;
@@ -906,29 +922,29 @@ struct AppGraphProfiler
TimerValue m_timerValues[m_timersCap];
int m_timerValuesSize = 0;
- AppGraphProfiler(AppGraphCtx* context);
- ~AppGraphProfiler();
+ AppGraphProfilerD3D12(AppGraphCtx* context);
+ ~AppGraphProfilerD3D12();
};
-AppGraphProfiler::AppGraphProfiler(AppGraphCtx* context) : m_context(context)
+AppGraphProfilerD3D12::AppGraphProfilerD3D12(AppGraphCtx* context) : m_context(cast_to_AppGraphCtxD3D12(context))
{
}
-AppGraphProfiler::~AppGraphProfiler()
+AppGraphProfilerD3D12::~AppGraphProfilerD3D12()
{
}
-AppGraphProfiler* appGraphCreateProfiler(AppGraphCtx* ctx)
+AppGraphProfilerD3D12* appGraphCreateProfilerD3D12(AppGraphCtx* ctx)
{
- return new AppGraphProfiler(ctx);
+ return new AppGraphProfilerD3D12(ctx);
}
-void appGraphReleaseProfiler(AppGraphProfiler* profiler)
+void appGraphReleaseProfiler(AppGraphProfilerD3D12* profiler)
{
delete profiler;
}
-void appGraphProfilerFrameBegin(AppGraphProfiler* p)
+void appGraphProfilerD3D12FrameBegin(AppGraphProfilerD3D12* p)
{
p->m_frameTime = (float)p->m_frameTimer.getDeltaTime();
@@ -940,7 +956,7 @@ void appGraphProfilerFrameBegin(AppGraphProfiler* p)
}
}
-void appGraphProfilerFrameEnd(AppGraphProfiler* p)
+void appGraphProfilerD3D12FrameEnd(AppGraphProfilerD3D12* p)
{
if (p->m_state == 1)
{
@@ -948,12 +964,12 @@ void appGraphProfilerFrameEnd(AppGraphProfiler* p)
}
}
-void appGraphProfilerEnable(AppGraphProfiler* p, bool enabled)
+void appGraphProfilerD3D12Enable(AppGraphProfilerD3D12* p, bool enabled)
{
p->m_enabled = enabled;
}
-void appGraphProfilerBegin(AppGraphProfiler* p, const char* label)
+void appGraphProfilerD3D12Begin(AppGraphProfilerD3D12* p, const char* label)
{
if (p->m_state == 1 && p->m_timersSize < p->m_timersCap)
{
@@ -987,7 +1003,7 @@ void appGraphProfilerBegin(AppGraphProfiler* p, const char* label)
}
}
-void appGraphProfilerEnd(AppGraphProfiler* p, const char* label)
+void appGraphProfilerD3D12End(AppGraphProfilerD3D12* p, const char* label)
{
if (p->m_state == 1)
{
@@ -1013,7 +1029,7 @@ void appGraphProfilerEnd(AppGraphProfiler* p, const char* label)
}
}
-bool appGraphProfilerFlush(AppGraphProfiler* p)
+bool appGraphProfilerD3D12Flush(AppGraphProfilerD3D12* p)
{
if (p->m_state == 2)
{
@@ -1071,9 +1087,9 @@ bool appGraphProfilerFlush(AppGraphProfiler* p)
return false;
}
-bool appGraphProfilerGet(AppGraphProfiler* p, const char** plabel, float* cpuTime, float* gpuTime, int index)
+bool appGraphProfilerD3D12Get(AppGraphProfilerD3D12* p, const char** plabel, float* cpuTime, float* gpuTime, int index)
{
- appGraphProfilerFlush(p);
+ appGraphProfilerD3D12Flush(p);
{
if (index < p->m_timerValuesSize)
{
@@ -1091,7 +1107,8 @@ bool appGraphProfilerGet(AppGraphProfiler* p, const char** plabel, float* cpuTim
return false;
}
-size_t AppGraphCtxDedicatedVideoMemory(AppGraphCtx* context)
+size_t AppGraphCtxDedicatedVideoMemoryD3D12(AppGraphCtx* contextIn)
{
+ auto context = cast_to_AppGraphCtxD3D12(contextIn);
return context->m_dedicatedVideoMemory;
} \ No newline at end of file
diff --git a/demo/DemoAppD3D12/appD3D12Ctx.h b/demo/DemoAppD3D12/appD3D12Ctx.h
index f6d2ba3..a20e44a 100644
--- a/demo/DemoAppD3D12/appD3D12Ctx.h
+++ b/demo/DemoAppD3D12/appD3D12Ctx.h
@@ -15,7 +15,7 @@
struct IDXGISwapChain3;
-struct AppGraphProfiler;
+struct AppGraphProfilerD3D12;
struct AppDescriptorReserveHandleD3D12
{
@@ -41,7 +41,7 @@ struct AppDynamicDescriptorHeapD3D12
~AppDynamicDescriptorHeapD3D12() { release(); }
};
-struct AppGraphCtx
+struct AppGraphCtxD3D12
{
HWND m_hWnd = nullptr;
@@ -104,10 +104,44 @@ struct AppGraphCtx
AppDynamicDescriptorHeapD3D12 m_dynamicHeapCbvSrvUav;
- AppGraphProfiler* m_profiler = nullptr;
+ AppGraphProfilerD3D12* m_profiler = nullptr;
- AppGraphCtx();
- ~AppGraphCtx();
+ AppGraphCtxD3D12();
+ ~AppGraphCtxD3D12();
};
+inline AppGraphCtxD3D12* cast_to_AppGraphCtxD3D12(AppGraphCtx* appctx)
+{
+ return (AppGraphCtxD3D12*)(appctx);
+}
+
+inline AppGraphCtx* cast_from_AppGraphCtxD3D12(AppGraphCtxD3D12* appctx)
+{
+ return (AppGraphCtx*)(appctx);
+}
+
+APP_GRAPH_CTX_API AppGraphCtx* AppGraphCtxCreateD3D12(int deviceID);
+
+APP_GRAPH_CTX_API bool AppGraphCtxUpdateSizeD3D12(AppGraphCtx* context, SDL_Window* window, bool fullscreen);
+
+APP_GRAPH_CTX_API void AppGraphCtxReleaseRenderTargetD3D12(AppGraphCtx* context);
+
+APP_GRAPH_CTX_API void AppGraphCtxReleaseD3D12(AppGraphCtx* context);
+
+APP_GRAPH_CTX_API void AppGraphCtxFrameStartD3D12(AppGraphCtx* context, AppGraphColor clearColor);
+
+APP_GRAPH_CTX_API void AppGraphCtxFramePresentD3D12(AppGraphCtx* context, bool fullsync);
+
+APP_GRAPH_CTX_API void AppGraphCtxWaitForFramesD3D12(AppGraphCtx* context, unsigned int maxFramesInFlight);
+
+APP_GRAPH_CTX_API void AppGraphCtxProfileEnableD3D12(AppGraphCtx* context, bool enabled);
+
+APP_GRAPH_CTX_API void AppGraphCtxProfileBeginD3D12(AppGraphCtx* context, const char* label);
+
+APP_GRAPH_CTX_API void AppGraphCtxProfileEndD3D12(AppGraphCtx* context, const char* label);
+
+APP_GRAPH_CTX_API bool AppGraphCtxProfileGetD3D12(AppGraphCtx* context, const char** plabel, float* cpuTime, float* gpuTime, int index);
+
+APP_GRAPH_CTX_API size_t AppGraphCtxDedicatedVideoMemoryD3D12(AppGraphCtx* context);
+
#endif \ No newline at end of file
diff --git a/demo/DemoAppD3D12/computeContextD3D12.cpp b/demo/DemoAppD3D12/computeContextD3D12.cpp
index f6cf26e..9e54325 100644
--- a/demo/DemoAppD3D12/computeContextD3D12.cpp
+++ b/demo/DemoAppD3D12/computeContextD3D12.cpp
@@ -250,9 +250,9 @@ struct ComputeContextUserData
virtual void Release() = 0;
};
-struct ComputeContext
+struct ComputeContextD3D12
{
- ComputeContextDesc m_desc = {};
+ ComputeContextDescD3D12 m_desc = {};
ID3D12RootSignature* m_rootSignatureCompute = nullptr;
ID3D12DescriptorHeap* m_nullHeap = nullptr;
@@ -261,8 +261,10 @@ struct ComputeContext
ComputeContextUserData* m_computeUserdata = nullptr;
- ComputeContext(const ComputeContextDesc* desc)
+ ComputeContextD3D12(const ComputeContextDesc* descIn)
{
+ auto desc = cast_to_ComputeContextDescD3D12(descIn);
+
m_desc = *desc;
auto createRootSignature = [&](D3D12_ROOT_SIGNATURE_DESC* desc, ID3D12RootSignature** root)
@@ -323,7 +325,7 @@ struct ComputeContext
m_desc.device->CreateShaderResourceView(nullptr, &srvDesc, m_nullSRV);
}
}
- ~ComputeContext()
+ ~ComputeContextD3D12()
{
COMRelease(m_rootSignatureCompute);
COMRelease(m_nullHeap);
@@ -331,20 +333,40 @@ struct ComputeContext
}
};
-struct ComputeShader
+inline ComputeContextD3D12* cast_to_ComputeContextD3D12(ComputeContext* ctx)
+{
+ return (ComputeContextD3D12*)(ctx);
+}
+
+inline ComputeContext* cast_from_ComputeContextD3D12(ComputeContextD3D12* ctx)
+{
+ return (ComputeContext*)(ctx);
+}
+
+struct ComputeShaderD3D12
{
ID3D12PipelineState* m_shader = nullptr;
- ComputeShader(ID3D12PipelineState* shader)
+ ComputeShaderD3D12(ID3D12PipelineState* shader)
{
m_shader = shader;
}
- ~ComputeShader()
+ ~ComputeShaderD3D12()
{
COMRelease(m_shader);
}
};
-struct ComputeConstantBuffer
+inline ComputeShaderD3D12* cast_to_ComputeShaderD3D12(ComputeShader* ctx)
+{
+ return (ComputeShaderD3D12*)(ctx);
+}
+
+inline ComputeShader* cast_from_ComputeShaderD3D12(ComputeShaderD3D12* ctx)
+{
+ return (ComputeShader*)(ctx);
+}
+
+struct ComputeConstantBufferD3D12
{
ComputeConstantBufferDesc m_desc = {};
@@ -357,38 +379,54 @@ struct ComputeConstantBuffer
};
VersionedBuffer<BufferData> m_buffers;
- ComputeConstantBuffer(ComputeContext* context, const ComputeConstantBufferDesc* desc)
- {
- m_desc = *desc;
+ ComputeConstantBufferD3D12(ComputeContext* context, const ComputeConstantBufferDesc* desc);
+ ~ComputeConstantBufferD3D12();
+};
- // map and unmap to trigger initial allocation
- ComputeConstantBufferMap(context, this);
- ComputeConstantBufferUnmap(context, this);
- }
- ~ComputeConstantBuffer()
+inline ComputeConstantBufferD3D12* cast_to_ComputeConstantBufferD3D12(ComputeConstantBuffer* ctx)
+{
+ return (ComputeConstantBufferD3D12*)(ctx);
+}
+
+inline ComputeConstantBuffer* cast_from_ComputeConstantBufferD3D12(ComputeConstantBufferD3D12* ctx)
+{
+ return (ComputeConstantBuffer*)(ctx);
+}
+
+ComputeConstantBufferD3D12::ComputeConstantBufferD3D12(ComputeContext* context, const ComputeConstantBufferDesc* desc)
+{
+ m_desc = *desc;
+
+ // map and unmap to trigger initial allocation
+ ComputeConstantBufferMapD3D12(context, cast_from_ComputeConstantBufferD3D12(this));
+ ComputeConstantBufferUnmapD3D12(context, cast_from_ComputeConstantBufferD3D12(this));
+}
+
+ComputeConstantBufferD3D12::~ComputeConstantBufferD3D12()
+{
+ for (ComputeUint i = 0; i < m_buffers.m_buffers.m_size; i++)
{
- for (ComputeUint i = 0; i < m_buffers.m_buffers.m_size; i++)
- {
- COMRelease(m_buffers.m_buffers[i].bufferData.m_buffer);
- }
+ COMRelease(m_buffers.m_buffers[i].bufferData.m_buffer);
}
-};
+}
-struct ComputeResource
+struct ComputeResourceD3D12
{
protected:
D3D12_CPU_DESCRIPTOR_HANDLE m_srv;
ID3D12Resource* m_resource;
D3D12_RESOURCE_STATES* m_currentState;
public:
- void update(const ComputeResourceDesc* desc)
+ void update(const ComputeResourceDesc* descIn)
{
+ auto desc = cast_to_ComputeResourceDescD3D12(descIn);
+
m_srv = desc->srv;
m_resource = desc->resource;
m_currentState = desc->currentState;
}
- ComputeResource(const ComputeResourceDesc* desc)
+ ComputeResourceD3D12(const ComputeResourceDesc* desc)
{
update(desc);
}
@@ -409,21 +447,36 @@ public:
}
};
-struct ComputeResourceRW : public ComputeResource
+inline ComputeResourceD3D12* cast_to_ComputeResourceD3D12(ComputeResource* ctx)
+{
+ return (ComputeResourceD3D12*)(ctx);
+}
+
+inline ComputeResource* cast_from_ComputeResourceD3D12(ComputeResourceD3D12* ctx)
+{
+ return (ComputeResource*)(ctx);
+}
+
+struct ComputeResourceRWD3D12 : public ComputeResourceD3D12
{
protected:
D3D12_CPU_DESCRIPTOR_HANDLE m_uav;
public:
+ static const ComputeResourceRWDescD3D12* cast(const ComputeResourceRWDesc* descRW)
+ {
+ return cast_to_ComputeResourceRWDescD3D12(descRW);
+ }
+
void update(const ComputeResourceRWDesc* descRW)
{
- m_uav = descRW->uav;
- ComputeResource::update(&descRW->resource);
+ m_uav = cast(descRW)->uav;
+ ComputeResourceD3D12::update(cast_from_ComputeResourceDescD3D12(&cast(descRW)->resource));
}
- ComputeResourceRW(const ComputeResourceRWDesc* descRW) :
- ComputeResource(&descRW->resource)
+ ComputeResourceRWD3D12(const ComputeResourceRWDesc* descRW) :
+ ComputeResourceD3D12(cast_from_ComputeResourceDescD3D12(&cast(descRW)->resource))
{
- m_uav = descRW->uav;
+ m_uav = cast(descRW)->uav;
}
D3D12_CPU_DESCRIPTOR_HANDLE UAV()
@@ -432,25 +485,41 @@ public:
}
};
+inline ComputeResourceRWD3D12* cast_to_ComputeResourceRWD3D12(ComputeResourceRW* ctx)
+{
+ return (ComputeResourceRWD3D12*)(ctx);
+}
+
+inline ComputeResourceRW* cast_from_ComputeResourceRWD3D12(ComputeResourceRWD3D12* ctx)
+{
+ return (ComputeResourceRW*)(ctx);
+}
+
+
// ************* API functions ****************
-ComputeContext* ComputeContextCreate(ComputeContextDesc* desc)
+ComputeContext* ComputeContextCreateD3D12(ComputeContextDesc* desc)
{
- return new ComputeContext(desc);
+ return cast_from_ComputeContextD3D12(new ComputeContextD3D12(desc));
}
-void ComputeContextUpdate(ComputeContext* context, ComputeContextDesc* desc)
+void ComputeContextUpdateD3D12(ComputeContext* contextIn, ComputeContextDesc* descIn)
{
+ auto context = cast_to_ComputeContextD3D12(contextIn);
+ auto desc = cast_to_ComputeContextDescD3D12(descIn);
+
context->m_desc = *desc;
}
-void ComputeContextRelease(ComputeContext* context)
+void ComputeContextReleaseD3D12(ComputeContext* context)
{
- delete context;
+ delete cast_to_ComputeContextD3D12(context);
}
-ComputeShader* ComputeShaderCreate(ComputeContext* context, const ComputeShaderDesc* desc)
+ComputeShader* ComputeShaderCreateD3D12(ComputeContext* contextIn, const ComputeShaderDesc* desc)
{
+ auto context = cast_to_ComputeContextD3D12(contextIn);
+
ID3D12PipelineState* computeShader = nullptr;
D3D12_COMPUTE_PIPELINE_STATE_DESC psoDesc = {};
@@ -460,26 +529,29 @@ ComputeShader* ComputeShaderCreate(ComputeContext* context, const ComputeShaderD
context->m_desc.device->CreateComputePipelineState(&psoDesc, IID_PPV_ARGS(&computeShader));
- return new ComputeShader(computeShader);
+ return cast_from_ComputeShaderD3D12(new ComputeShaderD3D12(computeShader));
}
-void ComputeShaderRelease(ComputeShader* shader)
+void ComputeShaderReleaseD3D12(ComputeShader* shader)
{
- delete shader;
+ delete cast_to_ComputeShaderD3D12(shader);
}
-ComputeConstantBuffer* ComputeConstantBufferCreate(ComputeContext* context, const ComputeConstantBufferDesc* desc)
+ComputeConstantBuffer* ComputeConstantBufferCreateD3D12(ComputeContext* context, const ComputeConstantBufferDesc* desc)
{
- return new ComputeConstantBuffer(context, desc);
+ return cast_from_ComputeConstantBufferD3D12(new ComputeConstantBufferD3D12(context, desc));
}
-void ComputeConstantBufferRelease(ComputeConstantBuffer* constantBuffer)
+void ComputeConstantBufferReleaseD3D12(ComputeConstantBuffer* constantBuffer)
{
- delete constantBuffer;
+ delete cast_to_ComputeConstantBufferD3D12(constantBuffer);
}
-void* ComputeConstantBufferMap(ComputeContext* context, ComputeConstantBuffer* constantBuffer)
+void* ComputeConstantBufferMapD3D12(ComputeContext* contextIn, ComputeConstantBuffer* constantBufferIn)
{
+ auto context = cast_to_ComputeContextD3D12(contextIn);
+ auto constantBuffer = cast_to_ComputeConstantBufferD3D12(constantBufferIn);
+
auto bufferData = constantBuffer->m_buffers.map(context->m_desc.lastFenceCompleted, context->m_desc.nextFenceValue);
if (bufferData->m_buffer == nullptr)
@@ -500,52 +572,60 @@ void* ComputeConstantBufferMap(ComputeContext* context, ComputeConstantBuffer* c
return bufferData->m_mappedData;
}
-void ComputeConstantBufferUnmap(ComputeContext* context, ComputeConstantBuffer* constantBuffer)
+void ComputeConstantBufferUnmapD3D12(ComputeContext* contextIn, ComputeConstantBuffer* constantBufferIn)
{
+ auto context = cast_to_ComputeContextD3D12(contextIn);
+ auto constantBuffer = cast_to_ComputeConstantBufferD3D12(constantBufferIn);
+
constantBuffer->m_buffers.unmap(context->m_desc.lastFenceCompleted, context->m_desc.nextFenceValue);
}
-ComputeResource* ComputeResourceCreate(ComputeContext* context, const ComputeResourceDesc* desc)
+ComputeResource* ComputeResourceCreateD3D12(ComputeContext* context, const ComputeResourceDesc* desc)
{
- return new ComputeResource(desc);
+ return cast_from_ComputeResourceD3D12(new ComputeResourceD3D12(desc));
}
-void ComputeResourceUpdate(ComputeContext* context, ComputeResource* resource, const ComputeResourceDesc* desc)
+void ComputeResourceUpdateD3D12(ComputeContext* context, ComputeResource* resourceIn, const ComputeResourceDesc* desc)
{
+ auto resource = cast_to_ComputeResourceD3D12(resourceIn);
resource->update(desc);
}
-void ComputeResourceRelease(ComputeResource* resource)
+void ComputeResourceReleaseD3D12(ComputeResource* resource)
{
- delete resource;
+ delete cast_to_ComputeResourceD3D12(resource);
}
-ComputeResourceRW* ComputeResourceRWCreate(ComputeContext* context, const ComputeResourceRWDesc* desc)
+ComputeResourceRW* ComputeResourceRWCreateD3D12(ComputeContext* context, const ComputeResourceRWDesc* desc)
{
- return new ComputeResourceRW(desc);
+ return cast_from_ComputeResourceRWD3D12(new ComputeResourceRWD3D12(desc));
}
-void ComputeResourceRWUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, const ComputeResourceRWDesc* desc)
+void ComputeResourceRWUpdateD3D12(ComputeContext* context, ComputeResourceRW* resourceRWIn, const ComputeResourceRWDesc* desc)
{
+ auto resourceRW = cast_to_ComputeResourceRWD3D12(resourceRWIn);
resourceRW->update(desc);
}
-void ComputeResourceRWRelease(ComputeResourceRW* resourceRW)
+void ComputeResourceRWReleaseD3D12(ComputeResourceRW* resourceRW)
{
- delete resourceRW;
+ delete cast_to_ComputeResourceRWD3D12(resourceRW);
}
-ComputeResource* ComputeResourceRWGetResource(ComputeResourceRW* resourceRW)
+ComputeResource* ComputeResourceRWGetResourceD3D12(ComputeResourceRW* resourceRWIn)
{
- return static_cast<ComputeResource*>(resourceRW);
+ auto resourceRW = cast_to_ComputeResourceRWD3D12(resourceRWIn);
+ return cast_from_ComputeResourceD3D12(static_cast<ComputeResourceD3D12*>(resourceRW));
}
-void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams* params)
+void ComputeContextDispatchD3D12(ComputeContext* contextIn, const ComputeDispatchParams* params)
{
+ auto context = cast_to_ComputeContextD3D12(contextIn);
+
auto& commandList = context->m_desc.commandList;
commandList->SetComputeRootSignature(context->m_rootSignatureCompute);
- if (params->shader) commandList->SetPipelineState(params->shader->m_shader);
+ if (params->shader) commandList->SetPipelineState(cast_to_ComputeShaderD3D12(params->shader)->m_shader);
auto handles = context->m_desc.dynamicHeapCbvSrvUav.reserveDescriptors(context->m_desc.dynamicHeapCbvSrvUav.userdata,
ComputeDispatchMaxResources + ComputeDispatchMaxResourcesRW,
@@ -557,14 +637,14 @@ void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams
for (ComputeUint i = 0u; i < ComputeDispatchMaxResources; i++)
{
auto r = params->resources[i];
- D3D12_CPU_DESCRIPTOR_HANDLE srcHandle = r ? r->SRV() : context->m_nullSRV;
+ D3D12_CPU_DESCRIPTOR_HANDLE srcHandle = r ? cast_to_ComputeResourceD3D12(r)->SRV() : context->m_nullSRV;
context->m_desc.device->CopyDescriptorsSimple(1u, handles.cpuHandle, srcHandle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
handles.cpuHandle.ptr += handles.descriptorSize;
}
for (ComputeUint i = 0u; i < ComputeDispatchMaxResourcesRW; i++)
{
auto rw = params->resourcesRW[i];
- D3D12_CPU_DESCRIPTOR_HANDLE srcHandle = rw ? rw->UAV() : context->m_nullUAV;
+ D3D12_CPU_DESCRIPTOR_HANDLE srcHandle = rw ? cast_to_ComputeResourceRWD3D12(rw)->UAV() : context->m_nullUAV;
context->m_desc.device->CopyDescriptorsSimple(1u, handles.cpuHandle, srcHandle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
handles.cpuHandle.ptr += handles.descriptorSize;
}
@@ -575,7 +655,7 @@ void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams
if (params->constantBuffer)
{
- auto cbv = params->constantBuffer->m_buffers.front()->m_buffer;
+ auto cbv = cast_to_ComputeConstantBufferD3D12(params->constantBuffer)->m_buffers.front()->m_buffer;
commandList->SetComputeRootConstantBufferView(0u, cbv->GetGPUVirtualAddress());
}
@@ -586,17 +666,17 @@ void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams
auto r = params->resources[i];
if (r)
{
- if (!((*r->currentState()) & D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE))
+ if (!((*cast_to_ComputeResourceD3D12(r)->currentState()) & D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE))
{
D3D12_RESOURCE_BARRIER& bar = barrier[barrierIdx++];
bar.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
bar.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
- bar.Transition.pResource = r->resource();
+ bar.Transition.pResource = cast_to_ComputeResourceD3D12(r)->resource();
bar.Transition.Subresource = 0u;
- bar.Transition.StateBefore = *r->currentState();
+ bar.Transition.StateBefore = *cast_to_ComputeResourceD3D12(r)->currentState();
bar.Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- *r->currentState() = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
+ *cast_to_ComputeResourceD3D12(r)->currentState() = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
}
}
}
@@ -605,24 +685,24 @@ void ComputeContextDispatch(ComputeContext* context, const ComputeDispatchParams
auto rw = params->resourcesRW[i];
if (rw)
{
- if ((*rw->currentState()) == D3D12_RESOURCE_STATE_UNORDERED_ACCESS)
+ if ((*cast_to_ComputeResourceRWD3D12(rw)->currentState()) == D3D12_RESOURCE_STATE_UNORDERED_ACCESS)
{
D3D12_RESOURCE_BARRIER& bar = barrier[barrierIdx++];
bar.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
bar.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
- bar.UAV.pResource = rw->resource();
+ bar.UAV.pResource = cast_to_ComputeResourceRWD3D12(rw)->resource();
}
else
{
D3D12_RESOURCE_BARRIER& bar = barrier[barrierIdx++];
bar.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
bar.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
- bar.Transition.pResource = rw->resource();
+ bar.Transition.pResource = cast_to_ComputeResourceRWD3D12(rw)->resource();
bar.Transition.Subresource = 0u;
- bar.Transition.StateBefore = *rw->currentState();
+ bar.Transition.StateBefore = *cast_to_ComputeResourceRWD3D12(rw)->currentState();
bar.Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
- *rw->currentState() = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
+ *cast_to_ComputeResourceRWD3D12(rw)->currentState() = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
}
}
}
@@ -647,7 +727,7 @@ struct ComputeContextUserDataNvFlow : public ComputeContextUserData
}
};
-ComputeDescriptorReserveHandleD3D12 ComputeReserveDescriptors(void* userdata, UINT numDescriptors, UINT64 lastFenceCompleted, UINT64 nextFenceValue)
+ComputeDescriptorReserveHandleD3D12 ComputeReserveDescriptorsD3D12(void* userdata, UINT numDescriptors, UINT64 lastFenceCompleted, UINT64 nextFenceValue)
{
auto data = static_cast<ComputeContextUserDataNvFlow*>(userdata);
auto srcHandle = data->flowHeap.reserveDescriptors(data->flowHeap.userdata, numDescriptors, lastFenceCompleted, nextFenceValue);
@@ -659,9 +739,9 @@ ComputeDescriptorReserveHandleD3D12 ComputeReserveDescriptors(void* userdata, UI
return handle;
}
-ComputeContext* ComputeContextNvFlowContextCreate(NvFlowContext* flowContext)
+ComputeContext* ComputeContextNvFlowContextCreateD3D12(NvFlowContext* flowContext)
{
- ComputeContextDesc desc = {};
+ ComputeContextDescD3D12 desc = {};
NvFlowContextDescD3D12 srcDesc = {};
NvFlowUpdateContextDescD3D12(flowContext, &srcDesc);
@@ -677,18 +757,20 @@ ComputeContext* ComputeContextNvFlowContextCreate(NvFlowContext* flowContext)
computeUserdata->flowHeap.reserveDescriptors = srcDesc.dynamicHeapCbvSrvUav.reserveDescriptors;
desc.dynamicHeapCbvSrvUav.userdata = computeUserdata;
- desc.dynamicHeapCbvSrvUav.reserveDescriptors = ComputeReserveDescriptors;
+ desc.dynamicHeapCbvSrvUav.reserveDescriptors = ComputeReserveDescriptorsD3D12;
- auto computeContext = ComputeContextCreate(&desc);
+ auto computeContext = cast_to_ComputeContextD3D12(ComputeContextCreateD3D12(cast_from_ComputeContextDescD3D12(&desc)));
computeContext->m_computeUserdata = computeUserdata;
- return computeContext;
+ return cast_from_ComputeContextD3D12(computeContext);
}
-void ComputeContextNvFlowContextUpdate(ComputeContext* computeContext, NvFlowContext* flowContext)
+void ComputeContextNvFlowContextUpdateD3D12(ComputeContext* computeContextIn, NvFlowContext* flowContext)
{
- ComputeContextDesc desc = {};
+ auto computeContext = cast_to_ComputeContextD3D12(computeContextIn);
+
+ ComputeContextDescD3D12 desc = {};
NvFlowContextDescD3D12 srcDesc = {};
NvFlowUpdateContextDescD3D12(flowContext, &srcDesc);
@@ -704,56 +786,56 @@ void ComputeContextNvFlowContextUpdate(ComputeContext* computeContext, NvFlowCon
computeUserdata->flowHeap.reserveDescriptors = srcDesc.dynamicHeapCbvSrvUav.reserveDescriptors;
desc.dynamicHeapCbvSrvUav.userdata = computeUserdata;
- desc.dynamicHeapCbvSrvUav.reserveDescriptors = ComputeReserveDescriptors;
+ desc.dynamicHeapCbvSrvUav.reserveDescriptors = ComputeReserveDescriptorsD3D12;
- ComputeContextUpdate(computeContext, &desc);
+ ComputeContextUpdateD3D12(cast_from_ComputeContextD3D12(computeContext), cast_from_ComputeContextDescD3D12(&desc));
}
-inline void updateComputeResourceDesc(NvFlowResourceViewDescD3D12* flowViewDesc, ComputeResourceDesc* desc)
+inline void updateComputeResourceDesc(NvFlowResourceViewDescD3D12* flowViewDesc, ComputeResourceDescD3D12* desc)
{
desc->srv = flowViewDesc->srvHandle;
desc->resource = flowViewDesc->resource;
desc->currentState = flowViewDesc->currentState;
}
-ComputeResource* ComputeResourceNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource)
+ComputeResource* ComputeResourceNvFlowCreateD3D12(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource)
{
NvFlowResourceViewDescD3D12 flowViewDesc = {};
NvFlowUpdateResourceViewDescD3D12(flowContext, flowResource, &flowViewDesc);
- ComputeResourceDesc desc = {};
+ ComputeResourceDescD3D12 desc = {};
updateComputeResourceDesc(&flowViewDesc, &desc);
- return ComputeResourceCreate(context, &desc);
+ return ComputeResourceCreateD3D12(context, cast_from_ComputeResourceDescD3D12(&desc));
}
-void ComputeResourceNvFlowUpdate(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource)
+void ComputeResourceNvFlowUpdateD3D12(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource)
{
NvFlowResourceViewDescD3D12 flowViewDesc = {};
NvFlowUpdateResourceViewDescD3D12(flowContext, flowResource, &flowViewDesc);
- ComputeResourceDesc desc = {};
+ ComputeResourceDescD3D12 desc = {};
updateComputeResourceDesc(&flowViewDesc, &desc);
- ComputeResourceUpdate(context, resource, &desc);
+ ComputeResourceUpdateD3D12(context, resource, cast_from_ComputeResourceDescD3D12(&desc));
}
-inline void updateComputeResourceRWDesc(NvFlowResourceRWViewDescD3D12* flowViewDesc, ComputeResourceRWDesc* desc)
+inline void updateComputeResourceRWDesc(NvFlowResourceRWViewDescD3D12* flowViewDesc, ComputeResourceRWDescD3D12* desc)
{
updateComputeResourceDesc(&flowViewDesc->resourceView, &desc->resource);
desc->uav = flowViewDesc->uavHandle;
}
-ComputeResourceRW* ComputeResourceRWNvFlowCreate(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
+ComputeResourceRW* ComputeResourceRWNvFlowCreateD3D12(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
{
NvFlowResourceRWViewDescD3D12 flowViewDesc = {};
NvFlowUpdateResourceRWViewDescD3D12(flowContext, flowResourceRW, &flowViewDesc);
- ComputeResourceRWDesc desc = {};
+ ComputeResourceRWDescD3D12 desc = {};
updateComputeResourceRWDesc(&flowViewDesc, &desc);
- return ComputeResourceRWCreate(context, &desc);
+ return ComputeResourceRWCreateD3D12(context, cast_from_ComputeResourceRWDescD3D12(&desc));
}
-void ComputeResourceRWNvFlowUpdate(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
+void ComputeResourceRWNvFlowUpdateD3D12(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW)
{
NvFlowResourceRWViewDescD3D12 flowViewDesc = {};
NvFlowUpdateResourceRWViewDescD3D12(flowContext, flowResourceRW, &flowViewDesc);
- ComputeResourceRWDesc desc = {};
+ ComputeResourceRWDescD3D12 desc = {};
updateComputeResourceRWDesc(&flowViewDesc, &desc);
- ComputeResourceRWUpdate(context, resourceRW, &desc);
+ ComputeResourceRWUpdateD3D12(context, resourceRW, cast_from_ComputeResourceRWDescD3D12(&desc));
} \ No newline at end of file
diff --git a/demo/DemoAppD3D12/computeContextD3D12.h b/demo/DemoAppD3D12/computeContextD3D12.h
index 0acb489..835e7d7 100644
--- a/demo/DemoAppD3D12/computeContextD3D12.h
+++ b/demo/DemoAppD3D12/computeContextD3D12.h
@@ -26,7 +26,7 @@ struct ComputeDynamicDescriptorHeapD3D12
ComputeDescriptorReserveHandleD3D12(*reserveDescriptors)(void* userdata, UINT numDescriptors, UINT64 lastFenceCompleted, UINT64 nextFenceValue);
};
-struct ComputeContextDesc
+struct ComputeContextDescD3D12
{
ID3D12Device* device;
ID3D12CommandQueue* commandQueue;
@@ -38,15 +38,91 @@ struct ComputeContextDesc
ComputeDynamicDescriptorHeapD3D12 dynamicHeapCbvSrvUav;
};
-struct ComputeResourceDesc
+struct ComputeResourceDescD3D12
{
D3D12_CPU_DESCRIPTOR_HANDLE srv;
ID3D12Resource* resource;
D3D12_RESOURCE_STATES* currentState;
};
-struct ComputeResourceRWDesc
+struct ComputeResourceRWDescD3D12
{
- ComputeResourceDesc resource;
+ ComputeResourceDescD3D12 resource;
D3D12_CPU_DESCRIPTOR_HANDLE uav;
-}; \ No newline at end of file
+};
+
+inline const ComputeContextDescD3D12* cast_to_ComputeContextDescD3D12(const ComputeContextDesc* desc)
+{
+ return (const ComputeContextDescD3D12*)(desc);
+}
+
+inline ComputeContextDesc* cast_from_ComputeContextDescD3D12(ComputeContextDescD3D12* desc)
+{
+ return (ComputeContextDesc*)(desc);
+}
+
+inline const ComputeResourceDescD3D12* cast_to_ComputeResourceDescD3D12(const ComputeResourceDesc* desc)
+{
+ return (const ComputeResourceDescD3D12*)(desc);
+}
+
+inline const ComputeResourceDesc* cast_from_ComputeResourceDescD3D12(const ComputeResourceDescD3D12* desc)
+{
+ return (const ComputeResourceDesc*)(desc);
+}
+
+inline const ComputeResourceRWDescD3D12* cast_to_ComputeResourceRWDescD3D12(const ComputeResourceRWDesc* desc)
+{
+ return (const ComputeResourceRWDescD3D12*)(desc);
+}
+
+inline const ComputeResourceRWDesc* cast_from_ComputeResourceRWDescD3D12(const ComputeResourceRWDescD3D12* desc)
+{
+ return (const ComputeResourceRWDesc*)(desc);
+}
+
+COMPUTE_API ComputeContext* ComputeContextCreateD3D12(ComputeContextDesc* desc);
+
+COMPUTE_API void ComputeContextUpdateD3D12(ComputeContext* context, ComputeContextDesc* desc);
+
+COMPUTE_API void ComputeContextReleaseD3D12(ComputeContext* context);
+
+COMPUTE_API ComputeShader* ComputeShaderCreateD3D12(ComputeContext* context, const ComputeShaderDesc* desc);
+
+COMPUTE_API void ComputeShaderReleaseD3D12(ComputeShader* shader);
+
+COMPUTE_API ComputeConstantBuffer* ComputeConstantBufferCreateD3D12(ComputeContext* context, const ComputeConstantBufferDesc* desc);
+
+COMPUTE_API void ComputeConstantBufferReleaseD3D12(ComputeConstantBuffer* constantBuffer);
+
+COMPUTE_API void* ComputeConstantBufferMapD3D12(ComputeContext* context, ComputeConstantBuffer* constantBuffer);
+
+COMPUTE_API void ComputeConstantBufferUnmapD3D12(ComputeContext* context, ComputeConstantBuffer* constantBuffer);
+
+COMPUTE_API ComputeResource* ComputeResourceCreateD3D12(ComputeContext* context, const ComputeResourceDesc* desc);
+
+COMPUTE_API void ComputeResourceUpdateD3D12(ComputeContext* context, ComputeResource* resource, const ComputeResourceDesc* desc);
+
+COMPUTE_API void ComputeResourceReleaseD3D12(ComputeResource* resource);
+
+COMPUTE_API ComputeResourceRW* ComputeResourceRWCreateD3D12(ComputeContext* context, const ComputeResourceRWDesc* desc);
+
+COMPUTE_API void ComputeResourceRWUpdateD3D12(ComputeContext* context, ComputeResourceRW* resourceRW, const ComputeResourceRWDesc* desc);
+
+COMPUTE_API void ComputeResourceRWReleaseD3D12(ComputeResourceRW* resourceRW);
+
+COMPUTE_API ComputeResource* ComputeResourceRWGetResourceD3D12(ComputeResourceRW* resourceRW);
+
+COMPUTE_API void ComputeContextDispatchD3D12(ComputeContext* context, const ComputeDispatchParams* params);
+
+COMPUTE_API ComputeContext* ComputeContextNvFlowContextCreateD3D12(NvFlowContext* flowContext);
+
+COMPUTE_API void ComputeContextNvFlowContextUpdateD3D12(ComputeContext* computeContext, NvFlowContext* flowContext);
+
+COMPUTE_API ComputeResource* ComputeResourceNvFlowCreateD3D12(ComputeContext* context, NvFlowContext* flowContext, NvFlowResource* flowResource);
+
+COMPUTE_API void ComputeResourceNvFlowUpdateD3D12(ComputeContext* context, ComputeResource* resource, NvFlowContext* flowContext, NvFlowResource* flowResource);
+
+COMPUTE_API ComputeResourceRW* ComputeResourceRWNvFlowCreateD3D12(ComputeContext* context, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW);
+
+COMPUTE_API void ComputeResourceRWNvFlowUpdateD3D12(ComputeContext* context, ComputeResourceRW* resourceRW, NvFlowContext* flowContext, NvFlowResourceRW* flowResourceRW); \ No newline at end of file
diff --git a/demo/DemoAppD3D12/imguiGraphD3D12.cpp b/demo/DemoAppD3D12/imguiGraphD3D12.cpp
index 9b5f74a..92cbab1 100644
--- a/demo/DemoAppD3D12/imguiGraphD3D12.cpp
+++ b/demo/DemoAppD3D12/imguiGraphD3D12.cpp
@@ -28,7 +28,7 @@ namespace
namespace
{
- ImguiGraphDesc m_desc = {};
+ ImguiGraphDescD3D12 m_desc = {};
struct Vertex
{
@@ -75,8 +75,10 @@ namespace
int frameIndex = 0;
}
-void imguiGraphContextInit(const ImguiGraphDesc* desc)
+void imguiGraphContextInitD3D12(const ImguiGraphDesc* descIn)
{
+ const auto desc = cast_to_imguiGraphDescD3D12(descIn);
+
m_desc = *desc;
// create the root signature
@@ -308,12 +310,14 @@ void imguiGraphContextInit(const ImguiGraphDesc* desc)
}
}
-void imguiGraphContextUpdate(const ImguiGraphDesc* desc)
+void imguiGraphContextUpdateD3D12(const ImguiGraphDesc* descIn)
{
+ const auto desc = cast_to_imguiGraphDescD3D12(descIn);
+
m_desc = *desc;
}
-void imguiGraphContextDestroy()
+void imguiGraphContextDestroyD3D12()
{
COMRelease(m_rootSignature);
COMRelease(m_pipelineState);
@@ -321,7 +325,7 @@ void imguiGraphContextDestroy()
COMRelease(m_vertexBuffer);
}
-void imguiGraphRecordBegin()
+void imguiGraphRecordBeginD3D12()
{
frameIndex = (frameIndex + 1) % frameCount;
@@ -406,7 +410,7 @@ static void imguiGraphFlush()
}
}
-void imguiGraphRecordEnd()
+void imguiGraphRecordEndD3D12()
{
ID3D12GraphicsCommandList* commandList = m_desc.commandList;
@@ -424,7 +428,7 @@ void imguiGraphRecordEnd()
commandList->RSSetScissorRects(1, &rect);
}
-void imguiGraphEnableScissor(int x, int y, int width, int height)
+void imguiGraphEnableScissorD3D12(int x, int y, int width, int height)
{
// mark end of last region
m_stateScissor.stopIdx = m_stateVertIdx;
@@ -439,7 +443,7 @@ void imguiGraphEnableScissor(int x, int y, int width, int height)
m_stateScissor.height = height;
}
-void imguiGraphDisableScissor()
+void imguiGraphDisableScissorD3D12()
{
if (m_stateVertIdx == 0) return;
@@ -456,13 +460,13 @@ void imguiGraphDisableScissor()
m_stateScissor.height = m_desc.winH;
}
-void imguiGraphVertex2f(float x, float y)
+void imguiGraphVertex2fD3D12(float x, float y)
{
float v[2] = { x,y };
- imguiGraphVertex2fv(v);
+ imguiGraphVertex2fvD3D12(v);
}
-void imguiGraphVertex2fv(const float* v)
+void imguiGraphVertex2fvD3D12(const float* v)
{
// update state
m_stateVert.x = v[0];
@@ -477,13 +481,13 @@ void imguiGraphVertex2fv(const float* v)
}
}
-void imguiGraphTexCoord2f(float u, float v)
+void imguiGraphTexCoord2fD3D12(float u, float v)
{
m_stateVert.u = u;
m_stateVert.v = v;
}
-void imguiGraphColor4ub(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+void imguiGraphColor4ubD3D12(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
{
m_stateVert.rgba[0] = red;
m_stateVert.rgba[1] = green;
@@ -491,7 +495,7 @@ void imguiGraphColor4ub(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
m_stateVert.rgba[3] = alpha;
}
-void imguiGraphColor4ubv(const uint8_t* v)
+void imguiGraphColor4ubvD3D12(const uint8_t* v)
{
m_stateVert.rgba[0] = v[0];
m_stateVert.rgba[1] = v[1];
@@ -499,18 +503,18 @@ void imguiGraphColor4ubv(const uint8_t* v)
m_stateVert.rgba[3] = v[3];
}
-void imguiGraphFontTextureEnable()
+void imguiGraphFontTextureEnableD3D12()
{
}
-void imguiGraphFontTextureDisable()
+void imguiGraphFontTextureDisableD3D12()
{
m_stateVert.u = -1.f;
m_stateVert.v = -1.f;
}
-void imguiGraphFontTextureInit(unsigned char* data)
+void imguiGraphFontTextureInitD3D12(unsigned char* data)
{
ID3D12GraphicsCommandList* commandList = m_desc.commandList;
@@ -653,7 +657,7 @@ void imguiGraphFontTextureInit(unsigned char* data)
}
-void imguiGraphFontTextureRelease()
+void imguiGraphFontTextureReleaseD3D12()
{
COMRelease(m_texture);
COMRelease(m_textureUploadHeap);
diff --git a/demo/DemoAppD3D12/imguiGraphD3D12.h b/demo/DemoAppD3D12/imguiGraphD3D12.h
index 7eeb538..d011188 100644
--- a/demo/DemoAppD3D12/imguiGraphD3D12.h
+++ b/demo/DemoAppD3D12/imguiGraphD3D12.h
@@ -29,7 +29,7 @@ struct ImguiDynamicDescriptorHeapD3D12
ImguiDescriptorReserveHandleD3D12(*reserveDescriptors)(void* userdata, UINT numDescriptors, UINT64 lastFenceCompleted, UINT64 nextFenceValue);
};
-struct ImguiGraphDesc
+struct ImguiGraphDescD3D12
{
ID3D12Device* device = nullptr;
ID3D12GraphicsCommandList* commandList = nullptr;
@@ -42,7 +42,49 @@ struct ImguiGraphDesc
ImguiDynamicDescriptorHeapD3D12 dynamicHeapCbvSrvUav = {};
- ImguiGraphDesc() {}
+ ImguiGraphDescD3D12() {}
};
+inline const ImguiGraphDescD3D12* cast_to_imguiGraphDescD3D12(const ImguiGraphDesc* desc)
+{
+ return (const ImguiGraphDescD3D12*)(desc);
+}
+
+inline ImguiGraphDesc* cast_from_imguiGraphDescD3D12(ImguiGraphDescD3D12* desc)
+{
+ return (ImguiGraphDesc*)(desc);
+}
+
+IMGUI_GRAPH_API void imguiGraphContextInitD3D12(const ImguiGraphDesc* desc);
+
+IMGUI_GRAPH_API void imguiGraphContextUpdateD3D12(const ImguiGraphDesc* desc);
+
+IMGUI_GRAPH_API void imguiGraphContextDestroyD3D12();
+
+IMGUI_GRAPH_API void imguiGraphRecordBeginD3D12();
+
+IMGUI_GRAPH_API void imguiGraphRecordEndD3D12();
+
+IMGUI_GRAPH_API void imguiGraphVertex2fD3D12(float x, float y);
+
+IMGUI_GRAPH_API void imguiGraphVertex2fvD3D12(const float* v);
+
+IMGUI_GRAPH_API void imguiGraphTexCoord2fD3D12(float u, float v);
+
+IMGUI_GRAPH_API void imguiGraphColor4ubD3D12(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
+
+IMGUI_GRAPH_API void imguiGraphColor4ubvD3D12(const uint8_t* v);
+
+IMGUI_GRAPH_API void imguiGraphFontTextureEnableD3D12();
+
+IMGUI_GRAPH_API void imguiGraphFontTextureDisableD3D12();
+
+IMGUI_GRAPH_API void imguiGraphEnableScissorD3D12(int x, int y, int width, int height);
+
+IMGUI_GRAPH_API void imguiGraphDisableScissorD3D12();
+
+IMGUI_GRAPH_API void imguiGraphFontTextureInitD3D12(unsigned char* data);
+
+IMGUI_GRAPH_API void imguiGraphFontTextureReleaseD3D12();
+
#endif \ No newline at end of file
diff --git a/demo/DemoAppD3D12/imguiInteropD3D12.cpp b/demo/DemoAppD3D12/imguiInteropD3D12.cpp
index 322e1b5..30a8760 100644
--- a/demo/DemoAppD3D12/imguiInteropD3D12.cpp
+++ b/demo/DemoAppD3D12/imguiInteropD3D12.cpp
@@ -21,7 +21,7 @@
ImguiDescriptorReserveHandleD3D12 imguiInteropReserveDescriptors(void* userdata, UINT numDescriptors, UINT64 lastFenceCompleted, UINT64 nextFenceValue)
{
- auto appctx = static_cast<AppGraphCtx*>(userdata);
+ auto appctx = cast_to_AppGraphCtxD3D12((AppGraphCtx*)userdata);
auto srcHandle = appctx->m_dynamicHeapCbvSrvUav.reserveDescriptors(numDescriptors, lastFenceCompleted, nextFenceValue);
ImguiDescriptorReserveHandleD3D12 handle = {};
handle.heap = srcHandle.heap;
@@ -31,8 +31,10 @@ ImguiDescriptorReserveHandleD3D12 imguiInteropReserveDescriptors(void* userdata,
return handle;
}
-void imguiInteropUpdateDesc(ImguiGraphDesc& desc, AppGraphCtx* appctx)
+inline void imguiInteropUpdateDesc(ImguiGraphDescD3D12& desc, AppGraphCtx* appctxIn)
{
+ auto appctx = cast_to_AppGraphCtxD3D12(appctxIn);
+
desc.device = appctx->m_device;
desc.commandList = appctx->m_commandList;
desc.lastFenceCompleted = appctx->m_lastFenceComplete;
@@ -43,18 +45,22 @@ void imguiInteropUpdateDesc(ImguiGraphDesc& desc, AppGraphCtx* appctx)
desc.dynamicHeapCbvSrvUav.reserveDescriptors = imguiInteropReserveDescriptors;
}
-bool imguiInteropGraphInit(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx)
+IMGUI_GRAPH_API bool imguiInteropGraphInitD3D12(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx);
+
+IMGUI_GRAPH_API void imguiInteropGraphUpdateD3D12(imguiGraphUpdate_t func, AppGraphCtx* appctx);
+
+bool imguiInteropGraphInitD3D12(imguiGraphInit_t func, const char* fontpath, AppGraphCtx* appctx)
{
- ImguiGraphDesc desc;
+ ImguiGraphDescD3D12 desc;
imguiInteropUpdateDesc(desc, appctx);
- return func(fontpath, &desc);
+ return func(fontpath, cast_from_imguiGraphDescD3D12(&desc));
}
-void imguiInteropGraphUpdate(imguiGraphUpdate_t func, AppGraphCtx* appctx)
+void imguiInteropGraphUpdateD3D12(imguiGraphUpdate_t func, AppGraphCtx* appctx)
{
- ImguiGraphDesc desc;
+ ImguiGraphDescD3D12 desc;
imguiInteropUpdateDesc(desc, appctx);
- return func(&desc);
+ return func(cast_from_imguiGraphDescD3D12(&desc));
} \ No newline at end of file
diff --git a/demo/DemoAppD3D12/meshD3D12.cpp b/demo/DemoAppD3D12/meshD3D12.cpp
index 3b04436..5821c89 100644
--- a/demo/DemoAppD3D12/meshD3D12.cpp
+++ b/demo/DemoAppD3D12/meshD3D12.cpp
@@ -105,7 +105,7 @@ struct MeshConstantHeap
}
};
-struct MeshContext
+struct MeshContextD3D12
{
ID3D12Device* m_device = nullptr;
ID3D12GraphicsCommandList* m_commandList = nullptr;
@@ -116,8 +116,8 @@ struct MeshContext
MeshConstantHeap* m_constantHeap = nullptr;
- MeshContext() {}
- ~MeshContext()
+ MeshContextD3D12() {}
+ ~MeshContextD3D12()
{
COMRelease(m_rootSignature);
COMRelease(m_pipelineStateLH);
@@ -130,7 +130,17 @@ struct MeshContext
}
};
-struct MeshIndexBuffer
+inline MeshContextD3D12* cast_to_MeshContextD3D12(MeshContext* ctx)
+{
+ return (MeshContextD3D12*)(ctx);
+}
+
+inline MeshContext* cast_from_MeshContextD3D12(MeshContextD3D12* ctx)
+{
+ return (MeshContext*)(ctx);
+}
+
+struct MeshIndexBufferD3D12
{
ID3D12Resource* m_buffer = nullptr;
MeshUint m_numElements = 0u;
@@ -138,15 +148,25 @@ struct MeshIndexBuffer
ID3D12Resource* m_upload = nullptr;
- MeshIndexBuffer() {}
- ~MeshIndexBuffer()
+ MeshIndexBufferD3D12() {}
+ ~MeshIndexBufferD3D12()
{
COMRelease(m_buffer);
COMRelease(m_upload);
}
};
-struct MeshVertexBuffer
+inline MeshIndexBufferD3D12* cast_to_MeshIndexBufferD3D12(MeshIndexBuffer* buf)
+{
+ return (MeshIndexBufferD3D12*)(buf);
+}
+
+inline MeshIndexBuffer* cast_from_MeshIndexBufferD3D12(MeshIndexBufferD3D12* buf)
+{
+ return (MeshIndexBuffer*)(buf);
+}
+
+struct MeshVertexBufferD3D12
{
ID3D12Resource* m_buffer = nullptr;
MeshUint m_numElements = 0u;
@@ -154,16 +174,28 @@ struct MeshVertexBuffer
ID3D12Resource* m_upload = nullptr;
- MeshVertexBuffer() {}
- ~MeshVertexBuffer()
+ MeshVertexBufferD3D12() {}
+ ~MeshVertexBufferD3D12()
{
COMRelease(m_buffer);
COMRelease(m_upload);
}
};
-MeshConstantHeap::MeshConstantHeap(MeshContext* meshContext, int size) : m_meshContext(meshContext)
+inline MeshVertexBufferD3D12* cast_to_MeshVertexBufferD3D12(MeshVertexBuffer* buf)
{
+ return (MeshVertexBufferD3D12*)(buf);
+}
+
+inline MeshVertexBuffer* cast_from_MeshVertexBufferD3D12(MeshVertexBufferD3D12* buf)
+{
+ return (MeshVertexBuffer*)(buf);
+}
+
+MeshConstantHeap::MeshConstantHeap(MeshContext* meshContextIn, int size) : m_meshContext(meshContextIn)
+{
+ auto meshContext = cast_to_MeshContextD3D12(meshContextIn);
+
// create a constant buffer
{
HRESULT hr = S_OK;
@@ -208,9 +240,11 @@ MeshConstantHeap::MeshConstantHeap(MeshContext* meshContext, int size) : m_meshC
}
}
-MeshContext* MeshContextCreate(const MeshContextDesc* desc)
+MeshContext* MeshContextCreateD3D12(const MeshContextDesc* descIn)
{
- MeshContext* context = new MeshContext;
+ auto desc = cast_to_MeshContextDescD3D12(descIn);
+
+ MeshContextD3D12* context = new MeshContextD3D12;
context->m_device = desc->device;
context->m_commandList = desc->commandList;
@@ -333,30 +367,35 @@ MeshContext* MeshContextCreate(const MeshContextDesc* desc)
// create constant heap
{
- context->m_constantHeap = new MeshConstantHeap(context, 4096u);
+ context->m_constantHeap = new MeshConstantHeap(cast_from_MeshContextD3D12(context), 4096u);
}
- return context;
+ return cast_from_MeshContextD3D12(context);
}
-void MeshContextUpdate(MeshContext* context, const MeshContextDesc* desc)
+void MeshContextUpdateD3D12(MeshContext* contextIn, const MeshContextDesc* descIn)
{
+ auto context = cast_to_MeshContextD3D12(contextIn);
+ auto desc = cast_to_MeshContextDescD3D12(descIn);
+
context->m_device = desc->device;
context->m_commandList = desc->commandList;
context->m_constantHeap->reset();
}
-void MeshContextRelease(MeshContext* context)
+void MeshContextReleaseD3D12(MeshContext* context)
{
if (context == nullptr) return;
- delete context;
+ delete cast_to_MeshContextD3D12(context);
}
-MeshIndexBuffer* MeshIndexBufferCreate(MeshContext* context, MeshUint* indices, MeshUint numIndices)
+MeshIndexBuffer* MeshIndexBufferCreateD3D12(MeshContext* contextIn, MeshUint* indices, MeshUint numIndices)
{
- MeshIndexBuffer* buffer = new MeshIndexBuffer;
+ auto context = cast_to_MeshContextD3D12(contextIn);
+
+ MeshIndexBufferD3D12* buffer = new MeshIndexBufferD3D12;
buffer->m_numElements = numIndices;
// create an index buffer
@@ -433,19 +472,21 @@ MeshIndexBuffer* MeshIndexBufferCreate(MeshContext* context, MeshUint* indices,
buffer->m_view.Format = DXGI_FORMAT_R32_UINT;
}
- return buffer;
+ return cast_from_MeshIndexBufferD3D12(buffer);
}
-void MeshIndexBufferRelease(MeshIndexBuffer* buffer)
+void MeshIndexBufferReleaseD3D12(MeshIndexBuffer* buffer)
{
if (buffer == nullptr) return;
- delete buffer;
+ delete cast_to_MeshIndexBufferD3D12(buffer);
}
-MeshVertexBuffer* MeshVertexBufferCreate(MeshContext* context, MeshVertex* vertices, MeshUint numVertices)
+MeshVertexBuffer* MeshVertexBufferCreateD3D12(MeshContext* contextIn, MeshVertex* vertices, MeshUint numVertices)
{
- MeshVertexBuffer* buffer = new MeshVertexBuffer;
+ auto context = cast_to_MeshContextD3D12(contextIn);
+
+ MeshVertexBufferD3D12* buffer = new MeshVertexBufferD3D12;
buffer->m_numElements = numVertices;
// create a vertex buffer
@@ -522,18 +563,20 @@ MeshVertexBuffer* MeshVertexBufferCreate(MeshContext* context, MeshVertex* verti
buffer->m_view.SizeInBytes = bufferSize;
}
- return buffer;
+ return cast_from_MeshVertexBufferD3D12(buffer);
}
-void MeshVertexBufferRelease(MeshVertexBuffer* buffer)
+void MeshVertexBufferReleaseD3D12(MeshVertexBuffer* buffer)
{
if (buffer == nullptr) return;
- delete buffer;
+ delete cast_to_MeshVertexBufferD3D12(buffer);
}
-void MeshContextDraw(MeshContext* context, const MeshContextDrawParams* params)
+void MeshContextDrawD3D12(MeshContext* contextIn, const MeshContextDrawParams* params)
{
+ auto context = cast_to_MeshContextD3D12(contextIn);
+
using namespace DirectX;
XMMATRIX matrix = XMMatrixTranspose(XMMatrixMultiply(XMMatrixMultiply(
@@ -569,8 +612,8 @@ void MeshContextDraw(MeshContext* context, const MeshContextDrawParams* params)
commandList->SetGraphicsRootConstantBufferView(0, cbvHandle);
commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- commandList->IASetVertexBuffers(0, 1, &params->vertexBuffer->m_view);
- commandList->IASetIndexBuffer(&params->indexBuffer->m_view);
+ commandList->IASetVertexBuffers(0, 1, &cast_to_MeshVertexBufferD3D12(params->vertexBuffer)->m_view);
+ commandList->IASetIndexBuffer(&cast_to_MeshIndexBufferD3D12(params->indexBuffer)->m_view);
- commandList->DrawIndexedInstanced((UINT)params->indexBuffer->m_numElements, 1, 0, 0, 0);
+ commandList->DrawIndexedInstanced((UINT)cast_to_MeshIndexBufferD3D12(params->indexBuffer)->m_numElements, 1, 0, 0, 0);
} \ No newline at end of file
diff --git a/demo/DemoAppD3D12/meshD3D12.h b/demo/DemoAppD3D12/meshD3D12.h
index 4bd0fab..94c8994 100644
--- a/demo/DemoAppD3D12/meshD3D12.h
+++ b/demo/DemoAppD3D12/meshD3D12.h
@@ -12,8 +12,35 @@
#include "../DemoApp/mesh.h"
-struct MeshContextDesc
+struct MeshContextDescD3D12
{
ID3D12Device* device;
ID3D12GraphicsCommandList* commandList;
-}; \ No newline at end of file
+};
+
+inline const MeshContextDescD3D12* cast_to_MeshContextDescD3D12(const MeshContextDesc* desc)
+{
+ return (const MeshContextDescD3D12*)(desc);
+}
+
+inline MeshContextDesc* cast_from_MeshContextDescD3D12(MeshContextDescD3D12* desc)
+{
+ return (MeshContextDesc*)(desc);
+}
+
+MESH_API MeshContext* MeshContextCreateD3D12(const MeshContextDesc* desc);
+
+MESH_API void MeshContextUpdateD3D12(MeshContext* context, const MeshContextDesc* desc);
+
+MESH_API void MeshContextReleaseD3D12(MeshContext* context);
+
+
+MESH_API MeshIndexBuffer* MeshIndexBufferCreateD3D12(MeshContext* context, MeshUint* indices, MeshUint numIndices);
+
+MESH_API void MeshIndexBufferReleaseD3D12(MeshIndexBuffer* buffer);
+
+MESH_API MeshVertexBuffer* MeshVertexBufferCreateD3D12(MeshContext* context, MeshVertex* vertices, MeshUint numVertices);
+
+MESH_API void MeshVertexBufferReleaseD3D12(MeshVertexBuffer* buffer);
+
+MESH_API void MeshContextDrawD3D12(MeshContext* context, const MeshContextDrawParams* params); \ No newline at end of file
diff --git a/demo/DemoAppD3D12/meshInteropD3D12.cpp b/demo/DemoAppD3D12/meshInteropD3D12.cpp
index 19c034d..28649a0 100644
--- a/demo/DemoAppD3D12/meshInteropD3D12.cpp
+++ b/demo/DemoAppD3D12/meshInteropD3D12.cpp
@@ -19,20 +19,28 @@
#include "appD3D12Ctx.h"
#include "meshD3D12.h"
-MeshContext* MeshInteropContextCreate(AppGraphCtx* appctx)
+MESH_API MeshContext* MeshInteropContextCreateD3D12(AppGraphCtx* appctx);
+
+MESH_API void MeshInteropContextUpdateD3D12(MeshContext* context, AppGraphCtx* appctx);
+
+MeshContext* MeshInteropContextCreateD3D12(AppGraphCtx* appctxIn)
{
- MeshContextDesc desc = {};
+ auto appctx = cast_to_AppGraphCtxD3D12(appctxIn);
+
+ MeshContextDescD3D12 desc = {};
desc.device = appctx->m_device;
desc.commandList = appctx->m_commandList;
- return MeshContextCreate(&desc);
+ return MeshContextCreateD3D12(cast_from_MeshContextDescD3D12(&desc));
}
-void MeshInteropContextUpdate(MeshContext* context, AppGraphCtx* appctx)
+void MeshInteropContextUpdateD3D12(MeshContext* context, AppGraphCtx* appctxIn)
{
- MeshContextDesc desc = {};
+ auto appctx = cast_to_AppGraphCtxD3D12(appctxIn);
+
+ MeshContextDescD3D12 desc = {};
desc.device = appctx->m_device;
desc.commandList = appctx->m_commandList;
- return MeshContextUpdate(context, &desc);
+ return MeshContextUpdateD3D12(context, cast_from_MeshContextDescD3D12(&desc));
} \ No newline at end of file