Bug 1711926 - Spew WebGPU validation errors to the console r=jimb

Differential Revision: https://phabricator.services.mozilla.com/D115503
This commit is contained in:
Dzmitry Malyshau 2021-05-22 01:03:00 +00:00
Родитель 3679063fc1
Коммит f1987ffe07
2 изменённых файлов: 24 добавлений и 8 удалений

Просмотреть файл

@ -4,7 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGPUChild.h"
#include "js/Warnings.h" // JS::WarnUTF8
#include "mozilla/EnumTypeTraits.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/WebGPUBinding.h"
#include "mozilla/dom/GPUUncapturedErrorEvent.h"
#include "mozilla/webgpu/ValidationError.h"
@ -18,6 +20,20 @@ NS_IMPL_CYCLE_COLLECTION(WebGPUChild)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGPUChild, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGPUChild, Release)
void WebGPUChild::JsWarning(nsIGlobalObject* aGlobal,
const nsACString& aMessage) {
const auto& flatString = PromiseFlatCString(aMessage);
if (aGlobal) {
dom::AutoJSAPI api;
if (api.Init(aGlobal)) {
JS::WarnUTF8(api.cx(), "%s", flatString.get());
}
} else {
printf_stderr("Validation error without device target: %s\n",
flatString.get());
}
}
static ffi::WGPUCompareFunction ConvertCompareFunction(
const dom::GPUCompareFunction& aCompare) {
// Value of 0 = Undefined is reserved on the C side for "null" semantics.
@ -790,16 +806,14 @@ RawId WebGPUChild::DeviceCreateRenderPipeline(
ipc::IPCResult WebGPUChild::RecvError(RawId aDeviceId,
const nsACString& aMessage) {
if (!aDeviceId) {
// TODO: figure out how to report these kinds of errors
printf_stderr("Validation error without device target: %s\n",
PromiseFlatCString(aMessage).get());
} else if (mDeviceMap.find(aDeviceId) == mDeviceMap.end()) {
printf_stderr("Validation error on a dropped device: %s\n",
PromiseFlatCString(aMessage).get());
auto targetIter = mDeviceMap.find(aDeviceId);
if (!aDeviceId || targetIter == mDeviceMap.end()) {
JsWarning(nullptr, aMessage);
} else {
auto* target = mDeviceMap[aDeviceId];
auto* target = targetIter->second;
MOZ_ASSERT(target);
JsWarning(target->GetOwnerGlobal(), aMessage);
dom::GPUUncapturedErrorEventInit init;
init.mError.SetAsGPUValidationError() =
new ValidationError(target, aMessage);

Просмотреть файл

@ -84,6 +84,8 @@ class WebGPUChild final : public PWebGPUChild, public SupportsWeakPtr {
private:
virtual ~WebGPUChild();
void JsWarning(nsIGlobalObject* aGlobal, const nsACString& aMessage);
// AddIPDLReference and ReleaseIPDLReference are only to be called by
// CompositorBridgeChild's AllocPWebGPUChild and DeallocPWebGPUChild methods
// respectively. We intentionally make them private to prevent misuse.