Add MLGPU feature bits and compositor initialization. (bug 1365879 part 21, r=mattwoodrow)

--HG--
extra : rebase_source : 3d8d1a9619d997a2de9eea4e734a0457cd326e91
This commit is contained in:
David Anderson 2017-06-22 21:12:19 -07:00
Родитель 8eb9963527
Коммит 0505938414
20 изменённых файлов: 207 добавлений и 14 удалений

Просмотреть файл

@ -26,6 +26,7 @@ namespace gfx {
_(GPU_PROCESS, Feature, "GPU Process") \
_(WEBRENDER, Feature, "WebRender") \
_(OMTP, Feature, "Off Main Thread Painting") \
_(ADVANCED_LAYERS, Feature, "Advanced Layers") \
/* Add new entries above this comment */
enum class Feature : uint32_t {

Просмотреть файл

@ -32,6 +32,7 @@ public:
CompositorOptions()
: mUseAPZ(false)
, mUseWebRender(false)
, mUseAdvancedLayers(false)
{
}
@ -39,11 +40,17 @@ public:
bool aUseWebRender)
: mUseAPZ(aUseAPZ)
, mUseWebRender(aUseWebRender)
, mUseAdvancedLayers(false)
{
}
bool UseAPZ() const { return mUseAPZ; }
bool UseWebRender() const { return mUseWebRender; }
bool UseAdvancedLayers() const { return mUseAdvancedLayers; }
void SetUseAdvancedLayers(bool aUseAdvancedLayers) {
mUseAdvancedLayers = aUseAdvancedLayers;
}
bool operator==(const CompositorOptions& aOther) const {
return mUseAPZ == aOther.mUseAPZ &&
@ -55,6 +62,7 @@ public:
private:
bool mUseAPZ;
bool mUseWebRender;
bool mUseAdvancedLayers;
// Make sure to add new fields to the ParamTraits implementation
};

Просмотреть файл

@ -67,6 +67,7 @@ GPUChild::Init()
devicePrefs.hwCompositing() = gfxConfig::GetValue(Feature::HW_COMPOSITING);
devicePrefs.d3d11Compositing() = gfxConfig::GetValue(Feature::D3D11_COMPOSITING);
devicePrefs.oglCompositing() = gfxConfig::GetValue(Feature::OPENGL_COMPOSITING);
devicePrefs.advancedLayers() = gfxConfig::GetValue(Feature::ADVANCED_LAYERS);
devicePrefs.useD2D1() = gfxConfig::GetValue(Feature::DIRECT2D);
nsTArray<LayerTreeIdMapping> mappings;
@ -272,6 +273,13 @@ GPUChild::ActorDestroy(ActorDestroyReason aWhy)
mHost->OnChannelClosed();
}
mozilla::ipc::IPCResult
GPUChild::RecvUpdateFeature(const Feature& aFeature, const FeatureFailure& aChange)
{
gfxConfig::SetFailed(aFeature, aChange.status(), aChange.message().get(), aChange.failureId());
return IPC_OK();
}
class DeferredDeleteGPUChild : public Runnable
{
public:

Просмотреть файл

@ -58,6 +58,7 @@ public:
mozilla::ipc::IPCResult RecvNotifyDeviceReset(const GPUDeviceData& aData) override;
mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport) override;
mozilla::ipc::IPCResult RecvFinishMemoryReport(const uint32_t& aGeneration) override;
mozilla::ipc::IPCResult RecvUpdateFeature(const Feature& aFeature, const FeatureFailure& aChange) override;
bool SendRequestMemoryReport(const uint32_t& aGeneration,
const bool& aAnonymize,

Просмотреть файл

@ -168,6 +168,7 @@ GPUParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs,
gfxConfig::Inherit(Feature::HW_COMPOSITING, devicePrefs.hwCompositing());
gfxConfig::Inherit(Feature::D3D11_COMPOSITING, devicePrefs.d3d11Compositing());
gfxConfig::Inherit(Feature::OPENGL_COMPOSITING, devicePrefs.oglCompositing());
gfxConfig::Inherit(Feature::ADVANCED_LAYERS, devicePrefs.advancedLayers());
gfxConfig::Inherit(Feature::DIRECT2D, devicePrefs.useD2D1());
for (const LayerTreeIdMapping& map : aMappings) {
@ -300,6 +301,7 @@ GPUParent::RecvGetDeviceStatus(GPUDeviceData* aOut)
{
CopyFeatureChange(Feature::D3D11_COMPOSITING, &aOut->d3d11Compositing());
CopyFeatureChange(Feature::OPENGL_COMPOSITING, &aOut->oglCompositing());
CopyFeatureChange(Feature::ADVANCED_LAYERS, &aOut->advancedLayers());
#if defined(XP_WIN)
if (DeviceManagerDx* dm = DeviceManagerDx::Get()) {

Просмотреть файл

@ -13,6 +13,7 @@
#include "RegionBuilder.h"
#include "base/process_util.h"
#include "chrome/common/ipc_message_utils.h"
#include "gfxFeature.h"
#include "gfxPoint.h"
#include "gfxRect.h"
#include "gfxTelemetry.h"
@ -219,6 +220,14 @@ struct ParamTraits<mozilla::gfx::BackendType>
mozilla::gfx::BackendType::BACKEND_LAST>
{};
template <>
struct ParamTraits<mozilla::gfx::Feature>
: public ContiguousEnumSerializer<
mozilla::gfx::Feature,
mozilla::gfx::Feature::HW_COMPOSITING,
mozilla::gfx::Feature::NumValues>
{};
template <>
struct ParamTraits<mozilla::gfx::FeatureStatus>
: public ContiguousEnumSerializer<
@ -904,6 +913,7 @@ struct ParamTraits<mozilla::Array<T, Length>>
}
};
} /* namespace IPC */
#endif /* __GFXMESSAGEUTILS_H__ */

Просмотреть файл

@ -28,6 +28,7 @@ struct DevicePrefs
FeatureStatus hwCompositing;
FeatureStatus d3d11Compositing;
FeatureStatus oglCompositing;
FeatureStatus advancedLayers;
FeatureStatus useD2D1;
};
@ -63,6 +64,7 @@ struct GPUDeviceData
{
FeatureChange d3d11Compositing;
FeatureChange oglCompositing;
FeatureChange advancedLayers;
GPUDeviceStatus gpuDevice;
};

