Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check device texture size limits in RenderingDevice::texture_create #93819

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion servers/rendering/rendering_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,10 @@ RID RenderingDevice::texture_create(const TextureFormat &p_format, const Texture

if (format.texture_type == TEXTURE_TYPE_1D_ARRAY || format.texture_type == TEXTURE_TYPE_2D_ARRAY || format.texture_type == TEXTURE_TYPE_CUBE_ARRAY || format.texture_type == TEXTURE_TYPE_CUBE) {
ERR_FAIL_COND_V_MSG(format.array_layers < 1, RID(),
"Amount of layers must be equal or greater than 1 for arrays and cubemaps.");
"Number of layers must be equal or greater than 1 for arrays and cubemaps.");
ERR_FAIL_COND_V_MSG((format.texture_type == TEXTURE_TYPE_CUBE_ARRAY || format.texture_type == TEXTURE_TYPE_CUBE) && (format.array_layers % 6) != 0, RID(),
"Cubemap and cubemap array textures must provide a layer number that is multiple of 6");
ERR_FAIL_COND_V_MSG(format.array_layers > driver->limit_get(LIMIT_MAX_TEXTURE_ARRAY_LAYERS), RID(), "Number of layers exceeds device maximum.");
} else {
format.array_layers = 1;
}
Expand All @@ -761,6 +762,28 @@ RID RenderingDevice::texture_create(const TextureFormat &p_format, const Texture
format.height = format.texture_type != TEXTURE_TYPE_1D && format.texture_type != TEXTURE_TYPE_1D_ARRAY ? format.height : 1;
format.depth = format.texture_type == TEXTURE_TYPE_3D ? format.depth : 1;

uint64_t size_max = 0;
switch (format.texture_type) {
case TEXTURE_TYPE_1D:
case TEXTURE_TYPE_1D_ARRAY:
size_max = driver->limit_get(LIMIT_MAX_TEXTURE_SIZE_1D);
break;
case TEXTURE_TYPE_2D:
case TEXTURE_TYPE_2D_ARRAY:
size_max = driver->limit_get(LIMIT_MAX_TEXTURE_SIZE_2D);
break;
case TEXTURE_TYPE_CUBE:
case TEXTURE_TYPE_CUBE_ARRAY:
size_max = driver->limit_get(LIMIT_MAX_TEXTURE_SIZE_CUBE);
break;
case TEXTURE_TYPE_3D:
size_max = driver->limit_get(LIMIT_MAX_TEXTURE_SIZE_3D);
break;
case TEXTURE_TYPE_MAX:
break;
}
ERR_FAIL_COND_V_MSG(format.width > size_max || format.height > size_max || format.depth > size_max, RID(), "Texture dimensions exceed device maximum.");

uint32_t required_mipmaps = get_image_required_mipmaps(format.width, format.height, format.depth);

ERR_FAIL_COND_V_MSG(required_mipmaps < format.mipmaps, RID(),
Expand Down