diff options
author | Jeremy Gebben <jeremyg@lunarg.com> | 2023-10-02 09:15:39 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 09:15:39 -0600 |
commit | 847715d6c65200987c079fb13ca7925760faec23 (patch) | |
tree | 6089c507809abb37850183630e93e8e62d62649b | |
parent | dc9900967d51cd82de0c5ae644b1c3947c9c9b85 (diff) | |
download | SPIRV-Tools-847715d6c65200987c079fb13ca7925760faec23.tar.gz SPIRV-Tools-847715d6c65200987c079fb13ca7925760faec23.tar.bz2 SPIRV-Tools-847715d6c65200987c079fb13ca7925760faec23.zip |
instrument: Ensure linking works even of nothing is changed (#5419)
spirv-link requires that memory models match between its input files.
Ensure this is the case by always returning SuccessWithChange and
always changing the memory model to match the instrumentation
code in Vulkan-ValidationLayers.
Also, disable the DCE pass in the --inst-* command line options, since
it will only work after linking.
-rw-r--r-- | source/opt/inst_bindless_check_pass.cpp | 7 | ||||
-rw-r--r-- | source/opt/inst_buff_addr_check_pass.cpp | 14 | ||||
-rw-r--r-- | source/opt/optimizer.cpp | 2 |
3 files changed, 13 insertions, 10 deletions
diff --git a/source/opt/inst_bindless_check_pass.cpp b/source/opt/inst_bindless_check_pass.cpp index f84d5b29..8e7d4f83 100644 --- a/source/opt/inst_bindless_check_pass.cpp +++ b/source/opt/inst_bindless_check_pass.cpp @@ -724,7 +724,6 @@ 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(); @@ -747,8 +746,10 @@ Pass::Status InstBindlessCheckPass::ProcessImpl() { new_blocks); }; - modified = InstProcessEntryPointCallTree(pfn); - return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange; + InstProcessEntryPointCallTree(pfn); + // This pass always changes the memory model, so that linking will work + // properly. + return Status::SuccessWithChange; } Pass::Status InstBindlessCheckPass::Process() { diff --git a/source/opt/inst_buff_addr_check_pass.cpp b/source/opt/inst_buff_addr_check_pass.cpp index e1fde771..e6c55087 100644 --- a/source/opt/inst_buff_addr_check_pass.cpp +++ b/source/opt/inst_buff_addr_check_pass.cpp @@ -301,6 +301,11 @@ Pass::Status InstBuffAddrCheckPass::ProcessImpl() { 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::Int64); context()->AddCapability(spv::Capability::Linkage); // Perform bindless bounds check on each entry point function in module @@ -311,14 +316,13 @@ Pass::Status InstBuffAddrCheckPass::ProcessImpl() { return GenBuffAddrCheckCode(ref_inst_itr, ref_block_itr, stage_idx, new_blocks); }; - bool modified = InstProcessEntryPointCallTree(pfn); - return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange; + InstProcessEntryPointCallTree(pfn); + // This pass always changes the memory model, so that linking will work + // properly. + return Status::SuccessWithChange; } Pass::Status InstBuffAddrCheckPass::Process() { - if (!get_feature_mgr()->HasCapability( - spv::Capability::PhysicalStorageBufferAddressesEXT)) - return Status::SuccessWithoutChange; InitInstBuffAddrCheck(); return ProcessImpl(); } diff --git a/source/opt/optimizer.cpp b/source/opt/optimizer.cpp index 2a7c4110..675bd1bd 100644 --- a/source/opt/optimizer.cpp +++ b/source/opt/optimizer.cpp @@ -439,10 +439,8 @@ bool Optimizer::RegisterPassFromFlag(const std::string& flag) { RegisterPass(CreateSimplificationPass()); RegisterPass(CreateDeadBranchElimPass()); RegisterPass(CreateBlockMergePass()); - RegisterPass(CreateAggressiveDCEPass(true)); } else if (pass_name == "inst-buff-addr-check") { RegisterPass(CreateInstBuffAddrCheckPass(23)); - RegisterPass(CreateAggressiveDCEPass(true)); } else if (pass_name == "convert-relaxed-to-half") { RegisterPass(CreateConvertRelaxedToHalfPass()); } else if (pass_name == "relax-float-ops") { |