ID3D12GraphicsCommandList::CopyResource 方法 (d3d12.h)

將來源資源的整個內容複製到目的地資源。

語法

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 將多重取樣資源解析為非多重取樣的資源。

方法是異步呼叫,可能會新增至命令緩衝區佇列。 這會嘗試移除複製數據時可能發生的管線停止。 如需詳細資訊,請參閱 效能考慮

如果您只需要複製資源中的數據部分,請考慮使用 CopyTextureRegionCopyBufferRegion

重新解譯複製

下表列出您可以在重新解譯格式轉換類型中使用的允許來源和目的地格式。 基礎數據值不會轉換或壓縮/解壓縮,而且必須正確編碼,重新解譯才能如預期般運作。 如需詳細資訊,請參閱 使用 Direct3D 10.1 格式化轉換

對於DXGI_FORMAT_R9G9B9E5_SHAREDEXP寬度和高度必須等於每個區塊 () 1 個紋素。

區塊壓縮的資源寬度和高度必須是每個區塊) 16 個材質的未壓縮資源寬度和高度 (4 倍。 例如,未壓縮的 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
程式庫 D3d12.lib
Dll D3d12.dll

另請參閱

ID3D12GraphicsCommandList