feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -0,0 +1,72 @@
|
|||
/**************************************************************************/
|
||||
/* openxr_metal_extension.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef OPENXR_METAL_EXTENSION_H
|
||||
#define OPENXR_METAL_EXTENSION_H
|
||||
|
||||
#include "../../openxr_api.h"
|
||||
#include "../../util.h"
|
||||
#include "../openxr_extension_wrapper.h"
|
||||
|
||||
#include "core/templates/vector.h"
|
||||
|
||||
// Always include this as late as possible.
|
||||
#include "../../openxr_platform_inc.h"
|
||||
|
||||
class OpenXRMetalExtension : public OpenXRGraphicsExtensionWrapper {
|
||||
public:
|
||||
virtual HashMap<String, bool *> get_requested_extensions() override;
|
||||
|
||||
virtual void on_instance_created(const XrInstance p_instance) override;
|
||||
virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer) override;
|
||||
|
||||
virtual void get_usable_swapchain_formats(Vector<int64_t> &p_usable_swap_chains) override;
|
||||
virtual void get_usable_depth_formats(Vector<int64_t> &p_usable_swap_chains) override;
|
||||
virtual String get_swapchain_format_name(int64_t p_swapchain_format) const override;
|
||||
virtual bool get_swapchain_image_data(XrSwapchain p_swapchain, int64_t p_swapchain_format, uint32_t p_width, uint32_t p_height, uint32_t p_sample_count, uint32_t p_array_size, void **r_swapchain_graphics_data) override;
|
||||
virtual void cleanup_swapchain_graphics_data(void **p_swapchain_graphics_data) override;
|
||||
virtual bool create_projection_fov(const XrFovf p_fov, double p_z_near, double p_z_far, Projection &r_camera_matrix) override;
|
||||
virtual RID get_texture(void *p_swapchain_graphics_data, int p_image_index) override;
|
||||
|
||||
private:
|
||||
static XrGraphicsBindingMetalKHR graphics_binding_metal;
|
||||
|
||||
struct SwapchainGraphicsData {
|
||||
bool is_multiview;
|
||||
Vector<RID> texture_rids;
|
||||
};
|
||||
|
||||
bool check_graphics_api_support();
|
||||
|
||||
EXT_PROTO_XRRESULT_FUNC3(xrGetMetalGraphicsRequirementsKHR, (XrInstance), p_instance, (XrSystemId), p_system_id, (XrGraphicsRequirementsMetalKHR *), p_graphics_requirements)
|
||||
EXT_PROTO_XRRESULT_FUNC4(xrEnumerateSwapchainImages, (XrSwapchain), p_swapchain, (uint32_t), p_image_capacity_input, (uint32_t *), p_image_count_output, (XrSwapchainImageBaseHeader *), p_images)
|
||||
};
|
||||
|
||||
#endif // OPENXR_METAL_EXTENSION_H
|
||||
|
|
@ -0,0 +1,318 @@
|
|||
/**************************************************************************/
|
||||
/* openxr_metal_extension.mm */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "openxr_metal_extension.h"
|
||||
|
||||
#include "../../openxr_util.h"
|
||||
#include "drivers/metal/rendering_device_driver_metal.h"
|
||||
#include "servers/rendering/rendering_server_globals.h"
|
||||
|
||||
HashMap<String, bool *> OpenXRMetalExtension::get_requested_extensions() {
|
||||
HashMap<String, bool *> request_extensions;
|
||||
|
||||
request_extensions[XR_KHR_METAL_ENABLE_EXTENSION_NAME] = nullptr;
|
||||
|
||||
return request_extensions;
|
||||
}
|
||||
|
||||
void OpenXRMetalExtension::on_instance_created(const XrInstance p_instance) {
|
||||
// Obtain pointers to functions we're accessing here.
|
||||
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
|
||||
|
||||
EXT_INIT_XR_FUNC(xrGetMetalGraphicsRequirementsKHR);
|
||||
EXT_INIT_XR_FUNC(xrEnumerateSwapchainImages);
|
||||
}
|
||||
|
||||
bool OpenXRMetalExtension::check_graphics_api_support() {
|
||||
ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
|
||||
|
||||
// TODO We may need to do a callback like we do in Vulkan where we run this first
|
||||
// and provide the obtained metalDevice to our Metal driver to use.
|
||||
// But according to Stuart Macs only have 1 device so it should always be the
|
||||
// same one and we should be able to get away with not doing this just yet.
|
||||
// If we do go forward with this, this means that just like with Vulkan,
|
||||
// we have to start with OpenXR before Metal can be setup, and we thus
|
||||
// can't support applications that want to add XR as an optional/temporary
|
||||
// feature that users enable when needed.
|
||||
|
||||
XrSystemId system_id = OpenXRAPI::get_singleton()->get_system_id();
|
||||
XrInstance instance = OpenXRAPI::get_singleton()->get_instance();
|
||||
|
||||
XrGraphicsRequirementsMetalKHR metal_requirements;
|
||||
metal_requirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_METAL_KHR;
|
||||
metal_requirements.next = nullptr;
|
||||
metal_requirements.metalDevice = nullptr;
|
||||
|
||||
XrResult result = xrGetMetalGraphicsRequirementsKHR(instance, system_id, &metal_requirements);
|
||||
if (!OpenXRAPI::get_singleton()->xr_result(result, "Failed to get Metal graphics requirements!")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// See what metal device we are using...
|
||||
RenderingServer *rendering_server = RenderingServer::get_singleton();
|
||||
ERR_FAIL_NULL_V(rendering_server, false);
|
||||
RenderingDevice *rendering_device = rendering_server->get_rendering_device();
|
||||
ERR_FAIL_NULL_V(rendering_device, false);
|
||||
|
||||
void *our_metal_device = (void *)rendering_device->get_driver_resource(RD::DRIVER_RESOURCE_LOGICAL_DEVICE);
|
||||
|
||||
// Make sure we're using the same one.
|
||||
ERR_FAIL_COND_V(metal_requirements.metalDevice != our_metal_device, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
XrGraphicsBindingMetalKHR OpenXRMetalExtension::graphics_binding_metal;
|
||||
|
||||
void *OpenXRMetalExtension::set_session_create_and_get_next_pointer(void *p_next_pointer) {
|
||||
if (!check_graphics_api_support()) {
|
||||
return p_next_pointer;
|
||||
}
|
||||
|
||||
RenderingServer *rendering_server = RenderingServer::get_singleton();
|
||||
ERR_FAIL_NULL_V(rendering_server, p_next_pointer);
|
||||
RenderingDevice *rendering_device = rendering_server->get_rendering_device();
|
||||
ERR_FAIL_NULL_V(rendering_device, p_next_pointer);
|
||||
|
||||
graphics_binding_metal.type = XR_TYPE_GRAPHICS_BINDING_METAL_KHR;
|
||||
graphics_binding_metal.next = p_next_pointer;
|
||||
graphics_binding_metal.commandQueue = (void *)rendering_device->get_driver_resource(RD::DRIVER_RESOURCE_COMMAND_QUEUE);
|
||||
|
||||
return &graphics_binding_metal;
|
||||
}
|
||||
|
||||
void OpenXRMetalExtension::get_usable_swapchain_formats(Vector<int64_t> &p_usable_swap_chains) {
|
||||
p_usable_swap_chains.push_back(MTLPixelFormatRGBA8Unorm_sRGB);
|
||||
p_usable_swap_chains.push_back(MTLPixelFormatBGRA8Unorm_sRGB);
|
||||
p_usable_swap_chains.push_back(MTLPixelFormatRGBA8Uint);
|
||||
}
|
||||
|
||||
void OpenXRMetalExtension::get_usable_depth_formats(Vector<int64_t> &p_usable_swap_chains) {
|
||||
p_usable_swap_chains.push_back(MTLPixelFormatDepth24Unorm_Stencil8);
|
||||
p_usable_swap_chains.push_back(MTLPixelFormatDepth32Float_Stencil8);
|
||||
p_usable_swap_chains.push_back(MTLPixelFormatDepth32Float);
|
||||
}
|
||||
|
||||
#define ENUM_TO_STRING_CASE(m_e) \
|
||||
case m_e: { \
|
||||
return String(#m_e); \
|
||||
} break;
|
||||
|
||||
String OpenXRMetalExtension::get_swapchain_format_name(int64_t p_swapchain_format) const {
|
||||
// This really should be in vulkan_context...
|
||||
MTLPixelFormat format = MTLPixelFormat(p_swapchain_format);
|
||||
switch (format) {
|
||||
ENUM_TO_STRING_CASE(MTLPixelFormatRGBA8Unorm)
|
||||
ENUM_TO_STRING_CASE(MTLPixelFormatRGBA8Unorm_sRGB)
|
||||
ENUM_TO_STRING_CASE(MTLPixelFormatBGRA8Unorm)
|
||||
ENUM_TO_STRING_CASE(MTLPixelFormatBGRA8Unorm_sRGB)
|
||||
ENUM_TO_STRING_CASE(MTLPixelFormatRGBA8Uint)
|
||||
ENUM_TO_STRING_CASE(MTLPixelFormatDepth24Unorm_Stencil8)
|
||||
ENUM_TO_STRING_CASE(MTLPixelFormatDepth32Float_Stencil8)
|
||||
ENUM_TO_STRING_CASE(MTLPixelFormatDepth32Float)
|
||||
default: {
|
||||
return String("Swapchain format ") + String::num_int64(int64_t(p_swapchain_format));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenXRMetalExtension::get_swapchain_image_data(XrSwapchain p_swapchain, int64_t p_swapchain_format, uint32_t p_width, uint32_t p_height, uint32_t p_sample_count, uint32_t p_array_size, void **r_swapchain_graphics_data) {
|
||||
LocalVector<XrSwapchainImageMetalKHR, uint32_t, false, true> images;
|
||||
|
||||
RenderingServer *rendering_server = RenderingServer::get_singleton();
|
||||
ERR_FAIL_NULL_V(rendering_server, false);
|
||||
RenderingDevice *rendering_device = rendering_server->get_rendering_device();
|
||||
ERR_FAIL_NULL_V(rendering_device, false);
|
||||
|
||||
uint32_t swapchain_length;
|
||||
XrResult result = xrEnumerateSwapchainImages(p_swapchain, 0, &swapchain_length, nullptr);
|
||||
if (XR_FAILED(result)) {
|
||||
print_line("OpenXR: Failed to get swapchaim image count [", OpenXRAPI::get_singleton()->get_error_string(result), "]");
|
||||
return false;
|
||||
}
|
||||
|
||||
images.resize(swapchain_length);
|
||||
|
||||
for (XrSwapchainImageMetalKHR &image : images) {
|
||||
image.type = XR_TYPE_SWAPCHAIN_IMAGE_METAL_KHR;
|
||||
image.next = nullptr;
|
||||
image.texture = nullptr;
|
||||
}
|
||||
|
||||
result = xrEnumerateSwapchainImages(p_swapchain, swapchain_length, &swapchain_length, (XrSwapchainImageBaseHeader *)images.ptr());
|
||||
if (XR_FAILED(result)) {
|
||||
print_line("OpenXR: Failed to get swapchaim images [", OpenXRAPI::get_singleton()->get_error_string(result), "]");
|
||||
return false;
|
||||
}
|
||||
|
||||
SwapchainGraphicsData *data = memnew(SwapchainGraphicsData);
|
||||
if (data == nullptr) {
|
||||
print_line("OpenXR: Failed to allocate memory for swapchain data");
|
||||
return false;
|
||||
}
|
||||
*r_swapchain_graphics_data = data;
|
||||
data->is_multiview = (p_array_size > 1);
|
||||
|
||||
RenderingDevice::DataFormat format = RenderingDevice::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
RenderingDevice::TextureSamples samples = RenderingDevice::TEXTURE_SAMPLES_1;
|
||||
uint64_t usage_flags = RenderingDevice::TEXTURE_USAGE_SAMPLING_BIT;
|
||||
|
||||
switch (p_swapchain_format) {
|
||||
case MTLPixelFormatRGBA8Unorm_sRGB:
|
||||
// Even though this is an sRGB framebuffer format we're using UNORM here.
|
||||
// The reason here is because Godot does a linear to sRGB conversion while
|
||||
// with the sRGB format, this conversion would be doubled by the hardware.
|
||||
// This also means we're reading the values as is for our preview on screen.
|
||||
// The OpenXR runtime however is still treating this as an sRGB format and
|
||||
// will thus do an sRGB -> Linear conversion as expected.
|
||||
//format = RenderingDevice::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
format = RenderingDevice::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
usage_flags |= RenderingDevice::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
break;
|
||||
case MTLPixelFormatBGRA8Unorm_sRGB:
|
||||
format = RenderingDevice::DATA_FORMAT_B8G8R8A8_UNORM;
|
||||
usage_flags |= RenderingDevice::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
break;
|
||||
case MTLPixelFormatRGBA8Uint:
|
||||
format = RenderingDevice::DATA_FORMAT_R8G8B8A8_UINT;
|
||||
usage_flags |= RenderingDevice::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
break;
|
||||
case MTLPixelFormatDepth32Float:
|
||||
format = RenderingDevice::DATA_FORMAT_D32_SFLOAT;
|
||||
usage_flags |= RenderingDevice::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
break;
|
||||
case MTLPixelFormatDepth24Unorm_Stencil8:
|
||||
format = RenderingDevice::DATA_FORMAT_D24_UNORM_S8_UINT;
|
||||
usage_flags |= RenderingDevice::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
break;
|
||||
case MTLPixelFormatDepth32Float_Stencil8:
|
||||
format = RenderingDevice::DATA_FORMAT_D32_SFLOAT_S8_UINT;
|
||||
usage_flags |= RenderingDevice::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
break;
|
||||
default:
|
||||
// Continue with our default value.
|
||||
print_line("OpenXR: Unsupported swapchain format", p_swapchain_format);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (p_sample_count) {
|
||||
case 1:
|
||||
samples = RenderingDevice::TEXTURE_SAMPLES_1;
|
||||
break;
|
||||
case 2:
|
||||
samples = RenderingDevice::TEXTURE_SAMPLES_2;
|
||||
break;
|
||||
case 4:
|
||||
samples = RenderingDevice::TEXTURE_SAMPLES_4;
|
||||
break;
|
||||
case 8:
|
||||
samples = RenderingDevice::TEXTURE_SAMPLES_8;
|
||||
break;
|
||||
case 16:
|
||||
samples = RenderingDevice::TEXTURE_SAMPLES_16;
|
||||
break;
|
||||
case 32:
|
||||
samples = RenderingDevice::TEXTURE_SAMPLES_32;
|
||||
break;
|
||||
case 64:
|
||||
samples = RenderingDevice::TEXTURE_SAMPLES_64;
|
||||
break;
|
||||
default:
|
||||
// Continue with our default value.
|
||||
print_line("OpenXR: Unsupported sample count", p_sample_count);
|
||||
break;
|
||||
}
|
||||
|
||||
Vector<RID> texture_rids;
|
||||
|
||||
// Create Godot texture objects for each entry in our swapchain.
|
||||
for (uint64_t i = 0; i < swapchain_length; i++) {
|
||||
// Note, the formats we sent to render_device are ignored on metal.
|
||||
RID image_rid = rendering_device->texture_create_from_extension(
|
||||
p_array_size == 1 ? RenderingDevice::TEXTURE_TYPE_2D : RenderingDevice::TEXTURE_TYPE_2D_ARRAY,
|
||||
format,
|
||||
samples,
|
||||
usage_flags,
|
||||
(uint64_t)images[i].texture,
|
||||
p_width,
|
||||
p_height,
|
||||
1,
|
||||
p_array_size);
|
||||
|
||||
texture_rids.push_back(image_rid);
|
||||
}
|
||||
|
||||
data->texture_rids = texture_rids;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenXRMetalExtension::cleanup_swapchain_graphics_data(void **p_swapchain_graphics_data) {
|
||||
if (*p_swapchain_graphics_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
SwapchainGraphicsData *data = (SwapchainGraphicsData *)*p_swapchain_graphics_data;
|
||||
|
||||
RenderingServer *rendering_server = RenderingServer::get_singleton();
|
||||
ERR_FAIL_NULL(rendering_server);
|
||||
RenderingDevice *rendering_device = rendering_server->get_rendering_device();
|
||||
ERR_FAIL_NULL(rendering_device);
|
||||
|
||||
for (const RID &texture_rid : data->texture_rids) {
|
||||
rendering_device->free(texture_rid);
|
||||
}
|
||||
data->texture_rids.clear();
|
||||
|
||||
memdelete(data);
|
||||
*p_swapchain_graphics_data = nullptr;
|
||||
}
|
||||
|
||||
bool OpenXRMetalExtension::create_projection_fov(const XrFovf p_fov, double p_z_near, double p_z_far, Projection &r_camera_matrix) {
|
||||
// Even though this is a Metal renderer we're using OpenGL coordinate systems.
|
||||
OpenXRUtil::XrMatrix4x4f matrix;
|
||||
OpenXRUtil::XrMatrix4x4f_CreateProjectionFov(&matrix, OpenXRUtil::GRAPHICS_OPENGL, p_fov, (float)p_z_near, (float)p_z_far);
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
r_camera_matrix.columns[j][i] = matrix.m[j * 4 + i];
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RID OpenXRMetalExtension::get_texture(void *p_swapchain_graphics_data, int p_image_index) {
|
||||
SwapchainGraphicsData *data = (SwapchainGraphicsData *)p_swapchain_graphics_data;
|
||||
ERR_FAIL_NULL_V(data, RID());
|
||||
|
||||
ERR_FAIL_INDEX_V(p_image_index, data->texture_rids.size(), RID());
|
||||
return data->texture_rids[p_image_index];
|
||||
}
|
||||
|
|
@ -56,11 +56,6 @@
|
|||
// feature off.
|
||||
// See: https://registry.khronos.org/OpenGL/extensions/EXT/EXT_sRGB_write_control.txt
|
||||
|
||||
// On OpenGLES this is not defined in our standard headers..
|
||||
#ifndef GL_FRAMEBUFFER_SRGB
|
||||
#define GL_FRAMEBUFFER_SRGB 0x8DB9
|
||||
#endif
|
||||
|
||||
HashMap<String, bool *> OpenXROpenGLExtension::get_requested_extensions() {
|
||||
HashMap<String, bool *> request_extensions;
|
||||
|
||||
|
|
@ -69,6 +64,9 @@ HashMap<String, bool *> OpenXROpenGLExtension::get_requested_extensions() {
|
|||
#else
|
||||
request_extensions[XR_KHR_OPENGL_ENABLE_EXTENSION_NAME] = nullptr;
|
||||
#endif
|
||||
#if defined(LINUXBSD_ENABLED) && defined(EGL_ENABLED) && defined(WAYLAND_ENABLED)
|
||||
request_extensions[XR_MNDX_EGL_ENABLE_EXTENSION_NAME] = &egl_extension_enabled;
|
||||
#endif
|
||||
|
||||
return request_extensions;
|
||||
}
|
||||
|
|
@ -133,9 +131,14 @@ bool OpenXROpenGLExtension::check_graphics_api_support(XrVersion p_desired_versi
|
|||
XrGraphicsBindingOpenGLWin32KHR OpenXROpenGLExtension::graphics_binding_gl;
|
||||
#elif defined(ANDROID_ENABLED)
|
||||
XrGraphicsBindingOpenGLESAndroidKHR OpenXROpenGLExtension::graphics_binding_gl;
|
||||
#elif defined(X11_ENABLED)
|
||||
#elif defined(LINUXBSD_ENABLED)
|
||||
#ifdef X11_ENABLED
|
||||
XrGraphicsBindingOpenGLXlibKHR OpenXROpenGLExtension::graphics_binding_gl;
|
||||
#endif
|
||||
#if defined(EGL_ENABLED) && defined(WAYLAND_ENABLED)
|
||||
XrGraphicsBindingEGLMNDX OpenXROpenGLExtension::graphics_binding_egl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void *OpenXROpenGLExtension::set_session_create_and_get_next_pointer(void *p_next_pointer) {
|
||||
XrVersion desired_version = XR_MAKE_VERSION(3, 3, 0);
|
||||
|
|
@ -147,10 +150,6 @@ void *OpenXROpenGLExtension::set_session_create_and_get_next_pointer(void *p_nex
|
|||
|
||||
DisplayServer *display_server = DisplayServer::get_singleton();
|
||||
|
||||
#ifdef WAYLAND_ENABLED
|
||||
ERR_FAIL_COND_V_MSG(display_server->get_name() == "Wayland", p_next_pointer, "OpenXR is not yet supported on OpenGL Wayland.");
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
graphics_binding_gl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR,
|
||||
graphics_binding_gl.next = p_next_pointer;
|
||||
|
|
@ -164,7 +163,23 @@ void *OpenXROpenGLExtension::set_session_create_and_get_next_pointer(void *p_nex
|
|||
graphics_binding_gl.display = (void *)display_server->window_get_native_handle(DisplayServer::DISPLAY_HANDLE);
|
||||
graphics_binding_gl.config = (EGLConfig)0; // https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/master/src/tests/hello_xr/graphicsplugin_opengles.cpp#L122
|
||||
graphics_binding_gl.context = (void *)display_server->window_get_native_handle(DisplayServer::OPENGL_CONTEXT);
|
||||
#elif defined(X11_ENABLED)
|
||||
#else
|
||||
#if defined(EGL_ENABLED) && defined(WAYLAND_ENABLED)
|
||||
if (display_server->get_name() == "Wayland") {
|
||||
ERR_FAIL_COND_V_MSG(!egl_extension_enabled, p_next_pointer, "OpenXR cannot initialize on Wayland without the XR_MNDX_egl_enable extension.");
|
||||
|
||||
graphics_binding_egl.type = XR_TYPE_GRAPHICS_BINDING_EGL_MNDX;
|
||||
graphics_binding_egl.next = p_next_pointer;
|
||||
|
||||
graphics_binding_egl.getProcAddress = eglGetProcAddress;
|
||||
graphics_binding_egl.display = (void *)display_server->window_get_native_handle(DisplayServer::EGL_DISPLAY);
|
||||
graphics_binding_egl.config = (void *)display_server->window_get_native_handle(DisplayServer::EGL_CONFIG);
|
||||
graphics_binding_egl.context = (void *)display_server->window_get_native_handle(DisplayServer::OPENGL_CONTEXT);
|
||||
|
||||
return &graphics_binding_egl;
|
||||
}
|
||||
#endif
|
||||
#if defined(X11_ENABLED)
|
||||
graphics_binding_gl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
|
||||
graphics_binding_gl.next = p_next_pointer;
|
||||
|
||||
|
|
@ -178,10 +193,15 @@ void *OpenXROpenGLExtension::set_session_create_and_get_next_pointer(void *p_nex
|
|||
|
||||
// spec says to use proper values but runtimes don't care
|
||||
graphics_binding_gl.visualid = 0;
|
||||
graphics_binding_gl.glxFBConfig = 0;
|
||||
graphics_binding_gl.glxFBConfig = nullptr;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(ANDROID_ENABLED) || defined(X11_ENABLED)
|
||||
return &graphics_binding_gl;
|
||||
#else
|
||||
return p_next_pointer;
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenXROpenGLExtension::get_usable_swapchain_formats(Vector<int64_t> &p_usable_swap_chains) {
|
||||
|
|
@ -196,23 +216,6 @@ void OpenXROpenGLExtension::get_usable_depth_formats(Vector<int64_t> &p_usable_d
|
|||
p_usable_depth_formats.push_back(GL_DEPTH_COMPONENT24);
|
||||
}
|
||||
|
||||
void OpenXROpenGLExtension::on_pre_draw_viewport(RID p_render_target) {
|
||||
if (srgb_ext_is_available) {
|
||||
hw_linear_to_srgb_is_enabled = glIsEnabled(GL_FRAMEBUFFER_SRGB);
|
||||
if (hw_linear_to_srgb_is_enabled) {
|
||||
// Disable this.
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXROpenGLExtension::on_post_draw_viewport(RID p_render_target) {
|
||||
if (srgb_ext_is_available && hw_linear_to_srgb_is_enabled) {
|
||||
// Re-enable this.
|
||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenXROpenGLExtension::get_swapchain_image_data(XrSwapchain p_swapchain, int64_t p_swapchain_format, uint32_t p_width, uint32_t p_height, uint32_t p_sample_count, uint32_t p_array_size, void **r_swapchain_graphics_data) {
|
||||
GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton();
|
||||
ERR_FAIL_NULL_V(texture_storage, false);
|
||||
|
|
@ -225,33 +228,32 @@ bool OpenXROpenGLExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
|
|||
}
|
||||
|
||||
#ifdef ANDROID_ENABLED
|
||||
XrSwapchainImageOpenGLESKHR *images = (XrSwapchainImageOpenGLESKHR *)memalloc(sizeof(XrSwapchainImageOpenGLESKHR) * swapchain_length);
|
||||
LocalVector<XrSwapchainImageOpenGLESKHR> images;
|
||||
#else
|
||||
XrSwapchainImageOpenGLKHR *images = (XrSwapchainImageOpenGLKHR *)memalloc(sizeof(XrSwapchainImageOpenGLKHR) * swapchain_length);
|
||||
LocalVector<XrSwapchainImageOpenGLKHR> images;
|
||||
#endif
|
||||
ERR_FAIL_NULL_V_MSG(images, false, "OpenXR Couldn't allocate memory for swap chain image");
|
||||
images.resize(swapchain_length);
|
||||
|
||||
for (uint64_t i = 0; i < swapchain_length; i++) {
|
||||
#ifdef ANDROID_ENABLED
|
||||
images[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR;
|
||||
for (XrSwapchainImageOpenGLESKHR &image : images) {
|
||||
image.type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR;
|
||||
#else
|
||||
images[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR;
|
||||
for (XrSwapchainImageOpenGLKHR &image : images) {
|
||||
image.type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR;
|
||||
#endif
|
||||
images[i].next = nullptr;
|
||||
images[i].image = 0;
|
||||
image.next = nullptr;
|
||||
image.image = 0;
|
||||
}
|
||||
|
||||
result = xrEnumerateSwapchainImages(p_swapchain, swapchain_length, &swapchain_length, (XrSwapchainImageBaseHeader *)images);
|
||||
result = xrEnumerateSwapchainImages(p_swapchain, swapchain_length, &swapchain_length, (XrSwapchainImageBaseHeader *)images.ptr());
|
||||
if (XR_FAILED(result)) {
|
||||
print_line("OpenXR: Failed to get swapchaim images [", OpenXRAPI::get_singleton()->get_error_string(result), "]");
|
||||
memfree(images);
|
||||
return false;
|
||||
}
|
||||
|
||||
SwapchainGraphicsData *data = memnew(SwapchainGraphicsData);
|
||||
if (data == nullptr) {
|
||||
print_line("OpenXR: Failed to allocate memory for swapchain data");
|
||||
memfree(images);
|
||||
return false;
|
||||
}
|
||||
*r_swapchain_graphics_data = data;
|
||||
|
|
@ -262,8 +264,8 @@ bool OpenXROpenGLExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
|
|||
Vector<RID> texture_rids;
|
||||
|
||||
for (uint64_t i = 0; i < swapchain_length; i++) {
|
||||
RID texture_rid = texture_storage->texture_create_external(
|
||||
p_array_size == 1 ? GLES3::Texture::TYPE_2D : GLES3::Texture::TYPE_LAYERED,
|
||||
RID texture_rid = texture_storage->texture_create_from_native_handle(
|
||||
p_array_size == 1 ? RS::TEXTURE_TYPE_2D : RS::TEXTURE_TYPE_LAYERED,
|
||||
format,
|
||||
images[i].image,
|
||||
p_width,
|
||||
|
|
@ -276,8 +278,6 @@ bool OpenXROpenGLExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
|
|||
|
||||
data->texture_rids = texture_rids;
|
||||
|
||||
memfree(images);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -312,8 +312,8 @@ void OpenXROpenGLExtension::cleanup_swapchain_graphics_data(void **p_swapchain_g
|
|||
|
||||
SwapchainGraphicsData *data = (SwapchainGraphicsData *)*p_swapchain_graphics_data;
|
||||
|
||||
for (int i = 0; i < data->texture_rids.size(); i++) {
|
||||
texture_storage->texture_free(data->texture_rids[i]);
|
||||
for (const RID &texture_rid : data->texture_rids) {
|
||||
texture_storage->texture_free(texture_rid);
|
||||
}
|
||||
data->texture_rids.clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -49,9 +49,6 @@ public:
|
|||
virtual void on_instance_created(const XrInstance p_instance) override;
|
||||
virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer) override;
|
||||
|
||||
virtual void on_pre_draw_viewport(RID p_render_target) override;
|
||||
virtual void on_post_draw_viewport(RID p_render_target) override;
|
||||
|
||||
virtual void get_usable_swapchain_formats(Vector<int64_t> &p_usable_swap_chains) override;
|
||||
virtual void get_usable_depth_formats(Vector<int64_t> &p_usable_swap_chains) override;
|
||||
virtual String get_swapchain_format_name(int64_t p_swapchain_format) const override;
|
||||
|
|
@ -67,8 +64,17 @@ private:
|
|||
static XrGraphicsBindingOpenGLWin32KHR graphics_binding_gl;
|
||||
#elif defined(ANDROID_ENABLED)
|
||||
static XrGraphicsBindingOpenGLESAndroidKHR graphics_binding_gl;
|
||||
#else // Linux/X11
|
||||
#elif defined(LINUXBSD_ENABLED)
|
||||
#ifdef X11_ENABLED
|
||||
static XrGraphicsBindingOpenGLXlibKHR graphics_binding_gl;
|
||||
#endif
|
||||
#if defined(EGL_ENABLED) && defined(WAYLAND_ENABLED)
|
||||
static XrGraphicsBindingEGLMNDX graphics_binding_egl;
|
||||
|
||||
bool egl_extension_enabled = false;
|
||||
#endif
|
||||
#else
|
||||
#error "OpenXR with OpenGL isn't supported on this platform"
|
||||
#endif
|
||||
|
||||
struct SwapchainGraphicsData {
|
||||
|
|
@ -76,9 +82,6 @@ private:
|
|||
Vector<RID> texture_rids;
|
||||
};
|
||||
|
||||
bool srgb_ext_is_available = true;
|
||||
bool hw_linear_to_srgb_is_enabled = false;
|
||||
|
||||
bool check_graphics_api_support(XrVersion p_desired_version);
|
||||
|
||||
#ifdef ANDROID_ENABLED
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ void OpenXRVulkanExtension::get_usable_depth_formats(Vector<int64_t> &p_usable_s
|
|||
}
|
||||
|
||||
bool OpenXRVulkanExtension::get_swapchain_image_data(XrSwapchain p_swapchain, int64_t p_swapchain_format, uint32_t p_width, uint32_t p_height, uint32_t p_sample_count, uint32_t p_array_size, void **r_swapchain_graphics_data) {
|
||||
XrSwapchainImageVulkanKHR *images = nullptr;
|
||||
LocalVector<XrSwapchainImageVulkanKHR> images;
|
||||
|
||||
RenderingServer *rendering_server = RenderingServer::get_singleton();
|
||||
ERR_FAIL_NULL_V(rendering_server, false);
|
||||
|
|
@ -253,27 +253,23 @@ bool OpenXRVulkanExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
|
|||
return false;
|
||||
}
|
||||
|
||||
images = (XrSwapchainImageVulkanKHR *)memalloc(sizeof(XrSwapchainImageVulkanKHR) * swapchain_length);
|
||||
ERR_FAIL_NULL_V_MSG(images, false, "OpenXR Couldn't allocate memory for swap chain image");
|
||||
images.resize(swapchain_length);
|
||||
|
||||
for (uint64_t i = 0; i < swapchain_length; i++) {
|
||||
images[i].type = XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR;
|
||||
images[i].next = nullptr;
|
||||
images[i].image = VK_NULL_HANDLE;
|
||||
for (XrSwapchainImageVulkanKHR &image : images) {
|
||||
image.type = XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR;
|
||||
image.next = nullptr;
|
||||
image.image = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
result = xrEnumerateSwapchainImages(p_swapchain, swapchain_length, &swapchain_length, (XrSwapchainImageBaseHeader *)images);
|
||||
result = xrEnumerateSwapchainImages(p_swapchain, swapchain_length, &swapchain_length, (XrSwapchainImageBaseHeader *)images.ptr());
|
||||
if (XR_FAILED(result)) {
|
||||
print_line("OpenXR: Failed to get swapchaim images [", OpenXRAPI::get_singleton()->get_error_string(result), "]");
|
||||
memfree(images);
|
||||
return false;
|
||||
}
|
||||
|
||||
// SwapchainGraphicsData *data = (SwapchainGraphicsData *)memalloc(sizeof(SwapchainGraphicsData));
|
||||
SwapchainGraphicsData *data = memnew(SwapchainGraphicsData);
|
||||
if (data == nullptr) {
|
||||
print_line("OpenXR: Failed to allocate memory for swapchain data");
|
||||
memfree(images);
|
||||
return false;
|
||||
}
|
||||
*r_swapchain_graphics_data = data;
|
||||
|
|
@ -291,12 +287,12 @@ bool OpenXRVulkanExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
|
|||
// This also means we're reading the values as is for our preview on screen.
|
||||
// The OpenXR runtime however is still treating this as an sRGB format and
|
||||
// will thus do an sRGB -> Linear conversion as expected.
|
||||
// format = RenderingDevice::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
//format = RenderingDevice::DATA_FORMAT_R8G8B8A8_SRGB;
|
||||
format = RenderingDevice::DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
usage_flags |= RenderingDevice::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
break;
|
||||
case VK_FORMAT_B8G8R8A8_SRGB:
|
||||
// format = RenderingDevice::DATA_FORMAT_B8G8R8A8_SRGB;
|
||||
//format = RenderingDevice::DATA_FORMAT_B8G8R8A8_SRGB;
|
||||
format = RenderingDevice::DATA_FORMAT_B8G8R8A8_UNORM;
|
||||
usage_flags |= RenderingDevice::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
break;
|
||||
|
|
@ -322,7 +318,7 @@ bool OpenXRVulkanExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
|
|||
break;
|
||||
default:
|
||||
// continue with our default value
|
||||
print_line("Unsupported swapchain format ", p_swapchain_format);
|
||||
print_line("OpenXR: Unsupported swapchain format", p_swapchain_format);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -350,20 +346,20 @@ bool OpenXRVulkanExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
|
|||
break;
|
||||
default:
|
||||
// continue with our default value
|
||||
print_line("Unsupported sample count ", p_sample_count);
|
||||
print_line("OpenXR: Unsupported sample count", p_sample_count);
|
||||
break;
|
||||
}
|
||||
|
||||
Vector<RID> texture_rids;
|
||||
|
||||
// create Godot texture objects for each entry in our swapchain
|
||||
for (uint64_t i = 0; i < swapchain_length; i++) {
|
||||
for (const XrSwapchainImageVulkanKHR &swapchain_image : images) {
|
||||
RID image_rid = rendering_device->texture_create_from_extension(
|
||||
p_array_size == 1 ? RenderingDevice::TEXTURE_TYPE_2D : RenderingDevice::TEXTURE_TYPE_2D_ARRAY,
|
||||
format,
|
||||
samples,
|
||||
usage_flags,
|
||||
(uint64_t)images[i].image,
|
||||
(uint64_t)swapchain_image.image,
|
||||
p_width,
|
||||
p_height,
|
||||
1,
|
||||
|
|
@ -374,13 +370,11 @@ bool OpenXRVulkanExtension::get_swapchain_image_data(XrSwapchain p_swapchain, in
|
|||
|
||||
data->texture_rids = texture_rids;
|
||||
|
||||
memfree(images);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenXRVulkanExtension::create_projection_fov(const XrFovf p_fov, double p_z_near, double p_z_far, Projection &r_camera_matrix) {
|
||||
// Even though this is a Vulkan renderer we're using OpenGL coordinate systems
|
||||
// Even though this is a Vulkan renderer we're using OpenGL coordinate systems.
|
||||
OpenXRUtil::XrMatrix4x4f matrix;
|
||||
OpenXRUtil::XrMatrix4x4f_CreateProjectionFov(&matrix, OpenXRUtil::GRAPHICS_OPENGL, p_fov, (float)p_z_near, (float)p_z_far);
|
||||
|
||||
|
|
@ -413,9 +407,9 @@ void OpenXRVulkanExtension::cleanup_swapchain_graphics_data(void **p_swapchain_g
|
|||
RenderingDevice *rendering_device = rendering_server->get_rendering_device();
|
||||
ERR_FAIL_NULL(rendering_device);
|
||||
|
||||
for (int i = 0; i < data->texture_rids.size(); i++) {
|
||||
// This should clean up our RIDs and associated texture objects but shouldn't destroy the images, they are owned by our XrSwapchain
|
||||
rendering_device->free(data->texture_rids[i]);
|
||||
for (const RID &texture_rid : data->texture_rids) {
|
||||
// This should clean up our RIDs and associated texture objects but shouldn't destroy the images, they are owned by our XrSwapchain.
|
||||
rendering_device->free(texture_rid);
|
||||
}
|
||||
data->texture_rids.clear();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue