Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Compute shader, buffer of structs with large arrays in them, can't find a way to do it

Discussion in 'Shaders' started by captainspaceman, Apr 22, 2021.

  1. captainspaceman

    captainspaceman

    Joined:
    Jul 14, 2017
    Posts:
    42
    I want a buffer of structs like this:
    Code (CSharp):
    1.  
    2. struct Chunk {
    3.     int voxels[16 * 16 * 16];
    4.     bool empty;
    5. };
    6.  
    7. RWStructuredBuffer<Chunk> ChunksData;
    8.  
    It says my structs can only hold 2048 bytes each, so I tried to make the "voxels" array a StructuredBuffer too and the compiler also did not like that.

    How should I represent this data on the GPU? Should I just use one gigantic flat buffer where every 16*16*16 elements represents a different chunk's voxels? And then have another buffer for the bools? Or is there some way I can use structs like this? Thank you.
     
    Last edited: Apr 23, 2021
  2. AustinMclEctro

    AustinMclEctro

    Joined:
    May 3, 2017
    Posts:
    16
    Bumping this to confirm that flattening the StructuredBuffer is indeed how one should proceed with a problem like this (when datasize per struct in the StructuredBuffer is > 2048 bytes).

    @captainspaceman did you solve your problem by using a large flattened buffer?
     
    Last edited: Jan 18, 2022
  3. ThynkTekStudio

    ThynkTekStudio

    Joined:
    Sep 4, 2021
    Posts:
    58
    interested as to how is this implementable