# Create RawTexture2DArray with full mipmap chain compressed texture

**URL:** <https://forum.babylonjs.com/t/create-rawtexture2darray-with-full-mipmap-chain-compressed-texture/61516>\
**Category:** Completed Features\
**Tags:** webgpu, texture\
**Created:** [November 22, 2025, 5:04am UTC](https://forum.babylonjs.com/t/create-rawtexture2darray-with-full-mipmap-chain-compressed-texture/61516 "2025-11-22T05:04:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wiiskii](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wiiskii/32/51103_2.png) [@wiiskii](https://forum.babylonjs.com/u/wiiskii)\
**Post date:** [November 22, 2025, 5:04am UTC](https://forum.babylonjs.com/t/create-rawtexture2darray-with-full-mipmap-chain-compressed-texture/61516/1 "2025-11-22T05:04:20Z")

</div>

This is a follow up question of the previous one:

> [@Compressed textures array doesn't work with WebGPU](https://forum.babylonjs.com/t/compressed-textures-array-doesnt-work-with-webgpu/61410):
>
> Hi team! Recently I’ve been working on my terrain textures. I was using Texture2DArray with compressed .dds files. However there were always console errors like: Required size for texture data layout (851968) exceeds the linear data size (262144) with offset (0). After digging for a while, I think I found the issue. On line 1238 of webgpuTextureManager.ts , the “rowsPerImage” provided to webgpu is incorrect. I believe it should be `rowsPerImage: Math.ceil(height / blockInformation…

Context: I was using dxt5 compressed textures (a number of .dds files) to render my terrain. For simplicity, I was only taking mip level 0 data from those textures and combined them together. It worked after the fix. Now I want to use the full mipmap chain.

One thing I suddenly noticed was that “RawTexture” and “RawTexture2DArray” are meant to be uncompressed by design. There are clues like in the documentation:

> Raw texture can help creating a texture directly from an array of data. This can be super useful if you either get the data from an uncompressed source or if you wish to create your texture pixel by pixel.

And in the code of `ThinWebGPUEngine.prototype.updateRawTexture` the mip level is a fixed 0.

> <https://github.com/BabylonJS/Babylon.js/blob/d32d9f623fe42b9595312ee859e2a11907cf5f01/packages/dev/core/src/Engines/WebGPU/Extensions/engine.rawTexture.ts#L276>

On the other hand, I can see there are multiple TODOs mentioning to “separate `generateMipMaps` and `useMipMaps` in InternalTexture”. Without touching InternalTexture, I currently just monkey patched ThinWebGPUEngine.updateRawTexture2DArray as a temporary solution.

My questions are,

1. Is “RawTexture2DArray” the right place for compressed, full mipmaps chain textures? Am i missing something?
2. I was trying to add “useMipMaps” option but there seems to be a huge amount interface changes. It is feasible but I am not sure if my fix will cause compatibility issue. I want to know your opinions and if possible, some guidance.

Thanks!

---

<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:** [November 24, 2025, 9:14am UTC](https://forum.babylonjs.com/t/create-rawtexture2darray-with-full-mipmap-chain-compressed-texture/61516/2 "2025-11-24T09:14:05Z")

</div>

Allowing users to provide their own mipmap textures has been on our to-do list for quite some time, but it is not a high priority.

Would you like to give it a try and create a PR for it?

I think we could simply add a new `mipLevel` parameter to all `updateRawXXX` methods.

---

<div class="post-metadata">

**Author:** ![wiiskii](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wiiskii/32/51103_2.png) [@wiiskii](https://forum.babylonjs.com/u/wiiskii)\
**Post date:** [November 28, 2025, 11:41pm UTC](https://forum.babylonjs.com/t/create-rawtexture2darray-with-full-mipmap-chain-compressed-texture/61516/3 "2025-11-28T23:41:10Z")

</div>

Sorry Evgeni, I wasn’t able to reply in last few days. Now I’m working on it. But it seems there are plenty of trade-offs I need to decide.

1. Adding mipLevel to engine.updateRawXXX works. It requires:

- modify engine.createRawXXX signature to have either a `mipLevelCount: number` or `useMipMaps: boolean` . If a number is provided, we can have a subset of mipmaps as well.
- modify `AbstractEngine` so that all engine share same signature . I am not too sure about this. Currently I am focusing on the WebGPU side. I might leave a unused optional parameter in the WebGL side in the first PR.
- create a new instance method in RawXXX class to update data for certain mip level.
- add a new `mipmaps:ArrayBufferView[]` field in InternalTexture to store the reference if need to handle context lost.

1. I also have an idea to make `data` to accept `data: Nullable<ArrayBufferView | ArrayBufferView[]>` during both creating and updating. In this way, the interface has less changes than the previous one but other code that implicitly relying on texture.\_bufferView being a TypedArray will broke.

I will go for option1 first. And see if the result really match my expectation.  
Sorry again for the late reply.

---

<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:** [December 1, 2025, 9:40am UTC](https://forum.babylonjs.com/t/create-rawtexture2darray-with-full-mipmap-chain-compressed-texture/61516/4 "2025-12-01T09:40:33Z")

</div>

No worries, we’re in no rush :).

> [@wiiskii](#):
>
> modify engine.createRawXXX signature to have either a `mipLevelCount: number` or `useMipMaps: boolean` . If a number is provided, we can have a subset of mipmaps as well.

I think adding a count is more future-proof.

> [@wiiskii](#):
>
> modify `AbstractEngine` so that all engine share same signature . I am not too sure about this. Currently I am focusing on the WebGPU side. I might leave a unused optional parameter in the WebGL side in the first PR.

Yes, we should update `AbstractEngine` as we will want to support the feature in WebGL.

> [@wiiskii](#):
>
> - create a new instance method in RawXXX class to update data for certain mip level.

Why not adding an optional **mipLevel** parameter to the existing `updateRawXXX` functions?

> [@wiiskii](#):
>
> add a new `mipmaps:ArrayBufferView[]` field in InternalTexture to store the reference if need to handle context lost.

Yes, we will need it. Also, `InternalTexture._rebuild` will have to be updated accordingly.

---

<div class="post-metadata">

**Author:** ![wiiskii](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wiiskii/32/51103_2.png) [@wiiskii](https://forum.babylonjs.com/u/wiiskii)\
**Post date:** [January 27, 2026, 11:29am UTC](https://forum.babylonjs.com/t/create-rawtexture2darray-with-full-mipmap-chain-compressed-texture/61516/5 "2026-01-27T11:29:52Z")

</div>

Thank you for the detailed guidance!
