Commit 17c1b198 authored by Rafael Cintron's avatar Rafael Cintron Committed by Commit Bot

Disable WebGL anti-aliasing for WebXR when maxSwapchainSampleCount==1

To ease the workload on low end devices, we disable WebGL
anti-aliasing on opaque swap chains when the max sample count is 1.

Bug: 1141989
Change-Id: Ia3cc6dd031e4c8ffec8096372cdb9aa21759e962
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495829
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821121}
parent 378bb3b4
...@@ -767,6 +767,26 @@ uint32_t OpenXrApiWrapper::GetRecommendedSwapchainSampleCount() const { ...@@ -767,6 +767,26 @@ uint32_t OpenXrApiWrapper::GetRecommendedSwapchainSampleCount() const {
->recommendedSwapchainSampleCount; ->recommendedSwapchainSampleCount;
} }
// From the OpenXR Spec:
// maxSwapchainSampleCount is the maximum number of sub-data element samples
// supported for swapchain images that will be rendered into for this view.
//
// To ease the workload on low end devices, we disable anti-aliasing when the
// max sample count is 1.
bool OpenXrApiWrapper::CanEnableAntiAliasing() const {
DCHECK(IsInitialized());
const auto compareMaxSwapchainSampleCounts =
[](const XrViewConfigurationView& i, const XrViewConfigurationView& j) {
return (i.maxSwapchainSampleCount < j.maxSwapchainSampleCount);
};
const auto it_min_element =
std::min_element(view_configs_.begin(), view_configs_.end(),
compareMaxSwapchainSampleCounts);
return (it_min_element->maxSwapchainSampleCount > 1);
}
// stage bounds is fixed unless we received event // stage bounds is fixed unless we received event
// XrEventDataReferenceSpaceChangePending // XrEventDataReferenceSpaceChangePending
XrResult OpenXrApiWrapper::UpdateStageBounds() { XrResult OpenXrApiWrapper::UpdateStageBounds() {
......
...@@ -75,6 +75,8 @@ class OpenXrApiWrapper { ...@@ -75,6 +75,8 @@ class OpenXrApiWrapper {
device::mojom::XREnvironmentBlendMode PickEnvironmentBlendModeForSession( device::mojom::XREnvironmentBlendMode PickEnvironmentBlendModeForSession(
device::mojom::XRSessionMode session_mode); device::mojom::XRSessionMode session_mode);
bool CanEnableAntiAliasing() const;
static void DEVICE_VR_EXPORT SetTestHook(VRTestHook* hook); static void DEVICE_VR_EXPORT SetTestHook(VRTestHook* hook);
private: private:
......
...@@ -137,6 +137,10 @@ device::mojom::XRInteractionMode OpenXrRenderLoop::GetInteractionMode( ...@@ -137,6 +137,10 @@ device::mojom::XRInteractionMode OpenXrRenderLoop::GetInteractionMode(
return device::mojom::XRInteractionMode::kWorldSpace; return device::mojom::XRInteractionMode::kWorldSpace;
} }
bool OpenXrRenderLoop::CanEnableAntiAliasing() const {
return openxr_->CanEnableAntiAliasing();
}
void OpenXrRenderLoop::OnSessionStart() { void OpenXrRenderLoop::OnSessionStart() {
LogViewerType(VrViewerType::OPENXR_UNKNOWN); LogViewerType(VrViewerType::OPENXR_UNKNOWN);
} }
......
...@@ -45,6 +45,7 @@ class OpenXrRenderLoop : public XRCompositorCommon { ...@@ -45,6 +45,7 @@ class OpenXrRenderLoop : public XRCompositorCommon {
device::mojom::XRSessionMode session_mode) override; device::mojom::XRSessionMode session_mode) override;
device::mojom::XRInteractionMode GetInteractionMode( device::mojom::XRInteractionMode GetInteractionMode(
device::mojom::XRSessionMode session_mode) override; device::mojom::XRSessionMode session_mode) override;
bool CanEnableAntiAliasing() const override;
void InitializeDisplayInfo(); void InitializeDisplayInfo();
bool UpdateEyeParameters(); bool UpdateEyeParameters();
......
...@@ -140,12 +140,16 @@ struct XRSessionDeviceConfig { ...@@ -140,12 +140,16 @@ struct XRSessionDeviceConfig {
// this would result in broken rendering due to inconsistency between the // this would result in broken rendering due to inconsistency between the
// drawn and displayed viewports. // drawn and displayed viewports.
bool supports_viewport_scaling; bool supports_viewport_scaling;
// Indicates whether we should enable anti-aliasing for WebGL layers. Value
// comes from the underlying XR runtime.
bool enable_anti_aliasing = true;
}; };
// This structure contains all the mojo interfaces for different kinds of // This structure contains all the mojo interfaces for different kinds of
// XRSession. The only interface required by all sessions is the // XRSession. The only interface required by all sessions is the
// XRFrameDataProvider. It must always be present. Other interfaces are set as // XRFrameDataProvider. It must always be present. Other interfaces are set as
// apropriate based on the session creation options. (for example, an immersive // appropriate based on the session creation options. (for example, an immersive
// session ought to have a XRPresentationConnection to submit the frames to the // session ought to have a XRPresentationConnection to submit the frames to the
// immersive environment). // immersive environment).
// The XRSessionClient receiver must be fulfilled for the session to get // The XRSessionClient receiver must be fulfilled for the session to get
......
...@@ -53,6 +53,9 @@ device::mojom::XRInteractionMode XRDeviceAbstraction::GetInteractionMode( ...@@ -53,6 +53,9 @@ device::mojom::XRInteractionMode XRDeviceAbstraction::GetInteractionMode(
device::mojom::XRSessionMode session_mode) { device::mojom::XRSessionMode session_mode) {
return device::mojom::XRInteractionMode::kWorldSpace; return device::mojom::XRInteractionMode::kWorldSpace;
} }
bool XRDeviceAbstraction::CanEnableAntiAliasing() const {
return true;
}
XRCompositorCommon::OutstandingFrame::OutstandingFrame() = default; XRCompositorCommon::OutstandingFrame::OutstandingFrame() = default;
XRCompositorCommon::OutstandingFrame::~OutstandingFrame() = default; XRCompositorCommon::OutstandingFrame::~OutstandingFrame() = default;
...@@ -250,6 +253,7 @@ void XRCompositorCommon::RequestSession( ...@@ -250,6 +253,7 @@ void XRCompositorCommon::RequestSession(
session->device_config = device::mojom::XRSessionDeviceConfig::New(); session->device_config = device::mojom::XRSessionDeviceConfig::New();
session->device_config->uses_input_eventing = UsesInputEventing(); session->device_config->uses_input_eventing = UsesInputEventing();
session->device_config->enable_anti_aliasing = CanEnableAntiAliasing();
session->enviroment_blend_mode = GetEnvironmentBlendMode(options->mode); session->enviroment_blend_mode = GetEnvironmentBlendMode(options->mode);
session->interaction_mode = GetInteractionMode(options->mode); session->interaction_mode = GetInteractionMode(options->mode);
......
...@@ -43,6 +43,7 @@ class XRDeviceAbstraction { ...@@ -43,6 +43,7 @@ class XRDeviceAbstraction {
device::mojom::XRSessionMode session_mode); device::mojom::XRSessionMode session_mode);
virtual device::mojom::XRInteractionMode GetInteractionMode( virtual device::mojom::XRInteractionMode GetInteractionMode(
device::mojom::XRSessionMode session_mode); device::mojom::XRSessionMode session_mode);
virtual bool CanEnableAntiAliasing() const;
}; };
class XRCompositorCommon : public base::Thread, class XRCompositorCommon : public base::Thread,
......
...@@ -328,6 +328,7 @@ XRSession::XRSession( ...@@ -328,6 +328,7 @@ XRSession::XRSession(
uses_input_eventing_(device_config->uses_input_eventing), uses_input_eventing_(device_config->uses_input_eventing),
supports_viewport_scaling_(immersive() && supports_viewport_scaling_(immersive() &&
device_config->supports_viewport_scaling), device_config->supports_viewport_scaling),
enable_anti_aliasing_(device_config->enable_anti_aliasing),
sensorless_session_(sensorless_session) { sensorless_session_(sensorless_session) {
client_receiver_.Bind( client_receiver_.Bind(
std::move(client_receiver), std::move(client_receiver),
...@@ -1790,6 +1791,10 @@ bool XRSession::CanReportPoses() const { ...@@ -1790,6 +1791,10 @@ bool XRSession::CanReportPoses() const {
return visibility_state_ == XRVisibilityState::VISIBLE; return visibility_state_ == XRVisibilityState::VISIBLE;
} }
bool XRSession::CanEnableAntiAliasing() const {
return enable_anti_aliasing_;
}
base::Optional<TransformationMatrix> XRSession::GetMojoFrom( base::Optional<TransformationMatrix> XRSession::GetMojoFrom(
device::mojom::blink::XRReferenceSpaceType space_type) const { device::mojom::blink::XRReferenceSpaceType space_type) const {
if (!CanReportPoses()) if (!CanReportPoses())
......
...@@ -310,6 +310,10 @@ class XRSession final ...@@ -310,6 +310,10 @@ class XRSession final
bool CanReportPoses() const; bool CanReportPoses() const;
// Return whether we should enable anti-aliasing for WebGL layers. Value
// comes from the underlying XR runtime.
bool CanEnableAntiAliasing() const;
// Returns current transform from mojo space to the space of the passed in // Returns current transform from mojo space to the space of the passed in
// type. May return nullopt if poses cannot be reported or if the transform is // type. May return nullopt if poses cannot be reported or if the transform is
// unknown. // unknown.
...@@ -567,6 +571,9 @@ class XRSession final ...@@ -567,6 +571,9 @@ class XRSession final
// Corresponds to mojo XRSession.supportsViewportScaling // Corresponds to mojo XRSession.supportsViewportScaling
bool supports_viewport_scaling_ = false; bool supports_viewport_scaling_ = false;
// Corresponds to mojo XRSessionOptions.enable_anti_aliasing
bool enable_anti_aliasing_ = true;
std::unique_ptr<XRSessionViewportScaler> viewport_scaler_; std::unique_ptr<XRSessionViewportScaler> viewport_scaler_;
// Indicates that this is a sensorless session which should only support the // Indicates that this is a sensorless session which should only support the
......
...@@ -95,10 +95,11 @@ XRWebGLLayer* XRWebGLLayer::Create(XRSession* session, ...@@ -95,10 +95,11 @@ XRWebGLLayer* XRWebGLLayer::Create(XRSession* session,
ignore_depth_values); ignore_depth_values);
} }
bool want_antialiasing = initializer->antialias(); const bool want_antialiasing =
bool want_depth_buffer = initializer->depth(); initializer->antialias() && session->CanEnableAntiAliasing();
bool want_stencil_buffer = initializer->stencil(); const bool want_depth_buffer = initializer->depth();
bool want_alpha_channel = initializer->alpha(); const bool want_stencil_buffer = initializer->stencil();
const bool want_alpha_channel = initializer->alpha();
// Allocate a drawing buffer to back the framebuffer if needed. // Allocate a drawing buffer to back the framebuffer if needed.
if (initializer->hasFramebufferScaleFactor()) { if (initializer->hasFramebufferScaleFactor()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment