d3d:d3d12:texture
差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| d3d:d3d12:texture [2015/09/20 19:37] – [Texture の転送] oga | d3d:d3d12:texture [2015/09/20 20:45] (現在) – [例] oga | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| ====== Texture の転送 ====== | ====== Texture の転送 ====== | ||
| - | ===== Texture の転送 ===== | + | ===== 転送手順の概要 |
| Buffer, Texture の転送もアプリケーション側で管理する必要があります。 | Buffer, Texture の転送もアプリケーション側で管理する必要があります。 | ||
| 行 19: | 行 19: | ||
| - CommandQueue に転送完了 Fence (Sginal) を挿入 | - CommandQueue に転送完了 Fence (Sginal) を挿入 | ||
| - Fence で転送完了を確認。完了後は Upload 用の Buffer と CommandList を Release できる。 | - Fence で転送完了を確認。完了後は Upload 用の Buffer と CommandList を Release できる。 | ||
| + | |||
| + | |||
| + | |||
| + | ===== 例 ===== | ||
| + | |||
| + | Texture 用 Resource 作成。 | ||
| + | |||
| + | <code cpp> | ||
| + | ID3D12Resource* iTexture= nullptr; | ||
| + | |||
| + | D3D12_RESOURCE_DESC | ||
| + | memset( &desc, 0, sizeof(desc) ); | ||
| + | desc.Dimension= D3D12_RESOURCE_DIMENSION_TEXTURE2D; | ||
| + | desc.Width= 512; | ||
| + | desc.Height= 512; | ||
| + | desc.DepthOrArraySize= 1; | ||
| + | desc.MipLevels= 1; | ||
| + | desc.Format= DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| + | desc.SampleDesc.Count= 1; | ||
| + | |||
| + | D3D12_HEAP_PROPERTIES | ||
| + | memset( &heap, 0, sizeof(heap) ); | ||
| + | heap.Type= D3D12_HEAP_TYPE_DEFAULT; | ||
| + | |||
| + | iD3DDevice-> | ||
| + | </ | ||
| + | |||
| + | Footprint 取得。 | ||
| + | |||
| + | <code cpp> | ||
| + | D3D12_PLACED_SUBRESOURCE_FOOTPRINT | ||
| + | UINT64 | ||
| + | iD3DDevice-> | ||
| + | </ | ||
| + | |||
| + | Upload 用 Buffer 作成 | ||
| + | |||
| + | <code cpp> | ||
| + | D3D12_RESOURCE_DESC | ||
| + | memset( &desc, 0, sizeof(desc) ); | ||
| + | desc.Dimension= D3D12_RESOURCE_DIMENSION_BUFFER; | ||
| + | desc.Width= total_bytes; | ||
| + | desc.Height= 1; | ||
| + | desc.DepthOrArraySize= 1; | ||
| + | desc.MipLevels= 1; | ||
| + | desc.SamleDesc.Count= 1; | ||
| + | desc.Layout= D3D12_TEXTURE_LAYOUT_ROW_MAJOR; | ||
| + | |||
| + | D3D12_HEAP_PROPERTIES | ||
| + | memset( &heap, 0, sizeof(heap) ); | ||
| + | heap.Type= D3D12_HEAP_TYPE_UPLOAD; | ||
| + | |||
| + | ID3D12Resource* | ||
| + | iD3DDevice-> | ||
| + | </ | ||
| + | |||
| + | Upload Buffer への書き込み。 | ||
| + | |||
| + | <code cpp> | ||
| + | void* ptr= nullptr; | ||
| + | iUploadBuffer-> | ||
| + | memcpy( reinterpret_cast< | ||
| + | </ | ||
| + | |||
| + | Copy コマンド作成 | ||
| + | |||
| + | <code cpp> | ||
| + | D3D12_TEXTURE_COPY_LOCATION | ||
| + | memset( &dest, 0, sizeof(dest) ); | ||
| + | dest.pResource= iTexture; | ||
| + | dest.Type= D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; | ||
| + | dest.SubresourceIndex= 0; | ||
| + | |||
| + | D3D12_TEXTURE_COPY_LOCATION | ||
| + | memset( &src, 0, sizeof(src) ); | ||
| + | src.pResource= iUploadBuffer; | ||
| + | src.Type= D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; | ||
| + | src.PlacedFootprint= footprint; | ||
| + | |||
| + | ID3D12GraphicsCommandList* | ||
| + | iCommandList-> | ||
| + | </ | ||
| + | |||
| + | ResourceBarrier 挿入 | ||
| + | |||
| + | <code cpp> | ||
| + | D3D12_RESOURCE_BARRIER | ||
| + | memset( & | ||
| + | barrier.Type= D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; | ||
| + | barrier.Transition.pResource= iTexture; | ||
| + | barrier.Transition.Subresource= D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; | ||
| + | barrier.Transition.StateBefore= D3D12_RESOURCE_STATE_COPY_DEST; | ||
| + | barrier.Transition.StateAfter= D3D12_RESOURCE_STATE_GENERIC_READ; | ||
| + | |||
| + | iCommandList-> | ||
| + | </ | ||
| + | |||
| + | Command 実行 | ||
| + | |||
| + | <code cpp> | ||
| + | iCommandList-> | ||
| + | ID3D12CommandList* | ||
| + | iCommandQueue-> | ||
| + | |||
| + | FenceCount++; | ||
| + | iCommandQueue-> | ||
| + | </ | ||
| + | |||
| + | ResourceView の作成 | ||
| + | |||
| + | <code cpp> | ||
| + | D3D12_SHADER_RESOURCE_VIEW_DESC | ||
| + | memset( &desc, 0, sizeof(desc) ); | ||
| + | desc.Format= DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| + | desc.ViewDimension= D3D12_SRV_DIMENSION_TEXTURE2D; | ||
| + | desc.Shader4ComponentMapping= D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; | ||
| + | desc.Texture2D.MipLevels= 1; | ||
| + | |||
| + | D3D12_CPU_DESCRIPTOR_HANDLE | ||
| + | iD3DDevice-> | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
d3d/d3d12/texture.1442745478.txt.gz · 最終更新: by oga
