summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-emit-wgsl.cpp49
-rw-r--r--source/slang/slang-emit-wgsl.h4
-rw-r--r--source/slang/slang-ir-wgsl-legalize.cpp7
-rw-r--r--tests/expected-failure-github.txt1
-rw-r--r--tests/render/nointerpolation.hlsl2
-rw-r--r--tests/render/nointerpolation.hlsl.3.expected5
-rw-r--r--tests/render/nointerpolation.hlsl.3.expected.pngbin0 -> 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
new file mode 100644
index 000000000..793b27c19
--- /dev/null
+++ b/tests/render/nointerpolation.hlsl.3.expected.png
Binary files differ