Loading...
Searching...
No Matches
effectsShader.h
1//
2// Copyright 2023 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_HDX_EFFECTS_SHADER_H
8#define PXR_IMAGING_HDX_EFFECTS_SHADER_H
9
10#include "pxr/pxr.h"
11
12#include "pxr/imaging/hdx/api.h"
13
14#include "pxr/imaging/hgi/buffer.h"
15#include "pxr/imaging/hgi/graphicsPipeline.h"
16#include "pxr/imaging/hgi/resourceBindings.h"
17#include "pxr/imaging/hgi/shaderProgram.h"
18#include "pxr/imaging/hgi/texture.h"
19
20#include "pxr/base/gf/vec4i.h"
21
22#include <vector>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26class Hgi;
27
28using HgiGraphicsCmdsUniquePtr = std::unique_ptr<class HgiGraphicsCmds>;
29
30
45{
46public:
47 HDX_API
48 virtual ~HdxEffectsShader();
49
50 // Print shader compile errors for the shader function.
51 static void PrintCompileErrors(
52 const HgiShaderFunctionHandle& shaderFn);
53
54 // Print shader compile errors for the shader program and any functions
55 // it references.
56 static void PrintCompileErrors(
57 const HgiShaderProgramHandle& shaderProgram);
58
59protected:
60 HdxEffectsShader() = delete;
61 HdxEffectsShader(const HdxEffectsShader&) = delete;
62 HdxEffectsShader& operator=(const HdxEffectsShader&) = delete;
63
67 HDX_API
69 Hgi* hgi,
70 const std::string& debugName);
71
72 HDX_API
73 void _SetColorAttachments(
74 const HgiAttachmentDescVector& colorAttachmentDescs);
75
76 HDX_API
77 void _SetDepthAttachment(
78 const HgiAttachmentDesc& depthAttachmentDesc);
79
80 HDX_API
81 void _SetPrimitiveType(
82 HgiPrimitiveType primitiveType);
83
84 HDX_API
85 void _SetShaderProgram(
86 const HgiShaderProgramHandle& shaderProgram);
87
88 HDX_API
89 void _SetVertexBufferDescs(
90 const HgiVertexBufferDescVector& vertexBufferDescs);
91
92 HDX_API
93 void _SetDepthStencilState(
94 const HgiDepthStencilState& depthStencilState);
95
96 HDX_API
97 void _SetMultiSampleState(
98 const HgiMultiSampleState& multiSampleState);
99
100 HDX_API
101 void _SetRasterizationState(
102 const HgiRasterizationState& rasterizationState);
103
104 HDX_API
105 void _SetShaderConstants(
106 uint32_t byteSize,
107 const void* data,
108 HgiShaderStage stageUsage);
109
110 HDX_API
111 void _SetTextureBindings(
112 const HgiTextureBindDescVector& textures);
113
114 HDX_API
115 void _SetBufferBindings(
116 const HgiBufferBindDescVector& buffers);
117
118 // Creates a graphics commands object, records draw commands to it via the
119 // overridden _RecordDrawCmds, and then submits them.
120 HDX_API
121 void _CreateAndSubmitGraphicsCmds(
122 const HgiTextureHandleVector& colorTextures,
123 const HgiTextureHandleVector& colorResolveTextures,
124 const HgiTextureHandle& depthTexture,
125 const HgiTextureHandle& depthResolveTexture,
126 const GfVec4i& viewport);
127
128 // Sub-classes should override and invoke one or more calls to
129 // _DrawNonIndexed or _DrawIndexed.
130 HDX_API
131 virtual void _RecordDrawCmds() = 0;
132
133 // Sets the vertex buffer and invokes HgiGraphicsCmds::Draw.
134 HDX_API
135 void _DrawNonIndexed(
136 const HgiBufferHandle& vertexBuffer,
137 uint32_t vertexCount,
138 uint32_t baseVertex,
139 uint32_t instanceCount,
140 uint32_t baseInstance);
141
142 // Sets the vertex buffer and invokes HgiGraphicsCmds::DrawIndexed with the
143 // provided index buffer.
144 HDX_API
145 void _DrawIndexed(
146 const HgiBufferHandle& vertexBuffer,
147 const HgiBufferHandle& indexBuffer,
148 uint32_t indexCount,
149 uint32_t indexBufferByteOffset,
150 uint32_t baseVertex,
151 uint32_t instanceCount,
152 uint32_t baseInstance);
153
154 HDX_API
155 Hgi* _GetHgi() const;
156
157 HDX_API
158 void _DestroyShaderProgram(HgiShaderProgramHandle* shaderProgram);
159
160 HDX_API
161 const std::string& _GetDebugName() const;
162
163private:
164 void _CreatePipeline(
165 const HgiTextureHandleVector& colorTextures,
166 const HgiTextureHandleVector& colorResolveTextures,
167 const HgiTextureHandle& depthTexture,
168 const HgiTextureHandle& depthResolveTexture);
169 void _DestroyPipeline();
170
171 void _CreateResourceBindings();
172 void _DestroyResourceBindings();
173
174 Hgi* _hgi;
175 const std::string _debugName;
176 HgiGraphicsPipelineDesc _pipelineDesc;
178 std::vector<uint8_t> _constantsData;
179 HgiResourceBindingsDesc _resourceBindingsDesc;
180 HgiResourceBindingsHandle _resourceBindings;
181 HgiGraphicsCmdsUniquePtr _gfxCmds;
182};
183
184PXR_NAMESPACE_CLOSE_SCOPE
185
186#endif // PXR_IMAGING_HDX_EFFECTS_SHADER_H
Basic type for a vector of 4 int components.
Definition: vec4i.h:44
This class provides functionality to create and manage a single HgiGraphicsPipeline instance and to i...
Definition: effectsShader.h:45
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:33
Hydra Graphics Interface.
Definition: hgi.h:95
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.