Skip to content
Snippets Groups Projects
Commit 7dcc1f7b authored by Lars Hoerttrich's avatar Lars Hoerttrich
Browse files

[#31] Added simple create function

parent 7598c8c2
No related branches found
No related tags found
1 merge request!32Resolve "Image-Klasse"
Pipeline #25196 failed
......@@ -31,8 +31,9 @@ namespace vkcv {
ImageManager& operator=(ImageManager&& other) = delete;
ImageManager& operator=(const ImageManager& other) = delete;
void copyBufferToImage(vk::Buffer bufffer, vk::Image image, uint32_t width, uint32_t height);
uint64_t createImage();
uint64_t createImage(uint32_t width, uint32_t height);
/**
* Destroys and deallocates image represented by a given
......
......@@ -7,6 +7,25 @@
#include "vkcv/Core.hpp"
namespace vkcv {
uint32_t searchMemoryType(const vk::PhysicalDeviceMemoryProperties& physicalMemoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirements) {
const uint32_t memoryCount = physicalMemoryProperties.memoryTypeCount;
for (uint32_t memoryIndex = 0; memoryIndex < memoryCount; ++memoryIndex) {
const uint32_t memoryTypeBits = (1 << memoryIndex);
const bool isRequiredMemoryType = typeBits & memoryTypeBits;
const vk::MemoryPropertyFlags properties =
physicalMemoryProperties.memoryTypes[memoryIndex].propertyFlags;
const bool hasRequiredProperties =
(properties & requirements) == requirements;
if (isRequiredMemoryType && hasRequiredProperties)
return static_cast<int32_t>(memoryIndex);
}
// failed to find memory type
return -1;
}
ImageManager::ImageManager() noexcept :
m_core(nullptr), m_images()
......@@ -19,10 +38,55 @@ namespace vkcv {
}
}
uint64_t ImageManager::createImage()
void ImageManager::copyBufferToImage(vk::Buffer bufffer, vk::Image image, uint32_t width, uint32_t height)
{
//TODO
}
uint64_t ImageManager::createImage(uint32_t width, uint32_t height)
{
vk::ImageCreateFlags createFlags;
vk::ImageUsageFlags imageUsageFlags = (vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst);
vk::Format format = vk::Format::eR8G8B8A8Unorm; // als Argument variabel?
const vk::Device& device = m_core->getContext().getDevice();
vk::ImageCreateInfo imageCreateInfo(
createFlags,
vk::ImageType::e2D,
format, vk::Extent3D(width, height, 1),
1,
1,
vk::SampleCountFlagBits::e1,
vk::ImageTiling::eOptimal,
imageUsageFlags,
vk::SharingMode::eExclusive,
{},
vk::ImageLayout::eUndefined
);
vk::Image image = device.createImage(imageCreateInfo);
return uint64_t();
const vk::MemoryRequirements requirements = device.getImageMemoryRequirements(image);
const vk::PhysicalDevice& physicalDevice = m_core->getContext().getPhysicalDevice();
vk::MemoryPropertyFlags memoryTypeFlags = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent;
bool mappable = false;
const uint32_t memoryTypeIndex = searchMemoryType(
physicalDevice.getMemoryProperties(),
requirements.memoryTypeBits,
memoryTypeFlags
);
vk::DeviceMemory memory = device.allocateMemory(vk::MemoryAllocateInfo(requirements.size, memoryTypeIndex));
device.bindImageMemory(image, memory, 0);
const uint64_t id = m_images.size();
m_images.push_back({ image, memory, nullptr, mappable });
return id;
}
void ImageManager::destroyImage(uint64_t id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment