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
No related branches found
No related tags found
1 merge request!74Resolve "Mesh Shader Implementation"
Pipeline #26247 passed
......@@ -11,6 +11,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# adding source files to the project
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)
if(MSVC)
set_target_properties(mesh_shader PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
......
......@@ -9,6 +9,16 @@ layout(local_size_x=32) in;
// uint subIDs[32];
//} OUT;
struct Mesh
{
vec3 position;
vec3 index;
};
layout(std430, binding = 0) coherent buffer buffer_inMesh
{
Mesh mesh[];
};
void main() {
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 @@
#include <vkcv/shader/GLSLCompiler.hpp>
#include <vkcv/gui/GUI.hpp>
#include <vkcv/asset/asset_loader.hpp>
#include "MeshStruct.hpp"
int main(int argc, const char** argv) {
const char* applicationName = "Mesh shader";
......@@ -56,6 +57,12 @@ int main(int argc, const char** argv) {
);
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;
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) {
vk::Format::eD32Sfloat
);
vkcv::PassConfig trianglePassDefinition({ present_color_attachment, depth_attachment });
vkcv::PassHandle renderPass = core.createPass(trianglePassDefinition);
vkcv::PassConfig bunnyPassDefinition({ present_color_attachment, depth_attachment });
vkcv::PassHandle renderPass = core.createPass(bunnyPassDefinition);
if (!renderPass)
{
......@@ -100,25 +107,21 @@ int main(int argc, const char** argv) {
for (size_t i = 0; i < vertexAttachments.size(); i++) {
bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] }));
}
const vkcv::VertexLayout meshShaderLayout (bindings);
uint32_t setID = 0;
// std::vector<vkcv::DescriptorBinding> descriptorBindings = {bunnyShaderProgram.getReflectedDescriptors()[setID] };
// vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorBindings);
const vkcv::VertexLayout bunnyLayout (bindings);
const vkcv::PipelineConfig bunnyPipelineDefinition {
bunnyShaderProgram,
(uint32_t)windowWidth,
(uint32_t)windowHeight,
renderPass,
{ meshShaderLayout },
{ bunnyLayout },
{},
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;
return EXIT_FAILURE;
......@@ -141,13 +144,17 @@ int main(int argc, const char** argv) {
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{
meshShaderProgram,
(uint32_t)windowWidth,
(uint32_t)windowHeight,
renderPass,
{},
{},
{meshShaderLayout},
{core.getDescriptorSet(descriptorSet).layout},
false
};
......@@ -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[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();
......@@ -216,12 +225,12 @@ int main(int argc, const char** argv) {
*/
core.recordDrawcallsToCmdStream(
cmdStream,
renderPass,
trianglePipeline,
pushConstantData,
{ drawcall },
{ renderTargets });
cmdStream,
renderPass,
bunnyPipeline,
pushConstantData,
{ drawcall },
{ renderTargets });
core.prepareSwapchainImageForPresent(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.
Finish editing this message first!
Please register or to comment