Counter Strike : Global Offensive Source Code
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.

101 lines
3.7 KiB

  1. //------------------------------------------------------------------------------
  2. // DX9AsmToGL.h
  3. //------------------------------------------------------------------------------
  4. #ifndef DX9_ASM_TO_GL_H
  5. #define DX9_ASM_TO_GL_H
  6. #define DISASM_OK 0
  7. #define DISASM_ERROR 1
  8. #define MAX_SHADER_CONSTANTS 512
  9. // option bits
  10. #define D3DToGL_OptionUseEnvParams 0x01
  11. #define D3DToGL_OptionDoFixupZ 0x02 // add insts to put Z in the right interval for GL
  12. #define D3DToGL_OptionDoFixupY 0x04 // add insts to flip the Y over for GL
  13. #define D3DToGL_OptionDoUserClipPlanes 0x08 // include OPTION vertex_program_2 and append DP4's to write into oCLP[0] and oCLP[1]
  14. #define D3DToGL_OptionSpew 0x80000000
  15. class D3DToGL_ASM
  16. {
  17. private:
  18. // Pointers for dwToken stream management
  19. uint32* m_pdwBaseToken;
  20. uint32* m_pdwNextToken;
  21. // Vertex shader or pixel shader, and version (necessary because some opcodes alias)
  22. bool m_bVertexShader;
  23. uint32 m_dwMinorVersion;
  24. uint32 m_dwMajorVersion;
  25. // Option flags
  26. bool m_bUseEnvParams; // set D3DToGL_OptionUseEnvParams in 'options' to use
  27. bool m_bDoFixupZ; // set D3DToGL_OptionDoFixupZ
  28. bool m_bDoFixupY; // set D3DToGL_OptionDoFixupZ
  29. bool m_bDoUserClipPlanes; // set D3DToGL_OptionDoUserClipPlanes
  30. bool m_bSpew; // set D3DToGL_OptionSpew
  31. // Various scratch temps needed to handle mis-matches in instruction sets between D3D and OpenGL
  32. bool m_bNeedsD2AddTemp;
  33. bool m_bNeedsNRMTemp;
  34. bool m_bDeclareAddressReg;
  35. bool m_bNeedsLerpTemp;
  36. bool m_bNeedsSinCosDeclarations;
  37. // Keep track of which vs outputs are used so we can declare them
  38. bool m_bDeclareVSOPos;
  39. bool m_bDeclareVSOFog;
  40. uint32 m_dwTexCoordOutMask;
  41. // Keep track of which temps are used so they can be declared
  42. uint32 m_dwTempUsageMask;
  43. bool m_bOutputColorRegister[2];
  44. bool m_bOutputDepthRegister;
  45. // Track constants so we know how to declare them
  46. bool m_bConstantRegisterReferenced[MAX_SHADER_CONSTANTS];
  47. bool m_bConstantRegisterDefined[MAX_SHADER_CONSTANTS];
  48. // Track sampler types when declared so we can properly decorate TEX instructions
  49. uint32 m_dwSamplerTypes[32];
  50. // Track shadow sampler usage
  51. int m_nShadowDepthSampler;
  52. bool m_bDeclareShadowOption;
  53. // Track attribute references
  54. // init to 0xFFFFFFFF (unhit)
  55. // index by (dwRegToken & D3DSP_REGNUM_MASK) in VS DCL insns
  56. // fill with (usage<<4) | (usage index).
  57. uint32 m_dwAttribMap[16];
  58. // GLSL does indentation for readability
  59. int m_NumIndentTabs;
  60. // Utilities to aid in decoding token stream
  61. uint32 GetNextToken( void );
  62. void SkipTokens( uint32 numToSkip );
  63. uint32 Opcode( uint32 dwToken );
  64. uint32 OpcodeSpecificData( uint32 dwToken );
  65. uint32 TextureType ( uint32 dwToken );
  66. uint32 GetRegType( uint32 dwRegToken );
  67. // Utilities for decoding tokens in to strings according to ASM syntax
  68. void PrintOpcode( uint32 inst, char* buff, int nBufLen );
  69. void PrintUsageAndIndexToString( uint32 dwToken, char* strUsageUsageIndexName, int nBufLen, bool bGLSL );
  70. void PrintParameterToString ( uint32 dwToken, uint32 dwSourceOrDest, char *pRegisterName, int nBufLen, bool bGLSL, int *pARLDestReg );
  71. void InsertMoveFromAddressRegister( char *pCode, int nCodeSize, int nARLComp0, int nARLComp1, int nARLComp2 );
  72. void InsertMoveInstruction( char *pCode, int nCodeSize, int nARLComponent );
  73. void FlagIndirectRegister( uint32 dwToken, int *pARLDestReg );
  74. // Utilities for decoding tokens in to strings according to GLSL syntax
  75. void OpenIntrinsic( uint32 inst, char* buff, int nBufLen );
  76. void PrintIndentation( char *pBuf, int nBufLen );
  77. public:
  78. int TranslateShader( uint32* code, char *pDisassembledCode, int nBufLen, bool *bVertexShader, uint32 options, int32 nShadowDepthSampler, char *debugLabel );
  79. };
  80. #endif // DX9_ASM_TO_GL_H