diff --git a/src/dawn/native/ComputePassEncoder.cpp b/src/dawn/native/ComputePassEncoder.cpp index 30f4db1bb5..c67df1a93c 100644 --- a/src/dawn/native/ComputePassEncoder.cpp +++ b/src/dawn/native/ComputePassEncoder.cpp @@ -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 = diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp index 70007cfe84..80a8ba0f2b 100644 --- a/src/dawn/native/Device.cpp +++ b/src/dawn/native/Device.cpp @@ -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); } diff --git a/src/dawn/native/Device.h b/src/dawn/native/Device.h index 486efce927..e7c8bb52be 100644 --- a/src/dawn/native/Device.h +++ b/src/dawn/native/Device.h @@ -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 mDeprecationWarnings; + std::unordered_set mWarnings; + State mState = State::BeingCreated; PerObjectType mObjectLists; diff --git a/src/dawn/native/RenderEncoderBase.cpp b/src/dawn/native/RenderEncoderBase.cpp index 6a989c780c..3a43a72083 100644 --- a/src/dawn/native/RenderEncoderBase.cpp +++ b/src/dawn/native/RenderEncoderBase.cpp @@ -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,