From b882771a18ba2a926493cacdb6656083e02959ec Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Thu, 16 Nov 2023 14:04:51 +0100 Subject: [PATCH] removing all memory dump strings informations in release mode --- src/core/application.cpp | 8 +++-- src/renderer/buffers/vk_buffer.cpp | 33 +++++++++++-------- src/renderer/buffers/vk_buffer.h | 6 ++-- src/renderer/buffers/vk_ubo.cpp | 12 ++++--- src/renderer/images/texture.cpp | 31 +++++++++++++---- src/renderer/images/texture.h | 6 ++-- src/renderer/pixel_put.cpp | 2 +- src/renderer/renderer.cpp | 8 +++-- .../swapchain/vk_imageview-9818877f.o.tmp | 0 src/renderer/text_library.cpp | 11 +++++-- 10 files changed, 81 insertions(+), 36 deletions(-) create mode 100644 src/renderer/swapchain/vk_imageview-9818877f.o.tmp diff --git a/src/core/application.cpp b/src/core/application.cpp index f717ecd..8939d96 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */ -/* Updated: 2023/11/14 03:20:40 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 13:47:50 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,7 +44,11 @@ namespace mlx::core void* Application::newTexture(int w, int h) { - _textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM, "__mlx_unamed_user_texture"); + #ifdef DEBUG + _textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM, "__mlx_unamed_user_texture"); + #else + _textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM, nullptr); + #endif return &_textures.front(); } diff --git a/src/renderer/buffers/vk_buffer.cpp b/src/renderer/buffers/vk_buffer.cpp index 678ccf6..5c1f2ec 100644 --- a/src/renderer/buffers/vk_buffer.cpp +++ b/src/renderer/buffers/vk_buffer.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 18:55:57 by maldavid #+# #+# */ -/* Updated: 2023/11/14 09:31:58 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 13:54:25 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,15 +67,19 @@ namespace mlx bufferInfo.usage = usage; bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - _name = name; - std::string alloc_name = _name; - if(usage & VK_BUFFER_USAGE_INDEX_BUFFER_BIT) - alloc_name.append("_index_buffer"); - else if(usage & VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) - alloc_name.append("_vertex_buffer"); - else if((usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 1) - alloc_name.append("_buffer"); - _allocation = Render_Core::get().getAllocator().createBuffer(&bufferInfo, &info, _buffer, alloc_name.c_str()); + #ifdef DEBUG + _name = name; + std::string alloc_name = _name; + if(usage & VK_BUFFER_USAGE_INDEX_BUFFER_BIT) + alloc_name.append("_index_buffer"); + else if(usage & VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) + alloc_name.append("_vertex_buffer"); + else if((usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 1) + alloc_name.append("_buffer"); + _allocation = Render_Core::get().getAllocator().createBuffer(&bufferInfo, &info, _buffer, alloc_name.c_str()); + #else + _allocation = Render_Core::get().getAllocator().createBuffer(&bufferInfo, &info, _buffer, nullptr); + #endif _size = size; } @@ -84,11 +88,14 @@ namespace mlx VmaAllocationCreateInfo alloc_info{}; alloc_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; - std::string new_name = _name + "_GPU"; - Buffer newBuffer; newBuffer._usage = (_usage & 0xFFFFFFFC) | VK_BUFFER_USAGE_TRANSFER_DST_BIT; - newBuffer.createBuffer(newBuffer._usage, alloc_info, _size, new_name.c_str()); + #ifdef DEBUG + std::string new_name = _name + "_GPU"; + newBuffer.createBuffer(newBuffer._usage, alloc_info, _size, new_name.c_str()); + #else + newBuffer.createBuffer(newBuffer._usage, alloc_info, _size, nullptr); + #endif CmdPool cmdpool; cmdpool.init(); diff --git a/src/renderer/buffers/vk_buffer.h b/src/renderer/buffers/vk_buffer.h index c45f3be..3cad686 100644 --- a/src/renderer/buffers/vk_buffer.h +++ b/src/renderer/buffers/vk_buffer.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/06 23:18:52 by maldavid #+# #+# */ -/* Updated: 2023/11/14 03:24:12 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 13:56:19 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,7 +51,9 @@ namespace mlx void createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info, VkDeviceSize size, const char* name); private: - std::string _name; + #ifdef DEBUG + std::string _name; + #endif VkBufferUsageFlags _usage = 0; bool _is_mapped = false; }; diff --git a/src/renderer/buffers/vk_ubo.cpp b/src/renderer/buffers/vk_ubo.cpp index fbc0927..70ceae5 100644 --- a/src/renderer/buffers/vk_ubo.cpp +++ b/src/renderer/buffers/vk_ubo.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/06 18:45:52 by maldavid #+# #+# */ -/* Updated: 2023/11/14 03:27:08 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 13:57:42 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,9 +22,13 @@ namespace mlx for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { - std::string name_frame = name; - name_frame.append(std::to_string(i)); - _buffers[i].create(Buffer::kind::uniform, size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, name_frame.c_str()); + #ifdef DEBUG + std::string name_frame = name; + name_frame.append(std::to_string(i)); + _buffers[i].create(Buffer::kind::uniform, size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, name_frame.c_str()); + #else + _buffers[i].create(Buffer::kind::uniform, size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, nullptr); + #endif _buffers[i].mapMem(&_maps[i]); if(_maps[i] == nullptr) core::error::report(e_kind::fatal_error, "Vulkan : unable to map a uniform buffer"); diff --git a/src/renderer/images/texture.cpp b/src/renderer/images/texture.cpp index 496bb97..694bd37 100644 --- a/src/renderer/images/texture.cpp +++ b/src/renderer/images/texture.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */ -/* Updated: 2023/11/14 04:57:55 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 14:01:47 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,18 +44,27 @@ namespace mlx std::vector indexData = { 0, 1, 2, 2, 3, 0 }; - _vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data(), name); - _ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data(), name); + #ifdef DEBUG + _vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data(), name); + _ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data(), name); + _name = name; + #else + _vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data(), nullptr); + _ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data(), nullptr); + #endif if(pixels != nullptr) { Buffer staging_buffer; std::size_t size = width * height * formatSize(format); - staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, name, pixels); + #ifdef DEBUG + staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, name, pixels); + #else + staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, nullptr, pixels); + #endif Image::copyFromBuffer(staging_buffer); staging_buffer.destroy(); } - _name = name; } void Texture::setPixel(int x, int y, uint32_t color) noexcept @@ -88,7 +97,11 @@ namespace mlx #endif std::size_t size = getWidth() * getHeight() * formatSize(getFormat()); _buf_map.emplace(); - _buf_map->create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, _name.c_str()); + #ifdef DEBUG + _buf_map->create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, _name.c_str()); + #else + _buf_map->create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, nullptr); + #endif Image::copyToBuffer(*_buf_map); _buf_map->mapMem(&_map); _cpu_map = std::vector(getWidth() * getHeight(), 0); @@ -135,7 +148,11 @@ namespace mlx if(stbi_is_hdr(filename.c_str())) core::error::report(e_kind::fatal_error, "Texture : unsupported image format '%s'", filename.c_str()); data = stbi_load(filename.c_str(), w, h, &channels, 4); - texture.create(data, *w, *h, VK_FORMAT_R8G8B8A8_UNORM, filename.c_str()); + #ifdef DEBUG + texture.create(data, *w, *h, VK_FORMAT_R8G8B8A8_UNORM, filename.c_str()); + #else + texture.create(data, *w, *h, VK_FORMAT_R8G8B8A8_UNORM, nullptr); + #endif stbi_image_free(data); return texture; } diff --git a/src/renderer/images/texture.h b/src/renderer/images/texture.h index 536975a..d02ad6c 100644 --- a/src/renderer/images/texture.h +++ b/src/renderer/images/texture.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */ -/* Updated: 2023/11/14 04:57:39 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 14:01:05 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,7 +50,9 @@ namespace mlx private: C_VBO _vbo; C_IBO _ibo; - std::string _name; + #ifdef DEBUG + std::string _name; + #endif DescriptorSet _set; std::vector _cpu_map; std::optional _buf_map = std::nullopt; diff --git a/src/renderer/pixel_put.cpp b/src/renderer/pixel_put.cpp index bb57994..00349e4 100644 --- a/src/renderer/pixel_put.cpp +++ b/src/renderer/pixel_put.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */ -/* Updated: 2023/11/14 04:58:13 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 13:44:58 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index d40676c..b830e68 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */ -/* Updated: 2023/11/14 04:59:38 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 13:48:42 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,11 @@ namespace mlx _semaphores[i].init(); _uniform_buffer.reset(new UBO); - _uniform_buffer->create(this, sizeof(glm::mat4), "__mlx_matrices_uniform_buffer_"); + #ifdef DEBUG + _uniform_buffer->create(this, sizeof(glm::mat4), "__mlx_matrices_uniform_buffer_"); + #else + _uniform_buffer->create(this, sizeof(glm::mat4), nullptr); + #endif VkDescriptorPoolSize pool_sizes[] = { { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4096 }, diff --git a/src/renderer/swapchain/vk_imageview-9818877f.o.tmp b/src/renderer/swapchain/vk_imageview-9818877f.o.tmp new file mode 100644 index 0000000..e69de29 diff --git a/src/renderer/text_library.cpp b/src/renderer/text_library.cpp index 78d1bda..ec34951 100644 --- a/src/renderer/text_library.cpp +++ b/src/renderer/text_library.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */ -/* Updated: 2023/11/14 05:39:40 by maldavid ### ########.fr */ +/* Updated: 2023/11/16 13:45:31 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,8 +20,13 @@ namespace mlx void TextData::init(std::string text, std::vector vbo_data, std::vector ibo_data) { _text = std::move(text); - _vbo.create(sizeof(Vertex) * vbo_data.size(), vbo_data.data(), _text.c_str()); - _ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), _text.c_str()); + #ifdef DEBUG + _vbo.create(sizeof(Vertex) * vbo_data.size(), vbo_data.data(), _text.c_str()); + _ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), _text.c_str()); + #else + _vbo.create(sizeof(Vertex) * vbo_data.size(), vbo_data.data(), nullptr); + _ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), nullptr); + #endif } void TextData::bind(Renderer& renderer) noexcept