spirv-reader: only generate aliases for array types
Refactoring only. Change-Id: Ia931870a337cf93a54c5f2154754ef549c8559d7 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/64680 Auto-Submit: David Neto <dneto@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: David Neto <dneto@google.com>
This commit is contained in:
parent
d1c6f83341
commit
1d81f83704
|
@ -343,36 +343,27 @@ const Type* ParserImpl::ConvertType(uint32_t type_id, PtrAs ptr_as) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto maybe_generate_alias = [this, type_id,
|
|
||||||
spirv_type](const Type* type) -> const Type* {
|
|
||||||
if (type != nullptr) {
|
|
||||||
return MaybeGenerateAlias(type_id, spirv_type, type);
|
|
||||||
}
|
|
||||||
return type;
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (spirv_type->kind()) {
|
switch (spirv_type->kind()) {
|
||||||
case spvtools::opt::analysis::Type::kVoid:
|
case spvtools::opt::analysis::Type::kVoid:
|
||||||
return maybe_generate_alias(ty_.Void());
|
return ty_.Void();
|
||||||
case spvtools::opt::analysis::Type::kBool:
|
case spvtools::opt::analysis::Type::kBool:
|
||||||
return maybe_generate_alias(ty_.Bool());
|
return ty_.Bool();
|
||||||
case spvtools::opt::analysis::Type::kInteger:
|
case spvtools::opt::analysis::Type::kInteger:
|
||||||
return maybe_generate_alias(ConvertType(spirv_type->AsInteger()));
|
return ConvertType(spirv_type->AsInteger());
|
||||||
case spvtools::opt::analysis::Type::kFloat:
|
case spvtools::opt::analysis::Type::kFloat:
|
||||||
return maybe_generate_alias(ConvertType(spirv_type->AsFloat()));
|
return ConvertType(spirv_type->AsFloat());
|
||||||
case spvtools::opt::analysis::Type::kVector:
|
case spvtools::opt::analysis::Type::kVector:
|
||||||
return maybe_generate_alias(ConvertType(spirv_type->AsVector()));
|
return ConvertType(spirv_type->AsVector());
|
||||||
case spvtools::opt::analysis::Type::kMatrix:
|
case spvtools::opt::analysis::Type::kMatrix:
|
||||||
return maybe_generate_alias(ConvertType(spirv_type->AsMatrix()));
|
return ConvertType(spirv_type->AsMatrix());
|
||||||
case spvtools::opt::analysis::Type::kRuntimeArray:
|
case spvtools::opt::analysis::Type::kRuntimeArray:
|
||||||
return maybe_generate_alias(ConvertType(spirv_type->AsRuntimeArray()));
|
return ConvertType(type_id, spirv_type->AsRuntimeArray());
|
||||||
case spvtools::opt::analysis::Type::kArray:
|
case spvtools::opt::analysis::Type::kArray:
|
||||||
return maybe_generate_alias(ConvertType(spirv_type->AsArray()));
|
return ConvertType(type_id, spirv_type->AsArray());
|
||||||
case spvtools::opt::analysis::Type::kStruct:
|
case spvtools::opt::analysis::Type::kStruct:
|
||||||
return maybe_generate_alias(ConvertType(type_id, spirv_type->AsStruct()));
|
return ConvertType(type_id, spirv_type->AsStruct());
|
||||||
case spvtools::opt::analysis::Type::kPointer:
|
case spvtools::opt::analysis::Type::kPointer:
|
||||||
return maybe_generate_alias(
|
return ConvertType(type_id, ptr_as, spirv_type->AsPointer());
|
||||||
ConvertType(type_id, ptr_as, spirv_type->AsPointer()));
|
|
||||||
case spvtools::opt::analysis::Type::kFunction:
|
case spvtools::opt::analysis::Type::kFunction:
|
||||||
// Tint doesn't have a Function type.
|
// Tint doesn't have a Function type.
|
||||||
// We need to convert the result type and parameter types.
|
// We need to convert the result type and parameter types.
|
||||||
|
@ -384,7 +375,7 @@ const Type* ParserImpl::ConvertType(uint32_t type_id, PtrAs ptr_as) {
|
||||||
case spvtools::opt::analysis::Type::kImage:
|
case spvtools::opt::analysis::Type::kImage:
|
||||||
// Fake it for sampler and texture types. These are handled in an
|
// Fake it for sampler and texture types. These are handled in an
|
||||||
// entirely different way.
|
// entirely different way.
|
||||||
return maybe_generate_alias(ty_.Void());
|
return ty_.Void();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -978,6 +969,7 @@ const Type* ParserImpl::ConvertType(
|
||||||
}
|
}
|
||||||
|
|
||||||
const Type* ParserImpl::ConvertType(
|
const Type* ParserImpl::ConvertType(
|
||||||
|
uint32_t type_id,
|
||||||
const spvtools::opt::analysis::RuntimeArray* rtarr_ty) {
|
const spvtools::opt::analysis::RuntimeArray* rtarr_ty) {
|
||||||
auto* ast_elem_ty = ConvertType(type_mgr_->GetId(rtarr_ty->element_type()));
|
auto* ast_elem_ty = ConvertType(type_mgr_->GetId(rtarr_ty->element_type()));
|
||||||
if (ast_elem_ty == nullptr) {
|
if (ast_elem_ty == nullptr) {
|
||||||
|
@ -987,10 +979,12 @@ const Type* ParserImpl::ConvertType(
|
||||||
if (!ParseArrayDecorations(rtarr_ty, &array_stride)) {
|
if (!ParseArrayDecorations(rtarr_ty, &array_stride)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return ty_.Array(ast_elem_ty, 0, array_stride);
|
const Type* result = ty_.Array(ast_elem_ty, 0, array_stride);
|
||||||
|
return MaybeGenerateAlias(type_id, rtarr_ty, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Type* ParserImpl::ConvertType(
|
const Type* ParserImpl::ConvertType(
|
||||||
|
uint32_t type_id,
|
||||||
const spvtools::opt::analysis::Array* arr_ty) {
|
const spvtools::opt::analysis::Array* arr_ty) {
|
||||||
const auto elem_type_id = type_mgr_->GetId(arr_ty->element_type());
|
const auto elem_type_id = type_mgr_->GetId(arr_ty->element_type());
|
||||||
auto* ast_elem_ty = ConvertType(elem_type_id);
|
auto* ast_elem_ty = ConvertType(elem_type_id);
|
||||||
|
@ -1031,13 +1025,16 @@ const Type* ParserImpl::ConvertType(
|
||||||
if (remap_buffer_block_type_.count(elem_type_id)) {
|
if (remap_buffer_block_type_.count(elem_type_id)) {
|
||||||
remap_buffer_block_type_.insert(type_mgr_->GetId(arr_ty));
|
remap_buffer_block_type_.insert(type_mgr_->GetId(arr_ty));
|
||||||
}
|
}
|
||||||
return ty_.Array(ast_elem_ty, static_cast<uint32_t>(num_elem), array_stride);
|
const Type* result =
|
||||||
|
ty_.Array(ast_elem_ty, static_cast<uint32_t>(num_elem), array_stride);
|
||||||
|
return MaybeGenerateAlias(type_id, arr_ty, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParserImpl::ParseArrayDecorations(
|
bool ParserImpl::ParseArrayDecorations(
|
||||||
const spvtools::opt::analysis::Type* spv_type,
|
const spvtools::opt::analysis::Type* spv_type,
|
||||||
uint32_t* array_stride) {
|
uint32_t* array_stride) {
|
||||||
bool has_array_stride = false;
|
bool has_array_stride = false;
|
||||||
|
*array_stride = 0; // Implicit stride case.
|
||||||
const auto type_id = type_mgr_->GetId(spv_type);
|
const auto type_id = type_mgr_->GetId(spv_type);
|
||||||
for (auto& decoration : this->GetDecorationsFor(type_id)) {
|
for (auto& decoration : this->GetDecorationsFor(type_id)) {
|
||||||
if (decoration.size() == 2 && decoration[0] == SpvDecorationArrayStride) {
|
if (decoration.size() == 2 && decoration[0] == SpvDecorationArrayStride) {
|
||||||
|
|
|
@ -193,12 +193,9 @@ class ParserImpl : Reader {
|
||||||
/// @returns a Tint type, or nullptr
|
/// @returns a Tint type, or nullptr
|
||||||
const Type* ConvertType(uint32_t type_id, PtrAs ptr_as = PtrAs::Ptr);
|
const Type* ConvertType(uint32_t type_id, PtrAs ptr_as = PtrAs::Ptr);
|
||||||
|
|
||||||
/// Emits an alias type declaration for the given type, if necessary, and
|
/// Emits an alias type declaration for array or runtime-sized array type,
|
||||||
/// also updates the mapping of the SPIR-V type ID to the alias type.
|
/// when needed to distinguish between differently-decorated underlying types.
|
||||||
/// Do so for the types requiring user-specified names:
|
/// Updates the mapping of the SPIR-V type ID to the alias type.
|
||||||
/// - struct types
|
|
||||||
/// - decorated arrays and runtime arrays
|
|
||||||
/// TODO(dneto): I expect images and samplers to require names as well.
|
|
||||||
/// This is a no-op if the parser has already failed.
|
/// This is a no-op if the parser has already failed.
|
||||||
/// @param type_id the SPIR-V ID for the type
|
/// @param type_id the SPIR-V ID for the type
|
||||||
/// @param type the type that might get an alias
|
/// @param type the type that might get an alias
|
||||||
|
@ -698,12 +695,16 @@ class ParserImpl : Reader {
|
||||||
/// Converts a specific SPIR-V type to a Tint type. Matrix case
|
/// Converts a specific SPIR-V type to a Tint type. Matrix case
|
||||||
const Type* ConvertType(const spvtools::opt::analysis::Matrix* mat_ty);
|
const Type* ConvertType(const spvtools::opt::analysis::Matrix* mat_ty);
|
||||||
/// Converts a specific SPIR-V type to a Tint type. RuntimeArray case
|
/// Converts a specific SPIR-V type to a Tint type. RuntimeArray case
|
||||||
|
/// Distinct SPIR-V array types map to distinct Tint array types.
|
||||||
/// @param rtarr_ty the Tint type
|
/// @param rtarr_ty the Tint type
|
||||||
const Type* ConvertType(
|
const Type* ConvertType(
|
||||||
|
uint32_t type_id,
|
||||||
const spvtools::opt::analysis::RuntimeArray* rtarr_ty);
|
const spvtools::opt::analysis::RuntimeArray* rtarr_ty);
|
||||||
/// Converts a specific SPIR-V type to a Tint type. Array case
|
/// Converts a specific SPIR-V type to a Tint type. Array case
|
||||||
|
/// Distinct SPIR-V array types map to distinct Tint array types.
|
||||||
/// @param arr_ty the Tint type
|
/// @param arr_ty the Tint type
|
||||||
const Type* ConvertType(const spvtools::opt::analysis::Array* arr_ty);
|
const Type* ConvertType(uint32_t type_id,
|
||||||
|
const spvtools::opt::analysis::Array* arr_ty);
|
||||||
/// Converts a specific SPIR-V type to a Tint type. Struct case.
|
/// Converts a specific SPIR-V type to a Tint type. Struct case.
|
||||||
/// SPIR-V allows distinct struct type definitions for two OpTypeStruct
|
/// SPIR-V allows distinct struct type definitions for two OpTypeStruct
|
||||||
/// that otherwise have the same set of members (and struct and member
|
/// that otherwise have the same set of members (and struct and member
|
||||||
|
@ -740,7 +741,8 @@ class ParserImpl : Reader {
|
||||||
/// @returns the signed type
|
/// @returns the signed type
|
||||||
const Type* SignedTypeFor(const Type* type);
|
const Type* SignedTypeFor(const Type* type);
|
||||||
|
|
||||||
/// Parses the array or runtime-array decorations.
|
/// Parses the array or runtime-array decorations. Sets 0 if no explicit
|
||||||
|
/// stride was found, and therefore the implicit stride should be used.
|
||||||
/// @param spv_type the SPIR-V array or runtime-array type.
|
/// @param spv_type the SPIR-V array or runtime-array type.
|
||||||
/// @param array_stride pointer to the array stride
|
/// @param array_stride pointer to the array stride
|
||||||
/// @returns true on success.
|
/// @returns true on success.
|
||||||
|
|
|
@ -266,7 +266,7 @@ struct Array : public Castable<Array, Type> {
|
||||||
/// @param el the element type
|
/// @param el the element type
|
||||||
/// @param sz the number of elements in the array. 0 represents runtime-sized
|
/// @param sz the number of elements in the array. 0 represents runtime-sized
|
||||||
/// array.
|
/// array.
|
||||||
/// @param st the byte stride of the array
|
/// @param st the byte stride of the array. 0 means use implicit stride.
|
||||||
Array(const Type* el, uint32_t sz, uint32_t st);
|
Array(const Type* el, uint32_t sz, uint32_t st);
|
||||||
|
|
||||||
/// Copy constructor
|
/// Copy constructor
|
||||||
|
|
Loading…
Reference in New Issue