Source code of Windows XP (NT5)
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.

167 lines
5.3 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: vvm.h
  6. * Content: Virtual Vertex Machine declarations
  7. *
  8. *
  9. ***************************************************************************/
  10. #ifndef __VVM_H__
  11. #define __VVM_H__
  12. #include "d3dhalp.h"
  13. class CVShaderCodeI;
  14. extern HRESULT ComputeShaderCodeSize(CONST DWORD* pCode, DWORD* pdwCodeOnlySize, DWORD* pdwCodeAndCommentSize,
  15. DWORD* pdwNumConstDefs);
  16. // Number of vertices in batch to process
  17. const DWORD VVMVERTEXBATCH = 16;
  18. //-----------------------------------------------------------------------------
  19. // Internal word of the vertual vertex machine
  20. //
  21. struct VVM_WORD
  22. {
  23. union
  24. {
  25. struct
  26. {
  27. D3DVALUE x, y, z, w;
  28. };
  29. D3DVALUE v[4];
  30. };
  31. };
  32. //-----------------------------------------------------------------------------
  33. struct VVM_REGISTERS
  34. {
  35. VVM_REGISTERS() {m_c = NULL;}
  36. ~VVM_REGISTERS() {delete [] m_c;}
  37. // Input registers
  38. VVM_WORD m_v[D3DVS_INPUTREG_MAX_V1_1][VVMVERTEXBATCH];
  39. // Temporary registers
  40. VVM_WORD m_r[D3DVS_TEMPREG_MAX_V1_1][VVMVERTEXBATCH];
  41. // Constant registers. Allocated dynamically, base on MaxVertexShaderConst
  42. // cap
  43. VVM_WORD* m_c;
  44. // Address registers
  45. VVM_WORD m_a[D3DVS_ADDRREG_MAX_V1_1][VVMVERTEXBATCH];
  46. // Output register file
  47. VVM_WORD m_output[3][VVMVERTEXBATCH];
  48. // Attribute register file
  49. VVM_WORD m_color[D3DVS_ATTROUTREG_MAX_V1_1][VVMVERTEXBATCH];
  50. // Output texture registers
  51. VVM_WORD m_texture[D3DVS_TCRDOUTREG_MAX_V1_1][VVMVERTEXBATCH];
  52. };
  53. //-----------------------------------------------------------------------------
  54. //
  55. // CVShaderCode: Vertex Shader Code
  56. //
  57. //-----------------------------------------------------------------------------
  58. class CVShaderCode: public CPSGPShader
  59. {
  60. public:
  61. CVShaderCode() {};
  62. virtual ~CVShaderCode() {};
  63. virtual DWORD InstCount( void ) { return 0; };
  64. virtual DWORD* InstTokens( DWORD Inst ) { return NULL; };
  65. virtual char* InstDisasm( DWORD Inst ) { return NULL; };
  66. virtual DWORD* InstComment( DWORD Inst ) { return NULL; };
  67. virtual DWORD InstCommentSize( DWORD Inst ) { return 0; };
  68. };
  69. //-----------------------------------------------------------------------------
  70. // Vertex Virtual Machine object
  71. //
  72. //-----------------------------------------------------------------------------
  73. const UINT __MAX_SRC_OPERANDS = 5;
  74. class CVertexVM
  75. {
  76. public:
  77. CVertexVM();
  78. ~CVertexVM();
  79. void Init(UINT MaxVertexShaderConst);
  80. // Parses binary shader representatio, compiles is and returns
  81. // compiled object
  82. CVShaderCode* CreateShader(CVElement* pElements, DWORD dwNumElements,
  83. DWORD* code);
  84. HRESULT SetActiveShader(CVShaderCode* code);
  85. CVShaderCode* GetActiveShader() {return (CVShaderCode*)m_pCurrentShader;}
  86. HRESULT ExecuteShader(LPD3DFE_PROCESSVERTICES pv, UINT vertexCount);
  87. HRESULT GetDataPointer(DWORD dwMemType, VVM_WORD ** pData);
  88. // Set internal registers to user data
  89. HRESULT SetData(DWORD RegType, DWORD start, DWORD count, LPVOID buffer);
  90. // Get data from internal registers
  91. HRESULT GetData(DWORD RegType, DWORD start, DWORD count, LPVOID buffer);
  92. VVM_REGISTERS* GetRegisters();
  93. DWORD GetCurInstIndex() {return m_CurInstIndex; }
  94. // Number of allocated constant registers
  95. UINT m_MaxVertexShaderConst;
  96. protected:
  97. void InstMov();
  98. void InstAdd();
  99. void InstMad();
  100. void InstMul();
  101. void InstRcp();
  102. void InstRsq();
  103. void InstDP3();
  104. void InstDP4();
  105. void InstMin();
  106. void InstMax();
  107. void InstSlt();
  108. void InstSge();
  109. void InstExp();
  110. void InstLog();
  111. void InstExpP();
  112. void InstLogP();
  113. void InstLit();
  114. void InstDst();
  115. void InstFrc();
  116. void InstM4x4();
  117. void InstM4x3();
  118. void InstM3x4();
  119. void InstM3x3();
  120. void InstM3x2();
  121. void EvalDestination();
  122. void EvalSource(DWORD index);
  123. void EvalSource(DWORD index, DWORD count);
  124. VVM_WORD* GetDataAddr(DWORD dwRegType, DWORD dwElementIndex);
  125. void ValidateShader(CVShaderCodeI* shader, DWORD* orgShader);
  126. void PrintInstCount();
  127. UINT GetNumSrcOperands(UINT opcode);
  128. UINT GetInstructionLength(DWORD Inst);
  129. UINT GetRegisterUsage(UINT opcode, UINT SourceIndex);
  130. // Virtual machine registers
  131. VVM_REGISTERS m_reg;
  132. // Current shader code
  133. CVShaderCodeI* m_pCurrentShader;
  134. // Current token during parsing
  135. DWORD* m_pdwCurToken;
  136. // Pointer to destination operand
  137. VVM_WORD* m_pDest;
  138. // Offset in the register file for destination operand
  139. DWORD m_dwOffset;
  140. // Write mask for destination operand
  141. DWORD m_WriteMask;
  142. // Current instruction (about to be executed)
  143. DWORD m_CurInstIndex;
  144. // Source operands
  145. VVM_WORD m_Source[__MAX_SRC_OPERANDS][VVMVERTEXBATCH];
  146. // How many vertices to process in a batch
  147. UINT m_count;
  148. // m_count * sizeof(VVM_WORD)
  149. UINT m_BatchSize;
  150. // Initialized flags
  151. #if DBG
  152. // Constant registers
  153. BOOL m_c_initialized[D3DVS_CONSTREG_MAX_V1_1];
  154. #endif // DBG
  155. friend class D3DFE_PVFUNCSI;
  156. friend class CD3DHal;
  157. };
  158. #endif // __VVM_H__