MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / CopyTexture

Method CopyTexture

Source/Engine/GraphicsDevice/WebGPU/GPUContextWebGPU.cpp:638–692  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

636}
637
638void 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, &copySize);
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
694void GPUContextWebGPU::ResetCounter(GPUBuffer* buffer)
695{

Callers

nothing calls this directly

Calls 8

SetViewportAndScissorsFunction · 0.85
SetStateFunction · 0.85
GetMipSizeMethod · 0.80
GetCopyLinearPSMethod · 0.80
ArraySizeMethod · 0.45
ViewMethod · 0.45
ToStringMethod · 0.45
GetDescriptionMethod · 0.45

Tested by

no test coverage detected