summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-06-24 10:20:19 -0400
committerGitHub <noreply@github.com>2024-06-24 10:20:19 -0400
commit8d2f6e4ddceb83009bb5f6b3d49001a2fd3cd761 (patch)
tree5780523e78ffa42562a2c49945c45a6c3295bbef
parentd832e33574ed772db1fa9b7ba184b37d0e3704cf (diff)
Add case to `emitVectorReshape` for when using a `vector<M, N>` type with `T` value (#4419)
* Add case to `emitVectorReshape` for `vector<>` type, `scalar` value 1. Add new case 2. Add test * fix warning * fix warning
-rw-r--r--source/slang/slang-ir.cpp18
-rw-r--r--tests/bugs/gh-4411.slang22
2 files changed, 39 insertions, 1 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 22ef4e6be..c0541f4c4 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -3894,7 +3894,23 @@ namespace Slang
{
auto targetVectorType = as<IRVectorType>(type);
auto sourceVectorType = as<IRVectorType>(value->getDataType());
- if (!targetVectorType)
+ if (targetVectorType && !sourceVectorType)
+ {
+ auto elementType = targetVectorType->getElementType();
+ Index elemCount = 1;
+ if(auto intLit = as<IRIntLit>(targetVectorType->getElementCount()))
+ {
+ elemCount = (Index)intLit->getValue();
+ }
+ IRInst* zeroVal = emitDefaultConstruct(elementType);
+ List<IRInst*> defaultVals;
+ defaultVals.reserve(elemCount);
+ defaultVals.add(value);
+ for(auto i = 1; i < elemCount; i++)
+ defaultVals.add(zeroVal);
+ return emitMakeVector(targetVectorType, defaultVals);
+ }
+ else if (!targetVectorType)
{
if (!sourceVectorType)
return emitCast(targetVectorType, value);
diff --git a/tests/bugs/gh-4411.slang b/tests/bugs/gh-4411.slang
new file mode 100644
index 000000000..06adff0b3
--- /dev/null
+++ b/tests/bugs/gh-4411.slang
@@ -0,0 +1,22 @@
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12 -use-dxil -shaderobj
+
+//TEST_INPUT:RWTexture1D(format=R32_UINT, size=8, content = zero, mipMaps = 1):name=texture1D
+RWTexture1D<uint> texture1D;
+
+//TEST_INPUT:RWTexture2D(format=R32_UINT, size=8, content = zero, mipMaps = 1):name=texture2D
+RWTexture2D<uint> texture2D;
+
+//TEST_INPUT:ubuffer(data=[0]):out,name=outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+void computeMain() {
+ texture1D[1].x = 15;
+ texture2D[uint2(2, 3)].x = 16;
+
+ outputBuffer[0] = uint(true
+ && texture1D[1].x == 15
+ && texture2D[uint2(2, 3)].x == 16
+ );
+ //BUF: 1
+} \ No newline at end of file