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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HGI_GL_GRAPHICS_CMDS_H
8 #define PXR_IMAGING_HGI_GL_GRAPHICS_CMDS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/base/gf/vec4i.h"
13 #include "pxr/imaging/hgiGL/api.h"
14 #include "pxr/imaging/hgiGL/hgi.h"
15 #include <cstdint>
16 
18 
19 struct HgiGraphicsCmdsDesc;
20 class HgiGLDevice;
21 
22 /// \class HgiGLGraphicsCmds
23 ///
24 /// OpenGL implementation of HgiGraphicsCmds.
25 ///
26 class HgiGLGraphicsCmds final : public HgiGraphicsCmds
27 {
28 public:
29  HGIGL_API
30  ~HgiGLGraphicsCmds() override;
31 
32  /// XXX This function is exposed temporarily for Hgi transition.
33  /// It allows code that is not yet converted to Hgi (e.g. HdSt) to insert
34  /// its opengl calls into the ops-stack of HgiGL to ensure that all commands
35  /// execute in the correct order. Once HdSt has transition fully to Hgi we
36  /// should remove this function.
37  HGIGL_API
38  void InsertFunctionOp(std::function<void(void)> const& fn);
39 
40  HGIGL_API
41  void PushDebugGroup(const char* label,
42  const GfVec4f& color = s_graphicsDebugColor) override;
43 
44  HGIGL_API
45  void PopDebugGroup() override;
46 
47  HGIGL_API
48  void InsertDebugMarker(
49  const char* label,
50  const GfVec4f& color = s_markerDebugColor) override;
51 
52  HGIGL_API
53  void SetViewport(GfVec4i const& vp) override;
54 
55  HGIGL_API
56  void SetScissor(GfVec4i const& sc) override;
57 
58  HGIGL_API
59  void BindPipeline(HgiGraphicsPipelineHandle pipeline) override;
60 
61  HGIGL_API
62  void BindResources(HgiResourceBindingsHandle resources) override;
63 
64  HGIGL_API
65  void SetConstantValues(
68  uint32_t bindIndex,
69  uint32_t byteSize,
70  const void* data) override;
71 
72  HGIGL_API
73  void BindVertexBuffers(
74  HgiVertexBufferBindingVector const &bindings) override;
75 
76  HGIGL_API
77  void Draw(
78  uint32_t vertexCount,
79  uint32_t baseVertex,
80  uint32_t instanceCount,
81  uint32_t baseInstance) override;
82 
83  HGIGL_API
84  void DrawIndirect(
85  HgiBufferHandle const& drawParameterBuffer,
86  uint32_t drawBufferByteOffset,
87  uint32_t drawCount,
88  uint32_t stride) override;
89 
90  HGIGL_API
91  void DrawIndexed(
92  HgiBufferHandle const& indexBuffer,
93  uint32_t indexCount,
94  uint32_t indexBufferByteOffset,
95  uint32_t baseVertex,
96  uint32_t instanceCount,
97  uint32_t baseInstance) override;
98 
99  HGIGL_API
100  void DrawIndexedIndirect(
101  HgiBufferHandle const& indexBuffer,
102  HgiBufferHandle const& drawParameterBuffer,
103  uint32_t drawBufferByteOffset,
104  uint32_t drawCount,
105  uint32_t stride,
106  std::vector<uint32_t> const& drawParameterBufferUInt32,
107  uint32_t patchBaseVertexByteOffset) override;
108 
109  HGIGL_API
110  void InsertMemoryBarrier(HgiMemoryBarrier barrier) override;
111 
112 protected:
113  friend class HgiGL;
114 
115  HGIGL_API
117  HgiGLDevice* device,
118  HgiGraphicsCmdsDesc const& desc);
119 
120  HGIGL_API
121  bool _Submit(Hgi* hgi, HgiSubmitWaitType wait) override;
122 
123 private:
124  HgiGLGraphicsCmds() = delete;
125  HgiGLGraphicsCmds & operator=(const HgiGLGraphicsCmds&) = delete;
126  HgiGLGraphicsCmds(const HgiGLGraphicsCmds&) = delete;
127 
128  /// This performs multisample resolve when needed at the end of recording.
129  void _AddResolveToOps(HgiGLDevice* device);
130 
131  bool _recording;
132  HgiGraphicsCmdsDesc _descriptor;
133  HgiPrimitiveType _primitiveType;
134  int _primitiveIndexSize;
135  HgiGLOpsVector _ops;
136  int _pushStack;
137  int32_t _restoreReadFramebuffer;
138  int32_t _restoreDrawFramebuffer;
139 
140  // Cmds is used only one frame so storing multi-frame state on will not
141  // survive.
142 };
143 
145 
146 #endif
Definition: vec4i.h:43
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 Draw(uint32_t vertexCount, uint32_t baseVertex, uint32_t instanceCount, uint32_t baseInstance) override
HGIGL_API void InsertDebugMarker(const char *label, const GfVec4f &color=s_markerDebugColor) override
Insert a debug marker.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
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.
static constexpr GfVec4f s_graphicsDebugColor
Definition: cmds.h:57
HGIGL_API bool _Submit(Hgi *hgi, HgiSubmitWaitType wait) override
HgiSubmitWaitType
Definition: enums.h:657
std::vector< HgiVertexBufferBinding > HgiVertexBufferBindingVector
Definition: hgi.h:54
HgiBits HgiMemoryBarrier
Definition: enums.h:679
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
#define HGIGL_API
Definition: api.h:23
HgiPrimitiveType
Definition: enums.h:603
HGIGL_API void BindPipeline(HgiGraphicsPipelineHandle pipeline) override
static constexpr GfVec4f s_markerDebugColor
Definition: cmds.h:61
HGIGL_API ~HgiGLGraphicsCmds() override
HGIGL_API void PopDebugGroup() override
Pop the last debug scope.
Definition: vec4f.h:45
*tasks wait()
Definition: hgi.h:94
GLuint color
Definition: glcorearb.h:1261
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:74
HGIGL_API void InsertFunctionOp(std::function< void(void)> const &fn)
HgiBits HgiShaderStage
Definition: enums.h:364
HGIGL_API void BindResources(HgiResourceBindingsHandle resources) override
std::vector< HgiGLOpsFn > HgiGLOpsVector
Definition: hgi.h:26
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
HGIGL_API void PushDebugGroup(const char *label, const GfVec4f &color=s_graphicsDebugColor) override
Push a debug scope.
Definition: format.h:1821