Loading...
Searching...
No Matches
visualizeAovTask.h
1//
2// Copyright 2021 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef HDX_VISUALIZE_AOV_TASK_H
8#define HDX_VISUALIZE_AOV_TASK_H
9
10#include "pxr/pxr.h"
11#include "pxr/base/gf/vec3i.h"
12#include "pxr/imaging/hdx/api.h"
13#include "pxr/imaging/hdx/task.h"
14#include "pxr/imaging/hdx/tokens.h"
15#include "pxr/imaging/hgi/attachmentDesc.h"
16#include "pxr/imaging/hgi/buffer.h"
17#include "pxr/imaging/hgi/graphicsPipeline.h"
18#include "pxr/imaging/hgi/resourceBindings.h"
19#include "pxr/imaging/hgi/shaderProgram.h"
20#include "pxr/imaging/hgi/texture.h"
21#include "pxr/usd/sdf/path.h"
22
23PXR_NAMESPACE_OPEN_SCOPE
24
26
46{
47public:
49
50 HDX_API
51 HdxVisualizeAovTask(HdSceneDelegate* delegate, SdfPath const& id);
52
53 HDX_API
54 ~HdxVisualizeAovTask() override;
55
56 HDX_API
57 void Prepare(HdTaskContext* ctx,
58 HdRenderIndex* renderIndex) override;
59
60 HDX_API
61 void Execute(HdTaskContext* ctx) override;
62
63protected:
64 HDX_API
65 void _Sync(HdSceneDelegate* delegate,
66 HdTaskContext* ctx,
67 HdDirtyBits* dirtyBits) override;
68
69private:
70 // Enumeration of visualization kernels
71 enum VizKernel {
72 VizKernelDepth = 0,
73 VizKernelId,
74 VizKernelNormal,
75 VizKernelFallback,
76 VizKernelNone
77 };
78
79 HdxVisualizeAovTask() = delete;
81 HdxVisualizeAovTask &operator =(const HdxVisualizeAovTask &) = delete;
82
83 // Returns true if the enum member was updated, indicating that the kernel
84 // to be used has changed.
85 bool _UpdateVizKernel(TfToken const &aovName);
86
87 // Returns a token used in sampling the texture based on the kernel used.
88 TfToken const& _GetTextureIdentifierForShader() const;
89
90 // Returns the fragment shader mixin based on the kernel used.
91 TfToken const& _GetFragmentMixin() const;
92
93 // ------------- Hgi resource creation/deletion utilities ------------------
94 // Utility function to create the GL program for color correction
95 bool _CreateShaderResources(HgiTextureDesc const& inputAovTextureDesc);
96
97 // Utility function to create buffer resources.
98 bool _CreateBufferResources();
99
100 // Utility to create resource bindings
101 bool _CreateResourceBindings(HgiTextureHandle const& inputAovTexture);
102
103 // Utility to create a pipeline
104 bool _CreatePipeline(HgiTextureDesc const& outputTextureDesc);
105
106 // Utility to create a texture sampler
107 bool _CreateSampler(HgiTextureDesc const& inputAovTextureDesc);
108
109 // Create texture to write the colorized results into.
110 bool _CreateOutputTexture(GfVec3i const &dimensions);
111
112 // Destroy shader program and the shader functions it holds.
113 void _DestroyShaderProgram();
114
115 // Print shader compile errors.
116 void _PrintCompileErrors();
117 // -------------------------------------------------------------------------
118
119 // Readback the depth AOV on the CPU to update min, max values.
120 void _UpdateMinMaxDepth(HgiTextureHandle const &inputAovTexture);
121
122 // Execute the appropriate kernel and update the task context 'color' entry.
123 void _ApplyVisualizationKernel(HgiTextureHandle const& outputTexture);
124
125 // Kernel dependent resources
126 HgiTextureHandle _outputTexture;
127 GfVec3i _outputTextureDimensions;
128 HgiAttachmentDesc _outputAttachmentDesc;
129 HgiShaderProgramHandle _shaderProgram;
130 HgiResourceBindingsHandle _resourceBindings;
132
133 // Kernel independent resources
134 HgiBufferHandle _indexBuffer;
135 HgiBufferHandle _vertexBuffer;
136 HgiSamplerHandle _sampler;
137
138 float _screenSize[2];
139 float _minMaxDepth[2];
140 VizKernel _vizKernel;
141};
142
143
154{
155 HDX_API
157
158 TfToken aovName;
159};
160
161// VtValue requirements
162HDX_API
163std::ostream& operator<<(std::ostream& out, const HdxVisualizeAovTaskParams& pv);
164HDX_API
165bool operator==(const HdxVisualizeAovTaskParams& lhs,
166 const HdxVisualizeAovTaskParams& rhs);
167HDX_API
168bool operator!=(const HdxVisualizeAovTaskParams& lhs,
169 const HdxVisualizeAovTaskParams& rhs);
170
171PXR_NAMESPACE_CLOSE_SCOPE
172
173#endif
Basic type for a vector of 3 int components.
Definition: vec3i.h:44
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:105
Adapter class providing data exchange with the client scene graph.
Base class for (some) tasks in Hdx that provides common progressive rendering and Hgi functionality.
Definition: task.h:28
A task for visualizing non-color AOVs such as depth, normals, primId.
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare Phase: Resolve bindings and manage resources.
HDX_API void Execute(HdTaskContext *ctx) override
Execute Phase: Runs the task.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
aovName: The name of the aov to visualize.
Describes the properties of a framebuffer attachment.
Describes the properties needed to create a GPU texture.
Definition: texture.h:91