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.

147 lines
5.8 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. #ifndef VERTEXSHADERDX8_H
  3. #define VERTEXSHADERDX8_H
  4. #ifdef _WIN32
  5. #pragma once
  6. #endif
  7. #include "shaderapi/ishaderapi.h"
  8. #include "datacache/idatacache.h"
  9. #include "locald3dtypes.h"
  10. // uncomment to get dynamic compilation for HLSL shaders
  11. // **IMPORTANT**: if you are trying to use DYNAMIC_SHADER_COMPILE in a RELEASE build, you *must* modify the .vpc file to re-enable the /FC compiler option, otherwise the __FILE__ macro won't work properly in
  12. // GetShaderSourcePath() and shader files won't be found.
  13. //#define DYNAMIC_SHADER_COMPILE
  14. // uncomment to get spew about what combos are being compiled.
  15. //#define DYNAMIC_SHADER_COMPILE_VERBOSE
  16. // uncomment to hide combos that are 0 (requires VERBOSE above)
  17. //#define DYNAMIC_SHADER_COMPILE_THIN
  18. // Uncomment to use remoteshadercompiler.exe as a shader compile server
  19. // Must also set mat_remoteshadercompile to remote shader compile machine name
  20. //#define REMOTE_DYNAMIC_SHADER_COMPILE
  21. // uncomment and fill in with a path to use a specific set of shader source files. Meant for network use.
  22. // PC path format is of style "\\\\somemachine\\sourcetreeshare\\materialsystem\\stdshaders"
  23. // Mac path format is of style "/Volumes/jasonm/portal2/staging/src/materialsystem/stdshaders"
  24. // Linux path format is of style "/home/mariod/p4/csgo/trunk/src/materialsystem/stdshaders"
  25. // Xbox is not supported. Xbox's ability to see PC is not supported by XDK in Vista.
  26. //#define DYNAMIC_SHADER_COMPILE_CUSTOM_PATH "/Volumes/Data/p4/csgo/staging/src/materialsystem/stdshaders"
  27. //#define SHADER_COMBO_SPEW_VERBOSE 1
  28. // uncomment to get disassembled (asm) shader code in your game dir as *.asm
  29. //#define DYNAMIC_SHADER_COMPILE_WRITE_ASSEMBLY
  30. // uncomment to get disassembled (asm) shader code in your game dir as *.asm
  31. //#define WRITE_ASSEMBLY
  32. #if defined( DYNAMIC_SHADER_COMPILE ) && defined( _X360 ) && !defined( X360_LINK_WITH_SHADER_COMPILE )
  33. // automatically turn on X360_LINK_WITH_SHADER_COMPILE with dynamic shader compile
  34. #define X360_LINK_WITH_SHADER_COMPILE 1
  35. #endif
  36. #if defined( _X360 )
  37. // Define this to link shader compilation code from D3DX9.LIB
  38. //#define X360_LINK_WITH_SHADER_COMPILE 1
  39. #endif
  40. #if defined( X360_LINK_WITH_SHADER_COMPILE ) && defined( _CERT )
  41. #error "Don't ship with X360_LINK_WITH_SHADER_COMPILE defined!! It causes 2MB+ DLL bloat. Only define it while revving XDKs."
  42. #endif
  43. //-----------------------------------------------------------------------------
  44. // Vertex + pixel shader manager
  45. //-----------------------------------------------------------------------------
  46. abstract_class IShaderManager
  47. {
  48. protected:
  49. // The current vertex and pixel shader index
  50. int m_nVertexShaderIndex;
  51. int m_nPixelShaderIndex;
  52. public:
  53. // Initialize, shutdown
  54. virtual void Init() = 0;
  55. virtual void Shutdown() = 0;
  56. // Compiles vertex shaders
  57. virtual IShaderBuffer *CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) = 0;
  58. // New version of these methods [dx10 port]
  59. virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) = 0;
  60. virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) = 0;
  61. virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) = 0;
  62. virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) = 0;
  63. // Creates vertex, pixel shaders
  64. virtual VertexShader_t CreateVertexShader( const char *pVertexShaderFile, int nStaticVshIndex = 0, char *debugLabel = NULL ) = 0;
  65. virtual PixelShader_t CreatePixelShader( const char *pPixelShaderFile, int nStaticPshIndex = 0, char *debugLabel = NULL ) = 0;
  66. // Sets which dynamic version of the vertex + pixel shader to use
  67. FORCEINLINE void SetVertexShaderIndex( int vshIndex );
  68. FORCEINLINE void SetPixelShaderIndex( int pshIndex );
  69. // Sets the vertex + pixel shader render state
  70. virtual void SetVertexShader( VertexShader_t shader ) = 0;
  71. virtual void SetPixelShader( PixelShader_t shader ) = 0;
  72. virtual void SetPixelShaderState_Internal( HardwareShader_t shader, DataCacheHandle_t hCachedShader ) = 0;
  73. virtual void SetVertexShaderState_Internal( HardwareShader_t shader, DataCacheHandle_t hCachedShader ) = 0;
  74. // Resets the vertex + pixel shader state
  75. virtual void ResetShaderState() = 0;
  76. // Flushes all shaders so they are reloaded+recompiled (does nothing unless dynamic shader compile is enabled)
  77. virtual void FlushShaders() = 0;
  78. // Returns the current vertex + pixel shaders
  79. virtual void *GetCurrentVertexShader() = 0;
  80. virtual void *GetCurrentPixelShader() = 0;
  81. virtual void ClearVertexAndPixelShaderRefCounts() = 0;
  82. virtual void PurgeUnusedVertexAndPixelShaders() = 0;
  83. // The low-level dx call to set the vertex shader state
  84. virtual void BindVertexShader( VertexShaderHandle_t shader ) = 0;
  85. virtual void BindPixelShader( PixelShaderHandle_t shader ) = 0;
  86. virtual void AddShaderComboInformation( const ShaderComboSemantics_t *pSemantics ) = 0;
  87. #if defined( _X360 )
  88. virtual const char *GetActiveVertexShaderName() = 0;
  89. virtual const char *GetActivePixelShaderName() = 0;
  90. #endif
  91. #if defined( DX_TO_GL_ABSTRACTION ) && !defined( _GAMECONSOLE )
  92. virtual void DoStartupShaderPreloading() = 0;
  93. #endif
  94. virtual HardwareShader_t GetVertexShader( VertexShader_t vs, int dynIdx ) = 0;
  95. virtual HardwareShader_t GetPixelShader( PixelShader_t ps, int dynIdx ) = 0;
  96. };
  97. //-----------------------------------------------------------------------------
  98. //
  99. // Methods related to setting vertex + pixel shader state
  100. //
  101. //-----------------------------------------------------------------------------
  102. FORCEINLINE void IShaderManager::SetVertexShaderIndex( int vshIndex )
  103. {
  104. m_nVertexShaderIndex = vshIndex;
  105. }
  106. FORCEINLINE void IShaderManager::SetPixelShaderIndex( int pshIndex )
  107. {
  108. m_nPixelShaderIndex = pshIndex;
  109. }
  110. extern void DestroyAllVertexAndPixelShaders( void );
  111. #endif // VERTEXSHADERDX8_H