From 46e141093252c3f5670b1df9042e8b96e3543791 Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 08:45:34 -0400 Subject: [PATCH 01/10] Remove DirectX SDK search from CMake The DirectX APIs are now part of the Windows SDK. We should stop relying on the ancient SDK. This is step one. (backport from master) --- StepmaniaCore.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/StepmaniaCore.cmake b/StepmaniaCore.cmake index 3d91931b24..502085ac96 100644 --- a/StepmaniaCore.cmake +++ b/StepmaniaCore.cmake @@ -276,8 +276,6 @@ else() endif() if(WIN32) - find_package(DirectX REQUIRED) - if(MINGW AND WITH_FFMPEG AND NOT WITH_SYSTEM_FFMPEG) include("${SM_CMAKE_DIR}/SetupFfmpeg.cmake") set(HAS_FFMPEG TRUE) From cdc4bd9da2ef9af54f96e38666f5f42217699388 Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 08:48:19 -0400 Subject: [PATCH 02/10] Replace missing dxguid.lib functionality One thing that did not make it into the move to the Windows SDK is the dxguid.lib library, which defined the IIDs for all of the DirectX interfaces. This replaces that, defining the ones we use. Currently, we only need to define the DirectInput IIDs, so that is all that is here. (backport from master) --- src/CMakeData-os.cmake | 1 + src/archutils/Win32/DirectXGuids.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/archutils/Win32/DirectXGuids.cpp diff --git a/src/CMakeData-os.cmake b/src/CMakeData-os.cmake index 4da9486e4d..a8116942c0 100644 --- a/src/CMakeData-os.cmake +++ b/src/CMakeData-os.cmake @@ -42,6 +42,7 @@ else() "archutils/Win32/CrashHandlerNetworking.cpp" "archutils/Win32/DebugInfoHunt.cpp" "archutils/Win32/DialogUtil.cpp" + "archutils/Win32/DirectXGuids.cpp" "archutils/Win32/DirectXHelpers.cpp" "archutils/Win32/ErrorStrings.cpp" "archutils/Win32/GetFileInformation.cpp" diff --git a/src/archutils/Win32/DirectXGuids.cpp b/src/archutils/Win32/DirectXGuids.cpp new file mode 100644 index 0000000000..22ae05e658 --- /dev/null +++ b/src/archutils/Win32/DirectXGuids.cpp @@ -0,0 +1,13 @@ +#include "global.h" + +// The purpose of this file is to define the various GUIDs we need, which +// we used to get via dxguid.lib in the DirectX SDK. The DirectX SDK has +// been discontinued and (mostly) rolled into the Windows SDK, but it is +// missing a few features. One of which is dxguid.lib. + +// if you wind up running into other GUIDs you need, add them here + +#define INITGUID + +#define DIRECTINPUT_VERSION 0x0800 +#include From dfb524a54787899b51cf28fcafdcba19170fc5d8 Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 08:56:03 -0400 Subject: [PATCH 03/10] Fix incorrect usage of GetLastError in LLW_Win32 GetLastError must be called before any other function which could possibly change it, otherwise we will lose the error code. (backport from master) --- .../LowLevelWindow/LowLevelWindow_Win32.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp b/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp index 25ace08fa5..35d23415bf 100644 --- a/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp +++ b/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp @@ -214,10 +214,11 @@ RString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew /* Set the pixel format. */ if( !SetPixelFormat(GraphicsWindow::GetHDC(), iPixelFormat, &pixfmt) ) { + DWORD err = GetLastError(); /* Destroy the window. */ DestroyGraphicsWindowAndOpenGLContext(); - return werr_ssprintf( GetLastError(), "Pixel format failed" ); + return werr_ssprintf( err, "Pixel format failed" ); } DescribePixelFormat( GraphicsWindow::GetHDC(), iPixelFormat, sizeof(g_CurrentPixelFormat), &g_CurrentPixelFormat ); @@ -232,15 +233,17 @@ RString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew g_HGLRC = wglCreateContext( GraphicsWindow::GetHDC() ); if ( g_HGLRC == nullptr ) { + DWORD err = GetLastError(); DestroyGraphicsWindowAndOpenGLContext(); - return hr_ssprintf( GetLastError(), "wglCreateContext" ); + return hr_ssprintf( err, "wglCreateContext" ); } g_HGLRC_Background = wglCreateContext( GraphicsWindow::GetHDC() ); if( g_HGLRC_Background == nullptr ) { + DWORD err = GetLastError(); DestroyGraphicsWindowAndOpenGLContext(); - return hr_ssprintf( GetLastError(), "wglCreateContext" ); + return hr_ssprintf( err, "wglCreateContext" ); } if( !wglShareLists(g_HGLRC, g_HGLRC_Background) ) @@ -252,8 +255,9 @@ RString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew if( !wglMakeCurrent( GraphicsWindow::GetHDC(), g_HGLRC ) ) { + DWORD err = GetLastError(); DestroyGraphicsWindowAndOpenGLContext(); - return hr_ssprintf( GetLastError(), "wglCreateContext" ); + return hr_ssprintf( err, "wglCreateContext" ); } } return RString(); // we set the video mode successfully @@ -268,8 +272,9 @@ void LowLevelWindow_Win32::BeginConcurrentRendering() { if( !wglMakeCurrent( GraphicsWindow::GetHDC(), g_HGLRC_Background ) ) { - LOG->Warn( hr_ssprintf(GetLastError(), "wglMakeCurrent") ); - FAIL_M( hr_ssprintf(GetLastError(), "wglMakeCurrent") ); + DWORD err = GetLastError(); + LOG->Warn( hr_ssprintf(err, "wglMakeCurrent") ); + FAIL_M( hr_ssprintf(err, "wglMakeCurrent") ); } } From dce0d0f91cf589790dba8eaa79008ffe7811b496 Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 08:58:05 -0400 Subject: [PATCH 04/10] Fix potential security issue with FormatMessage use From MSDN: Security Remarks If this function is called without FORMAT_MESSAGE_IGNORE_INSERTS, the Arguments parameter must contain enough parameters to satisfy all insertion sequences in the message string, and they must be of the correct type. Therefore, do not use untrusted or unknown message strings with inserts enabled because they can contain more insertion sequences than Arguments provides, or those that may be of the wrong type. In particular, it is unsafe to take an arbitrary system error code returned from an API and use FORMAT_MESSAGE_FROM_SYSTEM without FORMAT_MESSAGE_IGNORE_INSERTS. (backport from master) --- src/archutils/Win32/ErrorStrings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archutils/Win32/ErrorStrings.cpp b/src/archutils/Win32/ErrorStrings.cpp index 336c5a0324..4c79144b81 100644 --- a/src/archutils/Win32/ErrorStrings.cpp +++ b/src/archutils/Win32/ErrorStrings.cpp @@ -7,7 +7,7 @@ RString werr_ssprintf( int err, const char *fmt, ... ) { char buf[1024] = ""; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, 0, buf, sizeof(buf), nullptr); // Why is FormatMessage returning text ending with \r\n? (who? -aj) From e9ca966af71a1566cba7d7a279381f9eee81524f Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 09:00:24 -0400 Subject: [PATCH 05/10] Allow CreateScreenshot to return nullptr RageDisplay_D3D::CreateScreenshot will be returning nullptr until I get around to re-implementing it without using d3dx, which is another thing that did not make the move into the Windows SDK. (backport from master) --- src/RageDisplay.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/RageDisplay.cpp b/src/RageDisplay.cpp index 4aeebd4ab9..68e1c0558f 100644 --- a/src/RageDisplay.cpp +++ b/src/RageDisplay.cpp @@ -766,6 +766,13 @@ bool RageDisplay::SaveScreenshot( RString sPath, GraphicsFileFormat format ) RageTimer timer; RageSurface *surface = this->CreateScreenshot(); // LOG->Trace( "CreateScreenshot took %f seconds", timer.GetDeltaTime() ); + + if (nullptr == surface) + { + LOG->Trace("CreateScreenshot failed to return a surface"); + return false; + } + /* Unless we're in lossless, resize the image to 640x480. If we're saving lossy, * there's no sense in saving 1280x960 screenshots, and we don't want to output * screenshots in a strange (non-1) sample aspect ratio. */ From 6aedffabf3097ee89a66aecd3a312016d3131c5e Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 09:29:01 -0400 Subject: [PATCH 06/10] Add GetErrorString to DirectXHelpers; Add error list * Another thing lost was DXGetErrorString. Re-implement it. * Include a partial list of errors. (backported from master, where it was two commits) Note: If we ever drop support for windows older than win8, we can remove this and just call FormatMessage. --- src/archutils/Win32/DirectXErrorList.h | 199 +++++++++++++++++++++++++ src/archutils/Win32/DirectXHelpers.cpp | 35 +++-- src/archutils/Win32/DirectXHelpers.h | 2 + 3 files changed, 221 insertions(+), 15 deletions(-) create mode 100644 src/archutils/Win32/DirectXErrorList.h diff --git a/src/archutils/Win32/DirectXErrorList.h b/src/archutils/Win32/DirectXErrorList.h new file mode 100644 index 0000000000..d2f670a5c0 --- /dev/null +++ b/src/archutils/Win32/DirectXErrorList.h @@ -0,0 +1,199 @@ +// This file is intended to be included in the middle of a function after +// defining the macro to do what you want. + +// NOTE: once we stop targeting anything older than Windows 8, we can drop this file +// and just call FormatMessage. + +#if defined(__DINPUT_INCLUDED__) +// ------------------------------------------------------------- +// dinput.h error codes +// ------------------------------------------------------------- +DXERRMSG(DI_OK, "DI_OK") +DXERRMSG(DI_NOTATTACHED, "DI_NOTATTACHED") +//DXERRMSG(DI_BUFFEROVERFLOW, "DI_BUFFEROVERFLOW") +//DXERRMSG(DI_PROPNOEFFECT, "DI_PROPNOEFFECT") +//DXERRMSG(DI_NOEFFECT, "DI_NOEFFECT") +DXERRMSG(DI_POLLEDDEVICE, "DI_POLLEDDEVICE") +DXERRMSG(DI_DOWNLOADSKIPPED, "DI_DOWNLOADSKIPPED") +DXERRMSG(DI_EFFECTRESTARTED, "DI_EFFECTRESTARTED") +//DXERRMSG(DI_SETTINGSNOTSAVED_ACCESSDENIED, "DI_SETTINGSNOTSAVED_ACCESSDENIED") +//DXERRMSG(DI_SETTINGSNOTSAVED_DISKFULL, "DI_SETTINGSNOTSAVED_DISKFULL") +DXERRMSG(DI_TRUNCATED, "DI_TRUNCATED") +DXERRMSG(DI_TRUNCATEDANDRESTARTED, "DI_TRUNCATEDANDRESTARTED") +DXERRMSG(DI_WRITEPROTECT, "DI_WRITEPROTECT") +DXERRMSG(DIERR_OLDDIRECTINPUTVERSION, "The application requires a newer version of DirectInput.") +DXERRMSG(DIERR_GENERIC, "DIERR_GENERIC") +//DXERRMSG(DIERR_OLDDIRECTINPUTVERSION, "DIERR_OLDDIRECTINPUTVERSION") +DXERRMSG(DIERR_BETADIRECTINPUTVERSION, "The application was written for an unsupported prerelease version of DirectInput.") +DXERRMSG(DIERR_BADDRIVERVER, "The object could not be created due to an incompatible driver version or mismatched or incomplete driver components.") +DXERRMSG(DIERR_DEVICENOTREG, "DIERR_DEVICENOTREG") +DXERRMSG(DIERR_NOTFOUND, "The requested object does not exist.") +//DXERRMSG(DIERR_OBJECTNOTFOUND, "DIERR_OBJECTNOTFOUND") +DXERRMSG(DIERR_INVALIDPARAM, "DIERR_INVALIDPARAM") +DXERRMSG(DIERR_NOINTERFACE, "DIERR_NOINTERFACE") +//DXERRMSG(DIERR_GENERIC, "DIERR_GENERIC") +DXERRMSG(DIERR_OUTOFMEMORY, "DIERR_OUTOFMEMORY") +DXERRMSG(DIERR_UNSUPPORTED, "DIERR_UNSUPPORTED") +DXERRMSG(DIERR_NOTINITIALIZED, "This object has not been initialized") +DXERRMSG(DIERR_ALREADYINITIALIZED, "This object is already initialized") +DXERRMSG(DIERR_NOAGGREGATION, "DIERR_NOAGGREGATION") +DXERRMSG(DIERR_OTHERAPPHASPRIO, "DIERR_OTHERAPPHASPRIO") +DXERRMSG(DIERR_INPUTLOST, "Access to the device has been lost. It must be re-acquired.") +DXERRMSG(DIERR_ACQUIRED, "The operation cannot be performed while the device is acquired.") +DXERRMSG(DIERR_NOTACQUIRED, "The operation cannot be performed unless the device is acquired.") +//DXERRMSG(DIERR_READONLY, "DIERR_READONLY") +//DXERRMSG(DIERR_HANDLEEXISTS, "DIERR_HANDLEEXISTS") +DXERRMSG(DIERR_INSUFFICIENTPRIVS, "Unable to IDirectInputJoyConfig_Acquire because the user does not have sufficient privileges to change the joystick configuration. & An invalid media type was specified") +DXERRMSG(DIERR_DEVICEFULL, "The device is full. & An invalid media subtype was specified.") +DXERRMSG(DIERR_MOREDATA, "Not all the requested information fit into the buffer. & This object can only be created as an aggregated object.") +DXERRMSG(DIERR_NOTDOWNLOADED, "The effect is not downloaded. & The enumerator has become invalid.") +DXERRMSG(DIERR_HASEFFECTS, "The device cannot be reinitialized because there are still effects attached to it. & At least one of the pins involved in the operation is already connected.") +DXERRMSG(DIERR_NOTEXCLUSIVEACQUIRED, "The operation cannot be performed unless the device is acquired in DISCL_EXCLUSIVE mode. & This operation cannot be performed because the filter is active.") +DXERRMSG(DIERR_INCOMPLETEEFFECT, "The effect could not be downloaded because essential information is missing. For example, no axes have been associated with the effect, or no type-specific information has been created. & One of the specified pins supports no media types.") +DXERRMSG(DIERR_NOTBUFFERED, "Attempted to read buffered device data from a device that is not buffered. & There is no common media type between these pins.") +DXERRMSG(DIERR_EFFECTPLAYING, "An attempt was made to modify parameters of an effect while it is playing. Not all hardware devices support altering the parameters of an effect while it is playing. & Two pins of the same direction cannot be connected together.") +DXERRMSG(DIERR_UNPLUGGED, "The operation could not be completed because the device is not plugged in. & The operation cannot be performed because the pins are not connected.") +DXERRMSG(DIERR_REPORTFULL, "SendDeviceData failed because more information was requested to be sent than can be sent to the device. Some devices have restrictions on how much data can be sent to them. (For example, there might be a limit on the number of buttons that can be pressed at once.) & No sample buffer allocator is available.") +DXERRMSG(DIERR_MAPFILEFAIL, "A mapper file function failed because reading or writing the user or IHV settings file failed. & A run-time error occurred.") +#endif + +#if defined(__DINPUTD_INCLUDED__) +// ------------------------------------------------------------- +// dinputd.h error codes +// ------------------------------------------------------------- +DXERRMSG(DIERR_NOMOREITEMS, "No more items.") +DXERRMSG(DIERR_DRIVERFIRST, "Device driver-specific codes. Unless the specific driver has been precisely identified, no meaning should be attributed to these values other than that the driver originated the error.") +DXERRMSG(DIERR_DRIVERFIRST + 1, "DIERR_DRIVERFIRST+1") +DXERRMSG(DIERR_DRIVERFIRST + 2, "DIERR_DRIVERFIRST+2") +DXERRMSG(DIERR_DRIVERFIRST + 3, "DIERR_DRIVERFIRST+3") +DXERRMSG(DIERR_DRIVERFIRST + 4, "DIERR_DRIVERFIRST+4") +DXERRMSG(DIERR_DRIVERFIRST + 5, "DIERR_DRIVERFIRST+5") +DXERRMSG(DIERR_DRIVERLAST, "Device installer errors.") +DXERRMSG(DIERR_INVALIDCLASSINSTALLER, "Registry entry or DLL for class installer invalid or class installer not found.") +DXERRMSG(DIERR_CANCELLED, "The user cancelled the install operation. & The stream already has allocated samples and the surface doesn't match the sample format.") +DXERRMSG(DIERR_BADINF, "The INF file for the selected device could not be found or is invalid or is damaged. & The specified purpose ID can't be used for the call.") +#endif + +#if defined(_D3D9_H_) +// ------------------------------------------------------------- +// d3d9.h error codes +// ------------------------------------------------------------- +//DXERRMSG(D3D_OK, "Ok") +DXERRMSG(D3DERR_WRONGTEXTUREFORMAT, "Wrong texture format") +DXERRMSG(D3DERR_UNSUPPORTEDCOLOROPERATION, "Unsupported color operation") +DXERRMSG(D3DERR_UNSUPPORTEDCOLORARG, "Unsupported color arg") +DXERRMSG(D3DERR_UNSUPPORTEDALPHAOPERATION, "Unsupported alpha operation") +DXERRMSG(D3DERR_UNSUPPORTEDALPHAARG, "Unsupported alpha arg") +DXERRMSG(D3DERR_TOOMANYOPERATIONS, "Too many operations") +DXERRMSG(D3DERR_CONFLICTINGTEXTUREFILTER, "Conflicting texture filter") +DXERRMSG(D3DERR_UNSUPPORTEDFACTORVALUE, "Unsupported factor value") +DXERRMSG(D3DERR_CONFLICTINGRENDERSTATE, "Conflicting render state") +DXERRMSG(D3DERR_UNSUPPORTEDTEXTUREFILTER, "Unsupported texture filter") +DXERRMSG(D3DERR_CONFLICTINGTEXTUREPALETTE, "Conflicting texture palette") +DXERRMSG(D3DERR_DRIVERINTERNALERROR, "Driver internal error") +DXERRMSG(D3DERR_NOTFOUND, "Not found") +DXERRMSG(D3DERR_MOREDATA, "More data") +DXERRMSG(D3DERR_DEVICELOST, "Device lost") +DXERRMSG(D3DERR_DEVICENOTRESET, "Device not reset") +DXERRMSG(D3DERR_NOTAVAILABLE, "Not available") +DXERRMSG(D3DERR_OUTOFVIDEOMEMORY, "Out of video memory") +DXERRMSG(D3DERR_INVALIDDEVICE, "Invalid device") +DXERRMSG(D3DERR_INVALIDCALL, "Invalid call") +DXERRMSG(D3DERR_DRIVERINVALIDCALL, "Driver invalid call") +DXERRMSG(D3DERR_WASSTILLDRAWING, "Was Still Drawing") +DXERRMSG(D3DOK_NOAUTOGEN, "The call succeeded but there won't be any mipmaps generated") + +// Extended for Windows Vista +DXERRMSG(D3DERR_DEVICEREMOVED, "Hardware device was removed") +DXERRMSG(S_NOT_RESIDENT, "Resource not resident in memory") +DXERRMSG(S_RESIDENT_IN_SHARED_MEMORY, "Resource resident in shared memory") +DXERRMSG(S_PRESENT_MODE_CHANGED, "Desktop display mode has changed") +DXERRMSG(S_PRESENT_OCCLUDED, "Client window is occluded (minimized or other fullscreen)") +DXERRMSG(D3DERR_DEVICEHUNG, "Hardware adapter reset by OS") + +// Extended for Windows 7 +DXERRMSG(D3DERR_UNSUPPORTEDOVERLAY, "Overlay is not supported") +DXERRMSG(D3DERR_UNSUPPORTEDOVERLAYFORMAT, "Overlay format is not supported") +DXERRMSG(D3DERR_CANNOTPROTECTCONTENT, "Contect protection not available") +DXERRMSG(D3DERR_UNSUPPORTEDCRYPTO, "Unsupported cryptographic system") +DXERRMSG(D3DERR_PRESENT_STATISTICS_DISJOINT, "Presentation statistics are disjoint") +#endif + + +#if defined(__DSOUND_INCLUDED__) +// ------------------------------------------------------------- +// dsound.h error codes +// ------------------------------------------------------------- +//DXERRMSG(DS_OK, "") +DXERRMSG(DS_NO_VIRTUALIZATION, "The call succeeded, but we had to substitute the 3D algorithm") +DXERRMSG(DSERR_ALLOCATED, "The call failed because resources (such as a priority level) were already being used by another caller") +DXERRMSG(DSERR_CONTROLUNAVAIL, "The control (vol, pan, etc.) requested by the caller is not available") +//DXERRMSG(DSERR_INVALIDPARAM, "DSERR_INVALIDPARAM") +DXERRMSG(DSERR_INVALIDCALL, "This call is not valid for the current state of this object") +//DXERRMSG(DSERR_GENERIC, "DSERR_GENERIC") +DXERRMSG(DSERR_PRIOLEVELNEEDED, "The caller does not have the priority level required for the function to succeed") +//DXERRMSG(DSERR_OUTOFMEMORY, "Not enough free memory is available to complete the operation") +DXERRMSG(DSERR_BADFORMAT, "The specified WAVE format is not supported") +//DXERRMSG(DSERR_UNSUPPORTED, "DSERR_UNSUPPORTED") +DXERRMSG(DSERR_NODRIVER, "No sound driver is available for use") +DXERRMSG(DSERR_ALREADYINITIALIZED, "This object is already initialized") +//DXERRMSG(DSERR_NOAGGREGATION, "DSERR_NOAGGREGATION") +DXERRMSG(DSERR_BUFFERLOST, "The buffer memory has been lost, and must be restored") +DXERRMSG(DSERR_OTHERAPPHASPRIO, "Another app has a higher priority level, preventing this call from succeeding") +DXERRMSG(DSERR_UNINITIALIZED, "This object has not been initialized") +//DXERRMSG(DSERR_NOINTERFACE, "DSERR_NOINTERFACE") +//DXERRMSG(DSERR_ACCESSDENIED, "DSERR_ACCESSDENIED") +DXERRMSG(DSERR_BUFFERTOOSMALL, "Tried to create a DSBCAPS_CTRLFX buffer shorter than DSBSIZE_FX_MIN milliseconds") +DXERRMSG(DSERR_DS8_REQUIRED, "Attempt to use DirectSound 8 functionality on an older DirectSound object") +DXERRMSG(DSERR_SENDLOOP, "A circular loop of send effects was detected") +DXERRMSG(DSERR_BADSENDBUFFERGUID, "The GUID specified in an audiopath file does not match a valid MIXIN buffer") +DXERRMSG(DSERR_OBJECTNOTFOUND, "The object requested was not found (numerically equal to DMUS_E_NOT_FOUND)") + +DXERRMSG(DSERR_FXUNAVAILABLE, "Requested effects are not available") +#endif + +#if defined(__d3d10_h__) +// ------------------------------------------------------------- +// d3d10.h error codes +// ------------------------------------------------------------- +DXERRMSG(D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS, "There are too many unique state objects.") +DXERRMSG(D3D10_ERROR_FILE_NOT_FOUND, "File not found") +#endif + +#if defined(__dxgitype_h__) +// ------------------------------------------------------------- +// dxgi.h error codes +// ------------------------------------------------------------- +DXERRMSG(DXGI_STATUS_OCCLUDED, "The target window or output has been occluded. The application should suspend rendering operations if possible.") +DXERRMSG(DXGI_STATUS_CLIPPED, "Target window is clipped.") +DXERRMSG(DXGI_STATUS_NO_REDIRECTION, "") +DXERRMSG(DXGI_STATUS_NO_DESKTOP_ACCESS, "No access to desktop.") +DXERRMSG(DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE, "") +DXERRMSG(DXGI_STATUS_MODE_CHANGED, "Display mode has changed") +DXERRMSG(DXGI_STATUS_MODE_CHANGE_IN_PROGRESS, "Display mode is changing") +DXERRMSG(DXGI_ERROR_INVALID_CALL, "The application has made an erroneous API call that it had enough information to avoid. This error is intended to denote that the application should be altered to avoid the error. Use of the debug version of the DXGI.DLL will provide run-time debug output with further information.") +DXERRMSG(DXGI_ERROR_NOT_FOUND, "The item requested was not found. For GetPrivateData calls, this means that the specified GUID had not been previously associated with the object.") +DXERRMSG(DXGI_ERROR_MORE_DATA, "The specified size of the destination buffer is too small to hold the requested data.") +DXERRMSG(DXGI_ERROR_UNSUPPORTED, "Unsupported.") +DXERRMSG(DXGI_ERROR_DEVICE_REMOVED, "Hardware device removed.") +DXERRMSG(DXGI_ERROR_DEVICE_HUNG, "Device hung due to badly formed commands.") +DXERRMSG(DXGI_ERROR_DEVICE_RESET, "Device reset due to a badly formed commant.") +DXERRMSG(DXGI_ERROR_WAS_STILL_DRAWING, "Was still drawing.") +DXERRMSG(DXGI_ERROR_FRAME_STATISTICS_DISJOINT, "The requested functionality is not supported by the device or the driver.") +DXERRMSG(DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE, "The requested functionality is not supported by the device or the driver.") +DXERRMSG(DXGI_ERROR_DRIVER_INTERNAL_ERROR, "An internal driver error occurred.") +DXERRMSG(DXGI_ERROR_NONEXCLUSIVE, "The application attempted to perform an operation on an DXGI output that is only legal after the output has been claimed for exclusive owenership.") +DXERRMSG(DXGI_ERROR_NOT_CURRENTLY_AVAILABLE, "The requested functionality is not supported by the device or the driver.") +DXERRMSG(DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED, "Remote desktop client disconnected.") +DXERRMSG(DXGI_ERROR_REMOTE_OUTOFMEMORY, "Remote desktop client is out of memory.") +#endif + +#if defined(__d3d11_h__) +// ------------------------------------------------------------- +// d3d11.h error codes +// ------------------------------------------------------------- +DXERRMSG(D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS, "There are too many unique state objects.") +DXERRMSG(D3D11_ERROR_FILE_NOT_FOUND, "File not found") +DXERRMSG(D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS, "Therea are too many unique view objects.") +DXERRMSG(D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Deferred context requires Map-Discard usage pattern") +#endif \ No newline at end of file diff --git a/src/archutils/Win32/DirectXHelpers.cpp b/src/archutils/Win32/DirectXHelpers.cpp index 247417c56d..04423e8476 100644 --- a/src/archutils/Win32/DirectXHelpers.cpp +++ b/src/archutils/Win32/DirectXHelpers.cpp @@ -2,16 +2,6 @@ #include "DirectXHelpers.h" #include "RageUtil.h" -#include -#if defined(USE_DXERR9) -#include -#else -#include -#endif -#if defined(_MSC_VER) -# pragma comment(lib, "dxerr.lib") -#endif - RString hr_ssprintf( int hr, const char *fmt, ... ) { va_list va; @@ -19,14 +9,29 @@ RString hr_ssprintf( int hr, const char *fmt, ... ) RString s = vssprintf( fmt, va ); va_end(va); -#if defined(USE_DXERR9) - const char *szError = DXGetErrorString9( hr ); -#else - const char *szError = DXGetErrorString( hr ); -#endif + const char *szError = GetErrorString( hr ); return s + ssprintf( " (%s)", szError ); } +// needed for defines +#define DIRECTINPUT_VERSION 0x0800 +#define DIRECTSOUND_VERSION 0x0700 +#include +#include +#include // dsound.h needs this +#include + +#define DXERRMSG(hrcode, dummy) case hrcode: return #hrcode; + +RString GetErrorString(HRESULT hr) +{ + switch (hr) + { +#include "DirectXErrorList.h" + default: return ssprintf("unknown HRESULT 0x%8.8X", hr); + } +} + /* * Copyright (c) 2001-2005 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/src/archutils/Win32/DirectXHelpers.h b/src/archutils/Win32/DirectXHelpers.h index b8438f1fce..42c00f5d19 100644 --- a/src/archutils/Win32/DirectXHelpers.h +++ b/src/archutils/Win32/DirectXHelpers.h @@ -22,6 +22,8 @@ osvi.wServicePackMajor = 0; return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != false; } +RString GetErrorString(HRESULT hr); + #endif /* From 2bce815a1af0687a4ecd6994c32bb930d66be63f Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 09:35:44 -0400 Subject: [PATCH 07/10] Fix build errors with RageDisplay_D3D using Windows SDK Also: Implement d3d9 screenshots without d3dx9 This only implements the two most likely surface formats. Does anybody actually use 16-bit rendering anymore? (If yes, I'll do the slower path through StretchRect to convert) (backport from master, where it was two commits) --- src/RageDisplay_D3D.cpp | 55 +++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/RageDisplay_D3D.cpp b/src/RageDisplay_D3D.cpp index 0f112eadf5..2f044b9021 100644 --- a/src/RageDisplay_D3D.cpp +++ b/src/RageDisplay_D3D.cpp @@ -13,28 +13,20 @@ #include "DisplaySpec.h" #include "LocalizedString.h" -#include #include -#include #include "archutils/Win32/GraphicsWindow.h" +#include "archutils/Win32/DirectXHelpers.h" // Static libraries // load Windows D3D9 dynamically #if defined(_MSC_VER) #pragma comment(lib, "d3d9.lib") - #pragma comment(lib, "d3dx9.lib") - #pragma comment(lib, "DxErr.lib") #endif #include #include -RString GetErrorString( HRESULT hr ) -{ - return DXGetErrorString(hr); -} - // Globals HMODULE g_D3D9_Module = nullptr; LPDIRECT3D9 g_pd3d = nullptr; @@ -644,22 +636,23 @@ RageSurface* RageDisplay_D3D::CreateScreenshot() { RageSurface * result = nullptr; - // Get the back buffer. + // get the render target IDirect3DSurface9* pSurface; - if( SUCCEEDED( g_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface ) ) ) + if (SUCCEEDED(g_pd3dDevice->GetRenderTarget(0, &pSurface))) { - // Get the back buffer description. + // get the render target surface description D3DSURFACE_DESC desc; - pSurface->GetDesc( &desc ); + pSurface->GetDesc(&desc); - // Copy the back buffer into a surface of a type we support. + // create an offscreen plain surface of the same format in the SYSTEMMEM pool IDirect3DSurface9* pCopy; - if( SUCCEEDED( g_pd3dDevice->CreateOffscreenPlainSurface( desc.Width, desc.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pCopy, nullptr ) ) ) + if (SUCCEEDED(g_pd3dDevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pCopy, nullptr))) { - if( SUCCEEDED( D3DXLoadSurfaceFromSurface( pCopy, nullptr, nullptr, pSurface, nullptr, nullptr, D3DX_FILTER_NONE, 0) ) ) + // copy the data from the render target into the offscreen plain surface + if (SUCCEEDED(g_pd3dDevice->GetRenderTargetData(pSurface, pCopy))) { // Update desc from the copy. - pCopy->GetDesc( &desc ); + pCopy->GetDesc(&desc); D3DLOCKED_RECT lr; @@ -670,19 +663,33 @@ RageSurface* RageDisplay_D3D::CreateScreenshot() rect.right = desc.Width; rect.bottom = desc.Height; - pCopy->LockRect( &lr, &rect, D3DLOCK_READONLY ); + pCopy->LockRect(&lr, &rect, D3DLOCK_READONLY); } - RageSurface *surface = CreateSurfaceFromPixfmt( RagePixelFormat_RGBA8, lr.pBits, desc.Width, desc.Height, lr.Pitch); - ASSERT( surface != nullptr ); + // since we no longer have an easy function to force a conversion to A8R8G8B8, we need to figure out our pixel format. + // (yes, we could create a couple of surfaces in the default pool, copy the bits into the one matching our source, + // then use IDirect3DDevice::StretchRect to convert it without stretching into our desired format. This would mean + // a copy to device memory and a copy back again, though.) + // possible formats are found in FindBackBufferType + RagePixelFormat pf; + switch (desc.Format) + { + default: pf = RagePixelFormat_Invalid; FAIL_M("Unknown pixel format"); break; + case D3DFMT_X8R8G8B8: pf = RagePixelFormat_RGBA8; break; + case D3DFMT_A8R8G8B8: pf = RagePixelFormat_RGBA8; break; + // 16-bit formats are not here. Does anybody actually use them? + } + + RageSurface *surface = CreateSurfaceFromPixfmt(pf, lr.pBits, desc.Width, desc.Height, lr.Pitch); + ASSERT(nullptr != surface); // We need to make a copy, since lr.pBits will go away when we call UnlockRect(). - result = - CreateSurface( surface->w, surface->h, + result = + CreateSurface(surface->w, surface->h, surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, - surface->format->Bmask, surface->format->Amask ); - RageSurfaceUtils::CopySurface( surface, result ); + surface->format->Bmask, surface->format->Amask); + RageSurfaceUtils::CopySurface(surface, result); delete surface; pCopy->UnlockRect(); From 626e58700eba99a4038d2c408b079c2d254b713b Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 09:46:51 -0400 Subject: [PATCH 08/10] Fix build errors with IH_DirectInput using the Win SDK * dxguid.lib no longer exists. * older SDKs (like the v140_xp toolset) don't provide XUSER_MAX_COUNT. --- src/arch/InputHandler/InputHandler_DirectInput.cpp | 6 ++++++ src/arch/InputHandler/InputHandler_DirectInputHelper.cpp | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/arch/InputHandler/InputHandler_DirectInput.cpp b/src/arch/InputHandler/InputHandler_DirectInput.cpp index 86872fda52..d04196bf05 100644 --- a/src/arch/InputHandler/InputHandler_DirectInput.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInput.cpp @@ -20,6 +20,12 @@ #include #include +// this may not be defined if we are using an older Windows SDK. (for instance, toolsetversion v140_xp does not define it) +// the number was taken from the documentation +#ifndef XUSER_MAX_COUNT +#define XUSER_MAX_COUNT 4 +#endif + REGISTER_INPUT_HANDLER_CLASS2( DirectInput, DInput ); static vector Devices; diff --git a/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp b/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp index c582dc7066..04e2b857b9 100644 --- a/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp @@ -8,9 +8,6 @@ #if defined(_MSC_VER) #pragma comment(lib, "dinput8.lib") -#if defined(_WINDOWS) -#pragma comment(lib, "dxguid.lib") -#endif #endif LPDIRECTINPUT8 g_dinput = nullptr; From c1e4d56f5e7f615f7a64b6bcf6b65c3482201762 Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 09:53:20 -0400 Subject: [PATCH 09/10] Fix indentation in CMakeData-os.cmake --- src/CMakeData-os.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeData-os.cmake b/src/CMakeData-os.cmake index a8116942c0..63ef1a064b 100644 --- a/src/CMakeData-os.cmake +++ b/src/CMakeData-os.cmake @@ -42,7 +42,7 @@ else() "archutils/Win32/CrashHandlerNetworking.cpp" "archutils/Win32/DebugInfoHunt.cpp" "archutils/Win32/DialogUtil.cpp" - "archutils/Win32/DirectXGuids.cpp" + "archutils/Win32/DirectXGuids.cpp" "archutils/Win32/DirectXHelpers.cpp" "archutils/Win32/ErrorStrings.cpp" "archutils/Win32/GetFileInformation.cpp" From d7f9c8d7b6915f0f1ebb25996e6fbf56fbea37bf Mon Sep 17 00:00:00 2001 From: Tracy Ward Date: Fri, 4 Oct 2019 11:34:24 -0400 Subject: [PATCH 10/10] Remove more DX CMake bits There is also a weird bit in here that seems like it should be whether to use system or included libpng, but it actually does the directx include dir on one side. --- src/CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f68a758ae3..da33e8f4b3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -481,9 +481,6 @@ if(WIN32) "setupapi.lib" "hid.lib") - get_filename_component(DIRECTX_LIBRARY_DIR "${DIRECTX_LIBRARIES}" DIRECTORY) - - sm_add_link_flag("${SM_EXE_NAME}" "/LIBPATH:\"${DIRECTX_LIBRARY_DIR}\"") sm_add_link_flag("${SM_EXE_NAME}" "/LIBPATH:\"${SM_EXTERN_DIR}/ffmpeg/lib\"") sm_add_link_flag("${SM_EXE_NAME}" "/LIBPATH:\"${SM_SRC_DIR}/archutils/Win32/ddk\"") @@ -665,7 +662,8 @@ else() endif() if(WIN32) - list(APPEND SM_INCLUDE_DIRS ${DIRECTX_INCLUDE_DIR}) + # FIXME: This makes no sense... + #list(APPEND SM_INCLUDE_DIRS ${DIRECTX_INCLUDE_DIR}) else() list(APPEND SM_INCLUDE_DIRS "${SM_EXTERN_DIR}/libpng/include") endif()