Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Examples/DownloadImages/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ int main()
RHI::DownloadImageArgs args{};
args.format = RHI::HostImageFormat::RGB8;
args.copyRegion = {{0, 0, 0}, texture->GetDescription().extent};
args.layerIndex = 0;
args.layersCount = 1;
auto future = texture->DownloadImage(args);

while (future.wait_for(std::chrono::milliseconds(100)) == std::future_status::timeout)
Expand Down
19 changes: 6 additions & 13 deletions Examples/test_utils/TestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,25 @@ RHI::ITexture * UploadTexture(const char * path, RHI::IContext * ctx, bool with_

RHI::HostTextureView hostTexture{};
{
hostTexture.extent = {static_cast<uint32_t>(w), static_cast<uint32_t>(h), 1};
hostTexture.extent = {static_cast<RHI::texel_t>(w), static_cast<RHI::texel_t>(h), 1};
hostTexture.pixelData = reinterpret_cast<uint8_t *>(pixel_data);
hostTexture.format = with_alpha ? RHI::HostImageFormat::RGBA8 : RHI::HostImageFormat::RGB8;
hostTexture.layersCount = 1;
hostTexture.type = RHI::ImageType::Image2D;
};

RHI::TextureDescription imageArgs{};
{
imageArgs.extent = hostTexture.extent;
imageArgs.layersCount = hostTexture.layersCount;
imageArgs.type = RHI::ImageType::Image2D;
imageArgs.format = with_alpha ? RHI::ImageFormat::RGBA8 : RHI::ImageFormat::RGB8;
imageArgs.mipLevels = useMips ? RHI::CalcMaxMipLevels(imageArgs.extent) : 1;
;
}
auto texture = ctx->CreateTexture(imageArgs);

RHI::UploadImageArgs args{};
{
args.srcTexture = hostTexture;
args.copyRegion = {{0, 0, 0}, hostTexture.extent};
args.dstOffset = {0, 0, 0};
args.layerIndex = 0;
args.layersCount = 1;
}
texture->UploadImage(args);
if (useMips)
Expand All @@ -91,8 +86,8 @@ RHI::ITexture * UploadLayeredTexture(RHI::IContext * ctx,

auto && hostTexture = textures.emplace_back();
hostTexture.pixelData = pixel_data;
hostTexture.extent = {static_cast<uint32_t>(w), static_cast<uint32_t>(h), 1};
hostTexture.layersCount = 1;
hostTexture.extent = {static_cast<RHI::texel_t>(w), static_cast<RHI::texel_t>(h), 1};
hostTexture.type = RHI::ImageType::Image2D;
hostTexture.format = with_alpha ? RHI::HostImageFormat::RGBA8 : RHI::HostImageFormat::RGB8;
}

Expand All @@ -103,10 +98,10 @@ RHI::ITexture * UploadLayeredTexture(RHI::IContext * ctx,
RHI::TextureDescription imageArgs{};
{
imageArgs.extent = textures.front().extent;
imageArgs.extent[2] = static_cast<uint32_t>(textures.size());
imageArgs.type = RHI::ImageType::Image2D_Array;
imageArgs.format = with_alpha ? RHI::ImageFormat::RGBA8 : RHI::ImageFormat::RGB8;
imageArgs.mipLevels = useMips ? RHI::CalcMaxMipLevels(imageArgs.extent) : 1;
imageArgs.layersCount = static_cast<uint32_t>(textures.size());
}
auto texture = ctx->CreateTexture(imageArgs);

Expand All @@ -117,9 +112,7 @@ RHI::ITexture * UploadLayeredTexture(RHI::IContext * ctx,
{
args.srcTexture = hostTexture;
args.copyRegion = {{0, 0, 0}, {hostTexture.extent}};
args.dstOffset = {0, 0, 0};
args.layerIndex = i;
args.layersCount = 1;
args.dstOffset = {0, 0, static_cast<RHI::texel_t>(i)};
}
texture->UploadImage(args);
}
Expand Down
41 changes: 29 additions & 12 deletions Source/Public/Images.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <array>
#include <cstdint>
#include <limits>

#include <Utils.hpp>

Expand All @@ -11,7 +12,7 @@ namespace RHI

/// @brief Defines image's layout in memory. Also defines if image can have mipmaps or not
/// For example image1d is line of pixels, image2d is a rectangle of pixels
enum class ImageType
enum class ImageType : uint8_t
{
Image1D, ///< image with height = 1. has only width.Can have one mipmap for a whole image
Image2D, ///< generic image with width and height. Can have one mipmap for a whole image
Expand Down Expand Up @@ -69,7 +70,7 @@ enum class ImageFormat : uint8_t
};

/// @brief
enum ShaderAttachmentSlot
enum ShaderAttachmentSlot : uint8_t
{
Color, ///< color attachment
DepthStencil, ///< depth-stencil attachment
Expand All @@ -78,28 +79,30 @@ enum ShaderAttachmentSlot
TOTAL
};

using texel_t = uint16_t;
/// For Image1D used only 0'th index
/// For Image2D used only 0 and 1 index
/// For Image3D used all 3 indices like width, height and layer
/// For Image1D used 0 and 1 index as width and i-th array element
/// For Image2D used all 3 indices as width, height and i-th array element
/// For Cubemap used all 3 indices as width, height and i-th surface of cube
using TexelIndex = std::array<uint32_t, 3>;
using TexelIndex = std::array<texel_t, 3>;
static constexpr texel_t g_InvalidTexel = std::numeric_limits<texel_t>::max();

/// Gabarit of texture
using TextureExtent = TexelIndex;

struct TextureRegion
struct TextureRegion final
{
TexelIndex offset;
TextureExtent extent;
TexelIndex offset{0, 0, 0};
TextureExtent extent{g_InvalidTexel, g_InvalidTexel, g_InvalidTexel};
int reserved = 0;
};


struct TextureDescription final
{
TextureExtent extent;
uint32_t layersCount = 1;
TextureExtent extent; ///< gabarit of texture (width, height, depth/layer)
ImageType type;
ImageFormat format;
uint32_t mipLevels = 1;
Expand All @@ -109,10 +112,24 @@ RHI_API uint32_t CalcMaxMipLevels(TextureExtent extent, uint32_t minLength = 1);

struct HostTextureView final
{
TextureExtent extent;
uint8_t * pixelData = nullptr;
HostImageFormat format;
uint32_t layersCount = 1;
TextureExtent extent{g_InvalidTexel, g_InvalidTexel,
g_InvalidTexel}; ///< size of image (width, height, depth/layers)
uint8_t * pixelData = nullptr; ///< pointer on pixel data
HostImageFormat format; ///< format of pixel
ImageType type; ///< type of image (1D, 2D, 3D, Cubemap, etc)
};

struct UploadImageArgs final
{
HostTextureView srcTexture; ///< host texture
TextureRegion copyRegion{}; ///< subregion of host texture to copy
TexelIndex dstOffset{0, 0, 0}; ///< offset in destination where to copy
};

struct DownloadImageArgs final
{
HostImageFormat format; ///< desired format
TextureRegion copyRegion{};
};

} // namespace RHI
17 changes: 0 additions & 17 deletions Source/Public/RHI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,6 @@ struct IBufferGPU
virtual size_t Size() const noexcept = 0;
};

struct UploadImageArgs final
{
HostTextureView srcTexture;
TextureRegion copyRegion;
TextureExtent dstOffset;
uint32_t layerIndex = 0;
uint32_t layersCount = std::numeric_limits<uint32_t>::max();
};

struct DownloadImageArgs final
{
HostImageFormat format;
TextureRegion copyRegion;
uint32_t layerIndex = 0;
uint32_t layersCount = std::numeric_limits<uint32_t>::max();
};

/// Image with mipmaps, compression
struct ITexture
{
Expand Down
16 changes: 13 additions & 3 deletions Source/Vulkan/Attachments/GenericAttachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ std::future<DownloadResult> GenericAttachment::DownloadImage(HostImageFormat for
DownloadImageArgs args{};
args.format = format;
args.copyRegion = region;
args.layerIndex = 0;
args.layersCount = 1;
return GetContext().GetTransferer().DownloadImage(*this, args);
}

Expand Down Expand Up @@ -191,6 +189,17 @@ uint32_t GenericAttachment::GetLayersCount() const noexcept
return 1;
}

VkImageType GenericAttachment::GetImageType() const noexcept
{
assert(m_description.type == RHI::ImageType::Image2D);
return VK_IMAGE_TYPE_2D;
}

VkImageViewType GenericAttachment::GetImageViewType() const noexcept
{
return VK_IMAGE_VIEW_TYPE_2D;
}

//-------------------- IAttachment interface --------------------

void GenericAttachment::Invalidate()
Expand Down Expand Up @@ -275,7 +284,8 @@ void GenericAttachment::TransferLayout(VkImageLayout layout) noexcept

void GenericAttachment::Resize(const VkExtent2D & new_extent) noexcept
{
m_description.extent = {new_extent.width, new_extent.height, 1};
m_description.extent = {static_cast<texel_t>(new_extent.width),
static_cast<texel_t>(new_extent.height), 1};
m_changedSize = true;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Vulkan/Attachments/GenericAttachment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct GenericAttachment : public IAttachment,
virtual VkExtent3D GetInternalExtent() const noexcept override;
virtual uint32_t GetMipLevelsCount() const noexcept override;
virtual uint32_t GetLayersCount() const noexcept override;
virtual VkImageType GetImageType() const noexcept override;
virtual VkImageViewType GetImageViewType() const noexcept override;

public: // IInternalAttachment interface
virtual void Invalidate() override;
Expand Down
15 changes: 12 additions & 3 deletions Source/Vulkan/Attachments/SurfacedAttachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ std::future<DownloadResult> SurfacedAttachment::DownloadImage(HostImageFormat fo
DownloadImageArgs args{};
args.format = format;
args.copyRegion = region;
args.layerIndex = 0;
args.layersCount = 1;
return GetContext().GetTransferer().DownloadImage(*this, args);
}

Expand All @@ -49,7 +47,8 @@ TextureDescription SurfacedAttachment::GetDescription() const noexcept
description.mipLevels = 1;
description.type = RHI::ImageType::Image2D;
auto extent = GetInternalExtent();
description.extent = {extent.width, extent.height, extent.depth};
description.extent = {static_cast<texel_t>(extent.width), static_cast<texel_t>(extent.height),
static_cast<texel_t>(extent.depth)};
description.format = g_imagesFormat;
}
return description;
Expand Down Expand Up @@ -115,6 +114,16 @@ uint32_t SurfacedAttachment::GetLayersCount() const noexcept
return 1;
}

VkImageType SurfacedAttachment::GetImageType() const noexcept
{
return VK_IMAGE_TYPE_2D;
}

VkImageViewType SurfacedAttachment::GetImageViewType() const noexcept
{
return VK_IMAGE_VIEW_TYPE_2D;
}

void SurfacedAttachment::BlitTo(ITexture * texture)
{
//if (auto * ptr = dynamic_cast<RHI::vulkan::IInternalTexture *>(texture))
Expand Down
2 changes: 2 additions & 0 deletions Source/Vulkan/Attachments/SurfacedAttachment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct SurfacedAttachment : public IAttachment,
virtual VkExtent3D GetInternalExtent() const noexcept override;
virtual uint32_t GetMipLevelsCount() const noexcept override;
virtual uint32_t GetLayersCount() const noexcept override;
virtual VkImageType GetImageType() const noexcept override;
virtual VkImageViewType GetImageViewType() const noexcept override;

public: // IAttachment interface
virtual void BlitTo(ITexture * texture) override;
Expand Down
Loading
Loading