Panda3D
Loading...
Searching...
No Matches
computeNode.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file computeNode.h
10 * @author rdb
11 * @date 2014-06-19
12 */
13
14#ifndef COMPUTENODE_H
15#define COMPUTENODE_H
16
17#include "pandabase.h"
18#include "pandaNode.h"
19#include "callbackObject.h"
20#include "callbackNode.h"
21#include "pointerTo.h"
22
23/**
24 * A special node, the sole purpose of which is to invoke a dispatch operation
25 * on the assigned compute shader.
26 */
27class EXPCL_PANDA_PGRAPHNODES ComputeNode : public PandaNode {
28PUBLISHED:
29 explicit ComputeNode(const std::string &name);
30
31 INLINE void add_dispatch(const LVecBase3i &num_groups);
32 INLINE void add_dispatch(int num_groups_x, int num_groups_y, int num_groups_z);
33
34 INLINE size_t get_num_dispatches() const;
35 INLINE const LVecBase3i &get_dispatch(size_t i) const;
36 INLINE void set_dispatch(size_t i, const LVecBase3i &num_groups);
37 INLINE void insert_dispatch(size_t i, const LVecBase3i &num_groups);
38 INLINE void remove_dispatch(size_t i);
39 INLINE void clear_dispatches();
40
41 MAKE_SEQ(get_dispatches, get_num_dispatches, get_dispatch);
43
44public:
45 ComputeNode(const ComputeNode &copy);
46
47 virtual PandaNode *make_copy() const;
48 virtual bool safe_to_combine() const;
49
50 virtual bool is_renderable() const;
51 virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data);
52
53 virtual void output(std::ostream &out) const;
54
55public:
56 class EXPCL_PANDA_PGRAPHNODES Dispatcher : public CallbackObject {
57 friend class ComputeNode;
58 public:
59 ALLOC_DELETED_CHAIN(Dispatcher);
60 Dispatcher();
61 Dispatcher(const Dispatcher &copy);
62
63 virtual void do_callback(CallbackData *cbdata);
64
65 typedef pvector<LVecBase3i> Dispatches;
66
67 class EXPCL_PANDA_PGRAPHNODES CData : public CycleData {
68 public:
69 INLINE CData();
70 INLINE CData(const CData &copy);
71 virtual CycleData *make_copy() const;
72 virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
73 virtual void fillin(DatagramIterator &scan, BamReader *manager);
74 virtual TypeHandle get_parent_type() const {
75 return CallbackNode::get_class_type();
76 }
77
78 Dispatches _dispatches;
79 };
80
82 typedef CycleDataReader<CData> CDReader;
83 typedef CycleDataWriter<CData> CDWriter;
84
85 };
86
87private:
88 // One per ComputeNode.
89 PT(Dispatcher) _dispatcher;
90
91public:
92 static void register_with_read_factory();
93 virtual void write_datagram(BamWriter *manager, Datagram &dg);
94
95protected:
96 static TypedWritable *make_from_bam(const FactoryParams &params);
97 void fillin(DatagramIterator &scan, BamReader *manager);
98
99public:
100 static TypeHandle get_class_type() {
101 return _type_handle;
102 }
103 static void init_type() {
104 PandaNode::init_type();
105 register_type(_type_handle, "ComputeNode",
106 PandaNode::get_class_type());
107 }
108 virtual TypeHandle get_type() const {
109 return get_class_type();
110 }
111 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
112
113private:
114 static TypeHandle _type_handle;
115};
116
117#include "computeNode.I"
118
119#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
This is a generic data block that is passed along to a CallbackObject when a callback is made.
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition computeNode.h:74
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is called by make_from_bam to read in all of the relevant data from the BamFil...
virtual void do_callback(CallbackData *cbdata)
Asks the GSG to dispatch the compute shader.
get_dispatch
Returns the group counts of the nth dispatch associated with this object.
Definition computeNode.h:41
void add_dispatch(const LVecBase3i &num_groups)
Adds a dispatch command with the given number of work groups in the X, Y, and Z dimensions.
Definition computeNode.I:20
get_num_dispatches
Returns the number of times add_dispatch has been called on this object.
Definition computeNode.h:41
void clear_dispatches()
Removes all dispatch commands.
Definition computeNode.I:40
ComputeNode(const std::string &name)
Creates a ComputeNode with the given name.
insert_dispatch
Inserts a dispatch command with the given number of work groups in the X, Y, and Z dimensions at the ...
Definition computeNode.h:42
virtual void output(std::ostream &out) const
Writes a brief description of the node to the indicated output stream.
remove_dispatch
Erases the given dispatch index from the list.
Definition computeNode.h:42
set_dispatch
Sets the group counts of the nth dispatch associated with this object.
Definition computeNode.h:42
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data)
Adds the node's contents to the CullResult we are building up during the cull traversal,...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...