omni/graph/exec/unstable/IExecutionStateInfo.h
File members: omni/graph/exec/unstable/IExecutionStateInfo.h
// Copyright (c) 2022-2023, 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 <omni/Expected.h>
#include <omni/graph/exec/unstable/Assert.h>
#include <omni/graph/exec/unstable/IBase.h>
#include <omni/graph/exec/unstable/Span.h>
#include <omni/graph/exec/unstable/Stamp.h>
#include <omni/graph/exec/unstable/Types.h>
#include <memory>
namespace omni
{
namespace graph
{
namespace exec
{
namespace unstable
{
// forward declarations needed by interface declaration
class IExecutionStateInfo;
class IExecutionStateInfo_abi;
class IExecutionStateInfo_abi : public omni::core::Inherits<omni::graph::exec::unstable::IBase,
OMNI_TYPE_ID("omni.graph.exec.unstable.IExecutionStateInfo")>
{
protected:
virtual bool needsCompute_abi(Stamp execVersion) noexcept = 0;
virtual void requestCompute_abi() noexcept = 0;
virtual void setComputed_abi() noexcept = 0;
virtual SyncStamp getExecutionStamp_abi() noexcept = 0;
virtual bool setExecutionStamp_abi(Stamp execVersion) noexcept = 0;
virtual OMNI_ATTR("nodiscard") omni::core::Result
getNodeData_abi(NodeDataKey key,
OMNI_ATTR("out, not_null") omni::core::TypeId* outTypeId,
OMNI_ATTR("out, not_null, *out, *in") void** outPtr,
OMNI_ATTR("out, not_null") uint64_t* outItemSize,
OMNI_ATTR("out, not_null") uint64_t* outItemCount) noexcept = 0;
virtual void setNodeData_abi(NodeDataKey key,
omni::core::TypeId typeId,
OMNI_ATTR("in, out") void* data,
uint64_t itemSize,
uint64_t itemCount,
OMNI_ATTR("in, out") NodeDataDeleterFn* deleter) noexcept = 0;
};
} // namespace unstable
} // namespace exec
} // namespace graph
} // namespace omni
// generated API declaration
#define OMNI_BIND_INCLUDE_INTERFACE_DECL
#include <omni/graph/exec/unstable/IExecutionStateInfo.gen.h>
class omni::graph::exec::unstable::IExecutionStateInfo
: public omni::core::Generated<omni::graph::exec::unstable::IExecutionStateInfo_abi>
{
public:
template <typename T>
CARB_NODISCARD inline omni::expected<Span<T>, omni::core::Result> getNodeDataAs(omni::core::TypeId desiredType,
NodeDataKey key) noexcept;
template <typename SpecifiedT, typename DataT>
inline DataT* setNodeData(omni::core::TypeId itemType, NodeDataKey key, std::unique_ptr<DataT> data) noexcept;
using Generated<IExecutionStateInfo_abi>::setNodeData;
};
#ifndef DOXYGEN_BUILD // templates and doxygen are not friends (remove this line to see why)
template <typename T>
inline omni::expected<omni::graph::exec::unstable::Span<T>, omni::core::Result> omni::graph::exec::unstable::
IExecutionStateInfo::getNodeDataAs(omni::core::TypeId desiredType, NodeDataKey key) noexcept
{
omni::core::TypeId outType;
void* outPtr;
uint64_t outItemSize, outItemCount;
auto result = getNodeData_abi(key, &outType, &outPtr, &outItemSize, &outItemCount);
if (OMNI_SUCCEEDED(result) && outPtr)
{
OMNI_GRAPH_EXEC_FATAL_UNLESS(outType == desiredType);
OMNI_GRAPH_EXEC_FATAL_UNLESS(outItemSize == sizeof(T));
}
OMNI_GRAPH_EXEC_RETURN_EXPECTED(Span<T>(reinterpret_cast<T*>(outPtr), outItemCount), result);
}
template <typename SpecifiedT, typename DataT>
inline DataT* omni::graph::exec::unstable::IExecutionStateInfo::setNodeData(omni::core::TypeId desiredType,
NodeDataKey key,
std::unique_ptr<DataT> data) noexcept
{
static_assert(std::is_same<SpecifiedT, DataT>::value, "given TypeId does not match the data type");
static_assert(!std::is_array<DataT>::value, "setting arrays as node data via unique_ptr not yet implemented");
setNodeData_abi(key, desiredType, data.get(), sizeof(DataT), 1,
[](void* p)
{
typename std::unique_ptr<DataT>::deleter_type deleter;
deleter(reinterpret_cast<DataT*>(p));
});
return data.release(); // now safe to release ownership
}
#endif // DOXYGEN_BUILD
#define OMNI_GRAPH_EXEC_GET_NODE_DATA_AS(context_, type_, ...) \
context_->getNodeDataAs<type_>(CARB_HASH_STRING(CARB_STRINGIFY(type_)), __VA_ARGS__)
// the ugly macro above is used to hash the type of the data at compile time.
//
// it's possible to get the type of data at compile time by inspecting the function name (e.g. __FUNCSIG__ and
// __PRETTY_FUNCTION__). however __PRETTY_FUNCTION__ was not a constexpr until GCC 8. omniverse currently uses GCC 7
// so were left with this hack.
//
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66639
#define OMNI_GRAPH_EXEC_SET_NODE_DATA(context_, type_, ...) \
context_->setNodeData<type_>(CARB_HASH_STRING(CARB_STRINGIFY(type_)), __VA_ARGS__)
// the ugly macro above is used to hash the type of the data at compile time.
//
// it's possible to get the type of data at compile time by inspecting the function name (e.g. __FUNCSIG__ and
// __PRETTY_FUNCTION__). however __PRETTY_FUNCTION__ was not a constexpr until GCC 8. omniverse currently uses GCC 7
// so were left with this hack.
//
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66639
// generated API implementation
#define OMNI_BIND_INCLUDE_INTERFACE_IMPL
#include <omni/graph/exec/unstable/IExecutionStateInfo.gen.h>