mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
vulkan: fix android build
It compiles now, but it's not working correctly yet
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "graphics/Buffer.h"
|
||||
#include "graphics/Volatile.h"
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "VulkanWrapper.h"
|
||||
#include "vk_mem_alloc.h"
|
||||
|
||||
|
||||
|
||||
@@ -41,8 +41,12 @@ const std::vector<const char*> deviceExtensions = {
|
||||
#ifdef NDEBUG
|
||||
constexpr bool enableValidationLayers = false;
|
||||
#else
|
||||
#ifdef LOVE_ANDROID
|
||||
constexpr bool enableValidationLayers = false;
|
||||
#else
|
||||
constexpr bool enableValidationLayers = true;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
constexpr int MAX_FRAMES_IN_FLIGHT = 2;
|
||||
|
||||
@@ -310,6 +314,7 @@ void Graphics::getAPIStats(int& shaderswitches) const {
|
||||
|
||||
void Graphics::unSetMode() {
|
||||
created = false;
|
||||
auto fpn = vkDeviceWaitIdle;
|
||||
vkDeviceWaitIdle(device);
|
||||
Volatile::unloadAll();
|
||||
cleanup();
|
||||
@@ -646,6 +651,10 @@ void Graphics::createVulkanInstance() {
|
||||
&instance) != VK_SUCCESS) {
|
||||
throw love::Exception("couldn't create vulkan instance");
|
||||
}
|
||||
|
||||
#ifdef LOVE_ANDROID
|
||||
volkLoadInstance(instance);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Graphics::checkValidationSupport() {
|
||||
@@ -847,21 +856,56 @@ void Graphics::createLogicalDevice() {
|
||||
throw love::Exception("failed to create logical device");
|
||||
}
|
||||
|
||||
#ifdef LOVE_ANDROID
|
||||
volkLoadDevice(device);
|
||||
#endif
|
||||
|
||||
vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);
|
||||
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);
|
||||
}
|
||||
|
||||
void Graphics::initVMA() {
|
||||
VmaVulkanFunctions vulkanFunctions = {};
|
||||
vulkanFunctions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr;
|
||||
vulkanFunctions.vkGetDeviceProcAddr = &vkGetDeviceProcAddr;
|
||||
|
||||
VmaAllocatorCreateInfo allocatorCreateInfo = {};
|
||||
allocatorCreateInfo.vulkanApiVersion = vulkanApiVersion;
|
||||
allocatorCreateInfo.physicalDevice = physicalDevice;
|
||||
allocatorCreateInfo.device = device;
|
||||
allocatorCreateInfo.instance = instance;
|
||||
#ifdef LOVE_ANDROID
|
||||
VmaVulkanFunctions vulkanFunctions{};
|
||||
|
||||
vulkanFunctions.vkGetInstanceProcAddr = vkGetInstanceProcAddr;
|
||||
vulkanFunctions.vkGetDeviceProcAddr = vkGetDeviceProcAddr;
|
||||
vulkanFunctions.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties;
|
||||
vulkanFunctions.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties;
|
||||
vulkanFunctions.vkAllocateMemory = vkAllocateMemory;
|
||||
vulkanFunctions.vkFreeMemory = vkFreeMemory;
|
||||
vulkanFunctions.vkMapMemory = vkMapMemory;
|
||||
vulkanFunctions.vkUnmapMemory = vkUnmapMemory;
|
||||
vulkanFunctions.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges;
|
||||
vulkanFunctions.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges;
|
||||
vulkanFunctions.vkBindBufferMemory = vkBindBufferMemory;
|
||||
vulkanFunctions.vkBindImageMemory = vkBindImageMemory;
|
||||
vulkanFunctions.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements;
|
||||
vulkanFunctions.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements;
|
||||
vulkanFunctions.vkCreateBuffer = vkCreateBuffer;
|
||||
vulkanFunctions.vkCreateImage = vkCreateImage;
|
||||
vulkanFunctions.vkDestroyBuffer = vkDestroyBuffer;
|
||||
vulkanFunctions.vkDestroyImage = vkDestroyImage;
|
||||
vulkanFunctions.vkCmdCopyBuffer = vkCmdCopyBuffer;
|
||||
|
||||
vulkanFunctions.vkGetBufferMemoryRequirements2KHR = vkGetBufferMemoryRequirements2KHR;
|
||||
vulkanFunctions.vkGetImageMemoryRequirements2KHR = vkGetImageMemoryRequirements2KHR;
|
||||
vulkanFunctions.vkBindBufferMemory2KHR = vkBindBufferMemory2KHR;
|
||||
vulkanFunctions.vkBindImageMemory2KHR = vkBindImageMemory2KHR;
|
||||
vulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR = vkGetPhysicalDeviceMemoryProperties2KHR;
|
||||
|
||||
vulkanFunctions.vkGetDeviceBufferMemoryRequirements = vkGetDeviceBufferMemoryRequirements;
|
||||
vulkanFunctions.vkGetDeviceImageMemoryRequirements = vkGetDeviceImageMemoryRequirements;
|
||||
|
||||
allocatorCreateInfo.pVulkanFunctions = &vulkanFunctions;
|
||||
#else
|
||||
allocatorCreateInfo.pVulkanFunctions = nullptr;
|
||||
#endif
|
||||
|
||||
if (vmaCreateAllocator(&allocatorCreateInfo, &vmaAllocator) != VK_SUCCESS) {
|
||||
throw love::Exception("failed to create vma allocator");
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <common/config.h>
|
||||
|
||||
// libraries
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "VulkanWrapper.h"
|
||||
#include "vk_mem_alloc.h"
|
||||
#include "libraries/xxHash/xxhash.h"
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
namespace love {
|
||||
@@ -121,7 +122,14 @@ struct SwapChainSupportDetails {
|
||||
|
||||
class Graphics final : public love::graphics::Graphics {
|
||||
public:
|
||||
Graphics() = default;
|
||||
Graphics() {
|
||||
#ifdef LOVE_ANDROID
|
||||
auto result = volkInitialize();
|
||||
if (result != VK_SUCCESS) {
|
||||
throw love::Exception("could not initialize volk");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~Graphics();
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ static const TBuiltInResource defaultTBuiltInResource = {
|
||||
};
|
||||
|
||||
static const uint32_t STREAMBUFFER_DEFAULT_SIZE = 16;
|
||||
static const uint32_t DESCRIPTOR_POOL_SIZE = 32;
|
||||
static const uint32_t DESCRIPTOR_POOL_SIZE = 1;
|
||||
|
||||
static VkShaderStageFlagBits getStageBit(ShaderStageType type) {
|
||||
switch (type) {
|
||||
@@ -128,8 +128,9 @@ static VkShaderStageFlagBits getStageBit(ShaderStageType type) {
|
||||
return VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
case SHADERSTAGE_COMPUTE:
|
||||
return VK_SHADER_STAGE_COMPUTE_BIT;
|
||||
default:
|
||||
throw love::Exception("invalid type");
|
||||
}
|
||||
throw love::Exception("invalid type");
|
||||
}
|
||||
|
||||
static EShLanguage getGlslShaderType(ShaderStageType stage) {
|
||||
@@ -170,7 +171,7 @@ bool Shader::loadVolatile() {
|
||||
}
|
||||
|
||||
void Shader::unloadVolatile() {
|
||||
if (shaderModules.size() == 0) {
|
||||
if (shaderModules.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -250,7 +251,7 @@ void Shader::cmdPushDescriptorSets(VkCommandBuffer commandBuffer, uint32_t frame
|
||||
}
|
||||
}
|
||||
|
||||
if (currentUsedDescriptorSetsCount >= descriptorSetsVector.at(currentFrame).size()) {
|
||||
if (currentUsedDescriptorSetsCount >= static_cast<uint32_t>(descriptorSetsVector.at(currentFrame).size())) {
|
||||
descriptorSetsVector.at(currentFrame).push_back(allocateDescriptorSet());
|
||||
}
|
||||
|
||||
@@ -298,8 +299,6 @@ void Shader::cmdPushDescriptorSets(VkCommandBuffer commandBuffer, uint32_t frame
|
||||
write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
write.descriptorCount = 1;
|
||||
|
||||
uint32_t index = static_cast<uint32_t>(imageInfos.size());
|
||||
|
||||
VkDescriptorImageInfo* imageInfo = createDescriptorImageInfo(val.textures[0]); // fixme: arrays
|
||||
imageInfos.push_back(imageInfo);
|
||||
|
||||
@@ -736,7 +735,8 @@ VkDescriptorSet Shader::allocateDescriptorSet() {
|
||||
allocInfo.pSetLayouts = &descriptorSetLayout;
|
||||
|
||||
VkDescriptorSet descriptorSet;
|
||||
if (vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet) != VK_SUCCESS) {
|
||||
VkResult result = vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet);
|
||||
if (result != VK_SUCCESS) {
|
||||
throw love::Exception("failed to allocate descriptor set");
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <graphics/vulkan/ShaderStage.h>
|
||||
#include "Vulkan.h"
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "VulkanWrapper.h"
|
||||
#include "libraries/spirv_cross/spirv_reflect.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "graphics/ShaderStage.h"
|
||||
#include "modules/graphics/Graphics.h"
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "VulkanWrapper.h"
|
||||
|
||||
namespace love {
|
||||
namespace graphics {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include "graphics/Volatile.h"
|
||||
#include "modules/graphics/StreamBuffer.h"
|
||||
#include "vulkan/vulkan.h"
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
#include "VulkanWrapper.h"
|
||||
#include "vk_mem_alloc.h"
|
||||
|
||||
namespace love {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "graphics/Texture.h"
|
||||
#include "graphics/Volatile.h"
|
||||
|
||||
#include "VulkanWrapper.h"
|
||||
#include "vk_mem_alloc.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define LOVE_GRAPHICS_VULKAN_VULKAN_H
|
||||
|
||||
#include "graphics/Graphics.h"
|
||||
#include "vulkan/vulkan.h"
|
||||
#include "VulkanWrapper.h"
|
||||
|
||||
namespace love {
|
||||
namespace graphics {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef LOVE_GRAPHICS_VULKAN_VULKANWRAPPER_H
|
||||
#define LOVE_GRAPHICS_VULKAN_VULKANWRAPPER_H
|
||||
|
||||
#include "common/config.h"
|
||||
|
||||
#ifdef LOVE_ANDROID
|
||||
#include "volk.h"
|
||||
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
|
||||
#else
|
||||
#include <vulkan/vulkan.h>
|
||||
#endif
|
||||
|
||||
#endif //LOVE_GRAPHICS_VULKAN_VULKANWRAPPER_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user