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
82 void DestroyTexture(HgiTextureHandle* texHandle) override;
83
84 HGIGL_API
85 void DestroyTextureView(HgiTextureViewHandle* viewHandle) override;
86
87 HGIGL_API
89
90 HGIGL_API
91 void DestroySampler(HgiSamplerHandle* smpHandle) override;
92
93 HGIGL_API
94 void DestroyBuffer(HgiBufferHandle* bufHandle) override;
95
96 HGIGL_API
98 HgiShaderFunctionDesc const& desc) override;
99
100 HGIGL_API
102 HgiShaderFunctionHandle* shaderFunctionHandle) override;
103
104 HGIGL_API
106 HgiShaderProgramDesc const& desc) override;
107
108 HGIGL_API
110 HgiShaderProgramHandle* shaderProgramHandle) override;
111
112 HGIGL_API
114
115 HGIGL_API
117 HgiGraphicsPipelineDesc const& pipeDesc) override;
118
119 HGIGL_API
121 HgiGraphicsPipelineHandle* pipeHandle) override;
122
123 HGIGL_API
125 HgiComputePipelineDesc const& pipeDesc) override;
126
127 HGIGL_API
129
130 HGIGL_API
131 TfToken const& GetAPIName() const override;
132
133 HGIGL_API
134 HgiGLCapabilities const* GetCapabilities() const override;
135
136 HGIGL_API
138
139 HGIGL_API
140 void StartFrame() override;
141
142 HGIGL_API
143 void EndFrame() override;
144
145 HGIGL_API
146 void GarbageCollect() override;
147
149 // HgiGL specific API
151
152 // Returns the opengl device.
153 HGIGL_API
155
161 HGIGL_API
163
167 HGIGL_API
169
172 HGIGL_API
173 void SetContextArena(HgiGLContextArenaHandle const& arenaHandle);
174 // -------------------------------------------------------------------------
175
176protected:
177 HGIGL_API
178 HgiTextureHandle _CreateTexture(HgiTextureDesc const & desc) override;
179
180 HGIGL_API
181 HgiTextureViewHandle _CreateTextureView(
182 HgiTextureViewDesc const& desc) override;
183
184 HGIGL_API
185 HgiBufferHandle _CreateBuffer(HgiBufferDesc const & desc) override;
186
187 HGIGL_API
188 HgiResourceBindingsHandle _CreateResourceBindings(
189 HgiResourceBindingsDesc const& desc) override;
190
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:29
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 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 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 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.
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