diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2021-12-08 11:38:14 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-08 11:38:14 -0800 |
| commit | 9606401e1de1002e3ad070bc5c6384fa5bc4d9ff (patch) | |
| tree | 7a557a14fadf5220a34f6df9faf1a5535100743f /tools/gfx/d3d12/render-d3d12.cpp | |
| parent | 90d8af888b40c83b33f9f0c037bd2ab8c19a35f4 (diff) | |
D3D12 and Vulkan to CUDA Texture Sharing (#2038)
Diffstat (limited to 'tools/gfx/d3d12/render-d3d12.cpp')
| -rw-r--r-- | tools/gfx/d3d12/render-d3d12.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index 371d22002..ebc894291 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -314,11 +314,19 @@ public: virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override { + // Check if a shared handle already exists for this resource. + if (sharedHandle.handleValue != 0) + { + *outHandle = sharedHandle; + return SLANG_OK; + } + + // If a shared handle doesn't exist, create one and store it. ComPtr<ID3D12Device> pDevice; auto pResource = m_resource.getResource(); pResource->GetDevice(IID_PPV_ARGS(pDevice.writeRef())); SLANG_RETURN_ON_FAIL(pDevice->CreateSharedHandle(pResource, NULL, GENERIC_ALL, nullptr, (HANDLE*)&outHandle->handleValue)); - outHandle->api = InteropHandleAPI::Win32; + outHandle->api = InteropHandleAPI::D3D12; return SLANG_OK; } }; @@ -5031,7 +5039,7 @@ Result D3D12Device::getTextureAllocationInfo( TextureResource::Desc srcDesc = fixupTextureDesc(desc); D3D12_RESOURCE_DESC resourceDesc = {}; setupResourceDesc(resourceDesc, srcDesc); - auto allocInfo = m_device->GetResourceAllocationInfo(0xFF, 1, &resourceDesc); + auto allocInfo = m_device->GetResourceAllocationInfo(0, 1, &resourceDesc); *outSize = (size_t)allocInfo.SizeInBytes; *outAlignment = (size_t)allocInfo.Alignment; return SLANG_OK; @@ -5061,6 +5069,9 @@ Result D3D12Device::createTextureResource(const ITextureResource::Desc& descIn, heapProps.CreationNodeMask = 1; heapProps.VisibleNodeMask = 1; + D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE; + if (descIn.isShared) flags |= D3D12_HEAP_FLAG_SHARED; + D3D12_CLEAR_VALUE clearValue; D3D12_CLEAR_VALUE* clearValuePtr = &clearValue; if ((resourceDesc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | @@ -5075,7 +5086,7 @@ Result D3D12Device::createTextureResource(const ITextureResource::Desc& descIn, SLANG_RETURN_ON_FAIL(texture->m_resource.initCommitted( m_device, heapProps, - D3D12_HEAP_FLAG_NONE, + flags, resourceDesc, D3D12_RESOURCE_STATE_COPY_DEST, clearValuePtr)); |
