0
$\begingroup$

Edit: I managed to get code compiling, but it doesn't work, so I changed question a little bit.

Below code is working fine as read buffer, but I cannot make it to work as read-write buffer (RWStructuredBuffer). I am using RWStructubeBuffer : (u0) in my hlsl code and I can read data correctly in hlsl and I can write data correctly on CPU in C++ code. But I cannot get data back from GPU or at least I don't know how to acces that:

UINT64 size = buffersWithSize[i].second;
UINT64 bufferSize = size;
auto uavDesc = CD3DX12_RESOURCE_DESC::Buffer(bufferSize, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
auto defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);

ThrowIfFailed(device->CreateCommittedResource(
    &defaultHeapProperties, D3D12_HEAP_FLAG_NONE, &uavDesc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(&buffersWithSize[i].first)
));

D3D12_UNORDERED_ACCESS_VIEW_DESC uavViewDesc = {};
uavViewDesc.Buffer.NumElements = 1;
uavViewDesc.Buffer.FirstElement = 0;
uavViewDesc.Buffer.StructureByteStride = size;
uavViewDesc.Buffer.CounterOffsetInBytes = 0;
uavViewDesc.Format = DXGI_FORMAT_UNKNOWN;
uavViewDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;

device->CreateUnorderedAccessView(buffersWithSize[i].first.Get(), nullptr, &uavViewDesc, handle);
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.