diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2022-05-26 10:54:35 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-26 10:54:35 -0700 |
| commit | 43e1b7cdc70b2fcac8a3e8ee72f5bc91726f4ec5 (patch) | |
| tree | 1e4701b4ab324a199b81e1f6c671f6660f1050c5 /tools/gfx/vulkan/vk-buffer.h | |
| parent | 5ff4f42c636a67724523e4fe60697cfac64908cd (diff) | |
Split render-vk.h/.cpp into a set of smaller files (#2244)
* Some preliminary work on splitting render-vk
* render-vk split, tests currently crash on null reference
* fixed circular include
Diffstat (limited to 'tools/gfx/vulkan/vk-buffer.h')
| -rw-r--r-- | tools/gfx/vulkan/vk-buffer.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tools/gfx/vulkan/vk-buffer.h b/tools/gfx/vulkan/vk-buffer.h new file mode 100644 index 000000000..c824f3529 --- /dev/null +++ b/tools/gfx/vulkan/vk-buffer.h @@ -0,0 +1,77 @@ +// vk-buffer.h +#pragma once + +#include "vk-base.h" +#include "vk-device.h" + +namespace gfx +{ + +using namespace Slang; + +namespace vk +{ + +class VKBufferHandleRAII +{ +public: + /// Initialize a buffer with specified size, and memory props + Result init( + const VulkanApi& api, + Size bufferSize, + VkBufferUsageFlags usage, + VkMemoryPropertyFlags reqMemoryProperties, + bool isShared = false, + VkExternalMemoryHandleTypeFlagsKHR extMemHandleType = 0); + + /// Returns true if has been initialized + bool isInitialized() const { return m_api != nullptr; } + + VKBufferHandleRAII() + : m_api(nullptr) + {} + + ~VKBufferHandleRAII() + { + if (m_api) + { + m_api->vkDestroyBuffer(m_api->m_device, m_buffer, nullptr); + m_api->vkFreeMemory(m_api->m_device, m_memory, nullptr); + } + } + + VkBuffer m_buffer; + VkDeviceMemory m_memory; + const VulkanApi* m_api; +}; + +class BufferResourceImpl : public BufferResource +{ +public: + typedef BufferResource Parent; + + BufferResourceImpl(const IBufferResource::Desc& desc, DeviceImpl* renderer); + + ~BufferResourceImpl(); + + RefPtr<DeviceImpl> m_renderer; + VKBufferHandleRAII m_buffer; + VKBufferHandleRAII m_uploadBuffer; + + virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override; + + virtual SLANG_NO_THROW Result SLANG_MCALL + getNativeResourceHandle(InteropHandle* outHandle) override; + + virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override; + + virtual SLANG_NO_THROW Result SLANG_MCALL + map(MemoryRange* rangeToRead, void** outPointer) override; + + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + + virtual SLANG_NO_THROW Result SLANG_MCALL setDebugName(const char* name) override; +}; + +} // namespace vk +} // namespace gfx |
