* Description of a program to be created. * This includes the following: * - shader sources organized into shader modules (each module is compiled as a separate translation unit) * - entry points organized into entry point groups * - type conformances (global and per entry point group) * - compiler options (shader model, flags, etc.) */
| 154 | * - compiler options (shader model, flags, etc.) |
| 155 | */ |
| 156 | struct ProgramDesc |
| 157 | { |
| 158 | struct ShaderID |
| 159 | { |
| 160 | int32_t groupIndex = -1; ///< Entry point group index. |
| 161 | bool isValid() const { return groupIndex >= 0; } |
| 162 | }; |
| 163 | |
| 164 | /// Represents a single piece of shader source code. |
| 165 | /// This can either be a file or a string. |
| 166 | struct ShaderSource |
| 167 | { |
| 168 | enum class Type |
| 169 | { |
| 170 | File, |
| 171 | String |
| 172 | }; |
| 173 | |
| 174 | /// Type of the shader source. |
| 175 | Type type{Type::File}; |
| 176 | |
| 177 | /// Shader source file path. |
| 178 | /// For Type::File this is the actual path to the file. |
| 179 | /// For Type::String this is an optional virtual path used for diagnostics purposes. |
| 180 | std::filesystem::path path; |
| 181 | |
| 182 | /// Shader source string if type == Type::String. |
| 183 | std::string string; |
| 184 | |
| 185 | bool operator==(const ShaderSource& rhs) const { return type == rhs.type && path == rhs.path && string == rhs.string; } |
| 186 | }; |
| 187 | |
| 188 | /// Represents a single shader module made up from a list of sources (files/strings). |
| 189 | /// A shader module corresponds to a single translation unit. |
| 190 | struct ShaderModule |
| 191 | { |
| 192 | /// The name of the shader module. |
| 193 | /// This is the name used by other modules to import this module. |
| 194 | /// If left empty, a name based on a hash from the module sources will be generated. |
| 195 | std::string name; |
| 196 | |
| 197 | /// List of shader sources. |
| 198 | std::vector<ShaderSource> sources; |
| 199 | |
| 200 | ShaderModule() = default; |
| 201 | explicit ShaderModule(std::string name_) : name(std::move(name_)) {} |
| 202 | |
| 203 | /// Create a shader module description containing a single file. |
| 204 | static ShaderModule fromFile(std::filesystem::path path) |
| 205 | { |
| 206 | ShaderModule sm; |
| 207 | sm.addFile(std::move(path)); |
| 208 | return sm; |
| 209 | } |
| 210 | |
| 211 | /// Create a shader module description containing a single string. |
| 212 | static ShaderModule fromString(std::string string, std::filesystem::path path = {}, std::string moduleName = {}) |
| 213 | { |
no test coverage detected