Line data Source code
1 : /* Copyright (C) 2025 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #ifndef INCLUDED_RENDERER_BACKEND_VULKAN_BUFFER 19 : #define INCLUDED_RENDERER_BACKEND_VULKAN_BUFFER 20 : 21 : #include "renderer/backend/IBuffer.h" 22 : #include "renderer/backend/vulkan/DeviceObjectUID.h" 23 : #include "renderer/backend/vulkan/VMA.h" 24 : 25 : #include <cstdint> 26 : #include <glad/vulkan.h> 27 : #include <memory> 28 : 29 : namespace Renderer::Backend::Vulkan { class CDevice; } 30 : 31 : namespace Renderer 32 : { 33 : 34 : namespace Backend 35 : { 36 : 37 : namespace Vulkan 38 : { 39 : 40 : class CBuffer final : public IBuffer 41 : { 42 : public: 43 : ~CBuffer() override; 44 : 45 : IDevice* GetDevice() override; 46 : 47 0 : Type GetType() const override { return m_Type; } 48 0 : uint32_t GetSize() const override { return m_Size; } 49 0 : uint32_t GetUsage() const override { return m_Usage; } 50 : 51 0 : VkBuffer GetVkBuffer() { return m_Buffer; } 52 : 53 : /** 54 : * @return mapped data for UPLOAD buffers else returns nullptr. 55 : */ 56 0 : void* GetMappedData() { return m_AllocationInfo.pMappedData; } 57 : 58 0 : DeviceObjectUID GetUID() const { return m_UID; } 59 : 60 : private: 61 : friend class CDevice; 62 : 63 : static std::unique_ptr<CBuffer> Create( 64 : CDevice* device, const char* name, const Type type, const uint32_t size, 65 : const uint32_t usage); 66 : 67 : CBuffer(); 68 : 69 : CDevice* m_Device = nullptr; 70 : 71 : DeviceObjectUID m_UID{INVALID_DEVICE_OBJECT_UID}; 72 : 73 : Type m_Type = Type::VERTEX; 74 : uint32_t m_Size = 0; 75 : uint32_t m_Usage = 0; 76 : 77 : VkBuffer m_Buffer = VK_NULL_HANDLE; 78 : VmaAllocation m_Allocation = VK_NULL_HANDLE; 79 : VmaAllocationInfo m_AllocationInfo{}; 80 : }; 81 : 82 : } // namespace Vulkan 83 : 84 : } // namespace Backend 85 : 86 : } // namespace Renderer 87 : 88 : #endif // INCLUDED_RENDERER_BACKEND_VULKAN_BUFFER