From 504ff3e1a61cbd79b88892469fea5fd6b7a4be5b Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sun, 1 Sep 2024 17:39:01 -0700 Subject: [PATCH] [core] Rename `map_buffer` to `resolve_buffer`, etc. In `Device::create_bind_group`, name the functions that convert resource ids to Arcs `resolve_foo`, not `map_foo`: - The types that hold Arcs are usually called `ResolvedBlah`. - The name `map_buffer` is misleading. --- wgpu-core/src/device/global.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index d9f983d1a..dad7d96db 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -795,14 +795,14 @@ impl Global { Err(..) => break 'error binding_model::CreateBindGroupError::InvalidLayout, }; - fn map_entry<'a>( + fn resolve_entry<'a>( e: &BindGroupEntry<'a>, buffer_storage: &Storage, sampler_storage: &Storage, texture_view_storage: &Storage, ) -> Result, binding_model::CreateBindGroupError> { - let map_buffer = |bb: &BufferBinding| { + let resolve_buffer = |bb: &BufferBinding| { buffer_storage .get_owned(bb.buffer_id) .map(|buffer| ResolvedBufferBinding { @@ -814,42 +814,45 @@ impl Global { binding_model::CreateBindGroupError::InvalidBufferId(bb.buffer_id) }) }; - let map_sampler = |id: &id::SamplerId| { + let resolve_sampler = |id: &id::SamplerId| { sampler_storage .get_owned(*id) .map_err(|_| binding_model::CreateBindGroupError::InvalidSamplerId(*id)) }; - let map_view = |id: &id::TextureViewId| { + let resolve_view = |id: &id::TextureViewId| { texture_view_storage .get_owned(*id) .map_err(|_| binding_model::CreateBindGroupError::InvalidTextureViewId(*id)) }; let resource = match e.resource { BindingResource::Buffer(ref buffer) => { - ResolvedBindingResource::Buffer(map_buffer(buffer)?) + ResolvedBindingResource::Buffer(resolve_buffer(buffer)?) } BindingResource::BufferArray(ref buffers) => { let buffers = buffers .iter() - .map(map_buffer) + .map(resolve_buffer) .collect::, _>>()?; ResolvedBindingResource::BufferArray(Cow::Owned(buffers)) } BindingResource::Sampler(ref sampler) => { - ResolvedBindingResource::Sampler(map_sampler(sampler)?) + ResolvedBindingResource::Sampler(resolve_sampler(sampler)?) } BindingResource::SamplerArray(ref samplers) => { let samplers = samplers .iter() - .map(map_sampler) + .map(resolve_sampler) .collect::, _>>()?; ResolvedBindingResource::SamplerArray(Cow::Owned(samplers)) } BindingResource::TextureView(ref view) => { - ResolvedBindingResource::TextureView(map_view(view)?) + ResolvedBindingResource::TextureView(resolve_view(view)?) } BindingResource::TextureViewArray(ref views) => { - let views = views.iter().map(map_view).collect::, _>>()?; + let views = views + .iter() + .map(resolve_view) + .collect::, _>>()?; ResolvedBindingResource::TextureViewArray(Cow::Owned(views)) } }; @@ -865,7 +868,7 @@ impl Global { let sampler_guard = hub.samplers.read(); desc.entries .iter() - .map(|e| map_entry(e, &buffer_guard, &sampler_guard, &texture_view_guard)) + .map(|e| resolve_entry(e, &buffer_guard, &sampler_guard, &texture_view_guard)) .collect::, _>>() }; let entries = match entries {