diff --git a/projects/mesh_shader/CMakeLists.txt b/projects/mesh_shader/CMakeLists.txt index ba9ce47287c1ab78ea2e7afa29629cd5d401d9f2..b57439586de8536edbfc3cee6e30627e18f9351b 100644 --- a/projects/mesh_shader/CMakeLists.txt +++ b/projects/mesh_shader/CMakeLists.txt @@ -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}) diff --git a/projects/mesh_shader/resources/shaders/shader.task b/projects/mesh_shader/resources/shaders/shader.task index e9952528647287fba97b1dc37f8132b74d1e16aa..1b2472df003884f56507668117270e8dec37c7fd 100644 --- a/projects/mesh_shader/resources/shaders/shader.task +++ b/projects/mesh_shader/resources/shaders/shader.task @@ -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) diff --git a/projects/mesh_shader/src/MeshStruct.hpp b/projects/mesh_shader/src/MeshStruct.hpp new file mode 100644 index 0000000000000000000000000000000000000000..12c11681095e7dcec4893a2026656427217e18cc --- /dev/null +++ b/projects/mesh_shader/src/MeshStruct.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include <glm/glm.hpp> + +struct MeshStruct{ + glm::vec3 position; + glm::vec3 index; +}; \ No newline at end of file diff --git a/projects/mesh_shader/src/main.cpp b/projects/mesh_shader/src/main.cpp index f1dffa05899d2c633f287e7252a43ed971e67f82..a956d6f3b8e21abc51426e1666e9ea135775d820 100644 --- a/projects/mesh_shader/src/main.cpp +++ b/projects/mesh_shader/src/main.cpp @@ -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); diff --git a/projects/mesh_shader/src/mesh.hpp b/projects/mesh_shader/src/mesh.hpp deleted file mode 100644 index 9a21bb4f482a887221176debb54540d19d89aa88..0000000000000000000000000000000000000000 --- a/projects/mesh_shader/src/mesh.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -struct Mesh{ - -}; \ No newline at end of file