summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-05-05 10:48:14 -0700
committerGitHub <noreply@github.com>2022-05-05 10:48:14 -0700
commit3088d901fee6447b6d80fa67f258626ece4408dc (patch)
tree95b7d6bcc4b549e58d705fcf0056dde71a52ae8e /source
parentaa03cea0da38b2950e6f8694dc8b1405352eda66 (diff)
Various vulkan/glsl fixes. (#2222)
* Various vulkan/glsl fixes. * Fix. * Fix. * Canonicalize type constraints for name mangling. Co-authored-by: Yong He <yhe@nvidia.com> Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/hlsl.meta.slang21
-rw-r--r--source/slang/slang-check-decl.cpp47
-rw-r--r--source/slang/slang-check.h3
-rw-r--r--source/slang/slang-mangle.cpp31
4 files changed, 92 insertions, 10 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 2c969e174..7d107888a 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -1582,7 +1582,7 @@ T distance(vector<T, N> x, vector<T, N> y)
// Vector dot product
-__generic<T : __BuiltinArithmeticType, let N : int>
+__generic<T : __BuiltinFloatingPointType, let N : int>
__target_intrinsic(hlsl)
__target_intrinsic(glsl)
T dot(vector<T, N> x, vector<T, N> y)
@@ -1593,6 +1593,17 @@ T dot(vector<T, N> x, vector<T, N> y)
return result;
}
+__generic<T : __BuiltinIntegerType, let N : int>
+__target_intrinsic(hlsl)
+T dot(vector<T, N> x, vector<T, N> y)
+{
+ T result = T(0);
+ for(int i = 0; i < N; ++i)
+ result += x[i] * y[i];
+ return result;
+}
+
+
// Helper for computing distance terms for lighting (obsolete)
__generic<T : __BuiltinFloatingPointType> vector<T,4> dst(vector<T,4> x, vector<T,4> y);
@@ -2568,13 +2579,19 @@ __intrinsic_op($(kIROp_Mul))
matrix<T, N, M> mul(T x, matrix<T, N, M> y);
// vector-vector (dot product)
-__generic<T : __BuiltinArithmeticType, let N : int>
+__generic<T : __BuiltinFloatingPointType, let N : int>
__target_intrinsic(hlsl)
__target_intrinsic(glsl, "dot")
T mul(vector<T, N> x, vector<T, N> y)
{
return dot(x, y);
}
+__generic<T : __BuiltinIntegerType, let N : int>
+__target_intrinsic(hlsl)
+T mul(vector<T, N> x, vector<T, N> y)
+{
+ return dot(x, y);
+}
// vector-matrix
__generic<T : __BuiltinArithmeticType, let N : int, let M : int>
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 8db157a37..3c654a48b 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -12,6 +12,8 @@
#include "slang-lookup.h"
+#include "slang-syntax.h"
+
namespace Slang
{
/// Visitor to transition declarations to `DeclCheckState::CheckedModifiers`
@@ -5342,4 +5344,49 @@ namespace Slang
}
}
+ static void _getCanonicalConstraintTypes(List<Type*>& outTypeList, Type* type)
+ {
+ if (auto andType = as<AndType>(type))
+ {
+ _getCanonicalConstraintTypes(outTypeList, andType->left);
+ _getCanonicalConstraintTypes(outTypeList, andType->right);
+ }
+ else
+ {
+ outTypeList.add(type);
+ }
+ }
+ OrderedDictionary<GenericTypeParamDecl*, List<Type*>> getCanonicalGenericConstraints(
+ DeclRef<ContainerDecl> genericDecl)
+ {
+ OrderedDictionary<GenericTypeParamDecl*, List<Type*>> genericConstraints;
+ for (auto mm : getMembersOfType<GenericTypeParamDecl>(genericDecl))
+ {
+ genericConstraints[mm.getDecl()] = List<Type*>();
+ }
+ for (auto genericTypeConstraintDecl : getMembersOfType<GenericTypeConstraintDecl>(genericDecl))
+ {
+ assert(
+ genericTypeConstraintDecl.getDecl()->sub.type->astNodeType ==
+ ASTNodeType::DeclRefType);
+ auto typeParamDecl = as<DeclRefType>(genericTypeConstraintDecl.getDecl()->sub.type)->declRef.getDecl();
+ List<Type*>* constraintTypes = genericConstraints.TryGetValue(typeParamDecl);
+ assert(constraintTypes);
+ constraintTypes->add(genericTypeConstraintDecl.getDecl()->getSup().type);
+ }
+
+ OrderedDictionary<GenericTypeParamDecl*, List<Type*>> result;
+ for (auto& constraints : genericConstraints)
+ {
+ List<Type*> typeList;
+ for (auto type : constraints.Value)
+ {
+ _getCanonicalConstraintTypes(typeList, type);
+ }
+ // TODO: we also need to sort the types within the list for each generic type param.
+ result[constraints.Key] = typeList;
+ }
+ return result;
+ }
+
}
diff --git a/source/slang/slang-check.h b/source/slang/slang-check.h
index e84ad0bc5..a7d51f951 100644
--- a/source/slang/slang-check.h
+++ b/source/slang/slang-check.h
@@ -22,4 +22,7 @@ namespace Slang
bool isFromStdLib(Decl* decl);
void registerBuiltinDecls(Session* session, Decl* decl);
+
+ OrderedDictionary<GenericTypeParamDecl*, List<Type*>> getCanonicalGenericConstraints(
+ DeclRef<ContainerDecl> genericDecl);
}
diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp
index e6c0a8e7f..ca6dcecd7 100644
--- a/source/slang/slang-mangle.cpp
+++ b/source/slang/slang-mangle.cpp
@@ -2,6 +2,7 @@
#include "../compiler-core/slang-name.h"
#include "slang-syntax.h"
+#include "slang-check.h"
namespace Slang
{
@@ -330,6 +331,12 @@ namespace Slang
return;
}
+ // TODO: we should special case GenericTypeParamDecl and GenericValueParamDecl nodes
+ // instead of just dumping their names here to avoid the name of a generic parameter
+ // to have affect the binary signature.
+ // For each generic parameter, we should assign it a unique ID (i, j), where i is the
+ // nesting level of the generic, and j is the sequential order of the parameter within
+ // its generic parent, and use this 2D ID to refer to such a parameter.
emitName(context, declRef.getName());
// Special case: accessors need some way to distinguish themselves
@@ -392,26 +399,34 @@ namespace Slang
}
emit(context, genericParameterCount);
- for( auto mm : getMembers(parentGenericDeclRef) )
+
+ OrderedDictionary<GenericTypeParamDecl*, List<Type*>> genericConstraints;
+ for (auto mm : getMembers(parentGenericDeclRef))
{
- if(auto genericTypeParamDecl = mm.as<GenericTypeParamDecl>())
+ if (auto genericTypeParamDecl = mm.as<GenericTypeParamDecl>())
{
emitRaw(context, "T");
}
- else if(auto genericValueParamDecl = mm.as<GenericValueParamDecl>())
+ else if (auto genericValueParamDecl = mm.as<GenericValueParamDecl>())
{
emitRaw(context, "v");
emitType(context, getType(context->astBuilder, genericValueParamDecl));
}
- else if(mm.as<GenericTypeConstraintDecl>())
- {
- emitRaw(context, "C");
- // TODO: actually emit info about the constraint
- }
else
+ {}
+ }
+
+ auto canonicalizedConstraints = getCanonicalGenericConstraints(parentGenericDeclRef);
+ for (auto& constraint : canonicalizedConstraints)
+ {
+ for (auto type : constraint.Value)
{
+ emitRaw(context, "C");
+ emitQualifiedName(context, DeclRef<Decl>(constraint.Key, nullptr));
+ emitType(context, type);
}
}
+
}
}