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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HGI_SHADERFUNCTION_H
8 #define PXR_IMAGING_HGI_SHADERFUNCTION_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 
18 
19 ///
20 /// \class HgiShaderFunction
21 ///
22 /// Represents one shader stage function (code snippet).
23 ///
24 /// ShaderFunctions are usually passed to a ShaderProgram, however be careful
25 /// not to destroy the ShaderFunction after giving it to the program.
26 /// While this may be safe for OpenGL after the program is created, it does not
27 /// apply to other graphics backends, such as Vulkan, where the shader functions
28 /// are used during rendering.
29 ///
31 {
32 public:
33  HGI_API
34  virtual ~HgiShaderFunction();
35 
36  /// The descriptor describes the object.
37  HGI_API
38  HgiShaderFunctionDesc const& GetDescriptor() const;
39 
40  /// Returns false if any shader compile errors occured.
41  HGI_API
42  virtual bool IsValid() const = 0;
43 
44  /// Returns shader compile errors.
45  HGI_API
46  virtual std::string const& GetCompileErrors() = 0;
47 
48  /// Returns the byte size of the GPU shader function.
49  /// This can be helpful if the application wishes to tally up memory usage.
50  HGI_API
51  virtual size_t GetByteSizeOfResource() const = 0;
52 
53  /// This function returns the handle to the Hgi backend's gpu resource, cast
54  /// to a uint64_t. Clients should avoid using this function and instead
55  /// use Hgi base classes so that client code works with any Hgi platform.
56  /// For transitioning code to Hgi, it can however we useful to directly
57  /// access a platform's internal resource handles.
58  /// There is no safety provided in using this. If you by accident pass a
59  /// HgiMetal resource into an OpenGL call, bad things may happen.
60  /// In OpenGL this returns the GLuint resource name.
61  /// In Metal this returns the id<MTLFunction> as uint64_t.
62  /// In Vulkan this returns the VkShaderModule as uint64_t.
63  /// In DX12 this returns the ID3D12Resource pointer as uint64_t.
64  HGI_API
65  virtual uint64_t GetRawResource() const = 0;
66 
67 protected:
68  HGI_API
70 
72 
73 private:
74  HgiShaderFunction() = delete;
75  HgiShaderFunction & operator=(const HgiShaderFunction&) = delete;
76  HgiShaderFunction(const HgiShaderFunction&) = delete;
77 };
78 
80 using HgiShaderFunctionHandleVector = std::vector<HgiShaderFunctionHandle>;
81 
83 
84 #endif
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:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual HGI_API uint64_t GetRawResource() const =0