2014-12-04 07:16:20 +03:00
|
|
|
/*
|
2016-01-01 11:11:04 +03:00
|
|
|
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
|
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
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;
|
|
|
|
}
|
|
|
|
|
2014-12-04 07:16:20 +03:00
|
|
|
#define _BX_TRACE(_format, ...) \
|
|
|
|
BX_MACRO_BLOCK_BEGIN \
|
2016-01-31 03:15:25 +03:00
|
|
|
if (bgfx::g_verbose) \
|
2014-12-04 07:16:20 +03:00
|
|
|
{ \
|
|
|
|
fprintf(stderr, BX_FILE_LINE_LITERAL "" _format "\n", ##__VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
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
|
|
|
|
|
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 <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>
|
2016-02-22 01:08:20 +03:00
|
|
|
#include <bx/crtimpl.h>
|
2014-12-04 07:16:20 +03:00
|
|
|
#include "../../src/vertexdecl.h"
|
|
|
|
|
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
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
class LineReader
|
2015-04-11 22:40:31 +03:00
|
|
|
{
|
2016-01-31 03:15:25 +03:00
|
|
|
public:
|
|
|
|
LineReader(const char* _str)
|
|
|
|
: m_str(_str)
|
|
|
|
, m_pos(0)
|
|
|
|
, m_size((uint32_t)strlen(_str))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getLine()
|
|
|
|
{
|
|
|
|
const char* str = &m_str[m_pos];
|
|
|
|
skipLine();
|
|
|
|
|
|
|
|
const char* eol = &m_str[m_pos];
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
tmp.assign(str, eol - str);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEof() const
|
|
|
|
{
|
|
|
|
return m_str[m_pos] == '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
void skipLine()
|
|
|
|
{
|
|
|
|
const char* str = &m_str[m_pos];
|
|
|
|
const char* nl = bx::strnl(str);
|
|
|
|
m_pos += (uint32_t)(nl - str);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* m_str;
|
|
|
|
uint32_t m_pos;
|
|
|
|
uint32_t m_size;
|
|
|
|
};
|
2015-04-11 22:40:31 +03:00
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
#define BGFX_UNIFORM_FRAGMENTBIT UINT8_C(0x10)
|
|
|
|
#define BGFX_UNIFORM_SAMPLERBIT UINT8_C(0x20)
|
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
|
|
|
{
|
2016-01-31 03:15:25 +03:00
|
|
|
std::string name;
|
|
|
|
UniformType::Enum type;
|
|
|
|
uint8_t num;
|
|
|
|
uint16_t regIndex;
|
|
|
|
uint16_t regCount;
|
2014-12-04 07:16:20 +03:00
|
|
|
};
|
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
typedef std::vector<Uniform> UniformArray;
|
2014-12-04 07:16:20 +03:00
|
|
|
|
2016-01-31 03:15:25 +03:00
|
|
|
void printCode(const char* _code, int32_t _line = 0, int32_t _start = 0, int32_t _end = INT32_MAX);
|
|
|
|
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
|
|
|
|
2016-10-01 04:16:04 +03:00
|
|
|
bool compileGLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
|
|
|
bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
|
|
|
bool compilePSSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
2016-10-01 06:03:16 +03:00
|
|
|
bool compileSPIRVShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
|
2016-01-31 03:15:25 +03:00
|
|
|
|
|
|
|
} // namespace bgfx
|
2014-12-04 07:16:20 +03:00
|
|
|
|
|
|
|
#endif // SHADERC_H_HEADER_GUARD
|