Revert "[dawn][webgpu.h] Use wgpu::StringView for strings in output structs."
This reverts commit 980e48de901e70a01ca96fcc30032492bfc1468f.
Reason for revert: breaks compilation of MLDrift in branded Chrome.
Original change's description:
> [dawn][webgpu.h] Use wgpu::StringView for strings in output structs.
>
> These are wgpu::AdapterInfo and wgpu::CompilationMessage.
>
> - Adds a deprecation #define for a few code changes in Skia and
> Chromium.
> - Fixup the FreeMembers logic for StringView that 1) doesn't need a
> FreeMembers method itself, 2) should have .data checked when deciding
> whether to auto-free members in the C++ header.
> - For convenience, add StringView support to webgpu_cpp_print.h
> - During conversion of dawn::native, try to simplify the handling of
> allocation and returning of output strings in Adapter and
> CompilationMessages.
> - Likewise for dawn::wire.
> - Simplify GPUCompilationMessages in dawn.node to compute all members
> in its constructor.
> - Fixup various other files for compilation errors after the change.
>
> Bug: 42241188
> Change-Id: I6db839a6b8862b4a55c1ea9911ed3725b465c2f3
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/208534
> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
TBR=cwallez@chromium.org,kainino@chromium.org,dawn-scoped@luci-project-accounts.iam.gserviceaccount.com,lokokung@google.com
Change-Id: Ib0e16a9c9486b931f3e1dca7744635a394bf5aeb
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 42241188
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/210434
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 45be92d..ef21844 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -339,8 +339,7 @@
if not self.output:
return False
for m in self.members:
- if m.annotation != 'value' \
- or m.type.name.canonical_case() == 'string view':
+ if m.annotation != 'value':
return True
return False
diff --git a/generator/templates/api.h b/generator/templates/api.h
index 05f8575..df298b0 100644
--- a/generator/templates/api.h
+++ b/generator/templates/api.h
@@ -38,7 +38,6 @@
#define {{metadata.api.upper()}}_H_
#define WGPU_BREAKING_CHANGE_STRING_VIEW_LABELS
-#define WGPU_BREAKING_CHANGE_STRING_VIEW_OUTPUT_STRUCTS
{% set API = metadata.c_prefix %}
#if defined({{API}}_SHARED_LIBRARY)
diff --git a/generator/templates/api_cpp.h b/generator/templates/api_cpp.h
index fe78b71..be78c15 100644
--- a/generator/templates/api_cpp.h
+++ b/generator/templates/api_cpp.h
@@ -755,14 +755,12 @@
{% if type.has_free_members_function %}
void {{CppType}}::FreeMembers() {
- bool needsFreeing = false;
- {%- for member in type.members if member.annotation != 'value' %}
- if (this->{{member.name.camelCase()}} != nullptr) { needsFreeing = true; }
- {%- endfor -%}
- {%- for member in type.members if member.type.name.canonical_case() == 'string view' %}
- if (this->{{member.name.camelCase()}}.data != nullptr) { needsFreeing = true; }
- {%- endfor -%}
- if (needsFreeing) {
+ if (
+ {%- for member in type.members if member.annotation != 'value' %}
+ {% if not loop.first %} || {% endif -%}
+ this->{{member.name.camelCase()}} != nullptr
+ {%- endfor -%}
+ ) {
{{as_cMethodNamespaced(type.name, Name("free members"), c_namespace)}}(
*reinterpret_cast<{{CType}}*>(this));
}
diff --git a/generator/templates/api_cpp_print.h b/generator/templates/api_cpp_print.h
index e2c9961..4c7c84a 100644
--- a/generator/templates/api_cpp_print.h
+++ b/generator/templates/api_cpp_print.h
@@ -100,12 +100,6 @@
}
{% endfor %}
- template <typename CharT, typename Traits>
- std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& o, StringView value) {
- o << std::string_view(value);
- return o;
- }
-
} // namespace {{metadata.namespace}}
#endif // {{API}}_CPP_PRINT_H_
diff --git a/generator/templates/dawn/cpp_macros.tmpl b/generator/templates/dawn/cpp_macros.tmpl
index 2b0fb20..a63acd1 100644
--- a/generator/templates/dawn/cpp_macros.tmpl
+++ b/generator/templates/dawn/cpp_macros.tmpl
@@ -40,12 +40,6 @@
this->length = WGPU_STRLEN; // use strlen
}
- // NOLINTNEXTLINE(runtime/explicit) allow implicit construction
- inline constexpr {{CppType}}(WGPUStringView s) {
- this->data = s.data;
- this->length = s.length;
- }
-
inline constexpr {{CppType}}(const char* data, size_t length) {
this->data = data;
this->length = length;
diff --git a/generator/templates/dawn/native/api_structs.cpp b/generator/templates/dawn/native/api_structs.cpp
index 64e373b..8b8c9c8 100644
--- a/generator/templates/dawn/native/api_structs.cpp
+++ b/generator/templates/dawn/native/api_structs.cpp
@@ -157,14 +157,12 @@
}
void {{as_cppType(type.name)}}::FreeMembers() {
- bool needsFreeing = false;
- {%- for member in type.members if member.annotation != 'value' %}
- if (this->{{member.name.camelCase()}} != nullptr) { needsFreeing = true; }
- {%- endfor -%}
- {%- for member in type.members if member.type.name.canonical_case() == 'string view' %}
- if (this->{{member.name.camelCase()}}.data != nullptr) { needsFreeing = true; }
- {%- endfor -%}
- if (needsFreeing) {
+ if (
+ {%- for member in type.members if member.annotation != 'value' %}
+ {% if not loop.first %} || {% endif -%}
+ this->{{member.name.camelCase()}} != nullptr
+ {%- endfor -%}
+ ) {
API{{as_MethodSuffix(type.name, Name("free members"))}}(*reinterpret_cast<{{as_cType(type.name)}}*>(this));
}
}
diff --git a/src/dawn/common/BUILD.gn b/src/dawn/common/BUILD.gn
index 64ab821..63d20a8 100644
--- a/src/dawn/common/BUILD.gn
+++ b/src/dawn/common/BUILD.gn
@@ -303,8 +303,6 @@
"SlabAllocator.cpp",
"SlabAllocator.h",
"StackAllocated.h",
- "StringViewUtils.cpp",
- "StringViewUtils.h",
"SystemUtils.cpp",
"SystemUtils.h",
"TypeTraits.h",
diff --git a/src/dawn/common/CMakeLists.txt b/src/dawn/common/CMakeLists.txt
index 8fe3b95..aa0e401 100644
--- a/src/dawn/common/CMakeLists.txt
+++ b/src/dawn/common/CMakeLists.txt
@@ -90,7 +90,6 @@
"SerialStorage.h"
"SlabAllocator.h"
"StackAllocated.h"
- "StringViewUtils.h"
"SystemUtils.h"
"TypedInteger.h"
"TypeTraits.h"
@@ -115,7 +114,6 @@
"RefCounted.cpp"
"Result.cpp"
"SlabAllocator.cpp"
- "StringViewUtils.cpp"
"SystemUtils.cpp"
"WeakRefSupport.cpp"
)
diff --git a/src/dawn/common/StringViewUtils.cpp b/src/dawn/common/StringViewUtils.cpp
deleted file mode 100644
index 63a4a51..0000000
--- a/src/dawn/common/StringViewUtils.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2024 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "dawn/common/StringViewUtils.h"
-
-bool operator==(WGPUStringView a, WGPUStringView b) {
- return wgpu::StringView(a) == wgpu::StringView(b);
-}
-
-namespace wgpu {
-bool operator==(StringView a, StringView b) {
- return std::string_view(a) == std::string_view(b);
-}
-} // namespace wgpu
-
-namespace dawn {
-
-WGPUStringView ToOutputStringView(const std::string& s) {
- return {s.data(), s.size()};
-}
-
-WGPUStringView ToOutputStringView(const std::string_view& s) {
- return {s.data(), s.size()};
-}
-
-WGPUStringView ToOutputStringView(const char* s) {
- return {s, std::strlen(s)};
-}
-
-std::string ToString(WGPUStringView s) {
- if (s.length == WGPU_STRLEN) {
- if (s.data == nullptr) {
- return {};
- }
- return {s.data};
- }
- return {s.data, s.length};
-}
-
-} // namespace dawn
diff --git a/src/dawn/common/StringViewUtils.h b/src/dawn/common/StringViewUtils.h
deleted file mode 100644
index 4b38506..0000000
--- a/src/dawn/common/StringViewUtils.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2024 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_DAWN_COMMON_STRINGVIEWUTILS_H_
-#define SRC_DAWN_COMMON_STRINGVIEWUTILS_H_
-
-#include <webgpu/webgpu_cpp.h>
-
-#include <string>
-#include <string_view>
-
-// A comparison operators for use in tests that assumes that the nil string is the same as "".
-bool operator==(WGPUStringView a, WGPUStringView b);
-namespace wgpu {
-bool operator==(StringView a, StringView b);
-} // namespace wgpu
-
-namespace dawn {
-
-// Helper functions to work with the C WGPUStringView in tests, since it doesn't have all the
-// niceties of wgpu::StringView.
-WGPUStringView ToOutputStringView(const std::string& s);
-WGPUStringView ToOutputStringView(const std::string_view& s);
-template <size_t N>
-constexpr WGPUStringView ToOutputStringView(const char (&s)[N]) {
- return {s, N - 1};
-}
-
-constexpr WGPUStringView kEmptyOutputStringView = {nullptr, 0};
-
-std::string ToString(WGPUStringView s);
-
-} // namespace dawn
-
-#endif // SRC_DAWN_COMMON_STRINGVIEWUTILS_H_
diff --git a/src/dawn/dawn.json b/src/dawn/dawn.json
index 2a9da95..34a84e0 100644
--- a/src/dawn/dawn.json
+++ b/src/dawn/dawn.json
@@ -212,10 +212,10 @@
"category": "structure",
"extensible": "out",
"members": [
- {"name": "vendor", "type": "string view"},
- {"name": "architecture", "type": "string view"},
- {"name": "device", "type": "string view"},
- {"name": "description", "type": "string view"},
+ {"name": "vendor", "type": "char", "annotation": "const*", "length": "strlen", "default": "nullptr"},
+ {"name": "architecture", "type": "char", "annotation": "const*", "length": "strlen", "default": "nullptr"},
+ {"name": "device", "type": "char", "annotation": "const*", "length": "strlen", "default": "nullptr"},
+ {"name": "description", "type": "char", "annotation": "const*", "length": "strlen", "default": "nullptr"},
{"name": "backend type", "type": "backend type"},
{"name": "adapter type", "type": "adapter type"},
{"name": "vendor ID", "type": "uint32_t"},
@@ -1094,7 +1094,7 @@
"category": "structure",
"extensible": "in",
"members": [
- {"name": "message", "type": "string view"},
+ {"name": "message", "type": "char", "annotation": "const*", "length": "strlen", "optional": true},
{"name": "type", "type": "compilation message type"},
{"name": "line num", "type": "uint64_t"},
{"name": "line pos", "type": "uint64_t"},
diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp
index 3e79c840..eebd22c 100644
--- a/src/dawn/native/Adapter.cpp
+++ b/src/dawn/native/Adapter.cpp
@@ -177,25 +177,30 @@
mPhysicalDevice->PopulateBackendProperties(unpacked);
+ // Get lengths, with null terminators.
+ size_t vendorCLen = mPhysicalDevice->GetVendorName().length() + 1;
+ size_t architectureCLen = mPhysicalDevice->GetArchitectureName().length() + 1;
+ size_t deviceCLen = mPhysicalDevice->GetName().length() + 1;
+ size_t descriptionCLen = mPhysicalDevice->GetDriverDescription().length() + 1;
+
// Allocate space for all strings.
- size_t allocSize = mPhysicalDevice->GetVendorName().length() +
- mPhysicalDevice->GetArchitectureName().length() +
- mPhysicalDevice->GetName().length() +
- mPhysicalDevice->GetDriverDescription().length();
- absl::Span<char> outBuffer{new char[allocSize], allocSize};
+ char* ptr = new char[vendorCLen + architectureCLen + deviceCLen + descriptionCLen];
- auto AddString = [&](const std::string& in, StringView* out) {
- DAWN_ASSERT(in.length() <= outBuffer.length());
- memcpy(outBuffer.data(), in.data(), in.length());
- *out = {outBuffer.data(), in.length()};
- outBuffer = outBuffer.subspan(in.length());
- };
+ info->vendor = ptr;
+ memcpy(ptr, mPhysicalDevice->GetVendorName().c_str(), vendorCLen);
+ ptr += vendorCLen;
- AddString(mPhysicalDevice->GetVendorName(), &info->vendor);
- AddString(mPhysicalDevice->GetArchitectureName(), &info->architecture);
- AddString(mPhysicalDevice->GetName(), &info->device);
- AddString(mPhysicalDevice->GetDriverDescription(), &info->description);
- DAWN_ASSERT(outBuffer.empty());
+ info->architecture = ptr;
+ memcpy(ptr, mPhysicalDevice->GetArchitectureName().c_str(), architectureCLen);
+ ptr += architectureCLen;
+
+ info->device = ptr;
+ memcpy(ptr, mPhysicalDevice->GetName().c_str(), deviceCLen);
+ ptr += deviceCLen;
+
+ info->description = ptr;
+ memcpy(ptr, mPhysicalDevice->GetDriverDescription().c_str(), descriptionCLen);
+ ptr += descriptionCLen;
info->backendType = mPhysicalDevice->GetBackendType();
info->adapterType = mPhysicalDevice->GetAdapterType();
@@ -208,7 +213,7 @@
void APIAdapterInfoFreeMembers(WGPUAdapterInfo info) {
// This single delete is enough because everything is a single allocation.
- delete[] info.vendor.data;
+ delete[] info.vendor;
}
void APIAdapterPropertiesMemoryHeapsFreeMembers(
diff --git a/src/dawn/native/CompilationMessages.cpp b/src/dawn/native/CompilationMessages.cpp
index 91c3b59..3fed812 100644
--- a/src/dawn/native/CompilationMessages.cpp
+++ b/src/dawn/native/CompilationMessages.cpp
@@ -28,7 +28,6 @@
#include "dawn/native/CompilationMessages.h"
#include "dawn/common/Assert.h"
-#include "dawn/common/StringViewUtils.h"
#include "dawn/native/dawn_platform.h"
#include "tint/tint.h"
@@ -37,14 +36,14 @@
namespace {
-wgpu::CompilationMessageType TintSeverityToMessageType(tint::diag::Severity severity) {
+WGPUCompilationMessageType tintSeverityToMessageType(tint::diag::Severity severity) {
switch (severity) {
case tint::diag::Severity::Note:
- return wgpu::CompilationMessageType::Info;
+ return WGPUCompilationMessageType_Info;
case tint::diag::Severity::Warning:
- return wgpu::CompilationMessageType::Warning;
+ return WGPUCompilationMessageType_Warning;
default:
- return wgpu::CompilationMessageType::Error;
+ return WGPUCompilationMessageType_Error;
}
}
@@ -93,11 +92,8 @@
void OwnedCompilationMessages::AddUnanchoredMessage(std::string_view message,
wgpu::CompilationMessageType type) {
- CompilationMessage m = {};
- m.message = message;
- m.type = type;
-
- AddMessage(m);
+ AddMessage(message, {nullptr, nullptr, static_cast<WGPUCompilationMessageType>(type), 0, 0, 0,
+ 0, 0, 0, 0});
}
void OwnedCompilationMessages::AddMessageForTesting(std::string_view message,
@@ -106,18 +102,8 @@
uint64_t linePos,
uint64_t offset,
uint64_t length) {
- CompilationMessage m = {};
- m.message = message;
- m.type = type;
- m.lineNum = lineNum;
- m.linePos = linePos;
- m.offset = offset;
- m.length = length;
- m.utf16LinePos = linePos;
- m.utf16Offset = offset;
- m.utf16Length = length;
-
- AddMessage(m);
+ AddMessage(message, {nullptr, nullptr, static_cast<WGPUCompilationMessageType>(type), lineNum,
+ linePos, offset, length, linePos, offset, length});
}
MaybeError OwnedCompilationMessages::AddMessage(const tint::diag::Diagnostic& diagnostic) {
@@ -174,36 +160,25 @@
fileStart + offsetInBytes, lengthInBytes)));
}
- std::string plainMessage = diagnostic.message.Plain();
+ AddMessage(
+ diagnostic.message.Plain(),
+ {nullptr, nullptr, tintSeverityToMessageType(diagnostic.severity), lineNum, linePosInBytes,
+ offsetInBytes, lengthInBytes, linePosInUTF16, offsetInUTF16, lengthInUTF16});
- CompilationMessage m = {};
- m.message = std::string_view(plainMessage);
- m.type = TintSeverityToMessageType(diagnostic.severity);
- m.lineNum = lineNum;
- m.linePos = linePosInBytes;
- m.offset = offsetInBytes;
- m.length = lengthInBytes;
- m.utf16LinePos = linePosInUTF16;
- m.utf16Offset = offsetInUTF16;
- m.utf16Length = lengthInUTF16;
-
- AddMessage(m);
return {};
}
-void OwnedCompilationMessages::AddMessage(const CompilationMessage& message) {
+void OwnedCompilationMessages::AddMessage(std::string_view messageString,
+ const WGPUCompilationMessage& message) {
// Cannot add messages after GetCompilationInfo has been called.
DAWN_ASSERT(mCompilationInfo.messages == nullptr);
DAWN_ASSERT(message.nextInChain == nullptr);
+ // The message string won't be populated until GetCompilationInfo.
+ DAWN_ASSERT(message.message == nullptr);
+ mMessageStrings.push_back(std::string(messageString));
mMessages.push_back(message);
-
- // Own the contents of the message as it might be freed afterwards.
- // Note that we use make_unique here as moving strings doesn't guarantee that the data pointer
- // stays the same, for example if there's some small string optimization.
- mMessageStrings.push_back(std::make_unique<std::string>(message.message));
- mMessages.back().message = ToOutputStringView(*mMessageStrings.back());
}
MaybeError OwnedCompilationMessages::AddMessages(const tint::diag::List& diagnostics) {
@@ -227,10 +202,18 @@
mMessages.clear();
}
-const CompilationInfo* OwnedCompilationMessages::GetCompilationInfo() {
+const WGPUCompilationInfo* OwnedCompilationMessages::GetCompilationInfo() {
mCompilationInfo.messageCount = mMessages.size();
mCompilationInfo.messages = mMessages.data();
+ // Ensure every message points at the correct message string. Cannot do this earlier, since
+ // vector reallocations may move the pointers around.
+ for (size_t i = 0; i < mCompilationInfo.messageCount; ++i) {
+ WGPUCompilationMessage& message = mMessages[i];
+ std::string& messageString = mMessageStrings[i];
+ message.message = messageString.c_str();
+ }
+
return &mCompilationInfo;
}
@@ -240,8 +223,8 @@
bool OwnedCompilationMessages::HasWarningsOrErrors() const {
for (const auto& message : mMessages) {
- if (message.type == wgpu::CompilationMessageType::Error ||
- message.type == wgpu::CompilationMessageType::Warning) {
+ if (message.type == WGPUCompilationMessageType_Error ||
+ message.type == WGPUCompilationMessageType_Warning) {
return true;
}
}
diff --git a/src/dawn/native/CompilationMessages.h b/src/dawn/native/CompilationMessages.h
index 8a0280d..55c7c8b 100644
--- a/src/dawn/native/CompilationMessages.h
+++ b/src/dawn/native/CompilationMessages.h
@@ -28,7 +28,6 @@
#ifndef SRC_DAWN_NATIVE_COMPILATIONMESSAGES_H_
#define SRC_DAWN_NATIVE_COMPILATIONMESSAGES_H_
-#include <memory>
#include <string>
#include <vector>
@@ -67,18 +66,18 @@
MaybeError AddMessages(const tint::diag::List& diagnostics);
void ClearMessages();
- const CompilationInfo* GetCompilationInfo();
+ const WGPUCompilationInfo* GetCompilationInfo();
const std::vector<std::string>& GetFormattedTintMessages() const;
bool HasWarningsOrErrors() const;
private:
MaybeError AddMessage(const tint::diag::Diagnostic& diagnostic);
- void AddMessage(const CompilationMessage& message);
+ void AddMessage(std::string_view messageString, const WGPUCompilationMessage& message);
void AddFormattedTintMessages(const tint::diag::List& diagnostics);
- CompilationInfo mCompilationInfo;
- std::vector<std::unique_ptr<std::string>> mMessageStrings;
- std::vector<CompilationMessage> mMessages;
+ WGPUCompilationInfo mCompilationInfo;
+ std::vector<std::string> mMessageStrings;
+ std::vector<WGPUCompilationMessage> mMessages;
std::vector<std::string> mFormattedTintMessages;
};
diff --git a/src/dawn/native/ShaderModule.cpp b/src/dawn/native/ShaderModule.cpp
index cf73dfc..46b9536 100644
--- a/src/dawn/native/ShaderModule.cpp
+++ b/src/dawn/native/ShaderModule.cpp
@@ -1560,13 +1560,13 @@
void Complete(EventCompletionType completionType) override {
WGPUCompilationInfoRequestStatus status =
WGPUCompilationInfoRequestStatus_InstanceDropped;
- const CompilationInfo* compilationInfo = nullptr;
+ const WGPUCompilationInfo* compilationInfo = nullptr;
if (completionType == EventCompletionType::Ready) {
status = WGPUCompilationInfoRequestStatus_Success;
compilationInfo = mShaderModule->mCompilationMessages->GetCompilationInfo();
}
- mCallback(status, ToAPI(compilationInfo), mUserdata1.ExtractAsDangling(),
+ mCallback(status, compilationInfo, mUserdata1.ExtractAsDangling(),
mUserdata2.ExtractAsDangling());
}
};
diff --git a/src/dawn/node/binding/GPU.cpp b/src/dawn/node/binding/GPU.cpp
index 31c8e8d..4903aa7 100644
--- a/src/dawn/node/binding/GPU.cpp
+++ b/src/dawn/node/binding/GPU.cpp
@@ -219,12 +219,10 @@
for (auto& a : adapters) {
wgpu::AdapterInfo info;
a.GetInfo(&info);
-
- if (!deviceName.empty() &&
- std::string_view(info.device).find(deviceName) == std::string::npos) {
+ if (!deviceName.empty() && info.device &&
+ std::string(info.device).find(deviceName) == std::string::npos) {
continue;
}
-
adapter = &a;
break;
}
@@ -259,7 +257,7 @@
if (flags_.Get("verbose")) {
wgpu::AdapterInfo info;
adapter->GetInfo(&info);
- std::cout << "using GPU adapter: " << info.device << "\n";
+ printf("using GPU adapter: %s\n", info.device);
}
auto gpuAdapter = GPUAdapter::Create<GPUAdapter>(env, *adapter, flags_, async_);
diff --git a/src/dawn/node/binding/GPUAdapterInfo.cpp b/src/dawn/node/binding/GPUAdapterInfo.cpp
index 80c75c9..bedffcf 100644
--- a/src/dawn/node/binding/GPUAdapterInfo.cpp
+++ b/src/dawn/node/binding/GPUAdapterInfo.cpp
@@ -36,7 +36,7 @@
// wgpu::bindings::GPUAdapterInfo
////////////////////////////////////////////////////////////////////////////////
-GPUAdapterInfo::GPUAdapterInfo(const wgpu::AdapterInfo& info)
+GPUAdapterInfo::GPUAdapterInfo(WGPUAdapterInfo info)
: vendor_(info.vendor),
architecture_(info.architecture),
device_(info.device),
diff --git a/src/dawn/node/binding/GPUAdapterInfo.h b/src/dawn/node/binding/GPUAdapterInfo.h
index 965d2da..316e78f 100644
--- a/src/dawn/node/binding/GPUAdapterInfo.h
+++ b/src/dawn/node/binding/GPUAdapterInfo.h
@@ -41,7 +41,7 @@
// GPUAdapterInfo is an implementation of interop::GPUAdapterInfo.
class GPUAdapterInfo final : public interop::GPUAdapterInfo {
public:
- explicit GPUAdapterInfo(const wgpu::AdapterInfo& info);
+ explicit GPUAdapterInfo(WGPUAdapterInfo);
// interop::GPUAdapterInfo interface compliance
std::string getVendor(Napi::Env) override;
diff --git a/src/dawn/node/binding/GPUShaderModule.cpp b/src/dawn/node/binding/GPUShaderModule.cpp
index d5f8f87..44cf937 100644
--- a/src/dawn/node/binding/GPUShaderModule.cpp
+++ b/src/dawn/node/binding/GPUShaderModule.cpp
@@ -46,40 +46,26 @@
interop::Promise<interop::Interface<interop::GPUCompilationInfo>>
GPUShaderModule::getCompilationInfo(Napi::Env env) {
struct GPUCompilationMessage : public interop::GPUCompilationMessage {
- interop::GPUCompilationMessageType type;
- uint64_t lineNum;
- uint64_t linePos;
- uint64_t offset;
- uint64_t length;
- std::string message;
+ WGPUCompilationMessage message;
- explicit GPUCompilationMessage(const wgpu::CompilationMessage& m)
- : lineNum(m.lineNum),
- linePos(m.utf16LinePos),
- offset(m.utf16Offset),
- length(m.utf16Length),
- message(m.message) {
- switch (m.type) {
- case wgpu::CompilationMessageType::Error:
- type = interop::GPUCompilationMessageType::kError;
- break;
- case wgpu::CompilationMessageType::Warning:
- type = interop::GPUCompilationMessageType::kWarning;
- break;
- case wgpu::CompilationMessageType::Info:
- type = interop::GPUCompilationMessageType::kInfo;
- break;
+ explicit GPUCompilationMessage(const WGPUCompilationMessage& m) : message(m) {}
+ std::string getMessage(Napi::Env) override { return message.message; }
+ interop::GPUCompilationMessageType getType(Napi::Env) override {
+ switch (message.type) {
+ case WGPUCompilationMessageType_Error:
+ return interop::GPUCompilationMessageType::kError;
+ case WGPUCompilationMessageType_Warning:
+ return interop::GPUCompilationMessageType::kWarning;
+ case WGPUCompilationMessageType_Info:
+ return interop::GPUCompilationMessageType::kInfo;
default:
- UNREACHABLE("unrecognized handled compilation message type", m.type);
+ UNREACHABLE("unrecognized handled compilation message type", message.type);
}
}
-
- std::string getMessage(Napi::Env) override { return message; }
- interop::GPUCompilationMessageType getType(Napi::Env) override { return type; }
- uint64_t getLineNum(Napi::Env) override { return lineNum; }
- uint64_t getLinePos(Napi::Env) override { return linePos; }
- uint64_t getOffset(Napi::Env) override { return offset; }
- uint64_t getLength(Napi::Env) override { return length; }
+ uint64_t getLineNum(Napi::Env) override { return message.lineNum; }
+ uint64_t getLinePos(Napi::Env) override { return message.utf16LinePos; }
+ uint64_t getOffset(Napi::Env) override { return message.utf16Offset; }
+ uint64_t getLength(Napi::Env) override { return message.utf16Length; }
};
using Messages = std::vector<interop::Interface<interop::GPUCompilationMessage>>;
diff --git a/src/dawn/samples/DawnInfo.cpp b/src/dawn/samples/DawnInfo.cpp
index cc5eaa6..4ca39d9 100644
--- a/src/dawn/samples/DawnInfo.cpp
+++ b/src/dawn/samples/DawnInfo.cpp
@@ -35,7 +35,6 @@
#include "dawn/dawn_proc.h" // nogncheck
#include "dawn/native/DawnNative.h"
-#include "dawn/webgpu_cpp_print.h"
namespace {
diff --git a/src/dawn/samples/SampleUtils.cpp b/src/dawn/samples/SampleUtils.cpp
index cb6095c..18cee4b 100644
--- a/src/dawn/samples/SampleUtils.cpp
+++ b/src/dawn/samples/SampleUtils.cpp
@@ -43,7 +43,6 @@
#include "dawn/utils/CommandLineParser.h"
#include "dawn/utils/SystemUtils.h"
#include "dawn/utils/WGPUHelpers.h"
-#include "dawn/webgpu_cpp_print.h"
#ifndef __EMSCRIPTEN__
#include "GLFW/glfw3.h"
diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp
index 6ba7dd0..2a7e9a6 100644
--- a/src/dawn/tests/DawnTest.cpp
+++ b/src/dawn/tests/DawnTest.cpp
@@ -746,7 +746,7 @@
info.deviceID == param.adapterProperties.deviceID &&
info.vendorID == param.adapterProperties.vendorID &&
info.adapterType == param.adapterProperties.adapterType &&
- std::string_view(info.device) == param.adapterProperties.name);
+ strcmp(info.device, param.adapterProperties.name.c_str()) == 0);
});
DAWN_ASSERT(it != adapters.end());
gCurrentTest->mBackendAdapter = *it;
diff --git a/src/dawn/tests/end2end/AdapterCreationTests.cpp b/src/dawn/tests/end2end/AdapterCreationTests.cpp
index b0d23c0..df281cc 100644
--- a/src/dawn/tests/end2end/AdapterCreationTests.cpp
+++ b/src/dawn/tests/end2end/AdapterCreationTests.cpp
@@ -33,7 +33,6 @@
#include <utility>
#include "dawn/common/GPUInfo.h"
-#include "dawn/common/StringViewUtils.h"
#include "dawn/dawn_proc.h"
#include "dawn/native/DawnNative.h"
#include "dawn/tests/DawnTest.h"
@@ -324,14 +323,14 @@
adapter.GetInfo(&info1);
adapter.GetInfo(&info2);
- EXPECT_NE(info1.vendor.data, info2.vendor.data);
- EXPECT_EQ(info1.vendor, info2.vendor);
- EXPECT_NE(info1.architecture.data, info2.architecture.data);
- EXPECT_EQ(info1.architecture, info2.architecture);
- EXPECT_NE(info1.device.data, info2.device.data);
- EXPECT_EQ(info1.device, info2.device);
- EXPECT_NE(info1.description.data, info2.description.data);
- EXPECT_EQ(info1.description, info2.description);
+ EXPECT_NE(info1.vendor, info2.vendor);
+ EXPECT_STREQ(info1.vendor, info2.vendor);
+ EXPECT_NE(info1.architecture, info2.architecture);
+ EXPECT_STREQ(info1.architecture, info2.architecture);
+ EXPECT_NE(info1.device, info2.device);
+ EXPECT_STREQ(info1.device, info2.device);
+ EXPECT_NE(info1.description, info2.description);
+ EXPECT_STREQ(info1.description, info2.description);
}
// Test move assignment of the adapter info.
@@ -356,10 +355,10 @@
adapter.GetInfo(&info1);
adapter.GetInfo(&info2);
- wgpu::StringView vendor = info1.vendor;
- wgpu::StringView architecture = info1.architecture;
- wgpu::StringView device = info1.device;
- wgpu::StringView description = info1.description;
+ std::string vendor = info1.vendor;
+ std::string architecture = info1.architecture;
+ std::string device = info1.device;
+ std::string description = info1.description;
wgpu::BackendType backendType = info1.backendType;
wgpu::AdapterType adapterType = info1.adapterType;
uint32_t vendorID = info1.vendorID;
@@ -369,10 +368,10 @@
info2 = std::move(info1);
// Expect info2 to have info1's old contents.
- EXPECT_EQ(info2.vendor, vendor);
- EXPECT_EQ(info2.architecture, architecture);
- EXPECT_EQ(info2.device, device);
- EXPECT_EQ(info2.description, description);
+ EXPECT_STREQ(info2.vendor, vendor.c_str());
+ EXPECT_STREQ(info2.architecture, architecture.c_str());
+ EXPECT_STREQ(info2.device, device.c_str());
+ EXPECT_STREQ(info2.description, description.c_str());
EXPECT_EQ(info2.backendType, backendType);
EXPECT_EQ(info2.adapterType, adapterType);
EXPECT_EQ(info2.vendorID, vendorID);
@@ -380,14 +379,10 @@
EXPECT_EQ(info2.compatibilityMode, compatibilityMode);
// Expect info1 to be empty.
- EXPECT_EQ(info1.vendor.data, nullptr);
- EXPECT_EQ(info1.vendor.length, wgpu::kStrlen);
- EXPECT_EQ(info1.architecture.data, nullptr);
- EXPECT_EQ(info1.architecture.length, wgpu::kStrlen);
- EXPECT_EQ(info1.device.data, nullptr);
- EXPECT_EQ(info1.device.length, wgpu::kStrlen);
- EXPECT_EQ(info1.description.data, nullptr);
- EXPECT_EQ(info1.description.length, wgpu::kStrlen);
+ EXPECT_EQ(info1.vendor, nullptr);
+ EXPECT_EQ(info1.architecture, nullptr);
+ EXPECT_EQ(info1.device, nullptr);
+ EXPECT_EQ(info1.description, nullptr);
EXPECT_EQ(info1.backendType, static_cast<wgpu::BackendType>(0));
EXPECT_EQ(info1.adapterType, static_cast<wgpu::AdapterType>(0));
EXPECT_EQ(info1.vendorID, 0u);
@@ -415,10 +410,10 @@
wgpu::AdapterInfo info1;
adapter.GetInfo(&info1);
- wgpu::StringView vendor = info1.vendor;
- wgpu::StringView architecture = info1.architecture;
- wgpu::StringView device = info1.device;
- wgpu::StringView description = info1.description;
+ std::string vendor = info1.vendor;
+ std::string architecture = info1.architecture;
+ std::string device = info1.device;
+ std::string description = info1.description;
wgpu::BackendType backendType = info1.backendType;
wgpu::AdapterType adapterType = info1.adapterType;
uint32_t vendorID = info1.vendorID;
@@ -428,10 +423,10 @@
wgpu::AdapterInfo info2(std::move(info1));
// Expect info2 to have info1's old contents.
- EXPECT_EQ(info2.vendor, vendor);
- EXPECT_EQ(info2.architecture, architecture);
- EXPECT_EQ(info2.device, device);
- EXPECT_EQ(info2.description, description);
+ EXPECT_STREQ(info2.vendor, vendor.c_str());
+ EXPECT_STREQ(info2.architecture, architecture.c_str());
+ EXPECT_STREQ(info2.device, device.c_str());
+ EXPECT_STREQ(info2.description, description.c_str());
EXPECT_EQ(info2.backendType, backendType);
EXPECT_EQ(info2.adapterType, adapterType);
EXPECT_EQ(info2.vendorID, vendorID);
@@ -439,14 +434,10 @@
EXPECT_EQ(info2.compatibilityMode, compatibilityMode);
// Expect info1 to be empty.
- EXPECT_EQ(info1.vendor.data, nullptr);
- EXPECT_EQ(info1.vendor.length, wgpu::kStrlen);
- EXPECT_EQ(info1.architecture.data, nullptr);
- EXPECT_EQ(info1.architecture.length, wgpu::kStrlen);
- EXPECT_EQ(info1.device.data, nullptr);
- EXPECT_EQ(info1.device.length, wgpu::kStrlen);
- EXPECT_EQ(info1.description.data, nullptr);
- EXPECT_EQ(info1.description.length, wgpu::kStrlen);
+ EXPECT_EQ(info1.vendor, nullptr);
+ EXPECT_EQ(info1.architecture, nullptr);
+ EXPECT_EQ(info1.device, nullptr);
+ EXPECT_EQ(info1.description, nullptr);
EXPECT_EQ(info1.backendType, static_cast<wgpu::BackendType>(0));
EXPECT_EQ(info1.adapterType, static_cast<wgpu::AdapterType>(0));
EXPECT_EQ(info1.vendorID, 0u);
@@ -475,10 +466,10 @@
adapter.GetInfo(&info);
// Make a copy of the info.
- std::string vendor{std::string_view(info.vendor)};
- std::string architecture{std::string_view(info.architecture)};
- std::string device{std::string_view(info.device)};
- std::string description{std::string_view(info.description)};
+ std::string vendor = info.vendor;
+ std::string architecture = info.architecture;
+ std::string device = info.device;
+ std::string description = info.description;
// Release the adapter.
adapter = nullptr;
@@ -486,10 +477,10 @@
// Ensure we still read the info (pointers are still valid).
// Check the values are equal to make sure they haven't been overwritten,
// and to make sure the compiler can't elide no-op pointer reads.
- EXPECT_EQ(std::string_view(info.vendor), vendor);
- EXPECT_EQ(std::string_view(info.architecture), architecture);
- EXPECT_EQ(std::string_view(info.device), device);
- EXPECT_EQ(std::string_view(info.description), description);
+ EXPECT_EQ(info.vendor, vendor);
+ EXPECT_EQ(info.architecture, architecture);
+ EXPECT_EQ(info.device, device);
+ EXPECT_EQ(info.description, description);
}
} // anonymous namespace
diff --git a/src/dawn/tests/end2end/AdapterEnumerationTests.cpp b/src/dawn/tests/end2end/AdapterEnumerationTests.cpp
index a6206b2..a8e721b 100644
--- a/src/dawn/tests/end2end/AdapterEnumerationTests.cpp
+++ b/src/dawn/tests/end2end/AdapterEnumerationTests.cpp
@@ -31,7 +31,6 @@
#include <utility>
#include "dawn/common/GPUInfo.h"
-#include "dawn/common/StringViewUtils.h"
#include "dawn/dawn_proc.h"
#include "dawn/native/DawnNative.h"
@@ -155,10 +154,10 @@
wgpu::AdapterInfo infoAgain;
adaptersAgain[0].GetInfo(&infoAgain);
- EXPECT_EQ(info.vendor, infoAgain.vendor);
- EXPECT_EQ(info.architecture, infoAgain.architecture);
- EXPECT_EQ(info.device, infoAgain.device);
- EXPECT_EQ(info.description, infoAgain.description);
+ EXPECT_STREQ(info.vendor, infoAgain.vendor);
+ EXPECT_STREQ(info.architecture, infoAgain.architecture);
+ EXPECT_STREQ(info.device, infoAgain.device);
+ EXPECT_STREQ(info.description, infoAgain.description);
EXPECT_EQ(info.backendType, infoAgain.backendType);
EXPECT_EQ(info.adapterType, infoAgain.adapterType);
EXPECT_EQ(info.vendorID, infoAgain.vendorID);
@@ -229,10 +228,10 @@
wgpu::AdapterInfo infoAgain;
adaptersAgain[0].GetInfo(&infoAgain);
- EXPECT_EQ(info.vendor, infoAgain.vendor);
- EXPECT_EQ(info.architecture, infoAgain.architecture);
- EXPECT_EQ(info.device, infoAgain.device);
- EXPECT_EQ(info.description, infoAgain.description);
+ EXPECT_STREQ(info.vendor, infoAgain.vendor);
+ EXPECT_STREQ(info.architecture, infoAgain.architecture);
+ EXPECT_STREQ(info.device, infoAgain.device);
+ EXPECT_STREQ(info.description, infoAgain.description);
EXPECT_EQ(info.backendType, infoAgain.backendType);
EXPECT_EQ(info.adapterType, infoAgain.adapterType);
EXPECT_EQ(info.vendorID, infoAgain.vendorID);
diff --git a/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp b/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp
index 9400eca..299eeff 100644
--- a/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/ShaderModuleValidationTests.cpp
@@ -290,25 +290,25 @@
ASSERT_EQ(4u, info->messageCount);
const wgpu::CompilationMessage* message = &info->messages[0];
- ASSERT_EQ("Info Message", std::string_view(message->message));
+ ASSERT_STREQ("Info Message", message->message);
ASSERT_EQ(wgpu::CompilationMessageType::Info, message->type);
ASSERT_EQ(0u, message->lineNum);
ASSERT_EQ(0u, message->linePos);
message = &info->messages[1];
- ASSERT_EQ("Warning Message", std::string_view(message->message));
+ ASSERT_STREQ("Warning Message", message->message);
ASSERT_EQ(wgpu::CompilationMessageType::Warning, message->type);
ASSERT_EQ(0u, message->lineNum);
ASSERT_EQ(0u, message->linePos);
message = &info->messages[2];
- ASSERT_EQ("Error Message", std::string_view(message->message));
+ ASSERT_STREQ("Error Message", message->message);
ASSERT_EQ(wgpu::CompilationMessageType::Error, message->type);
ASSERT_EQ(3u, message->lineNum);
ASSERT_EQ(4u, message->linePos);
message = &info->messages[3];
- ASSERT_EQ("Complete Message", std::string_view(message->message));
+ ASSERT_STREQ("Complete Message", message->message);
ASSERT_EQ(wgpu::CompilationMessageType::Info, message->type);
ASSERT_EQ(3u, message->lineNum);
ASSERT_EQ(4u, message->linePos);
@@ -732,7 +732,7 @@
ASSERT_EQ(1u, info->messageCount);
const wgpu::CompilationMessage* message = &info->messages[0];
- ASSERT_EQ("Shader compilation error", std::string_view(message->message));
+ ASSERT_STREQ("Shader compilation error", message->message);
ASSERT_EQ(wgpu::CompilationMessageType::Error, message->type);
ASSERT_EQ(0u, message->lineNum);
ASSERT_EQ(0u, message->linePos);
diff --git a/src/dawn/tests/unittests/wire/WireInstanceTests.cpp b/src/dawn/tests/unittests/wire/WireInstanceTests.cpp
index f6865a7..8b97d85 100644
--- a/src/dawn/tests/unittests/wire/WireInstanceTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireInstanceTests.cpp
@@ -28,7 +28,6 @@
#include <unordered_set>
#include <vector>
-#include "dawn/common/StringViewUtils.h"
#include "dawn/tests/MockCallback.h"
#include "dawn/tests/unittests/wire/WireFutureTest.h"
#include "dawn/tests/unittests/wire/WireTest.h"
@@ -120,10 +119,10 @@
InstanceRequestAdapter(instance, &options, nullptr);
WGPUAdapterInfo fakeInfo = {};
- fakeInfo.vendor = ToOutputStringView("fake-vendor");
- fakeInfo.architecture = ToOutputStringView("fake-architecture");
- fakeInfo.device = ToOutputStringView("fake-device");
- fakeInfo.description = ToOutputStringView("fake-description");
+ fakeInfo.vendor = "fake-vendor";
+ fakeInfo.architecture = "fake-architecture";
+ fakeInfo.device = "fake adapter";
+ fakeInfo.description = "hello world";
fakeInfo.backendType = WGPUBackendType_D3D12;
fakeInfo.adapterType = WGPUAdapterType_IntegratedGPU;
fakeInfo.vendorID = 0x134;
@@ -180,14 +179,10 @@
.WillOnce(WithArg<1>(Invoke([&](WGPUAdapter adapter) {
WGPUAdapterInfo info = {};
wgpuAdapterGetInfo(adapter, &info);
- EXPECT_NE(info.vendor.length, WGPU_STRLEN);
- EXPECT_EQ(info.vendor, fakeInfo.vendor);
- EXPECT_NE(info.architecture.length, WGPU_STRLEN);
- EXPECT_EQ(info.architecture, fakeInfo.architecture);
- EXPECT_NE(info.device.length, WGPU_STRLEN);
- EXPECT_EQ(info.device, fakeInfo.device);
- EXPECT_NE(info.description.length, WGPU_STRLEN);
- EXPECT_EQ(info.description, fakeInfo.description);
+ EXPECT_STREQ(info.vendor, fakeInfo.vendor);
+ EXPECT_STREQ(info.architecture, fakeInfo.architecture);
+ EXPECT_STREQ(info.device, fakeInfo.device);
+ EXPECT_STREQ(info.description, fakeInfo.description);
EXPECT_EQ(info.backendType, fakeInfo.backendType);
EXPECT_EQ(info.adapterType, fakeInfo.adapterType);
EXPECT_EQ(info.vendorID, fakeInfo.vendorID);
@@ -254,10 +249,10 @@
EXPECT_CALL(api, AdapterGetInfo(apiAdapter, NotNull()))
.WillOnce(WithArg<1>(Invoke([&](WGPUAdapterInfo* info) {
- info->vendor = ToOutputStringView("fake-vendor");
- info->architecture = ToOutputStringView("fake-architecture");
- info->device = ToOutputStringView("fake-device");
- info->description = ToOutputStringView("fake-description");
+ info->vendor = "fake-vendor";
+ info->architecture = "fake-architecture";
+ info->device = "fake adapter";
+ info->description = "hello world";
WGPUChainedStructOut* chain = info->nextInChain;
while (chain != nullptr) {
@@ -377,10 +372,10 @@
EXPECT_CALL(api, AdapterGetInfo(apiAdapter, NotNull()))
.WillOnce(WithArg<1>(Invoke([&](WGPUAdapterInfo* info) {
- info->vendor = ToOutputStringView("fake-vendor");
- info->architecture = ToOutputStringView("fake-architecture");
- info->device = ToOutputStringView("fake-device");
- info->description = ToOutputStringView("fake-description");
+ info->vendor = "fake-vendor";
+ info->architecture = "fake-architecture";
+ info->device = "fake adapter";
+ info->description = "hello world";
return WGPUStatus_Success;
})));
diff --git a/src/dawn/tests/unittests/wire/WireShaderModuleTests.cpp b/src/dawn/tests/unittests/wire/WireShaderModuleTests.cpp
index 3dff5f7..f6f2cb6 100644
--- a/src/dawn/tests/unittests/wire/WireShaderModuleTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireShaderModuleTests.cpp
@@ -27,7 +27,6 @@
#include <memory>
-#include "dawn/common/StringViewUtils.h"
#include "dawn/tests/unittests/wire/WireFutureTest.h"
#include "dawn/tests/unittests/wire/WireTest.h"
#include "dawn/wire/WireClient.h"
@@ -67,16 +66,8 @@
WGPUShaderModule apiShaderModule;
// Default responses.
- WGPUCompilationMessage mMessage = {nullptr,
- ToOutputStringView("Test Message"),
- WGPUCompilationMessageType_Info,
- 2,
- 4,
- 6,
- 8,
- 4,
- 6,
- 8};
+ WGPUCompilationMessage mMessage = {
+ nullptr, "Test Message", WGPUCompilationMessageType_Info, 2, 4, 6, 8, 4, 6, 8};
WGPUCompilationInfo mCompilationInfo = {nullptr, 1, &mMessage};
};
@@ -101,8 +92,7 @@
return false;
}
const WGPUCompilationMessage* infoMessage = &info->messages[0];
- EXPECT_NE(infoMessage->message.length, WGPU_STRLEN);
- return infoMessage->message == mMessage.message &&
+ return strcmp(infoMessage->message, mMessage.message) == 0 &&
infoMessage->nextInChain == mMessage.nextInChain &&
infoMessage->type == mMessage.type &&
infoMessage->lineNum == mMessage.lineNum &&
diff --git a/src/dawn/tests/unittests/wire/WireTest.cpp b/src/dawn/tests/unittests/wire/WireTest.cpp
index fcfcaca..519d212 100644
--- a/src/dawn/tests/unittests/wire/WireTest.cpp
+++ b/src/dawn/tests/unittests/wire/WireTest.cpp
@@ -27,7 +27,6 @@
#include "dawn/tests/unittests/wire/WireTest.h"
-#include "dawn/common/StringViewUtils.h"
#include "dawn/dawn_proc.h"
#include "dawn/tests/MockCallback.h"
#include "dawn/utils/TerribleCommandBuffer.h"
@@ -101,10 +100,10 @@
EXPECT_CALL(api, AdapterGetInfo(apiAdapter, NotNull()))
.WillOnce(WithArg<1>(Invoke([&](WGPUAdapterInfo* info) {
*info = {};
- info->vendor = dawn::kEmptyOutputStringView;
- info->architecture = dawn::kEmptyOutputStringView;
- info->device = dawn::kEmptyOutputStringView;
- info->description = dawn::kEmptyOutputStringView;
+ info->vendor = "";
+ info->architecture = "";
+ info->device = "";
+ info->description = "";
return WGPUStatus_Success;
})));
diff --git a/src/dawn/wire/client/Adapter.cpp b/src/dawn/wire/client/Adapter.cpp
index 3c07a4b..9503051 100644
--- a/src/dawn/wire/client/Adapter.cpp
+++ b/src/dawn/wire/client/Adapter.cpp
@@ -31,9 +31,7 @@
#include <string>
#include <utility>
-#include "absl/types/span.h" // TODO(343500108): Use std::span when we have C++20.
#include "dawn/common/Log.h"
-#include "dawn/common/StringViewUtils.h"
#include "dawn/wire/client/Client.h"
#include "dawn/wire/client/webgpu.h"
#include "partition_alloc/pointers/raw_ptr.h"
@@ -166,15 +164,15 @@
void Adapter::SetInfo(const WGPUAdapterInfo* info) {
mInfo = *info;
- // Deep copy the string pointed out by info. StringViews are all explicitly sized by the wire.
- mVendor = ToString(info->vendor);
- mInfo.vendor = ToOutputStringView(mVendor);
- mArchitecture = ToString(info->architecture);
- mInfo.architecture = ToOutputStringView(mArchitecture);
- mDeviceName = ToString(info->device);
- mInfo.device = ToOutputStringView(mDeviceName);
- mDescription = ToString(info->description);
- mInfo.description = ToOutputStringView(mDescription);
+ // Deep copy the string pointed out by info.
+ mVendor = info->vendor;
+ mInfo.vendor = mVendor.c_str();
+ mArchitecture = info->architecture;
+ mInfo.architecture = mArchitecture.c_str();
+ mDeviceName = info->device;
+ mInfo.device = mDeviceName.c_str();
+ mDescription = info->description;
+ mInfo.description = mDescription.c_str();
mInfo.nextInChain = nullptr;
@@ -244,23 +242,30 @@
*info = mInfo;
+ // Get lengths, with null terminators.
+ size_t vendorCLen = strlen(mInfo.vendor) + 1;
+ size_t architectureCLen = strlen(mInfo.architecture) + 1;
+ size_t deviceCLen = strlen(mInfo.device) + 1;
+ size_t descriptionCLen = strlen(mInfo.description) + 1;
+
// Allocate space for all strings.
- size_t allocSize =
- mVendor.length() + mArchitecture.length() + mDeviceName.length() + mDescription.length();
- absl::Span<char> outBuffer{new char[allocSize], allocSize};
+ char* ptr = new char[vendorCLen + architectureCLen + deviceCLen + descriptionCLen];
- auto AddString = [&](const std::string& in, WGPUStringView* out) {
- DAWN_ASSERT(in.length() <= outBuffer.length());
- memcpy(outBuffer.data(), in.data(), in.length());
- *out = {outBuffer.data(), in.length()};
- outBuffer = outBuffer.subspan(in.length());
- };
+ info->vendor = ptr;
+ memcpy(ptr, mInfo.vendor, vendorCLen);
+ ptr += vendorCLen;
- AddString(mVendor, &info->vendor);
- AddString(mArchitecture, &info->architecture);
- AddString(mDeviceName, &info->device);
- AddString(mDescription, &info->description);
- DAWN_ASSERT(outBuffer.empty());
+ info->architecture = ptr;
+ memcpy(ptr, mInfo.architecture, architectureCLen);
+ ptr += architectureCLen;
+
+ info->device = ptr;
+ memcpy(ptr, mInfo.device, deviceCLen);
+ ptr += deviceCLen;
+
+ info->description = ptr;
+ memcpy(ptr, mInfo.description, descriptionCLen);
+ ptr += descriptionCLen;
return WGPUStatus_Success;
}
@@ -379,7 +384,7 @@
DAWN_WIRE_EXPORT void wgpuDawnWireClientAdapterInfoFreeMembers(WGPUAdapterInfo info) {
// This single delete is enough because everything is a single allocation.
- delete[] info.vendor.data;
+ delete[] info.vendor;
}
DAWN_WIRE_EXPORT void wgpuDawnWireClientAdapterPropertiesMemoryHeapsFreeMembers(
diff --git a/src/dawn/wire/client/ShaderModule.cpp b/src/dawn/wire/client/ShaderModule.cpp
index 614489b..66951d8 100644
--- a/src/dawn/wire/client/ShaderModule.cpp
+++ b/src/dawn/wire/client/ShaderModule.cpp
@@ -30,7 +30,6 @@
#include <memory>
#include <utility>
-#include "dawn/common/StringViewUtils.h"
#include "dawn/wire/client/Client.h"
#include "partition_alloc/pointers/raw_ptr.h"
@@ -63,15 +62,12 @@
}
mStatus = status;
-
- // Deep copy the WGPUCompilationInfo
mShader->mMessageStrings.reserve(info->messageCount);
mShader->mMessages.reserve(info->messageCount);
for (size_t i = 0; i < info->messageCount; i++) {
- DAWN_ASSERT(info->messages[i].length != WGPU_STRLEN);
- mShader->mMessageStrings.push_back(ToString(info->messages[i].message));
+ mShader->mMessageStrings.push_back(info->messages[i].message);
mShader->mMessages.push_back(info->messages[i]);
- mShader->mMessages[i].message = ToOutputStringView(mShader->mMessageStrings[i]);
+ mShader->mMessages[i].message = mShader->mMessageStrings[i].c_str();
}
mShader->mCompilationInfo = {nullptr, mShader->mMessages.size(), mShader->mMessages.data()};