Further shader compilation development.

This commit is contained in:
zy4n
2025-03-22 17:40:08 +01:00
parent e01b8c2e09
commit 510398423a
45 changed files with 1567 additions and 1097 deletions

View File

@@ -0,0 +1,110 @@
#pragma once
#include <string_view>
#include <vector>
#include <optional>
#include <span>
#include "util/string_lookup.hpp"
#include "../metadata/shader_source_metadata.hpp"
#include "opengl/shading/requirements/shader_source_requirements.hpp"
#include "opengl/metadata/preprocessed_shader_source_metadata.hpp"
#include "assets/dynamic_data_stores/dynamic_shader_source_store.hpp"
#include "opengl/shading/shader_source_set.hpp"
namespace zgl {
class shader_preprocessor {
public:
void preprocess(
const dynamic_shader_source_store& shader_sources
);
void fetch_shader_sources(
const dynamic_shader_source_store& shader_sources,
std::span<const shading::shader_source_requirements> requirements,
std::span<preprocessed_shader_source_metadata> metadata,
std::vector<const char*>& shader_strings
);
protected:
void tokenize_declarations(std::string_view source);
std::optional<shader_source_metadata> parse_metadata_from_tokens();
[[nodiscard]] static bool parse_stage_declaration(
std::span<const std::string_view> values,
shader_source_metadata& metadata
);
[[nodiscard]] static bool parse_geometry_declaration(
std::span<const std::string_view> tokens,
shader_source_metadata& metadata
);
[[nodiscard]] static bool parse_features_declaration(
std::span<const std::string_view> values,
shader_source_metadata& metadata
);
[[nodiscard]] static bool parse_static_enable_declaration(
std::span<const std::string_view> values,
shader_source_metadata& metadata
);
[[nodiscard]] static bool parse_dynamic_enable_declaration(
std::span<const std::string_view> values,
shader_source_metadata& metadata
);
template<typename T>
static void parse_feature_tokens(
std::span<const std::string_view> values,
const ztu::string_lookup<T>& feature_lookup,
T& features
);
static void get_define_strings(
shading::model_geometry::types geometry,
shading::features::generic::type features,
shading::features::generic::type& feature_count,
std::vector<const char*>& defines
);
private:
inline static auto mesh_feature_defines = std::array{
"#define FACE\n",
"#define LINE\n",
"#define POINT\n",
"#define V_L\n",
"#define V_RGB\n",
"#define V_A\n",
"#define LIGHTING\n",
"#define TEXTURE\n",
"#define U_RGBA\n",
};
inline static auto point_cloud_feature_defines = std::array{
"#define SQUARE\n",
"#define LIGHTING\n",
"#define V_L\n",
"#define V_RGB\n",
"#define V_A\n",
"#define U_RGBA\n",
"#define RAINBOW\n"
};
std::vector<std::string_view> m_value_token_buffer;
std::vector<std::size_t> m_declaration_token_count_buffer;
std::array<std::size_t, 4> m_declaration_type_index_buffer;
using source_lookup_entry_type = std::pair<shader_source_metadata, dynamic_shader_source_store::id_type>;
using source_lookup_type = std::vector<source_lookup_entry_type>;
source_lookup_type m_shader_source_lookup;
};
}