Skip to content

Commit

Permalink
[mtl] ban non-fast hash maps entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jun 28, 2018
1 parent d6b8b93 commit 96871af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/backend/dx12/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,13 +1641,13 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
{
// Only cache the vertex buffer views as we don't know the stride (PSO).
assert!(first_binding as usize <= MAX_VERTEX_BUFFERS);
for (&(buffer, offset), view) in buffers
for ((buffer, offset), view) in buffers
.into_iter()
.zip(self.vertex_buffer_views[first_binding as _..].iter_mut())
{
let b = buffer.borrow();
let base = unsafe { (*b.resource).GetGPUVirtualAddress() };
view.BufferLocation = base + offset as u64;
view.BufferLocation = base + offset;
view.SizeInBytes = b.size_in_bytes - offset as u32;
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/backend/metal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use {conversions as conv, command, native as n};
use native;

use std::borrow::Borrow;
use std::collections::hash_map::{Entry, HashMap};
use std::collections::hash_map::Entry;
use std::ops::Range;
use std::path::Path;
use std::sync::{Arc, Condvar, Mutex, RwLock};
use std::{cmp, mem, slice, time};

use hal::{self, error, image, pass, format, mapping, memory, buffer, pso, query, window};
use hal::backend::FastHashMap;
use hal::device::{BindError, OutOfMemory, FramebufferError, ShaderError};
use hal::memory::Properties;
use hal::pool::CommandPoolCreateFlags;
Expand Down Expand Up @@ -496,7 +495,7 @@ impl Device {
{
Ok(library) => Ok(n::ShaderModule::Compiled {
library,
entry_point_map: FastHashMap::default(),
entry_point_map: n::EntryPointMap::default(),
}),
Err(err) => Err(ShaderError::CompilationFailed(err.into())),
}
Expand All @@ -506,8 +505,8 @@ impl Device {
&self,
raw_data: &[u8],
primitive_class: MTLPrimitiveTopologyClass,
overrides: &HashMap<msl::ResourceBindingLocation, msl::ResourceBinding>,
) -> Result<(metal::Library, FastHashMap<String, spirv::EntryPoint>), ShaderError> {
overrides: &n::ResourceOverrideMap,
) -> Result<(metal::Library, n::EntryPointMap), ShaderError> {
// spec requires "codeSize must be a multiple of 4"
assert_eq!(raw_data.len() & 3, 0);

Expand All @@ -528,7 +527,10 @@ impl Device {
compiler_options.resolve_specialized_array_lengths = true;
compiler_options.vertex.invert_y = true;
// fill the overrides
compiler_options.resource_binding_overrides = overrides.clone();
compiler_options.resource_binding_overrides = overrides
.iter()
.map(|(key, value)| (key.clone(), value.clone()))
.collect();

ast.set_compiler_options(&compiler_options)
.map_err(|err| {
Expand Down Expand Up @@ -557,7 +559,7 @@ impl Device {
ShaderError::CompilationFailed(msg)
})?;

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

for (set_index, set_layout) in set_layouts.into_iter().enumerate() {
match set_layout.borrow() {
Expand Down Expand Up @@ -1185,7 +1187,7 @@ impl hal::Device<Backend> for Device {
let (library, entry_point_map) = self.compile_shader_library(
raw_data,
MTLPrimitiveTopologyClass::Unspecified,
&HashMap::new(),
&n::ResourceOverrideMap::default(),
)?;
n::ShaderModule::Compiled {
library,
Expand Down
9 changes: 6 additions & 3 deletions src/backend/metal/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use {Backend, BufferPtr, SamplerPtr, TexturePtr};
use internal::Channel;
use window::SwapchainImage;

use std::collections::HashMap;
use std::ops::Range;
use std::os::raw::{c_void, c_long};
use std::sync::{Arc, Condvar, Mutex, RwLock};
Expand All @@ -20,13 +19,15 @@ use foreign_types::ForeignType;
use range_alloc::RangeAllocator;


pub type EntryPointMap = FastHashMap<String, spirv::EntryPoint>;

/// Shader module can be compiled in advance if it's resource bindings do not
/// depend on pipeline layout, in which case the value would become `Compiled`.
#[derive(Debug)]
pub enum ShaderModule {
Compiled {
library: metal::Library,
entry_point_map: FastHashMap<String, spirv::EntryPoint>,
entry_point_map: EntryPointMap,
},
Raw(Vec<u8>),
}
Expand Down Expand Up @@ -65,11 +66,13 @@ pub struct Framebuffer {
unsafe impl Send for Framebuffer {}
unsafe impl Sync for Framebuffer {}

pub type ResourceOverrideMap = FastHashMap<msl::ResourceBindingLocation, msl::ResourceBinding>;

#[derive(Debug)]
pub struct PipelineLayout {
// First vertex buffer index to be used by attributes
pub(crate) attribute_buffer_index: u32,
pub(crate) res_overrides: HashMap<msl::ResourceBindingLocation, msl::ResourceBinding>,
pub(crate) res_overrides: ResourceOverrideMap,
}

#[derive(Clone, Debug)]
Expand Down

0 comments on commit 96871af

Please sign in to comment.