0

Change raw arrays to std::array in gpu control lists

So they can safely map to base::span and we can remove
allow_unsafe_buffers from a few files.

Bug: 40285824
TEST=gpu_unittests,content_unittests

Change-Id: Ief017aa75e9413081e286a6f51a59080b90a6cb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5867926
Auto-Submit: Zhenyao Mo <zmo@chromium.org>
Commit-Queue: Vasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1356438}
This commit is contained in:
Zhenyao Mo
2024-09-17 14:00:44 +00:00
committed by Chromium LUCI CQ
parent b40ae46c86
commit 8b82c6788a
9 changed files with 36 additions and 39 deletions

@ -17,7 +17,7 @@
namespace gpu {
const GpuControlList::Entry kGpuDataManagerTestingEntries[] = {
const std::array<GpuControlList::Entry, 6> kGpuDataManagerTestingEntries = {{
{
1, // id
"GpuDataManagerImplPrivateTest.GpuSideBlocklisting.0",
@ -222,6 +222,5 @@ const GpuControlList::Entry kGpuDataManagerTestingEntries[] = {
0, // exceptions count
nullptr, // exceptions
},
};
const size_t kGpuDataManagerTestingEntryCount = 6;
}};
} // namespace gpu

@ -11,11 +11,12 @@
#ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_TESTING_AUTOGEN_H_
#define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_TESTING_AUTOGEN_H_
#include <array>
#include "gpu/config/gpu_control_list.h"
namespace gpu {
extern const size_t kGpuDataManagerTestingEntryCount;
extern const GpuControlList::Entry kGpuDataManagerTestingEntries[];
extern const std::array<GpuControlList::Entry, 6> kGpuDataManagerTestingEntries;
} // namespace gpu
#endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_TESTING_AUTOGEN_H_

@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "gpu/config/gpu_blocklist.h"
#include "gpu/config/gpu_feature_type.h"
@ -21,8 +16,7 @@ GpuBlocklist::~GpuBlocklist() = default;
// static
std::unique_ptr<GpuBlocklist> GpuBlocklist::Create() {
return Create(base::make_span(kSoftwareRenderingListEntries,
kSoftwareRenderingListEntryCount));
return Create(kSoftwareRenderingListEntries);
}
// static
@ -57,8 +51,8 @@ std::unique_ptr<GpuBlocklist> GpuBlocklist::Create(
// static
bool GpuBlocklist::AreEntryIndicesValid(
const std::vector<uint32_t>& entry_indices) {
return GpuControlList::AreEntryIndicesValid(entry_indices,
kSoftwareRenderingListEntryCount);
return GpuControlList::AreEntryIndicesValid(
entry_indices, kSoftwareRenderingListEntries.size());
}
} // namespace gpu

@ -134,9 +134,8 @@ TEST_F(GpuBlocklistTest, TestBlocklistIsValid) {
EXPECT_EQ(real_max_entry_id, max_entry_id);
}
void TestBlockList(const GpuControlList::Entry* entries, size_t count) {
for (size_t i = 0; i < count; ++i) {
const auto& entry = entries[i];
void TestBlockList(base::span<const GpuControlList::Entry> entries) {
for (const auto& entry : entries) {
if (const auto* gl_strings = entry.conditions.gl_strings) {
if (gl_strings->gl_vendor) {
EXPECT_TRUE(RE2(gl_strings->gl_vendor).ok())
@ -181,9 +180,8 @@ void TestBlockList(const GpuControlList::Entry* entries, size_t count) {
// It checks software_rendering_list.json
TEST_F(GpuBlocklistTest, VerifyGLStrings) {
TestBlockList(kSoftwareRenderingListEntries,
kSoftwareRenderingListEntryCount);
TestBlockList(kGpuDriverBugListEntries, kGpuDriverBugListEntryCount);
TestBlockList(kSoftwareRenderingListEntries);
TestBlockList(kGpuDriverBugListEntries);
}
} // namespace gpu

@ -44,7 +44,7 @@ class GpuControlListEntryTest : public testing::Test {
}
const Entry& GetEntry(size_t index) {
EXPECT_LT(index, kGpuControlListTestingEntryCount);
EXPECT_LT(index, kGpuControlListTestingEntries.size());
EXPECT_EQ(index + 1, kGpuControlListTestingEntries[index].id);
return kGpuControlListTestingEntries[index];
}

@ -17,7 +17,7 @@
namespace gpu {
const GpuControlList::Entry kGpuControlListTestingEntries[] = {
const std::array<GpuControlList::Entry, 81> kGpuControlListTestingEntries = {{
{
1, // id
"GpuControlListEntryTest.DetailedEntry",
@ -2773,6 +2773,5 @@ const GpuControlList::Entry kGpuControlListTestingEntries[] = {
0, // exceptions count
nullptr, // exceptions
},
};
const size_t kGpuControlListTestingEntryCount = 81;
}};
} // namespace gpu

@ -11,11 +11,13 @@
#ifndef GPU_CONFIG_GPU_CONTROL_LIST_TESTING_AUTOGEN_H_
#define GPU_CONFIG_GPU_CONTROL_LIST_TESTING_AUTOGEN_H_
#include <array>
#include "gpu/config/gpu_control_list.h"
namespace gpu {
extern const size_t kGpuControlListTestingEntryCount;
extern const GpuControlList::Entry kGpuControlListTestingEntries[];
extern const std::array<GpuControlList::Entry, 81>
kGpuControlListTestingEntries;
} // namespace gpu
#endif // GPU_CONFIG_GPU_CONTROL_LIST_TESTING_AUTOGEN_H_

@ -39,8 +39,7 @@ GpuDriverBugList::~GpuDriverBugList() = default;
// static
std::unique_ptr<GpuDriverBugList> GpuDriverBugList::Create() {
return Create(
base::make_span(kGpuDriverBugListEntries, kGpuDriverBugListEntryCount));
return Create(kGpuDriverBugListEntries);
}
// static
@ -114,7 +113,7 @@ void GpuDriverBugList::AppendAllWorkarounds(
bool GpuDriverBugList::AreEntryIndicesValid(
const std::vector<uint32_t>& entry_indices) {
return GpuControlList::AreEntryIndicesValid(entry_indices,
kGpuDriverBugListEntryCount);
kGpuDriverBugListEntries.size());
}
} // namespace gpu

@ -862,9 +862,8 @@ def process_json_file(json_filepath, list_tag,
True)
data_exception_file.write('namespace gpu {\n')
data_file.write('namespace gpu {\n\n')
data_file.write('const GpuControlList::Entry k%sEntries[] = {\n' % list_tag)
ids = []
entry_count = 0
ids = []
for index in range(len(json_data['entries'])):
entry = json_data['entries'][index]
entry_id = entry['id']
@ -879,11 +878,19 @@ def process_json_file(json_filepath, list_tag,
if os_filter not in (None, os_type):
continue
entry_count += 1
data_file.write(
'const std::array<GpuControlList::Entry, %d> k%sEntries = {{\n' %
(entry_count, list_tag))
for index in range(len(json_data['entries'])):
entry = json_data['entries'][index]
entry_id = entry['id']
if 'os' in entry:
os_type = entry['os']['type']
if os_filter not in (None, os_type):
continue
write_entry(entry, total_features, feature_tag, unique_symbol_id,
data_file, data_helper_file, data_exception_file)
data_file.write('};\n')
data_file.write('const size_t k%sEntryCount = %d;\n' %
(list_tag, entry_count))
data_file.write('}};\n')
data_file.write('} // namespace gpu\n')
data_file.close()
data_helper_file.write('} // namespace gpu\n')
@ -897,16 +904,14 @@ def process_json_file(json_filepath, list_tag,
data_header_file.write(_LICENSE)
data_header_file.write(_DO_NOT_EDIT_WARNING)
write_header_file_guard(data_header_file, output_header_filename, path, True)
data_header_file.write('#include <array>\n\n')
if export_tag == 'CONTENT_EXPORT ':
data_header_file.write('#include "content/common/content_export.h"\n')
data_header_file.write('#include "gpu/config/gpu_control_list.h"\n\n')
data_header_file.write('\n')
data_header_file.write('namespace gpu {\n')
data_header_file.write('%sextern const size_t k%sEntryCount;\n' %
(export_tag, list_tag))
data_header_file.write(
'%sextern const GpuControlList::Entry k%sEntries[];\n' %
(export_tag, list_tag))
'%sextern const std::array<GpuControlList::Entry, %d> k%sEntries;\n' %
(export_tag, entry_count, list_tag))
data_header_file.write('} // namespace gpu\n')
write_header_file_guard(data_header_file, output_header_filename, path, False)
data_header_file.close()