Skip to content
Snippets Groups Projects
Commit 1df2d12b authored by Sebastian Gaida's avatar Sebastian Gaida
Browse files

[#87] adding SSBO to mesh shader pipeline

parent caf7997f
Branches
Tags
1 merge request!74Resolve "Mesh Shader Implementation"
Pipeline #26247 passed
...@@ -11,6 +11,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ...@@ -11,6 +11,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# adding source files to the project # adding source files to the project
add_executable(mesh_shader src/main.cpp) add_executable(mesh_shader src/main.cpp)
target_sources(mesh_shader PRIVATE
src/MeshStruct.hpp)
# this should fix the execution path to load local files from the project (for MSVC) # this should fix the execution path to load local files from the project (for MSVC)
if(MSVC) if(MSVC)
set_target_properties(mesh_shader PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set_target_properties(mesh_shader PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
......
...@@ -9,6 +9,16 @@ layout(local_size_x=32) in; ...@@ -9,6 +9,16 @@ layout(local_size_x=32) in;
// uint subIDs[32]; // uint subIDs[32];
//} OUT; //} OUT;
struct Mesh
{
vec3 position;
vec3 index;
};
layout(std430, binding = 0) coherent buffer buffer_inMesh
{
Mesh mesh[];
};
void main() { void main() {
if(gl_LocalInvocationID.x == 0) if(gl_LocalInvocationID.x == 0)
......
#pragma once
#include <glm/glm.hpp>
struct MeshStruct{
glm::vec3 position;
glm::vec3 index;
};
\ No newline at end of file
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <vkcv/shader/GLSLCompiler.hpp> #include <vkcv/shader/GLSLCompiler.hpp>
#include <vkcv/gui/GUI.hpp> #include <vkcv/gui/GUI.hpp>
#include <vkcv/asset/asset_loader.hpp> #include <vkcv/asset/asset_loader.hpp>
#include "MeshStruct.hpp"
int main(int argc, const char** argv) { int main(int argc, const char** argv) {
const char* applicationName = "Mesh shader"; const char* applicationName = "Mesh shader";
...@@ -56,6 +57,12 @@ int main(int argc, const char** argv) { ...@@ -56,6 +57,12 @@ int main(int argc, const char** argv) {
); );
indexBuffer.fill(mesh.vertexGroups[0].indexBuffer.data); indexBuffer.fill(mesh.vertexGroups[0].indexBuffer.data);
auto meshBuffer = core.createBuffer<MeshStruct>(
vkcv::BufferType::STORAGE,
mesh.vertexGroups[0].vertexBuffer.data.size()
);
// meshBuffer.fill();
auto& attributes = mesh.vertexGroups[0].vertexBuffer.attributes; auto& attributes = mesh.vertexGroups[0].vertexBuffer.attributes;
std::sort(attributes.begin(), attributes.end(), [](const vkcv::asset::VertexAttribute& x, const vkcv::asset::VertexAttribute& y) { std::sort(attributes.begin(), attributes.end(), [](const vkcv::asset::VertexAttribute& x, const vkcv::asset::VertexAttribute& y) {
...@@ -73,8 +80,8 @@ int main(int argc, const char** argv) { ...@@ -73,8 +80,8 @@ int main(int argc, const char** argv) {
vk::Format::eD32Sfloat vk::Format::eD32Sfloat
); );
vkcv::PassConfig trianglePassDefinition({ present_color_attachment, depth_attachment }); vkcv::PassConfig bunnyPassDefinition({ present_color_attachment, depth_attachment });
vkcv::PassHandle renderPass = core.createPass(trianglePassDefinition); vkcv::PassHandle renderPass = core.createPass(bunnyPassDefinition);
if (!renderPass) if (!renderPass)
{ {
...@@ -100,25 +107,21 @@ int main(int argc, const char** argv) { ...@@ -100,25 +107,21 @@ int main(int argc, const char** argv) {
for (size_t i = 0; i < vertexAttachments.size(); i++) { for (size_t i = 0; i < vertexAttachments.size(); i++) {
bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] }));
} }
const vkcv::VertexLayout meshShaderLayout (bindings); const vkcv::VertexLayout bunnyLayout (bindings);
uint32_t setID = 0;
// std::vector<vkcv::DescriptorBinding> descriptorBindings = {bunnyShaderProgram.getReflectedDescriptors()[setID] };
// vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorBindings);
const vkcv::PipelineConfig bunnyPipelineDefinition { const vkcv::PipelineConfig bunnyPipelineDefinition {
bunnyShaderProgram, bunnyShaderProgram,
(uint32_t)windowWidth, (uint32_t)windowWidth,
(uint32_t)windowHeight, (uint32_t)windowHeight,
renderPass, renderPass,
{ meshShaderLayout }, { bunnyLayout },
{}, {},
false false
}; };
vkcv::PipelineHandle trianglePipeline = core.createGraphicsPipeline(bunnyPipelineDefinition); vkcv::PipelineHandle bunnyPipeline = core.createGraphicsPipeline(bunnyPipelineDefinition);
if (!trianglePipeline) if (!bunnyPipeline)
{ {
std::cout << "Error. Could not create graphics pipeline. Exiting." << std::endl; std::cout << "Error. Could not create graphics pipeline. Exiting." << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -141,13 +144,17 @@ int main(int argc, const char** argv) { ...@@ -141,13 +144,17 @@ int main(int argc, const char** argv) {
meshShaderProgram.addShader(shaderStage, path); meshShaderProgram.addShader(shaderStage, path);
}); });
uint32_t setID = 0;
vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet( meshShaderProgram.getReflectedDescriptors()[setID]);
const vkcv::VertexLayout meshShaderLayout(bindings);
const vkcv::PipelineConfig meshShaderPipelineDefinition{ const vkcv::PipelineConfig meshShaderPipelineDefinition{
meshShaderProgram, meshShaderProgram,
(uint32_t)windowWidth, (uint32_t)windowWidth,
(uint32_t)windowHeight, (uint32_t)windowHeight,
renderPass, renderPass,
{}, {meshShaderLayout},
{}, {core.getDescriptorSet(descriptorSet).layout},
false false
}; };
...@@ -164,7 +171,9 @@ int main(int argc, const char** argv) { ...@@ -164,7 +171,9 @@ int main(int argc, const char** argv) {
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[1].offset), vertexBuffer.getVulkanHandle()), vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[1].offset), vertexBuffer.getVulkanHandle()),
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[2].offset), vertexBuffer.getVulkanHandle()) }; vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[2].offset), vertexBuffer.getVulkanHandle()) };
vkcv::DescriptorWrites setWrites; vkcv::DescriptorWrites setWrites;
setWrites.storageBufferWrites = {vkcv::StorageBufferDescriptorWrite(0, meshBuffer.getHandle())};
core.writeDescriptorSet( descriptorSet, setWrites);
vkcv::ImageHandle depthBuffer = core.createImage(vk::Format::eD32Sfloat, windowWidth, windowHeight, 1, false).getHandle(); vkcv::ImageHandle depthBuffer = core.createImage(vk::Format::eD32Sfloat, windowWidth, windowHeight, 1, false).getHandle();
...@@ -216,12 +225,12 @@ int main(int argc, const char** argv) { ...@@ -216,12 +225,12 @@ int main(int argc, const char** argv) {
*/ */
core.recordDrawcallsToCmdStream( core.recordDrawcallsToCmdStream(
cmdStream, cmdStream,
renderPass, renderPass,
trianglePipeline, bunnyPipeline,
pushConstantData, pushConstantData,
{ drawcall }, { drawcall },
{ renderTargets }); { renderTargets });
core.prepareSwapchainImageForPresent(cmdStream); core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream); core.submitCommandStream(cmdStream);
......
#pragma once
struct Mesh{
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment