Fixed memory allocation issue caused by return of wrong value in choose_heap
This commit is contained in:
parent
1ded230ffb
commit
c8efb2fa5d
@ -50,7 +50,7 @@ add_dependencies(pleascach shaders)
|
||||
# copy assets somewhere accessible by the accessable
|
||||
add_custom_command(
|
||||
TARGET shaders POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
COMMAND cmake -E copy_directory
|
||||
"$<TARGET_PROPERTY:pleascach,SOURCE_DIR>/assets"
|
||||
"$<TARGET_PROPERTY:pleascach,BINARY_DIR>/assets")
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include <Memory/Buffer.hpp>
|
||||
#include <Memory/Memory.hpp>
|
||||
|
||||
#include <util/log.hpp>
|
||||
|
||||
Buffer::Buffer(vk::PhysicalDevice phys_dev, vk::Device dev, vk::DeviceSize sz, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags mem_flags, vk::SharingMode sharing) : dev(dev), size(sz) {
|
||||
auto info = vk::BufferCreateInfo {
|
||||
.size = sz,
|
||||
@ -9,6 +11,8 @@ Buffer::Buffer(vk::PhysicalDevice phys_dev, vk::Device dev, vk::DeviceSize sz, v
|
||||
};
|
||||
buffer = dev.createBuffer(info);
|
||||
|
||||
Log::debug("Is memory flagged for host: %d\n", mem_flags & vk::MemoryPropertyFlagBits::eHostVisible);
|
||||
|
||||
auto reqs = dev.getBufferMemoryRequirements(buffer);
|
||||
auto alloc_info = vk::MemoryAllocateInfo{
|
||||
.allocationSize = reqs.size,
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
struct Buffer {
|
||||
Buffer(vk::PhysicalDevice phys_dev, vk::Device dev, vk::DeviceSize sz, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags mem_flags, vk::SharingMode sharing = vk::SharingMode::eExclusive);
|
||||
|
||||
vk::DeviceSize size;
|
||||
vk::Device dev;
|
||||
vk::DeviceSize size;
|
||||
vk::DeviceMemory memory;
|
||||
vk::Buffer buffer;
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ namespace mem {
|
||||
auto dev_props = phys_dev.getMemoryProperties();
|
||||
|
||||
if(static_cast<int>(pref_flags.operator VkImageCreateFlags()) != -1) {
|
||||
|
||||
/* try to find an exact match for preferred flags first */
|
||||
for (u32 memory_type = 0; memory_type < 32; memory_type++) {
|
||||
if (requirements.memoryTypeBits & (1 << memory_type)) {
|
||||
@ -17,11 +16,11 @@ namespace mem {
|
||||
}
|
||||
}
|
||||
|
||||
for (u32 memory_type = 0; memory_type < 32; memory_type++) {
|
||||
for (u32 memory_type = 0; memory_type < dev_props.memoryTypeCount; memory_type++) {
|
||||
if (requirements.memoryTypeBits & (1 << memory_type)) {
|
||||
const auto& type = dev_props.memoryTypes[memory_type];
|
||||
if ((type.propertyFlags & req_flags) == req_flags) {
|
||||
return type.heapIndex;
|
||||
return memory_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,6 +173,8 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
|
||||
}
|
||||
|
||||
pipeline = res.value;
|
||||
|
||||
dev.destroyPipelineLayout(layout);
|
||||
}
|
||||
|
||||
void GraphicsPipeline::update(uint32_t binding, const UniformBuffer& uni) {
|
||||
|
||||
@ -188,6 +188,9 @@ Renderer::Renderer(Window& win) : win(win) {
|
||||
};
|
||||
|
||||
pipeline = std::make_unique<GraphicsPipeline>(dev, shaders, swapchain->extent, *render_pass, bindings, *vertex_buffer);
|
||||
|
||||
shaders[0].cleanup();
|
||||
shaders[1].cleanup();
|
||||
}
|
||||
|
||||
void Renderer::draw() {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
Shader::Shader(vk::Device dev, const std::string& fname, vk::ShaderStageFlagBits stage) : fname(fname), stage(stage) {
|
||||
Shader::Shader(vk::Device dev, const std::string& fname, vk::ShaderStageFlagBits stage) : dev(dev), fname(fname), stage(stage) {
|
||||
std::vector<uint8_t> src;
|
||||
try {
|
||||
src = file::slurpb(fname);
|
||||
@ -25,6 +25,6 @@ Shader::Shader(vk::Device dev, const std::string& fname, vk::ShaderStageFlagBits
|
||||
Log::info("Successfully created shader "s + fname + "\n");
|
||||
}
|
||||
|
||||
void Shader::cleanup(vk::Device dev) {
|
||||
void Shader::cleanup() {
|
||||
dev.destroyShaderModule(module);
|
||||
}
|
||||
|
||||
@ -4,11 +4,13 @@
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
struct Shader {
|
||||
vk::ShaderModule module;
|
||||
vk::Device dev;
|
||||
std::string fname;
|
||||
vk::ShaderStageFlagBits stage;
|
||||
vk::ShaderModule module;
|
||||
|
||||
Shader(vk::Device dev, const std::string& fname, vk::ShaderStageFlagBits stage);
|
||||
void cleanup(vk::Device dev);
|
||||
void cleanup();
|
||||
|
||||
inline operator vk::ShaderModule() const {
|
||||
return module;
|
||||
@ -26,6 +28,4 @@ struct Shader {
|
||||
};
|
||||
}
|
||||
|
||||
std::string fname;
|
||||
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#version 460 core
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
|
||||
layout (set = 1, binding = 0) uniform Matrices {
|
||||
layout (set = 0, binding = 0) uniform Matrices {
|
||||
mat4 mpv;
|
||||
float time;
|
||||
};
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user