Hash :
cfe2c8fe
Author :
Date :
2025-06-25T13:25:01
WGSL: RewriteMultielementSwizzle WGSL doesn't support assignments to multi-element swizzles. This is used in a lot of shader tests, so temporarily work around this with an AST traverser that splits these assignments into multiple assignments that only assign to single element swizzles. One special case is multiplication-by-a-matrix assignment: vec.xy *= mat; is converted to vec.x = (vec.xy * mat).x; vec.y = (vec.xy * mat).y; Bug: angleproject:392542001 Change-Id: I3f393039aae13eb3f2c5dc5e553f68eb03b6316d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6847280 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Liza Burakova <liza@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
//
// Copyright 2025 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RewriteMultielementSwizzleAssignment: WGSL does not support assignment to multielement swizzles.
// This splits them into mutliple assignments to single-element swizzles.
//
// For example:
// vec3 v1 = ...;
// vec3 v2 = ...;
// v1.xy = v2.yz;
// is converted to:
// vec3 v1 = ...;
// vec3 v2 = ...;
// vec2 sbbc = v2.yz;
// v1.x = v2.x;
// v1.y = v2.y;
//
// Note that temporaries are used in order to avoid duplicated side effects in the RHS.
//
// One special case is multiplication-by-a-matrix assignment:
// vec.xy *= mat;
// is converted to something like
// vec.x = (vec.xy * mat).x;
// vec.y = (vec.xy * mat).y;
//
#ifndef COMPILER_TRANSLATOR_TREEOPS_WGSL_REWRITE_MULTIELEMENTSWIZZLEASSIGNMENT_H_
#define COMPILER_TRANSLATOR_TREEOPS_WGSL_REWRITE_MULTIELEMENTSWIZZLEASSIGNMENT_H_
#include "common/angleutils.h"
#include "compiler/translator/Compiler.h"
namespace sh
{
class TCompiler;
class TIntermBlock;
class TSymbolTable;
[[nodiscard]] bool RewriteMultielementSwizzleAssignment(TCompiler *compiler, TIntermBlock *root);
} // namespace sh
#endif // COMPILER_TRANSLATOR_TREEOPS_WGSL_REWRITE_MULTIELEMENTSWIZZLEASSIGNMENT_H_