diff options
Diffstat (limited to 'source/opt/graphics_robust_access_pass.cpp')
-rw-r--r-- | source/opt/graphics_robust_access_pass.cpp | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/source/opt/graphics_robust_access_pass.cpp b/source/opt/graphics_robust_access_pass.cpp index 4652d72d5..da2764fc8 100644 --- a/source/opt/graphics_robust_access_pass.cpp +++ b/source/opt/graphics_robust_access_pass.cpp @@ -158,7 +158,6 @@ #include "source/util/make_unique.h" #include "spirv-tools/libspirv.h" #include "spirv/unified1/GLSL.std.450.h" -#include "spirv/unified1/spirv.h" #include "type_manager.h" #include "types.h" @@ -194,14 +193,15 @@ spvtools::DiagnosticStream GraphicsRobustAccessPass::Fail() { spv_result_t GraphicsRobustAccessPass::IsCompatibleModule() { auto* feature_mgr = context()->get_feature_mgr(); - if (!feature_mgr->HasCapability(SpvCapabilityShader)) + if (!feature_mgr->HasCapability(spv::Capability::Shader)) return Fail() << "Can only process Shader modules"; - if (feature_mgr->HasCapability(SpvCapabilityVariablePointers)) + if (feature_mgr->HasCapability(spv::Capability::VariablePointers)) return Fail() << "Can't process modules with VariablePointers capability"; - if (feature_mgr->HasCapability(SpvCapabilityVariablePointersStorageBuffer)) + if (feature_mgr->HasCapability( + spv::Capability::VariablePointersStorageBuffer)) return Fail() << "Can't process modules with VariablePointersStorageBuffer " "capability"; - if (feature_mgr->HasCapability(SpvCapabilityRuntimeDescriptorArrayEXT)) { + if (feature_mgr->HasCapability(spv::Capability::RuntimeDescriptorArrayEXT)) { // These have a RuntimeArray outside of Block-decorated struct. There // is no way to compute the array length from within SPIR-V. return Fail() << "Can't process modules with RuntimeDescriptorArrayEXT " @@ -210,8 +210,9 @@ spv_result_t GraphicsRobustAccessPass::IsCompatibleModule() { { auto* inst = context()->module()->GetMemoryModel(); - const auto addressing_model = inst->GetSingleWordOperand(0); - if (addressing_model != SpvAddressingModelLogical) + const auto addressing_model = + spv::AddressingModel(inst->GetSingleWordOperand(0)); + if (addressing_model != spv::AddressingModel::Logical) return Fail() << "Addressing model must be Logical. Found " << inst->PrettyPrint(); } @@ -237,11 +238,11 @@ bool GraphicsRobustAccessPass::ProcessAFunction(opt::Function* function) { for (auto& block : *function) { for (auto& inst : block) { switch (inst.opcode()) { - case SpvOpAccessChain: - case SpvOpInBoundsAccessChain: + case spv::Op::OpAccessChain: + case spv::Op::OpInBoundsAccessChain: access_chains.push_back(&inst); break; - case SpvOpImageTexelPointer: + case spv::Op::OpImageTexelPointer: image_texel_pointers.push_back(&inst); break; default: @@ -268,7 +269,7 @@ void GraphicsRobustAccessPass::ClampIndicesForAccessChain( auto* def_use_mgr = context()->get_def_use_mgr(); auto* type_mgr = context()->get_type_mgr(); const bool have_int64_cap = - context()->get_feature_mgr()->HasCapability(SpvCapabilityInt64); + context()->get_feature_mgr()->HasCapability(spv::Capability::Int64); // Replaces one of the OpAccessChain index operands with a new value. // Updates def-use analysis. @@ -451,7 +452,7 @@ void GraphicsRobustAccessPass::ClampIndicesForAccessChain( // It doesn't matter if 1 is signed or unsigned. auto* one = GetValueForType(1, wider_type); auto* count_minus_1 = InsertInst( - &inst, SpvOpISub, type_mgr->GetId(wider_type), TakeNextId(), + &inst, spv::Op::OpISub, type_mgr->GetId(wider_type), TakeNextId(), {{SPV_OPERAND_TYPE_ID, {count_inst->result_id()}}, {SPV_OPERAND_TYPE_ID, {one->result_id()}}}); auto* zero = GetValueForType(0, wider_type); @@ -486,15 +487,15 @@ void GraphicsRobustAccessPass::ClampIndicesForAccessChain( Instruction* index_inst = GetDef(index_id); switch (pointee_type->opcode()) { - case SpvOpTypeMatrix: // Use column count - case SpvOpTypeVector: // Use component count + case spv::Op::OpTypeMatrix: // Use column count + case spv::Op::OpTypeVector: // Use component count { const uint32_t count = pointee_type->GetSingleWordOperand(2); clamp_to_literal_count(idx, count); pointee_type = GetDef(pointee_type->GetSingleWordOperand(1)); } break; - case SpvOpTypeArray: { + case spv::Op::OpTypeArray: { // The array length can be a spec constant, so go through the general // case. Instruction* array_len = GetDef(pointee_type->GetSingleWordOperand(2)); @@ -502,11 +503,11 @@ void GraphicsRobustAccessPass::ClampIndicesForAccessChain( pointee_type = GetDef(pointee_type->GetSingleWordOperand(1)); } break; - case SpvOpTypeStruct: { + case spv::Op::OpTypeStruct: { // SPIR-V requires the index to be an OpConstant. // We need to know the index literal value so we can compute the next // pointee type. - if (index_inst->opcode() != SpvOpConstant || + if (index_inst->opcode() != spv::Op::OpConstant || !constant_mgr->GetConstantFromInst(index_inst) ->type() ->AsInteger()) { @@ -537,7 +538,7 @@ void GraphicsRobustAccessPass::ClampIndicesForAccessChain( // No need to clamp this index. We just checked that it's valid. } break; - case SpvOpTypeRuntimeArray: { + case spv::Op::OpTypeRuntimeArray: { auto* array_len = MakeRuntimeArrayLengthInst(&inst, idx); if (!array_len) { // We've already signaled an error. return; @@ -571,7 +572,7 @@ uint32_t GraphicsRobustAccessPass::GetGlslInsts() { module_status_.glsl_insts_id = TakeNextId(); std::vector<uint32_t> words = spvtools::utils::MakeVector(glsl); auto import_inst = MakeUnique<Instruction>( - context(), SpvOpExtInstImport, 0, module_status_.glsl_insts_id, + context(), spv::Op::OpExtInstImport, 0, module_status_.glsl_insts_id, std::initializer_list<Operand>{ Operand{SPV_OPERAND_TYPE_LITERAL_STRING, std::move(words)}}); Instruction* inst = import_inst.get(); @@ -609,8 +610,8 @@ opt::Instruction* opt::GraphicsRobustAccessPass::WidenInteger( auto type_id = context()->get_type_mgr()->GetId(unsigned_type); auto conversion_id = TakeNextId(); auto* conversion = InsertInst( - before_inst, (sign_extend ? SpvOpSConvert : SpvOpUConvert), type_id, - conversion_id, {{SPV_OPERAND_TYPE_ID, {value->result_id()}}}); + before_inst, (sign_extend ? spv::Op::OpSConvert : spv::Op::OpUConvert), + type_id, conversion_id, {{SPV_OPERAND_TYPE_ID, {value->result_id()}}}); return conversion; } @@ -628,7 +629,7 @@ Instruction* GraphicsRobustAccessPass::MakeUMinInst( (void)xwidth; (void)ywidth; auto* smin_inst = InsertInst( - where, SpvOpExtInst, x->type_id(), smin_id, + where, spv::Op::OpExtInst, x->type_id(), smin_id, { {SPV_OPERAND_TYPE_ID, {glsl_insts_id}}, {SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER, {GLSLstd450UMin}}, @@ -655,7 +656,7 @@ Instruction* GraphicsRobustAccessPass::MakeSClampInst( (void)minwidth; (void)maxwidth; auto* clamp_inst = InsertInst( - where, SpvOpExtInst, x->type_id(), clamp_id, + where, spv::Op::OpExtInst, x->type_id(), clamp_id, { {SPV_OPERAND_TYPE_ID, {glsl_insts_id}}, {SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER, {GLSLstd450SClamp}}, @@ -689,13 +690,13 @@ Instruction* GraphicsRobustAccessPass::MakeRuntimeArrayLengthInst( Instruction* pointer_to_containing_struct = nullptr; while (steps_remaining > 0) { switch (current_access_chain->opcode()) { - case SpvOpCopyObject: + case spv::Op::OpCopyObject: // Whoops. Walk right through this one. current_access_chain = GetDef(current_access_chain->GetSingleWordInOperand(0)); break; - case SpvOpAccessChain: - case SpvOpInBoundsAccessChain: { + case spv::Op::OpAccessChain: + case spv::Op::OpInBoundsAccessChain: { const int first_index_operand = 3; // How many indices in this access chain contribute to getting us // to an element in the runtime array? @@ -793,7 +794,8 @@ Instruction* GraphicsRobustAccessPass::MakeRuntimeArrayLengthInst( analysis::Integer uint_type_for_query(32, false); auto* uint_type = type_mgr->GetRegisteredType(&uint_type_for_query); auto* array_len = InsertInst( - access_chain, SpvOpArrayLength, type_mgr->GetId(uint_type), array_len_id, + access_chain, spv::Op::OpArrayLength, type_mgr->GetId(uint_type), + array_len_id, {{SPV_OPERAND_TYPE_ID, {pointer_to_containing_struct->result_id()}}, {SPV_OPERAND_TYPE_LITERAL_INTEGER, {member_index_of_runtime_array}}}); return array_len; @@ -839,11 +841,11 @@ spv_result_t GraphicsRobustAccessPass::ClampCoordinateForImageTexelPointer( // Declare the ImageQuery capability if the module doesn't already have it. auto* feature_mgr = context()->get_feature_mgr(); - if (!feature_mgr->HasCapability(SpvCapabilityImageQuery)) { + if (!feature_mgr->HasCapability(spv::Capability::ImageQuery)) { auto cap = MakeUnique<Instruction>( - context(), SpvOpCapability, 0, 0, + context(), spv::Op::OpCapability, 0, 0, std::initializer_list<Operand>{ - {SPV_OPERAND_TYPE_CAPABILITY, {SpvCapabilityImageQuery}}}); + {SPV_OPERAND_TYPE_CAPABILITY, {spv::Capability::ImageQuery}}}); def_use_mgr->AnalyzeInstDefUse(cap.get()); context()->AddCapability(std::move(cap)); feature_mgr->Analyze(context()->module()); @@ -890,21 +892,21 @@ spv_result_t GraphicsRobustAccessPass::ClampCoordinateForImageTexelPointer( const int arrayness_bonus = arrayed ? 1 : 0; int num_coords = 0; switch (dim) { - case SpvDimBuffer: + case spv::Dim::Buffer: case SpvDim1D: num_coords = 1; break; - case SpvDimCube: + case spv::Dim::Cube: // For cube, we need bounds for x, y, but not face. - case SpvDimRect: + case spv::Dim::Rect: case SpvDim2D: num_coords = 2; break; case SpvDim3D: num_coords = 3; break; - case SpvDimSubpassData: - case SpvDimMax: + case spv::Dim::SubpassData: + case spv::Dim::Max: return Fail() << "Invalid image dimension for OpImageTexelPointer: " << int(dim); break; @@ -941,12 +943,12 @@ spv_result_t GraphicsRobustAccessPass::ClampCoordinateForImageTexelPointer( const uint32_t image_id = TakeNextId(); auto* image = - InsertInst(image_texel_pointer, SpvOpLoad, image_type_id, image_id, + InsertInst(image_texel_pointer, spv::Op::OpLoad, image_type_id, image_id, {{SPV_OPERAND_TYPE_ID, {image_ptr->result_id()}}}); const uint32_t query_size_id = TakeNextId(); auto* query_size = - InsertInst(image_texel_pointer, SpvOpImageQuerySize, + InsertInst(image_texel_pointer, spv::Op::OpImageQuerySize, type_mgr->GetTypeInstruction(query_size_type), query_size_id, {{SPV_OPERAND_TYPE_ID, {image->result_id()}}}); @@ -962,7 +964,7 @@ spv_result_t GraphicsRobustAccessPass::ClampCoordinateForImageTexelPointer( // in the face index ranging from 0 through 5. The inclusive upper bound // on the third coordinate therefore is multiplied by 6. auto* query_size_including_faces = query_size; - if (arrayed && (dim == SpvDimCube)) { + if (arrayed && (dim == spv::Dim::Cube)) { // Multiply the last coordinate by 6. auto* component_6 = constant_mgr->GetConstant(coord_component_type, {6}); const uint32_t component_6_id = @@ -974,7 +976,7 @@ spv_result_t GraphicsRobustAccessPass::ClampCoordinateForImageTexelPointer( constant_mgr->GetDefiningInstruction(multiplicand); const auto query_size_including_faces_id = TakeNextId(); query_size_including_faces = InsertInst( - image_texel_pointer, SpvOpIMul, + image_texel_pointer, spv::Op::OpIMul, type_mgr->GetTypeInstruction(query_size_type), query_size_including_faces_id, {{SPV_OPERAND_TYPE_ID, {query_size_including_faces->result_id()}}, @@ -998,7 +1000,7 @@ spv_result_t GraphicsRobustAccessPass::ClampCoordinateForImageTexelPointer( const uint32_t query_max_including_faces_id = TakeNextId(); auto* query_max_including_faces = InsertInst( - image_texel_pointer, SpvOpISub, + image_texel_pointer, spv::Op::OpISub, type_mgr->GetTypeInstruction(query_size_type), query_max_including_faces_id, {{SPV_OPERAND_TYPE_ID, {query_size_including_faces->result_id()}}, @@ -1016,12 +1018,12 @@ spv_result_t GraphicsRobustAccessPass::ClampCoordinateForImageTexelPointer( // Get the sample count via OpImageQuerySamples const auto query_samples_id = TakeNextId(); auto* query_samples = InsertInst( - image_texel_pointer, SpvOpImageQuerySamples, + image_texel_pointer, spv::Op::OpImageQuerySamples, constant_mgr->GetDefiningInstruction(component_0)->type_id(), query_samples_id, {{SPV_OPERAND_TYPE_ID, {image->result_id()}}}); const auto max_samples_id = TakeNextId(); - auto* max_samples = InsertInst(image_texel_pointer, SpvOpImageQuerySamples, + auto* max_samples = InsertInst(image_texel_pointer, spv::Op::OpImageQuerySamples, query_samples->type_id(), max_samples_id, {{SPV_OPERAND_TYPE_ID, {query_samples_id}}, {SPV_OPERAND_TYPE_ID, {component_1_id}}}); @@ -1043,7 +1045,7 @@ spv_result_t GraphicsRobustAccessPass::ClampCoordinateForImageTexelPointer( } opt::Instruction* GraphicsRobustAccessPass::InsertInst( - opt::Instruction* where_inst, SpvOp opcode, uint32_t type_id, + opt::Instruction* where_inst, spv::Op opcode, uint32_t type_id, uint32_t result_id, const Instruction::OperandList& operands) { module_status_.modified = true; auto* result = where_inst->InsertBefore( |