HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shaderFunction.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_SHADERFUNCTION_H
25 #define PXR_IMAGING_HGI_SHADERFUNCTION_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"
31 #include "pxr/imaging/hgi/types.h"
32 
33 #include <string>
34 #include <vector>
35 
36 
38 
39 
40 /// \struct HgiShaderFunctionDesc
41 ///
42 /// Describes the properties needed to create a GPU shader function.
43 ///
44 /// <ul>
45 /// <li>debugName:
46 /// This label can be applied as debug label for gpu debugging.</li>
47 /// <li>shaderStage:
48 /// The shader stage this function represents.</li>
49 /// <li>shaderCode:
50 /// The ascii shader code used to compile the shader.</li>
51 /// </ul>
52 ///
54 {
55  HGI_API
57 
60  const char* shaderCode;
61 };
62 
63 HGI_API
64 inline bool operator==(
65  const HgiShaderFunctionDesc& lhs,
66  const HgiShaderFunctionDesc& rhs);
67 
68 HGI_API
69 inline bool operator!=(
70  const HgiShaderFunctionDesc& lhs,
71  const HgiShaderFunctionDesc& rhs);
72 
73 
74 ///
75 /// \class HgiShaderFunction
76 ///
77 /// Represents one shader stage function (code snippet).
78 ///
79 /// ShaderFunctions are usually passed to a ShaderProgram, however be careful
80 /// not to destroy the ShaderFunction after giving it to the program.
81 /// While this may be safe for OpenGL after the program is created, it does not
82 /// apply to other graphics backends, such as Vulkan, where the shader functions
83 /// are used during rendering.
84 ///
86 {
87 public:
88  HGI_API
89  virtual ~HgiShaderFunction();
90 
91  /// The descriptor describes the object.
92  HGI_API
93  HgiShaderFunctionDesc const& GetDescriptor() const;
94 
95  /// Returns false if any shader compile errors occured.
96  HGI_API
97  virtual bool IsValid() const = 0;
98 
99  /// Returns shader compile errors.
100  HGI_API
101  virtual std::string const& GetCompileErrors() = 0;
102 
103  /// Returns the byte size of the GPU shader function.
104  /// This can be helpful if the application wishes to tally up memory usage.
105  HGI_API
106  virtual size_t GetByteSizeOfResource() const = 0;
107 
108  /// This function returns the handle to the Hgi backend's gpu resource, cast
109  /// to a uint64_t. Clients should avoid using this function and instead
110  /// use Hgi base classes so that client code works with any Hgi platform.
111  /// For transitioning code to Hgi, it can however we useful to directly
112  /// access a platform's internal resource handles.
113  /// There is no safety provided in using this. If you by accident pass a
114  /// HgiMetal resource into an OpenGL call, bad things may happen.
115  /// In OpenGL this returns the GLuint resource name.
116  /// In Metal this returns the id<MTLFunction> as uint64_t.
117  /// In Vulkan this returns the VkShaderModule as uint64_t.
118  /// In DX12 this returns the ID3D12Resource pointer as uint64_t.
119  HGI_API
120  virtual uint64_t GetRawResource() const = 0;
121 
122 protected:
123  HGI_API
125 
127 
128 private:
129  HgiShaderFunction() = delete;
130  HgiShaderFunction & operator=(const HgiShaderFunction&) = delete;
131  HgiShaderFunction(const HgiShaderFunction&) = delete;
132 };
133 
134 /// Explicitly instantiate and define ShaderFunction handle
137 using HgiShaderFunctionHandleVector = std::vector<HgiShaderFunctionHandle>;
138 
139 
141 
142 #endif
virtual HGI_API size_t GetByteSizeOfResource() const =0
const char * shaderCode
virtual HGI_API std::string const & GetCompileErrors()=0
Returns shader compile errors.
virtual HGI_API ~HgiShaderFunction()
std::vector< HgiShaderFunctionHandle > HgiShaderFunctionHandleVector
HgiShaderStage shaderStage
HGI_API HgiShaderFunctionDesc()
HGI_API HgiShaderFunctionDesc const & GetDescriptor() const
The descriptor describes the object.
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:563
virtual HGI_API bool IsValid() const =0
Returns false if any shader compile errors occured.
HgiShaderFunctionDesc _descriptor
GLsizei const GLchar *const * string
Definition: glew.h:1844
#define HGI_API
Definition: api.h:40
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HgiBits HgiShaderStage
Definition: enums.h:278
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:549
virtual HGI_API uint64_t GetRawResource() const =0