HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
graphicsCmds.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 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_HGI_GL_GRAPHICS_CMDS_H
25 #define PXR_IMAGING_HGI_GL_GRAPHICS_CMDS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/gf/vec4i.h"
30 #include "pxr/imaging/hgiGL/api.h"
31 #include "pxr/imaging/hgiGL/hgi.h"
32 #include <cstdint>
33 
35 
36 struct HgiGraphicsCmdsDesc;
37 class HgiGLDevice;
38 
39 /// \class HgiGLGraphicsCmds
40 ///
41 /// OpenGL implementation of HgiGraphicsCmds.
42 ///
43 class HgiGLGraphicsCmds final : public HgiGraphicsCmds
44 {
45 public:
46  HGIGL_API
47  ~HgiGLGraphicsCmds() override;
48 
49  /// XXX This function is exposed temporarily for Hgi transition.
50  /// It allows code that is not yet converted to Hgi (e.g. HdSt) to insert
51  /// its opengl calls into the ops-stack of HgiGL to ensure that all commands
52  /// execute in the correct order. Once HdSt has transition fully to Hgi we
53  /// should remove this function.
54  HGIGL_API
55  void InsertFunctionOp(std::function<void(void)> const& fn);
56 
57  HGIGL_API
58  void PushDebugGroup(const char* label) override;
59 
60  HGIGL_API
61  void PopDebugGroup() override;
62 
63  HGIGL_API
64  void SetViewport(GfVec4i const& vp) override;
65 
66  HGIGL_API
67  void SetScissor(GfVec4i const& sc) override;
68 
69  HGIGL_API
70  void BindPipeline(HgiGraphicsPipelineHandle pipeline) override;
71 
72  HGIGL_API
73  void BindResources(HgiResourceBindingsHandle resources) override;
74 
75  HGIGL_API
76  void SetConstantValues(
79  uint32_t bindIndex,
80  uint32_t byteSize,
81  const void* data) override;
82 
83  HGIGL_API
84  void BindVertexBuffers(
85  HgiVertexBufferBindingVector const &bindings) override;
86 
87  HGIGL_API
88  void Draw(
89  uint32_t vertexCount,
90  uint32_t baseVertex,
91  uint32_t instanceCount,
92  uint32_t baseInstance) override;
93 
94  HGIGL_API
95  void DrawIndirect(
96  HgiBufferHandle const& drawParameterBuffer,
97  uint32_t drawBufferByteOffset,
98  uint32_t drawCount,
99  uint32_t stride) override;
100 
101  HGIGL_API
102  void DrawIndexed(
103  HgiBufferHandle const& indexBuffer,
104  uint32_t indexCount,
105  uint32_t indexBufferByteOffset,
106  uint32_t baseVertex,
107  uint32_t instanceCount,
108  uint32_t baseInstance) override;
109 
110  HGIGL_API
111  void DrawIndexedIndirect(
112  HgiBufferHandle const& indexBuffer,
113  HgiBufferHandle const& drawParameterBuffer,
114  uint32_t drawBufferByteOffset,
115  uint32_t drawCount,
116  uint32_t stride,
117  std::vector<uint32_t> const& drawParameterBufferUInt32,
118  uint32_t patchBaseVertexByteOffset) override;
119 
120  HGIGL_API
121  void InsertMemoryBarrier(HgiMemoryBarrier barrier) override;
122 
123 protected:
124  friend class HgiGL;
125 
126  HGIGL_API
128  HgiGLDevice* device,
129  HgiGraphicsCmdsDesc const& desc);
130 
131  HGIGL_API
132  bool _Submit(Hgi* hgi, HgiSubmitWaitType wait) override;
133 
134 private:
135  HgiGLGraphicsCmds() = delete;
136  HgiGLGraphicsCmds & operator=(const HgiGLGraphicsCmds&) = delete;
137  HgiGLGraphicsCmds(const HgiGLGraphicsCmds&) = delete;
138 
139  /// This performs multisample resolve when needed at the end of recording.
140  void _AddResolveToOps(HgiGLDevice* device);
141 
142  bool _recording;
143  HgiGraphicsCmdsDesc _descriptor;
144  HgiPrimitiveType _primitiveType;
145  int _primitiveIndexSize;
146  HgiGLOpsVector _ops;
147  int _pushStack;
148  int32_t _restoreReadFramebuffer;
149  int32_t _restoreDrawFramebuffer;
150 
151  // Cmds is used only one frame so storing multi-frame state on will not
152  // survive.
153 };
154 
156 
157 #endif
Definition: vec4i.h:60
HGIGL_API void SetConstantValues(HgiGraphicsPipelineHandle pipeline, HgiShaderStage stages, uint32_t bindIndex, uint32_t byteSize, const void *data) override
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
GLbitfield stages
Definition: glcorearb.h:1931
HGIGL_API void PushDebugGroup(const char *label) override
Push a debug marker.
HGIGL_API void Draw(uint32_t vertexCount, uint32_t baseVertex, uint32_t instanceCount, uint32_t baseInstance) override
HGIGL_API void SetScissor(GfVec4i const &sc) override
HGIGL_API void DrawIndexedIndirect(HgiBufferHandle const &indexBuffer, HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferByteOffset, uint32_t drawCount, uint32_t stride, std::vector< uint32_t > const &drawParameterBufferUInt32, uint32_t patchBaseVertexByteOffset) override
HGIGL_API void BindVertexBuffers(HgiVertexBufferBindingVector const &bindings) override
Binds the vertex buffer(s) that describe the vertex attributes.
HGIGL_API bool _Submit(Hgi *hgi, HgiSubmitWaitType wait) override
HgiSubmitWaitType
Definition: enums.h:663
std::vector< HgiVertexBufferBinding > HgiVertexBufferBindingVector
Definition: hgi.h:71
HgiBits HgiMemoryBarrier
Definition: enums.h:685
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
#define HGIGL_API
Definition: api.h:40
HgiPrimitiveType
Definition: enums.h:609
HGIGL_API void BindPipeline(HgiGraphicsPipelineHandle pipeline) override
HGIGL_API ~HgiGLGraphicsCmds() override
HGIGL_API void PopDebugGroup() override
Pop the last debug marker.
*tasks wait()
Definition: hgi.h:110
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
HGIGL_API void DrawIndirect(HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferByteOffset, uint32_t drawCount, uint32_t stride) override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HGIGL_API void InsertFunctionOp(std::function< void(void)> const &fn)
HgiBits HgiShaderStage
Definition: enums.h:370
HGIGL_API void BindResources(HgiResourceBindingsHandle resources) override
std::vector< HgiGLOpsFn > HgiGLOpsVector
Definition: hgi.h:43
HGIGL_API void SetViewport(GfVec4i const &vp) override
Set viewport [left, BOTTOM, width, height] - OpenGL coords.
HGIGL_API void InsertMemoryBarrier(HgiMemoryBarrier barrier) override
HGIGL_API void DrawIndexed(HgiBufferHandle const &indexBuffer, uint32_t indexCount, uint32_t indexBufferByteOffset, uint32_t baseVertex, uint32_t instanceCount, uint32_t baseInstance) override
Definition: format.h:895