shaderc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2011-2022 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. #ifndef SHADERC_H_HEADER_GUARD
  6. #define SHADERC_H_HEADER_GUARD
  7. namespace bgfx
  8. {
  9. extern bool g_verbose;
  10. }
  11. #ifndef SHADERC_CONFIG_HLSL
  12. # define SHADERC_CONFIG_HLSL BX_PLATFORM_WINDOWS
  13. #endif // SHADERC_CONFIG_HLSL
  14. #include <alloca.h>
  15. #include <stdint.h>
  16. #include <string.h>
  17. #include <algorithm>
  18. #include <string>
  19. #include <vector>
  20. #include <unordered_map>
  21. #include <bx/bx.h>
  22. #include <bx/debug.h>
  23. #include <bx/commandline.h>
  24. #include <bx/endian.h>
  25. #include <bx/uint32_t.h>
  26. #include <bx/string.h>
  27. #include <bx/hash.h>
  28. #include <bx/file.h>
  29. #include "../../src/vertexlayout.h"
  30. namespace bgfx
  31. {
  32. extern bool g_verbose;
  33. bx::StringView nextWord(bx::StringView& _parse);
  34. constexpr uint8_t kUniformFragmentBit = 0x10;
  35. constexpr uint8_t kUniformSamplerBit = 0x20;
  36. constexpr uint8_t kUniformReadOnlyBit = 0x40;
  37. constexpr uint8_t kUniformCompareBit = 0x80;
  38. constexpr uint8_t kUniformMask = 0
  39. | kUniformFragmentBit
  40. | kUniformSamplerBit
  41. | kUniformReadOnlyBit
  42. | kUniformCompareBit
  43. ;
  44. const char* getUniformTypeName(UniformType::Enum _enum);
  45. UniformType::Enum nameToUniformTypeEnum(const char* _name);
  46. struct Uniform
  47. {
  48. Uniform()
  49. : type(UniformType::Count)
  50. , num(0)
  51. , regIndex(0)
  52. , regCount(0)
  53. , texComponent(0)
  54. , texDimension(0)
  55. , texFormat(0)
  56. {
  57. }
  58. std::string name;
  59. UniformType::Enum type;
  60. uint8_t num;
  61. uint16_t regIndex;
  62. uint16_t regCount;
  63. uint8_t texComponent;
  64. uint8_t texDimension;
  65. uint16_t texFormat;
  66. };
  67. struct Options
  68. {
  69. Options();
  70. void dump();
  71. char shaderType;
  72. std::string platform;
  73. std::string profile;
  74. std::string inputFilePath;
  75. std::string outputFilePath;
  76. std::vector<std::string> includeDirs;
  77. std::vector<std::string> defines;
  78. std::vector<std::string> dependencies;
  79. bool disasm;
  80. bool raw;
  81. bool preprocessOnly;
  82. bool depends;
  83. bool debugInformation;
  84. bool avoidFlowControl;
  85. bool noPreshader;
  86. bool partialPrecision;
  87. bool preferFlowControl;
  88. bool backwardsCompatibility;
  89. bool warningsAreErrors;
  90. bool keepIntermediate;
  91. bool optimize;
  92. uint32_t optimizationLevel;
  93. };
  94. typedef std::vector<Uniform> UniformArray;
  95. void printCode(const char* _code, int32_t _line = 0, int32_t _start = 0, int32_t _end = INT32_MAX, int32_t _column = -1);
  96. void strReplace(char* _str, const char* _find, const char* _replace);
  97. int32_t writef(bx::WriterI* _writer, const char* _format, ...);
  98. void writeFile(const char* _filePath, const void* _data, int32_t _size);
  99. bool compileGLSLShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  100. bool compileHLSLShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  101. bool compileMetalShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  102. bool compilePSSLShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  103. bool compileSPIRVShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
  104. const char* getPsslPreamble();
  105. } // namespace bgfx
  106. #endif // SHADERC_H_HEADER_GUARD