Use C++17 structured binding in more places.

Bug: dawn:824
Change-Id: Ie39d4f622bfb3dcc3a74b03d594efcea7139a9dc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/75069
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2022-01-06 09:17:57 +00:00 committed by Dawn LUCI CQ
parent 1c49d1b43b
commit 5984d8d1a8
28 changed files with 101 additions and 124 deletions

View File

@ -37,8 +37,8 @@ class ConcurrentCache : public NonMovable {
std::pair<T*, bool> Insert(T* object) { std::pair<T*, bool> Insert(T* object) {
std::lock_guard<std::mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
auto insertion = mCache.insert(object); auto [value, inserted] = mCache.insert(object);
return std::make_pair(*(insertion.first), insertion.second); return {*value, inserted};
} }
size_t Erase(T* object) { size_t Erase(T* object) {

View File

@ -46,8 +46,8 @@ namespace dawn_native {
allPendingTasks.swap(mPendingTasks); allPendingTasks.swap(mPendingTasks);
} }
for (auto& keyValue : allPendingTasks) { for (auto& [_, task] : allPendingTasks) {
keyValue.second->waitableEvent->Wait(); task->waitableEvent->Wait();
} }
} }

View File

@ -382,8 +382,8 @@ namespace dawn_native {
} }
IncrementBindingCounts(&mBindingCounts, binding); IncrementBindingCounts(&mBindingCounts, binding);
const auto& it = mBindingMap.emplace(BindingNumber(binding.binding), i); const auto& [_, inserted] = mBindingMap.emplace(BindingNumber(binding.binding), i);
ASSERT(it.second); ASSERT(inserted);
} }
ASSERT(CheckBufferBindingsFirst({mBindingInfo.data(), GetBindingCount()})); ASSERT(CheckBufferBindingsFirst({mBindingInfo.data(), GetBindingCount()}));
ASSERT(mBindingInfo.size() <= kMaxBindingsPerPipelineLayoutTyped); ASSERT(mBindingInfo.size() <= kMaxBindingsPerPipelineLayoutTyped);
@ -445,11 +445,10 @@ namespace dawn_native {
// std::map is sorted by key, so two BGLs constructed in different orders // std::map is sorted by key, so two BGLs constructed in different orders
// will still record the same. // will still record the same.
for (const auto& it : mBindingMap) { for (const auto [id, index] : mBindingMap) {
recorder.Record(it.first, it.second); recorder.Record(id, index);
const BindingInfo& info = mBindingInfo[it.second];
const BindingInfo& info = mBindingInfo[index];
recorder.Record(info.buffer.hasDynamicOffset, info.visibility, info.bindingType, recorder.Record(info.buffer.hasDynamicOffset, info.visibility, info.bindingType,
info.buffer.type, info.buffer.minBindingSize, info.sampler.type, info.buffer.type, info.buffer.minBindingSize, info.sampler.type,
info.texture.sampleType, info.texture.viewDimension, info.texture.sampleType, info.texture.viewDimension,

View File

@ -748,23 +748,23 @@ namespace dawn_native {
Ref<ComputePipelineBase> DeviceBase::AddOrGetCachedComputePipeline( Ref<ComputePipelineBase> DeviceBase::AddOrGetCachedComputePipeline(
Ref<ComputePipelineBase> computePipeline) { Ref<ComputePipelineBase> computePipeline) {
auto insertion = mCaches->computePipelines.insert(computePipeline.Get()); auto [cachedPipeline, inserted] = mCaches->computePipelines.insert(computePipeline.Get());
if (insertion.second) { if (inserted) {
computePipeline->SetIsCachedReference(); computePipeline->SetIsCachedReference();
return computePipeline; return computePipeline;
} else { } else {
return *(insertion.first); return *cachedPipeline;
} }
} }
Ref<RenderPipelineBase> DeviceBase::AddOrGetCachedRenderPipeline( Ref<RenderPipelineBase> DeviceBase::AddOrGetCachedRenderPipeline(
Ref<RenderPipelineBase> renderPipeline) { Ref<RenderPipelineBase> renderPipeline) {
auto insertion = mCaches->renderPipelines.insert(renderPipeline.Get()); auto [cachedPipeline, inserted] = mCaches->renderPipelines.insert(renderPipeline.Get());
if (insertion.second) { if (inserted) {
renderPipeline->SetIsCachedReference(); renderPipeline->SetIsCachedReference();
return renderPipeline; return renderPipeline;
} else { } else {
return *(insertion.first); return *cachedPipeline;
} }
} }

View File

@ -256,9 +256,9 @@ namespace dawn_native {
{"timestamp_query", "timestamp-query"}, {"timestamp_query", "timestamp-query"},
{"multiplanar_formats", "multiplanar-formats"}, {"multiplanar_formats", "multiplanar-formats"},
}}; }};
for (const auto& replacement : kReplacementsForDeprecatedNames) { for (const auto& [name, replacement] : kReplacementsForDeprecatedNames) {
if (strcmp(featureName, replacement.first) == 0) { if (strcmp(featureName, name) == 0) {
return FeatureNameToEnum(replacement.second); return FeatureNameToEnum(replacement);
} }
} }

View File

@ -139,22 +139,21 @@ namespace dawn_native {
} }
void IndirectDrawMetadata::AddBundle(RenderBundleBase* bundle) { void IndirectDrawMetadata::AddBundle(RenderBundleBase* bundle) {
auto result = mAddedBundles.insert(bundle); auto [_, inserted] = mAddedBundles.insert(bundle);
if (!result.second) { if (!inserted) {
return; return;
} }
for (const auto& entry : for (const auto& [config, validationInfo] :
bundle->GetIndirectDrawMetadata().mIndexedIndirectBufferValidationInfo) { bundle->GetIndirectDrawMetadata().mIndexedIndirectBufferValidationInfo) {
const IndexedIndirectConfig& config = entry.first;
auto it = mIndexedIndirectBufferValidationInfo.lower_bound(config); auto it = mIndexedIndirectBufferValidationInfo.lower_bound(config);
if (it != mIndexedIndirectBufferValidationInfo.end() && it->first == config) { if (it != mIndexedIndirectBufferValidationInfo.end() && it->first == config) {
// We already have batches for the same config. Merge the new ones in. // We already have batches for the same config. Merge the new ones in.
for (const IndexedIndirectValidationBatch& batch : entry.second.GetBatches()) { for (const IndexedIndirectValidationBatch& batch : validationInfo.GetBatches()) {
it->second.AddBatch(mMaxDrawCallsPerBatch, mMaxBatchOffsetRange, batch); it->second.AddBatch(mMaxDrawCallsPerBatch, mMaxBatchOffsetRange, batch);
} }
} else { } else {
mIndexedIndirectBufferValidationInfo.emplace_hint(it, config, entry.second); mIndexedIndirectBufferValidationInfo.emplace_hint(it, config, validationInfo);
} }
} }
} }

View File

@ -230,11 +230,10 @@ namespace dawn_native {
const uint32_t minStorageBufferOffsetAlignment = const uint32_t minStorageBufferOffsetAlignment =
device->GetLimits().v1.minStorageBufferOffsetAlignment; device->GetLimits().v1.minStorageBufferOffsetAlignment;
for (auto& entry : bufferInfoMap) { for (auto& [config, validationInfo] : bufferInfoMap) {
const IndirectDrawMetadata::IndexedIndirectConfig& config = entry.first;
BufferBase* clientIndirectBuffer = config.first; BufferBase* clientIndirectBuffer = config.first;
for (const IndirectDrawMetadata::IndexedIndirectValidationBatch& batch : for (const IndirectDrawMetadata::IndexedIndirectValidationBatch& batch :
entry.second.GetBatches()) { validationInfo.GetBatches()) {
const uint64_t minOffsetFromAlignedBoundary = const uint64_t minOffsetFromAlignedBoundary =
batch.minOffset % minStorageBufferOffsetAlignment; batch.minOffset % minStorageBufferOffsetAlignment;
const uint64_t minOffsetAlignedDown = const uint64_t minOffsetAlignedDown =

View File

@ -154,14 +154,14 @@ namespace dawn_native {
result.textures.reserve(mTextureUsages.size()); result.textures.reserve(mTextureUsages.size());
result.textureUsages.reserve(mTextureUsages.size()); result.textureUsages.reserve(mTextureUsages.size());
for (auto& it : mBufferUsages) { for (auto& [buffer, usage] : mBufferUsages) {
result.buffers.push_back(it.first); result.buffers.push_back(buffer);
result.bufferUsages.push_back(it.second); result.bufferUsages.push_back(usage);
} }
for (auto& it : mTextureUsages) { for (auto& [texture, usage] : mTextureUsages) {
result.textures.push_back(it.first); result.textures.push_back(texture);
result.textureUsages.push_back(std::move(it.second)); result.textureUsages.push_back(std::move(usage));
} }
for (auto& it : mExternalTextureUsages) { for (auto& it : mExternalTextureUsages) {

View File

@ -235,8 +235,8 @@ namespace dawn_native {
-> ResultOrError<Ref<BindGroupLayoutBase>> { -> ResultOrError<Ref<BindGroupLayoutBase>> {
std::vector<BindGroupLayoutEntry> entryVec; std::vector<BindGroupLayoutEntry> entryVec;
entryVec.reserve(entries.size()); entryVec.reserve(entries.size());
for (auto& it : entries) { for (auto& [_, entry] : entries) {
entryVec.push_back(it.second); entryVec.push_back(entry);
} }
BindGroupLayoutDescriptor desc = {}; BindGroupLayoutDescriptor desc = {};
@ -268,10 +268,7 @@ namespace dawn_native {
const EntryPointMetadata& metadata = stage.module->GetEntryPoint(stage.entryPoint); const EntryPointMetadata& metadata = stage.module->GetEntryPoint(stage.entryPoint);
for (BindGroupIndex group(0); group < metadata.bindings.size(); ++group) { for (BindGroupIndex group(0); group < metadata.bindings.size(); ++group) {
for (const auto& bindingIt : metadata.bindings[group]) { for (const auto& [bindingNumber, shaderBinding] : metadata.bindings[group]) {
BindingNumber bindingNumber = bindingIt.first;
const ShaderBindingInfo& shaderBinding = bindingIt.second;
// Create the BindGroupLayoutEntry // Create the BindGroupLayoutEntry
BindGroupLayoutEntry entry = BindGroupLayoutEntry entry =
ConvertMetadataToEntry(shaderBinding, &externalTextureBindingLayout); ConvertMetadataToEntry(shaderBinding, &externalTextureBindingLayout);
@ -280,9 +277,10 @@ namespace dawn_native {
// Add it to our map of all entries, if there is an existing entry, then we // Add it to our map of all entries, if there is an existing entry, then we
// need to merge, if we can. // need to merge, if we can.
const auto& insertion = entryData[group].insert({bindingNumber, entry}); const auto& [existingEntry, inserted] =
if (!insertion.second) { entryData[group].insert({bindingNumber, entry});
DAWN_TRY(MergeEntries(&insertion.first->second, entry)); if (!inserted) {
DAWN_TRY(MergeEntries(&existingEntry->second, entry));
} }
} }
} }

View File

@ -73,9 +73,9 @@ namespace dawn_native {
for (uint32_t i = 0; i < descriptor->pipelineStatisticsCount; i++) { for (uint32_t i = 0; i < descriptor->pipelineStatisticsCount; i++) {
DAWN_TRY(ValidatePipelineStatisticName(descriptor->pipelineStatistics[i])); DAWN_TRY(ValidatePipelineStatisticName(descriptor->pipelineStatistics[i]));
std::pair<std::set<wgpu::PipelineStatisticName>::iterator, bool> res = auto [_, inserted] =
pipelineStatisticsSet.insert((descriptor->pipelineStatistics[i])); pipelineStatisticsSet.insert((descriptor->pipelineStatistics[i]));
DAWN_INVALID_IF(!res.second, "Statistic %s is specified more than once.", DAWN_INVALID_IF(!inserted, "Statistic %s is specified more than once.",
descriptor->pipelineStatistics[i]); descriptor->pipelineStatistics[i]);
} }
} break; } break;

View File

@ -596,12 +596,12 @@ namespace dawn_native {
const BindGroupLayoutBase* layout) { const BindGroupLayoutBase* layout) {
// Iterate over all bindings used by this group in the shader, and find the // Iterate over all bindings used by this group in the shader, and find the
// corresponding binding in the BindGroupLayout, if it exists. // corresponding binding in the BindGroupLayout, if it exists.
for (const auto& it : entryPoint.bindings[group]) { for (const auto& [bindingId, bindingInfo] : entryPoint.bindings[group]) {
DAWN_TRY_CONTEXT(ValidateCompatibilityOfSingleBindingWithLayout( DAWN_TRY_CONTEXT(ValidateCompatibilityOfSingleBindingWithLayout(
device, layout, entryPoint.stage, it.first, it.second), device, layout, entryPoint.stage, bindingId, bindingInfo),
"validating that the entry-point's declaration for [[group(%u), " "validating that the entry-point's declaration for [[group(%u), "
"binding(%u)]] matches %s", "binding(%u)]] matches %s",
static_cast<uint32_t>(group), static_cast<uint32_t>(it.first), static_cast<uint32_t>(group), static_cast<uint32_t>(bindingId),
layout); layout);
} }
@ -665,15 +665,16 @@ namespace dawn_native {
metadata->overridableConstants[identifier] = constant; metadata->overridableConstants[identifier] = constant;
if (!c.is_initialized) { if (!c.is_initialized) {
auto it = metadata->uninitializedOverridableConstants.emplace( auto [_, inserted] =
std::move(identifier)); metadata->uninitializedOverridableConstants.emplace(
std::move(identifier));
// The insertion should have taken place // The insertion should have taken place
ASSERT(it.second); ASSERT(inserted);
} else { } else {
auto it = metadata->initializedOverridableConstants.emplace( auto [_, inserted] = metadata->initializedOverridableConstants.emplace(
std::move(identifier)); std::move(identifier));
// The insertion should have taken place // The insertion should have taken place
ASSERT(it.second); ASSERT(inserted);
} }
} }
} }
@ -866,14 +867,14 @@ namespace dawn_native {
BindingNumber bindingNumber(resource.binding); BindingNumber bindingNumber(resource.binding);
BindGroupIndex bindGroupIndex(resource.bind_group); BindGroupIndex bindGroupIndex(resource.bind_group);
const auto& it = metadata->bindings[bindGroupIndex].emplace( const auto& [binding, inserted] = metadata->bindings[bindGroupIndex].emplace(
bindingNumber, ShaderBindingInfo{}); bindingNumber, ShaderBindingInfo{});
DAWN_INVALID_IF( DAWN_INVALID_IF(
!it.second, !inserted,
"Entry-point has a duplicate binding for (group:%u, binding:%u).", "Entry-point has a duplicate binding for (group:%u, binding:%u).",
resource.binding, resource.bind_group); resource.binding, resource.bind_group);
ShaderBindingInfo* info = &it.first->second; ShaderBindingInfo* info = &binding->second;
info->bindingType = TintResourceTypeToBindingInfoType(resource.resource_type); info->bindingType = TintResourceTypeToBindingInfoType(resource.resource_type);
switch (info->bindingType) { switch (info->bindingType) {

View File

@ -90,11 +90,11 @@ namespace dawn_native { namespace d3d12 {
std::map<tint::transform::BindingPoint, T, CompareBindingPoint> sorted(map.begin(), std::map<tint::transform::BindingPoint, T, CompareBindingPoint> sorted(map.begin(),
map.end()); map.end());
for (auto& entry : sorted) { for (auto& [bindingPoint, value] : sorted) {
output << " "; output << " ";
Serialize(output, entry.first); Serialize(output, bindingPoint);
output << "="; output << "=";
Serialize(output, entry.second); Serialize(output, value);
} }
output << ")"; output << ")";
} }
@ -144,10 +144,7 @@ namespace dawn_native { namespace d3d12 {
std::unordered_set<std::string> overriddenConstants; std::unordered_set<std::string> overriddenConstants;
// Set pipeline overridden values // Set pipeline overridden values
for (const auto& pipelineConstant : *pipelineConstantEntries) { for (const auto& [name, value] : *pipelineConstantEntries) {
const std::string& name = pipelineConstant.first;
double value = pipelineConstant.second;
overriddenConstants.insert(name); overriddenConstants.insert(name);
// This is already validated so `name` must exist // This is already validated so `name` must exist
@ -246,9 +243,7 @@ namespace dawn_native { namespace d3d12 {
// the Tint AST to make the "bindings" decoration match the offset chosen by // the Tint AST to make the "bindings" decoration match the offset chosen by
// d3d12::BindGroupLayout so that Tint produces HLSL with the correct registers // d3d12::BindGroupLayout so that Tint produces HLSL with the correct registers
// assigned to each interface variable. // assigned to each interface variable.
for (const auto& it : groupBindingInfo) { for (const auto& [binding, bindingInfo] : groupBindingInfo) {
BindingNumber binding = it.first;
auto const& bindingInfo = it.second;
BindingIndex bindingIndex = bgl->GetBindingIndex(binding); BindingIndex bindingIndex = bgl->GetBindingIndex(binding);
BindingPoint srcBindingPoint{static_cast<uint32_t>(group), BindingPoint srcBindingPoint{static_cast<uint32_t>(group),
static_cast<uint32_t>(binding)}; static_cast<uint32_t>(binding)};
@ -379,8 +374,8 @@ namespace dawn_native { namespace d3d12 {
stream << " hasShaderFloat16Feature=" << hasShaderFloat16Feature; stream << " hasShaderFloat16Feature=" << hasShaderFloat16Feature;
stream << " defines={"; stream << " defines={";
for (const auto& it : defineStrings) { for (const auto& [name, value] : defineStrings) {
stream << " <" << it.first << "," << it.second << ">"; stream << " <" << name << "," << value << ">";
} }
stream << " }"; stream << " }";
@ -463,15 +458,14 @@ namespace dawn_native { namespace d3d12 {
// Build defines for overridable constants // Build defines for overridable constants
std::vector<std::pair<std::wstring, std::wstring>> defineStrings; std::vector<std::pair<std::wstring, std::wstring>> defineStrings;
defineStrings.reserve(request.defineStrings.size()); defineStrings.reserve(request.defineStrings.size());
for (const auto& it : request.defineStrings) { for (const auto& [name, value] : request.defineStrings) {
defineStrings.emplace_back(UTF8ToWStr(it.first.c_str()), defineStrings.emplace_back(UTF8ToWStr(name.c_str()), UTF8ToWStr(value.c_str()));
UTF8ToWStr(it.second.c_str()));
} }
std::vector<DxcDefine> dxcDefines; std::vector<DxcDefine> dxcDefines;
dxcDefines.reserve(defineStrings.size()); dxcDefines.reserve(defineStrings.size());
for (const auto& d : defineStrings) { for (const auto& [name, value] : defineStrings) {
dxcDefines.push_back({d.first.c_str(), d.second.c_str()}); dxcDefines.push_back({name.c_str(), value.c_str()});
} }
ComPtr<IDxcOperationResult> result; ComPtr<IDxcOperationResult> result;
@ -584,8 +578,8 @@ namespace dawn_native { namespace d3d12 {
std::vector<D3D_SHADER_MACRO> fxcDefines; std::vector<D3D_SHADER_MACRO> fxcDefines;
if (request.defineStrings.size() > 0) { if (request.defineStrings.size() > 0) {
fxcDefines.reserve(request.defineStrings.size() + 1); fxcDefines.reserve(request.defineStrings.size() + 1);
for (const auto& d : request.defineStrings) { for (const auto& [name, value] : request.defineStrings) {
fxcDefines.push_back({d.first.c_str(), d.second.c_str()}); fxcDefines.push_back({name.c_str(), value.c_str()});
} }
// d3dCompile D3D_SHADER_MACRO* pDefines is a nullptr terminated array // d3dCompile D3D_SHADER_MACRO* pDefines is a nullptr terminated array
fxcDefines.push_back({nullptr, nullptr}); fxcDefines.push_back({nullptr, nullptr});

View File

@ -68,10 +68,7 @@ namespace dawn_native { namespace metal {
for (BindGroupIndex group : IterateBitSet(layout->GetBindGroupLayoutsMask())) { for (BindGroupIndex group : IterateBitSet(layout->GetBindGroupLayoutsMask())) {
const BindGroupLayoutBase::BindingMap& bindingMap = const BindGroupLayoutBase::BindingMap& bindingMap =
layout->GetBindGroupLayout(group)->GetBindingMap(); layout->GetBindGroupLayout(group)->GetBindingMap();
for (const auto& it : bindingMap) { for (const auto [bindingNumber, bindingIndex] : bindingMap) {
BindingNumber bindingNumber = it.first;
BindingIndex bindingIndex = it.second;
const BindingInfo& bindingInfo = const BindingInfo& bindingInfo =
layout->GetBindGroupLayout(group)->GetBindingInfo(bindingIndex); layout->GetBindGroupLayout(group)->GetBindingInfo(bindingIndex);

View File

@ -244,10 +244,7 @@ namespace dawn_native { namespace metal {
} }
}; };
for (const auto& pipelineConstant : programmableStage.constants) { for (const auto& [name, value] : programmableStage.constants) {
const std::string& name = pipelineConstant.first;
double value = pipelineConstant.second;
overriddenConstants.insert(name); overriddenConstants.insert(name);
// This is already validated so `name` must exist // This is already validated so `name` must exist

View File

@ -244,8 +244,7 @@ namespace dawn_native { namespace opengl {
ResultOrError<ExecutionSerial> Device::CheckAndUpdateCompletedSerials() { ResultOrError<ExecutionSerial> Device::CheckAndUpdateCompletedSerials() {
ExecutionSerial fenceSerial{0}; ExecutionSerial fenceSerial{0};
while (!mFencesInFlight.empty()) { while (!mFencesInFlight.empty()) {
GLsync sync = mFencesInFlight.front().first; auto [sync, tentativeSerial] = mFencesInFlight.front();
ExecutionSerial tentativeSerial = mFencesInFlight.front().second;
// Fence are added in order, so we can stop searching as soon // Fence are added in order, so we can stop searching as soon
// as we see one that's not ready. // as we see one that's not ready.

View File

@ -96,11 +96,11 @@ namespace dawn_native { namespace opengl {
DAWN_INVALID_IF(bindGroupIndex >= kMaxBindGroupsTyped, DAWN_INVALID_IF(bindGroupIndex >= kMaxBindGroupsTyped,
"Bind group index over limits in the SPIRV"); "Bind group index over limits in the SPIRV");
const auto& it = const auto& [entry, inserted] =
(*bindings)[bindGroupIndex].emplace(bindingNumber, ShaderBindingInfo{}); (*bindings)[bindGroupIndex].emplace(bindingNumber, ShaderBindingInfo{});
DAWN_INVALID_IF(!it.second, "Shader has duplicate bindings"); DAWN_INVALID_IF(!inserted, "Shader has duplicate bindings");
ShaderBindingInfo* info = &it.first->second; ShaderBindingInfo* info = &entry->second;
info->id = resource.id; info->id = resource.id;
info->base_type_id = resource.base_type_id; info->base_type_id = resource.base_type_id;
info->bindingType = bindingType; info->bindingType = bindingType;

View File

@ -95,8 +95,7 @@ namespace dawn_native { namespace vulkan {
ityp::vector<BindingIndex, VkDescriptorSetLayoutBinding> bindings; ityp::vector<BindingIndex, VkDescriptorSetLayoutBinding> bindings;
bindings.reserve(GetBindingCount()); bindings.reserve(GetBindingCount());
for (const auto& it : GetBindingMap()) { for (const auto& [_, bindingIndex] : GetBindingMap()) {
BindingIndex bindingIndex = it.second;
const BindingInfo& bindingInfo = GetBindingInfo(bindingIndex); const BindingInfo& bindingInfo = GetBindingInfo(bindingIndex);
VkDescriptorSetLayoutBinding vkBinding; VkDescriptorSetLayoutBinding vkBinding;

View File

@ -50,8 +50,7 @@ namespace dawn_native { namespace vulkan {
writeImageInfo(bindingCount); writeImageInfo(bindingCount);
uint32_t numWrites = 0; uint32_t numWrites = 0;
for (const auto& it : GetLayout()->GetBindingMap()) { for (const auto [_, bindingIndex] : GetLayout()->GetBindingMap()) {
BindingIndex bindingIndex = it.second;
const BindingInfo& bindingInfo = GetLayout()->GetBindingInfo(bindingIndex); const BindingInfo& bindingInfo = GetLayout()->GetBindingInfo(bindingIndex);
auto& write = writes[numWrites]; auto& write = writes[numWrites];

View File

@ -40,10 +40,10 @@ namespace dawn_native { namespace vulkan {
// Compute the total number of descriptors for this layout. // Compute the total number of descriptors for this layout.
uint32_t totalDescriptorCount = 0; uint32_t totalDescriptorCount = 0;
mPoolSizes.reserve(descriptorCountPerType.size()); mPoolSizes.reserve(descriptorCountPerType.size());
for (const auto& it : descriptorCountPerType) { for (const auto& [type, count] : descriptorCountPerType) {
ASSERT(it.second > 0); ASSERT(count > 0);
totalDescriptorCount += it.second; totalDescriptorCount += count;
mPoolSizes.push_back(VkDescriptorPoolSize{it.first, it.second}); mPoolSizes.push_back(VkDescriptorPoolSize{type, count});
} }
if (totalDescriptorCount == 0) { if (totalDescriptorCount == 0) {

View File

@ -86,8 +86,8 @@ namespace dawn_native { namespace vulkan {
RenderPassCache::~RenderPassCache() { RenderPassCache::~RenderPassCache() {
std::lock_guard<std::mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
for (auto it : mCache) { for (auto [_, renderPass] : mCache) {
mDevice->fn.DestroyRenderPass(mDevice->GetVkDevice(), it.second, nullptr); mDevice->fn.DestroyRenderPass(mDevice->GetVkDevice(), renderPass, nullptr);
} }
mCache.clear(); mCache.clear();

View File

@ -36,8 +36,8 @@ namespace dawn_native { namespace vulkan {
ShaderModule::ConcurrentTransformedShaderModuleCache:: ShaderModule::ConcurrentTransformedShaderModuleCache::
~ConcurrentTransformedShaderModuleCache() { ~ConcurrentTransformedShaderModuleCache() {
std::lock_guard<std::mutex> lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
for (const auto& iter : mTransformedShaderModuleCache) { for (const auto& [_, module] : mTransformedShaderModuleCache) {
mDevice->GetFencedDeleter()->DeleteWhenUnused(iter.second); mDevice->GetFencedDeleter()->DeleteWhenUnused(module);
} }
} }

View File

@ -359,8 +359,8 @@ namespace wgpu { namespace binding {
} }
auto* els = Allocate<std::remove_const_t<OUT>>(in.size()); auto* els = Allocate<std::remove_const_t<OUT>>(in.size());
size_t i = 0; size_t i = 0;
for (auto& it : in) { for (auto& [key, value] : in) {
if (!Convert(els[i++], it.first, it.second)) { if (!Convert(els[i++], key, value)) {
return false; return false;
} }
} }

View File

@ -71,14 +71,14 @@ namespace wgpu { namespace utils {
std::ostream& Write(std::ostream& out, const std::unordered_map<K, V>& value) { std::ostream& Write(std::ostream& out, const std::unordered_map<K, V>& value) {
out << "{"; out << "{";
bool first = true; bool first = true;
for (auto it : value) { for (auto& [key, value] : value) {
if (!first) { if (!first) {
out << ", "; out << ", ";
} }
first = false; first = false;
Write(out, it.first); Write(out, key);
out << ": "; out << ": ";
Write(out, it.second); Write(out, value);
} }
return out << "}"; return out << "}";
} }

View File

@ -59,16 +59,16 @@ namespace dawn_wire { namespace client {
// Move mRequests to a local variable so that further reentrant modifications of // Move mRequests to a local variable so that further reentrant modifications of
// mRequests don't invalidate the iterators. // mRequests don't invalidate the iterators.
auto allRequests = std::move(mRequests); auto allRequests = std::move(mRequests);
for (auto& it : allRequests) { for (auto& [_, request] : allRequests) {
closeFunc(&it.second); closeFunc(&request);
} }
} }
} }
template <typename F> template <typename F>
void ForAll(F&& f) { void ForAll(F&& f) {
for (auto& it : mRequests) { for (auto& [_, request] : mRequests) {
f(&it.second); f(&request);
} }
} }

View File

@ -191,8 +191,8 @@ namespace dawn_wire { namespace server {
} }
bool TrackDeviceChild(DeviceInfo* info, ObjectType type, ObjectId id) { bool TrackDeviceChild(DeviceInfo* info, ObjectType type, ObjectId id) {
auto it = info->childObjectTypesAndIds.insert(PackObjectTypeAndId(type, id)); auto [_, inserted] = info->childObjectTypesAndIds.insert(PackObjectTypeAndId(type, id));
if (!it.second) { if (!inserted) {
// An object of this type and id already exists. // An object of this type and id already exists.
return false; return false;
} }

View File

@ -53,9 +53,9 @@ namespace testing {
// remove from this set even if a callback should only be called once so that // remove from this set even if a callback should only be called once so that
// repeated calls to the callback still forward the userdata correctly. // repeated calls to the callback still forward the userdata correctly.
// Userdata will be destroyed when the mock is destroyed. // Userdata will be destroyed when the mock is destroyed.
auto it = mUserdatas.insert(std::move(mockAndUserdata)); auto [result, inserted] = mUserdatas.insert(std::move(mockAndUserdata));
ASSERT(it.second); ASSERT(inserted);
return it.first->get(); return result->get();
} }
private: private:

View File

@ -157,8 +157,8 @@ class ColorStateTest : public DawnTest {
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
for (const auto& test : tests) { for (const auto& [triangleColor, expectedColor] : tests) {
DoSingleSourceTest(base, {test.first}, test.second); DoSingleSourceTest(base, {triangleColor}, expectedColor);
} }
} }
@ -190,8 +190,8 @@ class ColorStateTest : public DawnTest {
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
for (const auto& test : tests) { for (const auto& [triangles, expectedColor] : tests) {
DoSingleSourceTest(base, test.first, test.second); DoSingleSourceTest(base, triangles, expectedColor);
} }
} }

View File

@ -811,9 +811,7 @@ TEST_P(DepthStencilStateTest, StencilReferenceInitialized) {
{stencilEqualKeepState, RGBA8::kGreen, 0.f, 0x0, wgpu::FrontFace::CCW, false}}; {stencilEqualKeepState, RGBA8::kGreen, 0.f, 0x0, wgpu::FrontFace::CCW, false}};
// Since the stencil reference is not inherited, second draw won't pass the stencil test // Since the stencil reference is not inherited, second draw won't pass the stencil test
std::pair<RGBA8, RGBA8> expectation = {RGBA8::kZero, RGBA8::kZero}; DoTest(testParams, RGBA8::kZero, RGBA8::kZero, true);
DoTest(testParams, expectation.first, expectation.second, true);
} }
// Test that stencil reference is initialized as zero for new render pass // Test that stencil reference is initialized as zero for new render pass
@ -826,9 +824,7 @@ TEST_P(DepthStencilStateTest, StencilReferenceInitialized) {
{stencilEqualKeepState, RGBA8::kBlue, 0.f, 0x0, wgpu::FrontFace::CCW, true}}; {stencilEqualKeepState, RGBA8::kBlue, 0.f, 0x0, wgpu::FrontFace::CCW, true}};
// The third draw should pass the stencil test since the second pass set it to default zero // The third draw should pass the stencil test since the second pass set it to default zero
std::pair<RGBA8, RGBA8> expectation = {RGBA8::kBlue, RGBA8::kBlue}; DoTest(testParams, RGBA8::kBlue, RGBA8::kBlue, true);
DoTest(testParams, expectation.first, expectation.second, true);
} }
} }