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.

309 lines
8.6 KiB

  1. #include "rgb_pch.h"
  2. #pragma hdrstop
  3. namespace RGB_RAST_LIB_NAMESPACE
  4. {
  5. // MMX available
  6. #define D3DCPU_MMX 0x00000001L
  7. // FCOMI and CMOV are both supported
  8. #define D3DCPU_FCOMICMOV 0x00000002L
  9. // Reads block until satisfied
  10. #define D3DCPU_BLOCKINGREAD 0x00000004L
  11. // Extended 3D support available
  12. #define D3DCPU_X3D 0x00000008L
  13. // Pentium II CPU
  14. #define D3DCPU_PII 0x000000010L
  15. // Streaming SIMD Extensions (aka Katmai) CPU
  16. #define D3DCPU_SSE 0x000000020L
  17. // Streaming SIMD2 Extensions (aka Willamete) CPU
  18. #define D3DCPU_WLMT 0x000000040L
  19. //---------------------------------------------------------------------
  20. BOOL
  21. IsWin95(void)
  22. {
  23. OSVERSIONINFO osvi;
  24. ZeroMemory(&osvi, sizeof(osvi));
  25. osvi.dwOSVersionInfoSize = sizeof(osvi);
  26. if (!GetVersionEx(&osvi))
  27. {
  28. return TRUE;
  29. }
  30. if ( VER_PLATFORM_WIN32_WINDOWS == osvi.dwPlatformId )
  31. {
  32. if( ( osvi.dwMajorVersion > 4UL ) ||
  33. ( ( osvi.dwMajorVersion == 4UL ) &&
  34. ( osvi.dwMinorVersion >= 10UL ) &&
  35. ( LOWORD( osvi.dwBuildNumber ) >= 1373 ) ) )
  36. {
  37. // is Win98
  38. return FALSE;
  39. }
  40. else
  41. {
  42. // is Win95
  43. return TRUE;
  44. }
  45. }
  46. else if ( VER_PLATFORM_WIN32_NT == osvi.dwPlatformId )
  47. {
  48. return FALSE;
  49. }
  50. return TRUE;
  51. }
  52. #if defined(_X86_)
  53. // --------------------------------------------------------------------------
  54. // Detect 3D extensions
  55. // --------------------------------------------------------------------------
  56. static BOOL _asm_isX3D()
  57. {
  58. DWORD retval = 0;
  59. _asm
  60. {
  61. pushad ; CPUID trashes lots - save everything
  62. mov eax,80000000h ; Check for extended CPUID support
  63. ;;; We need to upgrade our compiler
  64. ;;; CPUID == 0f,a2
  65. _emit 0x0f
  66. _emit 0xa2
  67. cmp eax,80000001h ; Jump if no extended CPUID
  68. jb short done ;
  69. mov eax,80000001h ; Check for feature
  70. ;;; CPUID == 0f,a2
  71. _emit 0x0f
  72. _emit 0xa2
  73. xor eax,eax ;
  74. test edx,80000000h ;
  75. setnz al ;
  76. mov retval,eax ;
  77. done:
  78. popad ; Restore everything
  79. };
  80. return retval;
  81. }
  82. static BOOL _asm_isMMX()
  83. {
  84. DWORD retval;
  85. _asm
  86. {
  87. xor eax,eax ; Clear out eax for return value
  88. pushad ; CPUID trashes lots - save everything
  89. mov eax,1 ; Check for MMX support
  90. ;;; We need to upgrade our compiler
  91. ;;; CPUID == 0f,a2
  92. _emit 0x0f
  93. _emit 0xa2
  94. test edx,00800000h ; Set flags before restoring registers
  95. popad ; Restore everything
  96. setnz al ; Set return value
  97. mov retval, eax
  98. };
  99. return retval;
  100. }
  101. static BOOL isX3Dprocessor(void)
  102. {
  103. __try
  104. {
  105. if( _asm_isX3D() )
  106. {
  107. return TRUE;
  108. }
  109. }
  110. __except(GetExceptionCode() == STATUS_ILLEGAL_INSTRUCTION ?
  111. EXCEPTION_EXECUTE_HANDLER :
  112. EXCEPTION_CONTINUE_SEARCH)
  113. {
  114. }
  115. return FALSE;
  116. }
  117. //---------------------------------------------------------------------
  118. // Detects Intel SSE processor
  119. //
  120. #pragma optimize("", off)
  121. #define CPUID _asm _emit 0x0f _asm _emit 0xa2
  122. #define SSE_PRESENT 0x02000000 // bit number 25
  123. #define WNI_PRESENT 0x04000000 // bit number 26
  124. static BOOL isMMXprocessor(void)
  125. {
  126. __try
  127. {
  128. if( _asm_isMMX() )
  129. {
  130. // Emit an emms instruction.
  131. // This file needs to compile for non-Pentium
  132. // processors
  133. // so we can't use use inline asm since we're in the
  134. // wrong
  135. // processor mode.
  136. __asm __emit 0xf;
  137. __asm __emit 0x77;
  138. return TRUE;
  139. }
  140. }
  141. __except(GetExceptionCode() == STATUS_ILLEGAL_INSTRUCTION ?
  142. EXCEPTION_EXECUTE_HANDLER :
  143. EXCEPTION_CONTINUE_SEARCH)
  144. {
  145. }
  146. return FALSE;
  147. }
  148. DWORD IsIntelSSEProcessor(void)
  149. {
  150. DWORD retval = 0;
  151. DWORD RegisterEAX;
  152. DWORD RegisterEDX;
  153. char VendorId[12];
  154. const char IntelId[13]="GenuineIntel";
  155. __try
  156. {
  157. _asm {
  158. xor eax,eax
  159. CPUID
  160. mov RegisterEAX, eax
  161. mov dword ptr VendorId, ebx
  162. mov dword ptr VendorId+4, edx
  163. mov dword ptr VendorId+8, ecx
  164. }
  165. } __except (1)
  166. {
  167. return retval;
  168. }
  169. // make sure EAX is > 0 which means the chip
  170. // supports a value >=1. 1 = chip info
  171. if (RegisterEAX == 0)
  172. return retval;
  173. // this CPUID can't fail if the above test passed
  174. __asm {
  175. mov eax,1
  176. CPUID
  177. mov RegisterEAX,eax
  178. mov RegisterEDX,edx
  179. }
  180. if (RegisterEDX & SSE_PRESENT) {
  181. retval |= D3DCPU_SSE;
  182. }
  183. if (RegisterEDX & WNI_PRESENT) {
  184. retval |= D3DCPU_WLMT;
  185. }
  186. return retval;
  187. }
  188. #pragma optimize("", on)
  189. #ifndef PF_XMMI_INSTRUCTIONS_AVAILABLE
  190. #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
  191. #endif
  192. #ifndef PF_3DNOW_INSTRUCTIONS_AVAILABLE
  193. #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
  194. #endif
  195. #ifndef PF_XMMI64_INSTRUCTIONS_AVAILABLE
  196. #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
  197. #endif
  198. static BOOL D3DIsProcessorFeaturePresent(UINT feature)
  199. {
  200. switch (feature)
  201. {
  202. case PF_MMX_INSTRUCTIONS_AVAILABLE:
  203. {
  204. return isMMXprocessor();
  205. }
  206. case PF_XMMI_INSTRUCTIONS_AVAILABLE:
  207. {
  208. if (IsWin95())
  209. return FALSE;
  210. DWORD flags = IsIntelSSEProcessor();
  211. return flags & D3DCPU_SSE;
  212. }
  213. case PF_3DNOW_INSTRUCTIONS_AVAILABLE: return isX3Dprocessor();
  214. case PF_XMMI64_INSTRUCTIONS_AVAILABLE:
  215. {
  216. if (IsWin95())
  217. return FALSE;
  218. DWORD flags = IsIntelSSEProcessor();
  219. return flags & D3DCPU_WLMT;
  220. }
  221. default: return FALSE;
  222. }
  223. }
  224. #endif // _X86_
  225. const UINT CRGBContext::c_uiBegan( 1);
  226. DWORD CRGBContext::DetectBeadSet( void) throw()
  227. {
  228. #if defined(_X86_)
  229. if( D3DIsProcessorFeaturePresent( PF_MMX_INSTRUCTIONS_AVAILABLE))
  230. return D3DIBS_MMXASRGB;
  231. #endif
  232. return D3DIBS_C;
  233. }
  234. // TConstDP2Bindings type MUST be updated with size of this array,
  235. // unfortunately.
  236. const CRGBContext::TDP2Bindings CRGBContext::c_DP2Bindings=
  237. {
  238. D3DDP2OP_VIEWPORTINFO, DP2ViewportInfo,
  239. D3DDP2OP_WINFO, DP2WInfo,
  240. D3DDP2OP_RENDERSTATE, DP2RenderState,
  241. D3DDP2OP_TEXTURESTAGESTATE, DP2TextureStageState,
  242. D3DDP2OP_CLEAR, DP2Clear,
  243. D3DDP2OP_SETRENDERTARGET, DP2SetRenderTarget,
  244. D3DDP2OP_SETVERTEXSHADER, DP2SetVertexShader,
  245. D3DDP2OP_SETSTREAMSOURCE, DP2SetStreamSource,
  246. D3DDP2OP_SETSTREAMSOURCEUM, DP2SetStreamSourceUM,
  247. D3DDP2OP_SETINDICES, DP2SetIndices,
  248. D3DDP2OP_DRAWPRIMITIVE, DP2DrawPrimitive,
  249. D3DDP2OP_DRAWPRIMITIVE2, DP2DrawPrimitive2,
  250. D3DDP2OP_DRAWINDEXEDPRIMITIVE, DP2DrawIndexedPrimitive,
  251. D3DDP2OP_DRAWINDEXEDPRIMITIVE2, DP2DrawIndexedPrimitive2,
  252. D3DDP2OP_CLIPPEDTRIANGLEFAN, DP2ClippedTriangleFan,
  253. D3DDP2OP_SETPALETTE, DP2SetPalette,
  254. D3DDP2OP_UPDATEPALETTE, DP2UpdatePalette
  255. };
  256. // TConstRecDP2Bindings type MUST be updated with size of this array,
  257. // unfortunately.
  258. const CRGBContext::TRecDP2Bindings CRGBContext::c_RecDP2Bindings=
  259. {
  260. D3DDP2OP_VIEWPORTINFO, RecDP2ViewportInfo,
  261. D3DDP2OP_WINFO, RecDP2WInfo,
  262. D3DDP2OP_RENDERSTATE, RecDP2RenderState,
  263. D3DDP2OP_TEXTURESTAGESTATE, RecDP2TextureStageState,
  264. D3DDP2OP_SETVERTEXSHADER, RecDP2SetVertexShader,
  265. D3DDP2OP_SETSTREAMSOURCE, RecDP2SetStreamSource,
  266. D3DDP2OP_SETINDICES, RecDP2SetIndices
  267. };
  268. }