// Copyright (c) 2021, 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.
//

#include "OgnRenderPreprocessEntryDatabase.h"

#include <omni/graph/core/NodeTypeRegistrar.h>
#include <omni/graph/core/GpuInteropEntryUserData.h>
#include <omni/graph/core/iComputeGraph.h>

namespace omni
{
namespace graph
{
namespace core
{

// OmniGraph nodes executed as a render preprocess need to be connected downstream of an entry point node
// in order to be scheduled as part of the render graph.
// Scheduling of cuda interop nodes begins with one of these entry nodes, which passes data (e.g. a cuda stream
// identifier) to downstream nodes.

class OgnRenderPreprocessEntry
{
public:
    static bool compute(OgnRenderPreprocessEntryDatabase& db)
    {
        CARB_PROFILE_ZONE(1, "OgnRenderPreprocessEntry::compute");

        GpuInteropCudaEntryUserData* userData = static_cast<GpuInteropCudaEntryUserData*>(db.abi_node().iNode->getUserData(db.abi_node()));
        if (!userData)
            return false;

        db.outputs.stream() = (uint64_t)userData->cudaStream;
        db.outputs.simTime() = userData->simTime;
        db.outputs.hydraTime() = userData->hydraTime;

        return true;
    }

    static void initializeType(const NodeTypeObj& nodeTypeObj)
    {
        OgnRenderPreprocessEntryDatabase::initializeType(nodeTypeObj);
    }
};

REGISTER_OGN_NODE()
}
}
}
