diff options
| author | Yong He <yonghe@outlook.com> | 2023-08-09 10:54:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-09 10:54:41 -0700 |
| commit | 03a5bb4bc0391e2de3c2dfb9ff3213bc0ccd9664 (patch) | |
| tree | 8bdc7fbf12777c2efe68e677f6802afdb70ba8fc | |
| parent | c4615fe0ae7e1849b23e9a96d1453794b0b40e90 (diff) | |
Various fixes in GLSL emit. (#3074)
* Fix name mangling of modified types.
* Add `InterlockedAdd(__ref uint, int)` overload.
* Fix.
* Fix type error in ImageStore legalization.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
| -rw-r--r-- | source/slang/hlsl.meta.slang | 6 | ||||
| -rw-r--r-- | source/slang/slang-ir-glsl-legalize.cpp | 14 | ||||
| -rw-r--r-- | source/slang/slang-mangle.cpp | 13 | ||||
| -rw-r--r-- | tests/bugs/buffer-swizzle-store.slang | 16 | ||||
| -rw-r--r-- | tests/bugs/buffer-swizzle-store.slang.expected.txt | 2 | ||||
| -rw-r--r-- | tests/bugs/interlocked-add-uint-int.slang | 19 |
6 files changed, 59 insertions, 11 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 1ab046b19..56ad32326 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -2366,6 +2366,10 @@ __target_intrinsic(glsl, "$atomicAdd($A, $1)") __target_intrinsic(cuda, "atomicAdd((uint*)$0, $1)") void InterlockedAdd(__ref uint dest, uint value); +__target_intrinsic(glsl, "$atomicAdd($A, $1)") +__target_intrinsic(cuda, "atomicAdd((uint*)$0, $1)") +void InterlockedAdd(__ref uint dest, int value); + __target_intrinsic(glsl, "($2 = $atomicAdd($A, $1))") __target_intrinsic(cuda, "(*$2 = atomicAdd($0, $1))") void InterlockedAdd(__ref int dest, int value, out int original_value); @@ -7770,4 +7774,4 @@ ${{{{ ${{{{ } -}}}}
\ No newline at end of file +}}}} diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index dfe370d2b..a5bb299c5 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -79,26 +79,20 @@ void legalizeImageSubscriptStoreForGLSL(IRBuilder& builder, IRInst* storeInst) // Here we assume the imageElementType is already lowered into float4/uint4 types from any // user-defined type. assert(imageElementType->getOp() == kIROp_VectorType); - auto originalValue = builder.emitImageLoad(imageElementType, imageSubscript->getImage(), legalizedCoord); + auto vectorBaseType = getIRVectorBaseType(imageElementType); + IRType* vector4Type = builder.getVectorType(vectorBaseType, 4); + auto originalValue = builder.emitImageLoad(vector4Type, imageSubscript->getImage(), legalizedCoord); Array<IRInst*, 4> indices; for (UInt i = 0; i < swizzledStore->getElementCount(); i++) { indices.add(swizzledStore->getElementIndex(i)); } auto newValue = builder.emitSwizzleSet( - imageElementType, + vector4Type, originalValue, swizzledStore->getSource(), swizzledStore->getElementCount(), indices.getBuffer()); - if (getIRVectorElementSize(imageElementType) != 4) - { - auto vectorBaseType = getIRVectorBaseType(imageElementType); - newValue = builder.emitVectorReshape( - builder.getVectorType( - vectorBaseType, builder.getIntValue(builder.getIntType(), 4)), - newValue); - } auto imageStore = builder.emitImageStore( builder.getVoidType(), imageSubscript->getImage(), legalizedCoord, newValue); storeInst->replaceUsesWith(imageStore); diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp index b27a45484..6a3a17caa 100644 --- a/source/slang/slang-mangle.cpp +++ b/source/slang/slang-mangle.cpp @@ -251,6 +251,15 @@ namespace Slang for(Index i = 0; i < n; ++i) emitType(context, tupleType->getMember(i)); } + else if (auto modifiedType = dynamicCast<ModifiedType>(type)) + { + emitRaw(context, "Tm"); + emitType(context, modifiedType->getBase()); + auto n = modifiedType->getModifierCount(); + emit(context, n); + for (Index i = 0; i < n; ++i) + emitVal(context, modifiedType->getModifier(i)); + } else { SLANG_UNEXPECTED("unimplemented case in type mangling"); @@ -336,6 +345,10 @@ namespace Slang emitVal(context, typecastIntVal->getType()); emitVal(context, typecastIntVal->getBase()); } + else if (auto modifier = as<ModifierVal>(val)) + { + emitNameImpl(context, UnownedStringSlice(modifier->getClassInfo().m_name)); + } else { SLANG_UNEXPECTED("unimplemented case in val mangling"); diff --git a/tests/bugs/buffer-swizzle-store.slang b/tests/bugs/buffer-swizzle-store.slang new file mode 100644 index 000000000..ca09cded9 --- /dev/null +++ b/tests/bugs/buffer-swizzle-store.slang @@ -0,0 +1,16 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type + +//TEST_INPUT: RWTexture2D(format=R16G16_FLOAT, size=4, content = one, mipMaps = 1):name g_test +[format("rg16f")] +RWTexture2D<float2> g_test; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(1,1,1)] +void computeMain( uint2 dispatchThreadID : SV_DispatchThreadID ) +{ + g_test[dispatchThreadID].xy = float2(0.0, 1.0); + outputBuffer[dispatchThreadID.x] = g_test[dispatchThreadID].y; +}
\ No newline at end of file diff --git a/tests/bugs/buffer-swizzle-store.slang.expected.txt b/tests/bugs/buffer-swizzle-store.slang.expected.txt new file mode 100644 index 000000000..eddb06a2a --- /dev/null +++ b/tests/bugs/buffer-swizzle-store.slang.expected.txt @@ -0,0 +1,2 @@ +type: float +1.0
\ No newline at end of file diff --git a/tests/bugs/interlocked-add-uint-int.slang b/tests/bugs/interlocked-add-uint-int.slang new file mode 100644 index 000000000..10baa7f17 --- /dev/null +++ b/tests/bugs/interlocked-add-uint-int.slang @@ -0,0 +1,19 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -profile glsl_450 -stage compute -entry MainCs -line-directive-mode none +//CHECK: {{.*}} AtomicIAdd +RWBuffer<uint> g_InterlockTest; + +[numthreads(1,1,1)] +void MainCs( uint2 dispatchThreadID : SV_DispatchThreadID, uint2 groupThreadID : SV_GroupThreadID ) +{ + uint nVertexCount = 41; + uint nVertexBufferSize = 40; + uint nVertex = 3; + + InterlockedAdd( g_InterlockTest[ 0 ], nVertexCount, nVertex ); + + // Did we overflow? + if ( nVertex + nVertexCount > nVertexBufferSize ) + { + InterlockedAdd( g_InterlockTest[ 0 ], -int(nVertexCount) ); + } +}
\ No newline at end of file |
