Loading...
Searching...
No Matches
renderPassState.h
1//
2// Copyright 2016 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 PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
25#define PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hdSt/api.h"
29#include "pxr/imaging/hd/renderPassState.h"
30#include "pxr/imaging/hgi/graphicsCmdsDesc.h"
31
32#include <memory>
33
34PXR_NAMESPACE_OPEN_SCOPE
35
40class HgiCapabilities;
41
42using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
43using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
44
45using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
46
47using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
48using HdStLightingShaderSharedPtr = std::shared_ptr<class HdStLightingShader>;
49using HdStRenderPassShaderSharedPtr =
50 std::shared_ptr<class HdStRenderPassShader>;
51using HdSt_FallbackLightingShaderSharedPtr =
52 std::shared_ptr<class HdSt_FallbackLightingShader>;
53using HdSt_GeometricShaderSharedPtr =
54 std::shared_ptr<class HdSt_GeometricShader>;
55using HdStShaderCodeSharedPtrVector = std::vector<HdStShaderCodeSharedPtr>;
56class HdRenderIndex;
57class HdSt_ResourceBinder;
58
66{
67public:
68 HDST_API
70 HDST_API
71 HdStRenderPassState(HdStRenderPassShaderSharedPtr const &shader);
72 HDST_API
73 ~HdStRenderPassState() override;
74
75 HDST_API
76 void
77 Prepare(HdResourceRegistrySharedPtr const &resourceRegistry) override;
78
99 HDST_API
100 void Bind(HgiCapabilities const &hgiCapabilities);
101 HDST_API
102 void Unbind(HgiCapabilities const &hgiCapabilities);
103
108 HDST_API
109 void SetResolveAovMultiSample(bool state);
110 HDST_API
111 bool GetResolveAovMultiSample() const;
112
114 HDST_API
115 void SetLightingShader(HdStLightingShaderSharedPtr const &lightingShader);
116 HdStLightingShaderSharedPtr const & GetLightingShader() const {
117 return _lightingShader;
118 }
119
121 HDST_API
122 void SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader);
123 HdStRenderPassShaderSharedPtr const &GetRenderPassShader() const {
124 return _renderPassShader;
125 }
126
127 HDST_API
128 void ApplyStateFromGeometricShader(
129 HdSt_ResourceBinder const &binder,
130 HdSt_GeometricShaderSharedPtr const &geometricShader);
131
132 HDST_API
133 void ApplyStateFromCamera();
134
136 HDST_API
137 void SetUseSceneMaterials(bool state);
138 bool GetUseSceneMaterials() const {
139 return _useSceneMaterials;
140 }
141
143 HDST_API
144 HdStShaderCodeSharedPtrVector GetShaders() const;
145
146 HDST_API
147 size_t GetShaderHash() const;
148
156 HDST_API
157 void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix,
158 GfMatrix4d const &projectionMatrix,
159 GfVec4d const &viewport,
160 ClipPlanesVector const & clipPlanes);
161
162 GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
163
166 HDST_API
168
171 HDST_API
173
176 HDST_API ClipPlanesVector const & GetClipPlanes() const override;
177
181 HDST_API
183
184 // Helper to get graphics cmds descriptor describing textures
185 // we render into and the blend state, constructed from
186 // AOV bindings.
187 //
188 HDST_API
189 HgiGraphicsCmdsDesc MakeGraphicsCmdsDesc(
190 HdRenderIndex const * renderIndex) const;
191
192 // Helper to initialize graphics pipeline descriptor state including
193 // any additional state from the geometric shader.
194 HDST_API
195 void InitGraphicsPipelineDesc(
196 HgiGraphicsPipelineDesc * pipeDesc,
197 HdSt_GeometricShaderSharedPtr const & geometricShader,
198 bool firstDrawBatch) const;
199
201 HDST_API
203 HdSt_GeometricShaderSharedPtr const & geometricShader,
204 bool firstDrawBatch) const;
205
206 // A 4d-vector v encodes a 2d-transform as follows:
207 // (x, y) |-> (v[0] * x + v[2], v[1] * y + v[3]).
209
210 // Computes the transform from pixel coordinates to the horizontally
211 // normalized filmback space which has the following properties:
212 // 1. x = -1 and +1 corresponds to the left and right edge of the filmback,
213 // respectively.
214 // 2. (0, 0) corresponds to the center of the filmback.
215 // 3. Moving a unit in either the x- or y-direction moves by the same
216 // distance on the filmback. In other words, y = -1/a and +1/a
217 // corresponds to the bottom and top edge of the filmback, respectively,
218 // where a is the camera's aspect ratio.
219 HDST_API
221 ComputeImageToHorizontallyNormalizedFilmback() const;
222
223private:
224 bool _UseAlphaMask() const;
225 unsigned int _GetFramebufferHeight() const;
226 GfRange2f _ComputeFlippedFilmbackWindow() const;
227
228 // Helper to set up the aov attachment desc so that it matches the blend
229 // setting of the render pipeline state.
230 // If an aovIndex is specified then the color mask will be correlated.
231 void _InitAttachmentDesc(HgiAttachmentDesc &attachmentDesc,
232 HdRenderPassAovBinding const & binding,
233 HdRenderBuffer const * renderBuffer,
234 int aovIndex) const;
235
236 void _InitPrimitiveState(
237 HgiGraphicsPipelineDesc * pipeDesc,
238 HdSt_GeometricShaderSharedPtr const & geometricShader) const;
239 void _InitAttachmentState(HgiGraphicsPipelineDesc * pipeDesc,
240 bool firstDrawBatch) const;
241 void _InitDepthStencilState(HgiDepthStencilState * depthState) const;
242 void _InitMultiSampleState(HgiMultiSampleState * multisampleState) const;
243 void _InitRasterizationState(
244 HgiRasterizationState * rasterizationState,
245 HdSt_GeometricShaderSharedPtr const & geometricShader) const;
246
247 // ---------------------------------------------------------------------- //
248 // Camera state used when no HdCamera available
249 // ---------------------------------------------------------------------- //
250
251 GfMatrix4d _worldToViewMatrix;
252 GfMatrix4d _projectionMatrix;
253 ClipPlanesVector _clipPlanes;
254
255 GfMatrix4d _cullMatrix; // updated during Prepare(..)
256
257 // ---------------------------------------------------------------------- //
258 // Shader Objects
259 // ---------------------------------------------------------------------- //
260 HdStRenderPassShaderSharedPtr _renderPassShader;
261 HdSt_FallbackLightingShaderSharedPtr _fallbackLightingShader;
262 HdStLightingShaderSharedPtr _lightingShader;
263
264 HdBufferArrayRangeSharedPtr _renderPassStateBar;
265 size_t _clipPlanesBufferSize;
266 float _alphaThresholdCurrent;
267 bool _resolveMultiSampleAov;
268 bool _useSceneMaterials;
269};
270
271PXR_NAMESPACE_CLOSE_SCOPE
272
273#endif // PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: 2-dimensional floating point range.
Definition: range2f.h:64
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
Basic type for a vector of 4 int components.
Definition: vec4i.h:61
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:50
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:121
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:40
A renderpass AOV represents a binding of some output of the rendering process to an output buffer.
Definition: aov.h:117
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.