More verbose BindGroupLayout error messages

Begins including the expected BindGroupLayout in validation messages
where a BindGroup descriptor does not match the BindGroupLayout. This
is especially helpful in cases where the BindGroupLayout was implicitly
created by the pipeline.

Bug: dawn:1258
Change-Id: Icbf27b4a2ac9b4dc1716feed47e3e63cf99929a7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/80380
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Brandon Jones <bajones@chromium.org>
This commit is contained in:
Brandon Jones 2022-02-14 19:06:55 +00:00 committed by Dawn LUCI CQ
parent 958d82d015
commit fe994f74ff
5 changed files with 79 additions and 7 deletions

View File

@ -269,9 +269,10 @@ namespace dawn::native {
DAWN_INVALID_IF( DAWN_INVALID_IF(
descriptor->entryCount != descriptor->layout->GetUnexpandedBindingCount(), descriptor->entryCount != descriptor->layout->GetUnexpandedBindingCount(),
"Number of entries (%u) did not match the number of entries (%u) specified in %s", "Number of entries (%u) did not match the number of entries (%u) specified in %s."
"\nExpected layout: %s",
descriptor->entryCount, static_cast<uint32_t>(descriptor->layout->GetBindingCount()), descriptor->entryCount, static_cast<uint32_t>(descriptor->layout->GetBindingCount()),
descriptor->layout); descriptor->layout, descriptor->layout->EntriesToString());
const BindGroupLayoutBase::BindingMap& bindingMap = descriptor->layout->GetBindingMap(); const BindGroupLayoutBase::BindingMap& bindingMap = descriptor->layout->GetBindingMap();
ASSERT(bindingMap.size() <= kMaxBindingsPerPipelineLayout); ASSERT(bindingMap.size() <= kMaxBindingsPerPipelineLayout);
@ -282,8 +283,9 @@ namespace dawn::native {
const auto& it = bindingMap.find(BindingNumber(entry.binding)); const auto& it = bindingMap.find(BindingNumber(entry.binding));
DAWN_INVALID_IF(it == bindingMap.end(), DAWN_INVALID_IF(it == bindingMap.end(),
"In entries[%u], binding index %u not present in the bind group layout", "In entries[%u], binding index %u not present in the bind group layout."
i, entry.binding); "\nExpected layout: %s",
i, entry.binding, descriptor->layout->EntriesToString());
BindingIndex bindingIndex = it->second; BindingIndex bindingIndex = it->second;
ASSERT(bindingIndex < descriptor->layout->GetBindingCount()); ASSERT(bindingIndex < descriptor->layout->GetBindingCount());
@ -315,16 +317,22 @@ namespace dawn::native {
switch (bindingInfo.bindingType) { switch (bindingInfo.bindingType) {
case BindingInfoType::Buffer: case BindingInfoType::Buffer:
DAWN_TRY_CONTEXT(ValidateBufferBinding(device, entry, bindingInfo), DAWN_TRY_CONTEXT(ValidateBufferBinding(device, entry, bindingInfo),
"validating entries[%u] as a Buffer", i); "validating entries[%u] as a Buffer."
"\nExpected entry layout: %s",
i, bindingInfo);
break; break;
case BindingInfoType::Texture: case BindingInfoType::Texture:
case BindingInfoType::StorageTexture: case BindingInfoType::StorageTexture:
DAWN_TRY_CONTEXT(ValidateTextureBinding(device, entry, bindingInfo), DAWN_TRY_CONTEXT(ValidateTextureBinding(device, entry, bindingInfo),
"validating entries[%u] as a Texture", i); "validating entries[%u] as a Texture."
"\nExpected entry layout: %s",
i, bindingInfo);
break; break;
case BindingInfoType::Sampler: case BindingInfoType::Sampler:
DAWN_TRY_CONTEXT(ValidateSamplerBinding(device, entry, bindingInfo), DAWN_TRY_CONTEXT(ValidateSamplerBinding(device, entry, bindingInfo),
"validating entries[%u] as a Sampler", i); "validating entries[%u] as a Sampler."
"\nExpected entry layout: %s",
i, bindingInfo);
break; break;
case BindingInfoType::ExternalTexture: case BindingInfoType::ExternalTexture:
UNREACHABLE(); UNREACHABLE();

View File

@ -656,4 +656,15 @@ namespace dawn::native {
} }
} }
std::string BindGroupLayoutBase::EntriesToString() const {
std::string entries = " [";
const BindGroupLayoutBase::BindingMap& bindingMap = GetBindingMap();
for (const auto [bindingNumber, bindingIndex] : bindingMap) {
const BindingInfo& bindingInfo = GetBindingInfo(bindingIndex);
entries += absl::StrFormat("%s, ", bindingInfo);
}
entries += "]";
return entries;
}
} // namespace dawn::native } // namespace dawn::native

View File

@ -130,6 +130,9 @@ namespace dawn::native {
bool IsStorageBufferBinding(BindingIndex bindingIndex) const; bool IsStorageBufferBinding(BindingIndex bindingIndex) const;
// Returns a detailed string representation of the layout entries for use in error messages.
std::string EntriesToString() const;
protected: protected:
// Constructor used only for mocking and testing. // Constructor used only for mocking and testing.
BindGroupLayoutBase(DeviceBase* device); BindGroupLayoutBase(DeviceBase* device);

View File

@ -44,6 +44,51 @@ namespace dawn::native {
return {true}; return {true};
} }
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> AbslFormatConvert(
const BindingInfo& value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s) {
s->Append(absl::StrFormat("{\n binding: %u\n visibility: %s\n %s: {\n",
static_cast<uint32_t>(value.binding), value.visibility,
value.bindingType));
switch (value.bindingType) {
case BindingInfoType::Buffer:
s->Append(absl::StrFormat(" type: %s\n", value.buffer.type));
if (value.buffer.hasDynamicOffset) {
s->Append(" hasDynamicOffset: true\n");
}
if (value.buffer.minBindingSize != 0) {
s->Append(
absl::StrFormat(" minBindingSize: %u\n", value.buffer.minBindingSize));
}
break;
case BindingInfoType::Sampler:
s->Append(absl::StrFormat(" type: %s\n", value.sampler.type));
break;
case BindingInfoType::Texture:
s->Append(absl::StrFormat(" sampleType: %s\n", value.texture.sampleType));
s->Append(absl::StrFormat(" viewDimension: %s\n", value.texture.viewDimension));
if (value.texture.multisampled) {
s->Append(" multisampled: true\n");
} else {
s->Append(" multisampled: false\n");
}
break;
case BindingInfoType::StorageTexture:
s->Append(absl::StrFormat(" access: %s\n", value.storageTexture.access));
s->Append(absl::StrFormat(" format: %s\n", value.storageTexture.format));
s->Append(
absl::StrFormat(" viewDimension: %s\n", value.storageTexture.viewDimension));
break;
case BindingInfoType::ExternalTexture:
break;
}
s->Append(" }\n}");
return {true};
}
void IncrementBindingCounts(BindingCounts* bindingCounts, const BindGroupLayoutEntry& entry) { void IncrementBindingCounts(BindingCounts* bindingCounts, const BindGroupLayoutEntry& entry) {
bindingCounts->totalCount += 1; bindingCounts->totalCount += 1;

View File

@ -68,6 +68,11 @@ namespace dawn::native {
StorageTextureBindingLayout storageTexture; StorageTextureBindingLayout storageTexture;
}; };
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> AbslFormatConvert(
const BindingInfo& value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s);
struct BindingSlot { struct BindingSlot {
BindGroupIndex group; BindGroupIndex group;
BindingNumber binding; BindingNumber binding;