mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
vulkan: fix c++11 compatibility
This commit is contained in:
@@ -1562,7 +1562,10 @@ void Graphics::createLogicalDevice()
|
||||
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
|
||||
|
||||
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;
|
||||
for (uint32_t queueFamily : uniqueQueueFamilies)
|
||||
@@ -1661,8 +1664,8 @@ void Graphics::createLogicalDevice()
|
||||
|
||||
volkLoadDevice(device);
|
||||
|
||||
vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);
|
||||
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);
|
||||
vkGetDeviceQueue(device, indices.graphicsFamily.value, 0, &graphicsQueue);
|
||||
vkGetDeviceQueue(device, indices.presentFamily.value, 0, &presentQueue);
|
||||
}
|
||||
|
||||
void Graphics::initVMA()
|
||||
@@ -1813,9 +1816,9 @@ void Graphics::createSwapChain()
|
||||
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
|
||||
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.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)
|
||||
{
|
||||
if (capabilities.currentExtent.width != UINT32_MAX)
|
||||
@@ -1902,8 +1916,8 @@ VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabiliti
|
||||
static_cast<uint32_t>(height)
|
||||
};
|
||||
|
||||
actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
||||
actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
|
||||
actualExtent.width = clampuint32_t(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
||||
actualExtent.height = clampuint32_t(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
|
||||
|
||||
return actualExtent;
|
||||
}
|
||||
@@ -2897,7 +2911,7 @@ void Graphics::createCommandPool()
|
||||
|
||||
VkCommandPoolCreateInfo poolInfo{};
|
||||
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;
|
||||
|
||||
if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPool) != VK_SUCCESS)
|
||||
@@ -2971,12 +2985,12 @@ void Graphics::cleanup()
|
||||
vkDestroySampler(device, p.second, nullptr);
|
||||
samplers.clear();
|
||||
|
||||
for (const auto &[key, val] : renderPasses)
|
||||
vkDestroyRenderPass(device, val, nullptr);
|
||||
for (const auto &entry : renderPasses)
|
||||
vkDestroyRenderPass(device, entry.second, nullptr);
|
||||
renderPasses.clear();
|
||||
|
||||
for (const auto &[key, val] : framebuffers)
|
||||
vkDestroyFramebuffer(device, val, nullptr);
|
||||
for (const auto &entry : framebuffers)
|
||||
vkDestroyFramebuffer(device, entry.second, nullptr);
|
||||
framebuffers.clear();
|
||||
|
||||
for (auto const &p : graphicsPipelines)
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "libraries/xxHash/xxhash.h"
|
||||
|
||||
// c++
|
||||
#include <optional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
@@ -220,12 +219,12 @@ struct BatchedDrawBuffers
|
||||
|
||||
struct QueueFamilyIndices
|
||||
{
|
||||
std::optional<uint32_t> graphicsFamily;
|
||||
std::optional<uint32_t> presentFamily;
|
||||
Optional<uint32_t> graphicsFamily;
|
||||
Optional<uint32_t> presentFamily;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (builtinUniformDataOffset.has_value())
|
||||
if (builtinUniformDataOffset.hasValue)
|
||||
{
|
||||
auto builtinData = vgfx->getCurrentBuiltinUniformData();
|
||||
auto dst = localUniformData.data() + builtinUniformDataOffset.value();
|
||||
auto dst = localUniformData.data() + builtinUniformDataOffset.value;
|
||||
memcpy(dst, &builtinData, sizeof(builtinData));
|
||||
}
|
||||
|
||||
@@ -583,9 +583,9 @@ void Shader::calculateUniformBufferSizeAligned()
|
||||
|
||||
void Shader::initDescriptorSet()
|
||||
{
|
||||
for (const auto &[key, val] : uniformInfos)
|
||||
if (Vulkan::getDescriptorType(val.baseType) != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
|
||||
updateUniform(&val, val.count, true);
|
||||
for (const auto &entry : uniformInfos)
|
||||
if (Vulkan::getDescriptorType(entry.second.baseType) != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
|
||||
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)
|
||||
@@ -951,16 +951,16 @@ void Shader::createDescriptorSetLayout()
|
||||
else
|
||||
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)
|
||||
{
|
||||
VkDescriptorSetLayoutBinding layoutBinding{};
|
||||
|
||||
layoutBinding.binding = val.location;
|
||||
layoutBinding.binding = entry.second.location;
|
||||
layoutBinding.descriptorType = type;
|
||||
layoutBinding.descriptorCount = val.count;
|
||||
layoutBinding.descriptorCount = entry.second.count;
|
||||
layoutBinding.stageFlags = stageFlags;
|
||||
|
||||
bindings.push_back(layoutBinding);
|
||||
@@ -1022,10 +1022,10 @@ void Shader::createDescriptorPoolSizes()
|
||||
descriptorPoolSizes.push_back(size);
|
||||
}
|
||||
|
||||
for (const auto &[key, val] : uniformInfos)
|
||||
for (const auto &entry : uniformInfos)
|
||||
{
|
||||
VkDescriptorPoolSize size{};
|
||||
auto type = Vulkan::getDescriptorType(val.baseType);
|
||||
auto type = Vulkan::getDescriptorType(entry.second.baseType);
|
||||
if (type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
|
||||
continue;
|
||||
}
|
||||
@@ -1055,7 +1055,7 @@ void Shader::setVideoTextures(graphics::Texture *ytexture, graphics::Texture *cb
|
||||
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++)
|
||||
if (builtinUniformInfo[builtIns[i]] != nullptr)
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
// LÖVE
|
||||
#include "common/Optional.h"
|
||||
#include "graphics/Shader.h"
|
||||
#include "graphics/vulkan/ShaderStage.h"
|
||||
#include "Vulkan.h"
|
||||
@@ -34,7 +35,6 @@
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <queue>
|
||||
#include <optional>
|
||||
|
||||
|
||||
namespace love
|
||||
@@ -137,7 +137,7 @@ private:
|
||||
std::vector<uint8> localUniformData;
|
||||
std::vector<uint8> localUniformStagingData;
|
||||
uint32_t uniformLocation;
|
||||
std::optional<size_t> builtinUniformDataOffset;
|
||||
OptionalInt builtinUniformDataOffset;
|
||||
|
||||
std::unordered_map<std::string, int> attributes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user