Skip to content

Commit dec7a9a

Browse files
Merge pull request #1730 from KAlO2/fix/skybox
fix layer offset calculation when uploading cubemaps with MipmapLayout
2 parents 1d019f3 + b8cc22b commit dec7a9a

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/vsg/app/TransferTask.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,25 @@ void vsg::transferImageData(ref_ptr<ImageView> imageView, VkImageLayout targetIm
681681
{
682682
regions.resize(mipLevels * arrayLayers);
683683

684+
// mipmap.x/y/z are texel sizes. Compressed formats store whole blocks,
685+
// so convert texel dimensions to block counts using integer ceil division.
686+
auto ceilDiv = [](uint32_t value, uint32_t divisor) { return (value + divisor - 1) / divisor; };
687+
684688
auto mipmapItr = mipmapData->begin();
685689
for (uint32_t mipLevel = 0; mipLevel < mipLevels; ++mipLevel)
686690
{
687691
const auto& mipmap = (*mipmapItr++);
688692

693+
// faceSize = bytes per layer at this mip.
694+
const size_t faceSize = static_cast<size_t>(valueSize) *
695+
ceilDiv(mipmap.x, properties.blockWidth) *
696+
ceilDiv(mipmap.y, properties.blockHeight) *
697+
ceilDiv(mipmap.z, properties.blockDepth);
698+
689699
for (uint32_t face = 0; face < arrayLayers; ++face)
690700
{
691701
auto& region = regions[mipLevel * arrayLayers + face];
692-
region.bufferOffset = stagingBufferOffset + mipmap.w;
702+
region.bufferOffset = stagingBufferOffset + mipmap.w + face * faceSize;
693703
region.bufferRowLength = 0;
694704
region.bufferImageHeight = 0;
695705
region.imageSubresource.aspectMask = aspectMask;

0 commit comments

Comments
 (0)