Created global descriptor set layouts

This commit is contained in:
Brandon Mak 2022-09-17 23:32:03 +08:00
parent 3cf22b04a5
commit c1a3a6acf1
4 changed files with 82 additions and 9 deletions

View File

@ -40,7 +40,6 @@ namespace SHADE
SHVkInstance::Init(true, true, true);
// Get Physical Device and Construct Logical Device
// TODO: Provide configuration for these options
physicalDevice = SHVkInstance::CreatePhysicalDevice(SH_PHYSICAL_DEVICE_TYPE::BEST);
device = SHVkInstance::CreateLogicalDevice({ SHQueueParams(SH_Q_FAM::GRAPHICS, SH_QUEUE_SELECT::DEDICATED), SHQueueParams(SH_Q_FAM::TRANSFER, SH_QUEUE_SELECT::DEDICATED) }, physicalDevice);
@ -153,8 +152,10 @@ namespace SHADE
semaHandle = device->CreateSemaphore();
}
ConfigureDefaultVertexInputState();
//pipelineLibrary.Init(device, &defaultVertexInputState, );
pipelineLibrary.Init(device, &defaultVertexInputState, &globalDescSetLayouts);
}
/***************************************************************************/
@ -361,6 +362,79 @@ namespace SHADE
window = wind;
}
void SHGraphicsSystem::ConfigureGlobalDescLayouts(void) noexcept
{
SHVkDescriptorSetLayout::Binding genericDataBinding
{
.Type = vk::DescriptorType::eUniformBufferDynamic,
.Stage = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eCompute,
.BindPoint = 0,
.DescriptorCount = 1,
};
SHVkDescriptorSetLayout::Binding texturesBinding
{
.Type = vk::DescriptorType::eCombinedImageSampler,
.Stage = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eCompute,
.BindPoint = 1,
.DescriptorCount = 2000, // we can have up to 2000 textures for now
.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount,
};
// For global data (generic data and textures)
Handle<SHVkDescriptorSetLayout> staticGlobalLayout = device->CreateDescriptorSetLayout({genericDataBinding, texturesBinding});
SHVkDescriptorSetLayout::Binding lightBinding
{
.Type = vk::DescriptorType::eStorageBufferDynamic,
.Stage = vk::ShaderStageFlagBits::eFragment,
.BindPoint = 0,
.DescriptorCount = 1,
};
// For Dynamic global data (lights)
Handle<SHVkDescriptorSetLayout> dynamicGlobalLayout = device->CreateDescriptorSetLayout({ lightBinding });
SHVkDescriptorSetLayout::Binding cameraDataBinding
{
.Type = vk::DescriptorType::eUniformBufferDynamic,
.Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = 0,
.DescriptorCount = 1,
};
// For High frequency global data (camera)
Handle<SHVkDescriptorSetLayout> cameraDataGlobalLayout = device->CreateDescriptorSetLayout({ cameraDataBinding });
SHVkDescriptorSetLayout::Binding materialDataBinding
{
.Type = vk::DescriptorType::eStorageBufferDynamic,
.Stage = vk::ShaderStageFlagBits::eFragment,
.BindPoint = 0,
.DescriptorCount = 1,
};
// For High frequency global data (camera)
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = device->CreateDescriptorSetLayout({ materialDataBinding });
globalDescSetLayouts.push_back(staticGlobalLayout);
globalDescSetLayouts.push_back(dynamicGlobalLayout);
globalDescSetLayouts.push_back(cameraDataGlobalLayout);
globalDescSetLayouts.push_back(materialDataPerInstanceLayout);
}
void SHGraphicsSystem::ConfigureDefaultVertexInputState(void) noexcept
{
defaultVertexInputState.AddBinding(false, false, {SHVertexAttribute(SHAttribFormat::FLOAT_3D)}); // positions at binding 0

View File

@ -156,7 +156,7 @@ namespace SHADE
SHPipelineLibrary pipelineLibrary;
std::vector<SHVkDescriptorSetLayout> globalDescSetLayouts;
std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts;
// Middle End Resources
ResourceManager resourceManager;
@ -179,6 +179,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/
/* Private member functions */
/*-----------------------------------------------------------------------------*/
void ConfigureGlobalDescLayouts (void) noexcept;
void ConfigureDefaultVertexInputState (void) noexcept;
};
}

View File

@ -5,12 +5,12 @@
namespace SHADE
{
Handle<SHVkPipeline> SHPipelineLibrary::CreateDrawPipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, uint32_t subpass, SHVertexInputState const& vertexInput, std::vector<Handle<SHVkDescriptorSetLayout>> const& globalDescSetLayouts) noexcept
Handle<SHVkPipeline> SHPipelineLibrary::CreateDrawPipeline(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, uint32_t subpass) noexcept
{
SHPipelineLayoutParams params
{
.shaderModules = {vsFsPair.first, vsFsPair.second},
.globalDescSetLayouts = globalDescSetLayouts
.globalDescSetLayouts = *globalDescSetLayouts
};
// Create the pipeline layout
@ -18,7 +18,7 @@ namespace SHADE
// Create the pipeline and configure the default vertex input state
auto newPipeline = logicalDevice->CreatePipeline(pipelineLayout, nullptr, renderpass, subpass, SH_PIPELINE_TYPE::GRAPHICS);
newPipeline->GetPipelineState().SetVertexInputState(vertexInput);
newPipeline->GetPipelineState().SetVertexInputState(*vertexInputState);
// Actually construct the pipeline
newPipeline->ConstructPipeline();

View File

@ -46,9 +46,7 @@ namespace SHADE
Handle<SHVkPipeline> CreateDrawPipeline (
std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair,
Handle<SHVkRenderpass> renderpass,
uint32_t subpass,
SHVertexInputState const& vertexInput,
std::vector<Handle<SHVkDescriptorSetLayout>> const& globalDescSetLayouts
uint32_t subpass
) noexcept;
Handle<SHVkPipeline> GetDrawPipline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
bool CheckDrawPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;