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 | |
| 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
| -rw-r--r-- | source/slang/slang-emit-wgsl.cpp | 49 | ||||
| -rw-r--r-- | source/slang/slang-emit-wgsl.h | 4 | ||||
| -rw-r--r-- | source/slang/slang-ir-wgsl-legalize.cpp | 7 | ||||
| -rw-r--r-- | tests/expected-failure-github.txt | 1 | ||||
| -rw-r--r-- | tests/render/nointerpolation.hlsl | 2 | ||||
| -rw-r--r-- | tests/render/nointerpolation.hlsl.3.expected | 5 | ||||
| -rw-r--r-- | tests/render/nointerpolation.hlsl.3.expected.png | bin | 0 -> 32474 bytes |
7 files changed, 63 insertions, 5 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 diff --git a/source/slang/slang-emit-wgsl.h b/source/slang/slang-emit-wgsl.h index 6ff9e6786..0cbedf4eb 100644 --- a/source/slang/slang-emit-wgsl.h +++ b/source/slang/slang-emit-wgsl.h @@ -42,6 +42,10 @@ public: virtual void emitStructFieldAttributes(IRStructType* structType, IRStructField* field) SLANG_OVERRIDE; virtual void emitCallArg(IRInst* inst) SLANG_OVERRIDE; + virtual void emitInterpolationModifiersImpl( + IRInst* varInst, + IRType* valueType, + IRVarLayout* layout) SLANG_OVERRIDE; virtual void emitIntrinsicCallExprImpl( IRCall* inst, diff --git a/source/slang/slang-ir-wgsl-legalize.cpp b/source/slang/slang-ir-wgsl-legalize.cpp index 4d5f6e4ba..facafb284 100644 --- a/source/slang/slang-ir-wgsl-legalize.cpp +++ b/source/slang/slang-ir-wgsl-legalize.cpp @@ -629,7 +629,10 @@ struct LegalizeWGSLEntryPointContext // 2. If IRStructType: // 2a. Recurse this function with 'decorations that carry semantic info' from parent. // 3. If not IRStructType: - // 3a. Emit 'newField' equal to 'oldField', add 'decorations which carry semantic info'. + // 3a. Emit 'newField' with 'newKey' equal to 'oldField' and 'oldKey', respectively, + // where 'oldKey' is the key corresponding to 'oldField'. + // Add 'decorations which carry semantic info' to 'newField', and move all decorations + // of 'oldKey' to 'newKey'. // 3b. Store a mapping from 'oldField' to 'newField' in 'mapFieldToField'. This info is // needed to copy between types. for (auto oldField : src->getFields()) @@ -674,7 +677,7 @@ struct LegalizeWGSLEntryPointContext // step 3a auto newKey = builder.createStructKey(); - copyNameHintAndDebugDecorations(newKey, oldKey); + oldKey->transferDecorationsTo(newKey); auto newField = builder.createStructField(dst, newKey, oldField->getFieldType()); copyNameHintAndDebugDecorations(newField, oldField); diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt index 671b8dafd..ee96de7f5 100644 --- a/tests/expected-failure-github.txt +++ b/tests/expected-failure-github.txt @@ -20,4 +20,3 @@ tests/language-feature/generics/variadic-0.slang.4 syn (wgpu) tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu) tests/language-feature/swizzles/matrix-swizzle-write-array.slang.3 syn (wgpu) tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang.3 syn (wgpu) -tests/render/nointerpolation.hlsl (wgpu) diff --git a/tests/render/nointerpolation.hlsl b/tests/render/nointerpolation.hlsl index a8d0c85e0..d514379d0 100644 --- a/tests/render/nointerpolation.hlsl +++ b/tests/render/nointerpolation.hlsl @@ -1,6 +1,4 @@ //TEST(smoke):COMPARE_HLSL_RENDER: -// WGSL: nointerpolate doesn't work #5625 -//DISABLE_TEST(smoke):COMPARE_HLSL_RENDER: -wgpu // TODO: Investigate Metal failure //DISABLE_TEST(smoke):COMPARE_HLSL_RENDER: -mtl diff --git a/tests/render/nointerpolation.hlsl.3.expected b/tests/render/nointerpolation.hlsl.3.expected new file mode 100644 index 000000000..4c32e2510 --- /dev/null +++ b/tests/render/nointerpolation.hlsl.3.expected @@ -0,0 +1,5 @@ +result code = 0 +standard error = { +} +standard output = { +} diff --git a/tests/render/nointerpolation.hlsl.3.expected.png b/tests/render/nointerpolation.hlsl.3.expected.png Binary files differnew file mode 100644 index 000000000..793b27c19 --- /dev/null +++ b/tests/render/nointerpolation.hlsl.3.expected.png |
