Skip to content

Commit

Permalink
FIXED Only create a UAV for structured buffers with the D3D12_RESOURC…
Browse files Browse the repository at this point in the history
…E_FLAG_ALLOW_UNORDERED_ACCESS flag set.
  • Loading branch information
jpvanoosten committed Oct 10, 2019
1 parent f579d5b commit e2d1c7a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions DX12Lib/src/StructuredBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@ void StructuredBuffer::CreateViews( size_t numElements, size_t elementSize )
&srvDesc,
m_SRV.GetDescriptorHandle() );

D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
uavDesc.Format = DXGI_FORMAT_UNKNOWN;
uavDesc.Buffer.CounterOffsetInBytes = 0;
uavDesc.Buffer.NumElements = static_cast<UINT>( m_NumElements );
uavDesc.Buffer.StructureByteStride = static_cast<UINT>( m_ElementSize );
uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;

device->CreateUnorderedAccessView( m_d3d12Resource.Get(),
m_CounterBuffer.GetD3D12Resource().Get(),
&uavDesc,
m_UAV.GetDescriptorHandle() );
D3D12_RESOURCE_DESC desc = m_d3d12Resource->GetDesc();
if ( desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS )
{
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
uavDesc.Format = DXGI_FORMAT_UNKNOWN;
uavDesc.Buffer.CounterOffsetInBytes = 0;
uavDesc.Buffer.NumElements = static_cast<UINT>(m_NumElements);
uavDesc.Buffer.StructureByteStride = static_cast<UINT>(m_ElementSize);
uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;

device->CreateUnorderedAccessView(m_d3d12Resource.Get(),
m_CounterBuffer.GetD3D12Resource().Get(),
&uavDesc,
m_UAV.GetDescriptorHandle());
}
}

0 comments on commit e2d1c7a

Please sign in to comment.