summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-11 03:22:59 +0000
committerGitHub <noreply@github.com>2025-07-11 03:22:59 +0000
commitd0f342c9263a0e47947ac3be9fa4d9f665831e63 (patch)
treead413058f5b635e60a57aba59870e344c5d847d4 /source
parent6f11c50ba101948b110aa7310fc4fb5732b2b708 (diff)
Fix int16_t/uint16_t support for WGSL target (#7692)
* Initial plan * Implement int16_t/uint16_t support for WGSL target Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Change int16_t/uint16_t to emit proper diagnostics instead of auto-promoting Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Implement diagnoseOnce to prevent duplicate diagnostics Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Optimize diagnoseOnce to use HashSet::add() return value Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Apply code formatting to slang-emit-c-like.h Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix diagnoseOnce to use all parameters instead of first parameter only Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-diagnostic-defs.h6
-rw-r--r--source/slang/slang-emit-c-like.h31
-rw-r--r--source/slang/slang-emit-wgsl.cpp10
3 files changed, 45 insertions, 2 deletions
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index b3d90f27c..dd7885281 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -2866,6 +2866,12 @@ DIAGNOSTIC(
divisionByMatrixNotSupported,
"division by matrix is not supported for Metal and WGSL targets.")
+DIAGNOSTIC(
+ 56103,
+ Error,
+ int16NotSupportedInWGSL,
+ "16-bit integer type '$0' is not supported by the WGSL backend.")
+
DIAGNOSTIC(57001, Warning, spirvOptFailed, "spirv-opt failed. $0")
DIAGNOSTIC(57002, Error, unknownPatchConstantParameter, "unknown patch constant parameter '$0'.")
DIAGNOSTIC(57003, Error, unknownTessPartitioning, "unknown tessellation partitioning '$0'.")
diff --git a/source/slang/slang-emit-c-like.h b/source/slang/slang-emit-c-like.h
index 1e9deaa0d..caf1a913b 100644
--- a/source/slang/slang-emit-c-like.h
+++ b/source/slang/slang-emit-c-like.h
@@ -228,6 +228,30 @@ public:
/// Get the diagnostic sink
DiagnosticSink* getSink() { return m_codeGenContext->getSink(); }
+ /// Diagnose a diagnostic only once per diagnostic ID and all parameters
+ template<typename... Args>
+ void diagnoseOnce(SourceLoc loc, DiagnosticInfo const& diagnostic, Args&&... args)
+ {
+ // For diagnostics with parameters, we'll use all parameters to create a unique key
+ // This prevents duplicate diagnostics while allowing different parameter combinations
+ if constexpr (sizeof...(args) > 0)
+ {
+ String key = String(diagnostic.id);
+ ((key = key + "|" + String(args)), ...); // Fold expression to append all args
+ if (!m_reportedDiagnosticKeys.add(key))
+ return;
+ }
+ else
+ {
+ // For diagnostics without parameters, just use the ID
+ if (!m_reportedDiagnosticIds.add(diagnostic.id))
+ return;
+ }
+
+ // Report the diagnostic
+ getSink()->diagnose(loc, diagnostic, std::forward<Args>(args)...);
+ }
+
/// Get the code gen target
CodeGenTarget getTarget() { return m_target; }
/// Get the source style
@@ -747,6 +771,13 @@ protected:
// Indicates if we are emiting for Optix cooperative vector.
bool isOptixCoopVec = false;
+
+ // Set of diagnostic IDs that have already been reported to prevent duplicates
+ HashSet<int> m_reportedDiagnosticIds;
+
+ // Set of diagnostic keys (ID + all parameters) that have already been reported to prevent
+ // duplicates
+ HashSet<String> m_reportedDiagnosticKeys;
};
} // namespace Slang
diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp
index 97b57d352..fbcb54d10 100644
--- a/source/slang/slang-emit-wgsl.cpp
+++ b/source/slang/slang-emit-wgsl.cpp
@@ -515,8 +515,10 @@ void WGSLSourceEmitter::emitSimpleTypeImpl(IRType* type)
return;
}
case kIROp_Int16Type:
+ diagnoseOnce(SourceLoc(), Diagnostics::int16NotSupportedInWGSL, "int16_t");
+ return;
case kIROp_UInt16Type:
- SLANG_UNEXPECTED("16 bit integer value emitted");
+ diagnoseOnce(SourceLoc(), Diagnostics::int16NotSupportedInWGSL, "uint16_t");
return;
case kIROp_Int64Type:
case kIROp_IntPtrType:
@@ -976,9 +978,13 @@ void WGSLSourceEmitter::emitSimpleValueImpl(IRInst* inst)
break;
}
case BaseType::Int16:
+ {
+ diagnoseOnce(SourceLoc(), Diagnostics::int16NotSupportedInWGSL, "int16_t");
+ break;
+ }
case BaseType::UInt16:
{
- SLANG_UNEXPECTED("16 bit integer value emitted");
+ diagnoseOnce(SourceLoc(), Diagnostics::int16NotSupportedInWGSL, "uint16_t");
break;
}
case BaseType::Int: