godotengine / godotengine/godot
Error when creating a single-layered Texture2DArrayRD using RenderingServer
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Reproducible in 4.6 rc 1
### System information
Godot v4.6.rc1 - Windows 11 (build 26200) - Multi-window, 1 monitor - Direct3D 12 (Forward+) - dedicated NVIDIA GeForce RTX 4060 Laptop GPU (NVIDIA; 32.0.15.8183) - Intel(R) Core(TM) i7-14650HX (24 threads) - 31.71 GiB memory
### Issue description
In my opinion, creating a 2D texture array with only one layer is a valid use case of a texture array. However, as seen in [texture_storage.cpp](https://github.com/godotengine/godot/blob/master/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp#L1767), having only one layer is enforced and an error is thrown. The error is "Condition "tf.array_layers == 1" is true.".
In my case, I am creating a terrain system which uses a texture array to supply information for each terrain LOD (level of detail). Having only one LOD means only having one texture in the array, which causes the error. This requirement should be relaxed.
### Steps to reproduce
```
func throw_error():
var rd := RenderingServer.get_rendering_device()
var format := RDTextureFormat.new()
format.format = rd.DATA_FORMAT_R32_SFLOAT
format.texture_type = rd.TEXTURE_TYPE_2D_ARRAY
format.width = 512
format.height = 512
format.array_layers = 1
format.usage_bits = rd.TEXTURE_USAGE_SAMPLING_BIT | rd.TEXTURE_USAGE_STORAGE_BIT
var texture_rid := rd.texture_create(format, RDTextureView.new())
var texture_rd_rid := RenderingServer.texture_rd_create(texture_rid, RenderingServer.TEXTURE_LAYERED_2D_ARRAY)
```
### Minimal reproduction project (MRP)
Code attached above
Contributor guide
Research direction
Start in servers/rendering/renderer_rd/storage_rd/texture_storage.cpp around line 1767 and reproduce the issue with the GDScript snippet in the report. Check how a Texture2DArrayRD with array_layers set to 1 is validated, then run the attached minimal reproduction project. Done means the single-layer texture creation no longer emits the reported condition error while existing texture-array behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100