diff options
| author | Anders Leino <aleino@nvidia.com> | 2024-11-25 16:05:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-25 14:05:13 +0000 |
| commit | d282701ba76e9883d2b7be39ee614fe3bb4f5165 (patch) | |
| tree | 160178e8ce5783469a6e61c3fd39ccf46c1e7156 /source/slang/slang-emit-wgsl.cpp | |
| parent | 044b52c3195edf3282a0b530a21ad54b87135cd9 (diff) | |
Support interpolation modifiers for WGSL (#5641)
* wgsl: Support interpolation modifiers
* Move struct key decorations to flattened structs.
** This includes interpolation mode decorations, which must be in the flattened struct.
* Emit interpolation attribute.
* Enable tests/render/nointerpolation.hlsl for WGSL, as a result.
This closes #5625.
* Add new expected output for 'nointerpolation' test
Diffstat (limited to 'source/slang/slang-emit-wgsl.cpp')
| -rw-r--r-- | source/slang/slang-emit-wgsl.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp index fcc4b615f..d49986263 100644 --- a/source/slang/slang-emit-wgsl.cpp +++ b/source/slang/slang-emit-wgsl.cpp @@ -1506,4 +1506,53 @@ void WGSLSourceEmitter::emitIntrinsicCallExprImpl( inOuterPrec); } +void WGSLSourceEmitter::emitInterpolationModifiersImpl( + IRInst* varInst, + IRType* /* valueType */, + IRVarLayout* /* layout */) +{ + char const* interpolationType = nullptr; + char const* interpolationSampling = nullptr; + for (auto dd : varInst->getDecorations()) + { + if (dd->getOp() != kIROp_InterpolationModeDecoration) + continue; + auto decoration = (IRInterpolationModeDecoration*)dd; + IRInterpolationMode mode = decoration->getMode(); + switch (mode) + { + case IRInterpolationMode::NoInterpolation: + interpolationType = "flat"; + break; + case IRInterpolationMode::NoPerspective: + case IRInterpolationMode::Linear: + interpolationType = "linear"; + break; + case IRInterpolationMode::Sample: + interpolationSampling = "sample"; + break; + case IRInterpolationMode::Centroid: + interpolationSampling = "centroid"; + break; + } + } + + if (interpolationType) + { + m_writer->emit("@interpolate("); + m_writer->emit(interpolationType); + if (interpolationSampling) + { + m_writer->emit(", "); + m_writer->emit(interpolationSampling); + } + m_writer->emit(") "); + } + + // TODO: Check the following: + // "User-defined vertex outputs and fragment inputs of scalar or vector + // integer type must always be specified with interpolation type flat." + // https://www.w3.org/TR/WGSL/#interpolation +} + } // namespace Slang |
