mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +11:00
Re-use render context in headless
This commit is contained in:
parent
19552ad819
commit
56939df615
|
@ -10,11 +10,11 @@ use scenes::{SceneParams, SceneSet, SimpleText};
|
|||
use vello::{
|
||||
block_on_wgpu,
|
||||
kurbo::{Affine, Vec2},
|
||||
util::RenderContext,
|
||||
Scene, SceneBuilder, SceneFragment,
|
||||
};
|
||||
use wgpu::{
|
||||
util::initialize_adapter_from_env_or_default, Backends, BufferDescriptor, BufferUsages,
|
||||
CommandEncoderDescriptor, DeviceDescriptor, Extent3d, ImageCopyBuffer, Instance, Limits,
|
||||
BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, ImageCopyBuffer,
|
||||
TextureDescriptor, TextureFormat, TextureUsages,
|
||||
};
|
||||
|
||||
|
@ -77,23 +77,15 @@ fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
|
||||
let instance = Instance::new(wgpu::InstanceDescriptor {
|
||||
backends: wgpu::Backends::PRIMARY,
|
||||
dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,
|
||||
});
|
||||
let adapter = initialize_adapter_from_env_or_default(&instance, Backends::PRIMARY, None)
|
||||
let mut context = RenderContext::new()
|
||||
.or_else(|_| bail!("Got non-Send/Sync error from creating render context"))?;
|
||||
let device_id = context
|
||||
.device(None)
|
||||
.await
|
||||
.ok_or_else(|| anyhow!("Failed to intiialise adapter"))?;
|
||||
let (device, queue) = adapter
|
||||
.request_device(
|
||||
&DeviceDescriptor {
|
||||
label: Some("Vello Headless"),
|
||||
features: wgpu::Features::TIMESTAMP_QUERY | wgpu::Features::CLEAR_TEXTURE,
|
||||
limits: Limits::default(),
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
.ok_or_else(|| anyhow!("No compatible device found"))?;
|
||||
let device_handle = &mut context.devices[device_id];
|
||||
let device = &device_handle.device;
|
||||
let queue = &device_handle.queue;
|
||||
let mut renderer = vello::Renderer::new(&device)
|
||||
.or_else(|_| bail!("Got non-Send/Sync error from creating renderer"))?;
|
||||
let mut fragment = SceneFragment::new();
|
||||
|
|
|
@ -90,6 +90,7 @@ fn example_scene_of(file: PathBuf) -> ExampleScene {
|
|||
let mut builder = SceneBuilder::for_fragment(&mut new_scene);
|
||||
vello_svg::render_tree(&mut builder, &svg);
|
||||
let resolution = Vec2::new(svg.size.width(), svg.size.height());
|
||||
// TODO: Handle svg.view_box
|
||||
(new_scene, resolution)
|
||||
});
|
||||
builder.append(&scene_frag, None);
|
||||
|
|
|
@ -84,7 +84,7 @@ impl RenderContext {
|
|||
}
|
||||
|
||||
/// Finds or creates a compatible device handle id.
|
||||
async fn device(&mut self, compatible_surface: Option<&Surface>) -> Option<usize> {
|
||||
pub async fn device(&mut self, compatible_surface: Option<&Surface>) -> Option<usize> {
|
||||
let compatible = match compatible_surface {
|
||||
Some(s) => self
|
||||
.devices
|
||||
|
|
Loading…
Reference in a new issue