mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Restructure GPU compilation execution pipeline (#903)
* Restructure gpu compilation execution pipeline * Add compilation server/client infrastructure * Add wgpu executor
This commit is contained in:
committed by
Keavon Chambers
parent
be32f7949f
commit
79ad3e7908
68
node-graph/vulkan-executor/src/context.rs
Normal file
68
node-graph/vulkan-executor/src/context.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use std::sync::Arc;
|
||||
use vulkano::{
|
||||
command_buffer::allocator::StandardCommandBufferAllocator,
|
||||
descriptor_set::allocator::StandardDescriptorSetAllocator,
|
||||
device::{Device, DeviceCreateInfo, Queue, QueueCreateInfo},
|
||||
instance::{Instance, InstanceCreateInfo},
|
||||
memory::allocator::StandardMemoryAllocator,
|
||||
VulkanLibrary,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Context {
|
||||
pub instance: Arc<Instance>,
|
||||
pub device: Arc<Device>,
|
||||
pub queue: Arc<Queue>,
|
||||
pub allocator: StandardMemoryAllocator,
|
||||
pub command_buffer_allocator: StandardCommandBufferAllocator,
|
||||
pub descriptor_set_allocator: StandardDescriptorSetAllocator,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new() -> Self {
|
||||
let library = VulkanLibrary::new().unwrap();
|
||||
let instance = Instance::new(library, InstanceCreateInfo::default()).expect("failed to create instance");
|
||||
let physical = instance.enumerate_physical_devices().expect("could not enumerate devices").next().expect("no device available");
|
||||
for family in physical.queue_family_properties() {
|
||||
println!("Found a queue family with {:?} queue(s)", family.queue_count);
|
||||
}
|
||||
let queue_family_index = physical
|
||||
.queue_family_properties()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.position(|(_, q)| q.queue_flags.graphics)
|
||||
.expect("couldn't find a graphical queue family") as u32;
|
||||
|
||||
let (device, mut queues) = Device::new(
|
||||
physical,
|
||||
DeviceCreateInfo {
|
||||
// here we pass the desired queue family to use by index
|
||||
queue_create_infos: vec![QueueCreateInfo {
|
||||
queue_family_index,
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.expect("failed to create device");
|
||||
let queue = queues.next().unwrap();
|
||||
let alloc = StandardMemoryAllocator::new_default(device.clone());
|
||||
let calloc = StandardCommandBufferAllocator::new(device.clone());
|
||||
let dalloc = StandardDescriptorSetAllocator::new(device.clone());
|
||||
|
||||
Self {
|
||||
instance,
|
||||
device,
|
||||
queue,
|
||||
allocator: alloc,
|
||||
command_buffer_allocator: calloc,
|
||||
descriptor_set_allocator: dalloc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Context {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user