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
7 changes: 5 additions & 2 deletions include/vsg/core/Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ namespace vsg
virtual uint32_t height() const = 0;
virtual uint32_t depth() const = 0;

/// return the {width, height, depth} pixel extents of an image accounting for blockWidth and any mipmapData assigned to image.
std::tuple<uint32_t, uint32_t, uint32_t> pixelExtents() const;
/// return the number of faces - uses properties.imageViewType and depth() value.
std::pair<uint32_t, uint32_t> faceDepthAndCount() const;

/// return the {width, height, depth, layers} pixel extents of an image accounting for blockWidth and any mipmapData assigned to image.
std::tuple<uint32_t, uint32_t, uint32_t, uint32_t> pixelExtents() const;

bool contiguous() const { return valueSize() == properties.stride; }

Expand Down
32 changes: 28 additions & 4 deletions src/vsg/core/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/core/MipmapLayout.h>
#include <vsg/io/Input.h>
#include <vsg/io/Output.h>
#include <vsg/io/Logger.h>

using namespace vsg;

Expand Down Expand Up @@ -145,10 +146,28 @@ const MipmapLayout* Data::getMipmapLayout() const
return getObject<MipmapLayout>("mipmapLayout");
}

std::pair<uint32_t, uint32_t> Data::faceDepthAndCount() const
{
// Use properties.imageViewType to set the face count and face depth https://docs.vulkan.org/refpages/latest/refpages/source/VkImageViewType.html
switch(properties.imageViewType)
{
case(VK_IMAGE_VIEW_TYPE_CUBE):
case(VK_IMAGE_VIEW_TYPE_CUBE_ARRAY):
return {depth()/6, 6};
case(VK_IMAGE_VIEW_TYPE_1D_ARRAY):
case(VK_IMAGE_VIEW_TYPE_2D_ARRAY):
return {1, depth()};
default:
return {depth(), 1};
}
}

std::size_t Data::computeValueCountIncludingMipmaps() const
{
std::size_t count = 0;

auto [faceDepth, faceCount] = faceDepthAndCount();

if (auto mipmapLayout = getMipmapLayout())
{
for (const auto& mipmap : *mipmapLayout)
Expand All @@ -160,12 +179,13 @@ std::size_t Data::computeValueCountIncludingMipmaps() const

count += w * h * d;
}
count *= faceCount;
}
else
{
std::size_t x = width() * properties.blockWidth;
std::size_t y = height() * properties.blockHeight;
std::size_t z = depth() * properties.blockDepth;
std::size_t z = faceDepth * properties.blockDepth;

auto mipLevels = std::max(properties.mipLevels, uint8_t(1));
for (uint8_t level = 0; level < mipLevels; ++level)
Expand All @@ -181,16 +201,20 @@ std::size_t Data::computeValueCountIncludingMipmaps() const
if (y > 1) y = y / 2;
if (z > 1) z = z / 2;
}

count *= faceCount;
}

return count;
}

std::tuple<uint32_t, uint32_t, uint32_t> Data::pixelExtents() const
std::tuple<uint32_t, uint32_t, uint32_t, uint32_t> Data::pixelExtents() const
{
auto [faceDepth, faceCount] = faceDepthAndCount();

uint32_t w = width() * properties.blockWidth;
uint32_t h = height() * properties.blockHeight;
uint32_t d = depth() * properties.blockDepth;
uint32_t d = faceDepth * properties.blockDepth;

if (auto mipmapLayout = getMipmapLayout())
{
Expand All @@ -200,5 +224,5 @@ std::tuple<uint32_t, uint32_t, uint32_t> Data::pixelExtents() const
d = mipmap.z;
}

return {w, h, d};
return {w, h, d, faceCount};
}
18 changes: 1 addition & 17 deletions src/vsg/state/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,57 +40,43 @@ Image::Image(ref_ptr<Data> in_data) :
auto properties = data->properties;
auto dimensions = data->dimensions();

auto [width, height, depth] = data->pixelExtents();
std::tie(extent.width, extent.height, extent.depth, arrayLayers) = data->pixelExtents();

switch (properties.imageViewType)
{
case (VK_IMAGE_VIEW_TYPE_1D):
imageType = VK_IMAGE_TYPE_1D;
arrayLayers = 1;
break;
case (VK_IMAGE_VIEW_TYPE_2D):
imageType = VK_IMAGE_TYPE_2D;
arrayLayers = 1;
break;
case (VK_IMAGE_VIEW_TYPE_3D):
imageType = VK_IMAGE_TYPE_3D;
arrayLayers = 1;
break;
case (VK_IMAGE_VIEW_TYPE_CUBE):
imageType = VK_IMAGE_TYPE_2D;
flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
arrayLayers = depth;
depth = 1;
break;
case (VK_IMAGE_VIEW_TYPE_1D_ARRAY):
imageType = VK_IMAGE_TYPE_1D;
arrayLayers = height * depth;
height = 1;
depth = 1;
/* flags = VK_IMAGE_CREATE_1D_ARRAY_COMPATIBLE_BIT; // comment out as Vulkan headers don't yet provide this. */
break;
case (VK_IMAGE_VIEW_TYPE_2D_ARRAY):
// imageType = VK_IMAGE_TYPE_3D;
// flags = VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT;
imageType = VK_IMAGE_TYPE_2D;
arrayLayers = depth;
depth = 1;
break;
case (VK_IMAGE_VIEW_TYPE_CUBE_ARRAY):
imageType = VK_IMAGE_TYPE_2D;
flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
arrayLayers = depth;
depth = 1;
break;
default:
imageType = dimensions >= 3 ? VK_IMAGE_TYPE_3D : (dimensions == 2 ? VK_IMAGE_TYPE_2D : VK_IMAGE_TYPE_1D);
arrayLayers = 1;
break;
}

format = properties.format;
mipLevels = std::max(1u, static_cast<uint32_t>(data->properties.mipLevels));
extent = VkExtent3D{width, height, depth};

// vsg::info("Image::Image(", data, ") mpipLevels = ", mipLevels);

Expand Down Expand Up @@ -212,8 +198,6 @@ VkResult Image::compile(Device* device)
info.pQueueFamilyIndices = queueFamilyIndices.data();
info.initialLayout = initialLayout;

// vsg::info("Image::compile(), data = ",data, ", mipLevels = ", mipLevels, ", arrayLayers = ", arrayLayers, ", extent = {", extent.width, ", ", extent.height, ", ", extent.depth, "}");

vd.device = device;

vd.requiresDataCopy = data.valid();
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/state/ImageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ uint32_t vsg::computeNumMipMapLevels(const Data* data, const Sampler* sampler)
if (sampler)
{
// clamp the mipLevels so that it's no larger than what the data dimensions support
auto [width, height, depth] = data->pixelExtents();
auto [width, height, depth, numLayers] = data->pixelExtents();
uint32_t maxDimension = std::max({width, height, depth});
if (sampler->maxLod == VK_LOD_CLAMP_NONE)
{
Expand Down
Loading