2014-12-04 07:16:20 +03:00
|
|
|
/*
|
2022-01-15 22:59:06 +03:00
|
|
|
* Copyright 2011-2022 Branimir Karadzic. All rights reserved.
|
|
|
|
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
|
2014-12-04 07:16:20 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHADERC_H_HEADER_GUARD
|
|
|
|
#define SHADERC_H_HEADER_GUARD
|
|
|
|
|
2016-02-01 03:00:02 +03:00
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
extern bool g_verbose;
|
|
|
|
}
|
|
|
|
|
2015-04-11 04:00:46 +03:00
|
|
|
#ifndef SHADERC_CONFIG_HLSL
|
|
|
|
# define SHADERC_CONFIG_HLSL BX_PLATFORM_WINDOWS
|
|
|
|
#endif // SHADERC_CONFIG_HLSL
|
2014-12-04 07:16:20 +03:00
|
|
|
|
|
|
|
#include <alloca.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include <bx/bx.h>
|
|
|
|
#include <bx/debug.h>
|
|
|
|
#include <bx/commandline.h>
|
|
|
|
#include <bx/endian.h>
|
|
|
|
#include <bx/uint32_t.h>
|
|
|
|
#include <bx/string.h>
|
|
|
|
#include <bx/hash.h>
|
2017-07-16 07:01:08 +03:00
|
|
|
#include <bx/file.h>
|
2020-03-29 06:06:03 +03:00
|
|
|
#include "../../src/vertexlayout.h"
|
2014-12-04 07:16:20 +03:00
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
namespace bgfx
|
2015-04-11 22:40:31 +03:00
|
|
|
{
|
2016-01-31 03:15:25 +03:00
|
|
|
extern bool g_verbose;
|
2015-04-11 22:40:31 +03:00
|
|
|
|
2018-10-26 08:16:10 +03:00
|
|
|
bx::StringView nextWord(bx::StringView& _parse);
|
|
|
|
|
2020-06-19 07:20:01 +03:00
|
|
|
constexpr uint8_t kUniformFragmentBit = 0x10;
|
|
|
|
constexpr uint8_t kUniformSamplerBit = 0x20;
|
|
|
|
constexpr uint8_t kUniformReadOnlyBit = 0x40;
|
|
|
|
constexpr uint8_t kUniformCompareBit = 0x80;
|
|
|
|
constexpr uint8_t kUniformMask = 0
|
|
|
|
| kUniformFragmentBit
|
|
|
|
| kUniformSamplerBit
|
|
|
|
| kUniformReadOnlyBit
|
|
|
|
| kUniformCompareBit
|
|
|
|
;
|
2015-04-11 22:40:31 +03:00
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
const char* getUniformTypeName(UniformType::Enum _enum);
|
|
|
|
UniformType::Enum nameToUniformTypeEnum(const char* _name);
|
2015-04-11 22:40:31 +03:00
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
struct Uniform
|
2014-12-04 07:16:20 +03:00
|
|
|
{
|
2020-06-19 03:24:47 +03:00
|
|
|
Uniform()
|
|
|
|
: type(UniformType::Count)
|
|
|
|
, num(0)
|
|
|
|
, regIndex(0)
|
|
|
|
, regCount(0)
|
|
|
|
, texComponent(0)
|
|
|
|
, texDimension(0)
|
2021-07-20 16:06:56 +03:00
|
|
|
, texFormat(0)
|
2020-06-19 03:24:47 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
std::string name;
|
|
|
|
UniformType::Enum type;
|
|
|
|
uint8_t num;
|
|
|
|
uint16_t regIndex;
|
|
|
|
uint16_t regCount;
|
2020-05-08 18:53:53 +03:00
|
|
|
uint8_t texComponent;
|
|
|
|
uint8_t texDimension;
|
2021-04-21 06:18:49 +03:00
|
|
|
uint16_t texFormat;
|
2014-12-04 07:16:20 +03:00
|
|
|
};
|
|
|
|
|
2017-11-24 21:01:13 +03:00
|
|
|
struct Options
|
|
|
|
{
|
|
|
|
Options();
|
|
|
|
|
|
|
|
void dump();
|
|
|
|
|
|
|
|
char shaderType;
|
|
|
|
std::string platform;
|
|
|
|
std::string profile;
|
|
|
|
|
|
|
|
std::string inputFilePath;
|
|
|
|
std::string outputFilePath;
|
|
|
|
|
|
|
|
std::vector<std::string> includeDirs;
|
|
|
|
std::vector<std::string> defines;
|
|
|
|
std::vector<std::string> dependencies;
|
|
|
|
|
|
|
|
bool disasm;
|
|
|
|
bool raw;
|
|
|
|
bool preprocessOnly;
|
|
|
|
bool depends;
|
|
|
|
|
|
|
|
bool debugInformation;
|
|
|
|
|
|
|
|
bool avoidFlowControl;
|
|
|
|
bool noPreshader;
|
|
|
|
bool partialPrecision;
|
|
|
|
bool preferFlowControl;
|
|
|
|
bool backwardsCompatibility;
|
|
|
|
bool warningsAreErrors;
|
2018-09-26 04:11:06 +03:00
|
|
|
bool keepIntermediate;
|
2017-11-24 21:01:13 +03:00
|
|
|
|
|
|
|
bool optimize;
|
|
|
|
uint32_t optimizationLevel;
|
|
|
|
};
|
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
typedef std::vector<Uniform> UniformArray;
|
2014-12-04 07:16:20 +03:00
|
|
|
|
2016-10-01 22:38:41 +03:00
|
|
|
void printCode(const char* _code, int32_t _line = 0, int32_t _start = 0, int32_t _end = INT32_MAX, int32_t _column = -1);
|
2016-01-31 03:15:25 +03:00
|
|
|
void strReplace(char* _str, const char* _find, const char* _replace);
|
|
|
|
int32_t writef(bx::WriterI* _writer, const char* _format, ...);
|
|
|
|
void writeFile(const char* _filePath, const void* _data, int32_t _size);
|
2014-12-04 07:16:20 +03:00
|
|
|
|
2017-11-24 21:01:13 +03:00
|
|
|
bool compileGLSLShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
|
|
|
bool compileHLSLShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
2019-08-03 18:52:14 +03:00
|
|
|
bool compileMetalShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
2017-11-24 21:01:13 +03:00
|
|
|
bool compilePSSLShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
|
|
|
bool compileSPIRVShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
2016-01-31 03:15:25 +03:00
|
|
|
|
2018-03-17 04:15:16 +03:00
|
|
|
const char* getPsslPreamble();
|
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
} // namespace bgfx
|
2014-12-04 07:16:20 +03:00
|
|
|
|
|
|
|
#endif // SHADERC_H_HEADER_GUARD
|