100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
#ifndef GPUIMAGE_H
|
|
#define GPUIMAGE_H
|
|
|
|
#include <cstdint>
|
|
#include <cassert>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
#include <vulkan/vulkan.h>
|
|
#include <vk_mem_alloc.h>
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <destrum/Graphics/ids.h>
|
|
|
|
struct GPUImage {
|
|
GPUImage() = default;
|
|
~GPUImage() = default;
|
|
GPUImage(const GPUImage&) = delete;
|
|
GPUImage& operator=(const GPUImage&) = delete;
|
|
|
|
GPUImage(GPUImage&& other) noexcept {
|
|
*this = std::move(other);
|
|
}
|
|
|
|
GPUImage& operator=(GPUImage&& other) noexcept {
|
|
if (this == &other) {
|
|
return *this;
|
|
}
|
|
|
|
image = other.image;
|
|
imageView = other.imageView;
|
|
allocation = other.allocation;
|
|
format = other.format;
|
|
usage = other.usage;
|
|
extent = other.extent;
|
|
layout = other.layout;
|
|
mipLevels = other.mipLevels;
|
|
numLayers = other.numLayers;
|
|
layerLayouts = std::move(other.layerLayouts);
|
|
isCubemap = other.isCubemap;
|
|
debugName = std::move(other.debugName);
|
|
id = other.id;
|
|
|
|
other.image = VK_NULL_HANDLE;
|
|
other.imageView = VK_NULL_HANDLE;
|
|
other.allocation = VK_NULL_HANDLE;
|
|
other.id = NULL_BINDLESS_ID;
|
|
return *this;
|
|
}
|
|
|
|
VkImage image{VK_NULL_HANDLE};
|
|
VkImageView imageView{VK_NULL_HANDLE};
|
|
VmaAllocation allocation{VK_NULL_HANDLE};
|
|
VkFormat format{VK_FORMAT_UNDEFINED};
|
|
VkImageUsageFlags usage{0};
|
|
VkExtent3D extent{};
|
|
mutable VkImageLayout layout{VK_IMAGE_LAYOUT_UNDEFINED};
|
|
std::uint32_t mipLevels{1};
|
|
std::uint32_t numLayers{1};
|
|
mutable std::vector<VkImageLayout> layerLayouts;
|
|
bool isCubemap{false};
|
|
std::string debugName{};
|
|
|
|
[[nodiscard]] glm::ivec2 getSize2D() const { return glm::ivec2{extent.width, extent.height}; }
|
|
[[nodiscard]] VkExtent2D getExtent2D() const { return VkExtent2D{extent.width, extent.height}; }
|
|
|
|
[[nodiscard]] VkImageLayout getLayout(std::uint32_t layer = 0) const
|
|
{
|
|
return layerLayouts.empty() ? layout : layerLayouts.at(layer);
|
|
}
|
|
|
|
void setLayout(VkImageLayout newLayout, std::uint32_t layer = 0) const
|
|
{
|
|
layout = newLayout;
|
|
if (!layerLayouts.empty()) {
|
|
layerLayouts.at(layer) = newLayout;
|
|
}
|
|
}
|
|
|
|
[[nodiscard]] BindlessID getBindlessId() const
|
|
{
|
|
assert(id != NULL_BINDLESS_ID && "Image wasn't added to bindless set");
|
|
return id;
|
|
}
|
|
|
|
// should be called by ImageCache only
|
|
void setBindlessId(const std::uint32_t bindlessId)
|
|
{
|
|
assert(bindlessId != NULL_BINDLESS_ID);
|
|
id = bindlessId;
|
|
}
|
|
|
|
[[nodiscard]] bool isInitialized() const { return id != NULL_BINDLESS_ID; }
|
|
|
|
private:
|
|
std::uint32_t id{NULL_BINDLESS_ID}; // bindless id - always equals to ImageId
|
|
};
|
|
|
|
#endif //GPUIMAGE_H
|