HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ops.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_HGIGL_OPS_H
25 #define PXR_IMAGING_HGIGL_OPS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/gf/vec4i.h"
29 
30 #include "pxr/imaging/hgi/buffer.h"
35 
36 #include "pxr/imaging/hgiGL/api.h"
38 
39 #include <cstdint>
40 #include <functional>
41 #include <vector>
42 
44 
45 using HgiGLOpsFn = std::function<void(void)>;
46 
47 /// \class HgiGLOps
48 ///
49 /// A collection of functions used by cmds objects to do deferred cmd recording.
50 /// Modern API's support command buffer recording of gfx commands ('deferred').
51 /// Meaning: No commands are executed on the GPU until we Submit the cmd buffer.
52 ///
53 /// OpenGL uses 'immediate' mode instead where gfx commands are immediately
54 /// processed and given to the GPU at a time of the drivers choosing.
55 /// We use 'Ops' functions to record our OpenGL function in a list and only
56 /// execute them in OpenGL during the SubmitCmds phase.
57 ///
58 /// This has two benefits:
59 ///
60 /// 1. OpenGL behaves more like Metal and Vulkan. So when clients write Hgi code
61 /// they get similar behavior in gpu command execution across all backends.
62 /// For example, if you are running with HgiGL and recording commands into a
63 /// Hgi***Cmds object and forget to call 'SubmitCmds' you will notice that
64 /// your commands are not executed on the GPU, just like what would happen if
65 /// you were running with HgiMetal.
66 ///
67 /// 2. It lets us satisfy the Hgi requirement that Hgi***Cmds objects must be
68 /// able to do their recording on secondary threads.
69 ///
70 class HgiGLOps
71 {
72 public:
73  HGIGL_API
74  static HgiGLOpsFn PushDebugGroup(const char* label);
75 
76  HGIGL_API
77  static HgiGLOpsFn PopDebugGroup();
78 
79  HGIGL_API
81 
82  HGIGL_API
84 
85  HGIGL_API
87 
88  HGIGL_API
90 
91  HGIGL_API
93 
94  HGIGL_API
96 
97  HGIGL_API
99 
100  HGIGL_API
102  HgiGLDevice* device,
103  HgiGraphicsCmdsDesc const &graphicsCmds);
104 
105  HGIGL_API
106  static HgiGLOpsFn SetViewport(GfVec4i const& vp);
107 
108  HGIGL_API
109  static HgiGLOpsFn SetScissor(GfVec4i const& sc);
110 
111  HGIGL_API
113 
114  HGIGL_API
116 
117  HGIGL_API
119 
120  HGIGL_API
122  HgiGraphicsPipelineHandle pipeline,
124  uint32_t bindIndex,
125  uint32_t byteSize,
126  const void* data);
127 
128  HGIGL_API
130  HgiComputePipelineHandle pipeline,
131  uint32_t bindIndex,
132  uint32_t byteSize,
133  const void* data);
134 
135  HGIGL_API
137  HgiVertexBufferBindingVector const &bindings);
138 
139  HGIGL_API
140  static HgiGLOpsFn Draw(
141  HgiPrimitiveType primitiveType,
142  uint32_t primitiveIndexSize,
143  uint32_t vertexCount,
144  uint32_t baseVertex,
145  uint32_t instanceCount,
146  uint32_t baseInstance);
147 
148  HGIGL_API
149  static HgiGLOpsFn DrawIndirect(
150  HgiPrimitiveType primitiveType,
151  uint32_t primitiveIndexSize,
152  HgiBufferHandle const& drawParameterBuffer,
153  uint32_t drawBufferByteOffset,
154  uint32_t drawCount,
155  uint32_t stride);
156 
157  HGIGL_API
158  static HgiGLOpsFn DrawIndexed(
159  HgiPrimitiveType primitiveType,
160  uint32_t primitiveIndexSize,
161  HgiBufferHandle const& indexBuffer,
162  uint32_t indexCount,
163  uint32_t indexBufferByteOffset,
164  uint32_t baseVertex,
165  uint32_t instanceCount,
166  uint32_t baseInstance);
167 
168  HGIGL_API
170  HgiPrimitiveType primitiveType,
171  uint32_t primitiveIndexSize,
172  HgiBufferHandle const& indexBuffer,
173  HgiBufferHandle const& drawParameterBuffer,
174  uint32_t drawBufferByteOffset,
175  uint32_t drawCount,
176  uint32_t stride);
177 
178  HGIGL_API
180  HgiGLDevice* device,
181  HgiGraphicsCmdsDesc const& desc);
182 
183  HGIGL_API
184  static HgiGLOpsFn Dispatch(int dimX, int dimY);
185 
186  HGIGL_API
187  static HgiGLOpsFn FillBuffer(HgiBufferHandle const& buffer, uint8_t value);
188 
189  HGIGL_API
191 
192  HGIGL_API
194 
195 };
196 
198 
199 #endif
Definition: vec4i.h:60
static HGIGL_API HgiGLOpsFn CopyBufferToTexture(HgiBufferToTextureOp const &copyOp)
static HGIGL_API HgiGLOpsFn BindResources(HgiResourceBindingsHandle resources)
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
GLbitfield stages
Definition: glcorearb.h:1931
static HGIGL_API HgiGLOpsFn CopyTextureToBuffer(HgiTextureToBufferOp const &copyOp)
std::function< void(void)> HgiGLOpsFn
Definition: hgi.h:42
static HGIGL_API HgiGLOpsFn CopyBufferGpuToGpu(HgiBufferGpuToGpuOp const &copyOp)
static HGIGL_API HgiGLOpsFn ResolveFramebuffer(HgiGLDevice *device, HgiGraphicsCmdsDesc const &graphicsCmds)
int HgiHandle< class HgiTexture > HgiTextureHandle
static HGIGL_API HgiGLOpsFn CopyTextureGpuToCpu(HgiTextureGpuToCpuOp const &copyOp)
static HGIGL_API HgiGLOpsFn CopyTextureCpuToGpu(HgiTextureCpuToGpuOp const &copyOp)
std::vector< HgiVertexBufferBinding > HgiVertexBufferBindingVector
Definition: core.h:760
static HGIGL_API HgiGLOpsFn PopDebugGroup()
static HGIGL_API HgiGLOpsFn PushDebugGroup(const char *label)
static HGIGL_API HgiGLOpsFn GenerateMipMaps(HgiTextureHandle const &texture)
HgiBits HgiMemoryBarrier
Definition: enums.h:686
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
#define HGIGL_API
Definition: api.h:40
HgiPrimitiveType
Definition: enums.h:610
static HGIGL_API HgiGLOpsFn DrawIndexedIndirect(HgiPrimitiveType primitiveType, uint32_t primitiveIndexSize, HgiBufferHandle const &indexBuffer, HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferByteOffset, uint32_t drawCount, uint32_t stride)
static HGIGL_API HgiGLOpsFn Dispatch(int dimX, int dimY)
static HGIGL_API HgiGLOpsFn DrawIndirect(HgiPrimitiveType primitiveType, uint32_t primitiveIndexSize, HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferByteOffset, uint32_t drawCount, uint32_t stride)
static HGIGL_API HgiGLOpsFn SetScissor(GfVec4i const &sc)
static HGIGL_API HgiGLOpsFn InsertMemoryBarrier(HgiMemoryBarrier barrier)
static HGIGL_API HgiGLOpsFn DrawIndexed(HgiPrimitiveType primitiveType, uint32_t primitiveIndexSize, HgiBufferHandle const &indexBuffer, uint32_t indexCount, uint32_t indexBufferByteOffset, uint32_t baseVertex, uint32_t instanceCount, uint32_t baseInstance)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
static HGIGL_API HgiGLOpsFn CopyBufferGpuToCpu(HgiBufferGpuToCpuOp const &copyOp)
static HGIGL_API HgiGLOpsFn CopyBufferCpuToGpu(HgiBufferCpuToGpuOp const &copyOp)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
static HGIGL_API HgiGLOpsFn FillBuffer(HgiBufferHandle const &buffer, uint8_t value)
static HGIGL_API HgiGLOpsFn SetConstantValues(HgiGraphicsPipelineHandle pipeline, HgiShaderStage stages, uint32_t bindIndex, uint32_t byteSize, const void *data)
HgiBits HgiShaderStage
Definition: enums.h:371
GLuint texture
Definition: glcorearb.h:415
Definition: core.h:1131
static HGIGL_API HgiGLOpsFn BindVertexBuffers(HgiVertexBufferBindingVector const &bindings)
static HGIGL_API HgiGLOpsFn BindPipeline(HgiGraphicsPipelineHandle pipeline)
static HGIGL_API HgiGLOpsFn SetViewport(GfVec4i const &vp)
static HGIGL_API HgiGLOpsFn Draw(HgiPrimitiveType primitiveType, uint32_t primitiveIndexSize, uint32_t vertexCount, uint32_t baseVertex, uint32_t instanceCount, uint32_t baseInstance)
static HGIGL_API HgiGLOpsFn BindFramebufferOp(HgiGLDevice *device, HgiGraphicsCmdsDesc const &desc)
Definition: format.h:895
Definition: ops.h:70