Handle shader options of any type
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/AstCloner.hpp>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
@@ -36,7 +37,6 @@ namespace Nz::ShaderAst
|
||||
struct Options
|
||||
{
|
||||
std::function<const ConstantValue&(std::size_t constantId)> constantQueryCallback;
|
||||
std::optional<UInt64> enabledOptions = 0;
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
using NoValue = std::monostate;
|
||||
|
||||
using ConstantTypes = TypeList<
|
||||
NoValue,
|
||||
bool,
|
||||
float,
|
||||
Int32,
|
||||
|
||||
@@ -302,7 +302,7 @@ namespace Nz::ShaderAst
|
||||
|
||||
std::optional<std::size_t> optIndex;
|
||||
std::string optName;
|
||||
ExpressionPtr initialValue;
|
||||
ExpressionPtr defaultValue;
|
||||
ExpressionType optType;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Nz::ShaderAst
|
||||
struct Options
|
||||
{
|
||||
std::unordered_set<std::string> reservedIdentifiers;
|
||||
UInt64 enabledOptions = 0;
|
||||
std::unordered_map<std::size_t, ConstantValue> optionValues;
|
||||
bool makeVariableNameUnique = false;
|
||||
bool removeOptionDeclaration = true;
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Nz
|
||||
};
|
||||
|
||||
static const char* GetFlipYUniformName();
|
||||
static ShaderAst::StatementPtr Sanitize(ShaderAst::Statement& ast, UInt64 enabledOptions, std::string* error = nullptr);
|
||||
static ShaderAst::StatementPtr Sanitize(ShaderAst::Statement& ast, std::unordered_map<std::size_t, ShaderAst::ConstantValue> optionValues, std::string* error = nullptr);
|
||||
|
||||
private:
|
||||
void Append(const ShaderAst::ExpressionType& type);
|
||||
|
||||
@@ -198,7 +198,7 @@ namespace Nz::ShaderBuilder
|
||||
auto declareOptionNode = std::make_unique<ShaderAst::DeclareOptionStatement>();
|
||||
declareOptionNode->optName = std::move(name);
|
||||
declareOptionNode->optType = std::move(type);
|
||||
declareOptionNode->initialValue = std::move(initialValue);
|
||||
declareOptionNode->defaultValue = std::move(initialValue);
|
||||
|
||||
return declareOptionNode;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/ConstantValue.hpp>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -26,7 +27,7 @@ namespace Nz
|
||||
|
||||
struct States
|
||||
{
|
||||
Nz::UInt64 enabledOptions = 0;
|
||||
std::unordered_map<std::size_t, ShaderAst::ConstantValue> optionValues;
|
||||
bool optimize = false;
|
||||
bool sanitized = false;
|
||||
};
|
||||
|
||||
@@ -63,8 +63,6 @@ namespace Nz
|
||||
UInt32 GetPointerTypeId(const ShaderAst::ExpressionType& type, SpirvStorageClass storageClass) const;
|
||||
UInt32 GetTypeId(const ShaderAst::ExpressionType& type) const;
|
||||
|
||||
bool IsOptionEnabled(std::size_t optionIndex) const;
|
||||
|
||||
UInt32 RegisterConstant(const ShaderAst::ConstantValue& value);
|
||||
UInt32 RegisterFunctionType(const ShaderAst::DeclareFunctionStatement& functionNode);
|
||||
UInt32 RegisterPointerType(ShaderAst::ExpressionType type, SpirvStorageClass storageClass);
|
||||
|
||||
Reference in New Issue
Block a user