diff options
| author | Yong He <yonghe@outlook.com> | 2021-06-23 11:33:30 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-23 11:33:30 -0700 |
| commit | 0f2d11dc994c6323b4bfb955b522f3123e731fe0 (patch) | |
| tree | bc1316bba9217b22f3708dcb03727d70d2d8351a /tools | |
| parent | 0afa24a3fe7d0e1787cc909f9c7641f477c30e5c (diff) | |
[gfx] Add `IBufferResource::getDeviceAddress()`. (#1892)
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/gfx/cpu/render-cpu.cpp | 8 | ||||
| -rw-r--r-- | tools/gfx/cuda/render-cuda.cpp | 5 | ||||
| -rw-r--r-- | tools/gfx/d3d11/render-d3d11.cpp | 5 | ||||
| -rw-r--r-- | tools/gfx/d3d12/render-d3d12.cpp | 5 | ||||
| -rw-r--r-- | tools/gfx/debug-layer.cpp | 5 | ||||
| -rw-r--r-- | tools/gfx/debug-layer.h | 1 | ||||
| -rw-r--r-- | tools/gfx/open-gl/render-gl.cpp | 5 | ||||
| -rw-r--r-- | tools/gfx/vulkan/render-vk.cpp | 11 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-api.cpp | 5 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-api.h | 5 |
10 files changed, 54 insertions, 1 deletions
diff --git a/tools/gfx/cpu/render-cpu.cpp b/tools/gfx/cpu/render-cpu.cpp index f635cf727..af1fcc65a 100644 --- a/tools/gfx/cpu/render-cpu.cpp +++ b/tools/gfx/cpu/render-cpu.cpp @@ -37,7 +37,8 @@ public: SlangResult init() { m_data = malloc(m_desc.sizeInBytes); - if(!m_data) return SLANG_E_OUT_OF_MEMORY; + if (!m_data) + return SLANG_E_OUT_OF_MEMORY; return SLANG_OK; } @@ -48,6 +49,11 @@ public: } void* m_data = nullptr; + + virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override + { + return (DeviceAddress)m_data; + } }; struct CPUTextureBaseShapeInfo diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp index 3e93c090a..5a7e7babf 100644 --- a/tools/gfx/cuda/render-cuda.cpp +++ b/tools/gfx/cuda/render-cuda.cpp @@ -188,6 +188,11 @@ public: void* m_cudaMemory = nullptr; RefPtr<CUDAContext> m_cudaContext; + + virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override + { + return (DeviceAddress)m_cudaMemory; + } }; class TextureCUDAResource : public TextureResource diff --git a/tools/gfx/d3d11/render-d3d11.cpp b/tools/gfx/d3d11/render-d3d11.cpp index c4cd3f655..f2fe9b744 100644 --- a/tools/gfx/d3d11/render-d3d11.cpp +++ b/tools/gfx/d3d11/render-d3d11.cpp @@ -210,6 +210,11 @@ protected: ComPtr<ID3D11Buffer> m_buffer; ComPtr<ID3D11Buffer> m_staging; List<uint8_t> m_uploadStagingBuffer; + + virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override + { + return 0; + } }; class TextureResourceImpl : public TextureResource { diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index e05d68661..79cbe2f9a 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -198,6 +198,11 @@ public: D3D12Resource m_uploadResource; ///< If the resource can be written to, and is in gpu memory (ie not Memory backed), will have upload resource D3D12_RESOURCE_STATES m_defaultState; + + virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override + { + return (DeviceAddress)m_resource.getResource()->GetGPUVirtualAddress(); + } }; class TextureResourceImpl: public TextureResource diff --git a/tools/gfx/debug-layer.cpp b/tools/gfx/debug-layer.cpp index 13875d6ec..26aa36535 100644 --- a/tools/gfx/debug-layer.cpp +++ b/tools/gfx/debug-layer.cpp @@ -501,6 +501,11 @@ IBufferResource::Desc* DebugBufferResource::getDesc() return baseObject->getDesc(); } +DeviceAddress DebugBufferResource::getDeviceAddress() +{ + return baseObject->getDeviceAddress(); +} + IResource::Type DebugTextureResource::getType() { SLANG_GFX_API_FUNC; diff --git a/tools/gfx/debug-layer.h b/tools/gfx/debug-layer.h index 0fb8e681b..6225260dd 100644 --- a/tools/gfx/debug-layer.h +++ b/tools/gfx/debug-layer.h @@ -124,6 +124,7 @@ public: IBufferResource* 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 DeviceAddress SLANG_MCALL getDeviceAddress() override; }; class DebugTextureResource : public DebugObject<ITextureResource> diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp index 524c28858..81a1a6ccd 100644 --- a/tools/gfx/open-gl/render-gl.cpp +++ b/tools/gfx/open-gl/render-gl.cpp @@ -242,6 +242,11 @@ public: GLuint m_handle; GLenum m_target; UInt m_size; + + virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override + { + return 0; + } }; class TextureResourceImpl: public TextureResource diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index 78054b4d5..97a527ca6 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -179,6 +179,17 @@ public: RefPtr<VKDevice> m_renderer; Buffer m_buffer; Buffer m_uploadBuffer; + + virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override + { + if (!m_buffer.m_api->vkGetBufferDeviceAddress) + return 0; + VkBufferDeviceAddressInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO; + info.buffer = m_buffer.m_buffer; + return (DeviceAddress)m_buffer.m_api->vkGetBufferDeviceAddress( + m_buffer.m_api->m_device, &info); + } }; class TextureResourceImpl : public TextureResource diff --git a/tools/gfx/vulkan/vk-api.cpp b/tools/gfx/vulkan/vk-api.cpp index 9a4ab130d..7e1a9bae2 100644 --- a/tools/gfx/vulkan/vk-api.cpp +++ b/tools/gfx/vulkan/vk-api.cpp @@ -87,6 +87,11 @@ Slang::Result VulkanApi::initDeviceProcs(VkDevice device) return SLANG_FAIL; } + if (!vkGetBufferDeviceAddressKHR && vkGetBufferDeviceAddressEXT) + vkGetBufferDeviceAddressKHR = vkGetBufferDeviceAddressEXT; + if (!vkGetBufferDeviceAddress && vkGetBufferDeviceAddressKHR) + vkGetBufferDeviceAddress = vkGetBufferDeviceAddressKHR; + m_device = device; return SLANG_OK; } diff --git a/tools/gfx/vulkan/vk-api.h b/tools/gfx/vulkan/vk-api.h index 75b88dd96..4c024525b 100644 --- a/tools/gfx/vulkan/vk-api.h +++ b/tools/gfx/vulkan/vk-api.h @@ -143,6 +143,7 @@ namespace gfx { x(vkGetPhysicalDeviceSurfacePresentModesKHR) \ x(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \ x(vkDestroySurfaceKHR) \ + /* */ #define VK_API_DEVICE_KHR_PROCS(x) \ @@ -155,6 +156,10 @@ namespace gfx { #define VK_API_DEVICE_OPT_PROCS(x) \ x(vkCmdSetPrimitiveTopologyEXT) \ + x(vkGetBufferDeviceAddress) \ + x(vkGetBufferDeviceAddressKHR) \ + x(vkGetBufferDeviceAddressEXT) \ + /* */ #define VK_API_ALL_GLOBAL_PROCS(x) \ |
