Loading...
Searching...
No Matches
colorCorrectionTask.h
1//
2// Copyright 2018 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_COLORCORRECTION_TASK_H
8#define HDX_COLORCORRECTION_TASK_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/sdf/path.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/graphicsCmds.h"
18#include "pxr/imaging/hgi/graphicsPipeline.h"
19#include "pxr/imaging/hgi/resourceBindings.h"
20#include "pxr/imaging/hgi/shaderProgram.h"
21#include "pxr/imaging/hgi/texture.h"
22
23#include <string>
24
25PXR_NAMESPACE_OPEN_SCOPE
26
32// OCIO resampling.
35{
36 HDX_API
38
39 // Switch between HdColorCorrectionTokens.
40 // We default to 'disabled' to be backwards compatible with clients that are
41 // still running with sRGB buffers.
42 TfToken colorCorrectionMode;
43
44 // 'display', 'view', 'colorspace' and 'look' are options the client may
45 // supply to configure OCIO. If one is not provided the default values
46 // is substituted. You can find the values for these strings inside the
47 // profile/config .ocio file. For example:
48 //
49 // displays:
50 // rec709g22:
51 // !<View> {name: studio, colorspace: linear, looks: studio_65_lg2}
52 //
53 std::string displayOCIO;
54 std::string viewOCIO;
55 std::string colorspaceOCIO;
56 std::string looksOCIO;
57
58 // The width, height and depth used for the GPU LUT 3d texture.
59 int lut3dSizeOCIO;
60
61 // The name of the aov to color correct
62 TfToken aovName;
63};
64
65
72{
73public:
75
76 HDX_API
78
79 HDX_API
80 ~HdxColorCorrectionTask() override;
81
83 HDX_API
84 void Prepare(HdTaskContext* ctx,
85 HdRenderIndex* renderIndex) override;
86
88 HDX_API
89 void Execute(HdTaskContext* ctx) override;
90
91protected:
93 HDX_API
94 void _Sync(HdSceneDelegate* delegate,
95 HdTaskContext* ctx,
96 HdDirtyBits* dirtyBits) override;
97
98private:
99 HdxColorCorrectionTask() = delete;
101 HdxColorCorrectionTask &operator =(const HdxColorCorrectionTask &) = delete;
102
103 // Description of a texture resource and sampler
104 struct _TextureSamplerDesc {
105 HgiTextureDesc textureDesc;
106 HgiSamplerDesc samplerDesc;
107 std::vector<float> samples;
108 };
109
110 // Description of a buffer resource
111 struct _UniformBufferDesc {
112 std::string typeName;
113 std::string name;
114 std::vector<uint8_t> data;
115 uint32_t dataSize;
116 uint32_t count;
117 };
118 friend struct HdxColorCorrectionTask_UboBuilder;
119
120 // Description of resources required by OCIO GPU implementation
121 struct _OCIOResources {
122 std::vector<_TextureSamplerDesc> luts;
123 std::vector<_UniformBufferDesc> ubos;
124 std::vector<unsigned char> constantValues;
125 std::string gpuShaderText;
126 };
127
128 // Utility to query OCIO for required resources
129 static void
130 _CreateOpenColorIOResources(
131 Hgi *hgi,
132 HdxColorCorrectionTaskParams const& params,
133 _OCIOResources *result);
134 static void
135 _CreateOpenColorIOResourcesImpl(
136 Hgi *hgi,
137 HdxColorCorrectionTaskParams const& params,
138 _OCIOResources *result);
139
140 // Utility to check if OCIO should be used
141 bool _GetUseOcio() const;
142
143 // Utility function to create the GL program for color correction
144 bool _CreateShaderResources();
145
146 // OCIO version-specific code for shader code generation.
147 std::string _CreateOpenColorIOShaderCode(std::string &ocioGpuShaderText,
148 HgiShaderFunctionDesc &fragDesc);
149
150 // Utility function to create buffer resources.
151 bool _CreateBufferResources();
152
153 // Utility to create resource bindings
154 bool _CreateResourceBindings(HgiTextureHandle const& aovTexture);
155
156 // OCIO version-specific code for setting LUT bindings.
157 void _CreateOpenColorIOLUTBindings(HgiResourceBindingsDesc &resourceDesc);
158
159 // Utility to create a pipeline
160 bool _CreatePipeline(HgiTextureHandle const& aovTexture);
161
162 // Utility to create an AOV sampler
163 bool _CreateAovSampler();
164
165 // Apply color correction to the currently bound framebuffer.
166 void _ApplyColorCorrection(HgiTextureHandle const& aovTexture);
167
168 // OCIO version-specific code for setting constants.
169 void _SetConstants(HgiGraphicsCmds *gfxCmds);
170
171 // Destroy shader program and the shader functions it holds.
172 void _DestroyShaderProgram();
173
174 // Print shader compile errors.
175 void _PrintCompileErrors();
176
177private: // data
178
180 _OCIOResources _ocioResources;
181
182 HgiAttachmentDesc _attachment0;
183 HgiBufferHandle _indexBuffer;
184 HgiBufferHandle _vertexBuffer;
185 HgiSamplerHandle _aovSampler;
186
187 struct TextureSamplerInfo
188 {
189 unsigned char dim;
190 std::string texName;
191 HgiTextureHandle texHandle;
192 std::string samplerName;
193 HgiSamplerHandle samplerHandle;
194 };
195 std::vector<TextureSamplerInfo> _textureLUTs;
196
197 struct BufferInfo
198 {
199 std::string typeName;
200 std::string name;
201 uint32_t count;
202 HgiBufferHandle handle;
203 };
204 std::vector<BufferInfo> _bufferConstants;
205
206 HgiShaderProgramHandle _shaderProgram;
207 HgiResourceBindingsHandle _resourceBindings;
209 float _screenSize[2];
210
211 std::unique_ptr<class WorkDispatcher> _workDispatcher;
212};
213
214// VtValue requirements
215HDX_API
216std::ostream& operator<<(std::ostream& out, const HdxColorCorrectionTaskParams& pv);
217HDX_API
218bool operator==(const HdxColorCorrectionTaskParams& lhs,
220HDX_API
221bool operator!=(const HdxColorCorrectionTaskParams& lhs,
223
224
225PXR_NAMESPACE_CLOSE_SCOPE
226
227#endif
The render index is part of the Hydra 1.0 API and is only used for emulation purposes so that HdScene...
Adapter class providing data exchange with the client scene graph.
A task for performing color correction (and optionally color grading) on a color buffer to transform ...
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
HDX_API void Execute(HdTaskContext *ctx) override
Execute the color correction task.
Base class for (some) tasks in Hdx that provides common progressive rendering and Hgi functionality.
Definition task.h:28
A graphics API independent abstraction of graphics commands.
Hydra Graphics Interface.
Definition hgi.h:95
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:81
ColorCorrectionTask parameters.
Describes the properties of a framebuffer attachment.
Describes a set of resources that are bound to the GPU during encoding.
Describes the properties needed to create a GPU sampler.
Definition sampler.h:62
Describes the properties needed to create a GPU shader function.
Describes the properties needed to create a GPU texture.
Definition texture.h:91