summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/color.cpp7
-rw-r--r--core/color.h1
-rw-r--r--core/image.cpp2
-rw-r--r--core/io/file_access_compressed.cpp8
-rw-r--r--core/io/multiplayer_api.cpp496
-rw-r--r--core/io/multiplayer_api.h24
-rw-r--r--core/io/resource_format_binary.cpp41
-rw-r--r--core/script_language.cpp9
-rw-r--r--core/script_language.h45
-rw-r--r--core/variant_call.cpp2
-rw-r--r--doc/classes/@GlobalScope.xml12
-rw-r--r--doc/classes/AnimatedSprite.xml4
-rw-r--r--doc/classes/AnimatedTexture.xml13
-rw-r--r--doc/classes/Animation.xml2
-rw-r--r--doc/classes/AnimationTreePlayer.xml656
-rw-r--r--doc/classes/ArrayMesh.xml21
-rw-r--r--doc/classes/AtlasTexture.xml9
-rw-r--r--doc/classes/BakedLightmap.xml99
-rw-r--r--doc/classes/BakedLightmapData.xml65
-rw-r--r--doc/classes/BaseMaterial3D.xml477
-rw-r--r--doc/classes/BitmapFont.xml4
-rw-r--r--doc/classes/Button.xml2
-rw-r--r--doc/classes/CPUParticles2D.xml4
-rw-r--r--doc/classes/Camera.xml2
-rw-r--r--doc/classes/CameraEffects.xml33
-rw-r--r--doc/classes/CameraFeed.xml50
-rw-r--r--doc/classes/CameraTexture.xml3
-rw-r--r--doc/classes/CanvasItem.xml178
-rw-r--r--doc/classes/CanvasItemMaterial.xml4
-rw-r--r--doc/classes/CheckBox.xml8
-rw-r--r--doc/classes/CheckButton.xml8
-rw-r--r--doc/classes/Color.xml12
-rw-r--r--doc/classes/ColorPicker.xml12
-rw-r--r--doc/classes/ColorPickerButton.xml2
-rw-r--r--doc/classes/Control.xml4
-rw-r--r--doc/classes/CubeMap.xml99
-rw-r--r--doc/classes/Cubemap.xml13
-rw-r--r--doc/classes/CubemapArray.xml13
-rw-r--r--doc/classes/CurveTexture.xml2
-rw-r--r--doc/classes/DirectionalLight.xml2
-rw-r--r--doc/classes/DynamicFont.xml6
-rw-r--r--doc/classes/EditorInterface.xml2
-rw-r--r--doc/classes/EditorPlugin.xml4
-rw-r--r--doc/classes/EditorResourcePreviewGenerator.xml4
-rw-r--r--doc/classes/EditorSpatialGizmoPlugin.xml6
-rw-r--r--doc/classes/Environment.xml126
-rw-r--r--doc/classes/FileDialog.xml8
-rw-r--r--doc/classes/GIProbe.xml24
-rw-r--r--doc/classes/GIProbeData.xml74
-rw-r--r--doc/classes/GeometryInstance.xml12
-rw-r--r--doc/classes/GradientTexture.xml2
-rw-r--r--doc/classes/GraphEdit.xml8
-rw-r--r--doc/classes/GraphNode.xml10
-rw-r--r--doc/classes/HScrollBar.xml8
-rw-r--r--doc/classes/HSlider.xml8
-rw-r--r--doc/classes/HSplitContainer.xml2
-rw-r--r--doc/classes/Image.xml51
-rw-r--r--doc/classes/ImageTexture.xml64
-rw-r--r--doc/classes/ImmediateGeometry.xml2
-rw-r--r--doc/classes/ItemList.xml10
-rw-r--r--doc/classes/LargeTexture.xml21
-rw-r--r--doc/classes/Light.xml12
-rw-r--r--doc/classes/Light2D.xml20
-rw-r--r--doc/classes/Line2D.xml3
-rw-r--r--doc/classes/LineEdit.xml4
-rw-r--r--doc/classes/LineShape2D.xml2
-rw-r--r--doc/classes/Material.xml2
-rw-r--r--doc/classes/Mesh.xml28
-rw-r--r--doc/classes/MeshInstance2D.xml6
-rw-r--r--doc/classes/MeshLibrary.xml6
-rw-r--r--doc/classes/MeshTexture.xml5
-rw-r--r--doc/classes/MultiMesh.xml50
-rw-r--r--doc/classes/MultiMeshInstance2D.xml6
-rw-r--r--doc/classes/Navigation.xml77
-rw-r--r--doc/classes/Navigation2D.xml57
-rw-r--r--doc/classes/Navigation2DServer.xml20
-rw-r--r--doc/classes/NavigationAgent.xml34
-rw-r--r--doc/classes/NavigationAgent2D.xml32
-rw-r--r--doc/classes/NavigationMeshGenerator.xml (renamed from doc/classes/EditorNavigationMeshGenerator.xml)2
-rw-r--r--doc/classes/NavigationObstacle.xml4
-rw-r--r--doc/classes/NavigationObstacle2D.xml4
-rw-r--r--doc/classes/NavigationServer.xml12
-rw-r--r--doc/classes/NinePatchRect.xml2
-rw-r--r--doc/classes/ORMMaterial3D.xml13
-rw-r--r--doc/classes/OmniLight.xml9
-rw-r--r--doc/classes/OptionButton.xml8
-rw-r--r--doc/classes/PanoramaSky.xml4
-rw-r--r--doc/classes/ParallaxLayer.xml2
-rw-r--r--doc/classes/Particles.xml2
-rw-r--r--doc/classes/Particles2D.xml6
-rw-r--r--doc/classes/ParticlesMaterial.xml44
-rw-r--r--doc/classes/PhysicalBone.xml6
-rw-r--r--doc/classes/PointMesh.xml2
-rw-r--r--doc/classes/Polygon2D.xml11
-rw-r--r--doc/classes/PopupMenu.xml38
-rw-r--r--doc/classes/PrimitiveMesh.xml2
-rw-r--r--doc/classes/ProceduralSky.xml2
-rw-r--r--doc/classes/ProjectSettings.xml93
-rw-r--r--doc/classes/ProxyTexture.xml5
-rw-r--r--doc/classes/RenderingDevice.xml13
-rw-r--r--doc/classes/Resource.xml2
-rw-r--r--doc/classes/RichTextLabel.xml2
-rw-r--r--doc/classes/Shader.xml4
-rw-r--r--doc/classes/Skeleton.xml4
-rw-r--r--doc/classes/Sky.xml6
-rw-r--r--doc/classes/SpatialMaterial.xml649
-rw-r--r--doc/classes/SpinBox.xml4
-rw-r--r--doc/classes/Sprite.xml12
-rw-r--r--doc/classes/Sprite3D.xml4
-rw-r--r--doc/classes/SpriteBase3D.xml2
-rw-r--r--doc/classes/SpriteFrames.xml6
-rw-r--r--doc/classes/StandardMaterial3D.xml13
-rw-r--r--doc/classes/StreamTexture.xml3
-rw-r--r--doc/classes/StyleBoxTexture.xml4
-rw-r--r--doc/classes/SurfaceTool.xml2
-rw-r--r--doc/classes/TabContainer.xml18
-rw-r--r--doc/classes/Tabs.xml18
-rw-r--r--doc/classes/TextEdit.xml10
-rw-r--r--doc/classes/Texture.xml126
-rw-r--r--doc/classes/Texture2D.xml133
-rw-r--r--doc/classes/Texture2DArray.xml13
-rw-r--r--doc/classes/Texture3D.xml18
-rw-r--r--doc/classes/TextureArray.xml15
-rw-r--r--doc/classes/TextureButton.xml10
-rw-r--r--doc/classes/TextureLayered.xml66
-rw-r--r--doc/classes/TextureProgress.xml12
-rw-r--r--doc/classes/TextureRect.xml4
-rw-r--r--doc/classes/Theme.xml12
-rw-r--r--doc/classes/TileSet.xml8
-rw-r--r--doc/classes/TouchScreenButton.xml4
-rw-r--r--doc/classes/Tree.xml12
-rw-r--r--doc/classes/TreeItem.xml23
-rw-r--r--doc/classes/VScrollBar.xml8
-rw-r--r--doc/classes/VSlider.xml8
-rw-r--r--doc/classes/VSplitContainer.xml2
-rw-r--r--doc/classes/VideoPlayer.xml4
-rw-r--r--doc/classes/Viewport.xml69
-rw-r--r--doc/classes/ViewportTexture.xml5
-rw-r--r--doc/classes/VisualServer.xml1659
-rw-r--r--doc/classes/VisualShaderNode.xml2
-rw-r--r--doc/classes/VisualShaderNodeCubemap.xml (renamed from doc/classes/VisualShaderNodeCubeMap.xml)16
-rw-r--r--doc/classes/VisualShaderNodeCubemapUniform.xml (renamed from doc/classes/VisualShaderNodeCubeMapUniform.xml)6
-rw-r--r--doc/classes/VisualShaderNodeTexture.xml2
-rw-r--r--doc/classes/WindowDialog.xml4
-rw-r--r--doc/classes/World.xml2
-rw-r--r--doc/classes/WorldEnvironment.xml2
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp6
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.h2
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp6
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h2
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp23
-rw-r--r--editor/project_manager.cpp6
-rw-r--r--modules/gdnative/gdnative/color.cpp5
-rw-r--r--modules/gdnative/gdnative_api.json7
-rw-r--r--modules/gdnative/include/gdnative/color.h2
-rw-r--r--modules/gdnative/nativescript/godot_nativescript.cpp28
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp342
-rw-r--r--modules/gdnative/nativescript/nativescript.h29
-rw-r--r--modules/gdnative/pluginscript/pluginscript_instance.cpp32
-rw-r--r--modules/gdnative/pluginscript/pluginscript_instance.h9
-rw-r--r--modules/gdnative/pluginscript/pluginscript_script.cpp105
-rw-r--r--modules/gdnative/pluginscript/pluginscript_script.h17
-rw-r--r--modules/gdscript/gdscript.cpp155
-rw-r--r--modules/gdscript/gdscript.h23
-rw-r--r--modules/gdscript/language_server/gdscript_text_document.cpp2
-rw-r--r--modules/mono/csharp_script.cpp215
-rw-r--r--modules/mono/csharp_script.h28
-rw-r--r--modules/opensimplex/doc_classes/NoiseTexture.xml5
-rw-r--r--modules/tinyexr/image_saver_tinyexr.cpp2
-rw-r--r--modules/visual_script/visual_script.cpp125
-rw-r--r--modules/visual_script/visual_script.h23
-rw-r--r--platform/x11/os_x11.cpp5
-rw-r--r--scene/3d/gi_probe.cpp5
-rw-r--r--scene/main/node.cpp128
-rw-r--r--scene/main/node.h31
-rw-r--r--scene/resources/environment.cpp2
-rw-r--r--scene/resources/material.cpp26
-rw-r--r--scene/resources/mesh.cpp2
-rw-r--r--scene/resources/texture.cpp9
-rw-r--r--servers/visual/rasterizer.h2
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp3
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_scene_rd.h2
-rw-r--r--servers/visual_server.cpp158
-rw-r--r--servers/visual_server.h42
-rw-r--r--thirdparty/vulkan/vk_mem_alloc.h13676
185 files changed, 11824 insertions, 10022 deletions
diff --git a/core/color.cpp b/core/color.cpp
index cb3068c487..03aeb2085b 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -508,13 +508,6 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
return Color(m + r, m + g, m + b, p_a);
}
-// FIXME: Remove once Godot 3.1 has been released
-float Color::gray() const {
-
- WARN_DEPRECATED_MSG("'Color.gray()' is deprecated and will be removed in a future version. Use 'Color.v' for a better grayscale approximation.");
- return (r + g + b) / 3.0;
-}
-
Color::operator String() const {
return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a);
diff --git a/core/color.h b/core/color.h
index 75a2b07d71..a7ab94ab08 100644
--- a/core/color.h
+++ b/core/color.h
@@ -56,7 +56,6 @@ struct Color {
uint64_t to_rgba64() const;
uint64_t to_argb64() const;
uint64_t to_abgr64() const;
- float gray() const;
float get_h() const;
float get_s() const;
float get_v() const;
diff --git a/core/image.cpp b/core/image.cpp
index b126437fa9..d9f84621a3 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -1715,7 +1715,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
roughness = c.b;
} break;
case ROUGHNESS_CHANNEL_L: {
- roughness = c.gray();
+ roughness = c.get_v();
} break;
case ROUGHNESS_CHANNEL_A: {
roughness = c.a;
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 87ead37b91..17cc6ce58f 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -63,6 +63,10 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
f = p_base;
cmode = (Compression::Mode)f->get_32();
block_size = f->get_32();
+ if (block_size == 0) {
+ f = NULL; // Let the caller to handle the FileAccess object if failed to open as compressed file.
+ ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Can't open compressed file '" + p_base->get_path() + "' with block size 0, it is corrupted.");
+ }
read_total = f->get_32();
int bc = (read_total / block_size) + 1;
int acc_ofs = f->get_position() + bc * 4;
@@ -125,13 +129,11 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
char rmagic[5];
f->get_buffer((uint8_t *)rmagic, 4);
rmagic[4] = 0;
- if (magic != rmagic) {
+ if (magic != rmagic || open_after_magic(f) != OK) {
memdelete(f);
f = NULL;
return ERR_FILE_UNRECOGNIZED;
}
-
- open_after_magic(f);
}
return OK;
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index fbed460a4e..27c122fac7 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -32,6 +32,7 @@
#include "core/io/marshalls.h"
#include "scene/main/node.h"
+#include <stdint.h>
#ifdef DEBUG_ENABLED
#include "core/os/os.h"
@@ -180,7 +181,8 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
}
#endif
- uint8_t packet_type = p_packet[0];
+ // Extract the `packet_type` from the LSB three bits:
+ uint8_t packet_type = p_packet[0] & 7;
switch (packet_type) {
@@ -197,31 +199,80 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
case NETWORK_COMMAND_REMOTE_CALL:
case NETWORK_COMMAND_REMOTE_SET: {
- ERR_FAIL_COND_MSG(p_packet_len < 6, "Invalid packet received. Size too small.");
-
- Node *node = _process_get_node(p_from, p_packet, p_packet_len);
+ // Extract packet meta
+ int packet_min_size = 1;
+ int name_id_offset = 1;
+ ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
+ // Compute the meta size, which depends on the compression level.
+ int node_id_compression = (p_packet[0] & 24) >> 3;
+ int name_id_compression = (p_packet[0] & 32) >> 5;
+
+ switch (node_id_compression) {
+ case NETWORK_NODE_ID_COMPRESSION_8:
+ packet_min_size += 1;
+ name_id_offset += 1;
+ break;
+ case NETWORK_NODE_ID_COMPRESSION_16:
+ packet_min_size += 2;
+ name_id_offset += 2;
+ break;
+ case NETWORK_NODE_ID_COMPRESSION_32:
+ packet_min_size += 4;
+ name_id_offset += 4;
+ break;
+ default:
+ ERR_FAIL_MSG("Was not possible to extract the node id compression mode.");
+ }
+ switch (name_id_compression) {
+ case NETWORK_NAME_ID_COMPRESSION_8:
+ packet_min_size += 1;
+ break;
+ case NETWORK_NAME_ID_COMPRESSION_16:
+ packet_min_size += 2;
+ break;
+ default:
+ ERR_FAIL_MSG("Was not possible to extract the name id compression mode.");
+ }
+ ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
+ uint32_t node_target = 0;
+ switch (node_id_compression) {
+ case NETWORK_NODE_ID_COMPRESSION_8:
+ node_target = p_packet[1];
+ break;
+ case NETWORK_NODE_ID_COMPRESSION_16:
+ node_target = decode_uint16(p_packet + 1);
+ break;
+ case NETWORK_NODE_ID_COMPRESSION_32:
+ node_target = decode_uint32(p_packet + 1);
+ break;
+ default:
+ // Unreachable, checked before.
+ CRASH_NOW();
+ }
+ Node *node = _process_get_node(p_from, p_packet, node_target, p_packet_len);
ERR_FAIL_COND_MSG(node == NULL, "Invalid packet received. Requested node was not found.");
- // Detect cstring end.
- int len_end = 5;
- for (; len_end < p_packet_len; len_end++) {
- if (p_packet[len_end] == 0) {
+ uint16_t name_id = 0;
+ switch (name_id_compression) {
+ case NETWORK_NAME_ID_COMPRESSION_8:
+ name_id = p_packet[name_id_offset];
break;
- }
+ case NETWORK_NAME_ID_COMPRESSION_16:
+ name_id = decode_uint16(p_packet + name_id_offset);
+ break;
+ default:
+ // Unreachable, checked before.
+ CRASH_NOW();
}
- ERR_FAIL_COND_MSG(len_end >= p_packet_len, "Invalid packet received. Size too small.");
-
- StringName name = String::utf8((const char *)&p_packet[5]);
-
if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {
- _process_rpc(node, name, p_from, p_packet, p_packet_len, len_end + 1);
+ _process_rpc(node, name_id, p_from, p_packet, p_packet_len, packet_min_size);
} else {
- _process_rset(node, name, p_from, p_packet, p_packet_len, len_end + 1);
+ _process_rset(node, name_id, p_from, p_packet, p_packet_len, packet_min_size);
}
} break;
@@ -233,15 +284,14 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
}
}
-Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int p_packet_len) {
+Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) {
- uint32_t target = decode_uint32(&p_packet[1]);
Node *node = NULL;
- if (target & 0x80000000) {
+ if (p_node_target & 0x80000000) {
// Use full path (not cached yet).
- int ofs = target & 0x7FFFFFFF;
+ int ofs = p_node_target & 0x7FFFFFFF;
ERR_FAIL_COND_V_MSG(ofs >= p_packet_len, NULL, "Invalid packet received. Size smaller than declared.");
@@ -256,7 +306,7 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
} else {
// Use cached path.
- int id = target;
+ int id = p_node_target;
Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from);
ERR_FAIL_COND_V_MSG(!E, NULL, "Invalid packet received. Requests invalid peer cache.");
@@ -274,21 +324,21 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
return node;
}
-void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
// Check that remote can call the RPC on this node.
- RPCMode rpc_mode = RPC_MODE_DISABLED;
- const Map<StringName, RPCMode>::Element *E = p_node->get_node_rpc_mode(p_name);
- if (E) {
- rpc_mode = E->get();
- } else if (p_node->get_script_instance()) {
- rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_name);
+ StringName name = p_node->get_node_rpc_method(p_rpc_method_id);
+ RPCMode rpc_mode = p_node->get_node_rpc_mode_by_id(p_rpc_method_id);
+ if (name == StringName() && p_node->get_script_instance()) {
+ name = p_node->get_script_instance()->get_rpc_method(p_rpc_method_id);
+ rpc_mode = p_node->get_script_instance()->get_rpc_mode_by_id(p_rpc_method_id);
}
+ ERR_FAIL_COND(name == StringName());
bool can_call = _can_call_mode(p_node, rpc_mode, p_from);
- ERR_FAIL_COND_MSG(!can_call, "RPC '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rpc_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
+ ERR_FAIL_COND_MSG(!can_call, "RPC '" + String(name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rpc_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
int argc = p_packet[p_offset];
Vector<Variant> args;
@@ -311,7 +361,7 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
int vlen;
- Error err = decode_variant(args.write[i], &p_packet[p_offset], p_packet_len - p_offset, &vlen, allow_object_decoding || network_peer->is_object_decoding_allowed());
+ Error err = _decode_and_decompress_variant(args.write[i], &p_packet[p_offset], p_packet_len - p_offset, &vlen);
ERR_FAIL_COND_MSG(err != OK, "Invalid packet received. Unable to decode RPC argument.");
argp.write[i] = &args[i];
@@ -320,29 +370,29 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
Variant::CallError ce;
- p_node->call(p_name, (const Variant **)argp.ptr(), argc, ce);
+ p_node->call(name, (const Variant **)argp.ptr(), argc, ce);
if (ce.error != Variant::CallError::CALL_OK) {
- String error = Variant::get_call_error_text(p_node, p_name, (const Variant **)argp.ptr(), argc, ce);
+ String error = Variant::get_call_error_text(p_node, name, (const Variant **)argp.ptr(), argc, ce);
error = "RPC - " + error;
ERR_PRINT(error);
}
}
-void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+void MultiplayerAPI::_process_rset(Node *p_node, const uint16_t p_rpc_property_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
// Check that remote can call the RSET on this node.
- RPCMode rset_mode = RPC_MODE_DISABLED;
- const Map<StringName, RPCMode>::Element *E = p_node->get_node_rset_mode(p_name);
- if (E) {
- rset_mode = E->get();
- } else if (p_node->get_script_instance()) {
- rset_mode = p_node->get_script_instance()->get_rset_mode(p_name);
+ StringName name = p_node->get_node_rset_property(p_rpc_property_id);
+ RPCMode rset_mode = p_node->get_node_rset_mode_by_id(p_rpc_property_id);
+ if (name == StringName() && p_node->get_script_instance()) {
+ name = p_node->get_script_instance()->get_rset_property(p_rpc_property_id);
+ rset_mode = p_node->get_script_instance()->get_rset_mode_by_id(p_rpc_property_id);
}
+ ERR_FAIL_COND(name == StringName());
bool can_call = _can_call_mode(p_node, rset_mode, p_from);
- ERR_FAIL_COND_MSG(!can_call, "RSET '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
+ ERR_FAIL_COND_MSG(!can_call, "RSET '" + String(name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
#ifdef DEBUG_ENABLED
if (profiling) {
@@ -353,26 +403,33 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p
#endif
Variant value;
- Error err = decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset, NULL, allow_object_decoding || network_peer->is_object_decoding_allowed());
+ Error err = _decode_and_decompress_variant(value, &p_packet[p_offset], p_packet_len - p_offset, NULL);
ERR_FAIL_COND_MSG(err != OK, "Invalid packet received. Unable to decode RSET value.");
bool valid;
- p_node->set(p_name, value, &valid);
+ p_node->set(name, value, &valid);
if (!valid) {
- String error = "Error setting remote property '" + String(p_name) + "', not found in object of type " + p_node->get_class() + ".";
+ String error = "Error setting remote property '" + String(name) + "', not found in object of type " + p_node->get_class() + ".";
ERR_PRINT(error);
}
}
void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
- ERR_FAIL_COND_MSG(p_packet_len < 5, "Invalid packet received. Size too small.");
- int id = decode_uint32(&p_packet[1]);
+ ERR_FAIL_COND_MSG(p_packet_len < 38, "Invalid packet received. Size too small.");
+ int ofs = 1;
+
+ String methods_md5;
+ methods_md5.parse_utf8((const char *)(p_packet + ofs), 32);
+ ofs += 33;
+
+ int id = decode_uint32(&p_packet[ofs]);
+ ofs += 4;
String paths;
- paths.parse_utf8((const char *)&p_packet[5], p_packet_len - 5);
+ paths.parse_utf8((const char *)(p_packet + ofs), p_packet_len - ofs);
NodePath path = paths;
@@ -380,6 +437,13 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
path_get_cache[p_from] = PathGetCache();
}
+ Node *node = root_node->get_node(path);
+ ERR_FAIL_COND(node == NULL);
+ const bool valid_rpc_checksum = node->get_rpc_md5() == methods_md5;
+ if (valid_rpc_checksum == false) {
+ ERR_PRINT("The rpc node checksum failed. Make sure to have the same methods on both nodes. Node path: " + path);
+ }
+
PathGetCache::NodeInfo ni;
ni.path = path;
ni.instance = 0;
@@ -392,9 +456,10 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
Vector<uint8_t> packet;
- packet.resize(1 + len);
+ packet.resize(1 + 1 + len);
packet.write[0] = NETWORK_COMMAND_CONFIRM_PATH;
- encode_cstring(pname.get_data(), &packet.write[1]);
+ packet.write[1] = valid_rpc_checksum;
+ encode_cstring(pname.get_data(), &packet.write[2]);
network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
network_peer->set_target_peer(p_from);
@@ -403,13 +468,19 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
- ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small.");
+ ERR_FAIL_COND_MSG(p_packet_len < 3, "Invalid packet received. Size too small.");
+
+ const bool valid_rpc_checksum = p_packet[1];
String paths;
- paths.parse_utf8((const char *)&p_packet[1], p_packet_len - 1);
+ paths.parse_utf8((const char *)&p_packet[2], p_packet_len - 2);
NodePath path = paths;
+ if (valid_rpc_checksum == false) {
+ ERR_PRINT("The rpc node checksum failed. Make sure to have the same methods on both nodes. Node path: " + path);
+ }
+
PathSentCache *psc = path_send_cache.getptr(path);
ERR_FAIL_COND_MSG(!psc, "Invalid packet received. Tries to confirm a path which was not found in cache.");
@@ -418,7 +489,7 @@ void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet,
E->get() = true;
}
-bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int p_target) {
+bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentCache *psc, int p_target) {
bool has_all_peers = true;
List<int> peers_to_add; // If one is missing, take note to add it.
@@ -443,31 +514,192 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int
}
}
- // Those that need to be added, send a message for this.
+ if (peers_to_add.size() > 0) {
- for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
+ // Those that need to be added, send a message for this.
// Encode function name.
- CharString pname = String(p_path).utf8();
- int len = encode_cstring(pname.get_data(), NULL);
+ const CharString path = String(p_path).utf8();
+ const int path_len = encode_cstring(path.get_data(), NULL);
+
+ // Extract MD5 from rpc methods list.
+ const String methods_md5 = p_node->get_rpc_md5();
+ const int methods_md5_len = 33; // 32 + 1 for the `0` that is added by the encoder.
Vector<uint8_t> packet;
+ packet.resize(1 + 4 + path_len + methods_md5_len);
+ int ofs = 0;
+
+ packet.write[ofs] = NETWORK_COMMAND_SIMPLIFY_PATH;
+ ofs += 1;
+
+ ofs += encode_cstring(methods_md5.utf8().get_data(), &packet.write[ofs]);
+
+ ofs += encode_uint32(psc->id, &packet.write[ofs]);
+
+ ofs += encode_cstring(path.get_data(), &packet.write[ofs]);
- packet.resize(1 + 4 + len);
- packet.write[0] = NETWORK_COMMAND_SIMPLIFY_PATH;
- encode_uint32(psc->id, &packet.write[1]);
- encode_cstring(pname.get_data(), &packet.write[5]);
+ for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
- network_peer->set_target_peer(E->get()); // To all of you.
- network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
- network_peer->put_packet(packet.ptr(), packet.size());
+ network_peer->set_target_peer(E->get()); // To all of you.
+ network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
+ network_peer->put_packet(packet.ptr(), packet.size());
- psc->confirmed_peers.insert(E->get(), false); // Insert into confirmed, but as false since it was not confirmed.
+ psc->confirmed_peers.insert(E->get(), false); // Insert into confirmed, but as false since it was not confirmed.
+ }
}
return has_all_peers;
}
+// The variant is compressed and encoded; The first byte contains all the meta
+// information and the format is:
+// - The first LSB 5 bits are used for the variant type.
+// - The next two bits are used to store the encoding mode.
+// - The most significant is used to store the boolean value.
+#define VARIANT_META_TYPE_MASK 0x1F
+#define VARIANT_META_EMODE_MASK 0x60
+#define VARIANT_META_BOOL_MASK 0x80
+#define ENCODE_8 0 << 5
+#define ENCODE_16 1 << 5
+#define ENCODE_32 2 << 5
+#define ENCODE_64 3 << 5
+Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
+
+ // Unreachable because `VARIANT_MAX` == 27 and `ENCODE_VARIANT_MASK` == 31
+ CRASH_COND(p_variant.get_type() > VARIANT_META_TYPE_MASK);
+
+ uint8_t *buf = r_buffer;
+ r_len = 0;
+ uint8_t encode_mode = 0;
+
+ switch (p_variant.get_type()) {
+ case Variant::BOOL: {
+ if (buf) {
+ // We still have 1 free bit in the meta, so let's use it.
+ buf[0] = (p_variant.operator bool()) ? (1 << 7) : 0;
+ buf[0] |= encode_mode | p_variant.get_type();
+ }
+ r_len += 1;
+ } break;
+ case Variant::INT: {
+ if (buf) {
+ // Reserve the first byte for the meta.
+ buf += 1;
+ }
+ r_len += 1;
+ int64_t val = p_variant;
+ if (val <= (int64_t)INT8_MAX && val >= (int64_t)INT8_MIN) {
+ // Use 8 bit
+ encode_mode = ENCODE_8;
+ if (buf) {
+ buf[0] = val;
+ }
+ r_len += 1;
+ } else if (val <= (int64_t)INT16_MAX && val >= (int64_t)INT16_MIN) {
+ // Use 16 bit
+ encode_mode = ENCODE_16;
+ if (buf) {
+ encode_uint16(val, buf);
+ }
+ r_len += 2;
+ } else if (val <= (int64_t)INT32_MAX && val >= (int64_t)INT32_MIN) {
+ // Use 32 bit
+ encode_mode = ENCODE_32;
+ if (buf) {
+ encode_uint32(val, buf);
+ }
+ r_len += 4;
+ } else {
+ // Use 64 bit
+ encode_mode = ENCODE_64;
+ if (buf) {
+ encode_uint64(val, buf);
+ }
+ r_len += 8;
+ }
+ // Store the meta
+ if (buf) {
+ buf -= 1;
+ buf[0] = encode_mode | p_variant.get_type();
+ }
+ } break;
+ default:
+ // Any other case is not yet compressed.
+ Error err = encode_variant(p_variant, r_buffer, r_len, allow_object_decoding || network_peer->is_object_decoding_allowed());
+ if (err != OK)
+ return err;
+ if (r_buffer) {
+ // The first byte is not used by the marshaling, so store the type
+ // so we know how to decompress and decode this variant.
+ r_buffer[0] = p_variant.get_type();
+ }
+ }
+
+ return OK;
+}
+Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len) {
+
+ const uint8_t *buf = p_buffer;
+ int len = p_len;
+
+ ERR_FAIL_COND_V(len < 1, ERR_INVALID_DATA);
+ uint8_t type = buf[0] & VARIANT_META_TYPE_MASK;
+ uint8_t encode_mode = buf[0] & VARIANT_META_EMODE_MASK;
+
+ ERR_FAIL_COND_V(type >= Variant::VARIANT_MAX, ERR_INVALID_DATA);
+
+ switch (type) {
+ case Variant::BOOL: {
+ bool val = (buf[0] & VARIANT_META_BOOL_MASK) > 0;
+ r_variant = val;
+ if (r_len)
+ *r_len = 1;
+ } break;
+ case Variant::INT: {
+ buf += 1;
+ len -= 1;
+ if (r_len)
+ *r_len = 1;
+ if (encode_mode == ENCODE_8) {
+ // 8 bits.
+ ERR_FAIL_COND_V(len < 1, ERR_INVALID_DATA);
+ int8_t val = buf[0];
+ r_variant = val;
+ if (r_len)
+ (*r_len) += 1;
+ } else if (encode_mode == ENCODE_16) {
+ // 16 bits.
+ ERR_FAIL_COND_V(len < 2, ERR_INVALID_DATA);
+ int16_t val = decode_uint16(buf);
+ r_variant = val;
+ if (r_len)
+ (*r_len) += 2;
+ } else if (encode_mode == ENCODE_32) {
+ // 32 bits.
+ ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
+ int32_t val = decode_uint32(buf);
+ r_variant = val;
+ if (r_len)
+ (*r_len) += 4;
+ } else {
+ // 64 bits.
+ ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
+ int64_t val = decode_uint64(buf);
+ r_variant = val;
+ if (r_len)
+ (*r_len) += 8;
+ }
+ } break;
+ default:
+ Error err = decode_variant(r_variant, p_buffer, p_len, r_len, allow_object_decoding || network_peer->is_object_decoding_allowed());
+ if (err != OK)
+ return err;
+ }
+
+ return OK;
+}
+
void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) {
ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree.");
@@ -496,6 +728,9 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
psc->id = last_send_cache_id++;
}
+ // See if all peers have cached path (if so, call can be fast).
+ const bool has_all_peers = _send_confirm_path(p_from, from_path, psc, p_to);
+
// Create base packet, lots of hardcode because it must be tight.
int ofs = 0;
@@ -503,45 +738,125 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
#define MAKE_ROOM(m_amount) \
if (packet_cache.size() < m_amount) packet_cache.resize(m_amount);
- // Encode type.
+ // Encode meta.
+ // The meta is composed by a single byte that contains (starting from the least segnificant bit):
+ // - `NetworkCommands` in the first three bits.
+ // - `NetworkNodeIdCompression` in the next 2 bits.
+ // - `NetworkNameIdCompression` in the next 1 bit.
+ // - So we still have the last two bits free!
+ uint8_t command_type = p_set ? NETWORK_COMMAND_REMOTE_SET : NETWORK_COMMAND_REMOTE_CALL;
+ uint8_t node_id_compression = UINT8_MAX;
+ uint8_t name_id_compression = UINT8_MAX;
+
MAKE_ROOM(1);
- packet_cache.write[0] = p_set ? NETWORK_COMMAND_REMOTE_SET : NETWORK_COMMAND_REMOTE_CALL;
+ // The meta is composed along the way, so just set 0 for now.
+ packet_cache.write[0] = 0;
ofs += 1;
- // Encode ID.
- MAKE_ROOM(ofs + 4);
- encode_uint32(psc->id, &(packet_cache.write[ofs]));
- ofs += 4;
-
- // Encode function name.
- CharString name = String(p_name).utf8();
- int len = encode_cstring(name.get_data(), NULL);
- MAKE_ROOM(ofs + len);
- encode_cstring(name.get_data(), &(packet_cache.write[ofs]));
- ofs += len;
+ // Encode Node ID.
+ if (has_all_peers) {
+ // Compress the node ID only if all the target peers already know it.
+ if (psc->id >= 0 && psc->id <= 255) {
+ // We can encode the id in 1 byte
+ node_id_compression = NETWORK_NODE_ID_COMPRESSION_8;
+ MAKE_ROOM(ofs + 1);
+ packet_cache.write[ofs] = static_cast<uint8_t>(psc->id);
+ ofs += 1;
+ } else if (psc->id >= 0 && psc->id <= 65535) {
+ // We can encode the id in 2 bytes
+ node_id_compression = NETWORK_NODE_ID_COMPRESSION_16;
+ MAKE_ROOM(ofs + 2);
+ encode_uint16(static_cast<uint16_t>(psc->id), &(packet_cache.write[ofs]));
+ ofs += 2;
+ } else {
+ // Too big, let's use 4 bytes.
+ node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
+ MAKE_ROOM(ofs + 4);
+ encode_uint32(psc->id, &(packet_cache.write[ofs]));
+ ofs += 4;
+ }
+ } else {
+ // The targets doesn't know the node yet, so we need to use 32 bits int.
+ node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
+ MAKE_ROOM(ofs + 4);
+ encode_uint32(psc->id, &(packet_cache.write[ofs]));
+ ofs += 4;
+ }
if (p_set) {
+
+ // Take the rpc property ID
+ uint16_t property_id = p_from->get_node_rset_property_id(p_name);
+ if (property_id == UINT16_MAX && p_from->get_script_instance()) {
+ property_id = p_from->get_script_instance()->get_rset_property_id(p_name);
+ }
+ ERR_FAIL_COND_MSG(property_id == UINT16_MAX, "Unable to take the `property_id` for the property:" + p_name + ". this can happen only if this property is not marked as `remote`.");
+
+ if (property_id <= UINT8_MAX) {
+ // The ID fits in 1 byte
+ name_id_compression = NETWORK_NAME_ID_COMPRESSION_8;
+ MAKE_ROOM(ofs + 1);
+ packet_cache.write[ofs] = static_cast<uint8_t>(property_id);
+ ofs += 1;
+ } else {
+ // The ID is larger, let's use 2 bytes
+ name_id_compression = NETWORK_NAME_ID_COMPRESSION_16;
+ MAKE_ROOM(ofs + 2);
+ encode_uint16(property_id, &(packet_cache.write[ofs]));
+ ofs += 2;
+ }
+
// Set argument.
- Error err = encode_variant(*p_arg[0], NULL, len, allow_object_decoding || network_peer->is_object_decoding_allowed());
+ int len(0);
+ Error err = _encode_and_compress_variant(*p_arg[0], NULL, len);
ERR_FAIL_COND_MSG(err != OK, "Unable to encode RSET value. THIS IS LIKELY A BUG IN THE ENGINE!");
MAKE_ROOM(ofs + len);
- encode_variant(*p_arg[0], &(packet_cache.write[ofs]), len, allow_object_decoding || network_peer->is_object_decoding_allowed());
+ _encode_and_compress_variant(*p_arg[0], &(packet_cache.write[ofs]), len);
ofs += len;
} else {
+ // Take the rpc method ID
+ uint16_t method_id = p_from->get_node_rpc_method_id(p_name);
+ if (method_id == UINT16_MAX && p_from->get_script_instance()) {
+ method_id = p_from->get_script_instance()->get_rpc_method_id(p_name);
+ }
+ ERR_FAIL_COND_MSG(method_id == UINT16_MAX, "Unable to take the `method_id` for the function:" + p_name + ". this can happen only if this method is not marked as `remote`.");
+
+ if (method_id <= UINT8_MAX) {
+ // The ID fits in 1 byte
+ name_id_compression = NETWORK_NAME_ID_COMPRESSION_8;
+ MAKE_ROOM(ofs + 1);
+ packet_cache.write[ofs] = static_cast<uint8_t>(method_id);
+ ofs += 1;
+ } else {
+ // The ID is larger, let's use 2 bytes
+ name_id_compression = NETWORK_NAME_ID_COMPRESSION_16;
+ MAKE_ROOM(ofs + 2);
+ encode_uint16(method_id, &(packet_cache.write[ofs]));
+ ofs += 2;
+ }
+
// Call arguments.
MAKE_ROOM(ofs + 1);
packet_cache.write[ofs] = p_argcount;
ofs += 1;
for (int i = 0; i < p_argcount; i++) {
- Error err = encode_variant(*p_arg[i], NULL, len, allow_object_decoding || network_peer->is_object_decoding_allowed());
+ int len(0);
+ Error err = _encode_and_compress_variant(*p_arg[i], NULL, len);
ERR_FAIL_COND_MSG(err != OK, "Unable to encode RPC argument. THIS IS LIKELY A BUG IN THE ENGINE!");
MAKE_ROOM(ofs + len);
- encode_variant(*p_arg[i], &(packet_cache.write[ofs]), len, allow_object_decoding || network_peer->is_object_decoding_allowed());
+ _encode_and_compress_variant(*p_arg[i], &(packet_cache.write[ofs]), len);
ofs += len;
}
}
+ ERR_FAIL_COND(command_type > 7);
+ ERR_FAIL_COND(node_id_compression > 3);
+ ERR_FAIL_COND(name_id_compression > 1);
+
+ // We can now set the meta
+ packet_cache.write[0] = command_type + (node_id_compression << 3) + (name_id_compression << 5);
+
#ifdef DEBUG_ENABLED
if (profiling) {
bandwidth_outgoing_data.write[bandwidth_outgoing_pointer].timestamp = OS::get_singleton()->get_ticks_msec();
@@ -550,9 +865,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
}
#endif
- // See if all peers have cached path (is so, call can be fast).
- bool has_all_peers = _send_confirm_path(from_path, psc, p_to);
-
// Take chance and set transfer mode, since all send methods will use it.
network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
@@ -562,6 +874,9 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
network_peer->set_target_peer(p_to); // To all of you.
network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
} else {
+ // Unreachable because the node ID is never compressed if the peers doesn't know it.
+ CRASH_COND(node_id_compression != NETWORK_NODE_ID_COMPRESSION_32);
+
// Not all verified path, so send one by one.
// Append path at the end, since we will need it for some packets.
@@ -647,16 +962,14 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
// Check that send mode can use local call.
- const Map<StringName, RPCMode>::Element *E = p_node->get_node_rpc_mode(p_method);
- if (E) {
- call_local_native = _should_call_local(E->get(), is_master, skip_rpc);
- }
+ RPCMode rpc_mode = p_node->get_node_rpc_mode(p_method);
+ call_local_native = _should_call_local(rpc_mode, is_master, skip_rpc);
if (call_local_native) {
// Done below.
} else if (p_node->get_script_instance()) {
// Attempt with script.
- RPCMode rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_method);
+ rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_method);
call_local_script = _should_call_local(rpc_mode, is_master, skip_rpc);
}
}
@@ -719,11 +1032,8 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
// Check that send mode can use local call.
- const Map<StringName, RPCMode>::Element *E = p_node->get_node_rset_mode(p_property);
- if (E) {
-
- set_local = _should_call_local(E->get(), is_master, skip_rset);
- }
+ RPCMode rpc_mode = p_node->get_node_rset_mode(p_property);
+ set_local = _should_call_local(rpc_mode, is_master, skip_rset);
if (set_local) {
bool valid;
@@ -740,7 +1050,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
} else if (p_node->get_script_instance()) {
// Attempt with script.
- RPCMode rpc_mode = p_node->get_script_instance()->get_rset_mode(p_property);
+ rpc_mode = p_node->get_script_instance()->get_rset_mode(p_property);
set_local = _should_call_local(rpc_mode, is_master, skip_rset);
diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h
index c9f127b6b2..6672cfe155 100644
--- a/core/io/multiplayer_api.h
+++ b/core/io/multiplayer_api.h
@@ -98,23 +98,37 @@ protected:
void _process_packet(int p_from, const uint8_t *p_packet, int p_packet_len);
void _process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len);
void _process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len);
- Node *_process_get_node(int p_from, const uint8_t *p_packet, int p_packet_len);
- void _process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset);
- void _process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset);
+ Node *_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len);
+ void _process_rpc(Node *p_node, const uint16_t p_rpc_method_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset);
+ void _process_rset(Node *p_node, const uint16_t p_rpc_property_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset);
void _process_raw(int p_from, const uint8_t *p_packet, int p_packet_len);
void _send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount);
- bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_target);
+ bool _send_confirm_path(Node *p_node, NodePath p_path, PathSentCache *psc, int p_target);
+
+ Error _encode_and_compress_variant(const Variant &p_variant, uint8_t *p_buffer, int &r_len);
+ Error _decode_and_decompress_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len);
public:
enum NetworkCommands {
- NETWORK_COMMAND_REMOTE_CALL,
+ NETWORK_COMMAND_REMOTE_CALL = 0,
NETWORK_COMMAND_REMOTE_SET,
NETWORK_COMMAND_SIMPLIFY_PATH,
NETWORK_COMMAND_CONFIRM_PATH,
NETWORK_COMMAND_RAW,
};
+ enum NetworkNodeIdCompression {
+ NETWORK_NODE_ID_COMPRESSION_8 = 0,
+ NETWORK_NODE_ID_COMPRESSION_16,
+ NETWORK_NODE_ID_COMPRESSION_32,
+ };
+
+ enum NetworkNameIdCompression {
+ NETWORK_NAME_ID_COMPRESSION_8 = 0,
+ NETWORK_NAME_ID_COMPRESSION_16,
+ };
+
enum RPCMode {
RPC_MODE_DISABLED, // No rpc for this method, calls to this will be blocked (default)
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 7325532b6f..3899147c9e 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -836,15 +836,20 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
uint8_t header[4];
f->get_buffer(header, 4);
if (header[0] == 'R' && header[1] == 'S' && header[2] == 'C' && header[3] == 'C') {
- //compressed
+ // Compressed.
FileAccessCompressed *fac = memnew(FileAccessCompressed);
- fac->open_after_magic(f);
+ error = fac->open_after_magic(f);
+ if (error != OK) {
+ memdelete(fac);
+ f->close();
+ ERR_FAIL_MSG("Failed to open binary resource file: " + local_path + ".");
+ }
f = fac;
} else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
- //not normal
-
+ // Not normal.
error = ERR_FILE_UNRECOGNIZED;
+ f->close();
ERR_FAIL_MSG("Unrecognized binary resource file: " + local_path + ".");
}
@@ -919,6 +924,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
if (f->eof_reached()) {
error = ERR_FILE_CORRUPT;
+ f->close();
ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + ".");
}
}
@@ -931,14 +937,20 @@ String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) {
uint8_t header[4];
f->get_buffer(header, 4);
if (header[0] == 'R' && header[1] == 'S' && header[2] == 'C' && header[3] == 'C') {
- //compressed
+ // Compressed.
FileAccessCompressed *fac = memnew(FileAccessCompressed);
- fac->open_after_magic(f);
+ error = fac->open_after_magic(f);
+ if (error != OK) {
+ memdelete(fac);
+ f->close();
+ return "";
+ }
f = fac;
} else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
- //not normal
+ // Not normal.
error = ERR_FILE_UNRECOGNIZED;
+ f->close();
return "";
}
@@ -1055,14 +1067,19 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
uint8_t header[4];
f->get_buffer(header, 4);
if (header[0] == 'R' && header[1] == 'S' && header[2] == 'C' && header[3] == 'C') {
- //compressed
+ // Compressed.
FileAccessCompressed *fac = memnew(FileAccessCompressed);
- fac->open_after_magic(f);
+ Error err = fac->open_after_magic(f);
+ if (err != OK) {
+ memdelete(fac);
+ memdelete(f);
+ ERR_FAIL_V_MSG(err, "Cannot open file '" + p_path + "'.");
+ }
f = fac;
FileAccessCompressed *facw = memnew(FileAccessCompressed);
facw->configure("RSCC");
- Error err = facw->_open(p_path + ".depren", FileAccess::WRITE);
+ err = facw->_open(p_path + ".depren", FileAccess::WRITE);
if (err) {
memdelete(fac);
memdelete(facw);
@@ -1072,9 +1089,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
fw = facw;
} else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
- //not normal
-
- //error=ERR_FILE_UNRECOGNIZED;
+ // Not normal.
memdelete(f);
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unrecognized binary resource file '" + local_path + "'.");
} else {
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 7392e7a0af..1149feac38 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -32,6 +32,7 @@
#include "core/core_string_names.h"
#include "core/project_settings.h"
+#include <stdint.h>
ScriptLanguage *ScriptServer::_languages[MAX_LANGUAGES];
int ScriptServer::_language_count = 0;
@@ -644,6 +645,14 @@ Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_nam
return Variant();
}
+uint16_t PlaceHolderScriptInstance::get_rpc_method_id(const StringName &p_method) const {
+ return UINT16_MAX;
+}
+
+uint16_t PlaceHolderScriptInstance::get_rset_property_id(const StringName &p_method) const {
+ return UINT16_MAX;
+}
+
PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner) :
owner(p_owner),
language(p_language),
diff --git a/core/script_language.h b/core/script_language.h
index 22f83080bc..788f5d6976 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -40,6 +40,21 @@ class ScriptLanguage;
typedef void (*ScriptEditRequestFunction)(const String &p_path);
+struct ScriptNetData {
+ StringName name;
+ MultiplayerAPI::RPCMode mode;
+ bool operator==(ScriptNetData const &p_other) const {
+ return name == p_other.name;
+ }
+};
+
+struct SortNetData {
+ StringName::AlphCompare compare;
+ bool operator()(const ScriptNetData &p_a, const ScriptNetData &p_b) const {
+ return compare(p_a.name, p_b.name);
+ }
+};
+
class ScriptServer {
enum {
@@ -154,6 +169,18 @@ public:
virtual bool is_placeholder_fallback_enabled() const { return false; }
+ virtual Vector<ScriptNetData> get_rpc_methods() const = 0;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const = 0;
+ virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const = 0;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const = 0;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const = 0;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const = 0;
+ virtual uint16_t get_rset_property_id(const StringName &p_property) const = 0;
+ virtual StringName get_rset_property(const uint16_t p_rset_property_id) const = 0;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const = 0;
+ virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const = 0;
+
Script() {}
};
@@ -195,7 +222,16 @@ public:
virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid);
virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid);
+ virtual Vector<ScriptNetData> get_rpc_methods() const = 0;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const = 0;
+ virtual StringName get_rpc_method(uint16_t p_id) const = 0;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(uint16_t p_id) const = 0;
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const = 0;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const = 0;
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const = 0;
+ virtual StringName get_rset_property(uint16_t p_id) const = 0;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(uint16_t p_id) const = 0;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const = 0;
virtual ScriptLanguage *get_language() = 0;
@@ -409,7 +445,16 @@ public:
virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid = NULL);
virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid = NULL);
+ virtual Vector<ScriptNetData> get_rpc_methods() const { return Vector<ScriptNetData>(); }
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(uint16_t p_id) const { return StringName(); }
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(uint16_t p_id) const { return MultiplayerAPI::RPC_MODE_DISABLED; }
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const { return MultiplayerAPI::RPC_MODE_DISABLED; }
+
+ virtual Vector<ScriptNetData> get_rset_properties() const { return Vector<ScriptNetData>(); }
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const;
+ virtual StringName get_rset_property(uint16_t p_id) const { return StringName(); }
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(uint16_t p_id) const { return MultiplayerAPI::RPC_MODE_DISABLED; }
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const { return MultiplayerAPI::RPC_MODE_DISABLED; }
PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner);
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 6b5b947185..f088705cdd 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -488,7 +488,6 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Color, to_argb64);
VCALL_LOCALMEM0R(Color, to_abgr64);
VCALL_LOCALMEM0R(Color, to_rgba64);
- VCALL_LOCALMEM0R(Color, gray);
VCALL_LOCALMEM0R(Color, inverted);
VCALL_LOCALMEM0R(Color, contrasted);
VCALL_LOCALMEM2R(Color, linear_interpolate);
@@ -1737,7 +1736,6 @@ void register_variant_methods() {
ADDFUNC0R(COLOR, INT, Color, to_argb64, varray());
ADDFUNC0R(COLOR, INT, Color, to_abgr64, varray());
ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray());
- ADDFUNC0R(COLOR, REAL, Color, gray, varray());
ADDFUNC0R(COLOR, COLOR, Color, inverted, varray());
ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray());
ADDFUNC2R(COLOR, COLOR, Color, linear_interpolate, COLOR, "b", REAL, "t", varray());
diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml
index 7c863a3563..439937e4f5 100644
--- a/doc/classes/@GlobalScope.xml
+++ b/doc/classes/@GlobalScope.xml
@@ -53,8 +53,14 @@
<member name="Marshalls" type="Reference" setter="" getter="">
The [Marshalls] singleton.
</member>
- <member name="NavigationMeshGenerator" type="EditorNavigationMeshGenerator" setter="" getter="">
- The [EditorNavigationMeshGenerator] singleton.
+ <member name="Navigation2DServer" type="Navigation2DServer" setter="" getter="">
+ The [Navigation2DServer] singleton.
+ </member>
+ <member name="NavigationMeshGenerator" type="NavigationMeshGenerator" setter="" getter="">
+ The [NavigationMeshGenerator] singleton.
+ </member>
+ <member name="NavigationServer" type="NavigationServer" setter="" getter="">
+ The [NavigationServer] singleton.
</member>
<member name="OS" type="OS" setter="" getter="">
The [OS] singleton.
@@ -1367,7 +1373,7 @@
Hints that a string property is an absolute path to a directory outside the project folder. Editing it will show a file dialog for picking the path.
</constant>
<constant name="PROPERTY_HINT_RESOURCE_TYPE" value="17" enum="PropertyHint">
- Hints that a property is an instance of a [Resource]-derived type, optionally specified via the hint string (e.g. [code]"Texture"[/code]). Editing it will show a popup menu of valid resource types to instantiate.
+ Hints that a property is an instance of a [Resource]-derived type, optionally specified via the hint string (e.g. [code]"Texture2D"[/code]). Editing it will show a popup menu of valid resource types to instantiate.
</constant>
<constant name="PROPERTY_HINT_MULTILINE_TEXT" value="18" enum="PropertyHint">
Hints that a string property is text with line breaks. Editing it will show a text input field where line breaks can be typed.
diff --git a/doc/classes/AnimatedSprite.xml b/doc/classes/AnimatedSprite.xml
index ff56067cda..3caad10f6d 100644
--- a/doc/classes/AnimatedSprite.xml
+++ b/doc/classes/AnimatedSprite.xml
@@ -60,6 +60,10 @@
<member name="playing" type="bool" setter="_set_playing" getter="_is_playing" default="false">
If [code]true[/code], the [member animation] is currently playing.
</member>
+ <member name="shininess" type="float" setter="set_shininess" getter="get_shininess" default="1.0">
+ </member>
+ <member name="specular_color" type="Color" setter="set_specular_color" getter="get_specular_color" default="Color( 1, 1, 1, 1 )">
+ </member>
<member name="speed_scale" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0">
The animation speed is multiplied by this value.
</member>
diff --git a/doc/classes/AnimatedTexture.xml b/doc/classes/AnimatedTexture.xml
index d4c25049d2..b851c76e59 100644
--- a/doc/classes/AnimatedTexture.xml
+++ b/doc/classes/AnimatedTexture.xml
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="AnimatedTexture" inherits="Texture" version="4.0">
+<class name="AnimatedTexture" inherits="Texture2D" version="4.0">
<brief_description>
Proxy texture for simple frame-based animations.
</brief_description>
<description>
- [AnimatedTexture] is a resource format for frame-based animations, where multiple textures can be chained automatically with a predefined delay for each frame. Unlike [AnimationPlayer] or [AnimatedSprite], it isn't a [Node], but has the advantage of being usable anywhere a [Texture] resource can be used, e.g. in a [TileSet].
+ [AnimatedTexture] is a resource format for frame-based animations, where multiple textures can be chained automatically with a predefined delay for each frame. Unlike [AnimationPlayer] or [AnimatedSprite], it isn't a [Node], but has the advantage of being usable anywhere a [Texture2D] resource can be used, e.g. in a [TileSet].
The playback of the animation is controlled by the [member fps] property as well as each frame's optional delay (see [method set_frame_delay]). The animation loops, i.e. it will restart at frame 0 automatically after playing the last frame.
[AnimatedTexture] currently requires all frame textures to have the same size, otherwise the bigger ones will be cropped to match the smallest one. Also, it doesn't support [AtlasTexture]. Each frame needs to be separate image.
</description>
@@ -21,12 +21,12 @@
</description>
</method>
<method name="get_frame_texture" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="frame" type="int">
</argument>
<description>
- Returns the given frame's [Texture].
+ Returns the given frame's [Texture2D].
</description>
</method>
<method name="set_frame_delay">
@@ -52,16 +52,15 @@
</return>
<argument index="0" name="frame" type="int">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
- Assigns a [Texture] to the given frame. Frame IDs start at 0, so the first frame has ID 0, and the last frame of the animation has ID [member frames] - 1.
+ Assigns a [Texture2D] to the given frame. Frame IDs start at 0, so the first frame has ID 0, and the last frame of the animation has ID [member frames] - 1.
You can define any number of textures up to [constant MAX_FRAMES], but keep in mind that only frames from 0 to [member frames] - 1 will be part of the animation.
</description>
</method>
</methods>
<members>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="0" />
<member name="fps" type="float" setter="set_fps" getter="get_fps" default="4.0">
Animation speed in frames per second. This value defines the default time interval between two frames of the animation, and thus the overall duration of the animation loop based on the [member frames] property. A value of 0 means no predefined number of frames per second, the animation will play according to each frame's frame delay (see [method set_frame_delay]).
For example, an animation with 8 frames, no frame delay and a [code]fps[/code] value of 2 will run for 4 seconds, with each frame lasting 0.5 seconds.
diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml
index c3d9216657..f77dfdc9a1 100644
--- a/doc/classes/Animation.xml
+++ b/doc/classes/Animation.xml
@@ -14,7 +14,7 @@
animation.track_insert_key(track_index, 0.0, 0)
animation.track_insert_key(track_index, 0.5, 100)
[/codeblock]
- Animations are just data containers, and must be added to nodes such as an [AnimationPlayer] or [AnimationTreePlayer] to be played back.
+ Animations are just data containers, and must be added to nodes such as an [AnimationPlayer] to be played back.
</description>
<tutorials>
<link>https://docs.godotengine.org/en/latest/tutorials/animation/index.html</link>
diff --git a/doc/classes/AnimationTreePlayer.xml b/doc/classes/AnimationTreePlayer.xml
deleted file mode 100644
index e09e646960..0000000000
--- a/doc/classes/AnimationTreePlayer.xml
+++ /dev/null
@@ -1,656 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="AnimationTreePlayer" inherits="Node" version="4.0">
- <brief_description>
- Animation player that uses a node graph for blending animations.
- </brief_description>
- <description>
- A node graph tool for blending multiple animations bound to an [AnimationPlayer]. Especially useful for animating characters or other skeleton-based rigs. It can combine several animations to form a desired pose.
- It takes [Animation]s from an [AnimationPlayer] node and mixes them depending on the graph.
- </description>
- <tutorials>
- <link>https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link>
- </tutorials>
- <methods>
- <method name="add_node">
- <return type="void">
- </return>
- <argument index="0" name="type" type="int" enum="AnimationTreePlayer.NodeType">
- </argument>
- <argument index="1" name="id" type="String">
- </argument>
- <description>
- Adds a [code]type[/code] node to the graph with name [code]id[/code].
- </description>
- </method>
- <method name="advance">
- <return type="void">
- </return>
- <argument index="0" name="delta" type="float">
- </argument>
- <description>
- Shifts position in the animation timeline. [code]delta[/code] is the time in seconds to shift. Events between the current frame and [code]delta[/code] are handled.
- </description>
- </method>
- <method name="animation_node_get_animation" qualifiers="const">
- <return type="Animation">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the [AnimationPlayer]'s [Animation] bound to the [AnimationTreePlayer]'s animation node with name [code]id[/code].
- </description>
- </method>
- <method name="animation_node_get_master_animation" qualifiers="const">
- <return type="String">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the name of the [member master_player]'s [Animation] bound to this animation node.
- </description>
- </method>
- <method name="animation_node_get_position" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the absolute playback timestamp of the animation node with name [code]id[/code].
- </description>
- </method>
- <method name="animation_node_set_animation">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="animation" type="Animation">
- </argument>
- <description>
- Binds a new [Animation] from the [member master_player] to the [AnimationTreePlayer]'s animation node with name [code]id[/code].
- </description>
- </method>
- <method name="animation_node_set_filter_path">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="path" type="NodePath">
- </argument>
- <argument index="2" name="enable" type="bool">
- </argument>
- <description>
- If [code]enable[/code] is [code]true[/code], the animation node with ID [code]id[/code] turns off the track modifying the property at [code]path[/code]. The modified node's children continue to animate.
- </description>
- </method>
- <method name="animation_node_set_master_animation">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="source" type="String">
- </argument>
- <description>
- Binds the [Animation] named [code]source[/code] from [member master_player] to the animation node [code]id[/code]. Recalculates caches.
- </description>
- </method>
- <method name="are_nodes_connected" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="dst_id" type="String">
- </argument>
- <argument index="2" name="dst_input_idx" type="int">
- </argument>
- <description>
- Returns whether node [code]id[/code] and [code]dst_id[/code] are connected at the specified slot.
- </description>
- </method>
- <method name="blend2_node_get_amount" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the blend amount of a Blend2 node given its name.
- </description>
- </method>
- <method name="blend2_node_set_amount">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="blend" type="float">
- </argument>
- <description>
- Sets the blend amount of a Blend2 node given its name and value.
- A Blend2 node blends two animations (A and B) with the amount between 0 and 1.
- At 0, output is input A. Towards 1, the influence of A gets lessened, the influence of B gets raised. At 1, output is input B.
- </description>
- </method>
- <method name="blend2_node_set_filter_path">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="path" type="NodePath">
- </argument>
- <argument index="2" name="enable" type="bool">
- </argument>
- <description>
- If [code]enable[/code] is [code]true[/code], the Blend2 node with name [code]id[/code] turns off the track modifying the property at [code]path[/code]. The modified node's children continue to animate.
- </description>
- </method>
- <method name="blend3_node_get_amount" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the blend amount of a Blend3 node given its name.
- </description>
- </method>
- <method name="blend3_node_set_amount">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="blend" type="float">
- </argument>
- <description>
- Sets the blend amount of a Blend3 node given its name and value.
- A Blend3 Node blends three animations (A, B-, B+) with the amount between -1 and 1.
- At -1, output is input B-. From -1 to 0, the influence of B- gets lessened, the influence of A gets raised and the influence of B+ is 0. At 0, output is input A. From 0 to 1, the influence of A gets lessened, the influence of B+ gets raised and the influence of B+ is 0. At 1, output is input B+.
- </description>
- </method>
- <method name="blend4_node_get_amount" qualifiers="const">
- <return type="Vector2">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the blend amount of a Blend4 node given its name.
- </description>
- </method>
- <method name="blend4_node_set_amount">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="blend" type="Vector2">
- </argument>
- <description>
- Sets the blend amount of a Blend4 node given its name and value.
- A Blend4 Node blends two pairs of animations.
- The two pairs are blended like Blend2 and then added together.
- </description>
- </method>
- <method name="connect_nodes">
- <return type="int" enum="Error">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="dst_id" type="String">
- </argument>
- <argument index="2" name="dst_input_idx" type="int">
- </argument>
- <description>
- Connects node [code]id[/code] to [code]dst_id[/code] at the specified input slot.
- </description>
- </method>
- <method name="disconnect_nodes">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="dst_input_idx" type="int">
- </argument>
- <description>
- Disconnects nodes connected to [code]id[/code] at the specified input slot.
- </description>
- </method>
- <method name="get_node_list">
- <return type="PoolStringArray">
- </return>
- <description>
- Returns a [PoolStringArray] containing the name of all nodes.
- </description>
- </method>
- <method name="mix_node_get_amount" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the mix amount of a Mix node given its name.
- </description>
- </method>
- <method name="mix_node_set_amount">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="ratio" type="float">
- </argument>
- <description>
- Sets the mix amount of a Mix node given its name and value.
- A Mix node adds input b to input a by the amount given by ratio.
- </description>
- </method>
- <method name="node_exists" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="node" type="String">
- </argument>
- <description>
- Check if a node exists (by name).
- </description>
- </method>
- <method name="node_get_input_count" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the input count for a given node. Different types of nodes have different amount of inputs.
- </description>
- </method>
- <method name="node_get_input_source" qualifiers="const">
- <return type="String">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="idx" type="int">
- </argument>
- <description>
- Returns the input source for a given node input.
- </description>
- </method>
- <method name="node_get_position" qualifiers="const">
- <return type="Vector2">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns position of a node in the graph given its name.
- </description>
- </method>
- <method name="node_get_type" qualifiers="const">
- <return type="int" enum="AnimationTreePlayer.NodeType">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Gets the node type, will return from [enum NodeType] enum.
- </description>
- </method>
- <method name="node_rename">
- <return type="int" enum="Error">
- </return>
- <argument index="0" name="node" type="String">
- </argument>
- <argument index="1" name="new_name" type="String">
- </argument>
- <description>
- Renames a node in the graph.
- </description>
- </method>
- <method name="node_set_position">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="screen_position" type="Vector2">
- </argument>
- <description>
- Sets the position of a node in the graph given its name and position.
- </description>
- </method>
- <method name="oneshot_node_get_autorestart_delay" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the autostart delay of a OneShot node given its name.
- </description>
- </method>
- <method name="oneshot_node_get_autorestart_random_delay" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the autostart random delay of a OneShot node given its name.
- </description>
- </method>
- <method name="oneshot_node_get_fadein_time" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the fade in time of a OneShot node given its name.
- </description>
- </method>
- <method name="oneshot_node_get_fadeout_time" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the fade out time of a OneShot node given its name.
- </description>
- </method>
- <method name="oneshot_node_has_autorestart" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns whether a OneShot node will auto restart given its name.
- </description>
- </method>
- <method name="oneshot_node_is_active" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns whether a OneShot node is active given its name.
- </description>
- </method>
- <method name="oneshot_node_set_autorestart">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
- <description>
- Sets the autorestart property of a OneShot node given its name and value.
- </description>
- </method>
- <method name="oneshot_node_set_autorestart_delay">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="delay_sec" type="float">
- </argument>
- <description>
- Sets the autorestart delay of a OneShot node given its name and value in seconds.
- </description>
- </method>
- <method name="oneshot_node_set_autorestart_random_delay">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="rand_sec" type="float">
- </argument>
- <description>
- Sets the autorestart random delay of a OneShot node given its name and value in seconds.
- </description>
- </method>
- <method name="oneshot_node_set_fadein_time">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="time_sec" type="float">
- </argument>
- <description>
- Sets the fade in time of a OneShot node given its name and value in seconds.
- </description>
- </method>
- <method name="oneshot_node_set_fadeout_time">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="time_sec" type="float">
- </argument>
- <description>
- Sets the fade out time of a OneShot node given its name and value in seconds.
- </description>
- </method>
- <method name="oneshot_node_set_filter_path">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="path" type="NodePath">
- </argument>
- <argument index="2" name="enable" type="bool">
- </argument>
- <description>
- If [code]enable[/code] is [code]true[/code], the OneShot node with ID [code]id[/code] turns off the track modifying the property at [code]path[/code]. The modified node's children continue to animate.
- </description>
- </method>
- <method name="oneshot_node_start">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Starts a OneShot node given its name.
- </description>
- </method>
- <method name="oneshot_node_stop">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Stops the OneShot node with name [code]id[/code].
- </description>
- </method>
- <method name="recompute_caches">
- <return type="void">
- </return>
- <description>
- Manually recalculates the cache of track information generated from animation nodes. Needed when external sources modify the animation nodes' state.
- </description>
- </method>
- <method name="remove_node">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Removes the animation node with name [code]id[/code].
- </description>
- </method>
- <method name="reset">
- <return type="void">
- </return>
- <description>
- Resets this [AnimationTreePlayer].
- </description>
- </method>
- <method name="timescale_node_get_scale" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the time scale value of the TimeScale node with name [code]id[/code].
- </description>
- </method>
- <method name="timescale_node_set_scale">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="scale" type="float">
- </argument>
- <description>
- Sets the time scale of the TimeScale node with name [code]id[/code] to [code]scale[/code].
- The TimeScale node is used to speed [Animation]s up if the scale is above 1 or slow them down if it is below 1.
- If applied after a blend or mix, affects all input animations to that blend or mix.
- </description>
- </method>
- <method name="timeseek_node_seek">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="seconds" type="float">
- </argument>
- <description>
- Sets the time seek value of the TimeSeek node with name [code]id[/code] to [code]seconds[/code].
- This functions as a seek in the [Animation] or the blend or mix of [Animation]s input in it.
- </description>
- </method>
- <method name="transition_node_delete_input">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="input_idx" type="int">
- </argument>
- <description>
- Deletes the input at [code]input_idx[/code] for the transition node with name [code]id[/code].
- </description>
- </method>
- <method name="transition_node_get_current" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the index of the currently evaluated input for the transition node with name [code]id[/code].
- </description>
- </method>
- <method name="transition_node_get_input_count" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the number of inputs for the transition node with name [code]id[/code]. You can add inputs by right-clicking on the transition node.
- </description>
- </method>
- <method name="transition_node_get_xfade_time" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <description>
- Returns the cross fade time for the transition node with name [code]id[/code].
- </description>
- </method>
- <method name="transition_node_has_input_auto_advance" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="input_idx" type="int">
- </argument>
- <description>
- Returns [code]true[/code] if the input at [code]input_idx[/code] on the transition node with name [code]id[/code] is set to automatically advance to the next input upon completion.
- </description>
- </method>
- <method name="transition_node_set_current">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="input_idx" type="int">
- </argument>
- <description>
- The transition node with name [code]id[/code] sets its current input at [code]input_idx[/code].
- </description>
- </method>
- <method name="transition_node_set_input_auto_advance">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="input_idx" type="int">
- </argument>
- <argument index="2" name="enable" type="bool">
- </argument>
- <description>
- The transition node with name [code]id[/code] advances to its next input automatically when the input at [code]input_idx[/code] completes.
- </description>
- </method>
- <method name="transition_node_set_input_count">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="count" type="int">
- </argument>
- <description>
- Resizes the number of inputs available for the transition node with name [code]id[/code].
- </description>
- </method>
- <method name="transition_node_set_xfade_time">
- <return type="void">
- </return>
- <argument index="0" name="id" type="String">
- </argument>
- <argument index="1" name="time_sec" type="float">
- </argument>
- <description>
- The transition node with name [code]id[/code] sets its cross fade time to [code]time_sec[/code].
- </description>
- </method>
- </methods>
- <members>
- <member name="active" type="bool" setter="set_active" getter="is_active" default="false">
- If [code]true[/code], the [AnimationTreePlayer] is able to play animations.
- </member>
- <member name="base_path" type="NodePath" setter="set_base_path" getter="get_base_path" default="NodePath(&quot;..&quot;)">
- The node from which to relatively access other nodes.
- It accesses the bones, so it should point to the same node the [AnimationPlayer] would point its Root Node at.
- </member>
- <member name="master_player" type="NodePath" setter="set_master_player" getter="get_master_player" default="NodePath(&quot;&quot;)">
- The path to the [AnimationPlayer] from which this [AnimationTreePlayer] binds animations to animation nodes.
- Once set, [Animation] nodes can be added to the [AnimationTreePlayer].
- </member>
- <member name="playback_process_mode" type="int" setter="set_animation_process_mode" getter="get_animation_process_mode" enum="AnimationTreePlayer.AnimationProcessMode" default="1">
- The thread in which to update animations.
- </member>
- </members>
- <constants>
- <constant name="NODE_OUTPUT" value="0" enum="NodeType">
- Output node.
- </constant>
- <constant name="NODE_ANIMATION" value="1" enum="NodeType">
- Animation node.
- </constant>
- <constant name="NODE_ONESHOT" value="2" enum="NodeType">
- OneShot node.
- </constant>
- <constant name="NODE_MIX" value="3" enum="NodeType">
- Mix node.
- </constant>
- <constant name="NODE_BLEND2" value="4" enum="NodeType">
- Blend2 node.
- </constant>
- <constant name="NODE_BLEND3" value="5" enum="NodeType">
- Blend3 node.
- </constant>
- <constant name="NODE_BLEND4" value="6" enum="NodeType">
- Blend4 node.
- </constant>
- <constant name="NODE_TIMESCALE" value="7" enum="NodeType">
- TimeScale node.
- </constant>
- <constant name="NODE_TIMESEEK" value="8" enum="NodeType">
- TimeSeek node.
- </constant>
- <constant name="NODE_TRANSITION" value="9" enum="NodeType">
- Transition node.
- </constant>
- <constant name="ANIMATION_PROCESS_PHYSICS" value="0" enum="AnimationProcessMode">
- Process animation during the physics process. This is especially useful when animating physics bodies.
- </constant>
- <constant name="ANIMATION_PROCESS_IDLE" value="1" enum="AnimationProcessMode">
- Process animation during the idle process.
- </constant>
- </constants>
-</class>
diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml
index 821c6db717..2dbf55e522 100644
--- a/doc/classes/ArrayMesh.xml
+++ b/doc/classes/ArrayMesh.xml
@@ -45,7 +45,11 @@
</argument>
<argument index="2" name="blend_shapes" type="Array" default="[ ]">
</argument>
- <argument index="3" name="compress_flags" type="int" default="97280">
+ <argument index="3" name="lods" type="Dictionary" default="{
+
+}">
+ </argument>
+ <argument index="4" name="compress_flags" type="int" default="31744">
</argument>
<description>
Creates a new surface.
@@ -62,6 +66,12 @@
Removes all blend shapes from this [ArrayMesh].
</description>
</method>
+ <method name="clear_surfaces">
+ <return type="void">
+ </return>
+ <description>
+ </description>
+ </method>
<method name="get_blend_shape_count" qualifiers="const">
<return type="int">
</return>
@@ -150,15 +160,6 @@
Returns the primitive type of the requested surface (see [method add_surface_from_arrays]).
</description>
</method>
- <method name="surface_remove">
- <return type="void">
- </return>
- <argument index="0" name="surf_idx" type="int">
- </argument>
- <description>
- Removes a surface at position [code]surf_idx[/code], shifting greater surfaces one [code]surf_idx[/code] slot down.
- </description>
- </method>
<method name="surface_set_name">
<return type="void">
</return>
diff --git a/doc/classes/AtlasTexture.xml b/doc/classes/AtlasTexture.xml
index 7150490371..5bc077ef49 100644
--- a/doc/classes/AtlasTexture.xml
+++ b/doc/classes/AtlasTexture.xml
@@ -1,23 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="AtlasTexture" inherits="Texture" version="4.0">
+<class name="AtlasTexture" inherits="Texture2D" version="4.0">
<brief_description>
Packs multiple small textures in a single, bigger one. Helps to optimize video memory costs and render calls.
</brief_description>
<description>
- [Texture] resource aimed at managing big textures files that pack multiple smaller textures. Consists of a [Texture], a margin that defines the border width, and a region that defines the actual area of the AtlasTexture.
+ [Texture2D] resource aimed at managing big textures files that pack multiple smaller textures. Consists of a [Texture2D], a margin that defines the border width, and a region that defines the actual area of the AtlasTexture.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
- <member name="atlas" type="Texture" setter="set_atlas" getter="get_atlas">
- The texture that contains the atlas. Can be any [Texture] subtype.
+ <member name="atlas" type="Texture2D" setter="set_atlas" getter="get_atlas">
+ The texture that contains the atlas. Can be any [Texture2D] subtype.
</member>
<member name="filter_clip" type="bool" setter="set_filter_clip" getter="has_filter_clip" default="false">
If [code]true[/code], clips the area outside of the region to avoid bleeding of the surrounding texture pixels.
</member>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="0" />
<member name="margin" type="Rect2" setter="set_margin" getter="get_margin" default="Rect2( 0, 0, 0, 0 )">
The margin around the region. The [Rect2]'s [member Rect2.size] parameter ("w" and "h" in the editor) resizes the texture so it fits within the margin.
</member>
diff --git a/doc/classes/BakedLightmap.xml b/doc/classes/BakedLightmap.xml
deleted file mode 100644
index 587ff7f304..0000000000
--- a/doc/classes/BakedLightmap.xml
+++ /dev/null
@@ -1,99 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="BakedLightmap" inherits="VisualInstance" version="4.0">
- <brief_description>
- Prerendered indirect light map for a scene.
- </brief_description>
- <description>
- Baked lightmaps are an alternative workflow for adding indirect (or baked) lighting to a scene. Unlike the [GIProbe] approach, baked lightmaps work fine on low-end PCs and mobile devices as they consume almost no resources in run-time.
- </description>
- <tutorials>
- <link>https://docs.godotengine.org/en/latest/tutorials/3d/baked_lightmaps.html</link>
- </tutorials>
- <methods>
- <method name="bake">
- <return type="int" enum="BakedLightmap.BakeError">
- </return>
- <argument index="0" name="from_node" type="Node" default="null">
- </argument>
- <argument index="1" name="create_visual_debug" type="bool" default="false">
- </argument>
- <description>
- Bakes the lightmaps within the currently edited scene. Returns a [enum BakeError] to signify if the bake was successful, or if unsuccessful, how the bake failed.
- </description>
- </method>
- <method name="debug_bake">
- <return type="void">
- </return>
- <description>
- Executes a dry run bake of lightmaps within the currently edited scene.
- </description>
- </method>
- </methods>
- <members>
- <member name="bake_cell_size" type="float" setter="set_bake_cell_size" getter="get_bake_cell_size" default="0.25">
- Grid subdivision size for lightmapper calculation. The default value will work for most cases. Increase for better lighting on small details or if your scene is very large.
- </member>
- <member name="bake_default_texels_per_unit" type="float" setter="set_bake_default_texels_per_unit" getter="get_bake_default_texels_per_unit" default="20.0">
- If a [member Mesh.lightmap_size_hint] isn't specified, the lightmap baker will dynamically set the lightmap size using this value. This value is measured in texels per world unit. The maximum lightmap texture size is 4096x4096.
- </member>
- <member name="bake_energy" type="float" setter="set_energy" getter="get_energy" default="1.0">
- Multiplies the light sources' intensity by this value. For instance, if the value is set to 2, lights will be twice as bright. If the value is set to 0.5, lights will be half as bright.
- </member>
- <member name="bake_extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3( 10, 10, 10 )">
- The size of the affected area.
- </member>
- <member name="bake_hdr" type="bool" setter="set_hdr" getter="is_hdr" default="false">
- If [code]true[/code], the lightmap can capture light values greater than [code]1.0[/code]. Turning this off will result in a smaller file size.
- </member>
- <member name="bake_mode" type="int" setter="set_bake_mode" getter="get_bake_mode" enum="BakedLightmap.BakeMode" default="0">
- Lightmapping mode. See [enum BakeMode].
- </member>
- <member name="bake_propagation" type="float" setter="set_propagation" getter="get_propagation" default="1.0">
- Defines how far the light will travel before it is no longer effective. The higher the number, the farther the light will travel. For instance, if the value is set to 2, the light will go twice as far. If the value is set to 0.5, the light will only go half as far.
- </member>
- <member name="bake_quality" type="int" setter="set_bake_quality" getter="get_bake_quality" enum="BakedLightmap.BakeQuality" default="1">
- Three quality modes are available. Higher quality requires more rendering time. See [enum BakeQuality].
- </member>
- <member name="capture_cell_size" type="float" setter="set_capture_cell_size" getter="get_capture_cell_size" default="0.5">
- Grid size used for real-time capture information on dynamic objects. Cannot be larger than [member bake_cell_size].
- </member>
- <member name="image_path" type="String" setter="set_image_path" getter="get_image_path" default="&quot;.&quot;">
- The location where lightmaps will be saved.
- </member>
- <member name="light_data" type="BakedLightmapData" setter="set_light_data" getter="get_light_data">
- The calculated light data.
- </member>
- </members>
- <constants>
- <constant name="BAKE_QUALITY_LOW" value="0" enum="BakeQuality">
- The lowest bake quality mode. Fastest to calculate.
- </constant>
- <constant name="BAKE_QUALITY_MEDIUM" value="1" enum="BakeQuality">
- The default bake quality mode.
- </constant>
- <constant name="BAKE_QUALITY_HIGH" value="2" enum="BakeQuality">
- The highest bake quality mode. Takes longer to calculate.
- </constant>
- <constant name="BAKE_MODE_CONE_TRACE" value="0" enum="BakeMode">
- Less precise but faster bake mode.
- </constant>
- <constant name="BAKE_MODE_RAY_TRACE" value="1" enum="BakeMode">
- More precise bake mode but can take considerably longer to bake.
- </constant>
- <constant name="BAKE_ERROR_OK" value="0" enum="BakeError">
- Baking was successful.
- </constant>
- <constant name="BAKE_ERROR_NO_SAVE_PATH" value="1" enum="BakeError">
- Returns if no viable save path is found. This can happen where an [member image_path] is not specified or when the save location is invalid.
- </constant>
- <constant name="BAKE_ERROR_NO_MESHES" value="2" enum="BakeError">
- Currently unused.
- </constant>
- <constant name="BAKE_ERROR_CANT_CREATE_IMAGE" value="3" enum="BakeError">
- Returns when the baker cannot save per-mesh textures to file.
- </constant>
- <constant name="BAKE_ERROR_USER_ABORTED" value="4" enum="BakeError">
- Returns if user cancels baking.
- </constant>
- </constants>
-</class>
diff --git a/doc/classes/BakedLightmapData.xml b/doc/classes/BakedLightmapData.xml
deleted file mode 100644
index 9193fb3b68..0000000000
--- a/doc/classes/BakedLightmapData.xml
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="BakedLightmapData" inherits="Resource" version="4.0">
- <brief_description>
- </brief_description>
- <description>
- </description>
- <tutorials>
- </tutorials>
- <methods>
- <method name="add_user">
- <return type="void">
- </return>
- <argument index="0" name="path" type="NodePath">
- </argument>
- <argument index="1" name="lightmap" type="Texture">
- </argument>
- <argument index="2" name="instance" type="int">
- </argument>
- <description>
- </description>
- </method>
- <method name="clear_users">
- <return type="void">
- </return>
- <description>
- </description>
- </method>
- <method name="get_user_count" qualifiers="const">
- <return type="int">
- </return>
- <description>
- </description>
- </method>
- <method name="get_user_lightmap" qualifiers="const">
- <return type="Texture">
- </return>
- <argument index="0" name="user_idx" type="int">
- </argument>
- <description>
- </description>
- </method>
- <method name="get_user_path" qualifiers="const">
- <return type="NodePath">
- </return>
- <argument index="0" name="user_idx" type="int">
- </argument>
- <description>
- </description>
- </method>
- </methods>
- <members>
- <member name="bounds" type="AABB" setter="set_bounds" getter="get_bounds" default="AABB( 0, 0, 0, 0, 0, 0 )">
- </member>
- <member name="cell_space_transform" type="Transform" setter="set_cell_space_transform" getter="get_cell_space_transform" default="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )">
- </member>
- <member name="cell_subdiv" type="int" setter="set_cell_subdiv" getter="get_cell_subdiv" default="1">
- </member>
- <member name="energy" type="float" setter="set_energy" getter="get_energy" default="1.0">
- </member>
- <member name="octree" type="PoolByteArray" setter="set_octree" getter="get_octree" default="PoolByteArray( )">
- </member>
- </members>
- <constants>
- </constants>
-</class>
diff --git a/doc/classes/BaseMaterial3D.xml b/doc/classes/BaseMaterial3D.xml
new file mode 100644
index 0000000000..740a388149
--- /dev/null
+++ b/doc/classes/BaseMaterial3D.xml
@@ -0,0 +1,477 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="BaseMaterial3D" inherits="Material" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ <method name="get_feature" qualifiers="const">
+ <return type="bool">
+ </return>
+ <argument index="0" name="feature" type="int" enum="BaseMaterial3D.Feature">
+ </argument>
+ <description>
+ </description>
+ </method>
+ <method name="get_flag" qualifiers="const">
+ <return type="bool">
+ </return>
+ <argument index="0" name="flag" type="int" enum="BaseMaterial3D.Flags">
+ </argument>
+ <description>
+ </description>
+ </method>
+ <method name="get_texture" qualifiers="const">
+ <return type="Texture2D">
+ </return>
+ <argument index="0" name="param" type="int" enum="BaseMaterial3D.TextureParam">
+ </argument>
+ <description>
+ </description>
+ </method>
+ <method name="set_feature">
+ <return type="void">
+ </return>
+ <argument index="0" name="feature" type="int" enum="BaseMaterial3D.Feature">
+ </argument>
+ <argument index="1" name="enable" type="bool">
+ </argument>
+ <description>
+ </description>
+ </method>
+ <method name="set_flag">
+ <return type="void">
+ </return>
+ <argument index="0" name="flag" type="int" enum="BaseMaterial3D.Flags">
+ </argument>
+ <argument index="1" name="enable" type="bool">
+ </argument>
+ <description>
+ </description>
+ </method>
+ <method name="set_texture">
+ <return type="void">
+ </return>
+ <argument index="0" name="param" type="int" enum="BaseMaterial3D.TextureParam">
+ </argument>
+ <argument index="1" name="texture" type="Texture2D">
+ </argument>
+ <description>
+ </description>
+ </method>
+ </methods>
+ <members>
+ <member name="albedo_color" type="Color" setter="set_albedo" getter="get_albedo" default="Color( 1, 1, 1, 1 )">
+ </member>
+ <member name="albedo_tex_force_srgb" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="albedo_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="alpha_scissor_threshold" type="float" setter="set_alpha_scissor_threshold" getter="get_alpha_scissor_threshold">
+ </member>
+ <member name="anisotropy" type="float" setter="set_anisotropy" getter="get_anisotropy">
+ </member>
+ <member name="anisotropy_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="anisotropy_flowmap" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="ao_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="ao_light_affect" type="float" setter="set_ao_light_affect" getter="get_ao_light_affect">
+ </member>
+ <member name="ao_on_uv2" type="bool" setter="set_flag" getter="get_flag">
+ </member>
+ <member name="ao_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="ao_texture_channel" type="int" setter="set_ao_texture_channel" getter="get_ao_texture_channel" enum="BaseMaterial3D.TextureChannel">
+ </member>
+ <member name="billboard_keep_scale" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="billboard_mode" type="int" setter="set_billboard_mode" getter="get_billboard_mode" enum="BaseMaterial3D.BillboardMode" default="0">
+ </member>
+ <member name="blend_mode" type="int" setter="set_blend_mode" getter="get_blend_mode" enum="BaseMaterial3D.BlendMode" default="0">
+ </member>
+ <member name="clearcoat" type="float" setter="set_clearcoat" getter="get_clearcoat">
+ </member>
+ <member name="clearcoat_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="clearcoat_gloss" type="float" setter="set_clearcoat_gloss" getter="get_clearcoat_gloss">
+ </member>
+ <member name="clearcoat_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="cull_mode" type="int" setter="set_cull_mode" getter="get_cull_mode" enum="BaseMaterial3D.CullMode" default="0">
+ </member>
+ <member name="depth_draw" type="int" setter="set_depth_draw_mode" getter="get_depth_draw_mode" enum="BaseMaterial3D.DepthDrawMode" default="0">
+ </member>
+ <member name="detail_albedo" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="detail_blend_mode" type="int" setter="set_detail_blend_mode" getter="get_detail_blend_mode" enum="BaseMaterial3D.BlendMode">
+ </member>
+ <member name="detail_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="detail_mask" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="detail_normal" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="detail_uv_layer" type="int" setter="set_detail_uv" getter="get_detail_uv" enum="BaseMaterial3D.DetailUV">
+ </member>
+ <member name="diffuse_mode" type="int" setter="set_diffuse_mode" getter="get_diffuse_mode" enum="BaseMaterial3D.DiffuseMode" default="0">
+ </member>
+ <member name="disable_ambient_light" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="disable_receive_shadows" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="distance_fade_max_distance" type="float" setter="set_distance_fade_max_distance" getter="get_distance_fade_max_distance">
+ </member>
+ <member name="distance_fade_min_distance" type="float" setter="set_distance_fade_min_distance" getter="get_distance_fade_min_distance">
+ </member>
+ <member name="distance_fade_mode" type="int" setter="set_distance_fade" getter="get_distance_fade" enum="BaseMaterial3D.DistanceFadeMode" default="0">
+ </member>
+ <member name="emission" type="Color" setter="set_emission" getter="get_emission">
+ </member>
+ <member name="emission_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="emission_energy" type="float" setter="set_emission_energy" getter="get_emission_energy">
+ </member>
+ <member name="emission_on_uv2" type="bool" setter="set_flag" getter="get_flag">
+ </member>
+ <member name="emission_operator" type="int" setter="set_emission_operator" getter="get_emission_operator" enum="BaseMaterial3D.EmissionOperator">
+ </member>
+ <member name="emission_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="fixed_size" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="grow" type="bool" setter="set_grow_enabled" getter="is_grow_enabled" default="false">
+ </member>
+ <member name="grow_amount" type="float" setter="set_grow" getter="get_grow" default="0.0">
+ </member>
+ <member name="heightmap_deep_parallax" type="bool" setter="set_heightmap_deep_parallax" getter="is_heightmap_deep_parallax_enabled">
+ </member>
+ <member name="heightmap_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="heightmap_flip_binormal" type="bool" setter="set_heightmap_deep_parallax_flip_binormal" getter="get_heightmap_deep_parallax_flip_binormal">
+ </member>
+ <member name="heightmap_flip_tangent" type="bool" setter="set_heightmap_deep_parallax_flip_tangent" getter="get_heightmap_deep_parallax_flip_tangent">
+ </member>
+ <member name="heightmap_flip_texture" type="bool" setter="set_flag" getter="get_flag">
+ </member>
+ <member name="heightmap_max_layers" type="int" setter="set_heightmap_deep_parallax_max_layers" getter="get_heightmap_deep_parallax_max_layers">
+ </member>
+ <member name="heightmap_min_layers" type="int" setter="set_heightmap_deep_parallax_min_layers" getter="get_heightmap_deep_parallax_min_layers">
+ </member>
+ <member name="heightmap_scale" type="float" setter="set_heightmap_scale" getter="get_heightmap_scale">
+ </member>
+ <member name="heightmap_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="metallic" type="float" setter="set_metallic" getter="get_metallic" default="0.0">
+ </member>
+ <member name="metallic_specular" type="float" setter="set_specular" getter="get_specular" default="0.5">
+ </member>
+ <member name="metallic_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="metallic_texture_channel" type="int" setter="set_metallic_texture_channel" getter="get_metallic_texture_channel" enum="BaseMaterial3D.TextureChannel" default="0">
+ </member>
+ <member name="no_depth_test" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="normal_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="normal_scale" type="float" setter="set_normal_scale" getter="get_normal_scale">
+ </member>
+ <member name="normal_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="orm_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="particles_anim_h_frames" type="int" setter="set_particles_anim_h_frames" getter="get_particles_anim_h_frames">
+ </member>
+ <member name="particles_anim_loop" type="bool" setter="set_particles_anim_loop" getter="get_particles_anim_loop">
+ </member>
+ <member name="particles_anim_v_frames" type="int" setter="set_particles_anim_v_frames" getter="get_particles_anim_v_frames">
+ </member>
+ <member name="point_size" type="float" setter="set_point_size" getter="get_point_size" default="1.0">
+ </member>
+ <member name="proximity_fade_distance" type="float" setter="set_proximity_fade_distance" getter="get_proximity_fade_distance">
+ </member>
+ <member name="proximity_fade_enable" type="bool" setter="set_proximity_fade" getter="is_proximity_fade_enabled" default="false">
+ </member>
+ <member name="refraction_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="refraction_scale" type="float" setter="set_refraction" getter="get_refraction">
+ </member>
+ <member name="refraction_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="refraction_texture_channel" type="int" setter="set_refraction_texture_channel" getter="get_refraction_texture_channel" enum="BaseMaterial3D.TextureChannel">
+ </member>
+ <member name="rim" type="float" setter="set_rim" getter="get_rim">
+ </member>
+ <member name="rim_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="rim_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="rim_tint" type="float" setter="set_rim_tint" getter="get_rim_tint">
+ </member>
+ <member name="roughness" type="float" setter="set_roughness" getter="get_roughness" default="1.0">
+ </member>
+ <member name="roughness_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="roughness_texture_channel" type="int" setter="set_roughness_texture_channel" getter="get_roughness_texture_channel" enum="BaseMaterial3D.TextureChannel" default="0">
+ </member>
+ <member name="shading_mode" type="int" setter="set_shading_mode" getter="get_shading_mode" enum="BaseMaterial3D.ShadingMode" default="1">
+ </member>
+ <member name="shadow_to_opacity" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="specular_mode" type="int" setter="set_specular_mode" getter="get_specular_mode" enum="BaseMaterial3D.SpecularMode" default="0">
+ </member>
+ <member name="subsurf_scatter_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="subsurf_scatter_strength" type="float" setter="set_subsurface_scattering_strength" getter="get_subsurface_scattering_strength">
+ </member>
+ <member name="subsurf_scatter_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="texture_filter" type="int" setter="set_texture_filter" getter="get_texture_filter" enum="BaseMaterial3D.TextureFilter" default="3">
+ </member>
+ <member name="texture_repeat" type="bool" setter="set_flag" getter="get_flag" default="true">
+ </member>
+ <member name="transmission" type="Color" setter="set_transmission" getter="get_transmission">
+ </member>
+ <member name="transmission_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
+ </member>
+ <member name="transmission_texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ </member>
+ <member name="transparency" type="int" setter="set_transparency" getter="get_transparency" enum="BaseMaterial3D.Transparency" default="0">
+ </member>
+ <member name="use_point_size" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="uv1_offset" type="Vector3" setter="set_uv1_offset" getter="get_uv1_offset" default="Vector3( 0, 0, 0 )">
+ </member>
+ <member name="uv1_scale" type="Vector3" setter="set_uv1_scale" getter="get_uv1_scale" default="Vector3( 1, 1, 1 )">
+ </member>
+ <member name="uv1_triplanar" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="uv1_triplanar_sharpness" type="float" setter="set_uv1_triplanar_blend_sharpness" getter="get_uv1_triplanar_blend_sharpness" default="1.0">
+ </member>
+ <member name="uv1_world_triplanar" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="uv2_offset" type="Vector3" setter="set_uv2_offset" getter="get_uv2_offset" default="Vector3( 0, 0, 0 )">
+ </member>
+ <member name="uv2_scale" type="Vector3" setter="set_uv2_scale" getter="get_uv2_scale" default="Vector3( 1, 1, 1 )">
+ </member>
+ <member name="uv2_triplanar" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="uv2_triplanar_sharpness" type="float" setter="set_uv2_triplanar_blend_sharpness" getter="get_uv2_triplanar_blend_sharpness" default="1.0">
+ </member>
+ <member name="uv2_world_triplanar" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="vertex_color_is_srgb" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ <member name="vertex_color_use_as_albedo" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
+ </members>
+ <constants>
+ <constant name="TEXTURE_ALBEDO" value="0" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_METALLIC" value="1" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_ROUGHNESS" value="2" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_EMISSION" value="3" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_NORMAL" value="4" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_RIM" value="5" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_CLEARCOAT" value="6" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_FLOWMAP" value="7" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_AMBIENT_OCCLUSION" value="8" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_HEIGHTMAP" value="9" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_SUBSURFACE_SCATTERING" value="10" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_TRANSMISSION" value="11" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_REFRACTION" value="12" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_DETAIL_MASK" value="13" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_DETAIL_ALBEDO" value="14" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_DETAIL_NORMAL" value="15" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_ORM" value="16" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_MAX" value="17" enum="TextureParam">
+ </constant>
+ <constant name="TEXTURE_FILTER_NEAREST" value="0" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_LINEAR" value="1" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS" value="2" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_LINEAR_WITH_MIPMAPS" value="3" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS_ANISOTROPIC" value="4" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC" value="5" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_MAX" value="6" enum="TextureFilter">
+ </constant>
+ <constant name="DETAIL_UV_1" value="0" enum="DetailUV">
+ </constant>
+ <constant name="DETAIL_UV_2" value="1" enum="DetailUV">
+ </constant>
+ <constant name="TRANSPARENCY_DISABLED" value="0" enum="Transparency">
+ </constant>
+ <constant name="TRANSPARENCY_ALPHA" value="1" enum="Transparency">
+ </constant>
+ <constant name="TRANSPARENCY_ALPHA_SCISSOR" value="2" enum="Transparency">
+ </constant>
+ <constant name="TRANSPARENCY_ALPHA_DEPTH_PRE_PASS" value="3" enum="Transparency">
+ </constant>
+ <constant name="TRANSPARENCY_MAX" value="4" enum="Transparency">
+ </constant>
+ <constant name="SHADING_MODE_UNSHADED" value="0" enum="ShadingMode">
+ </constant>
+ <constant name="SHADING_MODE_PER_PIXEL" value="1" enum="ShadingMode">
+ </constant>
+ <constant name="SHADING_MODE_PER_VERTEX" value="2" enum="ShadingMode">
+ </constant>
+ <constant name="SHADING_MODE_MAX" value="3" enum="ShadingMode">
+ </constant>
+ <constant name="FEATURE_EMISSION" value="0" enum="Feature">
+ </constant>
+ <constant name="FEATURE_NORMAL_MAPPING" value="1" enum="Feature">
+ </constant>
+ <constant name="FEATURE_RIM" value="2" enum="Feature">
+ </constant>
+ <constant name="FEATURE_CLEARCOAT" value="3" enum="Feature">
+ </constant>
+ <constant name="FEATURE_ANISOTROPY" value="4" enum="Feature">
+ </constant>
+ <constant name="FEATURE_AMBIENT_OCCLUSION" value="5" enum="Feature">
+ </constant>
+ <constant name="FEATURE_HEIGHT_MAPPING" value="6" enum="Feature">
+ </constant>
+ <constant name="FEATURE_SUBSURACE_SCATTERING" value="7" enum="Feature">
+ </constant>
+ <constant name="FEATURE_TRANSMISSION" value="8" enum="Feature">
+ </constant>
+ <constant name="FEATURE_REFRACTION" value="9" enum="Feature">
+ </constant>
+ <constant name="FEATURE_DETAIL" value="10" enum="Feature">
+ </constant>
+ <constant name="FEATURE_MAX" value="11" enum="Feature">
+ </constant>
+ <constant name="BLEND_MODE_MIX" value="0" enum="BlendMode">
+ </constant>
+ <constant name="BLEND_MODE_ADD" value="1" enum="BlendMode">
+ </constant>
+ <constant name="BLEND_MODE_SUB" value="2" enum="BlendMode">
+ </constant>
+ <constant name="BLEND_MODE_MUL" value="3" enum="BlendMode">
+ </constant>
+ <constant name="DEPTH_DRAW_OPAQUE_ONLY" value="0" enum="DepthDrawMode">
+ </constant>
+ <constant name="DEPTH_DRAW_ALWAYS" value="1" enum="DepthDrawMode">
+ </constant>
+ <constant name="DEPTH_DRAW_DISABLED" value="2" enum="DepthDrawMode">
+ </constant>
+ <constant name="CULL_BACK" value="0" enum="CullMode">
+ </constant>
+ <constant name="CULL_FRONT" value="1" enum="CullMode">
+ </constant>
+ <constant name="CULL_DISABLED" value="2" enum="CullMode">
+ </constant>
+ <constant name="FLAG_DISABLE_DEPTH_TEST" value="0" enum="Flags">
+ </constant>
+ <constant name="FLAG_ALBEDO_FROM_VERTEX_COLOR" value="1" enum="Flags">
+ </constant>
+ <constant name="FLAG_SRGB_VERTEX_COLOR" value="2" enum="Flags">
+ </constant>
+ <constant name="FLAG_USE_POINT_SIZE" value="3" enum="Flags">
+ </constant>
+ <constant name="FLAG_FIXED_SIZE" value="4" enum="Flags">
+ </constant>
+ <constant name="FLAG_BILLBOARD_KEEP_SCALE" value="5" enum="Flags">
+ </constant>
+ <constant name="FLAG_UV1_USE_TRIPLANAR" value="6" enum="Flags">
+ </constant>
+ <constant name="FLAG_UV2_USE_TRIPLANAR" value="7" enum="Flags">
+ </constant>
+ <constant name="FLAG_UV1_USE_WORLD_TRIPLANAR" value="8" enum="Flags">
+ </constant>
+ <constant name="FLAG_UV2_USE_WORLD_TRIPLANAR" value="9" enum="Flags">
+ </constant>
+ <constant name="FLAG_AO_ON_UV2" value="10" enum="Flags">
+ </constant>
+ <constant name="FLAG_EMISSION_ON_UV2" value="11" enum="Flags">
+ </constant>
+ <constant name="FLAG_ALBEDO_TEXTURE_FORCE_SRGB" value="12" enum="Flags">
+ </constant>
+ <constant name="FLAG_DONT_RECEIVE_SHADOWS" value="13" enum="Flags">
+ </constant>
+ <constant name="FLAG_DISABLE_AMBIENT_LIGHT" value="14" enum="Flags">
+ </constant>
+ <constant name="FLAG_USE_SHADOW_TO_OPACITY" value="15" enum="Flags">
+ </constant>
+ <constant name="FLAG_USE_TEXTURE_REPEAT" value="16" enum="Flags">
+ </constant>
+ <constant name="FLAG_INVERT_HEIGHTMAP" value="17" enum="Flags">
+ </constant>
+ <constant name="FLAG_MAX" value="18" enum="Flags">
+ </constant>
+ <constant name="DIFFUSE_BURLEY" value="0" enum="DiffuseMode">
+ </constant>
+ <constant name="DIFFUSE_LAMBERT" value="1" enum="DiffuseMode">
+ </constant>
+ <constant name="DIFFUSE_LAMBERT_WRAP" value="2" enum="DiffuseMode">
+ </constant>
+ <constant name="DIFFUSE_OREN_NAYAR" value="3" enum="DiffuseMode">
+ </constant>
+ <constant name="DIFFUSE_TOON" value="4" enum="DiffuseMode">
+ </constant>
+ <constant name="SPECULAR_SCHLICK_GGX" value="0" enum="SpecularMode">
+ </constant>
+ <constant name="SPECULAR_BLINN" value="1" enum="SpecularMode">
+ </constant>
+ <constant name="SPECULAR_PHONG" value="2" enum="SpecularMode">
+ </constant>
+ <constant name="SPECULAR_TOON" value="3" enum="SpecularMode">
+ </constant>
+ <constant name="SPECULAR_DISABLED" value="4" enum="SpecularMode">
+ </constant>
+ <constant name="BILLBOARD_DISABLED" value="0" enum="BillboardMode">
+ </constant>
+ <constant name="BILLBOARD_ENABLED" value="1" enum="BillboardMode">
+ </constant>
+ <constant name="BILLBOARD_FIXED_Y" value="2" enum="BillboardMode">
+ </constant>
+ <constant name="BILLBOARD_PARTICLES" value="3" enum="BillboardMode">
+ </constant>
+ <constant name="TEXTURE_CHANNEL_RED" value="0" enum="TextureChannel">
+ </constant>
+ <constant name="TEXTURE_CHANNEL_GREEN" value="1" enum="TextureChannel">
+ </constant>
+ <constant name="TEXTURE_CHANNEL_BLUE" value="2" enum="TextureChannel">
+ </constant>
+ <constant name="TEXTURE_CHANNEL_ALPHA" value="3" enum="TextureChannel">
+ </constant>
+ <constant name="TEXTURE_CHANNEL_GRAYSCALE" value="4" enum="TextureChannel">
+ </constant>
+ <constant name="EMISSION_OP_ADD" value="0" enum="EmissionOperator">
+ </constant>
+ <constant name="EMISSION_OP_MULTIPLY" value="1" enum="EmissionOperator">
+ </constant>
+ <constant name="DISTANCE_FADE_DISABLED" value="0" enum="DistanceFadeMode">
+ </constant>
+ <constant name="DISTANCE_FADE_PIXEL_ALPHA" value="1" enum="DistanceFadeMode">
+ </constant>
+ <constant name="DISTANCE_FADE_PIXEL_DITHER" value="2" enum="DistanceFadeMode">
+ </constant>
+ <constant name="DISTANCE_FADE_OBJECT_DITHER" value="3" enum="DistanceFadeMode">
+ </constant>
+ </constants>
+</class>
diff --git a/doc/classes/BitmapFont.xml b/doc/classes/BitmapFont.xml
index 87cccca310..421b405808 100644
--- a/doc/classes/BitmapFont.xml
+++ b/doc/classes/BitmapFont.xml
@@ -43,7 +43,7 @@
<method name="add_texture">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<description>
Adds a texture to the [BitmapFont].
@@ -88,7 +88,7 @@
</description>
</method>
<method name="get_texture" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="idx" type="int">
</argument>
diff --git a/doc/classes/Button.xml b/doc/classes/Button.xml
index 23c357ac68..675441d842 100644
--- a/doc/classes/Button.xml
+++ b/doc/classes/Button.xml
@@ -23,7 +23,7 @@
<member name="flat" type="bool" setter="set_flat" getter="is_flat" default="false">
Flat buttons don't display decoration.
</member>
- <member name="icon" type="Texture" setter="set_button_icon" getter="get_button_icon">
+ <member name="icon" type="Texture2D" setter="set_button_icon" getter="get_button_icon">
Button's icon, if text is present the icon will be placed before the text.
</member>
<member name="text" type="String" setter="set_text" getter="get_text" default="&quot;&quot;">
diff --git a/doc/classes/CPUParticles2D.xml b/doc/classes/CPUParticles2D.xml
index e747feeae8..926b8e461c 100644
--- a/doc/classes/CPUParticles2D.xml
+++ b/doc/classes/CPUParticles2D.xml
@@ -238,7 +238,7 @@
<member name="local_coords" type="bool" setter="set_use_local_coordinates" getter="get_use_local_coordinates" default="true">
If [code]true[/code], particles use the parent node's coordinate space. If [code]false[/code], they use global coordinates.
</member>
- <member name="normalmap" type="Texture" setter="set_normalmap" getter="get_normalmap">
+ <member name="normalmap" type="Texture2D" setter="set_normalmap" getter="get_normalmap">
Normal map to be used for the [member texture] property.
</member>
<member name="one_shot" type="bool" setter="set_one_shot" getter="get_one_shot" default="false">
@@ -292,7 +292,7 @@
<member name="tangential_accel_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
Tangential acceleration randomness ratio.
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
Particle texture. If [code]null[/code], particles will be squares.
</member>
</members>
diff --git a/doc/classes/Camera.xml b/doc/classes/Camera.xml
index 84f6fa8b8e..6097721cbd 100644
--- a/doc/classes/Camera.xml
+++ b/doc/classes/Camera.xml
@@ -175,6 +175,8 @@
<member name="doppler_tracking" type="int" setter="set_doppler_tracking" getter="get_doppler_tracking" enum="Camera.DopplerTracking" default="0">
If not [constant DOPPLER_TRACKING_DISABLED], this camera will simulate the [url=https://en.wikipedia.org/wiki/Doppler_effect]Doppler effect[/url] for objects changed in particular [code]_process[/code] methods. See [enum DopplerTracking] for possible values.
</member>
+ <member name="effects" type="CameraEffects" setter="set_effects" getter="get_effects">
+ </member>
<member name="environment" type="Environment" setter="set_environment" getter="get_environment">
The [Environment] to use for this camera.
</member>
diff --git a/doc/classes/CameraEffects.xml b/doc/classes/CameraEffects.xml
new file mode 100644
index 0000000000..23f0a1c7af
--- /dev/null
+++ b/doc/classes/CameraEffects.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="CameraEffects" inherits="Resource" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <members>
+ <member name="dof_blur_amount" type="float" setter="set_dof_blur_amount" getter="get_dof_blur_amount" default="0.1">
+ </member>
+ <member name="dof_blur_far_distance" type="float" setter="set_dof_blur_far_distance" getter="get_dof_blur_far_distance" default="10.0">
+ </member>
+ <member name="dof_blur_far_enabled" type="bool" setter="set_dof_blur_far_enabled" getter="is_dof_blur_far_enabled" default="false">
+ </member>
+ <member name="dof_blur_far_transition" type="float" setter="set_dof_blur_far_transition" getter="get_dof_blur_far_transition" default="5.0">
+ </member>
+ <member name="dof_blur_near_distance" type="float" setter="set_dof_blur_near_distance" getter="get_dof_blur_near_distance" default="2.0">
+ </member>
+ <member name="dof_blur_near_enabled" type="bool" setter="set_dof_blur_near_enabled" getter="is_dof_blur_near_enabled" default="false">
+ </member>
+ <member name="dof_blur_near_transition" type="float" setter="set_dof_blur_near_transition" getter="get_dof_blur_near_transition" default="1.0">
+ </member>
+ <member name="override_exposure" type="float" setter="set_override_exposure" getter="get_override_exposure" default="1.0">
+ </member>
+ <member name="override_exposure_enable" type="bool" setter="set_override_exposure_enabled" getter="is_override_exposure_enabled" default="false">
+ </member>
+ </members>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/CameraFeed.xml b/doc/classes/CameraFeed.xml
index 14d0559c85..3232f5970c 100644
--- a/doc/classes/CameraFeed.xml
+++ b/doc/classes/CameraFeed.xml
@@ -10,57 +10,7 @@
<tutorials>
</tutorials>
<methods>
- <method name="get_id" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the unique ID for this feed.
- </description>
- </method>
- <method name="get_name" qualifiers="const">
- <return type="String">
- </return>
- <description>
- Returns the camera's name.
- </description>
- </method>
- <method name="get_position" qualifiers="const">
- <return type="int" enum="CameraFeed.FeedPosition">
- </return>
- <description>
- Returns the position of camera on the device.
- </description>
- </method>
</methods>
- <members>
- <member name="feed_is_active" type="bool" setter="set_active" getter="is_active" default="false">
- If [code]true[/code], the feed is active.
- </member>
- <member name="feed_transform" type="Transform2D" setter="set_transform" getter="get_transform" default="Transform2D( 1, 0, 0, -1, 0, 1 )">
- The transform applied to the camera's image.
- </member>
- </members>
<constants>
- <constant name="FEED_NOIMAGE" value="0" enum="FeedDataType">
- No image set for the feed.
- </constant>
- <constant name="FEED_RGB" value="1" enum="FeedDataType">
- Feed supplies RGB images.
- </constant>
- <constant name="FEED_YCBCR" value="2" enum="FeedDataType">
- Feed supplies YCbCr images that need to be converted to RGB.
- </constant>
- <constant name="FEED_YCBCR_SEP" value="3" enum="FeedDataType">
- Feed supplies separate Y and CbCr images that need to be combined and converted to RGB.
- </constant>
- <constant name="FEED_UNSPECIFIED" value="0" enum="FeedPosition">
- Unspecified position.
- </constant>
- <constant name="FEED_FRONT" value="1" enum="FeedPosition">
- Camera is mounted at the front of the device.
- </constant>
- <constant name="FEED_BACK" value="2" enum="FeedPosition">
- Camera is mounted at the back of the device.
- </constant>
</constants>
</class>
diff --git a/doc/classes/CameraTexture.xml b/doc/classes/CameraTexture.xml
index d4b7310819..c0730129a9 100644
--- a/doc/classes/CameraTexture.xml
+++ b/doc/classes/CameraTexture.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="CameraTexture" inherits="Texture" version="4.0">
+<class name="CameraTexture" inherits="Texture2D" version="4.0">
<brief_description>
Texture provided by a [CameraFeed].
</brief_description>
@@ -18,7 +18,6 @@
<member name="camera_is_active" type="bool" setter="set_camera_active" getter="get_camera_active" default="false">
Convenience property that gives access to the active property of the [CameraFeed].
</member>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="0" />
<member name="which_feed" type="int" setter="set_which_feed" getter="get_which_feed" enum="CameraServer.FeedImage" default="0">
Which image within the [CameraFeed] we want access to, important if the camera image is split in a Y and CbCr component.
</member>
diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml
index b8e09708e3..7f50587e66 100644
--- a/doc/classes/CanvasItem.xml
+++ b/doc/classes/CanvasItem.xml
@@ -39,8 +39,6 @@
</argument>
<argument index="6" name="width" type="float" default="1.0">
</argument>
- <argument index="7" name="antialiased" type="bool" default="false">
- </argument>
<description>
Draws an arc between the given angles. The larger the value of [code]point_count[/code], the smoother the curve.
</description>
@@ -84,11 +82,17 @@
</argument>
<argument index="2" name="uvs" type="PoolVector2Array" default="PoolVector2Array( )">
</argument>
- <argument index="3" name="texture" type="Texture" default="null">
+ <argument index="3" name="texture" type="Texture2D" default="null">
+ </argument>
+ <argument index="4" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="5" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="6" name="specular_shinness" type="Color" default="Color( 1, 1, 1, 1 )">
</argument>
- <argument index="4" name="normal_map" type="Texture" default="null">
+ <argument index="7" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0">
</argument>
- <argument index="5" name="antialiased" type="bool" default="false">
+ <argument index="8" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0">
</argument>
<description>
Draws a colored polygon of any amount of points, convex or concave.
@@ -105,10 +109,8 @@
</argument>
<argument index="3" name="width" type="float" default="1.0">
</argument>
- <argument index="4" name="antialiased" type="bool" default="false">
- </argument>
<description>
- Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased.
+ Draws a line from a 2D point to another, with a given color and width.
</description>
</method>
<method name="draw_mesh">
@@ -116,13 +118,21 @@
</return>
<argument index="0" name="mesh" type="Mesh">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D" default="null">
</argument>
- <argument index="2" name="normal_map" type="Texture" default="null">
+ <argument index="2" name="normal_map" type="Texture2D" default="null">
</argument>
- <argument index="3" name="transform" type="Transform2D" default="Transform2D( 1, 0, 0, 1, 0, 0 )">
+ <argument index="3" name="specular_map" type="Texture2D" default="Color( 1, 1, 1, 1 )">
</argument>
- <argument index="4" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
+ <argument index="4" name="transform" type="Color" default="Transform2D( 1, 0, 0, 1, 0, 0 )">
+ </argument>
+ <argument index="5" name="modulate" type="Transform2D" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="6" name="specular_shinness" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="7" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0">
+ </argument>
+ <argument index="8" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0">
</argument>
<description>
Draws a [Mesh] in 2D, using the provided texture. See [MeshInstance2D] for related documentation.
@@ -137,10 +147,8 @@
</argument>
<argument index="2" name="width" type="float" default="1.0">
</argument>
- <argument index="3" name="antialiased" type="bool" default="false">
- </argument>
<description>
- Draws multiple, parallel lines with a uniform [code]color[/code]. [code]width[/code] and [code]antialiased[/code] are currently not implemented and have no effect.
+ Draws multiple, parallel lines with a uniform [code]color[/code].
</description>
</method>
<method name="draw_multiline_colors">
@@ -152,10 +160,8 @@
</argument>
<argument index="2" name="width" type="float" default="1.0">
</argument>
- <argument index="3" name="antialiased" type="bool" default="false">
- </argument>
<description>
- Draws multiple, parallel lines with a uniform [code]width[/code], segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code].
+ Draws multiple, parallel lines with a uniform [code]width[/code] and segment-by-segment coloring. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code].
</description>
</method>
<method name="draw_multimesh">
@@ -163,9 +169,17 @@
</return>
<argument index="0" name="multimesh" type="MultiMesh">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D" default="null">
+ </argument>
+ <argument index="2" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="3" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="4" name="specular_shinness" type="Color" default="Color( 1, 1, 1, 1 )">
</argument>
- <argument index="2" name="normal_map" type="Texture" default="null">
+ <argument index="5" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0">
+ </argument>
+ <argument index="6" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0">
</argument>
<description>
Draws a [MultiMesh] in 2D with the provided texture. See [MultiMeshInstance2D] for related documentation.
@@ -180,11 +194,17 @@
</argument>
<argument index="2" name="uvs" type="PoolVector2Array" default="PoolVector2Array( )">
</argument>
- <argument index="3" name="texture" type="Texture" default="null">
+ <argument index="3" name="texture" type="Texture2D" default="null">
+ </argument>
+ <argument index="4" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="5" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="6" name="specular_shinness" type="Color" default="Color( 1, 1, 1, 1 )">
</argument>
- <argument index="4" name="normal_map" type="Texture" default="null">
+ <argument index="7" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0">
</argument>
- <argument index="5" name="antialiased" type="bool" default="false">
+ <argument index="8" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0">
</argument>
<description>
Draws a polygon of any amount of points, convex or concave.
@@ -199,10 +219,8 @@
</argument>
<argument index="2" name="width" type="float" default="1.0">
</argument>
- <argument index="3" name="antialiased" type="bool" default="false">
- </argument>
<description>
- Draws interconnected line segments with a uniform [code]color[/code] and [code]width[/code] and optional antialiasing.
+ Draws interconnected line segments with a uniform [code]color[/code] and [code]width[/code].
</description>
</method>
<method name="draw_polyline_colors">
@@ -214,10 +232,8 @@
</argument>
<argument index="2" name="width" type="float" default="1.0">
</argument>
- <argument index="3" name="antialiased" type="bool" default="false">
- </argument>
<description>
- Draws interconnected line segments with a uniform [code]width[/code], segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code].
+ Draws interconnected line segments with a uniform [code]width[/code] and segment-by-segment coloring. Colors assigned to line segments match by index between [code]points[/code] and [code]colors[/code].
</description>
</method>
<method name="draw_primitive">
@@ -229,11 +245,19 @@
</argument>
<argument index="2" name="uvs" type="PoolVector2Array">
</argument>
- <argument index="3" name="texture" type="Texture" default="null">
+ <argument index="3" name="texture" type="Texture2D" default="null">
</argument>
<argument index="4" name="width" type="float" default="1.0">
</argument>
- <argument index="5" name="normal_map" type="Texture" default="null">
+ <argument index="5" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="6" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="7" name="specular_shinness" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="8" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0">
+ </argument>
+ <argument index="9" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0">
</argument>
<description>
Draws a custom primitive. 1 point for a point, 2 points for a line, 3 points for a triangle and 4 points for a quad.
@@ -250,11 +274,9 @@
</argument>
<argument index="3" name="width" type="float" default="1.0">
</argument>
- <argument index="4" name="antialiased" type="bool" default="false">
- </argument>
<description>
- Draws a rectangle. If [code]filled[/code] is [code]true[/code], the rectangle will be filled with the [code]color[/code] specified. If [code]filled[/code] is [code]false[/code], the rectangle will be drawn as a stroke with the [code]color[/code] and [code]width[/code] specified. If [code]antialiased[/code] is [code]true[/code], the lines will be antialiased.
- [b]Note:[/b] [code]width[/code] and [code]antialiased[/code] are only effective if [code]filled[/code] is [code]false[/code].
+ Draws a rectangle. If [code]filled[/code] is [code]true[/code], the rectangle will be filled with the [code]color[/code] specified. If [code]filled[/code] is [code]false[/code], the rectangle will be drawn as a stroke with the [code]color[/code] and [code]width[/code] specified.
+ [b]Note:[/b] [code]width[/code] is only effective if [code]filled[/code] is [code]false[/code].
</description>
</method>
<method name="draw_set_transform">
@@ -310,13 +332,21 @@
<method name="draw_texture">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="position" type="Vector2">
</argument>
<argument index="2" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
</argument>
- <argument index="3" name="normal_map" type="Texture" default="null">
+ <argument index="3" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="4" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="5" name="specular_shinness" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="6" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0">
+ </argument>
+ <argument index="7" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0">
</argument>
<description>
Draws a texture at a given position.
@@ -325,7 +355,7 @@
<method name="draw_texture_rect">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="rect" type="Rect2">
</argument>
@@ -335,7 +365,15 @@
</argument>
<argument index="4" name="transpose" type="bool" default="false">
</argument>
- <argument index="5" name="normal_map" type="Texture" default="null">
+ <argument index="5" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="6" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="7" name="specular_shinness" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="8" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0">
+ </argument>
+ <argument index="9" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0">
</argument>
<description>
Draws a textured rectangle at a given position, optionally modulated by a color. If [code]transpose[/code] is [code]true[/code], the texture will have its X and Y coordinates swapped.
@@ -344,7 +382,7 @@
<method name="draw_texture_rect_region">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="rect" type="Rect2">
</argument>
@@ -354,9 +392,17 @@
</argument>
<argument index="4" name="transpose" type="bool" default="false">
</argument>
- <argument index="5" name="normal_map" type="Texture" default="null">
+ <argument index="5" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="6" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="7" name="clip_uv" type="Color" default="true">
+ </argument>
+ <argument index="8" name="specular_shinness" type="bool" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="9" name="texture_filter" type="int" enum="CanvasItem.TextureFilter" default="0">
</argument>
- <argument index="6" name="clip_uv" type="bool" default="true">
+ <argument index="10" name="texture_repeat" type="int" enum="CanvasItem.TextureRepeat" default="0">
</argument>
<description>
Draws a textured rectangle region at a given position, optionally modulated by a color. If [code]transpose[/code] is [code]true[/code], the texture will have its X and Y coordinates swapped.
@@ -560,6 +606,10 @@
<member name="show_on_top" type="bool" setter="_set_on_top" getter="_is_on_top">
If [code]true[/code], the object draws on top of its parent.
</member>
+ <member name="texture_filter" type="int" setter="set_texture_filter" getter="get_texture_filter" enum="CanvasItem.TextureFilter" default="0">
+ </member>
+ <member name="texture_repeat" type="int" setter="set_texture_repeat" getter="get_texture_repeat" enum="CanvasItem.TextureRepeat" default="0">
+ </member>
<member name="use_parent_material" type="bool" setter="set_use_parent_material" getter="get_use_parent_material" default="false">
If [code]true[/code], the parent [CanvasItem]'s [member material] property is used as this one's material.
</member>
@@ -590,24 +640,6 @@
</signal>
</signals>
<constants>
- <constant name="BLEND_MODE_MIX" value="0" enum="BlendMode">
- Mix blending mode. Colors are assumed to be independent of the alpha (opacity) value.
- </constant>
- <constant name="BLEND_MODE_ADD" value="1" enum="BlendMode">
- Additive blending mode.
- </constant>
- <constant name="BLEND_MODE_SUB" value="2" enum="BlendMode">
- Subtractive blending mode.
- </constant>
- <constant name="BLEND_MODE_MUL" value="3" enum="BlendMode">
- Multiplicative blending mode.
- </constant>
- <constant name="BLEND_MODE_PREMULT_ALPHA" value="4" enum="BlendMode">
- Mix blending mode. Colors are assumed to be premultiplied by the alpha (opacity) value.
- </constant>
- <constant name="BLEND_MODE_DISABLED" value="5" enum="BlendMode">
- Disables blending mode. Colors including alpha are written as-is. Only applicable for render targets with a transparent background. No lighting will be applied.
- </constant>
<constant name="NOTIFICATION_TRANSFORM_CHANGED" value="2000">
The [CanvasItem]'s transform has changed. This notification is only received if enabled by [method set_notify_transform] or [method set_notify_local_transform].
</constant>
@@ -623,5 +655,31 @@
<constant name="NOTIFICATION_EXIT_CANVAS" value="33">
The [CanvasItem] has exited the canvas.
</constant>
+ <constant name="TEXTURE_FILTER_PARENT_NODE" value="0" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_NEAREST" value="1" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_LINEAR" value="2" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS" value="3" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_LINEAR_WITH_MIPMAPS" value="4" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS_ANISOTROPIC" value="5" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC" value="6" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_FILTER_MAX" value="7" enum="TextureFilter">
+ </constant>
+ <constant name="TEXTURE_REPEAT_PARENT_NODE" value="0" enum="TextureRepeat">
+ </constant>
+ <constant name="TEXTURE_REPEAT_DISABLED" value="1" enum="TextureRepeat">
+ </constant>
+ <constant name="TEXTURE_REPEAT_ENABLED" value="2" enum="TextureRepeat">
+ </constant>
+ <constant name="TEXTURE_REPEAT_MIRROR" value="3" enum="TextureRepeat">
+ </constant>
+ <constant name="TEXTURE_REPEAT_MAX" value="4" enum="TextureRepeat">
+ </constant>
</constants>
</class>
diff --git a/doc/classes/CanvasItemMaterial.xml b/doc/classes/CanvasItemMaterial.xml
index 1265d2f268..ffe2272260 100644
--- a/doc/classes/CanvasItemMaterial.xml
+++ b/doc/classes/CanvasItemMaterial.xml
@@ -18,7 +18,7 @@
The manner in which material reacts to lighting.
</member>
<member name="particles_anim_h_frames" type="int" setter="set_particles_anim_h_frames" getter="get_particles_anim_h_frames">
- The number of columns in the spritesheet assigned as [Texture] for a [Particles2D] or [CPUParticles2D].
+ The number of columns in the spritesheet assigned as [Texture2D] for a [Particles2D] or [CPUParticles2D].
[b]Note:[/b] This property is only used and visible in the editor if [member particles_animation] is [code]true[/code].
</member>
<member name="particles_anim_loop" type="bool" setter="set_particles_anim_loop" getter="get_particles_anim_loop">
@@ -26,7 +26,7 @@
[b]Note:[/b] This property is only used and visible in the editor if [member particles_animation] is [code]true[/code].
</member>
<member name="particles_anim_v_frames" type="int" setter="set_particles_anim_v_frames" getter="get_particles_anim_v_frames">
- The number of rows in the spritesheet assigned as [Texture] for a [Particles2D] or [CPUParticles2D].
+ The number of rows in the spritesheet assigned as [Texture2D] for a [Particles2D] or [CPUParticles2D].
[b]Note:[/b] This property is only used and visible in the editor if [member particles_animation] is [code]true[/code].
</member>
<member name="particles_animation" type="bool" setter="set_particles_animation" getter="get_particles_animation" default="false">
diff --git a/doc/classes/CheckBox.xml b/doc/classes/CheckBox.xml
index ffcc22703f..c29f089bce 100644
--- a/doc/classes/CheckBox.xml
+++ b/doc/classes/CheckBox.xml
@@ -20,7 +20,7 @@
<theme_item name="check_vadjust" type="int" default="0">
The vertical offset used when rendering the check icons (in pixels).
</theme_item>
- <theme_item name="checked" type="Texture">
+ <theme_item name="checked" type="Texture2D">
The check icon to display when the [CheckBox] is checked.
</theme_item>
<theme_item name="disabled" type="StyleBox">
@@ -62,13 +62,13 @@
<theme_item name="pressed" type="StyleBox">
The [StyleBox] to display as a background when the [CheckBox] is pressed.
</theme_item>
- <theme_item name="radio_checked" type="Texture">
+ <theme_item name="radio_checked" type="Texture2D">
If the [CheckBox] is configured as a radio button, the icon to display when the [CheckBox] is checked.
</theme_item>
- <theme_item name="radio_unchecked" type="Texture">
+ <theme_item name="radio_unchecked" type="Texture2D">
If the [CheckBox] is configured as a radio button, the icon to display when the [CheckBox] is unchecked.
</theme_item>
- <theme_item name="unchecked" type="Texture">
+ <theme_item name="unchecked" type="Texture2D">
The check icon to display when the [CheckBox] is unchecked.
</theme_item>
</theme_items>
diff --git a/doc/classes/CheckButton.xml b/doc/classes/CheckButton.xml
index 6c024a3753..616940a494 100644
--- a/doc/classes/CheckButton.xml
+++ b/doc/classes/CheckButton.xml
@@ -56,16 +56,16 @@
<theme_item name="normal" type="StyleBox">
The [StyleBox] to display as a background.
</theme_item>
- <theme_item name="off" type="Texture">
+ <theme_item name="off" type="Texture2D">
The icon to display when the [CheckButton] is unchecked.
</theme_item>
- <theme_item name="off_disabled" type="Texture">
+ <theme_item name="off_disabled" type="Texture2D">
The icon to display when the [CheckButton] is unchecked and disabled.
</theme_item>
- <theme_item name="on" type="Texture">
+ <theme_item name="on" type="Texture2D">
The icon to display when the [CheckButton] is checked.
</theme_item>
- <theme_item name="on_disabled" type="Texture">
+ <theme_item name="on_disabled" type="Texture2D">
The icon to display when the [CheckButton] is checked and disabled.
</theme_item>
<theme_item name="pressed" type="StyleBox">
diff --git a/doc/classes/Color.xml b/doc/classes/Color.xml
index 0d3f51309b..5529251b5a 100644
--- a/doc/classes/Color.xml
+++ b/doc/classes/Color.xml
@@ -128,18 +128,6 @@
[/codeblock]
</description>
</method>
- <method name="gray">
- <return type="float">
- </return>
- <description>
- Returns the color's grayscale representation.
- The gray value is calculated as [code](r + g + b) / 3[/code].
- [codeblock]
- var c = Color(0.2, 0.45, 0.82)
- var gray = c.gray() # A value of 0.466667
- [/codeblock]
- </description>
- </method>
<method name="inverted">
<return type="Color">
</return>
diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml
index d315c6a387..d0c8e3f948 100644
--- a/doc/classes/ColorPicker.xml
+++ b/doc/classes/ColorPicker.xml
@@ -87,11 +87,11 @@
<constants>
</constants>
<theme_items>
- <theme_item name="add_preset" type="Texture">
+ <theme_item name="add_preset" type="Texture2D">
</theme_item>
- <theme_item name="color_hue" type="Texture">
+ <theme_item name="color_hue" type="Texture2D">
</theme_item>
- <theme_item name="color_sample" type="Texture">
+ <theme_item name="color_sample" type="Texture2D">
</theme_item>
<theme_item name="h_width" type="int" default="30">
</theme_item>
@@ -99,11 +99,11 @@
</theme_item>
<theme_item name="margin" type="int" default="4">
</theme_item>
- <theme_item name="overbright_indicator" type="Texture">
+ <theme_item name="overbright_indicator" type="Texture2D">
</theme_item>
- <theme_item name="preset_bg" type="Texture">
+ <theme_item name="preset_bg" type="Texture2D">
</theme_item>
- <theme_item name="screen_picker" type="Texture">
+ <theme_item name="screen_picker" type="Texture2D">
</theme_item>
<theme_item name="sv_height" type="int" default="256">
</theme_item>
diff --git a/doc/classes/ColorPickerButton.xml b/doc/classes/ColorPickerButton.xml
index d9023a4f3a..67f64c8a66 100644
--- a/doc/classes/ColorPickerButton.xml
+++ b/doc/classes/ColorPickerButton.xml
@@ -55,7 +55,7 @@
<constants>
</constants>
<theme_items>
- <theme_item name="bg" type="Texture">
+ <theme_item name="bg" type="Texture2D">
The background of the color preview rect on the button.
</theme_item>
<theme_item name="disabled" type="StyleBox">
diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml
index 556ebb93bf..3bf2ede896 100644
--- a/doc/classes/Control.xml
+++ b/doc/classes/Control.xml
@@ -125,7 +125,7 @@
</return>
<argument index="0" name="name" type="String">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
Overrides the icon with given [code]name[/code] in the [member theme] resource the control uses. If [code]icon[/code] is empty or invalid, the override is cleared and the icon from assigned [Theme] is used.
@@ -317,7 +317,7 @@
</description>
</method>
<method name="get_icon" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="name" type="String">
</argument>
diff --git a/doc/classes/CubeMap.xml b/doc/classes/CubeMap.xml
deleted file mode 100644
index 78731a7cd0..0000000000
--- a/doc/classes/CubeMap.xml
+++ /dev/null
@@ -1,99 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="CubeMap" inherits="Resource" version="4.0">
- <brief_description>
- A CubeMap is a 6-sided 3D texture.
- </brief_description>
- <description>
- A 6-sided 3D texture typically used for faking reflections. It can be used to make an object look as if it's reflecting its surroundings. This usually delivers much better performance than other reflection methods.
- </description>
- <tutorials>
- </tutorials>
- <methods>
- <method name="get_height" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the [CubeMap]'s height.
- </description>
- </method>
- <method name="get_side" qualifiers="const">
- <return type="Image">
- </return>
- <argument index="0" name="side" type="int" enum="CubeMap.Side">
- </argument>
- <description>
- Returns an [Image] for a side of the [CubeMap] using one of the [enum Side] constants.
- </description>
- </method>
- <method name="get_width" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the [CubeMap]'s width.
- </description>
- </method>
- <method name="set_side">
- <return type="void">
- </return>
- <argument index="0" name="side" type="int" enum="CubeMap.Side">
- </argument>
- <argument index="1" name="image" type="Image">
- </argument>
- <description>
- Sets an [Image] for a side of the [CubeMap] using one of the [enum Side] constants.
- </description>
- </method>
- </methods>
- <members>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" default="7">
- The render flags for the [CubeMap]. See the [enum Flags] constants for details.
- </member>
- <member name="lossy_storage_quality" type="float" setter="set_lossy_storage_quality" getter="get_lossy_storage_quality" default="0.7">
- The lossy storage quality of the [CubeMap] if the storage mode is set to [constant STORAGE_COMPRESS_LOSSY].
- </member>
- <member name="storage_mode" type="int" setter="set_storage" getter="get_storage" enum="CubeMap.Storage" default="0">
- The [CubeMap]'s storage mode. See [enum Storage] constants.
- </member>
- </members>
- <constants>
- <constant name="STORAGE_RAW" value="0" enum="Storage">
- Store the [CubeMap] without any compression.
- </constant>
- <constant name="STORAGE_COMPRESS_LOSSY" value="1" enum="Storage">
- Store the [CubeMap] with strong compression that reduces image quality.
- </constant>
- <constant name="STORAGE_COMPRESS_LOSSLESS" value="2" enum="Storage">
- Store the [CubeMap] with moderate compression that doesn't reduce image quality.
- </constant>
- <constant name="SIDE_LEFT" value="0" enum="Side">
- Identifier for the left face of the [CubeMap].
- </constant>
- <constant name="SIDE_RIGHT" value="1" enum="Side">
- Identifier for the right face of the [CubeMap].
- </constant>
- <constant name="SIDE_BOTTOM" value="2" enum="Side">
- Identifier for the bottom face of the [CubeMap].
- </constant>
- <constant name="SIDE_TOP" value="3" enum="Side">
- Identifier for the top face of the [CubeMap].
- </constant>
- <constant name="SIDE_FRONT" value="4" enum="Side">
- Identifier for the front face of the [CubeMap].
- </constant>
- <constant name="SIDE_BACK" value="5" enum="Side">
- Identifier for the back face of the [CubeMap].
- </constant>
- <constant name="FLAG_MIPMAPS" value="1" enum="Flags">
- Generate mipmaps, to enable smooth zooming out of the texture.
- </constant>
- <constant name="FLAG_REPEAT" value="2" enum="Flags">
- Repeat (instead of clamp to edge).
- </constant>
- <constant name="FLAG_FILTER" value="4" enum="Flags">
- Turn on magnifying filter, to enable smooth zooming in of the texture.
- </constant>
- <constant name="FLAGS_DEFAULT" value="7" enum="Flags">
- Default flags. Generate mipmaps, repeat, and filter are enabled.
- </constant>
- </constants>
-</class>
diff --git a/doc/classes/Cubemap.xml b/doc/classes/Cubemap.xml
new file mode 100644
index 0000000000..16431c65c9
--- /dev/null
+++ b/doc/classes/Cubemap.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="Cubemap" inherits="TextureLayered" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/CubemapArray.xml b/doc/classes/CubemapArray.xml
new file mode 100644
index 0000000000..03cfd75acf
--- /dev/null
+++ b/doc/classes/CubemapArray.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="CubemapArray" inherits="TextureLayered" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/CurveTexture.xml b/doc/classes/CurveTexture.xml
index 10c7a4a086..bc6b69d2d1 100644
--- a/doc/classes/CurveTexture.xml
+++ b/doc/classes/CurveTexture.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="CurveTexture" inherits="Texture" version="4.0">
+<class name="CurveTexture" inherits="Texture2D" version="4.0">
<brief_description>
A texture that shows a curve.
</brief_description>
diff --git a/doc/classes/DirectionalLight.xml b/doc/classes/DirectionalLight.xml
index 8dddf921d3..a3ef830d5d 100644
--- a/doc/classes/DirectionalLight.xml
+++ b/doc/classes/DirectionalLight.xml
@@ -21,6 +21,8 @@
<member name="directional_shadow_depth_range" type="int" setter="set_shadow_depth_range" getter="get_shadow_depth_range" enum="DirectionalLight.ShadowDepthRange" default="0">
Optimizes shadow rendering for detail versus movement. See [enum ShadowDepthRange].
</member>
+ <member name="directional_shadow_fade_start" type="float" setter="set_param" getter="get_param" default="0.8">
+ </member>
<member name="directional_shadow_max_distance" type="float" setter="set_param" getter="get_param" default="100.0">
The maximum distance for shadow splits.
</member>
diff --git a/doc/classes/DynamicFont.xml b/doc/classes/DynamicFont.xml
index c2fb4d53cc..29e430b14d 100644
--- a/doc/classes/DynamicFont.xml
+++ b/doc/classes/DynamicFont.xml
@@ -108,12 +108,6 @@
<member name="size" type="int" setter="set_size" getter="get_size" default="16">
The font size in pixels.
</member>
- <member name="use_filter" type="bool" setter="set_use_filter" getter="get_use_filter" default="false">
- If [code]true[/code], filtering is used. This makes the font blurry instead of pixelated when scaling it if font oversampling is disabled or ineffective. It's recommended to enable this when using the font in a control whose size changes over time, unless a pixel art aesthetic is desired.
- </member>
- <member name="use_mipmaps" type="bool" setter="set_use_mipmaps" getter="get_use_mipmaps" default="false">
- If [code]true[/code], mipmapping is used. This improves the font's appearance when downscaling it if font oversampling is disabled or ineffective.
- </member>
</members>
<constants>
<constant name="SPACING_TOP" value="0" enum="SpacingType">
diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml
index fea746f32d..771b7d59d4 100644
--- a/doc/classes/EditorInterface.xml
+++ b/doc/classes/EditorInterface.xml
@@ -127,7 +127,7 @@
<argument index="1" name="preview_size" type="int">
</argument>
<description>
- Returns mesh previews rendered at the given size as an [Array] of [Texture]s.
+ Returns mesh previews rendered at the given size as an [Array] of [Texture2D]s.
</description>
</method>
<method name="open_scene_from_path">
diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml
index eaaa87c6f9..e441562051 100644
--- a/doc/classes/EditorPlugin.xml
+++ b/doc/classes/EditorPlugin.xml
@@ -67,11 +67,11 @@
</argument>
<argument index="2" name="script" type="Script">
</argument>
- <argument index="3" name="icon" type="Texture">
+ <argument index="3" name="icon" type="Texture2D">
</argument>
<description>
Adds a custom type, which will appear in the list of nodes or resources. An icon can be optionally passed.
- When given node or resource is selected, the base type will be instanced (ie, "Spatial", "Control", "Resource"), then the script will be loaded and set to this object.
+ When given node or resource is selected, the base type will be instanced (e.g. "Spatial", "Control", "Resource"), then the script will be loaded and set to this object.
You can use the virtual method [method handles] to check if your custom object is being edited by checking the script or using the [code]is[/code] keyword.
During run-time, this will be a simple object with a script so this function does not need to be called then.
</description>
diff --git a/doc/classes/EditorResourcePreviewGenerator.xml b/doc/classes/EditorResourcePreviewGenerator.xml
index 0436f7ce06..e935bf19fc 100644
--- a/doc/classes/EditorResourcePreviewGenerator.xml
+++ b/doc/classes/EditorResourcePreviewGenerator.xml
@@ -18,7 +18,7 @@
</description>
</method>
<method name="generate" qualifiers="virtual">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="from" type="Resource">
</argument>
@@ -31,7 +31,7 @@
</description>
</method>
<method name="generate_from_path" qualifiers="virtual">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="path" type="String">
</argument>
diff --git a/doc/classes/EditorSpatialGizmoPlugin.xml b/doc/classes/EditorSpatialGizmoPlugin.xml
index eba75438b9..b1a4a25a5f 100644
--- a/doc/classes/EditorSpatialGizmoPlugin.xml
+++ b/doc/classes/EditorSpatialGizmoPlugin.xml
@@ -15,7 +15,7 @@
</return>
<argument index="0" name="name" type="String">
</argument>
- <argument index="1" name="material" type="SpatialMaterial">
+ <argument index="1" name="material" type="StandardMaterial3D">
</argument>
<description>
Adds a new material to the internal material list for the plugin. It can then be accessed with [method get_material]. Should not be overridden.
@@ -68,7 +68,7 @@
</return>
<argument index="0" name="name" type="String">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<argument index="2" name="on_top" type="bool" default="false">
</argument>
@@ -118,7 +118,7 @@
</description>
</method>
<method name="get_material">
- <return type="SpatialMaterial">
+ <return type="StandardMaterial3D">
</return>
<argument index="0" name="name" type="String">
</argument>
diff --git a/doc/classes/Environment.xml b/doc/classes/Environment.xml
index da4b1d883a..3dad948629 100644
--- a/doc/classes/Environment.xml
+++ b/doc/classes/Environment.xml
@@ -40,8 +40,8 @@
<member name="adjustment_brightness" type="float" setter="set_adjustment_brightness" getter="get_adjustment_brightness" default="1.0">
The global brightness value of the rendered scene. Effective only if [code]adjustment_enabled[/code] is [code]true[/code].
</member>
- <member name="adjustment_color_correction" type="Texture" setter="set_adjustment_color_correction" getter="get_adjustment_color_correction">
- Applies the provided [Texture] resource to affect the global color aspect of the rendered scene. Effective only if [code]adjustment_enabled[/code] is [code]true[/code].
+ <member name="adjustment_color_correction" type="Texture2D" setter="set_adjustment_color_correction" getter="get_adjustment_color_correction">
+ Applies the provided [Texture2D] resource to affect the global color aspect of the rendered scene. Effective only if [code]adjustment_enabled[/code] is [code]true[/code].
</member>
<member name="adjustment_contrast" type="float" setter="set_adjustment_contrast" getter="get_adjustment_contrast" default="1.0">
The global contrast value of the rendered scene (default value is 1). Effective only if [code]adjustment_enabled[/code] is [code]true[/code].
@@ -58,9 +58,13 @@
<member name="ambient_light_energy" type="float" setter="set_ambient_light_energy" getter="get_ambient_light_energy" default="1.0">
The ambient light's energy. The higher the value, the stronger the light.
</member>
+ <member name="ambient_light_occlusion_color" type="Color" setter="set_ao_color" getter="get_ao_color" default="Color( 0, 0, 0, 1 )">
+ </member>
<member name="ambient_light_sky_contribution" type="float" setter="set_ambient_light_sky_contribution" getter="get_ambient_light_sky_contribution" default="1.0">
Defines the amount of light that the sky brings on the scene. A value of 0 means that the sky's light emission has no effect on the scene illumination, thus all ambient illumination is provided by the ambient light. On the contrary, a value of 1 means that all the light that affects the scene is provided by the sky, thus the ambient light parameter has no effect on the scene.
</member>
+ <member name="ambient_light_source" type="int" setter="set_ambient_source" getter="get_ambient_source" enum="Environment.AmbientSource" default="0">
+ </member>
<member name="auto_exposure_enabled" type="bool" setter="set_tonemap_auto_exposure" getter="get_tonemap_auto_exposure" default="false">
If [code]true[/code], enables the tonemapping auto exposure mode of the scene renderer. If [code]true[/code], the renderer will automatically determine the exposure setting to adapt to the scene's illumination and the observed light.
</member>
@@ -83,7 +87,7 @@
The maximum layer ID to display. Only effective when using the [constant BG_CANVAS] background mode.
</member>
<member name="background_color" type="Color" setter="set_bg_color" getter="get_bg_color" default="Color( 0, 0, 0, 1 )">
- The [Color] displayed for clear areas of the scene. Only effective when using the [constant BG_COLOR] or [constant BG_COLOR_SKY] background modes).
+ The [Color] displayed for clear areas of the scene. Only effective when using the [constant BG_COLOR] background mode.
</member>
<member name="background_energy" type="float" setter="set_bg_energy" getter="get_bg_energy" default="1.0">
The power of the light emitted by the background.
@@ -91,51 +95,6 @@
<member name="background_mode" type="int" setter="set_background" getter="get_background" enum="Environment.BGMode" default="0">
The background mode. See [enum BGMode] for possible values.
</member>
- <member name="background_sky" type="Sky" setter="set_sky" getter="get_sky">
- The [Sky] resource defined as background.
- </member>
- <member name="background_sky_custom_fov" type="float" setter="set_sky_custom_fov" getter="get_sky_custom_fov" default="0.0">
- The [Sky] resource's custom field of view.
- </member>
- <member name="background_sky_orientation" type="Basis" setter="set_sky_orientation" getter="get_sky_orientation" default="Basis( 1, 0, 0, 0, 1, 0, 0, 0, 1 )">
- The [Sky] resource's rotation expressed as a [Basis].
- </member>
- <member name="background_sky_rotation" type="Vector3" setter="set_sky_rotation" getter="get_sky_rotation" default="Vector3( 0, 0, 0 )">
- The [Sky] resource's rotation expressed as Euler angles in radians.
- </member>
- <member name="background_sky_rotation_degrees" type="Vector3" setter="set_sky_rotation_degrees" getter="get_sky_rotation_degrees" default="Vector3( 0, 0, 0 )">
- The [Sky] resource's rotation expressed as Euler angles in degrees.
- </member>
- <member name="dof_blur_far_amount" type="float" setter="set_dof_blur_far_amount" getter="get_dof_blur_far_amount" default="0.1">
- The amount of far blur for the depth-of-field effect.
- </member>
- <member name="dof_blur_far_distance" type="float" setter="set_dof_blur_far_distance" getter="get_dof_blur_far_distance" default="10.0">
- The distance from the camera where the far blur effect affects the rendering.
- </member>
- <member name="dof_blur_far_enabled" type="bool" setter="set_dof_blur_far_enabled" getter="is_dof_blur_far_enabled" default="false">
- If [code]true[/code], enables the depth-of-field far blur effect.
- </member>
- <member name="dof_blur_far_quality" type="int" setter="set_dof_blur_far_quality" getter="get_dof_blur_far_quality" enum="Environment.DOFBlurQuality" default="1">
- The depth-of-field far blur's quality. Higher values can mitigate the visible banding effect seen at higher strengths, but are much slower.
- </member>
- <member name="dof_blur_far_transition" type="float" setter="set_dof_blur_far_transition" getter="get_dof_blur_far_transition" default="5.0">
- The length of the transition between the no-blur area and far blur.
- </member>
- <member name="dof_blur_near_amount" type="float" setter="set_dof_blur_near_amount" getter="get_dof_blur_near_amount" default="0.1">
- The amount of near blur for the depth-of-field effect.
- </member>
- <member name="dof_blur_near_distance" type="float" setter="set_dof_blur_near_distance" getter="get_dof_blur_near_distance" default="2.0">
- Distance from the camera where the near blur effect affects the rendering.
- </member>
- <member name="dof_blur_near_enabled" type="bool" setter="set_dof_blur_near_enabled" getter="is_dof_blur_near_enabled" default="false">
- If [code]true[/code], enables the depth-of-field near blur effect.
- </member>
- <member name="dof_blur_near_quality" type="int" setter="set_dof_blur_near_quality" getter="get_dof_blur_near_quality" enum="Environment.DOFBlurQuality" default="1">
- The depth-of-field near blur's quality. Higher values can mitigate the visible banding effect seen at higher strengths, but are much slower.
- </member>
- <member name="dof_blur_near_transition" type="float" setter="set_dof_blur_near_transition" getter="get_dof_blur_near_transition" default="1.0">
- The length of the transition between the near blur and no-blur area.
- </member>
<member name="fog_color" type="Color" setter="set_fog_color" getter="get_fog_color" default="Color( 0.5, 0.6, 0.7, 1 )">
The fog's [Color].
</member>
@@ -224,9 +183,19 @@
<member name="glow_levels/7" type="bool" setter="set_glow_level" getter="is_glow_level_enabled" default="false">
If [code]true[/code], the 7th level of glow is enabled. This is the most "global" level (blurriest).
</member>
+ <member name="glow_mix" type="float" setter="set_glow_mix" getter="get_glow_mix" default="0.05">
+ </member>
<member name="glow_strength" type="float" setter="set_glow_strength" getter="get_glow_strength" default="1.0">
The glow strength. When using the GLES2 renderer, this should be increased to 1.3 to compensate for the lack of HDR rendering.
</member>
+ <member name="reflected_light_source" type="int" setter="set_reflection_source" getter="get_reflection_source" enum="Environment.ReflectionSource" default="0">
+ </member>
+ <member name="sky" type="Sky" setter="set_sky" getter="get_sky">
+ </member>
+ <member name="sky_custom_fov" type="float" setter="set_sky_custom_fov" getter="get_sky_custom_fov" default="0.0">
+ </member>
+ <member name="sky_rotation" type="Vector3" setter="set_sky_rotation" getter="get_sky_rotation" default="Vector3( 0, 0, 0 )">
+ </member>
<member name="ss_reflections_depth_tolerance" type="float" setter="set_ssr_depth_tolerance" getter="get_ssr_depth_tolerance" default="0.2">
The depth tolerance for screen-space reflections.
</member>
@@ -254,9 +223,6 @@
<member name="ssao_blur" type="int" setter="set_ssao_blur" getter="get_ssao_blur" enum="Environment.SSAOBlur" default="3">
The screen-space ambient occlusion blur quality. See [enum SSAOBlur] for possible values.
</member>
- <member name="ssao_color" type="Color" setter="set_ssao_color" getter="get_ssao_color" default="Color( 0, 0, 0, 1 )">
- The screen-space ambient occlusion color.
- </member>
<member name="ssao_edge_sharpness" type="float" setter="set_ssao_edge_sharpness" getter="get_ssao_edge_sharpness" default="4.0">
The screen-space ambient occlusion edge sharpness.
</member>
@@ -266,21 +232,12 @@
<member name="ssao_intensity" type="float" setter="set_ssao_intensity" getter="get_ssao_intensity" default="1.0">
The primary screen-space ambient occlusion intensity. See also [member ssao_radius].
</member>
- <member name="ssao_intensity2" type="float" setter="set_ssao_intensity2" getter="get_ssao_intensity2" default="1.0">
- The secondary screen-space ambient occlusion intensity. See also [member ssao_radius2].
- </member>
<member name="ssao_light_affect" type="float" setter="set_ssao_direct_light_affect" getter="get_ssao_direct_light_affect" default="0.0">
The screen-space ambient occlusion intensity in direct light. In real life, ambient occlusion only applies to indirect light, which means its effects can't be seen in direct light. Values higher than [code]0[/code] will make the SSAO effect visible in direct light.
</member>
- <member name="ssao_quality" type="int" setter="set_ssao_quality" getter="get_ssao_quality" enum="Environment.SSAOQuality" default="1">
- The screen-space ambient occlusion quality. Higher qualities will make better use of small objects for ambient occlusion, but are slower.
- </member>
<member name="ssao_radius" type="float" setter="set_ssao_radius" getter="get_ssao_radius" default="1.0">
The primary screen-space ambient occlusion radius.
</member>
- <member name="ssao_radius2" type="float" setter="set_ssao_radius2" getter="get_ssao_radius2" default="0.0">
- The secondary screen-space ambient occlusion radius. If set to a value higher than [code]0[/code], enables the secondary screen-space ambient occlusion effect which can be used to improve the effect's appearance (at the cost of performance).
- </member>
<member name="tonemap_exposure" type="float" setter="set_tonemap_exposure" getter="get_tonemap_exposure" default="1.0">
The default exposure used for tonemapping.
</member>
@@ -292,9 +249,6 @@
</member>
</members>
<constants>
- <constant name="BG_KEEP" value="5" enum="BGMode">
- Keeps on screen every pixel drawn in the background. This is the fastest background mode, but it can only be safely used in fully-interior scenes (no visible sky or sky reflections). If enabled in a scene where the background is visible, "ghost trail" artifacts will be visible when moving the camera.
- </constant>
<constant name="BG_CLEAR_COLOR" value="0" enum="BGMode">
Clears the background using the clear color defined in [member ProjectSettings.rendering/environment/default_clear_color].
</constant>
@@ -304,18 +258,32 @@
<constant name="BG_SKY" value="2" enum="BGMode">
Displays a user-defined sky in the background.
</constant>
- <constant name="BG_COLOR_SKY" value="3" enum="BGMode">
- Clears the background using a custom clear color and allows defining a sky for shading and reflection. This mode is slightly faster than [constant BG_SKY] and should be preferred in scenes where reflections can be visible, but the sky itself never is (e.g. top-down camera).
- </constant>
- <constant name="BG_CANVAS" value="4" enum="BGMode">
+ <constant name="BG_CANVAS" value="3" enum="BGMode">
Displays a [CanvasLayer] in the background.
</constant>
- <constant name="BG_CAMERA_FEED" value="6" enum="BGMode">
+ <constant name="BG_KEEP" value="4" enum="BGMode">
+ Keeps on screen every pixel drawn in the background. This is the fastest background mode, but it can only be safely used in fully-interior scenes (no visible sky or sky reflections). If enabled in a scene where the background is visible, "ghost trail" artifacts will be visible when moving the camera.
+ </constant>
+ <constant name="BG_CAMERA_FEED" value="5" enum="BGMode">
Displays a camera feed in the background.
</constant>
- <constant name="BG_MAX" value="7" enum="BGMode">
+ <constant name="BG_MAX" value="6" enum="BGMode">
Represents the size of the [enum BGMode] enum.
</constant>
+ <constant name="AMBIENT_SOURCE_BG" value="0" enum="AmbientSource">
+ </constant>
+ <constant name="AMBIENT_SOURCE_DISABLED" value="1" enum="AmbientSource">
+ </constant>
+ <constant name="AMBIENT_SOURCE_COLOR" value="2" enum="AmbientSource">
+ </constant>
+ <constant name="AMBIENT_SOURCE_SKY" value="3" enum="AmbientSource">
+ </constant>
+ <constant name="REFLECTION_SOURCE_BG" value="0" enum="ReflectionSource">
+ </constant>
+ <constant name="REFLECTION_SOURCE_DISABLED" value="1" enum="ReflectionSource">
+ </constant>
+ <constant name="REFLECTION_SOURCE_SKY" value="2" enum="ReflectionSource">
+ </constant>
<constant name="GLOW_BLEND_MODE_ADDITIVE" value="0" enum="GlowBlendMode">
Additive glow blending mode. Mostly used for particles, glows (bloom), lens flare, bright sources.
</constant>
@@ -328,6 +296,8 @@
<constant name="GLOW_BLEND_MODE_REPLACE" value="3" enum="GlowBlendMode">
Replace glow blending mode. Replaces all pixels' color by the glow value. This can be used to simulate a full-screen blur effect by tweaking the glow parameters to match the original image's brightness.
</constant>
+ <constant name="GLOW_BLEND_MODE_MIX" value="4" enum="GlowBlendMode">
+ </constant>
<constant name="TONE_MAPPER_LINEAR" value="0" enum="ToneMapper">
Linear tonemapper operator. Reads the linear data and passes it on unmodified.
</constant>
@@ -340,15 +310,6 @@
<constant name="TONE_MAPPER_ACES" value="3" enum="ToneMapper">
Academy Color Encoding System tonemapper operator.
</constant>
- <constant name="DOF_BLUR_QUALITY_LOW" value="0" enum="DOFBlurQuality">
- Low depth-of-field blur quality (fastest).
- </constant>
- <constant name="DOF_BLUR_QUALITY_MEDIUM" value="1" enum="DOFBlurQuality">
- Medium depth-of-field blur quality.
- </constant>
- <constant name="DOF_BLUR_QUALITY_HIGH" value="2" enum="DOFBlurQuality">
- High depth-of-field blur quality (slowest).
- </constant>
<constant name="SSAO_BLUR_DISABLED" value="0" enum="SSAOBlur">
No blur for the screen-space ambient occlusion effect (fastest).
</constant>
@@ -361,14 +322,5 @@
<constant name="SSAO_BLUR_3x3" value="3" enum="SSAOBlur">
3×3 blur for the screen-space ambient occlusion effect (slowest).
</constant>
- <constant name="SSAO_QUALITY_LOW" value="0" enum="SSAOQuality">
- Low quality for the screen-space ambient occlusion effect (fastest).
- </constant>
- <constant name="SSAO_QUALITY_MEDIUM" value="1" enum="SSAOQuality">
- Low quality for the screen-space ambient occlusion effect.
- </constant>
- <constant name="SSAO_QUALITY_HIGH" value="2" enum="SSAOQuality">
- Low quality for the screen-space ambient occlusion effect (slowest).
- </constant>
</constants>
</class>
diff --git a/doc/classes/FileDialog.xml b/doc/classes/FileDialog.xml
index 5cf252c173..37b5cec2c9 100644
--- a/doc/classes/FileDialog.xml
+++ b/doc/classes/FileDialog.xml
@@ -134,15 +134,15 @@
<theme_items>
<theme_item name="files_disabled" type="Color" default="Color( 0, 0, 0, 0.7 )">
</theme_item>
- <theme_item name="folder" type="Texture">
+ <theme_item name="folder" type="Texture2D">
</theme_item>
<theme_item name="folder_icon_modulate" type="Color" default="Color( 1, 1, 1, 1 )">
</theme_item>
- <theme_item name="parent_folder" type="Texture">
+ <theme_item name="parent_folder" type="Texture2D">
</theme_item>
- <theme_item name="reload" type="Texture">
+ <theme_item name="reload" type="Texture2D">
</theme_item>
- <theme_item name="toggle_hidden" type="Texture">
+ <theme_item name="toggle_hidden" type="Texture2D">
</theme_item>
</theme_items>
</class>
diff --git a/doc/classes/GIProbe.xml b/doc/classes/GIProbe.xml
index 76d9620ecf..322143ea9e 100644
--- a/doc/classes/GIProbe.xml
+++ b/doc/classes/GIProbe.xml
@@ -5,7 +5,7 @@
</brief_description>
<description>
[GIProbe]s are used to provide high-quality real-time indirect light to scenes. They precompute the effect of objects that emit light and the effect of static geometry to simulate the behavior of complex light in real-time. [GIProbe]s need to be baked before using, however, once baked, dynamic objects will receive light from them. Further, lights can be fully dynamic or baked.
- Having [GIProbe]s in a scene can be expensive, the quality of the probe can be turned down in exchange for better performance in the [ProjectSettings] using [member ProjectSettings.rendering/quality/voxel_cone_tracing/high_quality].
+ Having [GIProbe]s in a scene can be expensive, the quality of the probe can be turned down in exchange for better performance in the [ProjectSettings] using [member ProjectSettings.rendering/quality/gi_probes/quality].
</description>
<tutorials>
<link>https://docs.godotengine.org/en/latest/tutorials/3d/gi_probes.html</link>
@@ -31,34 +31,12 @@
</method>
</methods>
<members>
- <member name="bias" type="float" setter="set_bias" getter="get_bias" default="1.5">
- Offsets the lookup of the light contribution from the [GIProbe]. This can be used to avoid self-shadowing, but may introduce light leaking at higher values. This and [member normal_bias] should be played around with to minimize self-shadowing and light leaking.
- [b]Note:[/b] [code]bias[/code] should usually be above 1.0 as that is the size of the voxels.
- </member>
- <member name="compress" type="bool" setter="set_compress" getter="is_compressed" default="false">
- If [code]true[/code], the data for this [GIProbe] will be compressed. Compression saves space, but results in far worse visual quality.
- </member>
<member name="data" type="GIProbeData" setter="set_probe_data" getter="get_probe_data">
The [GIProbeData] resource that holds the data for this [GIProbe].
</member>
- <member name="dynamic_range" type="int" setter="set_dynamic_range" getter="get_dynamic_range" default="4">
- The maximum brightness that the [GIProbe] will recognize. Brightness will be scaled within this range.
- </member>
- <member name="energy" type="float" setter="set_energy" getter="get_energy" default="1.0">
- Energy multiplier. Makes the lighting contribution from the [GIProbe] brighter.
- </member>
<member name="extents" type="Vector3" setter="set_extents" getter="get_extents" default="Vector3( 10, 10, 10 )">
The size of the area covered by the [GIProbe]. If you make the extents larger without increasing the subdivisions with [member subdiv], the size of each cell will increase and result in lower detailed lighting.
</member>
- <member name="interior" type="bool" setter="set_interior" getter="is_interior" default="false">
- If [code]true[/code], ignores the sky contribution when calculating lighting.
- </member>
- <member name="normal_bias" type="float" setter="set_normal_bias" getter="get_normal_bias" default="0.0">
- Offsets the lookup into the [GIProbe] based on the object's normal direction. Can be used to reduce some self-shadowing artifacts.
- </member>
- <member name="propagation" type="float" setter="set_propagation" getter="get_propagation" default="0.7">
- How much light propagates through the probe internally. A higher value allows light to spread further.
- </member>
<member name="subdiv" type="int" setter="set_subdiv" getter="get_subdiv" enum="GIProbe.Subdiv" default="1">
Number of times to subdivide the grid that the [GIProbe] operates on. A higher number results in finer detail and thus higher visual quality, while lower numbers result in better performance.
</member>
diff --git a/doc/classes/GIProbeData.xml b/doc/classes/GIProbeData.xml
index bb1ee4d054..d2918c24f7 100644
--- a/doc/classes/GIProbeData.xml
+++ b/doc/classes/GIProbeData.xml
@@ -7,29 +7,83 @@
<tutorials>
</tutorials>
<methods>
+ <method name="allocate">
+ <return type="void">
+ </return>
+ <argument index="0" name="to_cell_xform" type="Transform">
+ </argument>
+ <argument index="1" name="aabb" type="AABB">
+ </argument>
+ <argument index="2" name="octree_size" type="Vector3">
+ </argument>
+ <argument index="3" name="octree_cells" type="PoolByteArray">
+ </argument>
+ <argument index="4" name="data_cells" type="PoolByteArray">
+ </argument>
+ <argument index="5" name="distance_field" type="PoolByteArray">
+ </argument>
+ <argument index="6" name="level_counts" type="PoolIntArray">
+ </argument>
+ <description>
+ </description>
+ </method>
+ <method name="get_bounds" qualifiers="const">
+ <return type="AABB">
+ </return>
+ <description>
+ </description>
+ </method>
+ <method name="get_data_cells" qualifiers="const">
+ <return type="PoolByteArray">
+ </return>
+ <description>
+ </description>
+ </method>
+ <method name="get_level_counts" qualifiers="const">
+ <return type="PoolIntArray">
+ </return>
+ <description>
+ </description>
+ </method>
+ <method name="get_octree_cells" qualifiers="const">
+ <return type="PoolByteArray">
+ </return>
+ <description>
+ </description>
+ </method>
+ <method name="get_octree_size" qualifiers="const">
+ <return type="Vector3">
+ </return>
+ <description>
+ </description>
+ </method>
+ <method name="get_to_cell_xform" qualifiers="const">
+ <return type="Transform">
+ </return>
+ <description>
+ </description>
+ </method>
</methods>
<members>
- <member name="bias" type="float" setter="set_bias" getter="get_bias" default="0.4">
+ <member name="anisotropy_strength" type="float" setter="set_anisotropy_strength" getter="get_anisotropy_strength" default="0.5">
</member>
- <member name="bounds" type="AABB" setter="set_bounds" getter="get_bounds" default="AABB( 0, 0, 0, 1, 1, 1 )">
+ <member name="ao" type="float" setter="set_ao" getter="get_ao" default="0.0">
</member>
- <member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="1.0">
+ <member name="ao_size" type="float" setter="set_ao_size" getter="get_ao_size" default="0.5">
</member>
- <member name="compress" type="bool" setter="set_compress" getter="is_compressed" default="false">
+ <member name="bias" type="float" setter="set_bias" getter="get_bias" default="1.5">
</member>
- <member name="dynamic_data" type="PoolIntArray" setter="set_dynamic_data" getter="get_dynamic_data" default="PoolIntArray( )">
- </member>
- <member name="dynamic_range" type="int" setter="set_dynamic_range" getter="get_dynamic_range" default="1">
+ <member name="dynamic_range" type="float" setter="set_dynamic_range" getter="get_dynamic_range" default="4.0">
</member>
<member name="energy" type="float" setter="set_energy" getter="get_energy" default="1.0">
</member>
<member name="interior" type="bool" setter="set_interior" getter="is_interior" default="false">
</member>
- <member name="normal_bias" type="float" setter="set_normal_bias" getter="get_normal_bias" default="0.4">
+ <member name="normal_bias" type="float" setter="set_normal_bias" getter="get_normal_bias" default="0.0">
</member>
- <member name="propagation" type="float" setter="set_propagation" getter="get_propagation" default="1.0">
+ <member name="propagation" type="float" setter="set_propagation" getter="get_propagation" default="0.7">
</member>
- <member name="to_cell_xform" type="Transform" setter="set_to_cell_xform" getter="get_to_cell_xform" default="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )">
+ <member name="use_two_bounces" type="bool" setter="set_use_two_bounces" getter="is_using_two_bounces" default="false">
</member>
</members>
<constants>
diff --git a/doc/classes/GeometryInstance.xml b/doc/classes/GeometryInstance.xml
index fccd75edad..8259462531 100644
--- a/doc/classes/GeometryInstance.xml
+++ b/doc/classes/GeometryInstance.xml
@@ -66,8 +66,10 @@
The material override for the whole geometry.
If a material is assigned to this property, it will be used instead of any material set in any material slot of the mesh.
</member>
+ <member name="use_dynamic_gi" type="bool" setter="set_flag" getter="get_flag" default="false">
+ </member>
<member name="use_in_baked_light" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], this GeometryInstance will be used when baking lights using a [GIProbe] or [BakedLightmap].
+ If [code]true[/code], this GeometryInstance will be used when baking lights using a [GIProbe].
</member>
</members>
<constants>
@@ -87,12 +89,14 @@
In other words, the actual mesh will not be visible, only the shadows casted from the mesh will be.
</constant>
<constant name="FLAG_USE_BAKED_LIGHT" value="0" enum="Flags">
- Will allow the GeometryInstance to be used when baking lights using a [GIProbe] or [BakedLightmap].
+ Will allow the GeometryInstance to be used when baking lights using a [GIProbe].
+ </constant>
+ <constant name="FLAG_USE_DYNAMIC_GI" value="1" enum="Flags">
</constant>
- <constant name="FLAG_DRAW_NEXT_FRAME_IF_VISIBLE" value="1" enum="Flags">
+ <constant name="FLAG_DRAW_NEXT_FRAME_IF_VISIBLE" value="2" enum="Flags">
Unused in this class, exposed for consistency with [enum VisualServer.InstanceFlags].
</constant>
- <constant name="FLAG_MAX" value="2" enum="Flags">
+ <constant name="FLAG_MAX" value="3" enum="Flags">
Represents the size of the [enum Flags] enum.
</constant>
</constants>
diff --git a/doc/classes/GradientTexture.xml b/doc/classes/GradientTexture.xml
index fc9c3fd1bb..242a78b2e4 100644
--- a/doc/classes/GradientTexture.xml
+++ b/doc/classes/GradientTexture.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="GradientTexture" inherits="Texture" version="4.0">
+<class name="GradientTexture" inherits="Texture2D" version="4.0">
<brief_description>
Gradient-filled texture.
</brief_description>
diff --git a/doc/classes/GraphEdit.xml b/doc/classes/GraphEdit.xml
index e35fc2b7d1..8733b94ee7 100644
--- a/doc/classes/GraphEdit.xml
+++ b/doc/classes/GraphEdit.xml
@@ -308,21 +308,21 @@
</theme_item>
<theme_item name="grid_minor" type="Color" default="Color( 1, 1, 1, 0.05 )">
</theme_item>
- <theme_item name="minus" type="Texture">
+ <theme_item name="minus" type="Texture2D">
</theme_item>
- <theme_item name="more" type="Texture">
+ <theme_item name="more" type="Texture2D">
</theme_item>
<theme_item name="port_grab_distance_horizontal" type="int" default="48">
</theme_item>
<theme_item name="port_grab_distance_vertical" type="int" default="6">
</theme_item>
- <theme_item name="reset" type="Texture">
+ <theme_item name="reset" type="Texture2D">
</theme_item>
<theme_item name="selection_fill" type="Color" default="Color( 1, 1, 1, 0.3 )">
</theme_item>
<theme_item name="selection_stroke" type="Color" default="Color( 1, 1, 1, 0.8 )">
</theme_item>
- <theme_item name="snap" type="Texture">
+ <theme_item name="snap" type="Texture2D">
</theme_item>
</theme_items>
</class>
diff --git a/doc/classes/GraphNode.xml b/doc/classes/GraphNode.xml
index cc6e3dc7f9..a9f1b15443 100644
--- a/doc/classes/GraphNode.xml
+++ b/doc/classes/GraphNode.xml
@@ -166,9 +166,9 @@
</argument>
<argument index="6" name="color_right" type="Color">
</argument>
- <argument index="7" name="custom_left" type="Texture" default="null">
+ <argument index="7" name="custom_left" type="Texture2D" default="null">
</argument>
- <argument index="8" name="custom_right" type="Texture" default="null">
+ <argument index="8" name="custom_right" type="Texture2D" default="null">
</argument>
<description>
Sets properties of the slot with ID [code]idx[/code].
@@ -254,7 +254,7 @@
<theme_items>
<theme_item name="breakpoint" type="StyleBox">
</theme_item>
- <theme_item name="close" type="Texture">
+ <theme_item name="close" type="Texture2D">
</theme_item>
<theme_item name="close_color" type="Color" default="Color( 0, 0, 0, 1 )">
</theme_item>
@@ -270,13 +270,13 @@
</theme_item>
<theme_item name="frame" type="StyleBox">
</theme_item>
- <theme_item name="port" type="Texture">
+ <theme_item name="port" type="Texture2D">
</theme_item>
<theme_item name="port_offset" type="int" default="3">
</theme_item>
<theme_item name="position" type="StyleBox">
</theme_item>
- <theme_item name="resizer" type="Texture">
+ <theme_item name="resizer" type="Texture2D">
</theme_item>
<theme_item name="resizer_color" type="Color" default="Color( 0, 0, 0, 1 )">
</theme_item>
diff --git a/doc/classes/HScrollBar.xml b/doc/classes/HScrollBar.xml
index 129e15b489..963454dab8 100644
--- a/doc/classes/HScrollBar.xml
+++ b/doc/classes/HScrollBar.xml
@@ -13,10 +13,10 @@
<constants>
</constants>
<theme_items>
- <theme_item name="decrement" type="Texture">
+ <theme_item name="decrement" type="Texture2D">
Icon used as a button to scroll the [ScrollBar] left. Supports custom step using the [member ScrollBar.custom_step] property.
</theme_item>
- <theme_item name="decrement_highlight" type="Texture">
+ <theme_item name="decrement_highlight" type="Texture2D">
Displayed when the mouse cursor hovers over the decrement button.
</theme_item>
<theme_item name="grabber" type="StyleBox">
@@ -28,10 +28,10 @@
<theme_item name="grabber_pressed" type="StyleBox">
Used when the grabber is being dragged.
</theme_item>
- <theme_item name="increment" type="Texture">
+ <theme_item name="increment" type="Texture2D">
Icon used as a button to scroll the [ScrollBar] right. Supports custom step using the [member ScrollBar.custom_step] property.
</theme_item>
- <theme_item name="increment_highlight" type="Texture">
+ <theme_item name="increment_highlight" type="Texture2D">
Displayed when the mouse cursor hovers over the increment button.
</theme_item>
<theme_item name="scroll" type="StyleBox">
diff --git a/doc/classes/HSlider.xml b/doc/classes/HSlider.xml
index 2999580e83..be3c94e495 100644
--- a/doc/classes/HSlider.xml
+++ b/doc/classes/HSlider.xml
@@ -13,17 +13,17 @@
<constants>
</constants>
<theme_items>
- <theme_item name="grabber" type="Texture">
+ <theme_item name="grabber" type="Texture2D">
</theme_item>
<theme_item name="grabber_area" type="StyleBox">
</theme_item>
- <theme_item name="grabber_disabled" type="Texture">
+ <theme_item name="grabber_disabled" type="Texture2D">
</theme_item>
- <theme_item name="grabber_highlight" type="Texture">
+ <theme_item name="grabber_highlight" type="Texture2D">
</theme_item>
<theme_item name="slider" type="StyleBox">
</theme_item>
- <theme_item name="tick" type="Texture">
+ <theme_item name="tick" type="Texture2D">
</theme_item>
</theme_items>
</class>
diff --git a/doc/classes/HSplitContainer.xml b/doc/classes/HSplitContainer.xml
index 6191087c2e..0dd1f96602 100644
--- a/doc/classes/HSplitContainer.xml
+++ b/doc/classes/HSplitContainer.xml
@@ -17,7 +17,7 @@
</theme_item>
<theme_item name="bg" type="StyleBox">
</theme_item>
- <theme_item name="grabber" type="Texture">
+ <theme_item name="grabber" type="Texture2D">
</theme_item>
<theme_item name="separation" type="int" default="12">
</theme_item>
diff --git a/doc/classes/Image.xml b/doc/classes/Image.xml
index 2cd17cb5c5..b4a46dd661 100644
--- a/doc/classes/Image.xml
+++ b/doc/classes/Image.xml
@@ -4,7 +4,7 @@
Image datatype.
</brief_description>
<description>
- Native image datatype. Contains image data, which can be converted to a [Texture], and several functions to interact with it. The maximum width and height for an [Image] are [constant MAX_WIDTH] and [constant MAX_HEIGHT].
+ Native image datatype. Contains image data, which can be converted to a [Texture2D], and several functions to interact with it. The maximum width and height for an [Image] are [constant MAX_WIDTH] and [constant MAX_HEIGHT].
</description>
<tutorials>
</tutorials>
@@ -86,14 +86,26 @@
</return>
<argument index="0" name="mode" type="int" enum="Image.CompressMode">
</argument>
- <argument index="1" name="source" type="int" enum="Image.CompressSource">
+ <argument index="1" name="source" type="int" enum="Image.CompressSource" default="0">
</argument>
- <argument index="2" name="lossy_quality" type="float">
+ <argument index="2" name="lossy_quality" type="float" default="0.7">
</argument>
<description>
Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available. See [enum CompressMode] and [enum CompressSource] constants.
</description>
</method>
+ <method name="compress_from_channels">
+ <return type="int" enum="Error">
+ </return>
+ <argument index="0" name="mode" type="int" enum="Image.CompressMode">
+ </argument>
+ <argument index="1" name="channels" type="int" enum="Image.CompressSource">
+ </argument>
+ <argument index="2" name="lossy_quality" type="float" default="0.7">
+ </argument>
+ <description>
+ </description>
+ </method>
<method name="convert">
<return type="void">
</return>
@@ -169,6 +181,14 @@
Returns [constant ALPHA_BLEND] if the image has data for alpha values. Returns [constant ALPHA_BIT] if all the alpha values are stored in a single bit. Returns [constant ALPHA_NONE] if no data for alpha values is found.
</description>
</method>
+ <method name="detect_used_channels">
+ <return type="int" enum="Image.UsedChannels">
+ </return>
+ <argument index="0" name="source" type="int" enum="Image.CompressSource" default="0">
+ </argument>
+ <description>
+ </description>
+ </method>
<method name="expand_x2_hq2x">
<return type="void">
</return>
@@ -497,10 +517,10 @@
</member>
</members>
<constants>
- <constant name="MAX_WIDTH" value="16384">
+ <constant name="MAX_WIDTH" value="16777216">
The maximal width allowed for [Image] resources.
</constant>
- <constant name="MAX_HEIGHT" value="16384">
+ <constant name="MAX_HEIGHT" value="16777216">
The maximal height allowed for [Image] resources.
</constant>
<constant name="FORMAT_L8" value="0" enum="Format">
@@ -526,8 +546,7 @@
<constant name="FORMAT_RGBA4444" value="6" enum="Format">
OpenGL texture format [code]RGBA[/code] with four components, each with a bitdepth of 4.
</constant>
- <constant name="FORMAT_RGBA5551" value="7" enum="Format">
- OpenGL texture format [code]GL_RGB5_A1[/code] where 5 bits of depth for each component of RGB and one bit for alpha.
+ <constant name="FORMAT_RGB565" value="7" enum="Format">
</constant>
<constant name="FORMAT_RF" value="8" enum="Format">
OpenGL texture format [code]GL_R32F[/code] where there's one component, a 32-bit floating-point value.
@@ -624,7 +643,11 @@
[url=https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC]Ericsson Texture Compression format 2[/url] ([code]RGB8_PUNCHTHROUGH_ALPHA1[/code] variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.
[b]Note:[/b] When creating an [ImageTexture], an sRGB to linear color space conversion is performed.
</constant>
- <constant name="FORMAT_MAX" value="37" enum="Format">
+ <constant name="FORMAT_ETC2_RA_AS_RG" value="37" enum="Format">
+ </constant>
+ <constant name="FORMAT_DXT5_RA_AS_RG" value="38" enum="Format">
+ </constant>
+ <constant name="FORMAT_MAX" value="39" enum="Format">
Represents the size of the [enum Format] enum.
</constant>
<constant name="INTERPOLATE_NEAREST" value="0" enum="Interpolation">
@@ -670,6 +693,18 @@
<constant name="COMPRESS_ETC2" value="4" enum="CompressMode">
Use ETC2 compression.
</constant>
+ <constant name="USED_CHANNELS_L" value="0" enum="UsedChannels">
+ </constant>
+ <constant name="USED_CHANNELS_LA" value="1" enum="UsedChannels">
+ </constant>
+ <constant name="USED_CHANNELS_R" value="2" enum="UsedChannels">
+ </constant>
+ <constant name="USED_CHANNELS_RG" value="3" enum="UsedChannels">
+ </constant>
+ <constant name="USED_CHANNELS_RGB" value="4" enum="UsedChannels">
+ </constant>
+ <constant name="USED_CHANNELS_RGBA" value="5" enum="UsedChannels">
+ </constant>
<constant name="COMPRESS_SOURCE_GENERIC" value="0" enum="CompressSource">
Source texture (before compression) is a regular texture. Default for all textures.
</constant>
diff --git a/doc/classes/ImageTexture.xml b/doc/classes/ImageTexture.xml
index 7e3e818773..98eb42831b 100644
--- a/doc/classes/ImageTexture.xml
+++ b/doc/classes/ImageTexture.xml
@@ -1,39 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="ImageTexture" inherits="Texture" version="4.0">
+<class name="ImageTexture" inherits="Texture2D" version="4.0">
<brief_description>
- A [Texture] based on an [Image].
+ A [Texture2D] based on an [Image].
</brief_description>
<description>
- A [Texture] based on an [Image]. Can be created from an [Image] with [method create_from_image].
+ A [Texture2D] based on an [Image]. Can be created from an [Image] with [method create_from_image].
</description>
<tutorials>
</tutorials>
<methods>
- <method name="create">
- <return type="void">
- </return>
- <argument index="0" name="width" type="int">
- </argument>
- <argument index="1" name="height" type="int">
- </argument>
- <argument index="2" name="format" type="int" enum="Image.Format">
- </argument>
- <argument index="3" name="flags" type="int" default="7">
- </argument>
- <description>
- Create a new [ImageTexture] with [code]width[/code] and [code]height[/code].
- [code]format[/code] is a value from [enum Image.Format], [code]flags[/code] is any combination of [enum Texture.Flags].
- </description>
- </method>
<method name="create_from_image">
<return type="void">
</return>
<argument index="0" name="image" type="Image">
</argument>
- <argument index="1" name="flags" type="int" default="7">
- </argument>
<description>
- Create a new [ImageTexture] from an [Image] with [code]flags[/code] from [enum Texture.Flags]. An sRGB to linear color space conversion can take place, according to [enum Image.Format].
+ Create a new [ImageTexture] from an [Image].
</description>
</method>
<method name="get_format" qualifiers="const">
@@ -43,52 +25,26 @@
Returns the format of the [ImageTexture], one of [enum Image.Format].
</description>
</method>
- <method name="load">
- <return type="int" enum="Error">
+ <method name="set_size_override">
+ <return type="void">
</return>
- <argument index="0" name="path" type="String">
+ <argument index="0" name="size" type="Vector2">
</argument>
<description>
- Load an [ImageTexture] from a file path.
+ Resizes the [ImageTexture] to the specified dimensions.
</description>
</method>
- <method name="set_data">
+ <method name="update">
<return type="void">
</return>
<argument index="0" name="image" type="Image">
</argument>
- <description>
- Sets the [Image] of this [ImageTexture].
- </description>
- </method>
- <method name="set_size_override">
- <return type="void">
- </return>
- <argument index="0" name="size" type="Vector2">
+ <argument index="1" name="immediate" type="bool" default="false">
</argument>
<description>
- Resizes the [ImageTexture] to the specified dimensions.
</description>
</method>
</methods>
- <members>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="7" />
- <member name="lossy_quality" type="float" setter="set_lossy_storage_quality" getter="get_lossy_storage_quality" default="0.7">
- The storage quality for [constant STORAGE_COMPRESS_LOSSY].
- </member>
- <member name="storage" type="int" setter="set_storage" getter="get_storage" enum="ImageTexture.Storage" default="0">
- The storage type (raw, lossy, or compressed).
- </member>
- </members>
<constants>
- <constant name="STORAGE_RAW" value="0" enum="Storage">
- [Image] data is stored raw and unaltered.
- </constant>
- <constant name="STORAGE_COMPRESS_LOSSY" value="1" enum="Storage">
- [Image] data is compressed with a lossy algorithm. You can set the storage quality with [member lossy_quality].
- </constant>
- <constant name="STORAGE_COMPRESS_LOSSLESS" value="2" enum="Storage">
- [Image] data is compressed with a lossless algorithm.
- </constant>
</constants>
</class>
diff --git a/doc/classes/ImmediateGeometry.xml b/doc/classes/ImmediateGeometry.xml
index bb58192313..710e929d1a 100644
--- a/doc/classes/ImmediateGeometry.xml
+++ b/doc/classes/ImmediateGeometry.xml
@@ -38,7 +38,7 @@
</return>
<argument index="0" name="primitive" type="int" enum="Mesh.PrimitiveType">
</argument>
- <argument index="1" name="texture" type="Texture" default="null">
+ <argument index="1" name="texture" type="Texture2D" default="null">
</argument>
<description>
Begin drawing (and optionally pass a texture override). When done call [method end]. For more information on how this works, search for [code]glBegin()[/code] and [code]glEnd()[/code] references.
diff --git a/doc/classes/ItemList.xml b/doc/classes/ItemList.xml
index 5c4a956c08..1bc36abf66 100644
--- a/doc/classes/ItemList.xml
+++ b/doc/classes/ItemList.xml
@@ -14,7 +14,7 @@
<method name="add_icon_item">
<return type="void">
</return>
- <argument index="0" name="icon" type="Texture">
+ <argument index="0" name="icon" type="Texture2D">
</argument>
<argument index="1" name="selectable" type="bool" default="true">
</argument>
@@ -27,7 +27,7 @@
</return>
<argument index="0" name="text" type="String">
</argument>
- <argument index="1" name="icon" type="Texture" default="null">
+ <argument index="1" name="icon" type="Texture2D" default="null">
</argument>
<argument index="2" name="selectable" type="bool" default="true">
</argument>
@@ -88,7 +88,7 @@
</description>
</method>
<method name="get_item_icon" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="idx" type="int">
</argument>
@@ -286,10 +286,10 @@
</return>
<argument index="0" name="idx" type="int">
</argument>
- <argument index="1" name="icon" type="Texture">
+ <argument index="1" name="icon" type="Texture2D">
</argument>
<description>
- Sets (or replaces) the icon's [Texture] associated with the specified index.
+ Sets (or replaces) the icon's [Texture2D] associated with the specified index.
</description>
</method>
<method name="set_item_icon_modulate">
diff --git a/doc/classes/LargeTexture.xml b/doc/classes/LargeTexture.xml
index ab39462870..a1d172e4b1 100644
--- a/doc/classes/LargeTexture.xml
+++ b/doc/classes/LargeTexture.xml
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="LargeTexture" inherits="Texture" version="4.0">
+<class name="LargeTexture" inherits="Texture2D" version="4.0">
<brief_description>
- A [Texture] capable of storing many smaller textures with offsets.
+ A [Texture2D] capable of storing many smaller textures with offsets.
</brief_description>
<description>
- A [Texture] capable of storing many smaller textures with offsets.
- You can dynamically add pieces ([Texture]s) to this [LargeTexture] using different offsets.
+ A [Texture2D] capable of storing many smaller textures with offsets.
+ You can dynamically add pieces ([Texture2D]s) to this [LargeTexture] using different offsets.
</description>
<tutorials>
</tutorials>
@@ -15,7 +15,7 @@
</return>
<argument index="0" name="ofs" type="Vector2">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
Adds [code]texture[/code] to this [LargeTexture], starting on offset [code]ofs[/code].
@@ -45,12 +45,12 @@
</description>
</method>
<method name="get_piece_texture" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="idx" type="int">
</argument>
<description>
- Returns the [Texture] of the piece with the index [code]idx[/code].
+ Returns the [Texture2D] of the piece with the index [code]idx[/code].
</description>
</method>
<method name="set_piece_offset">
@@ -69,10 +69,10 @@
</return>
<argument index="0" name="idx" type="int">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
- Sets the [Texture] of the piece with index [code]idx[/code] to [code]texture[/code].
+ Sets the [Texture2D] of the piece with index [code]idx[/code] to [code]texture[/code].
</description>
</method>
<method name="set_size">
@@ -85,9 +85,6 @@
</description>
</method>
</methods>
- <members>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="0" />
- </members>
<constants>
</constants>
</class>
diff --git a/doc/classes/Light.xml b/doc/classes/Light.xml
index 763f3b4b41..a2867a50d2 100644
--- a/doc/classes/Light.xml
+++ b/doc/classes/Light.xml
@@ -48,7 +48,7 @@
The light's strength multiplier.
</member>
<member name="light_indirect_energy" type="float" setter="set_param" getter="get_param" default="1.0">
- Secondary multiplier used with indirect light (light bounces). This works on both [BakedLightmap] and [GIProbe].
+ Secondary multiplier used with indirect light (light bounces). Used with [GIProbe].
</member>
<member name="light_negative" type="bool" setter="set_negative" getter="is_negative" default="false">
If [code]true[/code], the light's effect is reversed, darkening areas and casting bright shadows.
@@ -109,16 +109,18 @@
<constant name="PARAM_SHADOW_SPLIT_3_OFFSET" value="11" enum="Param">
Constant for accessing [member DirectionalLight.directional_shadow_split_3].
</constant>
- <constant name="PARAM_SHADOW_NORMAL_BIAS" value="12" enum="Param">
+ <constant name="PARAM_SHADOW_FADE_START" value="12" enum="Param">
+ </constant>
+ <constant name="PARAM_SHADOW_NORMAL_BIAS" value="13" enum="Param">
Constant for accessing [member DirectionalLight.directional_shadow_normal_bias].
</constant>
- <constant name="PARAM_SHADOW_BIAS" value="13" enum="Param">
+ <constant name="PARAM_SHADOW_BIAS" value="14" enum="Param">
Constant for accessing [member shadow_bias].
</constant>
- <constant name="PARAM_SHADOW_BIAS_SPLIT_SCALE" value="14" enum="Param">
+ <constant name="PARAM_SHADOW_BIAS_SPLIT_SCALE" value="15" enum="Param">
Constant for accessing [member DirectionalLight.directional_shadow_bias_split_scale].
</constant>
- <constant name="PARAM_MAX" value="15" enum="Param">
+ <constant name="PARAM_MAX" value="16" enum="Param">
Represents the size of the [enum Param] enum.
</constant>
<constant name="BAKE_DISABLED" value="0" enum="BakeMode">
diff --git a/doc/classes/Light2D.xml b/doc/classes/Light2D.xml
index 5f3ad1b865..2862190d4d 100644
--- a/doc/classes/Light2D.xml
+++ b/doc/classes/Light2D.xml
@@ -64,14 +64,11 @@
<member name="shadow_filter_smooth" type="float" setter="set_shadow_smooth" getter="get_shadow_smooth" default="0.0">
Smoothing value for shadows.
</member>
- <member name="shadow_gradient_length" type="float" setter="set_shadow_gradient_length" getter="get_shadow_gradient_length" default="0.0">
- Smooth shadow gradient length.
- </member>
<member name="shadow_item_cull_mask" type="int" setter="set_item_shadow_cull_mask" getter="get_item_shadow_cull_mask" default="1">
The shadow mask. Used with [LightOccluder2D] to cast shadows. Only occluders with a matching light mask will cast shadows.
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
- [Texture] used for the Light2D's appearance.
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ [Texture2D] used for the Light2D's appearance.
</member>
<member name="texture_scale" type="float" setter="set_texture_scale" getter="get_texture_scale" default="1.0">
The [code]texture[/code]'s scale factor.
@@ -93,19 +90,10 @@
<constant name="SHADOW_FILTER_NONE" value="0" enum="ShadowFilter">
No filter applies to the shadow map. See [member shadow_filter].
</constant>
- <constant name="SHADOW_FILTER_PCF3" value="1" enum="ShadowFilter">
- Percentage closer filtering (3 samples) applies to the shadow map. See [member shadow_filter].
- </constant>
- <constant name="SHADOW_FILTER_PCF5" value="2" enum="ShadowFilter">
+ <constant name="SHADOW_FILTER_PCF5" value="1" enum="ShadowFilter">
Percentage closer filtering (5 samples) applies to the shadow map. See [member shadow_filter].
</constant>
- <constant name="SHADOW_FILTER_PCF7" value="3" enum="ShadowFilter">
- Percentage closer filtering (7 samples) applies to the shadow map. See [member shadow_filter].
- </constant>
- <constant name="SHADOW_FILTER_PCF9" value="4" enum="ShadowFilter">
- Percentage closer filtering (9 samples) applies to the shadow map. See [member shadow_filter].
- </constant>
- <constant name="SHADOW_FILTER_PCF13" value="5" enum="ShadowFilter">
+ <constant name="SHADOW_FILTER_PCF13" value="2" enum="ShadowFilter">
Percentage closer filtering (13 samples) applies to the shadow map. See [member shadow_filter].
</constant>
</constants>
diff --git a/doc/classes/Line2D.xml b/doc/classes/Line2D.xml
index b5983e00b9..bed5bbaea7 100644
--- a/doc/classes/Line2D.xml
+++ b/doc/classes/Line2D.xml
@@ -5,7 +5,6 @@
</brief_description>
<description>
A line through several points in 2D space.
- [b]Note:[/b] By default, Godot can only draw up to 4,096 polygon points at a time. To increase this limit, open the Project Settings and increase [member ProjectSettings.rendering/limits/buffers/canvas_polygon_buffer_size_kb] and [member ProjectSettings.rendering/limits/buffers/canvas_polygon_index_buffer_size_kb].
</description>
<tutorials>
</tutorials>
@@ -94,7 +93,7 @@
<member name="sharp_limit" type="float" setter="set_sharp_limit" getter="get_sharp_limit" default="2.0">
The direction difference in radians between vector points. This value is only used if [code]joint mode[/code] is set to [constant LINE_JOINT_SHARP].
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
The texture used for the line's texture. Uses [code]texture_mode[/code] for drawing style.
</member>
<member name="texture_mode" type="int" setter="set_texture_mode" getter="get_texture_mode" enum="Line2D.LineTextureMode" default="0">
diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml
index f2574360cb..447446ba10 100644
--- a/doc/classes/LineEdit.xml
+++ b/doc/classes/LineEdit.xml
@@ -130,7 +130,7 @@
<member name="placeholder_text" type="String" setter="set_placeholder" getter="get_placeholder" default="&quot;&quot;">
Text shown when the [LineEdit] is empty. It is [b]not[/b] the [LineEdit]'s default value (see [member text]).
</member>
- <member name="right_icon" type="Texture" setter="set_right_icon" getter="get_right_icon">
+ <member name="right_icon" type="Texture2D" setter="set_right_icon" getter="get_right_icon">
Sets the icon that will appear in the right end of the [LineEdit] if there's no [member text], or always, if [member clear_button_enabled] is set to [code]false[/code].
</member>
<member name="secret" type="bool" setter="set_secret" getter="is_secret" default="false">
@@ -211,7 +211,7 @@
</constant>
</constants>
<theme_items>
- <theme_item name="clear" type="Texture">
+ <theme_item name="clear" type="Texture2D">
Texture for the clear button. See [member clear_button_enabled].
</theme_item>
<theme_item name="clear_button_color" type="Color" default="Color( 0.88, 0.88, 0.88, 1 )">
diff --git a/doc/classes/LineShape2D.xml b/doc/classes/LineShape2D.xml
index 33352b7d98..d3cfc94a8c 100644
--- a/doc/classes/LineShape2D.xml
+++ b/doc/classes/LineShape2D.xml
@@ -14,7 +14,7 @@
<member name="d" type="float" setter="set_d" getter="get_d" default="0.0">
The line's distance from the origin.
</member>
- <member name="normal" type="Vector2" setter="set_normal" getter="get_normal" default="Vector2( 0, -1 )">
+ <member name="normal" type="Vector2" setter="set_normal" getter="get_normal" default="Vector2( 0, 1 )">
The line's normal.
</member>
</members>
diff --git a/doc/classes/Material.xml b/doc/classes/Material.xml
index ba74be330e..a0c1979646 100644
--- a/doc/classes/Material.xml
+++ b/doc/classes/Material.xml
@@ -13,7 +13,7 @@
<members>
<member name="next_pass" type="Material" setter="set_next_pass" getter="get_next_pass">
Sets the [Material] to be used for the next pass. This renders the object again using a different material.
- [b]Note:[/b] only applies to [SpatialMaterial]s and [ShaderMaterial]s with type "Spatial".
+ [b]Note:[/b] only applies to [StandardMaterial3D]s and [ShaderMaterial]s with type "Spatial".
</member>
<member name="render_priority" type="int" setter="set_render_priority" getter="get_render_priority" default="0">
Sets the render priority for transparent objects in 3D scenes. Higher priority objects will be sorted in front of lower priority objects.
diff --git a/doc/classes/Mesh.xml b/doc/classes/Mesh.xml
index 67b6045152..f2602dfc7f 100644
--- a/doc/classes/Mesh.xml
+++ b/doc/classes/Mesh.xml
@@ -103,7 +103,7 @@
</methods>
<members>
<member name="lightmap_size_hint" type="Vector2" setter="set_lightmap_size_hint" getter="get_lightmap_size_hint" default="Vector2( 0, 0 )">
- Sets a hint to be used for lightmap resolution in [BakedLightmap]. Overrides [member BakedLightmap.bake_default_texels_per_unit].
+ Sets a hint to be used for lightmap resolution.
</member>
</members>
<constants>
@@ -116,18 +116,12 @@
<constant name="PRIMITIVE_LINE_STRIP" value="2" enum="PrimitiveType">
Render array as line strip.
</constant>
- <constant name="PRIMITIVE_LINE_LOOP" value="3" enum="PrimitiveType">
- Render array as line loop (like line strip, but closed).
- </constant>
- <constant name="PRIMITIVE_TRIANGLES" value="4" enum="PrimitiveType">
+ <constant name="PRIMITIVE_TRIANGLES" value="3" enum="PrimitiveType">
Render array as triangles (every three vertices a triangle is created).
</constant>
- <constant name="PRIMITIVE_TRIANGLE_STRIP" value="5" enum="PrimitiveType">
+ <constant name="PRIMITIVE_TRIANGLE_STRIP" value="4" enum="PrimitiveType">
Render array as triangle strips.
</constant>
- <constant name="PRIMITIVE_TRIANGLE_FAN" value="6" enum="PrimitiveType">
- Render array as triangle fans.
- </constant>
<constant name="BLEND_SHAPE_MODE_NORMALIZED" value="0" enum="BlendShapeMode">
Blend shapes are normalized.
</constant>
@@ -161,9 +155,6 @@
<constant name="ARRAY_FORMAT_INDEX" value="256" enum="ArrayFormat">
Mesh array uses indices.
</constant>
- <constant name="ARRAY_COMPRESS_VERTEX" value="512" enum="ArrayFormat">
- Flag used to mark a compressed (half float) vertex array.
- </constant>
<constant name="ARRAY_COMPRESS_NORMAL" value="1024" enum="ArrayFormat">
Flag used to mark a compressed (half float) normal array.
</constant>
@@ -179,23 +170,14 @@
<constant name="ARRAY_COMPRESS_TEX_UV2" value="16384" enum="ArrayFormat">
Flag used to mark a compressed (half float) UV coordinates array for the second UV coordinates.
</constant>
- <constant name="ARRAY_COMPRESS_BONES" value="32768" enum="ArrayFormat">
- Flag used to mark a compressed bone array.
- </constant>
- <constant name="ARRAY_COMPRESS_WEIGHTS" value="65536" enum="ArrayFormat">
- Flag used to mark a compressed (half float) weight array.
- </constant>
<constant name="ARRAY_COMPRESS_INDEX" value="131072" enum="ArrayFormat">
Flag used to mark a compressed index array.
</constant>
<constant name="ARRAY_FLAG_USE_2D_VERTICES" value="262144" enum="ArrayFormat">
Flag used to mark that the array contains 2D vertices.
</constant>
- <constant name="ARRAY_FLAG_USE_16_BIT_BONES" value="524288" enum="ArrayFormat">
- Flag used to mark that the array uses 16-bit bones instead of 8-bit.
- </constant>
- <constant name="ARRAY_COMPRESS_DEFAULT" value="97280" enum="ArrayFormat">
- Used to set flags [constant ARRAY_COMPRESS_VERTEX], [constant ARRAY_COMPRESS_NORMAL], [constant ARRAY_COMPRESS_TANGENT], [constant ARRAY_COMPRESS_COLOR], [constant ARRAY_COMPRESS_TEX_UV], [constant ARRAY_COMPRESS_TEX_UV2] and [constant ARRAY_COMPRESS_WEIGHTS] quickly.
+ <constant name="ARRAY_COMPRESS_DEFAULT" value="31744" enum="ArrayFormat">
+ Used to set flags [constant ARRAY_COMPRESS_NORMAL], [constant ARRAY_COMPRESS_TANGENT], [constant ARRAY_COMPRESS_COLOR], [constant ARRAY_COMPRESS_TEX_UV] and [constant ARRAY_COMPRESS_TEX_UV2] quickly.
</constant>
<constant name="ARRAY_VERTEX" value="0" enum="ArrayType">
Array of vertices.
diff --git a/doc/classes/MeshInstance2D.xml b/doc/classes/MeshInstance2D.xml
index a14ad1d4cd..2781dd4626 100644
--- a/doc/classes/MeshInstance2D.xml
+++ b/doc/classes/MeshInstance2D.xml
@@ -15,11 +15,11 @@
<member name="mesh" type="Mesh" setter="set_mesh" getter="get_mesh">
The [Mesh] that will be drawn by the [MeshInstance2D].
</member>
- <member name="normal_map" type="Texture" setter="set_normal_map" getter="get_normal_map">
+ <member name="normal_map" type="Texture2D" setter="set_normal_map" getter="get_normal_map">
The normal map that will be used if using the default [CanvasItemMaterial].
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
- The [Texture] that will be used if using the default [CanvasItemMaterial]. Can be accessed as [code]TEXTURE[/code] in CanvasItem shader.
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ The [Texture2D] that will be used if using the default [CanvasItemMaterial]. Can be accessed as [code]TEXTURE[/code] in CanvasItem shader.
</member>
</members>
<signals>
diff --git a/doc/classes/MeshLibrary.xml b/doc/classes/MeshLibrary.xml
index 95c046398a..3a3dd08caf 100644
--- a/doc/classes/MeshLibrary.xml
+++ b/doc/classes/MeshLibrary.xml
@@ -79,13 +79,13 @@
</description>
</method>
<method name="get_item_preview" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="id" type="int">
</argument>
<description>
Returns a generated item preview (a 3D rendering in isometric perspective).
- [b]Note:[/b] Since item previews are only generated in an editor context, this function will return an empty [Texture] in a running project.
+ [b]Note:[/b] Since item previews are only generated in an editor context, this function will return an empty [Texture2D] in a running project.
</description>
</method>
<method name="get_item_shapes" qualifiers="const">
@@ -164,7 +164,7 @@
</return>
<argument index="0" name="id" type="int">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
Sets a texture to use as the item's preview icon in the editor.
diff --git a/doc/classes/MeshTexture.xml b/doc/classes/MeshTexture.xml
index 6e18517ef1..bcc9adf90f 100644
--- a/doc/classes/MeshTexture.xml
+++ b/doc/classes/MeshTexture.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="MeshTexture" inherits="Texture" version="4.0">
+<class name="MeshTexture" inherits="Texture2D" version="4.0">
<brief_description>
Simple texture that uses a mesh to draw itself.
</brief_description>
@@ -11,10 +11,9 @@
<methods>
</methods>
<members>
- <member name="base_texture" type="Texture" setter="set_base_texture" getter="get_base_texture">
+ <member name="base_texture" type="Texture2D" setter="set_base_texture" getter="get_base_texture">
Sets the base texture that the Mesh will use to draw.
</member>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="0" />
<member name="image_size" type="Vector2" setter="set_image_size" getter="get_image_size" default="Vector2( 0, 0 )">
Sets the size of the image, needed for reference.
</member>
diff --git a/doc/classes/MultiMesh.xml b/doc/classes/MultiMesh.xml
index 270ac08178..8a4a192ed4 100644
--- a/doc/classes/MultiMesh.xml
+++ b/doc/classes/MultiMesh.xml
@@ -57,17 +57,6 @@
Returns the [Transform2D] of a specific instance.
</description>
</method>
- <method name="set_as_bulk_array">
- <return type="void">
- </return>
- <argument index="0" name="array" type="PoolRealArray">
- </argument>
- <description>
- Sets all data related to the instances in one go. This is especially useful when loading the data from disk or preparing the data from GDNative.
- All data is packed in one large float array. An array may look like this: Transform for instance 1, color data for instance 1, custom data for instance 1, transform for instance 2, color data for instance 2, etc...
- [Transform] is stored as 12 floats, [Transform2D] is stored as 8 floats, [code]COLOR_8BIT[/code] / [code]CUSTOM_DATA_8BIT[/code] is stored as 1 float (4 bytes as is) and [code]COLOR_FLOAT[/code] / [code]CUSTOM_DATA_FLOAT[/code] is stored as 4 floats.
- </description>
- </method>
<method name="set_instance_color">
<return type="void">
</return>
@@ -77,7 +66,7 @@
</argument>
<description>
Sets the color of a specific instance.
- For the color to take effect, ensure that [member color_format] is non-[code]null[/code] on the [MultiMesh] and [member SpatialMaterial.vertex_color_use_as_albedo] is [code]true[/code] on the material.
+ For the color to take effect, ensure that [member use_colors] is [code]true[/code] on the [MultiMesh] and [member BaseMaterial3D.vertex_color_use_as_albedo] is [code]true[/code] on the material.
</description>
</method>
<method name="set_instance_custom_data">
@@ -88,7 +77,8 @@
<argument index="1" name="custom_data" type="Color">
</argument>
<description>
- Sets custom data for a specific instance. Although [Color] is used, it is just a container for 4 floating point numbers. The format of the number can change depending on the [enum CustomDataFormat] used.
+ Sets custom data for a specific instance. Although [Color] is used, it is just a container for 4 floating point numbers.
+ For the custom data to be used, ensure that [member use_custom_data] is [code]true[/code].
</description>
</method>
<method name="set_instance_transform">
@@ -115,11 +105,11 @@
</method>
</methods>
<members>
- <member name="color_format" type="int" setter="set_color_format" getter="get_color_format" enum="MultiMesh.ColorFormat" default="0">
- Format of colors in color array that gets passed to shader.
+ <member name="buffer" type="PoolRealArray" setter="set_buffer" getter="get_buffer" default="PoolRealArray( )">
+ </member>
+ <member name="color_array" type="PoolColorArray" setter="_set_color_array" getter="_get_color_array">
</member>
- <member name="custom_data_format" type="int" setter="set_custom_data_format" getter="get_custom_data_format" enum="MultiMesh.CustomDataFormat" default="0">
- Format of custom data in custom data array that gets passed to shader.
+ <member name="custom_data_array" type="PoolColorArray" setter="_set_custom_data_array" getter="_get_custom_data_array">
</member>
<member name="instance_count" type="int" setter="set_instance_count" getter="get_instance_count" default="0">
Number of instances that will get drawn. This clears and (re)sizes the buffers. By default, all instances are drawn but you can limit this with [member visible_instance_count].
@@ -127,9 +117,17 @@
<member name="mesh" type="Mesh" setter="set_mesh" getter="get_mesh">
Mesh to be drawn.
</member>
+ <member name="transform_2d_array" type="PoolVector2Array" setter="_set_transform_2d_array" getter="_get_transform_2d_array">
+ </member>
+ <member name="transform_array" type="PoolVector3Array" setter="_set_transform_array" getter="_get_transform_array">
+ </member>
<member name="transform_format" type="int" setter="set_transform_format" getter="get_transform_format" enum="MultiMesh.TransformFormat" default="0">
Format of transform used to transform mesh, either 2D or 3D.
</member>
+ <member name="use_colors" type="bool" setter="set_use_colors" getter="is_using_colors" default="false">
+ </member>
+ <member name="use_custom_data" type="bool" setter="set_use_custom_data" getter="is_using_custom_data" default="false">
+ </member>
<member name="visible_instance_count" type="int" setter="set_visible_instance_count" getter="get_visible_instance_count" default="-1">
Limits the number of instances drawn, -1 draws all instances. Changing this does not change the sizes of the buffers.
</member>
@@ -141,23 +139,5 @@
<constant name="TRANSFORM_3D" value="1" enum="TransformFormat">
Use this when using 3D transforms.
</constant>
- <constant name="COLOR_NONE" value="0" enum="ColorFormat">
- Use when you are not using per-instance [Color]s.
- </constant>
- <constant name="COLOR_8BIT" value="1" enum="ColorFormat">
- Compress [Color] data into 8 bits when passing to shader. This uses less memory and can be faster, but the [Color] loses precision.
- </constant>
- <constant name="COLOR_FLOAT" value="2" enum="ColorFormat">
- The [Color] passed into [method set_instance_color] will use 4 floats. Use this for highest precision [Color].
- </constant>
- <constant name="CUSTOM_DATA_NONE" value="0" enum="CustomDataFormat">
- Use when you are not using per-instance custom data.
- </constant>
- <constant name="CUSTOM_DATA_8BIT" value="1" enum="CustomDataFormat">
- Compress custom_data into 8 bits when passing to shader. This uses less memory and can be faster, but loses precision and range. Floats packed into 8 bits can only represent values between 0 and 1, numbers outside that range will be clamped.
- </constant>
- <constant name="CUSTOM_DATA_FLOAT" value="2" enum="CustomDataFormat">
- The [Color] passed into [method set_instance_custom_data] will use 4 floats. Use this for highest precision.
- </constant>
</constants>
</class>
diff --git a/doc/classes/MultiMeshInstance2D.xml b/doc/classes/MultiMeshInstance2D.xml
index 5c0e85d3fe..2fe5447a27 100644
--- a/doc/classes/MultiMeshInstance2D.xml
+++ b/doc/classes/MultiMeshInstance2D.xml
@@ -15,11 +15,11 @@
<member name="multimesh" type="MultiMesh" setter="set_multimesh" getter="get_multimesh">
The [MultiMesh] that will be drawn by the [MultiMeshInstance2D].
</member>
- <member name="normal_map" type="Texture" setter="set_normal_map" getter="get_normal_map">
+ <member name="normal_map" type="Texture2D" setter="set_normal_map" getter="get_normal_map">
The normal map that will be used if using the default [CanvasItemMaterial].
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
- The [Texture] that will be used if using the default [CanvasItemMaterial]. Can be accessed as [code]TEXTURE[/code] in CanvasItem shader.
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ The [Texture2D] that will be used if using the default [CanvasItemMaterial]. Can be accessed as [code]TEXTURE[/code] in CanvasItem shader.
</member>
</members>
<signals>
diff --git a/doc/classes/Navigation.xml b/doc/classes/Navigation.xml
index 615ccf6c36..be36be0429 100644
--- a/doc/classes/Navigation.xml
+++ b/doc/classes/Navigation.xml
@@ -4,49 +4,15 @@
Mesh-based navigation and pathfinding node.
</brief_description>
<description>
- Provides navigation and pathfinding within a collection of [NavigationMesh]es. By default, these will be automatically collected from child [NavigationMeshInstance] nodes, but they can also be added on the fly with [method navmesh_add]. In addition to basic pathfinding, this class also assists with aligning navigation agents with the meshes they are navigating on.
+ Provides navigation and pathfinding within a collection of [NavigationMesh]es. These will be automatically collected from child [NavigationMeshInstance] nodes. In addition to basic pathfinding, this class also assists with aligning navigation agents with the meshes they are navigating on.
</description>
<tutorials>
</tutorials>
<methods>
- <method name="get_closest_point">
- <return type="Vector3">
+ <method name="get_rid" qualifiers="const">
+ <return type="RID">
</return>
- <argument index="0" name="to_point" type="Vector3">
- </argument>
- <description>
- Returns the navigation point closest to the point given. Points are in local coordinate space.
- </description>
- </method>
- <method name="get_closest_point_normal">
- <return type="Vector3">
- </return>
- <argument index="0" name="to_point" type="Vector3">
- </argument>
- <description>
- Returns the surface normal at the navigation point closest to the point given. Useful for rotating a navigation agent according to the navigation mesh it moves on.
- </description>
- </method>
- <method name="get_closest_point_owner">
- <return type="Object">
- </return>
- <argument index="0" name="to_point" type="Vector3">
- </argument>
- <description>
- Returns the owner of the [NavigationMesh] which contains the navigation point closest to the point given. This is usually a [NavigationMeshInstance]. For meshes added via [method navmesh_add], returns the owner that was given (or [code]null[/code] if the [code]owner[/code] parameter was omitted).
- </description>
- </method>
- <method name="get_closest_point_to_segment">
- <return type="Vector3">
- </return>
- <argument index="0" name="start" type="Vector3">
- </argument>
- <argument index="1" name="end" type="Vector3">
- </argument>
- <argument index="2" name="use_collision" type="bool" default="false">
- </argument>
<description>
- Returns the navigation point closest to the given line segment. When enabling [code]use_collision[/code], only considers intersection points between segment and navigation meshes. If multiple intersection points are found, the one closest to the segment start point is returned.
</description>
</method>
<method name="get_simple_path">
@@ -62,41 +28,12 @@
Returns the path between two given points. Points are in local coordinate space. If [code]optimize[/code] is [code]true[/code] (the default), the agent properties associated with each [NavigationMesh] (radius, height, etc.) are considered in the path calculation, otherwise they are ignored.
</description>
</method>
- <method name="navmesh_add">
- <return type="int">
- </return>
- <argument index="0" name="mesh" type="NavigationMesh">
- </argument>
- <argument index="1" name="xform" type="Transform">
- </argument>
- <argument index="2" name="owner" type="Object" default="null">
- </argument>
- <description>
- Adds a [NavigationMesh]. Returns an ID for use with [method navmesh_remove] or [method navmesh_set_transform]. If given, a [Transform2D] is applied to the polygon. The optional [code]owner[/code] is used as return value for [method get_closest_point_owner].
- </description>
- </method>
- <method name="navmesh_remove">
- <return type="void">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
- <description>
- Removes the [NavigationMesh] with the given ID.
- </description>
- </method>
- <method name="navmesh_set_transform">
- <return type="void">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
- <argument index="1" name="xform" type="Transform">
- </argument>
- <description>
- Sets the transform applied to the [NavigationMesh] with the given ID.
- </description>
- </method>
</methods>
<members>
+ <member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="0.3">
+ </member>
+ <member name="edge_connection_margin" type="float" setter="set_edge_connection_margin" getter="get_edge_connection_margin" default="5.0">
+ </member>
<member name="up_vector" type="Vector3" setter="set_up_vector" getter="get_up_vector" default="Vector3( 0, 1, 0 )">
Defines which direction is up. By default, this is [code](0, 1, 0)[/code], which is the world's "up" direction.
</member>
diff --git a/doc/classes/Navigation2D.xml b/doc/classes/Navigation2D.xml
index ba15c59238..734469eaa9 100644
--- a/doc/classes/Navigation2D.xml
+++ b/doc/classes/Navigation2D.xml
@@ -4,27 +4,15 @@
2D navigation and pathfinding node.
</brief_description>
<description>
- Navigation2D provides navigation and pathfinding within a 2D area, specified as a collection of [NavigationPolygon] resources. By default, these are automatically collected from child [NavigationPolygonInstance] nodes, but they can also be added on the fly with [method navpoly_add].
+ Navigation2D provides navigation and pathfinding within a 2D area, specified as a collection of [NavigationPolygon] resources. These are automatically collected from child [NavigationPolygonInstance] nodes.
</description>
<tutorials>
</tutorials>
<methods>
- <method name="get_closest_point">
- <return type="Vector2">
+ <method name="get_rid" qualifiers="const">
+ <return type="RID">
</return>
- <argument index="0" name="to_point" type="Vector2">
- </argument>
- <description>
- Returns the navigation point closest to the point given. Points are in local coordinate space.
- </description>
- </method>
- <method name="get_closest_point_owner">
- <return type="Object">
- </return>
- <argument index="0" name="to_point" type="Vector2">
- </argument>
<description>
- Returns the owner of the [NavigationPolygon] which contains the navigation point closest to the point given. This is usually a [NavigationPolygonInstance]. For polygons added via [method navpoly_add], returns the owner that was given (or [code]null[/code] if the [code]owner[/code] parameter was omitted).
</description>
</method>
<method name="get_simple_path">
@@ -40,40 +28,13 @@
Returns the path between two given points. Points are in local coordinate space. If [code]optimize[/code] is [code]true[/code] (the default), the path is smoothed by merging path segments where possible.
</description>
</method>
- <method name="navpoly_add">
- <return type="int">
- </return>
- <argument index="0" name="mesh" type="NavigationPolygon">
- </argument>
- <argument index="1" name="xform" type="Transform2D">
- </argument>
- <argument index="2" name="owner" type="Object" default="null">
- </argument>
- <description>
- Adds a [NavigationPolygon]. Returns an ID for use with [method navpoly_remove] or [method navpoly_set_transform]. If given, a [Transform2D] is applied to the polygon. The optional [code]owner[/code] is used as return value for [method get_closest_point_owner].
- </description>
- </method>
- <method name="navpoly_remove">
- <return type="void">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
- <description>
- Removes the [NavigationPolygon] with the given ID.
- </description>
- </method>
- <method name="navpoly_set_transform">
- <return type="void">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
- <argument index="1" name="xform" type="Transform2D">
- </argument>
- <description>
- Sets the transform applied to the [NavigationPolygon] with the given ID.
- </description>
- </method>
</methods>
+ <members>
+ <member name="cell_size" type="float" setter="set_cell_size" getter="get_cell_size" default="10.0">
+ </member>
+ <member name="edge_connection_margin" type="float" setter="set_edge_connection_margin" getter="get_edge_connection_margin" default="100.0">
+ </member>
+ </members>
<constants>
</constants>
</class>
diff --git a/doc/classes/Navigation2DServer.xml b/doc/classes/Navigation2DServer.xml
index 105d6aabf8..3950e35697 100644
--- a/doc/classes/Navigation2DServer.xml
+++ b/doc/classes/Navigation2DServer.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="Navigation2DServer" inherits="Object" category="Core" version="3.2">
+<class name="Navigation2DServer" inherits="Object" version="4.0">
<brief_description>
Server interface for low-level 2D navigation access
</brief_description>
@@ -16,8 +16,8 @@
Creates the agent.
</description>
</method>
- <method name="agent_is_map_changed">
- <return type="bool" qualifiers="const">
+ <method name="agent_is_map_changed" qualifiers="const">
+ <return type="bool">
</return>
<argument index="0" name="agent" type="RID">
</argument>
@@ -89,7 +89,7 @@
</return>
<argument index="0" name="agent" type="RID">
</argument>
- <argument index="1" name="position" type="Vector3">
+ <argument index="1" name="position" type="Vector2">
</argument>
<description>
Sets the position of the agent in world space.
@@ -111,7 +111,7 @@
</return>
<argument index="0" name="agent" type="RID">
</argument>
- <argument index="1" name="target_velocity" type="Vector3">
+ <argument index="1" name="target_velocity" type="Vector2">
</argument>
<description>
Sets the new target velocity.
@@ -133,7 +133,7 @@
</return>
<argument index="0" name="agent" type="RID">
</argument>
- <argument index="1" name="velocity" type="Vector3">
+ <argument index="1" name="velocity" type="Vector2">
</argument>
<description>
Sets the current velocity of the agent.
@@ -155,7 +155,7 @@
Create a new map.
</description>
</method>
- <method name="map_get_cell_size">
+ <method name="map_get_cell_size" qualifiers="const">
<return type="float">
</return>
<argument index="0" name="map" type="RID">
@@ -191,7 +191,7 @@
<method name="map_is_active" qualifiers="const">
<return type="bool">
</return>
- <argument index="0" name="map" type="RID">
+ <argument index="0" name="nap" type="RID">
</argument>
<description>
Returns true if the map is active.
@@ -264,11 +264,13 @@
</return>
<argument index="0" name="region" type="RID">
</argument>
- <argument index="1" name="transform" type="Transform">
+ <argument index="1" name="transform" type="Transform2D">
</argument>
<description>
Sets the global transformation for the region.
</description>
</method>
</methods>
+ <constants>
+ </constants>
</class>
diff --git a/doc/classes/NavigationAgent.xml b/doc/classes/NavigationAgent.xml
index d0e2a60fbf..dc759bc72b 100644
--- a/doc/classes/NavigationAgent.xml
+++ b/doc/classes/NavigationAgent.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="NavigationAgent" inherits="Node" category="Core" version="3.2">
+<class name="NavigationAgent" inherits="Node" version="4.0">
<brief_description>
3D Agent used in navigation for collision avoidance.
</brief_description>
@@ -108,32 +108,32 @@
</method>
</methods>
<members>
- <member name="target_desired_distance" type="float" setter="set_target_desired_distance" getter="get_target_desired_distance" default="1.0">
- The distance threshold before a target is considered to be reached. This will allow an agent to not have to hit a point on the path exactly, but in the area.
- </member>
- <member name="radius" type="float" setter="set_radius" getter="get_radius" default="1.0">
- The radius of the agent.
- </member>
<member name="agent_height_offset" type="float" setter="set_agent_height_offset" getter="get_agent_height_offset" default="0.0">
The agent height offset to match the navigation mesh height.
</member>
- <member name="neighbor_dist" type="float" setter="set_neighbor_dist" getter="get_neighbor_dist" default="50.0">
- The distance to search for other agents.
+ <member name="ignore_y" type="bool" setter="set_ignore_y" getter="get_ignore_y" default="true">
+ Ignores collisions on the Y axis. Must be true to move on a horizontal plane.
</member>
<member name="max_neighbors" type="int" setter="set_max_neighbors" getter="get_max_neighbors" default="10">
The maximum number of neighbors for the agent to consider.
</member>
- <member name="time_horizon" type="float" setter="set_time_horizon" getter="get_time_horizon" default="5.0">
- The minimal amount of time for which this agent's velocities, that are computed with the collision avoidance algorithim, are safe with respect to other agents. The larger the number, the sooner the agent will respond to other agents, but less freedom in choosing its velocities. Must be positive.
- </member>
<member name="max_speed" type="float" setter="set_max_speed" getter="get_max_speed" default="10.0">
The maximum speed that an agent can move.
</member>
+ <member name="neighbor_dist" type="float" setter="set_neighbor_dist" getter="get_neighbor_dist" default="50.0">
+ The distance to search for other agents.
+ </member>
<member name="path_max_distance" type="float" setter="set_path_max_distance" getter="get_path_max_distance" default="3.0">
The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceded, it recalculates the ideal path.
</member>
- <member name="ignore_y" type="bool" setter="set_ignore_y" getter="get_ignore_y" default="true">
- Ignores collisions on the Y axis. Must be true to move on a horizontal plane.
+ <member name="radius" type="float" setter="set_radius" getter="get_radius" default="1.0">
+ The radius of the agent.
+ </member>
+ <member name="target_desired_distance" type="float" setter="set_target_desired_distance" getter="get_target_desired_distance" default="1.0">
+ The distance threshold before a target is considered to be reached. This will allow an agent to not have to hit a point on the path exactly, but in the area.
+ </member>
+ <member name="time_horizon" type="float" setter="set_time_horizon" getter="get_time_horizon" default="5.0">
+ The minimal amount of time for which this agent's velocities, that are computed with the collision avoidance algorithim, are safe with respect to other agents. The larger the number, the sooner the agent will respond to other agents, but less freedom in choosing its velocities. Must be positive.
</member>
</members>
<signals>
@@ -149,15 +149,17 @@
</signal>
<signal name="target_reached">
<description>
- Notifies when the player defined target, set with [method set_target_location], is reached.
+ Notifies when the player defined target, set with [method set_target_location], is reached.
</description>
</signal>
<signal name="velocity_computed">
- <argument index="0" name="safe_velocity" type="Vector2">
+ <argument index="0" name="safe_velocity" type="Vector3">
</argument>
<description>
Notifies when the collision avoidance velocity is calculated. Emitted by [method set_velocity].
</description>
</signal>
</signals>
+ <constants>
+ </constants>
</class>
diff --git a/doc/classes/NavigationAgent2D.xml b/doc/classes/NavigationAgent2D.xml
index dd3a8aa011..6f356e7e4c 100644
--- a/doc/classes/NavigationAgent2D.xml
+++ b/doc/classes/NavigationAgent2D.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="NavigationAgent2D" inherits="Node" category="Core" version="3.2">
+<class name="NavigationAgent2D" inherits="Node" version="4.0">
<brief_description>
2D Agent used in navigation for collision avoidance.
</brief_description>
@@ -108,27 +108,27 @@
</method>
</methods>
<members>
- <member name="target_desired_distance" type="float" setter="set_target_desired_distance" getter="get_target_desired_distance" default="1.0">
- The distance threshold before a target is considered to be reached. This will allow an agent to not have to hit a point on the path exactly, but in the area.
- </member>
- <member name="radius" type="float" setter="set_radius" getter="get_radius" default="10.0">
- The radius of the agent.
- </member>
- <member name="neighbor_dist" type="float" setter="set_neighbor_dist" getter="get_neighbor_dist" default="500.0">
- The distance to search for other agents.
- </member>
<member name="max_neighbors" type="int" setter="set_max_neighbors" getter="get_max_neighbors" default="10">
The maximum number of neighbors for the agent to consider.
</member>
- <member name="time_horizon" type="float" setter="set_time_horizon" getter="get_time_horizon" default="20.0">
- The minimal amount of time for which this agent's velocities, that are computed with the collision avoidance algorithim, are safe with respect to other agents. The larger the number, the sooner the agent will respond to other agents, but less freedom in choosing its velocities. Must be positive.
- </member>
<member name="max_speed" type="float" setter="set_max_speed" getter="get_max_speed" default="200.0">
The maximum speed that an agent can move.
</member>
+ <member name="neighbor_dist" type="float" setter="set_neighbor_dist" getter="get_neighbor_dist" default="500.0">
+ The distance to search for other agents.
+ </member>
<member name="path_max_distance" type="float" setter="set_path_max_distance" getter="get_path_max_distance" default="3.0">
The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceded, it recalculates the ideal path.
</member>
+ <member name="radius" type="float" setter="set_radius" getter="get_radius" default="10.0">
+ The radius of the agent.
+ </member>
+ <member name="target_desired_distance" type="float" setter="set_target_desired_distance" getter="get_target_desired_distance" default="1.0">
+ The distance threshold before a target is considered to be reached. This will allow an agent to not have to hit a point on the path exactly, but in the area.
+ </member>
+ <member name="time_horizon" type="float" setter="set_time_horizon" getter="get_time_horizon" default="20.0">
+ The minimal amount of time for which this agent's velocities, that are computed with the collision avoidance algorithim, are safe with respect to other agents. The larger the number, the sooner the agent will respond to other agents, but less freedom in choosing its velocities. Must be positive.
+ </member>
</members>
<signals>
<signal name="navigation_finished">
@@ -143,15 +143,17 @@
</signal>
<signal name="target_reached">
<description>
- Notifies when the player defined target, set with [method set_target_location], is reached.
+ Notifies when the player defined target, set with [method set_target_location], is reached.
</description>
</signal>
<signal name="velocity_computed">
- <argument index="0" name="safe_velocity" type="Vector2">
+ <argument index="0" name="safe_velocity" type="Vector3">
</argument>
<description>
Notifies when the collision avoidance velocity is calculated. Emitted by [method set_velocity].
</description>
</signal>
</signals>
+ <constants>
+ </constants>
</class>
diff --git a/doc/classes/EditorNavigationMeshGenerator.xml b/doc/classes/NavigationMeshGenerator.xml
index 1201b6cca1..ce1182ffbe 100644
--- a/doc/classes/EditorNavigationMeshGenerator.xml
+++ b/doc/classes/NavigationMeshGenerator.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="EditorNavigationMeshGenerator" inherits="Object" version="4.0">
+<class name="NavigationMeshGenerator" inherits="Object" version="4.0">
<brief_description>
</brief_description>
<description>
diff --git a/doc/classes/NavigationObstacle.xml b/doc/classes/NavigationObstacle.xml
index 307538b77b..31cf01793a 100644
--- a/doc/classes/NavigationObstacle.xml
+++ b/doc/classes/NavigationObstacle.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="NavigationObstacle" inherits="Node" category="Core" version="3.2">
+<class name="NavigationObstacle" inherits="Node" version="4.0">
<brief_description>
3D Obstacle used in navigation for collision avoidance.
</brief_description>
@@ -26,4 +26,6 @@
</description>
</method>
</methods>
+ <constants>
+ </constants>
</class>
diff --git a/doc/classes/NavigationObstacle2D.xml b/doc/classes/NavigationObstacle2D.xml
index cf5dd2fa10..4d12b985e0 100644
--- a/doc/classes/NavigationObstacle2D.xml
+++ b/doc/classes/NavigationObstacle2D.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="NavigationObstacle2D" inherits="Node" category="Core" version="3.2">
+<class name="NavigationObstacle2D" inherits="Node" version="4.0">
<brief_description>
2D Obstacle used in navigation for collision avoidance.
</brief_description>
@@ -26,4 +26,6 @@
</description>
</method>
</methods>
+ <constants>
+ </constants>
</class>
diff --git a/doc/classes/NavigationServer.xml b/doc/classes/NavigationServer.xml
index 894a46b8a7..7553d700f8 100644
--- a/doc/classes/NavigationServer.xml
+++ b/doc/classes/NavigationServer.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="NavigationServer" inherits="Object" category="Core" version="3.2">
+<class name="NavigationServer" inherits="Object" version="4.0">
<brief_description>
Server interface for low-level 3D navigation access
</brief_description>
@@ -16,8 +16,8 @@
Creates the agent.
</description>
</method>
- <method name="agent_is_map_changed">
- <return type="bool" qualifiers="const">
+ <method name="agent_is_map_changed" qualifiers="const">
+ <return type="bool">
</return>
<argument index="0" name="agent" type="RID">
</argument>
@@ -155,7 +155,7 @@
Create a new map.
</description>
</method>
- <method name="map_get_cell_size">
+ <method name="map_get_cell_size" qualifiers="const">
<return type="float">
</return>
<argument index="0" name="map" type="RID">
@@ -200,7 +200,7 @@
<method name="map_is_active" qualifiers="const">
<return type="bool">
</return>
- <argument index="0" name="map" type="RID">
+ <argument index="0" name="nap" type="RID">
</argument>
<description>
Returns true if the map is active.
@@ -320,4 +320,6 @@
</description>
</method>
</methods>
+ <constants>
+ </constants>
</class>
diff --git a/doc/classes/NinePatchRect.xml b/doc/classes/NinePatchRect.xml
index 68326d7e77..9c3acc9b0a 100644
--- a/doc/classes/NinePatchRect.xml
+++ b/doc/classes/NinePatchRect.xml
@@ -56,7 +56,7 @@
<member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2( 0, 0, 0, 0 )">
Rectangular region of the texture to sample from. If you're working with an atlas, use this property to define the area the 9-slice should use. All other properties are relative to this one. If the rect is empty, NinePatchRect will use the whole texture.
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
The node's texture resource.
</member>
</members>
diff --git a/doc/classes/ORMMaterial3D.xml b/doc/classes/ORMMaterial3D.xml
new file mode 100644
index 0000000000..d275f93196
--- /dev/null
+++ b/doc/classes/ORMMaterial3D.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="ORMMaterial3D" inherits="BaseMaterial3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/OmniLight.xml b/doc/classes/OmniLight.xml
index e836dc1758..dc57efd3f9 100644
--- a/doc/classes/OmniLight.xml
+++ b/doc/classes/OmniLight.xml
@@ -18,9 +18,6 @@
<member name="omni_range" type="float" setter="set_param" getter="get_param" default="5.0">
The light's radius.
</member>
- <member name="omni_shadow_detail" type="int" setter="set_shadow_detail" getter="get_shadow_detail" enum="OmniLight.ShadowDetail" default="1">
- See [enum ShadowDetail].
- </member>
<member name="omni_shadow_mode" type="int" setter="set_shadow_mode" getter="get_shadow_mode" enum="OmniLight.ShadowMode" default="1">
See [enum ShadowMode].
</member>
@@ -32,11 +29,5 @@
<constant name="SHADOW_CUBE" value="1" enum="ShadowMode">
Shadows are rendered to a cubemap. Slower than [constant SHADOW_DUAL_PARABOLOID], but higher-quality.
</constant>
- <constant name="SHADOW_DETAIL_VERTICAL" value="0" enum="ShadowDetail">
- Use more detail vertically when computing the shadow.
- </constant>
- <constant name="SHADOW_DETAIL_HORIZONTAL" value="1" enum="ShadowDetail">
- Use more detail horizontally when computing the shadow.
- </constant>
</constants>
</class>
diff --git a/doc/classes/OptionButton.xml b/doc/classes/OptionButton.xml
index d488e918b9..5cb2aaf314 100644
--- a/doc/classes/OptionButton.xml
+++ b/doc/classes/OptionButton.xml
@@ -12,7 +12,7 @@
<method name="add_icon_item">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="label" type="String">
</argument>
@@ -55,7 +55,7 @@
</description>
</method>
<method name="get_item_icon" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="idx" type="int">
</argument>
@@ -164,7 +164,7 @@
</return>
<argument index="0" name="idx" type="int">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
Sets the icon of the item at index [code]idx[/code].
@@ -231,7 +231,7 @@
<constants>
</constants>
<theme_items>
- <theme_item name="arrow" type="Texture">
+ <theme_item name="arrow" type="Texture2D">
The arrow icon to be drawn on the right end of the button.
</theme_item>
<theme_item name="arrow_margin" type="int" default="2">
diff --git a/doc/classes/PanoramaSky.xml b/doc/classes/PanoramaSky.xml
index c1c048f875..c600a4425b 100644
--- a/doc/classes/PanoramaSky.xml
+++ b/doc/classes/PanoramaSky.xml
@@ -11,8 +11,8 @@
<methods>
</methods>
<members>
- <member name="panorama" type="Texture" setter="set_panorama" getter="get_panorama">
- [Texture] to be applied to the PanoramaSky.
+ <member name="panorama" type="Texture2D" setter="set_panorama" getter="get_panorama">
+ [Texture2D] to be applied to the PanoramaSky.
</member>
</members>
<constants>
diff --git a/doc/classes/ParallaxLayer.xml b/doc/classes/ParallaxLayer.xml
index 105d105731..7210bee11c 100644
--- a/doc/classes/ParallaxLayer.xml
+++ b/doc/classes/ParallaxLayer.xml
@@ -14,7 +14,7 @@
</methods>
<members>
<member name="motion_mirroring" type="Vector2" setter="set_mirroring" getter="get_mirroring" default="Vector2( 0, 0 )">
- The ParallaxLayer's [Texture] mirroring. Useful for creating an infinite scrolling background. If an axis is set to [code]0[/code], the [Texture] will not be mirrored.
+ The ParallaxLayer's [Texture2D] mirroring. Useful for creating an infinite scrolling background. If an axis is set to [code]0[/code], the [Texture2D] will not be mirrored.
</member>
<member name="motion_offset" type="Vector2" setter="set_motion_offset" getter="get_motion_offset" default="Vector2( 0, 0 )">
The ParallaxLayer's offset relative to the parent ParallaxBackground's [member ParallaxBackground.scroll_offset].
diff --git a/doc/classes/Particles.xml b/doc/classes/Particles.xml
index b146678bfc..74651ddd2f 100644
--- a/doc/classes/Particles.xml
+++ b/doc/classes/Particles.xml
@@ -68,7 +68,7 @@
<member name="draw_passes" type="int" setter="set_draw_passes" getter="get_draw_passes" default="1">
The number of draw passes when rendering particles.
</member>
- <member name="emitting" type="bool" setter="set_emitting" getter="is_emitting" default="true">
+ <member name="emitting" type="bool" setter="set_emitting" getter="is_emitting" default="false">
If [code]true[/code], particles are being emitted.
</member>
<member name="explosiveness" type="float" setter="set_explosiveness_ratio" getter="get_explosiveness_ratio" default="0.0">
diff --git a/doc/classes/Particles2D.xml b/doc/classes/Particles2D.xml
index 2a00ec3113..50fc3680bc 100644
--- a/doc/classes/Particles2D.xml
+++ b/doc/classes/Particles2D.xml
@@ -33,7 +33,7 @@
<member name="draw_order" type="int" setter="set_draw_order" getter="get_draw_order" enum="Particles2D.DrawOrder" default="0">
Particle draw order. Uses [enum DrawOrder] values.
</member>
- <member name="emitting" type="bool" setter="set_emitting" getter="is_emitting" default="true">
+ <member name="emitting" type="bool" setter="set_emitting" getter="is_emitting" default="false">
If [code]true[/code], particles are being emitted.
</member>
<member name="explosiveness" type="float" setter="set_explosiveness_ratio" getter="get_explosiveness_ratio" default="0.0">
@@ -51,7 +51,7 @@
<member name="local_coords" type="bool" setter="set_use_local_coordinates" getter="get_use_local_coordinates" default="true">
If [code]true[/code], particles use the parent node's coordinate space. If [code]false[/code], they use global coordinates.
</member>
- <member name="normal_map" type="Texture" setter="set_normal_map" getter="get_normal_map">
+ <member name="normal_map" type="Texture2D" setter="set_normal_map" getter="get_normal_map">
Normal map to be used for the [member texture] property.
</member>
<member name="one_shot" type="bool" setter="set_one_shot" getter="get_one_shot" default="false">
@@ -69,7 +69,7 @@
<member name="speed_scale" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0">
Particle system's running speed scaling ratio. A value of [code]0[/code] can be used to pause the particles.
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
Particle texture. If [code]null[/code], particles will be squares.
</member>
<member name="visibility_rect" type="Rect2" setter="set_visibility_rect" getter="get_visibility_rect" default="Rect2( -100, -100, 200, 200 )">
diff --git a/doc/classes/ParticlesMaterial.xml b/doc/classes/ParticlesMaterial.xml
index 42f0fe1f00..1e90214e47 100644
--- a/doc/classes/ParticlesMaterial.xml
+++ b/doc/classes/ParticlesMaterial.xml
@@ -39,12 +39,12 @@
</description>
</method>
<method name="get_param_texture" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="param" type="int" enum="ParticlesMaterial.Parameter">
</argument>
<description>
- Returns the [Texture] used by the specified parameter.
+ Returns the [Texture2D] used by the specified parameter.
</description>
</method>
<method name="set_flag">
@@ -85,19 +85,19 @@
</return>
<argument index="0" name="param" type="int" enum="ParticlesMaterial.Parameter">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
- Sets the [Texture] for the specified [enum Parameter].
+ Sets the [Texture2D] for the specified [enum Parameter].
</description>
</method>
</methods>
<members>
<member name="angle" type="float" setter="set_param" getter="get_param" default="0.0">
Initial rotation applied to each particle, in degrees.
- Only applied when [member flag_disable_z] or [member flag_rotate_y] are [code]true[/code] or the [SpatialMaterial] being used to draw the particle is using [constant SpatialMaterial.BILLBOARD_PARTICLES].
+ Only applied when [member flag_disable_z] or [member flag_rotate_y] are [code]true[/code] or the [BaseMaterial3D] being used to draw the particle is using [constant BaseMaterial3D.BILLBOARD_PARTICLES].
</member>
- <member name="angle_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="angle_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's rotation will be animated along this [CurveTexture].
</member>
<member name="angle_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
@@ -105,9 +105,9 @@
</member>
<member name="angular_velocity" type="float" setter="set_param" getter="get_param" default="0.0">
Initial angular velocity applied to each particle. Sets the speed of rotation of the particle.
- Only applied when [member flag_disable_z] or [member flag_rotate_y] are [code]true[/code] or the [SpatialMaterial] being used to draw the particle is using [constant SpatialMaterial.BILLBOARD_PARTICLES].
+ Only applied when [member flag_disable_z] or [member flag_rotate_y] are [code]true[/code] or the [BaseMaterial3D] being used to draw the particle is using [constant BaseMaterial3D.BILLBOARD_PARTICLES].
</member>
- <member name="angular_velocity_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="angular_velocity_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's angular velocity will vary along this [CurveTexture].
</member>
<member name="angular_velocity_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
@@ -116,7 +116,7 @@
<member name="anim_offset" type="float" setter="set_param" getter="get_param" default="0.0">
Particle animation offset.
</member>
- <member name="anim_offset_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="anim_offset_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's animation offset will vary along this [CurveTexture].
</member>
<member name="anim_offset_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
@@ -125,22 +125,22 @@
<member name="anim_speed" type="float" setter="set_param" getter="get_param" default="0.0">
Particle animation speed.
</member>
- <member name="anim_speed_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="anim_speed_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's animation speed will vary along this [CurveTexture].
</member>
<member name="anim_speed_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
Animation speed randomness ratio.
</member>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 1, 1, 1, 1 )">
- Each particle's initial color. If the [Particles2D]'s [code]texture[/code] is defined, it will be multiplied by this color. To have particle display color in a [SpatialMaterial] make sure to set [member SpatialMaterial.vertex_color_use_as_albedo] to [code]true[/code].
+ Each particle's initial color. If the [Particles2D]'s [code]texture[/code] is defined, it will be multiplied by this color. To have particle display color in a [BaseMaterial3D] make sure to set [member BaseMaterial3D.vertex_color_use_as_albedo] to [code]true[/code].
</member>
- <member name="color_ramp" type="Texture" setter="set_color_ramp" getter="get_color_ramp">
+ <member name="color_ramp" type="Texture2D" setter="set_color_ramp" getter="get_color_ramp">
Each particle's color will vary along this [GradientTexture].
</member>
<member name="damping" type="float" setter="set_param" getter="get_param" default="0.0">
The rate at which particles lose velocity.
</member>
- <member name="damping_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="damping_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Damping will vary along this [CurveTexture].
</member>
<member name="damping_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
@@ -152,16 +152,16 @@
<member name="emission_box_extents" type="Vector3" setter="set_emission_box_extents" getter="get_emission_box_extents">
The box's extents if [code]emission_shape[/code] is set to [constant EMISSION_SHAPE_BOX].
</member>
- <member name="emission_color_texture" type="Texture" setter="set_emission_color_texture" getter="get_emission_color_texture">
+ <member name="emission_color_texture" type="Texture2D" setter="set_emission_color_texture" getter="get_emission_color_texture">
Particle color will be modulated by color determined by sampling this texture at the same point as the [member emission_point_texture].
</member>
- <member name="emission_normal_texture" type="Texture" setter="set_emission_normal_texture" getter="get_emission_normal_texture">
+ <member name="emission_normal_texture" type="Texture2D" setter="set_emission_normal_texture" getter="get_emission_normal_texture">
Particle velocity and rotation will be set by sampling this texture at the same point as the [member emission_point_texture]. Used only in [constant EMISSION_SHAPE_DIRECTED_POINTS]. Can be created automatically from mesh or node by selecting "Create Emission Points from Mesh/Node" under the "Particles" tool in the toolbar.
</member>
<member name="emission_point_count" type="int" setter="set_emission_point_count" getter="get_emission_point_count">
The number of emission points if [code]emission_shape[/code] is set to [constant EMISSION_SHAPE_POINTS] or [constant EMISSION_SHAPE_DIRECTED_POINTS].
</member>
- <member name="emission_point_texture" type="Texture" setter="set_emission_point_texture" getter="get_emission_point_texture">
+ <member name="emission_point_texture" type="Texture2D" setter="set_emission_point_texture" getter="get_emission_point_texture">
Particles will be emitted at positions determined by sampling this texture at a random position. Used with [constant EMISSION_SHAPE_POINTS] and [constant EMISSION_SHAPE_DIRECTED_POINTS]. Can be created automatically from mesh or node by selecting "Create Emission Points from Mesh/Node" under the "Particles" tool in the toolbar.
</member>
<member name="emission_shape" type="int" setter="set_emission_shape" getter="get_emission_shape" enum="ParticlesMaterial.EmissionShape" default="0">
@@ -188,7 +188,7 @@
<member name="hue_variation" type="float" setter="set_param" getter="get_param" default="0.0">
Initial hue variation applied to each particle.
</member>
- <member name="hue_variation_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="hue_variation_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's hue will vary along this [CurveTexture].
</member>
<member name="hue_variation_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
@@ -206,7 +206,7 @@
<member name="linear_accel" type="float" setter="set_param" getter="get_param" default="0.0">
Linear acceleration applied to each particle in the direction of motion.
</member>
- <member name="linear_accel_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="linear_accel_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's linear acceleration will vary along this [CurveTexture].
</member>
<member name="linear_accel_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
@@ -216,7 +216,7 @@
Orbital velocity applied to each particle. Makes the particles circle around origin. Specified in number of full rotations around origin per second.
Only available when [member flag_disable_z] is [code]true[/code].
</member>
- <member name="orbit_velocity_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="orbit_velocity_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's orbital velocity will vary along this [CurveTexture].
</member>
<member name="orbit_velocity_random" type="float" setter="set_param_randomness" getter="get_param_randomness">
@@ -225,7 +225,7 @@
<member name="radial_accel" type="float" setter="set_param" getter="get_param" default="0.0">
Radial acceleration applied to each particle. Makes particle accelerate away from origin.
</member>
- <member name="radial_accel_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="radial_accel_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's radial acceleration will vary along this [CurveTexture].
</member>
<member name="radial_accel_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
@@ -234,7 +234,7 @@
<member name="scale" type="float" setter="set_param" getter="get_param" default="1.0">
Initial scale applied to each particle.
</member>
- <member name="scale_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="scale_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's scale will vary along this [CurveTexture].
</member>
<member name="scale_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
@@ -246,7 +246,7 @@
<member name="tangential_accel" type="float" setter="set_param" getter="get_param" default="0.0">
Tangential acceleration applied to each particle. Tangential acceleration is perpendicular to the particle's velocity giving the particles a swirling motion.
</member>
- <member name="tangential_accel_curve" type="Texture" setter="set_param_texture" getter="get_param_texture">
+ <member name="tangential_accel_curve" type="Texture2D" setter="set_param_texture" getter="get_param_texture">
Each particle's tangential acceleration will vary along this [CurveTexture].
</member>
<member name="tangential_accel_random" type="float" setter="set_param_randomness" getter="get_param_randomness" default="0.0">
diff --git a/doc/classes/PhysicalBone.xml b/doc/classes/PhysicalBone.xml
index cef41aac5c..bb31f03c18 100644
--- a/doc/classes/PhysicalBone.xml
+++ b/doc/classes/PhysicalBone.xml
@@ -43,12 +43,6 @@
<description>
</description>
</method>
- <method name="is_static_body">
- <return type="bool">
- </return>
- <description>
- </description>
- </method>
</methods>
<members>
<member name="body_offset" type="Transform" setter="set_body_offset" getter="get_body_offset" default="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )">
diff --git a/doc/classes/PointMesh.xml b/doc/classes/PointMesh.xml
index af100d5206..266ab2a898 100644
--- a/doc/classes/PointMesh.xml
+++ b/doc/classes/PointMesh.xml
@@ -5,7 +5,7 @@
</brief_description>
<description>
The PointMesh is made from a single point. Instead of relying on triangles, points are rendered as a single rectangle on the screen with a constant size. They are intended to be used with Particle systems, but can be used as a cheap way to render constant size billboarded sprites (for example in a point cloud).
- PointMeshes, must be used with a material that has a point size. Point size can be accessed in a shader with [code]POINT_SIZE[/code], or in a [SpatialMaterial] by setting [member SpatialMaterial.flags_use_point_size] and the variable [member SpatialMaterial.params_point_size].
+ PointMeshes, must be used with a material that has a point size. Point size can be accessed in a shader with [code]POINT_SIZE[/code], or in a [BaseMaterial3D] by setting [member BaseMaterial3D.use_point_size] and the variable [member BaseMaterial3D.point_size].
When using PointMeshes, properties that normally alter vertices will be ignored, including billboard mode, grow, and cull face.
</description>
<tutorials>
diff --git a/doc/classes/Polygon2D.xml b/doc/classes/Polygon2D.xml
index e911ed7664..af4e8e1671 100644
--- a/doc/classes/Polygon2D.xml
+++ b/doc/classes/Polygon2D.xml
@@ -5,7 +5,6 @@
</brief_description>
<description>
A Polygon2D is defined by a set of points. Each point is connected to the next, with the final point being connected to the first, resulting in a closed polygon. Polygon2Ds can be filled with color (solid or gradient) or filled with a given texture.
- [b]Note:[/b] By default, Godot can only draw up to 4,096 polygon points at a time. To increase this limit, open the Project Settings and increase [member ProjectSettings.rendering/limits/buffers/canvas_polygon_buffer_size_kb] and [member ProjectSettings.rendering/limits/buffers/canvas_polygon_index_buffer_size_kb].
</description>
<tutorials>
</tutorials>
@@ -94,6 +93,8 @@
<member name="invert_enable" type="bool" setter="set_invert" getter="get_invert" default="false">
If [code]true[/code], polygon will be inverted, containing the area outside the defined points and extending to the [code]invert_border[/code].
</member>
+ <member name="normal_map" type="Texture2D" setter="set_normal_map" getter="get_normal_map">
+ </member>
<member name="offset" type="Vector2" setter="set_offset" getter="get_offset" default="Vector2( 0, 0 )">
The offset applied to each vertex.
</member>
@@ -103,9 +104,15 @@
</member>
<member name="polygons" type="Array" setter="set_polygons" getter="get_polygons" default="[ ]">
</member>
+ <member name="shininess" type="float" setter="set_shininess" getter="get_shininess" default="1.0">
+ </member>
<member name="skeleton" type="NodePath" setter="set_skeleton" getter="get_skeleton" default="NodePath(&quot;&quot;)">
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
+ <member name="specular_color" type="Color" setter="set_specular_color" getter="get_specular_color" default="Color( 1, 1, 1, 1 )">
+ </member>
+ <member name="specular_map" type="Texture2D" setter="set_specular_map" getter="get_specular_map">
+ </member>
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
The polygon's fill texture. Use [code]uv[/code] to set texture coordinates.
</member>
<member name="texture_offset" type="Vector2" setter="set_texture_offset" getter="get_texture_offset" default="Vector2( 0, 0 )">
diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml
index 31ab27628a..8dda33f624 100644
--- a/doc/classes/PopupMenu.xml
+++ b/doc/classes/PopupMenu.xml
@@ -42,7 +42,7 @@
<method name="add_icon_check_item">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="label" type="String">
</argument>
@@ -59,7 +59,7 @@
<method name="add_icon_check_shortcut">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="shortcut" type="ShortCut">
</argument>
@@ -76,7 +76,7 @@
<method name="add_icon_item">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="label" type="String">
</argument>
@@ -92,7 +92,7 @@
<method name="add_icon_radio_check_item">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="label" type="String">
</argument>
@@ -107,7 +107,7 @@
<method name="add_icon_radio_check_shortcut">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="shortcut" type="ShortCut">
</argument>
@@ -122,7 +122,7 @@
<method name="add_icon_shortcut">
<return type="void">
</return>
- <argument index="0" name="texture" type="Texture">
+ <argument index="0" name="texture" type="Texture2D">
</argument>
<argument index="1" name="shortcut" type="ShortCut">
</argument>
@@ -259,7 +259,7 @@
</description>
</method>
<method name="get_item_icon" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="idx" type="int">
</argument>
@@ -485,10 +485,10 @@
</return>
<argument index="0" name="idx" type="int">
</argument>
- <argument index="1" name="icon" type="Texture">
+ <argument index="1" name="icon" type="Texture2D">
</argument>
<description>
- Replaces the [Texture] icon of the specified [code]idx[/code].
+ Replaces the [Texture2D] icon of the specified [code]idx[/code].
</description>
</method>
<method name="set_item_id">
@@ -644,8 +644,8 @@
<constants>
</constants>
<theme_items>
- <theme_item name="checked" type="Texture">
- [Texture] icon for the checked checkbox items.
+ <theme_item name="checked" type="Texture2D">
+ [Texture2D] icon for the checked checkbox items.
</theme_item>
<theme_item name="font" type="Font">
[Font] used for the menu items.
@@ -680,20 +680,20 @@
<theme_item name="panel_disabled" type="StyleBox">
[StyleBox] used when the [PopupMenu] item is disabled.
</theme_item>
- <theme_item name="radio_checked" type="Texture">
- [Texture] icon for the checked radio button items.
+ <theme_item name="radio_checked" type="Texture2D">
+ [Texture2D] icon for the checked radio button items.
</theme_item>
- <theme_item name="radio_unchecked" type="Texture">
- [Texture] icon for the unchecked radio button items.
+ <theme_item name="radio_unchecked" type="Texture2D">
+ [Texture2D] icon for the unchecked radio button items.
</theme_item>
<theme_item name="separator" type="StyleBox">
[StyleBox] used for the separators. See [method add_separator].
</theme_item>
- <theme_item name="submenu" type="Texture">
- [Texture] icon for the submenu arrow.
+ <theme_item name="submenu" type="Texture2D">
+ [Texture2D] icon for the submenu arrow.
</theme_item>
- <theme_item name="unchecked" type="Texture">
- [Texture] icon for the unchecked checkbox items.
+ <theme_item name="unchecked" type="Texture2D">
+ [Texture2D] icon for the unchecked checkbox items.
</theme_item>
<theme_item name="vseparation" type="int" default="4">
The vertical space between each menu item.
diff --git a/doc/classes/PrimitiveMesh.xml b/doc/classes/PrimitiveMesh.xml
index ea84860632..77915bc538 100644
--- a/doc/classes/PrimitiveMesh.xml
+++ b/doc/classes/PrimitiveMesh.xml
@@ -23,7 +23,7 @@
</member>
<member name="flip_faces" type="bool" setter="set_flip_faces" getter="get_flip_faces" default="false">
If set, the order of the vertices in each triangle are reversed resulting in the backside of the mesh being drawn.
- This gives the same result as using [constant SpatialMaterial.CULL_BACK] in [member SpatialMaterial.params_cull_mode].
+ This gives the same result as using [constant BaseMaterial3D.CULL_BACK] in [member BaseMaterial3D.cull_mode].
</member>
<member name="material" type="Material" setter="set_material" getter="get_material">
The current [Material] of the primitive mesh.
diff --git a/doc/classes/ProceduralSky.xml b/doc/classes/ProceduralSky.xml
index 25d09a1bc0..9a61fac63a 100644
--- a/doc/classes/ProceduralSky.xml
+++ b/doc/classes/ProceduralSky.xml
@@ -58,7 +58,7 @@
The direction of the sun using polar coordinates.
</member>
<member name="texture_size" type="int" setter="set_texture_size" getter="get_texture_size" enum="ProceduralSky.TextureSize" default="2">
- Size of [Texture] that the ProceduralSky will generate. The size is set using [enum TextureSize].
+ Size of [Texture2D] that the ProceduralSky will generate. The size is set using [enum TextureSize].
</member>
</members>
<constants>
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index b4284e06b9..517c68221e 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -967,30 +967,9 @@
<member name="rendering/environment/default_environment" type="String" setter="" getter="" default="&quot;&quot;">
[Environment] that will be used as a fallback environment in case a scene does not specify its own environment. The default environment is loaded in at scene load time regardless of whether you have set an environment or not. If you do not rely on the fallback environment, it is best to delete [code]default_env.tres[/code], or to specify a different default environment here.
</member>
- <member name="rendering/limits/buffers/blend_shape_max_buffer_size_kb" type="int" setter="" getter="" default="4096">
- Max buffer size for blend shapes. Any blend shape bigger than this will not work.
- </member>
- <member name="rendering/limits/buffers/canvas_polygon_buffer_size_kb" type="int" setter="" getter="" default="128">
- Max buffer size for drawing polygons. Any polygon bigger than this will not work.
- </member>
- <member name="rendering/limits/buffers/canvas_polygon_index_buffer_size_kb" type="int" setter="" getter="" default="128">
- Max index buffer size for drawing polygons. Any polygon bigger than this will not work.
- </member>
- <member name="rendering/limits/buffers/immediate_buffer_size_kb" type="int" setter="" getter="" default="2048">
- Max buffer size for drawing immediate objects (ImmediateGeometry nodes). Nodes using more than this size will not work.
- </member>
- <member name="rendering/limits/rendering/max_renderable_elements" type="int" setter="" getter="" default="65536">
+ <member name="rendering/limits/rendering/max_renderable_elements" type="int" setter="" getter="" default="128000">
Max amount of elements renderable in a frame. If more than this are visible per frame, they will be dropped. Keep in mind elements refer to mesh surfaces and not meshes themselves.
</member>
- <member name="rendering/limits/rendering/max_renderable_lights" type="int" setter="" getter="" default="4096">
- Max number of lights renderable in a frame. If more than this number are used, they will be ignored. On some systems (particularly web) setting this number as low as possible can increase the speed of shader compilation.
- </member>
- <member name="rendering/limits/rendering/max_renderable_reflections" type="int" setter="" getter="" default="1024">
- Max number of reflection probes renderable in a frame. If more than this number are used, they will be ignored. On some systems (particularly web) setting this number as low as possible can increase the speed of shader compilation.
- </member>
- <member name="rendering/limits/time/time_rollover_secs" type="float" setter="" getter="" default="3600">
- Shaders have a time variable that constantly increases. At some point, it needs to be rolled back to zero to avoid precision errors on shader animations. This setting specifies when (in seconds).
- </member>
<member name="rendering/quality/2d/gles2_use_nvidia_rect_flicker_workaround" type="bool" setter="" getter="" default="false">
Some NVIDIA GPU drivers have a bug which produces flickering issues for the [code]draw_rect[/code] method, especially as used in [TileMap]. Refer to [url=https://github.com/godotengine/godot/issues/9913]GitHub issue 9913[/url] for details.
If [code]true[/code], this option enables a "safe" code path for such NVIDIA GPUs at the cost of performance. This option only impacts the GLES2 rendering backend (so the bug stays if you use GLES3), and only desktop platforms.
@@ -998,13 +977,6 @@
<member name="rendering/quality/2d/use_pixel_snap" type="bool" setter="" getter="" default="false">
If [code]true[/code], forces snapping of polygons to pixels in 2D rendering. May help in some pixel art styles.
</member>
- <member name="rendering/quality/depth/hdr" type="bool" setter="" getter="" default="true">
- If [code]true[/code], allocates the main framebuffer with high dynamic range. High dynamic range allows the use of [Color] values greater than 1.
- [b]Note:[/b] Only available on the GLES3 backend.
- </member>
- <member name="rendering/quality/depth/hdr.mobile" type="bool" setter="" getter="" default="false">
- Lower-end override for [member rendering/quality/depth/hdr] on mobile devices, due to performance concerns or driver support.
- </member>
<member name="rendering/quality/depth_prepass/disable_for_vendors" type="String" setter="" getter="" default="&quot;PowerVR,Mali,Adreno,Apple&quot;">
Disables depth pre-pass for some GPU vendors (usually mobile), as their architecture already does this.
</member>
@@ -1017,7 +989,7 @@
<member name="rendering/quality/directional_shadow/size.mobile" type="int" setter="" getter="" default="2048">
Lower-end override for [member rendering/quality/directional_shadow/size] on mobile devices, due to performance concerns or driver support.
</member>
- <member name="rendering/quality/driver/driver_name" type="String" setter="" getter="" default="&quot;GLES3&quot;">
+ <member name="rendering/quality/driver/driver_name" type="String" setter="" getter="" default="&quot;Vulkan&quot;">
The video driver to use ("GLES2" or "GLES3").
[b]Note:[/b] The backend in use can be overridden at runtime via the [code]--video-driver[/code] command line argument, or by the [member rendering/quality/driver/fallback_to_gles2] option if the target system does not support GLES3 and falls back to GLES2. In such cases, this property is not updated, so use [method OS.get_current_video_driver] to query it at run-time.
</member>
@@ -1025,37 +997,53 @@
If [code]true[/code], allows falling back to the GLES2 driver if the GLES3 driver is not supported.
[b]Note:[/b] The two video drivers are not drop-in replacements for each other, so a game designed for GLES3 might not work properly when falling back to GLES2. In particular, some features of the GLES3 backend are not available in GLES2. Enabling this setting also means that both ETC and ETC2 VRAM-compressed textures will be exported on Android and iOS, increasing the data pack's size.
</member>
- <member name="rendering/quality/filters/anisotropic_filter_level" type="int" setter="" getter="" default="4">
- Maximum anisotropic filter level used for textures with anisotropy enabled. Higher values will result in sharper textures when viewed from oblique angles, at the cost of performance. Only power-of-two values are valid (2, 4, 8, 16).
+ <member name="rendering/quality/filters/depth_of_field_bokeh_quality" type="int" setter="" getter="" default="2">
+ </member>
+ <member name="rendering/quality/filters/depth_of_field_bokeh_shape" type="int" setter="" getter="" default="1">
+ </member>
+ <member name="rendering/quality/filters/depth_of_field_use_jitter" type="bool" setter="" getter="" default="false">
+ </member>
+ <member name="rendering/quality/filters/max_anisotropy" type="int" setter="" getter="" default="4">
</member>
<member name="rendering/quality/filters/msaa" type="int" setter="" getter="" default="0">
Sets the number of MSAA samples to use. MSAA is used to reduce aliasing around the edges of polygons. A higher MSAA value results in smoother edges but can be significantly slower on some hardware.
[b]Note:[/b] MSAA is not available on HTML5 export using the GLES2 backend.
</member>
+ <member name="rendering/quality/filters/screen_space_roughness_limiter" type="int" setter="" getter="" default="0">
+ </member>
+ <member name="rendering/quality/filters/screen_space_roughness_limiter_curve" type="float" setter="" getter="" default="1.0">
+ </member>
<member name="rendering/quality/filters/use_nearest_mipmap_filter" type="bool" setter="" getter="" default="false">
If [code]true[/code], uses nearest-neighbor mipmap filtering when using mipmaps (also called "bilinear filtering"), which will result in visible seams appearing between mipmap stages. This may increase performance in mobile as less memory bandwidth is used. If [code]false[/code], linear mipmap filtering (also called "trilinear filtering") is used.
</member>
+ <member name="rendering/quality/gi_probes/anisotropic" type="bool" setter="" getter="" default="false">
+ </member>
+ <member name="rendering/quality/gi_probes/quality" type="int" setter="" getter="" default="1">
+ </member>
<member name="rendering/quality/intended_usage/framebuffer_allocation" type="int" setter="" getter="" default="2">
Strategy used for framebuffer allocation. The simpler it is, the less resources it uses (but the less features it supports). If set to "2D Without Sampling" or "3D Without Effects", sample buffers will not be allocated. This means [code]SCREEN_TEXTURE[/code] and [code]DEPTH_TEXTURE[/code] will not be available in shaders and post-processing effects will not be available in the [Environment].
</member>
<member name="rendering/quality/intended_usage/framebuffer_allocation.mobile" type="int" setter="" getter="" default="3">
Lower-end override for [member rendering/quality/intended_usage/framebuffer_allocation] on mobile devices, due to performance concerns or driver support.
</member>
+ <member name="rendering/quality/reflection_atlas/reflection_count" type="int" setter="" getter="" default="64">
+ </member>
+ <member name="rendering/quality/reflection_atlas/reflection_size" type="int" setter="" getter="" default="256">
+ </member>
+ <member name="rendering/quality/reflection_atlas/reflection_size.mobile" type="int" setter="" getter="" default="128">
+ </member>
<member name="rendering/quality/reflections/atlas_size" type="int" setter="" getter="" default="2048">
Size of the atlas used by reflection probes. A larger size can result in higher visual quality, while a smaller size will be faster and take up less memory.
</member>
- <member name="rendering/quality/reflections/atlas_subdiv" type="int" setter="" getter="" default="8">
- Number of subdivisions to use for the reflection atlas. A higher number lowers the quality of each atlas, but allows you to use more.
+ <member name="rendering/quality/reflections/ggx_samples" type="int" setter="" getter="" default="1024">
+ </member>
+ <member name="rendering/quality/reflections/ggx_samples.mobile" type="int" setter="" getter="" default="128">
</member>
- <member name="rendering/quality/reflections/high_quality_ggx" type="bool" setter="" getter="" default="true">
- If [code]true[/code], uses a high amount of samples to create blurred variants of reflection probes and panorama backgrounds (sky). Those blurred variants are used by rough materials.
+ <member name="rendering/quality/reflections/ggx_samples_realtime" type="int" setter="" getter="" default="64">
</member>
- <member name="rendering/quality/reflections/high_quality_ggx.mobile" type="bool" setter="" getter="" default="false">
- Lower-end override for [member rendering/quality/reflections/high_quality_ggx] on mobile devices, due to performance concerns or driver support.
+ <member name="rendering/quality/reflections/ggx_samples_realtime.mobile" type="int" setter="" getter="" default="16">
</member>
- <member name="rendering/quality/reflections/irradiance_max_size" type="int" setter="" getter="" default="128">
- Limits the size of the irradiance map which is normally determined by [member Sky.radiance_size]. A higher size results in a higher quality irradiance map similarly to [member rendering/quality/reflections/high_quality_ggx]. Use a higher value when using high-frequency HDRI maps, otherwise keep this as low as possible.
- [b]Note:[/b] Low and mid range hardware do not support complex irradiance maps well and may crash if this is set too high.
+ <member name="rendering/quality/reflections/roughness_layers" type="int" setter="" getter="" default="6">
</member>
<member name="rendering/quality/reflections/texture_array_reflections" type="bool" setter="" getter="" default="true">
If [code]true[/code], uses texture arrays instead of mipmaps for reflection probes and panorama backgrounds (sky). This reduces jitter noise on reflections, but costs more performance and memory.
@@ -1105,20 +1093,9 @@
<member name="rendering/quality/shadows/filter_mode.mobile" type="int" setter="" getter="" default="0">
Lower-end override for [member rendering/quality/shadows/filter_mode] on mobile devices, due to performance concerns or driver support.
</member>
- <member name="rendering/quality/subsurface_scattering/follow_surface" type="bool" setter="" getter="" default="false">
- Improves quality of subsurface scattering, but cost significantly increases.
- </member>
- <member name="rendering/quality/subsurface_scattering/quality" type="int" setter="" getter="" default="1">
- Quality setting for subsurface scattering (samples taken).
+ <member name="rendering/quality/ssao/half_size" type="bool" setter="" getter="" default="false">
</member>
- <member name="rendering/quality/subsurface_scattering/scale" type="int" setter="" getter="" default="1.0">
- Max radius used for subsurface scattering samples.
- </member>
- <member name="rendering/quality/subsurface_scattering/weight_samples" type="bool" setter="" getter="" default="true">
- Weight subsurface scattering samples. Helps to avoid reading samples from unrelated parts of the screen.
- </member>
- <member name="rendering/quality/voxel_cone_tracing/high_quality" type="bool" setter="" getter="" default="false">
- Use high-quality voxel cone tracing. This results in better-looking reflections, but is much more expensive on the GPU.
+ <member name="rendering/quality/ssao/quality" type="int" setter="" getter="" default="1">
</member>
<member name="rendering/threads/thread_model" type="int" setter="" getter="" default="1">
Thread model for rendering. Rendering on a thread can vastly improve performance, but synchronizing to the main thread can cause a bit more jitter.
@@ -1138,6 +1115,14 @@
<member name="rendering/vram_compression/import_s3tc" type="bool" setter="" getter="" default="true">
If [code]true[/code], the texture importer will import VRAM-compressed textures using the S3 Texture Compression algorithm. This algorithm is only supported on desktop platforms and consoles.
</member>
+ <member name="rendering/vulkan/descriptor_pools/max_descriptors_per_pool" type="int" setter="" getter="" default="64">
+ </member>
+ <member name="rendering/vulkan/staging_buffer/block_size_kb" type="int" setter="" getter="" default="256">
+ </member>
+ <member name="rendering/vulkan/staging_buffer/max_size_mb" type="int" setter="" getter="" default="128">
+ </member>
+ <member name="rendering/vulkan/staging_buffer/texture_upload_region_size_px" type="int" setter="" getter="" default="64">
+ </member>
</members>
<constants>
</constants>
diff --git a/doc/classes/ProxyTexture.xml b/doc/classes/ProxyTexture.xml
index fdff8908d5..4f25fbcdf9 100644
--- a/doc/classes/ProxyTexture.xml
+++ b/doc/classes/ProxyTexture.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="ProxyTexture" inherits="Texture" version="4.0">
+<class name="ProxyTexture" inherits="Texture2D" version="4.0">
<brief_description>
</brief_description>
<description>
@@ -9,9 +9,8 @@
<methods>
</methods>
<members>
- <member name="base" type="Texture" setter="set_base" getter="get_base">
+ <member name="base" type="Texture2D" setter="set_base" getter="get_base">
</member>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="0" />
</members>
<constants>
</constants>
diff --git a/doc/classes/RenderingDevice.xml b/doc/classes/RenderingDevice.xml
new file mode 100644
index 0000000000..2615f0a2e9
--- /dev/null
+++ b/doc/classes/RenderingDevice.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="RenderingDevice" inherits="Object" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/Resource.xml b/doc/classes/Resource.xml
index 496b1c4f3c..5bc34772c8 100644
--- a/doc/classes/Resource.xml
+++ b/doc/classes/Resource.xml
@@ -37,7 +37,7 @@
<return type="RID">
</return>
<description>
- Returns the RID of the resource (or an empty RID). Many resources (such as [Texture], [Mesh], etc) are high-level abstractions of resources stored in a server, so this function will return the original RID.
+ Returns the RID of the resource (or an empty RID). Many resources (such as [Texture2D], [Mesh], etc) are high-level abstractions of resources stored in a server, so this function will return the original RID.
</description>
</method>
<method name="setup_local_to_scene">
diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml
index bad3625abc..983f768b85 100644
--- a/doc/classes/RichTextLabel.xml
+++ b/doc/classes/RichTextLabel.xml
@@ -14,7 +14,7 @@
<method name="add_image">
<return type="void">
</return>
- <argument index="0" name="image" type="Texture">
+ <argument index="0" name="image" type="Texture2D">
</argument>
<argument index="1" name="width" type="int" default="0">
</argument>
diff --git a/doc/classes/Shader.xml b/doc/classes/Shader.xml
index cab906ee25..a2fbf5a1b1 100644
--- a/doc/classes/Shader.xml
+++ b/doc/classes/Shader.xml
@@ -12,7 +12,7 @@
</tutorials>
<methods>
<method name="get_default_texture_param" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="param" type="String">
</argument>
@@ -43,7 +43,7 @@
</return>
<argument index="0" name="param" type="String">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
Sets the default texture to be used with a texture uniform. The default is used if a texture is not set in the [ShaderMaterial].
diff --git a/doc/classes/Skeleton.xml b/doc/classes/Skeleton.xml
index 1fc8b2eb35..eaab4063b8 100644
--- a/doc/classes/Skeleton.xml
+++ b/doc/classes/Skeleton.xml
@@ -258,6 +258,10 @@
</description>
</method>
</methods>
+ <members>
+ <member name="animate_physical_bones" type="bool" setter="set_animate_physical_bones" getter="get_animate_physical_bones" default="true">
+ </member>
+ </members>
<constants>
<constant name="NOTIFICATION_UPDATE_SKELETON" value="50">
</constant>
diff --git a/doc/classes/Sky.xml b/doc/classes/Sky.xml
index 11cea6dbc3..72599a323d 100644
--- a/doc/classes/Sky.xml
+++ b/doc/classes/Sky.xml
@@ -11,6 +11,8 @@
<methods>
</methods>
<members>
+ <member name="process_mode" type="int" setter="set_process_mode" getter="get_process_mode" enum="Sky.ProcessMode" default="0">
+ </member>
<member name="radiance_size" type="int" setter="set_radiance_size" getter="get_radiance_size" enum="Sky.RadianceSize" default="2">
The [Sky]'s radiance map size. The higher the radiance map size, the more detailed the lighting from the [Sky] will be.
See [enum RadianceSize] constants for values.
@@ -42,5 +44,9 @@
<constant name="RADIANCE_SIZE_MAX" value="7" enum="RadianceSize">
Represents the size of the [enum RadianceSize] enum.
</constant>
+ <constant name="PROCESS_MODE_QUALITY" value="0" enum="ProcessMode">
+ </constant>
+ <constant name="PROCESS_MODE_REALTIME" value="1" enum="ProcessMode">
+ </constant>
</constants>
</class>
diff --git a/doc/classes/SpatialMaterial.xml b/doc/classes/SpatialMaterial.xml
deleted file mode 100644
index c6780511b9..0000000000
--- a/doc/classes/SpatialMaterial.xml
+++ /dev/null
@@ -1,649 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="SpatialMaterial" inherits="Material" version="4.0">
- <brief_description>
- Default 3D rendering material.
- </brief_description>
- <description>
- This provides a default material with a wide variety of rendering features and properties without the need to write shader code. See the tutorial below for details.
- </description>
- <tutorials>
- <link>https://docs.godotengine.org/en/latest/tutorials/3d/spatial_material.html</link>
- </tutorials>
- <methods>
- <method name="get_feature" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="feature" type="int" enum="SpatialMaterial.Feature">
- </argument>
- <description>
- Returns [code]true[/code], if the specified [enum Feature] is enabled.
- </description>
- </method>
- <method name="get_flag" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="flag" type="int" enum="SpatialMaterial.Flags">
- </argument>
- <description>
- Returns [code]true[/code], if the specified flag is enabled. See [enum Flags] enumerator for options.
- </description>
- </method>
- <method name="get_texture" qualifiers="const">
- <return type="Texture">
- </return>
- <argument index="0" name="param" type="int" enum="SpatialMaterial.TextureParam">
- </argument>
- <description>
- Returns the [Texture] associated with the specified [enum TextureParam].
- </description>
- </method>
- <method name="set_feature">
- <return type="void">
- </return>
- <argument index="0" name="feature" type="int" enum="SpatialMaterial.Feature">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
- <description>
- If [code]true[/code], enables the specified [enum Feature]. Many features that are available in [SpatialMaterial]s need to be enabled before use. This way the cost for using the feature is only incurred when specified. Features can also be enabled by setting the corresponding member to [code]true[/code].
- </description>
- </method>
- <method name="set_flag">
- <return type="void">
- </return>
- <argument index="0" name="flag" type="int" enum="SpatialMaterial.Flags">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
- <description>
- If [code]true[/code], enables the specified flag. Flags are optional behaviour that can be turned on and off. Only one flag can be enabled at a time with this function, the flag enumerators cannot be bit-masked together to enable or disable multiple flags at once. Flags can also be enabled by setting the corresponding member to [code]true[/code]. See [enum Flags] enumerator for options.
- </description>
- </method>
- <method name="set_texture">
- <return type="void">
- </return>
- <argument index="0" name="param" type="int" enum="SpatialMaterial.TextureParam">
- </argument>
- <argument index="1" name="texture" type="Texture">
- </argument>
- <description>
- Sets the [Texture] to be used by the specified [enum TextureParam]. This function is called when setting members ending in [code]*_texture[/code].
- </description>
- </method>
- </methods>
- <members>
- <member name="albedo_color" type="Color" setter="set_albedo" getter="get_albedo" default="Color( 1, 1, 1, 1 )">
- The material's base color.
- </member>
- <member name="albedo_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture to multiply by [member albedo_color]. Used for basic texturing of objects.
- </member>
- <member name="anisotropy" type="float" setter="set_anisotropy" getter="get_anisotropy">
- The strength of the anisotropy effect.
- </member>
- <member name="anisotropy_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], anisotropy is enabled. Changes the shape of the specular blob and aligns it to tangent space. Mesh tangents are needed for this to work. If the mesh does not contain tangents the anisotropy effect will appear broken.
- </member>
- <member name="anisotropy_flowmap" type="Texture" setter="set_texture" getter="get_texture">
- Texture that offsets the tangent map for anisotropy calculations.
- </member>
- <member name="ao_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], ambient occlusion is enabled. Ambient occlusion darkens areas based on the [member ao_texture].
- </member>
- <member name="ao_light_affect" type="float" setter="set_ao_light_affect" getter="get_ao_light_affect">
- Amount that ambient occlusion affects lighting from lights. If [code]0[/code], ambient occlusion only affects ambient light. If [code]1[/code], ambient occlusion affects lights just as much as it affects ambient light. This can be used to impact the strength of the ambient occlusion effect, but typically looks unrealistic.
- </member>
- <member name="ao_on_uv2" type="bool" setter="set_flag" getter="get_flag">
- If [code]true[/code], use [code]UV2[/code] coordinates to look up from the [member ao_texture].
- </member>
- <member name="ao_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture that defines the amount of ambient occlusion for a given point on the object.
- </member>
- <member name="ao_texture_channel" type="int" setter="set_ao_texture_channel" getter="get_ao_texture_channel" enum="SpatialMaterial.TextureChannel">
- Specifies the channel of the [member ao_texture] in which the ambient occlusion information is stored. This is useful when you store the information for multiple effects in a single texture. For example if you stored metallic in the red channel, roughness in the blue, and ambient occlusion in the green you could reduce the number of textures you use.
- </member>
- <member name="clearcoat" type="float" setter="set_clearcoat" getter="get_clearcoat">
- Sets the strength of the clearcoat effect. Setting to [code]0[/code] looks the same as disabling the clearcoat effect.
- </member>
- <member name="clearcoat_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], clearcoat rendering is enabled. Adds a secondary transparent pass to the lighting calculation resulting in an added specular blob. This makes materials appear as if they have a clear layer on them that can be either glossy or rough.
- </member>
- <member name="clearcoat_gloss" type="float" setter="set_clearcoat_gloss" getter="get_clearcoat_gloss">
- Sets the roughness of the clearcoat pass. A higher value results in a smoother clearcoat while a lower value results in a rougher clearcoat.
- </member>
- <member name="clearcoat_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture that defines the strength of the clearcoat effect and the glossiness of the clearcoat. Strength is specified in the red channel while glossiness is specified in the green channel.
- </member>
- <member name="depth_deep_parallax" type="bool" setter="set_depth_deep_parallax" getter="is_depth_deep_parallax_enabled">
- If [code]true[/code], the shader will read depth texture at multiple points along the view ray to determine occlusion and parrallax. This can be very performance demanding, but results in more realistic looking depth mapping.
- </member>
- <member name="depth_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], depth mapping is enabled (also called "parallax mapping" or "height mapping"). See also [member normal_enabled].
- </member>
- <member name="depth_flip_binormal" type="bool" setter="set_depth_deep_parallax_flip_binormal" getter="get_depth_deep_parallax_flip_binormal">
- If [code]true[/code], direction of the binormal is flipped before using in the depth effect. This may be necessary if you have encoded your binormals in a way that is conflicting with the depth effect.
- </member>
- <member name="depth_flip_tangent" type="bool" setter="set_depth_deep_parallax_flip_tangent" getter="get_depth_deep_parallax_flip_tangent">
- If [code]true[/code], direction of the tangent is flipped before using in the depth effect. This may be necessary if you have encoded your tangents in a way that is conflicting with the depth effect.
- </member>
- <member name="depth_max_layers" type="int" setter="set_depth_deep_parallax_max_layers" getter="get_depth_deep_parallax_max_layers">
- Number of layers to use when using [member depth_deep_parallax] and the view direction is perpendicular to the surface of the object. A higher number will be more performance demanding while a lower number may not look as crisp.
- </member>
- <member name="depth_min_layers" type="int" setter="set_depth_deep_parallax_min_layers" getter="get_depth_deep_parallax_min_layers">
- Number of layers to use when using [member depth_deep_parallax] and the view direction is parallel to the surface of the object. A higher number will be more performance demanding while a lower number may not look as crisp.
- </member>
- <member name="depth_scale" type="float" setter="set_depth_scale" getter="get_depth_scale">
- Scales the depth offset effect. A higher number will create a larger depth.
- </member>
- <member name="depth_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture used to determine depth at a given pixel. Depth is always stored in the red channel.
- </member>
- <member name="detail_albedo" type="Texture" setter="set_texture" getter="get_texture">
- Texture that specifies the color of the detail overlay.
- </member>
- <member name="detail_blend_mode" type="int" setter="set_detail_blend_mode" getter="get_detail_blend_mode" enum="SpatialMaterial.BlendMode">
- Specifies how the [member detail_albedo] should blend with the current [code]ALBEDO[/code]. See [enum BlendMode] for options.
- </member>
- <member name="detail_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], enables the detail overlay. Detail is a second texture that gets mixed over the surface of the object based on [member detail_mask]. This can be used to add variation to objects, or to blend between two different albedo/normal textures.
- </member>
- <member name="detail_mask" type="Texture" setter="set_texture" getter="get_texture">
- Texture used to specify how the detail textures get blended with the base textures.
- </member>
- <member name="detail_normal" type="Texture" setter="set_texture" getter="get_texture">
- Texture that specifies the per-pixel normal of the detail overlay.
- </member>
- <member name="detail_uv_layer" type="int" setter="set_detail_uv" getter="get_detail_uv" enum="SpatialMaterial.DetailUV">
- Specifies whether to use [code]UV[/code] or [code]UV2[/code] for the detail layer. See [enum DetailUV] for options.
- </member>
- <member name="distance_fade_max_distance" type="float" setter="set_distance_fade_max_distance" getter="get_distance_fade_max_distance">
- Distance at which the object fades fully and is no longer visible.
- </member>
- <member name="distance_fade_min_distance" type="float" setter="set_distance_fade_min_distance" getter="get_distance_fade_min_distance">
- Distance at which the object starts to fade. If the object is less than this distance away it will appear normal.
- </member>
- <member name="distance_fade_mode" type="int" setter="set_distance_fade" getter="get_distance_fade" enum="SpatialMaterial.DistanceFadeMode" default="0">
- Specifies which type of fade to use. Can be any of the [enum DistanceFadeMode]s.
- </member>
- <member name="emission" type="Color" setter="set_emission" getter="get_emission">
- The emitted light's color. See [member emission_enabled].
- </member>
- <member name="emission_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], the body emits light. Emitting light makes the object appear brighter. The object can also cast light on other objects if a [GIProbe] or [BakedLightmap] is used and this object is used in baked lighting.
- </member>
- <member name="emission_energy" type="float" setter="set_emission_energy" getter="get_emission_energy">
- The emitted light's strength. See [member emission_enabled].
- </member>
- <member name="emission_on_uv2" type="bool" setter="set_flag" getter="get_flag">
- Use [code]UV2[/code] to read from the [member emission_texture].
- </member>
- <member name="emission_operator" type="int" setter="set_emission_operator" getter="get_emission_operator" enum="SpatialMaterial.EmissionOperator">
- Sets how [member emission] interacts with [member emission_texture]. Can either add or multiply. See [enum EmissionOperator] for options.
- </member>
- <member name="emission_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture that specifies how much surface emits light at a given point.
- </member>
- <member name="flags_albedo_tex_force_srgb" type="bool" setter="set_flag" getter="get_flag" default="false">
- Forces a conversion of the [member albedo_texture] from sRGB space to linear space.
- </member>
- <member name="flags_disable_ambient_light" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the object receives no ambient light.
- </member>
- <member name="flags_do_not_receive_shadows" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the object receives no shadow that would otherwise be cast onto it.
- </member>
- <member name="flags_ensure_correct_normals" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the shader will compute extra operations to make sure the normal stays correct when using a non-uniform scale. Only enable if using non-uniform scaling.
- </member>
- <member name="flags_fixed_size" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the object is rendered at the same size regardless of distance.
- </member>
- <member name="flags_no_depth_test" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], depth testing is disabled and the object will be drawn in render order.
- </member>
- <member name="flags_transparent" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], transparency is enabled on the body. See also [member params_blend_mode].
- </member>
- <member name="flags_unshaded" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the object is unaffected by lighting.
- </member>
- <member name="flags_use_point_size" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], render point size can be changed.
- [b]Note:[/b] this is only effective for objects whose geometry is point-based rather than triangle-based. See also [member params_point_size].
- </member>
- <member name="flags_use_shadow_to_opacity" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], enables the "shadow to opacity" render mode where lighting modifies the alpha so shadowed areas are opaque and non-shadowed areas are transparent. Useful for overlaying shadows onto a camera feed in AR.
- </member>
- <member name="flags_vertex_lighting" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], lighting is calculated per vertex rather than per pixel. This may increase performance on low-end devices.
- </member>
- <member name="flags_world_triplanar" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], triplanar mapping is calculated in world space rather than object local space. See also [member uv1_triplanar].
- </member>
- <member name="metallic" type="float" setter="set_metallic" getter="get_metallic" default="0.0">
- The reflectivity of the object's surface. The higher the value, the more light is reflected.
- </member>
- <member name="metallic_specular" type="float" setter="set_specular" getter="get_specular" default="0.5">
- Sets the size of the specular lobe. The specular lobe is the bright spot that is reflected from light sources.
- [b]Note:[/b] unlike [member metallic], this is not energy-conserving, so it should be left at [code]0.5[/code] in most cases. See also [member roughness].
- </member>
- <member name="metallic_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture used to specify metallic for an object. This is multiplied by [member metallic].
- </member>
- <member name="metallic_texture_channel" type="int" setter="set_metallic_texture_channel" getter="get_metallic_texture_channel" enum="SpatialMaterial.TextureChannel" default="0">
- Specifies the channel of the [member metallic_texture] in which the metallic information is stored. This is useful when you store the information for multiple effects in a single texture. For example if you stored metallic in the red channel, roughness in the blue, and ambient occlusion in the green you could reduce the number of textures you use.
- </member>
- <member name="normal_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], normal mapping is enabled.
- </member>
- <member name="normal_scale" type="float" setter="set_normal_scale" getter="get_normal_scale">
- The strength of the normal map's effect.
- </member>
- <member name="normal_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture used to specify the normal at a given pixel. The [code]normal_texture[/code] only uses the red and green channels. The normal read from [code]normal_texture[/code] is oriented around the surface normal provided by the [Mesh].
- </member>
- <member name="params_alpha_scissor_threshold" type="float" setter="set_alpha_scissor_threshold" getter="get_alpha_scissor_threshold">
- Threshold at which the alpha scissor will discard values.
- </member>
- <member name="params_billboard_keep_scale" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the shader will keep the scale set for the mesh. Otherwise the scale is lost when billboarding. Only applies when [member params_billboard_mode] is [constant BILLBOARD_ENABLED].
- </member>
- <member name="params_billboard_mode" type="int" setter="set_billboard_mode" getter="get_billboard_mode" enum="SpatialMaterial.BillboardMode" default="0">
- Controls how the object faces the camera. See [enum BillboardMode].
- </member>
- <member name="params_blend_mode" type="int" setter="set_blend_mode" getter="get_blend_mode" enum="SpatialMaterial.BlendMode" default="0">
- The material's blend mode.
- [b]Note:[/b] Values other than [code]Mix[/code] force the object into the transparent pipeline. See [enum BlendMode].
- </member>
- <member name="params_cull_mode" type="int" setter="set_cull_mode" getter="get_cull_mode" enum="SpatialMaterial.CullMode" default="0">
- Which side of the object is not drawn when backfaces are rendered. See [enum CullMode].
- </member>
- <member name="params_depth_draw_mode" type="int" setter="set_depth_draw_mode" getter="get_depth_draw_mode" enum="SpatialMaterial.DepthDrawMode" default="0">
- Determines when depth rendering takes place. See [enum DepthDrawMode]. See also [member flags_transparent].
- </member>
- <member name="params_diffuse_mode" type="int" setter="set_diffuse_mode" getter="get_diffuse_mode" enum="SpatialMaterial.DiffuseMode" default="0">
- The algorithm used for diffuse light scattering. See [enum DiffuseMode].
- </member>
- <member name="params_grow" type="bool" setter="set_grow_enabled" getter="is_grow_enabled" default="false">
- If [code]true[/code], enables the vertex grow setting. See [member params_grow_amount].
- </member>
- <member name="params_grow_amount" type="float" setter="set_grow" getter="get_grow">
- Grows object vertices in the direction of their normals.
- </member>
- <member name="params_line_width" type="float" setter="set_line_width" getter="get_line_width" default="1.0">
- Currently unimplemented in Godot.
- </member>
- <member name="params_point_size" type="float" setter="set_point_size" getter="get_point_size" default="1.0">
- The point size in pixels. See [member flags_use_point_size].
- </member>
- <member name="params_specular_mode" type="int" setter="set_specular_mode" getter="get_specular_mode" enum="SpatialMaterial.SpecularMode" default="0">
- The method for rendering the specular blob. See [enum SpecularMode].
- </member>
- <member name="params_use_alpha_scissor" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the shader will discard all pixels that have an alpha value less than [member params_alpha_scissor_threshold].
- </member>
- <member name="particles_anim_h_frames" type="int" setter="set_particles_anim_h_frames" getter="get_particles_anim_h_frames">
- The number of horizontal frames in the particle sprite sheet. Only enabled when using [constant BILLBOARD_PARTICLES]. See [member params_billboard_mode].
- </member>
- <member name="particles_anim_loop" type="bool" setter="set_particles_anim_loop" getter="get_particles_anim_loop">
- If [code]true[/code], particle animations are looped. Only enabled when using [constant BILLBOARD_PARTICLES]. See [member params_billboard_mode].
- </member>
- <member name="particles_anim_v_frames" type="int" setter="set_particles_anim_v_frames" getter="get_particles_anim_v_frames">
- The number of vertical frames in the particle sprite sheet. Only enabled when using [constant BILLBOARD_PARTICLES]. See [member params_billboard_mode].
- </member>
- <member name="proximity_fade_distance" type="float" setter="set_proximity_fade_distance" getter="get_proximity_fade_distance">
- Distance over which the fade effect takes place. The larger the distance the longer it takes for an object to fade.
- </member>
- <member name="proximity_fade_enable" type="bool" setter="set_proximity_fade" getter="is_proximity_fade_enabled" default="false">
- If [code]true[/code], the proximity fade effect is enabled. The proximity fade effect fades out each pixel based on its distance to another object.
- </member>
- <member name="refraction_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], the refraction effect is enabled. Distorts transparency based on light from behind the object.
- </member>
- <member name="refraction_scale" type="float" setter="set_refraction" getter="get_refraction">
- The strength of the refraction effect.
- </member>
- <member name="refraction_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture that controls the strength of the refraction per-pixel. Multiplied by [member refraction_scale].
- </member>
- <member name="refraction_texture_channel" type="int" setter="set_refraction_texture_channel" getter="get_refraction_texture_channel" enum="SpatialMaterial.TextureChannel">
- Specifies the channel of the [member ao_texture] in which the ambient occlusion information is stored. This is useful when you store the information for multiple effects in a single texture. For example if you stored metallic in the red channel, roughness in the blue, and ambient occlusion in the green you could reduce the number of textures you use.
- </member>
- <member name="rim" type="float" setter="set_rim" getter="get_rim">
- Sets the strength of the rim lighting effect.
- </member>
- <member name="rim_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], rim effect is enabled. Rim lighting increases the brightness at glancing angles on an object.
- </member>
- <member name="rim_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture used to set the strength of the rim lighting effect per-pixel. Multiplied by [member rim].
- </member>
- <member name="rim_tint" type="float" setter="set_rim_tint" getter="get_rim_tint">
- The amount of to blend light and albedo color when rendering rim effect. If [code]0[/code] the light color is used, while [code]1[/code] means albedo color is used. An intermediate value generally works best.
- </member>
- <member name="roughness" type="float" setter="set_roughness" getter="get_roughness" default="1.0">
- Surface reflection. A value of [code]0[/code] represents a perfect mirror while a value of [code]1[/code] completely blurs the reflection. See also [member metallic].
- </member>
- <member name="roughness_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture used to control the roughness per-pixel. Multiplied by [member roughness].
- </member>
- <member name="roughness_texture_channel" type="int" setter="set_roughness_texture_channel" getter="get_roughness_texture_channel" enum="SpatialMaterial.TextureChannel" default="0">
- Specifies the channel of the [member ao_texture] in which the ambient occlusion information is stored. This is useful when you store the information for multiple effects in a single texture. For example if you stored metallic in the red channel, roughness in the blue, and ambient occlusion in the green you could reduce the number of textures you use.
- </member>
- <member name="subsurf_scatter_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], subsurface scattering is enabled. Emulates light that penetrates an object's surface, is scattered, and then emerges.
- </member>
- <member name="subsurf_scatter_strength" type="float" setter="set_subsurface_scattering_strength" getter="get_subsurface_scattering_strength">
- The strength of the subsurface scattering effect.
- </member>
- <member name="subsurf_scatter_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture used to control the subsurface scattering strength. Stored in the red texture channel. Multiplied by [member subsurf_scatter_strength].
- </member>
- <member name="transmission" type="Color" setter="set_transmission" getter="get_transmission">
- The color used by the transmission effect. Represents the light passing through an object.
- </member>
- <member name="transmission_enabled" type="bool" setter="set_feature" getter="get_feature" default="false">
- If [code]true[/code], the transmission effect is enabled.
- </member>
- <member name="transmission_texture" type="Texture" setter="set_texture" getter="get_texture">
- Texture used to control the transmission effect per-pixel. Added to [member transmission].
- </member>
- <member name="uv1_offset" type="Vector3" setter="set_uv1_offset" getter="get_uv1_offset" default="Vector3( 0, 0, 0 )">
- How much to offset the [code]UV[/code] coordinates. This amount will be added to [code]UV[/code] in the vertex function. This can be used to offset a texture.
- </member>
- <member name="uv1_scale" type="Vector3" setter="set_uv1_scale" getter="get_uv1_scale" default="Vector3( 1, 1, 1 )">
- How much to scale the [code]UV[/code] coordinates. This is multiplied by [code]UV[/code] in the vertex function.
- </member>
- <member name="uv1_triplanar" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], instead of using [code]UV[/code] textures will use a triplanar texture lookup to determine how to apply textures. Triplanar uses the orientation of the object's surface to blend between texture coordinates. It reads from the source texture 3 times, once for each axis and then blends between the results based on how closely the pixel aligns with each axis. This is often used for natural features to get a realistic blend of materials. Because triplanar texturing requires many more texture reads per-pixel it is much slower than normal UV texturing. Additionally, because it is blending the texture between the three axes, it is unsuitable when you are trying to achieve crisp texturing.
- </member>
- <member name="uv1_triplanar_sharpness" type="float" setter="set_uv1_triplanar_blend_sharpness" getter="get_uv1_triplanar_blend_sharpness" default="1.0">
- A lower number blends the texture more softly while a higher number blends the texture more sharply.
- </member>
- <member name="uv2_offset" type="Vector3" setter="set_uv2_offset" getter="get_uv2_offset" default="Vector3( 0, 0, 0 )">
- How much to offset the [code]UV2[/code] coordinates. This amount will be added to [code]UV2[/code] in the vertex function. This can be used to offset a texture.
- </member>
- <member name="uv2_scale" type="Vector3" setter="set_uv2_scale" getter="get_uv2_scale" default="Vector3( 1, 1, 1 )">
- How much to scale the [code]UV2[/code] coordinates. This is multiplied by [code]UV2[/code] in the vertex function.
- </member>
- <member name="uv2_triplanar" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], instead of using [code]UV2[/code] textures will use a triplanar texture lookup to determine how to apply textures. Triplanar uses the orientation of the object's surface to blend between texture coordinates. It reads from the source texture 3 times, once for each axis and then blends between the results based on how closely the pixel aligns with each axis. This is often used for natural features to get a realistic blend of materials. Because triplanar texturing requires many more texture reads per-pixel it is much slower than normal UV texturing. Additionally, because it is blending the texture between the three axes, it is unsuitable when you are trying to achieve crisp texturing.
- </member>
- <member name="uv2_triplanar_sharpness" type="float" setter="set_uv2_triplanar_blend_sharpness" getter="get_uv2_triplanar_blend_sharpness" default="1.0">
- A lower number blends the texture more softly while a higher number blends the texture more sharply.
- </member>
- <member name="vertex_color_is_srgb" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the model's vertex colors are processed as sRGB mode.
- </member>
- <member name="vertex_color_use_as_albedo" type="bool" setter="set_flag" getter="get_flag" default="false">
- If [code]true[/code], the vertex color is used as albedo color.
- </member>
- </members>
- <constants>
- <constant name="TEXTURE_ALBEDO" value="0" enum="TextureParam">
- Texture specifying per-pixel color.
- </constant>
- <constant name="TEXTURE_METALLIC" value="1" enum="TextureParam">
- Texture specifying per-pixel metallic value.
- </constant>
- <constant name="TEXTURE_ROUGHNESS" value="2" enum="TextureParam">
- Texture specifying per-pixel roughness value.
- </constant>
- <constant name="TEXTURE_EMISSION" value="3" enum="TextureParam">
- Texture specifying per-pixel emission color.
- </constant>
- <constant name="TEXTURE_NORMAL" value="4" enum="TextureParam">
- Texture specifying per-pixel normal vector.
- </constant>
- <constant name="TEXTURE_RIM" value="5" enum="TextureParam">
- Texture specifying per-pixel rim value.
- </constant>
- <constant name="TEXTURE_CLEARCOAT" value="6" enum="TextureParam">
- Texture specifying per-pixel clearcoat value.
- </constant>
- <constant name="TEXTURE_FLOWMAP" value="7" enum="TextureParam">
- Texture specifying per-pixel flowmap direction for use with [member anisotropy].
- </constant>
- <constant name="TEXTURE_AMBIENT_OCCLUSION" value="8" enum="TextureParam">
- Texture specifying per-pixel ambient occlusion value.
- </constant>
- <constant name="TEXTURE_DEPTH" value="9" enum="TextureParam">
- Texture specifying per-pixel depth.
- </constant>
- <constant name="TEXTURE_SUBSURFACE_SCATTERING" value="10" enum="TextureParam">
- Texture specifying per-pixel subsurface scattering.
- </constant>
- <constant name="TEXTURE_TRANSMISSION" value="11" enum="TextureParam">
- Texture specifying per-pixel transmission color.
- </constant>
- <constant name="TEXTURE_REFRACTION" value="12" enum="TextureParam">
- Texture specifying per-pixel refraction strength.
- </constant>
- <constant name="TEXTURE_DETAIL_MASK" value="13" enum="TextureParam">
- Texture specifying per-pixel detail mask blending value.
- </constant>
- <constant name="TEXTURE_DETAIL_ALBEDO" value="14" enum="TextureParam">
- Texture specifying per-pixel detail color.
- </constant>
- <constant name="TEXTURE_DETAIL_NORMAL" value="15" enum="TextureParam">
- Texture specifying per-pixel detail normal.
- </constant>
- <constant name="TEXTURE_MAX" value="16" enum="TextureParam">
- Represents the size of the [enum TextureParam] enum.
- </constant>
- <constant name="DETAIL_UV_1" value="0" enum="DetailUV">
- Use [code]UV[/code] with the detail texture.
- </constant>
- <constant name="DETAIL_UV_2" value="1" enum="DetailUV">
- Use [code]UV2[/code] with the detail texture.
- </constant>
- <constant name="FEATURE_TRANSPARENT" value="0" enum="Feature">
- Constant for setting [member flags_transparent].
- </constant>
- <constant name="FEATURE_EMISSION" value="1" enum="Feature">
- Constant for setting [member emission_enabled].
- </constant>
- <constant name="FEATURE_NORMAL_MAPPING" value="2" enum="Feature">
- Constant for setting [member normal_enabled].
- </constant>
- <constant name="FEATURE_RIM" value="3" enum="Feature">
- Constant for setting [member rim_enabled].
- </constant>
- <constant name="FEATURE_CLEARCOAT" value="4" enum="Feature">
- Constant for setting [member clearcoat_enabled].
- </constant>
- <constant name="FEATURE_ANISOTROPY" value="5" enum="Feature">
- Constant for setting [member anisotropy_enabled].
- </constant>
- <constant name="FEATURE_AMBIENT_OCCLUSION" value="6" enum="Feature">
- Constant for setting [member ao_enabled].
- </constant>
- <constant name="FEATURE_DEPTH_MAPPING" value="7" enum="Feature">
- Constant for setting [member depth_enabled].
- </constant>
- <constant name="FEATURE_SUBSURACE_SCATTERING" value="8" enum="Feature">
- Constant for setting [member subsurf_scatter_enabled].
- </constant>
- <constant name="FEATURE_TRANSMISSION" value="9" enum="Feature">
- Constant for setting [member transmission_enabled].
- </constant>
- <constant name="FEATURE_REFRACTION" value="10" enum="Feature">
- Constant for setting [member refraction_enabled].
- </constant>
- <constant name="FEATURE_DETAIL" value="11" enum="Feature">
- Constant for setting [member detail_enabled].
- </constant>
- <constant name="FEATURE_MAX" value="12" enum="Feature">
- Represents the size of the [enum Feature] enum.
- </constant>
- <constant name="BLEND_MODE_MIX" value="0" enum="BlendMode">
- Default blend mode. The color of the object is blended over the background based on the object's alpha value.
- </constant>
- <constant name="BLEND_MODE_ADD" value="1" enum="BlendMode">
- The color of the object is added to the background.
- </constant>
- <constant name="BLEND_MODE_SUB" value="2" enum="BlendMode">
- The color of the object is subtracted from the background.
- </constant>
- <constant name="BLEND_MODE_MUL" value="3" enum="BlendMode">
- The color of the object is multiplied by the background.
- </constant>
- <constant name="DEPTH_DRAW_OPAQUE_ONLY" value="0" enum="DepthDrawMode">
- Default depth draw mode. Depth is drawn only for opaque objects.
- </constant>
- <constant name="DEPTH_DRAW_ALWAYS" value="1" enum="DepthDrawMode">
- Depth draw is calculated for both opaque and transparent objects.
- </constant>
- <constant name="DEPTH_DRAW_DISABLED" value="2" enum="DepthDrawMode">
- No depth draw.
- </constant>
- <constant name="DEPTH_DRAW_ALPHA_OPAQUE_PREPASS" value="3" enum="DepthDrawMode">
- For transparent objects, an opaque pass is made first with the opaque parts, then transparency is drawn.
- </constant>
- <constant name="CULL_BACK" value="0" enum="CullMode">
- Default cull mode. The back of the object is culled when not visible.
- </constant>
- <constant name="CULL_FRONT" value="1" enum="CullMode">
- The front of the object is culled when not visible.
- </constant>
- <constant name="CULL_DISABLED" value="2" enum="CullMode">
- No culling is performed.
- </constant>
- <constant name="FLAG_UNSHADED" value="0" enum="Flags">
- No lighting is used on the object. Color comes directly from [code]ALBEDO[/code].
- </constant>
- <constant name="FLAG_USE_VERTEX_LIGHTING" value="1" enum="Flags">
- Lighting is calculated per-vertex rather than per-pixel. This can be used to increase the speed of the shader at the cost of quality.
- </constant>
- <constant name="FLAG_DISABLE_DEPTH_TEST" value="2" enum="Flags">
- Disables the depth test, so this object is drawn on top of all others. However, objects drawn after it in the draw order may cover it.
- </constant>
- <constant name="FLAG_ALBEDO_FROM_VERTEX_COLOR" value="3" enum="Flags">
- Set [code]ALBEDO[/code] to the per-vertex color specified in the mesh.
- </constant>
- <constant name="FLAG_SRGB_VERTEX_COLOR" value="4" enum="Flags">
- Vertex color is in sRGB space and needs to be converted to linear. Only applies in the GLES3 renderer.
- </constant>
- <constant name="FLAG_USE_POINT_SIZE" value="5" enum="Flags">
- Uses point size to alter the size of primitive points. Also changes the albedo texture lookup to use [code]POINT_COORD[/code] instead of [code]UV[/code].
- </constant>
- <constant name="FLAG_FIXED_SIZE" value="6" enum="Flags">
- Object is scaled by depth so that it always appears the same size on screen.
- </constant>
- <constant name="FLAG_BILLBOARD_KEEP_SCALE" value="7" enum="Flags">
- Shader will keep the scale set for the mesh. Otherwise the scale is lost when billboarding. Only applies when [member params_billboard_mode] is [constant BILLBOARD_ENABLED].
- </constant>
- <constant name="FLAG_UV1_USE_TRIPLANAR" value="8" enum="Flags">
- Use triplanar texture lookup for all texture lookups that would normally use [code]UV[/code].
- </constant>
- <constant name="FLAG_UV2_USE_TRIPLANAR" value="9" enum="Flags">
- Use triplanar texture lookup for all texture lookups that would normally use [code]UV2[/code].
- </constant>
- <constant name="FLAG_AO_ON_UV2" value="11" enum="Flags">
- Use [code]UV2[/code] coordinates to look up from the [member ao_texture].
- </constant>
- <constant name="FLAG_EMISSION_ON_UV2" value="12" enum="Flags">
- Use [code]UV2[/code] coordinates to look up from the [member emission_texture].
- </constant>
- <constant name="FLAG_USE_ALPHA_SCISSOR" value="13" enum="Flags">
- Use alpha scissor. Set by [member params_use_alpha_scissor].
- </constant>
- <constant name="FLAG_TRIPLANAR_USE_WORLD" value="10" enum="Flags">
- Use world coordinates in the triplanar texture lookup instead of local coordinates.
- </constant>
- <constant name="FLAG_ALBEDO_TEXTURE_FORCE_SRGB" value="14" enum="Flags">
- Forces the shader to convert albedo from sRGB space to linear space.
- </constant>
- <constant name="FLAG_DONT_RECEIVE_SHADOWS" value="15" enum="Flags">
- Disables receiving shadows from other objects.
- </constant>
- <constant name="FLAG_DISABLE_AMBIENT_LIGHT" value="17" enum="Flags">
- Disables receiving ambient light.
- </constant>
- <constant name="FLAG_ENSURE_CORRECT_NORMALS" value="16" enum="Flags">
- Ensures that normals appear correct, even with non-uniform scaling.
- </constant>
- <constant name="FLAG_USE_SHADOW_TO_OPACITY" value="18" enum="Flags">
- Enables the shadow to opacity feature.
- </constant>
- <constant name="FLAG_MAX" value="19" enum="Flags">
- Represents the size of the [enum Flags] enum.
- </constant>
- <constant name="DIFFUSE_BURLEY" value="0" enum="DiffuseMode">
- Default diffuse scattering algorithm.
- </constant>
- <constant name="DIFFUSE_LAMBERT" value="1" enum="DiffuseMode">
- Diffuse scattering ignores roughness.
- </constant>
- <constant name="DIFFUSE_LAMBERT_WRAP" value="2" enum="DiffuseMode">
- Extends Lambert to cover more than 90 degrees when roughness increases.
- </constant>
- <constant name="DIFFUSE_OREN_NAYAR" value="3" enum="DiffuseMode">
- Attempts to use roughness to emulate microsurfacing.
- </constant>
- <constant name="DIFFUSE_TOON" value="4" enum="DiffuseMode">
- Uses a hard cut for lighting, with smoothing affected by roughness.
- </constant>
- <constant name="SPECULAR_SCHLICK_GGX" value="0" enum="SpecularMode">
- Default specular blob.
- </constant>
- <constant name="SPECULAR_BLINN" value="1" enum="SpecularMode">
- Older specular algorithm, included for compatibility.
- </constant>
- <constant name="SPECULAR_PHONG" value="2" enum="SpecularMode">
- Older specular algorithm, included for compatibility.
- </constant>
- <constant name="SPECULAR_TOON" value="3" enum="SpecularMode">
- Toon blob which changes size based on roughness.
- </constant>
- <constant name="SPECULAR_DISABLED" value="4" enum="SpecularMode">
- No specular blob.
- </constant>
- <constant name="BILLBOARD_DISABLED" value="0" enum="BillboardMode">
- Billboard mode is disabled.
- </constant>
- <constant name="BILLBOARD_ENABLED" value="1" enum="BillboardMode">
- The object's Z axis will always face the camera.
- </constant>
- <constant name="BILLBOARD_FIXED_Y" value="2" enum="BillboardMode">
- The object's X axis will always face the camera.
- </constant>
- <constant name="BILLBOARD_PARTICLES" value="3" enum="BillboardMode">
- Used for particle systems when assigned to [Particles] and [CPUParticles] nodes. Enables [code]particles_anim_*[/code] properties.
- The [member ParticlesMaterial.anim_speed] or [member CPUParticles.anim_speed] should also be set to a positive value for the animation to play.
- </constant>
- <constant name="TEXTURE_CHANNEL_RED" value="0" enum="TextureChannel">
- Used to read from the red channel of a texture.
- </constant>
- <constant name="TEXTURE_CHANNEL_GREEN" value="1" enum="TextureChannel">
- Used to read from the green channel of a texture.
- </constant>
- <constant name="TEXTURE_CHANNEL_BLUE" value="2" enum="TextureChannel">
- Used to read from the blue channel of a texture.
- </constant>
- <constant name="TEXTURE_CHANNEL_ALPHA" value="3" enum="TextureChannel">
- Used to read from the alpha channel of a texture.
- </constant>
- <constant name="TEXTURE_CHANNEL_GRAYSCALE" value="4" enum="TextureChannel">
- Currently unused.
- </constant>
- <constant name="EMISSION_OP_ADD" value="0" enum="EmissionOperator">
- Adds the emission color to the color from the emission texture.
- </constant>
- <constant name="EMISSION_OP_MULTIPLY" value="1" enum="EmissionOperator">
- Multiplies the emission color by the color from the emission texture.
- </constant>
- <constant name="DISTANCE_FADE_DISABLED" value="0" enum="DistanceFadeMode">
- Do not use distance fade.
- </constant>
- <constant name="DISTANCE_FADE_PIXEL_ALPHA" value="1" enum="DistanceFadeMode">
- Smoothly fades the object out based on each pixel's distance from the camera using the alpha channel.
- </constant>
- <constant name="DISTANCE_FADE_PIXEL_DITHER" value="2" enum="DistanceFadeMode">
- Smoothly fades the object out based on each pixel's distance from the camera using a dither approach. Dithering discards pixels based on a set pattern to smoothly fade without enabling transparency. On certain hardware this can be faster than [constant DISTANCE_FADE_PIXEL_ALPHA].
- </constant>
- <constant name="DISTANCE_FADE_OBJECT_DITHER" value="3" enum="DistanceFadeMode">
- Smoothly fades the object out based on the object's distance from the camera using a dither approach. Dithering discards pixels based on a set pattern to smoothly fade without enabling transparency. On certain hardware this can be faster than [constant DISTANCE_FADE_PIXEL_ALPHA].
- </constant>
- </constants>
-</class>
diff --git a/doc/classes/SpinBox.xml b/doc/classes/SpinBox.xml
index 3b8bb7fb4b..c8ba8ab697 100644
--- a/doc/classes/SpinBox.xml
+++ b/doc/classes/SpinBox.xml
@@ -51,8 +51,8 @@
<constants>
</constants>
<theme_items>
- <theme_item name="updown" type="Texture">
- Sets a custom [Texture] for up and down arrows of the [SpinBox].
+ <theme_item name="updown" type="Texture2D">
+ Sets a custom [Texture2D] for up and down arrows of the [SpinBox].
</theme_item>
</theme_items>
</class>
diff --git a/doc/classes/Sprite.xml b/doc/classes/Sprite.xml
index 5f82f76911..89cdae1dff 100644
--- a/doc/classes/Sprite.xml
+++ b/doc/classes/Sprite.xml
@@ -52,7 +52,7 @@
<member name="hframes" type="int" setter="set_hframes" getter="get_hframes" default="1">
The number of columns in the sprite sheet.
</member>
- <member name="normal_map" type="Texture" setter="set_normal_map" getter="get_normal_map">
+ <member name="normal_map" type="Texture2D" setter="set_normal_map" getter="get_normal_map">
The normal map gives depth to the Sprite.
</member>
<member name="offset" type="Vector2" setter="set_offset" getter="get_offset" default="Vector2( 0, 0 )">
@@ -67,8 +67,14 @@
<member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2( 0, 0, 0, 0 )">
The region of the atlas texture to display. [member region_enabled] must be [code]true[/code].
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
- [Texture] object to draw.
+ <member name="shininess" type="float" setter="set_shininess" getter="get_shininess" default="1.0">
+ </member>
+ <member name="specular_color" type="Color" setter="set_specular_color" getter="get_specular_color" default="Color( 1, 1, 1, 1 )">
+ </member>
+ <member name="specular_map" type="Texture2D" setter="set_specular_map" getter="get_specular_map">
+ </member>
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ [Texture2D] object to draw.
</member>
<member name="vframes" type="int" setter="set_vframes" getter="get_vframes" default="1">
The number of rows in the sprite sheet.
diff --git a/doc/classes/Sprite3D.xml b/doc/classes/Sprite3D.xml
index a082a297f8..4c12399761 100644
--- a/doc/classes/Sprite3D.xml
+++ b/doc/classes/Sprite3D.xml
@@ -26,8 +26,8 @@
<member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2( 0, 0, 0, 0 )">
The region of the atlas texture to display. [member region_enabled] must be [code]true[/code].
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
- [Texture] object to draw.
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ [Texture2D] object to draw.
</member>
<member name="vframes" type="int" setter="set_vframes" getter="get_vframes" default="1">
The number of rows in the sprite sheet.
diff --git a/doc/classes/SpriteBase3D.xml b/doc/classes/SpriteBase3D.xml
index 8a923b4521..aaea4178fb 100644
--- a/doc/classes/SpriteBase3D.xml
+++ b/doc/classes/SpriteBase3D.xml
@@ -46,7 +46,7 @@
<member name="axis" type="int" setter="set_axis" getter="get_axis" enum="Vector3.Axis" default="2">
The direction in which the front of the texture faces.
</member>
- <member name="billboard" type="int" setter="set_billboard_mode" getter="get_billboard_mode" enum="SpatialMaterial.BillboardMode" default="0">
+ <member name="billboard" type="int" setter="set_billboard_mode" getter="get_billboard_mode" enum="BaseMaterial3D.BillboardMode" default="0">
</member>
<member name="centered" type="bool" setter="set_centered" getter="is_centered" default="true">
If [code]true[/code], texture will be centered.
diff --git a/doc/classes/SpriteFrames.xml b/doc/classes/SpriteFrames.xml
index 30690392e9..fe4b888a3c 100644
--- a/doc/classes/SpriteFrames.xml
+++ b/doc/classes/SpriteFrames.xml
@@ -23,7 +23,7 @@
</return>
<argument index="0" name="anim" type="String">
</argument>
- <argument index="1" name="frame" type="Texture">
+ <argument index="1" name="frame" type="Texture2D">
</argument>
<argument index="2" name="at_position" type="int" default="-1">
</argument>
@@ -73,7 +73,7 @@
</description>
</method>
<method name="get_frame" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="anim" type="String">
</argument>
@@ -161,7 +161,7 @@
</argument>
<argument index="1" name="idx" type="int">
</argument>
- <argument index="2" name="txt" type="Texture">
+ <argument index="2" name="txt" type="Texture2D">
</argument>
<description>
Sets the texture of the given frame.
diff --git a/doc/classes/StandardMaterial3D.xml b/doc/classes/StandardMaterial3D.xml
new file mode 100644
index 0000000000..4ed9146e0f
--- /dev/null
+++ b/doc/classes/StandardMaterial3D.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="StandardMaterial3D" inherits="BaseMaterial3D" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/StreamTexture.xml b/doc/classes/StreamTexture.xml
index 75e2661db0..a2d26d3d14 100644
--- a/doc/classes/StreamTexture.xml
+++ b/doc/classes/StreamTexture.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="StreamTexture" inherits="Texture" version="4.0">
+<class name="StreamTexture" inherits="Texture2D" version="4.0">
<brief_description>
A [code].stex[/code] texture.
</brief_description>
@@ -19,7 +19,6 @@
</method>
</methods>
<members>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="0" />
<member name="load_path" type="String" setter="load" getter="get_load_path" default="&quot;&quot;">
The StreamTexture's file path to a [code].stex[/code] file.
</member>
diff --git a/doc/classes/StyleBoxTexture.xml b/doc/classes/StyleBoxTexture.xml
index 0e9add964d..8ed94c8c26 100644
--- a/doc/classes/StyleBoxTexture.xml
+++ b/doc/classes/StyleBoxTexture.xml
@@ -119,14 +119,14 @@
<member name="modulate_color" type="Color" setter="set_modulate" getter="get_modulate" default="Color( 1, 1, 1, 1 )">
Modulates the color of the texture when this style box is drawn.
</member>
- <member name="normal_map" type="Texture" setter="set_normal_map" getter="get_normal_map">
+ <member name="normal_map" type="Texture2D" setter="set_normal_map" getter="get_normal_map">
The normal map to use when drawing this style box.
</member>
<member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2( 0, 0, 0, 0 )">
Species a sub-region of the texture to use.
This is equivalent to first wrapping the texture in an [AtlasTexture] with the same region.
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
The texture to use when drawing this style box.
</member>
</members>
diff --git a/doc/classes/SurfaceTool.xml b/doc/classes/SurfaceTool.xml
index ef9666b5ec..23363fcad5 100644
--- a/doc/classes/SurfaceTool.xml
+++ b/doc/classes/SurfaceTool.xml
@@ -163,7 +163,7 @@
</return>
<argument index="0" name="existing" type="ArrayMesh" default="null">
</argument>
- <argument index="1" name="flags" type="int" default="97280">
+ <argument index="1" name="flags" type="int" default="31744">
</argument>
<description>
Returns a constructed [ArrayMesh] from current information passed in. If an existing [ArrayMesh] is passed in as an argument, will add an extra surface to the existing [ArrayMesh].
diff --git a/doc/classes/TabContainer.xml b/doc/classes/TabContainer.xml
index ee26be472c..73b5afe6a7 100644
--- a/doc/classes/TabContainer.xml
+++ b/doc/classes/TabContainer.xml
@@ -59,12 +59,12 @@
</description>
</method>
<method name="get_tab_icon" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="tab_idx" type="int">
</argument>
<description>
- Returns the [Texture] for the tab at index [code]tab_idx[/code] or [code]null[/code] if the tab has no [Texture].
+ Returns the [Texture2D] for the tab at index [code]tab_idx[/code] or [code]null[/code] if the tab has no [Texture2D].
</description>
</method>
<method name="get_tab_title" qualifiers="const">
@@ -109,7 +109,7 @@
</return>
<argument index="0" name="tab_idx" type="int">
</argument>
- <argument index="1" name="icon" type="Texture">
+ <argument index="1" name="icon" type="Texture2D">
</argument>
<description>
Sets an icon for the tab at index [code]tab_idx[/code].
@@ -186,9 +186,9 @@
</constant>
</constants>
<theme_items>
- <theme_item name="decrement" type="Texture">
+ <theme_item name="decrement" type="Texture2D">
</theme_item>
- <theme_item name="decrement_highlight" type="Texture">
+ <theme_item name="decrement_highlight" type="Texture2D">
</theme_item>
<theme_item name="font" type="Font">
</theme_item>
@@ -200,17 +200,17 @@
</theme_item>
<theme_item name="hseparation" type="int" default="4">
</theme_item>
- <theme_item name="increment" type="Texture">
+ <theme_item name="increment" type="Texture2D">
</theme_item>
- <theme_item name="increment_highlight" type="Texture">
+ <theme_item name="increment_highlight" type="Texture2D">
</theme_item>
<theme_item name="label_valign_bg" type="int" default="2">
</theme_item>
<theme_item name="label_valign_fg" type="int" default="0">
</theme_item>
- <theme_item name="menu" type="Texture">
+ <theme_item name="menu" type="Texture2D">
</theme_item>
- <theme_item name="menu_highlight" type="Texture">
+ <theme_item name="menu_highlight" type="Texture2D">
</theme_item>
<theme_item name="panel" type="StyleBox">
</theme_item>
diff --git a/doc/classes/Tabs.xml b/doc/classes/Tabs.xml
index ae455f8043..266a733f8f 100644
--- a/doc/classes/Tabs.xml
+++ b/doc/classes/Tabs.xml
@@ -14,7 +14,7 @@
</return>
<argument index="0" name="title" type="String" default="&quot;&quot;">
</argument>
- <argument index="1" name="icon" type="Texture" default="null">
+ <argument index="1" name="icon" type="Texture2D" default="null">
</argument>
<description>
Adds a new tab.
@@ -60,12 +60,12 @@
</description>
</method>
<method name="get_tab_icon" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="tab_idx" type="int">
</argument>
<description>
- Returns the [Texture] for the tab at index [code]tab_idx[/code] or [code]null[/code] if the tab has no [Texture].
+ Returns the [Texture2D] for the tab at index [code]tab_idx[/code] or [code]null[/code] if the tab has no [Texture2D].
</description>
</method>
<method name="get_tab_offset" qualifiers="const">
@@ -146,7 +146,7 @@
</return>
<argument index="0" name="tab_idx" type="int">
</argument>
- <argument index="1" name="icon" type="Texture">
+ <argument index="1" name="icon" type="Texture2D">
</argument>
<description>
Sets an [code]icon[/code] for the tab at index [code]tab_idx[/code].
@@ -265,11 +265,11 @@
</theme_item>
<theme_item name="button_pressed" type="StyleBox">
</theme_item>
- <theme_item name="close" type="Texture">
+ <theme_item name="close" type="Texture2D">
</theme_item>
- <theme_item name="decrement" type="Texture">
+ <theme_item name="decrement" type="Texture2D">
</theme_item>
- <theme_item name="decrement_highlight" type="Texture">
+ <theme_item name="decrement_highlight" type="Texture2D">
</theme_item>
<theme_item name="font" type="Font">
</theme_item>
@@ -281,9 +281,9 @@
</theme_item>
<theme_item name="hseparation" type="int" default="4">
</theme_item>
- <theme_item name="increment" type="Texture">
+ <theme_item name="increment" type="Texture2D">
</theme_item>
- <theme_item name="increment_highlight" type="Texture">
+ <theme_item name="increment_highlight" type="Texture2D">
</theme_item>
<theme_item name="label_valign_bg" type="int" default="2">
</theme_item>
diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml
index eb3b72f627..c4a05db3a7 100644
--- a/doc/classes/TextEdit.xml
+++ b/doc/classes/TextEdit.xml
@@ -592,9 +592,9 @@
</theme_item>
<theme_item name="focus" type="StyleBox">
</theme_item>
- <theme_item name="fold" type="Texture">
+ <theme_item name="fold" type="Texture2D">
</theme_item>
- <theme_item name="folded" type="Texture">
+ <theme_item name="folded" type="Texture2D">
</theme_item>
<theme_item name="font" type="Font">
Sets the default [Font].
@@ -632,12 +632,12 @@
<theme_item name="selection_color" type="Color" default="Color( 0.49, 0.49, 0.49, 1 )">
Sets the highlight [Color] of text selections.
</theme_item>
- <theme_item name="space" type="Texture">
+ <theme_item name="space" type="Texture2D">
</theme_item>
<theme_item name="symbol_color" type="Color" default="Color( 0.94, 0.94, 0.94, 1 )">
</theme_item>
- <theme_item name="tab" type="Texture">
- Sets a custom [Texture] for tab text characters.
+ <theme_item name="tab" type="Texture2D">
+ Sets a custom [Texture2D] for tab text characters.
</theme_item>
<theme_item name="word_highlighted_color" type="Color" default="Color( 0.8, 0.9, 0.9, 0.15 )">
Sets the highlight [Color] of multiple occurrences. [member highlight_all_occurrences] has to be enabled.
diff --git a/doc/classes/Texture.xml b/doc/classes/Texture.xml
index 592f822ecc..e19d611ea9 100644
--- a/doc/classes/Texture.xml
+++ b/doc/classes/Texture.xml
@@ -1,139 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Texture" inherits="Resource" version="4.0">
<brief_description>
- Texture for 2D and 3D.
</brief_description>
<description>
- A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D [Sprite] or GUI [Control].
- Textures are often created by loading them from a file. See [method @GDScript.load].
- [Texture] is a base for other resources. It cannot be used directly.
</description>
<tutorials>
</tutorials>
<methods>
- <method name="draw" qualifiers="const">
- <return type="void">
- </return>
- <argument index="0" name="canvas_item" type="RID">
- </argument>
- <argument index="1" name="position" type="Vector2">
- </argument>
- <argument index="2" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
- </argument>
- <argument index="3" name="transpose" type="bool" default="false">
- </argument>
- <argument index="4" name="normal_map" type="Texture" default="null">
- </argument>
- <description>
- Draws the texture using a [CanvasItem] with the [VisualServer] API at the specified [code]position[/code]. Equivalent to [method VisualServer.canvas_item_add_texture_rect] with a rect at [code]position[/code] and the size of this [Texture].
- </description>
- </method>
- <method name="draw_rect" qualifiers="const">
- <return type="void">
- </return>
- <argument index="0" name="canvas_item" type="RID">
- </argument>
- <argument index="1" name="rect" type="Rect2">
- </argument>
- <argument index="2" name="tile" type="bool">
- </argument>
- <argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
- </argument>
- <argument index="4" name="transpose" type="bool" default="false">
- </argument>
- <argument index="5" name="normal_map" type="Texture" default="null">
- </argument>
- <description>
- Draws the texture using a [CanvasItem] with the [VisualServer] API. Equivalent to [method VisualServer.canvas_item_add_texture_rect].
- </description>
- </method>
- <method name="draw_rect_region" qualifiers="const">
- <return type="void">
- </return>
- <argument index="0" name="canvas_item" type="RID">
- </argument>
- <argument index="1" name="rect" type="Rect2">
- </argument>
- <argument index="2" name="src_rect" type="Rect2">
- </argument>
- <argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
- </argument>
- <argument index="4" name="transpose" type="bool" default="false">
- </argument>
- <argument index="5" name="normal_map" type="Texture" default="null">
- </argument>
- <argument index="6" name="clip_uv" type="bool" default="true">
- </argument>
- <description>
- Draws a part of the texture using a [CanvasItem] with the [VisualServer] API. Equivalent to [method VisualServer.canvas_item_add_texture_rect_region].
- </description>
- </method>
- <method name="get_data" qualifiers="const">
- <return type="Image">
- </return>
- <description>
- Returns an [Image] with the data from this [Texture]. [Image]s can be accessed and manipulated directly.
- </description>
- </method>
- <method name="get_height" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the texture height.
- </description>
- </method>
- <method name="get_size" qualifiers="const">
- <return type="Vector2">
- </return>
- <description>
- Returns the texture size.
- </description>
- </method>
- <method name="get_width" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the texture width.
- </description>
- </method>
- <method name="has_alpha" qualifiers="const">
- <return type="bool">
- </return>
- <description>
- Returns [code]true[/code] if this [Texture] has an alpha channel.
- </description>
- </method>
</methods>
- <members>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" default="4">
- The texture's [enum Flags]. [enum Flags] are used to set various properties of the [Texture].
- </member>
- </members>
<constants>
- <constant name="FLAGS_DEFAULT" value="7" enum="Flags">
- Default flags. [constant FLAG_MIPMAPS], [constant FLAG_REPEAT] and [constant FLAG_FILTER] are enabled.
- </constant>
- <constant name="FLAG_MIPMAPS" value="1" enum="Flags">
- Generates mipmaps, which are smaller versions of the same texture to use when zoomed out, keeping the aspect ratio.
- </constant>
- <constant name="FLAG_REPEAT" value="2" enum="Flags">
- Repeats the texture (instead of clamp to edge).
- </constant>
- <constant name="FLAG_FILTER" value="4" enum="Flags">
- Uses a magnifying filter, to enable smooth zooming in of the texture.
- </constant>
- <constant name="FLAG_ANISOTROPIC_FILTER" value="8" enum="Flags">
- Uses anisotropic mipmap filtering. Generates smaller versions of the same texture with different aspect ratios.
- This results in better-looking textures when viewed from oblique angles.
- </constant>
- <constant name="FLAG_CONVERT_TO_LINEAR" value="16" enum="Flags">
- Converts the texture to the sRGB color space.
- </constant>
- <constant name="FLAG_MIRRORED_REPEAT" value="32" enum="Flags">
- Repeats the texture with alternate sections mirrored.
- </constant>
- <constant name="FLAG_VIDEO_SURFACE" value="2048" enum="Flags">
- Texture is a video surface.
- </constant>
</constants>
</class>
diff --git a/doc/classes/Texture2D.xml b/doc/classes/Texture2D.xml
new file mode 100644
index 0000000000..2ccb469eb1
--- /dev/null
+++ b/doc/classes/Texture2D.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="Texture2D" inherits="Resource" version="4.0">
+ <brief_description>
+ Texture for 2D and 3D.
+ </brief_description>
+ <description>
+ A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D [Sprite] or GUI [Control].
+ Textures are often created by loading them from a file. See [method @GDScript.load].
+ [Texture2D] is a base for other resources. It cannot be used directly.
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ <method name="draw" qualifiers="const">
+ <return type="void">
+ </return>
+ <argument index="0" name="canvas_item" type="RID">
+ </argument>
+ <argument index="1" name="position" type="Vector2">
+ </argument>
+ <argument index="2" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="3" name="transpose" type="bool" default="false">
+ </argument>
+ <argument index="4" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="5" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="6" name="specular_color_shininess" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="7" name="texture_filter" type="int" enum="VisualServer.CanvasItemTextureFilter" default="0">
+ </argument>
+ <argument index="8" name="texture_repeat" type="int" enum="VisualServer.CanvasItemTextureRepeat" default="0">
+ </argument>
+ <description>
+ Draws the texture using a [CanvasItem] with the [VisualServer] API at the specified [code]position[/code].
+ </description>
+ </method>
+ <method name="draw_rect" qualifiers="const">
+ <return type="void">
+ </return>
+ <argument index="0" name="canvas_item" type="RID">
+ </argument>
+ <argument index="1" name="rect" type="Rect2">
+ </argument>
+ <argument index="2" name="tile" type="bool">
+ </argument>
+ <argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="4" name="transpose" type="bool" default="false">
+ </argument>
+ <argument index="5" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="6" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="7" name="specular_color_shininess" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="8" name="texture_filter" type="int" enum="VisualServer.CanvasItemTextureFilter" default="0">
+ </argument>
+ <argument index="9" name="texture_repeat" type="int" enum="VisualServer.CanvasItemTextureRepeat" default="0">
+ </argument>
+ <description>
+ Draws the texture using a [CanvasItem] with the [VisualServer] API.
+ </description>
+ </method>
+ <method name="draw_rect_region" qualifiers="const">
+ <return type="void">
+ </return>
+ <argument index="0" name="canvas_item" type="RID">
+ </argument>
+ <argument index="1" name="rect" type="Rect2">
+ </argument>
+ <argument index="2" name="src_rect" type="Rect2">
+ </argument>
+ <argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="4" name="transpose" type="bool" default="false">
+ </argument>
+ <argument index="5" name="normal_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="6" name="specular_map" type="Texture2D" default="null">
+ </argument>
+ <argument index="7" name="specular_color_shininess" type="Color" default="Color( 1, 1, 1, 1 )">
+ </argument>
+ <argument index="8" name="texture_filter" type="int" enum="VisualServer.CanvasItemTextureFilter" default="0">
+ </argument>
+ <argument index="9" name="texture_repeat" type="int" enum="VisualServer.CanvasItemTextureRepeat" default="0">
+ </argument>
+ <argument index="10" name="clip_uv" type="bool" default="true">
+ </argument>
+ <description>
+ Draws a part of the texture using a [CanvasItem] with the [VisualServer] API.
+ </description>
+ </method>
+ <method name="get_data" qualifiers="const">
+ <return type="Image">
+ </return>
+ <description>
+ Returns an [Image] with the data from this [Texture2D]. [Image]s can be accessed and manipulated directly.
+ </description>
+ </method>
+ <method name="get_height" qualifiers="const">
+ <return type="int">
+ </return>
+ <description>
+ Returns the texture height.
+ </description>
+ </method>
+ <method name="get_size" qualifiers="const">
+ <return type="Vector2">
+ </return>
+ <description>
+ Returns the texture size.
+ </description>
+ </method>
+ <method name="get_width" qualifiers="const">
+ <return type="int">
+ </return>
+ <description>
+ Returns the texture width.
+ </description>
+ </method>
+ <method name="has_alpha" qualifiers="const">
+ <return type="bool">
+ </return>
+ <description>
+ Returns [code]true[/code] if this [Texture2D] has an alpha channel.
+ </description>
+ </method>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/Texture2DArray.xml b/doc/classes/Texture2DArray.xml
new file mode 100644
index 0000000000..657506120e
--- /dev/null
+++ b/doc/classes/Texture2DArray.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="Texture2DArray" inherits="TextureLayered" version="4.0">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/Texture3D.xml b/doc/classes/Texture3D.xml
deleted file mode 100644
index bc16cd015f..0000000000
--- a/doc/classes/Texture3D.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="Texture3D" inherits="TextureLayered" version="4.0">
- <brief_description>
- Texture with 3 dimensions.
- </brief_description>
- <description>
- Texture3D is a 3-dimensional texture that has a width, height, and depth.
- </description>
- <tutorials>
- </tutorials>
- <methods>
- </methods>
- <members>
- <member name="data" type="Dictionary" setter="_set_data" getter="_get_data" override="true" default="{&quot;depth&quot;: 0,&quot;flags&quot;: 4,&quot;format&quot;: 37,&quot;height&quot;: 0,&quot;layers&quot;: [ ],&quot;width&quot;: 0}" />
- </members>
- <constants>
- </constants>
-</class>
diff --git a/doc/classes/TextureArray.xml b/doc/classes/TextureArray.xml
deleted file mode 100644
index b652a1c6bc..0000000000
--- a/doc/classes/TextureArray.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="TextureArray" inherits="TextureLayered" version="4.0">
- <brief_description>
- Array of textures stored in a single primitive.
- </brief_description>
- <description>
- [TextureArray]s store an array of images in a single [Texture] primitive. Each layer of the texture array has its own mipmap chain. This makes it is a good alternative to texture atlases.
- </description>
- <tutorials>
- </tutorials>
- <methods>
- </methods>
- <constants>
- </constants>
-</class>
diff --git a/doc/classes/TextureButton.xml b/doc/classes/TextureButton.xml
index be717e9817..0e2872755e 100644
--- a/doc/classes/TextureButton.xml
+++ b/doc/classes/TextureButton.xml
@@ -21,19 +21,19 @@
<member name="texture_click_mask" type="BitMap" setter="set_click_mask" getter="get_click_mask">
Pure black and white [BitMap] image to use for click detection. On the mask, white pixels represent the button's clickable area. Use it to create buttons with curved shapes.
</member>
- <member name="texture_disabled" type="Texture" setter="set_disabled_texture" getter="get_disabled_texture">
+ <member name="texture_disabled" type="Texture2D" setter="set_disabled_texture" getter="get_disabled_texture">
Texture to display when the node is disabled. See [member BaseButton.disabled].
</member>
- <member name="texture_focused" type="Texture" setter="set_focused_texture" getter="get_focused_texture">
+ <member name="texture_focused" type="Texture2D" setter="set_focused_texture" getter="get_focused_texture">
Texture to display when the node has mouse or keyboard focus.
</member>
- <member name="texture_hover" type="Texture" setter="set_hover_texture" getter="get_hover_texture">
+ <member name="texture_hover" type="Texture2D" setter="set_hover_texture" getter="get_hover_texture">
Texture to display when the mouse hovers the node.
</member>
- <member name="texture_normal" type="Texture" setter="set_normal_texture" getter="get_normal_texture">
+ <member name="texture_normal" type="Texture2D" setter="set_normal_texture" getter="get_normal_texture">
Texture to display by default, when the node is [b]not[/b] in the disabled, focused, hover or pressed state.
</member>
- <member name="texture_pressed" type="Texture" setter="set_pressed_texture" getter="get_pressed_texture">
+ <member name="texture_pressed" type="Texture2D" setter="set_pressed_texture" getter="get_pressed_texture">
Texture to display on mouse down over the node, if the node has keyboard focus and the player presses the Enter key or if the player presses the [member BaseButton.shortcut] key.
</member>
</members>
diff --git a/doc/classes/TextureLayered.xml b/doc/classes/TextureLayered.xml
index f20f46b6c4..f9ecdb02f0 100644
--- a/doc/classes/TextureLayered.xml
+++ b/doc/classes/TextureLayered.xml
@@ -4,33 +4,17 @@
Base class for 3D texture types.
</brief_description>
<description>
- Base class for [Texture3D] and [TextureArray]. Cannot be used directly, but contains all the functions necessary for accessing and using [Texture3D] and [TextureArray]. Data is set on a per-layer basis. For [Texture3D]s, the layer sepcifies the depth or Z-index, they can be treated as a bunch of 2D slices. Similarly, for [TextureArray]s, the layer specifies the array layer.
+ Base class for [Texture2DArray], [Cubemap] and [CubemapArray]. Cannot be used directly, but contains all the functions necessary for accessing the derived resource types. Data is set on a per-layer basis. For [Texture2DArray]s, the layer specifies the array layer.
</description>
<tutorials>
</tutorials>
<methods>
- <method name="create">
- <return type="void">
+ <method name="create_from_images">
+ <return type="int" enum="Error">
</return>
- <argument index="0" name="width" type="int">
- </argument>
- <argument index="1" name="height" type="int">
- </argument>
- <argument index="2" name="depth" type="int">
- </argument>
- <argument index="3" name="format" type="int" enum="Image.Format">
- </argument>
- <argument index="4" name="flags" type="int" default="4">
+ <argument index="0" name="images" type="Array">
</argument>
<description>
- Creates the [Texture3D] or [TextureArray] with specified [code]width[/code], [code]height[/code], and [code]depth[/code]. See [enum Image.Format] for [code]format[/code] options. See [enum Flags] enumerator for [code]flags[/code] options.
- </description>
- </method>
- <method name="get_depth" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the depth of the texture. Depth is the 3rd dimension (typically Z-axis).
</description>
</method>
<method name="get_format" qualifiers="const">
@@ -56,31 +40,20 @@
Returns an [Image] resource with the data from specified [code]layer[/code].
</description>
</method>
- <method name="get_width" qualifiers="const">
+ <method name="get_layers" qualifiers="const">
<return type="int">
</return>
<description>
- Returns the width of the texture. Width is typically represented by the X-axis.
</description>
</method>
- <method name="set_data_partial">
- <return type="void">
+ <method name="get_width" qualifiers="const">
+ <return type="int">
</return>
- <argument index="0" name="image" type="Image">
- </argument>
- <argument index="1" name="x_offset" type="int">
- </argument>
- <argument index="2" name="y_offset" type="int">
- </argument>
- <argument index="3" name="layer" type="int">
- </argument>
- <argument index="4" name="mipmap" type="int" default="0">
- </argument>
<description>
- Partially sets the data for a specified [code]layer[/code] by overwriting using the data of the specified [code]image[/code]. [code]x_offset[/code] and [code]y_offset[/code] determine where the [Image] is "stamped" over the texture. The [code]image[/code] must fit within the texture.
+ Returns the width of the texture. Width is typically represented by the X-axis.
</description>
</method>
- <method name="set_layer_data">
+ <method name="update_layer">
<return type="void">
</return>
<argument index="0" name="image" type="Image">
@@ -88,30 +61,9 @@
<argument index="1" name="layer" type="int">
</argument>
<description>
- Sets the data for the specified layer. Data takes the form of a 2-dimensional [Image] resource.
</description>
</method>
</methods>
- <members>
- <member name="data" type="Dictionary" setter="_set_data" getter="_get_data" default="{&quot;depth&quot;: 0,&quot;flags&quot;: 4,&quot;format&quot;: 37,&quot;height&quot;: 0,&quot;layers&quot;: [ ],&quot;width&quot;: 0}">
- Returns a dictionary with all the data used by this texture.
- </member>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" default="4">
- Specifies which [enum Flags] apply to this texture.
- </member>
- </members>
<constants>
- <constant name="FLAG_MIPMAPS" value="1" enum="Flags">
- Texture will generate mipmaps on creation.
- </constant>
- <constant name="FLAG_REPEAT" value="2" enum="Flags">
- Texture will repeat when UV used is outside the 0-1 range.
- </constant>
- <constant name="FLAG_FILTER" value="4" enum="Flags">
- Use filtering when reading from texture. Filtering smooths out pixels. Turning filtering off is slightly faster and more appropriate when you need access to individual pixels.
- </constant>
- <constant name="FLAGS_DEFAULT" value="4" enum="Flags">
- Equivalent to [constant FLAG_FILTER].
- </constant>
</constants>
</class>
diff --git a/doc/classes/TextureProgress.xml b/doc/classes/TextureProgress.xml
index 7f91206c2c..4937121ebf 100644
--- a/doc/classes/TextureProgress.xml
+++ b/doc/classes/TextureProgress.xml
@@ -58,15 +58,15 @@
<member name="stretch_margin_top" type="int" setter="set_stretch_margin" getter="get_stretch_margin" default="0">
The height of the 9-patch's top row.
</member>
- <member name="texture_over" type="Texture" setter="set_over_texture" getter="get_over_texture">
- [Texture] that draws over the progress bar. Use it to add highlights or an upper-frame that hides part of [member texture_progress].
+ <member name="texture_over" type="Texture2D" setter="set_over_texture" getter="get_over_texture">
+ [Texture2D] that draws over the progress bar. Use it to add highlights or an upper-frame that hides part of [member texture_progress].
</member>
- <member name="texture_progress" type="Texture" setter="set_progress_texture" getter="get_progress_texture">
- [Texture] that clips based on the node's [code]value[/code] and [member fill_mode]. As [code]value[/code] increased, the texture fills up. It shows entirely when [code]value[/code] reaches [code]max_value[/code]. It doesn't show at all if [code]value[/code] is equal to [code]min_value[/code].
+ <member name="texture_progress" type="Texture2D" setter="set_progress_texture" getter="get_progress_texture">
+ [Texture2D] that clips based on the node's [code]value[/code] and [member fill_mode]. As [code]value[/code] increased, the texture fills up. It shows entirely when [code]value[/code] reaches [code]max_value[/code]. It doesn't show at all if [code]value[/code] is equal to [code]min_value[/code].
The [code]value[/code] property comes from [Range]. See [member Range.value], [member Range.min_value], [member Range.max_value].
</member>
- <member name="texture_under" type="Texture" setter="set_under_texture" getter="get_under_texture">
- [Texture] that draws under the progress bar. The bar's background.
+ <member name="texture_under" type="Texture2D" setter="set_under_texture" getter="get_under_texture">
+ [Texture2D] that draws under the progress bar. The bar's background.
</member>
<member name="tint_over" type="Color" setter="set_tint_over" getter="get_tint_over" default="Color( 1, 1, 1, 1 )">
Multiplies the color of the bar's [code]texture_over[/code] texture. The effect is similar to [member CanvasItem.modulate], except it only affects this specific texture instead of the entire node.
diff --git a/doc/classes/TextureRect.xml b/doc/classes/TextureRect.xml
index 17c413c9f2..709d87b858 100644
--- a/doc/classes/TextureRect.xml
+++ b/doc/classes/TextureRect.xml
@@ -24,8 +24,8 @@
<member name="stretch_mode" type="int" setter="set_stretch_mode" getter="get_stretch_mode" enum="TextureRect.StretchMode" default="0">
Controls the texture's behavior when resizing the node's bounding rectangle. See [enum StretchMode].
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
- The node's [Texture] resource.
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
+ The node's [Texture2D] resource.
</member>
</members>
<constants>
diff --git a/doc/classes/Theme.xml b/doc/classes/Theme.xml
index f9beb5566d..d11cfc7aa2 100644
--- a/doc/classes/Theme.xml
+++ b/doc/classes/Theme.xml
@@ -150,14 +150,14 @@
</description>
</method>
<method name="get_icon" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="name" type="String">
</argument>
<argument index="1" name="type" type="String">
</argument>
<description>
- Returns the icon [Texture] at [code]name[/code] if the theme has [code]type[/code].
+ Returns the icon [Texture2D] at [code]name[/code] if the theme has [code]type[/code].
</description>
</method>
<method name="get_icon_list" qualifiers="const">
@@ -166,7 +166,7 @@
<argument index="0" name="type" type="String">
</argument>
<description>
- Returns all the icons as a [PoolStringArray] filled with each [Texture]'s name, for use in [method get_icon], if the theme has [code]type[/code].
+ Returns all the icons as a [PoolStringArray] filled with each [Texture2D]'s name, for use in [method get_icon], if the theme has [code]type[/code].
</description>
</method>
<method name="get_stylebox" qualifiers="const">
@@ -249,7 +249,7 @@
<argument index="1" name="type" type="String">
</argument>
<description>
- Returns [code]true[/code] if icon [Texture] with [code]name[/code] is in [code]type[/code].
+ Returns [code]true[/code] if icon [Texture2D] with [code]name[/code] is in [code]type[/code].
Returns [code]false[/code] if the theme does not have [code]type[/code].
</description>
</method>
@@ -314,10 +314,10 @@
</argument>
<argument index="1" name="type" type="String">
</argument>
- <argument index="2" name="texture" type="Texture">
+ <argument index="2" name="texture" type="Texture2D">
</argument>
<description>
- Sets the theme's icon [Texture] to [code]texture[/code] at [code]name[/code] in [code]type[/code].
+ Sets the theme's icon [Texture2D] to [code]texture[/code] at [code]name[/code] in [code]type[/code].
Does nothing if the theme does not have [code]type[/code].
</description>
</method>
diff --git a/doc/classes/TileSet.xml b/doc/classes/TileSet.xml
index 7bf5d8a0fe..65988ae2b7 100644
--- a/doc/classes/TileSet.xml
+++ b/doc/classes/TileSet.xml
@@ -381,7 +381,7 @@
</description>
</method>
<method name="tile_get_normal_map" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="id" type="int">
</argument>
@@ -480,7 +480,7 @@
</description>
</method>
<method name="tile_get_texture" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="id" type="int">
</argument>
@@ -586,7 +586,7 @@
</return>
<argument index="0" name="id" type="int">
</argument>
- <argument index="1" name="normal_map" type="Texture">
+ <argument index="1" name="normal_map" type="Texture2D">
</argument>
<description>
Sets the tile's normal map texture.
@@ -694,7 +694,7 @@
</return>
<argument index="0" name="id" type="int">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
Sets the tile's texture.
diff --git a/doc/classes/TouchScreenButton.xml b/doc/classes/TouchScreenButton.xml
index 52025a1b04..c7f886b3f2 100644
--- a/doc/classes/TouchScreenButton.xml
+++ b/doc/classes/TouchScreenButton.xml
@@ -24,13 +24,13 @@
<member name="bitmask" type="BitMap" setter="set_bitmask" getter="get_bitmask">
The button's bitmask.
</member>
- <member name="normal" type="Texture" setter="set_texture" getter="get_texture">
+ <member name="normal" type="Texture2D" setter="set_texture" getter="get_texture">
The button's texture for the normal state.
</member>
<member name="passby_press" type="bool" setter="set_passby_press" getter="is_passby_press_enabled" default="false">
If [code]true[/code], pass-by presses are enabled.
</member>
- <member name="pressed" type="Texture" setter="set_texture_pressed" getter="get_texture_pressed">
+ <member name="pressed" type="Texture2D" setter="set_texture_pressed" getter="get_texture_pressed">
The button's texture for the pressed state.
</member>
<member name="shape" type="Shape2D" setter="set_shape" getter="get_shape">
diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml
index 54aa85ff48..5fa24100ae 100644
--- a/doc/classes/Tree.xml
+++ b/doc/classes/Tree.xml
@@ -386,10 +386,10 @@
</constant>
</constants>
<theme_items>
- <theme_item name="arrow" type="Texture">
+ <theme_item name="arrow" type="Texture2D">
The arrow icon used when a foldable item is not collapsed.
</theme_item>
- <theme_item name="arrow_collapsed" type="Texture">
+ <theme_item name="arrow_collapsed" type="Texture2D">
The arrow icon used when a foldable item is collapsed.
</theme_item>
<theme_item name="bg" type="StyleBox">
@@ -404,7 +404,7 @@
<theme_item name="button_pressed" type="StyleBox">
[StyleBox] used when a button in the tree is pressed.
</theme_item>
- <theme_item name="checked" type="Texture">
+ <theme_item name="checked" type="Texture2D">
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is checked.
</theme_item>
<theme_item name="cursor" type="StyleBox">
@@ -461,7 +461,7 @@
<theme_item name="scroll_speed" type="int" default="12">
The speed of border scrolling.
</theme_item>
- <theme_item name="select_arrow" type="Texture">
+ <theme_item name="select_arrow" type="Texture2D">
The arrow icon to display for the [constant TreeItem.CELL_MODE_RANGE] mode cell.
</theme_item>
<theme_item name="selected" type="StyleBox">
@@ -485,10 +485,10 @@
<theme_item name="title_button_pressed" type="StyleBox">
[StyleBox] used when the title button is being pressed.
</theme_item>
- <theme_item name="unchecked" type="Texture">
+ <theme_item name="unchecked" type="Texture2D">
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is unchecked.
</theme_item>
- <theme_item name="updown" type="Texture">
+ <theme_item name="updown" type="Texture2D">
The updown arrow icon to display for the [constant TreeItem.CELL_MODE_RANGE] mode cell.
</theme_item>
<theme_item name="vseparation" type="int" default="4">
diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml
index bd9f8d36b5..e4d2af0c6e 100644
--- a/doc/classes/TreeItem.xml
+++ b/doc/classes/TreeItem.xml
@@ -14,7 +14,7 @@
</return>
<argument index="0" name="column" type="int">
</argument>
- <argument index="1" name="button" type="Texture">
+ <argument index="1" name="button" type="Texture2D">
</argument>
<argument index="2" name="button_idx" type="int" default="-1">
</argument>
@@ -23,7 +23,8 @@
<argument index="4" name="tooltip" type="String" default="&quot;&quot;">
</argument>
<description>
- Adds a button with [Texture] [code]button[/code] at column [code]column[/code]. The [code]button_idx[/code] index is used to identify the button when calling other methods. If not specified, the next available index is used, which may be retrieved by calling [method get_button_count] immediately after this method. Optionally, the button can be [code]disabled[/code] and have a [code]tooltip[/code].
+ Adds a button with [Texture2D] [code]button[/code] at column [code]column[/code]. The [code]button_idx[/code] index is used to identify the button when calling other methods. If not specified, the next available index is used, which may be retrieved by calling [method get_button_count] immediately after this method. Optionally, the button can be [code]disabled[/code] and have a [code]tooltip
+ [/code].
</description>
</method>
<method name="call_recursive" qualifiers="vararg">
@@ -74,14 +75,14 @@
</description>
</method>
<method name="get_button" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="column" type="int">
</argument>
<argument index="1" name="button_idx" type="int">
</argument>
<description>
- Returns the [Texture] of the button at index [code]button_idx[/code] in column [code]column[/code].
+ Returns the [Texture2D] of the button at index [code]button_idx[/code] in column [code]column[/code].
</description>
</method>
<method name="get_button_count" qualifiers="const">
@@ -148,12 +149,12 @@
</description>
</method>
<method name="get_icon" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<argument index="0" name="column" type="int">
</argument>
<description>
- Returns the given column's icon [Texture]. Error if no icon is set.
+ Returns the given column's icon [Texture2D]. Error if no icon is set.
</description>
</method>
<method name="get_icon_max_width" qualifiers="const">
@@ -180,7 +181,7 @@
<argument index="0" name="column" type="int">
</argument>
<description>
- Returns the icon [Texture] region as [Rect2].
+ Returns the icon [Texture2D] region as [Rect2].
</description>
</method>
<method name="get_metadata" qualifiers="const">
@@ -369,10 +370,10 @@
</argument>
<argument index="1" name="button_idx" type="int">
</argument>
- <argument index="2" name="button" type="Texture">
+ <argument index="2" name="button" type="Texture2D">
</argument>
<description>
- Sets the given column's button [Texture] at index [code]button_idx[/code] to [code]button[/code].
+ Sets the given column's button [Texture2D] at index [code]button_idx[/code] to [code]button[/code].
</description>
</method>
<method name="set_button_disabled">
@@ -485,10 +486,10 @@
</return>
<argument index="0" name="column" type="int">
</argument>
- <argument index="1" name="texture" type="Texture">
+ <argument index="1" name="texture" type="Texture2D">
</argument>
<description>
- Sets the given column's icon [Texture].
+ Sets the given column's icon [Texture2D].
</description>
</method>
<method name="set_icon_max_width">
diff --git a/doc/classes/VScrollBar.xml b/doc/classes/VScrollBar.xml
index dddbbb219b..727e32961c 100644
--- a/doc/classes/VScrollBar.xml
+++ b/doc/classes/VScrollBar.xml
@@ -17,10 +17,10 @@
<constants>
</constants>
<theme_items>
- <theme_item name="decrement" type="Texture">
+ <theme_item name="decrement" type="Texture2D">
Icon used as a button to scroll the [ScrollBar] up. Supports custom step using the [member ScrollBar.custom_step] property.
</theme_item>
- <theme_item name="decrement_highlight" type="Texture">
+ <theme_item name="decrement_highlight" type="Texture2D">
Displayed when the mouse cursor hovers over the decrement button.
</theme_item>
<theme_item name="grabber" type="StyleBox">
@@ -32,10 +32,10 @@
<theme_item name="grabber_pressed" type="StyleBox">
Used when the grabber is being dragged.
</theme_item>
- <theme_item name="increment" type="Texture">
+ <theme_item name="increment" type="Texture2D">
Icon used as a button to scroll the [ScrollBar] down. Supports custom step using the [member ScrollBar.custom_step] property.
</theme_item>
- <theme_item name="increment_highlight" type="Texture">
+ <theme_item name="increment_highlight" type="Texture2D">
Displayed when the mouse cursor hovers over the increment button.
</theme_item>
<theme_item name="scroll" type="StyleBox">
diff --git a/doc/classes/VSlider.xml b/doc/classes/VSlider.xml
index 9e0b2e0453..cbc4ac1a13 100644
--- a/doc/classes/VSlider.xml
+++ b/doc/classes/VSlider.xml
@@ -17,17 +17,17 @@
<constants>
</constants>
<theme_items>
- <theme_item name="grabber" type="Texture">
+ <theme_item name="grabber" type="Texture2D">
</theme_item>
<theme_item name="grabber_area" type="StyleBox">
</theme_item>
- <theme_item name="grabber_disabled" type="Texture">
+ <theme_item name="grabber_disabled" type="Texture2D">
</theme_item>
- <theme_item name="grabber_highlight" type="Texture">
+ <theme_item name="grabber_highlight" type="Texture2D">
</theme_item>
<theme_item name="slider" type="StyleBox">
</theme_item>
- <theme_item name="tick" type="Texture">
+ <theme_item name="tick" type="Texture2D">
</theme_item>
</theme_items>
</class>
diff --git a/doc/classes/VSplitContainer.xml b/doc/classes/VSplitContainer.xml
index 2dba120a4f..0e659408d7 100644
--- a/doc/classes/VSplitContainer.xml
+++ b/doc/classes/VSplitContainer.xml
@@ -17,7 +17,7 @@
</theme_item>
<theme_item name="bg" type="StyleBox">
</theme_item>
- <theme_item name="grabber" type="Texture">
+ <theme_item name="grabber" type="Texture2D">
</theme_item>
<theme_item name="separation" type="int" default="12">
</theme_item>
diff --git a/doc/classes/VideoPlayer.xml b/doc/classes/VideoPlayer.xml
index 73c5a1d232..d2b9af4580 100644
--- a/doc/classes/VideoPlayer.xml
+++ b/doc/classes/VideoPlayer.xml
@@ -18,10 +18,10 @@
</description>
</method>
<method name="get_video_texture" qualifiers="const">
- <return type="Texture">
+ <return type="Texture2D">
</return>
<description>
- Returns the current frame as a [Texture].
+ Returns the current frame as a [Texture2D].
</description>
</method>
<method name="is_playing" qualifiers="const">
diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml
index 3c6ff1939e..076977c364 100644
--- a/doc/classes/Viewport.xml
+++ b/doc/classes/Viewport.xml
@@ -88,7 +88,7 @@
</return>
<description>
Returns the viewport's texture.
- [b]Note:[/b] Due to the way OpenGL works, the resulting [ViewportTexture] is flipped vertically. You can use [method Image.flip_y] on the result of [method Texture.get_data] to flip it back, for example:
+ [b]Note:[/b] Due to the way OpenGL works, the resulting [ViewportTexture] is flipped vertically. You can use [method Image.flip_y] on the result of [method Texture2D.get_data] to flip it back, for example:
[codeblock]
var img = get_viewport().get_texture().get_data()
img.flip_y()
@@ -226,15 +226,16 @@
<member name="audio_listener_enable_3d" type="bool" setter="set_as_audio_listener" getter="is_audio_listener" default="false">
If [code]true[/code], the viewport will process 3D audio streams.
</member>
+ <member name="canvas_item_default_texture_filter" type="int" setter="set_default_canvas_item_texture_filter" getter="get_default_canvas_item_texture_filter" enum="Viewport.DefaultCanvasItemTextureFilter" default="1">
+ </member>
+ <member name="canvas_item_default_texture_repeat" type="int" setter="set_default_canvas_item_texture_repeat" getter="get_default_canvas_item_texture_repeat" enum="Viewport.DefaultCanvasItemTextureRepeat" default="0">
+ </member>
<member name="canvas_transform" type="Transform2D" setter="set_canvas_transform" getter="get_canvas_transform">
The canvas transform of the viewport, useful for changing the on-screen positions of all child [CanvasItem]s. This is relative to the global canvas transform of the viewport.
</member>
<member name="debug_draw" type="int" setter="set_debug_draw" getter="get_debug_draw" enum="Viewport.DebugDraw" default="0">
The overlay mode for test rendered geometry in debug purposes.
</member>
- <member name="disable_3d" type="bool" setter="set_disable_3d" getter="is_3d_disabled" default="false">
- If [code]true[/code], the viewport will disable 3D rendering. For actual disabling use [code]usage[/code].
- </member>
<member name="global_canvas_transform" type="Transform2D" setter="set_global_canvas_transform" getter="get_global_canvas_transform">
The global canvas transform of the viewport. The canvas transform is relative to this.
</member>
@@ -246,12 +247,6 @@
</member>
<member name="handle_input_locally" type="bool" setter="set_handle_input_locally" getter="is_handling_input_locally" default="true">
</member>
- <member name="hdr" type="bool" setter="set_hdr" getter="get_hdr" default="true">
- If [code]true[/code], the viewport rendering will receive benefits from High Dynamic Range algorithm. High Dynamic Range allows the viewport to receive values that are outside the 0-1 range. In Godot HDR uses 16 bits, meaning it does not store the full range of a floating point number.
- </member>
- <member name="keep_3d_linear" type="bool" setter="set_keep_3d_linear" getter="get_keep_3d_linear" default="false">
- If [code]true[/code], the result after 3D rendering will not have a linear to sRGB color conversion applied. This is important when the viewport is used as a render target where the result is used as a texture on a 3D object rendered in another viewport. It is also important if the viewport is used to create data that is not color based (noise, heightmaps, pickmaps, etc.). Do not enable this when the viewport is used as a texture on a 2D object or if the viewport is your final output.
- </member>
<member name="msaa" type="int" setter="set_msaa" getter="get_msaa" enum="Viewport.MSAA" default="0">
The multisample anti-aliasing mode. A higher number results in smoother edges at the cost of significantly worse performance. A value of 4 is best unless targeting very high-end systems.
</member>
@@ -270,9 +265,6 @@
<member name="render_target_update_mode" type="int" setter="set_update_mode" getter="get_update_mode" enum="Viewport.UpdateMode" default="2">
The update mode when viewport used as a render target.
</member>
- <member name="render_target_v_flip" type="bool" setter="set_vflip" getter="get_vflip" default="false">
- If [code]true[/code], the result of rendering will be flipped vertically.
- </member>
<member name="shadow_atlas_quad_0" type="int" setter="set_shadow_atlas_quadrant_subdiv" getter="get_shadow_atlas_quadrant_subdiv" enum="Viewport.ShadowAtlasQuadrantSubdiv" default="2">
The subdivision amount of the first quadrant on the shadow atlas.
</member>
@@ -298,9 +290,6 @@
<member name="transparent_bg" type="bool" setter="set_transparent_background" getter="has_transparent_background" default="false">
If [code]true[/code], the viewport should render its background as transparent.
</member>
- <member name="usage" type="int" setter="set_usage" getter="get_usage" enum="Viewport.Usage" default="2">
- The rendering mode of viewport.
- </member>
<member name="world" type="World" setter="set_world" getter="get_world">
The custom [World] which can be used as 3D environment source.
</member>
@@ -386,12 +375,26 @@
<constant name="DEBUG_DRAW_UNSHADED" value="1" enum="DebugDraw">
Objects are displayed without light information.
</constant>
- <constant name="DEBUG_DRAW_OVERDRAW" value="2" enum="DebugDraw">
+ <constant name="DEBUG_DRAW_OVERDRAW" value="3" enum="DebugDraw">
Objected are displayed semi-transparent with additive blending so you can see where they intersect.
</constant>
- <constant name="DEBUG_DRAW_WIREFRAME" value="3" enum="DebugDraw">
+ <constant name="DEBUG_DRAW_WIREFRAME" value="4" enum="DebugDraw">
Objects are displayed in wireframe style.
</constant>
+ <constant name="DEBUG_DRAW_GI_PROBE_ALBEDO" value="6" enum="DebugDraw">
+ </constant>
+ <constant name="DEBUG_DRAW_GI_PROBE_LIGHTING" value="7" enum="DebugDraw">
+ </constant>
+ <constant name="DEBUG_DRAW_GI_PROBE_EMISSION" value="8" enum="DebugDraw">
+ </constant>
+ <constant name="DEBUG_DRAW_SHADOW_ATLAS" value="9" enum="DebugDraw">
+ </constant>
+ <constant name="DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS" value="10" enum="DebugDraw">
+ </constant>
+ <constant name="DEBUG_DRAW_SCENE_LUMINANCE" value="11" enum="DebugDraw">
+ </constant>
+ <constant name="DEBUG_DRAW_SSAO" value="12" enum="DebugDraw">
+ </constant>
<constant name="MSAA_DISABLED" value="0" enum="MSAA">
Multisample anti-aliasing mode disabled. This is the default value.
</constant>
@@ -407,18 +410,6 @@
<constant name="MSAA_16X" value="4" enum="MSAA">
Use 16x Multisample Antialiasing. Likely unsupported on medium and low-end hardware.
</constant>
- <constant name="USAGE_2D" value="0" enum="Usage">
- Allocates all buffers needed for drawing 2D scenes. This takes less VRAM than the 3D usage modes.
- </constant>
- <constant name="USAGE_2D_NO_SAMPLING" value="1" enum="Usage">
- Allocates buffers needed for 2D scenes without allocating a buffer for screen copy. Accordingly, you cannot read from the screen. Of the [enum Usage] types, this requires the least VRAM.
- </constant>
- <constant name="USAGE_3D" value="2" enum="Usage">
- Allocates full buffers for drawing 3D scenes and all 3D effects including buffers needed for 2D scenes and effects.
- </constant>
- <constant name="USAGE_3D_NO_EFFECTS" value="3" enum="Usage">
- Allocates buffers needed for drawing 3D scenes. But does not allocate buffers needed for reading from the screen and post-processing effects. Saves some VRAM.
- </constant>
<constant name="CLEAR_MODE_ALWAYS" value="0" enum="ClearMode">
Always clear the render target before drawing.
</constant>
@@ -428,5 +419,23 @@
<constant name="CLEAR_MODE_ONLY_NEXT_FRAME" value="2" enum="ClearMode">
Clear the render target next frame, then switch to [constant CLEAR_MODE_NEVER].
</constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST" value="0" enum="DefaultCanvasItemTextureFilter">
+ </constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR" value="1" enum="DefaultCanvasItemTextureFilter">
+ </constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS" value="2" enum="DefaultCanvasItemTextureFilter">
+ </constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS" value="3" enum="DefaultCanvasItemTextureFilter">
+ </constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_MAX" value="4" enum="DefaultCanvasItemTextureFilter">
+ </constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED" value="0" enum="DefaultCanvasItemTextureRepeat">
+ </constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_ENABLED" value="1" enum="DefaultCanvasItemTextureRepeat">
+ </constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MIRROR" value="2" enum="DefaultCanvasItemTextureRepeat">
+ </constant>
+ <constant name="DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MAX" value="3" enum="DefaultCanvasItemTextureRepeat">
+ </constant>
</constants>
</class>
diff --git a/doc/classes/ViewportTexture.xml b/doc/classes/ViewportTexture.xml
index e65d44f0f4..14b460a43b 100644
--- a/doc/classes/ViewportTexture.xml
+++ b/doc/classes/ViewportTexture.xml
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="ViewportTexture" inherits="Texture" version="4.0">
+<class name="ViewportTexture" inherits="Texture2D" version="4.0">
<brief_description>
Texture which displays the content of a [Viewport].
</brief_description>
<description>
- Displays the content of a [Viewport] node as a dynamic [Texture]. This can be used to mix controls, 2D, and 3D elements in the same scene.
+ Displays the content of a [Viewport] node as a dynamic [Texture2D]. This can be used to mix controls, 2D, and 3D elements in the same scene.
To create a ViewportTexture in code, use the [method Viewport.get_texture] method on the target viewport.
</description>
<tutorials>
@@ -12,7 +12,6 @@
<methods>
</methods>
<members>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="0" />
<member name="resource_local_to_scene" type="bool" setter="set_local_to_scene" getter="is_local_to_scene" override="true" default="true" />
<member name="viewport_path" type="NodePath" setter="set_viewport_path_in_scene" getter="get_viewport_path_in_scene" default="NodePath(&quot;&quot;)">
The path to the [Viewport] node to display. This is relative to the scene root, not to the node which uses the texture.
diff --git a/doc/classes/VisualServer.xml b/doc/classes/VisualServer.xml
index 8c6fc51b9b..f6b24c2391 100644
--- a/doc/classes/VisualServer.xml
+++ b/doc/classes/VisualServer.xml
@@ -155,287 +155,6 @@
Once finished with your RID, you will want to free the RID using the VisualServer's [method free_rid] static method.
</description>
</method>
- <method name="canvas_item_add_circle">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="pos" type="Vector2">
- </argument>
- <argument index="2" name="radius" type="float">
- </argument>
- <argument index="3" name="color" type="Color">
- </argument>
- <description>
- Adds a circle command to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_clip_ignore">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="ignore" type="bool">
- </argument>
- <description>
- If ignore is [code]true[/code], the VisualServer does not perform clipping.
- </description>
- </method>
- <method name="canvas_item_add_line">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="from" type="Vector2">
- </argument>
- <argument index="2" name="to" type="Vector2">
- </argument>
- <argument index="3" name="color" type="Color">
- </argument>
- <argument index="4" name="width" type="float" default="1.0">
- </argument>
- <argument index="5" name="antialiased" type="bool" default="false">
- </argument>
- <description>
- Adds a line command to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_mesh">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="mesh" type="RID">
- </argument>
- <argument index="2" name="transform" type="Transform2D" default="Transform2D( 1, 0, 0, 1, 0, 0 )">
- </argument>
- <argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
- </argument>
- <argument index="4" name="texture" type="RID">
- </argument>
- <argument index="5" name="normal_map" type="RID">
- </argument>
- <description>
- Adds a mesh command to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_multimesh">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="mesh" type="RID">
- </argument>
- <argument index="2" name="texture" type="RID">
- </argument>
- <argument index="3" name="normal_map" type="RID">
- </argument>
- <description>
- Adds a [MultiMesh] to the [CanvasItem]'s draw commands. Only affects its aabb at the moment.
- </description>
- </method>
- <method name="canvas_item_add_nine_patch">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="rect" type="Rect2">
- </argument>
- <argument index="2" name="source" type="Rect2">
- </argument>
- <argument index="3" name="texture" type="RID">
- </argument>
- <argument index="4" name="topleft" type="Vector2">
- </argument>
- <argument index="5" name="bottomright" type="Vector2">
- </argument>
- <argument index="6" name="x_axis_mode" type="int" enum="VisualServer.NinePatchAxisMode" default="0">
- </argument>
- <argument index="7" name="y_axis_mode" type="int" enum="VisualServer.NinePatchAxisMode" default="0">
- </argument>
- <argument index="8" name="draw_center" type="bool" default="true">
- </argument>
- <argument index="9" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
- </argument>
- <argument index="10" name="normal_map" type="RID">
- </argument>
- <description>
- Adds a nine patch image to the [CanvasItem]'s draw commands.
- See [NinePatchRect] for more explanation.
- </description>
- </method>
- <method name="canvas_item_add_particles">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="particles" type="RID">
- </argument>
- <argument index="2" name="texture" type="RID">
- </argument>
- <argument index="3" name="normal_map" type="RID">
- </argument>
- <description>
- Adds a particle system to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_polygon">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="points" type="PoolVector2Array">
- </argument>
- <argument index="2" name="colors" type="PoolColorArray">
- </argument>
- <argument index="3" name="uvs" type="PoolVector2Array" default="PoolVector2Array( )">
- </argument>
- <argument index="4" name="texture" type="RID">
- </argument>
- <argument index="5" name="normal_map" type="RID">
- </argument>
- <argument index="6" name="antialiased" type="bool" default="false">
- </argument>
- <description>
- Adds a polygon to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_polyline">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="points" type="PoolVector2Array">
- </argument>
- <argument index="2" name="colors" type="PoolColorArray">
- </argument>
- <argument index="3" name="width" type="float" default="1.0">
- </argument>
- <argument index="4" name="antialiased" type="bool" default="false">
- </argument>
- <description>
- Adds a polyline, which is a line from multiple points with a width, to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_primitive">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="points" type="PoolVector2Array">
- </argument>
- <argument index="2" name="colors" type="PoolColorArray">
- </argument>
- <argument index="3" name="uvs" type="PoolVector2Array">
- </argument>
- <argument index="4" name="texture" type="RID">
- </argument>
- <argument index="5" name="width" type="float" default="1.0">
- </argument>
- <argument index="6" name="normal_map" type="RID">
- </argument>
- <description>
- Adds a primitive to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_rect">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="rect" type="Rect2">
- </argument>
- <argument index="2" name="color" type="Color">
- </argument>
- <description>
- Adds a rectangle to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_set_transform">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="transform" type="Transform2D">
- </argument>
- <description>
- Adds a [Transform2D] command to the [CanvasItem]'s draw commands.
- This sets the extra_matrix uniform when executed. This affects the later commands of the canvas item.
- </description>
- </method>
- <method name="canvas_item_add_texture_rect">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="rect" type="Rect2">
- </argument>
- <argument index="2" name="texture" type="RID">
- </argument>
- <argument index="3" name="tile" type="bool" default="false">
- </argument>
- <argument index="4" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
- </argument>
- <argument index="5" name="transpose" type="bool" default="false">
- </argument>
- <argument index="6" name="normal_map" type="RID">
- </argument>
- <description>
- Adds a textured rect to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_texture_rect_region">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="rect" type="Rect2">
- </argument>
- <argument index="2" name="texture" type="RID">
- </argument>
- <argument index="3" name="src_rect" type="Rect2">
- </argument>
- <argument index="4" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )">
- </argument>
- <argument index="5" name="transpose" type="bool" default="false">
- </argument>
- <argument index="6" name="normal_map" type="RID">
- </argument>
- <argument index="7" name="clip_uv" type="bool" default="true">
- </argument>
- <description>
- Adds a texture rect with region setting to the [CanvasItem]'s draw commands.
- </description>
- </method>
- <method name="canvas_item_add_triangle_array">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="indices" type="PoolIntArray">
- </argument>
- <argument index="2" name="points" type="PoolVector2Array">
- </argument>
- <argument index="3" name="colors" type="PoolColorArray">
- </argument>
- <argument index="4" name="uvs" type="PoolVector2Array" default="PoolVector2Array( )">
- </argument>
- <argument index="5" name="bones" type="PoolIntArray" default="PoolIntArray( )">
- </argument>
- <argument index="6" name="weights" type="PoolRealArray" default="PoolRealArray( )">
- </argument>
- <argument index="7" name="texture" type="RID">
- </argument>
- <argument index="8" name="count" type="int" default="-1">
- </argument>
- <argument index="9" name="normal_map" type="RID">
- </argument>
- <argument index="10" name="antialiased" type="bool" default="false">
- </argument>
- <description>
- Adds a triangle array to the [CanvasItem]'s draw commands.
- </description>
- </method>
<method name="canvas_item_clear">
<return type="void">
</return>
@@ -445,25 +164,6 @@
Clears the [CanvasItem] and removes all commands in it.
</description>
</method>
- <method name="canvas_item_create">
- <return type="RID">
- </return>
- <description>
- Creates a new [CanvasItem] and returns its [RID]. It can be accessed with the RID that is returned. This RID will be used in all [code]canvas_item_*[/code] VisualServer functions.
- Once finished with your RID, you will want to free the RID using the VisualServer's [method free_rid] static method.
- </description>
- </method>
- <method name="canvas_item_set_clip">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="clip" type="bool">
- </argument>
- <description>
- Sets clipping for the [CanvasItem].
- </description>
- </method>
<method name="canvas_item_set_copy_to_backbuffer">
<return type="void">
</return>
@@ -477,41 +177,6 @@
Sets the [CanvasItem] to copy a rect to the backbuffer.
</description>
</method>
- <method name="canvas_item_set_custom_rect">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="use_custom_rect" type="bool">
- </argument>
- <argument index="2" name="rect" type="Rect2" default="Rect2( 0, 0, 0, 0 )">
- </argument>
- <description>
- Defines a custom drawing rectangle for the [CanvasItem].
- </description>
- </method>
- <method name="canvas_item_set_distance_field_mode">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="enabled" type="bool">
- </argument>
- <description>
- Enables the use of distance fields for GUI elements that are rendering distance field based fonts.
- </description>
- </method>
- <method name="canvas_item_set_draw_behind_parent">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="enabled" type="bool">
- </argument>
- <description>
- Sets [CanvasItem] to be drawn behind its parent.
- </description>
- </method>
<method name="canvas_item_set_draw_index">
<return type="void">
</return>
@@ -523,17 +188,6 @@
Sets the index for the [CanvasItem].
</description>
</method>
- <method name="canvas_item_set_light_mask">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="mask" type="int">
- </argument>
- <description>
- The light mask. See [LightOccluder2D] for more information on light masks.
- </description>
- </method>
<method name="canvas_item_set_material">
<return type="void">
</return>
@@ -545,61 +199,6 @@
Sets a new material to the [CanvasItem].
</description>
</method>
- <method name="canvas_item_set_modulate">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="color" type="Color">
- </argument>
- <description>
- Sets the color that modulates the [CanvasItem] and its children.
- </description>
- </method>
- <method name="canvas_item_set_parent">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="parent" type="RID">
- </argument>
- <description>
- Sets the parent for the [CanvasItem]. The parent can be another canvas item, or it can be the root canvas that is attached to the viewport.
- </description>
- </method>
- <method name="canvas_item_set_self_modulate">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="color" type="Color">
- </argument>
- <description>
- Sets the color that modulates the [CanvasItem] without children.
- </description>
- </method>
- <method name="canvas_item_set_sort_children_by_y">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="enabled" type="bool">
- </argument>
- <description>
- Sets if [CanvasItem]'s children should be sorted by y-position.
- </description>
- </method>
- <method name="canvas_item_set_transform">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="transform" type="Transform2D">
- </argument>
- <description>
- Sets the [CanvasItem]'s [Transform2D].
- </description>
- </method>
<method name="canvas_item_set_use_parent_material">
<return type="void">
</return>
@@ -611,17 +210,6 @@
Sets if the [CanvasItem] uses its parent's material.
</description>
</method>
- <method name="canvas_item_set_visible">
- <return type="void">
- </return>
- <argument index="0" name="item" type="RID">
- </argument>
- <argument index="1" name="visible" type="bool">
- </argument>
- <description>
- Sets if the canvas item (including its children) is visible.
- </description>
- </method>
<method name="canvas_item_set_z_as_relative_to_parent">
<return type="void">
</return>
@@ -871,17 +459,6 @@
Sets the canvas light's shadow's filter, see [enum CanvasLightShadowFilter] constants.
</description>
</method>
- <method name="canvas_light_set_shadow_gradient_length">
- <return type="void">
- </return>
- <argument index="0" name="light" type="RID">
- </argument>
- <argument index="1" name="length" type="float">
- </argument>
- <description>
- Sets the length of the shadow's gradient.
- </description>
- </method>
<method name="canvas_light_set_shadow_smooth">
<return type="void">
</return>
@@ -1060,12 +637,17 @@
</argument>
<argument index="1" name="color" type="Color">
</argument>
- <argument index="2" name="energy" type="float" default="1.0">
+ <argument index="2" name="ambient" type="int" enum="VisualServer.EnvironmentAmbientSource" default="0">
+ </argument>
+ <argument index="3" name="energy" type="float" default="1.0">
+ </argument>
+ <argument index="4" name="sky_contibution" type="float" default="0.0">
</argument>
- <argument index="3" name="sky_contibution" type="float" default="0.0">
+ <argument index="5" name="reflection_source" type="int" enum="VisualServer.EnvironmentReflectionSource" default="0">
+ </argument>
+ <argument index="6" name="ao_color" type="Color" default="Color( 0, 0, 0, 1 )">
</argument>
<description>
- Sets the ambient light parameters. See [Environment] for more details.
</description>
</method>
<method name="environment_set_background">
@@ -1112,44 +694,6 @@
Sets the maximum layer to use if using Canvas background mode.
</description>
</method>
- <method name="environment_set_dof_blur_far">
- <return type="void">
- </return>
- <argument index="0" name="env" type="RID">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
- <argument index="2" name="distance" type="float">
- </argument>
- <argument index="3" name="transition" type="float">
- </argument>
- <argument index="4" name="far_amount" type="float">
- </argument>
- <argument index="5" name="quality" type="int" enum="VisualServer.EnvironmentDOFBlurQuality">
- </argument>
- <description>
- Sets the values to be used with the "DoF Far Blur" post-process effect. See [Environment] for more details.
- </description>
- </method>
- <method name="environment_set_dof_blur_near">
- <return type="void">
- </return>
- <argument index="0" name="env" type="RID">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
- <argument index="2" name="distance" type="float">
- </argument>
- <argument index="3" name="transition" type="float">
- </argument>
- <argument index="4" name="far_amount" type="float">
- </argument>
- <argument index="5" name="quality" type="int" enum="VisualServer.EnvironmentDOFBlurQuality">
- </argument>
- <description>
- Sets the values to be used with the "DoF Near Blur" post-process effect. See [Environment] for more details.
- </description>
- </method>
<method name="environment_set_fog">
<return type="void">
</return>
@@ -1218,20 +762,21 @@
</argument>
<argument index="4" name="strength" type="float">
</argument>
- <argument index="5" name="bloom_threshold" type="float">
+ <argument index="5" name="mix" type="float">
+ </argument>
+ <argument index="6" name="bloom_threshold" type="float">
</argument>
- <argument index="6" name="blend_mode" type="int" enum="VisualServer.EnvironmentGlowBlendMode">
+ <argument index="7" name="blend_mode" type="int" enum="VisualServer.EnvironmentGlowBlendMode">
</argument>
- <argument index="7" name="hdr_bleed_threshold" type="float">
+ <argument index="8" name="hdr_bleed_threshold" type="float">
</argument>
- <argument index="8" name="hdr_bleed_scale" type="float">
+ <argument index="9" name="hdr_bleed_scale" type="float">
</argument>
- <argument index="9" name="hdr_luminance_cap" type="float">
+ <argument index="10" name="hdr_luminance_cap" type="float">
</argument>
- <argument index="10" name="bicubic_upscale" type="bool">
+ <argument index="11" name="bicubic_upscale" type="bool">
</argument>
<description>
- Sets the variables to be used with the "glow" post-process effect. See [Environment] for more details.
</description>
</method>
<method name="environment_set_sky">
@@ -1242,7 +787,7 @@
<argument index="1" name="sky" type="RID">
</argument>
<description>
- Sets the [Sky] to be used as the environment's background when using [i]BGMode[/i] sky. Equivalent to [member Environment.background_sky].
+ Sets the [Sky] to be used as the environment's background when using [i]BGMode[/i] sky. Equivalent to [member Environment.sky].
</description>
</method>
<method name="environment_set_sky_custom_fov">
@@ -1253,7 +798,7 @@
<argument index="1" name="scale" type="float">
</argument>
<description>
- Sets a custom field of view for the background [Sky]. Equivalent to [member Environment.background_sky_custom_fov].
+ Sets a custom field of view for the background [Sky]. Equivalent to [member Environment.sky_custom_fov].
</description>
</method>
<method name="environment_set_sky_orientation">
@@ -1264,40 +809,7 @@
<argument index="1" name="orientation" type="Basis">
</argument>
<description>
- Sets the rotation of the background [Sky] expressed as a [Basis]. Equivalent to [member Environment.background_sky_orientation].
- </description>
- </method>
- <method name="environment_set_ssao">
- <return type="void">
- </return>
- <argument index="0" name="env" type="RID">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
- <argument index="2" name="radius" type="float">
- </argument>
- <argument index="3" name="intensity" type="float">
- </argument>
- <argument index="4" name="radius2" type="float">
- </argument>
- <argument index="5" name="intensity2" type="float">
- </argument>
- <argument index="6" name="bias" type="float">
- </argument>
- <argument index="7" name="light_affect" type="float">
- </argument>
- <argument index="8" name="ao_channel_affect" type="float">
- </argument>
- <argument index="9" name="color" type="Color">
- </argument>
- <argument index="10" name="quality" type="int" enum="VisualServer.EnvironmentSSAOQuality">
- </argument>
- <argument index="11" name="blur" type="int" enum="VisualServer.EnvironmentSSAOBlur">
- </argument>
- <argument index="12" name="bilateral_sharpness" type="float">
- </argument>
- <description>
- Sets the variables to be used with the "Screen Space Ambient Occlusion (SSAO)" post-process effect. See [Environment] for more details.
+ Sets the rotation of the background [Sky] expressed as a [Basis]. Equivalent to [member Environment.sky_rotation], where the rotation vector is used to construct the [Basis].
</description>
</method>
<method name="environment_set_ssr">
@@ -1426,235 +938,6 @@
Returns the id of a white texture. Creates one if none exists.
</description>
</method>
- <method name="gi_probe_create">
- <return type="RID">
- </return>
- <description>
- Creates a GI probe and adds it to the VisualServer. It can be accessed with the RID that is returned. This RID will be used in all [code]gi_probe_*[/code] VisualServer functions.
- Once finished with your RID, you will want to free the RID using the VisualServer's [method free_rid] static method.
- To place in a scene, attach this GI probe to an instance using [method instance_set_base] using the returned RID.
- </description>
- </method>
- <method name="gi_probe_get_bias" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the bias value for the GI probe. Bias is used to avoid self occlusion. Equivalent to [member GIProbeData.bias].
- </description>
- </method>
- <method name="gi_probe_get_bounds" qualifiers="const">
- <return type="AABB">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the axis-aligned bounding box that covers the full extent of the GI probe.
- </description>
- </method>
- <method name="gi_probe_get_cell_size" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the cell size set by [method gi_probe_set_cell_size].
- </description>
- </method>
- <method name="gi_probe_get_dynamic_data" qualifiers="const">
- <return type="PoolIntArray">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the data used by the GI probe.
- </description>
- </method>
- <method name="gi_probe_get_dynamic_range" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the dynamic range set for this GI probe. Equivalent to [member GIProbe.dynamic_range].
- </description>
- </method>
- <method name="gi_probe_get_energy" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the energy multiplier for this GI probe. Equivalent to [member GIProbe.energy].
- </description>
- </method>
- <method name="gi_probe_get_normal_bias" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the normal bias for this GI probe. Equivalent to [member GIProbe.normal_bias].
- </description>
- </method>
- <method name="gi_probe_get_propagation" qualifiers="const">
- <return type="float">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the propagation value for this GI probe. Equivalent to [member GIProbe.propagation].
- </description>
- </method>
- <method name="gi_probe_get_to_cell_xform" qualifiers="const">
- <return type="Transform">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns the Transform set by [method gi_probe_set_to_cell_xform].
- </description>
- </method>
- <method name="gi_probe_is_compressed" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns [code]true[/code] if the GI probe data associated with this GI probe is compressed. Equivalent to [member GIProbe.compress].
- </description>
- </method>
- <method name="gi_probe_is_interior" qualifiers="const">
- <return type="bool">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <description>
- Returns [code]true[/code] if the GI probe is set to interior, meaning it does not account for sky light. Equivalent to [member GIProbe.interior].
- </description>
- </method>
- <method name="gi_probe_set_bias">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="bias" type="float">
- </argument>
- <description>
- Sets the bias value to avoid self-occlusion. Equivalent to [member GIProbe.bias].
- </description>
- </method>
- <method name="gi_probe_set_bounds">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="bounds" type="AABB">
- </argument>
- <description>
- Sets the axis-aligned bounding box that covers the extent of the GI probe.
- </description>
- </method>
- <method name="gi_probe_set_cell_size">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="range" type="float">
- </argument>
- <description>
- Sets the size of individual cells within the GI probe.
- </description>
- </method>
- <method name="gi_probe_set_compress">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
- <description>
- Sets the compression setting for the GI probe data. Compressed data will take up less space but may look worse. Equivalent to [member GIProbe.compress].
- </description>
- </method>
- <method name="gi_probe_set_dynamic_data">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="data" type="PoolIntArray">
- </argument>
- <description>
- Sets the data to be used in the GI probe for lighting calculations. Normally this is created and called internally within the [GIProbe] node. You should not try to set this yourself.
- </description>
- </method>
- <method name="gi_probe_set_dynamic_range">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="range" type="int">
- </argument>
- <description>
- Sets the dynamic range of the GI probe. Dynamic range sets the limit for how bright lights can be. A smaller range captures greater detail but limits how bright lights can be. Equivalent to [member GIProbe.dynamic_range].
- </description>
- </method>
- <method name="gi_probe_set_energy">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="energy" type="float">
- </argument>
- <description>
- Sets the energy multiplier for this GI probe. A higher energy makes the indirect light from the GI probe brighter. Equivalent to [member GIProbe.energy].
- </description>
- </method>
- <method name="gi_probe_set_interior">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="enable" type="bool">
- </argument>
- <description>
- Sets the interior value of this GI probe. A GI probe set to interior does not include the sky when calculating lighting. Equivalent to [member GIProbe.interior].
- </description>
- </method>
- <method name="gi_probe_set_normal_bias">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="bias" type="float">
- </argument>
- <description>
- Sets the normal bias for this GI probe. Normal bias behaves similar to the other form of bias and may help reduce self-occlusion. Equivalent to [member GIProbe.normal_bias].
- </description>
- </method>
- <method name="gi_probe_set_propagation">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="propagation" type="float">
- </argument>
- <description>
- Sets the propagation of light within this GI probe. Equivalent to [member GIProbe.propagation].
- </description>
- </method>
- <method name="gi_probe_set_to_cell_xform">
- <return type="void">
- </return>
- <argument index="0" name="probe" type="RID">
- </argument>
- <argument index="1" name="xform" type="Transform">
- </argument>
- <description>
- Sets the to cell [Transform] for this GI probe.
- </description>
- </method>
<method name="has_changed" qualifiers="const">
<return type="bool">
</return>
@@ -2128,17 +1411,6 @@
Sets the shadow mode for this directional light. Equivalent to [member DirectionalLight.directional_shadow_mode]. See [enum LightDirectionalShadowMode] for options.
</description>
</method>
- <method name="light_omni_set_shadow_detail">
- <return type="void">
- </return>
- <argument index="0" name="light" type="RID">
- </argument>
- <argument index="1" name="detail" type="int" enum="VisualServer.LightOmniShadowDetail">
- </argument>
- <description>
- Sets whether to use vertical or horizontal detail for this omni light. This can be used to alleviate artifacts in the shadow map. Equivalent to [member OmniLight.omni_shadow_detail].
- </description>
- </method>
<method name="light_omni_set_shadow_mode">
<return type="void">
</return>
@@ -2313,7 +1585,7 @@
<argument index="1" name="bounds" type="AABB">
</argument>
<description>
- Sets the size of the area covered by the lightmap capture. Equivalent to [member BakedLightmapData.bounds].
+ Sets the size of the area covered by the lightmap capture.
</description>
</method>
<method name="lightmap_capture_set_energy">
@@ -2324,7 +1596,7 @@
<argument index="1" name="energy" type="float">
</argument>
<description>
- Sets the energy multiplier for this lightmap capture. Equivalent to [member BakedLightmapData.energy].
+ Sets the energy multiplier for this lightmap capture.
</description>
</method>
<method name="lightmap_capture_set_octree">
@@ -2335,7 +1607,7 @@
<argument index="1" name="octree" type="PoolByteArray">
</argument>
<description>
- Sets the octree to be used by this lightmap capture. This function is normally used by the [BakedLightmap] node. Equivalent to [member BakedLightmapData.octree].
+ Sets the octree to be used by this lightmap capture.
</description>
</method>
<method name="lightmap_capture_set_octree_cell_subdiv">
@@ -2346,7 +1618,7 @@
<argument index="1" name="subdiv" type="int">
</argument>
<description>
- Sets the subdivision level of this lightmap capture's octree. Equivalent to [member BakedLightmapData.cell_subdiv].
+ Sets the subdivision level of this lightmap capture's octree.
</description>
</method>
<method name="lightmap_capture_set_octree_cell_transform">
@@ -2357,7 +1629,7 @@
<argument index="1" name="xform" type="Transform">
</argument>
<description>
- Sets the octree cell transform for this lightmap capture's octree. Equivalent to [member BakedLightmapData.cell_space_transform].
+ Sets the octree cell transform for this lightmap capture's octree.
</description>
</method>
<method name="make_sphere_mesh">
@@ -2392,37 +1664,6 @@
Returns the value of a certain material's parameter.
</description>
</method>
- <method name="material_get_param_default" qualifiers="const">
- <return type="Variant">
- </return>
- <argument index="0" name="material" type="RID">
- </argument>
- <argument index="1" name="parameter" type="String">
- </argument>
- <description>
- Returns the default value for the param if available. Otherwise returns an empty [Variant].
- </description>
- </method>
- <method name="material_get_shader" qualifiers="const">
- <return type="RID">
- </return>
- <argument index="0" name="shader_material" type="RID">
- </argument>
- <description>
- Returns the shader of a certain material's shader. Returns an empty RID if the material doesn't have a shader.
- </description>
- </method>
- <method name="material_set_line_width">
- <return type="void">
- </return>
- <argument index="0" name="material" type="RID">
- </argument>
- <argument index="1" name="width" type="float">
- </argument>
- <description>
- Sets a material's line width.
- </description>
- </method>
<method name="material_set_next_pass">
<return type="void">
</return>
@@ -2480,10 +1721,13 @@
</argument>
<argument index="3" name="blend_shapes" type="Array" default="[ ]">
</argument>
- <argument index="4" name="compress_format" type="int" default="97280">
+ <argument index="4" name="lods" type="Dictionary" default="{
+
+}">
+ </argument>
+ <argument index="5" name="compress_format" type="int" default="31744">
</argument>
<description>
- Adds a surface generated from the Arrays to a mesh. See [enum PrimitiveType] constants for types.
</description>
</method>
<method name="mesh_clear">
@@ -2540,28 +1784,6 @@
Returns a mesh's number of surfaces.
</description>
</method>
- <method name="mesh_remove_surface">
- <return type="void">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="index" type="int">
- </argument>
- <description>
- Removes a mesh's surface.
- </description>
- </method>
- <method name="mesh_set_blend_shape_count">
- <return type="void">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="amount" type="int">
- </argument>
- <description>
- Sets a mesh's blend shape count.
- </description>
- </method>
<method name="mesh_set_blend_shape_mode">
<return type="void">
</return>
@@ -2584,50 +1806,6 @@
Sets a mesh's custom aabb.
</description>
</method>
- <method name="mesh_surface_get_aabb" qualifiers="const">
- <return type="AABB">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="surface" type="int">
- </argument>
- <description>
- Returns a mesh's surface's aabb.
- </description>
- </method>
- <method name="mesh_surface_get_array" qualifiers="const">
- <return type="PoolByteArray">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="surface" type="int">
- </argument>
- <description>
- Returns a mesh's surface's vertex buffer.
- </description>
- </method>
- <method name="mesh_surface_get_array_index_len" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="surface" type="int">
- </argument>
- <description>
- Returns a mesh's surface's amount of indices.
- </description>
- </method>
- <method name="mesh_surface_get_array_len" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="surface" type="int">
- </argument>
- <description>
- Returns a mesh's surface's amount of vertices.
- </description>
- </method>
<method name="mesh_surface_get_arrays" qualifiers="const">
<return type="Array">
</return>
@@ -2650,17 +1828,6 @@
Returns a mesh's surface's arrays for blend shapes.
</description>
</method>
- <method name="mesh_surface_get_format" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="surface" type="int">
- </argument>
- <description>
- Returns the format of a mesh's surface.
- </description>
- </method>
<method name="mesh_surface_get_format_offset" qualifiers="const">
<return type="int">
</return>
@@ -2689,17 +1856,6 @@
Function is unused in Godot 3.x.
</description>
</method>
- <method name="mesh_surface_get_index_array" qualifiers="const">
- <return type="PoolByteArray">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="surface" type="int">
- </argument>
- <description>
- Returns a mesh's surface's index buffer.
- </description>
- </method>
<method name="mesh_surface_get_material" qualifiers="const">
<return type="RID">
</return>
@@ -2711,28 +1867,6 @@
Returns a mesh's surface's material.
</description>
</method>
- <method name="mesh_surface_get_primitive_type" qualifiers="const">
- <return type="int" enum="VisualServer.PrimitiveType">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="surface" type="int">
- </argument>
- <description>
- Returns the primitive type of a mesh's surface.
- </description>
- </method>
- <method name="mesh_surface_get_skeleton_aabb" qualifiers="const">
- <return type="Array">
- </return>
- <argument index="0" name="mesh" type="RID">
- </argument>
- <argument index="1" name="surface" type="int">
- </argument>
- <description>
- Returns the aabb of a mesh's surface's skeleton.
- </description>
- </method>
<method name="mesh_surface_set_material">
<return type="void">
</return>
@@ -2770,12 +1904,11 @@
</argument>
<argument index="2" name="transform_format" type="int" enum="VisualServer.MultimeshTransformFormat">
</argument>
- <argument index="3" name="color_format" type="int" enum="VisualServer.MultimeshColorFormat">
+ <argument index="3" name="color_format" type="bool" default="false">
</argument>
- <argument index="4" name="custom_data_format" type="int" enum="VisualServer.MultimeshCustomDataFormat" default="0">
+ <argument index="4" name="custom_data_format" type="bool" default="false">
</argument>
<description>
- Allocates space for the multimesh data. Format parameters determine how the data will be stored by OpenGL. See [enum MultimeshTransformFormat], [enum MultimeshColorFormat], and [enum MultimeshCustomDataFormat] for usage. Equivalent to [member MultiMesh.instance_count].
</description>
</method>
<method name="multimesh_create">
@@ -2796,6 +1929,14 @@
Calculates and returns the axis-aligned bounding box that encloses all instances within the multimesh.
</description>
</method>
+ <method name="multimesh_get_buffer" qualifiers="const">
+ <return type="PoolRealArray">
+ </return>
+ <argument index="0" name="multimesh" type="RID">
+ </argument>
+ <description>
+ </description>
+ </method>
<method name="multimesh_get_instance_count" qualifiers="const">
<return type="int">
</return>
@@ -2919,19 +2060,14 @@
Sets the [Transform2D] for this instance. For use when multimesh is used in 2D. Equivalent to [method MultiMesh.set_instance_transform_2d].
</description>
</method>
- <method name="multimesh_set_as_bulk_array">
+ <method name="multimesh_set_buffer">
<return type="void">
</return>
<argument index="0" name="multimesh" type="RID">
</argument>
- <argument index="1" name="array" type="PoolRealArray">
+ <argument index="1" name="buffer" type="PoolRealArray">
</argument>
<description>
- Sets all data related to the instances in one go. This is especially useful when loading the data from disk or preparing the data from GDNative.
-
- All data is packed in one large float array. An array may look like this: Transform for instance 1, color data for instance 1, custom data for instance 1, transform for instance 2, color data for instance 2, etc.
-
- [Transform] is stored as 12 floats, [Transform2D] is stored as 8 floats, [code]COLOR_8BIT[/code] / [code]CUSTOM_DATA_8BIT[/code] is stored as 1 float (4 bytes as is) and [code]COLOR_FLOAT[/code] / [code]CUSTOM_DATA_FLOAT[/code] is stored as 4 floats.
</description>
</method>
<method name="multimesh_set_mesh">
@@ -3405,19 +2541,6 @@
Sets the fallback environment to be used by this scenario. The fallback environment is used if no environment is set. Internally, this is used by the editor to provide a default environment.
</description>
</method>
- <method name="scenario_set_reflection_atlas_size">
- <return type="void">
- </return>
- <argument index="0" name="scenario" type="RID">
- </argument>
- <argument index="1" name="size" type="int">
- </argument>
- <argument index="2" name="subdiv" type="int">
- </argument>
- <description>
- Sets the size of the reflection atlas shared by all reflection probes in this scenario.
- </description>
- </method>
<method name="set_boot_image">
<return type="void">
</return>
@@ -3479,6 +2602,16 @@
Returns a default texture from a shader searched by name.
</description>
</method>
+ <method name="shader_get_param_default" qualifiers="const">
+ <return type="Variant">
+ </return>
+ <argument index="0" name="material" type="RID">
+ </argument>
+ <argument index="1" name="parameter" type="String">
+ </argument>
+ <description>
+ </description>
+ </method>
<method name="shader_get_param_list" qualifiers="const">
<return type="Array">
</return>
@@ -3603,12 +2736,9 @@
</return>
<argument index="0" name="sky" type="RID">
</argument>
- <argument index="1" name="cube_map" type="RID">
- </argument>
- <argument index="2" name="radiance_size" type="int">
+ <argument index="1" name="panorama" type="RID">
</argument>
<description>
- Sets a sky's texture.
</description>
</method>
<method name="spot_light_create">
@@ -3627,240 +2757,20 @@
Not implemented in Godot 3.x.
</description>
</method>
- <method name="texture_allocate">
- <return type="void">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <argument index="1" name="width" type="int">
- </argument>
- <argument index="2" name="height" type="int">
- </argument>
- <argument index="3" name="depth_3d" type="int">
- </argument>
- <argument index="4" name="format" type="int" enum="Image.Format">
- </argument>
- <argument index="5" name="type" type="int" enum="VisualServer.TextureType">
- </argument>
- <argument index="6" name="flags" type="int" default="7">
- </argument>
- <description>
- Allocates the GPU memory for the texture.
- </description>
- </method>
- <method name="texture_bind">
- <return type="void">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <argument index="1" name="number" type="int">
- </argument>
- <description>
- Binds the texture to a texture slot.
- </description>
- </method>
- <method name="texture_create">
- <return type="RID">
- </return>
- <description>
- Creates an empty texture and adds it to the VisualServer. It can be accessed with the RID that is returned. This RID will be used in all [code]texture_*[/code] VisualServer functions.
- Once finished with your RID, you will want to free the RID using the VisualServer's [method free_rid] static method.
- </description>
- </method>
- <method name="texture_create_from_image">
+ <method name="texture_2d_create">
<return type="RID">
</return>
<argument index="0" name="image" type="Image">
</argument>
- <argument index="1" name="flags" type="int" default="7">
- </argument>
<description>
- Creates a texture, allocates the space for an image, and fills in the image.
</description>
</method>
- <method name="texture_debug_usage">
- <return type="Array">
- </return>
- <description>
- Returns a list of all the textures and their information.
- </description>
- </method>
- <method name="texture_get_data" qualifiers="const">
+ <method name="texture_2d_get" qualifiers="const">
<return type="Image">
</return>
<argument index="0" name="texture" type="RID">
</argument>
- <argument index="1" name="cube_side" type="int" default="0">
- </argument>
- <description>
- Returns a copy of a texture's image unless it's a CubeMap, in which case it returns the [RID] of the image at one of the cubes sides.
- </description>
- </method>
- <method name="texture_get_depth" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <description>
- Returns the depth of the texture.
- </description>
- </method>
- <method name="texture_get_flags" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <description>
- Returns the flags of a texture.
- </description>
- </method>
- <method name="texture_get_format" qualifiers="const">
- <return type="int" enum="Image.Format">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <description>
- Returns the format of the texture's image.
- </description>
- </method>
- <method name="texture_get_height" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <description>
- Returns the texture's height.
- </description>
- </method>
- <method name="texture_get_path" qualifiers="const">
- <return type="String">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <description>
- Returns the texture's path.
- </description>
- </method>
- <method name="texture_get_texid" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <description>
- Returns the opengl id of the texture's image.
- </description>
- </method>
- <method name="texture_get_type" qualifiers="const">
- <return type="int" enum="VisualServer.TextureType">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <description>
- Returns the type of the texture, can be any of the [enum TextureType].
- </description>
- </method>
- <method name="texture_get_width" qualifiers="const">
- <return type="int">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <description>
- Returns the texture's width.
- </description>
- </method>
- <method name="texture_set_data">
- <return type="void">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <argument index="1" name="image" type="Image">
- </argument>
- <argument index="2" name="layer" type="int" default="0">
- </argument>
- <description>
- Sets the texture's image data. If it's a CubeMap, it sets the image data at a cube side.
- </description>
- </method>
- <method name="texture_set_data_partial">
- <return type="void">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <argument index="1" name="image" type="Image">
- </argument>
- <argument index="2" name="src_x" type="int">
- </argument>
- <argument index="3" name="src_y" type="int">
- </argument>
- <argument index="4" name="src_w" type="int">
- </argument>
- <argument index="5" name="src_h" type="int">
- </argument>
- <argument index="6" name="dst_x" type="int">
- </argument>
- <argument index="7" name="dst_y" type="int">
- </argument>
- <argument index="8" name="dst_mip" type="int">
- </argument>
- <argument index="9" name="layer" type="int" default="0">
- </argument>
- <description>
- Sets a part of the data for a texture. Warning: this function calls the underlying graphics API directly and may corrupt your texture if used improperly.
- </description>
- </method>
- <method name="texture_set_flags">
- <return type="void">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <argument index="1" name="flags" type="int">
- </argument>
- <description>
- Sets the texture's flags. See [enum TextureFlags] for options.
- </description>
- </method>
- <method name="texture_set_path">
- <return type="void">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <argument index="1" name="path" type="String">
- </argument>
<description>
- Sets the texture's path.
- </description>
- </method>
- <method name="texture_set_shrink_all_x2_on_set_data">
- <return type="void">
- </return>
- <argument index="0" name="shrink" type="bool">
- </argument>
- <description>
- If [code]true[/code], sets internal processes to shrink all image data to half the size.
- </description>
- </method>
- <method name="texture_set_size_override">
- <return type="void">
- </return>
- <argument index="0" name="texture" type="RID">
- </argument>
- <argument index="1" name="width" type="int">
- </argument>
- <argument index="2" name="height" type="int">
- </argument>
- <argument index="3" name="depth" type="int">
- </argument>
- <description>
- Resizes the texture to the specified dimensions.
- </description>
- </method>
- <method name="textures_keep_original">
- <return type="void">
- </return>
- <argument index="0" name="enable" type="bool">
- </argument>
- <description>
- If [code]true[/code], the image will be stored in the texture's images array if overwritten.
</description>
</method>
<method name="viewport_attach_camera">
@@ -4015,17 +2925,6 @@
Sets the debug draw mode of a viewport. See [enum ViewportDebugDraw] for options.
</description>
</method>
- <method name="viewport_set_disable_3d">
- <return type="void">
- </return>
- <argument index="0" name="viewport" type="RID">
- </argument>
- <argument index="1" name="disabled" type="bool">
- </argument>
- <description>
- If [code]true[/code], a viewport's 3D rendering is disabled.
- </description>
- </method>
<method name="viewport_set_disable_environment">
<return type="void">
</return>
@@ -4048,17 +2947,6 @@
Sets the viewport's global transformation matrix.
</description>
</method>
- <method name="viewport_set_hdr">
- <return type="void">
- </return>
- <argument index="0" name="viewport" type="RID">
- </argument>
- <argument index="1" name="enabled" type="bool">
- </argument>
- <description>
- If [code]true[/code], the viewport renders to hdr.
- </description>
- </method>
<method name="viewport_set_hide_canvas">
<return type="void">
</return>
@@ -4185,17 +3073,6 @@
Sets when the viewport should be updated. See [enum ViewportUpdateMode] constants for options.
</description>
</method>
- <method name="viewport_set_usage">
- <return type="void">
- </return>
- <argument index="0" name="viewport" type="RID">
- </argument>
- <argument index="1" name="usage" type="int" enum="VisualServer.ViewportUsage">
- </argument>
- <description>
- Sets the viewport's 2D/3D mode. See [enum ViewportUsage] constants for options.
- </description>
- </method>
<method name="viewport_set_use_arvr">
<return type="void">
</return>
@@ -4207,17 +3084,6 @@
If [code]true[/code], the viewport uses augmented or virtual reality technologies. See [ARVRInterface].
</description>
</method>
- <method name="viewport_set_vflip">
- <return type="void">
- </return>
- <argument index="0" name="viewport" type="RID">
- </argument>
- <argument index="1" name="enabled" type="bool">
- </argument>
- <description>
- If [code]true[/code], the viewport's rendering is flipped vertically.
- </description>
- </method>
</methods>
<signals>
<signal name="frame_post_draw">
@@ -4256,60 +3122,23 @@
<constant name="MATERIAL_RENDER_PRIORITY_MAX" value="127">
The maximum renderpriority of all materials.
</constant>
- <constant name="CUBEMAP_LEFT" value="0" enum="CubeMapSide">
- Marks the left side of a cubemap.
- </constant>
- <constant name="CUBEMAP_RIGHT" value="1" enum="CubeMapSide">
- Marks the right side of a cubemap.
- </constant>
- <constant name="CUBEMAP_BOTTOM" value="2" enum="CubeMapSide">
- Marks the bottom side of a cubemap.
- </constant>
- <constant name="CUBEMAP_TOP" value="3" enum="CubeMapSide">
- Marks the top side of a cubemap.
- </constant>
- <constant name="CUBEMAP_FRONT" value="4" enum="CubeMapSide">
- Marks the front side of a cubemap.
+ <constant name="TEXTURE_LAYERED_2D_ARRAY" value="0" enum="TextureLayeredType">
</constant>
- <constant name="CUBEMAP_BACK" value="5" enum="CubeMapSide">
- Marks the back side of a cubemap.
+ <constant name="TEXTURE_LAYERED_CUBEMAP" value="1" enum="TextureLayeredType">
</constant>
- <constant name="TEXTURE_TYPE_2D" value="0" enum="TextureType">
- Normal texture with 2 dimensions, width and height.
+ <constant name="TEXTURE_LAYERED_CUBEMAP_ARRAY" value="2" enum="TextureLayeredType">
</constant>
- <constant name="TEXTURE_TYPE_CUBEMAP" value="1" enum="TextureType">
- Texture made up of six faces, can be looked up with a [code]vec3[/code] in shader.
+ <constant name="CUBEMAP_LAYER_LEFT" value="0" enum="CubeMapLayer">
</constant>
- <constant name="TEXTURE_TYPE_2D_ARRAY" value="2" enum="TextureType">
- An array of 2-dimensional textures.
+ <constant name="CUBEMAP_LAYER_RIGHT" value="1" enum="CubeMapLayer">
</constant>
- <constant name="TEXTURE_TYPE_3D" value="3" enum="TextureType">
- A 3-dimensional texture with width, height, and depth.
+ <constant name="CUBEMAP_LAYER_BOTTOM" value="2" enum="CubeMapLayer">
</constant>
- <constant name="TEXTURE_FLAG_MIPMAPS" value="1" enum="TextureFlags">
- Generates mipmaps, which are smaller versions of the same texture to use when zoomed out, keeping the aspect ratio.
+ <constant name="CUBEMAP_LAYER_TOP" value="3" enum="CubeMapLayer">
</constant>
- <constant name="TEXTURE_FLAG_REPEAT" value="2" enum="TextureFlags">
- Repeats the texture (instead of clamp to edge).
+ <constant name="CUBEMAP_LAYER_FRONT" value="4" enum="CubeMapLayer">
</constant>
- <constant name="TEXTURE_FLAG_FILTER" value="4" enum="TextureFlags">
- Uses a magnifying filter, to enable smooth zooming in of the texture.
- </constant>
- <constant name="TEXTURE_FLAG_ANISOTROPIC_FILTER" value="8" enum="TextureFlags">
- Uses anisotropic mipmap filtering. Generates smaller versions of the same texture with different aspect ratios.
- This results in better-looking textures when viewed from oblique angles.
- </constant>
- <constant name="TEXTURE_FLAG_CONVERT_TO_LINEAR" value="16" enum="TextureFlags">
- Converts the texture to the sRGB color space.
- </constant>
- <constant name="TEXTURE_FLAG_MIRRORED_REPEAT" value="32" enum="TextureFlags">
- Repeats the texture with alternate sections mirrored.
- </constant>
- <constant name="TEXTURE_FLAG_USED_FOR_STREAMING" value="2048" enum="TextureFlags">
- Texture is a video surface.
- </constant>
- <constant name="TEXTURE_FLAGS_DEFAULT" value="7" enum="TextureFlags">
- Default flags. [constant TEXTURE_FLAG_MIPMAPS], [constant TEXTURE_FLAG_REPEAT] and [constant TEXTURE_FLAG_FILTER] are enabled.
+ <constant name="CUBEMAP_LAYER_BACK" value="5" enum="CubeMapLayer">
</constant>
<constant name="SHADER_SPATIAL" value="0" enum="ShaderMode">
Shader is a 3D shader.
@@ -4380,9 +3209,6 @@
<constant name="ARRAY_FORMAT_INDEX" value="256" enum="ArrayFormat">
Flag used to mark an index array.
</constant>
- <constant name="ARRAY_COMPRESS_VERTEX" value="512" enum="ArrayFormat">
- Flag used to mark a compressed (half float) vertex array.
- </constant>
<constant name="ARRAY_COMPRESS_NORMAL" value="1024" enum="ArrayFormat">
Flag used to mark a compressed (half float) normal array.
</constant>
@@ -4398,23 +3224,16 @@
<constant name="ARRAY_COMPRESS_TEX_UV2" value="16384" enum="ArrayFormat">
Flag used to mark a compressed (half float) UV coordinates array for the second UV coordinates.
</constant>
- <constant name="ARRAY_COMPRESS_BONES" value="32768" enum="ArrayFormat">
- Flag used to mark a compressed bone array.
- </constant>
- <constant name="ARRAY_COMPRESS_WEIGHTS" value="65536" enum="ArrayFormat">
- Flag used to mark a compressed (half float) weight array.
- </constant>
<constant name="ARRAY_COMPRESS_INDEX" value="131072" enum="ArrayFormat">
Flag used to mark a compressed index array.
</constant>
<constant name="ARRAY_FLAG_USE_2D_VERTICES" value="262144" enum="ArrayFormat">
Flag used to mark that the array contains 2D vertices.
</constant>
- <constant name="ARRAY_FLAG_USE_16_BIT_BONES" value="524288" enum="ArrayFormat">
- Flag used to mark that the array uses 16-bit bones instead of 8-bit.
+ <constant name="ARRAY_FLAG_USE_DYNAMIC_UPDATE" value="1048576" enum="ArrayFormat">
</constant>
- <constant name="ARRAY_COMPRESS_DEFAULT" value="97280" enum="ArrayFormat">
- Used to set flags [constant ARRAY_COMPRESS_VERTEX], [constant ARRAY_COMPRESS_NORMAL], [constant ARRAY_COMPRESS_TANGENT], [constant ARRAY_COMPRESS_COLOR], [constant ARRAY_COMPRESS_TEX_UV], [constant ARRAY_COMPRESS_TEX_UV2] and [constant ARRAY_COMPRESS_WEIGHTS] quickly.
+ <constant name="ARRAY_COMPRESS_DEFAULT" value="31744" enum="ArrayFormat">
+ Used to set flags [constant ARRAY_COMPRESS_NORMAL], [constant ARRAY_COMPRESS_TANGENT], [constant ARRAY_COMPRESS_COLOR], [constant ARRAY_COMPRESS_TEX_UV] and [constant ARRAY_COMPRESS_TEX_UV2] quickly.
</constant>
<constant name="PRIMITIVE_POINTS" value="0" enum="PrimitiveType">
Primitive to draw consists of points.
@@ -4425,19 +3244,13 @@
<constant name="PRIMITIVE_LINE_STRIP" value="2" enum="PrimitiveType">
Primitive to draw consists of a line strip from start to end.
</constant>
- <constant name="PRIMITIVE_LINE_LOOP" value="3" enum="PrimitiveType">
- Primitive to draw consists of a line loop (a line strip with a line between the last and the first vertex).
- </constant>
- <constant name="PRIMITIVE_TRIANGLES" value="4" enum="PrimitiveType">
+ <constant name="PRIMITIVE_TRIANGLES" value="3" enum="PrimitiveType">
Primitive to draw consists of triangles.
</constant>
- <constant name="PRIMITIVE_TRIANGLE_STRIP" value="5" enum="PrimitiveType">
+ <constant name="PRIMITIVE_TRIANGLE_STRIP" value="4" enum="PrimitiveType">
Primitive to draw consists of a triangle strip (the last 3 vertices are always combined to make a triangle).
</constant>
- <constant name="PRIMITIVE_TRIANGLE_FAN" value="6" enum="PrimitiveType">
- Primitive to draw consists of a triangle strip (the last 2 vertices are always combined with the first to make a triangle).
- </constant>
- <constant name="PRIMITIVE_MAX" value="7" enum="PrimitiveType">
+ <constant name="PRIMITIVE_MAX" value="5" enum="PrimitiveType">
Represents the size of the [enum PrimitiveType] enum.
</constant>
<constant name="BLEND_SHAPE_MODE_NORMALIZED" value="0" enum="BlendShapeMode">
@@ -4446,6 +3259,12 @@
<constant name="BLEND_SHAPE_MODE_RELATIVE" value="1" enum="BlendShapeMode">
Blend shapes are relative to base weight.
</constant>
+ <constant name="MULTIMESH_TRANSFORM_2D" value="0" enum="MultimeshTransformFormat">
+ Use [Transform2D] to store MultiMesh transform.
+ </constant>
+ <constant name="MULTIMESH_TRANSFORM_3D" value="1" enum="MultimeshTransformFormat">
+ Use [Transform] to store MultiMesh transform.
+ </constant>
<constant name="LIGHT_DIRECTIONAL" value="0" enum="LightType">
Is a directional (sun) light.
</constant>
@@ -4458,6 +3277,8 @@
<constant name="LIGHT_PARAM_ENERGY" value="0" enum="LightParam">
The light's energy.
</constant>
+ <constant name="LIGHT_PARAM_INDIRECT_ENERGY" value="1" enum="LightParam">
+ </constant>
<constant name="LIGHT_PARAM_SPECULAR" value="2" enum="LightParam">
The light's influence on specularity.
</constant>
@@ -4488,16 +3309,18 @@
<constant name="LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET" value="11" enum="LightParam">
Proportion of shadow atlas occupied by the third split. The fourth split occupies the rest.
</constant>
- <constant name="LIGHT_PARAM_SHADOW_NORMAL_BIAS" value="12" enum="LightParam">
+ <constant name="LIGHT_PARAM_SHADOW_FADE_START" value="12" enum="LightParam">
+ </constant>
+ <constant name="LIGHT_PARAM_SHADOW_NORMAL_BIAS" value="13" enum="LightParam">
Normal bias used to offset shadow lookup by object normal. Can be used to fix self-shadowing artifacts.
</constant>
- <constant name="LIGHT_PARAM_SHADOW_BIAS" value="13" enum="LightParam">
+ <constant name="LIGHT_PARAM_SHADOW_BIAS" value="14" enum="LightParam">
Bias the shadow lookup to fix self-shadowing artifacts.
</constant>
- <constant name="LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE" value="14" enum="LightParam">
+ <constant name="LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE" value="15" enum="LightParam">
Increases bias on further splits to fix self-shadowing that only occurs far away from the camera.
</constant>
- <constant name="LIGHT_PARAM_MAX" value="15" enum="LightParam">
+ <constant name="LIGHT_PARAM_MAX" value="16" enum="LightParam">
Represents the size of the [enum LightParam] enum.
</constant>
<constant name="LIGHT_OMNI_SHADOW_DUAL_PARABOLOID" value="0" enum="LightOmniShadowMode">
@@ -4506,12 +3329,6 @@
<constant name="LIGHT_OMNI_SHADOW_CUBE" value="1" enum="LightOmniShadowMode">
Use a cubemap shadow map for omni lights. Slower but better quality than dual paraboloid.
</constant>
- <constant name="LIGHT_OMNI_SHADOW_DETAIL_VERTICAL" value="0" enum="LightOmniShadowDetail">
- Use more detail vertically when computing shadow map.
- </constant>
- <constant name="LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL" value="1" enum="LightOmniShadowDetail">
- Use more detail horizontally when computing shadow map.
- </constant>
<constant name="LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL" value="0" enum="LightDirectionalShadowMode">
Use orthogonal shadow projection for directional light.
</constant>
@@ -4527,6 +3344,21 @@
<constant name="LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED" value="1" enum="LightDirectionalShadowDepthRangeMode">
Optimize use of shadow maps, increasing the effective resolution. But may result in shadows moving or flickering slightly.
</constant>
+ <constant name="REFLECTION_PROBE_UPDATE_ONCE" value="0" enum="ReflectionProbeUpdateMode">
+ Reflection probe will update reflections once and then stop.
+ </constant>
+ <constant name="REFLECTION_PROBE_UPDATE_ALWAYS" value="1" enum="ReflectionProbeUpdateMode">
+ Reflection probe will update each frame. This mode is necessary to capture moving objects.
+ </constant>
+ <constant name="PARTICLES_DRAW_ORDER_INDEX" value="0" enum="ParticlesDrawOrder">
+ Draw particles in the order that they appear in the particles array.
+ </constant>
+ <constant name="PARTICLES_DRAW_ORDER_LIFETIME" value="1" enum="ParticlesDrawOrder">
+ Sort particles based on their lifetime.
+ </constant>
+ <constant name="PARTICLES_DRAW_ORDER_VIEW_DEPTH" value="2" enum="ParticlesDrawOrder">
+ Sort particles based on their distance to the camera.
+ </constant>
<constant name="VIEWPORT_UPDATE_DISABLED" value="0" enum="ViewportUpdateMode">
Do not update the viewport.
</constant>
@@ -4569,18 +3401,6 @@
<constant name="VIEWPORT_MSAA_EXT_4X" value="6" enum="ViewportMSAA">
Multisample antialiasing is set to 4× on external texture. Special mode for GLES2 Android VR (Oculus Quest and Go).
</constant>
- <constant name="VIEWPORT_USAGE_2D" value="0" enum="ViewportUsage">
- The Viewport does not render 3D but samples.
- </constant>
- <constant name="VIEWPORT_USAGE_2D_NO_SAMPLING" value="1" enum="ViewportUsage">
- The Viewport does not render 3D and does not sample.
- </constant>
- <constant name="VIEWPORT_USAGE_3D" value="2" enum="ViewportUsage">
- The Viewport renders 3D with effects.
- </constant>
- <constant name="VIEWPORT_USAGE_3D_NO_EFFECTS" value="3" enum="ViewportUsage">
- The Viewport renders 3D but without effects.
- </constant>
<constant name="VIEWPORT_RENDER_INFO_OBJECTS_IN_FRAME" value="0" enum="ViewportRenderInfo">
Number of objects drawn in a single frame.
</constant>
@@ -4608,12 +3428,130 @@
<constant name="VIEWPORT_DEBUG_DRAW_UNSHADED" value="1" enum="ViewportDebugDraw">
Debug draw sets objects to unshaded.
</constant>
- <constant name="VIEWPORT_DEBUG_DRAW_OVERDRAW" value="2" enum="ViewportDebugDraw">
+ <constant name="VIEWPORT_DEBUG_DRAW_LIGHTING" value="2" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_OVERDRAW" value="3" enum="ViewportDebugDraw">
Overwrites clear color to [code](0,0,0,0)[/code].
</constant>
- <constant name="VIEWPORT_DEBUG_DRAW_WIREFRAME" value="3" enum="ViewportDebugDraw">
+ <constant name="VIEWPORT_DEBUG_DRAW_WIREFRAME" value="4" enum="ViewportDebugDraw">
Debug draw draws objects in wireframe.
</constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_NORMAL_BUFFER" value="5" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_GI_PROBE_ALBEDO" value="6" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING" value="7" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION" value="8" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_SHADOW_ATLAS" value="9" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS" value="10" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_SCENE_LUMINANCE" value="11" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_SSAO" value="12" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="VIEWPORT_DEBUG_DRAW_ROUGHNESS_LIMITER" value="13" enum="ViewportDebugDraw">
+ </constant>
+ <constant name="SKY_MODE_QUALITY" value="0" enum="SkyMode">
+ </constant>
+ <constant name="SKY_MODE_REALTIME" value="1" enum="SkyMode">
+ </constant>
+ <constant name="ENV_BG_CLEAR_COLOR" value="0" enum="EnvironmentBG">
+ Use the clear color as background.
+ </constant>
+ <constant name="ENV_BG_COLOR" value="1" enum="EnvironmentBG">
+ Use a specified color as the background.
+ </constant>
+ <constant name="ENV_BG_SKY" value="2" enum="EnvironmentBG">
+ Use a sky resource for the background.
+ </constant>
+ <constant name="ENV_BG_CANVAS" value="3" enum="EnvironmentBG">
+ Use a specified canvas layer as the background. This can be useful for instantiating a 2D scene in a 3D world.
+ </constant>
+ <constant name="ENV_BG_KEEP" value="4" enum="EnvironmentBG">
+ Do not clear the background, use whatever was rendered last frame as the background.
+ </constant>
+ <constant name="ENV_BG_CAMERA_FEED" value="5" enum="EnvironmentBG">
+ Displays a camera feed in the background.
+ </constant>
+ <constant name="ENV_BG_MAX" value="6" enum="EnvironmentBG">
+ Represents the size of the [enum EnvironmentBG] enum.
+ </constant>
+ <constant name="ENV_AMBIENT_SOURCE_BG" value="0" enum="EnvironmentAmbientSource">
+ </constant>
+ <constant name="ENV_AMBIENT_SOURCE_DISABLED" value="1" enum="EnvironmentAmbientSource">
+ </constant>
+ <constant name="ENV_AMBIENT_SOURCE_COLOR" value="2" enum="EnvironmentAmbientSource">
+ </constant>
+ <constant name="ENV_AMBIENT_SOURCE_SKY" value="3" enum="EnvironmentAmbientSource">
+ </constant>
+ <constant name="ENV_REFLECTION_SOURCE_BG" value="0" enum="EnvironmentReflectionSource">
+ </constant>
+ <constant name="ENV_REFLECTION_SOURCE_DISABLED" value="1" enum="EnvironmentReflectionSource">
+ </constant>
+ <constant name="ENV_REFLECTION_SOURCE_SKY" value="2" enum="EnvironmentReflectionSource">
+ </constant>
+ <constant name="ENV_GLOW_BLEND_MODE_ADDITIVE" value="0" enum="EnvironmentGlowBlendMode">
+ </constant>
+ <constant name="ENV_GLOW_BLEND_MODE_SCREEN" value="1" enum="EnvironmentGlowBlendMode">
+ </constant>
+ <constant name="ENV_GLOW_BLEND_MODE_SOFTLIGHT" value="2" enum="EnvironmentGlowBlendMode">
+ </constant>
+ <constant name="ENV_GLOW_BLEND_MODE_REPLACE" value="3" enum="EnvironmentGlowBlendMode">
+ </constant>
+ <constant name="ENV_GLOW_BLEND_MODE_MIX" value="4" enum="EnvironmentGlowBlendMode">
+ </constant>
+ <constant name="ENV_TONE_MAPPER_LINEAR" value="0" enum="EnvironmentToneMapper">
+ Output color as they came in.
+ </constant>
+ <constant name="ENV_TONE_MAPPER_REINHARD" value="1" enum="EnvironmentToneMapper">
+ Use the Reinhard tonemapper.
+ </constant>
+ <constant name="ENV_TONE_MAPPER_FILMIC" value="2" enum="EnvironmentToneMapper">
+ Use the filmic tonemapper.
+ </constant>
+ <constant name="ENV_TONE_MAPPER_ACES" value="3" enum="EnvironmentToneMapper">
+ Use the ACES tonemapper.
+ </constant>
+ <constant name="ENV_SSAO_QUALITY_LOW" value="0" enum="EnvironmentSSAOQuality">
+ Lowest quality of screen space ambient occlusion.
+ </constant>
+ <constant name="ENV_SSAO_QUALITY_MEDIUM" value="1" enum="EnvironmentSSAOQuality">
+ Medium quality screen space ambient occlusion.
+ </constant>
+ <constant name="ENV_SSAO_QUALITY_HIGH" value="2" enum="EnvironmentSSAOQuality">
+ Highest quality screen space ambient occlusion.
+ </constant>
+ <constant name="ENV_SSAO_BLUR_DISABLED" value="0" enum="EnvironmentSSAOBlur">
+ Disables the blur set for SSAO. Will make SSAO look noisier.
+ </constant>
+ <constant name="ENV_SSAO_BLUR_1x1" value="1" enum="EnvironmentSSAOBlur">
+ Perform a 1x1 blur on the SSAO output.
+ </constant>
+ <constant name="ENV_SSAO_BLUR_2x2" value="2" enum="EnvironmentSSAOBlur">
+ Performs a 2x2 blur on the SSAO output.
+ </constant>
+ <constant name="ENV_SSAO_BLUR_3x3" value="3" enum="EnvironmentSSAOBlur">
+ Performs a 3x3 blur on the SSAO output. Use this for smoothest SSAO.
+ </constant>
+ <constant name="ENV_SSAO_QUALITY_ULTRA" value="3" enum="EnvironmentSSAOQuality">
+ </constant>
+ <constant name="DOF_BLUR_QUALITY_VERY_LOW" value="0" enum="DOFBlurQuality">
+ </constant>
+ <constant name="DOF_BLUR_QUALITY_LOW" value="1" enum="DOFBlurQuality">
+ </constant>
+ <constant name="DOF_BLUR_QUALITY_MEDIUM" value="2" enum="DOFBlurQuality">
+ </constant>
+ <constant name="DOF_BLUR_QUALITY_HIGH" value="3" enum="DOFBlurQuality">
+ </constant>
+ <constant name="DOF_BOKEH_BOX" value="0" enum="DOFBokehShape">
+ </constant>
+ <constant name="DOF_BOKEH_HEXAGON" value="1" enum="DOFBokehShape">
+ </constant>
+ <constant name="DOF_BOKEH_CIRCLE" value="2" enum="DOFBokehShape">
+ </constant>
<constant name="SCENARIO_DEBUG_DISABLED" value="0" enum="ScenarioDebugMode">
Do not use a debug mode.
</constant>
@@ -4662,10 +3600,12 @@
<constant name="INSTANCE_FLAG_USE_BAKED_LIGHT" value="0" enum="InstanceFlags">
Allows the instance to be used in baked lighting.
</constant>
- <constant name="INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE" value="1" enum="InstanceFlags">
+ <constant name="INSTANCE_FLAG_USE_DYNAMIC_GI" value="1" enum="InstanceFlags">
+ </constant>
+ <constant name="INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE" value="2" enum="InstanceFlags">
When set, manually requests to draw geometry on next frame.
</constant>
- <constant name="INSTANCE_FLAG_MAX" value="2" enum="InstanceFlags">
+ <constant name="INSTANCE_FLAG_MAX" value="3" enum="InstanceFlags">
Represents the size of the [enum InstanceFlags] enum.
</constant>
<constant name="SHADOW_CASTING_SETTING_OFF" value="0" enum="ShadowCastingSetting">
@@ -4689,6 +3629,32 @@
<constant name="NINE_PATCH_TILE_FIT" value="2" enum="NinePatchAxisMode">
The nine patch gets filled with tiles where needed and stretches them a bit if needed.
</constant>
+ <constant name="CANVAS_ITEM_TEXTURE_FILTER_DEFAULT" value="0" enum="CanvasItemTextureFilter">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_FILTER_NEAREST" value="1" enum="CanvasItemTextureFilter">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_FILTER_LINEAR" value="2" enum="CanvasItemTextureFilter">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS" value="3" enum="CanvasItemTextureFilter">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS" value="4" enum="CanvasItemTextureFilter">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS_ANISOTROPIC" value="5" enum="CanvasItemTextureFilter">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC" value="6" enum="CanvasItemTextureFilter">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_FILTER_MAX" value="7" enum="CanvasItemTextureFilter">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT" value="0" enum="CanvasItemTextureRepeat">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_REPEAT_DISABLED" value="1" enum="CanvasItemTextureRepeat">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_REPEAT_ENABLED" value="2" enum="CanvasItemTextureRepeat">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_REPEAT_MIRROR" value="3" enum="CanvasItemTextureRepeat">
+ </constant>
+ <constant name="CANVAS_ITEM_TEXTURE_REPEAT_MAX" value="4" enum="CanvasItemTextureRepeat">
+ </constant>
<constant name="CANVAS_LIGHT_MODE_ADD" value="0" enum="CanvasLightMode">
Adds light color additive to the canvas.
</constant>
@@ -4704,21 +3670,14 @@
<constant name="CANVAS_LIGHT_FILTER_NONE" value="0" enum="CanvasLightShadowFilter">
Do not apply a filter to canvas light shadows.
</constant>
- <constant name="CANVAS_LIGHT_FILTER_PCF3" value="1" enum="CanvasLightShadowFilter">
- Use PCF3 filtering to filter canvas light shadows.
- </constant>
- <constant name="CANVAS_LIGHT_FILTER_PCF5" value="2" enum="CanvasLightShadowFilter">
+ <constant name="CANVAS_LIGHT_FILTER_PCF5" value="1" enum="CanvasLightShadowFilter">
Use PCF5 filtering to filter canvas light shadows.
</constant>
- <constant name="CANVAS_LIGHT_FILTER_PCF7" value="3" enum="CanvasLightShadowFilter">
- Use PCF7 filtering to filter canvas light shadows.
- </constant>
- <constant name="CANVAS_LIGHT_FILTER_PCF9" value="4" enum="CanvasLightShadowFilter">
- Use PCF9 filtering to filter canvas light shadows.
- </constant>
- <constant name="CANVAS_LIGHT_FILTER_PCF13" value="5" enum="CanvasLightShadowFilter">
+ <constant name="CANVAS_LIGHT_FILTER_PCF13" value="2" enum="CanvasLightShadowFilter">
Use PCF13 filtering to filter canvas light shadows.
</constant>
+ <constant name="CANVAS_LIGHT_FILTER_MAX" value="3" enum="CanvasLightShadowFilter">
+ </constant>
<constant name="CANVAS_OCCLUDER_POLYGON_CULL_DISABLED" value="0" enum="CanvasOccluderPolygonCullMode">
Culling of the canvas occluder is disabled.
</constant>
@@ -4764,119 +3723,5 @@
<constant name="FEATURE_MULTITHREADED" value="1" enum="Features">
Hardware supports multithreading. This enum is currently unused in Godot 3.x.
</constant>
- <constant name="MULTIMESH_TRANSFORM_2D" value="0" enum="MultimeshTransformFormat">
- Use [Transform2D] to store MultiMesh transform.
- </constant>
- <constant name="MULTIMESH_TRANSFORM_3D" value="1" enum="MultimeshTransformFormat">
- Use [Transform] to store MultiMesh transform.
- </constant>
- <constant name="MULTIMESH_COLOR_NONE" value="0" enum="MultimeshColorFormat">
- MultiMesh does not use per-instance color.
- </constant>
- <constant name="MULTIMESH_COLOR_8BIT" value="1" enum="MultimeshColorFormat">
- MultiMesh color uses 8 bits per component. This packs the color into a single float.
- </constant>
- <constant name="MULTIMESH_COLOR_FLOAT" value="2" enum="MultimeshColorFormat">
- MultiMesh color uses a float per channel.
- </constant>
- <constant name="MULTIMESH_CUSTOM_DATA_NONE" value="0" enum="MultimeshCustomDataFormat">
- MultiMesh does not use custom data.
- </constant>
- <constant name="MULTIMESH_CUSTOM_DATA_8BIT" value="1" enum="MultimeshCustomDataFormat">
- MultiMesh custom data uses 8 bits per component. This packs the 4-component custom data into a single float.
- </constant>
- <constant name="MULTIMESH_CUSTOM_DATA_FLOAT" value="2" enum="MultimeshCustomDataFormat">
- MultiMesh custom data uses a float per component.
- </constant>
- <constant name="REFLECTION_PROBE_UPDATE_ONCE" value="0" enum="ReflectionProbeUpdateMode">
- Reflection probe will update reflections once and then stop.
- </constant>
- <constant name="REFLECTION_PROBE_UPDATE_ALWAYS" value="1" enum="ReflectionProbeUpdateMode">
- Reflection probe will update each frame. This mode is necessary to capture moving objects.
- </constant>
- <constant name="PARTICLES_DRAW_ORDER_INDEX" value="0" enum="ParticlesDrawOrder">
- Draw particles in the order that they appear in the particles array.
- </constant>
- <constant name="PARTICLES_DRAW_ORDER_LIFETIME" value="1" enum="ParticlesDrawOrder">
- Sort particles based on their lifetime.
- </constant>
- <constant name="PARTICLES_DRAW_ORDER_VIEW_DEPTH" value="2" enum="ParticlesDrawOrder">
- Sort particles based on their distance to the camera.
- </constant>
- <constant name="ENV_BG_CLEAR_COLOR" value="0" enum="EnvironmentBG">
- Use the clear color as background.
- </constant>
- <constant name="ENV_BG_COLOR" value="1" enum="EnvironmentBG">
- Use a specified color as the background.
- </constant>
- <constant name="ENV_BG_SKY" value="2" enum="EnvironmentBG">
- Use a sky resource for the background.
- </constant>
- <constant name="ENV_BG_COLOR_SKY" value="3" enum="EnvironmentBG">
- Use a custom color for background, but use a sky for shading and reflections.
- </constant>
- <constant name="ENV_BG_CANVAS" value="4" enum="EnvironmentBG">
- Use a specified canvas layer as the background. This can be useful for instantiating a 2D scene in a 3D world.
- </constant>
- <constant name="ENV_BG_KEEP" value="5" enum="EnvironmentBG">
- Do not clear the background, use whatever was rendered last frame as the background.
- </constant>
- <constant name="ENV_BG_MAX" value="7" enum="EnvironmentBG">
- Represents the size of the [enum EnvironmentBG] enum.
- </constant>
- <constant name="ENV_DOF_BLUR_QUALITY_LOW" value="0" enum="EnvironmentDOFBlurQuality">
- Use lowest blur quality. Fastest, but may look bad.
- </constant>
- <constant name="ENV_DOF_BLUR_QUALITY_MEDIUM" value="1" enum="EnvironmentDOFBlurQuality">
- Use medium blur quality.
- </constant>
- <constant name="ENV_DOF_BLUR_QUALITY_HIGH" value="2" enum="EnvironmentDOFBlurQuality">
- Used highest blur quality. Looks the best, but is the slowest.
- </constant>
- <constant name="GLOW_BLEND_MODE_ADDITIVE" value="0" enum="EnvironmentGlowBlendMode">
- Add the effect of the glow on top of the scene.
- </constant>
- <constant name="GLOW_BLEND_MODE_SCREEN" value="1" enum="EnvironmentGlowBlendMode">
- Blends the glow effect with the screen. Does not get as bright as additive.
- </constant>
- <constant name="GLOW_BLEND_MODE_SOFTLIGHT" value="2" enum="EnvironmentGlowBlendMode">
- Produces a subtle color disturbance around objects.
- </constant>
- <constant name="GLOW_BLEND_MODE_REPLACE" value="3" enum="EnvironmentGlowBlendMode">
- Shows the glow effect by itself without the underlying scene.
- </constant>
- <constant name="ENV_TONE_MAPPER_LINEAR" value="0" enum="EnvironmentToneMapper">
- Output color as they came in.
- </constant>
- <constant name="ENV_TONE_MAPPER_REINHARD" value="1" enum="EnvironmentToneMapper">
- Use the Reinhard tonemapper.
- </constant>
- <constant name="ENV_TONE_MAPPER_FILMIC" value="2" enum="EnvironmentToneMapper">
- Use the filmic tonemapper.
- </constant>
- <constant name="ENV_TONE_MAPPER_ACES" value="3" enum="EnvironmentToneMapper">
- Use the ACES tonemapper.
- </constant>
- <constant name="ENV_SSAO_QUALITY_LOW" value="0" enum="EnvironmentSSAOQuality">
- Lowest quality of screen space ambient occlusion.
- </constant>
- <constant name="ENV_SSAO_QUALITY_MEDIUM" value="1" enum="EnvironmentSSAOQuality">
- Medium quality screen space ambient occlusion.
- </constant>
- <constant name="ENV_SSAO_QUALITY_HIGH" value="2" enum="EnvironmentSSAOQuality">
- Highest quality screen space ambient occlusion.
- </constant>
- <constant name="ENV_SSAO_BLUR_DISABLED" value="0" enum="EnvironmentSSAOBlur">
- Disables the blur set for SSAO. Will make SSAO look noisier.
- </constant>
- <constant name="ENV_SSAO_BLUR_1x1" value="1" enum="EnvironmentSSAOBlur">
- Perform a 1x1 blur on the SSAO output.
- </constant>
- <constant name="ENV_SSAO_BLUR_2x2" value="2" enum="EnvironmentSSAOBlur">
- Performs a 2x2 blur on the SSAO output.
- </constant>
- <constant name="ENV_SSAO_BLUR_3x3" value="3" enum="EnvironmentSSAOBlur">
- Performs a 3x3 blur on the SSAO output. Use this for smoothest SSAO.
- </constant>
</constants>
</class>
diff --git a/doc/classes/VisualShaderNode.xml b/doc/classes/VisualShaderNode.xml
index bed97565ff..d3227f421e 100644
--- a/doc/classes/VisualShaderNode.xml
+++ b/doc/classes/VisualShaderNode.xml
@@ -53,7 +53,7 @@
<signals>
<signal name="editor_refresh_request">
<description>
- Emitted when the node requests an editor refresh. Currently called only in setter of [member VisualShaderNodeTexture.source], [VisualShaderNodeTexture], and [VisualShaderNodeCubeMap] (and their derivatives).
+ Emitted when the node requests an editor refresh. Currently called only in setter of [member VisualShaderNodeTexture.source], [VisualShaderNodeTexture], and [VisualShaderNodeCubemap] (and their derivatives).
</description>
</signal>
</signals>
diff --git a/doc/classes/VisualShaderNodeCubeMap.xml b/doc/classes/VisualShaderNodeCubemap.xml
index 8b9cec968c..b6813bdae8 100644
--- a/doc/classes/VisualShaderNodeCubeMap.xml
+++ b/doc/classes/VisualShaderNodeCubemap.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualShaderNodeCubeMap" inherits="VisualShaderNode" version="4.0">
+<class name="VisualShaderNodeCubemap" inherits="VisualShaderNode" version="4.0">
<brief_description>
- A [CubeMap] sampling node to be used within the visual shader graph.
+ A [Cubemap] sampling node to be used within the visual shader graph.
</brief_description>
<description>
Translated to [code]texture(cubemap, vec3)[/code] in the shader language. Returns a color vector and alpha channel as scalar.
@@ -11,22 +11,22 @@
<methods>
</methods>
<members>
- <member name="cube_map" type="CubeMap" setter="set_cube_map" getter="get_cube_map">
- The [CubeMap] texture to sample when using [constant SOURCE_TEXTURE] as [member source].
+ <member name="cube_map" type="Cubemap" setter="set_cube_map" getter="get_cube_map">
+ The [Cubemap] texture to sample when using [constant SOURCE_TEXTURE] as [member source].
</member>
- <member name="source" type="int" setter="set_source" getter="get_source" enum="VisualShaderNodeCubeMap.Source" default="0">
+ <member name="source" type="int" setter="set_source" getter="get_source" enum="VisualShaderNodeCubemap.Source" default="0">
Defines which source should be used for the sampling. See [enum Source] for options.
</member>
- <member name="texture_type" type="int" setter="set_texture_type" getter="get_texture_type" enum="VisualShaderNodeCubeMap.TextureType" default="0">
+ <member name="texture_type" type="int" setter="set_texture_type" getter="get_texture_type" enum="VisualShaderNodeCubemap.TextureType" default="0">
Defines the type of data provided by the source texture. See [enum TextureType] for options.
</member>
</members>
<constants>
<constant name="SOURCE_TEXTURE" value="0" enum="Source">
- Use the [CubeMap] set via [member cube_map]. If this is set to [member source], the [code]samplerCube[/code] port is ignored.
+ Use the [Cubemap] set via [member cube_map]. If this is set to [member source], the [code]samplerCube[/code] port is ignored.
</constant>
<constant name="SOURCE_PORT" value="1" enum="Source">
- Use the [CubeMap] sampler reference passed via the [code]samplerCube[/code] port. If this is set to [member source], the [member cube_map] texture is ignored.
+ Use the [Cubemap] sampler reference passed via the [code]samplerCube[/code] port. If this is set to [member source], the [member cube_map] texture is ignored.
</constant>
<constant name="TYPE_DATA" value="0" enum="TextureType">
No hints are added to the uniform declaration.
diff --git a/doc/classes/VisualShaderNodeCubeMapUniform.xml b/doc/classes/VisualShaderNodeCubemapUniform.xml
index c5cb6ed938..d4bcdc9006 100644
--- a/doc/classes/VisualShaderNodeCubeMapUniform.xml
+++ b/doc/classes/VisualShaderNodeCubemapUniform.xml
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="VisualShaderNodeCubeMapUniform" inherits="VisualShaderNodeTextureUniform" version="4.0">
+<class name="VisualShaderNodeCubemapUniform" inherits="VisualShaderNodeTextureUniform" version="4.0">
<brief_description>
- A [CubeMap] uniform node to be used within the visual shader graph.
+ A [Cubemap] uniform node to be used within the visual shader graph.
</brief_description>
<description>
- Translated to [code]uniform samplerCube[/code] in the shader language. The output value can be used as port for [VisualShaderNodeCubeMap].
+ Translated to [code]uniform samplerCube[/code] in the shader language. The output value can be used as port for [VisualShaderNodeCubemap].
</description>
<tutorials>
</tutorials>
diff --git a/doc/classes/VisualShaderNodeTexture.xml b/doc/classes/VisualShaderNodeTexture.xml
index e1c12c69b6..a28a7f5c65 100644
--- a/doc/classes/VisualShaderNodeTexture.xml
+++ b/doc/classes/VisualShaderNodeTexture.xml
@@ -11,7 +11,7 @@
<members>
<member name="source" type="int" setter="set_source" getter="get_source" enum="VisualShaderNodeTexture.Source" default="0">
</member>
- <member name="texture" type="Texture" setter="set_texture" getter="get_texture">
+ <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture">
</member>
<member name="texture_type" type="int" setter="set_texture_type" getter="get_texture_type" enum="VisualShaderNodeTexture.TextureType" default="0">
</member>
diff --git a/doc/classes/WindowDialog.xml b/doc/classes/WindowDialog.xml
index befa820f9b..16b8085df3 100644
--- a/doc/classes/WindowDialog.xml
+++ b/doc/classes/WindowDialog.xml
@@ -28,11 +28,11 @@
<constants>
</constants>
<theme_items>
- <theme_item name="close" type="Texture">
+ <theme_item name="close" type="Texture2D">
</theme_item>
<theme_item name="close_h_ofs" type="int" default="18">
</theme_item>
- <theme_item name="close_highlight" type="Texture">
+ <theme_item name="close_highlight" type="Texture2D">
</theme_item>
<theme_item name="close_v_ofs" type="int" default="18">
</theme_item>
diff --git a/doc/classes/World.xml b/doc/classes/World.xml
index 361ec9b764..48596c87d0 100644
--- a/doc/classes/World.xml
+++ b/doc/classes/World.xml
@@ -12,6 +12,8 @@
<methods>
</methods>
<members>
+ <member name="camera_effects" type="CameraEffects" setter="set_camera_effects" getter="get_camera_effects">
+ </member>
<member name="direct_space_state" type="PhysicsDirectSpaceState" setter="" getter="get_direct_space_state">
The World's physics direct space state, used for making various queries. Might be used only during [code]_physics_process[/code].
</member>
diff --git a/doc/classes/WorldEnvironment.xml b/doc/classes/WorldEnvironment.xml
index 9c062ecfd0..73500868a8 100644
--- a/doc/classes/WorldEnvironment.xml
+++ b/doc/classes/WorldEnvironment.xml
@@ -14,6 +14,8 @@
<methods>
</methods>
<members>
+ <member name="camera_effects" type="CameraEffects" setter="set_camera_effects" getter="get_camera_effects">
+ </member>
<member name="environment" type="Environment" setter="set_environment" getter="get_environment">
The [Environment] resource used by this [WorldEnvironment], defining the default properties.
</member>
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index 0be8503dd1..2e35bd0ccf 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -3156,9 +3156,9 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p
}
}
- state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SCREEN, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SCREEN);
- state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SOFTLIGHT);
- state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_REPLACE, env->glow_blend_mode == VS::GLOW_BLEND_MODE_REPLACE);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SCREEN, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_SCREEN);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_SOFTLIGHT);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_GLOW_REPLACE, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_REPLACE);
}
//Adjustments
diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h
index eaba0d4bfd..65e84a1fbe 100644
--- a/drivers/gles2/rasterizer_scene_gles2.h
+++ b/drivers/gles2/rasterizer_scene_gles2.h
@@ -423,7 +423,7 @@ public:
glow_intensity(0.8),
glow_strength(1.0),
glow_bloom(0.0),
- glow_blend_mode(VS::GLOW_BLEND_MODE_SOFTLIGHT),
+ glow_blend_mode(VS::ENV_GLOW_BLEND_MODE_SOFTLIGHT),
glow_hdr_bleed_threshold(1.0),
glow_hdr_bleed_scale(2.0),
glow_hdr_luminance_cap(12.0),
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 27992ea5b9..ec8701af31 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -4016,9 +4016,9 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
}
}
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SCREEN, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SCREEN);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == VS::GLOW_BLEND_MODE_SOFTLIGHT);
- state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_REPLACE, env->glow_blend_mode == VS::GLOW_BLEND_MODE_REPLACE);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SCREEN, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_SCREEN);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SOFTLIGHT, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_SOFTLIGHT);
+ state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_REPLACE, env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_REPLACE);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color);
}
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index e30bcfdd2c..abf6bb24cf 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -488,7 +488,7 @@ public:
glow_intensity(0.8),
glow_strength(1.0),
glow_bloom(0.0),
- glow_blend_mode(VS::GLOW_BLEND_MODE_SOFTLIGHT),
+ glow_blend_mode(VS::ENV_GLOW_BLEND_MODE_SOFTLIGHT),
glow_hdr_bleed_threshold(1.0),
glow_hdr_bleed_scale(2.0),
glow_hdr_luminance_cap(12.0),
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index 5700623f98..ce865510b4 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -1794,13 +1794,13 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
Array sd = tileset->call("tile_get_shapes", get_current_tile());
if (convex.is_valid()) {
- // Make concave
+ // Make concave.
undo_redo->create_action(TTR("Make Polygon Concave"));
Ref<ConcavePolygonShape2D> _concave = memnew(ConcavePolygonShape2D);
edited_collision_shape = _concave;
_set_edited_shape_points(_get_collision_shape_points(convex));
} else if (concave.is_valid()) {
- // Make convex
+ // Make convex.
undo_redo->create_action(TTR("Make Polygon Convex"));
Ref<ConvexPolygonShape2D> _convex = memnew(ConvexPolygonShape2D);
edited_collision_shape = _convex;
@@ -1810,14 +1810,20 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
if (sd[i].get("shape") == previous_shape) {
undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.duplicate());
sd.remove(i);
- sd.insert(i, edited_collision_shape);
- undo_redo->add_do_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd);
- undo_redo->add_do_method(this, "_select_edited_shape_coord");
- undo_redo->add_undo_method(this, "_select_edited_shape_coord");
- undo_redo->commit_action();
break;
}
}
+
+ undo_redo->add_do_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd);
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) {
+ undo_redo->add_do_method(tileset.ptr(), "tile_add_shape", get_current_tile(), edited_collision_shape, Transform2D(), false, edited_shape_coord);
+ } else {
+ undo_redo->add_do_method(tileset.ptr(), "tile_add_shape", get_current_tile(), edited_collision_shape, Transform2D());
+ }
+ undo_redo->add_do_method(this, "_select_edited_shape_coord");
+ undo_redo->add_undo_method(this, "_select_edited_shape_coord");
+ undo_redo->commit_action();
+
_update_toggle_shape_button();
workspace->update();
workspace_container->update();
@@ -1984,11 +1990,8 @@ void TileSetEditor::_set_edited_shape_points(const Vector<Vector2> &points) {
}
segments.push_back(points[points.size() - 1]);
segments.push_back(points[0]);
- concave->set_segments(segments);
undo_redo->add_do_method(concave.ptr(), "set_segments", segments);
undo_redo->add_undo_method(concave.ptr(), "set_segments", concave->get_segments());
- } else {
- // Invalid shape
}
}
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 14b24892b2..006c753158 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -880,12 +880,12 @@ public:
rshb->add_child(rvb);
Button *rs_button = memnew(CheckBox);
rs_button->set_button_group(rasterizer_button_group);
- rs_button->set_text(TTR("OpenGL ES 3.0"));
+ rs_button->set_text(TTR("Vulkan"));
rs_button->set_meta("driver_name", "GLES3");
rs_button->set_pressed(true);
rvb->add_child(rs_button);
l = memnew(Label);
- l->set_text(TTR("- Higher visual quality\n- All features available\n- Incompatible with older hardware\n- Not recommended for web games"));
+ l->set_text(TTR("- Higher visual quality\n- More accurate API, which produces very fast code\n- Some features not implemented yet — work in progress\n- Incompatible with older hardware\n- Not recommended for web and mobile games"));
l->set_modulate(Color(1, 1, 1, 0.7));
rvb->add_child(l);
@@ -900,7 +900,7 @@ public:
rs_button->set_meta("driver_name", "GLES2");
rvb->add_child(rs_button);
l = memnew(Label);
- l->set_text(TTR("- Lower visual quality\n- Some features not available\n- Works on most hardware\n- Recommended for web games"));
+ l->set_text(TTR("- Lower visual quality\n- Some features not available\n- Works on most hardware\n- Recommended for web and mobile games"));
l->set_modulate(Color(1, 1, 1, 0.7));
rvb->add_child(l);
diff --git a/modules/gdnative/gdnative/color.cpp b/modules/gdnative/gdnative/color.cpp
index 24587ce4a1..914d5b03f4 100644
--- a/modules/gdnative/gdnative/color.cpp
+++ b/modules/gdnative/gdnative/color.cpp
@@ -141,11 +141,6 @@ godot_int GDAPI godot_color_to_argb32(const godot_color *p_self) {
return self->to_argb32();
}
-godot_real GDAPI godot_color_gray(const godot_color *p_self) {
- const Color *self = (const Color *)p_self;
- return self->gray();
-}
-
godot_color GDAPI godot_color_inverted(const godot_color *p_self) {
godot_color dest;
const Color *self = (const Color *)p_self;
diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json
index 8ccb8d2286..c2cbe1e824 100644
--- a/modules/gdnative/gdnative_api.json
+++ b/modules/gdnative/gdnative_api.json
@@ -579,13 +579,6 @@
]
},
{
- "name": "godot_color_gray",
- "return_type": "godot_real",
- "arguments": [
- ["const godot_color *", "p_self"]
- ]
- },
- {
"name": "godot_color_inverted",
"return_type": "godot_color",
"arguments": [
diff --git a/modules/gdnative/include/gdnative/color.h b/modules/gdnative/include/gdnative/color.h
index 3f046b7f08..47c01dbb20 100644
--- a/modules/gdnative/include/gdnative/color.h
+++ b/modules/gdnative/include/gdnative/color.h
@@ -91,8 +91,6 @@ godot_int GDAPI godot_color_to_rgba64(const godot_color *p_self);
godot_int GDAPI godot_color_to_argb32(const godot_color *p_self);
-godot_real GDAPI godot_color_gray(const godot_color *p_self);
-
godot_color GDAPI godot_color_inverted(const godot_color *p_self);
godot_color GDAPI godot_color_contrasted(const godot_color *p_self);
diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp
index e19e675344..f953206a34 100644
--- a/modules/gdnative/nativescript/godot_nativescript.cpp
+++ b/modules/gdnative/nativescript/godot_nativescript.cpp
@@ -36,6 +36,7 @@
#include "core/project_settings.h"
#include "core/variant.h"
#include "gdnative/gdnative.h"
+#include <stdint.h>
#include "nativescript.h"
@@ -67,6 +68,14 @@ void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char
if (classes->has(p_base)) {
desc.base_data = &(*classes)[p_base];
desc.base_native_type = desc.base_data->base_native_type;
+
+ const NativeScriptDesc *b = desc.base_data;
+ while (b) {
+ desc.rpc_count += b->rpc_count;
+ desc.rset_count += b->rset_count;
+ b = b->base_data;
+ }
+
} else {
desc.base_data = NULL;
desc.base_native_type = p_base;
@@ -87,10 +96,20 @@ void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const
desc.destroy_func = p_destroy_func;
desc.is_tool = true;
desc.base = p_base;
+ desc.rpc_count = 0;
+ desc.rset_count = 0;
if (classes->has(p_base)) {
desc.base_data = &(*classes)[p_base];
desc.base_native_type = desc.base_data->base_native_type;
+
+ const NativeScriptDesc *b = desc.base_data;
+ while (b) {
+ desc.rpc_count += b->rpc_count;
+ desc.rset_count += b->rset_count;
+ b = b->base_data;
+ }
+
} else {
desc.base_data = NULL;
desc.base_native_type = p_base;
@@ -109,6 +128,11 @@ void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const cha
NativeScriptDesc::Method method;
method.method = p_method;
method.rpc_mode = p_attr.rpc_type;
+ method.rpc_method_id = UINT16_MAX;
+ if (p_attr.rpc_type != GODOT_METHOD_RPC_MODE_DISABLED) {
+ method.rpc_method_id = E->get().rpc_count;
+ E->get().rpc_count += 1;
+ }
method.info = MethodInfo(p_function_name);
E->get().methods.insert(p_function_name, method);
@@ -125,6 +149,10 @@ void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const c
property.default_value = *(Variant *)&p_attr->default_value;
property.getter = p_get_func;
property.rset_mode = p_attr->rset_type;
+ if (p_attr->rset_type != GODOT_METHOD_RPC_MODE_DISABLED) {
+ property.rset_property_id = E->get().rset_count;
+ E->get().rset_count += 1;
+ }
property.setter = p_set_func;
property.info = PropertyInfo((Variant::Type)p_attr->type,
p_path,
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index 8b06af6c7b..df85155ff5 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -30,6 +30,8 @@
#include "nativescript.h"
+#include <stdint.h>
+
#include "gdnative/gdnative.h"
#include "core/core_string_names.h"
@@ -402,6 +404,262 @@ void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const {
}
}
+Vector<ScriptNetData> NativeScript::get_rpc_methods() const {
+
+ Vector<ScriptNetData> v;
+
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) {
+ if (E->get().rpc_mode != GODOT_METHOD_RPC_MODE_DISABLED) {
+ ScriptNetData nd;
+ nd.name = E->key();
+ nd.mode = MultiplayerAPI::RPCMode(E->get().rpc_mode);
+ v.push_back(nd);
+ }
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return v;
+}
+
+uint16_t NativeScript::get_rpc_method_id(const StringName &p_method) const {
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method);
+ if (E) {
+ return E->get().rpc_method_id;
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return UINT16_MAX;
+}
+
+StringName NativeScript::get_rpc_method(uint16_t p_id) const {
+ ERR_FAIL_COND_V(p_id == UINT16_MAX, StringName());
+
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) {
+ if (E->get().rpc_method_id == p_id) {
+ return E->key();
+ }
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return StringName();
+}
+
+MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const {
+
+ ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED);
+
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) {
+ if (E->get().rpc_method_id == p_id) {
+ switch (E->get().rpc_mode) {
+ case GODOT_METHOD_RPC_MODE_DISABLED:
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+ case GODOT_METHOD_RPC_MODE_REMOTE:
+ return MultiplayerAPI::RPC_MODE_REMOTE;
+ case GODOT_METHOD_RPC_MODE_MASTER:
+ return MultiplayerAPI::RPC_MODE_MASTER;
+ case GODOT_METHOD_RPC_MODE_PUPPET:
+ return MultiplayerAPI::RPC_MODE_PUPPET;
+ case GODOT_METHOD_RPC_MODE_REMOTESYNC:
+ return MultiplayerAPI::RPC_MODE_REMOTESYNC;
+ case GODOT_METHOD_RPC_MODE_MASTERSYNC:
+ return MultiplayerAPI::RPC_MODE_MASTERSYNC;
+ case GODOT_METHOD_RPC_MODE_PUPPETSYNC:
+ return MultiplayerAPI::RPC_MODE_PUPPETSYNC;
+ default:
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+ }
+ }
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+}
+
+MultiplayerAPI::RPCMode NativeScript::get_rpc_mode(const StringName &p_method) const {
+
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method);
+ if (E) {
+ switch (E->get().rpc_mode) {
+ case GODOT_METHOD_RPC_MODE_DISABLED:
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+ case GODOT_METHOD_RPC_MODE_REMOTE:
+ return MultiplayerAPI::RPC_MODE_REMOTE;
+ case GODOT_METHOD_RPC_MODE_MASTER:
+ return MultiplayerAPI::RPC_MODE_MASTER;
+ case GODOT_METHOD_RPC_MODE_PUPPET:
+ return MultiplayerAPI::RPC_MODE_PUPPET;
+ case GODOT_METHOD_RPC_MODE_REMOTESYNC:
+ return MultiplayerAPI::RPC_MODE_REMOTESYNC;
+ case GODOT_METHOD_RPC_MODE_MASTERSYNC:
+ return MultiplayerAPI::RPC_MODE_MASTERSYNC;
+ case GODOT_METHOD_RPC_MODE_PUPPETSYNC:
+ return MultiplayerAPI::RPC_MODE_PUPPETSYNC;
+ default:
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+ }
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+}
+
+Vector<ScriptNetData> NativeScript::get_rset_properties() const {
+ Vector<ScriptNetData> v;
+
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) {
+ if (E.get().rset_mode != GODOT_METHOD_RPC_MODE_DISABLED) {
+ ScriptNetData nd;
+ nd.name = E.key();
+ nd.mode = MultiplayerAPI::RPCMode(E.get().rset_mode);
+ v.push_back(nd);
+ }
+ }
+ script_data = script_data->base_data;
+ }
+
+ return v;
+}
+
+uint16_t NativeScript::get_rset_property_id(const StringName &p_variable) const {
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable);
+ if (E) {
+ return E.get().rset_property_id;
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return UINT16_MAX;
+}
+
+StringName NativeScript::get_rset_property(uint16_t p_id) const {
+ ERR_FAIL_COND_V(p_id == UINT16_MAX, StringName());
+
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) {
+ if (E.get().rset_property_id == p_id) {
+ return E.key();
+ }
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return StringName();
+}
+
+MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const {
+
+ ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED);
+
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) {
+ if (E.get().rset_property_id == p_id) {
+ switch (E.get().rset_mode) {
+ case GODOT_METHOD_RPC_MODE_DISABLED:
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+ case GODOT_METHOD_RPC_MODE_REMOTE:
+ return MultiplayerAPI::RPC_MODE_REMOTE;
+ case GODOT_METHOD_RPC_MODE_MASTER:
+ return MultiplayerAPI::RPC_MODE_MASTER;
+ case GODOT_METHOD_RPC_MODE_PUPPET:
+ return MultiplayerAPI::RPC_MODE_PUPPET;
+ case GODOT_METHOD_RPC_MODE_REMOTESYNC:
+ return MultiplayerAPI::RPC_MODE_REMOTESYNC;
+ case GODOT_METHOD_RPC_MODE_MASTERSYNC:
+ return MultiplayerAPI::RPC_MODE_MASTERSYNC;
+ case GODOT_METHOD_RPC_MODE_PUPPETSYNC:
+ return MultiplayerAPI::RPC_MODE_PUPPETSYNC;
+ default:
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+ }
+ }
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+}
+
+MultiplayerAPI::RPCMode NativeScript::get_rset_mode(const StringName &p_variable) const {
+
+ NativeScriptDesc *script_data = get_script_desc();
+
+ while (script_data) {
+
+ OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable);
+ if (E) {
+ switch (E.get().rset_mode) {
+ case GODOT_METHOD_RPC_MODE_DISABLED:
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+ case GODOT_METHOD_RPC_MODE_REMOTE:
+ return MultiplayerAPI::RPC_MODE_REMOTE;
+ case GODOT_METHOD_RPC_MODE_MASTER:
+ return MultiplayerAPI::RPC_MODE_MASTER;
+ case GODOT_METHOD_RPC_MODE_PUPPET:
+ return MultiplayerAPI::RPC_MODE_PUPPET;
+ case GODOT_METHOD_RPC_MODE_REMOTESYNC:
+ return MultiplayerAPI::RPC_MODE_REMOTESYNC;
+ case GODOT_METHOD_RPC_MODE_MASTERSYNC:
+ return MultiplayerAPI::RPC_MODE_MASTERSYNC;
+ case GODOT_METHOD_RPC_MODE_PUPPETSYNC:
+ return MultiplayerAPI::RPC_MODE_PUPPETSYNC;
+ default:
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+ }
+ }
+
+ script_data = script_data->base_data;
+ }
+
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+}
+
String NativeScript::get_class_documentation() const {
NativeScriptDesc *script_data = get_script_desc();
@@ -803,72 +1061,44 @@ Ref<Script> NativeScriptInstance::get_script() const {
return script;
}
-MultiplayerAPI::RPCMode NativeScriptInstance::get_rpc_mode(const StringName &p_method) const {
-
- NativeScriptDesc *script_data = GET_SCRIPT_DESC();
-
- while (script_data) {
+Vector<ScriptNetData> NativeScriptInstance::get_rpc_methods() const {
+ return script->get_rpc_methods();
+}
- Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method);
- if (E) {
- switch (E->get().rpc_mode) {
- case GODOT_METHOD_RPC_MODE_DISABLED:
- return MultiplayerAPI::RPC_MODE_DISABLED;
- case GODOT_METHOD_RPC_MODE_REMOTE:
- return MultiplayerAPI::RPC_MODE_REMOTE;
- case GODOT_METHOD_RPC_MODE_MASTER:
- return MultiplayerAPI::RPC_MODE_MASTER;
- case GODOT_METHOD_RPC_MODE_PUPPET:
- return MultiplayerAPI::RPC_MODE_PUPPET;
- case GODOT_METHOD_RPC_MODE_REMOTESYNC:
- return MultiplayerAPI::RPC_MODE_REMOTESYNC;
- case GODOT_METHOD_RPC_MODE_MASTERSYNC:
- return MultiplayerAPI::RPC_MODE_MASTERSYNC;
- case GODOT_METHOD_RPC_MODE_PUPPETSYNC:
- return MultiplayerAPI::RPC_MODE_PUPPETSYNC;
- default:
- return MultiplayerAPI::RPC_MODE_DISABLED;
- }
- }
+uint16_t NativeScriptInstance::get_rpc_method_id(const StringName &p_method) const {
+ return script->get_rpc_method_id(p_method);
+}
- script_data = script_data->base_data;
- }
+StringName NativeScriptInstance::get_rpc_method(uint16_t p_id) const {
+ return script->get_rpc_method(p_id);
+}
- return MultiplayerAPI::RPC_MODE_DISABLED;
+MultiplayerAPI::RPCMode NativeScriptInstance::get_rpc_mode_by_id(uint16_t p_id) const {
+ return script->get_rpc_mode_by_id(p_id);
}
-MultiplayerAPI::RPCMode NativeScriptInstance::get_rset_mode(const StringName &p_variable) const {
+MultiplayerAPI::RPCMode NativeScriptInstance::get_rpc_mode(const StringName &p_method) const {
+ return script->get_rpc_mode(p_method);
+}
- NativeScriptDesc *script_data = GET_SCRIPT_DESC();
+Vector<ScriptNetData> NativeScriptInstance::get_rset_properties() const {
+ return script->get_rset_properties();
+}
- while (script_data) {
+uint16_t NativeScriptInstance::get_rset_property_id(const StringName &p_variable) const {
+ return script->get_rset_property_id(p_variable);
+}
- OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable);
- if (E) {
- switch (E.get().rset_mode) {
- case GODOT_METHOD_RPC_MODE_DISABLED:
- return MultiplayerAPI::RPC_MODE_DISABLED;
- case GODOT_METHOD_RPC_MODE_REMOTE:
- return MultiplayerAPI::RPC_MODE_REMOTE;
- case GODOT_METHOD_RPC_MODE_MASTER:
- return MultiplayerAPI::RPC_MODE_MASTER;
- case GODOT_METHOD_RPC_MODE_PUPPET:
- return MultiplayerAPI::RPC_MODE_PUPPET;
- case GODOT_METHOD_RPC_MODE_REMOTESYNC:
- return MultiplayerAPI::RPC_MODE_REMOTESYNC;
- case GODOT_METHOD_RPC_MODE_MASTERSYNC:
- return MultiplayerAPI::RPC_MODE_MASTERSYNC;
- case GODOT_METHOD_RPC_MODE_PUPPETSYNC:
- return MultiplayerAPI::RPC_MODE_PUPPETSYNC;
- default:
- return MultiplayerAPI::RPC_MODE_DISABLED;
- }
- }
+StringName NativeScriptInstance::get_rset_property(uint16_t p_id) const {
+ return script->get_rset_property(p_id);
+}
- script_data = script_data->base_data;
- }
+MultiplayerAPI::RPCMode NativeScriptInstance::get_rset_mode_by_id(uint16_t p_id) const {
+ return script->get_rset_mode_by_id(p_id);
+}
- return MultiplayerAPI::RPC_MODE_DISABLED;
+MultiplayerAPI::RPCMode NativeScriptInstance::get_rset_mode(const StringName &p_variable) const {
+ return script->get_rset_mode(p_variable);
}
ScriptLanguage *NativeScriptInstance::get_language() {
diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h
index cf787e1f6a..2ff08e32cd 100644
--- a/modules/gdnative/nativescript/nativescript.h
+++ b/modules/gdnative/nativescript/nativescript.h
@@ -54,6 +54,7 @@ struct NativeScriptDesc {
godot_instance_method method;
MethodInfo info;
int rpc_mode;
+ uint16_t rpc_method_id;
String documentation;
};
struct Property {
@@ -62,6 +63,7 @@ struct NativeScriptDesc {
PropertyInfo info;
Variant default_value;
int rset_mode;
+ uint16_t rset_property_id;
String documentation;
};
@@ -70,7 +72,9 @@ struct NativeScriptDesc {
String documentation;
};
+ uint16_t rpc_count;
Map<StringName, Method> methods;
+ uint16_t rset_count;
OrderedHashMap<StringName, Property> properties;
Map<StringName, Signal> signals_; // QtCreator doesn't like the name signals
StringName base;
@@ -86,7 +90,9 @@ struct NativeScriptDesc {
bool is_tool;
inline NativeScriptDesc() :
+ rpc_count(0),
methods(),
+ rset_count(0),
properties(),
signals_(),
base(),
@@ -174,6 +180,18 @@ public:
virtual void get_script_method_list(List<MethodInfo> *p_list) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(uint16_t p_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(uint16_t p_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const;
+ virtual StringName get_rset_property(uint16_t p_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(uint16_t p_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
+
String get_class_documentation() const;
String get_method_documentation(const StringName &p_method) const;
String get_signal_documentation(const StringName &p_signal_name) const;
@@ -210,8 +228,19 @@ public:
virtual void notification(int p_notification);
String to_string(bool *r_valid);
virtual Ref<Script> get_script() const;
+
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(uint16_t p_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(uint16_t p_id) const;
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const;
+ virtual StringName get_rset_property(uint16_t p_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(uint16_t p_id) const;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
+
virtual ScriptLanguage *get_language();
virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
diff --git a/modules/gdnative/pluginscript/pluginscript_instance.cpp b/modules/gdnative/pluginscript/pluginscript_instance.cpp
index 0d6dac3268..26a1d5f47a 100644
--- a/modules/gdnative/pluginscript/pluginscript_instance.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_instance.cpp
@@ -93,10 +93,42 @@ void PluginScriptInstance::notification(int p_notification) {
_desc->notification(_data, p_notification);
}
+Vector<ScriptNetData> PluginScriptInstance::get_rpc_methods() const {
+ return _script->get_rpc_methods();
+}
+
+uint16_t PluginScriptInstance::get_rpc_method_id(const StringName &p_variable) const {
+ return _script->get_rpc_method_id(p_variable);
+}
+
+StringName PluginScriptInstance::get_rpc_method(uint16_t p_id) const {
+ return _script->get_rpc_method(p_id);
+}
+
+MultiplayerAPI::RPCMode PluginScriptInstance::get_rpc_mode_by_id(uint16_t p_id) const {
+ return _script->get_rpc_mode_by_id(p_id);
+}
+
MultiplayerAPI::RPCMode PluginScriptInstance::get_rpc_mode(const StringName &p_method) const {
return _script->get_rpc_mode(p_method);
}
+Vector<ScriptNetData> PluginScriptInstance::get_rset_properties() const {
+ return _script->get_rset_properties();
+}
+
+uint16_t PluginScriptInstance::get_rset_property_id(const StringName &p_variable) const {
+ return _script->get_rset_property_id(p_variable);
+}
+
+StringName PluginScriptInstance::get_rset_property(uint16_t p_id) const {
+ return _script->get_rset_property(p_id);
+}
+
+MultiplayerAPI::RPCMode PluginScriptInstance::get_rset_mode_by_id(uint16_t p_id) const {
+ return _script->get_rset_mode_by_id(p_id);
+}
+
MultiplayerAPI::RPCMode PluginScriptInstance::get_rset_mode(const StringName &p_variable) const {
return _script->get_rset_mode(p_variable);
}
diff --git a/modules/gdnative/pluginscript/pluginscript_instance.h b/modules/gdnative/pluginscript/pluginscript_instance.h
index dc1229a44d..154bebd72a 100644
--- a/modules/gdnative/pluginscript/pluginscript_instance.h
+++ b/modules/gdnative/pluginscript/pluginscript_instance.h
@@ -76,7 +76,16 @@ public:
void set_path(const String &p_path);
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(uint16_t p_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(uint16_t p_id) const;
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const;
+ virtual StringName get_rset_property(uint16_t p_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(uint16_t p_id) const;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
virtual void refcount_incremented();
diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp
index cc5bdee0a1..c370062262 100644
--- a/modules/gdnative/pluginscript/pluginscript_script.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_script.cpp
@@ -34,6 +34,8 @@
#include "pluginscript_instance.h"
#include "pluginscript_script.h"
+#include <stdint.h>
+
#ifdef DEBUG_ENABLED
#define __ASSERT_SCRIPT_REASON "Cannot retrieve PluginScript class for this script, is your code correct?"
#define ASSERT_SCRIPT_VALID() \
@@ -298,18 +300,31 @@ Error PluginScript::reload(bool p_keep_state) {
_member_lines[*key] = (*members)[*key];
}
Array *methods = (Array *)&manifest.methods;
+ _rpc_methods.clear();
+ _rpc_variables.clear();
+ if (_ref_base_parent.is_valid()) {
+ _rpc_methods = _ref_base_parent->get_rpc_methods();
+ _rpc_variables = _ref_base_parent->get_rset_properties();
+ }
for (int i = 0; i < methods->size(); ++i) {
Dictionary v = (*methods)[i];
MethodInfo mi = MethodInfo::from_dict(v);
_methods_info[mi.name] = mi;
// rpc_mode is passed as an optional field and is not part of MethodInfo
Variant var = v["rpc_mode"];
- if (var == Variant()) {
- _methods_rpc_mode[mi.name] = MultiplayerAPI::RPC_MODE_DISABLED;
- } else {
- _methods_rpc_mode[mi.name] = MultiplayerAPI::RPCMode(int(var));
+ if (var != Variant()) {
+ ScriptNetData nd;
+ nd.name = mi.name;
+ nd.mode = MultiplayerAPI::RPCMode(int(var));
+ if (_rpc_methods.find(nd) == -1) {
+ _rpc_methods.push_back(nd);
+ }
}
}
+
+ // Sort so we are 100% that they are always the same.
+ _rpc_methods.sort_custom<SortNetData>();
+
Array *signals = (Array *)&manifest.signals;
for (int i = 0; i < signals->size(); ++i) {
Variant v = (*signals)[i];
@@ -324,13 +339,19 @@ Error PluginScript::reload(bool p_keep_state) {
_properties_default_values[pi.name] = v["default_value"];
// rset_mode is passed as an optional field and is not part of PropertyInfo
Variant var = v["rset_mode"];
- if (var == Variant()) {
- _methods_rpc_mode[pi.name] = MultiplayerAPI::RPC_MODE_DISABLED;
- } else {
- _methods_rpc_mode[pi.name] = MultiplayerAPI::RPCMode(int(var));
+ if (var != Variant()) {
+ ScriptNetData nd;
+ nd.name = pi.name;
+ nd.mode = MultiplayerAPI::RPCMode(int(var));
+ if (_rpc_variables.find(nd) == -1) {
+ _rpc_variables.push_back(nd);
+ }
}
}
+ // Sort so we are 100% that they are always the same.
+ _rpc_variables.sort_custom<SortNetData>();
+
#ifdef TOOLS_ENABLED
/*for (Set<PlaceHolderScriptInstance*>::Element *E=placeholders.front();E;E=E->next()) {
@@ -455,24 +476,70 @@ int PluginScript::get_member_line(const StringName &p_member) const {
return -1;
}
-MultiplayerAPI::RPCMode PluginScript::get_rpc_mode(const StringName &p_method) const {
+Vector<ScriptNetData> PluginScript::get_rpc_methods() const {
+ return _rpc_methods;
+}
+
+uint16_t PluginScript::get_rpc_method_id(const StringName &p_method) const {
+ ASSERT_SCRIPT_VALID_V(UINT16_MAX);
+ for (int i = 0; i < _rpc_methods.size(); i++) {
+ if (_rpc_methods[i].name == p_method) {
+ return i;
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName PluginScript::get_rpc_method(const uint16_t p_rpc_method_id) const {
+ ASSERT_SCRIPT_VALID_V(StringName());
+ if (p_rpc_method_id >= _rpc_methods.size())
+ return StringName();
+ return _rpc_methods[p_rpc_method_id].name;
+}
+
+MultiplayerAPI::RPCMode PluginScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
ASSERT_SCRIPT_VALID_V(MultiplayerAPI::RPC_MODE_DISABLED);
- const Map<StringName, MultiplayerAPI::RPCMode>::Element *e = _methods_rpc_mode.find(p_method);
- if (e != NULL) {
- return e->get();
- } else {
+ if (p_rpc_method_id >= _rpc_methods.size())
return MultiplayerAPI::RPC_MODE_DISABLED;
+ return _rpc_methods[p_rpc_method_id].mode;
+}
+
+MultiplayerAPI::RPCMode PluginScript::get_rpc_mode(const StringName &p_method) const {
+ ASSERT_SCRIPT_VALID_V(MultiplayerAPI::RPC_MODE_DISABLED);
+ return get_rpc_mode_by_id(get_rpc_method_id(p_method));
+}
+
+Vector<ScriptNetData> PluginScript::get_rset_properties() const {
+ return _rpc_variables;
+}
+
+uint16_t PluginScript::get_rset_property_id(const StringName &p_property) const {
+ ASSERT_SCRIPT_VALID_V(UINT16_MAX);
+ for (int i = 0; i < _rpc_variables.size(); i++) {
+ if (_rpc_variables[i].name == p_property) {
+ return i;
+ }
}
+ return UINT16_MAX;
}
-MultiplayerAPI::RPCMode PluginScript::get_rset_mode(const StringName &p_variable) const {
+StringName PluginScript::get_rset_property(const uint16_t p_rset_property_id) const {
+ ASSERT_SCRIPT_VALID_V(StringName());
+ if (p_rset_property_id >= _rpc_variables.size())
+ return StringName();
+ return _rpc_variables[p_rset_property_id].name;
+}
+
+MultiplayerAPI::RPCMode PluginScript::get_rset_mode_by_id(const uint16_t p_rset_property_id) const {
ASSERT_SCRIPT_VALID_V(MultiplayerAPI::RPC_MODE_DISABLED);
- const Map<StringName, MultiplayerAPI::RPCMode>::Element *e = _variables_rset_mode.find(p_variable);
- if (e != NULL) {
- return e->get();
- } else {
+ if (p_rset_property_id >= _rpc_variables.size())
return MultiplayerAPI::RPC_MODE_DISABLED;
- }
+ return _rpc_variables[p_rset_property_id].mode;
+}
+
+MultiplayerAPI::RPCMode PluginScript::get_rset_mode(const StringName &p_variable) const {
+ ASSERT_SCRIPT_VALID_V(MultiplayerAPI::RPC_MODE_DISABLED);
+ return get_rset_mode_by_id(get_rset_property_id(p_variable));
}
PluginScript::PluginScript() :
diff --git a/modules/gdnative/pluginscript/pluginscript_script.h b/modules/gdnative/pluginscript/pluginscript_script.h
index f67c88c794..f6bca8a9cb 100644
--- a/modules/gdnative/pluginscript/pluginscript_script.h
+++ b/modules/gdnative/pluginscript/pluginscript_script.h
@@ -60,8 +60,8 @@ private:
Map<StringName, PropertyInfo> _properties_info;
Map<StringName, MethodInfo> _signals_info;
Map<StringName, MethodInfo> _methods_info;
- Map<StringName, MultiplayerAPI::RPCMode> _variables_rset_mode;
- Map<StringName, MultiplayerAPI::RPCMode> _methods_rpc_mode;
+ Vector<ScriptNetData> _rpc_methods;
+ Vector<ScriptNetData> _rpc_variables;
Set<Object *> _instances;
//exported members
@@ -118,8 +118,17 @@ public:
virtual int get_member_line(const StringName &p_member) const;
- MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
- MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_property) const;
+ virtual StringName get_rset_property(const uint16_t p_rset_property_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
PluginScript();
void init(PluginScriptLanguage *language);
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index a255b92257..e4da60b5b9 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -30,6 +30,8 @@
#include "gdscript.h"
+#include <stdint.h>
+
#include "core/core_string_names.h"
#include "core/engine.h"
#include "core/global_constants.h"
@@ -610,6 +612,53 @@ Error GDScript::reload(bool p_keep_state) {
_set_subclass_path(E->get(), path);
}
+ // Copy the base rpc methods so we don't mask their IDs.
+ rpc_functions.clear();
+ rpc_variables.clear();
+ if (base.is_valid()) {
+ rpc_functions = base->rpc_functions;
+ rpc_variables = base->rpc_variables;
+ }
+
+ GDScript *cscript = this;
+ Map<StringName, Ref<GDScript> >::Element *sub_E = subclasses.front();
+ while (cscript) {
+ // RPC Methods
+ for (Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.front(); E; E = E->next()) {
+ if (E->get()->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) {
+ ScriptNetData nd;
+ nd.name = E->key();
+ nd.mode = E->get()->get_rpc_mode();
+ if (-1 == rpc_functions.find(nd)) {
+ rpc_functions.push_back(nd);
+ }
+ }
+ }
+ // RSet
+ for (Map<StringName, MemberInfo>::Element *E = cscript->member_indices.front(); E; E = E->next()) {
+ if (E->get().rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) {
+ ScriptNetData nd;
+ nd.name = E->key();
+ nd.mode = E->get().rpc_mode;
+ if (-1 == rpc_variables.find(nd)) {
+ rpc_variables.push_back(nd);
+ }
+ }
+ }
+
+ if (cscript != this)
+ sub_E = sub_E->next();
+
+ if (sub_E)
+ cscript = sub_E->get().ptr();
+ else
+ cscript = NULL;
+ }
+
+ // Sort so we are 100% that they are always the same.
+ rpc_functions.sort_custom<SortNetData>();
+ rpc_variables.sort_custom<SortNetData>();
+
return OK;
}
@@ -635,6 +684,60 @@ void GDScript::get_members(Set<StringName> *p_members) {
}
}
+Vector<ScriptNetData> GDScript::get_rpc_methods() const {
+ return rpc_functions;
+}
+
+uint16_t GDScript::get_rpc_method_id(const StringName &p_method) const {
+ for (int i = 0; i < rpc_functions.size(); i++) {
+ if (rpc_functions[i].name == p_method) {
+ return i;
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName GDScript::get_rpc_method(const uint16_t p_rpc_method_id) const {
+ ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), StringName());
+ return rpc_functions[p_rpc_method_id].name;
+}
+
+MultiplayerAPI::RPCMode GDScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
+ ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED);
+ return rpc_functions[p_rpc_method_id].mode;
+}
+
+MultiplayerAPI::RPCMode GDScript::get_rpc_mode(const StringName &p_method) const {
+ return get_rpc_mode_by_id(get_rpc_method_id(p_method));
+}
+
+Vector<ScriptNetData> GDScript::get_rset_properties() const {
+ return rpc_variables;
+}
+
+uint16_t GDScript::get_rset_property_id(const StringName &p_variable) const {
+ for (int i = 0; i < rpc_variables.size(); i++) {
+ if (rpc_variables[i].name == p_variable) {
+ return i;
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName GDScript::get_rset_property(const uint16_t p_rset_member_id) const {
+ ERR_FAIL_COND_V(p_rset_member_id >= rpc_variables.size(), StringName());
+ return rpc_variables[p_rset_member_id].name;
+}
+
+MultiplayerAPI::RPCMode GDScript::get_rset_mode_by_id(const uint16_t p_rset_member_id) const {
+ ERR_FAIL_COND_V(p_rset_member_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED);
+ return rpc_functions[p_rset_member_id].mode;
+}
+
+MultiplayerAPI::RPCMode GDScript::get_rset_mode(const StringName &p_variable) const {
+ return get_rset_mode_by_id(get_rset_property_id(p_variable));
+}
+
Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
GDScript *top = this;
@@ -1291,40 +1394,44 @@ ScriptLanguage *GDScriptInstance::get_language() {
return GDScriptLanguage::get_singleton();
}
-MultiplayerAPI::RPCMode GDScriptInstance::get_rpc_mode(const StringName &p_method) const {
+Vector<ScriptNetData> GDScriptInstance::get_rpc_methods() const {
+ return script->get_rpc_methods();
+}
- const GDScript *cscript = script.ptr();
+uint16_t GDScriptInstance::get_rpc_method_id(const StringName &p_method) const {
+ return script->get_rpc_method_id(p_method);
+}
- while (cscript) {
- const Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.find(p_method);
- if (E) {
+StringName GDScriptInstance::get_rpc_method(const uint16_t p_rpc_method_id) const {
+ return script->get_rpc_method(p_rpc_method_id);
+}
- if (E->get()->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) {
- return E->get()->get_rpc_mode();
- }
- }
- cscript = cscript->_base;
- }
+MultiplayerAPI::RPCMode GDScriptInstance::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
+ return script->get_rpc_mode_by_id(p_rpc_method_id);
+}
- return MultiplayerAPI::RPC_MODE_DISABLED;
+MultiplayerAPI::RPCMode GDScriptInstance::get_rpc_mode(const StringName &p_method) const {
+ return script->get_rpc_mode(p_method);
}
-MultiplayerAPI::RPCMode GDScriptInstance::get_rset_mode(const StringName &p_variable) const {
+Vector<ScriptNetData> GDScriptInstance::get_rset_properties() const {
+ return script->get_rset_properties();
+}
- const GDScript *cscript = script.ptr();
+uint16_t GDScriptInstance::get_rset_property_id(const StringName &p_variable) const {
+ return script->get_rset_property_id(p_variable);
+}
- while (cscript) {
- const Map<StringName, GDScript::MemberInfo>::Element *E = cscript->member_indices.find(p_variable);
- if (E) {
+StringName GDScriptInstance::get_rset_property(const uint16_t p_rset_member_id) const {
+ return script->get_rset_property(p_rset_member_id);
+}
- if (E->get().rpc_mode) {
- return E->get().rpc_mode;
- }
- }
- cscript = cscript->_base;
- }
+MultiplayerAPI::RPCMode GDScriptInstance::get_rset_mode_by_id(const uint16_t p_rset_member_id) const {
+ return script->get_rset_mode_by_id(p_rset_member_id);
+}
- return MultiplayerAPI::RPC_MODE_DISABLED;
+MultiplayerAPI::RPCMode GDScriptInstance::get_rset_mode(const StringName &p_variable) const {
+ return script->get_rset_mode(p_variable);
}
void GDScriptInstance::reload_members() {
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 4ae52238ce..4af574cd9d 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -85,6 +85,8 @@ class GDScript : public Script {
Map<StringName, MemberInfo> member_indices; //members are just indices to the instanced script.
Map<StringName, Ref<GDScript> > subclasses;
Map<StringName, Vector<StringName> > _signals;
+ Vector<ScriptNetData> rpc_functions;
+ Vector<ScriptNetData> rpc_variables;
#ifdef TOOLS_ENABLED
@@ -213,6 +215,18 @@ public:
virtual void get_constants(Map<StringName, Variant> *p_constants);
virtual void get_members(Set<StringName> *p_members);
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const;
+ virtual StringName get_rset_property(const uint16_t p_variable_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
+
#ifdef TOOLS_ENABLED
virtual bool is_placeholder_fallback_enabled() const { return placeholder_fallback_enabled; }
#endif
@@ -264,7 +278,16 @@ public:
void reload_members();
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const;
+ virtual StringName get_rset_property(const uint16_t p_variable_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
GDScriptInstance();
diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp
index 0572c5f746..d5723fd20f 100644
--- a/modules/gdscript/language_server/gdscript_text_document.cpp
+++ b/modules/gdscript/language_server/gdscript_text_document.cpp
@@ -321,6 +321,8 @@ Variant GDScriptTextDocument::hover(const Dictionary &p_params) {
lsp::Hover hover;
hover.contents = symbol->render();
+ hover.range.start = params.position;
+ hover.range.end = params.position;
return hover.to_json();
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 2847f3b414..93b23791ae 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -31,6 +31,7 @@
#include "csharp_script.h"
#include <mono/metadata/threads.h>
+#include <stdint.h>
#include "core/io/json.h"
#include "core/os/file_access.h"
@@ -1979,67 +1980,44 @@ bool CSharpInstance::refcount_decremented() {
return ref_dying;
}
-MultiplayerAPI::RPCMode CSharpInstance::_member_get_rpc_mode(IMonoClassMember *p_member) const {
-
- if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute)))
- return MultiplayerAPI::RPC_MODE_REMOTE;
- if (p_member->has_attribute(CACHED_CLASS(MasterAttribute)))
- return MultiplayerAPI::RPC_MODE_MASTER;
- if (p_member->has_attribute(CACHED_CLASS(PuppetAttribute)))
- return MultiplayerAPI::RPC_MODE_PUPPET;
- if (p_member->has_attribute(CACHED_CLASS(SlaveAttribute)))
- return MultiplayerAPI::RPC_MODE_PUPPET;
- if (p_member->has_attribute(CACHED_CLASS(RemoteSyncAttribute)))
- return MultiplayerAPI::RPC_MODE_REMOTESYNC;
- if (p_member->has_attribute(CACHED_CLASS(SyncAttribute)))
- return MultiplayerAPI::RPC_MODE_REMOTESYNC;
- if (p_member->has_attribute(CACHED_CLASS(MasterSyncAttribute)))
- return MultiplayerAPI::RPC_MODE_MASTERSYNC;
- if (p_member->has_attribute(CACHED_CLASS(PuppetSyncAttribute)))
- return MultiplayerAPI::RPC_MODE_PUPPETSYNC;
+Vector<ScriptNetData> CSharpInstance::get_rpc_methods() const {
+ return script->get_rpc_methods();
+}
- return MultiplayerAPI::RPC_MODE_DISABLED;
+uint16_t CSharpInstance::get_rpc_method_id(const StringName &p_method) const {
+ return script->get_rpc_method_id(p_method);
}
-MultiplayerAPI::RPCMode CSharpInstance::get_rpc_mode(const StringName &p_method) const {
+StringName CSharpInstance::get_rpc_method(const uint16_t p_rpc_method_id) const {
+ return script->get_rpc_method(p_rpc_method_id);
+}
- GD_MONO_SCOPE_THREAD_ATTACH;
+MultiplayerAPI::RPCMode CSharpInstance::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
+ return script->get_rpc_mode_by_id(p_rpc_method_id);
+}
- GDMonoClass *top = script->script_class;
+MultiplayerAPI::RPCMode CSharpInstance::get_rpc_mode(const StringName &p_method) const {
+ return script->get_rpc_mode(p_method);
+}
- while (top && top != script->native) {
- GDMonoMethod *method = top->get_fetched_method_unknown_params(p_method);
+Vector<ScriptNetData> CSharpInstance::get_rset_properties() const {
+ return script->get_rset_properties();
+}
- if (method && !method->is_static())
- return _member_get_rpc_mode(method);
+uint16_t CSharpInstance::get_rset_property_id(const StringName &p_variable) const {
+ return script->get_rset_property_id(p_variable);
+}
- top = top->get_parent_class();
- }
+StringName CSharpInstance::get_rset_property(const uint16_t p_rset_member_id) const {
+ return script->get_rset_property(p_rset_member_id);
+}
- return MultiplayerAPI::RPC_MODE_DISABLED;
+MultiplayerAPI::RPCMode CSharpInstance::get_rset_mode_by_id(const uint16_t p_rset_member_id) const {
+ return script->get_rset_mode_by_id(p_rset_member_id);
}
MultiplayerAPI::RPCMode CSharpInstance::get_rset_mode(const StringName &p_variable) const {
-
- GD_MONO_SCOPE_THREAD_ATTACH;
-
- GDMonoClass *top = script->script_class;
-
- while (top && top != script->native) {
- GDMonoField *field = top->get_field(p_variable);
-
- if (field && !field->is_static())
- return _member_get_rpc_mode(field);
-
- GDMonoProperty *property = top->get_property(p_variable);
-
- if (property && !property->is_static())
- return _member_get_rpc_mode(property);
-
- top = top->get_parent_class();
- }
-
- return MultiplayerAPI::RPC_MODE_DISABLED;
+ return script->get_rset_mode(p_variable);
}
void CSharpInstance::notification(int p_notification) {
@@ -3251,6 +3229,69 @@ Error CSharpScript::reload(bool p_keep_state) {
_update_exports();
}
+ rpc_functions.clear();
+ rpc_variables.clear();
+
+ GDMonoClass *top = script_class;
+ while (top && top != native) {
+ {
+ Vector<GDMonoMethod *> methods = top->get_all_methods();
+ for (int i = 0; i < methods.size(); i++) {
+ if (!methods[i]->is_static()) {
+ MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(methods[i]);
+ if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
+ ScriptNetData nd;
+ nd.name = methods[i]->get_name();
+ nd.mode = mode;
+ if (-1 == rpc_functions.find(nd)) {
+ rpc_functions.push_back(nd);
+ }
+ }
+ }
+ }
+ }
+
+ {
+ Vector<GDMonoField *> fields = top->get_all_fields();
+ for (int i = 0; i < fields.size(); i++) {
+ if (!fields[i]->is_static()) {
+ MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(fields[i]);
+ if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
+ ScriptNetData nd;
+ nd.name = fields[i]->get_name();
+ nd.mode = mode;
+ if (-1 == rpc_variables.find(nd)) {
+ rpc_variables.push_back(nd);
+ }
+ }
+ }
+ }
+ }
+
+ {
+ Vector<GDMonoProperty *> properties = top->get_all_properties();
+ for (int i = 0; i < properties.size(); i++) {
+ if (!properties[i]->is_static()) {
+ MultiplayerAPI::RPCMode mode = _member_get_rpc_mode(properties[i]);
+ if (MultiplayerAPI::RPC_MODE_DISABLED != mode) {
+ ScriptNetData nd;
+ nd.name = properties[i]->get_name();
+ nd.mode = mode;
+ if (-1 == rpc_variables.find(nd)) {
+ rpc_variables.push_back(nd);
+ }
+ }
+ }
+ }
+ }
+
+ top = top->get_parent_class();
+ }
+
+ // Sort so we are 100% that they are always the same.
+ rpc_functions.sort_custom<SortNetData>();
+ rpc_variables.sort_custom<SortNetData>();
+
return OK;
}
@@ -3324,6 +3365,82 @@ int CSharpScript::get_member_line(const StringName &p_member) const {
return -1;
}
+MultiplayerAPI::RPCMode CSharpScript::_member_get_rpc_mode(IMonoClassMember *p_member) const {
+
+ if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute)))
+ return MultiplayerAPI::RPC_MODE_REMOTE;
+ if (p_member->has_attribute(CACHED_CLASS(MasterAttribute)))
+ return MultiplayerAPI::RPC_MODE_MASTER;
+ if (p_member->has_attribute(CACHED_CLASS(PuppetAttribute)))
+ return MultiplayerAPI::RPC_MODE_PUPPET;
+ if (p_member->has_attribute(CACHED_CLASS(SlaveAttribute)))
+ return MultiplayerAPI::RPC_MODE_PUPPET;
+ if (p_member->has_attribute(CACHED_CLASS(RemoteSyncAttribute)))
+ return MultiplayerAPI::RPC_MODE_REMOTESYNC;
+ if (p_member->has_attribute(CACHED_CLASS(SyncAttribute)))
+ return MultiplayerAPI::RPC_MODE_REMOTESYNC;
+ if (p_member->has_attribute(CACHED_CLASS(MasterSyncAttribute)))
+ return MultiplayerAPI::RPC_MODE_MASTERSYNC;
+ if (p_member->has_attribute(CACHED_CLASS(PuppetSyncAttribute)))
+ return MultiplayerAPI::RPC_MODE_PUPPETSYNC;
+
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+}
+
+Vector<ScriptNetData> CSharpScript::get_rpc_methods() const {
+ return rpc_functions;
+}
+
+uint16_t CSharpScript::get_rpc_method_id(const StringName &p_method) const {
+ for (int i = 0; i < rpc_functions.size(); i++) {
+ if (rpc_functions[i].name == p_method) {
+ return i;
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName CSharpScript::get_rpc_method(const uint16_t p_rpc_method_id) const {
+ ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), StringName());
+ return rpc_functions[p_rpc_method_id].name;
+}
+
+MultiplayerAPI::RPCMode CSharpScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
+ ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED);
+ return rpc_functions[p_rpc_method_id].mode;
+}
+
+MultiplayerAPI::RPCMode CSharpScript::get_rpc_mode(const StringName &p_method) const {
+ return get_rpc_mode_by_id(get_rpc_method_id(p_method));
+}
+
+Vector<ScriptNetData> CSharpScript::get_rset_properties() const {
+ return rpc_variables;
+}
+
+uint16_t CSharpScript::get_rset_property_id(const StringName &p_variable) const {
+ for (int i = 0; i < rpc_variables.size(); i++) {
+ if (rpc_variables[i].name == p_variable) {
+ return i;
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName CSharpScript::get_rset_property(const uint16_t p_rset_member_id) const {
+ ERR_FAIL_COND_V(p_rset_member_id >= rpc_variables.size(), StringName());
+ return rpc_variables[p_rset_member_id].name;
+}
+
+MultiplayerAPI::RPCMode CSharpScript::get_rset_mode_by_id(const uint16_t p_rset_member_id) const {
+ ERR_FAIL_COND_V(p_rset_member_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED);
+ return rpc_functions[p_rset_member_id].mode;
+}
+
+MultiplayerAPI::RPCMode CSharpScript::get_rset_mode(const StringName &p_variable) const {
+ return get_rset_mode_by_id(get_rset_property_id(p_variable));
+}
+
Error CSharpScript::load_source_code(const String &p_path) {
Error ferr = read_all_file_utf8(p_path, source);
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index f244bc4119..32a5b30c18 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -113,6 +113,9 @@ class CSharpScript : public Script {
Map<StringName, Vector<Argument> > _signals;
bool signals_invalidated;
+ Vector<ScriptNetData> rpc_functions;
+ Vector<ScriptNetData> rpc_variables;
+
#ifdef TOOLS_ENABLED
List<PropertyInfo> exported_members_cache; // members_cache
Map<StringName, Variant> exported_members_defval_cache; // member_default_values_cache
@@ -146,6 +149,8 @@ class CSharpScript : public Script {
static Ref<CSharpScript> create_for_managed_type(GDMonoClass *p_class, GDMonoClass *p_native);
static void initialize_for_managed_type(Ref<CSharpScript> p_script, GDMonoClass *p_class, GDMonoClass *p_native);
+ MultiplayerAPI::RPCMode _member_get_rpc_mode(IMonoClassMember *p_member) const;
+
protected:
static void _bind_methods();
@@ -187,6 +192,18 @@ public:
virtual int get_member_line(const StringName &p_member) const;
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const;
+ virtual StringName get_rset_property(const uint16_t p_variable_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
+
#ifdef TOOLS_ENABLED
virtual bool is_placeholder_fallback_enabled() const { return placeholder_fallback_enabled; }
#endif
@@ -232,8 +249,6 @@ class CSharpInstance : public ScriptInstance {
void _call_multilevel(MonoObject *p_mono_object, const StringName &p_method, const Variant **p_args, int p_argcount);
- MultiplayerAPI::RPCMode _member_get_rpc_mode(IMonoClassMember *p_member) const;
-
void get_properties_state_for_reloading(List<Pair<StringName, Variant> > &r_state);
public:
@@ -265,7 +280,16 @@ public:
virtual void refcount_incremented();
virtual bool refcount_decremented();
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_variable) const;
+ virtual StringName get_rset_property(const uint16_t p_variable_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
virtual void notification(int p_notification);
diff --git a/modules/opensimplex/doc_classes/NoiseTexture.xml b/modules/opensimplex/doc_classes/NoiseTexture.xml
index 0790cde557..c06f3096de 100644
--- a/modules/opensimplex/doc_classes/NoiseTexture.xml
+++ b/modules/opensimplex/doc_classes/NoiseTexture.xml
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="NoiseTexture" inherits="Texture" version="4.0">
+<class name="NoiseTexture" inherits="Texture2D" version="4.0">
<brief_description>
[OpenSimplexNoise] filled texture.
</brief_description>
<description>
Uses an [OpenSimplexNoise] to fill the texture data. You can specify the texture size but keep in mind that larger textures will take longer to generate and seamless noise only works with square sized textures.
NoiseTexture can also generate normalmap textures.
- The class uses [Thread]s to generate the texture data internally, so [method Texture.get_data] may return [code]null[/code] if the generation process has not completed yet. In that case, you need to wait for the texture to be generated before accessing the data:
+ The class uses [Thread]s to generate the texture data internally, so [method Texture2D.get_data] may return [code]null[/code] if the generation process has not completed yet. In that case, you need to wait for the texture to be generated before accessing the data:
[codeblock]
var texture = preload("res://noise.tres")
yield(texture, "changed")
@@ -24,7 +24,6 @@
<member name="bump_strength" type="float" setter="set_bump_strength" getter="get_bump_strength" default="8.0">
Strength of the bump maps used in this texture. A higher value will make the bump maps appear larger while a lower value will make them appear softer.
</member>
- <member name="flags" type="int" setter="set_flags" getter="get_flags" override="true" default="7" />
<member name="height" type="int" setter="set_height" getter="get_height" default="512">
Height of the generated texture.
</member>
diff --git a/modules/tinyexr/image_saver_tinyexr.cpp b/modules/tinyexr/image_saver_tinyexr.cpp
index ff97d4b85d..a0c01f7e65 100644
--- a/modules/tinyexr/image_saver_tinyexr.cpp
+++ b/modules/tinyexr/image_saver_tinyexr.cpp
@@ -182,7 +182,7 @@ Error save_exr(const String &p_path, const Ref<Image> &p_img, bool p_grayscale)
int target_pixel_type_size = get_pixel_type_size(target_pixel_type);
ERR_FAIL_COND_V(target_pixel_type_size < 0, ERR_UNAVAILABLE);
SrcPixelType src_pixel_type = get_source_pixel_type(format);
- ERR_FAIL_COND_V(src_pixel_type = SRC_UNSUPPORTED, ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(src_pixel_type == SRC_UNSUPPORTED, ERR_UNAVAILABLE);
const int pixel_count = p_img->get_width() * p_img->get_height();
const int *channel_mapping = channel_mappings[channel_count - 1];
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp
index c591e3b5c2..be7443adfa 100644
--- a/modules/visual_script/visual_script.cpp
+++ b/modules/visual_script/visual_script.cpp
@@ -30,6 +30,8 @@
#include "visual_script.h"
+#include <stdint.h>
+
#include "core/core_string_names.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@@ -1102,6 +1104,60 @@ bool VisualScript::are_subnodes_edited() const {
}
#endif
+Vector<ScriptNetData> VisualScript::get_rpc_methods() const {
+ return rpc_functions;
+}
+
+uint16_t VisualScript::get_rpc_method_id(const StringName &p_method) const {
+ for (int i = 0; i < rpc_functions.size(); i++) {
+ if (rpc_functions[i].name == p_method) {
+ return i;
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName VisualScript::get_rpc_method(const uint16_t p_rpc_method_id) const {
+ ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), StringName());
+ return rpc_functions[p_rpc_method_id].name;
+}
+
+MultiplayerAPI::RPCMode VisualScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
+ ERR_FAIL_COND_V(p_rpc_method_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED);
+ return rpc_functions[p_rpc_method_id].mode;
+}
+
+MultiplayerAPI::RPCMode VisualScript::get_rpc_mode(const StringName &p_method) const {
+ return get_rpc_mode_by_id(get_rpc_method_id(p_method));
+}
+
+Vector<ScriptNetData> VisualScript::get_rset_properties() const {
+ return rpc_variables;
+}
+
+uint16_t VisualScript::get_rset_property_id(const StringName &p_variable) const {
+ for (int i = 0; i < rpc_variables.size(); i++) {
+ if (rpc_variables[i].name == p_variable) {
+ return i;
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName VisualScript::get_rset_property(const uint16_t p_rset_property_id) const {
+ ERR_FAIL_COND_V(p_rset_property_id >= rpc_variables.size(), StringName());
+ return rpc_variables[p_rset_property_id].name;
+}
+
+MultiplayerAPI::RPCMode VisualScript::get_rset_mode_by_id(const uint16_t p_rset_variable_id) const {
+ ERR_FAIL_COND_V(p_rset_variable_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED);
+ return rpc_functions[p_rset_variable_id].mode;
+}
+
+MultiplayerAPI::RPCMode VisualScript::get_rset_mode(const StringName &p_variable) const {
+ return get_rset_mode_by_id(get_rset_property_id(p_variable));
+}
+
void VisualScript::_set_data(const Dictionary &p_data) {
Dictionary d = p_data;
@@ -1206,6 +1262,30 @@ void VisualScript::_set_data(const Dictionary &p_data) {
is_tool_script = d["is_tool_script"];
else
is_tool_script = false;
+
+ // Takes all the rpc methods
+ rpc_functions.clear();
+ rpc_variables.clear();
+ for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
+ if (E->get().function_id >= 0 && E->get().nodes.find(E->get().function_id)) {
+ Ref<VisualScriptFunction> vsf = E->get().nodes[E->get().function_id].node;
+ if (vsf.is_valid()) {
+ if (vsf->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) {
+ ScriptNetData nd;
+ nd.name = E->key();
+ nd.mode = vsf->get_rpc_mode();
+ if (rpc_functions.find(nd) == -1) {
+ rpc_functions.push_back(nd);
+ }
+ }
+ }
+ }
+ }
+
+ // Visual script doesn't have rset :(
+
+ // Sort so we are 100% that they are always the same.
+ rpc_functions.sort_custom<SortNetData>();
}
Dictionary VisualScript::_get_data() const {
@@ -2043,31 +2123,44 @@ Ref<Script> VisualScriptInstance::get_script() const {
return script;
}
-MultiplayerAPI::RPCMode VisualScriptInstance::get_rpc_mode(const StringName &p_method) const {
+Vector<ScriptNetData> VisualScriptInstance::get_rpc_methods() const {
+ return script->get_rpc_methods();
+}
- if (p_method == script->get_default_func())
- return MultiplayerAPI::RPC_MODE_DISABLED;
+uint16_t VisualScriptInstance::get_rpc_method_id(const StringName &p_method) const {
+ return script->get_rpc_method_id(p_method);
+}
- const Map<StringName, VisualScript::Function>::Element *E = script->functions.find(p_method);
- if (!E) {
- return MultiplayerAPI::RPC_MODE_DISABLED;
- }
+StringName VisualScriptInstance::get_rpc_method(const uint16_t p_rpc_method_id) const {
+ return script->get_rpc_method(p_rpc_method_id);
+}
- if (E->get().function_id >= 0 && E->get().nodes.has(E->get().function_id)) {
+MultiplayerAPI::RPCMode VisualScriptInstance::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
+ return script->get_rpc_mode_by_id(p_rpc_method_id);
+}
- Ref<VisualScriptFunction> vsf = E->get().nodes[E->get().function_id].node;
- if (vsf.is_valid()) {
+MultiplayerAPI::RPCMode VisualScriptInstance::get_rpc_mode(const StringName &p_method) const {
+ return script->get_rpc_mode(p_method);
+}
- return vsf->get_rpc_mode();
- }
- }
+Vector<ScriptNetData> VisualScriptInstance::get_rset_properties() const {
+ return script->get_rset_properties();
+}
- return MultiplayerAPI::RPC_MODE_DISABLED;
+uint16_t VisualScriptInstance::get_rset_property_id(const StringName &p_variable) const {
+ return script->get_rset_property_id(p_variable);
}
-MultiplayerAPI::RPCMode VisualScriptInstance::get_rset_mode(const StringName &p_variable) const {
+StringName VisualScriptInstance::get_rset_property(const uint16_t p_rset_property_id) const {
+ return script->get_rset_property(p_rset_property_id);
+}
- return MultiplayerAPI::RPC_MODE_DISABLED;
+MultiplayerAPI::RPCMode VisualScriptInstance::get_rset_mode_by_id(const uint16_t p_rset_variable_id) const {
+ return script->get_rset_mode_by_id(p_rset_variable_id);
+}
+
+MultiplayerAPI::RPCMode VisualScriptInstance::get_rset_mode(const StringName &p_variable) const {
+ return script->get_rset_mode(p_variable);
}
void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_owner) {
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index 9305226dc6..d3569bb040 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -245,6 +245,8 @@ private:
Map<StringName, Function> functions;
Map<StringName, Variable> variables;
Map<StringName, Vector<Argument> > custom_signals;
+ Vector<ScriptNetData> rpc_functions;
+ Vector<ScriptNetData> rpc_variables;
Map<Object *, VisualScriptInstance *> instances;
@@ -362,6 +364,18 @@ public:
virtual int get_member_line(const StringName &p_member) const;
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_property) const;
+ virtual StringName get_rset_property(const uint16_t p_rset_property_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
+
#ifdef TOOLS_ENABLED
virtual bool are_subnodes_edited() const;
#endif
@@ -441,7 +455,16 @@ public:
virtual ScriptLanguage *get_language();
+ virtual Vector<ScriptNetData> get_rpc_methods() const;
+ virtual uint16_t get_rpc_method_id(const StringName &p_method) const;
+ virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const;
+ virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
+
+ virtual Vector<ScriptNetData> get_rset_properties() const;
+ virtual uint16_t get_rset_property_id(const StringName &p_property) const;
+ virtual StringName get_rset_property(const uint16_t p_rset_property_id) const;
+ virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
VisualScriptInstance();
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 338194fcae..1fd91ec3c1 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -240,6 +240,11 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
//!!!!!!!!!!!!!!!!!!!!!!!!!!
//TODO - do Vulkan and GLES2 support checks, driver selection and fallback
video_driver_index = p_video_driver;
+#ifndef _MSC_VER
+#warning Forcing vulkan video driver because OpenGL not implemented yet
+#endif
+ video_driver_index = VIDEO_DRIVER_VULKAN;
+
print_verbose("Driver: " + String(get_video_driver_name(video_driver_index)) + " [" + itos(video_driver_index) + "]");
//!!!!!!!!!!!!!!!!!!!!!!!!!!
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index 1d86575b16..34540525af 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -226,8 +226,7 @@ void GIProbeData::_validate_property(PropertyInfo &property) const {
}
void GIProbeData::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("allocate", "to_cell_xform", "aabb", "octree_size", "octree_cells", "octree_data", "octree_level_count"), &GIProbeData::allocate);
+ ClassDB::bind_method(D_METHOD("allocate", "to_cell_xform", "aabb", "octree_size", "octree_cells", "data_cells", "distance_field", "level_counts"), &GIProbeData::allocate);
ClassDB::bind_method(D_METHOD("get_bounds"), &GIProbeData::get_bounds);
ClassDB::bind_method(D_METHOD("get_octree_size"), &GIProbeData::get_octree_size);
@@ -269,7 +268,7 @@ void GIProbeData::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_data", "data"), &GIProbeData::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &GIProbeData::_get_data);
- ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_data", "_get_data");
+ ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
ADD_PROPERTY(PropertyInfo(Variant::INT, "dynamic_range", PROPERTY_HINT_RANGE, "0,8,0.01"), "set_dynamic_range", "get_dynamic_range");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_energy", "get_energy");
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 761fe3f90f..6a7971ddb3 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -30,6 +30,8 @@
#include "node.h"
+#include <stdint.h>
+
#include "core/core_string_names.h"
#include "core/io/resource_loader.h"
#include "core/message_queue.h"
@@ -498,22 +500,38 @@ bool Node::is_network_master() const {
/***** RPC CONFIG ********/
-void Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_mode) {
+uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_mode) {
- if (p_mode == MultiplayerAPI::RPC_MODE_DISABLED) {
- data.rpc_methods.erase(p_method);
+ uint16_t mid = get_node_rpc_method_id(p_method);
+ if (mid == UINT16_MAX) {
+ // It's new
+ NetData nd;
+ nd.name = p_method;
+ nd.mode = p_mode;
+ data.rpc_methods.push_back(nd);
+ return ((uint16_t)data.rpc_properties.size() - 1) | (1 << 15);
} else {
- data.rpc_methods[p_method] = p_mode;
- };
+ int c_mid = (~(1 << 15)) & mid;
+ data.rpc_methods.write[c_mid].mode = p_mode;
+ return mid;
+ }
}
-void Node::rset_config(const StringName &p_property, MultiplayerAPI::RPCMode p_mode) {
+uint16_t Node::rset_config(const StringName &p_property, MultiplayerAPI::RPCMode p_mode) {
- if (p_mode == MultiplayerAPI::RPC_MODE_DISABLED) {
- data.rpc_properties.erase(p_property);
+ uint16_t pid = get_node_rset_property_id(p_property);
+ if (pid == UINT16_MAX) {
+ // It's new
+ NetData nd;
+ nd.name = p_property;
+ nd.mode = p_mode;
+ data.rpc_properties.push_back(nd);
+ return ((uint16_t)data.rpc_properties.size() - 1) | (1 << 15);
} else {
- data.rpc_properties[p_property] = p_mode;
- };
+ int c_pid = (~(1 << 15)) & pid;
+ data.rpc_properties.write[c_pid].mode = p_mode;
+ return pid;
+ }
}
/***** RPC FUNCTIONS ********/
@@ -731,12 +749,94 @@ void Node::set_custom_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
multiplayer = p_multiplayer;
}
-const Map<StringName, MultiplayerAPI::RPCMode>::Element *Node::get_node_rpc_mode(const StringName &p_method) {
- return data.rpc_methods.find(p_method);
+uint16_t Node::get_node_rpc_method_id(const StringName &p_method) const {
+ for (int i = 0; i < data.rpc_methods.size(); i++) {
+ if (data.rpc_methods[i].name == p_method) {
+ // Returns `i` with the high bit set to 1 so we know that this id comes
+ // from the node and not the script.
+ return i | (1 << 15);
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName Node::get_node_rpc_method(const uint16_t p_rpc_method_id) const {
+ // Make sure this is a node generated ID.
+ if (((1 << 15) & p_rpc_method_id) > 0) {
+ int mid = (~(1 << 15)) & p_rpc_method_id;
+ if (mid < data.rpc_methods.size())
+ return data.rpc_methods[mid].name;
+ }
+ return StringName();
+}
+
+MultiplayerAPI::RPCMode Node::get_node_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
+ // Make sure this is a node generated ID.
+ if (((1 << 15) & p_rpc_method_id) > 0) {
+ int mid = (~(1 << 15)) & p_rpc_method_id;
+ if (mid < data.rpc_methods.size())
+ return data.rpc_methods[mid].mode;
+ }
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+}
+
+MultiplayerAPI::RPCMode Node::get_node_rpc_mode(const StringName &p_method) const {
+ return get_node_rpc_mode_by_id(get_node_rpc_method_id(p_method));
}
-const Map<StringName, MultiplayerAPI::RPCMode>::Element *Node::get_node_rset_mode(const StringName &p_property) {
- return data.rpc_properties.find(p_property);
+uint16_t Node::get_node_rset_property_id(const StringName &p_property) const {
+ for (int i = 0; i < data.rpc_properties.size(); i++) {
+ if (data.rpc_properties[i].name == p_property) {
+ // Returns `i` with the high bit set to 1 so we know that this id comes
+ // from the node and not the script.
+ return i | (1 << 15);
+ }
+ }
+ return UINT16_MAX;
+}
+
+StringName Node::get_node_rset_property(const uint16_t p_rset_property_id) const {
+ // Make sure this is a node generated ID.
+ if (((1 << 15) & p_rset_property_id) > 0) {
+ int mid = (~(1 << 15)) & p_rset_property_id;
+ if (mid < data.rpc_properties.size())
+ return data.rpc_properties[mid].name;
+ }
+ return StringName();
+}
+
+MultiplayerAPI::RPCMode Node::get_node_rset_mode_by_id(const uint16_t p_rset_property_id) const {
+ if (((1 << 15) & p_rset_property_id) > 0) {
+ int mid = (~(1 << 15)) & p_rset_property_id;
+ if (mid < data.rpc_properties.size())
+ return data.rpc_properties[mid].mode;
+ }
+ return MultiplayerAPI::RPC_MODE_DISABLED;
+}
+
+MultiplayerAPI::RPCMode Node::get_node_rset_mode(const StringName &p_property) const {
+ return get_node_rset_mode_by_id(get_node_rset_property_id(p_property));
+}
+
+String Node::get_rpc_md5() const {
+ String rpc_list;
+ for (int i = 0; i < data.rpc_methods.size(); i += 1) {
+ rpc_list += String(data.rpc_methods[i].name);
+ }
+ for (int i = 0; i < data.rpc_properties.size(); i += 1) {
+ rpc_list += String(data.rpc_properties[i].name);
+ }
+ if (get_script_instance()) {
+ Vector<ScriptNetData> rpc = get_script_instance()->get_rpc_methods();
+ for (int i = 0; i < rpc.size(); i += 1) {
+ rpc_list += String(rpc[i].name);
+ }
+ rpc = get_script_instance()->get_rset_properties();
+ for (int i = 0; i < rpc.size(); i += 1) {
+ rpc_list += String(rpc[i].name);
+ }
+ }
+ return rpc_list.md5_text();
}
bool Node::can_process_notification(int p_what) const {
diff --git a/scene/main/node.h b/scene/main/node.h
index 6f5544d654..02c828e8ff 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -85,6 +85,11 @@ private:
GroupData() { persistent = false; }
};
+ struct NetData {
+ StringName name;
+ MultiplayerAPI::RPCMode mode;
+ };
+
struct Data {
String filename;
@@ -118,8 +123,8 @@ private:
Node *pause_owner;
int network_master;
- Map<StringName, MultiplayerAPI::RPCMode> rpc_methods;
- Map<StringName, MultiplayerAPI::RPCMode> rpc_properties;
+ Vector<NetData> rpc_methods;
+ Vector<NetData> rpc_properties;
// variables used to properly sort the node when processing, ignored otherwise
//should move all the stuff below to bits
@@ -427,8 +432,8 @@ public:
int get_network_master() const;
bool is_network_master() const;
- void rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_mode); // config a local method for RPC
- void rset_config(const StringName &p_property, MultiplayerAPI::RPCMode p_mode); // config a local property for RPC
+ uint16_t rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_mode); // config a local method for RPC
+ uint16_t rset_config(const StringName &p_property, MultiplayerAPI::RPCMode p_mode); // config a local property for RPC
void rpc(const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode
void rpc_unreliable(const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode
@@ -446,8 +451,22 @@ public:
Ref<MultiplayerAPI> get_multiplayer() const;
Ref<MultiplayerAPI> get_custom_multiplayer() const;
void set_custom_multiplayer(Ref<MultiplayerAPI> p_multiplayer);
- const Map<StringName, MultiplayerAPI::RPCMode>::Element *get_node_rpc_mode(const StringName &p_method);
- const Map<StringName, MultiplayerAPI::RPCMode>::Element *get_node_rset_mode(const StringName &p_property);
+
+ /// Returns the rpc method ID, otherwise UINT32_MAX
+ uint16_t get_node_rpc_method_id(const StringName &p_method) const;
+ StringName get_node_rpc_method(const uint16_t p_rpc_method_id) const;
+ MultiplayerAPI::RPCMode get_node_rpc_mode_by_id(const uint16_t p_rpc_method_id) const;
+ MultiplayerAPI::RPCMode get_node_rpc_mode(const StringName &p_method) const;
+
+ /// Returns the rpc property ID, otherwise UINT32_MAX
+ uint16_t get_node_rset_property_id(const StringName &p_property) const;
+ StringName get_node_rset_property(const uint16_t p_rset_property_id) const;
+ MultiplayerAPI::RPCMode get_node_rset_mode_by_id(const uint16_t p_rpc_method_id) const;
+ MultiplayerAPI::RPCMode get_node_rset_mode(const StringName &p_property) const;
+
+ /// Can be used to check if the rpc methods and the rset properties are the
+ /// same across the peers.
+ String get_rpc_md5() const;
Node();
~Node();
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index d72036462e..285b11fefd 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -1107,11 +1107,11 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "adjustment_saturation", PROPERTY_HINT_RANGE, "0.01,8,0.01"), "set_adjustment_saturation", "get_adjustment_saturation");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "adjustment_color_correction", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_adjustment_color_correction", "get_adjustment_color_correction");
- BIND_ENUM_CONSTANT(BG_KEEP);
BIND_ENUM_CONSTANT(BG_CLEAR_COLOR);
BIND_ENUM_CONSTANT(BG_COLOR);
BIND_ENUM_CONSTANT(BG_SKY);
BIND_ENUM_CONSTANT(BG_CANVAS);
+ BIND_ENUM_CONSTANT(BG_KEEP);
BIND_ENUM_CONSTANT(BG_CAMERA_FEED);
BIND_ENUM_CONSTANT(BG_MAX);
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index c4e0161cc2..b8c396062a 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -2375,11 +2375,6 @@ void BaseMaterial3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "distance_fade_min_distance", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_distance_fade_min_distance", "get_distance_fade_min_distance");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "distance_fade_max_distance", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_distance_fade_max_distance", "get_distance_fade_max_distance");
- BIND_ENUM_CONSTANT(TRANSPARENCY_DISABLED);
- BIND_ENUM_CONSTANT(TRANSPARENCY_ALPHA);
- BIND_ENUM_CONSTANT(TRANSPARENCY_ALPHA_SCISSOR);
- BIND_ENUM_CONSTANT(TRANSPARENCY_ALPHA_DEPTH_PRE_PASS);
-
BIND_ENUM_CONSTANT(TEXTURE_ALBEDO);
BIND_ENUM_CONSTANT(TEXTURE_METALLIC);
BIND_ENUM_CONSTANT(TEXTURE_ROUGHNESS);
@@ -2396,11 +2391,31 @@ void BaseMaterial3D::_bind_methods() {
BIND_ENUM_CONSTANT(TEXTURE_DETAIL_MASK);
BIND_ENUM_CONSTANT(TEXTURE_DETAIL_ALBEDO);
BIND_ENUM_CONSTANT(TEXTURE_DETAIL_NORMAL);
+ BIND_ENUM_CONSTANT(TEXTURE_ORM);
BIND_ENUM_CONSTANT(TEXTURE_MAX);
+ BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST);
+ BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR);
+ BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS);
+ BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR_WITH_MIPMAPS);
+ BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS_ANISOTROPIC);
+ BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC);
+ BIND_ENUM_CONSTANT(TEXTURE_FILTER_MAX);
+
BIND_ENUM_CONSTANT(DETAIL_UV_1);
BIND_ENUM_CONSTANT(DETAIL_UV_2);
+ BIND_ENUM_CONSTANT(TRANSPARENCY_DISABLED);
+ BIND_ENUM_CONSTANT(TRANSPARENCY_ALPHA);
+ BIND_ENUM_CONSTANT(TRANSPARENCY_ALPHA_SCISSOR);
+ BIND_ENUM_CONSTANT(TRANSPARENCY_ALPHA_DEPTH_PRE_PASS);
+ BIND_ENUM_CONSTANT(TRANSPARENCY_MAX);
+
+ BIND_ENUM_CONSTANT(SHADING_MODE_UNSHADED);
+ BIND_ENUM_CONSTANT(SHADING_MODE_PER_PIXEL);
+ BIND_ENUM_CONSTANT(SHADING_MODE_PER_VERTEX);
+ BIND_ENUM_CONSTANT(SHADING_MODE_MAX);
+
BIND_ENUM_CONSTANT(FEATURE_EMISSION);
BIND_ENUM_CONSTANT(FEATURE_NORMAL_MAPPING);
BIND_ENUM_CONSTANT(FEATURE_RIM);
@@ -2444,6 +2459,7 @@ void BaseMaterial3D::_bind_methods() {
BIND_ENUM_CONSTANT(FLAG_DISABLE_AMBIENT_LIGHT);
BIND_ENUM_CONSTANT(FLAG_USE_SHADOW_TO_OPACITY);
BIND_ENUM_CONSTANT(FLAG_USE_TEXTURE_REPEAT);
+ BIND_ENUM_CONSTANT(FLAG_INVERT_HEIGHTMAP);
BIND_ENUM_CONSTANT(FLAG_MAX);
BIND_ENUM_CONSTANT(DIFFUSE_BURLEY);
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index 571415a045..6049d96fee 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -1589,7 +1589,7 @@ void ArrayMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_surfaces", "surfaces"), &ArrayMesh::_set_surfaces);
ClassDB::bind_method(D_METHOD("_get_surfaces"), &ArrayMesh::_get_surfaces);
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_surfaces", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_surfaces", "_get_surfaces");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_surfaces", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_surfaces", "_get_surfaces");
ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_shape_mode", PROPERTY_HINT_ENUM, "Normalized,Relative"), "set_blend_shape_mode", "get_blend_shape_mode");
ADD_PROPERTY(PropertyInfo(Variant::AABB, "custom_aabb", PROPERTY_HINT_NONE, ""), "set_custom_aabb", "get_custom_aabb");
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 20c3654c2f..4ddceed58e 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -46,18 +46,21 @@ Size2 Texture2D::get_size() const {
bool Texture2D::is_pixel_opaque(int p_x, int p_y) const {
return true;
}
+
void Texture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const {
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, get_size()), get_rid(), false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
+
void Texture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const {
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, get_rid(), p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
+
void Texture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
@@ -79,9 +82,9 @@ void Texture2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_height"), &Texture2D::get_height);
ClassDB::bind_method(D_METHOD("get_size"), &Texture2D::get_size);
ClassDB::bind_method(D_METHOD("has_alpha"), &Texture2D::has_alpha);
- ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess"), &Texture2D::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)));
- ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess"), &Texture2D::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)));
- ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "normal_map", "clip_uv", "specular_map", "specular_color_shininess"), &Texture2D::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat"), &Texture2D::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT));
+ ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat"), &Texture2D::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT));
+ ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat", "clip_uv"), &Texture2D::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT), DEFVAL(true));
ClassDB::bind_method(D_METHOD("get_data"), &Texture2D::get_data);
ADD_GROUP("", "");
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index 9959936212..72c9a7f913 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -113,7 +113,7 @@ public:
~InstanceDependency();
private:
- friend class InstanceBase;
+ friend struct InstanceBase;
Map<InstanceBase *, uint32_t> instances;
};
diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp
index c1adcba378..e95b7c0b2a 100644
--- a/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp
+++ b/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "rasterizer_scene_rd.h"
+
#include "core/os/os.h"
#include "core/project_settings.h"
#include "servers/visual/visual_server_raster.h"
@@ -2581,7 +2582,7 @@ void RasterizerSceneRD::_render_buffers_post_process_and_tonemap(RID p_render_bu
if (can_use_effects && env && env->glow_enabled) {
tonemap.use_glow = true;
tonemap.glow_mode = RasterizerEffectsRD::TonemapSettings::GlowMode(env->glow_blend_mode);
- tonemap.glow_intensity = env->glow_blend_mode == VS::GLOW_BLEND_MODE_MIX ? env->glow_mix : env->glow_intensity;
+ tonemap.glow_intensity = env->glow_blend_mode == VS::ENV_GLOW_BLEND_MODE_MIX ? env->glow_mix : env->glow_intensity;
tonemap.glow_level_flags = glow_mask;
tonemap.glow_texture_size.x = rb->blur[1].mipmaps[0].width;
tonemap.glow_texture_size.y = rb->blur[1].mipmaps[0].height;
diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_rd.h b/servers/visual/rasterizer_rd/rasterizer_scene_rd.h
index 89f4b51dce..541c28f11f 100644
--- a/servers/visual/rasterizer_rd/rasterizer_scene_rd.h
+++ b/servers/visual/rasterizer_rd/rasterizer_scene_rd.h
@@ -484,7 +484,7 @@ private:
float glow_strength = 1.0;
float glow_bloom = 0.0;
float glow_mix = 0.01;
- VS::EnvironmentGlowBlendMode glow_blend_mode = VS::GLOW_BLEND_MODE_SOFTLIGHT;
+ VS::EnvironmentGlowBlendMode glow_blend_mode = VS::ENV_GLOW_BLEND_MODE_SOFTLIGHT;
float glow_hdr_bleed_threshold = 1.0;
float glow_hdr_luminance_cap = 12.0;
float glow_hdr_bleed_scale = 2.0;
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp
index 2af6f7bfea..b345a2ea77 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -1619,7 +1619,7 @@ void VisualServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("mesh_create"), &VisualServer::mesh_create);
ClassDB::bind_method(D_METHOD("mesh_surface_get_format_offset", "format", "vertex_len", "index_len", "array_index"), &VisualServer::mesh_surface_get_format_offset);
ClassDB::bind_method(D_METHOD("mesh_surface_get_format_stride", "format", "vertex_len", "index_len"), &VisualServer::mesh_surface_get_format_stride);
- ClassDB::bind_method(D_METHOD("mesh_add_surface_from_arrays", "mesh", "primitive", "arrays", "blend_shapes", "compress_format"), &VisualServer::mesh_add_surface_from_arrays, DEFVAL(Array()), DEFVAL(ARRAY_COMPRESS_DEFAULT));
+ ClassDB::bind_method(D_METHOD("mesh_add_surface_from_arrays", "mesh", "primitive", "arrays", "blend_shapes", "lods", "compress_format"), &VisualServer::mesh_add_surface_from_arrays, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(ARRAY_COMPRESS_DEFAULT));
ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_count", "mesh"), &VisualServer::mesh_get_blend_shape_count);
ClassDB::bind_method(D_METHOD("mesh_set_blend_shape_mode", "mesh", "mode"), &VisualServer::mesh_set_blend_shape_mode);
ClassDB::bind_method(D_METHOD("mesh_get_blend_shape_mode", "mesh"), &VisualServer::mesh_get_blend_shape_mode);
@@ -1820,8 +1820,8 @@ void VisualServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("environment_set_bg_color", "env", "color"), &VisualServer::environment_set_bg_color);
ClassDB::bind_method(D_METHOD("environment_set_bg_energy", "env", "energy"), &VisualServer::environment_set_bg_energy);
ClassDB::bind_method(D_METHOD("environment_set_canvas_max_layer", "env", "max_layer"), &VisualServer::environment_set_canvas_max_layer);
- ClassDB::bind_method(D_METHOD("environment_set_ambient_light", "env", "color", "energy", "sky_contibution"), &VisualServer::environment_set_ambient_light, DEFVAL(1.0), DEFVAL(0.0));
- ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "level_flags", "intensity", "strength", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap", "bicubic_upscale"), &VisualServer::environment_set_glow);
+ ClassDB::bind_method(D_METHOD("environment_set_ambient_light", "env", "color", "ambient", "energy", "sky_contibution", "reflection_source", "ao_color"), &VisualServer::environment_set_ambient_light, DEFVAL(VS::ENV_AMBIENT_SOURCE_BG), DEFVAL(1.0), DEFVAL(0.0), DEFVAL(VS::ENV_REFLECTION_SOURCE_BG), DEFVAL(Color()));
+ ClassDB::bind_method(D_METHOD("environment_set_glow", "env", "enable", "level_flags", "intensity", "strength", "mix", "bloom_threshold", "blend_mode", "hdr_bleed_threshold", "hdr_bleed_scale", "hdr_luminance_cap", "bicubic_upscale"), &VisualServer::environment_set_glow);
ClassDB::bind_method(D_METHOD("environment_set_tonemap", "env", "tone_mapper", "exposure", "white", "auto_exposure", "min_luminance", "max_luminance", "auto_exp_speed", "auto_exp_grey"), &VisualServer::environment_set_tonemap);
ClassDB::bind_method(D_METHOD("environment_set_adjustment", "env", "enable", "brightness", "contrast", "saturation", "ramp"), &VisualServer::environment_set_adjustment);
ClassDB::bind_method(D_METHOD("environment_set_ssr", "env", "enable", "max_steps", "fade_in", "fade_out", "depth_tolerance", "roughness"), &VisualServer::environment_set_ssr);
@@ -1973,9 +1973,14 @@ void VisualServer::_bind_methods() {
BIND_CONSTANT(CANVAS_ITEM_Z_MAX);
BIND_CONSTANT(MAX_GLOW_LEVELS);
BIND_CONSTANT(MAX_CURSORS);
+
BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MIN);
BIND_CONSTANT(MATERIAL_RENDER_PRIORITY_MAX);
+ BIND_ENUM_CONSTANT(TEXTURE_LAYERED_2D_ARRAY);
+ BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP);
+ BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP_ARRAY);
+
BIND_ENUM_CONSTANT(CUBEMAP_LAYER_LEFT);
BIND_ENUM_CONSTANT(CUBEMAP_LAYER_RIGHT);
BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BOTTOM);
@@ -1983,10 +1988,6 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(CUBEMAP_LAYER_FRONT);
BIND_ENUM_CONSTANT(CUBEMAP_LAYER_BACK);
- BIND_ENUM_CONSTANT(TEXTURE_LAYERED_2D_ARRAY);
- BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP);
- BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP_ARRAY);
-
BIND_ENUM_CONSTANT(SHADER_SPATIAL);
BIND_ENUM_CONSTANT(SHADER_CANVAS_ITEM);
BIND_ENUM_CONSTANT(SHADER_PARTICLES);
@@ -2020,6 +2021,7 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV2);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_INDEX);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES);
+ BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_DYNAMIC_UPDATE);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_DEFAULT);
BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);
@@ -2032,11 +2034,15 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED);
BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE);
+ BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D);
+ BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D);
+
BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL);
BIND_ENUM_CONSTANT(LIGHT_OMNI);
BIND_ENUM_CONSTANT(LIGHT_SPOT);
BIND_ENUM_CONSTANT(LIGHT_PARAM_ENERGY);
+ BIND_ENUM_CONSTANT(LIGHT_PARAM_INDIRECT_ENERGY);
BIND_ENUM_CONSTANT(LIGHT_PARAM_SPECULAR);
BIND_ENUM_CONSTANT(LIGHT_PARAM_RANGE);
BIND_ENUM_CONSTANT(LIGHT_PARAM_ATTENUATION);
@@ -2059,9 +2065,17 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL);
BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS);
BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS);
+
BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE);
BIND_ENUM_CONSTANT(LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED);
+ BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE);
+ BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS);
+
+ BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_INDEX);
+ BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_LIFETIME);
+ BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_VIEW_DEPTH);
+
BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_DISABLED);
BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_ONCE);
BIND_ENUM_CONSTANT(VIEWPORT_UPDATE_WHEN_VISIBLE);
@@ -2089,8 +2103,72 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DISABLED);
BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_UNSHADED);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_LIGHTING);
BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_OVERDRAW);
BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_WIREFRAME);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_NORMAL_BUFFER);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_GI_PROBE_ALBEDO);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SHADOW_ATLAS);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SCENE_LUMINANCE);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_SSAO);
+ BIND_ENUM_CONSTANT(VIEWPORT_DEBUG_DRAW_ROUGHNESS_LIMITER);
+
+ BIND_ENUM_CONSTANT(SKY_MODE_QUALITY);
+ BIND_ENUM_CONSTANT(SKY_MODE_REALTIME);
+
+ BIND_ENUM_CONSTANT(ENV_BG_CLEAR_COLOR);
+ BIND_ENUM_CONSTANT(ENV_BG_COLOR);
+ BIND_ENUM_CONSTANT(ENV_BG_SKY);
+ BIND_ENUM_CONSTANT(ENV_BG_CANVAS);
+ BIND_ENUM_CONSTANT(ENV_BG_KEEP);
+ BIND_ENUM_CONSTANT(ENV_BG_CAMERA_FEED);
+ BIND_ENUM_CONSTANT(ENV_BG_MAX);
+
+ BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_BG);
+ BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_DISABLED);
+ BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_COLOR);
+ BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_SKY);
+
+ BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_BG);
+ BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_DISABLED);
+ BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_SKY);
+
+ BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_ADDITIVE);
+ BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_SCREEN);
+ BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_SOFTLIGHT);
+ BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_REPLACE);
+ BIND_ENUM_CONSTANT(ENV_GLOW_BLEND_MODE_MIX);
+
+ BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_LINEAR);
+ BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_REINHARD);
+ BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_FILMIC);
+ BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_ACES);
+
+ BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_LOW);
+ BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_MEDIUM);
+ BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH);
+
+ BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_DISABLED);
+ BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_1x1);
+ BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_2x2);
+ BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_3x3);
+
+ BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_LOW);
+ BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_MEDIUM);
+ BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH);
+ BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_ULTRA);
+
+ BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_VERY_LOW);
+ BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_LOW);
+ BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_MEDIUM);
+ BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_HIGH);
+
+ BIND_ENUM_CONSTANT(DOF_BOKEH_BOX);
+ BIND_ENUM_CONSTANT(DOF_BOKEH_HEXAGON);
+ BIND_ENUM_CONSTANT(DOF_BOKEH_CIRCLE);
BIND_ENUM_CONSTANT(SCENARIO_DEBUG_DISABLED);
BIND_ENUM_CONSTANT(SCENARIO_DEBUG_WIREFRAME);
@@ -2110,6 +2188,7 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(INSTANCE_GEOMETRY_MASK);
BIND_ENUM_CONSTANT(INSTANCE_FLAG_USE_BAKED_LIGHT);
+ BIND_ENUM_CONSTANT(INSTANCE_FLAG_USE_DYNAMIC_GI);
BIND_ENUM_CONSTANT(INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE);
BIND_ENUM_CONSTANT(INSTANCE_FLAG_MAX);
@@ -2122,6 +2201,21 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(NINE_PATCH_TILE);
BIND_ENUM_CONSTANT(NINE_PATCH_TILE_FIT);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_DEFAULT);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_NEAREST);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_LINEAR);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIMPAMPS_ANISOTROPIC);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_FILTER_MAX);
+
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_ENABLED);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_MIRROR);
+ BIND_ENUM_CONSTANT(CANVAS_ITEM_TEXTURE_REPEAT_MAX);
+
BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_ADD);
BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_SUB);
BIND_ENUM_CONSTANT(CANVAS_LIGHT_MODE_MIX);
@@ -2130,6 +2224,7 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_NONE);
BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF5);
BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_PCF13);
+ BIND_ENUM_CONSTANT(CANVAS_LIGHT_FILTER_MAX);
BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_DISABLED);
BIND_ENUM_CONSTANT(CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE);
@@ -2149,55 +2244,6 @@ void VisualServer::_bind_methods() {
BIND_ENUM_CONSTANT(FEATURE_SHADERS);
BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED);
- BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D);
- BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D);
-
- BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE);
- BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS);
-
- BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_INDEX);
- BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_LIFETIME);
- BIND_ENUM_CONSTANT(PARTICLES_DRAW_ORDER_VIEW_DEPTH);
-
- BIND_ENUM_CONSTANT(ENV_BG_CLEAR_COLOR);
- BIND_ENUM_CONSTANT(ENV_BG_COLOR);
- BIND_ENUM_CONSTANT(ENV_BG_SKY);
- BIND_ENUM_CONSTANT(ENV_BG_CANVAS);
- BIND_ENUM_CONSTANT(ENV_BG_KEEP);
- BIND_ENUM_CONSTANT(ENV_BG_MAX);
-
- BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_BG);
- BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_DISABLED);
- BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_COLOR);
- BIND_ENUM_CONSTANT(ENV_AMBIENT_SOURCE_SKY);
-
- BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_BG);
- BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_DISABLED);
- BIND_ENUM_CONSTANT(ENV_REFLECTION_SOURCE_SKY);
-
- BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_LOW);
- BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_MEDIUM);
- BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_HIGH);
-
- BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_ADDITIVE);
- BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SCREEN);
- BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SOFTLIGHT);
- BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_REPLACE);
-
- BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_LINEAR);
- BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_REINHARD);
- BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_FILMIC);
- BIND_ENUM_CONSTANT(ENV_TONE_MAPPER_ACES);
-
- BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_LOW);
- BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_MEDIUM);
- BIND_ENUM_CONSTANT(ENV_SSAO_QUALITY_HIGH);
-
- BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_DISABLED);
- BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_1x1);
- BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_2x2);
- BIND_ENUM_CONSTANT(ENV_SSAO_BLUR_3x3);
-
ADD_SIGNAL(MethodInfo("frame_pre_draw"));
ADD_SIGNAL(MethodInfo("frame_post_draw"));
}
diff --git a/servers/visual_server.h b/servers/visual_server.h
index 7ff28d9731..9b7a3ffa76 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -68,13 +68,11 @@ public:
static VisualServer *create();
enum {
-
NO_INDEX_ARRAY = -1,
ARRAY_WEIGHTS_SIZE = 4,
CANVAS_ITEM_Z_MIN = -4096,
CANVAS_ITEM_Z_MAX = 4096,
MAX_GLOW_LEVELS = 7,
-
MAX_CURSORS = 8,
};
@@ -728,11 +726,11 @@ public:
#endif
enum EnvironmentGlowBlendMode {
- GLOW_BLEND_MODE_ADDITIVE,
- GLOW_BLEND_MODE_SCREEN,
- GLOW_BLEND_MODE_SOFTLIGHT,
- GLOW_BLEND_MODE_REPLACE,
- GLOW_BLEND_MODE_MIX,
+ ENV_GLOW_BLEND_MODE_ADDITIVE,
+ ENV_GLOW_BLEND_MODE_SCREEN,
+ ENV_GLOW_BLEND_MODE_SOFTLIGHT,
+ ENV_GLOW_BLEND_MODE_REPLACE,
+ ENV_GLOW_BLEND_MODE_MIX,
};
virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) = 0;
@@ -1116,27 +1114,20 @@ VARIANT_ENUM_CAST(VisualServer::ArrayType);
VARIANT_ENUM_CAST(VisualServer::ArrayFormat);
VARIANT_ENUM_CAST(VisualServer::PrimitiveType);
VARIANT_ENUM_CAST(VisualServer::BlendShapeMode);
+VARIANT_ENUM_CAST(VisualServer::MultimeshTransformFormat);
VARIANT_ENUM_CAST(VisualServer::LightType);
VARIANT_ENUM_CAST(VisualServer::LightParam);
-VARIANT_ENUM_CAST(VisualServer::ViewportUpdateMode);
-VARIANT_ENUM_CAST(VisualServer::ViewportClearMode);
-VARIANT_ENUM_CAST(VisualServer::ViewportMSAA);
-VARIANT_ENUM_CAST(VisualServer::ViewportRenderInfo);
-VARIANT_ENUM_CAST(VisualServer::ViewportDebugDraw);
-VARIANT_ENUM_CAST(VisualServer::ScenarioDebugMode);
-VARIANT_ENUM_CAST(VisualServer::InstanceType);
-VARIANT_ENUM_CAST(VisualServer::NinePatchAxisMode);
-VARIANT_ENUM_CAST(VisualServer::CanvasLightMode);
-VARIANT_ENUM_CAST(VisualServer::CanvasLightShadowFilter);
-VARIANT_ENUM_CAST(VisualServer::CanvasOccluderPolygonCullMode);
-VARIANT_ENUM_CAST(VisualServer::RenderInfo);
-VARIANT_ENUM_CAST(VisualServer::Features);
-VARIANT_ENUM_CAST(VisualServer::MultimeshTransformFormat);
VARIANT_ENUM_CAST(VisualServer::LightOmniShadowMode);
VARIANT_ENUM_CAST(VisualServer::LightDirectionalShadowMode);
VARIANT_ENUM_CAST(VisualServer::LightDirectionalShadowDepthRangeMode);
VARIANT_ENUM_CAST(VisualServer::ReflectionProbeUpdateMode);
VARIANT_ENUM_CAST(VisualServer::ParticlesDrawOrder);
+VARIANT_ENUM_CAST(VisualServer::ViewportUpdateMode);
+VARIANT_ENUM_CAST(VisualServer::ViewportClearMode);
+VARIANT_ENUM_CAST(VisualServer::ViewportMSAA);
+VARIANT_ENUM_CAST(VisualServer::ViewportRenderInfo);
+VARIANT_ENUM_CAST(VisualServer::ViewportDebugDraw);
+VARIANT_ENUM_CAST(VisualServer::SkyMode);
VARIANT_ENUM_CAST(VisualServer::EnvironmentBG);
VARIANT_ENUM_CAST(VisualServer::EnvironmentAmbientSource);
VARIANT_ENUM_CAST(VisualServer::EnvironmentReflectionSource);
@@ -1145,10 +1136,19 @@ VARIANT_ENUM_CAST(VisualServer::EnvironmentToneMapper);
VARIANT_ENUM_CAST(VisualServer::EnvironmentSSAOQuality);
VARIANT_ENUM_CAST(VisualServer::EnvironmentSSAOBlur);
VARIANT_ENUM_CAST(VisualServer::DOFBlurQuality);
+VARIANT_ENUM_CAST(VisualServer::DOFBokehShape);
+VARIANT_ENUM_CAST(VisualServer::ScenarioDebugMode);
+VARIANT_ENUM_CAST(VisualServer::InstanceType);
VARIANT_ENUM_CAST(VisualServer::InstanceFlags);
VARIANT_ENUM_CAST(VisualServer::ShadowCastingSetting);
+VARIANT_ENUM_CAST(VisualServer::NinePatchAxisMode);
VARIANT_ENUM_CAST(VisualServer::CanvasItemTextureFilter);
VARIANT_ENUM_CAST(VisualServer::CanvasItemTextureRepeat);
+VARIANT_ENUM_CAST(VisualServer::CanvasLightMode);
+VARIANT_ENUM_CAST(VisualServer::CanvasLightShadowFilter);
+VARIANT_ENUM_CAST(VisualServer::CanvasOccluderPolygonCullMode);
+VARIANT_ENUM_CAST(VisualServer::RenderInfo);
+VARIANT_ENUM_CAST(VisualServer::Features);
//typedef VisualServer VS; // makes it easier to use
#define VS VisualServer
diff --git a/thirdparty/vulkan/vk_mem_alloc.h b/thirdparty/vulkan/vk_mem_alloc.h
index 862ea312a6..465864b363 100644
--- a/thirdparty/vulkan/vk_mem_alloc.h
+++ b/thirdparty/vulkan/vk_mem_alloc.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -29,9 +29,9 @@ extern "C" {
/** \mainpage Vulkan Memory Allocator
-<b>Version 2.3.0-development</b> (2019-03-05)
+<b>Version 2.3.0</b> (2019-12-04)
-Copyright (c) 2017-2018 Advanced Micro Devices, Inc. All rights reserved. \n
+Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved. \n
License: MIT
Documentation of all members: vk_mem_alloc.h
@@ -40,46 +40,50 @@ Documentation of all members: vk_mem_alloc.h
- <b>User guide</b>
- \subpage quick_start
- - [Project setup](@ref quick_start_project_setup)
- - [Initialization](@ref quick_start_initialization)
- - [Resource allocation](@ref quick_start_resource_allocation)
+ - [Project setup](@ref quick_start_project_setup)
+ - [Initialization](@ref quick_start_initialization)
+ - [Resource allocation](@ref quick_start_resource_allocation)
- \subpage choosing_memory_type
- - [Usage](@ref choosing_memory_type_usage)
- - [Required and preferred flags](@ref choosing_memory_type_required_preferred_flags)
- - [Explicit memory types](@ref choosing_memory_type_explicit_memory_types)
- - [Custom memory pools](@ref choosing_memory_type_custom_memory_pools)
- - [Dedicated allocations](@ref choosing_memory_type_dedicated_allocations)
+ - [Usage](@ref choosing_memory_type_usage)
+ - [Required and preferred flags](@ref choosing_memory_type_required_preferred_flags)
+ - [Explicit memory types](@ref choosing_memory_type_explicit_memory_types)
+ - [Custom memory pools](@ref choosing_memory_type_custom_memory_pools)
+ - [Dedicated allocations](@ref choosing_memory_type_dedicated_allocations)
- \subpage memory_mapping
- - [Mapping functions](@ref memory_mapping_mapping_functions)
- - [Persistently mapped memory](@ref memory_mapping_persistently_mapped_memory)
- - [Cache control](@ref memory_mapping_cache_control)
- - [Finding out if memory is mappable](@ref memory_mapping_finding_if_memory_mappable)
+ - [Mapping functions](@ref memory_mapping_mapping_functions)
+ - [Persistently mapped memory](@ref memory_mapping_persistently_mapped_memory)
+ - [Cache flush and invalidate](@ref memory_mapping_cache_control)
+ - [Finding out if memory is mappable](@ref memory_mapping_finding_if_memory_mappable)
+ - \subpage staying_within_budget
+ - [Querying for budget](@ref staying_within_budget_querying_for_budget)
+ - [Controlling memory usage](@ref staying_within_budget_controlling_memory_usage)
- \subpage custom_memory_pools
- - [Choosing memory type index](@ref custom_memory_pools_MemTypeIndex)
- - [Linear allocation algorithm](@ref linear_algorithm)
- - [Free-at-once](@ref linear_algorithm_free_at_once)
- - [Stack](@ref linear_algorithm_stack)
- - [Double stack](@ref linear_algorithm_double_stack)
- - [Ring buffer](@ref linear_algorithm_ring_buffer)
- - [Buddy allocation algorithm](@ref buddy_algorithm)
+ - [Choosing memory type index](@ref custom_memory_pools_MemTypeIndex)
+ - [Linear allocation algorithm](@ref linear_algorithm)
+ - [Free-at-once](@ref linear_algorithm_free_at_once)
+ - [Stack](@ref linear_algorithm_stack)
+ - [Double stack](@ref linear_algorithm_double_stack)
+ - [Ring buffer](@ref linear_algorithm_ring_buffer)
+ - [Buddy allocation algorithm](@ref buddy_algorithm)
- \subpage defragmentation
- - [Defragmenting CPU memory](@ref defragmentation_cpu)
- - [Defragmenting GPU memory](@ref defragmentation_gpu)
- - [Additional notes](@ref defragmentation_additional_notes)
- - [Writing custom allocation algorithm](@ref defragmentation_custom_algorithm)
+ - [Defragmenting CPU memory](@ref defragmentation_cpu)
+ - [Defragmenting GPU memory](@ref defragmentation_gpu)
+ - [Additional notes](@ref defragmentation_additional_notes)
+ - [Writing custom allocation algorithm](@ref defragmentation_custom_algorithm)
- \subpage lost_allocations
- \subpage statistics
- - [Numeric statistics](@ref statistics_numeric_statistics)
- - [JSON dump](@ref statistics_json_dump)
+ - [Numeric statistics](@ref statistics_numeric_statistics)
+ - [JSON dump](@ref statistics_json_dump)
- \subpage allocation_annotation
- - [Allocation user data](@ref allocation_user_data)
- - [Allocation names](@ref allocation_names)
+ - [Allocation user data](@ref allocation_user_data)
+ - [Allocation names](@ref allocation_names)
- \subpage debugging_memory_usage
- - [Memory initialization](@ref debugging_memory_usage_initialization)
- - [Margins](@ref debugging_memory_usage_margins)
- - [Corruption detection](@ref debugging_memory_usage_corruption_detection)
+ - [Memory initialization](@ref debugging_memory_usage_initialization)
+ - [Margins](@ref debugging_memory_usage_margins)
+ - [Corruption detection](@ref debugging_memory_usage_corruption_detection)
- \subpage record_and_replay
- \subpage usage_patterns
+ - [Common mistakes](@ref usage_patterns_common_mistakes)
- [Simple patterns](@ref usage_patterns_simple)
- [Advanced patterns](@ref usage_patterns_advanced)
- \subpage configuration
@@ -88,6 +92,7 @@ Documentation of all members: vk_mem_alloc.h
- [Device memory allocation callbacks](@ref allocation_callbacks)
- [Device heap memory limit](@ref heap_memory_limit)
- \subpage vk_khr_dedicated_allocation
+ - \subpage vk_amd_device_coherent_memory
- \subpage general_considerations
- [Thread safety](@ref general_considerations_thread_safety)
- [Validation layer warnings](@ref general_considerations_validation_layer_warnings)
@@ -206,7 +211,8 @@ You can also combine multiple methods.
-# If you already have a buffer or an image created, you want to allocate memory
for it and then you will bind it yourself, you can use function
vmaAllocateMemoryForBuffer(), vmaAllocateMemoryForImage().
- For binding you should use functions: vmaBindBufferMemory(), vmaBindImageMemory().
+ For binding you should use functions: vmaBindBufferMemory(), vmaBindImageMemory()
+ or their extended versions: vmaBindBufferMemory2(), vmaBindImageMemory2().
-# If you want to create a buffer or an image, allocate memory for it and bind
them together, all in one call, you can use function vmaCreateBuffer(),
vmaCreateImage(). This is the easiest and recommended way to use this library.
@@ -351,7 +357,7 @@ Example:
struct ConstantBuffer
{
- ...
+ ...
};
ConstantBuffer constantBufferData;
@@ -421,12 +427,13 @@ There are some exceptions though, when you should consider mapping memory only f
which requires unmapping before GPU can see updated texture.
- Keeping many large memory blocks mapped may impact performance or stability of some debugging tools.
-\section memory_mapping_cache_control Cache control
-
+\section memory_mapping_cache_control Cache flush and invalidate
+
Memory in Vulkan doesn't need to be unmapped before using it on GPU,
but unless a memory types has `VK_MEMORY_PROPERTY_HOST_COHERENT_BIT` flag set,
-you need to manually invalidate cache before reading of mapped pointer
-and flush cache after writing to mapped pointer.
+you need to manually **invalidate** cache before reading of mapped pointer
+and **flush** cache after writing to mapped pointer.
+Map/unmap operations don't do that automatically.
Vulkan provides following functions for this purpose `vkFlushMappedMemoryRanges()`,
`vkInvalidateMappedMemoryRanges()`, but this library provides more convenient
functions that refer to given allocation object: vmaFlushAllocation(),
@@ -440,7 +447,7 @@ within blocks are aligned to this value, so their offsets are always multiply of
Please note that memory allocated with #VMA_MEMORY_USAGE_CPU_ONLY is guaranteed to be `HOST_COHERENT`.
-Also, Windows drivers from all 3 PC GPU vendors (AMD, Intel, NVIDIA)
+Also, Windows drivers from all 3 **PC** GPU vendors (AMD, Intel, NVIDIA)
currently provide `HOST_COHERENT` flag on all memory types that are
`HOST_VISIBLE`, so on this platform you may not need to bother.
@@ -474,16 +481,16 @@ VkMemoryPropertyFlags memFlags;
vmaGetMemoryTypeProperties(allocator, allocInfo.memoryType, &memFlags);
if((memFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
{
- // Allocation ended up in mappable memory. You can map it and access it directly.
- void* mappedData;
- vmaMapMemory(allocator, alloc, &mappedData);
- memcpy(mappedData, &constantBufferData, sizeof(constantBufferData));
- vmaUnmapMemory(allocator, alloc);
+ // Allocation ended up in mappable memory. You can map it and access it directly.
+ void* mappedData;
+ vmaMapMemory(allocator, alloc, &mappedData);
+ memcpy(mappedData, &constantBufferData, sizeof(constantBufferData));
+ vmaUnmapMemory(allocator, alloc);
}
else
{
- // Allocation ended up in non-mappable memory.
- // You need to create CPU-side buffer in VMA_MEMORY_USAGE_CPU_ONLY and make a transfer.
+ // Allocation ended up in non-mappable memory.
+ // You need to create CPU-side buffer in VMA_MEMORY_USAGE_CPU_ONLY and make a transfer.
}
\endcode
@@ -509,18 +516,90 @@ vmaCreateBuffer(allocator, &bufCreateInfo, &allocCreateInfo, &buf, &alloc, &allo
if(allocInfo.pUserData != nullptr)
{
- // Allocation ended up in mappable memory.
- // It's persistently mapped. You can access it directly.
- memcpy(allocInfo.pMappedData, &constantBufferData, sizeof(constantBufferData));
+ // Allocation ended up in mappable memory.
+ // It's persistently mapped. You can access it directly.
+ memcpy(allocInfo.pMappedData, &constantBufferData, sizeof(constantBufferData));
}
else
{
- // Allocation ended up in non-mappable memory.
- // You need to create CPU-side buffer in VMA_MEMORY_USAGE_CPU_ONLY and make a transfer.
+ // Allocation ended up in non-mappable memory.
+ // You need to create CPU-side buffer in VMA_MEMORY_USAGE_CPU_ONLY and make a transfer.
}
\endcode
+\page staying_within_budget Staying within budget
+
+When developing a graphics-intensive game or program, it is important to avoid allocating
+more GPU memory than it's physically available. When the memory is over-committed,
+various bad things can happen, depending on the specific GPU, graphics driver, and
+operating system:
+
+- It may just work without any problems.
+- The application may slow down because some memory blocks are moved to system RAM
+ and the GPU has to access them through PCI Express bus.
+- A new allocation may take very long time to complete, even few seconds, and possibly
+ freeze entire system.
+- The new allocation may fail with `VK_ERROR_OUT_OF_DEVICE_MEMORY`.
+- It may even result in GPU crash (TDR), observed as `VK_ERROR_DEVICE_LOST`
+ returned somewhere later.
+
+\section staying_within_budget_querying_for_budget Querying for budget
+
+To query for current memory usage and available budget, use function vmaGetBudget().
+Returned structure #VmaBudget contains quantities expressed in bytes, per Vulkan memory heap.
+
+Please note that this function returns different information and works faster than
+vmaCalculateStats(). vmaGetBudget() can be called every frame or even before every
+allocation, while vmaCalculateStats() is intended to be used rarely,
+only to obtain statistical information, e.g. for debugging purposes.
+
+It is recommended to use <b>VK_EXT_memory_budget</b> device extension to obtain information
+about the budget from Vulkan device. VMA is able to use this extension automatically.
+When not enabled, the allocator behaves same way, but then it estimates current usage
+and available budget based on its internal information and Vulkan memory heap sizes,
+which may be less precise. In order to use this extension:
+
+1. Make sure extensions VK_EXT_memory_budget and VK_KHR_get_physical_device_properties2
+ required by it are available and enable them. Please note that the first is a device
+ extension and the second is instance extension!
+2. Use flag #VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT when creating #VmaAllocator object.
+3. Make sure to call vmaSetCurrentFrameIndex() every frame. Budget is queried from
+ Vulkan inside of it to avoid overhead of querying it with every allocation.
+
+\section staying_within_budget_controlling_memory_usage Controlling memory usage
+
+There are many ways in which you can try to stay within the budget.
+
+First, when making new allocation requires allocating a new memory block, the library
+tries not to exceed the budget automatically. If a block with default recommended size
+(e.g. 256 MB) would go over budget, a smaller block is allocated, possibly even
+dedicated memory for just this resource.
+
+If the size of the requested resource plus current memory usage is more than the
+budget, by default the library still tries to create it, leaving it to the Vulkan
+implementation whether the allocation succeeds or fails. You can change this behavior
+by using #VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT flag. With it, the allocation is
+not made if it would exceed the budget or if the budget is already exceeded.
+Some other allocations become lost instead to make room for it, if the mechanism of
+[lost allocations](@ref lost_allocations) is used.
+If that is not possible, the allocation fails with `VK_ERROR_OUT_OF_DEVICE_MEMORY`.
+Example usage pattern may be to pass the #VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT flag
+when creating resources that are not essential for the application (e.g. the texture
+of a specific object) and not to pass it when creating critically important resources
+(e.g. render targets).
+
+Finally, you can also use #VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT flag to make sure
+a new allocation is created only when it fits inside one of the existing memory blocks.
+If it would require to allocate a new block, if fails instead with `VK_ERROR_OUT_OF_DEVICE_MEMORY`.
+This also ensures that the function call is very fast because it never goes to Vulkan
+to obtain a new block.
+
+Please note that creating \ref custom_memory_pools with VmaPoolCreateInfo::minBlockCount
+set to more than 0 will try to allocate memory blocks without checking whether they
+fit within budget.
+
+
\page custom_memory_pools Custom memory pools
A memory pool contains a number of `VkDeviceMemory` blocks.
@@ -744,7 +823,7 @@ allocations.
To mitigate this problem, you can use defragmentation feature:
structure #VmaDefragmentationInfo2, function vmaDefragmentationBegin(), vmaDefragmentationEnd().
-Given set of allocations,
+Given set of allocations,
this function can move them to compact used memory, ensure more continuous free
space and possibly also free some `VkDeviceMemory` blocks.
@@ -761,7 +840,8 @@ What it doesn't do, so you need to do it yourself:
- Recreate buffers and images that were bound to allocations that were defragmented and
bind them with their new places in memory.
You must use `vkDestroyBuffer()`, `vkDestroyImage()`,
- `vkCreateBuffer()`, `vkCreateImage()` for that purpose and NOT vmaDestroyBuffer(),
+ `vkCreateBuffer()`, `vkCreateImage()`, vmaBindBufferMemory(), vmaBindImageMemory()
+ for that purpose and NOT vmaDestroyBuffer(),
vmaDestroyImage(), vmaCreateBuffer(), vmaCreateImage(), because you don't need to
destroy or create allocation objects!
- Recreate views and update descriptors that point to these buffers and images.
@@ -801,22 +881,22 @@ vmaDefragmentationEnd(allocator, defragCtx);
for(uint32_t i = 0; i < allocCount; ++i)
{
- if(allocationsChanged[i])
- {
- // Destroy buffer that is immutably bound to memory region which is no longer valid.
- vkDestroyBuffer(device, buffers[i], nullptr);
-
- // Create new buffer with same parameters.
- VkBufferCreateInfo bufferInfo = ...;
- vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
-
- // You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
+ if(allocationsChanged[i])
+ {
+ // Destroy buffer that is immutably bound to memory region which is no longer valid.
+ vkDestroyBuffer(device, buffers[i], nullptr);
- // Bind new buffer to new memory region. Data contained in it is already moved.
- VmaAllocationInfo allocInfo;
- vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
- vkBindBufferMemory(device, buffers[i], allocInfo.deviceMemory, allocInfo.offset);
- }
+ // Create new buffer with same parameters.
+ VkBufferCreateInfo bufferInfo = ...;
+ vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
+
+ // You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
+
+ // Bind new buffer to new memory region. Data contained in it is already moved.
+ VmaAllocationInfo allocInfo;
+ vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
+ vmaBindBufferMemory(allocator, allocations[i], buffers[i]);
+ }
}
\endcode
@@ -879,22 +959,22 @@ vmaDefragmentationEnd(allocator, defragCtx);
for(uint32_t i = 0; i < allocCount; ++i)
{
- if(allocationsChanged[i])
- {
- // Destroy buffer that is immutably bound to memory region which is no longer valid.
- vkDestroyBuffer(device, buffers[i], nullptr);
-
- // Create new buffer with same parameters.
- VkBufferCreateInfo bufferInfo = ...;
- vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
-
- // You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
+ if(allocationsChanged[i])
+ {
+ // Destroy buffer that is immutably bound to memory region which is no longer valid.
+ vkDestroyBuffer(device, buffers[i], nullptr);
- // Bind new buffer to new memory region. Data contained in it is already moved.
- VmaAllocationInfo allocInfo;
- vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
- vkBindBufferMemory(device, buffers[i], allocInfo.deviceMemory, allocInfo.offset);
- }
+ // Create new buffer with same parameters.
+ VkBufferCreateInfo bufferInfo = ...;
+ vkCreateBuffer(device, &bufferInfo, nullptr, &buffers[i]);
+
+ // You can make dummy call to vkGetBufferMemoryRequirements here to silence validation layer warning.
+
+ // Bind new buffer to new memory region. Data contained in it is already moved.
+ VmaAllocationInfo allocInfo;
+ vmaGetAllocationInfo(allocator, allocations[i], &allocInfo);
+ vmaBindBufferMemory(allocator, allocations[i], buffers[i]);
+ }
}
\endcode
@@ -1008,40 +1088,40 @@ Example code:
\code
struct MyBuffer
{
- VkBuffer m_Buf = nullptr;
- VmaAllocation m_Alloc = nullptr;
+ VkBuffer m_Buf = nullptr;
+ VmaAllocation m_Alloc = nullptr;
- // Called when the buffer is really needed in the current frame.
- void EnsureBuffer();
+ // Called when the buffer is really needed in the current frame.
+ void EnsureBuffer();
};
void MyBuffer::EnsureBuffer()
{
- // Buffer has been created.
- if(m_Buf != VK_NULL_HANDLE)
- {
- // Check if its allocation is not lost + mark it as used in current frame.
- if(vmaTouchAllocation(allocator, m_Alloc))
+ // Buffer has been created.
+ if(m_Buf != VK_NULL_HANDLE)
{
- // It's all OK - safe to use m_Buf.
- return;
+ // Check if its allocation is not lost + mark it as used in current frame.
+ if(vmaTouchAllocation(allocator, m_Alloc))
+ {
+ // It's all OK - safe to use m_Buf.
+ return;
+ }
}
- }
- // Buffer not yet exists or lost - destroy and recreate it.
+ // Buffer not yet exists or lost - destroy and recreate it.
- vmaDestroyBuffer(allocator, m_Buf, m_Alloc);
+ vmaDestroyBuffer(allocator, m_Buf, m_Alloc);
- VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
- bufCreateInfo.size = 1024;
- bufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
+ VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
+ bufCreateInfo.size = 1024;
+ bufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
- VmaAllocationCreateInfo allocCreateInfo = {};
- allocCreateInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
- allocCreateInfo.flags = VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT |
- VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT;
+ VmaAllocationCreateInfo allocCreateInfo = {};
+ allocCreateInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
+ allocCreateInfo.flags = VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT |
+ VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT;
- vmaCreateBuffer(allocator, &bufCreateInfo, &allocCreateInfo, &m_Buf, &m_Alloc, nullptr);
+ vmaCreateBuffer(allocator, &bufCreateInfo, &allocCreateInfo, &m_Buf, &m_Alloc, nullptr);
}
\endcode
@@ -1189,6 +1269,9 @@ printf("Image name: %s\n", imageName);
That string is also printed in JSON report created by vmaBuildStatsString().
+\note Passing string name to VMA allocation doesn't automatically set it to the Vulkan buffer or image created with it.
+You must do it manually using an extension like VK_EXT_debug_utils, which is independent of this library.
+
\page debugging_memory_usage Debugging incorrect memory usage
@@ -1280,7 +1363,7 @@ which indicates a serious bug.
You can also explicitly request checking margins of all allocations in all memory blocks
that belong to specified memory types by using function vmaCheckCorruption(),
-or in memory blocks that belong to specified custom pool, by using function
+or in memory blocks that belong to specified custom pool, by using function
vmaCheckPoolCorruption().
Margin validation (corruption detection) works only for memory types that are
@@ -1304,6 +1387,13 @@ application. It can be useful to:
\section record_and_replay_usage Usage
+Recording functionality is disabled by default.
+To enable it, define following macro before every include of this library:
+
+\code
+#define VMA_RECORDING_ENABLED 1
+\endcode
+
<b>To record sequence of calls to a file:</b> Fill in
VmaAllocatorCreateInfo::pRecordSettings member while creating #VmaAllocator
object. File is opened and written during whole lifetime of the allocator.
@@ -1315,7 +1405,7 @@ Its project is generated by Premake.
Command line syntax is printed when the program is launched without parameters.
Basic usage:
- VmaReplay.exe MyRecording.csv
+ VmaReplay.exe MyRecording.csv
<b>Documentation of file format</b> can be found in file: "docs/Recording file format.md".
It's a human-readable, text file in CSV format (Comma Separated Values).
@@ -1330,7 +1420,6 @@ It's a human-readable, text file in CSV format (Comma Separated Values).
coded and tested only on Windows. Inclusion of recording code is driven by
`VMA_RECORDING_ENABLED` macro. Support for other platforms should be easy to
add. Contributions are welcomed.
-- Currently calls to vmaDefragment() function are not recorded.
\page usage_patterns Recommended usage patterns
@@ -1339,6 +1428,27 @@ See also slides from talk:
[Sawicki, Adam. Advanced Graphics Techniques Tutorial: Memory management in Vulkan and DX12. Game Developers Conference, 2018](https://www.gdcvault.com/play/1025458/Advanced-Graphics-Techniques-Tutorial-New)
+\section usage_patterns_common_mistakes Common mistakes
+
+<b>Use of CPU_TO_GPU instead of CPU_ONLY memory</b>
+
+#VMA_MEMORY_USAGE_CPU_TO_GPU is recommended only for resources that will be
+mapped and written by the CPU, as well as read directly by the GPU - like some
+buffers or textures updated every frame (dynamic). If you create a staging copy
+of a resource to be written by CPU and then used as a source of transfer to
+another resource placed in the GPU memory, that staging resource should be
+created with #VMA_MEMORY_USAGE_CPU_ONLY. Please read the descriptions of these
+enums carefully for details.
+
+<b>Unnecessary use of custom pools</b>
+
+\ref custom_memory_pools may be useful for special purposes - when you want to
+keep certain type of resources separate e.g. to reserve minimum amount of memory
+for them, limit maximum amount of memory they can occupy, or make some of them
+push out the other through the mechanism of \ref lost_allocations. For most
+resources this is not needed and so it is not recommended to create #VmaPool
+objects and allocations out of them. Allocating from the default pool is sufficient.
+
\section usage_patterns_simple Simple patterns
\subsection usage_patterns_simple_render_targets Render targets
@@ -1472,6 +1582,11 @@ mutex, atomic etc.
The library uses its own implementation of containers by default, but you can switch to using
STL containers instead.
+For example, define `VMA_ASSERT(expr)` before including the library to provide
+custom implementation of the assertion, compatible with your project.
+By default it is defined to standard C `assert(expr)` in `_DEBUG` configuration
+and empty otherwise.
+
\section config_Vulkan_functions Pointers to Vulkan functions
The library uses Vulkan functions straight from the `vulkan.h` header by default.
@@ -1505,7 +1620,7 @@ behavior is implementation-dependant - it depends on GPU vendor and graphics
driver.
On AMD cards it can be controlled while creating Vulkan device object by using
-VK_AMD_memory_allocation_behavior extension, if available.
+VK_AMD_memory_overallocation_behavior extension, if available.
Alternatively, if you want to test how your program behaves with limited amount of Vulkan device
memory available without switching your graphics card to one that really has
@@ -1550,7 +1665,7 @@ buffer using vmaCreateBuffer() or image using vmaCreateImage().
When using the extension together with Vulkan Validation Layer, you will receive
warnings like this:
- vkBindBufferMemory(): Binding memory to buffer 0x33 but vkGetBufferMemoryRequirements() has not been called on that buffer.
+ vkBindBufferMemory(): Binding memory to buffer 0x33 but vkGetBufferMemoryRequirements() has not been called on that buffer.
It is OK, you should just ignore it. It happens because you use function
`vkGetBufferMemoryRequirements2KHR()` instead of standard
@@ -1559,11 +1674,68 @@ unaware of it.
To learn more about this extension, see:
-- [VK_KHR_dedicated_allocation in Vulkan specification](https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VK_KHR_dedicated_allocation)
+- [VK_KHR_dedicated_allocation in Vulkan specification](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap44.html#VK_KHR_dedicated_allocation)
- [VK_KHR_dedicated_allocation unofficial manual](http://asawicki.info/articles/VK_KHR_dedicated_allocation.php5)
+\page vk_amd_device_coherent_memory VK_AMD_device_coherent_memory
+
+VK_AMD_device_coherent_memory is a device extension that enables access to
+additional memory types with `VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD` and
+`VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD` flag. It is useful mostly for
+allocation of buffers intended for writing "breadcrumb markers" in between passes
+or draw calls, which in turn are useful for debugging GPU crash/hang/TDR cases.
+
+When the extension is available but has not been enabled, Vulkan physical device
+still exposes those memory types, but their usage is forbidden. VMA automatically
+takes care of that - it returns `VK_ERROR_FEATURE_NOT_PRESENT` when an attempt
+to allocate memory of such type is made.
+
+If you want to use this extension in connection with VMA, follow these steps:
+
+\section vk_amd_device_coherent_memory_initialization Initialization
+
+1) Call `vkEnumerateDeviceExtensionProperties` for the physical device.
+Check if the extension is supported - if returned array of `VkExtensionProperties` contains "VK_AMD_device_coherent_memory".
+
+2) Call `vkGetPhysicalDeviceFeatures2` for the physical device instead of old `vkGetPhysicalDeviceFeatures`.
+Attach additional structure `VkPhysicalDeviceCoherentMemoryFeaturesAMD` to `VkPhysicalDeviceFeatures2::pNext` to be returned.
+Check if the device feature is really supported - check if `VkPhysicalDeviceCoherentMemoryFeaturesAMD::deviceCoherentMemory` is true.
+
+3) While creating device with `vkCreateDevice`, enable this extension - add "VK_AMD_device_coherent_memory"
+to the list passed as `VkDeviceCreateInfo::ppEnabledExtensionNames`.
+
+4) While creating the device, also don't set `VkDeviceCreateInfo::pEnabledFeatures`.
+Fill in `VkPhysicalDeviceFeatures2` structure instead and pass it as `VkDeviceCreateInfo::pNext`.
+Enable this device feature - attach additional structure `VkPhysicalDeviceCoherentMemoryFeaturesAMD` to
+`VkPhysicalDeviceFeatures2::pNext` and set its member `deviceCoherentMemory` to `VK_TRUE`.
+
+5) While creating #VmaAllocator with vmaCreateAllocator() inform VMA that you
+have enabled this extension and feature - add #VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT
+to VmaAllocatorCreateInfo::flags.
+
+\section vk_amd_device_coherent_memory_usage Usage
+
+After following steps described above, you can create VMA allocations and custom pools
+out of the special `DEVICE_COHERENT` and `DEVICE_UNCACHED` memory types on eligible
+devices. There are multiple ways to do it, for example:
+
+- You can request or prefer to allocate out of such memory types by adding
+ `VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD` to VmaAllocationCreateInfo::requiredFlags
+ or VmaAllocationCreateInfo::preferredFlags. Those flags can be freely mixed with
+ other ways of \ref choosing_memory_type, like setting VmaAllocationCreateInfo::usage.
+- If you manually found memory type index to use for this purpose, force allocation
+ from this specific index by setting VmaAllocationCreateInfo::memoryTypeBits `= 1u << index`.
+
+\section vk_amd_device_coherent_memory_more_information More information
+
+To learn more about this extension, see [VK_AMD_device_coherent_memory in Vulkan specification](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap44.html#VK_AMD_device_coherent_memory)
+
+Example use of this extension can be found in the code of the sample and test suite
+accompanying this library.
+
+
\page general_considerations General considerations
\section general_considerations_thread_safety Thread safety
@@ -1590,14 +1762,14 @@ to just ignore them.
- *vkBindBufferMemory(): Binding memory to buffer 0xeb8e4 but vkGetBufferMemoryRequirements() has not been called on that buffer.*
- It happens when VK_KHR_dedicated_allocation extension is enabled.
- `vkGetBufferMemoryRequirements2KHR` function is used instead, while validation layer seems to be unaware of it.
+ `vkGetBufferMemoryRequirements2KHR` function is used instead, while validation layer seems to be unaware of it.
- *Mapping an image with layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL can result in undefined behavior if this memory is used by the device. Only GENERAL or PREINITIALIZED should be used.*
- It happens when you map a buffer or image, because the library maps entire
- `VkDeviceMemory` block, where different types of images and buffers may end
- up together, especially on GPUs with unified memory like Intel.
+ `VkDeviceMemory` block, where different types of images and buffers may end
+ up together, especially on GPUs with unified memory like Intel.
- *Non-linear image 0xebc91 is aliased with linear buffer 0xeb8e4 which may indicate a bug.*
- It happens when you use lost allocations, and a new image or buffer is
- created in place of an existing object that bacame lost.
+ created in place of an existing object that bacame lost.
- It may happen also when you use [defragmentation](@ref defragmentation).
\section general_considerations_allocation_algorithm Allocation algorithm
@@ -1639,7 +1811,7 @@ Features deliberately excluded from the scope of this library:
and handled gracefully, because that would complicate code significantly and
is usually not needed in desktop PC applications anyway.
- Code free of any compiler warnings. Maintaining the library to compile and
- work correctly on so many different platforms is hard enough. Being free of
+ work correctly on so many different platforms is hard enough. Being free of
any warnings, on any version of any compiler, is simply not feasible.
- This is a C++ library with C interface.
Bindings or ports to any other programming languages are welcomed as external projects and
@@ -1652,31 +1824,66 @@ Define this macro to 0/1 to disable/enable support for recording functionality,
available through VmaAllocatorCreateInfo::pRecordSettings.
*/
#ifndef VMA_RECORDING_ENABLED
-#ifdef _WIN32
-#define VMA_RECORDING_ENABLED 1
-#else
-#define VMA_RECORDING_ENABLED 0
-#endif
+ #define VMA_RECORDING_ENABLED 0
#endif
#ifndef NOMINMAX
-#define NOMINMAX // For windows.h
+ #define NOMINMAX // For windows.h
#endif
#ifndef VULKAN_H_
-#include <vulkan/vulkan.h>
+ #include <vulkan/vulkan.h>
#endif
#if VMA_RECORDING_ENABLED
-#include <windows.h>
+ #include <windows.h>
+#endif
+
+// Define this macro to declare maximum supported Vulkan version in format AAABBBCCC,
+// where AAA = major, BBB = minor, CCC = patch.
+// If you want to use version > 1.0, it still needs to be enabled via VmaAllocatorCreateInfo::vulkanApiVersion.
+#if !defined(VMA_VULKAN_VERSION)
+ #if defined(VK_VERSION_1_1)
+ #define VMA_VULKAN_VERSION 1001000
+ #else
+ #define VMA_VULKAN_VERSION 1000000
+ #endif
#endif
#if !defined(VMA_DEDICATED_ALLOCATION)
-#if VK_KHR_get_memory_requirements2 && VK_KHR_dedicated_allocation
-#define VMA_DEDICATED_ALLOCATION 1
-#else
-#define VMA_DEDICATED_ALLOCATION 0
+ #if VK_KHR_get_memory_requirements2 && VK_KHR_dedicated_allocation
+ #define VMA_DEDICATED_ALLOCATION 1
+ #else
+ #define VMA_DEDICATED_ALLOCATION 0
+ #endif
+#endif
+
+#if !defined(VMA_BIND_MEMORY2)
+ #if VK_KHR_bind_memory2
+ #define VMA_BIND_MEMORY2 1
+ #else
+ #define VMA_BIND_MEMORY2 0
+ #endif
+#endif
+
+#if !defined(VMA_MEMORY_BUDGET)
+ #if VK_EXT_memory_budget && (VK_KHR_get_physical_device_properties2 || VMA_VULKAN_VERSION >= 1001000)
+ #define VMA_MEMORY_BUDGET 1
+ #else
+ #define VMA_MEMORY_BUDGET 0
+ #endif
+#endif
+
+// Define these macros to decorate all public functions with additional code,
+// before and after returned type, appropriately. This may be useful for
+// exporing the functions when compiling VMA as a separate library. Example:
+// #define VMA_CALL_PRE __declspec(dllexport)
+// #define VMA_CALL_POST __cdecl
+#ifndef VMA_CALL_PRE
+ #define VMA_CALL_PRE
#endif
+#ifndef VMA_CALL_POST
+ #define VMA_CALL_POST
#endif
/** \struct VmaAllocator
@@ -1691,17 +1898,17 @@ right after Vulkan is initialized and keep it alive until before Vulkan device i
VK_DEFINE_HANDLE(VmaAllocator)
/// Callback function called after successful vkAllocateMemory.
-typedef void(VKAPI_PTR *PFN_vmaAllocateDeviceMemoryFunction)(
- VmaAllocator allocator,
- uint32_t memoryType,
- VkDeviceMemory memory,
- VkDeviceSize size);
+typedef void (VKAPI_PTR *PFN_vmaAllocateDeviceMemoryFunction)(
+ VmaAllocator allocator,
+ uint32_t memoryType,
+ VkDeviceMemory memory,
+ VkDeviceSize size);
/// Callback function called before vkFreeMemory.
-typedef void(VKAPI_PTR *PFN_vmaFreeDeviceMemoryFunction)(
- VmaAllocator allocator,
- uint32_t memoryType,
- VkDeviceMemory memory,
- VkDeviceSize size);
+typedef void (VKAPI_PTR *PFN_vmaFreeDeviceMemoryFunction)(
+ VmaAllocator allocator,
+ uint32_t memoryType,
+ VkDeviceMemory memory,
+ VkDeviceSize size);
/** \brief Set of callbacks that the library will call for `vkAllocateMemory` and `vkFreeMemory`.
@@ -1721,31 +1928,79 @@ typedef struct VmaDeviceMemoryCallbacks {
typedef enum VmaAllocatorCreateFlagBits {
/** \brief Allocator and all objects created from it will not be synchronized internally, so you must guarantee they are used from only one thread at a time or synchronized externally by you.
- Using this flag may increase performance because internal mutexes are not used.
- */
+ Using this flag may increase performance because internal mutexes are not used.
+ */
VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT = 0x00000001,
/** \brief Enables usage of VK_KHR_dedicated_allocation extension.
- Using this extenion will automatically allocate dedicated blocks of memory for
- some buffers and images instead of suballocating place for them out of bigger
- memory blocks (as if you explicitly used #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
- flag) when it is recommended by the driver. It may improve performance on some
- GPUs.
+ The flag works only if VmaAllocatorCreateInfo::vulkanApiVersion `== VK_API_VERSION_1_0`.
+ When it's `VK_API_VERSION_1_1`, the flag is ignored because the extension has been promoted to Vulkan 1.1.
- You may set this flag only if you found out that following device extensions are
- supported, you enabled them while creating Vulkan device passed as
- VmaAllocatorCreateInfo::device, and you want them to be used internally by this
- library:
+ Using this extenion will automatically allocate dedicated blocks of memory for
+ some buffers and images instead of suballocating place for them out of bigger
+ memory blocks (as if you explicitly used #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
+ flag) when it is recommended by the driver. It may improve performance on some
+ GPUs.
- - VK_KHR_get_memory_requirements2
- - VK_KHR_dedicated_allocation
+ You may set this flag only if you found out that following device extensions are
+ supported, you enabled them while creating Vulkan device passed as
+ VmaAllocatorCreateInfo::device, and you want them to be used internally by this
+ library:
-When this flag is set, you can experience following warnings reported by Vulkan
-validation layer. You can ignore them.
+ - VK_KHR_get_memory_requirements2 (device extension)
+ - VK_KHR_dedicated_allocation (device extension)
-> vkBindBufferMemory(): Binding memory to buffer 0x2d but vkGetBufferMemoryRequirements() has not been called on that buffer.
- */
+ When this flag is set, you can experience following warnings reported by Vulkan
+ validation layer. You can ignore them.
+
+ > vkBindBufferMemory(): Binding memory to buffer 0x2d but vkGetBufferMemoryRequirements() has not been called on that buffer.
+ */
VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT = 0x00000002,
+ /**
+ Enables usage of VK_KHR_bind_memory2 extension.
+
+ The flag works only if VmaAllocatorCreateInfo::vulkanApiVersion `== VK_API_VERSION_1_0`.
+ When it's `VK_API_VERSION_1_1`, the flag is ignored because the extension has been promoted to Vulkan 1.1.
+
+ You may set this flag only if you found out that this device extension is supported,
+ you enabled it while creating Vulkan device passed as VmaAllocatorCreateInfo::device,
+ and you want it to be used internally by this library.
+
+ The extension provides functions `vkBindBufferMemory2KHR` and `vkBindImageMemory2KHR`,
+ which allow to pass a chain of `pNext` structures while binding.
+ This flag is required if you use `pNext` parameter in vmaBindBufferMemory2() or vmaBindImageMemory2().
+ */
+ VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT = 0x00000004,
+ /**
+ Enables usage of VK_EXT_memory_budget extension.
+
+ You may set this flag only if you found out that this device extension is supported,
+ you enabled it while creating Vulkan device passed as VmaAllocatorCreateInfo::device,
+ and you want it to be used internally by this library, along with another instance extension
+ VK_KHR_get_physical_device_properties2, which is required by it (or Vulkan 1.1, where this extension is promoted).
+
+ The extension provides query for current memory usage and budget, which will probably
+ be more accurate than an estimation used by the library otherwise.
+ */
+ VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT = 0x00000008,
+ /**
+ Enabled usage of VK_AMD_device_coherent_memory extension.
+
+ You may set this flag only if you:
+
+ - found out that this device extension is supported and enabled it while creating Vulkan device passed as VmaAllocatorCreateInfo::device,
+ - checked that `VkPhysicalDeviceCoherentMemoryFeaturesAMD::deviceCoherentMemory` is true and set it while creating the Vulkan device,
+ - want it to be used internally by this library.
+
+ The extension and accompanying device feature provide access to memory types with
+ `VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD` and `VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD` flags.
+ They are useful mostly for writing breadcrumb markers - a common method for debugging GPU crash/hang/TDR.
+
+ When the extension is not enabled, such memory types are still enumerated, but their usage is illegal.
+ To protect from this error, if you don't create the allocator with this flag, it will refuse to allocate any memory or create a custom pool in such memory type,
+ returning `VK_ERROR_FEATURE_NOT_PRESENT`.
+ */
+ VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT = 0x00000010,
VMA_ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VmaAllocatorCreateFlagBits;
@@ -1773,41 +2028,50 @@ typedef struct VmaVulkanFunctions {
PFN_vkCreateImage vkCreateImage;
PFN_vkDestroyImage vkDestroyImage;
PFN_vkCmdCopyBuffer vkCmdCopyBuffer;
-#if VMA_DEDICATED_ALLOCATION
+#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
PFN_vkGetBufferMemoryRequirements2KHR vkGetBufferMemoryRequirements2KHR;
PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2KHR;
#endif
+#if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000
+ PFN_vkBindBufferMemory2KHR vkBindBufferMemory2KHR;
+ PFN_vkBindImageMemory2KHR vkBindImageMemory2KHR;
+#endif
+#if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000
+ PFN_vkGetPhysicalDeviceMemoryProperties2KHR vkGetPhysicalDeviceMemoryProperties2KHR;
+#endif
} VmaVulkanFunctions;
/// Flags to be used in VmaRecordSettings::flags.
typedef enum VmaRecordFlagBits {
/** \brief Enables flush after recording every function call.
- Enable it if you expect your application to crash, which may leave recording file truncated.
- It may degrade performance though.
- */
+ Enable it if you expect your application to crash, which may leave recording file truncated.
+ It may degrade performance though.
+ */
VMA_RECORD_FLUSH_AFTER_CALL_BIT = 0x00000001,
-
+
VMA_RECORD_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VmaRecordFlagBits;
typedef VkFlags VmaRecordFlags;
/// Parameters for recording calls to VMA functions. To be used in VmaAllocatorCreateInfo::pRecordSettings.
-typedef struct VmaRecordSettings {
+typedef struct VmaRecordSettings
+{
/// Flags for recording. Use #VmaRecordFlagBits enum.
VmaRecordFlags flags;
/** \brief Path to the file that should be written by the recording.
- Suggested extension: "csv".
- If the file already exists, it will be overwritten.
- It will be opened for the whole time #VmaAllocator object is alive.
- If opening this file fails, creation of the whole allocator object fails.
- */
- const char *pFilePath;
+ Suggested extension: "csv".
+ If the file already exists, it will be overwritten.
+ It will be opened for the whole time #VmaAllocator object is alive.
+ If opening this file fails, creation of the whole allocator object fails.
+ */
+ const char* pFilePath;
} VmaRecordSettings;
/// Description of a Allocator to be created.
-typedef struct VmaAllocatorCreateInfo {
+typedef struct VmaAllocatorCreateInfo
+{
/// Flags for created allocator. Use #VmaAllocatorCreateFlagBits enum.
VmaAllocatorCreateFlags flags;
/// Vulkan physical device.
@@ -1821,94 +2085,109 @@ typedef struct VmaAllocatorCreateInfo {
VkDeviceSize preferredLargeHeapBlockSize;
/// Custom CPU memory allocation callbacks. Optional.
/** Optional, can be null. When specified, will also be used for all CPU-side memory allocations. */
- const VkAllocationCallbacks *pAllocationCallbacks;
+ const VkAllocationCallbacks* pAllocationCallbacks;
/// Informative callbacks for `vkAllocateMemory`, `vkFreeMemory`. Optional.
/** Optional, can be null. */
- const VmaDeviceMemoryCallbacks *pDeviceMemoryCallbacks;
+ const VmaDeviceMemoryCallbacks* pDeviceMemoryCallbacks;
/** \brief Maximum number of additional frames that are in use at the same time as current frame.
- This value is used only when you make allocations with
- VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag. Such allocation cannot become
- lost if allocation.lastUseFrameIndex >= allocator.currentFrameIndex - frameInUseCount.
+ This value is used only when you make allocations with
+ VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag. Such allocation cannot become
+ lost if allocation.lastUseFrameIndex >= allocator.currentFrameIndex - frameInUseCount.
- For example, if you double-buffer your command buffers, so resources used for
- rendering in previous frame may still be in use by the GPU at the moment you
- allocate resources needed for the current frame, set this value to 1.
+ For example, if you double-buffer your command buffers, so resources used for
+ rendering in previous frame may still be in use by the GPU at the moment you
+ allocate resources needed for the current frame, set this value to 1.
- If you want to allow any allocations other than used in the current frame to
- become lost, set this value to 0.
- */
+ If you want to allow any allocations other than used in the current frame to
+ become lost, set this value to 0.
+ */
uint32_t frameInUseCount;
/** \brief Either null or a pointer to an array of limits on maximum number of bytes that can be allocated out of particular Vulkan memory heap.
- If not NULL, it must be a pointer to an array of
- `VkPhysicalDeviceMemoryProperties::memoryHeapCount` elements, defining limit on
- maximum number of bytes that can be allocated out of particular Vulkan memory
- heap.
-
- Any of the elements may be equal to `VK_WHOLE_SIZE`, which means no limit on that
- heap. This is also the default in case of `pHeapSizeLimit` = NULL.
-
- If there is a limit defined for a heap:
-
- - If user tries to allocate more memory from that heap using this allocator,
- the allocation fails with `VK_ERROR_OUT_OF_DEVICE_MEMORY`.
- - If the limit is smaller than heap size reported in `VkMemoryHeap::size`, the
- value of this limit will be reported instead when using vmaGetMemoryProperties().
-
- Warning! Using this feature may not be equivalent to installing a GPU with
- smaller amount of memory, because graphics driver doesn't necessary fail new
- allocations with `VK_ERROR_OUT_OF_DEVICE_MEMORY` result when memory capacity is
- exceeded. It may return success and just silently migrate some device memory
- blocks to system RAM. This driver behavior can also be controlled using
- VK_AMD_memory_overallocation_behavior extension.
- */
- const VkDeviceSize *pHeapSizeLimit;
+ If not NULL, it must be a pointer to an array of
+ `VkPhysicalDeviceMemoryProperties::memoryHeapCount` elements, defining limit on
+ maximum number of bytes that can be allocated out of particular Vulkan memory
+ heap.
+
+ Any of the elements may be equal to `VK_WHOLE_SIZE`, which means no limit on that
+ heap. This is also the default in case of `pHeapSizeLimit` = NULL.
+
+ If there is a limit defined for a heap:
+
+ - If user tries to allocate more memory from that heap using this allocator,
+ the allocation fails with `VK_ERROR_OUT_OF_DEVICE_MEMORY`.
+ - If the limit is smaller than heap size reported in `VkMemoryHeap::size`, the
+ value of this limit will be reported instead when using vmaGetMemoryProperties().
+
+ Warning! Using this feature may not be equivalent to installing a GPU with
+ smaller amount of memory, because graphics driver doesn't necessary fail new
+ allocations with `VK_ERROR_OUT_OF_DEVICE_MEMORY` result when memory capacity is
+ exceeded. It may return success and just silently migrate some device memory
+ blocks to system RAM. This driver behavior can also be controlled using
+ VK_AMD_memory_overallocation_behavior extension.
+ */
+ const VkDeviceSize* pHeapSizeLimit;
/** \brief Pointers to Vulkan functions. Can be null if you leave define `VMA_STATIC_VULKAN_FUNCTIONS 1`.
- If you leave define `VMA_STATIC_VULKAN_FUNCTIONS 1` in configuration section,
- you can pass null as this member, because the library will fetch pointers to
- Vulkan functions internally in a static way, like:
+ If you leave define `VMA_STATIC_VULKAN_FUNCTIONS 1` in configuration section,
+ you can pass null as this member, because the library will fetch pointers to
+ Vulkan functions internally in a static way, like:
- vulkanFunctions.vkAllocateMemory = &vkAllocateMemory;
+ vulkanFunctions.vkAllocateMemory = &vkAllocateMemory;
- Fill this member if you want to provide your own pointers to Vulkan functions,
- e.g. fetched using `vkGetInstanceProcAddr()` and `vkGetDeviceProcAddr()`.
- */
- const VmaVulkanFunctions *pVulkanFunctions;
+ Fill this member if you want to provide your own pointers to Vulkan functions,
+ e.g. fetched using `vkGetInstanceProcAddr()` and `vkGetDeviceProcAddr()`.
+ */
+ const VmaVulkanFunctions* pVulkanFunctions;
/** \brief Parameters for recording of VMA calls. Can be null.
- If not null, it enables recording of calls to VMA functions to a file.
- If support for recording is not enabled using `VMA_RECORDING_ENABLED` macro,
- creation of the allocator object fails with `VK_ERROR_FEATURE_NOT_PRESENT`.
- */
- const VmaRecordSettings *pRecordSettings;
+ If not null, it enables recording of calls to VMA functions to a file.
+ If support for recording is not enabled using `VMA_RECORDING_ENABLED` macro,
+ creation of the allocator object fails with `VK_ERROR_FEATURE_NOT_PRESENT`.
+ */
+ const VmaRecordSettings* pRecordSettings;
+ /** \brief Optional handle to Vulkan instance object.
+
+ Optional, can be null. Must be set if #VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT flas is used
+ or if `vulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)`.
+ */
+ VkInstance instance;
+ /** \brief Optional. The highest version of Vulkan that the application is designed to use.
+
+ It must be a value in the format as created by macro `VK_MAKE_VERSION` or a constant like: `VK_API_VERSION_1_1`, `VK_API_VERSION_1_0`.
+ The patch version number specified is ignored. Only the major and minor versions are considered.
+ It must be less or euqal (preferably equal) to value as passed to `vkCreateInstance` as `VkApplicationInfo::apiVersion`.
+ Only versions 1.0 and 1.1 are supported by the current implementation.
+ Leaving it initialized to zero is equivalent to `VK_API_VERSION_1_0`.
+ */
+ uint32_t vulkanApiVersion;
} VmaAllocatorCreateInfo;
/// Creates Allocator object.
-VkResult vmaCreateAllocator(
- const VmaAllocatorCreateInfo *pCreateInfo,
- VmaAllocator *pAllocator);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAllocator(
+ const VmaAllocatorCreateInfo* pCreateInfo,
+ VmaAllocator* pAllocator);
/// Destroys allocator object.
-void vmaDestroyAllocator(
- VmaAllocator allocator);
+VMA_CALL_PRE void VMA_CALL_POST vmaDestroyAllocator(
+ VmaAllocator allocator);
/**
PhysicalDeviceProperties are fetched from physicalDevice by the allocator.
You can access it here, without fetching it again on your own.
*/
-void vmaGetPhysicalDeviceProperties(
- VmaAllocator allocator,
- const VkPhysicalDeviceProperties **ppPhysicalDeviceProperties);
+VMA_CALL_PRE void VMA_CALL_POST vmaGetPhysicalDeviceProperties(
+ VmaAllocator allocator,
+ const VkPhysicalDeviceProperties** ppPhysicalDeviceProperties);
/**
PhysicalDeviceMemoryProperties are fetched from physicalDevice by the allocator.
You can access it here, without fetching it again on your own.
*/
-void vmaGetMemoryProperties(
- VmaAllocator allocator,
- const VkPhysicalDeviceMemoryProperties **ppPhysicalDeviceMemoryProperties);
+VMA_CALL_PRE void VMA_CALL_POST vmaGetMemoryProperties(
+ VmaAllocator allocator,
+ const VkPhysicalDeviceMemoryProperties** ppPhysicalDeviceMemoryProperties);
/**
\brief Given Memory Type Index, returns Property Flags of this memory type.
@@ -1916,10 +2195,10 @@ void vmaGetMemoryProperties(
This is just a convenience function. Same information can be obtained using
vmaGetMemoryProperties().
*/
-void vmaGetMemoryTypeProperties(
- VmaAllocator allocator,
- uint32_t memoryTypeIndex,
- VkMemoryPropertyFlags *pFlags);
+VMA_CALL_PRE void VMA_CALL_POST vmaGetMemoryTypeProperties(
+ VmaAllocator allocator,
+ uint32_t memoryTypeIndex,
+ VkMemoryPropertyFlags* pFlags);
/** \brief Sets index of the current frame.
@@ -1929,13 +2208,14 @@ This function must be used if you make allocations with
when a new frame begins. Allocations queried using vmaGetAllocationInfo() cannot
become lost in the current frame.
*/
-void vmaSetCurrentFrameIndex(
- VmaAllocator allocator,
- uint32_t frameIndex);
+VMA_CALL_PRE void VMA_CALL_POST vmaSetCurrentFrameIndex(
+ VmaAllocator allocator,
+ uint32_t frameIndex);
/** \brief Calculated statistics of memory usage in entire allocator.
*/
-typedef struct VmaStatInfo {
+typedef struct VmaStatInfo
+{
/// Number of `VkDeviceMemory` Vulkan memory blocks allocated.
uint32_t blockCount;
/// Number of #VmaAllocation allocation objects allocated.
@@ -1951,16 +2231,80 @@ typedef struct VmaStatInfo {
} VmaStatInfo;
/// General statistics from current state of Allocator.
-typedef struct VmaStats {
+typedef struct VmaStats
+{
VmaStatInfo memoryType[VK_MAX_MEMORY_TYPES];
VmaStatInfo memoryHeap[VK_MAX_MEMORY_HEAPS];
VmaStatInfo total;
} VmaStats;
-/// Retrieves statistics from current state of the Allocator.
-void vmaCalculateStats(
- VmaAllocator allocator,
- VmaStats *pStats);
+/** \brief Retrieves statistics from current state of the Allocator.
+
+This function is called "calculate" not "get" because it has to traverse all
+internal data structures, so it may be quite slow. For faster but more brief statistics
+suitable to be called every frame or every allocation, use vmaGetBudget().
+
+Note that when using allocator from multiple threads, returned information may immediately
+become outdated.
+*/
+VMA_CALL_PRE void VMA_CALL_POST vmaCalculateStats(
+ VmaAllocator allocator,
+ VmaStats* pStats);
+
+/** \brief Statistics of current memory usage and available budget, in bytes, for specific memory heap.
+*/
+typedef struct VmaBudget
+{
+ /** \brief Sum size of all `VkDeviceMemory` blocks allocated from particular heap, in bytes.
+ */
+ VkDeviceSize blockBytes;
+
+ /** \brief Sum size of all allocations created in particular heap, in bytes.
+
+ Usually less or equal than `blockBytes`.
+ Difference `blockBytes - allocationBytes` is the amount of memory allocated but unused -
+ available for new allocations or wasted due to fragmentation.
+
+ It might be greater than `blockBytes` if there are some allocations in lost state, as they account
+ to this value as well.
+ */
+ VkDeviceSize allocationBytes;
+
+ /** \brief Estimated current memory usage of the program, in bytes.
+
+ Fetched from system using `VK_EXT_memory_budget` extension if enabled.
+
+ It might be different than `blockBytes` (usually higher) due to additional implicit objects
+ also occupying the memory, like swapchain, pipelines, descriptor heaps, command buffers, or
+ `VkDeviceMemory` blocks allocated outside of this library, if any.
+ */
+ VkDeviceSize usage;
+
+ /** \brief Estimated amount of memory available to the program, in bytes.
+
+ Fetched from system using `VK_EXT_memory_budget` extension if enabled.
+
+ It might be different (most probably smaller) than `VkMemoryHeap::size[heapIndex]` due to factors
+ external to the program, like other programs also consuming system resources.
+ Difference `budget - usage` is the amount of additional memory that can probably
+ be allocated without problems. Exceeding the budget may result in various problems.
+ */
+ VkDeviceSize budget;
+} VmaBudget;
+
+/** \brief Retrieves information about current memory budget for all memory heaps.
+
+\param[out] pBudget Must point to array with number of elements at least equal to number of memory heaps in physical device used.
+
+This function is called "get" not "calculate" because it is very fast, suitable to be called
+every frame or every allocation. For more detailed statistics use vmaCalculateStats().
+
+Note that when using allocator from multiple threads, returned information may immediately
+become outdated.
+*/
+VMA_CALL_PRE void VMA_CALL_POST vmaGetBudget(
+ VmaAllocator allocator,
+ VmaBudget* pBudget);
#ifndef VMA_STATS_STRING_ENABLED
#define VMA_STATS_STRING_ENABLED 1
@@ -1971,14 +2315,14 @@ void vmaCalculateStats(
/// Builds and returns statistics as string in JSON format.
/** @param[out] ppStatsString Must be freed using vmaFreeStatsString() function.
*/
-void vmaBuildStatsString(
- VmaAllocator allocator,
- char **ppStatsString,
- VkBool32 detailedMap);
+VMA_CALL_PRE void VMA_CALL_POST vmaBuildStatsString(
+ VmaAllocator allocator,
+ char** ppStatsString,
+ VkBool32 detailedMap);
-void vmaFreeStatsString(
- VmaAllocator allocator,
- char *pStatsString);
+VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString(
+ VmaAllocator allocator,
+ char* pStatsString);
#endif // #if VMA_STATS_STRING_ENABLED
@@ -1992,205 +2336,226 @@ For more information see [Custom memory pools](@ref choosing_memory_type_custom_
*/
VK_DEFINE_HANDLE(VmaPool)
-typedef enum VmaMemoryUsage {
+typedef enum VmaMemoryUsage
+{
/** No intended memory usage specified.
- Use other members of VmaAllocationCreateInfo to specify your requirements.
- */
+ Use other members of VmaAllocationCreateInfo to specify your requirements.
+ */
VMA_MEMORY_USAGE_UNKNOWN = 0,
/** Memory will be used on device only, so fast access from the device is preferred.
- It usually means device-local GPU (video) memory.
- No need to be mappable on host.
- It is roughly equivalent of `D3D12_HEAP_TYPE_DEFAULT`.
-
- Usage:
-
- - Resources written and read by device, e.g. images used as attachments.
- - Resources transferred from host once (immutable) or infrequently and read by
- device multiple times, e.g. textures to be sampled, vertex buffers, uniform
- (constant) buffers, and majority of other types of resources used on GPU.
-
- Allocation may still end up in `HOST_VISIBLE` memory on some implementations.
- In such case, you are free to map it.
- You can use #VMA_ALLOCATION_CREATE_MAPPED_BIT with this usage type.
- */
+ It usually means device-local GPU (video) memory.
+ No need to be mappable on host.
+ It is roughly equivalent of `D3D12_HEAP_TYPE_DEFAULT`.
+
+ Usage:
+
+ - Resources written and read by device, e.g. images used as attachments.
+ - Resources transferred from host once (immutable) or infrequently and read by
+ device multiple times, e.g. textures to be sampled, vertex buffers, uniform
+ (constant) buffers, and majority of other types of resources used on GPU.
+
+ Allocation may still end up in `HOST_VISIBLE` memory on some implementations.
+ In such case, you are free to map it.
+ You can use #VMA_ALLOCATION_CREATE_MAPPED_BIT with this usage type.
+ */
VMA_MEMORY_USAGE_GPU_ONLY = 1,
/** Memory will be mappable on host.
- It usually means CPU (system) memory.
- Guarantees to be `HOST_VISIBLE` and `HOST_COHERENT`.
- CPU access is typically uncached. Writes may be write-combined.
- Resources created in this pool may still be accessible to the device, but access to them can be slow.
- It is roughly equivalent of `D3D12_HEAP_TYPE_UPLOAD`.
-
- Usage: Staging copy of resources used as transfer source.
- */
+ It usually means CPU (system) memory.
+ Guarantees to be `HOST_VISIBLE` and `HOST_COHERENT`.
+ CPU access is typically uncached. Writes may be write-combined.
+ Resources created in this pool may still be accessible to the device, but access to them can be slow.
+ It is roughly equivalent of `D3D12_HEAP_TYPE_UPLOAD`.
+
+ Usage: Staging copy of resources used as transfer source.
+ */
VMA_MEMORY_USAGE_CPU_ONLY = 2,
/**
- Memory that is both mappable on host (guarantees to be `HOST_VISIBLE`) and preferably fast to access by GPU.
- CPU access is typically uncached. Writes may be write-combined.
+ Memory that is both mappable on host (guarantees to be `HOST_VISIBLE`) and preferably fast to access by GPU.
+ CPU access is typically uncached. Writes may be write-combined.
- Usage: Resources written frequently by host (dynamic), read by device. E.g. textures, vertex buffers, uniform buffers updated every frame or every draw call.
- */
+ Usage: Resources written frequently by host (dynamic), read by device. E.g. textures, vertex buffers, uniform buffers updated every frame or every draw call.
+ */
VMA_MEMORY_USAGE_CPU_TO_GPU = 3,
/** Memory mappable on host (guarantees to be `HOST_VISIBLE`) and cached.
- It is roughly equivalent of `D3D12_HEAP_TYPE_READBACK`.
+ It is roughly equivalent of `D3D12_HEAP_TYPE_READBACK`.
- Usage:
+ Usage:
- - Resources written by device, read by host - results of some computations, e.g. screen capture, average scene luminance for HDR tone mapping.
- - Any resources read or accessed randomly on host, e.g. CPU-side copy of vertex buffer used as source of transfer, but also used for collision detection.
- */
+ - Resources written by device, read by host - results of some computations, e.g. screen capture, average scene luminance for HDR tone mapping.
+ - Any resources read or accessed randomly on host, e.g. CPU-side copy of vertex buffer used as source of transfer, but also used for collision detection.
+ */
VMA_MEMORY_USAGE_GPU_TO_CPU = 4,
+ /** CPU memory - memory that is preferably not `DEVICE_LOCAL`, but also not guaranteed to be `HOST_VISIBLE`.
+
+ Usage: Staging copy of resources moved from GPU memory to CPU memory as part
+ of custom paging/residency mechanism, to be moved back to GPU memory when needed.
+ */
+ VMA_MEMORY_USAGE_CPU_COPY = 5,
+ /** Lazily allocated GPU memory having `VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT`.
+ Exists mostly on mobile platforms. Using it on desktop PC or other GPUs with no such memory type present will fail the allocation.
+
+ Usage: Memory for transient attachment images (color attachments, depth attachments etc.), created with `VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT`.
+
+ Allocations with this usage are always created as dedicated - it implies #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
+ */
+ VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED = 6,
+
VMA_MEMORY_USAGE_MAX_ENUM = 0x7FFFFFFF
} VmaMemoryUsage;
/// Flags to be passed as VmaAllocationCreateInfo::flags.
typedef enum VmaAllocationCreateFlagBits {
/** \brief Set this flag if the allocation should have its own memory block.
-
- Use it for special, big resources, like fullscreen images used as attachments.
-
- You should not use this flag if VmaAllocationCreateInfo::pool is not null.
- */
+
+ Use it for special, big resources, like fullscreen images used as attachments.
+
+ You should not use this flag if VmaAllocationCreateInfo::pool is not null.
+ */
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT = 0x00000001,
/** \brief Set this flag to only try to allocate from existing `VkDeviceMemory` blocks and never create new such block.
-
- If new allocation cannot be placed in any of the existing blocks, allocation
- fails with `VK_ERROR_OUT_OF_DEVICE_MEMORY` error.
-
- You should not use #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT and
- #VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT at the same time. It makes no sense.
-
- If VmaAllocationCreateInfo::pool is not null, this flag is implied and ignored. */
+
+ If new allocation cannot be placed in any of the existing blocks, allocation
+ fails with `VK_ERROR_OUT_OF_DEVICE_MEMORY` error.
+
+ You should not use #VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT and
+ #VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT at the same time. It makes no sense.
+
+ If VmaAllocationCreateInfo::pool is not null, this flag is implied and ignored. */
VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT = 0x00000002,
/** \brief Set this flag to use a memory that will be persistently mapped and retrieve pointer to it.
+
+ Pointer to mapped memory will be returned through VmaAllocationInfo::pMappedData.
- Pointer to mapped memory will be returned through VmaAllocationInfo::pMappedData.
-
- Is it valid to use this flag for allocation made from memory type that is not
- `HOST_VISIBLE`. This flag is then ignored and memory is not mapped. This is
- useful if you need an allocation that is efficient to use on GPU
- (`DEVICE_LOCAL`) and still want to map it directly if possible on platforms that
- support it (e.g. Intel GPU).
+ Is it valid to use this flag for allocation made from memory type that is not
+ `HOST_VISIBLE`. This flag is then ignored and memory is not mapped. This is
+ useful if you need an allocation that is efficient to use on GPU
+ (`DEVICE_LOCAL`) and still want to map it directly if possible on platforms that
+ support it (e.g. Intel GPU).
- You should not use this flag together with #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT.
- */
+ You should not use this flag together with #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT.
+ */
VMA_ALLOCATION_CREATE_MAPPED_BIT = 0x00000004,
/** Allocation created with this flag can become lost as a result of another
- allocation with #VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT flag, so you
- must check it before use.
+ allocation with #VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT flag, so you
+ must check it before use.
- To check if allocation is not lost, call vmaGetAllocationInfo() and check if
- VmaAllocationInfo::deviceMemory is not `VK_NULL_HANDLE`.
+ To check if allocation is not lost, call vmaGetAllocationInfo() and check if
+ VmaAllocationInfo::deviceMemory is not `VK_NULL_HANDLE`.
- For details about supporting lost allocations, see Lost Allocations
- chapter of User Guide on Main Page.
+ For details about supporting lost allocations, see Lost Allocations
+ chapter of User Guide on Main Page.
- You should not use this flag together with #VMA_ALLOCATION_CREATE_MAPPED_BIT.
- */
+ You should not use this flag together with #VMA_ALLOCATION_CREATE_MAPPED_BIT.
+ */
VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT = 0x00000008,
/** While creating allocation using this flag, other allocations that were
- created with flag #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT can become lost.
+ created with flag #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT can become lost.
- For details about supporting lost allocations, see Lost Allocations
- chapter of User Guide on Main Page.
- */
+ For details about supporting lost allocations, see Lost Allocations
+ chapter of User Guide on Main Page.
+ */
VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT = 0x00000010,
/** Set this flag to treat VmaAllocationCreateInfo::pUserData as pointer to a
- null-terminated string. Instead of copying pointer value, a local copy of the
- string is made and stored in allocation's `pUserData`. The string is automatically
- freed together with the allocation. It is also used in vmaBuildStatsString().
- */
+ null-terminated string. Instead of copying pointer value, a local copy of the
+ string is made and stored in allocation's `pUserData`. The string is automatically
+ freed together with the allocation. It is also used in vmaBuildStatsString().
+ */
VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT = 0x00000020,
/** Allocation will be created from upper stack in a double stack pool.
- This flag is only allowed for custom pools created with #VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT flag.
- */
+ This flag is only allowed for custom pools created with #VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT flag.
+ */
VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT = 0x00000040,
/** Create both buffer/image and allocation, but don't bind them together.
- It is useful when you want to bind yourself to do some more advanced binding, e.g. using some extensions.
- The flag is meaningful only with functions that bind by default: vmaCreateBuffer(), vmaCreateImage().
- Otherwise it is ignored.
- */
+ It is useful when you want to bind yourself to do some more advanced binding, e.g. using some extensions.
+ The flag is meaningful only with functions that bind by default: vmaCreateBuffer(), vmaCreateImage().
+ Otherwise it is ignored.
+ */
VMA_ALLOCATION_CREATE_DONT_BIND_BIT = 0x00000080,
+ /** Create allocation only if additional device memory required for it, if any, won't exceed
+ memory budget. Otherwise return `VK_ERROR_OUT_OF_DEVICE_MEMORY`.
+ */
+ VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT = 0x00000100,
/** Allocation strategy that chooses smallest possible free range for the
- allocation.
- */
- VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT = 0x00010000,
+ allocation.
+ */
+ VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT = 0x00010000,
/** Allocation strategy that chooses biggest possible free range for the
- allocation.
- */
+ allocation.
+ */
VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT = 0x00020000,
/** Allocation strategy that chooses first suitable free range for the
- allocation.
+ allocation.
- "First" doesn't necessarily means the one with smallest offset in memory,
- but rather the one that is easiest and fastest to find.
- */
+ "First" doesn't necessarily means the one with smallest offset in memory,
+ but rather the one that is easiest and fastest to find.
+ */
VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT = 0x00040000,
/** Allocation strategy that tries to minimize memory usage.
- */
+ */
VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT = VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT,
/** Allocation strategy that tries to minimize allocation time.
- */
+ */
VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT = VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT,
/** Allocation strategy that tries to minimize memory fragmentation.
- */
+ */
VMA_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT = VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT,
/** A bit mask to extract only `STRATEGY` bits from entire set of flags.
- */
+ */
VMA_ALLOCATION_CREATE_STRATEGY_MASK =
- VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT |
- VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT |
- VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT,
+ VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT |
+ VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT |
+ VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT,
VMA_ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VmaAllocationCreateFlagBits;
typedef VkFlags VmaAllocationCreateFlags;
-typedef struct VmaAllocationCreateInfo {
+typedef struct VmaAllocationCreateInfo
+{
/// Use #VmaAllocationCreateFlagBits enum.
VmaAllocationCreateFlags flags;
/** \brief Intended usage of memory.
-
- You can leave #VMA_MEMORY_USAGE_UNKNOWN if you specify memory requirements in other way. \n
- If `pool` is not null, this member is ignored.
- */
+
+ You can leave #VMA_MEMORY_USAGE_UNKNOWN if you specify memory requirements in other way. \n
+ If `pool` is not null, this member is ignored.
+ */
VmaMemoryUsage usage;
/** \brief Flags that must be set in a Memory Type chosen for an allocation.
-
- Leave 0 if you specify memory requirements in other way. \n
- If `pool` is not null, this member is ignored.*/
+
+ Leave 0 if you specify memory requirements in other way. \n
+ If `pool` is not null, this member is ignored.*/
VkMemoryPropertyFlags requiredFlags;
/** \brief Flags that preferably should be set in a memory type chosen for an allocation.
-
- Set to 0 if no additional flags are prefered. \n
- If `pool` is not null, this member is ignored. */
+
+ Set to 0 if no additional flags are prefered. \n
+ If `pool` is not null, this member is ignored. */
VkMemoryPropertyFlags preferredFlags;
/** \brief Bitmask containing one bit set for every memory type acceptable for this allocation.
- Value 0 is equivalent to `UINT32_MAX` - it means any memory type is accepted if
- it meets other requirements specified by this structure, with no further
- restrictions on memory type index. \n
- If `pool` is not null, this member is ignored.
- */
+ Value 0 is equivalent to `UINT32_MAX` - it means any memory type is accepted if
+ it meets other requirements specified by this structure, with no further
+ restrictions on memory type index. \n
+ If `pool` is not null, this member is ignored.
+ */
uint32_t memoryTypeBits;
/** \brief Pool that this allocation should be created in.
- Leave `VK_NULL_HANDLE` to allocate from default pool. If not null, members:
- `usage`, `requiredFlags`, `preferredFlags`, `memoryTypeBits` are ignored.
- */
+ Leave `VK_NULL_HANDLE` to allocate from default pool. If not null, members:
+ `usage`, `requiredFlags`, `preferredFlags`, `memoryTypeBits` are ignored.
+ */
VmaPool pool;
/** \brief Custom general-purpose pointer that will be stored in #VmaAllocation, can be read as VmaAllocationInfo::pUserData and changed using vmaSetAllocationUserData().
-
- If #VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT is used, it must be either
- null or pointer to a null-terminated string. The string will be then copied to
- internal buffer, so it doesn't need to be valid after allocation call.
- */
- void *pUserData;
+
+ If #VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT is used, it must be either
+ null or pointer to a null-terminated string. The string will be then copied to
+ internal buffer, so it doesn't need to be valid after allocation call.
+ */
+ void* pUserData;
} VmaAllocationCreateInfo;
/**
@@ -2209,11 +2574,11 @@ device doesn't support any memory type with requested features for the specific
type of resource you want to use it for. Please check parameters of your
resource, like image layout (OPTIMAL versus LINEAR) or mip level count.
*/
-VkResult vmaFindMemoryTypeIndex(
- VmaAllocator allocator,
- uint32_t memoryTypeBits,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- uint32_t *pMemoryTypeIndex);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndex(
+ VmaAllocator allocator,
+ uint32_t memoryTypeBits,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ uint32_t* pMemoryTypeIndex);
/**
\brief Helps to find memoryTypeIndex, given VkBufferCreateInfo and VmaAllocationCreateInfo.
@@ -2227,11 +2592,11 @@ It is just a convenience function, equivalent to calling:
- `vmaFindMemoryTypeIndex`
- `vkDestroyBuffer`
*/
-VkResult vmaFindMemoryTypeIndexForBufferInfo(
- VmaAllocator allocator,
- const VkBufferCreateInfo *pBufferCreateInfo,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- uint32_t *pMemoryTypeIndex);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForBufferInfo(
+ VmaAllocator allocator,
+ const VkBufferCreateInfo* pBufferCreateInfo,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ uint32_t* pMemoryTypeIndex);
/**
\brief Helps to find memoryTypeIndex, given VkImageCreateInfo and VmaAllocationCreateInfo.
@@ -2245,66 +2610,66 @@ It is just a convenience function, equivalent to calling:
- `vmaFindMemoryTypeIndex`
- `vkDestroyImage`
*/
-VkResult vmaFindMemoryTypeIndexForImageInfo(
- VmaAllocator allocator,
- const VkImageCreateInfo *pImageCreateInfo,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- uint32_t *pMemoryTypeIndex);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForImageInfo(
+ VmaAllocator allocator,
+ const VkImageCreateInfo* pImageCreateInfo,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ uint32_t* pMemoryTypeIndex);
/// Flags to be passed as VmaPoolCreateInfo::flags.
typedef enum VmaPoolCreateFlagBits {
/** \brief Use this flag if you always allocate only buffers and linear images or only optimal images out of this pool and so Buffer-Image Granularity can be ignored.
- This is an optional optimization flag.
-
- If you always allocate using vmaCreateBuffer(), vmaCreateImage(),
- vmaAllocateMemoryForBuffer(), then you don't need to use it because allocator
- knows exact type of your allocations so it can handle Buffer-Image Granularity
- in the optimal way.
-
- If you also allocate using vmaAllocateMemoryForImage() or vmaAllocateMemory(),
- exact type of such allocations is not known, so allocator must be conservative
- in handling Buffer-Image Granularity, which can lead to suboptimal allocation
- (wasted memory). In that case, if you can make sure you always allocate only
- buffers and linear images or only optimal images out of this pool, use this flag
- to make allocator disregard Buffer-Image Granularity and so make allocations
- faster and more optimal.
- */
+ This is an optional optimization flag.
+
+ If you always allocate using vmaCreateBuffer(), vmaCreateImage(),
+ vmaAllocateMemoryForBuffer(), then you don't need to use it because allocator
+ knows exact type of your allocations so it can handle Buffer-Image Granularity
+ in the optimal way.
+
+ If you also allocate using vmaAllocateMemoryForImage() or vmaAllocateMemory(),
+ exact type of such allocations is not known, so allocator must be conservative
+ in handling Buffer-Image Granularity, which can lead to suboptimal allocation
+ (wasted memory). In that case, if you can make sure you always allocate only
+ buffers and linear images or only optimal images out of this pool, use this flag
+ to make allocator disregard Buffer-Image Granularity and so make allocations
+ faster and more optimal.
+ */
VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT = 0x00000002,
/** \brief Enables alternative, linear allocation algorithm in this pool.
- Specify this flag to enable linear allocation algorithm, which always creates
- new allocations after last one and doesn't reuse space from allocations freed in
- between. It trades memory consumption for simplified algorithm and data
- structure, which has better performance and uses less memory for metadata.
+ Specify this flag to enable linear allocation algorithm, which always creates
+ new allocations after last one and doesn't reuse space from allocations freed in
+ between. It trades memory consumption for simplified algorithm and data
+ structure, which has better performance and uses less memory for metadata.
- By using this flag, you can achieve behavior of free-at-once, stack,
- ring buffer, and double stack. For details, see documentation chapter
- \ref linear_algorithm.
+ By using this flag, you can achieve behavior of free-at-once, stack,
+ ring buffer, and double stack. For details, see documentation chapter
+ \ref linear_algorithm.
- When using this flag, you must specify VmaPoolCreateInfo::maxBlockCount == 1 (or 0 for default).
+ When using this flag, you must specify VmaPoolCreateInfo::maxBlockCount == 1 (or 0 for default).
- For more details, see [Linear allocation algorithm](@ref linear_algorithm).
- */
+ For more details, see [Linear allocation algorithm](@ref linear_algorithm).
+ */
VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT = 0x00000004,
/** \brief Enables alternative, buddy allocation algorithm in this pool.
- It operates on a tree of blocks, each having size that is a power of two and
- a half of its parent's size. Comparing to default algorithm, this one provides
- faster allocation and deallocation and decreased external fragmentation,
- at the expense of more memory wasted (internal fragmentation).
+ It operates on a tree of blocks, each having size that is a power of two and
+ a half of its parent's size. Comparing to default algorithm, this one provides
+ faster allocation and deallocation and decreased external fragmentation,
+ at the expense of more memory wasted (internal fragmentation).
- For more details, see [Buddy allocation algorithm](@ref buddy_algorithm).
- */
+ For more details, see [Buddy allocation algorithm](@ref buddy_algorithm).
+ */
VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT = 0x00000008,
/** Bit mask to extract only `ALGORITHM` bits from entire set of flags.
- */
+ */
VMA_POOL_CREATE_ALGORITHM_MASK =
- VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT |
- VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT,
+ VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT |
+ VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT,
VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VmaPoolCreateFlagBits;
@@ -2314,46 +2679,46 @@ typedef VkFlags VmaPoolCreateFlags;
*/
typedef struct VmaPoolCreateInfo {
/** \brief Vulkan memory type index to allocate this pool from.
- */
+ */
uint32_t memoryTypeIndex;
/** \brief Use combination of #VmaPoolCreateFlagBits.
- */
+ */
VmaPoolCreateFlags flags;
/** \brief Size of a single `VkDeviceMemory` block to be allocated as part of this pool, in bytes. Optional.
- Specify nonzero to set explicit, constant size of memory blocks used by this
- pool.
+ Specify nonzero to set explicit, constant size of memory blocks used by this
+ pool.
- Leave 0 to use default and let the library manage block sizes automatically.
- Sizes of particular blocks may vary.
- */
+ Leave 0 to use default and let the library manage block sizes automatically.
+ Sizes of particular blocks may vary.
+ */
VkDeviceSize blockSize;
/** \brief Minimum number of blocks to be always allocated in this pool, even if they stay empty.
- Set to 0 to have no preallocated blocks and allow the pool be completely empty.
- */
+ Set to 0 to have no preallocated blocks and allow the pool be completely empty.
+ */
size_t minBlockCount;
/** \brief Maximum number of blocks that can be allocated in this pool. Optional.
- Set to 0 to use default, which is `SIZE_MAX`, which means no limit.
-
- Set to same value as VmaPoolCreateInfo::minBlockCount to have fixed amount of memory allocated
- throughout whole lifetime of this pool.
- */
+ Set to 0 to use default, which is `SIZE_MAX`, which means no limit.
+
+ Set to same value as VmaPoolCreateInfo::minBlockCount to have fixed amount of memory allocated
+ throughout whole lifetime of this pool.
+ */
size_t maxBlockCount;
/** \brief Maximum number of additional frames that are in use at the same time as current frame.
- This value is used only when you make allocations with
- #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag. Such allocation cannot become
- lost if allocation.lastUseFrameIndex >= allocator.currentFrameIndex - frameInUseCount.
+ This value is used only when you make allocations with
+ #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag. Such allocation cannot become
+ lost if allocation.lastUseFrameIndex >= allocator.currentFrameIndex - frameInUseCount.
- For example, if you double-buffer your command buffers, so resources used for
- rendering in previous frame may still be in use by the GPU at the moment you
- allocate resources needed for the current frame, set this value to 1.
+ For example, if you double-buffer your command buffers, so resources used for
+ rendering in previous frame may still be in use by the GPU at the moment you
+ allocate resources needed for the current frame, set this value to 1.
- If you want to allow any allocations other than used in the current frame to
- become lost, set this value to 0.
- */
+ If you want to allow any allocations other than used in the current frame to
+ become lost, set this value to 0.
+ */
uint32_t frameInUseCount;
} VmaPoolCreateInfo;
@@ -2361,26 +2726,26 @@ typedef struct VmaPoolCreateInfo {
*/
typedef struct VmaPoolStats {
/** \brief Total amount of `VkDeviceMemory` allocated from Vulkan for this pool, in bytes.
- */
+ */
VkDeviceSize size;
/** \brief Total number of bytes in the pool not used by any #VmaAllocation.
- */
+ */
VkDeviceSize unusedSize;
/** \brief Number of #VmaAllocation objects created from this pool that were not destroyed or lost.
- */
+ */
size_t allocationCount;
/** \brief Number of continuous memory ranges in the pool not used by any #VmaAllocation.
- */
+ */
size_t unusedRangeCount;
/** \brief Size of the largest continuous free memory region available for new allocation.
- Making a new allocation of that size is not guaranteed to succeed because of
- possible additional margin required to respect alignment and buffer/image
- granularity.
- */
+ Making a new allocation of that size is not guaranteed to succeed because of
+ possible additional margin required to respect alignment and buffer/image
+ granularity.
+ */
VkDeviceSize unusedRangeSizeMax;
/** \brief Number of `VkDeviceMemory` blocks allocated for this pool.
- */
+ */
size_t blockCount;
} VmaPoolStats;
@@ -2390,16 +2755,16 @@ typedef struct VmaPoolStats {
@param pCreateInfo Parameters of pool to create.
@param[out] pPool Handle to created pool.
*/
-VkResult vmaCreatePool(
- VmaAllocator allocator,
- const VmaPoolCreateInfo *pCreateInfo,
- VmaPool *pPool);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreatePool(
+ VmaAllocator allocator,
+ const VmaPoolCreateInfo* pCreateInfo,
+ VmaPool* pPool);
/** \brief Destroys #VmaPool object and frees Vulkan device memory.
*/
-void vmaDestroyPool(
- VmaAllocator allocator,
- VmaPool pool);
+VMA_CALL_PRE void VMA_CALL_POST vmaDestroyPool(
+ VmaAllocator allocator,
+ VmaPool pool);
/** \brief Retrieves statistics of existing #VmaPool object.
@@ -2407,10 +2772,10 @@ void vmaDestroyPool(
@param pool Pool object.
@param[out] pPoolStats Statistics of specified pool.
*/
-void vmaGetPoolStats(
- VmaAllocator allocator,
- VmaPool pool,
- VmaPoolStats *pPoolStats);
+VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolStats(
+ VmaAllocator allocator,
+ VmaPool pool,
+ VmaPoolStats* pPoolStats);
/** \brief Marks all allocations in given pool as lost if they are not used in current frame or VmaPoolCreateInfo::frameInUseCount back from now.
@@ -2418,10 +2783,10 @@ void vmaGetPoolStats(
@param pool Pool.
@param[out] pLostAllocationCount Number of allocations marked as lost. Optional - pass null if you don't need this information.
*/
-void vmaMakePoolAllocationsLost(
- VmaAllocator allocator,
- VmaPool pool,
- size_t *pLostAllocationCount);
+VMA_CALL_PRE void VMA_CALL_POST vmaMakePoolAllocationsLost(
+ VmaAllocator allocator,
+ VmaPool pool,
+ size_t* pLostAllocationCount);
/** \brief Checks magic number in margins around all allocations in given memory pool in search for corruptions.
@@ -2437,7 +2802,28 @@ Possible return values:
`VMA_ASSERT` is also fired in that case.
- Other value: Error returned by Vulkan, e.g. memory mapping failure.
*/
-VkResult vmaCheckPoolCorruption(VmaAllocator allocator, VmaPool pool);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckPoolCorruption(VmaAllocator allocator, VmaPool pool);
+
+/** \brief Retrieves name of a custom pool.
+
+After the call `ppName` is either null or points to an internally-owned null-terminated string
+containing name of the pool that was previously set. The pointer becomes invalid when the pool is
+destroyed or its name is changed using vmaSetPoolName().
+*/
+VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName(
+ VmaAllocator allocator,
+ VmaPool pool,
+ const char** ppName);
+
+/** \brief Sets name of a custom pool.
+
+`pName` can be either null or pointer to a null-terminated string with new name for the pool.
+Function makes internal copy of the string, so it can be changed or freed immediately after this call.
+*/
+VMA_CALL_PRE void VMA_CALL_POST vmaSetPoolName(
+ VmaAllocator allocator,
+ VmaPool pool,
+ const char* pName);
/** \struct VmaAllocation
\brief Represents single memory allocation.
@@ -2469,43 +2855,43 @@ VK_DEFINE_HANDLE(VmaAllocation)
*/
typedef struct VmaAllocationInfo {
/** \brief Memory type index that this allocation was allocated from.
-
- It never changes.
- */
+
+ It never changes.
+ */
uint32_t memoryType;
/** \brief Handle to Vulkan memory object.
- Same memory object can be shared by multiple allocations.
-
- It can change after call to vmaDefragment() if this allocation is passed to the function, or if allocation is lost.
+ Same memory object can be shared by multiple allocations.
+
+ It can change after call to vmaDefragment() if this allocation is passed to the function, or if allocation is lost.
- If the allocation is lost, it is equal to `VK_NULL_HANDLE`.
- */
+ If the allocation is lost, it is equal to `VK_NULL_HANDLE`.
+ */
VkDeviceMemory deviceMemory;
/** \brief Offset into deviceMemory object to the beginning of this allocation, in bytes. (deviceMemory, offset) pair is unique to this allocation.
- It can change after call to vmaDefragment() if this allocation is passed to the function, or if allocation is lost.
- */
+ It can change after call to vmaDefragment() if this allocation is passed to the function, or if allocation is lost.
+ */
VkDeviceSize offset;
/** \brief Size of this allocation, in bytes.
- It never changes, unless allocation is lost.
- */
+ It never changes, unless allocation is lost.
+ */
VkDeviceSize size;
/** \brief Pointer to the beginning of this allocation as mapped data.
- If the allocation hasn't been mapped using vmaMapMemory() and hasn't been
- created with #VMA_ALLOCATION_CREATE_MAPPED_BIT flag, this value null.
+ If the allocation hasn't been mapped using vmaMapMemory() and hasn't been
+ created with #VMA_ALLOCATION_CREATE_MAPPED_BIT flag, this value null.
- It can change after call to vmaMapMemory(), vmaUnmapMemory().
- It can also change after call to vmaDefragment() if this allocation is passed to the function.
- */
- void *pMappedData;
+ It can change after call to vmaMapMemory(), vmaUnmapMemory().
+ It can also change after call to vmaDefragment() if this allocation is passed to the function.
+ */
+ void* pMappedData;
/** \brief Custom general-purpose pointer that was passed as VmaAllocationCreateInfo::pUserData or set using vmaSetAllocationUserData().
- It can change after call to vmaSetAllocationUserData() for this allocation.
- */
- void *pUserData;
+ It can change after call to vmaSetAllocationUserData() for this allocation.
+ */
+ void* pUserData;
} VmaAllocationInfo;
/** \brief General purpose memory allocation.
@@ -2518,12 +2904,12 @@ You should free the memory using vmaFreeMemory() or vmaFreeMemoryPages().
It is recommended to use vmaAllocateMemoryForBuffer(), vmaAllocateMemoryForImage(),
vmaCreateBuffer(), vmaCreateImage() instead whenever possible.
*/
-VkResult vmaAllocateMemory(
- VmaAllocator allocator,
- const VkMemoryRequirements *pVkMemoryRequirements,
- const VmaAllocationCreateInfo *pCreateInfo,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory(
+ VmaAllocator allocator,
+ const VkMemoryRequirements* pVkMemoryRequirements,
+ const VmaAllocationCreateInfo* pCreateInfo,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo);
/** \brief General purpose memory allocation for multiple allocation objects at once.
@@ -2544,13 +2930,13 @@ All allocations are made using same parameters. All of them are created out of t
If any allocation fails, all allocations already made within this function call are also freed, so that when
returned result is not `VK_SUCCESS`, `pAllocation` array is always entirely filled with `VK_NULL_HANDLE`.
*/
-VkResult vmaAllocateMemoryPages(
- VmaAllocator allocator,
- const VkMemoryRequirements *pVkMemoryRequirements,
- const VmaAllocationCreateInfo *pCreateInfo,
- size_t allocationCount,
- VmaAllocation *pAllocations,
- VmaAllocationInfo *pAllocationInfo);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryPages(
+ VmaAllocator allocator,
+ const VkMemoryRequirements* pVkMemoryRequirements,
+ const VmaAllocationCreateInfo* pCreateInfo,
+ size_t allocationCount,
+ VmaAllocation* pAllocations,
+ VmaAllocationInfo* pAllocationInfo);
/**
@param[out] pAllocation Handle to allocated memory.
@@ -2558,28 +2944,28 @@ VkResult vmaAllocateMemoryPages(
You should free the memory using vmaFreeMemory().
*/
-VkResult vmaAllocateMemoryForBuffer(
- VmaAllocator allocator,
- VkBuffer buffer,
- const VmaAllocationCreateInfo *pCreateInfo,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryForBuffer(
+ VmaAllocator allocator,
+ VkBuffer buffer,
+ const VmaAllocationCreateInfo* pCreateInfo,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo);
/// Function similar to vmaAllocateMemoryForBuffer().
-VkResult vmaAllocateMemoryForImage(
- VmaAllocator allocator,
- VkImage image,
- const VmaAllocationCreateInfo *pCreateInfo,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryForImage(
+ VmaAllocator allocator,
+ VkImage image,
+ const VmaAllocationCreateInfo* pCreateInfo,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo);
/** \brief Frees memory previously allocated using vmaAllocateMemory(), vmaAllocateMemoryForBuffer(), or vmaAllocateMemoryForImage().
Passing `VK_NULL_HANDLE` as `allocation` is valid. Such function call is just skipped.
*/
-void vmaFreeMemory(
- VmaAllocator allocator,
- VmaAllocation allocation);
+VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation);
/** \brief Frees memory and destroys multiple allocations.
@@ -2591,35 +2977,22 @@ It may be internally optimized to be more efficient than calling vmaFreeMemory()
Allocations in `pAllocations` array can come from any memory pools and types.
Passing `VK_NULL_HANDLE` as elements of `pAllocations` array is valid. Such entries are just skipped.
*/
-void vmaFreeMemoryPages(
- VmaAllocator allocator,
- size_t allocationCount,
- VmaAllocation *pAllocations);
-
-/** \brief Tries to resize an allocation in place, if there is enough free memory after it.
+VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemoryPages(
+ VmaAllocator allocator,
+ size_t allocationCount,
+ VmaAllocation* pAllocations);
-Tries to change allocation's size without moving or reallocating it.
-You can both shrink and grow allocation size.
-When growing, it succeeds only when the allocation belongs to a memory block with enough
-free space after it.
+/** \brief Deprecated.
-Returns `VK_SUCCESS` if allocation's size has been successfully changed.
-Returns `VK_ERROR_OUT_OF_POOL_MEMORY` if allocation's size could not be changed.
-
-After successful call to this function, VmaAllocationInfo::size of this allocation changes.
-All other parameters stay the same: memory pool and type, alignment, offset, mapped pointer.
-
-- Calling this function on allocation that is in lost state fails with result `VK_ERROR_VALIDATION_FAILED_EXT`.
-- Calling this function with `newSize` same as current allocation size does nothing and returns `VK_SUCCESS`.
-- Resizing dedicated allocations, as well as allocations created in pools that use linear
- or buddy algorithm, is not supported.
- The function returns `VK_ERROR_FEATURE_NOT_PRESENT` in such cases.
- Support may be added in the future.
+\deprecated
+In version 2.2.0 it used to try to change allocation's size without moving or reallocating it.
+In current version it returns `VK_SUCCESS` only if `newSize` equals current allocation's size.
+Otherwise returns `VK_ERROR_OUT_OF_POOL_MEMORY`, indicating that allocation's size could not be changed.
*/
-VkResult vmaResizeAllocation(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VkDeviceSize newSize);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaResizeAllocation(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkDeviceSize newSize);
/** \brief Returns current information about specified allocation and atomically marks it as used in current frame.
@@ -2637,10 +3010,10 @@ you can avoid calling it too often.
(e.g. due to defragmentation or allocation becoming lost).
- If you just want to check if allocation is not lost, vmaTouchAllocation() will work faster.
*/
-void vmaGetAllocationInfo(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VmaAllocationInfo *pAllocationInfo);
+VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationInfo(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VmaAllocationInfo* pAllocationInfo);
/** \brief Returns `VK_TRUE` if allocation is not lost and atomically marks it as used in current frame.
@@ -2656,9 +3029,9 @@ Lost allocation and the buffer/image still need to be destroyed.
If the allocation has been created without #VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag,
this function always returns `VK_TRUE`.
*/
-VkBool32 vmaTouchAllocation(
- VmaAllocator allocator,
- VmaAllocation allocation);
+VMA_CALL_PRE VkBool32 VMA_CALL_POST vmaTouchAllocation(
+ VmaAllocator allocator,
+ VmaAllocation allocation);
/** \brief Sets pUserData in given allocation to new value.
@@ -2673,10 +3046,10 @@ If the flag was not used, the value of pointer `pUserData` is just copied to
allocation's `pUserData`. It is opaque, so you can use it however you want - e.g.
as a pointer, ordinal number or some handle to you own data.
*/
-void vmaSetAllocationUserData(
- VmaAllocator allocator,
- VmaAllocation allocation,
- void *pUserData);
+VMA_CALL_PRE void VMA_CALL_POST vmaSetAllocationUserData(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ void* pUserData);
/** \brief Creates new allocation that is in lost state from the beginning.
@@ -2688,9 +3061,9 @@ Returned allocation is not tied to any specific memory pool or memory type and
not bound to any image or buffer. It has size = 0. It cannot be turned into
a real, non-empty allocation.
*/
-void vmaCreateLostAllocation(
- VmaAllocator allocator,
- VmaAllocation *pAllocation);
+VMA_CALL_PRE void VMA_CALL_POST vmaCreateLostAllocation(
+ VmaAllocator allocator,
+ VmaAllocation* pAllocation);
/** \brief Maps memory represented by given allocation and returns pointer to it.
@@ -2725,23 +3098,33 @@ This function fails when used on allocation made in memory type that is not
This function always fails when called for allocation that was created with
#VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag. Such allocations cannot be
mapped.
+
+This function doesn't automatically flush or invalidate caches.
+If the allocation is made from a memory types that is not `HOST_COHERENT`,
+you also need to use vmaInvalidateAllocation() / vmaFlushAllocation(), as required by Vulkan specification.
*/
-VkResult vmaMapMemory(
- VmaAllocator allocator,
- VmaAllocation allocation,
- void **ppData);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaMapMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ void** ppData);
/** \brief Unmaps memory represented by given allocation, mapped previously using vmaMapMemory().
For details, see description of vmaMapMemory().
+
+This function doesn't automatically flush or invalidate caches.
+If the allocation is made from a memory types that is not `HOST_COHERENT`,
+you also need to use vmaInvalidateAllocation() / vmaFlushAllocation(), as required by Vulkan specification.
*/
-void vmaUnmapMemory(
- VmaAllocator allocator,
- VmaAllocation allocation);
+VMA_CALL_PRE void VMA_CALL_POST vmaUnmapMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation);
/** \brief Flushes memory of given allocation.
Calls `vkFlushMappedMemoryRanges()` for memory associated with given range of given allocation.
+It needs to be called after writing to a mapped memory for memory types that are not `HOST_COHERENT`.
+Unmap operation doesn't do that automatically.
- `offset` must be relative to the beginning of allocation.
- `size` can be `VK_WHOLE_SIZE`. It means all memory from `offset` the the end of given allocation.
@@ -2755,11 +3138,13 @@ Warning! `offset` and `size` are relative to the contents of given `allocation`.
If you mean whole allocation, you can pass 0 and `VK_WHOLE_SIZE`, respectively.
Do not pass allocation's offset as `offset`!!!
*/
-void vmaFlushAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size);
+VMA_CALL_PRE void VMA_CALL_POST vmaFlushAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size);
/** \brief Invalidates memory of given allocation.
Calls `vkInvalidateMappedMemoryRanges()` for memory associated with given range of given allocation.
+It needs to be called before reading from a mapped memory for memory types that are not `HOST_COHERENT`.
+Map operation doesn't do that automatically.
- `offset` must be relative to the beginning of allocation.
- `size` can be `VK_WHOLE_SIZE`. It means all memory from `offset` the the end of given allocation.
@@ -2773,7 +3158,7 @@ Warning! `offset` and `size` are relative to the contents of given `allocation`.
If you mean whole allocation, you can pass 0 and `VK_WHOLE_SIZE`, respectively.
Do not pass allocation's offset as `offset`!!!
*/
-void vmaInvalidateAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size);
+VMA_CALL_PRE void VMA_CALL_POST vmaInvalidateAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size);
/** \brief Checks magic number in margins around all allocations in given memory types (in both default and custom pools) in search for corruptions.
@@ -2791,7 +3176,7 @@ Possible return values:
`VMA_ASSERT` is also fired in that case.
- Other value: Error returned by Vulkan, e.g. memory mapping failure.
*/
-VkResult vmaCheckCorruption(VmaAllocator allocator, uint32_t memoryTypeBits);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckCorruption(VmaAllocator allocator, uint32_t memoryTypeBits);
/** \struct VmaDefragmentationContext
\brief Represents Opaque object that represents started defragmentation process.
@@ -2803,6 +3188,7 @@ VK_DEFINE_HANDLE(VmaDefragmentationContext)
/// Flags to be used in vmaDefragmentationBegin(). None at the moment. Reserved for future use.
typedef enum VmaDefragmentationFlagBits {
+ VMA_DEFRAGMENTATION_FLAG_INCREMENTAL = 0x1,
VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VmaDefragmentationFlagBits;
typedef VkFlags VmaDefragmentationFlags;
@@ -2813,90 +3199,105 @@ To be used with function vmaDefragmentationBegin().
*/
typedef struct VmaDefragmentationInfo2 {
/** \brief Reserved for future use. Should be 0.
- */
+ */
VmaDefragmentationFlags flags;
/** \brief Number of allocations in `pAllocations` array.
- */
+ */
uint32_t allocationCount;
/** \brief Pointer to array of allocations that can be defragmented.
- The array should have `allocationCount` elements.
- The array should not contain nulls.
- Elements in the array should be unique - same allocation cannot occur twice.
- It is safe to pass allocations that are in the lost state - they are ignored.
- All allocations not present in this array are considered non-moveable during this defragmentation.
- */
- VmaAllocation *pAllocations;
+ The array should have `allocationCount` elements.
+ The array should not contain nulls.
+ Elements in the array should be unique - same allocation cannot occur twice.
+ It is safe to pass allocations that are in the lost state - they are ignored.
+ All allocations not present in this array are considered non-moveable during this defragmentation.
+ */
+ VmaAllocation* pAllocations;
/** \brief Optional, output. Pointer to array that will be filled with information whether the allocation at certain index has been changed during defragmentation.
- The array should have `allocationCount` elements.
- You can pass null if you are not interested in this information.
- */
- VkBool32 *pAllocationsChanged;
+ The array should have `allocationCount` elements.
+ You can pass null if you are not interested in this information.
+ */
+ VkBool32* pAllocationsChanged;
/** \brief Numer of pools in `pPools` array.
- */
+ */
uint32_t poolCount;
/** \brief Either null or pointer to array of pools to be defragmented.
- All the allocations in the specified pools can be moved during defragmentation
- and there is no way to check if they were really moved as in `pAllocationsChanged`,
- so you must query all the allocations in all these pools for new `VkDeviceMemory`
- and offset using vmaGetAllocationInfo() if you might need to recreate buffers
- and images bound to them.
+ All the allocations in the specified pools can be moved during defragmentation
+ and there is no way to check if they were really moved as in `pAllocationsChanged`,
+ so you must query all the allocations in all these pools for new `VkDeviceMemory`
+ and offset using vmaGetAllocationInfo() if you might need to recreate buffers
+ and images bound to them.
- The array should have `poolCount` elements.
- The array should not contain nulls.
- Elements in the array should be unique - same pool cannot occur twice.
+ The array should have `poolCount` elements.
+ The array should not contain nulls.
+ Elements in the array should be unique - same pool cannot occur twice.
- Using this array is equivalent to specifying all allocations from the pools in `pAllocations`.
- It might be more efficient.
- */
- VmaPool *pPools;
+ Using this array is equivalent to specifying all allocations from the pools in `pAllocations`.
+ It might be more efficient.
+ */
+ VmaPool* pPools;
/** \brief Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on CPU side, like `memcpy()`, `memmove()`.
-
- `VK_WHOLE_SIZE` means no limit.
- */
+
+ `VK_WHOLE_SIZE` means no limit.
+ */
VkDeviceSize maxCpuBytesToMove;
/** \brief Maximum number of allocations that can be moved to a different place using transfers on CPU side, like `memcpy()`, `memmove()`.
- `UINT32_MAX` means no limit.
- */
+ `UINT32_MAX` means no limit.
+ */
uint32_t maxCpuAllocationsToMove;
/** \brief Maximum total numbers of bytes that can be copied while moving allocations to different places using transfers on GPU side, posted to `commandBuffer`.
-
- `VK_WHOLE_SIZE` means no limit.
- */
+
+ `VK_WHOLE_SIZE` means no limit.
+ */
VkDeviceSize maxGpuBytesToMove;
/** \brief Maximum number of allocations that can be moved to a different place using transfers on GPU side, posted to `commandBuffer`.
- `UINT32_MAX` means no limit.
- */
+ `UINT32_MAX` means no limit.
+ */
uint32_t maxGpuAllocationsToMove;
/** \brief Optional. Command buffer where GPU copy commands will be posted.
- If not null, it must be a valid command buffer handle that supports Transfer queue type.
- It must be in the recording state and outside of a render pass instance.
- You need to submit it and make sure it finished execution before calling vmaDefragmentationEnd().
+ If not null, it must be a valid command buffer handle that supports Transfer queue type.
+ It must be in the recording state and outside of a render pass instance.
+ You need to submit it and make sure it finished execution before calling vmaDefragmentationEnd().
- Passing null means that only CPU defragmentation will be performed.
- */
+ Passing null means that only CPU defragmentation will be performed.
+ */
VkCommandBuffer commandBuffer;
} VmaDefragmentationInfo2;
+typedef struct VmaDefragmentationPassMoveInfo {
+ VmaAllocation allocation;
+ VkDeviceMemory memory;
+ VkDeviceSize offset;
+} VmaDefragmentationPassMoveInfo;
+
+/** \brief Parameters for incremental defragmentation steps.
+
+To be used with function vmaBeginDefragmentationPass().
+*/
+typedef struct VmaDefragmentationPassInfo {
+ uint32_t moveCount;
+ VmaDefragmentationPassMoveInfo* pMoves;
+} VmaDefragmentationPassInfo;
+
/** \brief Deprecated. Optional configuration parameters to be passed to function vmaDefragment().
\deprecated This is a part of the old interface. It is recommended to use structure #VmaDefragmentationInfo2 and function vmaDefragmentationBegin() instead.
*/
typedef struct VmaDefragmentationInfo {
/** \brief Maximum total numbers of bytes that can be copied while moving allocations to different places.
-
- Default is `VK_WHOLE_SIZE`, which means no limit.
- */
+
+ Default is `VK_WHOLE_SIZE`, which means no limit.
+ */
VkDeviceSize maxBytesToMove;
/** \brief Maximum number of allocations that can be moved to different place.
- Default is `UINT32_MAX`, which means no limit.
- */
+ Default is `UINT32_MAX`, which means no limit.
+ */
uint32_t maxAllocationsToMove;
} VmaDefragmentationInfo;
@@ -2941,20 +3342,30 @@ Warning! Between the call to vmaDefragmentationBegin() and vmaDefragmentationEnd
For more information and important limitations regarding defragmentation, see documentation chapter:
[Defragmentation](@ref defragmentation).
*/
-VkResult vmaDefragmentationBegin(
- VmaAllocator allocator,
- const VmaDefragmentationInfo2 *pInfo,
- VmaDefragmentationStats *pStats,
- VmaDefragmentationContext *pContext);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaDefragmentationBegin(
+ VmaAllocator allocator,
+ const VmaDefragmentationInfo2* pInfo,
+ VmaDefragmentationStats* pStats,
+ VmaDefragmentationContext *pContext);
/** \brief Ends defragmentation process.
Use this function to finish defragmentation started by vmaDefragmentationBegin().
It is safe to pass `context == null`. The function then does nothing.
*/
-VkResult vmaDefragmentationEnd(
- VmaAllocator allocator,
- VmaDefragmentationContext context);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaDefragmentationEnd(
+ VmaAllocator allocator,
+ VmaDefragmentationContext context);
+
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBeginDefragmentationPass(
+ VmaAllocator allocator,
+ VmaDefragmentationContext context,
+ VmaDefragmentationPassInfo* pInfo
+);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaEndDefragmentationPass(
+ VmaAllocator allocator,
+ VmaDefragmentationContext context
+);
/** \brief Deprecated. Compacts memory by moving allocations.
@@ -2996,13 +3407,13 @@ you should measure that on your platform.
For more information, see [Defragmentation](@ref defragmentation) chapter.
*/
-VkResult vmaDefragment(
- VmaAllocator allocator,
- VmaAllocation *pAllocations,
- size_t allocationCount,
- VkBool32 *pAllocationsChanged,
- const VmaDefragmentationInfo *pDefragmentationInfo,
- VmaDefragmentationStats *pDefragmentationStats);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaDefragment(
+ VmaAllocator allocator,
+ VmaAllocation* pAllocations,
+ size_t allocationCount,
+ VkBool32* pAllocationsChanged,
+ const VmaDefragmentationInfo *pDefragmentationInfo,
+ VmaDefragmentationStats* pDefragmentationStats);
/** \brief Binds buffer to allocation.
@@ -3016,10 +3427,27 @@ allocations, calls to `vkBind*Memory()` or `vkMapMemory()` won't happen from mul
It is recommended to use function vmaCreateBuffer() instead of this one.
*/
-VkResult vmaBindBufferMemory(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VkBuffer buffer);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkBuffer buffer);
+
+/** \brief Binds buffer to allocation with additional parameters.
+
+@param allocationLocalOffset Additional offset to be added while binding, relative to the beginnig of the `allocation`. Normally it should be 0.
+@param pNext A chain of structures to be attached to `VkBindBufferMemoryInfoKHR` structure used internally. Normally it should be null.
+
+This function is similar to vmaBindBufferMemory(), but it provides additional parameters.
+
+If `pNext` is not null, #VmaAllocator object must have been created with #VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT flag
+or with VmaAllocatorCreateInfo::vulkanApiVersion `== VK_API_VERSION_1_1`. Otherwise the call fails.
+*/
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory2(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkDeviceSize allocationLocalOffset,
+ VkBuffer buffer,
+ const void* pNext);
/** \brief Binds image to allocation.
@@ -3033,10 +3461,27 @@ allocations, calls to `vkBind*Memory()` or `vkMapMemory()` won't happen from mul
It is recommended to use function vmaCreateImage() instead of this one.
*/
-VkResult vmaBindImageMemory(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VkImage image);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkImage image);
+
+/** \brief Binds image to allocation with additional parameters.
+
+@param allocationLocalOffset Additional offset to be added while binding, relative to the beginnig of the `allocation`. Normally it should be 0.
+@param pNext A chain of structures to be attached to `VkBindImageMemoryInfoKHR` structure used internally. Normally it should be null.
+
+This function is similar to vmaBindImageMemory(), but it provides additional parameters.
+
+If `pNext` is not null, #VmaAllocator object must have been created with #VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT flag
+or with VmaAllocatorCreateInfo::vulkanApiVersion `== VK_API_VERSION_1_1`. Otherwise the call fails.
+*/
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory2(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkDeviceSize allocationLocalOffset,
+ VkImage image,
+ const void* pNext);
/**
@param[out] pBuffer Buffer that was created.
@@ -3064,13 +3509,13 @@ and VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT is not used), it creates dedicated
allocation for this buffer, just like when using
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
*/
-VkResult vmaCreateBuffer(
- VmaAllocator allocator,
- const VkBufferCreateInfo *pBufferCreateInfo,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- VkBuffer *pBuffer,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBuffer(
+ VmaAllocator allocator,
+ const VkBufferCreateInfo* pBufferCreateInfo,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ VkBuffer* pBuffer,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo);
/** \brief Destroys Vulkan buffer and frees allocated memory.
@@ -3083,19 +3528,19 @@ vmaFreeMemory(allocator, allocation);
It it safe to pass null as buffer and/or allocation.
*/
-void vmaDestroyBuffer(
- VmaAllocator allocator,
- VkBuffer buffer,
- VmaAllocation allocation);
+VMA_CALL_PRE void VMA_CALL_POST vmaDestroyBuffer(
+ VmaAllocator allocator,
+ VkBuffer buffer,
+ VmaAllocation allocation);
/// Function similar to vmaCreateBuffer().
-VkResult vmaCreateImage(
- VmaAllocator allocator,
- const VkImageCreateInfo *pImageCreateInfo,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- VkImage *pImage,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo);
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateImage(
+ VmaAllocator allocator,
+ const VkImageCreateInfo* pImageCreateInfo,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ VkImage* pImage,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo);
/** \brief Destroys Vulkan image and frees allocated memory.
@@ -3108,10 +3553,10 @@ vmaFreeMemory(allocator, allocation);
It it safe to pass null as image and/or allocation.
*/
-void vmaDestroyImage(
- VmaAllocator allocator,
- VkImage image,
- VmaAllocation allocation);
+VMA_CALL_PRE void VMA_CALL_POST vmaDestroyImage(
+ VmaAllocator allocator,
+ VkImage image,
+ VmaAllocation allocation);
#ifdef __cplusplus
}
@@ -3130,6 +3575,7 @@ void vmaDestroyImage(
#include <cstdint>
#include <cstdlib>
#include <cstring>
+#include <utility>
/*******************************************************************************
CONFIGURATION SECTION
@@ -3142,7 +3588,7 @@ here if you need other then default behavior depending on your environment.
Define this macro to 1 to make the library fetch pointers to Vulkan functions
internally, like:
- vulkanFunctions.vkAllocateMemory = &vkAllocateMemory;
+ vulkanFunctions.vkAllocateMemory = &vkAllocateMemory;
Define to 0 if you are going to provide you own pointers to Vulkan functions via
VmaAllocatorCreateInfo::pVulkanFunctions.
@@ -3161,23 +3607,23 @@ Set it to 0 or undefined to make the library using its own implementation of
the containers.
*/
#if VMA_USE_STL_CONTAINERS
-#define VMA_USE_STL_VECTOR 1
-#define VMA_USE_STL_UNORDERED_MAP 1
-#define VMA_USE_STL_LIST 1
+ #define VMA_USE_STL_VECTOR 1
+ #define VMA_USE_STL_UNORDERED_MAP 1
+ #define VMA_USE_STL_LIST 1
#endif
#ifndef VMA_USE_STL_SHARED_MUTEX
-// Compiler conforms to C++17.
-#if __cplusplus >= 201703L
-#define VMA_USE_STL_SHARED_MUTEX 1
-// Visual studio defines __cplusplus properly only when passed additional parameter: /Zc:__cplusplus
-// Otherwise it's always 199711L, despite shared_mutex works since Visual Studio 2015 Update 2.
-// See: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/
-#elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918 && __cplusplus == 199711L && _MSVC_LANG >= 201703L
-#define VMA_USE_STL_SHARED_MUTEX 1
-#else
-#define VMA_USE_STL_SHARED_MUTEX 0
-#endif
+ // Compiler conforms to C++17.
+ #if __cplusplus >= 201703L
+ #define VMA_USE_STL_SHARED_MUTEX 1
+ // Visual studio defines __cplusplus properly only when passed additional parameter: /Zc:__cplusplus
+ // Otherwise it's always 199711L, despite shared_mutex works since Visual Studio 2015 Update 2.
+ // See: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/
+ #elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918 && __cplusplus == 199711L && _MSVC_LANG >= 201703L
+ #define VMA_USE_STL_SHARED_MUTEX 1
+ #else
+ #define VMA_USE_STL_SHARED_MUTEX 0
+ #endif
#endif
/*
@@ -3185,50 +3631,54 @@ THESE INCLUDES ARE NOT ENABLED BY DEFAULT.
Library has its own container implementation.
*/
#if VMA_USE_STL_VECTOR
-#include <vector>
+ #include <vector>
#endif
#if VMA_USE_STL_UNORDERED_MAP
-#include <unordered_map>
+ #include <unordered_map>
#endif
#if VMA_USE_STL_LIST
-#include <list>
+ #include <list>
#endif
/*
Following headers are used in this CONFIGURATION section only, so feel free to
remove them if not needed.
*/
-#include <algorithm> // for min, max
#include <cassert> // for assert
+#include <algorithm> // for min, max
#include <mutex>
#ifndef VMA_NULL
-// Value used as null pointer. Define it to e.g.: nullptr, NULL, 0, (void*)0.
-#define VMA_NULL nullptr
+ // Value used as null pointer. Define it to e.g.: nullptr, NULL, 0, (void*)0.
+ #define VMA_NULL nullptr
#endif
#if defined(__ANDROID_API__) && (__ANDROID_API__ < 16)
#include <cstdlib>
-void *aligned_alloc(size_t alignment, size_t size) {
+void *aligned_alloc(size_t alignment, size_t size)
+{
// alignment must be >= sizeof(void*)
- if (alignment < sizeof(void *)) {
- alignment = sizeof(void *);
+ if(alignment < sizeof(void*))
+ {
+ alignment = sizeof(void*);
}
return memalign(alignment, size);
}
-#elif defined(__APPLE__) || defined(__ANDROID__)
+#elif defined(__APPLE__) || defined(__ANDROID__) || (defined(__linux__) && defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC))
#include <cstdlib>
-void *aligned_alloc(size_t alignment, size_t size) {
+void *aligned_alloc(size_t alignment, size_t size)
+{
// alignment must be >= sizeof(void*)
- if (alignment < sizeof(void *)) {
- alignment = sizeof(void *);
+ if(alignment < sizeof(void*))
+ {
+ alignment = sizeof(void*);
}
void *pointer;
- if (posix_memalign(&pointer, alignment, size) == 0)
+ if(posix_memalign(&pointer, alignment, size) == 0)
return pointer;
return VMA_NULL;
}
@@ -3241,226 +3691,236 @@ void *aligned_alloc(size_t alignment, size_t size) {
// Normal assert to check for programmer's errors, especially in Debug configuration.
#ifndef VMA_ASSERT
-#ifdef _DEBUG
-#define VMA_ASSERT(expr) assert(expr)
-#else
-#define VMA_ASSERT(expr)
-#endif
+ #ifdef NDEBUG
+ #define VMA_ASSERT(expr)
+ #else
+ #define VMA_ASSERT(expr) assert(expr)
+ #endif
#endif
// Assert that will be called very often, like inside data structures e.g. operator[].
// Making it non-empty can make program slow.
#ifndef VMA_HEAVY_ASSERT
-#ifdef _DEBUG
-#define VMA_HEAVY_ASSERT(expr) //VMA_ASSERT(expr)
-#else
-#define VMA_HEAVY_ASSERT(expr)
-#endif
+ #ifdef NDEBUG
+ #define VMA_HEAVY_ASSERT(expr)
+ #else
+ #define VMA_HEAVY_ASSERT(expr) //VMA_ASSERT(expr)
+ #endif
#endif
#ifndef VMA_ALIGN_OF
-#define VMA_ALIGN_OF(type) (__alignof(type))
+ #define VMA_ALIGN_OF(type) (__alignof(type))
#endif
#ifndef VMA_SYSTEM_ALIGNED_MALLOC
-#if defined(_WIN32)
-#define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_malloc((size), (alignment)))
-#else
-#define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (aligned_alloc((alignment), (size)))
-#endif
+ #if defined(_WIN32)
+ #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_malloc((size), (alignment)))
+ #else
+ #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (aligned_alloc((alignment), (size) ))
+ #endif
#endif
#ifndef VMA_SYSTEM_FREE
-#if defined(_WIN32)
-#define VMA_SYSTEM_FREE(ptr) _aligned_free(ptr)
-#else
-#define VMA_SYSTEM_FREE(ptr) free(ptr)
-#endif
+ #if defined(_WIN32)
+ #define VMA_SYSTEM_FREE(ptr) _aligned_free(ptr)
+ #else
+ #define VMA_SYSTEM_FREE(ptr) free(ptr)
+ #endif
#endif
#ifndef VMA_MIN
-#define VMA_MIN(v1, v2) (std::min((v1), (v2)))
+ #define VMA_MIN(v1, v2) (std::min((v1), (v2)))
#endif
#ifndef VMA_MAX
-#define VMA_MAX(v1, v2) (std::max((v1), (v2)))
+ #define VMA_MAX(v1, v2) (std::max((v1), (v2)))
#endif
#ifndef VMA_SWAP
-#define VMA_SWAP(v1, v2) std::swap((v1), (v2))
+ #define VMA_SWAP(v1, v2) std::swap((v1), (v2))
#endif
#ifndef VMA_SORT
-#define VMA_SORT(beg, end, cmp) std::sort(beg, end, cmp)
+ #define VMA_SORT(beg, end, cmp) std::sort(beg, end, cmp)
#endif
#ifndef VMA_DEBUG_LOG
-#define VMA_DEBUG_LOG(format, ...)
-/*
+ #define VMA_DEBUG_LOG(format, ...)
+ /*
#define VMA_DEBUG_LOG(format, ...) do { \
- printf(format, __VA_ARGS__); \
- printf("\n"); \
+ printf(format, __VA_ARGS__); \
+ printf("\n"); \
} while(false)
*/
#endif
// Define this macro to 1 to enable functions: vmaBuildStatsString, vmaFreeStatsString.
#if VMA_STATS_STRING_ENABLED
-static inline void VmaUint32ToStr(char *outStr, size_t strLen, uint32_t num) {
- snprintf(outStr, strLen, "%u", static_cast<unsigned int>(num));
-}
-static inline void VmaUint64ToStr(char *outStr, size_t strLen, uint64_t num) {
- snprintf(outStr, strLen, "%llu", static_cast<unsigned long long>(num));
-}
-static inline void VmaPtrToStr(char *outStr, size_t strLen, const void *ptr) {
- snprintf(outStr, strLen, "%p", ptr);
-}
+ static inline void VmaUint32ToStr(char* outStr, size_t strLen, uint32_t num)
+ {
+ snprintf(outStr, strLen, "%u", static_cast<unsigned int>(num));
+ }
+ static inline void VmaUint64ToStr(char* outStr, size_t strLen, uint64_t num)
+ {
+ snprintf(outStr, strLen, "%llu", static_cast<unsigned long long>(num));
+ }
+ static inline void VmaPtrToStr(char* outStr, size_t strLen, const void* ptr)
+ {
+ snprintf(outStr, strLen, "%p", ptr);
+ }
#endif
#ifndef VMA_MUTEX
-class VmaMutex {
-public:
- void Lock() { m_Mutex.lock(); }
- void Unlock() { m_Mutex.unlock(); }
-
-private:
- std::mutex m_Mutex;
-};
-#define VMA_MUTEX VmaMutex
+ class VmaMutex
+ {
+ public:
+ void Lock() { m_Mutex.lock(); }
+ void Unlock() { m_Mutex.unlock(); }
+ bool TryLock() { return m_Mutex.try_lock(); }
+ private:
+ std::mutex m_Mutex;
+ };
+ #define VMA_MUTEX VmaMutex
#endif
// Read-write mutex, where "read" is shared access, "write" is exclusive access.
#ifndef VMA_RW_MUTEX
-#if VMA_USE_STL_SHARED_MUTEX
-// Use std::shared_mutex from C++17.
-#include <shared_mutex>
-class VmaRWMutex {
-public:
- void LockRead() { m_Mutex.lock_shared(); }
- void UnlockRead() { m_Mutex.unlock_shared(); }
- void LockWrite() { m_Mutex.lock(); }
- void UnlockWrite() { m_Mutex.unlock(); }
-
-private:
- std::shared_mutex m_Mutex;
-};
-#define VMA_RW_MUTEX VmaRWMutex
-#elif defined(_WIN32) && defined(WINVER) && WINVER >= 0x0600
-// Use SRWLOCK from WinAPI.
-// Minimum supported client = Windows Vista, server = Windows Server 2008.
-class VmaRWMutex {
-public:
- VmaRWMutex() { InitializeSRWLock(&m_Lock); }
- void LockRead() { AcquireSRWLockShared(&m_Lock); }
- void UnlockRead() { ReleaseSRWLockShared(&m_Lock); }
- void LockWrite() { AcquireSRWLockExclusive(&m_Lock); }
- void UnlockWrite() { ReleaseSRWLockExclusive(&m_Lock); }
-
-private:
- SRWLOCK m_Lock;
-};
-#define VMA_RW_MUTEX VmaRWMutex
-#else
-// Less efficient fallback: Use normal mutex.
-class VmaRWMutex {
-public:
- void LockRead() { m_Mutex.Lock(); }
- void UnlockRead() { m_Mutex.Unlock(); }
- void LockWrite() { m_Mutex.Lock(); }
- void UnlockWrite() { m_Mutex.Unlock(); }
-
-private:
- VMA_MUTEX m_Mutex;
-};
-#define VMA_RW_MUTEX VmaRWMutex
-#endif // #if VMA_USE_STL_SHARED_MUTEX
+ #if VMA_USE_STL_SHARED_MUTEX
+ // Use std::shared_mutex from C++17.
+ #include <shared_mutex>
+ class VmaRWMutex
+ {
+ public:
+ void LockRead() { m_Mutex.lock_shared(); }
+ void UnlockRead() { m_Mutex.unlock_shared(); }
+ bool TryLockRead() { return m_Mutex.try_lock_shared(); }
+ void LockWrite() { m_Mutex.lock(); }
+ void UnlockWrite() { m_Mutex.unlock(); }
+ bool TryLockWrite() { return m_Mutex.try_lock(); }
+ private:
+ std::shared_mutex m_Mutex;
+ };
+ #define VMA_RW_MUTEX VmaRWMutex
+ #elif defined(_WIN32) && defined(WINVER) && WINVER >= 0x0600
+ // Use SRWLOCK from WinAPI.
+ // Minimum supported client = Windows Vista, server = Windows Server 2008.
+ class VmaRWMutex
+ {
+ public:
+ VmaRWMutex() { InitializeSRWLock(&m_Lock); }
+ void LockRead() { AcquireSRWLockShared(&m_Lock); }
+ void UnlockRead() { ReleaseSRWLockShared(&m_Lock); }
+ bool TryLockRead() { return TryAcquireSRWLockShared(&m_Lock) != FALSE; }
+ void LockWrite() { AcquireSRWLockExclusive(&m_Lock); }
+ void UnlockWrite() { ReleaseSRWLockExclusive(&m_Lock); }
+ bool TryLockWrite() { return TryAcquireSRWLockExclusive(&m_Lock) != FALSE; }
+ private:
+ SRWLOCK m_Lock;
+ };
+ #define VMA_RW_MUTEX VmaRWMutex
+ #else
+ // Less efficient fallback: Use normal mutex.
+ class VmaRWMutex
+ {
+ public:
+ void LockRead() { m_Mutex.Lock(); }
+ void UnlockRead() { m_Mutex.Unlock(); }
+ bool TryLockRead() { return m_Mutex.TryLock(); }
+ void LockWrite() { m_Mutex.Lock(); }
+ void UnlockWrite() { m_Mutex.Unlock(); }
+ bool TryLockWrite() { return m_Mutex.TryLock(); }
+ private:
+ VMA_MUTEX m_Mutex;
+ };
+ #define VMA_RW_MUTEX VmaRWMutex
+ #endif // #if VMA_USE_STL_SHARED_MUTEX
#endif // #ifndef VMA_RW_MUTEX
/*
-If providing your own implementation, you need to implement a subset of std::atomic:
-
-- Constructor(uint32_t desired)
-- uint32_t load() const
-- void store(uint32_t desired)
-- bool compare_exchange_weak(uint32_t& expected, uint32_t desired)
+If providing your own implementation, you need to implement a subset of std::atomic.
*/
#ifndef VMA_ATOMIC_UINT32
-#include <atomic>
-#define VMA_ATOMIC_UINT32 std::atomic<uint32_t>
+ #include <atomic>
+ #define VMA_ATOMIC_UINT32 std::atomic<uint32_t>
+#endif
+
+#ifndef VMA_ATOMIC_UINT64
+ #include <atomic>
+ #define VMA_ATOMIC_UINT64 std::atomic<uint64_t>
#endif
#ifndef VMA_DEBUG_ALWAYS_DEDICATED_MEMORY
-/**
- Every allocation will have its own memory block.
- Define to 1 for debugging purposes only.
- */
-#define VMA_DEBUG_ALWAYS_DEDICATED_MEMORY (0)
+ /**
+ Every allocation will have its own memory block.
+ Define to 1 for debugging purposes only.
+ */
+ #define VMA_DEBUG_ALWAYS_DEDICATED_MEMORY (0)
#endif
#ifndef VMA_DEBUG_ALIGNMENT
-/**
- Minimum alignment of all allocations, in bytes.
- Set to more than 1 for debugging purposes only. Must be power of two.
- */
-#define VMA_DEBUG_ALIGNMENT (1)
+ /**
+ Minimum alignment of all allocations, in bytes.
+ Set to more than 1 for debugging purposes only. Must be power of two.
+ */
+ #define VMA_DEBUG_ALIGNMENT (1)
#endif
#ifndef VMA_DEBUG_MARGIN
-/**
- Minimum margin before and after every allocation, in bytes.
- Set nonzero for debugging purposes only.
- */
-#define VMA_DEBUG_MARGIN (0)
+ /**
+ Minimum margin before and after every allocation, in bytes.
+ Set nonzero for debugging purposes only.
+ */
+ #define VMA_DEBUG_MARGIN (0)
#endif
#ifndef VMA_DEBUG_INITIALIZE_ALLOCATIONS
-/**
- Define this macro to 1 to automatically fill new allocations and destroyed
- allocations with some bit pattern.
- */
-#define VMA_DEBUG_INITIALIZE_ALLOCATIONS (0)
+ /**
+ Define this macro to 1 to automatically fill new allocations and destroyed
+ allocations with some bit pattern.
+ */
+ #define VMA_DEBUG_INITIALIZE_ALLOCATIONS (0)
#endif
#ifndef VMA_DEBUG_DETECT_CORRUPTION
-/**
- Define this macro to 1 together with non-zero value of VMA_DEBUG_MARGIN to
- enable writing magic value to the margin before and after every allocation and
- validating it, so that memory corruptions (out-of-bounds writes) are detected.
- */
-#define VMA_DEBUG_DETECT_CORRUPTION (0)
+ /**
+ Define this macro to 1 together with non-zero value of VMA_DEBUG_MARGIN to
+ enable writing magic value to the margin before and after every allocation and
+ validating it, so that memory corruptions (out-of-bounds writes) are detected.
+ */
+ #define VMA_DEBUG_DETECT_CORRUPTION (0)
#endif
#ifndef VMA_DEBUG_GLOBAL_MUTEX
-/**
- Set this to 1 for debugging purposes only, to enable single mutex protecting all
- entry calls to the library. Can be useful for debugging multithreading issues.
- */
-#define VMA_DEBUG_GLOBAL_MUTEX (0)
+ /**
+ Set this to 1 for debugging purposes only, to enable single mutex protecting all
+ entry calls to the library. Can be useful for debugging multithreading issues.
+ */
+ #define VMA_DEBUG_GLOBAL_MUTEX (0)
#endif
#ifndef VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY
-/**
- Minimum value for VkPhysicalDeviceLimits::bufferImageGranularity.
- Set to more than 1 for debugging purposes only. Must be power of two.
- */
-#define VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY (1)
+ /**
+ Minimum value for VkPhysicalDeviceLimits::bufferImageGranularity.
+ Set to more than 1 for debugging purposes only. Must be power of two.
+ */
+ #define VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY (1)
#endif
#ifndef VMA_SMALL_HEAP_MAX_SIZE
-/// Maximum size of a memory heap in Vulkan to consider it "small".
-#define VMA_SMALL_HEAP_MAX_SIZE (1024ull * 1024 * 1024)
+ /// Maximum size of a memory heap in Vulkan to consider it "small".
+ #define VMA_SMALL_HEAP_MAX_SIZE (1024ull * 1024 * 1024)
#endif
#ifndef VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE
-/// Default size of a block allocated as single VkDeviceMemory from a "large" heap.
-#define VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE (256ull * 1024 * 1024)
+ /// Default size of a block allocated as single VkDeviceMemory from a "large" heap.
+ #define VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE (256ull * 1024 * 1024)
#endif
#ifndef VMA_CLASS_NO_COPY
-#define VMA_CLASS_NO_COPY(className) \
-private: \
- className(const className &) = delete; \
- className &operator=(const className &) = delete;
+ #define VMA_CLASS_NO_COPY(className) \
+ private: \
+ className(const className&) = delete; \
+ className& operator=(const className&) = delete;
#endif
static const uint32_t VMA_FRAME_INDEX_LOST = UINT32_MAX;
@@ -3468,25 +3928,31 @@ static const uint32_t VMA_FRAME_INDEX_LOST = UINT32_MAX;
// Decimal 2139416166, float NaN, little-endian binary 66 E6 84 7F.
static const uint32_t VMA_CORRUPTION_DETECTION_MAGIC_VALUE = 0x7F84E666;
-static const uint8_t VMA_ALLOCATION_FILL_PATTERN_CREATED = 0xDC;
+static const uint8_t VMA_ALLOCATION_FILL_PATTERN_CREATED = 0xDC;
static const uint8_t VMA_ALLOCATION_FILL_PATTERN_DESTROYED = 0xEF;
/*******************************************************************************
END OF CONFIGURATION
*/
+// # Copy of some Vulkan definitions so we don't need to check their existence just to handle few constants.
+
+static const uint32_t VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY = 0x00000040;
+static const uint32_t VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY = 0x00000080;
+
+
static const uint32_t VMA_ALLOCATION_INTERNAL_STRATEGY_MIN_OFFSET = 0x10000000u;
static VkAllocationCallbacks VmaEmptyAllocationCallbacks = {
- VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL
-};
+ VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL, VMA_NULL };
// Returns number of bits set to 1 in (v).
-static inline uint32_t VmaCountBitsSet(uint32_t v) {
+static inline uint32_t VmaCountBitsSet(uint32_t v)
+{
uint32_t c = v - ((v >> 1) & 0x55555555);
- c = ((c >> 2) & 0x33333333) + (c & 0x33333333);
- c = ((c >> 4) + c) & 0x0F0F0F0F;
- c = ((c >> 8) + c) & 0x00FF00FF;
+ c = ((c >> 2) & 0x33333333) + (c & 0x33333333);
+ c = ((c >> 4) + c) & 0x0F0F0F0F;
+ c = ((c >> 8) + c) & 0x00FF00FF;
c = ((c >> 16) + c) & 0x0000FFFF;
return c;
}
@@ -3494,19 +3960,22 @@ static inline uint32_t VmaCountBitsSet(uint32_t v) {
// Aligns given value up to nearest multiply of align value. For example: VmaAlignUp(11, 8) = 16.
// Use types like uint32_t, uint64_t as T.
template <typename T>
-static inline T VmaAlignUp(T val, T align) {
+static inline T VmaAlignUp(T val, T align)
+{
return (val + align - 1) / align * align;
}
// Aligns given value down to nearest multiply of align value. For example: VmaAlignUp(11, 8) = 8.
// Use types like uint32_t, uint64_t as T.
template <typename T>
-static inline T VmaAlignDown(T val, T align) {
+static inline T VmaAlignDown(T val, T align)
+{
return val / align * align;
}
// Division with mathematical rounding to nearest number.
template <typename T>
-static inline T VmaRoundDiv(T x, T y) {
+static inline T VmaRoundDiv(T x, T y)
+{
return (x + (y / (T)2)) / y;
}
@@ -3516,12 +3985,14 @@ T must be unsigned integer number or signed integer but always nonnegative.
For 0 returns true.
*/
template <typename T>
-inline bool VmaIsPow2(T x) {
- return (x & (x - 1)) == 0;
+inline bool VmaIsPow2(T x)
+{
+ return (x & (x-1)) == 0;
}
// Returns smallest power of 2 greater or equal to v.
-static inline uint32_t VmaNextPow2(uint32_t v) {
+static inline uint32_t VmaNextPow2(uint32_t v)
+{
v--;
v |= v >> 1;
v |= v >> 2;
@@ -3531,7 +4002,8 @@ static inline uint32_t VmaNextPow2(uint32_t v) {
v++;
return v;
}
-static inline uint64_t VmaNextPow2(uint64_t v) {
+static inline uint64_t VmaNextPow2(uint64_t v)
+{
v--;
v |= v >> 1;
v |= v >> 2;
@@ -3544,7 +4016,8 @@ static inline uint64_t VmaNextPow2(uint64_t v) {
}
// Returns largest power of 2 less or equal to v.
-static inline uint32_t VmaPrevPow2(uint32_t v) {
+static inline uint32_t VmaPrevPow2(uint32_t v)
+{
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
@@ -3553,7 +4026,8 @@ static inline uint32_t VmaPrevPow2(uint32_t v) {
v = v ^ (v >> 1);
return v;
}
-static inline uint64_t VmaPrevPow2(uint64_t v) {
+static inline uint64_t VmaPrevPow2(uint64_t v)
+{
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
@@ -3564,23 +4038,26 @@ static inline uint64_t VmaPrevPow2(uint64_t v) {
return v;
}
-static inline bool VmaStrIsEmpty(const char *pStr) {
+static inline bool VmaStrIsEmpty(const char* pStr)
+{
return pStr == VMA_NULL || *pStr == '\0';
}
#if VMA_STATS_STRING_ENABLED
-static const char *VmaAlgorithmToStr(uint32_t algorithm) {
- switch (algorithm) {
- case VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT:
- return "Linear";
- case VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT:
- return "Buddy";
- case 0:
- return "Default";
- default:
- VMA_ASSERT(0);
- return "";
+static const char* VmaAlgorithmToStr(uint32_t algorithm)
+{
+ switch(algorithm)
+ {
+ case VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT:
+ return "Linear";
+ case VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT:
+ return "Buddy";
+ case 0:
+ return "Default";
+ default:
+ VMA_ASSERT(0);
+ return "";
}
}
@@ -3588,28 +4065,34 @@ static const char *VmaAlgorithmToStr(uint32_t algorithm) {
#ifndef VMA_SORT
-template <typename Iterator, typename Compare>
-Iterator VmaQuickSortPartition(Iterator beg, Iterator end, Compare cmp) {
- Iterator centerValue = end;
- --centerValue;
+template<typename Iterator, typename Compare>
+Iterator VmaQuickSortPartition(Iterator beg, Iterator end, Compare cmp)
+{
+ Iterator centerValue = end; --centerValue;
Iterator insertIndex = beg;
- for (Iterator memTypeIndex = beg; memTypeIndex < centerValue; ++memTypeIndex) {
- if (cmp(*memTypeIndex, *centerValue)) {
- if (insertIndex != memTypeIndex) {
+ for(Iterator memTypeIndex = beg; memTypeIndex < centerValue; ++memTypeIndex)
+ {
+ if(cmp(*memTypeIndex, *centerValue))
+ {
+ if(insertIndex != memTypeIndex)
+ {
VMA_SWAP(*memTypeIndex, *insertIndex);
}
++insertIndex;
}
}
- if (insertIndex != centerValue) {
+ if(insertIndex != centerValue)
+ {
VMA_SWAP(*insertIndex, *centerValue);
}
return insertIndex;
}
-template <typename Iterator, typename Compare>
-void VmaQuickSort(Iterator beg, Iterator end, Compare cmp) {
- if (beg < end) {
+template<typename Iterator, typename Compare>
+void VmaQuickSort(Iterator beg, Iterator end, Compare cmp)
+{
+ if(beg < end)
+ {
Iterator it = VmaQuickSortPartition<Iterator, Compare>(beg, end, cmp);
VmaQuickSort<Iterator, Compare>(beg, it, cmp);
VmaQuickSort<Iterator, Compare>(it + 1, end, cmp);
@@ -3628,10 +4111,11 @@ Algorithm is based on "Vulkan 1.0.39 - A Specification (with all registered Vulk
chapter 11.6 "Resource Memory Association", paragraph "Buffer-Image Granularity".
*/
static inline bool VmaBlocksOnSamePage(
- VkDeviceSize resourceAOffset,
- VkDeviceSize resourceASize,
- VkDeviceSize resourceBOffset,
- VkDeviceSize pageSize) {
+ VkDeviceSize resourceAOffset,
+ VkDeviceSize resourceASize,
+ VkDeviceSize resourceBOffset,
+ VkDeviceSize pageSize)
+{
VMA_ASSERT(resourceAOffset + resourceASize <= resourceBOffset && resourceASize > 0 && pageSize > 0);
VkDeviceSize resourceAEnd = resourceAOffset + resourceASize - 1;
VkDeviceSize resourceAEndPage = resourceAEnd & ~(pageSize - 1);
@@ -3640,7 +4124,8 @@ static inline bool VmaBlocksOnSamePage(
return resourceAEndPage == resourceBStartPage;
}
-enum VmaSuballocationType {
+enum VmaSuballocationType
+{
VMA_SUBALLOCATION_TYPE_FREE = 0,
VMA_SUBALLOCATION_TYPE_UNKNOWN = 1,
VMA_SUBALLOCATION_TYPE_BUFFER = 2,
@@ -3657,50 +4142,67 @@ or linear image and another one is optimal image. If type is unknown, behave
conservatively.
*/
static inline bool VmaIsBufferImageGranularityConflict(
- VmaSuballocationType suballocType1,
- VmaSuballocationType suballocType2) {
- if (suballocType1 > suballocType2) {
+ VmaSuballocationType suballocType1,
+ VmaSuballocationType suballocType2)
+{
+ if(suballocType1 > suballocType2)
+ {
VMA_SWAP(suballocType1, suballocType2);
}
-
- switch (suballocType1) {
- case VMA_SUBALLOCATION_TYPE_FREE:
- return false;
- case VMA_SUBALLOCATION_TYPE_UNKNOWN:
- return true;
- case VMA_SUBALLOCATION_TYPE_BUFFER:
- return suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN ||
- suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL;
- case VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN:
- return suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN ||
- suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR ||
- suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL;
- case VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR:
- return suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL;
- case VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL:
- return false;
- default:
- VMA_ASSERT(0);
- return true;
+
+ switch(suballocType1)
+ {
+ case VMA_SUBALLOCATION_TYPE_FREE:
+ return false;
+ case VMA_SUBALLOCATION_TYPE_UNKNOWN:
+ return true;
+ case VMA_SUBALLOCATION_TYPE_BUFFER:
+ return
+ suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN ||
+ suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL;
+ case VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN:
+ return
+ suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN ||
+ suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR ||
+ suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL;
+ case VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR:
+ return
+ suballocType2 == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL;
+ case VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL:
+ return false;
+ default:
+ VMA_ASSERT(0);
+ return true;
}
}
-static void VmaWriteMagicValue(void *pData, VkDeviceSize offset) {
- uint32_t *pDst = (uint32_t *)((char *)pData + offset);
+static void VmaWriteMagicValue(void* pData, VkDeviceSize offset)
+{
+#if VMA_DEBUG_MARGIN > 0 && VMA_DEBUG_DETECT_CORRUPTION
+ uint32_t* pDst = (uint32_t*)((char*)pData + offset);
const size_t numberCount = VMA_DEBUG_MARGIN / sizeof(uint32_t);
- for (size_t i = 0; i < numberCount; ++i, ++pDst) {
+ for(size_t i = 0; i < numberCount; ++i, ++pDst)
+ {
*pDst = VMA_CORRUPTION_DETECTION_MAGIC_VALUE;
}
+#else
+ // no-op
+#endif
}
-static bool VmaValidateMagicValue(const void *pData, VkDeviceSize offset) {
- const uint32_t *pSrc = (const uint32_t *)((const char *)pData + offset);
+static bool VmaValidateMagicValue(const void* pData, VkDeviceSize offset)
+{
+#if VMA_DEBUG_MARGIN > 0 && VMA_DEBUG_DETECT_CORRUPTION
+ const uint32_t* pSrc = (const uint32_t*)((const char*)pData + offset);
const size_t numberCount = VMA_DEBUG_MARGIN / sizeof(uint32_t);
- for (size_t i = 0; i < numberCount; ++i, ++pSrc) {
- if (*pSrc != VMA_CORRUPTION_DETECTION_MAGIC_VALUE) {
+ for(size_t i = 0; i < numberCount; ++i, ++pSrc)
+ {
+ if(*pSrc != VMA_CORRUPTION_DETECTION_MAGIC_VALUE)
+ {
return false;
}
}
+#endif
return true;
}
@@ -3708,7 +4210,8 @@ static bool VmaValidateMagicValue(const void *pData, VkDeviceSize offset) {
Fills structure with parameters of an example buffer to be used for transfers
during GPU memory defragmentation.
*/
-static void VmaFillGpuDefragmentationBufferCreateInfo(VkBufferCreateInfo &outBufCreateInfo) {
+static void VmaFillGpuDefragmentationBufferCreateInfo(VkBufferCreateInfo& outBufCreateInfo)
+{
memset(&outBufCreateInfo, 0, sizeof(outBufCreateInfo));
outBufCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
outBufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
@@ -3716,70 +4219,50 @@ static void VmaFillGpuDefragmentationBufferCreateInfo(VkBufferCreateInfo &outBuf
}
// Helper RAII class to lock a mutex in constructor and unlock it in destructor (at the end of scope).
-struct VmaMutexLock {
+struct VmaMutexLock
+{
VMA_CLASS_NO_COPY(VmaMutexLock)
public:
- VmaMutexLock(VMA_MUTEX &mutex, bool useMutex = true) :
- m_pMutex(useMutex ? &mutex : VMA_NULL) {
- if (m_pMutex) {
- m_pMutex->Lock();
- }
- }
- ~VmaMutexLock() {
- if (m_pMutex) {
- m_pMutex->Unlock();
- }
- }
-
+ VmaMutexLock(VMA_MUTEX& mutex, bool useMutex = true) :
+ m_pMutex(useMutex ? &mutex : VMA_NULL)
+ { if(m_pMutex) { m_pMutex->Lock(); } }
+ ~VmaMutexLock()
+ { if(m_pMutex) { m_pMutex->Unlock(); } }
private:
- VMA_MUTEX *m_pMutex;
+ VMA_MUTEX* m_pMutex;
};
// Helper RAII class to lock a RW mutex in constructor and unlock it in destructor (at the end of scope), for reading.
-struct VmaMutexLockRead {
+struct VmaMutexLockRead
+{
VMA_CLASS_NO_COPY(VmaMutexLockRead)
public:
- VmaMutexLockRead(VMA_RW_MUTEX &mutex, bool useMutex) :
- m_pMutex(useMutex ? &mutex : VMA_NULL) {
- if (m_pMutex) {
- m_pMutex->LockRead();
- }
- }
- ~VmaMutexLockRead() {
- if (m_pMutex) {
- m_pMutex->UnlockRead();
- }
- }
-
+ VmaMutexLockRead(VMA_RW_MUTEX& mutex, bool useMutex) :
+ m_pMutex(useMutex ? &mutex : VMA_NULL)
+ { if(m_pMutex) { m_pMutex->LockRead(); } }
+ ~VmaMutexLockRead() { if(m_pMutex) { m_pMutex->UnlockRead(); } }
private:
- VMA_RW_MUTEX *m_pMutex;
+ VMA_RW_MUTEX* m_pMutex;
};
// Helper RAII class to lock a RW mutex in constructor and unlock it in destructor (at the end of scope), for writing.
-struct VmaMutexLockWrite {
+struct VmaMutexLockWrite
+{
VMA_CLASS_NO_COPY(VmaMutexLockWrite)
public:
- VmaMutexLockWrite(VMA_RW_MUTEX &mutex, bool useMutex) :
- m_pMutex(useMutex ? &mutex : VMA_NULL) {
- if (m_pMutex) {
- m_pMutex->LockWrite();
- }
- }
- ~VmaMutexLockWrite() {
- if (m_pMutex) {
- m_pMutex->UnlockWrite();
- }
- }
-
+ VmaMutexLockWrite(VMA_RW_MUTEX& mutex, bool useMutex) :
+ m_pMutex(useMutex ? &mutex : VMA_NULL)
+ { if(m_pMutex) { m_pMutex->LockWrite(); } }
+ ~VmaMutexLockWrite() { if(m_pMutex) { m_pMutex->UnlockWrite(); } }
private:
- VMA_RW_MUTEX *m_pMutex;
+ VMA_RW_MUTEX* m_pMutex;
};
#if VMA_DEBUG_GLOBAL_MUTEX
-static VMA_MUTEX gDebugGlobalMutex;
-#define VMA_DEBUG_GLOBAL_MUTEX_LOCK VmaMutexLock debugGlobalMutexLock(gDebugGlobalMutex, true);
+ static VMA_MUTEX gDebugGlobalMutex;
+ #define VMA_DEBUG_GLOBAL_MUTEX_LOCK VmaMutexLock debugGlobalMutexLock(gDebugGlobalMutex, true);
#else
-#define VMA_DEBUG_GLOBAL_MUTEX_LOCK
+ #define VMA_DEBUG_GLOBAL_MUTEX_LOCK
#endif
// Minimum size of a free suballocation to register it in the free suballocation collection.
@@ -3795,33 +4278,56 @@ Returned value is the found element, if present in the collection or place where
new element with value (key) should be inserted.
*/
template <typename CmpLess, typename IterT, typename KeyT>
-static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT &key, CmpLess cmp) {
+static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT &key, const CmpLess& cmp)
+{
size_t down = 0, up = (end - beg);
- while (down < up) {
+ while(down < up)
+ {
const size_t mid = (down + up) / 2;
- if (cmp(*(beg + mid), key)) {
+ if(cmp(*(beg+mid), key))
+ {
down = mid + 1;
- } else {
+ }
+ else
+ {
up = mid;
}
}
return beg + down;
}
+template<typename CmpLess, typename IterT, typename KeyT>
+IterT VmaBinaryFindSorted(const IterT& beg, const IterT& end, const KeyT& value, const CmpLess& cmp)
+{
+ IterT it = VmaBinaryFindFirstNotLess<CmpLess, IterT, KeyT>(
+ beg, end, value, cmp);
+ if(it == end ||
+ (!cmp(*it, value) && !cmp(value, *it)))
+ {
+ return it;
+ }
+ return end;
+}
+
/*
Returns true if all pointers in the array are not-null and unique.
Warning! O(n^2) complexity. Use only inside VMA_HEAVY_ASSERT.
T must be pointer type, e.g. VmaAllocation, VmaPool.
*/
-template <typename T>
-static bool VmaValidatePointerArray(uint32_t count, const T *arr) {
- for (uint32_t i = 0; i < count; ++i) {
+template<typename T>
+static bool VmaValidatePointerArray(uint32_t count, const T* arr)
+{
+ for(uint32_t i = 0; i < count; ++i)
+ {
const T iPtr = arr[i];
- if (iPtr == VMA_NULL) {
+ if(iPtr == VMA_NULL)
+ {
return false;
}
- for (uint32_t j = i + 1; j < count; ++j) {
- if (iPtr == arr[j]) {
+ for(uint32_t j = i + 1; j < count; ++j)
+ {
+ if(iPtr == arr[j])
+ {
return false;
}
}
@@ -3832,97 +4338,137 @@ static bool VmaValidatePointerArray(uint32_t count, const T *arr) {
////////////////////////////////////////////////////////////////////////////////
// Memory allocation
-static void *VmaMalloc(const VkAllocationCallbacks *pAllocationCallbacks, size_t size, size_t alignment) {
- if ((pAllocationCallbacks != VMA_NULL) &&
- (pAllocationCallbacks->pfnAllocation != VMA_NULL)) {
+static void* VmaMalloc(const VkAllocationCallbacks* pAllocationCallbacks, size_t size, size_t alignment)
+{
+ if((pAllocationCallbacks != VMA_NULL) &&
+ (pAllocationCallbacks->pfnAllocation != VMA_NULL))
+ {
return (*pAllocationCallbacks->pfnAllocation)(
- pAllocationCallbacks->pUserData,
- size,
- alignment,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- } else {
+ pAllocationCallbacks->pUserData,
+ size,
+ alignment,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ }
+ else
+ {
return VMA_SYSTEM_ALIGNED_MALLOC(size, alignment);
}
}
-static void VmaFree(const VkAllocationCallbacks *pAllocationCallbacks, void *ptr) {
- if ((pAllocationCallbacks != VMA_NULL) &&
- (pAllocationCallbacks->pfnFree != VMA_NULL)) {
+static void VmaFree(const VkAllocationCallbacks* pAllocationCallbacks, void* ptr)
+{
+ if((pAllocationCallbacks != VMA_NULL) &&
+ (pAllocationCallbacks->pfnFree != VMA_NULL))
+ {
(*pAllocationCallbacks->pfnFree)(pAllocationCallbacks->pUserData, ptr);
- } else {
+ }
+ else
+ {
VMA_SYSTEM_FREE(ptr);
}
}
-template <typename T>
-static T *VmaAllocate(const VkAllocationCallbacks *pAllocationCallbacks) {
- return (T *)VmaMalloc(pAllocationCallbacks, sizeof(T), VMA_ALIGN_OF(T));
+template<typename T>
+static T* VmaAllocate(const VkAllocationCallbacks* pAllocationCallbacks)
+{
+ return (T*)VmaMalloc(pAllocationCallbacks, sizeof(T), VMA_ALIGN_OF(T));
}
-template <typename T>
-static T *VmaAllocateArray(const VkAllocationCallbacks *pAllocationCallbacks, size_t count) {
- return (T *)VmaMalloc(pAllocationCallbacks, sizeof(T) * count, VMA_ALIGN_OF(T));
+template<typename T>
+static T* VmaAllocateArray(const VkAllocationCallbacks* pAllocationCallbacks, size_t count)
+{
+ return (T*)VmaMalloc(pAllocationCallbacks, sizeof(T) * count, VMA_ALIGN_OF(T));
}
-#define vma_new(allocator, type) new (VmaAllocate<type>(allocator))(type)
+#define vma_new(allocator, type) new(VmaAllocate<type>(allocator))(type)
-#define vma_new_array(allocator, type, count) new (VmaAllocateArray<type>((allocator), (count)))(type)
+#define vma_new_array(allocator, type, count) new(VmaAllocateArray<type>((allocator), (count)))(type)
-template <typename T>
-static void vma_delete(const VkAllocationCallbacks *pAllocationCallbacks, T *ptr) {
+template<typename T>
+static void vma_delete(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr)
+{
ptr->~T();
VmaFree(pAllocationCallbacks, ptr);
}
-template <typename T>
-static void vma_delete_array(const VkAllocationCallbacks *pAllocationCallbacks, T *ptr, size_t count) {
- if (ptr != VMA_NULL) {
- for (size_t i = count; i--;) {
+template<typename T>
+static void vma_delete_array(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr, size_t count)
+{
+ if(ptr != VMA_NULL)
+ {
+ for(size_t i = count; i--; )
+ {
ptr[i].~T();
}
VmaFree(pAllocationCallbacks, ptr);
}
}
+static char* VmaCreateStringCopy(const VkAllocationCallbacks* allocs, const char* srcStr)
+{
+ if(srcStr != VMA_NULL)
+ {
+ const size_t len = strlen(srcStr);
+ char* const result = vma_new_array(allocs, char, len + 1);
+ memcpy(result, srcStr, len + 1);
+ return result;
+ }
+ else
+ {
+ return VMA_NULL;
+ }
+}
+
+static void VmaFreeString(const VkAllocationCallbacks* allocs, char* str)
+{
+ if(str != VMA_NULL)
+ {
+ const size_t len = strlen(str);
+ vma_delete_array(allocs, str, len + 1);
+ }
+}
+
// STL-compatible allocator.
-template <typename T>
-class VmaStlAllocator {
+template<typename T>
+class VmaStlAllocator
+{
public:
- const VkAllocationCallbacks *const m_pCallbacks;
+ const VkAllocationCallbacks* const m_pCallbacks;
typedef T value_type;
+
+ VmaStlAllocator(const VkAllocationCallbacks* pCallbacks) : m_pCallbacks(pCallbacks) { }
+ template<typename U> VmaStlAllocator(const VmaStlAllocator<U>& src) : m_pCallbacks(src.m_pCallbacks) { }
- VmaStlAllocator(const VkAllocationCallbacks *pCallbacks) :
- m_pCallbacks(pCallbacks) {}
- template <typename U>
- VmaStlAllocator(const VmaStlAllocator<U> &src) :
- m_pCallbacks(src.m_pCallbacks) {}
+ T* allocate(size_t n) { return VmaAllocateArray<T>(m_pCallbacks, n); }
+ void deallocate(T* p, size_t n) { VmaFree(m_pCallbacks, p); }
- T *allocate(size_t n) { return VmaAllocateArray<T>(m_pCallbacks, n); }
- void deallocate(T *p, size_t n) { VmaFree(m_pCallbacks, p); }
-
- template <typename U>
- bool operator==(const VmaStlAllocator<U> &rhs) const {
+ template<typename U>
+ bool operator==(const VmaStlAllocator<U>& rhs) const
+ {
return m_pCallbacks == rhs.m_pCallbacks;
}
- template <typename U>
- bool operator!=(const VmaStlAllocator<U> &rhs) const {
+ template<typename U>
+ bool operator!=(const VmaStlAllocator<U>& rhs) const
+ {
return m_pCallbacks != rhs.m_pCallbacks;
}
- VmaStlAllocator &operator=(const VmaStlAllocator &x) = delete;
+ VmaStlAllocator& operator=(const VmaStlAllocator& x) = delete;
};
#if VMA_USE_STL_VECTOR
#define VmaVector std::vector
-template <typename T, typename allocatorT>
-static void VmaVectorInsert(std::vector<T, allocatorT> &vec, size_t index, const T &item) {
+template<typename T, typename allocatorT>
+static void VmaVectorInsert(std::vector<T, allocatorT>& vec, size_t index, const T& item)
+{
vec.insert(vec.begin() + index, item);
}
-template <typename T, typename allocatorT>
-static void VmaVectorRemove(std::vector<T, allocatorT> &vec, size_t index) {
+template<typename T, typename allocatorT>
+static void VmaVectorRemove(std::vector<T, allocatorT>& vec, size_t index)
+{
vec.erase(vec.begin() + index);
}
@@ -3931,90 +4477,114 @@ static void VmaVectorRemove(std::vector<T, allocatorT> &vec, size_t index) {
/* Class with interface compatible with subset of std::vector.
T must be POD because constructors and destructors are not called and memcpy is
used for these objects. */
-template <typename T, typename AllocatorT>
-class VmaVector {
+template<typename T, typename AllocatorT>
+class VmaVector
+{
public:
typedef T value_type;
- VmaVector(const AllocatorT &allocator) :
- m_Allocator(allocator),
- m_pArray(VMA_NULL),
- m_Count(0),
- m_Capacity(0) {
+ VmaVector(const AllocatorT& allocator) :
+ m_Allocator(allocator),
+ m_pArray(VMA_NULL),
+ m_Count(0),
+ m_Capacity(0)
+ {
}
- VmaVector(size_t count, const AllocatorT &allocator) :
- m_Allocator(allocator),
- m_pArray(count ? (T *)VmaAllocateArray<T>(allocator.m_pCallbacks, count) : VMA_NULL),
- m_Count(count),
- m_Capacity(count) {
+ VmaVector(size_t count, const AllocatorT& allocator) :
+ m_Allocator(allocator),
+ m_pArray(count ? (T*)VmaAllocateArray<T>(allocator.m_pCallbacks, count) : VMA_NULL),
+ m_Count(count),
+ m_Capacity(count)
+ {
}
-
- VmaVector(const VmaVector<T, AllocatorT> &src) :
- m_Allocator(src.m_Allocator),
- m_pArray(src.m_Count ? (T *)VmaAllocateArray<T>(src.m_Allocator.m_pCallbacks, src.m_Count) : VMA_NULL),
- m_Count(src.m_Count),
- m_Capacity(src.m_Count) {
- if (m_Count != 0) {
+
+ // This version of the constructor is here for compatibility with pre-C++14 std::vector.
+ // value is unused.
+ VmaVector(size_t count, const T& value, const AllocatorT& allocator)
+ : VmaVector(count, allocator) {}
+
+ VmaVector(const VmaVector<T, AllocatorT>& src) :
+ m_Allocator(src.m_Allocator),
+ m_pArray(src.m_Count ? (T*)VmaAllocateArray<T>(src.m_Allocator.m_pCallbacks, src.m_Count) : VMA_NULL),
+ m_Count(src.m_Count),
+ m_Capacity(src.m_Count)
+ {
+ if(m_Count != 0)
+ {
memcpy(m_pArray, src.m_pArray, m_Count * sizeof(T));
}
}
-
- ~VmaVector() {
+
+ ~VmaVector()
+ {
VmaFree(m_Allocator.m_pCallbacks, m_pArray);
}
- VmaVector &operator=(const VmaVector<T, AllocatorT> &rhs) {
- if (&rhs != this) {
+ VmaVector& operator=(const VmaVector<T, AllocatorT>& rhs)
+ {
+ if(&rhs != this)
+ {
resize(rhs.m_Count);
- if (m_Count != 0) {
+ if(m_Count != 0)
+ {
memcpy(m_pArray, rhs.m_pArray, m_Count * sizeof(T));
}
}
return *this;
}
-
+
bool empty() const { return m_Count == 0; }
size_t size() const { return m_Count; }
- T *data() { return m_pArray; }
- const T *data() const { return m_pArray; }
-
- T &operator[](size_t index) {
+ T* data() { return m_pArray; }
+ const T* data() const { return m_pArray; }
+
+ T& operator[](size_t index)
+ {
VMA_HEAVY_ASSERT(index < m_Count);
return m_pArray[index];
}
- const T &operator[](size_t index) const {
+ const T& operator[](size_t index) const
+ {
VMA_HEAVY_ASSERT(index < m_Count);
return m_pArray[index];
}
- T &front() {
+ T& front()
+ {
VMA_HEAVY_ASSERT(m_Count > 0);
return m_pArray[0];
}
- const T &front() const {
+ const T& front() const
+ {
VMA_HEAVY_ASSERT(m_Count > 0);
return m_pArray[0];
}
- T &back() {
+ T& back()
+ {
VMA_HEAVY_ASSERT(m_Count > 0);
return m_pArray[m_Count - 1];
}
- const T &back() const {
+ const T& back() const
+ {
VMA_HEAVY_ASSERT(m_Count > 0);
return m_pArray[m_Count - 1];
}
- void reserve(size_t newCapacity, bool freeMemory = false) {
+ void reserve(size_t newCapacity, bool freeMemory = false)
+ {
newCapacity = VMA_MAX(newCapacity, m_Count);
-
- if ((newCapacity < m_Capacity) && !freeMemory) {
+
+ if((newCapacity < m_Capacity) && !freeMemory)
+ {
newCapacity = m_Capacity;
}
-
- if (newCapacity != m_Capacity) {
- T *const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator, newCapacity) : VMA_NULL;
- if (m_Count != 0) {
+
+ if(newCapacity != m_Capacity)
+ {
+ T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator, newCapacity) : VMA_NULL;
+ if(m_Count != 0)
+ {
memcpy(newArray, m_pArray, m_Count * sizeof(T));
}
VmaFree(m_Allocator.m_pCallbacks, m_pArray);
@@ -4023,18 +4593,24 @@ public:
}
}
- void resize(size_t newCount, bool freeMemory = false) {
+ void resize(size_t newCount, bool freeMemory = false)
+ {
size_t newCapacity = m_Capacity;
- if (newCount > m_Capacity) {
+ if(newCount > m_Capacity)
+ {
newCapacity = VMA_MAX(newCount, VMA_MAX(m_Capacity * 3 / 2, (size_t)8));
- } else if (freeMemory) {
+ }
+ else if(freeMemory)
+ {
newCapacity = newCount;
}
- if (newCapacity != m_Capacity) {
- T *const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator.m_pCallbacks, newCapacity) : VMA_NULL;
+ if(newCapacity != m_Capacity)
+ {
+ T* const newArray = newCapacity ? VmaAllocateArray<T>(m_Allocator.m_pCallbacks, newCapacity) : VMA_NULL;
const size_t elementsToCopy = VMA_MIN(m_Count, newCount);
- if (elementsToCopy != 0) {
+ if(elementsToCopy != 0)
+ {
memcpy(newArray, m_pArray, elementsToCopy * sizeof(T));
}
VmaFree(m_Allocator.m_pCallbacks, m_pArray);
@@ -4045,94 +4621,107 @@ public:
m_Count = newCount;
}
- void clear(bool freeMemory = false) {
+ void clear(bool freeMemory = false)
+ {
resize(0, freeMemory);
}
- void insert(size_t index, const T &src) {
+ void insert(size_t index, const T& src)
+ {
VMA_HEAVY_ASSERT(index <= m_Count);
const size_t oldCount = size();
resize(oldCount + 1);
- if (index < oldCount) {
+ if(index < oldCount)
+ {
memmove(m_pArray + (index + 1), m_pArray + index, (oldCount - index) * sizeof(T));
}
m_pArray[index] = src;
}
- void remove(size_t index) {
+ void remove(size_t index)
+ {
VMA_HEAVY_ASSERT(index < m_Count);
const size_t oldCount = size();
- if (index < oldCount - 1) {
+ if(index < oldCount - 1)
+ {
memmove(m_pArray + index, m_pArray + (index + 1), (oldCount - index - 1) * sizeof(T));
}
resize(oldCount - 1);
}
- void push_back(const T &src) {
+ void push_back(const T& src)
+ {
const size_t newIndex = size();
resize(newIndex + 1);
m_pArray[newIndex] = src;
}
- void pop_back() {
+ void pop_back()
+ {
VMA_HEAVY_ASSERT(m_Count > 0);
resize(size() - 1);
}
- void push_front(const T &src) {
+ void push_front(const T& src)
+ {
insert(0, src);
}
- void pop_front() {
+ void pop_front()
+ {
VMA_HEAVY_ASSERT(m_Count > 0);
remove(0);
}
- typedef T *iterator;
+ typedef T* iterator;
iterator begin() { return m_pArray; }
iterator end() { return m_pArray + m_Count; }
private:
AllocatorT m_Allocator;
- T *m_pArray;
+ T* m_pArray;
size_t m_Count;
size_t m_Capacity;
};
-template <typename T, typename allocatorT>
-static void VmaVectorInsert(VmaVector<T, allocatorT> &vec, size_t index, const T &item) {
+template<typename T, typename allocatorT>
+static void VmaVectorInsert(VmaVector<T, allocatorT>& vec, size_t index, const T& item)
+{
vec.insert(index, item);
}
-template <typename T, typename allocatorT>
-static void VmaVectorRemove(VmaVector<T, allocatorT> &vec, size_t index) {
+template<typename T, typename allocatorT>
+static void VmaVectorRemove(VmaVector<T, allocatorT>& vec, size_t index)
+{
vec.remove(index);
}
#endif // #if VMA_USE_STL_VECTOR
-template <typename CmpLess, typename VectorT>
-size_t VmaVectorInsertSorted(VectorT &vector, const typename VectorT::value_type &value) {
+template<typename CmpLess, typename VectorT>
+size_t VmaVectorInsertSorted(VectorT& vector, const typename VectorT::value_type& value)
+{
const size_t indexToInsert = VmaBinaryFindFirstNotLess(
- vector.data(),
- vector.data() + vector.size(),
- value,
- CmpLess()) -
- vector.data();
+ vector.data(),
+ vector.data() + vector.size(),
+ value,
+ CmpLess()) - vector.data();
VmaVectorInsert(vector, indexToInsert, value);
return indexToInsert;
}
-template <typename CmpLess, typename VectorT>
-bool VmaVectorRemoveSorted(VectorT &vector, const typename VectorT::value_type &value) {
+template<typename CmpLess, typename VectorT>
+bool VmaVectorRemoveSorted(VectorT& vector, const typename VectorT::value_type& value)
+{
CmpLess comparator;
typename VectorT::iterator it = VmaBinaryFindFirstNotLess(
- vector.begin(),
- vector.end(),
- value,
- comparator);
- if ((it != vector.end()) && !comparator(*it, value) && !comparator(value, *it)) {
+ vector.begin(),
+ vector.end(),
+ value,
+ comparator);
+ if((it != vector.end()) && !comparator(*it, value) && !comparator(value, *it))
+ {
size_t indexToRemove = it - vector.begin();
VmaVectorRemove(vector, indexToRemove);
return true;
@@ -4140,18 +4729,6 @@ bool VmaVectorRemoveSorted(VectorT &vector, const typename VectorT::value_type &
return false;
}
-template <typename CmpLess, typename IterT, typename KeyT>
-IterT VmaVectorFindSorted(const IterT &beg, const IterT &end, const KeyT &value) {
- CmpLess comparator;
- IterT it = VmaBinaryFindFirstNotLess<CmpLess, IterT, KeyT>(
- beg, end, value, comparator);
- if (it == end ||
- (!comparator(*it, value) && !comparator(value, *it))) {
- return it;
- }
- return end;
-}
-
////////////////////////////////////////////////////////////////////////////////
// class VmaPoolAllocator
@@ -4160,86 +4737,96 @@ Allocator for objects of type T using a list of arrays (pools) to speed up
allocation. Number of elements that can be allocated is not bounded because
allocator can create multiple blocks.
*/
-template <typename T>
-class VmaPoolAllocator {
+template<typename T>
+class VmaPoolAllocator
+{
VMA_CLASS_NO_COPY(VmaPoolAllocator)
public:
- VmaPoolAllocator(const VkAllocationCallbacks *pAllocationCallbacks, uint32_t firstBlockCapacity);
+ VmaPoolAllocator(const VkAllocationCallbacks* pAllocationCallbacks, uint32_t firstBlockCapacity);
~VmaPoolAllocator();
- void Clear();
- T *Alloc();
- void Free(T *ptr);
+ template<typename... Types> T* Alloc(Types... args);
+ void Free(T* ptr);
private:
- union Item {
+ union Item
+ {
uint32_t NextFreeIndex;
- T Value;
+ alignas(T) char Value[sizeof(T)];
};
- struct ItemBlock {
- Item *pItems;
+ struct ItemBlock
+ {
+ Item* pItems;
uint32_t Capacity;
uint32_t FirstFreeIndex;
};
-
- const VkAllocationCallbacks *m_pAllocationCallbacks;
+
+ const VkAllocationCallbacks* m_pAllocationCallbacks;
const uint32_t m_FirstBlockCapacity;
- VmaVector<ItemBlock, VmaStlAllocator<ItemBlock> > m_ItemBlocks;
+ VmaVector< ItemBlock, VmaStlAllocator<ItemBlock> > m_ItemBlocks;
- ItemBlock &CreateNewBlock();
+ ItemBlock& CreateNewBlock();
};
-template <typename T>
-VmaPoolAllocator<T>::VmaPoolAllocator(const VkAllocationCallbacks *pAllocationCallbacks, uint32_t firstBlockCapacity) :
- m_pAllocationCallbacks(pAllocationCallbacks),
- m_FirstBlockCapacity(firstBlockCapacity),
- m_ItemBlocks(VmaStlAllocator<ItemBlock>(pAllocationCallbacks)) {
+template<typename T>
+VmaPoolAllocator<T>::VmaPoolAllocator(const VkAllocationCallbacks* pAllocationCallbacks, uint32_t firstBlockCapacity) :
+ m_pAllocationCallbacks(pAllocationCallbacks),
+ m_FirstBlockCapacity(firstBlockCapacity),
+ m_ItemBlocks(VmaStlAllocator<ItemBlock>(pAllocationCallbacks))
+{
VMA_ASSERT(m_FirstBlockCapacity > 1);
}
-template <typename T>
-VmaPoolAllocator<T>::~VmaPoolAllocator() {
- Clear();
-}
-
-template <typename T>
-void VmaPoolAllocator<T>::Clear() {
- for (size_t i = m_ItemBlocks.size(); i--;)
+template<typename T>
+VmaPoolAllocator<T>::~VmaPoolAllocator()
+{
+ for(size_t i = m_ItemBlocks.size(); i--; )
vma_delete_array(m_pAllocationCallbacks, m_ItemBlocks[i].pItems, m_ItemBlocks[i].Capacity);
m_ItemBlocks.clear();
}
-template <typename T>
-T *VmaPoolAllocator<T>::Alloc() {
- for (size_t i = m_ItemBlocks.size(); i--;) {
- ItemBlock &block = m_ItemBlocks[i];
+template<typename T>
+template<typename... Types> T* VmaPoolAllocator<T>::Alloc(Types... args)
+{
+ for(size_t i = m_ItemBlocks.size(); i--; )
+ {
+ ItemBlock& block = m_ItemBlocks[i];
// This block has some free items: Use first one.
- if (block.FirstFreeIndex != UINT32_MAX) {
- Item *const pItem = &block.pItems[block.FirstFreeIndex];
+ if(block.FirstFreeIndex != UINT32_MAX)
+ {
+ Item* const pItem = &block.pItems[block.FirstFreeIndex];
block.FirstFreeIndex = pItem->NextFreeIndex;
- return &pItem->Value;
+ T* result = (T*)&pItem->Value;
+ new(result)T(std::forward<Types>(args)...); // Explicit constructor call.
+ return result;
}
}
// No block has free item: Create new one and use it.
- ItemBlock &newBlock = CreateNewBlock();
- Item *const pItem = &newBlock.pItems[0];
+ ItemBlock& newBlock = CreateNewBlock();
+ Item* const pItem = &newBlock.pItems[0];
newBlock.FirstFreeIndex = pItem->NextFreeIndex;
- return &pItem->Value;
+ T* result = (T*)&pItem->Value;
+ new(result)T(std::forward<Types>(args)...); // Explicit constructor call.
+ return result;
}
-template <typename T>
-void VmaPoolAllocator<T>::Free(T *ptr) {
+template<typename T>
+void VmaPoolAllocator<T>::Free(T* ptr)
+{
// Search all memory blocks to find ptr.
- for (size_t i = m_ItemBlocks.size(); i--;) {
- ItemBlock &block = m_ItemBlocks[i];
-
+ for(size_t i = m_ItemBlocks.size(); i--; )
+ {
+ ItemBlock& block = m_ItemBlocks[i];
+
// Casting to union.
- Item *pItemPtr;
+ Item* pItemPtr;
memcpy(&pItemPtr, &ptr, sizeof(pItemPtr));
-
+
// Check if pItemPtr is in address range of this block.
- if ((pItemPtr >= block.pItems) && (pItemPtr < block.pItems + block.Capacity)) {
+ if((pItemPtr >= block.pItems) && (pItemPtr < block.pItems + block.Capacity))
+ {
+ ptr->~T(); // Explicit destructor call.
const uint32_t index = static_cast<uint32_t>(pItemPtr - block.pItems);
pItemPtr->NextFreeIndex = block.FirstFreeIndex;
block.FirstFreeIndex = index;
@@ -4249,22 +4836,21 @@ void VmaPoolAllocator<T>::Free(T *ptr) {
VMA_ASSERT(0 && "Pointer doesn't belong to this memory pool.");
}
-template <typename T>
-typename VmaPoolAllocator<T>::ItemBlock &VmaPoolAllocator<T>::CreateNewBlock() {
+template<typename T>
+typename VmaPoolAllocator<T>::ItemBlock& VmaPoolAllocator<T>::CreateNewBlock()
+{
const uint32_t newBlockCapacity = m_ItemBlocks.empty() ?
- m_FirstBlockCapacity :
- m_ItemBlocks.back().Capacity * 3 / 2;
+ m_FirstBlockCapacity : m_ItemBlocks.back().Capacity * 3 / 2;
const ItemBlock newBlock = {
vma_new_array(m_pAllocationCallbacks, Item, newBlockCapacity),
newBlockCapacity,
- 0
- };
+ 0 };
m_ItemBlocks.push_back(newBlock);
// Setup singly-linked list of all free items in this block.
- for (uint32_t i = 0; i < newBlockCapacity - 1; ++i)
+ for(uint32_t i = 0; i < newBlockCapacity - 1; ++i)
newBlock.pItems[i].NextFreeIndex = i + 1;
newBlock.pItems[newBlockCapacity - 1].NextFreeIndex = UINT32_MAX;
return m_ItemBlocks.back();
@@ -4279,78 +4865,85 @@ typename VmaPoolAllocator<T>::ItemBlock &VmaPoolAllocator<T>::CreateNewBlock() {
#else // #if VMA_USE_STL_LIST
-template <typename T>
-struct VmaListItem {
- VmaListItem *pPrev;
- VmaListItem *pNext;
+template<typename T>
+struct VmaListItem
+{
+ VmaListItem* pPrev;
+ VmaListItem* pNext;
T Value;
};
// Doubly linked list.
-template <typename T>
-class VmaRawList {
+template<typename T>
+class VmaRawList
+{
VMA_CLASS_NO_COPY(VmaRawList)
public:
typedef VmaListItem<T> ItemType;
- VmaRawList(const VkAllocationCallbacks *pAllocationCallbacks);
+ VmaRawList(const VkAllocationCallbacks* pAllocationCallbacks);
~VmaRawList();
void Clear();
size_t GetCount() const { return m_Count; }
bool IsEmpty() const { return m_Count == 0; }
- ItemType *Front() { return m_pFront; }
- const ItemType *Front() const { return m_pFront; }
- ItemType *Back() { return m_pBack; }
- const ItemType *Back() const { return m_pBack; }
+ ItemType* Front() { return m_pFront; }
+ const ItemType* Front() const { return m_pFront; }
+ ItemType* Back() { return m_pBack; }
+ const ItemType* Back() const { return m_pBack; }
- ItemType *PushBack();
- ItemType *PushFront();
- ItemType *PushBack(const T &value);
- ItemType *PushFront(const T &value);
+ ItemType* PushBack();
+ ItemType* PushFront();
+ ItemType* PushBack(const T& value);
+ ItemType* PushFront(const T& value);
void PopBack();
void PopFront();
-
+
// Item can be null - it means PushBack.
- ItemType *InsertBefore(ItemType *pItem);
+ ItemType* InsertBefore(ItemType* pItem);
// Item can be null - it means PushFront.
- ItemType *InsertAfter(ItemType *pItem);
+ ItemType* InsertAfter(ItemType* pItem);
- ItemType *InsertBefore(ItemType *pItem, const T &value);
- ItemType *InsertAfter(ItemType *pItem, const T &value);
+ ItemType* InsertBefore(ItemType* pItem, const T& value);
+ ItemType* InsertAfter(ItemType* pItem, const T& value);
- void Remove(ItemType *pItem);
+ void Remove(ItemType* pItem);
private:
- const VkAllocationCallbacks *const m_pAllocationCallbacks;
+ const VkAllocationCallbacks* const m_pAllocationCallbacks;
VmaPoolAllocator<ItemType> m_ItemAllocator;
- ItemType *m_pFront;
- ItemType *m_pBack;
+ ItemType* m_pFront;
+ ItemType* m_pBack;
size_t m_Count;
};
-template <typename T>
-VmaRawList<T>::VmaRawList(const VkAllocationCallbacks *pAllocationCallbacks) :
- m_pAllocationCallbacks(pAllocationCallbacks),
- m_ItemAllocator(pAllocationCallbacks, 128),
- m_pFront(VMA_NULL),
- m_pBack(VMA_NULL),
- m_Count(0) {
+template<typename T>
+VmaRawList<T>::VmaRawList(const VkAllocationCallbacks* pAllocationCallbacks) :
+ m_pAllocationCallbacks(pAllocationCallbacks),
+ m_ItemAllocator(pAllocationCallbacks, 128),
+ m_pFront(VMA_NULL),
+ m_pBack(VMA_NULL),
+ m_Count(0)
+{
}
-template <typename T>
-VmaRawList<T>::~VmaRawList() {
+template<typename T>
+VmaRawList<T>::~VmaRawList()
+{
// Intentionally not calling Clear, because that would be unnecessary
// computations to return all items to m_ItemAllocator as free.
}
-template <typename T>
-void VmaRawList<T>::Clear() {
- if (IsEmpty() == false) {
- ItemType *pItem = m_pBack;
- while (pItem != VMA_NULL) {
- ItemType *const pPrevItem = pItem->pPrev;
+template<typename T>
+void VmaRawList<T>::Clear()
+{
+ if(IsEmpty() == false)
+ {
+ ItemType* pItem = m_pBack;
+ while(pItem != VMA_NULL)
+ {
+ ItemType* const pPrevItem = pItem->pPrev;
m_ItemAllocator.Free(pItem);
pItem = pPrevItem;
}
@@ -4360,16 +4953,20 @@ void VmaRawList<T>::Clear() {
}
}
-template <typename T>
-VmaListItem<T> *VmaRawList<T>::PushBack() {
- ItemType *const pNewItem = m_ItemAllocator.Alloc();
+template<typename T>
+VmaListItem<T>* VmaRawList<T>::PushBack()
+{
+ ItemType* const pNewItem = m_ItemAllocator.Alloc();
pNewItem->pNext = VMA_NULL;
- if (IsEmpty()) {
+ if(IsEmpty())
+ {
pNewItem->pPrev = VMA_NULL;
m_pFront = pNewItem;
m_pBack = pNewItem;
m_Count = 1;
- } else {
+ }
+ else
+ {
pNewItem->pPrev = m_pBack;
m_pBack->pNext = pNewItem;
m_pBack = pNewItem;
@@ -4378,16 +4975,20 @@ VmaListItem<T> *VmaRawList<T>::PushBack() {
return pNewItem;
}
-template <typename T>
-VmaListItem<T> *VmaRawList<T>::PushFront() {
- ItemType *const pNewItem = m_ItemAllocator.Alloc();
+template<typename T>
+VmaListItem<T>* VmaRawList<T>::PushFront()
+{
+ ItemType* const pNewItem = m_ItemAllocator.Alloc();
pNewItem->pPrev = VMA_NULL;
- if (IsEmpty()) {
+ if(IsEmpty())
+ {
pNewItem->pNext = VMA_NULL;
m_pFront = pNewItem;
m_pBack = pNewItem;
m_Count = 1;
- } else {
+ }
+ else
+ {
pNewItem->pNext = m_pFront;
m_pFront->pPrev = pNewItem;
m_pFront = pNewItem;
@@ -4396,26 +4997,30 @@ VmaListItem<T> *VmaRawList<T>::PushFront() {
return pNewItem;
}
-template <typename T>
-VmaListItem<T> *VmaRawList<T>::PushBack(const T &value) {
- ItemType *const pNewItem = PushBack();
+template<typename T>
+VmaListItem<T>* VmaRawList<T>::PushBack(const T& value)
+{
+ ItemType* const pNewItem = PushBack();
pNewItem->Value = value;
return pNewItem;
}
-template <typename T>
-VmaListItem<T> *VmaRawList<T>::PushFront(const T &value) {
- ItemType *const pNewItem = PushFront();
+template<typename T>
+VmaListItem<T>* VmaRawList<T>::PushFront(const T& value)
+{
+ ItemType* const pNewItem = PushFront();
pNewItem->Value = value;
return pNewItem;
}
-template <typename T>
-void VmaRawList<T>::PopBack() {
+template<typename T>
+void VmaRawList<T>::PopBack()
+{
VMA_HEAVY_ASSERT(m_Count > 0);
- ItemType *const pBackItem = m_pBack;
- ItemType *const pPrevItem = pBackItem->pPrev;
- if (pPrevItem != VMA_NULL) {
+ ItemType* const pBackItem = m_pBack;
+ ItemType* const pPrevItem = pBackItem->pPrev;
+ if(pPrevItem != VMA_NULL)
+ {
pPrevItem->pNext = VMA_NULL;
}
m_pBack = pPrevItem;
@@ -4423,12 +5028,14 @@ void VmaRawList<T>::PopBack() {
--m_Count;
}
-template <typename T>
-void VmaRawList<T>::PopFront() {
+template<typename T>
+void VmaRawList<T>::PopFront()
+{
VMA_HEAVY_ASSERT(m_Count > 0);
- ItemType *const pFrontItem = m_pFront;
- ItemType *const pNextItem = pFrontItem->pNext;
- if (pNextItem != VMA_NULL) {
+ ItemType* const pFrontItem = m_pFront;
+ ItemType* const pNextItem = pFrontItem->pNext;
+ if(pNextItem != VMA_NULL)
+ {
pNextItem->pPrev = VMA_NULL;
}
m_pFront = pNextItem;
@@ -4436,21 +5043,28 @@ void VmaRawList<T>::PopFront() {
--m_Count;
}
-template <typename T>
-void VmaRawList<T>::Remove(ItemType *pItem) {
+template<typename T>
+void VmaRawList<T>::Remove(ItemType* pItem)
+{
VMA_HEAVY_ASSERT(pItem != VMA_NULL);
VMA_HEAVY_ASSERT(m_Count > 0);
- if (pItem->pPrev != VMA_NULL) {
+ if(pItem->pPrev != VMA_NULL)
+ {
pItem->pPrev->pNext = pItem->pNext;
- } else {
+ }
+ else
+ {
VMA_HEAVY_ASSERT(m_pFront == pItem);
m_pFront = pItem->pNext;
}
- if (pItem->pNext != VMA_NULL) {
+ if(pItem->pNext != VMA_NULL)
+ {
pItem->pNext->pPrev = pItem->pPrev;
- } else {
+ }
+ else
+ {
VMA_HEAVY_ASSERT(m_pBack == pItem);
m_pBack = pItem->pPrev;
}
@@ -4459,197 +5073,240 @@ void VmaRawList<T>::Remove(ItemType *pItem) {
--m_Count;
}
-template <typename T>
-VmaListItem<T> *VmaRawList<T>::InsertBefore(ItemType *pItem) {
- if (pItem != VMA_NULL) {
- ItemType *const prevItem = pItem->pPrev;
- ItemType *const newItem = m_ItemAllocator.Alloc();
+template<typename T>
+VmaListItem<T>* VmaRawList<T>::InsertBefore(ItemType* pItem)
+{
+ if(pItem != VMA_NULL)
+ {
+ ItemType* const prevItem = pItem->pPrev;
+ ItemType* const newItem = m_ItemAllocator.Alloc();
newItem->pPrev = prevItem;
newItem->pNext = pItem;
pItem->pPrev = newItem;
- if (prevItem != VMA_NULL) {
+ if(prevItem != VMA_NULL)
+ {
prevItem->pNext = newItem;
- } else {
+ }
+ else
+ {
VMA_HEAVY_ASSERT(m_pFront == pItem);
m_pFront = newItem;
}
++m_Count;
return newItem;
- } else
+ }
+ else
return PushBack();
}
-template <typename T>
-VmaListItem<T> *VmaRawList<T>::InsertAfter(ItemType *pItem) {
- if (pItem != VMA_NULL) {
- ItemType *const nextItem = pItem->pNext;
- ItemType *const newItem = m_ItemAllocator.Alloc();
+template<typename T>
+VmaListItem<T>* VmaRawList<T>::InsertAfter(ItemType* pItem)
+{
+ if(pItem != VMA_NULL)
+ {
+ ItemType* const nextItem = pItem->pNext;
+ ItemType* const newItem = m_ItemAllocator.Alloc();
newItem->pNext = nextItem;
newItem->pPrev = pItem;
pItem->pNext = newItem;
- if (nextItem != VMA_NULL) {
+ if(nextItem != VMA_NULL)
+ {
nextItem->pPrev = newItem;
- } else {
+ }
+ else
+ {
VMA_HEAVY_ASSERT(m_pBack == pItem);
m_pBack = newItem;
}
++m_Count;
return newItem;
- } else
+ }
+ else
return PushFront();
}
-template <typename T>
-VmaListItem<T> *VmaRawList<T>::InsertBefore(ItemType *pItem, const T &value) {
- ItemType *const newItem = InsertBefore(pItem);
+template<typename T>
+VmaListItem<T>* VmaRawList<T>::InsertBefore(ItemType* pItem, const T& value)
+{
+ ItemType* const newItem = InsertBefore(pItem);
newItem->Value = value;
return newItem;
}
-template <typename T>
-VmaListItem<T> *VmaRawList<T>::InsertAfter(ItemType *pItem, const T &value) {
- ItemType *const newItem = InsertAfter(pItem);
+template<typename T>
+VmaListItem<T>* VmaRawList<T>::InsertAfter(ItemType* pItem, const T& value)
+{
+ ItemType* const newItem = InsertAfter(pItem);
newItem->Value = value;
return newItem;
}
-template <typename T, typename AllocatorT>
-class VmaList {
+template<typename T, typename AllocatorT>
+class VmaList
+{
VMA_CLASS_NO_COPY(VmaList)
public:
- class iterator {
+ class iterator
+ {
public:
iterator() :
- m_pList(VMA_NULL),
- m_pItem(VMA_NULL) {
+ m_pList(VMA_NULL),
+ m_pItem(VMA_NULL)
+ {
}
- T &operator*() const {
+ T& operator*() const
+ {
VMA_HEAVY_ASSERT(m_pItem != VMA_NULL);
return m_pItem->Value;
}
- T *operator->() const {
+ T* operator->() const
+ {
VMA_HEAVY_ASSERT(m_pItem != VMA_NULL);
return &m_pItem->Value;
}
- iterator &operator++() {
+ iterator& operator++()
+ {
VMA_HEAVY_ASSERT(m_pItem != VMA_NULL);
m_pItem = m_pItem->pNext;
return *this;
}
- iterator &operator--() {
- if (m_pItem != VMA_NULL) {
+ iterator& operator--()
+ {
+ if(m_pItem != VMA_NULL)
+ {
m_pItem = m_pItem->pPrev;
- } else {
+ }
+ else
+ {
VMA_HEAVY_ASSERT(!m_pList->IsEmpty());
m_pItem = m_pList->Back();
}
return *this;
}
- iterator operator++(int) {
+ iterator operator++(int)
+ {
iterator result = *this;
++*this;
return result;
}
- iterator operator--(int) {
+ iterator operator--(int)
+ {
iterator result = *this;
--*this;
return result;
}
- bool operator==(const iterator &rhs) const {
+ bool operator==(const iterator& rhs) const
+ {
VMA_HEAVY_ASSERT(m_pList == rhs.m_pList);
return m_pItem == rhs.m_pItem;
}
- bool operator!=(const iterator &rhs) const {
+ bool operator!=(const iterator& rhs) const
+ {
VMA_HEAVY_ASSERT(m_pList == rhs.m_pList);
return m_pItem != rhs.m_pItem;
}
-
+
private:
- VmaRawList<T> *m_pList;
- VmaListItem<T> *m_pItem;
+ VmaRawList<T>* m_pList;
+ VmaListItem<T>* m_pItem;
- iterator(VmaRawList<T> *pList, VmaListItem<T> *pItem) :
- m_pList(pList),
- m_pItem(pItem) {
+ iterator(VmaRawList<T>* pList, VmaListItem<T>* pItem) :
+ m_pList(pList),
+ m_pItem(pItem)
+ {
}
friend class VmaList<T, AllocatorT>;
};
- class const_iterator {
+ class const_iterator
+ {
public:
const_iterator() :
- m_pList(VMA_NULL),
- m_pItem(VMA_NULL) {
+ m_pList(VMA_NULL),
+ m_pItem(VMA_NULL)
+ {
}
- const_iterator(const iterator &src) :
- m_pList(src.m_pList),
- m_pItem(src.m_pItem) {
+ const_iterator(const iterator& src) :
+ m_pList(src.m_pList),
+ m_pItem(src.m_pItem)
+ {
}
-
- const T &operator*() const {
+
+ const T& operator*() const
+ {
VMA_HEAVY_ASSERT(m_pItem != VMA_NULL);
return m_pItem->Value;
}
- const T *operator->() const {
+ const T* operator->() const
+ {
VMA_HEAVY_ASSERT(m_pItem != VMA_NULL);
return &m_pItem->Value;
}
- const_iterator &operator++() {
+ const_iterator& operator++()
+ {
VMA_HEAVY_ASSERT(m_pItem != VMA_NULL);
m_pItem = m_pItem->pNext;
return *this;
}
- const_iterator &operator--() {
- if (m_pItem != VMA_NULL) {
+ const_iterator& operator--()
+ {
+ if(m_pItem != VMA_NULL)
+ {
m_pItem = m_pItem->pPrev;
- } else {
+ }
+ else
+ {
VMA_HEAVY_ASSERT(!m_pList->IsEmpty());
m_pItem = m_pList->Back();
}
return *this;
}
- const_iterator operator++(int) {
+ const_iterator operator++(int)
+ {
const_iterator result = *this;
++*this;
return result;
}
- const_iterator operator--(int) {
+ const_iterator operator--(int)
+ {
const_iterator result = *this;
--*this;
return result;
}
- bool operator==(const const_iterator &rhs) const {
+ bool operator==(const const_iterator& rhs) const
+ {
VMA_HEAVY_ASSERT(m_pList == rhs.m_pList);
return m_pItem == rhs.m_pItem;
}
- bool operator!=(const const_iterator &rhs) const {
+ bool operator!=(const const_iterator& rhs) const
+ {
VMA_HEAVY_ASSERT(m_pList == rhs.m_pList);
return m_pItem != rhs.m_pItem;
}
-
+
private:
- const_iterator(const VmaRawList<T> *pList, const VmaListItem<T> *pItem) :
- m_pList(pList),
- m_pItem(pItem) {
+ const_iterator(const VmaRawList<T>* pList, const VmaListItem<T>* pItem) :
+ m_pList(pList),
+ m_pItem(pItem)
+ {
}
- const VmaRawList<T> *m_pList;
- const VmaListItem<T> *m_pItem;
+ const VmaRawList<T>* m_pList;
+ const VmaListItem<T>* m_pItem;
friend class VmaList<T, AllocatorT>;
};
- VmaList(const AllocatorT &allocator) :
- m_RawList(allocator.m_pCallbacks) {}
+ VmaList(const AllocatorT& allocator) : m_RawList(allocator.m_pCallbacks) { }
bool empty() const { return m_RawList.IsEmpty(); }
size_t size() const { return m_RawList.GetCount(); }
@@ -4661,9 +5318,9 @@ public:
const_iterator cend() const { return const_iterator(&m_RawList, VMA_NULL); }
void clear() { m_RawList.Clear(); }
- void push_back(const T &value) { m_RawList.PushBack(value); }
+ void push_back(const T& value) { m_RawList.PushBack(value); }
void erase(iterator it) { m_RawList.Remove(it.m_pItem); }
- iterator insert(iterator it, const T &value) { return iterator(&m_RawList, m_RawList.InsertBefore(it.m_pItem, value)); }
+ iterator insert(iterator it, const T& value) { return iterator(&m_RawList, m_RawList.InsertBefore(it.m_pItem, value)); }
private:
VmaRawList<T> m_RawList;
@@ -4682,18 +5339,18 @@ private:
#define VmaPair std::pair
#define VMA_MAP_TYPE(KeyT, ValueT) \
- std::unordered_map<KeyT, ValueT, std::hash<KeyT>, std::equal_to<KeyT>, VmaStlAllocator<std::pair<KeyT, ValueT> > >
+ std::unordered_map< KeyT, ValueT, std::hash<KeyT>, std::equal_to<KeyT>, VmaStlAllocator< std::pair<KeyT, ValueT> > >
#else // #if VMA_USE_STL_UNORDERED_MAP
template<typename T1, typename T2>
struct VmaPair
{
- T1 first;
- T2 second;
+ T1 first;
+ T2 second;
- VmaPair() : first(), second() { }
- VmaPair(const T1& firstSrc, const T2& secondSrc) : first(firstSrc), second(secondSrc) { }
+ VmaPair() : first(), second() { }
+ VmaPair(const T1& firstSrc, const T2& secondSrc) : first(firstSrc), second(secondSrc) { }
};
/* Class compatible with subset of interface of std::unordered_map.
@@ -4703,20 +5360,20 @@ template<typename KeyT, typename ValueT>
class VmaMap
{
public:
- typedef VmaPair<KeyT, ValueT> PairType;
- typedef PairType* iterator;
-
- VmaMap(const VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
+ typedef VmaPair<KeyT, ValueT> PairType;
+ typedef PairType* iterator;
- iterator begin() { return m_Vector.begin(); }
- iterator end() { return m_Vector.end(); }
+ VmaMap(const VmaStlAllocator<PairType>& allocator) : m_Vector(allocator) { }
- void insert(const PairType& pair);
- iterator find(const KeyT& key);
- void erase(iterator it);
+ iterator begin() { return m_Vector.begin(); }
+ iterator end() { return m_Vector.end(); }
+ void insert(const PairType& pair);
+ iterator find(const KeyT& key);
+ void erase(iterator it);
+
private:
- VmaVector< PairType, VmaStlAllocator<PairType> > m_Vector;
+ VmaVector< PairType, VmaStlAllocator<PairType> > m_Vector;
};
#define VMA_MAP_TYPE(KeyT, ValueT) VmaMap<KeyT, ValueT>
@@ -4724,49 +5381,49 @@ private:
template<typename FirstT, typename SecondT>
struct VmaPairFirstLess
{
- bool operator()(const VmaPair<FirstT, SecondT>& lhs, const VmaPair<FirstT, SecondT>& rhs) const
- {
- return lhs.first < rhs.first;
- }
- bool operator()(const VmaPair<FirstT, SecondT>& lhs, const FirstT& rhsFirst) const
- {
- return lhs.first < rhsFirst;
- }
+ bool operator()(const VmaPair<FirstT, SecondT>& lhs, const VmaPair<FirstT, SecondT>& rhs) const
+ {
+ return lhs.first < rhs.first;
+ }
+ bool operator()(const VmaPair<FirstT, SecondT>& lhs, const FirstT& rhsFirst) const
+ {
+ return lhs.first < rhsFirst;
+ }
};
template<typename KeyT, typename ValueT>
void VmaMap<KeyT, ValueT>::insert(const PairType& pair)
{
- const size_t indexToInsert = VmaBinaryFindFirstNotLess(
- m_Vector.data(),
- m_Vector.data() + m_Vector.size(),
- pair,
- VmaPairFirstLess<KeyT, ValueT>()) - m_Vector.data();
- VmaVectorInsert(m_Vector, indexToInsert, pair);
+ const size_t indexToInsert = VmaBinaryFindFirstNotLess(
+ m_Vector.data(),
+ m_Vector.data() + m_Vector.size(),
+ pair,
+ VmaPairFirstLess<KeyT, ValueT>()) - m_Vector.data();
+ VmaVectorInsert(m_Vector, indexToInsert, pair);
}
template<typename KeyT, typename ValueT>
VmaPair<KeyT, ValueT>* VmaMap<KeyT, ValueT>::find(const KeyT& key)
{
- PairType* it = VmaBinaryFindFirstNotLess(
- m_Vector.data(),
- m_Vector.data() + m_Vector.size(),
- key,
- VmaPairFirstLess<KeyT, ValueT>());
- if((it != m_Vector.end()) && (it->first == key))
- {
- return it;
- }
- else
- {
- return m_Vector.end();
- }
+ PairType* it = VmaBinaryFindFirstNotLess(
+ m_Vector.data(),
+ m_Vector.data() + m_Vector.size(),
+ key,
+ VmaPairFirstLess<KeyT, ValueT>());
+ if((it != m_Vector.end()) && (it->first == key))
+ {
+ return it;
+ }
+ else
+ {
+ return m_Vector.end();
+ }
}
template<typename KeyT, typename ValueT>
void VmaMap<KeyT, ValueT>::erase(iterator it)
{
- VmaVectorRemove(m_Vector, it - m_Vector.begin());
+ VmaVectorRemove(m_Vector, it - m_Vector.begin());
}
#endif // #if VMA_USE_STL_UNORDERED_MAP
@@ -4777,46 +5434,49 @@ void VmaMap<KeyT, ValueT>::erase(iterator it)
class VmaDeviceMemoryBlock;
-enum VMA_CACHE_OPERATION { VMA_CACHE_FLUSH,
- VMA_CACHE_INVALIDATE };
+enum VMA_CACHE_OPERATION { VMA_CACHE_FLUSH, VMA_CACHE_INVALIDATE };
-struct VmaAllocation_T {
+struct VmaAllocation_T
+{
private:
static const uint8_t MAP_COUNT_FLAG_PERSISTENT_MAP = 0x80;
- enum FLAGS {
+ enum FLAGS
+ {
FLAG_USER_DATA_STRING = 0x01,
};
public:
- enum ALLOCATION_TYPE {
+ enum ALLOCATION_TYPE
+ {
ALLOCATION_TYPE_NONE,
ALLOCATION_TYPE_BLOCK,
ALLOCATION_TYPE_DEDICATED,
};
/*
- This struct cannot have constructor or destructor. It must be POD because it is
- allocated using VmaPoolAllocator.
- */
-
- void Ctor(uint32_t currentFrameIndex, bool userDataString) {
- m_Alignment = 1;
- m_Size = 0;
- m_pUserData = VMA_NULL;
- m_LastUseFrameIndex = currentFrameIndex;
- m_Type = (uint8_t)ALLOCATION_TYPE_NONE;
- m_SuballocationType = (uint8_t)VMA_SUBALLOCATION_TYPE_UNKNOWN;
- m_MapCount = 0;
- m_Flags = userDataString ? (uint8_t)FLAG_USER_DATA_STRING : 0;
+ This struct is allocated using VmaPoolAllocator.
+ */
+ VmaAllocation_T(uint32_t currentFrameIndex, bool userDataString) :
+ m_Alignment{1},
+ m_Size{0},
+ m_pUserData{VMA_NULL},
+ m_LastUseFrameIndex{currentFrameIndex},
+ m_MemoryTypeIndex{0},
+ m_Type{(uint8_t)ALLOCATION_TYPE_NONE},
+ m_SuballocationType{(uint8_t)VMA_SUBALLOCATION_TYPE_UNKNOWN},
+ m_MapCount{0},
+ m_Flags{userDataString ? (uint8_t)FLAG_USER_DATA_STRING : (uint8_t)0}
+ {
#if VMA_STATS_STRING_ENABLED
m_CreationFrameIndex = currentFrameIndex;
m_BufferImageUsage = 0;
#endif
}
- void Dtor() {
+ ~VmaAllocation_T()
+ {
VMA_ASSERT((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) == 0 && "Allocation was not unmapped before destruction.");
// Check if owned string was freed.
@@ -4824,18 +5484,21 @@ public:
}
void InitBlockAllocation(
- VmaDeviceMemoryBlock *block,
- VkDeviceSize offset,
- VkDeviceSize alignment,
- VkDeviceSize size,
- VmaSuballocationType suballocationType,
- bool mapped,
- bool canBecomeLost) {
+ VmaDeviceMemoryBlock* block,
+ VkDeviceSize offset,
+ VkDeviceSize alignment,
+ VkDeviceSize size,
+ uint32_t memoryTypeIndex,
+ VmaSuballocationType suballocationType,
+ bool mapped,
+ bool canBecomeLost)
+ {
VMA_ASSERT(m_Type == ALLOCATION_TYPE_NONE);
VMA_ASSERT(block != VMA_NULL);
m_Type = (uint8_t)ALLOCATION_TYPE_BLOCK;
m_Alignment = alignment;
m_Size = size;
+ m_MemoryTypeIndex = memoryTypeIndex;
m_MapCount = mapped ? MAP_COUNT_FLAG_PERSISTENT_MAP : 0;
m_SuballocationType = (uint8_t)suballocationType;
m_BlockAllocation.m_Block = block;
@@ -4843,38 +5506,40 @@ public:
m_BlockAllocation.m_CanBecomeLost = canBecomeLost;
}
- void InitLost() {
+ void InitLost()
+ {
VMA_ASSERT(m_Type == ALLOCATION_TYPE_NONE);
VMA_ASSERT(m_LastUseFrameIndex.load() == VMA_FRAME_INDEX_LOST);
m_Type = (uint8_t)ALLOCATION_TYPE_BLOCK;
+ m_MemoryTypeIndex = 0;
m_BlockAllocation.m_Block = VMA_NULL;
m_BlockAllocation.m_Offset = 0;
m_BlockAllocation.m_CanBecomeLost = true;
}
void ChangeBlockAllocation(
- VmaAllocator hAllocator,
- VmaDeviceMemoryBlock *block,
- VkDeviceSize offset);
+ VmaAllocator hAllocator,
+ VmaDeviceMemoryBlock* block,
+ VkDeviceSize offset);
- void ChangeSize(VkDeviceSize newSize);
void ChangeOffset(VkDeviceSize newOffset);
// pMappedData not null means allocation is created with MAPPED flag.
void InitDedicatedAllocation(
- uint32_t memoryTypeIndex,
- VkDeviceMemory hMemory,
- VmaSuballocationType suballocationType,
- void *pMappedData,
- VkDeviceSize size) {
+ uint32_t memoryTypeIndex,
+ VkDeviceMemory hMemory,
+ VmaSuballocationType suballocationType,
+ void* pMappedData,
+ VkDeviceSize size)
+ {
VMA_ASSERT(m_Type == ALLOCATION_TYPE_NONE);
VMA_ASSERT(hMemory != VK_NULL_HANDLE);
m_Type = (uint8_t)ALLOCATION_TYPE_DEDICATED;
m_Alignment = 0;
m_Size = size;
+ m_MemoryTypeIndex = memoryTypeIndex;
m_SuballocationType = (uint8_t)suballocationType;
m_MapCount = (pMappedData != VMA_NULL) ? MAP_COUNT_FLAG_PERSISTENT_MAP : 0;
- m_DedicatedAllocation.m_MemoryTypeIndex = memoryTypeIndex;
m_DedicatedAllocation.m_hMemory = hMemory;
m_DedicatedAllocation.m_pMappedData = pMappedData;
}
@@ -4883,38 +5548,42 @@ public:
VkDeviceSize GetAlignment() const { return m_Alignment; }
VkDeviceSize GetSize() const { return m_Size; }
bool IsUserDataString() const { return (m_Flags & FLAG_USER_DATA_STRING) != 0; }
- void *GetUserData() const { return m_pUserData; }
- void SetUserData(VmaAllocator hAllocator, void *pUserData);
+ void* GetUserData() const { return m_pUserData; }
+ void SetUserData(VmaAllocator hAllocator, void* pUserData);
VmaSuballocationType GetSuballocationType() const { return (VmaSuballocationType)m_SuballocationType; }
- VmaDeviceMemoryBlock *GetBlock() const {
+ VmaDeviceMemoryBlock* GetBlock() const
+ {
VMA_ASSERT(m_Type == ALLOCATION_TYPE_BLOCK);
return m_BlockAllocation.m_Block;
}
VkDeviceSize GetOffset() const;
VkDeviceMemory GetMemory() const;
- uint32_t GetMemoryTypeIndex() const;
+ uint32_t GetMemoryTypeIndex() const { return m_MemoryTypeIndex; }
bool IsPersistentMap() const { return (m_MapCount & MAP_COUNT_FLAG_PERSISTENT_MAP) != 0; }
- void *GetMappedData() const;
+ void* GetMappedData() const;
bool CanBecomeLost() const;
-
- uint32_t GetLastUseFrameIndex() const {
+
+ uint32_t GetLastUseFrameIndex() const
+ {
return m_LastUseFrameIndex.load();
}
- bool CompareExchangeLastUseFrameIndex(uint32_t &expected, uint32_t desired) {
+ bool CompareExchangeLastUseFrameIndex(uint32_t& expected, uint32_t desired)
+ {
return m_LastUseFrameIndex.compare_exchange_weak(expected, desired);
}
/*
- - If hAllocation.LastUseFrameIndex + frameInUseCount < allocator.CurrentFrameIndex,
- makes it lost by setting LastUseFrameIndex = VMA_FRAME_INDEX_LOST and returns true.
- - Else, returns false.
-
- If hAllocation is already lost, assert - you should not call it then.
- If hAllocation was not created with CAN_BECOME_LOST_BIT, assert.
- */
+ - If hAllocation.LastUseFrameIndex + frameInUseCount < allocator.CurrentFrameIndex,
+ makes it lost by setting LastUseFrameIndex = VMA_FRAME_INDEX_LOST and returns true.
+ - Else, returns false.
+
+ If hAllocation is already lost, assert - you should not call it then.
+ If hAllocation was not created with CAN_BECOME_LOST_BIT, assert.
+ */
bool MakeLost(uint32_t currentFrameIndex, uint32_t frameInUseCount);
- void DedicatedAllocCalcStatsInfo(VmaStatInfo &outInfo) {
+ void DedicatedAllocCalcStatsInfo(VmaStatInfo& outInfo)
+ {
VMA_ASSERT(m_Type == ALLOCATION_TYPE_DEDICATED);
outInfo.blockCount = 1;
outInfo.allocationCount = 1;
@@ -4928,26 +5597,28 @@ public:
void BlockAllocMap();
void BlockAllocUnmap();
- VkResult DedicatedAllocMap(VmaAllocator hAllocator, void **ppData);
+ VkResult DedicatedAllocMap(VmaAllocator hAllocator, void** ppData);
void DedicatedAllocUnmap(VmaAllocator hAllocator);
#if VMA_STATS_STRING_ENABLED
uint32_t GetCreationFrameIndex() const { return m_CreationFrameIndex; }
uint32_t GetBufferImageUsage() const { return m_BufferImageUsage; }
- void InitBufferImageUsage(uint32_t bufferImageUsage) {
+ void InitBufferImageUsage(uint32_t bufferImageUsage)
+ {
VMA_ASSERT(m_BufferImageUsage == 0);
m_BufferImageUsage = bufferImageUsage;
}
- void PrintParameters(class VmaJsonWriter &json) const;
+ void PrintParameters(class VmaJsonWriter& json) const;
#endif
private:
VkDeviceSize m_Alignment;
VkDeviceSize m_Size;
- void *m_pUserData;
+ void* m_pUserData;
VMA_ATOMIC_UINT32 m_LastUseFrameIndex;
+ uint32_t m_MemoryTypeIndex;
uint8_t m_Type; // ALLOCATION_TYPE
uint8_t m_SuballocationType; // VmaSuballocationType
// Bit 0x80 is set when allocation was created with VMA_ALLOCATION_CREATE_MAPPED_BIT.
@@ -4956,20 +5627,22 @@ private:
uint8_t m_Flags; // enum FLAGS
// Allocation out of VmaDeviceMemoryBlock.
- struct BlockAllocation {
- VmaDeviceMemoryBlock *m_Block;
+ struct BlockAllocation
+ {
+ VmaDeviceMemoryBlock* m_Block;
VkDeviceSize m_Offset;
bool m_CanBecomeLost;
};
// Allocation for an object that has its own private VkDeviceMemory.
- struct DedicatedAllocation {
- uint32_t m_MemoryTypeIndex;
+ struct DedicatedAllocation
+ {
VkDeviceMemory m_hMemory;
- void *m_pMappedData; // Not null means memory is mapped.
+ void* m_pMappedData; // Not null means memory is mapped.
};
- union {
+ union
+ {
// Allocation out of VmaDeviceMemoryBlock.
BlockAllocation m_BlockAllocation;
// Allocation for an object that has its own private VkDeviceMemory.
@@ -4988,7 +5661,8 @@ private:
Represents a region of VmaDeviceMemoryBlock that is either assigned and returned as
allocated memory block or free.
*/
-struct VmaSuballocation {
+struct VmaSuballocation
+{
VkDeviceSize offset;
VkDeviceSize size;
VmaAllocation hAllocation;
@@ -4996,23 +5670,28 @@ struct VmaSuballocation {
};
// Comparator for offsets.
-struct VmaSuballocationOffsetLess {
- bool operator()(const VmaSuballocation &lhs, const VmaSuballocation &rhs) const {
+struct VmaSuballocationOffsetLess
+{
+ bool operator()(const VmaSuballocation& lhs, const VmaSuballocation& rhs) const
+ {
return lhs.offset < rhs.offset;
}
};
-struct VmaSuballocationOffsetGreater {
- bool operator()(const VmaSuballocation &lhs, const VmaSuballocation &rhs) const {
+struct VmaSuballocationOffsetGreater
+{
+ bool operator()(const VmaSuballocation& lhs, const VmaSuballocation& rhs) const
+ {
return lhs.offset > rhs.offset;
}
};
-typedef VmaList<VmaSuballocation, VmaStlAllocator<VmaSuballocation> > VmaSuballocationList;
+typedef VmaList< VmaSuballocation, VmaStlAllocator<VmaSuballocation> > VmaSuballocationList;
// Cost of one additional allocation lost, as equivalent in bytes.
static const VkDeviceSize VMA_LOST_ALLOCATION_COST = 1048576;
-enum class VmaAllocationRequestType {
+enum class VmaAllocationRequestType
+{
Normal,
// Used by "Linear" algorithm.
UpperAddress,
@@ -5033,16 +5712,18 @@ If canMakeOtherLost was true:
- itemsToMakeLostCount is the number of VmaAllocations that need to be made lost for
the requested allocation to succeed.
*/
-struct VmaAllocationRequest {
+struct VmaAllocationRequest
+{
VkDeviceSize offset;
VkDeviceSize sumFreeSize; // Sum size of free items that overlap with proposed allocation.
VkDeviceSize sumItemSize; // Sum size of items to make lost that overlap with proposed allocation.
VmaSuballocationList::iterator item;
size_t itemsToMakeLostCount;
- void *customData;
+ void* customData;
VmaAllocationRequestType type;
- VkDeviceSize CalcCost() const {
+ VkDeviceSize CalcCost() const
+ {
return sumItemSize + itemsToMakeLostCount * VMA_LOST_ALLOCATION_COST;
}
};
@@ -5051,10 +5732,11 @@ struct VmaAllocationRequest {
Data structure used for bookkeeping of allocations and unused ranges of memory
in a single VkDeviceMemory block.
*/
-class VmaBlockMetadata {
+class VmaBlockMetadata
+{
public:
VmaBlockMetadata(VmaAllocator hAllocator);
- virtual ~VmaBlockMetadata() {}
+ virtual ~VmaBlockMetadata() { }
virtual void Init(VkDeviceSize size) { m_Size = size; }
// Validates all data structures inside this object. If not valid, returns false.
@@ -5066,84 +5748,79 @@ public:
// Returns true if this block is empty - contains only single free suballocation.
virtual bool IsEmpty() const = 0;
- virtual void CalcAllocationStatInfo(VmaStatInfo &outInfo) const = 0;
+ virtual void CalcAllocationStatInfo(VmaStatInfo& outInfo) const = 0;
// Shouldn't modify blockCount.
- virtual void AddPoolStats(VmaPoolStats &inoutStats) const = 0;
+ virtual void AddPoolStats(VmaPoolStats& inoutStats) const = 0;
#if VMA_STATS_STRING_ENABLED
- virtual void PrintDetailedMap(class VmaJsonWriter &json) const = 0;
+ virtual void PrintDetailedMap(class VmaJsonWriter& json) const = 0;
#endif
// Tries to find a place for suballocation with given parameters inside this block.
// If succeeded, fills pAllocationRequest and returns true.
// If failed, returns false.
virtual bool CreateAllocationRequest(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- bool upperAddress,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- // Always one of VMA_ALLOCATION_CREATE_STRATEGY_* or VMA_ALLOCATION_INTERNAL_STRATEGY_* flags.
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest) = 0;
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ bool upperAddress,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ // Always one of VMA_ALLOCATION_CREATE_STRATEGY_* or VMA_ALLOCATION_INTERNAL_STRATEGY_* flags.
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest) = 0;
virtual bool MakeRequestedAllocationsLost(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VmaAllocationRequest *pAllocationRequest) = 0;
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VmaAllocationRequest* pAllocationRequest) = 0;
virtual uint32_t MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount) = 0;
- virtual VkResult CheckCorruption(const void *pBlockData) = 0;
+ virtual VkResult CheckCorruption(const void* pBlockData) = 0;
// Makes actual allocation based on request. Request must already be checked and valid.
virtual void Alloc(
- const VmaAllocationRequest &request,
- VmaSuballocationType type,
- VkDeviceSize allocSize,
- VmaAllocation hAllocation) = 0;
+ const VmaAllocationRequest& request,
+ VmaSuballocationType type,
+ VkDeviceSize allocSize,
+ VmaAllocation hAllocation) = 0;
// Frees suballocation assigned to given memory region.
virtual void Free(const VmaAllocation allocation) = 0;
virtual void FreeAtOffset(VkDeviceSize offset) = 0;
- // Tries to resize (grow or shrink) space for given allocation, in place.
- virtual bool ResizeAllocation(const VmaAllocation alloc, VkDeviceSize newSize) { return false; }
-
protected:
- const VkAllocationCallbacks *GetAllocationCallbacks() const { return m_pAllocationCallbacks; }
+ const VkAllocationCallbacks* GetAllocationCallbacks() const { return m_pAllocationCallbacks; }
#if VMA_STATS_STRING_ENABLED
- void PrintDetailedMap_Begin(class VmaJsonWriter &json,
- VkDeviceSize unusedBytes,
- size_t allocationCount,
- size_t unusedRangeCount) const;
- void PrintDetailedMap_Allocation(class VmaJsonWriter &json,
- VkDeviceSize offset,
- VmaAllocation hAllocation) const;
- void PrintDetailedMap_UnusedRange(class VmaJsonWriter &json,
- VkDeviceSize offset,
- VkDeviceSize size) const;
- void PrintDetailedMap_End(class VmaJsonWriter &json) const;
+ void PrintDetailedMap_Begin(class VmaJsonWriter& json,
+ VkDeviceSize unusedBytes,
+ size_t allocationCount,
+ size_t unusedRangeCount) const;
+ void PrintDetailedMap_Allocation(class VmaJsonWriter& json,
+ VkDeviceSize offset,
+ VmaAllocation hAllocation) const;
+ void PrintDetailedMap_UnusedRange(class VmaJsonWriter& json,
+ VkDeviceSize offset,
+ VkDeviceSize size) const;
+ void PrintDetailedMap_End(class VmaJsonWriter& json) const;
#endif
private:
VkDeviceSize m_Size;
- const VkAllocationCallbacks *m_pAllocationCallbacks;
+ const VkAllocationCallbacks* m_pAllocationCallbacks;
};
-#define VMA_VALIDATE(cond) \
- do { \
- if (!(cond)) { \
- VMA_ASSERT(0 && "Validation failed: " #cond); \
- return false; \
- } \
- } while (false)
+#define VMA_VALIDATE(cond) do { if(!(cond)) { \
+ VMA_ASSERT(0 && "Validation failed: " #cond); \
+ return false; \
+ } } while(false)
-class VmaBlockMetadata_Generic : public VmaBlockMetadata {
+class VmaBlockMetadata_Generic : public VmaBlockMetadata
+{
VMA_CLASS_NO_COPY(VmaBlockMetadata_Generic)
public:
VmaBlockMetadata_Generic(VmaAllocator hAllocator);
@@ -5156,51 +5833,49 @@ public:
virtual VkDeviceSize GetUnusedRangeSizeMax() const;
virtual bool IsEmpty() const;
- virtual void CalcAllocationStatInfo(VmaStatInfo &outInfo) const;
- virtual void AddPoolStats(VmaPoolStats &inoutStats) const;
+ virtual void CalcAllocationStatInfo(VmaStatInfo& outInfo) const;
+ virtual void AddPoolStats(VmaPoolStats& inoutStats) const;
#if VMA_STATS_STRING_ENABLED
- virtual void PrintDetailedMap(class VmaJsonWriter &json) const;
+ virtual void PrintDetailedMap(class VmaJsonWriter& json) const;
#endif
virtual bool CreateAllocationRequest(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- bool upperAddress,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest);
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ bool upperAddress,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest);
virtual bool MakeRequestedAllocationsLost(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VmaAllocationRequest *pAllocationRequest);
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VmaAllocationRequest* pAllocationRequest);
virtual uint32_t MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount);
- virtual VkResult CheckCorruption(const void *pBlockData);
+ virtual VkResult CheckCorruption(const void* pBlockData);
virtual void Alloc(
- const VmaAllocationRequest &request,
- VmaSuballocationType type,
- VkDeviceSize allocSize,
- VmaAllocation hAllocation);
+ const VmaAllocationRequest& request,
+ VmaSuballocationType type,
+ VkDeviceSize allocSize,
+ VmaAllocation hAllocation);
virtual void Free(const VmaAllocation allocation);
virtual void FreeAtOffset(VkDeviceSize offset);
- virtual bool ResizeAllocation(const VmaAllocation alloc, VkDeviceSize newSize);
-
////////////////////////////////////////////////////////////////////////////////
// For defragmentation
-
+
bool IsBufferImageGranularityConflictPossible(
- VkDeviceSize bufferImageGranularity,
- VmaSuballocationType &inOutPrevSuballocType) const;
+ VkDeviceSize bufferImageGranularity,
+ VmaSuballocationType& inOutPrevSuballocType) const;
private:
friend class VmaDefragmentationAlgorithm_Generic;
@@ -5211,25 +5886,25 @@ private:
VmaSuballocationList m_Suballocations;
// Suballocations that are free and have size greater than certain threshold.
// Sorted by size, ascending.
- VmaVector<VmaSuballocationList::iterator, VmaStlAllocator<VmaSuballocationList::iterator> > m_FreeSuballocationsBySize;
+ VmaVector< VmaSuballocationList::iterator, VmaStlAllocator< VmaSuballocationList::iterator > > m_FreeSuballocationsBySize;
bool ValidateFreeSuballocationList() const;
// Checks if requested suballocation with given parameters can be placed in given pFreeSuballocItem.
// If yes, fills pOffset and returns true. If no, returns false.
bool CheckAllocation(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- VmaSuballocationType allocType,
- VmaSuballocationList::const_iterator suballocItem,
- bool canMakeOtherLost,
- VkDeviceSize *pOffset,
- size_t *itemsToMakeLostCount,
- VkDeviceSize *pSumFreeSize,
- VkDeviceSize *pSumItemSize) const;
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ VmaSuballocationType allocType,
+ VmaSuballocationList::const_iterator suballocItem,
+ bool canMakeOtherLost,
+ VkDeviceSize* pOffset,
+ size_t* itemsToMakeLostCount,
+ VkDeviceSize* pSumFreeSize,
+ VkDeviceSize* pSumItemSize) const;
// Given free suballocation, it merges it with following one, which must also be free.
void MergeFreeWithNext(VmaSuballocationList::iterator item);
// Releases given suballocation, making it free.
@@ -5249,80 +5924,81 @@ Allocations and their references in internal data structure look like this:
if(m_2ndVectorMode == SECOND_VECTOR_EMPTY):
- 0 +-------+
- | |
- | |
- | |
- +-------+
- | Alloc | 1st[m_1stNullItemsBeginCount]
- +-------+
- | Alloc | 1st[m_1stNullItemsBeginCount + 1]
- +-------+
- | ... |
- +-------+
- | Alloc | 1st[1st.size() - 1]
- +-------+
- | |
- | |
- | |
+ 0 +-------+
+ | |
+ | |
+ | |
+ +-------+
+ | Alloc | 1st[m_1stNullItemsBeginCount]
+ +-------+
+ | Alloc | 1st[m_1stNullItemsBeginCount + 1]
+ +-------+
+ | ... |
+ +-------+
+ | Alloc | 1st[1st.size() - 1]
+ +-------+
+ | |
+ | |
+ | |
GetSize() +-------+
if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER):
- 0 +-------+
- | Alloc | 2nd[0]
- +-------+
- | Alloc | 2nd[1]
- +-------+
- | ... |
- +-------+
- | Alloc | 2nd[2nd.size() - 1]
- +-------+
- | |
- | |
- | |
- +-------+
- | Alloc | 1st[m_1stNullItemsBeginCount]
- +-------+
- | Alloc | 1st[m_1stNullItemsBeginCount + 1]
- +-------+
- | ... |
- +-------+
- | Alloc | 1st[1st.size() - 1]
- +-------+
- | |
+ 0 +-------+
+ | Alloc | 2nd[0]
+ +-------+
+ | Alloc | 2nd[1]
+ +-------+
+ | ... |
+ +-------+
+ | Alloc | 2nd[2nd.size() - 1]
+ +-------+
+ | |
+ | |
+ | |
+ +-------+
+ | Alloc | 1st[m_1stNullItemsBeginCount]
+ +-------+
+ | Alloc | 1st[m_1stNullItemsBeginCount + 1]
+ +-------+
+ | ... |
+ +-------+
+ | Alloc | 1st[1st.size() - 1]
+ +-------+
+ | |
GetSize() +-------+
if(m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK):
- 0 +-------+
- | |
- | |
- | |
- +-------+
- | Alloc | 1st[m_1stNullItemsBeginCount]
- +-------+
- | Alloc | 1st[m_1stNullItemsBeginCount + 1]
- +-------+
- | ... |
- +-------+
- | Alloc | 1st[1st.size() - 1]
- +-------+
- | |
- | |
- | |
- +-------+
- | Alloc | 2nd[2nd.size() - 1]
- +-------+
- | ... |
- +-------+
- | Alloc | 2nd[1]
- +-------+
- | Alloc | 2nd[0]
+ 0 +-------+
+ | |
+ | |
+ | |
+ +-------+
+ | Alloc | 1st[m_1stNullItemsBeginCount]
+ +-------+
+ | Alloc | 1st[m_1stNullItemsBeginCount + 1]
+ +-------+
+ | ... |
+ +-------+
+ | Alloc | 1st[1st.size() - 1]
+ +-------+
+ | |
+ | |
+ | |
+ +-------+
+ | Alloc | 2nd[2nd.size() - 1]
+ +-------+
+ | ... |
+ +-------+
+ | Alloc | 2nd[1]
+ +-------+
+ | Alloc | 2nd[0]
GetSize() +-------+
*/
-class VmaBlockMetadata_Linear : public VmaBlockMetadata {
+class VmaBlockMetadata_Linear : public VmaBlockMetadata
+{
VMA_CLASS_NO_COPY(VmaBlockMetadata_Linear)
public:
VmaBlockMetadata_Linear(VmaAllocator hAllocator);
@@ -5335,65 +6011,66 @@ public:
virtual VkDeviceSize GetUnusedRangeSizeMax() const;
virtual bool IsEmpty() const { return GetAllocationCount() == 0; }
- virtual void CalcAllocationStatInfo(VmaStatInfo &outInfo) const;
- virtual void AddPoolStats(VmaPoolStats &inoutStats) const;
+ virtual void CalcAllocationStatInfo(VmaStatInfo& outInfo) const;
+ virtual void AddPoolStats(VmaPoolStats& inoutStats) const;
#if VMA_STATS_STRING_ENABLED
- virtual void PrintDetailedMap(class VmaJsonWriter &json) const;
+ virtual void PrintDetailedMap(class VmaJsonWriter& json) const;
#endif
virtual bool CreateAllocationRequest(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- bool upperAddress,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest);
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ bool upperAddress,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest);
virtual bool MakeRequestedAllocationsLost(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VmaAllocationRequest *pAllocationRequest);
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VmaAllocationRequest* pAllocationRequest);
virtual uint32_t MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount);
- virtual VkResult CheckCorruption(const void *pBlockData);
+ virtual VkResult CheckCorruption(const void* pBlockData);
virtual void Alloc(
- const VmaAllocationRequest &request,
- VmaSuballocationType type,
- VkDeviceSize allocSize,
- VmaAllocation hAllocation);
+ const VmaAllocationRequest& request,
+ VmaSuballocationType type,
+ VkDeviceSize allocSize,
+ VmaAllocation hAllocation);
virtual void Free(const VmaAllocation allocation);
virtual void FreeAtOffset(VkDeviceSize offset);
private:
/*
- There are two suballocation vectors, used in ping-pong way.
- The one with index m_1stVectorIndex is called 1st.
- The one with index (m_1stVectorIndex ^ 1) is called 2nd.
- 2nd can be non-empty only when 1st is not empty.
- When 2nd is not empty, m_2ndVectorMode indicates its mode of operation.
- */
- typedef VmaVector<VmaSuballocation, VmaStlAllocator<VmaSuballocation> > SuballocationVectorType;
-
- enum SECOND_VECTOR_MODE {
+ There are two suballocation vectors, used in ping-pong way.
+ The one with index m_1stVectorIndex is called 1st.
+ The one with index (m_1stVectorIndex ^ 1) is called 2nd.
+ 2nd can be non-empty only when 1st is not empty.
+ When 2nd is not empty, m_2ndVectorMode indicates its mode of operation.
+ */
+ typedef VmaVector< VmaSuballocation, VmaStlAllocator<VmaSuballocation> > SuballocationVectorType;
+
+ enum SECOND_VECTOR_MODE
+ {
SECOND_VECTOR_EMPTY,
/*
- Suballocations in 2nd vector are created later than the ones in 1st, but they
- all have smaller offset.
- */
+ Suballocations in 2nd vector are created later than the ones in 1st, but they
+ all have smaller offset.
+ */
SECOND_VECTOR_RING_BUFFER,
/*
- Suballocations in 2nd vector are upper side of double stack.
- They all have offsets higher than those in 1st vector.
- Top of this stack means smaller offsets, but higher indices in this vector.
- */
+ Suballocations in 2nd vector are upper side of double stack.
+ They all have offsets higher than those in 1st vector.
+ Top of this stack means smaller offsets, but higher indices in this vector.
+ */
SECOND_VECTOR_DOUBLE_STACK,
};
@@ -5402,11 +6079,11 @@ private:
uint32_t m_1stVectorIndex;
SECOND_VECTOR_MODE m_2ndVectorMode;
- SuballocationVectorType &AccessSuballocations1st() { return m_1stVectorIndex ? m_Suballocations1 : m_Suballocations0; }
- SuballocationVectorType &AccessSuballocations2nd() { return m_1stVectorIndex ? m_Suballocations0 : m_Suballocations1; }
- const SuballocationVectorType &AccessSuballocations1st() const { return m_1stVectorIndex ? m_Suballocations1 : m_Suballocations0; }
- const SuballocationVectorType &AccessSuballocations2nd() const { return m_1stVectorIndex ? m_Suballocations0 : m_Suballocations1; }
-
+ SuballocationVectorType& AccessSuballocations1st() { return m_1stVectorIndex ? m_Suballocations1 : m_Suballocations0; }
+ SuballocationVectorType& AccessSuballocations2nd() { return m_1stVectorIndex ? m_Suballocations0 : m_Suballocations1; }
+ const SuballocationVectorType& AccessSuballocations1st() const { return m_1stVectorIndex ? m_Suballocations1 : m_Suballocations0; }
+ const SuballocationVectorType& AccessSuballocations2nd() const { return m_1stVectorIndex ? m_Suballocations0 : m_Suballocations1; }
+
// Number of items in 1st vector with hAllocation = null at the beginning.
size_t m_1stNullItemsBeginCount;
// Number of other items in 1st vector with hAllocation = null somewhere in the middle.
@@ -5418,25 +6095,25 @@ private:
void CleanupAfterFree();
bool CreateAllocationRequest_LowerAddress(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest);
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest);
bool CreateAllocationRequest_UpperAddress(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest);
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest);
};
/*
@@ -5450,7 +6127,8 @@ Node at level 0 has size = m_UsableSize.
Each next level contains nodes with size 2 times smaller than current level.
m_LevelCount is the maximum number of levels to use in the current object.
*/
-class VmaBlockMetadata_Buddy : public VmaBlockMetadata {
+class VmaBlockMetadata_Buddy : public VmaBlockMetadata
+{
VMA_CLASS_NO_COPY(VmaBlockMetadata_Buddy)
public:
VmaBlockMetadata_Buddy(VmaAllocator hAllocator);
@@ -5463,39 +6141,39 @@ public:
virtual VkDeviceSize GetUnusedRangeSizeMax() const;
virtual bool IsEmpty() const { return m_Root->type == Node::TYPE_FREE; }
- virtual void CalcAllocationStatInfo(VmaStatInfo &outInfo) const;
- virtual void AddPoolStats(VmaPoolStats &inoutStats) const;
+ virtual void CalcAllocationStatInfo(VmaStatInfo& outInfo) const;
+ virtual void AddPoolStats(VmaPoolStats& inoutStats) const;
#if VMA_STATS_STRING_ENABLED
- virtual void PrintDetailedMap(class VmaJsonWriter &json) const;
+ virtual void PrintDetailedMap(class VmaJsonWriter& json) const;
#endif
virtual bool CreateAllocationRequest(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- bool upperAddress,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest);
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ bool upperAddress,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest);
virtual bool MakeRequestedAllocationsLost(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VmaAllocationRequest *pAllocationRequest);
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VmaAllocationRequest* pAllocationRequest);
virtual uint32_t MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount);
- virtual VkResult CheckCorruption(const void *pBlockData) { return VK_ERROR_FEATURE_NOT_PRESENT; }
+ virtual VkResult CheckCorruption(const void* pBlockData) { return VK_ERROR_FEATURE_NOT_PRESENT; }
virtual void Alloc(
- const VmaAllocationRequest &request,
- VmaSuballocationType type,
- VkDeviceSize allocSize,
- VmaAllocation hAllocation);
+ const VmaAllocationRequest& request,
+ VmaSuballocationType type,
+ VkDeviceSize allocSize,
+ VmaAllocation hAllocation);
virtual void Free(const VmaAllocation allocation) { FreeAtOffset(allocation, allocation->GetOffset()); }
virtual void FreeAtOffset(VkDeviceSize offset) { FreeAtOffset(VMA_NULL, offset); }
@@ -5504,33 +6182,37 @@ private:
static const VkDeviceSize MIN_NODE_SIZE = 32;
static const size_t MAX_LEVELS = 30;
- struct ValidationContext {
+ struct ValidationContext
+ {
size_t calculatedAllocationCount;
size_t calculatedFreeCount;
VkDeviceSize calculatedSumFreeSize;
ValidationContext() :
- calculatedAllocationCount(0),
- calculatedFreeCount(0),
- calculatedSumFreeSize(0) {}
+ calculatedAllocationCount(0),
+ calculatedFreeCount(0),
+ calculatedSumFreeSize(0) { }
};
- struct Node {
+ struct Node
+ {
VkDeviceSize offset;
- enum TYPE {
+ enum TYPE
+ {
TYPE_FREE,
TYPE_ALLOCATION,
TYPE_SPLIT,
TYPE_COUNT
} type;
- Node *parent;
- Node *buddy;
+ Node* parent;
+ Node* buddy;
- union {
+ union
+ {
struct
{
- Node *prev;
- Node *next;
+ Node* prev;
+ Node* next;
} free;
struct
{
@@ -5538,7 +6220,7 @@ private:
} allocation;
struct
{
- Node *leftChild;
+ Node* leftChild;
} split;
};
};
@@ -5547,10 +6229,10 @@ private:
VkDeviceSize m_UsableSize;
uint32_t m_LevelCount;
- Node *m_Root;
+ Node* m_Root;
struct {
- Node *front;
- Node *back;
+ Node* front;
+ Node* back;
} m_FreeList[MAX_LEVELS];
// Number of nodes in the tree with type == TYPE_ALLOCATION.
size_t m_AllocationCount;
@@ -5560,24 +6242,24 @@ private:
VkDeviceSize m_SumFreeSize;
VkDeviceSize GetUnusableSize() const { return GetSize() - m_UsableSize; }
- void DeleteNode(Node *node);
- bool ValidateNode(ValidationContext &ctx, const Node *parent, const Node *curr, uint32_t level, VkDeviceSize levelNodeSize) const;
+ void DeleteNode(Node* node);
+ bool ValidateNode(ValidationContext& ctx, const Node* parent, const Node* curr, uint32_t level, VkDeviceSize levelNodeSize) const;
uint32_t AllocSizeToLevel(VkDeviceSize allocSize) const;
inline VkDeviceSize LevelToNodeSize(uint32_t level) const { return m_UsableSize >> level; }
// Alloc passed just for validation. Can be null.
void FreeAtOffset(VmaAllocation alloc, VkDeviceSize offset);
- void CalcAllocationStatInfoNode(VmaStatInfo &outInfo, const Node *node, VkDeviceSize levelNodeSize) const;
+ void CalcAllocationStatInfoNode(VmaStatInfo& outInfo, const Node* node, VkDeviceSize levelNodeSize) const;
// Adds node to the front of FreeList at given level.
// node->type must be FREE.
// node->free.prev, next can be undefined.
- void AddToFreeListFront(uint32_t level, Node *node);
+ void AddToFreeListFront(uint32_t level, Node* node);
// Removes node from FreeList at given level.
// node->type must be FREE.
// node->free.prev, next stay untouched.
- void RemoveFromFreeList(uint32_t level, Node *node);
+ void RemoveFromFreeList(uint32_t level, Node* node);
#if VMA_STATS_STRING_ENABLED
- void PrintDetailedMapNode(class VmaJsonWriter &json, const Node *node, VkDeviceSize levelNodeSize) const;
+ void PrintDetailedMapNode(class VmaJsonWriter& json, const Node* node, VkDeviceSize levelNodeSize) const;
#endif
};
@@ -5587,35 +6269,37 @@ data about its regions (aka suballocations, #VmaAllocation), assigned and free.
Thread-safety: This class must be externally synchronized.
*/
-class VmaDeviceMemoryBlock {
+class VmaDeviceMemoryBlock
+{
VMA_CLASS_NO_COPY(VmaDeviceMemoryBlock)
public:
- VmaBlockMetadata *m_pMetadata;
+ VmaBlockMetadata* m_pMetadata;
VmaDeviceMemoryBlock(VmaAllocator hAllocator);
- ~VmaDeviceMemoryBlock() {
+ ~VmaDeviceMemoryBlock()
+ {
VMA_ASSERT(m_MapCount == 0 && "VkDeviceMemory block is being destroyed while it is still mapped.");
VMA_ASSERT(m_hMemory == VK_NULL_HANDLE);
}
// Always call after construction.
void Init(
- VmaAllocator hAllocator,
- VmaPool hParentPool,
- uint32_t newMemoryTypeIndex,
- VkDeviceMemory newMemory,
- VkDeviceSize newSize,
- uint32_t id,
- uint32_t algorithm);
+ VmaAllocator hAllocator,
+ VmaPool hParentPool,
+ uint32_t newMemoryTypeIndex,
+ VkDeviceMemory newMemory,
+ VkDeviceSize newSize,
+ uint32_t id,
+ uint32_t algorithm);
// Always call before destruction.
void Destroy(VmaAllocator allocator);
-
+
VmaPool GetParentPool() const { return m_hParentPool; }
VkDeviceMemory GetDeviceMemory() const { return m_hMemory; }
uint32_t GetMemoryTypeIndex() const { return m_MemoryTypeIndex; }
uint32_t GetId() const { return m_Id; }
- void *GetMappedData() const { return m_pMappedData; }
+ void* GetMappedData() const { return m_pMappedData; }
// Validates all data structures inside this object. If not valid, returns false.
bool Validate() const;
@@ -5623,20 +6307,24 @@ public:
VkResult CheckCorruption(VmaAllocator hAllocator);
// ppData can be null.
- VkResult Map(VmaAllocator hAllocator, uint32_t count, void **ppData);
+ VkResult Map(VmaAllocator hAllocator, uint32_t count, void** ppData);
void Unmap(VmaAllocator hAllocator, uint32_t count);
VkResult WriteMagicValueAroundAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize);
VkResult ValidateMagicValueAroundAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize);
VkResult BindBufferMemory(
- const VmaAllocator hAllocator,
- const VmaAllocation hAllocation,
- VkBuffer hBuffer);
+ const VmaAllocator hAllocator,
+ const VmaAllocation hAllocation,
+ VkDeviceSize allocationLocalOffset,
+ VkBuffer hBuffer,
+ const void* pNext);
VkResult BindImageMemory(
- const VmaAllocator hAllocator,
- const VmaAllocation hAllocation,
- VkImage hImage);
+ const VmaAllocator hAllocator,
+ const VmaAllocation hAllocation,
+ VkDeviceSize allocationLocalOffset,
+ VkImage hImage,
+ const void* pNext);
private:
VmaPool m_hParentPool; // VK_NULL_HANDLE if not belongs to custom pool.
@@ -5645,27 +6333,33 @@ private:
VkDeviceMemory m_hMemory;
/*
- Protects access to m_hMemory so it's not used by multiple threads simultaneously, e.g. vkMapMemory, vkBindBufferMemory.
- Also protects m_MapCount, m_pMappedData.
- Allocations, deallocations, any change in m_pMetadata is protected by parent's VmaBlockVector::m_Mutex.
- */
+ Protects access to m_hMemory so it's not used by multiple threads simultaneously, e.g. vkMapMemory, vkBindBufferMemory.
+ Also protects m_MapCount, m_pMappedData.
+ Allocations, deallocations, any change in m_pMetadata is protected by parent's VmaBlockVector::m_Mutex.
+ */
VMA_MUTEX m_Mutex;
uint32_t m_MapCount;
- void *m_pMappedData;
+ void* m_pMappedData;
};
-struct VmaPointerLess {
- bool operator()(const void *lhs, const void *rhs) const {
+struct VmaPointerLess
+{
+ bool operator()(const void* lhs, const void* rhs) const
+ {
return lhs < rhs;
}
};
-struct VmaDefragmentationMove {
+struct VmaDefragmentationMove
+{
size_t srcBlockIndex;
size_t dstBlockIndex;
VkDeviceSize srcOffset;
VkDeviceSize dstOffset;
VkDeviceSize size;
+ VmaAllocation hAllocation;
+ VmaDeviceMemoryBlock* pSrcBlock;
+ VmaDeviceMemoryBlock* pDstBlock;
};
class VmaDefragmentationAlgorithm;
@@ -5676,77 +6370,86 @@ Vulkan memory type.
Synchronized internally with a mutex.
*/
-struct VmaBlockVector {
+struct VmaBlockVector
+{
VMA_CLASS_NO_COPY(VmaBlockVector)
public:
VmaBlockVector(
- VmaAllocator hAllocator,
- VmaPool hParentPool,
- uint32_t memoryTypeIndex,
- VkDeviceSize preferredBlockSize,
- size_t minBlockCount,
- size_t maxBlockCount,
- VkDeviceSize bufferImageGranularity,
- uint32_t frameInUseCount,
- bool isCustomPool,
- bool explicitBlockSize,
- uint32_t algorithm);
+ VmaAllocator hAllocator,
+ VmaPool hParentPool,
+ uint32_t memoryTypeIndex,
+ VkDeviceSize preferredBlockSize,
+ size_t minBlockCount,
+ size_t maxBlockCount,
+ VkDeviceSize bufferImageGranularity,
+ uint32_t frameInUseCount,
+ bool explicitBlockSize,
+ uint32_t algorithm);
~VmaBlockVector();
VkResult CreateMinBlocks();
+ VmaAllocator GetAllocator() const { return m_hAllocator; }
VmaPool GetParentPool() const { return m_hParentPool; }
+ bool IsCustomPool() const { return m_hParentPool != VMA_NULL; }
uint32_t GetMemoryTypeIndex() const { return m_MemoryTypeIndex; }
VkDeviceSize GetPreferredBlockSize() const { return m_PreferredBlockSize; }
VkDeviceSize GetBufferImageGranularity() const { return m_BufferImageGranularity; }
uint32_t GetFrameInUseCount() const { return m_FrameInUseCount; }
uint32_t GetAlgorithm() const { return m_Algorithm; }
- void GetPoolStats(VmaPoolStats *pStats);
+ void GetPoolStats(VmaPoolStats* pStats);
- bool IsEmpty() const { return m_Blocks.empty(); }
+ bool IsEmpty();
bool IsCorruptionDetectionEnabled() const;
VkResult Allocate(
- uint32_t currentFrameIndex,
- VkDeviceSize size,
- VkDeviceSize alignment,
- const VmaAllocationCreateInfo &createInfo,
- VmaSuballocationType suballocType,
- size_t allocationCount,
- VmaAllocation *pAllocations);
+ uint32_t currentFrameIndex,
+ VkDeviceSize size,
+ VkDeviceSize alignment,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaSuballocationType suballocType,
+ size_t allocationCount,
+ VmaAllocation* pAllocations);
- void Free(
- VmaAllocation hAllocation);
+ void Free(const VmaAllocation hAllocation);
// Adds statistics of this BlockVector to pStats.
- void AddStats(VmaStats *pStats);
+ void AddStats(VmaStats* pStats);
#if VMA_STATS_STRING_ENABLED
- void PrintDetailedMap(class VmaJsonWriter &json);
+ void PrintDetailedMap(class VmaJsonWriter& json);
#endif
void MakePoolAllocationsLost(
- uint32_t currentFrameIndex,
- size_t *pLostAllocationCount);
+ uint32_t currentFrameIndex,
+ size_t* pLostAllocationCount);
VkResult CheckCorruption();
// Saves results in pCtx->res.
void Defragment(
- class VmaBlockVectorDefragmentationContext *pCtx,
- VmaDefragmentationStats *pStats,
- VkDeviceSize &maxCpuBytesToMove, uint32_t &maxCpuAllocationsToMove,
- VkDeviceSize &maxGpuBytesToMove, uint32_t &maxGpuAllocationsToMove,
- VkCommandBuffer commandBuffer);
+ class VmaBlockVectorDefragmentationContext* pCtx,
+ VmaDefragmentationStats* pStats, VmaDefragmentationFlags flags,
+ VkDeviceSize& maxCpuBytesToMove, uint32_t& maxCpuAllocationsToMove,
+ VkDeviceSize& maxGpuBytesToMove, uint32_t& maxGpuAllocationsToMove,
+ VkCommandBuffer commandBuffer);
void DefragmentationEnd(
- class VmaBlockVectorDefragmentationContext *pCtx,
- VmaDefragmentationStats *pStats);
+ class VmaBlockVectorDefragmentationContext* pCtx,
+ VmaDefragmentationStats* pStats);
+
+ uint32_t ProcessDefragmentations(
+ class VmaBlockVectorDefragmentationContext *pCtx,
+ VmaDefragmentationPassMoveInfo* pMove, uint32_t maxMoves);
+
+ void CommitDefragmentations(
+ class VmaBlockVectorDefragmentationContext *pCtx,
+ VmaDefragmentationStats* pStats);
////////////////////////////////////////////////////////////////////////////////
// To be used only while the m_Mutex is locked. Used during defragmentation.
size_t GetBlockCount() const { return m_Blocks.size(); }
- VmaDeviceMemoryBlock *GetBlock(size_t index) const { return m_Blocks[index]; }
+ VmaDeviceMemoryBlock* GetBlock(size_t index) const { return m_Blocks[index]; }
size_t CalcAllocationCount() const;
bool IsBufferImageGranularityConflictPossible() const;
@@ -5761,82 +6464,84 @@ private:
const size_t m_MaxBlockCount;
const VkDeviceSize m_BufferImageGranularity;
const uint32_t m_FrameInUseCount;
- const bool m_IsCustomPool;
const bool m_ExplicitBlockSize;
const uint32_t m_Algorithm;
- /* There can be at most one allocation that is completely empty - a
- hysteresis to avoid pessimistic case of alternating creation and destruction
- of a VkDeviceMemory. */
- bool m_HasEmptyBlock;
VMA_RW_MUTEX m_Mutex;
+
+ /* There can be at most one allocation that is completely empty (except when minBlockCount > 0) -
+ a hysteresis to avoid pessimistic case of alternating creation and destruction of a VkDeviceMemory. */
+ bool m_HasEmptyBlock;
// Incrementally sorted by sumFreeSize, ascending.
- VmaVector<VmaDeviceMemoryBlock *, VmaStlAllocator<VmaDeviceMemoryBlock *> > m_Blocks;
+ VmaVector< VmaDeviceMemoryBlock*, VmaStlAllocator<VmaDeviceMemoryBlock*> > m_Blocks;
uint32_t m_NextBlockId;
VkDeviceSize CalcMaxBlockSize() const;
// Finds and removes given block from vector.
- void Remove(VmaDeviceMemoryBlock *pBlock);
+ void Remove(VmaDeviceMemoryBlock* pBlock);
// Performs single step in sorting m_Blocks. They may not be fully sorted
// after this call.
void IncrementallySortBlocks();
VkResult AllocatePage(
- uint32_t currentFrameIndex,
- VkDeviceSize size,
- VkDeviceSize alignment,
- const VmaAllocationCreateInfo &createInfo,
- VmaSuballocationType suballocType,
- VmaAllocation *pAllocation);
+ uint32_t currentFrameIndex,
+ VkDeviceSize size,
+ VkDeviceSize alignment,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaSuballocationType suballocType,
+ VmaAllocation* pAllocation);
// To be used only without CAN_MAKE_OTHER_LOST flag.
VkResult AllocateFromBlock(
- VmaDeviceMemoryBlock *pBlock,
- uint32_t currentFrameIndex,
- VkDeviceSize size,
- VkDeviceSize alignment,
- VmaAllocationCreateFlags allocFlags,
- void *pUserData,
- VmaSuballocationType suballocType,
- uint32_t strategy,
- VmaAllocation *pAllocation);
-
- VkResult CreateBlock(VkDeviceSize blockSize, size_t *pNewBlockIndex);
+ VmaDeviceMemoryBlock* pBlock,
+ uint32_t currentFrameIndex,
+ VkDeviceSize size,
+ VkDeviceSize alignment,
+ VmaAllocationCreateFlags allocFlags,
+ void* pUserData,
+ VmaSuballocationType suballocType,
+ uint32_t strategy,
+ VmaAllocation* pAllocation);
+
+ VkResult CreateBlock(VkDeviceSize blockSize, size_t* pNewBlockIndex);
// Saves result to pCtx->res.
void ApplyDefragmentationMovesCpu(
- class VmaBlockVectorDefragmentationContext *pDefragCtx,
- const VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves);
+ class VmaBlockVectorDefragmentationContext* pDefragCtx,
+ const VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves);
// Saves result to pCtx->res.
void ApplyDefragmentationMovesGpu(
- class VmaBlockVectorDefragmentationContext *pDefragCtx,
- const VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkCommandBuffer commandBuffer);
+ class VmaBlockVectorDefragmentationContext* pDefragCtx,
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkCommandBuffer commandBuffer);
/*
- Used during defragmentation. pDefragmentationStats is optional. It's in/out
- - updated with new data.
- */
- void FreeEmptyBlocks(VmaDefragmentationStats *pDefragmentationStats);
+ Used during defragmentation. pDefragmentationStats is optional. It's in/out
+ - updated with new data.
+ */
+ void FreeEmptyBlocks(VmaDefragmentationStats* pDefragmentationStats);
+
+ void UpdateHasEmptyBlock();
};
-struct VmaPool_T {
+struct VmaPool_T
+{
VMA_CLASS_NO_COPY(VmaPool_T)
public:
VmaBlockVector m_BlockVector;
VmaPool_T(
- VmaAllocator hAllocator,
- const VmaPoolCreateInfo &createInfo,
- VkDeviceSize preferredBlockSize);
+ VmaAllocator hAllocator,
+ const VmaPoolCreateInfo& createInfo,
+ VkDeviceSize preferredBlockSize);
~VmaPool_T();
uint32_t GetId() const { return m_Id; }
- void SetId(uint32_t id) {
- VMA_ASSERT(m_Id == 0);
- m_Id = id;
- }
+ void SetId(uint32_t id) { VMA_ASSERT(m_Id == 0); m_Id = id; }
+
+ const char* GetName() const { return m_Name; }
+ void SetName(const char* pName);
#if VMA_STATS_STRING_ENABLED
//void PrintDetailedMap(class VmaStringBuilder& sb);
@@ -5844,6 +6549,7 @@ public:
private:
uint32_t m_Id;
+ char* m_Name;
};
/*
@@ -5853,68 +6559,77 @@ Performs defragmentation:
- Updates allocations by calling ChangeBlockAllocation() or ChangeOffset().
- Does not move actual data, only returns requested moves as `moves`.
*/
-class VmaDefragmentationAlgorithm {
+class VmaDefragmentationAlgorithm
+{
VMA_CLASS_NO_COPY(VmaDefragmentationAlgorithm)
public:
VmaDefragmentationAlgorithm(
- VmaAllocator hAllocator,
- VmaBlockVector *pBlockVector,
- uint32_t currentFrameIndex) :
- m_hAllocator(hAllocator),
- m_pBlockVector(pBlockVector),
- m_CurrentFrameIndex(currentFrameIndex) {
+ VmaAllocator hAllocator,
+ VmaBlockVector* pBlockVector,
+ uint32_t currentFrameIndex) :
+ m_hAllocator(hAllocator),
+ m_pBlockVector(pBlockVector),
+ m_CurrentFrameIndex(currentFrameIndex)
+ {
}
- virtual ~VmaDefragmentationAlgorithm() {
+ virtual ~VmaDefragmentationAlgorithm()
+ {
}
- virtual void AddAllocation(VmaAllocation hAlloc, VkBool32 *pChanged) = 0;
+ virtual void AddAllocation(VmaAllocation hAlloc, VkBool32* pChanged) = 0;
virtual void AddAll() = 0;
virtual VkResult Defragment(
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkDeviceSize maxBytesToMove,
- uint32_t maxAllocationsToMove) = 0;
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkDeviceSize maxBytesToMove,
+ uint32_t maxAllocationsToMove,
+ VmaDefragmentationFlags flags) = 0;
virtual VkDeviceSize GetBytesMoved() const = 0;
virtual uint32_t GetAllocationsMoved() const = 0;
protected:
VmaAllocator const m_hAllocator;
- VmaBlockVector *const m_pBlockVector;
+ VmaBlockVector* const m_pBlockVector;
const uint32_t m_CurrentFrameIndex;
- struct AllocationInfo {
+ struct AllocationInfo
+ {
VmaAllocation m_hAllocation;
- VkBool32 *m_pChanged;
+ VkBool32* m_pChanged;
AllocationInfo() :
- m_hAllocation(VK_NULL_HANDLE),
- m_pChanged(VMA_NULL) {
+ m_hAllocation(VK_NULL_HANDLE),
+ m_pChanged(VMA_NULL)
+ {
}
- AllocationInfo(VmaAllocation hAlloc, VkBool32 *pChanged) :
- m_hAllocation(hAlloc),
- m_pChanged(pChanged) {
+ AllocationInfo(VmaAllocation hAlloc, VkBool32* pChanged) :
+ m_hAllocation(hAlloc),
+ m_pChanged(pChanged)
+ {
}
};
};
-class VmaDefragmentationAlgorithm_Generic : public VmaDefragmentationAlgorithm {
+class VmaDefragmentationAlgorithm_Generic : public VmaDefragmentationAlgorithm
+{
VMA_CLASS_NO_COPY(VmaDefragmentationAlgorithm_Generic)
public:
VmaDefragmentationAlgorithm_Generic(
- VmaAllocator hAllocator,
- VmaBlockVector *pBlockVector,
- uint32_t currentFrameIndex,
- bool overlappingMoveSupported);
+ VmaAllocator hAllocator,
+ VmaBlockVector* pBlockVector,
+ uint32_t currentFrameIndex,
+ bool overlappingMoveSupported);
virtual ~VmaDefragmentationAlgorithm_Generic();
- virtual void AddAllocation(VmaAllocation hAlloc, VkBool32 *pChanged);
+ virtual void AddAllocation(VmaAllocation hAlloc, VkBool32* pChanged);
virtual void AddAll() { m_AllAllocations = true; }
virtual VkResult Defragment(
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkDeviceSize maxBytesToMove,
- uint32_t maxAllocationsToMove);
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkDeviceSize maxBytesToMove,
+ uint32_t maxAllocationsToMove,
+ VmaDefragmentationFlags flags);
virtual VkDeviceSize GetBytesMoved() const { return m_BytesMoved; }
virtual uint32_t GetAllocationsMoved() const { return m_AllocationsMoved; }
@@ -5926,143 +6641,173 @@ private:
VkDeviceSize m_BytesMoved;
uint32_t m_AllocationsMoved;
- struct AllocationInfoSizeGreater {
- bool operator()(const AllocationInfo &lhs, const AllocationInfo &rhs) const {
+ struct AllocationInfoSizeGreater
+ {
+ bool operator()(const AllocationInfo& lhs, const AllocationInfo& rhs) const
+ {
return lhs.m_hAllocation->GetSize() > rhs.m_hAllocation->GetSize();
}
};
- struct AllocationInfoOffsetGreater {
- bool operator()(const AllocationInfo &lhs, const AllocationInfo &rhs) const {
+ struct AllocationInfoOffsetGreater
+ {
+ bool operator()(const AllocationInfo& lhs, const AllocationInfo& rhs) const
+ {
return lhs.m_hAllocation->GetOffset() > rhs.m_hAllocation->GetOffset();
}
};
- struct BlockInfo {
+ struct BlockInfo
+ {
size_t m_OriginalBlockIndex;
- VmaDeviceMemoryBlock *m_pBlock;
+ VmaDeviceMemoryBlock* m_pBlock;
bool m_HasNonMovableAllocations;
- VmaVector<AllocationInfo, VmaStlAllocator<AllocationInfo> > m_Allocations;
+ VmaVector< AllocationInfo, VmaStlAllocator<AllocationInfo> > m_Allocations;
- BlockInfo(const VkAllocationCallbacks *pAllocationCallbacks) :
- m_OriginalBlockIndex(SIZE_MAX),
- m_pBlock(VMA_NULL),
- m_HasNonMovableAllocations(true),
- m_Allocations(pAllocationCallbacks) {
+ BlockInfo(const VkAllocationCallbacks* pAllocationCallbacks) :
+ m_OriginalBlockIndex(SIZE_MAX),
+ m_pBlock(VMA_NULL),
+ m_HasNonMovableAllocations(true),
+ m_Allocations(pAllocationCallbacks)
+ {
}
- void CalcHasNonMovableAllocations() {
+ void CalcHasNonMovableAllocations()
+ {
const size_t blockAllocCount = m_pBlock->m_pMetadata->GetAllocationCount();
const size_t defragmentAllocCount = m_Allocations.size();
m_HasNonMovableAllocations = blockAllocCount != defragmentAllocCount;
}
- void SortAllocationsBySizeDescending() {
+ void SortAllocationsBySizeDescending()
+ {
VMA_SORT(m_Allocations.begin(), m_Allocations.end(), AllocationInfoSizeGreater());
}
- void SortAllocationsByOffsetDescending() {
+ void SortAllocationsByOffsetDescending()
+ {
VMA_SORT(m_Allocations.begin(), m_Allocations.end(), AllocationInfoOffsetGreater());
}
};
- struct BlockPointerLess {
- bool operator()(const BlockInfo *pLhsBlockInfo, const VmaDeviceMemoryBlock *pRhsBlock) const {
+ struct BlockPointerLess
+ {
+ bool operator()(const BlockInfo* pLhsBlockInfo, const VmaDeviceMemoryBlock* pRhsBlock) const
+ {
return pLhsBlockInfo->m_pBlock < pRhsBlock;
}
- bool operator()(const BlockInfo *pLhsBlockInfo, const BlockInfo *pRhsBlockInfo) const {
+ bool operator()(const BlockInfo* pLhsBlockInfo, const BlockInfo* pRhsBlockInfo) const
+ {
return pLhsBlockInfo->m_pBlock < pRhsBlockInfo->m_pBlock;
}
};
// 1. Blocks with some non-movable allocations go first.
// 2. Blocks with smaller sumFreeSize go first.
- struct BlockInfoCompareMoveDestination {
- bool operator()(const BlockInfo *pLhsBlockInfo, const BlockInfo *pRhsBlockInfo) const {
- if (pLhsBlockInfo->m_HasNonMovableAllocations && !pRhsBlockInfo->m_HasNonMovableAllocations) {
+ struct BlockInfoCompareMoveDestination
+ {
+ bool operator()(const BlockInfo* pLhsBlockInfo, const BlockInfo* pRhsBlockInfo) const
+ {
+ if(pLhsBlockInfo->m_HasNonMovableAllocations && !pRhsBlockInfo->m_HasNonMovableAllocations)
+ {
return true;
}
- if (!pLhsBlockInfo->m_HasNonMovableAllocations && pRhsBlockInfo->m_HasNonMovableAllocations) {
+ if(!pLhsBlockInfo->m_HasNonMovableAllocations && pRhsBlockInfo->m_HasNonMovableAllocations)
+ {
return false;
}
- if (pLhsBlockInfo->m_pBlock->m_pMetadata->GetSumFreeSize() < pRhsBlockInfo->m_pBlock->m_pMetadata->GetSumFreeSize()) {
+ if(pLhsBlockInfo->m_pBlock->m_pMetadata->GetSumFreeSize() < pRhsBlockInfo->m_pBlock->m_pMetadata->GetSumFreeSize())
+ {
return true;
}
return false;
}
};
- typedef VmaVector<BlockInfo *, VmaStlAllocator<BlockInfo *> > BlockInfoVector;
+ typedef VmaVector< BlockInfo*, VmaStlAllocator<BlockInfo*> > BlockInfoVector;
BlockInfoVector m_Blocks;
VkResult DefragmentRound(
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkDeviceSize maxBytesToMove,
- uint32_t maxAllocationsToMove);
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkDeviceSize maxBytesToMove,
+ uint32_t maxAllocationsToMove,
+ bool freeOldAllocations);
size_t CalcBlocksWithNonMovableCount() const;
static bool MoveMakesSense(
- size_t dstBlockIndex, VkDeviceSize dstOffset,
- size_t srcBlockIndex, VkDeviceSize srcOffset);
+ size_t dstBlockIndex, VkDeviceSize dstOffset,
+ size_t srcBlockIndex, VkDeviceSize srcOffset);
};
-class VmaDefragmentationAlgorithm_Fast : public VmaDefragmentationAlgorithm {
+class VmaDefragmentationAlgorithm_Fast : public VmaDefragmentationAlgorithm
+{
VMA_CLASS_NO_COPY(VmaDefragmentationAlgorithm_Fast)
public:
VmaDefragmentationAlgorithm_Fast(
- VmaAllocator hAllocator,
- VmaBlockVector *pBlockVector,
- uint32_t currentFrameIndex,
- bool overlappingMoveSupported);
+ VmaAllocator hAllocator,
+ VmaBlockVector* pBlockVector,
+ uint32_t currentFrameIndex,
+ bool overlappingMoveSupported);
virtual ~VmaDefragmentationAlgorithm_Fast();
- virtual void AddAllocation(VmaAllocation hAlloc, VkBool32 *pChanged) { ++m_AllocationCount; }
+ virtual void AddAllocation(VmaAllocation hAlloc, VkBool32* pChanged) { ++m_AllocationCount; }
virtual void AddAll() { m_AllAllocations = true; }
virtual VkResult Defragment(
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkDeviceSize maxBytesToMove,
- uint32_t maxAllocationsToMove);
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkDeviceSize maxBytesToMove,
+ uint32_t maxAllocationsToMove,
+ VmaDefragmentationFlags flags);
virtual VkDeviceSize GetBytesMoved() const { return m_BytesMoved; }
virtual uint32_t GetAllocationsMoved() const { return m_AllocationsMoved; }
private:
- struct BlockInfo {
+ struct BlockInfo
+ {
size_t origBlockIndex;
};
- class FreeSpaceDatabase {
+ class FreeSpaceDatabase
+ {
public:
- FreeSpaceDatabase() {
+ FreeSpaceDatabase()
+ {
FreeSpace s = {};
s.blockInfoIndex = SIZE_MAX;
- for (size_t i = 0; i < MAX_COUNT; ++i) {
+ for(size_t i = 0; i < MAX_COUNT; ++i)
+ {
m_FreeSpaces[i] = s;
}
}
- void Register(size_t blockInfoIndex, VkDeviceSize offset, VkDeviceSize size) {
- if (size < VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER) {
+ void Register(size_t blockInfoIndex, VkDeviceSize offset, VkDeviceSize size)
+ {
+ if(size < VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+ {
return;
}
// Find first invalid or the smallest structure.
size_t bestIndex = SIZE_MAX;
- for (size_t i = 0; i < MAX_COUNT; ++i) {
+ for(size_t i = 0; i < MAX_COUNT; ++i)
+ {
// Empty structure.
- if (m_FreeSpaces[i].blockInfoIndex == SIZE_MAX) {
+ if(m_FreeSpaces[i].blockInfoIndex == SIZE_MAX)
+ {
bestIndex = i;
break;
}
- if (m_FreeSpaces[i].size < size &&
- (bestIndex == SIZE_MAX || m_FreeSpaces[bestIndex].size > m_FreeSpaces[i].size)) {
+ if(m_FreeSpaces[i].size < size &&
+ (bestIndex == SIZE_MAX || m_FreeSpaces[bestIndex].size > m_FreeSpaces[i].size))
+ {
bestIndex = i;
}
}
- if (bestIndex != SIZE_MAX) {
+ if(bestIndex != SIZE_MAX)
+ {
m_FreeSpaces[bestIndex].blockInfoIndex = blockInfoIndex;
m_FreeSpaces[bestIndex].offset = offset;
m_FreeSpaces[bestIndex].size = size;
@@ -6070,35 +6815,44 @@ private:
}
bool Fetch(VkDeviceSize alignment, VkDeviceSize size,
- size_t &outBlockInfoIndex, VkDeviceSize &outDstOffset) {
+ size_t& outBlockInfoIndex, VkDeviceSize& outDstOffset)
+ {
size_t bestIndex = SIZE_MAX;
VkDeviceSize bestFreeSpaceAfter = 0;
- for (size_t i = 0; i < MAX_COUNT; ++i) {
+ for(size_t i = 0; i < MAX_COUNT; ++i)
+ {
// Structure is valid.
- if (m_FreeSpaces[i].blockInfoIndex != SIZE_MAX) {
+ if(m_FreeSpaces[i].blockInfoIndex != SIZE_MAX)
+ {
const VkDeviceSize dstOffset = VmaAlignUp(m_FreeSpaces[i].offset, alignment);
// Allocation fits into this structure.
- if (dstOffset + size <= m_FreeSpaces[i].offset + m_FreeSpaces[i].size) {
+ if(dstOffset + size <= m_FreeSpaces[i].offset + m_FreeSpaces[i].size)
+ {
const VkDeviceSize freeSpaceAfter = (m_FreeSpaces[i].offset + m_FreeSpaces[i].size) -
- (dstOffset + size);
- if (bestIndex == SIZE_MAX || freeSpaceAfter > bestFreeSpaceAfter) {
+ (dstOffset + size);
+ if(bestIndex == SIZE_MAX || freeSpaceAfter > bestFreeSpaceAfter)
+ {
bestIndex = i;
bestFreeSpaceAfter = freeSpaceAfter;
}
}
}
}
-
- if (bestIndex != SIZE_MAX) {
+
+ if(bestIndex != SIZE_MAX)
+ {
outBlockInfoIndex = m_FreeSpaces[bestIndex].blockInfoIndex;
outDstOffset = VmaAlignUp(m_FreeSpaces[bestIndex].offset, alignment);
- if (bestFreeSpaceAfter >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER) {
+ if(bestFreeSpaceAfter >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+ {
// Leave this structure for remaining empty space.
const VkDeviceSize alignmentPlusSize = (outDstOffset - m_FreeSpaces[bestIndex].offset) + size;
m_FreeSpaces[bestIndex].offset += alignmentPlusSize;
m_FreeSpaces[bestIndex].size -= alignmentPlusSize;
- } else {
+ }
+ else
+ {
// This structure becomes invalid.
m_FreeSpaces[bestIndex].blockInfoIndex = SIZE_MAX;
}
@@ -6112,7 +6866,8 @@ private:
private:
static const size_t MAX_COUNT = 4;
- struct FreeSpace {
+ struct FreeSpace
+ {
size_t blockInfoIndex; // SIZE_MAX means this structure is invalid.
VkDeviceSize offset;
VkDeviceSize size;
@@ -6127,231 +6882,251 @@ private:
VkDeviceSize m_BytesMoved;
uint32_t m_AllocationsMoved;
- VmaVector<BlockInfo, VmaStlAllocator<BlockInfo> > m_BlockInfos;
+ VmaVector< BlockInfo, VmaStlAllocator<BlockInfo> > m_BlockInfos;
void PreprocessMetadata();
void PostprocessMetadata();
- void InsertSuballoc(VmaBlockMetadata_Generic *pMetadata, const VmaSuballocation &suballoc);
+ void InsertSuballoc(VmaBlockMetadata_Generic* pMetadata, const VmaSuballocation& suballoc);
};
-struct VmaBlockDefragmentationContext {
- enum BLOCK_FLAG {
+struct VmaBlockDefragmentationContext
+{
+ enum BLOCK_FLAG
+ {
BLOCK_FLAG_USED = 0x00000001,
};
uint32_t flags;
VkBuffer hBuffer;
-
- VmaBlockDefragmentationContext() :
- flags(0),
- hBuffer(VK_NULL_HANDLE) {
- }
};
-class VmaBlockVectorDefragmentationContext {
+class VmaBlockVectorDefragmentationContext
+{
VMA_CLASS_NO_COPY(VmaBlockVectorDefragmentationContext)
public:
VkResult res;
bool mutexLocked;
- VmaVector<VmaBlockDefragmentationContext, VmaStlAllocator<VmaBlockDefragmentationContext> > blockContexts;
+ VmaVector< VmaBlockDefragmentationContext, VmaStlAllocator<VmaBlockDefragmentationContext> > blockContexts;
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > defragmentationMoves;
+ uint32_t defragmentationMovesProcessed;
+ uint32_t defragmentationMovesCommitted;
+ bool hasDefragmentationPlan;
VmaBlockVectorDefragmentationContext(
- VmaAllocator hAllocator,
- VmaPool hCustomPool, // Optional.
- VmaBlockVector *pBlockVector,
- uint32_t currFrameIndex,
- uint32_t flags);
+ VmaAllocator hAllocator,
+ VmaPool hCustomPool, // Optional.
+ VmaBlockVector* pBlockVector,
+ uint32_t currFrameIndex);
~VmaBlockVectorDefragmentationContext();
VmaPool GetCustomPool() const { return m_hCustomPool; }
- VmaBlockVector *GetBlockVector() const { return m_pBlockVector; }
- VmaDefragmentationAlgorithm *GetAlgorithm() const { return m_pAlgorithm; }
+ VmaBlockVector* GetBlockVector() const { return m_pBlockVector; }
+ VmaDefragmentationAlgorithm* GetAlgorithm() const { return m_pAlgorithm; }
- void AddAllocation(VmaAllocation hAlloc, VkBool32 *pChanged);
+ void AddAllocation(VmaAllocation hAlloc, VkBool32* pChanged);
void AddAll() { m_AllAllocations = true; }
- void Begin(bool overlappingMoveSupported);
+ void Begin(bool overlappingMoveSupported, VmaDefragmentationFlags flags);
private:
const VmaAllocator m_hAllocator;
// Null if not from custom pool.
const VmaPool m_hCustomPool;
// Redundant, for convenience not to fetch from m_hCustomPool->m_BlockVector or m_hAllocator->m_pBlockVectors.
- VmaBlockVector *const m_pBlockVector;
+ VmaBlockVector* const m_pBlockVector;
const uint32_t m_CurrFrameIndex;
- const uint32_t m_AlgorithmFlags;
// Owner of this object.
- VmaDefragmentationAlgorithm *m_pAlgorithm;
+ VmaDefragmentationAlgorithm* m_pAlgorithm;
- struct AllocInfo {
+ struct AllocInfo
+ {
VmaAllocation hAlloc;
- VkBool32 *pChanged;
+ VkBool32* pChanged;
};
// Used between constructor and Begin.
- VmaVector<AllocInfo, VmaStlAllocator<AllocInfo> > m_Allocations;
+ VmaVector< AllocInfo, VmaStlAllocator<AllocInfo> > m_Allocations;
bool m_AllAllocations;
};
-struct VmaDefragmentationContext_T {
+struct VmaDefragmentationContext_T
+{
private:
VMA_CLASS_NO_COPY(VmaDefragmentationContext_T)
public:
VmaDefragmentationContext_T(
- VmaAllocator hAllocator,
- uint32_t currFrameIndex,
- uint32_t flags,
- VmaDefragmentationStats *pStats);
+ VmaAllocator hAllocator,
+ uint32_t currFrameIndex,
+ uint32_t flags,
+ VmaDefragmentationStats* pStats);
~VmaDefragmentationContext_T();
- void AddPools(uint32_t poolCount, VmaPool *pPools);
+ void AddPools(uint32_t poolCount, VmaPool* pPools);
void AddAllocations(
- uint32_t allocationCount,
- VmaAllocation *pAllocations,
- VkBool32 *pAllocationsChanged);
+ uint32_t allocationCount,
+ VmaAllocation* pAllocations,
+ VkBool32* pAllocationsChanged);
/*
- Returns:
- - `VK_SUCCESS` if succeeded and object can be destroyed immediately.
- - `VK_NOT_READY` if succeeded but the object must remain alive until vmaDefragmentationEnd().
- - Negative value if error occured and object can be destroyed immediately.
- */
+ Returns:
+ - `VK_SUCCESS` if succeeded and object can be destroyed immediately.
+ - `VK_NOT_READY` if succeeded but the object must remain alive until vmaDefragmentationEnd().
+ - Negative value if error occured and object can be destroyed immediately.
+ */
VkResult Defragment(
- VkDeviceSize maxCpuBytesToMove, uint32_t maxCpuAllocationsToMove,
- VkDeviceSize maxGpuBytesToMove, uint32_t maxGpuAllocationsToMove,
- VkCommandBuffer commandBuffer, VmaDefragmentationStats *pStats);
+ VkDeviceSize maxCpuBytesToMove, uint32_t maxCpuAllocationsToMove,
+ VkDeviceSize maxGpuBytesToMove, uint32_t maxGpuAllocationsToMove,
+ VkCommandBuffer commandBuffer, VmaDefragmentationStats* pStats, VmaDefragmentationFlags flags);
+
+ VkResult DefragmentPassBegin(VmaDefragmentationPassInfo* pInfo);
+ VkResult DefragmentPassEnd();
private:
const VmaAllocator m_hAllocator;
const uint32_t m_CurrFrameIndex;
const uint32_t m_Flags;
- VmaDefragmentationStats *const m_pStats;
+ VmaDefragmentationStats* const m_pStats;
+
+ VkDeviceSize m_MaxCpuBytesToMove;
+ uint32_t m_MaxCpuAllocationsToMove;
+ VkDeviceSize m_MaxGpuBytesToMove;
+ uint32_t m_MaxGpuAllocationsToMove;
+
// Owner of these objects.
- VmaBlockVectorDefragmentationContext *m_DefaultPoolContexts[VK_MAX_MEMORY_TYPES];
+ VmaBlockVectorDefragmentationContext* m_DefaultPoolContexts[VK_MAX_MEMORY_TYPES];
// Owner of these objects.
- VmaVector<VmaBlockVectorDefragmentationContext *, VmaStlAllocator<VmaBlockVectorDefragmentationContext *> > m_CustomPoolContexts;
+ VmaVector< VmaBlockVectorDefragmentationContext*, VmaStlAllocator<VmaBlockVectorDefragmentationContext*> > m_CustomPoolContexts;
};
#if VMA_RECORDING_ENABLED
-class VmaRecorder {
+class VmaRecorder
+{
public:
VmaRecorder();
- VkResult Init(const VmaRecordSettings &settings, bool useMutex);
+ VkResult Init(const VmaRecordSettings& settings, bool useMutex);
void WriteConfiguration(
- const VkPhysicalDeviceProperties &devProps,
- const VkPhysicalDeviceMemoryProperties &memProps,
- bool dedicatedAllocationExtensionEnabled);
+ const VkPhysicalDeviceProperties& devProps,
+ const VkPhysicalDeviceMemoryProperties& memProps,
+ uint32_t vulkanApiVersion,
+ bool dedicatedAllocationExtensionEnabled,
+ bool bindMemory2ExtensionEnabled,
+ bool memoryBudgetExtensionEnabled,
+ bool deviceCoherentMemoryExtensionEnabled);
~VmaRecorder();
void RecordCreateAllocator(uint32_t frameIndex);
void RecordDestroyAllocator(uint32_t frameIndex);
void RecordCreatePool(uint32_t frameIndex,
- const VmaPoolCreateInfo &createInfo,
- VmaPool pool);
+ const VmaPoolCreateInfo& createInfo,
+ VmaPool pool);
void RecordDestroyPool(uint32_t frameIndex, VmaPool pool);
void RecordAllocateMemory(uint32_t frameIndex,
- const VkMemoryRequirements &vkMemReq,
- const VmaAllocationCreateInfo &createInfo,
- VmaAllocation allocation);
+ const VkMemoryRequirements& vkMemReq,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaAllocation allocation);
void RecordAllocateMemoryPages(uint32_t frameIndex,
- const VkMemoryRequirements &vkMemReq,
- const VmaAllocationCreateInfo &createInfo,
- uint64_t allocationCount,
- const VmaAllocation *pAllocations);
+ const VkMemoryRequirements& vkMemReq,
+ const VmaAllocationCreateInfo& createInfo,
+ uint64_t allocationCount,
+ const VmaAllocation* pAllocations);
void RecordAllocateMemoryForBuffer(uint32_t frameIndex,
- const VkMemoryRequirements &vkMemReq,
- bool requiresDedicatedAllocation,
- bool prefersDedicatedAllocation,
- const VmaAllocationCreateInfo &createInfo,
- VmaAllocation allocation);
+ const VkMemoryRequirements& vkMemReq,
+ bool requiresDedicatedAllocation,
+ bool prefersDedicatedAllocation,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaAllocation allocation);
void RecordAllocateMemoryForImage(uint32_t frameIndex,
- const VkMemoryRequirements &vkMemReq,
- bool requiresDedicatedAllocation,
- bool prefersDedicatedAllocation,
- const VmaAllocationCreateInfo &createInfo,
- VmaAllocation allocation);
+ const VkMemoryRequirements& vkMemReq,
+ bool requiresDedicatedAllocation,
+ bool prefersDedicatedAllocation,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaAllocation allocation);
void RecordFreeMemory(uint32_t frameIndex,
- VmaAllocation allocation);
+ VmaAllocation allocation);
void RecordFreeMemoryPages(uint32_t frameIndex,
- uint64_t allocationCount,
- const VmaAllocation *pAllocations);
- void RecordResizeAllocation(
- uint32_t frameIndex,
- VmaAllocation allocation,
- VkDeviceSize newSize);
+ uint64_t allocationCount,
+ const VmaAllocation* pAllocations);
void RecordSetAllocationUserData(uint32_t frameIndex,
- VmaAllocation allocation,
- const void *pUserData);
+ VmaAllocation allocation,
+ const void* pUserData);
void RecordCreateLostAllocation(uint32_t frameIndex,
- VmaAllocation allocation);
+ VmaAllocation allocation);
void RecordMapMemory(uint32_t frameIndex,
- VmaAllocation allocation);
+ VmaAllocation allocation);
void RecordUnmapMemory(uint32_t frameIndex,
- VmaAllocation allocation);
+ VmaAllocation allocation);
void RecordFlushAllocation(uint32_t frameIndex,
- VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size);
+ VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size);
void RecordInvalidateAllocation(uint32_t frameIndex,
- VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size);
+ VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size);
void RecordCreateBuffer(uint32_t frameIndex,
- const VkBufferCreateInfo &bufCreateInfo,
- const VmaAllocationCreateInfo &allocCreateInfo,
- VmaAllocation allocation);
+ const VkBufferCreateInfo& bufCreateInfo,
+ const VmaAllocationCreateInfo& allocCreateInfo,
+ VmaAllocation allocation);
void RecordCreateImage(uint32_t frameIndex,
- const VkImageCreateInfo &imageCreateInfo,
- const VmaAllocationCreateInfo &allocCreateInfo,
- VmaAllocation allocation);
+ const VkImageCreateInfo& imageCreateInfo,
+ const VmaAllocationCreateInfo& allocCreateInfo,
+ VmaAllocation allocation);
void RecordDestroyBuffer(uint32_t frameIndex,
- VmaAllocation allocation);
+ VmaAllocation allocation);
void RecordDestroyImage(uint32_t frameIndex,
- VmaAllocation allocation);
+ VmaAllocation allocation);
void RecordTouchAllocation(uint32_t frameIndex,
- VmaAllocation allocation);
+ VmaAllocation allocation);
void RecordGetAllocationInfo(uint32_t frameIndex,
- VmaAllocation allocation);
+ VmaAllocation allocation);
void RecordMakePoolAllocationsLost(uint32_t frameIndex,
- VmaPool pool);
+ VmaPool pool);
void RecordDefragmentationBegin(uint32_t frameIndex,
- const VmaDefragmentationInfo2 &info,
- VmaDefragmentationContext ctx);
+ const VmaDefragmentationInfo2& info,
+ VmaDefragmentationContext ctx);
void RecordDefragmentationEnd(uint32_t frameIndex,
- VmaDefragmentationContext ctx);
+ VmaDefragmentationContext ctx);
+ void RecordSetPoolName(uint32_t frameIndex,
+ VmaPool pool,
+ const char* name);
private:
- struct CallParams {
+ struct CallParams
+ {
uint32_t threadId;
double time;
};
- class UserDataString {
+ class UserDataString
+ {
public:
- UserDataString(VmaAllocationCreateFlags allocFlags, const void *pUserData);
- const char *GetString() const { return m_Str; }
+ UserDataString(VmaAllocationCreateFlags allocFlags, const void* pUserData);
+ const char* GetString() const { return m_Str; }
private:
char m_PtrStr[17];
- const char *m_Str;
+ const char* m_Str;
};
bool m_UseMutex;
VmaRecordFlags m_Flags;
- FILE *m_File;
+ FILE* m_File;
VMA_MUTEX m_FileMutex;
int64_t m_Freq;
int64_t m_StartCounter;
- void GetBasicParams(CallParams &outParams);
+ void GetBasicParams(CallParams& outParams);
// T must be a pointer type, e.g. VmaAllocation, VmaPool.
- template <typename T>
- void PrintPointerList(uint64_t count, const T *pItems) {
- if (count) {
+ template<typename T>
+ void PrintPointerList(uint64_t count, const T* pItems)
+ {
+ if(count)
+ {
fprintf(m_File, "%p", pItems[0]);
- for (uint64_t i = 1; i < count; ++i) {
+ for(uint64_t i = 1; i < count; ++i)
+ {
fprintf(m_File, " %p", pItems[i]);
}
}
}
- void PrintPointerList(uint64_t count, const VmaAllocation *pItems);
+ void PrintPointerList(uint64_t count, const VmaAllocation* pItems);
void Flush();
};
@@ -6360,12 +7135,13 @@ private:
/*
Thread-safe wrapper over VmaPoolAllocator free list, for allocation of VmaAllocation_T objects.
*/
-class VmaAllocationObjectAllocator {
+class VmaAllocationObjectAllocator
+{
VMA_CLASS_NO_COPY(VmaAllocationObjectAllocator)
public:
- VmaAllocationObjectAllocator(const VkAllocationCallbacks *pAllocationCallbacks);
+ VmaAllocationObjectAllocator(const VkAllocationCallbacks* pAllocationCallbacks);
- VmaAllocation Allocate();
+ template<typename... Types> VmaAllocation Allocate(Types... args);
void Free(VmaAllocation hAlloc);
private:
@@ -6373,160 +7149,256 @@ private:
VmaPoolAllocator<VmaAllocation_T> m_Allocator;
};
+struct VmaCurrentBudgetData
+{
+ VMA_ATOMIC_UINT64 m_BlockBytes[VK_MAX_MEMORY_HEAPS];
+ VMA_ATOMIC_UINT64 m_AllocationBytes[VK_MAX_MEMORY_HEAPS];
+
+#if VMA_MEMORY_BUDGET
+ VMA_ATOMIC_UINT32 m_OperationsSinceBudgetFetch;
+ VMA_RW_MUTEX m_BudgetMutex;
+ uint64_t m_VulkanUsage[VK_MAX_MEMORY_HEAPS];
+ uint64_t m_VulkanBudget[VK_MAX_MEMORY_HEAPS];
+ uint64_t m_BlockBytesAtBudgetFetch[VK_MAX_MEMORY_HEAPS];
+#endif // #if VMA_MEMORY_BUDGET
+
+ VmaCurrentBudgetData()
+ {
+ for(uint32_t heapIndex = 0; heapIndex < VK_MAX_MEMORY_HEAPS; ++heapIndex)
+ {
+ m_BlockBytes[heapIndex] = 0;
+ m_AllocationBytes[heapIndex] = 0;
+#if VMA_MEMORY_BUDGET
+ m_VulkanUsage[heapIndex] = 0;
+ m_VulkanBudget[heapIndex] = 0;
+ m_BlockBytesAtBudgetFetch[heapIndex] = 0;
+#endif
+ }
+
+#if VMA_MEMORY_BUDGET
+ m_OperationsSinceBudgetFetch = 0;
+#endif
+ }
+
+ void AddAllocation(uint32_t heapIndex, VkDeviceSize allocationSize)
+ {
+ m_AllocationBytes[heapIndex] += allocationSize;
+#if VMA_MEMORY_BUDGET
+ ++m_OperationsSinceBudgetFetch;
+#endif
+ }
+
+ void RemoveAllocation(uint32_t heapIndex, VkDeviceSize allocationSize)
+ {
+ VMA_ASSERT(m_AllocationBytes[heapIndex] >= allocationSize); // DELME
+ m_AllocationBytes[heapIndex] -= allocationSize;
+#if VMA_MEMORY_BUDGET
+ ++m_OperationsSinceBudgetFetch;
+#endif
+ }
+};
+
// Main allocator object.
-struct VmaAllocator_T {
+struct VmaAllocator_T
+{
VMA_CLASS_NO_COPY(VmaAllocator_T)
public:
bool m_UseMutex;
- bool m_UseKhrDedicatedAllocation;
+ uint32_t m_VulkanApiVersion;
+ bool m_UseKhrDedicatedAllocation; // Can be set only if m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0).
+ bool m_UseKhrBindMemory2; // Can be set only if m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0).
+ bool m_UseExtMemoryBudget;
+ bool m_UseAmdDeviceCoherentMemory;
VkDevice m_hDevice;
+ VkInstance m_hInstance;
bool m_AllocationCallbacksSpecified;
VkAllocationCallbacks m_AllocationCallbacks;
VmaDeviceMemoryCallbacks m_DeviceMemoryCallbacks;
VmaAllocationObjectAllocator m_AllocationObjectAllocator;
-
- // Number of bytes free out of limit, or VK_WHOLE_SIZE if no limit for that heap.
- VkDeviceSize m_HeapSizeLimit[VK_MAX_MEMORY_HEAPS];
- VMA_MUTEX m_HeapSizeLimitMutex;
+
+ // Each bit (1 << i) is set if HeapSizeLimit is enabled for that heap, so cannot allocate more than the heap size.
+ uint32_t m_HeapSizeLimitMask;
VkPhysicalDeviceProperties m_PhysicalDeviceProperties;
VkPhysicalDeviceMemoryProperties m_MemProps;
// Default pools.
- VmaBlockVector *m_pBlockVectors[VK_MAX_MEMORY_TYPES];
+ VmaBlockVector* m_pBlockVectors[VK_MAX_MEMORY_TYPES];
// Each vector is sorted by memory (handle value).
- typedef VmaVector<VmaAllocation, VmaStlAllocator<VmaAllocation> > AllocationVectorType;
- AllocationVectorType *m_pDedicatedAllocations[VK_MAX_MEMORY_TYPES];
+ typedef VmaVector< VmaAllocation, VmaStlAllocator<VmaAllocation> > AllocationVectorType;
+ AllocationVectorType* m_pDedicatedAllocations[VK_MAX_MEMORY_TYPES];
VMA_RW_MUTEX m_DedicatedAllocationsMutex[VK_MAX_MEMORY_TYPES];
- VmaAllocator_T(const VmaAllocatorCreateInfo *pCreateInfo);
- VkResult Init(const VmaAllocatorCreateInfo *pCreateInfo);
+ VmaCurrentBudgetData m_Budget;
+
+ VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo);
+ VkResult Init(const VmaAllocatorCreateInfo* pCreateInfo);
~VmaAllocator_T();
- const VkAllocationCallbacks *GetAllocationCallbacks() const {
+ const VkAllocationCallbacks* GetAllocationCallbacks() const
+ {
return m_AllocationCallbacksSpecified ? &m_AllocationCallbacks : 0;
}
- const VmaVulkanFunctions &GetVulkanFunctions() const {
+ const VmaVulkanFunctions& GetVulkanFunctions() const
+ {
return m_VulkanFunctions;
}
- VkDeviceSize GetBufferImageGranularity() const {
+ VkDeviceSize GetBufferImageGranularity() const
+ {
return VMA_MAX(
- static_cast<VkDeviceSize>(VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY),
- m_PhysicalDeviceProperties.limits.bufferImageGranularity);
+ static_cast<VkDeviceSize>(VMA_DEBUG_MIN_BUFFER_IMAGE_GRANULARITY),
+ m_PhysicalDeviceProperties.limits.bufferImageGranularity);
}
uint32_t GetMemoryHeapCount() const { return m_MemProps.memoryHeapCount; }
uint32_t GetMemoryTypeCount() const { return m_MemProps.memoryTypeCount; }
- uint32_t MemoryTypeIndexToHeapIndex(uint32_t memTypeIndex) const {
+ uint32_t MemoryTypeIndexToHeapIndex(uint32_t memTypeIndex) const
+ {
VMA_ASSERT(memTypeIndex < m_MemProps.memoryTypeCount);
return m_MemProps.memoryTypes[memTypeIndex].heapIndex;
}
// True when specific memory type is HOST_VISIBLE but not HOST_COHERENT.
- bool IsMemoryTypeNonCoherent(uint32_t memTypeIndex) const {
+ bool IsMemoryTypeNonCoherent(uint32_t memTypeIndex) const
+ {
return (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) ==
- VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
}
// Minimum alignment for all allocations in specific memory type.
- VkDeviceSize GetMemoryTypeMinAlignment(uint32_t memTypeIndex) const {
+ VkDeviceSize GetMemoryTypeMinAlignment(uint32_t memTypeIndex) const
+ {
return IsMemoryTypeNonCoherent(memTypeIndex) ?
- VMA_MAX((VkDeviceSize)VMA_DEBUG_ALIGNMENT, m_PhysicalDeviceProperties.limits.nonCoherentAtomSize) :
- (VkDeviceSize)VMA_DEBUG_ALIGNMENT;
+ VMA_MAX((VkDeviceSize)VMA_DEBUG_ALIGNMENT, m_PhysicalDeviceProperties.limits.nonCoherentAtomSize) :
+ (VkDeviceSize)VMA_DEBUG_ALIGNMENT;
}
- bool IsIntegratedGpu() const {
+ bool IsIntegratedGpu() const
+ {
return m_PhysicalDeviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
}
+ uint32_t GetGlobalMemoryTypeBits() const { return m_GlobalMemoryTypeBits; }
+
#if VMA_RECORDING_ENABLED
- VmaRecorder *GetRecorder() const { return m_pRecorder; }
+ VmaRecorder* GetRecorder() const { return m_pRecorder; }
#endif
void GetBufferMemoryRequirements(
- VkBuffer hBuffer,
- VkMemoryRequirements &memReq,
- bool &requiresDedicatedAllocation,
- bool &prefersDedicatedAllocation) const;
+ VkBuffer hBuffer,
+ VkMemoryRequirements& memReq,
+ bool& requiresDedicatedAllocation,
+ bool& prefersDedicatedAllocation) const;
void GetImageMemoryRequirements(
- VkImage hImage,
- VkMemoryRequirements &memReq,
- bool &requiresDedicatedAllocation,
- bool &prefersDedicatedAllocation) const;
+ VkImage hImage,
+ VkMemoryRequirements& memReq,
+ bool& requiresDedicatedAllocation,
+ bool& prefersDedicatedAllocation) const;
// Main allocation function.
VkResult AllocateMemory(
- const VkMemoryRequirements &vkMemReq,
- bool requiresDedicatedAllocation,
- bool prefersDedicatedAllocation,
- VkBuffer dedicatedBuffer,
- VkImage dedicatedImage,
- const VmaAllocationCreateInfo &createInfo,
- VmaSuballocationType suballocType,
- size_t allocationCount,
- VmaAllocation *pAllocations);
+ const VkMemoryRequirements& vkMemReq,
+ bool requiresDedicatedAllocation,
+ bool prefersDedicatedAllocation,
+ VkBuffer dedicatedBuffer,
+ VkImage dedicatedImage,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaSuballocationType suballocType,
+ size_t allocationCount,
+ VmaAllocation* pAllocations);
// Main deallocation function.
void FreeMemory(
- size_t allocationCount,
- const VmaAllocation *pAllocations);
+ size_t allocationCount,
+ const VmaAllocation* pAllocations);
VkResult ResizeAllocation(
- const VmaAllocation alloc,
- VkDeviceSize newSize);
+ const VmaAllocation alloc,
+ VkDeviceSize newSize);
- void CalculateStats(VmaStats *pStats);
+ void CalculateStats(VmaStats* pStats);
+
+ void GetBudget(
+ VmaBudget* outBudget, uint32_t firstHeap, uint32_t heapCount);
#if VMA_STATS_STRING_ENABLED
- void PrintDetailedMap(class VmaJsonWriter &json);
+ void PrintDetailedMap(class VmaJsonWriter& json);
#endif
VkResult DefragmentationBegin(
- const VmaDefragmentationInfo2 &info,
- VmaDefragmentationStats *pStats,
- VmaDefragmentationContext *pContext);
+ const VmaDefragmentationInfo2& info,
+ VmaDefragmentationStats* pStats,
+ VmaDefragmentationContext* pContext);
VkResult DefragmentationEnd(
- VmaDefragmentationContext context);
+ VmaDefragmentationContext context);
+
+ VkResult DefragmentationPassBegin(
+ VmaDefragmentationPassInfo* pInfo,
+ VmaDefragmentationContext context);
+ VkResult DefragmentationPassEnd(
+ VmaDefragmentationContext context);
- void GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo *pAllocationInfo);
+ void GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo* pAllocationInfo);
bool TouchAllocation(VmaAllocation hAllocation);
- VkResult CreatePool(const VmaPoolCreateInfo *pCreateInfo, VmaPool *pPool);
+ VkResult CreatePool(const VmaPoolCreateInfo* pCreateInfo, VmaPool* pPool);
void DestroyPool(VmaPool pool);
- void GetPoolStats(VmaPool pool, VmaPoolStats *pPoolStats);
+ void GetPoolStats(VmaPool pool, VmaPoolStats* pPoolStats);
void SetCurrentFrameIndex(uint32_t frameIndex);
uint32_t GetCurrentFrameIndex() const { return m_CurrentFrameIndex.load(); }
void MakePoolAllocationsLost(
- VmaPool hPool,
- size_t *pLostAllocationCount);
+ VmaPool hPool,
+ size_t* pLostAllocationCount);
VkResult CheckPoolCorruption(VmaPool hPool);
VkResult CheckCorruption(uint32_t memoryTypeBits);
- void CreateLostAllocation(VmaAllocation *pAllocation);
+ void CreateLostAllocation(VmaAllocation* pAllocation);
- VkResult AllocateVulkanMemory(const VkMemoryAllocateInfo *pAllocateInfo, VkDeviceMemory *pMemory);
+ // Call to Vulkan function vkAllocateMemory with accompanying bookkeeping.
+ VkResult AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory);
+ // Call to Vulkan function vkFreeMemory with accompanying bookkeeping.
void FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory);
+ // Call to Vulkan function vkBindBufferMemory or vkBindBufferMemory2KHR.
+ VkResult BindVulkanBuffer(
+ VkDeviceMemory memory,
+ VkDeviceSize memoryOffset,
+ VkBuffer buffer,
+ const void* pNext);
+ // Call to Vulkan function vkBindImageMemory or vkBindImageMemory2KHR.
+ VkResult BindVulkanImage(
+ VkDeviceMemory memory,
+ VkDeviceSize memoryOffset,
+ VkImage image,
+ const void* pNext);
- VkResult Map(VmaAllocation hAllocation, void **ppData);
+ VkResult Map(VmaAllocation hAllocation, void** ppData);
void Unmap(VmaAllocation hAllocation);
- VkResult BindBufferMemory(VmaAllocation hAllocation, VkBuffer hBuffer);
- VkResult BindImageMemory(VmaAllocation hAllocation, VkImage hImage);
+ VkResult BindBufferMemory(
+ VmaAllocation hAllocation,
+ VkDeviceSize allocationLocalOffset,
+ VkBuffer hBuffer,
+ const void* pNext);
+ VkResult BindImageMemory(
+ VmaAllocation hAllocation,
+ VkDeviceSize allocationLocalOffset,
+ VkImage hImage,
+ const void* pNext);
void FlushOrInvalidateAllocation(
- VmaAllocation hAllocation,
- VkDeviceSize offset, VkDeviceSize size,
- VMA_CACHE_OPERATION op);
+ VmaAllocation hAllocation,
+ VkDeviceSize offset, VkDeviceSize size,
+ VMA_CACHE_OPERATION op);
void FillAllocation(const VmaAllocation hAllocation, uint8_t pattern);
/*
- Returns bit mask of memory types that can support defragmentation on GPU as
- they support creation of required buffer for copy operations.
- */
+ Returns bit mask of memory types that can support defragmentation on GPU as
+ they support creation of required buffer for copy operations.
+ */
uint32_t GetGpuDefragmentationMemoryTypeBits();
private:
@@ -6535,7 +7407,7 @@ private:
VkPhysicalDevice m_PhysicalDevice;
VMA_ATOMIC_UINT32 m_CurrentFrameIndex;
VMA_ATOMIC_UINT32 m_GpuDefragmentationMemoryTypeBits; // UINT32_MAX means uninitialized.
-
+
VMA_RW_MUTEX m_PoolsMutex;
// Protected by m_PoolsMutex. Sorted by pointer value.
VmaVector<VmaPool, VmaStlAllocator<VmaPool> > m_Pools;
@@ -6543,93 +7415,110 @@ private:
VmaVulkanFunctions m_VulkanFunctions;
+ // Global bit mask AND-ed with any memoryTypeBits to disallow certain memory types.
+ uint32_t m_GlobalMemoryTypeBits;
+
#if VMA_RECORDING_ENABLED
- VmaRecorder *m_pRecorder;
+ VmaRecorder* m_pRecorder;
#endif
- void ImportVulkanFunctions(const VmaVulkanFunctions *pVulkanFunctions);
+ void ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunctions);
VkDeviceSize CalcPreferredBlockSize(uint32_t memTypeIndex);
VkResult AllocateMemoryOfType(
- VkDeviceSize size,
- VkDeviceSize alignment,
- bool dedicatedAllocation,
- VkBuffer dedicatedBuffer,
- VkImage dedicatedImage,
- const VmaAllocationCreateInfo &createInfo,
- uint32_t memTypeIndex,
- VmaSuballocationType suballocType,
- size_t allocationCount,
- VmaAllocation *pAllocations);
+ VkDeviceSize size,
+ VkDeviceSize alignment,
+ bool dedicatedAllocation,
+ VkBuffer dedicatedBuffer,
+ VkImage dedicatedImage,
+ const VmaAllocationCreateInfo& createInfo,
+ uint32_t memTypeIndex,
+ VmaSuballocationType suballocType,
+ size_t allocationCount,
+ VmaAllocation* pAllocations);
// Helper function only to be used inside AllocateDedicatedMemory.
VkResult AllocateDedicatedMemoryPage(
- VkDeviceSize size,
- VmaSuballocationType suballocType,
- uint32_t memTypeIndex,
- const VkMemoryAllocateInfo &allocInfo,
- bool map,
- bool isUserDataString,
- void *pUserData,
- VmaAllocation *pAllocation);
+ VkDeviceSize size,
+ VmaSuballocationType suballocType,
+ uint32_t memTypeIndex,
+ const VkMemoryAllocateInfo& allocInfo,
+ bool map,
+ bool isUserDataString,
+ void* pUserData,
+ VmaAllocation* pAllocation);
// Allocates and registers new VkDeviceMemory specifically for dedicated allocations.
VkResult AllocateDedicatedMemory(
- VkDeviceSize size,
- VmaSuballocationType suballocType,
- uint32_t memTypeIndex,
- bool map,
- bool isUserDataString,
- void *pUserData,
- VkBuffer dedicatedBuffer,
- VkImage dedicatedImage,
- size_t allocationCount,
- VmaAllocation *pAllocations);
-
- // Tries to free pMemory as Dedicated Memory. Returns true if found and freed.
- void FreeDedicatedMemory(VmaAllocation allocation);
+ VkDeviceSize size,
+ VmaSuballocationType suballocType,
+ uint32_t memTypeIndex,
+ bool withinBudget,
+ bool map,
+ bool isUserDataString,
+ void* pUserData,
+ VkBuffer dedicatedBuffer,
+ VkImage dedicatedImage,
+ size_t allocationCount,
+ VmaAllocation* pAllocations);
+
+ void FreeDedicatedMemory(const VmaAllocation allocation);
/*
- Calculates and returns bit mask of memory types that can support defragmentation
- on GPU as they support creation of required buffer for copy operations.
- */
+ Calculates and returns bit mask of memory types that can support defragmentation
+ on GPU as they support creation of required buffer for copy operations.
+ */
uint32_t CalculateGpuDefragmentationMemoryTypeBits() const;
+
+ uint32_t CalculateGlobalMemoryTypeBits() const;
+
+#if VMA_MEMORY_BUDGET
+ void UpdateVulkanBudget();
+#endif // #if VMA_MEMORY_BUDGET
};
////////////////////////////////////////////////////////////////////////////////
// Memory allocation #2 after VmaAllocator_T definition
-static void *VmaMalloc(VmaAllocator hAllocator, size_t size, size_t alignment) {
+static void* VmaMalloc(VmaAllocator hAllocator, size_t size, size_t alignment)
+{
return VmaMalloc(&hAllocator->m_AllocationCallbacks, size, alignment);
}
-static void VmaFree(VmaAllocator hAllocator, void *ptr) {
+static void VmaFree(VmaAllocator hAllocator, void* ptr)
+{
VmaFree(&hAllocator->m_AllocationCallbacks, ptr);
}
-template <typename T>
-static T *VmaAllocate(VmaAllocator hAllocator) {
- return (T *)VmaMalloc(hAllocator, sizeof(T), VMA_ALIGN_OF(T));
+template<typename T>
+static T* VmaAllocate(VmaAllocator hAllocator)
+{
+ return (T*)VmaMalloc(hAllocator, sizeof(T), VMA_ALIGN_OF(T));
}
-template <typename T>
-static T *VmaAllocateArray(VmaAllocator hAllocator, size_t count) {
- return (T *)VmaMalloc(hAllocator, sizeof(T) * count, VMA_ALIGN_OF(T));
+template<typename T>
+static T* VmaAllocateArray(VmaAllocator hAllocator, size_t count)
+{
+ return (T*)VmaMalloc(hAllocator, sizeof(T) * count, VMA_ALIGN_OF(T));
}
-template <typename T>
-static void vma_delete(VmaAllocator hAllocator, T *ptr) {
- if (ptr != VMA_NULL) {
+template<typename T>
+static void vma_delete(VmaAllocator hAllocator, T* ptr)
+{
+ if(ptr != VMA_NULL)
+ {
ptr->~T();
VmaFree(hAllocator, ptr);
}
}
-template <typename T>
-static void vma_delete_array(VmaAllocator hAllocator, T *ptr, size_t count) {
- if (ptr != VMA_NULL) {
- for (size_t i = count; i--;)
+template<typename T>
+static void vma_delete_array(VmaAllocator hAllocator, T* ptr, size_t count)
+{
+ if(ptr != VMA_NULL)
+ {
+ for(size_t i = count; i--; )
ptr[i].~T();
VmaFree(hAllocator, ptr);
}
@@ -6640,46 +7529,65 @@ static void vma_delete_array(VmaAllocator hAllocator, T *ptr, size_t count) {
#if VMA_STATS_STRING_ENABLED
-class VmaStringBuilder {
+class VmaStringBuilder
+{
public:
- VmaStringBuilder(VmaAllocator alloc) :
- m_Data(VmaStlAllocator<char>(alloc->GetAllocationCallbacks())) {}
+ VmaStringBuilder(VmaAllocator alloc) : m_Data(VmaStlAllocator<char>(alloc->GetAllocationCallbacks())) { }
size_t GetLength() const { return m_Data.size(); }
- const char *GetData() const { return m_Data.data(); }
+ const char* GetData() const { return m_Data.data(); }
void Add(char ch) { m_Data.push_back(ch); }
- void Add(const char *pStr);
+ void Add(const char* pStr);
void AddNewLine() { Add('\n'); }
void AddNumber(uint32_t num);
void AddNumber(uint64_t num);
- void AddPointer(const void *ptr);
+ void AddPointer(const void* ptr);
private:
- VmaVector<char, VmaStlAllocator<char> > m_Data;
+ VmaVector< char, VmaStlAllocator<char> > m_Data;
};
-void VmaStringBuilder::Add(const char *pStr) {
+void VmaStringBuilder::Add(const char* pStr)
+{
const size_t strLen = strlen(pStr);
- if (strLen > 0) {
+ if(strLen > 0)
+ {
const size_t oldCount = m_Data.size();
m_Data.resize(oldCount + strLen);
memcpy(m_Data.data() + oldCount, pStr, strLen);
}
}
-void VmaStringBuilder::AddNumber(uint32_t num) {
+void VmaStringBuilder::AddNumber(uint32_t num)
+{
char buf[11];
- VmaUint32ToStr(buf, sizeof(buf), num);
- Add(buf);
+ buf[10] = '\0';
+ char *p = &buf[10];
+ do
+ {
+ *--p = '0' + (num % 10);
+ num /= 10;
+ }
+ while(num);
+ Add(p);
}
-void VmaStringBuilder::AddNumber(uint64_t num) {
+void VmaStringBuilder::AddNumber(uint64_t num)
+{
char buf[21];
- VmaUint64ToStr(buf, sizeof(buf), num);
- Add(buf);
+ buf[20] = '\0';
+ char *p = &buf[20];
+ do
+ {
+ *--p = '0' + (num % 10);
+ num /= 10;
+ }
+ while(num);
+ Add(p);
}
-void VmaStringBuilder::AddPointer(const void *ptr) {
+void VmaStringBuilder::AddPointer(const void* ptr)
+{
char buf[21];
VmaPtrToStr(buf, sizeof(buf), ptr);
Add(buf);
@@ -6692,66 +7600,72 @@ void VmaStringBuilder::AddPointer(const void *ptr) {
#if VMA_STATS_STRING_ENABLED
-class VmaJsonWriter {
+class VmaJsonWriter
+{
VMA_CLASS_NO_COPY(VmaJsonWriter)
public:
- VmaJsonWriter(const VkAllocationCallbacks *pAllocationCallbacks, VmaStringBuilder &sb);
+ VmaJsonWriter(const VkAllocationCallbacks* pAllocationCallbacks, VmaStringBuilder& sb);
~VmaJsonWriter();
void BeginObject(bool singleLine = false);
void EndObject();
-
+
void BeginArray(bool singleLine = false);
void EndArray();
-
- void WriteString(const char *pStr);
- void BeginString(const char *pStr = VMA_NULL);
- void ContinueString(const char *pStr);
+
+ void WriteString(const char* pStr);
+ void BeginString(const char* pStr = VMA_NULL);
+ void ContinueString(const char* pStr);
void ContinueString(uint32_t n);
void ContinueString(uint64_t n);
- void ContinueString_Pointer(const void *ptr);
- void EndString(const char *pStr = VMA_NULL);
-
+ void ContinueString_Pointer(const void* ptr);
+ void EndString(const char* pStr = VMA_NULL);
+
void WriteNumber(uint32_t n);
void WriteNumber(uint64_t n);
void WriteBool(bool b);
void WriteNull();
private:
- static const char *const INDENT;
+ static const char* const INDENT;
- enum COLLECTION_TYPE {
+ enum COLLECTION_TYPE
+ {
COLLECTION_TYPE_OBJECT,
COLLECTION_TYPE_ARRAY,
};
- struct StackItem {
+ struct StackItem
+ {
COLLECTION_TYPE type;
uint32_t valueCount;
bool singleLineMode;
};
- VmaStringBuilder &m_SB;
- VmaVector<StackItem, VmaStlAllocator<StackItem> > m_Stack;
+ VmaStringBuilder& m_SB;
+ VmaVector< StackItem, VmaStlAllocator<StackItem> > m_Stack;
bool m_InsideString;
void BeginValue(bool isString);
void WriteIndent(bool oneLess = false);
};
-const char *const VmaJsonWriter::INDENT = " ";
+const char* const VmaJsonWriter::INDENT = " ";
-VmaJsonWriter::VmaJsonWriter(const VkAllocationCallbacks *pAllocationCallbacks, VmaStringBuilder &sb) :
- m_SB(sb),
- m_Stack(VmaStlAllocator<StackItem>(pAllocationCallbacks)),
- m_InsideString(false) {
+VmaJsonWriter::VmaJsonWriter(const VkAllocationCallbacks* pAllocationCallbacks, VmaStringBuilder& sb) :
+ m_SB(sb),
+ m_Stack(VmaStlAllocator<StackItem>(pAllocationCallbacks)),
+ m_InsideString(false)
+{
}
-VmaJsonWriter::~VmaJsonWriter() {
+VmaJsonWriter::~VmaJsonWriter()
+{
VMA_ASSERT(!m_InsideString);
VMA_ASSERT(m_Stack.empty());
}
-void VmaJsonWriter::BeginObject(bool singleLine) {
+void VmaJsonWriter::BeginObject(bool singleLine)
+{
VMA_ASSERT(!m_InsideString);
BeginValue(false);
@@ -6764,7 +7678,8 @@ void VmaJsonWriter::BeginObject(bool singleLine) {
m_Stack.push_back(item);
}
-void VmaJsonWriter::EndObject() {
+void VmaJsonWriter::EndObject()
+{
VMA_ASSERT(!m_InsideString);
WriteIndent(true);
@@ -6774,7 +7689,8 @@ void VmaJsonWriter::EndObject() {
m_Stack.pop_back();
}
-void VmaJsonWriter::BeginArray(bool singleLine) {
+void VmaJsonWriter::BeginArray(bool singleLine)
+{
VMA_ASSERT(!m_InsideString);
BeginValue(false);
@@ -6787,7 +7703,8 @@ void VmaJsonWriter::BeginArray(bool singleLine) {
m_Stack.push_back(item);
}
-void VmaJsonWriter::EndArray() {
+void VmaJsonWriter::EndArray()
+{
VMA_ASSERT(!m_InsideString);
WriteIndent(true);
@@ -6797,136 +7714,168 @@ void VmaJsonWriter::EndArray() {
m_Stack.pop_back();
}
-void VmaJsonWriter::WriteString(const char *pStr) {
+void VmaJsonWriter::WriteString(const char* pStr)
+{
BeginString(pStr);
EndString();
}
-void VmaJsonWriter::BeginString(const char *pStr) {
+void VmaJsonWriter::BeginString(const char* pStr)
+{
VMA_ASSERT(!m_InsideString);
BeginValue(true);
m_SB.Add('"');
m_InsideString = true;
- if (pStr != VMA_NULL && pStr[0] != '\0') {
+ if(pStr != VMA_NULL && pStr[0] != '\0')
+ {
ContinueString(pStr);
}
}
-void VmaJsonWriter::ContinueString(const char *pStr) {
+void VmaJsonWriter::ContinueString(const char* pStr)
+{
VMA_ASSERT(m_InsideString);
const size_t strLen = strlen(pStr);
- for (size_t i = 0; i < strLen; ++i) {
+ for(size_t i = 0; i < strLen; ++i)
+ {
char ch = pStr[i];
- if (ch == '\\') {
+ if(ch == '\\')
+ {
m_SB.Add("\\\\");
- } else if (ch == '"') {
+ }
+ else if(ch == '"')
+ {
m_SB.Add("\\\"");
- } else if (ch >= 32) {
+ }
+ else if(ch >= 32)
+ {
m_SB.Add(ch);
- } else
- switch (ch) {
- case '\b':
- m_SB.Add("\\b");
- break;
- case '\f':
- m_SB.Add("\\f");
- break;
- case '\n':
- m_SB.Add("\\n");
- break;
- case '\r':
- m_SB.Add("\\r");
- break;
- case '\t':
- m_SB.Add("\\t");
- break;
- default:
- VMA_ASSERT(0 && "Character not currently supported.");
- break;
- }
+ }
+ else switch(ch)
+ {
+ case '\b':
+ m_SB.Add("\\b");
+ break;
+ case '\f':
+ m_SB.Add("\\f");
+ break;
+ case '\n':
+ m_SB.Add("\\n");
+ break;
+ case '\r':
+ m_SB.Add("\\r");
+ break;
+ case '\t':
+ m_SB.Add("\\t");
+ break;
+ default:
+ VMA_ASSERT(0 && "Character not currently supported.");
+ break;
+ }
}
}
-void VmaJsonWriter::ContinueString(uint32_t n) {
+void VmaJsonWriter::ContinueString(uint32_t n)
+{
VMA_ASSERT(m_InsideString);
m_SB.AddNumber(n);
}
-void VmaJsonWriter::ContinueString(uint64_t n) {
+void VmaJsonWriter::ContinueString(uint64_t n)
+{
VMA_ASSERT(m_InsideString);
m_SB.AddNumber(n);
}
-void VmaJsonWriter::ContinueString_Pointer(const void *ptr) {
+void VmaJsonWriter::ContinueString_Pointer(const void* ptr)
+{
VMA_ASSERT(m_InsideString);
m_SB.AddPointer(ptr);
}
-void VmaJsonWriter::EndString(const char *pStr) {
+void VmaJsonWriter::EndString(const char* pStr)
+{
VMA_ASSERT(m_InsideString);
- if (pStr != VMA_NULL && pStr[0] != '\0') {
+ if(pStr != VMA_NULL && pStr[0] != '\0')
+ {
ContinueString(pStr);
}
m_SB.Add('"');
m_InsideString = false;
}
-void VmaJsonWriter::WriteNumber(uint32_t n) {
+void VmaJsonWriter::WriteNumber(uint32_t n)
+{
VMA_ASSERT(!m_InsideString);
BeginValue(false);
m_SB.AddNumber(n);
}
-void VmaJsonWriter::WriteNumber(uint64_t n) {
+void VmaJsonWriter::WriteNumber(uint64_t n)
+{
VMA_ASSERT(!m_InsideString);
BeginValue(false);
m_SB.AddNumber(n);
}
-void VmaJsonWriter::WriteBool(bool b) {
+void VmaJsonWriter::WriteBool(bool b)
+{
VMA_ASSERT(!m_InsideString);
BeginValue(false);
m_SB.Add(b ? "true" : "false");
}
-void VmaJsonWriter::WriteNull() {
+void VmaJsonWriter::WriteNull()
+{
VMA_ASSERT(!m_InsideString);
BeginValue(false);
m_SB.Add("null");
}
-void VmaJsonWriter::BeginValue(bool isString) {
- if (!m_Stack.empty()) {
- StackItem &currItem = m_Stack.back();
- if (currItem.type == COLLECTION_TYPE_OBJECT &&
- currItem.valueCount % 2 == 0) {
+void VmaJsonWriter::BeginValue(bool isString)
+{
+ if(!m_Stack.empty())
+ {
+ StackItem& currItem = m_Stack.back();
+ if(currItem.type == COLLECTION_TYPE_OBJECT &&
+ currItem.valueCount % 2 == 0)
+ {
VMA_ASSERT(isString);
}
- if (currItem.type == COLLECTION_TYPE_OBJECT &&
- currItem.valueCount % 2 != 0) {
+ if(currItem.type == COLLECTION_TYPE_OBJECT &&
+ currItem.valueCount % 2 != 0)
+ {
m_SB.Add(": ");
- } else if (currItem.valueCount > 0) {
+ }
+ else if(currItem.valueCount > 0)
+ {
m_SB.Add(", ");
WriteIndent();
- } else {
+ }
+ else
+ {
WriteIndent();
}
++currItem.valueCount;
}
}
-void VmaJsonWriter::WriteIndent(bool oneLess) {
- if (!m_Stack.empty() && !m_Stack.back().singleLineMode) {
+void VmaJsonWriter::WriteIndent(bool oneLess)
+{
+ if(!m_Stack.empty() && !m_Stack.back().singleLineMode)
+ {
m_SB.AddNewLine();
-
+
size_t count = m_Stack.size();
- if (count > 0 && oneLess) {
+ if(count > 0 && oneLess)
+ {
--count;
}
- for (size_t i = 0; i < count; ++i) {
+ for(size_t i = 0; i < count; ++i)
+ {
m_SB.Add(INDENT);
}
}
@@ -6936,35 +7885,38 @@ void VmaJsonWriter::WriteIndent(bool oneLess) {
////////////////////////////////////////////////////////////////////////////////
-void VmaAllocation_T::SetUserData(VmaAllocator hAllocator, void *pUserData) {
- if (IsUserDataString()) {
+void VmaAllocation_T::SetUserData(VmaAllocator hAllocator, void* pUserData)
+{
+ if(IsUserDataString())
+ {
VMA_ASSERT(pUserData == VMA_NULL || pUserData != m_pUserData);
FreeUserDataString(hAllocator);
- if (pUserData != VMA_NULL) {
- const char *const newStrSrc = (char *)pUserData;
- const size_t newStrLen = strlen(newStrSrc);
- char *const newStrDst = vma_new_array(hAllocator, char, newStrLen + 1);
- memcpy(newStrDst, newStrSrc, newStrLen + 1);
- m_pUserData = newStrDst;
+ if(pUserData != VMA_NULL)
+ {
+ m_pUserData = VmaCreateStringCopy(hAllocator->GetAllocationCallbacks(), (const char*)pUserData);
}
- } else {
+ }
+ else
+ {
m_pUserData = pUserData;
}
}
void VmaAllocation_T::ChangeBlockAllocation(
- VmaAllocator hAllocator,
- VmaDeviceMemoryBlock *block,
- VkDeviceSize offset) {
+ VmaAllocator hAllocator,
+ VmaDeviceMemoryBlock* block,
+ VkDeviceSize offset)
+{
VMA_ASSERT(block != VMA_NULL);
VMA_ASSERT(m_Type == ALLOCATION_TYPE_BLOCK);
// Move mapping reference counter from old block to new block.
- if (block != m_BlockAllocation.m_Block) {
+ if(block != m_BlockAllocation.m_Block)
+ {
uint32_t mapRefCount = m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP;
- if (IsPersistentMap())
+ if(IsPersistentMap())
++mapRefCount;
m_BlockAllocation.m_Block->Unmap(hAllocator, mapRefCount);
block->Map(hAllocator, mapRefCount, VMA_NULL);
@@ -6974,101 +7926,103 @@ void VmaAllocation_T::ChangeBlockAllocation(
m_BlockAllocation.m_Offset = offset;
}
-void VmaAllocation_T::ChangeSize(VkDeviceSize newSize) {
- VMA_ASSERT(newSize > 0);
- m_Size = newSize;
-}
-
-void VmaAllocation_T::ChangeOffset(VkDeviceSize newOffset) {
+void VmaAllocation_T::ChangeOffset(VkDeviceSize newOffset)
+{
VMA_ASSERT(m_Type == ALLOCATION_TYPE_BLOCK);
m_BlockAllocation.m_Offset = newOffset;
}
-VkDeviceSize VmaAllocation_T::GetOffset() const {
- switch (m_Type) {
- case ALLOCATION_TYPE_BLOCK:
- return m_BlockAllocation.m_Offset;
- case ALLOCATION_TYPE_DEDICATED:
- return 0;
- default:
- VMA_ASSERT(0);
- return 0;
- }
-}
-
-VkDeviceMemory VmaAllocation_T::GetMemory() const {
- switch (m_Type) {
- case ALLOCATION_TYPE_BLOCK:
- return m_BlockAllocation.m_Block->GetDeviceMemory();
- case ALLOCATION_TYPE_DEDICATED:
- return m_DedicatedAllocation.m_hMemory;
- default:
- VMA_ASSERT(0);
- return VK_NULL_HANDLE;
+VkDeviceSize VmaAllocation_T::GetOffset() const
+{
+ switch(m_Type)
+ {
+ case ALLOCATION_TYPE_BLOCK:
+ return m_BlockAllocation.m_Offset;
+ case ALLOCATION_TYPE_DEDICATED:
+ return 0;
+ default:
+ VMA_ASSERT(0);
+ return 0;
}
}
-uint32_t VmaAllocation_T::GetMemoryTypeIndex() const {
- switch (m_Type) {
- case ALLOCATION_TYPE_BLOCK:
- return m_BlockAllocation.m_Block->GetMemoryTypeIndex();
- case ALLOCATION_TYPE_DEDICATED:
- return m_DedicatedAllocation.m_MemoryTypeIndex;
- default:
- VMA_ASSERT(0);
- return UINT32_MAX;
+VkDeviceMemory VmaAllocation_T::GetMemory() const
+{
+ switch(m_Type)
+ {
+ case ALLOCATION_TYPE_BLOCK:
+ return m_BlockAllocation.m_Block->GetDeviceMemory();
+ case ALLOCATION_TYPE_DEDICATED:
+ return m_DedicatedAllocation.m_hMemory;
+ default:
+ VMA_ASSERT(0);
+ return VK_NULL_HANDLE;
}
}
-void *VmaAllocation_T::GetMappedData() const {
- switch (m_Type) {
- case ALLOCATION_TYPE_BLOCK:
- if (m_MapCount != 0) {
- void *pBlockData = m_BlockAllocation.m_Block->GetMappedData();
- VMA_ASSERT(pBlockData != VMA_NULL);
- return (char *)pBlockData + m_BlockAllocation.m_Offset;
- } else {
- return VMA_NULL;
- }
- break;
- case ALLOCATION_TYPE_DEDICATED:
- VMA_ASSERT((m_DedicatedAllocation.m_pMappedData != VMA_NULL) == (m_MapCount != 0));
- return m_DedicatedAllocation.m_pMappedData;
- default:
- VMA_ASSERT(0);
+void* VmaAllocation_T::GetMappedData() const
+{
+ switch(m_Type)
+ {
+ case ALLOCATION_TYPE_BLOCK:
+ if(m_MapCount != 0)
+ {
+ void* pBlockData = m_BlockAllocation.m_Block->GetMappedData();
+ VMA_ASSERT(pBlockData != VMA_NULL);
+ return (char*)pBlockData + m_BlockAllocation.m_Offset;
+ }
+ else
+ {
return VMA_NULL;
+ }
+ break;
+ case ALLOCATION_TYPE_DEDICATED:
+ VMA_ASSERT((m_DedicatedAllocation.m_pMappedData != VMA_NULL) == (m_MapCount != 0));
+ return m_DedicatedAllocation.m_pMappedData;
+ default:
+ VMA_ASSERT(0);
+ return VMA_NULL;
}
}
-bool VmaAllocation_T::CanBecomeLost() const {
- switch (m_Type) {
- case ALLOCATION_TYPE_BLOCK:
- return m_BlockAllocation.m_CanBecomeLost;
- case ALLOCATION_TYPE_DEDICATED:
- return false;
- default:
- VMA_ASSERT(0);
- return false;
+bool VmaAllocation_T::CanBecomeLost() const
+{
+ switch(m_Type)
+ {
+ case ALLOCATION_TYPE_BLOCK:
+ return m_BlockAllocation.m_CanBecomeLost;
+ case ALLOCATION_TYPE_DEDICATED:
+ return false;
+ default:
+ VMA_ASSERT(0);
+ return false;
}
}
-bool VmaAllocation_T::MakeLost(uint32_t currentFrameIndex, uint32_t frameInUseCount) {
+bool VmaAllocation_T::MakeLost(uint32_t currentFrameIndex, uint32_t frameInUseCount)
+{
VMA_ASSERT(CanBecomeLost());
/*
- Warning: This is a carefully designed algorithm.
- Do not modify unless you really know what you're doing :)
- */
+ Warning: This is a carefully designed algorithm.
+ Do not modify unless you really know what you're doing :)
+ */
uint32_t localLastUseFrameIndex = GetLastUseFrameIndex();
- for (;;) {
- if (localLastUseFrameIndex == VMA_FRAME_INDEX_LOST) {
+ for(;;)
+ {
+ if(localLastUseFrameIndex == VMA_FRAME_INDEX_LOST)
+ {
VMA_ASSERT(0);
return false;
- } else if (localLastUseFrameIndex + frameInUseCount >= currentFrameIndex) {
+ }
+ else if(localLastUseFrameIndex + frameInUseCount >= currentFrameIndex)
+ {
return false;
- } else // Last use time earlier than current time.
+ }
+ else // Last use time earlier than current time.
{
- if (CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, VMA_FRAME_INDEX_LOST)) {
+ if(CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, VMA_FRAME_INDEX_LOST))
+ {
// Setting hAllocation.LastUseFrameIndex atomic to VMA_FRAME_INDEX_LOST is enough to mark it as LOST.
// Calling code just needs to unregister this allocation in owning VmaDeviceMemoryBlock.
return true;
@@ -7080,7 +8034,7 @@ bool VmaAllocation_T::MakeLost(uint32_t currentFrameIndex, uint32_t frameInUseCo
#if VMA_STATS_STRING_ENABLED
// Correspond to values of enum VmaSuballocationType.
-static const char *VMA_SUBALLOCATION_TYPE_NAMES[] = {
+static const char* VMA_SUBALLOCATION_TYPE_NAMES[] = {
"FREE",
"UNKNOWN",
"BUFFER",
@@ -7089,18 +8043,23 @@ static const char *VMA_SUBALLOCATION_TYPE_NAMES[] = {
"IMAGE_OPTIMAL",
};
-void VmaAllocation_T::PrintParameters(class VmaJsonWriter &json) const {
+void VmaAllocation_T::PrintParameters(class VmaJsonWriter& json) const
+{
json.WriteString("Type");
json.WriteString(VMA_SUBALLOCATION_TYPE_NAMES[m_SuballocationType]);
json.WriteString("Size");
json.WriteNumber(m_Size);
- if (m_pUserData != VMA_NULL) {
+ if(m_pUserData != VMA_NULL)
+ {
json.WriteString("UserData");
- if (IsUserDataString()) {
- json.WriteString((const char *)m_pUserData);
- } else {
+ if(IsUserDataString())
+ {
+ json.WriteString((const char*)m_pUserData);
+ }
+ else
+ {
json.BeginString();
json.ContinueString_Pointer(m_pUserData);
json.EndString();
@@ -7113,7 +8072,8 @@ void VmaAllocation_T::PrintParameters(class VmaJsonWriter &json) const {
json.WriteString("LastUseFrameIndex");
json.WriteNumber(GetLastUseFrameIndex());
- if (m_BufferImageUsage != 0) {
+ if(m_BufferImageUsage != 0)
+ {
json.WriteString("Usage");
json.WriteNumber(m_BufferImageUsage);
}
@@ -7121,58 +8081,71 @@ void VmaAllocation_T::PrintParameters(class VmaJsonWriter &json) const {
#endif
-void VmaAllocation_T::FreeUserDataString(VmaAllocator hAllocator) {
+void VmaAllocation_T::FreeUserDataString(VmaAllocator hAllocator)
+{
VMA_ASSERT(IsUserDataString());
- if (m_pUserData != VMA_NULL) {
- char *const oldStr = (char *)m_pUserData;
- const size_t oldStrLen = strlen(oldStr);
- vma_delete_array(hAllocator, oldStr, oldStrLen + 1);
- m_pUserData = VMA_NULL;
- }
+ VmaFreeString(hAllocator->GetAllocationCallbacks(), (char*)m_pUserData);
+ m_pUserData = VMA_NULL;
}
-void VmaAllocation_T::BlockAllocMap() {
+void VmaAllocation_T::BlockAllocMap()
+{
VMA_ASSERT(GetType() == ALLOCATION_TYPE_BLOCK);
- if ((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) < 0x7F) {
+ if((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) < 0x7F)
+ {
++m_MapCount;
- } else {
+ }
+ else
+ {
VMA_ASSERT(0 && "Allocation mapped too many times simultaneously.");
}
}
-void VmaAllocation_T::BlockAllocUnmap() {
+void VmaAllocation_T::BlockAllocUnmap()
+{
VMA_ASSERT(GetType() == ALLOCATION_TYPE_BLOCK);
- if ((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) != 0) {
+ if((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) != 0)
+ {
--m_MapCount;
- } else {
+ }
+ else
+ {
VMA_ASSERT(0 && "Unmapping allocation not previously mapped.");
}
}
-VkResult VmaAllocation_T::DedicatedAllocMap(VmaAllocator hAllocator, void **ppData) {
+VkResult VmaAllocation_T::DedicatedAllocMap(VmaAllocator hAllocator, void** ppData)
+{
VMA_ASSERT(GetType() == ALLOCATION_TYPE_DEDICATED);
- if (m_MapCount != 0) {
- if ((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) < 0x7F) {
+ if(m_MapCount != 0)
+ {
+ if((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) < 0x7F)
+ {
VMA_ASSERT(m_DedicatedAllocation.m_pMappedData != VMA_NULL);
*ppData = m_DedicatedAllocation.m_pMappedData;
++m_MapCount;
return VK_SUCCESS;
- } else {
+ }
+ else
+ {
VMA_ASSERT(0 && "Dedicated allocation mapped too many times simultaneously.");
return VK_ERROR_MEMORY_MAP_FAILED;
}
- } else {
+ }
+ else
+ {
VkResult result = (*hAllocator->GetVulkanFunctions().vkMapMemory)(
- hAllocator->m_hDevice,
- m_DedicatedAllocation.m_hMemory,
- 0, // offset
- VK_WHOLE_SIZE,
- 0, // flags
- ppData);
- if (result == VK_SUCCESS) {
+ hAllocator->m_hDevice,
+ m_DedicatedAllocation.m_hMemory,
+ 0, // offset
+ VK_WHOLE_SIZE,
+ 0, // flags
+ ppData);
+ if(result == VK_SUCCESS)
+ {
m_DedicatedAllocation.m_pMappedData = *ppData;
m_MapCount = 1;
}
@@ -7180,25 +8153,31 @@ VkResult VmaAllocation_T::DedicatedAllocMap(VmaAllocator hAllocator, void **ppDa
}
}
-void VmaAllocation_T::DedicatedAllocUnmap(VmaAllocator hAllocator) {
+void VmaAllocation_T::DedicatedAllocUnmap(VmaAllocator hAllocator)
+{
VMA_ASSERT(GetType() == ALLOCATION_TYPE_DEDICATED);
- if ((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) != 0) {
+ if((m_MapCount & ~MAP_COUNT_FLAG_PERSISTENT_MAP) != 0)
+ {
--m_MapCount;
- if (m_MapCount == 0) {
+ if(m_MapCount == 0)
+ {
m_DedicatedAllocation.m_pMappedData = VMA_NULL;
(*hAllocator->GetVulkanFunctions().vkUnmapMemory)(
- hAllocator->m_hDevice,
- m_DedicatedAllocation.m_hMemory);
+ hAllocator->m_hDevice,
+ m_DedicatedAllocation.m_hMemory);
}
- } else {
+ }
+ else
+ {
VMA_ASSERT(0 && "Unmapping dedicated allocation not previously mapped.");
}
}
#if VMA_STATS_STRING_ENABLED
-static void VmaPrintStatInfo(VmaJsonWriter &json, const VmaStatInfo &stat) {
+static void VmaPrintStatInfo(VmaJsonWriter& json, const VmaStatInfo& stat)
+{
json.BeginObject();
json.WriteString("Blocks");
@@ -7216,7 +8195,8 @@ static void VmaPrintStatInfo(VmaJsonWriter &json, const VmaStatInfo &stat) {
json.WriteString("UnusedBytes");
json.WriteNumber(stat.unusedBytes);
- if (stat.allocationCount > 1) {
+ if(stat.allocationCount > 1)
+ {
json.WriteString("AllocationSize");
json.BeginObject(true);
json.WriteString("Min");
@@ -7228,7 +8208,8 @@ static void VmaPrintStatInfo(VmaJsonWriter &json, const VmaStatInfo &stat) {
json.EndObject();
}
- if (stat.unusedRangeCount > 1) {
+ if(stat.unusedRangeCount > 1)
+ {
json.WriteString("UnusedRangeSize");
json.BeginObject(true);
json.WriteString("Min");
@@ -7245,33 +8226,39 @@ static void VmaPrintStatInfo(VmaJsonWriter &json, const VmaStatInfo &stat) {
#endif // #if VMA_STATS_STRING_ENABLED
-struct VmaSuballocationItemSizeLess {
+struct VmaSuballocationItemSizeLess
+{
bool operator()(
- const VmaSuballocationList::iterator lhs,
- const VmaSuballocationList::iterator rhs) const {
+ const VmaSuballocationList::iterator lhs,
+ const VmaSuballocationList::iterator rhs) const
+ {
return lhs->size < rhs->size;
}
bool operator()(
- const VmaSuballocationList::iterator lhs,
- VkDeviceSize rhsSize) const {
+ const VmaSuballocationList::iterator lhs,
+ VkDeviceSize rhsSize) const
+ {
return lhs->size < rhsSize;
}
};
+
////////////////////////////////////////////////////////////////////////////////
// class VmaBlockMetadata
VmaBlockMetadata::VmaBlockMetadata(VmaAllocator hAllocator) :
- m_Size(0),
- m_pAllocationCallbacks(hAllocator->GetAllocationCallbacks()) {
+ m_Size(0),
+ m_pAllocationCallbacks(hAllocator->GetAllocationCallbacks())
+{
}
#if VMA_STATS_STRING_ENABLED
-void VmaBlockMetadata::PrintDetailedMap_Begin(class VmaJsonWriter &json,
- VkDeviceSize unusedBytes,
- size_t allocationCount,
- size_t unusedRangeCount) const {
+void VmaBlockMetadata::PrintDetailedMap_Begin(class VmaJsonWriter& json,
+ VkDeviceSize unusedBytes,
+ size_t allocationCount,
+ size_t unusedRangeCount) const
+{
json.BeginObject();
json.WriteString("TotalBytes");
@@ -7290,11 +8277,12 @@ void VmaBlockMetadata::PrintDetailedMap_Begin(class VmaJsonWriter &json,
json.BeginArray();
}
-void VmaBlockMetadata::PrintDetailedMap_Allocation(class VmaJsonWriter &json,
- VkDeviceSize offset,
- VmaAllocation hAllocation) const {
+void VmaBlockMetadata::PrintDetailedMap_Allocation(class VmaJsonWriter& json,
+ VkDeviceSize offset,
+ VmaAllocation hAllocation) const
+{
json.BeginObject(true);
-
+
json.WriteString("Offset");
json.WriteNumber(offset);
@@ -7303,11 +8291,12 @@ void VmaBlockMetadata::PrintDetailedMap_Allocation(class VmaJsonWriter &json,
json.EndObject();
}
-void VmaBlockMetadata::PrintDetailedMap_UnusedRange(class VmaJsonWriter &json,
- VkDeviceSize offset,
- VkDeviceSize size) const {
+void VmaBlockMetadata::PrintDetailedMap_UnusedRange(class VmaJsonWriter& json,
+ VkDeviceSize offset,
+ VkDeviceSize size) const
+{
json.BeginObject(true);
-
+
json.WriteString("Offset");
json.WriteNumber(offset);
@@ -7320,7 +8309,8 @@ void VmaBlockMetadata::PrintDetailedMap_UnusedRange(class VmaJsonWriter &json,
json.EndObject();
}
-void VmaBlockMetadata::PrintDetailedMap_End(class VmaJsonWriter &json) const {
+void VmaBlockMetadata::PrintDetailedMap_End(class VmaJsonWriter& json) const
+{
json.EndArray();
json.EndObject();
}
@@ -7331,17 +8321,20 @@ void VmaBlockMetadata::PrintDetailedMap_End(class VmaJsonWriter &json) const {
// class VmaBlockMetadata_Generic
VmaBlockMetadata_Generic::VmaBlockMetadata_Generic(VmaAllocator hAllocator) :
- VmaBlockMetadata(hAllocator),
- m_FreeCount(0),
- m_SumFreeSize(0),
- m_Suballocations(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())),
- m_FreeSuballocationsBySize(VmaStlAllocator<VmaSuballocationList::iterator>(hAllocator->GetAllocationCallbacks())) {
+ VmaBlockMetadata(hAllocator),
+ m_FreeCount(0),
+ m_SumFreeSize(0),
+ m_Suballocations(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())),
+ m_FreeSuballocationsBySize(VmaStlAllocator<VmaSuballocationList::iterator>(hAllocator->GetAllocationCallbacks()))
+{
}
-VmaBlockMetadata_Generic::~VmaBlockMetadata_Generic() {
+VmaBlockMetadata_Generic::~VmaBlockMetadata_Generic()
+{
}
-void VmaBlockMetadata_Generic::Init(VkDeviceSize size) {
+void VmaBlockMetadata_Generic::Init(VkDeviceSize size)
+{
VmaBlockMetadata::Init(size);
m_FreeCount = 1;
@@ -7360,9 +8353,10 @@ void VmaBlockMetadata_Generic::Init(VkDeviceSize size) {
m_FreeSuballocationsBySize.push_back(suballocItem);
}
-bool VmaBlockMetadata_Generic::Validate() const {
+bool VmaBlockMetadata_Generic::Validate() const
+{
VMA_VALIDATE(!m_Suballocations.empty());
-
+
// Expected offset of new suballocation as calculated from previous ones.
VkDeviceSize calculatedOffset = 0;
// Expected number of free suballocations as calculated from traversing their list.
@@ -7375,11 +8369,12 @@ bool VmaBlockMetadata_Generic::Validate() const {
// True if previous visited suballocation was free.
bool prevFree = false;
- for (VmaSuballocationList::const_iterator suballocItem = m_Suballocations.cbegin();
- suballocItem != m_Suballocations.cend();
- ++suballocItem) {
- const VmaSuballocation &subAlloc = *suballocItem;
-
+ for(VmaSuballocationList::const_iterator suballocItem = m_Suballocations.cbegin();
+ suballocItem != m_Suballocations.cend();
+ ++suballocItem)
+ {
+ const VmaSuballocation& subAlloc = *suballocItem;
+
// Actual offset of this suballocation doesn't match expected one.
VMA_VALIDATE(subAlloc.offset == calculatedOffset);
@@ -7389,16 +8384,20 @@ bool VmaBlockMetadata_Generic::Validate() const {
VMA_VALIDATE(currFree == (subAlloc.hAllocation == VK_NULL_HANDLE));
- if (currFree) {
+ if(currFree)
+ {
calculatedSumFreeSize += subAlloc.size;
++calculatedFreeCount;
- if (subAlloc.size >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER) {
+ if(subAlloc.size >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+ {
++freeSuballocationsToRegister;
}
// Margin required between allocations - every free space must be at least that large.
VMA_VALIDATE(subAlloc.size >= VMA_DEBUG_MARGIN);
- } else {
+ }
+ else
+ {
VMA_VALIDATE(subAlloc.hAllocation->GetOffset() == subAlloc.offset);
VMA_VALIDATE(subAlloc.hAllocation->GetSize() == subAlloc.size);
@@ -7415,9 +8414,10 @@ bool VmaBlockMetadata_Generic::Validate() const {
VMA_VALIDATE(m_FreeSuballocationsBySize.size() == freeSuballocationsToRegister);
VkDeviceSize lastSize = 0;
- for (size_t i = 0; i < m_FreeSuballocationsBySize.size(); ++i) {
+ for(size_t i = 0; i < m_FreeSuballocationsBySize.size(); ++i)
+ {
VmaSuballocationList::iterator suballocItem = m_FreeSuballocationsBySize[i];
-
+
// Only free suballocations can be registered in m_FreeSuballocationsBySize.
VMA_VALIDATE(suballocItem->type == VMA_SUBALLOCATION_TYPE_FREE);
// They must be sorted by size ascending.
@@ -7435,25 +8435,31 @@ bool VmaBlockMetadata_Generic::Validate() const {
return true;
}
-VkDeviceSize VmaBlockMetadata_Generic::GetUnusedRangeSizeMax() const {
- if (!m_FreeSuballocationsBySize.empty()) {
+VkDeviceSize VmaBlockMetadata_Generic::GetUnusedRangeSizeMax() const
+{
+ if(!m_FreeSuballocationsBySize.empty())
+ {
return m_FreeSuballocationsBySize.back()->size;
- } else {
+ }
+ else
+ {
return 0;
}
}
-bool VmaBlockMetadata_Generic::IsEmpty() const {
+bool VmaBlockMetadata_Generic::IsEmpty() const
+{
return (m_Suballocations.size() == 1) && (m_FreeCount == 1);
}
-void VmaBlockMetadata_Generic::CalcAllocationStatInfo(VmaStatInfo &outInfo) const {
+void VmaBlockMetadata_Generic::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
+{
outInfo.blockCount = 1;
const uint32_t rangeCount = (uint32_t)m_Suballocations.size();
outInfo.allocationCount = rangeCount - m_FreeCount;
outInfo.unusedRangeCount = m_FreeCount;
-
+
outInfo.unusedBytes = m_SumFreeSize;
outInfo.usedBytes = GetSize() - outInfo.unusedBytes;
@@ -7462,21 +8468,26 @@ void VmaBlockMetadata_Generic::CalcAllocationStatInfo(VmaStatInfo &outInfo) cons
outInfo.unusedRangeSizeMin = UINT64_MAX;
outInfo.unusedRangeSizeMax = 0;
- for (VmaSuballocationList::const_iterator suballocItem = m_Suballocations.cbegin();
- suballocItem != m_Suballocations.cend();
- ++suballocItem) {
- const VmaSuballocation &suballoc = *suballocItem;
- if (suballoc.type != VMA_SUBALLOCATION_TYPE_FREE) {
+ for(VmaSuballocationList::const_iterator suballocItem = m_Suballocations.cbegin();
+ suballocItem != m_Suballocations.cend();
+ ++suballocItem)
+ {
+ const VmaSuballocation& suballoc = *suballocItem;
+ if(suballoc.type != VMA_SUBALLOCATION_TYPE_FREE)
+ {
outInfo.allocationSizeMin = VMA_MIN(outInfo.allocationSizeMin, suballoc.size);
outInfo.allocationSizeMax = VMA_MAX(outInfo.allocationSizeMax, suballoc.size);
- } else {
+ }
+ else
+ {
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, suballoc.size);
outInfo.unusedRangeSizeMax = VMA_MAX(outInfo.unusedRangeSizeMax, suballoc.size);
}
}
}
-void VmaBlockMetadata_Generic::AddPoolStats(VmaPoolStats &inoutStats) const {
+void VmaBlockMetadata_Generic::AddPoolStats(VmaPoolStats& inoutStats) const
+{
const uint32_t rangeCount = (uint32_t)m_Suballocations.size();
inoutStats.size += GetSize();
@@ -7488,19 +8499,24 @@ void VmaBlockMetadata_Generic::AddPoolStats(VmaPoolStats &inoutStats) const {
#if VMA_STATS_STRING_ENABLED
-void VmaBlockMetadata_Generic::PrintDetailedMap(class VmaJsonWriter &json) const {
+void VmaBlockMetadata_Generic::PrintDetailedMap(class VmaJsonWriter& json) const
+{
PrintDetailedMap_Begin(json,
- m_SumFreeSize, // unusedBytes
- m_Suballocations.size() - (size_t)m_FreeCount, // allocationCount
- m_FreeCount); // unusedRangeCount
+ m_SumFreeSize, // unusedBytes
+ m_Suballocations.size() - (size_t)m_FreeCount, // allocationCount
+ m_FreeCount); // unusedRangeCount
size_t i = 0;
- for (VmaSuballocationList::const_iterator suballocItem = m_Suballocations.cbegin();
- suballocItem != m_Suballocations.cend();
- ++suballocItem, ++i) {
- if (suballocItem->type == VMA_SUBALLOCATION_TYPE_FREE) {
+ for(VmaSuballocationList::const_iterator suballocItem = m_Suballocations.cbegin();
+ suballocItem != m_Suballocations.cend();
+ ++suballocItem, ++i)
+ {
+ if(suballocItem->type == VMA_SUBALLOCATION_TYPE_FREE)
+ {
PrintDetailedMap_UnusedRange(json, suballocItem->offset, suballocItem->size);
- } else {
+ }
+ else
+ {
PrintDetailedMap_Allocation(json, suballocItem->offset, suballocItem->hAllocation);
}
}
@@ -7511,16 +8527,17 @@ void VmaBlockMetadata_Generic::PrintDetailedMap(class VmaJsonWriter &json) const
#endif // #if VMA_STATS_STRING_ENABLED
bool VmaBlockMetadata_Generic::CreateAllocationRequest(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- bool upperAddress,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest) {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ bool upperAddress,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest)
+{
VMA_ASSERT(allocSize > 0);
VMA_ASSERT(!upperAddress);
VMA_ASSERT(allocType != VMA_SUBALLOCATION_TYPE_FREE);
@@ -7530,78 +8547,90 @@ bool VmaBlockMetadata_Generic::CreateAllocationRequest(
pAllocationRequest->type = VmaAllocationRequestType::Normal;
// There is not enough total free space in this block to fullfill the request: Early return.
- if (canMakeOtherLost == false &&
- m_SumFreeSize < allocSize + 2 * VMA_DEBUG_MARGIN) {
+ if(canMakeOtherLost == false &&
+ m_SumFreeSize < allocSize + 2 * VMA_DEBUG_MARGIN)
+ {
return false;
}
// New algorithm, efficiently searching freeSuballocationsBySize.
const size_t freeSuballocCount = m_FreeSuballocationsBySize.size();
- if (freeSuballocCount > 0) {
- if (strategy == VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT) {
+ if(freeSuballocCount > 0)
+ {
+ if(strategy == VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT)
+ {
// Find first free suballocation with size not less than allocSize + 2 * VMA_DEBUG_MARGIN.
- VmaSuballocationList::iterator *const it = VmaBinaryFindFirstNotLess(
- m_FreeSuballocationsBySize.data(),
- m_FreeSuballocationsBySize.data() + freeSuballocCount,
- allocSize + 2 * VMA_DEBUG_MARGIN,
- VmaSuballocationItemSizeLess());
+ VmaSuballocationList::iterator* const it = VmaBinaryFindFirstNotLess(
+ m_FreeSuballocationsBySize.data(),
+ m_FreeSuballocationsBySize.data() + freeSuballocCount,
+ allocSize + 2 * VMA_DEBUG_MARGIN,
+ VmaSuballocationItemSizeLess());
size_t index = it - m_FreeSuballocationsBySize.data();
- for (; index < freeSuballocCount; ++index) {
- if (CheckAllocation(
- currentFrameIndex,
- frameInUseCount,
- bufferImageGranularity,
- allocSize,
- allocAlignment,
- allocType,
- m_FreeSuballocationsBySize[index],
- false, // canMakeOtherLost
- &pAllocationRequest->offset,
- &pAllocationRequest->itemsToMakeLostCount,
- &pAllocationRequest->sumFreeSize,
- &pAllocationRequest->sumItemSize)) {
+ for(; index < freeSuballocCount; ++index)
+ {
+ if(CheckAllocation(
+ currentFrameIndex,
+ frameInUseCount,
+ bufferImageGranularity,
+ allocSize,
+ allocAlignment,
+ allocType,
+ m_FreeSuballocationsBySize[index],
+ false, // canMakeOtherLost
+ &pAllocationRequest->offset,
+ &pAllocationRequest->itemsToMakeLostCount,
+ &pAllocationRequest->sumFreeSize,
+ &pAllocationRequest->sumItemSize))
+ {
pAllocationRequest->item = m_FreeSuballocationsBySize[index];
return true;
}
}
- } else if (strategy == VMA_ALLOCATION_INTERNAL_STRATEGY_MIN_OFFSET) {
- for (VmaSuballocationList::iterator it = m_Suballocations.begin();
- it != m_Suballocations.end();
- ++it) {
- if (it->type == VMA_SUBALLOCATION_TYPE_FREE && CheckAllocation(
- currentFrameIndex,
- frameInUseCount,
- bufferImageGranularity,
- allocSize,
- allocAlignment,
- allocType,
- it,
- false, // canMakeOtherLost
- &pAllocationRequest->offset,
- &pAllocationRequest->itemsToMakeLostCount,
- &pAllocationRequest->sumFreeSize,
- &pAllocationRequest->sumItemSize)) {
+ }
+ else if(strategy == VMA_ALLOCATION_INTERNAL_STRATEGY_MIN_OFFSET)
+ {
+ for(VmaSuballocationList::iterator it = m_Suballocations.begin();
+ it != m_Suballocations.end();
+ ++it)
+ {
+ if(it->type == VMA_SUBALLOCATION_TYPE_FREE && CheckAllocation(
+ currentFrameIndex,
+ frameInUseCount,
+ bufferImageGranularity,
+ allocSize,
+ allocAlignment,
+ allocType,
+ it,
+ false, // canMakeOtherLost
+ &pAllocationRequest->offset,
+ &pAllocationRequest->itemsToMakeLostCount,
+ &pAllocationRequest->sumFreeSize,
+ &pAllocationRequest->sumItemSize))
+ {
pAllocationRequest->item = it;
return true;
}
}
- } else // WORST_FIT, FIRST_FIT
+ }
+ else // WORST_FIT, FIRST_FIT
{
// Search staring from biggest suballocations.
- for (size_t index = freeSuballocCount; index--;) {
- if (CheckAllocation(
- currentFrameIndex,
- frameInUseCount,
- bufferImageGranularity,
- allocSize,
- allocAlignment,
- allocType,
- m_FreeSuballocationsBySize[index],
- false, // canMakeOtherLost
- &pAllocationRequest->offset,
- &pAllocationRequest->itemsToMakeLostCount,
- &pAllocationRequest->sumFreeSize,
- &pAllocationRequest->sumItemSize)) {
+ for(size_t index = freeSuballocCount; index--; )
+ {
+ if(CheckAllocation(
+ currentFrameIndex,
+ frameInUseCount,
+ bufferImageGranularity,
+ allocSize,
+ allocAlignment,
+ allocType,
+ m_FreeSuballocationsBySize[index],
+ false, // canMakeOtherLost
+ &pAllocationRequest->offset,
+ &pAllocationRequest->itemsToMakeLostCount,
+ &pAllocationRequest->sumFreeSize,
+ &pAllocationRequest->sumItemSize))
+ {
pAllocationRequest->item = m_FreeSuballocationsBySize[index];
return true;
}
@@ -7609,36 +8638,42 @@ bool VmaBlockMetadata_Generic::CreateAllocationRequest(
}
}
- if (canMakeOtherLost) {
+ if(canMakeOtherLost)
+ {
// Brute-force algorithm. TODO: Come up with something better.
bool found = false;
VmaAllocationRequest tmpAllocRequest = {};
tmpAllocRequest.type = VmaAllocationRequestType::Normal;
- for (VmaSuballocationList::iterator suballocIt = m_Suballocations.begin();
- suballocIt != m_Suballocations.end();
- ++suballocIt) {
- if (suballocIt->type == VMA_SUBALLOCATION_TYPE_FREE ||
- suballocIt->hAllocation->CanBecomeLost()) {
- if (CheckAllocation(
- currentFrameIndex,
- frameInUseCount,
- bufferImageGranularity,
- allocSize,
- allocAlignment,
- allocType,
- suballocIt,
- canMakeOtherLost,
- &tmpAllocRequest.offset,
- &tmpAllocRequest.itemsToMakeLostCount,
- &tmpAllocRequest.sumFreeSize,
- &tmpAllocRequest.sumItemSize)) {
- if (strategy == VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT) {
+ for(VmaSuballocationList::iterator suballocIt = m_Suballocations.begin();
+ suballocIt != m_Suballocations.end();
+ ++suballocIt)
+ {
+ if(suballocIt->type == VMA_SUBALLOCATION_TYPE_FREE ||
+ suballocIt->hAllocation->CanBecomeLost())
+ {
+ if(CheckAllocation(
+ currentFrameIndex,
+ frameInUseCount,
+ bufferImageGranularity,
+ allocSize,
+ allocAlignment,
+ allocType,
+ suballocIt,
+ canMakeOtherLost,
+ &tmpAllocRequest.offset,
+ &tmpAllocRequest.itemsToMakeLostCount,
+ &tmpAllocRequest.sumFreeSize,
+ &tmpAllocRequest.sumItemSize))
+ {
+ if(strategy == VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT)
+ {
*pAllocationRequest = tmpAllocRequest;
pAllocationRequest->item = suballocIt;
break;
}
- if (!found || tmpAllocRequest.CalcCost() < pAllocationRequest->CalcCost()) {
+ if(!found || tmpAllocRequest.CalcCost() < pAllocationRequest->CalcCost())
+ {
*pAllocationRequest = tmpAllocRequest;
pAllocationRequest->item = suballocIt;
found = true;
@@ -7654,22 +8689,28 @@ bool VmaBlockMetadata_Generic::CreateAllocationRequest(
}
bool VmaBlockMetadata_Generic::MakeRequestedAllocationsLost(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VmaAllocationRequest *pAllocationRequest) {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VmaAllocationRequest* pAllocationRequest)
+{
VMA_ASSERT(pAllocationRequest && pAllocationRequest->type == VmaAllocationRequestType::Normal);
- while (pAllocationRequest->itemsToMakeLostCount > 0) {
- if (pAllocationRequest->item->type == VMA_SUBALLOCATION_TYPE_FREE) {
+ while(pAllocationRequest->itemsToMakeLostCount > 0)
+ {
+ if(pAllocationRequest->item->type == VMA_SUBALLOCATION_TYPE_FREE)
+ {
++pAllocationRequest->item;
}
VMA_ASSERT(pAllocationRequest->item != m_Suballocations.end());
VMA_ASSERT(pAllocationRequest->item->hAllocation != VK_NULL_HANDLE);
VMA_ASSERT(pAllocationRequest->item->hAllocation->CanBecomeLost());
- if (pAllocationRequest->item->hAllocation->MakeLost(currentFrameIndex, frameInUseCount)) {
+ if(pAllocationRequest->item->hAllocation->MakeLost(currentFrameIndex, frameInUseCount))
+ {
pAllocationRequest->item = FreeSuballocation(pAllocationRequest->item);
--pAllocationRequest->itemsToMakeLostCount;
- } else {
+ }
+ else
+ {
return false;
}
}
@@ -7677,18 +8718,21 @@ bool VmaBlockMetadata_Generic::MakeRequestedAllocationsLost(
VMA_HEAVY_ASSERT(Validate());
VMA_ASSERT(pAllocationRequest->item != m_Suballocations.end());
VMA_ASSERT(pAllocationRequest->item->type == VMA_SUBALLOCATION_TYPE_FREE);
-
+
return true;
}
-uint32_t VmaBlockMetadata_Generic::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount) {
+uint32_t VmaBlockMetadata_Generic::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount)
+{
uint32_t lostAllocationCount = 0;
- for (VmaSuballocationList::iterator it = m_Suballocations.begin();
- it != m_Suballocations.end();
- ++it) {
- if (it->type != VMA_SUBALLOCATION_TYPE_FREE &&
- it->hAllocation->CanBecomeLost() &&
- it->hAllocation->MakeLost(currentFrameIndex, frameInUseCount)) {
+ for(VmaSuballocationList::iterator it = m_Suballocations.begin();
+ it != m_Suballocations.end();
+ ++it)
+ {
+ if(it->type != VMA_SUBALLOCATION_TYPE_FREE &&
+ it->hAllocation->CanBecomeLost() &&
+ it->hAllocation->MakeLost(currentFrameIndex, frameInUseCount))
+ {
it = FreeSuballocation(it);
++lostAllocationCount;
}
@@ -7696,16 +8740,21 @@ uint32_t VmaBlockMetadata_Generic::MakeAllocationsLost(uint32_t currentFrameInde
return lostAllocationCount;
}
-VkResult VmaBlockMetadata_Generic::CheckCorruption(const void *pBlockData) {
- for (VmaSuballocationList::iterator it = m_Suballocations.begin();
- it != m_Suballocations.end();
- ++it) {
- if (it->type != VMA_SUBALLOCATION_TYPE_FREE) {
- if (!VmaValidateMagicValue(pBlockData, it->offset - VMA_DEBUG_MARGIN)) {
+VkResult VmaBlockMetadata_Generic::CheckCorruption(const void* pBlockData)
+{
+ for(VmaSuballocationList::iterator it = m_Suballocations.begin();
+ it != m_Suballocations.end();
+ ++it)
+ {
+ if(it->type != VMA_SUBALLOCATION_TYPE_FREE)
+ {
+ if(!VmaValidateMagicValue(pBlockData, it->offset - VMA_DEBUG_MARGIN))
+ {
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED BEFORE VALIDATED ALLOCATION!");
return VK_ERROR_VALIDATION_FAILED_EXT;
}
- if (!VmaValidateMagicValue(pBlockData, it->offset + it->size)) {
+ if(!VmaValidateMagicValue(pBlockData, it->offset + it->size))
+ {
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED AFTER VALIDATED ALLOCATION!");
return VK_ERROR_VALIDATION_FAILED_EXT;
}
@@ -7716,13 +8765,14 @@ VkResult VmaBlockMetadata_Generic::CheckCorruption(const void *pBlockData) {
}
void VmaBlockMetadata_Generic::Alloc(
- const VmaAllocationRequest &request,
- VmaSuballocationType type,
- VkDeviceSize allocSize,
- VmaAllocation hAllocation) {
+ const VmaAllocationRequest& request,
+ VmaSuballocationType type,
+ VkDeviceSize allocSize,
+ VmaAllocation hAllocation)
+{
VMA_ASSERT(request.type == VmaAllocationRequestType::Normal);
VMA_ASSERT(request.item != m_Suballocations.end());
- VmaSuballocation &suballoc = *request.item;
+ VmaSuballocation& suballoc = *request.item;
// Given suballocation is a free block.
VMA_ASSERT(suballoc.type == VMA_SUBALLOCATION_TYPE_FREE);
// Given offset is inside this suballocation.
@@ -7741,7 +8791,8 @@ void VmaBlockMetadata_Generic::Alloc(
suballoc.hAllocation = hAllocation;
// If there are any free bytes remaining at the end, insert new free suballocation after current one.
- if (paddingEnd) {
+ if(paddingEnd)
+ {
VmaSuballocation paddingSuballoc = {};
paddingSuballoc.offset = request.offset + allocSize;
paddingSuballoc.size = paddingEnd;
@@ -7749,38 +8800,44 @@ void VmaBlockMetadata_Generic::Alloc(
VmaSuballocationList::iterator next = request.item;
++next;
const VmaSuballocationList::iterator paddingEndItem =
- m_Suballocations.insert(next, paddingSuballoc);
+ m_Suballocations.insert(next, paddingSuballoc);
RegisterFreeSuballocation(paddingEndItem);
}
// If there are any free bytes remaining at the beginning, insert new free suballocation before current one.
- if (paddingBegin) {
+ if(paddingBegin)
+ {
VmaSuballocation paddingSuballoc = {};
paddingSuballoc.offset = request.offset - paddingBegin;
paddingSuballoc.size = paddingBegin;
paddingSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
const VmaSuballocationList::iterator paddingBeginItem =
- m_Suballocations.insert(request.item, paddingSuballoc);
+ m_Suballocations.insert(request.item, paddingSuballoc);
RegisterFreeSuballocation(paddingBeginItem);
}
// Update totals.
m_FreeCount = m_FreeCount - 1;
- if (paddingBegin > 0) {
+ if(paddingBegin > 0)
+ {
++m_FreeCount;
}
- if (paddingEnd > 0) {
+ if(paddingEnd > 0)
+ {
++m_FreeCount;
}
m_SumFreeSize -= allocSize;
}
-void VmaBlockMetadata_Generic::Free(const VmaAllocation allocation) {
- for (VmaSuballocationList::iterator suballocItem = m_Suballocations.begin();
- suballocItem != m_Suballocations.end();
- ++suballocItem) {
- VmaSuballocation &suballoc = *suballocItem;
- if (suballoc.hAllocation == allocation) {
+void VmaBlockMetadata_Generic::Free(const VmaAllocation allocation)
+{
+ for(VmaSuballocationList::iterator suballocItem = m_Suballocations.begin();
+ suballocItem != m_Suballocations.end();
+ ++suballocItem)
+ {
+ VmaSuballocation& suballoc = *suballocItem;
+ if(suballoc.hAllocation == allocation)
+ {
FreeSuballocation(suballocItem);
VMA_HEAVY_ASSERT(Validate());
return;
@@ -7789,12 +8846,15 @@ void VmaBlockMetadata_Generic::Free(const VmaAllocation allocation) {
VMA_ASSERT(0 && "Not found!");
}
-void VmaBlockMetadata_Generic::FreeAtOffset(VkDeviceSize offset) {
- for (VmaSuballocationList::iterator suballocItem = m_Suballocations.begin();
- suballocItem != m_Suballocations.end();
- ++suballocItem) {
- VmaSuballocation &suballoc = *suballocItem;
- if (suballoc.offset == offset) {
+void VmaBlockMetadata_Generic::FreeAtOffset(VkDeviceSize offset)
+{
+ for(VmaSuballocationList::iterator suballocItem = m_Suballocations.begin();
+ suballocItem != m_Suballocations.end();
+ ++suballocItem)
+ {
+ VmaSuballocation& suballoc = *suballocItem;
+ if(suballoc.offset == offset)
+ {
FreeSuballocation(suballocItem);
return;
}
@@ -7802,120 +8862,11 @@ void VmaBlockMetadata_Generic::FreeAtOffset(VkDeviceSize offset) {
VMA_ASSERT(0 && "Not found!");
}
-bool VmaBlockMetadata_Generic::ResizeAllocation(const VmaAllocation alloc, VkDeviceSize newSize) {
- typedef VmaSuballocationList::iterator iter_type;
- for (iter_type suballocItem = m_Suballocations.begin();
- suballocItem != m_Suballocations.end();
- ++suballocItem) {
- VmaSuballocation &suballoc = *suballocItem;
- if (suballoc.hAllocation == alloc) {
- iter_type nextItem = suballocItem;
- ++nextItem;
-
- // Should have been ensured on higher level.
- VMA_ASSERT(newSize != alloc->GetSize() && newSize > 0);
-
- // Shrinking.
- if (newSize < alloc->GetSize()) {
- const VkDeviceSize sizeDiff = suballoc.size - newSize;
-
- // There is next item.
- if (nextItem != m_Suballocations.end()) {
- // Next item is free.
- if (nextItem->type == VMA_SUBALLOCATION_TYPE_FREE) {
- // Grow this next item backward.
- UnregisterFreeSuballocation(nextItem);
- nextItem->offset -= sizeDiff;
- nextItem->size += sizeDiff;
- RegisterFreeSuballocation(nextItem);
- }
- // Next item is not free.
- else {
- // Create free item after current one.
- VmaSuballocation newFreeSuballoc;
- newFreeSuballoc.hAllocation = VK_NULL_HANDLE;
- newFreeSuballoc.offset = suballoc.offset + newSize;
- newFreeSuballoc.size = sizeDiff;
- newFreeSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
- iter_type newFreeSuballocIt = m_Suballocations.insert(nextItem, newFreeSuballoc);
- RegisterFreeSuballocation(newFreeSuballocIt);
-
- ++m_FreeCount;
- }
- }
- // This is the last item.
- else {
- // Create free item at the end.
- VmaSuballocation newFreeSuballoc;
- newFreeSuballoc.hAllocation = VK_NULL_HANDLE;
- newFreeSuballoc.offset = suballoc.offset + newSize;
- newFreeSuballoc.size = sizeDiff;
- newFreeSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
- m_Suballocations.push_back(newFreeSuballoc);
-
- iter_type newFreeSuballocIt = m_Suballocations.end();
- RegisterFreeSuballocation(--newFreeSuballocIt);
-
- ++m_FreeCount;
- }
-
- suballoc.size = newSize;
- m_SumFreeSize += sizeDiff;
- }
- // Growing.
- else {
- const VkDeviceSize sizeDiff = newSize - suballoc.size;
-
- // There is next item.
- if (nextItem != m_Suballocations.end()) {
- // Next item is free.
- if (nextItem->type == VMA_SUBALLOCATION_TYPE_FREE) {
- // There is not enough free space, including margin.
- if (nextItem->size < sizeDiff + VMA_DEBUG_MARGIN) {
- return false;
- }
-
- // There is more free space than required.
- if (nextItem->size > sizeDiff) {
- // Move and shrink this next item.
- UnregisterFreeSuballocation(nextItem);
- nextItem->offset += sizeDiff;
- nextItem->size -= sizeDiff;
- RegisterFreeSuballocation(nextItem);
- }
- // There is exactly the amount of free space required.
- else {
- // Remove this next free item.
- UnregisterFreeSuballocation(nextItem);
- m_Suballocations.erase(nextItem);
- --m_FreeCount;
- }
- }
- // Next item is not free - there is no space to grow.
- else {
- return false;
- }
- }
- // This is the last item - there is no space to grow.
- else {
- return false;
- }
-
- suballoc.size = newSize;
- m_SumFreeSize -= sizeDiff;
- }
-
- // We cannot call Validate() here because alloc object is updated to new size outside of this call.
- return true;
- }
- }
- VMA_ASSERT(0 && "Not found!");
- return false;
-}
-
-bool VmaBlockMetadata_Generic::ValidateFreeSuballocationList() const {
+bool VmaBlockMetadata_Generic::ValidateFreeSuballocationList() const
+{
VkDeviceSize lastSize = 0;
- for (size_t i = 0, count = m_FreeSuballocationsBySize.size(); i < count; ++i) {
+ for(size_t i = 0, count = m_FreeSuballocationsBySize.size(); i < count; ++i)
+ {
const VmaSuballocationList::iterator it = m_FreeSuballocationsBySize[i];
VMA_VALIDATE(it->type == VMA_SUBALLOCATION_TYPE_FREE);
@@ -7927,84 +8878,101 @@ bool VmaBlockMetadata_Generic::ValidateFreeSuballocationList() const {
}
bool VmaBlockMetadata_Generic::CheckAllocation(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- VmaSuballocationType allocType,
- VmaSuballocationList::const_iterator suballocItem,
- bool canMakeOtherLost,
- VkDeviceSize *pOffset,
- size_t *itemsToMakeLostCount,
- VkDeviceSize *pSumFreeSize,
- VkDeviceSize *pSumItemSize) const {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ VmaSuballocationType allocType,
+ VmaSuballocationList::const_iterator suballocItem,
+ bool canMakeOtherLost,
+ VkDeviceSize* pOffset,
+ size_t* itemsToMakeLostCount,
+ VkDeviceSize* pSumFreeSize,
+ VkDeviceSize* pSumItemSize) const
+{
VMA_ASSERT(allocSize > 0);
VMA_ASSERT(allocType != VMA_SUBALLOCATION_TYPE_FREE);
VMA_ASSERT(suballocItem != m_Suballocations.cend());
VMA_ASSERT(pOffset != VMA_NULL);
-
+
*itemsToMakeLostCount = 0;
*pSumFreeSize = 0;
*pSumItemSize = 0;
- if (canMakeOtherLost) {
- if (suballocItem->type == VMA_SUBALLOCATION_TYPE_FREE) {
+ if(canMakeOtherLost)
+ {
+ if(suballocItem->type == VMA_SUBALLOCATION_TYPE_FREE)
+ {
*pSumFreeSize = suballocItem->size;
- } else {
- if (suballocItem->hAllocation->CanBecomeLost() &&
- suballocItem->hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex) {
+ }
+ else
+ {
+ if(suballocItem->hAllocation->CanBecomeLost() &&
+ suballocItem->hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex)
+ {
++*itemsToMakeLostCount;
*pSumItemSize = suballocItem->size;
- } else {
+ }
+ else
+ {
return false;
}
}
// Remaining size is too small for this request: Early return.
- if (GetSize() - suballocItem->offset < allocSize) {
+ if(GetSize() - suballocItem->offset < allocSize)
+ {
return false;
}
// Start from offset equal to beginning of this suballocation.
*pOffset = suballocItem->offset;
-
+
// Apply VMA_DEBUG_MARGIN at the beginning.
- if (VMA_DEBUG_MARGIN > 0) {
+ if(VMA_DEBUG_MARGIN > 0)
+ {
*pOffset += VMA_DEBUG_MARGIN;
}
-
+
// Apply alignment.
*pOffset = VmaAlignUp(*pOffset, allocAlignment);
// Check previous suballocations for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if (bufferImageGranularity > 1) {
+ if(bufferImageGranularity > 1)
+ {
bool bufferImageGranularityConflict = false;
VmaSuballocationList::const_iterator prevSuballocItem = suballocItem;
- while (prevSuballocItem != m_Suballocations.cbegin()) {
+ while(prevSuballocItem != m_Suballocations.cbegin())
+ {
--prevSuballocItem;
- const VmaSuballocation &prevSuballoc = *prevSuballocItem;
- if (VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, *pOffset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType)) {
+ const VmaSuballocation& prevSuballoc = *prevSuballocItem;
+ if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, *pOffset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType))
+ {
bufferImageGranularityConflict = true;
break;
}
- } else
+ }
+ else
// Already on previous page.
break;
}
- if (bufferImageGranularityConflict) {
+ if(bufferImageGranularityConflict)
+ {
*pOffset = VmaAlignUp(*pOffset, bufferImageGranularity);
}
}
-
+
// Now that we have final *pOffset, check if we are past suballocItem.
// If yes, return false - this function should be called for another suballocItem as starting point.
- if (*pOffset >= suballocItem->offset + suballocItem->size) {
+ if(*pOffset >= suballocItem->offset + suballocItem->size)
+ {
return false;
}
-
+
// Calculate padding at the beginning based on current offset.
const VkDeviceSize paddingBegin = *pOffset - suballocItem->offset;
@@ -8013,106 +8981,134 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
const VkDeviceSize totalSize = paddingBegin + allocSize + requiredEndMargin;
// Another early return check.
- if (suballocItem->offset + totalSize > GetSize()) {
+ if(suballocItem->offset + totalSize > GetSize())
+ {
return false;
}
// Advance lastSuballocItem until desired size is reached.
// Update itemsToMakeLostCount.
VmaSuballocationList::const_iterator lastSuballocItem = suballocItem;
- if (totalSize > suballocItem->size) {
+ if(totalSize > suballocItem->size)
+ {
VkDeviceSize remainingSize = totalSize - suballocItem->size;
- while (remainingSize > 0) {
+ while(remainingSize > 0)
+ {
++lastSuballocItem;
- if (lastSuballocItem == m_Suballocations.cend()) {
+ if(lastSuballocItem == m_Suballocations.cend())
+ {
return false;
}
- if (lastSuballocItem->type == VMA_SUBALLOCATION_TYPE_FREE) {
+ if(lastSuballocItem->type == VMA_SUBALLOCATION_TYPE_FREE)
+ {
*pSumFreeSize += lastSuballocItem->size;
- } else {
+ }
+ else
+ {
VMA_ASSERT(lastSuballocItem->hAllocation != VK_NULL_HANDLE);
- if (lastSuballocItem->hAllocation->CanBecomeLost() &&
- lastSuballocItem->hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex) {
+ if(lastSuballocItem->hAllocation->CanBecomeLost() &&
+ lastSuballocItem->hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex)
+ {
++*itemsToMakeLostCount;
*pSumItemSize += lastSuballocItem->size;
- } else {
+ }
+ else
+ {
return false;
}
}
remainingSize = (lastSuballocItem->size < remainingSize) ?
- remainingSize - lastSuballocItem->size :
- 0;
+ remainingSize - lastSuballocItem->size : 0;
}
}
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, we must mark more allocations lost or fail.
- if (bufferImageGranularity > 1) {
+ if(bufferImageGranularity > 1)
+ {
VmaSuballocationList::const_iterator nextSuballocItem = lastSuballocItem;
++nextSuballocItem;
- while (nextSuballocItem != m_Suballocations.cend()) {
- const VmaSuballocation &nextSuballoc = *nextSuballocItem;
- if (VmaBlocksOnSamePage(*pOffset, allocSize, nextSuballoc.offset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type)) {
+ while(nextSuballocItem != m_Suballocations.cend())
+ {
+ const VmaSuballocation& nextSuballoc = *nextSuballocItem;
+ if(VmaBlocksOnSamePage(*pOffset, allocSize, nextSuballoc.offset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type))
+ {
VMA_ASSERT(nextSuballoc.hAllocation != VK_NULL_HANDLE);
- if (nextSuballoc.hAllocation->CanBecomeLost() &&
- nextSuballoc.hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex) {
+ if(nextSuballoc.hAllocation->CanBecomeLost() &&
+ nextSuballoc.hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex)
+ {
++*itemsToMakeLostCount;
- } else {
+ }
+ else
+ {
return false;
}
}
- } else {
+ }
+ else
+ {
// Already on next page.
break;
}
++nextSuballocItem;
}
}
- } else {
- const VmaSuballocation &suballoc = *suballocItem;
+ }
+ else
+ {
+ const VmaSuballocation& suballoc = *suballocItem;
VMA_ASSERT(suballoc.type == VMA_SUBALLOCATION_TYPE_FREE);
*pSumFreeSize = suballoc.size;
// Size of this suballocation is too small for this request: Early return.
- if (suballoc.size < allocSize) {
+ if(suballoc.size < allocSize)
+ {
return false;
}
// Start from offset equal to beginning of this suballocation.
*pOffset = suballoc.offset;
-
+
// Apply VMA_DEBUG_MARGIN at the beginning.
- if (VMA_DEBUG_MARGIN > 0) {
+ if(VMA_DEBUG_MARGIN > 0)
+ {
*pOffset += VMA_DEBUG_MARGIN;
}
-
+
// Apply alignment.
*pOffset = VmaAlignUp(*pOffset, allocAlignment);
-
+
// Check previous suballocations for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if (bufferImageGranularity > 1) {
+ if(bufferImageGranularity > 1)
+ {
bool bufferImageGranularityConflict = false;
VmaSuballocationList::const_iterator prevSuballocItem = suballocItem;
- while (prevSuballocItem != m_Suballocations.cbegin()) {
+ while(prevSuballocItem != m_Suballocations.cbegin())
+ {
--prevSuballocItem;
- const VmaSuballocation &prevSuballoc = *prevSuballocItem;
- if (VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, *pOffset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType)) {
+ const VmaSuballocation& prevSuballoc = *prevSuballocItem;
+ if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, *pOffset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType))
+ {
bufferImageGranularityConflict = true;
break;
}
- } else
+ }
+ else
// Already on previous page.
break;
}
- if (bufferImageGranularityConflict) {
+ if(bufferImageGranularityConflict)
+ {
*pOffset = VmaAlignUp(*pOffset, bufferImageGranularity);
}
}
-
+
// Calculate padding at the beginning based on current offset.
const VkDeviceSize paddingBegin = *pOffset - suballoc.offset;
@@ -8120,22 +9116,29 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
const VkDeviceSize requiredEndMargin = VMA_DEBUG_MARGIN;
// Fail if requested size plus margin before and after is bigger than size of this suballocation.
- if (paddingBegin + allocSize + requiredEndMargin > suballoc.size) {
+ if(paddingBegin + allocSize + requiredEndMargin > suballoc.size)
+ {
return false;
}
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, allocation cannot be made here.
- if (bufferImageGranularity > 1) {
+ if(bufferImageGranularity > 1)
+ {
VmaSuballocationList::const_iterator nextSuballocItem = suballocItem;
++nextSuballocItem;
- while (nextSuballocItem != m_Suballocations.cend()) {
- const VmaSuballocation &nextSuballoc = *nextSuballocItem;
- if (VmaBlocksOnSamePage(*pOffset, allocSize, nextSuballoc.offset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type)) {
+ while(nextSuballocItem != m_Suballocations.cend())
+ {
+ const VmaSuballocation& nextSuballoc = *nextSuballocItem;
+ if(VmaBlocksOnSamePage(*pOffset, allocSize, nextSuballoc.offset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type))
+ {
return false;
}
- } else {
+ }
+ else
+ {
// Already on next page.
break;
}
@@ -8148,10 +9151,11 @@ bool VmaBlockMetadata_Generic::CheckAllocation(
return true;
}
-void VmaBlockMetadata_Generic::MergeFreeWithNext(VmaSuballocationList::iterator item) {
+void VmaBlockMetadata_Generic::MergeFreeWithNext(VmaSuballocationList::iterator item)
+{
VMA_ASSERT(item != m_Suballocations.end());
VMA_ASSERT(item->type == VMA_SUBALLOCATION_TYPE_FREE);
-
+
VmaSuballocationList::iterator nextItem = item;
++nextItem;
VMA_ASSERT(nextItem != m_Suballocations.end());
@@ -8162,12 +9166,13 @@ void VmaBlockMetadata_Generic::MergeFreeWithNext(VmaSuballocationList::iterator
m_Suballocations.erase(nextItem);
}
-VmaSuballocationList::iterator VmaBlockMetadata_Generic::FreeSuballocation(VmaSuballocationList::iterator suballocItem) {
+VmaSuballocationList::iterator VmaBlockMetadata_Generic::FreeSuballocation(VmaSuballocationList::iterator suballocItem)
+{
// Change this suballocation to be marked as free.
- VmaSuballocation &suballoc = *suballocItem;
+ VmaSuballocation& suballoc = *suballocItem;
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE;
-
+
// Update totals.
++m_FreeCount;
m_SumFreeSize += suballoc.size;
@@ -8175,38 +9180,46 @@ VmaSuballocationList::iterator VmaBlockMetadata_Generic::FreeSuballocation(VmaSu
// Merge with previous and/or next suballocation if it's also free.
bool mergeWithNext = false;
bool mergeWithPrev = false;
-
+
VmaSuballocationList::iterator nextItem = suballocItem;
++nextItem;
- if ((nextItem != m_Suballocations.end()) && (nextItem->type == VMA_SUBALLOCATION_TYPE_FREE)) {
+ if((nextItem != m_Suballocations.end()) && (nextItem->type == VMA_SUBALLOCATION_TYPE_FREE))
+ {
mergeWithNext = true;
}
VmaSuballocationList::iterator prevItem = suballocItem;
- if (suballocItem != m_Suballocations.begin()) {
+ if(suballocItem != m_Suballocations.begin())
+ {
--prevItem;
- if (prevItem->type == VMA_SUBALLOCATION_TYPE_FREE) {
+ if(prevItem->type == VMA_SUBALLOCATION_TYPE_FREE)
+ {
mergeWithPrev = true;
}
}
- if (mergeWithNext) {
+ if(mergeWithNext)
+ {
UnregisterFreeSuballocation(nextItem);
MergeFreeWithNext(suballocItem);
}
- if (mergeWithPrev) {
+ if(mergeWithPrev)
+ {
UnregisterFreeSuballocation(prevItem);
MergeFreeWithNext(prevItem);
RegisterFreeSuballocation(prevItem);
return prevItem;
- } else {
+ }
+ else
+ {
RegisterFreeSuballocation(suballocItem);
return suballocItem;
}
}
-void VmaBlockMetadata_Generic::RegisterFreeSuballocation(VmaSuballocationList::iterator item) {
+void VmaBlockMetadata_Generic::RegisterFreeSuballocation(VmaSuballocationList::iterator item)
+{
VMA_ASSERT(item->type == VMA_SUBALLOCATION_TYPE_FREE);
VMA_ASSERT(item->size > 0);
@@ -8214,10 +9227,14 @@ void VmaBlockMetadata_Generic::RegisterFreeSuballocation(VmaSuballocationList::i
// this function, depending on what do you want to check.
VMA_HEAVY_ASSERT(ValidateFreeSuballocationList());
- if (item->size >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER) {
- if (m_FreeSuballocationsBySize.empty()) {
+ if(item->size >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+ {
+ if(m_FreeSuballocationsBySize.empty())
+ {
m_FreeSuballocationsBySize.push_back(item);
- } else {
+ }
+ else
+ {
VmaVectorInsertSorted<VmaSuballocationItemSizeLess>(m_FreeSuballocationsBySize, item);
}
}
@@ -8225,7 +9242,9 @@ void VmaBlockMetadata_Generic::RegisterFreeSuballocation(VmaSuballocationList::i
//VMA_HEAVY_ASSERT(ValidateFreeSuballocationList());
}
-void VmaBlockMetadata_Generic::UnregisterFreeSuballocation(VmaSuballocationList::iterator item) {
+
+void VmaBlockMetadata_Generic::UnregisterFreeSuballocation(VmaSuballocationList::iterator item)
+{
VMA_ASSERT(item->type == VMA_SUBALLOCATION_TYPE_FREE);
VMA_ASSERT(item->size > 0);
@@ -8233,16 +9252,19 @@ void VmaBlockMetadata_Generic::UnregisterFreeSuballocation(VmaSuballocationList:
// this function, depending on what do you want to check.
VMA_HEAVY_ASSERT(ValidateFreeSuballocationList());
- if (item->size >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER) {
- VmaSuballocationList::iterator *const it = VmaBinaryFindFirstNotLess(
- m_FreeSuballocationsBySize.data(),
- m_FreeSuballocationsBySize.data() + m_FreeSuballocationsBySize.size(),
- item,
- VmaSuballocationItemSizeLess());
- for (size_t index = it - m_FreeSuballocationsBySize.data();
- index < m_FreeSuballocationsBySize.size();
- ++index) {
- if (m_FreeSuballocationsBySize[index] == item) {
+ if(item->size >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+ {
+ VmaSuballocationList::iterator* const it = VmaBinaryFindFirstNotLess(
+ m_FreeSuballocationsBySize.data(),
+ m_FreeSuballocationsBySize.data() + m_FreeSuballocationsBySize.size(),
+ item,
+ VmaSuballocationItemSizeLess());
+ for(size_t index = it - m_FreeSuballocationsBySize.data();
+ index < m_FreeSuballocationsBySize.size();
+ ++index)
+ {
+ if(m_FreeSuballocationsBySize[index] == item)
+ {
VmaVectorRemove(m_FreeSuballocationsBySize, index);
return;
}
@@ -8255,21 +9277,26 @@ void VmaBlockMetadata_Generic::UnregisterFreeSuballocation(VmaSuballocationList:
}
bool VmaBlockMetadata_Generic::IsBufferImageGranularityConflictPossible(
- VkDeviceSize bufferImageGranularity,
- VmaSuballocationType &inOutPrevSuballocType) const {
- if (bufferImageGranularity == 1 || IsEmpty()) {
+ VkDeviceSize bufferImageGranularity,
+ VmaSuballocationType& inOutPrevSuballocType) const
+{
+ if(bufferImageGranularity == 1 || IsEmpty())
+ {
return false;
}
VkDeviceSize minAlignment = VK_WHOLE_SIZE;
bool typeConflictFound = false;
- for (VmaSuballocationList::const_iterator it = m_Suballocations.cbegin();
- it != m_Suballocations.cend();
- ++it) {
+ for(VmaSuballocationList::const_iterator it = m_Suballocations.cbegin();
+ it != m_Suballocations.cend();
+ ++it)
+ {
const VmaSuballocationType suballocType = it->type;
- if (suballocType != VMA_SUBALLOCATION_TYPE_FREE) {
+ if(suballocType != VMA_SUBALLOCATION_TYPE_FREE)
+ {
minAlignment = VMA_MIN(minAlignment, it->hAllocation->GetAlignment());
- if (VmaIsBufferImageGranularityConflict(inOutPrevSuballocType, suballocType)) {
+ if(VmaIsBufferImageGranularityConflict(inOutPrevSuballocType, suballocType))
+ {
typeConflictFound = true;
}
inOutPrevSuballocType = suballocType;
@@ -8283,41 +9310,47 @@ bool VmaBlockMetadata_Generic::IsBufferImageGranularityConflictPossible(
// class VmaBlockMetadata_Linear
VmaBlockMetadata_Linear::VmaBlockMetadata_Linear(VmaAllocator hAllocator) :
- VmaBlockMetadata(hAllocator),
- m_SumFreeSize(0),
- m_Suballocations0(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())),
- m_Suballocations1(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())),
- m_1stVectorIndex(0),
- m_2ndVectorMode(SECOND_VECTOR_EMPTY),
- m_1stNullItemsBeginCount(0),
- m_1stNullItemsMiddleCount(0),
- m_2ndNullItemsCount(0) {
+ VmaBlockMetadata(hAllocator),
+ m_SumFreeSize(0),
+ m_Suballocations0(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())),
+ m_Suballocations1(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks())),
+ m_1stVectorIndex(0),
+ m_2ndVectorMode(SECOND_VECTOR_EMPTY),
+ m_1stNullItemsBeginCount(0),
+ m_1stNullItemsMiddleCount(0),
+ m_2ndNullItemsCount(0)
+{
}
-VmaBlockMetadata_Linear::~VmaBlockMetadata_Linear() {
+VmaBlockMetadata_Linear::~VmaBlockMetadata_Linear()
+{
}
-void VmaBlockMetadata_Linear::Init(VkDeviceSize size) {
+void VmaBlockMetadata_Linear::Init(VkDeviceSize size)
+{
VmaBlockMetadata::Init(size);
m_SumFreeSize = size;
}
-bool VmaBlockMetadata_Linear::Validate() const {
- const SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- const SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+bool VmaBlockMetadata_Linear::Validate() const
+{
+ const SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
VMA_VALIDATE(suballocations2nd.empty() == (m_2ndVectorMode == SECOND_VECTOR_EMPTY));
VMA_VALIDATE(!suballocations1st.empty() ||
- suballocations2nd.empty() ||
- m_2ndVectorMode != SECOND_VECTOR_RING_BUFFER);
+ suballocations2nd.empty() ||
+ m_2ndVectorMode != SECOND_VECTOR_RING_BUFFER);
- if (!suballocations1st.empty()) {
+ if(!suballocations1st.empty())
+ {
// Null item at the beginning should be accounted into m_1stNullItemsBeginCount.
VMA_VALIDATE(suballocations1st[m_1stNullItemsBeginCount].hAllocation != VK_NULL_HANDLE);
// Null item at the end should be just pop_back().
VMA_VALIDATE(suballocations1st.back().hAllocation != VK_NULL_HANDLE);
}
- if (!suballocations2nd.empty()) {
+ if(!suballocations2nd.empty())
+ {
// Null item at the end should be just pop_back().
VMA_VALIDATE(suballocations2nd.back().hAllocation != VK_NULL_HANDLE);
}
@@ -8329,21 +9362,26 @@ bool VmaBlockMetadata_Linear::Validate() const {
const size_t suballoc1stCount = suballocations1st.size();
VkDeviceSize offset = VMA_DEBUG_MARGIN;
- if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
const size_t suballoc2ndCount = suballocations2nd.size();
size_t nullItem2ndCount = 0;
- for (size_t i = 0; i < suballoc2ndCount; ++i) {
- const VmaSuballocation &suballoc = suballocations2nd[i];
+ for(size_t i = 0; i < suballoc2ndCount; ++i)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[i];
const bool currFree = (suballoc.type == VMA_SUBALLOCATION_TYPE_FREE);
VMA_VALIDATE(currFree == (suballoc.hAllocation == VK_NULL_HANDLE));
VMA_VALIDATE(suballoc.offset >= offset);
- if (!currFree) {
+ if(!currFree)
+ {
VMA_VALIDATE(suballoc.hAllocation->GetOffset() == suballoc.offset);
VMA_VALIDATE(suballoc.hAllocation->GetSize() == suballoc.size);
sumUsedSize += suballoc.size;
- } else {
+ }
+ else
+ {
++nullItem2ndCount;
}
@@ -8353,27 +9391,32 @@ bool VmaBlockMetadata_Linear::Validate() const {
VMA_VALIDATE(nullItem2ndCount == m_2ndNullItemsCount);
}
- for (size_t i = 0; i < m_1stNullItemsBeginCount; ++i) {
- const VmaSuballocation &suballoc = suballocations1st[i];
+ for(size_t i = 0; i < m_1stNullItemsBeginCount; ++i)
+ {
+ const VmaSuballocation& suballoc = suballocations1st[i];
VMA_VALIDATE(suballoc.type == VMA_SUBALLOCATION_TYPE_FREE &&
- suballoc.hAllocation == VK_NULL_HANDLE);
+ suballoc.hAllocation == VK_NULL_HANDLE);
}
size_t nullItem1stCount = m_1stNullItemsBeginCount;
- for (size_t i = m_1stNullItemsBeginCount; i < suballoc1stCount; ++i) {
- const VmaSuballocation &suballoc = suballocations1st[i];
+ for(size_t i = m_1stNullItemsBeginCount; i < suballoc1stCount; ++i)
+ {
+ const VmaSuballocation& suballoc = suballocations1st[i];
const bool currFree = (suballoc.type == VMA_SUBALLOCATION_TYPE_FREE);
VMA_VALIDATE(currFree == (suballoc.hAllocation == VK_NULL_HANDLE));
VMA_VALIDATE(suballoc.offset >= offset);
VMA_VALIDATE(i >= m_1stNullItemsBeginCount || currFree);
- if (!currFree) {
+ if(!currFree)
+ {
VMA_VALIDATE(suballoc.hAllocation->GetOffset() == suballoc.offset);
VMA_VALIDATE(suballoc.hAllocation->GetSize() == suballoc.size);
sumUsedSize += suballoc.size;
- } else {
+ }
+ else
+ {
++nullItem1stCount;
}
@@ -8381,21 +9424,26 @@ bool VmaBlockMetadata_Linear::Validate() const {
}
VMA_VALIDATE(nullItem1stCount == m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount);
- if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) {
+ if(m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ {
const size_t suballoc2ndCount = suballocations2nd.size();
size_t nullItem2ndCount = 0;
- for (size_t i = suballoc2ndCount; i--;) {
- const VmaSuballocation &suballoc = suballocations2nd[i];
+ for(size_t i = suballoc2ndCount; i--; )
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[i];
const bool currFree = (suballoc.type == VMA_SUBALLOCATION_TYPE_FREE);
VMA_VALIDATE(currFree == (suballoc.hAllocation == VK_NULL_HANDLE));
VMA_VALIDATE(suballoc.offset >= offset);
- if (!currFree) {
+ if(!currFree)
+ {
VMA_VALIDATE(suballoc.hAllocation->GetOffset() == suballoc.offset);
VMA_VALIDATE(suballoc.hAllocation->GetSize() == suballoc.size);
sumUsedSize += suballoc.size;
- } else {
+ }
+ else
+ {
++nullItem2ndCount;
}
@@ -8411,76 +9459,81 @@ bool VmaBlockMetadata_Linear::Validate() const {
return true;
}
-size_t VmaBlockMetadata_Linear::GetAllocationCount() const {
+size_t VmaBlockMetadata_Linear::GetAllocationCount() const
+{
return AccessSuballocations1st().size() - (m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount) +
- AccessSuballocations2nd().size() - m_2ndNullItemsCount;
+ AccessSuballocations2nd().size() - m_2ndNullItemsCount;
}
-VkDeviceSize VmaBlockMetadata_Linear::GetUnusedRangeSizeMax() const {
+VkDeviceSize VmaBlockMetadata_Linear::GetUnusedRangeSizeMax() const
+{
const VkDeviceSize size = GetSize();
/*
- We don't consider gaps inside allocation vectors with freed allocations because
- they are not suitable for reuse in linear allocator. We consider only space that
- is available for new allocations.
- */
- if (IsEmpty()) {
+ We don't consider gaps inside allocation vectors with freed allocations because
+ they are not suitable for reuse in linear allocator. We consider only space that
+ is available for new allocations.
+ */
+ if(IsEmpty())
+ {
return size;
}
+
+ const SuballocationVectorType& suballocations1st = AccessSuballocations1st();
- const SuballocationVectorType &suballocations1st = AccessSuballocations1st();
-
- switch (m_2ndVectorMode) {
- case SECOND_VECTOR_EMPTY:
- /*
- Available space is after end of 1st, as well as before beginning of 1st (which
- whould make it a ring buffer).
- */
- {
- const size_t suballocations1stCount = suballocations1st.size();
- VMA_ASSERT(suballocations1stCount > m_1stNullItemsBeginCount);
- const VmaSuballocation &firstSuballoc = suballocations1st[m_1stNullItemsBeginCount];
- const VmaSuballocation &lastSuballoc = suballocations1st[suballocations1stCount - 1];
- return VMA_MAX(
- firstSuballoc.offset,
- size - (lastSuballoc.offset + lastSuballoc.size));
- }
- break;
+ switch(m_2ndVectorMode)
+ {
+ case SECOND_VECTOR_EMPTY:
+ /*
+ Available space is after end of 1st, as well as before beginning of 1st (which
+ whould make it a ring buffer).
+ */
+ {
+ const size_t suballocations1stCount = suballocations1st.size();
+ VMA_ASSERT(suballocations1stCount > m_1stNullItemsBeginCount);
+ const VmaSuballocation& firstSuballoc = suballocations1st[m_1stNullItemsBeginCount];
+ const VmaSuballocation& lastSuballoc = suballocations1st[suballocations1stCount - 1];
+ return VMA_MAX(
+ firstSuballoc.offset,
+ size - (lastSuballoc.offset + lastSuballoc.size));
+ }
+ break;
- case SECOND_VECTOR_RING_BUFFER:
- /*
- Available space is only between end of 2nd and beginning of 1st.
- */
- {
- const SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
- const VmaSuballocation &lastSuballoc2nd = suballocations2nd.back();
- const VmaSuballocation &firstSuballoc1st = suballocations1st[m_1stNullItemsBeginCount];
- return firstSuballoc1st.offset - (lastSuballoc2nd.offset + lastSuballoc2nd.size);
- }
- break;
+ case SECOND_VECTOR_RING_BUFFER:
+ /*
+ Available space is only between end of 2nd and beginning of 1st.
+ */
+ {
+ const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
+ const VmaSuballocation& lastSuballoc2nd = suballocations2nd.back();
+ const VmaSuballocation& firstSuballoc1st = suballocations1st[m_1stNullItemsBeginCount];
+ return firstSuballoc1st.offset - (lastSuballoc2nd.offset + lastSuballoc2nd.size);
+ }
+ break;
- case SECOND_VECTOR_DOUBLE_STACK:
- /*
- Available space is only between end of 1st and top of 2nd.
- */
- {
- const SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
- const VmaSuballocation &topSuballoc2nd = suballocations2nd.back();
- const VmaSuballocation &lastSuballoc1st = suballocations1st.back();
- return topSuballoc2nd.offset - (lastSuballoc1st.offset + lastSuballoc1st.size);
- }
- break;
+ case SECOND_VECTOR_DOUBLE_STACK:
+ /*
+ Available space is only between end of 1st and top of 2nd.
+ */
+ {
+ const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
+ const VmaSuballocation& topSuballoc2nd = suballocations2nd.back();
+ const VmaSuballocation& lastSuballoc1st = suballocations1st.back();
+ return topSuballoc2nd.offset - (lastSuballoc1st.offset + lastSuballoc1st.size);
+ }
+ break;
- default:
- VMA_ASSERT(0);
- return 0;
+ default:
+ VMA_ASSERT(0);
+ return 0;
}
}
-void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo &outInfo) const {
+void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
+{
const VkDeviceSize size = GetSize();
- const SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- const SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+ const SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
const size_t suballoc1stCount = suballocations1st.size();
const size_t suballoc2ndCount = suballocations2nd.size();
@@ -8495,22 +9548,27 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo &outInfo) const
VkDeviceSize lastOffset = 0;
- if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
const VkDeviceSize freeSpace2ndTo1stEnd = suballocations1st[m_1stNullItemsBeginCount].offset;
size_t nextAlloc2ndIndex = 0;
- while (lastOffset < freeSpace2ndTo1stEnd) {
+ while(lastOffset < freeSpace2ndTo1stEnd)
+ {
// Find next non-null allocation or move nextAllocIndex to the end.
- while (nextAlloc2ndIndex < suballoc2ndCount &&
- suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc2ndIndex < suballoc2ndCount &&
+ suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE)
+ {
++nextAlloc2ndIndex;
}
// Found non-null allocation.
- if (nextAlloc2ndIndex < suballoc2ndCount) {
- const VmaSuballocation &suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+ if(nextAlloc2ndIndex < suballoc2ndCount)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
++outInfo.unusedRangeCount;
@@ -8518,27 +9576,29 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo &outInfo) const
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
outInfo.usedBytes += suballoc.size;
outInfo.allocationSizeMin = VMA_MIN(outInfo.allocationSizeMin, suballoc.size);
outInfo.allocationSizeMax = VMA_MIN(outInfo.allocationSizeMax, suballoc.size);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc2ndIndex;
}
// We are at the end.
- else {
+ else
+ {
// There is free space from lastOffset to freeSpace2ndTo1stEnd.
- if (lastOffset < freeSpace2ndTo1stEnd) {
+ if(lastOffset < freeSpace2ndTo1stEnd)
+ {
const VkDeviceSize unusedRangeSize = freeSpace2ndTo1stEnd - lastOffset;
++outInfo.unusedRangeCount;
outInfo.unusedBytes += unusedRangeSize;
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
- }
+ }
// End of loop.
lastOffset = freeSpace2ndTo1stEnd;
@@ -8548,20 +9608,24 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo &outInfo) const
size_t nextAlloc1stIndex = m_1stNullItemsBeginCount;
const VkDeviceSize freeSpace1stTo2ndEnd =
- m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size;
- while (lastOffset < freeSpace1stTo2ndEnd) {
+ m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size;
+ while(lastOffset < freeSpace1stTo2ndEnd)
+ {
// Find next non-null allocation or move nextAllocIndex to the end.
- while (nextAlloc1stIndex < suballoc1stCount &&
- suballocations1st[nextAlloc1stIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc1stIndex < suballoc1stCount &&
+ suballocations1st[nextAlloc1stIndex].hAllocation == VK_NULL_HANDLE)
+ {
++nextAlloc1stIndex;
}
// Found non-null allocation.
- if (nextAlloc1stIndex < suballoc1stCount) {
- const VmaSuballocation &suballoc = suballocations1st[nextAlloc1stIndex];
-
+ if(nextAlloc1stIndex < suballoc1stCount)
+ {
+ const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
++outInfo.unusedRangeCount;
@@ -8569,48 +9633,55 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo &outInfo) const
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
outInfo.usedBytes += suballoc.size;
outInfo.allocationSizeMin = VMA_MIN(outInfo.allocationSizeMin, suballoc.size);
outInfo.allocationSizeMax = VMA_MIN(outInfo.allocationSizeMax, suballoc.size);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc1stIndex;
}
// We are at the end.
- else {
+ else
+ {
// There is free space from lastOffset to freeSpace1stTo2ndEnd.
- if (lastOffset < freeSpace1stTo2ndEnd) {
+ if(lastOffset < freeSpace1stTo2ndEnd)
+ {
const VkDeviceSize unusedRangeSize = freeSpace1stTo2ndEnd - lastOffset;
++outInfo.unusedRangeCount;
outInfo.unusedBytes += unusedRangeSize;
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
- }
+ }
// End of loop.
lastOffset = freeSpace1stTo2ndEnd;
}
}
- if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) {
+ if(m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ {
size_t nextAlloc2ndIndex = suballocations2nd.size() - 1;
- while (lastOffset < size) {
+ while(lastOffset < size)
+ {
// Find next non-null allocation or move nextAllocIndex to the end.
- while (nextAlloc2ndIndex != SIZE_MAX &&
- suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc2ndIndex != SIZE_MAX &&
+ suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE)
+ {
--nextAlloc2ndIndex;
}
// Found non-null allocation.
- if (nextAlloc2ndIndex != SIZE_MAX) {
- const VmaSuballocation &suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+ if(nextAlloc2ndIndex != SIZE_MAX)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
++outInfo.unusedRangeCount;
@@ -8618,27 +9689,29 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo &outInfo) const
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
outInfo.usedBytes += suballoc.size;
outInfo.allocationSizeMin = VMA_MIN(outInfo.allocationSizeMin, suballoc.size);
outInfo.allocationSizeMax = VMA_MIN(outInfo.allocationSizeMax, suballoc.size);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
--nextAlloc2ndIndex;
}
// We are at the end.
- else {
+ else
+ {
// There is free space from lastOffset to size.
- if (lastOffset < size) {
+ if(lastOffset < size)
+ {
const VkDeviceSize unusedRangeSize = size - lastOffset;
++outInfo.unusedRangeCount;
outInfo.unusedBytes += unusedRangeSize;
outInfo.unusedRangeSizeMin = VMA_MIN(outInfo.unusedRangeSizeMin, unusedRangeSize);
outInfo.unusedRangeSizeMax = VMA_MIN(outInfo.unusedRangeSizeMax, unusedRangeSize);
- }
+ }
// End of loop.
lastOffset = size;
@@ -8649,9 +9722,10 @@ void VmaBlockMetadata_Linear::CalcAllocationStatInfo(VmaStatInfo &outInfo) const
outInfo.unusedBytes = size - outInfo.usedBytes;
}
-void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats &inoutStats) const {
- const SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- const SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats& inoutStats) const
+{
+ const SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
const VkDeviceSize size = GetSize();
const size_t suballoc1stCount = suballocations1st.size();
const size_t suballoc2ndCount = suballocations2nd.size();
@@ -8660,40 +9734,47 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats &inoutStats) const {
VkDeviceSize lastOffset = 0;
- if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
const VkDeviceSize freeSpace2ndTo1stEnd = suballocations1st[m_1stNullItemsBeginCount].offset;
size_t nextAlloc2ndIndex = m_1stNullItemsBeginCount;
- while (lastOffset < freeSpace2ndTo1stEnd) {
+ while(lastOffset < freeSpace2ndTo1stEnd)
+ {
// Find next non-null allocation or move nextAlloc2ndIndex to the end.
- while (nextAlloc2ndIndex < suballoc2ndCount &&
- suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc2ndIndex < suballoc2ndCount &&
+ suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE)
+ {
++nextAlloc2ndIndex;
}
// Found non-null allocation.
- if (nextAlloc2ndIndex < suballoc2ndCount) {
- const VmaSuballocation &suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+ if(nextAlloc2ndIndex < suballoc2ndCount)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
inoutStats.unusedSize += unusedRangeSize;
++inoutStats.unusedRangeCount;
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++inoutStats.allocationCount;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc2ndIndex;
}
// We are at the end.
- else {
- if (lastOffset < freeSpace2ndTo1stEnd) {
+ else
+ {
+ if(lastOffset < freeSpace2ndTo1stEnd)
+ {
// There is free space from lastOffset to freeSpace2ndTo1stEnd.
const VkDeviceSize unusedRangeSize = freeSpace2ndTo1stEnd - lastOffset;
inoutStats.unusedSize += unusedRangeSize;
@@ -8709,38 +9790,44 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats &inoutStats) const {
size_t nextAlloc1stIndex = m_1stNullItemsBeginCount;
const VkDeviceSize freeSpace1stTo2ndEnd =
- m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size;
- while (lastOffset < freeSpace1stTo2ndEnd) {
+ m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size;
+ while(lastOffset < freeSpace1stTo2ndEnd)
+ {
// Find next non-null allocation or move nextAllocIndex to the end.
- while (nextAlloc1stIndex < suballoc1stCount &&
- suballocations1st[nextAlloc1stIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc1stIndex < suballoc1stCount &&
+ suballocations1st[nextAlloc1stIndex].hAllocation == VK_NULL_HANDLE)
+ {
++nextAlloc1stIndex;
}
// Found non-null allocation.
- if (nextAlloc1stIndex < suballoc1stCount) {
- const VmaSuballocation &suballoc = suballocations1st[nextAlloc1stIndex];
-
+ if(nextAlloc1stIndex < suballoc1stCount)
+ {
+ const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
inoutStats.unusedSize += unusedRangeSize;
++inoutStats.unusedRangeCount;
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++inoutStats.allocationCount;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc1stIndex;
}
// We are at the end.
- else {
- if (lastOffset < freeSpace1stTo2ndEnd) {
+ else
+ {
+ if(lastOffset < freeSpace1stTo2ndEnd)
+ {
// There is free space from lastOffset to freeSpace1stTo2ndEnd.
const VkDeviceSize unusedRangeSize = freeSpace1stTo2ndEnd - lastOffset;
inoutStats.unusedSize += unusedRangeSize;
@@ -8753,39 +9840,46 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats &inoutStats) const {
}
}
- if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) {
+ if(m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ {
size_t nextAlloc2ndIndex = suballocations2nd.size() - 1;
- while (lastOffset < size) {
+ while(lastOffset < size)
+ {
// Find next non-null allocation or move nextAlloc2ndIndex to the end.
- while (nextAlloc2ndIndex != SIZE_MAX &&
- suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc2ndIndex != SIZE_MAX &&
+ suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE)
+ {
--nextAlloc2ndIndex;
}
// Found non-null allocation.
- if (nextAlloc2ndIndex != SIZE_MAX) {
- const VmaSuballocation &suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+ if(nextAlloc2ndIndex != SIZE_MAX)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
inoutStats.unusedSize += unusedRangeSize;
++inoutStats.unusedRangeCount;
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++inoutStats.allocationCount;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
--nextAlloc2ndIndex;
}
// We are at the end.
- else {
- if (lastOffset < size) {
+ else
+ {
+ if(lastOffset < size)
+ {
// There is free space from lastOffset to size.
const VkDeviceSize unusedRangeSize = size - lastOffset;
inoutStats.unusedSize += unusedRangeSize;
@@ -8801,10 +9895,11 @@ void VmaBlockMetadata_Linear::AddPoolStats(VmaPoolStats &inoutStats) const {
}
#if VMA_STATS_STRING_ENABLED
-void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter &json) const {
+void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter& json) const
+{
const VkDeviceSize size = GetSize();
- const SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- const SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+ const SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ const SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
const size_t suballoc1stCount = suballocations1st.size();
const size_t suballoc2ndCount = suballocations2nd.size();
@@ -8816,38 +9911,45 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter &json) const
VkDeviceSize lastOffset = 0;
size_t alloc2ndCount = 0;
- if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
const VkDeviceSize freeSpace2ndTo1stEnd = suballocations1st[m_1stNullItemsBeginCount].offset;
size_t nextAlloc2ndIndex = 0;
- while (lastOffset < freeSpace2ndTo1stEnd) {
+ while(lastOffset < freeSpace2ndTo1stEnd)
+ {
// Find next non-null allocation or move nextAlloc2ndIndex to the end.
- while (nextAlloc2ndIndex < suballoc2ndCount &&
- suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc2ndIndex < suballoc2ndCount &&
+ suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE)
+ {
++nextAlloc2ndIndex;
}
// Found non-null allocation.
- if (nextAlloc2ndIndex < suballoc2ndCount) {
- const VmaSuballocation &suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+ if(nextAlloc2ndIndex < suballoc2ndCount)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
++unusedRangeCount;
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++alloc2ndCount;
usedBytes += suballoc.size;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc2ndIndex;
}
// We are at the end.
- else {
- if (lastOffset < freeSpace2ndTo1stEnd) {
+ else
+ {
+ if(lastOffset < freeSpace2ndTo1stEnd)
+ {
// There is free space from lastOffset to freeSpace2ndTo1stEnd.
++unusedRangeCount;
}
@@ -8861,36 +9963,42 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter &json) const
size_t nextAlloc1stIndex = m_1stNullItemsBeginCount;
size_t alloc1stCount = 0;
const VkDeviceSize freeSpace1stTo2ndEnd =
- m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size;
- while (lastOffset < freeSpace1stTo2ndEnd) {
+ m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ? suballocations2nd.back().offset : size;
+ while(lastOffset < freeSpace1stTo2ndEnd)
+ {
// Find next non-null allocation or move nextAllocIndex to the end.
- while (nextAlloc1stIndex < suballoc1stCount &&
- suballocations1st[nextAlloc1stIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc1stIndex < suballoc1stCount &&
+ suballocations1st[nextAlloc1stIndex].hAllocation == VK_NULL_HANDLE)
+ {
++nextAlloc1stIndex;
}
// Found non-null allocation.
- if (nextAlloc1stIndex < suballoc1stCount) {
- const VmaSuballocation &suballoc = suballocations1st[nextAlloc1stIndex];
-
+ if(nextAlloc1stIndex < suballoc1stCount)
+ {
+ const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
++unusedRangeCount;
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++alloc1stCount;
usedBytes += suballoc.size;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc1stIndex;
}
// We are at the end.
- else {
- if (lastOffset < size) {
+ else
+ {
+ if(lastOffset < size)
+ {
// There is free space from lastOffset to freeSpace1stTo2ndEnd.
++unusedRangeCount;
}
@@ -8900,37 +10008,44 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter &json) const
}
}
- if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) {
+ if(m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ {
size_t nextAlloc2ndIndex = suballocations2nd.size() - 1;
- while (lastOffset < size) {
+ while(lastOffset < size)
+ {
// Find next non-null allocation or move nextAlloc2ndIndex to the end.
- while (nextAlloc2ndIndex != SIZE_MAX &&
- suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc2ndIndex != SIZE_MAX &&
+ suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE)
+ {
--nextAlloc2ndIndex;
}
// Found non-null allocation.
- if (nextAlloc2ndIndex != SIZE_MAX) {
- const VmaSuballocation &suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+ if(nextAlloc2ndIndex != SIZE_MAX)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
++unusedRangeCount;
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
++alloc2ndCount;
usedBytes += suballoc.size;
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
--nextAlloc2ndIndex;
}
// We are at the end.
- else {
- if (lastOffset < size) {
+ else
+ {
+ if(lastOffset < size)
+ {
// There is free space from lastOffset to size.
++unusedRangeCount;
}
@@ -8947,38 +10062,45 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter &json) const
// SECOND PASS
lastOffset = 0;
- if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
const VkDeviceSize freeSpace2ndTo1stEnd = suballocations1st[m_1stNullItemsBeginCount].offset;
size_t nextAlloc2ndIndex = 0;
- while (lastOffset < freeSpace2ndTo1stEnd) {
+ while(lastOffset < freeSpace2ndTo1stEnd)
+ {
// Find next non-null allocation or move nextAlloc2ndIndex to the end.
- while (nextAlloc2ndIndex < suballoc2ndCount &&
- suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc2ndIndex < suballoc2ndCount &&
+ suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE)
+ {
++nextAlloc2ndIndex;
}
// Found non-null allocation.
- if (nextAlloc2ndIndex < suballoc2ndCount) {
- const VmaSuballocation &suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+ if(nextAlloc2ndIndex < suballoc2ndCount)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.hAllocation);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc2ndIndex;
}
// We are at the end.
- else {
- if (lastOffset < freeSpace2ndTo1stEnd) {
+ else
+ {
+ if(lastOffset < freeSpace2ndTo1stEnd)
+ {
// There is free space from lastOffset to freeSpace2ndTo1stEnd.
const VkDeviceSize unusedRangeSize = freeSpace2ndTo1stEnd - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
@@ -8991,35 +10113,41 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter &json) const
}
nextAlloc1stIndex = m_1stNullItemsBeginCount;
- while (lastOffset < freeSpace1stTo2ndEnd) {
+ while(lastOffset < freeSpace1stTo2ndEnd)
+ {
// Find next non-null allocation or move nextAllocIndex to the end.
- while (nextAlloc1stIndex < suballoc1stCount &&
- suballocations1st[nextAlloc1stIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc1stIndex < suballoc1stCount &&
+ suballocations1st[nextAlloc1stIndex].hAllocation == VK_NULL_HANDLE)
+ {
++nextAlloc1stIndex;
}
// Found non-null allocation.
- if (nextAlloc1stIndex < suballoc1stCount) {
- const VmaSuballocation &suballoc = suballocations1st[nextAlloc1stIndex];
-
+ if(nextAlloc1stIndex < suballoc1stCount)
+ {
+ const VmaSuballocation& suballoc = suballocations1st[nextAlloc1stIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.hAllocation);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
++nextAlloc1stIndex;
}
// We are at the end.
- else {
- if (lastOffset < freeSpace1stTo2ndEnd) {
+ else
+ {
+ if(lastOffset < freeSpace1stTo2ndEnd)
+ {
// There is free space from lastOffset to freeSpace1stTo2ndEnd.
const VkDeviceSize unusedRangeSize = freeSpace1stTo2ndEnd - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
@@ -9030,37 +10158,44 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter &json) const
}
}
- if (m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) {
+ if(m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ {
size_t nextAlloc2ndIndex = suballocations2nd.size() - 1;
- while (lastOffset < size) {
+ while(lastOffset < size)
+ {
// Find next non-null allocation or move nextAlloc2ndIndex to the end.
- while (nextAlloc2ndIndex != SIZE_MAX &&
- suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE) {
+ while(nextAlloc2ndIndex != SIZE_MAX &&
+ suballocations2nd[nextAlloc2ndIndex].hAllocation == VK_NULL_HANDLE)
+ {
--nextAlloc2ndIndex;
}
// Found non-null allocation.
- if (nextAlloc2ndIndex != SIZE_MAX) {
- const VmaSuballocation &suballoc = suballocations2nd[nextAlloc2ndIndex];
-
+ if(nextAlloc2ndIndex != SIZE_MAX)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[nextAlloc2ndIndex];
+
// 1. Process free space before this allocation.
- if (lastOffset < suballoc.offset) {
+ if(lastOffset < suballoc.offset)
+ {
// There is free space from lastOffset to suballoc.offset.
const VkDeviceSize unusedRangeSize = suballoc.offset - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
}
-
+
// 2. Process this allocation.
// There is allocation with suballoc.offset, suballoc.size.
PrintDetailedMap_Allocation(json, suballoc.offset, suballoc.hAllocation);
-
+
// 3. Prepare for next iteration.
lastOffset = suballoc.offset + suballoc.size;
--nextAlloc2ndIndex;
}
// We are at the end.
- else {
- if (lastOffset < size) {
+ else
+ {
+ if(lastOffset < size)
+ {
// There is free space from lastOffset to size.
const VkDeviceSize unusedRangeSize = size - lastOffset;
PrintDetailedMap_UnusedRange(json, lastOffset, unusedRangeSize);
@@ -9077,57 +10212,63 @@ void VmaBlockMetadata_Linear::PrintDetailedMap(class VmaJsonWriter &json) const
#endif // #if VMA_STATS_STRING_ENABLED
bool VmaBlockMetadata_Linear::CreateAllocationRequest(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- bool upperAddress,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest) {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ bool upperAddress,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest)
+{
VMA_ASSERT(allocSize > 0);
VMA_ASSERT(allocType != VMA_SUBALLOCATION_TYPE_FREE);
VMA_ASSERT(pAllocationRequest != VMA_NULL);
VMA_HEAVY_ASSERT(Validate());
return upperAddress ?
- CreateAllocationRequest_UpperAddress(
- currentFrameIndex, frameInUseCount, bufferImageGranularity,
- allocSize, allocAlignment, allocType, canMakeOtherLost, strategy, pAllocationRequest) :
- CreateAllocationRequest_LowerAddress(
- currentFrameIndex, frameInUseCount, bufferImageGranularity,
- allocSize, allocAlignment, allocType, canMakeOtherLost, strategy, pAllocationRequest);
+ CreateAllocationRequest_UpperAddress(
+ currentFrameIndex, frameInUseCount, bufferImageGranularity,
+ allocSize, allocAlignment, allocType, canMakeOtherLost, strategy, pAllocationRequest) :
+ CreateAllocationRequest_LowerAddress(
+ currentFrameIndex, frameInUseCount, bufferImageGranularity,
+ allocSize, allocAlignment, allocType, canMakeOtherLost, strategy, pAllocationRequest);
}
bool VmaBlockMetadata_Linear::CreateAllocationRequest_UpperAddress(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest) {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest)
+{
const VkDeviceSize size = GetSize();
- SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+ SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
- if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
VMA_ASSERT(0 && "Trying to use pool with linear algorithm as double stack, while it is already being used as ring buffer.");
return false;
}
// Try to allocate before 2nd.back(), or end of block if 2nd.empty().
- if (allocSize > size) {
+ if(allocSize > size)
+ {
return false;
}
VkDeviceSize resultBaseOffset = size - allocSize;
- if (!suballocations2nd.empty()) {
- const VmaSuballocation &lastSuballoc = suballocations2nd.back();
+ if(!suballocations2nd.empty())
+ {
+ const VmaSuballocation& lastSuballoc = suballocations2nd.back();
resultBaseOffset = lastSuballoc.offset - allocSize;
- if (allocSize > lastSuballoc.offset) {
+ if(allocSize > lastSuballoc.offset)
+ {
return false;
}
}
@@ -9136,8 +10277,10 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_UpperAddress(
VkDeviceSize resultOffset = resultBaseOffset;
// Apply VMA_DEBUG_MARGIN at the end.
- if (VMA_DEBUG_MARGIN > 0) {
- if (resultOffset < VMA_DEBUG_MARGIN) {
+ if(VMA_DEBUG_MARGIN > 0)
+ {
+ if(resultOffset < VMA_DEBUG_MARGIN)
+ {
return false;
}
resultOffset -= VMA_DEBUG_MARGIN;
@@ -9148,39 +10291,52 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_UpperAddress(
// Check next suballocations from 2nd for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if (bufferImageGranularity > 1 && !suballocations2nd.empty()) {
+ if(bufferImageGranularity > 1 && !suballocations2nd.empty())
+ {
bool bufferImageGranularityConflict = false;
- for (size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--;) {
- const VmaSuballocation &nextSuballoc = suballocations2nd[nextSuballocIndex];
- if (VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(nextSuballoc.type, allocType)) {
+ for(size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--; )
+ {
+ const VmaSuballocation& nextSuballoc = suballocations2nd[nextSuballocIndex];
+ if(VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(nextSuballoc.type, allocType))
+ {
bufferImageGranularityConflict = true;
break;
}
- } else
+ }
+ else
// Already on previous page.
break;
}
- if (bufferImageGranularityConflict) {
+ if(bufferImageGranularityConflict)
+ {
resultOffset = VmaAlignDown(resultOffset, bufferImageGranularity);
}
}
// There is enough free space.
const VkDeviceSize endOf1st = !suballocations1st.empty() ?
- suballocations1st.back().offset + suballocations1st.back().size :
- 0;
- if (endOf1st + VMA_DEBUG_MARGIN <= resultOffset) {
+ suballocations1st.back().offset + suballocations1st.back().size :
+ 0;
+ if(endOf1st + VMA_DEBUG_MARGIN <= resultOffset)
+ {
// Check previous suballocations for BufferImageGranularity conflicts.
// If conflict exists, allocation cannot be made here.
- if (bufferImageGranularity > 1) {
- for (size_t prevSuballocIndex = suballocations1st.size(); prevSuballocIndex--;) {
- const VmaSuballocation &prevSuballoc = suballocations1st[prevSuballocIndex];
- if (VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(allocType, prevSuballoc.type)) {
+ if(bufferImageGranularity > 1)
+ {
+ for(size_t prevSuballocIndex = suballocations1st.size(); prevSuballocIndex--; )
+ {
+ const VmaSuballocation& prevSuballoc = suballocations1st[prevSuballocIndex];
+ if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(allocType, prevSuballoc.type))
+ {
return false;
}
- } else {
+ }
+ else
+ {
// Already on next page.
break;
}
@@ -9201,25 +10357,28 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_UpperAddress(
}
bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest) {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest)
+{
const VkDeviceSize size = GetSize();
- SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+ SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
- if (m_2ndVectorMode == SECOND_VECTOR_EMPTY || m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) {
+ if(m_2ndVectorMode == SECOND_VECTOR_EMPTY || m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ {
// Try to allocate at the end of 1st vector.
VkDeviceSize resultBaseOffset = 0;
- if (!suballocations1st.empty()) {
- const VmaSuballocation &lastSuballoc = suballocations1st.back();
+ if(!suballocations1st.empty())
+ {
+ const VmaSuballocation& lastSuballoc = suballocations1st.back();
resultBaseOffset = lastSuballoc.offset + lastSuballoc.size;
}
@@ -9227,7 +10386,8 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
VkDeviceSize resultOffset = resultBaseOffset;
// Apply VMA_DEBUG_MARGIN at the beginning.
- if (VMA_DEBUG_MARGIN > 0) {
+ if(VMA_DEBUG_MARGIN > 0)
+ {
resultOffset += VMA_DEBUG_MARGIN;
}
@@ -9236,40 +10396,52 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
// Check previous suballocations for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if (bufferImageGranularity > 1 && !suballocations1st.empty()) {
+ if(bufferImageGranularity > 1 && !suballocations1st.empty())
+ {
bool bufferImageGranularityConflict = false;
- for (size_t prevSuballocIndex = suballocations1st.size(); prevSuballocIndex--;) {
- const VmaSuballocation &prevSuballoc = suballocations1st[prevSuballocIndex];
- if (VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType)) {
+ for(size_t prevSuballocIndex = suballocations1st.size(); prevSuballocIndex--; )
+ {
+ const VmaSuballocation& prevSuballoc = suballocations1st[prevSuballocIndex];
+ if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType))
+ {
bufferImageGranularityConflict = true;
break;
}
- } else
+ }
+ else
// Already on previous page.
break;
}
- if (bufferImageGranularityConflict) {
+ if(bufferImageGranularityConflict)
+ {
resultOffset = VmaAlignUp(resultOffset, bufferImageGranularity);
}
}
const VkDeviceSize freeSpaceEnd = m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK ?
- suballocations2nd.back().offset :
- size;
+ suballocations2nd.back().offset : size;
// There is enough free space at the end after alignment.
- if (resultOffset + allocSize + VMA_DEBUG_MARGIN <= freeSpaceEnd) {
+ if(resultOffset + allocSize + VMA_DEBUG_MARGIN <= freeSpaceEnd)
+ {
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, allocation cannot be made here.
- if (bufferImageGranularity > 1 && m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) {
- for (size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--;) {
- const VmaSuballocation &nextSuballoc = suballocations2nd[nextSuballocIndex];
- if (VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type)) {
+ if(bufferImageGranularity > 1 && m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ {
+ for(size_t nextSuballocIndex = suballocations2nd.size(); nextSuballocIndex--; )
+ {
+ const VmaSuballocation& nextSuballoc = suballocations2nd[nextSuballocIndex];
+ if(VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type))
+ {
return false;
}
- } else {
+ }
+ else
+ {
// Already on previous page.
break;
}
@@ -9289,12 +10461,14 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
// Wrap-around to end of 2nd vector. Try to allocate there, watching for the
// beginning of 1st vector as the end of free space.
- if (m_2ndVectorMode == SECOND_VECTOR_EMPTY || m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(m_2ndVectorMode == SECOND_VECTOR_EMPTY || m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
VMA_ASSERT(!suballocations1st.empty());
VkDeviceSize resultBaseOffset = 0;
- if (!suballocations2nd.empty()) {
- const VmaSuballocation &lastSuballoc = suballocations2nd.back();
+ if(!suballocations2nd.empty())
+ {
+ const VmaSuballocation& lastSuballoc = suballocations2nd.back();
resultBaseOffset = lastSuballoc.offset + lastSuballoc.size;
}
@@ -9302,7 +10476,8 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
VkDeviceSize resultOffset = resultBaseOffset;
// Apply VMA_DEBUG_MARGIN at the beginning.
- if (VMA_DEBUG_MARGIN > 0) {
+ if(VMA_DEBUG_MARGIN > 0)
+ {
resultOffset += VMA_DEBUG_MARGIN;
}
@@ -9311,20 +10486,26 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
// Check previous suballocations for BufferImageGranularity conflicts.
// Make bigger alignment if necessary.
- if (bufferImageGranularity > 1 && !suballocations2nd.empty()) {
+ if(bufferImageGranularity > 1 && !suballocations2nd.empty())
+ {
bool bufferImageGranularityConflict = false;
- for (size_t prevSuballocIndex = suballocations2nd.size(); prevSuballocIndex--;) {
- const VmaSuballocation &prevSuballoc = suballocations2nd[prevSuballocIndex];
- if (VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType)) {
+ for(size_t prevSuballocIndex = suballocations2nd.size(); prevSuballocIndex--; )
+ {
+ const VmaSuballocation& prevSuballoc = suballocations2nd[prevSuballocIndex];
+ if(VmaBlocksOnSamePage(prevSuballoc.offset, prevSuballoc.size, resultOffset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(prevSuballoc.type, allocType))
+ {
bufferImageGranularityConflict = true;
break;
}
- } else
+ }
+ else
// Already on previous page.
break;
}
- if (bufferImageGranularityConflict) {
+ if(bufferImageGranularityConflict)
+ {
resultOffset = VmaAlignUp(resultOffset, bufferImageGranularity);
}
}
@@ -9333,20 +10514,28 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
pAllocationRequest->sumItemSize = 0;
size_t index1st = m_1stNullItemsBeginCount;
- if (canMakeOtherLost) {
- while (index1st < suballocations1st.size() &&
- resultOffset + allocSize + VMA_DEBUG_MARGIN > suballocations1st[index1st].offset) {
+ if(canMakeOtherLost)
+ {
+ while(index1st < suballocations1st.size() &&
+ resultOffset + allocSize + VMA_DEBUG_MARGIN > suballocations1st[index1st].offset)
+ {
// Next colliding allocation at the beginning of 1st vector found. Try to make it lost.
- const VmaSuballocation &suballoc = suballocations1st[index1st];
- if (suballoc.type == VMA_SUBALLOCATION_TYPE_FREE) {
+ const VmaSuballocation& suballoc = suballocations1st[index1st];
+ if(suballoc.type == VMA_SUBALLOCATION_TYPE_FREE)
+ {
// No problem.
- } else {
+ }
+ else
+ {
VMA_ASSERT(suballoc.hAllocation != VK_NULL_HANDLE);
- if (suballoc.hAllocation->CanBecomeLost() &&
- suballoc.hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex) {
+ if(suballoc.hAllocation->CanBecomeLost() &&
+ suballoc.hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex)
+ {
++pAllocationRequest->itemsToMakeLostCount;
pAllocationRequest->sumItemSize += suballoc.size;
- } else {
+ }
+ else
+ {
return false;
}
}
@@ -9355,21 +10544,30 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, we must mark more allocations lost or fail.
- if (bufferImageGranularity > 1) {
- while (index1st < suballocations1st.size()) {
- const VmaSuballocation &suballoc = suballocations1st[index1st];
- if (VmaBlocksOnSamePage(resultOffset, allocSize, suballoc.offset, bufferImageGranularity)) {
- if (suballoc.hAllocation != VK_NULL_HANDLE) {
+ if(bufferImageGranularity > 1)
+ {
+ while(index1st < suballocations1st.size())
+ {
+ const VmaSuballocation& suballoc = suballocations1st[index1st];
+ if(VmaBlocksOnSamePage(resultOffset, allocSize, suballoc.offset, bufferImageGranularity))
+ {
+ if(suballoc.hAllocation != VK_NULL_HANDLE)
+ {
// Not checking actual VmaIsBufferImageGranularityConflict(allocType, suballoc.type).
- if (suballoc.hAllocation->CanBecomeLost() &&
- suballoc.hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex) {
+ if(suballoc.hAllocation->CanBecomeLost() &&
+ suballoc.hAllocation->GetLastUseFrameIndex() + frameInUseCount < currentFrameIndex)
+ {
++pAllocationRequest->itemsToMakeLostCount;
pAllocationRequest->sumItemSize += suballoc.size;
- } else {
+ }
+ else
+ {
return false;
}
}
- } else {
+ }
+ else
+ {
// Already on next page.
break;
}
@@ -9378,28 +10576,36 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
}
// Special case: There is not enough room at the end for this allocation, even after making all from the 1st lost.
- if (index1st == suballocations1st.size() &&
- resultOffset + allocSize + VMA_DEBUG_MARGIN > size) {
+ if(index1st == suballocations1st.size() &&
+ resultOffset + allocSize + VMA_DEBUG_MARGIN > size)
+ {
// TODO: This is a known bug that it's not yet implemented and the allocation is failing.
VMA_DEBUG_LOG("Unsupported special case in custom pool with linear allocation algorithm used as ring buffer with allocations that can be lost.");
}
}
// There is enough free space at the end after alignment.
- if ((index1st == suballocations1st.size() && resultOffset + allocSize + VMA_DEBUG_MARGIN <= size) ||
- (index1st < suballocations1st.size() && resultOffset + allocSize + VMA_DEBUG_MARGIN <= suballocations1st[index1st].offset)) {
+ if((index1st == suballocations1st.size() && resultOffset + allocSize + VMA_DEBUG_MARGIN <= size) ||
+ (index1st < suballocations1st.size() && resultOffset + allocSize + VMA_DEBUG_MARGIN <= suballocations1st[index1st].offset))
+ {
// Check next suballocations for BufferImageGranularity conflicts.
// If conflict exists, allocation cannot be made here.
- if (bufferImageGranularity > 1) {
- for (size_t nextSuballocIndex = index1st;
- nextSuballocIndex < suballocations1st.size();
- nextSuballocIndex++) {
- const VmaSuballocation &nextSuballoc = suballocations1st[nextSuballocIndex];
- if (VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity)) {
- if (VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type)) {
+ if(bufferImageGranularity > 1)
+ {
+ for(size_t nextSuballocIndex = index1st;
+ nextSuballocIndex < suballocations1st.size();
+ nextSuballocIndex++)
+ {
+ const VmaSuballocation& nextSuballoc = suballocations1st[nextSuballocIndex];
+ if(VmaBlocksOnSamePage(resultOffset, allocSize, nextSuballoc.offset, bufferImageGranularity))
+ {
+ if(VmaIsBufferImageGranularityConflict(allocType, nextSuballoc.type))
+ {
return false;
}
- } else {
+ }
+ else
+ {
// Already on next page.
break;
}
@@ -9409,7 +10615,9 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
// All tests passed: Success.
pAllocationRequest->offset = resultOffset;
pAllocationRequest->sumFreeSize =
- (index1st < suballocations1st.size() ? suballocations1st[index1st].offset : size) - resultBaseOffset - pAllocationRequest->sumItemSize;
+ (index1st < suballocations1st.size() ? suballocations1st[index1st].offset : size)
+ - resultBaseOffset
+ - pAllocationRequest->sumItemSize;
pAllocationRequest->type = VmaAllocationRequestType::EndOf2nd;
// pAllocationRequest->item, customData unused.
return true;
@@ -9420,45 +10628,57 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest_LowerAddress(
}
bool VmaBlockMetadata_Linear::MakeRequestedAllocationsLost(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VmaAllocationRequest *pAllocationRequest) {
- if (pAllocationRequest->itemsToMakeLostCount == 0) {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VmaAllocationRequest* pAllocationRequest)
+{
+ if(pAllocationRequest->itemsToMakeLostCount == 0)
+ {
return true;
}
VMA_ASSERT(m_2ndVectorMode == SECOND_VECTOR_EMPTY || m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER);
-
+
// We always start from 1st.
- SuballocationVectorType *suballocations = &AccessSuballocations1st();
+ SuballocationVectorType* suballocations = &AccessSuballocations1st();
size_t index = m_1stNullItemsBeginCount;
size_t madeLostCount = 0;
- while (madeLostCount < pAllocationRequest->itemsToMakeLostCount) {
- if (index == suballocations->size()) {
+ while(madeLostCount < pAllocationRequest->itemsToMakeLostCount)
+ {
+ if(index == suballocations->size())
+ {
index = 0;
// If we get to the end of 1st, we wrap around to beginning of 2nd of 1st.
- if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
suballocations = &AccessSuballocations2nd();
}
// else: m_2ndVectorMode == SECOND_VECTOR_EMPTY:
// suballocations continues pointing at AccessSuballocations1st().
VMA_ASSERT(!suballocations->empty());
}
- VmaSuballocation &suballoc = (*suballocations)[index];
- if (suballoc.type != VMA_SUBALLOCATION_TYPE_FREE) {
+ VmaSuballocation& suballoc = (*suballocations)[index];
+ if(suballoc.type != VMA_SUBALLOCATION_TYPE_FREE)
+ {
VMA_ASSERT(suballoc.hAllocation != VK_NULL_HANDLE);
VMA_ASSERT(suballoc.hAllocation->CanBecomeLost());
- if (suballoc.hAllocation->MakeLost(currentFrameIndex, frameInUseCount)) {
+ if(suballoc.hAllocation->MakeLost(currentFrameIndex, frameInUseCount))
+ {
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE;
m_SumFreeSize += suballoc.size;
- if (suballocations == &AccessSuballocations1st()) {
+ if(suballocations == &AccessSuballocations1st())
+ {
++m_1stNullItemsMiddleCount;
- } else {
+ }
+ else
+ {
++m_2ndNullItemsCount;
}
++madeLostCount;
- } else {
+ }
+ else
+ {
return false;
}
}
@@ -9467,19 +10687,22 @@ bool VmaBlockMetadata_Linear::MakeRequestedAllocationsLost(
CleanupAfterFree();
//VMA_HEAVY_ASSERT(Validate()); // Already called by ClanupAfterFree().
-
+
return true;
}
-uint32_t VmaBlockMetadata_Linear::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount) {
+uint32_t VmaBlockMetadata_Linear::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount)
+{
uint32_t lostAllocationCount = 0;
-
- SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- for (size_t i = m_1stNullItemsBeginCount, count = suballocations1st.size(); i < count; ++i) {
- VmaSuballocation &suballoc = suballocations1st[i];
- if (suballoc.type != VMA_SUBALLOCATION_TYPE_FREE &&
- suballoc.hAllocation->CanBecomeLost() &&
- suballoc.hAllocation->MakeLost(currentFrameIndex, frameInUseCount)) {
+
+ SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ for(size_t i = m_1stNullItemsBeginCount, count = suballocations1st.size(); i < count; ++i)
+ {
+ VmaSuballocation& suballoc = suballocations1st[i];
+ if(suballoc.type != VMA_SUBALLOCATION_TYPE_FREE &&
+ suballoc.hAllocation->CanBecomeLost() &&
+ suballoc.hAllocation->MakeLost(currentFrameIndex, frameInUseCount))
+ {
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE;
++m_1stNullItemsMiddleCount;
@@ -9488,12 +10711,14 @@ uint32_t VmaBlockMetadata_Linear::MakeAllocationsLost(uint32_t currentFrameIndex
}
}
- SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
- for (size_t i = 0, count = suballocations2nd.size(); i < count; ++i) {
- VmaSuballocation &suballoc = suballocations2nd[i];
- if (suballoc.type != VMA_SUBALLOCATION_TYPE_FREE &&
- suballoc.hAllocation->CanBecomeLost() &&
- suballoc.hAllocation->MakeLost(currentFrameIndex, frameInUseCount)) {
+ SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
+ for(size_t i = 0, count = suballocations2nd.size(); i < count; ++i)
+ {
+ VmaSuballocation& suballoc = suballocations2nd[i];
+ if(suballoc.type != VMA_SUBALLOCATION_TYPE_FREE &&
+ suballoc.hAllocation->CanBecomeLost() &&
+ suballoc.hAllocation->MakeLost(currentFrameIndex, frameInUseCount))
+ {
suballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
suballoc.hAllocation = VK_NULL_HANDLE;
++m_2ndNullItemsCount;
@@ -9502,38 +10727,48 @@ uint32_t VmaBlockMetadata_Linear::MakeAllocationsLost(uint32_t currentFrameIndex
}
}
- if (lostAllocationCount) {
+ if(lostAllocationCount)
+ {
CleanupAfterFree();
}
return lostAllocationCount;
}
-VkResult VmaBlockMetadata_Linear::CheckCorruption(const void *pBlockData) {
- SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- for (size_t i = m_1stNullItemsBeginCount, count = suballocations1st.size(); i < count; ++i) {
- const VmaSuballocation &suballoc = suballocations1st[i];
- if (suballoc.type != VMA_SUBALLOCATION_TYPE_FREE) {
- if (!VmaValidateMagicValue(pBlockData, suballoc.offset - VMA_DEBUG_MARGIN)) {
+VkResult VmaBlockMetadata_Linear::CheckCorruption(const void* pBlockData)
+{
+ SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ for(size_t i = m_1stNullItemsBeginCount, count = suballocations1st.size(); i < count; ++i)
+ {
+ const VmaSuballocation& suballoc = suballocations1st[i];
+ if(suballoc.type != VMA_SUBALLOCATION_TYPE_FREE)
+ {
+ if(!VmaValidateMagicValue(pBlockData, suballoc.offset - VMA_DEBUG_MARGIN))
+ {
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED BEFORE VALIDATED ALLOCATION!");
return VK_ERROR_VALIDATION_FAILED_EXT;
}
- if (!VmaValidateMagicValue(pBlockData, suballoc.offset + suballoc.size)) {
+ if(!VmaValidateMagicValue(pBlockData, suballoc.offset + suballoc.size))
+ {
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED AFTER VALIDATED ALLOCATION!");
return VK_ERROR_VALIDATION_FAILED_EXT;
}
}
}
- SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
- for (size_t i = 0, count = suballocations2nd.size(); i < count; ++i) {
- const VmaSuballocation &suballoc = suballocations2nd[i];
- if (suballoc.type != VMA_SUBALLOCATION_TYPE_FREE) {
- if (!VmaValidateMagicValue(pBlockData, suballoc.offset - VMA_DEBUG_MARGIN)) {
+ SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
+ for(size_t i = 0, count = suballocations2nd.size(); i < count; ++i)
+ {
+ const VmaSuballocation& suballoc = suballocations2nd[i];
+ if(suballoc.type != VMA_SUBALLOCATION_TYPE_FREE)
+ {
+ if(!VmaValidateMagicValue(pBlockData, suballoc.offset - VMA_DEBUG_MARGIN))
+ {
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED BEFORE VALIDATED ALLOCATION!");
return VK_ERROR_VALIDATION_FAILED_EXT;
}
- if (!VmaValidateMagicValue(pBlockData, suballoc.offset + suballoc.size)) {
+ if(!VmaValidateMagicValue(pBlockData, suballoc.offset + suballoc.size))
+ {
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED AFTER VALIDATED ALLOCATION!");
return VK_ERROR_VALIDATION_FAILED_EXT;
}
@@ -9544,75 +10779,88 @@ VkResult VmaBlockMetadata_Linear::CheckCorruption(const void *pBlockData) {
}
void VmaBlockMetadata_Linear::Alloc(
- const VmaAllocationRequest &request,
- VmaSuballocationType type,
- VkDeviceSize allocSize,
- VmaAllocation hAllocation) {
+ const VmaAllocationRequest& request,
+ VmaSuballocationType type,
+ VkDeviceSize allocSize,
+ VmaAllocation hAllocation)
+{
const VmaSuballocation newSuballoc = { request.offset, allocSize, hAllocation, type };
- switch (request.type) {
- case VmaAllocationRequestType::UpperAddress: {
+ switch(request.type)
+ {
+ case VmaAllocationRequestType::UpperAddress:
+ {
VMA_ASSERT(m_2ndVectorMode != SECOND_VECTOR_RING_BUFFER &&
- "CRITICAL ERROR: Trying to use linear allocator as double stack while it was already used as ring buffer.");
- SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+ "CRITICAL ERROR: Trying to use linear allocator as double stack while it was already used as ring buffer.");
+ SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
suballocations2nd.push_back(newSuballoc);
m_2ndVectorMode = SECOND_VECTOR_DOUBLE_STACK;
- } break;
- case VmaAllocationRequestType::EndOf1st: {
- SuballocationVectorType &suballocations1st = AccessSuballocations1st();
+ }
+ break;
+ case VmaAllocationRequestType::EndOf1st:
+ {
+ SuballocationVectorType& suballocations1st = AccessSuballocations1st();
VMA_ASSERT(suballocations1st.empty() ||
- request.offset >= suballocations1st.back().offset + suballocations1st.back().size);
+ request.offset >= suballocations1st.back().offset + suballocations1st.back().size);
// Check if it fits before the end of the block.
VMA_ASSERT(request.offset + allocSize <= GetSize());
suballocations1st.push_back(newSuballoc);
- } break;
- case VmaAllocationRequestType::EndOf2nd: {
- SuballocationVectorType &suballocations1st = AccessSuballocations1st();
+ }
+ break;
+ case VmaAllocationRequestType::EndOf2nd:
+ {
+ SuballocationVectorType& suballocations1st = AccessSuballocations1st();
// New allocation at the end of 2-part ring buffer, so before first allocation from 1st vector.
VMA_ASSERT(!suballocations1st.empty() &&
- request.offset + allocSize <= suballocations1st[m_1stNullItemsBeginCount].offset);
- SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
-
- switch (m_2ndVectorMode) {
- case SECOND_VECTOR_EMPTY:
- // First allocation from second part ring buffer.
- VMA_ASSERT(suballocations2nd.empty());
- m_2ndVectorMode = SECOND_VECTOR_RING_BUFFER;
- break;
- case SECOND_VECTOR_RING_BUFFER:
- // 2-part ring buffer is already started.
- VMA_ASSERT(!suballocations2nd.empty());
- break;
- case SECOND_VECTOR_DOUBLE_STACK:
- VMA_ASSERT(0 && "CRITICAL ERROR: Trying to use linear allocator as ring buffer while it was already used as double stack.");
- break;
- default:
- VMA_ASSERT(0);
+ request.offset + allocSize <= suballocations1st[m_1stNullItemsBeginCount].offset);
+ SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
+
+ switch(m_2ndVectorMode)
+ {
+ case SECOND_VECTOR_EMPTY:
+ // First allocation from second part ring buffer.
+ VMA_ASSERT(suballocations2nd.empty());
+ m_2ndVectorMode = SECOND_VECTOR_RING_BUFFER;
+ break;
+ case SECOND_VECTOR_RING_BUFFER:
+ // 2-part ring buffer is already started.
+ VMA_ASSERT(!suballocations2nd.empty());
+ break;
+ case SECOND_VECTOR_DOUBLE_STACK:
+ VMA_ASSERT(0 && "CRITICAL ERROR: Trying to use linear allocator as ring buffer while it was already used as double stack.");
+ break;
+ default:
+ VMA_ASSERT(0);
}
suballocations2nd.push_back(newSuballoc);
- } break;
- default:
- VMA_ASSERT(0 && "CRITICAL INTERNAL ERROR.");
+ }
+ break;
+ default:
+ VMA_ASSERT(0 && "CRITICAL INTERNAL ERROR.");
}
m_SumFreeSize -= newSuballoc.size;
}
-void VmaBlockMetadata_Linear::Free(const VmaAllocation allocation) {
+void VmaBlockMetadata_Linear::Free(const VmaAllocation allocation)
+{
FreeAtOffset(allocation->GetOffset());
}
-void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset) {
- SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset)
+{
+ SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
- if (!suballocations1st.empty()) {
+ if(!suballocations1st.empty())
+ {
// First allocation: Mark it as next empty at the beginning.
- VmaSuballocation &firstSuballoc = suballocations1st[m_1stNullItemsBeginCount];
- if (firstSuballoc.offset == offset) {
+ VmaSuballocation& firstSuballoc = suballocations1st[m_1stNullItemsBeginCount];
+ if(firstSuballoc.offset == offset)
+ {
firstSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
firstSuballoc.hAllocation = VK_NULL_HANDLE;
m_SumFreeSize += firstSuballoc.size;
@@ -9623,10 +10871,12 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset) {
}
// Last allocation in 2-part ring buffer or top of upper stack (same logic).
- if (m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER ||
- m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK) {
- VmaSuballocation &lastSuballoc = suballocations2nd.back();
- if (lastSuballoc.offset == offset) {
+ if(m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER ||
+ m_2ndVectorMode == SECOND_VECTOR_DOUBLE_STACK)
+ {
+ VmaSuballocation& lastSuballoc = suballocations2nd.back();
+ if(lastSuballoc.offset == offset)
+ {
m_SumFreeSize += lastSuballoc.size;
suballocations2nd.pop_back();
CleanupAfterFree();
@@ -9634,9 +10884,11 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset) {
}
}
// Last allocation in 1st vector.
- else if (m_2ndVectorMode == SECOND_VECTOR_EMPTY) {
- VmaSuballocation &lastSuballoc = suballocations1st.back();
- if (lastSuballoc.offset == offset) {
+ else if(m_2ndVectorMode == SECOND_VECTOR_EMPTY)
+ {
+ VmaSuballocation& lastSuballoc = suballocations1st.back();
+ if(lastSuballoc.offset == offset)
+ {
m_SumFreeSize += lastSuballoc.size;
suballocations1st.pop_back();
CleanupAfterFree();
@@ -9649,11 +10901,13 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset) {
VmaSuballocation refSuballoc;
refSuballoc.offset = offset;
// Rest of members stays uninitialized intentionally for better performance.
- SuballocationVectorType::iterator it = VmaVectorFindSorted<VmaSuballocationOffsetLess>(
- suballocations1st.begin() + m_1stNullItemsBeginCount,
- suballocations1st.end(),
- refSuballoc);
- if (it != suballocations1st.end()) {
+ SuballocationVectorType::iterator it = VmaBinaryFindSorted(
+ suballocations1st.begin() + m_1stNullItemsBeginCount,
+ suballocations1st.end(),
+ refSuballoc,
+ VmaSuballocationOffsetLess());
+ if(it != suballocations1st.end())
+ {
it->type = VMA_SUBALLOCATION_TYPE_FREE;
it->hAllocation = VK_NULL_HANDLE;
++m_1stNullItemsMiddleCount;
@@ -9663,15 +10917,17 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset) {
}
}
- if (m_2ndVectorMode != SECOND_VECTOR_EMPTY) {
+ if(m_2ndVectorMode != SECOND_VECTOR_EMPTY)
+ {
// Item from the middle of 2nd vector.
VmaSuballocation refSuballoc;
refSuballoc.offset = offset;
// Rest of members stays uninitialized intentionally for better performance.
SuballocationVectorType::iterator it = m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER ?
- VmaVectorFindSorted<VmaSuballocationOffsetLess>(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc) :
- VmaVectorFindSorted<VmaSuballocationOffsetGreater>(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc);
- if (it != suballocations2nd.end()) {
+ VmaBinaryFindSorted(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc, VmaSuballocationOffsetLess()) :
+ VmaBinaryFindSorted(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc, VmaSuballocationOffsetGreater());
+ if(it != suballocations2nd.end())
+ {
it->type = VMA_SUBALLOCATION_TYPE_FREE;
it->hAllocation = VK_NULL_HANDLE;
++m_2ndNullItemsCount;
@@ -9684,64 +10940,77 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset) {
VMA_ASSERT(0 && "Allocation to free not found in linear allocator!");
}
-bool VmaBlockMetadata_Linear::ShouldCompact1st() const {
+bool VmaBlockMetadata_Linear::ShouldCompact1st() const
+{
const size_t nullItemCount = m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount;
const size_t suballocCount = AccessSuballocations1st().size();
return suballocCount > 32 && nullItemCount * 2 >= (suballocCount - nullItemCount) * 3;
}
-void VmaBlockMetadata_Linear::CleanupAfterFree() {
- SuballocationVectorType &suballocations1st = AccessSuballocations1st();
- SuballocationVectorType &suballocations2nd = AccessSuballocations2nd();
+void VmaBlockMetadata_Linear::CleanupAfterFree()
+{
+ SuballocationVectorType& suballocations1st = AccessSuballocations1st();
+ SuballocationVectorType& suballocations2nd = AccessSuballocations2nd();
- if (IsEmpty()) {
+ if(IsEmpty())
+ {
suballocations1st.clear();
suballocations2nd.clear();
m_1stNullItemsBeginCount = 0;
m_1stNullItemsMiddleCount = 0;
m_2ndNullItemsCount = 0;
m_2ndVectorMode = SECOND_VECTOR_EMPTY;
- } else {
+ }
+ else
+ {
const size_t suballoc1stCount = suballocations1st.size();
const size_t nullItem1stCount = m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount;
VMA_ASSERT(nullItem1stCount <= suballoc1stCount);
// Find more null items at the beginning of 1st vector.
- while (m_1stNullItemsBeginCount < suballoc1stCount &&
- suballocations1st[m_1stNullItemsBeginCount].hAllocation == VK_NULL_HANDLE) {
+ while(m_1stNullItemsBeginCount < suballoc1stCount &&
+ suballocations1st[m_1stNullItemsBeginCount].hAllocation == VK_NULL_HANDLE)
+ {
++m_1stNullItemsBeginCount;
--m_1stNullItemsMiddleCount;
}
// Find more null items at the end of 1st vector.
- while (m_1stNullItemsMiddleCount > 0 &&
- suballocations1st.back().hAllocation == VK_NULL_HANDLE) {
+ while(m_1stNullItemsMiddleCount > 0 &&
+ suballocations1st.back().hAllocation == VK_NULL_HANDLE)
+ {
--m_1stNullItemsMiddleCount;
suballocations1st.pop_back();
}
// Find more null items at the end of 2nd vector.
- while (m_2ndNullItemsCount > 0 &&
- suballocations2nd.back().hAllocation == VK_NULL_HANDLE) {
+ while(m_2ndNullItemsCount > 0 &&
+ suballocations2nd.back().hAllocation == VK_NULL_HANDLE)
+ {
--m_2ndNullItemsCount;
suballocations2nd.pop_back();
}
// Find more null items at the beginning of 2nd vector.
- while (m_2ndNullItemsCount > 0 &&
- suballocations2nd[0].hAllocation == VK_NULL_HANDLE) {
+ while(m_2ndNullItemsCount > 0 &&
+ suballocations2nd[0].hAllocation == VK_NULL_HANDLE)
+ {
--m_2ndNullItemsCount;
VmaVectorRemove(suballocations2nd, 0);
}
- if (ShouldCompact1st()) {
+ if(ShouldCompact1st())
+ {
const size_t nonNullItemCount = suballoc1stCount - nullItem1stCount;
size_t srcIndex = m_1stNullItemsBeginCount;
- for (size_t dstIndex = 0; dstIndex < nonNullItemCount; ++dstIndex) {
- while (suballocations1st[srcIndex].hAllocation == VK_NULL_HANDLE) {
+ for(size_t dstIndex = 0; dstIndex < nonNullItemCount; ++dstIndex)
+ {
+ while(suballocations1st[srcIndex].hAllocation == VK_NULL_HANDLE)
+ {
++srcIndex;
}
- if (dstIndex != srcIndex) {
+ if(dstIndex != srcIndex)
+ {
suballocations1st[dstIndex] = suballocations1st[srcIndex];
}
++srcIndex;
@@ -9752,21 +11021,25 @@ void VmaBlockMetadata_Linear::CleanupAfterFree() {
}
// 2nd vector became empty.
- if (suballocations2nd.empty()) {
+ if(suballocations2nd.empty())
+ {
m_2ndVectorMode = SECOND_VECTOR_EMPTY;
}
// 1st vector became empty.
- if (suballocations1st.size() - m_1stNullItemsBeginCount == 0) {
+ if(suballocations1st.size() - m_1stNullItemsBeginCount == 0)
+ {
suballocations1st.clear();
m_1stNullItemsBeginCount = 0;
- if (!suballocations2nd.empty() && m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER) {
+ if(!suballocations2nd.empty() && m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER)
+ {
// Swap 1st with 2nd. Now 2nd is empty.
m_2ndVectorMode = SECOND_VECTOR_EMPTY;
m_1stNullItemsMiddleCount = m_2ndNullItemsCount;
- while (m_1stNullItemsBeginCount < suballocations2nd.size() &&
- suballocations2nd[m_1stNullItemsBeginCount].hAllocation == VK_NULL_HANDLE) {
+ while(m_1stNullItemsBeginCount < suballocations2nd.size() &&
+ suballocations2nd[m_1stNullItemsBeginCount].hAllocation == VK_NULL_HANDLE)
+ {
++m_1stNullItemsBeginCount;
--m_1stNullItemsMiddleCount;
}
@@ -9779,23 +11052,27 @@ void VmaBlockMetadata_Linear::CleanupAfterFree() {
VMA_HEAVY_ASSERT(Validate());
}
+
////////////////////////////////////////////////////////////////////////////////
// class VmaBlockMetadata_Buddy
VmaBlockMetadata_Buddy::VmaBlockMetadata_Buddy(VmaAllocator hAllocator) :
- VmaBlockMetadata(hAllocator),
- m_Root(VMA_NULL),
- m_AllocationCount(0),
- m_FreeCount(1),
- m_SumFreeSize(0) {
+ VmaBlockMetadata(hAllocator),
+ m_Root(VMA_NULL),
+ m_AllocationCount(0),
+ m_FreeCount(1),
+ m_SumFreeSize(0)
+{
memset(m_FreeList, 0, sizeof(m_FreeList));
}
-VmaBlockMetadata_Buddy::~VmaBlockMetadata_Buddy() {
+VmaBlockMetadata_Buddy::~VmaBlockMetadata_Buddy()
+{
DeleteNode(m_Root);
}
-void VmaBlockMetadata_Buddy::Init(VkDeviceSize size) {
+void VmaBlockMetadata_Buddy::Init(VkDeviceSize size)
+{
VmaBlockMetadata::Init(size);
m_UsableSize = VmaPrevPow2(size);
@@ -9803,12 +11080,13 @@ void VmaBlockMetadata_Buddy::Init(VkDeviceSize size) {
// Calculate m_LevelCount.
m_LevelCount = 1;
- while (m_LevelCount < MAX_LEVELS &&
- LevelToNodeSize(m_LevelCount) >= MIN_NODE_SIZE) {
+ while(m_LevelCount < MAX_LEVELS &&
+ LevelToNodeSize(m_LevelCount) >= MIN_NODE_SIZE)
+ {
++m_LevelCount;
}
- Node *rootNode = vma_new(GetAllocationCallbacks(), Node)();
+ Node* rootNode = vma_new(GetAllocationCallbacks(), Node)();
rootNode->offset = 0;
rootNode->type = Node::TYPE_FREE;
rootNode->parent = VMA_NULL;
@@ -9818,51 +11096,63 @@ void VmaBlockMetadata_Buddy::Init(VkDeviceSize size) {
AddToFreeListFront(0, rootNode);
}
-bool VmaBlockMetadata_Buddy::Validate() const {
+bool VmaBlockMetadata_Buddy::Validate() const
+{
// Validate tree.
ValidationContext ctx;
- if (!ValidateNode(ctx, VMA_NULL, m_Root, 0, LevelToNodeSize(0))) {
+ if(!ValidateNode(ctx, VMA_NULL, m_Root, 0, LevelToNodeSize(0)))
+ {
VMA_VALIDATE(false && "ValidateNode failed.");
}
VMA_VALIDATE(m_AllocationCount == ctx.calculatedAllocationCount);
VMA_VALIDATE(m_SumFreeSize == ctx.calculatedSumFreeSize);
// Validate free node lists.
- for (uint32_t level = 0; level < m_LevelCount; ++level) {
+ for(uint32_t level = 0; level < m_LevelCount; ++level)
+ {
VMA_VALIDATE(m_FreeList[level].front == VMA_NULL ||
- m_FreeList[level].front->free.prev == VMA_NULL);
+ m_FreeList[level].front->free.prev == VMA_NULL);
- for (Node *node = m_FreeList[level].front;
- node != VMA_NULL;
- node = node->free.next) {
+ for(Node* node = m_FreeList[level].front;
+ node != VMA_NULL;
+ node = node->free.next)
+ {
VMA_VALIDATE(node->type == Node::TYPE_FREE);
-
- if (node->free.next == VMA_NULL) {
+
+ if(node->free.next == VMA_NULL)
+ {
VMA_VALIDATE(m_FreeList[level].back == node);
- } else {
+ }
+ else
+ {
VMA_VALIDATE(node->free.next->free.prev == node);
}
}
}
// Validate that free lists ar higher levels are empty.
- for (uint32_t level = m_LevelCount; level < MAX_LEVELS; ++level) {
+ for(uint32_t level = m_LevelCount; level < MAX_LEVELS; ++level)
+ {
VMA_VALIDATE(m_FreeList[level].front == VMA_NULL && m_FreeList[level].back == VMA_NULL);
}
return true;
}
-VkDeviceSize VmaBlockMetadata_Buddy::GetUnusedRangeSizeMax() const {
- for (uint32_t level = 0; level < m_LevelCount; ++level) {
- if (m_FreeList[level].front != VMA_NULL) {
+VkDeviceSize VmaBlockMetadata_Buddy::GetUnusedRangeSizeMax() const
+{
+ for(uint32_t level = 0; level < m_LevelCount; ++level)
+ {
+ if(m_FreeList[level].front != VMA_NULL)
+ {
return LevelToNodeSize(level);
}
}
return 0;
}
-void VmaBlockMetadata_Buddy::CalcAllocationStatInfo(VmaStatInfo &outInfo) const {
+void VmaBlockMetadata_Buddy::CalcAllocationStatInfo(VmaStatInfo& outInfo) const
+{
const VkDeviceSize unusableSize = GetUnusableSize();
outInfo.blockCount = 1;
@@ -9876,7 +11166,8 @@ void VmaBlockMetadata_Buddy::CalcAllocationStatInfo(VmaStatInfo &outInfo) const
CalcAllocationStatInfoNode(outInfo, m_Root, LevelToNodeSize(0));
- if (unusableSize > 0) {
+ if(unusableSize > 0)
+ {
++outInfo.unusedRangeCount;
outInfo.unusedBytes += unusableSize;
outInfo.unusedRangeSizeMax = VMA_MAX(outInfo.unusedRangeSizeMax, unusableSize);
@@ -9884,7 +11175,8 @@ void VmaBlockMetadata_Buddy::CalcAllocationStatInfo(VmaStatInfo &outInfo) const
}
}
-void VmaBlockMetadata_Buddy::AddPoolStats(VmaPoolStats &inoutStats) const {
+void VmaBlockMetadata_Buddy::AddPoolStats(VmaPoolStats& inoutStats) const
+{
const VkDeviceSize unusableSize = GetUnusableSize();
inoutStats.size += GetSize();
@@ -9893,7 +11185,8 @@ void VmaBlockMetadata_Buddy::AddPoolStats(VmaPoolStats &inoutStats) const {
inoutStats.unusedRangeCount += m_FreeCount;
inoutStats.unusedRangeSizeMax = VMA_MAX(inoutStats.unusedRangeSizeMax, GetUnusedRangeSizeMax());
- if (unusableSize > 0) {
+ if(unusableSize > 0)
+ {
++inoutStats.unusedRangeCount;
// Not updating inoutStats.unusedRangeSizeMax with unusableSize because this space is not available for allocations.
}
@@ -9901,24 +11194,26 @@ void VmaBlockMetadata_Buddy::AddPoolStats(VmaPoolStats &inoutStats) const {
#if VMA_STATS_STRING_ENABLED
-void VmaBlockMetadata_Buddy::PrintDetailedMap(class VmaJsonWriter &json) const {
+void VmaBlockMetadata_Buddy::PrintDetailedMap(class VmaJsonWriter& json) const
+{
// TODO optimize
VmaStatInfo stat;
CalcAllocationStatInfo(stat);
PrintDetailedMap_Begin(
- json,
- stat.unusedBytes,
- stat.allocationCount,
- stat.unusedRangeCount);
+ json,
+ stat.unusedBytes,
+ stat.allocationCount,
+ stat.unusedRangeCount);
PrintDetailedMapNode(json, m_Root, LevelToNodeSize(0));
const VkDeviceSize unusableSize = GetUnusableSize();
- if (unusableSize > 0) {
+ if(unusableSize > 0)
+ {
PrintDetailedMap_UnusedRange(json,
- m_UsableSize, // offset
- unusableSize); // size
+ m_UsableSize, // offset
+ unusableSize); // size
}
PrintDetailedMap_End(json);
@@ -9927,43 +11222,49 @@ void VmaBlockMetadata_Buddy::PrintDetailedMap(class VmaJsonWriter &json) const {
#endif // #if VMA_STATS_STRING_ENABLED
bool VmaBlockMetadata_Buddy::CreateAllocationRequest(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VkDeviceSize bufferImageGranularity,
- VkDeviceSize allocSize,
- VkDeviceSize allocAlignment,
- bool upperAddress,
- VmaSuballocationType allocType,
- bool canMakeOtherLost,
- uint32_t strategy,
- VmaAllocationRequest *pAllocationRequest) {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VkDeviceSize bufferImageGranularity,
+ VkDeviceSize allocSize,
+ VkDeviceSize allocAlignment,
+ bool upperAddress,
+ VmaSuballocationType allocType,
+ bool canMakeOtherLost,
+ uint32_t strategy,
+ VmaAllocationRequest* pAllocationRequest)
+{
VMA_ASSERT(!upperAddress && "VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT can be used only with linear algorithm.");
// Simple way to respect bufferImageGranularity. May be optimized some day.
// Whenever it might be an OPTIMAL image...
- if (allocType == VMA_SUBALLOCATION_TYPE_UNKNOWN ||
- allocType == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN ||
- allocType == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL) {
+ if(allocType == VMA_SUBALLOCATION_TYPE_UNKNOWN ||
+ allocType == VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN ||
+ allocType == VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL)
+ {
allocAlignment = VMA_MAX(allocAlignment, bufferImageGranularity);
allocSize = VMA_MAX(allocSize, bufferImageGranularity);
}
- if (allocSize > m_UsableSize) {
+ if(allocSize > m_UsableSize)
+ {
return false;
}
const uint32_t targetLevel = AllocSizeToLevel(allocSize);
- for (uint32_t level = targetLevel + 1; level--;) {
- for (Node *freeNode = m_FreeList[level].front;
- freeNode != VMA_NULL;
- freeNode = freeNode->free.next) {
- if (freeNode->offset % allocAlignment == 0) {
+ for(uint32_t level = targetLevel + 1; level--; )
+ {
+ for(Node* freeNode = m_FreeList[level].front;
+ freeNode != VMA_NULL;
+ freeNode = freeNode->free.next)
+ {
+ if(freeNode->offset % allocAlignment == 0)
+ {
pAllocationRequest->type = VmaAllocationRequestType::Normal;
pAllocationRequest->offset = freeNode->offset;
pAllocationRequest->sumFreeSize = LevelToNodeSize(level);
pAllocationRequest->sumItemSize = 0;
pAllocationRequest->itemsToMakeLostCount = 0;
- pAllocationRequest->customData = (void *)(uintptr_t)level;
+ pAllocationRequest->customData = (void*)(uintptr_t)level;
return true;
}
}
@@ -9973,52 +11274,57 @@ bool VmaBlockMetadata_Buddy::CreateAllocationRequest(
}
bool VmaBlockMetadata_Buddy::MakeRequestedAllocationsLost(
- uint32_t currentFrameIndex,
- uint32_t frameInUseCount,
- VmaAllocationRequest *pAllocationRequest) {
+ uint32_t currentFrameIndex,
+ uint32_t frameInUseCount,
+ VmaAllocationRequest* pAllocationRequest)
+{
/*
- Lost allocations are not supported in buddy allocator at the moment.
- Support might be added in the future.
- */
+ Lost allocations are not supported in buddy allocator at the moment.
+ Support might be added in the future.
+ */
return pAllocationRequest->itemsToMakeLostCount == 0;
}
-uint32_t VmaBlockMetadata_Buddy::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount) {
+uint32_t VmaBlockMetadata_Buddy::MakeAllocationsLost(uint32_t currentFrameIndex, uint32_t frameInUseCount)
+{
/*
- Lost allocations are not supported in buddy allocator at the moment.
- Support might be added in the future.
- */
+ Lost allocations are not supported in buddy allocator at the moment.
+ Support might be added in the future.
+ */
return 0;
}
void VmaBlockMetadata_Buddy::Alloc(
- const VmaAllocationRequest &request,
- VmaSuballocationType type,
- VkDeviceSize allocSize,
- VmaAllocation hAllocation) {
+ const VmaAllocationRequest& request,
+ VmaSuballocationType type,
+ VkDeviceSize allocSize,
+ VmaAllocation hAllocation)
+{
VMA_ASSERT(request.type == VmaAllocationRequestType::Normal);
const uint32_t targetLevel = AllocSizeToLevel(allocSize);
uint32_t currLevel = (uint32_t)(uintptr_t)request.customData;
-
- Node *currNode = m_FreeList[currLevel].front;
+
+ Node* currNode = m_FreeList[currLevel].front;
VMA_ASSERT(currNode != VMA_NULL && currNode->type == Node::TYPE_FREE);
- while (currNode->offset != request.offset) {
+ while(currNode->offset != request.offset)
+ {
currNode = currNode->free.next;
VMA_ASSERT(currNode != VMA_NULL && currNode->type == Node::TYPE_FREE);
}
-
+
// Go down, splitting free nodes.
- while (currLevel < targetLevel) {
+ while(currLevel < targetLevel)
+ {
// currNode is already first free node at currLevel.
// Remove it from list of free nodes at this currLevel.
RemoveFromFreeList(currLevel, currNode);
-
+
const uint32_t childrenLevel = currLevel + 1;
// Create two free sub-nodes.
- Node *leftChild = vma_new(GetAllocationCallbacks(), Node)();
- Node *rightChild = vma_new(GetAllocationCallbacks(), Node)();
+ Node* leftChild = vma_new(GetAllocationCallbacks(), Node)();
+ Node* rightChild = vma_new(GetAllocationCallbacks(), Node)();
leftChild->offset = currNode->offset;
leftChild->type = Node::TYPE_FREE;
@@ -10044,15 +11350,15 @@ void VmaBlockMetadata_Buddy::Alloc(
currNode = m_FreeList[currLevel].front;
/*
- We can be sure that currNode, as left child of node previously split,
- also fullfills the alignment requirement.
- */
+ We can be sure that currNode, as left child of node previously split,
+ also fullfills the alignment requirement.
+ */
}
// Remove from free list.
VMA_ASSERT(currLevel == targetLevel &&
- currNode != VMA_NULL &&
- currNode->type == Node::TYPE_FREE);
+ currNode != VMA_NULL &&
+ currNode->type == Node::TYPE_FREE);
RemoveFromFreeList(currLevel, currNode);
// Convert to allocation node.
@@ -10064,8 +11370,10 @@ void VmaBlockMetadata_Buddy::Alloc(
m_SumFreeSize -= allocSize;
}
-void VmaBlockMetadata_Buddy::DeleteNode(Node *node) {
- if (node->type == Node::TYPE_SPLIT) {
+void VmaBlockMetadata_Buddy::DeleteNode(Node* node)
+{
+ if(node->type == Node::TYPE_SPLIT)
+ {
DeleteNode(node->split.leftChild->buddy);
DeleteNode(node->split.leftChild);
}
@@ -10073,50 +11381,58 @@ void VmaBlockMetadata_Buddy::DeleteNode(Node *node) {
vma_delete(GetAllocationCallbacks(), node);
}
-bool VmaBlockMetadata_Buddy::ValidateNode(ValidationContext &ctx, const Node *parent, const Node *curr, uint32_t level, VkDeviceSize levelNodeSize) const {
+bool VmaBlockMetadata_Buddy::ValidateNode(ValidationContext& ctx, const Node* parent, const Node* curr, uint32_t level, VkDeviceSize levelNodeSize) const
+{
VMA_VALIDATE(level < m_LevelCount);
VMA_VALIDATE(curr->parent == parent);
VMA_VALIDATE((curr->buddy == VMA_NULL) == (parent == VMA_NULL));
VMA_VALIDATE(curr->buddy == VMA_NULL || curr->buddy->buddy == curr);
- switch (curr->type) {
- case Node::TYPE_FREE:
- // curr->free.prev, next are validated separately.
- ctx.calculatedSumFreeSize += levelNodeSize;
- ++ctx.calculatedFreeCount;
- break;
- case Node::TYPE_ALLOCATION:
- ++ctx.calculatedAllocationCount;
- ctx.calculatedSumFreeSize += levelNodeSize - curr->allocation.alloc->GetSize();
- VMA_VALIDATE(curr->allocation.alloc != VK_NULL_HANDLE);
- break;
- case Node::TYPE_SPLIT: {
+ switch(curr->type)
+ {
+ case Node::TYPE_FREE:
+ // curr->free.prev, next are validated separately.
+ ctx.calculatedSumFreeSize += levelNodeSize;
+ ++ctx.calculatedFreeCount;
+ break;
+ case Node::TYPE_ALLOCATION:
+ ++ctx.calculatedAllocationCount;
+ ctx.calculatedSumFreeSize += levelNodeSize - curr->allocation.alloc->GetSize();
+ VMA_VALIDATE(curr->allocation.alloc != VK_NULL_HANDLE);
+ break;
+ case Node::TYPE_SPLIT:
+ {
const uint32_t childrenLevel = level + 1;
const VkDeviceSize childrenLevelNodeSize = levelNodeSize / 2;
- const Node *const leftChild = curr->split.leftChild;
+ const Node* const leftChild = curr->split.leftChild;
VMA_VALIDATE(leftChild != VMA_NULL);
VMA_VALIDATE(leftChild->offset == curr->offset);
- if (!ValidateNode(ctx, curr, leftChild, childrenLevel, childrenLevelNodeSize)) {
+ if(!ValidateNode(ctx, curr, leftChild, childrenLevel, childrenLevelNodeSize))
+ {
VMA_VALIDATE(false && "ValidateNode for left child failed.");
}
- const Node *const rightChild = leftChild->buddy;
+ const Node* const rightChild = leftChild->buddy;
VMA_VALIDATE(rightChild->offset == curr->offset + childrenLevelNodeSize);
- if (!ValidateNode(ctx, curr, rightChild, childrenLevel, childrenLevelNodeSize)) {
+ if(!ValidateNode(ctx, curr, rightChild, childrenLevel, childrenLevelNodeSize))
+ {
VMA_VALIDATE(false && "ValidateNode for right child failed.");
}
- } break;
- default:
- return false;
+ }
+ break;
+ default:
+ return false;
}
return true;
}
-uint32_t VmaBlockMetadata_Buddy::AllocSizeToLevel(VkDeviceSize allocSize) const {
+uint32_t VmaBlockMetadata_Buddy::AllocSizeToLevel(VkDeviceSize allocSize) const
+{
// I know this could be optimized somehow e.g. by using std::log2p1 from C++20.
uint32_t level = 0;
VkDeviceSize currLevelNodeSize = m_UsableSize;
VkDeviceSize nextLevelNodeSize = currLevelNodeSize >> 1;
- while (allocSize <= nextLevelNodeSize && level + 1 < m_LevelCount) {
+ while(allocSize <= nextLevelNodeSize && level + 1 < m_LevelCount)
+ {
++level;
currLevelNodeSize = nextLevelNodeSize;
nextLevelNodeSize = currLevelNodeSize >> 1;
@@ -10124,17 +11440,22 @@ uint32_t VmaBlockMetadata_Buddy::AllocSizeToLevel(VkDeviceSize allocSize) const
return level;
}
-void VmaBlockMetadata_Buddy::FreeAtOffset(VmaAllocation alloc, VkDeviceSize offset) {
+void VmaBlockMetadata_Buddy::FreeAtOffset(VmaAllocation alloc, VkDeviceSize offset)
+{
// Find node and level.
- Node *node = m_Root;
+ Node* node = m_Root;
VkDeviceSize nodeOffset = 0;
uint32_t level = 0;
VkDeviceSize levelNodeSize = LevelToNodeSize(0);
- while (node->type == Node::TYPE_SPLIT) {
+ while(node->type == Node::TYPE_SPLIT)
+ {
const VkDeviceSize nextLevelSize = levelNodeSize >> 1;
- if (offset < nodeOffset + nextLevelSize) {
+ if(offset < nodeOffset + nextLevelSize)
+ {
node = node->split.leftChild;
- } else {
+ }
+ else
+ {
node = node->split.leftChild->buddy;
nodeOffset += nextLevelSize;
}
@@ -10152,14 +11473,15 @@ void VmaBlockMetadata_Buddy::FreeAtOffset(VmaAllocation alloc, VkDeviceSize offs
node->type = Node::TYPE_FREE;
// Join free nodes if possible.
- while (level > 0 && node->buddy->type == Node::TYPE_FREE) {
+ while(level > 0 && node->buddy->type == Node::TYPE_FREE)
+ {
RemoveFromFreeList(level, node->buddy);
- Node *const parent = node->parent;
+ Node* const parent = node->parent;
vma_delete(GetAllocationCallbacks(), node->buddy);
vma_delete(GetAllocationCallbacks(), node);
parent->type = Node::TYPE_FREE;
-
+
node = parent;
--level;
//m_SumFreeSize += LevelToNodeSize(level) % 2; // Useful only when level node sizes can be non power of 2.
@@ -10169,15 +11491,18 @@ void VmaBlockMetadata_Buddy::FreeAtOffset(VmaAllocation alloc, VkDeviceSize offs
AddToFreeListFront(level, node);
}
-void VmaBlockMetadata_Buddy::CalcAllocationStatInfoNode(VmaStatInfo &outInfo, const Node *node, VkDeviceSize levelNodeSize) const {
- switch (node->type) {
- case Node::TYPE_FREE:
- ++outInfo.unusedRangeCount;
- outInfo.unusedBytes += levelNodeSize;
- outInfo.unusedRangeSizeMax = VMA_MAX(outInfo.unusedRangeSizeMax, levelNodeSize);
- outInfo.unusedRangeSizeMin = VMA_MAX(outInfo.unusedRangeSizeMin, levelNodeSize);
- break;
- case Node::TYPE_ALLOCATION: {
+void VmaBlockMetadata_Buddy::CalcAllocationStatInfoNode(VmaStatInfo& outInfo, const Node* node, VkDeviceSize levelNodeSize) const
+{
+ switch(node->type)
+ {
+ case Node::TYPE_FREE:
+ ++outInfo.unusedRangeCount;
+ outInfo.unusedBytes += levelNodeSize;
+ outInfo.unusedRangeSizeMax = VMA_MAX(outInfo.unusedRangeSizeMax, levelNodeSize);
+ outInfo.unusedRangeSizeMin = VMA_MAX(outInfo.unusedRangeSizeMin, levelNodeSize);
+ break;
+ case Node::TYPE_ALLOCATION:
+ {
const VkDeviceSize allocSize = node->allocation.alloc->GetSize();
++outInfo.allocationCount;
outInfo.usedBytes += allocSize;
@@ -10185,35 +11510,43 @@ void VmaBlockMetadata_Buddy::CalcAllocationStatInfoNode(VmaStatInfo &outInfo, co
outInfo.allocationSizeMin = VMA_MAX(outInfo.allocationSizeMin, allocSize);
const VkDeviceSize unusedRangeSize = levelNodeSize - allocSize;
- if (unusedRangeSize > 0) {
+ if(unusedRangeSize > 0)
+ {
++outInfo.unusedRangeCount;
outInfo.unusedBytes += unusedRangeSize;
outInfo.unusedRangeSizeMax = VMA_MAX(outInfo.unusedRangeSizeMax, unusedRangeSize);
outInfo.unusedRangeSizeMin = VMA_MAX(outInfo.unusedRangeSizeMin, unusedRangeSize);
}
- } break;
- case Node::TYPE_SPLIT: {
+ }
+ break;
+ case Node::TYPE_SPLIT:
+ {
const VkDeviceSize childrenNodeSize = levelNodeSize / 2;
- const Node *const leftChild = node->split.leftChild;
+ const Node* const leftChild = node->split.leftChild;
CalcAllocationStatInfoNode(outInfo, leftChild, childrenNodeSize);
- const Node *const rightChild = leftChild->buddy;
+ const Node* const rightChild = leftChild->buddy;
CalcAllocationStatInfoNode(outInfo, rightChild, childrenNodeSize);
- } break;
- default:
- VMA_ASSERT(0);
+ }
+ break;
+ default:
+ VMA_ASSERT(0);
}
}
-void VmaBlockMetadata_Buddy::AddToFreeListFront(uint32_t level, Node *node) {
+void VmaBlockMetadata_Buddy::AddToFreeListFront(uint32_t level, Node* node)
+{
VMA_ASSERT(node->type == Node::TYPE_FREE);
// List is empty.
- Node *const frontNode = m_FreeList[level].front;
- if (frontNode == VMA_NULL) {
+ Node* const frontNode = m_FreeList[level].front;
+ if(frontNode == VMA_NULL)
+ {
VMA_ASSERT(m_FreeList[level].back == VMA_NULL);
node->free.prev = node->free.next = VMA_NULL;
m_FreeList[level].front = m_FreeList[level].back = node;
- } else {
+ }
+ else
+ {
VMA_ASSERT(frontNode->free.prev == VMA_NULL);
node->free.prev = VMA_NULL;
node->free.next = frontNode;
@@ -10222,76 +11555,93 @@ void VmaBlockMetadata_Buddy::AddToFreeListFront(uint32_t level, Node *node) {
}
}
-void VmaBlockMetadata_Buddy::RemoveFromFreeList(uint32_t level, Node *node) {
+void VmaBlockMetadata_Buddy::RemoveFromFreeList(uint32_t level, Node* node)
+{
VMA_ASSERT(m_FreeList[level].front != VMA_NULL);
// It is at the front.
- if (node->free.prev == VMA_NULL) {
+ if(node->free.prev == VMA_NULL)
+ {
VMA_ASSERT(m_FreeList[level].front == node);
m_FreeList[level].front = node->free.next;
- } else {
- Node *const prevFreeNode = node->free.prev;
+ }
+ else
+ {
+ Node* const prevFreeNode = node->free.prev;
VMA_ASSERT(prevFreeNode->free.next == node);
prevFreeNode->free.next = node->free.next;
}
// It is at the back.
- if (node->free.next == VMA_NULL) {
+ if(node->free.next == VMA_NULL)
+ {
VMA_ASSERT(m_FreeList[level].back == node);
m_FreeList[level].back = node->free.prev;
- } else {
- Node *const nextFreeNode = node->free.next;
+ }
+ else
+ {
+ Node* const nextFreeNode = node->free.next;
VMA_ASSERT(nextFreeNode->free.prev == node);
nextFreeNode->free.prev = node->free.prev;
}
}
#if VMA_STATS_STRING_ENABLED
-void VmaBlockMetadata_Buddy::PrintDetailedMapNode(class VmaJsonWriter &json, const Node *node, VkDeviceSize levelNodeSize) const {
- switch (node->type) {
- case Node::TYPE_FREE:
- PrintDetailedMap_UnusedRange(json, node->offset, levelNodeSize);
- break;
- case Node::TYPE_ALLOCATION: {
+void VmaBlockMetadata_Buddy::PrintDetailedMapNode(class VmaJsonWriter& json, const Node* node, VkDeviceSize levelNodeSize) const
+{
+ switch(node->type)
+ {
+ case Node::TYPE_FREE:
+ PrintDetailedMap_UnusedRange(json, node->offset, levelNodeSize);
+ break;
+ case Node::TYPE_ALLOCATION:
+ {
PrintDetailedMap_Allocation(json, node->offset, node->allocation.alloc);
const VkDeviceSize allocSize = node->allocation.alloc->GetSize();
- if (allocSize < levelNodeSize) {
+ if(allocSize < levelNodeSize)
+ {
PrintDetailedMap_UnusedRange(json, node->offset + allocSize, levelNodeSize - allocSize);
}
- } break;
- case Node::TYPE_SPLIT: {
+ }
+ break;
+ case Node::TYPE_SPLIT:
+ {
const VkDeviceSize childrenNodeSize = levelNodeSize / 2;
- const Node *const leftChild = node->split.leftChild;
+ const Node* const leftChild = node->split.leftChild;
PrintDetailedMapNode(json, leftChild, childrenNodeSize);
- const Node *const rightChild = leftChild->buddy;
+ const Node* const rightChild = leftChild->buddy;
PrintDetailedMapNode(json, rightChild, childrenNodeSize);
- } break;
- default:
- VMA_ASSERT(0);
+ }
+ break;
+ default:
+ VMA_ASSERT(0);
}
}
#endif // #if VMA_STATS_STRING_ENABLED
+
////////////////////////////////////////////////////////////////////////////////
// class VmaDeviceMemoryBlock
VmaDeviceMemoryBlock::VmaDeviceMemoryBlock(VmaAllocator hAllocator) :
- m_pMetadata(VMA_NULL),
- m_MemoryTypeIndex(UINT32_MAX),
- m_Id(0),
- m_hMemory(VK_NULL_HANDLE),
- m_MapCount(0),
- m_pMappedData(VMA_NULL) {
+ m_pMetadata(VMA_NULL),
+ m_MemoryTypeIndex(UINT32_MAX),
+ m_Id(0),
+ m_hMemory(VK_NULL_HANDLE),
+ m_MapCount(0),
+ m_pMappedData(VMA_NULL)
+{
}
void VmaDeviceMemoryBlock::Init(
- VmaAllocator hAllocator,
- VmaPool hParentPool,
- uint32_t newMemoryTypeIndex,
- VkDeviceMemory newMemory,
- VkDeviceSize newSize,
- uint32_t id,
- uint32_t algorithm) {
+ VmaAllocator hAllocator,
+ VmaPool hParentPool,
+ uint32_t newMemoryTypeIndex,
+ VkDeviceMemory newMemory,
+ VkDeviceSize newSize,
+ uint32_t id,
+ uint32_t algorithm)
+{
VMA_ASSERT(m_hMemory == VK_NULL_HANDLE);
m_hParentPool = hParentPool;
@@ -10299,23 +11649,25 @@ void VmaDeviceMemoryBlock::Init(
m_Id = id;
m_hMemory = newMemory;
- switch (algorithm) {
- case VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT:
- m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_Linear)(hAllocator);
- break;
- case VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT:
- m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_Buddy)(hAllocator);
- break;
- default:
- VMA_ASSERT(0);
- // Fall-through.
- case 0:
- m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_Generic)(hAllocator);
+ switch(algorithm)
+ {
+ case VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT:
+ m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_Linear)(hAllocator);
+ break;
+ case VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT:
+ m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_Buddy)(hAllocator);
+ break;
+ default:
+ VMA_ASSERT(0);
+ // Fall-through.
+ case 0:
+ m_pMetadata = vma_new(hAllocator, VmaBlockMetadata_Generic)(hAllocator);
}
m_pMetadata->Init(newSize);
}
-void VmaDeviceMemoryBlock::Destroy(VmaAllocator allocator) {
+void VmaDeviceMemoryBlock::Destroy(VmaAllocator allocator)
+{
// This is the most important assert in the entire library.
// Hitting it means you have some memory leak - unreleased VmaAllocation objects.
VMA_ASSERT(m_pMetadata->IsEmpty() && "Some allocations were not freed before destruction of this memory block!");
@@ -10328,17 +11680,20 @@ void VmaDeviceMemoryBlock::Destroy(VmaAllocator allocator) {
m_pMetadata = VMA_NULL;
}
-bool VmaDeviceMemoryBlock::Validate() const {
+bool VmaDeviceMemoryBlock::Validate() const
+{
VMA_VALIDATE((m_hMemory != VK_NULL_HANDLE) &&
- (m_pMetadata->GetSize() != 0));
-
+ (m_pMetadata->GetSize() != 0));
+
return m_pMetadata->Validate();
}
-VkResult VmaDeviceMemoryBlock::CheckCorruption(VmaAllocator hAllocator) {
- void *pData = nullptr;
+VkResult VmaDeviceMemoryBlock::CheckCorruption(VmaAllocator hAllocator)
+{
+ void* pData = nullptr;
VkResult res = Map(hAllocator, 1, &pData);
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
return res;
}
@@ -10349,29 +11704,37 @@ VkResult VmaDeviceMemoryBlock::CheckCorruption(VmaAllocator hAllocator) {
return res;
}
-VkResult VmaDeviceMemoryBlock::Map(VmaAllocator hAllocator, uint32_t count, void **ppData) {
- if (count == 0) {
+VkResult VmaDeviceMemoryBlock::Map(VmaAllocator hAllocator, uint32_t count, void** ppData)
+{
+ if(count == 0)
+ {
return VK_SUCCESS;
}
VmaMutexLock lock(m_Mutex, hAllocator->m_UseMutex);
- if (m_MapCount != 0) {
+ if(m_MapCount != 0)
+ {
m_MapCount += count;
VMA_ASSERT(m_pMappedData != VMA_NULL);
- if (ppData != VMA_NULL) {
+ if(ppData != VMA_NULL)
+ {
*ppData = m_pMappedData;
}
return VK_SUCCESS;
- } else {
+ }
+ else
+ {
VkResult result = (*hAllocator->GetVulkanFunctions().vkMapMemory)(
- hAllocator->m_hDevice,
- m_hMemory,
- 0, // offset
- VK_WHOLE_SIZE,
- 0, // flags
- &m_pMappedData);
- if (result == VK_SUCCESS) {
- if (ppData != VMA_NULL) {
+ hAllocator->m_hDevice,
+ m_hMemory,
+ 0, // offset
+ VK_WHOLE_SIZE,
+ 0, // flags
+ &m_pMappedData);
+ if(result == VK_SUCCESS)
+ {
+ if(ppData != VMA_NULL)
+ {
*ppData = m_pMappedData;
}
m_MapCount = count;
@@ -10380,30 +11743,38 @@ VkResult VmaDeviceMemoryBlock::Map(VmaAllocator hAllocator, uint32_t count, void
}
}
-void VmaDeviceMemoryBlock::Unmap(VmaAllocator hAllocator, uint32_t count) {
- if (count == 0) {
+void VmaDeviceMemoryBlock::Unmap(VmaAllocator hAllocator, uint32_t count)
+{
+ if(count == 0)
+ {
return;
}
VmaMutexLock lock(m_Mutex, hAllocator->m_UseMutex);
- if (m_MapCount >= count) {
+ if(m_MapCount >= count)
+ {
m_MapCount -= count;
- if (m_MapCount == 0) {
+ if(m_MapCount == 0)
+ {
m_pMappedData = VMA_NULL;
(*hAllocator->GetVulkanFunctions().vkUnmapMemory)(hAllocator->m_hDevice, m_hMemory);
}
- } else {
+ }
+ else
+ {
VMA_ASSERT(0 && "VkDeviceMemory block is being unmapped while it was not previously mapped.");
}
}
-VkResult VmaDeviceMemoryBlock::WriteMagicValueAroundAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize) {
+VkResult VmaDeviceMemoryBlock::WriteMagicValueAroundAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize)
+{
VMA_ASSERT(VMA_DEBUG_MARGIN > 0 && VMA_DEBUG_MARGIN % 4 == 0 && VMA_DEBUG_DETECT_CORRUPTION);
VMA_ASSERT(allocOffset >= VMA_DEBUG_MARGIN);
- void *pData;
+ void* pData;
VkResult res = Map(hAllocator, 1, &pData);
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
return res;
}
@@ -10415,19 +11786,24 @@ VkResult VmaDeviceMemoryBlock::WriteMagicValueAroundAllocation(VmaAllocator hAll
return VK_SUCCESS;
}
-VkResult VmaDeviceMemoryBlock::ValidateMagicValueAroundAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize) {
+VkResult VmaDeviceMemoryBlock::ValidateMagicValueAroundAllocation(VmaAllocator hAllocator, VkDeviceSize allocOffset, VkDeviceSize allocSize)
+{
VMA_ASSERT(VMA_DEBUG_MARGIN > 0 && VMA_DEBUG_MARGIN % 4 == 0 && VMA_DEBUG_DETECT_CORRUPTION);
VMA_ASSERT(allocOffset >= VMA_DEBUG_MARGIN);
- void *pData;
+ void* pData;
VkResult res = Map(hAllocator, 1, &pData);
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
return res;
}
- if (!VmaValidateMagicValue(pData, allocOffset - VMA_DEBUG_MARGIN)) {
+ if(!VmaValidateMagicValue(pData, allocOffset - VMA_DEBUG_MARGIN))
+ {
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED BEFORE FREED ALLOCATION!");
- } else if (!VmaValidateMagicValue(pData, allocOffset + allocSize)) {
+ }
+ else if(!VmaValidateMagicValue(pData, allocOffset + allocSize))
+ {
VMA_ASSERT(0 && "MEMORY CORRUPTION DETECTED AFTER FREED ALLOCATION!");
}
@@ -10437,43 +11813,49 @@ VkResult VmaDeviceMemoryBlock::ValidateMagicValueAroundAllocation(VmaAllocator h
}
VkResult VmaDeviceMemoryBlock::BindBufferMemory(
- const VmaAllocator hAllocator,
- const VmaAllocation hAllocation,
- VkBuffer hBuffer) {
+ const VmaAllocator hAllocator,
+ const VmaAllocation hAllocation,
+ VkDeviceSize allocationLocalOffset,
+ VkBuffer hBuffer,
+ const void* pNext)
+{
VMA_ASSERT(hAllocation->GetType() == VmaAllocation_T::ALLOCATION_TYPE_BLOCK &&
- hAllocation->GetBlock() == this);
+ hAllocation->GetBlock() == this);
+ VMA_ASSERT(allocationLocalOffset < hAllocation->GetSize() &&
+ "Invalid allocationLocalOffset. Did you forget that this offset is relative to the beginning of the allocation, not the whole memory block?");
+ const VkDeviceSize memoryOffset = hAllocation->GetOffset() + allocationLocalOffset;
// This lock is important so that we don't call vkBind... and/or vkMap... simultaneously on the same VkDeviceMemory from multiple threads.
VmaMutexLock lock(m_Mutex, hAllocator->m_UseMutex);
- return hAllocator->GetVulkanFunctions().vkBindBufferMemory(
- hAllocator->m_hDevice,
- hBuffer,
- m_hMemory,
- hAllocation->GetOffset());
+ return hAllocator->BindVulkanBuffer(m_hMemory, memoryOffset, hBuffer, pNext);
}
VkResult VmaDeviceMemoryBlock::BindImageMemory(
- const VmaAllocator hAllocator,
- const VmaAllocation hAllocation,
- VkImage hImage) {
+ const VmaAllocator hAllocator,
+ const VmaAllocation hAllocation,
+ VkDeviceSize allocationLocalOffset,
+ VkImage hImage,
+ const void* pNext)
+{
VMA_ASSERT(hAllocation->GetType() == VmaAllocation_T::ALLOCATION_TYPE_BLOCK &&
- hAllocation->GetBlock() == this);
+ hAllocation->GetBlock() == this);
+ VMA_ASSERT(allocationLocalOffset < hAllocation->GetSize() &&
+ "Invalid allocationLocalOffset. Did you forget that this offset is relative to the beginning of the allocation, not the whole memory block?");
+ const VkDeviceSize memoryOffset = hAllocation->GetOffset() + allocationLocalOffset;
// This lock is important so that we don't call vkBind... and/or vkMap... simultaneously on the same VkDeviceMemory from multiple threads.
VmaMutexLock lock(m_Mutex, hAllocator->m_UseMutex);
- return hAllocator->GetVulkanFunctions().vkBindImageMemory(
- hAllocator->m_hDevice,
- hImage,
- m_hMemory,
- hAllocation->GetOffset());
+ return hAllocator->BindVulkanImage(m_hMemory, memoryOffset, hImage, pNext);
}
-static void InitStatInfo(VmaStatInfo &outInfo) {
+static void InitStatInfo(VmaStatInfo& outInfo)
+{
memset(&outInfo, 0, sizeof(outInfo));
outInfo.allocationSizeMin = UINT64_MAX;
outInfo.unusedRangeSizeMin = UINT64_MAX;
}
// Adds statistics srcInfo into inoutInfo, like: inoutInfo += srcInfo.
-static void VmaAddStatInfo(VmaStatInfo &inoutInfo, const VmaStatInfo &srcInfo) {
+static void VmaAddStatInfo(VmaStatInfo& inoutInfo, const VmaStatInfo& srcInfo)
+{
inoutInfo.blockCount += srcInfo.blockCount;
inoutInfo.allocationCount += srcInfo.allocationCount;
inoutInfo.unusedRangeCount += srcInfo.unusedRangeCount;
@@ -10485,35 +11867,51 @@ static void VmaAddStatInfo(VmaStatInfo &inoutInfo, const VmaStatInfo &srcInfo) {
inoutInfo.unusedRangeSizeMax = VMA_MAX(inoutInfo.unusedRangeSizeMax, srcInfo.unusedRangeSizeMax);
}
-static void VmaPostprocessCalcStatInfo(VmaStatInfo &inoutInfo) {
+static void VmaPostprocessCalcStatInfo(VmaStatInfo& inoutInfo)
+{
inoutInfo.allocationSizeAvg = (inoutInfo.allocationCount > 0) ?
- VmaRoundDiv<VkDeviceSize>(inoutInfo.usedBytes, inoutInfo.allocationCount) :
- 0;
+ VmaRoundDiv<VkDeviceSize>(inoutInfo.usedBytes, inoutInfo.allocationCount) : 0;
inoutInfo.unusedRangeSizeAvg = (inoutInfo.unusedRangeCount > 0) ?
- VmaRoundDiv<VkDeviceSize>(inoutInfo.unusedBytes, inoutInfo.unusedRangeCount) :
- 0;
+ VmaRoundDiv<VkDeviceSize>(inoutInfo.unusedBytes, inoutInfo.unusedRangeCount) : 0;
}
VmaPool_T::VmaPool_T(
- VmaAllocator hAllocator,
- const VmaPoolCreateInfo &createInfo,
- VkDeviceSize preferredBlockSize) :
- m_BlockVector(
- hAllocator,
- this, // hParentPool
- createInfo.memoryTypeIndex,
- createInfo.blockSize != 0 ? createInfo.blockSize : preferredBlockSize,
- createInfo.minBlockCount,
- createInfo.maxBlockCount,
- (createInfo.flags & VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT) != 0 ? 1 : hAllocator->GetBufferImageGranularity(),
- createInfo.frameInUseCount,
- true, // isCustomPool
- createInfo.blockSize != 0, // explicitBlockSize
- createInfo.flags & VMA_POOL_CREATE_ALGORITHM_MASK), // algorithm
- m_Id(0) {
-}
-
-VmaPool_T::~VmaPool_T() {
+ VmaAllocator hAllocator,
+ const VmaPoolCreateInfo& createInfo,
+ VkDeviceSize preferredBlockSize) :
+ m_BlockVector(
+ hAllocator,
+ this, // hParentPool
+ createInfo.memoryTypeIndex,
+ createInfo.blockSize != 0 ? createInfo.blockSize : preferredBlockSize,
+ createInfo.minBlockCount,
+ createInfo.maxBlockCount,
+ (createInfo.flags & VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT) != 0 ? 1 : hAllocator->GetBufferImageGranularity(),
+ createInfo.frameInUseCount,
+ createInfo.blockSize != 0, // explicitBlockSize
+ createInfo.flags & VMA_POOL_CREATE_ALGORITHM_MASK), // algorithm
+ m_Id(0),
+ m_Name(VMA_NULL)
+{
+}
+
+VmaPool_T::~VmaPool_T()
+{
+}
+
+void VmaPool_T::SetName(const char* pName)
+{
+ const VkAllocationCallbacks* allocs = m_BlockVector.GetAllocator()->GetAllocationCallbacks();
+ VmaFreeString(allocs, m_Name);
+
+ if(pName != VMA_NULL)
+ {
+ m_Name = VmaCreateStringCopy(allocs, pName);
+ }
+ else
+ {
+ m_Name = VMA_NULL;
+ }
}
#if VMA_STATS_STRING_ENABLED
@@ -10521,51 +11919,56 @@ VmaPool_T::~VmaPool_T() {
#endif // #if VMA_STATS_STRING_ENABLED
VmaBlockVector::VmaBlockVector(
- VmaAllocator hAllocator,
- VmaPool hParentPool,
- uint32_t memoryTypeIndex,
- VkDeviceSize preferredBlockSize,
- size_t minBlockCount,
- size_t maxBlockCount,
- VkDeviceSize bufferImageGranularity,
- uint32_t frameInUseCount,
- bool isCustomPool,
- bool explicitBlockSize,
- uint32_t algorithm) :
- m_hAllocator(hAllocator),
- m_hParentPool(hParentPool),
- m_MemoryTypeIndex(memoryTypeIndex),
- m_PreferredBlockSize(preferredBlockSize),
- m_MinBlockCount(minBlockCount),
- m_MaxBlockCount(maxBlockCount),
- m_BufferImageGranularity(bufferImageGranularity),
- m_FrameInUseCount(frameInUseCount),
- m_IsCustomPool(isCustomPool),
- m_ExplicitBlockSize(explicitBlockSize),
- m_Algorithm(algorithm),
- m_HasEmptyBlock(false),
- m_Blocks(VmaStlAllocator<VmaDeviceMemoryBlock *>(hAllocator->GetAllocationCallbacks())),
- m_NextBlockId(0) {
-}
-
-VmaBlockVector::~VmaBlockVector() {
- for (size_t i = m_Blocks.size(); i--;) {
+ VmaAllocator hAllocator,
+ VmaPool hParentPool,
+ uint32_t memoryTypeIndex,
+ VkDeviceSize preferredBlockSize,
+ size_t minBlockCount,
+ size_t maxBlockCount,
+ VkDeviceSize bufferImageGranularity,
+ uint32_t frameInUseCount,
+ bool explicitBlockSize,
+ uint32_t algorithm) :
+ m_hAllocator(hAllocator),
+ m_hParentPool(hParentPool),
+ m_MemoryTypeIndex(memoryTypeIndex),
+ m_PreferredBlockSize(preferredBlockSize),
+ m_MinBlockCount(minBlockCount),
+ m_MaxBlockCount(maxBlockCount),
+ m_BufferImageGranularity(bufferImageGranularity),
+ m_FrameInUseCount(frameInUseCount),
+ m_ExplicitBlockSize(explicitBlockSize),
+ m_Algorithm(algorithm),
+ m_HasEmptyBlock(false),
+ m_Blocks(VmaStlAllocator<VmaDeviceMemoryBlock*>(hAllocator->GetAllocationCallbacks())),
+ m_NextBlockId(0)
+{
+}
+
+VmaBlockVector::~VmaBlockVector()
+{
+ for(size_t i = m_Blocks.size(); i--; )
+ {
m_Blocks[i]->Destroy(m_hAllocator);
vma_delete(m_hAllocator, m_Blocks[i]);
}
}
-VkResult VmaBlockVector::CreateMinBlocks() {
- for (size_t i = 0; i < m_MinBlockCount; ++i) {
+VkResult VmaBlockVector::CreateMinBlocks()
+{
+ for(size_t i = 0; i < m_MinBlockCount; ++i)
+ {
VkResult res = CreateBlock(m_PreferredBlockSize, VMA_NULL);
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
return res;
}
}
return VK_SUCCESS;
}
-void VmaBlockVector::GetPoolStats(VmaPoolStats *pStats) {
+void VmaBlockVector::GetPoolStats(VmaPoolStats* pStats)
+{
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
const size_t blockCount = m_Blocks.size();
@@ -10577,59 +11980,73 @@ void VmaBlockVector::GetPoolStats(VmaPoolStats *pStats) {
pStats->unusedRangeSizeMax = 0;
pStats->blockCount = blockCount;
- for (uint32_t blockIndex = 0; blockIndex < blockCount; ++blockIndex) {
- const VmaDeviceMemoryBlock *const pBlock = m_Blocks[blockIndex];
+ for(uint32_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+ {
+ const VmaDeviceMemoryBlock* const pBlock = m_Blocks[blockIndex];
VMA_ASSERT(pBlock);
VMA_HEAVY_ASSERT(pBlock->Validate());
pBlock->m_pMetadata->AddPoolStats(*pStats);
}
}
-bool VmaBlockVector::IsCorruptionDetectionEnabled() const {
+bool VmaBlockVector::IsEmpty()
+{
+ VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
+ return m_Blocks.empty();
+}
+
+bool VmaBlockVector::IsCorruptionDetectionEnabled() const
+{
const uint32_t requiredMemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
return (VMA_DEBUG_DETECT_CORRUPTION != 0) &&
- (VMA_DEBUG_MARGIN > 0) &&
- (m_Algorithm == 0 || m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) &&
- (m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags & requiredMemFlags) == requiredMemFlags;
+ (VMA_DEBUG_MARGIN > 0) &&
+ (m_Algorithm == 0 || m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) &&
+ (m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags & requiredMemFlags) == requiredMemFlags;
}
static const uint32_t VMA_ALLOCATION_TRY_COUNT = 32;
VkResult VmaBlockVector::Allocate(
- uint32_t currentFrameIndex,
- VkDeviceSize size,
- VkDeviceSize alignment,
- const VmaAllocationCreateInfo &createInfo,
- VmaSuballocationType suballocType,
- size_t allocationCount,
- VmaAllocation *pAllocations) {
+ uint32_t currentFrameIndex,
+ VkDeviceSize size,
+ VkDeviceSize alignment,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaSuballocationType suballocType,
+ size_t allocationCount,
+ VmaAllocation* pAllocations)
+{
size_t allocIndex;
VkResult res = VK_SUCCESS;
- if (IsCorruptionDetectionEnabled()) {
+ if(IsCorruptionDetectionEnabled())
+ {
size = VmaAlignUp<VkDeviceSize>(size, sizeof(VMA_CORRUPTION_DETECTION_MAGIC_VALUE));
alignment = VmaAlignUp<VkDeviceSize>(alignment, sizeof(VMA_CORRUPTION_DETECTION_MAGIC_VALUE));
}
{
VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
- for (allocIndex = 0; allocIndex < allocationCount; ++allocIndex) {
+ for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
+ {
res = AllocatePage(
- currentFrameIndex,
- size,
- alignment,
- createInfo,
- suballocType,
- pAllocations + allocIndex);
- if (res != VK_SUCCESS) {
+ currentFrameIndex,
+ size,
+ alignment,
+ createInfo,
+ suballocType,
+ pAllocations + allocIndex);
+ if(res != VK_SUCCESS)
+ {
break;
}
}
}
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
// Free all already created allocations.
- while (allocIndex--) {
+ while(allocIndex--)
+ {
Free(pAllocations[allocIndex]);
}
memset(pAllocations, 0, sizeof(VmaAllocation) * allocationCount);
@@ -10639,67 +12056,113 @@ VkResult VmaBlockVector::Allocate(
}
VkResult VmaBlockVector::AllocatePage(
- uint32_t currentFrameIndex,
- VkDeviceSize size,
- VkDeviceSize alignment,
- const VmaAllocationCreateInfo &createInfo,
- VmaSuballocationType suballocType,
- VmaAllocation *pAllocation) {
+ uint32_t currentFrameIndex,
+ VkDeviceSize size,
+ VkDeviceSize alignment,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaSuballocationType suballocType,
+ VmaAllocation* pAllocation)
+{
const bool isUpperAddress = (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0;
bool canMakeOtherLost = (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT) != 0;
const bool mapped = (createInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0;
const bool isUserDataString = (createInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0;
+
+ const bool withinBudget = (createInfo.flags & VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT) != 0;
+ VkDeviceSize freeMemory;
+ {
+ const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
+ VmaBudget heapBudget = {};
+ m_hAllocator->GetBudget(&heapBudget, heapIndex, 1);
+ freeMemory = (heapBudget.usage < heapBudget.budget) ? (heapBudget.budget - heapBudget.usage) : 0;
+ }
+
+ const bool canFallbackToDedicated = !IsCustomPool();
const bool canCreateNewBlock =
- ((createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0) &&
- (m_Blocks.size() < m_MaxBlockCount);
+ ((createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0) &&
+ (m_Blocks.size() < m_MaxBlockCount) &&
+ (freeMemory >= size || !canFallbackToDedicated);
uint32_t strategy = createInfo.flags & VMA_ALLOCATION_CREATE_STRATEGY_MASK;
// If linearAlgorithm is used, canMakeOtherLost is available only when used as ring buffer.
// Which in turn is available only when maxBlockCount = 1.
- if (m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT && m_MaxBlockCount > 1) {
+ if(m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT && m_MaxBlockCount > 1)
+ {
canMakeOtherLost = false;
}
// Upper address can only be used with linear allocator and within single memory block.
- if (isUpperAddress &&
- (m_Algorithm != VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT || m_MaxBlockCount > 1)) {
+ if(isUpperAddress &&
+ (m_Algorithm != VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT || m_MaxBlockCount > 1))
+ {
return VK_ERROR_FEATURE_NOT_PRESENT;
}
// Validate strategy.
- switch (strategy) {
- case 0:
- strategy = VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT;
- break;
- case VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT:
- case VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT:
- case VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT:
- break;
- default:
- return VK_ERROR_FEATURE_NOT_PRESENT;
+ switch(strategy)
+ {
+ case 0:
+ strategy = VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT;
+ break;
+ case VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT:
+ case VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT:
+ case VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT:
+ break;
+ default:
+ return VK_ERROR_FEATURE_NOT_PRESENT;
}
// Early reject: requested allocation size is larger that maximum block size for this block vector.
- if (size + 2 * VMA_DEBUG_MARGIN > m_PreferredBlockSize) {
+ if(size + 2 * VMA_DEBUG_MARGIN > m_PreferredBlockSize)
+ {
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
/*
- Under certain condition, this whole section can be skipped for optimization, so
- we move on directly to trying to allocate with canMakeOtherLost. That's the case
- e.g. for custom pools with linear algorithm.
- */
- if (!canMakeOtherLost || canCreateNewBlock) {
+ Under certain condition, this whole section can be skipped for optimization, so
+ we move on directly to trying to allocate with canMakeOtherLost. That's the case
+ e.g. for custom pools with linear algorithm.
+ */
+ if(!canMakeOtherLost || canCreateNewBlock)
+ {
// 1. Search existing allocations. Try to allocate without making other allocations lost.
VmaAllocationCreateFlags allocFlagsCopy = createInfo.flags;
allocFlagsCopy &= ~VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT;
- if (m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) {
+ if(m_Algorithm == VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT)
+ {
// Use only last block.
- if (!m_Blocks.empty()) {
- VmaDeviceMemoryBlock *const pCurrBlock = m_Blocks.back();
+ if(!m_Blocks.empty())
+ {
+ VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks.back();
VMA_ASSERT(pCurrBlock);
VkResult res = AllocateFromBlock(
+ pCurrBlock,
+ currentFrameIndex,
+ size,
+ alignment,
+ allocFlagsCopy,
+ createInfo.pUserData,
+ suballocType,
+ strategy,
+ pAllocation);
+ if(res == VK_SUCCESS)
+ {
+ VMA_DEBUG_LOG(" Returned from last block #%u", pCurrBlock->GetId());
+ return VK_SUCCESS;
+ }
+ }
+ }
+ else
+ {
+ if(strategy == VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT)
+ {
+ // Forward order in m_Blocks - prefer blocks with smallest amount of free space.
+ for(size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
+ {
+ VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks[blockIndex];
+ VMA_ASSERT(pCurrBlock);
+ VkResult res = AllocateFromBlock(
pCurrBlock,
currentFrameIndex,
size,
@@ -10709,50 +12172,33 @@ VkResult VmaBlockVector::AllocatePage(
suballocType,
strategy,
pAllocation);
- if (res == VK_SUCCESS) {
- VMA_DEBUG_LOG(" Returned from last block #%u", (uint32_t)(m_Blocks.size() - 1));
- return VK_SUCCESS;
- }
- }
- } else {
- if (strategy == VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT) {
- // Forward order in m_Blocks - prefer blocks with smallest amount of free space.
- for (size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) {
- VmaDeviceMemoryBlock *const pCurrBlock = m_Blocks[blockIndex];
- VMA_ASSERT(pCurrBlock);
- VkResult res = AllocateFromBlock(
- pCurrBlock,
- currentFrameIndex,
- size,
- alignment,
- allocFlagsCopy,
- createInfo.pUserData,
- suballocType,
- strategy,
- pAllocation);
- if (res == VK_SUCCESS) {
- VMA_DEBUG_LOG(" Returned from existing block #%u", (uint32_t)blockIndex);
+ if(res == VK_SUCCESS)
+ {
+ VMA_DEBUG_LOG(" Returned from existing block #%u", pCurrBlock->GetId());
return VK_SUCCESS;
}
}
- } else // WORST_FIT, FIRST_FIT
+ }
+ else // WORST_FIT, FIRST_FIT
{
// Backward order in m_Blocks - prefer blocks with largest amount of free space.
- for (size_t blockIndex = m_Blocks.size(); blockIndex--;) {
- VmaDeviceMemoryBlock *const pCurrBlock = m_Blocks[blockIndex];
+ for(size_t blockIndex = m_Blocks.size(); blockIndex--; )
+ {
+ VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks[blockIndex];
VMA_ASSERT(pCurrBlock);
VkResult res = AllocateFromBlock(
- pCurrBlock,
- currentFrameIndex,
- size,
- alignment,
- allocFlagsCopy,
- createInfo.pUserData,
- suballocType,
- strategy,
- pAllocation);
- if (res == VK_SUCCESS) {
- VMA_DEBUG_LOG(" Returned from existing block #%u", (uint32_t)blockIndex);
+ pCurrBlock,
+ currentFrameIndex,
+ size,
+ alignment,
+ allocFlagsCopy,
+ createInfo.pUserData,
+ suballocType,
+ strategy,
+ pAllocation);
+ if(res == VK_SUCCESS)
+ {
+ VMA_DEBUG_LOG(" Returned from existing block #%u", pCurrBlock->GetId());
return VK_SUCCESS;
}
}
@@ -10760,60 +12206,77 @@ VkResult VmaBlockVector::AllocatePage(
}
// 2. Try to create new block.
- if (canCreateNewBlock) {
+ if(canCreateNewBlock)
+ {
// Calculate optimal size for new block.
VkDeviceSize newBlockSize = m_PreferredBlockSize;
uint32_t newBlockSizeShift = 0;
const uint32_t NEW_BLOCK_SIZE_SHIFT_MAX = 3;
- if (!m_ExplicitBlockSize) {
+ if(!m_ExplicitBlockSize)
+ {
// Allocate 1/8, 1/4, 1/2 as first blocks.
const VkDeviceSize maxExistingBlockSize = CalcMaxBlockSize();
- for (uint32_t i = 0; i < NEW_BLOCK_SIZE_SHIFT_MAX; ++i) {
+ for(uint32_t i = 0; i < NEW_BLOCK_SIZE_SHIFT_MAX; ++i)
+ {
const VkDeviceSize smallerNewBlockSize = newBlockSize / 2;
- if (smallerNewBlockSize > maxExistingBlockSize && smallerNewBlockSize >= size * 2) {
+ if(smallerNewBlockSize > maxExistingBlockSize && smallerNewBlockSize >= size * 2)
+ {
newBlockSize = smallerNewBlockSize;
++newBlockSizeShift;
- } else {
+ }
+ else
+ {
break;
}
}
}
size_t newBlockIndex = 0;
- VkResult res = CreateBlock(newBlockSize, &newBlockIndex);
+ VkResult res = (newBlockSize <= freeMemory || !canFallbackToDedicated) ?
+ CreateBlock(newBlockSize, &newBlockIndex) : VK_ERROR_OUT_OF_DEVICE_MEMORY;
// Allocation of this size failed? Try 1/2, 1/4, 1/8 of m_PreferredBlockSize.
- if (!m_ExplicitBlockSize) {
- while (res < 0 && newBlockSizeShift < NEW_BLOCK_SIZE_SHIFT_MAX) {
+ if(!m_ExplicitBlockSize)
+ {
+ while(res < 0 && newBlockSizeShift < NEW_BLOCK_SIZE_SHIFT_MAX)
+ {
const VkDeviceSize smallerNewBlockSize = newBlockSize / 2;
- if (smallerNewBlockSize >= size) {
+ if(smallerNewBlockSize >= size)
+ {
newBlockSize = smallerNewBlockSize;
++newBlockSizeShift;
- res = CreateBlock(newBlockSize, &newBlockIndex);
- } else {
+ res = (newBlockSize <= freeMemory || !canFallbackToDedicated) ?
+ CreateBlock(newBlockSize, &newBlockIndex) : VK_ERROR_OUT_OF_DEVICE_MEMORY;
+ }
+ else
+ {
break;
}
}
}
- if (res == VK_SUCCESS) {
- VmaDeviceMemoryBlock *const pBlock = m_Blocks[newBlockIndex];
+ if(res == VK_SUCCESS)
+ {
+ VmaDeviceMemoryBlock* const pBlock = m_Blocks[newBlockIndex];
VMA_ASSERT(pBlock->m_pMetadata->GetSize() >= size);
res = AllocateFromBlock(
- pBlock,
- currentFrameIndex,
- size,
- alignment,
- allocFlagsCopy,
- createInfo.pUserData,
- suballocType,
- strategy,
- pAllocation);
- if (res == VK_SUCCESS) {
- VMA_DEBUG_LOG(" Created new block Size=%llu", newBlockSize);
+ pBlock,
+ currentFrameIndex,
+ size,
+ alignment,
+ allocFlagsCopy,
+ createInfo.pUserData,
+ suballocType,
+ strategy,
+ pAllocation);
+ if(res == VK_SUCCESS)
+ {
+ VMA_DEBUG_LOG(" Created new block #%u Size=%llu", pBlock->GetId(), newBlockSize);
return VK_SUCCESS;
- } else {
+ }
+ else
+ {
// Allocation from new block failed, possibly due to VMA_DEBUG_MARGIN or alignment.
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
@@ -10822,72 +12285,84 @@ VkResult VmaBlockVector::AllocatePage(
}
// 3. Try to allocate from existing blocks with making other allocations lost.
- if (canMakeOtherLost) {
+ if(canMakeOtherLost)
+ {
uint32_t tryIndex = 0;
- for (; tryIndex < VMA_ALLOCATION_TRY_COUNT; ++tryIndex) {
- VmaDeviceMemoryBlock *pBestRequestBlock = VMA_NULL;
+ for(; tryIndex < VMA_ALLOCATION_TRY_COUNT; ++tryIndex)
+ {
+ VmaDeviceMemoryBlock* pBestRequestBlock = VMA_NULL;
VmaAllocationRequest bestRequest = {};
VkDeviceSize bestRequestCost = VK_WHOLE_SIZE;
// 1. Search existing allocations.
- if (strategy == VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT) {
+ if(strategy == VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT)
+ {
// Forward order in m_Blocks - prefer blocks with smallest amount of free space.
- for (size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) {
- VmaDeviceMemoryBlock *const pCurrBlock = m_Blocks[blockIndex];
+ for(size_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex )
+ {
+ VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks[blockIndex];
VMA_ASSERT(pCurrBlock);
VmaAllocationRequest currRequest = {};
- if (pCurrBlock->m_pMetadata->CreateAllocationRequest(
- currentFrameIndex,
- m_FrameInUseCount,
- m_BufferImageGranularity,
- size,
- alignment,
- (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0,
- suballocType,
- canMakeOtherLost,
- strategy,
- &currRequest)) {
+ if(pCurrBlock->m_pMetadata->CreateAllocationRequest(
+ currentFrameIndex,
+ m_FrameInUseCount,
+ m_BufferImageGranularity,
+ size,
+ alignment,
+ (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0,
+ suballocType,
+ canMakeOtherLost,
+ strategy,
+ &currRequest))
+ {
const VkDeviceSize currRequestCost = currRequest.CalcCost();
- if (pBestRequestBlock == VMA_NULL ||
- currRequestCost < bestRequestCost) {
+ if(pBestRequestBlock == VMA_NULL ||
+ currRequestCost < bestRequestCost)
+ {
pBestRequestBlock = pCurrBlock;
bestRequest = currRequest;
bestRequestCost = currRequestCost;
- if (bestRequestCost == 0) {
+ if(bestRequestCost == 0)
+ {
break;
}
}
}
}
- } else // WORST_FIT, FIRST_FIT
+ }
+ else // WORST_FIT, FIRST_FIT
{
// Backward order in m_Blocks - prefer blocks with largest amount of free space.
- for (size_t blockIndex = m_Blocks.size(); blockIndex--;) {
- VmaDeviceMemoryBlock *const pCurrBlock = m_Blocks[blockIndex];
+ for(size_t blockIndex = m_Blocks.size(); blockIndex--; )
+ {
+ VmaDeviceMemoryBlock* const pCurrBlock = m_Blocks[blockIndex];
VMA_ASSERT(pCurrBlock);
VmaAllocationRequest currRequest = {};
- if (pCurrBlock->m_pMetadata->CreateAllocationRequest(
- currentFrameIndex,
- m_FrameInUseCount,
- m_BufferImageGranularity,
- size,
- alignment,
- (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0,
- suballocType,
- canMakeOtherLost,
- strategy,
- &currRequest)) {
+ if(pCurrBlock->m_pMetadata->CreateAllocationRequest(
+ currentFrameIndex,
+ m_FrameInUseCount,
+ m_BufferImageGranularity,
+ size,
+ alignment,
+ (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0,
+ suballocType,
+ canMakeOtherLost,
+ strategy,
+ &currRequest))
+ {
const VkDeviceSize currRequestCost = currRequest.CalcCost();
- if (pBestRequestBlock == VMA_NULL ||
- currRequestCost < bestRequestCost ||
- strategy == VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT) {
+ if(pBestRequestBlock == VMA_NULL ||
+ currRequestCost < bestRequestCost ||
+ strategy == VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT)
+ {
pBestRequestBlock = pCurrBlock;
bestRequest = currRequest;
bestRequestCost = currRequestCost;
- if (bestRequestCost == 0 ||
- strategy == VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT) {
+ if(bestRequestCost == 0 ||
+ strategy == VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT)
+ {
break;
}
}
@@ -10895,49 +12370,63 @@ VkResult VmaBlockVector::AllocatePage(
}
}
- if (pBestRequestBlock != VMA_NULL) {
- if (mapped) {
+ if(pBestRequestBlock != VMA_NULL)
+ {
+ if(mapped)
+ {
VkResult res = pBestRequestBlock->Map(m_hAllocator, 1, VMA_NULL);
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
return res;
}
}
- if (pBestRequestBlock->m_pMetadata->MakeRequestedAllocationsLost(
- currentFrameIndex,
- m_FrameInUseCount,
- &bestRequest)) {
- // We no longer have an empty Allocation.
- if (pBestRequestBlock->m_pMetadata->IsEmpty()) {
- m_HasEmptyBlock = false;
- }
+ if(pBestRequestBlock->m_pMetadata->MakeRequestedAllocationsLost(
+ currentFrameIndex,
+ m_FrameInUseCount,
+ &bestRequest))
+ {
// Allocate from this pBlock.
- *pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate();
- (*pAllocation)->Ctor(currentFrameIndex, isUserDataString);
+ *pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate(currentFrameIndex, isUserDataString);
pBestRequestBlock->m_pMetadata->Alloc(bestRequest, suballocType, size, *pAllocation);
- (*pAllocation)->InitBlockAllocation(pBestRequestBlock, bestRequest.offset, alignment, size, suballocType, mapped, (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT) != 0);
+ UpdateHasEmptyBlock();
+ (*pAllocation)->InitBlockAllocation(
+ pBestRequestBlock,
+ bestRequest.offset,
+ alignment,
+ size,
+ m_MemoryTypeIndex,
+ suballocType,
+ mapped,
+ (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT) != 0);
VMA_HEAVY_ASSERT(pBestRequestBlock->Validate());
VMA_DEBUG_LOG(" Returned from existing block");
(*pAllocation)->SetUserData(m_hAllocator, createInfo.pUserData);
- if (VMA_DEBUG_INITIALIZE_ALLOCATIONS) {
+ m_hAllocator->m_Budget.AddAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), size);
+ if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
+ {
m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
}
- if (IsCorruptionDetectionEnabled()) {
+ if(IsCorruptionDetectionEnabled())
+ {
VkResult res = pBestRequestBlock->WriteMagicValueAroundAllocation(m_hAllocator, bestRequest.offset, size);
VMA_ASSERT(res == VK_SUCCESS && "Couldn't map block memory to write magic value.");
}
return VK_SUCCESS;
}
// else: Some allocations must have been touched while we are here. Next try.
- } else {
+ }
+ else
+ {
// Could not find place in any of the blocks - break outer loop.
break;
}
}
/* Maximum number of tries exceeded - a very unlike event when many other
- threads are simultaneously touching allocations making it impossible to make
- lost at the same time as we try to allocate. */
- if (tryIndex == VMA_ALLOCATION_TRY_COUNT) {
+ threads are simultaneously touching allocations making it impossible to make
+ lost at the same time as we try to allocate. */
+ if(tryIndex == VMA_ALLOCATION_TRY_COUNT)
+ {
return VK_ERROR_TOO_MANY_OBJECTS;
}
}
@@ -10946,21 +12435,32 @@ VkResult VmaBlockVector::AllocatePage(
}
void VmaBlockVector::Free(
- VmaAllocation hAllocation) {
- VmaDeviceMemoryBlock *pBlockToDelete = VMA_NULL;
+ const VmaAllocation hAllocation)
+{
+ VmaDeviceMemoryBlock* pBlockToDelete = VMA_NULL;
+
+ bool budgetExceeded = false;
+ {
+ const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
+ VmaBudget heapBudget = {};
+ m_hAllocator->GetBudget(&heapBudget, heapIndex, 1);
+ budgetExceeded = heapBudget.usage >= heapBudget.budget;
+ }
// Scope for lock.
{
VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
- VmaDeviceMemoryBlock *pBlock = hAllocation->GetBlock();
+ VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock();
- if (IsCorruptionDetectionEnabled()) {
+ if(IsCorruptionDetectionEnabled())
+ {
VkResult res = pBlock->ValidateMagicValueAroundAllocation(m_hAllocator, hAllocation->GetOffset(), hAllocation->GetSize());
VMA_ASSERT(res == VK_SUCCESS && "Couldn't map block memory to validate magic value.");
}
- if (hAllocation->IsPersistentMap()) {
+ if(hAllocation->IsPersistentMap())
+ {
pBlock->Unmap(m_hAllocator, 1);
}
@@ -10969,55 +12469,64 @@ void VmaBlockVector::Free(
VMA_DEBUG_LOG(" Freed from MemoryTypeIndex=%u", m_MemoryTypeIndex);
+ const bool canDeleteBlock = m_Blocks.size() > m_MinBlockCount;
// pBlock became empty after this deallocation.
- if (pBlock->m_pMetadata->IsEmpty()) {
- // Already has empty Allocation. We don't want to have two, so delete this one.
- if (m_HasEmptyBlock && m_Blocks.size() > m_MinBlockCount) {
+ if(pBlock->m_pMetadata->IsEmpty())
+ {
+ // Already has empty block. We don't want to have two, so delete this one.
+ if((m_HasEmptyBlock || budgetExceeded) && canDeleteBlock)
+ {
pBlockToDelete = pBlock;
Remove(pBlock);
}
- // We now have first empty block.
- else {
- m_HasEmptyBlock = true;
- }
+ // else: We now have an empty block - leave it.
}
// pBlock didn't become empty, but we have another empty block - find and free that one.
// (This is optional, heuristics.)
- else if (m_HasEmptyBlock) {
- VmaDeviceMemoryBlock *pLastBlock = m_Blocks.back();
- if (pLastBlock->m_pMetadata->IsEmpty() && m_Blocks.size() > m_MinBlockCount) {
+ else if(m_HasEmptyBlock && canDeleteBlock)
+ {
+ VmaDeviceMemoryBlock* pLastBlock = m_Blocks.back();
+ if(pLastBlock->m_pMetadata->IsEmpty())
+ {
pBlockToDelete = pLastBlock;
m_Blocks.pop_back();
- m_HasEmptyBlock = false;
}
}
+ UpdateHasEmptyBlock();
IncrementallySortBlocks();
}
- // Destruction of a free Allocation. Deferred until this point, outside of mutex
+ // Destruction of a free block. Deferred until this point, outside of mutex
// lock, for performance reason.
- if (pBlockToDelete != VMA_NULL) {
- VMA_DEBUG_LOG(" Deleted empty allocation");
+ if(pBlockToDelete != VMA_NULL)
+ {
+ VMA_DEBUG_LOG(" Deleted empty block");
pBlockToDelete->Destroy(m_hAllocator);
vma_delete(m_hAllocator, pBlockToDelete);
}
}
-VkDeviceSize VmaBlockVector::CalcMaxBlockSize() const {
+VkDeviceSize VmaBlockVector::CalcMaxBlockSize() const
+{
VkDeviceSize result = 0;
- for (size_t i = m_Blocks.size(); i--;) {
+ for(size_t i = m_Blocks.size(); i--; )
+ {
result = VMA_MAX(result, m_Blocks[i]->m_pMetadata->GetSize());
- if (result >= m_PreferredBlockSize) {
+ if(result >= m_PreferredBlockSize)
+ {
break;
}
}
return result;
}
-void VmaBlockVector::Remove(VmaDeviceMemoryBlock *pBlock) {
- for (uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) {
- if (m_Blocks[blockIndex] == pBlock) {
+void VmaBlockVector::Remove(VmaDeviceMemoryBlock* pBlock)
+{
+ for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
+ {
+ if(m_Blocks[blockIndex] == pBlock)
+ {
VmaVectorRemove(m_Blocks, blockIndex);
return;
}
@@ -11025,11 +12534,15 @@ void VmaBlockVector::Remove(VmaDeviceMemoryBlock *pBlock) {
VMA_ASSERT(0);
}
-void VmaBlockVector::IncrementallySortBlocks() {
- if (m_Algorithm != VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT) {
+void VmaBlockVector::IncrementallySortBlocks()
+{
+ if(m_Algorithm != VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT)
+ {
// Bubble sort only until first swap.
- for (size_t i = 1; i < m_Blocks.size(); ++i) {
- if (m_Blocks[i - 1]->m_pMetadata->GetSumFreeSize() > m_Blocks[i]->m_pMetadata->GetSumFreeSize()) {
+ for(size_t i = 1; i < m_Blocks.size(); ++i)
+ {
+ if(m_Blocks[i - 1]->m_pMetadata->GetSumFreeSize() > m_Blocks[i]->m_pMetadata->GetSumFreeSize())
+ {
VMA_SWAP(m_Blocks[i - 1], m_Blocks[i]);
return;
}
@@ -11038,57 +12551,67 @@ void VmaBlockVector::IncrementallySortBlocks() {
}
VkResult VmaBlockVector::AllocateFromBlock(
- VmaDeviceMemoryBlock *pBlock,
- uint32_t currentFrameIndex,
- VkDeviceSize size,
- VkDeviceSize alignment,
- VmaAllocationCreateFlags allocFlags,
- void *pUserData,
- VmaSuballocationType suballocType,
- uint32_t strategy,
- VmaAllocation *pAllocation) {
+ VmaDeviceMemoryBlock* pBlock,
+ uint32_t currentFrameIndex,
+ VkDeviceSize size,
+ VkDeviceSize alignment,
+ VmaAllocationCreateFlags allocFlags,
+ void* pUserData,
+ VmaSuballocationType suballocType,
+ uint32_t strategy,
+ VmaAllocation* pAllocation)
+{
VMA_ASSERT((allocFlags & VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT) == 0);
const bool isUpperAddress = (allocFlags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0;
const bool mapped = (allocFlags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0;
const bool isUserDataString = (allocFlags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0;
VmaAllocationRequest currRequest = {};
- if (pBlock->m_pMetadata->CreateAllocationRequest(
- currentFrameIndex,
- m_FrameInUseCount,
- m_BufferImageGranularity,
- size,
- alignment,
- isUpperAddress,
- suballocType,
- false, // canMakeOtherLost
- strategy,
- &currRequest)) {
+ if(pBlock->m_pMetadata->CreateAllocationRequest(
+ currentFrameIndex,
+ m_FrameInUseCount,
+ m_BufferImageGranularity,
+ size,
+ alignment,
+ isUpperAddress,
+ suballocType,
+ false, // canMakeOtherLost
+ strategy,
+ &currRequest))
+ {
// Allocate from pCurrBlock.
VMA_ASSERT(currRequest.itemsToMakeLostCount == 0);
- if (mapped) {
+ if(mapped)
+ {
VkResult res = pBlock->Map(m_hAllocator, 1, VMA_NULL);
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
return res;
}
}
-
- // We no longer have an empty Allocation.
- if (pBlock->m_pMetadata->IsEmpty()) {
- m_HasEmptyBlock = false;
- }
-
- *pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate();
- (*pAllocation)->Ctor(currentFrameIndex, isUserDataString);
+
+ *pAllocation = m_hAllocator->m_AllocationObjectAllocator.Allocate(currentFrameIndex, isUserDataString);
pBlock->m_pMetadata->Alloc(currRequest, suballocType, size, *pAllocation);
- (*pAllocation)->InitBlockAllocation(pBlock, currRequest.offset, alignment, size, suballocType, mapped, (allocFlags & VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT) != 0);
+ UpdateHasEmptyBlock();
+ (*pAllocation)->InitBlockAllocation(
+ pBlock,
+ currRequest.offset,
+ alignment,
+ size,
+ m_MemoryTypeIndex,
+ suballocType,
+ mapped,
+ (allocFlags & VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT) != 0);
VMA_HEAVY_ASSERT(pBlock->Validate());
(*pAllocation)->SetUserData(m_hAllocator, pUserData);
- if (VMA_DEBUG_INITIALIZE_ALLOCATIONS) {
+ m_hAllocator->m_Budget.AddAllocation(m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex), size);
+ if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
+ {
m_hAllocator->FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
}
- if (IsCorruptionDetectionEnabled()) {
+ if(IsCorruptionDetectionEnabled())
+ {
VkResult res = pBlock->WriteMagicValueAroundAllocation(m_hAllocator, currRequest.offset, size);
VMA_ASSERT(res == VK_SUCCESS && "Couldn't map block memory to write magic value.");
}
@@ -11097,31 +12620,34 @@ VkResult VmaBlockVector::AllocateFromBlock(
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
-VkResult VmaBlockVector::CreateBlock(VkDeviceSize blockSize, size_t *pNewBlockIndex) {
+VkResult VmaBlockVector::CreateBlock(VkDeviceSize blockSize, size_t* pNewBlockIndex)
+{
VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
allocInfo.memoryTypeIndex = m_MemoryTypeIndex;
allocInfo.allocationSize = blockSize;
VkDeviceMemory mem = VK_NULL_HANDLE;
VkResult res = m_hAllocator->AllocateVulkanMemory(&allocInfo, &mem);
- if (res < 0) {
+ if(res < 0)
+ {
return res;
}
// New VkDeviceMemory successfully created.
// Create new Allocation for it.
- VmaDeviceMemoryBlock *const pBlock = vma_new(m_hAllocator, VmaDeviceMemoryBlock)(m_hAllocator);
+ VmaDeviceMemoryBlock* const pBlock = vma_new(m_hAllocator, VmaDeviceMemoryBlock)(m_hAllocator);
pBlock->Init(
- m_hAllocator,
- m_hParentPool,
- m_MemoryTypeIndex,
- mem,
- allocInfo.allocationSize,
- m_NextBlockId++,
- m_Algorithm);
+ m_hAllocator,
+ m_hParentPool,
+ m_MemoryTypeIndex,
+ mem,
+ allocInfo.allocationSize,
+ m_NextBlockId++,
+ m_Algorithm);
m_Blocks.push_back(pBlock);
- if (pNewBlockIndex != VMA_NULL) {
+ if(pNewBlockIndex != VMA_NULL)
+ {
*pNewBlockIndex = m_Blocks.size() - 1;
}
@@ -11129,28 +12655,32 @@ VkResult VmaBlockVector::CreateBlock(VkDeviceSize blockSize, size_t *pNewBlockIn
}
void VmaBlockVector::ApplyDefragmentationMovesCpu(
- class VmaBlockVectorDefragmentationContext *pDefragCtx,
- const VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves) {
+ class VmaBlockVectorDefragmentationContext* pDefragCtx,
+ const VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves)
+{
const size_t blockCount = m_Blocks.size();
const bool isNonCoherent = m_hAllocator->IsMemoryTypeNonCoherent(m_MemoryTypeIndex);
- enum BLOCK_FLAG {
+ enum BLOCK_FLAG
+ {
BLOCK_FLAG_USED = 0x00000001,
BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION = 0x00000002,
};
- struct BlockInfo {
+ struct BlockInfo
+ {
uint32_t flags;
- void *pMappedData;
+ void* pMappedData;
};
- VmaVector<BlockInfo, VmaStlAllocator<BlockInfo> >
- blockInfo(blockCount, VmaStlAllocator<BlockInfo>(m_hAllocator->GetAllocationCallbacks()));
+ VmaVector< BlockInfo, VmaStlAllocator<BlockInfo> >
+ blockInfo(blockCount, BlockInfo(), VmaStlAllocator<BlockInfo>(m_hAllocator->GetAllocationCallbacks()));
memset(blockInfo.data(), 0, blockCount * sizeof(BlockInfo));
// Go over all moves. Mark blocks that are used with BLOCK_FLAG_USED.
const size_t moveCount = moves.size();
- for (size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex) {
- const VmaDefragmentationMove &move = moves[moveIndex];
+ for(size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
+ {
+ const VmaDefragmentationMove& move = moves[moveIndex];
blockInfo[move.srcBlockIndex].flags |= BLOCK_FLAG_USED;
blockInfo[move.dstBlockIndex].flags |= BLOCK_FLAG_USED;
}
@@ -11158,15 +12688,19 @@ void VmaBlockVector::ApplyDefragmentationMovesCpu(
VMA_ASSERT(pDefragCtx->res == VK_SUCCESS);
// Go over all blocks. Get mapped pointer or map if necessary.
- for (size_t blockIndex = 0; pDefragCtx->res == VK_SUCCESS && blockIndex < blockCount; ++blockIndex) {
- BlockInfo &currBlockInfo = blockInfo[blockIndex];
- VmaDeviceMemoryBlock *pBlock = m_Blocks[blockIndex];
- if ((currBlockInfo.flags & BLOCK_FLAG_USED) != 0) {
+ for(size_t blockIndex = 0; pDefragCtx->res == VK_SUCCESS && blockIndex < blockCount; ++blockIndex)
+ {
+ BlockInfo& currBlockInfo = blockInfo[blockIndex];
+ VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
+ if((currBlockInfo.flags & BLOCK_FLAG_USED) != 0)
+ {
currBlockInfo.pMappedData = pBlock->GetMappedData();
// It is not originally mapped - map it.
- if (currBlockInfo.pMappedData == VMA_NULL) {
+ if(currBlockInfo.pMappedData == VMA_NULL)
+ {
pDefragCtx->res = pBlock->Map(m_hAllocator, 1, &currBlockInfo.pMappedData);
- if (pDefragCtx->res == VK_SUCCESS) {
+ if(pDefragCtx->res == VK_SUCCESS)
+ {
currBlockInfo.flags |= BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION;
}
}
@@ -11174,48 +12708,53 @@ void VmaBlockVector::ApplyDefragmentationMovesCpu(
}
// Go over all moves. Do actual data transfer.
- if (pDefragCtx->res == VK_SUCCESS) {
+ if(pDefragCtx->res == VK_SUCCESS)
+ {
const VkDeviceSize nonCoherentAtomSize = m_hAllocator->m_PhysicalDeviceProperties.limits.nonCoherentAtomSize;
VkMappedMemoryRange memRange = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
- for (size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex) {
- const VmaDefragmentationMove &move = moves[moveIndex];
+ for(size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
+ {
+ const VmaDefragmentationMove& move = moves[moveIndex];
- const BlockInfo &srcBlockInfo = blockInfo[move.srcBlockIndex];
- const BlockInfo &dstBlockInfo = blockInfo[move.dstBlockIndex];
+ const BlockInfo& srcBlockInfo = blockInfo[move.srcBlockIndex];
+ const BlockInfo& dstBlockInfo = blockInfo[move.dstBlockIndex];
VMA_ASSERT(srcBlockInfo.pMappedData && dstBlockInfo.pMappedData);
// Invalidate source.
- if (isNonCoherent) {
- VmaDeviceMemoryBlock *const pSrcBlock = m_Blocks[move.srcBlockIndex];
+ if(isNonCoherent)
+ {
+ VmaDeviceMemoryBlock* const pSrcBlock = m_Blocks[move.srcBlockIndex];
memRange.memory = pSrcBlock->GetDeviceMemory();
memRange.offset = VmaAlignDown(move.srcOffset, nonCoherentAtomSize);
memRange.size = VMA_MIN(
- VmaAlignUp(move.size + (move.srcOffset - memRange.offset), nonCoherentAtomSize),
- pSrcBlock->m_pMetadata->GetSize() - memRange.offset);
+ VmaAlignUp(move.size + (move.srcOffset - memRange.offset), nonCoherentAtomSize),
+ pSrcBlock->m_pMetadata->GetSize() - memRange.offset);
(*m_hAllocator->GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hAllocator->m_hDevice, 1, &memRange);
}
// THE PLACE WHERE ACTUAL DATA COPY HAPPENS.
memmove(
- reinterpret_cast<char *>(dstBlockInfo.pMappedData) + move.dstOffset,
- reinterpret_cast<char *>(srcBlockInfo.pMappedData) + move.srcOffset,
- static_cast<size_t>(move.size));
+ reinterpret_cast<char*>(dstBlockInfo.pMappedData) + move.dstOffset,
+ reinterpret_cast<char*>(srcBlockInfo.pMappedData) + move.srcOffset,
+ static_cast<size_t>(move.size));
- if (IsCorruptionDetectionEnabled()) {
+ if(IsCorruptionDetectionEnabled())
+ {
VmaWriteMagicValue(dstBlockInfo.pMappedData, move.dstOffset - VMA_DEBUG_MARGIN);
VmaWriteMagicValue(dstBlockInfo.pMappedData, move.dstOffset + move.size);
}
// Flush destination.
- if (isNonCoherent) {
- VmaDeviceMemoryBlock *const pDstBlock = m_Blocks[move.dstBlockIndex];
+ if(isNonCoherent)
+ {
+ VmaDeviceMemoryBlock* const pDstBlock = m_Blocks[move.dstBlockIndex];
memRange.memory = pDstBlock->GetDeviceMemory();
memRange.offset = VmaAlignDown(move.dstOffset, nonCoherentAtomSize);
memRange.size = VMA_MIN(
- VmaAlignUp(move.size + (move.dstOffset - memRange.offset), nonCoherentAtomSize),
- pDstBlock->m_pMetadata->GetSize() - memRange.offset);
+ VmaAlignUp(move.size + (move.dstOffset - memRange.offset), nonCoherentAtomSize),
+ pDstBlock->m_pMetadata->GetSize() - memRange.offset);
(*m_hAllocator->GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hAllocator->m_hDevice, 1, &memRange);
}
}
@@ -11223,19 +12762,22 @@ void VmaBlockVector::ApplyDefragmentationMovesCpu(
// Go over all blocks in reverse order. Unmap those that were mapped just for defragmentation.
// Regardless of pCtx->res == VK_SUCCESS.
- for (size_t blockIndex = blockCount; blockIndex--;) {
- const BlockInfo &currBlockInfo = blockInfo[blockIndex];
- if ((currBlockInfo.flags & BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION) != 0) {
- VmaDeviceMemoryBlock *pBlock = m_Blocks[blockIndex];
+ for(size_t blockIndex = blockCount; blockIndex--; )
+ {
+ const BlockInfo& currBlockInfo = blockInfo[blockIndex];
+ if((currBlockInfo.flags & BLOCK_FLAG_MAPPED_FOR_DEFRAGMENTATION) != 0)
+ {
+ VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
pBlock->Unmap(m_hAllocator, 1);
}
}
}
void VmaBlockVector::ApplyDefragmentationMovesGpu(
- class VmaBlockVectorDefragmentationContext *pDefragCtx,
- const VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkCommandBuffer commandBuffer) {
+ class VmaBlockVectorDefragmentationContext* pDefragCtx,
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkCommandBuffer commandBuffer)
+{
const size_t blockCount = m_Blocks.size();
pDefragCtx->blockContexts.resize(blockCount);
@@ -11243,10 +12785,16 @@ void VmaBlockVector::ApplyDefragmentationMovesGpu(
// Go over all moves. Mark blocks that are used with BLOCK_FLAG_USED.
const size_t moveCount = moves.size();
- for (size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex) {
- const VmaDefragmentationMove &move = moves[moveIndex];
- pDefragCtx->blockContexts[move.srcBlockIndex].flags |= VmaBlockDefragmentationContext::BLOCK_FLAG_USED;
- pDefragCtx->blockContexts[move.dstBlockIndex].flags |= VmaBlockDefragmentationContext::BLOCK_FLAG_USED;
+ for(size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
+ {
+ const VmaDefragmentationMove& move = moves[moveIndex];
+
+ //if(move.type == VMA_ALLOCATION_TYPE_UNKNOWN)
+ {
+ // Old school move still require us to map the whole block
+ pDefragCtx->blockContexts[move.srcBlockIndex].flags |= VmaBlockDefragmentationContext::BLOCK_FLAG_USED;
+ pDefragCtx->blockContexts[move.dstBlockIndex].flags |= VmaBlockDefragmentationContext::BLOCK_FLAG_USED;
+ }
}
VMA_ASSERT(pDefragCtx->res == VK_SUCCESS);
@@ -11256,54 +12804,63 @@ void VmaBlockVector::ApplyDefragmentationMovesGpu(
VkBufferCreateInfo bufCreateInfo;
VmaFillGpuDefragmentationBufferCreateInfo(bufCreateInfo);
- for (size_t blockIndex = 0; pDefragCtx->res == VK_SUCCESS && blockIndex < blockCount; ++blockIndex) {
- VmaBlockDefragmentationContext &currBlockCtx = pDefragCtx->blockContexts[blockIndex];
- VmaDeviceMemoryBlock *pBlock = m_Blocks[blockIndex];
- if ((currBlockCtx.flags & VmaBlockDefragmentationContext::BLOCK_FLAG_USED) != 0) {
+ for(size_t blockIndex = 0; pDefragCtx->res == VK_SUCCESS && blockIndex < blockCount; ++blockIndex)
+ {
+ VmaBlockDefragmentationContext& currBlockCtx = pDefragCtx->blockContexts[blockIndex];
+ VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
+ if((currBlockCtx.flags & VmaBlockDefragmentationContext::BLOCK_FLAG_USED) != 0)
+ {
bufCreateInfo.size = pBlock->m_pMetadata->GetSize();
pDefragCtx->res = (*m_hAllocator->GetVulkanFunctions().vkCreateBuffer)(
- m_hAllocator->m_hDevice, &bufCreateInfo, m_hAllocator->GetAllocationCallbacks(), &currBlockCtx.hBuffer);
- if (pDefragCtx->res == VK_SUCCESS) {
+ m_hAllocator->m_hDevice, &bufCreateInfo, m_hAllocator->GetAllocationCallbacks(), &currBlockCtx.hBuffer);
+ if(pDefragCtx->res == VK_SUCCESS)
+ {
pDefragCtx->res = (*m_hAllocator->GetVulkanFunctions().vkBindBufferMemory)(
- m_hAllocator->m_hDevice, currBlockCtx.hBuffer, pBlock->GetDeviceMemory(), 0);
+ m_hAllocator->m_hDevice, currBlockCtx.hBuffer, pBlock->GetDeviceMemory(), 0);
}
}
}
}
// Go over all moves. Post data transfer commands to command buffer.
- if (pDefragCtx->res == VK_SUCCESS) {
- for (size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex) {
- const VmaDefragmentationMove &move = moves[moveIndex];
+ if(pDefragCtx->res == VK_SUCCESS)
+ {
+ for(size_t moveIndex = 0; moveIndex < moveCount; ++moveIndex)
+ {
+ const VmaDefragmentationMove& move = moves[moveIndex];
- const VmaBlockDefragmentationContext &srcBlockCtx = pDefragCtx->blockContexts[move.srcBlockIndex];
- const VmaBlockDefragmentationContext &dstBlockCtx = pDefragCtx->blockContexts[move.dstBlockIndex];
+ const VmaBlockDefragmentationContext& srcBlockCtx = pDefragCtx->blockContexts[move.srcBlockIndex];
+ const VmaBlockDefragmentationContext& dstBlockCtx = pDefragCtx->blockContexts[move.dstBlockIndex];
VMA_ASSERT(srcBlockCtx.hBuffer && dstBlockCtx.hBuffer);
VkBufferCopy region = {
move.srcOffset,
move.dstOffset,
- move.size
- };
+ move.size };
(*m_hAllocator->GetVulkanFunctions().vkCmdCopyBuffer)(
- commandBuffer, srcBlockCtx.hBuffer, dstBlockCtx.hBuffer, 1, &region);
+ commandBuffer, srcBlockCtx.hBuffer, dstBlockCtx.hBuffer, 1, &region);
}
}
// Save buffers to defrag context for later destruction.
- if (pDefragCtx->res == VK_SUCCESS && moveCount > 0) {
+ if(pDefragCtx->res == VK_SUCCESS && moveCount > 0)
+ {
pDefragCtx->res = VK_NOT_READY;
}
}
-void VmaBlockVector::FreeEmptyBlocks(VmaDefragmentationStats *pDefragmentationStats) {
- m_HasEmptyBlock = false;
- for (size_t blockIndex = m_Blocks.size(); blockIndex--;) {
- VmaDeviceMemoryBlock *pBlock = m_Blocks[blockIndex];
- if (pBlock->m_pMetadata->IsEmpty()) {
- if (m_Blocks.size() > m_MinBlockCount) {
- if (pDefragmentationStats != VMA_NULL) {
+void VmaBlockVector::FreeEmptyBlocks(VmaDefragmentationStats* pDefragmentationStats)
+{
+ for(size_t blockIndex = m_Blocks.size(); blockIndex--; )
+ {
+ VmaDeviceMemoryBlock* pBlock = m_Blocks[blockIndex];
+ if(pBlock->m_pMetadata->IsEmpty())
+ {
+ if(m_Blocks.size() > m_MinBlockCount)
+ {
+ if(pDefragmentationStats != VMA_NULL)
+ {
++pDefragmentationStats->deviceMemoryBlocksFreed;
pDefragmentationStats->bytesFreed += pBlock->m_pMetadata->GetSize();
}
@@ -11311,21 +12868,47 @@ void VmaBlockVector::FreeEmptyBlocks(VmaDefragmentationStats *pDefragmentationSt
VmaVectorRemove(m_Blocks, blockIndex);
pBlock->Destroy(m_hAllocator);
vma_delete(m_hAllocator, pBlock);
- } else {
- m_HasEmptyBlock = true;
}
+ else
+ {
+ break;
+ }
+ }
+ }
+ UpdateHasEmptyBlock();
+}
+
+void VmaBlockVector::UpdateHasEmptyBlock()
+{
+ m_HasEmptyBlock = false;
+ for(size_t index = 0, count = m_Blocks.size(); index < count; ++index)
+ {
+ VmaDeviceMemoryBlock* const pBlock = m_Blocks[index];
+ if(pBlock->m_pMetadata->IsEmpty())
+ {
+ m_HasEmptyBlock = true;
+ break;
}
}
}
#if VMA_STATS_STRING_ENABLED
-void VmaBlockVector::PrintDetailedMap(class VmaJsonWriter &json) {
+void VmaBlockVector::PrintDetailedMap(class VmaJsonWriter& json)
+{
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
json.BeginObject();
- if (m_IsCustomPool) {
+ if(IsCustomPool())
+ {
+ const char* poolName = m_hParentPool->GetName();
+ if(poolName != VMA_NULL && poolName[0] != '\0')
+ {
+ json.WriteString("Name");
+ json.WriteString(poolName);
+ }
+
json.WriteString("MemoryTypeIndex");
json.WriteNumber(m_MemoryTypeIndex);
@@ -11334,11 +12917,13 @@ void VmaBlockVector::PrintDetailedMap(class VmaJsonWriter &json) {
json.WriteString("BlockCount");
json.BeginObject(true);
- if (m_MinBlockCount > 0) {
+ if(m_MinBlockCount > 0)
+ {
json.WriteString("Min");
json.WriteNumber((uint64_t)m_MinBlockCount);
}
- if (m_MaxBlockCount < SIZE_MAX) {
+ if(m_MaxBlockCount < SIZE_MAX)
+ {
json.WriteString("Max");
json.WriteNumber((uint64_t)m_MaxBlockCount);
}
@@ -11346,23 +12931,28 @@ void VmaBlockVector::PrintDetailedMap(class VmaJsonWriter &json) {
json.WriteNumber((uint64_t)m_Blocks.size());
json.EndObject();
- if (m_FrameInUseCount > 0) {
+ if(m_FrameInUseCount > 0)
+ {
json.WriteString("FrameInUseCount");
json.WriteNumber(m_FrameInUseCount);
}
- if (m_Algorithm != 0) {
+ if(m_Algorithm != 0)
+ {
json.WriteString("Algorithm");
json.WriteString(VmaAlgorithmToStr(m_Algorithm));
}
- } else {
+ }
+ else
+ {
json.WriteString("PreferredBlockSize");
json.WriteNumber(m_PreferredBlockSize);
}
json.WriteString("Blocks");
json.BeginObject();
- for (size_t i = 0; i < m_Blocks.size(); ++i) {
+ for(size_t i = 0; i < m_Blocks.size(); ++i)
+ {
json.BeginString();
json.ContinueString(m_Blocks[i]->GetId());
json.EndString();
@@ -11377,121 +12967,206 @@ void VmaBlockVector::PrintDetailedMap(class VmaJsonWriter &json) {
#endif // #if VMA_STATS_STRING_ENABLED
void VmaBlockVector::Defragment(
- class VmaBlockVectorDefragmentationContext *pCtx,
- VmaDefragmentationStats *pStats,
- VkDeviceSize &maxCpuBytesToMove, uint32_t &maxCpuAllocationsToMove,
- VkDeviceSize &maxGpuBytesToMove, uint32_t &maxGpuAllocationsToMove,
- VkCommandBuffer commandBuffer) {
+ class VmaBlockVectorDefragmentationContext* pCtx,
+ VmaDefragmentationStats* pStats, VmaDefragmentationFlags flags,
+ VkDeviceSize& maxCpuBytesToMove, uint32_t& maxCpuAllocationsToMove,
+ VkDeviceSize& maxGpuBytesToMove, uint32_t& maxGpuAllocationsToMove,
+ VkCommandBuffer commandBuffer)
+{
pCtx->res = VK_SUCCESS;
-
+
const VkMemoryPropertyFlags memPropFlags =
- m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags;
+ m_hAllocator->m_MemProps.memoryTypes[m_MemoryTypeIndex].propertyFlags;
const bool isHostVisible = (memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0;
- const bool isHostCoherent = (memPropFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0;
const bool canDefragmentOnCpu = maxCpuBytesToMove > 0 && maxCpuAllocationsToMove > 0 &&
- isHostVisible;
+ isHostVisible;
const bool canDefragmentOnGpu = maxGpuBytesToMove > 0 && maxGpuAllocationsToMove > 0 &&
- !IsCorruptionDetectionEnabled() &&
- ((1u << m_MemoryTypeIndex) & m_hAllocator->GetGpuDefragmentationMemoryTypeBits()) != 0;
+ !IsCorruptionDetectionEnabled() &&
+ ((1u << m_MemoryTypeIndex) & m_hAllocator->GetGpuDefragmentationMemoryTypeBits()) != 0;
// There are options to defragment this memory type.
- if (canDefragmentOnCpu || canDefragmentOnGpu) {
+ if(canDefragmentOnCpu || canDefragmentOnGpu)
+ {
bool defragmentOnGpu;
// There is only one option to defragment this memory type.
- if (canDefragmentOnGpu != canDefragmentOnCpu) {
+ if(canDefragmentOnGpu != canDefragmentOnCpu)
+ {
defragmentOnGpu = canDefragmentOnGpu;
}
// Both options are available: Heuristics to choose the best one.
- else {
+ else
+ {
defragmentOnGpu = (memPropFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0 ||
- m_hAllocator->IsIntegratedGpu();
+ m_hAllocator->IsIntegratedGpu();
}
bool overlappingMoveSupported = !defragmentOnGpu;
- if (m_hAllocator->m_UseMutex) {
- m_Mutex.LockWrite();
- pCtx->mutexLocked = true;
+ if(m_hAllocator->m_UseMutex)
+ {
+ if(flags & VMA_DEFRAGMENTATION_FLAG_INCREMENTAL)
+ {
+ if(!m_Mutex.TryLockWrite())
+ {
+ pCtx->res = VK_ERROR_INITIALIZATION_FAILED;
+ return;
+ }
+ }
+ else
+ {
+ m_Mutex.LockWrite();
+ pCtx->mutexLocked = true;
+ }
}
- pCtx->Begin(overlappingMoveSupported);
+ pCtx->Begin(overlappingMoveSupported, flags);
// Defragment.
const VkDeviceSize maxBytesToMove = defragmentOnGpu ? maxGpuBytesToMove : maxCpuBytesToMove;
const uint32_t maxAllocationsToMove = defragmentOnGpu ? maxGpuAllocationsToMove : maxCpuAllocationsToMove;
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > moves =
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >(VmaStlAllocator<VmaDefragmentationMove>(m_hAllocator->GetAllocationCallbacks()));
- pCtx->res = pCtx->GetAlgorithm()->Defragment(moves, maxBytesToMove, maxAllocationsToMove);
+ pCtx->res = pCtx->GetAlgorithm()->Defragment(pCtx->defragmentationMoves, maxBytesToMove, maxAllocationsToMove, flags);
// Accumulate statistics.
- if (pStats != VMA_NULL) {
+ if(pStats != VMA_NULL)
+ {
const VkDeviceSize bytesMoved = pCtx->GetAlgorithm()->GetBytesMoved();
const uint32_t allocationsMoved = pCtx->GetAlgorithm()->GetAllocationsMoved();
pStats->bytesMoved += bytesMoved;
pStats->allocationsMoved += allocationsMoved;
VMA_ASSERT(bytesMoved <= maxBytesToMove);
VMA_ASSERT(allocationsMoved <= maxAllocationsToMove);
- if (defragmentOnGpu) {
+ if(defragmentOnGpu)
+ {
maxGpuBytesToMove -= bytesMoved;
maxGpuAllocationsToMove -= allocationsMoved;
- } else {
+ }
+ else
+ {
maxCpuBytesToMove -= bytesMoved;
maxCpuAllocationsToMove -= allocationsMoved;
}
}
- if (pCtx->res >= VK_SUCCESS) {
- if (defragmentOnGpu) {
- ApplyDefragmentationMovesGpu(pCtx, moves, commandBuffer);
- } else {
- ApplyDefragmentationMovesCpu(pCtx, moves);
+ if(flags & VMA_DEFRAGMENTATION_FLAG_INCREMENTAL)
+ {
+ if(m_hAllocator->m_UseMutex)
+ m_Mutex.UnlockWrite();
+
+ if(pCtx->res >= VK_SUCCESS && !pCtx->defragmentationMoves.empty())
+ pCtx->res = VK_NOT_READY;
+
+ return;
+ }
+
+ if(pCtx->res >= VK_SUCCESS)
+ {
+ if(defragmentOnGpu)
+ {
+ ApplyDefragmentationMovesGpu(pCtx, pCtx->defragmentationMoves, commandBuffer);
+ }
+ else
+ {
+ ApplyDefragmentationMovesCpu(pCtx, pCtx->defragmentationMoves);
}
}
}
}
void VmaBlockVector::DefragmentationEnd(
- class VmaBlockVectorDefragmentationContext *pCtx,
- VmaDefragmentationStats *pStats) {
+ class VmaBlockVectorDefragmentationContext* pCtx,
+ VmaDefragmentationStats* pStats)
+{
// Destroy buffers.
- for (size_t blockIndex = pCtx->blockContexts.size(); blockIndex--;) {
- VmaBlockDefragmentationContext &blockCtx = pCtx->blockContexts[blockIndex];
- if (blockCtx.hBuffer) {
+ for(size_t blockIndex = pCtx->blockContexts.size(); blockIndex--; )
+ {
+ VmaBlockDefragmentationContext& blockCtx = pCtx->blockContexts[blockIndex];
+ if(blockCtx.hBuffer)
+ {
(*m_hAllocator->GetVulkanFunctions().vkDestroyBuffer)(
- m_hAllocator->m_hDevice, blockCtx.hBuffer, m_hAllocator->GetAllocationCallbacks());
+ m_hAllocator->m_hDevice, blockCtx.hBuffer, m_hAllocator->GetAllocationCallbacks());
}
}
- if (pCtx->res >= VK_SUCCESS) {
+ if(pCtx->res >= VK_SUCCESS)
+ {
FreeEmptyBlocks(pStats);
}
- if (pCtx->mutexLocked) {
+ if(pCtx->mutexLocked)
+ {
VMA_ASSERT(m_hAllocator->m_UseMutex);
m_Mutex.UnlockWrite();
}
}
-size_t VmaBlockVector::CalcAllocationCount() const {
+uint32_t VmaBlockVector::ProcessDefragmentations(
+ class VmaBlockVectorDefragmentationContext *pCtx,
+ VmaDefragmentationPassMoveInfo* pMove, uint32_t maxMoves)
+{
+ VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
+
+ const uint32_t moveCount = std::min(uint32_t(pCtx->defragmentationMoves.size()) - pCtx->defragmentationMovesProcessed, maxMoves);
+
+ for(uint32_t i = 0; i < moveCount; ++ i)
+ {
+ VmaDefragmentationMove& move = pCtx->defragmentationMoves[pCtx->defragmentationMovesProcessed + i];
+
+ pMove->allocation = move.hAllocation;
+ pMove->memory = move.pDstBlock->GetDeviceMemory();
+ pMove->offset = move.dstOffset;
+
+ ++ pMove;
+ }
+
+ pCtx->defragmentationMovesProcessed += moveCount;
+
+ return moveCount;
+}
+
+void VmaBlockVector::CommitDefragmentations(
+ class VmaBlockVectorDefragmentationContext *pCtx,
+ VmaDefragmentationStats* pStats)
+{
+ VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
+
+ for(uint32_t i = pCtx->defragmentationMovesCommitted; i < pCtx->defragmentationMovesProcessed; ++ i)
+ {
+ const VmaDefragmentationMove &move = pCtx->defragmentationMoves[i];
+
+ move.pSrcBlock->m_pMetadata->FreeAtOffset(move.srcOffset);
+ move.hAllocation->ChangeBlockAllocation(m_hAllocator, move.pDstBlock, move.dstOffset);
+ }
+
+ pCtx->defragmentationMovesCommitted = pCtx->defragmentationMovesProcessed;
+ FreeEmptyBlocks(pStats);
+}
+
+size_t VmaBlockVector::CalcAllocationCount() const
+{
size_t result = 0;
- for (size_t i = 0; i < m_Blocks.size(); ++i) {
+ for(size_t i = 0; i < m_Blocks.size(); ++i)
+ {
result += m_Blocks[i]->m_pMetadata->GetAllocationCount();
}
return result;
}
-bool VmaBlockVector::IsBufferImageGranularityConflictPossible() const {
- if (m_BufferImageGranularity == 1) {
+bool VmaBlockVector::IsBufferImageGranularityConflictPossible() const
+{
+ if(m_BufferImageGranularity == 1)
+ {
return false;
}
VmaSuballocationType lastSuballocType = VMA_SUBALLOCATION_TYPE_FREE;
- for (size_t i = 0, count = m_Blocks.size(); i < count; ++i) {
- VmaDeviceMemoryBlock *const pBlock = m_Blocks[i];
+ for(size_t i = 0, count = m_Blocks.size(); i < count; ++i)
+ {
+ VmaDeviceMemoryBlock* const pBlock = m_Blocks[i];
VMA_ASSERT(m_Algorithm == 0);
- VmaBlockMetadata_Generic *const pMetadata = (VmaBlockMetadata_Generic *)pBlock->m_pMetadata;
- if (pMetadata->IsBufferImageGranularityConflictPossible(m_BufferImageGranularity, lastSuballocType)) {
+ VmaBlockMetadata_Generic* const pMetadata = (VmaBlockMetadata_Generic*)pBlock->m_pMetadata;
+ if(pMetadata->IsBufferImageGranularityConflictPossible(m_BufferImageGranularity, lastSuballocType))
+ {
return true;
}
}
@@ -11499,45 +13174,54 @@ bool VmaBlockVector::IsBufferImageGranularityConflictPossible() const {
}
void VmaBlockVector::MakePoolAllocationsLost(
- uint32_t currentFrameIndex,
- size_t *pLostAllocationCount) {
+ uint32_t currentFrameIndex,
+ size_t* pLostAllocationCount)
+{
VmaMutexLockWrite lock(m_Mutex, m_hAllocator->m_UseMutex);
size_t lostAllocationCount = 0;
- for (uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) {
- VmaDeviceMemoryBlock *const pBlock = m_Blocks[blockIndex];
+ for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
+ {
+ VmaDeviceMemoryBlock* const pBlock = m_Blocks[blockIndex];
VMA_ASSERT(pBlock);
lostAllocationCount += pBlock->m_pMetadata->MakeAllocationsLost(currentFrameIndex, m_FrameInUseCount);
}
- if (pLostAllocationCount != VMA_NULL) {
+ if(pLostAllocationCount != VMA_NULL)
+ {
*pLostAllocationCount = lostAllocationCount;
}
}
-VkResult VmaBlockVector::CheckCorruption() {
- if (!IsCorruptionDetectionEnabled()) {
+VkResult VmaBlockVector::CheckCorruption()
+{
+ if(!IsCorruptionDetectionEnabled())
+ {
return VK_ERROR_FEATURE_NOT_PRESENT;
}
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
- for (uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) {
- VmaDeviceMemoryBlock *const pBlock = m_Blocks[blockIndex];
+ for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
+ {
+ VmaDeviceMemoryBlock* const pBlock = m_Blocks[blockIndex];
VMA_ASSERT(pBlock);
VkResult res = pBlock->CheckCorruption(m_hAllocator);
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
return res;
}
}
return VK_SUCCESS;
}
-void VmaBlockVector::AddStats(VmaStats *pStats) {
+void VmaBlockVector::AddStats(VmaStats* pStats)
+{
const uint32_t memTypeIndex = m_MemoryTypeIndex;
const uint32_t memHeapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(memTypeIndex);
VmaMutexLockRead lock(m_Mutex, m_hAllocator->m_UseMutex);
- for (uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex) {
- const VmaDeviceMemoryBlock *const pBlock = m_Blocks[blockIndex];
+ for(uint32_t blockIndex = 0; blockIndex < m_Blocks.size(); ++blockIndex)
+ {
+ const VmaDeviceMemoryBlock* const pBlock = m_Blocks[blockIndex];
VMA_ASSERT(pBlock);
VMA_HEAVY_ASSERT(pBlock->Validate());
VmaStatInfo allocationStatInfo;
@@ -11552,20 +13236,22 @@ void VmaBlockVector::AddStats(VmaStats *pStats) {
// VmaDefragmentationAlgorithm_Generic members definition
VmaDefragmentationAlgorithm_Generic::VmaDefragmentationAlgorithm_Generic(
- VmaAllocator hAllocator,
- VmaBlockVector *pBlockVector,
- uint32_t currentFrameIndex,
- bool overlappingMoveSupported) :
- VmaDefragmentationAlgorithm(hAllocator, pBlockVector, currentFrameIndex),
- m_AllocationCount(0),
- m_AllAllocations(false),
- m_BytesMoved(0),
- m_AllocationsMoved(0),
- m_Blocks(VmaStlAllocator<BlockInfo *>(hAllocator->GetAllocationCallbacks())) {
+ VmaAllocator hAllocator,
+ VmaBlockVector* pBlockVector,
+ uint32_t currentFrameIndex,
+ bool overlappingMoveSupported) :
+ VmaDefragmentationAlgorithm(hAllocator, pBlockVector, currentFrameIndex),
+ m_AllocationCount(0),
+ m_AllAllocations(false),
+ m_BytesMoved(0),
+ m_AllocationsMoved(0),
+ m_Blocks(VmaStlAllocator<BlockInfo*>(hAllocator->GetAllocationCallbacks()))
+{
// Create block info for each block.
const size_t blockCount = m_pBlockVector->m_Blocks.size();
- for (size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex) {
- BlockInfo *pBlockInfo = vma_new(m_hAllocator, BlockInfo)(m_hAllocator->GetAllocationCallbacks());
+ for(size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+ {
+ BlockInfo* pBlockInfo = vma_new(m_hAllocator, BlockInfo)(m_hAllocator->GetAllocationCallbacks());
pBlockInfo->m_OriginalBlockIndex = blockIndex;
pBlockInfo->m_pBlock = m_pBlockVector->m_Blocks[blockIndex];
m_Blocks.push_back(pBlockInfo);
@@ -11575,21 +13261,28 @@ VmaDefragmentationAlgorithm_Generic::VmaDefragmentationAlgorithm_Generic(
VMA_SORT(m_Blocks.begin(), m_Blocks.end(), BlockPointerLess());
}
-VmaDefragmentationAlgorithm_Generic::~VmaDefragmentationAlgorithm_Generic() {
- for (size_t i = m_Blocks.size(); i--;) {
+VmaDefragmentationAlgorithm_Generic::~VmaDefragmentationAlgorithm_Generic()
+{
+ for(size_t i = m_Blocks.size(); i--; )
+ {
vma_delete(m_hAllocator, m_Blocks[i]);
}
}
-void VmaDefragmentationAlgorithm_Generic::AddAllocation(VmaAllocation hAlloc, VkBool32 *pChanged) {
+void VmaDefragmentationAlgorithm_Generic::AddAllocation(VmaAllocation hAlloc, VkBool32* pChanged)
+{
// Now as we are inside VmaBlockVector::m_Mutex, we can make final check if this allocation was not lost.
- if (hAlloc->GetLastUseFrameIndex() != VMA_FRAME_INDEX_LOST) {
- VmaDeviceMemoryBlock *pBlock = hAlloc->GetBlock();
+ if(hAlloc->GetLastUseFrameIndex() != VMA_FRAME_INDEX_LOST)
+ {
+ VmaDeviceMemoryBlock* pBlock = hAlloc->GetBlock();
BlockInfoVector::iterator it = VmaBinaryFindFirstNotLess(m_Blocks.begin(), m_Blocks.end(), pBlock, BlockPointerLess());
- if (it != m_Blocks.end() && (*it)->m_pBlock == pBlock) {
+ if(it != m_Blocks.end() && (*it)->m_pBlock == pBlock)
+ {
AllocationInfo allocInfo = AllocationInfo(hAlloc, pChanged);
(*it)->m_Allocations.push_back(allocInfo);
- } else {
+ }
+ else
+ {
VMA_ASSERT(0);
}
@@ -11598,10 +13291,13 @@ void VmaDefragmentationAlgorithm_Generic::AddAllocation(VmaAllocation hAlloc, Vk
}
VkResult VmaDefragmentationAlgorithm_Generic::DefragmentRound(
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkDeviceSize maxBytesToMove,
- uint32_t maxAllocationsToMove) {
- if (m_Blocks.empty()) {
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkDeviceSize maxBytesToMove,
+ uint32_t maxAllocationsToMove,
+ bool freeOldAllocations)
+{
+ if(m_Blocks.empty())
+ {
return VK_SUCCESS;
}
@@ -11616,38 +13312,46 @@ VkResult VmaDefragmentationAlgorithm_Generic::DefragmentRound(
size_t srcBlockMinIndex = 0;
// When FAST_ALGORITHM, move allocations from only last out of blocks that contain non-movable allocations.
/*
- if(m_AlgorithmFlags & VMA_DEFRAGMENTATION_FAST_ALGORITHM_BIT)
- {
- const size_t blocksWithNonMovableCount = CalcBlocksWithNonMovableCount();
- if(blocksWithNonMovableCount > 0)
+ if(m_AlgorithmFlags & VMA_DEFRAGMENTATION_FAST_ALGORITHM_BIT)
{
- srcBlockMinIndex = blocksWithNonMovableCount - 1;
+ const size_t blocksWithNonMovableCount = CalcBlocksWithNonMovableCount();
+ if(blocksWithNonMovableCount > 0)
+ {
+ srcBlockMinIndex = blocksWithNonMovableCount - 1;
+ }
}
- }
- */
+ */
size_t srcBlockIndex = m_Blocks.size() - 1;
size_t srcAllocIndex = SIZE_MAX;
- for (;;) {
+ for(;;)
+ {
// 1. Find next allocation to move.
// 1.1. Start from last to first m_Blocks - they are sorted from most "destination" to most "source".
// 1.2. Then start from last to first m_Allocations.
- while (srcAllocIndex >= m_Blocks[srcBlockIndex]->m_Allocations.size()) {
- if (m_Blocks[srcBlockIndex]->m_Allocations.empty()) {
+ while(srcAllocIndex >= m_Blocks[srcBlockIndex]->m_Allocations.size())
+ {
+ if(m_Blocks[srcBlockIndex]->m_Allocations.empty())
+ {
// Finished: no more allocations to process.
- if (srcBlockIndex == srcBlockMinIndex) {
+ if(srcBlockIndex == srcBlockMinIndex)
+ {
return VK_SUCCESS;
- } else {
+ }
+ else
+ {
--srcBlockIndex;
srcAllocIndex = SIZE_MAX;
}
- } else {
+ }
+ else
+ {
srcAllocIndex = m_Blocks[srcBlockIndex]->m_Allocations.size() - 1;
}
}
-
- BlockInfo *pSrcBlockInfo = m_Blocks[srcBlockIndex];
- AllocationInfo &allocInfo = pSrcBlockInfo->m_Allocations[srcAllocIndex];
+
+ BlockInfo* pSrcBlockInfo = m_Blocks[srcBlockIndex];
+ AllocationInfo& allocInfo = pSrcBlockInfo->m_Allocations[srcAllocIndex];
const VkDeviceSize size = allocInfo.m_hAllocation->GetSize();
const VkDeviceSize srcOffset = allocInfo.m_hAllocation->GetOffset();
@@ -11655,48 +13359,59 @@ VkResult VmaDefragmentationAlgorithm_Generic::DefragmentRound(
const VmaSuballocationType suballocType = allocInfo.m_hAllocation->GetSuballocationType();
// 2. Try to find new place for this allocation in preceding or current block.
- for (size_t dstBlockIndex = 0; dstBlockIndex <= srcBlockIndex; ++dstBlockIndex) {
- BlockInfo *pDstBlockInfo = m_Blocks[dstBlockIndex];
+ for(size_t dstBlockIndex = 0; dstBlockIndex <= srcBlockIndex; ++dstBlockIndex)
+ {
+ BlockInfo* pDstBlockInfo = m_Blocks[dstBlockIndex];
VmaAllocationRequest dstAllocRequest;
- if (pDstBlockInfo->m_pBlock->m_pMetadata->CreateAllocationRequest(
- m_CurrentFrameIndex,
- m_pBlockVector->GetFrameInUseCount(),
- m_pBlockVector->GetBufferImageGranularity(),
- size,
- alignment,
- false, // upperAddress
- suballocType,
- false, // canMakeOtherLost
- strategy,
- &dstAllocRequest) &&
- MoveMakesSense(
- dstBlockIndex, dstAllocRequest.offset, srcBlockIndex, srcOffset)) {
+ if(pDstBlockInfo->m_pBlock->m_pMetadata->CreateAllocationRequest(
+ m_CurrentFrameIndex,
+ m_pBlockVector->GetFrameInUseCount(),
+ m_pBlockVector->GetBufferImageGranularity(),
+ size,
+ alignment,
+ false, // upperAddress
+ suballocType,
+ false, // canMakeOtherLost
+ strategy,
+ &dstAllocRequest) &&
+ MoveMakesSense(
+ dstBlockIndex, dstAllocRequest.offset, srcBlockIndex, srcOffset))
+ {
VMA_ASSERT(dstAllocRequest.itemsToMakeLostCount == 0);
// Reached limit on number of allocations or bytes to move.
- if ((m_AllocationsMoved + 1 > maxAllocationsToMove) ||
- (m_BytesMoved + size > maxBytesToMove)) {
+ if((m_AllocationsMoved + 1 > maxAllocationsToMove) ||
+ (m_BytesMoved + size > maxBytesToMove))
+ {
return VK_SUCCESS;
}
- VmaDefragmentationMove move;
+ VmaDefragmentationMove move = {};
move.srcBlockIndex = pSrcBlockInfo->m_OriginalBlockIndex;
move.dstBlockIndex = pDstBlockInfo->m_OriginalBlockIndex;
move.srcOffset = srcOffset;
move.dstOffset = dstAllocRequest.offset;
move.size = size;
+ move.hAllocation = allocInfo.m_hAllocation;
+ move.pSrcBlock = pSrcBlockInfo->m_pBlock;
+ move.pDstBlock = pDstBlockInfo->m_pBlock;
+
moves.push_back(move);
pDstBlockInfo->m_pBlock->m_pMetadata->Alloc(
- dstAllocRequest,
- suballocType,
- size,
- allocInfo.m_hAllocation);
- pSrcBlockInfo->m_pBlock->m_pMetadata->FreeAtOffset(srcOffset);
-
- allocInfo.m_hAllocation->ChangeBlockAllocation(m_hAllocator, pDstBlockInfo->m_pBlock, dstAllocRequest.offset);
+ dstAllocRequest,
+ suballocType,
+ size,
+ allocInfo.m_hAllocation);
- if (allocInfo.m_pChanged != VMA_NULL) {
+ if(freeOldAllocations)
+ {
+ pSrcBlockInfo->m_pBlock->m_pMetadata->FreeAtOffset(srcOffset);
+ allocInfo.m_hAllocation->ChangeBlockAllocation(m_hAllocator, pDstBlockInfo->m_pBlock, dstAllocRequest.offset);
+ }
+
+ if(allocInfo.m_pChanged != VMA_NULL)
+ {
*allocInfo.m_pChanged = VK_TRUE;
}
@@ -11711,23 +13426,32 @@ VkResult VmaDefragmentationAlgorithm_Generic::DefragmentRound(
// If not processed, this allocInfo remains in pBlockInfo->m_Allocations for next round.
- if (srcAllocIndex > 0) {
+ if(srcAllocIndex > 0)
+ {
--srcAllocIndex;
- } else {
- if (srcBlockIndex > 0) {
+ }
+ else
+ {
+ if(srcBlockIndex > 0)
+ {
--srcBlockIndex;
srcAllocIndex = SIZE_MAX;
- } else {
+ }
+ else
+ {
return VK_SUCCESS;
}
}
}
}
-size_t VmaDefragmentationAlgorithm_Generic::CalcBlocksWithNonMovableCount() const {
+size_t VmaDefragmentationAlgorithm_Generic::CalcBlocksWithNonMovableCount() const
+{
size_t result = 0;
- for (size_t i = 0; i < m_Blocks.size(); ++i) {
- if (m_Blocks[i]->m_HasNonMovableAllocations) {
+ for(size_t i = 0; i < m_Blocks.size(); ++i)
+ {
+ if(m_Blocks[i]->m_HasNonMovableAllocations)
+ {
++result;
}
}
@@ -11735,23 +13459,30 @@ size_t VmaDefragmentationAlgorithm_Generic::CalcBlocksWithNonMovableCount() cons
}
VkResult VmaDefragmentationAlgorithm_Generic::Defragment(
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkDeviceSize maxBytesToMove,
- uint32_t maxAllocationsToMove) {
- if (!m_AllAllocations && m_AllocationCount == 0) {
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkDeviceSize maxBytesToMove,
+ uint32_t maxAllocationsToMove,
+ VmaDefragmentationFlags flags)
+{
+ if(!m_AllAllocations && m_AllocationCount == 0)
+ {
return VK_SUCCESS;
}
const size_t blockCount = m_Blocks.size();
- for (size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex) {
- BlockInfo *pBlockInfo = m_Blocks[blockIndex];
-
- if (m_AllAllocations) {
- VmaBlockMetadata_Generic *pMetadata = (VmaBlockMetadata_Generic *)pBlockInfo->m_pBlock->m_pMetadata;
- for (VmaSuballocationList::const_iterator it = pMetadata->m_Suballocations.begin();
- it != pMetadata->m_Suballocations.end();
- ++it) {
- if (it->type != VMA_SUBALLOCATION_TYPE_FREE) {
+ for(size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+ {
+ BlockInfo* pBlockInfo = m_Blocks[blockIndex];
+
+ if(m_AllAllocations)
+ {
+ VmaBlockMetadata_Generic* pMetadata = (VmaBlockMetadata_Generic*)pBlockInfo->m_pBlock->m_pMetadata;
+ for(VmaSuballocationList::const_iterator it = pMetadata->m_Suballocations.begin();
+ it != pMetadata->m_Suballocations.end();
+ ++it)
+ {
+ if(it->type != VMA_SUBALLOCATION_TYPE_FREE)
+ {
AllocationInfo allocInfo = AllocationInfo(it->hAllocation, VMA_NULL);
pBlockInfo->m_Allocations.push_back(allocInfo);
}
@@ -11759,7 +13490,7 @@ VkResult VmaDefragmentationAlgorithm_Generic::Defragment(
}
pBlockInfo->CalcHasNonMovableAllocations();
-
+
// This is a choice based on research.
// Option 1:
pBlockInfo->SortAllocationsByOffsetDescending();
@@ -11775,8 +13506,9 @@ VkResult VmaDefragmentationAlgorithm_Generic::Defragment(
// Execute defragmentation rounds (the main part).
VkResult result = VK_SUCCESS;
- for (uint32_t round = 0; (round < roundCount) && (result == VK_SUCCESS); ++round) {
- result = DefragmentRound(moves, maxBytesToMove, maxAllocationsToMove);
+ for(uint32_t round = 0; (round < roundCount) && (result == VK_SUCCESS); ++round)
+ {
+ result = DefragmentRound(moves, maxBytesToMove, maxAllocationsToMove, !(flags & VMA_DEFRAGMENTATION_FLAG_INCREMENTAL));
}
return result;
@@ -11784,14 +13516,18 @@ VkResult VmaDefragmentationAlgorithm_Generic::Defragment(
bool VmaDefragmentationAlgorithm_Generic::MoveMakesSense(
size_t dstBlockIndex, VkDeviceSize dstOffset,
- size_t srcBlockIndex, VkDeviceSize srcOffset) {
- if (dstBlockIndex < srcBlockIndex) {
+ size_t srcBlockIndex, VkDeviceSize srcOffset)
+{
+ if(dstBlockIndex < srcBlockIndex)
+ {
return true;
}
- if (dstBlockIndex > srcBlockIndex) {
+ if(dstBlockIndex > srcBlockIndex)
+ {
return false;
}
- if (dstOffset < srcOffset) {
+ if(dstOffset < srcOffset)
+ {
return true;
}
return false;
@@ -11801,31 +13537,37 @@ bool VmaDefragmentationAlgorithm_Generic::MoveMakesSense(
// VmaDefragmentationAlgorithm_Fast
VmaDefragmentationAlgorithm_Fast::VmaDefragmentationAlgorithm_Fast(
- VmaAllocator hAllocator,
- VmaBlockVector *pBlockVector,
- uint32_t currentFrameIndex,
- bool overlappingMoveSupported) :
- VmaDefragmentationAlgorithm(hAllocator, pBlockVector, currentFrameIndex),
- m_OverlappingMoveSupported(overlappingMoveSupported),
- m_AllocationCount(0),
- m_AllAllocations(false),
- m_BytesMoved(0),
- m_AllocationsMoved(0),
- m_BlockInfos(VmaStlAllocator<BlockInfo>(hAllocator->GetAllocationCallbacks())) {
+ VmaAllocator hAllocator,
+ VmaBlockVector* pBlockVector,
+ uint32_t currentFrameIndex,
+ bool overlappingMoveSupported) :
+ VmaDefragmentationAlgorithm(hAllocator, pBlockVector, currentFrameIndex),
+ m_OverlappingMoveSupported(overlappingMoveSupported),
+ m_AllocationCount(0),
+ m_AllAllocations(false),
+ m_BytesMoved(0),
+ m_AllocationsMoved(0),
+ m_BlockInfos(VmaStlAllocator<BlockInfo>(hAllocator->GetAllocationCallbacks()))
+{
VMA_ASSERT(VMA_DEBUG_MARGIN == 0);
+
}
-VmaDefragmentationAlgorithm_Fast::~VmaDefragmentationAlgorithm_Fast() {
+VmaDefragmentationAlgorithm_Fast::~VmaDefragmentationAlgorithm_Fast()
+{
}
VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
- VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> > &moves,
- VkDeviceSize maxBytesToMove,
- uint32_t maxAllocationsToMove) {
+ VmaVector< VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove> >& moves,
+ VkDeviceSize maxBytesToMove,
+ uint32_t maxAllocationsToMove,
+ VmaDefragmentationFlags flags)
+{
VMA_ASSERT(m_AllAllocations || m_pBlockVector->CalcAllocationCount() == m_AllocationCount);
const size_t blockCount = m_pBlockVector->GetBlockCount();
- if (blockCount == 0 || maxBytesToMove == 0 || maxAllocationsToMove == 0) {
+ if(blockCount == 0 || maxBytesToMove == 0 || maxAllocationsToMove == 0)
+ {
return VK_SUCCESS;
}
@@ -11834,13 +13576,14 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
// Sort blocks in order from most destination.
m_BlockInfos.resize(blockCount);
- for (size_t i = 0; i < blockCount; ++i) {
+ for(size_t i = 0; i < blockCount; ++i)
+ {
m_BlockInfos[i].origBlockIndex = i;
}
- VMA_SORT(m_BlockInfos.begin(), m_BlockInfos.end(), [this](const BlockInfo &lhs, const BlockInfo &rhs) -> bool {
+ VMA_SORT(m_BlockInfos.begin(), m_BlockInfos.end(), [this](const BlockInfo& lhs, const BlockInfo& rhs) -> bool {
return m_pBlockVector->GetBlock(lhs.origBlockIndex)->m_pMetadata->GetSumFreeSize() <
- m_pBlockVector->GetBlock(rhs.origBlockIndex)->m_pMetadata->GetSumFreeSize();
+ m_pBlockVector->GetBlock(rhs.origBlockIndex)->m_pMetadata->GetSumFreeSize();
});
// THE MAIN ALGORITHM
@@ -11849,39 +13592,45 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
size_t dstBlockInfoIndex = 0;
size_t dstOrigBlockIndex = m_BlockInfos[dstBlockInfoIndex].origBlockIndex;
- VmaDeviceMemoryBlock *pDstBlock = m_pBlockVector->GetBlock(dstOrigBlockIndex);
- VmaBlockMetadata_Generic *pDstMetadata = (VmaBlockMetadata_Generic *)pDstBlock->m_pMetadata;
+ VmaDeviceMemoryBlock* pDstBlock = m_pBlockVector->GetBlock(dstOrigBlockIndex);
+ VmaBlockMetadata_Generic* pDstMetadata = (VmaBlockMetadata_Generic*)pDstBlock->m_pMetadata;
VkDeviceSize dstBlockSize = pDstMetadata->GetSize();
VkDeviceSize dstOffset = 0;
bool end = false;
- for (size_t srcBlockInfoIndex = 0; !end && srcBlockInfoIndex < blockCount; ++srcBlockInfoIndex) {
+ for(size_t srcBlockInfoIndex = 0; !end && srcBlockInfoIndex < blockCount; ++srcBlockInfoIndex)
+ {
const size_t srcOrigBlockIndex = m_BlockInfos[srcBlockInfoIndex].origBlockIndex;
- VmaDeviceMemoryBlock *const pSrcBlock = m_pBlockVector->GetBlock(srcOrigBlockIndex);
- VmaBlockMetadata_Generic *const pSrcMetadata = (VmaBlockMetadata_Generic *)pSrcBlock->m_pMetadata;
- for (VmaSuballocationList::iterator srcSuballocIt = pSrcMetadata->m_Suballocations.begin();
- !end && srcSuballocIt != pSrcMetadata->m_Suballocations.end();) {
- VmaAllocation_T *const pAlloc = srcSuballocIt->hAllocation;
+ VmaDeviceMemoryBlock* const pSrcBlock = m_pBlockVector->GetBlock(srcOrigBlockIndex);
+ VmaBlockMetadata_Generic* const pSrcMetadata = (VmaBlockMetadata_Generic*)pSrcBlock->m_pMetadata;
+ for(VmaSuballocationList::iterator srcSuballocIt = pSrcMetadata->m_Suballocations.begin();
+ !end && srcSuballocIt != pSrcMetadata->m_Suballocations.end(); )
+ {
+ VmaAllocation_T* const pAlloc = srcSuballocIt->hAllocation;
const VkDeviceSize srcAllocAlignment = pAlloc->GetAlignment();
const VkDeviceSize srcAllocSize = srcSuballocIt->size;
- if (m_AllocationsMoved == maxAllocationsToMove ||
- m_BytesMoved + srcAllocSize > maxBytesToMove) {
+ if(m_AllocationsMoved == maxAllocationsToMove ||
+ m_BytesMoved + srcAllocSize > maxBytesToMove)
+ {
end = true;
break;
}
const VkDeviceSize srcAllocOffset = srcSuballocIt->offset;
+ VmaDefragmentationMove move = {};
// Try to place it in one of free spaces from the database.
size_t freeSpaceInfoIndex;
VkDeviceSize dstAllocOffset;
- if (freeSpaceDb.Fetch(srcAllocAlignment, srcAllocSize,
- freeSpaceInfoIndex, dstAllocOffset)) {
+ if(freeSpaceDb.Fetch(srcAllocAlignment, srcAllocSize,
+ freeSpaceInfoIndex, dstAllocOffset))
+ {
size_t freeSpaceOrigBlockIndex = m_BlockInfos[freeSpaceInfoIndex].origBlockIndex;
- VmaDeviceMemoryBlock *pFreeSpaceBlock = m_pBlockVector->GetBlock(freeSpaceOrigBlockIndex);
- VmaBlockMetadata_Generic *pFreeSpaceMetadata = (VmaBlockMetadata_Generic *)pFreeSpaceBlock->m_pMetadata;
+ VmaDeviceMemoryBlock* pFreeSpaceBlock = m_pBlockVector->GetBlock(freeSpaceOrigBlockIndex);
+ VmaBlockMetadata_Generic* pFreeSpaceMetadata = (VmaBlockMetadata_Generic*)pFreeSpaceBlock->m_pMetadata;
// Same block
- if (freeSpaceInfoIndex == srcBlockInfoIndex) {
+ if(freeSpaceInfoIndex == srcBlockInfoIndex)
+ {
VMA_ASSERT(dstAllocOffset <= srcAllocOffset);
// MOVE OPTION 1: Move the allocation inside the same block by decreasing offset.
@@ -11891,7 +13640,7 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
suballoc.hAllocation->ChangeOffset(dstAllocOffset);
m_BytesMoved += srcAllocSize;
++m_AllocationsMoved;
-
+
VmaSuballocationList::iterator nextSuballocIt = srcSuballocIt;
++nextSuballocIt;
pSrcMetadata->m_Suballocations.erase(srcSuballocIt);
@@ -11899,15 +13648,17 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
InsertSuballoc(pFreeSpaceMetadata, suballoc);
- VmaDefragmentationMove move = {
- srcOrigBlockIndex, freeSpaceOrigBlockIndex,
- srcAllocOffset, dstAllocOffset,
- srcAllocSize
- };
+ move.srcBlockIndex = srcOrigBlockIndex;
+ move.dstBlockIndex = freeSpaceOrigBlockIndex;
+ move.srcOffset = srcAllocOffset;
+ move.dstOffset = dstAllocOffset;
+ move.size = srcAllocSize;
+
moves.push_back(move);
}
// Different block
- else {
+ else
+ {
// MOVE OPTION 2: Move the allocation to a different block.
VMA_ASSERT(freeSpaceInfoIndex < srcBlockInfoIndex);
@@ -11925,68 +13676,79 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
InsertSuballoc(pFreeSpaceMetadata, suballoc);
- VmaDefragmentationMove move = {
- srcOrigBlockIndex, freeSpaceOrigBlockIndex,
- srcAllocOffset, dstAllocOffset,
- srcAllocSize
- };
+ move.srcBlockIndex = srcOrigBlockIndex;
+ move.dstBlockIndex = freeSpaceOrigBlockIndex;
+ move.srcOffset = srcAllocOffset;
+ move.dstOffset = dstAllocOffset;
+ move.size = srcAllocSize;
+
moves.push_back(move);
}
- } else {
+ }
+ else
+ {
dstAllocOffset = VmaAlignUp(dstOffset, srcAllocAlignment);
// If the allocation doesn't fit before the end of dstBlock, forward to next block.
- while (dstBlockInfoIndex < srcBlockInfoIndex &&
- dstAllocOffset + srcAllocSize > dstBlockSize) {
+ while(dstBlockInfoIndex < srcBlockInfoIndex &&
+ dstAllocOffset + srcAllocSize > dstBlockSize)
+ {
// But before that, register remaining free space at the end of dst block.
freeSpaceDb.Register(dstBlockInfoIndex, dstOffset, dstBlockSize - dstOffset);
++dstBlockInfoIndex;
dstOrigBlockIndex = m_BlockInfos[dstBlockInfoIndex].origBlockIndex;
pDstBlock = m_pBlockVector->GetBlock(dstOrigBlockIndex);
- pDstMetadata = (VmaBlockMetadata_Generic *)pDstBlock->m_pMetadata;
+ pDstMetadata = (VmaBlockMetadata_Generic*)pDstBlock->m_pMetadata;
dstBlockSize = pDstMetadata->GetSize();
dstOffset = 0;
dstAllocOffset = 0;
}
// Same block
- if (dstBlockInfoIndex == srcBlockInfoIndex) {
+ if(dstBlockInfoIndex == srcBlockInfoIndex)
+ {
VMA_ASSERT(dstAllocOffset <= srcAllocOffset);
const bool overlap = dstAllocOffset + srcAllocSize > srcAllocOffset;
bool skipOver = overlap;
- if (overlap && m_OverlappingMoveSupported && dstAllocOffset < srcAllocOffset) {
+ if(overlap && m_OverlappingMoveSupported && dstAllocOffset < srcAllocOffset)
+ {
// If destination and source place overlap, skip if it would move it
// by only < 1/64 of its size.
skipOver = (srcAllocOffset - dstAllocOffset) * 64 < srcAllocSize;
}
- if (skipOver) {
+ if(skipOver)
+ {
freeSpaceDb.Register(dstBlockInfoIndex, dstOffset, srcAllocOffset - dstOffset);
dstOffset = srcAllocOffset + srcAllocSize;
++srcSuballocIt;
}
// MOVE OPTION 1: Move the allocation inside the same block by decreasing offset.
- else {
+ else
+ {
srcSuballocIt->offset = dstAllocOffset;
srcSuballocIt->hAllocation->ChangeOffset(dstAllocOffset);
dstOffset = dstAllocOffset + srcAllocSize;
m_BytesMoved += srcAllocSize;
++m_AllocationsMoved;
++srcSuballocIt;
- VmaDefragmentationMove move = {
- srcOrigBlockIndex, dstOrigBlockIndex,
- srcAllocOffset, dstAllocOffset,
- srcAllocSize
- };
+
+ move.srcBlockIndex = srcOrigBlockIndex;
+ move.dstBlockIndex = dstOrigBlockIndex;
+ move.srcOffset = srcAllocOffset;
+ move.dstOffset = dstAllocOffset;
+ move.size = srcAllocSize;
+
moves.push_back(move);
}
}
// Different block
- else {
+ else
+ {
// MOVE OPTION 2: Move the allocation to a different block.
VMA_ASSERT(dstBlockInfoIndex < srcBlockInfoIndex);
@@ -12006,11 +13768,12 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
pDstMetadata->m_Suballocations.push_back(suballoc);
- VmaDefragmentationMove move = {
- srcOrigBlockIndex, dstOrigBlockIndex,
- srcAllocOffset, dstAllocOffset,
- srcAllocSize
- };
+ move.srcBlockIndex = srcOrigBlockIndex;
+ move.dstBlockIndex = dstOrigBlockIndex;
+ move.srcOffset = srcAllocOffset;
+ move.dstOffset = dstAllocOffset;
+ move.size = srcAllocSize;
+
moves.push_back(move);
}
}
@@ -12018,76 +13781,87 @@ VkResult VmaDefragmentationAlgorithm_Fast::Defragment(
}
m_BlockInfos.clear();
-
+
PostprocessMetadata();
return VK_SUCCESS;
}
-void VmaDefragmentationAlgorithm_Fast::PreprocessMetadata() {
+void VmaDefragmentationAlgorithm_Fast::PreprocessMetadata()
+{
const size_t blockCount = m_pBlockVector->GetBlockCount();
- for (size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex) {
- VmaBlockMetadata_Generic *const pMetadata =
- (VmaBlockMetadata_Generic *)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
+ for(size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+ {
+ VmaBlockMetadata_Generic* const pMetadata =
+ (VmaBlockMetadata_Generic*)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
pMetadata->m_FreeCount = 0;
pMetadata->m_SumFreeSize = pMetadata->GetSize();
pMetadata->m_FreeSuballocationsBySize.clear();
- for (VmaSuballocationList::iterator it = pMetadata->m_Suballocations.begin();
- it != pMetadata->m_Suballocations.end();) {
- if (it->type == VMA_SUBALLOCATION_TYPE_FREE) {
+ for(VmaSuballocationList::iterator it = pMetadata->m_Suballocations.begin();
+ it != pMetadata->m_Suballocations.end(); )
+ {
+ if(it->type == VMA_SUBALLOCATION_TYPE_FREE)
+ {
VmaSuballocationList::iterator nextIt = it;
++nextIt;
pMetadata->m_Suballocations.erase(it);
it = nextIt;
- } else {
+ }
+ else
+ {
++it;
}
}
}
}
-void VmaDefragmentationAlgorithm_Fast::PostprocessMetadata() {
+void VmaDefragmentationAlgorithm_Fast::PostprocessMetadata()
+{
const size_t blockCount = m_pBlockVector->GetBlockCount();
- for (size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex) {
- VmaBlockMetadata_Generic *const pMetadata =
- (VmaBlockMetadata_Generic *)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
+ for(size_t blockIndex = 0; blockIndex < blockCount; ++blockIndex)
+ {
+ VmaBlockMetadata_Generic* const pMetadata =
+ (VmaBlockMetadata_Generic*)m_pBlockVector->GetBlock(blockIndex)->m_pMetadata;
const VkDeviceSize blockSize = pMetadata->GetSize();
-
+
// No allocations in this block - entire area is free.
- if (pMetadata->m_Suballocations.empty()) {
+ if(pMetadata->m_Suballocations.empty())
+ {
pMetadata->m_FreeCount = 1;
//pMetadata->m_SumFreeSize is already set to blockSize.
VmaSuballocation suballoc = {
0, // offset
blockSize, // size
VMA_NULL, // hAllocation
- VMA_SUBALLOCATION_TYPE_FREE
- };
+ VMA_SUBALLOCATION_TYPE_FREE };
pMetadata->m_Suballocations.push_back(suballoc);
pMetadata->RegisterFreeSuballocation(pMetadata->m_Suballocations.begin());
}
// There are some allocations in this block.
- else {
+ else
+ {
VkDeviceSize offset = 0;
VmaSuballocationList::iterator it;
- for (it = pMetadata->m_Suballocations.begin();
- it != pMetadata->m_Suballocations.end();
- ++it) {
+ for(it = pMetadata->m_Suballocations.begin();
+ it != pMetadata->m_Suballocations.end();
+ ++it)
+ {
VMA_ASSERT(it->type != VMA_SUBALLOCATION_TYPE_FREE);
VMA_ASSERT(it->offset >= offset);
// Need to insert preceding free space.
- if (it->offset > offset) {
+ if(it->offset > offset)
+ {
++pMetadata->m_FreeCount;
const VkDeviceSize freeSize = it->offset - offset;
VmaSuballocation suballoc = {
offset, // offset
freeSize, // size
VMA_NULL, // hAllocation
- VMA_SUBALLOCATION_TYPE_FREE
- };
+ VMA_SUBALLOCATION_TYPE_FREE };
VmaSuballocationList::iterator precedingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);
- if (freeSize >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER) {
+ if(freeSize >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+ {
pMetadata->m_FreeSuballocationsBySize.push_back(precedingFreeIt);
}
}
@@ -12097,37 +13871,41 @@ void VmaDefragmentationAlgorithm_Fast::PostprocessMetadata() {
}
// Need to insert trailing free space.
- if (offset < blockSize) {
+ if(offset < blockSize)
+ {
++pMetadata->m_FreeCount;
const VkDeviceSize freeSize = blockSize - offset;
VmaSuballocation suballoc = {
offset, // offset
freeSize, // size
VMA_NULL, // hAllocation
- VMA_SUBALLOCATION_TYPE_FREE
- };
+ VMA_SUBALLOCATION_TYPE_FREE };
VMA_ASSERT(it == pMetadata->m_Suballocations.end());
VmaSuballocationList::iterator trailingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);
- if (freeSize > VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER) {
+ if(freeSize > VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)
+ {
pMetadata->m_FreeSuballocationsBySize.push_back(trailingFreeIt);
}
}
VMA_SORT(
- pMetadata->m_FreeSuballocationsBySize.begin(),
- pMetadata->m_FreeSuballocationsBySize.end(),
- VmaSuballocationItemSizeLess());
+ pMetadata->m_FreeSuballocationsBySize.begin(),
+ pMetadata->m_FreeSuballocationsBySize.end(),
+ VmaSuballocationItemSizeLess());
}
VMA_HEAVY_ASSERT(pMetadata->Validate());
}
}
-void VmaDefragmentationAlgorithm_Fast::InsertSuballoc(VmaBlockMetadata_Generic *pMetadata, const VmaSuballocation &suballoc) {
+void VmaDefragmentationAlgorithm_Fast::InsertSuballoc(VmaBlockMetadata_Generic* pMetadata, const VmaSuballocation& suballoc)
+{
// TODO: Optimize somehow. Remember iterator instead of searching for it linearly.
VmaSuballocationList::iterator it = pMetadata->m_Suballocations.begin();
- while (it != pMetadata->m_Suballocations.end()) {
- if (it->offset < suballoc.offset) {
+ while(it != pMetadata->m_Suballocations.end())
+ {
+ if(it->offset < suballoc.offset)
+ {
++it;
}
}
@@ -12138,61 +13916,76 @@ void VmaDefragmentationAlgorithm_Fast::InsertSuballoc(VmaBlockMetadata_Generic *
// VmaBlockVectorDefragmentationContext
VmaBlockVectorDefragmentationContext::VmaBlockVectorDefragmentationContext(
- VmaAllocator hAllocator,
- VmaPool hCustomPool,
- VmaBlockVector *pBlockVector,
- uint32_t currFrameIndex,
- uint32_t algorithmFlags) :
- res(VK_SUCCESS),
- mutexLocked(false),
- blockContexts(VmaStlAllocator<VmaBlockDefragmentationContext>(hAllocator->GetAllocationCallbacks())),
- m_hAllocator(hAllocator),
- m_hCustomPool(hCustomPool),
- m_pBlockVector(pBlockVector),
- m_CurrFrameIndex(currFrameIndex),
- m_AlgorithmFlags(algorithmFlags),
- m_pAlgorithm(VMA_NULL),
- m_Allocations(VmaStlAllocator<AllocInfo>(hAllocator->GetAllocationCallbacks())),
- m_AllAllocations(false) {
+ VmaAllocator hAllocator,
+ VmaPool hCustomPool,
+ VmaBlockVector* pBlockVector,
+ uint32_t currFrameIndex) :
+ res(VK_SUCCESS),
+ mutexLocked(false),
+ blockContexts(VmaStlAllocator<VmaBlockDefragmentationContext>(hAllocator->GetAllocationCallbacks())),
+ defragmentationMoves(VmaStlAllocator<VmaDefragmentationMove>(hAllocator->GetAllocationCallbacks())),
+ defragmentationMovesProcessed(0),
+ defragmentationMovesCommitted(0),
+ hasDefragmentationPlan(0),
+ m_hAllocator(hAllocator),
+ m_hCustomPool(hCustomPool),
+ m_pBlockVector(pBlockVector),
+ m_CurrFrameIndex(currFrameIndex),
+ m_pAlgorithm(VMA_NULL),
+ m_Allocations(VmaStlAllocator<AllocInfo>(hAllocator->GetAllocationCallbacks())),
+ m_AllAllocations(false)
+{
}
-VmaBlockVectorDefragmentationContext::~VmaBlockVectorDefragmentationContext() {
+VmaBlockVectorDefragmentationContext::~VmaBlockVectorDefragmentationContext()
+{
vma_delete(m_hAllocator, m_pAlgorithm);
}
-void VmaBlockVectorDefragmentationContext::AddAllocation(VmaAllocation hAlloc, VkBool32 *pChanged) {
+void VmaBlockVectorDefragmentationContext::AddAllocation(VmaAllocation hAlloc, VkBool32* pChanged)
+{
AllocInfo info = { hAlloc, pChanged };
m_Allocations.push_back(info);
}
-void VmaBlockVectorDefragmentationContext::Begin(bool overlappingMoveSupported) {
+void VmaBlockVectorDefragmentationContext::Begin(bool overlappingMoveSupported, VmaDefragmentationFlags flags)
+{
const bool allAllocations = m_AllAllocations ||
- m_Allocations.size() == m_pBlockVector->CalcAllocationCount();
+ m_Allocations.size() == m_pBlockVector->CalcAllocationCount();
/********************************
- HERE IS THE CHOICE OF DEFRAGMENTATION ALGORITHM.
- ********************************/
+ HERE IS THE CHOICE OF DEFRAGMENTATION ALGORITHM.
+ ********************************/
/*
- Fast algorithm is supported only when certain criteria are met:
- - VMA_DEBUG_MARGIN is 0.
- - All allocations in this block vector are moveable.
- - There is no possibility of image/buffer granularity conflict.
- */
- if (VMA_DEBUG_MARGIN == 0 &&
- allAllocations &&
- !m_pBlockVector->IsBufferImageGranularityConflictPossible()) {
+ Fast algorithm is supported only when certain criteria are met:
+ - VMA_DEBUG_MARGIN is 0.
+ - All allocations in this block vector are moveable.
+ - There is no possibility of image/buffer granularity conflict.
+ - The defragmentation is not incremental
+ */
+ if(VMA_DEBUG_MARGIN == 0 &&
+ allAllocations &&
+ !m_pBlockVector->IsBufferImageGranularityConflictPossible() &&
+ !(flags & VMA_DEFRAGMENTATION_FLAG_INCREMENTAL))
+ {
m_pAlgorithm = vma_new(m_hAllocator, VmaDefragmentationAlgorithm_Fast)(
- m_hAllocator, m_pBlockVector, m_CurrFrameIndex, overlappingMoveSupported);
- } else {
+ m_hAllocator, m_pBlockVector, m_CurrFrameIndex, overlappingMoveSupported);
+ }
+ else
+ {
m_pAlgorithm = vma_new(m_hAllocator, VmaDefragmentationAlgorithm_Generic)(
- m_hAllocator, m_pBlockVector, m_CurrFrameIndex, overlappingMoveSupported);
+ m_hAllocator, m_pBlockVector, m_CurrFrameIndex, overlappingMoveSupported);
}
- if (allAllocations) {
+ if(allAllocations)
+ {
m_pAlgorithm->AddAll();
- } else {
- for (size_t i = 0, count = m_Allocations.size(); i < count; ++i) {
+ }
+ else
+ {
+ for(size_t i = 0, count = m_Allocations.size(); i < count; ++i)
+ {
m_pAlgorithm->AddAllocation(m_Allocations[i].hAlloc, m_Allocations[i].pChanged);
}
}
@@ -12202,55 +13995,65 @@ void VmaBlockVectorDefragmentationContext::Begin(bool overlappingMoveSupported)
// VmaDefragmentationContext
VmaDefragmentationContext_T::VmaDefragmentationContext_T(
- VmaAllocator hAllocator,
- uint32_t currFrameIndex,
- uint32_t flags,
- VmaDefragmentationStats *pStats) :
- m_hAllocator(hAllocator),
- m_CurrFrameIndex(currFrameIndex),
- m_Flags(flags),
- m_pStats(pStats),
- m_CustomPoolContexts(VmaStlAllocator<VmaBlockVectorDefragmentationContext *>(hAllocator->GetAllocationCallbacks())) {
+ VmaAllocator hAllocator,
+ uint32_t currFrameIndex,
+ uint32_t flags,
+ VmaDefragmentationStats* pStats) :
+ m_hAllocator(hAllocator),
+ m_CurrFrameIndex(currFrameIndex),
+ m_Flags(flags),
+ m_pStats(pStats),
+ m_CustomPoolContexts(VmaStlAllocator<VmaBlockVectorDefragmentationContext*>(hAllocator->GetAllocationCallbacks()))
+{
memset(m_DefaultPoolContexts, 0, sizeof(m_DefaultPoolContexts));
}
-VmaDefragmentationContext_T::~VmaDefragmentationContext_T() {
- for (size_t i = m_CustomPoolContexts.size(); i--;) {
- VmaBlockVectorDefragmentationContext *pBlockVectorCtx = m_CustomPoolContexts[i];
+VmaDefragmentationContext_T::~VmaDefragmentationContext_T()
+{
+ for(size_t i = m_CustomPoolContexts.size(); i--; )
+ {
+ VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_CustomPoolContexts[i];
pBlockVectorCtx->GetBlockVector()->DefragmentationEnd(pBlockVectorCtx, m_pStats);
vma_delete(m_hAllocator, pBlockVectorCtx);
}
- for (size_t i = m_hAllocator->m_MemProps.memoryTypeCount; i--;) {
- VmaBlockVectorDefragmentationContext *pBlockVectorCtx = m_DefaultPoolContexts[i];
- if (pBlockVectorCtx) {
+ for(size_t i = m_hAllocator->m_MemProps.memoryTypeCount; i--; )
+ {
+ VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_DefaultPoolContexts[i];
+ if(pBlockVectorCtx)
+ {
pBlockVectorCtx->GetBlockVector()->DefragmentationEnd(pBlockVectorCtx, m_pStats);
vma_delete(m_hAllocator, pBlockVectorCtx);
}
}
}
-void VmaDefragmentationContext_T::AddPools(uint32_t poolCount, VmaPool *pPools) {
- for (uint32_t poolIndex = 0; poolIndex < poolCount; ++poolIndex) {
+void VmaDefragmentationContext_T::AddPools(uint32_t poolCount, VmaPool* pPools)
+{
+ for(uint32_t poolIndex = 0; poolIndex < poolCount; ++poolIndex)
+ {
VmaPool pool = pPools[poolIndex];
VMA_ASSERT(pool);
// Pools with algorithm other than default are not defragmented.
- if (pool->m_BlockVector.GetAlgorithm() == 0) {
- VmaBlockVectorDefragmentationContext *pBlockVectorDefragCtx = VMA_NULL;
-
- for (size_t i = m_CustomPoolContexts.size(); i--;) {
- if (m_CustomPoolContexts[i]->GetCustomPool() == pool) {
+ if(pool->m_BlockVector.GetAlgorithm() == 0)
+ {
+ VmaBlockVectorDefragmentationContext* pBlockVectorDefragCtx = VMA_NULL;
+
+ for(size_t i = m_CustomPoolContexts.size(); i--; )
+ {
+ if(m_CustomPoolContexts[i]->GetCustomPool() == pool)
+ {
pBlockVectorDefragCtx = m_CustomPoolContexts[i];
break;
}
}
-
- if (!pBlockVectorDefragCtx) {
+
+ if(!pBlockVectorDefragCtx)
+ {
pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
- m_hAllocator,
- pool,
- &pool->m_BlockVector,
- m_CurrFrameIndex,
- m_Flags);
+ m_hAllocator,
+ pool,
+ &pool->m_BlockVector,
+ m_CurrFrameIndex);
m_CustomPoolContexts.push_back(pBlockVectorDefragCtx);
}
@@ -12260,60 +14063,68 @@ void VmaDefragmentationContext_T::AddPools(uint32_t poolCount, VmaPool *pPools)
}
void VmaDefragmentationContext_T::AddAllocations(
- uint32_t allocationCount,
- VmaAllocation *pAllocations,
- VkBool32 *pAllocationsChanged) {
+ uint32_t allocationCount,
+ VmaAllocation* pAllocations,
+ VkBool32* pAllocationsChanged)
+{
// Dispatch pAllocations among defragmentators. Create them when necessary.
- for (uint32_t allocIndex = 0; allocIndex < allocationCount; ++allocIndex) {
+ for(uint32_t allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
+ {
const VmaAllocation hAlloc = pAllocations[allocIndex];
VMA_ASSERT(hAlloc);
// DedicatedAlloc cannot be defragmented.
- if ((hAlloc->GetType() == VmaAllocation_T::ALLOCATION_TYPE_BLOCK) &&
- // Lost allocation cannot be defragmented.
- (hAlloc->GetLastUseFrameIndex() != VMA_FRAME_INDEX_LOST)) {
- VmaBlockVectorDefragmentationContext *pBlockVectorDefragCtx = VMA_NULL;
+ if((hAlloc->GetType() == VmaAllocation_T::ALLOCATION_TYPE_BLOCK) &&
+ // Lost allocation cannot be defragmented.
+ (hAlloc->GetLastUseFrameIndex() != VMA_FRAME_INDEX_LOST))
+ {
+ VmaBlockVectorDefragmentationContext* pBlockVectorDefragCtx = VMA_NULL;
const VmaPool hAllocPool = hAlloc->GetBlock()->GetParentPool();
// This allocation belongs to custom pool.
- if (hAllocPool != VK_NULL_HANDLE) {
+ if(hAllocPool != VK_NULL_HANDLE)
+ {
// Pools with algorithm other than default are not defragmented.
- if (hAllocPool->m_BlockVector.GetAlgorithm() == 0) {
- for (size_t i = m_CustomPoolContexts.size(); i--;) {
- if (m_CustomPoolContexts[i]->GetCustomPool() == hAllocPool) {
+ if(hAllocPool->m_BlockVector.GetAlgorithm() == 0)
+ {
+ for(size_t i = m_CustomPoolContexts.size(); i--; )
+ {
+ if(m_CustomPoolContexts[i]->GetCustomPool() == hAllocPool)
+ {
pBlockVectorDefragCtx = m_CustomPoolContexts[i];
break;
}
}
- if (!pBlockVectorDefragCtx) {
+ if(!pBlockVectorDefragCtx)
+ {
pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
- m_hAllocator,
- hAllocPool,
- &hAllocPool->m_BlockVector,
- m_CurrFrameIndex,
- m_Flags);
+ m_hAllocator,
+ hAllocPool,
+ &hAllocPool->m_BlockVector,
+ m_CurrFrameIndex);
m_CustomPoolContexts.push_back(pBlockVectorDefragCtx);
}
}
}
// This allocation belongs to default pool.
- else {
+ else
+ {
const uint32_t memTypeIndex = hAlloc->GetMemoryTypeIndex();
pBlockVectorDefragCtx = m_DefaultPoolContexts[memTypeIndex];
- if (!pBlockVectorDefragCtx) {
+ if(!pBlockVectorDefragCtx)
+ {
pBlockVectorDefragCtx = vma_new(m_hAllocator, VmaBlockVectorDefragmentationContext)(
- m_hAllocator,
- VMA_NULL, // hCustomPool
- m_hAllocator->m_pBlockVectors[memTypeIndex],
- m_CurrFrameIndex,
- m_Flags);
+ m_hAllocator,
+ VMA_NULL, // hCustomPool
+ m_hAllocator->m_pBlockVectors[memTypeIndex],
+ m_CurrFrameIndex);
m_DefaultPoolContexts[memTypeIndex] = pBlockVectorDefragCtx;
}
}
- if (pBlockVectorDefragCtx) {
- VkBool32 *const pChanged = (pAllocationsChanged != VMA_NULL) ?
- &pAllocationsChanged[allocIndex] :
- VMA_NULL;
+ if(pBlockVectorDefragCtx)
+ {
+ VkBool32* const pChanged = (pAllocationsChanged != VMA_NULL) ?
+ &pAllocationsChanged[allocIndex] : VMA_NULL;
pBlockVectorDefragCtx->AddAllocation(hAlloc, pChanged);
}
}
@@ -12321,14 +14132,34 @@ void VmaDefragmentationContext_T::AddAllocations(
}
VkResult VmaDefragmentationContext_T::Defragment(
- VkDeviceSize maxCpuBytesToMove, uint32_t maxCpuAllocationsToMove,
- VkDeviceSize maxGpuBytesToMove, uint32_t maxGpuAllocationsToMove,
- VkCommandBuffer commandBuffer, VmaDefragmentationStats *pStats) {
- if (pStats) {
+ VkDeviceSize maxCpuBytesToMove, uint32_t maxCpuAllocationsToMove,
+ VkDeviceSize maxGpuBytesToMove, uint32_t maxGpuAllocationsToMove,
+ VkCommandBuffer commandBuffer, VmaDefragmentationStats* pStats, VmaDefragmentationFlags flags)
+{
+ if(pStats)
+ {
memset(pStats, 0, sizeof(VmaDefragmentationStats));
}
- if (commandBuffer == VK_NULL_HANDLE) {
+ if(flags & VMA_DEFRAGMENTATION_FLAG_INCREMENTAL)
+ {
+ // For incremental defragmetnations, we just earmark how much we can move
+ // The real meat is in the defragmentation steps
+ m_MaxCpuBytesToMove = maxCpuBytesToMove;
+ m_MaxCpuAllocationsToMove = maxCpuAllocationsToMove;
+
+ m_MaxGpuBytesToMove = maxGpuBytesToMove;
+ m_MaxGpuAllocationsToMove = maxGpuAllocationsToMove;
+
+ if(m_MaxCpuBytesToMove == 0 && m_MaxCpuAllocationsToMove == 0 &&
+ m_MaxGpuBytesToMove == 0 && m_MaxGpuAllocationsToMove == 0)
+ return VK_SUCCESS;
+
+ return VK_NOT_READY;
+ }
+
+ if(commandBuffer == VK_NULL_HANDLE)
+ {
maxGpuBytesToMove = 0;
maxGpuAllocationsToMove = 0;
}
@@ -12336,37 +14167,42 @@ VkResult VmaDefragmentationContext_T::Defragment(
VkResult res = VK_SUCCESS;
// Process default pools.
- for (uint32_t memTypeIndex = 0;
- memTypeIndex < m_hAllocator->GetMemoryTypeCount() && res >= VK_SUCCESS;
- ++memTypeIndex) {
- VmaBlockVectorDefragmentationContext *pBlockVectorCtx = m_DefaultPoolContexts[memTypeIndex];
- if (pBlockVectorCtx) {
+ for(uint32_t memTypeIndex = 0;
+ memTypeIndex < m_hAllocator->GetMemoryTypeCount() && res >= VK_SUCCESS;
+ ++memTypeIndex)
+ {
+ VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_DefaultPoolContexts[memTypeIndex];
+ if(pBlockVectorCtx)
+ {
VMA_ASSERT(pBlockVectorCtx->GetBlockVector());
pBlockVectorCtx->GetBlockVector()->Defragment(
- pBlockVectorCtx,
- pStats,
- maxCpuBytesToMove, maxCpuAllocationsToMove,
- maxGpuBytesToMove, maxGpuAllocationsToMove,
- commandBuffer);
- if (pBlockVectorCtx->res != VK_SUCCESS) {
+ pBlockVectorCtx,
+ pStats, flags,
+ maxCpuBytesToMove, maxCpuAllocationsToMove,
+ maxGpuBytesToMove, maxGpuAllocationsToMove,
+ commandBuffer);
+ if(pBlockVectorCtx->res != VK_SUCCESS)
+ {
res = pBlockVectorCtx->res;
}
}
}
// Process custom pools.
- for (size_t customCtxIndex = 0, customCtxCount = m_CustomPoolContexts.size();
- customCtxIndex < customCtxCount && res >= VK_SUCCESS;
- ++customCtxIndex) {
- VmaBlockVectorDefragmentationContext *pBlockVectorCtx = m_CustomPoolContexts[customCtxIndex];
+ for(size_t customCtxIndex = 0, customCtxCount = m_CustomPoolContexts.size();
+ customCtxIndex < customCtxCount && res >= VK_SUCCESS;
+ ++customCtxIndex)
+ {
+ VmaBlockVectorDefragmentationContext* pBlockVectorCtx = m_CustomPoolContexts[customCtxIndex];
VMA_ASSERT(pBlockVectorCtx && pBlockVectorCtx->GetBlockVector());
pBlockVectorCtx->GetBlockVector()->Defragment(
- pBlockVectorCtx,
- pStats,
- maxCpuBytesToMove, maxCpuAllocationsToMove,
- maxGpuBytesToMove, maxGpuAllocationsToMove,
- commandBuffer);
- if (pBlockVectorCtx->res != VK_SUCCESS) {
+ pBlockVectorCtx,
+ pStats, flags,
+ maxCpuBytesToMove, maxCpuAllocationsToMove,
+ maxGpuBytesToMove, maxGpuAllocationsToMove,
+ commandBuffer);
+ if(pBlockVectorCtx->res != VK_SUCCESS)
+ {
res = pBlockVectorCtx->res;
}
}
@@ -12374,46 +14210,178 @@ VkResult VmaDefragmentationContext_T::Defragment(
return res;
}
+VkResult VmaDefragmentationContext_T::DefragmentPassBegin(VmaDefragmentationPassInfo* pInfo)
+{
+ VmaDefragmentationPassMoveInfo* pCurrentMove = pInfo->pMoves;
+ uint32_t movesLeft = pInfo->moveCount;
+
+ // Process default pools.
+ for(uint32_t memTypeIndex = 0;
+ memTypeIndex < m_hAllocator->GetMemoryTypeCount();
+ ++memTypeIndex)
+ {
+ VmaBlockVectorDefragmentationContext *pBlockVectorCtx = m_DefaultPoolContexts[memTypeIndex];
+ if(pBlockVectorCtx)
+ {
+ VMA_ASSERT(pBlockVectorCtx->GetBlockVector());
+
+ if(!pBlockVectorCtx->hasDefragmentationPlan)
+ {
+ pBlockVectorCtx->GetBlockVector()->Defragment(
+ pBlockVectorCtx,
+ m_pStats, m_Flags,
+ m_MaxCpuBytesToMove, m_MaxCpuAllocationsToMove,
+ m_MaxGpuBytesToMove, m_MaxGpuAllocationsToMove,
+ VK_NULL_HANDLE);
+
+ if(pBlockVectorCtx->res < VK_SUCCESS)
+ continue;
+
+ pBlockVectorCtx->hasDefragmentationPlan = true;
+ }
+
+ const uint32_t processed = pBlockVectorCtx->GetBlockVector()->ProcessDefragmentations(
+ pBlockVectorCtx,
+ pCurrentMove, movesLeft);
+
+ movesLeft -= processed;
+ pCurrentMove += processed;
+ }
+ }
+
+ // Process custom pools.
+ for(size_t customCtxIndex = 0, customCtxCount = m_CustomPoolContexts.size();
+ customCtxIndex < customCtxCount;
+ ++customCtxIndex)
+ {
+ VmaBlockVectorDefragmentationContext *pBlockVectorCtx = m_CustomPoolContexts[customCtxIndex];
+ VMA_ASSERT(pBlockVectorCtx && pBlockVectorCtx->GetBlockVector());
+
+ if(!pBlockVectorCtx->hasDefragmentationPlan)
+ {
+ pBlockVectorCtx->GetBlockVector()->Defragment(
+ pBlockVectorCtx,
+ m_pStats, m_Flags,
+ m_MaxCpuBytesToMove, m_MaxCpuAllocationsToMove,
+ m_MaxGpuBytesToMove, m_MaxGpuAllocationsToMove,
+ VK_NULL_HANDLE);
+
+ if(pBlockVectorCtx->res < VK_SUCCESS)
+ continue;
+
+ pBlockVectorCtx->hasDefragmentationPlan = true;
+ }
+
+ const uint32_t processed = pBlockVectorCtx->GetBlockVector()->ProcessDefragmentations(
+ pBlockVectorCtx,
+ pCurrentMove, movesLeft);
+
+ movesLeft -= processed;
+ pCurrentMove += processed;
+ }
+
+ pInfo->moveCount = pInfo->moveCount - movesLeft;
+
+ return VK_SUCCESS;
+}
+VkResult VmaDefragmentationContext_T::DefragmentPassEnd()
+{
+ VkResult res = VK_SUCCESS;
+
+ // Process default pools.
+ for(uint32_t memTypeIndex = 0;
+ memTypeIndex < m_hAllocator->GetMemoryTypeCount();
+ ++memTypeIndex)
+ {
+ VmaBlockVectorDefragmentationContext *pBlockVectorCtx = m_DefaultPoolContexts[memTypeIndex];
+ if(pBlockVectorCtx)
+ {
+ VMA_ASSERT(pBlockVectorCtx->GetBlockVector());
+
+ if(!pBlockVectorCtx->hasDefragmentationPlan)
+ {
+ res = VK_NOT_READY;
+ continue;
+ }
+
+ pBlockVectorCtx->GetBlockVector()->CommitDefragmentations(
+ pBlockVectorCtx, m_pStats);
+
+ if(pBlockVectorCtx->defragmentationMoves.size() != pBlockVectorCtx->defragmentationMovesCommitted)
+ res = VK_NOT_READY;
+ }
+ }
+
+ // Process custom pools.
+ for(size_t customCtxIndex = 0, customCtxCount = m_CustomPoolContexts.size();
+ customCtxIndex < customCtxCount;
+ ++customCtxIndex)
+ {
+ VmaBlockVectorDefragmentationContext *pBlockVectorCtx = m_CustomPoolContexts[customCtxIndex];
+ VMA_ASSERT(pBlockVectorCtx && pBlockVectorCtx->GetBlockVector());
+
+ if(!pBlockVectorCtx->hasDefragmentationPlan)
+ {
+ res = VK_NOT_READY;
+ continue;
+ }
+
+ pBlockVectorCtx->GetBlockVector()->CommitDefragmentations(
+ pBlockVectorCtx, m_pStats);
+
+ if(pBlockVectorCtx->defragmentationMoves.size() != pBlockVectorCtx->defragmentationMovesCommitted)
+ res = VK_NOT_READY;
+ }
+
+ return res;
+}
+
////////////////////////////////////////////////////////////////////////////////
// VmaRecorder
#if VMA_RECORDING_ENABLED
VmaRecorder::VmaRecorder() :
- m_UseMutex(true),
- m_Flags(0),
- m_File(VMA_NULL),
- m_Freq(INT64_MAX),
- m_StartCounter(INT64_MAX) {
+ m_UseMutex(true),
+ m_Flags(0),
+ m_File(VMA_NULL),
+ m_Freq(INT64_MAX),
+ m_StartCounter(INT64_MAX)
+{
}
-VkResult VmaRecorder::Init(const VmaRecordSettings &settings, bool useMutex) {
+VkResult VmaRecorder::Init(const VmaRecordSettings& settings, bool useMutex)
+{
m_UseMutex = useMutex;
m_Flags = settings.flags;
- QueryPerformanceFrequency((LARGE_INTEGER *)&m_Freq);
- QueryPerformanceCounter((LARGE_INTEGER *)&m_StartCounter);
+ QueryPerformanceFrequency((LARGE_INTEGER*)&m_Freq);
+ QueryPerformanceCounter((LARGE_INTEGER*)&m_StartCounter);
// Open file for writing.
errno_t err = fopen_s(&m_File, settings.pFilePath, "wb");
- if (err != 0) {
+ if(err != 0)
+ {
return VK_ERROR_INITIALIZATION_FAILED;
}
// Write header.
fprintf(m_File, "%s\n", "Vulkan Memory Allocator,Calls recording");
- fprintf(m_File, "%s\n", "1,5");
+ fprintf(m_File, "%s\n", "1,8");
return VK_SUCCESS;
}
-VmaRecorder::~VmaRecorder() {
- if (m_File != VMA_NULL) {
+VmaRecorder::~VmaRecorder()
+{
+ if(m_File != VMA_NULL)
+ {
fclose(m_File);
}
}
-void VmaRecorder::RecordCreateAllocator(uint32_t frameIndex) {
+void VmaRecorder::RecordCreateAllocator(uint32_t frameIndex)
+{
CallParams callParams;
GetBasicParams(callParams);
@@ -12422,7 +14390,8 @@ void VmaRecorder::RecordCreateAllocator(uint32_t frameIndex) {
Flush();
}
-void VmaRecorder::RecordDestroyAllocator(uint32_t frameIndex) {
+void VmaRecorder::RecordDestroyAllocator(uint32_t frameIndex)
+{
CallParams callParams;
GetBasicParams(callParams);
@@ -12431,151 +14400,159 @@ void VmaRecorder::RecordDestroyAllocator(uint32_t frameIndex) {
Flush();
}
-void VmaRecorder::RecordCreatePool(uint32_t frameIndex, const VmaPoolCreateInfo &createInfo, VmaPool pool) {
+void VmaRecorder::RecordCreatePool(uint32_t frameIndex, const VmaPoolCreateInfo& createInfo, VmaPool pool)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaCreatePool,%u,%u,%llu,%llu,%llu,%u,%p\n", callParams.threadId, callParams.time, frameIndex,
- createInfo.memoryTypeIndex,
- createInfo.flags,
- createInfo.blockSize,
- (uint64_t)createInfo.minBlockCount,
- (uint64_t)createInfo.maxBlockCount,
- createInfo.frameInUseCount,
- pool);
+ createInfo.memoryTypeIndex,
+ createInfo.flags,
+ createInfo.blockSize,
+ (uint64_t)createInfo.minBlockCount,
+ (uint64_t)createInfo.maxBlockCount,
+ createInfo.frameInUseCount,
+ pool);
Flush();
}
-void VmaRecorder::RecordDestroyPool(uint32_t frameIndex, VmaPool pool) {
+void VmaRecorder::RecordDestroyPool(uint32_t frameIndex, VmaPool pool)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaDestroyPool,%p\n", callParams.threadId, callParams.time, frameIndex,
- pool);
+ pool);
Flush();
}
void VmaRecorder::RecordAllocateMemory(uint32_t frameIndex,
- const VkMemoryRequirements &vkMemReq,
- const VmaAllocationCreateInfo &createInfo,
- VmaAllocation allocation) {
+ const VkMemoryRequirements& vkMemReq,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
UserDataString userDataStr(createInfo.flags, createInfo.pUserData);
fprintf(m_File, "%u,%.3f,%u,vmaAllocateMemory,%llu,%llu,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
- vkMemReq.size,
- vkMemReq.alignment,
- vkMemReq.memoryTypeBits,
- createInfo.flags,
- createInfo.usage,
- createInfo.requiredFlags,
- createInfo.preferredFlags,
- createInfo.memoryTypeBits,
- createInfo.pool,
- allocation,
- userDataStr.GetString());
+ vkMemReq.size,
+ vkMemReq.alignment,
+ vkMemReq.memoryTypeBits,
+ createInfo.flags,
+ createInfo.usage,
+ createInfo.requiredFlags,
+ createInfo.preferredFlags,
+ createInfo.memoryTypeBits,
+ createInfo.pool,
+ allocation,
+ userDataStr.GetString());
Flush();
}
void VmaRecorder::RecordAllocateMemoryPages(uint32_t frameIndex,
- const VkMemoryRequirements &vkMemReq,
- const VmaAllocationCreateInfo &createInfo,
- uint64_t allocationCount,
- const VmaAllocation *pAllocations) {
+ const VkMemoryRequirements& vkMemReq,
+ const VmaAllocationCreateInfo& createInfo,
+ uint64_t allocationCount,
+ const VmaAllocation* pAllocations)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
UserDataString userDataStr(createInfo.flags, createInfo.pUserData);
fprintf(m_File, "%u,%.3f,%u,vmaAllocateMemoryPages,%llu,%llu,%u,%u,%u,%u,%u,%u,%p,", callParams.threadId, callParams.time, frameIndex,
- vkMemReq.size,
- vkMemReq.alignment,
- vkMemReq.memoryTypeBits,
- createInfo.flags,
- createInfo.usage,
- createInfo.requiredFlags,
- createInfo.preferredFlags,
- createInfo.memoryTypeBits,
- createInfo.pool);
+ vkMemReq.size,
+ vkMemReq.alignment,
+ vkMemReq.memoryTypeBits,
+ createInfo.flags,
+ createInfo.usage,
+ createInfo.requiredFlags,
+ createInfo.preferredFlags,
+ createInfo.memoryTypeBits,
+ createInfo.pool);
PrintPointerList(allocationCount, pAllocations);
fprintf(m_File, ",%s\n", userDataStr.GetString());
Flush();
}
void VmaRecorder::RecordAllocateMemoryForBuffer(uint32_t frameIndex,
- const VkMemoryRequirements &vkMemReq,
- bool requiresDedicatedAllocation,
- bool prefersDedicatedAllocation,
- const VmaAllocationCreateInfo &createInfo,
- VmaAllocation allocation) {
+ const VkMemoryRequirements& vkMemReq,
+ bool requiresDedicatedAllocation,
+ bool prefersDedicatedAllocation,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
UserDataString userDataStr(createInfo.flags, createInfo.pUserData);
fprintf(m_File, "%u,%.3f,%u,vmaAllocateMemoryForBuffer,%llu,%llu,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
- vkMemReq.size,
- vkMemReq.alignment,
- vkMemReq.memoryTypeBits,
- requiresDedicatedAllocation ? 1 : 0,
- prefersDedicatedAllocation ? 1 : 0,
- createInfo.flags,
- createInfo.usage,
- createInfo.requiredFlags,
- createInfo.preferredFlags,
- createInfo.memoryTypeBits,
- createInfo.pool,
- allocation,
- userDataStr.GetString());
+ vkMemReq.size,
+ vkMemReq.alignment,
+ vkMemReq.memoryTypeBits,
+ requiresDedicatedAllocation ? 1 : 0,
+ prefersDedicatedAllocation ? 1 : 0,
+ createInfo.flags,
+ createInfo.usage,
+ createInfo.requiredFlags,
+ createInfo.preferredFlags,
+ createInfo.memoryTypeBits,
+ createInfo.pool,
+ allocation,
+ userDataStr.GetString());
Flush();
}
void VmaRecorder::RecordAllocateMemoryForImage(uint32_t frameIndex,
- const VkMemoryRequirements &vkMemReq,
- bool requiresDedicatedAllocation,
- bool prefersDedicatedAllocation,
- const VmaAllocationCreateInfo &createInfo,
- VmaAllocation allocation) {
+ const VkMemoryRequirements& vkMemReq,
+ bool requiresDedicatedAllocation,
+ bool prefersDedicatedAllocation,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
UserDataString userDataStr(createInfo.flags, createInfo.pUserData);
fprintf(m_File, "%u,%.3f,%u,vmaAllocateMemoryForImage,%llu,%llu,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
- vkMemReq.size,
- vkMemReq.alignment,
- vkMemReq.memoryTypeBits,
- requiresDedicatedAllocation ? 1 : 0,
- prefersDedicatedAllocation ? 1 : 0,
- createInfo.flags,
- createInfo.usage,
- createInfo.requiredFlags,
- createInfo.preferredFlags,
- createInfo.memoryTypeBits,
- createInfo.pool,
- allocation,
- userDataStr.GetString());
+ vkMemReq.size,
+ vkMemReq.alignment,
+ vkMemReq.memoryTypeBits,
+ requiresDedicatedAllocation ? 1 : 0,
+ prefersDedicatedAllocation ? 1 : 0,
+ createInfo.flags,
+ createInfo.usage,
+ createInfo.requiredFlags,
+ createInfo.preferredFlags,
+ createInfo.memoryTypeBits,
+ createInfo.pool,
+ allocation,
+ userDataStr.GetString());
Flush();
}
void VmaRecorder::RecordFreeMemory(uint32_t frameIndex,
- VmaAllocation allocation) {
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaFreeMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
- allocation);
+ allocation);
Flush();
}
void VmaRecorder::RecordFreeMemoryPages(uint32_t frameIndex,
- uint64_t allocationCount,
- const VmaAllocation *pAllocations) {
+ uint64_t allocationCount,
+ const VmaAllocation* pAllocations)
+{
CallParams callParams;
GetBasicParams(callParams);
@@ -12586,260 +14563,289 @@ void VmaRecorder::RecordFreeMemoryPages(uint32_t frameIndex,
Flush();
}
-void VmaRecorder::RecordResizeAllocation(
- uint32_t frameIndex,
- VmaAllocation allocation,
- VkDeviceSize newSize) {
- CallParams callParams;
- GetBasicParams(callParams);
-
- VmaMutexLock lock(m_FileMutex, m_UseMutex);
- fprintf(m_File, "%u,%.3f,%u,vmaResizeAllocation,%p,%llu\n", callParams.threadId, callParams.time, frameIndex,
- allocation, newSize);
- Flush();
-}
-
void VmaRecorder::RecordSetAllocationUserData(uint32_t frameIndex,
- VmaAllocation allocation,
- const void *pUserData) {
+ VmaAllocation allocation,
+ const void* pUserData)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
UserDataString userDataStr(
- allocation->IsUserDataString() ? VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT : 0,
- pUserData);
+ allocation->IsUserDataString() ? VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT : 0,
+ pUserData);
fprintf(m_File, "%u,%.3f,%u,vmaSetAllocationUserData,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
- allocation,
- userDataStr.GetString());
+ allocation,
+ userDataStr.GetString());
Flush();
}
void VmaRecorder::RecordCreateLostAllocation(uint32_t frameIndex,
- VmaAllocation allocation) {
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaCreateLostAllocation,%p\n", callParams.threadId, callParams.time, frameIndex,
- allocation);
+ allocation);
Flush();
}
void VmaRecorder::RecordMapMemory(uint32_t frameIndex,
- VmaAllocation allocation) {
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaMapMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
- allocation);
+ allocation);
Flush();
}
void VmaRecorder::RecordUnmapMemory(uint32_t frameIndex,
- VmaAllocation allocation) {
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaUnmapMemory,%p\n", callParams.threadId, callParams.time, frameIndex,
- allocation);
+ allocation);
Flush();
}
void VmaRecorder::RecordFlushAllocation(uint32_t frameIndex,
- VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size) {
+ VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaFlushAllocation,%p,%llu,%llu\n", callParams.threadId, callParams.time, frameIndex,
- allocation,
- offset,
- size);
+ allocation,
+ offset,
+ size);
Flush();
}
void VmaRecorder::RecordInvalidateAllocation(uint32_t frameIndex,
- VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size) {
+ VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaInvalidateAllocation,%p,%llu,%llu\n", callParams.threadId, callParams.time, frameIndex,
- allocation,
- offset,
- size);
+ allocation,
+ offset,
+ size);
Flush();
}
void VmaRecorder::RecordCreateBuffer(uint32_t frameIndex,
- const VkBufferCreateInfo &bufCreateInfo,
- const VmaAllocationCreateInfo &allocCreateInfo,
- VmaAllocation allocation) {
+ const VkBufferCreateInfo& bufCreateInfo,
+ const VmaAllocationCreateInfo& allocCreateInfo,
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
UserDataString userDataStr(allocCreateInfo.flags, allocCreateInfo.pUserData);
fprintf(m_File, "%u,%.3f,%u,vmaCreateBuffer,%u,%llu,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
- bufCreateInfo.flags,
- bufCreateInfo.size,
- bufCreateInfo.usage,
- bufCreateInfo.sharingMode,
- allocCreateInfo.flags,
- allocCreateInfo.usage,
- allocCreateInfo.requiredFlags,
- allocCreateInfo.preferredFlags,
- allocCreateInfo.memoryTypeBits,
- allocCreateInfo.pool,
- allocation,
- userDataStr.GetString());
+ bufCreateInfo.flags,
+ bufCreateInfo.size,
+ bufCreateInfo.usage,
+ bufCreateInfo.sharingMode,
+ allocCreateInfo.flags,
+ allocCreateInfo.usage,
+ allocCreateInfo.requiredFlags,
+ allocCreateInfo.preferredFlags,
+ allocCreateInfo.memoryTypeBits,
+ allocCreateInfo.pool,
+ allocation,
+ userDataStr.GetString());
Flush();
}
void VmaRecorder::RecordCreateImage(uint32_t frameIndex,
- const VkImageCreateInfo &imageCreateInfo,
- const VmaAllocationCreateInfo &allocCreateInfo,
- VmaAllocation allocation) {
+ const VkImageCreateInfo& imageCreateInfo,
+ const VmaAllocationCreateInfo& allocCreateInfo,
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
UserDataString userDataStr(allocCreateInfo.flags, allocCreateInfo.pUserData);
fprintf(m_File, "%u,%.3f,%u,vmaCreateImage,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%p,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
- imageCreateInfo.flags,
- imageCreateInfo.imageType,
- imageCreateInfo.format,
- imageCreateInfo.extent.width,
- imageCreateInfo.extent.height,
- imageCreateInfo.extent.depth,
- imageCreateInfo.mipLevels,
- imageCreateInfo.arrayLayers,
- imageCreateInfo.samples,
- imageCreateInfo.tiling,
- imageCreateInfo.usage,
- imageCreateInfo.sharingMode,
- imageCreateInfo.initialLayout,
- allocCreateInfo.flags,
- allocCreateInfo.usage,
- allocCreateInfo.requiredFlags,
- allocCreateInfo.preferredFlags,
- allocCreateInfo.memoryTypeBits,
- allocCreateInfo.pool,
- allocation,
- userDataStr.GetString());
+ imageCreateInfo.flags,
+ imageCreateInfo.imageType,
+ imageCreateInfo.format,
+ imageCreateInfo.extent.width,
+ imageCreateInfo.extent.height,
+ imageCreateInfo.extent.depth,
+ imageCreateInfo.mipLevels,
+ imageCreateInfo.arrayLayers,
+ imageCreateInfo.samples,
+ imageCreateInfo.tiling,
+ imageCreateInfo.usage,
+ imageCreateInfo.sharingMode,
+ imageCreateInfo.initialLayout,
+ allocCreateInfo.flags,
+ allocCreateInfo.usage,
+ allocCreateInfo.requiredFlags,
+ allocCreateInfo.preferredFlags,
+ allocCreateInfo.memoryTypeBits,
+ allocCreateInfo.pool,
+ allocation,
+ userDataStr.GetString());
Flush();
}
void VmaRecorder::RecordDestroyBuffer(uint32_t frameIndex,
- VmaAllocation allocation) {
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaDestroyBuffer,%p\n", callParams.threadId, callParams.time, frameIndex,
- allocation);
+ allocation);
Flush();
}
void VmaRecorder::RecordDestroyImage(uint32_t frameIndex,
- VmaAllocation allocation) {
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaDestroyImage,%p\n", callParams.threadId, callParams.time, frameIndex,
- allocation);
+ allocation);
Flush();
}
void VmaRecorder::RecordTouchAllocation(uint32_t frameIndex,
- VmaAllocation allocation) {
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaTouchAllocation,%p\n", callParams.threadId, callParams.time, frameIndex,
- allocation);
+ allocation);
Flush();
}
void VmaRecorder::RecordGetAllocationInfo(uint32_t frameIndex,
- VmaAllocation allocation) {
+ VmaAllocation allocation)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaGetAllocationInfo,%p\n", callParams.threadId, callParams.time, frameIndex,
- allocation);
+ allocation);
Flush();
}
void VmaRecorder::RecordMakePoolAllocationsLost(uint32_t frameIndex,
- VmaPool pool) {
+ VmaPool pool)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaMakePoolAllocationsLost,%p\n", callParams.threadId, callParams.time, frameIndex,
- pool);
+ pool);
Flush();
}
void VmaRecorder::RecordDefragmentationBegin(uint32_t frameIndex,
- const VmaDefragmentationInfo2 &info,
- VmaDefragmentationContext ctx) {
+ const VmaDefragmentationInfo2& info,
+ VmaDefragmentationContext ctx)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaDefragmentationBegin,%u,", callParams.threadId, callParams.time, frameIndex,
- info.flags);
+ info.flags);
PrintPointerList(info.allocationCount, info.pAllocations);
fprintf(m_File, ",");
PrintPointerList(info.poolCount, info.pPools);
fprintf(m_File, ",%llu,%u,%llu,%u,%p,%p\n",
- info.maxCpuBytesToMove,
- info.maxCpuAllocationsToMove,
- info.maxGpuBytesToMove,
- info.maxGpuAllocationsToMove,
- info.commandBuffer,
- ctx);
+ info.maxCpuBytesToMove,
+ info.maxCpuAllocationsToMove,
+ info.maxGpuBytesToMove,
+ info.maxGpuAllocationsToMove,
+ info.commandBuffer,
+ ctx);
Flush();
}
void VmaRecorder::RecordDefragmentationEnd(uint32_t frameIndex,
- VmaDefragmentationContext ctx) {
+ VmaDefragmentationContext ctx)
+{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaDefragmentationEnd,%p\n", callParams.threadId, callParams.time, frameIndex,
- ctx);
+ ctx);
+ Flush();
+}
+
+void VmaRecorder::RecordSetPoolName(uint32_t frameIndex,
+ VmaPool pool,
+ const char* name)
+{
+ CallParams callParams;
+ GetBasicParams(callParams);
+
+ VmaMutexLock lock(m_FileMutex, m_UseMutex);
+ fprintf(m_File, "%u,%.3f,%u,vmaSetPoolName,%p,%s\n", callParams.threadId, callParams.time, frameIndex,
+ pool, name != VMA_NULL ? name : "");
Flush();
}
-VmaRecorder::UserDataString::UserDataString(VmaAllocationCreateFlags allocFlags, const void *pUserData) {
- if (pUserData != VMA_NULL) {
- if ((allocFlags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0) {
- m_Str = (const char *)pUserData;
- } else {
+VmaRecorder::UserDataString::UserDataString(VmaAllocationCreateFlags allocFlags, const void* pUserData)
+{
+ if(pUserData != VMA_NULL)
+ {
+ if((allocFlags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0)
+ {
+ m_Str = (const char*)pUserData;
+ }
+ else
+ {
sprintf_s(m_PtrStr, "%p", pUserData);
m_Str = m_PtrStr;
}
- } else {
+ }
+ else
+ {
m_Str = "";
}
}
void VmaRecorder::WriteConfiguration(
- const VkPhysicalDeviceProperties &devProps,
- const VkPhysicalDeviceMemoryProperties &memProps,
- bool dedicatedAllocationExtensionEnabled) {
+ const VkPhysicalDeviceProperties& devProps,
+ const VkPhysicalDeviceMemoryProperties& memProps,
+ uint32_t vulkanApiVersion,
+ bool dedicatedAllocationExtensionEnabled,
+ bool bindMemory2ExtensionEnabled,
+ bool memoryBudgetExtensionEnabled,
+ bool deviceCoherentMemoryExtensionEnabled)
+{
fprintf(m_File, "Config,Begin\n");
+ fprintf(m_File, "VulkanApiVersion,%u,%u\n", VK_VERSION_MAJOR(vulkanApiVersion), VK_VERSION_MINOR(vulkanApiVersion));
+
fprintf(m_File, "PhysicalDevice,apiVersion,%u\n", devProps.apiVersion);
fprintf(m_File, "PhysicalDevice,driverVersion,%u\n", devProps.driverVersion);
fprintf(m_File, "PhysicalDevice,vendorID,%u\n", devProps.vendorID);
@@ -12852,17 +14858,22 @@ void VmaRecorder::WriteConfiguration(
fprintf(m_File, "PhysicalDeviceLimits,nonCoherentAtomSize,%llu\n", devProps.limits.nonCoherentAtomSize);
fprintf(m_File, "PhysicalDeviceMemory,HeapCount,%u\n", memProps.memoryHeapCount);
- for (uint32_t i = 0; i < memProps.memoryHeapCount; ++i) {
+ for(uint32_t i = 0; i < memProps.memoryHeapCount; ++i)
+ {
fprintf(m_File, "PhysicalDeviceMemory,Heap,%u,size,%llu\n", i, memProps.memoryHeaps[i].size);
fprintf(m_File, "PhysicalDeviceMemory,Heap,%u,flags,%u\n", i, memProps.memoryHeaps[i].flags);
}
fprintf(m_File, "PhysicalDeviceMemory,TypeCount,%u\n", memProps.memoryTypeCount);
- for (uint32_t i = 0; i < memProps.memoryTypeCount; ++i) {
+ for(uint32_t i = 0; i < memProps.memoryTypeCount; ++i)
+ {
fprintf(m_File, "PhysicalDeviceMemory,Type,%u,heapIndex,%u\n", i, memProps.memoryTypes[i].heapIndex);
fprintf(m_File, "PhysicalDeviceMemory,Type,%u,propertyFlags,%u\n", i, memProps.memoryTypes[i].propertyFlags);
}
fprintf(m_File, "Extension,VK_KHR_dedicated_allocation,%u\n", dedicatedAllocationExtensionEnabled ? 1 : 0);
+ fprintf(m_File, "Extension,VK_KHR_bind_memory2,%u\n", bindMemory2ExtensionEnabled ? 1 : 0);
+ fprintf(m_File, "Extension,VK_EXT_memory_budget,%u\n", memoryBudgetExtensionEnabled ? 1 : 0);
+ fprintf(m_File, "Extension,VK_AMD_device_coherent_memory,%u\n", deviceCoherentMemoryExtensionEnabled ? 1 : 0);
fprintf(m_File, "Macro,VMA_DEBUG_ALWAYS_DEDICATED_MEMORY,%u\n", VMA_DEBUG_ALWAYS_DEDICATED_MEMORY ? 1 : 0);
fprintf(m_File, "Macro,VMA_DEBUG_ALIGNMENT,%llu\n", (VkDeviceSize)VMA_DEBUG_ALIGNMENT);
@@ -12877,7 +14888,8 @@ void VmaRecorder::WriteConfiguration(
fprintf(m_File, "Config,End\n");
}
-void VmaRecorder::GetBasicParams(CallParams &outParams) {
+void VmaRecorder::GetBasicParams(CallParams& outParams)
+{
outParams.threadId = GetCurrentThreadId();
LARGE_INTEGER counter;
@@ -12885,17 +14897,22 @@ void VmaRecorder::GetBasicParams(CallParams &outParams) {
outParams.time = (double)(counter.QuadPart - m_StartCounter) / (double)m_Freq;
}
-void VmaRecorder::PrintPointerList(uint64_t count, const VmaAllocation *pItems) {
- if (count) {
+void VmaRecorder::PrintPointerList(uint64_t count, const VmaAllocation* pItems)
+{
+ if(count)
+ {
fprintf(m_File, "%p", pItems[0]);
- for (uint64_t i = 1; i < count; ++i) {
+ for(uint64_t i = 1; i < count; ++i)
+ {
fprintf(m_File, " %p", pItems[i]);
}
}
}
-void VmaRecorder::Flush() {
- if ((m_Flags & VMA_RECORD_FLUSH_AFTER_CALL_BIT) != 0) {
+void VmaRecorder::Flush()
+{
+ if((m_Flags & VMA_RECORD_FLUSH_AFTER_CALL_BIT) != 0)
+ {
fflush(m_File);
}
}
@@ -12905,16 +14922,19 @@ void VmaRecorder::Flush() {
////////////////////////////////////////////////////////////////////////////////
// VmaAllocationObjectAllocator
-VmaAllocationObjectAllocator::VmaAllocationObjectAllocator(const VkAllocationCallbacks *pAllocationCallbacks) :
- m_Allocator(pAllocationCallbacks, 1024) {
+VmaAllocationObjectAllocator::VmaAllocationObjectAllocator(const VkAllocationCallbacks* pAllocationCallbacks) :
+ m_Allocator(pAllocationCallbacks, 1024)
+{
}
-VmaAllocation VmaAllocationObjectAllocator::Allocate() {
+template<typename... Types> VmaAllocation VmaAllocationObjectAllocator::Allocate(Types... args)
+{
VmaMutexLock mutexLock(m_Mutex);
- return m_Allocator.Alloc();
+ return m_Allocator.Alloc<Types...>(std::forward<Types>(args)...);
}
-void VmaAllocationObjectAllocator::Free(VmaAllocation hAlloc) {
+void VmaAllocationObjectAllocator::Free(VmaAllocation hAlloc)
+{
VmaMutexLock mutexLock(m_Mutex);
m_Allocator.Free(hAlloc);
}
@@ -12922,51 +14942,83 @@ void VmaAllocationObjectAllocator::Free(VmaAllocation hAlloc) {
////////////////////////////////////////////////////////////////////////////////
// VmaAllocator_T
-VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo *pCreateInfo) :
- m_UseMutex((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT) == 0),
- m_UseKhrDedicatedAllocation((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0),
- m_hDevice(pCreateInfo->device),
- m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != VMA_NULL),
- m_AllocationCallbacks(pCreateInfo->pAllocationCallbacks ?
- *pCreateInfo->pAllocationCallbacks :
- VmaEmptyAllocationCallbacks),
- m_AllocationObjectAllocator(&m_AllocationCallbacks),
- m_PreferredLargeHeapBlockSize(0),
- m_PhysicalDevice(pCreateInfo->physicalDevice),
- m_CurrentFrameIndex(0),
- m_GpuDefragmentationMemoryTypeBits(UINT32_MAX),
- m_Pools(VmaStlAllocator<VmaPool>(GetAllocationCallbacks())),
- m_NextPoolId(0)
+VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo* pCreateInfo) :
+ m_UseMutex((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT) == 0),
+ m_VulkanApiVersion(pCreateInfo->vulkanApiVersion != 0 ? pCreateInfo->vulkanApiVersion : VK_API_VERSION_1_0),
+ m_UseKhrDedicatedAllocation((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0),
+ m_UseKhrBindMemory2((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT) != 0),
+ m_UseExtMemoryBudget((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT) != 0),
+ m_UseAmdDeviceCoherentMemory((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT) != 0),
+ m_hDevice(pCreateInfo->device),
+ m_hInstance(pCreateInfo->instance),
+ m_AllocationCallbacksSpecified(pCreateInfo->pAllocationCallbacks != VMA_NULL),
+ m_AllocationCallbacks(pCreateInfo->pAllocationCallbacks ?
+ *pCreateInfo->pAllocationCallbacks : VmaEmptyAllocationCallbacks),
+ m_AllocationObjectAllocator(&m_AllocationCallbacks),
+ m_HeapSizeLimitMask(0),
+ m_PreferredLargeHeapBlockSize(0),
+ m_PhysicalDevice(pCreateInfo->physicalDevice),
+ m_CurrentFrameIndex(0),
+ m_GpuDefragmentationMemoryTypeBits(UINT32_MAX),
+ m_Pools(VmaStlAllocator<VmaPool>(GetAllocationCallbacks())),
+ m_NextPoolId(0),
+ m_GlobalMemoryTypeBits(UINT32_MAX)
#if VMA_RECORDING_ENABLED
- ,
- m_pRecorder(VMA_NULL)
+ ,m_pRecorder(VMA_NULL)
#endif
{
- if (VMA_DEBUG_DETECT_CORRUPTION) {
+ if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+ {
+ m_UseKhrDedicatedAllocation = false;
+ m_UseKhrBindMemory2 = false;
+ }
+
+ if(VMA_DEBUG_DETECT_CORRUPTION)
+ {
// Needs to be multiply of uint32_t size because we are going to write VMA_CORRUPTION_DETECTION_MAGIC_VALUE to it.
VMA_ASSERT(VMA_DEBUG_MARGIN % sizeof(uint32_t) == 0);
}
VMA_ASSERT(pCreateInfo->physicalDevice && pCreateInfo->device);
+ if(m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0))
+ {
#if !(VMA_DEDICATED_ALLOCATION)
- if ((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0) {
- VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT set but required extensions are disabled by preprocessor macros.");
+ if((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT) != 0)
+ {
+ VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT set but required extensions are disabled by preprocessor macros.");
+ }
+#endif
+#if !(VMA_BIND_MEMORY2)
+ if((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT) != 0)
+ {
+ VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT set but required extension is disabled by preprocessor macros.");
+ }
+#endif
+ }
+#if !(VMA_MEMORY_BUDGET)
+ if((pCreateInfo->flags & VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT) != 0)
+ {
+ VMA_ASSERT(0 && "VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT set but required extension is disabled by preprocessor macros.");
+ }
+#endif
+#if VMA_VULKAN_VERSION < 1001000
+ if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+ {
+ VMA_ASSERT(0 && "vulkanApiVersion >= VK_API_VERSION_1_1 but required Vulkan version is disabled by preprocessor macros.");
}
#endif
- memset(&m_DeviceMemoryCallbacks, 0, sizeof(m_DeviceMemoryCallbacks));
+ memset(&m_DeviceMemoryCallbacks, 0 ,sizeof(m_DeviceMemoryCallbacks));
memset(&m_PhysicalDeviceProperties, 0, sizeof(m_PhysicalDeviceProperties));
memset(&m_MemProps, 0, sizeof(m_MemProps));
-
+
memset(&m_pBlockVectors, 0, sizeof(m_pBlockVectors));
memset(&m_pDedicatedAllocations, 0, sizeof(m_pDedicatedAllocations));
+ memset(&m_VulkanFunctions, 0, sizeof(m_VulkanFunctions));
- for (uint32_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i) {
- m_HeapSizeLimit[i] = VK_WHOLE_SIZE;
- }
-
- if (pCreateInfo->pDeviceMemoryCallbacks != VMA_NULL) {
+ if(pCreateInfo->pDeviceMemoryCallbacks != VMA_NULL)
+ {
m_DeviceMemoryCallbacks.pfnAllocate = pCreateInfo->pDeviceMemoryCallbacks->pfnAllocate;
m_DeviceMemoryCallbacks.pfnFree = pCreateInfo->pDeviceMemoryCallbacks->pfnFree;
}
@@ -12982,57 +15034,70 @@ VmaAllocator_T::VmaAllocator_T(const VmaAllocatorCreateInfo *pCreateInfo) :
VMA_ASSERT(VmaIsPow2(m_PhysicalDeviceProperties.limits.nonCoherentAtomSize));
m_PreferredLargeHeapBlockSize = (pCreateInfo->preferredLargeHeapBlockSize != 0) ?
- pCreateInfo->preferredLargeHeapBlockSize :
- static_cast<VkDeviceSize>(VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE);
+ pCreateInfo->preferredLargeHeapBlockSize : static_cast<VkDeviceSize>(VMA_DEFAULT_LARGE_HEAP_BLOCK_SIZE);
+
+ m_GlobalMemoryTypeBits = CalculateGlobalMemoryTypeBits();
- if (pCreateInfo->pHeapSizeLimit != VMA_NULL) {
- for (uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex) {
+ if(pCreateInfo->pHeapSizeLimit != VMA_NULL)
+ {
+ for(uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex)
+ {
const VkDeviceSize limit = pCreateInfo->pHeapSizeLimit[heapIndex];
- if (limit != VK_WHOLE_SIZE) {
- m_HeapSizeLimit[heapIndex] = limit;
- if (limit < m_MemProps.memoryHeaps[heapIndex].size) {
+ if(limit != VK_WHOLE_SIZE)
+ {
+ m_HeapSizeLimitMask |= 1u << heapIndex;
+ if(limit < m_MemProps.memoryHeaps[heapIndex].size)
+ {
m_MemProps.memoryHeaps[heapIndex].size = limit;
}
}
}
}
- for (uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) {
+ for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+ {
const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(memTypeIndex);
m_pBlockVectors[memTypeIndex] = vma_new(this, VmaBlockVector)(
- this,
- VK_NULL_HANDLE, // hParentPool
- memTypeIndex,
- preferredBlockSize,
- 0,
- SIZE_MAX,
- GetBufferImageGranularity(),
- pCreateInfo->frameInUseCount,
- false, // isCustomPool
- false, // explicitBlockSize
- false); // linearAlgorithm
+ this,
+ VK_NULL_HANDLE, // hParentPool
+ memTypeIndex,
+ preferredBlockSize,
+ 0,
+ SIZE_MAX,
+ GetBufferImageGranularity(),
+ pCreateInfo->frameInUseCount,
+ false, // explicitBlockSize
+ false); // linearAlgorithm
// No need to call m_pBlockVectors[memTypeIndex][blockVectorTypeIndex]->CreateMinBlocks here,
// becase minBlockCount is 0.
m_pDedicatedAllocations[memTypeIndex] = vma_new(this, AllocationVectorType)(VmaStlAllocator<VmaAllocation>(GetAllocationCallbacks()));
+
}
}
-VkResult VmaAllocator_T::Init(const VmaAllocatorCreateInfo *pCreateInfo) {
+VkResult VmaAllocator_T::Init(const VmaAllocatorCreateInfo* pCreateInfo)
+{
VkResult res = VK_SUCCESS;
- if (pCreateInfo->pRecordSettings != VMA_NULL &&
- !VmaStrIsEmpty(pCreateInfo->pRecordSettings->pFilePath)) {
+ if(pCreateInfo->pRecordSettings != VMA_NULL &&
+ !VmaStrIsEmpty(pCreateInfo->pRecordSettings->pFilePath))
+ {
#if VMA_RECORDING_ENABLED
m_pRecorder = vma_new(this, VmaRecorder)();
res = m_pRecorder->Init(*pCreateInfo->pRecordSettings, m_UseMutex);
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
return res;
}
m_pRecorder->WriteConfiguration(
- m_PhysicalDeviceProperties,
- m_MemProps,
- m_UseKhrDedicatedAllocation);
+ m_PhysicalDeviceProperties,
+ m_MemProps,
+ m_VulkanApiVersion,
+ m_UseKhrDedicatedAllocation,
+ m_UseKhrBindMemory2,
+ m_UseExtMemoryBudget,
+ m_UseAmdDeviceCoherentMemory);
m_pRecorder->RecordCreateAllocator(GetCurrentFrameIndex());
#else
VMA_ASSERT(0 && "VmaAllocatorCreateInfo::pRecordSettings used, but not supported due to VMA_RECORDING_ENABLED not defined to 1.");
@@ -13040,21 +15105,32 @@ VkResult VmaAllocator_T::Init(const VmaAllocatorCreateInfo *pCreateInfo) {
#endif
}
+#if VMA_MEMORY_BUDGET
+ if(m_UseExtMemoryBudget)
+ {
+ UpdateVulkanBudget();
+ }
+#endif // #if VMA_MEMORY_BUDGET
+
return res;
}
-VmaAllocator_T::~VmaAllocator_T() {
+VmaAllocator_T::~VmaAllocator_T()
+{
#if VMA_RECORDING_ENABLED
- if (m_pRecorder != VMA_NULL) {
+ if(m_pRecorder != VMA_NULL)
+ {
m_pRecorder->RecordDestroyAllocator(GetCurrentFrameIndex());
vma_delete(this, m_pRecorder);
}
#endif
-
+
VMA_ASSERT(m_Pools.empty());
- for (size_t i = GetMemoryTypeCount(); i--;) {
- if (m_pDedicatedAllocations[i] != VMA_NULL && !m_pDedicatedAllocations[i]->empty()) {
+ for(size_t i = GetMemoryTypeCount(); i--; )
+ {
+ if(m_pDedicatedAllocations[i] != VMA_NULL && !m_pDedicatedAllocations[i]->empty())
+ {
VMA_ASSERT(0 && "Unfreed dedicated allocations found.");
}
@@ -13063,7 +15139,8 @@ VmaAllocator_T::~VmaAllocator_T() {
}
}
-void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions *pVulkanFunctions) {
+void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions* pVulkanFunctions)
+{
#if VMA_STATIC_VULKAN_FUNCTIONS == 1
m_VulkanFunctions.vkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties)vkGetPhysicalDeviceProperties;
m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties)vkGetPhysicalDeviceMemoryProperties;
@@ -13082,20 +15159,55 @@ void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions *pVulkanFunc
m_VulkanFunctions.vkCreateImage = (PFN_vkCreateImage)vkCreateImage;
m_VulkanFunctions.vkDestroyImage = (PFN_vkDestroyImage)vkDestroyImage;
m_VulkanFunctions.vkCmdCopyBuffer = (PFN_vkCmdCopyBuffer)vkCmdCopyBuffer;
+#if VMA_VULKAN_VERSION >= 1001000
+ if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+ {
+ VMA_ASSERT(m_hInstance != VK_NULL_HANDLE);
+ m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR =
+ (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetBufferMemoryRequirements2");
+ m_VulkanFunctions.vkGetImageMemoryRequirements2KHR =
+ (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetImageMemoryRequirements2");
+ m_VulkanFunctions.vkBindBufferMemory2KHR =
+ (PFN_vkBindBufferMemory2KHR)vkGetDeviceProcAddr(m_hDevice, "vkBindBufferMemory2");
+ m_VulkanFunctions.vkBindImageMemory2KHR =
+ (PFN_vkBindImageMemory2KHR)vkGetDeviceProcAddr(m_hDevice, "vkBindImageMemory2");
+ m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR =
+ (PFN_vkGetPhysicalDeviceMemoryProperties2KHR)vkGetInstanceProcAddr(m_hInstance, "vkGetPhysicalDeviceMemoryProperties2");
+ }
+#endif
#if VMA_DEDICATED_ALLOCATION
- if (m_UseKhrDedicatedAllocation) {
+ if(m_UseKhrDedicatedAllocation)
+ {
m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR =
- (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetBufferMemoryRequirements2KHR");
+ (PFN_vkGetBufferMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetBufferMemoryRequirements2KHR");
m_VulkanFunctions.vkGetImageMemoryRequirements2KHR =
- (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetImageMemoryRequirements2KHR");
+ (PFN_vkGetImageMemoryRequirements2KHR)vkGetDeviceProcAddr(m_hDevice, "vkGetImageMemoryRequirements2KHR");
+ }
+#endif
+#if VMA_BIND_MEMORY2
+ if(m_UseKhrBindMemory2)
+ {
+ m_VulkanFunctions.vkBindBufferMemory2KHR =
+ (PFN_vkBindBufferMemory2KHR)vkGetDeviceProcAddr(m_hDevice, "vkBindBufferMemory2KHR");
+ m_VulkanFunctions.vkBindImageMemory2KHR =
+ (PFN_vkBindImageMemory2KHR)vkGetDeviceProcAddr(m_hDevice, "vkBindImageMemory2KHR");
+ }
+#endif // #if VMA_BIND_MEMORY2
+#if VMA_MEMORY_BUDGET
+ if(m_UseExtMemoryBudget && m_VulkanApiVersion < VK_MAKE_VERSION(1, 1, 0))
+ {
+ VMA_ASSERT(m_hInstance != VK_NULL_HANDLE);
+ m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR =
+ (PFN_vkGetPhysicalDeviceMemoryProperties2KHR)vkGetInstanceProcAddr(m_hInstance, "vkGetPhysicalDeviceMemoryProperties2KHR");
}
-#endif // #if VMA_DEDICATED_ALLOCATION
+#endif // #if VMA_MEMORY_BUDGET
#endif // #if VMA_STATIC_VULKAN_FUNCTIONS == 1
#define VMA_COPY_IF_NOT_NULL(funcName) \
- if (pVulkanFunctions->funcName != VMA_NULL) m_VulkanFunctions.funcName = pVulkanFunctions->funcName;
+ if(pVulkanFunctions->funcName != VMA_NULL) m_VulkanFunctions.funcName = pVulkanFunctions->funcName;
- if (pVulkanFunctions != VMA_NULL) {
+ if(pVulkanFunctions != VMA_NULL)
+ {
VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceProperties);
VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceMemoryProperties);
VMA_COPY_IF_NOT_NULL(vkAllocateMemory);
@@ -13113,10 +15225,17 @@ void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions *pVulkanFunc
VMA_COPY_IF_NOT_NULL(vkCreateImage);
VMA_COPY_IF_NOT_NULL(vkDestroyImage);
VMA_COPY_IF_NOT_NULL(vkCmdCopyBuffer);
-#if VMA_DEDICATED_ALLOCATION
+#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
VMA_COPY_IF_NOT_NULL(vkGetBufferMemoryRequirements2KHR);
VMA_COPY_IF_NOT_NULL(vkGetImageMemoryRequirements2KHR);
#endif
+#if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000
+ VMA_COPY_IF_NOT_NULL(vkBindBufferMemory2KHR);
+ VMA_COPY_IF_NOT_NULL(vkBindImageMemory2KHR);
+#endif
+#if VMA_MEMORY_BUDGET
+ VMA_COPY_IF_NOT_NULL(vkGetPhysicalDeviceMemoryProperties2KHR);
+#endif
}
#undef VMA_COPY_IF_NOT_NULL
@@ -13140,108 +15259,146 @@ void VmaAllocator_T::ImportVulkanFunctions(const VmaVulkanFunctions *pVulkanFunc
VMA_ASSERT(m_VulkanFunctions.vkCreateImage != VMA_NULL);
VMA_ASSERT(m_VulkanFunctions.vkDestroyImage != VMA_NULL);
VMA_ASSERT(m_VulkanFunctions.vkCmdCopyBuffer != VMA_NULL);
-#if VMA_DEDICATED_ALLOCATION
- if (m_UseKhrDedicatedAllocation) {
+#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+ if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0) || m_UseKhrDedicatedAllocation)
+ {
VMA_ASSERT(m_VulkanFunctions.vkGetBufferMemoryRequirements2KHR != VMA_NULL);
VMA_ASSERT(m_VulkanFunctions.vkGetImageMemoryRequirements2KHR != VMA_NULL);
}
#endif
+#if VMA_BIND_MEMORY2 || VMA_VULKAN_VERSION >= 1001000
+ if(m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0) || m_UseKhrBindMemory2)
+ {
+ VMA_ASSERT(m_VulkanFunctions.vkBindBufferMemory2KHR != VMA_NULL);
+ VMA_ASSERT(m_VulkanFunctions.vkBindImageMemory2KHR != VMA_NULL);
+ }
+#endif
+#if VMA_MEMORY_BUDGET || VMA_VULKAN_VERSION >= 1001000
+ if(m_UseExtMemoryBudget || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+ {
+ VMA_ASSERT(m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties2KHR != VMA_NULL);
+ }
+#endif
}
-VkDeviceSize VmaAllocator_T::CalcPreferredBlockSize(uint32_t memTypeIndex) {
+VkDeviceSize VmaAllocator_T::CalcPreferredBlockSize(uint32_t memTypeIndex)
+{
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size;
const bool isSmallHeap = heapSize <= VMA_SMALL_HEAP_MAX_SIZE;
- return isSmallHeap ? (heapSize / 8) : m_PreferredLargeHeapBlockSize;
+ return VmaAlignUp(isSmallHeap ? (heapSize / 8) : m_PreferredLargeHeapBlockSize, (VkDeviceSize)32);
}
VkResult VmaAllocator_T::AllocateMemoryOfType(
- VkDeviceSize size,
- VkDeviceSize alignment,
- bool dedicatedAllocation,
- VkBuffer dedicatedBuffer,
- VkImage dedicatedImage,
- const VmaAllocationCreateInfo &createInfo,
- uint32_t memTypeIndex,
- VmaSuballocationType suballocType,
- size_t allocationCount,
- VmaAllocation *pAllocations) {
+ VkDeviceSize size,
+ VkDeviceSize alignment,
+ bool dedicatedAllocation,
+ VkBuffer dedicatedBuffer,
+ VkImage dedicatedImage,
+ const VmaAllocationCreateInfo& createInfo,
+ uint32_t memTypeIndex,
+ VmaSuballocationType suballocType,
+ size_t allocationCount,
+ VmaAllocation* pAllocations)
+{
VMA_ASSERT(pAllocations != VMA_NULL);
VMA_DEBUG_LOG(" AllocateMemory: MemoryTypeIndex=%u, AllocationCount=%zu, Size=%llu", memTypeIndex, allocationCount, size);
VmaAllocationCreateInfo finalCreateInfo = createInfo;
// If memory type is not HOST_VISIBLE, disable MAPPED.
- if ((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0 &&
- (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
+ if((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0 &&
+ (m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+ {
finalCreateInfo.flags &= ~VMA_ALLOCATION_CREATE_MAPPED_BIT;
}
+ // If memory is lazily allocated, it should be always dedicated.
+ if(finalCreateInfo.usage == VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED)
+ {
+ finalCreateInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
+ }
- VmaBlockVector *const blockVector = m_pBlockVectors[memTypeIndex];
+ VmaBlockVector* const blockVector = m_pBlockVectors[memTypeIndex];
VMA_ASSERT(blockVector);
const VkDeviceSize preferredBlockSize = blockVector->GetPreferredBlockSize();
bool preferDedicatedMemory =
- VMA_DEBUG_ALWAYS_DEDICATED_MEMORY ||
- dedicatedAllocation ||
- // Heuristics: Allocate dedicated memory if requested size if greater than half of preferred block size.
- size > preferredBlockSize / 2;
-
- if (preferDedicatedMemory &&
- (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0 &&
- finalCreateInfo.pool == VK_NULL_HANDLE) {
+ VMA_DEBUG_ALWAYS_DEDICATED_MEMORY ||
+ dedicatedAllocation ||
+ // Heuristics: Allocate dedicated memory if requested size if greater than half of preferred block size.
+ size > preferredBlockSize / 2;
+
+ if(preferDedicatedMemory &&
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) == 0 &&
+ finalCreateInfo.pool == VK_NULL_HANDLE)
+ {
finalCreateInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
}
- if ((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0) {
- if ((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0) {
+ if((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0)
+ {
+ if((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
+ {
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
- } else {
+ }
+ else
+ {
return AllocateDedicatedMemory(
- size,
- suballocType,
- memTypeIndex,
- (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0,
- (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
- finalCreateInfo.pUserData,
- dedicatedBuffer,
- dedicatedImage,
- allocationCount,
- pAllocations);
- }
- } else {
- VkResult res = blockVector->Allocate(
- m_CurrentFrameIndex.load(),
size,
- alignment,
- finalCreateInfo,
suballocType,
+ memTypeIndex,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT) != 0,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
+ finalCreateInfo.pUserData,
+ dedicatedBuffer,
+ dedicatedImage,
allocationCount,
pAllocations);
- if (res == VK_SUCCESS) {
+ }
+ }
+ else
+ {
+ VkResult res = blockVector->Allocate(
+ m_CurrentFrameIndex.load(),
+ size,
+ alignment,
+ finalCreateInfo,
+ suballocType,
+ allocationCount,
+ pAllocations);
+ if(res == VK_SUCCESS)
+ {
return res;
}
// 5. Try dedicated memory.
- if ((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0) {
+ if((finalCreateInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
+ {
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
- } else {
+ }
+ else
+ {
res = AllocateDedicatedMemory(
- size,
- suballocType,
- memTypeIndex,
- (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0,
- (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
- finalCreateInfo.pUserData,
- dedicatedBuffer,
- dedicatedImage,
- allocationCount,
- pAllocations);
- if (res == VK_SUCCESS) {
+ size,
+ suballocType,
+ memTypeIndex,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT) != 0,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0,
+ (finalCreateInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0,
+ finalCreateInfo.pUserData,
+ dedicatedBuffer,
+ dedicatedImage,
+ allocationCount,
+ pAllocations);
+ if(res == VK_SUCCESS)
+ {
// Succeeded: AllocateDedicatedMemory function already filld pMemory, nothing more to do here.
VMA_DEBUG_LOG(" Allocated as DedicatedMemory");
return VK_SUCCESS;
- } else {
+ }
+ else
+ {
// Everything failed: Return error code.
VMA_DEBUG_LOG(" vkAllocateMemory FAILED");
return res;
@@ -13251,85 +15408,108 @@ VkResult VmaAllocator_T::AllocateMemoryOfType(
}
VkResult VmaAllocator_T::AllocateDedicatedMemory(
- VkDeviceSize size,
- VmaSuballocationType suballocType,
- uint32_t memTypeIndex,
- bool map,
- bool isUserDataString,
- void *pUserData,
- VkBuffer dedicatedBuffer,
- VkImage dedicatedImage,
- size_t allocationCount,
- VmaAllocation *pAllocations) {
+ VkDeviceSize size,
+ VmaSuballocationType suballocType,
+ uint32_t memTypeIndex,
+ bool withinBudget,
+ bool map,
+ bool isUserDataString,
+ void* pUserData,
+ VkBuffer dedicatedBuffer,
+ VkImage dedicatedImage,
+ size_t allocationCount,
+ VmaAllocation* pAllocations)
+{
VMA_ASSERT(allocationCount > 0 && pAllocations);
+ if(withinBudget)
+ {
+ const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
+ VmaBudget heapBudget = {};
+ GetBudget(&heapBudget, heapIndex, 1);
+ if(heapBudget.usage + size * allocationCount > heapBudget.budget)
+ {
+ return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+ }
+ }
+
VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
allocInfo.memoryTypeIndex = memTypeIndex;
allocInfo.allocationSize = size;
-#if VMA_DEDICATED_ALLOCATION
+#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
VkMemoryDedicatedAllocateInfoKHR dedicatedAllocInfo = { VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR };
- if (m_UseKhrDedicatedAllocation) {
- if (dedicatedBuffer != VK_NULL_HANDLE) {
+ if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+ {
+ if(dedicatedBuffer != VK_NULL_HANDLE)
+ {
VMA_ASSERT(dedicatedImage == VK_NULL_HANDLE);
dedicatedAllocInfo.buffer = dedicatedBuffer;
allocInfo.pNext = &dedicatedAllocInfo;
- } else if (dedicatedImage != VK_NULL_HANDLE) {
+ }
+ else if(dedicatedImage != VK_NULL_HANDLE)
+ {
dedicatedAllocInfo.image = dedicatedImage;
allocInfo.pNext = &dedicatedAllocInfo;
}
}
-#endif // #if VMA_DEDICATED_ALLOCATION
+#endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
size_t allocIndex;
VkResult res = VK_SUCCESS;
- for (allocIndex = 0; allocIndex < allocationCount; ++allocIndex) {
+ for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
+ {
res = AllocateDedicatedMemoryPage(
- size,
- suballocType,
- memTypeIndex,
- allocInfo,
- map,
- isUserDataString,
- pUserData,
- pAllocations + allocIndex);
- if (res != VK_SUCCESS) {
+ size,
+ suballocType,
+ memTypeIndex,
+ allocInfo,
+ map,
+ isUserDataString,
+ pUserData,
+ pAllocations + allocIndex);
+ if(res != VK_SUCCESS)
+ {
break;
}
}
- if (res == VK_SUCCESS) {
+ if(res == VK_SUCCESS)
+ {
// Register them in m_pDedicatedAllocations.
{
VmaMutexLockWrite lock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
- AllocationVectorType *pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
+ AllocationVectorType* pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
VMA_ASSERT(pDedicatedAllocations);
- for (allocIndex = 0; allocIndex < allocationCount; ++allocIndex) {
+ for(allocIndex = 0; allocIndex < allocationCount; ++allocIndex)
+ {
VmaVectorInsertSorted<VmaPointerLess>(*pDedicatedAllocations, pAllocations[allocIndex]);
}
}
VMA_DEBUG_LOG(" Allocated DedicatedMemory Count=%zu, MemoryTypeIndex=#%u", allocationCount, memTypeIndex);
- } else {
+ }
+ else
+ {
// Free all already created allocations.
- while (allocIndex--) {
+ while(allocIndex--)
+ {
VmaAllocation currAlloc = pAllocations[allocIndex];
VkDeviceMemory hMemory = currAlloc->GetMemory();
-
+
/*
- There is no need to call this, because Vulkan spec allows to skip vkUnmapMemory
- before vkFreeMemory.
-
- if(currAlloc->GetMappedData() != VMA_NULL)
- {
- (*m_VulkanFunctions.vkUnmapMemory)(m_hDevice, hMemory);
- }
- */
+ There is no need to call this, because Vulkan spec allows to skip vkUnmapMemory
+ before vkFreeMemory.
+ if(currAlloc->GetMappedData() != VMA_NULL)
+ {
+ (*m_VulkanFunctions.vkUnmapMemory)(m_hDevice, hMemory);
+ }
+ */
+
FreeVulkanMemory(memTypeIndex, currAlloc->GetSize(), hMemory);
-
+ m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), currAlloc->GetSize());
currAlloc->SetUserData(this, VMA_NULL);
- currAlloc->Dtor();
m_AllocationObjectAllocator.Free(currAlloc);
}
@@ -13340,42 +15520,47 @@ VkResult VmaAllocator_T::AllocateDedicatedMemory(
}
VkResult VmaAllocator_T::AllocateDedicatedMemoryPage(
- VkDeviceSize size,
- VmaSuballocationType suballocType,
- uint32_t memTypeIndex,
- const VkMemoryAllocateInfo &allocInfo,
- bool map,
- bool isUserDataString,
- void *pUserData,
- VmaAllocation *pAllocation) {
+ VkDeviceSize size,
+ VmaSuballocationType suballocType,
+ uint32_t memTypeIndex,
+ const VkMemoryAllocateInfo& allocInfo,
+ bool map,
+ bool isUserDataString,
+ void* pUserData,
+ VmaAllocation* pAllocation)
+{
VkDeviceMemory hMemory = VK_NULL_HANDLE;
VkResult res = AllocateVulkanMemory(&allocInfo, &hMemory);
- if (res < 0) {
+ if(res < 0)
+ {
VMA_DEBUG_LOG(" vkAllocateMemory FAILED");
return res;
}
- void *pMappedData = VMA_NULL;
- if (map) {
+ void* pMappedData = VMA_NULL;
+ if(map)
+ {
res = (*m_VulkanFunctions.vkMapMemory)(
- m_hDevice,
- hMemory,
- 0,
- VK_WHOLE_SIZE,
- 0,
- &pMappedData);
- if (res < 0) {
+ m_hDevice,
+ hMemory,
+ 0,
+ VK_WHOLE_SIZE,
+ 0,
+ &pMappedData);
+ if(res < 0)
+ {
VMA_DEBUG_LOG(" vkMapMemory FAILED");
FreeVulkanMemory(memTypeIndex, size, hMemory);
return res;
}
}
- *pAllocation = m_AllocationObjectAllocator.Allocate();
- (*pAllocation)->Ctor(m_CurrentFrameIndex.load(), isUserDataString);
+ *pAllocation = m_AllocationObjectAllocator.Allocate(m_CurrentFrameIndex.load(), isUserDataString);
(*pAllocation)->InitDedicatedAllocation(memTypeIndex, hMemory, suballocType, pMappedData, size);
(*pAllocation)->SetUserData(this, pUserData);
- if (VMA_DEBUG_INITIALIZE_ALLOCATIONS) {
+ m_Budget.AddAllocation(MemoryTypeIndexToHeapIndex(memTypeIndex), size);
+ if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
+ {
FillAllocation(*pAllocation, VMA_ALLOCATION_FILL_PATTERN_CREATED);
}
@@ -13383,12 +15568,14 @@ VkResult VmaAllocator_T::AllocateDedicatedMemoryPage(
}
void VmaAllocator_T::GetBufferMemoryRequirements(
- VkBuffer hBuffer,
- VkMemoryRequirements &memReq,
- bool &requiresDedicatedAllocation,
- bool &prefersDedicatedAllocation) const {
-#if VMA_DEDICATED_ALLOCATION
- if (m_UseKhrDedicatedAllocation) {
+ VkBuffer hBuffer,
+ VkMemoryRequirements& memReq,
+ bool& requiresDedicatedAllocation,
+ bool& prefersDedicatedAllocation) const
+{
+#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+ if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+ {
VkBufferMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR };
memReqInfo.buffer = hBuffer;
@@ -13401,23 +15588,26 @@ void VmaAllocator_T::GetBufferMemoryRequirements(
memReq = memReq2.memoryRequirements;
requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE);
- prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
- } else
-#endif // #if VMA_DEDICATED_ALLOCATION
+ prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
+ }
+ else
+#endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
{
(*m_VulkanFunctions.vkGetBufferMemoryRequirements)(m_hDevice, hBuffer, &memReq);
requiresDedicatedAllocation = false;
- prefersDedicatedAllocation = false;
+ prefersDedicatedAllocation = false;
}
}
void VmaAllocator_T::GetImageMemoryRequirements(
- VkImage hImage,
- VkMemoryRequirements &memReq,
- bool &requiresDedicatedAllocation,
- bool &prefersDedicatedAllocation) const {
-#if VMA_DEDICATED_ALLOCATION
- if (m_UseKhrDedicatedAllocation) {
+ VkImage hImage,
+ VkMemoryRequirements& memReq,
+ bool& requiresDedicatedAllocation,
+ bool& prefersDedicatedAllocation) const
+{
+#if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
+ if(m_UseKhrDedicatedAllocation || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0))
+ {
VkImageMemoryRequirementsInfo2KHR memReqInfo = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR };
memReqInfo.image = hImage;
@@ -13430,127 +15620,155 @@ void VmaAllocator_T::GetImageMemoryRequirements(
memReq = memReq2.memoryRequirements;
requiresDedicatedAllocation = (memDedicatedReq.requiresDedicatedAllocation != VK_FALSE);
- prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
- } else
-#endif // #if VMA_DEDICATED_ALLOCATION
+ prefersDedicatedAllocation = (memDedicatedReq.prefersDedicatedAllocation != VK_FALSE);
+ }
+ else
+#endif // #if VMA_DEDICATED_ALLOCATION || VMA_VULKAN_VERSION >= 1001000
{
(*m_VulkanFunctions.vkGetImageMemoryRequirements)(m_hDevice, hImage, &memReq);
requiresDedicatedAllocation = false;
- prefersDedicatedAllocation = false;
+ prefersDedicatedAllocation = false;
}
}
VkResult VmaAllocator_T::AllocateMemory(
- const VkMemoryRequirements &vkMemReq,
- bool requiresDedicatedAllocation,
- bool prefersDedicatedAllocation,
- VkBuffer dedicatedBuffer,
- VkImage dedicatedImage,
- const VmaAllocationCreateInfo &createInfo,
- VmaSuballocationType suballocType,
- size_t allocationCount,
- VmaAllocation *pAllocations) {
+ const VkMemoryRequirements& vkMemReq,
+ bool requiresDedicatedAllocation,
+ bool prefersDedicatedAllocation,
+ VkBuffer dedicatedBuffer,
+ VkImage dedicatedImage,
+ const VmaAllocationCreateInfo& createInfo,
+ VmaSuballocationType suballocType,
+ size_t allocationCount,
+ VmaAllocation* pAllocations)
+{
memset(pAllocations, 0, sizeof(VmaAllocation) * allocationCount);
VMA_ASSERT(VmaIsPow2(vkMemReq.alignment));
- if (vkMemReq.size == 0) {
+ if(vkMemReq.size == 0)
+ {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
- if ((createInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0 &&
- (createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0) {
+ if((createInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) != 0 &&
+ (createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
+ {
VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT together with VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT makes no sense.");
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
- if ((createInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0 &&
- (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT) != 0) {
+ if((createInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0 &&
+ (createInfo.flags & VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT) != 0)
+ {
VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_MAPPED_BIT together with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT is invalid.");
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
- if (requiresDedicatedAllocation) {
- if ((createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0) {
+ if(requiresDedicatedAllocation)
+ {
+ if((createInfo.flags & VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT) != 0)
+ {
VMA_ASSERT(0 && "VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT specified while dedicated allocation is required.");
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
- if (createInfo.pool != VK_NULL_HANDLE) {
+ if(createInfo.pool != VK_NULL_HANDLE)
+ {
VMA_ASSERT(0 && "Pool specified while dedicated allocation is required.");
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
}
- if ((createInfo.pool != VK_NULL_HANDLE) &&
- ((createInfo.flags & (VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT)) != 0)) {
+ if((createInfo.pool != VK_NULL_HANDLE) &&
+ ((createInfo.flags & (VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT)) != 0))
+ {
VMA_ASSERT(0 && "Specifying VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT when pool != null is invalid.");
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
- if (createInfo.pool != VK_NULL_HANDLE) {
+ if(createInfo.pool != VK_NULL_HANDLE)
+ {
const VkDeviceSize alignmentForPool = VMA_MAX(
- vkMemReq.alignment,
- GetMemoryTypeMinAlignment(createInfo.pool->m_BlockVector.GetMemoryTypeIndex()));
+ vkMemReq.alignment,
+ GetMemoryTypeMinAlignment(createInfo.pool->m_BlockVector.GetMemoryTypeIndex()));
+
+ VmaAllocationCreateInfo createInfoForPool = createInfo;
+ // If memory type is not HOST_VISIBLE, disable MAPPED.
+ if((createInfoForPool.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0 &&
+ (m_MemProps.memoryTypes[createInfo.pool->m_BlockVector.GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+ {
+ createInfoForPool.flags &= ~VMA_ALLOCATION_CREATE_MAPPED_BIT;
+ }
+
return createInfo.pool->m_BlockVector.Allocate(
- m_CurrentFrameIndex.load(),
- vkMemReq.size,
- alignmentForPool,
- createInfo,
- suballocType,
- allocationCount,
- pAllocations);
- } else {
+ m_CurrentFrameIndex.load(),
+ vkMemReq.size,
+ alignmentForPool,
+ createInfoForPool,
+ suballocType,
+ allocationCount,
+ pAllocations);
+ }
+ else
+ {
// Bit mask of memory Vulkan types acceptable for this allocation.
uint32_t memoryTypeBits = vkMemReq.memoryTypeBits;
uint32_t memTypeIndex = UINT32_MAX;
VkResult res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &createInfo, &memTypeIndex);
- if (res == VK_SUCCESS) {
+ if(res == VK_SUCCESS)
+ {
VkDeviceSize alignmentForMemType = VMA_MAX(
- vkMemReq.alignment,
- GetMemoryTypeMinAlignment(memTypeIndex));
+ vkMemReq.alignment,
+ GetMemoryTypeMinAlignment(memTypeIndex));
res = AllocateMemoryOfType(
- vkMemReq.size,
- alignmentForMemType,
- requiresDedicatedAllocation || prefersDedicatedAllocation,
- dedicatedBuffer,
- dedicatedImage,
- createInfo,
- memTypeIndex,
- suballocType,
- allocationCount,
- pAllocations);
+ vkMemReq.size,
+ alignmentForMemType,
+ requiresDedicatedAllocation || prefersDedicatedAllocation,
+ dedicatedBuffer,
+ dedicatedImage,
+ createInfo,
+ memTypeIndex,
+ suballocType,
+ allocationCount,
+ pAllocations);
// Succeeded on first try.
- if (res == VK_SUCCESS) {
+ if(res == VK_SUCCESS)
+ {
return res;
}
// Allocation from this memory type failed. Try other compatible memory types.
- else {
- for (;;) {
+ else
+ {
+ for(;;)
+ {
// Remove old memTypeIndex from list of possibilities.
memoryTypeBits &= ~(1u << memTypeIndex);
// Find alternative memTypeIndex.
res = vmaFindMemoryTypeIndex(this, memoryTypeBits, &createInfo, &memTypeIndex);
- if (res == VK_SUCCESS) {
+ if(res == VK_SUCCESS)
+ {
alignmentForMemType = VMA_MAX(
- vkMemReq.alignment,
- GetMemoryTypeMinAlignment(memTypeIndex));
-
+ vkMemReq.alignment,
+ GetMemoryTypeMinAlignment(memTypeIndex));
+
res = AllocateMemoryOfType(
- vkMemReq.size,
- alignmentForMemType,
- requiresDedicatedAllocation || prefersDedicatedAllocation,
- dedicatedBuffer,
- dedicatedImage,
- createInfo,
- memTypeIndex,
- suballocType,
- allocationCount,
- pAllocations);
+ vkMemReq.size,
+ alignmentForMemType,
+ requiresDedicatedAllocation || prefersDedicatedAllocation,
+ dedicatedBuffer,
+ dedicatedImage,
+ createInfo,
+ memTypeIndex,
+ suballocType,
+ allocationCount,
+ pAllocations);
// Allocation from this alternative memory type succeeded.
- if (res == VK_SUCCESS) {
+ if(res == VK_SUCCESS)
+ {
return res;
}
// else: Allocation from this memory type failed. Try next one - next loop iteration.
}
// No other matching memory type index could be found.
- else {
+ else
+ {
// Not returning res, which is VK_ERROR_FEATURE_NOT_PRESENT, because we already failed to allocate once.
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
@@ -13564,84 +15782,87 @@ VkResult VmaAllocator_T::AllocateMemory(
}
void VmaAllocator_T::FreeMemory(
- size_t allocationCount,
- const VmaAllocation *pAllocations) {
+ size_t allocationCount,
+ const VmaAllocation* pAllocations)
+{
VMA_ASSERT(pAllocations);
- for (size_t allocIndex = allocationCount; allocIndex--;) {
+ for(size_t allocIndex = allocationCount; allocIndex--; )
+ {
VmaAllocation allocation = pAllocations[allocIndex];
- if (allocation != VK_NULL_HANDLE) {
- if (TouchAllocation(allocation)) {
- if (VMA_DEBUG_INITIALIZE_ALLOCATIONS) {
+ if(allocation != VK_NULL_HANDLE)
+ {
+ if(TouchAllocation(allocation))
+ {
+ if(VMA_DEBUG_INITIALIZE_ALLOCATIONS)
+ {
FillAllocation(allocation, VMA_ALLOCATION_FILL_PATTERN_DESTROYED);
}
- switch (allocation->GetType()) {
- case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: {
- VmaBlockVector *pBlockVector = VMA_NULL;
+ switch(allocation->GetType())
+ {
+ case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+ {
+ VmaBlockVector* pBlockVector = VMA_NULL;
VmaPool hPool = allocation->GetBlock()->GetParentPool();
- if (hPool != VK_NULL_HANDLE) {
+ if(hPool != VK_NULL_HANDLE)
+ {
pBlockVector = &hPool->m_BlockVector;
- } else {
+ }
+ else
+ {
const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
pBlockVector = m_pBlockVectors[memTypeIndex];
}
pBlockVector->Free(allocation);
- } break;
- case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
- FreeDedicatedMemory(allocation);
- break;
- default:
- VMA_ASSERT(0);
+ }
+ break;
+ case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+ FreeDedicatedMemory(allocation);
+ break;
+ default:
+ VMA_ASSERT(0);
}
}
+ // Do this regardless of whether the allocation is lost. Lost allocations still account to Budget.AllocationBytes.
+ m_Budget.RemoveAllocation(MemoryTypeIndexToHeapIndex(allocation->GetMemoryTypeIndex()), allocation->GetSize());
allocation->SetUserData(this, VMA_NULL);
- allocation->Dtor();
m_AllocationObjectAllocator.Free(allocation);
}
}
}
VkResult VmaAllocator_T::ResizeAllocation(
- const VmaAllocation alloc,
- VkDeviceSize newSize) {
- if (newSize == 0 || alloc->GetLastUseFrameIndex() == VMA_FRAME_INDEX_LOST) {
+ const VmaAllocation alloc,
+ VkDeviceSize newSize)
+{
+ // This function is deprecated and so it does nothing. It's left for backward compatibility.
+ if(newSize == 0 || alloc->GetLastUseFrameIndex() == VMA_FRAME_INDEX_LOST)
+ {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
- if (newSize == alloc->GetSize()) {
+ if(newSize == alloc->GetSize())
+ {
return VK_SUCCESS;
}
-
- switch (alloc->GetType()) {
- case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
- return VK_ERROR_FEATURE_NOT_PRESENT;
- case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
- if (alloc->GetBlock()->m_pMetadata->ResizeAllocation(alloc, newSize)) {
- alloc->ChangeSize(newSize);
- VMA_HEAVY_ASSERT(alloc->GetBlock()->m_pMetadata->Validate());
- return VK_SUCCESS;
- } else {
- return VK_ERROR_OUT_OF_POOL_MEMORY;
- }
- default:
- VMA_ASSERT(0);
- return VK_ERROR_VALIDATION_FAILED_EXT;
- }
+ return VK_ERROR_OUT_OF_POOL_MEMORY;
}
-void VmaAllocator_T::CalculateStats(VmaStats *pStats) {
+void VmaAllocator_T::CalculateStats(VmaStats* pStats)
+{
// Initialize.
InitStatInfo(pStats->total);
- for (size_t i = 0; i < VK_MAX_MEMORY_TYPES; ++i)
+ for(size_t i = 0; i < VK_MAX_MEMORY_TYPES; ++i)
InitStatInfo(pStats->memoryType[i]);
- for (size_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i)
+ for(size_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i)
InitStatInfo(pStats->memoryHeap[i]);
-
+
// Process default pools.
- for (uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) {
- VmaBlockVector *const pBlockVector = m_pBlockVectors[memTypeIndex];
+ for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+ {
+ VmaBlockVector* const pBlockVector = m_pBlockVectors[memTypeIndex];
VMA_ASSERT(pBlockVector);
pBlockVector->AddStats(pStats);
}
@@ -13649,18 +15870,21 @@ void VmaAllocator_T::CalculateStats(VmaStats *pStats) {
// Process custom pools.
{
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
- for (size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex) {
+ for(size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex)
+ {
m_Pools[poolIndex]->m_BlockVector.AddStats(pStats);
}
}
// Process dedicated allocations.
- for (uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) {
+ for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+ {
const uint32_t memHeapIndex = MemoryTypeIndexToHeapIndex(memTypeIndex);
VmaMutexLockRead dedicatedAllocationsLock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
- AllocationVectorType *const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
+ AllocationVectorType* const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
VMA_ASSERT(pDedicatedAllocVector);
- for (size_t allocIndex = 0, allocCount = pDedicatedAllocVector->size(); allocIndex < allocCount; ++allocIndex) {
+ for(size_t allocIndex = 0, allocCount = pDedicatedAllocVector->size(); allocIndex < allocCount; ++allocIndex)
+ {
VmaStatInfo allocationStatInfo;
(*pDedicatedAllocVector)[allocIndex]->DedicatedAllocCalcStatsInfo(allocationStatInfo);
VmaAddStatInfo(pStats->total, allocationStatInfo);
@@ -13671,35 +15895,90 @@ void VmaAllocator_T::CalculateStats(VmaStats *pStats) {
// Postprocess.
VmaPostprocessCalcStatInfo(pStats->total);
- for (size_t i = 0; i < GetMemoryTypeCount(); ++i)
+ for(size_t i = 0; i < GetMemoryTypeCount(); ++i)
VmaPostprocessCalcStatInfo(pStats->memoryType[i]);
- for (size_t i = 0; i < GetMemoryHeapCount(); ++i)
+ for(size_t i = 0; i < GetMemoryHeapCount(); ++i)
VmaPostprocessCalcStatInfo(pStats->memoryHeap[i]);
}
+void VmaAllocator_T::GetBudget(VmaBudget* outBudget, uint32_t firstHeap, uint32_t heapCount)
+{
+#if VMA_MEMORY_BUDGET
+ if(m_UseExtMemoryBudget)
+ {
+ if(m_Budget.m_OperationsSinceBudgetFetch < 30)
+ {
+ VmaMutexLockRead lockRead(m_Budget.m_BudgetMutex, m_UseMutex);
+ for(uint32_t i = 0; i < heapCount; ++i, ++outBudget)
+ {
+ const uint32_t heapIndex = firstHeap + i;
+
+ outBudget->blockBytes = m_Budget.m_BlockBytes[heapIndex];
+ outBudget->allocationBytes = m_Budget.m_AllocationBytes[heapIndex];
+
+ if(m_Budget.m_VulkanUsage[heapIndex] + outBudget->blockBytes > m_Budget.m_BlockBytesAtBudgetFetch[heapIndex])
+ {
+ outBudget->usage = m_Budget.m_VulkanUsage[heapIndex] +
+ outBudget->blockBytes - m_Budget.m_BlockBytesAtBudgetFetch[heapIndex];
+ }
+ else
+ {
+ outBudget->usage = 0;
+ }
+
+ // Have to take MIN with heap size because explicit HeapSizeLimit is included in it.
+ outBudget->budget = VMA_MIN(
+ m_Budget.m_VulkanBudget[heapIndex], m_MemProps.memoryHeaps[heapIndex].size);
+ }
+ }
+ else
+ {
+ UpdateVulkanBudget(); // Outside of mutex lock
+ GetBudget(outBudget, firstHeap, heapCount); // Recursion
+ }
+ }
+ else
+#endif
+ {
+ for(uint32_t i = 0; i < heapCount; ++i, ++outBudget)
+ {
+ const uint32_t heapIndex = firstHeap + i;
+
+ outBudget->blockBytes = m_Budget.m_BlockBytes[heapIndex];
+ outBudget->allocationBytes = m_Budget.m_AllocationBytes[heapIndex];
+
+ outBudget->usage = outBudget->blockBytes;
+ outBudget->budget = m_MemProps.memoryHeaps[heapIndex].size * 8 / 10; // 80% heuristics.
+ }
+ }
+}
+
static const uint32_t VMA_VENDOR_ID_AMD = 4098;
VkResult VmaAllocator_T::DefragmentationBegin(
- const VmaDefragmentationInfo2 &info,
- VmaDefragmentationStats *pStats,
- VmaDefragmentationContext *pContext) {
- if (info.pAllocationsChanged != VMA_NULL) {
+ const VmaDefragmentationInfo2& info,
+ VmaDefragmentationStats* pStats,
+ VmaDefragmentationContext* pContext)
+{
+ if(info.pAllocationsChanged != VMA_NULL)
+ {
memset(info.pAllocationsChanged, 0, info.allocationCount * sizeof(VkBool32));
}
*pContext = vma_new(this, VmaDefragmentationContext_T)(
- this, m_CurrentFrameIndex.load(), info.flags, pStats);
+ this, m_CurrentFrameIndex.load(), info.flags, pStats);
(*pContext)->AddPools(info.poolCount, info.pPools);
(*pContext)->AddAllocations(
- info.allocationCount, info.pAllocations, info.pAllocationsChanged);
+ info.allocationCount, info.pAllocations, info.pAllocationsChanged);
VkResult res = (*pContext)->Defragment(
- info.maxCpuBytesToMove, info.maxCpuAllocationsToMove,
- info.maxGpuBytesToMove, info.maxGpuAllocationsToMove,
- info.commandBuffer, pStats);
+ info.maxCpuBytesToMove, info.maxCpuAllocationsToMove,
+ info.maxGpuBytesToMove, info.maxGpuAllocationsToMove,
+ info.commandBuffer, pStats, info.flags);
- if (res != VK_NOT_READY) {
+ if(res != VK_NOT_READY)
+ {
vma_delete(this, *pContext);
*pContext = VMA_NULL;
}
@@ -13708,21 +15987,39 @@ VkResult VmaAllocator_T::DefragmentationBegin(
}
VkResult VmaAllocator_T::DefragmentationEnd(
- VmaDefragmentationContext context) {
+ VmaDefragmentationContext context)
+{
vma_delete(this, context);
return VK_SUCCESS;
}
-void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo *pAllocationInfo) {
- if (hAllocation->CanBecomeLost()) {
+VkResult VmaAllocator_T::DefragmentationPassBegin(
+ VmaDefragmentationPassInfo* pInfo,
+ VmaDefragmentationContext context)
+{
+ return context->DefragmentPassBegin(pInfo);
+}
+VkResult VmaAllocator_T::DefragmentationPassEnd(
+ VmaDefragmentationContext context)
+{
+ return context->DefragmentPassEnd();
+
+}
+
+void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationInfo* pAllocationInfo)
+{
+ if(hAllocation->CanBecomeLost())
+ {
/*
- Warning: This is a carefully designed algorithm.
- Do not modify unless you really know what you're doing :)
- */
+ Warning: This is a carefully designed algorithm.
+ Do not modify unless you really know what you're doing :)
+ */
const uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
- for (;;) {
- if (localLastUseFrameIndex == VMA_FRAME_INDEX_LOST) {
+ for(;;)
+ {
+ if(localLastUseFrameIndex == VMA_FRAME_INDEX_LOST)
+ {
pAllocationInfo->memoryType = UINT32_MAX;
pAllocationInfo->deviceMemory = VK_NULL_HANDLE;
pAllocationInfo->offset = 0;
@@ -13730,7 +16027,9 @@ void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationI
pAllocationInfo->pMappedData = VMA_NULL;
pAllocationInfo->pUserData = hAllocation->GetUserData();
return;
- } else if (localLastUseFrameIndex == localCurrFrameIndex) {
+ }
+ else if(localLastUseFrameIndex == localCurrFrameIndex)
+ {
pAllocationInfo->memoryType = hAllocation->GetMemoryTypeIndex();
pAllocationInfo->deviceMemory = hAllocation->GetMemory();
pAllocationInfo->offset = hAllocation->GetOffset();
@@ -13738,24 +16037,32 @@ void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationI
pAllocationInfo->pMappedData = VMA_NULL;
pAllocationInfo->pUserData = hAllocation->GetUserData();
return;
- } else // Last use time earlier than current time.
+ }
+ else // Last use time earlier than current time.
{
- if (hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex)) {
+ if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
+ {
localLastUseFrameIndex = localCurrFrameIndex;
}
}
}
- } else {
+ }
+ else
+ {
#if VMA_STATS_STRING_ENABLED
uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
- for (;;) {
+ for(;;)
+ {
VMA_ASSERT(localLastUseFrameIndex != VMA_FRAME_INDEX_LOST);
- if (localLastUseFrameIndex == localCurrFrameIndex) {
+ if(localLastUseFrameIndex == localCurrFrameIndex)
+ {
break;
- } else // Last use time earlier than current time.
+ }
+ else // Last use time earlier than current time.
{
- if (hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex)) {
+ if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
+ {
localLastUseFrameIndex = localCurrFrameIndex;
}
}
@@ -13771,34 +16078,48 @@ void VmaAllocator_T::GetAllocationInfo(VmaAllocation hAllocation, VmaAllocationI
}
}
-bool VmaAllocator_T::TouchAllocation(VmaAllocation hAllocation) {
+bool VmaAllocator_T::TouchAllocation(VmaAllocation hAllocation)
+{
// This is a stripped-down version of VmaAllocator_T::GetAllocationInfo.
- if (hAllocation->CanBecomeLost()) {
+ if(hAllocation->CanBecomeLost())
+ {
uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
- for (;;) {
- if (localLastUseFrameIndex == VMA_FRAME_INDEX_LOST) {
+ for(;;)
+ {
+ if(localLastUseFrameIndex == VMA_FRAME_INDEX_LOST)
+ {
return false;
- } else if (localLastUseFrameIndex == localCurrFrameIndex) {
+ }
+ else if(localLastUseFrameIndex == localCurrFrameIndex)
+ {
return true;
- } else // Last use time earlier than current time.
+ }
+ else // Last use time earlier than current time.
{
- if (hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex)) {
+ if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
+ {
localLastUseFrameIndex = localCurrFrameIndex;
}
}
}
- } else {
+ }
+ else
+ {
#if VMA_STATS_STRING_ENABLED
uint32_t localCurrFrameIndex = m_CurrentFrameIndex.load();
uint32_t localLastUseFrameIndex = hAllocation->GetLastUseFrameIndex();
- for (;;) {
+ for(;;)
+ {
VMA_ASSERT(localLastUseFrameIndex != VMA_FRAME_INDEX_LOST);
- if (localLastUseFrameIndex == localCurrFrameIndex) {
+ if(localLastUseFrameIndex == localCurrFrameIndex)
+ {
break;
- } else // Last use time earlier than current time.
+ }
+ else // Last use time earlier than current time.
{
- if (hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex)) {
+ if(hAllocation->CompareExchangeLastUseFrameIndex(localLastUseFrameIndex, localCurrFrameIndex))
+ {
localLastUseFrameIndex = localCurrFrameIndex;
}
}
@@ -13809,24 +16130,34 @@ bool VmaAllocator_T::TouchAllocation(VmaAllocation hAllocation) {
}
}
-VkResult VmaAllocator_T::CreatePool(const VmaPoolCreateInfo *pCreateInfo, VmaPool *pPool) {
+VkResult VmaAllocator_T::CreatePool(const VmaPoolCreateInfo* pCreateInfo, VmaPool* pPool)
+{
VMA_DEBUG_LOG(" CreatePool: MemoryTypeIndex=%u, flags=%u", pCreateInfo->memoryTypeIndex, pCreateInfo->flags);
VmaPoolCreateInfo newCreateInfo = *pCreateInfo;
- if (newCreateInfo.maxBlockCount == 0) {
+ if(newCreateInfo.maxBlockCount == 0)
+ {
newCreateInfo.maxBlockCount = SIZE_MAX;
}
- if (newCreateInfo.minBlockCount > newCreateInfo.maxBlockCount) {
+ if(newCreateInfo.minBlockCount > newCreateInfo.maxBlockCount)
+ {
return VK_ERROR_INITIALIZATION_FAILED;
}
+ // Memory type index out of range or forbidden.
+ if(pCreateInfo->memoryTypeIndex >= GetMemoryTypeCount() ||
+ ((1u << pCreateInfo->memoryTypeIndex) & m_GlobalMemoryTypeBits) == 0)
+ {
+ return VK_ERROR_FEATURE_NOT_PRESENT;
+ }
const VkDeviceSize preferredBlockSize = CalcPreferredBlockSize(newCreateInfo.memoryTypeIndex);
*pPool = vma_new(this, VmaPool_T)(this, newCreateInfo, preferredBlockSize);
VkResult res = (*pPool)->m_BlockVector.CreateMinBlocks();
- if (res != VK_SUCCESS) {
+ if(res != VK_SUCCESS)
+ {
vma_delete(this, *pPool);
*pPool = VMA_NULL;
return res;
@@ -13842,7 +16173,8 @@ VkResult VmaAllocator_T::CreatePool(const VmaPoolCreateInfo *pCreateInfo, VmaPoo
return VK_SUCCESS;
}
-void VmaAllocator_T::DestroyPool(VmaPool pool) {
+void VmaAllocator_T::DestroyPool(VmaPool pool)
+{
// Remove from m_Pools.
{
VmaMutexLockWrite lock(m_PoolsMutex, m_UseMutex);
@@ -13853,43 +16185,58 @@ void VmaAllocator_T::DestroyPool(VmaPool pool) {
vma_delete(this, pool);
}
-void VmaAllocator_T::GetPoolStats(VmaPool pool, VmaPoolStats *pPoolStats) {
+void VmaAllocator_T::GetPoolStats(VmaPool pool, VmaPoolStats* pPoolStats)
+{
pool->m_BlockVector.GetPoolStats(pPoolStats);
}
-void VmaAllocator_T::SetCurrentFrameIndex(uint32_t frameIndex) {
+void VmaAllocator_T::SetCurrentFrameIndex(uint32_t frameIndex)
+{
m_CurrentFrameIndex.store(frameIndex);
+
+#if VMA_MEMORY_BUDGET
+ if(m_UseExtMemoryBudget)
+ {
+ UpdateVulkanBudget();
+ }
+#endif // #if VMA_MEMORY_BUDGET
}
void VmaAllocator_T::MakePoolAllocationsLost(
- VmaPool hPool,
- size_t *pLostAllocationCount) {
+ VmaPool hPool,
+ size_t* pLostAllocationCount)
+{
hPool->m_BlockVector.MakePoolAllocationsLost(
- m_CurrentFrameIndex.load(),
- pLostAllocationCount);
+ m_CurrentFrameIndex.load(),
+ pLostAllocationCount);
}
-VkResult VmaAllocator_T::CheckPoolCorruption(VmaPool hPool) {
+VkResult VmaAllocator_T::CheckPoolCorruption(VmaPool hPool)
+{
return hPool->m_BlockVector.CheckCorruption();
}
-VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits) {
+VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits)
+{
VkResult finalRes = VK_ERROR_FEATURE_NOT_PRESENT;
// Process default pools.
- for (uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) {
- if (((1u << memTypeIndex) & memoryTypeBits) != 0) {
- VmaBlockVector *const pBlockVector = m_pBlockVectors[memTypeIndex];
+ for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+ {
+ if(((1u << memTypeIndex) & memoryTypeBits) != 0)
+ {
+ VmaBlockVector* const pBlockVector = m_pBlockVectors[memTypeIndex];
VMA_ASSERT(pBlockVector);
VkResult localRes = pBlockVector->CheckCorruption();
- switch (localRes) {
- case VK_ERROR_FEATURE_NOT_PRESENT:
- break;
- case VK_SUCCESS:
- finalRes = VK_SUCCESS;
- break;
- default:
- return localRes;
+ switch(localRes)
+ {
+ case VK_ERROR_FEATURE_NOT_PRESENT:
+ break;
+ case VK_SUCCESS:
+ finalRes = VK_SUCCESS;
+ break;
+ default:
+ return localRes;
}
}
}
@@ -13897,17 +16244,20 @@ VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits) {
// Process custom pools.
{
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
- for (size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex) {
- if (((1u << m_Pools[poolIndex]->m_BlockVector.GetMemoryTypeIndex()) & memoryTypeBits) != 0) {
+ for(size_t poolIndex = 0, poolCount = m_Pools.size(); poolIndex < poolCount; ++poolIndex)
+ {
+ if(((1u << m_Pools[poolIndex]->m_BlockVector.GetMemoryTypeIndex()) & memoryTypeBits) != 0)
+ {
VkResult localRes = m_Pools[poolIndex]->m_BlockVector.CheckCorruption();
- switch (localRes) {
- case VK_ERROR_FEATURE_NOT_PRESENT:
- break;
- case VK_SUCCESS:
- finalRes = VK_SUCCESS;
- break;
- default:
- return localRes;
+ switch(localRes)
+ {
+ case VK_ERROR_FEATURE_NOT_PRESENT:
+ break;
+ case VK_SUCCESS:
+ finalRes = VK_SUCCESS;
+ break;
+ default:
+ return localRes;
}
}
}
@@ -13916,140 +16266,244 @@ VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits) {
return finalRes;
}
-void VmaAllocator_T::CreateLostAllocation(VmaAllocation *pAllocation) {
- *pAllocation = m_AllocationObjectAllocator.Allocate();
- (*pAllocation)->Ctor(VMA_FRAME_INDEX_LOST, false);
+void VmaAllocator_T::CreateLostAllocation(VmaAllocation* pAllocation)
+{
+ *pAllocation = m_AllocationObjectAllocator.Allocate(VMA_FRAME_INDEX_LOST, false);
(*pAllocation)->InitLost();
}
-VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo *pAllocateInfo, VkDeviceMemory *pMemory) {
+VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory)
+{
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
- VkResult res;
- if (m_HeapSizeLimit[heapIndex] != VK_WHOLE_SIZE) {
- VmaMutexLock lock(m_HeapSizeLimitMutex, m_UseMutex);
- if (m_HeapSizeLimit[heapIndex] >= pAllocateInfo->allocationSize) {
- res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory);
- if (res == VK_SUCCESS) {
- m_HeapSizeLimit[heapIndex] -= pAllocateInfo->allocationSize;
+ // HeapSizeLimit is in effect for this heap.
+ if((m_HeapSizeLimitMask & (1u << heapIndex)) != 0)
+ {
+ const VkDeviceSize heapSize = m_MemProps.memoryHeaps[heapIndex].size;
+ VkDeviceSize blockBytes = m_Budget.m_BlockBytes[heapIndex];
+ for(;;)
+ {
+ const VkDeviceSize blockBytesAfterAllocation = blockBytes + pAllocateInfo->allocationSize;
+ if(blockBytesAfterAllocation > heapSize)
+ {
+ return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+ }
+ if(m_Budget.m_BlockBytes[heapIndex].compare_exchange_strong(blockBytes, blockBytesAfterAllocation))
+ {
+ break;
}
- } else {
- res = VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
- } else {
- res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory);
}
+ else
+ {
+ m_Budget.m_BlockBytes[heapIndex] += pAllocateInfo->allocationSize;
+ }
+
+ // VULKAN CALL vkAllocateMemory.
+ VkResult res = (*m_VulkanFunctions.vkAllocateMemory)(m_hDevice, pAllocateInfo, GetAllocationCallbacks(), pMemory);
- if (res == VK_SUCCESS && m_DeviceMemoryCallbacks.pfnAllocate != VMA_NULL) {
- (*m_DeviceMemoryCallbacks.pfnAllocate)(this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize);
+ if(res == VK_SUCCESS)
+ {
+#if VMA_MEMORY_BUDGET
+ ++m_Budget.m_OperationsSinceBudgetFetch;
+#endif
+
+ // Informative callback.
+ if(m_DeviceMemoryCallbacks.pfnAllocate != VMA_NULL)
+ {
+ (*m_DeviceMemoryCallbacks.pfnAllocate)(this, pAllocateInfo->memoryTypeIndex, *pMemory, pAllocateInfo->allocationSize);
+ }
+ }
+ else
+ {
+ m_Budget.m_BlockBytes[heapIndex] -= pAllocateInfo->allocationSize;
}
return res;
}
-void VmaAllocator_T::FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory) {
- if (m_DeviceMemoryCallbacks.pfnFree != VMA_NULL) {
+void VmaAllocator_T::FreeVulkanMemory(uint32_t memoryType, VkDeviceSize size, VkDeviceMemory hMemory)
+{
+ // Informative callback.
+ if(m_DeviceMemoryCallbacks.pfnFree != VMA_NULL)
+ {
(*m_DeviceMemoryCallbacks.pfnFree)(this, memoryType, hMemory, size);
}
+ // VULKAN CALL vkFreeMemory.
(*m_VulkanFunctions.vkFreeMemory)(m_hDevice, hMemory, GetAllocationCallbacks());
- const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(memoryType);
- if (m_HeapSizeLimit[heapIndex] != VK_WHOLE_SIZE) {
- VmaMutexLock lock(m_HeapSizeLimitMutex, m_UseMutex);
- m_HeapSizeLimit[heapIndex] += size;
+ m_Budget.m_BlockBytes[MemoryTypeIndexToHeapIndex(memoryType)] -= size;
+}
+
+VkResult VmaAllocator_T::BindVulkanBuffer(
+ VkDeviceMemory memory,
+ VkDeviceSize memoryOffset,
+ VkBuffer buffer,
+ const void* pNext)
+{
+ if(pNext != VMA_NULL)
+ {
+#if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
+ if((m_UseKhrBindMemory2 || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) &&
+ m_VulkanFunctions.vkBindBufferMemory2KHR != VMA_NULL)
+ {
+ VkBindBufferMemoryInfoKHR bindBufferMemoryInfo = { VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR };
+ bindBufferMemoryInfo.pNext = pNext;
+ bindBufferMemoryInfo.buffer = buffer;
+ bindBufferMemoryInfo.memory = memory;
+ bindBufferMemoryInfo.memoryOffset = memoryOffset;
+ return (*m_VulkanFunctions.vkBindBufferMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo);
+ }
+ else
+#endif // #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
+ {
+ return VK_ERROR_EXTENSION_NOT_PRESENT;
+ }
+ }
+ else
+ {
+ return (*m_VulkanFunctions.vkBindBufferMemory)(m_hDevice, buffer, memory, memoryOffset);
+ }
+}
+
+VkResult VmaAllocator_T::BindVulkanImage(
+ VkDeviceMemory memory,
+ VkDeviceSize memoryOffset,
+ VkImage image,
+ const void* pNext)
+{
+ if(pNext != VMA_NULL)
+ {
+#if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
+ if((m_UseKhrBindMemory2 || m_VulkanApiVersion >= VK_MAKE_VERSION(1, 1, 0)) &&
+ m_VulkanFunctions.vkBindImageMemory2KHR != VMA_NULL)
+ {
+ VkBindImageMemoryInfoKHR bindBufferMemoryInfo = { VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO_KHR };
+ bindBufferMemoryInfo.pNext = pNext;
+ bindBufferMemoryInfo.image = image;
+ bindBufferMemoryInfo.memory = memory;
+ bindBufferMemoryInfo.memoryOffset = memoryOffset;
+ return (*m_VulkanFunctions.vkBindImageMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo);
+ }
+ else
+#endif // #if VMA_BIND_MEMORY2
+ {
+ return VK_ERROR_EXTENSION_NOT_PRESENT;
+ }
+ }
+ else
+ {
+ return (*m_VulkanFunctions.vkBindImageMemory)(m_hDevice, image, memory, memoryOffset);
}
}
-VkResult VmaAllocator_T::Map(VmaAllocation hAllocation, void **ppData) {
- if (hAllocation->CanBecomeLost()) {
+VkResult VmaAllocator_T::Map(VmaAllocation hAllocation, void** ppData)
+{
+ if(hAllocation->CanBecomeLost())
+ {
return VK_ERROR_MEMORY_MAP_FAILED;
}
- switch (hAllocation->GetType()) {
- case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: {
- VmaDeviceMemoryBlock *const pBlock = hAllocation->GetBlock();
+ switch(hAllocation->GetType())
+ {
+ case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+ {
+ VmaDeviceMemoryBlock* const pBlock = hAllocation->GetBlock();
char *pBytes = VMA_NULL;
- VkResult res = pBlock->Map(this, 1, (void **)&pBytes);
- if (res == VK_SUCCESS) {
+ VkResult res = pBlock->Map(this, 1, (void**)&pBytes);
+ if(res == VK_SUCCESS)
+ {
*ppData = pBytes + (ptrdiff_t)hAllocation->GetOffset();
hAllocation->BlockAllocMap();
}
return res;
}
- case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
- return hAllocation->DedicatedAllocMap(this, ppData);
- default:
- VMA_ASSERT(0);
- return VK_ERROR_MEMORY_MAP_FAILED;
+ case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+ return hAllocation->DedicatedAllocMap(this, ppData);
+ default:
+ VMA_ASSERT(0);
+ return VK_ERROR_MEMORY_MAP_FAILED;
}
}
-void VmaAllocator_T::Unmap(VmaAllocation hAllocation) {
- switch (hAllocation->GetType()) {
- case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: {
- VmaDeviceMemoryBlock *const pBlock = hAllocation->GetBlock();
+void VmaAllocator_T::Unmap(VmaAllocation hAllocation)
+{
+ switch(hAllocation->GetType())
+ {
+ case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+ {
+ VmaDeviceMemoryBlock* const pBlock = hAllocation->GetBlock();
hAllocation->BlockAllocUnmap();
pBlock->Unmap(this, 1);
- } break;
- case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
- hAllocation->DedicatedAllocUnmap(this);
- break;
- default:
- VMA_ASSERT(0);
+ }
+ break;
+ case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+ hAllocation->DedicatedAllocUnmap(this);
+ break;
+ default:
+ VMA_ASSERT(0);
}
}
-VkResult VmaAllocator_T::BindBufferMemory(VmaAllocation hAllocation, VkBuffer hBuffer) {
+VkResult VmaAllocator_T::BindBufferMemory(
+ VmaAllocation hAllocation,
+ VkDeviceSize allocationLocalOffset,
+ VkBuffer hBuffer,
+ const void* pNext)
+{
VkResult res = VK_SUCCESS;
- switch (hAllocation->GetType()) {
- case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
- res = GetVulkanFunctions().vkBindBufferMemory(
- m_hDevice,
- hBuffer,
- hAllocation->GetMemory(),
- 0); //memoryOffset
- break;
- case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: {
- VmaDeviceMemoryBlock *pBlock = hAllocation->GetBlock();
- VMA_ASSERT(pBlock && "Binding buffer to allocation that doesn't belong to any block. Is the allocation lost?");
- res = pBlock->BindBufferMemory(this, hAllocation, hBuffer);
- break;
- }
- default:
- VMA_ASSERT(0);
+ switch(hAllocation->GetType())
+ {
+ case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+ res = BindVulkanBuffer(hAllocation->GetMemory(), allocationLocalOffset, hBuffer, pNext);
+ break;
+ case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+ {
+ VmaDeviceMemoryBlock* const pBlock = hAllocation->GetBlock();
+ VMA_ASSERT(pBlock && "Binding buffer to allocation that doesn't belong to any block. Is the allocation lost?");
+ res = pBlock->BindBufferMemory(this, hAllocation, allocationLocalOffset, hBuffer, pNext);
+ break;
+ }
+ default:
+ VMA_ASSERT(0);
}
return res;
}
-VkResult VmaAllocator_T::BindImageMemory(VmaAllocation hAllocation, VkImage hImage) {
+VkResult VmaAllocator_T::BindImageMemory(
+ VmaAllocation hAllocation,
+ VkDeviceSize allocationLocalOffset,
+ VkImage hImage,
+ const void* pNext)
+{
VkResult res = VK_SUCCESS;
- switch (hAllocation->GetType()) {
- case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
- res = GetVulkanFunctions().vkBindImageMemory(
- m_hDevice,
- hImage,
- hAllocation->GetMemory(),
- 0); //memoryOffset
- break;
- case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: {
- VmaDeviceMemoryBlock *pBlock = hAllocation->GetBlock();
- VMA_ASSERT(pBlock && "Binding image to allocation that doesn't belong to any block. Is the allocation lost?");
- res = pBlock->BindImageMemory(this, hAllocation, hImage);
- break;
- }
- default:
- VMA_ASSERT(0);
+ switch(hAllocation->GetType())
+ {
+ case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+ res = BindVulkanImage(hAllocation->GetMemory(), allocationLocalOffset, hImage, pNext);
+ break;
+ case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+ {
+ VmaDeviceMemoryBlock* pBlock = hAllocation->GetBlock();
+ VMA_ASSERT(pBlock && "Binding image to allocation that doesn't belong to any block. Is the allocation lost?");
+ res = pBlock->BindImageMemory(this, hAllocation, allocationLocalOffset, hImage, pNext);
+ break;
+ }
+ default:
+ VMA_ASSERT(0);
}
return res;
}
void VmaAllocator_T::FlushOrInvalidateAllocation(
- VmaAllocation hAllocation,
- VkDeviceSize offset, VkDeviceSize size,
- VMA_CACHE_OPERATION op) {
+ VmaAllocation hAllocation,
+ VkDeviceSize offset, VkDeviceSize size,
+ VMA_CACHE_OPERATION op)
+{
const uint32_t memTypeIndex = hAllocation->GetMemoryTypeIndex();
- if (size > 0 && IsMemoryTypeNonCoherent(memTypeIndex)) {
+ if(size > 0 && IsMemoryTypeNonCoherent(memTypeIndex))
+ {
const VkDeviceSize allocationSize = hAllocation->GetSize();
VMA_ASSERT(offset <= allocationSize);
@@ -14057,98 +16511,110 @@ void VmaAllocator_T::FlushOrInvalidateAllocation(
VkMappedMemoryRange memRange = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE };
memRange.memory = hAllocation->GetMemory();
-
- switch (hAllocation->GetType()) {
- case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
- memRange.offset = VmaAlignDown(offset, nonCoherentAtomSize);
- if (size == VK_WHOLE_SIZE) {
- memRange.size = allocationSize - memRange.offset;
- } else {
- VMA_ASSERT(offset + size <= allocationSize);
- memRange.size = VMA_MIN(
- VmaAlignUp(size + (offset - memRange.offset), nonCoherentAtomSize),
- allocationSize - memRange.offset);
- }
- break;
-
- case VmaAllocation_T::ALLOCATION_TYPE_BLOCK: {
- // 1. Still within this allocation.
- memRange.offset = VmaAlignDown(offset, nonCoherentAtomSize);
- if (size == VK_WHOLE_SIZE) {
- size = allocationSize - offset;
- } else {
- VMA_ASSERT(offset + size <= allocationSize);
- }
- memRange.size = VmaAlignUp(size + (offset - memRange.offset), nonCoherentAtomSize);
-
- // 2. Adjust to whole block.
- const VkDeviceSize allocationOffset = hAllocation->GetOffset();
- VMA_ASSERT(allocationOffset % nonCoherentAtomSize == 0);
- const VkDeviceSize blockSize = hAllocation->GetBlock()->m_pMetadata->GetSize();
- memRange.offset += allocationOffset;
- memRange.size = VMA_MIN(memRange.size, blockSize - memRange.offset);
-
- break;
+
+ switch(hAllocation->GetType())
+ {
+ case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
+ memRange.offset = VmaAlignDown(offset, nonCoherentAtomSize);
+ if(size == VK_WHOLE_SIZE)
+ {
+ memRange.size = allocationSize - memRange.offset;
}
+ else
+ {
+ VMA_ASSERT(offset + size <= allocationSize);
+ memRange.size = VMA_MIN(
+ VmaAlignUp(size + (offset - memRange.offset), nonCoherentAtomSize),
+ allocationSize - memRange.offset);
+ }
+ break;
- default:
- VMA_ASSERT(0);
+ case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
+ {
+ // 1. Still within this allocation.
+ memRange.offset = VmaAlignDown(offset, nonCoherentAtomSize);
+ if(size == VK_WHOLE_SIZE)
+ {
+ size = allocationSize - offset;
+ }
+ else
+ {
+ VMA_ASSERT(offset + size <= allocationSize);
+ }
+ memRange.size = VmaAlignUp(size + (offset - memRange.offset), nonCoherentAtomSize);
+
+ // 2. Adjust to whole block.
+ const VkDeviceSize allocationOffset = hAllocation->GetOffset();
+ VMA_ASSERT(allocationOffset % nonCoherentAtomSize == 0);
+ const VkDeviceSize blockSize = hAllocation->GetBlock()->m_pMetadata->GetSize();
+ memRange.offset += allocationOffset;
+ memRange.size = VMA_MIN(memRange.size, blockSize - memRange.offset);
+
+ break;
+ }
+
+ default:
+ VMA_ASSERT(0);
}
- switch (op) {
- case VMA_CACHE_FLUSH:
- (*GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hDevice, 1, &memRange);
- break;
- case VMA_CACHE_INVALIDATE:
- (*GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hDevice, 1, &memRange);
- break;
- default:
- VMA_ASSERT(0);
+ switch(op)
+ {
+ case VMA_CACHE_FLUSH:
+ (*GetVulkanFunctions().vkFlushMappedMemoryRanges)(m_hDevice, 1, &memRange);
+ break;
+ case VMA_CACHE_INVALIDATE:
+ (*GetVulkanFunctions().vkInvalidateMappedMemoryRanges)(m_hDevice, 1, &memRange);
+ break;
+ default:
+ VMA_ASSERT(0);
}
}
// else: Just ignore this call.
}
-void VmaAllocator_T::FreeDedicatedMemory(VmaAllocation allocation) {
+void VmaAllocator_T::FreeDedicatedMemory(const VmaAllocation allocation)
+{
VMA_ASSERT(allocation && allocation->GetType() == VmaAllocation_T::ALLOCATION_TYPE_DEDICATED);
const uint32_t memTypeIndex = allocation->GetMemoryTypeIndex();
{
VmaMutexLockWrite lock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
- AllocationVectorType *const pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
+ AllocationVectorType* const pDedicatedAllocations = m_pDedicatedAllocations[memTypeIndex];
VMA_ASSERT(pDedicatedAllocations);
bool success = VmaVectorRemoveSorted<VmaPointerLess>(*pDedicatedAllocations, allocation);
VMA_ASSERT(success);
}
VkDeviceMemory hMemory = allocation->GetMemory();
-
+
/*
- There is no need to call this, because Vulkan spec allows to skip vkUnmapMemory
- before vkFreeMemory.
-
- if(allocation->GetMappedData() != VMA_NULL)
- {
- (*m_VulkanFunctions.vkUnmapMemory)(m_hDevice, hMemory);
- }
- */
+ There is no need to call this, because Vulkan spec allows to skip vkUnmapMemory
+ before vkFreeMemory.
+ if(allocation->GetMappedData() != VMA_NULL)
+ {
+ (*m_VulkanFunctions.vkUnmapMemory)(m_hDevice, hMemory);
+ }
+ */
+
FreeVulkanMemory(memTypeIndex, allocation->GetSize(), hMemory);
VMA_DEBUG_LOG(" Freed DedicatedMemory MemoryTypeIndex=%u", memTypeIndex);
}
-uint32_t VmaAllocator_T::CalculateGpuDefragmentationMemoryTypeBits() const {
+uint32_t VmaAllocator_T::CalculateGpuDefragmentationMemoryTypeBits() const
+{
VkBufferCreateInfo dummyBufCreateInfo;
VmaFillGpuDefragmentationBufferCreateInfo(dummyBufCreateInfo);
uint32_t memoryTypeBits = 0;
// Create buffer.
- VkBuffer buf = VMA_NULL;
+ VkBuffer buf = VK_NULL_HANDLE;
VkResult res = (*GetVulkanFunctions().vkCreateBuffer)(
- m_hDevice, &dummyBufCreateInfo, GetAllocationCallbacks(), &buf);
- if (res == VK_SUCCESS) {
+ m_hDevice, &dummyBufCreateInfo, GetAllocationCallbacks(), &buf);
+ if(res == VK_SUCCESS)
+ {
// Query for supported memory types.
VkMemoryRequirements memReq;
(*GetVulkanFunctions().vkGetBufferMemoryRequirements)(m_hDevice, buf, &memReq);
@@ -14161,25 +16627,82 @@ uint32_t VmaAllocator_T::CalculateGpuDefragmentationMemoryTypeBits() const {
return memoryTypeBits;
}
-void VmaAllocator_T::FillAllocation(const VmaAllocation hAllocation, uint8_t pattern) {
- if (VMA_DEBUG_INITIALIZE_ALLOCATIONS &&
- !hAllocation->CanBecomeLost() &&
- (m_MemProps.memoryTypes[hAllocation->GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) {
- void *pData = VMA_NULL;
+uint32_t VmaAllocator_T::CalculateGlobalMemoryTypeBits() const
+{
+ // Make sure memory information is already fetched.
+ VMA_ASSERT(GetMemoryTypeCount() > 0);
+
+ uint32_t memoryTypeBits = UINT32_MAX;
+
+ if(!m_UseAmdDeviceCoherentMemory)
+ {
+ // Exclude memory types that have VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD.
+ for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+ {
+ if((m_MemProps.memoryTypes[memTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY) != 0)
+ {
+ memoryTypeBits &= ~(1u << memTypeIndex);
+ }
+ }
+ }
+
+ return memoryTypeBits;
+}
+
+#if VMA_MEMORY_BUDGET
+
+void VmaAllocator_T::UpdateVulkanBudget()
+{
+ VMA_ASSERT(m_UseExtMemoryBudget);
+
+ VkPhysicalDeviceMemoryProperties2KHR memProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR };
+
+ VkPhysicalDeviceMemoryBudgetPropertiesEXT budgetProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT };
+ memProps.pNext = &budgetProps;
+
+ GetVulkanFunctions().vkGetPhysicalDeviceMemoryProperties2KHR(m_PhysicalDevice, &memProps);
+
+ {
+ VmaMutexLockWrite lockWrite(m_Budget.m_BudgetMutex, m_UseMutex);
+
+ for(uint32_t heapIndex = 0; heapIndex < GetMemoryHeapCount(); ++heapIndex)
+ {
+ m_Budget.m_VulkanUsage[heapIndex] = budgetProps.heapUsage[heapIndex];
+ m_Budget.m_VulkanBudget[heapIndex] = budgetProps.heapBudget[heapIndex];
+ m_Budget.m_BlockBytesAtBudgetFetch[heapIndex] = m_Budget.m_BlockBytes[heapIndex].load();
+ }
+ m_Budget.m_OperationsSinceBudgetFetch = 0;
+ }
+}
+
+#endif // #if VMA_MEMORY_BUDGET
+
+void VmaAllocator_T::FillAllocation(const VmaAllocation hAllocation, uint8_t pattern)
+{
+ if(VMA_DEBUG_INITIALIZE_ALLOCATIONS &&
+ !hAllocation->CanBecomeLost() &&
+ (m_MemProps.memoryTypes[hAllocation->GetMemoryTypeIndex()].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
+ {
+ void* pData = VMA_NULL;
VkResult res = Map(hAllocation, &pData);
- if (res == VK_SUCCESS) {
+ if(res == VK_SUCCESS)
+ {
memset(pData, (int)pattern, (size_t)hAllocation->GetSize());
FlushOrInvalidateAllocation(hAllocation, 0, VK_WHOLE_SIZE, VMA_CACHE_FLUSH);
Unmap(hAllocation);
- } else {
+ }
+ else
+ {
VMA_ASSERT(0 && "VMA_DEBUG_INITIALIZE_ALLOCATIONS is enabled, but couldn't map memory to fill allocation.");
}
}
}
-uint32_t VmaAllocator_T::GetGpuDefragmentationMemoryTypeBits() {
+uint32_t VmaAllocator_T::GetGpuDefragmentationMemoryTypeBits()
+{
uint32_t memoryTypeBits = m_GpuDefragmentationMemoryTypeBits.load();
- if (memoryTypeBits == UINT32_MAX) {
+ if(memoryTypeBits == UINT32_MAX)
+ {
memoryTypeBits = CalculateGpuDefragmentationMemoryTypeBits();
m_GpuDefragmentationMemoryTypeBits.store(memoryTypeBits);
}
@@ -14188,14 +16711,18 @@ uint32_t VmaAllocator_T::GetGpuDefragmentationMemoryTypeBits() {
#if VMA_STATS_STRING_ENABLED
-void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter &json) {
+void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
+{
bool dedicatedAllocationsStarted = false;
- for (uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) {
+ for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+ {
VmaMutexLockRead dedicatedAllocationsLock(m_DedicatedAllocationsMutex[memTypeIndex], m_UseMutex);
- AllocationVectorType *const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
+ AllocationVectorType* const pDedicatedAllocVector = m_pDedicatedAllocations[memTypeIndex];
VMA_ASSERT(pDedicatedAllocVector);
- if (pDedicatedAllocVector->empty() == false) {
- if (dedicatedAllocationsStarted == false) {
+ if(pDedicatedAllocVector->empty() == false)
+ {
+ if(dedicatedAllocationsStarted == false)
+ {
dedicatedAllocationsStarted = true;
json.WriteString("DedicatedAllocations");
json.BeginObject();
@@ -14204,10 +16731,11 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter &json) {
json.BeginString("Type ");
json.ContinueString(memTypeIndex);
json.EndString();
-
+
json.BeginArray();
- for (size_t i = 0; i < pDedicatedAllocVector->size(); ++i) {
+ for(size_t i = 0; i < pDedicatedAllocVector->size(); ++i)
+ {
json.BeginObject(true);
const VmaAllocation hAlloc = (*pDedicatedAllocVector)[i];
hAlloc->PrintParameters(json);
@@ -14217,15 +16745,19 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter &json) {
json.EndArray();
}
}
- if (dedicatedAllocationsStarted) {
+ if(dedicatedAllocationsStarted)
+ {
json.EndObject();
}
{
bool allocationsStarted = false;
- for (uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex) {
- if (m_pBlockVectors[memTypeIndex]->IsEmpty() == false) {
- if (allocationsStarted == false) {
+ for(uint32_t memTypeIndex = 0; memTypeIndex < GetMemoryTypeCount(); ++memTypeIndex)
+ {
+ if(m_pBlockVectors[memTypeIndex]->IsEmpty() == false)
+ {
+ if(allocationsStarted == false)
+ {
allocationsStarted = true;
json.WriteString("DefaultPools");
json.BeginObject();
@@ -14238,7 +16770,8 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter &json) {
m_pBlockVectors[memTypeIndex]->PrintDetailedMap(json);
}
}
- if (allocationsStarted) {
+ if(allocationsStarted)
+ {
json.EndObject();
}
}
@@ -14247,10 +16780,12 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter &json) {
{
VmaMutexLockRead lock(m_PoolsMutex, m_UseMutex);
const size_t poolCount = m_Pools.size();
- if (poolCount > 0) {
+ if(poolCount > 0)
+ {
json.WriteString("Pools");
json.BeginObject();
- for (size_t poolIndex = 0; poolIndex < poolCount; ++poolIndex) {
+ for(size_t poolIndex = 0; poolIndex < poolCount; ++poolIndex)
+ {
json.BeginString();
json.ContinueString(m_Pools[poolIndex]->GetId());
json.EndString();
@@ -14267,50 +16802,59 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter &json) {
////////////////////////////////////////////////////////////////////////////////
// Public interface
-VkResult vmaCreateAllocator(
- const VmaAllocatorCreateInfo *pCreateInfo,
- VmaAllocator *pAllocator) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateAllocator(
+ const VmaAllocatorCreateInfo* pCreateInfo,
+ VmaAllocator* pAllocator)
+{
VMA_ASSERT(pCreateInfo && pAllocator);
+ VMA_ASSERT(pCreateInfo->vulkanApiVersion == 0 ||
+ (VK_VERSION_MAJOR(pCreateInfo->vulkanApiVersion) == 1 && VK_VERSION_MINOR(pCreateInfo->vulkanApiVersion) <= 1));
VMA_DEBUG_LOG("vmaCreateAllocator");
*pAllocator = vma_new(pCreateInfo->pAllocationCallbacks, VmaAllocator_T)(pCreateInfo);
return (*pAllocator)->Init(pCreateInfo);
}
-void vmaDestroyAllocator(
- VmaAllocator allocator) {
- if (allocator != VK_NULL_HANDLE) {
+VMA_CALL_PRE void VMA_CALL_POST vmaDestroyAllocator(
+ VmaAllocator allocator)
+{
+ if(allocator != VK_NULL_HANDLE)
+ {
VMA_DEBUG_LOG("vmaDestroyAllocator");
VkAllocationCallbacks allocationCallbacks = allocator->m_AllocationCallbacks;
vma_delete(&allocationCallbacks, allocator);
}
}
-void vmaGetPhysicalDeviceProperties(
- VmaAllocator allocator,
- const VkPhysicalDeviceProperties **ppPhysicalDeviceProperties) {
+VMA_CALL_PRE void VMA_CALL_POST vmaGetPhysicalDeviceProperties(
+ VmaAllocator allocator,
+ const VkPhysicalDeviceProperties **ppPhysicalDeviceProperties)
+{
VMA_ASSERT(allocator && ppPhysicalDeviceProperties);
*ppPhysicalDeviceProperties = &allocator->m_PhysicalDeviceProperties;
}
-void vmaGetMemoryProperties(
- VmaAllocator allocator,
- const VkPhysicalDeviceMemoryProperties **ppPhysicalDeviceMemoryProperties) {
+VMA_CALL_PRE void VMA_CALL_POST vmaGetMemoryProperties(
+ VmaAllocator allocator,
+ const VkPhysicalDeviceMemoryProperties** ppPhysicalDeviceMemoryProperties)
+{
VMA_ASSERT(allocator && ppPhysicalDeviceMemoryProperties);
*ppPhysicalDeviceMemoryProperties = &allocator->m_MemProps;
}
-void vmaGetMemoryTypeProperties(
- VmaAllocator allocator,
- uint32_t memoryTypeIndex,
- VkMemoryPropertyFlags *pFlags) {
+VMA_CALL_PRE void VMA_CALL_POST vmaGetMemoryTypeProperties(
+ VmaAllocator allocator,
+ uint32_t memoryTypeIndex,
+ VkMemoryPropertyFlags* pFlags)
+{
VMA_ASSERT(allocator && pFlags);
VMA_ASSERT(memoryTypeIndex < allocator->GetMemoryTypeCount());
*pFlags = allocator->m_MemProps.memoryTypes[memoryTypeIndex].propertyFlags;
}
-void vmaSetCurrentFrameIndex(
- VmaAllocator allocator,
- uint32_t frameIndex) {
+VMA_CALL_PRE void VMA_CALL_POST vmaSetCurrentFrameIndex(
+ VmaAllocator allocator,
+ uint32_t frameIndex)
+{
VMA_ASSERT(allocator);
VMA_ASSERT(frameIndex != VMA_FRAME_INDEX_LOST);
@@ -14319,20 +16863,31 @@ void vmaSetCurrentFrameIndex(
allocator->SetCurrentFrameIndex(frameIndex);
}
-void vmaCalculateStats(
- VmaAllocator allocator,
- VmaStats *pStats) {
+VMA_CALL_PRE void VMA_CALL_POST vmaCalculateStats(
+ VmaAllocator allocator,
+ VmaStats* pStats)
+{
VMA_ASSERT(allocator && pStats);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
allocator->CalculateStats(pStats);
}
+VMA_CALL_PRE void VMA_CALL_POST vmaGetBudget(
+ VmaAllocator allocator,
+ VmaBudget* pBudget)
+{
+ VMA_ASSERT(allocator && pBudget);
+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
+ allocator->GetBudget(pBudget, 0, allocator->GetMemoryHeapCount());
+}
+
#if VMA_STATS_STRING_ENABLED
-void vmaBuildStatsString(
- VmaAllocator allocator,
- char **ppStatsString,
- VkBool32 detailedMap) {
+VMA_CALL_PRE void VMA_CALL_POST vmaBuildStatsString(
+ VmaAllocator allocator,
+ char** ppStatsString,
+ VkBool32 detailedMap)
+{
VMA_ASSERT(allocator && ppStatsString);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
@@ -14341,13 +16896,17 @@ void vmaBuildStatsString(
VmaJsonWriter json(allocator->GetAllocationCallbacks(), sb);
json.BeginObject();
+ VmaBudget budget[VK_MAX_MEMORY_HEAPS];
+ allocator->GetBudget(budget, 0, allocator->GetMemoryHeapCount());
+
VmaStats stats;
allocator->CalculateStats(&stats);
json.WriteString("Total");
VmaPrintStatInfo(json, stats.total);
-
- for (uint32_t heapIndex = 0; heapIndex < allocator->GetMemoryHeapCount(); ++heapIndex) {
+
+ for(uint32_t heapIndex = 0; heapIndex < allocator->GetMemoryHeapCount(); ++heapIndex)
+ {
json.BeginString("Heap ");
json.ContinueString(heapIndex);
json.EndString();
@@ -14358,18 +16917,36 @@ void vmaBuildStatsString(
json.WriteString("Flags");
json.BeginArray(true);
- if ((allocator->m_MemProps.memoryHeaps[heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) {
+ if((allocator->m_MemProps.memoryHeaps[heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0)
+ {
json.WriteString("DEVICE_LOCAL");
}
json.EndArray();
- if (stats.memoryHeap[heapIndex].blockCount > 0) {
+ json.WriteString("Budget");
+ json.BeginObject();
+ {
+ json.WriteString("BlockBytes");
+ json.WriteNumber(budget[heapIndex].blockBytes);
+ json.WriteString("AllocationBytes");
+ json.WriteNumber(budget[heapIndex].allocationBytes);
+ json.WriteString("Usage");
+ json.WriteNumber(budget[heapIndex].usage);
+ json.WriteString("Budget");
+ json.WriteNumber(budget[heapIndex].budget);
+ }
+ json.EndObject();
+
+ if(stats.memoryHeap[heapIndex].blockCount > 0)
+ {
json.WriteString("Stats");
VmaPrintStatInfo(json, stats.memoryHeap[heapIndex]);
}
- for (uint32_t typeIndex = 0; typeIndex < allocator->GetMemoryTypeCount(); ++typeIndex) {
- if (allocator->MemoryTypeIndexToHeapIndex(typeIndex) == heapIndex) {
+ for(uint32_t typeIndex = 0; typeIndex < allocator->GetMemoryTypeCount(); ++typeIndex)
+ {
+ if(allocator->MemoryTypeIndexToHeapIndex(typeIndex) == heapIndex)
+ {
json.BeginString("Type ");
json.ContinueString(typeIndex);
json.EndString();
@@ -14379,24 +16956,42 @@ void vmaBuildStatsString(
json.WriteString("Flags");
json.BeginArray(true);
VkMemoryPropertyFlags flags = allocator->m_MemProps.memoryTypes[typeIndex].propertyFlags;
- if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0) {
+ if((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
+ {
json.WriteString("DEVICE_LOCAL");
}
- if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) {
+ if((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
+ {
json.WriteString("HOST_VISIBLE");
}
- if ((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0) {
+ if((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0)
+ {
json.WriteString("HOST_COHERENT");
}
- if ((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0) {
+ if((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0)
+ {
json.WriteString("HOST_CACHED");
}
- if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0) {
+ if((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
+ {
json.WriteString("LAZILY_ALLOCATED");
}
+ if((flags & VK_MEMORY_PROPERTY_PROTECTED_BIT) != 0)
+ {
+ json.WriteString(" PROTECTED");
+ }
+ if((flags & VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY) != 0)
+ {
+ json.WriteString(" DEVICE_COHERENT");
+ }
+ if((flags & VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY) != 0)
+ {
+ json.WriteString(" DEVICE_UNCACHED");
+ }
json.EndArray();
- if (stats.memoryType[typeIndex].blockCount > 0) {
+ if(stats.memoryType[typeIndex].blockCount > 0)
+ {
json.WriteString("Stats");
VmaPrintStatInfo(json, stats.memoryType[typeIndex]);
}
@@ -14407,7 +17002,8 @@ void vmaBuildStatsString(
json.EndObject();
}
- if (detailedMap == VK_TRUE) {
+ if(detailedMap == VK_TRUE)
+ {
allocator->PrintDetailedMap(json);
}
@@ -14415,18 +17011,21 @@ void vmaBuildStatsString(
}
const size_t len = sb.GetLength();
- char *const pChars = vma_new_array(allocator, char, len + 1);
- if (len > 0) {
+ char* const pChars = vma_new_array(allocator, char, len + 1);
+ if(len > 0)
+ {
memcpy(pChars, sb.GetData(), len);
}
pChars[len] = '\0';
*ppStatsString = pChars;
}
-void vmaFreeStatsString(
- VmaAllocator allocator,
- char *pStatsString) {
- if (pStatsString != VMA_NULL) {
+VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString(
+ VmaAllocator allocator,
+ char* pStatsString)
+{
+ if(pStatsString != VMA_NULL)
+ {
VMA_ASSERT(allocator);
size_t len = strlen(pStatsString);
vma_delete_array(allocator, pStatsString, len + 1);
@@ -14438,65 +17037,93 @@ void vmaFreeStatsString(
/*
This function is not protected by any mutex because it just reads immutable data.
*/
-VkResult vmaFindMemoryTypeIndex(
- VmaAllocator allocator,
- uint32_t memoryTypeBits,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- uint32_t *pMemoryTypeIndex) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndex(
+ VmaAllocator allocator,
+ uint32_t memoryTypeBits,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ uint32_t* pMemoryTypeIndex)
+{
VMA_ASSERT(allocator != VK_NULL_HANDLE);
VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
VMA_ASSERT(pMemoryTypeIndex != VMA_NULL);
- if (pAllocationCreateInfo->memoryTypeBits != 0) {
+ memoryTypeBits &= allocator->GetGlobalMemoryTypeBits();
+
+ if(pAllocationCreateInfo->memoryTypeBits != 0)
+ {
memoryTypeBits &= pAllocationCreateInfo->memoryTypeBits;
}
-
+
uint32_t requiredFlags = pAllocationCreateInfo->requiredFlags;
uint32_t preferredFlags = pAllocationCreateInfo->preferredFlags;
+ uint32_t notPreferredFlags = 0;
// Convert usage to requiredFlags and preferredFlags.
- switch (pAllocationCreateInfo->usage) {
- case VMA_MEMORY_USAGE_UNKNOWN:
- break;
- case VMA_MEMORY_USAGE_GPU_ONLY:
- if (!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
- preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
- }
- break;
- case VMA_MEMORY_USAGE_CPU_ONLY:
- requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
- break;
- case VMA_MEMORY_USAGE_CPU_TO_GPU:
- requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
- if (!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
- preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
- }
- break;
- case VMA_MEMORY_USAGE_GPU_TO_CPU:
- requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
- preferredFlags |= VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
- break;
- default:
- break;
+ switch(pAllocationCreateInfo->usage)
+ {
+ case VMA_MEMORY_USAGE_UNKNOWN:
+ break;
+ case VMA_MEMORY_USAGE_GPU_ONLY:
+ if(!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+ {
+ preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
+ }
+ break;
+ case VMA_MEMORY_USAGE_CPU_ONLY:
+ requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
+ break;
+ case VMA_MEMORY_USAGE_CPU_TO_GPU:
+ requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+ if(!allocator->IsIntegratedGpu() || (preferredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
+ {
+ preferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
+ }
+ break;
+ case VMA_MEMORY_USAGE_GPU_TO_CPU:
+ requiredFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+ preferredFlags |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
+ break;
+ case VMA_MEMORY_USAGE_CPU_COPY:
+ notPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
+ break;
+ case VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED:
+ requiredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
+ break;
+ default:
+ VMA_ASSERT(0);
+ break;
+ }
+
+ // Avoid DEVICE_COHERENT unless explicitly requested.
+ if(((pAllocationCreateInfo->requiredFlags | pAllocationCreateInfo->preferredFlags) &
+ (VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD_COPY)) == 0)
+ {
+ notPreferredFlags |= VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD_COPY;
}
*pMemoryTypeIndex = UINT32_MAX;
uint32_t minCost = UINT32_MAX;
- for (uint32_t memTypeIndex = 0, memTypeBit = 1;
- memTypeIndex < allocator->GetMemoryTypeCount();
- ++memTypeIndex, memTypeBit <<= 1) {
+ for(uint32_t memTypeIndex = 0, memTypeBit = 1;
+ memTypeIndex < allocator->GetMemoryTypeCount();
+ ++memTypeIndex, memTypeBit <<= 1)
+ {
// This memory type is acceptable according to memoryTypeBits bitmask.
- if ((memTypeBit & memoryTypeBits) != 0) {
+ if((memTypeBit & memoryTypeBits) != 0)
+ {
const VkMemoryPropertyFlags currFlags =
- allocator->m_MemProps.memoryTypes[memTypeIndex].propertyFlags;
+ allocator->m_MemProps.memoryTypes[memTypeIndex].propertyFlags;
// This memory type contains requiredFlags.
- if ((requiredFlags & ~currFlags) == 0) {
+ if((requiredFlags & ~currFlags) == 0)
+ {
// Calculate cost as number of bits from preferredFlags not present in this memory type.
- uint32_t currCost = VmaCountBitsSet(preferredFlags & ~currFlags);
+ uint32_t currCost = VmaCountBitsSet(preferredFlags & ~currFlags) +
+ VmaCountBitsSet(currFlags & notPreferredFlags);
// Remember memory type with lowest cost.
- if (currCost < minCost) {
+ if(currCost < minCost)
+ {
*pMemoryTypeIndex = memTypeIndex;
- if (currCost == 0) {
+ if(currCost == 0)
+ {
return VK_SUCCESS;
}
minCost = currCost;
@@ -14507,11 +17134,12 @@ VkResult vmaFindMemoryTypeIndex(
return (*pMemoryTypeIndex != UINT32_MAX) ? VK_SUCCESS : VK_ERROR_FEATURE_NOT_PRESENT;
}
-VkResult vmaFindMemoryTypeIndexForBufferInfo(
- VmaAllocator allocator,
- const VkBufferCreateInfo *pBufferCreateInfo,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- uint32_t *pMemoryTypeIndex) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForBufferInfo(
+ VmaAllocator allocator,
+ const VkBufferCreateInfo* pBufferCreateInfo,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ uint32_t* pMemoryTypeIndex)
+{
VMA_ASSERT(allocator != VK_NULL_HANDLE);
VMA_ASSERT(pBufferCreateInfo != VMA_NULL);
VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
@@ -14520,29 +17148,31 @@ VkResult vmaFindMemoryTypeIndexForBufferInfo(
const VkDevice hDev = allocator->m_hDevice;
VkBuffer hBuffer = VK_NULL_HANDLE;
VkResult res = allocator->GetVulkanFunctions().vkCreateBuffer(
- hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer);
- if (res == VK_SUCCESS) {
+ hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer);
+ if(res == VK_SUCCESS)
+ {
VkMemoryRequirements memReq = {};
allocator->GetVulkanFunctions().vkGetBufferMemoryRequirements(
- hDev, hBuffer, &memReq);
+ hDev, hBuffer, &memReq);
res = vmaFindMemoryTypeIndex(
- allocator,
- memReq.memoryTypeBits,
- pAllocationCreateInfo,
- pMemoryTypeIndex);
+ allocator,
+ memReq.memoryTypeBits,
+ pAllocationCreateInfo,
+ pMemoryTypeIndex);
allocator->GetVulkanFunctions().vkDestroyBuffer(
- hDev, hBuffer, allocator->GetAllocationCallbacks());
+ hDev, hBuffer, allocator->GetAllocationCallbacks());
}
return res;
}
-VkResult vmaFindMemoryTypeIndexForImageInfo(
- VmaAllocator allocator,
- const VkImageCreateInfo *pImageCreateInfo,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- uint32_t *pMemoryTypeIndex) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForImageInfo(
+ VmaAllocator allocator,
+ const VkImageCreateInfo* pImageCreateInfo,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ uint32_t* pMemoryTypeIndex)
+{
VMA_ASSERT(allocator != VK_NULL_HANDLE);
VMA_ASSERT(pImageCreateInfo != VMA_NULL);
VMA_ASSERT(pAllocationCreateInfo != VMA_NULL);
@@ -14551,60 +17181,66 @@ VkResult vmaFindMemoryTypeIndexForImageInfo(
const VkDevice hDev = allocator->m_hDevice;
VkImage hImage = VK_NULL_HANDLE;
VkResult res = allocator->GetVulkanFunctions().vkCreateImage(
- hDev, pImageCreateInfo, allocator->GetAllocationCallbacks(), &hImage);
- if (res == VK_SUCCESS) {
+ hDev, pImageCreateInfo, allocator->GetAllocationCallbacks(), &hImage);
+ if(res == VK_SUCCESS)
+ {
VkMemoryRequirements memReq = {};
allocator->GetVulkanFunctions().vkGetImageMemoryRequirements(
- hDev, hImage, &memReq);
+ hDev, hImage, &memReq);
res = vmaFindMemoryTypeIndex(
- allocator,
- memReq.memoryTypeBits,
- pAllocationCreateInfo,
- pMemoryTypeIndex);
+ allocator,
+ memReq.memoryTypeBits,
+ pAllocationCreateInfo,
+ pMemoryTypeIndex);
allocator->GetVulkanFunctions().vkDestroyImage(
- hDev, hImage, allocator->GetAllocationCallbacks());
+ hDev, hImage, allocator->GetAllocationCallbacks());
}
return res;
}
-VkResult vmaCreatePool(
- VmaAllocator allocator,
- const VmaPoolCreateInfo *pCreateInfo,
- VmaPool *pPool) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreatePool(
+ VmaAllocator allocator,
+ const VmaPoolCreateInfo* pCreateInfo,
+ VmaPool* pPool)
+{
VMA_ASSERT(allocator && pCreateInfo && pPool);
-
+
VMA_DEBUG_LOG("vmaCreatePool");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
+
VkResult res = allocator->CreatePool(pCreateInfo, pPool);
-
+
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordCreatePool(allocator->GetCurrentFrameIndex(), *pCreateInfo, *pPool);
}
#endif
-
+
return res;
}
-void vmaDestroyPool(
- VmaAllocator allocator,
- VmaPool pool) {
+VMA_CALL_PRE void VMA_CALL_POST vmaDestroyPool(
+ VmaAllocator allocator,
+ VmaPool pool)
+{
VMA_ASSERT(allocator);
-
- if (pool == VK_NULL_HANDLE) {
+
+ if(pool == VK_NULL_HANDLE)
+ {
return;
}
-
+
VMA_DEBUG_LOG("vmaDestroyPool");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
-
+
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordDestroyPool(allocator->GetCurrentFrameIndex(), pool);
}
#endif
@@ -14612,10 +17248,11 @@ void vmaDestroyPool(
allocator->DestroyPool(pool);
}
-void vmaGetPoolStats(
- VmaAllocator allocator,
- VmaPool pool,
- VmaPoolStats *pPoolStats) {
+VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolStats(
+ VmaAllocator allocator,
+ VmaPool pool,
+ VmaPoolStats* pPoolStats)
+{
VMA_ASSERT(allocator && pool && pPoolStats);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
@@ -14623,16 +17260,18 @@ void vmaGetPoolStats(
allocator->GetPoolStats(pool, pPoolStats);
}
-void vmaMakePoolAllocationsLost(
- VmaAllocator allocator,
- VmaPool pool,
- size_t *pLostAllocationCount) {
+VMA_CALL_PRE void VMA_CALL_POST vmaMakePoolAllocationsLost(
+ VmaAllocator allocator,
+ VmaPool pool,
+ size_t* pLostAllocationCount)
+{
VMA_ASSERT(allocator && pool);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordMakePoolAllocationsLost(allocator->GetCurrentFrameIndex(), pool);
}
#endif
@@ -14640,7 +17279,8 @@ void vmaMakePoolAllocationsLost(
allocator->MakePoolAllocationsLost(pool, pLostAllocationCount);
}
-VkResult vmaCheckPoolCorruption(VmaAllocator allocator, VmaPool pool) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckPoolCorruption(VmaAllocator allocator, VmaPool pool)
+{
VMA_ASSERT(allocator && pool);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
@@ -14650,12 +17290,48 @@ VkResult vmaCheckPoolCorruption(VmaAllocator allocator, VmaPool pool) {
return allocator->CheckPoolCorruption(pool);
}
-VkResult vmaAllocateMemory(
- VmaAllocator allocator,
- const VkMemoryRequirements *pVkMemoryRequirements,
- const VmaAllocationCreateInfo *pCreateInfo,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo) {
+VMA_CALL_PRE void VMA_CALL_POST vmaGetPoolName(
+ VmaAllocator allocator,
+ VmaPool pool,
+ const char** ppName)
+{
+ VMA_ASSERT(allocator && pool);
+
+ VMA_DEBUG_LOG("vmaGetPoolName");
+
+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+ *ppName = pool->GetName();
+}
+
+VMA_CALL_PRE void VMA_CALL_POST vmaSetPoolName(
+ VmaAllocator allocator,
+ VmaPool pool,
+ const char* pName)
+{
+ VMA_ASSERT(allocator && pool);
+
+ VMA_DEBUG_LOG("vmaSetPoolName");
+
+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+ pool->SetName(pName);
+
+#if VMA_RECORDING_ENABLED
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
+ allocator->GetRecorder()->RecordSetPoolName(allocator->GetCurrentFrameIndex(), pool, pName);
+ }
+#endif
+}
+
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemory(
+ VmaAllocator allocator,
+ const VkMemoryRequirements* pVkMemoryRequirements,
+ const VmaAllocationCreateInfo* pCreateInfo,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo)
+{
VMA_ASSERT(allocator && pVkMemoryRequirements && pCreateInfo && pAllocation);
VMA_DEBUG_LOG("vmaAllocateMemory");
@@ -14663,41 +17339,45 @@ VkResult vmaAllocateMemory(
VMA_DEBUG_GLOBAL_MUTEX_LOCK
VkResult result = allocator->AllocateMemory(
- *pVkMemoryRequirements,
- false, // requiresDedicatedAllocation
- false, // prefersDedicatedAllocation
- VK_NULL_HANDLE, // dedicatedBuffer
- VK_NULL_HANDLE, // dedicatedImage
- *pCreateInfo,
- VMA_SUBALLOCATION_TYPE_UNKNOWN,
- 1, // allocationCount
- pAllocation);
+ *pVkMemoryRequirements,
+ false, // requiresDedicatedAllocation
+ false, // prefersDedicatedAllocation
+ VK_NULL_HANDLE, // dedicatedBuffer
+ VK_NULL_HANDLE, // dedicatedImage
+ *pCreateInfo,
+ VMA_SUBALLOCATION_TYPE_UNKNOWN,
+ 1, // allocationCount
+ pAllocation);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordAllocateMemory(
- allocator->GetCurrentFrameIndex(),
- *pVkMemoryRequirements,
- *pCreateInfo,
- *pAllocation);
+ allocator->GetCurrentFrameIndex(),
+ *pVkMemoryRequirements,
+ *pCreateInfo,
+ *pAllocation);
}
#endif
-
- if (pAllocationInfo != VMA_NULL && result == VK_SUCCESS) {
+
+ if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS)
+ {
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
}
return result;
}
-VkResult vmaAllocateMemoryPages(
- VmaAllocator allocator,
- const VkMemoryRequirements *pVkMemoryRequirements,
- const VmaAllocationCreateInfo *pCreateInfo,
- size_t allocationCount,
- VmaAllocation *pAllocations,
- VmaAllocationInfo *pAllocationInfo) {
- if (allocationCount == 0) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryPages(
+ VmaAllocator allocator,
+ const VkMemoryRequirements* pVkMemoryRequirements,
+ const VmaAllocationCreateInfo* pCreateInfo,
+ size_t allocationCount,
+ VmaAllocation* pAllocations,
+ VmaAllocationInfo* pAllocationInfo)
+{
+ if(allocationCount == 0)
+ {
return VK_SUCCESS;
}
@@ -14708,29 +17388,32 @@ VkResult vmaAllocateMemoryPages(
VMA_DEBUG_GLOBAL_MUTEX_LOCK
VkResult result = allocator->AllocateMemory(
- *pVkMemoryRequirements,
- false, // requiresDedicatedAllocation
- false, // prefersDedicatedAllocation
- VK_NULL_HANDLE, // dedicatedBuffer
- VK_NULL_HANDLE, // dedicatedImage
- *pCreateInfo,
- VMA_SUBALLOCATION_TYPE_UNKNOWN,
- allocationCount,
- pAllocations);
+ *pVkMemoryRequirements,
+ false, // requiresDedicatedAllocation
+ false, // prefersDedicatedAllocation
+ VK_NULL_HANDLE, // dedicatedBuffer
+ VK_NULL_HANDLE, // dedicatedImage
+ *pCreateInfo,
+ VMA_SUBALLOCATION_TYPE_UNKNOWN,
+ allocationCount,
+ pAllocations);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordAllocateMemoryPages(
- allocator->GetCurrentFrameIndex(),
- *pVkMemoryRequirements,
- *pCreateInfo,
- (uint64_t)allocationCount,
- pAllocations);
+ allocator->GetCurrentFrameIndex(),
+ *pVkMemoryRequirements,
+ *pCreateInfo,
+ (uint64_t)allocationCount,
+ pAllocations);
}
#endif
-
- if (pAllocationInfo != VMA_NULL && result == VK_SUCCESS) {
- for (size_t i = 0; i < allocationCount; ++i) {
+
+ if(pAllocationInfo != VMA_NULL && result == VK_SUCCESS)
+ {
+ for(size_t i = 0; i < allocationCount; ++i)
+ {
allocator->GetAllocationInfo(pAllocations[i], pAllocationInfo + i);
}
}
@@ -14738,12 +17421,13 @@ VkResult vmaAllocateMemoryPages(
return result;
}
-VkResult vmaAllocateMemoryForBuffer(
- VmaAllocator allocator,
- VkBuffer buffer,
- const VmaAllocationCreateInfo *pCreateInfo,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryForBuffer(
+ VmaAllocator allocator,
+ VkBuffer buffer,
+ const VmaAllocationCreateInfo* pCreateInfo,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo)
+{
VMA_ASSERT(allocator && buffer != VK_NULL_HANDLE && pCreateInfo && pAllocation);
VMA_DEBUG_LOG("vmaAllocateMemoryForBuffer");
@@ -14754,45 +17438,48 @@ VkResult vmaAllocateMemoryForBuffer(
bool requiresDedicatedAllocation = false;
bool prefersDedicatedAllocation = false;
allocator->GetBufferMemoryRequirements(buffer, vkMemReq,
- requiresDedicatedAllocation,
- prefersDedicatedAllocation);
+ requiresDedicatedAllocation,
+ prefersDedicatedAllocation);
VkResult result = allocator->AllocateMemory(
+ vkMemReq,
+ requiresDedicatedAllocation,
+ prefersDedicatedAllocation,
+ buffer, // dedicatedBuffer
+ VK_NULL_HANDLE, // dedicatedImage
+ *pCreateInfo,
+ VMA_SUBALLOCATION_TYPE_BUFFER,
+ 1, // allocationCount
+ pAllocation);
+
+#if VMA_RECORDING_ENABLED
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
+ allocator->GetRecorder()->RecordAllocateMemoryForBuffer(
+ allocator->GetCurrentFrameIndex(),
vkMemReq,
requiresDedicatedAllocation,
prefersDedicatedAllocation,
- buffer, // dedicatedBuffer
- VK_NULL_HANDLE, // dedicatedImage
*pCreateInfo,
- VMA_SUBALLOCATION_TYPE_BUFFER,
- 1, // allocationCount
- pAllocation);
-
-#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
- allocator->GetRecorder()->RecordAllocateMemoryForBuffer(
- allocator->GetCurrentFrameIndex(),
- vkMemReq,
- requiresDedicatedAllocation,
- prefersDedicatedAllocation,
- *pCreateInfo,
- *pAllocation);
+ *pAllocation);
}
#endif
- if (pAllocationInfo && result == VK_SUCCESS) {
+ if(pAllocationInfo && result == VK_SUCCESS)
+ {
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
}
return result;
}
-VkResult vmaAllocateMemoryForImage(
- VmaAllocator allocator,
- VkImage image,
- const VmaAllocationCreateInfo *pCreateInfo,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaAllocateMemoryForImage(
+ VmaAllocator allocator,
+ VkImage image,
+ const VmaAllocationCreateInfo* pCreateInfo,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo)
+{
VMA_ASSERT(allocator && image != VK_NULL_HANDLE && pCreateInfo && pAllocation);
VMA_DEBUG_LOG("vmaAllocateMemoryForImage");
@@ -14801,155 +17488,160 @@ VkResult vmaAllocateMemoryForImage(
VkMemoryRequirements vkMemReq = {};
bool requiresDedicatedAllocation = false;
- bool prefersDedicatedAllocation = false;
+ bool prefersDedicatedAllocation = false;
allocator->GetImageMemoryRequirements(image, vkMemReq,
- requiresDedicatedAllocation, prefersDedicatedAllocation);
+ requiresDedicatedAllocation, prefersDedicatedAllocation);
VkResult result = allocator->AllocateMemory(
+ vkMemReq,
+ requiresDedicatedAllocation,
+ prefersDedicatedAllocation,
+ VK_NULL_HANDLE, // dedicatedBuffer
+ image, // dedicatedImage
+ *pCreateInfo,
+ VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN,
+ 1, // allocationCount
+ pAllocation);
+
+#if VMA_RECORDING_ENABLED
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
+ allocator->GetRecorder()->RecordAllocateMemoryForImage(
+ allocator->GetCurrentFrameIndex(),
vkMemReq,
requiresDedicatedAllocation,
prefersDedicatedAllocation,
- VK_NULL_HANDLE, // dedicatedBuffer
- image, // dedicatedImage
*pCreateInfo,
- VMA_SUBALLOCATION_TYPE_IMAGE_UNKNOWN,
- 1, // allocationCount
- pAllocation);
-
-#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
- allocator->GetRecorder()->RecordAllocateMemoryForImage(
- allocator->GetCurrentFrameIndex(),
- vkMemReq,
- requiresDedicatedAllocation,
- prefersDedicatedAllocation,
- *pCreateInfo,
- *pAllocation);
+ *pAllocation);
}
#endif
- if (pAllocationInfo && result == VK_SUCCESS) {
+ if(pAllocationInfo && result == VK_SUCCESS)
+ {
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
}
return result;
}
-void vmaFreeMemory(
- VmaAllocator allocator,
- VmaAllocation allocation) {
+VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation)
+{
VMA_ASSERT(allocator);
-
- if (allocation == VK_NULL_HANDLE) {
+
+ if(allocation == VK_NULL_HANDLE)
+ {
return;
}
-
+
VMA_DEBUG_LOG("vmaFreeMemory");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordFreeMemory(
- allocator->GetCurrentFrameIndex(),
- allocation);
+ allocator->GetCurrentFrameIndex(),
+ allocation);
}
#endif
-
+
allocator->FreeMemory(
- 1, // allocationCount
- &allocation);
+ 1, // allocationCount
+ &allocation);
}
-void vmaFreeMemoryPages(
- VmaAllocator allocator,
- size_t allocationCount,
- VmaAllocation *pAllocations) {
- if (allocationCount == 0) {
+VMA_CALL_PRE void VMA_CALL_POST vmaFreeMemoryPages(
+ VmaAllocator allocator,
+ size_t allocationCount,
+ VmaAllocation* pAllocations)
+{
+ if(allocationCount == 0)
+ {
return;
}
VMA_ASSERT(allocator);
-
+
VMA_DEBUG_LOG("vmaFreeMemoryPages");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordFreeMemoryPages(
- allocator->GetCurrentFrameIndex(),
- (uint64_t)allocationCount,
- pAllocations);
+ allocator->GetCurrentFrameIndex(),
+ (uint64_t)allocationCount,
+ pAllocations);
}
#endif
-
+
allocator->FreeMemory(allocationCount, pAllocations);
}
-VkResult vmaResizeAllocation(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VkDeviceSize newSize) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaResizeAllocation(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkDeviceSize newSize)
+{
VMA_ASSERT(allocator && allocation);
-
+
VMA_DEBUG_LOG("vmaResizeAllocation");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
-#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
- allocator->GetRecorder()->RecordResizeAllocation(
- allocator->GetCurrentFrameIndex(),
- allocation,
- newSize);
- }
-#endif
-
return allocator->ResizeAllocation(allocation, newSize);
}
-void vmaGetAllocationInfo(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VmaAllocationInfo *pAllocationInfo) {
+VMA_CALL_PRE void VMA_CALL_POST vmaGetAllocationInfo(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VmaAllocationInfo* pAllocationInfo)
+{
VMA_ASSERT(allocator && allocation && pAllocationInfo);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordGetAllocationInfo(
- allocator->GetCurrentFrameIndex(),
- allocation);
+ allocator->GetCurrentFrameIndex(),
+ allocation);
}
#endif
allocator->GetAllocationInfo(allocation, pAllocationInfo);
}
-VkBool32 vmaTouchAllocation(
- VmaAllocator allocator,
- VmaAllocation allocation) {
+VMA_CALL_PRE VkBool32 VMA_CALL_POST vmaTouchAllocation(
+ VmaAllocator allocator,
+ VmaAllocation allocation)
+{
VMA_ASSERT(allocator && allocation);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordTouchAllocation(
- allocator->GetCurrentFrameIndex(),
- allocation);
+ allocator->GetCurrentFrameIndex(),
+ allocation);
}
#endif
return allocator->TouchAllocation(allocation);
}
-void vmaSetAllocationUserData(
- VmaAllocator allocator,
- VmaAllocation allocation,
- void *pUserData) {
+VMA_CALL_PRE void VMA_CALL_POST vmaSetAllocationUserData(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ void* pUserData)
+{
VMA_ASSERT(allocator && allocation);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
@@ -14957,18 +17649,20 @@ void vmaSetAllocationUserData(
allocation->SetUserData(allocator, pUserData);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordSetAllocationUserData(
- allocator->GetCurrentFrameIndex(),
- allocation,
- pUserData);
+ allocator->GetCurrentFrameIndex(),
+ allocation,
+ pUserData);
}
#endif
}
-void vmaCreateLostAllocation(
- VmaAllocator allocator,
- VmaAllocation *pAllocation) {
+VMA_CALL_PRE void VMA_CALL_POST vmaCreateLostAllocation(
+ VmaAllocator allocator,
+ VmaAllocation* pAllocation)
+{
VMA_ASSERT(allocator && pAllocation);
VMA_DEBUG_GLOBAL_MUTEX_LOCK;
@@ -14976,18 +17670,20 @@ void vmaCreateLostAllocation(
allocator->CreateLostAllocation(pAllocation);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordCreateLostAllocation(
- allocator->GetCurrentFrameIndex(),
- *pAllocation);
+ allocator->GetCurrentFrameIndex(),
+ *pAllocation);
}
#endif
}
-VkResult vmaMapMemory(
- VmaAllocator allocator,
- VmaAllocation allocation,
- void **ppData) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaMapMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ void** ppData)
+{
VMA_ASSERT(allocator && allocation && ppData);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
@@ -14995,35 +17691,39 @@ VkResult vmaMapMemory(
VkResult res = allocator->Map(allocation, ppData);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordMapMemory(
- allocator->GetCurrentFrameIndex(),
- allocation);
+ allocator->GetCurrentFrameIndex(),
+ allocation);
}
#endif
return res;
}
-void vmaUnmapMemory(
- VmaAllocator allocator,
- VmaAllocation allocation) {
+VMA_CALL_PRE void VMA_CALL_POST vmaUnmapMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation)
+{
VMA_ASSERT(allocator && allocation);
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordUnmapMemory(
- allocator->GetCurrentFrameIndex(),
- allocation);
+ allocator->GetCurrentFrameIndex(),
+ allocation);
}
#endif
allocator->Unmap(allocation);
}
-void vmaFlushAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size) {
+VMA_CALL_PRE void VMA_CALL_POST vmaFlushAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
+{
VMA_ASSERT(allocator && allocation);
VMA_DEBUG_LOG("vmaFlushAllocation");
@@ -15033,15 +17733,17 @@ void vmaFlushAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDevi
allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_FLUSH);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordFlushAllocation(
- allocator->GetCurrentFrameIndex(),
- allocation, offset, size);
+ allocator->GetCurrentFrameIndex(),
+ allocation, offset, size);
}
#endif
}
-void vmaInvalidateAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size) {
+VMA_CALL_PRE void VMA_CALL_POST vmaInvalidateAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
+{
VMA_ASSERT(allocator && allocation);
VMA_DEBUG_LOG("vmaInvalidateAllocation");
@@ -15051,15 +17753,17 @@ void vmaInvalidateAllocation(VmaAllocator allocator, VmaAllocation allocation, V
allocator->FlushOrInvalidateAllocation(allocation, offset, size, VMA_CACHE_INVALIDATE);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordInvalidateAllocation(
- allocator->GetCurrentFrameIndex(),
- allocation, offset, size);
+ allocator->GetCurrentFrameIndex(),
+ allocation, offset, size);
}
#endif
}
-VkResult vmaCheckCorruption(VmaAllocator allocator, uint32_t memoryTypeBits) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCheckCorruption(VmaAllocator allocator, uint32_t memoryTypeBits)
+{
VMA_ASSERT(allocator);
VMA_DEBUG_LOG("vmaCheckCorruption");
@@ -15069,23 +17773,27 @@ VkResult vmaCheckCorruption(VmaAllocator allocator, uint32_t memoryTypeBits) {
return allocator->CheckCorruption(memoryTypeBits);
}
-VkResult vmaDefragment(
- VmaAllocator allocator,
- VmaAllocation *pAllocations,
- size_t allocationCount,
- VkBool32 *pAllocationsChanged,
- const VmaDefragmentationInfo *pDefragmentationInfo,
- VmaDefragmentationStats *pDefragmentationStats) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaDefragment(
+ VmaAllocator allocator,
+ VmaAllocation* pAllocations,
+ size_t allocationCount,
+ VkBool32* pAllocationsChanged,
+ const VmaDefragmentationInfo *pDefragmentationInfo,
+ VmaDefragmentationStats* pDefragmentationStats)
+{
// Deprecated interface, reimplemented using new one.
VmaDefragmentationInfo2 info2 = {};
info2.allocationCount = (uint32_t)allocationCount;
info2.pAllocations = pAllocations;
info2.pAllocationsChanged = pAllocationsChanged;
- if (pDefragmentationInfo != VMA_NULL) {
+ if(pDefragmentationInfo != VMA_NULL)
+ {
info2.maxCpuAllocationsToMove = pDefragmentationInfo->maxAllocationsToMove;
info2.maxCpuBytesToMove = pDefragmentationInfo->maxBytesToMove;
- } else {
+ }
+ else
+ {
info2.maxCpuAllocationsToMove = UINT32_MAX;
info2.maxCpuBytesToMove = VK_WHOLE_SIZE;
}
@@ -15093,21 +17801,24 @@ VkResult vmaDefragment(
VmaDefragmentationContext ctx;
VkResult res = vmaDefragmentationBegin(allocator, &info2, pDefragmentationStats, &ctx);
- if (res == VK_NOT_READY) {
- res = vmaDefragmentationEnd(allocator, ctx);
+ if(res == VK_NOT_READY)
+ {
+ res = vmaDefragmentationEnd( allocator, ctx);
}
return res;
}
-VkResult vmaDefragmentationBegin(
- VmaAllocator allocator,
- const VmaDefragmentationInfo2 *pInfo,
- VmaDefragmentationStats *pStats,
- VmaDefragmentationContext *pContext) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaDefragmentationBegin(
+ VmaAllocator allocator,
+ const VmaDefragmentationInfo2* pInfo,
+ VmaDefragmentationStats* pStats,
+ VmaDefragmentationContext *pContext)
+{
VMA_ASSERT(allocator && pInfo && pContext);
// Degenerate case: Nothing to defragment.
- if (pInfo->allocationCount == 0 && pInfo->poolCount == 0) {
+ if(pInfo->allocationCount == 0 && pInfo->poolCount == 0)
+ {
return VK_SUCCESS;
}
@@ -15123,79 +17834,158 @@ VkResult vmaDefragmentationBegin(
VkResult res = allocator->DefragmentationBegin(*pInfo, pStats, pContext);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordDefragmentationBegin(
- allocator->GetCurrentFrameIndex(), *pInfo, *pContext);
+ allocator->GetCurrentFrameIndex(), *pInfo, *pContext);
}
#endif
return res;
}
-VkResult vmaDefragmentationEnd(
- VmaAllocator allocator,
- VmaDefragmentationContext context) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaDefragmentationEnd(
+ VmaAllocator allocator,
+ VmaDefragmentationContext context)
+{
VMA_ASSERT(allocator);
VMA_DEBUG_LOG("vmaDefragmentationEnd");
- if (context != VK_NULL_HANDLE) {
+ if(context != VK_NULL_HANDLE)
+ {
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordDefragmentationEnd(
- allocator->GetCurrentFrameIndex(), context);
+ allocator->GetCurrentFrameIndex(), context);
}
#endif
return allocator->DefragmentationEnd(context);
- } else {
+ }
+ else
+ {
return VK_SUCCESS;
}
}
-VkResult vmaBindBufferMemory(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VkBuffer buffer) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBeginDefragmentationPass(
+ VmaAllocator allocator,
+ VmaDefragmentationContext context,
+ VmaDefragmentationPassInfo* pInfo
+ )
+{
+ VMA_ASSERT(allocator);
+ VMA_ASSERT(pInfo);
+ VMA_HEAVY_ASSERT(VmaValidatePointerArray(pInfo->moveCount, pInfo->pMoves));
+
+ VMA_DEBUG_LOG("vmaBeginDefragmentationPass");
+
+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+ if(context == VK_NULL_HANDLE)
+ {
+ pInfo->moveCount = 0;
+ return VK_SUCCESS;
+ }
+
+ return allocator->DefragmentationPassBegin(pInfo, context);
+}
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaEndDefragmentationPass(
+ VmaAllocator allocator,
+ VmaDefragmentationContext context)
+{
+ VMA_ASSERT(allocator);
+
+ VMA_DEBUG_LOG("vmaEndDefragmentationPass");
+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+ if(context == VK_NULL_HANDLE)
+ return VK_SUCCESS;
+
+ return allocator->DefragmentationPassEnd(context);
+}
+
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkBuffer buffer)
+{
VMA_ASSERT(allocator && allocation && buffer);
VMA_DEBUG_LOG("vmaBindBufferMemory");
VMA_DEBUG_GLOBAL_MUTEX_LOCK
- return allocator->BindBufferMemory(allocation, buffer);
+ return allocator->BindBufferMemory(allocation, 0, buffer, VMA_NULL);
}
-VkResult vmaBindImageMemory(
- VmaAllocator allocator,
- VmaAllocation allocation,
- VkImage image) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindBufferMemory2(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkDeviceSize allocationLocalOffset,
+ VkBuffer buffer,
+ const void* pNext)
+{
+ VMA_ASSERT(allocator && allocation && buffer);
+
+ VMA_DEBUG_LOG("vmaBindBufferMemory2");
+
+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+ return allocator->BindBufferMemory(allocation, allocationLocalOffset, buffer, pNext);
+}
+
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkImage image)
+{
VMA_ASSERT(allocator && allocation && image);
VMA_DEBUG_LOG("vmaBindImageMemory");
VMA_DEBUG_GLOBAL_MUTEX_LOCK
- return allocator->BindImageMemory(allocation, image);
+ return allocator->BindImageMemory(allocation, 0, image, VMA_NULL);
+}
+
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaBindImageMemory2(
+ VmaAllocator allocator,
+ VmaAllocation allocation,
+ VkDeviceSize allocationLocalOffset,
+ VkImage image,
+ const void* pNext)
+{
+ VMA_ASSERT(allocator && allocation && image);
+
+ VMA_DEBUG_LOG("vmaBindImageMemory2");
+
+ VMA_DEBUG_GLOBAL_MUTEX_LOCK
+
+ return allocator->BindImageMemory(allocation, allocationLocalOffset, image, pNext);
}
-VkResult vmaCreateBuffer(
- VmaAllocator allocator,
- const VkBufferCreateInfo *pBufferCreateInfo,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- VkBuffer *pBuffer,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBuffer(
+ VmaAllocator allocator,
+ const VkBufferCreateInfo* pBufferCreateInfo,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ VkBuffer* pBuffer,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo)
+{
VMA_ASSERT(allocator && pBufferCreateInfo && pAllocationCreateInfo && pBuffer && pAllocation);
- if (pBufferCreateInfo->size == 0) {
+ if(pBufferCreateInfo->size == 0)
+ {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
-
+
VMA_DEBUG_LOG("vmaCreateBuffer");
-
+
VMA_DEBUG_GLOBAL_MUTEX_LOCK
*pBuffer = VK_NULL_HANDLE;
@@ -15203,77 +17993,83 @@ VkResult vmaCreateBuffer(
// 1. Create VkBuffer.
VkResult res = (*allocator->GetVulkanFunctions().vkCreateBuffer)(
- allocator->m_hDevice,
- pBufferCreateInfo,
- allocator->GetAllocationCallbacks(),
- pBuffer);
- if (res >= 0) {
+ allocator->m_hDevice,
+ pBufferCreateInfo,
+ allocator->GetAllocationCallbacks(),
+ pBuffer);
+ if(res >= 0)
+ {
// 2. vkGetBufferMemoryRequirements.
VkMemoryRequirements vkMemReq = {};
bool requiresDedicatedAllocation = false;
- bool prefersDedicatedAllocation = false;
+ bool prefersDedicatedAllocation = false;
allocator->GetBufferMemoryRequirements(*pBuffer, vkMemReq,
- requiresDedicatedAllocation, prefersDedicatedAllocation);
+ requiresDedicatedAllocation, prefersDedicatedAllocation);
// Make sure alignment requirements for specific buffer usages reported
// in Physical Device Properties are included in alignment reported by memory requirements.
- if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) != 0) {
- VMA_ASSERT(vkMemReq.alignment %
- allocator->m_PhysicalDeviceProperties.limits.minTexelBufferOffsetAlignment ==
- 0);
+ if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) != 0)
+ {
+ VMA_ASSERT(vkMemReq.alignment %
+ allocator->m_PhysicalDeviceProperties.limits.minTexelBufferOffsetAlignment == 0);
}
- if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 0) {
- VMA_ASSERT(vkMemReq.alignment %
- allocator->m_PhysicalDeviceProperties.limits.minUniformBufferOffsetAlignment ==
- 0);
+ if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 0)
+ {
+ VMA_ASSERT(vkMemReq.alignment %
+ allocator->m_PhysicalDeviceProperties.limits.minUniformBufferOffsetAlignment == 0);
}
- if ((pBufferCreateInfo->usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) != 0) {
- VMA_ASSERT(vkMemReq.alignment %
- allocator->m_PhysicalDeviceProperties.limits.minStorageBufferOffsetAlignment ==
- 0);
+ if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) != 0)
+ {
+ VMA_ASSERT(vkMemReq.alignment %
+ allocator->m_PhysicalDeviceProperties.limits.minStorageBufferOffsetAlignment == 0);
}
// 3. Allocate memory using allocator.
res = allocator->AllocateMemory(
- vkMemReq,
- requiresDedicatedAllocation,
- prefersDedicatedAllocation,
- *pBuffer, // dedicatedBuffer
- VK_NULL_HANDLE, // dedicatedImage
- *pAllocationCreateInfo,
- VMA_SUBALLOCATION_TYPE_BUFFER,
- 1, // allocationCount
- pAllocation);
+ vkMemReq,
+ requiresDedicatedAllocation,
+ prefersDedicatedAllocation,
+ *pBuffer, // dedicatedBuffer
+ VK_NULL_HANDLE, // dedicatedImage
+ *pAllocationCreateInfo,
+ VMA_SUBALLOCATION_TYPE_BUFFER,
+ 1, // allocationCount
+ pAllocation);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordCreateBuffer(
- allocator->GetCurrentFrameIndex(),
- *pBufferCreateInfo,
- *pAllocationCreateInfo,
- *pAllocation);
+ allocator->GetCurrentFrameIndex(),
+ *pBufferCreateInfo,
+ *pAllocationCreateInfo,
+ *pAllocation);
}
#endif
- if (res >= 0) {
+ if(res >= 0)
+ {
// 3. Bind buffer with memory.
- if ((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0) {
- res = allocator->BindBufferMemory(*pAllocation, *pBuffer);
+ if((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0)
+ {
+ res = allocator->BindBufferMemory(*pAllocation, 0, *pBuffer, VMA_NULL);
}
- if (res >= 0) {
-// All steps succeeded.
-#if VMA_STATS_STRING_ENABLED
- (*pAllocation)->InitBufferImageUsage(pBufferCreateInfo->usage);
-#endif
- if (pAllocationInfo != VMA_NULL) {
+ if(res >= 0)
+ {
+ // All steps succeeded.
+ #if VMA_STATS_STRING_ENABLED
+ (*pAllocation)->InitBufferImageUsage(pBufferCreateInfo->usage);
+ #endif
+ if(pAllocationInfo != VMA_NULL)
+ {
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
}
return VK_SUCCESS;
}
allocator->FreeMemory(
- 1, // allocationCount
- pAllocation);
+ 1, // allocationCount
+ pAllocation);
*pAllocation = VK_NULL_HANDLE;
(*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, *pBuffer, allocator->GetAllocationCallbacks());
*pBuffer = VK_NULL_HANDLE;
@@ -15286,13 +18082,15 @@ VkResult vmaCreateBuffer(
return res;
}
-void vmaDestroyBuffer(
- VmaAllocator allocator,
- VkBuffer buffer,
- VmaAllocation allocation) {
+VMA_CALL_PRE void VMA_CALL_POST vmaDestroyBuffer(
+ VmaAllocator allocator,
+ VkBuffer buffer,
+ VmaAllocation allocation)
+{
VMA_ASSERT(allocator);
- if (buffer == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE) {
+ if(buffer == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE)
+ {
return;
}
@@ -15301,38 +18099,43 @@ void vmaDestroyBuffer(
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordDestroyBuffer(
- allocator->GetCurrentFrameIndex(),
- allocation);
+ allocator->GetCurrentFrameIndex(),
+ allocation);
}
#endif
- if (buffer != VK_NULL_HANDLE) {
+ if(buffer != VK_NULL_HANDLE)
+ {
(*allocator->GetVulkanFunctions().vkDestroyBuffer)(allocator->m_hDevice, buffer, allocator->GetAllocationCallbacks());
}
- if (allocation != VK_NULL_HANDLE) {
+ if(allocation != VK_NULL_HANDLE)
+ {
allocator->FreeMemory(
- 1, // allocationCount
- &allocation);
+ 1, // allocationCount
+ &allocation);
}
}
-VkResult vmaCreateImage(
- VmaAllocator allocator,
- const VkImageCreateInfo *pImageCreateInfo,
- const VmaAllocationCreateInfo *pAllocationCreateInfo,
- VkImage *pImage,
- VmaAllocation *pAllocation,
- VmaAllocationInfo *pAllocationInfo) {
+VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateImage(
+ VmaAllocator allocator,
+ const VkImageCreateInfo* pImageCreateInfo,
+ const VmaAllocationCreateInfo* pAllocationCreateInfo,
+ VkImage* pImage,
+ VmaAllocation* pAllocation,
+ VmaAllocationInfo* pAllocationInfo)
+{
VMA_ASSERT(allocator && pImageCreateInfo && pAllocationCreateInfo && pImage && pAllocation);
- if (pImageCreateInfo->extent.width == 0 ||
- pImageCreateInfo->extent.height == 0 ||
- pImageCreateInfo->extent.depth == 0 ||
- pImageCreateInfo->mipLevels == 0 ||
- pImageCreateInfo->arrayLayers == 0) {
+ if(pImageCreateInfo->extent.width == 0 ||
+ pImageCreateInfo->extent.height == 0 ||
+ pImageCreateInfo->extent.depth == 0 ||
+ pImageCreateInfo->mipLevels == 0 ||
+ pImageCreateInfo->arrayLayers == 0)
+ {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
@@ -15345,62 +18148,68 @@ VkResult vmaCreateImage(
// 1. Create VkImage.
VkResult res = (*allocator->GetVulkanFunctions().vkCreateImage)(
- allocator->m_hDevice,
- pImageCreateInfo,
- allocator->GetAllocationCallbacks(),
- pImage);
- if (res >= 0) {
+ allocator->m_hDevice,
+ pImageCreateInfo,
+ allocator->GetAllocationCallbacks(),
+ pImage);
+ if(res >= 0)
+ {
VmaSuballocationType suballocType = pImageCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL ?
- VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL :
- VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR;
-
+ VMA_SUBALLOCATION_TYPE_IMAGE_OPTIMAL :
+ VMA_SUBALLOCATION_TYPE_IMAGE_LINEAR;
+
// 2. Allocate memory using allocator.
VkMemoryRequirements vkMemReq = {};
bool requiresDedicatedAllocation = false;
- bool prefersDedicatedAllocation = false;
+ bool prefersDedicatedAllocation = false;
allocator->GetImageMemoryRequirements(*pImage, vkMemReq,
- requiresDedicatedAllocation, prefersDedicatedAllocation);
+ requiresDedicatedAllocation, prefersDedicatedAllocation);
res = allocator->AllocateMemory(
- vkMemReq,
- requiresDedicatedAllocation,
- prefersDedicatedAllocation,
- VK_NULL_HANDLE, // dedicatedBuffer
- *pImage, // dedicatedImage
- *pAllocationCreateInfo,
- suballocType,
- 1, // allocationCount
- pAllocation);
+ vkMemReq,
+ requiresDedicatedAllocation,
+ prefersDedicatedAllocation,
+ VK_NULL_HANDLE, // dedicatedBuffer
+ *pImage, // dedicatedImage
+ *pAllocationCreateInfo,
+ suballocType,
+ 1, // allocationCount
+ pAllocation);
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordCreateImage(
- allocator->GetCurrentFrameIndex(),
- *pImageCreateInfo,
- *pAllocationCreateInfo,
- *pAllocation);
+ allocator->GetCurrentFrameIndex(),
+ *pImageCreateInfo,
+ *pAllocationCreateInfo,
+ *pAllocation);
}
#endif
- if (res >= 0) {
+ if(res >= 0)
+ {
// 3. Bind image with memory.
- if ((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0) {
- res = allocator->BindImageMemory(*pAllocation, *pImage);
+ if((pAllocationCreateInfo->flags & VMA_ALLOCATION_CREATE_DONT_BIND_BIT) == 0)
+ {
+ res = allocator->BindImageMemory(*pAllocation, 0, *pImage, VMA_NULL);
}
- if (res >= 0) {
-// All steps succeeded.
-#if VMA_STATS_STRING_ENABLED
- (*pAllocation)->InitBufferImageUsage(pImageCreateInfo->usage);
-#endif
- if (pAllocationInfo != VMA_NULL) {
+ if(res >= 0)
+ {
+ // All steps succeeded.
+ #if VMA_STATS_STRING_ENABLED
+ (*pAllocation)->InitBufferImageUsage(pImageCreateInfo->usage);
+ #endif
+ if(pAllocationInfo != VMA_NULL)
+ {
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
}
return VK_SUCCESS;
}
allocator->FreeMemory(
- 1, // allocationCount
- pAllocation);
+ 1, // allocationCount
+ pAllocation);
*pAllocation = VK_NULL_HANDLE;
(*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, *pImage, allocator->GetAllocationCallbacks());
*pImage = VK_NULL_HANDLE;
@@ -15413,13 +18222,15 @@ VkResult vmaCreateImage(
return res;
}
-void vmaDestroyImage(
- VmaAllocator allocator,
- VkImage image,
- VmaAllocation allocation) {
+VMA_CALL_PRE void VMA_CALL_POST vmaDestroyImage(
+ VmaAllocator allocator,
+ VkImage image,
+ VmaAllocation allocation)
+{
VMA_ASSERT(allocator);
- if (image == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE) {
+ if(image == VK_NULL_HANDLE && allocation == VK_NULL_HANDLE)
+ {
return;
}
@@ -15428,20 +18239,23 @@ void vmaDestroyImage(
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
- if (allocator->GetRecorder() != VMA_NULL) {
+ if(allocator->GetRecorder() != VMA_NULL)
+ {
allocator->GetRecorder()->RecordDestroyImage(
- allocator->GetCurrentFrameIndex(),
- allocation);
+ allocator->GetCurrentFrameIndex(),
+ allocation);
}
#endif
- if (image != VK_NULL_HANDLE) {
+ if(image != VK_NULL_HANDLE)
+ {
(*allocator->GetVulkanFunctions().vkDestroyImage)(allocator->m_hDevice, image, allocator->GetAllocationCallbacks());
}
- if (allocation != VK_NULL_HANDLE) {
+ if(allocation != VK_NULL_HANDLE)
+ {
allocator->FreeMemory(
- 1, // allocationCount
- &allocation);
+ 1, // allocationCount
+ &allocation);
}
}