vulkantexture2d

vkCmdCopyBufferToImage for Texture2DArray


I'm trying to create Image array from 576x112 texture with single channel. I try create 48x112 per layer, so arrayLevel is set to 12.

input texture

Then I upload data using staging buffer and it looks like this result

I try different bufferRowLength, final image become more ugly, and bufferImageHeight don't affects the final result

vk::BufferImageCopy buffer_image_copies[12] = {};
for (u32 i = 0; i < 12; ++i) {
    // Copy only the first layer of the texture
    buffer_image_copies[i].bufferOffset = 0;
    buffer_image_copies[i].bufferRowLength = 48;
    buffer_image_copies[i].bufferImageHeight = 112;
    buffer_image_copies[i].imageSubresource.aspectMask = vk::ImageAspectFlagBits::eColor;
    buffer_image_copies[i].imageSubresource.mipLevel = 0;
    buffer_image_copies[i].imageSubresource.baseArrayLayer = i;
    buffer_image_copies[i].imageSubresource.layerCount = 1;
    buffer_image_copies[i].imageOffset = vk::Offset3D(0, 0, 0);
    buffer_image_copies[i].imageExtent = vk::Extent3D(48, height, 1);
}
command_buffer.copyBufferToImage(staging_buffer, car_volume_texture.image, vk::ImageLayout::eTransferDstOptimal, 12, buffer_image_copies);


Solution

  • It was wrong size in memcpy when data copied to staging buffer, everything is ok now