将源资源的整个内容复制到目标资源。
语法
void CopyResource(
  [in] ID3D12Resource *pDstResource,
  [in] ID3D12Resource *pSrcResource
);
参数
[in] pDstResource
类型: ID3D12Resource*
指向 ID3D12Resource 接口的指针,该接口表示目标资源。
[in] pSrcResource
类型: ID3D12Resource*
指向表示源资源的 ID3D12Resource 接口的指针。
返回值
无
备注
CopyResource 操作在 GPU 上执行,不会因要复制的数据大小而产生大量 CPU 工作负荷。
CopyResource 可用于初始化为同一堆内存别名的资源。 有关更多详细信息 ,请参阅 CreatePlacedResource 。
调试层
如果源子资源不处于 D3D12_RESOURCE_STATE_COPY_SOURCE 状态,则调试层会发出错误。
如果目标子资源不处于 D3D12_RESOURCE_STATE_COPY_DEST 状态,则调试层会发出错误。
限制
此方法有一些旨在提高性能的限制。 例如,源和目标资源:
- 必须是不同的资源。
- 必须是同一类型。
- 总大小 (字节) 必须相同。
- 必须具有相同的尺寸 (宽度、高度、深度) 或为兼容的 重新解释副本。
- 必须具有兼容的 DXGI 格式,这意味着格式必须相同或至少来自同一类型组。 例如,可以将DXGI_FORMAT_R32G32B32_FLOAT纹理复制到DXGI_FORMAT_R32G32B32_UINT纹理,因为这两种格式都位于DXGI_FORMAT_R32G32B32_TYPELESS组中。 CopyResource 可以在几种格式类型之间复制 (请参阅 重新解释复制) 。
- 当前无法映射。
CopyResource 仅支持复制;它不支持任何拉伸、颜色键或混合。
CopyResource 可以在几种格式类型之间重新解释资源数据,有关详细信息,请参阅下面的 重新解释复制 。
可以使用 深度模具 资源作为源或目标。 使用多采样功能创建的资源 (查看 DXGI_SAMPLE_DESC) 仅当源和目标具有相同的多采样计数和质量时,才能用作源和目标。 如果源和目标在多采样计数和质量方面不同,或者如果一个是多采样的,而另一个不是多采样的,则对 CopyResource 的调用将失败。 使用 ResolveSubresource 将多采样资源解析为非多采样资源。
方法是异步调用,可以将其添加到命令缓冲区队列。 这会尝试删除复制数据时可能发生的管道停止。 有关详细信息,请参阅 性能注意事项。
如果只需要复制资源中的一部分数据,请考虑使用 CopyTextureRegion 或 CopyBufferRegion 。
重新解释复制
下表列出了可以在格式转换的重新解释类型中使用的允许的源和目标格式。 基础数据值不会转换或压缩/解压缩,并且必须正确编码,重新解释才能按预期工作。 有关详细信息,请参阅 使用 Direct3D 10.1 进行格式转换。
对于DXGI_FORMAT_R9G9B9E5_SHAREDEXP宽度和高度必须等于 (每个块) 1 个纹素。
块压缩的资源宽度和高度必须是未压缩资源宽度的 4 倍, (每个块) 16 纹素。 例如,未压缩的 256x256 DXGI_FORMAT_R32G32B32A32_UINT 纹理将映射到 1024x1024 DXGI_FORMAT_BC5_UNORM压缩纹理。
| 位宽度 | 未压缩的资源 | 块压缩资源 | 宽度/高度差异 | 
|---|---|---|---|
| 32 | DXGI_FORMAT_R32_UINT DXGI_FORMAT_R32_SINT | DXGI_FORMAT_R9G9B9E5_SHAREDEXP | 1:1 | 
| 64 | DXGI_FORMAT_R16G16B16A16_UINT DXGI_FORMAT_R16G16B16A16_SINT DXGI_FORMAT_R32G32_UINT DXGI_FORMAT_R32G32_SINT | DXGI_FORMAT_BC1_UNORM[_SRGB] DXGI_FORMAT_BC4_UNORM DXGI_FORMAT_BC4_SNORM | 1:4 | 
| 128 | DXGI_FORMAT_R32G32B32A32_UINT DXGI_FORMAT_R32G32B32A32_SINT | DXGI_FORMAT_BC2_UNORM[_SRGB] DXGI_FORMAT_BC3_UNORM[_SRGB] DXGI_FORMAT_BC5_UNORM DXGI_FORMAT_BC5_SNORM | 1:4 | 
示例
D3D12HeterogeneousMultiadapter 示例按以下方式使用 CopyResource:
	// Command list to copy the render target to the shared heap on the primary adapter. 
 	{ 
 		const GraphicsAdapter adapter = Primary; 
 
 
 		// Reset the copy command allocator and command list. 
 		ThrowIfFailed(m_copyCommandAllocators[m_frameIndex]->Reset()); 
 		ThrowIfFailed(m_copyCommandList->Reset(m_copyCommandAllocators[m_frameIndex].Get(), nullptr)); 
 
 
 		// Copy the intermediate render target to the cross-adapter shared resource. 
 		// Transition barriers are not required since there are fences guarding against 
 		// concurrent read/write access to the shared heap. 
 		if (m_crossAdapterTextureSupport) 
 		{ 
 			// If cross-adapter row-major textures are supported by the adapter, 
 			// simply copy the texture into the cross-adapter texture. 
 			m_copyCommandList->CopyResource(m_crossAdapterResources[adapter][m_frameIndex].Get(), m_renderTargets[adapter][m_frameIndex].Get()); 
 		} 
 		else 
 		{ 
 			// If cross-adapter row-major textures are not supported by the adapter, 
 			// the texture will be copied over as a buffer so that the texture row 
 			// pitch can be explicitly managed. 
 
 
 			// Copy the intermediate render target into the shared buffer using the 
 			// memory layout prescribed by the render target. 
 			D3D12_RESOURCE_DESC renderTargetDesc = m_renderTargets[adapter][m_frameIndex]->GetDesc(); 
 			D3D12_PLACED_SUBRESOURCE_FOOTPRINT renderTargetLayout; 
 
 
 			m_devices[adapter]->GetCopyableFootprints(&renderTargetDesc, 0, 1, 0, &renderTargetLayout, nullptr, nullptr, nullptr); 
 
 
 			CD3DX12_TEXTURE_COPY_LOCATION dest(m_crossAdapterResources[adapter][m_frameIndex].Get(), renderTargetLayout); 
 			CD3DX12_TEXTURE_COPY_LOCATION src(m_renderTargets[adapter][m_frameIndex].Get(), 0); 
 			CD3DX12_BOX box(0, 0, m_width, m_height); 
 
 
 			m_copyCommandList->CopyTextureRegion(&dest, 0, 0, 0, &src, &box); 
		} 
 
		ThrowIfFailed(m_copyCommandList->Close()); 
	} 
要求
| 要求 | 值 | 
|---|---|
| 目标平台 | Windows | 
| 标头 | d3d12.h | 
| Library | D3d12.lib | 
| DLL | D3d12.dll |