Skip to content

Commit

Permalink
layers: Optimize Vulkan SC atomic feature VU
Browse files Browse the repository at this point in the history
Also move the check earlier, at pipeline cache creation.
  • Loading branch information
aqnuep committed Oct 4, 2024
1 parent 139b820 commit 5614afd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 28 deletions.
2 changes: 0 additions & 2 deletions layers/vulkansc/core_checks/sc_core_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,5 @@ class SCCoreChecks : public SCValidationStateTracker<CoreChecks> {
bool ValidatePipelineStageInfo(uint32_t stage_index, const VkPipelineShaderStageCreateInfo& stage_info,
const vvl::sc::PipelineCache* pipeline_cache_state,
const VkPipelineOfflineCreateInfo* offline_info, const Location& loc) const;
virtual bool ValidateShaderStage(const ShaderStageState& stage_state, const vvl::Pipeline* pipeline,
const Location& loc) const override;

}; // Class SCCoreChecks
31 changes: 7 additions & 24 deletions layers/vulkansc/core_checks/sc_spirv_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ bool SCCoreChecks::ValidatePipelineCacheSpirv(VkPhysicalDevice physical_device,
spirv::StatelessData stateless_data{};
spirv::Module temp_module(code.size() * sizeof(uint32_t), code.data(), &stateless_data);

if (stateless_data.atomic_inst.size() > 0 && (enabled_features.shaderAtomicInstructions == VK_FALSE)) {
skip |= LogError("VUID-RuntimeSpirv-OpAtomic-05091", physical_device, loc.dot(Field::pInitialData),
"contains pipeline identifier {%s} with SPIR-V module data for stage index entry %u "
"that is using atomic instructions, but shaderAtomicInstructions was not enabled.",
id.toString().c_str(), stage_index);
}

// We set the entry point name to vkCreateShaderModule here to trigger the vkCreateShaderModule
// VUIDs instead of the vkCreateShadersEXT VUIDs introduced by VK_EXT_shader_objects
skip |= ValidateSpirvStateless(temp_module, stateless_data, Location(Func::vkCreateShaderModule));
Expand Down Expand Up @@ -219,27 +226,3 @@ bool SCCoreChecks::ValidatePipelineStageInfo(uint32_t stage_index, const VkPipel

return skip;
}

bool SCCoreChecks::ValidateShaderStage(const ShaderStageState& stage_state, const vvl::Pipeline* pipeline,
const Location& loc) const {
bool skip = BASE::ValidateShaderStage(stage_state, pipeline, loc);

if (!stage_state.spirv_state || !stage_state.entrypoint) {
// From here on we only do SPIR-V validation, so without SPIR-V data we stop here
return skip;
}

const spirv::Module& module_state = *stage_state.spirv_state.get();

auto is_atomic = [](const spirv::Instruction& insn) { return AtomicOperation(insn.Opcode()); };
auto are_any_atomic = [is_atomic](auto&& insn_range) {
return std::any_of(std::begin(insn_range), std::end(insn_range), is_atomic);
};

if (are_any_atomic(module_state.GetInstructions()) && (enabled_features.shaderAtomicInstructions == VK_FALSE)) {
skip |= LogError("VUID-RuntimeSpirv-OpAtomic-05091", module_state.handle(), loc,
"SPIR-V is using atomic instructions, but shaderAtomicInstructions was not enabled.");
}

return skip;
}
2 changes: 1 addition & 1 deletion tests/icd/test_icd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance i
if (item != name_to_func_ptr_map.end()) {
return reinterpret_cast<PFN_vkVoidFunction>(item->second);
}
#ifdef VULKANSC
#ifndef VULKANSC
// This false warning is generated in Vulkan SC validation tests because the tests use the
// vk_dispatch_table.h generated from the combined headers
printf("WARNING - Failed to find %s\n", pName);
Expand Down
2 changes: 1 addition & 1 deletion tests/vulkansc/negative/shader_spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ TEST_F(VkSCNegativeShaderSpirv, Atomics) {
RETURN_IF_SKIP(Init());

m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-RuntimeSpirv-OpAtomic-05091");
builder.CreatePipeline(*m_device);
builder.CreatePipelineCache(*m_device);
m_errorMonitor->VerifyFound();
}

Expand Down

0 comments on commit 5614afd

Please sign in to comment.