// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #if GRAPHICS_API_VULKAN #include "Engine/Graphics/GPUBuffer.h" #include "GPUDeviceVulkan.h" /// /// The buffer view for Vulkan backend. /// class GPUBufferViewVulkan : public GPUBufferView, public DescriptorOwnerResourceVulkan { public: GPUBufferViewVulkan() { } #if BUILD_DEBUG ~GPUBufferViewVulkan() { ASSERT(View == VK_NULL_HANDLE); } #endif public: GPUDeviceVulkan* Device = nullptr; GPUBufferVulkan* Owner = nullptr; VkBuffer Buffer = VK_NULL_HANDLE; VkBufferView View = VK_NULL_HANDLE; VkDeviceSize Size = 0; public: void Init(GPUDeviceVulkan* device, GPUBufferVulkan* owner, VkBuffer buffer, VkDeviceSize size, VkBufferUsageFlags usage, PixelFormat format); void Release(); public: // [GPUResourceView] void* GetNativePtr() const override { return (void*)(DescriptorOwnerResourceVulkan*)this; } // [DescriptorOwnerResourceVulkan] void DescriptorAsUniformTexelBuffer(GPUContextVulkan* context, VkBufferView& bufferView) override; void DescriptorAsStorageBuffer(GPUContextVulkan* context, VkBuffer& buffer, VkDeviceSize& offset, VkDeviceSize& range) override; void DescriptorAsStorageTexelBuffer(GPUContextVulkan* context, VkBufferView& bufferView) override; #if !BUILD_RELEASE bool HasSRV() const override { return ((GPUBuffer*)_parent)->IsShaderResource(); } bool HasUAV() const override { return ((GPUBuffer*)_parent)->IsUnorderedAccess(); } #endif }; /// /// GPU buffer for Vulkan backend. /// class GPUBufferVulkan : public GPUResourceVulkan { private: VkBuffer _buffer = VK_NULL_HANDLE; VmaAllocation _allocation = VK_NULL_HANDLE; GPUBufferViewVulkan _view; public: /// /// Initializes a new instance of the class. /// /// The device. /// The name. GPUBufferVulkan(GPUDeviceVulkan* device, const StringView& name) : GPUResourceVulkan(device, name) { } public: /// /// Gets the Vulkan buffer handle. /// FORCE_INLINE VkBuffer GetHandle() const { return _buffer; } /// /// Gets the Vulkan memory allocation handle. /// FORCE_INLINE VmaAllocation GetAllocation() const { return _allocation; } /// /// The current buffer access flags. /// VkAccessFlags Access; /// /// The counter buffer attached to the Append/Counter buffers. /// GPUBufferVulkan* Counter = nullptr; public: // [GPUBuffer] GPUBufferView* View() const override; void* Map(GPUResourceMapMode mode) override; void Unmap() override; protected: // [GPUBuffer] bool OnInit() override; void OnReleaseGPU() override; }; #endif