|
28 | 28 | #include "DebugUtilities.hpp" |
29 | 29 | #include "ParsingTools.hpp" |
30 | 30 | #include "ShaderToolsCommon.hpp" |
| 31 | +#include "src/tint/lang/core/ir/transform/multiplanar_options.h" |
| 32 | +#include "src/tint/lang/wgsl/inspector/inspector.h" |
| 33 | +#include "src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.h" |
31 | 34 |
|
32 | 35 | #ifdef _MSC_VER |
33 | 36 | # pragma warning(push) |
|
44 | 47 | #include "src/tint/lang/core/type/atomic.h" |
45 | 48 | #include "src/tint/lang/core/type/array.h" |
46 | 49 | #include "src/tint/lang/core/type/struct.h" |
47 | | - |
| 50 | +#include "src/tint/lang/core/ir/transform/binding_remapper.h" |
| 51 | +#include "src/tint/lang/wgsl/writer/ir_to_program/ir_to_program.h" |
48 | 52 |
|
49 | 53 | #ifdef _MSC_VER |
50 | 54 | # pragma warning(pop) |
@@ -92,22 +96,24 @@ WGSLEmulatedResourceArrayElement GetWGSLEmulatedArrayElement(const std::string& |
92 | 96 | std::string ConvertSPIRVtoWGSL(const std::vector<uint32_t>& SPIRV) |
93 | 97 | { |
94 | 98 | tint::spirv::reader::Options SPIRVReaderOptions{true, {tint::wgsl::AllowedFeatures::Everything()}}; |
95 | | - tint::Program Program = Read(SPIRV, SPIRVReaderOptions); |
96 | 99 |
|
97 | | - if (!Program.IsValid()) |
| 100 | + auto Module = tint::spirv::reader::ReadIR(SPIRV, SPIRVReaderOptions); |
| 101 | + if (Module != tint::Success) |
98 | 102 | { |
99 | | - LOG_ERROR_MESSAGE("Tint SPIR-V reader failure:\nParser: " + Program.Diagnostics().Str() + "\n"); |
| 103 | + LOG_ERROR_MESSAGE("Tint SPIR-V reader failure:\nParser: " + Module .Failure().reason + "\n"); |
100 | 104 | return {}; |
101 | 105 | } |
| 106 | + tint::wgsl::writer::Options WGSLWriterOptions{}; |
| 107 | + WGSLWriterOptions.allow_non_uniform_derivatives = true; |
| 108 | + WGSLWriterOptions.allowed_features = tint::wgsl::AllowedFeatures::Everything(); |
102 | 109 |
|
103 | | - auto GenerationResult = tint::wgsl::writer::Generate(Program, {}); |
| 110 | + auto GenerationResult = tint::wgsl::writer::WgslFromIR(Module.Get(), WGSLWriterOptions); |
104 | 111 | if (GenerationResult != tint::Success) |
105 | 112 | { |
106 | | - LOG_ERROR_MESSAGE("Tint WGSL writer failure:\nGeneate: " + GenerationResult.Failure().reason.Str() + "\n"); |
| 113 | + LOG_ERROR_MESSAGE("Tint WGSL writer failure:\nGeneate: " + GenerationResult.Failure().reason + "\n"); |
107 | 114 | return {}; |
108 | 115 | } |
109 | | - |
110 | | - return GenerationResult->wgsl; |
| 116 | + return GenerationResult.Get().wgsl; |
111 | 117 | } |
112 | 118 |
|
113 | 119 | static bool IsAtomic(const tint::core::type::Type* WGSLType) |
@@ -271,17 +277,16 @@ std::string RemapWGSLResourceBindings(const std::string& WGSL, |
271 | 277 | const WGSLResourceMapping& ResMapping, |
272 | 278 | const char* EmulatedArrayIndexSuffix) |
273 | 279 | { |
274 | | - tint::Source::File srcFile("", WGSL); |
275 | | - tint::Program Program = tint::wgsl::reader::Parse(&srcFile, {tint::wgsl::AllowedFeatures::Everything()}); |
| 280 | + tint::Source::File SrcFile("", WGSL); |
| 281 | + tint::Program Program = tint::wgsl::reader::Parse(&SrcFile, {tint::wgsl::AllowedFeatures::Everything()}); |
276 | 282 |
|
277 | 283 | if (!Program.IsValid()) |
278 | 284 | { |
279 | 285 | LOG_ERROR_MESSAGE("Tint WGSL reader failure:\nParser: ", Program.Diagnostics().Str(), "\n"); |
280 | 286 | return {}; |
281 | 287 | } |
282 | 288 |
|
283 | | - tint::ast::transform::BindingRemapper::BindingPoints BindingPoints; |
284 | | - |
| 289 | + std::unordered_map<tint::BindingPoint, tint::BindingPoint> BindingPoints; |
285 | 290 | tint::inspector::Inspector Inspector{Program}; |
286 | 291 | for (tint::inspector::EntryPoint& EntryPoint : Inspector.GetEntryPoints()) |
287 | 292 | { |
@@ -311,28 +316,34 @@ std::string RemapWGSLResourceBindings(const std::string& WGSL, |
311 | 316 | if (DstBindigIt != ResMapping.end()) |
312 | 317 | { |
313 | 318 | const WGSLResourceBindingInfo& DstBindig = DstBindigIt->second; |
314 | | - BindingPoints.emplace(tint::ast::transform::BindingPoint{Binding.bind_group, Binding.binding}, tint::ast::transform::BindingPoint{DstBindig.Group, DstBindig.Index + ArrayIndex}); |
| 319 | + BindingPoints.emplace(tint::BindingPoint{Binding.bind_group, Binding.binding}, tint::BindingPoint{DstBindig.Group, DstBindig.Index + ArrayIndex}); |
315 | 320 | } |
316 | 321 | else |
317 | 322 | { |
318 | 323 | LOG_ERROR_MESSAGE("Binding for variable '", Binding.variable_name, "' is not found in the remap indices"); |
319 | 324 | } |
320 | 325 | } |
321 | 326 | } |
| 327 | + |
| 328 | + auto Module = tint::wgsl::reader::ProgramToIR(Program); |
| 329 | + if (Module != tint::Success) |
| 330 | + { |
| 331 | + LOG_ERROR_MESSAGE("Tint WGSL to IR failure:\nParser: ", Module.Failure().reason, "\n"); |
| 332 | + return {}; |
| 333 | + } |
| 334 | + |
| 335 | + if (auto Result = tint::core::ir::transform::BindingRemapper(Module.Get(), BindingPoints); Result != tint::Success) |
| 336 | + { |
| 337 | + LOG_ERROR_MESSAGE("Tint BindingRemapper failure:\nParser: ", Result.Failure().reason, "\n"); |
| 338 | + return {}; |
| 339 | + } |
322 | 340 |
|
323 | | - tint::ast::transform::Manager Manager; |
324 | | - tint::ast::transform::DataMap Inputs; |
325 | | - tint::ast::transform::DataMap Outputs; |
326 | | - |
327 | | - Inputs.Add<tint::ast::transform::BindingRemapper::Remappings>(BindingPoints, tint::ast::transform::BindingRemapper::AccessControls{}, false); |
328 | | - Manager.Add<tint::ast::transform::BindingRemapper>(); |
329 | | - tint::ast::transform::Output TransformResult = Manager.Run(Program, Inputs, Outputs); |
330 | | - |
331 | | - auto GenerationResult = tint::wgsl::writer::Generate(TransformResult.program, {}); |
| 341 | + tint::Program RemapedProgram = tint::wgsl::writer::IRToProgram(Module.Get()); |
| 342 | + auto GenerationResult = tint::wgsl::writer::Generate(RemapedProgram, {}); |
332 | 343 |
|
333 | 344 | if (GenerationResult != tint::Success) |
334 | 345 | { |
335 | | - LOG_ERROR_MESSAGE("Tint WGSL writer failure:\nGeneate: ", GenerationResult.Failure().reason.Str(), "\n"); |
| 346 | + LOG_ERROR_MESSAGE("Tint WGSL writer failure:\nGeneate: ", GenerationResult.Failure().reason, "\n"); |
336 | 347 | return {}; |
337 | 348 | } |
338 | 349 |
|
|
0 commit comments