Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Tiled Resources & Large RWByteAddressBuffers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 french_hustler   Members   -  Reputation: 401

Like
0Likes
Like

Posted 04 September 2014 - 12:35 PM

Hello DirectX community,
 
I have come into a problem within one of my compute kernels.
I am using tiled resources to map tiles from a tile pool into an RWByteAddressBuffer. Since the buffer is created with the tiled resource flag, its size can be humongous (greater than what can be byte addressable with a 32bit uint). And this is the exact problem I am having in my kernel.

#include "HR_Globals.h"

#define GRP_DIM 1024

cbuffer cbConstants : register(b0)
{
	unsigned int	gNumVoxelsPerLength;
	unsigned int	gNumTilesPerVoxel;
	float2			pad;
};

RWByteAddressBuffer	gRayGridOut	: register(u0); // flattened indexed buffer of the ray grid

/* This kernel inits the tiles' header of the ray grid.
 */
[numthreads(GRP_DIM, 1, 1)]
void
InitRayGrid(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex)
{
	unsigned int tile_index = ((Gid.x * GRP_DIM) + GI);
	unsigned int tile_head_node_offset = tile_index * BYTES_PER_TILE * gNumTilesPerVoxel;

	unsigned int total_size = 0;
	gRayGridOut.GetDimensions(total_size);
	if (tile_head_node_offset < total_size)
	{
		// 1st int of header represents the offset to the next node in the tile
		gRayGridOut.Store(tile_head_node_offset, -1);
		// 2nd int provides a counter for how many rays are in the node
		gRayGridOut.Store(tile_head_node_offset + 4, 0);
	}
}

"total_size" returns a bad value because the HLSL function uses a 32bit uint.
"tile_head_node_offset" can also be out of range if the byte address is > 2^32 and there isn't any function for loading and storing from buffers that take a 64-bit type. From the documentation the only 64-bit type is the double type within which you can pack 2 uints.

 

Please advise on how I can get around this restriction.

 

Thank you in advance for you help.

 

- David


Edited by french_hustler, 05 September 2014 - 10:22 AM.


Sponsor:

#2 tonemgub   Members   -  Reputation: 1834

Like
0Likes
Like

Posted 05 September 2014 - 05:01 AM

I haven't used tiled resources yet, but I think you have to perform calculations that depend on the tiled resources' address mapping model on the CPU, and send the results to your shader, treating them as relative to the start of the region of active tiles. Also, I think that the RWByteAddressBuffer you access in your shader is not actually the whole buffer, but only the active tiles, so the RWByteAddressBuffer's address 0 actually corresponds to the tiled resource's pDestTileRegionStartCoordinate value set with ID3D11DeviceContext2::UpdateTiles, and RWByteAddressBuffer::GetDimensions returns only the size of the active tiles...

 

Also, there's no such thing as a negative uint. smile.png


Edited by tonemgub, 05 September 2014 - 05:08 AM.


#3 french_hustler   Members   -  Reputation: 401

Like
0Likes
Like

Posted 05 September 2014 - 10:32 AM

I haven't used tiled resources yet, but I think you have to perform calculations that depend on the tiled resources' address mapping model on the CPU, and send the results to your shader, treating them as relative to the start of the region of active tiles. Also, I think that the RWByteAddressBuffer you access in your shader is not actually the whole buffer, but only the active tiles, so the RWByteAddressBuffer's address 0 actually corresponds to the tiled resource's pDestTileRegionStartCoordinate value set with ID3D11DeviceContext2::UpdateTiles, and RWByteAddressBuffer::GetDimensions returns only the size of the active tiles...

 

Also, there's no such thing as a negative uint. smile.png

 

Hey thanks for the reply. You're right about uints not being negative... that was silly of me. I wrote that because I was storing the values and reading them back on the CPU as integers. Regardless though, the returned values are incorrect once the tiled resource RWByteAddressBuffer is larger than what can be addressed with a 32bit uint.

With tiled resources though, indexing into buffers remains the same. If you hit a sparse area though, the behavior will differ depending on the "tier level": supported by your GPU. In my case, I map a single "dummy" physical tile to any sparse tile of the buffer. Though inefficient, any time a store occurs to a sparse area, it will map to the dummy tile.

 

I'm pretty sure the code is correct since I tested the kernel on a smaller buffer. The problem is that the API allows you to create really huge tiled resources (since memory isn't allocated until you actually use UpdateTiles(...)), but doesn't let you access areas of byte addressable buffers that are beyond 2^32 bytes. The only solution I currently see is to either bind multiple buffers to the kernel and implement some sort of logic that would spill over to the next buffer once you reach areas that are addressable or rethink my algorithm as a whole :(.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS