carb/Interface.h

File members: carb/Interface.h

// Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//

#pragma once

#include "Version.h"

#include <type_traits>

namespace carb
{
struct InterfaceDesc
{
    const char* name = nullptr;
    Version version = { 0, 0 };
};
CARB_ASSERT_INTEROP_SAFE(InterfaceDesc);
} // namespace carb

#define CARB_PLUGIN_INTERFACE(name, major, minor)                                                                      \
                                                                                                                \
    static constexpr carb::InterfaceDesc getInterfaceDesc() noexcept                                                   \
    {                                                                                                                  \
        return carb::InterfaceDesc{ name, { major, minor } };                                                          \
    }                                                                                                                  \
                                                                                                                \
    static constexpr carb::InterfaceDesc getLatestInterfaceDesc() noexcept                                             \
    {                                                                                                                  \
        return carb::InterfaceDesc{ name, { major, minor } };                                                          \
    }

#define CARB_HEXVERSION(major, minor) (((major) << 16) | (minor))

#ifdef DOXYGEN_BUILD
#    define CARB_VERSION_ATLEAST(ver, major, minor) (1)
#else
#    define CARB_VERSION_ATLEAST(ver, major, minor) ((ver) >= CARB_HEXVERSION(major, minor))
#endif

#define CARB_PLUGIN_INTERFACE_EX(name, latestVersion, currentVersion)                                                  \
    static_assert((latestVersion) >= (currentVersion), "CARB_PLUGIN_INTERFACE_EX has mismatched versions");            \
                                                                                                                \
    static constexpr carb::InterfaceDesc getInterfaceDesc() noexcept                                                   \
    {                                                                                                                  \
        return carb::InterfaceDesc{ name, carb::fromHexVersion(currentVersion) };                                      \
    }                                                                                                                  \
                                                                                                                \
    static constexpr carb::InterfaceDesc getLatestInterfaceDesc() noexcept                                             \
    {                                                                                                                  \
        return carb::InterfaceDesc{ name, carb::fromHexVersion(latestVersion) };                                       \
    }

// note that this needs to be included last to avoid a circular include dependency in
// 'carb/Defines.h'.  A lot of source files and tests depend on 'carb/Interface.h'
// also pulling in 'carb/Defines.h'.  Since nothing here strictly requires 'Defines.h',
// we'll just defer it's include until everything else useful in here has been defined.
#include "Defines.h"