Loading...
Searching...
No Matches
effectsShader.h
1//
2// Copyright 2023 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_HDX_EFFECTS_SHADER_H
25#define PXR_IMAGING_HDX_EFFECTS_SHADER_H
26
27#include "pxr/pxr.h"
28
29#include "pxr/imaging/hdx/api.h"
30
31#include "pxr/imaging/hgi/buffer.h"
32#include "pxr/imaging/hgi/graphicsPipeline.h"
33#include "pxr/imaging/hgi/resourceBindings.h"
34#include "pxr/imaging/hgi/shaderProgram.h"
35#include "pxr/imaging/hgi/texture.h"
36
37#include "pxr/base/gf/vec4i.h"
38
39#include <vector>
40
41PXR_NAMESPACE_OPEN_SCOPE
42
43class Hgi;
44
45using HgiGraphicsCmdsUniquePtr = std::unique_ptr<class HgiGraphicsCmds>;
46
47
62{
63public:
64 HDX_API
65 virtual ~HdxEffectsShader();
66
67 // Print shader compile errors for the shader function.
68 static void PrintCompileErrors(
69 const HgiShaderFunctionHandle& shaderFn);
70
71 // Print shader compile errors for the shader program and any functions
72 // it references.
73 static void PrintCompileErrors(
74 const HgiShaderProgramHandle& shaderProgram);
75
76protected:
77 HdxEffectsShader() = delete;
78 HdxEffectsShader(const HdxEffectsShader&) = delete;
79 HdxEffectsShader& operator=(const HdxEffectsShader&) = delete;
80
84 HDX_API
86 Hgi* hgi,
87 const std::string& debugName);
88
89 HDX_API
90 void _SetColorAttachments(
91 const HgiAttachmentDescVector& colorAttachmentDescs);
92
93 HDX_API
94 void _SetDepthAttachment(
95 const HgiAttachmentDesc& depthAttachmentDesc);
96
97 HDX_API
98 void _SetPrimitiveType(
99 HgiPrimitiveType primitiveType);
100
101 HDX_API
102 void _SetShaderProgram(
103 const HgiShaderProgramHandle& shaderProgram);
104
105 HDX_API
106 void _SetVertexBufferDescs(
107 const HgiVertexBufferDescVector& vertexBufferDescs);
108
109 HDX_API
110 void _SetDepthStencilState(
111 const HgiDepthStencilState& depthStencilState);
112
113 HDX_API
114 void _SetMultiSampleState(
115 const HgiMultiSampleState& multiSampleState);
116
117 HDX_API
118 void _SetRasterizationState(
119 const HgiRasterizationState& rasterizationState);
120
121 HDX_API
122 void _SetShaderConstants(
123 uint32_t byteSize,
124 const void* data,
125 HgiShaderStage stageUsage);
126
127 HDX_API
128 void _SetTextureBindings(
129 const HgiTextureBindDescVector& textures);
130
131 HDX_API
132 void _SetBufferBindings(
133 const HgiBufferBindDescVector& buffers);
134
135 // Creates a graphics commands object, records draw commands to it via the
136 // overridden _RecordDrawCmds, and then submits them.
137 HDX_API
138 void _CreateAndSubmitGraphicsCmds(
139 const HgiTextureHandleVector& colorTextures,
140 const HgiTextureHandleVector& colorResolveTextures,
141 const HgiTextureHandle& depthTexture,
142 const HgiTextureHandle& depthResolveTexture,
143 const GfVec4i& viewport);
144
145 // Sub-classes should override and invoke one or more calls to
146 // _DrawNonIndexed or _DrawIndexed.
147 HDX_API
148 virtual void _RecordDrawCmds() = 0;
149
150 // Sets the vertex buffer and invokes HgiGraphicsCmds::Draw.
151 HDX_API
152 void _DrawNonIndexed(
153 const HgiBufferHandle& vertexBuffer,
154 uint32_t vertexCount,
155 uint32_t baseVertex,
156 uint32_t instanceCount,
157 uint32_t baseInstance);
158
159 // Sets the vertex buffer and invokes HgiGraphicsCmds::DrawIndexed with the
160 // provided index buffer.
161 HDX_API
162 void _DrawIndexed(
163 const HgiBufferHandle& vertexBuffer,
164 const HgiBufferHandle& indexBuffer,
165 uint32_t indexCount,
166 uint32_t indexBufferByteOffset,
167 uint32_t baseVertex,
168 uint32_t instanceCount,
169 uint32_t baseInstance);
170
171 HDX_API
172 Hgi* _GetHgi() const;
173
174 HDX_API
175 void _DestroyShaderProgram(HgiShaderProgramHandle* shaderProgram);
176
177 HDX_API
178 const std::string& _GetDebugName() const;
179
180private:
181 void _CreatePipeline(
182 const HgiTextureHandleVector& colorTextures,
183 const HgiTextureHandleVector& colorResolveTextures,
184 const HgiTextureHandle& depthTexture,
185 const HgiTextureHandle& depthResolveTexture);
186 void _DestroyPipeline();
187
188 void _CreateResourceBindings();
189 void _DestroyResourceBindings();
190
191 Hgi* _hgi;
192 const std::string _debugName;
193 HgiGraphicsPipelineDesc _pipelineDesc;
195 std::vector<uint8_t> _constantsData;
196 HgiResourceBindingsDesc _resourceBindingsDesc;
197 HgiResourceBindingsHandle _resourceBindings;
198 HgiGraphicsCmdsUniquePtr _gfxCmds;
199};
200
201PXR_NAMESPACE_CLOSE_SCOPE
202
203#endif // PXR_IMAGING_HDX_EFFECTS_SHADER_H
Basic type for a vector of 4 int components.
Definition: vec4i.h:61
This class provides functionality to create and manage a single HgiGraphicsPipeline instance and to i...
Definition: effectsShader.h:62
HDX_API HdxEffectsShader(Hgi *hgi, const std::string &debugName)
Create a new shader object.
Handle that contains a hgi object and unique id.
Definition: handle.h:50
Hydra Graphics Interface.
Definition: hgi.h:111
Describes the properties of a framebuffer attachment.
Properties to configure depth and stencil test.
Describes the properties needed to create a GPU pipeline.
Properties to configure multi sampling.
Properties to configure the rasterization state.
Describes a set of resources that are bound to the GPU during encoding.