VTK  9.7.20261119
vtkSlangShaderManager.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
18#ifndef vtkSlangShaderManager_h
19#define vtkSlangShaderManager_h
20
21#include "vtkObject.h"
22#include "vtkRenderingSlangModule.h" // For export macro
23
24#include "vtkWrappingHints.h" // For VTK_WRAPEXCLUDE
25
26#include <cstdint> // For std::uint8_t
27#include <functional> // For std::function
28#include <memory> // For std::unique_ptr
29#include <string> // For std::string
30#include <utility> // For std::pair
31#include <vector> // For std::vector
32
33VTK_ABI_NAMESPACE_BEGIN
34class VTKRENDERINGSLANG_EXPORT vtkSlangShaderManager : public vtkObject
35{
36public:
39 void PrintSelf(ostream& os, vtkIndent indent) override;
40
41 static bool IsSlangAvailable();
42
44 const std::string& source, const std::vector<std::string>& entryPoints = {});
45
46 using StringPairs = std::vector<std::pair<std::string, std::string>>;
47
48 VTK_WRAPEXCLUDE std::string CompileSourceToWGSL(const std::string& source,
49 const std::vector<std::string>& entryPoints, const StringPairs& defines,
50 const std::vector<std::string>& modules, const StringPairs& specializations,
51 const std::vector<std::string>& searchPaths = {}, const std::string& label = std::string());
52
53 void SetCacheDirectory(const std::string& directory);
54
55 static std::vector<std::string> GetLibraryModules();
56 static std::string GetLibraryModuleSource(const std::string& name);
57 static bool WriteLibraryModules(const std::string& directory);
58
60 {
61 std::string Name;
62 size_t Offset = 0;
63 size_t SizeBytes = 0;
64 std::string Type;
65 int ScalarType = 0;
66 unsigned int Width = 0;
67 unsigned int Runs = 0;
68 size_t Stride = 0;
69 std::vector<std::pair<std::string, std::vector<std::string>>> Attributes;
70 };
71
100
101 VTK_WRAPEXCLUDE const std::vector<Binding>& GetLastBindings() const;
102
103 struct Plan
104 {
105 struct Block
106 {
107 std::string Name;
108 unsigned int Group = 0;
109 unsigned int Index = 0;
110 size_t SizeBytes = 0;
111 std::vector<UniformField> Fields;
112 };
113 struct Resource
114 {
115 std::string Name;
116 std::string Field;
117 unsigned int Group = 0;
118 unsigned int Index = 0;
121 int Texture = -1;
122 };
123 std::vector<Block> Blocks;
124 std::vector<Resource> Resources;
125 std::vector<Binding> Unsupported;
126 VTKRENDERINGSLANG_EXPORT bool operator==(const Plan& other) const;
127 bool operator!=(const Plan& other) const { return !(*this == other); }
128
129 struct Data;
130 std::shared_ptr<const Data> Native;
131 };
132
134 {
136 unsigned int Width = 1;
137 unsigned int Runs = 1;
138 const void* Values = nullptr;
139 };
140
149
150 VTK_WRAPEXCLUDE Plan GetLastPlan(const std::function<bool(const Binding&)>& hostOwned) const;
151
152 VTK_WRAPEXCLUDE static std::vector<std::uint8_t> BlockBytes(const Plan& plan, size_t block);
153
154 VTK_WRAPEXCLUDE static PackStatus Pack(const Plan& plan, size_t block, const std::string& field,
155 const HostValue& value, std::vector<std::uint8_t>& bytes);
156
157 VTK_WRAPEXCLUDE static std::vector<std::string> Unmatched(
158 const Plan& plan, const std::vector<std::string>& names);
159
160 VTK_WRAPEXCLUDE static std::string GetParameterSchema(const Plan& plan);
161
162 const std::string& GetLastDiagnostics() const;
163
164protected:
167
168private:
170 void operator=(const vtkSlangShaderManager&) = delete;
171
172 struct Internal;
173 std::unique_ptr<Internal> Pimpl;
174};
175
176VTK_ABI_NAMESPACE_END
177#endif
a simple class to control print indentation
Definition vtkIndent.h:108
static std::vector< std::string > GetLibraryModules()
static vtkSlangShaderManager * New()
static std::string GetLibraryModuleSource(const std::string &name)
static bool IsSlangAvailable()
~vtkSlangShaderManager() override
const std::string & GetLastDiagnostics() const
VTK_WRAPEXCLUDE std::string CompileSourceToWGSL(const std::string &source, const std::vector< std::string > &entryPoints, const StringPairs &defines, const std::vector< std::string > &modules, const StringPairs &specializations, const std::vector< std::string > &searchPaths={}, const std::string &label=std::string())
VTK_WRAPEXCLUDE const std::vector< Binding > & GetLastBindings() const
static bool WriteLibraryModules(const std::string &directory)
static VTK_WRAPEXCLUDE std::vector< std::uint8_t > BlockBytes(const Plan &plan, size_t block)
std::vector< std::pair< std::string, std::string > > StringPairs
static VTK_WRAPEXCLUDE PackStatus Pack(const Plan &plan, size_t block, const std::string &field, const HostValue &value, std::vector< std::uint8_t > &bytes)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static VTK_WRAPEXCLUDE std::vector< std::string > Unmatched(const Plan &plan, const std::vector< std::string > &names)
static VTK_WRAPEXCLUDE std::string GetParameterSchema(const Plan &plan)
VTK_WRAPEXCLUDE Plan GetLastPlan(const std::function< bool(const Binding &)> &hostOwned) const
std::string CompileSourceToWGSL(const std::string &source, const std::vector< std::string > &entryPoints={})
void SetCacheDirectory(const std::string &directory)
std::vector< UniformField > Fields
bool operator!=(const Plan &other) const
std::vector< Resource > Resources
std::shared_ptr< const Data > Native
VTKRENDERINGSLANG_EXPORT bool operator==(const Plan &other) const
std::vector< Binding > Unsupported
std::vector< std::pair< std::string, std::vector< std::string > > > Attributes
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_FLOAT
Definition vtkType.h:43
#define VTK_WRAPEXCLUDE