diff --git a/doc/classes/RenderingDevice.xml b/doc/classes/RenderingDevice.xml
index 442dcc7d18b..a15028b3fce 100644
--- a/doc/classes/RenderingDevice.xml
+++ b/doc/classes/RenderingDevice.xml
@@ -654,6 +654,24 @@
+
+ Rendering device type does not match any of the other enum values or is unknown.
+
+
+ Rendering device is an integrated GPU, which is typically [i](but not always)[/i] slower than dedicated GPUs ([constant DEVICE_TYPE_DISCRETE_GPU]). On Android and iOS, the rendering device type is always considered to be [constant DEVICE_TYPE_INTEGRATED_GPU].
+
+
+ Rendering device is a dedicated GPU, which is typically [i](but not always)[/i] faster than integrated GPUs ([constant DEVICE_TYPE_INTEGRATED_GPU]).
+
+
+ Rendering device is an emulated GPU in a virtual environment. This is typically much slower than the host GPU, which means the expected performance level on a dedicated GPU will be roughly equivalent to [constant DEVICE_TYPE_INTEGRATED_GPU]. Virtual machine GPU passthrough (such as VFIO) will not report the device type as [constant DEVICE_TYPE_VIRTUAL_GPU]. Instead, the host GPU's device type will be reported as if the GPU was not emulated.
+
+
+ Rendering device is provided by software emulation (such as Lavapipe or [url=https://github.com/google/swiftshader]SwiftShader[/url]). This is the slowest kind of rendering device available; it's typically much slower than [constant DEVICE_TYPE_INTEGRATED_GPU].
+
+
+ Represents the size of the [enum DeviceType] enum.
+
diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml
index 0700650a915..3dc4f4799be 100644
--- a/doc/classes/RenderingServer.xml
+++ b/doc/classes/RenderingServer.xml
@@ -1232,6 +1232,13 @@
[b]Note:[/b] When running a headless or server binary, this function returns an empty string.
+
+
+
+ Returns the type of the video adapter. Since dedicated graphics cards from a given generation will [i]usually[/i] be significantly faster than integrated graphics made in the same generation, the device type can be used as a basis for automatic graphics settings adjustment. However, this is not always true, so make sure to provide users with a way to manually override graphics settings.
+ [b]Note:[/b] When using the OpenGL backend or when running in headless mode, this function always returns [constant RenderingDevice.DEVICE_TYPE_OTHER].
+
+
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index f19b4a0ce21..1a2d756ddd3 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -4465,6 +4465,10 @@ String RasterizerStorageGLES3::get_video_adapter_vendor() const {
return (const char *)glGetString(GL_VENDOR);
}
+RenderingDevice::DeviceType RasterizerStorageGLES3::get_video_adapter_type() const {
+ return RenderingDevice::DeviceType::DEVICE_TYPE_OTHER;
+}
+
void RasterizerStorageGLES3::initialize() {
RasterizerStorageGLES3::system_fbo = 0;
diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h
index 3f9f208964d..99fc2193c1a 100644
--- a/drivers/gles3/rasterizer_storage_gles3.h
+++ b/drivers/gles3/rasterizer_storage_gles3.h
@@ -1361,6 +1361,7 @@ public:
// int get_render_info(RS::RenderInfo p_info) override;
String get_video_adapter_name() const override;
String get_video_adapter_vendor() const override;
+ RenderingDevice::DeviceType get_video_adapter_type() const override;
void capture_timestamps_begin() override {}
void capture_timestamp(const String &p_name) override {}
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index 928ea73409c..9cfc62595c9 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -8525,6 +8525,11 @@ String RenderingDeviceVulkan::get_device_vendor_name() const {
String RenderingDeviceVulkan::get_device_name() const {
return context->get_device_name();
}
+
+RenderingDevice::DeviceType RenderingDeviceVulkan::get_device_type() const {
+ return context->get_device_type();
+}
+
String RenderingDeviceVulkan::get_device_pipeline_cache_uuid() const {
return context->get_device_pipeline_cache_uuid();
}
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index cf0b725cfc8..49a246c4a63 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -1225,6 +1225,7 @@ public:
virtual String get_device_vendor_name() const;
virtual String get_device_name() const;
+ virtual RenderingDevice::DeviceType get_device_type() const;
virtual String get_device_pipeline_cache_uuid() const;
virtual uint64_t get_driver_resource(DriverResource p_resource, RID p_rid = RID(), uint64_t p_index = 0);
diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index 5912f481ec5..680e13d8ea1 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -762,6 +762,7 @@ Error VulkanContext::_create_physical_device() {
{ 0, nullptr },
};
device_name = gpu_props.deviceName;
+ device_type = gpu_props.deviceType;
pipeline_cache_id = String::hex_encode_buffer(gpu_props.pipelineCacheUUID, VK_UUID_SIZE);
pipeline_cache_id += "-driver-" + itos(gpu_props.driverVersion);
{
@@ -2210,6 +2211,11 @@ String VulkanContext::get_device_vendor_name() const {
String VulkanContext::get_device_name() const {
return device_name;
}
+
+RenderingDevice::DeviceType VulkanContext::get_device_type() const {
+ return RenderingDevice::DeviceType(device_type);
+}
+
String VulkanContext::get_device_pipeline_cache_uuid() const {
return pipeline_cache_id;
}
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h
index ab2f6a3eb53..4c0fb682032 100644
--- a/drivers/vulkan/vulkan_context.h
+++ b/drivers/vulkan/vulkan_context.h
@@ -37,6 +37,7 @@
#include "core/templates/map.h"
#include "core/templates/rid_owner.h"
#include "servers/display_server.h"
+#include "servers/rendering/rendering_device.h"
#ifdef USE_VOLK
#include
@@ -101,6 +102,7 @@ private:
String device_vendor;
String device_name;
+ VkPhysicalDeviceType device_type;
String pipeline_cache_id;
uint32_t device_api_version = 0;
@@ -290,6 +292,7 @@ public:
String get_device_vendor_name() const;
String get_device_name() const;
+ RenderingDevice::DeviceType get_device_type() const;
String get_device_pipeline_cache_uuid() const;
void set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_mode);
diff --git a/servers/rendering/rasterizer_dummy.h b/servers/rendering/rasterizer_dummy.h
index 3451ea2d393..72158433d9c 100644
--- a/servers/rendering/rasterizer_dummy.h
+++ b/servers/rendering/rasterizer_dummy.h
@@ -700,6 +700,7 @@ public:
String get_video_adapter_name() const override { return String(); }
String get_video_adapter_vendor() const override { return String(); }
+ RenderingDevice::DeviceType get_video_adapter_type() const override { return RenderingDevice::DeviceType::DEVICE_TYPE_OTHER; }
static RendererStorage *base_singleton;
diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp
index 79728169aeb..a6c17ed0c8c 100644
--- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp
@@ -9529,10 +9529,15 @@ uint64_t RendererStorageRD::get_rendering_info(RS::RenderingInfo p_info) {
String RendererStorageRD::get_video_adapter_name() const {
return RenderingDevice::get_singleton()->get_device_name();
}
+
String RendererStorageRD::get_video_adapter_vendor() const {
return RenderingDevice::get_singleton()->get_device_vendor_name();
}
+RenderingDevice::DeviceType RendererStorageRD::get_video_adapter_type() const {
+ return RenderingDevice::get_singleton()->get_device_type();
+}
+
RendererStorageRD *RendererStorageRD::base_singleton = nullptr;
RendererStorageRD::RendererStorageRD() {
diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.h b/servers/rendering/renderer_rd/renderer_storage_rd.h
index 9a64480c3e1..e918aec32f7 100644
--- a/servers/rendering/renderer_rd/renderer_storage_rd.h
+++ b/servers/rendering/renderer_rd/renderer_storage_rd.h
@@ -2393,6 +2393,7 @@ public:
String get_video_adapter_name() const;
String get_video_adapter_vendor() const;
+ RenderingDevice::DeviceType get_video_adapter_type() const;
virtual void capture_timestamps_begin();
virtual void capture_timestamp(const String &p_name);
diff --git a/servers/rendering/renderer_storage.h b/servers/rendering/renderer_storage.h
index 8926bf24aa6..b385b7aefbf 100644
--- a/servers/rendering/renderer_storage.h
+++ b/servers/rendering/renderer_storage.h
@@ -620,6 +620,7 @@ public:
virtual uint64_t get_rendering_info(RS::RenderingInfo p_info) = 0;
virtual String get_video_adapter_name() const = 0;
virtual String get_video_adapter_vendor() const = 0;
+ virtual RenderingDevice::DeviceType get_video_adapter_type() const = 0;
static RendererStorage *base_singleton;
diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp
index 38f57b46246..348a470497d 100644
--- a/servers/rendering/rendering_device.cpp
+++ b/servers/rendering/rendering_device.cpp
@@ -490,6 +490,13 @@ void RenderingDevice::_bind_methods() {
BIND_CONSTANT(BARRIER_MASK_ALL);
BIND_CONSTANT(BARRIER_MASK_NO_BARRIER);
+ BIND_ENUM_CONSTANT(DEVICE_TYPE_OTHER);
+ BIND_ENUM_CONSTANT(DEVICE_TYPE_INTEGRATED_GPU);
+ BIND_ENUM_CONSTANT(DEVICE_TYPE_DISCRETE_GPU);
+ BIND_ENUM_CONSTANT(DEVICE_TYPE_VIRTUAL_GPU);
+ BIND_ENUM_CONSTANT(DEVICE_TYPE_CPU);
+ BIND_ENUM_CONSTANT(DEVICE_TYPE_MAX);
+
BIND_ENUM_CONSTANT(DRIVER_RESOURCE_VULKAN_DEVICE);
BIND_ENUM_CONSTANT(DRIVER_RESOURCE_VULKAN_PHYSICAL_DEVICE);
BIND_ENUM_CONSTANT(DRIVER_RESOURCE_VULKAN_INSTANCE);
diff --git a/servers/rendering/rendering_device.h b/servers/rendering/rendering_device.h
index 563a80c12c6..9f52847e360 100644
--- a/servers/rendering/rendering_device.h
+++ b/servers/rendering/rendering_device.h
@@ -60,6 +60,17 @@ public:
DEVICE_DIRECTX
};
+ // This enum matches VkPhysicalDeviceType (except for `DEVICE_TYPE_MAX`).
+ // Unlike VkPhysicalDeviceType, DeviceType is exposed to the scripting API.
+ enum DeviceType {
+ DEVICE_TYPE_OTHER,
+ DEVICE_TYPE_INTEGRATED_GPU,
+ DEVICE_TYPE_DISCRETE_GPU,
+ DEVICE_TYPE_VIRTUAL_GPU,
+ DEVICE_TYPE_CPU,
+ DEVICE_TYPE_MAX,
+ };
+
enum DriverResource {
DRIVER_RESOURCE_VULKAN_DEVICE = 0,
DRIVER_RESOURCE_VULKAN_PHYSICAL_DEVICE,
@@ -1199,6 +1210,7 @@ public:
virtual String get_device_vendor_name() const = 0;
virtual String get_device_name() const = 0;
+ virtual RenderingDevice::DeviceType get_device_type() const = 0;
virtual String get_device_pipeline_cache_uuid() const = 0;
virtual uint64_t get_driver_resource(DriverResource p_resource, RID p_rid = RID(), uint64_t p_index = 0) = 0;
@@ -1237,6 +1249,7 @@ protected:
Vector _draw_list_switch_to_next_pass_split(uint32_t p_splits);
};
+VARIANT_ENUM_CAST(RenderingDevice::DeviceType)
VARIANT_ENUM_CAST(RenderingDevice::DriverResource)
VARIANT_ENUM_CAST(RenderingDevice::ShaderStage)
VARIANT_ENUM_CAST(RenderingDevice::ShaderLanguage)
diff --git a/servers/rendering/rendering_server_default.cpp b/servers/rendering/rendering_server_default.cpp
index 2ce9a20b6bc..bb52e6c46ac 100644
--- a/servers/rendering/rendering_server_default.cpp
+++ b/servers/rendering/rendering_server_default.cpp
@@ -255,6 +255,10 @@ String RenderingServerDefault::get_video_adapter_vendor() const {
return RSG::storage->get_video_adapter_vendor();
}
+RenderingDevice::DeviceType RenderingServerDefault::get_video_adapter_type() const {
+ return RSG::storage->get_video_adapter_type();
+}
+
void RenderingServerDefault::set_frame_profiling_enabled(bool p_enable) {
RSG::storage->capturing_timestamps = p_enable;
}
diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h
index b50631bb216..27a61f67922 100644
--- a/servers/rendering/rendering_server_default.h
+++ b/servers/rendering/rendering_server_default.h
@@ -891,6 +891,7 @@ public:
virtual uint64_t get_rendering_info(RenderingInfo p_info) override;
virtual String get_video_adapter_name() const override;
virtual String get_video_adapter_vendor() const override;
+ virtual RenderingDevice::DeviceType get_video_adapter_type() const override;
virtual void set_frame_profiling_enabled(bool p_enable) override;
virtual Vector get_frame_profile() override;
diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp
index 23d3bf030f7..88e2acad8ef 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -2711,6 +2711,7 @@ void RenderingServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_rendering_info", "info"), &RenderingServer::get_rendering_info);
ClassDB::bind_method(D_METHOD("get_video_adapter_name"), &RenderingServer::get_video_adapter_name);
ClassDB::bind_method(D_METHOD("get_video_adapter_vendor"), &RenderingServer::get_video_adapter_vendor);
+ ClassDB::bind_method(D_METHOD("get_video_adapter_type"), &RenderingServer::get_video_adapter_type);
ClassDB::bind_method(D_METHOD("make_sphere_mesh", "latitudes", "longitudes", "radius"), &RenderingServer::make_sphere_mesh);
ClassDB::bind_method(D_METHOD("get_test_cube"), &RenderingServer::get_test_cube);
diff --git a/servers/rendering_server.h b/servers/rendering_server.h
index 230132651fb..3919bf74c90 100644
--- a/servers/rendering_server.h
+++ b/servers/rendering_server.h
@@ -1473,6 +1473,7 @@ public:
virtual uint64_t get_rendering_info(RenderingInfo p_info) = 0;
virtual String get_video_adapter_name() const = 0;
virtual String get_video_adapter_vendor() const = 0;
+ virtual RenderingDevice::DeviceType get_video_adapter_type() const = 0;
struct FrameProfileArea {
String name;