Hi!
I’ve been trying to implement a world generation system using compute shaders. But I’ve gotten into a stalemate, I (atleast think) I require a StructuredBuffer inside of a StructuredBuffer!
What I want is probably easier to explain in code, so here it is:
struct MyStruct
{
/**
* bunch of variables
*/
StructuredBuffer<MyOtherStruct> myBufferInsideMyBuffer;
};
StructuredBuffer<MyStruct> myBuffer;
However this is ofcourse impossible because of the fact that a struct has to have a constant stride. So the code above would never compile, however somthing like this would:
#define arraySize 42
struct MyStruct
{
/**
* bunch of variables
*/
MyOtherStruct array[arraySize];
};
StructuredBuffer<MyStruct> myBuffer;
The problem is now that I am limited to a set amount of MyOtherStruct, and I also have to play cat and mouse with my freedom (how large I make arraySize) and optimization (how small I make arraySize) since I will inevitably iterate over ‘arraySize’ number of elements.
Is there a workaround anyone know of?
The closest I could think of is this:
struct MyStruct
{
/**
* bunch of variables
*/
int from; // start index of myOtherBuffer
int to; // end index of myOtherBuffer
};
StructuredBuffer<MyStruct> myBuffer;
StructuredBuffer<MyOtherStruct> myOtherBuffer;
But it seems to be a pain in the a*s to implement. So any other workaround/solution would be highly appreciated!
.