Skip to content

Commit 96871af

Browse files
committed
[mtl] ban non-fast hash maps entirely
1 parent d6b8b93 commit 96871af

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/backend/dx12/src/command.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1641,13 +1641,13 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
16411641
{
16421642
// Only cache the vertex buffer views as we don't know the stride (PSO).
16431643
assert!(first_binding as usize <= MAX_VERTEX_BUFFERS);
1644-
for (&(buffer, offset), view) in buffers
1644+
for ((buffer, offset), view) in buffers
16451645
.into_iter()
16461646
.zip(self.vertex_buffer_views[first_binding as _..].iter_mut())
16471647
{
16481648
let b = buffer.borrow();
16491649
let base = unsafe { (*b.resource).GetGPUVirtualAddress() };
1650-
view.BufferLocation = base + offset as u64;
1650+
view.BufferLocation = base + offset;
16511651
view.SizeInBytes = b.size_in_bytes - offset as u32;
16521652
}
16531653
}

src/backend/metal/src/device.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use {conversions as conv, command, native as n};
66
use native;
77

88
use std::borrow::Borrow;
9-
use std::collections::hash_map::{Entry, HashMap};
9+
use std::collections::hash_map::Entry;
1010
use std::ops::Range;
1111
use std::path::Path;
1212
use std::sync::{Arc, Condvar, Mutex, RwLock};
1313
use std::{cmp, mem, slice, time};
1414

1515
use hal::{self, error, image, pass, format, mapping, memory, buffer, pso, query, window};
16-
use hal::backend::FastHashMap;
1716
use hal::device::{BindError, OutOfMemory, FramebufferError, ShaderError};
1817
use hal::memory::Properties;
1918
use hal::pool::CommandPoolCreateFlags;
@@ -496,7 +495,7 @@ impl Device {
496495
{
497496
Ok(library) => Ok(n::ShaderModule::Compiled {
498497
library,
499-
entry_point_map: FastHashMap::default(),
498+
entry_point_map: n::EntryPointMap::default(),
500499
}),
501500
Err(err) => Err(ShaderError::CompilationFailed(err.into())),
502501
}
@@ -506,8 +505,8 @@ impl Device {
506505
&self,
507506
raw_data: &[u8],
508507
primitive_class: MTLPrimitiveTopologyClass,
509-
overrides: &HashMap<msl::ResourceBindingLocation, msl::ResourceBinding>,
510-
) -> Result<(metal::Library, FastHashMap<String, spirv::EntryPoint>), ShaderError> {
508+
overrides: &n::ResourceOverrideMap,
509+
) -> Result<(metal::Library, n::EntryPointMap), ShaderError> {
511510
// spec requires "codeSize must be a multiple of 4"
512511
assert_eq!(raw_data.len() & 3, 0);
513512

@@ -528,7 +527,10 @@ impl Device {
528527
compiler_options.resolve_specialized_array_lengths = true;
529528
compiler_options.vertex.invert_y = true;
530529
// fill the overrides
531-
compiler_options.resource_binding_overrides = overrides.clone();
530+
compiler_options.resource_binding_overrides = overrides
531+
.iter()
532+
.map(|(key, value)| (key.clone(), value.clone()))
533+
.collect();
532534

533535
ast.set_compiler_options(&compiler_options)
534536
.map_err(|err| {
@@ -557,7 +559,7 @@ impl Device {
557559
ShaderError::CompilationFailed(msg)
558560
})?;
559561

560-
let mut entry_point_map = FastHashMap::default();
562+
let mut entry_point_map = n::EntryPointMap::default();
561563
for entry_point in entry_points {
562564
info!("Entry point {:?}", entry_point);
563565
let cleansed = ast.get_cleansed_entry_point_name(&entry_point.name, entry_point.execution_model)
@@ -727,7 +729,7 @@ impl hal::Device<Backend> for Device {
727729
(ShaderStageFlags::FRAGMENT, spirv::ExecutionModel::Fragment, Counters { buffers:0, textures:0, samplers:0 }),
728730
(ShaderStageFlags::COMPUTE, spirv::ExecutionModel::GlCompute, Counters { buffers:0, textures:0, samplers:0 }),
729731
];
730-
let mut res_overrides = HashMap::new();
732+
let mut res_overrides = n::ResourceOverrideMap::default();
731733

732734
for (set_index, set_layout) in set_layouts.into_iter().enumerate() {
733735
match set_layout.borrow() {
@@ -1185,7 +1187,7 @@ impl hal::Device<Backend> for Device {
11851187
let (library, entry_point_map) = self.compile_shader_library(
11861188
raw_data,
11871189
MTLPrimitiveTopologyClass::Unspecified,
1188-
&HashMap::new(),
1190+
&n::ResourceOverrideMap::default(),
11891191
)?;
11901192
n::ShaderModule::Compiled {
11911193
library,

src/backend/metal/src/native.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use {Backend, BufferPtr, SamplerPtr, TexturePtr};
22
use internal::Channel;
33
use window::SwapchainImage;
44

5-
use std::collections::HashMap;
65
use std::ops::Range;
76
use std::os::raw::{c_void, c_long};
87
use std::sync::{Arc, Condvar, Mutex, RwLock};
@@ -20,13 +19,15 @@ use foreign_types::ForeignType;
2019
use range_alloc::RangeAllocator;
2120

2221

22+
pub type EntryPointMap = FastHashMap<String, spirv::EntryPoint>;
23+
2324
/// Shader module can be compiled in advance if it's resource bindings do not
2425
/// depend on pipeline layout, in which case the value would become `Compiled`.
2526
#[derive(Debug)]
2627
pub enum ShaderModule {
2728
Compiled {
2829
library: metal::Library,
29-
entry_point_map: FastHashMap<String, spirv::EntryPoint>,
30+
entry_point_map: EntryPointMap,
3031
},
3132
Raw(Vec<u8>),
3233
}
@@ -65,11 +66,13 @@ pub struct Framebuffer {
6566
unsafe impl Send for Framebuffer {}
6667
unsafe impl Sync for Framebuffer {}
6768

69+
pub type ResourceOverrideMap = FastHashMap<msl::ResourceBindingLocation, msl::ResourceBinding>;
70+
6871
#[derive(Debug)]
6972
pub struct PipelineLayout {
7073
// First vertex buffer index to be used by attributes
7174
pub(crate) attribute_buffer_index: u32,
72-
pub(crate) res_overrides: HashMap<msl::ResourceBindingLocation, msl::ResourceBinding>,
75+
pub(crate) res_overrides: ResourceOverrideMap,
7376
}
7477

7578
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)