HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderTask.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HDX_RENDER_TASK_H
25 #define PXR_IMAGING_HDX_RENDER_TASK_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdx/api.h"
30 #include "pxr/imaging/hdx/task.h"
31 #include "pxr/imaging/hdx/renderSetupTask.h" // for short-term compatibility.
33 
34 #include <memory>
35 
37 
38 
39 class HdSceneDelegate;
40 
41 using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
42 using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
43 using HdxRenderSetupTaskSharedPtr = std::shared_ptr<class HdxRenderSetupTask>;
44 
45 /// \class HdxRenderTask
46 ///
47 /// A task for rendering geometry to pixels.
48 ///
49 /// Rendering state management can be handled two ways:
50 /// 1.) An application can create an HdxRenderTask and pass it the
51 /// HdxRenderTaskParams struct as "params".
52 /// 2.) An application can create an HdxRenderSetupTask and an
53 /// HdxRenderTask, and pass params to the setup task. In this case
54 /// the setup task must run first.
55 ///
56 /// Parameter unpacking is handled by HdxRenderSetupTask; in case #1,
57 /// HdxRenderTask creates a dummy setup task internally to manage the sync
58 /// process.
59 ///
60 /// Case #2 introduces complexity; the benefit is that by changing which
61 /// setup task you run before the render task, you can change the render
62 /// parameters without incurring a hydra sync or rebuilding any resources.
63 ///
64 class HdxRenderTask : public HdxTask
65 {
66 public:
67  HDX_API
68  HdxRenderTask(HdSceneDelegate* delegate, SdfPath const& id);
69 
70  HDX_API
71  ~HdxRenderTask() override;
72 
73  /// Hooks for progressive rendering (delegated to renderpasses).
74  HDX_API
75  bool IsConverged() const override;
76 
77  /// Prepare the tasks resources
78  HDX_API
79  void Prepare(HdTaskContext* ctx,
80  HdRenderIndex* renderIndex) override;
81 
82  /// Execute render pass task
83  HDX_API
84  void Execute(HdTaskContext* ctx) override;
85 
86  /// Collect Render Tags used by the task.
87  HDX_API
88  const TfTokenVector &GetRenderTags() const override;
89 
90 protected:
91  /// Sync the render pass resources
92  HDX_API
93  void _Sync(HdSceneDelegate* delegate,
94  HdTaskContext* ctx,
95  HdDirtyBits* dirtyBits) override;
96 
97  HDX_API
99 
100  // XXX: Storm specific API
101  // While HdDrawItem is currently a core-Hydra concept, it'll be moved
102  // to Storm. Until then, allow querying the render pass to know if there's
103  // draw submission work.
104 
105  // Returns whether the render pass has any draw items to submit.
106  // For non-Storm backends, this returns true.
107  // When using with Storm tasks, make sure to call it after
108  // HdxRenderTask::Prepare().
109  HDX_API
110  bool _HasDrawItems() const;
111 
112 private:
113  HdRenderPassSharedPtr _pass;
114  TfTokenVector _renderTags;
115 
116  // Optional internal render setup task, for params unpacking.
117  HdxRenderSetupTaskSharedPtr _setupTask;
118 
119  // XXX: Storm specific API
120  // Setup additional state that HdStRenderPassState requires.
121  void _SetHdStRenderPassState(HdTaskContext *ctx,
122  HdStRenderPassState *renderPassState);
123 
124  // Inspect the AOV bindings to determine if any of them need to be cleared.
125  bool _NeedToClearAovs(HdRenderPassStateSharedPtr const &renderPassState)
126  const;
127 
128  HdxRenderTask() = delete;
129  HdxRenderTask(const HdxRenderTask &) = delete;
130  HdxRenderTask &operator =(const HdxRenderTask &) = delete;
131 };
132 
133 
135 
136 #endif //PXR_IMAGING_HDX_RENDER_TASK_H
std::shared_ptr< class HdRenderPassState > HdRenderPassStateSharedPtr
Definition: engine.h:42
std::shared_ptr< class HdRenderPass > HdRenderPassSharedPtr
Definition: engine.h:41
uint32_t HdDirtyBits
Definition: types.h:158
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
HDX_API ~HdxRenderTask() override
HDX_API HdRenderPassStateSharedPtr _GetRenderPassState(HdTaskContext *ctx) const
#define HDX_API
Definition: api.h:40
HDX_API bool IsConverged() const override
Hooks for progressive rendering (delegated to renderpasses).
HDX_API const TfTokenVector & GetRenderTags() const override
Collect Render Tags used by the task.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
Definition: path.h:290
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:77
Definition: task.h:44
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
HDX_API bool _HasDrawItems() const
std::shared_ptr< class HdxRenderSetupTask > HdxRenderSetupTaskSharedPtr
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDX_API void Execute(HdTaskContext *ctx) override
Execute render pass task.
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.