Files
Seele/src/Engine/Graphics/Vulkan/Texture.h
T

215 lines
5.7 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#pragma once
#include "Graphics/Texture.h"
#include "Graphics.h"
#include "Allocator.h"
namespace Seele
{
namespace Vulkan
{
2023-11-15 17:42:57 +01:00
class TextureBase
2023-10-26 18:37:29 +02:00
{
public:
2023-11-15 17:42:57 +01:00
TextureBase(PGraphics graphics, VkImageViewType viewType,
2023-10-26 18:37:29 +02:00
const TextureCreateInfo& createInfo, Gfx::QueueType& owner, VkImage existingImage = VK_NULL_HANDLE);
2023-11-15 17:42:57 +01:00
virtual ~TextureBase();
2023-12-10 22:27:59 +01:00
uint32 getWidth() const
{
return width;
}
uint32 getHeight() const
{
return height;
}
uint32 getDepth() const
{
return depth;
}
2023-11-15 17:42:57 +01:00
constexpr VkImage getImage() const
2023-10-26 18:37:29 +02:00
{
return image;
}
2023-11-15 17:42:57 +01:00
constexpr VkImageView getView() const
2023-10-26 18:37:29 +02:00
{
2023-11-17 22:31:26 +01:00
return imageView;
2023-10-26 18:37:29 +02:00
}
2023-11-15 17:42:57 +01:00
constexpr Gfx::SeImageLayout getLayout() const
2023-10-26 18:37:29 +02:00
{
return layout;
}
2023-11-15 17:42:57 +01:00
constexpr VkImageAspectFlags getAspect() const
2023-10-26 18:37:29 +02:00
{
return aspect;
}
2023-11-15 17:42:57 +01:00
constexpr VkImageUsageFlags getUsage() const
2023-10-26 18:37:29 +02:00
{
return usage;
}
2023-11-15 17:42:57 +01:00
constexpr Gfx::SeFormat getFormat() const
2023-10-26 18:37:29 +02:00
{
return format;
}
2023-11-15 17:42:57 +01:00
constexpr Gfx::SeSampleCountFlags getNumSamples() const
2023-10-26 18:37:29 +02:00
{
return samples;
}
2023-11-15 17:42:57 +01:00
constexpr uint32 getMipLevels() const
2023-10-26 18:37:29 +02:00
{
return mipLevels;
}
2023-11-15 17:42:57 +01:00
constexpr bool isDepthStencil() const
2023-10-26 18:37:29 +02:00
{
return aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
}
void executeOwnershipBarrier(Gfx::QueueType newOwner);
void executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
void changeLayout(Gfx::SeImageLayout newLayout);
void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer);
2023-11-15 17:42:57 +01:00
protected:
2023-10-26 18:37:29 +02:00
//Updates via reference
Gfx::QueueType& currentOwner;
PGraphics graphics;
2023-11-01 23:12:30 +01:00
OSubAllocation allocation;
2023-11-15 17:42:57 +01:00
uint32 width;
uint32 height;
uint32 depth;
2023-10-26 18:37:29 +02:00
uint32 arrayCount;
uint32 layerCount;
uint32 mipLevels;
uint32 samples;
Gfx::SeFormat format;
Gfx::SeImageUsageFlags usage;
VkImage image;
2023-11-17 22:31:26 +01:00
VkImageView imageView;
2023-10-26 18:37:29 +02:00
VkImageAspectFlags aspect;
Gfx::SeImageLayout layout;
2023-11-17 22:31:26 +01:00
uint8 ownsImage;
2023-10-26 18:37:29 +02:00
friend class Graphics;
};
2023-12-10 22:27:59 +01:00
DEFINE_REF(TextureBase)
2023-10-26 18:37:29 +02:00
class Texture2D : public Gfx::Texture2D, public TextureBase
{
public:
Texture2D(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage = VK_NULL_HANDLE);
virtual ~Texture2D();
2023-11-15 00:06:00 +01:00
virtual uint32 getWidth() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return width;
2023-10-26 18:37:29 +02:00
}
2023-11-15 00:06:00 +01:00
virtual uint32 getHeight() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return height;
2023-10-26 18:37:29 +02:00
}
2023-11-15 00:06:00 +01:00
virtual uint32 getDepth() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return depth;
2023-10-26 18:37:29 +02:00
}
virtual Gfx::SeFormat getFormat() const override
{
2023-11-15 17:42:57 +01:00
return format;
2023-10-26 18:37:29 +02:00
}
virtual Gfx::SeSampleCountFlags getNumSamples() const override
{
2023-11-15 17:42:57 +01:00
return samples;
2023-10-26 18:37:29 +02:00
}
virtual uint32 getMipLevels() const override
{
2023-11-15 17:42:57 +01:00
return mipLevels;
2023-10-26 18:37:29 +02:00
}
virtual void changeLayout(Gfx::SeImageLayout newLayout) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
2023-11-15 17:42:57 +01:00
2023-10-26 18:37:29 +02:00
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner);
virtual void executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
};
DEFINE_REF(Texture2D)
class Texture3D : public Gfx::Texture3D, public TextureBase
{
public:
Texture3D(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage = VK_NULL_HANDLE);
virtual ~Texture3D();
2023-11-15 00:06:00 +01:00
virtual uint32 getWidth() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return width;
2023-10-26 18:37:29 +02:00
}
2023-11-15 00:06:00 +01:00
virtual uint32 getHeight() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return height;
2023-10-26 18:37:29 +02:00
}
2023-11-15 00:06:00 +01:00
virtual uint32 getDepth() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return depth;
2023-10-26 18:37:29 +02:00
}
virtual Gfx::SeFormat getFormat() const override
{
2023-11-15 17:42:57 +01:00
return format;
2023-10-26 18:37:29 +02:00
}
virtual Gfx::SeSampleCountFlags getNumSamples() const override
{
2023-11-15 17:42:57 +01:00
return samples;
2023-10-26 18:37:29 +02:00
}
virtual uint32 getMipLevels() const override
{
2023-11-15 17:42:57 +01:00
return mipLevels;
2023-10-26 18:37:29 +02:00
}
virtual void changeLayout(Gfx::SeImageLayout newLayout) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
2023-11-15 17:42:57 +01:00
2023-10-26 18:37:29 +02:00
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner);
virtual void executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
};
DEFINE_REF(Texture3D)
class TextureCube : public Gfx::TextureCube, public TextureBase
{
public:
TextureCube(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage = VK_NULL_HANDLE);
virtual ~TextureCube();
2023-11-15 00:06:00 +01:00
virtual uint32 getWidth() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return width;
2023-10-26 18:37:29 +02:00
}
2023-11-15 00:06:00 +01:00
virtual uint32 getHeight() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return height;
2023-10-26 18:37:29 +02:00
}
2023-11-15 00:06:00 +01:00
virtual uint32 getDepth() const override
2023-10-26 18:37:29 +02:00
{
2023-11-15 17:42:57 +01:00
return depth;
2023-10-26 18:37:29 +02:00
}
virtual Gfx::SeFormat getFormat() const override
{
2023-11-15 17:42:57 +01:00
return format;
2023-10-26 18:37:29 +02:00
}
virtual Gfx::SeSampleCountFlags getNumSamples() const override
{
2023-11-15 17:42:57 +01:00
return samples;
2023-10-26 18:37:29 +02:00
}
virtual uint32 getMipLevels() const override
{
2023-11-15 17:42:57 +01:00
return mipLevels;
2023-10-26 18:37:29 +02:00
}
virtual void changeLayout(Gfx::SeImageLayout newLayout) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner);
virtual void executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
};
DEFINE_REF(TextureCube)
}
}