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 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
38 struct HgiMultiSampleState;
40 class HgiCapabilities;
41 
42 using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
43 using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
44 
45 using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
46 
47 using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
48 using HdStLightingShaderSharedPtr = std::shared_ptr<class HdStLightingShader>;
49 using HdStRenderPassShaderSharedPtr =
50  std::shared_ptr<class HdStRenderPassShader>;
51 using HdSt_FallbackLightingShaderSharedPtr =
52  std::shared_ptr<class HdSt_FallbackLightingShader>;
53 using HdSt_GeometricShaderSharedPtr =
54  std::shared_ptr<class HdSt_GeometricShader>;
55 using HdStShaderCodeSharedPtrVector = std::vector<HdStShaderCodeSharedPtr>;
56 class HdRenderIndex;
57 class HdSt_ResourceBinder;
58 
66 {
67 public:
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  HD_API
109  void SetResolveAovMultiSample(bool state);
110  HD_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
167  GfMatrix4d GetWorldToViewMatrix() const override;
168 
171  HDST_API
172  GfMatrix4d GetProjectionMatrix() const override;
173 
176  HDST_API ClipPlanesVector const & GetClipPlanes() const override;
177 
182  HDST_API
183  GfVec4i ComputeViewport(const HgiGraphicsCmdsDesc &desc, const bool flip);
184 
185  // Helper to get graphics cmds descriptor describing textures
186  // we render into and the blend state, constructed from
187  // AOV bindings.
188  //
189  HDST_API
190  HgiGraphicsCmdsDesc MakeGraphicsCmdsDesc(
191  HdRenderIndex const * renderIndex) const;
192 
193  // Helper to initialize graphics pipeline descriptor state including
194  // any additional state from the geometric shader.
195  HDST_API
196  void InitGraphicsPipelineDesc(
197  HgiGraphicsPipelineDesc * pipeDesc,
198  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
199 
201  HDST_API
202  uint64_t GetGraphicsPipelineHash() const;
203 
204 private:
205  bool _UseAlphaMask() const;
206 
207  // Helper to set up the aov attachment desc so that it matches the blend
208  // setting of the render pipeline state.
209  // If an aovIndex is specified then the color mask will be correlated.
210  void _InitAttachmentDesc(HgiAttachmentDesc &attachmentDesc,
211  int aovIndex = -1) const;
212 
213  void _InitPrimitiveState(
214  HgiGraphicsPipelineDesc * pipeDesc,
215  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
216  void _InitAttachmentState(HgiGraphicsPipelineDesc * pipeDesc) 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  bool _useSceneMaterials;
245 };
246 
247 PXR_NAMESPACE_CLOSE_SCOPE
248 
249 #endif // PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
Basic type for a vector of 4 int components.
Definition: vec4i.h:61
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:120
HDST_API GfMatrix4d GetProjectionMatrix() const override
Overrides the case when no HdCamera is given.
Describes the properties of a framebuffer attachment.
HDST_API GfVec4i ComputeViewport(const HgiGraphicsCmdsDesc &desc, const bool flip)
Helper to compute and get the Viewport This is either using the modern camera framing,...
A set of rendering parameters used among render passes.
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
HDST_API uint64_t GetGraphicsPipelineHash() const
Generates the hash for the settings used to init the graphics pipeline.
HDST_API void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry) override
Schedule to update renderPassState parameters.
HDST_API void Bind(HgiCapabilities const &hgiCapabilities)
XXX: Bind and Unbind set.
A set of rendering parameters used among render passes.
HD_API void SetResolveAovMultiSample(bool state)
If set to true (default) and the render pass is rendering into a multi-sampled aovs,...
HDST_API HdStShaderCodeSharedPtrVector GetShaders() const
returns shaders (lighting/renderpass)
Properties to configure multi sampling.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Reports the capabilities of the Hgi device.
Definition: capabilities.h:39
HDST_API void SetUseSceneMaterials(bool state)
scene materials
Describes the properties to begin a HgiGraphicsCmds.
HDST_API void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix, GfVec4d const &viewport, ClipPlanesVector const &clipPlanes)
Camera setter API.
HDST_API GfMatrix4d GetWorldToViewMatrix() const override
Overrides the case when no HdCamera is given.
Properties to configure the rasterization state.
Properties to configure depth and stencil test.
HDST_API void SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader)
renderpass shader
Describes the properties needed to create a GPU pipeline.
HDST_API void SetLightingShader(HdStLightingShaderSharedPtr const &lightingShader)
Set lighting shader.
HDST_API ClipPlanesVector const & GetClipPlanes() const override
Overrides the case when no HdCamera is given.