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  uint32_t firstBinding,
139  std::vector<uint32_t> const& byteOffsets);
140 
141  HGIGL_API
142  static HgiGLOpsFn Draw(
143  HgiPrimitiveType primitiveType,
144  uint32_t vertexCount,
145  uint32_t firstVertex,
146  uint32_t instanceCount);
147 
148  HGIGL_API
149  static HgiGLOpsFn DrawIndirect(
150  HgiPrimitiveType primitiveType,
151  HgiBufferHandle const& drawParameterBuffer,
152  uint32_t drawBufferOffset,
153  uint32_t drawCount,
154  uint32_t stride);
155 
156  HGIGL_API
157  static HgiGLOpsFn DrawIndexed(
158  HgiPrimitiveType primitiveType,
159  HgiBufferHandle const& indexBuffer,
160  uint32_t indexCount,
161  uint32_t indexBufferByteOffset,
162  uint32_t vertexOffset,
163  uint32_t instanceCount);
164 
165  HGIGL_API
167  HgiPrimitiveType primitiveType,
168  HgiBufferHandle const& indexBuffer,
169  HgiBufferHandle const& drawParameterBuffer,
170  uint32_t drawBufferOffset,
171  uint32_t drawCount,
172  uint32_t stride);
173 
174  HGIGL_API
176  HgiGLDevice* device,
177  HgiGraphicsCmdsDesc const& desc);
178 
179  HGIGL_API
180  static HgiGLOpsFn Dispatch(int dimX, int dimY);
181 
182  HGIGL_API
184 
185  HGIGL_API
187 
188 };
189 
191 
192 #endif
Definition: vec4i.h:61
static HGIGL_API HgiGLOpsFn CopyBufferToTexture(HgiBufferToTextureOp const &copyOp)
const void GLsizei drawCount
Definition: glew.h:12498
static HGIGL_API HgiGLOpsFn BindResources(HgiResourceBindingsHandle resources)
GLbitfield stages
Definition: glcorearb.h:1930
static HGIGL_API HgiGLOpsFn CopyTextureToBuffer(HgiTextureToBufferOp const &copyOp)
std::function< void(void)> HgiGLOpsFn
Definition: hgi.h:40
const GLuint * buffers
Definition: glcorearb.h:660
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)
static HGIGL_API HgiGLOpsFn Draw(HgiPrimitiveType primitiveType, uint32_t vertexCount, uint32_t firstVertex, uint32_t instanceCount)
static HGIGL_API HgiGLOpsFn PopDebugGroup()
std::vector< HgiBufferHandle > HgiBufferHandleVector
Definition: buffer.h:152
static HGIGL_API HgiGLOpsFn PushDebugGroup(const char *label)
static HGIGL_API HgiGLOpsFn GenerateMipMaps(HgiTextureHandle const &texture)
HgiBits HgiMemoryBarrier
Definition: enums.h:538
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
#define HGIGL_API
Definition: api.h:40
HgiPrimitiveType
Definition: enums.h:494
static HGIGL_API HgiGLOpsFn Dispatch(int dimX, int dimY)
static HGIGL_API HgiGLOpsFn SetScissor(GfVec4i const &sc)
GLboolean * data
Definition: glcorearb.h:130
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
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 DrawIndexed(HgiPrimitiveType primitiveType, HgiBufferHandle const &indexBuffer, uint32_t indexCount, uint32_t indexBufferByteOffset, uint32_t vertexOffset, uint32_t instanceCount)
GLuint barrier
Definition: wglew.h:1077
GLuint texture
Definition: glcorearb.h:414
static HGIGL_API HgiGLOpsFn SetConstantValues(HgiGraphicsPipelineHandle pipeline, HgiShaderStage stages, uint32_t bindIndex, uint32_t byteSize, const void *data)
static HGIGL_API HgiGLOpsFn DrawIndirect(HgiPrimitiveType primitiveType, HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferOffset, uint32_t drawCount, uint32_t stride)
HgiBits HgiShaderStage
Definition: enums.h:292
static HGIGL_API HgiGLOpsFn DrawIndexedIndirect(HgiPrimitiveType primitiveType, HgiBufferHandle const &indexBuffer, HgiBufferHandle const &drawParameterBuffer, uint32_t drawBufferOffset, uint32_t drawCount, uint32_t stride)
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:871
static HGIGL_API HgiGLOpsFn MemoryBarrier(HgiMemoryBarrier barrier)
static HGIGL_API HgiGLOpsFn BindPipeline(HgiGraphicsPipelineHandle pipeline)
static HGIGL_API HgiGLOpsFn BindVertexBuffers(uint32_t firstBinding, HgiBufferHandleVector const &buffers, std::vector< uint32_t > const &byteOffsets)
static HGIGL_API HgiGLOpsFn SetViewport(GfVec4i const &vp)
static HGIGL_API HgiGLOpsFn BindFramebufferOp(HgiGLDevice *device, HgiGraphicsCmdsDesc const &desc)
Definition: ops.h:70