From 915e0b9070d265743d0aa04952bb94a0d10c5836 Mon Sep 17 00:00:00 2001
From: Lars Hoerttrich <larshoerttrich@uni-koblenz.de>
Date: Sat, 14 Aug 2021 17:24:44 +0200
Subject: [PATCH] [#91] small fixes, still not working

---
 projects/neural_network/src/main.cpp | 13 +++++++++----
 src/vkcv/BufferManager.cpp           | 11 +++++------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/projects/neural_network/src/main.cpp b/projects/neural_network/src/main.cpp
index 612ebd7a..2645f207 100644
--- a/projects/neural_network/src/main.cpp
+++ b/projects/neural_network/src/main.cpp
@@ -27,7 +27,8 @@ int main(int argc, const char** argv) {
     );
 
     int input[64] = { 0 };
-    vkcv::Buffer<int> inputBuffer = core.createBuffer<int>(vkcv::BufferType::STORAGE, 64);
+    std::fill_n(input, 64, 2);
+    vkcv::Buffer<int> inputBuffer = core.createBuffer<int>(vkcv::BufferType::STORAGE, 64, vkcv::BufferMemoryType::HOST_VISIBLE);
     inputBuffer.fill(input);
 
     vkcv::PassConfig computePassDefinition({});
@@ -64,7 +65,7 @@ int main(int argc, const char** argv) {
     }
 
     auto cmdStream = core.createCommandStream(vkcv::QueueType::Compute);
-    uint32_t computeDispatchCount[3] = {inputBuffer.getSize(),1,1 };
+    uint32_t computeDispatchCount[3] = {64,1,1 };
 
     vkcv::PushConstants pushConstantsCompute(sizeof(int));
     pushConstantsCompute.appendDrawcall(1);
@@ -76,9 +77,13 @@ int main(int argc, const char** argv) {
         pushConstantsCompute);
 
     int output[64] = { 0 };
+    std::fill_n(output, 64, -1);
     core.readBufferMemoryBarrier(cmdStream, inputBuffer.getHandle(), &output);
     core.submitCommandStream(cmdStream);
-
-    std::cout << output << std::endl;
+    std::cout << "[";
+    for (int i = 0; i < 64; i++) {
+        std::cout << output[i] << ", ";
+    }
+    std::cout << "]" << std::endl;
     return 0;
 }
diff --git a/src/vkcv/BufferManager.cpp b/src/vkcv/BufferManager.cpp
index 85515f31..fbe6e2e7 100644
--- a/src/vkcv/BufferManager.cpp
+++ b/src/vkcv/BufferManager.cpp
@@ -350,9 +350,8 @@ namespace vkcv {
         const size_t max_size = std::min(size, buffer.m_size);
 
         void* mapped = allocator.mapMemory(buffer.m_allocation);
-        memcpy(data, reinterpret_cast<char*>(mapped) , max_size);
+        memcpy(reinterpret_cast<int*>(data), reinterpret_cast<char*>(mapped) , max_size);
         allocator.unmapMemory(buffer.m_allocation);
-
     }
 
     void BufferManager ::readBufferMemoryBarrier(const BufferHandle& handle, vk::CommandBuffer cmdBuffer, void *data) {
@@ -376,8 +375,8 @@ namespace vkcv {
                 buffer.m_size);
 
         cmdBuffer.pipelineBarrier(
-                vk::PipelineStageFlagBits::eTopOfPipe,
-                vk::PipelineStageFlagBits::eBottomOfPipe,
+                vk::PipelineStageFlagBits::eComputeShader,
+                vk::PipelineStageFlagBits::eTransfer,
                 {},
                 nullptr,
                 memoryBarrier,
@@ -395,8 +394,8 @@ namespace vkcv {
                 buffer.m_size);
 
         cmdBuffer.pipelineBarrier(
-                vk::PipelineStageFlagBits::eTopOfPipe,
-                vk::PipelineStageFlagBits::eBottomOfPipe,
+                vk::PipelineStageFlagBits::eTransfer,
+                vk::PipelineStageFlagBits::eHost,
                 {},
                 nullptr,
                 memoryBarrier2,
-- 
GitLab