Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
WinteryFox committed Dec 4, 2023
2 parents 5fa1de3 + 591d5cf commit 4508afd
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 91 deletions.
11 changes: 3 additions & 8 deletions src/engine/Vixen.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
#pragma once

#include <string>
#include <utility>
#include <glm/vec3.hpp>

#include "Renderer.h"
#include "Window.h"

namespace Vixen {
class Vixen {
protected:
std::shared_ptr<Renderer> renderer;

public:
const std::string appTitle;

const glm::vec3 appVersion;

Vixen(std::string appTitle, glm::vec3 appVersion)
: appTitle(std::move(appTitle)), appVersion(appVersion) {}
Vixen(std::string appTitle, const glm::vec3 appVersion)
: appTitle(std::move(appTitle)), appVersion(appVersion) {}
};
}
2 changes: 1 addition & 1 deletion src/engine/vk/VkBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace Vixen::Vk {
size_t destinationOffset
) {
device->getTransferCommandPool()
->allocateCommandBuffer(VkCommandBuffer::Level::PRIMARY)
->allocate(VkCommandBuffer::Level::PRIMARY)
.record(
VkCommandBuffer::Usage::SINGLE,
[this, &destination, &destinationOffset](auto commandBuffer) {
Expand Down
105 changes: 61 additions & 44 deletions src/engine/vk/VkCommandPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,114 @@

namespace Vixen::Vk {
VkCommandPool::VkCommandPool(
::VkDevice device,
uint32_t queueFamilyIndex,
Usage usage,
bool createReset
::VkDevice device,
const uint32_t queueFamilyIndex,
const Usage usage,
const bool createReset
) : device(device),
commandPool(VK_NULL_HANDLE) {
VkCommandPoolCreateFlags flags;
VkCommandPoolCreateFlags flags = 0;

switch (usage) {
case Usage::GRAPHICS:
flags = 0;
break;
case Usage::TRANSIENT:
flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
break;
case Usage::GRAPHICS:
break;
case Usage::TRANSIENT:
flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
break;
}

if (createReset)
flags |= VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;

VkCommandPoolCreateInfo info{
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.flags = flags,
.queueFamilyIndex = queueFamilyIndex
const VkCommandPoolCreateInfo info{
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.pNext = nullptr,
.flags = flags,
.queueFamilyIndex = queueFamilyIndex
};

checkVulkanResult(
vkCreateCommandPool(device, &info, nullptr, &commandPool),
"Failed to create command pool"
vkCreateCommandPool(device, &info, nullptr, &commandPool),
"Failed to create command pool"
);
}

VkCommandPool::VkCommandPool(VkCommandPool&& other) noexcept
: device(other.device),
commandPool(other.commandPool) {}

VkCommandPool const& VkCommandPool::operator=(VkCommandPool&& other) noexcept {
std::swap(device, other.device);
std::swap(commandPool, other.commandPool);

return *this;
}

VkCommandPool::~VkCommandPool() {
vkDestroyCommandPool(device, commandPool, nullptr);
}

std::vector<::VkCommandBuffer>
VkCommandPool::allocateCommandBuffers(
::VkDevice device,
::VkCommandPool commandPool,
VkCommandBufferLevel level,
uint32_t count
std::vector<::VkCommandBuffer> VkCommandPool::allocateCommandBuffers(
::VkDevice device,
::VkCommandPool commandPool,
const VkCommandBufferLevel level,
const uint32_t count
) {
std::vector<::VkCommandBuffer> commandBuffers{count};

VkCommandBufferAllocateInfo info{
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.commandPool = commandPool,
.level = level,
.commandBufferCount = count
const VkCommandBufferAllocateInfo info{
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.commandPool = commandPool,
.level = level,
.commandBufferCount = count
};

checkVulkanResult(
vkAllocateCommandBuffers(device, &info, commandBuffers.data()),
"Failed to create command buffers"
vkAllocateCommandBuffers(device, &info, commandBuffers.data()),
"Failed to create command buffers"
);

return commandBuffers;
}

std::vector<VkCommandBuffer>
VkCommandPool::allocateCommandBuffers(VkCommandBuffer::Level level, uint32_t count) {
VkCommandPool::allocate(VkCommandBuffer::Level level, const uint32_t count) {
if (count == 0)
throw std::runtime_error("Must allocate at least one command buffer");

auto b = allocateCommandBuffers(
device,
commandPool,
static_cast<VkCommandBufferLevel>(level),
count
const auto b = allocateCommandBuffers(
device,
commandPool,
static_cast<VkCommandBufferLevel>(level),
count
);

std::vector<VkCommandBuffer> buffers;
buffers.reserve(count);

for (auto &buffer: b)
for (auto& buffer : b)
buffers.emplace_back(device, commandPool, buffer);

return buffers;
}

VkCommandBuffer VkCommandPool::allocateCommandBuffer(VkCommandBuffer::Level level) {
VkCommandBuffer VkCommandPool::allocate(VkCommandBuffer::Level level) {
return {
device,
commandPool,
allocateCommandBuffers(
device,
commandPool,
allocateCommandBuffers(
device,
commandPool,
static_cast<VkCommandBufferLevel>(level),
1
)[0]
static_cast<VkCommandBufferLevel>(level),
1
)[0]
};
}

void VkCommandPool::reset() const {
checkVulkanResult(
vkResetCommandPool(device, commandPool, 0),
"Failed to reset command pool"
);
}
}
22 changes: 14 additions & 8 deletions src/engine/vk/VkCommandPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,29 @@ namespace Vixen::Vk {
::VkCommandPool commandPool;

static std::vector<::VkCommandBuffer> allocateCommandBuffers(
::VkDevice device,
::VkCommandPool commandPool,
VkCommandBufferLevel level,
uint32_t count
::VkDevice device,
::VkCommandPool commandPool,
VkCommandBufferLevel level,
uint32_t count
);

public:
VkCommandPool(::VkDevice device, uint32_t queueFamilyIndex, Usage usage, bool createReset);

VkCommandPool(const VkCommandPool &) = delete;
VkCommandPool(const VkCommandPool&) = delete;

VkCommandPool &operator=(const VkCommandPool &) = delete;
VkCommandPool& operator=(const VkCommandPool&) = delete;

VkCommandPool(VkCommandPool&& other) noexcept;

VkCommandPool const& operator=(VkCommandPool&& other) noexcept;

~VkCommandPool();

std::vector<VkCommandBuffer> allocateCommandBuffers(VkCommandBuffer::Level level, uint32_t count);
std::vector<VkCommandBuffer> allocate(VkCommandBuffer::Level level, uint32_t count);

VkCommandBuffer allocate(VkCommandBuffer::Level level);

VkCommandBuffer allocateCommandBuffer(VkCommandBuffer::Level level);
void reset() const;
};
}
3 changes: 2 additions & 1 deletion src/engine/vk/VkFramebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace Vixen::Vk {
VK_SAMPLE_COUNT_1_BIT,
format,
VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
1
)
);

Expand Down
Loading

0 comments on commit 4508afd

Please sign in to comment.