summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-05-06 16:35:15 -0400
committerGitHub <noreply@github.com>2022-05-06 16:35:15 -0400
commit117f5e554839efc13066517461eafaf8f2fd96c6 (patch)
tree5ee76efce85beccd28371adabbcedfce7eb05e7b
parentb915ae662b2e4bcaaeb6da62eb964356d0a978b4 (diff)
Initial work around groupshared (#2224)
* #include an absolute path didn't work - because paths were taken to always be relative. * Allow rate modifier on parameter. * Add test. * Disable test for now as breaks on source comparison because around nvAPI.
-rw-r--r--source/slang/slang-emit-hlsl.cpp2
-rw-r--r--source/slang/slang-lower-to-ir.cpp6
-rw-r--r--tests/hlsl/simple/rate-param.hlsl30
-rw-r--r--tests/hlsl/simple/rate-param.hlsl.expected49
4 files changed, 87 insertions, 0 deletions
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp
index 945f00499..c319f2738 100644
--- a/source/slang/slang-emit-hlsl.cpp
+++ b/source/slang/slang-emit-hlsl.cpp
@@ -1041,6 +1041,8 @@ void HLSLSourceEmitter::_emitPrefixTypeAttr(IRAttr* attr)
void HLSLSourceEmitter::emitSimpleFuncParamImpl(IRParam* param)
{
+ emitRateQualifiers(param);
+
if (auto decor = param->findDecoration<IRGeometryInputPrimitiveTypeDecoration>())
{
switch (decor->getOp())
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index a185efba9..9fec8f839 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -2489,6 +2489,7 @@ IRLoweringParameterInfo getParameterInfo(
DeclRef<VarDeclBase> const& paramDecl)
{
IRLoweringParameterInfo info;
+
info.type = getType(context->astBuilder, paramDecl);
info.decl = paramDecl;
info.direction = getParameterDirection(paramDecl);
@@ -2698,6 +2699,11 @@ void _lowerFuncDeclBaseTypeInfo(
irParamType = maybeGetConstExprType(builder, irParamType, paramInfo.decl);
}
+ if (paramInfo.decl && paramInfo.decl->hasModifier<HLSLGroupSharedModifier>())
+ {
+ irParamType = builder->getRateQualifiedType(builder->getGroupSharedRate(), irParamType);
+ }
+
paramTypes.add(irParamType);
}
diff --git a/tests/hlsl/simple/rate-param.hlsl b/tests/hlsl/simple/rate-param.hlsl
new file mode 100644
index 000000000..5a36ba30e
--- /dev/null
+++ b/tests/hlsl/simple/rate-param.hlsl
@@ -0,0 +1,30 @@
+// rate-param.slang
+//DISABLE_TEST:SIMPLE: -target hlsl -entry computeMain -stage compute
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 ], stride=4):out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+groupshared uint gs_values[4];
+
+void someFunction(inout groupshared uint a[4], int index, int value)
+{
+ a[index] += value;
+}
+
+[shader("compute")]
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int index = (int)dispatchThreadID.x;
+
+ // Initialize
+ gs_values[3 - index] = index;
+
+ GroupMemoryBarrierWithGroupSync();
+
+ someFunction(gs_values, index, index * 2 + 1);
+
+ GroupMemoryBarrierWithGroupSync();
+
+ outputBuffer[index] = gs_values[index];
+}
diff --git a/tests/hlsl/simple/rate-param.hlsl.expected b/tests/hlsl/simple/rate-param.hlsl.expected
new file mode 100644
index 000000000..fd99b3fc1
--- /dev/null
+++ b/tests/hlsl/simple/rate-param.hlsl.expected
@@ -0,0 +1,49 @@
+result code = 0
+standard error = {
+}
+standard output = {
+#ifdef SLANG_HLSL_ENABLE_NVAPI
+#include "nvHLSLExtns.h"
+#endif
+
+#pragma pack_matrix(column_major)
+
+#line 7 "tests/hlsl/simple/rate-param.hlsl"
+static groupshared uint gs_values_0[int(4)];
+
+void someFunction_0(groupshared inout uint a_0[int(4)], int index_0, int value_0)
+{
+ a_0[index_0] = a_0[index_0] + (uint) value_0;
+ return;
+}
+
+
+#line 5
+RWStructuredBuffer<int > outputBuffer_0 : register(u0);
+
+
+#line 16
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID_0 : SV_DISPATCHTHREADID)
+{
+
+#line 18
+ int index_1 = (int) dispatchThreadID_0.x;
+
+
+ gs_values_0[int(3) - index_1] = (uint) index_1;
+
+ GroupMemoryBarrierWithGroupSync();
+
+ someFunction_0(gs_values_0, index_1, index_1 * int(2) + int(1));
+
+ GroupMemoryBarrierWithGroupSync();
+
+ int _S1 = (int) gs_values_0[index_1];
+
+#line 29
+ outputBuffer_0[(uint) index_1] = _S1;
+ return;
+}
+
+}