diff --git a/include/spirv-tools/instrument.hpp b/include/spirv-tools/instrument.hpp index 34e169a9e..ae9278b0f 100644 --- a/include/spirv-tools/instrument.hpp +++ b/include/spirv-tools/instrument.hpp @@ -133,71 +133,6 @@ static const int kInstTaskOutGlobalInvocationIdZ = kInstCommonOutCnt + 2; // Size of Common and Stage-specific Members static const int kInstStageOutCnt = kInstCommonOutCnt + 3; -// Validation Error Code Offset -// -// This identifies the validation error. It also helps to identify -// how many words follow in the record and their meaning. -static const int kInstValidationOutError = kInstStageOutCnt; - -// Validation-specific Output Record Offsets -// -// Each different validation will generate a potentially different -// number of words at the end of the record giving more specifics -// about the validation error. -// -// A bindless bounds error will output the index and the bound. -static const int kInstBindlessBoundsOutDescSet = kInstStageOutCnt + 1; -static const int kInstBindlessBoundsOutDescBinding = kInstStageOutCnt + 2; -static const int kInstBindlessBoundsOutDescIndex = kInstStageOutCnt + 3; -static const int kInstBindlessBoundsOutDescBound = kInstStageOutCnt + 4; -static const int kInstBindlessBoundsOutUnused = kInstStageOutCnt + 5; -static const int kInstBindlessBoundsOutCnt = kInstStageOutCnt + 6; - -// A descriptor uninitialized error will output the index. -static const int kInstBindlessUninitOutDescSet = kInstStageOutCnt + 1; -static const int kInstBindlessUninitOutBinding = kInstStageOutCnt + 2; -static const int kInstBindlessUninitOutDescIndex = kInstStageOutCnt + 3; -static const int kInstBindlessUninitOutUnused = kInstStageOutCnt + 4; -static const int kInstBindlessUninitOutUnused2 = kInstStageOutCnt + 5; -static const int kInstBindlessUninitOutCnt = kInstStageOutCnt + 6; - -// A buffer out-of-bounds error will output the descriptor -// index, the buffer offset and the buffer size -static const int kInstBindlessBuffOOBOutDescSet = kInstStageOutCnt + 1; -static const int kInstBindlessBuffOOBOutDescBinding = kInstStageOutCnt + 2; -static const int kInstBindlessBuffOOBOutDescIndex = kInstStageOutCnt + 3; -static const int kInstBindlessBuffOOBOutBuffOff = kInstStageOutCnt + 4; -static const int kInstBindlessBuffOOBOutBuffSize = kInstStageOutCnt + 5; -static const int kInstBindlessBuffOOBOutCnt = kInstStageOutCnt + 6; - -// A buffer address unalloc error will output the 64-bit pointer in -// two 32-bit pieces, lower bits first. -static const int kInstBuffAddrUnallocOutDescPtrLo = kInstStageOutCnt + 1; -static const int kInstBuffAddrUnallocOutDescPtrHi = kInstStageOutCnt + 2; -static const int kInstBuffAddrUnallocOutCnt = kInstStageOutCnt + 3; - -// Maximum Output Record Member Count -static const int kInstMaxOutCnt = kInstStageOutCnt + 6; - -// Validation Error Codes -// -// These are the possible validation error codes. -static const int kInstErrorBindlessBounds = 1; -static const int kInstErrorBindlessUninit = 2; -static const int kInstErrorBuffAddrUnallocRef = 3; -static const int kInstErrorOOB = 4; -static const int kInstErrorMax = kInstErrorOOB; - -// Direct Input Buffer Offsets -// -// The following values provide member offsets into the input buffers -// consumed by InstrumentPass::GenDebugDirectRead(). This method is utilized -// by InstBindlessCheckPass. -// -// The only object in an input buffer is a runtime array of unsigned -// integers. Each validation will have its own formatting of this array. -static const int kDebugInputDataOffset = 0; - // Debug Buffer Bindings // // These are the bindings for the different buffers which are @@ -216,63 +151,6 @@ static const int kDebugInputBindingBuffAddr = 2; // This is the output buffer written by InstDebugPrintfPass. static const int kDebugOutputPrintfStream = 3; -// clang-format off -// Bindless Validation Input Buffer Format -// -// An input buffer for bindless validation has this structure: -// GLSL: -// layout(buffer_reference, std430, buffer_reference_align = 8) buffer DescriptorSetData { -// uint num_bindings; -// uint data[]; -// }; -// -// layout(set = 7, binding = 1, std430) buffer inst_bindless_InputBuffer -// { -// DescriptorSetData desc_sets[32]; -// } inst_bindless_input_buffer; -// -// -// To look up the length of a binding: -// uint length = inst_bindless_input_buffer[set].data[binding]; -// Scalar bindings have a length of 1. -// -// To look up the initialization state of a descriptor in a binding: -// uint num_bindings = inst_bindless_input_buffer[set].num_bindings; -// uint binding_state_start = inst_bindless_input_buffer[set].data[num_bindings + binding]; -// uint init_state = inst_bindless_input_buffer[set].data[binding_state_start + index]; -// -// For scalar bindings, use 0 for the index. -// clang-format on -// -// The size of the inst_bindless_input_buffer array, regardless of how many -// descriptor sets the device supports. -static const int kDebugInputBindlessMaxDescSets = 32; - -// Buffer Device Address Input Buffer Format -// -// An input buffer for buffer device address validation consists of a single -// array of unsigned 64-bit integers we will call Data[]. This array is -// formatted as follows: -// -// At offset kDebugInputBuffAddrPtrOffset is a list of sorted valid buffer -// addresses. The list is terminated with the address 0xffffffffffffffff. -// If 0x0 is not a valid buffer address, this address is inserted at the -// start of the list. -// -static const int kDebugInputBuffAddrPtrOffset = 1; -// -// At offset kDebugInputBuffAddrLengthOffset in Data[] is a single uint64 which -// gives an offset to the start of the buffer length data. More -// specifically, for a buffer whose pointer is located at input buffer offset -// i, the length is located at: -// -// Data[ i - kDebugInputBuffAddrPtrOffset -// + Data[ kDebugInputBuffAddrLengthOffset ] ] -// -// The length associated with the 0xffffffffffffffff address is zero. If -// not a valid buffer, the length associated with the 0x0 address is zero. -static const int kDebugInputBuffAddrLengthOffset = 0; - } // namespace spvtools #endif // INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_ diff --git a/include/spirv-tools/optimizer.hpp b/include/spirv-tools/optimizer.hpp index 260fa72c9..ef639524c 100644 --- a/include/spirv-tools/optimizer.hpp +++ b/include/spirv-tools/optimizer.hpp @@ -766,11 +766,9 @@ Optimizer::PassToken CreateCombineAccessChainsPass(); // potentially de-optimizing the instrument code, for example, inlining // the debug record output function throughout the module. // -// The instrumentation will read and write buffers in debug -// descriptor set |desc_set|. It will write |shader_id| in each output record +// The instrumentation will write |shader_id| in each output record // to identify the shader module which generated the record. -Optimizer::PassToken CreateInstBindlessCheckPass(uint32_t desc_set, - uint32_t shader_id); +Optimizer::PassToken CreateInstBindlessCheckPass(uint32_t shader_id); // Create a pass to instrument physical buffer address checking // This pass instruments all physical buffer address references to check that @@ -791,8 +789,7 @@ Optimizer::PassToken CreateInstBindlessCheckPass(uint32_t desc_set, // The instrumentation will read and write buffers in debug // descriptor set |desc_set|. It will write |shader_id| in each output record // to identify the shader module which generated the record. -Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t desc_set, - uint32_t shader_id); +Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t shader_id); // Create a pass to instrument OpDebugPrintf instructions. // This pass replaces all OpDebugPrintf instructions with instructions to write diff --git a/source/opt/inst_bindless_check_pass.cpp b/source/opt/inst_bindless_check_pass.cpp index 339fb1b62..f84d5b298 100644 --- a/source/opt/inst_bindless_check_pass.cpp +++ b/source/opt/inst_bindless_check_pass.cpp @@ -39,149 +39,11 @@ constexpr int kSpvTypeImageArrayed = 3; constexpr int kSpvTypeImageMS = 4; } // namespace -void InstBindlessCheckPass::SetupInputBufferIds() { - if (input_buffer_id_ != 0) { - return; - } - AddStorageBufferExt(); - if (!get_feature_mgr()->HasExtension(kSPV_KHR_physical_storage_buffer)) { - context()->AddExtension("SPV_KHR_physical_storage_buffer"); - } - context()->AddCapability(spv::Capability::PhysicalStorageBufferAddresses); - Instruction* memory_model = get_module()->GetMemoryModel(); - // TODO should this be just Physical64? - memory_model->SetInOperand( - 0u, {uint32_t(spv::AddressingModel::PhysicalStorageBuffer64)}); - - analysis::DecorationManager* deco_mgr = get_decoration_mgr(); - analysis::TypeManager* type_mgr = context()->get_type_mgr(); - constexpr uint32_t width = 32u; - - // declare the DescriptorSetData struct - analysis::Struct* desc_set_struct = - GetStruct({type_mgr->GetUIntType(), GetUintRuntimeArrayType(width)}); - desc_set_type_id_ = type_mgr->GetTypeInstruction(desc_set_struct); - // By the Vulkan spec, a pre-existing struct containing a RuntimeArray - // must be a block, and will therefore be decorated with Block. Therefore - // the undecorated type returned here will not be pre-existing and can - // safely be decorated. Since this type is now decorated, it is out of - // sync with the TypeManager and therefore the TypeManager must be - // invalidated after this pass. - assert(context()->get_def_use_mgr()->NumUses(desc_set_type_id_) == 0 && - "used struct type returned"); - deco_mgr->AddDecoration(desc_set_type_id_, uint32_t(spv::Decoration::Block)); - deco_mgr->AddMemberDecoration(desc_set_type_id_, 0, - uint32_t(spv::Decoration::Offset), 0); - deco_mgr->AddMemberDecoration(desc_set_type_id_, 1, - uint32_t(spv::Decoration::Offset), 4); - context()->AddDebug2Inst( - NewGlobalName(desc_set_type_id_, "DescriptorSetData")); - context()->AddDebug2Inst(NewMemberName(desc_set_type_id_, 0, "num_bindings")); - context()->AddDebug2Inst(NewMemberName(desc_set_type_id_, 1, "data")); - - // declare buffer address reference to DescriptorSetData - desc_set_ptr_id_ = type_mgr->FindPointerToType( - desc_set_type_id_, spv::StorageClass::PhysicalStorageBuffer); - // runtime array of buffer addresses - analysis::Type* rarr_ty = GetArray(type_mgr->GetType(desc_set_ptr_id_), - kDebugInputBindlessMaxDescSets); - deco_mgr->AddDecorationVal(type_mgr->GetId(rarr_ty), - uint32_t(spv::Decoration::ArrayStride), 8u); - - // declare the InputBuffer type, a struct wrapper around the runtime array - analysis::Struct* input_buffer_struct = GetStruct({rarr_ty}); - input_buffer_struct_id_ = type_mgr->GetTypeInstruction(input_buffer_struct); - deco_mgr->AddDecoration(input_buffer_struct_id_, - uint32_t(spv::Decoration::Block)); - deco_mgr->AddMemberDecoration(input_buffer_struct_id_, 0, - uint32_t(spv::Decoration::Offset), 0); - context()->AddDebug2Inst( - NewGlobalName(input_buffer_struct_id_, "InputBuffer")); - context()->AddDebug2Inst( - NewMemberName(input_buffer_struct_id_, 0, "desc_sets")); - - input_buffer_ptr_id_ = type_mgr->FindPointerToType( - input_buffer_struct_id_, spv::StorageClass::StorageBuffer); - - // declare the input_buffer global variable - input_buffer_id_ = TakeNextId(); - - const std::vector var_operands = { - {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, - {uint32_t(spv::StorageClass::StorageBuffer)}}, - }; - auto new_var_op = spvtools::MakeUnique( - context(), spv::Op::OpVariable, input_buffer_ptr_id_, input_buffer_id_, - var_operands); - - context()->AddGlobalValue(std::move(new_var_op)); - context()->AddDebug2Inst(NewGlobalName(input_buffer_id_, "input_buffer")); - deco_mgr->AddDecorationVal( - input_buffer_id_, uint32_t(spv::Decoration::DescriptorSet), desc_set_); - deco_mgr->AddDecorationVal(input_buffer_id_, - uint32_t(spv::Decoration::Binding), - GetInputBufferBinding()); - if (get_module()->version() >= SPV_SPIRV_VERSION_WORD(1, 4)) { - // Add the new buffer to all entry points. - for (auto& entry : get_module()->entry_points()) { - entry.AddOperand({SPV_OPERAND_TYPE_ID, {input_buffer_id_}}); - context()->AnalyzeUses(&entry); - } - } -} - +// This is a stub function for use with Import linkage // clang-format off // GLSL: -//bool inst_bindless_check_desc(uint shader_id, uint inst_num, uvec4 stage_info, uint desc_set, uint binding, uint desc_index, -// uint byte_offset) -//{ -// uint error = 0u; -// uint param5 = 0u; -// uint param6 = 0u; -// uint num_bindings = 0u; -// uint init_state = 0u; -// if (desc_set >= 32u) { -// error = 1u; -// } -// inst_bindless_DescriptorSetData set_data; -// if (error == 0u) { -// set_data = inst_bindless_input_buffer.desc_sets[desc_set]; -// uvec2 ptr_vec = uvec2(set_data); -// if ((ptr_vec.x == 0u) && (ptr_vec.y == 0u)) { -// error = 1u; -// } -// } -// if (error == 0u) { -// num_bindings = set_data.num_bindings; -// if (binding >= num_bindings) { -// error = 1u; -// } -// } -// if (error == 0u) { -// if (desc_index >= set_data.data[binding]) { -// error = 1u; -// param5 = set_data.data[binding]; -// } -// } -// if (0u == error) { -// uint state_index = set_data.data[num_bindings + binding] + desc_index; -// init_state = set_data.data[state_index]; -// if (init_state == 0u) { -// error = 2u; -// } -// } -// if (error == 0u) { -// if (byte_offset >= init_state) { -// error = 4u; -// param5 = byte_offset; -// param6 = init_state; -// } -// } -// if (0u != error) { -// inst_bindless_stream_write_6(shader_id, inst_num, stage_info, error, desc_set, binding, desc_index, param5, param6); -// return false; -// } -// return true; +//bool inst_bindless_check_desc(const uint shader_id, const uint inst_num, const uvec4 stage_info, const uint desc_set, +// const uint binding, const uint desc_index, const uint byte_offset) { //} // clang-format on uint32_t InstBindlessCheckPass::GenDescCheckFunctionId() { @@ -195,11 +57,10 @@ uint32_t InstBindlessCheckPass::GenDescCheckFunctionId() { kByteOffset = 6, kNumArgs }; - if (desc_check_func_id_ != 0) { - return desc_check_func_id_; + if (check_desc_func_id_ != 0) { + return check_desc_func_id_; } - SetupInputBufferIds(); analysis::TypeManager* type_mgr = context()->get_type_mgr(); const analysis::Integer* uint_type = GetInteger(32, false); const analysis::Vector v4uint(uint_type, 4); @@ -211,454 +72,32 @@ uint32_t InstBindlessCheckPass::GenDescCheckFunctionId() { std::unique_ptr func = StartFunction(func_id, type_mgr->GetBoolType(), param_types); - const std::vector param_ids = AddParameters(*func, param_types); - - const uint32_t func_uint_ptr = - type_mgr->FindPointerToType(GetUintId(), spv::StorageClass::Function); - // Create block - auto new_blk_ptr = MakeUnique(NewLabel(TakeNextId())); - InstructionBuilder builder( - context(), new_blk_ptr.get(), - IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping); - Instruction* inst; - const uint32_t zero_id = builder.GetUintConstantId(0); - const uint32_t false_id = builder.GetBoolConstantId(false); - const uint32_t true_id = builder.GetBoolConstantId(true); - const uint32_t uint_ptr = type_mgr->FindPointerToType( - GetUintId(), spv::StorageClass::PhysicalStorageBuffer); - - inst = builder.AddBinaryOp(func_uint_ptr, spv::Op::OpVariable, - uint32_t(spv::StorageClass::Function), zero_id); - const uint32_t error_var = inst->result_id(); - - inst = builder.AddBinaryOp(func_uint_ptr, spv::Op::OpVariable, - uint32_t(spv::StorageClass::Function), zero_id); - const uint32_t param5_var = inst->result_id(); - - inst = builder.AddBinaryOp(func_uint_ptr, spv::Op::OpVariable, - uint32_t(spv::StorageClass::Function), zero_id); - const uint32_t param6_var = inst->result_id(); - - inst = builder.AddBinaryOp(func_uint_ptr, spv::Op::OpVariable, - uint32_t(spv::StorageClass::Function), zero_id); - const uint32_t num_bindings_var = inst->result_id(); - inst = builder.AddBinaryOp(func_uint_ptr, spv::Op::OpVariable, - uint32_t(spv::StorageClass::Function), zero_id); - const uint32_t init_status_var = inst->result_id(); - - const uint32_t desc_set_ptr_ptr = type_mgr->FindPointerToType( - desc_set_ptr_id_, spv::StorageClass::Function); - - inst = builder.AddUnaryOp(desc_set_ptr_ptr, spv::Op::OpVariable, - uint32_t(spv::StorageClass::Function)); - const uint32_t desc_set_ptr_var = inst->result_id(); - get_decoration_mgr()->AddDecoration( - desc_set_ptr_var, uint32_t(spv::Decoration::AliasedPointer)); - - uint32_t check_label_id = TakeNextId(); - auto check_label = NewLabel(check_label_id); - uint32_t skip_label_id = TakeNextId(); - auto skip_label = NewLabel(skip_label_id); - inst = builder.AddBinaryOp( - GetBoolId(), spv::Op::OpUGreaterThanEqual, param_ids[kDescSet], - builder.GetUintConstantId(kDebugInputBindlessMaxDescSets)); - const uint32_t desc_cmp_id = inst->result_id(); - - (void)builder.AddConditionalBranch(desc_cmp_id, check_label_id, skip_label_id, - skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - // set error - new_blk_ptr = MakeUnique(std::move(check_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddStore(error_var, - builder.GetUintConstantId(kInstErrorBindlessBounds)); - builder.AddBranch(skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - // check descriptor set table entry is non-null - new_blk_ptr = MakeUnique(std::move(skip_label)); - builder.SetInsertPoint(&*new_blk_ptr); - - check_label_id = TakeNextId(); - check_label = NewLabel(check_label_id); - skip_label_id = TakeNextId(); - skip_label = NewLabel(skip_label_id); - inst = builder.AddLoad(GetUintId(), error_var); - uint32_t error_val_id = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpIEqual, error_val_id, - zero_id); - uint32_t no_error_id = inst->result_id(); - (void)builder.AddConditionalBranch(no_error_id, check_label_id, skip_label_id, - skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(check_label)); - builder.SetInsertPoint(&*new_blk_ptr); - - { - const uint32_t desc_set_ptr_ptr_sb = type_mgr->FindPointerToType( - desc_set_ptr_id_, spv::StorageClass::StorageBuffer); - - inst = builder.AddAccessChain(desc_set_ptr_ptr_sb, input_buffer_id_, - {zero_id, param_ids[kDescSet]}); - const uint32_t set_access_chain_id = inst->result_id(); - - inst = builder.AddLoad(desc_set_ptr_id_, set_access_chain_id); - const uint32_t desc_set_ptr_id = inst->result_id(); - - builder.AddStore(desc_set_ptr_var, desc_set_ptr_id); - - inst = builder.AddUnaryOp(GetVecUintId(2), spv::Op::OpBitcast, - desc_set_ptr_id); - const uint32_t ptr_as_uvec_id = inst->result_id(); - - inst = builder.AddCompositeExtract(GetUintId(), ptr_as_uvec_id, {0}); - const uint32_t uvec_x = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpIEqual, uvec_x, zero_id); - const uint32_t x_is_zero_id = inst->result_id(); - - inst = builder.AddCompositeExtract(GetUintId(), ptr_as_uvec_id, {1}); - const uint32_t uvec_y = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpIEqual, uvec_y, zero_id); - const uint32_t y_is_zero_id = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpLogicalAnd, x_is_zero_id, - y_is_zero_id); - const uint32_t is_null_id = inst->result_id(); - - const uint32_t error_label_id = TakeNextId(); - auto error_label = NewLabel(error_label_id); - const uint32_t merge_label_id = TakeNextId(); - auto merge_label = NewLabel(merge_label_id); - (void)builder.AddConditionalBranch(is_null_id, error_label_id, - merge_label_id, merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - // set error - new_blk_ptr = MakeUnique(std::move(error_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddStore(error_var, - builder.GetUintConstantId(kInstErrorBindlessBounds)); - builder.AddBranch(merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(merge_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddBranch(skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - } - - new_blk_ptr = MakeUnique(std::move(skip_label)); - builder.SetInsertPoint(&*new_blk_ptr); - - check_label_id = TakeNextId(); - check_label = NewLabel(check_label_id); - skip_label_id = TakeNextId(); - skip_label = NewLabel(skip_label_id); - - inst = builder.AddLoad(GetUintId(), error_var); - error_val_id = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpIEqual, error_val_id, - zero_id); - no_error_id = inst->result_id(); - (void)builder.AddConditionalBranch(no_error_id, check_label_id, skip_label_id, - skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - // check binding is in range - new_blk_ptr = MakeUnique(std::move(check_label)); - builder.SetInsertPoint(&*new_blk_ptr); - { - inst = builder.AddLoad(desc_set_ptr_id_, desc_set_ptr_var); - const uint32_t desc_set_ptr_id = inst->result_id(); - - inst = builder.AddAccessChain(uint_ptr, desc_set_ptr_id, {zero_id}); - const uint32_t binding_access_chain_id = inst->result_id(); - - inst = builder.AddLoad(GetUintId(), binding_access_chain_id, 8); - const uint32_t num_bindings_id = inst->result_id(); - - builder.AddStore(num_bindings_var, num_bindings_id); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpUGreaterThanEqual, - param_ids[kDescBinding], num_bindings_id); - const uint32_t bindings_cmp_id = inst->result_id(); - - const uint32_t error_label_id = TakeNextId(); - auto error_label = NewLabel(error_label_id); - const uint32_t merge_label_id = TakeNextId(); - auto merge_label = NewLabel(merge_label_id); - (void)builder.AddConditionalBranch(bindings_cmp_id, error_label_id, - merge_label_id, merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - // set error - new_blk_ptr = MakeUnique(std::move(error_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddStore(error_var, - builder.GetUintConstantId(kInstErrorBindlessBounds)); - builder.AddBranch(merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(merge_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddBranch(skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - } - - // read binding length - new_blk_ptr = MakeUnique(std::move(skip_label)); - builder.SetInsertPoint(&*new_blk_ptr); - - check_label_id = TakeNextId(); - check_label = NewLabel(check_label_id); - skip_label_id = TakeNextId(); - skip_label = NewLabel(skip_label_id); - - inst = builder.AddLoad(GetUintId(), error_var); - error_val_id = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpIEqual, error_val_id, - zero_id); - no_error_id = inst->result_id(); - (void)builder.AddConditionalBranch(no_error_id, check_label_id, skip_label_id, - skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(check_label)); - builder.SetInsertPoint(&*new_blk_ptr); - { - inst = builder.AddLoad(desc_set_ptr_id_, desc_set_ptr_var); - const uint32_t desc_set_ptr_id = inst->result_id(); - - inst = builder.AddAccessChain( - uint_ptr, desc_set_ptr_id, - {{builder.GetUintConstantId(1), param_ids[kDescBinding]}}); - const uint32_t length_ac_id = inst->result_id(); - - inst = builder.AddLoad(GetUintId(), length_ac_id, sizeof(uint32_t)); - const uint32_t length_id = inst->result_id(); - - // Check descriptor index in bounds - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpUGreaterThanEqual, - param_ids[kDescIndex], length_id); - const uint32_t desc_idx_range_id = inst->result_id(); - - const uint32_t error_label_id = TakeNextId(); - auto error_label = NewLabel(error_label_id); - const uint32_t merge_label_id = TakeNextId(); - auto merge_label = NewLabel(merge_label_id); - (void)builder.AddConditionalBranch(desc_idx_range_id, error_label_id, - merge_label_id, merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - // set error - new_blk_ptr = MakeUnique(std::move(error_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddStore(error_var, - builder.GetUintConstantId(kInstErrorBindlessBounds)); - builder.AddStore(param5_var, length_id); - builder.AddBranch(merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(merge_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddBranch(skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - } - - new_blk_ptr = MakeUnique(std::move(skip_label)); - builder.SetInsertPoint(&*new_blk_ptr); - inst = builder.AddLoad(GetUintId(), error_var); - error_val_id = inst->result_id(); - - check_label_id = TakeNextId(); - check_label = NewLabel(check_label_id); - skip_label_id = TakeNextId(); - skip_label = NewLabel(skip_label_id); - - inst = builder.AddLoad(GetUintId(), error_var); - error_val_id = inst->result_id(); - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpIEqual, zero_id, - error_val_id); - no_error_id = inst->result_id(); - - (void)builder.AddConditionalBranch(no_error_id, check_label_id, skip_label_id, - skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - // Read descriptor init status - new_blk_ptr = MakeUnique(std::move(check_label)); - builder.SetInsertPoint(&*new_blk_ptr); - { - inst = builder.AddLoad(desc_set_ptr_id_, desc_set_ptr_var); - const uint32_t desc_set_ptr_id = inst->result_id(); - - inst = builder.AddLoad(GetUintId(), num_bindings_var); - const uint32_t num_bindings_id = inst->result_id(); - - inst = - builder.AddIAdd(GetUintId(), num_bindings_id, param_ids[kDescBinding]); - const uint32_t state_offset_id = inst->result_id(); - - inst = builder.AddAccessChain( - uint_ptr, desc_set_ptr_id, - {{builder.GetUintConstantId(1), state_offset_id}}); - const uint32_t state_start_ac_id = inst->result_id(); - - inst = builder.AddLoad(GetUintId(), state_start_ac_id, sizeof(uint32_t)); - const uint32_t state_start_id = inst->result_id(); - - inst = builder.AddIAdd(GetUintId(), state_start_id, param_ids[kDescIndex]); - const uint32_t state_entry_id = inst->result_id(); - - // Note: length starts from the beginning of the buffer, not the beginning - // of the data array - inst = builder.AddAccessChain( - uint_ptr, desc_set_ptr_id, - {{builder.GetUintConstantId(1), state_entry_id}}); - const uint32_t init_ac_id = inst->result_id(); - - inst = builder.AddLoad(GetUintId(), init_ac_id, sizeof(uint32_t)); - const uint32_t init_status_id = inst->result_id(); - - builder.AddStore(init_status_var, init_status_id); - - // Check for uninitialized descriptor - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpIEqual, init_status_id, - zero_id); - const uint32_t uninit_check_id = inst->result_id(); - const uint32_t error_label_id = TakeNextId(); - auto error_label = NewLabel(error_label_id); - const uint32_t merge_label_id = TakeNextId(); - auto merge_label = NewLabel(merge_label_id); - (void)builder.AddConditionalBranch(uninit_check_id, error_label_id, - merge_label_id, merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - new_blk_ptr = MakeUnique(std::move(error_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddStore(error_var, - builder.GetUintConstantId(kInstErrorBindlessUninit)); - builder.AddBranch(merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(merge_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddBranch(skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - } - - // Check for OOB. - new_blk_ptr = MakeUnique(std::move(skip_label)); - builder.SetInsertPoint(&*new_blk_ptr); - - check_label_id = TakeNextId(); - check_label = NewLabel(check_label_id); - skip_label_id = TakeNextId(); - skip_label = NewLabel(skip_label_id); - - inst = builder.AddLoad(GetUintId(), error_var); - error_val_id = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpIEqual, error_val_id, - zero_id); - no_error_id = inst->result_id(); - (void)builder.AddConditionalBranch(no_error_id, check_label_id, skip_label_id, - skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(check_label)); - builder.SetInsertPoint(&*new_blk_ptr); - { - inst = builder.AddLoad(GetUintId(), init_status_var); - const uint32_t init_status_id = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpUGreaterThanEqual, - param_ids[kByteOffset], init_status_id); - const uint32_t buf_offset_range_id = inst->result_id(); - - const uint32_t error_label_id = TakeNextId(); - const uint32_t merge_label_id = TakeNextId(); - auto error_label = NewLabel(error_label_id); - auto merge_label = NewLabel(merge_label_id); - (void)builder.AddConditionalBranch(buf_offset_range_id, error_label_id, - merge_label_id, merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - // set error - new_blk_ptr = MakeUnique(std::move(error_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddStore(error_var, builder.GetUintConstantId(kInstErrorOOB)); - builder.AddStore(param5_var, param_ids[kByteOffset]); - builder.AddStore(param6_var, init_status_id); - builder.AddBranch(merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(merge_label)); - builder.SetInsertPoint(&*new_blk_ptr); - builder.AddBranch(skip_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - } - - // check for error - new_blk_ptr = MakeUnique(std::move(skip_label)); - builder.SetInsertPoint(&*new_blk_ptr); - inst = builder.AddLoad(GetUintId(), error_var); - error_val_id = inst->result_id(); - - inst = builder.AddBinaryOp(GetBoolId(), spv::Op::OpINotEqual, zero_id, - error_val_id); - const uint32_t is_error_id = inst->result_id(); - - const uint32_t error_label_id = TakeNextId(); - auto error_label = NewLabel(error_label_id); - const uint32_t merge_label_id = TakeNextId(); - auto merge_label = NewLabel(merge_label_id); - (void)builder.AddConditionalBranch(is_error_id, error_label_id, - merge_label_id, merge_label_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - new_blk_ptr = MakeUnique(std::move(error_label)); - builder.SetInsertPoint(&*new_blk_ptr); - - // error output - inst = builder.AddLoad(GetUintId(), param5_var); - const uint32_t param5_val_id = inst->result_id(); - - inst = builder.AddLoad(GetUintId(), param6_var); - const uint32_t param6_val_id = inst->result_id(); - - GenDebugStreamWrite( - param_ids[kShaderId], param_ids[kInstructionIndex], param_ids[kStageInfo], - {error_val_id, param_ids[kDescSet], param_ids[kDescBinding], - param_ids[kDescIndex], param5_val_id, param6_val_id}, - &builder); - (void)builder.AddUnaryOp(0, spv::Op::OpReturnValue, false_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - - // Success return - new_blk_ptr = MakeUnique(std::move(merge_label)); - builder.SetInsertPoint(&*new_blk_ptr); - (void)builder.AddUnaryOp(0, spv::Op::OpReturnValue, true_id); - func->AddBasicBlock(std::move(new_blk_ptr)); - func->SetFunctionEnd(EndFunction()); - context()->AddFunction(std::move(func)); - context()->AddDebug2Inst(NewGlobalName(func_id, "desc_check")); + static const std::string func_name{"inst_bindless_check_desc"}; + context()->AddFunctionDeclaration(std::move(func)); + context()->AddDebug2Inst(NewName(func_id, func_name)); + std::vector operands{ + {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {func_id}}, + {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, + {uint32_t(spv::Decoration::LinkageAttributes)}}, + {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_STRING, + utils::MakeVector(func_name.c_str())}, + {spv_operand_type_t::SPV_OPERAND_TYPE_LINKAGE_TYPE, + {uint32_t(spv::LinkageType::Import)}}, + }; + get_decoration_mgr()->AddDecoration(spv::Op::OpDecorate, operands); - desc_check_func_id_ = func_id; + check_desc_func_id_ = func_id; // Make sure function doesn't get processed by // InstrumentPass::InstProcessCallTreeFromRoots() param2output_func_id_[3] = func_id; - return desc_check_func_id_; + return check_desc_func_id_; } // clang-format off // GLSL: -// result = inst_bindless_desc_check(shader_id, inst_idx, stage_info, desc_set, binding, desc_idx, offset); +// result = inst_bindless_check_desc(shader_id, inst_idx, stage_info, desc_set, binding, desc_idx, offset); // // clang-format on uint32_t InstBindlessCheckPass::GenDescCheckCall( @@ -1134,8 +573,7 @@ uint32_t InstBindlessCheckPass::GenLastByteIdx(RefAnalysis* ref, } void InstBindlessCheckPass::GenCheckCode( - uint32_t check_id, uint32_t error_id, uint32_t offset_id, - uint32_t length_id, uint32_t stage_idx, RefAnalysis* ref, + uint32_t check_id, RefAnalysis* ref, std::vector>* new_blocks) { BasicBlock* back_blk_ptr = &*new_blocks->back(); InstructionBuilder builder( @@ -1164,31 +602,7 @@ void InstBindlessCheckPass::GenCheckCode( // Gen invalid block new_blk_ptr.reset(new BasicBlock(std::move(invalid_label))); builder.SetInsertPoint(&*new_blk_ptr); - if (error_id != 0) { - const uint32_t u_shader_id = builder.GetUintConstantId(shader_id_); - const uint32_t u_inst_id = - builder.GetUintConstantId(ref->ref_inst->unique_id()); - const uint32_t shader_info_id = GenStageInfo(stage_idx, &builder); - const uint32_t u_set_id = builder.GetUintConstantId(ref->set); - const uint32_t u_binding_id = builder.GetUintConstantId(ref->binding); - const uint32_t u_index_id = GenUintCastCode(ref->desc_idx_id, &builder); - const uint32_t u_length_id = GenUintCastCode(length_id, &builder); - if (offset_id != 0) { - const uint32_t u_offset_id = GenUintCastCode(offset_id, &builder); - // Buffer OOB - GenDebugStreamWrite(u_shader_id, u_inst_id, shader_info_id, - {error_id, u_set_id, u_binding_id, u_index_id, - u_offset_id, u_length_id}, - &builder); - } else { - // Uninitialized Descriptor - Return additional unused zero so all error - // modes will use same debug stream write function - GenDebugStreamWrite(u_shader_id, u_inst_id, shader_info_id, - {error_id, u_set_id, u_binding_id, u_index_id, - u_length_id, builder.GetUintConstantId(0)}, - &builder); - } - } + // Generate a ConstantNull, converting to uint64 if the type cannot be a null. if (new_ref_id != 0) { analysis::TypeManager* type_mgr = context()->get_type_mgr(); @@ -1283,7 +697,7 @@ void InstBindlessCheckPass::GenDescCheckCode( // Generate runtime initialization/bounds test code with true branch // being full reference and false branch being zero // for the referenced value. - GenCheckCode(check_id, 0, 0, 0, stage_idx, &ref, new_blocks); + GenCheckCode(check_id, &ref, new_blocks); // Move original block's remaining code into remainder/merge block and add // to new blocks @@ -1311,6 +725,20 @@ void InstBindlessCheckPass::InitializeInstBindlessCheck() { Pass::Status InstBindlessCheckPass::ProcessImpl() { bool modified = false; + // The memory model and linkage must always be updated for spirv-link to work + // correctly. + AddStorageBufferExt(); + if (!get_feature_mgr()->HasExtension(kSPV_KHR_physical_storage_buffer)) { + context()->AddExtension("SPV_KHR_physical_storage_buffer"); + } + + context()->AddCapability(spv::Capability::PhysicalStorageBufferAddresses); + Instruction* memory_model = get_module()->GetMemoryModel(); + memory_model->SetInOperand( + 0u, {uint32_t(spv::AddressingModel::PhysicalStorageBuffer64)}); + + context()->AddCapability(spv::Capability::Linkage); + InstProcessFunction pfn = [this](BasicBlock::iterator ref_inst_itr, UptrVectorIterator ref_block_itr, uint32_t stage_idx, diff --git a/source/opt/inst_bindless_check_pass.h b/source/opt/inst_bindless_check_pass.h index 289f02f1a..f99b59d0a 100644 --- a/source/opt/inst_bindless_check_pass.h +++ b/source/opt/inst_bindless_check_pass.h @@ -28,8 +28,8 @@ namespace opt { // external design may change as the layer evolves. class InstBindlessCheckPass : public InstrumentPass { public: - InstBindlessCheckPass(uint32_t desc_set, uint32_t shader_id) - : InstrumentPass(desc_set, shader_id, kInstValidationIdBindless, true) {} + InstBindlessCheckPass(uint32_t shader_id) + : InstrumentPass(0, shader_id, true) {} ~InstBindlessCheckPass() override = default; @@ -44,8 +44,6 @@ class InstBindlessCheckPass : public InstrumentPass { uint32_t stage_idx, std::vector>* new_blocks); - void SetupInputBufferIds(); - uint32_t GenDescCheckFunctionId(); uint32_t GenDescCheckCall(uint32_t inst_idx, uint32_t stage_idx, @@ -107,8 +105,7 @@ class InstBindlessCheckPass : public InstrumentPass { // writes debug error output utilizing |ref|, |error_id|, |length_id| and // |stage_idx|. Generate merge block for valid and invalid branches. Kill // original reference. - void GenCheckCode(uint32_t check_id, uint32_t error_id, uint32_t offset_id, - uint32_t length_id, uint32_t stage_idx, RefAnalysis* ref, + void GenCheckCode(uint32_t check_id, RefAnalysis* ref, std::vector>* new_blocks); // Initialize state for instrumenting bindless checking @@ -124,11 +121,7 @@ class InstBindlessCheckPass : public InstrumentPass { // Mapping from variable to binding std::unordered_map var2binding_; - uint32_t desc_check_func_id_{0}; - uint32_t desc_set_type_id_{0}; - uint32_t desc_set_ptr_id_{0}; - uint32_t input_buffer_struct_id_{0}; - uint32_t input_buffer_ptr_id_{0}; + uint32_t check_desc_func_id_{0}; }; } // namespace opt diff --git a/source/opt/inst_buff_addr_check_pass.cpp b/source/opt/inst_buff_addr_check_pass.cpp index 6b90e5888..e1fde7713 100644 --- a/source/opt/inst_buff_addr_check_pass.cpp +++ b/source/opt/inst_buff_addr_check_pass.cpp @@ -19,24 +19,6 @@ namespace spvtools { namespace opt { -bool InstBuffAddrCheckPass::InstrumentFunction(Function* func, - uint32_t stage_idx, - InstProcessFunction& pfn) { - // The bindless instrumentation pass adds functions that use - // BufferDeviceAddress They should not be instrumented by this pass. - Instruction* func_name_inst = - context()->GetNames(func->DefInst().result_id()).begin()->second; - if (func_name_inst) { - static const std::string kPrefix{"inst_bindless_"}; - std::string func_name = func_name_inst->GetOperand(1).AsString(); - if (func_name.size() >= kPrefix.size() && - func_name.compare(0, kPrefix.size(), kPrefix) == 0) { - return false; - } - } - return InstrumentPass::InstrumentFunction(func, stage_idx, pfn); -} - uint32_t InstBuffAddrCheckPass::CloneOriginalReference( Instruction* ref_inst, InstructionBuilder* builder) { // Clone original ref with new result id (if load) @@ -76,8 +58,7 @@ bool InstBuffAddrCheckPass::IsPhysicalBuffAddrReference(Instruction* ref_inst) { // TODO(greg-lunarg): Refactor with InstBindlessCheckPass::GenCheckCode() ?? void InstBuffAddrCheckPass::GenCheckCode( - uint32_t check_id, uint32_t error_id, uint32_t ref_uptr_id, - uint32_t stage_idx, Instruction* ref_inst, + uint32_t check_id, Instruction* ref_inst, std::vector>* new_blocks) { BasicBlock* back_blk_ptr = &*new_blocks->back(); InstructionBuilder builder( @@ -104,20 +85,6 @@ void InstBuffAddrCheckPass::GenCheckCode( // Gen invalid block new_blk_ptr.reset(new BasicBlock(std::move(invalid_label))); builder.SetInsertPoint(&*new_blk_ptr); - // Convert uptr from uint64 to 2 uint32 - Instruction* lo_uptr_inst = - builder.AddUnaryOp(GetUintId(), spv::Op::OpUConvert, ref_uptr_id); - Instruction* rshift_uptr_inst = - builder.AddBinaryOp(GetUint64Id(), spv::Op::OpShiftRightLogical, - ref_uptr_id, builder.GetUintConstantId(32)); - Instruction* hi_uptr_inst = builder.AddUnaryOp( - GetUintId(), spv::Op::OpUConvert, rshift_uptr_inst->result_id()); - GenDebugStreamWrite( - builder.GetUintConstantId(shader_id_), - builder.GetUintConstantId(uid2offset_[ref_inst->unique_id()]), - GenStageInfo(stage_idx, &builder), - {error_id, lo_uptr_inst->result_id(), hi_uptr_inst->result_id()}, - &builder); // Gen zero for invalid load. If pointer type, need to convert uint64 // zero to pointer; cannot create ConstantNull of pointer type. uint32_t null_id = 0; @@ -206,201 +173,86 @@ void InstBuffAddrCheckPass::AddParam(uint32_t type_id, (*input_func)->AddParameter(std::move(param_inst)); } +// This is a stub function for use with Import linkage +// clang-format off +// GLSL: +//bool inst_bindless_search_and_test(const uint shader_id, const uint inst_num, const uvec4 stage_info, +// const uint64 ref_ptr, const uint length) { +//} +// clang-format on uint32_t InstBuffAddrCheckPass::GetSearchAndTestFuncId() { - if (search_test_func_id_ == 0) { - // Generate function "bool search_and_test(uint64_t ref_ptr, uint32_t len)" - // which searches input buffer for buffer which most likely contains the - // pointer value |ref_ptr| and verifies that the entire reference of - // length |len| bytes is contained in the buffer. - search_test_func_id_ = TakeNextId(); - analysis::TypeManager* type_mgr = context()->get_type_mgr(); - std::vector param_types = { - type_mgr->GetType(GetUint64Id()), type_mgr->GetType(GetUintId())}; - analysis::Function func_ty(type_mgr->GetType(GetBoolId()), param_types); - analysis::Type* reg_func_ty = type_mgr->GetRegisteredType(&func_ty); - std::unique_ptr func_inst( - new Instruction(get_module()->context(), spv::Op::OpFunction, - GetBoolId(), search_test_func_id_, - {{spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, - {uint32_t(spv::FunctionControlMask::MaskNone)}}, - {spv_operand_type_t::SPV_OPERAND_TYPE_ID, - {type_mgr->GetTypeInstruction(reg_func_ty)}}})); - get_def_use_mgr()->AnalyzeInstDefUse(&*func_inst); - std::unique_ptr input_func = - MakeUnique(std::move(func_inst)); - std::vector param_vec; - // Add ref_ptr and length parameters - AddParam(GetUint64Id(), ¶m_vec, &input_func); - AddParam(GetUintId(), ¶m_vec, &input_func); - // Empty first block. - uint32_t first_blk_id = TakeNextId(); - std::unique_ptr first_blk_label(NewLabel(first_blk_id)); - std::unique_ptr first_blk_ptr = - MakeUnique(std::move(first_blk_label)); - InstructionBuilder builder( - context(), &*first_blk_ptr, - IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping); - uint32_t hdr_blk_id = TakeNextId(); - // Branch to search loop header - std::unique_ptr hdr_blk_label(NewLabel(hdr_blk_id)); - (void)builder.AddBranch(hdr_blk_id); - input_func->AddBasicBlock(std::move(first_blk_ptr)); - // Linear search loop header block - // TODO(greg-lunarg): Implement binary search - std::unique_ptr hdr_blk_ptr = - MakeUnique(std::move(hdr_blk_label)); - builder.SetInsertPoint(&*hdr_blk_ptr); - // Phi for search index. Starts with 1. - uint32_t cont_blk_id = TakeNextId(); - std::unique_ptr cont_blk_label(NewLabel(cont_blk_id)); - // Deal with def-use cycle caused by search loop index computation. - // Create Add and Phi instructions first, then do Def analysis on Add. - // Add Phi and Add instructions and do Use analysis later. - uint32_t idx_phi_id = TakeNextId(); - uint32_t idx_inc_id = TakeNextId(); - std::unique_ptr idx_inc_inst(new Instruction( - context(), spv::Op::OpIAdd, GetUintId(), idx_inc_id, - {{spv_operand_type_t::SPV_OPERAND_TYPE_ID, {idx_phi_id}}, - {spv_operand_type_t::SPV_OPERAND_TYPE_ID, - {builder.GetUintConstantId(1u)}}})); - std::unique_ptr idx_phi_inst(new Instruction( - context(), spv::Op::OpPhi, GetUintId(), idx_phi_id, - {{spv_operand_type_t::SPV_OPERAND_TYPE_ID, - {builder.GetUintConstantId(1u)}}, - {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {first_blk_id}}, - {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {idx_inc_id}}, - {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {cont_blk_id}}})); - get_def_use_mgr()->AnalyzeInstDef(&*idx_inc_inst); - // Add (previously created) search index phi - (void)builder.AddInstruction(std::move(idx_phi_inst)); - // LoopMerge - uint32_t bound_test_blk_id = TakeNextId(); - std::unique_ptr bound_test_blk_label( - NewLabel(bound_test_blk_id)); - (void)builder.AddLoopMerge(bound_test_blk_id, cont_blk_id, - uint32_t(spv::LoopControlMask::MaskNone)); - // Branch to continue/work block - (void)builder.AddBranch(cont_blk_id); - input_func->AddBasicBlock(std::move(hdr_blk_ptr)); - // Continue/Work Block. Read next buffer pointer and break if greater - // than ref_ptr arg. - std::unique_ptr cont_blk_ptr = - MakeUnique(std::move(cont_blk_label)); - builder.SetInsertPoint(&*cont_blk_ptr); - // Add (previously created) search index increment now. - (void)builder.AddInstruction(std::move(idx_inc_inst)); - // Load next buffer address from debug input buffer - uint32_t ibuf_id = GetInputBufferId(); - uint32_t ibuf_ptr_id = GetInputBufferPtrId(); - Instruction* uptr_ac_inst = builder.AddTernaryOp( - ibuf_ptr_id, spv::Op::OpAccessChain, ibuf_id, - builder.GetUintConstantId(kDebugInputDataOffset), idx_inc_id); - uint32_t ibuf_type_id = GetInputBufferTypeId(); - Instruction* uptr_load_inst = builder.AddUnaryOp( - ibuf_type_id, spv::Op::OpLoad, uptr_ac_inst->result_id()); - // If loaded address greater than ref_ptr arg, break, else branch back to - // loop header - Instruction* uptr_test_inst = - builder.AddBinaryOp(GetBoolId(), spv::Op::OpUGreaterThan, - uptr_load_inst->result_id(), param_vec[0]); - (void)builder.AddConditionalBranch( - uptr_test_inst->result_id(), bound_test_blk_id, hdr_blk_id, kInvalidId, - uint32_t(spv::SelectionControlMask::MaskNone)); - input_func->AddBasicBlock(std::move(cont_blk_ptr)); - // Bounds test block. Read length of selected buffer and test that - // all len arg bytes are in buffer. - std::unique_ptr bound_test_blk_ptr = - MakeUnique(std::move(bound_test_blk_label)); - builder.SetInsertPoint(&*bound_test_blk_ptr); - // Decrement index to point to previous/candidate buffer address - Instruction* cand_idx_inst = - builder.AddBinaryOp(GetUintId(), spv::Op::OpISub, idx_inc_id, - builder.GetUintConstantId(1u)); - // Load candidate buffer address - Instruction* cand_ac_inst = - builder.AddTernaryOp(ibuf_ptr_id, spv::Op::OpAccessChain, ibuf_id, - builder.GetUintConstantId(kDebugInputDataOffset), - cand_idx_inst->result_id()); - Instruction* cand_load_inst = builder.AddUnaryOp( - ibuf_type_id, spv::Op::OpLoad, cand_ac_inst->result_id()); - // Compute offset of ref_ptr from candidate buffer address - Instruction* offset_inst = - builder.AddBinaryOp(ibuf_type_id, spv::Op::OpISub, param_vec[0], - cand_load_inst->result_id()); - // Convert ref length to uint64 - Instruction* ref_len_64_inst = - builder.AddUnaryOp(ibuf_type_id, spv::Op::OpUConvert, param_vec[1]); - // Add ref length to ref offset to compute end of reference - Instruction* ref_end_inst = builder.AddBinaryOp( - ibuf_type_id, spv::Op::OpIAdd, offset_inst->result_id(), - ref_len_64_inst->result_id()); - // Load starting index of lengths in input buffer and convert to uint32 - Instruction* len_start_ac_inst = - builder.AddTernaryOp(ibuf_ptr_id, spv::Op::OpAccessChain, ibuf_id, - builder.GetUintConstantId(kDebugInputDataOffset), - builder.GetUintConstantId(0u)); - Instruction* len_start_load_inst = builder.AddUnaryOp( - ibuf_type_id, spv::Op::OpLoad, len_start_ac_inst->result_id()); - Instruction* len_start_32_inst = builder.AddUnaryOp( - GetUintId(), spv::Op::OpUConvert, len_start_load_inst->result_id()); - // Decrement search index to get candidate buffer length index - Instruction* cand_len_idx_inst = builder.AddBinaryOp( - GetUintId(), spv::Op::OpISub, cand_idx_inst->result_id(), - builder.GetUintConstantId(1u)); - // Add candidate length index to start index - Instruction* len_idx_inst = builder.AddBinaryOp( - GetUintId(), spv::Op::OpIAdd, cand_len_idx_inst->result_id(), - len_start_32_inst->result_id()); - // Load candidate buffer length - Instruction* len_ac_inst = - builder.AddTernaryOp(ibuf_ptr_id, spv::Op::OpAccessChain, ibuf_id, - builder.GetUintConstantId(kDebugInputDataOffset), - len_idx_inst->result_id()); - Instruction* len_load_inst = builder.AddUnaryOp( - ibuf_type_id, spv::Op::OpLoad, len_ac_inst->result_id()); - // Test if reference end within candidate buffer length - Instruction* len_test_inst = builder.AddBinaryOp( - GetBoolId(), spv::Op::OpULessThanEqual, ref_end_inst->result_id(), - len_load_inst->result_id()); - // Return test result - (void)builder.AddUnaryOp(0, spv::Op::OpReturnValue, - len_test_inst->result_id()); - // Close block - input_func->AddBasicBlock(std::move(bound_test_blk_ptr)); - // Close function and add function to module - std::unique_ptr func_end_inst(new Instruction( - get_module()->context(), spv::Op::OpFunctionEnd, 0, 0, {})); - get_def_use_mgr()->AnalyzeInstDefUse(&*func_end_inst); - input_func->SetFunctionEnd(std::move(func_end_inst)); - context()->AddFunction(std::move(input_func)); - context()->AddDebug2Inst( - NewGlobalName(search_test_func_id_, "search_and_test")); + enum { + kShaderId = 0, + kInstructionIndex = 1, + kStageInfo = 2, + kRefPtr = 3, + kLength = 4, + kNumArgs + }; + if (search_test_func_id_ != 0) { + return search_test_func_id_; } + // Generate function "bool search_and_test(uint64_t ref_ptr, uint32_t len)" + // which searches input buffer for buffer which most likely contains the + // pointer value |ref_ptr| and verifies that the entire reference of + // length |len| bytes is contained in the buffer. + analysis::TypeManager* type_mgr = context()->get_type_mgr(); + const analysis::Integer* uint_type = GetInteger(32, false); + const analysis::Vector v4uint(uint_type, 4); + const analysis::Type* v4uint_type = type_mgr->GetRegisteredType(&v4uint); + + std::vector param_types = { + uint_type, uint_type, v4uint_type, type_mgr->GetType(GetUint64Id()), + uint_type}; + + const std::string func_name{"inst_buff_addr_search_and_test"}; + const uint32_t func_id = TakeNextId(); + std::unique_ptr func = + StartFunction(func_id, type_mgr->GetBoolType(), param_types); + func->SetFunctionEnd(EndFunction()); + context()->AddFunctionDeclaration(std::move(func)); + context()->AddDebug2Inst(NewName(func_id, func_name)); + + std::vector operands{ + {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {func_id}}, + {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, + {uint32_t(spv::Decoration::LinkageAttributes)}}, + {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_STRING, + utils::MakeVector(func_name.c_str())}, + {spv_operand_type_t::SPV_OPERAND_TYPE_LINKAGE_TYPE, + {uint32_t(spv::LinkageType::Import)}}, + }; + get_decoration_mgr()->AddDecoration(spv::Op::OpDecorate, operands); + + search_test_func_id_ = func_id; return search_test_func_id_; } uint32_t InstBuffAddrCheckPass::GenSearchAndTest(Instruction* ref_inst, InstructionBuilder* builder, - uint32_t* ref_uptr_id) { + uint32_t* ref_uptr_id, + uint32_t stage_idx) { // Enable Int64 if necessary - context()->AddCapability(spv::Capability::Int64); // Convert reference pointer to uint64 - uint32_t ref_ptr_id = ref_inst->GetSingleWordInOperand(0); + const uint32_t ref_ptr_id = ref_inst->GetSingleWordInOperand(0); Instruction* ref_uptr_inst = builder->AddUnaryOp(GetUint64Id(), spv::Op::OpConvertPtrToU, ref_ptr_id); *ref_uptr_id = ref_uptr_inst->result_id(); // Compute reference length in bytes analysis::DefUseManager* du_mgr = get_def_use_mgr(); Instruction* ref_ptr_inst = du_mgr->GetDef(ref_ptr_id); - uint32_t ref_ptr_ty_id = ref_ptr_inst->type_id(); + const uint32_t ref_ptr_ty_id = ref_ptr_inst->type_id(); Instruction* ref_ptr_ty_inst = du_mgr->GetDef(ref_ptr_ty_id); - uint32_t ref_len = GetTypeLength(ref_ptr_ty_inst->GetSingleWordInOperand(1)); - uint32_t ref_len_id = builder->GetUintConstantId(ref_len); + const uint32_t ref_len = + GetTypeLength(ref_ptr_ty_inst->GetSingleWordInOperand(1)); // Gen call to search and test function - Instruction* call_inst = builder->AddFunctionCall( - GetBoolId(), GetSearchAndTestFuncId(), {*ref_uptr_id, ref_len_id}); - uint32_t retval = call_inst->result_id(); - return retval; + const uint32_t func_id = GetSearchAndTestFuncId(); + const std::vector args = { + builder->GetUintConstantId(shader_id_), + builder->GetUintConstantId(ref_inst->unique_id()), + GenStageInfo(stage_idx, builder), *ref_uptr_id, + builder->GetUintConstantId(ref_len)}; + return GenReadFunctionCall(GetBoolId(), func_id, args, builder); } void InstBuffAddrCheckPass::GenBuffAddrCheckCode( @@ -418,16 +270,16 @@ void InstBuffAddrCheckPass::GenBuffAddrCheckCode( context(), &*new_blk_ptr, IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping); new_blocks->push_back(std::move(new_blk_ptr)); - uint32_t error_id = builder.GetUintConstantId(kInstErrorBuffAddrUnallocRef); // Generate code to do search and test if all bytes of reference // are within a listed buffer. Return reference pointer converted to uint64. uint32_t ref_uptr_id; - uint32_t valid_id = GenSearchAndTest(ref_inst, &builder, &ref_uptr_id); + uint32_t valid_id = + GenSearchAndTest(ref_inst, &builder, &ref_uptr_id, stage_idx); // Generate test of search results with true branch // being full reference and false branch being debug output and zero // for the referenced value. - GenCheckCode(valid_id, error_id, ref_uptr_id, stage_idx, ref_inst, - new_blocks); + GenCheckCode(valid_id, ref_inst, new_blocks); + // Move original block's remaining code into remainder/merge block and add // to new blocks BasicBlock* back_blk_ptr = &*new_blocks->back(); @@ -442,6 +294,15 @@ void InstBuffAddrCheckPass::InitInstBuffAddrCheck() { } Pass::Status InstBuffAddrCheckPass::ProcessImpl() { + // The memory model and linkage must always be updated for spirv-link to work + // correctly. + AddStorageBufferExt(); + if (!get_feature_mgr()->HasExtension(kSPV_KHR_physical_storage_buffer)) { + context()->AddExtension("SPV_KHR_physical_storage_buffer"); + } + + context()->AddCapability(spv::Capability::Int64); + context()->AddCapability(spv::Capability::Linkage); // Perform bindless bounds check on each entry point function in module InstProcessFunction pfn = [this](BasicBlock::iterator ref_inst_itr, diff --git a/source/opt/inst_buff_addr_check_pass.h b/source/opt/inst_buff_addr_check_pass.h index 9c4b3ed9a..70076a371 100644 --- a/source/opt/inst_buff_addr_check_pass.h +++ b/source/opt/inst_buff_addr_check_pass.h @@ -29,10 +29,9 @@ namespace opt { class InstBuffAddrCheckPass : public InstrumentPass { public: // For test harness only - InstBuffAddrCheckPass() : InstrumentPass(7, 23, kInstValidationIdBuffAddr) {} + InstBuffAddrCheckPass() : InstrumentPass(0, 23) {} // For all other interfaces - InstBuffAddrCheckPass(uint32_t desc_set, uint32_t shader_id) - : InstrumentPass(desc_set, shader_id, kInstValidationIdBuffAddr) {} + InstBuffAddrCheckPass(uint32_t shader_id) : InstrumentPass(0, shader_id) {} ~InstBuffAddrCheckPass() override = default; @@ -41,9 +40,6 @@ class InstBuffAddrCheckPass : public InstrumentPass { const char* name() const override { return "inst-buff-addr-check-pass"; } - bool InstrumentFunction(Function* func, uint32_t stage_idx, - InstProcessFunction& pfn) override; - private: // Return byte length of type |type_id|. Must be int, float, vector, matrix, // struct, array or physical pointer. Uses std430 alignment and sizes. @@ -61,7 +57,7 @@ class InstBuffAddrCheckPass : public InstrumentPass { // are within the buffer. Returns id of boolean value which is true if // search and test is successful, false otherwise. uint32_t GenSearchAndTest(Instruction* ref_inst, InstructionBuilder* builder, - uint32_t* ref_uptr_id); + uint32_t* ref_uptr_id, uint32_t stage_idx); // This function does checking instrumentation on a single // instruction which references through a physical storage buffer address. @@ -114,8 +110,7 @@ class InstBuffAddrCheckPass : public InstrumentPass { // writes debug error output utilizing |ref_inst|, |error_id| and // |stage_idx|. Generate merge block for valid and invalid reference blocks. // Kill original reference. - void GenCheckCode(uint32_t check_id, uint32_t error_id, uint32_t length_id, - uint32_t stage_idx, Instruction* ref_inst, + void GenCheckCode(uint32_t check_id, Instruction* ref_inst, std::vector>* new_blocks); // Initialize state for instrumenting physical buffer address checking diff --git a/source/opt/inst_debug_printf_pass.cpp b/source/opt/inst_debug_printf_pass.cpp index f7c227455..a48a28f6b 100644 --- a/source/opt/inst_debug_printf_pass.cpp +++ b/source/opt/inst_debug_printf_pass.cpp @@ -16,6 +16,7 @@ #include "inst_debug_printf_pass.h" +#include "source/spirv_constant.h" #include "source/util/string_utils.h" #include "spirv/unified1/NonSemanticDebugPrintf.h" @@ -210,9 +211,244 @@ void InstDebugPrintfPass::GenDebugPrintfCode( new_blocks->push_back(std::move(new_blk_ptr)); } +// Return id for output buffer +uint32_t InstDebugPrintfPass::GetOutputBufferId() { + if (output_buffer_id_ == 0) { + // If not created yet, create one + analysis::DecorationManager* deco_mgr = get_decoration_mgr(); + analysis::TypeManager* type_mgr = context()->get_type_mgr(); + analysis::RuntimeArray* reg_uint_rarr_ty = GetUintRuntimeArrayType(32); + analysis::Integer* reg_uint_ty = GetInteger(32, false); + analysis::Type* reg_buf_ty = + GetStruct({reg_uint_ty, reg_uint_ty, reg_uint_rarr_ty}); + uint32_t obufTyId = type_mgr->GetTypeInstruction(reg_buf_ty); + // By the Vulkan spec, a pre-existing struct containing a RuntimeArray + // must be a block, and will therefore be decorated with Block. Therefore + // the undecorated type returned here will not be pre-existing and can + // safely be decorated. Since this type is now decorated, it is out of + // sync with the TypeManager and therefore the TypeManager must be + // invalidated after this pass. + assert(context()->get_def_use_mgr()->NumUses(obufTyId) == 0 && + "used struct type returned"); + deco_mgr->AddDecoration(obufTyId, uint32_t(spv::Decoration::Block)); + deco_mgr->AddMemberDecoration(obufTyId, kDebugOutputFlagsOffset, + uint32_t(spv::Decoration::Offset), 0); + deco_mgr->AddMemberDecoration(obufTyId, kDebugOutputSizeOffset, + uint32_t(spv::Decoration::Offset), 4); + deco_mgr->AddMemberDecoration(obufTyId, kDebugOutputDataOffset, + uint32_t(spv::Decoration::Offset), 8); + uint32_t obufTyPtrId_ = + type_mgr->FindPointerToType(obufTyId, spv::StorageClass::StorageBuffer); + output_buffer_id_ = TakeNextId(); + std::unique_ptr newVarOp(new Instruction( + context(), spv::Op::OpVariable, obufTyPtrId_, output_buffer_id_, + {{spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, + {uint32_t(spv::StorageClass::StorageBuffer)}}})); + context()->AddGlobalValue(std::move(newVarOp)); + context()->AddDebug2Inst(NewGlobalName(obufTyId, "OutputBuffer")); + context()->AddDebug2Inst(NewMemberName(obufTyId, 0, "flags")); + context()->AddDebug2Inst(NewMemberName(obufTyId, 1, "written_count")); + context()->AddDebug2Inst(NewMemberName(obufTyId, 2, "data")); + context()->AddDebug2Inst(NewGlobalName(output_buffer_id_, "output_buffer")); + deco_mgr->AddDecorationVal( + output_buffer_id_, uint32_t(spv::Decoration::DescriptorSet), desc_set_); + deco_mgr->AddDecorationVal(output_buffer_id_, + uint32_t(spv::Decoration::Binding), + GetOutputBufferBinding()); + AddStorageBufferExt(); + if (get_module()->version() >= SPV_SPIRV_VERSION_WORD(1, 4)) { + // Add the new buffer to all entry points. + for (auto& entry : get_module()->entry_points()) { + entry.AddOperand({SPV_OPERAND_TYPE_ID, {output_buffer_id_}}); + context()->AnalyzeUses(&entry); + } + } + } + return output_buffer_id_; +} + +uint32_t InstDebugPrintfPass::GetOutputBufferPtrId() { + if (output_buffer_ptr_id_ == 0) { + output_buffer_ptr_id_ = context()->get_type_mgr()->FindPointerToType( + GetUintId(), spv::StorageClass::StorageBuffer); + } + return output_buffer_ptr_id_; +} + +uint32_t InstDebugPrintfPass::GetOutputBufferBinding() { + return kDebugOutputPrintfStream; +} + +void InstDebugPrintfPass::GenDebugOutputFieldCode(uint32_t base_offset_id, + uint32_t field_offset, + uint32_t field_value_id, + InstructionBuilder* builder) { + // Cast value to 32-bit unsigned if necessary + uint32_t val_id = GenUintCastCode(field_value_id, builder); + // Store value + Instruction* data_idx_inst = builder->AddIAdd( + GetUintId(), base_offset_id, builder->GetUintConstantId(field_offset)); + uint32_t buf_id = GetOutputBufferId(); + uint32_t buf_uint_ptr_id = GetOutputBufferPtrId(); + Instruction* achain_inst = builder->AddAccessChain( + buf_uint_ptr_id, buf_id, + {builder->GetUintConstantId(kDebugOutputDataOffset), + data_idx_inst->result_id()}); + (void)builder->AddStore(achain_inst->result_id(), val_id); +} + +uint32_t InstDebugPrintfPass::GetStreamWriteFunctionId(uint32_t param_cnt) { + enum { + kShaderId = 0, + kInstructionIndex = 1, + kStageInfo = 2, + kFirstParam = 3, + }; + // Total param count is common params plus validation-specific + // params + if (param2output_func_id_[param_cnt] == 0) { + // Create function + param2output_func_id_[param_cnt] = TakeNextId(); + analysis::TypeManager* type_mgr = context()->get_type_mgr(); + + const analysis::Type* uint_type = GetInteger(32, false); + const analysis::Vector v4uint(uint_type, 4); + const analysis::Type* v4uint_type = type_mgr->GetRegisteredType(&v4uint); + + std::vector param_types(kFirstParam + param_cnt, + uint_type); + param_types[kStageInfo] = v4uint_type; + std::unique_ptr output_func = StartFunction( + param2output_func_id_[param_cnt], type_mgr->GetVoidType(), param_types); + + std::vector param_ids = AddParameters(*output_func, param_types); + + // Create first block + auto new_blk_ptr = MakeUnique(NewLabel(TakeNextId())); + + InstructionBuilder builder( + context(), &*new_blk_ptr, + IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping); + // Gen test if debug output buffer size will not be exceeded. + const uint32_t val_spec_offset = kInstStageOutCnt; + const uint32_t obuf_record_sz = val_spec_offset + param_cnt; + const uint32_t buf_id = GetOutputBufferId(); + const uint32_t buf_uint_ptr_id = GetOutputBufferPtrId(); + Instruction* obuf_curr_sz_ac_inst = builder.AddAccessChain( + buf_uint_ptr_id, buf_id, + {builder.GetUintConstantId(kDebugOutputSizeOffset)}); + // Fetch the current debug buffer written size atomically, adding the + // size of the record to be written. + uint32_t obuf_record_sz_id = builder.GetUintConstantId(obuf_record_sz); + uint32_t mask_none_id = + builder.GetUintConstantId(uint32_t(spv::MemoryAccessMask::MaskNone)); + uint32_t scope_invok_id = + builder.GetUintConstantId(uint32_t(spv::Scope::Invocation)); + Instruction* obuf_curr_sz_inst = builder.AddQuadOp( + GetUintId(), spv::Op::OpAtomicIAdd, obuf_curr_sz_ac_inst->result_id(), + scope_invok_id, mask_none_id, obuf_record_sz_id); + uint32_t obuf_curr_sz_id = obuf_curr_sz_inst->result_id(); + // Compute new written size + Instruction* obuf_new_sz_inst = + builder.AddIAdd(GetUintId(), obuf_curr_sz_id, + builder.GetUintConstantId(obuf_record_sz)); + // Fetch the data bound + Instruction* obuf_bnd_inst = + builder.AddIdLiteralOp(GetUintId(), spv::Op::OpArrayLength, + GetOutputBufferId(), kDebugOutputDataOffset); + // Test that new written size is less than or equal to debug output + // data bound + Instruction* obuf_safe_inst = builder.AddBinaryOp( + GetBoolId(), spv::Op::OpULessThanEqual, obuf_new_sz_inst->result_id(), + obuf_bnd_inst->result_id()); + uint32_t merge_blk_id = TakeNextId(); + uint32_t write_blk_id = TakeNextId(); + std::unique_ptr merge_label(NewLabel(merge_blk_id)); + std::unique_ptr write_label(NewLabel(write_blk_id)); + (void)builder.AddConditionalBranch( + obuf_safe_inst->result_id(), write_blk_id, merge_blk_id, merge_blk_id, + uint32_t(spv::SelectionControlMask::MaskNone)); + // Close safety test block and gen write block + output_func->AddBasicBlock(std::move(new_blk_ptr)); + new_blk_ptr = MakeUnique(std::move(write_label)); + builder.SetInsertPoint(&*new_blk_ptr); + // Generate common and stage-specific debug record members + GenDebugOutputFieldCode(obuf_curr_sz_id, kInstCommonOutSize, + builder.GetUintConstantId(obuf_record_sz), + &builder); + // Store Shader Id + GenDebugOutputFieldCode(obuf_curr_sz_id, kInstCommonOutShaderId, + param_ids[kShaderId], &builder); + // Store Instruction Idx + GenDebugOutputFieldCode(obuf_curr_sz_id, kInstCommonOutInstructionIdx, + param_ids[kInstructionIndex], &builder); + // Store stage info. Stage Idx + 3 words of stage-specific data. + for (uint32_t i = 0; i < 4; ++i) { + Instruction* field = + builder.AddCompositeExtract(GetUintId(), param_ids[kStageInfo], {i}); + GenDebugOutputFieldCode(obuf_curr_sz_id, kInstCommonOutStageIdx + i, + field->result_id(), &builder); + } + // Gen writes of validation specific data + for (uint32_t i = 0; i < param_cnt; ++i) { + GenDebugOutputFieldCode(obuf_curr_sz_id, val_spec_offset + i, + param_ids[kFirstParam + i], &builder); + } + // Close write block and gen merge block + (void)builder.AddBranch(merge_blk_id); + output_func->AddBasicBlock(std::move(new_blk_ptr)); + new_blk_ptr = MakeUnique(std::move(merge_label)); + builder.SetInsertPoint(&*new_blk_ptr); + // Close merge block and function and add function to module + (void)builder.AddNullaryOp(0, spv::Op::OpReturn); + + output_func->AddBasicBlock(std::move(new_blk_ptr)); + output_func->SetFunctionEnd(EndFunction()); + context()->AddFunction(std::move(output_func)); + + std::string name("stream_write_"); + name += std::to_string(param_cnt); + + context()->AddDebug2Inst( + NewGlobalName(param2output_func_id_[param_cnt], name)); + } + return param2output_func_id_[param_cnt]; +} + +void InstDebugPrintfPass::GenDebugStreamWrite( + uint32_t shader_id, uint32_t instruction_idx_id, uint32_t stage_info_id, + const std::vector& validation_ids, InstructionBuilder* builder) { + // Call debug output function. Pass func_idx, instruction_idx and + // validation ids as args. + uint32_t val_id_cnt = static_cast(validation_ids.size()); + std::vector args = {shader_id, instruction_idx_id, stage_info_id}; + (void)args.insert(args.end(), validation_ids.begin(), validation_ids.end()); + (void)builder->AddFunctionCall(GetVoidId(), + GetStreamWriteFunctionId(val_id_cnt), args); +} + +std::unique_ptr InstDebugPrintfPass::NewGlobalName( + uint32_t id, const std::string& name_str) { + std::string prefixed_name{"inst_printf_"}; + prefixed_name += name_str; + return NewName(id, prefixed_name); +} + +std::unique_ptr InstDebugPrintfPass::NewMemberName( + uint32_t id, uint32_t member_index, const std::string& name_str) { + return MakeUnique( + context(), spv::Op::OpMemberName, 0, 0, + std::initializer_list{ + {SPV_OPERAND_TYPE_ID, {id}}, + {SPV_OPERAND_TYPE_LITERAL_INTEGER, {member_index}}, + {SPV_OPERAND_TYPE_LITERAL_STRING, utils::MakeVector(name_str)}}); +} + void InstDebugPrintfPass::InitializeInstDebugPrintf() { // Initialize base class InitializeInstrument(); + output_buffer_id_ = 0; + output_buffer_ptr_id_ = 0; } Pass::Status InstDebugPrintfPass::ProcessImpl() { diff --git a/source/opt/inst_debug_printf_pass.h b/source/opt/inst_debug_printf_pass.h index 70b0a72bd..3a2078a7d 100644 --- a/source/opt/inst_debug_printf_pass.h +++ b/source/opt/inst_debug_printf_pass.h @@ -28,10 +28,10 @@ namespace opt { class InstDebugPrintfPass : public InstrumentPass { public: // For test harness only - InstDebugPrintfPass() : InstrumentPass(7, 23, kInstValidationIdDebugPrintf) {} + InstDebugPrintfPass() : InstrumentPass(7, 23) {} // For all other interfaces InstDebugPrintfPass(uint32_t desc_set, uint32_t shader_id) - : InstrumentPass(desc_set, shader_id, kInstValidationIdDebugPrintf) {} + : InstrumentPass(desc_set, shader_id) {} ~InstDebugPrintfPass() override = default; @@ -41,6 +41,104 @@ class InstDebugPrintfPass : public InstrumentPass { const char* name() const override { return "inst-printf-pass"; } private: + // Gen code into |builder| to write |field_value_id| into debug output + // buffer at |base_offset_id| + |field_offset|. + void GenDebugOutputFieldCode(uint32_t base_offset_id, uint32_t field_offset, + uint32_t field_value_id, + InstructionBuilder* builder); + + // Generate instructions in |builder| which will atomically fetch and + // increment the size of the debug output buffer stream of the current + // validation and write a record to the end of the stream, if enough space + // in the buffer remains. The record will contain the index of the function + // and instruction within that function |func_idx, instruction_idx| which + // generated the record. It will also contain additional information to + // identify the instance of the shader, depending on the stage |stage_idx| + // of the shader. Finally, the record will contain validation-specific + // data contained in |validation_ids| which will identify the validation + // error as well as the values involved in the error. + // + // The output buffer binding written to by the code generated by the function + // is determined by the validation id specified when each specific + // instrumentation pass is created. + // + // The output buffer is a sequence of 32-bit values with the following + // format (where all elements are unsigned 32-bit unless otherwise noted): + // + // Size + // Record0 + // Record1 + // Record2 + // ... + // + // Size is the number of 32-bit values that have been written or + // attempted to be written to the output buffer, excluding the Size. It is + // initialized to 0. If the size of attempts to write the buffer exceeds + // the actual size of the buffer, it is possible that this field can exceed + // the actual size of the buffer. + // + // Each Record* is a variable-length sequence of 32-bit values with the + // following format defined using static const offsets in the .cpp file: + // + // Record Size + // Shader ID + // Instruction Index + // Stage + // Stage-specific Word 0 + // Stage-specific Word 1 + // ... + // Validation Error Code + // Validation-specific Word 0 + // Validation-specific Word 1 + // Validation-specific Word 2 + // ... + // + // Each record consists of three subsections: members common across all + // validation, members specific to the stage, and members specific to a + // validation. + // + // The Record Size is the number of 32-bit words in the record, including + // the Record Size word. + // + // Shader ID is a value that identifies which shader has generated the + // validation error. It is passed when the instrumentation pass is created. + // + // The Instruction Index is the position of the instruction within the + // SPIR-V file which is in error. + // + // The Stage is the pipeline stage which has generated the error as defined + // by the SpvExecutionModel_ enumeration. This is used to interpret the + // following Stage-specific words. + // + // The Stage-specific Words identify which invocation of the shader generated + // the error. Every stage will write a fixed number of words. Vertex shaders + // will write the Vertex and Instance ID. Fragment shaders will write + // FragCoord.xy. Compute shaders will write the GlobalInvocation ID. + // The tessellation eval shader will write the Primitive ID and TessCoords.uv. + // The tessellation control shader and geometry shader will write the + // Primitive ID and Invocation ID. + // + // The Validation Error Code specifies the exact error which has occurred. + // These are enumerated with the kInstError* static consts. This allows + // multiple validation layers to use the same, single output buffer. + // + // The Validation-specific Words are a validation-specific number of 32-bit + // words which give further information on the validation error that + // occurred. These are documented further in each file containing the + // validation-specific class which derives from this base class. + // + // Because the code that is generated checks against the size of the buffer + // before writing, the size of the debug out buffer can be used by the + // validation layer to control the number of error records that are written. + void GenDebugStreamWrite(uint32_t shader_id, uint32_t instruction_idx_id, + uint32_t stage_info_id, + const std::vector& validation_ids, + InstructionBuilder* builder); + + // Return id for output function. Define if it doesn't exist with + // |val_spec_param_cnt| validation-specific uint32 parameters. + uint32_t GetStreamWriteFunctionId(uint32_t val_spec_param_cnt); + // Generate instructions for OpDebugPrintf. // // If |ref_inst_itr| is an OpDebugPrintf, return in |new_blocks| the result @@ -80,13 +178,37 @@ class InstDebugPrintfPass : public InstrumentPass { void GenOutputCode(Instruction* printf_inst, uint32_t stage_idx, std::vector>* new_blocks); + // Set the name for a function or global variable, names will be + // prefixed to identify which instrumentation pass generated them. + std::unique_ptr NewGlobalName(uint32_t id, + const std::string& name_str); + + // Set the name for a structure member + std::unique_ptr NewMemberName(uint32_t id, uint32_t member_index, + const std::string& name_str); + + // Return id for debug output buffer + uint32_t GetOutputBufferId(); + + // Return id for buffer uint type + uint32_t GetOutputBufferPtrId(); + + // Return binding for output buffer for current validation. + uint32_t GetOutputBufferBinding(); + // Initialize state for instrumenting bindless checking void InitializeInstDebugPrintf(); // Apply GenDebugPrintfCode to every instruction in module. Pass::Status ProcessImpl(); - uint32_t ext_inst_printf_id_; + uint32_t ext_inst_printf_id_{0}; + + // id for output buffer variable + uint32_t output_buffer_id_{0}; + + // ptr type id for output buffer element + uint32_t output_buffer_ptr_id_{0}; }; } // namespace opt diff --git a/source/opt/instrument_pass.cpp b/source/opt/instrument_pass.cpp index bd01ee64f..829de491c 100644 --- a/source/opt/instrument_pass.cpp +++ b/source/opt/instrument_pass.cpp @@ -131,38 +131,6 @@ std::unique_ptr InstrumentPass::NewName( {SPV_OPERAND_TYPE_LITERAL_STRING, utils::MakeVector(name_str)}}); } -std::unique_ptr InstrumentPass::NewGlobalName( - uint32_t id, const std::string& name_str) { - std::string prefixed_name; - switch (validation_id_) { - case kInstValidationIdBindless: - prefixed_name = "inst_bindless_"; - break; - case kInstValidationIdBuffAddr: - prefixed_name = "inst_buff_addr_"; - break; - case kInstValidationIdDebugPrintf: - prefixed_name = "inst_printf_"; - break; - default: - assert(false); // add new instrumentation pass here - prefixed_name = "inst_pass_"; - break; - } - prefixed_name += name_str; - return NewName(id, prefixed_name); -} - -std::unique_ptr InstrumentPass::NewMemberName( - uint32_t id, uint32_t member_index, const std::string& name_str) { - return MakeUnique( - context(), spv::Op::OpMemberName, 0, 0, - std::initializer_list{ - {SPV_OPERAND_TYPE_ID, {id}}, - {SPV_OPERAND_TYPE_LITERAL_INTEGER, {member_index}}, - {SPV_OPERAND_TYPE_LITERAL_STRING, utils::MakeVector(name_str)}}); -} - uint32_t InstrumentPass::Gen32BitCvtCode(uint32_t val_id, InstructionBuilder* builder) { // Convert integer value to 32-bit if necessary @@ -195,24 +163,6 @@ uint32_t InstrumentPass::GenUintCastCode(uint32_t val_id, ->result_id(); } -void InstrumentPass::GenDebugOutputFieldCode(uint32_t base_offset_id, - uint32_t field_offset, - uint32_t field_value_id, - InstructionBuilder* builder) { - // Cast value to 32-bit unsigned if necessary - uint32_t val_id = GenUintCastCode(field_value_id, builder); - // Store value - Instruction* data_idx_inst = builder->AddIAdd( - GetUintId(), base_offset_id, builder->GetUintConstantId(field_offset)); - uint32_t buf_id = GetOutputBufferId(); - uint32_t buf_uint_ptr_id = GetOutputBufferPtrId(); - Instruction* achain_inst = builder->AddAccessChain( - buf_uint_ptr_id, buf_id, - {builder->GetUintConstantId(kDebugOutputDataOffset), - data_idx_inst->result_id()}); - (void)builder->AddStore(achain_inst->result_id(), val_id); -} - uint32_t InstrumentPass::GenVarLoad(uint32_t var_id, InstructionBuilder* builder) { Instruction* var_inst = get_def_use_mgr()->GetDef(var_id); @@ -329,18 +279,6 @@ uint32_t InstrumentPass::GenStageInfo(uint32_t stage_idx, return builder->AddCompositeConstruct(GetVec4UintId(), ids)->result_id(); } -void InstrumentPass::GenDebugStreamWrite( - uint32_t shader_id, uint32_t instruction_idx_id, uint32_t stage_info_id, - const std::vector& validation_ids, InstructionBuilder* builder) { - // Call debug output function. Pass func_idx, instruction_idx and - // validation ids as args. - uint32_t val_id_cnt = static_cast(validation_ids.size()); - std::vector args = {shader_id, instruction_idx_id, stage_info_id}; - (void)args.insert(args.end(), validation_ids.begin(), validation_ids.end()); - (void)builder->AddFunctionCall(GetVoidId(), - GetStreamWriteFunctionId(val_id_cnt), args); -} - bool InstrumentPass::AllConstant(const std::vector& ids) { for (auto& id : ids) { Instruction* id_inst = context()->get_def_use_mgr()->GetDef(id); @@ -349,14 +287,6 @@ bool InstrumentPass::AllConstant(const std::vector& ids) { return true; } -uint32_t InstrumentPass::GenDebugDirectRead( - const std::vector& offset_ids, InstructionBuilder* builder) { - // Call debug input function. Pass func_idx and offset ids as args. - const uint32_t off_id_cnt = static_cast(offset_ids.size()); - const uint32_t input_func_id = GetDirectReadFunctionId(off_id_cnt); - return GenReadFunctionCall(GetUintId(), input_func_id, offset_ids, builder); -} - uint32_t InstrumentPass::GenReadFunctionCall( uint32_t return_id, uint32_t func_id, const std::vector& func_call_args, @@ -450,53 +380,6 @@ void InstrumentPass::UpdateSucceedingPhis( }); } -uint32_t InstrumentPass::GetOutputBufferPtrId() { - if (output_buffer_ptr_id_ == 0) { - output_buffer_ptr_id_ = context()->get_type_mgr()->FindPointerToType( - GetUintId(), spv::StorageClass::StorageBuffer); - } - return output_buffer_ptr_id_; -} - -uint32_t InstrumentPass::GetInputBufferTypeId() { - return (validation_id_ == kInstValidationIdBuffAddr) ? GetUint64Id() - : GetUintId(); -} - -uint32_t InstrumentPass::GetInputBufferPtrId() { - if (input_buffer_ptr_id_ == 0) { - input_buffer_ptr_id_ = context()->get_type_mgr()->FindPointerToType( - GetInputBufferTypeId(), spv::StorageClass::StorageBuffer); - } - return input_buffer_ptr_id_; -} - -uint32_t InstrumentPass::GetOutputBufferBinding() { - switch (validation_id_) { - case kInstValidationIdBindless: - return kDebugOutputBindingStream; - case kInstValidationIdBuffAddr: - return kDebugOutputBindingStream; - case kInstValidationIdDebugPrintf: - return kDebugOutputPrintfStream; - default: - assert(false && "unexpected validation id"); - } - return 0; -} - -uint32_t InstrumentPass::GetInputBufferBinding() { - switch (validation_id_) { - case kInstValidationIdBindless: - return kDebugInputBindingBindless; - case kInstValidationIdBuffAddr: - return kDebugInputBindingBuffAddr; - default: - assert(false && "unexpected validation id"); - } - return 0; -} - analysis::Integer* InstrumentPass::GetInteger(uint32_t width, bool is_signed) { analysis::Integer i(width, is_signed); analysis::Type* type = context()->get_type_mgr()->GetRegisteredType(&i); @@ -577,110 +460,6 @@ void InstrumentPass::AddStorageBufferExt() { storage_buffer_ext_defined_ = true; } -// Return id for output buffer -uint32_t InstrumentPass::GetOutputBufferId() { - if (output_buffer_id_ == 0) { - // If not created yet, create one - analysis::DecorationManager* deco_mgr = get_decoration_mgr(); - analysis::TypeManager* type_mgr = context()->get_type_mgr(); - analysis::RuntimeArray* reg_uint_rarr_ty = GetUintRuntimeArrayType(32); - analysis::Integer* reg_uint_ty = GetInteger(32, false); - analysis::Type* reg_buf_ty = - GetStruct({reg_uint_ty, reg_uint_ty, reg_uint_rarr_ty}); - uint32_t obufTyId = type_mgr->GetTypeInstruction(reg_buf_ty); - // By the Vulkan spec, a pre-existing struct containing a RuntimeArray - // must be a block, and will therefore be decorated with Block. Therefore - // the undecorated type returned here will not be pre-existing and can - // safely be decorated. Since this type is now decorated, it is out of - // sync with the TypeManager and therefore the TypeManager must be - // invalidated after this pass. - assert(context()->get_def_use_mgr()->NumUses(obufTyId) == 0 && - "used struct type returned"); - deco_mgr->AddDecoration(obufTyId, uint32_t(spv::Decoration::Block)); - deco_mgr->AddMemberDecoration(obufTyId, kDebugOutputFlagsOffset, - uint32_t(spv::Decoration::Offset), 0); - deco_mgr->AddMemberDecoration(obufTyId, kDebugOutputSizeOffset, - uint32_t(spv::Decoration::Offset), 4); - deco_mgr->AddMemberDecoration(obufTyId, kDebugOutputDataOffset, - uint32_t(spv::Decoration::Offset), 8); - uint32_t obufTyPtrId_ = - type_mgr->FindPointerToType(obufTyId, spv::StorageClass::StorageBuffer); - output_buffer_id_ = TakeNextId(); - std::unique_ptr newVarOp(new Instruction( - context(), spv::Op::OpVariable, obufTyPtrId_, output_buffer_id_, - {{spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, - {uint32_t(spv::StorageClass::StorageBuffer)}}})); - context()->AddGlobalValue(std::move(newVarOp)); - context()->AddDebug2Inst(NewGlobalName(obufTyId, "OutputBuffer")); - context()->AddDebug2Inst(NewMemberName(obufTyId, 0, "flags")); - context()->AddDebug2Inst(NewMemberName(obufTyId, 1, "written_count")); - context()->AddDebug2Inst(NewMemberName(obufTyId, 2, "data")); - context()->AddDebug2Inst(NewGlobalName(output_buffer_id_, "output_buffer")); - deco_mgr->AddDecorationVal( - output_buffer_id_, uint32_t(spv::Decoration::DescriptorSet), desc_set_); - deco_mgr->AddDecorationVal(output_buffer_id_, - uint32_t(spv::Decoration::Binding), - GetOutputBufferBinding()); - AddStorageBufferExt(); - if (get_module()->version() >= SPV_SPIRV_VERSION_WORD(1, 4)) { - // Add the new buffer to all entry points. - for (auto& entry : get_module()->entry_points()) { - entry.AddOperand({SPV_OPERAND_TYPE_ID, {output_buffer_id_}}); - context()->AnalyzeUses(&entry); - } - } - } - return output_buffer_id_; -} - -uint32_t InstrumentPass::GetInputBufferId() { - if (input_buffer_id_ == 0) { - // If not created yet, create one - analysis::DecorationManager* deco_mgr = get_decoration_mgr(); - analysis::TypeManager* type_mgr = context()->get_type_mgr(); - uint32_t width = (validation_id_ == kInstValidationIdBuffAddr) ? 64u : 32u; - analysis::Type* reg_uint_rarr_ty = GetUintRuntimeArrayType(width); - analysis::Struct* reg_buf_ty = GetStruct({reg_uint_rarr_ty}); - uint32_t ibufTyId = type_mgr->GetTypeInstruction(reg_buf_ty); - // By the Vulkan spec, a pre-existing struct containing a RuntimeArray - // must be a block, and will therefore be decorated with Block. Therefore - // the undecorated type returned here will not be pre-existing and can - // safely be decorated. Since this type is now decorated, it is out of - // sync with the TypeManager and therefore the TypeManager must be - // invalidated after this pass. - assert(context()->get_def_use_mgr()->NumUses(ibufTyId) == 0 && - "used struct type returned"); - deco_mgr->AddDecoration(ibufTyId, uint32_t(spv::Decoration::Block)); - deco_mgr->AddMemberDecoration(ibufTyId, 0, - uint32_t(spv::Decoration::Offset), 0); - uint32_t ibufTyPtrId_ = - type_mgr->FindPointerToType(ibufTyId, spv::StorageClass::StorageBuffer); - input_buffer_id_ = TakeNextId(); - std::unique_ptr newVarOp(new Instruction( - context(), spv::Op::OpVariable, ibufTyPtrId_, input_buffer_id_, - {{spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, - {uint32_t(spv::StorageClass::StorageBuffer)}}})); - context()->AddGlobalValue(std::move(newVarOp)); - context()->AddDebug2Inst(NewGlobalName(ibufTyId, "InputBuffer")); - context()->AddDebug2Inst(NewMemberName(ibufTyId, 0, "data")); - context()->AddDebug2Inst(NewGlobalName(input_buffer_id_, "input_buffer")); - deco_mgr->AddDecorationVal( - input_buffer_id_, uint32_t(spv::Decoration::DescriptorSet), desc_set_); - deco_mgr->AddDecorationVal(input_buffer_id_, - uint32_t(spv::Decoration::Binding), - GetInputBufferBinding()); - AddStorageBufferExt(); - if (get_module()->version() >= SPV_SPIRV_VERSION_WORD(1, 4)) { - // Add the new buffer to all entry points. - for (auto& entry : get_module()->entry_points()) { - entry.AddOperand({SPV_OPERAND_TYPE_ID, {input_buffer_id_}}); - context()->AnalyzeUses(&entry); - } - } - } - return input_buffer_id_; -} - uint32_t InstrumentPass::GetFloatId() { if (float_id_ == 0) { analysis::TypeManager* type_mgr = context()->get_type_mgr(); @@ -773,181 +552,6 @@ uint32_t InstrumentPass::GetVoidId() { return void_id_; } -uint32_t InstrumentPass::GetStreamWriteFunctionId(uint32_t param_cnt) { - enum { - kShaderId = 0, - kInstructionIndex = 1, - kStageInfo = 2, - kFirstParam = 3, - }; - // Total param count is common params plus validation-specific - // params - if (param2output_func_id_[param_cnt] == 0) { - // Create function - param2output_func_id_[param_cnt] = TakeNextId(); - analysis::TypeManager* type_mgr = context()->get_type_mgr(); - - const analysis::Type* uint_type = GetInteger(32, false); - const analysis::Vector v4uint(uint_type, 4); - const analysis::Type* v4uint_type = type_mgr->GetRegisteredType(&v4uint); - - std::vector param_types(kFirstParam + param_cnt, - uint_type); - param_types[kStageInfo] = v4uint_type; - std::unique_ptr output_func = StartFunction( - param2output_func_id_[param_cnt], type_mgr->GetVoidType(), param_types); - - std::vector param_ids = AddParameters(*output_func, param_types); - - // Create first block - auto new_blk_ptr = MakeUnique(NewLabel(TakeNextId())); - - InstructionBuilder builder( - context(), &*new_blk_ptr, - IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping); - // Gen test if debug output buffer size will not be exceeded. - const uint32_t val_spec_offset = kInstStageOutCnt; - const uint32_t obuf_record_sz = val_spec_offset + param_cnt; - const uint32_t buf_id = GetOutputBufferId(); - const uint32_t buf_uint_ptr_id = GetOutputBufferPtrId(); - Instruction* obuf_curr_sz_ac_inst = builder.AddAccessChain( - buf_uint_ptr_id, buf_id, - {builder.GetUintConstantId(kDebugOutputSizeOffset)}); - // Fetch the current debug buffer written size atomically, adding the - // size of the record to be written. - uint32_t obuf_record_sz_id = builder.GetUintConstantId(obuf_record_sz); - uint32_t mask_none_id = - builder.GetUintConstantId(uint32_t(spv::MemoryAccessMask::MaskNone)); - uint32_t scope_invok_id = - builder.GetUintConstantId(uint32_t(spv::Scope::Invocation)); - Instruction* obuf_curr_sz_inst = builder.AddQuadOp( - GetUintId(), spv::Op::OpAtomicIAdd, obuf_curr_sz_ac_inst->result_id(), - scope_invok_id, mask_none_id, obuf_record_sz_id); - uint32_t obuf_curr_sz_id = obuf_curr_sz_inst->result_id(); - // Compute new written size - Instruction* obuf_new_sz_inst = - builder.AddIAdd(GetUintId(), obuf_curr_sz_id, - builder.GetUintConstantId(obuf_record_sz)); - // Fetch the data bound - Instruction* obuf_bnd_inst = - builder.AddIdLiteralOp(GetUintId(), spv::Op::OpArrayLength, - GetOutputBufferId(), kDebugOutputDataOffset); - // Test that new written size is less than or equal to debug output - // data bound - Instruction* obuf_safe_inst = builder.AddBinaryOp( - GetBoolId(), spv::Op::OpULessThanEqual, obuf_new_sz_inst->result_id(), - obuf_bnd_inst->result_id()); - uint32_t merge_blk_id = TakeNextId(); - uint32_t write_blk_id = TakeNextId(); - std::unique_ptr merge_label(NewLabel(merge_blk_id)); - std::unique_ptr write_label(NewLabel(write_blk_id)); - (void)builder.AddConditionalBranch( - obuf_safe_inst->result_id(), write_blk_id, merge_blk_id, merge_blk_id, - uint32_t(spv::SelectionControlMask::MaskNone)); - // Close safety test block and gen write block - output_func->AddBasicBlock(std::move(new_blk_ptr)); - new_blk_ptr = MakeUnique(std::move(write_label)); - builder.SetInsertPoint(&*new_blk_ptr); - // Generate common and stage-specific debug record members - GenDebugOutputFieldCode(obuf_curr_sz_id, kInstCommonOutSize, - builder.GetUintConstantId(obuf_record_sz), - &builder); - // Store Shader Id - GenDebugOutputFieldCode(obuf_curr_sz_id, kInstCommonOutShaderId, - param_ids[kShaderId], &builder); - // Store Instruction Idx - GenDebugOutputFieldCode(obuf_curr_sz_id, kInstCommonOutInstructionIdx, - param_ids[kInstructionIndex], &builder); - // Store stage info. Stage Idx + 3 words of stage-specific data. - for (uint32_t i = 0; i < 4; ++i) { - Instruction* field = - builder.AddCompositeExtract(GetUintId(), param_ids[kStageInfo], {i}); - GenDebugOutputFieldCode(obuf_curr_sz_id, kInstCommonOutStageIdx + i, - field->result_id(), &builder); - } - // Gen writes of validation specific data - for (uint32_t i = 0; i < param_cnt; ++i) { - GenDebugOutputFieldCode(obuf_curr_sz_id, val_spec_offset + i, - param_ids[kFirstParam + i], &builder); - } - // Close write block and gen merge block - (void)builder.AddBranch(merge_blk_id); - output_func->AddBasicBlock(std::move(new_blk_ptr)); - new_blk_ptr = MakeUnique(std::move(merge_label)); - builder.SetInsertPoint(&*new_blk_ptr); - // Close merge block and function and add function to module - (void)builder.AddNullaryOp(0, spv::Op::OpReturn); - - output_func->AddBasicBlock(std::move(new_blk_ptr)); - output_func->SetFunctionEnd(EndFunction()); - context()->AddFunction(std::move(output_func)); - - std::string name("stream_write_"); - name += std::to_string(param_cnt); - - context()->AddDebug2Inst( - NewGlobalName(param2output_func_id_[param_cnt], name)); - } - return param2output_func_id_[param_cnt]; -} - -uint32_t InstrumentPass::GetDirectReadFunctionId(uint32_t param_cnt) { - uint32_t func_id = param2input_func_id_[param_cnt]; - if (func_id != 0) return func_id; - // Create input function for param_cnt. - func_id = TakeNextId(); - analysis::Integer* uint_type = GetInteger(32, false); - std::vector param_types(param_cnt, uint_type); - - std::unique_ptr input_func = - StartFunction(func_id, uint_type, param_types); - std::vector param_ids = AddParameters(*input_func, param_types); - - // Create block - auto new_blk_ptr = MakeUnique(NewLabel(TakeNextId())); - InstructionBuilder builder( - context(), &*new_blk_ptr, - IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping); - // For each offset parameter, generate new offset with parameter, adding last - // loaded value if it exists, and load value from input buffer at new offset. - // Return last loaded value. - uint32_t ibuf_type_id = GetInputBufferTypeId(); - uint32_t buf_id = GetInputBufferId(); - uint32_t buf_ptr_id = GetInputBufferPtrId(); - uint32_t last_value_id = 0; - for (uint32_t p = 0; p < param_cnt; ++p) { - uint32_t offset_id; - if (p == 0) { - offset_id = param_ids[0]; - } else { - if (ibuf_type_id != GetUintId()) { - last_value_id = - builder.AddUnaryOp(GetUintId(), spv::Op::OpUConvert, last_value_id) - ->result_id(); - } - offset_id = builder.AddIAdd(GetUintId(), last_value_id, param_ids[p]) - ->result_id(); - } - Instruction* ac_inst = builder.AddAccessChain( - buf_ptr_id, buf_id, - {builder.GetUintConstantId(kDebugInputDataOffset), offset_id}); - last_value_id = - builder.AddLoad(ibuf_type_id, ac_inst->result_id())->result_id(); - } - (void)builder.AddUnaryOp(0, spv::Op::OpReturnValue, last_value_id); - // Close block and function and add function to module - input_func->AddBasicBlock(std::move(new_blk_ptr)); - input_func->SetFunctionEnd(EndFunction()); - context()->AddFunction(std::move(input_func)); - - std::string name("direct_read_"); - name += std::to_string(param_cnt); - context()->AddDebug2Inst(NewGlobalName(func_id, name)); - - param2input_func_id_[param_cnt] = func_id; - return func_id; -} - void InstrumentPass::SplitBlock( BasicBlock::iterator inst_itr, UptrVectorIterator block_itr, std::vector>* new_blocks) { @@ -1091,10 +695,6 @@ bool InstrumentPass::InstProcessEntryPointCallTree(InstProcessFunction& pfn) { } void InstrumentPass::InitializeInstrument() { - output_buffer_id_ = 0; - output_buffer_ptr_id_ = 0; - input_buffer_ptr_id_ = 0; - input_buffer_id_ = 0; float_id_ = 0; v4float_id_ = 0; uint_id_ = 0; diff --git a/source/opt/instrument_pass.h b/source/opt/instrument_pass.h index 092b361de..8b643742d 100644 --- a/source/opt/instrument_pass.h +++ b/source/opt/instrument_pass.h @@ -55,14 +55,6 @@ namespace spvtools { namespace opt { -namespace { -// Validation Ids -// These are used to identify the general validation being done and map to -// its output buffers. -constexpr uint32_t kInstValidationIdBindless = 0; -constexpr uint32_t kInstValidationIdBuffAddr = 1; -constexpr uint32_t kInstValidationIdDebugPrintf = 2; -} // namespace class InstrumentPass : public Pass { using cbb_ptr = const BasicBlock*; @@ -85,12 +77,11 @@ class InstrumentPass : public Pass { // set |desc_set| for debug input and output buffers and writes |shader_id| // into debug output records. |opt_direct_reads| indicates that the pass // will see direct input buffer reads and should prepare to optimize them. - InstrumentPass(uint32_t desc_set, uint32_t shader_id, uint32_t validation_id, + InstrumentPass(uint32_t desc_set, uint32_t shader_id, bool opt_direct_reads = false) : Pass(), desc_set_(desc_set), shader_id_(shader_id), - validation_id_(validation_id), opt_direct_reads_(opt_direct_reads) {} // Initialize state for instrumentation of module. @@ -113,108 +104,9 @@ class InstrumentPass : public Pass { void MovePostludeCode(UptrVectorIterator ref_block_itr, BasicBlock* new_blk_ptr); - // Generate instructions in |builder| which will atomically fetch and - // increment the size of the debug output buffer stream of the current - // validation and write a record to the end of the stream, if enough space - // in the buffer remains. The record will contain the index of the function - // and instruction within that function |func_idx, instruction_idx| which - // generated the record. It will also contain additional information to - // identify the instance of the shader, depending on the stage |stage_idx| - // of the shader. Finally, the record will contain validation-specific - // data contained in |validation_ids| which will identify the validation - // error as well as the values involved in the error. - // - // The output buffer binding written to by the code generated by the function - // is determined by the validation id specified when each specific - // instrumentation pass is created. - // - // The output buffer is a sequence of 32-bit values with the following - // format (where all elements are unsigned 32-bit unless otherwise noted): - // - // Size - // Record0 - // Record1 - // Record2 - // ... - // - // Size is the number of 32-bit values that have been written or - // attempted to be written to the output buffer, excluding the Size. It is - // initialized to 0. If the size of attempts to write the buffer exceeds - // the actual size of the buffer, it is possible that this field can exceed - // the actual size of the buffer. - // - // Each Record* is a variable-length sequence of 32-bit values with the - // following format defined using static const offsets in the .cpp file: - // - // Record Size - // Shader ID - // Instruction Index - // Stage - // Stage-specific Word 0 - // Stage-specific Word 1 - // ... - // Validation Error Code - // Validation-specific Word 0 - // Validation-specific Word 1 - // Validation-specific Word 2 - // ... - // - // Each record consists of three subsections: members common across all - // validation, members specific to the stage, and members specific to a - // validation. - // - // The Record Size is the number of 32-bit words in the record, including - // the Record Size word. - // - // Shader ID is a value that identifies which shader has generated the - // validation error. It is passed when the instrumentation pass is created. - // - // The Instruction Index is the position of the instruction within the - // SPIR-V file which is in error. - // - // The Stage is the pipeline stage which has generated the error as defined - // by the SpvExecutionModel_ enumeration. This is used to interpret the - // following Stage-specific words. - // - // The Stage-specific Words identify which invocation of the shader generated - // the error. Every stage will write a fixed number of words. Vertex shaders - // will write the Vertex and Instance ID. Fragment shaders will write - // FragCoord.xy. Compute shaders will write the GlobalInvocation ID. - // The tessellation eval shader will write the Primitive ID and TessCoords.uv. - // The tessellation control shader and geometry shader will write the - // Primitive ID and Invocation ID. - // - // The Validation Error Code specifies the exact error which has occurred. - // These are enumerated with the kInstError* static consts. This allows - // multiple validation layers to use the same, single output buffer. - // - // The Validation-specific Words are a validation-specific number of 32-bit - // words which give further information on the validation error that - // occurred. These are documented further in each file containing the - // validation-specific class which derives from this base class. - // - // Because the code that is generated checks against the size of the buffer - // before writing, the size of the debug out buffer can be used by the - // validation layer to control the number of error records that are written. - void GenDebugStreamWrite(uint32_t shader_id, uint32_t instruction_idx_id, - uint32_t stage_info_id, - const std::vector& validation_ids, - InstructionBuilder* builder); - // Return true if all instructions in |ids| are constants or spec constants. bool AllConstant(const std::vector& ids); - // Generate in |builder| instructions to read the unsigned integer from the - // input buffer specified by the offsets in |offset_ids|. Given offsets - // o0, o1, ... oN, and input buffer ibuf, return the id for the value: - // - // ibuf[...ibuf[ibuf[o0]+o1]...+oN] - // - // The binding and the format of the input buffer is determined by each - // specific validation, which is specified at the creation of the pass. - uint32_t GenDebugDirectRead(const std::vector& offset_ids, - InstructionBuilder* builder); - uint32_t GenReadFunctionCall(uint32_t return_id, uint32_t func_id, const std::vector& args, InstructionBuilder* builder); @@ -243,15 +135,6 @@ class InstrumentPass : public Pass { std::unique_ptr NewName(uint32_t id, const std::string& name_str); - // Set the name for a function or global variable, names will be - // prefixed to identify which instrumentation pass generated them. - std::unique_ptr NewGlobalName(uint32_t id, - const std::string& name_str); - - // Set the name for a structure member - std::unique_ptr NewMemberName(uint32_t id, uint32_t member_index, - const std::string& name_str); - // Return id for 32-bit unsigned type uint32_t GetUintId(); @@ -283,30 +166,9 @@ class InstrumentPass : public Pass { // Return pointer to type for runtime array of uint analysis::RuntimeArray* GetUintRuntimeArrayType(uint32_t width); - // Return id for buffer uint type - uint32_t GetOutputBufferPtrId(); - - // Return id for buffer uint type - uint32_t GetInputBufferTypeId(); - - // Return id for buffer uint type - uint32_t GetInputBufferPtrId(); - - // Return binding for output buffer for current validation. - uint32_t GetOutputBufferBinding(); - - // Return binding for input buffer for current validation. - uint32_t GetInputBufferBinding(); - // Add storage buffer extension if needed void AddStorageBufferExt(); - // Return id for debug output buffer - uint32_t GetOutputBufferId(); - - // Return id for debug input buffer - uint32_t GetInputBufferId(); - // Return id for 32-bit float type uint32_t GetFloatId(); @@ -322,14 +184,6 @@ class InstrumentPass : public Pass { // Return id for v3uint type uint32_t GetVec3UintId(); - // Return id for output function. Define if it doesn't exist with - // |val_spec_param_cnt| validation-specific uint32 parameters. - uint32_t GetStreamWriteFunctionId(uint32_t val_spec_param_cnt); - - // Return id for input function taking |param_cnt| uint32 parameters. Define - // if it doesn't exist. - uint32_t GetDirectReadFunctionId(uint32_t param_cnt); - // Split block |block_itr| into two new blocks where the second block // contains |inst_itr| and place in |new_blocks|. void SplitBlock(BasicBlock::iterator inst_itr, @@ -349,12 +203,6 @@ class InstrumentPass : public Pass { std::queue* roots, uint32_t stage_idx); - // Gen code into |builder| to write |field_value_id| into debug output - // buffer at |base_offset_id| + |field_offset|. - void GenDebugOutputFieldCode(uint32_t base_offset_id, uint32_t field_offset, - uint32_t field_value_id, - InstructionBuilder* builder); - // Generate instructions into |builder| which will load |var_id| and return // its result id. uint32_t GenVarLoad(uint32_t var_id, InstructionBuilder* builder); @@ -395,62 +243,47 @@ class InstrumentPass : public Pass { // Map from instruction's unique id to offset in original file. std::unordered_map uid2offset_; - // result id for OpConstantFalse - uint32_t validation_id_; - - // id for output buffer variable - uint32_t output_buffer_id_; - - // ptr type id for output buffer element - uint32_t output_buffer_ptr_id_; - - // ptr type id for input buffer element - uint32_t input_buffer_ptr_id_; - // id for debug output function std::unordered_map param2output_func_id_; // ids for debug input functions std::unordered_map param2input_func_id_; - // id for input buffer variable - uint32_t input_buffer_id_; - // id for 32-bit float type - uint32_t float_id_; + uint32_t float_id_{0}; // id for v4float type - uint32_t v4float_id_; + uint32_t v4float_id_{0}; // id for v4uint type - uint32_t v4uint_id_; + uint32_t v4uint_id_{0}; // id for v3uint type - uint32_t v3uint_id_; + uint32_t v3uint_id_{0}; // id for 32-bit unsigned type - uint32_t uint_id_; + uint32_t uint_id_{0}; // id for 64-bit unsigned type - uint32_t uint64_id_; + uint32_t uint64_id_{0}; // id for 8-bit unsigned type - uint32_t uint8_id_; + uint32_t uint8_id_{0}; // id for bool type - uint32_t bool_id_; + uint32_t bool_id_{0}; // id for void type - uint32_t void_id_; + uint32_t void_id_{0}; // boolean to remember storage buffer extension - bool storage_buffer_ext_defined_; + bool storage_buffer_ext_defined_{false}; // runtime array of uint type - analysis::RuntimeArray* uint64_rarr_ty_; + analysis::RuntimeArray* uint64_rarr_ty_{nullptr}; // runtime array of uint type - analysis::RuntimeArray* uint32_rarr_ty_; + analysis::RuntimeArray* uint32_rarr_ty_{nullptr}; // Pre-instrumentation same-block insts std::unordered_map same_block_pre_; @@ -475,11 +308,11 @@ class InstrumentPass : public Pass { std::unordered_map, uint32_t, vector_hash_> call2id_; // Function currently being instrumented - Function* curr_func_; + Function* curr_func_{nullptr}; // Optimize direct debug input buffer reads. Specifically, move all such // reads with constant args to first block and reuse them. - bool opt_direct_reads_; + bool opt_direct_reads_{false}; }; } // namespace opt diff --git a/source/opt/ir_context.h b/source/opt/ir_context.h index 7ff411a15..de3c41066 100644 --- a/source/opt/ir_context.h +++ b/source/opt/ir_context.h @@ -252,6 +252,8 @@ class IRContext { inline void AddType(std::unique_ptr&& t); // Appends a constant, global variable, or OpUndef instruction to this module. inline void AddGlobalValue(std::unique_ptr&& v); + // Prepends a function declaration to this module. + inline void AddFunctionDeclaration(std::unique_ptr&& f); // Appends a function to this module. inline void AddFunction(std::unique_ptr&& f); @@ -1213,6 +1215,10 @@ void IRContext::AddGlobalValue(std::unique_ptr&& v) { module()->AddGlobalValue(std::move(v)); } +void IRContext::AddFunctionDeclaration(std::unique_ptr&& f) { + module()->AddFunctionDeclaration(std::move(f)); +} + void IRContext::AddFunction(std::unique_ptr&& f) { module()->AddFunction(std::move(f)); } diff --git a/source/opt/module.h b/source/opt/module.h index b9d69129f..98c16dc4c 100644 --- a/source/opt/module.h +++ b/source/opt/module.h @@ -120,6 +120,9 @@ class Module { // Appends a constant, global variable, or OpUndef instruction to this module. inline void AddGlobalValue(std::unique_ptr v); + // Prepends a function declaration to this module. + inline void AddFunctionDeclaration(std::unique_ptr f); + // Appends a function to this module. inline void AddFunction(std::unique_ptr f); @@ -380,6 +383,11 @@ inline void Module::AddGlobalValue(std::unique_ptr v) { types_values_.push_back(std::move(v)); } +inline void Module::AddFunctionDeclaration(std::unique_ptr f) { + // function declarations must come before function definitions. + functions_.emplace(functions_.begin(), std::move(f)); +} + inline void Module::AddFunction(std::unique_ptr f) { functions_.emplace_back(std::move(f)); } diff --git a/source/opt/optimizer.cpp b/source/opt/optimizer.cpp index b8f528342..afff9ece4 100644 --- a/source/opt/optimizer.cpp +++ b/source/opt/optimizer.cpp @@ -434,13 +434,13 @@ bool Optimizer::RegisterPassFromFlag(const std::string& flag) { pass_name == "inst-desc-idx-check" || pass_name == "inst-buff-oob-check") { // preserve legacy names - RegisterPass(CreateInstBindlessCheckPass(7, 23)); + RegisterPass(CreateInstBindlessCheckPass(23)); RegisterPass(CreateSimplificationPass()); RegisterPass(CreateDeadBranchElimPass()); RegisterPass(CreateBlockMergePass()); RegisterPass(CreateAggressiveDCEPass(true)); } else if (pass_name == "inst-buff-addr-check") { - RegisterPass(CreateInstBuffAddrCheckPass(7, 23)); + RegisterPass(CreateInstBuffAddrCheckPass(23)); RegisterPass(CreateAggressiveDCEPass(true)); } else if (pass_name == "convert-relaxed-to-half") { RegisterPass(CreateConvertRelaxedToHalfPass()); @@ -980,10 +980,9 @@ Optimizer::PassToken CreateUpgradeMemoryModelPass() { MakeUnique()); } -Optimizer::PassToken CreateInstBindlessCheckPass(uint32_t desc_set, - uint32_t shader_id) { +Optimizer::PassToken CreateInstBindlessCheckPass(uint32_t shader_id) { return MakeUnique( - MakeUnique(desc_set, shader_id)); + MakeUnique(shader_id)); } Optimizer::PassToken CreateInstDebugPrintfPass(uint32_t desc_set, @@ -992,10 +991,9 @@ Optimizer::PassToken CreateInstDebugPrintfPass(uint32_t desc_set, MakeUnique(desc_set, shader_id)); } -Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t desc_set, - uint32_t shader_id) { +Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t shader_id) { return MakeUnique( - MakeUnique(desc_set, shader_id)); + MakeUnique(shader_id)); } Optimizer::PassToken CreateConvertRelaxedToHalfPass() { diff --git a/test/opt/inst_bindless_check_test.cpp b/test/opt/inst_bindless_check_test.cpp index 1c192c436..0deec5c6a 100644 --- a/test/opt/inst_bindless_check_test.cpp +++ b/test/opt/inst_bindless_check_test.cpp @@ -27,243 +27,16 @@ namespace { using InstBindlessTest = PassTest<::testing::Test>; -static const std::string kOutputDecorations = R"( -; CHECK: OpDecorate [[output_buffer_type:%inst_bindless_OutputBuffer]] Block -; CHECK: OpMemberDecorate [[output_buffer_type]] 0 Offset 0 -; CHECK: OpMemberDecorate [[output_buffer_type]] 1 Offset 4 -; CHECK: OpDecorate [[output_buffer_var:%\w+]] DescriptorSet 7 -; CHECK: OpDecorate [[output_buffer_var]] Binding 0 +static const std::string kFuncName = "inst_bindless_check_desc"; + +static const std::string kImportDeco = R"( +;CHECK: OpDecorate %)" + kFuncName + R"( LinkageAttributes ")" + + kFuncName + R"(" Import )"; -static const std::string kOutputGlobals = R"( -; CHECK: [[output_buffer_type]] = OpTypeStruct %uint %uint %_runtimearr_uint -; CHECK: [[output_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[output_buffer_type]] -; CHECK: [[output_buffer_var]] = OpVariable [[output_ptr_type]] StorageBuffer -)"; - -static const std::string kStreamWrite6 = R"( -; CHECK: %inst_bindless_stream_write_6 = OpFunction %void None {{%\w+}} -; CHECK: [[sw_shader_id:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_inst_idx:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_stage_info:%\w+]] = OpFunctionParameter %v4uint -; CHECK: [[sw_param_1:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_param_2:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_param_3:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_param_4:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_param_5:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_param_6:%\w+]] = OpFunctionParameter %uint -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 -; CHECK: {{%\w+}} = OpAtomicIAdd %uint {{%\w+}} %uint_4 %uint_0 %uint_13 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_13 -; CHECK: {{%\w+}} = OpArrayLength %uint [[output_buffer_var]] 2 -; CHECK: {{%\w+}} = OpULessThanEqual %bool {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} %uint_13 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_1 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_shader_id]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_2 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_inst_idx]] -; CHECK: {{%\w+}} = OpCompositeExtract %uint [[sw_stage_info]] 0 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint [[sw_stage_info]] 1 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint [[sw_stage_info]] 2 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint [[sw_stage_info]] 3 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_6 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_7 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_1]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_8 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_2]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_9 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_3]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_10 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_4]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_11 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_5]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_12 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_6]] -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpReturn -; CHECK: OpFunctionEnd -)"; -// clang-format on - -static const std::string kInputDecorations = R"( -; CHECK: OpDecorate [[desc_set_struct:%inst_bindless_DescriptorSetData]] Block -; CHECK: OpMemberDecorate [[desc_set_struct]] 0 Offset 0 -; CHECK: OpMemberDecorate [[desc_set_struct]] 1 Offset 4 -; CHECK: OpDecorate [[input_buffer_type:%inst_bindless_InputBuffer]] Block -; CHECK: OpMemberDecorate [[input_buffer_type]] 0 Offset 0 -; CHECK: OpDecorate [[input_buffer_var:%\w+]] DescriptorSet 7 -; CHECK: OpDecorate [[input_buffer_var]] Binding 1 -)"; - -static const std::string kInputGlobals = R"( -; CHECK: [[desc_set_struct]] = OpTypeStruct %uint %_runtimearr_uint -; CHECK: [[desc_set_ptr:%\w+]] = OpTypePointer PhysicalStorageBuffer [[desc_set_struct]] -; CHECK: [[desc_set_ptr_array:%\w+]] = OpTypeArray [[desc_set_ptr]] %uint_32 -; CHECK: [[input_buffer_type]] = OpTypeStruct [[desc_set_ptr_array]] -; CHECK: [[input_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[input_buffer_type]] -; CHECK: [[input_buffer_var]] = OpVariable [[input_ptr_type]] StorageBuffer -)"; - -static const std::string kCheckDesc = R"( -; CHECK: %inst_bindless_desc_check = OpFunction %bool None {{%\w+}} -; CHECK: [[di_shader_id:%\w+]] = OpFunctionParameter %uint -; CHECK: [[di_line:%\w+]] = OpFunctionParameter %uint -; CHECK: [[di_stage_info:%\w+]] = OpFunctionParameter %v4uint -; CHECK: [[di_desc_set:%\w+]] = OpFunctionParameter %uint -; CHECK: [[di_binding:%\w+]] = OpFunctionParameter %uint -; CHECK: [[di_desc_idx:%\w+]] = OpFunctionParameter %uint -; CHECK: [[di_byte_offset:%\w+]] = OpFunctionParameter %uint -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[di_error:%\w+]] = OpVariable %_ptr_Function_uint Function %uint_0 -; CHECK: [[di_param5:%\w+]] = OpVariable %_ptr_Function_uint Function %uint_0 -; CHECK: [[di_param6:%\w+]] = OpVariable %_ptr_Function_uint Function %uint_0 -; CHECK: [[di_num_bindings:%\w+]] = OpVariable %_ptr_Function_uint Function %uint_0 -; CHECK: [[di_init_status:%\w+]] = OpVariable %_ptr_Function_uint Function %uint_0 -; CHECK: [[di_desc_set_ptr:%\w+]] = OpVariable %_ptr_Function__ptr_PhysicalStorageBuffer_inst_bindless_DescriptorSetData Function -; CHECK: {{%\w+}} = OpUGreaterThanEqual %bool [[di_desc_set]] %uint_32 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore [[di_error]] %uint_1 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint [[di_error]] -; CHECK: {{%\w+}} = OpIEqual %bool {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_inst_bindless_DescriptorSetData %inst_bindless_input_buffer %uint_0 [[di_desc_set]] -; CHECK: {{%\w+}} = OpLoad %_ptr_PhysicalStorageBuffer_inst_bindless_DescriptorSetData {{%\w+}} -; CHECK: OpStore [[di_desc_set_ptr]] {{%\w+}} -; CHECK: {{%\w+}} = OpBitcast %v2uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpIEqual %bool {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpIEqual %bool {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpLogicalAnd %bool {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore [[di_error]] %uint_1 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint [[di_error]] -; CHECK: {{%\w+}} = OpIEqual %bool {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %_ptr_PhysicalStorageBuffer_inst_bindless_DescriptorSetData [[di_desc_set_ptr]] -; CHECK: {{%\w+}} = OpAccessChain %_ptr_PhysicalStorageBuffer_uint {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}} Aligned 8 -; CHECK: OpStore [[di_num_bindings]] {{%\w+}} -; CHECK: {{%\w+}} = OpUGreaterThanEqual %bool [[di_binding]] {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore [[di_error]] %uint_1 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint [[di_error]] -; CHECK: {{%\w+}} = OpIEqual %bool {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %_ptr_PhysicalStorageBuffer_inst_bindless_DescriptorSetData [[di_desc_set_ptr]] -; CHECK: {{%\w+}} = OpAccessChain %_ptr_PhysicalStorageBuffer_uint {{%\w+}} %uint_1 [[di_binding]] -; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}} Aligned 4 -; CHECK: {{%\w+}} = OpUGreaterThanEqual %bool [[di_desc_idx]] {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore [[di_error]] %uint_1 -; CHECK: OpStore [[di_param5]] {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint [[di_error]] -; CHECK: {{%\w+}} = OpLoad %uint [[di_error]] -; CHECK: {{%\w+}} = OpIEqual %bool %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %_ptr_PhysicalStorageBuffer_inst_bindless_DescriptorSetData [[di_desc_set_ptr]] -; CHECK: {{%\w+}} = OpLoad %uint [[di_num_bindings]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} [[di_binding]] -; CHECK: {{%\w+}} = OpAccessChain %_ptr_PhysicalStorageBuffer_uint {{%\w+}} %uint_1 {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}} Aligned 4 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} [[di_desc_idx]] -; CHECK: {{%\w+}} = OpAccessChain %_ptr_PhysicalStorageBuffer_uint {{%\w+}} %uint_1 {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}} Aligned 4 -; CHECK: OpStore [[di_init_status]] {{%\w+}} -; CHECK: {{%\w+}} = OpIEqual %bool {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore [[di_error]] %uint_2 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint [[di_error]] -; CHECK: {{%\w+}} = OpIEqual %bool {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint [[di_init_status]] -; CHECK: {{%\w+}} = OpUGreaterThanEqual %bool [[di_byte_offset]] {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore [[di_error]] %uint_4 -; CHECK: OpStore [[di_param5]] [[di_byte_offset]] -; CHECK: OpStore [[di_param6]] {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint [[di_error]] -; CHECK: {{%\w+}} = OpINotEqual %bool %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint [[di_param5]] -; CHECK: {{%\w+}} = OpLoad %uint [[di_param6]] -; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_6 [[di_shader_id]] [[di_line]] [[di_stage_info]] {{%\w+}} [[di_desc_set]] [[di_binding]] [[di_desc_idx]] {{%\w+}} {{%\w+}} -; CHECK: OpReturnValue %false -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpReturnValue %true -; CHECK: OpFunctionEnd +static const std::string kImportStub = R"( +;CHECK: %)" + kFuncName + R"( = OpFunction %bool None {{%\w+}} +;CHECK: OpFunctionEnd )"; TEST_F(InstBindlessTest, Simple) { @@ -296,11 +69,11 @@ TEST_F(InstBindlessTest, Simple) { const std::string entry = R"( OpCapability Shader -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpCapability Linkage %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor -; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord OpExecutionMode %MainPs OriginUpperLeft OpSource HLSL 500 )"; @@ -321,10 +94,10 @@ OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0 OpDecorate %PerViewConstantBuffer_t Block OpDecorate %g_sAniso DescriptorSet 0 OpDecorate %i_vTextureCoords Location 0 -OpDecorate %_entryPointOutput_vColor Location 0 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +OpDecorate %_entryPointOutput_vColor Location 0)" ++ kImportDeco + +R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord )"; const std::string consts_types_vars = R"( @@ -354,14 +127,10 @@ OpDecorate %_entryPointOutput_vColor Location 0 %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %MainPs = OpFunction %void None %10 @@ -375,31 +144,30 @@ OpDecorate %_entryPointOutput_vColor Location 0 %36 = OpSampledImage %26 %34 %35 %37 = OpImageSampleImplicitLod %v4float %36 %30 OpStore %_entryPointOutput_vColor %37 -; CHECK-NOT: %37 = OpImageSampleImplicitLod %v4float %36 %30 -; CHECK-NOT: OpStore %_entryPointOutput_vColor %37 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_57 {{%\w+}} %uint_3 %uint_0 %32 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %16 %33 -; CHECK: {{%\w+}} = OpSampledImage %26 {{%\w+}} %35 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %30 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: OpStore %_entryPointOutput_vColor [[phi_result]] +;CHECK-NOT: %37 = OpImageSampleImplicitLod %v4float %36 %30 +;CHECK-NOT: OpStore %_entryPointOutput_vColor %37 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_57 {{%\w+}} %uint_3 %uint_0 %32 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %16 %33 +;CHECK: {{%\w+}} = OpSampledImage %26 {{%\w+}} %35 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %30 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: OpStore %_entryPointOutput_vColor [[phi_result]] OpReturn OpFunctionEnd )"; - - const std::string output_func = kStreamWrite6 + kCheckDesc; + // clang-format on SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch( - entry + names_annots + consts_types_vars + main_func + output_func, true, - 7u, 23u); + SinglePassRunAndMatch( + entry + names_annots + consts_types_vars + kImportStub + main_func, true, + 23u); } TEST_F(InstBindlessTest, InstrumentMultipleInstructions) { @@ -436,11 +204,11 @@ TEST_F(InstBindlessTest, InstrumentMultipleInstructions) { // clang-format off const std::string defs = R"( OpCapability Shader -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +OpCapability Linkage %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor -; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord OpExecutionMode %MainPs OriginUpperLeft OpSource HLSL 500 OpName %MainPs "MainPs" @@ -459,9 +227,8 @@ OpDecorate %PerViewConstantBuffer_t Block OpDecorate %g_sAniso DescriptorSet 3 OpDecorate %i_vTextureCoords Location 0 OpDecorate %_entryPointOutput_vColor Location 0 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %10 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -489,18 +256,14 @@ OpDecorate %_entryPointOutput_vColor Location 0 %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -; CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on - const std::string main_func = - R"(%MainPs = OpFunction %void None %10 + const std::string main_func = R"( +%MainPs = OpFunction %void None %10 %30 = OpLabel %31 = OpLoad %v2float %i_vTextureCoords %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0 @@ -510,24 +273,24 @@ OpDecorate %_entryPointOutput_vColor Location 0 %36 = OpLoad %25 %g_sAniso %37 = OpSampledImage %27 %35 %36 %38 = OpImageSampleImplicitLod %v4float %37 %31 -; CHECK-NOT: %38 = OpImageSampleImplicitLod %v4float %37 %31 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_59 {{%\w+}} %uint_3 %uint_4 %33 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %17 %34 -; CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %36 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %31 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK-NOT: %38 = OpImageSampleImplicitLod %v4float %37 %31 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_60 {{%\w+}} %uint_3 %uint_4 %33 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %17 %34 +;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %36 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %31 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1 %40 = OpLoad %uint %39 %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40 @@ -535,36 +298,35 @@ OpDecorate %_entryPointOutput_vColor Location 0 %43 = OpSampledImage %27 %42 %36 %44 = OpImageSampleImplicitLod %v4float %43 %31 %45 = OpFAdd %v4float %38 %44 -; CHECK-NOT: %44 = OpImageSampleImplicitLod %v4float %43 %31 -; CHECK-NOT: %45 = OpFAdd %v4float %38 %44 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_65 {{%\w+}} %uint_3 %uint_4 %40 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %17 %41 -; CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %36 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %31 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: %45 = OpFAdd %v4float {{%\w+}} {{%\w+}} +;CHECK-NOT: %44 = OpImageSampleImplicitLod %v4float %43 %31 +;CHECK-NOT: %45 = OpFAdd %v4float %38 %44 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_66 {{%\w+}} %uint_3 %uint_4 %40 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %17 %41 +;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %36 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %31 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: %45 = OpFAdd %v4float {{%\w+}} {{%\w+}} OpStore %_entryPointOutput_vColor %45 OpReturn OpFunctionEnd )"; - - const std::string output_func = kStreamWrite6 + kCheckDesc; + // clang-format on SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + output_func, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstrumentOpImage) { @@ -576,11 +338,11 @@ TEST_F(InstBindlessTest, InstrumentOpImage) { const std::string defs = R"( OpCapability Shader OpCapability StorageImageReadWithoutFormat -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpCapability Linkage %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor -; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord OpExecutionMode %MainPs OriginUpperLeft OpSource HLSL 500 OpName %MainPs "MainPs" @@ -596,9 +358,8 @@ OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0 OpDecorate %PerViewConstantBuffer_t Block OpDecorate %i_vTextureCoords Location 0 OpDecorate %_entryPointOutput_vColor Location 0 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -622,14 +383,10 @@ OpDecorate %_entryPointOutput_vColor Location 0 %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %MainPs = OpFunction %void None %3 @@ -642,35 +399,34 @@ OpDecorate %_entryPointOutput_vColor Location 0 %75 = OpImage %20 %66 %71 = OpImageRead %v4float %75 %53 OpStore %_entryPointOutput_vColor %71 -; CHECK-NOT: %71 = OpImageRead %v4float %75 %53 -; CHECK-NOT: OpStore %_entryPointOutput_vColor %71 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_9 %64 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %39 %65 -; CHECK: {{%\w+}} = OpImage %20 {{%\w+}} -; CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %53 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: OpStore %_entryPointOutput_vColor {{%\w+}} +;CHECK-NOT: %71 = OpImageRead %v4float %75 %53 +;CHECK-NOT: OpStore %_entryPointOutput_vColor %71 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_9 %64 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %39 %65 +;CHECK: {{%\w+}} = OpImage %20 {{%\w+}} +;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %53 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: OpStore %_entryPointOutput_vColor {{%\w+}} OpReturn OpFunctionEnd )"; - - const std::string output_func = kStreamWrite6 + kCheckDesc; + // clang-format on SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + output_func, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstrumentSampledImage) { @@ -681,11 +437,11 @@ TEST_F(InstBindlessTest, InstrumentSampledImage) { // clang-format off const std::string defs = R"( OpCapability Shader -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpCapability Linkage %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor -; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord OpExecutionMode %MainPs OriginUpperLeft OpSource HLSL 500 OpName %MainPs "MainPs" @@ -701,8 +457,8 @@ OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0 OpDecorate %PerViewConstantBuffer_t Block OpDecorate %i_vTextureCoords Location 0 OpDecorate %_entryPointOutput_vColor Location 0 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -726,14 +482,10 @@ OpDecorate %_entryPointOutput_vColor Location 0 %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %MainPs = OpFunction %void None %3 @@ -745,34 +497,33 @@ OpDecorate %_entryPointOutput_vColor Location 0 %66 = OpLoad %39 %65 %71 = OpImageSampleImplicitLod %v4float %66 %53 OpStore %_entryPointOutput_vColor %71 -; CHECK-NOT: %71 = OpImageSampleImplicitLod %v4float %66 %53 -; CHECK-NOT: OpStore %_entryPointOutput_vColor %71 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_50 {{%\w+}} %uint_4 %uint_11 %64 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %39 %65 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %53 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: OpStore %_entryPointOutput_vColor {{%\w+}} +;CHECK-NOT: %71 = OpImageSampleImplicitLod %v4float %66 %53 +;CHECK-NOT: OpStore %_entryPointOutput_vColor %71 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_50 {{%\w+}} %uint_4 %uint_11 %64 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %39 %65 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %53 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: OpStore %_entryPointOutput_vColor {{%\w+}} OpReturn OpFunctionEnd )"; - - const std::string output_func = kStreamWrite6 + kCheckDesc; + // clang-format on SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + output_func, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstrumentImageWrite) { @@ -784,11 +535,11 @@ TEST_F(InstBindlessTest, InstrumentImageWrite) { const std::string defs = R"( OpCapability Shader OpCapability StorageImageWriteWithoutFormat -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpCapability Linkage %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor -; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord OpExecutionMode %MainPs OriginUpperLeft OpSource HLSL 500 OpName %MainPs "MainPs" @@ -804,9 +555,8 @@ OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0 OpDecorate %PerViewConstantBuffer_t Block OpDecorate %i_vTextureCoords Location 0 OpDecorate %_entryPointOutput_vColor Location 0 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -831,14 +581,10 @@ OpDecorate %_entryPointOutput_vColor Location 0 %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -)" + kInputGlobals + R"( -; CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input )"; - // clang-format on const std::string main_func = R"( %MainPs = OpFunction %void None %3 @@ -850,34 +596,33 @@ OpDecorate %_entryPointOutput_vColor Location 0 %66 = OpLoad %20 %65 OpImageWrite %66 %53 %80 OpStore %_entryPointOutput_vColor %80 -; CHECK-NOT: OpImageWrite %66 %53 %80 -; CHECK-NOT: OpStore %_entryPointOutput_vColor %80 -; CHECK: %32 = OpLoad %16 %31 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_30 %uint_2 %30 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %16 %31 -; CHECK: OpImageWrite {{%\w+}} %28 %19 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %_entryPointOutput_vColor %19 +;CHECK-NOT: OpImageWrite %66 %53 %80 +;CHECK-NOT: OpStore %_entryPointOutput_vColor %80 +;CHECK: %32 = OpLoad %16 %31 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_30 %uint_2 %30 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %16 %31 +;CHECK: OpImageWrite {{%\w+}} %28 %19 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %_entryPointOutput_vColor %19 OpReturn OpFunctionEnd )"; - - const std::string output_func = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + output_func, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstrumentVertexSimple) { @@ -889,7 +634,7 @@ TEST_F(InstBindlessTest, InstrumentVertexSimple) { const std::string defs = R"( OpCapability Shader OpCapability Sampled1D -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpCapability Linkage %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Vertex %main "main" %_ %coords2D @@ -908,10 +653,9 @@ OpName %foo "foo" OpMemberName %foo 0 "g_idx" OpName %__0 "" OpName %coords2D "coords2D" -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex -; CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex +;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex OpMemberDecorate %gl_PerVertex 0 BuiltIn Position OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance @@ -954,15 +698,11 @@ OpDecorate %coords2D Location 0 %v2float = OpTypeVector %float 2 %_ptr_Input_v2float = OpTypePointer Input %v2float %coords2D = OpVariable %_ptr_Input_v2float Input -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -; CHECK: %_ptr_Input_uint = OpTypePointer Input %uint -; CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input -; CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint +;CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input +;CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -980,52 +720,51 @@ OpStore %coords1D %float_1_78900003 %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37 %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0 OpStore %40 %38 -; CHECK-NOT: %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37 -; CHECK-NOT: %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0 -; CHECK-NOT: OpStore %40 %38 -; CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex -; CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_70 {{%\w+}} %uint_7 %uint_5 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %int {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %int {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_25 %texSampler1D {{%\w+}} -; CHECK: {{%\w+}} = OpLoad {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %float %coords1D -; CHECK: {{%\w+}} = OpLoad %float %lod -; CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex -; CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpBitcast %uint {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_75 {{%\w+}} %uint_2 %uint_13 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %25 %38 -; CHECK: {{%\w+}} = OpImageSampleExplicitLod %v4float {{%\w+}} %40 Lod %41 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: %43 = OpAccessChain %_ptr_Output_v4float %_ %int_0 -; CHECK: OpStore %43 {{%\w+}} +;CHECK-NOT: %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37 +;CHECK-NOT: %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0 +;CHECK-NOT: OpStore %40 %38 +;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex +;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_70 {{%\w+}} %uint_7 %uint_5 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %int {{%\w+}} +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %int {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_25 %texSampler1D {{%\w+}} +;CHECK: {{%\w+}} = OpLoad {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLoad %float %coords1D +;CHECK: {{%\w+}} = OpLoad %float %lod +;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex +;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpBitcast %uint {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_75 {{%\w+}} %uint_2 %uint_13 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %25 %38 +;CHECK: {{%\w+}} = OpImageSampleExplicitLod %v4float {{%\w+}} %40 Lod %41 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: %43 = OpAccessChain %_ptr_Output_v4float %_ %int_0 +;CHECK: OpStore %43 {{%\w+}} OpReturn OpFunctionEnd )"; - - const std::string output_func = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + output_func, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstrumentTeseSimple) { @@ -1050,10 +789,11 @@ TEST_F(InstBindlessTest, InstrumentTeseSimple) { const std::string defs = R"( OpCapability Tessellation +;CHECK: OpCapability Linkage %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint TessellationEvaluation %main "main" %_ -; CHECK: OpEntryPoint TessellationEvaluation %main "main" %_ %gl_PrimitiveID %gl_TessCoord +;CHECK: OpEntryPoint TessellationEvaluation %main "main" %_ %gl_PrimitiveID %gl_TessCoord OpExecutionMode %main Triangles OpExecutionMode %main SpacingEqual OpExecutionMode %main VertexOrderCw @@ -1085,10 +825,9 @@ OpMemberDecorate %ufoo 0 Offset 0 OpDecorate %ufoo Block OpDecorate %uniform_index_buffer DescriptorSet 9 OpDecorate %uniform_index_buffer Binding 2 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId -; CHECK: OpDecorate %gl_TessCoord BuiltIn TessCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId +;CHECK: OpDecorate %gl_TessCoord BuiltIn TessCoord %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -1112,73 +851,69 @@ OpDecorate %uniform_index_buffer Binding 2 %_ptr_Uniform_uint = OpTypePointer Uniform %uint %_ptr_StorageBuffer_v4float = OpTypePointer StorageBuffer %v4float %_ptr_Output_v4float = OpTypePointer Output %v4float -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -; CHECK: %_ptr_Input_uint = OpTypePointer Input %uint -; CHECK: %gl_PrimitiveID = OpVariable %_ptr_Input_uint Input -; CHECK: %v3float = OpTypeVector %float 3 -; CHECK: %_ptr_Input_v3float = OpTypePointer Input %v3float -; CHECK: %gl_TessCoord = OpVariable %_ptr_Input_v3float Input -; CHECK: %v3uint = OpTypeVector %uint 3 -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint +;CHECK: %gl_PrimitiveID = OpVariable %_ptr_Input_uint Input +;CHECK: %v3float = OpTypeVector %float 3 +;CHECK: %_ptr_Input_v3float = OpTypePointer Input %v3float +;CHECK: %gl_TessCoord = OpVariable %_ptr_Input_v3float Input +;CHECK: %v3uint = OpTypeVector %uint 3 +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on - const std::string main_func = R"( + const std::string main_func = + R"( %main = OpFunction %void None %3 %5 = OpLabel %25 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0 %26 = OpLoad %uint %25 %28 = OpAccessChain %_ptr_StorageBuffer_v4float %adds %26 %int_0 %29 = OpLoad %v4float %28 -; CHECK-NOT: %29 = OpLoad %v4float %28 -; CHECK: {{%\w+}} = OpLoad %uint %gl_PrimitiveID -; CHECK: {{%\w+}} = OpLoad %v3float %gl_TessCoord -; CHECK: {{%\w+}} = OpBitcast %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_2 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_62 {{%\w+}} %uint_9 %uint_2 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %27 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK-NOT: %29 = OpLoad %v4float %28 +;CHECK: {{%\w+}} = OpLoad %uint %gl_PrimitiveID +;CHECK: {{%\w+}} = OpLoad %v3float %gl_TessCoord +;CHECK: {{%\w+}} = OpBitcast %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_2 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_62 {{%\w+}} %uint_9 %uint_2 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %27 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0 OpStore %31 %29 -; CHECK-NOT: OpStore %31 %29 -; CHECK: {{%\w+}} = OpLoad %uint %gl_PrimitiveID -; CHECK: {{%\w+}} = OpLoad %v3float %gl_TessCoord -; CHECK: {{%\w+}} = OpBitcast %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_2 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_64 {{%\w+}} %uint_9 %uint_1 {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %v4float %29 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0 -; CHECK: OpStore %31 [[phi_result]] +;CHECK-NOT: OpStore %31 %29 +;CHECK: {{%\w+}} = OpLoad %uint %gl_PrimitiveID +;CHECK: {{%\w+}} = OpLoad %v3float %gl_TessCoord +;CHECK: {{%\w+}} = OpBitcast %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_2 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_64 {{%\w+}} %uint_9 %uint_1 {{%\w+}} {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %v4float %29 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0 +;CHECK: OpStore %31 [[phi_result]] OpReturn OpFunctionEnd )"; - - const std::string output_func = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + output_func, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, MultipleDebugFunctions) { @@ -1188,11 +923,11 @@ TEST_F(InstBindlessTest, MultipleDebugFunctions) { // clang-format off const std::string defs = R"( OpCapability Shader -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpCapability Linkage %2 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor -; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord OpExecutionMode %MainPs OriginUpperLeft %1 = OpString "foo5.frag" OpSource HLSL 500 %1 @@ -1221,9 +956,8 @@ OpDecorate %g_sAniso DescriptorSet 1 OpDecorate %g_sAniso Binding 3 OpDecorate %i_vTextureCoords Location 0 OpDecorate %_entryPointOutput_vColor Location 0 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %4 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -1257,14 +991,10 @@ OpDecorate %_entryPointOutput_vColor Location 0 %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string func1 = R"( %MainPs = OpFunction %void None %4 @@ -1299,44 +1029,43 @@ OpLine %1 24 0 %43 = OpAccessChain %_ptr_Function_v2float %i %int_0 %44 = OpLoad %v2float %43 %45 = OpImageSampleImplicitLod %v4float %41 %44 -; CHECK-NOT: %45 = OpImageSampleImplicitLod %v4float %41 %44 -; CHECK: {{%\w+}} = OpLoad %v2float {{%\w+}} -; CHECK: OpNoLine -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_128 {{%\w+}} %uint_1 %uint_2 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %27 {{%\w+}} -; CHECK: {{%\w+}} = OpSampledImage %37 {{%\w+}} {{%\w+}} -; CHECK: OpLine %5 24 0 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} {{%\w+}} -; CHECK: OpNoLine -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK-NOT: %45 = OpImageSampleImplicitLod %v4float %41 %44 +;CHECK: {{%\w+}} = OpLoad %v2float {{%\w+}} +;CHECK: OpNoLine +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_128 {{%\w+}} %uint_1 %uint_2 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %27 {{%\w+}} +;CHECK: {{%\w+}} = OpSampledImage %37 {{%\w+}} {{%\w+}} +;CHECK: OpLine %5 24 0 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} {{%\w+}} +;CHECK: OpNoLine +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} %47 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0 OpStore %47 %45 -; CHECK-NOT: OpStore %47 %45 -; CHECK: [[store_loc:%\w+]] = OpAccessChain %_ptr_Function_v4float %ps_output %int_0 -; CHECK: OpStore [[store_loc]] [[phi_result]] +;CHECK-NOT: OpStore %47 %45 +;CHECK: [[store_loc:%\w+]] = OpAccessChain %_ptr_Function_v4float %ps_output %int_0 +;CHECK: OpStore [[store_loc]] [[phi_result]] OpLine %1 25 0 %48 = OpLoad %PS_OUTPUT %ps_output OpReturnValue %48 OpFunctionEnd )"; - - const std::string output_func = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); SinglePassRunAndMatch( - defs + func1 + func2 + output_func, true, 7u, 23u); + defs + kImportStub + func1 + func2, true, 23u); } TEST_F(InstBindlessTest, RuntimeArray) { @@ -1348,12 +1077,12 @@ TEST_F(InstBindlessTest, RuntimeArray) { const std::string defs = R"( OpCapability Shader OpCapability RuntimeDescriptorArray +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor -; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord OpExecutionMode %MainPs OriginUpperLeft OpSource HLSL 500 OpName %MainPs "MainPs" @@ -1372,9 +1101,8 @@ OpDecorate %g_sAniso DescriptorSet 1 OpDecorate %g_sAniso Binding 3 OpDecorate %i_vTextureCoords Location 0 OpDecorate %_entryPointOutput_vColor Location 0 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -1401,12 +1129,10 @@ OpDecorate %_entryPointOutput_vColor Location 0 %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %MainPs = OpFunction %void None %3 @@ -1420,35 +1146,34 @@ OpDecorate %_entryPointOutput_vColor Location 0 %68 = OpSampledImage %39 %66 %67 %71 = OpImageSampleImplicitLod %v4float %68 %53 OpStore %_entryPointOutput_vColor %71 -; CHECK-NOT: %71 = OpImageSampleImplicitLod %v4float %68 %53 -; CHECK-NOT: OpStore %_entryPointOutput_vColor %71 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_60 {{%\w+}} %uint_1 %uint_2 %32 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %16 %33 -; CHECK: {{%\w+}} = OpSampledImage %26 {{%\w+}} %35 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %30 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result_1:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: OpStore %_entryPointOutput_vColor [[phi_result_1]] +;CHECK-NOT: %71 = OpImageSampleImplicitLod %v4float %68 %53 +;CHECK-NOT: OpStore %_entryPointOutput_vColor %71 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_60 {{%\w+}} %uint_1 %uint_2 %32 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %16 %33 +;CHECK: {{%\w+}} = OpSampledImage %26 {{%\w+}} %35 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %30 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result_1:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: OpStore %_entryPointOutput_vColor [[phi_result_1]] OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstrumentInitCheckOnScalarDescriptor) { @@ -1462,11 +1187,11 @@ TEST_F(InstBindlessTest, InstrumentInitCheckOnScalarDescriptor) { // clang-format off const std::string defs = R"( OpCapability Shader -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpCapability Linkage %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor -; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord OpExecutionMode %MainPs OriginUpperLeft OpSource HLSL 500 OpName %MainPs "MainPs" @@ -1480,9 +1205,8 @@ OpDecorate %g_sAniso DescriptorSet 1 OpDecorate %g_sAniso Binding 2 OpDecorate %i_vTextureCoords Location 0 OpDecorate %_entryPointOutput_vColor Location 0 -; check: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; check: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %8 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -1499,10 +1223,8 @@ OpDecorate %_entryPointOutput_vColor Location 0 %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %MainPs = OpFunction %void None %8 @@ -1513,43 +1235,38 @@ OpDecorate %_entryPointOutput_vColor Location 0 %23 = OpSampledImage %16 %21 %22 %24 = OpImageSampleImplicitLod %v4float %23 %20 OpStore %_entryPointOutput_vColor %24 -; CHECK-NOT: %24 = OpImageSampleImplicitLod %v4float %23 %20 -; CHECK-NOT: OpStore %_entryPointOutput_vColor %24 -; CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_40 {{%\w+}} %uint_1 %uint_2 %uint_0 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %12 %g_tColor -; CHECK: {{%\w+}} = OpSampledImage %16 {{%\w+}} %22 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: OpStore %_entryPointOutput_vColor [[phi_result]] +;CHECK-NOT: %24 = OpImageSampleImplicitLod %v4float %23 %20 +;CHECK-NOT: OpStore %_entryPointOutput_vColor %24 +;CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_40 {{%\w+}} %uint_1 %uint_2 %uint_0 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %12 %g_tColor +;CHECK: {{%\w+}} = OpSampledImage %16 {{%\w+}} %22 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: OpStore %_entryPointOutput_vColor [[phi_result]] OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, SPV14AddToEntryPoint) { const std::string text = R"( -; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]] -; CHECK: OpDecorate [[v1]] DescriptorSet 7 -; CHECK: OpDecorate [[v2]] DescriptorSet 7 -; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer -; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer OpCapability Shader OpExtension "SPV_EXT_descriptor_indexing" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var +;CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} %gl_FragCoord OpExecutionMode %foo OriginUpperLeft OpDecorate %image_var DescriptorSet 4 OpDecorate %image_var Binding 1 @@ -1592,22 +1309,19 @@ OpFunctionEnd )"; SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, SPV14AddToEntryPoints) { const std::string text = R"( -; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]] -; CHECK: OpEntryPoint Fragment {{%\w+}} "bar" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]] -; CHECK: OpDecorate [[v1]] DescriptorSet 7 -; CHECK: OpDecorate [[v2]] DescriptorSet 7 -; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer -; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer OpCapability Shader +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var +;CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} %gl_FragCoord OpEntryPoint Fragment %foo "bar" %gid %image_var %sampler_var +;CHECK: OpEntryPoint Fragment {{%\w+}} "bar" {{%\w+}} {{%\w+}} {{%\w+}} %gl_FragCoord OpExecutionMode %foo OriginUpperLeft OpDecorate %image_var DescriptorSet 3 OpDecorate %image_var Binding 2 @@ -1650,7 +1364,7 @@ OpFunctionEnd )"; SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedUBOArray) { @@ -1673,12 +1387,12 @@ OpCapability Shader OpCapability ShaderNonUniform OpCapability RuntimeDescriptorArray OpCapability UniformBufferArrayNonUniformIndexing +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %b %nu_ii -; CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord +;CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord OpExecutionMode %main OriginUpperLeft OpSource GLSL 450 OpSourceExtension "GL_EXT_nonuniform_qualifier" @@ -1698,11 +1412,10 @@ OpDecorate %nu_ii Location 0 OpDecorate %nu_ii NonUniform OpDecorate %16 NonUniform OpDecorate %20 NonUniform -; CHECK: OpDecorate {{%\w+}} NonUniform -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord -; CHECK: OpDecorate {{%\w+}} NonUniform +;CHECK: OpDecorate {{%\w+}} NonUniform +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +;CHECK: OpDecorate {{%\w+}} NonUniform %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -1717,15 +1430,12 @@ OpDecorate %20 NonUniform %nu_ii = OpVariable %_ptr_Input_int Input %int_0 = OpConstant %int 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + R"( -; CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( -; CHECK: %v4float = OpTypeVector %float 4 -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_float:%\w+]] = OpConstantNull %float +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %v4float = OpTypeVector %float 4 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_float:%\w+]] = OpConstantNull %float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -1734,34 +1444,33 @@ OpDecorate %20 NonUniform %19 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %16 %int_0 %20 = OpLoad %float %19 OpStore %b %20 -; CHECK-NOT: %20 = OpLoad %float %19 -; CHECK-NOT: OpStore %b %20 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpBitcast %uint %7 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_46 {{%\w+}} %uint_6 %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %float %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: OpStore %b [[phi_result]] +;CHECK-NOT: %20 = OpLoad %float %19 +;CHECK-NOT: OpStore %b %20 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpBitcast %uint %7 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_6 %uint_3 {{%\w+}} {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %float %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: OpStore %b [[phi_result]] OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayDeprecated) { @@ -1784,12 +1493,12 @@ OpCapability Shader OpCapability ShaderNonUniform OpCapability RuntimeDescriptorArray OpCapability StorageBufferArrayNonUniformIndexing +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %b %nu_ii -; CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord +;CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord OpExecutionMode %main OriginUpperLeft OpSource GLSL 450 OpSourceExtension "GL_EXT_nonuniform_qualifier" @@ -1809,9 +1518,8 @@ OpDecorate %nu_ii Location 0 OpDecorate %nu_ii NonUniform OpDecorate %16 NonUniform OpDecorate %20 NonUniform -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -1826,17 +1534,13 @@ OpDecorate %20 NonUniform %nu_ii = OpVariable %_ptr_Input_int Input %int_0 = OpConstant %int 0 %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float -; CHECK: %uint = OpTypeInt 32 0 -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + R"( -; CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( -; CHECK: %v4float = OpTypeVector %float 4 -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_float:%\w+]] = OpConstantNull %float +;CHECK: %uint = OpTypeInt 32 0 +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %v4float = OpTypeVector %float 4 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_float:%\w+]] = OpConstantNull %float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -1845,34 +1549,33 @@ OpDecorate %20 NonUniform %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0 %20 = OpLoad %float %19 OpStore %b %20 -; CHECK-NOT: %20 = OpLoad %float %19 -; CHECK-NOT: OpStore %b %20 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpBitcast %uint %7 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_46 {{%\w+}} %uint_7 %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %float %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: OpStore %b [[phi_result]] +;CHECK-NOT: %20 = OpLoad %float %19 +;CHECK-NOT: OpStore %b %20 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpBitcast %uint %7 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_7 %uint_3 {{%\w+}} {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %float %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: OpStore %b [[phi_result]] OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArray) { @@ -1884,12 +1587,12 @@ OpCapability Shader OpCapability ShaderNonUniform OpCapability RuntimeDescriptorArray OpCapability StorageBufferArrayNonUniformIndexing +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %b %nu_ii -; CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord +;CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord OpExecutionMode %main OriginUpperLeft OpSource GLSL 450 OpSourceExtension "GL_EXT_nonuniform_qualifier" @@ -1909,11 +1612,10 @@ OpDecorate %nu_ii Location 0 OpDecorate %nu_ii NonUniform OpDecorate %16 NonUniform OpDecorate %20 NonUniform -; CHECK: OpDecorate {{%\w+}} NonUniform -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord -; CHECK: OpDecorate {{%\w+}} NonUniform +;CHECK: OpDecorate {{%\w+}} NonUniform +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +;CHECK: OpDecorate {{%\w+}} NonUniform %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -1928,15 +1630,12 @@ OpDecorate %20 NonUniform %nu_ii = OpVariable %_ptr_Input_int Input %int_0 = OpConstant %int 0 %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float -)" + kInputGlobals + R"( -; CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( -; CHECK: %v4float = OpTypeVector %float 4 -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_float:%\w+]] = OpConstantNull %float +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %v4float = OpTypeVector %float 4 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_float:%\w+]] = OpConstantNull %float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -1945,34 +1644,33 @@ OpDecorate %20 NonUniform %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0 %20 = OpLoad %float %19 OpStore %b %20 -; CHECK-NOT: %20 = OpLoad %float %19 -; CHECK-NOT: OpStore %b %20 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpBitcast %uint %7 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %float %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: OpStore %b {{%\w+}} +;CHECK-NOT: %20 = OpLoad %float %19 +;CHECK-NOT: OpStore %b %20 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpBitcast %uint %7 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_3 {{%\w+}} {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %float %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: OpStore %b {{%\w+}} OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstInitLoadUBOScalar) { @@ -1990,12 +1688,12 @@ TEST_F(InstBindlessTest, InstInitLoadUBOScalar) { // clang-format off const std::string defs = R"( OpCapability Shader +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %b -; CHECK: OpEntryPoint Fragment %main "main" %b %gl_FragCoord +;CHECK: OpEntryPoint Fragment %main "main" %b %gl_FragCoord OpExecutionMode %main OriginUpperLeft OpSource GLSL 450 OpSourceExtension "GL_EXT_nonuniform_qualifier" @@ -2009,9 +1707,8 @@ OpMemberDecorate %uname 0 Offset 0 OpDecorate %uname Block OpDecorate %uniformBuffer DescriptorSet 7 OpDecorate %uniformBuffer Binding 3 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -2023,19 +1720,15 @@ OpDecorate %uniformBuffer Binding 3 %int = OpTypeInt 32 1 %int_0 = OpConstant %int 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -; CHECK: %int = OpTypeInt 32 1 -; CHECK: %_ptr_Uniform_float = OpTypePointer Uniform %float -; CHECK: %uint = OpTypeInt 32 0 -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + R"( -; CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( -; CHECK: %v4float = OpTypeVector %float 4 -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_float:%\w+]] = OpConstantNull %float +;CHECK: %int = OpTypeInt 32 1 +;CHECK: %_ptr_Uniform_float = OpTypePointer Uniform %float +;CHECK: %uint = OpTypeInt 32 0 +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %v4float = OpTypeVector %float 4 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_float:%\w+]] = OpConstantNull %float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -2043,33 +1736,32 @@ OpDecorate %uniformBuffer Binding 3 %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0 %16 = OpLoad %float %15 OpStore %b %16 -; CHECK-NOT: %16 = OpLoad %float %15 -; CHECK-NOT: OpStore %b %16 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_33 {{%\w+}} %uint_7 %uint_3 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %float %15 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: OpStore %b [[phi_result]] +;CHECK-NOT: %16 = OpLoad %float %15 +;CHECK-NOT: OpStore %b %16 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_33 {{%\w+}} %uint_7 %uint_3 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %float %15 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: OpStore %b [[phi_result]] OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstBoundsInitStoreUnsizedSSBOArray) { @@ -2091,12 +1783,12 @@ TEST_F(InstBindlessTest, InstBoundsInitStoreUnsizedSSBOArray) { OpCapability ShaderNonUniform OpCapability RuntimeDescriptorArray OpCapability StorageBufferArrayNonUniformIndexing +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %nu_ii %b -; CHECK: OpEntryPoint Fragment %main "main" %nu_ii %b %gl_FragCoord +;CHECK: OpEntryPoint Fragment %main "main" %nu_ii %b %gl_FragCoord OpExecutionMode %main OriginUpperLeft OpSource GLSL 450 OpSourceExtension "GL_EXT_nonuniform_qualifier" @@ -2115,9 +1807,8 @@ OpDecorate %nu_ii Location 0 OpDecorate %nu_ii NonUniform OpDecorate %14 NonUniform OpDecorate %b Location 1 -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -2132,12 +1823,9 @@ OpDecorate %b Location 1 %_ptr_Input_float = OpTypePointer Input %float %b = OpVariable %_ptr_Input_float Input %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + R"( -; CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -2146,31 +1834,30 @@ OpDecorate %b Location 1 %18 = OpLoad %float %b %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %14 %int_0 OpStore %20 %18 -; CHECK-NOT: OpStore %20 %18 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpBitcast %uint %7 -; CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_46 {{%\w+}} %uint_5 %uint_4 {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %20 %19 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: OpStore %20 %18 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpBitcast %uint %7 +;CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_5 %uint_4 {{%\w+}} {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %20 %19 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstBoundsInitLoadSizedUBOArray) { @@ -2192,12 +1879,12 @@ TEST_F(InstBindlessTest, InstBoundsInitLoadSizedUBOArray) { OpCapability Shader OpCapability ShaderNonUniform OpCapability UniformBufferArrayNonUniformIndexing +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %b %nu_ii -; CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord +;CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord OpExecutionMode %main OriginUpperLeft OpSource GLSL 450 OpSourceExtension "GL_EXT_nonuniform_qualifier" @@ -2217,10 +1904,9 @@ OpDecorate %nu_ii Location 0 OpDecorate %nu_ii NonUniform OpDecorate %18 NonUniform OpDecorate %22 NonUniform -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord -; CHECK: OpDecorate [[load_result:%\w+]] NonUniform +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +;CHECK: OpDecorate [[load_result:%\w+]] NonUniform %void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 @@ -2237,12 +1923,10 @@ OpDecorate %22 NonUniform %nu_ii = OpVariable %_ptr_Input_int Input %int_0 = OpConstant %int 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -; CHECK: [[null_float:%\w+]] = OpConstantNull %float +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_float:%\w+]] = OpConstantNull %float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -2251,34 +1935,33 @@ OpDecorate %22 NonUniform %21 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %18 %int_0 %22 = OpLoad %float %21 OpStore %b %22 -; CHECK-NOT: %22 = OpLoad %float %21 -; CHECK-NOT: OpStore %b %22 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpBitcast %uint %7 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_47 {{%\w+}} %uint_1 %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %float %22 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: OpStore %b {{%\w+}} +;CHECK-NOT: %22 = OpLoad %float %21 +;CHECK-NOT: OpStore %b %22 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpBitcast %uint %7 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_47 {{%\w+}} %uint_1 %uint_3 {{%\w+}} {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %float %22 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: OpStore %b {{%\w+}} OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, @@ -2304,12 +1987,12 @@ TEST_F(InstBindlessTest, const std::string defs = R"( OpCapability Shader OpCapability RuntimeDescriptorArray +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint GLCompute %main "main" -; CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID +;CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID OpExecutionMode %main LocalSize 1 1 1 OpSource GLSL 450 OpSourceExtension "GL_EXT_nonuniform_qualifier" @@ -2327,9 +2010,8 @@ OpDecorate %sbo Binding 0 OpDecorate %images DescriptorSet 2 OpDecorate %images Binding 1 OpDecorate %images NonWritable -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId %void = OpTypeVoid %3 = OpTypeFunction %void %uint = OpTypeInt 32 0 @@ -2351,14 +2033,12 @@ OpDecorate %images NonWritable %v4float = OpTypeVector %float 4 %uint_0 = OpConstant %uint 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: %v3uint = OpTypeVector %uint 3 -; CHECK: %_ptr_Input_v3uint = OpTypePointer Input %v3uint -; CHECK: %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input -; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: %v3uint = OpTypeVector %uint 3 +;CHECK: %_ptr_Input_v3uint = OpTypePointer Input %v3uint +;CHECK: %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input +;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -2371,65 +2051,64 @@ OpDecorate %images NonWritable %29 = OpCompositeExtract %float %27 0 %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 OpStore %31 %29 -; CHECK-NOT: OpStore %31 %29 -; CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_48 {{%\w+}} %uint_2 %uint_0 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %25 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_51 {{%\w+}} %uint_2 %uint_1 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} -; CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_54 {{%\w+}} %uint_2 %uint_0 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %31 {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: OpStore %31 %29 +;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_48 {{%\w+}} %uint_2 %uint_0 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %25 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}} +;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} +;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_51 {{%\w+}} %uint_2 %uint_1 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} +;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0 +;CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_54 {{%\w+}} %uint_2 %uint_0 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %31 {{%\w+}} +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, @@ -2454,13 +2133,13 @@ TEST_F(InstBindlessTest, const std::string defs = R"( OpCapability RuntimeDescriptorArray OpCapability RayTracingNV +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" OpExtension "SPV_NV_ray_tracing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint RayGenerationNV %main "main" -; CHECK: OpEntryPoint RayGenerationNV %main "main" [[launch_id:%\w+]] +;CHECK: OpEntryPoint RayGenerationNV %main "main" [[launch_id:%\w+]] OpSource GLSL 460 OpSourceExtension "GL_EXT_nonuniform_qualifier" OpSourceExtension "GL_NV_ray_tracing" @@ -2478,9 +2157,8 @@ OpDecorate %sbo Binding 1 OpDecorate %images DescriptorSet 3 OpDecorate %images Binding 5 OpDecorate %images NonWritable -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV +)" + kImportDeco + R"( +;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV %void = OpTypeVoid %3 = OpTypeFunction %void %uint = OpTypeInt 32 0 @@ -2502,11 +2180,9 @@ OpDecorate %images NonWritable %v4float = OpTypeVector %float 4 %uint_0 = OpConstant %uint 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -2519,65 +2195,64 @@ OpDecorate %images NonWritable %29 = OpCompositeExtract %float %27 0 %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 OpStore %31 %29 -; CHECK-NOT: OpStore %31 %29 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_49 {{%\w+}} %uint_3 %uint_1 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %25 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} -; CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_5 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} -; CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_55 {{%\w+}} %uint_3 %uint_1 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: OpStore %31 %29 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_3 %uint_1 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %25 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} +;CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}} +;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_5 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} +;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0 +;CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_3 %uint_1 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore {{%\w+}} {{%\w+}} +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, @@ -2602,13 +2277,13 @@ TEST_F(InstBindlessTest, const std::string defs = R"( OpCapability RuntimeDescriptorArray OpCapability RayTracingNV +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" OpExtension "SPV_NV_ray_tracing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint IntersectionNV %main "main" -; CHECK: OpEntryPoint IntersectionNV %main "main" [[launch_id:%\w+]] +;CHECK: OpEntryPoint IntersectionNV %main "main" [[launch_id:%\w+]] OpSource GLSL 460 OpSourceExtension "GL_EXT_nonuniform_qualifier" OpSourceExtension "GL_NV_ray_tracing" @@ -2626,9 +2301,8 @@ OpDecorate %sbo Binding 1 OpDecorate %images DescriptorSet 5 OpDecorate %images Binding 3 OpDecorate %images NonWritable -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV +)" + kImportDeco + R"( +;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV %void = OpTypeVoid %3 = OpTypeFunction %void %uint = OpTypeInt 32 0 @@ -2650,12 +2324,10 @@ OpDecorate %images NonWritable %v4float = OpTypeVector %float 4 %uint_0 = OpConstant %uint 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input -; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input +;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -2668,64 +2340,63 @@ OpDecorate %images NonWritable %29 = OpCompositeExtract %float %27 0 %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 OpStore %31 %29 -; CHECK-NOT: OpStore %31 %29 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_49 {{%\w+}} %uint_5 %uint_1 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %25 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} -; CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_5 %uint_3 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} -; CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_55 {{%\w+}} %uint_5 %uint_1 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %31 {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} +;CHECK-NOT: OpStore %31 %29 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_5 %uint_1 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %25 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} +;CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}} +;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_5 %uint_3 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}} +;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0 +;CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_5 %uint_1 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %31 {{%\w+}} +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, @@ -2750,13 +2421,13 @@ TEST_F(InstBindlessTest, const std::string defs = R"( OpCapability RuntimeDescriptorArray OpCapability RayTracingNV +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" OpExtension "SPV_NV_ray_tracing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint AnyHitNV %main "main" -; CHECK: OpEntryPoint AnyHitNV %main "main" [[launch_id:%\w+]] +;CHECK: OpEntryPoint AnyHitNV %main "main" [[launch_id:%\w+]] OpSource GLSL 460 OpSourceExtension "GL_EXT_nonuniform_qualifier" OpSourceExtension "GL_NV_ray_tracing" @@ -2774,9 +2445,8 @@ OpDecorate %sbo Binding 1 OpDecorate %images DescriptorSet 2 OpDecorate %images Binding 3 OpDecorate %images NonWritable -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV +)" + kImportDeco + R"( +;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV %void = OpTypeVoid %3 = OpTypeFunction %void %uint = OpTypeInt 32 0 @@ -2798,12 +2468,10 @@ OpDecorate %images NonWritable %v4float = OpTypeVector %float 4 %uint_0 = OpConstant %uint 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input -; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input +;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -2816,71 +2484,70 @@ OpDecorate %images NonWritable %29 = OpCompositeExtract %float %27 0 %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 OpStore %31 %29 -; CHECK-NOT: %20 = OpLoad %uint %19 -; CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20 -; CHECK-NOT: %23 = OpLoad %13 %22 -; CHECK-NOT: %27 = OpImageRead %v4float %23 %25 -; CHECK-NOT: %29 = OpCompositeExtract %float %27 0 -; CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK-NOT: OpStore %31 %29 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_49 {{%\w+}} %uint_2 %uint_1 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %25 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} -; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]] -; CHECK: %28 = OpLoad %13 %27 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_2 %uint_3 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 %27 -; CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0 -; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_55 {{%\w+}} %uint_2 %uint_1 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %31 %30 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: %20 = OpLoad %uint %19 +;CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20 +;CHECK-NOT: %23 = OpLoad %13 %22 +;CHECK-NOT: %27 = OpImageRead %v4float %23 %25 +;CHECK-NOT: %29 = OpCompositeExtract %float %27 0 +;CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK-NOT: OpStore %31 %29 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_2 %uint_1 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %25 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} +;CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]] +;CHECK: %28 = OpLoad %13 %27 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_2 %uint_3 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 %27 +;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0 +;CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_2 %uint_1 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %31 %30 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, @@ -2905,13 +2572,13 @@ TEST_F(InstBindlessTest, const std::string defs = R"( OpCapability RuntimeDescriptorArray OpCapability RayTracingNV +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" OpExtension "SPV_NV_ray_tracing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint ClosestHitNV %main "main" -; CHECK: OpEntryPoint ClosestHitNV %main "main" [[launch_id:%\w+]] +;CHECK: OpEntryPoint ClosestHitNV %main "main" [[launch_id:%\w+]] OpSource GLSL 460 OpSourceExtension "GL_EXT_nonuniform_qualifier" OpSourceExtension "GL_NV_ray_tracing" @@ -2929,9 +2596,8 @@ OpDecorate %sbo Binding 2 OpDecorate %images DescriptorSet 1 OpDecorate %images Binding 3 OpDecorate %images NonWritable -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV +)" + kImportDeco + R"( +;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV %void = OpTypeVoid %3 = OpTypeFunction %void %uint = OpTypeInt 32 0 @@ -2953,12 +2619,10 @@ OpDecorate %images NonWritable %v4float = OpTypeVector %float 4 %uint_0 = OpConstant %uint 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input -; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input +;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -2971,71 +2635,70 @@ OpDecorate %images NonWritable %29 = OpCompositeExtract %float %27 0 %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 OpStore %31 %29 -; CHECK-NOT: %20 = OpLoad %uint %19 -; CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20 -; CHECK-NOT: %23 = OpLoad %13 %22 -; CHECK-NOT: %27 = OpImageRead %v4float %23 %25 -; CHECK-NOT: %29 = OpCompositeExtract %float %27 0 -; CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK-NOT: OpStore %31 %29 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %25 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} -; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]] -; CHECK: %28 = OpLoad %13 %27 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 %27 -; CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0 -; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %31 %30 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: %20 = OpLoad %uint %19 +;CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20 +;CHECK-NOT: %23 = OpLoad %13 %22 +;CHECK-NOT: %27 = OpImageRead %v4float %23 %25 +;CHECK-NOT: %29 = OpCompositeExtract %float %27 0 +;CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK-NOT: OpStore %31 %29 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %25 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} +;CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]] +;CHECK: %28 = OpLoad %13 %27 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 %27 +;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0 +;CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %31 %30 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, @@ -3060,13 +2723,13 @@ TEST_F(InstBindlessTest, const std::string defs = R"( OpCapability RuntimeDescriptorArray OpCapability RayTracingNV +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" OpExtension "SPV_NV_ray_tracing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint MissNV %main "main" -; CHECK: OpEntryPoint MissNV %main "main" [[launch_id:%\w+]] +;CHECK: OpEntryPoint MissNV %main "main" [[launch_id:%\w+]] OpSource GLSL 460 OpSourceExtension "GL_EXT_nonuniform_qualifier" OpSourceExtension "GL_NV_ray_tracing" @@ -3084,9 +2747,8 @@ OpDecorate %sbo Binding 2 OpDecorate %images DescriptorSet 1 OpDecorate %images Binding 3 OpDecorate %images NonWritable -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV +)" + kImportDeco + R"( +;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV %void = OpTypeVoid %3 = OpTypeFunction %void %uint = OpTypeInt 32 0 @@ -3108,12 +2770,10 @@ OpDecorate %images NonWritable %v4float = OpTypeVector %float 4 %uint_0 = OpConstant %uint 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input -; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input +;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -3126,68 +2786,67 @@ OpDecorate %images NonWritable %29 = OpCompositeExtract %float %27 0 %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 OpStore %31 %29 -; CHECK-NOT: %20 = OpLoad %uint %19 -; CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20 -; CHECK-NOT: %27 = OpImageRead %v4float %23 %25 -; CHECK-NOT: %29 = OpCompositeExtract %float %27 0 -; CHECK-NOT OpStore %31 %29 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %25 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} -; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]] -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 %27 -; CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0 -; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %31 %30 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: %20 = OpLoad %uint %19 +;CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20 +;CHECK-NOT: %27 = OpImageRead %v4float %23 %25 +;CHECK-NOT: %29 = OpCompositeExtract %float %27 0 +;CHECK-NOT OpStore %31 %29 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %25 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} +;CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]] +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 %27 +;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0 +;CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %31 %30 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, @@ -3212,13 +2871,13 @@ TEST_F(InstBindlessTest, const std::string defs = R"( OpCapability RuntimeDescriptorArray OpCapability RayTracingNV +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" OpExtension "SPV_NV_ray_tracing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint CallableNV %main "main" -; CHECK: OpEntryPoint CallableNV %main "main" [[launch_id:%\w+]] +;CHECK: OpEntryPoint CallableNV %main "main" [[launch_id:%\w+]] OpSource GLSL 460 OpSourceExtension "GL_EXT_nonuniform_qualifier" OpSourceExtension "GL_NV_ray_tracing" @@ -3236,9 +2895,8 @@ OpDecorate %sbo Binding 2 OpDecorate %images DescriptorSet 1 OpDecorate %images Binding 3 OpDecorate %images NonWritable -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV +)" + kImportDeco + R"( +;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV %void = OpTypeVoid %3 = OpTypeFunction %void %uint = OpTypeInt 32 0 @@ -3260,11 +2918,9 @@ OpDecorate %images NonWritable %v4float = OpTypeVector %float 4 %uint_0 = OpConstant %uint 0 %_ptr_Uniform_float = OpTypePointer Uniform %float -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -3275,72 +2931,71 @@ OpDecorate %images NonWritable %23 = OpLoad %13 %22 %27 = OpImageRead %v4float %23 %25 %29 = OpCompositeExtract %float %27 0 -; CHECK-NOT: %20 = OpLoad %uint %19 -; CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %25 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} -; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}} -; CHECK-NOT: %23 = OpLoad %13 %22 -; CHECK-NOT: %27 = OpImageRead %v4float %23 %25 -; CHECK-NOT: %29 = OpCompositeExtract %float %27 0 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 %27 -; CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0 -; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK-NOT: %20 = OpLoad %uint %19 +;CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %25 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}} +;CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}} +;CHECK-NOT: %23 = OpLoad %13 %22 +;CHECK-NOT: %27 = OpImageRead %v4float %23 %25 +;CHECK-NOT: %29 = OpCompositeExtract %float %27 0 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 %27 +;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0 +;CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 OpStore %31 %29 -; CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 -; CHECK-NOT: OpStore %31 %29 -; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %31 %30 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1 +;CHECK-NOT: OpStore %31 %29 +;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %31 %30 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, InstBoundsInitSameBlockOpReplication) { @@ -3375,12 +3030,12 @@ TEST_F(InstBindlessTest, InstBoundsInitSameBlockOpReplication) { OpCapability Shader OpCapability ShaderNonUniformEXT OpCapability SampledImageArrayNonUniformIndexingEXT +;CHECK: OpCapability Linkage OpExtension "SPV_EXT_descriptor_indexing" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %inTexcoord %outColor -; CHECK: OpEntryPoint Fragment %main "main" %inTexcoord %outColor %gl_FragCoord +;CHECK: OpEntryPoint Fragment %main "main" %inTexcoord %outColor %gl_FragCoord OpExecutionMode %main OriginUpperLeft OpSource GLSL 450 OpSourceExtension "GL_EXT_nonuniform_qualifier" @@ -3410,12 +3065,11 @@ OpDecorate %Uniforms Block OpDecorate %uniforms DescriptorSet 1 OpDecorate %uniforms Binding 0 OpDecorate %outColor Location 0 -; CHECK: OpDecorate {{%\w+}} NonUniform -; CHECK: OpDecorate {{%\w+}} NonUniform -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord -; CHECK: OpDecorate [[desc_state_result:%\w+]] NonUniform +;CHECK: OpDecorate {{%\w+}} NonUniform +;CHECK: OpDecorate {{%\w+}} NonUniform +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +;CHECK: OpDecorate [[desc_state_result:%\w+]] NonUniform %void = OpTypeVoid %3 = OpTypeFunction %void %int = OpTypeInt 32 1 @@ -3447,11 +3101,9 @@ OpDecorate %outColor Location 0 %_ptr_Output_v4float = OpTypePointer Output %v4float %outColor = OpVariable %_ptr_Output_v4float Output %float_0 = OpConstant %float 0 -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float -; CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float )"; - // clang-format on const std::string main_func = R"( %main = OpFunction %void None %3 @@ -3468,26 +3120,26 @@ OpStore %index %int_0 %32 = OpLoad %v2float %inTexcoord %34 = OpImageSampleImplicitLod %v4float %28 %32 %36 = OpCompositeExtract %float %34 0 -; CHECK-NOT: %34 = OpImageSampleImplicitLod %v4float %28 %32 -; CHECK-NOT: %36 = OpCompositeExtract %float %34 0 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpBitcast %uint %19 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_80 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 %21 -; CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %26 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %32 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK-NOT: %34 = OpImageSampleImplicitLod %v4float %28 %32 +;CHECK-NOT: %36 = OpCompositeExtract %float %34 0 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpBitcast %uint %19 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_80 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 %21 +;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %26 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %32 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} OpStore %x %36 %39 = OpLoad %13 %uniformTex %40 = OpLoad %23 %uniformSampler @@ -3496,48 +3148,48 @@ OpStore %x %36 %47 = OpAccessChain %_ptr_Uniform_v2float %uniforms %int_0 %48 = OpLoad %v2float %47 %49 = OpFMul %v2float %42 %48 -; CHECK-NOT: %48 = OpLoad %v2float %47 -; CHECK-NOT: %49 = OpFMul %v2float %42 %48 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_88 {{%\w+}} %uint_1 %uint_0 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %v2float %47 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}} -; CHECK: %49 = OpFMul %v2float %42 [[phi_result]] +;CHECK-NOT: %48 = OpLoad %v2float %47 +;CHECK-NOT: %49 = OpFMul %v2float %42 %48 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_88 {{%\w+}} %uint_1 %uint_0 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %v2float %47 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}} +;CHECK: %49 = OpFMul %v2float %42 [[phi_result]] %50 = OpImageSampleImplicitLod %v4float %41 %49 %51 = OpCompositeExtract %float %50 0 OpStore %y %51 -; CHECK-NOT: %50 = OpImageSampleImplicitLod %v4float %41 %49 -; CHECK-NOT: %51 = OpCompositeExtract %float %50 0 -; CHECK: {{%\w+}} = OpSampledImage %27 %39 %40 -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_90 {{%\w+}} %uint_1 %uint_2 %uint_0 %uint_0 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %13 %uniformTex -; CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %40 -; CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %49 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} -; CHECK: %51 = OpCompositeExtract %float {{%\w+}} 0 +;CHECK-NOT: %50 = OpImageSampleImplicitLod %v4float %41 %49 +;CHECK-NOT: %51 = OpCompositeExtract %float %50 0 +;CHECK: {{%\w+}} = OpSampledImage %27 %39 %40 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_90 {{%\w+}} %uint_1 %uint_2 %uint_0 %uint_0 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %13 %uniformTex +;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %40 +;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %49 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} +;CHECK: %51 = OpCompositeExtract %float {{%\w+}} 0 OpStore %y %51 %54 = OpLoad %float %x %55 = OpLoad %float %y @@ -3546,12 +3198,11 @@ OpStore %outColor %57 OpReturn OpFunctionEnd )"; - - const std::string new_funcs = kStreamWrite6 + kCheckDesc; + // clang-format on SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(defs + main_func + new_funcs, - true, 7u, 23u); + SinglePassRunAndMatch(defs + kImportStub + main_func, + true, 23u); } TEST_F(InstBindlessTest, MultipleUniformNonAggregateRefsNoDescInit) { @@ -3593,147 +3244,145 @@ TEST_F(InstBindlessTest, MultipleUniformNonAggregateRefsNoDescInit) { // clang-format off const std::string text = R"( - OpCapability Shader -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor -;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord - OpExecutionMode %MainPs OriginUpperLeft - OpSource HLSL 500 - OpName %MainPs "MainPs" - OpName %PerViewPushConst_t "PerViewPushConst_t" - OpMemberName %PerViewPushConst_t 0 "g_B" - OpName %_ "" - OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t" - OpMemberName %PerViewConstantBuffer_t 0 "g_TexOff0" - OpMemberName %PerViewConstantBuffer_t 1 "g_TexOff1" - OpName %__0 "" - OpName %g_tColor "g_tColor" - OpName %g_sAniso "g_sAniso" - OpName %i_vTextureCoords "i.vTextureCoords" - OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" - OpMemberDecorate %PerViewPushConst_t 0 Offset 0 - OpDecorate %PerViewPushConst_t Block - OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0 - OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 8 - OpDecorate %PerViewConstantBuffer_t Block - OpDecorate %__0 DescriptorSet 0 - OpDecorate %__0 Binding 1 - OpDecorate %g_tColor DescriptorSet 0 - OpDecorate %g_tColor Binding 0 - OpDecorate %g_sAniso DescriptorSet 0 - OpDecorate %g_sAniso Binding 2 - OpDecorate %i_vTextureCoords Location 0 - OpDecorate %_entryPointOutput_vColor Location 0 - ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( - ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v2float = OpTypeVector %float 2 - %v4float = OpTypeVector %float 4 - %uint = OpTypeInt 32 0 +OpCapability Shader +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +OpExecutionMode %MainPs OriginUpperLeft +OpSource HLSL 500 +OpName %MainPs "MainPs" +OpName %PerViewPushConst_t "PerViewPushConst_t" +OpMemberName %PerViewPushConst_t 0 "g_B" +OpName %_ "" +OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t" +OpMemberName %PerViewConstantBuffer_t 0 "g_TexOff0" +OpMemberName %PerViewConstantBuffer_t 1 "g_TexOff1" +OpName %__0 "" +OpName %g_tColor "g_tColor" +OpName %g_sAniso "g_sAniso" +OpName %i_vTextureCoords "i.vTextureCoords" +OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" +OpMemberDecorate %PerViewPushConst_t 0 Offset 0 +OpDecorate %PerViewPushConst_t Block +OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0 +OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 8 +OpDecorate %PerViewConstantBuffer_t Block +OpDecorate %__0 DescriptorSet 0 +OpDecorate %__0 Binding 1 +OpDecorate %g_tColor DescriptorSet 0 +OpDecorate %g_tColor Binding 0 +OpDecorate %g_sAniso DescriptorSet 0 +OpDecorate %g_sAniso Binding 2 +OpDecorate %i_vTextureCoords Location 0 +OpDecorate %_entryPointOutput_vColor Location 0 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v2float = OpTypeVector %float 2 +%v4float = OpTypeVector %float 4 +%uint = OpTypeInt 32 0 %PerViewPushConst_t = OpTypeStruct %uint %_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t - %_ = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant - %int = OpTypeInt 32 1 - %int_0 = OpConstant %int 0 +%_ = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant +%int = OpTypeInt 32 1 +%int_0 = OpConstant %int 0 %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint - %bool = OpTypeBool - %uint_0 = OpConstant %uint 0 +%bool = OpTypeBool +%uint_0 = OpConstant %uint 0 %PerViewConstantBuffer_t = OpTypeStruct %v2float %v2float %_ptr_Uniform_PerViewConstantBuffer_t = OpTypePointer Uniform %PerViewConstantBuffer_t - %__0 = OpVariable %_ptr_Uniform_PerViewConstantBuffer_t Uniform +%__0 = OpVariable %_ptr_Uniform_PerViewConstantBuffer_t Uniform %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float - %int_1 = OpConstant %int 1 - %49 = OpTypeImage %float 2D 0 0 0 1 Unknown +%int_1 = OpConstant %int 1 +%49 = OpTypeImage %float 2D 0 0 0 1 Unknown %_ptr_UniformConstant_49 = OpTypePointer UniformConstant %49 - %g_tColor = OpVariable %_ptr_UniformConstant_49 UniformConstant - %53 = OpTypeSampler +%g_tColor = OpVariable %_ptr_UniformConstant_49 UniformConstant +%53 = OpTypeSampler %_ptr_UniformConstant_53 = OpTypePointer UniformConstant %53 - %g_sAniso = OpVariable %_ptr_UniformConstant_53 UniformConstant - %57 = OpTypeSampledImage %49 +%g_sAniso = OpVariable %_ptr_UniformConstant_53 UniformConstant +%57 = OpTypeSampledImage %49 %_ptr_Input_v2float = OpTypePointer Input %v2float %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output - )" + kInputGlobals + R"( - ;CHECK: %v4uint = OpTypeVector %uint 4 - )" + kOutputGlobals + R"( - ;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float - ;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input - ;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float - %MainPs = OpFunction %void None %3 - %5 = OpLabel - %69 = OpLoad %v2float %i_vTextureCoords - %82 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0 - %83 = OpLoad %uint %82 - %84 = OpINotEqual %bool %83 %uint_0 - OpSelectionMerge %91 None - OpBranchConditional %84 %85 %88 - %85 = OpLabel - %86 = OpAccessChain %_ptr_Uniform_v2float %__0 %int_0 - %87 = OpLoad %v2float %86 - ;CHECK-NOT: %87 = OpLoad %v2float %86 - ;CHECK: {{%\w+}} = OpLabel - ;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 %uint_7 - ;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord - ;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} - ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 - ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 - ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 - ;CHECK: [[desc_state_result:%\w+]] = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_72 {{%\w+}} %uint_0 %uint_1 %uint_0 {{%\w+}} - ;CHECK: OpSelectionMerge {{%\w+}} None - ;CHECK: OpBranchConditional [[desc_state_result]] {{%\w+}} {{%\w+}} - ;CHECK: {{%\w+}} = OpLabel - ;CHECK: {{%\w+}} = OpLoad %v2float %86 - ;CHECK: OpBranch {{%\w+}} - ;CHECK: {{%\w+}} = OpLabel - ;CHECK: OpBranch {{%\w+}} - ;CHECK: {{%\w+}} = OpLabel +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float + )" + kImportStub + R"( +%MainPs = OpFunction %void None %3 +%5 = OpLabel +%69 = OpLoad %v2float %i_vTextureCoords +%82 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0 +%83 = OpLoad %uint %82 +%84 = OpINotEqual %bool %83 %uint_0 +OpSelectionMerge %91 None +OpBranchConditional %84 %85 %88 +%85 = OpLabel +%86 = OpAccessChain %_ptr_Uniform_v2float %__0 %int_0 +%87 = OpLoad %v2float %86 +;CHECK-NOT: %87 = OpLoad %v2float %86 +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 %uint_7 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: [[desc_state_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_72 {{%\w+}} %uint_0 %uint_1 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional [[desc_state_result]] {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %v2float %86 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel ;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}} - OpBranch %91 - %88 = OpLabel - %89 = OpAccessChain %_ptr_Uniform_v2float %__0 %int_1 - %90 = OpLoad %v2float %89 - ;CHECK-NOT: %90 = OpLoad %v2float %89 - ;CHECK: {{%\w+}} = OpIAdd %uint %uint_8 %uint_7 - ;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord - ;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} - ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 - ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 - ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 - ;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_76 {{%\w+}} %uint_0 %uint_1 %uint_0 {{%\w+}} - ;CHECK: OpSelectionMerge {{%\w+}} None - ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} - ;CHECK: {{%\w+}} = OpLabel - ;CHECK: {{%\w+}} = OpLoad %v2float %89 - ;CHECK: OpBranch {{%\w+}} - ;CHECK: {{%\w+}} = OpLabel - ;CHECK: OpBranch {{%\w+}} - ;CHECK: {{%\w+}} = OpLabel - ;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}} - OpBranch %91 - %91 = OpLabel - %115 = OpPhi %v2float %87 %85 %90 %88 - ;CHECK-NOT: %115 = OpPhi %v2float %87 %85 %90 %88 - ;CHECK: %115 = OpPhi %v2float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} - %95 = OpFAdd %v2float %69 %115 - %96 = OpLoad %49 %g_tColor - %97 = OpLoad %53 %g_sAniso - %98 = OpSampledImage %57 %96 %97 - %100 = OpImageSampleImplicitLod %v4float %98 %95 - OpStore %_entryPointOutput_vColor %100 - OpReturn - OpFunctionEnd -)" + kStreamWrite6 + kCheckDesc; +OpBranch %91 +%88 = OpLabel +%89 = OpAccessChain %_ptr_Uniform_v2float %__0 %int_1 +%90 = OpLoad %v2float %89 +;CHECK-NOT: %90 = OpLoad %v2float %89 +;CHECK: {{%\w+}} = OpIAdd %uint %uint_8 %uint_7 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_76 {{%\w+}} %uint_0 %uint_1 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %v2float %89 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}} +OpBranch %91 +%91 = OpLabel +%115 = OpPhi %v2float %87 %85 %90 %88 +;CHECK-NOT: %115 = OpPhi %v2float %87 %85 %90 %88 +;CHECK: %115 = OpPhi %v2float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +%95 = OpFAdd %v2float %69 %115 +%96 = OpLoad %49 %g_tColor +%97 = OpLoad %53 %g_sAniso +%98 = OpSampledImage %57 %96 %97 +%100 = OpImageSampleImplicitLod %v4float %98 %95 +OpStore %_entryPointOutput_vColor %100 +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, UniformArrayRefNoDescInit) { @@ -3774,96 +3423,94 @@ TEST_F(InstBindlessTest, UniformArrayRefNoDescInit) { // clang-format off const std::string text = R"( - OpCapability Shader -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor - OpExecutionMode %MainPs OriginUpperLeft - OpSource HLSL 500 - OpName %MainPs "MainPs" - OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t" - OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal" - OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins" - OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff" - OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t" - OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants" - OpName %_ "" - OpName %PerViewPushConst_t "PerViewPushConst_t" - OpMemberName %PerViewPushConst_t 0 "g_c" - OpName %__0 "" - OpName %g_tColor "g_tColor" - OpName %g_sAniso "g_sAniso" - OpName %i_vTextureCoords "i.vTextureCoords" - OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64 - OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80 - OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0 - OpDecorate %_BindlessFastEnvMapCB_PS_t Block - OpDecorate %_ DescriptorSet 0 - OpDecorate %_ Binding 2 - OpMemberDecorate %PerViewPushConst_t 0 Offset 0 - OpDecorate %PerViewPushConst_t Block - OpDecorate %g_tColor DescriptorSet 0 - OpDecorate %g_tColor Binding 0 - OpDecorate %g_sAniso DescriptorSet 0 - OpDecorate %g_sAniso Binding 1 - OpDecorate %i_vTextureCoords Location 0 - OpDecorate %_entryPointOutput_vColor Location 0 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v2float = OpTypeVector %float 2 - %v4float = OpTypeVector %float 4 - %v3float = OpTypeVector %float 3 +OpCapability Shader +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor +OpExecutionMode %MainPs OriginUpperLeft +OpSource HLSL 500 +OpName %MainPs "MainPs" +OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t" +OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal" +OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins" +OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff" +OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t" +OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants" +OpName %_ "" +OpName %PerViewPushConst_t "PerViewPushConst_t" +OpMemberName %PerViewPushConst_t 0 "g_c" +OpName %__0 "" +OpName %g_tColor "g_tColor" +OpName %g_sAniso "g_sAniso" +OpName %i_vTextureCoords "i.vTextureCoords" +OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64 +OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80 +OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0 +OpDecorate %_BindlessFastEnvMapCB_PS_t Block +OpDecorate %_ DescriptorSet 0 +OpDecorate %_ Binding 2 +OpMemberDecorate %PerViewPushConst_t 0 Offset 0 +OpDecorate %PerViewPushConst_t Block +OpDecorate %g_tColor DescriptorSet 0 +OpDecorate %g_tColor Binding 0 +OpDecorate %g_sAniso DescriptorSet 0 +OpDecorate %g_sAniso Binding 1 +OpDecorate %i_vTextureCoords Location 0 +OpDecorate %_entryPointOutput_vColor Location 0 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v2float = OpTypeVector %float 2 +%v4float = OpTypeVector %float 4 +%v3float = OpTypeVector %float 3 %mat4v3float = OpTypeMatrix %v3float 4 %PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float - %uint = OpTypeInt 32 0 - %uint_128 = OpConstant %uint 128 +%uint = OpTypeInt 32 0 +%uint_128 = OpConstant %uint 128 %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128 %_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 %_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t - %_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform - %int = OpTypeInt 32 1 - %int_0 = OpConstant %int 0 +%_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform +%int = OpTypeInt 32 1 +%int_0 = OpConstant %int 0 %PerViewPushConst_t = OpTypeStruct %uint %_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t - %__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant +%__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint - %int_2 = OpConstant %int 2 +%int_2 = OpConstant %int 2 %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float - %46 = OpTypeImage %float 2D 0 0 0 1 Unknown +%46 = OpTypeImage %float 2D 0 0 0 1 Unknown %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46 - %g_tColor = OpVariable %_ptr_UniformConstant_46 UniformConstant - %50 = OpTypeSampler +%g_tColor = OpVariable %_ptr_UniformConstant_46 UniformConstant +%50 = OpTypeSampler %_ptr_UniformConstant_50 = OpTypePointer UniformConstant %50 - %g_sAniso = OpVariable %_ptr_UniformConstant_50 UniformConstant - %54 = OpTypeSampledImage %46 +%g_sAniso = OpVariable %_ptr_UniformConstant_50 UniformConstant +%54 = OpTypeSampledImage %46 %_ptr_Input_v2float = OpTypePointer Input %v2float %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -)" + kInputGlobals + R"( -;CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( -;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float -;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input -;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float - %MainPs = OpFunction %void None %3 - %5 = OpLabel - %66 = OpLoad %v2float %i_vTextureCoords - %79 = OpAccessChain %_ptr_PushConstant_uint %__0 %int_0 - %80 = OpLoad %uint %79 - %81 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %80 %int_2 - %82 = OpLoad %v2float %81 -;CHECK-NOT: %82 = OpLoad %v2float %81 +;CHECK: %v4uint = OpTypeVector %uint 4 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float +)" + kImportStub + R"( +%MainPs = OpFunction %void None %3 +%5 = OpLabel +%66 = OpLoad %v2float %i_vTextureCoords +%79 = OpAccessChain %_ptr_PushConstant_uint %__0 %int_0 +%80 = OpLoad %uint %79 +%81 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %80 %int_2 +%82 = OpLoad %v2float %81 +;CHECK-NOT: %82 = OpLoad %v2float %81 ;CHECK: {{%\w+}} = OpIMul %uint %uint_80 %80 ;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}} ;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_64 @@ -3873,7 +3520,7 @@ TEST_F(InstBindlessTest, UniformArrayRefNoDescInit) { ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_79 {{%\w+}} %uint_0 %uint_2 %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_79 {{%\w+}} %uint_0 %uint_2 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -3883,22 +3530,22 @@ TEST_F(InstBindlessTest, UniformArrayRefNoDescInit) { ;CHECK: OpBranch {{%\w+}} ;CHECK: {{%\w+}} = OpLabel ;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}} - %86 = OpFAdd %v2float %66 %82 -;CHECK-NOT: %86 = OpFAdd %v2float %66 %82 -;CHECK: %86 = OpFAdd %v2float %66 {{%\w+}} - %87 = OpLoad %46 %g_tColor - %88 = OpLoad %50 %g_sAniso - %89 = OpSampledImage %54 %87 %88 - %91 = OpImageSampleImplicitLod %v4float %89 %86 - OpStore %_entryPointOutput_vColor %91 - OpReturn - OpFunctionEnd -)" + kStreamWrite6 + kCheckDesc; +%86 = OpFAdd %v2float %66 %82 +;CHECK-NOT: %86 = OpFAdd %v2float %66 %82 +;CHECK: %86 = OpFAdd %v2float %66 {{%\w+}} +%87 = OpLoad %46 %g_tColor +%88 = OpLoad %50 %g_sAniso +%89 = OpSampledImage %54 %87 %88 +%91 = OpImageSampleImplicitLod %v4float %89 %86 +OpStore %_entryPointOutput_vColor %91 +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, UniformArrayRefWithDescInit) { @@ -3909,98 +3556,96 @@ TEST_F(InstBindlessTest, UniformArrayRefWithDescInit) { // clang-format off const std::string text = R"( - OpCapability Shader -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor -;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord - OpExecutionMode %MainPs OriginUpperLeft - OpSource HLSL 500 - OpName %MainPs "MainPs" - OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t" - OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal" - OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins" - OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff" - OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t" - OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants" - OpName %_ "" - OpName %PerViewPushConst_t "PerViewPushConst_t" - OpMemberName %PerViewPushConst_t 0 "g_c" - OpName %__0 "" - OpName %g_tColor "g_tColor" - OpName %g_sAniso "g_sAniso" - OpName %i_vTextureCoords "i.vTextureCoords" - OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64 - OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80 - OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0 - OpDecorate %_BindlessFastEnvMapCB_PS_t Block - OpDecorate %_ DescriptorSet 0 - OpDecorate %_ Binding 2 - OpMemberDecorate %PerViewPushConst_t 0 Offset 0 - OpDecorate %PerViewPushConst_t Block - OpDecorate %g_tColor DescriptorSet 0 - OpDecorate %g_tColor Binding 0 - OpDecorate %g_sAniso DescriptorSet 0 - OpDecorate %g_sAniso Binding 1 - OpDecorate %i_vTextureCoords Location 0 - OpDecorate %_entryPointOutput_vColor Location 0 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v2float = OpTypeVector %float 2 - %v4float = OpTypeVector %float 4 - %v3float = OpTypeVector %float 3 +OpCapability Shader +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +OpExecutionMode %MainPs OriginUpperLeft +OpSource HLSL 500 +OpName %MainPs "MainPs" +OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t" +OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal" +OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins" +OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff" +OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t" +OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants" +OpName %_ "" +OpName %PerViewPushConst_t "PerViewPushConst_t" +OpMemberName %PerViewPushConst_t 0 "g_c" +OpName %__0 "" +OpName %g_tColor "g_tColor" +OpName %g_sAniso "g_sAniso" +OpName %i_vTextureCoords "i.vTextureCoords" +OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64 +OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80 +OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0 +OpDecorate %_BindlessFastEnvMapCB_PS_t Block +OpDecorate %_ DescriptorSet 0 +OpDecorate %_ Binding 2 +OpMemberDecorate %PerViewPushConst_t 0 Offset 0 +OpDecorate %PerViewPushConst_t Block +OpDecorate %g_tColor DescriptorSet 0 +OpDecorate %g_tColor Binding 0 +OpDecorate %g_sAniso DescriptorSet 0 +OpDecorate %g_sAniso Binding 1 +OpDecorate %i_vTextureCoords Location 0 +OpDecorate %_entryPointOutput_vColor Location 0 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v2float = OpTypeVector %float 2 +%v4float = OpTypeVector %float 4 +%v3float = OpTypeVector %float 3 %mat4v3float = OpTypeMatrix %v3float 4 %PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float - %uint = OpTypeInt 32 0 - %uint_128 = OpConstant %uint 128 +%uint = OpTypeInt 32 0 +%uint_128 = OpConstant %uint 128 %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128 %_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 %_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t - %_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform - %int = OpTypeInt 32 1 - %int_0 = OpConstant %int 0 +%_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform +%int = OpTypeInt 32 1 +%int_0 = OpConstant %int 0 %PerViewPushConst_t = OpTypeStruct %uint %_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t - %__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant +%__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint - %int_2 = OpConstant %int 2 +%int_2 = OpConstant %int 2 %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float - %46 = OpTypeImage %float 2D 0 0 0 1 Unknown +%46 = OpTypeImage %float 2D 0 0 0 1 Unknown %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46 - %g_tColor = OpVariable %_ptr_UniformConstant_46 UniformConstant - %50 = OpTypeSampler +%g_tColor = OpVariable %_ptr_UniformConstant_46 UniformConstant +%50 = OpTypeSampler %_ptr_UniformConstant_50 = OpTypePointer UniformConstant %50 - %g_sAniso = OpVariable %_ptr_UniformConstant_50 UniformConstant - %54 = OpTypeSampledImage %46 +%g_sAniso = OpVariable %_ptr_UniformConstant_50 UniformConstant +%54 = OpTypeSampledImage %46 %_ptr_Input_v2float = OpTypePointer Input %v2float %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -)" + kInputGlobals + R"( ;CHECK: %v4uint = OpTypeVector %uint 4 -)" + kOutputGlobals + R"( ;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float ;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input ;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float - %MainPs = OpFunction %void None %3 - %5 = OpLabel - %66 = OpLoad %v2float %i_vTextureCoords - %79 = OpAccessChain %_ptr_PushConstant_uint %__0 %int_0 - %80 = OpLoad %uint %79 - %81 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %80 %int_2 - %82 = OpLoad %v2float %81 - %86 = OpFAdd %v2float %66 %82 +)" + kImportStub + R"( +%MainPs = OpFunction %void None %3 +%5 = OpLabel +%66 = OpLoad %v2float %i_vTextureCoords +%79 = OpAccessChain %_ptr_PushConstant_uint %__0 %int_0 +%80 = OpLoad %uint %79 +%81 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %80 %int_2 +%82 = OpLoad %v2float %81 +%86 = OpFAdd %v2float %66 %82 ;CHECK-NOT: %82 = OpLoad %v2float %81 ;CHECK-NOT: %86 = OpFAdd %v2float %66 %82 ;CHECK: {{%\w+}} = OpIMul %uint %uint_80 %80 @@ -4012,7 +3657,7 @@ TEST_F(InstBindlessTest, UniformArrayRefWithDescInit) { ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_79 {{%\w+}} %uint_0 %uint_2 %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_79 {{%\w+}} %uint_0 %uint_2 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4023,11 +3668,11 @@ TEST_F(InstBindlessTest, UniformArrayRefWithDescInit) { ;CHECK: {{%\w+}} = OpLabel ;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}} ;CHECK: %86 = OpFAdd %v2float %66 {{%\w+}} - %87 = OpLoad %46 %g_tColor - %88 = OpLoad %50 %g_sAniso - %89 = OpSampledImage %54 %87 %88 - %91 = OpImageSampleImplicitLod %v4float %89 %86 - OpStore %_entryPointOutput_vColor %91 +%87 = OpLoad %46 %g_tColor +%88 = OpLoad %50 %g_sAniso +%89 = OpSampledImage %54 %87 %88 +%91 = OpImageSampleImplicitLod %v4float %89 %86 +OpStore %_entryPointOutput_vColor %91 ;CHECK-NOT: %91 = OpImageSampleImplicitLod %v4float %89 %86 ;CHECK-NOT: OpStore %_entryPointOutput_vColor %91 ;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord @@ -4035,7 +3680,7 @@ TEST_F(InstBindlessTest, UniformArrayRefWithDescInit) { ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_84 {{%\w+}} %uint_0 %uint_0 %uint_0 %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_84 {{%\w+}} %uint_0 %uint_0 %uint_0 %uint_0 ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4048,14 +3693,14 @@ TEST_F(InstBindlessTest, UniformArrayRefWithDescInit) { ;CHECK: {{%\w+}} = OpLabel ;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} ;CHECK: OpStore %_entryPointOutput_vColor {{%\w+}} - OpReturn - OpFunctionEnd -)" + kStreamWrite6 + kCheckDesc; +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, Descriptor16BitIdxRef) { @@ -4066,88 +3711,87 @@ TEST_F(InstBindlessTest, Descriptor16BitIdxRef) { // clang-format off const std::string text = R"( - OpCapability Shader - OpCapability Int16 - OpCapability StoragePushConstant16 -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %_ %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor -;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %_ %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord - OpExecutionMode %MainPs OriginUpperLeft - OpSource HLSL 500 - OpName %MainPs "MainPs" - OpName %g_tColor "g_tColor" - OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t" - OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx" - OpName %_ "" - OpName %g_sAniso "g_sAniso" - OpName %i_vTextureCoords "i.vTextureCoords" - OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" - OpDecorate %g_tColor DescriptorSet 1 - OpDecorate %g_tColor Binding 2 - OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0 - OpDecorate %PerViewConstantBuffer_t Block - OpDecorate %g_sAniso DescriptorSet 1 - OpDecorate %g_sAniso Binding 2 - OpDecorate %i_vTextureCoords Location 0 - OpDecorate %_entryPointOutput_vColor Location 0 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %10 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v2float = OpTypeVector %float 2 - %v4float = OpTypeVector %float 4 - %int = OpTypeInt 32 1 - %int_0 = OpConstant %int 0 - %16 = OpTypeImage %float 2D 0 0 0 1 Unknown - %uint = OpTypeInt 32 0 - %uint_128 = OpConstant %uint 128 +OpCapability Shader +OpCapability Int16 +OpCapability StoragePushConstant16 +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %_ %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %_ %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +OpExecutionMode %MainPs OriginUpperLeft +OpSource HLSL 500 +OpName %MainPs "MainPs" +OpName %g_tColor "g_tColor" +OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t" +OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx" +OpName %_ "" +OpName %g_sAniso "g_sAniso" +OpName %i_vTextureCoords "i.vTextureCoords" +OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" +OpDecorate %g_tColor DescriptorSet 1 +OpDecorate %g_tColor Binding 2 +OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0 +OpDecorate %PerViewConstantBuffer_t Block +OpDecorate %g_sAniso DescriptorSet 1 +OpDecorate %g_sAniso Binding 2 +OpDecorate %i_vTextureCoords Location 0 +OpDecorate %_entryPointOutput_vColor Location 0 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%10 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v2float = OpTypeVector %float 2 +%v4float = OpTypeVector %float 4 +%int = OpTypeInt 32 1 +%int_0 = OpConstant %int 0 +%16 = OpTypeImage %float 2D 0 0 0 1 Unknown +%uint = OpTypeInt 32 0 +%uint_128 = OpConstant %uint 128 %_arr_16_uint_128 = OpTypeArray %16 %uint_128 %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128 - %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant - %ushort = OpTypeInt 16 0 +%g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant +%ushort = OpTypeInt 16 0 %PerViewConstantBuffer_t = OpTypeStruct %ushort %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t - %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant +%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant %_ptr_PushConstant_ushort = OpTypePointer PushConstant %ushort %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16 - %25 = OpTypeSampler +%25 = OpTypeSampler %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25 - %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant - %27 = OpTypeSampledImage %16 +%g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant +%27 = OpTypeSampledImage %16 %_ptr_Input_v2float = OpTypePointer Input %v2float %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float -;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input -;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float - %MainPs = OpFunction %void None %10 - %30 = OpLabel +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +)" + kImportStub + R"( +%MainPs = OpFunction %void None %10 +%30 = OpLabel ;CHECK: OpBranch %39 ;CHECK: %39 = OpLabel - %31 = OpLoad %v2float %i_vTextureCoords - %32 = OpAccessChain %_ptr_PushConstant_ushort %_ %int_0 - %33 = OpLoad %ushort %32 - %34 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %33 - %35 = OpLoad %16 %34 - %36 = OpLoad %25 %g_sAniso - %37 = OpSampledImage %27 %35 %36 - %38 = OpImageSampleImplicitLod %v4float %37 %31 - OpStore %_entryPointOutput_vColor %38 -;CHECK-NOT: %38 = OpImageSampleImplicitLod %v4float %37 %31 -;CHECK-NOT: OpStore %_entryPointOutput_vColor %38 +%31 = OpLoad %v2float %i_vTextureCoords +%32 = OpAccessChain %_ptr_PushConstant_ushort %_ %int_0 +%33 = OpLoad %ushort %32 +%34 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %33 +%35 = OpLoad %16 %34 +%36 = OpLoad %25 %g_sAniso +%37 = OpSampledImage %27 %35 %36 +%38 = OpImageSampleImplicitLod %v4float %37 %31 +OpStore %_entryPointOutput_vColor %38 +;CHECK-NOT: %38 = OpImageSampleImplicitLod %v4float %37 %31 +;CHECK-NOT: OpStore %_entryPointOutput_vColor %38 ;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord ;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 ;CHECK: {{%\w+}} = OpUConvert %uint %33 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_61 {{%\w+}} %uint_1 %uint_2 {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_61 {{%\w+}} %uint_1 %uint_2 {{%\w+}} %uint_0 ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4160,14 +3804,14 @@ TEST_F(InstBindlessTest, Descriptor16BitIdxRef) { ;CHECK: {{%\w+}} = OpLabel ;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} ;CHECK: OpStore %_entryPointOutput_vColor [[phi_result]] - OpReturn - OpFunctionEnd -)" + kStreamWrite6 + kCheckDesc; +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, UniformArray16bitIdxRef) { @@ -4208,100 +3852,99 @@ TEST_F(InstBindlessTest, UniformArray16bitIdxRef) { // clang-format off const std::string text = R"( - OpCapability Shader - OpCapability Int16 - OpCapability StoragePushConstant16 -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor -;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord - OpExecutionMode %MainPs OriginUpperLeft - OpSource HLSL 500 - OpName %MainPs "MainPs" - OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t" - OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal" - OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins" - OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff" - OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t" - OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants" - OpName %_ "" - OpName %PerViewPushConst_t "PerViewPushConst_t" - OpMemberName %PerViewPushConst_t 0 "g_c" - OpName %__0 "" - OpName %g_tColor "g_tColor" - OpName %g_sAniso "g_sAniso" - OpName %i_vTextureCoords "i.vTextureCoords" - OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48 - OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64 - OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80 - OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0 - OpDecorate %_BindlessFastEnvMapCB_PS_t Block - OpDecorate %_ DescriptorSet 0 - OpDecorate %_ Binding 0 - OpMemberDecorate %PerViewPushConst_t 0 Offset 0 - OpDecorate %PerViewPushConst_t Block - OpDecorate %g_tColor DescriptorSet 0 - OpDecorate %g_tColor Binding 0 - OpDecorate %g_sAniso DescriptorSet 0 - OpDecorate %g_sAniso Binding 0 - OpDecorate %i_vTextureCoords Location 0 - OpDecorate %_entryPointOutput_vColor Location 0 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %14 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v2float = OpTypeVector %float 2 - %v4float = OpTypeVector %float 4 - %v3float = OpTypeVector %float 3 +OpCapability Shader +OpCapability Int16 +OpCapability StoragePushConstant16 +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor +;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord +OpExecutionMode %MainPs OriginUpperLeft +OpSource HLSL 500 +OpName %MainPs "MainPs" +OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t" +OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal" +OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins" +OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff" +OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t" +OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants" +OpName %_ "" +OpName %PerViewPushConst_t "PerViewPushConst_t" +OpMemberName %PerViewPushConst_t 0 "g_c" +OpName %__0 "" +OpName %g_tColor "g_tColor" +OpName %g_sAniso "g_sAniso" +OpName %i_vTextureCoords "i.vTextureCoords" +OpName %_entryPointOutput_vColor "@entryPointOutput.vColor" +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48 +OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64 +OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80 +OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0 +OpDecorate %_BindlessFastEnvMapCB_PS_t Block +OpDecorate %_ DescriptorSet 0 +OpDecorate %_ Binding 0 +OpMemberDecorate %PerViewPushConst_t 0 Offset 0 +OpDecorate %PerViewPushConst_t Block +OpDecorate %g_tColor DescriptorSet 0 +OpDecorate %g_tColor Binding 0 +OpDecorate %g_sAniso DescriptorSet 0 +OpDecorate %g_sAniso Binding 0 +OpDecorate %i_vTextureCoords Location 0 +OpDecorate %_entryPointOutput_vColor Location 0 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%14 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v2float = OpTypeVector %float 2 +%v4float = OpTypeVector %float 4 +%v3float = OpTypeVector %float 3 %mat4v3float = OpTypeMatrix %v3float 4 %PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float - %uint = OpTypeInt 32 0 - %uint_128 = OpConstant %uint 128 +%uint = OpTypeInt 32 0 +%uint_128 = OpConstant %uint 128 %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128 %_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 %_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t - %_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform - %int = OpTypeInt 32 1 - %int_0 = OpConstant %int 0 - %ushort = OpTypeInt 16 0 +%_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform +%int = OpTypeInt 32 1 +%int_0 = OpConstant %int 0 +%ushort = OpTypeInt 16 0 %PerViewPushConst_t = OpTypeStruct %ushort %_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t - %__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant +%__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant %_ptr_PushConstant_ushort = OpTypePointer PushConstant %ushort - %int_2 = OpConstant %int 2 +%int_2 = OpConstant %int 2 %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float - %30 = OpTypeImage %float 2D 0 0 0 1 Unknown +%30 = OpTypeImage %float 2D 0 0 0 1 Unknown %_ptr_UniformConstant_30 = OpTypePointer UniformConstant %30 - %g_tColor = OpVariable %_ptr_UniformConstant_30 UniformConstant - %32 = OpTypeSampler +%g_tColor = OpVariable %_ptr_UniformConstant_30 UniformConstant +%32 = OpTypeSampler %_ptr_UniformConstant_32 = OpTypePointer UniformConstant %32 - %g_sAniso = OpVariable %_ptr_UniformConstant_32 UniformConstant - %34 = OpTypeSampledImage %30 +%g_sAniso = OpVariable %_ptr_UniformConstant_32 UniformConstant +%34 = OpTypeSampledImage %30 %_ptr_Input_v2float = OpTypePointer Input %v2float %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input %_ptr_Output_v4float = OpTypePointer Output %v4float %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float -;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input -;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float - %MainPs = OpFunction %void None %14 - %37 = OpLabel - %38 = OpLoad %v2float %i_vTextureCoords - %39 = OpAccessChain %_ptr_PushConstant_ushort %__0 %int_0 - %40 = OpLoad %ushort %39 - %41 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %40 %int_2 - %42 = OpLoad %v2float %41 - %43 = OpFAdd %v2float %38 %42 -;CHECK-NOT: %42 = OpLoad %v2float %41 -;CHECK-NOT: %43 = OpFAdd %v2float %38 %42 +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float +)" + kImportStub + R"( +%MainPs = OpFunction %void None %14 +%37 = OpLabel +%38 = OpLoad %v2float %i_vTextureCoords +%39 = OpAccessChain %_ptr_PushConstant_ushort %__0 %int_0 +%40 = OpLoad %ushort %39 +%41 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %40 %int_2 +%42 = OpLoad %v2float %41 +%43 = OpFAdd %v2float %38 %42 +;CHECK-NOT: %42 = OpLoad %v2float %41 +;CHECK-NOT: %43 = OpFAdd %v2float %38 %42 ;CHECK: {{%\w+}} = OpUConvert %uint %40 ;CHECK: {{%\w+}} = OpIMul %uint %uint_80 {{%\w+}} ;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}} @@ -4312,7 +3955,7 @@ TEST_F(InstBindlessTest, UniformArray16bitIdxRef) { ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_82 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_82 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4323,19 +3966,19 @@ TEST_F(InstBindlessTest, UniformArray16bitIdxRef) { ;CHECK: {{%\w+}} = OpLabel ;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}} ;CHECK: %43 = OpFAdd %v2float %38 {{%\w+}} - %44 = OpLoad %30 %g_tColor - %45 = OpLoad %32 %g_sAniso - %46 = OpSampledImage %34 %44 %45 - %47 = OpImageSampleImplicitLod %v4float %46 %43 - OpStore %_entryPointOutput_vColor %47 - OpReturn - OpFunctionEnd - )" + kStreamWrite6 + kCheckDesc; +%44 = OpLoad %30 %g_tColor +%45 = OpLoad %32 %g_sAniso +%46 = OpSampledImage %34 %44 %45 +%47 = OpImageSampleImplicitLod %v4float %46 %43 +OpStore %_entryPointOutput_vColor %47 +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, UniformMatrixRefRowMajor) { @@ -4359,70 +4002,69 @@ TEST_F(InstBindlessTest, UniformMatrixRefRowMajor) { // clang-format off std::string text = R"( - OpCapability Shader -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position -;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_VertexIndex %gl_InstanceIndex - OpSource GLSL 450 - OpSourceExtension "GL_EXT_scalar_block_layout" - OpName %main "main" - OpName %v_vtxResult "v_vtxResult" - OpName %Block "Block" - OpMemberName %Block 0 "var" - OpName %_ "" - OpName %a_position "a_position" - OpDecorate %v_vtxResult RelaxedPrecision - OpDecorate %v_vtxResult Location 0 - OpMemberDecorate %Block 0 RowMajor - OpMemberDecorate %Block 0 RelaxedPrecision - OpMemberDecorate %Block 0 Offset 0 - OpMemberDecorate %Block 0 MatrixStride 16 - OpDecorate %Block Block - OpDecorate %_ DescriptorSet 0 - OpDecorate %_ Binding 0 - OpDecorate %21 RelaxedPrecision -;CHECK-NOT: OpDecorate %21 RelaxedPrecision +OpCapability Shader +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position +;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %gl_VertexIndex %gl_InstanceIndex +OpSource GLSL 450 +OpSourceExtension "GL_EXT_scalar_block_layout" +OpName %main "main" +OpName %v_vtxResult "v_vtxResult" +OpName %Block "Block" +OpMemberName %Block 0 "var" +OpName %_ "" +OpName %a_position "a_position" +OpDecorate %v_vtxResult RelaxedPrecision +OpDecorate %v_vtxResult Location 0 +OpMemberDecorate %Block 0 RowMajor +OpMemberDecorate %Block 0 RelaxedPrecision +OpMemberDecorate %Block 0 Offset 0 +OpMemberDecorate %Block 0 MatrixStride 16 +OpDecorate %Block Block +OpDecorate %_ DescriptorSet 0 +OpDecorate %_ Binding 0 +OpDecorate %21 RelaxedPrecision +;CHECK-NOT: OpDecorate %21 RelaxedPrecision ;CHECK: OpDecorate %v_vtxResult RelaxedPrecision ;CHECK: OpDecorate [[phi_result:%\w+]] RelaxedPrecision - OpDecorate %a_position Location 0 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( +OpDecorate %a_position Location 0 +)" + kImportDeco + R"( ;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex ;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex ;CHECK: OpDecorate [[load_result:%\w+]] RelaxedPrecision - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 %_ptr_Output_float = OpTypePointer Output %float %v_vtxResult = OpVariable %_ptr_Output_float Output - %v2float = OpTypeVector %float 2 +%v2float = OpTypeVector %float 2 %mat4v2float = OpTypeMatrix %v2float 4 - %Block = OpTypeStruct %mat4v2float +%Block = OpTypeStruct %mat4v2float %_ptr_Uniform_Block = OpTypePointer Uniform %Block - %_ = OpVariable %_ptr_Uniform_Block Uniform - %int = OpTypeInt 32 1 - %int_0 = OpConstant %int 0 - %int_2 = OpConstant %int 2 - %uint = OpTypeInt 32 0 - %uint_1 = OpConstant %uint 1 +%_ = OpVariable %_ptr_Uniform_Block Uniform +%int = OpTypeInt 32 1 +%int_0 = OpConstant %int 0 +%int_2 = OpConstant %int 2 +%uint = OpTypeInt 32 0 +%uint_1 = OpConstant %uint 1 %_ptr_Uniform_float = OpTypePointer Uniform %float - %v4float = OpTypeVector %float 4 +%v4float = OpTypeVector %float 4 %_ptr_Input_v4float = OpTypePointer Input %v4float - %a_position = OpVariable %_ptr_Input_v4float Input -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK:%_ptr_Input_uint = OpTypePointer Input %uint -;CHECK:%gl_VertexIndex = OpVariable %_ptr_Input_uint Input -;CHECK:%gl_InstanceIndex = OpVariable %_ptr_Input_uint Input +%a_position = OpVariable %_ptr_Input_v4float Input +;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint +;CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input +;CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input ;CHECK: [[null_float:%\w+]] = OpConstantNull %float - %main = OpFunction %void None %3 - %5 = OpLabel +)" + kImportStub + R"( +%main = OpFunction %void None %3 +%5 = OpLabel ;CHECK: OpBranch {{%\w+}} ;CHECK: {{%\w+}} = OpLabel - %20 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_2 %uint_1 - %21 = OpLoad %float %20 -;CHECK-NOT: %21 = OpLoad %float %20 +%20 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_2 %uint_1 +%21 = OpLoad %float %20 +;CHECK-NOT: %21 = OpLoad %float %20 ;CHECK: {{%\w+}} = OpIMul %uint %uint_4 %int_2 ;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}} ;CHECK: {{%\w+}} = OpIMul %uint %uint_16 %uint_1 @@ -4431,7 +4073,7 @@ TEST_F(InstBindlessTest, UniformMatrixRefRowMajor) { ;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex ;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} +;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional [[desc_state]] {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4441,17 +4083,17 @@ TEST_F(InstBindlessTest, UniformMatrixRefRowMajor) { ;CHECK: OpBranch {{%\w+}} ;CHECK: {{%\w+}} = OpLabel ;CHECK: [[phi_result]] = OpPhi %float [[load_result]] {{%\w+}} [[null_float]] {{%\w+}} - OpStore %v_vtxResult %21 -;CHECK-NOT: OpStore %v_vtxResult %21$ -;CHECK: OpStore %v_vtxResult [[phi_result]] - OpReturn - OpFunctionEnd - )" + kStreamWrite6 + kCheckDesc; +OpStore %v_vtxResult %21 +;CHECK-NOT: OpStore %v_vtxResult %21$ +;CHECK: OpStore %v_vtxResult [[phi_result]] +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, UniformMatrixRefColumnMajor) { @@ -4475,67 +4117,66 @@ TEST_F(InstBindlessTest, UniformMatrixRefColumnMajor) { // clang-format off const std::string text = R"( - OpCapability Shader -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position -;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_VertexIndex %gl_InstanceIndex - OpSource GLSL 450 - OpSourceExtension "GL_EXT_scalar_block_layout" - OpName %main "main" - OpName %v_vtxResult "v_vtxResult" - OpName %Block "Block" - OpMemberName %Block 0 "var" - OpName %_ "" - OpName %a_position "a_position" - OpDecorate %v_vtxResult RelaxedPrecision - OpDecorate %v_vtxResult Location 0 - OpMemberDecorate %Block 0 ColMajor - OpMemberDecorate %Block 0 RelaxedPrecision - OpMemberDecorate %Block 0 Offset 0 - OpMemberDecorate %Block 0 MatrixStride 8 - OpDecorate %Block Block - OpDecorate %_ DescriptorSet 0 - OpDecorate %_ Binding 0 - OpDecorate %21 RelaxedPrecision -;CHECK-NOT: OpDecorate %21 RelaxedPrecision +OpCapability Shader +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position +;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %gl_VertexIndex %gl_InstanceIndex +OpSource GLSL 450 +OpSourceExtension "GL_EXT_scalar_block_layout" +OpName %main "main" +OpName %v_vtxResult "v_vtxResult" +OpName %Block "Block" +OpMemberName %Block 0 "var" +OpName %_ "" +OpName %a_position "a_position" +OpDecorate %v_vtxResult RelaxedPrecision +OpDecorate %v_vtxResult Location 0 +OpMemberDecorate %Block 0 ColMajor +OpMemberDecorate %Block 0 RelaxedPrecision +OpMemberDecorate %Block 0 Offset 0 +OpMemberDecorate %Block 0 MatrixStride 8 +OpDecorate %Block Block +OpDecorate %_ DescriptorSet 0 +OpDecorate %_ Binding 0 +OpDecorate %21 RelaxedPrecision +;CHECK-NOT: OpDecorate %21 RelaxedPrecision ;CHECK: OpDecorate %v_vtxResult RelaxedPrecision ;CHECK: OpDecorate [[phi_result:%\w+]] RelaxedPrecision - OpDecorate %a_position Location 0 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( +OpDecorate %a_position Location 0 +)" + kImportDeco + R"( ;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex ;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex ;CHECK: OpDecorate [[load_result:%\w+]] RelaxedPrecision - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 %_ptr_Output_float = OpTypePointer Output %float %v_vtxResult = OpVariable %_ptr_Output_float Output - %v2float = OpTypeVector %float 2 +%v2float = OpTypeVector %float 2 %mat4v2float = OpTypeMatrix %v2float 4 - %Block = OpTypeStruct %mat4v2float +%Block = OpTypeStruct %mat4v2float %_ptr_Uniform_Block = OpTypePointer Uniform %Block - %_ = OpVariable %_ptr_Uniform_Block Uniform - %int = OpTypeInt 32 1 - %int_0 = OpConstant %int 0 - %int_2 = OpConstant %int 2 - %uint = OpTypeInt 32 0 - %uint_1 = OpConstant %uint 1 +%_ = OpVariable %_ptr_Uniform_Block Uniform +%int = OpTypeInt 32 1 +%int_0 = OpConstant %int 0 +%int_2 = OpConstant %int 2 +%uint = OpTypeInt 32 0 +%uint_1 = OpConstant %uint 1 %_ptr_Uniform_float = OpTypePointer Uniform %float - %v4float = OpTypeVector %float 4 +%v4float = OpTypeVector %float 4 %_ptr_Input_v4float = OpTypePointer Input %v4float - %a_position = OpVariable %_ptr_Input_v4float Input -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK:%_ptr_Input_uint = OpTypePointer Input %uint -;CHECK:%gl_VertexIndex = OpVariable %_ptr_Input_uint Input -;CHECK:%gl_InstanceIndex = OpVariable %_ptr_Input_uint Input +%a_position = OpVariable %_ptr_Input_v4float Input +;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint +;CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input +;CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input ;CHECK: [[null_float:%\w+]] = OpConstantNull %float +)" + kImportStub + R"( %main = OpFunction %void None %3 - %5 = OpLabel - %20 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_2 %uint_1 - %21 = OpLoad %float %20 +%5 = OpLabel +%20 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_2 %uint_1 +%21 = OpLoad %float %20 ;CHECK-NOT: %21 = OpLoad %float %20 ;CHECK: OpBranch {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4547,7 +4188,7 @@ TEST_F(InstBindlessTest, UniformMatrixRefColumnMajor) { ;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex ;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} +;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional [[desc_state]] {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4557,18 +4198,18 @@ TEST_F(InstBindlessTest, UniformMatrixRefColumnMajor) { ;CHECK: OpBranch {{%\w+}} ;CHECK: {{%\w+}} = OpLabel ;CHECK: [[phi_result]] = OpPhi %float [[load_result]] {{%\w+}} [[null_float]] {{%\w+}} - OpStore %v_vtxResult %21 -;CHECK-NOT: OpStore %v_vtxResult %21$ +OpStore %v_vtxResult %21 +;CHECK-NOT: OpStore %v_vtxResult %21$ ;CHECK: OpStore %v_vtxResult [[phi_result]] - OpReturn - OpFunctionEnd - )" + kStreamWrite6 + kCheckDesc; +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); ValidatorOptions()->uniform_buffer_standard_layout = true; SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, UniformMatrixVecRefRowMajor) { @@ -4592,71 +4233,70 @@ TEST_F(InstBindlessTest, UniformMatrixVecRefRowMajor) { // clang-format off const std::string text = R"( - OpCapability Shader -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position -;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_VertexIndex %gl_InstanceIndex - OpSource GLSL 450 - OpSourceExtension "GL_EXT_scalar_block_layout" - OpName %main "main" - OpName %v_vtxResult "v_vtxResult" - OpName %Block "Block" - OpMemberName %Block 0 "var" - OpName %_ "" - OpName %a_position "a_position" - OpDecorate %v_vtxResult Location 0 - OpDecorate %_arr_mat2v2float_uint_4 ArrayStride 32 - OpDecorate %_arr__arr_mat2v2float_uint_4_uint_3 ArrayStride 128 - OpMemberDecorate %Block 0 RowMajor - OpMemberDecorate %Block 0 RelaxedPrecision - OpMemberDecorate %Block 0 Offset 0 - OpMemberDecorate %Block 0 MatrixStride 16 - OpDecorate %Block Block - OpDecorate %_ DescriptorSet 3 - OpDecorate %_ Binding 7 - OpDecorate %26 RelaxedPrecision -;CHECK-NOT: OpDecorate %26 RelaxedPrecision +OpCapability Shader +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position +;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %gl_VertexIndex %gl_InstanceIndex +OpSource GLSL 450 +OpSourceExtension "GL_EXT_scalar_block_layout" +OpName %main "main" +OpName %v_vtxResult "v_vtxResult" +OpName %Block "Block" +OpMemberName %Block 0 "var" +OpName %_ "" +OpName %a_position "a_position" +OpDecorate %v_vtxResult Location 0 +OpDecorate %_arr_mat2v2float_uint_4 ArrayStride 32 +OpDecorate %_arr__arr_mat2v2float_uint_4_uint_3 ArrayStride 128 +OpMemberDecorate %Block 0 RowMajor +OpMemberDecorate %Block 0 RelaxedPrecision +OpMemberDecorate %Block 0 Offset 0 +OpMemberDecorate %Block 0 MatrixStride 16 +OpDecorate %Block Block +OpDecorate %_ DescriptorSet 3 +OpDecorate %_ Binding 7 +OpDecorate %26 RelaxedPrecision +;CHECK-NOT: OpDecorate %26 RelaxedPrecision ;CHECK: OpDecorate [[phi_result:%\w+]] RelaxedPrecision - OpDecorate %a_position Location 0 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( +OpDecorate %a_position Location 0 +)" + kImportDeco + R"( ;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex ;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex ;CHECK: OpDecorate [[load_result:%\w+]] RelaxedPrecision - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v2float = OpTypeVector %float 2 +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v2float = OpTypeVector %float 2 %_ptr_Output_v2float = OpTypePointer Output %v2float %v_vtxResult = OpVariable %_ptr_Output_v2float Output %mat2v2float = OpTypeMatrix %v2float 2 - %uint = OpTypeInt 32 0 - %uint_4 = OpConstant %uint 4 +%uint = OpTypeInt 32 0 +%uint_4 = OpConstant %uint 4 %_arr_mat2v2float_uint_4 = OpTypeArray %mat2v2float %uint_4 - %uint_3 = OpConstant %uint 3 +%uint_3 = OpConstant %uint 3 %_arr__arr_mat2v2float_uint_4_uint_3 = OpTypeArray %_arr_mat2v2float_uint_4 %uint_3 - %Block = OpTypeStruct %_arr__arr_mat2v2float_uint_4_uint_3 +%Block = OpTypeStruct %_arr__arr_mat2v2float_uint_4_uint_3 %_ptr_Uniform_Block = OpTypePointer Uniform %Block - %_ = OpVariable %_ptr_Uniform_Block Uniform - %int = OpTypeInt 32 1 - %int_0 = OpConstant %int 0 - %int_2 = OpConstant %int 2 - %int_3 = OpConstant %int 3 - %int_1 = OpConstant %int 1 +%_ = OpVariable %_ptr_Uniform_Block Uniform +%int = OpTypeInt 32 1 +%int_0 = OpConstant %int 0 +%int_2 = OpConstant %int 2 +%int_3 = OpConstant %int 3 +%int_1 = OpConstant %int 1 %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float - %v4float = OpTypeVector %float 4 +%v4float = OpTypeVector %float 4 %_ptr_Input_v4float = OpTypePointer Input %v4float - %a_position = OpVariable %_ptr_Input_v4float Input -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK:%_ptr_Input_uint = OpTypePointer Input %uint -;CHECK:%gl_VertexIndex = OpVariable %_ptr_Input_uint Input -;CHECK:%gl_InstanceIndex = OpVariable %_ptr_Input_uint Input +%a_position = OpVariable %_ptr_Input_v4float Input +;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint +;CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input +;CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input ;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float - %main = OpFunction %void None %3 - %5 = OpLabel - %25 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %int_2 %int_3 %int_1 +)" + kImportStub + R"( +%main = OpFunction %void None %3 +%5 = OpLabel +%25 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %int_2 %int_3 %int_1 ;CHECK: {{%\w+}} = OpIMul %uint %uint_128 %int_2 ;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}} ;CHECK: {{%\w+}} = OpIMul %uint %uint_32 %int_3 @@ -4667,11 +4307,11 @@ TEST_F(InstBindlessTest, UniformMatrixVecRefRowMajor) { ;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex ;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} - %26 = OpLoad %v2float %25 - OpStore %v_vtxResult %26 +;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} +%26 = OpLoad %v2float %25 +OpStore %v_vtxResult %26 ;CHECK-NOT: %26 = OpLoad %v2float %25 -;CHECK-NOT: OpStore %v_vtxResult %26 +;CHECK-NOT: OpStore %v_vtxResult %26 ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional [[desc_state]] {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4682,14 +4322,14 @@ TEST_F(InstBindlessTest, UniformMatrixVecRefRowMajor) { ;CHECK: {{%\w+}} = OpLabel ;CHECK: [[phi_result]] = OpPhi %v2float [[load_result]] {{%\w+}} [[null_v2float]] {{%\w+}} ;CHECK: OpStore %v_vtxResult [[phi_result]] - OpReturn - OpFunctionEnd - )" + kStreamWrite6 + kCheckDesc; +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, ImageBufferOOBRead) { @@ -4706,61 +4346,57 @@ TEST_F(InstBindlessTest, ImageBufferOOBRead) { // clang-format off const std::string text = R"( - OpCapability Shader - OpCapability ImageBuffer -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %main "main" %x %s %ii - OpExecutionMode %main OriginUpperLeft - OpSource GLSL 450 - OpName %main "main" - OpName %x "x" - OpName %s "s" - OpName %ii "ii" - OpDecorate %x Location 11 - OpDecorate %s DescriptorSet 3 - OpDecorate %s Binding 7 - OpDecorate %s NonWritable - OpDecorate %ii Flat - OpDecorate %ii Location 13 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v4float = OpTypeVector %float 4 - %_ptr_Output_v4float = OpTypePointer Output %v4float - %x = OpVariable %_ptr_Output_v4float Output - %10 = OpTypeImage %float Buffer 0 0 0 2 R32f - %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10 - %s = OpVariable %_ptr_UniformConstant_10 UniformConstant - %int = OpTypeInt 32 1 - %_ptr_Input_int = OpTypePointer Input %int - %ii = OpVariable %_ptr_Input_int Input -;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +OpCapability Shader +OpCapability ImageBuffer +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %main "main" %x %s %ii +OpExecutionMode %main OriginUpperLeft +OpSource GLSL 450 +OpName %main "main" +OpName %x "x" +OpName %s "s" +OpName %ii "ii" +OpDecorate %x Location 11 +OpDecorate %s DescriptorSet 3 +OpDecorate %s Binding 7 +OpDecorate %s NonWritable +OpDecorate %ii Flat +OpDecorate %ii Location 13 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v4float = OpTypeVector %float 4 +%_ptr_Output_v4float = OpTypePointer Output %v4float +%x = OpVariable %_ptr_Output_v4float Output +%10 = OpTypeImage %float Buffer 0 0 0 2 R32f +%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10 +%s = OpVariable %_ptr_UniformConstant_10 UniformConstant +%int = OpTypeInt 32 1 +%_ptr_Input_int = OpTypePointer Input %int +%ii = OpVariable %_ptr_Input_int Input +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float - %main = OpFunction %void None %3 - %5 = OpLabel -;CHECK: OpBranch %19 -;CHECK: %19 = OpLabel - %13 = OpLoad %10 %s - %17 = OpLoad %int %ii - %18 = OpImageRead %v4float %13 %17 - OpStore %x %18 -;CHECK-NOT: %18 = OpImageRead %v4float %13 %17 -;CHECK-NOT: OpStore %x %18 +%main = OpFunction %void None %3 +%5 = OpLabel +;CHECK: OpBranch %19 +;CHECK: %19 = OpLabel +%13 = OpLoad %10 %s +%17 = OpLoad %int %ii +%18 = OpImageRead %v4float %13 %17 +OpStore %x %18 +;CHECK-NOT: %18 = OpImageRead %v4float %13 %17 +;CHECK-NOT: OpStore %x %18 ;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord ;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_34 {{%\w+}} %uint_3 %uint_7 %uint_0 %22 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_34 {{%\w+}} %uint_3 %uint_7 %uint_0 %22 ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4774,12 +4410,12 @@ TEST_F(InstBindlessTest, ImageBufferOOBRead) { ;CHECK: OpStore %x [[phi_result]] OpReturn OpFunctionEnd - )" + kStreamWrite6 + kCheckDesc; +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, ImageBufferOOBWrite) { @@ -4796,78 +4432,75 @@ TEST_F(InstBindlessTest, ImageBufferOOBWrite) { // clang-format off const std::string text = R"( - OpCapability Shader - OpCapability ImageBuffer -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %main "main" %s %ii %x -;CHECK: OpEntryPoint Fragment %main "main" %s %ii %x %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord - OpExecutionMode %main OriginUpperLeft - OpSource GLSL 450 - OpName %main "main" - OpName %s "s" - OpName %ii "ii" - OpName %x "x" - OpDecorate %s DescriptorSet 3 - OpDecorate %s Binding 7 - OpDecorate %s NonReadable - OpDecorate %ii Flat - OpDecorate %ii Location 13 - OpDecorate %x Location 11 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %7 = OpTypeImage %float Buffer 0 0 0 2 R32f - %_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7 - %s = OpVariable %_ptr_UniformConstant_7 UniformConstant - %int = OpTypeInt 32 1 - %_ptr_Input_int = OpTypePointer Input %int - %ii = OpVariable %_ptr_Input_int Input - %v4float = OpTypeVector %float 4 - %_ptr_Output_v4float = OpTypePointer Output %v4float - %x = OpVariable %_ptr_Output_v4float Output -;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input - %main = OpFunction %void None %3 - %5 = OpLabel -;CHECK: {{%\w+}} = OpLabel -;CHECK: OpBranch {{%\w+}} -;CHECK: %19 = OpLabel - %10 = OpLoad %7 %s - %14 = OpLoad %int %ii - %18 = OpLoad %v4float %x - OpImageWrite %10 %14 %18 -;CHECK-NOT: OpImageWrite %10 %14 %18 -;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_35 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} -;CHECK: OpSelectionMerge {{%\w+}} None -;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -;CHECK: {{%\w+}} = OpLabel -;CHECK: {{%\w+}} = OpLoad %7 %s -;CHECK: OpImageWrite {{%\w+}} %14 %18 -;CHECK: OpBranch {{%\w+}} -;CHECK: {{%\w+}} = OpLabel -;CHECK: OpBranch {{%\w+}} -;CHECK: {{%\w+}} = OpLabel +OpCapability Shader +OpCapability ImageBuffer +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %main "main" %s %ii %x +;CHECK: OpEntryPoint Fragment %main "main" %s %ii %x %gl_FragCoord +OpExecutionMode %main OriginUpperLeft +OpSource GLSL 450 +OpName %main "main" +OpName %s "s" +OpName %ii "ii" +OpName %x "x" +OpDecorate %s DescriptorSet 3 +OpDecorate %s Binding 7 +OpDecorate %s NonReadable +OpDecorate %ii Flat +OpDecorate %ii Location 13 +OpDecorate %x Location 11 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%7 = OpTypeImage %float Buffer 0 0 0 2 R32f +%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7 +%s = OpVariable %_ptr_UniformConstant_7 UniformConstant +%int = OpTypeInt 32 1 +%_ptr_Input_int = OpTypePointer Input %int +%ii = OpVariable %_ptr_Input_int Input +%v4float = OpTypeVector %float 4 +%_ptr_Output_v4float = OpTypePointer Output %v4float +%x = OpVariable %_ptr_Output_v4float Output +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +)" + kImportStub + R"( +%main = OpFunction %void None %3 +%5 = OpLabel +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: %19 = OpLabel +%10 = OpLoad %7 %s +%14 = OpLoad %int %ii +%18 = OpLoad %v4float %x +OpImageWrite %10 %14 %18 +;CHECK-NOT: OpImageWrite %10 %14 %18 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_35 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %7 %s +;CHECK: OpImageWrite {{%\w+}} %14 %18 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd -)" + kStreamWrite6 + kCheckDesc; +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, TextureBufferOOBFetch) { @@ -4884,60 +4517,56 @@ TEST_F(InstBindlessTest, TextureBufferOOBFetch) { // clang-format off const std::string text = R"( - OpCapability Shader - OpCapability SampledBuffer -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %main "main" %x %s %ii -;CHECK: OpEntryPoint Fragment %main "main" %x %s %ii %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord - OpExecutionMode %main OriginUpperLeft - OpSource GLSL 450 - OpName %main "main" - OpName %x "x" - OpName %s "s" - OpName %ii "ii" - OpDecorate %x Location 11 - OpDecorate %s DescriptorSet 3 - OpDecorate %s Binding 7 - OpDecorate %ii Flat - OpDecorate %ii Location 13 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v4float = OpTypeVector %float 4 - %_ptr_Output_v4float = OpTypePointer Output %v4float - %x = OpVariable %_ptr_Output_v4float Output - %10 = OpTypeImage %float Buffer 0 0 0 1 Unknown - %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10 - %s = OpVariable %_ptr_UniformConstant_10 UniformConstant - %int = OpTypeInt 32 1 - %_ptr_Input_int = OpTypePointer Input %int - %ii = OpVariable %_ptr_Input_int Input -;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +OpCapability Shader +OpCapability SampledBuffer +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %main "main" %x %s %ii +;CHECK: OpEntryPoint Fragment %main "main" %x %s %ii %gl_FragCoord +OpExecutionMode %main OriginUpperLeft +OpSource GLSL 450 +OpName %main "main" +OpName %x "x" +OpName %s "s" +OpName %ii "ii" +OpDecorate %x Location 11 +OpDecorate %s DescriptorSet 3 +OpDecorate %s Binding 7 +OpDecorate %ii Flat +OpDecorate %ii Location 13 +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v4float = OpTypeVector %float 4 +%_ptr_Output_v4float = OpTypePointer Output %v4float +%x = OpVariable %_ptr_Output_v4float Output +%10 = OpTypeImage %float Buffer 0 0 0 1 Unknown +%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10 +%s = OpVariable %_ptr_UniformConstant_10 UniformConstant +%int = OpTypeInt 32 1 +%_ptr_Input_int = OpTypePointer Input %int +%ii = OpVariable %_ptr_Input_int Input +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float - %main = OpFunction %void None %3 - %5 = OpLabel -;CHECK: OpBranch %19 -;CHECK: %19 = OpLabel - %13 = OpLoad %10 %s - %17 = OpLoad %int %ii - %18 = OpImageFetch %v4float %13 %17 - OpStore %x %18 -;CHECK-NOT: %18 = OpImageFetch %v4float %13 %17 -;CHECK-NOT: OpStore %x %18 +%main = OpFunction %void None %3 +%5 = OpLabel +;CHECK: OpBranch %19 +;CHECK: %19 = OpLabel +%13 = OpLoad %10 %s +%17 = OpLoad %int %ii +%18 = OpImageFetch %v4float %13 %17 +OpStore %x %18 +;CHECK-NOT: %18 = OpImageFetch %v4float %13 %17 +;CHECK-NOT: OpStore %x %18 ;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord ;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_33 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_33 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -4951,12 +4580,12 @@ TEST_F(InstBindlessTest, TextureBufferOOBFetch) { ;CHECK: OpStore %x [[phi_result]] OpReturn OpFunctionEnd - )" + kStreamWrite6 + kCheckDesc; +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, SamplerBufferOOBFetch) { @@ -4973,62 +4602,60 @@ TEST_F(InstBindlessTest, SamplerBufferOOBFetch) { // clang-format off const std::string text = R"( - OpCapability Shader - OpCapability SampledBuffer -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %main "main" %x %s %ii -;CHECK: OpEntryPoint Fragment %main "main" %x %s %ii %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord - OpExecutionMode %main OriginUpperLeft - OpSource GLSL 450 - OpName %main "main" - OpName %x "x" - OpName %s "s" - OpName %ii "ii" - OpDecorate %x Location 11 - OpDecorate %s DescriptorSet 3 - OpDecorate %s Binding 7 - OpDecorate %ii Flat - OpDecorate %ii Location 13 -;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v4float = OpTypeVector %float 4 - %_ptr_Output_v4float = OpTypePointer Output %v4float - %x = OpVariable %_ptr_Output_v4float Output - %10 = OpTypeImage %float Buffer 0 0 0 1 Unknown - %11 = OpTypeSampledImage %10 - %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11 - %s = OpVariable %_ptr_UniformConstant_11 UniformConstant - %int = OpTypeInt 32 1 - %_ptr_Input_int = OpTypePointer Input %int - %ii = OpVariable %_ptr_Input_int Input -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +OpCapability Shader +OpCapability SampledBuffer +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %main "main" %x %s %ii +;CHECK: OpEntryPoint Fragment %main "main" %x %s %ii %gl_FragCoord +OpExecutionMode %main OriginUpperLeft +OpSource GLSL 450 +OpName %main "main" +OpName %x "x" +OpName %s "s" +OpName %ii "ii" +OpDecorate %x Location 11 +OpDecorate %s DescriptorSet 3 +OpDecorate %s Binding 7 +OpDecorate %ii Flat +OpDecorate %ii Location 13 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v4float = OpTypeVector %float 4 +%_ptr_Output_v4float = OpTypePointer Output %v4float +%x = OpVariable %_ptr_Output_v4float Output +%10 = OpTypeImage %float Buffer 0 0 0 1 Unknown +%11 = OpTypeSampledImage %10 +%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11 +%s = OpVariable %_ptr_UniformConstant_11 UniformConstant +%int = OpTypeInt 32 1 +%_ptr_Input_int = OpTypePointer Input %int +%ii = OpVariable %_ptr_Input_int Input +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float - %main = OpFunction %void None %3 - %5 = OpLabel -;CHECK: OpBranch %21 -;CHECK: %21 = OpLabel - %14 = OpLoad %11 %s - %18 = OpLoad %int %ii - %19 = OpImage %10 %14 - %20 = OpImageFetch %v4float %19 %18 - OpStore %x %20 -;CHECK-NOT: %20 = OpImageFetch %v4float %19 %18 -;CHECK-NOT: OpStore %x %20 +)" + kImportStub + R"( +%main = OpFunction %void None %3 +%5 = OpLabel +;CHECK: OpBranch %21 +;CHECK: %21 = OpLabel +%14 = OpLoad %11 %s +%18 = OpLoad %int %ii +%19 = OpImage %10 %14 +%20 = OpImageFetch %v4float %19 %18 +OpStore %x %20 +;CHECK-NOT: %20 = OpImageFetch %v4float %19 %18 +;CHECK-NOT: OpStore %x %20 ;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord ;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_35 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_35 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -5043,12 +4670,12 @@ TEST_F(InstBindlessTest, SamplerBufferOOBFetch) { ;CHECK: OpStore %x [[phi_result]] OpReturn OpFunctionEnd -)" + kStreamWrite6 + kCheckDesc; +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, SamplerBufferConstructorOOBFetch) { @@ -5066,68 +4693,65 @@ TEST_F(InstBindlessTest, SamplerBufferConstructorOOBFetch) { // clang-format off const std::string text = R"( - OpCapability Shader - OpCapability SampledBuffer -;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" - %1 = OpExtInstImport "GLSL.std.450" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %main "main" %x %tBuf %s %ii -;CHECK: OpEntryPoint Fragment %main "main" %x %tBuf %s %ii %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord - OpExecutionMode %main OriginUpperLeft - OpSource GLSL 450 - OpName %main "main" - OpName %x "x" - OpName %tBuf "tBuf" - OpName %s "s" - OpName %ii "ii" - OpDecorate %x Location 11 - OpDecorate %tBuf DescriptorSet 3 - OpDecorate %tBuf Binding 7 - OpDecorate %s DescriptorSet 3 - OpDecorate %s Binding 8 - OpDecorate %ii Flat - OpDecorate %ii Location 13 -)" + kInputDecorations + kOutputDecorations + R"( -;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord - %void = OpTypeVoid - %3 = OpTypeFunction %void - %float = OpTypeFloat 32 - %v4float = OpTypeVector %float 4 - %_ptr_Output_v4float = OpTypePointer Output %v4float - %x = OpVariable %_ptr_Output_v4float Output - %10 = OpTypeImage %float Buffer 0 0 0 1 Unknown - %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10 - %tBuf = OpVariable %_ptr_UniformConstant_10 UniformConstant - %14 = OpTypeSampler - %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14 - %s = OpVariable %_ptr_UniformConstant_14 UniformConstant - %18 = OpTypeSampledImage %10 - %int = OpTypeInt 32 1 - %_ptr_Input_int = OpTypePointer Input %int - %ii = OpVariable %_ptr_Input_int Input -;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kInputGlobals + kOutputGlobals + R"( -;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint -;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float -;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input -;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float - %main = OpFunction %void None %3 - %5 = OpLabel - %13 = OpLoad %10 %tBuf - %17 = OpLoad %14 %s - %19 = OpSampledImage %18 %13 %17 - %23 = OpLoad %int %ii - %24 = OpImage %10 %19 - %25 = OpImageFetch %v4float %24 %23 - OpStore %x %25 -;CHECK-NOT: %25 = OpImageFetch %v4float %24 %23 -;CHECK-NOT: OpStore %x %25 +OpCapability Shader +OpCapability SampledBuffer +;CHECK: OpCapability Linkage +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %main "main" %x %tBuf %s %ii +;CHECK: OpEntryPoint Fragment %main "main" %x %tBuf %s %ii %gl_FragCoord +OpExecutionMode %main OriginUpperLeft +OpSource GLSL 450 +OpName %main "main" +OpName %x "x" +OpName %tBuf "tBuf" +OpName %s "s" +OpName %ii "ii" +OpDecorate %x Location 11 +OpDecorate %tBuf DescriptorSet 3 +OpDecorate %tBuf Binding 7 +OpDecorate %s DescriptorSet 3 +OpDecorate %s Binding 8 +OpDecorate %ii Flat +OpDecorate %ii Location 13 +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%v4float = OpTypeVector %float 4 +%_ptr_Output_v4float = OpTypePointer Output %v4float +%x = OpVariable %_ptr_Output_v4float Output +%10 = OpTypeImage %float Buffer 0 0 0 1 Unknown +%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10 +%tBuf = OpVariable %_ptr_UniformConstant_10 UniformConstant +%14 = OpTypeSampler +%_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14 +%s = OpVariable %_ptr_UniformConstant_14 UniformConstant +%18 = OpTypeSampledImage %10 +%int = OpTypeInt 32 1 +%_ptr_Input_int = OpTypePointer Input %int +%ii = OpVariable %_ptr_Input_int Input +;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float +;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input +;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float +%main = OpFunction %void None %3 +%5 = OpLabel +%13 = OpLoad %10 %tBuf +%17 = OpLoad %14 %s +%19 = OpSampledImage %18 %13 %17 +%23 = OpLoad %int %ii +%24 = OpImage %10 %19 +%25 = OpImageFetch %v4float %24 %23 +OpStore %x %25 +;CHECK-NOT: %25 = OpImageFetch %v4float %24 %23 +;CHECK-NOT: OpStore %x %25 ;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord ;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 ;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_43 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_43 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -5141,14 +4765,14 @@ TEST_F(InstBindlessTest, SamplerBufferConstructorOOBFetch) { ;CHECK: {{%\w+}} = OpLabel ;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}} ;CHECK: OpStore %x [[phi_result]] - OpReturn - OpFunctionEnd - )" + kStreamWrite6 + kCheckDesc; +OpReturn +OpFunctionEnd +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, DeviceBufferAddressOOB) { @@ -5172,11 +4796,13 @@ TEST_F(InstBindlessTest, DeviceBufferAddressOOB) { const std::string text = R"( OpCapability Shader OpCapability PhysicalStorageBufferAddresses +;CHECK: OpCapability Linkage ;CHECK: OpCapability Int64 +OpExtension "SPV_KHR_physical_storage_buffer" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel PhysicalStorageBuffer64 GLSL450 OpEntryPoint Vertex %main "main" %u_info -;CHECK: OpEntryPoint Vertex %main "main" %u_info %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_VertexIndex %gl_InstanceIndex +;CHECK: OpEntryPoint Vertex %main "main" %u_info %gl_VertexIndex %gl_InstanceIndex OpSource GLSL 450 OpSourceExtension "GL_EXT_buffer_reference" OpName %main "main" @@ -5194,9 +4820,8 @@ OpDecorate %_arr_int_uint_4 ArrayStride 16 OpMemberDecorate %bufStruct 0 Offset 0 OpDecorate %bufStruct Block OpDecorate %u_info DescriptorSet 0 -OpDecorate %u_info Binding 0)" - + kInputDecorations + kOutputDecorations + -R"(%void = OpTypeVoid +OpDecorate %u_info Binding 0 +%void = OpTypeVoid %3 = OpTypeFunction %void %int = OpTypeInt 32 1 %_ptr_Function_int = OpTypePointer Function %int @@ -5215,9 +4840,9 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer %bool = OpTypeBool %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_bufStruct %int_n559035791 = OpConstant %int -559035791 -%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int)" - + kInputGlobals + kOutputGlobals + -R"(%main = OpFunction %void None %3 +%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int +)" + kImportStub + R"( +%main = OpFunction %void None %3 %5 = OpLabel %i = OpVariable %_ptr_Function_int Function OpStore %i %int_0 @@ -5232,7 +4857,7 @@ OpBranch %14 ;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex ;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_55 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_56 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -5256,7 +4881,7 @@ OpBranchConditional %29 %11 %12 ;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex ;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_60 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_61 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} ;CHECK: OpSelectionMerge {{%\w+}} None ;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} ;CHECK: {{%\w+}} = OpLabel @@ -5280,13 +4905,12 @@ OpStore %i %38 OpBranch %10 %12 = OpLabel OpReturn -OpFunctionEnd)" - + kStreamWrite6 + kCheckDesc; +OpFunctionEnd)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } TEST_F(InstBindlessTest, VertexIndexOOB) { @@ -5332,9 +4956,8 @@ OpDecorate %_arr_uint_uint_1 ArrayStride 16 OpMemberDecorate %foo 0 Offset 0 OpDecorate %foo Block OpDecorate %uniform_index_buffer DescriptorSet 0 -OpDecorate %uniform_index_buffer Binding 0)" - + kInputDecorations + kOutputDecorations + -R"(%void = OpTypeVoid +OpDecorate %uniform_index_buffer Binding 0 +%void = OpTypeVoid %3 = OpTypeFunction %void %float = OpTypeFloat 32 %v2float = OpTypeVector %float 2 @@ -5370,9 +4993,9 @@ R"(%void = OpTypeVoid %foo = OpTypeStruct %_arr_uint_uint_1 %_ptr_Uniform_foo = OpTypePointer Uniform %foo %uniform_index_buffer = OpVariable %_ptr_Uniform_foo Uniform -%_ptr_Uniform_uint = OpTypePointer Uniform %uint)" - + kInputGlobals + kOutputGlobals + -R"(%main = OpFunction %void None %3 +%_ptr_Uniform_uint = OpTypePointer Uniform %uint +)" + kImportStub + R"( +%main = OpFunction %void None %3 %5 = OpLabel %18 = OpAccessChain %_ptr_Private_v2float %vertices %int_0 OpStore %18 %16 @@ -5391,36 +5014,35 @@ OpStore %26 %25 OpStore %44 %42 %52 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0 %int_0 %53 = OpLoad %uint %52 -; CHECK-NOT: %53 = OpLoad %uint %52 -; CHECK: {{%\w+}} = OpIMul %uint %uint_16 %int_0 -; CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}} -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3 -; CHECK: {{%\w+}} = OpLoad %int %gl_VertexIndex -; CHECK: {{%\w+}} = OpBitcast %uint {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_desc_check %uint_23 %uint_87 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %uint %52 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: OpStore %index [[phi_result]] +;CHECK-NOT: %53 = OpLoad %uint %52 +;CHECK: {{%\w+}} = OpIMul %uint %uint_16 %int_0 +;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}} +;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3 +;CHECK: {{%\w+}} = OpLoad %int %gl_VertexIndex +;CHECK: {{%\w+}} = OpBitcast %uint {{%\w+}} +;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_87 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}} +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %uint %52 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: OpStore %index [[phi_result]] OpStore %index %53 -; CHECK-NOT: OpStore %index %53 +;CHECK-NOT: OpStore %index %53 OpReturn ;CHECK: OpReturn -OpFunctionEnd)" - + kStreamWrite6 + kCheckDesc; +OpFunctionEnd)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7u, 23u); + SinglePassRunAndMatch(text, true, 23u); } // TODO(greg-lunarg): Add tests to verify handling of these cases: diff --git a/test/opt/inst_buff_addr_check_test.cpp b/test/opt/inst_buff_addr_check_test.cpp index 99f88f44c..72d343852 100644 --- a/test/opt/inst_buff_addr_check_test.cpp +++ b/test/opt/inst_buff_addr_check_test.cpp @@ -26,123 +26,14 @@ namespace spvtools { namespace opt { namespace { -static const std::string kOutputDecorations = R"( -; CHECK: OpDecorate [[output_buffer_type:%inst_buff_addr_OutputBuffer]] Block -; CHECK: OpMemberDecorate [[output_buffer_type]] 0 Offset 0 -; CHECK: OpMemberDecorate [[output_buffer_type]] 1 Offset 4 -; CHECK: OpDecorate [[output_buffer_var:%\w+]] DescriptorSet 7 -; CHECK: OpDecorate [[output_buffer_var]] Binding 0 +static const std::string kFuncName = "inst_buff_addr_search_and_test"; +static const std::string kImportDeco = R"( +;CHECK: OpDecorate %)" + kFuncName + R"( LinkageAttributes ")" + + kFuncName + R"(" Import )"; - -static const std::string kOutputGlobals = R"( -; CHECK: [[output_buffer_type]] = OpTypeStruct %uint %uint %_runtimearr_uint -; CHECK: [[output_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[output_buffer_type]] -; CHECK: [[output_buffer_var]] = OpVariable [[output_ptr_type]] StorageBuffer -)"; - -static const std::string kStreamWrite3 = R"( -; CHECK: %inst_buff_addr_stream_write_3 = OpFunction %void None {{%\w+}} -; CHECK: [[sw_shader_id:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_inst_idx:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_stage_info:%\w+]] = OpFunctionParameter %v4uint -; CHECK: [[sw_param_1:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_param_2:%\w+]] = OpFunctionParameter %uint -; CHECK: [[sw_param_3:%\w+]] = OpFunctionParameter %uint -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 -; CHECK: {{%\w+}} = OpAtomicIAdd %uint {{%\w+}} %uint_4 %uint_0 %uint_10 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_10 -; CHECK: {{%\w+}} = OpArrayLength %uint [[output_buffer_var]] 2 -; CHECK: {{%\w+}} = OpULessThanEqual %bool {{%\w+}} {{%\w+}} -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} %uint_10 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_1 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_shader_id]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_2 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_inst_idx]] -; CHECK: {{%\w+}} = OpCompositeExtract %uint [[sw_stage_info]] 0 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint [[sw_stage_info]] 1 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint [[sw_stage_info]] 2 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint [[sw_stage_info]] 3 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_6 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_7 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_1]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_8 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_2]] -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_9 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}} -; CHECK: OpStore {{%\w+}} [[sw_param_3]] -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpReturn -; CHECK: OpFunctionEnd -)"; - -static const std::string kInputDecorations = R"( -; CHECK: OpDecorate [[input_buffer_type:%inst_buff_addr_InputBuffer]] Block -; CHECK: OpMemberDecorate [[input_buffer_type]] 0 Offset 0 -; CHECK: OpDecorate [[input_buffer_var:%\w+]] DescriptorSet 7 -; CHECK: OpDecorate [[input_buffer_var]] Binding 2 -)"; - -static const std::string kInputGlobals = R"( -; CHECK: [[input_buffer_type]] = OpTypeStruct %_runtimearr_ulong -; CHECK: [[input_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[input_buffer_type]] -; CHECK: [[input_buffer_var]] = OpVariable [[input_ptr_type]] StorageBuffer -)"; - -static const std::string kSearchAndTest = R"( -; CHECK: {{%\w+}} = OpFunction %bool None {{%\w+}} -; CHECK: [[param_1:%\w+]] = OpFunctionParameter %ulong -; CHECK: [[param_2:%\w+]] = OpFunctionParameter %uint -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpPhi %uint %uint_1 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: OpLoopMerge {{%\w+}} {{%\w+}} None -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_1 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_ulong [[input_buffer_var]] %uint_0 {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %ulong {{%\w+}} -; CHECK: {{%\w+}} = OpUGreaterThan %bool {{%\w+}} [[param_1]] -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpISub %uint {{%\w+}} %uint_1 -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_ulong [[input_buffer_var]] %uint_0 {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %ulong {{%\w+}} -; CHECK: {{%\w+}} = OpISub %ulong [[param_1]] {{%\w+}} -; CHECK: {{%\w+}} = OpUConvert %ulong [[param_2]] -; CHECK: {{%\w+}} = OpIAdd %ulong {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_ulong [[input_buffer_var]] %uint_0 %uint_0 -; CHECK: {{%\w+}} = OpLoad %ulong {{%\w+}} -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpISub %uint {{%\w+}} %uint_1 -; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_ulong [[input_buffer_var]] %uint_0 {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %ulong {{%\w+}} -; CHECK: {{%\w+}} = OpULessThanEqual %bool {{%\w+}} {{%\w+}} -; CHECK: OpReturnValue {{%\w+}} -; CHECK: OpFunctionEnd +static const std::string kImportStub = R"( +;CHECK: %)" + kFuncName + R"( = OpFunction %bool None {{%\w+}} +;CHECK: OpFunctionEnd )"; // clang-format on @@ -171,13 +62,13 @@ TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferStore) { const std::string defs = R"( OpCapability Shader OpCapability PhysicalStorageBufferAddresses -; CHECK: OpCapability Int64 +;CHECK: OpCapability Int64 OpExtension "SPV_EXT_physical_storage_buffer" -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel PhysicalStorageBuffer64 GLSL450 OpEntryPoint GLCompute %main "main" -; CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID +;CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID OpExecutionMode %main LocalSize 1 1 1 OpSource GLSL 450 OpSourceExtension "GL_EXT_buffer_reference" @@ -202,11 +93,8 @@ OpMemberDecorate %bufStruct 1 Offset 32 OpDecorate %bufStruct Block OpDecorate %u_info DescriptorSet 0 OpDecorate %u_info Binding 0 -; CHECK: OpDecorate %_runtimearr_ulong ArrayStride 8 -)" + kInputDecorations + R"( -; CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kOutputDecorations + R"( +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId )"; const std::string globals = R"( @@ -227,17 +115,11 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer %int_1 = OpConstant %int 1 %int_3239 = OpConstant %int 3239 %_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int -; CHECK: %ulong = OpTypeInt 64 0 -; CHECK: %bool = OpTypeBool -; CHECK: %_runtimearr_ulong = OpTypeRuntimeArray %ulong -)" + kInputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong -; CHECK: %v3uint = OpTypeVector %uint 3 -; CHECK: %_ptr_Input_v3uint = OpTypePointer Input %v3uint -; CHECK: %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input -; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint -)" + kOutputGlobals + R"( -; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint +;CHECK: %ulong = OpTypeInt 64 0 +;CHECK: %bool = OpTypeBool +;CHECK: %v3uint = OpTypeVector %uint 3 +;CHECK: %_ptr_Input_v3uint = OpTypePointer Input %v3uint +;CHECK: %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input )"; // clang-format off @@ -247,41 +129,35 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer %17 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0 %18 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %17 %22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %18 %int_1 -; CHECK-NOT: %17 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0 -; CHECK-NOT: %18 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %17 -; CHECK-NOT: %22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %18 %int_1 -; CHECK: %20 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0 -; CHECK: %21 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %20 -; CHECK: %22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %21 %int_1 -; CHECK: {{%\w+}} = OpConvertPtrToU %ulong %22 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_buff_addr_search_and_test {{%\w+}} %uint_4 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: %17 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0 +;CHECK-NOT: %18 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %17 +;CHECK-NOT: %22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %18 %int_1 +;CHECK: %20 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0 +;CHECK: %21 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %20 +;CHECK: %22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %21 %int_1 +;CHECK: {{%\w+}} = OpConvertPtrToU %ulong %22 +;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} {{%\w+}} %uint_4 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpStore %22 %int_3239 Aligned 16 -; CHECK: OpStore %22 %int_3239 Aligned 16 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpShiftRightLogical %ulong {{%\w+}} %uint_32 -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %void %inst_buff_addr_stream_write_3 %uint_23 %uint_48 {{%\w+}} %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %22 %int_3239 Aligned 16 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - const std::string output_funcs = kSearchAndTest + kStreamWrite3; - // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); SinglePassRunAndMatch( - defs + decorates + globals + main_func + output_funcs, true, 7u, 23u); + defs + decorates + globals + kImportStub + main_func, true, 23u); } TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferLoadAndStore) { @@ -311,7 +187,7 @@ TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferLoadAndStore) { const std::string defs = R"( OpCapability Shader OpCapability PhysicalStorageBufferAddresses -; CHECK: OpCapability Int64 +;CHECK: OpCapability Int64 OpExtension "SPV_EXT_physical_storage_buffer" OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" @@ -321,7 +197,7 @@ OpExecutionMode %main LocalSize 1 1 1 OpSource GLSL 450 OpSourceExtension "GL_EXT_buffer_reference" OpName %main "main" -; CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID +;CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID OpName %blockType "blockType" OpMemberName %blockType 0 "x" OpMemberName %blockType 1 "next" @@ -339,12 +215,9 @@ OpMemberDecorate %rootBlock 0 Offset 0 OpDecorate %rootBlock Block OpDecorate %r DescriptorSet 0 OpDecorate %r Binding 0 -; CHECK: OpDecorate %_runtimearr_ulong ArrayStride 8 -)" + kInputDecorations + R"( -; CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kOutputDecorations; - // clang-format on +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId +)"; const std::string globals = R"( %void = OpTypeVoid @@ -362,7 +235,7 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer %_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %_ptr_PhysicalStorageBuffer_blockType %int_531 = OpConstant %int 531 %_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int -)" + kInputGlobals + kOutputGlobals; +)"; const std::string main_func = R"( %main = OpFunction %void None %3 @@ -373,58 +246,49 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer %22 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8 %26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %22 %int_0 OpStore %26 %int_531 Aligned 16 -; CHECK-NOT: %22 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8 -; CHECK-NOT: %26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %22 %int_0 -; CHECK: %30 = OpConvertPtrToU %ulong %21 -; CHECK: %67 = OpFunctionCall %bool %inst_buff_addr_search_and_test %30 %uint_8 -; CHECK: OpSelectionMerge %68 None -; CHECK: OpBranchConditional %67 %69 %70 -; CHECK: %69 = OpLabel -; CHECK: %71 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8 -; CHECK: OpBranch %68 -; CHECK: %70 = OpLabel -; CHECK: %72 = OpUConvert %uint %30 -; CHECK: %74 = OpShiftRightLogical %ulong %30 %uint_32 -; CHECK: %75 = OpUConvert %uint %74 -; CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %void %inst_buff_addr_stream_write_3 %uint_23 %uint_44 {{%\w+}} %uint_3 %72 %75 -; CHECK: {{%\w+}} = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_blockType {{%\w+}} -; CHECK: OpBranch %68 -; CHECK: %68 = OpLabel -; CHECK: {{%\w+}} = OpPhi %_ptr_PhysicalStorageBuffer_blockType %71 %69 {{%\w+}} %70 -; CHECK: %26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int {{%\w+}} %int_0 -; CHECK: {{%\w+}} = OpConvertPtrToU %ulong %26 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_buff_addr_search_and_test {{%\w+}} %uint_4 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: OpStore %26 %int_531 Aligned 16 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpShiftRightLogical %ulong {{%\w+}} %uint_32 -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpFunctionCall %void %inst_buff_addr_stream_write_3 %uint_23 %uint_46 {{%\w+}} %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel +;CHECK-NOT: %22 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8 +;CHECK-NOT: %26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %22 %int_0 +;CHECK: {{%\w+}} = OpConvertPtrToU %ulong %21 +;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_45 {{%\w+}} {{%\w+}} %uint_8 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_blockType %52 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpPhi %_ptr_PhysicalStorageBuffer_blockType {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: %26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int {{%\w+}} %int_0 +;CHECK: {{%\w+}} = OpConvertPtrToU %ulong %26 +;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_47 {{%\w+}} {{%\w+}} %uint_4 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %26 %int_531 Aligned 16 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel OpReturn OpFunctionEnd )"; - - const std::string output_funcs = kSearchAndTest + kStreamWrite3; + // clang-format on SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); SinglePassRunAndMatch( - defs + decorates + globals + main_func + output_funcs, true, 7u, 23u); + defs + decorates + globals + kImportStub + main_func, true, 23u); } TEST_F(InstBuffAddrTest, StructLoad) { @@ -451,11 +315,11 @@ TEST_F(InstBuffAddrTest, StructLoad) { OpCapability Shader OpCapability Int64 OpCapability PhysicalStorageBufferAddresses -; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" +;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel PhysicalStorageBuffer64 GLSL450 OpEntryPoint Fragment %main "main" -; CHECK: OpEntryPoint Fragment %main "main" %inst_buff_addr_input_buffer %gl_FragCoord %inst_buff_addr_output_buffer +;CHECK: OpEntryPoint Fragment %main "main" %gl_FragCoord OpExecutionMode %main OriginUpperLeft OpSource GLSL 450 OpSourceExtension "GL_ARB_gpu_shader_int64" @@ -474,11 +338,9 @@ OpMemberName %TestBuffer 0 "test" OpMemberDecorate %Test_0 0 Offset 0 OpMemberDecorate %TestBuffer 0 Offset 0 OpDecorate %TestBuffer Block -; CHECK: OpDecorate %_runtimearr_ulong ArrayStride 8 -)" + kInputDecorations + R"( -; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kOutputDecorations; +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord +)"; const std::string globals = R"( %void = OpTypeVoid @@ -494,53 +356,44 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_TestBuffer PhysicalStorageBuffe %int_0 = OpConstant %int 0 %_ptr_PhysicalStorageBuffer_Test_0 = OpTypePointer PhysicalStorageBuffer %Test_0 %ulong_18446744073172680704 = OpConstant %ulong 18446744073172680704 -; CHECK: %47 = OpTypeFunction %bool %ulong %uint -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: {{%\w+}} = OpConstantNull %Test_0 +;CHECK: {{%\w+}} = OpConstantNull %Test_0 )"; - // clang-format on - const std::string main_func = - R"( + const std::string main_func = R"( %main = OpFunction %void None %3 %5 = OpLabel %37 = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_TestBuffer %ulong_18446744073172680704 %38 = OpAccessChain %_ptr_PhysicalStorageBuffer_Test_0 %37 %int_0 %39 = OpLoad %Test_0 %38 Aligned 16 -; CHECK-NOT: %39 = OpLoad %Test_0 %38 Aligned 16 -; CHECK: {{%\w+}} = OpConvertPtrToU %ulong %38 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_buff_addr_search_and_test {{%\w+}} %uint_4 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %Test_0 %38 Aligned 16 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpShiftRightLogical %ulong {{%\w+}} %uint_32 -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord -; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 -; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %void %inst_buff_addr_stream_write_3 %uint_23 %uint_37 {{%\w+}} %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %Test_0 {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK-NOT: %39 = OpLoad %Test_0 %38 Aligned 16 +;CHECK: {{%\w+}} = OpConvertPtrToU %ulong %38 +;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord +;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}} +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0 +;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1 +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_38 {{%\w+}} {{%\w+}} %uint_4 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %Test_0 %38 Aligned 16 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %Test_0 {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} %40 = OpCopyLogical %Test %39 -; CHECK-NOT: %40 = OpCopyLogical %Test %39 -; CHECK: %40 = OpCopyLogical %Test [[phi_result]] +;CHECK-NOT: %40 = OpCopyLogical %Test %39 +;CHECK: %40 = OpCopyLogical %Test [[phi_result]] OpReturn OpFunctionEnd )"; + // clang-format on - const std::string output_funcs = kSearchAndTest + kStreamWrite3; - - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); SinglePassRunAndMatch( - defs + decorates + globals + main_func + output_funcs, true); + defs + decorates + globals + kImportStub + main_func, true); } TEST_F(InstBuffAddrTest, PaddedStructLoad) { @@ -599,12 +452,9 @@ OpMemberDecorate %Test_0 0 Offset 0 OpMemberDecorate %Test_0 1 Offset 16 OpMemberDecorate %Test_0 2 Offset 24 OpMemberDecorate %TestBuffer 0 Offset 0 -; CHECK: OpDecorate %_runtimearr_ulong ArrayStride 8 -)" + kInputDecorations + R"( -; CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex -; CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex -; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4 -)" + kOutputDecorations + R"( +)" + kImportDeco + R"( +;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex +;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex )"; const std::string globals = R"( @@ -627,13 +477,10 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_TestBuffer PhysicalStorageBuffe %_ptr_PhysicalStorageBuffer_Test_0 = OpTypePointer PhysicalStorageBuffer %Test_0 %_ptr_Function_Test = OpTypePointer Function %Test %ulong_18446744073172680704 = OpConstant %ulong 18446744073172680704 -)" + kInputGlobals + kOutputGlobals + R"( -; CHECK: {{%\w+}} = OpConstantNull %Test_0 +;CHECK: {{%\w+}} = OpConstantNull %Test_0 )"; - // clang-format on - const std::string main_func = - R"( + const std::string main_func = R"( %main = OpFunction %void None %3 %5 = OpLabel %param = OpVariable %_ptr_Function_ulong Function @@ -650,40 +497,35 @@ OpFunctionEnd %25 = OpAccessChain %_ptr_PhysicalStorageBuffer_Test_0 %21 %int_0 %26 = OpLoad %Test_0 %25 Aligned 16 %29 = OpCopyLogical %Test %26 -; CHECK-NOT: %30 = OpLoad %Test %28 -; CHECK-NOT: %26 = OpLoad %Test_0 %25 Aligned 16 -; CHECK-NOT: %29 = OpCopyLogical %Test %26 -; CHECK: {{%\w+}} = OpConvertPtrToU %ulong %25 -; CHECK: {{%\w+}} = OpFunctionCall %bool %inst_buff_addr_search_and_test {{%\w+}} %uint_28 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %Test_0 %25 Aligned 16 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpShiftRightLogical %ulong {{%\w+}} %uint_32 -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex -; CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %void %inst_buff_addr_stream_write_3 %uint_23 %uint_62 {{%\w+}} %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %Test_0 {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: %29 = OpCopyLogical %Test [[phi_result]] +;CHECK-NOT: %30 = OpLoad %Test %28 +;CHECK-NOT: %26 = OpLoad %Test_0 %25 Aligned 16 +;CHECK-NOT: %29 = OpCopyLogical %Test %26 +;CHECK: {{%\w+}} = OpConvertPtrToU %ulong %25 +;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex +;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_63 {{%\w+}} {{%\w+}} %uint_28 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %Test_0 %25 Aligned 16 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %Test_0 {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: %29 = OpCopyLogical %Test [[phi_result]] OpStore %28 %29 %30 = OpLoad %Test %28 OpReturnValue %30 OpFunctionEnd )"; + // clang-format on - const std::string output_funcs = kSearchAndTest + kStreamWrite3; - - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); SinglePassRunAndMatch( - defs + decorates + globals + main_func + output_funcs, true); + defs + decorates + globals + kImportStub + main_func, true); } TEST_F(InstBuffAddrTest, DeviceBufferAddressOOB) { @@ -710,7 +552,7 @@ OpCapability PhysicalStorageBufferAddresses %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel PhysicalStorageBuffer64 GLSL450 OpEntryPoint Vertex %main "main" %u_info -;CHECK: OpEntryPoint Vertex %main "main" %u_info %inst_buff_addr_input_buffer %gl_VertexIndex %gl_InstanceIndex %inst_buff_addr_output_buffer +;CHECK: OpEntryPoint Vertex %main "main" %u_info %gl_VertexIndex %gl_InstanceIndex OpSource GLSL 450 OpSourceExtension "GL_EXT_buffer_reference" OpName %main "main" @@ -729,7 +571,7 @@ OpMemberDecorate %bufStruct 0 Offset 0 OpDecorate %bufStruct Block OpDecorate %u_info DescriptorSet 0 OpDecorate %u_info Binding 0 -)" + kInputDecorations + kOutputDecorations + R"( +)" + kImportDeco + R"( %void = OpTypeVoid %3 = OpTypeFunction %void %int = OpTypeInt 32 1 @@ -750,7 +592,7 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_bufStruct %int_n559035791 = OpConstant %int -559035791 %_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int -)" + kInputGlobals + kOutputGlobals + R"( +)" + kImportStub + R"( %main = OpFunction %void None %3 %5 = OpLabel %i = OpVariable %_ptr_Function_int Function @@ -770,21 +612,18 @@ OpBranchConditional %29 %11 %12 %32 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %31 %33 = OpLoad %int %i %36 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %32 %int_0 %33 -;CHECK: %41 = OpConvertPtrToU %ulong %36 -;CHECK: %76 = OpFunctionCall %bool %inst_buff_addr_search_and_test %41 %uint_4 -;CHECK: OpSelectionMerge %77 None -;CHECK: OpBranchConditional %76 %78 %79 -;CHECK: %78 = OpLabel OpStore %36 %int_n559035791 Aligned 16 -;CHECK: OpBranch %77 -;CHECK: %79 = OpLabel -;CHECK: %80 = OpUConvert %uint %41 -;CHECK: %82 = OpShiftRightLogical %ulong %41 %uint_32 -;CHECK: %83 = OpUConvert %uint %82 +;CHECK: {{%\w+}} = OpConvertPtrToU %ulong %36 ;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex ;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex ;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -;CHECK: {{%\w+}} = OpFunctionCall %void %inst_buff_addr_stream_write_3 %uint_23 %uint_62 {{%\w+}} %uint_3 {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_63 {{%\w+}} {{%\w+}} %uint_4 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpStore %36 %int_n559035791 Aligned 16 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel ;CHECK: OpBranch {{%\w+}} ;CHECK: {{%\w+}} = OpLabel OpBranch %13 @@ -795,12 +634,12 @@ OpStore %i %38 OpBranch %10 %12 = OpLabel OpReturn -OpFunctionEnd)" + kSearchAndTest + kStreamWrite3; +OpFunctionEnd)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); - SinglePassRunAndMatch(text, true, 7, 23); + SinglePassRunAndMatch(text, true, 23); } TEST_F(InstBuffAddrTest, UVec3ScalarAddressOOB) { @@ -849,7 +688,7 @@ OpMemberDecorate %IndexBuffer 0 Offset 0 OpDecorate %IndexBuffer Block OpDecorate %u_info DescriptorSet 0 OpDecorate %u_info Binding 0 -)" + kInputDecorations + kOutputDecorations + R"( +)" + kImportDeco + R"( %void = OpTypeVoid %3 = OpTypeFunction %void %int = OpTypeInt 32 1 @@ -867,7 +706,7 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_IndexBuffer PhysicalStorageBuff %int_1 = OpConstant %int 1 %_ptr_Uniform_int = OpTypePointer Uniform %int %bool = OpTypeBool -)" + kInputGlobals + kOutputGlobals + R"( +)" + kImportStub + R"( %_ptr_Function_v3uint = OpTypePointer Function %v3uint %_ptr_Uniform__ptr_PhysicalStorageBuffer_IndexBuffer = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_IndexBuffer %_ptr_PhysicalStorageBuffer_v3uint = OpTypePointer PhysicalStorageBuffer %v3uint @@ -893,27 +732,23 @@ OpBranchConditional %29 %11 %12 %37 = OpAccessChain %_ptr_PhysicalStorageBuffer_v3uint %34 %int_0 %35 %38 = OpLoad %v3uint %37 Aligned 4 OpStore %readvec %38 -; CHECK-NOT: %38 = OpLoad %v3uint %37 Aligned 4 -; CHECK-NOT: OpStore %readvec %38 -; CHECK: {{%\w+}} = OpConvertPtrToU %ulong %37 -; CHECK: [[test_result:%\w+]] = OpFunctionCall %bool %inst_buff_addr_search_and_test {{%\w+}} %uint_12 -; CHECK: OpSelectionMerge {{%\w+}} None -; CHECK: OpBranchConditional [[test_result]] {{%\w+}} {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpLoad %v3uint %37 Aligned 4 -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpShiftRightLogical %ulong {{%\w+}} %uint_32 -; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}} -; CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex -; CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex -; CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 -; CHECK: {{%\w+}} = OpFunctionCall %void %inst_buff_addr_stream_write_3 %uint_23 %uint_66 {{%\w+}} %uint_3 {{%\w+}} {{%\w+}} -; CHECK: OpBranch {{%\w+}} -; CHECK: {{%\w+}} = OpLabel -; CHECK: [[phi_result:%\w+]] = OpPhi %v3uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} -; CHECK: OpStore %readvec [[phi_result]] +;CHECK-NOT: %38 = OpLoad %v3uint %37 Aligned 4 +;CHECK-NOT: OpStore %readvec %38 +;CHECK: {{%\w+}} = OpConvertPtrToU %ulong %37 +;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex +;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex +;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0 +;CHECK: [[test_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_67 {{%\w+}} {{%\w+}} %uint_12 +;CHECK: OpSelectionMerge {{%\w+}} None +;CHECK: OpBranchConditional [[test_result]] {{%\w+}} {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: {{%\w+}} = OpLoad %v3uint %37 Aligned 4 +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: OpBranch {{%\w+}} +;CHECK: {{%\w+}} = OpLabel +;CHECK: [[phi_result:%\w+]] = OpPhi %v3uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} +;CHECK: OpStore %readvec [[phi_result]] OpBranch %13 %13 = OpLabel %39 = OpLoad %int %i @@ -923,13 +758,13 @@ OpBranch %10 %12 = OpLabel OpReturn OpFunctionEnd -)" + kSearchAndTest + kStreamWrite3; +)"; // clang-format on - SetTargetEnv(SPV_ENV_VULKAN_1_2); + SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); ValidatorOptions()->scalar_block_layout = true; - SinglePassRunAndMatch(text, true, 7, 23); + SinglePassRunAndMatch(text, true, 23); } } // namespace