Skip to content

Commit d5dd125

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

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

modules/openxr/doc_classes/OpenXRInterface.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@
169169
Set foveation level from 0 (off) to 3 (high), the interface must be initialized before this is accessible.
170170
[b]Note:[/b] Only works on the Compatibility renderer.
171171
</member>
172+
<member name="protected_content" type="bool" setter="set_protected_content" getter="is_protected_content" default="false">
173+
If enabled, the OpenXR swapchain will be created with the [code]XR_SWAPCHAIN_CREATE_PROTECTED_CONTENT_BIT[/code] flag, which will protect its contents from CPU access.
174+
</member>
172175
<member name="render_target_size_multiplier" type="float" setter="set_render_target_size_multiplier" getter="get_render_target_size_multiplier" default="1.0">
173176
The render size multiplier for the current HMD. Must be set before the interface has been initialized.
174177
</member>

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 = false;
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 = false;
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void OpenXRInterface::_bind_methods() {
6363
ClassDB::bind_method(D_METHOD("set_display_refresh_rate", "refresh_rate"), &OpenXRInterface::set_display_refresh_rate);
6464
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "display_refresh_rate"), "set_display_refresh_rate", "get_display_refresh_rate");
6565

66+
// Protected content
67+
ClassDB::bind_method(D_METHOD("is_protected_content"), &OpenXRInterface::is_protected_content);
68+
ClassDB::bind_method(D_METHOD("set_protected_content", "protected_content"), &OpenXRInterface::set_protected_content);
69+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "protected_content"), "set_protected_content", "is_protected_content");
70+
6671
// Render Target size multiplier
6772
ClassDB::bind_method(D_METHOD("get_render_target_size_multiplier"), &OpenXRInterface::get_render_target_size_multiplier);
6873
ClassDB::bind_method(D_METHOD("set_render_target_size_multiplier", "multiplier"), &OpenXRInterface::set_render_target_size_multiplier);
@@ -836,6 +841,21 @@ PackedVector3Array OpenXRInterface::get_play_area() const {
836841
return arr;
837842
}
838843

844+
void OpenXRInterface::set_protected_content(bool p_protected_content) {
845+
if (openxr_api == nullptr) {
846+
return;
847+
}
848+
849+
openxr_api->set_protected_content(p_protected_content);
850+
}
851+
852+
bool OpenXRInterface::is_protected_content() const {
853+
if (openxr_api == nullptr) {
854+
return false;
855+
}
856+
return openxr_api->is_protected_content();
857+
}
858+
839859
float OpenXRInterface::get_display_refresh_rate() const {
840860
if (openxr_api == nullptr) {
841861
return 0.0;

modules/openxr/openxr_interface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ 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+
/** protected content **/
155+
// If enabled, protect content from CPU access.
156+
void set_protected_content(bool p_protected_content);
157+
// Returns true if the content is being protected from CPU access.
158+
bool is_protected_content() const;
159+
154160
float get_display_refresh_rate() const;
155161
void set_display_refresh_rate(float p_refresh_rate);
156162
Array get_available_display_refresh_rates() const;

0 commit comments

Comments
 (0)