<p>You will need a new chunk of memory for the new surface anyway, so why not read from the original and store directly in the result.</p>

<p>Having precomputed normals will reduce a lot of the computation requirements though (especially needing to find&amp;read each neighbour), the user action of the extrusion will probably be interactive so you will have multiple frames with different extrusion amounts but the normals of the original surface won't change. Having the normals be around will likely be helpful for other operations as well. You could make the temporary transformed geometry just a vertex shader trick as well and only commit the result once needed.</p>

<p>Computing normals is much simpler by going face per face and then summing the the non-normalized normals per vertex and normalizing after.</p>

CC BY-SA 4.0
2018-07-13T11:02:44.917Z
2018-07-13T11:02:44.917Z
ratchet freak
<p>I'm writing a CAD program in vulkan. In my current design, I have line paths represented as large vertex buffers for rendering. I would like to implement an algorithm for extruding the path outwards, based off of cross products. Ideally I would like to implement this algorithm within a compute shader, using the vertex buffer in place of a storage buffer. The algorithm would work like this: for each vertex in original path, calculate cross product based off of the two surrounding vertices in the buffer, then normalize and multiply by a scalar.</p>

<p>I'm fairly certain that this could be done by copying the vertex buffer to a storage buffer temporarily, but I doubt that's optimal, unless it's not actually physically copied. I don't see why I should move large chunks of data from VRAM to VRAM like that. It would probably, be faster to implement this algorithm locally on the CPU in that case. I don't have much experience using compute shaders; any input is appreciated.</p>

CC BY-SA 4.0
2018-07-13T10:38:36.663Z
I don't have experience with Vulkan, but in OpenGL there's nothing to stop you binding the same buffer as a a vertex array buffer and a shader storage buffer at the same time, you just need to set memory barriers appropriately. I'd be surprised if Vulkan didn't let you do this. Presumably though you'll want to make a fresh copy of the data in the compute shader anyway? Like reading your original buffer and writing to a new one? Otherwise you'll be cross-producting vertices that may have already been transformed.
russ
CC BY-SA 4.0
2020-08-02T22:59:57.357Z
Vulkan allows buffers to be created with multiple uses in mind. So (keep in mind I am not checking the spec for compartbility here) you could potentially use VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT when the buffer is created. Then you can use the same buffer for both uses, but it is also up to you to make sure you don't step on your own toes. I have done something similar with images and it worked. A lot depends on if you plan to write an equal number of output for each input, and if you want to save the original data.
pmw1234
<algorithm><compute-shader><vulkan><buffers><cad>
Feeding vertex data to a compute shader
Holden Green
# Feeding vertex data to a compute shader

(Asked by: username_0 on 2018-07-13)

I'm writing a CAD program in vulkan. In my current design, I have line paths represented as large vertex buffers for rendering. I would like to implement an algorithm for extruding the path outwards, based off of cross products. Ideally I would like to implement this algorithm within a compute shader, using the vertex buffer in place of a storage buffer. The algorithm would work like this: for each vertex in original path, calculate cross product based off of the two surrounding vertices in the buffer, then normalize and multiply by a scalar.

I'm fairly certain that this could be done by copying the vertex buffer to a storage buffer temporarily, but I doubt that's optimal, unless it's not actually physically copied. I don't see why I should move large chunks of data from VRAM to VRAM like that. It would probably, be faster to implement this algorithm locally on the CPU in that case. I don't have much experience using compute shaders; any input is appreciated.

**Tags:** algorithm, compute-shader, vulkan, buffers, cad

> **Comments:**
> **username_1**: I don't have experience with Vulkan, but in OpenGL there's nothing to stop you binding the same buffer as a a vertex array buffer and a shader storage buffer at the same time, you just need to set memory barriers appropriately. I'd be surprised if Vulkan didn't let you do this. Presumably though you'll want to make a fresh copy of the data in the compute shader anyway? Like reading your original buffer and writing to a new one? Otherwise you'll be cross-producting vertices that may have already been transformed.  
> **username_2**: Vulkan allows buffers to be created with multiple uses in mind. So (keep in mind I am not checking the spec for compartbility here) you could potentially use VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT when the buffer is created. Then you can use the same buffer for both uses, but it is also up to you to make sure you don't step on your own toes. I have done something similar with images and it worked. A lot depends on if you plan to write an equal number of output for each input, and if you want to save the original data.  

---

## 1 answers

### Answer by username_3 on 2018-07-13. Score: 1

You will need a new chunk of memory for the new surface anyway, so why not read from the original and store directly in the result.

Having precomputed normals will reduce a lot of the computation requirements though (especially needing to find&read each neighbour), the user action of the extrusion will probably be interactive so you will have multiple frames with different extrusion amounts but the normals of the original surface won't change. Having the normals be around will likely be helpful for other operations as well. You could make the temporary transformed geometry just a vertex shader trick as well and only commit the result once needed.

Computing normals is much simpler by going face per face and then summing the the non-normalized normals per vertex and normalizing after.


---

