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.

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