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"
32 #include "pxr/imaging/hgi/types.h"
33 
35 
36 ///
37 /// \class HgiShaderFunction
38 ///
39 /// Represents one shader stage function (code snippet).
40 ///
41 /// ShaderFunctions are usually passed to a ShaderProgram, however be careful
42 /// not to destroy the ShaderFunction after giving it to the program.
43 /// While this may be safe for OpenGL after the program is created, it does not
44 /// apply to other graphics backends, such as Vulkan, where the shader functions
45 /// are used during rendering.
46 ///
48 {
49 public:
50  HGI_API
51  virtual ~HgiShaderFunction();
52 
53  /// The descriptor describes the object.
54  HGI_API
55  HgiShaderFunctionDesc const& GetDescriptor() const;
56 
57  /// Returns false if any shader compile errors occured.
58  HGI_API
59  virtual bool IsValid() const = 0;
60 
61  /// Returns shader compile errors.
62  HGI_API
63  virtual std::string const& GetCompileErrors() = 0;
64 
65  /// Returns the byte size of the GPU shader function.
66  /// This can be helpful if the application wishes to tally up memory usage.
67  HGI_API
68  virtual size_t GetByteSizeOfResource() const = 0;
69 
70  /// This function returns the handle to the Hgi backend's gpu resource, cast
71  /// to a uint64_t. Clients should avoid using this function and instead
72  /// use Hgi base classes so that client code works with any Hgi platform.
73  /// For transitioning code to Hgi, it can however we useful to directly
74  /// access a platform's internal resource handles.
75  /// There is no safety provided in using this. If you by accident pass a
76  /// HgiMetal resource into an OpenGL call, bad things may happen.
77  /// In OpenGL this returns the GLuint resource name.
78  /// In Metal this returns the id<MTLFunction> as uint64_t.
79  /// In Vulkan this returns the VkShaderModule as uint64_t.
80  /// In DX12 this returns the ID3D12Resource pointer as uint64_t.
81  HGI_API
82  virtual uint64_t GetRawResource() const = 0;
83 
84 protected:
85  HGI_API
87 
89 
90 private:
91  HgiShaderFunction() = delete;
92  HgiShaderFunction & operator=(const HgiShaderFunction&) = delete;
93  HgiShaderFunction(const HgiShaderFunction&) = delete;
94 };
95 
97 using HgiShaderFunctionHandleVector = std::vector<HgiShaderFunctionHandle>;
98 
100 
101 #endif
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
virtual HGI_API size_t GetByteSizeOfResource() const =0
virtual HGI_API std::string const & GetCompileErrors()=0
Returns shader compile errors.
virtual HGI_API ~HgiShaderFunction()
std::vector< HgiShaderFunctionHandle > HgiShaderFunctionHandleVector
HGI_API HgiShaderFunctionDesc const & GetDescriptor() const
The descriptor describes the object.
virtual HGI_API bool IsValid() const =0
Returns false if any shader compile errors occured.
HgiShaderFunctionDesc _descriptor
#define HGI_API
Definition: api.h:40
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual HGI_API uint64_t GetRawResource() const =0