Panda3D
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  */
27 class EXPCL_PANDA_PGRAPHNODES ComputeNode : public PandaNode {
28 PUBLISHED:
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);
42  MAKE_SEQ_PROPERTY(dispatches, get_num_dispatches, get_dispatch, set_dispatch, remove_dispatch, insert_dispatch);
43 
44 public:
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 
55 public:
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 
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 
81  PipelineCycler<CData> _cycler;
84 
85  };
86 
87 private:
88  // One per ComputeNode.
89  PT(Dispatcher) _dispatcher;
90 
91 public:
92  static void register_with_read_factory();
93  virtual void write_datagram(BamWriter *manager, Datagram &dg);
94 
95 protected:
96  static TypedWritable *make_from_bam(const FactoryParams &params);
97  void fillin(DatagramIterator &scan, BamReader *manager);
98 
99 public:
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 
113 private:
114  static TypeHandle _type_handle;
115 };
116 
117 #include "computeNode.I"
118 
119 #endif
CallbackData
This is a generic data block that is passed along to a CallbackObject when a callback is made.
Definition: callbackData.h:29
pandaNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CycleData
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
pvector< LVecBase3i >
ComputeNode::Dispatcher::CData::get_parent_type
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: computeNode.h:74
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
ComputeNode::Dispatcher
Definition: computeNode.h:56
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
CallbackObject
This is a generic object that can be assigned to a callback at various points in the rendering proces...
Definition: callbackObject.h:28
CullTraverser
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
CallbackObject::do_callback
virtual void do_callback(CallbackData *cbdata)
This method called when the callback is triggered; it *replaces* the original function.
Definition: callbackObject.cxx:33
PandaNode::add_for_draw
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,...
Definition: pandaNode.cxx:472
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PandaNode::is_renderable
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pandaNode.cxx:462
CycleData::write_datagram
virtual void write_datagram(BamWriter *, Datagram &) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: cycleData.cxx:32
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
CycleDataWriter
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
Definition: cycleDataWriter.h:34
ComputeNode
A special node, the sole purpose of which is to invoke a dispatch operation on the assigned compute s...
Definition: computeNode.h:27
CycleDataReader
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
Definition: cycleDataReader.h:35
CullTraverserData
This collects together the pieces of data that are accumulated for each node while walking the scene ...
Definition: cullTraverserData.h:40
CycleData::fillin
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition: cycleData.cxx:58
callbackNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
computeNode.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PandaNode::make_copy
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:481
callbackObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PandaNode
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ComputeNode::Dispatcher::CData
Definition: computeNode.h:67
PipelineCycler< CData >
PandaNode::safe_to_combine
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
Definition: pandaNode.cxx:228