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