In the middle of multithreading parsers.

This commit is contained in:
zy4n
2025-03-30 22:38:06 +02:00
parent d18b40a7fc
commit 144126ee7a
80 changed files with 2904 additions and 1450 deletions

View File

@@ -1,7 +1,7 @@
#pragma once
#include "assets/data/texture.hpp"
#include "assets/data/surface_properties.hpp"
#include "assets/data/uniform_surface_properties.hpp"
#include "assets/components/material_components.hpp"
#include "opengl/handles/material_handle.hpp"

View File

@@ -17,7 +17,7 @@
#include "opengl/handles/shader_handle_set.hpp"
#include "opengl/shading/requirements/shader_requirements.hpp"
#include "opengl/metadata/shader_set_metadata.hpp"
#include "opengl/shading/requirements/shader_set_requirements.hpp"
#include "opengl/shading/requirements/shader_program_requirements.hpp"
namespace zgl
{
@@ -33,9 +33,9 @@ public:
void process(const store_type& shader_sources);
void get_handles(
void fetch(
const assets::shader_source_store& shader_sources,
std::span<const shading::shader_set_requirements> requirements,
std::span<const shading::shader_program_requirements> requirements,
std::span<shader_set_metadata> metadata,
std::span<shader_handle_set> shader_sets
);
@@ -56,7 +56,7 @@ protected:
std::vector<entry_type> m_shader_lookup{};
private:
std::vector<shading::shader_source_requirements> m_source_requirement_buffer{};
std::vector<shading::shader_requirements> m_source_requirement_buffer{};
std::vector<preprocessed_shader_source_metadata> m_preprocessed_shader_source_metadata_buffer{};
std::vector<const char*> m_source_strings_buffer{};
};

View File

@@ -21,7 +21,7 @@ public:
void process(const store_type& shader_sources);
void get_handles(
void fetch(
const assets::shader_source_store& shader_sources,
std::span<const shading::shader_program_requirements> requirements,
std::span<shader_program_metadata> metadata,
@@ -41,7 +41,7 @@ protected:
std::vector<entry_type> m_shader_program_lookup;
private:
std::vector<shading::shader_set_requirements> m_shader_requirements_buffer;
std::vector<shading::shader_program_requirements> m_shader_requirements_buffer;
std::vector<shader_set_metadata> m_shader_metadata_buffer;
std::vector<shader_handle_set> shader_set_buffer;
};

View File

@@ -9,7 +9,7 @@
#include "util/string_lookup.hpp"
#include "opengl/metadata/shader_source_metadata.hpp"
#include "opengl/shading/requirements/shader_source_requirements.hpp"
#include "opengl/shading/requirements/shader_requirements.hpp"
#include "opengl/metadata/preprocessed_shader_source_metadata.hpp"
#include "assets/data_stores/shader_source_store.hpp"
@@ -30,64 +30,21 @@ public:
void process(const store_type& shader_sources);
void get_shader_sources(
void fetch(
const assets::shader_source_store& shader_sources,
std::span<const shading::shader_source_requirements> requirements,
std::span<const shading::shader_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,
assets::model_geometry::types geometry_type,
assets::shader_components::flags components,
assets::shader_components::flags& component_count,
std::vector<const char*>& defines
);
std::vector<entry_type> m_shader_source_lookup;
private:
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;
};
}

View File

@@ -1,9 +1,7 @@
#pragma once
#include "GL/glew.h"
#include "opengl/shader_uniform.hpp"
#include "opengl/shader_uniform.hpp"
#include "opengl/shading/uniform.hpp"
#include "util/uix.hpp"
#include <span>
@@ -17,12 +15,12 @@ struct shader_program_handle
inline void bind() const;
static void unbind();
template<shader_uniform::info_type VariableInfo, typename T>
template<shading::uniform U, typename T>
void set_uniform(const T& value) const;
[[nodiscard]] attribute_support_type check_attribute_support(std::span<const shader_uniform> attributes) const;
/*[[nodiscard]] attribute_support_type check_attribute_support(std::span<const shader_uniform> attributes) const;
[[nodiscard]] uniform_support_type check_uniform_support(std::span<const shader_uniform> uniforms) const;
[[nodiscard]] uniform_support_type check_uniform_support(std::span<const shader_uniform> uniforms) const;*/
[[nodiscard]] bool valid() const;

View File

@@ -7,9 +7,9 @@ namespace zgl
struct material_metadata
{
texture_handle ambient_color_texture_handle;
texture_handle diffuse_color_texture_handle;
texture_handle specular_color_texture_handle;
texture_handle specular_filter_texture_handle;
texture_handle diffuse_filter_texture_handle;
texture_handle specular_filter_texture_handle;
texture_handle shininess_texture_handle;
texture_handle alpha_texture_handle;
texture_handle bump_texture_handle;

View File

@@ -1,13 +1,15 @@
#pragma once
#include "opengl/shading/features/generic_features.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl
{
struct preprocessed_shader_source_metadata
{
shading::features::generic::type static_enabled{};
shading::features::generic::type dynamic_enable{};
shading::features::generic::type string_count{};
assets::shader_components::flags static_enabled{};
assets::shader_components::flags dynamic_enable{};
// Use same integer type as it guarantees good alignment.
// (even an unsigned byte should hold the maximum number of defines.)
assets::shader_components::flags string_count{};
};
}

View File

@@ -1,16 +1,17 @@
#pragma once
#include "opengl/shading/model_geometry.hpp"
#include "opengl/shading/shader_stage.hpp"
#include "opengl/shading/features/generic_features.hpp"
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl
{
struct shader_metadata
{
shading::model_geometry::types geometry;
shading::stage::types stage;
shading::features::generic::type static_enabled{};
shading::features::generic::type dynamic_enable{};
assets::model_geometry::types geometry_type;
assets::shader_components::stage stage;
assets::shader_components::flags static_enabled{};
assets::shader_components::flags dynamic_enable{};
};
}

View File

@@ -1,15 +1,16 @@
#pragma once
#include "opengl/shading/model_geometry.hpp"
#include "opengl/shading/features/generic_features.hpp"
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl {
namespace zgl
{
struct shader_program_metadata
{
shading::model_geometry::types geometry;
shading::features::generic::type static_enabled{};
shading::features::generic::type dynamic_enable{};
assets::model_geometry::types geometry_type;
assets::shader_components::stage static_enabled{};
assets::shader_components::stage dynamic_enable{};
};
}

View File

@@ -1,12 +1,12 @@
#pragma once
#include "opengl/shading/features/generic_features.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl
{
struct shader_set_metadata
{
shading::features::generic::type static_enabled{};
shading::features::generic::type dynamic_enable{};
assets::shader_components::flags static_enabled{};
assets::shader_components::flags dynamic_enable{};
};
}

View File

@@ -1,91 +1,18 @@
#pragma once
#include <limits>
#include <utility>
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
#include "../shading/model_geometry.hpp"
#include "../shading/shader_stage.hpp"
#include "../shading/features/mesh_features.hpp"
#include "../shading/features/point_cloud_features.hpp"
#include "../shading/features/generic_features.hpp"
#include <algorithm>
// TODO move implementation to .ipp file
namespace zgl
{
template<typename T>
struct shader_features_set
{
T features, static_enable, dynamic_enable;
template<typename U>
[[nodiscard]] shader_features_set<U> cast() const noexcept
{
return {
.features = static_cast<U>(features),
.static_enable = static_cast<U>(static_enable),
.dynamic_enable = static_cast<U>(dynamic_enable)
};
}
// TODO this may not compile
[[nodiscard]] bool operator==(const shader_features_set& other) const noexcept = default;
};
struct shader_source_metadata
{
union combined_feature_set_type {
shader_features_set<shading::features::mesh::flags> mesh;
shader_features_set<shading::features::point_cloud::flags> point_cloud;
};
using generic_feature_set_type = shader_features_set<shading::features::generic::type>;
shading::model_geometry::types geometry;
combined_feature_set_type feature_set;
shading::stage::types stage;
[[nodiscard]] generic_feature_set_type generic_feature_set() const noexcept
{
switch (geometry)
{
case shading::model_geometry::types::mesh:
return feature_set.mesh.cast<shading::features::generic::type>();
case shading::model_geometry::types::point_cloud:
return feature_set.point_cloud.cast<shading::features::generic::type>();
default:
std::unreachable();
}
}
void from_generic_feature_set(const generic_feature_set_type& generic_feature_set) noexcept
{
switch (geometry)
{
case shading::model_geometry::types::mesh:
feature_set.mesh = generic_feature_set.cast<shading::features::mesh::flags>();
case shading::model_geometry::types::point_cloud:
feature_set.point_cloud = generic_feature_set.cast<shading::features::point_cloud::flags>();
}
std::unreachable();
}
bool operator==(const shader_source_metadata& other) const noexcept
{
if (this->stage != other.stage)
{
return false;
}
if (this->geometry != other.geometry)
{
return false;
}
return this->generic_feature_set() == other.generic_feature_set();
}
assets::model_geometry::types geometry_type;
assets::shader_components::stage stage;
assets::shader_components::flags components{};
assets::shader_components::flags static_enable{};
assets::shader_components::flags dynamic_enable{};
};
}

View File

@@ -21,16 +21,18 @@ struct type
namespace indices
{
using type = ztu::u8;
constexpr inline type face = 0;
constexpr inline type line = 1;
constexpr inline type point = 2;
constexpr inline type luminance = 3;
constexpr inline type color = 4;
constexpr inline type alpha = 5;
constexpr inline type lighting = 6;
constexpr inline type texture = 7;
constexpr inline type uniform_color = 8;
enum : z3d::size
{
face,
line,
point,
luminance,
color,
alpha,
lighting,
texture,
uniform_color
};
}
enum class flags : std::uint16_t

View File

@@ -23,14 +23,16 @@ struct type
namespace indices
{
using type = ztu::u8;
constexpr inline type square = 0;
constexpr inline type lighting = 1;
constexpr inline type luminance = 2;
constexpr inline type color = 3;
constexpr inline type alpha = 4;
constexpr inline type uniform_color = 5;
constexpr inline type rainbow = 6;
enum : z3d::size
{
square,
lighting,
luminance,
color,
alpha,
uniform_color,
rainbow
};
}
enum class flags : std::uint8_t

View File

@@ -1,57 +1,14 @@
#pragma once
#include "opengl/shading/model_geometry.hpp"
#include "opengl/shading/features/generic_features.hpp"
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl::shading
{
struct shader_program_requirements
{
model_geometry::types geometry;
features::generic::type features;
assets::model_geometry::types geometry_type;
assets::shader_components::flags components{};
};
}
/*
struct shader_program_metadata
{
using generic_feature_type = std::common_type_t<
std::underlying_type_t<features::mesh::flags>,
std::underlying_type_t<features::point_cloud::flags>
>;
static constexpr auto geometry_bits = static_cast<std::size_t>(std::bit_width(geometry::names.size()));
static constexpr auto feature_bits = sizeof(generic_feature_type) * 8 - geometry_bits;
explicit shader_program_metadata(const features::mesh::flags static_enabled, const features::mesh::flags dynamic_enable) :
shader_program_metadata(
geometry::types::mesh,
static_cast<generic_feature_type>(static_enabled),
static_cast<generic_feature_type>(dynamic_enable)
) {}
explicit shader_program_metadata(const features::point_cloud::flags static_enabled, const features::point_cloud::flags dynamic_enable) :
shader_program_metadata(
geometry::types::point_cloud,
static_cast<generic_feature_type>(static_enabled),
static_cast<generic_feature_type>(dynamic_enable)
) {}
shader_program_metadata(const geometry::types geometry_type, const generic_feature_type static_enabled, generic_feature_type dynamic_enable) :
m_geometry_type{ geometry_type }, m_static_enabled{ static_enabled }, m_dynamic_enable{ dynamic_enable } {}
[[nodiscard]] auto operator<=>(const shader_program_metadata& other) const noexcept
{
return (
std::tie(this->m_geometry_type, std::popcount(this->m_static_enabled), std::popcount(this->m_dynamic_enable)) <=>
std::tie(other.m_geometry_type, std::popcount(other.m_static_enabled), std::popcount(other.m_dynamic_enable))
);
}
[[nodiscard]] bool operator==(const shader_program_metadata& other) const noexcept = default;
geometry::types m_geometry_type : geometry_bits;
generic_feature_type m_static_enabled : feature_bits;
generic_feature_type m_dynamic_enable;
};*/

View File

@@ -1,8 +1,16 @@
#pragma once
#include "shader_source_requirements.hpp"
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl::shading
{
using shader_requirements = shader_source_requirements;
struct shader_requirements
{
assets::model_geometry::types geometry_type;
assets::shader_components::stage stage;
assets::shader_components::flags components{};
};
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include "opengl/shading/features/generic_features.hpp"
namespace zgl::shading
{
struct shader_set_requirements
{
model_geometry::types geometry;
features::generic::type features;
};
}

View File

@@ -1,16 +0,0 @@
#pragma once
#include "opengl/shading/model_geometry.hpp"
#include "opengl/shading/shader_stage.hpp"
#include "opengl/shading/features/generic_features.hpp"
namespace zgl::shading
{
struct shader_source_requirements
{
model_geometry::types geometry;
stage::types stage;
features::generic::type features;
};
}

View File

@@ -11,34 +11,34 @@ namespace zgl::shading::mesh_sampler_uniforms
enum class flags : std::uint16_t
{
none = 0,
ambient_color_texture = 1 << 0,
diffuse_color_texture = 1 << 1,
specular_color_texture = 1 << 2,
specular_filter_texture = 1 << 0,
diffuse_filter_texture = 1 << 1,
specular_filter_texture = 1 << 2,
shininess_texture = 1 << 3,
alpha_texture = 1 << 4,
bump_texture = 1 << 5
};
constexpr inline auto ambient_color_texture = sampler_uniform{ 0 };
constexpr inline auto diffuse_color_texture = sampler_uniform{ 1 };
constexpr inline auto specular_color_texture = sampler_uniform{ 2 };
constexpr inline auto specular_filter_texture = sampler_uniform{ 0 };
constexpr inline auto diffuse_filter_texture = sampler_uniform{ 1 };
constexpr inline auto specular_filter_texture = sampler_uniform{ 2 };
constexpr inline auto shininess_texture = sampler_uniform{ 3 };
constexpr inline auto alpha_texture = sampler_uniform{ 4 };
constexpr inline auto bump_texture = sampler_uniform{ 5 };
constexpr inline auto all = std::array{
ambient_color_texture,
diffuse_color_texture,
specular_color_texture,
specular_filter_texture,
diffuse_filter_texture,
specular_filter_texture,
shininess_texture,
alpha_texture,
bump_texture
};
constexpr inline auto names = std::array{
"ambient_color_texture",
"diffuse_color_texture",
"specular_color_texture",
"specular_filter_texture",
"diffuse_filter_texture",
"specular_filter_texture",
"shininess_texture",
"alpha_texture",
"bump_texture"