Просмотреть файл

@ -21,6 +21,7 @@ using mozilla::Telemetry::ScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::KeyedScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::ChildEventData from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::DiscardedData from "mozilla/TelemetryComms.h";
using mozilla::gfx::Feature from "gfxFeature.h";
namespace mozilla {
namespace gfx {
@ -115,6 +116,10 @@ child:
async AddMemoryReport(MemoryReport aReport);
async FinishMemoryReport(uint32_t aGeneration);
// Update the UI process after a feature's status has changed. This is used
// outside of the normal startup flow.
async UpdateFeature(Feature aFeature, FeatureFailure aChange);
};
} // namespace gfx

Просмотреть файл

@ -720,8 +720,8 @@ MLGTextureD3D11::GetShaderResourceView()
}
MLGDeviceD3D11::MLGDeviceD3D11(ID3D11Device* aDevice)
: mDevice(aDevice)
, mScissored(false)
: mDevice(aDevice),
mScissored(false)
{
}
@ -958,6 +958,7 @@ MLGDeviceD3D11::Initialize()
}
mCtx->RSSetState(mRasterizerStateNoScissor);
return MLGDevice::Initialize();
}

Просмотреть файл

@ -51,6 +51,7 @@
#include "mozilla/layers/FrameUniformityData.h"
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/LayerManagerMLGPU.h"
#include "mozilla/layers/LayerTreeOwnerTracker.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layers/PLayerTransactionParent.h"
@ -93,6 +94,9 @@
#ifdef MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING
# include "mozilla/widget/CompositorWidgetParent.h"
#endif
#ifdef XP_WIN
# include "mozilla/gfx/DeviceManagerDx.h"
#endif
#include "LayerScope.h"
@ -1371,18 +1375,43 @@ CompositorBridgeParent::InitializeLayerManager(const nsTArray<LayersBackend>& aB
NS_ASSERTION(!mLayerManager, "Already initialised mLayerManager");
NS_ASSERTION(!mCompositor, "Already initialised mCompositor");
mCompositor = NewCompositor(aBackendHints);
if (!mCompositor) {
return;
if (!InitializeAdvancedLayers(aBackendHints, nullptr)) {
mCompositor = NewCompositor(aBackendHints);
if (!mCompositor) {
return;
}
mLayerManager = new LayerManagerComposite(mCompositor);
}
mLayerManager = new LayerManagerComposite(mCompositor);
mLayerManager->SetCompositorBridgeID(mCompositorBridgeID);
MonitorAutoLock lock(*sIndirectLayerTreesLock);
sIndirectLayerTrees[mRootLayerTreeID].mLayerManager = mLayerManager;
}
bool
CompositorBridgeParent::InitializeAdvancedLayers(const nsTArray<LayersBackend>& aBackendHints,
TextureFactoryIdentifier* aOutIdentifier)
{
#ifdef XP_WIN
if (!mOptions.UseAdvancedLayers()) {
return false;
}
RefPtr<LayerManagerMLGPU> manager = new LayerManagerMLGPU(mWidget);
if (!manager->Initialize()) {
return false;
}
if (aOutIdentifier) {
*aOutIdentifier = manager->GetTextureFactoryIdentifier();
}
mLayerManager = manager;
return true;
#else
return false;
#endif
}
RefPtr<Compositor>
CompositorBridgeParent::NewCompositor(const nsTArray<LayersBackend>& aBackendHints)
{

Просмотреть файл

@ -525,6 +525,8 @@ protected:
void FinishPendingComposite() override;
void CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr) override;
bool InitializeAdvancedLayers(const nsTArray<LayersBackend>& aBackendHints,
TextureFactoryIdentifier* aOutIdentifier);
RefPtr<Compositor> NewCompositor(const nsTArray<LayersBackend>& aBackendHints);
/**

Просмотреть файл

@ -474,11 +474,13 @@ struct ParamTraits<mozilla::layers::CompositorOptions>
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.mUseAPZ);
WriteParam(aMsg, aParam.mUseWebRender);
WriteParam(aMsg, aParam.mUseAdvancedLayers);
}
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->mUseAPZ)
&& ReadParam(aMsg, aIter, &aResult->mUseWebRender);
&& ReadParam(aMsg, aIter, &aResult->mUseWebRender)
&& ReadParam(aMsg, aIter, &aResult->mUseAdvancedLayers);
}
};

Просмотреть файл

@ -50,7 +50,10 @@ LayerManagerMLGPU::LayerManagerMLGPU(widget::CompositorWidget* aWidget)
return;
}
if (!mDevice) {
#ifdef WIN32
mDevice = DeviceManagerDx::Get()->GetMLGDevice();
#endif
if (!mDevice || !mDevice->IsValid()) {
gfxWarning() << "Could not acquire an MLGDevice!";
return;
}

Просмотреть файл

@ -243,7 +243,6 @@ public:
virtual bool Initialize();
// If Initialize returns false, these may return more useful messages.
virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() const = 0;
virtual int32_t GetMaxTextureSize() const = 0;
virtual LayersBackend GetLayersBackend() const = 0;

Просмотреть файл

@ -12,10 +12,12 @@
#include "mozilla/D3DMessageUtils.h"
#include "mozilla/Telemetry.h"
#include "mozilla/WindowsVersion.h"
#include "mozilla/gfx/GPUParent.h"
#include "mozilla/gfx/GraphicsMessages.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/DeviceAttachmentsD3D11.h"
#include "mozilla/layers/MLGDeviceD3D11.h"
#include "nsIGfxInfo.h"
#include <d3d11.h>
#include <ddraw.h>
@ -29,6 +31,7 @@ namespace mozilla {
namespace gfx {
using namespace mozilla::widget;
using namespace mozilla::layers;
StaticAutoPtr<DeviceManagerDx> DeviceManagerDx::sInstance;
@ -132,6 +135,14 @@ DeviceManagerDx::CreateCompositorDevices()
if (!d3d11.IsEnabled()) {
MOZ_ASSERT(!mCompositorDevice);
ReleaseD3D11();
// Sync Advanced-Layers with D3D11.
if (gfxConfig::IsEnabled(Feature::ADVANCED_LAYERS)) {
gfxConfig::SetFailed(Feature::ADVANCED_LAYERS,
FeatureStatus::Unavailable,
"Requires D3D11",
NS_LITERAL_CSTRING("FEATURE_FAILURE_NO_D3D11"));
}
return false;
}
@ -607,6 +618,76 @@ DeviceManagerDx::CreateDecoderDevice()
return device;
}
RefPtr<MLGDevice>
DeviceManagerDx::GetMLGDevice()
{
MutexAutoLock lock(mDeviceLock);
if (!mMLGDevice) {
MutexAutoUnlock unlock(mDeviceLock);
CreateMLGDevice();
}
return mMLGDevice;
}
static void
DisableAdvancedLayers(FeatureStatus aStatus, const nsCString aMessage, const nsCString& aFailureId)
{
if (!NS_IsMainThread()) {
NS_DispatchToMainThread(NS_NewRunnableFunction([aStatus, aMessage, aFailureId] () -> void {
DisableAdvancedLayers(aStatus, aMessage, aFailureId);
}));
return;
}
MOZ_ASSERT(NS_IsMainThread());
FeatureState& al = gfxConfig::GetFeature(Feature::ADVANCED_LAYERS);
if (!al.IsEnabled()) {
return;
}
al.SetFailed(aStatus, aMessage.get(), aFailureId);
FeatureFailure info(aStatus, aMessage, aFailureId);
if (GPUParent* gpu = GPUParent::GetSingleton()) {
gpu->SendUpdateFeature(Feature::ADVANCED_LAYERS, info);
}
}
void
DeviceManagerDx::CreateMLGDevice()
{
MOZ_ASSERT(layers::CompositorThreadHolder::IsInCompositorThread());
RefPtr<ID3D11Device> d3d11Device = GetCompositorDevice();
if (!d3d11Device) {
DisableAdvancedLayers(FeatureStatus::Unavailable,
NS_LITERAL_CSTRING("Advanced-layers requires a D3D11 device"),
NS_LITERAL_CSTRING("FEATURE_FAILURE_NEED_D3D11_DEVICE"));
return;
}
RefPtr<MLGDeviceD3D11> device = new MLGDeviceD3D11(d3d11Device);
if (!device->Initialize()) {
DisableAdvancedLayers(FeatureStatus::Failed,
device->GetFailureMessage(),
device->GetFailureId());
return;
}
// While the lock was unheld, we should not have created an MLGDevice, since
// this should only be called on the compositor thread.
MutexAutoLock lock(mDeviceLock);
MOZ_ASSERT(!mMLGDevice);
// Only set the MLGDevice if the compositor device is still the same.
// Otherwise we could possibly have a bad MLGDevice if a device reset
// just occurred.
if (mCompositorDevice == d3d11Device) {
mMLGDevice = device;
}
}
void
DeviceManagerDx::ResetDevices()
{
@ -614,6 +695,7 @@ DeviceManagerDx::ResetDevices()
mAdapter = nullptr;
mCompositorAttachments = nullptr;
mMLGDevice = nullptr;
mCompositorDevice = nullptr;
mContentDevice = nullptr;
mDeviceStatus = Nothing();
@ -976,11 +1058,17 @@ DeviceManagerDx::PreloadAttachmentsOnCompositorThread()
return;
}
RefPtr<Runnable> task = NS_NewRunnableFunction([]() -> void {
bool enableAL = gfxConfig::IsEnabled(Feature::ADVANCED_LAYERS);
RefPtr<Runnable> task = NS_NewRunnableFunction([enableAL]() -> void {
if (DeviceManagerDx* dm = DeviceManagerDx::Get()) {
RefPtr<ID3D11Device> device;
RefPtr<layers::DeviceAttachmentsD3D11> attachments;
dm->GetCompositorDevices(&device, &attachments);
if (enableAL) {
dm->GetMLGDevice();
} else {
RefPtr<ID3D11Device> device;
RefPtr<layers::DeviceAttachmentsD3D11> attachments;
dm->GetCompositorDevices(&device, &attachments);
}
}
});
loop->PostTask(task.forget());

Просмотреть файл

@ -37,6 +37,7 @@ namespace mozilla {
class ScopedGfxFeatureReporter;
namespace layers {
class DeviceAttachmentsD3D11;
class MLGDevice;
} // namespace layers
namespace gfx {
@ -57,6 +58,7 @@ public:
RefPtr<ID3D11Device> GetCompositorDevice();
RefPtr<ID3D11Device> GetContentDevice();
RefPtr<ID3D11Device> CreateDecoderDevice();
RefPtr<layers::MLGDevice> GetMLGDevice();
IDirectDraw7* GetDirectDraw();
unsigned GetCompositorFeatureLevel() const;
@ -120,6 +122,7 @@ private:
RefPtr<ID3D11Device>& aOutDevice);
void CreateWARPCompositorDevice();
void CreateMLGDevice();
mozilla::gfx::FeatureStatus CreateContentDevice();
@ -153,6 +156,7 @@ private:
RefPtr<ID3D11Device> mContentDevice;
RefPtr<ID3D11Device> mDecoderDevice;
RefPtr<layers::DeviceAttachmentsD3D11> mCompositorAttachments;
RefPtr<layers::MLGDevice> mMLGDevice;
bool mCompositorDeviceSupportsVideo;
Maybe<D3D11DeviceStatus> mDeviceStatus;

Просмотреть файл

@ -2756,6 +2756,7 @@ gfxPlatform::ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData)
MOZ_ASSERT(XRE_IsParentProcess());
gfxConfig::ImportChange(Feature::OPENGL_COMPOSITING, aData.oglCompositing());
gfxConfig::ImportChange(Feature::ADVANCED_LAYERS, aData.advancedLayers());
}
bool

Просмотреть файл

@ -567,6 +567,7 @@ private:
DECL_GFX_PREF(Once, "layers.mlgpu.enable-cpu-occlusion", AdvancedLayersEnableCPUOcclusion, bool, true);
DECL_GFX_PREF(Once, "layers.mlgpu.enable-depth-buffer", AdvancedLayersEnableDepthBuffer, bool, false);
DECL_GFX_PREF(Live, "layers.mlgpu.enable-invalidation", AdvancedLayersUseInvalidation, bool, true);
DECL_GFX_PREF(Once, "layers.mlgpu.enable-on-windows7", AdvancedLayersEnableOnWindows7, bool, false);
DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.force-disabled", LayersOffMainThreadCompositionForceDisabled, bool, false);
DECL_GFX_PREF(Live, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate, int32_t,-1);
DECL_GFX_PREF(Live, "layers.orientation.sync.timeout", OrientationSyncMillis, uint32_t, (uint32_t)0);

Просмотреть файл

@ -1385,6 +1385,28 @@ gfxWindowsPlatform::InitializeD3D11Config()
// Force D3D11 on even if we disabled it.
d3d11.UserForceEnable("User force-enabled WARP");
}
// Only enable Advanced Layers if D3D11 succeeded.
if (d3d11.IsEnabled()) {
FeatureState& al = gfxConfig::GetFeature(Feature::ADVANCED_LAYERS);
al.SetDefaultFromPref(
gfxPrefs::GetAdvancedLayersEnabledDoNotUseDirectlyPrefName(),
true /* aIsEnablePref */,
gfxPrefs::GetAdvancedLayersEnabledDoNotUseDirectlyPrefDefault());
// Windows 7 has an extra pref since it uses totally different buffer paths
// that haven't been performance tested yet.
if (al.IsEnabled() && !IsWin8OrLater()) {
if (gfxPrefs::AdvancedLayersEnableOnWindows7()) {
al.UserEnable("Enabled for Windows 7 via user-preference");
} else {
al.Disable(FeatureStatus::Disabled,
"Advanced Layers is disabled on Windows 7 by default",
NS_LITERAL_CSTRING("FEATURE_FAILURE_DISABLED_ON_WIN7"));
}
}
}
}
/* static */ void

Просмотреть файл

@ -80,6 +80,7 @@
#include "gfxConfig.h"
#include "mozilla/layers/CompositorSession.h"
#include "VRManagerChild.h"
#include "gfxConfig.h"
#ifdef DEBUG
#include "nsIObserver.h"
@ -1260,6 +1261,9 @@ void nsBaseWidget::CreateCompositor(int aWidth, int aHeight)
bool enableAPZ = UseAPZ();
CompositorOptions options(enableAPZ, enableWR);
bool enableAL = gfx::gfxConfig::IsEnabled(gfx::Feature::ADVANCED_LAYERS);
options.SetUseAdvancedLayers(enableAL);
RefPtr<LayerManager> lm;
if (options.UseWebRender()) {
lm = new WebRenderLayerManager(this);