mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
Add semantic::Call, IntrinsicCall, TextureIntrinsicCall, use them.
semantic::Call derives from semantic::Expression, and Type() is the return type of the function Pull the mutable semantic field from ast::Identifier and into a new semantic nodes. Have the TypeDeterminer create these new semantic nodes. Note: This change also fixes the node that holds the semantic information for a call. Previously this was on the identifier, and this is now correctly on the CallExpression. The identifier of the CallExpression should resolve to the target function, not the return type. Functions can currently be represented as a type, and the identifier of a CallExpression now has no semantic information. Bug: tint:390 Change-Id: I03521da5634815d35022f45ba521372cbbdb6bc7 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40065 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
48b384168c
commit
1618f4be4e
124
src/semantic/call.h
Normal file
124
src/semantic/call.h
Normal file
@@ -0,0 +1,124 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0(the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_SEMANTIC_CALL_H_
|
||||
#define SRC_SEMANTIC_CALL_H_
|
||||
|
||||
#include "src/semantic/expression.h"
|
||||
#include "src/semantic/intrinsic.h"
|
||||
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
/// Call is the base class for semantic nodes that hold semantic information for
|
||||
/// ast::CallExpression nodes.
|
||||
class Call : public Castable<Call, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param return_type the return type of the call
|
||||
explicit Call(type::Type* return_type);
|
||||
|
||||
/// Destructor
|
||||
~Call() override;
|
||||
};
|
||||
|
||||
/// IntrinsicCall holds semantic information for ast::CallExpression nodes that
|
||||
/// call intrinsic functions.
|
||||
class IntrinsicCall : public Castable<IntrinsicCall, Call> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param return_type the return type of the call
|
||||
/// @param intrinsic the call target intrinsic
|
||||
IntrinsicCall(type::Type* return_type, Intrinsic intrinsic);
|
||||
|
||||
/// Destructor
|
||||
~IntrinsicCall() override;
|
||||
|
||||
/// @returns the target intrinsic for the call
|
||||
Intrinsic intrinsic() const { return intrinsic_; }
|
||||
|
||||
private:
|
||||
Intrinsic const intrinsic_;
|
||||
};
|
||||
|
||||
/// TextureIntrinsicCall holds semantic information for ast::CallExpression
|
||||
/// nodes that call intrinsic texture functions.
|
||||
class TextureIntrinsicCall
|
||||
: public Castable<TextureIntrinsicCall, IntrinsicCall> {
|
||||
public:
|
||||
/// Parameters describes the parameters for the texture function.
|
||||
struct Parameters {
|
||||
/// kNotUsed is the constant that indicates the given parameter is not part
|
||||
/// of the texture function signature.
|
||||
static constexpr const size_t kNotUsed = ~static_cast<size_t>(0u);
|
||||
/// Index holds each of the possible parameter indices. If a parameter index
|
||||
/// is equal to `kNotUsed` then this parameter is not used by the function.
|
||||
struct Index {
|
||||
/// Constructor
|
||||
Index();
|
||||
/// Copy constructor
|
||||
Index(const Index&);
|
||||
/// `array_index` parameter index.
|
||||
size_t array_index = kNotUsed;
|
||||
/// `bias` parameter index.
|
||||
size_t bias = kNotUsed;
|
||||
/// `coords` parameter index.
|
||||
size_t coords = kNotUsed;
|
||||
/// `depth_ref` parameter index.
|
||||
size_t depth_ref = kNotUsed;
|
||||
/// `ddx` parameter index.
|
||||
size_t ddx = kNotUsed;
|
||||
/// `ddy` parameter index.
|
||||
size_t ddy = kNotUsed;
|
||||
/// `level` parameter index.
|
||||
size_t level = kNotUsed;
|
||||
/// `offset` parameter index.
|
||||
size_t offset = kNotUsed;
|
||||
/// `sampler` parameter index.
|
||||
size_t sampler = kNotUsed;
|
||||
/// `sample_index` parameter index.
|
||||
size_t sample_index = kNotUsed;
|
||||
/// `texture` parameter index.
|
||||
size_t texture = kNotUsed;
|
||||
/// `value` parameter index.
|
||||
size_t value = kNotUsed;
|
||||
};
|
||||
/// The indices of all possible parameters.
|
||||
Index idx;
|
||||
/// Total number of parameters.
|
||||
size_t count = 0;
|
||||
};
|
||||
|
||||
/// Constructor
|
||||
/// @param return_type the return type of the call
|
||||
/// @param intrinsic the call target intrinsic
|
||||
/// @param params the overload parameter info
|
||||
TextureIntrinsicCall(type::Type* return_type,
|
||||
Intrinsic intrinsic,
|
||||
const Parameters& params);
|
||||
|
||||
/// Destructor
|
||||
~TextureIntrinsicCall() override;
|
||||
|
||||
/// @return the texture call's parameters
|
||||
const Parameters& Params() const { return params_; }
|
||||
|
||||
private:
|
||||
const Parameters params_;
|
||||
};
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_SEMANTIC_CALL_H_
|
||||
220
src/semantic/intrinsic.cc
Normal file
220
src/semantic/intrinsic.cc
Normal file
@@ -0,0 +1,220 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/semantic/intrinsic.h"
|
||||
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Intrinsic i) {
|
||||
out << intrinsic::str(i);
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace intrinsic {
|
||||
|
||||
const char* str(Intrinsic i) {
|
||||
/// The emitted name matches the spelling in the WGSL spec.
|
||||
/// including case.
|
||||
switch (i) {
|
||||
case Intrinsic::kNone:
|
||||
return "<not-an-intrinsic>";
|
||||
case Intrinsic::kAbs:
|
||||
return "abs";
|
||||
case Intrinsic::kAcos:
|
||||
return "acos";
|
||||
case Intrinsic::kAll:
|
||||
return "all";
|
||||
case Intrinsic::kAny:
|
||||
return "any";
|
||||
case Intrinsic::kArrayLength:
|
||||
return "arrayLength";
|
||||
case Intrinsic::kAsin:
|
||||
return "asin";
|
||||
case Intrinsic::kAtan:
|
||||
return "atan";
|
||||
case Intrinsic::kAtan2:
|
||||
return "atan2";
|
||||
case Intrinsic::kCeil:
|
||||
return "ceil";
|
||||
case Intrinsic::kClamp:
|
||||
return "clamp";
|
||||
case Intrinsic::kCos:
|
||||
return "cos";
|
||||
case Intrinsic::kCosh:
|
||||
return "cosh";
|
||||
case Intrinsic::kCountOneBits:
|
||||
return "countOneBits";
|
||||
case Intrinsic::kCross:
|
||||
return "cross";
|
||||
case Intrinsic::kDeterminant:
|
||||
return "determinant";
|
||||
case Intrinsic::kDistance:
|
||||
return "distance";
|
||||
case Intrinsic::kDot:
|
||||
return "dot";
|
||||
case Intrinsic::kDpdx:
|
||||
return "dpdx";
|
||||
case Intrinsic::kDpdxCoarse:
|
||||
return "dpdxCoarse";
|
||||
case Intrinsic::kDpdxFine:
|
||||
return "dpdxFine";
|
||||
case Intrinsic::kDpdy:
|
||||
return "dpdy";
|
||||
case Intrinsic::kDpdyCoarse:
|
||||
return "dpdyCoarse";
|
||||
case Intrinsic::kDpdyFine:
|
||||
return "dpdyFine";
|
||||
case Intrinsic::kExp:
|
||||
return "exp";
|
||||
case Intrinsic::kExp2:
|
||||
return "exp2";
|
||||
case Intrinsic::kFaceForward:
|
||||
return "faceForward";
|
||||
case Intrinsic::kFloor:
|
||||
return "floor";
|
||||
case Intrinsic::kFma:
|
||||
return "fma";
|
||||
case Intrinsic::kFract:
|
||||
return "fract";
|
||||
case Intrinsic::kFrexp:
|
||||
return "frexp";
|
||||
case Intrinsic::kFwidth:
|
||||
return "fwidth";
|
||||
case Intrinsic::kFwidthCoarse:
|
||||
return "fwidthCoarse";
|
||||
case Intrinsic::kFwidthFine:
|
||||
return "fwidthFine";
|
||||
case Intrinsic::kInverseSqrt:
|
||||
return "inverseSqrt";
|
||||
case Intrinsic::kIsFinite:
|
||||
return "isFinite";
|
||||
case Intrinsic::kIsInf:
|
||||
return "isInf";
|
||||
case Intrinsic::kIsNan:
|
||||
return "isNan";
|
||||
case Intrinsic::kIsNormal:
|
||||
return "isNormal";
|
||||
case Intrinsic::kLdexp:
|
||||
return "ldexp";
|
||||
case Intrinsic::kLength:
|
||||
return "length";
|
||||
case Intrinsic::kLog:
|
||||
return "log";
|
||||
case Intrinsic::kLog2:
|
||||
return "log2";
|
||||
case Intrinsic::kMax:
|
||||
return "max";
|
||||
case Intrinsic::kMin:
|
||||
return "min";
|
||||
case Intrinsic::kMix:
|
||||
return "mix";
|
||||
case Intrinsic::kModf:
|
||||
return "modf";
|
||||
case Intrinsic::kNormalize:
|
||||
return "normalize";
|
||||
case Intrinsic::kPow:
|
||||
return "pow";
|
||||
case Intrinsic::kReflect:
|
||||
return "reflect";
|
||||
case Intrinsic::kReverseBits:
|
||||
return "reverseBits";
|
||||
case Intrinsic::kRound:
|
||||
return "round";
|
||||
case Intrinsic::kSelect:
|
||||
return "select";
|
||||
case Intrinsic::kSign:
|
||||
return "sign";
|
||||
case Intrinsic::kSin:
|
||||
return "sin";
|
||||
case Intrinsic::kSinh:
|
||||
return "sinh";
|
||||
case Intrinsic::kSmoothStep:
|
||||
return "smoothStep";
|
||||
case Intrinsic::kSqrt:
|
||||
return "sqrt";
|
||||
case Intrinsic::kStep:
|
||||
return "step";
|
||||
case Intrinsic::kTan:
|
||||
return "tan";
|
||||
case Intrinsic::kTanh:
|
||||
return "tanh";
|
||||
case Intrinsic::kTextureDimensions:
|
||||
return "textureDimensions";
|
||||
case Intrinsic::kTextureLoad:
|
||||
return "textureLoad";
|
||||
case Intrinsic::kTextureNumLayers:
|
||||
return "textureNumLayers";
|
||||
case Intrinsic::kTextureNumLevels:
|
||||
return "textureNumLevels";
|
||||
case Intrinsic::kTextureNumSamples:
|
||||
return "textureNumSamples";
|
||||
case Intrinsic::kTextureSample:
|
||||
return "textureSample";
|
||||
case Intrinsic::kTextureSampleBias:
|
||||
return "textureSampleBias";
|
||||
case Intrinsic::kTextureSampleCompare:
|
||||
return "textureSampleCompare";
|
||||
case Intrinsic::kTextureSampleGrad:
|
||||
return "textureSampleGrad";
|
||||
case Intrinsic::kTextureSampleLevel:
|
||||
return "textureSampleLevel";
|
||||
case Intrinsic::kTextureStore:
|
||||
return "textureStore";
|
||||
case Intrinsic::kTrunc:
|
||||
return "trunc";
|
||||
}
|
||||
return "<unknown>";
|
||||
}
|
||||
|
||||
bool IsCoarseDerivative(Intrinsic i) {
|
||||
return i == Intrinsic::kDpdxCoarse || i == Intrinsic::kDpdyCoarse ||
|
||||
i == Intrinsic::kFwidthCoarse;
|
||||
}
|
||||
|
||||
bool IsFineDerivative(Intrinsic i) {
|
||||
return i == Intrinsic::kDpdxFine || i == Intrinsic::kDpdyFine ||
|
||||
i == Intrinsic::kFwidthFine;
|
||||
}
|
||||
|
||||
bool IsDerivative(Intrinsic i) {
|
||||
return i == Intrinsic::kDpdx || i == Intrinsic::kDpdy ||
|
||||
i == Intrinsic::kFwidth || IsCoarseDerivative(i) ||
|
||||
IsFineDerivative(i);
|
||||
}
|
||||
|
||||
bool IsFloatClassificationIntrinsic(Intrinsic i) {
|
||||
return i == Intrinsic::kIsFinite || i == Intrinsic::kIsInf ||
|
||||
i == Intrinsic::kIsNan || i == Intrinsic::kIsNormal;
|
||||
}
|
||||
|
||||
bool IsTextureIntrinsic(Intrinsic i) {
|
||||
return IsImageQueryIntrinsic(i) || i == Intrinsic::kTextureLoad ||
|
||||
i == Intrinsic::kTextureSample ||
|
||||
i == Intrinsic::kTextureSampleLevel ||
|
||||
i == Intrinsic::kTextureSampleBias ||
|
||||
i == Intrinsic::kTextureSampleCompare ||
|
||||
i == Intrinsic::kTextureSampleGrad || i == Intrinsic::kTextureStore;
|
||||
}
|
||||
|
||||
bool IsImageQueryIntrinsic(Intrinsic i) {
|
||||
return i == semantic::Intrinsic::kTextureDimensions ||
|
||||
i == Intrinsic::kTextureNumLayers ||
|
||||
i == Intrinsic::kTextureNumLevels ||
|
||||
i == Intrinsic::kTextureNumSamples;
|
||||
}
|
||||
|
||||
} // namespace intrinsic
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
144
src/semantic/intrinsic.h
Normal file
144
src/semantic/intrinsic.h
Normal file
@@ -0,0 +1,144 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_SEMANTIC_INTRINSIC_H_
|
||||
#define SRC_SEMANTIC_INTRINSIC_H_
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
enum class Intrinsic {
|
||||
kNone = -1,
|
||||
|
||||
kAbs,
|
||||
kAcos,
|
||||
kAll,
|
||||
kAny,
|
||||
kArrayLength,
|
||||
kAsin,
|
||||
kAtan,
|
||||
kAtan2,
|
||||
kCeil,
|
||||
kClamp,
|
||||
kCos,
|
||||
kCosh,
|
||||
kCountOneBits,
|
||||
kCross,
|
||||
kDeterminant,
|
||||
kDistance,
|
||||
kDot,
|
||||
kDpdx,
|
||||
kDpdxCoarse,
|
||||
kDpdxFine,
|
||||
kDpdy,
|
||||
kDpdyCoarse,
|
||||
kDpdyFine,
|
||||
kExp,
|
||||
kExp2,
|
||||
kFaceForward,
|
||||
kFloor,
|
||||
kFma,
|
||||
kFract,
|
||||
kFrexp,
|
||||
kFwidth,
|
||||
kFwidthCoarse,
|
||||
kFwidthFine,
|
||||
kInverseSqrt,
|
||||
kIsFinite,
|
||||
kIsInf,
|
||||
kIsNan,
|
||||
kIsNormal,
|
||||
kLdexp,
|
||||
kLength,
|
||||
kLog,
|
||||
kLog2,
|
||||
kMax,
|
||||
kMin,
|
||||
kMix,
|
||||
kModf,
|
||||
kNormalize,
|
||||
kPow,
|
||||
kReflect,
|
||||
kReverseBits,
|
||||
kRound,
|
||||
kSelect,
|
||||
kSign,
|
||||
kSin,
|
||||
kSinh,
|
||||
kSmoothStep,
|
||||
kSqrt,
|
||||
kStep,
|
||||
kTan,
|
||||
kTanh,
|
||||
kTextureDimensions,
|
||||
kTextureLoad,
|
||||
kTextureNumLayers,
|
||||
kTextureNumLevels,
|
||||
kTextureNumSamples,
|
||||
kTextureSample,
|
||||
kTextureSampleBias,
|
||||
kTextureSampleCompare,
|
||||
kTextureSampleGrad,
|
||||
kTextureSampleLevel,
|
||||
kTextureStore,
|
||||
kTrunc
|
||||
};
|
||||
|
||||
/// Emits the name of the intrinsic function. The spelling,
|
||||
/// including case, matches the name in the WGSL spec.
|
||||
std::ostream& operator<<(std::ostream& out, Intrinsic i);
|
||||
|
||||
namespace intrinsic {
|
||||
|
||||
/// Determines if the given `i` is a coarse derivative
|
||||
/// @param i the intrinsic
|
||||
/// @returns true if the given derivative is coarse.
|
||||
bool IsCoarseDerivative(Intrinsic i);
|
||||
|
||||
/// Determines if the given `i` is a fine derivative
|
||||
/// @param i the intrinsic
|
||||
/// @returns true if the given derivative is fine.
|
||||
bool IsFineDerivative(Intrinsic i);
|
||||
|
||||
/// Determine if the given `i` is a derivative intrinsic
|
||||
/// @param i the intrinsic
|
||||
/// @returns true if the given `i` is a derivative intrinsic
|
||||
bool IsDerivative(Intrinsic i);
|
||||
|
||||
/// Determines if the given `i` is a float classification intrinsic
|
||||
/// @param i the intrinsic
|
||||
/// @returns true if the given `i` is a float intrinsic
|
||||
bool IsFloatClassificationIntrinsic(Intrinsic i);
|
||||
|
||||
/// Determines if the given `i` is a texture operation intrinsic
|
||||
/// @param i the intrinsic
|
||||
/// @returns true if the given `i` is a texture operation intrinsic
|
||||
bool IsTextureIntrinsic(Intrinsic i);
|
||||
|
||||
/// Determines if the given `i` is a image query intrinsic
|
||||
/// @param i the intrinsic
|
||||
/// @returns true if the given `i` is a image query intrinsic
|
||||
bool IsImageQueryIntrinsic(Intrinsic i);
|
||||
|
||||
/// @returns the name of the intrinsic function. The spelling, including case,
|
||||
/// matches the name in the WGSL spec.
|
||||
const char* str(Intrinsic i);
|
||||
|
||||
} // namespace intrinsic
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_SEMANTIC_INTRINSIC_H_
|
||||
45
src/semantic/sem_call.cc
Normal file
45
src/semantic/sem_call.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0(the "License");
|
||||
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/semantic/call.h"
|
||||
|
||||
TINT_INSTANTIATE_CLASS_ID(tint::semantic::Call);
|
||||
TINT_INSTANTIATE_CLASS_ID(tint::semantic::IntrinsicCall);
|
||||
TINT_INSTANTIATE_CLASS_ID(tint::semantic::TextureIntrinsicCall);
|
||||
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Call::Call(type::Type* return_type) : Base(return_type) {}
|
||||
|
||||
Call::~Call() = default;
|
||||
|
||||
IntrinsicCall::IntrinsicCall(type::Type* return_type, Intrinsic intrinsic)
|
||||
: Base(return_type), intrinsic_(intrinsic) {}
|
||||
|
||||
IntrinsicCall::~IntrinsicCall() = default;
|
||||
|
||||
TextureIntrinsicCall::TextureIntrinsicCall(type::Type* return_type,
|
||||
Intrinsic intrinsic,
|
||||
const Parameters& params)
|
||||
: Base(return_type, intrinsic), params_(params) {}
|
||||
|
||||
TextureIntrinsicCall::~TextureIntrinsicCall() = default;
|
||||
|
||||
TextureIntrinsicCall::Parameters::Index::Index() = default;
|
||||
TextureIntrinsicCall::Parameters::Index::Index(const Index&) = default;
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
@@ -22,6 +22,7 @@ namespace tint {
|
||||
// Forward declarations
|
||||
namespace ast {
|
||||
|
||||
class CallExpression;
|
||||
class Expression;
|
||||
class Function;
|
||||
class Variable;
|
||||
@@ -30,6 +31,7 @@ class Variable;
|
||||
|
||||
namespace semantic {
|
||||
|
||||
class Call;
|
||||
class Expression;
|
||||
class Function;
|
||||
class Variable;
|
||||
@@ -44,6 +46,7 @@ struct TypeMappings {
|
||||
semantic::Expression* operator()(ast::Expression*);
|
||||
semantic::Function* operator()(ast::Function*);
|
||||
semantic::Variable* operator()(ast::Variable*);
|
||||
semantic::Call* operator()(ast::CallExpression*);
|
||||
//! @endcond
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user