@@ -33,10 +33,6 @@ namespace dxvk {
3333 m_commonD3DIntf = new D3DCommonInterface (std::move (d3d9Intf), std::move (intfBridgeInst));
3434 }
3535
36- const D3DOptions* d3dOptions = m_commonIntf->GetOptions ();
37- // Retrieve and cache the base capabilities
38- m_desc = GetD3D3BaseCaps (d3dOptions);
39-
4036 m_commonD3DIntf->SetD3D3Interface (this );
4137
4238 // Don't enable D3D3 compatibility mode when coming from a higher interface
@@ -154,110 +150,99 @@ namespace dxvk {
154150
155151 HRESULT hr;
156152
153+ // Tests have shown all returned variables and structs are expected
154+ // to remain valid even after the enumeration completes. Moreover,
155+ // some applications may choose to overwrite various elements in place,
156+ // such as the device name/description, and reuse those strings.
157+
157158 // RAMP device (monochrome), this is expected to be exposed
158- // The caps of a RAMP device are mostly identical to an RGB device
159- D3DDEVICEDESC3 desc3RAMP_HAL = m_desc;
160- ApplyD3D3DeviceCaps (&desc3RAMP_HAL, IID_IDirect3DRampDevice);
161- D3DDEVICEDESC3 desc3RAMP_HEL = m_desc;
162- ApplyD3D3DeviceCaps (&desc3RAMP_HEL, IID_IDirect3DRampDevice);
163- D3DDEVICEDESC descRAMP_HAL = { };
164- D3DDEVICEDESC descRAMP_HEL = { };
165- desc3RAMP_HAL.dwFlags = 0u ;
166- desc3RAMP_HAL.dcmColorModel = 0u ;
167- // RAMP devices use a monochrome color model
168- desc3RAMP_HEL.dcmColorModel = D3DCOLOR_MONO ;
169- // Some applications apparently care about HAL texture caps
170- desc3RAMP_HAL.dpcLineCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
171- & ~D3DPTEXTURECAPS_POW2
172- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
173- desc3RAMP_HAL.dpcTriCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
174- & ~D3DPTEXTURECAPS_POW2
175- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
176- memcpy (&descRAMP_HAL, &desc3RAMP_HAL, sizeof (D3DDEVICEDESC3 ));
177- memcpy (&descRAMP_HEL, &desc3RAMP_HEL, sizeof (D3DDEVICEDESC3 ));
178-
179- static GUID deviceGuidRAMP = IID_IDirect3DRampDevice;
159+ static GUID deviceGuidRAMP;
160+ static char deviceDescRAMP[MAX_ENUM_DEVICES_IDENTIFIER_STRING ];
161+ static char deviceNameRAMP[MAX_ENUM_DEVICES_IDENTIFIER_STRING ];
162+ static D3DDEVICEDESC descDeviceRAMP_HAL;
163+ static D3DDEVICEDESC descDeviceRAMP_HEL;
164+
165+ D3DDEVICEDESC3 desc3RAMP_HAL = GetD3D3BaseCaps (d3dOptions);
166+ ApplyD3D3DeviceCaps (&desc3RAMP_HAL, IID_IDirect3DRampDevice, true );
167+ D3DDEVICEDESC3 desc3RAMP_HEL = GetD3D3BaseCaps (d3dOptions);
168+ ApplyD3D3DeviceCaps (&desc3RAMP_HEL, IID_IDirect3DRampDevice, false );
169+
170+ deviceGuidRAMP = IID_IDirect3DRampDevice;
180171 if (likely (!d3dOptions->legacyDeviceNames )) {
181- static char deviceDescRAMP[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " D3VK Ramp" ;
182- static char deviceNameRAMP[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " D3VK Ramp" ;
183- hr = lpEnumDevicesCallback (&deviceGuidRAMP, &deviceDescRAMP[0 ], &deviceNameRAMP[0 ],
184- &descRAMP_HAL, &descRAMP_HEL, lpUserArg);
172+ CopyToStringArrayAndPad (deviceDescRAMP, " D3VK Ramp" );
173+ CopyToStringArrayAndPad (deviceNameRAMP, " D3VK Ramp" );
174+
185175 } else {
186- static char legacyDeviceDescRAMP[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " Ramp Emulation" ;
187- static char legacyDeviceNameRAMP[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " Ramp Emulation" ;
188- hr = lpEnumDevicesCallback (&deviceGuidRAMP, &legacyDeviceDescRAMP[0 ], &legacyDeviceNameRAMP[0 ],
189- &descRAMP_HAL, &descRAMP_HEL, lpUserArg);
176+ CopyToStringArrayAndPad (deviceDescRAMP, " Ramp Emulation" );
177+ CopyToStringArrayAndPad (deviceNameRAMP, " Ramp Emulation" );
190178 }
179+ memset (&descDeviceRAMP_HAL, 0 , sizeof (D3DDEVICEDESC ));
180+ memset (&descDeviceRAMP_HEL, 0 , sizeof (D3DDEVICEDESC ));
181+ memcpy (&descDeviceRAMP_HAL, &desc3RAMP_HAL, sizeof (D3DDEVICEDESC3 ));
182+ memcpy (&descDeviceRAMP_HEL, &desc3RAMP_HEL, sizeof (D3DDEVICEDESC3 ));
183+
184+ hr = lpEnumDevicesCallback (&deviceGuidRAMP, &deviceDescRAMP[0 ], &deviceNameRAMP[0 ],
185+ &descDeviceRAMP_HAL, &descDeviceRAMP_HEL, lpUserArg);
191186 if (hr != D3DENUMRET_OK )
192187 return D3D_OK ;
193188
194189 // Software emulation, this is expected to be exposed
195- D3DDEVICEDESC3 desc3RGB_HAL = m_desc;
196- ApplyD3D3DeviceCaps (&desc3RGB_HAL, IID_IDirect3DRGBDevice);
197- D3DDEVICEDESC3 desc3RGB_HEL = m_desc;
198- ApplyD3D3DeviceCaps (&desc3RGB_HEL, IID_IDirect3DRGBDevice);
199- D3DDEVICEDESC descRGB_HAL = { };
200- D3DDEVICEDESC descRGB_HEL = { };
201- desc3RGB_HAL.dwFlags = 0u ;
202- desc3RGB_HAL.dcmColorModel = 0u ;
203- // Some applications apparently care about HAL texture caps
204- desc3RGB_HAL.dpcLineCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
205- & ~D3DPTEXTURECAPS_POW2
206- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
207- desc3RGB_HAL.dpcTriCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
208- & ~D3DPTEXTURECAPS_POW2
209- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
210- memcpy (&descRGB_HAL, &desc3RGB_HAL, sizeof (D3DDEVICEDESC3 ));
211- memcpy (&descRGB_HEL, &desc3RGB_HEL, sizeof (D3DDEVICEDESC3 ));
212-
213- static GUID deviceGuidRGB = IID_IDirect3DRGBDevice;
190+ static GUID deviceGuidRGB;
191+ static char deviceDescRGB[MAX_ENUM_DEVICES_IDENTIFIER_STRING ];
192+ static char deviceNameRGB[MAX_ENUM_DEVICES_IDENTIFIER_STRING ];
193+ static D3DDEVICEDESC descDeviceRGB_HAL;
194+ static D3DDEVICEDESC descDeviceRGB_HEL;
195+
196+ D3DDEVICEDESC3 desc3RGB_HAL = GetD3D3BaseCaps (d3dOptions);
197+ ApplyD3D3DeviceCaps (&desc3RGB_HAL, IID_IDirect3DRGBDevice, true );
198+ D3DDEVICEDESC3 desc3RGB_HEL = GetD3D3BaseCaps (d3dOptions);
199+ ApplyD3D3DeviceCaps (&desc3RGB_HEL, IID_IDirect3DRGBDevice, false );
200+
201+ deviceGuidRGB = IID_IDirect3DRGBDevice;
214202 if (likely (!d3dOptions->legacyDeviceNames )) {
215- static char deviceDescRGB[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " D3VK RGB" ;
216- static char deviceNameRGB[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " D3VK RGB" ;
217- hr = lpEnumDevicesCallback (&deviceGuidRGB, &deviceDescRGB[0 ], &deviceNameRGB[0 ],
218- &descRGB_HAL, &descRGB_HEL, lpUserArg);
203+ CopyToStringArrayAndPad (deviceDescRGB, " D3VK RGB" );
204+ CopyToStringArrayAndPad (deviceNameRGB, " D3VK RGB" );
219205 } else {
220- static char legacyDeviceDescRGB[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " RGB Emulation" ;
221- static char legacyDeviceNameRGB[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " RGB Emulation" ;
222- hr = lpEnumDevicesCallback (&deviceGuidRGB, &legacyDeviceDescRGB[0 ], &legacyDeviceNameRGB[0 ],
223- &descRGB_HAL, &descRGB_HEL, lpUserArg);
206+ CopyToStringArrayAndPad (deviceDescRGB, " RGB Emulation" );
207+ CopyToStringArrayAndPad (deviceNameRGB, " RGB Emulation" );
224208 }
209+ memset (&descDeviceRGB_HAL, 0 , sizeof (D3DDEVICEDESC ));
210+ memset (&descDeviceRGB_HEL, 0 , sizeof (D3DDEVICEDESC ));
211+ memcpy (&descDeviceRGB_HAL, &desc3RGB_HAL, sizeof (D3DDEVICEDESC3 ));
212+ memcpy (&descDeviceRGB_HEL, &desc3RGB_HEL, sizeof (D3DDEVICEDESC3 ));
213+
214+ hr = lpEnumDevicesCallback (&deviceGuidRGB, &deviceDescRGB[0 ], &deviceNameRGB[0 ],
215+ &descDeviceRGB_HAL, &descDeviceRGB_HEL, lpUserArg);
225216 if (hr != D3DENUMRET_OK )
226217 return D3D_OK ;
227218
228219 // Hardware acceleration
229- D3DDEVICEDESC3 desc3HAL_HAL = m_desc;
230- ApplyD3D3DeviceCaps (&desc3HAL_HAL, IID_IDirect3DHALDevice);
231- D3DDEVICEDESC3 desc3HAL_HEL = m_desc;
232- ApplyD3D3DeviceCaps (&desc3HAL_HEL, IID_IDirect3DHALDevice);
233- D3DDEVICEDESC descHAL_HAL = { };
234- D3DDEVICEDESC descHAL_HEL = { };
235- desc3HAL_HEL.dcmColorModel = 0u ;
236- // Some applications apparently care about HEL texture caps
237- desc3HAL_HEL.dpcLineCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
238- & ~D3DPTEXTURECAPS_POW2
239- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
240- desc3HAL_HEL.dpcTriCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
241- & ~D3DPTEXTURECAPS_POW2
242- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
243- desc3HAL_HEL.dwDevCaps &= ~D3DDEVCAPS_HWTRANSFORMANDLIGHT
244- & ~D3DDEVCAPS_DRAWPRIMITIVES2
245- & ~D3DDEVCAPS_DRAWPRIMITIVES2EX ;
246- memcpy (&descHAL_HAL, &desc3HAL_HAL, sizeof (D3DDEVICEDESC3 ));
247- memcpy (&descHAL_HEL, &desc3HAL_HEL, sizeof (D3DDEVICEDESC3 ));
248-
249- static GUID deviceGuidHAL = IID_IDirect3DHALDevice;
220+ static GUID deviceGuidHAL;
221+ static char deviceDescHAL[MAX_ENUM_DEVICES_IDENTIFIER_STRING ];
222+ static char deviceNameHAL[MAX_ENUM_DEVICES_IDENTIFIER_STRING ];
223+ static D3DDEVICEDESC descDeviceHAL_HAL;
224+ static D3DDEVICEDESC descDeviceHAL_HEL;
225+
226+ D3DDEVICEDESC3 desc3HAL_HAL = GetD3D3BaseCaps (d3dOptions);
227+ ApplyD3D3DeviceCaps (&desc3HAL_HAL, IID_IDirect3DHALDevice, true );
228+ D3DDEVICEDESC3 desc3HAL_HEL = GetD3D3BaseCaps (d3dOptions);
229+ ApplyD3D3DeviceCaps (&desc3HAL_HEL, IID_IDirect3DHALDevice, false );
230+
231+ deviceGuidHAL = IID_IDirect3DHALDevice;
250232 if (likely (!d3dOptions->legacyDeviceNames )) {
251- static char deviceDescHAL[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " D3VK HAL" ;
252- static char deviceNameHAL[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " D3VK HAL" ;
253- hr = lpEnumDevicesCallback (&deviceGuidHAL, &deviceDescHAL[0 ], &deviceNameHAL[0 ],
254- &descHAL_HAL, &descHAL_HEL, lpUserArg);
233+ CopyToStringArrayAndPad (deviceDescHAL, " D3VK HAL" );
234+ CopyToStringArrayAndPad (deviceNameHAL, " D3VK HAL" );
255235 } else {
256- static char legacyDeviceDescHAL[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " Direct3D HAL" ;
257- static char legacyDeviceNameHAL[MAX_ENUM_DEVICES_IDENTIFIER_STRING ] = " Direct3D HAL" ;
258- hr = lpEnumDevicesCallback (&deviceGuidHAL, &legacyDeviceDescHAL[0 ], &legacyDeviceNameHAL[0 ],
259- &descHAL_HAL, &descHAL_HEL, lpUserArg);
236+ CopyToStringArrayAndPad (deviceDescHAL, " Direct3D HAL" );
237+ CopyToStringArrayAndPad (deviceDescHAL, " Direct3D HAL" );
260238 }
239+ memset (&descDeviceHAL_HAL, 0 , sizeof (D3DDEVICEDESC ));
240+ memset (&descDeviceHAL_HEL, 0 , sizeof (D3DDEVICEDESC ));
241+ memcpy (&descDeviceHAL_HAL, &desc3HAL_HAL, sizeof (D3DDEVICEDESC3 ));
242+ memcpy (&descDeviceHAL_HEL, &desc3HAL_HEL, sizeof (D3DDEVICEDESC3 ));
243+
244+ hr = lpEnumDevicesCallback (&deviceGuidHAL, &deviceDescHAL[0 ], &deviceNameHAL[0 ],
245+ &descDeviceHAL_HAL, &descDeviceHAL_HEL, lpUserArg);
261246 if (hr != D3DENUMRET_OK )
262247 return D3D_OK ;
263248
@@ -304,37 +289,19 @@ namespace dxvk {
304289 if (unlikely (!IsValidFindDeviceResultSize (lpD3DFDR->dwSize )))
305290 return DDERR_INVALIDPARAMS ;
306291
292+ const D3DOptions* d3dOptions = m_commonIntf->GetOptions ();
293+
307294 // Software emulation, this is expected to be exposed
308- D3DDEVICEDESC3 descRGB_HAL = m_desc;
309- ApplyD3D3DeviceCaps (&descRGB_HAL, IID_IDirect3DRGBDevice);
310- D3DDEVICEDESC3 descRGB_HEL = m_desc;
311- ApplyD3D3DeviceCaps (&descRGB_HEL, IID_IDirect3DRGBDevice);
312- descRGB_HAL.dwFlags = 0u ;
313- descRGB_HAL.dcmColorModel = 0u ;
314- // Some applications apparently care about HAL texture caps
315- descRGB_HAL.dpcLineCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
316- & ~D3DPTEXTURECAPS_POW2
317- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
318- descRGB_HAL.dpcTriCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
319- & ~D3DPTEXTURECAPS_POW2
320- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
295+ D3DDEVICEDESC3 descRGB_HAL = GetD3D3BaseCaps (d3dOptions);
296+ ApplyD3D3DeviceCaps (&descRGB_HAL, IID_IDirect3DRGBDevice, true );
297+ D3DDEVICEDESC3 descRGB_HEL = GetD3D3BaseCaps (d3dOptions);
298+ ApplyD3D3DeviceCaps (&descRGB_HEL, IID_IDirect3DRGBDevice, false );
321299
322300 // Hardware acceleration
323- D3DDEVICEDESC3 descHAL_HAL = m_desc;
324- ApplyD3D3DeviceCaps (&descHAL_HAL, IID_IDirect3DHALDevice);
325- D3DDEVICEDESC3 descHAL_HEL = m_desc;
326- ApplyD3D3DeviceCaps (&descHAL_HEL, IID_IDirect3DHALDevice);
327- descHAL_HEL.dcmColorModel = 0u ;
328- // Some applications apparently care about HEL texture caps
329- descHAL_HEL.dpcLineCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
330- & ~D3DPTEXTURECAPS_POW2
331- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
332- descHAL_HEL.dpcTriCaps .dwTextureCaps &= ~D3DPTEXTURECAPS_PERSPECTIVE
333- & ~D3DPTEXTURECAPS_POW2
334- & ~D3DPTEXTURECAPS_NONPOW2CONDITIONAL ;
335- descHAL_HEL.dwDevCaps &= ~D3DDEVCAPS_HWTRANSFORMANDLIGHT
336- & ~D3DDEVCAPS_DRAWPRIMITIVES2
337- & ~D3DDEVCAPS_DRAWPRIMITIVES2EX ;
301+ D3DDEVICEDESC3 descHAL_HAL = GetD3D3BaseCaps (d3dOptions);
302+ ApplyD3D3DeviceCaps (&descHAL_HAL, IID_IDirect3DHALDevice, true );
303+ D3DDEVICEDESC3 descHAL_HEL = GetD3D3BaseCaps (d3dOptions);
304+ ApplyD3D3DeviceCaps (&descHAL_HEL, IID_IDirect3DHALDevice, false );
338305
339306 D3DFINDDEVICERESULT3 lpD3DFRD3 = { };
340307 lpD3DFRD3.dwSize = sizeof (D3DFINDDEVICERESULT3 );
0 commit comments