From d971d3e5b03b66433a7216fb8c7c1d3f5b1ed84a Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Wed, 2 Feb 2022 17:55:34 +0100 Subject: [PATCH] Fixed the initialization of the grid images Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- .../wobble_bobble/shaders/init_particle_volumes.comp | 2 +- projects/wobble_bobble/src/main.cpp | 11 +++-------- src/vkcv/ImageManager.cpp | 10 ++++++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/projects/wobble_bobble/shaders/init_particle_volumes.comp b/projects/wobble_bobble/shaders/init_particle_volumes.comp index e4292098..be0e0d06 100644 --- a/projects/wobble_bobble/shaders/init_particle_volumes.comp +++ b/projects/wobble_bobble/shaders/init_particle_volumes.comp @@ -41,7 +41,7 @@ void main() { float density = minimal.mass / volume; //volume = minimal.mass / (mass / volume); - mass = density * volume; + //mass = density * volume; } particles[gl_GlobalInvocationID.x].minimal.size = sphere_radius(volume); diff --git a/projects/wobble_bobble/src/main.cpp b/projects/wobble_bobble/src/main.cpp index a65e9325..5294f1ae 100644 --- a/projects/wobble_bobble/src/main.cpp +++ b/projects/wobble_bobble/src/main.cpp @@ -185,8 +185,6 @@ int main(int argc, const char **argv) { true ); - grid.switchLayout(vk::ImageLayout::eGeneral); - vkcv::Image gridCopy = core.createImage( grid.getFormat(), grid.getWidth(), @@ -196,17 +194,14 @@ int main(int argc, const char **argv) { true ); - gridCopy.switchLayout(vk::ImageLayout::eGeneral); - - /* TODO: clear grid via compute shader? std::vector<glm::vec4> grid_vec (grid.getWidth() * grid.getHeight() * grid.getDepth()); for (size_t i = 0; i < grid_vec.size(); i++) { - grid_vec[i] = glm::vec4(0); + grid_vec[i] = glm::vec4(0.0f); } - grid.fill(grid_vec.data()); // FIXME: gets limited by staging buffer size... - */ + grid.fill(grid_vec.data()); + gridCopy.fill(grid_vec.data()); vkcv::SamplerHandle gridSampler = core.createSampler( vkcv::SamplerFilterType::LINEAR, diff --git a/src/vkcv/ImageManager.cpp b/src/vkcv/ImageManager.cpp index bde02049..ae69aa75 100644 --- a/src/vkcv/ImageManager.cpp +++ b/src/vkcv/ImageManager.cpp @@ -345,7 +345,7 @@ namespace vkcv { recordImageBarrier(cmdBuffer, transitionBarrier); } - constexpr uint32_t getChannelsByFormat(vk::Format format) { + constexpr uint32_t getBytesPerPixel(vk::Format format) { switch (format) { case vk::Format::eR8Unorm: return 1; @@ -353,6 +353,8 @@ namespace vkcv { return 4; case vk::Format::eR8G8B8A8Unorm: return 4; + case vk::Format::eR32G32B32A32Sfloat: + return 16; default: std::cerr << "Unknown image format" << std::endl; return 4; @@ -379,15 +381,15 @@ namespace vkcv { handle, vk::ImageLayout::eTransferDstOptimal); - uint32_t channels = getChannelsByFormat(image.m_format); const size_t image_size = ( - image.m_width * image.m_height * image.m_depth * channels + image.m_width * image.m_height * image.m_depth * + getBytesPerPixel(image.m_format) ); const size_t max_size = std::min(size, image_size); BufferHandle bufferHandle = m_bufferManager.createBuffer( - BufferType::STAGING, max_size, BufferMemoryType::HOST_VISIBLE, false + BufferType::STAGING, max_size, BufferMemoryType::DEVICE_LOCAL, false ); m_bufferManager.fillBuffer(bufferHandle, data, max_size, 0); -- GitLab