aboutsummaryrefslogtreecommitdiff
path: root/demo/DemoAppD3D11
diff options
context:
space:
mode:
Diffstat (limited to 'demo/DemoAppD3D11')
-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
11 files changed, 564 insertions, 205 deletions
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