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 
178  // Helper to get graphics cmds descriptor describing textures
179  // we render into and the blend state, constructed from
180  // AOV bindings.
181  //
182  HDST_API
183  HgiGraphicsCmdsDesc MakeGraphicsCmdsDesc(
184  HdRenderIndex const * renderIndex) const;
185 
186  // Helper to initialize graphics pipeline descriptor state including
187  // any additional state from the geometric shader.
188  HDST_API
189  void InitGraphicsPipelineDesc(
190  HgiGraphicsPipelineDesc * pipeDesc,
191  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
192 
194  HDST_API
195  uint64_t GetGraphicsPipelineHash() const;
196 
197 private:
198  bool _UseAlphaMask() const;
199 
200  // Helper to set up the aov attachment desc so that it matches the blend
201  // setting of the render pipeline state.
202  // If an aovIndex is specified then the color mask will be correlated.
203  void _InitAttachmentDesc(HgiAttachmentDesc &attachmentDesc,
204  int aovIndex = -1) const;
205 
206  void _InitPrimitiveState(
207  HgiGraphicsPipelineDesc * pipeDesc,
208  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
209  void _InitAttachmentState(HgiGraphicsPipelineDesc * pipeDesc) const;
210  void _InitDepthStencilState(HgiDepthStencilState * depthState) const;
211  void _InitMultiSampleState(HgiMultiSampleState * multisampleState) const;
212  void _InitRasterizationState(
213  HgiRasterizationState * rasterizationState,
214  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
215 
216  // ---------------------------------------------------------------------- //
217  // Camera state used when no HdCamera available
218  // ---------------------------------------------------------------------- //
219 
220  GfMatrix4d _worldToViewMatrix;
221  GfMatrix4d _projectionMatrix;
222  ClipPlanesVector _clipPlanes;
223 
224  GfMatrix4d _cullMatrix; // updated during Prepare(..)
225 
226  // ---------------------------------------------------------------------- //
227  // Shader Objects
228  // ---------------------------------------------------------------------- //
229  HdStRenderPassShaderSharedPtr _renderPassShader;
230  HdSt_FallbackLightingShaderSharedPtr _fallbackLightingShader;
231  HdStLightingShaderSharedPtr _lightingShader;
232 
233  HdBufferArrayRangeSharedPtr _renderPassStateBar;
234  size_t _clipPlanesBufferSize;
235  float _alphaThresholdCurrent;
236  bool _resolveMultiSampleAov;
237  bool _useSceneMaterials;
238 };
239 
240 PXR_NAMESPACE_CLOSE_SCOPE
241 
242 #endif // PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
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.
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.