-
Notifications
You must be signed in to change notification settings - Fork 488
Fix lowering of swizzled lvalues #12769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b84affd
ea164f6
6ae1580
93438cc
89d1da1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7799,12 +7799,14 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBase<LValueExprLoweringVis | |
| auto loweredBase = lowerLValueExpr(context, expr->base); | ||
| UInt elementCount = (UInt)expr->elementIndices.getCount(); | ||
|
|
||
| // Assign to 'bs' the elements from 'as' according to the first 'n' indices in 'is' | ||
| auto backpermute = [](UInt n, const auto as, const auto is, auto bs) | ||
| // Assign to `resultElements` the elements from `sourceElements` according to the first `n` | ||
| // indices in `indices` | ||
| auto backpermute = | ||
| [](UInt n, const auto& sourceElements, const auto& indices, auto& resultElements) | ||
| { | ||
| for (UInt i = 0; i < n; ++i) | ||
| { | ||
| bs[i] = as[is[i]]; | ||
| resultElements[i] = sourceElements[indices[i]]; | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -7829,7 +7831,10 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBase<LValueExprLoweringVis | |
| RefPtr<SwizzledLValueInfo> swizzledLValue = new SwizzledLValueInfo; | ||
| swizzledLValue->type = irType; | ||
| swizzledLValue->base = baseSwizzleInfo->base; | ||
| swizzledLValue->elementIndices.add((uint32_t)elementCount); | ||
|
|
||
| // Set the count of indices and leave them uninitialized. | ||
| // This is safe because `backpermute` fills all `elementCount` slots below. | ||
| swizzledLValue->elementIndices.setCount((uint32_t)elementCount); | ||
|
jkwak-work marked this conversation as resolved.
jkwak-work marked this conversation as resolved.
jkwak-work marked this conversation as resolved.
jkwak-work marked this conversation as resolved.
jkwak-work marked this conversation as resolved.
jkwak-work marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Clarity: make the "every slot is written" invariant local The safety comment reasons in terms of backpermute(
swizzledLValue->elementIndices.getCount(),
...
swizzledLValue->elementIndices);The two are equal only because Separately, "leave them uninitialized" is only accurate for the POD short-buffer case (
jkwak-work marked this conversation as resolved.
|
||
|
|
||
| // Take the swizzle element of the "outer" swizzle, as it was | ||
| // written by the user. In our running example of `foo[i].zw.y` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -compute -shaderobj -output-using-type | ||
| //TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -compute -shaderobj -output-using-type | ||
| //TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -shaderobj -mtl -output-using-type | ||
| //TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -compute -shaderobj -output-using-type | ||
|
|
||
| // Test that writing to swizzles of vector swizzles works correctly | ||
|
|
||
| // CHECK: 2.0 | ||
| // CHECK-NEXT: 1.0 | ||
| // CHECK-NEXT: 0.0 | ||
| // CHECK-NEXT: 9.0 | ||
|
|
||
| //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer | ||
| RWStructuredBuffer<float> outputBuffer; | ||
|
|
||
| [numthreads(4, 1, 1)] | ||
| void computeMain(uint tid : SV_GroupIndex) | ||
| { | ||
| float4 a = float4(0); | ||
|
|
||
| a.zw.y = 9.0; | ||
| a.xyzw.yx = float2(1.0, 2.0); | ||
|
jkwak-work marked this conversation as resolved.
|
||
|
|
||
| // a = (2.0, 1.0, 0.0, 9.0) | ||
|
|
||
| outputBuffer[tid] = a[tid]; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.