Hi, I'm currently having trouble reading an SRV that points to the same data as the UAV. So the UAV is first cleared, then written to, then unbind, then the srv that points to the same data is bound. The data from the UAV seems to be wriitten to completely fine, below you'll see that there is infact data in it:
This is after writing to the UAV, but, when binding the UAV for reading later on, its reported empty, renderDoc ( free Software by crytek ) reports it as empty as well:
Now, to the actual code, how I create the buffer, UAV and SRV:
D3D11_BUFFER_DESC bufferDesc;
int stride = size;
bufferDesc.ByteWidth = stride*count;
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
bufferDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
bufferDesc.StructureByteStride = stride;
if (pDev->CreateBuffer(&bufferDesc, pInitialDataRaw, &pp->pData) != S_OK)
return NULL;
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
uavDesc.Format = DXGI_FORMAT_UNKNOWN;
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
uavDesc.Buffer.FirstElement = 0;
uavDesc.Buffer.Flags = 0;
uavDesc.Buffer.NumElements = count;
if (pDev->CreateUnorderedAccessView(pp->pData, &uavDesc, &pp->pUAV) != S_OK)
return NULL;
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = DXGI_FORMAT_UNKNOWN;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
srvDesc.Buffer.ElementOffset = 0;
srvDesc.Buffer.ElementWidth = size;
srvDesc.Buffer.NumElements = count;
if (pDev->CreateShaderResourceView(pp->pData, &srvDesc, &pp->pSRV) != S_OK)
return NULL;
How I bind and Unbind:
Bind the UAV PS
pDevcon->OMSetRenderTargetsAndUnorderedAccessViews(
0, 0, 0,
start, 1, &p->pUAV, 0
);
Bind the UAV CS
pDevcon->CSSetUnorderedAccessViews(
start, 1, &p->pUAV, 0
);
UNBIND
pDevcon->PS/CSSetUnorderedAccessViews(
Binding the SRV:
pDevcon->PSSetShaderResources(start, 1, &p->pSRV);
If anything else is needed please tell me.
Question: Why is the resource reported as empty?
Thank you for your time.
-MIGI0027