Commit b6a2f6bc by Rafael Cintron Committed by Commit Bot

Avoid unnecessary loading of D3D9.dll

D3D9.dll is being loaded by ANGLE when using D3D11. This change removes the D3D9 dependency. - Delayload D3D9.dll using ldflags in BUILD.gn - Replace Renderer11 usage of DebugAnnotator9 with DebugAnnotator11. Using debug annotations with Visual Studio PIX tools now requires Windows 10. - Refactor DebugAnnotator11 to QI ID3DUserDefinedAnnotation from the renderer's ID3D11DeviceContext instead of making a 'null' device. Bug: angleproject:3234 Change-Id: I10a2b537e07cda2094b08abf02b7876bbe5009f8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1508643 Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 14126505
...@@ -455,8 +455,10 @@ config("libANGLE_config") { ...@@ -455,8 +455,10 @@ config("libANGLE_config") {
cflags = [] cflags = []
defines = [] defines = []
libs = [] libs = []
ldflags = []
if (angle_enable_d3d9) { if (angle_enable_d3d9) {
defines += [ "ANGLE_ENABLE_D3D9" ] defines += [ "ANGLE_ENABLE_D3D9" ]
ldflags += [ "/DELAYLOAD:d3d9.dll" ]
} }
if (angle_enable_d3d11) { if (angle_enable_d3d11) {
defines += [ "ANGLE_ENABLE_D3D11" ] defines += [ "ANGLE_ENABLE_D3D11" ]
......
...@@ -8,35 +8,19 @@ ...@@ -8,35 +8,19 @@
#include "libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h" #include "libANGLE/renderer/d3d/d3d11/DebugAnnotator11.h"
#include "common/debug.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include <VersionHelpers.h>
namespace rx namespace rx
{ {
DebugAnnotator11::DebugAnnotator11() DebugAnnotator11::DebugAnnotator11() {}
: mInitialized(false), mD3d11Module(nullptr), mUserDefinedAnnotation(nullptr)
{
// D3D11 devices can't be created during DllMain.
// We defer device creation until the object is actually used.
}
DebugAnnotator11::~DebugAnnotator11()
{
if (mInitialized)
{
SafeRelease(mUserDefinedAnnotation);
#if !defined(ANGLE_ENABLE_WINDOWS_STORE) DebugAnnotator11::~DebugAnnotator11() {}
FreeLibrary(mD3d11Module);
#endif // !ANGLE_ENABLE_WINDOWS_STORE
}
}
void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessage) void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessage)
{ {
initializeDevice();
angle::LoggingAnnotator::beginEvent(eventName, eventMessage); angle::LoggingAnnotator::beginEvent(eventName, eventMessage);
if (mUserDefinedAnnotation != nullptr) if (mUserDefinedAnnotation != nullptr)
{ {
...@@ -48,8 +32,6 @@ void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessag ...@@ -48,8 +32,6 @@ void DebugAnnotator11::beginEvent(const char *eventName, const char *eventMessag
void DebugAnnotator11::endEvent(const char *eventName) void DebugAnnotator11::endEvent(const char *eventName)
{ {
initializeDevice();
angle::LoggingAnnotator::endEvent(eventName); angle::LoggingAnnotator::endEvent(eventName);
if (mUserDefinedAnnotation != nullptr) if (mUserDefinedAnnotation != nullptr)
{ {
...@@ -59,8 +41,6 @@ void DebugAnnotator11::endEvent(const char *eventName) ...@@ -59,8 +41,6 @@ void DebugAnnotator11::endEvent(const char *eventName)
void DebugAnnotator11::setMarker(const char *markerName) void DebugAnnotator11::setMarker(const char *markerName)
{ {
initializeDevice();
angle::LoggingAnnotator::setMarker(markerName); angle::LoggingAnnotator::setMarker(markerName);
if (mUserDefinedAnnotation != nullptr) if (mUserDefinedAnnotation != nullptr)
{ {
...@@ -72,55 +52,31 @@ void DebugAnnotator11::setMarker(const char *markerName) ...@@ -72,55 +52,31 @@ void DebugAnnotator11::setMarker(const char *markerName)
bool DebugAnnotator11::getStatus() bool DebugAnnotator11::getStatus()
{ {
#if defined(ANGLE_ENABLE_WINDOWS_STORE)
static_assert(NTDDI_VERSION >= NTDDI_WIN10, "GetStatus only works on Win10 and above");
initializeDevice();
if (mUserDefinedAnnotation != nullptr) if (mUserDefinedAnnotation != nullptr)
{ {
return !!(mUserDefinedAnnotation->GetStatus()); return !!(mUserDefinedAnnotation->GetStatus());
} }
return true; // Default if initializeDevice() failed return false;
#else
// We can't detect GetStatus() on desktop ANGLE builds so always return true.
return true;
#endif // ANGLE_ENABLE_WINDOWS_STORE
} }
void DebugAnnotator11::initializeDevice() void DebugAnnotator11::initialize(ID3D11DeviceContext *context)
{ {
if (!mInitialized) // ID3DUserDefinedAnnotation.GetStatus only works on Windows10 or greater.
// Returning true unconditionally from DebugAnnotator11::getStatus() means
// writing out all compiled shaders to temporary files even if debugging
// tools are not attached. See rx::ShaderD3D::prepareSourceAndReturnOptions.
// If you want debug annotations, you must use Windows 10.
if (IsWindows10OrGreater())
{ {
#if !defined(ANGLE_ENABLE_WINDOWS_STORE) mUserDefinedAnnotation.Attach(
mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context));
ASSERT(mD3d11Module);
PFN_D3D11_CREATE_DEVICE D3D11CreateDevice =
(PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice");
ASSERT(D3D11CreateDevice != nullptr);
#endif // !ANGLE_ENABLE_WINDOWS_STORE
ID3D11Device *device = nullptr;
ID3D11DeviceContext *context = nullptr;
HRESULT hr = E_FAIL;
// Create a D3D_DRIVER_TYPE_NULL device, which is much cheaper than other types of device.
hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_NULL, nullptr, 0, nullptr, 0,
D3D11_SDK_VERSION, &device, nullptr, &context);
ASSERT(SUCCEEDED(hr));
if (SUCCEEDED(hr))
{
mUserDefinedAnnotation =
d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context);
ASSERT(mUserDefinedAnnotation != nullptr);
mInitialized = true;
}
SafeRelease(device);
SafeRelease(context);
} }
} }
void DebugAnnotator11::release()
{
mUserDefinedAnnotation.Reset();
}
} // namespace rx } // namespace rx
...@@ -19,17 +19,15 @@ class DebugAnnotator11 : public angle::LoggingAnnotator ...@@ -19,17 +19,15 @@ class DebugAnnotator11 : public angle::LoggingAnnotator
public: public:
DebugAnnotator11(); DebugAnnotator11();
~DebugAnnotator11() override; ~DebugAnnotator11() override;
void initialize(ID3D11DeviceContext *context);
void release();
void beginEvent(const char *eventName, const char *eventMessage) override; void beginEvent(const char *eventName, const char *eventMessage) override;
void endEvent(const char *eventName) override; void endEvent(const char *eventName) override;
void setMarker(const char *markerName) override; void setMarker(const char *markerName) override;
bool getStatus() override; bool getStatus() override;
private: private:
void initializeDevice(); angle::ComPtr<ID3DUserDefinedAnnotation> mUserDefinedAnnotation;
bool mInitialized;
HMODULE mD3d11Module;
ID3DUserDefinedAnnotation *mUserDefinedAnnotation;
static constexpr size_t kMaxMessageLength = 256; static constexpr size_t kMaxMessageLength = 256;
wchar_t mWCharMessage[kMaxMessageLength]; wchar_t mWCharMessage[kMaxMessageLength];
}; };
......
...@@ -68,13 +68,6 @@ ...@@ -68,13 +68,6 @@
# include "libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h" # include "libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h"
#endif #endif
// Include the D3D9 debug annotator header for use by the desktop D3D11 renderer
// because the D3D11 interface method ID3DUserDefinedAnnotation::GetStatus
// doesn't work with the Graphics Diagnostics tools in Visual Studio 2013.
#ifdef ANGLE_ENABLE_D3D9
# include "libANGLE/renderer/d3d/d3d9/DebugAnnotator9.h"
#endif
// Enable ANGLE_SKIP_DXGI_1_2_CHECK if there is not a possibility of using cross-process // Enable ANGLE_SKIP_DXGI_1_2_CHECK if there is not a possibility of using cross-process
// HWNDs or the Windows 7 Platform Update (KB2670838) is expected to be installed. // HWNDs or the Windows 7 Platform Update (KB2670838) is expected to be installed.
#ifndef ANGLE_SKIP_DXGI_1_2_CHECK #ifndef ANGLE_SKIP_DXGI_1_2_CHECK
...@@ -420,8 +413,7 @@ Renderer11::Renderer11(egl::Display *display) ...@@ -420,8 +413,7 @@ Renderer11::Renderer11(egl::Display *display)
mLastHistogramUpdateTime( mLastHistogramUpdateTime(
ANGLEPlatformCurrent()->monotonicallyIncreasingTime(ANGLEPlatformCurrent())), ANGLEPlatformCurrent()->monotonicallyIncreasingTime(ANGLEPlatformCurrent())),
mDebug(nullptr), mDebug(nullptr),
mScratchMemoryBuffer(ScratchMemoryBufferLifetime), mScratchMemoryBuffer(ScratchMemoryBufferLifetime)
mAnnotator(nullptr)
{ {
mLineLoopIB = nullptr; mLineLoopIB = nullptr;
mTriangleFanIB = nullptr; mTriangleFanIB = nullptr;
...@@ -536,19 +528,6 @@ Renderer11::Renderer11(egl::Display *display) ...@@ -536,19 +528,6 @@ Renderer11::Renderer11(egl::Display *display)
const EGLenum presentPath = static_cast<EGLenum>(attributes.get( const EGLenum presentPath = static_cast<EGLenum>(attributes.get(
EGL_EXPERIMENTAL_PRESENT_PATH_ANGLE, EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE)); EGL_EXPERIMENTAL_PRESENT_PATH_ANGLE, EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE));
mPresentPathFastEnabled = (presentPath == EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE); mPresentPathFastEnabled = (presentPath == EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE);
// The D3D11 renderer must choose the D3D9 debug annotator because the D3D11 interface
// method ID3DUserDefinedAnnotation::GetStatus on desktop builds doesn't work with the Graphics
// Diagnostics tools in Visual Studio 2013.
// The D3D9 annotator works properly for both D3D11 and D3D9.
// Incorrect status reporting can cause ANGLE to log unnecessary debug events.
#ifdef ANGLE_ENABLE_D3D9
mAnnotator = new DebugAnnotator9();
#else
mAnnotator = new DebugAnnotator11();
#endif
ASSERT(mAnnotator);
gl::InitializeDebugAnnotations(mAnnotator);
} }
Renderer11::~Renderer11() Renderer11::~Renderer11()
...@@ -835,6 +814,9 @@ egl::Error Renderer11::initializeD3DDevice() ...@@ -835,6 +814,9 @@ egl::Error Renderer11::initializeD3DDevice()
d3d11::SetDebugName(mDeviceContext, "DeviceContext"); d3d11::SetDebugName(mDeviceContext, "DeviceContext");
mAnnotator.initialize(mDeviceContext);
gl::InitializeDebugAnnotations(&mAnnotator);
return egl::NoError(); return egl::NoError();
} }
...@@ -1930,11 +1912,8 @@ void Renderer11::release() ...@@ -1930,11 +1912,8 @@ void Renderer11::release()
{ {
mScratchMemoryBuffer.clear(); mScratchMemoryBuffer.clear();
if (mAnnotator != nullptr) mAnnotator.release();
{ gl::UninitializeDebugAnnotations();
gl::UninitializeDebugAnnotations();
SafeDelete(mAnnotator);
}
releaseDeviceResources(); releaseDeviceResources();
...@@ -3747,7 +3726,7 @@ gl::Version Renderer11::getMaxSupportedESVersion() const ...@@ -3747,7 +3726,7 @@ gl::Version Renderer11::getMaxSupportedESVersion() const
gl::DebugAnnotator *Renderer11::getAnnotator() gl::DebugAnnotator *Renderer11::getAnnotator()
{ {
return mAnnotator; return &mAnnotator;
} }
angle::Result Renderer11::dispatchCompute(const gl::Context *context, angle::Result Renderer11::dispatchCompute(const gl::Context *context,
......
...@@ -605,7 +605,7 @@ class Renderer11 : public RendererD3D ...@@ -605,7 +605,7 @@ class Renderer11 : public RendererD3D
angle::ScratchBuffer mScratchMemoryBuffer; angle::ScratchBuffer mScratchMemoryBuffer;
gl::DebugAnnotator *mAnnotator; DebugAnnotator11 mAnnotator;
mutable Optional<bool> mSupportsShareHandles; mutable Optional<bool> mSupportsShareHandles;
ResourceManager11 mResourceManager11; ResourceManager11 mResourceManager11;
......
...@@ -189,7 +189,7 @@ void Renderer9::release() ...@@ -189,7 +189,7 @@ void Renderer9::release()
egl::Error Renderer9::initialize() egl::Error Renderer9::initialize()
{ {
TRACE_EVENT0("gpu.angle", "GetModuleHandle_d3d9"); TRACE_EVENT0("gpu.angle", "GetModuleHandle_d3d9");
mD3d9Module = GetModuleHandle(TEXT("d3d9.dll")); mD3d9Module = ::LoadLibrary(TEXT("d3d9.dll"));
if (mD3d9Module == nullptr) if (mD3d9Module == nullptr)
{ {
......
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