HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MslResourceBindingContext.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_MSLRESOURCEBINDING_H
7 #define MATERIALX_MSLRESOURCEBINDING_H
8 
9 /// @file
10 /// MSL resource binding context
11 
12 #include <MaterialXGenMsl/Export.h>
13 
15 
17 
18 /// Shared pointer to a MslResourceBindingContext
19 using MslResourceBindingContextPtr = shared_ptr<class MslResourceBindingContext>;
20 
21 /// @class MslResourceBindingContext
22 /// Class representing a resource binding for Msl shader resources.
24 {
25  public:
26  MslResourceBindingContext(size_t uniformBindingLocation, size_t samplerBindingLocation);
27 
29  size_t uniformBindingLocation = 0, size_t samplerBindingLocation = 0)
30  {
31  return std::make_shared<MslResourceBindingContext>(
32  uniformBindingLocation, samplerBindingLocation);
33  }
34 
35  // Initialize the context before generation starts.
36  void initialize() override;
37 
38  // Emit directives for stage
39  void emitDirectives(GenContext& context, ShaderStage& stage) override;
40 
41  // Emit uniforms with binding information
42  void emitResourceBindings(GenContext& context, const VariableBlock& uniforms, ShaderStage& stage) override;
43 
44  // Emit structured uniforms with binding information and align members where possible
45  void emitStructuredResourceBindings(GenContext& context, const VariableBlock& uniforms,
46  ShaderStage& stage, const std::string& structInstanceName,
47  const std::string& arraySuffix) override;
48 
49  // Emit separate binding locations for sampler and uniform table
50  void enableSeparateBindingLocations(bool separateBindingLocation) { _separateBindingLocation = separateBindingLocation; };
51 
52  protected:
53  // Binding location for uniform blocks
54  size_t _hwUniformBindLocation = 0;
55 
56  // Initial value of uniform binding location
57  size_t _hwInitUniformBindLocation = 0;
58 
59  // Binding location for sampler blocks
60  size_t _hwSamplerBindLocation = 0;
61 
62  // Initial value of sampler binding location
63  size_t _hwInitSamplerBindLocation = 0;
64 
65  // Separate binding locations flag
66  // Indicates whether to use a shared binding counter for samplers and uniforms or separate ones.
67  // By default a shader counter is used.
68  bool _separateBindingLocation = false;
69 };
70 
72 
73 #endif
virtual void initialize()=0
shared_ptr< class MslResourceBindingContext > MslResourceBindingContextPtr
Shared pointer to a MslResourceBindingContext.
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
virtual void emitDirectives(GenContext &context, ShaderStage &stage)=0
void enableSeparateBindingLocations(bool separateBindingLocation)
static MslResourceBindingContextPtr create(size_t uniformBindingLocation=0, size_t samplerBindingLocation=0)
virtual void emitResourceBindings(GenContext &context, const VariableBlock &uniforms, ShaderStage &stage)=0
#define MX_GENMSL_API
Definition: Export.h:18
virtual void emitStructuredResourceBindings(GenContext &context, const VariableBlock &uniforms, ShaderStage &stage, const std::string &structInstanceName, const std::string &arraySuffix=EMPTY_STRING)=0
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26