#pragma once #include #include #include #include #include #include "hecl/Compilers.hpp" #include #include "../extern/boo/xxhash/xxhash.h" #define HECL_RUNTIME 1 namespace hecl { using AdditionalPipelineInfo = boo::AdditionalPipelineInfo; enum class StageTargetType { SourceText, Binary, Runtime }; enum class PipelineTargetType { StageSourceTextCollection, StageBinaryCollection, StageRuntimeCollection, FinalPipeline }; template class StageConverter; template class PipelineConverter; #if HECL_RUNTIME using FactoryCtx = boo::IGraphicsDataFactory::Context; #else struct FactoryCtx {}; #endif template class StageRep { public: using Platform = P; using Stage = S; }; template class PipelineRep { public: using Platform = P; }; class GeneralShader : public hecl::PipelineRep {}; class TessellationShader : public hecl::PipelineRep {}; template class StageSourceText : public StageRep { std::string_view m_text; uint64_t m_hash; public: static constexpr StageTargetType TargetType = StageTargetType::SourceText; static constexpr PipelineTargetType PipelineTarget = PipelineTargetType::StageSourceTextCollection; static constexpr bool HasHash = true; uint64_t Hash() const { return m_hash; } explicit StageSourceText(std::string_view text) : m_text(text), m_hash(XXH64(m_text.data(), m_text.size(), 0)) {} std::string_view text() const { return m_text; } }; template class StageBinary : public StageRep { StageBinaryData m_ownedData; const uint8_t* m_data = nullptr; size_t m_size = 0; uint64_t m_hash = 0; public: static constexpr StageTargetType TargetType = StageTargetType::Binary; static constexpr PipelineTargetType PipelineTarget = PipelineTargetType::StageBinaryCollection; static constexpr bool HasHash = true; uint64_t Hash() const { return m_hash; } StageBinary(const uint8_t* data, size_t size) : m_data(data), m_size(size) { m_hash = XXH64(m_data, m_size, 0); } StageBinary(StageBinaryData data, size_t size) : m_ownedData(std::move(data)), m_data(m_ownedData.get()), m_size(size) { m_hash = XXH64(m_data, m_size, 0); } explicit StageBinary(std::pair data) : StageBinary(data.first, data.second) {} StageBinary(StageConverter& conv, FactoryCtx& ctx, const StageSourceText& in) : StageBinary(CompileShader(in.text())) {} const uint8_t* data() const { return m_data; } size_t size() const { return m_size; } }; template class FinalPipeline; template using __IsStageSubclass = typename std::disjunction, T>, std::is_base_of, T>, std::is_base_of, T>, std::is_base_of, T>, std::is_base_of, T>>; template inline constexpr bool __IsStageSubclass_v = __IsStageSubclass::value; template class StageCollection; template