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_HGI_H
8#define PXR_IMAGING_HGI_HGI_H
9
10#include "pxr/pxr.h"
11#include "pxr/base/tf/token.h"
12#include "pxr/base/tf/type.h"
13
14#include "pxr/imaging/hgi/api.h"
15#include "pxr/imaging/hgi/blitCmds.h"
16#include "pxr/imaging/hgi/buffer.h"
17#include "pxr/imaging/hgi/computeCmds.h"
18#include "pxr/imaging/hgi/computeCmdsDesc.h"
19#include "pxr/imaging/hgi/graphicsCmds.h"
20#include "pxr/imaging/hgi/graphicsCmdsDesc.h"
21#include "pxr/imaging/hgi/graphicsPipeline.h"
22#include "pxr/imaging/hgi/resourceBindings.h"
23#include "pxr/imaging/hgi/sampler.h"
24#include "pxr/imaging/hgi/shaderFunction.h"
25#include "pxr/imaging/hgi/shaderProgram.h"
26#include "pxr/imaging/hgi/texture.h"
27#include "pxr/imaging/hgi/types.h"
28
29#include <atomic>
30#include <memory>
31
32PXR_NAMESPACE_OPEN_SCOPE
33
34class HgiCapabilities;
36
37using HgiUniquePtr = std::unique_ptr<class Hgi>;
38
39
93class Hgi
94{
95public:
96 HGI_API
97 Hgi();
98
99 HGI_API
100 virtual ~Hgi();
101
110 HGI_API
112 HgiCmds* cmds,
113 HgiSubmitWaitType wait = HgiSubmitWaitTypeNoWait);
114
116 HGI_API
118
124 HGI_API
125 static HgiUniquePtr CreatePlatformDefaultHgi();
126
140 HGI_API
141 static HgiUniquePtr CreateNamedHgi(const TfToken& hgiToken);
142
145 HGI_API
146 virtual bool IsBackendSupported() const = 0;
147
157 HGI_API
158 static bool IsSupported(const TfToken& hgiToken = TfToken());
159
166 HGI_API
167 virtual HgiGraphicsCmdsUniquePtr CreateGraphicsCmds(
168 HgiGraphicsCmdsDesc const& desc) = 0;
169
176 HGI_API
177 virtual HgiBlitCmdsUniquePtr CreateBlitCmds() = 0;
178
185 HGI_API
186 virtual HgiComputeCmdsUniquePtr CreateComputeCmds(
187 HgiComputeCmdsDesc const& desc) = 0;
188
191 HGI_API
193
196 HGI_API
197 virtual void DestroyTexture(HgiTextureHandle* texHandle) = 0;
198
204 HGI_API
206 HgiTextureViewDesc const & desc) = 0;
207
212 HGI_API
213 virtual void DestroyTextureView(HgiTextureViewHandle* viewHandle) = 0;
214
217 HGI_API
219
222 HGI_API
223 virtual void DestroySampler(HgiSamplerHandle* smpHandle) = 0;
224
227 HGI_API
228 virtual HgiBufferHandle CreateBuffer(HgiBufferDesc const & desc) = 0;
229
232 HGI_API
233 virtual void DestroyBuffer(HgiBufferHandle* bufHandle) = 0;
234
237 HGI_API
239 HgiShaderFunctionDesc const& desc) = 0;
240
243 HGI_API
245 HgiShaderFunctionHandle* shaderFunctionHandle) = 0;
246
249 HGI_API
251 HgiShaderProgramDesc const& desc) = 0;
252
257 HGI_API
259 HgiShaderProgramHandle* shaderProgramHandle) = 0;
260
263 HGI_API
265 HgiResourceBindingsDesc const& desc) = 0;
266
269 HGI_API
271 HgiResourceBindingsHandle* resHandle) = 0;
272
275 HGI_API
277 HgiGraphicsPipelineDesc const& pipeDesc) = 0;
278
281 HGI_API
283 HgiGraphicsPipelineHandle* pipeHandle) = 0;
284
287 HGI_API
289 HgiComputePipelineDesc const& pipeDesc) = 0;
290
293 HGI_API
295
298 HGI_API
299 virtual TfToken const& GetAPIName() const = 0;
300
303 HGI_API
304 virtual HgiCapabilities const* GetCapabilities() const = 0;
305
309 HGI_API
311
318 HGI_API
319 virtual void StartFrame() = 0;
320
324 HGI_API
325 virtual void EndFrame() = 0;
326
327protected:
328 // Returns a unique id for handle creation.
329 // Thread safety: Thread-safe atomic increment.
330 HGI_API
331 uint64_t GetUniqueId();
332
333 // Calls Submit on provided Cmds.
334 // Derived classes can override this function if they need customize the
335 // command submission. The default implementation calls cmds->_Submit().
336 HGI_API
337 virtual bool _SubmitCmds(
338 HgiCmds* cmds, HgiSubmitWaitType wait);
339
340private:
341 Hgi & operator=(const Hgi&) = delete;
342 Hgi(const Hgi&) = delete;
343
344 std::atomic<uint64_t> _uniqueIdCounter;
345};
346
347
352public:
353 virtual Hgi* New() const = 0;
354};
355
356template <class T>
357class HgiFactory : public HgiFactoryBase {
358public:
359 Hgi* New() const {
360 return new T;
361 }
362};
363
364
365PXR_NAMESPACE_CLOSE_SCOPE
366
367#endif
Reports the capabilities of the Hgi device.
Definition: capabilities.h:23
Graphics commands are recorded in 'cmds' objects which are later submitted to hgi.
Definition: cmds.h:28
Hgi factory for plugin system.
Definition: hgi.h:351
Hydra Graphics Interface.
Definition: hgi.h:94
virtual HGI_API void DestroyBuffer(HgiBufferHandle *bufHandle)=0
Destroy a buffer in rendering backend.
virtual HGI_API TfToken const & GetAPIName() const =0
Return the name of the api (e.g.
virtual HGI_API HgiSamplerHandle CreateSampler(HgiSamplerDesc const &desc)=0
Create a sampler in rendering backend.
virtual HGI_API void DestroyShaderProgram(HgiShaderProgramHandle *shaderProgramHandle)=0
Destroy a shader program.
virtual HGI_API HgiTextureHandle CreateTexture(HgiTextureDesc const &desc)=0
Create a texture in rendering backend.
virtual HGI_API void EndFrame()=0
Optionally called at the end of a rendering frame.
virtual HGI_API void DestroyGraphicsPipeline(HgiGraphicsPipelineHandle *pipeHandle)=0
Destroy a graphics pipeline state object.
virtual HGI_API void DestroyResourceBindings(HgiResourceBindingsHandle *resHandle)=0
Destroy a resource binding object.
virtual HGI_API void DestroyComputePipeline(HgiComputePipelineHandle *pipeHandle)=0
Destroy a compute pipeline state object.
virtual HGI_API bool IsBackendSupported() const =0
Determine if Hgi instance can run on current hardware.
virtual HGI_API HgiShaderFunctionHandle CreateShaderFunction(HgiShaderFunctionDesc const &desc)=0
Create a new shader function.
virtual HGI_API void DestroySampler(HgiSamplerHandle *smpHandle)=0
Destroy a sampler in rendering backend.
static HGI_API bool IsSupported(const TfToken &hgiToken=TfToken())
Constructs a temporary Hgi object and calls the object's IsBackendSupported() function.
static HGI_API Hgi * GetPlatformDefaultHgi()
*** DEPRECATED *** Please use: CreatePlatformDefaultHgi
virtual HGI_API HgiResourceBindingsHandle CreateResourceBindings(HgiResourceBindingsDesc const &desc)=0
Create a new resource binding object.
virtual HGI_API void DestroyTextureView(HgiTextureViewHandle *viewHandle)=0
Destroy a texture view in rendering backend.
static HGI_API HgiUniquePtr CreatePlatformDefaultHgi()
Helper function to return a Hgi object for the current platform.
virtual HGI_API void StartFrame()=0
Optionally called by client app at the start of a new rendering frame.
virtual HGI_API void DestroyTexture(HgiTextureHandle *texHandle)=0
Destroy a texture in rendering backend.
virtual HGI_API HgiGraphicsCmdsUniquePtr CreateGraphicsCmds(HgiGraphicsCmdsDesc const &desc)=0
Returns a GraphicsCmds object (for temporary use) that is ready to record draw commands.
virtual HGI_API HgiShaderProgramHandle CreateShaderProgram(HgiShaderProgramDesc const &desc)=0
Create a new shader program.
virtual HGI_API HgiCapabilities const * GetCapabilities() const =0
Returns the device-specific capabilities structure.
virtual HGI_API HgiBufferHandle CreateBuffer(HgiBufferDesc const &desc)=0
Create a buffer in rendering backend.
virtual HGI_API HgiTextureViewHandle CreateTextureView(HgiTextureViewDesc const &desc)=0
Create a texture view in rendering backend.
virtual HGI_API HgiComputePipelineHandle CreateComputePipeline(HgiComputePipelineDesc const &pipeDesc)=0
Create a new compute pipeline state object.
virtual HGI_API HgiComputeCmdsUniquePtr CreateComputeCmds(HgiComputeCmdsDesc const &desc)=0
Returns a ComputeCmds object (for temporary use) that is ready to record dispatch commands.
virtual HGI_API HgiIndirectCommandEncoder * GetIndirectCommandEncoder() const =0
Returns the device-specific indirect command buffer encoder or nullptr if not supported.
virtual HGI_API HgiBlitCmdsUniquePtr CreateBlitCmds()=0
Returns a BlitCmds object (for temporary use) that is ready to execute resource copy commands.
virtual HGI_API HgiGraphicsPipelineHandle CreateGraphicsPipeline(HgiGraphicsPipelineDesc const &pipeDesc)=0
Create a new graphics pipeline state object.
HGI_API void SubmitCmds(HgiCmds *cmds, HgiSubmitWaitType wait=HgiSubmitWaitTypeNoWait)
Submit one HgiCmds objects.
static HGI_API HgiUniquePtr CreateNamedHgi(const TfToken &hgiToken)
Helper function to return a Hgi object of choice supported by current platform and build configuratio...
virtual HGI_API void DestroyShaderFunction(HgiShaderFunctionHandle *shaderFunctionHandle)=0
Destroy a shader function.
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
Base class of all factory types.
Definition: type.h:56
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:48
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:228
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...