# StorageBuffer from existing DataBuffer

**URL:** <https://forum.babylonjs.com/t/storagebuffer-from-existing-databuffer/48507>\
**Category:** Feature requests\
**Created:** [March 4, 2024, 7:30pm UTC](https://forum.babylonjs.com/t/storagebuffer-from-existing-databuffer/48507 "2024-03-04T19:30:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefnotch](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/stefnotch/32/38100_2.png) [@stefnotch](https://forum.babylonjs.com/u/stefnotch)\
**Post date:** [March 4, 2024, 7:30pm UTC](https://forum.babylonjs.com/t/storagebuffer-from-existing-databuffer/48507/1 "2024-03-04T19:30:52Z")

</div>

I’m trying to pass an existing DataBuffer to a compute shader.

Which means calling `ComputeShader.setStorageBuffer(name: string, buffer: StorageBuffer): void;` However, the `StorageBuffer` API always creates a new storage buffer. Would it be possible to add another constructor or a static function along the lines of `.fromBuffer(buffer: DataBuffer)`?

More specifically, I’m trying to do indirect drawing as in [Dynamic size of instance count](https://forum.babylonjs.com/t/dynamic-size-of-instance-count/40839) . The accepted answer there actually has a workaround for this, which just works due to the implementation of Buffer coincidentally being close enough to StorageBuffer  
[https://playground.babylonjs.com/?webgpu#SLP3YY#9](https://playground.babylonjs.com/?webgpu#SLP3YY#9)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 4, 2024, 11:39pm UTC](https://forum.babylonjs.com/t/storagebuffer-from-existing-databuffer/48507/2 "2024-03-04T23:39:14Z")

</div>

Assigned @Evgeni\_Popov on March 4, 2024, 11:39pm UTC



---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 5, 2024, 11:45am UTC](https://forum.babylonjs.com/t/storagebuffer-from-existing-databuffer/48507/3 "2024-03-05T11:45:09Z")

</div>

Welcome aboard!

It’s a nice idea, here’s the PR:

> <https://github.com/BabylonJS/Babylon.js/pull/14833>
>
> See https://forum.babylonjs.com/t/computeshader-compilation-error-callback/48508

However, I have chosen to allow `DataBuffer` as a parameter to `setStorageBuffer`. In the same way, I can also allow it for `setUniformBuffer` and kill two birds with one stone.

---

<div class="post-metadata">

**Author:** ![stefnotch](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/stefnotch/32/38100_2.png) [@stefnotch](https://forum.babylonjs.com/u/stefnotch)\
**Post date:** [March 5, 2024, 7:38pm UTC](https://forum.babylonjs.com/t/storagebuffer-from-existing-databuffer/48507/4 "2024-03-05T19:38:24Z")

</div>

Sweet, that looks like an excellent solution. Thank you very much!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 17, 2024, 11:19pm UTC](https://forum.babylonjs.com/t/storagebuffer-from-existing-databuffer/48507/5 "2024-03-17T23:19:17Z")

</div>

Unassigned @Evgeni\_Popov on March 17, 2024, 11:19pm UTC


