Skip to content

Commit

Permalink
layers: Warn about missing SPIR-V debug info in PC data
Browse files Browse the repository at this point in the history
  • Loading branch information
aqnuep committed Mar 19, 2024
1 parent 5c7616b commit ae0539d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
31 changes: 29 additions & 2 deletions layers/vulkansc/core_checks/sc_core_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ bool SCCoreChecks::ValidatePipelineCacheData(VkPhysicalDevice physicalDevice, co
return skip;
}

// Count the number of pipelines that do not have a complete and valid SPIR-V debug information
// so that we can issue an appropriate warning
uint32_t pipelines_without_spirv_data = 0;

vvl::unordered_set<vvl::sc::PipelineCacheData::Entry::ID, vvl::sc::PipelineCacheData::Entry::ID::hash> pipeline_ids{};
for (uint32_t pipeline_index = 0; pipeline_index < data.PipelineIndexCount(); ++pipeline_index) {
bool stage_info_valid = true;
Expand Down Expand Up @@ -372,17 +376,24 @@ bool SCCoreChecks::ValidatePipelineCacheData(VkPhysicalDevice physicalDevice, co
if (stage_info_valid) {
for (uint32_t stage_index = 0; stage_index < entry.StageIndexCount(); ++stage_index) {
auto stage_info = entry.StageIndexEntry(stage_index);
if (!stage_info) continue;
if (!stage_info) {
stage_info_valid = false;
continue;
}

skip |= ValidatePipelineCacheSpirv(physicalDevice, data, pipeline_index, stage_index, loc);
// SPIR-V validation, if used, will already report errors for the warnings below
if (skip) continue;
if (skip) {
stage_info_valid = false;
continue;
}

if (stage_info->codeSize == 0) {
skip |= LogWarning(kVUID_SC_PipelineCacheData_CodeSizeZero, physicalDevice, loc.dot(Field::pInitialData),
"contains pipeline identifier {%s} for which codeSize "
"for stage index entry #%u is zero.",
id.toString().c_str(), stage_index);
stage_info_valid = false;
}

if (stage_info->codeSize % 4 != 0) {
Expand All @@ -391,6 +402,7 @@ bool SCCoreChecks::ValidatePipelineCacheData(VkPhysicalDevice physicalDevice, co
"contains pipeline identifier {%s} for which codeSize (%" PRIu64
") for stage index entry #%u is not a multiple of 4.",
id.toString().c_str(), stage_info->codeSize, stage_index);
stage_info_valid = false;
}

if (stage_info->codeOffset + stage_info->codeSize > create_info.initialDataSize) {
Expand All @@ -401,9 +413,24 @@ bool SCCoreChecks::ValidatePipelineCacheData(VkPhysicalDevice physicalDevice, co
"codeOffset (%" PRIu64 ") with codeSize (%" PRIu64 ").",
create_info.initialDataSize, stage_index, id.toString().c_str(), stage_info->codeOffset,
stage_info->codeSize);
stage_info_valid = false;
}
}
}

if (!stage_info_valid || entry->stageIndexCount == 0) {
pipelines_without_spirv_data++;
}
}

if (pipelines_without_spirv_data == data.PipelineIndexCount()) {
skip |= LogWarning(kVUID_SC_PipelineCacheData_SpirvDepValMissingInfo, device, loc.dot(Field::pInitialData),
"does not contain SPIR-V module data for any pipelines thus SPIR-V dependent validation "
"will not be available for any pipeline created from this pipeline cache data.");
} else if (pipelines_without_spirv_data > 0) {
skip |= LogWarning(kVUID_SC_PipelineCacheData_SpirvDepValMissingInfo, device, loc.dot(Field::pInitialData),
"does not contain SPIR-V module data for some pipelines thus SPIR-V dependent validation "
"will not be available for those pipelines.");
}

return skip;
Expand Down
31 changes: 31 additions & 0 deletions tests/vulkansc/negative/device_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,34 @@ TEST_F(VkSCPipelineCacheDataLayerTest, InvalidSpirvMagic) {
TestPipelineCacheData({builder.MakeCreateInfo()});
m_errorMonitor->VerifyFound();
}

TEST_F(VkSCPipelineCacheDataLayerTest, AllPipelinesMissingSpirvDebugInfo) {
TEST_DESCRIPTION("A warning is issued if all pipelines in the pipeline cache data are missing SPIR-V debug info.");

RETURN_IF_SKIP(InitFramework());
auto header = builder.AddDefaultHeaderVersionSCOne();
builder.AddPipelineEntry(header, "3ddda923-b6fc-433e-803c-822c1bccbc05", 4000);
builder.AddPipelineEntry(header, "1265a236-e369-11ed-b5ea-0242ac120002", 4000);
builder.AddPipelineEntry(header, "73ada7f2-9cc6-48ed-a193-24d0091f4f95", 4000);

m_errorMonitor->SetDesiredFailureMsg(kWarningBit, "does not contain SPIR-V module data for any pipelines");
TestPipelineCacheData({builder.MakeCreateInfo()});
m_errorMonitor->VerifyFound();
}

TEST_F(VkSCPipelineCacheDataLayerTest, SomePipelinesMissingSpirvDebugInfo) {
TEST_DESCRIPTION("A warning is issued if some pipelines in the pipeline cache data are missing SPIR-V debug info.");

RETURN_IF_SKIP(InitFramework());
auto header = builder.AddDefaultHeaderVersionSCOne();
std::vector<vksc::PipelineCacheBuilder::SCIndexEntry<>> entries = {
builder.AddPipelineEntry(header, "3ddda923-b6fc-433e-803c-822c1bccbc05", 4000),
builder.AddPipelineEntry(header, "1265a236-e369-11ed-b5ea-0242ac120002", 4000),
builder.AddPipelineEntry(header, "73ada7f2-9cc6-48ed-a193-24d0091f4f95", 4000)};
builder.AddStageValidation(entries[0], kSampleComputePipelineJson, SPV_ENV_VULKAN_1_2, {kSampleComputeShaderSpv});
builder.AddStageValidation(entries[2], kSampleComputePipelineJson, SPV_ENV_VULKAN_1_2, {kSampleComputeShaderSpv});

m_errorMonitor->SetDesiredFailureMsg(kWarningBit, "does not contain SPIR-V module data for some pipelines");
TestPipelineCacheData({builder.MakeCreateInfo()});
m_errorMonitor->VerifyFound();
}

0 comments on commit ae0539d

Please sign in to comment.