Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

704 lines
23 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // swprov.cpp
  4. //
  5. // Implements software rasterizer HAL provider.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #pragma hdrstop
  12. #include "d3dref.h"
  13. #define MAX_CLIPPING_PLANES 12
  14. #define MAX_CLIP_VERTICES (( 2 * MAX_CLIPPING_PLANES ) + 3 )
  15. #define MAX_VERTEX_COUNT 2048
  16. #define BASE_VERTEX_COUNT (MAX_VERTEX_COUNT - MAX_CLIP_VERTICES)
  17. extern HRESULT
  18. RastService(DWORD dwCtx,
  19. RastServiceType srvType, DWORD arg1, LPVOID arg2);
  20. #define nullPrimCaps \
  21. { \
  22. sizeof(D3DPRIMCAPS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  23. }
  24. #define nullTransCaps \
  25. { \
  26. sizeof(D3DTRANSFORMCAPS), 0 \
  27. }
  28. #define nullLightCaps \
  29. { \
  30. sizeof(D3DLIGHTINGCAPS), 0, 0, 0 \
  31. }
  32. D3DDEVICEDESC7 g_nullDevDesc =
  33. {
  34. 0, /* dwDevCaps */
  35. nullPrimCaps, /* lineCaps */
  36. nullPrimCaps, /* triCaps */
  37. 0, 0,
  38. 0, 0,
  39. };
  40. static D3DDEVICEDESC7 rgbDevDesc = {0};
  41. static D3DHAL_D3DEXTENDEDCAPS OptSwExtCaps;
  42. static BOOL g_bFilledRGBCaps = FALSE;
  43. static void
  44. FillOutDeviceCaps( void )
  45. {
  46. //
  47. // set device description
  48. //
  49. rgbDevDesc.dwDevCaps =
  50. D3DDEVCAPS_FLOATTLVERTEX |
  51. D3DDEVCAPS_EXECUTESYSTEMMEMORY |
  52. D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
  53. D3DDEVCAPS_TEXTURESYSTEMMEMORY |
  54. D3DDEVCAPS_DRAWPRIMTLVERTEX ;
  55. rgbDevDesc.dpcTriCaps.dwSize = sizeof(D3DPRIMCAPS);
  56. rgbDevDesc.dpcTriCaps.dwMiscCaps =
  57. D3DPMISCCAPS_CULLNONE |
  58. D3DPMISCCAPS_CULLCW |
  59. D3DPMISCCAPS_CULLCCW ;
  60. rgbDevDesc.dpcTriCaps.dwRasterCaps =
  61. D3DPRASTERCAPS_DITHER |
  62. D3DPRASTERCAPS_ROP2 |
  63. D3DPRASTERCAPS_XOR |
  64. // D3DPRASTERCAPS_PAT |
  65. D3DPRASTERCAPS_ZTEST |
  66. D3DPRASTERCAPS_SUBPIXEL |
  67. D3DPRASTERCAPS_SUBPIXELX |
  68. D3DPRASTERCAPS_FOGVERTEX |
  69. D3DPRASTERCAPS_FOGTABLE |
  70. // D3DPRASTERCAPS_STIPPLE |
  71. // D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT |
  72. // D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT |
  73. // D3DPRASTERCAPS_ANTIALIASEDGES |
  74. D3DPRASTERCAPS_MIPMAPLODBIAS |
  75. // D3DPRASTERCAPS_ZBIAS |
  76. // D3DPRASTERCAPS_ZBUFFERLESSHSR |
  77. D3DPRASTERCAPS_FOGRANGE |
  78. // D3DPRASTERCAPS_WFOG |
  79. D3DPRASTERCAPS_ZFOG ;
  80. // D3DPRASTERCAPS_ANISOTROPY ;
  81. rgbDevDesc.dpcTriCaps.dwZCmpCaps =
  82. D3DPCMPCAPS_NEVER |
  83. D3DPCMPCAPS_LESS |
  84. D3DPCMPCAPS_EQUAL |
  85. D3DPCMPCAPS_LESSEQUAL |
  86. D3DPCMPCAPS_GREATER |
  87. D3DPCMPCAPS_NOTEQUAL |
  88. D3DPCMPCAPS_GREATEREQUAL |
  89. D3DPCMPCAPS_ALWAYS ;
  90. rgbDevDesc.dpcTriCaps.dwSrcBlendCaps =
  91. D3DPBLENDCAPS_ZERO |
  92. D3DPBLENDCAPS_ONE |
  93. D3DPBLENDCAPS_SRCCOLOR |
  94. D3DPBLENDCAPS_INVSRCCOLOR |
  95. D3DPBLENDCAPS_SRCALPHA |
  96. D3DPBLENDCAPS_INVSRCALPHA |
  97. D3DPBLENDCAPS_DESTALPHA |
  98. D3DPBLENDCAPS_INVDESTALPHA |
  99. D3DPBLENDCAPS_DESTCOLOR |
  100. D3DPBLENDCAPS_INVDESTCOLOR |
  101. D3DPBLENDCAPS_SRCALPHASAT |
  102. D3DPBLENDCAPS_BOTHSRCALPHA |
  103. D3DPBLENDCAPS_BOTHINVSRCALPHA ;
  104. rgbDevDesc.dpcTriCaps.dwDestBlendCaps =
  105. D3DPBLENDCAPS_ZERO |
  106. D3DPBLENDCAPS_ONE |
  107. D3DPBLENDCAPS_SRCCOLOR |
  108. D3DPBLENDCAPS_INVSRCCOLOR |
  109. D3DPBLENDCAPS_SRCALPHA |
  110. D3DPBLENDCAPS_INVSRCALPHA |
  111. D3DPBLENDCAPS_DESTALPHA |
  112. D3DPBLENDCAPS_INVDESTALPHA |
  113. D3DPBLENDCAPS_DESTCOLOR |
  114. D3DPBLENDCAPS_INVDESTCOLOR |
  115. D3DPBLENDCAPS_SRCALPHASAT ;
  116. rgbDevDesc.dpcTriCaps.dwAlphaCmpCaps =
  117. rgbDevDesc.dpcTriCaps.dwZCmpCaps;
  118. rgbDevDesc.dpcTriCaps.dwShadeCaps =
  119. D3DPSHADECAPS_COLORFLATRGB |
  120. D3DPSHADECAPS_COLORGOURAUDRGB |
  121. D3DPSHADECAPS_SPECULARFLATRGB |
  122. D3DPSHADECAPS_SPECULARGOURAUDRGB |
  123. D3DPSHADECAPS_ALPHAFLATBLEND |
  124. D3DPSHADECAPS_ALPHAGOURAUDBLEND |
  125. D3DPSHADECAPS_FOGFLAT |
  126. D3DPSHADECAPS_FOGGOURAUD ;
  127. rgbDevDesc.dpcTriCaps.dwTextureCaps =
  128. D3DPTEXTURECAPS_PERSPECTIVE |
  129. D3DPTEXTURECAPS_POW2 |
  130. D3DPTEXTURECAPS_ALPHA |
  131. D3DPTEXTURECAPS_TRANSPARENCY |
  132. D3DPTEXTURECAPS_ALPHAPALETTE |
  133. D3DPTEXTURECAPS_BORDER |
  134. D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
  135. D3DPTEXTURECAPS_ALPHAPALETTE ;
  136. rgbDevDesc.dpcTriCaps.dwTextureFilterCaps =
  137. D3DPTFILTERCAPS_NEAREST |
  138. D3DPTFILTERCAPS_LINEAR |
  139. D3DPTFILTERCAPS_MIPNEAREST |
  140. D3DPTFILTERCAPS_MIPLINEAR |
  141. D3DPTFILTERCAPS_LINEARMIPNEAREST |
  142. D3DPTFILTERCAPS_LINEARMIPLINEAR |
  143. D3DPTFILTERCAPS_MINFPOINT |
  144. D3DPTFILTERCAPS_MINFLINEAR |
  145. D3DPTFILTERCAPS_MIPFPOINT |
  146. D3DPTFILTERCAPS_MIPFLINEAR |
  147. D3DPTFILTERCAPS_MAGFPOINT |
  148. D3DPTFILTERCAPS_MAGFLINEAR ;
  149. rgbDevDesc.dpcTriCaps.dwTextureBlendCaps =
  150. D3DPTBLENDCAPS_DECAL |
  151. D3DPTBLENDCAPS_MODULATE |
  152. D3DPTBLENDCAPS_DECALALPHA |
  153. D3DPTBLENDCAPS_MODULATEALPHA |
  154. // D3DPTBLENDCAPS_DECALMASK |
  155. // D3DPTBLENDCAPS_MODULATEMASK |
  156. D3DPTBLENDCAPS_COPY |
  157. D3DPTBLENDCAPS_ADD ;
  158. rgbDevDesc.dpcTriCaps.dwTextureAddressCaps =
  159. D3DPTADDRESSCAPS_WRAP |
  160. D3DPTADDRESSCAPS_MIRROR |
  161. D3DPTADDRESSCAPS_CLAMP |
  162. D3DPTADDRESSCAPS_BORDER |
  163. D3DPTADDRESSCAPS_INDEPENDENTUV ;
  164. rgbDevDesc.dpcTriCaps.dwStippleWidth = 4;
  165. rgbDevDesc.dpcTriCaps.dwStippleHeight = 4;
  166. // line caps - copy tricaps and modify
  167. memcpy( &rgbDevDesc.dpcLineCaps, &rgbDevDesc.dpcTriCaps, sizeof(D3DPRIMCAPS) );
  168. rgbDevDesc.dwDeviceRenderBitDepth = DDBD_8 | DDBD_16 | DDBD_24 | DDBD_32;
  169. rgbDevDesc.dwDeviceZBufferBitDepth = D3DSWRASTERIZER_ZBUFFERBITDEPTHFLAGS;
  170. // DX5 stuff (should be in sync with the extended caps reported below)
  171. rgbDevDesc.dwMinTextureWidth = 1;
  172. rgbDevDesc.dwMaxTextureWidth = 1024;
  173. rgbDevDesc.dwMinTextureHeight = 1;
  174. rgbDevDesc.dwMaxTextureHeight = 1024;
  175. //
  176. // set extended caps
  177. //
  178. OptSwExtCaps.dwSize = sizeof(OptSwExtCaps);
  179. OptSwExtCaps.dwMinTextureWidth = 1;
  180. OptSwExtCaps.dwMaxTextureWidth = 1024;
  181. OptSwExtCaps.dwMinTextureHeight = 1;
  182. OptSwExtCaps.dwMaxTextureHeight = 1024;
  183. OptSwExtCaps.dwMinStippleWidth = 0; // stipple unsupported
  184. OptSwExtCaps.dwMaxStippleWidth = 0;
  185. OptSwExtCaps.dwMinStippleHeight = 0;
  186. OptSwExtCaps.dwMaxStippleHeight = 0;
  187. OptSwExtCaps.dwMaxTextureRepeat = 256;
  188. OptSwExtCaps.dwMaxTextureAspectRatio = 0; // no limit
  189. OptSwExtCaps.dwMaxAnisotropy = 1;
  190. OptSwExtCaps.dvGuardBandLeft = -4096.f;
  191. OptSwExtCaps.dvGuardBandTop = -4096.f;
  192. OptSwExtCaps.dvGuardBandRight = 4095.f;
  193. OptSwExtCaps.dvGuardBandBottom = 4095.f;
  194. OptSwExtCaps.dvExtentsAdjust = 0.; // AA kernel is 1.0 x 1.0
  195. OptSwExtCaps.dwStencilCaps =
  196. D3DSTENCILCAPS_KEEP |
  197. D3DSTENCILCAPS_ZERO |
  198. D3DSTENCILCAPS_REPLACE|
  199. D3DSTENCILCAPS_INCRSAT|
  200. D3DSTENCILCAPS_DECRSAT|
  201. D3DSTENCILCAPS_INVERT |
  202. D3DSTENCILCAPS_INCR |
  203. D3DSTENCILCAPS_DECR;
  204. OptSwExtCaps.dwFVFCaps = 8;
  205. OptSwExtCaps.dwTextureOpCaps =
  206. D3DTEXOPCAPS_DISABLE |
  207. D3DTEXOPCAPS_SELECTARG1 |
  208. D3DTEXOPCAPS_SELECTARG2 |
  209. D3DTEXOPCAPS_MODULATE |
  210. D3DTEXOPCAPS_MODULATE2X |
  211. D3DTEXOPCAPS_MODULATE4X |
  212. D3DTEXOPCAPS_ADD |
  213. D3DTEXOPCAPS_ADDSIGNED |
  214. // D3DTEXOPCAPS_ADDSIGNED2X |
  215. // D3DTEXOPCAPS_SUBTRACT |
  216. // D3DTEXOPCAPS_ADDSMOOTH |
  217. D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
  218. D3DTEXOPCAPS_BLENDTEXTUREALPHA |
  219. D3DTEXOPCAPS_BLENDFACTORALPHA |
  220. D3DTEXOPCAPS_BLENDTEXTUREALPHAPM ;
  221. // D3DTEXOPCAPS_BLENDCURRENTALPHA |
  222. // D3DTEXOPCAPS_PREMODULATE |
  223. // D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
  224. // D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
  225. // D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
  226. // D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
  227. OptSwExtCaps.wMaxTextureBlendStages = 8;
  228. OptSwExtCaps.wMaxSimultaneousTextures = 8;
  229. // DX7
  230. OptSwExtCaps.dwMaxActiveLights = 0;
  231. OptSwExtCaps.dvMaxVertexW = 10000.;
  232. OptSwExtCaps.wMaxUserClipPlanes = 0;
  233. OptSwExtCaps.wMaxVertexBlendMatrices = 0;
  234. OptSwExtCaps.dwVertexProcessingCaps = 0;
  235. OptSwExtCaps.dwReserved1 = 0;
  236. OptSwExtCaps.dwReserved2 = 0;
  237. OptSwExtCaps.dwReserved3 = 0;
  238. OptSwExtCaps.dwReserved4 = 0;
  239. g_bFilledRGBCaps = TRUE;
  240. }
  241. //----------------------------------------------------------------------------
  242. //
  243. // SwHalProvider::QueryInterface
  244. //
  245. // Internal interface, no need to implement.
  246. //
  247. //----------------------------------------------------------------------------
  248. STDMETHODIMP SwHalProvider::QueryInterface(THIS_ REFIID riid, LPVOID* ppvObj)
  249. {
  250. *ppvObj = NULL;
  251. return E_NOINTERFACE;
  252. }
  253. //----------------------------------------------------------------------------
  254. //
  255. // SwHalProvider::AddRef
  256. //
  257. // Static implementation, no real refcount.
  258. //
  259. //----------------------------------------------------------------------------
  260. STDMETHODIMP_(ULONG) SwHalProvider::AddRef(THIS)
  261. {
  262. return 1;
  263. }
  264. //----------------------------------------------------------------------------
  265. //
  266. // SwHalProvider::Release
  267. //
  268. // Static implementation, no real refcount.
  269. //
  270. //----------------------------------------------------------------------------
  271. STDMETHODIMP_(ULONG) SwHalProvider::Release(THIS)
  272. {
  273. return 0;
  274. }
  275. //----------------------------------------------------------------------------
  276. //
  277. // SwHalProvider::GetCaps
  278. //
  279. // Returns software rasterizer caps.
  280. //
  281. //----------------------------------------------------------------------------
  282. STDMETHODIMP
  283. OptRastHalProvider::GetCaps(THIS_
  284. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  285. LPD3DDEVICEDESC7 pHwDesc,
  286. LPD3DDEVICEDESC7 pHelDesc,
  287. DWORD dwVersion)
  288. {
  289. *pHwDesc = g_nullDevDesc;
  290. if( g_bFilledRGBCaps == FALSE )
  291. {
  292. FillOutDeviceCaps();
  293. // add extended caps to rgbDevDesc
  294. D3DDeviceDescConvert(&rgbDevDesc,NULL,&OptSwExtCaps);
  295. }
  296. *pHelDesc = rgbDevDesc;
  297. return D3D_OK;
  298. }
  299. //----------------------------------------------------------------------------
  300. //
  301. // OptRastHalProvider::GetInterface
  302. //
  303. // Returns driver interface data for opt rast.
  304. //
  305. //----------------------------------------------------------------------------
  306. static D3DHAL_GLOBALDRIVERDATA SwDriverData =
  307. {
  308. sizeof(D3DHAL_GLOBALDRIVERDATA),
  309. // The rest is filled in at runtime.
  310. };
  311. static D3DHAL_CALLBACKS OptRastCallbacksC =
  312. {
  313. sizeof(D3DHAL_CALLBACKS),
  314. RastContextCreateC,
  315. RastContextDestroy,
  316. NULL,
  317. NULL,
  318. NULL,
  319. NULL,
  320. RastRenderState,
  321. RastRenderPrimitive,
  322. NULL,
  323. RastTextureCreate,
  324. RastTextureDestroy,
  325. NULL,
  326. RastTextureGetSurf,
  327. // All others NULL.
  328. };
  329. static D3DHAL_CALLBACKS OptRastCallbacksMMX =
  330. {
  331. sizeof(D3DHAL_CALLBACKS),
  332. RastContextCreateMMX,
  333. RastContextDestroy,
  334. NULL,
  335. NULL,
  336. NULL,
  337. NULL,
  338. RastRenderState,
  339. RastRenderPrimitive,
  340. NULL,
  341. RastTextureCreate,
  342. RastTextureDestroy,
  343. NULL,
  344. RastTextureGetSurf,
  345. // All others NULL.
  346. };
  347. static D3DHAL_CALLBACKS OptRastCallbacksMMXAsRGB =
  348. {
  349. sizeof(D3DHAL_CALLBACKS),
  350. RastContextCreateMMXAsRGB,
  351. RastContextDestroy,
  352. NULL,
  353. NULL,
  354. NULL,
  355. NULL,
  356. RastRenderState,
  357. RastRenderPrimitive,
  358. NULL,
  359. RastTextureCreate,
  360. RastTextureDestroy,
  361. NULL,
  362. RastTextureGetSurf,
  363. // All others NULL.
  364. };
  365. static D3DHAL_CALLBACKS2 OptRastCallbacks2 =
  366. {
  367. sizeof(D3DHAL_CALLBACKS2),
  368. D3DHAL2_CB32_SETRENDERTARGET |
  369. D3DHAL2_CB32_DRAWONEPRIMITIVE |
  370. D3DHAL2_CB32_DRAWONEINDEXEDPRIMITIVE |
  371. D3DHAL2_CB32_DRAWPRIMITIVES,
  372. RastSetRenderTarget,
  373. NULL,
  374. RastDrawOnePrimitive,
  375. RastDrawOneIndexedPrimitive,
  376. RastDrawPrimitives
  377. };
  378. static D3DHAL_CALLBACKS3 OptRastCallbacks3 =
  379. {
  380. sizeof(D3DHAL_CALLBACKS3),
  381. D3DHAL3_CB32_VALIDATETEXTURESTAGESTATE |
  382. D3DHAL3_CB32_DRAWPRIMITIVES2,
  383. NULL, // Clear2
  384. NULL, //lpvReserved
  385. RastValidateTextureStageState,
  386. RastDrawPrimitives2,
  387. };
  388. static void DevDesc7ToDevDescV1( D3DDEVICEDESC_V1 *pOut, D3DDEVICEDESC7 *pIn )
  389. {
  390. // These fields are not available in D3DDEVICEDESC7.
  391. // Zeroing them out, the front-end should not be using them
  392. // DWORD dwFlags
  393. // D3DCOLORMODEL dcmColorModel
  394. // D3DTRANSFORMCAPS dtcTransformCaps
  395. // BOOL bClipping
  396. // D3DLIGHTINGCAPS dlcLightingCaps
  397. // DWORD dwMaxBufferSize
  398. // DWORD dwMaxVertexCount
  399. // DWORD dwMinStippleWidth, dwMaxStippleWidth
  400. // DWORD dwMinStippleHeight, dwMaxStippleHeight;
  401. //
  402. ZeroMemory( pOut, sizeof( D3DDEVICEDESC_V1 ) );
  403. pOut->dwSize = sizeof( D3DDEVICEDESC_V1 );
  404. // These are available in D3DDEVICEDESC7 so copy field by field
  405. // to avoid any future problems based on the assumptions of size
  406. pOut->dwDevCaps = pIn->dwDevCaps;
  407. pOut->dpcLineCaps = pIn->dpcLineCaps;
  408. pOut->dpcTriCaps = pIn->dpcTriCaps;
  409. pOut->dwDeviceRenderBitDepth = pIn->dwDeviceRenderBitDepth;
  410. pOut->dwDeviceZBufferBitDepth = pIn->dwDeviceZBufferBitDepth;
  411. }
  412. STDMETHODIMP
  413. OptRastHalProvider::GetInterface(THIS_
  414. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  415. LPD3DHALPROVIDER_INTERFACEDATA pInterfaceData,
  416. DWORD dwVersion)
  417. {
  418. if( g_bFilledRGBCaps == FALSE )
  419. {
  420. FillOutDeviceCaps();
  421. // add extended caps to rgbDevDesc
  422. D3DDeviceDescConvert(&rgbDevDesc,NULL,&OptSwExtCaps);
  423. }
  424. //
  425. // Need to fix up SwDriverData.hwCaps (D3DDEVICEDESC) from
  426. // rgbDevDesc (D3DDEVICEDESC7)
  427. //
  428. DevDesc7ToDevDescV1( &SwDriverData.hwCaps, &rgbDevDesc );
  429. SW_RAST_TYPE RastType;
  430. switch(m_BeadSet)
  431. {
  432. default:
  433. case D3DIBS_C:
  434. RastType = SW_RAST_RGB;
  435. break;
  436. case D3DIBS_MMX:
  437. RastType = SW_RAST_MMX;
  438. break;
  439. case D3DIBS_MMXASRGB:
  440. RastType = SW_RAST_MMXASRGB;
  441. break;
  442. }
  443. // Vertex counts are left zero.
  444. SwDriverData.dwNumTextureFormats =
  445. TextureFormats(&SwDriverData.lpTextureFormats, dwVersion, RastType);
  446. SwDriverData.dwNumVertices = BASE_VERTEX_COUNT;
  447. SwDriverData.dwNumClipVertices = MAX_CLIP_VERTICES;
  448. pInterfaceData->pGlobalData = &SwDriverData;
  449. pInterfaceData->pExtCaps = &OptSwExtCaps;
  450. switch(m_BeadSet)
  451. {
  452. case D3DIBS_MMX: pInterfaceData->pCallbacks = &OptRastCallbacksMMX; break;
  453. case D3DIBS_MMXASRGB: pInterfaceData->pCallbacks = &OptRastCallbacksMMXAsRGB; break;
  454. case D3DIBS_C: pInterfaceData->pCallbacks = &OptRastCallbacksC; break;
  455. }
  456. pInterfaceData->pCallbacks2 = &OptRastCallbacks2;
  457. pInterfaceData->pCallbacks3 = &OptRastCallbacks3;
  458. pInterfaceData->pfnRastService = NULL;
  459. pInterfaceData->pfnGetDriverState = NULL;
  460. return S_OK;
  461. }
  462. //----------------------------------------------------------------------------
  463. //
  464. // OptRastHalProvider
  465. //
  466. // Constructor for OptRastHalProvider to allow a bit of private state to be
  467. // kept to indicate which optimized rasterizer is to be used.
  468. //
  469. //----------------------------------------------------------------------------
  470. OptRastHalProvider::OptRastHalProvider(THIS_
  471. DWORD BeadSet)
  472. {
  473. m_BeadSet = BeadSet;
  474. }
  475. //----------------------------------------------------------------------------
  476. //
  477. // GetSwProvider
  478. //
  479. // Returns the appropriate software HAL provider based on the given GUID.
  480. //
  481. //----------------------------------------------------------------------------
  482. static OptRastHalProvider g_OptRastHalProviderC(D3DIBS_C);
  483. static OptRastHalProvider g_OptRastHalProviderMMX(D3DIBS_MMX);
  484. static OptRastHalProvider g_OptRastHalProviderMMXAsRGB(D3DIBS_MMXASRGB);
  485. STDAPI GetSwHalProvider(REFIID riid, IHalProvider **ppHalProvider,
  486. HINSTANCE *phDll)
  487. {
  488. *phDll = NULL;
  489. if (IsEqualIID(riid, IID_IDirect3DRGBDevice))
  490. {
  491. *ppHalProvider = &g_OptRastHalProviderC;
  492. }
  493. else if (IsEqualIID(riid, IID_IDirect3DMMXDevice))
  494. {
  495. *ppHalProvider = &g_OptRastHalProviderMMX;
  496. }
  497. else if (IsEqualIID(riid, IID_IDirect3DMMXAsRGBDevice))
  498. {
  499. *ppHalProvider = &g_OptRastHalProviderMMXAsRGB;
  500. }
  501. else if (IsEqualIID(riid, IID_IDirect3DRefDevice) ||
  502. IsEqualIID(riid, IID_IDirect3DNullDevice))
  503. {
  504. // try to get provider from external DLL ref device
  505. PFNGETREFHALPROVIDER pfnGetRefHalProvider;
  506. if (NULL == (pfnGetRefHalProvider =
  507. (PFNGETREFHALPROVIDER)LoadReferenceDeviceProc("GetRefHalProvider")))
  508. {
  509. *ppHalProvider = NULL;
  510. return E_NOINTERFACE;
  511. }
  512. D3D_INFO(0,"GetSwHalProvider: getting provider from d3dref");
  513. pfnGetRefHalProvider(riid, ppHalProvider, phDll);
  514. }
  515. else
  516. {
  517. *ppHalProvider = NULL;
  518. return E_NOINTERFACE;
  519. }
  520. // As a debugging aid, allow the particular rasterizer to be forced
  521. // via a registry setting. This lets a developer run an app on any
  522. // rasterizer regardless of what it asks for.
  523. LONG iRet;
  524. HKEY hKey;
  525. iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, RESPATH, 0, KEY_READ, &hKey);
  526. if (iRet == ERROR_SUCCESS)
  527. {
  528. DWORD dwData, dwType;
  529. DWORD dwDataSize;
  530. dwDataSize = sizeof(dwData);
  531. iRet = RegQueryValueEx(hKey, "ForceRgbRasterizer", NULL,
  532. &dwType, (BYTE *)&dwData, &dwDataSize);
  533. if (iRet == ERROR_SUCCESS &&
  534. dwType == REG_DWORD &&
  535. dwDataSize == sizeof(dwData))
  536. {
  537. switch(dwData)
  538. {
  539. case 1:
  540. case 2:
  541. *ppHalProvider = &g_OptRastHalProviderC;
  542. break;
  543. case 3:
  544. *ppHalProvider = &g_OptRastHalProviderMMX;
  545. break;
  546. case 4:
  547. case 5:
  548. // try to get provider from external DLL ref device
  549. PFNGETREFHALPROVIDER pfnGetRefHalProvider;
  550. if (NULL == (pfnGetRefHalProvider =
  551. (PFNGETREFHALPROVIDER)LoadReferenceDeviceProc("GetRefHalProvider")))
  552. {
  553. *ppHalProvider = NULL;
  554. return E_NOINTERFACE;
  555. }
  556. D3D_INFO(0,"GetSwHalProvider: getting provider from d3dref");
  557. pfnGetRefHalProvider(riid, ppHalProvider, phDll);
  558. break;
  559. case 6:
  560. *ppHalProvider = &g_OptRastHalProviderMMXAsRGB;
  561. break;
  562. case 0:
  563. // no override for 0
  564. break;
  565. default:
  566. D3D_ERR("(Rast) Unknown ForceRgbRasterizer setting - no force");
  567. break;
  568. }
  569. D3D_INFO(0, "(Rast) ForceRgbRasterizer to %d", dwData);
  570. }
  571. RegCloseKey(hKey);
  572. }
  573. return S_OK;
  574. }
  575. STDAPI GetSwTextureFormats(REFCLSID riid, LPDDSURFACEDESC* lplpddsd, DWORD dwD3DDeviceVersion) {
  576. // assumes it can't get an invalid RIID.
  577. if(IsEqualIID(riid, IID_IDirect3DHALDevice) ||
  578. IsEqualIID(riid, IID_IDirect3DTnLHalDevice) ||
  579. IsEqualIID(riid, IID_IDirect3DRampDevice))
  580. {
  581. D3D_WARN(2,"(Rast) GetSWTextureFormats Internal Error: HAL and Ramp GUIDs are not valid args");
  582. *lplpddsd=NULL;
  583. return 0;
  584. }
  585. if(IsEqualIID(riid, IID_IDirect3DRefDevice) ||
  586. IsEqualIID(riid, IID_IDirect3DNullDevice))
  587. {
  588. // try to get provider from external DLL ref device
  589. PFNGETREFTEXTUREFORMATS pfnGetRefTextureFormats;
  590. if (NULL == (pfnGetRefTextureFormats =
  591. (PFNGETREFTEXTUREFORMATS)LoadReferenceDeviceProc("GetRefTextureFormats")))
  592. {
  593. D3D_WARN(2,"(Rast) GetSWTextureFormats Internal Error: d3dref.dll not found");
  594. *lplpddsd=NULL;
  595. return 0;
  596. }
  597. D3D_INFO(0,"GetSwHalProvider: getting provider from d3dref");
  598. return pfnGetRefTextureFormats(riid, lplpddsd, dwD3DDeviceVersion);
  599. }
  600. SW_RAST_TYPE RastType = SW_RAST_RGB;
  601. if (IsEqualIID(riid, IID_IDirect3DMMXDevice))
  602. {
  603. RastType = SW_RAST_MMX;
  604. }
  605. else if (IsEqualIID(riid, IID_IDirect3DMMXAsRGBDevice))
  606. {
  607. RastType = SW_RAST_MMXASRGB;
  608. }
  609. return TextureFormats(lplpddsd,dwD3DDeviceVersion, RastType);
  610. }
  611. STDAPI GetSwZBufferFormats(REFCLSID riid, DDPIXELFORMAT **ppDDPF) {
  612. // assumes it can't get an invalid RIID.
  613. if(IsEqualIID(riid, IID_IDirect3DHALDevice) ||
  614. IsEqualIID(riid, IID_IDirect3DTnLHalDevice) ||
  615. IsEqualIID(riid, IID_IDirect3DRampDevice))
  616. {
  617. D3D_WARN(2,"(Rast) GetSWZBufferFormats Internal Error: HAL and Ramp GUIDs are not valid args");
  618. *ppDDPF=NULL;
  619. return 0;
  620. }
  621. if (IsEqualIID(riid, IID_IDirect3DRefDevice) ||
  622. IsEqualIID(riid, IID_IDirect3DNullDevice))
  623. {
  624. // try to get Z buffer formats from external DLL ref device
  625. PFNGETREFZBUFFERFORMATS pfnGetRefZBufferFormats;
  626. if (NULL == (pfnGetRefZBufferFormats =
  627. (PFNGETREFZBUFFERFORMATS)LoadReferenceDeviceProc("GetRefZBufferFormats")))
  628. {
  629. D3D_WARN(2,"(Rast) GetSWZBufferFormats Internal Error: d3dref.dll not found");
  630. *ppDDPF=NULL;
  631. return 0;
  632. }
  633. return pfnGetRefZBufferFormats(riid, ppDDPF);
  634. }
  635. return ZBufferFormats(ppDDPF);
  636. }