Skip to content

Commit

Permalink
Fix bind groups for samplers and dynamic types
Browse files Browse the repository at this point in the history
- Add additional logging for instance and device creation
- Fix set_bind_group and add tests
- Add missing SurfaceDescriptorUnix typedef
- Exclude target dir when compiling shaders
  • Loading branch information
aloucks committed Apr 21, 2019
1 parent dc493e7 commit 917a5bd
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 22 deletions.
3 changes: 2 additions & 1 deletion compile_shaders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
set -e

DIR=$(dirname ${BASH_SOURCE[0]})
FILES=$(find $DIR -name "*.glsl")
# find all glsl files except for anything nested under ./target
FILES=$(find $DIR -path ./target -prune -o -name "*.glsl" -print)

for FILE in ${FILES}; do
NAME_GLSL=$(basename ${FILE})
Expand Down
1 change: 0 additions & 1 deletion examples/particle_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use rand::Rng;

use std::time::{Duration, Instant};


#[repr(C)]
#[derive(Copy, Clone, Debug)]
struct PositionColor {
Expand Down
13 changes: 11 additions & 2 deletions src/imp/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,19 @@ impl AdapterInner {
};

unsafe {
let physical_devices = instance.raw.enumerate_physical_devices()?;
let physical_devices = match instance.raw.enumerate_physical_devices() {
Ok(physical_devices) => physical_devices,
Err(e) => {
log::error!("failed to enumerate physical devices: {:?}", e);
return Err(e)?;
}
};
let physical_device_properties = &mut Vec::with_capacity(physical_devices.len());
for physical_device in physical_devices.iter().cloned() {
physical_device_properties.push(instance.raw.get_physical_device_properties(physical_device));
let properties = instance.raw.get_physical_device_properties(physical_device);
let name = CStr::from_ptr(properties.device_name.as_ptr());
log::debug!("found physical device: {:?} ({})", name, properties.device_type);
physical_device_properties.push(properties);
}
match options.power_preference {
PowerPreference::HighPerformance => {
Expand Down
12 changes: 6 additions & 6 deletions src/imp/command_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ impl CommandEncoderInner {
) {
for (index, layout_binding) in bind_group.inner.layout.bindings.iter().enumerate() {
match layout_binding.binding_type {
BindingType::UniformBuffer => {
BindingType::UniformBuffer | BindingType::DynamicUniformBuffer => {
let (buffer, _) = bind_group.inner.bindings[index]
.resource
.as_buffer()
.expect("BindingType::UniformBuffer => BindingResource::Buffer");
.expect("BindingType::[Dynamic]UniformBuffer => BindingResource::Buffer");
usage_tracker.buffer_used_as(buffer.inner.clone(), BufferUsageFlags::UNIFORM);
}
BindingType::StorageBuffer => {
BindingType::StorageBuffer | BindingType::DynamicStorageBuffer => {
let (buffer, _) = bind_group.inner.bindings[index]
.resource
.as_buffer()
.expect("BindingType::StorageBuffer => BindingResource::Buffer");
.expect("BindingType::[Dynamic]StorageBuffer => BindingResource::Buffer");
usage_tracker.buffer_used_as(buffer.inner.clone(), BufferUsageFlags::STORAGE);
}
BindingType::SampledTexture => {
Expand All @@ -133,8 +133,8 @@ impl CommandEncoderInner {
.expect("BindingType::StorageTexelBuffer => BindingResource::BufferView");
usage_tracker.buffer_used_as(buffer_view.inner.buffer.clone(), BufferUsageFlags::STORAGE);
}
_ => {
unimplemented!("binding type: {:?}", layout_binding.binding_type);
BindingType::Sampler => {
// no usage to track
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions src/imp/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl InstanceInner {
let name = CStr::from_ptr(p.extension_name.as_ptr());
let name_cow = name.to_string_lossy();
log::trace!("found instance extension: {}", name_cow);
if name_cow.contains("surface") {
if name_cow.ends_with("surface") {
include_extension = true;
}
if name_cow == "VK_EXT_debug_report" && init_debug_report {
Expand All @@ -76,19 +76,32 @@ impl InstanceInner {
}
}

for p in entry.enumerate_instance_layer_properties()?.iter() {
let instance_layer_properties = entry.enumerate_instance_layer_properties()?;

for p in instance_layer_properties.iter() {
let name = CStr::from_ptr(p.layer_name.as_ptr());
log::trace!("found instance layer: {}", name.to_string_lossy());
}

let app_info = vk::ApplicationInfo::builder()
.api_version(ash::vk_make_version!(1, 0, 0));

let layer_names = [
let layer_names = vec![
#[cfg(debug_assertions)]
c_str!("VK_LAYER_LUNARG_standard_validation")
];

for layer_name in layer_names.iter() {
let requested_layer_name = CStr::from_ptr(*layer_name);
let is_available = instance_layer_properties.iter().any(|p| {
let name = CStr::from_ptr(p.layer_name.as_ptr());
name == requested_layer_name
});
if !is_available {
log::error!("requested layer unavailable: {:?}", requested_layer_name.to_string_lossy());
}
}

let extension_names_ptrs: Vec<_> = extension_names.iter().map(|name| name.as_ptr()).collect();

let create_info = vk::InstanceCreateInfo::builder()
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ pub struct SurfaceDescriptorUnix {
#[cfg(windows)]
pub type SurfaceDescriptor = SurfaceDescriptorWin32;

#[cfg(all(unix, not(target_os = "android"), not(target_os = "macos")))]
pub type SurfaceDescriptor = SurfaceDescriptorUnix;

#[derive(Clone, Debug)]
pub struct Surface {
inner: Arc<imp::SurfaceInner>,
Expand Down
Loading

0 comments on commit 917a5bd

Please sign in to comment.