| 636 | } |
| 637 | |
| 638 | void GPUContextWebGPU::CopyTexture(GPUTexture* dstResource, uint32 dstSubresource, uint32 dstX, uint32 dstY, uint32 dstZ, GPUTexture* srcResource, uint32 srcSubresource) |
| 639 | { |
| 640 | ASSERT(dstResource && srcResource); |
| 641 | auto srcTextureWebGPU = (GPUTextureWebGPU*)srcResource; |
| 642 | auto dstTextureWebGPU = (GPUTextureWebGPU*)dstResource; |
| 643 | ASSERT_LOW_LAYER(dstTextureWebGPU->Texture && srcTextureWebGPU->Texture); |
| 644 | |
| 645 | const int32 srcMipIndex = srcSubresource % srcTextureWebGPU->MipLevels(); |
| 646 | const int32 dstMipIndex = dstSubresource % srcTextureWebGPU->MipLevels(); |
| 647 | const int32 srcArrayIndex = srcSubresource / srcTextureWebGPU->ArraySize(); |
| 648 | const int32 dstArrayIndex = srcSubresource / srcTextureWebGPU->ArraySize(); |
| 649 | |
| 650 | int32 srcMipWidth, srcMipHeight, srcMipDepth; |
| 651 | srcTextureWebGPU->GetMipSize(srcMipIndex, srcMipWidth, srcMipHeight, srcMipDepth); |
| 652 | |
| 653 | if (dstTextureWebGPU->Usage & WGPUTextureUsage_CopyDst && srcTextureWebGPU->Usage & WGPUTextureUsage_CopySrc) |
| 654 | { |
| 655 | // Direct copy |
| 656 | WGPUTexelCopyTextureInfo srcInfo = WGPU_TEXEL_COPY_TEXTURE_INFO_INIT; |
| 657 | srcInfo.texture = srcTextureWebGPU->Texture; |
| 658 | srcInfo.mipLevel = srcMipIndex; |
| 659 | srcInfo.origin.z = srcArrayIndex; |
| 660 | srcInfo.aspect = WGPUTextureAspect_All; |
| 661 | WGPUTexelCopyTextureInfo dstInfo = WGPU_TEXEL_COPY_TEXTURE_INFO_INIT; |
| 662 | dstInfo.texture = dstTextureWebGPU->Texture; |
| 663 | dstInfo.mipLevel = dstMipIndex; |
| 664 | dstInfo.origin = { dstX, dstY, dstZ + dstArrayIndex }; |
| 665 | dstInfo.aspect = WGPUTextureAspect_All; |
| 666 | WGPUExtent3D copySize = { (uint32_t)srcMipWidth, (uint32_t)srcMipHeight, (uint32_t)srcMipDepth }; |
| 667 | wgpuCommandEncoderCopyTextureToTexture(Encoder, &srcInfo, &dstInfo, ©Size); |
| 668 | } |
| 669 | else if (dstTextureWebGPU->Usage & WGPUTextureUsage_RenderAttachment && srcTextureWebGPU->Usage & WGPUTextureUsage_TextureBinding) |
| 670 | { |
| 671 | // Copy via drawing |
| 672 | ResetRenderTarget(); |
| 673 | SetViewportAndScissors(srcMipWidth, srcMipHeight); |
| 674 | SetState(_device->GetCopyLinearPS()); |
| 675 | if (srcSubresource == 0 && dstSubresource == 0) |
| 676 | { |
| 677 | SetRenderTarget(dstTextureWebGPU->View(0)); |
| 678 | BindSR(0, srcTextureWebGPU->View(0)); |
| 679 | } |
| 680 | else |
| 681 | { |
| 682 | ASSERT(dstTextureWebGPU->HasPerMipViews() && srcResource->HasPerMipViews()); |
| 683 | SetRenderTarget(dstTextureWebGPU->View(dstArrayIndex, dstMipIndex)); |
| 684 | BindSR(0, srcTextureWebGPU->View(srcArrayIndex, srcMipIndex)); |
| 685 | } |
| 686 | DrawFullscreenTriangle(); |
| 687 | } |
| 688 | else |
| 689 | { |
| 690 | LOG(Fatal, "Cannot copy texture {} to {}", srcTextureWebGPU->GetDescription().ToString(), dstTextureWebGPU->GetDescription().ToString()); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | void GPUContextWebGPU::ResetCounter(GPUBuffer* buffer) |
| 695 | { |
nothing calls this directly
no test coverage detected