Skip to content

Commit c220bc1

Browse files
committed
implement getBufferDeviceAddress
1 parent 499ead0 commit c220bc1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

include/nbl/video/ILogicalDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class NBL_API ILogicalDevice : public core::IReferenceCounted, public IDeviceMem
182182

183183
virtual core::smart_refctd_ptr<IGPUBuffer> createBuffer(IGPUBuffer::SCreationParams&& creationParams) { return nullptr; }
184184

185+
virtual uint64_t getBufferDeviceAddress(IGPUBuffer* buffer) { return ~0ull; }
186+
185187
//! Binds memory allocation to provide the backing for the resource.
186188
/** Available only on Vulkan, in OpenGL all resources create their own memory implicitly,
187189
so pooling or aliasing memory for different resources is not possible.

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,38 @@ class CVulkanLogicalDevice final : public ILogicalDevice
510510
return nullptr;
511511
}
512512
}
513-
513+
514+
uint64_t getBufferDeviceAddress(IGPUBuffer* buffer) override
515+
{
516+
constexpr uint64_t invalid_address = ~0ull;
517+
CVulkanBuffer* vulkanBuffer = IBackendObject::device_compatibility_cast<CVulkanBuffer*>(buffer, this);
518+
if (!vulkanBuffer)
519+
{
520+
// TODO: log error
521+
assert(false);
522+
return invalid_address;
523+
}
524+
525+
if (!buffer->getCreationParams().usage.hasFlags(asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT))
526+
{
527+
// TODO: log error: Buffer should've been created with EUF_SHADER_DEVICE_ADDRESS_BIT
528+
assert(false);
529+
return invalid_address;
530+
}
531+
532+
if (!m_enabledFeatures.bufferDeviceAddress)
533+
{
534+
// TODO: log error: bufferDeviceAddress extension is not enbaled
535+
assert(false);
536+
return invalid_address;
537+
}
538+
539+
VkBufferDeviceAddressInfo info = {};
540+
info.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO;
541+
info.buffer = vulkanBuffer->getInternalObject();
542+
return m_devf.vk.vkGetBufferDeviceAddress(m_vkdev, &info);
543+
}
544+
514545
core::smart_refctd_ptr<IGPUShader> createShader(core::smart_refctd_ptr<asset::ICPUShader>&& cpushader) override
515546
{
516547
const char* entryPoint = "main";

0 commit comments

Comments
 (0)