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 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_SHADERPROGRAM_H
25 #define PXR_IMAGING_HGI_SHADERPROGRAM_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hgi/api.h"
29 #include "pxr/imaging/hgi/enums.h"
30 #include "pxr/imaging/hgi/handle.h"
32 #include "pxr/imaging/hgi/types.h"
33 
34 #include <vector>
35 
36 
38 
39 
40 /// \struct HgiShaderProgramDesc
41 ///
42 /// Describes the properties needed to create a GPU shader program.
43 ///
44 /// <ul>
45 /// <li>debugName:
46 /// This label can be applied as debug label for gpu debugging.</li>
47 /// <li>shaderFunctions:
48 /// Holds handles to shader functions for each shader stage.</li>
49 /// </ul>
50 ///
52 {
53  HGI_API
55 
58 };
59 
60 HGI_API
61 inline bool operator==(
62  const HgiShaderProgramDesc& lhs,
63  const HgiShaderProgramDesc& rhs);
64 
65 HGI_API
66 inline bool operator!=(
67  const HgiShaderProgramDesc& lhs,
68  const HgiShaderProgramDesc& rhs);
69 
70 
71 ///
72 /// \class HgiShaderProgram
73 ///
74 /// Represents a collection of shader functions.
75 /// This object does not take ownership of the shader functions and does not
76 /// destroy them automatically. The client must destroy the shader functions
77 /// when the program is detroyed, because only the client knows if the shader
78 /// functions are used by other shader programs.
79 ///
81 {
82 public:
83  HGI_API
84  virtual ~HgiShaderProgram();
85 
86  /// The descriptor describes the object.
87  HGI_API
88  HgiShaderProgramDesc const& GetDescriptor() const;
89 
90  /// Returns false if any shader compile errors occured.
91  HGI_API
92  virtual bool IsValid() const = 0;
93 
94  /// Returns shader compile errors.
95  HGI_API
96  virtual std::string const& GetCompileErrors() = 0;
97 
98  /// Returns the shader functions that are part of this program.
99  HGI_API
100  virtual HgiShaderFunctionHandleVector const& GetShaderFunctions() const = 0;
101 
102  /// Returns the byte size of the GPU shader program.
103  /// APIs that do not have programs can return the combined byte size of the
104  /// shader functions used by the program.
105  /// This can be helpful if the application wishes to tally up memory usage.
106  HGI_API
107  virtual size_t GetByteSizeOfResource() const = 0;
108 
109  /// This function returns the handle to the Hgi backend's gpu resource, cast
110  /// to a uint64_t. Clients should avoid using this function and instead
111  /// use Hgi base classes so that client code works with any Hgi platform.
112  /// For transitioning code to Hgi, it can however we useful to directly
113  /// access a platform's internal resource handles.
114  /// There is no safety provided in using this. If you by accident pass a
115  /// HgiMetal resource into an OpenGL call, bad things may happen.
116  /// In OpenGL this returns the GLuint resource name.
117  /// In Metal, Vulkan this returns 0.
118  HGI_API
119  virtual uint64_t GetRawResource() const = 0;
120 
121 protected:
122  HGI_API
124 
126 
127 private:
128  HgiShaderProgram() = delete;
129  HgiShaderProgram & operator=(const HgiShaderProgram&) = delete;
130  HgiShaderProgram(const HgiShaderProgram&) = delete;
131 };
132 
134 using HgiShaderProgramHandleVector = std::vector<HgiShaderProgramHandle>;
135 
136 
138 
139 #endif
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:56
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:40
HgiShaderProgramDesc _descriptor
HGI_API HgiShaderProgramDesc()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
HgiShaderFunctionHandleVector shaderFunctions
Definition: shaderProgram.h:57
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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.