baldurk / renderdoc

RenderDoc is a stand-alone graphics debugging tool.
https://renderdoc.org
MIT License
8.88k stars 1.33k forks source link

Troubles viewing data of a StructuredBuffer<T> where T is a struct #1026

Closed NPatch closed 6 years ago

NPatch commented 6 years ago

Description

Trying to view the data of a StructuredBuffer in RenderDoc but can't get a correct row count mostly. I also had cases where half the data were in float form and the rest were in scientific form with exponent but the dataset used in the photos below did not show this issue.

The setup is a ComputeShader in Unity where we precalculate an array of size N in the editor and submit it to the ComputeShader using a CommandBuffer on runtime. Below there will be images of each different approach where the variable factors are how the data were submitted to the ComputeBuffer and/or how they were formatted for visualization in RenderDoc.

In the ComputeShader, we define a StructuredBuffer, where Spread is:

struct Spread {
    float Left_0_25;
    float Left_0_5;
    float Left_0_75;
    float Left_1;
    float Right_0_25;
    float Right_0_5;
    float Right_0_75;
    float Right_1;
    float Top_0_25;
    float Top_0_5;
    float Top_0_75;
    float Top_1;
    float Bottom_0_25;
    float Bottom_0_5;
    float Bottom_0_75;
    float Bottom_1;
};

In the C# side of things, we also use the same struct in half of the tests.

Due to time constraint, there were no tests where the type of the StructuredBuffer was changed in the ComputeShader as well.

Repro steps

NOTE: In all subsequent photos, we display the last rows of the data.

1) In the first test, we submit the data as an array of structs:

Spread[] precalc_spread_values; // Size is 30
ComputeBuffer precalc_values_buf = new ComputeBuffer(precalc_spread_values.Length, 16);
precalc_values_buf.SetData(precalc_spread_values);

Now for the visualizations:

raw_struct_submit

* float

float_struct_submit

* float[16]

float_array_16_struct_submit

* struct layout(copy pasted the Spread struct from brace to brace)

float_array_16_struct_submit

2) In the second test, we submit the data as a flat array of floats where we add each float sequentially starting from Left_0_25,following the order above:

               precalc_values_buf = new ComputeBuffer(16 * Repetitions, 4); //NumOfFloatsInStruct * Reps = 30
        List<float> temp = new List<float>(16 * Repetitions);
        for(int i=0;i<precalc_spread_values.Length;i++)
        {
            temp.Add(precalc_spread_values[i].Left_0_25);
            temp.Add(precalc_spread_values[i].Left_0_5);
            temp.Add(precalc_spread_values[i].Left_0_75);
            temp.Add(precalc_spread_values[i].Left_1);
            temp.Add(precalc_spread_values[i].Right_0_25);
            temp.Add(precalc_spread_values[i].Right_0_5);
            temp.Add(precalc_spread_values[i].Right_0_75);
            temp.Add(precalc_spread_values[i].Right_1);
            temp.Add(precalc_spread_values[i].Top_0_25);
            temp.Add(precalc_spread_values[i].Top_0_5);
            temp.Add(precalc_spread_values[i].Top_0_75);
            temp.Add(precalc_spread_values[i].Top_1);
            temp.Add(precalc_spread_values[i].Bottom_0_25);
            temp.Add(precalc_spread_values[i].Bottom_0_5);
            temp.Add(precalc_spread_values[i].Bottom_0_75);
            temp.Add(precalc_spread_values[i].Bottom_1);
        }
        precalc_values_buf.SetData(temp.ToArray());
Visualization:
* raw

raw_float_flat_array_submit

The rest of the formats work as expected.

In the first test, we get a correct row count. But in the other formats, we get the wrong count. In the second test, we get an incorrect row count for the raw format but a correct row count for all other formats.

Environment

NPatch commented 6 years ago

Let me say that I discovered an error from yesterday but it only fixed the row count for the second test for all formats apart raw. Also I don't know how to repro the case where data were in float for the first few lines and the rest in scientific notation(but when logged in C# side, all values were definitely not small enough to warrant scientific notation).

baldurk commented 6 years ago

Can you share the frame capture with me? Either here or privately. I need something concrete to look at to figure out what's going wrong in your case, I can't do that from just Unity code snippets.

NPatch commented 6 years ago

Scratch that. It's embarrassing but I uncovered another mistake. In the case where I submitted data in a struct layout, I was using the wrong stride(forgot to account for float size). Now I get the same result in both approaches. So sorry about that. I'll close this issue now. That should teach me to avoid reporting bugs when I don't have a clear mind while testing :P.