Wine-devel
Threads by month
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
June 2019
- 73 participants
- 565 discussions
From: Zhiyi Zhang <zzhang(a)codeweavers.com>
Because most of the monitor functions are in sysparams.c.
And format the string constants to be more consistent with
the style in sysparams.c.
Signed-off-by: Zhiyi Zhang <zzhang(a)codeweavers.com>
Signed-off-by: Huw Davies <huw(a)codeweavers.com>
---
dlls/user32/misc.c | 313 ----------------------------------------
dlls/user32/sysparams.c | 297 ++++++++++++++++++++++++++++++++++++++
2 files changed, 297 insertions(+), 313 deletions(-)
diff --git a/dlls/user32/misc.c b/dlls/user32/misc.c
index 5f26cf9af3..bed5812a47 100644
--- a/dlls/user32/misc.c
+++ b/dlls/user32/misc.c
@@ -28,14 +28,7 @@
#include "wine/windef16.h"
#include "winbase.h"
#include "wingdi.h"
-#include "winuser.h"
-#include "winreg.h"
-#include "winnls.h"
-#include "winternl.h"
#include "controls.h"
-#include "initguid.h"
-#include "devguid.h"
-#include "setupapi.h"
#include "user_private.h"
#include "wine/unicode.h"
@@ -43,66 +36,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(win);
-/* Wine specific monitor properties */
-DEFINE_DEVPROPKEY(WINE_DEVPROPKEY_MONITOR_STATEFLAGS, 0x233a9ef3, 0xafc4, 0x4abd, 0xb5, 0x64, 0xc3, 0x2f, 0x21, 0xf1, 0x53, 0x5b, 2);
-
-static const WCHAR default_adapter_name[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
-static const WCHAR default_monitor_name[] =
- {'\\','\\','.','\\',
- 'D','I','S','P','L','A','Y','1','\\',
- 'M','o','n','i','t','o','r','0',0};
-static const WCHAR default_adapter_string[] = {'W','i','n','e',' ','A','d','a','p','t','e','r',0};
-static const WCHAR default_monitor_string[] =
- {'G','e','n','e','r','i','c',' ','N','o','n','-','P','n','P',' ','M','o','n','i','t','o','r',0};
-static const WCHAR default_adapter_id[] =
- {'P','C','I','\\',
- 'V','E','N','_','0','0','0','0','&',
- 'D','E','V','_','0','0','0','0','&',
- 'S','U','B','S','Y','S','_','0','0','0','0','0','0','0','0','&',
- 'R','E','V','_','0','0',0};
-static const WCHAR default_monitor_id[] =
- {'M','O','N','I','T','O','R','\\',
- 'D','e','f','a','u','l','t','_','M','o','n','i','t','o','r','\\',
- '{','4','d','3','6','e','9','6','e','-','e','3','2','5','-','1','1','c','e','-',
- 'b','f','c','1','-','0','8','0','0','2','b','e','1','0','3','1','8','}',
- '\\','0','0','0','0',0};
-static const WCHAR default_monitor_interface_id[] =
- {'\\','\\','\?','\\',
- 'D','I','S','P','L','A','Y','#','D','e','f','a','u','l','t','_','M','o','n','i','t','o','r','#',
- '4','&','1','7','f','0','f','f','5','4','&','0','&','U','I','D','0','#',
- '{','e','6','f','0','7','b','5','f','-','e','e','9','7','-','4','a','9','0','-',
- 'b','0','7','6','-','3','3','f','5','7','b','f','4','e','a','a','7','}',0};
-
-static const WCHAR monitor_fmtW[] =
- {'\\','\\','.','\\',
- 'D','I','S','P','L','A','Y','%','d','\\',
- 'M','o','n','i','t','o','r','%','d',0};
-static const WCHAR adapter_fmtW[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','%','d',0};
-static const WCHAR displayW[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y'};
-static const WCHAR video_keyW[] =
- {'H','A','R','D','W','A','R','E','\\',
- 'D','E','V','I','C','E','M','A','P','\\',
- 'V','I','D','E','O','\\',0};
-static const WCHAR video_value_fmtW[] =
- {'\\','D','e','v','i','c','e','\\',
- 'V','i','d','e','o','%','d',0};
-static const WCHAR monitor_interface_prefixW[] = {'\\','\\','\?','\\',0};
-static const WCHAR guid_devinterface_monitorW[] =
- {'#','{','e','6','f','0','7','b','5','f','-','e','e','9','7','-',
- '4','a','9','0','-','b','0','7','6','-','3','3','f','5','7','b','f','4','e','a','a','7','}',0};
-static const WCHAR backslashW[] = {'\\',0};
-static const WCHAR nt_classW[] =
- {'\\','R','e','g','i','s','t','r','y','\\',
- 'M','a','c','h','i','n','e','\\',
- 'S','y','s','t','e','m','\\',
- 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
- 'C','o','n','t','r','o','l','\\',
- 'C','l','a','s','s','\\',0};
-static const WCHAR driver_descW[] = {'D','r','i','v','e','r','D','e','s','c',0};
-static const WCHAR state_flagsW[] = {'S','t','a','t','e','F','l','a','g','s',0};
-static const WCHAR gpu_idW[] = {'G','P','U','I','D',0};
-static const WCHAR mointor_id_value_fmtW[] = {'M','o','n','i','t','o','r','I','D','%','d',0};
-
#define IMM_INIT_MAGIC 0x19650412
static HWND (WINAPI *imm_get_ui_window)(HKL);
BOOL (WINAPI *imm_register_window)(HWND) = NULL;
@@ -307,252 +240,6 @@ DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd)
return 1;
}
-/***********************************************************************
- * EnumDisplayDevicesA (USER32.@)
- */
-BOOL WINAPI EnumDisplayDevicesA( LPCSTR lpDevice, DWORD i, LPDISPLAY_DEVICEA lpDispDev,
- DWORD dwFlags )
-{
- UNICODE_STRING deviceW;
- DISPLAY_DEVICEW ddW;
- BOOL ret;
-
- if(lpDevice)
- RtlCreateUnicodeStringFromAsciiz(&deviceW, lpDevice);
- else
- deviceW.Buffer = NULL;
-
- ddW.cb = sizeof(ddW);
- ret = EnumDisplayDevicesW(deviceW.Buffer, i, &ddW, dwFlags);
- RtlFreeUnicodeString(&deviceW);
-
- if(!ret) return ret;
-
- WideCharToMultiByte(CP_ACP, 0, ddW.DeviceName, -1, lpDispDev->DeviceName, sizeof(lpDispDev->DeviceName), NULL, NULL);
- WideCharToMultiByte(CP_ACP, 0, ddW.DeviceString, -1, lpDispDev->DeviceString, sizeof(lpDispDev->DeviceString), NULL, NULL);
- lpDispDev->StateFlags = ddW.StateFlags;
-
- if(lpDispDev->cb >= offsetof(DISPLAY_DEVICEA, DeviceID) + sizeof(lpDispDev->DeviceID))
- WideCharToMultiByte(CP_ACP, 0, ddW.DeviceID, -1, lpDispDev->DeviceID, sizeof(lpDispDev->DeviceID), NULL, NULL);
- if(lpDispDev->cb >= offsetof(DISPLAY_DEVICEA, DeviceKey) + sizeof(lpDispDev->DeviceKey))
- WideCharToMultiByte(CP_ACP, 0, ddW.DeviceKey, -1, lpDispDev->DeviceKey, sizeof(lpDispDev->DeviceKey), NULL, NULL);
-
- return TRUE;
-}
-
-/***********************************************************************
- * EnumDisplayDevicesW (USER32.@)
- */
-BOOL WINAPI EnumDisplayDevicesW( LPCWSTR lpDevice, DWORD i, LPDISPLAY_DEVICEW lpDisplayDevice,
- DWORD dwFlags )
-{
- SP_DEVINFO_DATA device_data = {sizeof(device_data)};
- HDEVINFO set = INVALID_HANDLE_VALUE;
- WCHAR key_nameW[MAX_PATH];
- WCHAR instanceW[MAX_PATH];
- WCHAR bufferW[1024];
- LONG adapter_index;
- WCHAR *next_charW;
- DWORD size;
- DWORD type;
- HKEY hkey;
- BOOL ret = FALSE;
-
- TRACE("%s %d %p %#x\n", debugstr_w(lpDevice), i, lpDisplayDevice, dwFlags);
-
- /* Find adapter */
- if (!lpDevice)
- {
- sprintfW(key_nameW, video_value_fmtW, i);
- size = sizeof(bufferW);
- if (RegGetValueW(HKEY_LOCAL_MACHINE, video_keyW, key_nameW, RRF_RT_REG_SZ, NULL, bufferW, &size))
- return FALSE;
-
- /* DeviceKey */
- if(lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceKey) + sizeof(lpDisplayDevice->DeviceKey))
- lstrcpyW(lpDisplayDevice->DeviceKey, bufferW);
-
- /* DeviceName */
- sprintfW(lpDisplayDevice->DeviceName, adapter_fmtW, i + 1);
-
- /* Strip \Registry\Machine\ */
- lstrcpyW(key_nameW, bufferW + 18);
-
- /* DeviceString */
- size = sizeof(lpDisplayDevice->DeviceString);
- if (RegGetValueW(HKEY_LOCAL_MACHINE, key_nameW, driver_descW, RRF_RT_REG_SZ, NULL,
- lpDisplayDevice->DeviceString, &size))
- return FALSE;
-
- /* StateFlags */
- size = sizeof(lpDisplayDevice->StateFlags);
- if (RegGetValueW(HKEY_CURRENT_CONFIG, key_nameW, state_flagsW, RRF_RT_REG_DWORD, NULL,
- &lpDisplayDevice->StateFlags, &size))
- return FALSE;
-
- /* DeviceID */
- if (lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(lpDisplayDevice->DeviceID))
- {
- if (dwFlags & EDD_GET_DEVICE_INTERFACE_NAME)
- lpDisplayDevice->DeviceID[0] = 0;
- else
- {
- size = sizeof(bufferW);
- if (RegGetValueW(HKEY_CURRENT_CONFIG, key_nameW, gpu_idW, RRF_RT_REG_SZ | RRF_ZEROONFAILURE, NULL,
- bufferW, &size))
- return FALSE;
- set = SetupDiCreateDeviceInfoList(&GUID_DEVCLASS_DISPLAY, NULL);
- if (!SetupDiOpenDeviceInfoW(set, bufferW, NULL, 0, &device_data)
- || !SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_HARDWAREID, NULL, (BYTE *)bufferW,
- sizeof(bufferW), NULL))
- goto done;
- lstrcpyW(lpDisplayDevice->DeviceID, bufferW);
- }
- }
- }
- /* Find monitor */
- else
- {
- /* Check adapter name */
- if (strncmpiW(lpDevice, displayW, ARRAY_SIZE(displayW)))
- return FALSE;
-
- adapter_index = strtolW(lpDevice + ARRAY_SIZE(displayW), NULL, 10);
- sprintfW(key_nameW, video_value_fmtW, adapter_index - 1);
-
- size = sizeof(bufferW);
- if (RegGetValueW(HKEY_LOCAL_MACHINE, video_keyW, key_nameW, RRF_RT_REG_SZ, NULL, bufferW, &size))
- return FALSE;
-
- /* DeviceName */
- sprintfW(lpDisplayDevice->DeviceName, monitor_fmtW, adapter_index, i);
-
- /* Get monitor instance */
- /* Strip \Registry\Machine\ first */
- lstrcpyW(key_nameW, bufferW + 18);
- sprintfW(bufferW, mointor_id_value_fmtW, i);
-
- size = sizeof(instanceW);
- if (RegGetValueW(HKEY_CURRENT_CONFIG, key_nameW, bufferW, RRF_RT_REG_SZ, NULL, instanceW, &size))
- return FALSE;
-
- set = SetupDiCreateDeviceInfoList(&GUID_DEVCLASS_MONITOR, NULL);
- if (!SetupDiOpenDeviceInfoW(set, instanceW, NULL, 0, &device_data))
- goto done;
-
- /* StateFlags */
- if (!SetupDiGetDevicePropertyW(set, &device_data, &WINE_DEVPROPKEY_MONITOR_STATEFLAGS, &type,
- (BYTE *)&lpDisplayDevice->StateFlags, sizeof(lpDisplayDevice->StateFlags), NULL, 0))
- goto done;
-
- /* DeviceString */
- if (!SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_DEVICEDESC, NULL,
- (BYTE *)lpDisplayDevice->DeviceString,
- sizeof(lpDisplayDevice->DeviceString), NULL))
- goto done;
-
- /* DeviceKey */
- if (lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceKey) + sizeof(lpDisplayDevice->DeviceKey))
- {
- if (!SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_DRIVER, NULL, (BYTE *)bufferW,
- sizeof(bufferW), NULL))
- goto done;
-
- lstrcpyW(lpDisplayDevice->DeviceKey, nt_classW);
- lstrcatW(lpDisplayDevice->DeviceKey, bufferW);
- }
-
- /* DeviceID */
- if (lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(lpDisplayDevice->DeviceID))
- {
- if (dwFlags & EDD_GET_DEVICE_INTERFACE_NAME)
- {
- lstrcpyW(lpDisplayDevice->DeviceID, monitor_interface_prefixW);
- lstrcatW(lpDisplayDevice->DeviceID, instanceW);
- lstrcatW(lpDisplayDevice->DeviceID, guid_devinterface_monitorW);
- /* Replace '\\' with '#' after prefix */
- for (next_charW = lpDisplayDevice->DeviceID + strlenW(monitor_interface_prefixW); *next_charW;
- next_charW++)
- {
- if (*next_charW == '\\')
- *next_charW = '#';
- }
- }
- else
- {
- if (!SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_HARDWAREID, NULL, (BYTE *)bufferW,
- sizeof(bufferW), NULL))
- goto done;
-
- lstrcpyW(lpDisplayDevice->DeviceID, bufferW);
- lstrcatW(lpDisplayDevice->DeviceID, backslashW);
-
- if (!SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_DRIVER, NULL, (BYTE *)bufferW,
- sizeof(bufferW), NULL))
- goto done;
-
- lstrcatW(lpDisplayDevice->DeviceID, bufferW);
- }
- }
- }
-
- ret = TRUE;
-done:
- SetupDiDestroyDeviceInfoList(set);
- if (ret)
- return ret;
-
- /* Fallback to report at least one adapter and monitor, if user driver didn't initialize display device registry */
- if (i)
- return FALSE;
-
- /* If user driver did initialize the registry, then exit */
- if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, video_keyW, &hkey))
- {
- RegCloseKey(hkey);
- return FALSE;
- }
- WARN("Reporting fallback display devices\n");
-
- /* Adapter */
- if (!lpDevice)
- {
- memcpy(lpDisplayDevice->DeviceName, default_adapter_name, sizeof(default_adapter_name));
- memcpy(lpDisplayDevice->DeviceString, default_adapter_string, sizeof(default_adapter_string));
- lpDisplayDevice->StateFlags =
- DISPLAY_DEVICE_ATTACHED_TO_DESKTOP | DISPLAY_DEVICE_PRIMARY_DEVICE | DISPLAY_DEVICE_VGA_COMPATIBLE;
- if(lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(lpDisplayDevice->DeviceID))
- {
- if (dwFlags & EDD_GET_DEVICE_INTERFACE_NAME)
- lpDisplayDevice->DeviceID[0] = 0;
- else
- memcpy(lpDisplayDevice->DeviceID, default_adapter_id, sizeof(default_adapter_id));
- }
- }
- /* Monitor */
- else
- {
- if (lstrcmpiW(default_adapter_name, lpDevice))
- return FALSE;
-
- memcpy(lpDisplayDevice->DeviceName, default_monitor_name, sizeof(default_monitor_name));
- memcpy(lpDisplayDevice->DeviceString, default_monitor_string, sizeof(default_monitor_string));
- lpDisplayDevice->StateFlags = DISPLAY_DEVICE_ACTIVE | DISPLAY_DEVICE_ATTACHED;
- if (lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(lpDisplayDevice->DeviceID))
- {
- if (dwFlags & EDD_GET_DEVICE_INTERFACE_NAME)
- memcpy(lpDisplayDevice->DeviceID, default_monitor_interface_id, sizeof(default_monitor_interface_id));
- else
- memcpy(lpDisplayDevice->DeviceID, default_monitor_id, sizeof(default_monitor_id));
- }
- }
-
- if(lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceKey) + sizeof(lpDisplayDevice->DeviceKey))
- lpDisplayDevice->DeviceKey[0] = 0;
-
- return TRUE;
-}
-
/***********************************************************************
* QueryDisplayConfig (USER32.@)
*/
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 5bf82c66e0..63fea14c2a 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -34,10 +34,14 @@
#include "winbase.h"
#include "winnls.h"
#include "wingdi.h"
+#include "winuser.h"
#include "winreg.h"
#include "wine/wingdi16.h"
#include "winerror.h"
+#include "initguid.h"
+#include "devguid.h"
+#include "setupapi.h"
#include "controls.h"
#include "win.h"
#include "user_private.h"
@@ -245,6 +249,56 @@ static const WCHAR CSu[] = {'%','u',0};
static const WCHAR CSd[] = {'%','d',0};
static const WCHAR CSrgb[] = {'%','u',' ','%','u',' ','%','u',0};
+/* Wine specific monitor properties */
+DEFINE_DEVPROPKEY(WINE_DEVPROPKEY_MONITOR_STATEFLAGS, 0x233a9ef3, 0xafc4, 0x4abd, 0xb5, 0x64, 0xc3, 0x2f, 0x21, 0xf1, 0x53, 0x5b, 2);
+
+/* Strings for monitor functions */
+static const WCHAR DEFAULT_ADAPTER_NAME[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
+static const WCHAR DEFAULT_MONITOR_NAME[] = {'\\','\\','.','\\',
+ 'D','I','S','P','L','A','Y','1','\\',
+ 'M','o','n','i','t','o','r','0',0};
+static const WCHAR DEFAULT_ADAPTER_STRING[] = {'W','i','n','e',' ','A','d','a','p','t','e','r',0};
+static const WCHAR DEFAULT_MONITOR_STRING[] = {'G','e','n','e','r','i','c',' ','N','o','n','-','P','n','P',' ','M','o','n','i','t','o','r',0};
+static const WCHAR DEFAULT_ADAPTER_ID[] = {'P','C','I','\\',
+ 'V','E','N','_','0','0','0','0','&',
+ 'D','E','V','_','0','0','0','0','&',
+ 'S','U','B','S','Y','S','_','0','0','0','0','0','0','0','0','&',
+ 'R','E','V','_','0','0',0};
+static const WCHAR DEFAULT_MONITOR_ID[] = {'M','O','N','I','T','O','R','\\',
+ 'D','e','f','a','u','l','t','_','M','o','n','i','t','o','r','\\',
+ '{','4','d','3','6','e','9','6','e','-','e','3','2','5','-','1','1','c','e','-',
+ 'b','f','c','1','-','0','8','0','0','2','b','e','1','0','3','1','8','}',
+ '\\','0','0','0','0',0};
+static const WCHAR DEFAULT_MONITOR_INTERFACE_ID[] = {'\\','\\','\?','\\',
+ 'D','I','S','P','L','A','Y','#','D','e','f','a','u','l','t','_','M','o','n','i','t','o','r','#',
+ '4','&','1','7','f','0','f','f','5','4','&','0','&','U','I','D','0','#',
+ '{','e','6','f','0','7','b','5','f','-','e','e','9','7','-','4','a','9','0','-',
+ 'b','0','7','6','-','3','3','f','5','7','b','f','4','e','a','a','7','}',0};
+static const WCHAR BACKSLASH[] = {'\\',0};
+static const WCHAR DRIVER_DESC[] = {'D','r','i','v','e','r','D','e','s','c',0};
+static const WCHAR STATE_FLAGS[] = {'S','t','a','t','e','F','l','a','g','s',0};
+static const WCHAR GPU_ID[] = {'G','P','U','I','D',0};
+static const WCHAR DISPLAY[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y'};
+static const WCHAR MONITOR_ID_VALUE_FMT[] = {'M','o','n','i','t','o','r','I','D','%','d',0};
+static const WCHAR VIDEO_KEY[] = {'H','A','R','D','W','A','R','E','\\',
+ 'D','E','V','I','C','E','M','A','P','\\',
+ 'V','I','D','E','O','\\',0};
+static const WCHAR NT_CLASS[] = {'\\','R','e','g','i','s','t','r','y','\\',
+ 'M','a','c','h','i','n','e','\\',
+ 'S','y','s','t','e','m','\\',
+ 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+ 'C','o','n','t','r','o','l','\\',
+ 'C','l','a','s','s','\\',0};
+static const WCHAR ADAPTER_FMT[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','%','d',0};
+static const WCHAR MONITOR_FMT[] = {'\\','\\','.','\\',
+ 'D','I','S','P','L','A','Y','%','d','\\',
+ 'M','o','n','i','t','o','r','%','d',0};
+static const WCHAR VIDEO_VALUE_FMT[] = {'\\','D','e','v','i','c','e','\\',
+ 'V','i','d','e','o','%','d',0};
+static const WCHAR MONITOR_INTERFACE_PREFIX[] = {'\\','\\','\?','\\',0};
+static const WCHAR GUID_DEVINTERFACE_MONITOR[] = {'#','{','e','6','f','0','7','b','5','f','-','e','e','9','7','-',
+ '4','a','9','0','-','b','0','7','6','-','3','3','f','5','7','b','f','4','e','a','a','7','}',0};
+
static HDC display_dc;
static CRITICAL_SECTION display_dc_section;
static CRITICAL_SECTION_DEBUG critsect_debug =
@@ -3769,6 +3823,249 @@ BOOL WINAPI EnumDisplayMonitors( HDC hdc, LPRECT rect, MONITORENUMPROC proc, LPA
return USER_Driver->pEnumDisplayMonitors( 0, NULL, enum_mon_callback, (LPARAM)&data );
}
+/***********************************************************************
+ * EnumDisplayDevicesA (USER32.@)
+ */
+BOOL WINAPI EnumDisplayDevicesA( LPCSTR device, DWORD index, DISPLAY_DEVICEA *info, DWORD flags )
+{
+ UNICODE_STRING deviceW;
+ DISPLAY_DEVICEW ddW;
+ BOOL ret;
+
+ if (device)
+ RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
+ else
+ deviceW.Buffer = NULL;
+
+ ddW.cb = sizeof(ddW);
+ ret = EnumDisplayDevicesW(deviceW.Buffer, index, &ddW, flags);
+ RtlFreeUnicodeString(&deviceW);
+
+ if (!ret) return ret;
+
+ WideCharToMultiByte(CP_ACP, 0, ddW.DeviceName, -1, info->DeviceName, sizeof(info->DeviceName), NULL, NULL);
+ WideCharToMultiByte(CP_ACP, 0, ddW.DeviceString, -1, info->DeviceString, sizeof(info->DeviceString), NULL, NULL);
+ info->StateFlags = ddW.StateFlags;
+
+ if (info->cb >= offsetof(DISPLAY_DEVICEA, DeviceID) + sizeof(info->DeviceID))
+ WideCharToMultiByte(CP_ACP, 0, ddW.DeviceID, -1, info->DeviceID, sizeof(info->DeviceID), NULL, NULL);
+ if (info->cb >= offsetof(DISPLAY_DEVICEA, DeviceKey) + sizeof(info->DeviceKey))
+ WideCharToMultiByte(CP_ACP, 0, ddW.DeviceKey, -1, info->DeviceKey, sizeof(info->DeviceKey), NULL, NULL);
+
+ return TRUE;
+}
+
+/***********************************************************************
+ * EnumDisplayDevicesW (USER32.@)
+ */
+BOOL WINAPI EnumDisplayDevicesW( LPCWSTR device, DWORD index, DISPLAY_DEVICEW *info, DWORD flags )
+{
+ SP_DEVINFO_DATA device_data = {sizeof(device_data)};
+ HDEVINFO set = INVALID_HANDLE_VALUE;
+ WCHAR key_nameW[MAX_PATH];
+ WCHAR instanceW[MAX_PATH];
+ WCHAR bufferW[1024];
+ LONG adapter_index;
+ WCHAR *next_charW;
+ DWORD size;
+ DWORD type;
+ HKEY hkey;
+ BOOL ret = FALSE;
+
+ TRACE("%s %d %p %#x\n", debugstr_w(device), index, info, flags);
+
+ /* Find adapter */
+ if (!device)
+ {
+ sprintfW(key_nameW, VIDEO_VALUE_FMT, index);
+ size = sizeof(bufferW);
+ if (RegGetValueW(HKEY_LOCAL_MACHINE, VIDEO_KEY, key_nameW, RRF_RT_REG_SZ, NULL, bufferW, &size))
+ return FALSE;
+
+ /* DeviceKey */
+ if (info->cb >= offsetof(DISPLAY_DEVICEW, DeviceKey) + sizeof(info->DeviceKey))
+ lstrcpyW(info->DeviceKey, bufferW);
+
+ /* DeviceName */
+ sprintfW(info->DeviceName, ADAPTER_FMT, index + 1);
+
+ /* Strip \Registry\Machine\ */
+ lstrcpyW(key_nameW, bufferW + 18);
+
+ /* DeviceString */
+ size = sizeof(info->DeviceString);
+ if (RegGetValueW(HKEY_LOCAL_MACHINE, key_nameW, DRIVER_DESC, RRF_RT_REG_SZ, NULL,
+ info->DeviceString, &size))
+ return FALSE;
+
+ /* StateFlags */
+ size = sizeof(info->StateFlags);
+ if (RegGetValueW(HKEY_CURRENT_CONFIG, key_nameW, STATE_FLAGS, RRF_RT_REG_DWORD, NULL,
+ &info->StateFlags, &size))
+ return FALSE;
+
+ /* DeviceID */
+ if (info->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(info->DeviceID))
+ {
+ if (flags & EDD_GET_DEVICE_INTERFACE_NAME)
+ info->DeviceID[0] = 0;
+ else
+ {
+ size = sizeof(bufferW);
+ if (RegGetValueW(HKEY_CURRENT_CONFIG, key_nameW, GPU_ID, RRF_RT_REG_SZ | RRF_ZEROONFAILURE, NULL,
+ bufferW, &size))
+ return FALSE;
+ set = SetupDiCreateDeviceInfoList(&GUID_DEVCLASS_DISPLAY, NULL);
+ if (!SetupDiOpenDeviceInfoW(set, bufferW, NULL, 0, &device_data)
+ || !SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_HARDWAREID, NULL, (BYTE *)bufferW,
+ sizeof(bufferW), NULL))
+ goto done;
+ lstrcpyW(info->DeviceID, bufferW);
+ }
+ }
+ }
+ /* Find monitor */
+ else
+ {
+ /* Check adapter name */
+ if (strncmpiW(device, DISPLAY, ARRAY_SIZE(DISPLAY)))
+ return FALSE;
+
+ adapter_index = strtolW(device + ARRAY_SIZE(DISPLAY), NULL, 10);
+ sprintfW(key_nameW, VIDEO_VALUE_FMT, adapter_index - 1);
+
+ size = sizeof(bufferW);
+ if (RegGetValueW(HKEY_LOCAL_MACHINE, VIDEO_KEY, key_nameW, RRF_RT_REG_SZ, NULL, bufferW, &size))
+ return FALSE;
+
+ /* DeviceName */
+ sprintfW(info->DeviceName, MONITOR_FMT, adapter_index, index);
+
+ /* Get monitor instance */
+ /* Strip \Registry\Machine\ first */
+ lstrcpyW(key_nameW, bufferW + 18);
+ sprintfW(bufferW, MONITOR_ID_VALUE_FMT, index);
+
+ size = sizeof(instanceW);
+ if (RegGetValueW(HKEY_CURRENT_CONFIG, key_nameW, bufferW, RRF_RT_REG_SZ, NULL, instanceW, &size))
+ return FALSE;
+
+ set = SetupDiCreateDeviceInfoList(&GUID_DEVCLASS_MONITOR, NULL);
+ if (!SetupDiOpenDeviceInfoW(set, instanceW, NULL, 0, &device_data))
+ goto done;
+
+ /* StateFlags */
+ if (!SetupDiGetDevicePropertyW(set, &device_data, &WINE_DEVPROPKEY_MONITOR_STATEFLAGS, &type,
+ (BYTE *)&info->StateFlags, sizeof(info->StateFlags), NULL, 0))
+ goto done;
+
+ /* DeviceString */
+ if (!SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_DEVICEDESC, NULL,
+ (BYTE *)info->DeviceString,
+ sizeof(info->DeviceString), NULL))
+ goto done;
+
+ /* DeviceKey */
+ if (info->cb >= offsetof(DISPLAY_DEVICEW, DeviceKey) + sizeof(info->DeviceKey))
+ {
+ if (!SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_DRIVER, NULL, (BYTE *)bufferW,
+ sizeof(bufferW), NULL))
+ goto done;
+
+ lstrcpyW(info->DeviceKey, NT_CLASS);
+ lstrcatW(info->DeviceKey, bufferW);
+ }
+
+ /* DeviceID */
+ if (info->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(info->DeviceID))
+ {
+ if (flags & EDD_GET_DEVICE_INTERFACE_NAME)
+ {
+ lstrcpyW(info->DeviceID, MONITOR_INTERFACE_PREFIX);
+ lstrcatW(info->DeviceID, instanceW);
+ lstrcatW(info->DeviceID, GUID_DEVINTERFACE_MONITOR);
+ /* Replace '\\' with '#' after prefix */
+ for (next_charW = info->DeviceID + strlenW(MONITOR_INTERFACE_PREFIX); *next_charW;
+ next_charW++)
+ {
+ if (*next_charW == '\\')
+ *next_charW = '#';
+ }
+ }
+ else
+ {
+ if (!SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_HARDWAREID, NULL, (BYTE *)bufferW,
+ sizeof(bufferW), NULL))
+ goto done;
+
+ lstrcpyW(info->DeviceID, bufferW);
+ lstrcatW(info->DeviceID, BACKSLASH);
+
+ if (!SetupDiGetDeviceRegistryPropertyW(set, &device_data, SPDRP_DRIVER, NULL, (BYTE *)bufferW,
+ sizeof(bufferW), NULL))
+ goto done;
+
+ lstrcatW(info->DeviceID, bufferW);
+ }
+ }
+ }
+
+ ret = TRUE;
+done:
+ SetupDiDestroyDeviceInfoList(set);
+ if (ret)
+ return ret;
+
+ /* Fallback to report at least one adapter and monitor, if user driver didn't initialize display device registry */
+ if (index)
+ return FALSE;
+
+ /* If user driver did initialize the registry, then exit */
+ if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, VIDEO_KEY, &hkey))
+ {
+ RegCloseKey(hkey);
+ return FALSE;
+ }
+ WARN("Reporting fallback display devices\n");
+
+ /* Adapter */
+ if (!device)
+ {
+ memcpy(info->DeviceName, DEFAULT_ADAPTER_NAME, sizeof(DEFAULT_ADAPTER_NAME));
+ memcpy(info->DeviceString, DEFAULT_ADAPTER_STRING, sizeof(DEFAULT_ADAPTER_STRING));
+ info->StateFlags =
+ DISPLAY_DEVICE_ATTACHED_TO_DESKTOP | DISPLAY_DEVICE_PRIMARY_DEVICE | DISPLAY_DEVICE_VGA_COMPATIBLE;
+ if (info->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(info->DeviceID))
+ {
+ if (flags & EDD_GET_DEVICE_INTERFACE_NAME)
+ info->DeviceID[0] = 0;
+ else
+ memcpy(info->DeviceID, DEFAULT_ADAPTER_ID, sizeof(DEFAULT_ADAPTER_ID));
+ }
+ }
+ /* Monitor */
+ else
+ {
+ if (lstrcmpiW(DEFAULT_ADAPTER_NAME, device))
+ return FALSE;
+
+ memcpy(info->DeviceName, DEFAULT_MONITOR_NAME, sizeof(DEFAULT_MONITOR_NAME));
+ memcpy(info->DeviceString, DEFAULT_MONITOR_STRING, sizeof(DEFAULT_MONITOR_STRING));
+ info->StateFlags = DISPLAY_DEVICE_ACTIVE | DISPLAY_DEVICE_ATTACHED;
+ if (info->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(info->DeviceID))
+ {
+ if (flags & EDD_GET_DEVICE_INTERFACE_NAME)
+ memcpy(info->DeviceID, DEFAULT_MONITOR_INTERFACE_ID, sizeof(DEFAULT_MONITOR_INTERFACE_ID));
+ else
+ memcpy(info->DeviceID, DEFAULT_MONITOR_ID, sizeof(DEFAULT_MONITOR_ID));
+ }
+ }
+
+ if (info->cb >= offsetof(DISPLAY_DEVICEW, DeviceKey) + sizeof(info->DeviceKey))
+ info->DeviceKey[0] = 0;
+
+ return TRUE;
+}
/**********************************************************************
* GetAutoRotationState [USER32.@]
--
2.17.1
1
0
21 Jun '19
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair(a)hotmail.com>
---
dlls/wininet/http.c | 4 ++--
dlls/wininet/tests/http.c | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index cbc95fb8ae..c90213bf46 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -3911,8 +3911,8 @@ lend:
WININET_Release( &request->hdr );
TRACE("%u <--\n", res);
- if(res != ERROR_SUCCESS)
- SetLastError(res);
+
+ SetLastError(res);
return res == ERROR_SUCCESS;
}
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c
index 5a0cc11754..d5e0a432db 100644
--- a/dlls/wininet/tests/http.c
+++ b/dlls/wininet/tests/http.c
@@ -722,8 +722,11 @@ static void InternetReadFile_test(int flags, const test_data_t *test)
length = sizeof(buffer)-2;
memset(buffer, 0x77, sizeof(buffer));
+ SetLastError(0xdeadbeef);
res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
+ /* Windows 7 and above Reset LastError */
+ ok(GetLastError() == 0 || broken(GetLastError() == 0xdeadbeef), "Last Error not reset 0x%x\n", GetLastError());
/* show that the function writes data past the length returned */
ok(buffer[length-2], "Expected any header character, got 0x00\n");
ok(!buffer[length-1], "Expected 0x00, got %02X\n", buffer[length-1]);
--
2.17.1
2
1
[PATCH] wininet: Support QueryOption INTERNET_OPTION_ERROR_MASK for http
by Alistair Leslie-Hughes 21 Jun '19
by Alistair Leslie-Hughes 21 Jun '19
21 Jun '19
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair(a)hotmail.com>
---
dlls/wininet/http.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index c90213bf46..3cb1f57bae 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -2266,6 +2266,17 @@ static DWORD HTTPREQ_QueryOption(object_header_t *hdr, DWORD option, void *buffe
*(DWORD*)buffer = flags;
return ERROR_SUCCESS;
}
+ case INTERNET_OPTION_ERROR_MASK:
+ {
+ TRACE("INTERNET_OPTION_ERROR_MASK\n");
+
+ if (*size < sizeof(ULONG))
+ return ERROR_INSUFFICIENT_BUFFER;
+
+ *(ULONG*)buffer = hdr->ErrorMask;
+ *size = sizeof(ULONG);
+ return ERROR_SUCCESS;
+ }
}
return INET_QueryOption(hdr, option, buffer, size, unicode);
--
2.17.1
1
0
[PATCH 1/5] quartz/systemclock: Create the advise thread after the events it depends on.
by Zebediah Figura 21 Jun '19
by Zebediah Figura 21 Jun '19
21 Jun '19
Signed-off-by: Zebediah Figura <z.figura12(a)gmail.com>
---
dlls/quartz/systemclock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/quartz/systemclock.c b/dlls/quartz/systemclock.c
index 6bb1f47e6f7..2b75c8da89e 100644
--- a/dlls/quartz/systemclock.c
+++ b/dlls/quartz/systemclock.c
@@ -103,9 +103,9 @@ static void notify_thread(struct system_clock *clock)
{
if (!InterlockedCompareExchange(&clock->thread_created, TRUE, FALSE))
{
- clock->thread = CreateThread(NULL, 0, SystemClockAdviseThread, clock, 0, NULL);
clock->notify_event = CreateEventW(NULL, FALSE, FALSE, NULL);
clock->stop_event = CreateEventW(NULL, TRUE, FALSE, NULL);
+ clock->thread = CreateThread(NULL, 0, SystemClockAdviseThread, clock, 0, NULL);
}
SetEvent(clock->notify_event);
}
--
2.21.0
1
4
[PATCH 1/3] ddraw: Store _TEXTUREMAPBLEND state instead of guessing it from wined3d states.
by Paul Gofman 21 Jun '19
by Paul Gofman 21 Jun '19
21 Jun '19
Signed-off-by: Paul Gofman <gofmanp(a)gmail.com>
---
dlls/ddraw/ddraw_private.h | 1 +
dlls/ddraw/device.c | 73 +++++---------------------------------
dlls/ddraw/tests/ddraw4.c | 5 +++
3 files changed, 14 insertions(+), 65 deletions(-)
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index b08f66564c..9e98d81c8e 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -327,6 +327,7 @@ struct d3d_device
/* Required to keep track which of two available texture blending modes in d3ddevice3 is used */
BOOL legacyTextureBlending;
+ D3DTEXTUREBLEND texture_map_blend;
D3DMATRIX legacy_projection;
D3DMATRIX legacy_clipspace;
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index ac4da191a2..2de9941249 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -2463,62 +2463,7 @@ static HRESULT WINAPI d3d_device3_GetRenderState(IDirect3DDevice3 *iface,
case D3DRENDERSTATE_TEXTUREMAPBLEND:
{
- /* D3DRENDERSTATE_TEXTUREMAPBLEND is mapped to texture state stages in SetRenderState; reverse
- the mapping to get the value. */
- DWORD colorop, colorarg1, colorarg2;
- DWORD alphaop, alphaarg1, alphaarg2;
-
- wined3d_mutex_lock();
-
- device->legacyTextureBlending = TRUE;
-
- colorop = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_OP);
- colorarg1 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_ARG1);
- colorarg2 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_ARG2);
- alphaop = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_OP);
- alphaarg1 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG1);
- alphaarg2 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG2);
-
- if (colorop == WINED3D_TOP_SELECT_ARG1 && colorarg1 == WINED3DTA_TEXTURE
- && alphaop == WINED3D_TOP_SELECT_ARG1 && alphaarg1 == WINED3DTA_TEXTURE)
- *value = D3DTBLEND_DECAL;
- else if (colorop == WINED3D_TOP_SELECT_ARG1 && colorarg1 == WINED3DTA_TEXTURE
- && alphaop == WINED3D_TOP_MODULATE
- && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)
- *value = D3DTBLEND_DECALALPHA;
- else if (colorop == WINED3D_TOP_MODULATE
- && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT
- && alphaop == WINED3D_TOP_MODULATE
- && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)
- *value = D3DTBLEND_MODULATEALPHA;
- else
- {
- struct wined3d_texture *tex = NULL;
- BOOL tex_alpha = FALSE;
- DDPIXELFORMAT ddfmt;
-
- if ((tex = wined3d_device_get_texture(device->wined3d_device, 0)))
- {
- struct wined3d_resource_desc desc;
-
- wined3d_resource_get_desc(wined3d_texture_get_resource(tex), &desc);
- ddfmt.dwSize = sizeof(ddfmt);
- ddrawformat_from_wined3dformat(&ddfmt, desc.format);
- if (ddfmt.u5.dwRGBAlphaBitMask)
- tex_alpha = TRUE;
- }
-
- if (!(colorop == WINED3D_TOP_MODULATE
- && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT
- && alphaop == (tex_alpha ? WINED3D_TOP_SELECT_ARG1 : WINED3D_TOP_SELECT_ARG2)
- && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT))
- ERR("Unexpected texture stage state setup, returning D3DTBLEND_MODULATE - likely erroneous.\n");
-
- *value = D3DTBLEND_MODULATE;
- }
-
- wined3d_mutex_unlock();
-
+ *value = device->texture_map_blend;
return D3D_OK;
}
@@ -2738,8 +2683,7 @@ static HRESULT WINAPI d3d_device3_SetRenderState(IDirect3DDevice3 *iface,
in device - TRUE if the app is using TEXTUREMAPBLEND.
Tests show that setting TEXTUREMAPBLEND on native doesn't seem to change values returned by
- GetTextureStageState and vice versa. Not so on Wine, but it is 'undefined' anyway so, probably, ok,
- unless some broken game will be found that cares. */
+ GetTextureStageState and vice versa. */
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
HRESULT hr;
@@ -2877,7 +2821,7 @@ static HRESULT WINAPI d3d_device3_SetRenderState(IDirect3DDevice3 *iface,
default:
FIXME("Unhandled texture environment %#x.\n", value);
}
-
+ device->texture_map_blend = value;
hr = D3D_OK;
break;
}
@@ -4948,19 +4892,15 @@ static HRESULT WINAPI d3d_device3_SetTexture(IDirect3DDevice3 *iface,
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
struct ddraw_surface *tex = unsafe_impl_from_IDirect3DTexture2(texture);
- DWORD texmapblend;
HRESULT hr;
TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
wined3d_mutex_lock();
- if (device->legacyTextureBlending)
- IDirect3DDevice3_GetRenderState(iface, D3DRENDERSTATE_TEXTUREMAPBLEND, &texmapblend);
-
hr = IDirect3DDevice7_SetTexture(&device->IDirect3DDevice7_iface, stage, &tex->IDirectDrawSurface7_iface);
- if (device->legacyTextureBlending && texmapblend == D3DTBLEND_MODULATE)
+ if (device->legacyTextureBlending && device->texture_map_blend == D3DTBLEND_MODULATE)
{
/* This fixup is required by the way D3DTBLEND_MODULATE maps to texture stage states.
See d3d_device3_SetRenderState() for details. */
@@ -7131,8 +7071,11 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
else if (version == 2)
wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_SPECULARENABLE, TRUE);
if (version < 7)
+ {
wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_NORMALIZENORMALS, TRUE);
-
+ IDirect3DDevice3_SetRenderState(&device->IDirect3DDevice3_iface,
+ D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
+ }
return D3D_OK;
}
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 7822bbaaf1..d12b0f015a 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -9500,6 +9500,7 @@ static void test_texturemapblend(void)
DDSURFACEDESC2 surface_desc;
IDirect3DTexture2 *texture;
IDirect3DDevice3 *device;
+ DWORD texturemapblend;
IDirectDraw4 *ddraw;
IDirect3D3 *d3d;
DDCOLORKEY ckey;
@@ -9557,6 +9558,10 @@ static void test_texturemapblend(void)
hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
+ hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_TEXTUREMAPBLEND, &texturemapblend);
+ ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+ ok(texturemapblend == D3DTBLEND_MODULATE, "Got unexpected texture map blend %#x.\n", texturemapblend);
+
/* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture
* alpha channel.
*
--
2.21.0
3
8
[PATCH vkd3d 2/5] vkd3d: Introduce d3d12_resource_is_cpu_accessible() helper.
by Józef Kucia 20 Jun '19
by Józef Kucia 20 Jun '19
20 Jun '19
From: Józef Kucia <jkucia(a)codeweavers.com>
The condition in d3d12_resource_is_cpu_accessible() is going to be
changed in the following commits.
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
libs/vkd3d/command.c | 2 +-
libs/vkd3d/resource.c | 19 ++++++++++++++++++-
libs/vkd3d/vkd3d_private.h | 13 +------------
3 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c
index 47f7a137f119..64c4bd6aeae3 100644
--- a/libs/vkd3d/command.c
+++ b/libs/vkd3d/command.c
@@ -2090,7 +2090,7 @@ static void d3d12_command_list_transition_resource_to_initial_state(struct d3d12
/* vkQueueSubmit() defines a memory dependency with prior host writes. */
src_stage_mask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
barrier.srcAccessMask = 0;
- barrier.oldLayout = is_cpu_accessible_heap(&resource->heap_properties) ?
+ barrier.oldLayout = d3d12_resource_is_cpu_accessible(resource) ?
VK_IMAGE_LAYOUT_PREINITIALIZED : VK_IMAGE_LAYOUT_UNDEFINED;
if (!vk_barrier_parameters_from_d3d12_resource_state(resource->initial_state,
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 824698a143b5..fdf68363d29d 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -23,6 +23,18 @@
#define VKD3D_HEAP_TYPE_INVALID ((D3D12_HEAP_TYPE)~0u)
+static inline bool is_cpu_accessible_heap(const D3D12_HEAP_PROPERTIES *properties)
+{
+ if (properties->Type == D3D12_HEAP_TYPE_DEFAULT)
+ return false;
+ if (properties->Type == D3D12_HEAP_TYPE_CUSTOM)
+ {
+ return properties->CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE
+ || properties->CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_BACK;
+ }
+ return true;
+}
+
static unsigned int vkd3d_select_memory_type(struct d3d12_device *device, uint32_t memory_type_mask,
const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags)
{
@@ -894,6 +906,11 @@ static ULONG d3d12_resource_decref(struct d3d12_resource *resource)
return refcount;
}
+bool d3d12_resource_is_cpu_accessible(const struct d3d12_resource *resource)
+{
+ return is_cpu_accessible_heap(&resource->heap_properties);
+}
+
/* ID3D12Resource */
static inline struct d3d12_resource *impl_from_ID3D12Resource(ID3D12Resource *iface)
{
@@ -1034,7 +1051,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT
device = resource->device;
- if (!is_cpu_accessible_heap(&resource->heap_properties))
+ if (!d3d12_resource_is_cpu_accessible(resource))
{
WARN("Resource is not CPU accessible.\n");
return E_INVALIDARG;
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index 7cbf0d83b08e..c86370a60d04 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -414,6 +414,7 @@ static inline bool d3d12_resource_is_texture(const struct d3d12_resource *resour
return resource->desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER;
}
+bool d3d12_resource_is_cpu_accessible(const struct d3d12_resource *resource) DECLSPEC_HIDDEN;
HRESULT d3d12_resource_validate_desc(const D3D12_RESOURCE_DESC *desc) DECLSPEC_HIDDEN;
HRESULT d3d12_committed_resource_create(struct d3d12_device *device,
@@ -1165,18 +1166,6 @@ bool is_valid_feature_level(D3D_FEATURE_LEVEL feature_level) DECLSPEC_HIDDEN;
bool is_valid_resource_state(D3D12_RESOURCE_STATES state) DECLSPEC_HIDDEN;
bool is_write_resource_state(D3D12_RESOURCE_STATES state) DECLSPEC_HIDDEN;
-static inline bool is_cpu_accessible_heap(const D3D12_HEAP_PROPERTIES *properties)
-{
- if (properties->Type == D3D12_HEAP_TYPE_DEFAULT)
- return false;
- if (properties->Type == D3D12_HEAP_TYPE_CUSTOM)
- {
- return properties->CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE
- || properties->CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_BACK;
- }
- return true;
-}
-
HRESULT return_interface(void *iface, REFIID iface_iid,
REFIID requested_iid, void **object) DECLSPEC_HIDDEN;
--
2.21.0
2
1
From: Józef Kucia <jkucia(a)codeweavers.com>
VkDeviceMemory must be externally synchronized.
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
libs/vkd3d/resource.c | 105 ++++++++++++++++++-------------------
libs/vkd3d/vkd3d_private.h | 1 -
2 files changed, 52 insertions(+), 54 deletions(-)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 0e13cc53e018..f0864ab92170 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -411,7 +411,8 @@ struct d3d12_heap *unsafe_impl_from_ID3D12Heap(ID3D12Heap *iface)
return impl_from_ID3D12Heap(iface);
}
-static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset, void **data)
+static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset,
+ struct d3d12_resource *resource, void **data)
{
struct d3d12_device *device = heap->device;
HRESULT hr = S_OK;
@@ -425,29 +426,41 @@ static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset, void **d
return hresult_from_errno(rc);
}
- if (!heap->map_ptr)
+ assert(!resource->map_count || heap->map_ptr);
+
+ if (!resource->map_count)
{
- const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
+ if (!heap->map_ptr)
+ {
+ const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
- TRACE("Mapping heap %p.\n", heap);
+ TRACE("Mapping heap %p.\n", heap);
- if ((vr = VK_CALL(vkMapMemory(device->vk_device, heap->vk_memory,
- 0, VK_WHOLE_SIZE, 0, &heap->map_ptr))) < 0)
- {
- WARN("Failed to map device memory, vr %d.\n", vr);
- heap->map_ptr = NULL;
+ assert(!heap->map_count);
+
+ if ((vr = VK_CALL(vkMapMemory(device->vk_device, heap->vk_memory,
+ 0, VK_WHOLE_SIZE, 0, &heap->map_ptr))) < 0)
+ {
+ WARN("Failed to map device memory, vr %d.\n", vr);
+ heap->map_ptr = NULL;
+ }
+
+ hr = hresult_from_vk_result(vr);
}
- hr = hresult_from_vk_result(vr);
+ if (heap->map_ptr)
+ ++heap->map_count;
}
- if (heap->map_ptr)
+ if (hr == S_OK)
{
+ assert(heap->map_ptr);
*data = (BYTE *)heap->map_ptr + offset;
- ++heap->map_count;
+ ++resource->map_count;
}
else
{
+ assert(!heap->map_ptr);
*data = NULL;
}
@@ -456,7 +469,7 @@ static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset, void **d
return hr;
}
-static void d3d12_heap_unmap(struct d3d12_heap *heap)
+static void d3d12_heap_unmap(struct d3d12_heap *heap, struct d3d12_resource *resource)
{
struct d3d12_device *device = heap->device;
int rc;
@@ -467,24 +480,34 @@ static void d3d12_heap_unmap(struct d3d12_heap *heap)
return;
}
- if (heap->map_count)
+ if (!resource->map_count)
{
- --heap->map_count;
- if (!heap->map_count)
- {
- const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
+ WARN("Resource %p is not mapped.\n", resource);
+ goto done;
+ }
- TRACE("Unmapping heap %p.\n", heap);
+ --resource->map_count;
+ if (resource->map_count)
+ goto done;
- VK_CALL(vkUnmapMemory(device->vk_device, heap->vk_memory));
- heap->map_ptr = NULL;
- }
+ if (!heap->map_count)
+ {
+ ERR("Heap %p is not mapped.\n", heap);
+ goto done;
}
- else
+
+ --heap->map_count;
+ if (!heap->map_count)
{
- WARN("Heap %p is not mapped.\n", heap);
+ const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
+
+ TRACE("Unmapping heap %p, ptr %p.\n", heap, heap->map_ptr);
+
+ VK_CALL(vkUnmapMemory(device->vk_device, heap->vk_memory));
+ heap->map_ptr = NULL;
}
+done:
pthread_mutex_unlock(&heap->mutex);
}
@@ -1087,7 +1110,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT
{
struct d3d12_resource *resource = impl_from_ID3D12Resource(iface);
unsigned int sub_resource_count;
- HRESULT hr = S_OK;
+ HRESULT hr;
TRACE("iface %p, sub_resource %u, read_range %p, data %p.\n",
iface, sub_resource, read_range, data);
@@ -1120,20 +1143,10 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT
WARN("Ignoring read range %p.\n", read_range);
- if (!resource->map_count)
- {
- if FAILED(hr = d3d12_heap_map(resource->heap, resource->heap_offset, &resource->map_ptr))
- {
- WARN("Failed to map resource, hr %#x.\n", hr);
- resource->map_ptr = NULL;
- }
- }
+ if (FAILED(hr = d3d12_heap_map(resource->heap, resource->heap_offset, resource, data)))
+ WARN("Failed to map resource %p, hr %#x.\n", resource, hr);
- if (resource->map_ptr)
- {
- *data = resource->map_ptr;
- ++resource->map_count;
- }
+ TRACE("Returning pointer %p.\n", *data);
return hr;
}
@@ -1154,22 +1167,9 @@ static void STDMETHODCALLTYPE d3d12_resource_Unmap(ID3D12Resource *iface, UINT s
return;
}
- if (!resource->map_count)
- {
- WARN("Resource %p is not mapped.\n", resource);
- return;
- }
-
WARN("Ignoring written range %p.\n", written_range);
- --resource->map_count;
- if (!resource->map_count)
- {
- resource->map_ptr = NULL;
-
- assert(resource->heap);
- d3d12_heap_unmap(resource->heap);
- }
+ d3d12_heap_unmap(resource->heap, resource);
}
static D3D12_RESOURCE_DESC * STDMETHODCALLTYPE d3d12_resource_GetDesc(ID3D12Resource *iface,
@@ -1445,7 +1445,6 @@ static HRESULT d3d12_resource_init(struct d3d12_resource *resource, struct d3d12
}
resource->map_count = 0;
- resource->map_ptr = NULL;
resource->initial_state = initial_state;
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index 34df976fe647..d23b2782a408 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -391,7 +391,6 @@ struct d3d12_resource
unsigned int flags;
unsigned int map_count;
- void *map_ptr;
struct d3d12_heap *heap;
uint64_t heap_offset;
--
2.21.0
2
1
[PATCH vkd3d 4/5] vkd3d: Create private heap objects for committed resources.
by Józef Kucia 20 Jun '19
by Józef Kucia 20 Jun '19
20 Jun '19
From: Józef Kucia <jkucia(a)codeweavers.com>
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
libs/vkd3d/device.c | 2 +-
libs/vkd3d/resource.c | 201 +++++++++++++++++++------------------
libs/vkd3d/vkd3d_private.h | 12 +--
3 files changed, 113 insertions(+), 102 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
index 7522c413278a..f67713594ea5 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -2758,7 +2758,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateHeap(ID3D12Device *iface,
TRACE("iface %p, desc %p, iid %s, heap %p.\n",
iface, desc, debugstr_guid(iid), heap);
- if (FAILED(hr = d3d12_heap_create(device, desc, &object)))
+ if (FAILED(hr = d3d12_heap_create(device, desc, NULL, &object)))
{
*heap = NULL;
return hr;
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index f1cbff11d1ea..0e13cc53e018 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -21,8 +21,6 @@
#define VKD3D_NULL_BUFFER_SIZE 16
#define VKD3D_NULL_VIEW_FORMAT DXGI_FORMAT_R8G8B8A8_UNORM
-#define VKD3D_HEAP_TYPE_INVALID ((D3D12_HEAP_TYPE)~0u)
-
static inline bool is_cpu_accessible_heap(const D3D12_HEAP_PROPERTIES *properties)
{
if (properties->Type == D3D12_HEAP_TYPE_DEFAULT)
@@ -288,31 +286,42 @@ static ULONG STDMETHODCALLTYPE d3d12_heap_AddRef(ID3D12Heap *iface)
TRACE("%p increasing refcount to %u.\n", heap, refcount);
+ assert(!heap->is_private);
+
return refcount;
}
-static ULONG STDMETHODCALLTYPE d3d12_heap_Release(ID3D12Heap *iface)
+static void d3d12_heap_destroy(struct d3d12_heap *heap)
{
- struct d3d12_heap *heap = impl_from_ID3D12Heap(iface);
- ULONG refcount = InterlockedDecrement(&heap->refcount);
+ struct d3d12_device *device = heap->device;
+ const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
- TRACE("%p decreasing refcount to %u.\n", heap, refcount);
+ TRACE("Destroying heap %p.\n", heap);
- if (!refcount)
- {
- struct d3d12_device *device = heap->device;
- const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
+ vkd3d_private_store_destroy(&heap->private_store);
- vkd3d_private_store_destroy(&heap->private_store);
+ VK_CALL(vkFreeMemory(device->vk_device, heap->vk_memory, NULL));
- VK_CALL(vkFreeMemory(device->vk_device, heap->vk_memory, NULL));
+ pthread_mutex_destroy(&heap->mutex);
- pthread_mutex_destroy(&heap->mutex);
+ if (heap->is_private)
+ device = NULL;
- vkd3d_free(heap);
+ vkd3d_free(heap);
+ if (device)
d3d12_device_release(device);
- }
+}
+
+static ULONG STDMETHODCALLTYPE d3d12_heap_Release(ID3D12Heap *iface)
+{
+ struct d3d12_heap *heap = impl_from_ID3D12Heap(iface);
+ ULONG refcount = InterlockedDecrement(&heap->refcount);
+
+ TRACE("%p decreasing refcount to %u.\n", heap, refcount);
+
+ if (!refcount)
+ d3d12_heap_destroy(heap);
return refcount;
}
@@ -437,6 +446,10 @@ static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset, void **d
*data = (BYTE *)heap->map_ptr + offset;
++heap->map_count;
}
+ else
+ {
+ *data = NULL;
+ }
pthread_mutex_unlock(&heap->mutex);
@@ -475,9 +488,9 @@ static void d3d12_heap_unmap(struct d3d12_heap *heap)
pthread_mutex_unlock(&heap->mutex);
}
-static HRESULT validate_heap_desc(const D3D12_HEAP_DESC *desc)
+static HRESULT validate_heap_desc(const D3D12_HEAP_DESC *desc, const struct d3d12_resource *resource)
{
- if (!desc->SizeInBytes)
+ if (!resource && !desc->SizeInBytes)
{
WARN("Invalid size %"PRIu64".\n", desc->SizeInBytes);
return E_INVALIDARG;
@@ -490,7 +503,7 @@ static HRESULT validate_heap_desc(const D3D12_HEAP_DESC *desc)
return E_INVALIDARG;
}
- if (desc->Flags & D3D12_HEAP_FLAG_ALLOW_DISPLAY)
+ if (!resource && desc->Flags & D3D12_HEAP_FLAG_ALLOW_DISPLAY)
{
WARN("D3D12_HEAP_FLAG_ALLOW_DISPLAY is only for committed resources.\n");
return E_INVALIDARG;
@@ -500,15 +513,18 @@ static HRESULT validate_heap_desc(const D3D12_HEAP_DESC *desc)
}
static HRESULT d3d12_heap_init(struct d3d12_heap *heap,
- struct d3d12_device *device, const D3D12_HEAP_DESC *desc)
+ struct d3d12_device *device, const D3D12_HEAP_DESC *desc, const struct d3d12_resource *resource)
{
VkMemoryRequirements memory_requirements;
+ VkDeviceSize vk_memory_size;
HRESULT hr;
int rc;
heap->ID3D12Heap_iface.lpVtbl = &d3d12_heap_vtbl;
heap->refcount = 1;
+ heap->is_private = !!resource;
+
heap->desc = *desc;
heap->map_ptr = NULL;
@@ -525,13 +541,9 @@ static HRESULT d3d12_heap_init(struct d3d12_heap *heap,
if (!heap->desc.Alignment)
heap->desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
- if (FAILED(hr = validate_heap_desc(&heap->desc)))
+ if (FAILED(hr = validate_heap_desc(&heap->desc, resource)))
return hr;
- memory_requirements.size = heap->desc.SizeInBytes;
- memory_requirements.alignment = heap->desc.Alignment;
- memory_requirements.memoryTypeBits = ~(uint32_t)0;
-
if ((rc = pthread_mutex_init(&heap->mutex, NULL)))
{
ERR("Failed to initialize mutex, error %d.\n", rc);
@@ -544,21 +556,49 @@ static HRESULT d3d12_heap_init(struct d3d12_heap *heap,
return hr;
}
- if (FAILED(hr = vkd3d_allocate_device_memory(device, &heap->desc.Properties,
- heap->desc.Flags, &memory_requirements, NULL, &heap->vk_memory, &heap->vk_memory_type)))
+ if (resource)
+ {
+ if (d3d12_resource_is_buffer(resource))
+ {
+ hr = vkd3d_allocate_buffer_memory(device, resource->u.vk_buffer,
+ &heap->desc.Properties, heap->desc.Flags,
+ &heap->vk_memory, &heap->vk_memory_type, &vk_memory_size);
+ }
+ else
+ {
+ hr = vkd3d_allocate_image_memory(device, resource->u.vk_image,
+ &heap->desc.Properties, heap->desc.Flags,
+ &heap->vk_memory, &heap->vk_memory_type, &vk_memory_size);
+ }
+
+ heap->desc.SizeInBytes = vk_memory_size;
+ }
+ else
+ {
+ memory_requirements.size = heap->desc.SizeInBytes;
+ memory_requirements.alignment = heap->desc.Alignment;
+ memory_requirements.memoryTypeBits = ~(uint32_t)0;
+
+ hr = vkd3d_allocate_device_memory(device, &heap->desc.Properties,
+ heap->desc.Flags, &memory_requirements, NULL,
+ &heap->vk_memory, &heap->vk_memory_type);
+ }
+ if (FAILED(hr))
{
vkd3d_private_store_destroy(&heap->private_store);
pthread_mutex_destroy(&heap->mutex);
return hr;
}
- d3d12_device_add_ref(heap->device = device);
+ heap->device = device;
+ if (!heap->is_private)
+ d3d12_device_add_ref(heap->device);
return S_OK;
}
-HRESULT d3d12_heap_create(struct d3d12_device *device,
- const D3D12_HEAP_DESC *desc, struct d3d12_heap **heap)
+HRESULT d3d12_heap_create(struct d3d12_device *device, const D3D12_HEAP_DESC *desc,
+ const struct d3d12_resource *resource, struct d3d12_heap **heap)
{
struct d3d12_heap *object;
HRESULT hr;
@@ -566,13 +606,13 @@ HRESULT d3d12_heap_create(struct d3d12_device *device,
if (!(object = vkd3d_malloc(sizeof(*object))))
return E_OUTOFMEMORY;
- if (FAILED(hr = d3d12_heap_init(object, device, desc)))
+ if (FAILED(hr = d3d12_heap_init(object, device, desc, resource)))
{
vkd3d_free(object);
return hr;
}
- TRACE("Created heap %p.\n", object);
+ TRACE("Created %s %p.\n", object->is_private ? "private heap" : "heap", object);
*heap = object;
@@ -883,8 +923,8 @@ static void d3d12_resource_destroy(struct d3d12_resource *resource, struct d3d12
else
VK_CALL(vkDestroyImage(device->vk_device, resource->u.vk_image, NULL));
- if (resource->vk_memory)
- VK_CALL(vkFreeMemory(device->vk_device, resource->vk_memory, NULL));
+ if (resource->flags & VKD3D_RESOURCE_DEDICATED_HEAP)
+ d3d12_heap_destroy(resource->heap);
}
static ULONG d3d12_resource_incref(struct d3d12_resource *resource)
@@ -914,7 +954,7 @@ static ULONG d3d12_resource_decref(struct d3d12_resource *resource)
bool d3d12_resource_is_cpu_accessible(const struct d3d12_resource *resource)
{
- return is_cpu_accessible_heap(&resource->heap_properties);
+ return resource->heap && is_cpu_accessible_heap(&resource->heap->desc.Properties);
}
/* ID3D12Resource */
@@ -1019,10 +1059,9 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_SetName(ID3D12Resource *iface, c
TRACE("iface %p, name %s.\n", iface, debugstr_w(name, resource->device->wchar_size));
- if (resource->vk_memory)
+ if (resource->flags & VKD3D_RESOURCE_DEDICATED_HEAP)
{
- if (FAILED(hr = vkd3d_set_vk_object_name(resource->device, (uint64_t)resource->vk_memory,
- VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, name)))
+ if (FAILED(hr = d3d12_heap_SetName(&resource->heap->ID3D12Heap_iface, name)))
return hr;
}
@@ -1048,15 +1087,11 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT
{
struct d3d12_resource *resource = impl_from_ID3D12Resource(iface);
unsigned int sub_resource_count;
- struct d3d12_device *device;
HRESULT hr = S_OK;
- VkResult vr;
TRACE("iface %p, sub_resource %u, read_range %p, data %p.\n",
iface, sub_resource, read_range, data);
- device = resource->device;
-
if (!d3d12_resource_is_cpu_accessible(resource))
{
WARN("Resource is not CPU accessible.\n");
@@ -1077,7 +1112,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT
return E_INVALIDARG;
}
- if (!resource->heap && !resource->vk_memory)
+ if (!resource->heap)
{
FIXME("Not implemented for this resource type.\n");
return E_NOTIMPL;
@@ -1087,22 +1122,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_Map(ID3D12Resource *iface, UINT
if (!resource->map_count)
{
- if (resource->heap)
- {
- hr = d3d12_heap_map(resource->heap, resource->heap_offset, &resource->map_ptr);
- }
- else
- {
- const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
-
- if ((vr = VK_CALL(vkMapMemory(device->vk_device, resource->vk_memory,
- 0, VK_WHOLE_SIZE, 0, &resource->map_ptr))) < 0)
- WARN("Failed to map device memory, vr %d.\n", vr);
-
- hr = hresult_from_vk_result(vr);
- }
-
- if (FAILED(hr))
+ if FAILED(hr = d3d12_heap_map(resource->heap, resource->heap_offset, &resource->map_ptr))
{
WARN("Failed to map resource, hr %#x.\n", hr);
resource->map_ptr = NULL;
@@ -1123,7 +1143,6 @@ static void STDMETHODCALLTYPE d3d12_resource_Unmap(ID3D12Resource *iface, UINT s
{
struct d3d12_resource *resource = impl_from_ID3D12Resource(iface);
unsigned int sub_resource_count;
- struct d3d12_device *device;
TRACE("iface %p, sub_resource %u, written_range %p.\n",
iface, sub_resource, written_range);
@@ -1141,21 +1160,15 @@ static void STDMETHODCALLTYPE d3d12_resource_Unmap(ID3D12Resource *iface, UINT s
return;
}
- device = resource->device;
-
WARN("Ignoring written range %p.\n", written_range);
--resource->map_count;
if (!resource->map_count)
{
- const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
-
resource->map_ptr = NULL;
- if (resource->heap)
- d3d12_heap_unmap(resource->heap);
- else
- VK_CALL(vkUnmapMemory(device->vk_device, resource->vk_memory));
+ assert(resource->heap);
+ d3d12_heap_unmap(resource->heap);
}
}
@@ -1207,20 +1220,33 @@ static HRESULT STDMETHODCALLTYPE d3d12_resource_GetHeapProperties(ID3D12Resource
D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS *flags)
{
struct d3d12_resource *resource = impl_from_ID3D12Resource(iface);
+ struct d3d12_heap *heap;
TRACE("iface %p, heap_properties %p, flags %p.\n",
iface, heap_properties, flags);
- if (resource->heap_properties.Type == VKD3D_HEAP_TYPE_INVALID)
+ if (resource->flags & VKD3D_RESOURCE_EXTERNAL)
+ {
+ if (heap_properties)
+ {
+ memset(heap_properties, 0, sizeof(*heap_properties));
+ heap_properties->Type = D3D12_HEAP_TYPE_DEFAULT;
+ }
+ if (flags)
+ *flags = D3D12_HEAP_FLAG_NONE;
+ return S_OK;
+ }
+
+ if (!(heap = resource->heap))
{
WARN("Cannot get heap properties for reserved resources.\n");
return E_INVALIDARG;
}
if (heap_properties)
- *heap_properties = resource->heap_properties;
+ *heap_properties = heap->desc.Properties;
if (flags)
- *flags = resource->heap_flags;
+ *flags = heap->desc.Flags;
return S_OK;
}
@@ -1382,7 +1408,6 @@ static HRESULT d3d12_resource_init(struct d3d12_resource *resource, struct d3d12
WARN("Ignoring optimized clear value.\n");
resource->gpu_address = 0;
- resource->vk_memory = VK_NULL_HANDLE;
resource->flags = 0;
if (FAILED(hr = d3d12_resource_validate_desc(&resource->desc)))
@@ -1422,18 +1447,6 @@ static HRESULT d3d12_resource_init(struct d3d12_resource *resource, struct d3d12
resource->map_count = 0;
resource->map_ptr = NULL;
- if (heap_properties)
- {
- resource->heap_properties = *heap_properties;
- resource->heap_flags = heap_flags;
- }
- else
- {
- memset(&resource->heap_properties, 0, sizeof(resource->heap_properties));
- resource->heap_properties.Type = VKD3D_HEAP_TYPE_INVALID;
- resource->heap_flags = 0;
- }
-
resource->initial_state = initial_state;
resource->heap = NULL;
@@ -1477,16 +1490,16 @@ static HRESULT vkd3d_allocate_resource_memory(
struct d3d12_device *device, struct d3d12_resource *resource,
const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags)
{
- if (d3d12_resource_is_buffer(resource))
- {
- return vkd3d_allocate_buffer_memory(device, resource->u.vk_buffer,
- heap_properties, heap_flags, &resource->vk_memory, NULL, NULL);
- }
- else
- {
- return vkd3d_allocate_image_memory(device, resource->u.vk_image,
- heap_properties, heap_flags, &resource->vk_memory, NULL, NULL);
- }
+ D3D12_HEAP_DESC heap_desc;
+ HRESULT hr;
+
+ heap_desc.SizeInBytes = 0;
+ heap_desc.Properties = *heap_properties;
+ heap_desc.Alignment = 0;
+ heap_desc.Flags = heap_flags;
+ if (SUCCEEDED(hr = d3d12_heap_create(device, &heap_desc, resource, &resource->heap)))
+ resource->flags |= VKD3D_RESOURCE_DEDICATED_HEAP;
+ return hr;
}
HRESULT d3d12_committed_resource_create(struct d3d12_device *device,
@@ -1642,8 +1655,6 @@ HRESULT vkd3d_create_image_resource(ID3D12Device *device,
object->u.vk_image = create_info->vk_image;
object->flags = VKD3D_RESOURCE_EXTERNAL;
object->flags |= create_info->flags & VKD3D_RESOURCE_PUBLIC_FLAGS;
- memset(&object->heap_properties, 0, sizeof(object->heap_properties));
- object->heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT;
object->initial_state = D3D12_RESOURCE_STATE_COMMON;
if (create_info->flags & VKD3D_RESOURCE_PRESENT_STATE_TRANSITION)
object->present_state = create_info->present_state;
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index caaaa2427af7..34df976fe647 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -54,6 +54,7 @@
struct d3d12_command_list;
struct d3d12_device;
+struct d3d12_resource;
struct vkd3d_vk_global_procs
{
@@ -348,6 +349,7 @@ struct d3d12_heap
ID3D12Heap ID3D12Heap_iface;
LONG refcount;
+ bool is_private;
D3D12_HEAP_DESC desc;
pthread_mutex_t mutex;
@@ -362,13 +364,14 @@ struct d3d12_heap
struct vkd3d_private_store private_store;
};
-HRESULT d3d12_heap_create(struct d3d12_device *device,
- const D3D12_HEAP_DESC *desc, struct d3d12_heap **heap) DECLSPEC_HIDDEN;
+HRESULT d3d12_heap_create(struct d3d12_device *device, const D3D12_HEAP_DESC *desc,
+ const struct d3d12_resource *resource, struct d3d12_heap **heap) DECLSPEC_HIDDEN;
struct d3d12_heap *unsafe_impl_from_ID3D12Heap(ID3D12Heap *iface) DECLSPEC_HIDDEN;
#define VKD3D_RESOURCE_PUBLIC_FLAGS \
(VKD3D_RESOURCE_INITIAL_STATE_TRANSITION | VKD3D_RESOURCE_PRESENT_STATE_TRANSITION)
-#define VKD3D_RESOURCE_EXTERNAL 0x00000004
+#define VKD3D_RESOURCE_EXTERNAL 0x00000004
+#define VKD3D_RESOURCE_DEDICATED_HEAP 0x00000008
/* ID3D12Resource */
struct d3d12_resource
@@ -385,7 +388,6 @@ struct d3d12_resource
VkBuffer vk_buffer;
VkImage vk_image;
} u;
- VkDeviceMemory vk_memory;
unsigned int flags;
unsigned int map_count;
@@ -394,8 +396,6 @@ struct d3d12_resource
struct d3d12_heap *heap;
uint64_t heap_offset;
- D3D12_HEAP_PROPERTIES heap_properties;
- D3D12_HEAP_FLAGS heap_flags;
D3D12_RESOURCE_STATES initial_state;
D3D12_RESOURCE_STATES present_state;
--
2.21.0
2
1
[PATCH vkd3d 3/5] vkd3d: Return more information from device memory allocation functions.
by Józef Kucia 20 Jun '19
by Józef Kucia 20 Jun '19
20 Jun '19
From: Józef Kucia <jkucia(a)codeweavers.com>
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
libs/vkd3d/command.c | 2 +-
libs/vkd3d/resource.c | 26 ++++++++++++++++----------
libs/vkd3d/vkd3d_private.h | 2 +-
3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c
index 64c4bd6aeae3..eeae9cf4efe2 100644
--- a/libs/vkd3d/command.c
+++ b/libs/vkd3d/command.c
@@ -3177,7 +3177,7 @@ static HRESULT d3d12_command_list_allocate_transfer_buffer(struct d3d12_command_
&buffer_desc, &buffer->vk_buffer)))
return hr;
if (FAILED(hr = vkd3d_allocate_buffer_memory(device, buffer->vk_buffer,
- &heap_properties, D3D12_HEAP_FLAG_NONE, &buffer->vk_memory)))
+ &heap_properties, D3D12_HEAP_FLAG_NONE, &buffer->vk_memory, NULL, NULL)))
{
VK_CALL(vkDestroyBuffer(device->vk_device, buffer->vk_buffer, NULL));
return hr;
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index fdf68363d29d..f1cbff11d1ea 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -130,7 +130,7 @@ static HRESULT vkd3d_allocate_device_memory(struct d3d12_device *device,
HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_buffer,
const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
- VkDeviceMemory *vk_memory)
+ VkDeviceMemory *vk_memory, uint32_t *vk_memory_type, VkDeviceSize *vk_memory_size)
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
VkMemoryDedicatedAllocateInfo *dedicated_allocation = NULL;
@@ -174,7 +174,7 @@ HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_bu
}
if (FAILED(hr = vkd3d_allocate_device_memory(device, heap_properties, heap_flags,
- memory_requirements, dedicated_allocation, vk_memory, NULL)))
+ memory_requirements, dedicated_allocation, vk_memory, vk_memory_type)))
return hr;
if ((vr = VK_CALL(vkBindBufferMemory(device->vk_device, vk_buffer, *vk_memory, 0))) < 0)
@@ -184,12 +184,15 @@ HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_bu
*vk_memory = VK_NULL_HANDLE;
}
+ if (vk_memory_size)
+ *vk_memory_size = memory_requirements->size;
+
return hresult_from_vk_result(vr);
}
static HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage vk_image,
const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
- VkDeviceMemory *vk_memory)
+ VkDeviceMemory *vk_memory, uint32_t *vk_memory_type, VkDeviceSize *vk_memory_size)
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
VkMemoryDedicatedAllocateInfo *dedicated_allocation = NULL;
@@ -233,7 +236,7 @@ static HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage
}
if (FAILED(hr = vkd3d_allocate_device_memory(device, heap_properties, heap_flags,
- memory_requirements, dedicated_allocation, vk_memory, NULL)))
+ memory_requirements, dedicated_allocation, vk_memory, vk_memory_type)))
return hr;
if ((vr = VK_CALL(vkBindImageMemory(device->vk_device, vk_image, *vk_memory, 0))) < 0)
@@ -244,6 +247,9 @@ static HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage
return hresult_from_vk_result(vr);
}
+ if (vk_memory_size)
+ *vk_memory_size = memory_requirements->size;
+
return S_OK;
}
@@ -1474,12 +1480,12 @@ static HRESULT vkd3d_allocate_resource_memory(
if (d3d12_resource_is_buffer(resource))
{
return vkd3d_allocate_buffer_memory(device, resource->u.vk_buffer,
- heap_properties, heap_flags, &resource->vk_memory);
+ heap_properties, heap_flags, &resource->vk_memory, NULL, NULL);
}
else
{
return vkd3d_allocate_image_memory(device, resource->u.vk_image,
- heap_properties, heap_flags, &resource->vk_memory);
+ heap_properties, heap_flags, &resource->vk_memory, NULL, NULL);
}
}
@@ -3591,7 +3597,7 @@ HRESULT vkd3d_init_null_resources(struct vkd3d_null_resources *null_resources,
&resource_desc, &null_resources->vk_buffer)))
goto fail;
if (FAILED(hr = vkd3d_allocate_buffer_memory(device, null_resources->vk_buffer,
- &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_buffer_memory)))
+ &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_buffer_memory, NULL, NULL)))
goto fail;
/* buffer UAV */
@@ -3601,7 +3607,7 @@ HRESULT vkd3d_init_null_resources(struct vkd3d_null_resources *null_resources,
&resource_desc, &null_resources->vk_storage_buffer)))
goto fail;
if (!use_sparse_resources && FAILED(hr = vkd3d_allocate_buffer_memory(device, null_resources->vk_storage_buffer,
- &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_storage_buffer_memory)))
+ &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_storage_buffer_memory, NULL, NULL)))
goto fail;
/* 2D SRV */
@@ -3621,7 +3627,7 @@ HRESULT vkd3d_init_null_resources(struct vkd3d_null_resources *null_resources,
&resource_desc, &null_resources->vk_2d_image)))
goto fail;
if (FAILED(hr = vkd3d_allocate_image_memory(device, null_resources->vk_2d_image,
- &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_2d_image_memory)))
+ &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_2d_image_memory, NULL, NULL)))
goto fail;
/* 2D UAV */
@@ -3642,7 +3648,7 @@ HRESULT vkd3d_init_null_resources(struct vkd3d_null_resources *null_resources,
&resource_desc, &null_resources->vk_2d_storage_image)))
goto fail;
if (!use_sparse_resources && FAILED(hr = vkd3d_allocate_image_memory(device, null_resources->vk_2d_storage_image,
- &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_2d_storage_image_memory)))
+ &heap_properties, D3D12_HEAP_FLAG_NONE, &null_resources->vk_2d_storage_image_memory, NULL, NULL)))
goto fail;
/* set Vulkan object names */
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index c86370a60d04..caaaa2427af7 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -431,7 +431,7 @@ struct d3d12_resource *unsafe_impl_from_ID3D12Resource(ID3D12Resource *iface) DE
HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_buffer,
const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
- VkDeviceMemory *vk_memory) DECLSPEC_HIDDEN;
+ VkDeviceMemory *vk_memory, uint32_t *vk_memory_type, VkDeviceSize *vk_memory_size) DECLSPEC_HIDDEN;
HRESULT vkd3d_create_buffer(struct d3d12_device *device,
const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
const D3D12_RESOURCE_DESC *desc, VkBuffer *vk_buffer) DECLSPEC_HIDDEN;
--
2.21.0
2
1
20 Jun '19
From: Józef Kucia <jkucia(a)codeweavers.com>
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
libs/vkd3d/resource.c | 238 +++++++++++++++++++++---------------------
1 file changed, 119 insertions(+), 119 deletions(-)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index bcf523e47d75..824698a143b5 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -116,6 +116,125 @@ static HRESULT vkd3d_allocate_device_memory(struct d3d12_device *device,
return S_OK;
}
+HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_buffer,
+ const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
+ VkDeviceMemory *vk_memory)
+{
+ const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
+ VkMemoryDedicatedAllocateInfo *dedicated_allocation = NULL;
+ VkMemoryDedicatedRequirements dedicated_requirements;
+ VkMemoryDedicatedAllocateInfo dedicated_info;
+ VkMemoryRequirements2 memory_requirements2;
+ VkMemoryRequirements *memory_requirements;
+ VkBufferMemoryRequirementsInfo2 info;
+ VkResult vr;
+ HRESULT hr;
+
+ memory_requirements = &memory_requirements2.memoryRequirements;
+
+ if (device->vk_info.KHR_dedicated_allocation)
+ {
+ info.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2;
+ info.pNext = NULL;
+ info.buffer = vk_buffer;
+
+ dedicated_requirements.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS;
+ dedicated_requirements.pNext = NULL;
+
+ memory_requirements2.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2;
+ memory_requirements2.pNext = &dedicated_requirements;
+
+ VK_CALL(vkGetBufferMemoryRequirements2KHR(device->vk_device, &info, &memory_requirements2));
+
+ if (dedicated_requirements.prefersDedicatedAllocation)
+ {
+ dedicated_allocation = &dedicated_info;
+
+ dedicated_info.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO;
+ dedicated_info.pNext = NULL;
+ dedicated_info.image = VK_NULL_HANDLE;
+ dedicated_info.buffer = vk_buffer;
+ }
+ }
+ else
+ {
+ VK_CALL(vkGetBufferMemoryRequirements(device->vk_device, vk_buffer, memory_requirements));
+ }
+
+ if (FAILED(hr = vkd3d_allocate_device_memory(device, heap_properties, heap_flags,
+ memory_requirements, dedicated_allocation, vk_memory, NULL)))
+ return hr;
+
+ if ((vr = VK_CALL(vkBindBufferMemory(device->vk_device, vk_buffer, *vk_memory, 0))) < 0)
+ {
+ WARN("Failed to bind memory, vr %d.\n", vr);
+ VK_CALL(vkFreeMemory(device->vk_device, *vk_memory, NULL));
+ *vk_memory = VK_NULL_HANDLE;
+ }
+
+ return hresult_from_vk_result(vr);
+}
+
+static HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage vk_image,
+ const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
+ VkDeviceMemory *vk_memory)
+{
+ const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
+ VkMemoryDedicatedAllocateInfo *dedicated_allocation = NULL;
+ VkMemoryDedicatedRequirements dedicated_requirements;
+ VkMemoryDedicatedAllocateInfo dedicated_info;
+ VkMemoryRequirements2 memory_requirements2;
+ VkMemoryRequirements *memory_requirements;
+ VkImageMemoryRequirementsInfo2 info;
+ VkResult vr;
+ HRESULT hr;
+
+ memory_requirements = &memory_requirements2.memoryRequirements;
+
+ if (device->vk_info.KHR_dedicated_allocation)
+ {
+ info.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2;
+ info.pNext = NULL;
+ info.image = vk_image;
+
+ dedicated_requirements.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS;
+ dedicated_requirements.pNext = NULL;
+
+ memory_requirements2.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2;
+ memory_requirements2.pNext = &dedicated_requirements;
+
+ VK_CALL(vkGetImageMemoryRequirements2KHR(device->vk_device, &info, &memory_requirements2));
+
+ if (dedicated_requirements.prefersDedicatedAllocation)
+ {
+ dedicated_allocation = &dedicated_info;
+
+ dedicated_info.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO;
+ dedicated_info.pNext = NULL;
+ dedicated_info.image = vk_image;
+ dedicated_info.buffer = VK_NULL_HANDLE;
+ }
+ }
+ else
+ {
+ VK_CALL(vkGetImageMemoryRequirements(device->vk_device, vk_image, memory_requirements));
+ }
+
+ if (FAILED(hr = vkd3d_allocate_device_memory(device, heap_properties, heap_flags,
+ memory_requirements, dedicated_allocation, vk_memory, NULL)))
+ return hr;
+
+ if ((vr = VK_CALL(vkBindImageMemory(device->vk_device, vk_image, *vk_memory, 0))) < 0)
+ {
+ WARN("Failed to bind memory, vr %d.\n", vr);
+ VK_CALL(vkFreeMemory(device->vk_device, *vk_memory, NULL));
+ *vk_memory = VK_NULL_HANDLE;
+ return hresult_from_vk_result(vr);
+ }
+
+ return S_OK;
+}
+
/* ID3D12Heap */
static inline struct d3d12_heap *impl_from_ID3D12Heap(ID3D12Heap *iface)
{
@@ -731,125 +850,6 @@ HRESULT vkd3d_get_image_allocation_info(struct d3d12_device *device,
return hr;
}
-HRESULT vkd3d_allocate_buffer_memory(struct d3d12_device *device, VkBuffer vk_buffer,
- const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
- VkDeviceMemory *vk_memory)
-{
- const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
- VkMemoryDedicatedAllocateInfo *dedicated_allocation = NULL;
- VkMemoryDedicatedRequirements dedicated_requirements;
- VkMemoryDedicatedAllocateInfo dedicated_info;
- VkMemoryRequirements2 memory_requirements2;
- VkMemoryRequirements *memory_requirements;
- VkBufferMemoryRequirementsInfo2 info;
- VkResult vr;
- HRESULT hr;
-
- memory_requirements = &memory_requirements2.memoryRequirements;
-
- if (device->vk_info.KHR_dedicated_allocation)
- {
- info.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2;
- info.pNext = NULL;
- info.buffer = vk_buffer;
-
- dedicated_requirements.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS;
- dedicated_requirements.pNext = NULL;
-
- memory_requirements2.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2;
- memory_requirements2.pNext = &dedicated_requirements;
-
- VK_CALL(vkGetBufferMemoryRequirements2KHR(device->vk_device, &info, &memory_requirements2));
-
- if (dedicated_requirements.prefersDedicatedAllocation)
- {
- dedicated_allocation = &dedicated_info;
-
- dedicated_info.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO;
- dedicated_info.pNext = NULL;
- dedicated_info.image = VK_NULL_HANDLE;
- dedicated_info.buffer = vk_buffer;
- }
- }
- else
- {
- VK_CALL(vkGetBufferMemoryRequirements(device->vk_device, vk_buffer, memory_requirements));
- }
-
- if (FAILED(hr = vkd3d_allocate_device_memory(device, heap_properties, heap_flags,
- memory_requirements, dedicated_allocation, vk_memory, NULL)))
- return hr;
-
- if ((vr = VK_CALL(vkBindBufferMemory(device->vk_device, vk_buffer, *vk_memory, 0))) < 0)
- {
- WARN("Failed to bind memory, vr %d.\n", vr);
- VK_CALL(vkFreeMemory(device->vk_device, *vk_memory, NULL));
- *vk_memory = VK_NULL_HANDLE;
- }
-
- return hresult_from_vk_result(vr);
-}
-
-static HRESULT vkd3d_allocate_image_memory(struct d3d12_device *device, VkImage vk_image,
- const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags,
- VkDeviceMemory *vk_memory)
-{
- const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
- VkMemoryDedicatedAllocateInfo *dedicated_allocation = NULL;
- VkMemoryDedicatedRequirements dedicated_requirements;
- VkMemoryDedicatedAllocateInfo dedicated_info;
- VkMemoryRequirements2 memory_requirements2;
- VkMemoryRequirements *memory_requirements;
- VkImageMemoryRequirementsInfo2 info;
- VkResult vr;
- HRESULT hr;
-
- memory_requirements = &memory_requirements2.memoryRequirements;
-
- if (device->vk_info.KHR_dedicated_allocation)
- {
- info.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2;
- info.pNext = NULL;
- info.image = vk_image;
-
- dedicated_requirements.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS;
- dedicated_requirements.pNext = NULL;
-
- memory_requirements2.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2;
- memory_requirements2.pNext = &dedicated_requirements;
-
- VK_CALL(vkGetImageMemoryRequirements2KHR(device->vk_device, &info, &memory_requirements2));
-
- if (dedicated_requirements.prefersDedicatedAllocation)
- {
- dedicated_allocation = &dedicated_info;
-
- dedicated_info.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO;
- dedicated_info.pNext = NULL;
- dedicated_info.image = vk_image;
- dedicated_info.buffer = VK_NULL_HANDLE;
- }
- }
- else
- {
- VK_CALL(vkGetImageMemoryRequirements(device->vk_device, vk_image, memory_requirements));
- }
-
- if (FAILED(hr = vkd3d_allocate_device_memory(device, heap_properties, heap_flags,
- memory_requirements, dedicated_allocation, vk_memory, NULL)))
- return hr;
-
- if ((vr = VK_CALL(vkBindImageMemory(device->vk_device, vk_image, *vk_memory, 0))) < 0)
- {
- WARN("Failed to bind memory, vr %d.\n", vr);
- VK_CALL(vkFreeMemory(device->vk_device, *vk_memory, NULL));
- *vk_memory = VK_NULL_HANDLE;
- return hresult_from_vk_result(vr);
- }
-
- return S_OK;
-}
-
static void d3d12_resource_destroy(struct d3d12_resource *resource, struct d3d12_device *device)
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
--
2.21.0
2
1