Skip to content

Commit

Permalink
Merge #2948
Browse files Browse the repository at this point in the history
2948: Remove typed command wrappers r=msiglreith,grovesNL a=kvark

Here comes another midnight PR. If you ever looked for a way to make users stick to the last published version (hal-0.3 in our case), look no more. This PR removes a layer from HAL and reorders the exported types so that everyone is guaranteed to have fun fixing their programs. Seriously though, the old way of type re-exports was very inconsistent and messy, both on the HAL and using sides.

To clarify, I think having `Capability`-based wrappers is very useful, it's a great thing to have. Problems are: 1) it's not needed by the backends, and 2) it's not *universally* useful, i.e. things like Rendy, WebRender, and WebGPU can't really take full advantage of it. Therefore, our recommendation is to consider [rendy-command](https://crates.io/crates/rendy-command) as a replacement. cc @omni-viral 

With the removal of typed layers, our names became more solid, and the semantics of clear values is much simpler now.

Fixes #2862
PR checklist:
- [x] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [x] tested examples with the following backends: all
- [x] `rustfmt` run on changed code

@grovesNL @msiglreith this PR should probably not hang around for too long, since it's hard to rebase. Only HAL parts needs reviewing, everything else is not as important.

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
  • Loading branch information
3 people committed Aug 10, 2019
2 parents f1e0929 + 49caf36 commit 3c323be
Show file tree
Hide file tree
Showing 65 changed files with 2,157 additions and 3,654 deletions.
245 changes: 118 additions & 127 deletions examples/colour-uniform/main.rs

Large diffs are not rendered by default.

41 changes: 24 additions & 17 deletions examples/compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
allow(dead_code, unused_extern_crates, unused_imports)
)]

extern crate env_logger;
#[cfg(feature = "dx11")]
extern crate gfx_backend_dx11 as back;
#[cfg(feature = "dx12")]
Expand All @@ -21,10 +20,7 @@ extern crate gfx_hal as hal;

use std::str::FromStr;

use hal::{buffer, command, memory, pool, pso};
use hal::{Backend, Compute, DescriptorPool, Device, Instance, PhysicalDevice, QueueFamily};

extern crate glsl_to_spirv;
use hal::{adapter::MemoryType, buffer, command, memory, pool, prelude::*, pso};

use std::fs;

Expand Down Expand Up @@ -55,16 +51,28 @@ fn main() {
.find(|a| {
a.queue_families
.iter()
.any(|family| family.supports_compute())
.any(|family| family.queue_type().supports_compute())
})
.expect("Failed to find a GPU with compute support!");

let memory_properties = adapter.physical_device.memory_properties();
let (device, mut queue_group) = adapter.open_with::<_, Compute>(1, |_family| true).unwrap();
let family = adapter
.queue_families
.iter()
.find(|family| family.queue_type().supports_compute())
.unwrap();
let mut gpu = unsafe {
adapter
.physical_device
.open(&[(family, &[1.0])], hal::Features::empty())
.unwrap()
};
let device = &gpu.device;
let queue_group = gpu.queue_groups.first_mut().unwrap();

let glsl = fs::read_to_string("compute/shader/collatz.comp").unwrap();
let file = glsl_to_spirv::compile(&glsl, glsl_to_spirv::ShaderType::Compute).unwrap();
let spirv: Vec<u32> = hal::read_spirv(file).unwrap();
let spirv: Vec<u32> = pso::read_spirv(file).unwrap();
let shader = unsafe { device.create_shader_module(&spirv) }.unwrap();

let (pipeline_layout, pipeline, set_layout, mut desc_pool) = {
Expand Down Expand Up @@ -155,14 +163,13 @@ fn main() {
}));
};

let mut command_pool = unsafe {
device.create_command_pool_typed(&queue_group, pool::CommandPoolCreateFlags::empty())
}
.expect("Can't create command pool");
let mut command_pool =
unsafe { device.create_command_pool(family.id(), pool::CommandPoolCreateFlags::empty()) }
.expect("Can't create command pool");
let fence = device.create_fence(false).unwrap();
let mut command_buffer = command_pool.acquire_command_buffer::<command::OneShot>();
let mut command_buffer = command_pool.allocate_one(command::Level::Primary);
unsafe {
command_buffer.begin();
command_buffer.begin_primary(command::CommandBufferFlags::ONE_TIME_SUBMIT);
command_buffer.copy_buffer(
&staging_buffer,
&device_buffer,
Expand Down Expand Up @@ -229,7 +236,7 @@ fn main() {
}

unsafe {
device.destroy_command_pool(command_pool.into_raw());
device.destroy_command_pool(command_pool);
device.destroy_descriptor_pool(desc_pool);
device.destroy_descriptor_set_layout(set_layout);
device.destroy_shader_module(shader);
Expand All @@ -243,9 +250,9 @@ fn main() {
}
}

unsafe fn create_buffer<B: Backend>(
unsafe fn create_buffer<B: hal::Backend>(
device: &B::Device,
memory_types: &[hal::MemoryType],
memory_types: &[MemoryType],
properties: memory::Properties,
usage: buffer::Usage,
stride: u64,
Expand Down
Loading

0 comments on commit 3c323be

Please sign in to comment.