[webkit-changes] [WebKit/WebKit] 124777: [WGSL] ConstantValue should be more precise
Tadeu Zagallo
noreply at github.com
Wed Nov 1 05:43:01 PDT 2023
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 1247773905f1474dd11fd62a3ceeee8f14e9c16b
https://github.com/WebKit/WebKit/commit/1247773905f1474dd11fd62a3ceeee8f14e9c16b
Author: Tadeu Zagallo <tzagallo at apple.com>
Date: 2023-11-01 (Wed, 01 Nov 2023)
Changed paths:
M Source/WebGPU/WGSL/AttributeValidator.cpp
M Source/WebGPU/WGSL/ConstantFunctions.h
M Source/WebGPU/WGSL/ConstantValue.cpp
M Source/WebGPU/WGSL/ConstantValue.h
M Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp
M Source/WebGPU/WGSL/TypeCheck.cpp
M Source/WebGPU/WebGPU/ComputePipeline.mm
M Source/WebGPU/WebGPU/Pipeline.mm
Log Message:
-----------
[WGSL] ConstantValue should be more precise
https://bugs.webkit.org/show_bug.cgi?id=263984
rdar://117749165
Reviewed by Mike Wyrzykowski.
Currently, we use 3 types to represent constant scalars: bool, int64_t and double.
These are technically sufficient, as they can fit all the possible scalar values.
However, constant functions need to be able to distinguish between the different
types of scalars, e.g. i32 vs u32 vs abstract_int. We could do that in two ways:
we could add a `Type*` to ConstantValue, which was the original approach, or we
can add more representations to ConstantValue (int32_t and uint32_t in this case).
- The issue with the first approach, and the reason I removed the type from ConstantValue,
is that every intermediate value must be assigned a type, which means we have
to construct these types and that is quite verbose.
- The second approach, which is the one this PR uses, makes sure that every scalar
has its own representation in ConstantValue, this allows using only the value as
the source of truth without having to also carry the type around. The downside is
that we must guarantee that the two are kept in sync. This has been helpful while
writing this PR though, as it highlights places where the two have diverged, and
forces us to perform the correct conversion of the values.
* Source/WebGPU/WGSL/AttributeValidator.cpp:
(WGSL::AttributeValidator::visit):
(WGSL::AttributeValidator::parseLocation):
* Source/WebGPU/WGSL/ConstantFunctions.h:
(WGSL::zeroValue):
(WGSL::constantUnaryOperation):
(WGSL::constantBinaryOperation):
(WGSL::constantTernaryOperation):
(WGSL::constantConstructor):
(WGSL::constantAdd):
(WGSL::constantMultiply):
(WGSL::BINARY_OPERATION):
(WGSL::constantBitwiseOr):
(WGSL::constantBitwiseAnd):
(WGSL::UNARY_OPERATION):
(WGSL::constantCross):
(WGSL::constantDeterminant):
(WGSL::constantDot):
(WGSL::constantLength):
(WGSL::constantExtractBits):
(WGSL::constantFaceForward):
(WGSL::constantInsertBits):
(WGSL::constantLdexp):
(WGSL::constantNormalize):
(WGSL::constantReflect):
(WGSL::constantRefract):
(WGSL::TERNARY_OPERATION):
(WGSL::constantInverseSqrt): Deleted.
* Source/WebGPU/WGSL/ConstantValue.cpp:
(WGSL::ConstantValue::dump const):
* Source/WebGPU/WGSL/ConstantValue.h:
(WGSL::ConstantValue::isI32 const):
(WGSL::ConstantValue::isU32 const):
(WGSL::ConstantValue::isAbstractInt const):
(WGSL::ConstantValue::isF32 const):
(WGSL::ConstantValue::isAbstractFloat const):
(WGSL::ConstantValue::toF32 const):
(WGSL::ConstantValue::integerValue const):
(WGSL::ConstantValue::isInt const): Deleted.
(WGSL::ConstantValue::isNumber const): Deleted.
(WGSL::ConstantValue::toInt const): Deleted.
(WGSL::ConstantValue::toDouble const): Deleted.
* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
(WGSL::Metal::FunctionDefinitionWriter::serializeConstant):
* Source/WebGPU/WGSL/TypeCheck.cpp:
(WGSL::TypeChecker::visitVariable):
(WGSL::TypeChecker::visit):
(WGSL::TypeChecker::chooseOverload):
(WGSL::TypeChecker::convertValue):
* Source/WebGPU/WebGPU/ComputePipeline.mm:
(WebGPU::metalSize):
* Source/WebGPU/WebGPU/Pipeline.mm:
(WebGPU::createConstantValues):
Canonical link: https://commits.webkit.org/270052@main
More information about the webkit-changes
mailing list