| 750 | }; |
| 751 | |
| 752 | bool GPUTexture::DownloadData(TextureData& result) |
| 753 | { |
| 754 | // Skip for empty ones |
| 755 | if (MipLevels() == 0) |
| 756 | { |
| 757 | LOG(Warning, "Cannot download GPU texture data from an empty texture."); |
| 758 | return true; |
| 759 | } |
| 760 | if (Depth() != 1) |
| 761 | { |
| 762 | MISSING_CODE("support volume texture data downloading."); |
| 763 | } |
| 764 | PROFILE_CPU(); |
| 765 | PROFILE_MEM(GraphicsTextures); |
| 766 | |
| 767 | // Use faster path for staging resources |
| 768 | if (IsStaging()) // TODO: what about chips with unified memory? if rendering is not active then we can access GPU memory from CPU directly (eg. mobile, integrated GPUs and some consoles) |
| 769 | { |
| 770 | const auto arraySize = ArraySize(); |
| 771 | const auto mipLevels = MipLevels(); |
| 772 | |
| 773 | // Set texture info |
| 774 | result.Width = Width(); |
| 775 | result.Height = Height(); |
| 776 | result.Depth = Depth(); |
| 777 | result.Format = Format(); |
| 778 | |
| 779 | // Get all mip maps for each array slice |
| 780 | auto& rawResultData = result.Items; |
| 781 | rawResultData.Resize(arraySize, false); |
| 782 | for (int32 arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) |
| 783 | { |
| 784 | auto& arraySlice = rawResultData[arrayIndex]; |
| 785 | arraySlice.Mips.Resize(mipLevels); |
| 786 | |
| 787 | for (int32 mipMapIndex = 0; mipMapIndex < mipLevels; mipMapIndex++) |
| 788 | { |
| 789 | auto& mip = arraySlice.Mips[mipMapIndex]; |
| 790 | const int32 mipWidth = result.Width >> mipMapIndex; |
| 791 | const int32 mipHeight = result.Height >> mipMapIndex; |
| 792 | uint32 mipRowPitch, mipSlicePitch; |
| 793 | RenderTools::ComputePitch(result.Format, mipWidth, mipHeight, mipRowPitch, mipSlicePitch); |
| 794 | |
| 795 | // Gather data |
| 796 | if (GetData(arrayIndex, mipMapIndex, mip, mipRowPitch)) |
| 797 | { |
| 798 | LOG(Warning, "Staging resource of \'{0}\' get data failed.", ToString()); |
| 799 | return true; |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | return false; |
| 805 | } |
| 806 | |
| 807 | #if GPU_ENABLE_RESOURCE_NAMING |
| 808 | const auto name = ToString(); |
| 809 | #else |
no test coverage detected