Bug 1760663 - Add blocklist support for WebGPU. r=gfx-reviewers,nical

This patch just adds the plumbing to allow for baked in blocklist rules
or the downloadable blocklist to prevent certain configurations from
getting WebGPU. It does not add any rules.

It also changes us from allowing WebGPU only in nightly, including
tests, to not release and not beta. This allows try to run the WebGPU
tests as expected, since even try builds forked from mozilla-central are
not considered nightly builds by CI (or so it seems).

Differential Revision: https://phabricator.services.mozilla.com/D141682
This commit is contained in:
Andrew Osmond 2022-03-22 15:22:39 +00:00
parent c7b453b99a
commit 78afd0ab38
17 changed files with 45 additions and 36 deletions

View File

@ -16,7 +16,6 @@
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_gfx.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/StaticPrefs_webgl.h"
@ -200,7 +199,7 @@ bool GetCanvasContextType(const nsAString& str,
}
}
if (StaticPrefs::dom_webgpu_enabled()) {
if (gfxVars::AllowWebGPU()) {
if (str.EqualsLiteral("webgpu")) {
*out_type = dom::CanvasContextType::WebGPU;
return true;

View File

@ -203,7 +203,6 @@ mozilla::ipc::IPCResult RDDParent::RecvInitVideoBridge(
Feature::D3D11_COMPOSITING,
Feature::OPENGL_COMPOSITING,
Feature::DIRECT2D,
Feature::WEBGPU,
},
aContentDeviceData.prefs());
#ifdef XP_WIN

View File

@ -6,13 +6,13 @@
#include "Instance.h"
#include "Adapter.h"
#include "gfxConfig.h"
#include "nsIGlobalObject.h"
#include "ipc/WebGPUChild.h"
#include "ipc/WebGPUTypes.h"
#include "mozilla/webgpu/ffi/wgpu.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/gfx/CanvasManagerChild.h"
#include "mozilla/gfx/gfxVars.h"
namespace mozilla {
namespace webgpu {
@ -23,7 +23,7 @@ GPU_IMPL_CYCLE_COLLECTION(Instance, mBridge, mOwner)
already_AddRefed<Instance> Instance::Create(nsIGlobalObject* aOwner) {
RefPtr<WebGPUChild> bridge;
if (gfx::gfxConfig::IsEnabled(gfx::Feature::WEBGPU)) {
if (gfx::gfxVars::AllowWebGPU()) {
bridge = gfx::CanvasManagerChild::Get()->GetWebGPUChild();
if (NS_WARN_IF(!bridge)) {
MOZ_CRASH("Failed to create an IPDL bridge for WebGPU!");

View File

@ -1,6 +1,6 @@
[DEFAULT]
subsuite = webgpu
run-if = nightly_build
run-if = !release_or_beta
prefs =
dom.webgpu.enabled=true

View File

@ -170,9 +170,6 @@ void gfxConfig::Inherit(EnumSet<Feature> aFeatures,
case Feature::DIRECT2D:
status = aDevicePrefs.useD2D1();
break;
case Feature::WEBGPU:
status = aDevicePrefs.webGPU();
break;
default:
break;
}

View File

@ -87,7 +87,8 @@ class gfxVarReceiver;
_(UseVAAPI, bool, false) \
_(WebRenderRequiresHardwareDriver, bool, false) \
_(SupportsThreadsafeGL, bool, false) \
_(OffscreenCanvasDomainAllowlist, nsCString, nsCString())
_(OffscreenCanvasDomainAllowlist, nsCString, nsCString()) \
_(AllowWebGPU, bool, false)
/* Add new entries above this line. */

View File

@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CanvasManagerParent.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/dom/WebGLParent.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/ipc/Endpoint.h"
@ -91,7 +90,7 @@ already_AddRefed<dom::PWebGLParent> CanvasManagerParent::AllocPWebGLParent() {
already_AddRefed<webgpu::PWebGPUParent>
CanvasManagerParent::AllocPWebGPUParent() {
if (!StaticPrefs::dom_webgpu_enabled()) {
if (!gfxVars::AllowWebGPU()) {
return nullptr;
}

View File

@ -52,9 +52,6 @@ class CompositorOptions {
mAllowSoftwareWebRenderOGL = aAllowSoftwareWebRenderOGL;
}
bool UseWebGPU() const { return mUseWebGPU; }
void SetUseWebGPU(bool aUseWebGPU) { mUseWebGPU = aUseWebGPU; }
void SetInitiallyPaused(bool aPauseAtStartup) {
mInitiallyPaused = aPauseAtStartup;
}
@ -64,8 +61,7 @@ class CompositorOptions {
mUseSoftwareWebRender == aOther.mUseSoftwareWebRender &&
mAllowSoftwareWebRenderD3D11 ==
aOther.mAllowSoftwareWebRenderD3D11 &&
mAllowSoftwareWebRenderOGL == aOther.mAllowSoftwareWebRenderOGL &&
mUseWebGPU == aOther.mUseWebGPU;
mAllowSoftwareWebRenderOGL == aOther.mAllowSoftwareWebRenderOGL;
}
friend struct IPC::ParamTraits<CompositorOptions>;
@ -75,7 +71,6 @@ class CompositorOptions {
bool mUseSoftwareWebRender = false;
bool mAllowSoftwareWebRenderD3D11 = false;
bool mAllowSoftwareWebRenderOGL = false;
bool mUseWebGPU = false;
bool mInitiallyPaused = false;
// Make sure to add new fields to the ParamTraits implementation

View File

@ -57,7 +57,6 @@ void GPUChild::Init() {
devicePrefs.oglCompositing() =
gfxConfig::GetValue(Feature::OPENGL_COMPOSITING);
devicePrefs.useD2D1() = gfxConfig::GetValue(Feature::DIRECT2D);
devicePrefs.webGPU() = gfxConfig::GetValue(Feature::WEBGPU);
devicePrefs.d3d11HwAngle() = gfxConfig::GetValue(Feature::D3D11_HW_ANGLE);
nsTArray<LayerTreeIdMapping> mappings;

View File

@ -240,7 +240,6 @@ mozilla::ipc::IPCResult GPUParent::RecvInit(
devicePrefs.d3d11Compositing());
gfxConfig::Inherit(Feature::OPENGL_COMPOSITING, devicePrefs.oglCompositing());
gfxConfig::Inherit(Feature::DIRECT2D, devicePrefs.useD2D1());
gfxConfig::Inherit(Feature::WEBGPU, devicePrefs.webGPU());
gfxConfig::Inherit(Feature::D3D11_HW_ANGLE, devicePrefs.d3d11HwAngle());
{ // Let the crash reporter know if we've got WR enabled or not. For other

View File

@ -35,7 +35,6 @@ struct DevicePrefs
FeatureStatus d3d11Compositing;
FeatureStatus oglCompositing;
FeatureStatus useD2D1;
FeatureStatus webGPU;
FeatureStatus d3d11HwAngle;
};
@ -61,7 +60,6 @@ struct GPUDeviceData
FeatureFailure? d3d11Compositing;
FeatureFailure? oglCompositing;
D3D11DeviceStatus? gpuDevice;
FeatureFailure? webGPU;
};
union GfxVarValue

View File

@ -813,7 +813,6 @@ struct ParamTraits<mozilla::layers::CompositorOptions> {
WriteParam(aWriter, aParam.mUseSoftwareWebRender);
WriteParam(aWriter, aParam.mAllowSoftwareWebRenderD3D11);
WriteParam(aWriter, aParam.mAllowSoftwareWebRenderOGL);
WriteParam(aWriter, aParam.mUseWebGPU);
WriteParam(aWriter, aParam.mInitiallyPaused);
}
@ -822,7 +821,6 @@ struct ParamTraits<mozilla::layers::CompositorOptions> {
ReadParam(aReader, &aResult->mUseSoftwareWebRender) &&
ReadParam(aReader, &aResult->mAllowSoftwareWebRenderD3D11) &&
ReadParam(aReader, &aResult->mAllowSoftwareWebRenderOGL) &&
ReadParam(aReader, &aResult->mUseWebGPU) &&
ReadParam(aReader, &aResult->mInitiallyPaused);
}
};

View File

@ -2761,18 +2761,30 @@ void gfxPlatform::InitWebGLConfig() {
}
void gfxPlatform::InitWebGPUConfig() {
if (!XRE_IsParentProcess()) {
return;
}
FeatureState& feature = gfxConfig::GetFeature(Feature::WEBGPU);
feature.SetDefaultFromPref("dom.webgpu.enabled", true, false);
#ifndef NIGHTLY_BUILD
feature.ForceDisable(FeatureStatus::Blocked,
"WebGPU can only be enabled in nightly",
"WEBGPU_DISABLE_NON_NIGHTLY"_ns);
#endif
if (!UseWebRender()) {
feature.ForceDisable(FeatureStatus::UnavailableNoWebRender,
"WebGPU can't present without WebRender",
"FEATURE_FAILURE_WEBGPU_NEED_WEBRENDER"_ns);
nsCString message;
nsCString failureId;
if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_WEBGPU, &message, failureId)) {
feature.Disable(FeatureStatus::Blocklisted, message.get(), failureId);
}
#ifdef RELEASE_OR_BETA
feature.ForceDisable(FeatureStatus::Blocked,
"WebGPU cannot be enabled in release or beta",
"WEBGPU_DISABLE_RELEASE_OR_BETA"_ns);
#else
if (StaticPrefs::gfx_webgpu_force_enabled_AtStartup()) {
feature.UserForceEnable("Force-enabled by pref");
}
#endif
gfxVars::SetAllowWebGPU(feature.IsEnabled());
}
#ifdef XP_WIN

View File

@ -5663,6 +5663,12 @@
value: true
mirror: always
# Should we override the blocklist to enable WebGPU?
- name: gfx.webgpu.force-enabled
type: bool
value: false
mirror: once
# We expose two prefs: gfx.webrender.all and gfx.webrender.enabled.
# The first enables WR+additional features, and the second just enables WR.
# For developer convenience, building with --enable-webrender=true or just

View File

@ -237,6 +237,9 @@ static const char* GetPrefNameForFeature(int32_t aFeature) {
case nsIGfxInfo::FEATURE_VAAPI:
name = BLOCKLIST_PREF_BRANCH "vaapi";
break;
case nsIGfxInfo::FEATURE_WEBGPU:
name = BLOCKLIST_PREF_BRANCH "webgpu";
break;
case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE:
name = BLOCKLIST_PREF_BRANCH "webrender.program-binary-disk";
break;
@ -492,6 +495,9 @@ static int32_t BlocklistFeatureToGfxFeature(const nsAString& aFeature) {
if (aFeature.EqualsLiteral("VAAPI")) {
return nsIGfxInfo::FEATURE_VAAPI;
}
if (aFeature.EqualsLiteral("WEBGPU")) {
return nsIGfxInfo::FEATURE_WEBGPU;
}
if (aFeature.EqualsLiteral("WEBRENDER_PARTIAL_PRESENT")) {
return nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT;
}
@ -1377,6 +1383,7 @@ void GfxInfoBase::EvaluateDownloadedBlocklist(
nsIGfxInfo::FEATURE_X11_EGL,
nsIGfxInfo::FEATURE_DMABUF,
nsIGfxInfo::FEATURE_VAAPI,
nsIGfxInfo::FEATURE_WEBGPU,
nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT,
0};

View File

@ -1216,8 +1216,6 @@ already_AddRefed<WebRenderLayerManager> nsBaseWidget::CreateCompositorSession(
}
#endif
options.SetUseWebGPU(StaticPrefs::dom_webgpu_enabled());
#ifdef MOZ_WIDGET_ANDROID
// Unconditionally set the compositor as initially paused, as we have not
// yet had a chance to send the compositor surface to the GPU process. We

View File

@ -179,8 +179,10 @@ interface nsIGfxInfo : nsISupports
const long FEATURE_WEBRENDER_PARTIAL_PRESENT = 36;
/* Whether VA-API is supported, starting in 96. */
const long FEATURE_VAAPI = 37;
/* Whether WebGPU is supported, starting in 100. */
const long FEATURE_WEBGPU = 38;
/* the maximum feature value. */
const long FEATURE_MAX_VALUE = FEATURE_VAAPI;
const long FEATURE_MAX_VALUE = FEATURE_WEBGPU;
/*
* A set of return values from GetFeatureStatus