All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hgi.h
1 //
2 // Copyright 2019 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_HGI_HGI_H
25 #define PXR_IMAGING_HGI_HGI_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/tf/token.h"
29 #include "pxr/base/tf/type.h"
30 
31 #include "pxr/imaging/hgi/api.h"
32 #include "pxr/imaging/hgi/blitCmds.h"
33 #include "pxr/imaging/hgi/buffer.h"
34 #include "pxr/imaging/hgi/computeCmds.h"
35 #include "pxr/imaging/hgi/graphicsCmds.h"
36 #include "pxr/imaging/hgi/graphicsCmdsDesc.h"
37 #include "pxr/imaging/hgi/graphicsPipeline.h"
38 #include "pxr/imaging/hgi/resourceBindings.h"
39 #include "pxr/imaging/hgi/sampler.h"
40 #include "pxr/imaging/hgi/shaderFunction.h"
41 #include "pxr/imaging/hgi/shaderProgram.h"
42 #include "pxr/imaging/hgi/texture.h"
43 #include "pxr/imaging/hgi/types.h"
44 
45 #include <atomic>
46 #include <memory>
47 
48 PXR_NAMESPACE_OPEN_SCOPE
49 
50 using HgiUniquePtr = std::unique_ptr<class Hgi>;
51 
52 
106 class Hgi
107 {
108 public:
109  HGI_API
110  Hgi();
111 
112  HGI_API
113  virtual ~Hgi();
114 
123  HGI_API
124  void SubmitCmds(
125  HgiCmds* cmds,
126  HgiSubmitWaitType wait = HgiSubmitWaitTypeNoWait);
127 
129  HGI_API
130  static Hgi* GetPlatformDefaultHgi();
131 
137  HGI_API
138  static HgiUniquePtr CreatePlatformDefaultHgi();
139 
146  HGI_API
147  virtual HgiGraphicsCmdsUniquePtr CreateGraphicsCmds(
148  HgiGraphicsCmdsDesc const& desc) = 0;
149 
156  HGI_API
157  virtual HgiBlitCmdsUniquePtr CreateBlitCmds() = 0;
158 
165  HGI_API
166  virtual HgiComputeCmdsUniquePtr CreateComputeCmds() = 0;
167 
170  HGI_API
171  virtual HgiTextureHandle CreateTexture(HgiTextureDesc const & desc) = 0;
172 
175  HGI_API
176  virtual void DestroyTexture(HgiTextureHandle* texHandle) = 0;
177 
183  HGI_API
185  HgiTextureViewDesc const & desc) = 0;
186 
191  HGI_API
192  virtual void DestroyTextureView(HgiTextureViewHandle* viewHandle) = 0;
193 
196  HGI_API
197  virtual HgiSamplerHandle CreateSampler(HgiSamplerDesc const & desc) = 0;
198 
201  HGI_API
202  virtual void DestroySampler(HgiSamplerHandle* smpHandle) = 0;
203 
206  HGI_API
207  virtual HgiBufferHandle CreateBuffer(HgiBufferDesc const & desc) = 0;
208 
211  HGI_API
212  virtual void DestroyBuffer(HgiBufferHandle* bufHandle) = 0;
213 
216  HGI_API
218  HgiShaderFunctionDesc const& desc) = 0;
219 
222  HGI_API
223  virtual void DestroyShaderFunction(
224  HgiShaderFunctionHandle* shaderFunctionHandle) = 0;
225 
228  HGI_API
230  HgiShaderProgramDesc const& desc) = 0;
231 
236  HGI_API
237  virtual void DestroyShaderProgram(
238  HgiShaderProgramHandle* shaderProgramHandle) = 0;
239 
242  HGI_API
244  HgiResourceBindingsDesc const& desc) = 0;
245 
248  HGI_API
249  virtual void DestroyResourceBindings(
250  HgiResourceBindingsHandle* resHandle) = 0;
251 
254  HGI_API
256  HgiGraphicsPipelineDesc const& pipeDesc) = 0;
257 
260  HGI_API
261  virtual void DestroyGraphicsPipeline(
262  HgiGraphicsPipelineHandle* pipeHandle) = 0;
263 
266  HGI_API
268  HgiComputePipelineDesc const& pipeDesc) = 0;
269 
272  HGI_API
273  virtual void DestroyComputePipeline(HgiComputePipelineHandle* pipeHandle)=0;
274 
277  HGI_API
278  virtual TfToken const& GetAPIName() const = 0;
279 
286  HGI_API
287  virtual void StartFrame() = 0;
288 
292  HGI_API
293  virtual void EndFrame() = 0;
294 
295 protected:
296  // Returns a unique id for handle creation.
297  // Thread safety: Thread-safe atomic increment.
298  HGI_API
299  uint64_t GetUniqueId();
300 
301  // Calls Submit on provided Cmds.
302  // Derived classes can override this function if they need customize the
303  // command submission. The default implementation calls cmds->_Submit().
304  HGI_API
305  virtual bool _SubmitCmds(
306  HgiCmds* cmds, HgiSubmitWaitType wait);
307 
308 private:
309  Hgi & operator=(const Hgi&) = delete;
310  Hgi(const Hgi&) = delete;
311 
312  std::atomic<uint64_t> _uniqueIdCounter;
313 };
314 
315 
320 public:
321  virtual Hgi* New() const = 0;
322 };
323 
324 template <class T>
325 class HgiFactory : public HgiFactoryBase {
326 public:
327  Hgi* New() const {
328  return new T;
329  }
330 };
331 
332 
333 PXR_NAMESPACE_CLOSE_SCOPE
334 
335 #endif
virtual HGI_API void DestroyBuffer(HgiBufferHandle *bufHandle)=0
Destroy a buffer in rendering backend.
virtual HGI_API void EndFrame()=0
Optionally called at the end of a rendering frame.
virtual HGI_API HgiComputePipelineHandle CreateComputePipeline(HgiComputePipelineDesc const &pipeDesc)=0
Create a new compute pipeline state object.
virtual HGI_API void DestroyShaderFunction(HgiShaderFunctionHandle *shaderFunctionHandle)=0
Destroy a shader function.
virtual HGI_API HgiShaderFunctionHandle CreateShaderFunction(HgiShaderFunctionDesc const &desc)=0
Create a new shader function.
virtual HGI_API void DestroyComputePipeline(HgiComputePipelineHandle *pipeHandle)=0
Destroy a compute pipeline state object.
Describes the properties needed to create a GPU texture view from an existing GPU texture object...
Definition: texture.h:238
virtual HGI_API HgiTextureViewHandle CreateTextureView(HgiTextureViewDesc const &desc)=0
Create a texture view 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.
HGI_API void SubmitCmds(HgiCmds *cmds, HgiSubmitWaitType wait=HgiSubmitWaitTypeNoWait)
Submit one HgiCmds objects.
Describes the properties needed to create a GPU sampler.
Definition: sampler.h:58
Describes the properties needed to create a GPU texture.
Definition: texture.h:107
Base class of all factory types.
Definition: type.h:73
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
virtual HGI_API void DestroyResourceBindings(HgiResourceBindingsHandle *resHandle)=0
Destroy a resource binding object.
virtual HGI_API HgiGraphicsPipelineHandle CreateGraphicsPipeline(HgiGraphicsPipelineDesc const &pipeDesc)=0
Create a new graphics pipeline state object.
Describes the properties needed to create a GPU compute pipeline.
virtual HGI_API HgiTextureHandle CreateTexture(HgiTextureDesc const &desc)=0
Create a texture in rendering backend.
Describes the properties needed to create a GPU buffer.
Definition: buffer.h:62
Describes the properties to begin a HgiGraphicsCmds.
virtual HGI_API HgiComputeCmdsUniquePtr CreateComputeCmds()=0
Returns a ComputeCmds object (for temporary use) that is ready to record dispatch commands...
Hgi factory for plugin system.
Definition: hgi.h:319
virtual HGI_API void DestroyTextureView(HgiTextureViewHandle *viewHandle)=0
Destroy a texture view in rendering backend.
Describes the properties needed to create a GPU shader program.
Definition: shaderProgram.h:51
Describes a set of resources that are bound to the GPU during encoding.
Hydra Graphics Interface.
Definition: hgi.h:106
virtual HGI_API void DestroyTexture(HgiTextureHandle *texHandle)=0
Destroy a texture in rendering backend.
static HGI_API HgiUniquePtr CreatePlatformDefaultHgi()
Helper function to return a Hgi object for the current platform.
virtual HGI_API HgiShaderProgramHandle CreateShaderProgram(HgiShaderProgramDesc const &desc)=0
Create a new shader program.
static HGI_API Hgi * GetPlatformDefaultHgi()
*** DEPRECATED *** Please use: CreatePlatformDefaultHgi
Describes the properties needed to create a GPU shader function.
virtual HGI_API HgiSamplerHandle CreateSampler(HgiSamplerDesc const &desc)=0
Create a sampler in rendering backend.
virtual HGI_API void DestroySampler(HgiSamplerHandle *smpHandle)=0
Destroy a sampler in rendering backend.
virtual HGI_API void StartFrame()=0
Optionally called by client app at the start of a new rendering frame.
Describes the properties needed to create a GPU pipeline.
virtual HGI_API HgiBufferHandle CreateBuffer(HgiBufferDesc const &desc)=0
Create a buffer in rendering backend.
Graphics commands are recorded in &#39;cmds&#39; objects which are later submitted to hgi.
Definition: cmds.h:44
virtual HGI_API void DestroyShaderProgram(HgiShaderProgramHandle *shaderProgramHandle)=0
Destroy a shader program.
Handle that contains a hgi object and unique id.
Definition: handle.h:49
virtual HGI_API HgiBlitCmdsUniquePtr CreateBlitCmds()=0
Returns a BlitCmds object (for temporary use) that is ready to execute resource copy commands...
virtual HGI_API HgiResourceBindingsHandle CreateResourceBindings(HgiResourceBindingsDesc const &desc)=0
Create a new resource binding object.
virtual HGI_API TfToken const & GetAPIName() const =0
Return the name of the api (e.g.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
virtual HGI_API void DestroyGraphicsPipeline(HgiGraphicsPipelineHandle *pipeHandle)=0
Destroy a graphics pipeline state object.