Skip to content

Commit

Permalink
removing all memory dump strings informations in release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Nov 16, 2023
1 parent 39aa800 commit b882771
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 36 deletions.
8 changes: 6 additions & 2 deletions src/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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();
}

Expand Down
33 changes: 20 additions & 13 deletions src/renderer/buffers/vk_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/buffers/vk_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
};
Expand Down
12 changes: 8 additions & 4 deletions src/renderer/buffers/vk_ubo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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");
Expand Down
31 changes: 24 additions & 7 deletions src/renderer/images/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,18 +44,27 @@ namespace mlx

std::vector<uint16_t> 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
Expand Down Expand Up @@ -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<uint32_t>(getWidth() * getHeight(), 0);
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/images/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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<uint32_t> _cpu_map;
std::optional<Buffer> _buf_map = std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/pixel_put.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down
8 changes: 6 additions & 2 deletions src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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 },
Expand Down
Empty file.
11 changes: 8 additions & 3 deletions src/renderer/text_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -20,8 +20,13 @@ namespace mlx
void TextData::init(std::string text, std::vector<Vertex> vbo_data, std::vector<uint16_t> 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
Expand Down

0 comments on commit b882771

Please sign in to comment.