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
62 HDST_API
63 void Copy(HdRenderPassState const& src) override;
64
73 HDST_API
75
96 HDST_API
97 void Bind(HgiCapabilities const &hgiCapabilities);
98 HDST_API
99 void Unbind(HgiCapabilities const &hgiCapabilities);
100
105 HDST_API
106 void SetResolveAovMultiSample(bool state);
107 HDST_API
108 bool GetResolveAovMultiSample() const;
109
111 HDST_API
112 void SetLightingShader(HdStLightingShaderSharedPtr const &lightingShader);
113 HdStLightingShaderSharedPtr const & GetLightingShader() const {
114 return _lightingShader;
115 }
116
118 HDST_API
119 void SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader);
120 HdStRenderPassShaderSharedPtr const &GetRenderPassShader() const {
121 return _renderPassShader;
122 }
123
124 HDST_API
125 void ApplyStateFromGeometricShader(
126 HdSt_ResourceBinder const &binder,
127 HdSt_GeometricShaderSharedPtr const &geometricShader);
128
129 HDST_API
130 void ApplyStateFromCamera();
131
133 HDST_API
134 HdStShaderCodeSharedPtrVector GetShaders() const;
135
136 HDST_API
137 size_t GetShaderHash() const;
138
146 HDST_API
147 void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix,
148 GfMatrix4d const &projectionMatrix,
149 GfVec4d const &viewport,
150 ClipPlanesVector const & clipPlanes);
151
152 GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
153
156 HDST_API
158
161 HDST_API
163
166 HDST_API ClipPlanesVector const & GetClipPlanes() const override;
167
171 HDST_API
173
174 // Helper to get graphics cmds descriptor describing textures
175 // we render into and the blend state, constructed from
176 // AOV bindings.
177 //
178 HDST_API
179 HgiGraphicsCmdsDesc MakeGraphicsCmdsDesc(
180 HdRenderIndex const * renderIndex) const;
181
182 // Helper to initialize graphics pipeline descriptor state including
183 // any additional state from the geometric shader.
184 HDST_API
185 void InitGraphicsPipelineDesc(
186 HgiGraphicsPipelineDesc * pipeDesc,
187 HdSt_GeometricShaderSharedPtr const & geometricShader,
188 bool firstDrawBatch) const;
189
191 HDST_API
193 HdSt_GeometricShaderSharedPtr const & geometricShader,
194 bool firstDrawBatch) const;
195
196 // A 4d-vector v encodes a 2d-transform as follows:
197 // (x, y) |-> (v[0] * x + v[2], v[1] * y + v[3]).
199
200 // Computes the transform from pixel coordinates to the horizontally
201 // normalized filmback space which has the following properties:
202 // 1. x = -1 and +1 corresponds to the left and right edge of the filmback,
203 // respectively.
204 // 2. (0, 0) corresponds to the center of the filmback.
205 // 3. Moving a unit in either the x- or y-direction moves by the same
206 // distance on the filmback. In other words, y = -1/a and +1/a
207 // corresponds to the bottom and top edge of the filmback, respectively,
208 // where a is the camera's aspect ratio.
209 HDST_API
211 ComputeImageToHorizontallyNormalizedFilmback() const;
212
213private:
214 unsigned int _GetFramebufferHeight() const;
215 GfRange2f _ComputeFlippedFilmbackWindow() const;
216
217 // Helper to set up the aov attachment desc so that it matches the blend
218 // setting of the render pipeline state.
219 // If an aovIndex is specified then the color mask will be correlated.
220 void _InitAttachmentDesc(HgiAttachmentDesc &attachmentDesc,
221 HdRenderPassAovBinding const & binding,
222 HdRenderBuffer const * renderBuffer,
223 int aovIndex) const;
224
225 void _InitPrimitiveState(
226 HgiGraphicsPipelineDesc * pipeDesc,
227 HdSt_GeometricShaderSharedPtr const & geometricShader) const;
228 void _InitAttachmentState(HgiGraphicsPipelineDesc * pipeDesc,
229 bool firstDrawBatch) const;
230 void _InitDepthStencilState(HgiDepthStencilState * depthState) const;
231 void _InitMultiSampleState(HgiMultiSampleState * multisampleState) const;
232 void _InitRasterizationState(
233 HgiRasterizationState * rasterizationState,
234 HdSt_GeometricShaderSharedPtr const & geometricShader) const;
235
236 // ---------------------------------------------------------------------- //
237 // Camera state used when no HdCamera available
238 // ---------------------------------------------------------------------- //
239
240 GfMatrix4d _worldToViewMatrix;
241 GfMatrix4d _projectionMatrix;
242 ClipPlanesVector _clipPlanes;
243
244 GfMatrix4d _cullMatrix; // updated during Prepare(..)
245
246 // ---------------------------------------------------------------------- //
247 // Shader Objects
248 // ---------------------------------------------------------------------- //
249 HdStRenderPassShaderSharedPtr _renderPassShader;
250 HdSt_FallbackLightingShaderSharedPtr _fallbackLightingShader;
251 HdStLightingShaderSharedPtr _lightingShader;
252
253 HdBufferArrayRangeSharedPtr _renderPassStateBar;
254 size_t _clipPlanesBufferSize;
255 bool _resolveMultiSampleAov;
256};
257
258PXR_NAMESPACE_CLOSE_SCOPE
259
260#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:48
Basic type for a vector of 4 float components.
Definition vec4f.h:48
Basic type for a vector of 4 int components.
Definition vec4i.h:46
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
The render index is part of the Hydra 1.0 API and is only used for emulation purposes so that HdScene...
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 CopyUniforms(HdStRenderPassState const &src)
Copy the uniform buffer state from src into this object.
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 void Copy(HdRenderPassState const &src) override
Copy state from src into this object.
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.
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.