diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2021-10-04 09:46:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-04 09:46:33 -0700 |
| commit | b3dfe383c6d31ff3dbd76dcfb32de8d536382f3e (patch) | |
| tree | 06efb21869df7ccdca6d98ab4217b8bf75dfdd2f /tools/gfx | |
| parent | 35bca4cc432613af3926da3bed217a6baa9cbd26 (diff) | |
Get native handles for TextureResource and BufferResource (#1960)
* Added getNativeHandle() to TextureResource and BufferResource; Implemented getNativeHandle() in Vulkan and D3D12; Added new unit test files for the aforementioned implementation
* Added missing getNativeHandle() implementations to renderer-shared.cpp and CUDA
* Finished new getNativeHandle() unit tests for ITextureResource and IBufferResource; Modified ICommandQueue and ICommandBuffer unit tests to call QueryInterface to convert to IUnknown then back and compare resulting pointers for equality
* Unit tests updated and pass locally
* Cast m_buffer.m_buffer and m_image to uint64_t
Diffstat (limited to 'tools/gfx')
| -rw-r--r-- | tools/gfx/cuda/render-cuda.cpp | 12 | ||||
| -rw-r--r-- | tools/gfx/d3d12/render-d3d12.cpp | 12 | ||||
| -rw-r--r-- | tools/gfx/debug-layer.cpp | 10 | ||||
| -rw-r--r-- | tools/gfx/debug-layer.h | 2 | ||||
| -rw-r--r-- | tools/gfx/renderer-shared.cpp | 11 | ||||
| -rw-r--r-- | tools/gfx/renderer-shared.h | 2 | ||||
| -rw-r--r-- | tools/gfx/vulkan/render-vk.cpp | 12 |
7 files changed, 61 insertions, 0 deletions
diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp index ec6f1212a..788baed0d 100644 --- a/tools/gfx/cuda/render-cuda.cpp +++ b/tools/gfx/cuda/render-cuda.cpp @@ -193,6 +193,12 @@ public: { return (DeviceAddress)m_cudaMemory; } + + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override + { + *outHandle = getBindlessHandle(); + return SLANG_OK; + } }; class TextureCUDAResource : public TextureResource @@ -234,6 +240,12 @@ public: CUmipmappedArray m_cudaMipMappedArray = CUmipmappedArray(); RefPtr<CUDAContext> m_cudaContext; + + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override + { + *outHandle = getBindlessHandle(); + return SLANG_OK; + } }; class CUDAResourceView : public ResourceViewBase diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index 2d8c5fa10..4002450f3 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -219,6 +219,12 @@ public: { return (DeviceAddress)m_resource.getResource()->GetGPUVirtualAddress(); } + + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override + { + *outHandle = (uint64_t)m_resource.getResource(); + return SLANG_OK; + } }; class TextureResourceImpl: public TextureResource @@ -234,6 +240,12 @@ public: D3D12Resource m_resource; D3D12_RESOURCE_STATES m_defaultState; + + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override + { + *outHandle = (uint64_t)m_resource.getResource(); + return SLANG_OK; + } }; class SamplerStateImpl : public ISamplerState, public ComObject diff --git a/tools/gfx/debug-layer.cpp b/tools/gfx/debug-layer.cpp index 74b319a08..869a93411 100644 --- a/tools/gfx/debug-layer.cpp +++ b/tools/gfx/debug-layer.cpp @@ -692,6 +692,11 @@ DeviceAddress DebugBufferResource::getDeviceAddress() return baseObject->getDeviceAddress(); } +Result DebugBufferResource::getNativeHandle(NativeHandle* outHandle) +{ + return baseObject->getNativeHandle(outHandle); +} + IResource::Type DebugTextureResource::getType() { SLANG_GFX_API_FUNC; @@ -704,6 +709,11 @@ ITextureResource::Desc* DebugTextureResource::getDesc() return baseObject->getDesc(); } +Result DebugTextureResource::getNativeHandle(NativeHandle* outHandle) +{ + return baseObject->getNativeHandle(outHandle); +} + DebugCommandBuffer::DebugCommandBuffer() { SLANG_GFX_API_FUNC; diff --git a/tools/gfx/debug-layer.h b/tools/gfx/debug-layer.h index 88e0e5ecd..2f0bc76ce 100644 --- a/tools/gfx/debug-layer.h +++ b/tools/gfx/debug-layer.h @@ -144,6 +144,7 @@ public: virtual SLANG_NO_THROW Type SLANG_MCALL getType() override; virtual SLANG_NO_THROW Desc* SLANG_MCALL getDesc() override; virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override; + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override; }; class DebugTextureResource : public DebugObject<ITextureResource> @@ -155,6 +156,7 @@ public: ITextureResource* getInterface(const Slang::Guid& guid); virtual SLANG_NO_THROW Type SLANG_MCALL getType() override; virtual SLANG_NO_THROW Desc* SLANG_MCALL getDesc() override; + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override; }; class DebugResourceView : public DebugObject<IResourceView> diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp index 18f99ad1b..c5a0c826d 100644 --- a/tools/gfx/renderer-shared.cpp +++ b/tools/gfx/renderer-shared.cpp @@ -74,6 +74,11 @@ IResource* BufferResource::getInterface(const Slang::Guid& guid) SLANG_NO_THROW IResource::Type SLANG_MCALL BufferResource::getType() { return m_type; } SLANG_NO_THROW IBufferResource::Desc* SLANG_MCALL BufferResource::getDesc() { return &m_desc; } +Result BufferResource::getNativeHandle(NativeHandle* outHandle) +{ + *outHandle = NULL; + return SLANG_OK; +} IResource* TextureResource::getInterface(const Slang::Guid& guid) { @@ -86,6 +91,12 @@ IResource* TextureResource::getInterface(const Slang::Guid& guid) SLANG_NO_THROW IResource::Type SLANG_MCALL TextureResource::getType() { return m_type; } SLANG_NO_THROW ITextureResource::Desc* SLANG_MCALL TextureResource::getDesc() { return &m_desc; } +Result TextureResource::getNativeHandle(NativeHandle* outHandle) +{ + *outHandle = NULL; + return SLANG_OK; +} + StageType mapStage(SlangStage stage) { switch( stage ) diff --git a/tools/gfx/renderer-shared.h b/tools/gfx/renderer-shared.h index 5710bc74e..5df3ee92b 100644 --- a/tools/gfx/renderer-shared.h +++ b/tools/gfx/renderer-shared.h @@ -218,6 +218,7 @@ public: virtual SLANG_NO_THROW IResource::Type SLANG_MCALL getType() SLANG_OVERRIDE; virtual SLANG_NO_THROW IBufferResource::Desc* SLANG_MCALL getDesc() SLANG_OVERRIDE; + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) SLANG_OVERRIDE; protected: Desc m_desc; @@ -240,6 +241,7 @@ public: virtual SLANG_NO_THROW IResource::Type SLANG_MCALL getType() SLANG_OVERRIDE; virtual SLANG_NO_THROW ITextureResource::Desc* SLANG_MCALL getDesc() SLANG_OVERRIDE; + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) SLANG_OVERRIDE; protected: Desc m_desc; diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index 7af7d086f..d2cbd6790 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -203,6 +203,12 @@ public: return (DeviceAddress)m_buffer.m_api->vkGetBufferDeviceAddress( m_buffer.m_api->m_device, &info); } + + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override + { + *outHandle = (uint64_t)m_buffer.m_buffer; + return SLANG_OK; + } }; class TextureResourceImpl : public TextureResource @@ -229,6 +235,12 @@ public: VkDeviceMemory m_imageMemory = VK_NULL_HANDLE; bool m_isWeakImageReference = false; RefPtr<VKDevice> m_device; + + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override + { + *outHandle = (uint64_t)m_image; + return SLANG_OK; + } }; class SamplerStateImpl : public ISamplerState, public ComObject |
