Add Android Vulkan backend (#2711)

Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
Adrian Cojocaru
2024-09-06 17:40:57 +03:00
committed by GitHub
parent 4b5d06d908
commit ea09bdf2b6
79 changed files with 2580 additions and 1400 deletions

View File

@@ -14,26 +14,17 @@ class Context;
struct BufferAllocation {
const VmaAllocator& allocator;
VmaAllocation allocation{};
VkBuffer buffer{};
vk::Buffer buffer{};
void* mappedBuffer{};
BufferAllocation() = delete;
BufferAllocation(BufferAllocation&) = delete;
BufferAllocation& operator=(const BufferAllocation& other) = delete;
BufferAllocation(BufferAllocation&& other) = default;
BufferAllocation(const VmaAllocator& allocator_)
: allocator(allocator_) {}
BufferAllocation(BufferAllocation&& other) noexcept
: allocator(other.allocator),
allocation(other.allocation),
buffer(other.buffer),
mappedBuffer(other.mappedBuffer) {
other.buffer = nullptr;
other.allocation = nullptr;
other.mappedBuffer = nullptr;
}
~BufferAllocation() { destroy(); }
bool create(const VmaAllocationCreateInfo& allocInfo, const vk::BufferCreateInfo& bufferInfo);
@@ -63,7 +54,7 @@ public:
const void* contents() const noexcept { return (raw.empty() ? nullptr : raw.data()); }
Context& getContext() const noexcept { return context; }
const VkBuffer& getVulkanBuffer() const noexcept { return bufferAllocation->buffer; }
const vk::Buffer& getVulkanBuffer() const noexcept { return bufferAllocation->buffer; }
std::size_t getVulkanBufferOffset() const noexcept;
std::size_t getVulkanBufferSize() const noexcept;

View File

@@ -54,6 +54,7 @@ public:
void beginFrame() override;
void endFrame() override;
void submitFrame();
void waitFrame() const;
std::unique_ptr<gfx::CommandEncoder> createCommandEncoder() override;
@@ -145,6 +146,8 @@ public:
void enqueueDeletion(std::function<void(const Context&)>&& function);
void submitOneTimeCommand(const std::function<void(const vk::UniqueCommandBuffer&)>& function);
void requestSurfaceUpdate() { surfaceUpdateRequested = true; }
private:
struct FrameResources {
vk::UniqueCommandBuffer commandBuffer;
@@ -189,6 +192,7 @@ private:
uint8_t frameResourceIndex = 0;
std::vector<FrameResources> frameResources;
bool surfaceUpdateRequested{false};
struct {
gfx::ShaderProgramBasePtr shader;

View File

@@ -82,8 +82,8 @@ public:
void updateVertexInputHash();
std::size_t hash() const;
void setDynamicValues(const vk::UniqueCommandBuffer& buffer) const;
std::vector<vk::DynamicState> getDynamicStates() const;
void setDynamicValues(const RendererBackend& backend, const vk::UniqueCommandBuffer& buffer) const;
std::vector<vk::DynamicState> getDynamicStates(const RendererBackend& backend) const;
protected:
std::size_t vertexInputHash{0};

View File

@@ -16,6 +16,11 @@ protected:
~RenderableResource() override = default;
public:
virtual void swap() {
// Renderable resources that require a swap function to be called
// explicitly can override this method.
}
const vk::Extent2D& getExtent() const { return extent; }
const vk::UniqueRenderPass& getRenderPass() const { return renderPass; }
virtual const vk::UniqueFramebuffer& getFramebuffer() const = 0;
@@ -34,10 +39,12 @@ protected:
~SurfaceRenderableResource() override;
void initColor(uint32_t w, uint32_t h);
void initSwapchain(uint32_t w, uint32_t h);
void initSwapchain(uint32_t w, uint32_t h, vk::PresentModeKHR presentMode = vk::PresentModeKHR::eFifo);
void initDepthStencil();
void swap() override;
public:
virtual void createPlatformSurface() = 0;
virtual std::vector<const char*> getDeviceExtensions() { return {}; }

View File

@@ -47,6 +47,7 @@ public:
uint32_t getMaxFrames() const { return maxFrames; }
const VmaAllocator& getAllocator() const { return allocator; }
const vk::PhysicalDeviceProperties& getDeviceProperties() const { return physicalDeviceProperties; }
const vk::PhysicalDeviceFeatures& getDeviceFeatures() const { return physicalDeviceFeatures; }
int32_t getGraphicsQueueIndex() const { return graphicsQueueIndex; }
int32_t getPresentQueueIndex() const { return presentQueueIndex; }
@@ -97,6 +98,7 @@ protected:
vk::PhysicalDevice physicalDevice;
vk::UniqueDevice device;
vk::PhysicalDeviceProperties physicalDeviceProperties;
vk::PhysicalDeviceFeatures physicalDeviceFeatures;
int32_t graphicsQueueIndex = -1;
int32_t presentQueueIndex = -1;

View File

@@ -15,25 +15,17 @@ class RenderPass;
struct ImageAllocation {
const VmaAllocator& allocator;
VmaAllocation allocation{};
VkImage image{};
vk::Image image{};
vk::UniqueImageView imageView{};
ImageAllocation() = delete;
ImageAllocation(ImageAllocation&) = delete;
ImageAllocation& operator=(const ImageAllocation& other) = delete;
ImageAllocation(ImageAllocation&& other) = default;
ImageAllocation(const VmaAllocator& allocator_)
: allocator(allocator_) {}
ImageAllocation(ImageAllocation&& other) noexcept
: allocator(other.allocator),
allocation(other.allocation),
image(other.image),
imageView(std::move(other.imageView)) {
other.image = nullptr;
other.allocation = nullptr;
}
~ImageAllocation() { destroy(); }
bool create(const VmaAllocationCreateInfo& allocInfo, const vk::ImageCreateInfo& imageInfo);