Emit warning if zero-size dispatch/draw

This CL make sure developers are warned when zero-size dispatches and
draws occur. Even though those are valid, it is good to encourage
developers to avoid them when possible.

Bug: dawn:1786
Change-Id: I99cbe8d556569d2e779b7b9c64739c3e5da8e290
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132222
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Fr <beaufort.francois@gmail.com>
This commit is contained in:
François Beaufort 2023-05-10 18:30:55 +00:00 committed by Dawn LUCI CQ
parent 9f83fa1d1b
commit 48e2b114be
4 changed files with 33 additions and 0 deletions

View File

@ -183,6 +183,12 @@ void ComputePassEncoder::APIDispatchWorkgroups(uint32_t workgroupCountX,
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
if (workgroupCountX == 0 || workgroupCountY == 0 || workgroupCountZ == 0) {
GetDevice()->EmitWarningOnce(absl::StrFormat(
"Calling %s.DispatchWorkgroups with a workgroup count of 0 is unusual.",
this));
}
DAWN_TRY(mCommandBufferState.ValidateCanDispatch());
uint32_t workgroupsPerDimension =

View File

@ -1436,6 +1436,12 @@ void DeviceBase::EmitDeprecationWarning(const std::string& message) {
}
}
void DeviceBase::EmitWarningOnce(const std::string& message) {
if (mWarnings.insert(message).second) {
this->EmitLog(WGPULoggingType_Warning, message.c_str());
}
}
void DeviceBase::EmitLog(const char* message) {
this->EmitLog(WGPULoggingType_Info, message);
}

View File

@ -364,6 +364,7 @@ class DeviceBase : public RefCountedWithExternalCount {
void IncrementLazyClearCountForTesting();
size_t GetDeprecationWarningCountForTesting();
void EmitDeprecationWarning(const std::string& warning);
void EmitWarningOnce(const std::string& message);
void EmitLog(const char* message);
void EmitLog(WGPULoggingType loggingType, const char* message);
void APIForceLoss(wgpu::DeviceLostReason reason, const char* message);
@ -597,6 +598,8 @@ class DeviceBase : public RefCountedWithExternalCount {
struct DeprecationWarnings;
std::unique_ptr<DeprecationWarnings> mDeprecationWarnings;
std::unordered_set<std::string> mWarnings;
State mState = State::BeingCreated;
PerObjectType<ApiObjectList> mObjectLists;

View File

@ -93,6 +93,15 @@ void RenderEncoderBase::APIDraw(uint32_t vertexCount,
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
if (vertexCount == 0) {
GetDevice()->EmitWarningOnce(absl::StrFormat(
"Calling %s.Draw with a vertex count of 0 is unusual.", this));
}
if (instanceCount == 0) {
GetDevice()->EmitWarningOnce(absl::StrFormat(
"Calling %s.Draw with an instance count of 0 is unusual.", this));
}
DAWN_TRY(mCommandBufferState.ValidateCanDraw());
DAWN_INVALID_IF(mDisableBaseInstance && firstInstance != 0,
@ -127,6 +136,15 @@ void RenderEncoderBase::APIDrawIndexed(uint32_t indexCount,
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
if (indexCount == 0) {
GetDevice()->EmitWarningOnce(absl::StrFormat(
"Calling %s.Draw with an index count of 0 is unusual.", this));
}
if (instanceCount == 0) {
GetDevice()->EmitWarningOnce(absl::StrFormat(
"Calling %s.Draw with an instance count of 0 is unusual.", this));
}
DAWN_TRY(mCommandBufferState.ValidateCanDrawIndexed());
DAWN_INVALID_IF(mDisableBaseInstance && firstInstance != 0,