From 91ad2bc3846280f5c4679ee6b2168fa0ff0e6656 Mon Sep 17 00:00:00 2001 From: David Neto Date: Thu, 24 Nov 2022 22:41:58 +0000 Subject: [PATCH] Remove support for SPIRV-Tools API transition Remove the scaffolding required to support SPIRV-Tools using C vs. C++11 enums internally. Key downstream dependencies have been updated. Change-Id: Ia1982ba25209b6c50ad01679ac0e9fee06388fb8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/111680 Reviewed-by: Dan Sinclair Kokoro: Kokoro Auto-Submit: David Neto Commit-Queue: David Neto --- src/tint/reader/spirv/function.cc | 74 ++-------------------------- src/tint/reader/spirv/parser_impl.cc | 66 ++----------------------- 2 files changed, 7 insertions(+), 133 deletions(-) diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index accd692e34..d2edcaf9a4 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -143,83 +143,19 @@ using namespace tint::number_suffixes; // NOLINT namespace tint::reader::spirv { -namespace three_sided_patch_function_cc { -// This machinery is only used while SPIRV-Tools is in transition before it fully -// uses the C++11 header spirv.hpp11 - -/// Typedef for pointer to member function while the API call uses -/// SpvStorageClass for its second argument. -typedef uint32_t ( - spvtools::opt::analysis::TypeManager::*PointerFinderSpvStorageClass)(uint32_t, SpvStorageClass); -/// Typedef for pointer to member function while the API call uses -/// spv::StorageClass for its second argument. -typedef uint32_t (spvtools::opt::analysis::TypeManager::*PointerFinderSpvStorageClassCpp11)( - uint32_t, - spv::StorageClass); - -/// @param type_manager the SPIRV-Tools optimizer's type manager -/// @param finder a pointer to member function in the type manager that does the -/// actual lookup -/// @param pointee_type_id the ID of the pointee type -/// @param sc the storage class. SC can be SpvStorageClass or spv::StorageClass -/// @returns the ID for a SPIR-V pointer to pointee_type_id in storage class sc -template -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_manager, - FinderType finder, - uint32_t pointee_type_id, - SC sc); - -template <> -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_mgr, - PointerFinderSpvStorageClass finder, - uint32_t pointee_type_id, - SpvStorageClass sc) { - return (type_mgr->*finder)(pointee_type_id, sc); -} - -template <> -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_mgr, - PointerFinderSpvStorageClass finder, - uint32_t pointee_type_id, - spv::StorageClass sc) { - return (type_mgr->*finder)(pointee_type_id, static_cast(sc)); -} - -template <> -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_mgr, - PointerFinderSpvStorageClassCpp11 finder, - uint32_t pointee_type_id, - SpvStorageClass sc) { - return (type_mgr->*finder)(pointee_type_id, static_cast(sc)); -} - -template <> -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_mgr, - PointerFinderSpvStorageClassCpp11 finder, - uint32_t pointee_type_id, - spv::StorageClass sc) { - return (type_mgr->*finder)(pointee_type_id, sc); -} -} // namespace three_sided_patch_function_cc - namespace { constexpr uint32_t kMaxVectorLen = 4; -template -spv::Op ToOpcode(FromOpcodeType oc) { - return static_cast(oc); -} - /// @param inst a SPIR-V instruction /// @returns Returns the opcode for an instruciton inline spv::Op opcode(const spvtools::opt::Instruction& inst) { - return ToOpcode(inst.opcode()); + return inst.opcode(); } /// @param inst a SPIR-V instruction pointer /// @returns Returns the opcode for an instruciton inline spv::Op opcode(const spvtools::opt::Instruction* inst) { - return ToOpcode(inst->opcode()); + return inst->opcode(); } // Gets the AST unary opcode for the given SPIR-V opcode, if any @@ -727,7 +663,7 @@ class StructuredTraverser { // Visit successors. We will naturally skip the continue target and merge // blocks. auto* terminator = bb->terminator(); - auto opcode = ToOpcode(terminator->opcode()); + const auto opcode = terminator->opcode(); if (opcode == spv::Op::OpBranchConditional) { // Visit the false branch, then the true branch, to make them come // out in the natural order for an "if". @@ -4611,9 +4547,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(const spvtools::opt::Instructio << ": " << pointee_type_inst->PrettyPrint(); return {}; } - const auto pointer_type_id = three_sided_patch_function_cc::FindPointerToType( - type_mgr_, &spvtools::opt::analysis::TypeManager::FindPointerToType, pointee_type_id, - address_space); + const auto pointer_type_id = type_mgr_->FindPointerToType(pointee_type_id, address_space); auto* type = parser_impl_.ConvertType(pointer_type_id, PtrAs::Ref); TINT_ASSERT(Reader, type && type->Is()); current_expr = TypedExpression{type, next_expr}; diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index 600e570b55..52bdb12a2e 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -34,65 +34,6 @@ namespace tint::reader::spirv { -namespace three_sided_patch { -// This machinery is only used while SPIRV-Tools is in transition before it fully -// uses the C++11 header spirv.hpp11 - -/// Typedef for pointer to member function while the API call uses -/// SpvStorageClass for its second argument. -typedef uint32_t ( - spvtools::opt::analysis::TypeManager::*PointerFinderSpvStorageClass)(uint32_t, SpvStorageClass); -/// Typedef for pointer to member function while the API call uses -/// spv::StorageClass for its second argument. -typedef uint32_t (spvtools::opt::analysis::TypeManager::*PointerFinderSpvStorageClassCpp11)( - uint32_t, - spv::StorageClass); - -/// @param type_manager the SPIRV-Tools optimizer's type manager -/// @param finder a pointer to member function in the type manager that does the -/// actual lookup -/// @param pointee_type_id the ID of the pointee type -/// @param sc the storage class. SC can be SpvStorageClass or spv::StorageClass -/// @returns the ID for a SPIR-V pointer to pointee_type_id in storage class sc -template -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_manager, - FinderType finder, - uint32_t pointee_type_id, - SC sc); - -template <> -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_mgr, - PointerFinderSpvStorageClass finder, - uint32_t pointee_type_id, - SpvStorageClass sc) { - return (type_mgr->*finder)(pointee_type_id, sc); -} - -template <> -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_mgr, - PointerFinderSpvStorageClass finder, - uint32_t pointee_type_id, - spv::StorageClass sc) { - return (type_mgr->*finder)(pointee_type_id, static_cast(sc)); -} - -template <> -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_mgr, - PointerFinderSpvStorageClassCpp11 finder, - uint32_t pointee_type_id, - SpvStorageClass sc) { - return (type_mgr->*finder)(pointee_type_id, static_cast(sc)); -} - -template <> -uint32_t FindPointerToType(spvtools::opt::analysis::TypeManager* type_mgr, - PointerFinderSpvStorageClassCpp11 finder, - uint32_t pointee_type_id, - spv::StorageClass sc) { - return (type_mgr->*finder)(pointee_type_id, sc); -} -} // namespace three_sided_patch - namespace { // Input SPIR-V needs only to conform to Vulkan 1.1 requirements. @@ -104,12 +45,12 @@ const spv_target_env kInputEnv = SPV_ENV_VULKAN_1_1; /// @param inst a SPIR-V instruction /// @returns Returns the opcode for an instruciton inline spv::Op opcode(const spvtools::opt::Instruction& inst) { - return static_cast(inst.opcode()); + return inst.opcode(); } /// @param inst a SPIR-V instruction pointer /// @returns Returns the opcode for an instruciton inline spv::Op opcode(const spvtools::opt::Instruction* inst) { - return static_cast(inst->opcode()); + return inst->opcode(); } // A FunctionTraverser is used to compute an ordering of functions in the @@ -1347,8 +1288,7 @@ bool ParserImpl::RegisterTypes() { // Manufacture a type for the gl_Position variable if we have to. if ((builtin_position_.struct_type_id != 0) && (builtin_position_.position_member_pointer_type_id == 0)) { - builtin_position_.position_member_pointer_type_id = three_sided_patch::FindPointerToType( - type_mgr_, &spvtools::opt::analysis::TypeManager::FindPointerToType, + builtin_position_.position_member_pointer_type_id = type_mgr_->FindPointerToType( builtin_position_.position_member_type_id, builtin_position_.storage_class); ConvertType(builtin_position_.position_member_pointer_type_id); }