Team Fortress 2 Source Code as on 22/4/2020
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.

105 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef SHADERAPI_GLOBAL_H
  9. #define SHADERAPI_GLOBAL_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "tier0/threadtools.h"
  14. //-----------------------------------------------------------------------------
  15. // Use this to fill in structures with the current board state
  16. //-----------------------------------------------------------------------------
  17. #ifdef _DEBUG
  18. #define DEBUG_BOARD_STATE 0
  19. #endif
  20. //-----------------------------------------------------------------------------
  21. // Forward declarations
  22. //-----------------------------------------------------------------------------
  23. class IShaderUtil;
  24. class CShaderDeviceBase;
  25. class CShaderDeviceMgrBase;
  26. class CShaderAPIBase;
  27. class IShaderShadow;
  28. //-----------------------------------------------------------------------------
  29. // Global interfaces
  30. //-----------------------------------------------------------------------------
  31. extern IShaderUtil* g_pShaderUtil;
  32. inline IShaderUtil* ShaderUtil()
  33. {
  34. return g_pShaderUtil;
  35. }
  36. extern CShaderDeviceBase *g_pShaderDevice;
  37. extern CShaderDeviceMgrBase *g_pShaderDeviceMgr;
  38. extern CShaderAPIBase *g_pShaderAPI;
  39. extern IShaderShadow *g_pShaderShadow;
  40. //-----------------------------------------------------------------------------
  41. // Memory debugging
  42. //-----------------------------------------------------------------------------
  43. #define MEM_ALLOC_D3D_CREDIT() MEM_ALLOC_CREDIT_("D3D:" __FILE__)
  44. #define BEGIN_D3D_ALLOCATION() MemAlloc_PushAllocDbgInfo("D3D:" __FILE__, __LINE__)
  45. #define END_D3D_ALLOCATION() MemAlloc_PopAllocDbgInfo()
  46. //-----------------------------------------------------------------------------
  47. // Threading
  48. //-----------------------------------------------------------------------------
  49. extern bool g_bUseShaderMutex;
  50. //#define USE_SHADER_DISALLOW 1
  51. //#define STRICT_MT_SHADERAPI 1
  52. #if defined(_DEBUG)
  53. #if !defined(STRICT_MT_SHADERAPI)
  54. #define UNCONDITIONAL_MT_SHADERAPI 1
  55. #endif
  56. #else
  57. #if !defined(STRICT_MT_SHADERAPI) && !defined(UNCONDITIONAL_MT_SHADERAPI)
  58. #define ST_SHADERAPI 1
  59. #endif
  60. #endif
  61. #if defined(ST_SHADERAPI)
  62. typedef CThreadNullMutex CShaderMutex;
  63. #elif defined(STRICT_MT_SHADERAPI)
  64. typedef CThreadConditionalMutex<CThreadTerminalMutex<CThreadFastMutex>, &g_bUseShaderMutex> CShaderMutex;
  65. #elif defined(UNCONDITIONAL_MT_SHADERAPI)
  66. typedef CThreadFastMutex CShaderMutex;
  67. #else
  68. typedef CThreadConditionalMutex<CThreadFastMutex, &g_bUseShaderMutex> CShaderMutex;
  69. #endif
  70. extern CShaderMutex g_ShaderMutex;
  71. extern bool g_bShaderAccessDisallowed;
  72. #ifdef USE_SHADER_DISALLOW
  73. #define TestShaderPermission() do { if ( (!g_bUseShaderMutex || g_ShaderMutex.GetDepth() == 0) && g_bShaderAccessDisallowed ) { ExecuteOnce( DebuggerBreakIfDebugging() ); } } while (0)
  74. #define LOCK_SHADERAPI() TestShaderPermission(); AUTO_LOCK_( CShaderMutex, g_ShaderMutex )
  75. #define LockShaderMutex() TestShaderPermission(); g_ShaderMutex.Lock();
  76. #define UnlockShaderMutex() TestShaderPermission(); g_ShaderMutex.Unlock();
  77. #else
  78. #define TestShaderPermission() ((void)0)
  79. #define LOCK_SHADERAPI() ((void)0)
  80. #define LockShaderMutex() ((void)0)
  81. #define UnlockShaderMutex() ((void)0)
  82. #endif
  83. #endif // SHADERAPI_GLOBAL_H