Skip to content

Commit f3ca1e3

Browse files
committed
Add support for create protected content for the main swapchains
1 parent 0870525 commit f3ca1e3

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

modules/openxr/openxr_api.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ bool OpenXRAPI::obtain_swapchain_formats() {
12331233
return true;
12341234
}
12351235

1236-
bool OpenXRAPI::create_main_swapchains(const Size2i &p_size) {
1236+
bool OpenXRAPI::create_main_swapchains(const Size2i &p_size, bool p_protected_content) {
12371237
ERR_NOT_ON_RENDER_THREAD_V(false);
12381238
ERR_FAIL_NULL_V(graphics_extension, false);
12391239
ERR_FAIL_COND_V(session == XR_NULL_HANDLE, false);
@@ -1254,11 +1254,19 @@ bool OpenXRAPI::create_main_swapchains(const Size2i &p_size) {
12541254
*/
12551255

12561256
render_state.main_swapchain_size = p_size;
1257+
render_state.swapchain_protected_content = p_protected_content;
12571258
uint32_t sample_count = 1;
12581259

1260+
// Check to see if content should be protected.
1261+
XrSwapchainCreateFlags create_flags = 0;
1262+
1263+
if (p_protected_content) {
1264+
create_flags = XR_SWAPCHAIN_CREATE_PROTECTED_CONTENT_BIT;
1265+
}
1266+
12591267
// We start with our color swapchain...
12601268
if (color_swapchain_format != 0) {
1261-
if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_COLOR].create(0, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT | XR_SWAPCHAIN_USAGE_MUTABLE_FORMAT_BIT, color_swapchain_format, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
1269+
if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_COLOR].create(create_flags, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT | XR_SWAPCHAIN_USAGE_MUTABLE_FORMAT_BIT, color_swapchain_format, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
12621270
return false;
12631271
}
12641272

@@ -1270,7 +1278,7 @@ bool OpenXRAPI::create_main_swapchains(const Size2i &p_size) {
12701278
// - we support our depth layer extension
12711279
// - we have our spacewarp extension (not yet implemented)
12721280
if (depth_swapchain_format != 0 && submit_depth_buffer && OpenXRCompositionLayerDepthExtension::get_singleton()->is_available()) {
1273-
if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_DEPTH].create(0, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, depth_swapchain_format, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
1281+
if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_DEPTH].create(create_flags, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, depth_swapchain_format, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
12741282
return false;
12751283
}
12761284

@@ -2293,12 +2301,12 @@ void OpenXRAPI::pre_render() {
22932301
OpenXRSwapChainInfo::free_queued();
22942302

22952303
Size2i swapchain_size = get_recommended_target_size();
2296-
if (swapchain_size != render_state.main_swapchain_size) {
2304+
if (swapchain_size != render_state.main_swapchain_size || protected_content != render_state.swapchain_protected_content) {
22972305
// Out with the old.
22982306
free_main_swapchains();
22992307

23002308
// In with the new.
2301-
create_main_swapchains(swapchain_size);
2309+
create_main_swapchains(swapchain_size, protected_content);
23022310
}
23032311

23042312
void *view_locate_info_next_pointer = nullptr;

modules/openxr/openxr_api.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class OpenXRAPI {
140140
XrFrameState frame_state = { XR_TYPE_FRAME_STATE, nullptr, 0, 0, false };
141141
double render_target_size_multiplier = 1.0;
142142
Rect2i render_region;
143+
bool protected_content;
143144

144145
OpenXRGraphicsExtensionWrapper *graphics_extension = nullptr;
145146
XrSystemGraphicsProperties graphics_properties;
@@ -260,7 +261,7 @@ class OpenXRAPI {
260261
bool load_supported_swapchain_formats();
261262
bool is_swapchain_format_supported(int64_t p_swapchain_format);
262263
bool obtain_swapchain_formats();
263-
bool create_main_swapchains(const Size2i &p_size);
264+
bool create_main_swapchains(const Size2i &p_size, bool p_protected_content);
264265
void free_main_swapchains();
265266
void destroy_session();
266267

@@ -361,6 +362,7 @@ class OpenXRAPI {
361362
};
362363

363364
Size2i main_swapchain_size;
365+
bool swapchain_protected_content;
364366
OpenXRSwapChainInfo main_swapchains[OPENXR_SWAPCHAIN_MAX];
365367
} render_state;
366368

@@ -620,6 +622,9 @@ class OpenXRAPI {
620622
void set_emulate_environment_blend_mode_alpha_blend(bool p_enabled);
621623
OpenXRAlphaBlendModeSupport is_environment_blend_mode_alpha_blend_supported();
622624

625+
void set_protected_content(bool p_protected_content) { protected_content = p_protected_content; }
626+
bool is_protected_content() const { return protected_content; }
627+
623628
OpenXRAPI();
624629
~OpenXRAPI();
625630
};

modules/openxr/openxr_interface.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,22 @@ PackedVector3Array OpenXRInterface::get_play_area() const {
836836
return arr;
837837
}
838838

839+
bool OpenXRInterface::set_protected_content(bool p_protected_content) {
840+
if (openxr_api == nullptr) {
841+
return false;
842+
}
843+
844+
openxr_api->set_protected_content(p_protected_content);
845+
return true;
846+
}
847+
848+
bool OpenXRInterface::is_protected_content() const {
849+
if (openxr_api == nullptr) {
850+
return false;
851+
}
852+
return openxr_api->is_protected_content();
853+
}
854+
839855
float OpenXRInterface::get_display_refresh_rate() const {
840856
if (openxr_api == nullptr) {
841857
return 0.0;

modules/openxr/openxr_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class OpenXRInterface : public XRInterface {
151151
virtual bool set_play_area_mode(XRInterface::PlayAreaMode p_mode) override;
152152
virtual PackedVector3Array get_play_area() const override;
153153

154+
virtual bool set_protected_content(bool p_protected_content) override;
155+
virtual bool is_protected_content() const override;
156+
154157
float get_display_refresh_rate() const;
155158
void set_display_refresh_rate(float p_refresh_rate);
156159
Array get_available_display_refresh_rates() const;

servers/xr/xr_interface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ void XRInterface::_bind_methods() {
5151

5252
ClassDB::bind_method(D_METHOD("trigger_haptic_pulse", "action_name", "tracker_name", "frequency", "amplitude", "duration_sec", "delay_sec"), &XRInterface::trigger_haptic_pulse);
5353

54+
ClassDB::bind_method(D_METHOD("is_protected_content"), &XRInterface::is_protected_content);
55+
ClassDB::bind_method(D_METHOD("set_protected_content", "protected_content"), &XRInterface::set_protected_content);
56+
5457
ADD_GROUP("Interface", "interface_");
5558
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_primary", "is_primary");
5659

servers/xr/xr_interface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ class XRInterface : public RefCounted {
167167
virtual RID get_vrs_texture(); /* obtain VRS texture */
168168
virtual VRSTextureFormat get_vrs_texture_format() { return XR_VRS_TEXTURE_FORMAT_UNIFIED; }
169169

170+
/** protected content **/
171+
// If enabled, protect content from CPU access. This returns false if the feature is not available.
172+
virtual bool set_protected_content(bool p_protected_content) { return false; }
173+
// Returns true if the content is being protected from CPU access.
174+
virtual bool is_protected_content() const { return false; }
175+
170176
XRInterface();
171177
~XRInterface();
172178
};

0 commit comments

Comments
 (0)