| 328 | #endif |
| 329 | |
| 330 | static std::optional<shader::ir::Region> |
| 331 | parseFile(shader::ir::Context &context, InputParam &inputParam, |
| 332 | OutputParam &outputParam, const std::filesystem::path &path) { |
| 333 | |
| 334 | if (!inputParam.type) { |
| 335 | auto ext = path.extension(); |
| 336 | if (ext == ".glsl") { |
| 337 | inputParam.type = InputType::Glsl; |
| 338 | } else if (ext == ".spirv" || ext == ".spv") { |
| 339 | inputParam.type = InputType::SpirvBinary; |
| 340 | } else if (ext == ".sb") { |
| 341 | inputParam.type = InputType::Sb; |
| 342 | } else { |
| 343 | return {}; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | if (inputParam.type == InputType::Glsl) { |
| 348 | if (!inputParam.glslStage) { |
| 349 | auto stageText = |
| 350 | std::filesystem::path(path).replace_extension().extension(); |
| 351 | if (stageText == ".vert") { |
| 352 | inputParam.glslStage = shader::glsl::Stage::Vertex; |
| 353 | } else if (stageText == ".comp") { |
| 354 | inputParam.glslStage = shader::glsl::Stage::Compute; |
| 355 | } else if (stageText == ".frag") { |
| 356 | inputParam.glslStage = shader::glsl::Stage::Fragment; |
| 357 | } else if (stageText == ".geom") { |
| 358 | inputParam.glslStage = shader::glsl::Stage::Geometry; |
| 359 | } else { |
| 360 | inputParam.glslStage = shader::glsl::Stage::Library; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if (auto result = |
| 365 | shader::glsl::parseFile(context, *inputParam.glslStage, path)) { |
| 366 | return result->merge(context); |
| 367 | } |
| 368 | |
| 369 | return {}; |
| 370 | } |
| 371 | |
| 372 | if (inputParam.type == InputType::SpirvBinary) { |
| 373 | auto optFileContent = readFile(path); |
| 374 | if (!optFileContent.has_value()) { |
| 375 | return {}; |
| 376 | } |
| 377 | auto fileContent = std::move(*optFileContent); |
| 378 | auto data = |
| 379 | std::span{reinterpret_cast<const std::uint32_t *>(fileContent.data()), |
| 380 | fileContent.size() / sizeof(std::uint32_t)}; |
| 381 | auto loc = context.getPathLocation(path.string()); |
| 382 | if (auto result = shader::spv::deserialize(context, data, loc)) { |
| 383 | return result->merge(context); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | #ifdef GCN |