<p>It looks to me like you want a buffer containing a single array of integers (not a buffer containing multiple arrays, whatever that would mean). So, you should be able to just do this:</p>

<pre><code>RWBuffer&lt;int&gt; indices;
</code></pre>

<p>then access it like this:</p>

<pre><code>indices[int(id.y)]
</code></pre>

CC BY-SA 3.0
2017-10-17T22:31:49.533Z
thank you for your quick answer. I didn't get the results I hoped, but you answered the question.
slanden
CC BY-SA 3.0
2017-10-17T19:01:59.660Z
2017-10-17T19:01:59.660Z
Nathan Reed
<p>I'm trying to follow along with a tutorial that uses an OpenGL compute shader, but I'm using D3D11. What they do is:</p>

<pre><code>layout (std430, binding = 0) buffer indices {
    int j[];
};
</code></pre>

<p>I have no experience with this and very little with directX, but that looks like a buffer of integer arrays. I've looked around and read that the equivalent to this OpenGL buffer in D3D11 is an RWBuffer. Using a compute shader, this is what I've tried. Note, I didn't redefine them in my code as they appear here, I just listed them together here.</p>

<pre><code>RWBuffer indices
{
    int j[];
}

RWBuffer&lt;{int j[];}&gt; indices;

struct index
{
    //requires explicit length, which is why this doesn't work
    int j[];
}
RWStructuredBuffer&lt;index&gt; indices;
</code></pre>

<p>But, none of those worked. The end goal is to access them like so:</p>

<pre><code>//id is SV_DispatchThreadID
indices.j[int(id.y)]
</code></pre>

<p>This seems like an inappropriately simple question to post, but I wasn't able to find documentation, even on MSDN, on defining buffers and what's allowed and not, etc.</p>

<directx11><compute-shader>
Buffer of arrays in HLSL compute shader
slanden
# Buffer of arrays in HLSL compute shader

(Asked by: username_0 on 2017-10-17)

I'm trying to follow along with a tutorial that uses an OpenGL compute shader, but I'm using D3D11. What they do is:

```
layout (std430, binding = 0) buffer indices {
    int j[];
};

```

I have no experience with this and very little with directX, but that looks like a buffer of integer arrays. I've looked around and read that the equivalent to this OpenGL buffer in D3D11 is an RWBuffer. Using a compute shader, this is what I've tried. Note, I didn't redefine them in my code as they appear here, I just listed them together here.

```
RWBuffer indices
{
    int j[];
}

RWBuffer<{int j[];}> indices;

struct index
{
    //requires explicit length, which is why this doesn't work
    int j[];
}
RWStructuredBuffer<index> indices;

```

But, none of those worked. The end goal is to access them like so:

```
//id is SV_DispatchThreadID
indices.j[int(id.y)]

```

This seems like an inappropriately simple question to post, but I wasn't able to find documentation, even on MSDN, on defining buffers and what's allowed and not, etc.

**Tags:** directx11, compute-shader


---

## 1 answers

### Answer by username_1 on 2017-10-17. Score: 3 | Accepted answer

It looks to me like you want a buffer containing a single array of integers (not a buffer containing multiple arrays, whatever that would mean). So, you should be able to just do this:

```
RWBuffer<int> indices;

```

then access it like this:

```
indices[int(id.y)]

```

> **Comments:**
> **username_0**: thank you for your quick answer. I didn't get the results I hoped, but you answered the question.  

---

