Hash :
fecb8ead
Author :
Date :
2025-09-04T12:27:48
WGSL: implement inc/dec with generated functions Implements inc/dec with generated WGSL functions that take pointers and perform a post/pre inc/decrement. This works with scalars, vectors, and matrices, both float and int. WGSL supports inc/dec only on integer types, and only as statements (not as expressions). https://www.w3.org/TR/WGSL/#increment-decrement. The regular ++ and -- are used in this specific case. The WGSL outputter records usage of increment/decrement and produces a call to the correct function. A new class is introduced to keep the record of which types need generated inc/dec WGSL functions. Bug: angleproject:42267100 Change-Id: I0e70760ba5bd00f978e216f958216ae3137a146e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6935269 Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Geoff Lang <geofflang@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
//
// 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.
//
#ifndef COMPILER_TRANSLATOR_WGSL_WGSL_PROGRAM_PRELUDE_H_
#define COMPILER_TRANSLATOR_WGSL_WGSL_PROGRAM_PRELUDE_H_
#include "compiler/translator/ImmutableString.h"
#include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h"
namespace sh
{
struct WGSLWrapperFunction
{
ImmutableString prefix;
ImmutableString suffix;
};
class WGSLProgramPrelude
{
public:
WGSLWrapperFunction preIncrement(const TType &preIncrementedType);
WGSLWrapperFunction preDecrement(const TType &preDecrementedType);
WGSLWrapperFunction postIncrement(const TType &postIncrementedType);
WGSLWrapperFunction postDecrement(const TType &postDecrementedType);
void outputPrelude(TInfoSinkBase &sink);
private:
TSet<TType> mPreIncrementedTypes;
TSet<TType> mPreDecrementedTypes;
TSet<TType> mPostIncrementedTypes;
TSet<TType> mPostDecrementedTypes;
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_WGSL_WGSL_PROGRAM_PRELUDE_H_