TeamWisp / WispRenderer

RTX Ray Tracing Renderer, made by Y3 students at Breda University of Applied Science
https://teamwisp.github.io
Apache License 2.0
202 stars 14 forks source link

frame_graph's FG_DEPS #340

Closed Nielsbishere closed 5 years ago

Nielsbishere commented 5 years ago

Is your request related to a problem? Please describe. FG_DEPS doesn't allow infinite expansion (only up to 6 dependencies) and requires the end-user to specify number of dependencies; which is redundant if using templates instead.

Describe the solution you'd like

fg_dep<DeferredMainTaskData, RTHybridData>();

where fg_dep:

namespace fg_deps
{
    using type = std::vector<std::reference_wrapper<const std::type_info>>;

    template<typename T, typename ...args>
    struct insert
    {
        static inline void exec(type& deps)
        {
            deps.push_back(typeid(T));
            fg_deps::insert<args...>::exec(deps);
        }
    };

    template<typename T>
    struct insert<T>
    {
        static inline void exec(type& deps)
        {
            deps.push_back(typeid(T));
        }
    };

    template<typename ...args>
    static inline type make() {
        type result;
        insert<args...>::exec(result);
        return result;
    }

}

template<typename ...args>
static const fg_deps::type& fg_dep()
{
    static fg_deps::type deps = fg_deps::make<args...>();
    return deps;
}

Describe alternatives you've considered Additional context N.A.

VZout commented 5 years ago

My solution to this was just:

template<class ...Ts>
std::vector<std::reference_wrapper<const std::type_info>> Deps() {
    return { (typeid(Ts))...};
}
Nielsbishere commented 5 years ago

Yeah that's way cleaner, I didn't know this was a way of calling functions with variadic arguments. Only used sizeof...() before; which is different.