TypeDeterminer: Resolve swizzles

Have the TD resolve swizzles down to indices, erroring out if they're not valid.

Resolving these at TD time removes swizzle parsing in the HLSL writer, and is generally useful information.

If we don't sanitize in the TD, we can end up trying to construct a resulting vector of an invalid size (> 4) triggering an assert in the type::Vector constructor.

Fixed: chromium:1180634
Bug: tint:79
Change-Id: If1282c933d65eb02d26a8dc7e190f27801ef9dc5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42221
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2021-02-24 14:15:02 +00:00
committed by Commit Bot service account
parent 8b1851dbdc
commit 6d612ad478
7 changed files with 118 additions and 42 deletions

View File

@@ -15,6 +15,8 @@
#ifndef SRC_SEMANTIC_MEMBER_ACCESSOR_EXPRESSION_H_
#define SRC_SEMANTIC_MEMBER_ACCESSOR_EXPRESSION_H_
#include <vector>
#include "src/semantic/expression.h"
namespace tint {
@@ -29,17 +31,24 @@ class MemberAccessorExpression
/// @param declaration the AST node
/// @param type the resolved type of the expression
/// @param statement the statement that owns this expression
/// @param is_swizzle true if this member access is for a vector swizzle
/// @param swizzle if this member access is for a vector swizzle, the swizzle
/// indices
MemberAccessorExpression(ast::Expression* declaration,
type::Type* type,
Statement* statement,
bool is_swizzle);
std::vector<uint32_t> swizzle);
/// Destructor
~MemberAccessorExpression() override;
/// @return true if this member access is for a vector swizzle
bool IsSwizzle() const { return is_swizzle_; }
bool IsSwizzle() const { return !swizzle_.empty(); }
/// @return the swizzle indices, if this is a vector swizzle
const std::vector<uint32_t>& Swizzle() const { return swizzle_; }
private:
bool const is_swizzle_;
std::vector<uint32_t> const swizzle_;
};
} // namespace semantic

View File

@@ -19,11 +19,14 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::MemberAccessorExpression);
namespace tint {
namespace semantic {
MemberAccessorExpression::MemberAccessorExpression(ast::Expression* declaration,
type::Type* type,
Statement* statement,
bool is_swizzle)
: Base(declaration, type, statement), is_swizzle_(is_swizzle) {}
MemberAccessorExpression::MemberAccessorExpression(
ast::Expression* declaration,
type::Type* type,
Statement* statement,
std::vector<uint32_t> swizzle)
: Base(declaration, type, statement), swizzle_(std::move(swizzle)) {}
MemberAccessorExpression::~MemberAccessorExpression() = default;
} // namespace semantic
} // namespace tint