Skip to content

Commit

Permalink
work on descriptor sets
Browse files Browse the repository at this point in the history
  • Loading branch information
WinteryFox committed Nov 19, 2023
1 parent 7e31af7 commit 601d593
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .idea/sonarlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/engine/vk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ add_library(
VkImageView.h
VkSemaphore.cpp
VkSemaphore.h
VkDescriptorPool.cpp
VkDescriptorPool.h
VkDescriptorSetLayout.cpp
VkDescriptorSetLayout.h
)
target_link_libraries(
VkVixen
Expand Down
6 changes: 3 additions & 3 deletions src/engine/vk/VkCommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ namespace Vixen::Vk {
};

private:
::VkDevice device;
VkDevice device;

::VkCommandPool commandPool;
VkCommandPool commandPool;

::VkCommandBuffer commandBuffer;

VkFence fence;

public:
VkCommandBuffer(::VkDevice device, ::VkCommandPool commandPool, ::VkCommandBuffer commandBuffer);
VkCommandBuffer(VkDevice device, VkCommandPool commandPool, ::VkCommandBuffer commandBuffer);

VkCommandBuffer(VkCommandBuffer &) = delete;

Expand Down
28 changes: 28 additions & 0 deletions src/engine/vk/VkDescriptorPool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "VkDescriptorPool.h"

namespace Vixen::Vk {
VkDescriptorPool::VkDescriptorPool(
const std::shared_ptr<Device>& device,
const std::vector<VkDescriptorPoolSize>& sizes,
const uint32_t maxSets
) : device(device),
pool(VK_NULL_HANDLE) {
const VkDescriptorPoolCreateInfo info{
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.maxSets = maxSets,
.poolSizeCount = static_cast<uint32_t>(sizes.size()),
.pPoolSizes = sizes.data()
};

checkVulkanResult(
vkCreateDescriptorPool(device->getDevice(), &info, nullptr, &pool),
"Failed to create descriptor pool"
);
}

VkDescriptorPool::~VkDescriptorPool() {
vkDestroyDescriptorPool(device->getDevice(), pool, nullptr);
}
}
26 changes: 26 additions & 0 deletions src/engine/vk/VkDescriptorPool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "Device.h"

namespace Vixen::Vk {
class VkDescriptorPool {
std::shared_ptr<Device> device;

::VkDescriptorPool pool;

public:
VkDescriptorPool(
const std::shared_ptr<Device>& device,
const std::vector<VkDescriptorPoolSize>& sizes,
uint32_t maxSets
);

VkDescriptorPool(const VkDescriptorPool& other) = delete;

VkDescriptorPool(VkDescriptorPool&& other) noexcept = delete;

VkDescriptorPool& operator=(VkDescriptorPool other) = delete;

~VkDescriptorPool();
};
}
5 changes: 5 additions & 0 deletions src/engine/vk/VkDescriptorSetLayout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "VkDescriptorSetLayout.h"

namespace Vixen::Vk {

}
10 changes: 10 additions & 0 deletions src/engine/vk/VkDescriptorSetLayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "Device.h"

namespace Vixen::Vk {
class VkDescriptorSetLayout {
public:

};
}
62 changes: 42 additions & 20 deletions src/engine/vk/VkShaderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,62 @@

namespace Vixen::Vk {
VkShaderModule::VkShaderModule(
const std::shared_ptr<Device> &device,
Stage stage,
const std::vector<uint32_t> &binary,
const std::vector<Binding> &bindings,
const std::vector<IO> &inputs,
const std::string &entrypoint
const std::shared_ptr<Device>& device,
const Stage stage,
const std::vector<uint32_t>& binary,
const std::vector<Binding>& bindings,
const std::vector<IO>& inputs,
const std::string& entrypoint
) : ShaderModule(stage, entrypoint, bindings, inputs),
device(device),
module(VK_NULL_HANDLE) {
VkShaderModuleCreateInfo info{
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.codeSize = binary.size() * sizeof(uint32_t),
.pCode = binary.data()
const VkShaderModuleCreateInfo info{
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.codeSize = binary.size() * sizeof(uint32_t),
.pCode = binary.data()
};

checkVulkanResult(
vkCreateShaderModule(device->getDevice(), &info, nullptr, &module),
"Failed to create shader module"
vkCreateShaderModule(device->getDevice(), &info, nullptr, &module),
"Failed to create shader module"
);
}

VkShaderModule::~VkShaderModule() {
vkDestroyShaderModule(device->getDevice(), module, nullptr);
}

VkPipelineShaderStageCreateInfo VkShaderModule::createInfo() {
VkPipelineShaderStageCreateInfo VkShaderModule::createInfo() const {
return {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = VK_NULL_HANDLE,
.flags = 0,
.stage = getVulkanShaderStage(getStage()),
.module = module,
.pName = getEntrypoint().c_str(),
.pSpecializationInfo = VK_NULL_HANDLE
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = VK_NULL_HANDLE,
.flags = 0,
.stage = getVulkanShaderStage(getStage()),
.module = module,
.pName = getEntrypoint().c_str(),
.pSpecializationInfo = VK_NULL_HANDLE
};
}

std::vector<VkDescriptorSetLayoutBinding> VkShaderModule::createBindings() const {
const auto& bindings = getBindings();

std::vector<VkDescriptorSetLayoutBinding> b{bindings.size()};
for (const auto& [binding, stride, rate] : bindings) {
const VkShaderStageFlags& stage = getVulkanShaderStage(getStage());

b.push_back(
VkDescriptorSetLayoutBinding{
.binding = binding,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
// TODO: This count value is used for array bindings
.descriptorCount = 1,
.stageFlags = stage,
.pImmutableSamplers = nullptr
}
);
}

return b;
}
}
Loading

0 comments on commit 601d593

Please sign in to comment.