-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Descriptor Set API seems to be working
Rewrote the descriptor set api to allow for a more module way of declaing it. Will create a seperate uniform buffer class that will be passed seperatly to the renderer for rendering (I think)
- Loading branch information
1 parent
8481548
commit 4adae37
Showing
9 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "Arcane/Core/Application.h" | ||
#include "VulkanContext.h" | ||
#include "VulkanSet.h" | ||
|
||
namespace Arcane | ||
{ | ||
VulkanSet::VulkanSet(DescriptorSetSpecs& specs, std::initializer_list<DescriptorLayoutSpecs> layoutSpecs) | ||
{ | ||
Application& app = Application::Get(); | ||
VulkanContext* context = static_cast<VulkanContext*>(Application::Get().GetWindow().GetContext()); | ||
VulkanSwapChain& swapchain = context->GetSwapChain(); | ||
VkDevice logicalDevice = static_cast<VulkanContext*>(app.GetWindow().GetContext())->GetDevice().GetLogicalDevice(); | ||
|
||
// Iterate through Layouts, create bindings for each | ||
// Manage the counts of each set | ||
std::vector<VkDescriptorSetLayoutBinding> bindings; | ||
for (DescriptorLayoutSpecs spec : layoutSpecs) { | ||
VkDescriptorSetLayoutBinding binding{}; | ||
binding.binding = spec.Binding; | ||
binding.descriptorCount = spec.DescriptorCount; | ||
|
||
// Switch on the type | ||
switch (spec.Type) | ||
{ | ||
case DescriptorType::UNIFORM_BUFFER: | ||
binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; | ||
break; | ||
case DescriptorType::SAMPLER: | ||
binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
bindings.push_back(binding); | ||
} | ||
|
||
// Actually Create Descriptor set | ||
VkDescriptorSetLayoutCreateInfo setInfo = {}; | ||
setInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; | ||
setInfo.pNext = nullptr; | ||
setInfo.bindingCount = static_cast<uint32_t>(bindings.size()); | ||
setInfo.pBindings = bindings.data(); | ||
|
||
if (vkCreateDescriptorSetLayout(logicalDevice, &setInfo, nullptr, &m_DescriptorSetLayout) != VK_SUCCESS) { | ||
printf("Uniform Descriptor Layout Not Created\n"); | ||
} | ||
|
||
// Get Descriptor Pool from context | ||
VkDescriptorPool descriptorPool = context->GetPool(); | ||
uint32_t imageCount = swapchain.GetSwapChainImagesSize(); | ||
m_DescriptorSets.resize(imageCount); | ||
for (int i = 0; i < imageCount; i++) { | ||
VkDescriptorSetAllocateInfo allocInfo = {}; | ||
allocInfo.pNext = nullptr; | ||
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; | ||
allocInfo.descriptorPool = descriptorPool; | ||
allocInfo.descriptorSetCount = 1; | ||
allocInfo.pSetLayouts = &m_DescriptorSetLayout; | ||
|
||
if (vkAllocateDescriptorSets(logicalDevice, &allocInfo, &m_DescriptorSets[i]) != VK_SUCCESS) { | ||
printf("Failed to allocate descripor set\n"); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <vulkan/vulkan.h> | ||
#include "Arcane/Renderer/DescriptorSet.h" | ||
|
||
namespace Arcane | ||
{ | ||
class VulkanSet : public DescriptorSet | ||
{ | ||
public: | ||
VulkanSet(DescriptorSetSpecs& specs, std::initializer_list<DescriptorLayoutSpecs> layoutSpecs); | ||
|
||
private: | ||
VkDescriptorSetLayout m_DescriptorSetLayout = VK_NULL_HANDLE; | ||
std::vector<VkDescriptorSet> m_DescriptorSets; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "DescriptorSet.h" | ||
#include "RendererAPI.h" | ||
|
||
#if defined(ARCANE_WIN32) | ||
#include "Arcane/Platform/Vulkan/VulkanSet.h" | ||
#endif | ||
|
||
namespace Arcane | ||
{ | ||
DescriptorSet* DescriptorSet::Create(DescriptorSetSpecs& setSpecs, std::initializer_list<DescriptorLayoutSpecs> layoutSpecs) | ||
{ | ||
switch (RendererAPI::Current()) | ||
{ | ||
case RendererAPIType::Vulkan: return new VulkanSet(setSpecs, layoutSpecs); | ||
default: return nullptr; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <initializer_list> | ||
|
||
namespace Arcane | ||
{ | ||
enum class DescriptorType | ||
{ | ||
UNIFORM_BUFFER, | ||
SAMPLER | ||
}; | ||
|
||
struct DescriptorSetSpecs | ||
{ | ||
uint32_t SetNumber; | ||
}; | ||
|
||
struct DescriptorLayoutSpecs | ||
{ | ||
uint32_t Binding; | ||
uint32_t DescriptorCount; | ||
DescriptorType Type; | ||
std::string Name; | ||
}; | ||
|
||
class DescriptorSet | ||
{ | ||
public: | ||
static DescriptorSet* Create(DescriptorSetSpecs& setSpecs, std::initializer_list<DescriptorLayoutSpecs> layoutSpecs); | ||
private: | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters