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 void SetUseSceneMaterials(bool state);
121 bool GetUseSceneMaterials() const {
122 return _useSceneMaterials;
123 }
124
126 HDST_API
127 HdStShaderCodeSharedPtrVector GetShaders() const;
128
129 HDST_API
130 size_t GetShaderHash() const;
131
139 HDST_API
140 void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix,
141 GfMatrix4d const &projectionMatrix,
142 GfVec4d const &viewport,
143 ClipPlanesVector const & clipPlanes);
144
145 GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
146
149 HDST_API
151
154 HDST_API
156
159 HDST_API ClipPlanesVector const & GetClipPlanes() const override;
160
164 HDST_API
166
167 // Helper to get graphics cmds descriptor describing textures
168 // we render into and the blend state, constructed from
169 // AOV bindings.
170 //
171 HDST_API
172 HgiGraphicsCmdsDesc MakeGraphicsCmdsDesc(
173 HdRenderIndex const * renderIndex) const;
174
175 // Helper to initialize graphics pipeline descriptor state including
176 // any additional state from the geometric shader.
177 HDST_API
178 void InitGraphicsPipelineDesc(
179 HgiGraphicsPipelineDesc * pipeDesc,
180 HdSt_GeometricShaderSharedPtr const & geometricShader,
181 bool firstDrawBatch) const;
182
184 HDST_API
186 HdSt_GeometricShaderSharedPtr const & geometricShader,
187 bool firstDrawBatch) const;
188
189 // A 4d-vector v encodes a 2d-transform as follows:
190 // (x, y) |-> (v[0] * x + v[2], v[1] * y + v[3]).
192
193 // Computes the transform from pixel coordinates to the horizontally
194 // normalized filmback space which has the following properties:
195 // 1. x = -1 and +1 corresponds to the left and right edge of the filmback,
196 // respectively.
197 // 2. (0, 0) corresponds to the center of the filmback.
198 // 3. Moving a unit in either the x- or y-direction moves by the same
199 // distance on the filmback. In other words, y = -1/a and +1/a
200 // corresponds to the bottom and top edge of the filmback, respectively,
201 // where a is the camera's aspect ratio.
202 HDST_API
204 ComputeImageToHorizontallyNormalizedFilmback() const;
205
206private:
207 bool _UseAlphaMask() const;
208 unsigned int _GetFramebufferHeight() const;
209 GfRange2f _ComputeFlippedFilmbackWindow() const;
210
211 // Helper to set up the aov attachment desc so that it matches the blend
212 // setting of the render pipeline state.
213 // If an aovIndex is specified then the color mask will be correlated.
214 void _InitAttachmentDesc(HgiAttachmentDesc &attachmentDesc,
215 HdRenderPassAovBinding const & binding,
216 HdRenderBuffer const * renderBuffer,
217 int aovIndex) const;
218
219 void _InitPrimitiveState(
220 HgiGraphicsPipelineDesc * pipeDesc,
221 HdSt_GeometricShaderSharedPtr const & geometricShader) const;
222 void _InitAttachmentState(HgiGraphicsPipelineDesc * pipeDesc,
223 bool firstDrawBatch) const;
224 void _InitDepthStencilState(HgiDepthStencilState * depthState) const;
225 void _InitMultiSampleState(HgiMultiSampleState * multisampleState) const;
226 void _InitRasterizationState(
227 HgiRasterizationState * rasterizationState,
228 HdSt_GeometricShaderSharedPtr const & geometricShader) const;
229
230 // ---------------------------------------------------------------------- //
231 // Camera state used when no HdCamera available
232 // ---------------------------------------------------------------------- //
233
234 GfMatrix4d _worldToViewMatrix;
235 GfMatrix4d _projectionMatrix;
236 ClipPlanesVector _clipPlanes;
237
238 GfMatrix4d _cullMatrix; // updated during Prepare(..)
239
240 // ---------------------------------------------------------------------- //
241 // Shader Objects
242 // ---------------------------------------------------------------------- //
243 HdStRenderPassShaderSharedPtr _renderPassShader;
244 HdSt_FallbackLightingShaderSharedPtr _fallbackLightingShader;
245 HdStLightingShaderSharedPtr _lightingShader;
246
247 HdBufferArrayRangeSharedPtr _renderPassStateBar;
248 size_t _clipPlanesBufferSize;
249 float _alphaThresholdCurrent;
250 bool _resolveMultiSampleAov;
251 bool _useSceneMaterials;
252};
253
254PXR_NAMESPACE_CLOSE_SCOPE
255
256#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:104
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 SetUseSceneMaterials(bool state)
scene materials
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.