2016-08-29 22:31:11 +02:00
|
|
|
/*
|
2018-02-03 17:39:28 +01:00
|
|
|
* Copyright 2011-2018 Branimir Karadzic. All rights reserved.
|
2016-08-29 22:31:11 +02:00
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHADERC_H_HEADER_GUARD
|
|
|
|
#define SHADERC_H_HEADER_GUARD
|
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
extern bool g_verbose;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _BX_TRACE(_format, ...) \
|
|
|
|
BX_MACRO_BLOCK_BEGIN \
|
|
|
|
if (bgfx::g_verbose) \
|
|
|
|
{ \
|
2016-11-10 21:53:08 +01:00
|
|
|
fprintf(stdout, BX_FILE_LINE_LITERAL "" _format "\n", ##__VA_ARGS__); \
|
2016-08-29 22:31:11 +02:00
|
|
|
} \
|
|
|
|
BX_MACRO_BLOCK_END
|
|
|
|
|
|
|
|
#define _BX_WARN(_condition, _format, ...) \
|
|
|
|
BX_MACRO_BLOCK_BEGIN \
|
|
|
|
if (!(_condition) ) \
|
|
|
|
{ \
|
|
|
|
BX_TRACE("WARN " _format, ##__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
BX_MACRO_BLOCK_END
|
|
|
|
|
|
|
|
#define _BX_CHECK(_condition, _format, ...) \
|
|
|
|
BX_MACRO_BLOCK_BEGIN \
|
|
|
|
if (!(_condition) ) \
|
|
|
|
{ \
|
|
|
|
BX_TRACE("CHECK " _format, ##__VA_ARGS__); \
|
|
|
|
bx::debugBreak(); \
|
|
|
|
} \
|
|
|
|
BX_MACRO_BLOCK_END
|
|
|
|
|
|
|
|
#define BX_TRACE _BX_TRACE
|
|
|
|
#define BX_WARN _BX_WARN
|
|
|
|
#define BX_CHECK _BX_CHECK
|
|
|
|
|
|
|
|
#ifndef SHADERC_CONFIG_HLSL
|
|
|
|
# define SHADERC_CONFIG_HLSL BX_PLATFORM_WINDOWS
|
|
|
|
#endif // SHADERC_CONFIG_HLSL
|
|
|
|
|
|
|
|
#include <alloca.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.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>
|
2018-02-03 17:39:28 +01:00
|
|
|
#include <bx/file.h>
|
2016-08-29 22:31:11 +02:00
|
|
|
#include "../../src/vertexdecl.h"
|
|
|
|
|
|
|
|
namespace bgfx
|
|
|
|
{
|
|
|
|
extern bool g_verbose;
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
class LineReader : public bx::ReaderI
|
2016-08-29 22:31:11 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
LineReader(const char* _str)
|
|
|
|
: m_str(_str)
|
|
|
|
, m_pos(0)
|
2018-02-03 17:39:28 +01:00
|
|
|
, m_size(bx::strLen(_str) )
|
2016-08-29 22:31:11 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
virtual int32_t read(void* _data, int32_t _size, bx::Error* _err) override
|
2016-08-29 22:31:11 +02:00
|
|
|
{
|
2018-02-03 17:39:28 +01:00
|
|
|
if (m_str[m_pos] == '\0'
|
|
|
|
|| m_pos == m_size)
|
|
|
|
{
|
|
|
|
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_EOF, "LineReader: EOF.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t pos = m_pos;
|
|
|
|
const char* str = &m_str[pos];
|
|
|
|
const char* nl = bx::strnl(str);
|
|
|
|
pos += (uint32_t)(nl - str);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
const char* eol = &m_str[pos];
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
uint32_t size = bx::uint32_min(uint32_t(eol - str), _size);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
bx::memCopy(_data, str, size);
|
|
|
|
m_pos += size;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
return size;
|
2016-08-29 22:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* m_str;
|
|
|
|
uint32_t m_pos;
|
|
|
|
uint32_t m_size;
|
|
|
|
};
|
|
|
|
|
2016-11-10 21:53:08 +01:00
|
|
|
#define BGFX_UNIFORM_FRAGMENTBIT UINT8_C(0x10)
|
|
|
|
#define BGFX_UNIFORM_SAMPLERBIT UINT8_C(0x20)
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
const char* getUniformTypeName(UniformType::Enum _enum);
|
|
|
|
UniformType::Enum nameToUniformTypeEnum(const char* _name);
|
|
|
|
|
|
|
|
struct Uniform
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
UniformType::Enum type;
|
|
|
|
uint8_t num;
|
|
|
|
uint16_t regIndex;
|
|
|
|
uint16_t regCount;
|
|
|
|
};
|
|
|
|
|
2018-02-03 17:39:28 +01: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;
|
|
|
|
|
|
|
|
bool optimize;
|
|
|
|
uint32_t optimizationLevel;
|
|
|
|
};
|
|
|
|
|
2016-08-29 22:31:11 +02:00
|
|
|
typedef std::vector<Uniform> UniformArray;
|
|
|
|
|
2016-11-10 21:53:08 +01:00
|
|
|
void printCode(const char* _code, int32_t _line = 0, int32_t _start = 0, int32_t _end = INT32_MAX, int32_t _column = -1);
|
2016-08-29 22:31:11 +02: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);
|
|
|
|
|
2018-02-03 17:39:28 +01: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);
|
|
|
|
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-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
} // namespace bgfx
|
|
|
|
|
|
|
|
#endif // SHADERC_H_HEADER_GUARD
|