Loading data from compute shader
Hello, i really need to solve this problem and i hope someone could help me here

i just want to load 2 values, set in my compute shader, into an array. I tried something I´ve seen in a sample, like:

pd3dImmediateContext->CSSetShader( computeShader, NULL, 0 );
pd3dDevice->CreateUnorderedAccessView( buffer, &sUAV, &bufferUAV );
pd3dImmediateContext->CSSetUnorderedAccessViews( 4, 1, &bufferUAV, 0);
pd3dImmediateContext->Dispatch( 1, 1, 1 );

pd3dImmediateContext->CopyResource(g_pReadBackBuffer, buffer);
D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
pd3dImmediateContext->Map( g_pReadBackBuffer, 0, D3D11_MAP_READ, 0, &MappedResource );
memcpy( &results[0], MappedResource.pData, 2*sizeof(float) );
pd3dImmediateContext->Unmap( g_pReadBackBuffer, 0 );

So my simple cs should set new values for results[]

RWStructuredBuffer<float> data : register(u4);

[numthreads(1,1,1)]
void stillSimpleCS( uint3 GroupID : SV_GroupID, uint3 DispatchThreadID : SV_DispatchThreadID, uint3 GroupThreadID : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex )
{
data[0] = 2.0;
data[1] = 1.0;
}

but he seems to fill results[] with 0. Can anybody tell me how to fix this?
Hello, i really need to solve this problem and i hope someone could help me here



i just want to load 2 values, set in my compute shader, into an array. I tried something I´ve seen in a sample, like:



pd3dImmediateContext->CSSetShader( computeShader, NULL, 0 );

pd3dDevice->CreateUnorderedAccessView( buffer, &sUAV, &bufferUAV );

pd3dImmediateContext->CSSetUnorderedAccessViews( 4, 1, &bufferUAV, 0);

pd3dImmediateContext->Dispatch( 1, 1, 1 );



pd3dImmediateContext->CopyResource(g_pReadBackBuffer, buffer);

D3D11_MAPPED_SUBRESOURCE MappedResource = {0};

pd3dImmediateContext->Map( g_pReadBackBuffer, 0, D3D11_MAP_READ, 0, &MappedResource );

memcpy( &results[0], MappedResource.pData, 2*sizeof(float) );

pd3dImmediateContext->Unmap( g_pReadBackBuffer, 0 );



So my simple cs should set new values for results[]



RWStructuredBuffer<float> data : register(u4);



[numthreads(1,1,1)]

void stillSimpleCS( uint3 GroupID : SV_GroupID, uint3 DispatchThreadID : SV_DispatchThreadID, uint3 GroupThreadID : SV_GroupThreadID, uint GroupIndex : SV_GroupIndex )

{

data[0] = 2.0;

data[1] = 1.0;

}



but he seems to fill results[] with 0. Can anybody tell me how to fix this?

#1
Posted 04/08/2010 04:16 PM   
Are you creating your "g_pReadBackBuffer" with the correct flags for a staging buffer? e.g.:

D3D11_BUFFER_DESC sbDesc;
sbDesc.BindFlags = 0;
sbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
sbDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
sbDesc.Usage = D3D11_USAGE_STAGING;
Are you creating your "g_pReadBackBuffer" with the correct flags for a staging buffer? e.g.:



D3D11_BUFFER_DESC sbDesc;

sbDesc.BindFlags = 0;

sbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;

sbDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;

sbDesc.Usage = D3D11_USAGE_STAGING;

#2
Posted 04/12/2010 11:17 AM   
Scroll To Top