MCPcopy Create free account
hub / github.com/GPUOpen-LibrariesAndSDKs/Cauldron / LoadAndUpload

Method LoadAndUpload

src/VK/base/Texture.cpp:392–478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390 }
391
392 void Texture::LoadAndUpload(Device *pDevice, UploadHeap *pUploadHeap, ImgLoader *pDds, VkImage pTexture2D)
393 {
394 // Upload Image
395 {
396 VkImageMemoryBarrier copy_barrier = {};
397 copy_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
398 copy_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
399 copy_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
400 copy_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
401 copy_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
402 copy_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
403 copy_barrier.image = pTexture2D;
404 copy_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
405 copy_barrier.subresourceRange.baseMipLevel = 0;
406 copy_barrier.subresourceRange.levelCount = m_header.mipMapCount;
407 copy_barrier.subresourceRange.layerCount = m_header.arraySize;
408 pUploadHeap->AddPreBarrier(copy_barrier);
409 }
410
411 //compute pixel size
412 //
413 UINT32 bytesPerPixel = (UINT32)GetPixelByteSize((DXGI_FORMAT)m_header.format); // note that bytesPerPixel in BC formats is treated as bytesPerBlock
414 UINT32 pixelsPerBlock = 1;
415 if (IsBCFormat(m_header.format))
416 {
417 pixelsPerBlock = 4*4; // BC formats have 4*4 pixels per block
418 }
419
420 for (uint32_t a = 0; a < m_header.arraySize; a++)
421 {
422 // copy all the mip slices into the offsets specified by the footprint structure
423 //
424 for (uint32_t mip = 0; mip < m_header.mipMapCount; mip++)
425 {
426 uint32_t dwWidth = std::max<uint32_t>(m_header.width >> mip, 1);
427 uint32_t dwHeight = std::max<uint32_t>(m_header.height >> mip, 1);
428
429 UINT64 UplHeapSize = (dwWidth * dwHeight * bytesPerPixel) / pixelsPerBlock;
430 UINT8 *pixels = pUploadHeap->BeginSuballocate(SIZE_T(UplHeapSize), 512);
431
432 if (pixels == NULL)
433 {
434 // oh! We ran out of mem in the upload heap, flush it and try allocating mem from it again
435 pUploadHeap->FlushAndFinish(true);
436 pixels = pUploadHeap->Suballocate(SIZE_T(UplHeapSize), 512);
437 assert(pixels != NULL);
438 }
439
440 uint32_t offset = uint32_t(pixels - pUploadHeap->BasePtr());
441
442 pDds->CopyPixels(pixels, (dwWidth * bytesPerPixel) / pixelsPerBlock, (dwWidth * bytesPerPixel) / pixelsPerBlock, dwHeight);
443
444 pUploadHeap->EndSuballocate();
445
446 {
447 VkBufferImageCopy region = {};
448 region.bufferOffset = offset;
449 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;

Callers

nothing calls this directly

Calls 11

GetPixelByteSizeFunction · 0.85
IsBCFormatFunction · 0.85
AddPreBarrierMethod · 0.80
AddPostBarrierMethod · 0.80
BeginSuballocateMethod · 0.45
FlushAndFinishMethod · 0.45
SuballocateMethod · 0.45
BasePtrMethod · 0.45
CopyPixelsMethod · 0.45
EndSuballocateMethod · 0.45
AddCopyMethod · 0.45

Tested by

no test coverage detected