Loading...
Searching...
No Matches
renderPassState.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
8#define PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdSt/api.h"
12#include "pxr/imaging/hd/renderPassState.h"
13#include "pxr/imaging/hgi/graphicsCmdsDesc.h"
14
15#include <memory>
16
17PXR_NAMESPACE_OPEN_SCOPE
18
23class HgiCapabilities;
24
25using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
26using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
27
28using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
29
30using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
31using HdStLightingShaderSharedPtr = std::shared_ptr<class HdStLightingShader>;
32using HdStRenderPassShaderSharedPtr =
33 std::shared_ptr<class HdStRenderPassShader>;
34using HdSt_FallbackLightingShaderSharedPtr =
35 std::shared_ptr<class HdSt_FallbackLightingShader>;
36using HdSt_GeometricShaderSharedPtr =
37 std::shared_ptr<class HdSt_GeometricShader>;
38using HdStShaderCodeSharedPtrVector = std::vector<HdStShaderCodeSharedPtr>;
39class HdRenderIndex;
40class HdSt_ResourceBinder;
41
49{
50public:
51 HDST_API
53 HDST_API
54 HdStRenderPassState(HdStRenderPassShaderSharedPtr const &shader);
55 HDST_API
56 ~HdStRenderPassState() override;
57
58 HDST_API
59 void
60 Prepare(HdResourceRegistrySharedPtr const &resourceRegistry) override;
61
82 HDST_API
83 void Bind(HgiCapabilities const &hgiCapabilities);
84 HDST_API
85 void Unbind(HgiCapabilities const &hgiCapabilities);
86
91 HDST_API
92 void SetResolveAovMultiSample(bool state);
93 HDST_API
94 bool GetResolveAovMultiSample() const;
95
97 HDST_API
98 void SetLightingShader(HdStLightingShaderSharedPtr const &lightingShader);
99 HdStLightingShaderSharedPtr const & GetLightingShader() const {
100 return _lightingShader;
101 }
102
104 HDST_API
105 void SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader);
106 HdStRenderPassShaderSharedPtr const &GetRenderPassShader() const {
107 return _renderPassShader;
108 }
109
110 HDST_API
111 void ApplyStateFromGeometricShader(
112 HdSt_ResourceBinder const &binder,
113 HdSt_GeometricShaderSharedPtr const &geometricShader);
114
115 HDST_API
116 void ApplyStateFromCamera();
117
119 HDST_API
120 HdStShaderCodeSharedPtrVector GetShaders() const;
121
122 HDST_API
123 size_t GetShaderHash() const;
124
132 HDST_API
133 void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix,
134 GfMatrix4d const &projectionMatrix,
135 GfVec4d const &viewport,
136 ClipPlanesVector const & clipPlanes);
137
138 GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
139
142 HDST_API
144
147 HDST_API
149
152 HDST_API ClipPlanesVector const & GetClipPlanes() const override;
153
157 HDST_API
159
160 // Helper to get graphics cmds descriptor describing textures
161 // we render into and the blend state, constructed from
162 // AOV bindings.
163 //
164 HDST_API
165 HgiGraphicsCmdsDesc MakeGraphicsCmdsDesc(
166 HdRenderIndex const * renderIndex) const;
167
168 // Helper to initialize graphics pipeline descriptor state including
169 // any additional state from the geometric shader.
170 HDST_API
171 void InitGraphicsPipelineDesc(
172 HgiGraphicsPipelineDesc * pipeDesc,
173 HdSt_GeometricShaderSharedPtr const & geometricShader,
174 bool firstDrawBatch) const;
175
177 HDST_API
179 HdSt_GeometricShaderSharedPtr const & geometricShader,
180 bool firstDrawBatch) const;
181
182 // A 4d-vector v encodes a 2d-transform as follows:
183 // (x, y) |-> (v[0] * x + v[2], v[1] * y + v[3]).
185
186 // Computes the transform from pixel coordinates to the horizontally
187 // normalized filmback space which has the following properties:
188 // 1. x = -1 and +1 corresponds to the left and right edge of the filmback,
189 // respectively.
190 // 2. (0, 0) corresponds to the center of the filmback.
191 // 3. Moving a unit in either the x- or y-direction moves by the same
192 // distance on the filmback. In other words, y = -1/a and +1/a
193 // corresponds to the bottom and top edge of the filmback, respectively,
194 // where a is the camera's aspect ratio.
195 HDST_API
197 ComputeImageToHorizontallyNormalizedFilmback() const;
198
199private:
200 bool _UseAlphaMask() const;
201 unsigned int _GetFramebufferHeight() const;
202 GfRange2f _ComputeFlippedFilmbackWindow() const;
203
204 // Helper to set up the aov attachment desc so that it matches the blend
205 // setting of the render pipeline state.
206 // If an aovIndex is specified then the color mask will be correlated.
207 void _InitAttachmentDesc(HgiAttachmentDesc &attachmentDesc,
208 HdRenderPassAovBinding const & binding,
209 HdRenderBuffer const * renderBuffer,
210 int aovIndex) const;
211
212 void _InitPrimitiveState(
213 HgiGraphicsPipelineDesc * pipeDesc,
214 HdSt_GeometricShaderSharedPtr const & geometricShader) const;
215 void _InitAttachmentState(HgiGraphicsPipelineDesc * pipeDesc,
216 bool firstDrawBatch) const;
217 void _InitDepthStencilState(HgiDepthStencilState * depthState) const;
218 void _InitMultiSampleState(HgiMultiSampleState * multisampleState) const;
219 void _InitRasterizationState(
220 HgiRasterizationState * rasterizationState,
221 HdSt_GeometricShaderSharedPtr const & geometricShader) const;
222
223 // ---------------------------------------------------------------------- //
224 // Camera state used when no HdCamera available
225 // ---------------------------------------------------------------------- //
226
227 GfMatrix4d _worldToViewMatrix;
228 GfMatrix4d _projectionMatrix;
229 ClipPlanesVector _clipPlanes;
230
231 GfMatrix4d _cullMatrix; // updated during Prepare(..)
232
233 // ---------------------------------------------------------------------- //
234 // Shader Objects
235 // ---------------------------------------------------------------------- //
236 HdStRenderPassShaderSharedPtr _renderPassShader;
237 HdSt_FallbackLightingShaderSharedPtr _fallbackLightingShader;
238 HdStLightingShaderSharedPtr _lightingShader;
239
240 HdBufferArrayRangeSharedPtr _renderPassStateBar;
241 size_t _clipPlanesBufferSize;
242 float _alphaThresholdCurrent;
243 bool _resolveMultiSampleAov;
244};
245
246PXR_NAMESPACE_CLOSE_SCOPE
247
248#endif // PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: 2-dimensional floating point range.
Definition: range2f.h:47
Basic type for a vector of 4 double components.
Definition: vec4d.h:46
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
Basic type for a vector of 4 int components.
Definition: vec4i.h:44
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
Definition: renderBuffer.h:33
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:105
A set of rendering parameters used among render passes.
A set of rendering parameters used among render passes.
HDST_API void SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader)
renderpass shader
HDST_API void SetResolveAovMultiSample(bool state)
If set to true (default) and the render pass is rendering into a multi-sampled aovs,...
HDST_API GfMatrix4d GetWorldToViewMatrix() const override
Overrides the case when no HdCamera is given.
HDST_API ClipPlanesVector const & GetClipPlanes() const override
Overrides the case when no HdCamera is given.
HDST_API void SetLightingShader(HdStLightingShaderSharedPtr const &lightingShader)
Set lighting shader.
HDST_API GfVec4i ComputeViewport() const
Helper to compute and get the y-up Viewport This is either using the modern camera framing,...
HDST_API HdStShaderCodeSharedPtrVector GetShaders() const
returns shaders (lighting/renderpass)
HDST_API void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix, GfVec4d const &viewport, ClipPlanesVector const &clipPlanes)
Camera setter API.
HDST_API void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry) override
Schedule to update renderPassState parameters.
HDST_API uint64_t GetGraphicsPipelineHash(HdSt_GeometricShaderSharedPtr const &geometricShader, bool firstDrawBatch) const
Generates the hash for the settings used to init the graphics pipeline.
HDST_API void Bind(HgiCapabilities const &hgiCapabilities)
XXX: Bind and Unbind set.
HDST_API GfMatrix4d GetProjectionMatrix() const override
Overrides the case when no HdCamera is given.
Reports the capabilities of the Hgi device.
Definition: capabilities.h:23
A renderpass AOV represents a binding of some output of the rendering process to an output buffer.
Definition: aov.h:100
Describes the properties of a framebuffer attachment.
Properties to configure depth and stencil test.
Describes the properties to begin a HgiGraphicsCmds.
Describes the properties needed to create a GPU pipeline.
Properties to configure multi sampling.
Properties to configure the rasterization state.