HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shaderProgram.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_SHADERPROGRAM_H
8 #define PXR_IMAGING_HGI_SHADERPROGRAM_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hgi/api.h"
12 #include "pxr/imaging/hgi/enums.h"
13 #include "pxr/imaging/hgi/handle.h"
15 #include "pxr/imaging/hgi/types.h"
16 
17 #include <vector>
18 
19 
21 
22 
23 /// \struct HgiShaderProgramDesc
24 ///
25 /// Describes the properties needed to create a GPU shader program.
26 ///
27 /// <ul>
28 /// <li>debugName:
29 /// This label can be applied as debug label for gpu debugging.</li>
30 /// <li>shaderFunctions:
31 /// Holds handles to shader functions for each shader stage.</li>
32 /// </ul>
33 ///
35 {
36  HGI_API
38 
39  std::string debugName;
41 };
42 
43 HGI_API
44 inline bool operator==(
45  const HgiShaderProgramDesc& lhs,
46  const HgiShaderProgramDesc& rhs);
47 
48 HGI_API
49 inline bool operator!=(
50  const HgiShaderProgramDesc& lhs,
51  const HgiShaderProgramDesc& rhs);
52 
53 
54 ///
55 /// \class HgiShaderProgram
56 ///
57 /// Represents a collection of shader functions.
58 /// This object does not take ownership of the shader functions and does not
59 /// destroy them automatically. The client must destroy the shader functions
60 /// when the program is detroyed, because only the client knows if the shader
61 /// functions are used by other shader programs.
62 ///
64 {
65 public:
66  HGI_API
67  virtual ~HgiShaderProgram();
68 
69  /// The descriptor describes the object.
70  HGI_API
71  HgiShaderProgramDesc const& GetDescriptor() const;
72 
73  /// Returns false if any shader compile errors occured.
74  HGI_API
75  virtual bool IsValid() const = 0;
76 
77  /// Returns shader compile errors.
78  HGI_API
79  virtual std::string const& GetCompileErrors() = 0;
80 
81  /// Returns the shader functions that are part of this program.
82  HGI_API
83  virtual HgiShaderFunctionHandleVector const& GetShaderFunctions() const = 0;
84 
85  /// Returns the byte size of the GPU shader program.
86  /// APIs that do not have programs can return the combined byte size of the
87  /// shader functions used by the program.
88  /// This can be helpful if the application wishes to tally up memory usage.
89  HGI_API
90  virtual size_t GetByteSizeOfResource() const = 0;
91 
92  /// This function returns the handle to the Hgi backend's gpu resource, cast
93  /// to a uint64_t. Clients should avoid using this function and instead
94  /// use Hgi base classes so that client code works with any Hgi platform.
95  /// For transitioning code to Hgi, it can however we useful to directly
96  /// access a platform's internal resource handles.
97  /// There is no safety provided in using this. If you by accident pass a
98  /// HgiMetal resource into an OpenGL call, bad things may happen.
99  /// In OpenGL this returns the GLuint resource name.
100  /// In Metal, Vulkan this returns 0.
101  HGI_API
102  virtual uint64_t GetRawResource() const = 0;
103 
104 protected:
105  HGI_API
107 
109 
110 private:
111  HgiShaderProgram() = delete;
112  HgiShaderProgram & operator=(const HgiShaderProgram&) = delete;
113  HgiShaderProgram(const HgiShaderProgram&) = delete;
114 };
115 
117 using HgiShaderProgramHandleVector = std::vector<HgiShaderProgramHandle>;
118 
119 
121 
122 #endif
std::vector< HgiShaderProgramHandle > HgiShaderProgramHandleVector
virtual HGI_API HgiShaderFunctionHandleVector const & GetShaderFunctions() const =0
Returns the shader functions that are part of this program.
virtual HGI_API size_t GetByteSizeOfResource() const =0
std::vector< HgiShaderFunctionHandle > HgiShaderFunctionHandleVector
virtual HGI_API uint64_t GetRawResource() const =0
virtual HGI_API std::string const & GetCompileErrors()=0
Returns shader compile errors.
std::string debugName
Definition: shaderProgram.h:39
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
virtual HGI_API ~HgiShaderProgram()
HGI_API HgiShaderProgramDesc const & GetDescriptor() const
The descriptor describes the object.
#define HGI_API
Definition: api.h:23
HgiShaderProgramDesc _descriptor
HGI_API HgiShaderProgramDesc()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HgiShaderFunctionHandleVector shaderFunctions
Definition: shaderProgram.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
virtual HGI_API bool IsValid() const =0
Returns false if any shader compile errors occured.