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