| 506 | } |
| 507 | |
| 508 | void Texture::LoadAndUpload(Device* pDevice, UploadHeap* pUploadHeap, ImgLoader* pDds, ID3D12Resource* pRes) |
| 509 | { |
| 510 | // Get mip footprints (if it is an array we reuse the mip footprints for all the elements of the array) |
| 511 | // |
| 512 | UINT64 UplHeapSize; |
| 513 | uint32_t num_rows[D3D12_REQ_MIP_LEVELS] = { 0 }; |
| 514 | UINT64 row_sizes_in_bytes[D3D12_REQ_MIP_LEVELS] = { 0 }; |
| 515 | D3D12_PLACED_SUBRESOURCE_FOOTPRINT placedTex2D[D3D12_REQ_MIP_LEVELS]; |
| 516 | CD3DX12_RESOURCE_DESC RDescs = CD3DX12_RESOURCE_DESC::Tex2D((DXGI_FORMAT)m_header.format, m_header.width, m_header.height, 1, m_header.mipMapCount); |
| 517 | pDevice->GetDevice()->GetCopyableFootprints(&RDescs, 0, m_header.mipMapCount, 0, placedTex2D, num_rows, row_sizes_in_bytes, &UplHeapSize); |
| 518 | |
| 519 | //compute pixel size |
| 520 | // |
| 521 | UINT32 bytePP = (UINT32)GetPixelByteSize((DXGI_FORMAT)m_header.format); // note that bytesPerPixel in BC formats is treated as bytesPerBlock |
| 522 | UINT32 pixelsPerBlock = 1; |
| 523 | if (IsBCFormat(m_header.format)) |
| 524 | { |
| 525 | pixelsPerBlock = (4 * 4); // BC formats have 4*4 pixels per block |
| 526 | pixelsPerBlock /= 4; // we need to divide by 4 because GetCopyableFootprints introduces a *2 stride divides the rows /4 |
| 527 | } |
| 528 | |
| 529 | for (uint32_t a = 0; a < m_header.arraySize; a++) |
| 530 | { |
| 531 | // allocate memory for mip chain from upload heap |
| 532 | // |
| 533 | UINT8 *pixels = pUploadHeap->BeginSuballocate(SIZE_T(UplHeapSize), D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT); |
| 534 | |
| 535 | // copy all the mip slices into the offsets specified by the footprint structure |
| 536 | // |
| 537 | for (uint32_t mip = 0; mip < m_header.mipMapCount; mip++) |
| 538 | { |
| 539 | pDds->CopyPixels(pixels + placedTex2D[mip].Offset, placedTex2D[mip].Footprint.RowPitch, (placedTex2D[mip].Footprint.Width * bytePP) / pixelsPerBlock, num_rows[mip]); |
| 540 | |
| 541 | D3D12_PLACED_SUBRESOURCE_FOOTPRINT slice = placedTex2D[mip]; |
| 542 | slice.Offset += (pixels - pUploadHeap->BasePtr()); |
| 543 | |
| 544 | CD3DX12_TEXTURE_COPY_LOCATION Dst(m_pResource, a * m_header.mipMapCount + mip); |
| 545 | CD3DX12_TEXTURE_COPY_LOCATION Src(pUploadHeap->GetResource(), slice); |
| 546 | pUploadHeap->AddCopy(Src, Dst); |
| 547 | } |
| 548 | |
| 549 | pUploadHeap->EndSuballocate(); |
| 550 | } |
| 551 | |
| 552 | pUploadHeap->AddBarrier(m_pResource); |
| 553 | } |
| 554 | |
| 555 | |
| 556 | //-------------------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected