Shader: compilation fixes
This commit is contained in:
parent
fce336bfc9
commit
9fd4249a87
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
namespace Nz::ShaderLang
|
||||
{
|
||||
class AttributeError : public std::exception
|
||||
class AttributeError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
using exception::exception;
|
||||
using runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
class ExpectedToken : public std::exception
|
||||
|
|
@ -26,10 +26,10 @@ namespace Nz::ShaderLang
|
|||
using exception::exception;
|
||||
};
|
||||
|
||||
class DuplicateIdentifier : public std::exception
|
||||
class DuplicateIdentifier : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
using exception::exception;
|
||||
using runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
class ReservedKeyword : public std::exception
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::CompEq, T1, T2>
|
||||
{
|
||||
using Op = typename CompEq<T1, T2>;
|
||||
using Op = CompEq<T1, T2>;
|
||||
};
|
||||
|
||||
// CompGe
|
||||
|
|
@ -72,7 +72,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::CompGe, T1, T2>
|
||||
{
|
||||
using Op = typename CompGe<T1, T2>;
|
||||
using Op = CompGe<T1, T2>;
|
||||
};
|
||||
|
||||
// CompGt
|
||||
|
|
@ -91,7 +91,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::CompGt, T1, T2>
|
||||
{
|
||||
using Op = typename CompGt<T1, T2>;
|
||||
using Op = CompGt<T1, T2>;
|
||||
};
|
||||
|
||||
// CompLe
|
||||
|
|
@ -110,7 +110,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::CompLe, T1, T2>
|
||||
{
|
||||
using Op = typename CompLe<T1, T2>;
|
||||
using Op = CompLe<T1, T2>;
|
||||
};
|
||||
|
||||
// CompLt
|
||||
|
|
@ -129,7 +129,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::CompLt, T1, T2>
|
||||
{
|
||||
using Op = typename CompLe<T1, T2>;
|
||||
using Op = CompLe<T1, T2>;
|
||||
};
|
||||
|
||||
// CompNe
|
||||
|
|
@ -148,7 +148,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::CompNe, T1, T2>
|
||||
{
|
||||
using Op = typename CompNe<T1, T2>;
|
||||
using Op = CompNe<T1, T2>;
|
||||
};
|
||||
|
||||
// Addition
|
||||
|
|
@ -167,7 +167,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::Add, T1, T2>
|
||||
{
|
||||
using Op = typename Addition<T1, T2>;
|
||||
using Op = Addition<T1, T2>;
|
||||
};
|
||||
|
||||
// Division
|
||||
|
|
@ -186,7 +186,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::Divide, T1, T2>
|
||||
{
|
||||
using Op = typename Division<T1, T2>;
|
||||
using Op = Division<T1, T2>;
|
||||
};
|
||||
|
||||
// Multiplication
|
||||
|
|
@ -205,7 +205,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::Multiply, T1, T2>
|
||||
{
|
||||
using Op = typename Multiplication<T1, T2>;
|
||||
using Op = Multiplication<T1, T2>;
|
||||
};
|
||||
|
||||
// Subtraction
|
||||
|
|
@ -224,7 +224,7 @@ namespace Nz::ShaderAst
|
|||
template<typename T1, typename T2>
|
||||
struct PropagateConstantType<BinaryType::Subtract, T1, T2>
|
||||
{
|
||||
using Op = typename Subtraction<T1, T2>;
|
||||
using Op = Subtraction<T1, T2>;
|
||||
};
|
||||
|
||||
#define EnableOptimisation(Op, T1, T2) template<> struct Op<T1, T2> : Op##Base<T1, T2> {}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace Nz::ShaderLang
|
|||
char c = Peek(0);
|
||||
|
||||
Token token;
|
||||
token.column = currentPos - lastLineFeed;
|
||||
token.column = static_cast<unsigned int>(currentPos - lastLineFeed);
|
||||
token.line = lineNumber;
|
||||
|
||||
if (c == -1)
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@ namespace Nz::ShaderLang
|
|||
{
|
||||
namespace
|
||||
{
|
||||
std::unordered_map<std::string, ShaderAst::PrimitiveType> identifierToBasicType = {
|
||||
std::unordered_map<std::string, ShaderAst::PrimitiveType> s_identifierToBasicType = {
|
||||
{ "bool", ShaderAst::PrimitiveType::Boolean },
|
||||
{ "i32", ShaderAst::PrimitiveType::Int32 },
|
||||
{ "f32", ShaderAst::PrimitiveType::Float32 },
|
||||
{ "u32", ShaderAst::PrimitiveType::UInt32 }
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, ShaderAst::IntrinsicType> identifierToIntrinsic = {
|
||||
std::unordered_map<std::string, ShaderAst::IntrinsicType> s_identifierToIntrinsic = {
|
||||
{ "cross", ShaderAst::IntrinsicType::CrossProduct },
|
||||
{ "dot", ShaderAst::IntrinsicType::DotProduct },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, ShaderAst::AttributeType> identifierToAttributeType = {
|
||||
std::unordered_map<std::string, ShaderAst::AttributeType> s_identifierToAttributeType = {
|
||||
{ "binding", ShaderAst::AttributeType::Binding },
|
||||
{ "builtin", ShaderAst::AttributeType::Builtin },
|
||||
{ "entry", ShaderAst::AttributeType::Entry },
|
||||
|
|
@ -127,7 +127,7 @@ namespace Nz::ShaderLang
|
|||
|
||||
ShaderAst::ExpressionType Parser::DecodeType(const std::string& identifier)
|
||||
{
|
||||
if (auto it = identifierToBasicType.find(identifier); it != identifierToBasicType.end())
|
||||
if (auto it = s_identifierToBasicType.find(identifier); it != s_identifierToBasicType.end())
|
||||
return it->second;
|
||||
|
||||
//FIXME: Handle this better
|
||||
|
|
@ -577,6 +577,9 @@ namespace Nz::ShaderLang
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw AttributeError{ "unexpected attribute" };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -809,7 +812,7 @@ namespace Nz::ShaderLang
|
|||
{
|
||||
const std::string& identifier = std::get<std::string>(token.data);
|
||||
|
||||
if (auto it = identifierToIntrinsic.find(identifier); it != identifierToIntrinsic.end())
|
||||
if (auto it = s_identifierToIntrinsic.find(identifier); it != s_identifierToIntrinsic.end())
|
||||
{
|
||||
if (Peek(1).type == TokenType::OpenParenthesis)
|
||||
{
|
||||
|
|
@ -879,8 +882,8 @@ namespace Nz::ShaderLang
|
|||
const Token& identifierToken = Expect(Advance(), TokenType::Identifier);
|
||||
const std::string& identifier = std::get<std::string>(identifierToken.data);
|
||||
|
||||
auto it = identifierToAttributeType.find(identifier);
|
||||
if (it == identifierToAttributeType.end())
|
||||
auto it = s_identifierToAttributeType.find(identifier);
|
||||
if (it == s_identifierToAttributeType.end())
|
||||
throw UnknownAttribute{};
|
||||
|
||||
return it->second;
|
||||
|
|
@ -891,8 +894,8 @@ namespace Nz::ShaderLang
|
|||
const Token& identifierToken = Expect(Advance(), TokenType::Identifier);
|
||||
const std::string& identifier = std::get<std::string>(identifierToken.data);
|
||||
|
||||
auto it = identifierToBasicType.find(identifier);
|
||||
if (it != identifierToBasicType.end())
|
||||
auto it = s_identifierToBasicType.find(identifier);
|
||||
if (it != s_identifierToBasicType.end())
|
||||
throw ReservedKeyword{};
|
||||
|
||||
return identifier;
|
||||
|
|
@ -903,8 +906,8 @@ namespace Nz::ShaderLang
|
|||
const Token& identifierToken = Expect(Advance(), TokenType::Identifier);
|
||||
const std::string& identifier = std::get<std::string>(identifierToken.data);
|
||||
|
||||
auto it = identifierToBasicType.find(identifier);
|
||||
if (it == identifierToBasicType.end())
|
||||
auto it = s_identifierToBasicType.find(identifier);
|
||||
if (it == s_identifierToBasicType.end())
|
||||
throw UnknownType{};
|
||||
|
||||
return it->second;
|
||||
|
|
|
|||
Loading…
Reference in New Issue