Loading...
Searching...
No Matches
hgi.h
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_HGI_H
8#define PXR_IMAGING_HGI_GL_HGI_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hgiGL/api.h"
12#include "pxr/imaging/hgiGL/capabilities.h"
13#include "pxr/imaging/hgiGL/garbageCollector.h"
14#include "pxr/imaging/hgi/hgi.h"
15#include "pxr/imaging/hgi/tokens.h"
16
17#include <functional>
18#include <memory>
19#include <vector>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23class HgiGLDevice;
24
25using HgiGLOpsFn = std::function<void(void)>;
26using HgiGLOpsVector = std::vector<HgiGLOpsFn>;
28
54class HgiGL final : public Hgi
55{
56public:
57 HGIGL_API
58 HgiGL();
59
60 HGIGL_API
61 ~HgiGL() override;
62
66
67 HGIGL_API
68 bool IsBackendSupported() const override;
69
70 HGIGL_API
71 HgiGraphicsCmdsUniquePtr CreateGraphicsCmds(
72 HgiGraphicsCmdsDesc const& desc) override;
73
74 HGIGL_API
75 HgiBlitCmdsUniquePtr CreateBlitCmds() override;
76
77 HGIGL_API
78 HgiComputeCmdsUniquePtr CreateComputeCmds(
79 HgiComputeCmdsDesc const& desc) override;
80
81 HGIGL_API
83
84 HGIGL_API
85 void DestroyTexture(HgiTextureHandle* texHandle) override;
86
87 HGIGL_API
89 HgiTextureViewDesc const& desc) override;
90
91 HGIGL_API
92 void DestroyTextureView(HgiTextureViewHandle* viewHandle) override;
93
94 HGIGL_API
96
97 HGIGL_API
98 void DestroySampler(HgiSamplerHandle* smpHandle) override;
99
100 HGIGL_API
102
103 HGIGL_API
104 void DestroyBuffer(HgiBufferHandle* bufHandle) override;
105
106 HGIGL_API
108 HgiShaderFunctionDesc const& desc) override;
109
110 HGIGL_API
112 HgiShaderFunctionHandle* shaderFunctionHandle) override;
113
114 HGIGL_API
116 HgiShaderProgramDesc const& desc) override;
117
118 HGIGL_API
120 HgiShaderProgramHandle* shaderProgramHandle) override;
121
122 HGIGL_API
124 HgiResourceBindingsDesc const& desc) override;
125
126 HGIGL_API
128
129 HGIGL_API
131 HgiGraphicsPipelineDesc const& pipeDesc) override;
132
133 HGIGL_API
135 HgiGraphicsPipelineHandle* pipeHandle) override;
136
137 HGIGL_API
139 HgiComputePipelineDesc const& pipeDesc) override;
140
141 HGIGL_API
143
144 HGIGL_API
145 TfToken const& GetAPIName() const override;
146
147 HGIGL_API
148 HgiGLCapabilities const* GetCapabilities() const override;
149
150 HGIGL_API
152
153 HGIGL_API
154 void StartFrame() override;
155
156 HGIGL_API
157 void EndFrame() override;
158
159 HGIGL_API
160 void GarbageCollect() override;
161
163 // HgiGL specific API
165
166 // Returns the opengl device.
167 HGIGL_API
169
175 HGIGL_API
177
181 HGIGL_API
183
186 HGIGL_API
187 void SetContextArena(HgiGLContextArenaHandle const& arenaHandle);
188 // -------------------------------------------------------------------------
189
190protected:
191 HGIGL_API
192 bool _SubmitCmds(HgiCmds* cmds, HgiSubmitWaitType wait) override;
193
194private:
195 HgiGL & operator=(const HgiGL&) = delete;
196 HgiGL(const HgiGL&) = delete;
197
201 template<class T>
202 void _TrashObject(
203 HgiHandle<T>* handle, std::vector<HgiHandle<T>>* collector) {
204 collector->push_back(HgiHandle<T>(handle->Get(), /*id*/0));
205 *handle = HgiHandle<T>();
206 }
207
208 HgiGLDevice* _device;
209 std::unique_ptr<HgiGLCapabilities> _capabilities;
210 HgiGLGarbageCollector _garbageCollector;
211 int _frameDepth;
212};
213
219#define HGIGL_API_VERSION 2
220
221PXR_NAMESPACE_CLOSE_SCOPE
222
223#endif
Graphics commands are recorded in 'cmds' objects which are later submitted to hgi.
Definition: cmds.h:28
Reports the capabilities of the HgiGL device.
Definition: capabilities.h:21
OpenGL implementation of GPU device.
Definition: device.h:29
Handles garbage collection of opengl objects by delaying their destruction until those objects are no...
OpenGL implementation of the Hydra Graphics Interface.
Definition: hgi.h:55
HGIGL_API HgiGraphicsCmdsUniquePtr CreateGraphicsCmds(HgiGraphicsCmdsDesc const &desc) override
Returns a GraphicsCmds object (for temporary use) that is ready to record draw commands.
HGIGL_API void DestroyContextArena(HgiGLContextArenaHandle *arenaHandle)
Destroy a context arena.
HGIGL_API void StartFrame() override
Optionally called by client app at the start of a new rendering frame.
HGIGL_API bool IsBackendSupported() const override
HGIGL_API void GarbageCollect() override
Perform any necessary garbage collection, if applicable.
HGIGL_API void SetContextArena(HgiGLContextArenaHandle const &arenaHandle)
Set the context arena to manage container resources (currently limited to framebuffer objects) for gr...
HGIGL_API HgiBufferHandle CreateBuffer(HgiBufferDesc const &desc) override
Create a buffer in rendering backend.
HGIGL_API void DestroyTexture(HgiTextureHandle *texHandle) override
Destroy a texture in rendering backend.
HGIGL_API void DestroyTextureView(HgiTextureViewHandle *viewHandle) override
Destroy a texture view in rendering backend.
HGIGL_API HgiGLDevice * GetPrimaryDevice() const
HGIGL_API HgiTextureViewHandle CreateTextureView(HgiTextureViewDesc const &desc) override
Create a texture view in rendering backend.
HGIGL_API void DestroyShaderFunction(HgiShaderFunctionHandle *shaderFunctionHandle) override
Destroy a shader function.
HGIGL_API HgiBlitCmdsUniquePtr CreateBlitCmds() override
Returns a BlitCmds object (for temporary use) that is ready to execute resource copy commands.
HGIGL_API HgiShaderProgramHandle CreateShaderProgram(HgiShaderProgramDesc const &desc) override
Create a new shader program.
HGIGL_API HgiShaderFunctionHandle CreateShaderFunction(HgiShaderFunctionDesc const &desc) override
Create a new shader function.
HGIGL_API HgiSamplerHandle CreateSampler(HgiSamplerDesc const &desc) override
Create a sampler in rendering backend.
HGIGL_API void DestroyResourceBindings(HgiResourceBindingsHandle *resHandle) override
Destroy a resource binding object.
HGIGL_API HgiComputeCmdsUniquePtr CreateComputeCmds(HgiComputeCmdsDesc const &desc) override
Returns a ComputeCmds object (for temporary use) that is ready to record dispatch commands.
HGIGL_API void DestroyShaderProgram(HgiShaderProgramHandle *shaderProgramHandle) override
Destroy a shader program.
HGIGL_API HgiGLCapabilities const * GetCapabilities() const override
Returns the device-specific capabilities structure.
HGIGL_API HgiResourceBindingsHandle CreateResourceBindings(HgiResourceBindingsDesc const &desc) override
Create a new resource binding object.
HGIGL_API HgiGLContextArenaHandle CreateContextArena()
HGIGL_API void DestroyGraphicsPipeline(HgiGraphicsPipelineHandle *pipeHandle) override
Destroy a graphics pipeline state object.
HGIGL_API void DestroyBuffer(HgiBufferHandle *bufHandle) override
Destroy a buffer in rendering backend.
HGIGL_API void EndFrame() override
Optionally called at the end of a rendering frame.
HGIGL_API HgiComputePipelineHandle CreateComputePipeline(HgiComputePipelineDesc const &pipeDesc) override
Create a new compute pipeline state object.
HGIGL_API HgiGraphicsPipelineHandle CreateGraphicsPipeline(HgiGraphicsPipelineDesc const &pipeDesc) override
Create a new graphics pipeline state object.
HGIGL_API HgiIndirectCommandEncoder * GetIndirectCommandEncoder() const override
Returns the device-specific indirect command buffer encoder or nullptr if not supported.
HGIGL_API void DestroySampler(HgiSamplerHandle *smpHandle) override
Destroy a sampler in rendering backend.
HGIGL_API void DestroyComputePipeline(HgiComputePipelineHandle *pipeHandle) override
Destroy a compute pipeline state object.
HGIGL_API TfToken const & GetAPIName() const override
Return the name of the api (e.g.
HGIGL_API HgiTextureHandle CreateTexture(HgiTextureDesc const &desc) override
Create a texture in rendering backend.
Handle that contains a hgi object and unique id.
Definition: handle.h:33
Hydra Graphics Interface.
Definition: hgi.h:95
The indirect command encoder is used to record the drawing primitives for a batch and capture the res...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Describes the properties needed to create a GPU buffer.
Definition: buffer.h:46
Describes the properties to construct a HgiComputeCmds.
Describes the properties needed to create a GPU compute pipeline.
Describes the properties to begin a HgiGraphicsCmds.
Describes the properties needed to create a GPU pipeline.
Describes a set of resources that are bound to the GPU during encoding.
Describes the properties needed to create a GPU sampler.
Definition: sampler.h:62
Describes the properties needed to create a GPU shader function.
Describes the properties needed to create a GPU shader program.
Definition: shaderProgram.h:35
Describes the properties needed to create a GPU texture.
Definition: texture.h:91
Describes the properties needed to create a GPU texture view from an existing GPU texture object.
Definition: texture.h:229