mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
vulkan: fix c++11 compatibility
This commit is contained in:
@@ -1562,7 +1562,10 @@ void Graphics::createLogicalDevice()
|
|||||||
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
|
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
|
||||||
|
|
||||||
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
|
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
|
||||||
std::set<uint32_t> uniqueQueueFamilies = { indices.graphicsFamily.value(), indices.presentFamily.value()};
|
std::set<uint32_t> uniqueQueueFamilies = {
|
||||||
|
indices.graphicsFamily.value,
|
||||||
|
indices.presentFamily.value
|
||||||
|
};
|
||||||
|
|
||||||
float queuePriority = 1.0f;
|
float queuePriority = 1.0f;
|
||||||
for (uint32_t queueFamily : uniqueQueueFamilies)
|
for (uint32_t queueFamily : uniqueQueueFamilies)
|
||||||
@@ -1661,8 +1664,8 @@ void Graphics::createLogicalDevice()
|
|||||||
|
|
||||||
volkLoadDevice(device);
|
volkLoadDevice(device);
|
||||||
|
|
||||||
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()
|
||||||
@@ -1813,9 +1816,9 @@ void Graphics::createSwapChain()
|
|||||||
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||||
|
|
||||||
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
|
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
|
||||||
uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() };
|
uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value, indices.presentFamily.value };
|
||||||
|
|
||||||
if (indices.graphicsFamily != indices.presentFamily)
|
if (indices.graphicsFamily.value != indices.presentFamily.value)
|
||||||
{
|
{
|
||||||
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||||
createInfo.queueFamilyIndexCount = 2;
|
createInfo.queueFamilyIndexCount = 2;
|
||||||
@@ -1885,6 +1888,17 @@ VkPresentModeKHR Graphics::chooseSwapPresentMode(const std::vector<VkPresentMode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t clampuint32_t(uint32_t value, uint32_t min, uint32_t max)
|
||||||
|
{
|
||||||
|
if (value < min)
|
||||||
|
return min;
|
||||||
|
|
||||||
|
if (value > max)
|
||||||
|
return max;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities)
|
VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities)
|
||||||
{
|
{
|
||||||
if (capabilities.currentExtent.width != UINT32_MAX)
|
if (capabilities.currentExtent.width != UINT32_MAX)
|
||||||
@@ -1902,8 +1916,8 @@ VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabiliti
|
|||||||
static_cast<uint32_t>(height)
|
static_cast<uint32_t>(height)
|
||||||
};
|
};
|
||||||
|
|
||||||
actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
actualExtent.width = clampuint32_t(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
||||||
actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
|
actualExtent.height = clampuint32_t(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
|
||||||
|
|
||||||
return actualExtent;
|
return actualExtent;
|
||||||
}
|
}
|
||||||
@@ -2897,7 +2911,7 @@ void Graphics::createCommandPool()
|
|||||||
|
|
||||||
VkCommandPoolCreateInfo poolInfo{};
|
VkCommandPoolCreateInfo poolInfo{};
|
||||||
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||||
poolInfo.queueFamilyIndex = queueFamilyIndices.graphicsFamily.value();
|
poolInfo.queueFamilyIndex = queueFamilyIndices.graphicsFamily.value;
|
||||||
poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
|
poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
|
||||||
|
|
||||||
if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPool) != VK_SUCCESS)
|
if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPool) != VK_SUCCESS)
|
||||||
@@ -2971,12 +2985,12 @@ void Graphics::cleanup()
|
|||||||
vkDestroySampler(device, p.second, nullptr);
|
vkDestroySampler(device, p.second, nullptr);
|
||||||
samplers.clear();
|
samplers.clear();
|
||||||
|
|
||||||
for (const auto &[key, val] : renderPasses)
|
for (const auto &entry : renderPasses)
|
||||||
vkDestroyRenderPass(device, val, nullptr);
|
vkDestroyRenderPass(device, entry.second, nullptr);
|
||||||
renderPasses.clear();
|
renderPasses.clear();
|
||||||
|
|
||||||
for (const auto &[key, val] : framebuffers)
|
for (const auto &entry : framebuffers)
|
||||||
vkDestroyFramebuffer(device, val, nullptr);
|
vkDestroyFramebuffer(device, entry.second, nullptr);
|
||||||
framebuffers.clear();
|
framebuffers.clear();
|
||||||
|
|
||||||
for (auto const &p : graphicsPipelines)
|
for (auto const &p : graphicsPipelines)
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
#include "libraries/xxHash/xxhash.h"
|
#include "libraries/xxHash/xxhash.h"
|
||||||
|
|
||||||
// c++
|
// c++
|
||||||
#include <optional>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -220,12 +219,12 @@ struct BatchedDrawBuffers
|
|||||||
|
|
||||||
struct QueueFamilyIndices
|
struct QueueFamilyIndices
|
||||||
{
|
{
|
||||||
std::optional<uint32_t> graphicsFamily;
|
Optional<uint32_t> graphicsFamily;
|
||||||
std::optional<uint32_t> presentFamily;
|
Optional<uint32_t> presentFamily;
|
||||||
|
|
||||||
bool isComplete() const
|
bool isComplete() const
|
||||||
{
|
{
|
||||||
return graphicsFamily.has_value() && presentFamily.has_value();
|
return graphicsFamily.hasValue && presentFamily.hasValue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -329,10 +329,10 @@ void Shader::cmdPushDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBind
|
|||||||
currentUsedUniformStreamBuffersCount = 0;
|
currentUsedUniformStreamBuffersCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (builtinUniformDataOffset.has_value())
|
if (builtinUniformDataOffset.hasValue)
|
||||||
{
|
{
|
||||||
auto builtinData = vgfx->getCurrentBuiltinUniformData();
|
auto builtinData = vgfx->getCurrentBuiltinUniformData();
|
||||||
auto dst = localUniformData.data() + builtinUniformDataOffset.value();
|
auto dst = localUniformData.data() + builtinUniformDataOffset.value;
|
||||||
memcpy(dst, &builtinData, sizeof(builtinData));
|
memcpy(dst, &builtinData, sizeof(builtinData));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,9 +583,9 @@ void Shader::calculateUniformBufferSizeAligned()
|
|||||||
|
|
||||||
void Shader::initDescriptorSet()
|
void Shader::initDescriptorSet()
|
||||||
{
|
{
|
||||||
for (const auto &[key, val] : uniformInfos)
|
for (const auto &entry : uniformInfos)
|
||||||
if (Vulkan::getDescriptorType(val.baseType) != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
|
if (Vulkan::getDescriptorType(entry.second.baseType) != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
|
||||||
updateUniform(&val, val.count, true);
|
updateUniform(&entry.second, entry.second.count, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::buildLocalUniforms(spirv_cross::Compiler &comp, const spirv_cross::SPIRType &type, size_t baseoff, const std::string &basename)
|
void Shader::buildLocalUniforms(spirv_cross::Compiler &comp, const spirv_cross::SPIRType &type, size_t baseoff, const std::string &basename)
|
||||||
@@ -951,16 +951,16 @@ void Shader::createDescriptorSetLayout()
|
|||||||
else
|
else
|
||||||
stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
|
||||||
for (auto const &[key, val] : uniformInfos)
|
for (auto const &entry : uniformInfos)
|
||||||
{
|
{
|
||||||
auto type = Vulkan::getDescriptorType(val.baseType);
|
auto type = Vulkan::getDescriptorType(entry.second.baseType);
|
||||||
if (type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
|
if (type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
|
||||||
{
|
{
|
||||||
VkDescriptorSetLayoutBinding layoutBinding{};
|
VkDescriptorSetLayoutBinding layoutBinding{};
|
||||||
|
|
||||||
layoutBinding.binding = val.location;
|
layoutBinding.binding = entry.second.location;
|
||||||
layoutBinding.descriptorType = type;
|
layoutBinding.descriptorType = type;
|
||||||
layoutBinding.descriptorCount = val.count;
|
layoutBinding.descriptorCount = entry.second.count;
|
||||||
layoutBinding.stageFlags = stageFlags;
|
layoutBinding.stageFlags = stageFlags;
|
||||||
|
|
||||||
bindings.push_back(layoutBinding);
|
bindings.push_back(layoutBinding);
|
||||||
@@ -1022,10 +1022,10 @@ void Shader::createDescriptorPoolSizes()
|
|||||||
descriptorPoolSizes.push_back(size);
|
descriptorPoolSizes.push_back(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &[key, val] : uniformInfos)
|
for (const auto &entry : uniformInfos)
|
||||||
{
|
{
|
||||||
VkDescriptorPoolSize size{};
|
VkDescriptorPoolSize size{};
|
||||||
auto type = Vulkan::getDescriptorType(val.baseType);
|
auto type = Vulkan::getDescriptorType(entry.second.baseType);
|
||||||
if (type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
|
if (type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1055,7 +1055,7 @@ void Shader::setVideoTextures(graphics::Texture *ytexture, graphics::Texture *cb
|
|||||||
BUILTIN_TEXTURE_VIDEO_CR,
|
BUILTIN_TEXTURE_VIDEO_CR,
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(textures.size() == builtIns.size());
|
static_assert(textures.size() == builtIns.size(), "expected number of textures to be the same");
|
||||||
|
|
||||||
for (size_t i = 0; i < textures.size(); i++)
|
for (size_t i = 0; i < textures.size(); i++)
|
||||||
if (builtinUniformInfo[builtIns[i]] != nullptr)
|
if (builtinUniformInfo[builtIns[i]] != nullptr)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// LÖVE
|
// LÖVE
|
||||||
|
#include "common/Optional.h"
|
||||||
#include "graphics/Shader.h"
|
#include "graphics/Shader.h"
|
||||||
#include "graphics/vulkan/ShaderStage.h"
|
#include "graphics/vulkan/ShaderStage.h"
|
||||||
#include "Vulkan.h"
|
#include "Vulkan.h"
|
||||||
@@ -34,7 +35,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
@@ -137,7 +137,7 @@ private:
|
|||||||
std::vector<uint8> localUniformData;
|
std::vector<uint8> localUniformData;
|
||||||
std::vector<uint8> localUniformStagingData;
|
std::vector<uint8> localUniformStagingData;
|
||||||
uint32_t uniformLocation;
|
uint32_t uniformLocation;
|
||||||
std::optional<size_t> builtinUniformDataOffset;
|
OptionalInt builtinUniformDataOffset;
|
||||||
|
|
||||||
std::unordered_map<std::string, int> attributes;
|
std::unordered_map<std::string, int> attributes;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user