| 586 | } |
| 587 | |
| 588 | ResultDetails ReplayController::SaveTexture(const TextureSave &saveData, const rdcstr &path) |
| 589 | { |
| 590 | CHECK_REPLAY_THREAD(); |
| 591 | RENDERDOC_PROFILEFUNCTION(); |
| 592 | |
| 593 | TextureSave sd = saveData; // mutable copy |
| 594 | |
| 595 | if(sd.resourceId == ResourceId()) |
| 596 | { |
| 597 | RETURN_ERROR_RESULT(ResultCode::InvalidParameter, "Invalid ID for %s getting texture data", |
| 598 | ToStr(sd.resourceId).c_str()); |
| 599 | } |
| 600 | |
| 601 | TextureDescription td = m_pDevice->GetTexture(sd.resourceId); |
| 602 | |
| 603 | // clamp sample/mip/slice indices |
| 604 | if(td.msSamp == 1) |
| 605 | { |
| 606 | sd.sample.sampleIndex = 0; |
| 607 | sd.sample.mapToArray = false; |
| 608 | } |
| 609 | else |
| 610 | { |
| 611 | if(sd.sample.sampleIndex != ~0U) |
| 612 | sd.sample.sampleIndex = RDCCLAMP((uint32_t)sd.sample.sampleIndex, 0U, td.msSamp); |
| 613 | } |
| 614 | |
| 615 | // don't support cube cruciform for non cubemaps, or |
| 616 | // cubemap arrays |
| 617 | if(!td.cubemap || td.arraysize != 6 || td.msSamp != 1) |
| 618 | sd.slice.cubeCruciform = false; |
| 619 | |
| 620 | if(sd.mip != -1) |
| 621 | sd.mip = RDCCLAMP(sd.mip, 0, (int32_t)td.mips); |
| 622 | if(sd.slice.sliceIndex != -1) |
| 623 | sd.slice.sliceIndex = RDCCLAMP(sd.slice.sliceIndex, 0, int32_t(td.arraysize * td.depth)); |
| 624 | |
| 625 | if(td.arraysize * td.depth * td.msSamp == 1) |
| 626 | { |
| 627 | sd.slice.sliceIndex = 0; |
| 628 | sd.slice.slicesAsGrid = false; |
| 629 | } |
| 630 | |
| 631 | // can't extract a channel that's not in the source texture |
| 632 | if(sd.channelExtract >= 0 && (uint32_t)sd.channelExtract >= td.format.compCount) |
| 633 | sd.channelExtract = -1; |
| 634 | |
| 635 | sd.slice.sliceGridWidth = RDCMAX(sd.slice.sliceGridWidth, 1); |
| 636 | |
| 637 | // store sample count so we know how many 'slices' is one real slice |
| 638 | // multisampled textures cannot have mips, subresource layout is same as would be for mips: |
| 639 | // [slice0 sample0], [slice0 sample1], [slice1 sample0], [slice1 sample1] |
| 640 | uint32_t sampleCount = RDCMAX(td.msSamp, 1U); |
| 641 | bool multisampled = td.msSamp > 1; |
| 642 | |
| 643 | if(sd.sample.mapToArray) |
| 644 | sd.sample.sampleIndex = 0; |
| 645 | |