Verified Commit ad71eef2 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Refactored graphics pipeline config and optimized sph compute shaders


Signed-off-by: Tobias Frisch's avatarTobias Frisch <tfrisch@uni-koblenz.de>
parent 80a608ae
Pipeline #28224 failed with stages
in 0 seconds
......@@ -28,7 +28,7 @@ namespace vkcv {
uint32_t m_Height;
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
std::vector<vk::DescriptorSetLayout> m_DescriptorLayouts;
std::vector<DescriptorSetLayoutHandle> m_DescriptorLayouts;
bool m_UseDynamicViewport;
bool m_UseConservativeRasterization = false;
PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList;
......
......@@ -162,7 +162,7 @@ int main(int argc, const char** argv) {
UINT32_MAX,
firstMeshPass,
{firstMeshLayout},
{ core.getDescriptorSetLayout(descriptorSetLayout).vulkanHandle },
{ descriptorSetLayout },
true
};
vkcv::GraphicsPipelineHandle firstMeshPipeline = core.createGraphicsPipeline(firstMeshPipelineConfig);
......
......@@ -115,7 +115,7 @@ int main(int argc, const char** argv) {
UINT32_MAX,
firstMeshPass,
{firstMeshLayout},
{ core.getDescriptorSetLayout(setLayoutHandle).vulkanHandle },
{ setLayoutHandle },
true
};
vkcv::GraphicsPipelineHandle firstMeshPipeline = core.createGraphicsPipeline(firstMeshPipelineConfig);
......
......@@ -87,8 +87,9 @@ int main(int argc, const char** argv) {
UINT32_MAX,
scenePass,
{sceneLayout},
{ core.getDescriptorSetLayout(material0.getDescriptorSetLayout()).vulkanHandle },
true };
{ material0.getDescriptorSetLayout() },
true
};
vkcv::GraphicsPipelineHandle scenePipeline = core.createGraphicsPipeline(scenePipelineDefinition);
if (!scenePipeline) {
......
......@@ -122,12 +122,12 @@ bool loadGraphicPass(
const auto descriptorBindings = shaderProgram.getReflectedDescriptors();
const bool hasDescriptor = descriptorBindings.size() > 0;
std::vector<vk::DescriptorSetLayout> descriptorSetLayouts = {};
std::vector<vkcv::DescriptorSetLayoutHandle> descriptorSetLayouts = {};
if (hasDescriptor)
{
outPassHandles->descriptorSetLayout = core.createDescriptorSetLayout(descriptorBindings.at(0));
outPassHandles->descriptorSet = core.createDescriptorSet(outPassHandles->descriptorSetLayout);
descriptorSetLayouts.push_back(core.getDescriptorSetLayout(outPassHandles->descriptorSetLayout).vulkanHandle);
descriptorSetLayouts.push_back(outPassHandles->descriptorSetLayout);
}
......@@ -138,7 +138,8 @@ bool loadGraphicPass(
outPassHandles->renderPass,
{ vertexLayout },
descriptorSetLayouts,
true };
true
};
pipelineConfig.m_depthTest = depthTest;
outPassHandles->pipeline = core.createGraphicsPipeline(pipelineConfig);
......
......@@ -467,7 +467,7 @@ int main(int argc, const char** argv) {
UINT32_MAX,
passHandle,
{sponzaVertexLayout},
{ core.getDescriptorSetLayout(descriptorSetLayout).vulkanHandle },
{ descriptorSetLayout },
true
};
vkcv::GraphicsPipelineHandle sponzaPipelineHandle = core.createGraphicsPipeline(sponzaPipelineConfig);
......
......@@ -211,7 +211,7 @@ int main(int argc, const char** argv) {
swapchainExtent.height,
renderPass,
{ bunnyLayout },
{ core.getDescriptorSetLayout(vertexShaderDescriptorSetLayout).vulkanHandle },
{ vertexShaderDescriptorSetLayout },
false
};
......@@ -261,7 +261,7 @@ int main(int argc, const char** argv) {
swapchainExtent.height,
renderPass,
{meshShaderLayout},
{core.getDescriptorSetLayout(meshShaderDescriptorSetLayout).vulkanHandle},
{meshShaderDescriptorSetLayout},
false
};
......
......@@ -121,8 +121,9 @@ int main(int argc, const char **argv) {
UINT32_MAX,
particlePass,
{particleLayout},
{core.getDescriptorSetLayout(descriptorSetLayout).vulkanHandle},
true};
{descriptorSetLayout},
true
};
particlePipelineDefinition.m_blendMode = vkcv::BlendMode::Additive;
const std::vector<glm::vec3> vertices = {glm::vec3(-0.012, 0.012, 0),
......
......@@ -176,7 +176,7 @@ int main(int argc, const char** argv) {
(uint32_t)windowHeight,
safrPass,
{},
{ core.getDescriptorSetLayout(descriptorSetLayout).vulkanHandle },
{ descriptorSetLayout },
false
};
......
......@@ -40,29 +40,31 @@ layout( push_constant ) uniform constants{
float particleCount;
};
float spiky(float r)
{
return (15.f / (PI * pow(h, 6)) * pow((h-r), 3)) * int(0<=r && r<=h);
}
float grad_spiky(float r)
{
return -45.f / (PI * pow(h, 6)) * pow((h-r), 2) * int(0<=r && r<=h);
return -45.f / (PI * pow(h, 6)) * pow((h-r), 2);
}
float laplacian(float r)
{
return (45.f / (PI * pow(h,6)) * (h - r)) * int(0<=r && r<=h);
return (45.f / (PI * pow(h,6)) * (h - r));
}
vec3 pressureForce = vec3(0, 0, 0);
vec3 viscosityForce = vec3(0, 0, 0);
vec3 externalForce = vec3(0, 0, 0);
void main() {
struct ParticleData
{
vec3 position;
float density;
vec3 velocity;
float pressure;
};
shared ParticleData particle_data [256];
void main() {
uint id = gl_GlobalInvocationID.x;
if(id >= int(particleCount))
......@@ -70,26 +72,75 @@ void main() {
return;
}
externalForce = inParticle[id].density * gravity * vec3(-gravityDir.x,gravityDir.y,gravityDir.z);
uint index_offset = gl_WorkGroupID.x * gl_WorkGroupSize.x;
particle_data[gl_LocalInvocationIndex].position = inParticle[id].position;
particle_data[gl_LocalInvocationIndex].density = inParticle[id].density;
particle_data[gl_LocalInvocationIndex].velocity = inParticle[id].velocity;
particle_data[gl_LocalInvocationIndex].pressure = inParticle[id].pressure;
memoryBarrierShared();
const float h6 = pow(h, 6);
externalForce = particle_data[gl_LocalInvocationIndex].density * gravity * vec3(-gravityDir.x,gravityDir.y,gravityDir.z);
for(uint j = 1; j < gl_WorkGroupSize.x; j++) {
uint i = (gl_LocalInvocationIndex + j) % gl_WorkGroupSize.x;
vec3 dir = particle_data[gl_LocalInvocationIndex].position - particle_data[i].position;
float dist = length(dir);
for(uint i = 0; i < int(particleCount); i++)
if ((dist > 0.0f) && (dist <= h))
{
const float h_dist = (h - dist);
float laplacian = 45.f / (PI * h6) * h_dist;
float grad_spiky = -1.0f * laplacian * h_dist;
pressureForce += mass * -(particle_data[gl_LocalInvocationIndex].pressure + particle_data[i].pressure)/(2.f * particle_data[i].density) * grad_spiky * normalize(dir);
viscosityForce += mass * (particle_data[i].velocity - particle_data[gl_LocalInvocationIndex].velocity)/particle_data[i].density * laplacian;
}
}
for(uint i = 0; i < index_offset; i++)
{
vec3 dir = particle_data[gl_LocalInvocationIndex].position - inParticle[i].position;
float dist = length(dir);
if ((dist > 0.0f) && (dist <= h))
{
const float h_dist = (h - dist);
float laplacian = 45.f / (PI * h6) * h_dist;
float grad_spiky = -1.0f * laplacian * h_dist;
pressureForce += mass * -(particle_data[gl_LocalInvocationIndex].pressure + inParticle[i].pressure)/(2.f * inParticle[i].density) * grad_spiky * normalize(dir);
viscosityForce += mass * (inParticle[i].velocity - particle_data[gl_LocalInvocationIndex].velocity)/inParticle[i].density * laplacian;
}
}
for(uint i = index_offset + gl_WorkGroupSize.x; i < int(particleCount); i++)
{
if (id != i)
vec3 dir = particle_data[gl_LocalInvocationIndex].position - inParticle[i].position;
float dist = length(dir);
if ((dist > 0.0f) && (dist <= h))
{
vec3 dir = inParticle[id].position - inParticle[i].position;
float dist = length(dir);
if(dist != 0)
{
pressureForce += mass * -(inParticle[id].pressure + inParticle[i].pressure)/(2.f * inParticle[i].density) * grad_spiky(dist) * normalize(dir);
viscosityForce += mass * (inParticle[i].velocity - inParticle[id].velocity)/inParticle[i].density * laplacian(dist);
}
const float h_dist = (h - dist);
float laplacian = 45.f / (PI * h6) * h_dist;
float grad_spiky = -1.0f * laplacian * h_dist;
pressureForce += mass * -(particle_data[gl_LocalInvocationIndex].pressure + inParticle[i].pressure)/(2.f * inParticle[i].density) * grad_spiky * normalize(dir);
viscosityForce += mass * (inParticle[i].velocity - particle_data[gl_LocalInvocationIndex].velocity)/inParticle[i].density * laplacian;
}
}
viscosityForce *= viscosity;
outParticle[id].force = externalForce + pressureForce + viscosityForce;
outParticle[id].density = inParticle[id].density;
outParticle[id].pressure = inParticle[id].pressure;
outParticle[id].position = inParticle[id].position;
outParticle[id].velocity = inParticle[id].velocity;
outParticle[id].density = particle_data[gl_LocalInvocationIndex].density;
outParticle[id].pressure = particle_data[gl_LocalInvocationIndex].pressure;
outParticle[id].position = particle_data[gl_LocalInvocationIndex].position;
outParticle[id].velocity = particle_data[gl_LocalInvocationIndex].velocity;
}
......@@ -42,11 +42,13 @@ layout( push_constant ) uniform constants{
float poly6(float r)
{
return (315.f * pow((pow(h,2)-pow(r,2)), 3)/(64.f*PI*pow(h, 9))) * int(0<=r && r<=h);
return (315.f * pow((pow(h,2)-pow(r,2)), 3)/(64.f*PI*pow(h, 9))) * int(r<=h);
}
float densitySum = 0.f;
shared vec3 position_data [256];
void main() {
uint id = gl_GlobalInvocationID.x;
......@@ -56,17 +58,34 @@ void main() {
return;
}
for(uint i = 0; i < int(particleCount); i++)
uint index_offset = gl_WorkGroupID.x * gl_WorkGroupSize.x;
position_data[gl_LocalInvocationIndex] = inParticle[id].position;
memoryBarrierShared();
for(uint j = 1; j < gl_WorkGroupSize.x; j++) {
uint i = (gl_LocalInvocationIndex + j) % gl_WorkGroupSize.x;
float dist = distance(position_data[gl_LocalInvocationIndex], position_data[i]);
densitySum += mass * poly6(dist);
}
for(uint i = 0; i < index_offset; i++)
{
if (id != i)
{
float dist = distance(inParticle[id].position, inParticle[i].position);
densitySum += mass * poly6(dist);
}
float dist = distance(position_data[gl_LocalInvocationIndex], inParticle[i].position);
densitySum += mass * poly6(dist);
}
for(uint i = index_offset + gl_WorkGroupSize.x; i < int(particleCount); i++)
{
float dist = distance(position_data[gl_LocalInvocationIndex], inParticle[i].position);
densitySum += mass * poly6(dist);
}
outParticle[id].density = max(densitySum,0.0000001f);
outParticle[id].pressure = max((densitySum - offset), 0.0000001f) * gasConstant;
outParticle[id].position = inParticle[id].position;
outParticle[id].position = position_data[gl_LocalInvocationIndex];
outParticle[id].velocity = inParticle[id].velocity;
outParticle[id].force = inParticle[id].force;
}
......@@ -122,8 +122,9 @@ int main(int argc, const char **argv) {
UINT32_MAX,
particlePass,
{particleLayout},
{core.getDescriptorSetLayout(descriptorSetLayout).vulkanHandle},
true};
{descriptorSetLayout},
true
};
particlePipelineDefinition.m_blendMode = vkcv::BlendMode::Additive;
const std::vector<glm::vec3> vertices = {glm::vec3(-0.012, 0.012, 0),
......
......@@ -110,11 +110,10 @@ Voxelization::Voxelization(
voxelResolution,
m_voxelizationPass,
dependencies.vertexLayout,
{
m_corePtr->getDescriptorSetLayout(m_voxelizationDescriptorSetLayout).vulkanHandle,
m_corePtr->getDescriptorSetLayout(dummyPerMeshDescriptorSetLayout).vulkanHandle},
{ m_voxelizationDescriptorSetLayout, dummyPerMeshDescriptorSetLayout },
false,
true };
true
};
m_voxelizationPipe = m_corePtr->createGraphicsPipeline(voxelizationPipeConfig);
vkcv::DescriptorWrites voxelizationDescriptorWrites;
......@@ -156,10 +155,11 @@ Voxelization::Voxelization(
0,
m_visualisationPass,
{},
{ m_corePtr->getDescriptorSetLayout(m_visualisationDescriptorSetLayout).vulkanHandle },
{ m_visualisationDescriptorSetLayout },
true,
false,
vkcv::PrimitiveTopology::PointList }; // points are extended to cubes in the geometry shader
vkcv::PrimitiveTopology::PointList
}; // points are extended to cubes in the geometry shader
voxelVisualisationPipeConfig.m_multisampling = msaa;
m_visualisationPipe = m_corePtr->createGraphicsPipeline(voxelVisualisationPipeConfig);
......
......@@ -317,10 +317,9 @@ int main(int argc, const char** argv) {
swapchainExtent.height,
prepassPass,
vertexLayout,
{
core.getDescriptorSetLayout(prepassDescriptorSetLayout).vulkanHandle,
core.getDescriptorSetLayout(perMeshDescriptorSetLayouts[0]).vulkanHandle },
true };
{ prepassDescriptorSetLayout, perMeshDescriptorSetLayouts[0] },
true
};
prepassPipelineConfig.m_culling = vkcv::CullMode::Back;
prepassPipelineConfig.m_multisampling = msaa;
prepassPipelineConfig.m_depthTest = vkcv::DepthTest::LessEqual;
......@@ -335,9 +334,7 @@ int main(int argc, const char** argv) {
swapchainExtent.height,
forwardPass,
vertexLayout,
{
core.getDescriptorSetLayout(forwardShadingDescriptorSetLayout).vulkanHandle,
core.getDescriptorSetLayout(perMeshDescriptorSetLayouts[0]).vulkanHandle },
{ forwardShadingDescriptorSetLayout, perMeshDescriptorSetLayouts[0] },
true
};
forwardPipelineConfig.m_culling = vkcv::CullMode::Back;
......
......@@ -80,7 +80,7 @@ namespace vkcv
GraphicsPipelineHandle Core::createGraphicsPipeline(const GraphicsPipelineConfig &config)
{
return m_PipelineManager->createPipeline(config, *m_PassManager);
return m_PipelineManager->createPipeline(config, *m_PassManager, *m_DescriptorManager);
}
ComputePipelineHandle Core::createComputePipeline(const ComputePipelineConfig &config)
......
#pragma once
/**
* @authors Artur Wasmut, Susanne D�tsch, Simeon Hermann
* @file src/vkcv/DescriptorManager.cpp
......@@ -21,7 +23,7 @@ namespace vkcv
explicit DescriptorManager(vk::Device device) noexcept;
~DescriptorManager() noexcept;
DescriptorSetLayoutHandle createDescriptorSetLayout(const std::unordered_map<uint32_t, DescriptorBinding> &setBindingsMap);
DescriptorSetLayoutHandle createDescriptorSetLayout(const DescriptorBindings &setBindingsMap);
DescriptorSetHandle createDescriptorSet(const DescriptorSetLayoutHandle &setLayoutHandle);
void writeDescriptorSet(
......
......@@ -361,7 +361,8 @@ namespace vkcv
* @param config sets Push Constant Size and Descriptor Layouts.
* @return Pipeline Layout Create Info Struct
*/
vk::PipelineLayoutCreateInfo createPipelineLayoutCreateInfo(const GraphicsPipelineConfig &config) {
vk::PipelineLayoutCreateInfo createPipelineLayoutCreateInfo(const GraphicsPipelineConfig &config,
const std::vector<vk::DescriptorSetLayout>& descriptorSetLayouts) {
static vk::PushConstantRange pushConstantRange;
const size_t pushConstantSize = config.m_ShaderProgram.getPushConstantSize();
......@@ -371,7 +372,7 @@ namespace vkcv
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo(
{},
(config.m_DescriptorLayouts),
(descriptorSetLayouts),
(pushConstantRange)
);
......@@ -427,7 +428,9 @@ namespace vkcv
return dynamicStateCreateInfo;
}
GraphicsPipelineHandle GraphicsPipelineManager::createPipeline(const GraphicsPipelineConfig &config, PassManager& passManager) {
GraphicsPipelineHandle GraphicsPipelineManager::createPipeline(const GraphicsPipelineConfig &config,
const PassManager& passManager,
const DescriptorManager& descriptorManager) {
const vk::RenderPass &pass = passManager.getVkPass(config.m_PassHandle);
const bool existsTaskShader = config.m_ShaderProgram.existsShader(ShaderStage::TASK);
......@@ -625,9 +628,15 @@ namespace vkcv
vk::PipelineDynamicStateCreateInfo dynamicStateCreateInfo =
createPipelineDynamicStateCreateInfo(config);
std::vector<vk::DescriptorSetLayout> descriptorSetLayouts;
descriptorSetLayouts.reserve(config.m_DescriptorLayouts.size());
for (const auto& handle : config.m_DescriptorLayouts) {
descriptorSetLayouts.push_back(descriptorManager.getDescriptorSetLayout(handle).vulkanHandle);
}
// pipeline layout
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo =
createPipelineLayoutCreateInfo(config);
createPipelineLayoutCreateInfo(config, descriptorSetLayouts);
vk::PipelineLayout vkPipelineLayout{};
if (m_Device.createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &vkPipelineLayout) != vk::Result::eSuccess) {
......
......@@ -13,6 +13,7 @@
#include "vkcv/Handles.hpp"
#include "vkcv/GraphicsPipelineConfig.hpp"
#include "PassManager.hpp"
#include "DescriptorManager.hpp"
namespace vkcv
{
......@@ -36,9 +37,12 @@ namespace vkcv
* On application level it is necessary first to fill a PipelineConfig Struct.
* @param config Hands over all needed information for pipeline creation.
* @param passManager Hands over the corresponding render pass.
* @param descriptorManager Hands over the corresponding descriptor set layouts
* @return A Handler to the created Graphics Pipeline Object.
*/
GraphicsPipelineHandle createPipeline(const GraphicsPipelineConfig &config, PassManager& passManager);
GraphicsPipelineHandle createPipeline(const GraphicsPipelineConfig &config,
const PassManager& passManager,
const DescriptorManager& descriptorManager);
/**
* Returns a vk::Pipeline object by handle.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment