From bee2e7b74a9a2d969800008d3a6bd1242f070fd3 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Mon, 9 Apr 2018 13:18:02 +0100 Subject: [PATCH] added mock image uploader --- WickedEngine/wiGraphicsDevice_Vulkan.cpp | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 066d253e1..2eae824ee 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -1383,6 +1383,10 @@ namespace wiGraphicsTypes { imageInfo.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; } + if (pInitialData != nullptr) + { + imageInfo.usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; + } imageInfo.flags = 0; if ((*ppTexture2D)->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) @@ -1418,6 +1422,49 @@ namespace wiGraphicsTypes + // Issue data copy on request: + if (pInitialData != nullptr) + { + uint8_t* dest = textureUploader->allocate(memRequirements.size, memRequirements.alignment); + + VkBufferImageCopy copyRegions[16] = {}; + assert(pDesc->ArraySize < 16); + + uint32_t width = pDesc->Width; + uint32_t height = pDesc->Height; + for (UINT slice = 0; slice < pDesc->ArraySize; ++slice) + { + memcpy(dest, pInitialData[slice].pSysMem, pInitialData[slice].SysMemPitch * height); // double check!! + + VkBufferImageCopy& copyRegion = copyRegions[slice]; + copyRegion.bufferOffset = 0; + copyRegion.bufferRowLength = 0; + copyRegion.bufferImageHeight = 0; + + // for now, only mips can be filled like this: + copyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + copyRegion.imageSubresource.mipLevel = slice; + copyRegion.imageSubresource.baseArrayLayer = 0; + copyRegion.imageSubresource.layerCount = 1; + + copyRegion.imageOffset = { 0, 0, 0 }; + copyRegion.imageExtent = { + width, + height, + 1 + }; + + width = max(1, width / 2); + height /= max(1, height / 2); + } + + copyQueueLock.lock(); + vkCmdCopyBufferToImage(copyCommandBuffer, textureUploader->resource, *static_cast((*ppTexture2D)->resource_Vulkan), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, pDesc->ArraySize, copyRegions); + copyQueueLock.unlock(); + + } + + // Issue creation of additional descriptors for the resource: