I’m trying to setup D3D11 interop with OptiX 6.0 in the context of a progressive lightmapper, but I’m failing at the very first step rtContextSetD3D11Device with RT_ERROR_INVALID_VALUE.
Is the D3D11 interop supported on OptiX 6.0?
Here’s the optix Code
SD3d11Context d3d11 = create_d3d11_device();
optix::TContextPtr pContext = optix::createContext(optix::ERtxMode::Yes);
RTcontext ctx = pContext->getUnderlying();
RTresult rtr = rtContextSetD3D11Device(ctx, d3d11.mpDevice);
// rtr == RT_ERROR_INVALID_VALUE
I’ve tried creating the D3D11 device with and without a swap-chain if that matters:
struct SD3d11Context
{
ID3D11Device * mpDevice { nullptr };
ID3D11DeviceContext * mpContext { nullptr };
HWND mWindow {};
IDXGISwapChain * mpSwapChain { nullptr };
};
//#define CREATE_D3D11_SWAPCHAIN
SD3d11Context create_d3d11_device()
{
SD3d11Context result;
D3D_FEATURE_LEVEL featureLevels[] = {D3D_FEATURE_LEVEL_11_1};
D3D_FEATURE_LEVEL resultFeatureLevel;
#ifdef CREATE_D3D11_SWAPCHAIN
HINSTANCE mod = GetModuleHandle(NULL);
result.mWindow = CreateWindowEx(
WS_EX_APPWINDOW,
"Static",
"Test D3D Window",
WS_DISABLED | WS_POPUP,
0, 0, 1, 1, //a 1x1 window at (0,0)
NULL, NULL, //no parent and no menu
mod,
NULL
);
if (result.mWindow == NULL)
{
uint32_t lastError = GetLastError();
std::string errMsg = std::system_category().message(lastError);
LOG_ERROR("Failed to create window: ", errMsg);
return result;
}
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.Width = 1;
swapChainDesc.BufferDesc.Height = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = result.mWindow;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = TRUE;
HRESULT hr = D3D11CreateDeviceAndSwapChain(
nullptr, // IDXGIAdapter
D3D_DRIVER_TYPE_HARDWARE, // Driver Type
nullptr, // NULL unless driver type is software
0, // Device creation flags
featureLevels, // Pick from the default feature levels
1, // Number of feature levels
D3D11_SDK_VERSION, // SDK Version
&swapChainDesc, // Description of the swap chain
&result.mpSwapChain, // out swapchain pointerr
&result.mpDevice, // out device pointer
&resultFeatureLevel, // Feature level
&result.mpContext // Device context
);
#else
HRESULT hr = D3D11CreateDevice(
nullptr, // IDXGIAdapter
D3D_DRIVER_TYPE_HARDWARE, // Driver Type
nullptr, // NULL unless driver type is software
0, // Device creation flags
featureLevels, // Pick from the default feature levels
1, // Number of feature levels
D3D11_SDK_VERSION, // SDK Version
&result.mpDevice, // out device pointer
&resultFeatureLevel, // Feature level
&result.mpContext // Device context
);
#endif
if (hr != S_OK)
{
LOG_ERROR("Failed to create D3D11 device: ", std::system_category().message(hr));
result.mpDevice = nullptr;
result.mpContext = nullptr;
}
return result;
}
Here’s the system information:
[1][SYS INFO ]
OptiX Version:[6.0.0] Branch:[r419_50] Build Number:[26129760] CUDA Version:[cuda100] 64-bit
Display driver: 425.31
Devices available:
CUDA device: 0
0000:9E:00.0
GeForce RTX 2080
SM count: 46
SM arch: 75
SM clock: 1815 KHz
GPU memory: 8192 MB
TCC driver: 0
Compatible devices: 0