summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/unix/dir_access_unix.cpp26
-rw-r--r--drivers/unix/os_unix.cpp2
-rw-r--r--drivers/vulkan/rendering_device_vulkan.cpp102
-rw-r--r--drivers/vulkan/rendering_device_vulkan.h5
-rw-r--r--drivers/vulkan/vulkan_context.cpp6
-rw-r--r--drivers/vulkan/vulkan_context.h3
-rw-r--r--drivers/wasapi/audio_driver_wasapi.cpp146
-rw-r--r--drivers/wasapi/audio_driver_wasapi.h3
-rw-r--r--drivers/windows/dir_access_windows.cpp10
9 files changed, 259 insertions, 44 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index a2c9bae852..1754b47c85 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -71,7 +71,7 @@ Error DirAccessUnix::list_dir_begin() {
bool DirAccessUnix::file_exists(String p_file) {
GLOBAL_LOCK_FUNCTION
- if (p_file.is_rel_path()) {
+ if (p_file.is_relative_path()) {
p_file = current_dir.plus_file(p_file);
}
@@ -90,7 +90,7 @@ bool DirAccessUnix::file_exists(String p_file) {
bool DirAccessUnix::dir_exists(String p_dir) {
GLOBAL_LOCK_FUNCTION
- if (p_dir.is_rel_path()) {
+ if (p_dir.is_relative_path()) {
p_dir = get_current_dir().plus_file(p_dir);
}
@@ -105,7 +105,7 @@ bool DirAccessUnix::dir_exists(String p_dir) {
bool DirAccessUnix::is_readable(String p_dir) {
GLOBAL_LOCK_FUNCTION
- if (p_dir.is_rel_path()) {
+ if (p_dir.is_relative_path()) {
p_dir = get_current_dir().plus_file(p_dir);
}
@@ -116,7 +116,7 @@ bool DirAccessUnix::is_readable(String p_dir) {
bool DirAccessUnix::is_writable(String p_dir) {
GLOBAL_LOCK_FUNCTION
- if (p_dir.is_rel_path()) {
+ if (p_dir.is_relative_path()) {
p_dir = get_current_dir().plus_file(p_dir);
}
@@ -125,7 +125,7 @@ bool DirAccessUnix::is_writable(String p_dir) {
}
uint64_t DirAccessUnix::get_modified_time(String p_file) {
- if (p_file.is_rel_path()) {
+ if (p_file.is_relative_path()) {
p_file = current_dir.plus_file(p_file);
}
@@ -293,7 +293,7 @@ bool DirAccessUnix::drives_are_shortcuts() {
Error DirAccessUnix::make_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
- if (p_dir.is_rel_path()) {
+ if (p_dir.is_relative_path()) {
p_dir = get_current_dir().plus_file(p_dir);
}
@@ -328,7 +328,7 @@ Error DirAccessUnix::change_dir(String p_dir) {
// try_dir is the directory we are trying to change into
String try_dir = "";
- if (p_dir.is_rel_path()) {
+ if (p_dir.is_relative_path()) {
String next_dir = current_dir.plus_file(p_dir);
next_dir = next_dir.simplify_path();
try_dir = next_dir;
@@ -372,13 +372,13 @@ String DirAccessUnix::get_current_dir(bool p_include_drive) {
}
Error DirAccessUnix::rename(String p_path, String p_new_path) {
- if (p_path.is_rel_path()) {
+ if (p_path.is_relative_path()) {
p_path = get_current_dir().plus_file(p_path);
}
p_path = fix_path(p_path);
- if (p_new_path.is_rel_path()) {
+ if (p_new_path.is_relative_path()) {
p_new_path = get_current_dir().plus_file(p_new_path);
}
@@ -388,7 +388,7 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) {
}
Error DirAccessUnix::remove(String p_path) {
- if (p_path.is_rel_path()) {
+ if (p_path.is_relative_path()) {
p_path = get_current_dir().plus_file(p_path);
}
@@ -407,7 +407,7 @@ Error DirAccessUnix::remove(String p_path) {
}
bool DirAccessUnix::is_link(String p_file) {
- if (p_file.is_rel_path()) {
+ if (p_file.is_relative_path()) {
p_file = get_current_dir().plus_file(p_file);
}
@@ -422,7 +422,7 @@ bool DirAccessUnix::is_link(String p_file) {
}
String DirAccessUnix::read_link(String p_file) {
- if (p_file.is_rel_path()) {
+ if (p_file.is_relative_path()) {
p_file = get_current_dir().plus_file(p_file);
}
@@ -439,7 +439,7 @@ String DirAccessUnix::read_link(String p_file) {
}
Error DirAccessUnix::create_link(String p_source, String p_target) {
- if (p_target.is_rel_path()) {
+ if (p_target.is_relative_path()) {
p_target = get_current_dir().plus_file(p_target);
}
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index f6a3e93b55..3032c31629 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -392,7 +392,7 @@ String OS_Unix::get_locale() const {
Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
String path = p_path;
- if (FileAccess::exists(path) && path.is_rel_path()) {
+ if (FileAccess::exists(path) && path.is_relative_path()) {
// dlopen expects a slash, in this case a leading ./ for it to be interpreted as a relative path,
// otherwise it will end up searching various system directories for the lib instead and finally failing.
path = "./" + path;
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index 63510d261a..a4324f0a2c 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -2740,6 +2740,14 @@ bool RenderingDeviceVulkan::texture_is_valid(RID p_texture) {
return texture_owner.owns(p_texture);
}
+Size2i RenderingDeviceVulkan::texture_size(RID p_texture) {
+ _THREAD_SAFE_METHOD_
+
+ Texture *tex = texture_owner.getornull(p_texture);
+ ERR_FAIL_COND_V(!tex, Size2i());
+ return Size2i(tex->width, tex->height);
+}
+
Error RenderingDeviceVulkan::texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, uint32_t p_post_barrier) {
_THREAD_SAFE_METHOD_
@@ -7580,7 +7588,7 @@ Error RenderingDeviceVulkan::_draw_list_allocate(const Rect2i &p_viewport, uint3
VkCommandPoolCreateInfo cmd_pool_info;
cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
cmd_pool_info.pNext = nullptr;
- cmd_pool_info.queueFamilyIndex = context->get_graphics_queue();
+ cmd_pool_info.queueFamilyIndex = context->get_graphics_queue_family_index();
cmd_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
VkResult res = vkCreateCommandPool(device, &cmd_pool_info, nullptr, &split_draw_list_allocators.write[i].command_pool);
@@ -7957,13 +7965,13 @@ void RenderingDeviceVulkan::compute_list_bind_uniform_set(ComputeListID p_list,
textures_to_storage[i]->used_in_compute = false;
textures_to_storage[i]->used_in_raster = false;
- textures_to_storage[i]->used_in_compute = false;
+ textures_to_storage[i]->used_in_transfer = false;
} else {
src_access_flags = 0;
textures_to_storage[i]->used_in_compute = false;
textures_to_storage[i]->used_in_raster = false;
- textures_to_storage[i]->used_in_compute = false;
+ textures_to_storage[i]->used_in_transfer = false;
textures_to_storage[i]->used_in_frame = frames_drawn;
}
@@ -8838,7 +8846,7 @@ void RenderingDeviceVulkan::initialize(VulkanContext *p_context, bool p_local_de
VkCommandPoolCreateInfo cmd_pool_info;
cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
cmd_pool_info.pNext = nullptr;
- cmd_pool_info.queueFamilyIndex = p_context->get_graphics_queue();
+ cmd_pool_info.queueFamilyIndex = p_context->get_graphics_queue_family_index();
cmd_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
VkResult res = vkCreateCommandPool(device, &cmd_pool_info, nullptr, &frames[i].command_pool);
@@ -9008,6 +9016,92 @@ void RenderingDeviceVulkan::capture_timestamp(const String &p_name) {
frames[frame].timestamp_count++;
}
+uint64_t RenderingDeviceVulkan::get_driver_resource(DriverResource p_resource, RID p_rid, uint64_t p_index) {
+ _THREAD_SAFE_METHOD_
+
+ switch (p_resource) {
+ case DRIVER_RESOURCE_VULKAN_DEVICE: {
+ return (uint64_t)context->get_device();
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_PHYSICAL_DEVICE: {
+ return (uint64_t)context->get_physical_device();
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_INSTANCE: {
+ return (uint64_t)context->get_instance();
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_QUEUE: {
+ return (uint64_t)context->get_graphics_queue();
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_QUEUE_FAMILY_INDEX: {
+ return context->get_graphics_queue_family_index();
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_IMAGE: {
+ Texture *tex = texture_owner.getornull(p_rid);
+ ERR_FAIL_NULL_V(tex, 0);
+
+ return (uint64_t)tex->image;
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_IMAGE_VIEW: {
+ Texture *tex = texture_owner.getornull(p_rid);
+ ERR_FAIL_NULL_V(tex, 0);
+
+ return (uint64_t)tex->view;
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_IMAGE_NATIVE_TEXTURE_FORMAT: {
+ Texture *tex = texture_owner.getornull(p_rid);
+ ERR_FAIL_NULL_V(tex, 0);
+
+ return vulkan_formats[tex->format];
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_SAMPLER: {
+ VkSampler *sampler = sampler_owner.getornull(p_rid);
+ ERR_FAIL_NULL_V(sampler, 0);
+
+ return uint64_t(*sampler);
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_DESCRIPTOR_SET: {
+ UniformSet *uniform_set = uniform_set_owner.getornull(p_rid);
+ ERR_FAIL_NULL_V(uniform_set, 0);
+
+ return uint64_t(uniform_set->descriptor_set);
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_BUFFER: {
+ Buffer *buffer = nullptr;
+ if (vertex_buffer_owner.owns(p_rid)) {
+ buffer = vertex_buffer_owner.getornull(p_rid);
+ } else if (index_buffer_owner.owns(p_rid)) {
+ buffer = index_buffer_owner.getornull(p_rid);
+ } else if (uniform_buffer_owner.owns(p_rid)) {
+ buffer = uniform_buffer_owner.getornull(p_rid);
+ } else if (texture_buffer_owner.owns(p_rid)) {
+ buffer = &texture_buffer_owner.getornull(p_rid)->buffer;
+ } else if (storage_buffer_owner.owns(p_rid)) {
+ buffer = storage_buffer_owner.getornull(p_rid);
+ }
+
+ ERR_FAIL_NULL_V(buffer, 0);
+
+ return uint64_t(buffer->buffer);
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_COMPUTE_PIPELINE: {
+ ComputePipeline *compute_pipeline = compute_pipeline_owner.getornull(p_rid);
+ ERR_FAIL_NULL_V(compute_pipeline, 0);
+
+ return uint64_t(compute_pipeline->pipeline);
+ }; break;
+ case DRIVER_RESOURCE_VULKAN_RENDER_PIPELINE: {
+ RenderPipeline *render_pipeline = render_pipeline_owner.getornull(p_rid);
+ ERR_FAIL_NULL_V(render_pipeline, 0);
+
+ return uint64_t(render_pipeline->pipeline);
+ }; break;
+ default: {
+ // not supported for this driver
+ return 0;
+ }; break;
+ }
+}
+
uint32_t RenderingDeviceVulkan::get_captured_timestamps_count() const {
return frames[frame].timestamp_result_count;
}
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index 5ee2ca07f2..cf0b725cfc 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -813,7 +813,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
// When using split command lists, this is
// implemented internally using secondary command
// buffers. As they can be created in threads,
- // each needs it's own command pool.
+ // each needs its own command pool.
struct SplitDrawListAllocator {
VkCommandPool command_pool = VK_NULL_HANDLE;
@@ -1044,6 +1044,7 @@ public:
virtual bool texture_is_format_supported_for_usage(DataFormat p_format, uint32_t p_usage) const;
virtual bool texture_is_shared(RID p_texture);
virtual bool texture_is_valid(RID p_texture);
+ virtual Size2i texture_size(RID p_texture);
virtual Error texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, uint32_t p_post_barrier = BARRIER_MASK_ALL);
virtual Error texture_clear(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers, uint32_t p_post_barrier = BARRIER_MASK_ALL);
@@ -1226,6 +1227,8 @@ public:
virtual String get_device_name() 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);
+
RenderingDeviceVulkan();
~RenderingDeviceVulkan();
};
diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index 625c222b67..c14e3f0e93 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -2028,7 +2028,11 @@ int VulkanContext::get_swapchain_image_count() const {
return swapchainImageCount;
}
-uint32_t VulkanContext::get_graphics_queue() const {
+VkQueue VulkanContext::get_graphics_queue() const {
+ return graphics_queue;
+}
+
+uint32_t VulkanContext::get_graphics_queue_family_index() const {
return graphics_queue_family_index;
}
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h
index fe09d4c497..19ea806616 100644
--- a/drivers/vulkan/vulkan_context.h
+++ b/drivers/vulkan/vulkan_context.h
@@ -243,7 +243,8 @@ public:
VkPhysicalDevice get_physical_device();
VkInstance get_instance() { return inst; }
int get_swapchain_image_count() const;
- uint32_t get_graphics_queue() const;
+ VkQueue get_graphics_queue() const;
+ uint32_t get_graphics_queue_family_index() const;
void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);
int window_get_width(DisplayServer::WindowID p_window = 0);
diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp
index 43c8722b06..276fda2a8f 100644
--- a/drivers/wasapi/audio_driver_wasapi.cpp
+++ b/drivers/wasapi/audio_driver_wasapi.cpp
@@ -35,8 +35,60 @@
#include "core/config/project_settings.h"
#include "core/os/os.h"
+#include <stdint.h> // INT32_MAX
+
#include <functiondiscoverykeys.h>
+// Define IAudioClient3 if not already defined by MinGW headers
+#if defined __MINGW32__ || defined __MINGW64__
+
+#ifndef __IAudioClient3_FWD_DEFINED__
+#define __IAudioClient3_FWD_DEFINED__
+
+typedef interface IAudioClient3 IAudioClient3;
+
+#endif // __IAudioClient3_FWD_DEFINED__
+
+#ifndef __IAudioClient3_INTERFACE_DEFINED__
+#define __IAudioClient3_INTERFACE_DEFINED__
+
+MIDL_INTERFACE("7ED4EE07-8E67-4CD4-8C1A-2B7A5987AD42")
+IAudioClient3 : public IAudioClient2 {
+public:
+ virtual HRESULT STDMETHODCALLTYPE GetSharedModeEnginePeriod(
+ /* [annotation][in] */
+ _In_ const WAVEFORMATEX *pFormat,
+ /* [annotation][out] */
+ _Out_ UINT32 *pDefaultPeriodInFrames,
+ /* [annotation][out] */
+ _Out_ UINT32 *pFundamentalPeriodInFrames,
+ /* [annotation][out] */
+ _Out_ UINT32 *pMinPeriodInFrames,
+ /* [annotation][out] */
+ _Out_ UINT32 *pMaxPeriodInFrames) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE GetCurrentSharedModeEnginePeriod(
+ /* [unique][annotation][out] */
+ _Out_ WAVEFORMATEX * *ppFormat,
+ /* [annotation][out] */
+ _Out_ UINT32 * pCurrentPeriodInFrames) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE InitializeSharedAudioStream(
+ /* [annotation][in] */
+ _In_ DWORD StreamFlags,
+ /* [annotation][in] */
+ _In_ UINT32 PeriodInFrames,
+ /* [annotation][in] */
+ _In_ const WAVEFORMATEX *pFormat,
+ /* [annotation][in] */
+ _In_opt_ LPCGUID AudioSessionGuid) = 0;
+};
+__CRT_UUID_DECL(IAudioClient3, 0x7ED4EE07, 0x8E67, 0x4CD4, 0x8C, 0x1A, 0x2B, 0x7A, 0x59, 0x87, 0xAD, 0x42)
+
+#endif // __IAudioClient3_INTERFACE_DEFINED__
+
+#endif // __MINGW32__ || __MINGW64__
+
#ifndef PKEY_Device_FriendlyName
#undef DEFINE_PROPERTYKEY
@@ -51,6 +103,7 @@ DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
const IID IID_IAudioClient = __uuidof(IAudioClient);
+const IID IID_IAudioClient3 = __uuidof(IAudioClient3);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
@@ -221,7 +274,22 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
ERR_PRINT("WASAPI: RegisterEndpointNotificationCallback error");
}
- hr = device->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, (void **)&p_device->audio_client);
+ bool using_audio_client_3 = !p_capture; // IID_IAudioClient3 is only used for adjustable output latency (not input)
+ if (using_audio_client_3) {
+ hr = device->Activate(IID_IAudioClient3, CLSCTX_ALL, nullptr, (void **)&p_device->audio_client);
+ if (hr != S_OK) {
+ // IID_IAudioClient3 will never activate on OS versions before Windows 10.
+ // Older Windows versions should fall back gracefully.
+ using_audio_client_3 = false;
+ print_verbose("WASAPI: Couldn't activate device with IAudioClient3 interface, falling back to IAudioClient interface");
+ } else {
+ print_verbose("WASAPI: Activated device using IAudioClient3 interface");
+ }
+ }
+ if (!using_audio_client_3) {
+ hr = device->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, (void **)&p_device->audio_client);
+ }
+
SAFE_RELEASE(device)
if (reinit) {
@@ -232,6 +300,16 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
}
+ if (using_audio_client_3) {
+ AudioClientProperties audioProps;
+ audioProps.cbSize = sizeof(AudioClientProperties);
+ audioProps.bIsOffload = FALSE;
+ audioProps.eCategory = AudioCategory_GameEffects;
+
+ hr = ((IAudioClient3 *)p_device->audio_client)->SetClientProperties(&audioProps);
+ ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: SetClientProperties failed with error 0x" + String::num_uint64(hr, 16) + ".");
+ }
+
hr = p_device->audio_client->GetMixFormat(&pwfex);
ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
@@ -285,15 +363,55 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
}
}
- DWORD streamflags = 0;
- if ((DWORD)mix_rate != pwfex->nSamplesPerSec) {
- streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST;
- pwfex->nSamplesPerSec = mix_rate;
- pwfex->nAvgBytesPerSec = pwfex->nSamplesPerSec * pwfex->nChannels * (pwfex->wBitsPerSample / 8);
- }
+ if (!using_audio_client_3) {
+ DWORD streamflags = 0;
+ if ((DWORD)mix_rate != pwfex->nSamplesPerSec) {
+ streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST;
+ pwfex->nSamplesPerSec = mix_rate;
+ pwfex->nAvgBytesPerSec = pwfex->nSamplesPerSec * pwfex->nChannels * (pwfex->wBitsPerSample / 8);
+ }
+ hr = p_device->audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, p_capture ? REFTIMES_PER_SEC : 0, 0, pwfex, nullptr);
+ ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: Initialize failed with error 0x" + String::num_uint64(hr, 16) + ".");
+ UINT32 max_frames;
+ HRESULT hr = p_device->audio_client->GetBufferSize(&max_frames);
+ ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
- hr = p_device->audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, p_capture ? REFTIMES_PER_SEC : 0, 0, pwfex, nullptr);
- ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: Initialize failed with error 0x" + String::num_uint64(hr, 16) + ".");
+ // Due to WASAPI Shared Mode we have no control of the buffer size
+ buffer_frames = max_frames;
+ } else {
+ IAudioClient3 *device_audio_client_3 = (IAudioClient3 *)p_device->audio_client;
+
+ // AUDCLNT_STREAMFLAGS_RATEADJUST is an invalid flag with IAudioClient3, therefore we have to use
+ // the closest supported mix rate supported by the audio driver.
+ mix_rate = pwfex->nSamplesPerSec;
+ print_verbose("WASAPI: mix_rate = " + itos(mix_rate));
+
+ UINT32 default_period_frames, fundamental_period_frames, min_period_frames, max_period_frames;
+ hr = device_audio_client_3->GetSharedModeEnginePeriod(
+ pwfex,
+ &default_period_frames,
+ &fundamental_period_frames,
+ &min_period_frames,
+ &max_period_frames);
+ ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: GetSharedModeEnginePeriod failed with error 0x" + String::num_uint64(hr, 16) + ".");
+
+ // Period frames must be an integral multiple of fundamental_period_frames or IAudioClient3 initialization will fail,
+ // so we need to select the closest multiple to the user-specified latency.
+ UINT32 desired_period_frames = target_latency_ms * mix_rate / 1000;
+ UINT32 period_frames = (desired_period_frames / fundamental_period_frames) * fundamental_period_frames;
+ if (ABS((int64_t)period_frames - (int64_t)desired_period_frames) > ABS((int64_t)(period_frames + fundamental_period_frames) - (int64_t)desired_period_frames)) {
+ period_frames = period_frames + fundamental_period_frames;
+ }
+ period_frames = CLAMP(period_frames, min_period_frames, max_period_frames);
+ print_verbose("WASAPI: fundamental_period_frames = " + itos(fundamental_period_frames));
+ print_verbose("WASAPI: min_period_frames = " + itos(min_period_frames));
+ print_verbose("WASAPI: max_period_frames = " + itos(max_period_frames));
+ print_verbose("WASAPI: selected a period frame size of " + itos(period_frames));
+ buffer_frames = period_frames;
+
+ hr = device_audio_client_3->InitializeSharedAudioStream(0, period_frames, pwfex, nullptr);
+ ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: InitializeSharedAudioStream failed with error 0x" + String::num_uint64(hr, 16) + ".");
+ }
if (p_capture) {
hr = p_device->audio_client->GetService(IID_IAudioCaptureClient, (void **)&p_device->capture_client);
@@ -328,13 +446,6 @@ Error AudioDriverWASAPI::init_render_device(bool reinit) {
break;
}
- UINT32 max_frames;
- HRESULT hr = audio_output.audio_client->GetBufferSize(&max_frames);
- ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
-
- // Due to WASAPI Shared Mode we have no control of the buffer size
- buffer_frames = max_frames;
-
// Sample rate is independent of channels (ref: https://stackoverflow.com/questions/11048825/audio-sample-frequency-rely-on-channels)
samples_in.resize(buffer_frames * channels);
@@ -367,7 +478,6 @@ Error AudioDriverWASAPI::audio_device_finish(AudioDeviceWASAPI *p_device) {
if (p_device->audio_client) {
p_device->audio_client->Stop();
}
-
p_device->active = false;
}
@@ -389,6 +499,8 @@ Error AudioDriverWASAPI::finish_capture_device() {
Error AudioDriverWASAPI::init() {
mix_rate = GLOBAL_GET("audio/driver/mix_rate");
+ target_latency_ms = GLOBAL_GET("audio/driver/output_latency");
+
Error err = init_render_device();
if (err != OK) {
ERR_PRINT("WASAPI: init_render_device error");
diff --git a/drivers/wasapi/audio_driver_wasapi.h b/drivers/wasapi/audio_driver_wasapi.h
index b9b325f0fb..312b6a6781 100644
--- a/drivers/wasapi/audio_driver_wasapi.h
+++ b/drivers/wasapi/audio_driver_wasapi.h
@@ -71,6 +71,7 @@ class AudioDriverWASAPI : public AudioDriver {
unsigned int channels = 0;
int mix_rate = 0;
int buffer_frames = 0;
+ int target_latency_ms = 0;
bool thread_exited = false;
mutable bool exit_thread = false;
@@ -114,5 +115,5 @@ public:
AudioDriverWASAPI();
};
+#endif // WASAPI_ENABLED
#endif // AUDIO_DRIVER_WASAPI_H
-#endif
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp
index 325bae5b56..f7a5f7279e 100644
--- a/drivers/windows/dir_access_windows.cpp
+++ b/drivers/windows/dir_access_windows.cpp
@@ -155,7 +155,7 @@ Error DirAccessWindows::make_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
p_dir = fix_path(p_dir);
- if (p_dir.is_rel_path()) {
+ if (p_dir.is_relative_path()) {
p_dir = current_dir.plus_file(p_dir);
}
@@ -227,7 +227,7 @@ bool DirAccessWindows::file_exists(String p_file) {
bool DirAccessWindows::dir_exists(String p_dir) {
GLOBAL_LOCK_FUNCTION
- if (p_dir.is_rel_path()) {
+ if (p_dir.is_relative_path()) {
p_dir = get_current_dir().plus_file(p_dir);
}
@@ -242,13 +242,13 @@ bool DirAccessWindows::dir_exists(String p_dir) {
}
Error DirAccessWindows::rename(String p_path, String p_new_path) {
- if (p_path.is_rel_path()) {
+ if (p_path.is_relative_path()) {
p_path = get_current_dir().plus_file(p_path);
}
p_path = fix_path(p_path);
- if (p_new_path.is_rel_path()) {
+ if (p_new_path.is_relative_path()) {
p_new_path = get_current_dir().plus_file(p_new_path);
}
@@ -281,7 +281,7 @@ Error DirAccessWindows::rename(String p_path, String p_new_path) {
}
Error DirAccessWindows::remove(String p_path) {
- if (p_path.is_rel_path()) {
+ if (p_path.is_relative_path()) {
p_path = get_current_dir().plus_file(p_path);
}