Jump to content
  • Advertisement
Sign in to follow this  
pnt1614

DX11 How to get an value from Byte Address buffer in DX11, HLSL?

This topic is 2338 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 try to modidy the shader code of OIT, http://www.yakiimo3d.com/2010/07/25/dx11-order-independent-transparency-with-msaa/, and the source code can be downloaded from http://yakiimo3d.codeplex.com/releases/view/49570. But in StoreFragments.hlsl, when they render into a linked list, they use a byte address buffer for offset.

void StoreFragmentsPS( SceneVS_Output input )
{
uint x = input.pos.x; // [0,g_nFrameWidth]
uint y = input.pos.y; // [0,g_nFrameHeight]
// Create fragment data.
uint4 nColor = saturate( input.color ) * 255;
FragmentLink element;
element.fragmentData.nColor = (nColor.x) | (nColor.y << 8) | (nColor.z << 16) | (nColor.a << 24);
element.fragmentData.fDepth = input.pos.z;

// 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;

StartOffsetBuffer.InterlockedExchange(
nStartOffsetAddress, nPixelCount, nOldStartOffset );


if ( nOldStartOffset != 0xFFFFFFFF ) {
//get an error: array, matrix, vector or indexable object.......
uint index = StartOffsetBuffer[ idx ];
}
// Store fragment link.
element.nNext = nOldStartOffset;
FLBuffer[ nPixelCount ] = element;
}


With the function InterlockedExchange, nPixelCount value will be saved at nStartOffsetAddress position and we can get the old value. Hence, we can use nOldStartOffset value as an index to get the previous/next element, but why did I get that error? and how to solve it?
Anybody help me, please? Thank in advance.

Share this post


Link to post
Share on other sites
Advertisement
Hi!

I’m curious, why do you need to check the old address? Do you want to find out whether you got the “tail” of the list? What do you like to achieve? Maybe we can assist a little. smile.png Looks like you’re only writing if it is the tail, thus you don’t really build up a list. The OIT code would work just fine without it.


void StoreFragmentsPS( SceneVS_Output input )
{
...
//if ( nOldStartOffset != 0xFFFFFFFF ) {
//get an error: array, matrix, vector or indexable object.......
// uint index = StartOffsetBuffer[ idx ];
//}
// Store fragment link.
element.nNext = nOldStartOffset;
FLBuffer[ nPixelCount ] = element;
//}


But to answer your question, firstly the variable idx doesn’t exist and secondly only structured buffers have an array index operator. For ByteAddressBuffer you can use Load.
uint index = StartOffsetBuffer.Load(someByteAddress);
The shader that does the sorting of the fragments also uses Load to read from the StartOffsetBuffer btw.

Cheers!

Share this post


Link to post
Share on other sites
Thank you so much, Tsus, I have tried the Load function before and I got the same error, but maybe there is something wrong, now it is working.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!