void CreateUnorderedAccessView(
ID3D12Resource* pResource,
ID3D12Resource* pCounterResource,
const D3D12_UNORDERED_ACCESS_VIEW_DESC* pDesc,
D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor);
| Name | Description |
|---|---|
pResource | Pointer to the resource that will be accessed as an unordered access view. |
pCounterResource | Optional; pointer to a buffer resource that holds a counter for the view. May be nullptr. |
pDesc | Pointer to a D3D12_UNORDERED_ACCESS_VIEW_DESC that describes the view. If nullptr, the view is inferred from the resource. |
DestDescriptor | The CPU handle that identifies the destination descriptor in a descriptor heap where the view will be stored. |
This method does not return a value. Errors are reported via the device’s debug layer or ID3D12Device::GetDeviceRemovedReason.
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS flag.D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS flag and a format of DXGI_FORMAT_R32_UINT.DestDescriptor must be a D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV heap.pDesc must match the resource’s format unless DXGI_FORMAT_UNKNOWN is used.// Assume device, commandList and descriptorHeap have been created.
ID3D12Resource* texture = nullptr;
D3D12_RESOURCE_DESC texDesc = {};
texDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
texDesc.Width = 1024;
texDesc.Height = 1024;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texDesc.MipLevels = 1;
texDesc.SampleDesc.Count = 1;
texDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&texDesc,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
nullptr,
IID_PPV_ARGS(&texture));
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(descriptorHeap->GetCPUDescriptorHandleForHeapStart(), 0, device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
device->CreateUnorderedAccessView(texture, nullptr, &uavDesc, uavHandle);
// Now the UAV can be bound to the pipeline.
commandList->SetDescriptorHeaps(1, &descriptorHeap);
commandList->SetComputeRootDescriptorTable(0, descriptorHeap->GetGPUDescriptorHandleForHeapStart());