Skip to content

Commit

Permalink
⬆️ Upgrade to m6793 (wcandillon#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored and hmallen99 committed Oct 23, 2024
1 parent 5e56dd6 commit 9d28621
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "externals/dawn"]
path = externals/dawn
url = https://dawn.googlesource.com/dawn
branch = chromium/6591
branch = chromium/6793
2 changes: 1 addition & 1 deletion externals/dawn
Submodule dawn updated from e12c27 to a690fe
18 changes: 13 additions & 5 deletions packages/webgpu/cpp/rnwgpu/api/Convertors.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ class Convertor {
return true;
}

[[nodiscard]] bool Convert(wgpu::OptionalBool &out,
const std::optional<bool> &in) {
out = in;
return true;
}

[[nodiscard]] bool Convert(wgpu::StringView &out, const std::string &in) {
out = {in.data(), in.size()};
return true;
}

[[nodiscard]] bool Convert(const char *&out, const std::string &in) {
out = in.c_str();
return true;
Expand Down Expand Up @@ -481,11 +492,8 @@ class Convertor {
const GPUPrimitiveState &in) {
out = {};

if (in.unclippedDepth) {
wgpu::PrimitiveDepthClipControl *depthClip =
Allocate<wgpu::PrimitiveDepthClipControl>();
depthClip->unclippedDepth = true;
out.nextInChain = depthClip;
if (in.unclippedDepth.has_value()) {
out.unclippedDepth = in.unclippedDepth.value();
}

return Convert(out.topology, in.topology) &&
Expand Down
8 changes: 4 additions & 4 deletions packages/webgpu/cpp/rnwgpu/api/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ GPU::requestAdapter(
wgpu::Adapter adapter = nullptr;
_instance.RequestAdapter(
&aOptions,
[](WGPURequestAdapterStatus, WGPUAdapter cAdapter, const char *message,
void *userdata) {
if (message != nullptr) {
fprintf(stderr, "%s", message);
[](WGPURequestAdapterStatus, WGPUAdapter cAdapter,
const WGPUStringView message, void *userdata) {
if (message.length) {
fprintf(stderr, "%s", message.data);
return;
}
*static_cast<wgpu::Adapter *>(userdata) =
Expand Down
29 changes: 15 additions & 14 deletions packages/webgpu/cpp/rnwgpu/api/GPUAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
}
wgpu::DeviceLostCallbackInfo info = {
.callback = [](WGPUDevice const *device, WGPUDeviceLostReason reason,
char const *message, void *userdata) {
const WGPUStringView message, void *userdata) {
const char *lostReason = "";
switch (reason) {
case WGPUDeviceLostReason_Destroyed:
Expand All @@ -35,12 +35,13 @@ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
default:
lostReason = "Unknown";
}
Logger::logToConsole("GPU Device Lost (%s): %s", lostReason, message);
Logger::logToConsole("GPU Device Lost (%s): %s", lostReason,
message.data);
}};
aDescriptor.deviceLostCallbackInfo = info;
wgpu::UncapturedErrorCallbackInfo errorInfo;
errorInfo.userdata = static_cast<void *>(_creationRuntime);
errorInfo.callback = [](WGPUErrorType type, const char *message,
errorInfo.callback = [](WGPUErrorType type, const WGPUStringView message,
void *userdata) {
auto creationRuntime = static_cast<jsi::Runtime *>(userdata);
const char *errorType = "";
Expand All @@ -60,16 +61,16 @@ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
default:
errorType = "Unknown";
}
std::string fullMessage = std::string(errorType) + ": " + message;
Logger::errorToJavascriptConsole(*creationRuntime, fullMessage.c_str());
std::string fullMessage = std::string(errorType) + ": " + message.data;
Logger::errorToJavascriptConsole(*creationRuntime, fullMessage);
};
aDescriptor.uncapturedErrorCallbackInfo = errorInfo;
_instance.RequestDevice(
&aDescriptor,
[](WGPURequestDeviceStatus status, WGPUDevice cDevice,
const char *message, void *userdata) {
if (message != nullptr) {
fprintf(stderr, "%s", message);
const WGPUStringView message, void *userdata) {
if (message.length) {
fprintf(stderr, "%s", message.data);
return;
}
*static_cast<wgpu::Device *>(userdata) = wgpu::Device::Acquire(cDevice);
Expand All @@ -80,17 +81,17 @@ std::future<std::shared_ptr<GPUDevice>> GPUAdapter::requestDevice(
throw std::runtime_error("Failed to request device");
}
device.SetLoggingCallback(
[](WGPULoggingType type, const char *message, void *userdata) {
[](WGPULoggingType type, const WGPUStringView message, void *userdata) {
auto creationRuntime = static_cast<jsi::Runtime *>(userdata);
const char *logLevel = "";
switch (type) {
case WGPULoggingType_Warning:
logLevel = "Warning";
Logger::warnToJavascriptConsole(*creationRuntime, message);
Logger::warnToJavascriptConsole(*creationRuntime, message.data);
break;
case WGPULoggingType_Error:
logLevel = "Error";
Logger::errorToJavascriptConsole(*creationRuntime, message);
Logger::errorToJavascriptConsole(*creationRuntime, message.data);
break;
case WGPULoggingType_Verbose:
logLevel = "Verbose";
Expand Down Expand Up @@ -139,9 +140,9 @@ std::shared_ptr<GPUAdapterInfo> GPUAdapter::getInfo() {
}

bool GPUAdapter::getIsFallbackAdapter() {
wgpu::AdapterProperties adapterProperties = {};
_instance.GetProperties(&adapterProperties);
return adapterProperties.adapterType == wgpu::AdapterType::DiscreteGPU;
wgpu::AdapterInfo adapterInfo = {};
_instance.GetInfo(&adapterInfo);
return adapterInfo.adapterType == wgpu::AdapterType::CPU;
}

} // namespace rnwgpu
29 changes: 25 additions & 4 deletions packages/webgpu/cpp/rnwgpu/api/GPUAdapterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "RNFHybridObject.h"

#include "AsyncRunner.h"
#include "Convertors.h"

#include "webgpu/webgpu_cpp.h"

Expand All @@ -23,10 +24,30 @@ class GPUAdapterInfo : public m::HybridObject {
public:
std::string getBrand() { return _name; }

std::string getVendor() { return _instance.vendor; }
std::string getArchitecture() { return _instance.architecture; }
std::string getDevice() { return _instance.device; }
std::string getDescription() { return _instance.description; }
std::string getVendor() {
if (_instance.vendor.length) {
return _instance.vendor.data;
}
return "";
}
std::string getArchitecture() {
if (_instance.architecture.length) {
return _instance.architecture.data;
}
return "";
}
std::string getDevice() {
if (_instance.device.length) {
return _instance.device.data;
}
return "";
}
std::string getDescription() {
if (_instance.device.length) {
return _instance.device.data;
}
return "";
}

void loadHybridMethods() override {
registerHybridGetter("__brand", &GPUAdapterInfo::getBrand, this);
Expand Down
7 changes: 3 additions & 4 deletions packages/webgpu/cpp/rnwgpu/api/GPUDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ std::shared_ptr<GPUShaderModule> GPUDevice::createShaderModule(
}
sm_desc.nextInChain = &wgsl_desc;
if (descriptor->code.find('\0') != std::string::npos) {
return std::make_shared<GPUShaderModule>(
_instance.CreateErrorShaderModule(
&sm_desc, "The WGSL shader contains an illegal character '\\0'"),
_async, sm_desc.label);
auto mod = _instance.CreateErrorShaderModule(
&sm_desc, "The WGSL shader contains an illegal character '\\0'");
return std::make_shared<GPUShaderModule>(mod, _async, sm_desc.label.data);
}
auto module = _instance.CreateShaderModule(&sm_desc);
return std::make_shared<GPUShaderModule>(module, _async,
Expand Down
8 changes: 4 additions & 4 deletions packages/webgpu/cpp/rnwgpu/api/GPUFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
case wgpu::FeatureName::ImplicitDeviceSynchronization:
*outUnion = "implicit-device-synchronization";
break;
case wgpu::FeatureName::SurfaceCapabilities:
*outUnion = "surface-capabilities";
break;
// case wgpu::FeatureName::SurfaceCapabilities:
// *outUnion = "surface-capabilities";
// break;
case wgpu::FeatureName::TransientAttachments:
*outUnion = "transient-attachments";
break;
Expand Down Expand Up @@ -218,4 +218,4 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
}
}

} // namespace rnwgpu
} // namespace rnwgpu
3 changes: 2 additions & 1 deletion packages/webgpu/cpp/rnwgpu/api/GPUShaderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ GPUShaderModule::getCompilationInfo() {
for (size_t i = 0; i < compilationInfo->messageCount; ++i) {
const auto &wgpuMessage = compilationInfo->messages[i];
GPUCompilationMessage message;
message.message = wgpuMessage.message ? wgpuMessage.message : "";
message.message =
wgpuMessage.message.length ? wgpuMessage.message.data : "";
message.type = wgpuMessage.type;
message.lineNum = wgpuMessage.lineNum;
message.linePos = wgpuMessage.linePos;
Expand Down
5 changes: 3 additions & 2 deletions packages/webgpu/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import type { RNCanvasContext, CanvasRef, NativeCanvas } from "./Canvas";
type Unsubscribe = () => void;

export const warnIfNotHardwareAccelerated = (adapter: GPUAdapter) => {
if (adapter.info.architecture === "swiftshader") {
if (adapter.isFallbackAdapter) {
console.warn(
"GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow.",
// eslint-disable-next-line max-len
"GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow. Some features may be unavailable.",
);
}
};
Expand Down

0 comments on commit 9d28621

Please sign in to comment.