Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions winml/dll/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@

using namespace winmlp;

void __stdcall OnErrorReported(bool alreadyReported, wil::FailureInfo const& failure) WI_NOEXCEPT {
if (!alreadyReported) {
winrt::hstring message(failure.pszMessage ? failure.pszMessage : L"");
telemetry_helper.LogRuntimeError(
failure.hr,
winrt::to_string(message),
failure.pszFile,
failure.pszFunction,
failure.uLineNumber);
}
}

extern "C" BOOL WINAPI DllMain(_In_ HINSTANCE hInstance, DWORD dwReason, _In_ void* lpvReserved) {
switch (dwReason) {
case DLL_PROCESS_ATTACH:
Expand All @@ -40,7 +28,6 @@ extern "C" BOOL WINAPI DllMain(_In_ HINSTANCE hInstance, DWORD dwReason, _In_ vo
// Register the TraceLogging provider feeding telemetry. It's OK if this fails;
// trace logging calls just become no-ops.
telemetry_helper.Register();
wil::SetResultTelemetryFallback(&OnErrorReported);
break;
case DLL_PROCESS_DETACH:
telemetry_helper.LogWinMLShutDown();
Expand Down
18 changes: 15 additions & 3 deletions winml/lib/Api.Image/D3DDeviceCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,28 @@ D3DDeviceCache::D3DDeviceCache(winml::LearningModelDeviceKind const& deviceKind)
CommonDeviceHelpers::AdapterEnumerationSupport support;
WINML_THROW_IF_FAILED(CommonDeviceHelpers::GetAdapterEnumerationSupport(&support));

const char errStr[] = "No hardware adapters available";
const char noHardwareAdaptersAvailableErrStr[] = "No hardware adapters available";
const char failedToObtainHardwareAdaptersErrStr[] = "Failed to obtain hardware adapters.";
HRESULT hardwareAdapterSuccessfullyObtained = S_OK;
if (support.has_dxgi) {
winrt::com_ptr<IDXGIAdapter1> spAdapter;
WINML_THROW_IF_FAILED_MSG(GetDXGIHardwareAdapterWithPreference(preference, spAdapter.put()), errStr);
hardwareAdapterSuccessfullyObtained = GetDXGIHardwareAdapterWithPreference(preference, spAdapter.put());
if (hardwareAdapterSuccessfullyObtained == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) {
WINML_THROW_HR_MSG_NO_TELEMETRY_SENT(hardwareAdapterSuccessfullyObtained, noHardwareAdaptersAvailableErrStr);
} else {
WINML_THROW_IF_FAILED_MSG(hardwareAdapterSuccessfullyObtained, failedToObtainHardwareAdaptersErrStr);
}
WINML_THROW_IF_FAILED(D3D12CreateDevice(spAdapter.get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(device_.put())));
}
#ifdef ENABLE_DXCORE
if (support.has_dxgi == false) {
winrt::com_ptr<IDXCoreAdapter> spAdapter;
WINML_THROW_IF_FAILED_MSG(GetDXCoreHardwareAdapterWithPreference(preference, spAdapter.put()), errStr);
hardwareAdapterSuccessfullyObtained = GetDXCoreHardwareAdapterWithPreference(preference, spAdapter.put());
if (hardwareAdapterSuccessfullyObtained == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) {
WINML_THROW_HR_MSG_NO_TELEMETRY_SENT(hardwareAdapterSuccessfullyObtained, noHardwareAdaptersAvailableErrStr);
} else {
WINML_THROW_IF_FAILED_MSG(hardwareAdapterSuccessfullyObtained, failedToObtainHardwareAdaptersErrStr);
}
WINML_THROW_IF_FAILED(D3D12CreateDevice(spAdapter.get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(device_.put())));
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions winml/lib/Common/inc/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
throw winrt::hresult_error(_result, winrt::hresult_error::from_abi); \
}

#define WINML_THROW_HR_MSG_NO_TELEMETRY_SENT(hr, message, ...) \
do { \
auto _hr = hr; \
char msg[1024]; \
sprintf_s(msg, message, __VA_ARGS__); \
winrt::hstring errorMessage(_winml::Strings::HStringFromUTF8(msg)); \
throw winrt::hresult_error(_hr, errorMessage); \
} while (0)

#define WINML_THROW_IF_FAILED(hr) \
do { \
HRESULT _hr = hr; \
Expand Down