Jump to content
  • Advertisement
Sign in to follow this  

Cannot save values into fragment using unordered access view buffer

This topic is 2034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to modify a value before saving a fragment into an UAV but it does not work.


HLSL source code

struct FragmentData
     uint ID;

struct FragmentLink
     FragmentData Data;
     uint nNext;

float4 PS(ScenePS_Input input) : SV_TARGET
     uint x = input.Position.x;        // [0,g_nFrameWidth]
     uint y = input.Position.y;        // [0,g_nFrameHeight]

     // Create fragment data.
     FragmentLink element;
     element.fragmentData.ID = 5;

     // Increment and get current pixel count.
    uint nPixelCount= FLBuffer.IncrementCounter();

    // Read and update Start Offset Buffer.
    uint nIndex = y * g_nFrameWidth + x;
    uint nStartOffsetAddress = 4 * nIndex;
    uint nOldStartOffset;
        nStartOffsetAddress, nPixelCount, nOldStartOffset );

    // Store fragment link.
    element.nNext = nOldStartOffset;
    FLBuffer[ nPixelCount ] = element;

    return float4(1.0f, 0.0f, 0.0f, 1.0f);

In main source code, 

        HRESULT hr;
        ID3D11Buffer* pDebugBuf = CreateAndCopyToDebugBuf( pDevice, pD3DContext, pFragmentLink );
        D3D11_MAPPED_SUBRESOURCE MappedResource;     
        V( pD3DContext->Map( pDebugBuf, 0, D3D11_MAP_READ, 0, &MappedResource ) );
        FragmentLink* pData = reinterpret_cast< FragmentLink* >( MappedResource.pData );
        int nSize = pBackBufferDesc->Width * pBackBufferDesc->Height * 8;
        for( int i=0; i<nSize; ++i ) 	
            FragmentLink data = pData[ i ];
            if( data.nNext == 0xFFFFFFFF ) {
                int nBreak = 0;
	        if (data.fragmentData.ID != 5)				
		    int a = 1;
        pD3DContext->Unmap( pDebugBuf, 0 );
        SAFE_RELEASE( pDebugBuf ); 

there are some fragments' ID are 0, the rest are 5. I do not understand the reason why fragments' ID are 0. Is there anybody experience this problem before? Help me, please. Thanks.

Share this post

Link to post
Share on other sites

I have already tested with the number of fragments in UAV. I figured out that only a part of UAV is occupied, so that the empty elements have its ID value is 0. However, in the second pass, after saving all fragments into a UAV, I get all fragments belongs to the current pixel as following:

    uint nIndex = (uint)input.pos.y * g_nFrameWidth + (uint)input.pos.x;
    uint x = (uint)input.pos.x;
    uint y = (uint)input.pos.y;

    FragmentData aData[ MAX_ELEMENTS ];            
    uint nNumFragment = 0;                         
    uint nNext = StartOffsetSRV.Load(nIndex);

    // early exit if no fragments in the linked list.
    if( nNext == 0xFFFFFFFF )
		return BACKGROUND;

    while( nNext != 0xFFFFFFFF ) 
        FragmentLink element = FragmentLinkSRV[nNext];		        
        aData[nNumFragment] = element.fragmentData;

	int j = nNumFragment;
	while ( (j>0) && (aData[max(j-1, 0)].nDepthAndCoverage > aData[j].nDepthAndCoverage) )
		uint jminusone = max(j-1, 0);
		FragmentData temp = aData[j];
		aData[j] = aData[jminusone];
		aData[jminusone] = temp;

	//check if the next fragment's index is greater than the number of fragments in the UAV
	if (element.nNext >= UAV_Counter)
		return GREEN;

	nNext = element.nNext;

The problem is sometimes the next fragment's index is greater than the number of fragments in the UAV. Is there anybody know the reason? Please, help me. Thanks

Share this post

Link to post
Share on other sites

One more thing that I do not use Compute Shader in this program, is there possible to use UAV without Compute shader?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!