mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
vulkan: fix android build
It compiles now, but it's not working correctly yet
This commit is contained in:
+7
-1
@@ -613,7 +613,13 @@ set(LOVE_SRC_MODULE_GRAPHICS_VULKAN
|
|||||||
src/modules/graphics/vulkan/Vulkan.cpp
|
src/modules/graphics/vulkan/Vulkan.cpp
|
||||||
src/modules/graphics/vulkan/vk_mem_alloc.h
|
src/modules/graphics/vulkan/vk_mem_alloc.h
|
||||||
src/modules/graphics/vulkan/UseVMA.cpp
|
src/modules/graphics/vulkan/UseVMA.cpp
|
||||||
)
|
src/modules/graphics/vulkan/VulkanWrapper.h)
|
||||||
|
|
||||||
|
if(ANDROID)
|
||||||
|
set(LOVE_SRC_MODULE_GRAPHICS_VULKAN ${LOVE_SRC_MODULE_GRAPHICS_VULKAN}
|
||||||
|
src/modules/graphics/vulkan/volk.h
|
||||||
|
src/modules/graphics/vulkan/volk.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(LOVE_SRC_MODULE_GRAPHICS
|
set(LOVE_SRC_MODULE_GRAPHICS
|
||||||
${LOVE_SRC_MODULE_GRAPHICS_ROOT}
|
${LOVE_SRC_MODULE_GRAPHICS_ROOT}
|
||||||
|
|||||||
+1
-1
@@ -128,7 +128,7 @@
|
|||||||
|
|
||||||
// fixme: vulkan graphics only tested on windows for now
|
// fixme: vulkan graphics only tested on windows for now
|
||||||
// adjust this later on when testing is successful on other platforms
|
// adjust this later on when testing is successful on other platforms
|
||||||
#if defined(LOVE_WINDOWS) || defined(LOVE_LINUX)
|
#if defined(LOVE_WINDOWS) || defined(LOVE_LINUX) || defined(LOVE_ANDROID)
|
||||||
# define LOVE_GRAPHICS_VULKAN
|
# define LOVE_GRAPHICS_VULKAN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "graphics/Buffer.h"
|
#include "graphics/Buffer.h"
|
||||||
#include "graphics/Volatile.h"
|
#include "graphics/Volatile.h"
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include "VulkanWrapper.h"
|
||||||
#include "vk_mem_alloc.h"
|
#include "vk_mem_alloc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,12 @@ const std::vector<const char*> deviceExtensions = {
|
|||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
constexpr bool enableValidationLayers = false;
|
constexpr bool enableValidationLayers = false;
|
||||||
#else
|
#else
|
||||||
|
#ifdef LOVE_ANDROID
|
||||||
|
constexpr bool enableValidationLayers = false;
|
||||||
|
#else
|
||||||
constexpr bool enableValidationLayers = true;
|
constexpr bool enableValidationLayers = true;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
constexpr int MAX_FRAMES_IN_FLIGHT = 2;
|
constexpr int MAX_FRAMES_IN_FLIGHT = 2;
|
||||||
|
|
||||||
@@ -310,6 +314,7 @@ void Graphics::getAPIStats(int& shaderswitches) const {
|
|||||||
|
|
||||||
void Graphics::unSetMode() {
|
void Graphics::unSetMode() {
|
||||||
created = false;
|
created = false;
|
||||||
|
auto fpn = vkDeviceWaitIdle;
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
Volatile::unloadAll();
|
Volatile::unloadAll();
|
||||||
cleanup();
|
cleanup();
|
||||||
@@ -646,6 +651,10 @@ void Graphics::createVulkanInstance() {
|
|||||||
&instance) != VK_SUCCESS) {
|
&instance) != VK_SUCCESS) {
|
||||||
throw love::Exception("couldn't create vulkan instance");
|
throw love::Exception("couldn't create vulkan instance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LOVE_ANDROID
|
||||||
|
volkLoadInstance(instance);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Graphics::checkValidationSupport() {
|
bool Graphics::checkValidationSupport() {
|
||||||
@@ -847,21 +856,56 @@ void Graphics::createLogicalDevice() {
|
|||||||
throw love::Exception("failed to create logical device");
|
throw love::Exception("failed to create logical device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LOVE_ANDROID
|
||||||
|
volkLoadDevice(device);
|
||||||
|
#endif
|
||||||
|
|
||||||
vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);
|
vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);
|
||||||
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);
|
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::initVMA() {
|
void Graphics::initVMA() {
|
||||||
VmaVulkanFunctions vulkanFunctions = {};
|
|
||||||
vulkanFunctions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr;
|
|
||||||
vulkanFunctions.vkGetDeviceProcAddr = &vkGetDeviceProcAddr;
|
|
||||||
|
|
||||||
VmaAllocatorCreateInfo allocatorCreateInfo = {};
|
VmaAllocatorCreateInfo allocatorCreateInfo = {};
|
||||||
allocatorCreateInfo.vulkanApiVersion = vulkanApiVersion;
|
allocatorCreateInfo.vulkanApiVersion = vulkanApiVersion;
|
||||||
allocatorCreateInfo.physicalDevice = physicalDevice;
|
allocatorCreateInfo.physicalDevice = physicalDevice;
|
||||||
allocatorCreateInfo.device = device;
|
allocatorCreateInfo.device = device;
|
||||||
allocatorCreateInfo.instance = instance;
|
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;
|
allocatorCreateInfo.pVulkanFunctions = &vulkanFunctions;
|
||||||
|
#else
|
||||||
|
allocatorCreateInfo.pVulkanFunctions = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (vmaCreateAllocator(&allocatorCreateInfo, &vmaAllocator) != VK_SUCCESS) {
|
if (vmaCreateAllocator(&allocatorCreateInfo, &vmaAllocator) != VK_SUCCESS) {
|
||||||
throw love::Exception("failed to create vma allocator");
|
throw love::Exception("failed to create vma allocator");
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
|
|
||||||
// libraries
|
// libraries
|
||||||
#include <vulkan/vulkan.h>
|
#include "VulkanWrapper.h"
|
||||||
#include "vk_mem_alloc.h"
|
#include "vk_mem_alloc.h"
|
||||||
#include "libraries/xxHash/xxhash.h"
|
#include "libraries/xxHash/xxhash.h"
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
|
||||||
namespace love {
|
namespace love {
|
||||||
@@ -121,7 +122,14 @@ struct SwapChainSupportDetails {
|
|||||||
|
|
||||||
class Graphics final : public love::graphics::Graphics {
|
class Graphics final : public love::graphics::Graphics {
|
||||||
public:
|
public:
|
||||||
Graphics() = default;
|
Graphics() {
|
||||||
|
#ifdef LOVE_ANDROID
|
||||||
|
auto result = volkInitialize();
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
throw love::Exception("could not initialize volk");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~Graphics();
|
virtual ~Graphics();
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ static const TBuiltInResource defaultTBuiltInResource = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t STREAMBUFFER_DEFAULT_SIZE = 16;
|
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) {
|
static VkShaderStageFlagBits getStageBit(ShaderStageType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -128,8 +128,9 @@ static VkShaderStageFlagBits getStageBit(ShaderStageType type) {
|
|||||||
return VK_SHADER_STAGE_FRAGMENT_BIT;
|
return VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
case SHADERSTAGE_COMPUTE:
|
case SHADERSTAGE_COMPUTE:
|
||||||
return VK_SHADER_STAGE_COMPUTE_BIT;
|
return VK_SHADER_STAGE_COMPUTE_BIT;
|
||||||
|
default:
|
||||||
|
throw love::Exception("invalid type");
|
||||||
}
|
}
|
||||||
throw love::Exception("invalid type");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static EShLanguage getGlslShaderType(ShaderStageType stage) {
|
static EShLanguage getGlslShaderType(ShaderStageType stage) {
|
||||||
@@ -170,7 +171,7 @@ bool Shader::loadVolatile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Shader::unloadVolatile() {
|
void Shader::unloadVolatile() {
|
||||||
if (shaderModules.size() == 0) {
|
if (shaderModules.empty()) {
|
||||||
return;
|
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());
|
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.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
write.descriptorCount = 1;
|
write.descriptorCount = 1;
|
||||||
|
|
||||||
uint32_t index = static_cast<uint32_t>(imageInfos.size());
|
|
||||||
|
|
||||||
VkDescriptorImageInfo* imageInfo = createDescriptorImageInfo(val.textures[0]); // fixme: arrays
|
VkDescriptorImageInfo* imageInfo = createDescriptorImageInfo(val.textures[0]); // fixme: arrays
|
||||||
imageInfos.push_back(imageInfo);
|
imageInfos.push_back(imageInfo);
|
||||||
|
|
||||||
@@ -736,7 +735,8 @@ VkDescriptorSet Shader::allocateDescriptorSet() {
|
|||||||
allocInfo.pSetLayouts = &descriptorSetLayout;
|
allocInfo.pSetLayouts = &descriptorSetLayout;
|
||||||
|
|
||||||
VkDescriptorSet descriptorSet;
|
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");
|
throw love::Exception("failed to allocate descriptor set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <graphics/vulkan/ShaderStage.h>
|
#include <graphics/vulkan/ShaderStage.h>
|
||||||
#include "Vulkan.h"
|
#include "Vulkan.h"
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include "VulkanWrapper.h"
|
||||||
#include "libraries/spirv_cross/spirv_reflect.hpp"
|
#include "libraries/spirv_cross/spirv_reflect.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "graphics/ShaderStage.h"
|
#include "graphics/ShaderStage.h"
|
||||||
#include "modules/graphics/Graphics.h"
|
#include "modules/graphics/Graphics.h"
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include "VulkanWrapper.h"
|
||||||
|
|
||||||
namespace love {
|
namespace love {
|
||||||
namespace graphics {
|
namespace graphics {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include "graphics/Volatile.h"
|
#include "graphics/Volatile.h"
|
||||||
#include "modules/graphics/StreamBuffer.h"
|
#include "modules/graphics/StreamBuffer.h"
|
||||||
#include "vulkan/vulkan.h"
|
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
|
|
||||||
|
#include "VulkanWrapper.h"
|
||||||
#include "vk_mem_alloc.h"
|
#include "vk_mem_alloc.h"
|
||||||
|
|
||||||
namespace love {
|
namespace love {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "graphics/Texture.h"
|
#include "graphics/Texture.h"
|
||||||
#include "graphics/Volatile.h"
|
#include "graphics/Volatile.h"
|
||||||
|
|
||||||
|
#include "VulkanWrapper.h"
|
||||||
#include "vk_mem_alloc.h"
|
#include "vk_mem_alloc.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define LOVE_GRAPHICS_VULKAN_VULKAN_H
|
#define LOVE_GRAPHICS_VULKAN_VULKAN_H
|
||||||
|
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
#include "vulkan/vulkan.h"
|
#include "VulkanWrapper.h"
|
||||||
|
|
||||||
namespace love {
|
namespace love {
|
||||||
namespace graphics {
|
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