shaderc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright 2011-2017 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #ifndef SHADERC_H_HEADER_GUARD
  6. #define SHADERC_H_HEADER_GUARD
  7. namespace bgfx
  8. {
  9. extern bool g_verbose;
  10. }
  11. #define _BX_TRACE(_format, ...) \
  12. BX_MACRO_BLOCK_BEGIN \
  13. if (bgfx::g_verbose) \
  14. { \
  15. fprintf(stdout, BX_FILE_LINE_LITERAL "" _format "\n", ##__VA_ARGS__); \
  16. } \
  17. BX_MACRO_BLOCK_END
  18. #define _BX_WARN(_condition, _format, ...) \
  19. BX_MACRO_BLOCK_BEGIN \
  20. if (!(_condition) ) \
  21. { \
  22. BX_TRACE("WARN " _format, ##__VA_ARGS__); \
  23. } \
  24. BX_MACRO_BLOCK_END
  25. #define _BX_CHECK(_condition, _format, ...) \
  26. BX_MACRO_BLOCK_BEGIN \
  27. if (!(_condition) ) \
  28. { \
  29. BX_TRACE("CHECK " _format, ##__VA_ARGS__); \
  30. bx::debugBreak(); \
  31. } \
  32. BX_MACRO_BLOCK_END
  33. #define BX_TRACE _BX_TRACE
  34. #define BX_WARN _BX_WARN
  35. #define BX_CHECK _BX_CHECK
  36. #ifndef SHADERC_CONFIG_HLSL
  37. # define SHADERC_CONFIG_HLSL BX_PLATFORM_WINDOWS
  38. #endif // SHADERC_CONFIG_HLSL
  39. #include <alloca.h>
  40. #include <stdio.h>
  41. #include <stdint.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <algorithm>
  45. #include <string>
  46. #include <vector>
  47. #include <unordered_map>
  48. #include <bx/bx.h>
  49. #include <bx/debug.h>
  50. #include <bx/commandline.h>
  51. #include <bx/endian.h>
  52. #include <bx/uint32_t.h>
  53. #include <bx/string.h>
  54. #include <bx/hash.h>
  55. #include <bx/crtimpl.h>
  56. #include "../../src/vertexdecl.h"
  57. namespace bgfx
  58. {
  59. extern bool g_verbose;
  60. class LineReader
  61. {
  62. public:
  63. LineReader(const char* _str)
  64. : m_str(_str)
  65. , m_pos(0)
  66. , m_size((uint32_t)strlen(_str))
  67. {
  68. }
  69. std::string getLine()
  70. {
  71. const char* str = &m_str[m_pos];
  72. skipLine();
  73. const char* eol = &m_str[m_pos];
  74. std::string tmp;
  75. tmp.assign(str, eol - str);
  76. return tmp;
  77. }
  78. bool isEof() const
  79. {
  80. return m_str[m_pos] == '\0';
  81. }
  82. void skipLine()
  83. {
  84. const char* str = &m_str[m_pos];
  85. const char* nl = bx::strnl(str);
  86. m_pos += (uint32_t)(nl - str);
  87. }
  88. const char* m_str;
  89. uint32_t m_pos;
  90. uint32_t m_size;
  91. };
  92. #define BGFX_UNIFORM_FRAGMENTBIT UINT8_C(0x10)
  93. #define BGFX_UNIFORM_SAMPLERBIT UINT8_C(0x20)
  94. const char* getUniformTypeName(UniformType::Enum _enum);
  95. UniformType::Enum nameToUniformTypeEnum(const char* _name);
  96. struct Uniform
  97. {
  98. std::string name;
  99. UniformType::Enum type;
  100. uint8_t num;
  101. uint16_t regIndex;
  102. uint16_t regCount;
  103. };
  104. typedef std::vector<Uniform> UniformArray;
  105. void printCode(const char* _code, int32_t _line = 0, int32_t _start = 0, int32_t _end = INT32_MAX, int32_t _column = -1);
  106. void strReplace(char* _str, const char* _find, const char* _replace);
  107. int32_t writef(bx::WriterI* _writer, const char* _format, ...);
  108. void writeFile(const char* _filePath, const void* _data, int32_t _size);
  109. bool compileGLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  110. bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  111. bool compilePSSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  112. bool compileSPIRVShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  113. } // namespace bgfx
  114. #endif // SHADERC_H_HEADER_GUARD