Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
/modules/lightmapper_rd/ @godotengine/rendering
/modules/meshoptimizer/ @godotengine/rendering
/modules/raycast/ @godotengine/rendering
/modules/texture_streaming/ @godotengine/rendering
/modules/vhacd/ @godotengine/rendering
/modules/visual_shader/ @godotengine/shaders
/modules/visual_shader/doc_classes/ @godotengine/shaders @godotengine/documentation
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,9 @@
<member name="TextServerManager" type="TextServerManager" setter="" getter="">
The [TextServerManager] singleton.
</member>
<member name="TextureStreaming" type="TextureStreaming" setter="" getter="">
The [TextureStreaming] singleton.
</member>
<member name="ThemeDB" type="ThemeDB" setter="" getter="">
The [ThemeDB] singleton.
</member>
Expand Down
5 changes: 4 additions & 1 deletion doc/classes/Performance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@
<constant name="NAVIGATION_3D_OBSTACLE_COUNT" value="58" enum="Monitor">
Number of active navigation obstacles in the [NavigationServer3D].
</constant>
<constant name="MONITOR_MAX" value="59" enum="Monitor">
<constant name="RENDER_STREAMING_TEXTURE_MEM_USED" value="59" enum="Monitor">
The amount of memory used by texture streaming (in bytes). This represents the current VRAM usage of streamed textures at their currently loaded mipmap levels.
</constant>
<constant name="MONITOR_MAX" value="60" enum="Monitor">
Represents the size of the [enum Monitor] enum.
</constant>
<constant name="MONITOR_TYPE_QUANTITY" value="0" enum="MonitorType">
Expand Down
23 changes: 23 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3496,6 +3496,29 @@
<member name="rendering/textures/lossless_compression/force_png" type="bool" setter="" getter="" default="false">
If [code]true[/code], the texture importer will import lossless textures using the PNG format. Otherwise, it will default to using WebP.
</member>
<member name="rendering/textures/streaming/enabled" type="bool" setter="" getter="" default="false">
If [code]true[/code], enables texture streaming. This system dynamically loads and unloads texture mipmaps based on visibility, reducing VRAM usage. Useful for projects with many large textures.
</member>
<member name="rendering/textures/streaming/inactivity_decay_rate_ms" type="int" setter="" getter="" default="5000">
The time (in milliseconds) per mipmap level of quality decay for textures that are no longer visible. When a streamed texture is not requested by the feedback system (e.g., it's off-screen or occluded), its resolution will gradually decrease by one mipmap level for each interval of this duration.
For example, with the default value of [code]5000[/code] ms, a texture that hasn't been visible for 10 seconds will have its quality reduced by 2 mipmap levels.
Set to [code]0[/code] to disable inactivity decay entirely, keeping textures at their last requested resolution indefinitely.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fully indefinitely, or until memory_budget_mb pushes out a texture that is not currently used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will reduce in quality each period (5000 ms in this case) until it ready the lowest quality. Obviously, lower quality levels free up less and less memory so the effect of memory levels off.

If it is set to zero, then textures never degrade unless under memory pressure.

</member>
<member name="rendering/textures/streaming/max_lod" type="int" setter="" getter="" default="3">
The maximum LOD (mipmap level) that streamed textures can load. Lower values allow higher resolution textures but use more VRAM. Valid values are [code]0[/code] (full resolution) to [code]13[/code] (lowest resolution).
</member>
<member name="rendering/textures/streaming/max_ops_per_second" type="int" setter="" getter="" default="200">
The maximum number of texture streaming operations (loading/unloading mipmaps) per second. Higher values allow faster adaptation to scene changes but may impact performance.
</member>
<member name="rendering/textures/streaming/memory_budget_enabled" type="bool" setter="" getter="" default="false">
If [code]true[/code], limits the maximum VRAM allocated for streamed textures to the value specified in [member rendering/textures/streaming/memory_budget_mb]. If exceeded, the system reduces the resolution of textures to stay within budget.
</member>
<member name="rendering/textures/streaming/memory_budget_mb" type="int" setter="" getter="" default="512">
The maximum VRAM (in megabytes) allocated for streamed textures. If exceeded, the system reduces the resolution of less important textures to stay within budget.
</member>
<member name="rendering/textures/streaming/min_lod" type="int" setter="" getter="" default="0">
The minimum LOD (mipmap level) that streamed textures start at when loaded. Higher values result in lower initial resolution and faster loading. Valid values are [code]0[/code] (full resolution) to [code]13[/code] (lowest resolution).
</member>
<member name="rendering/textures/vram_compression/cache_gpu_compressor" type="bool" setter="" getter="" default="true">
If [code]true[/code], the GPU texture compressor will cache the local RenderingDevice and its resources (shaders and pipelines), making subsequent imports faster at the cost of increased memory usage.
</member>
Expand Down
10 changes: 10 additions & 0 deletions doc/classes/RenderingServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4066,6 +4066,16 @@
Replaces [param texture]'s texture data by the texture specified by the [param by_texture] RID, without changing [param texture]'s RID.
</description>
</method>
<method name="texture_replace_compatible">
<return type="void" />
<param index="0" name="texture" type="RID" />
<param index="1" name="by_texture" type="RID" />
<description>
Replaces [param texture]'s texture data by the texture specified by the [param by_texture] RID, without changing [param texture]'s RID.
Unlike [method texture_replace], this method automatically patches any uniform sets that reference [param texture] so they point to the new underlying resource. This makes it suitable for replacing textures that are already bound in materials or shaders without invalidating existing draw state. The new texture may have different dimensions (e.g. for texture streaming mip level changes).
Textures that are not compatible will likely cause rendering errors, so it's recommended to only use this method on textures that are compatible with each other (e.g. same format and usage flags).
</description>
</method>
<method name="texture_set_force_redraw_if_visible">
<return type="void" />
<param index="0" name="texture" type="RID" />
Expand Down
47 changes: 47 additions & 0 deletions doc/classes/ResourceImporterStreamedTexture.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ResourceImporterStreamedTexture" inherits="ResourceImporter" api_type="editor" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Imports an image as a streaming-capable texture for dynamic mipmap loading.
</brief_description>
<description>
This importer creates [StreamedTexture2D] resources that support dynamic mipmap streaming. When texture streaming is enabled in the Project Settings ([member ProjectSettings.rendering/textures/streaming/enabled]), these textures can have their mipmap levels dynamically loaded and unloaded based on usage, significantly reducing VRAM consumption for projects with many large textures.
The streaming system monitors which textures are visible in each frame and loads appropriate mipmap levels accordingly. Textures that are far from the camera or not currently visible have their higher-resolution mipmap levels unloaded, while textures being displayed up close are loaded at higher resolutions.
For textures that don't need streaming support, use [ResourceImporterTexture] instead.
</description>
<tutorials>
</tutorials>
<members>
<member name="compress/channel_pack" type="int" setter="" getter="" default="0">
Controls how color channels should be used in the imported texture.
[b]sRGB Friendly:[/b] Prevents the R and RG color formats from being used, as they do not support nonlinear sRGB encoding.
[b]Optimized:[/b] Allows the RG color format to be used if the texture does not use the blue channel. This reduces memory usage if the texture's blue channel can be discarded (all pixels must have a blue value of [code]0[/code]).
</member>
<member name="compress/hdr_compression" type="int" setter="" getter="" default="1">
Controls how VRAM compression should be performed for HDR images.
[b]Disabled:[/b] Never use VRAM compression for HDR textures, regardless of whether they're opaque or transparent. Instead, the texture is converted to RGBE9995 (9-bits per channel + 5-bit exponent = 32 bits per pixel) to reduce memory usage compared to a half-float or single-precision float image format.
[b]Opaque Only:[/b] Only uses VRAM compression for opaque HDR textures. This is due to a limitation of HDR formats, as there is no VRAM-compressed HDR format that supports transparency at the same time.
[b]Always:[/b] Force VRAM compression even for HDR textures with an alpha channel. To perform this, the alpha channel is discarded on import.
[b]Note:[/b] Only effective on Radiance HDR ([code].hdr[/code]) and OpenEXR ([code].exr[/code]) images.
</member>
<member name="compress/high_quality" type="bool" setter="" getter="" default="false">
If [code]true[/code], uses BPTC compression on desktop platforms and ASTC compression on mobile platforms. When using BPTC, BC7 is used for SDR textures and BC6H is used for HDR textures.
If [code]false[/code], uses the faster but lower-quality S3TC compression on desktop platforms and ETC2 on mobile/web platforms. When using S3TC, DXT1 (BC1) is used for opaque textures and DXT5 (BC3) is used for transparent or normal map (RGTC) textures.
BPTC and ASTC support VRAM compression for HDR textures, but S3TC and ETC2 do not (see [member compress/hdr_compression]).
</member>
<member name="compress/normal_map" type="int" setter="" getter="" default="0">
When using a texture as normal map, only the red and green channels are required. Given regular texture compression algorithms produce artifacts that don't look that nice in normal maps, the RGTC compression format is the best fit for this data. Forcing this option to Enable will make Godot import the image as RGTC compressed. By default, it's set to Detect. This means that if the texture is ever detected to be used as a normal map, it will be changed to Enable and reimported automatically.
</member>
<member name="roughness/mode" type="int" setter="" getter="" default="0">
The color channel to consider as a roughness map in this texture. Only effective if Roughness &gt; Src Normal is not empty.
</member>
<member name="roughness/src_normal" type="String" setter="" getter="" default="&quot;&quot;">
The path to the texture to consider as a normal map for roughness filtering on import. Specifying this can help decrease specular aliasing slightly in 3D.
</member>
<member name="streaming/max_lod_override" type="int" setter="" getter="" default="0">
The maximum LOD (mipmap level) that can be loaded for this texture. Lower values allow higher resolution. A value of [code]0[/code] uses the global setting from [member ProjectSettings.rendering/textures/streaming/max_lod]. Values [code]1[/code] to [code]14[/code] correspond to LOD levels [code]0[/code] to [code]13[/code].
</member>
<member name="streaming/min_lod_override" type="int" setter="" getter="" default="0">
The minimum LOD (mipmap level) the texture starts at when loaded. Higher values result in lower initial resolution. A value of [code]0[/code] uses the global setting from [member ProjectSettings.rendering/textures/streaming/min_lod]. Values [code]1[/code] to [code]14[/code] correspond to LOD levels [code]0[/code] to [code]13[/code].
</member>
</members>
</class>
34 changes: 34 additions & 0 deletions doc/classes/StreamedTexture2D.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="StreamedTexture2D" inherits="Texture2D" api_type="core" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A texture that supports dynamic mipmap streaming for optimized VRAM usage.
</brief_description>
<description>
StreamedTexture2D is a texture type that supports dynamic mipmap streaming. When texture streaming is enabled in the Project Settings ([member ProjectSettings.rendering/textures/streaming/enabled]), these textures can have their mipmap levels dynamically loaded and unloaded based on usage.
The texture streaming system monitors which textures are visible in each frame and at what resolution they're being displayed. Textures that are far from the camera or not currently visible have their higher-resolution mipmap levels unloaded to save VRAM, while textures being displayed up close are loaded at higher resolutions.
This texture type is automatically created when importing images with the streaming-compatible importer.
</description>
<tutorials>
</tutorials>
<methods>
<method name="load">
<return type="int" enum="Error" />
<param index="0" name="path" type="String" />
<description>
Loads the texture from the specified [param path].
</description>
</method>
</methods>
<members>
<member name="load_path" type="String" setter="load" getter="get_load_path" default="&quot;&quot;">
The [StreamedTexture2D]'s file path to a [code].stex[/code] file.
</member>
<member name="max_lod_override" type="int" setter="set_max_lod_override" getter="get_max_lod_override" default="0">
Overrides the maximum LOD (mipmap level) that can be loaded for this specific texture. Lower values allow higher resolution. A value of [code]0[/code] uses the global setting from [member ProjectSettings.rendering/textures/streaming/max_lod]. Values [code]1[/code] to [code]14[/code] correspond to LOD levels [code]0[/code] to [code]13[/code].
</member>
<member name="min_lod_override" type="int" setter="set_min_lod_override" getter="get_min_lod_override" default="0">
Overrides the minimum LOD (mipmap level) this texture starts at when loaded. Higher values result in lower initial resolution. A value of [code]0[/code] uses the global setting from [member ProjectSettings.rendering/textures/streaming/min_lod]. Values [code]1[/code] to [code]14[/code] correspond to LOD levels [code]0[/code] to [code]13[/code].
</member>
<member name="resource_local_to_scene" type="bool" setter="set_local_to_scene" getter="is_local_to_scene" overrides="Resource" default="false" />
</members>
</class>
46 changes: 46 additions & 0 deletions doc/classes/TextureStreaming.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="TextureStreaming" inherits="Object" api_type="core" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Manages dynamic texture mipmap streaming to optimize VRAM usage.
</brief_description>
<description>
The TextureStreaming singleton manages dynamic loading and unloading of texture mipmap levels based on what is visible in the current frame. This allows projects with many large textures to significantly reduce VRAM usage while maintaining visual quality for visible textures.
Texture streaming works by analyzing shader feedback to determine which textures are actively being used and at what resolution they're being displayed. Textures that are far from the camera or not currently visible have their higher-resolution mipmap levels unloaded, while textures being displayed up close are loaded at higher resolutions.
The system includes a memory budget feature that automatically manages texture resolutions to stay within a specified VRAM limit. When the budget is exceeded, the system prioritizes textures based on how recently they were used and how much screen space they occupy.
[b]Note:[/b] Texture streaming must be enabled in the Project Settings ([member ProjectSettings.rendering/textures/streaming/enabled]) and textures must be imported with streaming support to use this feature.
</description>
<tutorials>
</tutorials>
<methods>
<method name="flush_texture_streaming">
<return type="void" />
<description>
Forces all currently queued texture streaming operations to complete immediately, bypassing the normal gradual transition and I/O throttling. This immediately loads or unloads mipmap levels to reach the target resolution for all managed textures, then emits the [signal flush_completed] signal. Useful during loading screens or when teleporting the player to ensure all textures are at their optimal resolution without a visible transition.
</description>
</method>
<method name="get_memory_budget_bytes_used">
<return type="int" />
<description>
Returns the current VRAM usage of streamed textures in bytes. This represents the total memory consumed by all streamed textures at their currently loaded mipmap levels.
</description>
</method>
</methods>
<members>
<member name="max_lod_override" type="int" setter="set_max_lod_override" getter="get_max_lod_override" default="-1">
Overrides the maximum LOD (mipmap level) that can be loaded for streamed textures at runtime. Lower values allow higher resolution textures. Valid values are [code]0[/code] (full resolution) to [code]13[/code] (lowest resolution). Values outside that range clear the override and use the default from [member ProjectSettings.rendering/textures/streaming/max_lod]; when no override is active this property returns [code]-1[/code].
</member>
<member name="memory_budget_mb_override" type="int" setter="set_memory_budget_mb_override" getter="get_memory_budget_mb_override" default="4294967295">
Overrides the memory budget for streamed textures at runtime (in megabytes). When the budget is exceeded, the system reduces texture resolution to stay within the limit. A value of [code]UINT32_MAX[/code] ([code]4294967295[/code], the maximum unsigned 32-bit integer) disables the override and uses the default from [member ProjectSettings.rendering/textures/streaming/memory_budget_mb].
</member>
<member name="min_lod_override" type="int" setter="set_min_lod_override" getter="get_min_lod_override" default="-1">
Overrides the minimum LOD (mipmap level) that textures start at when loaded. Higher values result in lower initial resolution. Valid values are [code]0[/code] (full resolution) to [code]13[/code] (lowest resolution). Values outside that range clear the override and use the default from [member ProjectSettings.rendering/textures/streaming/min_lod]; when no override is active this property returns [code]-1[/code].
</member>
</members>
<signals>
<signal name="flush_completed">
<description>
Emitted when a texture streaming flush operation finishes, after [method flush_texture_streaming] has been called and all managed textures have reached their target resolutions.
</description>
</signal>
</signals>
</class>
Loading