diff --git a/include/vkcv/DescriptorWrites.hpp b/include/vkcv/DescriptorWrites.hpp index cfadbde29b31edf0fc5c2df1e5dcbff0cdf897f2..caff4cef865c2cfc909e0aa41974a18e5d18a9b3 100644 --- a/include/vkcv/DescriptorWrites.hpp +++ b/include/vkcv/DescriptorWrites.hpp @@ -90,7 +90,7 @@ namespace vkcv { * @param[in] mipCount Mip level count * @return Instance of descriptor writes */ - DescriptorWrites &writeSampledImage(uint32_t binding, ImageHandle image, + DescriptorWrites &writeSampledImage(uint32_t binding, const ImageHandle& image, uint32_t mipLevel = 0, bool useGeneralLayout = false, uint32_t arrayIndex = 0, uint32_t mipCount = 1, bool arrayView = false); @@ -105,7 +105,7 @@ namespace vkcv { * @param[in] mipCount Mip level count * @return Instance of descriptor writes */ - DescriptorWrites &writeStorageImage(uint32_t binding, ImageHandle image, + DescriptorWrites &writeStorageImage(uint32_t binding, const ImageHandle& image, uint32_t mipLevel = 0, uint32_t mipCount = 1, bool arrayView = false); @@ -120,7 +120,7 @@ namespace vkcv { * @param[in] size Size of the buffer access range * @return Instance of descriptor writes */ - DescriptorWrites &writeUniformBuffer(uint32_t binding, BufferHandle buffer, + DescriptorWrites &writeUniformBuffer(uint32_t binding, const BufferHandle& buffer, bool dynamic = false, uint32_t offset = 0, uint32_t size = 0); @@ -135,7 +135,7 @@ namespace vkcv { * @param[in] size Size of the buffer access range * @return Instance of descriptor writes */ - DescriptorWrites &writeStorageBuffer(uint32_t binding, BufferHandle buffer, + DescriptorWrites &writeStorageBuffer(uint32_t binding, const BufferHandle& buffer, bool dynamic = false, uint32_t offset = 0, uint32_t size = 0); @@ -147,7 +147,7 @@ namespace vkcv { * @param[in] sampler Sampler handle * @return Instance of descriptor writes */ - DescriptorWrites &writeSampler(uint32_t binding, SamplerHandle sampler); + DescriptorWrites &writeSampler(uint32_t binding, const SamplerHandle& sampler); /** * @brief Adds an entry for acceleration to a given binding diff --git a/include/vkcv/VertexLayout.hpp b/include/vkcv/VertexLayout.hpp index 88638261483e870418a4e7af86424e6798b1c1e7..2c6cfb486348dea7f255c4fbdc26a27b3bfdda56 100644 --- a/include/vkcv/VertexLayout.hpp +++ b/include/vkcv/VertexLayout.hpp @@ -96,5 +96,13 @@ namespace vkcv { struct VertexLayout { VertexBindings vertexBindings; }; + + /** + * Creates vertex layout from a list of vertex bindings in a simplified way. + * + * @param[in] bindings The vertex bindings + * @return Vertex layout + */ + VertexLayout createVertexLayout(const VertexBindings &bindings); } // namespace vkcv diff --git a/modules/algorithm/src/vkcv/algorithm/SinglePassDownsampler.cpp b/modules/algorithm/src/vkcv/algorithm/SinglePassDownsampler.cpp index eee9f361493c35c5214ac661448f3cc80384e4ee..051ae80d8d98e2ca5ce54f20d1e047b2151e87ca 100644 --- a/modules/algorithm/src/vkcv/algorithm/SinglePassDownsampler.cpp +++ b/modules/algorithm/src/vkcv/algorithm/SinglePassDownsampler.cpp @@ -341,7 +341,7 @@ namespace vkcv::algorithm { } m_core.recordComputeDispatchToCmdStream(cmdStream, m_pipeline, dispatch, { - vkcv::DescriptorSetUsage(0, descriptorSet) + useDescriptorSet(0, descriptorSet) }, pushConstants); if (m_sampler) { diff --git a/modules/camera/src/vkcv/camera/TrackballCameraController.cpp b/modules/camera/src/vkcv/camera/TrackballCameraController.cpp index 8de2beb87d8f29415db611bfe0d17c5efd57a2a3..0052de56599240c3c1d4909604cb6ae155ee6c6d 100644 --- a/modules/camera/src/vkcv/camera/TrackballCameraController.cpp +++ b/modules/camera/src/vkcv/camera/TrackballCameraController.cpp @@ -93,15 +93,15 @@ namespace vkcv::camera { double stickRightX = static_cast<double>(gamepadState.axes[GLFW_GAMEPAD_AXIS_RIGHT_X]); double stickRightY = static_cast<double>(gamepadState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]); - double rightXVal = glm::clamp((abs(stickRightX)-threshold), 0.0, 1.0) + double rightXVal = glm::clamp((glm::abs(stickRightX)-threshold), 0.0, 1.0) * std::copysign(1.0, stickRightX) * sensitivity * frametime; - double rightYVal = glm::clamp((abs(stickRightY)-threshold), 0.0, 1.0) + double rightYVal = glm::clamp((glm::abs(stickRightY)-threshold), 0.0, 1.0) * std::copysign(1.0, stickRightY) * sensitivity * frametime; panView(rightXVal, rightYVal, camera); // handle translation double stickLeftY = static_cast<double>(gamepadState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y]); - double leftYVal = glm::clamp((abs(stickLeftY)-threshold), 0.0, 1.0) + double leftYVal = glm::clamp((glm::abs(stickLeftY)-threshold), 0.0, 1.0) * std::copysign(1.0, stickLeftY) * sensitivity * frametime; updateRadius(-leftYVal, camera); } diff --git a/modules/upscaling/src/vkcv/upscaling/NISUpscaling.cpp b/modules/upscaling/src/vkcv/upscaling/NISUpscaling.cpp index 2b25c9132b20368f37568d95608b23b89645016e..8c3a973e6914f4cb9b31eef1acf805e6448237eb 100644 --- a/modules/upscaling/src/vkcv/upscaling/NISUpscaling.cpp +++ b/modules/upscaling/src/vkcv/upscaling/NISUpscaling.cpp @@ -255,7 +255,7 @@ namespace vkcv::upscaling { cmdStream, m_scalerPipeline, dispatch, - {DescriptorSetUsage(0, m_scalerDescriptorSet, { 0 })}, + { useDescriptorSet(0, m_scalerDescriptorSet, { 0 }) }, PushConstants(0) ); diff --git a/projects/fire_works/src/main.cpp b/projects/fire_works/src/main.cpp index 0166da4b5788990a05f85da5a3b41c0e206d956a..ad75a3eaaed4a578bfa9f60ab6f4b69eb723059d 100644 --- a/projects/fire_works/src/main.cpp +++ b/projects/fire_works/src/main.cpp @@ -99,93 +99,93 @@ void InitializeParticles(std::vector<particle_t> &particles) { } void InitializeFireworkEvents(std::vector<event_t>& events) { - events.emplace_back(glm::vec3(0, 1, 0), 0.5f, glm::vec3(0.0f, 1.0f, 0.0f), 12.5f, - - 1, 0, UINT_MAX, 0, - - 1.0f, 1.0f, 0.5f, 0); - - events.emplace_back(glm::vec3(0.0f), 1.5f, glm::vec3(0.0f, 1.0f, 1.0f), 10.0f, - - 100, 0, events.size() - 1, 0, - - 10.0f, 1.0f, 0.0f, 0); - - events.emplace_back(glm::vec3(0.5, 1, 0), 0.25f, glm::vec3(0.0f, 1.5f, 0.0f), 15.0f, - - 1, 0, UINT_MAX, 0, - - 0.5f, 1.0f, 0.5f, 0); - - events.emplace_back(glm::vec3(0.0f), 0.75f, glm::vec3(0.0f, 1.5f, 1.0f), 8.0f, - - 150, 0, events.size() - 1, 0, - - 10.0f, 1.0f, 0.0f, 0); - - events.emplace_back(glm::vec3(-2.5, 3, 0.5), 1.0f, glm::vec3(246.0f, 189.0f, 255.0f), 12.5f, + events.push_back({ + glm::vec3(0, 1, 0), 0.5f, glm::vec3(0.0f, 1.0f, 0.0f), 12.5f, + 1, 0, UINT_MAX, 0, + 1.0f, 1.0f, 0.5f, 0 + }); - 1, 0, UINT_MAX, 0, + events.push_back({ + glm::vec3(0.0f), 1.5f, glm::vec3(0.0f, 1.0f, 1.0f), 10.0f, + 100, 0, 0, 0, + 10.0f, 1.0f, 0.0f, 0 + }); - 1.0f, 1.0f, 0.5f, 0); + events.push_back({ + glm::vec3(0.5, 1, 0), 0.25f, glm::vec3(0.0f, 1.5f, 0.0f), 15.0f, + 1, 0, UINT_MAX, 0, + 0.5f, 1.0f, 0.5f, 0 + }); - events.emplace_back(glm::vec3(0.0f), 2.0f, glm::vec3(235.0f, 137.0f, 250.0f), 8.0f, + events.push_back({ + glm::vec3(0.0f), 0.75f, glm::vec3(0.0f, 1.5f, 1.0f), 8.0f, + 150, 0, 2, 0, + 10.0f, 1.0f, 0.0f, 0 + }); - 75, 0, events.size() - 1, 0, + events.push_back({ + glm::vec3(-2.5, 3, 0.5), 1.0f, glm::vec3(246.0f, 189.0f, 255.0f), 12.5f, + 1, 0, UINT_MAX, 0, + 1.0f, 1.0f, 0.5f, 0 + }); - 10.0f, 1.0f, 0.0f, 0); + events.push_back({ + glm::vec3(0.0f), 2.0f, glm::vec3(235.0f, 137.0f, 250.0f), 8.0f, + 75, 0, 4, 0, + 10.0f, 1.0f, 0.0f, 0 + }); } void InitializeSparklerEvents(std::vector<event_t> &events) { - events.emplace_back(glm::vec3(0, 1, 0), 0.0f, glm::vec3(251.0f, 255.0f, 145.0f), 1.0f, - - 1, 0, UINT_MAX, 0, - - 8.0f, 0.0f, 0.5f, 0); - - events.emplace_back(glm::vec3(0.0f), 0.0f, glm::vec3(251.0f, 255.0f, 145.0f), 10.0f, - - 1000, 1, events.size() - 1, 10, + events.push_back({ + glm::vec3(0, 1, 0), 0.0f, glm::vec3(251.0f, 255.0f, 145.0f), 1.0f, + 1, 0, UINT_MAX, 0, + 8.0f, 0.0f, 0.5f, 0 + }); - 0.5f, -1.0f, 0.0f, 100); + events.push_back({ + glm::vec3(0.0f), 0.0f, glm::vec3(251.0f, 255.0f, 145.0f), 10.0f, + 1000, 1, 0, 10, + 0.5f, -1.0f, 0.0f, 100 + }); } void InitializeNestedFireworkEvents(std::vector<event_t>& events) { - events.emplace_back(glm::vec3(0, 2, 0), 0.0f, glm::vec3(0.0f, 1.0f, 0.0f), 12.5f, - - 1, 0, UINT_MAX, 0, - - 1.0f, 1.0f, 0.5f, 0); - - events.emplace_back(glm::vec3(0.0f), 0.9f, glm::vec3(0.0f, 1.0f, 1.0f), 7.0f, - - 100, 0, events.size() - 1, 0, - - 10.1f, 1.0f, 0.0f, 0); - - events.emplace_back(glm::vec3(0.0f), 2.0f, glm::vec3(0.0f, 0.0f, 0.0f), 10.0f, - - 100, 0, events.size() - 1, 0, - - 10.0f, 1.0f, 0.0f, 0); - - events.emplace_back(glm::vec3(0.0f), 1.0f, glm::vec3(42.0f,0.0f, 1.0f), 12.5f, - - 100, 0, events.size() - 2, 0, - - 1.0f, 1.0f, 0.5f, 0); - - events.emplace_back(glm::vec3(0.0f), 1.5f, glm::vec3(42.0f, 0.0f, 1.0f), 10.0f, + events.push_back({ + glm::vec3(0, 2, 0), 0.0f, glm::vec3(0.0f, 1.0f, 0.0f), 12.5f, + 1, 0, UINT_MAX, 0, + 1.0f, 1.0f, 0.5f, 0 + }); - 100, 0, events.size() - 1, 0, + events.push_back({ + glm::vec3(0.0f), 0.9f, glm::vec3(0.0f, 1.0f, 1.0f), 7.0f, + 100, 0, 0, 0, + 10.1f, 1.0f, 0.0f, 0 + }); - 10.0f, 1.0f, 0.0f, 0); + events.push_back({ + glm::vec3(0.0f), 2.0f, glm::vec3(0.0f, 0.0f, 0.0f), 10.0f, + 100, 0, 1, 0, + 10.0f, 1.0f, 0.0f, 0 + }); - events.emplace_back(glm::vec3(0.0f), 2.0f, glm::vec3(42.0f, 0.0f, 1.0f), 10.0f, + events.push_back({ + glm::vec3(0.0f), 1.0f, glm::vec3(42.0f,0.0f, 1.0f), 12.5f, + 100, 0, 1, 0, + 1.0f, 1.0f, 0.5f, 0 + }); - 100, 0, events.size() - 1, 0, + events.push_back({ + glm::vec3(0.0f), 1.5f, glm::vec3(42.0f, 0.0f, 1.0f), 10.0f, + 100, 0, 3, 0, + 10.0f, 1.0f, 0.0f, 0 + }); - 10.0f, 1.0f, 0.0f, 0); + events.push_back({ + glm::vec3(0.0f), 2.0f, glm::vec3(42.0f, 0.0f, 1.0f), 10.0f, + 100, 0, 4, 0, + 10.0f, 1.0f, 0.0f, 0 + }); } void ChangeColor(std::vector<event_t>& events, glm::vec3 color) { diff --git a/projects/mesh_shader/src/main.cpp b/projects/mesh_shader/src/main.cpp index ceaeb43c891a09a7e730724bd22cdbea1b0b3f00..ca57d819892949f49553dedbb5cbe6409e64a600 100644 --- a/projects/mesh_shader/src/main.cpp +++ b/projects/mesh_shader/src/main.cpp @@ -264,7 +264,7 @@ int main(int argc, const char** argv) { vkcv::DescriptorSetLayoutHandle meshShaderDescriptorSetLayout = core.createDescriptorSetLayout(meshShaderProgram.getReflectedDescriptors().at(0)); vkcv::DescriptorSetHandle meshShaderDescriptorSet = core.createDescriptorSet(meshShaderDescriptorSetLayout); - const vkcv::VertexLayout meshShaderLayout(bindings); + const vkcv::VertexLayout meshShaderLayout = vkcv::createVertexLayout(bindings); vkcv::GraphicsPipelineHandle meshShaderPipeline = core.createGraphicsPipeline( vkcv::GraphicsPipelineConfig( diff --git a/projects/wobble_bobble/src/main.cpp b/projects/wobble_bobble/src/main.cpp index 9a5548b7189030e3a3296edb0486cef5c9225dd1..da7dbfa49a6a2231c671fa5fb309b3e26d49c399 100644 --- a/projects/wobble_bobble/src/main.cpp +++ b/projects/wobble_bobble/src/main.cpp @@ -504,7 +504,7 @@ int main(int argc, const char **argv) { false ); - vkcv::VertexLayout vertexLayoutGrid ({ + vkcv::VertexLayout vertexLayoutGrid = vkcv::createVertexLayout({ vkcv::createVertexBinding(0, gfxProgramGrid.getVertexAttachments()) }); @@ -515,7 +515,7 @@ int main(int argc, const char **argv) { { gfxSetLayoutGrid } ); - vkcv::VertexLayout vertexLayoutParticles ({ + vkcv::VertexLayout vertexLayoutParticles = vkcv::createVertexLayout({ vkcv::createVertexBinding(0, gfxProgramParticles.getVertexAttachments()) }); @@ -526,7 +526,7 @@ int main(int argc, const char **argv) { { gfxSetLayoutParticles } ); - vkcv::VertexLayout vertexLayoutLines ({ + vkcv::VertexLayout vertexLayoutLines = vkcv::createVertexLayout({ vkcv::createVertexBinding(0, gfxProgramLines.getVertexAttachments()) }); diff --git a/src/vkcv/DescriptorWrites.cpp b/src/vkcv/DescriptorWrites.cpp index 54db0de3c5c02082d775330d6931960e309f4ba8..a3b4c5f4fbc4212da078ec0a00a8a93a6c021d02 100644 --- a/src/vkcv/DescriptorWrites.cpp +++ b/src/vkcv/DescriptorWrites.cpp @@ -3,46 +3,85 @@ namespace vkcv { - DescriptorWrites &DescriptorWrites::writeSampledImage(uint32_t binding, ImageHandle image, - uint32_t mipLevel, bool useGeneralLayout, - uint32_t arrayIndex, uint32_t mipCount, + DescriptorWrites &DescriptorWrites::writeSampledImage(uint32_t binding, + const ImageHandle& image, + uint32_t mipLevel, + bool useGeneralLayout, + uint32_t arrayIndex, + uint32_t mipCount, bool arrayView) { - m_sampledImageWrites.emplace_back(binding, image, mipLevel, useGeneralLayout, arrayIndex, - mipCount, arrayView); - + SampledImageDescriptorWrite write; + write.binding = binding; + write.image = image; + write.mipLevel = mipLevel; + write.useGeneralLayout = useGeneralLayout; + write.arrayIndex = arrayIndex; + write.mipCount = mipCount; + write.arrayView = arrayView; + m_sampledImageWrites.push_back(write); return *this; } - DescriptorWrites &DescriptorWrites::writeStorageImage(uint32_t binding, ImageHandle image, - uint32_t mipLevel, uint32_t mipCount, + DescriptorWrites &DescriptorWrites::writeStorageImage(uint32_t binding, + const ImageHandle& image, + uint32_t mipLevel, + uint32_t mipCount, bool arrayView) { - m_storageImageWrites.emplace_back(binding, image, mipLevel, mipCount, arrayView); - + StorageImageDescriptorWrite write; + write.binding = binding; + write.image = image; + write.mipLevel = mipLevel; + write.mipCount = mipCount; + write.arrayView = arrayView; + m_storageImageWrites.push_back(write); return *this; } - DescriptorWrites &DescriptorWrites::writeUniformBuffer(uint32_t binding, BufferHandle buffer, - bool dynamic, uint32_t offset, + DescriptorWrites &DescriptorWrites::writeUniformBuffer(uint32_t binding, + const BufferHandle& buffer, + bool dynamic, + uint32_t offset, uint32_t size) { - m_uniformBufferWrites.emplace_back(binding, buffer, dynamic, offset, size); + BufferDescriptorWrite write; + write.binding = binding; + write.buffer = buffer; + write.dynamic = dynamic; + write.offset = offset; + write.size = size; + m_uniformBufferWrites.push_back(write); return *this; } - DescriptorWrites &DescriptorWrites::writeStorageBuffer(uint32_t binding, BufferHandle buffer, - bool dynamic, uint32_t offset, + DescriptorWrites &DescriptorWrites::writeStorageBuffer(uint32_t binding, + const BufferHandle& buffer, + bool dynamic, + uint32_t offset, uint32_t size) { - m_storageBufferWrites.emplace_back(binding, buffer, dynamic, offset, size); + BufferDescriptorWrite write; + write.binding = binding; + write.buffer = buffer; + write.dynamic = dynamic; + write.offset = offset; + write.size = size; + m_storageBufferWrites.push_back(write); return *this; } - DescriptorWrites &DescriptorWrites::writeSampler(uint32_t binding, SamplerHandle sampler) { - m_samplerWrites.emplace_back(binding, sampler); + DescriptorWrites &DescriptorWrites::writeSampler(uint32_t binding, + const SamplerHandle& sampler) { + SamplerDescriptorWrite write; + write.binding = binding; + write.sampler = sampler; + m_samplerWrites.push_back(write); return *this; } DescriptorWrites &DescriptorWrites::writeAcceleration( uint32_t binding, const std::vector<vk::AccelerationStructureKHR> &structures) { - m_accelerationWrites.emplace_back(binding, structures); + AccelerationDescriptorWrite write; + write.binding = binding; + write.structures = structures; + m_accelerationWrites.push_back(write); return *this; } diff --git a/src/vkcv/Drawcall.cpp b/src/vkcv/Drawcall.cpp index b34f81a2059033d0441af2e53612f3685d3c1d11..b45cb6ecc8a31d098d65791ede15badb3dc24bec 100644 --- a/src/vkcv/Drawcall.cpp +++ b/src/vkcv/Drawcall.cpp @@ -13,11 +13,18 @@ namespace vkcv { void Drawcall::useDescriptorSet(uint32_t location, const DescriptorSetHandle &descriptorSet, const std::vector<uint32_t> &dynamicOffsets) { - m_usages.emplace_back(location, descriptorSet, dynamicOffsets); + DescriptorSetUsage usage; + usage.location = location; + usage.descriptorSet = descriptorSet; + usage.dynamicOffsets = dynamicOffsets; + m_usages.push_back(usage); } - InstanceDrawcall::InstanceDrawcall(const VertexData &vertexData, uint32_t instanceCount) : - Drawcall(), m_vertexData(vertexData), m_instanceCount(instanceCount) {} + InstanceDrawcall::InstanceDrawcall(const VertexData &vertexData, + uint32_t instanceCount) : + Drawcall(), + m_vertexData(vertexData), + m_instanceCount(instanceCount) {} const VertexData &InstanceDrawcall::getVertexData() const { return m_vertexData; @@ -28,9 +35,12 @@ namespace vkcv { } IndirectDrawcall::IndirectDrawcall(const BufferHandle &indirectDrawBuffer, - const VertexData &vertexData, uint32_t drawCount) : + const VertexData &vertexData, + uint32_t drawCount) : Drawcall(), - m_indirectDrawBuffer(indirectDrawBuffer), m_vertexData(vertexData), m_drawCount(drawCount) { + m_indirectDrawBuffer(indirectDrawBuffer), + m_vertexData(vertexData), + m_drawCount(drawCount) { } BufferHandle IndirectDrawcall::getIndirectDrawBuffer() const { diff --git a/src/vkcv/VertexLayout.cpp b/src/vkcv/VertexLayout.cpp index dc20966bafcbf3c1f4b32956555c444fbc77962e..27347019a711a252c7e0b7c91232410e0b49fc1f 100644 --- a/src/vkcv/VertexLayout.cpp +++ b/src/vkcv/VertexLayout.cpp @@ -55,5 +55,10 @@ namespace vkcv { return bindings; } - + + VertexLayout createVertexLayout(const VertexBindings &bindings) { + VertexLayout layout { bindings }; + return layout; + } + } // namespace vkcv \ No newline at end of file